From 992d4b4b8d3f3a630a2cf00d593ee4ce4dfa7ce8 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Thu, 9 Jan 2025 22:12:06 +0100 Subject: New upstream version 2.7.0~rc8+repack --- lib/77bit/77bit.txt | 168 +- lib/77bit/CQ_messages.txt | 24 +- lib/77bit/NewCode.txt | 98 +- lib/77bit/New_Features_WSJT-X_2.0.txt | 526 +- lib/77bit/all28.txt | 80 +- lib/77bit/arrl_sec.txt | 166 +- lib/77bit/call_to_c28.f90 | 42 +- lib/77bit/calls.txt | 10 +- lib/77bit/calls1.txt | 42 +- lib/77bit/calls2.txt | 14 +- lib/77bit/calls3.txt | 8 +- lib/77bit/encode77.f90 | 120 +- lib/77bit/encode77.out | 82 +- lib/77bit/free_text.f90 | 116 +- lib/77bit/g2 | 12 +- lib/77bit/g8 | 6 +- lib/77bit/hash22calc.f90 | 84 +- lib/77bit/messages.txt | 200 +- lib/77bit/messages_2.txt | 98 +- lib/77bit/msgtypes.txt | 46 +- lib/77bit/msgtypes.txt.0 | 46 +- lib/77bit/my_hash.f90 | 22 +- lib/77bit/nonstd_to_c58.f90 | 26 +- lib/77bit/packjt77.f90 | 3290 +++++----- lib/77bit/parse77.f90 | 22 +- lib/77bit/test28.f90 | 126 +- lib/77bit/test28.txt | 70 +- lib/77bit/todo.txt | 118 +- lib/77bit/tokens.txt | 24 +- lib/77bit/wsjt-x_v2.0.txt | 426 +- lib/CQnnnCAT.txt | 78 +- lib/C_interface_module.f90 | 882 +-- lib/afc65b.f90 | 188 +- lib/afc9.f90 | 162 +- lib/ana932.f90 | 42 +- lib/astrosub.f90 | 196 +- lib/avecho.f90 | 240 +- lib/averms.f90 | 40 +- lib/avg4.f90 | 4 +- lib/blanker.f90 | 104 +- lib/bpdecode128_90.f90 | 234 +- lib/bpdecode128_90.f90.save | 232 +- lib/bpdecode144.f90 | 696 +- lib/bpdecode40.f90 | 296 +- lib/cablog.f90 | 284 +- lib/calibrate.f90 | 192 +- lib/char.h | 114 +- lib/chkfft2.f90 | 374 +- lib/chkfft3.f90 | 354 +- lib/code426.f90 | 124 +- lib/conv232.f90 | 76 +- lib/count4.f90 | 108 +- lib/crc.f90 | 108 +- lib/crc10.cpp | 62 +- lib/crc13.cpp | 62 +- lib/crc14.cpp | 62 +- lib/cwsim.f90 | 470 +- lib/db.f90 | 10 +- lib/decode4.f90 | 224 +- lib/decode9w.f90 | 134 +- lib/decode_msk144.f90 | 112 +- lib/decode_rs.c | 526 +- lib/decoder.f90 | 1704 ++--- lib/deep4.f90 | 338 +- lib/deg2grid.f90 | 60 +- lib/degrade_snr.f90 | 42 +- lib/demod64a.f90 | 122 +- lib/determ.f90 | 64 +- lib/digi-contest.txt | 554 +- lib/downsam9.f90 | 176 +- lib/echo_snr.f90 | 102 +- lib/echosim.f90 | 252 +- lib/emedop.dat | 16 +- lib/emedop.f90 | 134 +- lib/encode232.f90 | 66 +- lib/encode4.f90 | 40 +- lib/encode_128_90.f90 | 116 +- lib/encode_msk40.f90 | 92 +- lib/encode_rs.c | 94 +- lib/entail.f90 | 60 +- lib/ephem.f90 | 170 +- lib/extract.f90 | 486 +- lib/extract4.f90 | 138 +- lib/extractmessage77.f90 | 34 +- lib/fano232.f90 | 276 +- lib/fast9.f90 | 382 +- lib/fast_decode.f90 | 180 +- lib/fchisq0.f90 | 46 +- lib/fer | 82 +- lib/fer65.f90 | 390 +- lib/fersum.f90 | 144 +- lib/fftw3.f90 | 128 +- lib/fftw3mod.f90 | 8 +- lib/fil3c.f90 | 144 +- lib/fil4.f90 | 98 +- lib/fitcal.f90 | 68 +- lib/fix_contest_msg.f90 | 64 +- lib/fixwav.f90 | 132 +- lib/flat1a.f90 | 58 +- lib/flat1b.f90 | 58 +- lib/flat4.f90 | 106 +- lib/fmtave.f90 | 128 +- lib/fmtmsg.f90 | 42 +- lib/foldspec9f.f90 | 60 +- lib/four2a.f90 | 228 +- lib/fqso_first.f90 | 64 +- lib/fspread_lorentz.f90 | 94 +- lib/fst280_decode.f90 | 1124 ++-- lib/fst4/bpdecode240_101.f90 | 222 +- lib/fst4/decode240_101.f90 | 310 +- lib/fst4/decode240_74.f90 | 322 +- lib/fst4/encode240_101.f90 | 88 +- lib/fst4/encode240_74.f90 | 88 +- lib/fst4/fastosd240_74.f90 | 578 +- lib/fst4/fst4sim.f90 | 318 +- lib/fst4/gen_fst4wave.f90 | 186 +- lib/fst4/genfst4.f90 | 222 +- lib/fst4/get_crc24.f90 | 50 +- lib/fst4/get_fst4_bitmetrics.f90 | 380 +- lib/fst4/get_fst4_bitmetrics2.f90 | 254 +- lib/fst4/ldpc_240_101_generator.f90 | 284 +- lib/fst4/ldpc_240_101_parity.f90 | 786 +-- lib/fst4/ldpc_240_74_generator.f90 | 340 +- lib/fst4/ldpc_240_74_parity.f90 | 846 +-- lib/fst4/ldpcsim240_101.f90 | 274 +- lib/fst4/ldpcsim240_74.f90 | 540 +- lib/fst4/osd240_101.f90 | 808 +-- lib/fst4/osd240_74.f90 | 808 +-- lib/fst4_decode.f90 | 2050 +++--- lib/ft2/cdatetime.f90 | 12 +- lib/ft2/ft2.f90 | 558 +- lib/ft2/ft2.ini | 4 +- lib/ft2/ft2_decode.f90 | 596 +- lib/ft2/ft2_gfsk_iwave.f90 | 176 +- lib/ft2/ft2_iwave.f90 | 128 +- lib/ft2/ft2_params.f90 | 24 +- lib/ft2/ft2audio.c | 694 +- lib/ft2/g4.cmd | 14 +- lib/ft2/gcom1.f90 | 68 +- lib/ft2/genft2.f90 | 172 +- lib/ft2/getcandidates2a.f90 | 128 +- lib/ft2/gfsk_pulse.f90 | 12 +- lib/ft2/portaudio.h | 2246 +++---- lib/ft2/ptt.c | 116 +- lib/ft2/ptt_unix.c | 682 +- lib/ft4/clockit.f90 | 222 +- lib/ft4/ft4_downsample.f90 | 96 +- lib/ft4/ft4_testmsg.f90 | 100 +- lib/ft4/ft4code.f90 | 204 +- lib/ft4/ft4sim.f90 | 250 +- lib/ft4/ft4sim_mult.f90 | 206 +- lib/ft4/gen_ft4wave.f90 | 132 +- lib/ft4/genft4.f90 | 180 +- lib/ft4/get_ft4_bitmetrics.f90 | 232 +- lib/ft4/getcandidates4.f90 | 166 +- lib/ft4/messages.txt | 324 +- lib/ft4/subtractft4.f90 | 132 +- lib/ft4/sync4d.f90 | 192 +- lib/ft4_decode.f90 | 934 +-- lib/ft8/bpdecode174_91.f90 | 234 +- lib/ft8/chkcrc13a.f90 | 48 +- lib/ft8/chkcrc14a.f90 | 48 +- lib/ft8/chkdec.f90 | 322 +- lib/ft8/decode174_91.f90 | 310 +- lib/ft8/encode174.f90 | 100 +- lib/ft8/encode174_91.f90 | 116 +- lib/ft8/encode174_91_nocrc.f90 | 94 +- lib/ft8/ft8_a7.f90 | 756 +-- lib/ft8/ft8_testmsg.f90 | 102 +- lib/ft8/ft8apset.f90 | 124 +- lib/ft8/ft8b.f90 | 1006 +-- lib/ft8/ft8c.f90 | 522 +- lib/ft8/ft8code.f90 | 210 +- lib/ft8/ft8d.f90 | 126 +- lib/ft8/ft8q3.f90 | 218 +- lib/ft8/ft8sim.f90 | 282 +- lib/ft8/gen_ft8wave.f90 | 166 +- lib/ft8/genft8.f90 | 92 +- lib/ft8/genft8refsig.f90 | 46 +- lib/ft8/get_crc14.f90 | 50 +- lib/ft8/ldpc_174_87_params.f90 | 204 +- lib/ft8/ldpc_174_91_c_colorder.f90 | 22 +- lib/ft8/ldpc_174_91_c_generator.f90 | 172 +- lib/ft8/ldpc_174_91_c_parity.f90 | 540 +- lib/ft8/ldpcsim174_91.f90 | 538 +- lib/ft8/osd174_91.f90 | 818 +-- lib/ft8/subtractft8.f90 | 212 +- lib/ft8/test_ft8q3.f90 | 82 +- lib/ft8_decode.f90 | 600 +- lib/ftrsd/Makefile | 106 +- lib/ftrsd/Makefile.sfrsd | 60 +- lib/ftrsd/Makefile.sfrsd3 | 76 +- lib/ftrsd/decode_rs.c | 536 +- lib/ftrsd/encode_rs.c | 94 +- lib/ftrsd/extract2.f90 | 290 +- lib/ftrsd/ftrsd2.c | 426 +- lib/ftrsd/ftrsd_paper/Makefile | 80 +- lib/ftrsd/ftrsd_paper/binomial.c | 138 +- lib/ftrsd/ftrsd_paper/binomial_subs.c | 110 +- lib/ftrsd/ftrsd_paper/bmdata-rf.dat | 22 +- lib/ftrsd/ftrsd_paper/bmdata.dat | 16 +- lib/ftrsd/ftrsd_paper/bmtheory25.dat | 86 +- lib/ftrsd/ftrsd_paper/bmtheory40.dat | 86 +- lib/ftrsd/ftrsd_paper/bmtheory43.dat | 86 +- lib/ftrsd/ftrsd_paper/bodide.f90 | 108 +- lib/ftrsd/ftrsd_paper/bodide.lab | 8 +- lib/ftrsd/ftrsd_paper/fig_bodide.gnuplot | 48 +- lib/ftrsd/ftrsd_paper/fig_ntrials_vs_nhard.gnuplot | 28 +- lib/ftrsd/ftrsd_paper/fig_psuccess.gnuplot | 50 +- lib/ftrsd/ftrsd_paper/fig_wer.gnuplot | 46 +- lib/ftrsd/ftrsd_paper/fig_wer2.gnuplot | 46 +- lib/ftrsd/ftrsd_paper/fig_wer3.gnuplot | 42 +- lib/ftrsd/ftrsd_paper/ftdata-10.dat | 20 +- lib/ftrsd/ftrsd_paper/ftdata-100.dat | 20 +- lib/ftrsd/ftrsd_paper/ftdata-1000.dat | 18 +- lib/ftrsd/ftrsd_paper/ftdata-10000.dat | 22 +- lib/ftrsd/ftrsd_paper/ftdata-100000.dat | 22 +- lib/ftrsd/ftrsd_paper/ftrsd.lyx | 6578 +++++++++---------- lib/ftrsd/ftrsd_paper/kvasd-12.dat | 16 +- lib/ftrsd/ftrsd_paper/kvasd-15.dat | 18 +- lib/ftrsd/ftrsd_paper/kvasd-8.dat | 16 +- lib/ftrsd/ftrsd_paper/mfsk.f90 | 66 +- lib/ftrsd/ftrsd_paper/prob.f90 | 82 +- lib/ftrsd/ftrsd_paper/psuccess.lab | 28 +- lib/ftrsd/ftrsd_paper/stats-100000-24db-3.dat | 1860 +++--- lib/ftrsd/ftrsd_paper/stats_0.0 | 54 +- lib/ftrsd/ftrsd_paper/stats_0.2 | 54 +- lib/ftrsd/ftrsd_paper/stats_1.0 | 54 +- lib/ftrsd/ftrsd_paper/wer2.lab | 12 +- lib/ftrsd/ftrsdap.c | 454 +- lib/ftrsd/init_rs.c | 238 +- lib/ftrsd/int.h | 108 +- lib/ftrsd/rs2.h | 32 +- lib/ftrsd/rsdtest.f90 | 68 +- lib/ftrsd/sfrsd.c | 274 +- lib/ftrsd/sfrsd2.h | 6 +- lib/ftrsd/sfrsd3.c | 486 +- lib/g1 | 8 +- lib/g1.bat | 8 +- lib/g2.bat | 8 +- lib/g3.bat | 8 +- lib/g4.bat | 6 +- lib/gen4.f90 | 86 +- lib/genmet.f90 | 180 +- lib/genmsk_128_90.f90 | 240 +- lib/genqra64.f90 | 140 +- lib/genwave.f90 | 104 +- lib/genwspr.f90 | 60 +- lib/get_q3list.f90 | 264 +- lib/getmet4.f90 | 112 +- lib/gran.c | 68 +- lib/graycode.f90 | 18 +- lib/grayline.f90 | 64 +- lib/grid2deg.f90 | 78 +- lib/hash.f90 | 20 +- lib/hashing.f90 | 20 +- lib/hint65.f90 | 308 +- lib/hspec.f90 | 222 +- lib/igray.c | 36 +- lib/image.f90 | 672 +- lib/indexx.f90 | 182 +- lib/init_random_seed.c | 164 +- lib/init_random_seed.f90 | 110 +- lib/init_random_seed.h | 40 +- lib/init_rs.c | 240 +- lib/int.h | 114 +- lib/inter_wspr.f90 | 90 +- lib/interleave4.f90 | 86 +- lib/iso_c_utilities.f90 | 174 +- lib/jplsubs.f | 1798 +++--- lib/jt4.f90 | 52 +- lib/jt4_decode.f90 | 824 +-- lib/jt4a.f90 | 4 +- lib/jt4code.f90 | 100 +- lib/jt4sim.f90 | 362 +- lib/jt65.f90 | 286 +- lib/jt65_decode.f90 | 1044 +-- lib/jt65_test.f90 | 156 +- lib/jt65code.f90 | 206 +- lib/jt65sim.f90 | 624 +- lib/jt9.f90 | 762 +-- lib/jt9_decode.f90 | 344 +- lib/jt9a.f90 | 204 +- lib/jt9code.f90 | 172 +- lib/jt9com.f90 | 124 +- lib/jt9w.f90 | 56 +- lib/ldpc_128_90_b_generator.f90 | 82 +- lib/ldpc_128_90_b_reordered_parity.f90 | 368 +- lib/ldpc_128_90_generator.f90 | 82 +- lib/ldpc_128_90_reordered_parity.f90 | 352 +- lib/ldpcsim128_90.f90 | 284 +- lib/ldpcsim40.f90 | 276 +- lib/libration.f90 | 76 +- lib/lorentzian.f90 | 204 +- lib/lpf1.f90 | 58 +- lib/makepings.f90 | 50 +- lib/map65_mmdec.f90 | 180 +- lib/met8.21 | 512 +- lib/mixlpf.f90 | 50 +- lib/morse.f90 | 174 +- lib/msk144_freq_search.f90 | 100 +- lib/msk144_testmsg.f90 | 94 +- lib/msk144code.f90 | 166 +- lib/msk144decodeframe.f90 | 224 +- lib/msk144signalquality.f90 | 426 +- lib/msk144sim.f90 | 212 +- lib/msk144spd.f90 | 392 +- lib/msk144sync.f90 | 202 +- lib/msk40_freq_search.f90 | 106 +- lib/msk40decodeframe.f90 | 326 +- lib/msk40spd.f90 | 396 +- lib/msk40sync.f90 | 206 +- lib/mskber.f90 | 292 +- lib/mskdt.f90 | 156 +- lib/mskrtd.f90 | 522 +- lib/nfft.dat | 4134 ++++++------ lib/nuttal_window.f90 | 30 +- lib/osd128_90.f90 | 750 +-- lib/packjt.f90 | 2066 +++--- lib/pctile.f90 | 42 +- lib/peakup.f90 | 16 +- lib/pfx.f90 | 100 +- lib/platanh.f90 | 48 +- lib/pltanh.f90 | 48 +- lib/polyfit.f90 | 144 +- lib/prcom.f90 | 2 +- lib/prog_args.f90 | 8 +- lib/ps4.f90 | 54 +- lib/psk_parse.f90 | 216 +- lib/ptt.c | 100 +- lib/q65_decode.f90 | 1010 +-- lib/q65params.f90 | 64 +- lib/qra/q65/Makefile.Win | 80 +- lib/qra/q65/build.sh | 4 +- lib/qra/q65/ebnovalues.txt | 32 +- lib/qra/q65/fadengauss.c | 604 +- lib/qra/q65/fadenlorentz.c | 608 +- lib/qra/q65/genq65.f90 | 102 +- lib/qra/q65/normrnd.c | 164 +- lib/qra/q65/normrnd.h | 102 +- lib/qra/q65/npfwht.c | 430 +- lib/qra/q65/npfwht.h | 90 +- lib/qra/q65/pdmath.c | 770 +-- lib/qra/q65/pdmath.h | 170 +- lib/qra/q65/q65.c | 1778 ++--- lib/qra/q65/q65.f90 | 1824 +++--- lib/qra/q65/q65.h | 246 +- lib/qra/q65/q65.sln | 40 +- lib/qra/q65/q65.vcproj | 510 +- lib/qra/q65/q65_ap.f90 | 332 +- lib/qra/q65/q65_encoding_modules.f90 | 442 +- lib/qra/q65/q65_ftn_test.f90 | 102 +- lib/qra/q65/q65_loops.f90 | 202 +- lib/qra/q65/q65_set_list.f90 | 194 +- lib/qra/q65/q65_set_list2.f90 | 140 +- lib/qra/q65/q65_subs.c | 294 +- lib/qra/q65/q65code.f90 | 58 +- lib/qra/q65/q65sim.f90 | 494 +- lib/qra/q65/q65test.c | 1820 +++--- lib/qra/q65/qra15_65_64_irr_e23.c | 1116 ++-- lib/qra/q65/qra15_65_64_irr_e23.h | 82 +- lib/qra/q65/qracodes.c | 948 +-- lib/qra/q65/qracodes.h | 160 +- lib/qra/q65/wer-ff-qra15_65_64_irr_e23-ap00.txt | 38 +- lib/qra/qracodes/Makefile.Win | 66 +- lib/qra/qracodes/ebno10000.txt | 14 +- lib/qra/qracodes/ebnovalues.txt | 28 +- lib/qra/qracodes/ebnovaluesfast.txt | 22 +- lib/qra/qracodes/main.c | 1474 ++--- lib/qra/qracodes/normrnd.c | 164 +- lib/qra/qracodes/normrnd.h | 102 +- lib/qra/qracodes/npfwht.c | 430 +- lib/qra/qracodes/npfwht.h | 90 +- lib/qra/qracodes/pdmath.c | 770 +-- lib/qra/qracodes/pdmath.h | 170 +- lib/qra/qracodes/qra12_63_64_irr_b.c | 1066 +-- lib/qra/qracodes/qra12_63_64_irr_b.h | 78 +- lib/qra/qracodes/qra13_64_64_irr_e.c | 1066 +-- lib/qra/qracodes/qra13_64_64_irr_e.h | 78 +- lib/qra/qracodes/qracodes.c | 948 +-- lib/qra/qracodes/qracodes.h | 158 +- lib/qra64code.f90 | 128 +- lib/qratest.f90 | 108 +- lib/readwav.f90 | 146 +- lib/rectify_msk.f90 | 128 +- lib/refspectrum.f90 | 316 +- lib/rig_control.c | 198 +- lib/rs.h | 70 +- lib/rtty_spec.f90 | 204 +- lib/save_dxbase.f90 | 18 +- lib/save_echo_params.f90 | 58 +- lib/savec2.f90 | 110 +- lib/sec0.f90 | 42 +- lib/sec_midn.f90 | 22 +- lib/sfrsd.f90 | 242 +- lib/sgran.c | 14 +- lib/sh65.f90 | 188 +- lib/sh65snr.f90 | 72 +- lib/shell.f90 | 54 +- lib/shmem.cpp | 40 +- lib/shmem.f90 | 90 +- lib/slasubs.f | 6800 ++++++++++---------- lib/sleep.h | 64 +- lib/sleep_msec.f90 | 8 +- lib/slope.f90 | 80 +- lib/smo.f90 | 38 +- lib/smolorentz.f90 | 84 +- lib/softsym9f.f90 | 110 +- lib/softsym9w.f90 | 250 +- lib/sort.f90 | 192 +- lib/spec64.f90 | 106 +- lib/spec9f.f90 | 60 +- lib/spec_qra65.f90 | 100 +- lib/stats.f90 | 132 +- lib/sumsim.f90 | 84 +- lib/superfox/foxgen2.f90 | 150 +- lib/superfox/ft8_params.f90 | 24 +- lib/superfox/gtag.f90 | 6 +- lib/superfox/julian.f90 | 78 +- lib/superfox/popen_module.f90 | 206 +- lib/superfox/qpc/dbgprintf.c | 134 +- lib/superfox/qpc/dbgprintf.h | 128 +- lib/superfox/qpc/nhash2.c | 766 +-- lib/superfox/qpc/nhash2.h | 44 +- lib/superfox/qpc/np_qpc.c | 658 +- lib/superfox/qpc/np_qpc.h | 124 +- lib/superfox/qpc/np_rnd.c | 270 +- lib/superfox/qpc/np_rnd.h | 118 +- lib/superfox/qpc/qpc_fwht.c | 466 +- lib/superfox/qpc/qpc_fwht.h | 114 +- lib/superfox/qpc/qpc_main.cpp | 396 +- lib/superfox/qpc/qpc_mod.f90 | 76 +- lib/superfox/qpc/qpc_n127k50q128.c | 120 +- lib/superfox/qpc/qpc_subs.c | 230 +- lib/superfox/qpc_decode2.f90 | 300 +- lib/superfox/qpc_likelihoods2.f90 | 56 +- lib/superfox/qpc_snr.f90 | 34 +- lib/superfox/qpc_sync.f90 | 214 +- lib/superfox/ran1.f90 | 56 +- lib/superfox/sfox_ana.f90 | 34 +- lib/superfox/sfox_assemble.f90 | 184 +- lib/superfox/sfox_demod.f90 | 158 +- lib/superfox/sfox_gen_gfsk.f90 | 172 +- lib/superfox/sfox_mod.f90 | 146 +- lib/superfox/sfox_pack.f90 | 356 +- lib/superfox/sfox_prob.f90 | 110 +- lib/superfox/sfox_remove.f90 | 96 + lib/superfox/sfox_remove_ft8.f90 | 426 +- lib/superfox/sfox_remove_tone.f90 | 204 +- lib/superfox/sfox_unpack.f90 | 238 +- lib/superfox/sfox_wave.f90 | 80 +- lib/superfox/sfox_wave_gfsk.f90 | 154 +- lib/superfox/sfoxsim.f90 | 328 +- lib/superfox/sfrx.f90 | 118 +- lib/superfox/sfrx_sub.f90 | 108 +- lib/superfox/sftx.f90 | 214 +- lib/superfox/sftx_sub.f90 | 130 +- lib/superfox/superfox_qpc_2.txt | 132 +- lib/superfox/twkfreq2.f90 | 38 +- lib/symspec.f90 | 252 +- lib/sync65.f90 | 188 +- lib/sync9f.f90 | 110 +- lib/syncmsk.f90 | 608 +- lib/tab.c | 72 +- lib/test_init_random_seed.f90 | 16 +- lib/test_q65.f90 | 382 +- lib/test_snr.f90 | 134 +- lib/testfast9.f90 | 84 +- lib/testmsg.f90 | 290 +- lib/timefft.f90 | 282 +- lib/timefft_opts.f90 | 96 +- lib/timer_C_wrapper.f90 | 114 +- lib/timer_common.inc | 6 +- lib/timer_impl.f90 | 532 +- lib/timer_module.f90 | 48 +- lib/timf2.f90 | 284 +- lib/tstrig.c | 52 +- lib/tstrig.h | 100 +- lib/tweak1.f90 | 46 +- lib/types.f90 | 36 +- lib/update_msk40_hasharray.f90 | 50 +- lib/update_recent_calls.f90 | 38 +- lib/usleep.c | 16 +- lib/vit213.c | 442 +- lib/vit216.c | 438 +- lib/wav11.f90 | 54 +- lib/wav12.f90 | 98 +- lib/wavhdr.f90 | 220 +- lib/wisdom.c | 26 +- lib/wqencode.f90 | 130 +- lib/wrapkarn.c | 140 +- lib/wsjt_modes.txt | 136 +- lib/wspr_downsample.f90 | 152 +- lib/wsprcode/go.sh | 2 +- lib/wsprcode/wspr_old_subs.f90 | 1874 +++--- lib/wsprcode/wsprcode.f90 | 316 +- lib/wsprd/Makefile | 78 +- lib/wsprd/Makefile.MinGW | 60 +- lib/wsprd/Makefile.win32 | 80 +- lib/wsprd/README | 140 +- lib/wsprd/fano.c | 478 +- lib/wsprd/fano.h | 78 +- lib/wsprd/fftw3.h | 820 +-- lib/wsprd/genmet.f90 | 100 +- lib/wsprd/gran.c | 56 +- lib/wsprd/jelinek.c | 326 +- lib/wsprd/jelinek.h | 48 +- lib/wsprd/metric_tables.c | 276 +- lib/wsprd/mettab.c | 152 +- lib/wsprd/nhash.c | 766 +-- lib/wsprd/nhash.h | 42 +- lib/wsprd/osdwspr.f90 | 722 +-- lib/wsprd/t2.f90 | 22 +- lib/wsprd/tab.c | 82 +- lib/wsprd/unpk.c.obsolete | 248 +- lib/wsprd/wspr_params.f90 | 40 +- lib/wsprd/wspr_wav.f90 | 98 +- lib/wsprd/wsprd.c | 3163 ++++----- lib/wsprd/wsprd_stats.txt | 48 +- lib/wsprd/wsprd_utils.c | 680 +- lib/wsprd/wsprd_utils.h | 58 +- lib/wsprd/wsprsim.c | 424 +- lib/wsprd/wsprsim_utils.c | 624 +- lib/wsprd/wsprsim_utils.h | 32 +- lib/wsprd/wsprsimf.f90 | 226 +- lib/xcall.txt | 536 +- lib/xcor.f90 | 152 +- lib/zplot9.f90 | 62 +- lib/zplt.f90 | 224 +- 529 files changed, 73300 insertions(+), 73177 deletions(-) create mode 100755 lib/superfox/sfox_remove.f90 (limited to 'lib') diff --git a/lib/77bit/77bit.txt b/lib/77bit/77bit.txt index 3d1edff6..ae8f3dd3 100755 --- a/lib/77bit/77bit.txt +++ b/lib/77bit/77bit.txt @@ -1,84 +1,84 @@ -Starting with WSJT-X 2.0, the FT8 and MSK144 protocols convey a 77-bit -payload. For most purposes these bits are interpreted as 3 bits (i3) -for message type and 74 for user information. Any message type that -uses fewer than 74 information bits can assign the remaining bits to -define message subtypes. For example, Type i3=0 uses 71 information -bits and the remaining 3 bits, here called n3, define 8 possible -subtypes. - ----------------------------------------------------------------------------------- -i3.n3 Example message Bits Total Purpose ----------------------------------------------------------------------------------- -0.0 FREE TEXT MSG 71 71 Free text -0.1 K1ABC RR73; W9XYZ -12 28 28 10 5 71 DXpedition Mode -0.2 ... tbd -0.3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day -0.4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day -0.5 123456789ABCDEF012 71 71 Telemetry (18 hex) -0.6 Temporarily hijacked in packjt77 for WSPR-LF. This is not necessary! -0.7 ... tbd - -1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg -2 PA3XYZ/P GM4ABC/P R JO22 28 1 28 1 1 15 74 EU VHF contest -3 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY Roundup -4 PJ4/KA1ABC RR73 12 58 1 2 1 74 Nonstandard calls -5 R 570007 JO22DB 12 22 1 3 11 25 74 EU VHF Contest -6 ... tbd -7 ... tbd ----------------------------------------------------------------------------------- -NB: three 74-bit message types and two 71-bit message subtypes are still TBD. ----------------------------------------------------------------------------------- - -The 28-bit fields normally used for callsigns are configured rather -differently from before. - -Facts about the 28-bit integers used to encode standard callsigns: - 2^28 = 268,435,456 Available values - 37*36*10*27*27*27 = 262,177,560 Used for standard callsigns - ----------- - 6,257,896 Difference - 2^22 = 4,194,304 Used for 22-bit hash codes - ----------- - 2,063,592 available for CQ, CQ nnn, CQ xxxx, QRZ, ... - - -Further details on message types: ------------------------------------------------------------------------------ -i3.n3 ------------------------------------------------------------------------------ -0.0 Free text, up to 13 characters. - -0.1 DXpedition mode, as developed for KH1/KH7Z. - -0.2 Report, QSO serial number from 0001 to 4095, 6-character grid, and Roger - for EU VHF contests. - -0.3 ARRL Field Day exchange (1-16 transmitters). - -0.4 ARRL Field Day exchange (17-32 transmitters). - -0.5 Telemetry, 71 bits - -1. Two callsigns, Roger, and grid or report. Each callsign may have - an appended "/R" to indicate Rover status for NA VHF contests. - Either callsign may be nonstandard if enclosed in angle brackets, - for example . - -2. Same as Type 1, but uses /P instead of /R. For European VHF contests. - -3. Standard message for ARRL RTTY Roundup. Optional "TU;" at - beginning to finish a previous QSO; then two standard callsigns, - optional "R", a 3-bit report (529 to 599), and 13 bits to indicate - US state, Canadian province/territory, or DX serial number from - 0001 to 7999. - -4. One hashed call or "CQ"; one compound or nonstandard call with up - to 11 characters; and (if not "CQ") an optional RRR, RR73, or 73. - ---------------------------------------------------------------------------- -The following are tentative and not included in first release. - -5. CQ WW RTTY - US/Can: RST CQZ state/prov R 579 5 NJ R1 r3 z6 u7 - DX: RST + CQzone R 559 15 R1 r3 z6 - -6. CQ WPX RTTY - RST + serial R 589 0013 R1 r3 n12 +Starting with WSJT-X 2.0, the FT8 and MSK144 protocols convey a 77-bit +payload. For most purposes these bits are interpreted as 3 bits (i3) +for message type and 74 for user information. Any message type that +uses fewer than 74 information bits can assign the remaining bits to +define message subtypes. For example, Type i3=0 uses 71 information +bits and the remaining 3 bits, here called n3, define 8 possible +subtypes. + +---------------------------------------------------------------------------------- +i3.n3 Example message Bits Total Purpose +---------------------------------------------------------------------------------- +0.0 FREE TEXT MSG 71 71 Free text +0.1 K1ABC RR73; W9XYZ -12 28 28 10 5 71 DXpedition Mode +0.2 ... tbd +0.3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day +0.4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day +0.5 123456789ABCDEF012 71 71 Telemetry (18 hex) +0.6 Temporarily hijacked in packjt77 for WSPR-LF. This is not necessary! +0.7 ... tbd + +1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg +2 PA3XYZ/P GM4ABC/P R JO22 28 1 28 1 1 15 74 EU VHF contest +3 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY Roundup +4 PJ4/KA1ABC RR73 12 58 1 2 1 74 Nonstandard calls +5 R 570007 JO22DB 12 22 1 3 11 25 74 EU VHF Contest +6 ... tbd +7 ... tbd +---------------------------------------------------------------------------------- +NB: three 74-bit message types and two 71-bit message subtypes are still TBD. +---------------------------------------------------------------------------------- + +The 28-bit fields normally used for callsigns are configured rather +differently from before. + +Facts about the 28-bit integers used to encode standard callsigns: + 2^28 = 268,435,456 Available values + 37*36*10*27*27*27 = 262,177,560 Used for standard callsigns + ----------- + 6,257,896 Difference + 2^22 = 4,194,304 Used for 22-bit hash codes + ----------- + 2,063,592 available for CQ, CQ nnn, CQ xxxx, QRZ, ... + + +Further details on message types: +----------------------------------------------------------------------------- +i3.n3 +----------------------------------------------------------------------------- +0.0 Free text, up to 13 characters. + +0.1 DXpedition mode, as developed for KH1/KH7Z. + +0.2 Report, QSO serial number from 0001 to 4095, 6-character grid, and Roger + for EU VHF contests. + +0.3 ARRL Field Day exchange (1-16 transmitters). + +0.4 ARRL Field Day exchange (17-32 transmitters). + +0.5 Telemetry, 71 bits + +1. Two callsigns, Roger, and grid or report. Each callsign may have + an appended "/R" to indicate Rover status for NA VHF contests. + Either callsign may be nonstandard if enclosed in angle brackets, + for example . + +2. Same as Type 1, but uses /P instead of /R. For European VHF contests. + +3. Standard message for ARRL RTTY Roundup. Optional "TU;" at + beginning to finish a previous QSO; then two standard callsigns, + optional "R", a 3-bit report (529 to 599), and 13 bits to indicate + US state, Canadian province/territory, or DX serial number from + 0001 to 7999. + +4. One hashed call or "CQ"; one compound or nonstandard call with up + to 11 characters; and (if not "CQ") an optional RRR, RR73, or 73. + +--------------------------------------------------------------------------- +The following are tentative and not included in first release. + +5. CQ WW RTTY - US/Can: RST CQZ state/prov R 579 5 NJ R1 r3 z6 u7 + DX: RST + CQzone R 559 15 R1 r3 z6 + +6. CQ WPX RTTY - RST + serial R 589 0013 R1 r3 n12 diff --git a/lib/77bit/CQ_messages.txt b/lib/77bit/CQ_messages.txt index 9dc618a1..f131f9fb 100755 --- a/lib/77bit/CQ_messages.txt +++ b/lib/77bit/CQ_messages.txt @@ -1,12 +1,12 @@ -CQ K1ABC FN42 -DE K1ABC FN42 -QRZ K1ABC FN42 -CQ AA K1ABC FN42 -CQ ZZ K1ABC FN42 -CQ 000 K1ABC FN42 -CQ 313 K1ABC FN42 -CQ 999 K1ABC FN42 -CQ AAA K1ABC FN42 -CQ ZZZ K1ABC FN42 -CQ AAAA K1ABC FN42 -CQ ZZZZ K1ABC FN42 +CQ K1ABC FN42 +DE K1ABC FN42 +QRZ K1ABC FN42 +CQ AA K1ABC FN42 +CQ ZZ K1ABC FN42 +CQ 000 K1ABC FN42 +CQ 313 K1ABC FN42 +CQ 999 K1ABC FN42 +CQ AAA K1ABC FN42 +CQ ZZZ K1ABC FN42 +CQ AAAA K1ABC FN42 +CQ ZZZZ K1ABC FN42 diff --git a/lib/77bit/NewCode.txt b/lib/77bit/NewCode.txt index 6ae6e926..99b3603e 100755 --- a/lib/77bit/NewCode.txt +++ b/lib/77bit/NewCode.txt @@ -1,49 +1,49 @@ -i3 n3 isync Operating activity, Message Type ------------------------------------------------------------ - 0 0 1 Std QSO msg (bit 72=0) - 0 0 1 Free text (bit 72=1) - 0 1 1 Fox DXpedition msg with "RR73;" ------------------------------------------------------------ - 1 0 2 Std QSO msg - 0 1 2 Fox DXpedition msg with "RR73;" - 1 * 2 NA VHF contest - 2 * 2 EU VHF contest (Tx1, Tx6) - 0 2 2 EU VHF contest (Tx2, Tx3) - 0 3 2 ARRL Field Day (1-16 transmitters) - 0 4 2 ARRL Field Day (17-32 transmitters) - 3 * 2 ARRL RTTY Roundup - 4 * 2 Compound and non-standard calls ------------------------------------------------------------ -* ==> "don't care" (types i3=1,2,3,4 do not have subtypes) ------------------------------------------------------------ - -A. Required GUI Additions (after July 3): - - 1. Entry widgets for fixed parts of contest exchanges: comboBoxes - for ARRL section, US State/Canadian Province, number of - transmitters and entry Class for Field Day. - - 2. Spinner control for serial numbers: used for EU_VHF_Contest, - and for DX stations in RTTYroundup. - -B. Code near the end of GenStdMsgs(): - - 1. if(m_config.bNA_VHF_Contest()): do as with present checkbox - 2. if(m_config.bEU_VHF_Contest()): make EU_VHF messages - 3. if(m_config.bFieldDay()): make FD messages - 4. if(m_config.bRTTYroundup()): make RR messages - 5. if MyCall or DXcall is compound or nonstandard, make new msgs - -C. Code just before calling genft8_(): - - 1. m_i3=0, m_n3=0, m_isync=1 - 2. if(check m_config.bGenerate77()) m_isync=2 - 3. if msg is not an old-style standard msg, see if it's valid - as a 77-bit msg - 4. if NO: transmit as Free Text - if YES: set i3, n3, and isync=2 - -D. Auto-sequencer code - - 1. Probably lots of changes needed: details TBD, after we make the - new messages work with Auto-Seq off. +i3 n3 isync Operating activity, Message Type +----------------------------------------------------------- + 0 0 1 Std QSO msg (bit 72=0) + 0 0 1 Free text (bit 72=1) + 0 1 1 Fox DXpedition msg with "RR73;" +----------------------------------------------------------- + 1 0 2 Std QSO msg + 0 1 2 Fox DXpedition msg with "RR73;" + 1 * 2 NA VHF contest + 2 * 2 EU VHF contest (Tx1, Tx6) + 0 2 2 EU VHF contest (Tx2, Tx3) + 0 3 2 ARRL Field Day (1-16 transmitters) + 0 4 2 ARRL Field Day (17-32 transmitters) + 3 * 2 ARRL RTTY Roundup + 4 * 2 Compound and non-standard calls +----------------------------------------------------------- +* ==> "don't care" (types i3=1,2,3,4 do not have subtypes) +----------------------------------------------------------- + +A. Required GUI Additions (after July 3): + + 1. Entry widgets for fixed parts of contest exchanges: comboBoxes + for ARRL section, US State/Canadian Province, number of + transmitters and entry Class for Field Day. + + 2. Spinner control for serial numbers: used for EU_VHF_Contest, + and for DX stations in RTTYroundup. + +B. Code near the end of GenStdMsgs(): + + 1. if(m_config.bNA_VHF_Contest()): do as with present checkbox + 2. if(m_config.bEU_VHF_Contest()): make EU_VHF messages + 3. if(m_config.bFieldDay()): make FD messages + 4. if(m_config.bRTTYroundup()): make RR messages + 5. if MyCall or DXcall is compound or nonstandard, make new msgs + +C. Code just before calling genft8_(): + + 1. m_i3=0, m_n3=0, m_isync=1 + 2. if(check m_config.bGenerate77()) m_isync=2 + 3. if msg is not an old-style standard msg, see if it's valid + as a 77-bit msg + 4. if NO: transmit as Free Text + if YES: set i3, n3, and isync=2 + +D. Auto-sequencer code + + 1. Probably lots of changes needed: details TBD, after we make the + new messages work with Auto-Seq off. diff --git a/lib/77bit/New_Features_WSJT-X_2.0.txt b/lib/77bit/New_Features_WSJT-X_2.0.txt index 85398209..55d5f3c7 100755 --- a/lib/77bit/New_Features_WSJT-X_2.0.txt +++ b/lib/77bit/New_Features_WSJT-X_2.0.txt @@ -1,263 +1,263 @@ - New Features in WSJT-X 2.0 - September 17, 2018 - -------------------------- - -This document is an update to the white paper "Plans for WSJT-X -Version 2.0" that was publicly distributed on July 26, 2018. It -describes the most important enhancements in WSJT-X 2.0 relative to -version 1.9.1. - -A majority of new program features involve the FT8 and MSK144 -protocols. Both modes have been upgraded to use use 77-bit -information payloads rather than the 75 bits of the older FT8 protocol -or 72 bits of JT4, JT9, JT65, MSK144, and QRA64. Cyclic redundancy -checks (CRCs) that protect against false decodes have been increased -from 12 to 14 bits (FT8) and from 8 to 13 bits (MSK144). These -changes bring many benefits, including support of structured messages -optimized for the following special types of QSOs and exchanged -information: - -1. NA VHF Contest operation with full and transparent support of grid - locators and "/R" (Rover) callsigns - -2. EU VHF Contest operation with the exchange of 6-digit locators, QSO - serial numbers, and "/P" (portable) callsigns - -3. ARRL Field Day operation with standard Field Day exchanges such as - "6A SNJ" - -4. ARRL RTTY Roundup operation with standard contest exchanges such as - "579 NJ" or "559 0071" - -5. Compound and nonstandard callsigns (up tp 11 characters); no need - for distinctions about "Type 1" or "Type 2" prefixes/suffixes - -6. A special "telemetry" message format for exchange of arbitrary - information up to 71 bits - -7. All features of FT8 DXpedition mode, as in WSJT-X v1.9.1 - -Conveying more information in the same bandwidth, using the same -modulation scheme, necessarily means a higher code rate and less -energy per information bit. Nevertheless, the decoding threshold S/N -for the new FT8 is slightly lower than for the old version, because of -improvements in the decoding algorithm. Decoding threshold for MSK144 -is a fraction of a dB higher than before. Symbol rates and occupied -bandwidths for both modes are the same as before, and false-decode -rates are significantly lower. - -OTHER PROGRAM ENHANCEMENTS: WSJT-X 2.0 has several other new features -and capabilities. The WSPR decoder has significantly better -sensitivity, by about 1 dB. Color highlighting of decoded messages -provides worked-before status for callsigns, grid locators, and DXCC -entities on a "by band" basis. Color highlighting can also identify -stations that have (or have not) uploaded their logs to "Logbook of -the World" (LoTW) within the past year. (Recent information from LoTW -for this purpose can be downloaded from the ARRL web site.) - -WSJT-X 2.0 introduces no significant changes to any of the modes JT4, -JT9, JT65, QRA64, ISCAT, Echo, or FreqCal. - -IMPORTANT: For the convenience of beta-testers, the first and second -release candidates -- releases with "-rc1" or "-rc2" in their names -- -will have Rx and Tx capability for both the new FT8 protocol and the -older one. Starting with the third release candidate ("-rc3"), and in -the general-availability full release of WSJT-X 2.0, only the new -protocol will be supported. In contrast, the new MSK144 protocol -replaces the old one from the outset, without backward compatibility. -To minimize on-the-air confusion, it's important that users be aware -of these distinctions and the schedule for release of WSJT-X 2.0, as -detailed below. - -MESSAGE FORMATS: The following table shows examples of message formats -supported by the new FT8 and MSK144 protocols. Parameters i3 and n3 -(shown in the first column) are used in the software to define major -and minor 77-bit message types. - ----------------------------------------------------------------------------------- -i3.n3 Example Messages Comments ----------------------------------------------------------------------------------- - 0.0 TNX BOB 73 GL Free text - 0.1 K1ABC RR73; W9XYZ -08 DXpedition Mode - 0.2 PA9XYZ 590003 IO91NP EU VHF Contest - 0.2 G4ABC/P R 570007 JO22DB EU VHF Contest - 0.3 K1ABC W9XYZ 6A WI ARRL Field Day - 0.3 W9XYZ K1ABC R 2B EMA ARRL Field Day - 0.5 123456789ABCDEF012 Telemetry (71 bits, 18 hex digits) - 1. CQ FD K1ABC FN42 ARRL Field Day - 1. CQ RU K1ABC FN42 ARRL RTTY Roundup - 1. CQ K1ABC FN42 - 1. CQ TEST K1ABC FN42 NA VHF Contest - 1. CQ TEST K1ABC/R FN42 NA VHF Contest - 1. K1ABC W9XYZ EN37 - 1. K1ABC W9XYZ -09 - 1. K1ABC W9XYZ R-17 - 1. K1ABC W9XYZ RRR - 1. K1ABC W9XYZ 73 - 1. K1ABC W9XYZ RR73 - 1. K1ABC/R W9XYZ EN37 NA VHF Contest - 1. K1ABC W9XYZ/R RR73 NA VHF Contest - 1. K1ABC/R W9XYZ/R RR73 NA VHF Contest - 1. W9XYZ Compound call - 1. W9XYZ 73 Compound call - 1. W9XYZ -13 Nonstandard call - 1. W9XYZ R+02 Nonstandard call - 1. W9XYZ RRR Nonstandard call - 1. W9XYZ RR73 Nonstandard call - 2. CQ G4ABC/P IO91 EU VHF contest - 2. G4ABC/P PA9XYZ JO22 EU VHF contest - 2. PA9XYZ G4ABC/P RR73 EU VHF contest - 3. K1ABC KA0DEF 559 MO ARRL RTTY Roundup - 3. K1ABC W9XYZ 579 WI ARRL RTTY Roundup - 3. KA1ABC G3AAA 529 0013 ARRL RTTY Roundup - 3. TU; KA0DEF K1ABC R 569 MA ARRL RTTY Roundup - 3. TU; K1ABC G3AAA R 559 0194 ARRL RTTY Roundup - 3. W9XYZ K1ABC R 589 MA ARRL RTTY Roundup - 4. CQ PJ4/K1ABC - 4. CQ YW18FIFA Nonstandard call - 4. YW18FIFA RR73 Nonstandard call - 4. PJ4/K1ABC RRR Nonstandard call - 4. YW18FIFA Nonstandard call - 4. YW18FIFA 73 Nonstandard call - 4. PJ4/K1ABC Nonstandard call - 4. PJ4/K1ABC 73 Nonstandard call - 4. YW18FIFA RRR Nonstandard call ----------------------------------------------------------------------------------- - -In the above list, callsigns enclosed in angle brackets (e.g., -, ) are transmitted as hash codes. They will be -displayed correctly by receiving stations that have copied the full -callsign without brackets in a previous transmissiion. Otherwise the -receiving software will display <...>. Hash collisions are possible -but should be rare, and extremely rare within a particular QSO. - -Some minimal message sequences that take advantage of the new 77-bit -formats are illustrated below. Model QSOs 1 and 2 are the same as -those used by the old FT8 and MSK144 protocols, and QSO number 3 is -the same as the existing FT8 DXpedition Mode. Model QSOs 4 through 9 -were not possible with the old protocols. - ----------------------------------------------------------------------------------- -1. Standard QSO ----------------------------------------------------------------------------------- -CQ K1ABC FN42 - K1ABC W9XYZ EN37 -W9XYZ K1ABC -11 - K1ABC W9XYZ R-09 -W9XYZ K1ABC RRR - K1ABC W9XYZ 73 - ----------------------------------------------------------------------------------- -2. Short-cycle QSO ----------------------------------------------------------------------------------- -CQ K1ABC FN42 - K1ABC W9XYZ -09 -W9XYZ K1ABC R-11 - K1ABC W9XYZ RR73 -W9XYZ K1ABC 73 - ----------------------------------------------------------------------------------- -3. FT8 DXpedition Mode ----------------------------------------------------------------------------------- -CQ KH1/KH7Z - KH7Z K1ABC FN42 -K1ABC KH7Z -12 - KH7Z K1ABC R-14 - KH7Z W9XYZ EN37 - ... possibly other callers ... -K1ABC RR73; W9XYZ -08 - ----------------------------------------------------------------------------------- -4. ARRL Field Day ----------------------------------------------------------------------------------- -CQ FD K1ABC FN42 - K1ABC W9XYZ 6A WI -W9XYZ K1ABC R 2B EMA - K1ABC W9XYZ RR73 - ----------------------------------------------------------------------------------- -5. ARRL VHF Contests ----------------------------------------------------------------------------------- -CQ TEST K1ABC/R FN42 "/R" is optional - K1ABC/R W9XYZ EN37 on either callsign -W9XYZ K1ABC/R R FN42 - K1ABC/R W9XYZ RR73 - ----------------------------------------------------------------------------------- -6. ARRL RTTY Roundup ----------------------------------------------------------------------------------- -CQ TEST K1ABC FN42 - K1ABC W9XYZ 579 WI -W9XYZ K1ABC R 589 MA - K1ABC KA0DEF 559 MO -TU; KA0DEF K1ABC R 569 MA - KA1ABC G3AAA 529 0013 -TU; G3AAA K1ABC R 559 MA - ----------------------------------------------------------------------------------- -7. EU VHF Contest ----------------------------------------------------------------------------------- -CQ TEST G4ABC/P IO91 "/P" is optional - G4ABC/P PA9XYZ JO22 on either callsign -PA9XYZ 590003 IO91NP - G4ABC/P R 570007 JO22DB -PA9XYZ G4ABC/P RR73 - ----------------------------------------------------------------------------------- -8. Compound or nonstandard callsign calling CQ ----------------------------------------------------------------------------------- -CQ PJ4/K1ABC - PJ4/K1ABC -W9XYZ -11 - W9XYZ R-09 - PJ4/K1ABC RRR - PJ4/K1ABC 73 - ----------------------------------------------------------------------------------- -9. Compound or nonstandard callsign answering CQ ----------------------------------------------------------------------------------- -CQ W9XYZ EN37 - YW18FIFA - W9XYZ -11 - W9XYZ R-09 -YW18FIFA RRR - YW18FIFA 73 ----------------------------------------------------------------------------------- - - -RELEASE SCHEDULE: Candidate releases of WSJT-X 2.0 will have built-in -expiration dates after which they cannot be used. Target dates for -planned releases are as follows: - -September 17: -rc1 (expires Oct 31) -October 15: -rc2 (expires Nov 30) -November 12: -rc3 (expires Dec 31) -December 10: GA Full release of WSJT-X 2.0 - -WSJT-X 2.0-rc1 provides the first chance for beta testers to use the -new 77-bit messages. It supports the old (v1.9.1) FT8 protocol as -well as the new message types illustrated above. To avoid QRMing -legacy FT8 users with incompatible messages they can't decode, and to -help concentrate testing activity into a few sub-bands, we recommend -using the new FT8 capabilities on the 40- or 20-meter bands at dial -frequencies 7.078 or 14.078 MHz. These frequencies are offered as FT8 -alternatives on the drop-down frequency-selection control on the main -window. - -The new MSK144 is fully functional for QSOs between any two stations -using a WSJT-X v2.0 release. MSK144 is not backward compatible with -earlier program versions. Therefore during the testing period, -approximately Sept 17 through December 10, we recommend using the new -MSK144 capabilities on 50.380 MHz (IARU Region 1) or 50.280 (Regions 2 -and 3). By specific arrangement, or as soon as most regular users -have upgraded to a v2.0 release, MSK144 activity can be moved back to -50.360 (Region 1) or 50.260 (Regions 2 and 3). - -By design, our proposed release schedule will make WSJT-X 2.0 usable -for all relevant ARRL operating events and Eurpoean VHF contests after -January 1, 2019. - -Dates of relevant upcoming ARRL contests ----------------------------------------- -RTTY Roundup: January 5-6, 2019 -VHF Sweepstakes: January 19-21, 2019 + New Features in WSJT-X 2.0 + September 17, 2018 + -------------------------- + +This document is an update to the white paper "Plans for WSJT-X +Version 2.0" that was publicly distributed on July 26, 2018. It +describes the most important enhancements in WSJT-X 2.0 relative to +version 1.9.1. + +A majority of new program features involve the FT8 and MSK144 +protocols. Both modes have been upgraded to use use 77-bit +information payloads rather than the 75 bits of the older FT8 protocol +or 72 bits of JT4, JT9, JT65, MSK144, and QRA64. Cyclic redundancy +checks (CRCs) that protect against false decodes have been increased +from 12 to 14 bits (FT8) and from 8 to 13 bits (MSK144). These +changes bring many benefits, including support of structured messages +optimized for the following special types of QSOs and exchanged +information: + +1. NA VHF Contest operation with full and transparent support of grid + locators and "/R" (Rover) callsigns + +2. EU VHF Contest operation with the exchange of 6-digit locators, QSO + serial numbers, and "/P" (portable) callsigns + +3. ARRL Field Day operation with standard Field Day exchanges such as + "6A SNJ" + +4. ARRL RTTY Roundup operation with standard contest exchanges such as + "579 NJ" or "559 0071" + +5. Compound and nonstandard callsigns (up tp 11 characters); no need + for distinctions about "Type 1" or "Type 2" prefixes/suffixes + +6. A special "telemetry" message format for exchange of arbitrary + information up to 71 bits + +7. All features of FT8 DXpedition mode, as in WSJT-X v1.9.1 + +Conveying more information in the same bandwidth, using the same +modulation scheme, necessarily means a higher code rate and less +energy per information bit. Nevertheless, the decoding threshold S/N +for the new FT8 is slightly lower than for the old version, because of +improvements in the decoding algorithm. Decoding threshold for MSK144 +is a fraction of a dB higher than before. Symbol rates and occupied +bandwidths for both modes are the same as before, and false-decode +rates are significantly lower. + +OTHER PROGRAM ENHANCEMENTS: WSJT-X 2.0 has several other new features +and capabilities. The WSPR decoder has significantly better +sensitivity, by about 1 dB. Color highlighting of decoded messages +provides worked-before status for callsigns, grid locators, and DXCC +entities on a "by band" basis. Color highlighting can also identify +stations that have (or have not) uploaded their logs to "Logbook of +the World" (LoTW) within the past year. (Recent information from LoTW +for this purpose can be downloaded from the ARRL web site.) + +WSJT-X 2.0 introduces no significant changes to any of the modes JT4, +JT9, JT65, QRA64, ISCAT, Echo, or FreqCal. + +IMPORTANT: For the convenience of beta-testers, the first and second +release candidates -- releases with "-rc1" or "-rc2" in their names -- +will have Rx and Tx capability for both the new FT8 protocol and the +older one. Starting with the third release candidate ("-rc3"), and in +the general-availability full release of WSJT-X 2.0, only the new +protocol will be supported. In contrast, the new MSK144 protocol +replaces the old one from the outset, without backward compatibility. +To minimize on-the-air confusion, it's important that users be aware +of these distinctions and the schedule for release of WSJT-X 2.0, as +detailed below. + +MESSAGE FORMATS: The following table shows examples of message formats +supported by the new FT8 and MSK144 protocols. Parameters i3 and n3 +(shown in the first column) are used in the software to define major +and minor 77-bit message types. + +---------------------------------------------------------------------------------- +i3.n3 Example Messages Comments +---------------------------------------------------------------------------------- + 0.0 TNX BOB 73 GL Free text + 0.1 K1ABC RR73; W9XYZ -08 DXpedition Mode + 0.2 PA9XYZ 590003 IO91NP EU VHF Contest + 0.2 G4ABC/P R 570007 JO22DB EU VHF Contest + 0.3 K1ABC W9XYZ 6A WI ARRL Field Day + 0.3 W9XYZ K1ABC R 2B EMA ARRL Field Day + 0.5 123456789ABCDEF012 Telemetry (71 bits, 18 hex digits) + 1. CQ FD K1ABC FN42 ARRL Field Day + 1. CQ RU K1ABC FN42 ARRL RTTY Roundup + 1. CQ K1ABC FN42 + 1. CQ TEST K1ABC FN42 NA VHF Contest + 1. CQ TEST K1ABC/R FN42 NA VHF Contest + 1. K1ABC W9XYZ EN37 + 1. K1ABC W9XYZ -09 + 1. K1ABC W9XYZ R-17 + 1. K1ABC W9XYZ RRR + 1. K1ABC W9XYZ 73 + 1. K1ABC W9XYZ RR73 + 1. K1ABC/R W9XYZ EN37 NA VHF Contest + 1. K1ABC W9XYZ/R RR73 NA VHF Contest + 1. K1ABC/R W9XYZ/R RR73 NA VHF Contest + 1. W9XYZ Compound call + 1. W9XYZ 73 Compound call + 1. W9XYZ -13 Nonstandard call + 1. W9XYZ R+02 Nonstandard call + 1. W9XYZ RRR Nonstandard call + 1. W9XYZ RR73 Nonstandard call + 2. CQ G4ABC/P IO91 EU VHF contest + 2. G4ABC/P PA9XYZ JO22 EU VHF contest + 2. PA9XYZ G4ABC/P RR73 EU VHF contest + 3. K1ABC KA0DEF 559 MO ARRL RTTY Roundup + 3. K1ABC W9XYZ 579 WI ARRL RTTY Roundup + 3. KA1ABC G3AAA 529 0013 ARRL RTTY Roundup + 3. TU; KA0DEF K1ABC R 569 MA ARRL RTTY Roundup + 3. TU; K1ABC G3AAA R 559 0194 ARRL RTTY Roundup + 3. W9XYZ K1ABC R 589 MA ARRL RTTY Roundup + 4. CQ PJ4/K1ABC + 4. CQ YW18FIFA Nonstandard call + 4. YW18FIFA RR73 Nonstandard call + 4. PJ4/K1ABC RRR Nonstandard call + 4. YW18FIFA Nonstandard call + 4. YW18FIFA 73 Nonstandard call + 4. PJ4/K1ABC Nonstandard call + 4. PJ4/K1ABC 73 Nonstandard call + 4. YW18FIFA RRR Nonstandard call +---------------------------------------------------------------------------------- + +In the above list, callsigns enclosed in angle brackets (e.g., +, ) are transmitted as hash codes. They will be +displayed correctly by receiving stations that have copied the full +callsign without brackets in a previous transmissiion. Otherwise the +receiving software will display <...>. Hash collisions are possible +but should be rare, and extremely rare within a particular QSO. + +Some minimal message sequences that take advantage of the new 77-bit +formats are illustrated below. Model QSOs 1 and 2 are the same as +those used by the old FT8 and MSK144 protocols, and QSO number 3 is +the same as the existing FT8 DXpedition Mode. Model QSOs 4 through 9 +were not possible with the old protocols. + +---------------------------------------------------------------------------------- +1. Standard QSO +---------------------------------------------------------------------------------- +CQ K1ABC FN42 + K1ABC W9XYZ EN37 +W9XYZ K1ABC -11 + K1ABC W9XYZ R-09 +W9XYZ K1ABC RRR + K1ABC W9XYZ 73 + +---------------------------------------------------------------------------------- +2. Short-cycle QSO +---------------------------------------------------------------------------------- +CQ K1ABC FN42 + K1ABC W9XYZ -09 +W9XYZ K1ABC R-11 + K1ABC W9XYZ RR73 +W9XYZ K1ABC 73 + +---------------------------------------------------------------------------------- +3. FT8 DXpedition Mode +---------------------------------------------------------------------------------- +CQ KH1/KH7Z + KH7Z K1ABC FN42 +K1ABC KH7Z -12 + KH7Z K1ABC R-14 + KH7Z W9XYZ EN37 + ... possibly other callers ... +K1ABC RR73; W9XYZ -08 + +---------------------------------------------------------------------------------- +4. ARRL Field Day +---------------------------------------------------------------------------------- +CQ FD K1ABC FN42 + K1ABC W9XYZ 6A WI +W9XYZ K1ABC R 2B EMA + K1ABC W9XYZ RR73 + +---------------------------------------------------------------------------------- +5. ARRL VHF Contests +---------------------------------------------------------------------------------- +CQ TEST K1ABC/R FN42 "/R" is optional + K1ABC/R W9XYZ EN37 on either callsign +W9XYZ K1ABC/R R FN42 + K1ABC/R W9XYZ RR73 + +---------------------------------------------------------------------------------- +6. ARRL RTTY Roundup +---------------------------------------------------------------------------------- +CQ TEST K1ABC FN42 + K1ABC W9XYZ 579 WI +W9XYZ K1ABC R 589 MA + K1ABC KA0DEF 559 MO +TU; KA0DEF K1ABC R 569 MA + KA1ABC G3AAA 529 0013 +TU; G3AAA K1ABC R 559 MA + +---------------------------------------------------------------------------------- +7. EU VHF Contest +---------------------------------------------------------------------------------- +CQ TEST G4ABC/P IO91 "/P" is optional + G4ABC/P PA9XYZ JO22 on either callsign +PA9XYZ 590003 IO91NP + G4ABC/P R 570007 JO22DB +PA9XYZ G4ABC/P RR73 + +---------------------------------------------------------------------------------- +8. Compound or nonstandard callsign calling CQ +---------------------------------------------------------------------------------- +CQ PJ4/K1ABC + PJ4/K1ABC +W9XYZ -11 + W9XYZ R-09 + PJ4/K1ABC RRR + PJ4/K1ABC 73 + +---------------------------------------------------------------------------------- +9. Compound or nonstandard callsign answering CQ +---------------------------------------------------------------------------------- +CQ W9XYZ EN37 + YW18FIFA + W9XYZ -11 + W9XYZ R-09 +YW18FIFA RRR + YW18FIFA 73 +---------------------------------------------------------------------------------- + + +RELEASE SCHEDULE: Candidate releases of WSJT-X 2.0 will have built-in +expiration dates after which they cannot be used. Target dates for +planned releases are as follows: + +September 17: -rc1 (expires Oct 31) +October 15: -rc2 (expires Nov 30) +November 12: -rc3 (expires Dec 31) +December 10: GA Full release of WSJT-X 2.0 + +WSJT-X 2.0-rc1 provides the first chance for beta testers to use the +new 77-bit messages. It supports the old (v1.9.1) FT8 protocol as +well as the new message types illustrated above. To avoid QRMing +legacy FT8 users with incompatible messages they can't decode, and to +help concentrate testing activity into a few sub-bands, we recommend +using the new FT8 capabilities on the 40- or 20-meter bands at dial +frequencies 7.078 or 14.078 MHz. These frequencies are offered as FT8 +alternatives on the drop-down frequency-selection control on the main +window. + +The new MSK144 is fully functional for QSOs between any two stations +using a WSJT-X v2.0 release. MSK144 is not backward compatible with +earlier program versions. Therefore during the testing period, +approximately Sept 17 through December 10, we recommend using the new +MSK144 capabilities on 50.380 MHz (IARU Region 1) or 50.280 (Regions 2 +and 3). By specific arrangement, or as soon as most regular users +have upgraded to a v2.0 release, MSK144 activity can be moved back to +50.360 (Region 1) or 50.260 (Regions 2 and 3). + +By design, our proposed release schedule will make WSJT-X 2.0 usable +for all relevant ARRL operating events and Eurpoean VHF contests after +January 1, 2019. + +Dates of relevant upcoming ARRL contests +---------------------------------------- +RTTY Roundup: January 5-6, 2019 +VHF Sweepstakes: January 19-21, 2019 diff --git a/lib/77bit/all28.txt b/lib/77bit/all28.txt index 651e7af0..2a6e2781 100755 --- a/lib/77bit/all28.txt +++ b/lib/77bit/all28.txt @@ -1,40 +1,40 @@ - - -5B1ABC -999ABC -9Y4AB -9Y4XYZ -A00A -A0A -A0AA -A0AAA -A0AAB -AA0AAA -CQ -CQ_000 -CQ_313 -CQ_999 -CQ_A -CQ_AAAA -CQ_AB -CQ_ABC -CQ_ABCD -CQ_DX -CQ_ZZZZ -DE -EI30T -HA70BAY -HB9GOLD -K1ABC -K1JT -KA0ABC -KA1ABC -KA1JT -KH1/KH7Z -QRZ -W2000XYZ -WB9XYZ -YB50ST -YW18FIFA -ZM90DX -ZS9YOTA + + +5B1ABC +999ABC +9Y4AB +9Y4XYZ +A00A +A0A +A0AA +A0AAA +A0AAB +AA0AAA +CQ +CQ_000 +CQ_313 +CQ_999 +CQ_A +CQ_AAAA +CQ_AB +CQ_ABC +CQ_ABCD +CQ_DX +CQ_ZZZZ +DE +EI30T +HA70BAY +HB9GOLD +K1ABC +K1JT +KA0ABC +KA1ABC +KA1JT +KH1/KH7Z +QRZ +W2000XYZ +WB9XYZ +YB50ST +YW18FIFA +ZM90DX +ZS9YOTA diff --git a/lib/77bit/arrl_sec.txt b/lib/77bit/arrl_sec.txt index a6b295a3..b97b64f4 100755 --- a/lib/77bit/arrl_sec.txt +++ b/lib/77bit/arrl_sec.txt @@ -1,83 +1,83 @@ -AB -AK -AL -AR -AZ -BC -CO -CT -DE -EB -EMA -ENY -EPA -EWA -GA -GTA -IA -ID -IL -IN -KS -KY -LA -LAX -MAR -MB -MDC -ME -MI -MN -MO -MS -MT -NC -ND -NE -NFL -NH -NL -NLI -NM -NNJ -NNY -NT -NTX -NV -OH -OK -ONE -ONN -ONS -OR -ORG -PAC -PR -QC -RI -SB -SC -SCV -SD -SDG -SF -SFL -SJV -SK -SNJ -STX -SV -TN -UT -VA -VI -VT -WCF -WI -WMA -WNY -WPA -WTX -WV -WWA -WY +AB +AK +AL +AR +AZ +BC +CO +CT +DE +EB +EMA +ENY +EPA +EWA +GA +GTA +IA +ID +IL +IN +KS +KY +LA +LAX +MAR +MB +MDC +ME +MI +MN +MO +MS +MT +NC +ND +NE +NFL +NH +NL +NLI +NM +NNJ +NNY +NT +NTX +NV +OH +OK +ONE +ONN +ONS +OR +ORG +PAC +PR +QC +RI +SB +SC +SCV +SD +SDG +SF +SFL +SJV +SK +SNJ +STX +SV +TN +UT +VA +VI +VT +WCF +WI +WMA +WNY +WPA +WTX +WV +WWA +WY diff --git a/lib/77bit/call_to_c28.f90 b/lib/77bit/call_to_c28.f90 index b10251fa..96930c57 100755 --- a/lib/77bit/call_to_c28.f90 +++ b/lib/77bit/call_to_c28.f90 @@ -1,21 +1,21 @@ -program call_to_c28 - parameter (NTOKENS=2063592,MAX22=4194304) - character*6 call_std - character a1*37,a2*36,a3*10,a4*27 - data a1/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ - data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ - data a3/'0123456789'/ - data a4/' ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ - ! call_std must be right adjusted, length 6 - call_std=' K1ABC' !Redefine as needed - i1=index(a1,call_std(1:1))-1 - i2=index(a2,call_std(2:2))-1 - i3=index(a3,call_std(3:3))-1 - i4=index(a4,call_std(4:4))-1 - i5=index(a4,call_std(5:5))-1 - i6=index(a4,call_std(6:6))-1 - n28=NTOKENS + MAX22 + 36*10*27*27*27*i1 + 10*27*27*27*i2 + & - 27*27*27*i3 + 27*27*i4 + 27*i5 + i6 - write(*,1000) call_std,n28 -1000 format('Callsign: ',a6,2x,'c28 as decimal integer:',i10) -end program call_to_c28 +program call_to_c28 + parameter (NTOKENS=2063592,MAX22=4194304) + character*6 call_std + character a1*37,a2*36,a3*10,a4*27 + data a1/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ + data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ + data a3/'0123456789'/ + data a4/' ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ + ! call_std must be right adjusted, length 6 + call_std=' K1ABC' !Redefine as needed + i1=index(a1,call_std(1:1))-1 + i2=index(a2,call_std(2:2))-1 + i3=index(a3,call_std(3:3))-1 + i4=index(a4,call_std(4:4))-1 + i5=index(a4,call_std(5:5))-1 + i6=index(a4,call_std(6:6))-1 + n28=NTOKENS + MAX22 + 36*10*27*27*27*i1 + 10*27*27*27*i2 + & + 27*27*27*i3 + 27*27*i4 + 27*i5 + i6 + write(*,1000) call_std,n28 +1000 format('Callsign: ',a6,2x,'c28 as decimal integer:',i10) +end program call_to_c28 diff --git a/lib/77bit/calls.txt b/lib/77bit/calls.txt index c119cf0b..c542c9b6 100755 --- a/lib/77bit/calls.txt +++ b/lib/77bit/calls.txt @@ -1,5 +1,5 @@ -KA1ABC -WB9XYZ -KH1/KH7Z - -CQ DX K1ABC +KA1ABC +WB9XYZ +KH1/KH7Z + +CQ DX K1ABC diff --git a/lib/77bit/calls1.txt b/lib/77bit/calls1.txt index 0613de2e..888b4555 100755 --- a/lib/77bit/calls1.txt +++ b/lib/77bit/calls1.txt @@ -1,21 +1,21 @@ - - -K1ABC -WB9XYZ -KA1ABC -WB9XYZ -K1JT -KA1JT -5B1ABC -9Y4XYZ -9Y4AB -999ABC -ZM90DX -EI30T -ZS9YOTA -HA70BAY -HB9GOLD -YW18FIFA -YB50ST -WB2000XYZ -WB2000XYZABCD + + +K1ABC +WB9XYZ +KA1ABC +WB9XYZ +K1JT +KA1JT +5B1ABC +9Y4XYZ +9Y4AB +999ABC +ZM90DX +EI30T +ZS9YOTA +HA70BAY +HB9GOLD +YW18FIFA +YB50ST +WB2000XYZ +WB2000XYZABCD diff --git a/lib/77bit/calls2.txt b/lib/77bit/calls2.txt index c642498b..b1f48774 100755 --- a/lib/77bit/calls2.txt +++ b/lib/77bit/calls2.txt @@ -1,7 +1,7 @@ -A0A -A00A -A0AA -A0AAA -KA0ABC -5B1ABC -9Y4XYZ +A0A +A00A +A0AA +A0AAA +KA0ABC +5B1ABC +9Y4XYZ diff --git a/lib/77bit/calls3.txt b/lib/77bit/calls3.txt index 01a122ca..69a81bb9 100755 --- a/lib/77bit/calls3.txt +++ b/lib/77bit/calls3.txt @@ -1,4 +1,4 @@ -AA0AAA -A0AAA -A0AAB -A0AA +AA0AAA +A0AAA +A0AAB +A0AA diff --git a/lib/77bit/encode77.f90 b/lib/77bit/encode77.f90 index bfd97cd5..99af70cd 100755 --- a/lib/77bit/encode77.f90 +++ b/lib/77bit/encode77.f90 @@ -1,60 +1,60 @@ -program encode77 - - use packjt77 - - character*80 msg0 - character msg*37,cerr*1 - character*77 c77 - character*80 infile - character*13 w(19) - integer nw(19) - logical unpk77_success - - nargs=iargc() - if(nargs.ne.1 .and.nargs.ne.2) then - print*,'Usage: encode77 "message"' - print*,' encode77 -f ' - go to 999 - endif - call getarg(1,msg0) - call fmtmsg(msg0,iz) - if(nargs.eq.2) then - call getarg(2,infile) - open(10,file=infile,status='old') - write(*,1000) -1000 format('i3.n3 Err Message to be encoded Decoded message' & - /80('-')) - endif - - do iline=1,999 - if(nargs.eq.2) read(10,1002,end=999) msg0 -1002 format(a80) - if(msg0(1:1).eq.'$') exit - if(msg0.eq.' ') cycle - if(msg0(2:2).eq.'.' .or. msg0(3:3).eq.'.') cycle - if(msg0(1:3).eq.'---') cycle - msg0=adjustl(msg0) - i3=-1 - n3=-1 - call pack77(msg0(1:37),i3,n3,c77) - call unpack77(c77,1,msg,unpk77_success) - cerr=' ' - if(msg.ne.msg0(1:37)) cerr='*' - if(i3.eq.0 .and.n3.ne.6) write(*,1004) i3,n3,cerr,msg0(1:37),msg -1004 format(i2,'.',i1,4x,a1,1x,a37,1x,a37) - if(i3.eq.0 .and.n3.eq.6) then - call split77(msg,nwords,nw,w) - j2=0 - if(nwords.eq.2 .and. len(trim(w(2))).le.2) j2=1 - if(nwords.eq.2 .and. len(trim(w(2))).eq.6) j2=2 - write(*,1005) i3,n3,j2,cerr,msg0(1:37),msg -1005 format(i2,'.',i1,'.',i1,2x,a1,1x,a37,1x,a37) - endif - if(i3.ge.1) write(*,1006) i3,cerr,msg0(1:37),msg -1006 format(i2,'.',5x,a1,1x,a37,1x,a37) - if(nargs.eq.1) exit - enddo - -999 end program encode77 - -include '../chkcall.f90' +program encode77 + + use packjt77 + + character*80 msg0 + character msg*37,cerr*1 + character*77 c77 + character*80 infile + character*13 w(19) + integer nw(19) + logical unpk77_success + + nargs=iargc() + if(nargs.ne.1 .and.nargs.ne.2) then + print*,'Usage: encode77 "message"' + print*,' encode77 -f ' + go to 999 + endif + call getarg(1,msg0) + call fmtmsg(msg0,iz) + if(nargs.eq.2) then + call getarg(2,infile) + open(10,file=infile,status='old') + write(*,1000) +1000 format('i3.n3 Err Message to be encoded Decoded message' & + /80('-')) + endif + + do iline=1,999 + if(nargs.eq.2) read(10,1002,end=999) msg0 +1002 format(a80) + if(msg0(1:1).eq.'$') exit + if(msg0.eq.' ') cycle + if(msg0(2:2).eq.'.' .or. msg0(3:3).eq.'.') cycle + if(msg0(1:3).eq.'---') cycle + msg0=adjustl(msg0) + i3=-1 + n3=-1 + call pack77(msg0(1:37),i3,n3,c77) + call unpack77(c77,1,msg,unpk77_success) + cerr=' ' + if(msg.ne.msg0(1:37)) cerr='*' + if(i3.eq.0 .and.n3.ne.6) write(*,1004) i3,n3,cerr,msg0(1:37),msg +1004 format(i2,'.',i1,4x,a1,1x,a37,1x,a37) + if(i3.eq.0 .and.n3.eq.6) then + call split77(msg,nwords,nw,w) + j2=0 + if(nwords.eq.2 .and. len(trim(w(2))).le.2) j2=1 + if(nwords.eq.2 .and. len(trim(w(2))).eq.6) j2=2 + write(*,1005) i3,n3,j2,cerr,msg0(1:37),msg +1005 format(i2,'.',i1,'.',i1,2x,a1,1x,a37,1x,a37) + endif + if(i3.ge.1) write(*,1006) i3,cerr,msg0(1:37),msg +1006 format(i2,'.',5x,a1,1x,a37,1x,a37) + if(nargs.eq.1) exit + enddo + +999 end program encode77 + +include '../chkcall.f90' diff --git a/lib/77bit/encode77.out b/lib/77bit/encode77.out index 651adde7..2d0f7d4c 100755 --- a/lib/77bit/encode77.out +++ b/lib/77bit/encode77.out @@ -1,41 +1,41 @@ -i3.n3 Err Message to be encoded Decoded message --------------------------------------------------------------------------------- - 1. CQ K1ABC FN42 CQ K1ABC FN42 - 1. K1ABC W9XYZ EN37 K1ABC W9XYZ EN37 - 1. W9XYZ K1ABC -11 W9XYZ K1ABC -11 - 1. K1ABC W9XYZ R-09 K1ABC W9XYZ R-09 - 1. W9XYZ K1ABC RRR W9XYZ K1ABC RRR - 1. K1ABC W9XYZ 73 K1ABC W9XYZ 73 - 1. CQ K1ABC FN42 CQ K1ABC FN42 - 1. K1ABC W9XYZ -09 K1ABC W9XYZ -09 - 1. W9XYZ K1ABC R-11 W9XYZ K1ABC R-11 - 1. K1ABC W9XYZ RR73 K1ABC W9XYZ RR73 - 1. W9XYZ K1ABC 73 W9XYZ K1ABC 73 - 4. CQ KH1/KH7Z CQ KH1/KH7Z - 1. KH7Z K1ABC FN42 KH7Z K1ABC FN42 - 1. K1ABC KH7Z -12 K1ABC KH7Z -12 - 1. KH7Z K1ABC R-14 KH7Z K1ABC R-14 - 0.1 K1ABC RR73; W9XYZ -08 K1ABC RR73; W9XYZ -08 - 1. CQ FD K1ABC FN42 CQ FD K1ABC FN42 - 0.3 K1ABC W9XYZ 6A WI K1ABC W9XYZ 6A WI - 0.3 W9XYZ K1ABC R 2B EMA W9XYZ K1ABC R 2B EMA - 1. K1ABC W9XYZ RR73 K1ABC W9XYZ RR73 - 1. CQ TEST K1ABC/R FN42 CQ TEST K1ABC/R FN42 - 1. K1ABC/R W9XYZ EN37 K1ABC/R W9XYZ EN37 - 1. W9XYZ K1ABC/R R FN42 W9XYZ K1ABC/R R FN42 - 1. K1ABC/R W9XYZ RR73 K1ABC/R W9XYZ RR73 - 1. CQ TEST K1ABC FN42 CQ TEST K1ABC FN42 - 3. K1ABC W9XYZ 579 WI K1ABC W9XYZ 579 WI - 3. W9XYZ K1ABC R 589 MA W9XYZ K1ABC R 589 MA - 1. K1ABC W9XYZ RR73 K1ABC W9XYZ RR73 - 2. CQ G4ABC/P IO91 CQ G4ABC/P IO91 - 2. G4ABC/P PA9XYZ JO22 G4ABC/P PA9XYZ JO22 - 0.2 PA9XYZ 590003 IO91NP PA9XYZ 590003 IO91NP - 0.2 G4ABC/P R 570007 JO22DB G4ABC/P R 570007 JO22DB - 2. PA9XYZ G4ABC/P RR73 PA9XYZ G4ABC/P RR73 - 4. CQ PJ4/K1ABC CQ PJ4/K1ABC - 4. W9XYZ W9XYZ - 1. W9XYZ K1ABC -11 W9XYZ K1ABC -11 - 1. K1ABC W9XYZ R-09 K1ABC W9XYZ R-09 - 4. W9XYZ RRR W9XYZ RRR - 4. W9XYZ 73 W9XYZ 73 +i3.n3 Err Message to be encoded Decoded message +-------------------------------------------------------------------------------- + 1. CQ K1ABC FN42 CQ K1ABC FN42 + 1. K1ABC W9XYZ EN37 K1ABC W9XYZ EN37 + 1. W9XYZ K1ABC -11 W9XYZ K1ABC -11 + 1. K1ABC W9XYZ R-09 K1ABC W9XYZ R-09 + 1. W9XYZ K1ABC RRR W9XYZ K1ABC RRR + 1. K1ABC W9XYZ 73 K1ABC W9XYZ 73 + 1. CQ K1ABC FN42 CQ K1ABC FN42 + 1. K1ABC W9XYZ -09 K1ABC W9XYZ -09 + 1. W9XYZ K1ABC R-11 W9XYZ K1ABC R-11 + 1. K1ABC W9XYZ RR73 K1ABC W9XYZ RR73 + 1. W9XYZ K1ABC 73 W9XYZ K1ABC 73 + 4. CQ KH1/KH7Z CQ KH1/KH7Z + 1. KH7Z K1ABC FN42 KH7Z K1ABC FN42 + 1. K1ABC KH7Z -12 K1ABC KH7Z -12 + 1. KH7Z K1ABC R-14 KH7Z K1ABC R-14 + 0.1 K1ABC RR73; W9XYZ -08 K1ABC RR73; W9XYZ -08 + 1. CQ FD K1ABC FN42 CQ FD K1ABC FN42 + 0.3 K1ABC W9XYZ 6A WI K1ABC W9XYZ 6A WI + 0.3 W9XYZ K1ABC R 2B EMA W9XYZ K1ABC R 2B EMA + 1. K1ABC W9XYZ RR73 K1ABC W9XYZ RR73 + 1. CQ TEST K1ABC/R FN42 CQ TEST K1ABC/R FN42 + 1. K1ABC/R W9XYZ EN37 K1ABC/R W9XYZ EN37 + 1. W9XYZ K1ABC/R R FN42 W9XYZ K1ABC/R R FN42 + 1. K1ABC/R W9XYZ RR73 K1ABC/R W9XYZ RR73 + 1. CQ TEST K1ABC FN42 CQ TEST K1ABC FN42 + 3. K1ABC W9XYZ 579 WI K1ABC W9XYZ 579 WI + 3. W9XYZ K1ABC R 589 MA W9XYZ K1ABC R 589 MA + 1. K1ABC W9XYZ RR73 K1ABC W9XYZ RR73 + 2. CQ G4ABC/P IO91 CQ G4ABC/P IO91 + 2. G4ABC/P PA9XYZ JO22 G4ABC/P PA9XYZ JO22 + 0.2 PA9XYZ 590003 IO91NP PA9XYZ 590003 IO91NP + 0.2 G4ABC/P R 570007 JO22DB G4ABC/P R 570007 JO22DB + 2. PA9XYZ G4ABC/P RR73 PA9XYZ G4ABC/P RR73 + 4. CQ PJ4/K1ABC CQ PJ4/K1ABC + 4. W9XYZ W9XYZ + 1. W9XYZ K1ABC -11 W9XYZ K1ABC -11 + 1. K1ABC W9XYZ R-09 K1ABC W9XYZ R-09 + 4. W9XYZ RRR W9XYZ RRR + 4. W9XYZ 73 W9XYZ 73 diff --git a/lib/77bit/free_text.f90 b/lib/77bit/free_text.f90 index 5f222f37..c7e66823 100755 --- a/lib/77bit/free_text.f90 +++ b/lib/77bit/free_text.f90 @@ -1,58 +1,58 @@ -program free_text - character*13 c13,w - character*71 f71 - character*42 c - character*1 qa(10),qb(10) - data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/ - c13='TNX BOB 73 GL' !Redefine as needed - call mp_short_init - qa=char(0) - w=adjustr(c13) - do i=1,13 - j=index(c,w(i:i))-1 - if(j.lt.0) j=0 - call mp_short_mult(qb,qa(2:10),9,42) !qb(1:9)=42*qa(2:9) - call mp_short_add(qa,qb(2:10),9,j) !qa(1:9)=qb(2:9)+j - enddo - write(f71,1000) qa(2:10) -1000 format(b7.7,8b8.8) - write(*,1010) c13,f71 -1010 format('Free text: ',a13/'f71: ',a71) -end program free_text - -subroutine mp_short_ops(w,u) -! Multi-precision arithmetic with storage in character arrays. - character*1 w(*),u(*) - integer i,ireg,j,n,ir,iv,ii1,ii2 - character*1 creg(4) - save ii1,ii2 - equivalence (ireg,creg) - - entry mp_short_init - ireg=256*ichar('2')+ichar('1') - do j=1,4 - if (creg(j).eq.'1') ii1=j - if (creg(j).eq.'2') ii2=j - enddo - return - - entry mp_short_add(w,u,n,iv) - ireg=256*iv - do j=n,1,-1 - ireg=ichar(u(j))+ichar(creg(ii2)) - w(j+1)=creg(ii1) - enddo - w(1)=creg(ii2) - return - - entry mp_short_mult(w,u,n,iv) - ireg=0 - do j=n,1,-1 - ireg=ichar(u(j))*iv+ichar(creg(ii2)) - w(j+1)=creg(ii1) - enddo - w(1)=creg(ii2) - return - - return -end subroutine mp_short_ops +program free_text + character*13 c13,w + character*71 f71 + character*42 c + character*1 qa(10),qb(10) + data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/ + c13='TNX BOB 73 GL' !Redefine as needed + call mp_short_init + qa=char(0) + w=adjustr(c13) + do i=1,13 + j=index(c,w(i:i))-1 + if(j.lt.0) j=0 + call mp_short_mult(qb,qa(2:10),9,42) !qb(1:9)=42*qa(2:9) + call mp_short_add(qa,qb(2:10),9,j) !qa(1:9)=qb(2:9)+j + enddo + write(f71,1000) qa(2:10) +1000 format(b7.7,8b8.8) + write(*,1010) c13,f71 +1010 format('Free text: ',a13/'f71: ',a71) +end program free_text + +subroutine mp_short_ops(w,u) +! Multi-precision arithmetic with storage in character arrays. + character*1 w(*),u(*) + integer i,ireg,j,n,ir,iv,ii1,ii2 + character*1 creg(4) + save ii1,ii2 + equivalence (ireg,creg) + + entry mp_short_init + ireg=256*ichar('2')+ichar('1') + do j=1,4 + if (creg(j).eq.'1') ii1=j + if (creg(j).eq.'2') ii2=j + enddo + return + + entry mp_short_add(w,u,n,iv) + ireg=256*iv + do j=n,1,-1 + ireg=ichar(u(j))+ichar(creg(ii2)) + w(j+1)=creg(ii1) + enddo + w(1)=creg(ii2) + return + + entry mp_short_mult(w,u,n,iv) + ireg=0 + do j=n,1,-1 + ireg=ichar(u(j))*iv+ichar(creg(ii2)) + w(j+1)=creg(ii1) + enddo + w(1)=creg(ii2) + return + + return +end subroutine mp_short_ops diff --git a/lib/77bit/g2 b/lib/77bit/g2 index 0c34ab2e..9c19b3a2 100755 --- a/lib/77bit/g2 +++ b/lib/77bit/g2 @@ -1,6 +1,6 @@ -gfortran -c ../packjt.f90 -gfortran -c packjt77.f90 -gfortran -o encode77 -fbounds-check -Wall -Wno-conversion \ - encode77.f90 ../deg2grid.f90 ../grid2deg.f90 ../fix_contest_msg.f90 \ - ../to_contest_msg.f90 ../fmtmsg.f90 ../azdist.f90 ../geodist.f90 \ - packjt.o packjt77.o +gfortran -c ../packjt.f90 +gfortran -c packjt77.f90 +gfortran -o encode77 -fbounds-check -Wall -Wno-conversion \ + encode77.f90 ../deg2grid.f90 ../grid2deg.f90 ../fix_contest_msg.f90 \ + ../to_contest_msg.f90 ../fmtmsg.f90 ../azdist.f90 ../geodist.f90 \ + packjt.o packjt77.o diff --git a/lib/77bit/g8 b/lib/77bit/g8 index c91f843a..33819134 100755 --- a/lib/77bit/g8 +++ b/lib/77bit/g8 @@ -1,3 +1,3 @@ -gfortran -c packjt77.f90 -gfortran -o test28 -fbounds-check -Wall -Wno-conversion test28.f90 \ - ../chkcall.f90 packjt77.o +gfortran -c packjt77.f90 +gfortran -o test28 -fbounds-check -Wall -Wno-conversion test28.f90 \ + ../chkcall.f90 packjt77.o diff --git a/lib/77bit/hash22calc.f90 b/lib/77bit/hash22calc.f90 index 46581a98..500e1eea 100755 --- a/lib/77bit/hash22calc.f90 +++ b/lib/77bit/hash22calc.f90 @@ -1,42 +1,42 @@ -program hash22calc -! Given a valid callsign, calculate and print its 22-bit hash. - - use packjt77 - - character*13 callsign - character*1 c - character*6 basecall - logical cok - - nargs=iargc() - if(nargs.ne.1) then - print*,'Given a valid callsign, print its 22-bit hash.' - print*,'Usage: hash22calc ' - print*,' e.g. hash22calc W9ABC' - go to 999 - endif - call getarg(1,callsign) - -! convert to upper case - ilen=len(trim(callsign)) - do i=1, ilen - c=callsign(i:i) - if(c.ge.'a' .and. c.le.'z') c=char(ichar(c)-32) !Force upper case - callsign(i:i)=c - enddo - -! check for a valid callsign - call chkcall(callsign,basecall,cok) - if(.not.cok) then - print*,'Invalid callsign' - print*,'Usage: hash22calc ' - goto 999 - endif - -! calculate the hash - n22 = ihashcall(callsign,22) - write(*,'(a,i7.7)') callsign,n22 - -999 end program hash22calc - -include '../chkcall.f90' +program hash22calc +! Given a valid callsign, calculate and print its 22-bit hash. + + use packjt77 + + character*13 callsign + character*1 c + character*6 basecall + logical cok + + nargs=iargc() + if(nargs.ne.1) then + print*,'Given a valid callsign, print its 22-bit hash.' + print*,'Usage: hash22calc ' + print*,' e.g. hash22calc W9ABC' + go to 999 + endif + call getarg(1,callsign) + +! convert to upper case + ilen=len(trim(callsign)) + do i=1, ilen + c=callsign(i:i) + if(c.ge.'a' .and. c.le.'z') c=char(ichar(c)-32) !Force upper case + callsign(i:i)=c + enddo + +! check for a valid callsign + call chkcall(callsign,basecall,cok) + if(.not.cok) then + print*,'Invalid callsign' + print*,'Usage: hash22calc ' + goto 999 + endif + +! calculate the hash + n22 = ihashcall(callsign,22) + write(*,'(a,i7.7)') callsign,n22 + +999 end program hash22calc + +include '../chkcall.f90' diff --git a/lib/77bit/messages.txt b/lib/77bit/messages.txt index aa036bec..d84bba2c 100755 --- a/lib/77bit/messages.txt +++ b/lib/77bit/messages.txt @@ -1,100 +1,100 @@ -1. Standard QSO ------------------------------------------------------------ -CQ K1ABC FN42 - K1ABC W9XYZ EN37 -W9XYZ K1ABC -11 - K1ABC W9XYZ R-09 -W9XYZ K1ABC RRR - K1ABC W9XYZ 73 - -2. Short-cycle QSO ------------------------------------------------------------ -CQ K1ABC FN42 - K1ABC W9XYZ -09 -W9XYZ K1ABC R-11 - K1ABC W9XYZ RR73 -W9XYZ K1ABC 73 - -3. FT8 DXpedition Mode ------------------------------------------------------------ -CQ KH1/KH7Z - KH7Z K1ABC FN42 -K1ABC KH7Z -12 - KH7Z K1ABC R-14 -K1ABC RR73; W9XYZ -08 - -4. ARRL Field Day ------------------------------------------------------------ -CQ FD K1ABC FN42 - K1ABC W9XYZ 6A WI -W9XYZ K1ABC R 2B EMA - K1ABC W9XYZ RR73 - -5. ARRL VHF Contests ------------------------------------------------------------ -CQ TEST K1ABC/R FN42 - K1ABC/R W9XYZ EN37 -W9XYZ K1ABC/R R FN42 - K1ABC/R W9XYZ RR73 - -6. ARRL RTTY Contest ------------------------------------------------------------ -CQ TEST K1ABC FN42 - K1ABC W9XYZ 579 WI -W9XYZ K1ABC R 589 MA - K1ABC KA0DEF 559 MO -TU; KA0DEF K1ABC R 569 MA - KA1ABC G3AAA 529 0013 -TU; G3AAA K1ABC R 559 MA - -7. EU VHF Contest ------------------------------------------------------------ -CQ G4ABC/P IO91 - G4ABC/P PA9XYZ JO22 - 590003 IO91NP - R 570007 JO22DB -PA9XYZ G4ABC/P RR73 - -8. Compound or nonstandard calls CQ ------------------------------------------------------------ -CQ PJ4/K1ABC - PJ4/K1ABC -W9XYZ -11 - W9XYZ R-09 - PJ4/K1ABC RRR - PJ4/K1ABC 73 - -9. Compound or nonstandard answers CQ ------------------------------------------------------------ -CQ W9XYZ EN37 - YW18FIFA - W9XYZ -11 - W9XYZ R-09 -YW18FIFA RRR - YW18FIFA 73 - -10. Other stuff ------------------------------------------------------------ -TNX BOB 73 GL -CQ YW18FIFA - KA1ABC -KA1ABC -11 - KA1ABC R-17 - YW18FIFA RR73 - KA1ABC 73 -123456789ABCDEF012 -K1ABC FN42 37 -PJ4/K1ABC 37 -K1ABC/VE3 37 -KA1ABC/VEX 37 - FK52UD - FK52UD - 590001 FN20QI - 590001 FN20QI - 590001 FN20QI - 590001 FN20QI - 590001 FN20QI -CQ OE21FTDMC -K9AN K1JT R- -K9AN K1JT R+ -K1AN K1JT WXY +1. Standard QSO +----------------------------------------------------------- +CQ K1ABC FN42 + K1ABC W9XYZ EN37 +W9XYZ K1ABC -11 + K1ABC W9XYZ R-09 +W9XYZ K1ABC RRR + K1ABC W9XYZ 73 + +2. Short-cycle QSO +----------------------------------------------------------- +CQ K1ABC FN42 + K1ABC W9XYZ -09 +W9XYZ K1ABC R-11 + K1ABC W9XYZ RR73 +W9XYZ K1ABC 73 + +3. FT8 DXpedition Mode +----------------------------------------------------------- +CQ KH1/KH7Z + KH7Z K1ABC FN42 +K1ABC KH7Z -12 + KH7Z K1ABC R-14 +K1ABC RR73; W9XYZ -08 + +4. ARRL Field Day +----------------------------------------------------------- +CQ FD K1ABC FN42 + K1ABC W9XYZ 6A WI +W9XYZ K1ABC R 2B EMA + K1ABC W9XYZ RR73 + +5. ARRL VHF Contests +----------------------------------------------------------- +CQ TEST K1ABC/R FN42 + K1ABC/R W9XYZ EN37 +W9XYZ K1ABC/R R FN42 + K1ABC/R W9XYZ RR73 + +6. ARRL RTTY Contest +----------------------------------------------------------- +CQ TEST K1ABC FN42 + K1ABC W9XYZ 579 WI +W9XYZ K1ABC R 589 MA + K1ABC KA0DEF 559 MO +TU; KA0DEF K1ABC R 569 MA + KA1ABC G3AAA 529 0013 +TU; G3AAA K1ABC R 559 MA + +7. EU VHF Contest +----------------------------------------------------------- +CQ G4ABC/P IO91 + G4ABC/P PA9XYZ JO22 + 590003 IO91NP + R 570007 JO22DB +PA9XYZ G4ABC/P RR73 + +8. Compound or nonstandard calls CQ +----------------------------------------------------------- +CQ PJ4/K1ABC + PJ4/K1ABC +W9XYZ -11 + W9XYZ R-09 + PJ4/K1ABC RRR + PJ4/K1ABC 73 + +9. Compound or nonstandard answers CQ +----------------------------------------------------------- +CQ W9XYZ EN37 + YW18FIFA + W9XYZ -11 + W9XYZ R-09 +YW18FIFA RRR + YW18FIFA 73 + +10. Other stuff +----------------------------------------------------------- +TNX BOB 73 GL +CQ YW18FIFA + KA1ABC +KA1ABC -11 + KA1ABC R-17 + YW18FIFA RR73 + KA1ABC 73 +123456789ABCDEF012 +K1ABC FN42 37 +PJ4/K1ABC 37 +K1ABC/VE3 37 +KA1ABC/VEX 37 + FK52UD + FK52UD + 590001 FN20QI + 590001 FN20QI + 590001 FN20QI + 590001 FN20QI + 590001 FN20QI +CQ OE21FTDMC +K9AN K1JT R- +K9AN K1JT R+ +K1AN K1JT WXY diff --git a/lib/77bit/messages_2.txt b/lib/77bit/messages_2.txt index f55c9b33..38399e69 100755 --- a/lib/77bit/messages_2.txt +++ b/lib/77bit/messages_2.txt @@ -1,49 +1,49 @@ -FREE TEXT MSG 71 0 71 -CQ YW18FIFA -K1ABC RR73; W9XYZ -12 28 28 10 5 1 71 DXpedition Mode -PA3XYZ/P R 590003 IO91NP 28 1 1 3 12 25 2 70 EU VHF contest (2) -PA3XYZ 520093 IO91NP 28 1 1 3 12 25 2 70 EU VHF contest (2) -WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 3 71 ARRL Field Day -WA9XYZ KA1ABC 7D EMA 28 28 1 4 3 7 3 71 ARRL Field Day -WA9XYZ G8ABC 1D DX 28 28 1 4 3 7 3 71 ARRL Field Day -WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 4 71 ARRL Field Day -123456789ABCDEF012 71 71 Telemetry (18 hex) -71234567 71 71 Telemetry (18 hex) -81234567 71 71 Telemetry (18 hex) -7123456789ABCDEF01 71 71 Telemetry (18 hex) -8123456789ABCDEF01 71 71 Telemetry (18 hex) -WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg -WA9XYZ KA1ABC R-19 28 1 28 1 1 15 74 Standard msg -WA9XYZ KA1ABC +03 28 1 28 1 1 15 74 Standard msg -WA9XYZ KA1ABC -30 28 1 28 1 1 15 74 Standard msg -WA9XYZ KA1ABC +30 28 1 28 1 1 15 74 Standard msg -CQ K1ABC FN42 -DE K1ABC FN42 -QRZ K1ABC FN42 -CQ AA K1ABC FN42 -CQ ZZ K1ABC FN42 -CQ 000 K1ABC FN42 -CQ 313 K1ABC FN42 -CQ 999 K1ABC FN42 -CQ AAA K1ABC FN42 -CQ ZZZ K1ABC FN42 -CQ AAAA K1ABC FN42 -CQ ZZZZ K1ABC FN42 -CQ KH1/KH7Z -CQ YW18FIFA -CQ W4/YW18FIFA -PA1XYZ/P GM4ABC/P R FN42 28 1 28 1 1 15 74 EU VHF Contest -TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest -TU; W9XYZ G8ABC R 559 0013 1 28 28 1 3 13 74 ARRL RTTY (DX) -W9XYZ K1ABC 519 MA 1 28 28 1 3 13 74 ARRL RTTY contest -W9XYZ K1ABC 529 MA 1 28 28 1 3 13 74 ARRL RTTY contest -W9XYZ K1ABC 599 MA 1 28 28 1 3 13 74 ARRL RTTY contest -W9XYZ K1ABC 599 SNJ 1 28 28 1 3 13 74 ARRL RTTY contest -W9XYZ G8ABC 529 0013 1 28 28 1 3 13 74 ARRL RTTY (DX) -W9XYZ G8ABC 599 0013 1 28 28 1 3 13 74 ARRL RTTY (DX) - PJ4/KA1ABC 13 58 1 2 74 Nonstandard call -PJ4/KA1ABC RRR 13 58 1 2 74 Nonstandard call - PJ4/KA1ABC RR73 13 58 1 2 74 Nonstandard call -PJ4/KA1ABC 73 13 58 1 2 74 Nonstandard call - PJ4/KA1ABC 73 13 58 1 2 74 Nonstandard call -CQ 313 YW18FIFA +FREE TEXT MSG 71 0 71 +CQ YW18FIFA +K1ABC RR73; W9XYZ -12 28 28 10 5 1 71 DXpedition Mode +PA3XYZ/P R 590003 IO91NP 28 1 1 3 12 25 2 70 EU VHF contest (2) +PA3XYZ 520093 IO91NP 28 1 1 3 12 25 2 70 EU VHF contest (2) +WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 3 71 ARRL Field Day +WA9XYZ KA1ABC 7D EMA 28 28 1 4 3 7 3 71 ARRL Field Day +WA9XYZ G8ABC 1D DX 28 28 1 4 3 7 3 71 ARRL Field Day +WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 4 71 ARRL Field Day +123456789ABCDEF012 71 71 Telemetry (18 hex) +71234567 71 71 Telemetry (18 hex) +81234567 71 71 Telemetry (18 hex) +7123456789ABCDEF01 71 71 Telemetry (18 hex) +8123456789ABCDEF01 71 71 Telemetry (18 hex) +WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg +WA9XYZ KA1ABC R-19 28 1 28 1 1 15 74 Standard msg +WA9XYZ KA1ABC +03 28 1 28 1 1 15 74 Standard msg +WA9XYZ KA1ABC -30 28 1 28 1 1 15 74 Standard msg +WA9XYZ KA1ABC +30 28 1 28 1 1 15 74 Standard msg +CQ K1ABC FN42 +DE K1ABC FN42 +QRZ K1ABC FN42 +CQ AA K1ABC FN42 +CQ ZZ K1ABC FN42 +CQ 000 K1ABC FN42 +CQ 313 K1ABC FN42 +CQ 999 K1ABC FN42 +CQ AAA K1ABC FN42 +CQ ZZZ K1ABC FN42 +CQ AAAA K1ABC FN42 +CQ ZZZZ K1ABC FN42 +CQ KH1/KH7Z +CQ YW18FIFA +CQ W4/YW18FIFA +PA1XYZ/P GM4ABC/P R FN42 28 1 28 1 1 15 74 EU VHF Contest +TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest +TU; W9XYZ G8ABC R 559 0013 1 28 28 1 3 13 74 ARRL RTTY (DX) +W9XYZ K1ABC 519 MA 1 28 28 1 3 13 74 ARRL RTTY contest +W9XYZ K1ABC 529 MA 1 28 28 1 3 13 74 ARRL RTTY contest +W9XYZ K1ABC 599 MA 1 28 28 1 3 13 74 ARRL RTTY contest +W9XYZ K1ABC 599 SNJ 1 28 28 1 3 13 74 ARRL RTTY contest +W9XYZ G8ABC 529 0013 1 28 28 1 3 13 74 ARRL RTTY (DX) +W9XYZ G8ABC 599 0013 1 28 28 1 3 13 74 ARRL RTTY (DX) + PJ4/KA1ABC 13 58 1 2 74 Nonstandard call +PJ4/KA1ABC RRR 13 58 1 2 74 Nonstandard call + PJ4/KA1ABC RR73 13 58 1 2 74 Nonstandard call +PJ4/KA1ABC 73 13 58 1 2 74 Nonstandard call + PJ4/KA1ABC 73 13 58 1 2 74 Nonstandard call +CQ 313 YW18FIFA diff --git a/lib/77bit/msgtypes.txt b/lib/77bit/msgtypes.txt index 77633ee9..0cb0044f 100755 --- a/lib/77bit/msgtypes.txt +++ b/lib/77bit/msgtypes.txt @@ -1,23 +1,23 @@ -i3 n3 Bits Total Message type ---------------------------------------------------------------------------------------- -0 0 FREE TEXT MSG 71 71 -0 1 K1ABC RR73; W9XYZ -12 28 28 10 5 71 DXpedition Mode -0 2 PA3XYZ/P R 590003 IO91NP 28 1 1 3 12 25 70 EU VHF contest (2) -0 2 PA3XYZ 520093 IO91NP 28 1 1 3 12 25 70 EU VHF contest (2) -0 3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day -0 3 WA9XYZ KA1ABC 7D EMA 28 28 1 4 3 7 71 ARRL Field Day -0 3 WA9XYZ G8ABC 1D DX 28 28 1 4 3 7 71 ARRL Field Day -0 4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day -0 5 123456789ABCDEF012 71 71 Telemetry (18 hex) -0 5 7123456789ABCDEF01 71 71 Telemetry (18 hex) -0 5 71234567 71 71 Telemetry (18 hex) -0 5 81234567 71 71 Telemetry (18 hex) -0 5 8123456789ABCDEF01 71 71 Telemetry (18 hex) -1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg -1 WA9XYZ KA1ABC R-11 28 1 28 1 1 15 74 Standard msg -2 PA1XYZ/P GM4ABC/P R FN42 28 1 28 1 1 15 74 EU VHF Contest -3 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest -3 TU; W9XYZ G8ABC R 559 0013 1 28 28 1 3 13 74 ARRL RTTY (DX) -4 PJ4/KA1ABC RR73 13 58 1 2 74 Nonstandard call -4 PJ4/KA1ABC 13 58 1 2 74 Nonstandard call -4 PJ4/KA1ABC RRR 13 58 1 2 74 Nonstandard call +i3 n3 Bits Total Message type +--------------------------------------------------------------------------------------- +0 0 FREE TEXT MSG 71 71 +0 1 K1ABC RR73; W9XYZ -12 28 28 10 5 71 DXpedition Mode +0 2 PA3XYZ/P R 590003 IO91NP 28 1 1 3 12 25 70 EU VHF contest (2) +0 2 PA3XYZ 520093 IO91NP 28 1 1 3 12 25 70 EU VHF contest (2) +0 3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day +0 3 WA9XYZ KA1ABC 7D EMA 28 28 1 4 3 7 71 ARRL Field Day +0 3 WA9XYZ G8ABC 1D DX 28 28 1 4 3 7 71 ARRL Field Day +0 4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day +0 5 123456789ABCDEF012 71 71 Telemetry (18 hex) +0 5 7123456789ABCDEF01 71 71 Telemetry (18 hex) +0 5 71234567 71 71 Telemetry (18 hex) +0 5 81234567 71 71 Telemetry (18 hex) +0 5 8123456789ABCDEF01 71 71 Telemetry (18 hex) +1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg +1 WA9XYZ KA1ABC R-11 28 1 28 1 1 15 74 Standard msg +2 PA1XYZ/P GM4ABC/P R FN42 28 1 28 1 1 15 74 EU VHF Contest +3 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest +3 TU; W9XYZ G8ABC R 559 0013 1 28 28 1 3 13 74 ARRL RTTY (DX) +4 PJ4/KA1ABC RR73 13 58 1 2 74 Nonstandard call +4 PJ4/KA1ABC 13 58 1 2 74 Nonstandard call +4 PJ4/KA1ABC RRR 13 58 1 2 74 Nonstandard call diff --git a/lib/77bit/msgtypes.txt.0 b/lib/77bit/msgtypes.txt.0 index 3a2b968e..a1ab61f6 100755 --- a/lib/77bit/msgtypes.txt.0 +++ b/lib/77bit/msgtypes.txt.0 @@ -1,23 +1,23 @@ -i3 n3 --------------------------------------------------------------------------------------- -0 0 FREE TEXT MSG 71 0 71 -0 1 K1ABC RR73; W9XYZ -11 28 28 10 5 1 71 DXpedition Mode -0 2 PA3XYZ/P R 590003 IO91NP 28 1 1 3 12 25 2 70 EU VHF contest (2) -0 3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 3 71 ARRL Field Day -0 4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 4 71 ARRL Field Day -1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg -2 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest -3 PJ4/KA1ABC R-11 13 53 1 1 6 74 Nonstandard calls -4 PA3XYZ/P GM4ABC/P R IO91 28 1 28 1 1 15 74 EU VHF contest - -0 0 HELLO WORLD 1 -0 0 hello world 2 - -0 1 K1ABC RR73; W9XYZ -11 -0 2 PA3XYZ 590003 IO91NP -0 3 WA9XYZ KA1ABC 16A EMA -0 4 WA9XYZ KA1ABC 32A EMA -1 WA9XYZ/R KA1ABC/R R FN42 -2 W9XYZ K1ABC 579 MA -3 PJ4/KA1ABC -11 -4 PA3XYZ/P GM4ABC/P R IO91 +i3 n3 +-------------------------------------------------------------------------------------- +0 0 FREE TEXT MSG 71 0 71 +0 1 K1ABC RR73; W9XYZ -11 28 28 10 5 1 71 DXpedition Mode +0 2 PA3XYZ/P R 590003 IO91NP 28 1 1 3 12 25 2 70 EU VHF contest (2) +0 3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 3 71 ARRL Field Day +0 4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 4 71 ARRL Field Day +1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg +2 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest +3 PJ4/KA1ABC R-11 13 53 1 1 6 74 Nonstandard calls +4 PA3XYZ/P GM4ABC/P R IO91 28 1 28 1 1 15 74 EU VHF contest + +0 0 HELLO WORLD 1 +0 0 hello world 2 + +0 1 K1ABC RR73; W9XYZ -11 +0 2 PA3XYZ 590003 IO91NP +0 3 WA9XYZ KA1ABC 16A EMA +0 4 WA9XYZ KA1ABC 32A EMA +1 WA9XYZ/R KA1ABC/R R FN42 +2 W9XYZ K1ABC 579 MA +3 PJ4/KA1ABC -11 +4 PA3XYZ/P GM4ABC/P R IO91 diff --git a/lib/77bit/my_hash.f90 b/lib/77bit/my_hash.f90 index 8562d987..4e1a6c6c 100755 --- a/lib/77bit/my_hash.f90 +++ b/lib/77bit/my_hash.f90 @@ -1,11 +1,11 @@ -subroutine my_hash(mycall) - - use packjt77 - character*(*) mycall - character*13 c13 - - c13=mycall//' ' - call save_hash_call(c13,n10,n12,n22) - - return -end subroutine my_hash +subroutine my_hash(mycall) + + use packjt77 + character*(*) mycall + character*13 c13 + + c13=mycall//' ' + call save_hash_call(c13,n10,n12,n22) + + return +end subroutine my_hash diff --git a/lib/77bit/nonstd_to_c58.f90 b/lib/77bit/nonstd_to_c58.f90 index 431c3a97..09190423 100755 --- a/lib/77bit/nonstd_to_c58.f90 +++ b/lib/77bit/nonstd_to_c58.f90 @@ -1,13 +1,13 @@ -program nonstd_to_c58 - integer*8 n58 - character*11 call_nonstd - character*38 c - data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ - call_nonstd='PJ4/K1ABC' !Redifine as needed - n58=0 - do i=1,11 - n58=n58*38 + index(c,call_nonstd(i:i)) - 1 - enddo - write(*,1000) call_nonstd,n58 -1000 format('Callsign: ',a11,2x,'c58 as decimal integer:',i20) -end program nonstd_to_c58 +program nonstd_to_c58 + integer*8 n58 + character*11 call_nonstd + character*38 c + data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ + call_nonstd='PJ4/K1ABC' !Redifine as needed + n58=0 + do i=1,11 + n58=n58*38 + index(c,call_nonstd(i:i)) - 1 + enddo + write(*,1000) call_nonstd,n58 +1000 format('Callsign: ',a11,2x,'c58 as decimal integer:',i20) +end program nonstd_to_c58 diff --git a/lib/77bit/packjt77.f90 b/lib/77bit/packjt77.f90 index dc03072a..47cd3b6b 100755 --- a/lib/77bit/packjt77.f90 +++ b/lib/77bit/packjt77.f90 @@ -1,1645 +1,1645 @@ -module packjt77 - -! These variables are accessible from outside via "use packjt77": - parameter (MAXHASH=1000,MAXRECENT=10) - character (len=13), dimension(0:1023) :: calls10='' - character (len=13), dimension(0:4095) :: calls12='' - character (len=13), dimension(1:MAXHASH) :: calls22='' - character (len=13), dimension(1:MAXRECENT) :: recent_calls='' - character (len=13) :: mycall13='' - character (len=13) :: dxcall13='' - character (len=6) :: dxbase='' - integer, dimension(1:MAXHASH) :: ihash22=-1 - integer :: nzhash=0 - integer n28a,n28b - - contains - -subroutine hash10(n10,c13) - - character*13 c13 - - c13='<...>' - if(n10.lt.0 .or. n10.gt.1023) return - if(len(trim(calls10(n10))).gt.0) then - c13=calls10(n10) - c13='<'//trim(c13)//'>' - endif - return - -end subroutine hash10 - -subroutine hash12(n12,c13) - - character*13 c13 - - c13='<...>' - if(n12.lt.0 .or. n12.gt.4095) return - if(len(trim(calls12(n12))).gt.0) then - c13=calls12(n12) - c13='<'//trim(c13)//'>' - endif - return - -end subroutine hash12 - - -subroutine hash22(n22,c13) - - character*13 c13 - - c13='<...>' - do i=1,nzhash - if(ihash22(i).eq.n22) then - c13=calls22(i) - c13='<'//trim(c13)//'>' - go to 900 - endif - enddo - -900 return -end subroutine hash22 - - -integer function ihashcall(c0,m) - - integer*8 n8 - character*13 c0 - character*38 c - data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ - - n8=0 - do i=1,11 - j=index(c,c0(i:i)) - 1 - n8=38*n8 + j - enddo - ihashcall=ishft(47055833459_8*n8,m-64) - - return -end function ihashcall - -subroutine save_hash_call(c13,n10,n12,n22) - - character*13 c13,cw - - cw=c13 - if(cw(1:1).eq.' ' .or. cw(1:5).eq.'<...>') return - if(cw(1:1).eq.'<') cw=cw(2:) - i=index(cw,'>') - if(i.gt.0) cw(i:)=' ' - - if(len(trim(cw)) .lt. 3) return - - n10=ihashcall(cw,10) - if(n10.ge.0 .and. n10 .le. 1023 .and. cw.ne.mycall13) calls10(n10)=cw - - n12=ihashcall(cw,12) - if(n12.ge.0 .and. n12 .le. 4095 .and. cw.ne.mycall13) calls12(n12)=cw - - n22=ihashcall(cw,22) - if(any(ihash22.eq.n22)) then ! If entry exists, make sure callsign is the most recently received one - where(ihash22.eq.n22) calls22=cw - go to 900 - endif - -! New entry: move table down, making room for new one at the top - ihash22(MAXHASH:2:-1)=ihash22(MAXHASH-1:1:-1) - -! Add the new entry - calls22(MAXHASH:2:-1)=calls22(MAXHASH-1:1:-1) - ihash22(1)=n22 - calls22(1)=cw - if(nzhash.lt.MAXHASH) nzhash=nzhash+1 -900 continue - return -end subroutine save_hash_call - -subroutine pack77(msg0,i3,n3,c77) - - use packjt - character*37 msg,msg0 - character*18 c18 - character*13 w(19) - character*77 c77 - integer nw(19) - integer ntel(3) - - msg=msg0 - if(msg(1:3).eq.'$DX') then - i1=index(msg,' ') - msg=trim(dxbase)//' '//msg(i1+1:) - endif - - i3_hint=i3 - n3_hint=n3 - i3=-1 - n3=-1 - if(i3_hint.eq.0 .and. n3_hint.eq.5) go to 5 - -! Convert msg to upper case; collapse multiple blanks; parse into words. - call split77(msg,nwords,nw,w) - if(msg(1:3).eq.'CQ ' .or. msg(1:3).eq.'DE ' .or. msg(1:4).eq.'QRZ ') go to 100 - -! Check 0.1 (DXpedition mode) - call pack77_01(nwords,w,i3,n3,c77) - if(i3.ge.0 .or. n3.ge.1) go to 900 -! Check 0.2 (EU VHF contest exchange) -! call pack77_02(nwords,w,i3,n3,c77) -! if(i3.ge.0) go to 900 - -! Check 0.3 and 0.4 (ARRL Field Day exchange) - call pack77_03(nwords,w,i3,n3,c77) - if(i3.ge.0) go to 900 - if(nwords.ge.2) go to 100 - - ! Check 0.5 (telemetry) -5 i0=index(msg,' ') - c18=msg(1:i0-1) - c18=adjustr(c18) - ntel=-99 - read(c18,1005,err=6) ntel -1005 format(3z6) - if(ntel(1).ge.2**23) go to 800 -6 if(ntel(1).ge.0 .and. ntel(2).ge.0 .and. ntel(3).ge.0) then - i3=0 - n3=5 - write(c77,1006) ntel,n3,i3 -1006 format(b23.23,2b24.24,2b3.3) - go to 900 - endif - -100 call pack77_06(nwords,w,i3,n3,c77,i3_hint,n3_hint) - if(i3.ge.0) go to 900 - -! Check Type 1 (Standard 77-bit message) or Type 2, with optional "/P" - call pack77_1(nwords,w,i3,n3,c77) - if(i3.ge.0) go to 900 - -! Check Type 3 (ARRL RTTY contest exchange) - call pack77_3(nwords,w,i3,n3,c77) - if(i3.ge.0) go to 900 - -! Check Type 4 (One nonstandard call and one hashed call) - call pack77_4(nwords,w,i3,n3,c77) - if(i3.ge.0) go to 900 - -! Check Type 5 (EU VHF Contest with 2 hashed calls, report, serial, and grid6) - call pack77_5(nwords,w,i3,n3,c77) - if(i3.ge.0) go to 900 - -! It defaults to free text -800 i3=0 - n3=0 - msg(14:)=' ' - call packtext77(msg(1:13),c77(1:71)) - write(c77(72:77),'(2b3.3)') n3,i3 - -900 return -end subroutine pack77 - -subroutine unpack77(c77,nrx,msg,unpk77_success) -! -! nrx=1 when unpacking a received message -! nrx=0 when unpacking a to-be-transmitted message -! the value of nrx is used to decide when mycall13 or dxcall13 should -! be used in place of a callsign from the hashtable -! - parameter (NSEC=86) !Number of ARRL Sections - parameter (NUSCAN=171) !Number of States and Provinces - parameter (MAXGRID4=32400) - integer*8 n58 - integer ntel(3) - character*77 c77 - character*37 msg - character*13 call_1,call_2,call_3,call_1a - character*13 mycall13_0,dxcall13_0 - character*11 c11 - character*3 crpt,cntx,cpfx - character*3 cmult(NUSCAN) - character*6 cexch,grid6 - character*4 grid4,cserial - character*3 csec(NSEC) - character*38 c - character*36 a2 - integer hashmy10,hashmy12,hashmy22,hashdx10,hashdx12,hashdx22 - logical unpk28_success,unpk77_success,unpkg4_success - logical dxcall13_set,mycall13_set - - data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/,nzzz/46656/ - data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ - data csec/ & - "AB ","AK ","AL ","AR ","AZ ","BC ","CO ","CT ","DE ","EB ", & - "EMA","ENY","EPA","EWA","GA ","GH ","IA ","ID ","IL ","IN ", & - "KS ","KY ","LA ","LAX","NS ","MB ","MDC","ME ","MI ","MN ", & - "MO ","MS ","MT ","NC ","ND ","NE ","NFL","NH ","NL ","NLI", & - "NM ","NNJ","NNY","TER","NTX","NV ","OH ","OK ","ONE","ONN", & - "ONS","OR ","ORG","PAC","PR ","QC ","RI ","SB ","SC ","SCV", & - "SD ","SDG","SF ","SFL","SJV","SK ","SNJ","STX","SV ","TN ", & - "UT ","VA ","VI ","VT ","WCF","WI ","WMA","WNY","WPA","WTX", & - "WV ","WWA","WY ","DX ","PE ","NB "/ - data cmult/ & - "AL ","AK ","AZ ","AR ","CA ","CO ","CT ","DE ","FL ","GA ", & - "HI ","ID ","IL ","IN ","IA ","KS ","KY ","LA ","ME ","MD ", & - "MA ","MI ","MN ","MS ","MO ","MT ","NE ","NV ","NH ","NJ ", & - "NM ","NY ","NC ","ND ","OH ","OK ","OR ","PA ","RI ","SC ", & - "SD ","TN ","TX ","UT ","VT ","VA ","WA ","WV ","WI ","WY ", & - "NB ","NS ","QC ","ON ","MB ","SK ","AB ","BC ","NWT","NF ", & - "LB ","NU ","YT ","PEI","DC ","DR ","FR ","GD ","GR ","OV ", & - "ZH ","ZL ","X01","X02","X03","X04","X05","X06","X07","X08", & - "X09","X10","X11","X12","X13","X14","X15","X16","X17","X18", & - "X19","X20","X21","X22","X23","X24","X25","X26","X27","X28", & - "X29","X30","X31","X32","X33","X34","X35","X36","X37","X38", & - "X39","X40","X41","X42","X43","X44","X45","X46","X47","X48", & - "X49","X50","X51","X52","X53","X54","X55","X56","X57","X58", & - "X59","X60","X61","X62","X63","X64","X65","X66","X67","X68", & - "X69","X70","X71","X72","X73","X74","X75","X76","X77","X78", & - "X79","X80","X81","X82","X83","X84","X85","X86","X87","X88", & - "X89","X90","X91","X92","X93","X94","X95","X96","X97","X98", & - "X99"/ - data dxcall13_set/.false./ - data mycall13_set/.false./ - data mycall13_0/''/ - data dxcall13_0/''/ - - save hashmy10,hashmy12,hashmy22,hashdx10,hashdx12,hashdx22 - - if(mycall13.ne.mycall13_0) then - if(len(trim(mycall13)).gt.2) then - mycall13_set=.true. - mycall13_0=mycall13 - call save_hash_call(mycall13,hashmy10,hashmy12,hashmy22) - else - mycall13_set=.false. - endif - endif - - if(dxcall13.ne.dxcall13_0) then - if(len(trim(dxcall13)).gt.2) then - dxcall13_set=.true. - dxcall13_0=dxcall13 - hashdx10=ihashcall(dxcall13,10) - hashdx12=ihashcall(dxcall13,12) - hashdx22=ihashcall(dxcall13,22) - endif - endif - unpk77_success=.true. - -! Check for bad data - do i=1,77 - if(c77(i:i).ne.'0' .and. c77(i:i).ne.'1') then - msg='failed unpack' - unpk77_success=.false. - return - endif - enddo - - read(c77(72:77),'(2b3)') n3,i3 - msg=repeat(' ',37) - - if(i3.eq.0 .and. n3.eq.0) then -! 0.0 Free text - call unpacktext77(c77(1:71),msg(1:13)) - msg(14:)=' ' - msg=adjustl(msg) - if(msg(1:1).eq.' ') then - unpk77_success=.false. - return - endif - - else if(i3.eq.0 .and. n3.eq.1) then -! 0.1 K1ABC RR73; W9XYZ -11 28 28 10 5 71 DXpedition Mode - read(c77,1010) n28a,n28b,n10,n5 -1010 format(2b28,b10,b5) - irpt=2*n5 - 30 - write(crpt,1012) irpt -1012 format(i3.2) - if(irpt.ge.0) crpt(1:1)='+' - call unpack28(n28a,call_1,unpk28_success) - if(.not.unpk28_success .or. n28a.le.2) unpk77_success=.false. - call unpack28(n28b,call_2,unpk28_success) - if(.not.unpk28_success .or. n28b.le.2) unpk77_success=.false. - call hash10(n10,call_3) - if(nrx.eq.1 .and. & - dxcall13_set .and. & - hashdx10.eq.n10) call_3='<'//trim(dxcall13)//'>' - if(nrx.eq.0 .and. & - mycall13_set .and. & - n10.eq.hashmy10) call_3='<'//trim(mycall13)//'>' - msg=trim(call_1)//' RR73; '//trim(call_2)//' '//trim(call_3)//' '//crpt - - else if(i3.eq.0 .and. n3.eq.2) then - unpk77_success=.false. - - else if(i3.eq.0 .and. (n3.eq.3 .or. n3.eq.4)) then -! 0.3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day -! 0.4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day - read(c77,1030) n28a,n28b,ir,intx,nclass,isec -1030 format(2b28,b1,b4,b3,b7) - if(isec.gt.NSEC .or. isec.lt.1) then - unpk77_success=.false. - isec=1 - endif - call unpack28(n28a,call_1,unpk28_success) - if(.not.unpk28_success .or. n28a.le.2) unpk77_success=.false. - call unpack28(n28b,call_2,unpk28_success) - if(.not.unpk28_success .or. n28b.le.2) unpk77_success=.false. - ntx=intx+1 - if(n3.eq.4) ntx=ntx+16 - write(cntx(1:2),1032) ntx -1032 format(i2) - cntx(3:3)=char(ichar('A')+nclass) - if(ir.eq.0 .and. ntx.lt.10) msg=trim(call_1)//' '//trim(call_2)// & - cntx//' '//csec(isec) - if(ir.eq.1 .and. ntx.lt.10) msg=trim(call_1)//' '//trim(call_2)// & - ' R'//cntx//' '//csec(isec) - if(ir.eq.0 .and. ntx.ge.10) msg=trim(call_1)//' '//trim(call_2)// & - ' '//cntx//' '//csec(isec) - if(ir.eq.1 .and. ntx.ge.10) msg=trim(call_1)//' '//trim(call_2)// & - ' R '//cntx//' '//csec(isec) - - else if(i3.eq.0 .and. n3.eq.5) then -! 0.5 0123456789abcdef01 71 71 Telemetry (18 hex) - read(c77,1006) ntel -1006 format(b23,2b24) - write(msg,1007) ntel -1007 format(3z6.6) - do i=1,18 - if(msg(i:i).ne.'0') exit - msg(i:i)=' ' - enddo - msg=adjustl(msg) - - else if(i3.eq.0 .and. n3.eq.6) then - read(c77(48:50),'(3b1)') j48,j49,j50 -! bits 48:50 -! itype=1: x00 -! itype=2: xx1 -! itype=3: 010 - if(j50.eq.1) then - itype=2 - else if(j49.eq.0) then - itype=1 - else if(j48.eq.0) then - itype=3 - else - itype=-1 - unpk77_success=.false. - endif - - if(itype.eq.1) then -! WSPR Type 1 - read(c77,2010) n28,igrid4,idbm -2010 format(b28.28,b15.15,b5.5) - idbm=nint(idbm*10.0/3.0) - if(idbm.lt.0 .or. idbm.gt.60) unpk77_success=.false. - call unpack28(n28,call_1,unpk28_success) - if(.not.unpk28_success) unpk77_success=.false. - call to_grid4(igrid4,grid4,unpkg4_success) - if(.not.unpkg4_success) unpk77_success=.false. - write(crpt,'(i3)') idbm - msg=trim(call_1)//' '//grid4//' '//trim(adjustl(crpt)) - if (unpk77_success) call save_hash_call(call_1,n10,n12,n22) !### Is this OK here? ### - - else if(itype.eq.2) then -! WSPR Type 2 - read(c77,2020) n28,npfx,idbm -2020 format(b28.28,b16.16,b5.5) - idbm=nint(idbm*10.0/3.0) - if(idbm.lt.0 .or. idbm.gt.60) unpk77_success=.false. - call unpack28(n28,call_1,unpk28_success) - if(.not.unpk28_success) unpk77_success=.false. - write(crpt,'(i3)') idbm - cpfx=' ' - if(npfx.lt.nzzz) then -! Prefix - do i=3,1,-1 - j=mod(npfx,36)+1 - cpfx(i:i)=a2(j:j) - npfx=npfx/36 - if(npfx.eq.0) exit - enddo - msg=trim(adjustl(cpfx))//'/'//trim(call_1)//' '//trim(adjustl(crpt)) - call_1a=trim(adjustl(cpfx))//'/'//trim(call_1) - call save_hash_call(call_1a,n10,n12,n22) !### Is this OK here? ### - else -! Suffix - npfx=npfx-nzzz - if(npfx.le.35) then - cpfx(1:1)=a2(npfx+1:npfx+1) - else if(npfx.gt.35 .and. npfx.le.1295) then - cpfx(1:1)=a2(npfx/36+1:npfx/36+1) - cpfx(2:2)=a2(mod(npfx,36)+1:mod(npfx,36)+1) - else if(npfx.gt.1295 .and. npfx.le.12959) then - cpfx(1:1)=a2(npfx/360+1:npfx/360+1) - cpfx(2:2)=a2(mod(npfx/10,36)+1:mod(npfx/10,36)+1) - cpfx(3:3)=a2(mod(npfx,10)+1:mod(npfx,10)+1) - else - unpk77_success=.false. - return - endif - msg=trim(call_1)//'/'//trim(adjustl(cpfx))//' '//trim(adjustl(crpt)) - call_1a=trim(call_1)//'/'//trim(adjustl(cpfx)) - call save_hash_call(call_1a,n10,n12,n22) !### Is this OK here? ### - endif - - else if(itype.eq.3) then -! WSPR Type 3 - read(c77,2030) n22,igrid6 -2030 format(b22.22,b25.25) - n28=n22+2063592 - call unpack28(n28,call_1,unpk28_success) - if(.not.unpk28_success) unpk77_success=.false. - call to_grid(igrid6,grid6,unpkg4_success) - if(.not.unpkg4_success) unpk77_success=.false. - msg=trim(call_1)//' '//grid6 - endif - - else if(i3.eq.0 .and. n3.gt.6) then - unpk77_success=.false. - - else if(i3.eq.1 .or. i3.eq.2) then -! Type 1 (standard message) or Type 2 ("/P" form for EU VHF contest) - read(c77,1000) n28a,ipa,n28b,ipb,ir,igrid4,i3 -1000 format(2(b28,b1),b1,b15,b3) - call unpack28(n28a,call_1,unpk28_success) - if(nrx.eq.1 .and. mycall13_set .and. hashmy22.eq.(n28a-2063592)) then - call_1='<'//trim(mycall13)//'>' - unpk28_success=.true. - endif - if(.not.unpk28_success) unpk77_success=.false. - call unpack28(n28b,call_2,unpk28_success) - if(.not.unpk28_success) unpk77_success=.false. - if(call_1(1:3).eq.'CQ_') call_1(3:3)=' ' - if(index(call_1,'<').le.0) then - i=index(call_1,' ') - if(i.ge.4 .and. ipa.eq.1 .and. i3.eq.1) call_1(i:i+1)='/R' - if(i.ge.4 .and. ipa.eq.1 .and. i3.eq.2) call_1(i:i+1)='/P' - if(i.ge.4) call add_call_to_recent_calls(call_1) - endif - if(index(call_2,'<').le.0) then - i=index(call_2,' ') - if(i.ge.4 .and. ipb.eq.1 .and. i3.eq.1) call_2(i:i+1)='/R' - if(i.ge.4 .and. ipb.eq.1 .and. i3.eq.2) call_2(i:i+1)='/P' - if(i.ge.4) then - call add_call_to_recent_calls(call_2) -! only hash the "from" call - call save_hash_call(call_2,ndum10,ndum12,ndum22) - endif - endif - if(igrid4.le.MAXGRID4) then - call to_grid4(igrid4,grid4,unpkg4_success) - if(.not.unpkg4_success) unpk77_success=.false. - if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//grid4 - if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R '//grid4 - if(msg(1:3).eq.'CQ ' .and. ir.eq.1) unpk77_success=.false. - else - irpt=igrid4-MAXGRID4 - if(irpt.eq.1) msg=trim(call_1)//' '//trim(call_2) - if(irpt.eq.2) msg=trim(call_1)//' '//trim(call_2)//' RRR' - if(irpt.eq.3) msg=trim(call_1)//' '//trim(call_2)//' RR73' - if(irpt.eq.4) msg=trim(call_1)//' '//trim(call_2)//' 73' - if(irpt.ge.5) then - isnr=irpt-35 - if(isnr.gt.50) isnr=isnr-101 - write(crpt,'(i3.2)') isnr - if(crpt(1:1).eq.' ') crpt(1:1)='+' - if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//crpt - if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R'//crpt - endif - if(msg(1:3).eq.'CQ ' .and. irpt.ge.2) unpk77_success=.false. - endif - - else if(i3.eq.3) then -! Type 3: ARRL RTTY Contest - read(c77,1040) itu,n28a,n28b,ir,irpt,nexch,i3 -1040 format(b1,2b28.28,b1,b3.3,b13.13,b3.3) - write(crpt,1042) irpt+2 -1042 format('5',i1,'9') - nserial=nexch - imult=-1 - if(nexch.gt.8000) then - imult=nexch-8000 - nserial=-1 - endif - call unpack28(n28a,call_1,unpk28_success) - if(.not.unpk28_success) unpk77_success=.false. - call unpack28(n28b,call_2,unpk28_success) - if(.not.unpk28_success) unpk77_success=.false. - imult=0 - nserial=0 - if(nexch.gt.8000) imult=nexch-8000 - if(nexch.lt.8000) nserial=nexch - - if(imult.ge.1 .and.imult.le.NUSCAN) then - if(itu.eq.0 .and. ir.eq.0) msg=trim(call_1)//' '//trim(call_2)// & - ' '//crpt//' '//cmult(imult) - if(itu.eq.1 .and. ir.eq.0) msg='TU; '//trim(call_1)//' '//trim(call_2)// & - ' '//crpt//' '//cmult(imult) - if(itu.eq.0 .and. ir.eq.1) msg=trim(call_1)//' '//trim(call_2)// & - ' R '//crpt//' '//cmult(imult) - if(itu.eq.1 .and. ir.eq.1) msg='TU; '//trim(call_1)//' '//trim(call_2)// & - ' R '//crpt//' '//cmult(imult) - else if(nserial.ge.1 .and. nserial.le.7999) then - write(cserial,'(i4.4)') nserial - if(itu.eq.0 .and. ir.eq.0) msg=trim(call_1)//' '//trim(call_2)// & - ' '//crpt//' '//cserial - if(itu.eq.1 .and. ir.eq.0) msg='TU; '//trim(call_1)//' '//trim(call_2)// & - ' '//crpt//' '//cserial - if(itu.eq.0 .and. ir.eq.1) msg=trim(call_1)//' '//trim(call_2)// & - ' R '//crpt//' '//cserial - if(itu.eq.1 .and. ir.eq.1) msg='TU; '//trim(call_1)//' '//trim(call_2)// & - ' R '//crpt//' '//cserial - endif - else if(i3.eq.4) then -! Type 4 - read(c77,1050) n12,n58,iflip,nrpt,icq -1050 format(b12,b58,b1,b2,b1) - do i=11,1,-1 - j=mod(n58,38)+1 - c11(i:i)=c(j:j) - n58=n58/38 - enddo - call hash12(n12,call_3) - if(iflip.eq.0) then ! 12 bit hash for TO call - call_1=call_3 - call_2=adjustl(c11)//' ' - call add_call_to_recent_calls(call_2) - call save_hash_call(call_2,ndum10,ndum12,ndum22) - if(nrx.eq.1 .and. & - dxcall13_set .and. mycall13_set .and. & - call_2.eq.dxcall13 .and. & - n12.eq.hashmy12 ) call_1='<'//trim(mycall13)//'>' - if(nrx.eq.1 .and. & - mycall13_set .and. & - index(call_1,'<...>').gt.0 .and. & - n12.eq.hashmy12 ) call_1='<'//trim(mycall13)//'>' - else ! 12 bit hash for DE call - call_1=adjustl(c11) - call_2=call_3 - call add_call_to_recent_calls(call_1) - if(nrx.eq.0 .and. & - mycall13_set .and. & - n12.eq.hashmy12) call_2='<'//trim(mycall13)//'>' - endif - if(icq.eq.0) then - if(nrpt.eq.0) msg=trim(call_1)//' '//trim(call_2) - if(nrpt.eq.1) msg=trim(call_1)//' '//trim(call_2)//' RRR' - if(nrpt.eq.2) msg=trim(call_1)//' '//trim(call_2)//' RR73' - if(nrpt.eq.3) msg=trim(call_1)//' '//trim(call_2)//' 73' - else - msg='CQ '//trim(call_2) - endif - - else if(i3.eq.5) then - -! Type 5 R 590003 IO91NP h12 h22 r1 s3 S11 g25 -! EU VHF contest - read(c77,1060) n12,n22,ir,irpt,iserial,igrid6 -1060 format(b12,b22,b1,b3,b11,b25) - if(igrid6.lt.0 .or. igrid6.gt.18662399) then - unpk77_success=.false. - return - endif - call hash12(n12,call_1) - if(n12.eq.hashmy12) call_1='<'//trim(mycall13)//'>' - call hash22(n22,call_2) - nrs=52+irpt - write(cexch,1022) nrs,iserial -1022 format(i2,i4.4) - call to_grid6(igrid6,grid6,unpk77_success) - if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//cexch//' '//grid6 - if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R '//cexch//' '//grid6 - - else if(i3.ge.6) then ! i3 values 6 and 7 are not yet defined - unpk77_success=.false. - endif - if(msg(1:4).eq.'CQ <') unpk77_success=.false. - - return -end subroutine unpack77 - -subroutine pack28(c13,n28) - -! Pack a special token, a 22-bit hash code, or a valid base call into a 28-bit -! integer. - - parameter (NTOKENS=2063592,MAX22=4194304) - logical is_digit,is_letter - character*13 c13 - character*6 callsign - character*1 c - character*4 c4 - character*37 a1 - character*36 a2 - character*10 a3 - character*27 a4 - data a1/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ - data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ - data a3/'0123456789'/ - data a4/' ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ - - is_digit(c)=c.ge.'0' .and. c.le.'9' - is_letter(c)=c.ge.'A' .and. c.le.'Z' - - n28=-1 -! Work-around for Swaziland prefix: - if(c13(1:4).eq.'3DA0') callsign='3D0'//c13(5:7) -! Work-around for Guinea prefixes: - if(c13(1:2).eq.'3X' .and. c13(3:3).ge.'A' .and. & - c13(3:3).le.'Z') callsign='Q'//c13(3:6) - -! Check for special tokens first - if(c13(1:3).eq.'DE ') then - n28=0 - go to 900 - endif - - if(c13(1:4).eq.'QRZ ') then - n28=1 - go to 900 - endif - - if(c13(1:3).eq.'CQ ') then - n28=2 - go to 900 - endif - - if(c13(1:3).eq.'CQ_') then - n=len(trim(c13)) - if(n.ge.4 .and. n.le.7) then - nlet=0 - nnum=0 - do i=4,n - c=c13(i:i) - if(c.ge.'A' .and. c.le.'Z') nlet=nlet+1 - if(c.ge.'0' .and. c.le.'9') nnum=nnum+1 - enddo - if(nnum.eq.3 .and. nlet.eq.0) then - read(c13(4:3+nnum),*) nqsy - n28=3+nqsy - go to 900 - endif - if(nlet.ge.1 .and. nlet.le.4 .and. nnum.eq.0) then - c4=c13(4:n) - c4=adjustr(c4) - m=0 - do i=1,4 - j=0 - c=c4(i:i) - if(c.ge.'A' .and. c.le.'Z') j=ichar(c)-ichar('A')+1 - m=27*m + j - enddo - n28=3+1000+m - go to 900 - endif - endif - endif - -! Check for <...> callsign - if(c13(1:1).eq.'<')then - call save_hash_call(c13,n10,n12,n22) !Save callsign in hash table - i2=index(c13,'>') - c13=c13(2:i2-1) - n22=ihashcall(c13,22) - n28=NTOKENS + n22 - go to 900 - endif - -! Check for standard callsign - iarea=-1 - n=len(trim(c13)) - do i=n,2,-1 - if(is_digit(c13(i:i))) exit - enddo - iarea=i !Call-area digit - npdig=0 !Digits before call area - nplet=0 !Letters before call area - do i=1,iarea-1 - if(is_digit(c13(i:i))) npdig=npdig+1 - if(is_letter(c13(i:i))) nplet=nplet+1 - enddo - nslet=0 - do i=iarea+1,n - if(is_letter(c13(i:i))) nslet=nslet+1 - enddo - if(iarea.lt.2 .or. iarea.gt.3 .or. nplet.eq.0 .or. & - npdig.ge.iarea-1 .or. nslet.gt.3) then -! Treat this as a nonstandard callsign: compute its 22-bit hash - call save_hash_call(c13,n10,n12,n22) !Save callsign in hash table - n22=ihashcall(c13,22) - n28=NTOKENS + n22 - go to 900 - endif - - n=len(trim(c13)) -! This is a standard callsign - call save_hash_call(c13,n10,n12,n22) !Save callsign in hash table - if(iarea.eq.2) callsign=' '//c13(1:5) - if(iarea.eq.3) callsign=c13(1:6) - i1=index(a1,callsign(1:1))-1 - i2=index(a2,callsign(2:2))-1 - i3=index(a3,callsign(3:3))-1 - i4=index(a4,callsign(4:4))-1 - i5=index(a4,callsign(5:5))-1 - i6=index(a4,callsign(6:6))-1 - n28=36*10*27*27*27*i1 + 10*27*27*27*i2 + 27*27*27*i3 + 27*27*i4 + & - 27*i5 + i6 - n28=n28 + NTOKENS + MAX22 - -900 n28=iand(n28,ishft(1,28)-1) - return -end subroutine pack28 - - -subroutine unpack28(n28_0,c13,success) - - parameter (NTOKENS=2063592,MAX22=4194304) - logical success - character*13 c13 - character*37 c1 - character*36 c2 - character*10 c3 - character*27 c4 - data c1/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ - data c2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ - data c3/'0123456789'/ - data c4/' ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ - - success=.true. - n28=n28_0 - if(n28.lt.NTOKENS) then -! Special tokens DE, QRZ, CQ, CQ_nnn, CQ_aaaa - if(n28.eq.0) c13='DE ' - if(n28.eq.1) c13='QRZ ' - if(n28.eq.2) c13='CQ ' - if(n28.le.2) go to 900 - if(n28.le.1002) then - write(c13,1002) n28-3 -1002 format('CQ_',i3.3) - go to 900 - endif - if(n28.le.532443) then - n=n28-1003 - n0=n - i1=n/(27*27*27) - n=n-27*27*27*i1 - i2=n/(27*27) - n=n-27*27*i2 - i3=n/27 - i4=n-27*i3 - c13=c4(i1+1:i1+1)//c4(i2+1:i2+1)//c4(i3+1:i3+1)//c4(i4+1:i4+1) - c13=adjustl(c13) - c13='CQ_'//c13(1:10) - go to 900 - endif - endif - n28=n28-NTOKENS - if(n28.lt.MAX22) then -! This is a 22-bit hash of a callsign - n22=n28 - call hash22(n22,c13) !Retrieve callsign from hash table - go to 900 - endif - -! Standard callsign - n=n28 - MAX22 - i1=n/(36*10*27*27*27) - n=n-36*10*27*27*27*i1 - i2=n/(10*27*27*27) - n=n-10*27*27*27*i2 - i3=n/(27*27*27) - n=n-27*27*27*i3 - i4=n/(27*27) - n=n-27*27*i4 - i5=n/27 - i6=n-27*i5 - c13=c1(i1+1:i1+1)//c2(i2+1:i2+1)//c3(i3+1:i3+1)//c4(i4+1:i4+1)// & - c4(i5+1:i5+1)//c4(i6+1:i6+1) - c13=adjustl(c13) - -900 i0=index(c13,' ') - if(i0.ne.0 .and. i0.lt.len(trim(c13))) then - c13='QU1RK' - success=.false. - endif - return -end subroutine unpack28 - -subroutine split77(msg,nwords,nw,w) - -! Convert msg to upper case; collapse multiple blanks; parse into words. - - character*37 msg - character*13 w(19) - character*1 c,c0 - character*6 bcall_1 - logical ok1 - integer nw(19) - - iz=len(trim(msg)) - j=0 - k=0 - n=0 - c0=' ' - w=' ' - do i=1,iz - if(ichar(msg(i:i)).eq.0) msg(i:i)=' ' - c=msg(i:i) !Single character - if(c.eq.' ' .and. c0.eq.' ') cycle !Skip leading/repeated blanks - if(c.ne.' ' .and. c0.eq.' ') then - k=k+1 !New word - n=0 - endif - j=j+1 !Index in msg - n=n+1 !Index in word - if(c.ge.'a' .and. c.le.'z') c=char(ichar(c)-32) !Force upper case - msg(j:j)=c - if(n.le.13) w(k)(n:n)=c !Copy character c into word - c0=c - enddo - iz=j !Message length - nwords=k !Number of words in msg - if(nwords.le.0) go to 900 - do i=1,nwords - nw(i)=len(trim(w(i))) - enddo - msg(iz+1:)=' ' - if(nwords.lt.3) go to 900 - call chkcall(w(3),bcall_1,ok1) - if(ok1 .and. w(1)(1:3).eq.'CQ ') then - w(1)='CQ_'//w(2)(1:10) !Make "CQ " into "CQ_" - w(2:12)=w(3:13) !Move all remaining words down by one - nwords=nwords-1 - endif - -900 return -end subroutine split77 - - -subroutine pack77_01(nwords,w,i3,n3,c77) - -! Pack a Type 0.1 message: DXpedition mode -! Example message: "K1ABC RR73; W9XYZ -11" 28 28 10 5 - - character*13 w(19),c13 - character*77 c77 - character*6 bcall_1,bcall_2 - logical ok1,ok2 - - if(nwords.ne.5) go to 900 !Must have 5 words - if(trim(w(2)).ne.'RR73;') go to 900 !2nd word must be "RR73;" - if(w(4)(1:1).ne.'<') go to 900 !4th word must have <...> - if(index(w(4),'>').lt.1) go to 900 - n=-99 - read(w(5),*,err=1) n -1 if(n.eq.-99) go to 900 !5th word must be a valid report - n5=(n+30)/2 - if(n5.lt.0) n5=0 - if(n5.gt.31) n5=31 - call chkcall(w(1),bcall_1,ok1) - if(.not.ok1) go to 900 !1st word must be a valid basecall - call chkcall(w(3),bcall_2,ok2) - if(.not.ok2) go to 900 !3rd word must be a valid basecall - -! Type 0.1: K1ABC RR73; W9XYZ -11 28 28 10 5 71 - i3=0 - n3=1 - call pack28(w(1),n28a) - call pack28(w(3),n28b) - call save_hash_call(w(4),n10,n12,n22) - i2=index(w(4),'>') - c13=w(4)(2:i2-1) - n10=ihashcall(c13,10) - write(c77,1010) n28a,n28b,n10,n5,n3,i3 -1010 format(2b28.28,b10.10,b5.5,2b3.3) - -900 return -end subroutine pack77_01 - - -subroutine pack77_03(nwords,w,i3,n3,c77) - -! Check 0.3 and 0.4 (ARRL Field Day exchange) -! Example message: WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 - - parameter (NSEC=86) !Number of ARRL Sections - character*13 w(19) - character*77 c77 - character*6 bcall_1,bcall_2 - character*3 csec(NSEC) - logical ok1,ok2 - data csec/ & - "AB ","AK ","AL ","AR ","AZ ","BC ","CO ","CT ","DE ","EB ", & - "EMA","ENY","EPA","EWA","GA ","GH ","IA ","ID ","IL ","IN ", & - "KS ","KY ","LA ","LAX","NS ","MB ","MDC","ME ","MI ","MN ", & - "MO ","MS ","MT ","NC ","ND ","NE ","NFL","NH ","NL ","NLI", & - "NM ","NNJ","NNY","TER","NTX","NV ","OH ","OK ","ONE","ONN", & - "ONS","OR ","ORG","PAC","PR ","QC ","RI ","SB ","SC ","SCV", & - "SD ","SDG","SF ","SFL","SJV","SK ","SNJ","STX","SV ","TN ", & - "UT ","VA ","VI ","VT ","WCF","WI ","WMA","WNY","WPA","WTX", & - "WV ","WWA","WY ","DX ","PE ","NB "/ - - if(nwords.lt.4 .or. nwords.gt.5) return - call chkcall(w(1),bcall_1,ok1) - call chkcall(w(2),bcall_2,ok2) - if(.not.ok1 .or. .not.ok2) return - isec=-1 - do i=1,NSEC - if(csec(i).eq.w(nwords)(1:3)) then - isec=i - exit - endif - enddo - if(isec.eq.-1) return - if(nwords.eq.5 .and. trim(w(3)).ne.'R') return - - ntx=-1 - j=len(trim(w(nwords-1)))-1 - read(w(nwords-1)(1:j),*,err=1,end=1) ntx !Number of transmitters -1 if(ntx.lt.1 .or. ntx.gt.32) return - nclass=ichar(w(nwords-1)(j+1:j+1))-ichar('A') - - m=len(trim(w(nwords))) !Length of section abbreviation - if(m.lt.2 .or. m.gt.3) return - -! 0.3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day -! 0.4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day - - i3=0 - n3=3 !Type 0.3 ARRL Field Day - intx=ntx-1 - if(intx.ge.16) then - n3=4 !Type 0.4 ARRL Field Day - intx=ntx-17 - endif - call pack28(w(1),n28a) - call pack28(w(2),n28b) - ir=0 - if(w(3)(1:2).eq.'R ') ir=1 - write(c77,1010) n28a,n28b,ir,intx,nclass,isec,n3,i3 -1010 format(2b28.28,b1,b4.4,b3.3,b7.7,2b3.3) - - return -end subroutine pack77_03 - - -subroutine pack77_06(nwords,w,i3,n3,c77,i3_hint,n3_hint) - - character*13 w(19) - character*77 c77 - character*6 bcall,grid6 - character*4 grid4 - character*1 c - character*36 a2 - data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/,nzzz/46656/ - - logical is_grid4,is_grid6,is_digit,ok - is_grid4(grid4)=len(trim(grid4)).eq.4 .and. & - grid4(1:1).ge.'A' .and. grid4(1:1).le.'R' .and. & - grid4(2:2).ge.'A' .and. grid4(2:2).le.'R' .and. & - grid4(3:3).ge.'0' .and. grid4(3:3).le.'9' .and. & - grid4(4:4).ge.'0' .and. grid4(4:4).le.'9' - - is_grid6(grid6)=(len(trim(grid6)).eq.6.or.len(trim(grid6)).eq.4).and. & - grid6(1:1).ge.'A' .and. grid6(1:1).le.'R' .and. & - grid6(2:2).ge.'A' .and. grid6(2:2).le.'R' .and. & - grid6(3:3).ge.'0' .and. grid6(3:3).le.'9' .and. & - grid6(4:4).ge.'0' .and. grid6(4:4).le.'9' .and. & - (len(trim(grid6)).eq.4.or. & - (grid6(5:5).ge.'A' .and. grid6(5:5).le.'X' .and. & - grid6(6:6).ge.'A' .and. grid6(6:6).le.'X')) - - is_digit(c)=c.ge.'0' .and. c.le.'9' - - m1=len(trim(w(1))) - m2=len(trim(w(2))) - m3=len(trim(w(3))) - if(nwords.eq.3 .and. m1.ge.3 .and. m1.le.6 .and. m2.eq.4 .and. m3.le.2) then -! WSPR Type 1 - if(.not.is_grid4(w(2)(1:4))) go to 900 - if(.not.is_digit(w(3)(1:1))) go to 900 - if(m3.eq.2) then - if(.not.is_digit(w(3)(2:2))) go to 900 - endif - i3=0 - n3=6 - call pack28(w(1),n28) - grid4=w(2)(1:4) - k1=(ichar(grid4(1:1))-ichar('A'))*18*10*10 - k2=(ichar(grid4(2:2))-ichar('A'))*10*10 - k3=(ichar(grid4(3:3))-ichar('0'))*10 - k4=(ichar(grid4(4:4))-ichar('0')) - igrid4=k1+k2+k3+k4 - read(w(3),*) idbm - if(idbm.lt.0) idbm=0 - if(idbm.gt.60) idbm=60 - idbm=nint(0.3*idbm) - write(c77,1010) n28,igrid4,idbm,0,0,0,n3,i3 -1010 format(b28.28,b15.15,b5.5,2i1,b21.21,2b3.3) - go to 900 - endif - if(nwords.eq.2 .and. m1.ge.5 .and. m1.le.10 .and. m2.le.2) then -! WSPR Type 2 - i1=index(w(1),'/') - if(i1.lt.2 .or. i1.eq.m1) go to 900 - if(.not.is_digit(w(2)(1:1))) go to 900 - if(i1.eq.(m1-3) .and. .not.is_digit(w(1)(m1:m1))) go to 900 - if(m2.eq.2) then - if(.not.is_digit(w(2)(2:2))) go to 900 - endif - call chkcall(w(1),bcall,ok) - if(.not.ok) go to 900 - if(i1.le.4) then -! We have a prefix - npfx=index(a2,w(1)(1:1))-1 - if(i1.ge.3) npfx=36*npfx + index(a2,w(1)(2:2))-1 - if(i1.eq.4) npfx=36*npfx + index(a2,w(1)(3:3))-1 - else -! We have a suffix - if((m1-i1).eq.1) npfx=index(a2,w(1)(i1+1:i1+1))-1 - if((m1-i1).eq.2) npfx=36*(index(a2,w(1)(i1+1:i1+1))-1) + & - index(a2,w(1)(i1+2:i1+2))-1 - if((m1-i1).eq.3) then -! Third character of a suffix must be a digit - if(.not.is_digit(w(1)(i1+3:i1+3))) go to 900 - npfx=36*10*(index(a2,w(1)(i1+1:i1+1))-1) + & - 10*(index(a2,w(1)(i1+2:i1+2))-1) + index(a2,w(1)(i1+3:i1+3))-1 - endif - npfx=npfx + nzzz - endif - i3=0 - n3=6 - call pack28(bcall//' ',n28) - read(w(2),*) idbm - if(idbm.lt.0) idbm=0 - if(idbm.gt.60) idbm=60 - idbm=nint(0.3*idbm) - write(c77,1020) n28,npfx,idbm,1,0,n3,i3 -1020 format(b28.28,b16.16,b5.5,i1,b21.21,2b3.3) - go to 900 - endif - - if(i3_hint.eq.0.and.n3_hint.eq.6.and.nwords.eq.2 .and. m1.ge.5 & - .and. m1.le.12 .and. m2.le.6) then -! WSPR Type 3 - - !n3_hint=6 and i3_hint=0 is a hint that the caller wanted a - !50-bit encoding rather than the possible alternative n3=4 77-bit - !encoding - if(index(w(1),'<').lt.1 .or. index(w(1),'>').lt.1) go to 900 - grid6=w(2)(1:6) - if(.not.is_grid6(grid6)) go to 900 - i3=0 - n3=6 - call pack28(w(1),n28) - n22=n28-2063592 - k1=(ichar(grid6(1:1))-ichar('A'))*18*10*10*25*25 - k2=(ichar(grid6(2:2))-ichar('A'))*10*10*25*25 - k3=(ichar(grid6(3:3))-ichar('0'))*10*25*25 - k4=(ichar(grid6(4:4))-ichar('0'))*25*25 - if (grid6(5:6).eq.' ') then - igrid6=k1+k2+k3+k4+24*25+24 - else - k5=(ichar(grid6(5:5))-ichar('A'))*25 - k6=(ichar(grid6(6:6))-ichar('A')) - igrid6=k1+k2+k3+k4+k5+k6 - endif - write(c77,1030) n22,igrid6,2,0,n3,i3 -1030 format(b22.22,b25.25,b3.3,b21.21,2b3.3) - endif - -900 return -end subroutine pack77_06 - - -subroutine pack77_1(nwords,w,i3,n3,c77) - -! Check Type 1 (Standard 77-bit message) and Type 2 (ditto, with a "/P" call) -! Example message: WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 - - parameter (MAXGRID4=32400) - character*13 w(19),c13 - character*77 c77 - character*6 bcall_1,bcall_2 - character*4 grid4 - character c1*1,c2*2 - logical is_grid4 - logical ok1,ok2 - is_grid4(grid4)=len(trim(grid4)).eq.4 .and. & - grid4(1:1).ge.'A' .and. grid4(1:1).le.'R' .and. & - grid4(2:2).ge.'A' .and. grid4(2:2).le.'R' .and. & - grid4(3:3).ge.'0' .and. grid4(3:3).le.'9' .and. & - grid4(4:4).ge.'0' .and. grid4(4:4).le.'9' - - if(nwords.lt.2 .or. nwords.gt.4) return - call chkcall(w(1),bcall_1,ok1) - call chkcall(w(2),bcall_2,ok2) - if(w(1)(1:3).eq.'DE ' .or. w(1)(1:3).eq.'CQ_' .or. w(1)(1:3).eq.'CQ ' .or. & - w(1)(1:4).eq.'QRZ ') ok1=.true. - if(w(1)(1:1).eq.'<' .and. index(w(1),'>').ge.5) ok1=.true. - if(w(2)(1:1).eq.'<' .and. index(w(2),'>').ge.5) ok2=.true. - if(.not.ok1 .or. .not.ok2) return - if(w(1)(1:1).eq.'<' .and. index(w(2),'/').gt.0) return - if(w(2)(1:1).eq.'<' .and. index(w(1),'/').gt.0) return - if(nwords.eq.2 .and. (.not.ok2 .or. index(w(2),'/').ge.2)) return - if(nwords.eq.2) go to 10 - - c1=w(nwords)(1:1) - c2=w(nwords)(1:2) - if(.not.is_grid4(w(nwords)(1:4)) .and. c1.ne.'+' .and. c1.ne.'-' & - .and. c2.ne.'R+' .and. c2.ne.'R-' .and. trim(w(nwords)).ne.'RRR' .and. & - trim(w(nwords)).ne.'RR73' .and. trim(w(nwords)).ne.'73') return - if(c1.eq.'+' .or. c1.eq.'-') then - ir=0 - read(w(nwords),*,err=900) irpt - if(irpt.ge.-50 .and. irpt.le.-31) irpt=irpt+101 - irpt=irpt+35 - else if(c2.eq.'R+' .or. c2.eq.'R-') then - ir=1 - read(w(nwords)(2:),*,err=900) irpt - if(irpt.ge.-50 .and. irpt.le.-31) irpt=irpt+101 - irpt=irpt+35 - else if(trim(w(nwords)).eq.'RRR') then - ir=0 - irpt=2 - else if(trim(w(nwords)).eq.'RR73') then - ir=0 - irpt=3 - else if(trim(w(nwords)).eq.'73') then - ir=0 - irpt=4 - endif - -! 1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg -! 2 PA3XYZ/P GM4ABC/P R JO22 28 1 28 1 1 15 74 EU VHF contest - -10 i1psuffix=index(w(1)//' ' ,'/P ') - i2psuffix=index(w(2)//' ','/P ') - if(nwords.eq.2 .or. nwords.eq.3 .or. (nwords.eq.4 .and. & - w(3)(1:2).eq.'R ')) then - n3=0 - i3=1 !Type 1: Standard message, possibly with "/R" - if (i1psuffix.ge.4.or.i2psuffix.ge.4) i3=2 !Type 2, with "/P" - endif - c13=bcall_1 - if(c13(1:3).eq.'CQ_' .or. w(1)(1:1).eq.'<') c13=w(1) - call pack28(c13,n28a) - c13=bcall_2 - if(w(2)(1:1).eq.'<') c13=w(2) - call pack28(c13,n28b) - ipa=0 - ipb=0 - if(i1psuffix.ge.4.or.index(w(1)//' ','/R ').ge.4) ipa=1 - if(i2psuffix.ge.4.or.index(w(2)//' ','/R ').ge.4) ipb=1 - - grid4=w(nwords)(1:4) - if(is_grid4(grid4)) then - ir=0 - if(w(3).eq.'R ') ir=1 - j1=(ichar(grid4(1:1))-ichar('A'))*18*10*10 - j2=(ichar(grid4(2:2))-ichar('A'))*10*10 - j3=(ichar(grid4(3:3))-ichar('0'))*10 - j4=(ichar(grid4(4:4))-ichar('0')) - igrid4=j1+j2+j3+j4 - else - igrid4=MAXGRID4 + irpt - endif - if(nwords.eq.2) then - ir=0 - irpt=1 - igrid4=MAXGRID4+irpt - endif - write(c77,1000) n28a,ipa,n28b,ipb,ir,igrid4,i3 -1000 format(2(b28.28,b1),b1,b15.15,b3.3) - return - -900 return -end subroutine pack77_1 - - -subroutine pack77_3(nwords,w,i3,n3,c77) - -! Check Type 3 (ARRL RTTY contest exchange) -! ARRL RTTY - US/Can: rpt state/prov R 579 MA -! - DX: rpt serial R 559 0013 -! Example message: TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 - - parameter (NUSCAN=171) !Number of US states and Canadian provinces/territories - character*13 w(19) - character*77 c77 - character*6 bcall_1,bcall_2 - character*3 cmult(NUSCAN),mult - character crpt*3 - logical ok1,ok2 - data cmult/ & - "AL ","AK ","AZ ","AR ","CA ","CO ","CT ","DE ","FL ","GA ", & - "HI ","ID ","IL ","IN ","IA ","KS ","KY ","LA ","ME ","MD ", & - "MA ","MI ","MN ","MS ","MO ","MT ","NE ","NV ","NH ","NJ ", & - "NM ","NY ","NC ","ND ","OH ","OK ","OR ","PA ","RI ","SC ", & - "SD ","TN ","TX ","UT ","VT ","VA ","WA ","WV ","WI ","WY ", & - "NB ","NS ","QC ","ON ","MB ","SK ","AB ","BC ","NWT","NF ", & - "LB ","NU ","YT ","PEI","DC ","DR ","FR ","GD ","GR ","OV ", & - "ZH ","ZL ","X01","X02","X03","X04","X05","X06","X07","X08", & - "X09","X10","X11","X12","X13","X14","X15","X16","X17","X18", & - "X19","X20","X21","X22","X23","X24","X25","X26","X27","X28", & - "X29","X30","X31","X32","X33","X34","X35","X36","X37","X38", & - "X39","X40","X41","X42","X43","X44","X45","X46","X47","X48", & - "X49","X50","X51","X52","X53","X54","X55","X56","X57","X58", & - "X59","X60","X61","X62","X63","X64","X65","X66","X67","X68", & - "X69","X70","X71","X72","X73","X74","X75","X76","X77","X78", & - "X79","X80","X81","X82","X83","X84","X85","X86","X87","X88", & - "X89","X90","X91","X92","X93","X94","X95","X96","X97","X98", & - "X99"/ - - if(w(1)(1:1).eq.'<' .and. w(2)(1:1).eq.'<') go to 900 - if(nwords.eq.4 .or. nwords.eq.5 .or. nwords.eq.6) then - i1=1 - if(trim(w(1)).eq.'TU;') i1=2 - call chkcall(w(i1),bcall_1,ok1) - call chkcall(w(i1+1),bcall_2,ok2) - if(.not.ok1 .or. .not.ok2) go to 900 - crpt=w(nwords-1)(1:3) - if(index(crpt,'-').ge.1 .or. index(crpt,'+').ge.1) go to 900 - if(crpt(1:1).eq.'5' .and. crpt(2:2).ge.'2' .and. crpt(2:2).le.'9' .and. & - crpt(3:3).eq.'9') then - nserial=0 - read(w(nwords),*,err=1) nserial - endif -1 mult=' ' - imult=-1 - do i=1,NUSCAN - if(cmult(i).eq.w(nwords)) then - imult=i - mult=cmult(i) - exit - endif - enddo - nexch=0 - if(nserial.gt.0) nexch=nserial - if(imult.gt.0) nexch=8000+imult - if(mult.ne.' ' .or. nserial.gt.0) then - i3=3 - n3=0 - itu=0 - if(trim(w(1)).eq.'TU;') itu=1 - call pack28(w(1+itu),n28a) - call pack28(w(2+itu),n28b) - ir=0 - if(w(3+itu)(1:2).eq.'R ') ir=1 - read(w(3+itu+ir),*,err=900) irpt - irpt=(irpt-509)/10 - 2 - if(irpt.lt.0) irpt=0 - if(irpt.gt.7) irpt=7 -! 3 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest -! 3 TU; W9XYZ G8ABC R 559 0013 1 28 28 1 3 13 74 ARRL RTTY (DX) - write(c77,1010) itu,n28a,n28b,ir,irpt,nexch,i3 -1010 format(b1,2b28.28,b1,b3.3,b13.13,b3.3) - endif - endif - -900 return -end subroutine pack77_3 - - -subroutine pack77_4(nwords,w,i3,n3,c77) - -! Check Type 4 (One nonstandard call and one hashed call) -! Example message: PJ4/KA1ABC RR73 12 58 1 2 1 74 - - integer*8 n58 - logical ok1,ok2 - character*13 w(19) - character*77 c77 - character*13 call_1,call_2 - character*11 c11 - character*6 bcall_1,bcall_2 - character*38 c - data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ - - iflip=0 - i3=-1 - if(nwords.eq.2 .or. nwords.eq.3) then - call_1=w(1) - if(call_1(1:1).eq.'<') call_1=w(1)(2:len(trim(w(1)))-1) - call_2=w(2) - if(call_2(1:1).eq.'<') call_2=w(2)(2:len(trim(w(2)))-1) - call chkcall(call_1,bcall_1,ok1) - call chkcall(call_2,bcall_2,ok2) - if(call_1.eq.bcall_1 .and. call_2.eq.bcall_2 .and. ok1 .and. ok2) go to 900 - icq=0 - if(trim(w(1)).eq.'CQ' .or. (ok1.and.ok2)) then - if(trim(w(1)).eq.'CQ' .and. len(trim(w(2))).le.4) go to 900 - i3=4 - n3=0 - if(trim(w(1)).eq.'CQ') icq=1 - endif - - if(icq.eq.1) then - iflip=0 - n12=0 - c11=adjustr(call_2(1:11)) - call save_hash_call(w(2),n10,n12,n22) - else if(w(1)(1:1).eq.'<') then - iflip=0 - i3=4 - call save_hash_call(w(1),n10,n12,n22) - c11=adjustr(call_2(1:11)) - else if(w(2)(1:1).eq.'<') then - iflip=1 - i3=4 - call save_hash_call(w(2),n10,n12,n22) - c11=adjustr(call_1(1:11)) - endif - n58=0 - do i=1,11 - n58=n58*38 + index(c,c11(i:i)) - 1 - enddo - nrpt=0 - if(trim(w(3)).eq.'RRR') nrpt=1 - if(trim(w(3)).eq.'RR73') nrpt=2 - if(trim(w(3)).eq.'73') nrpt=3 - if(icq.eq.1) then - iflip=0 - nrpt=0 - endif - write(c77,1010) n12,n58,iflip,nrpt,icq,i3 -1010 format(b12.12,b58.58,b1,b2.2,b1,b3.3) - do i=1,77 - if(c77(i:i).eq.'*') c77(i:i)='0' !### Clean up any illegal chars ### - enddo - endif - -900 return -end subroutine pack77_4 - -subroutine pack77_5(nwords,w,i3,n3,c77) - -! Pack a Type 0.2 message: EU VHF Contest mode -! Example message: PA3XYZ/P R 590003 IO91NP 28 1 1 3 12 25 -! R 590003 IO91NP h10 h20 r1 s3 s12 g25 - - character*13 w(19),c13 - character*77 c77 - character*6 grid6 - logical is_grid6 - - is_grid6(grid6)=len(trim(grid6)).eq.6 .and. & - grid6(1:1).ge.'A' .and. grid6(1:1).le.'R' .and. & - grid6(2:2).ge.'A' .and. grid6(2:2).le.'R' .and. & - grid6(3:3).ge.'0' .and. grid6(3:3).le.'9' .and. & - grid6(4:4).ge.'0' .and. grid6(4:4).le.'9' .and. & - grid6(5:5).ge.'A' .and. grid6(5:5).le.'X' .and. & - grid6(6:6).ge.'A' .and. grid6(6:6).le.'X' - - if(nwords.lt.4 .or. nwords.gt.5) return !nwords must be 4 or 5 - if(w(1)(1:1).ne.'<' .or. w(2)(1:1).ne.'<') return !Both calls must be hashed - nx=-1 - read(w(nwords-1),*,err=2) nx -2 if(nx.lt.520001 .or. nx.gt.594095) return !Exchange between 520001 - 594095 - if(.not.is_grid6(w(nwords)(1:6))) return !Last word must be a valid grid6 - -! Type 0.2: R 590003 IO91NP h10 h20 r1 s3 s12 g25 - - i3=5 - n3=0 - - call save_hash_call(w(1),n10,n12,n22) - i2=index(w(1),'>') - c13=w(1)(2:i2-1) - n12=ihashcall(c13,12) - - call save_hash_call(w(2),n10a,n12a,n22) - i2=index(w(2),'>') - c13=w(2)(2:i2-1) - n22=ihashcall(c13,22) - - ir=0 - if(w(3)(1:2).eq.'R ') ir=1 - irpt=nx/10000 - 52 - iserial=mod(nx,10000) - if(iserial.gt.2047) iserial=2047 - grid6=w(nwords)(1:6) - j1=(ichar(grid6(1:1))-ichar('A'))*18*10*10*24*24 - j2=(ichar(grid6(2:2))-ichar('A'))*10*10*24*24 - j3=(ichar(grid6(3:3))-ichar('0'))*10*24*24 - j4=(ichar(grid6(4:4))-ichar('0'))*24*24 - j5=(ichar(grid6(5:5))-ichar('A'))*24 - j6=(ichar(grid6(6:6))-ichar('A')) - igrid6=j1+j2+j3+j4+j5+j6 - - write(c77,1010) n12,n22,ir,irpt,iserial,igrid6,i3 -1010 format(b12.12,b22.22,b1,b3.3,b11.11,b25.25,b3.3) - - return -end subroutine pack77_5 - - -subroutine packtext77(c13,c71) - - character*13 c13,w - character*71 c71 - character*42 c - character*1 qa(10),qb(10) - data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/ - - call mp_short_init - qa=char(0) - w=adjustr(c13) - do i=1,13 - j=index(c,w(i:i))-1 - if(j.lt.0) j=0 - call mp_short_mult(qb,qa(2:10),9,42) !qb(1:9)=42*qa(2:9) - call mp_short_add(qa,qb(2:10),9,j) !qa(1:9)=qb(2:9)+j - enddo - - write(c71,1010) qa(2:10) -1010 format(b7.7,8b8.8) - - return -end subroutine packtext77 - -subroutine unpacktext77(c71,c13) - - integer*1 ia(10) - character*1 qa(10),qb(10) - character*13 c13 - character*71 c71 - character*42 c - equivalence (qa,ia),(qb,ib) - data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/ - - qa(1)=char(0) - read(c71,1010) qa(2:10) -1010 format(b7.7,8b8.8) - - do i=13,1,-1 - call mp_short_div(qb,qa(2:10),9,42,ir) - c13(i:i)=c(ir+1:ir+1) - qa(2:10)=qb(1:9) - enddo - - return -end subroutine unpacktext77 - -subroutine mp_short_ops(w,u) - character*1 w(*),u(*) - integer i,ireg,j,n,ir,iv,ii1,ii2 - character*1 creg(4) - save ii1,ii2 - equivalence (ireg,creg) - - entry mp_short_init - ireg=256*ichar('2')+ichar('1') - do j=1,4 - if (creg(j).eq.'1') ii1=j - if (creg(j).eq.'2') ii2=j - enddo - return - - entry mp_short_add(w,u,n,iv) - ireg=256*iv - do j=n,1,-1 - ireg=ichar(u(j))+ichar(creg(ii2)) - w(j+1)=creg(ii1) - enddo - w(1)=creg(ii2) - return - - entry mp_short_mult(w,u,n,iv) - ireg=0 - do j=n,1,-1 - ireg=ichar(u(j))*iv+ichar(creg(ii2)) - w(j+1)=creg(ii1) - enddo - w(1)=creg(ii2) - return - - entry mp_short_div(w,u,n,iv,ir) - ir=0 - do j=1,n - i=256*ir+ichar(u(j)) - w(j)=char(i/iv) - ir=mod(i,iv) - enddo - return - - return -end subroutine mp_short_ops - -subroutine add_call_to_recent_calls(callsign) - - character*13 callsign - logical ladd - -! only add if the callsign is not already on the list - ladd=.true. - do i=1,MAXRECENT-1 ! if callsign is at the end of the list add it again - if(recent_calls(i).eq.callsign) ladd=.false. - enddo - - if(ladd) then - do i=MAXRECENT,2,-1 - recent_calls(i)=recent_calls(i-1) - enddo - recent_calls(1)=callsign - endif - -! Make sure that callsign is hashed -! call save_hash_call(callsign,n10,n12,n22) ! commented out - do this in the calling routine: - - return -end subroutine add_call_to_recent_calls - -subroutine to_grid4(n,grid4,ok) - character*4 grid4 - logical ok - - ok=.false. - j1=n/(18*10*10) - if (j1.lt.0.or.j1.gt.17) goto 900 - n=n-j1*18*10*10 - j2=n/(10*10) - if (j2.lt.0.or.j2.gt.17) goto 900 - n=n-j2*10*10 - j3=n/10 - if (j3.lt.0.or.j3.gt.9) goto 900 - j4=n-j3*10 - if (j4.lt.0.or.j4.gt.9) goto 900 - grid4(1:1)=char(j1+ichar('A')) - grid4(2:2)=char(j2+ichar('A')) - grid4(3:3)=char(j3+ichar('0')) - grid4(4:4)=char(j4+ichar('0')) - ok=.true. - -900 return -end subroutine to_grid4 - -subroutine to_grid6(n,grid6,ok) - character*6 grid6 - logical ok - - ok=.false. - j1=n/(18*10*10*24*24) - if (j1.lt.0.or.j1.gt.17) goto 900 - n=n-j1*18*10*10*24*24 - j2=n/(10*10*24*24) - if (j2.lt.0.or.j2.gt.17) goto 900 - n=n-j2*10*10*24*24 - j3=n/(10*24*24) - if (j3.lt.0.or.j3.gt.9) goto 900 - n=n-j3*10*24*24 - j4=n/(24*24) - if (j4.lt.0.or.j4.gt.9) goto 900 - n=n-j4*24*24 - j5=n/24 - if (j5.lt.0.or.j5.gt.23) goto 900 - j6=n-j5*24 - if (j6.lt.0.or.j6.gt.23) goto 900 - grid6(1:1)=char(j1+ichar('A')) - grid6(2:2)=char(j2+ichar('A')) - grid6(3:3)=char(j3+ichar('0')) - grid6(4:4)=char(j4+ichar('0')) - grid6(5:5)=char(j5+ichar('A')) - grid6(6:6)=char(j6+ichar('A')) - ok=.true. - -900 return -end subroutine to_grid6 - -subroutine to_grid(n,grid6,ok) - ! 4-, or 6-character grid - character*6 grid6 - logical ok - - ok=.false. - j1=n/(18*10*10*25*25) - if (j1.lt.0.or.j1.gt.17) goto 900 - n=n-j1*18*10*10*25*25 - j2=n/(10*10*25*25) - if (j2.lt.0.or.j2.gt.17) goto 900 - n=n-j2*10*10*25*25 - j3=n/(10*25*25) - if (j3.lt.0.or.j3.gt.9) goto 900 - n=n-j3*10*25*25 - j4=n/(25*25) - if (j4.lt.0.or.j4.gt.9) goto 900 - n=n-j4*25*25 - j5=n/25 - if (j5.lt.0.or.j5.gt.24) goto 900 - j6=n-j5*25 - if (j6.lt.0.or.j6.gt.24) goto 900 - grid6='' - grid6(1:1)=char(j1+ichar('A')) - grid6(2:2)=char(j2+ichar('A')) - grid6(3:3)=char(j3+ichar('0')) - grid6(4:4)=char(j4+ichar('0')) - if (j5.ne.24.or.j6.ne.24) then - grid6(5:5)=char(j5+ichar('A')) - grid6(6:6)=char(j6+ichar('A')) - endif - ok=.true. - -900 return -end subroutine to_grid - -end module packjt77 +module packjt77 + +! These variables are accessible from outside via "use packjt77": + parameter (MAXHASH=1000,MAXRECENT=10) + character (len=13), dimension(0:1023) :: calls10='' + character (len=13), dimension(0:4095) :: calls12='' + character (len=13), dimension(1:MAXHASH) :: calls22='' + character (len=13), dimension(1:MAXRECENT) :: recent_calls='' + character (len=13) :: mycall13='' + character (len=13) :: dxcall13='' + character (len=6) :: dxbase='' + integer, dimension(1:MAXHASH) :: ihash22=-1 + integer :: nzhash=0 + integer n28a,n28b + + contains + +subroutine hash10(n10,c13) + + character*13 c13 + + c13='<...>' + if(n10.lt.0 .or. n10.gt.1023) return + if(len(trim(calls10(n10))).gt.0) then + c13=calls10(n10) + c13='<'//trim(c13)//'>' + endif + return + +end subroutine hash10 + +subroutine hash12(n12,c13) + + character*13 c13 + + c13='<...>' + if(n12.lt.0 .or. n12.gt.4095) return + if(len(trim(calls12(n12))).gt.0) then + c13=calls12(n12) + c13='<'//trim(c13)//'>' + endif + return + +end subroutine hash12 + + +subroutine hash22(n22,c13) + + character*13 c13 + + c13='<...>' + do i=1,nzhash + if(ihash22(i).eq.n22) then + c13=calls22(i) + c13='<'//trim(c13)//'>' + go to 900 + endif + enddo + +900 return +end subroutine hash22 + + +integer function ihashcall(c0,m) + + integer*8 n8 + character*13 c0 + character*38 c + data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ + + n8=0 + do i=1,11 + j=index(c,c0(i:i)) - 1 + n8=38*n8 + j + enddo + ihashcall=ishft(47055833459_8*n8,m-64) + + return +end function ihashcall + +subroutine save_hash_call(c13,n10,n12,n22) + + character*13 c13,cw + + cw=c13 + if(cw(1:1).eq.' ' .or. cw(1:5).eq.'<...>') return + if(cw(1:1).eq.'<') cw=cw(2:) + i=index(cw,'>') + if(i.gt.0) cw(i:)=' ' + + if(len(trim(cw)) .lt. 3) return + + n10=ihashcall(cw,10) + if(n10.ge.0 .and. n10 .le. 1023 .and. cw.ne.mycall13) calls10(n10)=cw + + n12=ihashcall(cw,12) + if(n12.ge.0 .and. n12 .le. 4095 .and. cw.ne.mycall13) calls12(n12)=cw + + n22=ihashcall(cw,22) + if(any(ihash22.eq.n22)) then ! If entry exists, make sure callsign is the most recently received one + where(ihash22.eq.n22) calls22=cw + go to 900 + endif + +! New entry: move table down, making room for new one at the top + ihash22(MAXHASH:2:-1)=ihash22(MAXHASH-1:1:-1) + +! Add the new entry + calls22(MAXHASH:2:-1)=calls22(MAXHASH-1:1:-1) + ihash22(1)=n22 + calls22(1)=cw + if(nzhash.lt.MAXHASH) nzhash=nzhash+1 +900 continue + return +end subroutine save_hash_call + +subroutine pack77(msg0,i3,n3,c77) + + use packjt + character*37 msg,msg0 + character*18 c18 + character*13 w(19) + character*77 c77 + integer nw(19) + integer ntel(3) + + msg=msg0 + if(msg(1:3).eq.'$DX') then + i1=index(msg,' ') + msg=trim(dxbase)//' '//msg(i1+1:) + endif + + i3_hint=i3 + n3_hint=n3 + i3=-1 + n3=-1 + if(i3_hint.eq.0 .and. n3_hint.eq.5) go to 5 + +! Convert msg to upper case; collapse multiple blanks; parse into words. + call split77(msg,nwords,nw,w) + if(msg(1:3).eq.'CQ ' .or. msg(1:3).eq.'DE ' .or. msg(1:4).eq.'QRZ ') go to 100 + +! Check 0.1 (DXpedition mode) + call pack77_01(nwords,w,i3,n3,c77) + if(i3.ge.0 .or. n3.ge.1) go to 900 +! Check 0.2 (EU VHF contest exchange) +! call pack77_02(nwords,w,i3,n3,c77) +! if(i3.ge.0) go to 900 + +! Check 0.3 and 0.4 (ARRL Field Day exchange) + call pack77_03(nwords,w,i3,n3,c77) + if(i3.ge.0) go to 900 + if(nwords.ge.2) go to 100 + + ! Check 0.5 (telemetry) +5 i0=index(msg,' ') + c18=msg(1:i0-1) + c18=adjustr(c18) + ntel=-99 + read(c18,1005,err=6) ntel +1005 format(3z6) + if(ntel(1).ge.2**23) go to 800 +6 if(ntel(1).ge.0 .and. ntel(2).ge.0 .and. ntel(3).ge.0) then + i3=0 + n3=5 + write(c77,1006) ntel,n3,i3 +1006 format(b23.23,2b24.24,2b3.3) + go to 900 + endif + +100 call pack77_06(nwords,w,i3,n3,c77,i3_hint,n3_hint) + if(i3.ge.0) go to 900 + +! Check Type 1 (Standard 77-bit message) or Type 2, with optional "/P" + call pack77_1(nwords,w,i3,n3,c77) + if(i3.ge.0) go to 900 + +! Check Type 3 (ARRL RTTY contest exchange) + call pack77_3(nwords,w,i3,n3,c77) + if(i3.ge.0) go to 900 + +! Check Type 4 (One nonstandard call and one hashed call) + call pack77_4(nwords,w,i3,n3,c77) + if(i3.ge.0) go to 900 + +! Check Type 5 (EU VHF Contest with 2 hashed calls, report, serial, and grid6) + call pack77_5(nwords,w,i3,n3,c77) + if(i3.ge.0) go to 900 + +! It defaults to free text +800 i3=0 + n3=0 + msg(14:)=' ' + call packtext77(msg(1:13),c77(1:71)) + write(c77(72:77),'(2b3.3)') n3,i3 + +900 return +end subroutine pack77 + +subroutine unpack77(c77,nrx,msg,unpk77_success) +! +! nrx=1 when unpacking a received message +! nrx=0 when unpacking a to-be-transmitted message +! the value of nrx is used to decide when mycall13 or dxcall13 should +! be used in place of a callsign from the hashtable +! + parameter (NSEC=86) !Number of ARRL Sections + parameter (NUSCAN=171) !Number of States and Provinces + parameter (MAXGRID4=32400) + integer*8 n58 + integer ntel(3) + character*77 c77 + character*37 msg + character*13 call_1,call_2,call_3,call_1a + character*13 mycall13_0,dxcall13_0 + character*11 c11 + character*3 crpt,cntx,cpfx + character*3 cmult(NUSCAN) + character*6 cexch,grid6 + character*4 grid4,cserial + character*3 csec(NSEC) + character*38 c + character*36 a2 + integer hashmy10,hashmy12,hashmy22,hashdx10,hashdx12,hashdx22 + logical unpk28_success,unpk77_success,unpkg4_success + logical dxcall13_set,mycall13_set + + data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/,nzzz/46656/ + data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ + data csec/ & + "AB ","AK ","AL ","AR ","AZ ","BC ","CO ","CT ","DE ","EB ", & + "EMA","ENY","EPA","EWA","GA ","GH ","IA ","ID ","IL ","IN ", & + "KS ","KY ","LA ","LAX","NS ","MB ","MDC","ME ","MI ","MN ", & + "MO ","MS ","MT ","NC ","ND ","NE ","NFL","NH ","NL ","NLI", & + "NM ","NNJ","NNY","TER","NTX","NV ","OH ","OK ","ONE","ONN", & + "ONS","OR ","ORG","PAC","PR ","QC ","RI ","SB ","SC ","SCV", & + "SD ","SDG","SF ","SFL","SJV","SK ","SNJ","STX","SV ","TN ", & + "UT ","VA ","VI ","VT ","WCF","WI ","WMA","WNY","WPA","WTX", & + "WV ","WWA","WY ","DX ","PE ","NB "/ + data cmult/ & + "AL ","AK ","AZ ","AR ","CA ","CO ","CT ","DE ","FL ","GA ", & + "HI ","ID ","IL ","IN ","IA ","KS ","KY ","LA ","ME ","MD ", & + "MA ","MI ","MN ","MS ","MO ","MT ","NE ","NV ","NH ","NJ ", & + "NM ","NY ","NC ","ND ","OH ","OK ","OR ","PA ","RI ","SC ", & + "SD ","TN ","TX ","UT ","VT ","VA ","WA ","WV ","WI ","WY ", & + "NB ","NS ","QC ","ON ","MB ","SK ","AB ","BC ","NWT","NF ", & + "LB ","NU ","YT ","PEI","DC ","DR ","FR ","GD ","GR ","OV ", & + "ZH ","ZL ","X01","X02","X03","X04","X05","X06","X07","X08", & + "X09","X10","X11","X12","X13","X14","X15","X16","X17","X18", & + "X19","X20","X21","X22","X23","X24","X25","X26","X27","X28", & + "X29","X30","X31","X32","X33","X34","X35","X36","X37","X38", & + "X39","X40","X41","X42","X43","X44","X45","X46","X47","X48", & + "X49","X50","X51","X52","X53","X54","X55","X56","X57","X58", & + "X59","X60","X61","X62","X63","X64","X65","X66","X67","X68", & + "X69","X70","X71","X72","X73","X74","X75","X76","X77","X78", & + "X79","X80","X81","X82","X83","X84","X85","X86","X87","X88", & + "X89","X90","X91","X92","X93","X94","X95","X96","X97","X98", & + "X99"/ + data dxcall13_set/.false./ + data mycall13_set/.false./ + data mycall13_0/''/ + data dxcall13_0/''/ + + save hashmy10,hashmy12,hashmy22,hashdx10,hashdx12,hashdx22 + + if(mycall13.ne.mycall13_0) then + if(len(trim(mycall13)).gt.2) then + mycall13_set=.true. + mycall13_0=mycall13 + call save_hash_call(mycall13,hashmy10,hashmy12,hashmy22) + else + mycall13_set=.false. + endif + endif + + if(dxcall13.ne.dxcall13_0) then + if(len(trim(dxcall13)).gt.2) then + dxcall13_set=.true. + dxcall13_0=dxcall13 + hashdx10=ihashcall(dxcall13,10) + hashdx12=ihashcall(dxcall13,12) + hashdx22=ihashcall(dxcall13,22) + endif + endif + unpk77_success=.true. + +! Check for bad data + do i=1,77 + if(c77(i:i).ne.'0' .and. c77(i:i).ne.'1') then + msg='failed unpack' + unpk77_success=.false. + return + endif + enddo + + read(c77(72:77),'(2b3)') n3,i3 + msg=repeat(' ',37) + + if(i3.eq.0 .and. n3.eq.0) then +! 0.0 Free text + call unpacktext77(c77(1:71),msg(1:13)) + msg(14:)=' ' + msg=adjustl(msg) + if(msg(1:1).eq.' ') then + unpk77_success=.false. + return + endif + + else if(i3.eq.0 .and. n3.eq.1) then +! 0.1 K1ABC RR73; W9XYZ -11 28 28 10 5 71 DXpedition Mode + read(c77,1010) n28a,n28b,n10,n5 +1010 format(2b28,b10,b5) + irpt=2*n5 - 30 + write(crpt,1012) irpt +1012 format(i3.2) + if(irpt.ge.0) crpt(1:1)='+' + call unpack28(n28a,call_1,unpk28_success) + if(.not.unpk28_success .or. n28a.le.2) unpk77_success=.false. + call unpack28(n28b,call_2,unpk28_success) + if(.not.unpk28_success .or. n28b.le.2) unpk77_success=.false. + call hash10(n10,call_3) + if(nrx.eq.1 .and. & + dxcall13_set .and. & + hashdx10.eq.n10) call_3='<'//trim(dxcall13)//'>' + if(nrx.eq.0 .and. & + mycall13_set .and. & + n10.eq.hashmy10) call_3='<'//trim(mycall13)//'>' + msg=trim(call_1)//' RR73; '//trim(call_2)//' '//trim(call_3)//' '//crpt + + else if(i3.eq.0 .and. n3.eq.2) then + unpk77_success=.false. + + else if(i3.eq.0 .and. (n3.eq.3 .or. n3.eq.4)) then +! 0.3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day +! 0.4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day + read(c77,1030) n28a,n28b,ir,intx,nclass,isec +1030 format(2b28,b1,b4,b3,b7) + if(isec.gt.NSEC .or. isec.lt.1) then + unpk77_success=.false. + isec=1 + endif + call unpack28(n28a,call_1,unpk28_success) + if(.not.unpk28_success .or. n28a.le.2) unpk77_success=.false. + call unpack28(n28b,call_2,unpk28_success) + if(.not.unpk28_success .or. n28b.le.2) unpk77_success=.false. + ntx=intx+1 + if(n3.eq.4) ntx=ntx+16 + write(cntx(1:2),1032) ntx +1032 format(i2) + cntx(3:3)=char(ichar('A')+nclass) + if(ir.eq.0 .and. ntx.lt.10) msg=trim(call_1)//' '//trim(call_2)// & + cntx//' '//csec(isec) + if(ir.eq.1 .and. ntx.lt.10) msg=trim(call_1)//' '//trim(call_2)// & + ' R'//cntx//' '//csec(isec) + if(ir.eq.0 .and. ntx.ge.10) msg=trim(call_1)//' '//trim(call_2)// & + ' '//cntx//' '//csec(isec) + if(ir.eq.1 .and. ntx.ge.10) msg=trim(call_1)//' '//trim(call_2)// & + ' R '//cntx//' '//csec(isec) + + else if(i3.eq.0 .and. n3.eq.5) then +! 0.5 0123456789abcdef01 71 71 Telemetry (18 hex) + read(c77,1006) ntel +1006 format(b23,2b24) + write(msg,1007) ntel +1007 format(3z6.6) + do i=1,18 + if(msg(i:i).ne.'0') exit + msg(i:i)=' ' + enddo + msg=adjustl(msg) + + else if(i3.eq.0 .and. n3.eq.6) then + read(c77(48:50),'(3b1)') j48,j49,j50 +! bits 48:50 +! itype=1: x00 +! itype=2: xx1 +! itype=3: 010 + if(j50.eq.1) then + itype=2 + else if(j49.eq.0) then + itype=1 + else if(j48.eq.0) then + itype=3 + else + itype=-1 + unpk77_success=.false. + endif + + if(itype.eq.1) then +! WSPR Type 1 + read(c77,2010) n28,igrid4,idbm +2010 format(b28.28,b15.15,b5.5) + idbm=nint(idbm*10.0/3.0) + if(idbm.lt.0 .or. idbm.gt.60) unpk77_success=.false. + call unpack28(n28,call_1,unpk28_success) + if(.not.unpk28_success) unpk77_success=.false. + call to_grid4(igrid4,grid4,unpkg4_success) + if(.not.unpkg4_success) unpk77_success=.false. + write(crpt,'(i3)') idbm + msg=trim(call_1)//' '//grid4//' '//trim(adjustl(crpt)) + if (unpk77_success) call save_hash_call(call_1,n10,n12,n22) !### Is this OK here? ### + + else if(itype.eq.2) then +! WSPR Type 2 + read(c77,2020) n28,npfx,idbm +2020 format(b28.28,b16.16,b5.5) + idbm=nint(idbm*10.0/3.0) + if(idbm.lt.0 .or. idbm.gt.60) unpk77_success=.false. + call unpack28(n28,call_1,unpk28_success) + if(.not.unpk28_success) unpk77_success=.false. + write(crpt,'(i3)') idbm + cpfx=' ' + if(npfx.lt.nzzz) then +! Prefix + do i=3,1,-1 + j=mod(npfx,36)+1 + cpfx(i:i)=a2(j:j) + npfx=npfx/36 + if(npfx.eq.0) exit + enddo + msg=trim(adjustl(cpfx))//'/'//trim(call_1)//' '//trim(adjustl(crpt)) + call_1a=trim(adjustl(cpfx))//'/'//trim(call_1) + call save_hash_call(call_1a,n10,n12,n22) !### Is this OK here? ### + else +! Suffix + npfx=npfx-nzzz + if(npfx.le.35) then + cpfx(1:1)=a2(npfx+1:npfx+1) + else if(npfx.gt.35 .and. npfx.le.1295) then + cpfx(1:1)=a2(npfx/36+1:npfx/36+1) + cpfx(2:2)=a2(mod(npfx,36)+1:mod(npfx,36)+1) + else if(npfx.gt.1295 .and. npfx.le.12959) then + cpfx(1:1)=a2(npfx/360+1:npfx/360+1) + cpfx(2:2)=a2(mod(npfx/10,36)+1:mod(npfx/10,36)+1) + cpfx(3:3)=a2(mod(npfx,10)+1:mod(npfx,10)+1) + else + unpk77_success=.false. + return + endif + msg=trim(call_1)//'/'//trim(adjustl(cpfx))//' '//trim(adjustl(crpt)) + call_1a=trim(call_1)//'/'//trim(adjustl(cpfx)) + call save_hash_call(call_1a,n10,n12,n22) !### Is this OK here? ### + endif + + else if(itype.eq.3) then +! WSPR Type 3 + read(c77,2030) n22,igrid6 +2030 format(b22.22,b25.25) + n28=n22+2063592 + call unpack28(n28,call_1,unpk28_success) + if(.not.unpk28_success) unpk77_success=.false. + call to_grid(igrid6,grid6,unpkg4_success) + if(.not.unpkg4_success) unpk77_success=.false. + msg=trim(call_1)//' '//grid6 + endif + + else if(i3.eq.0 .and. n3.gt.6) then + unpk77_success=.false. + + else if(i3.eq.1 .or. i3.eq.2) then +! Type 1 (standard message) or Type 2 ("/P" form for EU VHF contest) + read(c77,1000) n28a,ipa,n28b,ipb,ir,igrid4,i3 +1000 format(2(b28,b1),b1,b15,b3) + call unpack28(n28a,call_1,unpk28_success) + if(nrx.eq.1 .and. mycall13_set .and. hashmy22.eq.(n28a-2063592)) then + call_1='<'//trim(mycall13)//'>' + unpk28_success=.true. + endif + if(.not.unpk28_success) unpk77_success=.false. + call unpack28(n28b,call_2,unpk28_success) + if(.not.unpk28_success) unpk77_success=.false. + if(call_1(1:3).eq.'CQ_') call_1(3:3)=' ' + if(index(call_1,'<').le.0) then + i=index(call_1,' ') + if(i.ge.4 .and. ipa.eq.1 .and. i3.eq.1) call_1(i:i+1)='/R' + if(i.ge.4 .and. ipa.eq.1 .and. i3.eq.2) call_1(i:i+1)='/P' + if(i.ge.4) call add_call_to_recent_calls(call_1) + endif + if(index(call_2,'<').le.0) then + i=index(call_2,' ') + if(i.ge.4 .and. ipb.eq.1 .and. i3.eq.1) call_2(i:i+1)='/R' + if(i.ge.4 .and. ipb.eq.1 .and. i3.eq.2) call_2(i:i+1)='/P' + if(i.ge.4) then + call add_call_to_recent_calls(call_2) +! only hash the "from" call + call save_hash_call(call_2,ndum10,ndum12,ndum22) + endif + endif + if(igrid4.le.MAXGRID4) then + call to_grid4(igrid4,grid4,unpkg4_success) + if(.not.unpkg4_success) unpk77_success=.false. + if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//grid4 + if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R '//grid4 + if(msg(1:3).eq.'CQ ' .and. ir.eq.1) unpk77_success=.false. + else + irpt=igrid4-MAXGRID4 + if(irpt.eq.1) msg=trim(call_1)//' '//trim(call_2) + if(irpt.eq.2) msg=trim(call_1)//' '//trim(call_2)//' RRR' + if(irpt.eq.3) msg=trim(call_1)//' '//trim(call_2)//' RR73' + if(irpt.eq.4) msg=trim(call_1)//' '//trim(call_2)//' 73' + if(irpt.ge.5) then + isnr=irpt-35 + if(isnr.gt.50) isnr=isnr-101 + write(crpt,'(i3.2)') isnr + if(crpt(1:1).eq.' ') crpt(1:1)='+' + if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//crpt + if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R'//crpt + endif + if(msg(1:3).eq.'CQ ' .and. irpt.ge.2) unpk77_success=.false. + endif + + else if(i3.eq.3) then +! Type 3: ARRL RTTY Contest + read(c77,1040) itu,n28a,n28b,ir,irpt,nexch,i3 +1040 format(b1,2b28.28,b1,b3.3,b13.13,b3.3) + write(crpt,1042) irpt+2 +1042 format('5',i1,'9') + nserial=nexch + imult=-1 + if(nexch.gt.8000) then + imult=nexch-8000 + nserial=-1 + endif + call unpack28(n28a,call_1,unpk28_success) + if(.not.unpk28_success) unpk77_success=.false. + call unpack28(n28b,call_2,unpk28_success) + if(.not.unpk28_success) unpk77_success=.false. + imult=0 + nserial=0 + if(nexch.gt.8000) imult=nexch-8000 + if(nexch.lt.8000) nserial=nexch + + if(imult.ge.1 .and.imult.le.NUSCAN) then + if(itu.eq.0 .and. ir.eq.0) msg=trim(call_1)//' '//trim(call_2)// & + ' '//crpt//' '//cmult(imult) + if(itu.eq.1 .and. ir.eq.0) msg='TU; '//trim(call_1)//' '//trim(call_2)// & + ' '//crpt//' '//cmult(imult) + if(itu.eq.0 .and. ir.eq.1) msg=trim(call_1)//' '//trim(call_2)// & + ' R '//crpt//' '//cmult(imult) + if(itu.eq.1 .and. ir.eq.1) msg='TU; '//trim(call_1)//' '//trim(call_2)// & + ' R '//crpt//' '//cmult(imult) + else if(nserial.ge.1 .and. nserial.le.7999) then + write(cserial,'(i4.4)') nserial + if(itu.eq.0 .and. ir.eq.0) msg=trim(call_1)//' '//trim(call_2)// & + ' '//crpt//' '//cserial + if(itu.eq.1 .and. ir.eq.0) msg='TU; '//trim(call_1)//' '//trim(call_2)// & + ' '//crpt//' '//cserial + if(itu.eq.0 .and. ir.eq.1) msg=trim(call_1)//' '//trim(call_2)// & + ' R '//crpt//' '//cserial + if(itu.eq.1 .and. ir.eq.1) msg='TU; '//trim(call_1)//' '//trim(call_2)// & + ' R '//crpt//' '//cserial + endif + else if(i3.eq.4) then +! Type 4 + read(c77,1050) n12,n58,iflip,nrpt,icq +1050 format(b12,b58,b1,b2,b1) + do i=11,1,-1 + j=mod(n58,38)+1 + c11(i:i)=c(j:j) + n58=n58/38 + enddo + call hash12(n12,call_3) + if(iflip.eq.0) then ! 12 bit hash for TO call + call_1=call_3 + call_2=adjustl(c11)//' ' + call add_call_to_recent_calls(call_2) + call save_hash_call(call_2,ndum10,ndum12,ndum22) + if(nrx.eq.1 .and. & + dxcall13_set .and. mycall13_set .and. & + call_2.eq.dxcall13 .and. & + n12.eq.hashmy12 ) call_1='<'//trim(mycall13)//'>' + if(nrx.eq.1 .and. & + mycall13_set .and. & + index(call_1,'<...>').gt.0 .and. & + n12.eq.hashmy12 ) call_1='<'//trim(mycall13)//'>' + else ! 12 bit hash for DE call + call_1=adjustl(c11) + call_2=call_3 + call add_call_to_recent_calls(call_1) + if(nrx.eq.0 .and. & + mycall13_set .and. & + n12.eq.hashmy12) call_2='<'//trim(mycall13)//'>' + endif + if(icq.eq.0) then + if(nrpt.eq.0) msg=trim(call_1)//' '//trim(call_2) + if(nrpt.eq.1) msg=trim(call_1)//' '//trim(call_2)//' RRR' + if(nrpt.eq.2) msg=trim(call_1)//' '//trim(call_2)//' RR73' + if(nrpt.eq.3) msg=trim(call_1)//' '//trim(call_2)//' 73' + else + msg='CQ '//trim(call_2) + endif + + else if(i3.eq.5) then + +! Type 5 R 590003 IO91NP h12 h22 r1 s3 S11 g25 +! EU VHF contest + read(c77,1060) n12,n22,ir,irpt,iserial,igrid6 +1060 format(b12,b22,b1,b3,b11,b25) + if(igrid6.lt.0 .or. igrid6.gt.18662399) then + unpk77_success=.false. + return + endif + call hash12(n12,call_1) + if(n12.eq.hashmy12) call_1='<'//trim(mycall13)//'>' + call hash22(n22,call_2) + nrs=52+irpt + write(cexch,1022) nrs,iserial +1022 format(i2,i4.4) + call to_grid6(igrid6,grid6,unpk77_success) + if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//cexch//' '//grid6 + if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R '//cexch//' '//grid6 + + else if(i3.ge.6) then ! i3 values 6 and 7 are not yet defined + unpk77_success=.false. + endif + if(msg(1:4).eq.'CQ <') unpk77_success=.false. + + return +end subroutine unpack77 + +subroutine pack28(c13,n28) + +! Pack a special token, a 22-bit hash code, or a valid base call into a 28-bit +! integer. + + parameter (NTOKENS=2063592,MAX22=4194304) + logical is_digit,is_letter + character*13 c13 + character*6 callsign + character*1 c + character*4 c4 + character*37 a1 + character*36 a2 + character*10 a3 + character*27 a4 + data a1/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ + data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ + data a3/'0123456789'/ + data a4/' ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ + + is_digit(c)=c.ge.'0' .and. c.le.'9' + is_letter(c)=c.ge.'A' .and. c.le.'Z' + + n28=-1 +! Work-around for Swaziland prefix: + if(c13(1:4).eq.'3DA0') callsign='3D0'//c13(5:7) +! Work-around for Guinea prefixes: + if(c13(1:2).eq.'3X' .and. c13(3:3).ge.'A' .and. & + c13(3:3).le.'Z') callsign='Q'//c13(3:6) + +! Check for special tokens first + if(c13(1:3).eq.'DE ') then + n28=0 + go to 900 + endif + + if(c13(1:4).eq.'QRZ ') then + n28=1 + go to 900 + endif + + if(c13(1:3).eq.'CQ ') then + n28=2 + go to 900 + endif + + if(c13(1:3).eq.'CQ_') then + n=len(trim(c13)) + if(n.ge.4 .and. n.le.7) then + nlet=0 + nnum=0 + do i=4,n + c=c13(i:i) + if(c.ge.'A' .and. c.le.'Z') nlet=nlet+1 + if(c.ge.'0' .and. c.le.'9') nnum=nnum+1 + enddo + if(nnum.eq.3 .and. nlet.eq.0) then + read(c13(4:3+nnum),*) nqsy + n28=3+nqsy + go to 900 + endif + if(nlet.ge.1 .and. nlet.le.4 .and. nnum.eq.0) then + c4=c13(4:n) + c4=adjustr(c4) + m=0 + do i=1,4 + j=0 + c=c4(i:i) + if(c.ge.'A' .and. c.le.'Z') j=ichar(c)-ichar('A')+1 + m=27*m + j + enddo + n28=3+1000+m + go to 900 + endif + endif + endif + +! Check for <...> callsign + if(c13(1:1).eq.'<')then + call save_hash_call(c13,n10,n12,n22) !Save callsign in hash table + i2=index(c13,'>') + c13=c13(2:i2-1) + n22=ihashcall(c13,22) + n28=NTOKENS + n22 + go to 900 + endif + +! Check for standard callsign + iarea=-1 + n=len(trim(c13)) + do i=n,2,-1 + if(is_digit(c13(i:i))) exit + enddo + iarea=i !Call-area digit + npdig=0 !Digits before call area + nplet=0 !Letters before call area + do i=1,iarea-1 + if(is_digit(c13(i:i))) npdig=npdig+1 + if(is_letter(c13(i:i))) nplet=nplet+1 + enddo + nslet=0 + do i=iarea+1,n + if(is_letter(c13(i:i))) nslet=nslet+1 + enddo + if(iarea.lt.2 .or. iarea.gt.3 .or. nplet.eq.0 .or. & + npdig.ge.iarea-1 .or. nslet.gt.3) then +! Treat this as a nonstandard callsign: compute its 22-bit hash + call save_hash_call(c13,n10,n12,n22) !Save callsign in hash table + n22=ihashcall(c13,22) + n28=NTOKENS + n22 + go to 900 + endif + + n=len(trim(c13)) +! This is a standard callsign + call save_hash_call(c13,n10,n12,n22) !Save callsign in hash table + if(iarea.eq.2) callsign=' '//c13(1:5) + if(iarea.eq.3) callsign=c13(1:6) + i1=index(a1,callsign(1:1))-1 + i2=index(a2,callsign(2:2))-1 + i3=index(a3,callsign(3:3))-1 + i4=index(a4,callsign(4:4))-1 + i5=index(a4,callsign(5:5))-1 + i6=index(a4,callsign(6:6))-1 + n28=36*10*27*27*27*i1 + 10*27*27*27*i2 + 27*27*27*i3 + 27*27*i4 + & + 27*i5 + i6 + n28=n28 + NTOKENS + MAX22 + +900 n28=iand(n28,ishft(1,28)-1) + return +end subroutine pack28 + + +subroutine unpack28(n28_0,c13,success) + + parameter (NTOKENS=2063592,MAX22=4194304) + logical success + character*13 c13 + character*37 c1 + character*36 c2 + character*10 c3 + character*27 c4 + data c1/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ + data c2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ + data c3/'0123456789'/ + data c4/' ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ + + success=.true. + n28=n28_0 + if(n28.lt.NTOKENS) then +! Special tokens DE, QRZ, CQ, CQ_nnn, CQ_aaaa + if(n28.eq.0) c13='DE ' + if(n28.eq.1) c13='QRZ ' + if(n28.eq.2) c13='CQ ' + if(n28.le.2) go to 900 + if(n28.le.1002) then + write(c13,1002) n28-3 +1002 format('CQ_',i3.3) + go to 900 + endif + if(n28.le.532443) then + n=n28-1003 + n0=n + i1=n/(27*27*27) + n=n-27*27*27*i1 + i2=n/(27*27) + n=n-27*27*i2 + i3=n/27 + i4=n-27*i3 + c13=c4(i1+1:i1+1)//c4(i2+1:i2+1)//c4(i3+1:i3+1)//c4(i4+1:i4+1) + c13=adjustl(c13) + c13='CQ_'//c13(1:10) + go to 900 + endif + endif + n28=n28-NTOKENS + if(n28.lt.MAX22) then +! This is a 22-bit hash of a callsign + n22=n28 + call hash22(n22,c13) !Retrieve callsign from hash table + go to 900 + endif + +! Standard callsign + n=n28 - MAX22 + i1=n/(36*10*27*27*27) + n=n-36*10*27*27*27*i1 + i2=n/(10*27*27*27) + n=n-10*27*27*27*i2 + i3=n/(27*27*27) + n=n-27*27*27*i3 + i4=n/(27*27) + n=n-27*27*i4 + i5=n/27 + i6=n-27*i5 + c13=c1(i1+1:i1+1)//c2(i2+1:i2+1)//c3(i3+1:i3+1)//c4(i4+1:i4+1)// & + c4(i5+1:i5+1)//c4(i6+1:i6+1) + c13=adjustl(c13) + +900 i0=index(c13,' ') + if(i0.ne.0 .and. i0.lt.len(trim(c13))) then + c13='QU1RK' + success=.false. + endif + return +end subroutine unpack28 + +subroutine split77(msg,nwords,nw,w) + +! Convert msg to upper case; collapse multiple blanks; parse into words. + + character*37 msg + character*13 w(19) + character*1 c,c0 + character*6 bcall_1 + logical ok1 + integer nw(19) + + iz=len(trim(msg)) + j=0 + k=0 + n=0 + c0=' ' + w=' ' + do i=1,iz + if(ichar(msg(i:i)).eq.0) msg(i:i)=' ' + c=msg(i:i) !Single character + if(c.eq.' ' .and. c0.eq.' ') cycle !Skip leading/repeated blanks + if(c.ne.' ' .and. c0.eq.' ') then + k=k+1 !New word + n=0 + endif + j=j+1 !Index in msg + n=n+1 !Index in word + if(c.ge.'a' .and. c.le.'z') c=char(ichar(c)-32) !Force upper case + msg(j:j)=c + if(n.le.13) w(k)(n:n)=c !Copy character c into word + c0=c + enddo + iz=j !Message length + nwords=k !Number of words in msg + if(nwords.le.0) go to 900 + do i=1,nwords + nw(i)=len(trim(w(i))) + enddo + msg(iz+1:)=' ' + if(nwords.lt.3) go to 900 + call chkcall(w(3),bcall_1,ok1) + if(ok1 .and. w(1)(1:3).eq.'CQ ') then + w(1)='CQ_'//w(2)(1:10) !Make "CQ " into "CQ_" + w(2:12)=w(3:13) !Move all remaining words down by one + nwords=nwords-1 + endif + +900 return +end subroutine split77 + + +subroutine pack77_01(nwords,w,i3,n3,c77) + +! Pack a Type 0.1 message: DXpedition mode +! Example message: "K1ABC RR73; W9XYZ -11" 28 28 10 5 + + character*13 w(19),c13 + character*77 c77 + character*6 bcall_1,bcall_2 + logical ok1,ok2 + + if(nwords.ne.5) go to 900 !Must have 5 words + if(trim(w(2)).ne.'RR73;') go to 900 !2nd word must be "RR73;" + if(w(4)(1:1).ne.'<') go to 900 !4th word must have <...> + if(index(w(4),'>').lt.1) go to 900 + n=-99 + read(w(5),*,err=1) n +1 if(n.eq.-99) go to 900 !5th word must be a valid report + n5=(n+30)/2 + if(n5.lt.0) n5=0 + if(n5.gt.31) n5=31 + call chkcall(w(1),bcall_1,ok1) + if(.not.ok1) go to 900 !1st word must be a valid basecall + call chkcall(w(3),bcall_2,ok2) + if(.not.ok2) go to 900 !3rd word must be a valid basecall + +! Type 0.1: K1ABC RR73; W9XYZ -11 28 28 10 5 71 + i3=0 + n3=1 + call pack28(w(1),n28a) + call pack28(w(3),n28b) + call save_hash_call(w(4),n10,n12,n22) + i2=index(w(4),'>') + c13=w(4)(2:i2-1) + n10=ihashcall(c13,10) + write(c77,1010) n28a,n28b,n10,n5,n3,i3 +1010 format(2b28.28,b10.10,b5.5,2b3.3) + +900 return +end subroutine pack77_01 + + +subroutine pack77_03(nwords,w,i3,n3,c77) + +! Check 0.3 and 0.4 (ARRL Field Day exchange) +! Example message: WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 + + parameter (NSEC=86) !Number of ARRL Sections + character*13 w(19) + character*77 c77 + character*6 bcall_1,bcall_2 + character*3 csec(NSEC) + logical ok1,ok2 + data csec/ & + "AB ","AK ","AL ","AR ","AZ ","BC ","CO ","CT ","DE ","EB ", & + "EMA","ENY","EPA","EWA","GA ","GH ","IA ","ID ","IL ","IN ", & + "KS ","KY ","LA ","LAX","NS ","MB ","MDC","ME ","MI ","MN ", & + "MO ","MS ","MT ","NC ","ND ","NE ","NFL","NH ","NL ","NLI", & + "NM ","NNJ","NNY","TER","NTX","NV ","OH ","OK ","ONE","ONN", & + "ONS","OR ","ORG","PAC","PR ","QC ","RI ","SB ","SC ","SCV", & + "SD ","SDG","SF ","SFL","SJV","SK ","SNJ","STX","SV ","TN ", & + "UT ","VA ","VI ","VT ","WCF","WI ","WMA","WNY","WPA","WTX", & + "WV ","WWA","WY ","DX ","PE ","NB "/ + + if(nwords.lt.4 .or. nwords.gt.5) return + call chkcall(w(1),bcall_1,ok1) + call chkcall(w(2),bcall_2,ok2) + if(.not.ok1 .or. .not.ok2) return + isec=-1 + do i=1,NSEC + if(csec(i).eq.w(nwords)(1:3)) then + isec=i + exit + endif + enddo + if(isec.eq.-1) return + if(nwords.eq.5 .and. trim(w(3)).ne.'R') return + + ntx=-1 + j=len(trim(w(nwords-1)))-1 + read(w(nwords-1)(1:j),*,err=1,end=1) ntx !Number of transmitters +1 if(ntx.lt.1 .or. ntx.gt.32) return + nclass=ichar(w(nwords-1)(j+1:j+1))-ichar('A') + + m=len(trim(w(nwords))) !Length of section abbreviation + if(m.lt.2 .or. m.gt.3) return + +! 0.3 WA9XYZ KA1ABC R 16A EMA 28 28 1 4 3 7 71 ARRL Field Day +! 0.4 WA9XYZ KA1ABC R 32A EMA 28 28 1 4 3 7 71 ARRL Field Day + + i3=0 + n3=3 !Type 0.3 ARRL Field Day + intx=ntx-1 + if(intx.ge.16) then + n3=4 !Type 0.4 ARRL Field Day + intx=ntx-17 + endif + call pack28(w(1),n28a) + call pack28(w(2),n28b) + ir=0 + if(w(3)(1:2).eq.'R ') ir=1 + write(c77,1010) n28a,n28b,ir,intx,nclass,isec,n3,i3 +1010 format(2b28.28,b1,b4.4,b3.3,b7.7,2b3.3) + + return +end subroutine pack77_03 + + +subroutine pack77_06(nwords,w,i3,n3,c77,i3_hint,n3_hint) + + character*13 w(19) + character*77 c77 + character*6 bcall,grid6 + character*4 grid4 + character*1 c + character*36 a2 + data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/,nzzz/46656/ + + logical is_grid4,is_grid6,is_digit,ok + is_grid4(grid4)=len(trim(grid4)).eq.4 .and. & + grid4(1:1).ge.'A' .and. grid4(1:1).le.'R' .and. & + grid4(2:2).ge.'A' .and. grid4(2:2).le.'R' .and. & + grid4(3:3).ge.'0' .and. grid4(3:3).le.'9' .and. & + grid4(4:4).ge.'0' .and. grid4(4:4).le.'9' + + is_grid6(grid6)=(len(trim(grid6)).eq.6.or.len(trim(grid6)).eq.4).and. & + grid6(1:1).ge.'A' .and. grid6(1:1).le.'R' .and. & + grid6(2:2).ge.'A' .and. grid6(2:2).le.'R' .and. & + grid6(3:3).ge.'0' .and. grid6(3:3).le.'9' .and. & + grid6(4:4).ge.'0' .and. grid6(4:4).le.'9' .and. & + (len(trim(grid6)).eq.4.or. & + (grid6(5:5).ge.'A' .and. grid6(5:5).le.'X' .and. & + grid6(6:6).ge.'A' .and. grid6(6:6).le.'X')) + + is_digit(c)=c.ge.'0' .and. c.le.'9' + + m1=len(trim(w(1))) + m2=len(trim(w(2))) + m3=len(trim(w(3))) + if(nwords.eq.3 .and. m1.ge.3 .and. m1.le.6 .and. m2.eq.4 .and. m3.le.2) then +! WSPR Type 1 + if(.not.is_grid4(w(2)(1:4))) go to 900 + if(.not.is_digit(w(3)(1:1))) go to 900 + if(m3.eq.2) then + if(.not.is_digit(w(3)(2:2))) go to 900 + endif + i3=0 + n3=6 + call pack28(w(1),n28) + grid4=w(2)(1:4) + k1=(ichar(grid4(1:1))-ichar('A'))*18*10*10 + k2=(ichar(grid4(2:2))-ichar('A'))*10*10 + k3=(ichar(grid4(3:3))-ichar('0'))*10 + k4=(ichar(grid4(4:4))-ichar('0')) + igrid4=k1+k2+k3+k4 + read(w(3),*) idbm + if(idbm.lt.0) idbm=0 + if(idbm.gt.60) idbm=60 + idbm=nint(0.3*idbm) + write(c77,1010) n28,igrid4,idbm,0,0,0,n3,i3 +1010 format(b28.28,b15.15,b5.5,2i1,b21.21,2b3.3) + go to 900 + endif + if(nwords.eq.2 .and. m1.ge.5 .and. m1.le.10 .and. m2.le.2) then +! WSPR Type 2 + i1=index(w(1),'/') + if(i1.lt.2 .or. i1.eq.m1) go to 900 + if(.not.is_digit(w(2)(1:1))) go to 900 + if(i1.eq.(m1-3) .and. .not.is_digit(w(1)(m1:m1))) go to 900 + if(m2.eq.2) then + if(.not.is_digit(w(2)(2:2))) go to 900 + endif + call chkcall(w(1),bcall,ok) + if(.not.ok) go to 900 + if(i1.le.4) then +! We have a prefix + npfx=index(a2,w(1)(1:1))-1 + if(i1.ge.3) npfx=36*npfx + index(a2,w(1)(2:2))-1 + if(i1.eq.4) npfx=36*npfx + index(a2,w(1)(3:3))-1 + else +! We have a suffix + if((m1-i1).eq.1) npfx=index(a2,w(1)(i1+1:i1+1))-1 + if((m1-i1).eq.2) npfx=36*(index(a2,w(1)(i1+1:i1+1))-1) + & + index(a2,w(1)(i1+2:i1+2))-1 + if((m1-i1).eq.3) then +! Third character of a suffix must be a digit + if(.not.is_digit(w(1)(i1+3:i1+3))) go to 900 + npfx=36*10*(index(a2,w(1)(i1+1:i1+1))-1) + & + 10*(index(a2,w(1)(i1+2:i1+2))-1) + index(a2,w(1)(i1+3:i1+3))-1 + endif + npfx=npfx + nzzz + endif + i3=0 + n3=6 + call pack28(bcall//' ',n28) + read(w(2),*) idbm + if(idbm.lt.0) idbm=0 + if(idbm.gt.60) idbm=60 + idbm=nint(0.3*idbm) + write(c77,1020) n28,npfx,idbm,1,0,n3,i3 +1020 format(b28.28,b16.16,b5.5,i1,b21.21,2b3.3) + go to 900 + endif + + if(i3_hint.eq.0.and.n3_hint.eq.6.and.nwords.eq.2 .and. m1.ge.5 & + .and. m1.le.12 .and. m2.le.6) then +! WSPR Type 3 + + !n3_hint=6 and i3_hint=0 is a hint that the caller wanted a + !50-bit encoding rather than the possible alternative n3=4 77-bit + !encoding + if(index(w(1),'<').lt.1 .or. index(w(1),'>').lt.1) go to 900 + grid6=w(2)(1:6) + if(.not.is_grid6(grid6)) go to 900 + i3=0 + n3=6 + call pack28(w(1),n28) + n22=n28-2063592 + k1=(ichar(grid6(1:1))-ichar('A'))*18*10*10*25*25 + k2=(ichar(grid6(2:2))-ichar('A'))*10*10*25*25 + k3=(ichar(grid6(3:3))-ichar('0'))*10*25*25 + k4=(ichar(grid6(4:4))-ichar('0'))*25*25 + if (grid6(5:6).eq.' ') then + igrid6=k1+k2+k3+k4+24*25+24 + else + k5=(ichar(grid6(5:5))-ichar('A'))*25 + k6=(ichar(grid6(6:6))-ichar('A')) + igrid6=k1+k2+k3+k4+k5+k6 + endif + write(c77,1030) n22,igrid6,2,0,n3,i3 +1030 format(b22.22,b25.25,b3.3,b21.21,2b3.3) + endif + +900 return +end subroutine pack77_06 + + +subroutine pack77_1(nwords,w,i3,n3,c77) + +! Check Type 1 (Standard 77-bit message) and Type 2 (ditto, with a "/P" call) +! Example message: WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 + + parameter (MAXGRID4=32400) + character*13 w(19),c13 + character*77 c77 + character*6 bcall_1,bcall_2 + character*4 grid4 + character c1*1,c2*2 + logical is_grid4 + logical ok1,ok2 + is_grid4(grid4)=len(trim(grid4)).eq.4 .and. & + grid4(1:1).ge.'A' .and. grid4(1:1).le.'R' .and. & + grid4(2:2).ge.'A' .and. grid4(2:2).le.'R' .and. & + grid4(3:3).ge.'0' .and. grid4(3:3).le.'9' .and. & + grid4(4:4).ge.'0' .and. grid4(4:4).le.'9' + + if(nwords.lt.2 .or. nwords.gt.4) return + call chkcall(w(1),bcall_1,ok1) + call chkcall(w(2),bcall_2,ok2) + if(w(1)(1:3).eq.'DE ' .or. w(1)(1:3).eq.'CQ_' .or. w(1)(1:3).eq.'CQ ' .or. & + w(1)(1:4).eq.'QRZ ') ok1=.true. + if(w(1)(1:1).eq.'<' .and. index(w(1),'>').ge.5) ok1=.true. + if(w(2)(1:1).eq.'<' .and. index(w(2),'>').ge.5) ok2=.true. + if(.not.ok1 .or. .not.ok2) return + if(w(1)(1:1).eq.'<' .and. index(w(2),'/').gt.0) return + if(w(2)(1:1).eq.'<' .and. index(w(1),'/').gt.0) return + if(nwords.eq.2 .and. (.not.ok2 .or. index(w(2),'/').ge.2)) return + if(nwords.eq.2) go to 10 + + c1=w(nwords)(1:1) + c2=w(nwords)(1:2) + if(.not.is_grid4(w(nwords)(1:4)) .and. c1.ne.'+' .and. c1.ne.'-' & + .and. c2.ne.'R+' .and. c2.ne.'R-' .and. trim(w(nwords)).ne.'RRR' .and. & + trim(w(nwords)).ne.'RR73' .and. trim(w(nwords)).ne.'73') return + if(c1.eq.'+' .or. c1.eq.'-') then + ir=0 + read(w(nwords),*,err=900) irpt + if(irpt.ge.-50 .and. irpt.le.-31) irpt=irpt+101 + irpt=irpt+35 + else if(c2.eq.'R+' .or. c2.eq.'R-') then + ir=1 + read(w(nwords)(2:),*,err=900) irpt + if(irpt.ge.-50 .and. irpt.le.-31) irpt=irpt+101 + irpt=irpt+35 + else if(trim(w(nwords)).eq.'RRR') then + ir=0 + irpt=2 + else if(trim(w(nwords)).eq.'RR73') then + ir=0 + irpt=3 + else if(trim(w(nwords)).eq.'73') then + ir=0 + irpt=4 + endif + +! 1 WA9XYZ/R KA1ABC/R R FN42 28 1 28 1 1 15 74 Standard msg +! 2 PA3XYZ/P GM4ABC/P R JO22 28 1 28 1 1 15 74 EU VHF contest + +10 i1psuffix=index(w(1)//' ' ,'/P ') + i2psuffix=index(w(2)//' ','/P ') + if(nwords.eq.2 .or. nwords.eq.3 .or. (nwords.eq.4 .and. & + w(3)(1:2).eq.'R ')) then + n3=0 + i3=1 !Type 1: Standard message, possibly with "/R" + if (i1psuffix.ge.4.or.i2psuffix.ge.4) i3=2 !Type 2, with "/P" + endif + c13=bcall_1 + if(c13(1:3).eq.'CQ_' .or. w(1)(1:1).eq.'<') c13=w(1) + call pack28(c13,n28a) + c13=bcall_2 + if(w(2)(1:1).eq.'<') c13=w(2) + call pack28(c13,n28b) + ipa=0 + ipb=0 + if(i1psuffix.ge.4.or.index(w(1)//' ','/R ').ge.4) ipa=1 + if(i2psuffix.ge.4.or.index(w(2)//' ','/R ').ge.4) ipb=1 + + grid4=w(nwords)(1:4) + if(is_grid4(grid4)) then + ir=0 + if(w(3).eq.'R ') ir=1 + j1=(ichar(grid4(1:1))-ichar('A'))*18*10*10 + j2=(ichar(grid4(2:2))-ichar('A'))*10*10 + j3=(ichar(grid4(3:3))-ichar('0'))*10 + j4=(ichar(grid4(4:4))-ichar('0')) + igrid4=j1+j2+j3+j4 + else + igrid4=MAXGRID4 + irpt + endif + if(nwords.eq.2) then + ir=0 + irpt=1 + igrid4=MAXGRID4+irpt + endif + write(c77,1000) n28a,ipa,n28b,ipb,ir,igrid4,i3 +1000 format(2(b28.28,b1),b1,b15.15,b3.3) + return + +900 return +end subroutine pack77_1 + + +subroutine pack77_3(nwords,w,i3,n3,c77) + +! Check Type 3 (ARRL RTTY contest exchange) +! ARRL RTTY - US/Can: rpt state/prov R 579 MA +! - DX: rpt serial R 559 0013 +! Example message: TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 + + parameter (NUSCAN=171) !Number of US states and Canadian provinces/territories + character*13 w(19) + character*77 c77 + character*6 bcall_1,bcall_2 + character*3 cmult(NUSCAN),mult + character crpt*3 + logical ok1,ok2 + data cmult/ & + "AL ","AK ","AZ ","AR ","CA ","CO ","CT ","DE ","FL ","GA ", & + "HI ","ID ","IL ","IN ","IA ","KS ","KY ","LA ","ME ","MD ", & + "MA ","MI ","MN ","MS ","MO ","MT ","NE ","NV ","NH ","NJ ", & + "NM ","NY ","NC ","ND ","OH ","OK ","OR ","PA ","RI ","SC ", & + "SD ","TN ","TX ","UT ","VT ","VA ","WA ","WV ","WI ","WY ", & + "NB ","NS ","QC ","ON ","MB ","SK ","AB ","BC ","NWT","NF ", & + "LB ","NU ","YT ","PEI","DC ","DR ","FR ","GD ","GR ","OV ", & + "ZH ","ZL ","X01","X02","X03","X04","X05","X06","X07","X08", & + "X09","X10","X11","X12","X13","X14","X15","X16","X17","X18", & + "X19","X20","X21","X22","X23","X24","X25","X26","X27","X28", & + "X29","X30","X31","X32","X33","X34","X35","X36","X37","X38", & + "X39","X40","X41","X42","X43","X44","X45","X46","X47","X48", & + "X49","X50","X51","X52","X53","X54","X55","X56","X57","X58", & + "X59","X60","X61","X62","X63","X64","X65","X66","X67","X68", & + "X69","X70","X71","X72","X73","X74","X75","X76","X77","X78", & + "X79","X80","X81","X82","X83","X84","X85","X86","X87","X88", & + "X89","X90","X91","X92","X93","X94","X95","X96","X97","X98", & + "X99"/ + + if(w(1)(1:1).eq.'<' .and. w(2)(1:1).eq.'<') go to 900 + if(nwords.eq.4 .or. nwords.eq.5 .or. nwords.eq.6) then + i1=1 + if(trim(w(1)).eq.'TU;') i1=2 + call chkcall(w(i1),bcall_1,ok1) + call chkcall(w(i1+1),bcall_2,ok2) + if(.not.ok1 .or. .not.ok2) go to 900 + crpt=w(nwords-1)(1:3) + if(index(crpt,'-').ge.1 .or. index(crpt,'+').ge.1) go to 900 + if(crpt(1:1).eq.'5' .and. crpt(2:2).ge.'2' .and. crpt(2:2).le.'9' .and. & + crpt(3:3).eq.'9') then + nserial=0 + read(w(nwords),*,err=1) nserial + endif +1 mult=' ' + imult=-1 + do i=1,NUSCAN + if(cmult(i).eq.w(nwords)) then + imult=i + mult=cmult(i) + exit + endif + enddo + nexch=0 + if(nserial.gt.0) nexch=nserial + if(imult.gt.0) nexch=8000+imult + if(mult.ne.' ' .or. nserial.gt.0) then + i3=3 + n3=0 + itu=0 + if(trim(w(1)).eq.'TU;') itu=1 + call pack28(w(1+itu),n28a) + call pack28(w(2+itu),n28b) + ir=0 + if(w(3+itu)(1:2).eq.'R ') ir=1 + read(w(3+itu+ir),*,err=900) irpt + irpt=(irpt-509)/10 - 2 + if(irpt.lt.0) irpt=0 + if(irpt.gt.7) irpt=7 +! 3 TU; W9XYZ K1ABC R 579 MA 1 28 28 1 3 13 74 ARRL RTTY contest +! 3 TU; W9XYZ G8ABC R 559 0013 1 28 28 1 3 13 74 ARRL RTTY (DX) + write(c77,1010) itu,n28a,n28b,ir,irpt,nexch,i3 +1010 format(b1,2b28.28,b1,b3.3,b13.13,b3.3) + endif + endif + +900 return +end subroutine pack77_3 + + +subroutine pack77_4(nwords,w,i3,n3,c77) + +! Check Type 4 (One nonstandard call and one hashed call) +! Example message: PJ4/KA1ABC RR73 12 58 1 2 1 74 + + integer*8 n58 + logical ok1,ok2 + character*13 w(19) + character*77 c77 + character*13 call_1,call_2 + character*11 c11 + character*6 bcall_1,bcall_2 + character*38 c + data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ + + iflip=0 + i3=-1 + if(nwords.eq.2 .or. nwords.eq.3) then + call_1=w(1) + if(call_1(1:1).eq.'<') call_1=w(1)(2:len(trim(w(1)))-1) + call_2=w(2) + if(call_2(1:1).eq.'<') call_2=w(2)(2:len(trim(w(2)))-1) + call chkcall(call_1,bcall_1,ok1) + call chkcall(call_2,bcall_2,ok2) + if(call_1.eq.bcall_1 .and. call_2.eq.bcall_2 .and. ok1 .and. ok2) go to 900 + icq=0 + if(trim(w(1)).eq.'CQ' .or. (ok1.and.ok2)) then + if(trim(w(1)).eq.'CQ' .and. len(trim(w(2))).le.4) go to 900 + i3=4 + n3=0 + if(trim(w(1)).eq.'CQ') icq=1 + endif + + if(icq.eq.1) then + iflip=0 + n12=0 + c11=adjustr(call_2(1:11)) + call save_hash_call(w(2),n10,n12,n22) + else if(w(1)(1:1).eq.'<') then + iflip=0 + i3=4 + call save_hash_call(w(1),n10,n12,n22) + c11=adjustr(call_2(1:11)) + else if(w(2)(1:1).eq.'<') then + iflip=1 + i3=4 + call save_hash_call(w(2),n10,n12,n22) + c11=adjustr(call_1(1:11)) + endif + n58=0 + do i=1,11 + n58=n58*38 + index(c,c11(i:i)) - 1 + enddo + nrpt=0 + if(trim(w(3)).eq.'RRR') nrpt=1 + if(trim(w(3)).eq.'RR73') nrpt=2 + if(trim(w(3)).eq.'73') nrpt=3 + if(icq.eq.1) then + iflip=0 + nrpt=0 + endif + write(c77,1010) n12,n58,iflip,nrpt,icq,i3 +1010 format(b12.12,b58.58,b1,b2.2,b1,b3.3) + do i=1,77 + if(c77(i:i).eq.'*') c77(i:i)='0' !### Clean up any illegal chars ### + enddo + endif + +900 return +end subroutine pack77_4 + +subroutine pack77_5(nwords,w,i3,n3,c77) + +! Pack a Type 0.2 message: EU VHF Contest mode +! Example message: PA3XYZ/P R 590003 IO91NP 28 1 1 3 12 25 +! R 590003 IO91NP h10 h20 r1 s3 s12 g25 + + character*13 w(19),c13 + character*77 c77 + character*6 grid6 + logical is_grid6 + + is_grid6(grid6)=len(trim(grid6)).eq.6 .and. & + grid6(1:1).ge.'A' .and. grid6(1:1).le.'R' .and. & + grid6(2:2).ge.'A' .and. grid6(2:2).le.'R' .and. & + grid6(3:3).ge.'0' .and. grid6(3:3).le.'9' .and. & + grid6(4:4).ge.'0' .and. grid6(4:4).le.'9' .and. & + grid6(5:5).ge.'A' .and. grid6(5:5).le.'X' .and. & + grid6(6:6).ge.'A' .and. grid6(6:6).le.'X' + + if(nwords.lt.4 .or. nwords.gt.5) return !nwords must be 4 or 5 + if(w(1)(1:1).ne.'<' .or. w(2)(1:1).ne.'<') return !Both calls must be hashed + nx=-1 + read(w(nwords-1),*,err=2) nx +2 if(nx.lt.520001 .or. nx.gt.594095) return !Exchange between 520001 - 594095 + if(.not.is_grid6(w(nwords)(1:6))) return !Last word must be a valid grid6 + +! Type 0.2: R 590003 IO91NP h10 h20 r1 s3 s12 g25 + + i3=5 + n3=0 + + call save_hash_call(w(1),n10,n12,n22) + i2=index(w(1),'>') + c13=w(1)(2:i2-1) + n12=ihashcall(c13,12) + + call save_hash_call(w(2),n10a,n12a,n22) + i2=index(w(2),'>') + c13=w(2)(2:i2-1) + n22=ihashcall(c13,22) + + ir=0 + if(w(3)(1:2).eq.'R ') ir=1 + irpt=nx/10000 - 52 + iserial=mod(nx,10000) + if(iserial.gt.2047) iserial=2047 + grid6=w(nwords)(1:6) + j1=(ichar(grid6(1:1))-ichar('A'))*18*10*10*24*24 + j2=(ichar(grid6(2:2))-ichar('A'))*10*10*24*24 + j3=(ichar(grid6(3:3))-ichar('0'))*10*24*24 + j4=(ichar(grid6(4:4))-ichar('0'))*24*24 + j5=(ichar(grid6(5:5))-ichar('A'))*24 + j6=(ichar(grid6(6:6))-ichar('A')) + igrid6=j1+j2+j3+j4+j5+j6 + + write(c77,1010) n12,n22,ir,irpt,iserial,igrid6,i3 +1010 format(b12.12,b22.22,b1,b3.3,b11.11,b25.25,b3.3) + + return +end subroutine pack77_5 + + +subroutine packtext77(c13,c71) + + character*13 c13,w + character*71 c71 + character*42 c + character*1 qa(10),qb(10) + data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/ + + call mp_short_init + qa=char(0) + w=adjustr(c13) + do i=1,13 + j=index(c,w(i:i))-1 + if(j.lt.0) j=0 + call mp_short_mult(qb,qa(2:10),9,42) !qb(1:9)=42*qa(2:9) + call mp_short_add(qa,qb(2:10),9,j) !qa(1:9)=qb(2:9)+j + enddo + + write(c71,1010) qa(2:10) +1010 format(b7.7,8b8.8) + + return +end subroutine packtext77 + +subroutine unpacktext77(c71,c13) + + integer*1 ia(10) + character*1 qa(10),qb(10) + character*13 c13 + character*71 c71 + character*42 c + equivalence (qa,ia),(qb,ib) + data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/ + + qa(1)=char(0) + read(c71,1010) qa(2:10) +1010 format(b7.7,8b8.8) + + do i=13,1,-1 + call mp_short_div(qb,qa(2:10),9,42,ir) + c13(i:i)=c(ir+1:ir+1) + qa(2:10)=qb(1:9) + enddo + + return +end subroutine unpacktext77 + +subroutine mp_short_ops(w,u) + character*1 w(*),u(*) + integer i,ireg,j,n,ir,iv,ii1,ii2 + character*1 creg(4) + save ii1,ii2 + equivalence (ireg,creg) + + entry mp_short_init + ireg=256*ichar('2')+ichar('1') + do j=1,4 + if (creg(j).eq.'1') ii1=j + if (creg(j).eq.'2') ii2=j + enddo + return + + entry mp_short_add(w,u,n,iv) + ireg=256*iv + do j=n,1,-1 + ireg=ichar(u(j))+ichar(creg(ii2)) + w(j+1)=creg(ii1) + enddo + w(1)=creg(ii2) + return + + entry mp_short_mult(w,u,n,iv) + ireg=0 + do j=n,1,-1 + ireg=ichar(u(j))*iv+ichar(creg(ii2)) + w(j+1)=creg(ii1) + enddo + w(1)=creg(ii2) + return + + entry mp_short_div(w,u,n,iv,ir) + ir=0 + do j=1,n + i=256*ir+ichar(u(j)) + w(j)=char(i/iv) + ir=mod(i,iv) + enddo + return + + return +end subroutine mp_short_ops + +subroutine add_call_to_recent_calls(callsign) + + character*13 callsign + logical ladd + +! only add if the callsign is not already on the list + ladd=.true. + do i=1,MAXRECENT-1 ! if callsign is at the end of the list add it again + if(recent_calls(i).eq.callsign) ladd=.false. + enddo + + if(ladd) then + do i=MAXRECENT,2,-1 + recent_calls(i)=recent_calls(i-1) + enddo + recent_calls(1)=callsign + endif + +! Make sure that callsign is hashed +! call save_hash_call(callsign,n10,n12,n22) ! commented out - do this in the calling routine: + + return +end subroutine add_call_to_recent_calls + +subroutine to_grid4(n,grid4,ok) + character*4 grid4 + logical ok + + ok=.false. + j1=n/(18*10*10) + if (j1.lt.0.or.j1.gt.17) goto 900 + n=n-j1*18*10*10 + j2=n/(10*10) + if (j2.lt.0.or.j2.gt.17) goto 900 + n=n-j2*10*10 + j3=n/10 + if (j3.lt.0.or.j3.gt.9) goto 900 + j4=n-j3*10 + if (j4.lt.0.or.j4.gt.9) goto 900 + grid4(1:1)=char(j1+ichar('A')) + grid4(2:2)=char(j2+ichar('A')) + grid4(3:3)=char(j3+ichar('0')) + grid4(4:4)=char(j4+ichar('0')) + ok=.true. + +900 return +end subroutine to_grid4 + +subroutine to_grid6(n,grid6,ok) + character*6 grid6 + logical ok + + ok=.false. + j1=n/(18*10*10*24*24) + if (j1.lt.0.or.j1.gt.17) goto 900 + n=n-j1*18*10*10*24*24 + j2=n/(10*10*24*24) + if (j2.lt.0.or.j2.gt.17) goto 900 + n=n-j2*10*10*24*24 + j3=n/(10*24*24) + if (j3.lt.0.or.j3.gt.9) goto 900 + n=n-j3*10*24*24 + j4=n/(24*24) + if (j4.lt.0.or.j4.gt.9) goto 900 + n=n-j4*24*24 + j5=n/24 + if (j5.lt.0.or.j5.gt.23) goto 900 + j6=n-j5*24 + if (j6.lt.0.or.j6.gt.23) goto 900 + grid6(1:1)=char(j1+ichar('A')) + grid6(2:2)=char(j2+ichar('A')) + grid6(3:3)=char(j3+ichar('0')) + grid6(4:4)=char(j4+ichar('0')) + grid6(5:5)=char(j5+ichar('A')) + grid6(6:6)=char(j6+ichar('A')) + ok=.true. + +900 return +end subroutine to_grid6 + +subroutine to_grid(n,grid6,ok) + ! 4-, or 6-character grid + character*6 grid6 + logical ok + + ok=.false. + j1=n/(18*10*10*25*25) + if (j1.lt.0.or.j1.gt.17) goto 900 + n=n-j1*18*10*10*25*25 + j2=n/(10*10*25*25) + if (j2.lt.0.or.j2.gt.17) goto 900 + n=n-j2*10*10*25*25 + j3=n/(10*25*25) + if (j3.lt.0.or.j3.gt.9) goto 900 + n=n-j3*10*25*25 + j4=n/(25*25) + if (j4.lt.0.or.j4.gt.9) goto 900 + n=n-j4*25*25 + j5=n/25 + if (j5.lt.0.or.j5.gt.24) goto 900 + j6=n-j5*25 + if (j6.lt.0.or.j6.gt.24) goto 900 + grid6='' + grid6(1:1)=char(j1+ichar('A')) + grid6(2:2)=char(j2+ichar('A')) + grid6(3:3)=char(j3+ichar('0')) + grid6(4:4)=char(j4+ichar('0')) + if (j5.ne.24.or.j6.ne.24) then + grid6(5:5)=char(j5+ichar('A')) + grid6(6:6)=char(j6+ichar('A')) + endif + ok=.true. + +900 return +end subroutine to_grid + +end module packjt77 diff --git a/lib/77bit/parse77.f90 b/lib/77bit/parse77.f90 index 9107ed4d..a0a8b861 100755 --- a/lib/77bit/parse77.f90 +++ b/lib/77bit/parse77.f90 @@ -1,11 +1,11 @@ -subroutine parse77(msg,i3,n3) - - use packjt77 - character msg*37,c77*77 - - i3=-1 - n3=-1 - call pack77(msg,i3,n3,c77) - - return -end subroutine parse77 +subroutine parse77(msg,i3,n3) + + use packjt77 + character msg*37,c77*77 + + i3=-1 + n3=-1 + call pack77(msg,i3,n3,c77) + + return +end subroutine parse77 diff --git a/lib/77bit/test28.f90 b/lib/77bit/test28.f90 index 51cf069f..30ce1544 100755 --- a/lib/77bit/test28.f90 +++ b/lib/77bit/test28.f90 @@ -1,63 +1,63 @@ -program test28 - - use packjt77 - parameter (NTOKENS=2063592,MAX22=4194304) - character*13 arg,call_00,call_0,call_1 - character*1 cerr - logical unpk28_success - - nargs=iargc() - n28=-1 - if(nargs.eq.1) then - call getarg(1,arg) - read(arg,'(i13)',err=2) n28 - endif - if(n28.ge.0) go to 100 - -2 open(10,file='test28.txt',status='old') - - write(*,1000) -1000 format('Encoded text Recovered text n28 Err? Type'/60('-')) - - do iline=1,999999 - if(nargs.eq.0) then - read(10,'(a13)',end=999) call_0 - else - call_0=arg - endif - if(call_0.eq.' ') exit - if(call_0(1:3).eq.'CQ ' .and. call_0(4:4).ne.' ') call_0(3:3)='_' - call_1=' ' - call_00=call_0 - call pack28(call_00,n28) - call unpack28(n28,call_1,unpk28_success) - cerr=' ' - if(call_0.ne.call_1) cerr='*' - if(call_0(1:3).eq.'CQ_') call_0(3:3)=' ' - if(call_1(1:3).eq.'CQ_') call_1(3:3)=' ' - if(n28.lt.NTOKENS) write(*,1010) call_0,call_1,n28,cerr -1010 format(a13,2x,a13,i10,2x,a1,2x,'Special token') - if(n28.ge.NTOKENS .and. n28.lt.NTOKENS+MAX22) then - call_00=call_0 - call save_hash_call(call_00,n10,n12,n22) - write(*,1012) call_0,call_1,n28,cerr,n22 -1012 format(a13,2x,a13,i10,2x,a1,2x,'22-bit hash',i15) - endif - if(n28.ge.NTOKENS+MAX22) write(*,1014) call_0,call_1,n28,cerr -1014 format(a13,2x,a13,i10,2x,a1,2x,'Standard callsign') - if(nargs.gt.0) exit - enddo - go to 999 - -100 call unpack28(n28,call_1,unpk28_success) - cerr=' ' - if(.not.unpk28_success) cerr='*' - if(call_1(1:3).eq.'CQ_') call_1(3:3)=' ' - if(n28.lt.NTOKENS) write(*,2010) n28,call_1,cerr -2010 format(i10,2x,a13,2x,a1,2x,'Special token') - if(n28.ge.NTOKENS .and. n28.lt.NTOKENS+MAX22) write(*,2012) n28,call_1,cerr -2012 format(i10,2x,a13,2x,a1,2x,'22-bit hash') - if(n28.ge.NTOKENS+MAX22) write(*,2014) n28,call_1,cerr -2014 format(i10,2x,a13,2x,a1,2x,'Standard callsign') - -999 end program test28 +program test28 + + use packjt77 + parameter (NTOKENS=2063592,MAX22=4194304) + character*13 arg,call_00,call_0,call_1 + character*1 cerr + logical unpk28_success + + nargs=iargc() + n28=-1 + if(nargs.eq.1) then + call getarg(1,arg) + read(arg,'(i13)',err=2) n28 + endif + if(n28.ge.0) go to 100 + +2 open(10,file='test28.txt',status='old') + + write(*,1000) +1000 format('Encoded text Recovered text n28 Err? Type'/60('-')) + + do iline=1,999999 + if(nargs.eq.0) then + read(10,'(a13)',end=999) call_0 + else + call_0=arg + endif + if(call_0.eq.' ') exit + if(call_0(1:3).eq.'CQ ' .and. call_0(4:4).ne.' ') call_0(3:3)='_' + call_1=' ' + call_00=call_0 + call pack28(call_00,n28) + call unpack28(n28,call_1,unpk28_success) + cerr=' ' + if(call_0.ne.call_1) cerr='*' + if(call_0(1:3).eq.'CQ_') call_0(3:3)=' ' + if(call_1(1:3).eq.'CQ_') call_1(3:3)=' ' + if(n28.lt.NTOKENS) write(*,1010) call_0,call_1,n28,cerr +1010 format(a13,2x,a13,i10,2x,a1,2x,'Special token') + if(n28.ge.NTOKENS .and. n28.lt.NTOKENS+MAX22) then + call_00=call_0 + call save_hash_call(call_00,n10,n12,n22) + write(*,1012) call_0,call_1,n28,cerr,n22 +1012 format(a13,2x,a13,i10,2x,a1,2x,'22-bit hash',i15) + endif + if(n28.ge.NTOKENS+MAX22) write(*,1014) call_0,call_1,n28,cerr +1014 format(a13,2x,a13,i10,2x,a1,2x,'Standard callsign') + if(nargs.gt.0) exit + enddo + go to 999 + +100 call unpack28(n28,call_1,unpk28_success) + cerr=' ' + if(.not.unpk28_success) cerr='*' + if(call_1(1:3).eq.'CQ_') call_1(3:3)=' ' + if(n28.lt.NTOKENS) write(*,2010) n28,call_1,cerr +2010 format(i10,2x,a13,2x,a1,2x,'Special token') + if(n28.ge.NTOKENS .and. n28.lt.NTOKENS+MAX22) write(*,2012) n28,call_1,cerr +2012 format(i10,2x,a13,2x,a1,2x,'22-bit hash') + if(n28.ge.NTOKENS+MAX22) write(*,2014) n28,call_1,cerr +2014 format(i10,2x,a13,2x,a1,2x,'Standard callsign') + +999 end program test28 diff --git a/lib/77bit/test28.txt b/lib/77bit/test28.txt index d12020b8..b2801121 100755 --- a/lib/77bit/test28.txt +++ b/lib/77bit/test28.txt @@ -1,35 +1,35 @@ -DE -QRZ -CQ -CQ_000 -CQ_001 -CQ_999 -CQ_A -CQ_Z -CQ_AA -CQ_ZZ -CQ_AAA -CQ_ZZZ -CQ_AAAA -CQ_ZZZZ - - - - - - - - - - -A0 -A0A -K1ABC -K1JT -5B1ABC -9Y4AB -9Y4XYZ -KA1ABC -KA1JT -WB9XYZ -ZZ9ZZZ +DE +QRZ +CQ +CQ_000 +CQ_001 +CQ_999 +CQ_A +CQ_Z +CQ_AA +CQ_ZZ +CQ_AAA +CQ_ZZZ +CQ_AAAA +CQ_ZZZZ + + + + + + + + + + +A0 +A0A +K1ABC +K1JT +5B1ABC +9Y4AB +9Y4XYZ +KA1ABC +KA1JT +WB9XYZ +ZZ9ZZZ diff --git a/lib/77bit/todo.txt b/lib/77bit/todo.txt index b74e8cc1..dcc78e1c 100755 --- a/lib/77bit/todo.txt +++ b/lib/77bit/todo.txt @@ -1,59 +1,59 @@ - To Do for FT8++ - --------------- - -The following list is for informtion and general guidance. Everything -is subject to change, and not all ideas are necessarily good ones! - -1. Nomenclature and parameters for message types - - Old-style = classic 72-bit JT-style source-encoding - FT8: (174,87) code: 72-bit info, i3bit, CRC12, isync=1 - MSK144: (128,80) code: 72-bit info, CRC8 - - New-style - FT8: (174,91) code: 74+3+14, sync uses isync=2 - MSK144: (128,90) code: 74+3+13 - -2. (K1JT) For backward compatibility (good for, say, 6 months only?), -by default we'll generate old-style messages where possible, new-style -messages where they are needed. We'll decode both old and new types. - -3. (K1JT -- DONE) Two new checkboxes on Advanced tab to enable 77-bit -messages: - - "Always generate new-style (77-bit) messages." - - "Decode only 77-bit messages - -4. (K9AN -- MOSTLY DONE) New-style messages can be as long as 37 -characters. We'll need to allow for that in a number of places. - -5. (K9AN -- DONE) Subroutine genft8() will need to parse the message to be -transmitted, determine the effective message type i3 and possibly -subtype, n3. It will then generate itone, calling genft8_174_91(() if -needed. - -6. (K1JT) Code to generate the user-readable messages for each -specialized type of operating, e.g., NA VHF contest, EU VHF contest, -ARRL Field Day, ARRL RTTY Roundup, use of nonstandard calls. - -7. (??) Code to do the necessary auto-sequencing for each specialized -type of operating. - -8. (K9AN -- MOSTLY DONE) What's needed for MSK144 with LDPC(128,90) ? -Still need to work on Sh messages. How will genmsk_128_90 know when to -generate a Sh message? - -9. (K9AN) Work on the implementation of AP decoding. For which message types -should AP be implemented? For each message type/QSO state that will use -AP decoding, need to create an AP decoding table that defines the number and -type of AP decoding passes. - -========================================================================== -The following are just ideas: - -- Options to sort/filter decoded signals - -- New Fox message type using constant-envelope waveform and higher - symbol rate to accommodate multiple simultaneous QSOs. RR73 sent to - 0-5 calls, report sent to 0-5 calls. Decoding uses AP for missing - calls, thereby effectively making lower-rate codes when not all - slots are used. - -- Hound should send spots of Fox to PSK Reporter. + To Do for FT8++ + --------------- + +The following list is for informtion and general guidance. Everything +is subject to change, and not all ideas are necessarily good ones! + +1. Nomenclature and parameters for message types + - Old-style = classic 72-bit JT-style source-encoding + FT8: (174,87) code: 72-bit info, i3bit, CRC12, isync=1 + MSK144: (128,80) code: 72-bit info, CRC8 + - New-style + FT8: (174,91) code: 74+3+14, sync uses isync=2 + MSK144: (128,90) code: 74+3+13 + +2. (K1JT) For backward compatibility (good for, say, 6 months only?), +by default we'll generate old-style messages where possible, new-style +messages where they are needed. We'll decode both old and new types. + +3. (K1JT -- DONE) Two new checkboxes on Advanced tab to enable 77-bit +messages: + - "Always generate new-style (77-bit) messages." + - "Decode only 77-bit messages + +4. (K9AN -- MOSTLY DONE) New-style messages can be as long as 37 +characters. We'll need to allow for that in a number of places. + +5. (K9AN -- DONE) Subroutine genft8() will need to parse the message to be +transmitted, determine the effective message type i3 and possibly +subtype, n3. It will then generate itone, calling genft8_174_91(() if +needed. + +6. (K1JT) Code to generate the user-readable messages for each +specialized type of operating, e.g., NA VHF contest, EU VHF contest, +ARRL Field Day, ARRL RTTY Roundup, use of nonstandard calls. + +7. (??) Code to do the necessary auto-sequencing for each specialized +type of operating. + +8. (K9AN -- MOSTLY DONE) What's needed for MSK144 with LDPC(128,90) ? +Still need to work on Sh messages. How will genmsk_128_90 know when to +generate a Sh message? + +9. (K9AN) Work on the implementation of AP decoding. For which message types +should AP be implemented? For each message type/QSO state that will use +AP decoding, need to create an AP decoding table that defines the number and +type of AP decoding passes. + +========================================================================== +The following are just ideas: + +- Options to sort/filter decoded signals + +- New Fox message type using constant-envelope waveform and higher + symbol rate to accommodate multiple simultaneous QSOs. RR73 sent to + 0-5 calls, report sent to 0-5 calls. Decoding uses AP for missing + calls, thereby effectively making lower-rate codes when not all + slots are used. + +- Hound should send spots of Fox to PSK Reporter. diff --git a/lib/77bit/tokens.txt b/lib/77bit/tokens.txt index 1e144d8c..bb514204 100755 --- a/lib/77bit/tokens.txt +++ b/lib/77bit/tokens.txt @@ -1,12 +1,12 @@ -DE -QRZ -CQ -CQ_000 -CQ_313 -CQ_999 -CQ_A -CQ_AAAA -CQ_AB -CQ_ABC -CQ_ABCD -CQ_ZZZZ +DE +QRZ +CQ +CQ_000 +CQ_313 +CQ_999 +CQ_A +CQ_AAAA +CQ_AB +CQ_ABC +CQ_ABCD +CQ_ZZZZ diff --git a/lib/77bit/wsjt-x_v2.0.txt b/lib/77bit/wsjt-x_v2.0.txt index b68559d8..59464dae 100755 --- a/lib/77bit/wsjt-x_v2.0.txt +++ b/lib/77bit/wsjt-x_v2.0.txt @@ -1,213 +1,213 @@ - Plans for WSJT-X Version 2.0 - ---------------------------- - -This white paper describes a number of important enhancements planned -for WSJT-X Version 2.0. Most of them involve the FT8 and MSK144 -protocols, which will be upgraded to use use 77-bit information -payloads rather than the present 72 or 75 bits. This modest increase -in information content will make possible new message types that -support the following special types of QSOs and exchanged information: - -1. NA VHF Contest operation with full and transparent support of grid - locators and "/R" (Rover) callsigns - -2. EU VHF Contest operation with the exchange of 6-digit locators, QSO - serial numbers, and "/P" (portable) callsigns - -3. ARRL Field Day operation with standard Field Day exchanges - -4. ARRL RTTY Roundup operation with standard contest exchanges - -5. Better and more user-friendly support for compound and nonstandard - callsigns - -6. A special "telemetry" message format for exchange of arbitrary - information (up to 71 bits) - -Decoding sensitivity for the new messages will be essentially the same -as for the FT8 and MSK144 modes presently in WSJT-X v1.9.1. The -existing FT8 DXpedition mode will still be supported, and a more -powerful DXpedition mode may be offered as well. - -In this document we'll call the new FT8 protocol "FT8+". It will be a -superset of the FT8 implemented in v1.9.1, providing at least -temporary compatibility and inter-operability with older program -versions. We may decide to remove support for old-style 72- and -75-bit messages after a specified switchover interval. - -In contrast, the new MSK144 protocol will replace the old one without -backward compatibility. We believe the smaller and more specialized -group of MSK144 users will upgrade quickly and not find this -restriction to be a problem. - -Here are some examples of message formats that will be supported by -FT8+ and MSK144 in WSJT-X v2.0. The list is not exhaustive. -Parameters i3 and n3 (shown in column 1) are used in the software to -define major and minor 77-bit message types. - ----------------------------------------------------------------------------------- -i3.n3 Example Messages Comments ----------------------------------------------------------------------------------- - 0.0 TNX BOB 73 GL Free text - 0.1 K1ABC RR73; W9XYZ -08 DXpedition Mode (sent only by Fox) - 0.2 G4ABC/P R 570007 JO22DB EU VHF Contest - 0.2 PA9XYZ 590003 IO91NP EU VHF Contest - 0.3 K1ABC W9XYZ 6A WI ARRL Field Day - 0.3 W9XYZ K1ABC R 2B EMA ARRL Field Day - 0.5 123456789ABCD Telemetry (18 hex digits) - 1. W9XYZ Compound call - 1. W9XYZ 73 - 1. CQ FD K1ABC FN42 - 1. CQ K1ABC FN42 - 1. CQ TEST K1ABC FN42 NA VHF Contest ("TEST" is optional) - 1. CQ TEST K1ABC/R FN42 - 1. K1ABC W9XYZ EN37 - 1. K1ABC W9XYZ -09 - 1. K1ABC W9XYZ R-17 - 1. K1ABC W9XYZ RRR - 1. K1ABC W9XYZ 73 - 1. K1ABC W9XYZ RR73 - 1. K1ABC/R W9XYZ EN37 - 1. K1ABC W9XYZ/R RR73 - 1. W9XYZ -13 Nonstandard call - 1. W9XYZ R+02 - 1. W9XYZ RRR - 1. W9XYZ RR73 - 2. CQ G4ABC/P IO91 - 2. G4ABC/P PA9XYZ JO22 - 2. PA9XYZ G4ABC/P RR73 - 3. K1ABC KA0DEF 559 MO ARRL RTTY Roundup - 3. K1ABC W9XYZ 579 WI ARRL RTTY Roundup - 3. KA1ABC G3AAA 529 0013 ARRL RTTY Roundup - 3. TU; G3AAA K1ABC R 559 MA ARRL RTTY Roundup - 3. TU; KA0DEF K1ABC R 569 MA ARRL RTTY Roundup - 3. W9XYZ K1ABC R 589 MA ARRL RTTY Roundup - 4. CQ KH1/KH7Z Compound call - 4. CQ YW18FIFA Nonstandard call ----------------------------------------------------------------------------------- - - -Here are some examples of minimal QSO sequences that take advantage -(where necessary) of the new protocol capabilities. Model QSOs number -1 and 2 are supported already, with the present FT8 and MSK144 -protocols, and number 3 with the existing FT8 DXpedition Mode. Model -QSOs 4-8 (and others not illustrated here) require the new protocols -with 77-bit messages. - ----------------------------------------------------------------------------------- -1. Standard QSO ----------------------------------------------------------------------------------- -CQ K1ABC FN42 - K1ABC W9XYZ EN37 -W9XYZ K1ABC -11 - K1ABC W9XYZ R-09 -W9XYZ K1ABC RRR - K1ABC W9XYZ 73 - ----------------------------------------------------------------------------------- -2. Short-cycle QSO ----------------------------------------------------------------------------------- -CQ K1ABC FN42 - K1ABC W9XYZ -09 -W9XYZ K1ABC R-11 - K1ABC W9XYZ RR73 -W9XYZ K1ABC 73 - ----------------------------------------------------------------------------------- -3. FT8 DXpedition Mode ----------------------------------------------------------------------------------- -CQ KH1/KH7Z - KH7Z K1ABC FN42 -K1ABC KH7Z -12 - KH7Z K1ABC R-14 - KH7Z W9XYZ EN37 - ... possibly other callers ... -K1ABC RR73; W9XYZ -08 - ----------------------------------------------------------------------------------- -4. ARRL Field Day ----------------------------------------------------------------------------------- -CQ FD K1ABC FN42 - K1ABC W9XYZ 6A WI -W9XYZ K1ABC R 2B EMA - K1ABC W9XYZ RR73 - ----------------------------------------------------------------------------------- -5. ARRL VHF Contests ----------------------------------------------------------------------------------- -CQ TEST K1ABC/R FN42 - K1ABC/R W9XYZ EN37 -W9XYZ K1ABC/R R FN42 - K1ABC/R W9XYZ RR73 - ----------------------------------------------------------------------------------- -6. ARRL RTTY Contest ----------------------------------------------------------------------------------- -CQ TEST K1ABC FN42 - K1ABC W9XYZ 579 WI -W9XYZ K1ABC R 589 MA - K1ABC W9XYZ RR73 - ----------------------------------------------------------------------------------- -7. EU VHF Contest ----------------------------------------------------------------------------------- -CQ TEST G4ABC/P IO91 - G4ABC/P PA9XYZ JO22 -PA9XYZ 590003 IO91NP - G4ABC/P R 570007 JO22DB -PA9XYZ G4ABC/P RRR - G4ABC/P PA9XYZ 73 - ----------------------------------------------------------------------------------- -8. Compound call ----------------------------------------------------------------------------------- -CQ PJ4/K1ABC - W9XYZ -W9XYZ K1ABC -11 - K1ABC W9XYZ R-09 -W9XYZ RRR - W9XYZ 73 ----------------------------------------------------------------------------------- - - -To minimize confusion that's likely to arise during a switchover from -v1.9.1 to v2.0, we propose to follow a well advertised schedule: - -"RC1 Date" -- perhaps as early as September 15, 2018? -------------------------------------------------------- - -This will be the first chance for beta testers to try WSJT-X using the -77-bit messages. We may restrict this opportunity to specific -volunteer testers, and we'll probably include an "upgrade by -xxxx_date" message to remind people that they are using a release -intended only for testing. - -FT8+ will support the old (v1.9.1) protocol as well as the new message -types outlined above. To avoid QRMing legacy FT8 users with messages -they can't decode, we'll recommend testing FT8+ on frequencies -formerly used for JT9. - -MSK144 will be fully functional between any two stations using the RC1 -software, but it will not be backward compatible with earlier program -versions. - -"RC2, RC3,... Date" -- perhaps in October? --------------------------------------------- - -As needed, depending on results of testing. - -GA Release Date -- perhaps in November? ---------------------------------------------- - -Official General Availability release of WSJT-X v2.0.0. The original -MSK144 protocol will be declared obsolete. - - -For reference: Dates of relevant upcoming ARRL contests -------------------------------------------------------- -VHF QSO Party: September 8-10, 2018 -RTTY Roundup: January 5-6, 2019 -VHF SS: January 19-21, 2019 - -Our proposed schedule should make WSJT-X Version 2.0 usable for -relevant ARRL operating events in 2019. + Plans for WSJT-X Version 2.0 + ---------------------------- + +This white paper describes a number of important enhancements planned +for WSJT-X Version 2.0. Most of them involve the FT8 and MSK144 +protocols, which will be upgraded to use use 77-bit information +payloads rather than the present 72 or 75 bits. This modest increase +in information content will make possible new message types that +support the following special types of QSOs and exchanged information: + +1. NA VHF Contest operation with full and transparent support of grid + locators and "/R" (Rover) callsigns + +2. EU VHF Contest operation with the exchange of 6-digit locators, QSO + serial numbers, and "/P" (portable) callsigns + +3. ARRL Field Day operation with standard Field Day exchanges + +4. ARRL RTTY Roundup operation with standard contest exchanges + +5. Better and more user-friendly support for compound and nonstandard + callsigns + +6. A special "telemetry" message format for exchange of arbitrary + information (up to 71 bits) + +Decoding sensitivity for the new messages will be essentially the same +as for the FT8 and MSK144 modes presently in WSJT-X v1.9.1. The +existing FT8 DXpedition mode will still be supported, and a more +powerful DXpedition mode may be offered as well. + +In this document we'll call the new FT8 protocol "FT8+". It will be a +superset of the FT8 implemented in v1.9.1, providing at least +temporary compatibility and inter-operability with older program +versions. We may decide to remove support for old-style 72- and +75-bit messages after a specified switchover interval. + +In contrast, the new MSK144 protocol will replace the old one without +backward compatibility. We believe the smaller and more specialized +group of MSK144 users will upgrade quickly and not find this +restriction to be a problem. + +Here are some examples of message formats that will be supported by +FT8+ and MSK144 in WSJT-X v2.0. The list is not exhaustive. +Parameters i3 and n3 (shown in column 1) are used in the software to +define major and minor 77-bit message types. + +---------------------------------------------------------------------------------- +i3.n3 Example Messages Comments +---------------------------------------------------------------------------------- + 0.0 TNX BOB 73 GL Free text + 0.1 K1ABC RR73; W9XYZ -08 DXpedition Mode (sent only by Fox) + 0.2 G4ABC/P R 570007 JO22DB EU VHF Contest + 0.2 PA9XYZ 590003 IO91NP EU VHF Contest + 0.3 K1ABC W9XYZ 6A WI ARRL Field Day + 0.3 W9XYZ K1ABC R 2B EMA ARRL Field Day + 0.5 123456789ABCD Telemetry (18 hex digits) + 1. W9XYZ Compound call + 1. W9XYZ 73 + 1. CQ FD K1ABC FN42 + 1. CQ K1ABC FN42 + 1. CQ TEST K1ABC FN42 NA VHF Contest ("TEST" is optional) + 1. CQ TEST K1ABC/R FN42 + 1. K1ABC W9XYZ EN37 + 1. K1ABC W9XYZ -09 + 1. K1ABC W9XYZ R-17 + 1. K1ABC W9XYZ RRR + 1. K1ABC W9XYZ 73 + 1. K1ABC W9XYZ RR73 + 1. K1ABC/R W9XYZ EN37 + 1. K1ABC W9XYZ/R RR73 + 1. W9XYZ -13 Nonstandard call + 1. W9XYZ R+02 + 1. W9XYZ RRR + 1. W9XYZ RR73 + 2. CQ G4ABC/P IO91 + 2. G4ABC/P PA9XYZ JO22 + 2. PA9XYZ G4ABC/P RR73 + 3. K1ABC KA0DEF 559 MO ARRL RTTY Roundup + 3. K1ABC W9XYZ 579 WI ARRL RTTY Roundup + 3. KA1ABC G3AAA 529 0013 ARRL RTTY Roundup + 3. TU; G3AAA K1ABC R 559 MA ARRL RTTY Roundup + 3. TU; KA0DEF K1ABC R 569 MA ARRL RTTY Roundup + 3. W9XYZ K1ABC R 589 MA ARRL RTTY Roundup + 4. CQ KH1/KH7Z Compound call + 4. CQ YW18FIFA Nonstandard call +---------------------------------------------------------------------------------- + + +Here are some examples of minimal QSO sequences that take advantage +(where necessary) of the new protocol capabilities. Model QSOs number +1 and 2 are supported already, with the present FT8 and MSK144 +protocols, and number 3 with the existing FT8 DXpedition Mode. Model +QSOs 4-8 (and others not illustrated here) require the new protocols +with 77-bit messages. + +---------------------------------------------------------------------------------- +1. Standard QSO +---------------------------------------------------------------------------------- +CQ K1ABC FN42 + K1ABC W9XYZ EN37 +W9XYZ K1ABC -11 + K1ABC W9XYZ R-09 +W9XYZ K1ABC RRR + K1ABC W9XYZ 73 + +---------------------------------------------------------------------------------- +2. Short-cycle QSO +---------------------------------------------------------------------------------- +CQ K1ABC FN42 + K1ABC W9XYZ -09 +W9XYZ K1ABC R-11 + K1ABC W9XYZ RR73 +W9XYZ K1ABC 73 + +---------------------------------------------------------------------------------- +3. FT8 DXpedition Mode +---------------------------------------------------------------------------------- +CQ KH1/KH7Z + KH7Z K1ABC FN42 +K1ABC KH7Z -12 + KH7Z K1ABC R-14 + KH7Z W9XYZ EN37 + ... possibly other callers ... +K1ABC RR73; W9XYZ -08 + +---------------------------------------------------------------------------------- +4. ARRL Field Day +---------------------------------------------------------------------------------- +CQ FD K1ABC FN42 + K1ABC W9XYZ 6A WI +W9XYZ K1ABC R 2B EMA + K1ABC W9XYZ RR73 + +---------------------------------------------------------------------------------- +5. ARRL VHF Contests +---------------------------------------------------------------------------------- +CQ TEST K1ABC/R FN42 + K1ABC/R W9XYZ EN37 +W9XYZ K1ABC/R R FN42 + K1ABC/R W9XYZ RR73 + +---------------------------------------------------------------------------------- +6. ARRL RTTY Contest +---------------------------------------------------------------------------------- +CQ TEST K1ABC FN42 + K1ABC W9XYZ 579 WI +W9XYZ K1ABC R 589 MA + K1ABC W9XYZ RR73 + +---------------------------------------------------------------------------------- +7. EU VHF Contest +---------------------------------------------------------------------------------- +CQ TEST G4ABC/P IO91 + G4ABC/P PA9XYZ JO22 +PA9XYZ 590003 IO91NP + G4ABC/P R 570007 JO22DB +PA9XYZ G4ABC/P RRR + G4ABC/P PA9XYZ 73 + +---------------------------------------------------------------------------------- +8. Compound call +---------------------------------------------------------------------------------- +CQ PJ4/K1ABC + W9XYZ +W9XYZ K1ABC -11 + K1ABC W9XYZ R-09 +W9XYZ RRR + W9XYZ 73 +---------------------------------------------------------------------------------- + + +To minimize confusion that's likely to arise during a switchover from +v1.9.1 to v2.0, we propose to follow a well advertised schedule: + +"RC1 Date" -- perhaps as early as September 15, 2018? +------------------------------------------------------- + +This will be the first chance for beta testers to try WSJT-X using the +77-bit messages. We may restrict this opportunity to specific +volunteer testers, and we'll probably include an "upgrade by +xxxx_date" message to remind people that they are using a release +intended only for testing. + +FT8+ will support the old (v1.9.1) protocol as well as the new message +types outlined above. To avoid QRMing legacy FT8 users with messages +they can't decode, we'll recommend testing FT8+ on frequencies +formerly used for JT9. + +MSK144 will be fully functional between any two stations using the RC1 +software, but it will not be backward compatible with earlier program +versions. + +"RC2, RC3,... Date" -- perhaps in October? +-------------------------------------------- + +As needed, depending on results of testing. + +GA Release Date -- perhaps in November? +--------------------------------------------- + +Official General Availability release of WSJT-X v2.0.0. The original +MSK144 protocol will be declared obsolete. + + +For reference: Dates of relevant upcoming ARRL contests +------------------------------------------------------- +VHF QSO Party: September 8-10, 2018 +RTTY Roundup: January 5-6, 2019 +VHF SS: January 19-21, 2019 + +Our proposed schedule should make WSJT-X Version 2.0 usable for +relevant ARRL operating events in 2019. diff --git a/lib/CQnnnCAT.txt b/lib/CQnnnCAT.txt index 1dea9078..d7e92d01 100755 --- a/lib/CQnnnCAT.txt +++ b/lib/CQnnnCAT.txt @@ -1,39 +1,39 @@ -Before using the new "CQ nnn ..." feature in JTMSK mode, I suggest -performing the following tests of the necessary CAT control for your -radio. (I'm assuming that you already have some experience with -JTMSK.) - -TEST 1: --------------------------------------------------------------------------- -1. Start WSJT-X -2. Settings: "Enable VHF/UHF/Microwave features, "Rx frequency offset - with 'CQ nnn ...'", Split=Rig, or Split="Fake it" -3. Main screen settings: Band=50.280, mode=JTMSK, T/R=15 s -4. Activate CQRx, set CQ Rx=265 - ==> Rx dial should now read 50.265 and Tx6 should be queued -5. Click "Enable Tx" - ==> Tx sequences should occur at 50.280, Rx at 50.265 - -With most rigs, this test should work with Split configured as either -"Rig" or "Fake it". - -TEST 2: --------------------------------------------------------------------------- -1. Start WSJT-X -2. Settings: MyCall=K1JT, "Enable VHF/UHF/Microwave features, - "Rx frequency offset with 'CQ nnn ...'", Split=Rig or "Fake it" -4. Main screen settings: Band=50.280, mode=JTMSK, T/R=15 s -5. Open file 150826_120515.wav - ==> see decoded message "K1JT VE1SKY FN74" -6. Click "Monitor" to restart monitoring -7. Activate CQRx, set CQ Rx=265 - ==> Rx dial should now read 50.265; Tx6 should be queued -8. Click "Enable Tx" - ==> Tx sequences should occur at 50.280, Rx at 50.265 -9. After the start of a transmission, double-click on the decoded message - "K1JT VE1SKY FN74" - ==> Tx2 should be generated and queued; transmission will pause - briefly, Tx freq changed to 50.265, then Tx resumed. - -The test file is posted at -http://physics.princeton.edu/pulsar/K1JT/150826_120515.wav +Before using the new "CQ nnn ..." feature in JTMSK mode, I suggest +performing the following tests of the necessary CAT control for your +radio. (I'm assuming that you already have some experience with +JTMSK.) + +TEST 1: +-------------------------------------------------------------------------- +1. Start WSJT-X +2. Settings: "Enable VHF/UHF/Microwave features, "Rx frequency offset + with 'CQ nnn ...'", Split=Rig, or Split="Fake it" +3. Main screen settings: Band=50.280, mode=JTMSK, T/R=15 s +4. Activate CQRx, set CQ Rx=265 + ==> Rx dial should now read 50.265 and Tx6 should be queued +5. Click "Enable Tx" + ==> Tx sequences should occur at 50.280, Rx at 50.265 + +With most rigs, this test should work with Split configured as either +"Rig" or "Fake it". + +TEST 2: +-------------------------------------------------------------------------- +1. Start WSJT-X +2. Settings: MyCall=K1JT, "Enable VHF/UHF/Microwave features, + "Rx frequency offset with 'CQ nnn ...'", Split=Rig or "Fake it" +4. Main screen settings: Band=50.280, mode=JTMSK, T/R=15 s +5. Open file 150826_120515.wav + ==> see decoded message "K1JT VE1SKY FN74" +6. Click "Monitor" to restart monitoring +7. Activate CQRx, set CQ Rx=265 + ==> Rx dial should now read 50.265; Tx6 should be queued +8. Click "Enable Tx" + ==> Tx sequences should occur at 50.280, Rx at 50.265 +9. After the start of a transmission, double-click on the decoded message + "K1JT VE1SKY FN74" + ==> Tx2 should be generated and queued; transmission will pause + briefly, Tx freq changed to 50.265, then Tx resumed. + +The test file is posted at +http://physics.princeton.edu/pulsar/K1JT/150826_120515.wav diff --git a/lib/C_interface_module.f90 b/lib/C_interface_module.f90 index 0688dcd1..47fee9de 100755 --- a/lib/C_interface_module.f90 +++ b/lib/C_interface_module.f90 @@ -1,441 +1,441 @@ -! FILE: c_interface_module.f90 -! PURPOSE: Supplement ISO-C-Binding to provide type aliases and interfaces -! to common ISO-C string functions to aid working with strings. -! AUTHOR: Joseph M. Krahn -! STATUS: Still in development. Reasonably complete, but somewhat limited testing. -! -! The idea is to provide type aliases for all ISO-C types, so that the -! Fortran interface code more explicitly defines the actual C interface. -! This should be updated to support F2008 variable-length allocatable -! strings. -! -! Entity names all have the "C_" prefix, as with ISO-C-Binding, with a -! few exceptions. -! -! Sourced from: http://fortranwiki.org/fortran/show/c_interface_module -! -! One FORALL statement reverted to a DO loop to avoid a gfortran 4.9.2 ICE -! -module C_interface_module - use, intrinsic :: ISO_C_Binding, & - ! C type aliases for pointer derived types: - C_ptr => C_ptr , & - C_char_ptr => C_ptr, & - C_const_char_ptr => C_ptr, & - C_void_ptr => C_ptr, & - C_const_void_ptr => C_ptr - - implicit none - public - - !---------------------------------------------------------------------------- - ! C type aliases for intrinsic type KIND parameters: - - ! NOTE: a C enum may not always be a standard C int - integer, parameter :: C_enum = C_int - - ! Defining off_t is difficult, because it may depend on "LARGEFILE" selection. - ! integer, parameter :: C_off_t = ?? - - ! C string terminator alais using the 3-letter ASCII name. - ! The C_ prefix is not used because it is just an ASCII character. - character(len=1,kind=C_char), parameter :: NUL = C_NULL_char - - ! NOTE: In C, "char" is distinct from "signed char", unlike integers. - ! The plain "char" type is specific for text/string values, whereas - ! "signed char" should indicate 1-byte integer data. - ! - ! Most ISO-C systems have wide chars "wchar_t", but Fortran compilers - ! have limited support for different character kinds. UTF encoding - ! adds more complexity. This should be updated as Fortran compilers - ! include support for more character types. - ! - - ! Fortran does not (yet) support unsigned types. - integer, parameter :: & - C_unsigned = C_int, & - C_unsigned_short = C_short, & - C_unsigned_long = C_long, & - C_unsigned_long_long = C_long_long, & - C_unsigned_char = C_signed_char, & - C_ssize_t = C_size_t, & - C_uint8_t = C_int8_t, & - C_uint16_t = C_int16_t, & - C_uint32_t = C_int32_t, & - C_uint64_t = C_int64_t, & - C_uint_least8_t = C_int_least8_t, & - C_uint_least16_t = C_int_least16_t, & - C_uint_least32_t = C_int_least32_t, & - C_uint_least64_t = C_int_least64_t, & - C_uint_fast8_t = C_int_fast8_t, & - C_uint_fast16_t = C_int_fast16_t, & - C_uint_fast32_t = C_int_fast32_t, & - C_uint_fast64_t = C_int_fast64_t, & - C_uintmax_t = C_intmax_t - ! Note: ptrdiff_t cannot be reliably defined from other types. - ! When practical, it is larger than a pointer because it benefits - ! from the full unsigned range in both positive and negative directions. - - ! Integer versions including 'int', where the 'int' is optional: - integer, parameter :: & - C_short_int = C_short, & - C_long_int = C_long, & - C_long_long_int = C_long_long, & - C_unsigned_int = C_unsigned, & - C_unsigned_short_int = C_short, & - C_unsigned_long_int = C_long, & - C_unsigned_long_long_int = C_long_long - - interface C_F_string - module procedure C_F_string_ptr - module procedure C_F_string_chars - end interface C_F_string - - interface F_C_string - module procedure F_C_string_ptr - module procedure F_C_string_chars - end interface F_C_string - - !======================================================================= - ! Some useful ISO C library string functions from - ! These are based on GCC header sections marked as NAMESPACE_STD - interface - - ! Copy N bytes of SRC to DEST, no aliasing or overlapping allowed. - ! extern void *memcpy (void *dest, const void *src, size_t n); - function C_memcpy(dest, src, n) result(result) bind(C,name="memcpy") - import C_void_ptr, C_size_t - type(C_void_ptr) :: result - type(C_void_ptr), value, intent(in) :: dest ! target=intent(out) - type(C_void_ptr), value, intent(in) :: src ! target=intent(in) - integer(C_size_t), value, intent(in) :: n - end function C_memcpy - - ! Copy N bytes of SRC to DEST, guaranteeing correct behavior for overlapping strings. - !extern void *memmove (void *dest, const void *src, size_t n) - function C_memmove(dest, src, n) result(result) bind(C,name="memmove") - import C_void_ptr, C_size_t - type(C_void_ptr) :: result - type(C_void_ptr), value, intent(in) :: dest ! target=intent(out) - type(C_void_ptr), value, intent(in) :: src - integer(C_size_t), value, intent(in) :: n - end function C_memmove - - ! Set N bytes of S to C. - !extern void *memset (void *s, int c, size_t n) - function C_memset(s, c, n) result(result) bind(C,name="memset") - import C_void_ptr, C_int, C_size_t - type(C_void_ptr) :: result - type(C_void_ptr), value, intent(in) :: s ! target=intent(out) - integer(C_int), value, intent(in) :: c - integer(C_size_t), value, intent(in) :: n - end function C_memset - - ! Compare N bytes of S1 and S2. - !extern int memcmp (const void *s1, const void *s2, size_t n) - pure function C_memcmp(s1, s2, n) result(result) bind(C,name="memcmp") - import C_int, C_void_ptr, C_size_t - integer(C_int) :: result - type(C_void_ptr), value, intent(in) :: s1 - type(C_void_ptr), value, intent(in) :: s2 - integer(C_size_t), value, intent(in) :: n - end function C_memcmp - - ! Search N bytes of S for C. - !extern void *memchr (const void *s, int c, size_t n) - pure function C_memchr(s, c, n) result(result) bind(C,name="memchr") - import C_void_ptr, C_int, C_size_t - type(C_void_ptr) :: result - type(C_void_ptr), value, intent(in) :: s - integer(C_int), value, intent(in) :: c - integer(C_size_t), value, intent(in) :: n - end function C_memchr - - ! Copy SRC to DEST. - !extern char *strcpy (char *dest, const char *src) - function C_strcpy(dest, src) result(result) bind(C,name="strcpy") - import C_char_ptr, C_size_t - type(C_char_ptr) :: result - type(C_char_ptr), value, intent(in) :: dest ! target=intent(out) - type(C_char_ptr), value, intent(in) :: src - end function C_strcpy - - ! Copy no more than N characters of SRC to DEST. - !extern char *strncpy (char *dest, const char *src, size_t n) - function C_strncpy(dest, src, n) result(result) bind(C,name="strncpy") - import C_char_ptr, C_size_t - type(C_char_ptr) :: result - type(C_char_ptr), value, intent(in) :: dest ! target=intent(out) - type(C_char_ptr), value, intent(in) :: src - integer(C_size_t), value, intent(in) :: n - end function C_strncpy - - ! Append SRC onto DEST. - !extern char *strcat (char *dest, const char *src) - function C_strcat(dest, src) result(result) bind(C,name="strcat") - import C_char_ptr, C_size_t - type(C_char_ptr) :: result - type(C_char_ptr), value, intent(in) :: dest ! target=intent(out) - type(C_char_ptr), value, intent(in) :: src - end function C_strcat - - ! Append no more than N characters from SRC onto DEST. - !extern char *strncat (char *dest, const char *src, size_t n) - function C_strncat(dest, src, n) result(result) bind(C,name="strncat") - import C_char_ptr, C_size_t - type(C_char_ptr) :: result - type(C_char_ptr), value, intent(in) :: dest ! target=intent(out) - type(C_char_ptr), value, intent(in) :: src - integer(C_size_t), value, intent(in) :: n - end function C_strncat - - ! Compare S1 and S2. - !extern int strcmp (const char *s1, const char *s2) - pure function C_strcmp(s1, s2) result(result) bind(C,name="strcmp") - import C_int, C_char_ptr, C_size_t - integer(C_int) :: result - type(C_char_ptr), value, intent(in) :: s1 - type(C_char_ptr), value, intent(in) :: s2 - end function C_strcmp - - ! Compare N characters of S1 and S2. - !extern int strncmp (const char *s1, const char *s2, size_t n) - pure function C_strncmp(s1, s2, n) result(result) bind(C,name="strncmp") - import C_int, C_char_ptr, C_size_t - integer(C_int) :: result - type(C_char_ptr), value, intent(in) :: s1 - type(C_char_ptr), value, intent(in) :: s2 - integer(C_size_t), value, intent(in) :: n - end function C_strncmp - - ! Return the length of S. - !extern size_t strlen (const char *s) - pure function C_strlen(s) result(result) bind(C,name="strlen") - import C_char_ptr, C_size_t - integer(C_size_t) :: result - type(C_char_ptr), value, intent(in) :: s !character(len=*), intent(in) - end function C_strlen - - end interface - - ! End of - !========================================================================= - ! Standard ISO-C malloc routines: - interface - - ! void *calloc(size_t nmemb, size_t size); - type(C_void_ptr) function C_calloc(nmemb, size) bind(C,name="calloc") - import C_void_ptr, C_size_t - integer(C_size_t), value, intent(in) :: nmemb, size - end function C_calloc - - ! void *malloc(size_t size); - type(C_void_ptr) function C_malloc(size) bind(C,name="malloc") - import C_void_ptr, C_size_t - integer(C_size_t), value, intent(in) :: size - end function C_malloc - - ! void free(void *ptr); - subroutine C_free(ptr) bind(C,name="free") - import C_void_ptr - type(C_void_ptr), value, intent(in) :: ptr - end subroutine C_free - - ! void *realloc(void *ptr, size_t size); - type(C_void_ptr) function C_realloc(ptr,size) bind(C,name="realloc") - import C_void_ptr, C_size_t - type(C_void_ptr), value, intent(in) :: ptr - integer(C_size_t), value, intent(in) :: size - end function C_realloc - - end interface - - interface assignment(=) - module procedure F_string_assign_C_string - end interface assignment(=) - - !========================================================================== - -contains - - ! HACK: For some reason, C_associated was not defined as pure. - pure logical function C_associated_pure(ptr) result(associated) - type(C_ptr), intent(in) :: ptr - integer(C_intptr_t) :: iptr - iptr = transfer(ptr,iptr) - associated = (iptr /= 0) - end function C_associated_pure - - ! Set a fixed-length Fortran string to the value of a C string. - subroutine F_string_assign_C_string(F_string, C_string) - character(len=*), intent(out) :: F_string - type(C_ptr), intent(in) :: C_string - character(len=1,kind=C_char), pointer :: p_chars(:) - integer :: i - if (.not. C_associated(C_string) ) then - F_string = ' ' - else - call C_F_pointer(C_string,p_chars,[huge(0)]) - i=1 - do while(p_chars(i)/=NUL .and. i<=len(F_string)) - F_string(i:i) = p_chars(i) - i=i+1 - end do - if (i C_ptr , & + C_char_ptr => C_ptr, & + C_const_char_ptr => C_ptr, & + C_void_ptr => C_ptr, & + C_const_void_ptr => C_ptr + + implicit none + public + + !---------------------------------------------------------------------------- + ! C type aliases for intrinsic type KIND parameters: + + ! NOTE: a C enum may not always be a standard C int + integer, parameter :: C_enum = C_int + + ! Defining off_t is difficult, because it may depend on "LARGEFILE" selection. + ! integer, parameter :: C_off_t = ?? + + ! C string terminator alais using the 3-letter ASCII name. + ! The C_ prefix is not used because it is just an ASCII character. + character(len=1,kind=C_char), parameter :: NUL = C_NULL_char + + ! NOTE: In C, "char" is distinct from "signed char", unlike integers. + ! The plain "char" type is specific for text/string values, whereas + ! "signed char" should indicate 1-byte integer data. + ! + ! Most ISO-C systems have wide chars "wchar_t", but Fortran compilers + ! have limited support for different character kinds. UTF encoding + ! adds more complexity. This should be updated as Fortran compilers + ! include support for more character types. + ! + + ! Fortran does not (yet) support unsigned types. + integer, parameter :: & + C_unsigned = C_int, & + C_unsigned_short = C_short, & + C_unsigned_long = C_long, & + C_unsigned_long_long = C_long_long, & + C_unsigned_char = C_signed_char, & + C_ssize_t = C_size_t, & + C_uint8_t = C_int8_t, & + C_uint16_t = C_int16_t, & + C_uint32_t = C_int32_t, & + C_uint64_t = C_int64_t, & + C_uint_least8_t = C_int_least8_t, & + C_uint_least16_t = C_int_least16_t, & + C_uint_least32_t = C_int_least32_t, & + C_uint_least64_t = C_int_least64_t, & + C_uint_fast8_t = C_int_fast8_t, & + C_uint_fast16_t = C_int_fast16_t, & + C_uint_fast32_t = C_int_fast32_t, & + C_uint_fast64_t = C_int_fast64_t, & + C_uintmax_t = C_intmax_t + ! Note: ptrdiff_t cannot be reliably defined from other types. + ! When practical, it is larger than a pointer because it benefits + ! from the full unsigned range in both positive and negative directions. + + ! Integer versions including 'int', where the 'int' is optional: + integer, parameter :: & + C_short_int = C_short, & + C_long_int = C_long, & + C_long_long_int = C_long_long, & + C_unsigned_int = C_unsigned, & + C_unsigned_short_int = C_short, & + C_unsigned_long_int = C_long, & + C_unsigned_long_long_int = C_long_long + + interface C_F_string + module procedure C_F_string_ptr + module procedure C_F_string_chars + end interface C_F_string + + interface F_C_string + module procedure F_C_string_ptr + module procedure F_C_string_chars + end interface F_C_string + + !======================================================================= + ! Some useful ISO C library string functions from + ! These are based on GCC header sections marked as NAMESPACE_STD + interface + + ! Copy N bytes of SRC to DEST, no aliasing or overlapping allowed. + ! extern void *memcpy (void *dest, const void *src, size_t n); + function C_memcpy(dest, src, n) result(result) bind(C,name="memcpy") + import C_void_ptr, C_size_t + type(C_void_ptr) :: result + type(C_void_ptr), value, intent(in) :: dest ! target=intent(out) + type(C_void_ptr), value, intent(in) :: src ! target=intent(in) + integer(C_size_t), value, intent(in) :: n + end function C_memcpy + + ! Copy N bytes of SRC to DEST, guaranteeing correct behavior for overlapping strings. + !extern void *memmove (void *dest, const void *src, size_t n) + function C_memmove(dest, src, n) result(result) bind(C,name="memmove") + import C_void_ptr, C_size_t + type(C_void_ptr) :: result + type(C_void_ptr), value, intent(in) :: dest ! target=intent(out) + type(C_void_ptr), value, intent(in) :: src + integer(C_size_t), value, intent(in) :: n + end function C_memmove + + ! Set N bytes of S to C. + !extern void *memset (void *s, int c, size_t n) + function C_memset(s, c, n) result(result) bind(C,name="memset") + import C_void_ptr, C_int, C_size_t + type(C_void_ptr) :: result + type(C_void_ptr), value, intent(in) :: s ! target=intent(out) + integer(C_int), value, intent(in) :: c + integer(C_size_t), value, intent(in) :: n + end function C_memset + + ! Compare N bytes of S1 and S2. + !extern int memcmp (const void *s1, const void *s2, size_t n) + pure function C_memcmp(s1, s2, n) result(result) bind(C,name="memcmp") + import C_int, C_void_ptr, C_size_t + integer(C_int) :: result + type(C_void_ptr), value, intent(in) :: s1 + type(C_void_ptr), value, intent(in) :: s2 + integer(C_size_t), value, intent(in) :: n + end function C_memcmp + + ! Search N bytes of S for C. + !extern void *memchr (const void *s, int c, size_t n) + pure function C_memchr(s, c, n) result(result) bind(C,name="memchr") + import C_void_ptr, C_int, C_size_t + type(C_void_ptr) :: result + type(C_void_ptr), value, intent(in) :: s + integer(C_int), value, intent(in) :: c + integer(C_size_t), value, intent(in) :: n + end function C_memchr + + ! Copy SRC to DEST. + !extern char *strcpy (char *dest, const char *src) + function C_strcpy(dest, src) result(result) bind(C,name="strcpy") + import C_char_ptr, C_size_t + type(C_char_ptr) :: result + type(C_char_ptr), value, intent(in) :: dest ! target=intent(out) + type(C_char_ptr), value, intent(in) :: src + end function C_strcpy + + ! Copy no more than N characters of SRC to DEST. + !extern char *strncpy (char *dest, const char *src, size_t n) + function C_strncpy(dest, src, n) result(result) bind(C,name="strncpy") + import C_char_ptr, C_size_t + type(C_char_ptr) :: result + type(C_char_ptr), value, intent(in) :: dest ! target=intent(out) + type(C_char_ptr), value, intent(in) :: src + integer(C_size_t), value, intent(in) :: n + end function C_strncpy + + ! Append SRC onto DEST. + !extern char *strcat (char *dest, const char *src) + function C_strcat(dest, src) result(result) bind(C,name="strcat") + import C_char_ptr, C_size_t + type(C_char_ptr) :: result + type(C_char_ptr), value, intent(in) :: dest ! target=intent(out) + type(C_char_ptr), value, intent(in) :: src + end function C_strcat + + ! Append no more than N characters from SRC onto DEST. + !extern char *strncat (char *dest, const char *src, size_t n) + function C_strncat(dest, src, n) result(result) bind(C,name="strncat") + import C_char_ptr, C_size_t + type(C_char_ptr) :: result + type(C_char_ptr), value, intent(in) :: dest ! target=intent(out) + type(C_char_ptr), value, intent(in) :: src + integer(C_size_t), value, intent(in) :: n + end function C_strncat + + ! Compare S1 and S2. + !extern int strcmp (const char *s1, const char *s2) + pure function C_strcmp(s1, s2) result(result) bind(C,name="strcmp") + import C_int, C_char_ptr, C_size_t + integer(C_int) :: result + type(C_char_ptr), value, intent(in) :: s1 + type(C_char_ptr), value, intent(in) :: s2 + end function C_strcmp + + ! Compare N characters of S1 and S2. + !extern int strncmp (const char *s1, const char *s2, size_t n) + pure function C_strncmp(s1, s2, n) result(result) bind(C,name="strncmp") + import C_int, C_char_ptr, C_size_t + integer(C_int) :: result + type(C_char_ptr), value, intent(in) :: s1 + type(C_char_ptr), value, intent(in) :: s2 + integer(C_size_t), value, intent(in) :: n + end function C_strncmp + + ! Return the length of S. + !extern size_t strlen (const char *s) + pure function C_strlen(s) result(result) bind(C,name="strlen") + import C_char_ptr, C_size_t + integer(C_size_t) :: result + type(C_char_ptr), value, intent(in) :: s !character(len=*), intent(in) + end function C_strlen + + end interface + + ! End of + !========================================================================= + ! Standard ISO-C malloc routines: + interface + + ! void *calloc(size_t nmemb, size_t size); + type(C_void_ptr) function C_calloc(nmemb, size) bind(C,name="calloc") + import C_void_ptr, C_size_t + integer(C_size_t), value, intent(in) :: nmemb, size + end function C_calloc + + ! void *malloc(size_t size); + type(C_void_ptr) function C_malloc(size) bind(C,name="malloc") + import C_void_ptr, C_size_t + integer(C_size_t), value, intent(in) :: size + end function C_malloc + + ! void free(void *ptr); + subroutine C_free(ptr) bind(C,name="free") + import C_void_ptr + type(C_void_ptr), value, intent(in) :: ptr + end subroutine C_free + + ! void *realloc(void *ptr, size_t size); + type(C_void_ptr) function C_realloc(ptr,size) bind(C,name="realloc") + import C_void_ptr, C_size_t + type(C_void_ptr), value, intent(in) :: ptr + integer(C_size_t), value, intent(in) :: size + end function C_realloc + + end interface + + interface assignment(=) + module procedure F_string_assign_C_string + end interface assignment(=) + + !========================================================================== + +contains + + ! HACK: For some reason, C_associated was not defined as pure. + pure logical function C_associated_pure(ptr) result(associated) + type(C_ptr), intent(in) :: ptr + integer(C_intptr_t) :: iptr + iptr = transfer(ptr,iptr) + associated = (iptr /= 0) + end function C_associated_pure + + ! Set a fixed-length Fortran string to the value of a C string. + subroutine F_string_assign_C_string(F_string, C_string) + character(len=*), intent(out) :: F_string + type(C_ptr), intent(in) :: C_string + character(len=1,kind=C_char), pointer :: p_chars(:) + integer :: i + if (.not. C_associated(C_string) ) then + F_string = ' ' + else + call C_F_pointer(C_string,p_chars,[huge(0)]) + i=1 + do while(p_chars(i)/=NUL .and. i<=len(F_string)) + F_string(i:i) = p_chars(i) + i=i+1 + end do + if (i a(1:3) - - complex cx(npts) - real a(5),deltaa(5) - - a=0. - a1=0. - a2=0. - i2=8*mode65 - i1=-i2 - j2=8*mode65 - j1=-j2 - ccfmax=0. - istep=2*mode65 - do iter=1,2 - do i=i1,i2,istep - a(1)=i - do j=j1,j2,istep - a(2)=j - chisq=fchisq65(cx,npts,fsample,nflip,a,ccf,dtmax) - if(ccf.gt.ccfmax) then - a1=a(1) - a2=a(2) - ccfmax=ccf - endif -! write(81,3081) istep,i1,i2,j1,j2,i,j,ccf,ccfmax,dtmax,a1,a2 -!3081 format(7i4,5f8.2) - enddo - enddo - i1=int(a1)-istep - i2=int(a1)+istep - j1=int(a2)-istep - j2=int(a2)+istep - istep=1 - enddo - -! a(1)=0. -! a(2)=0. - a(1)=a1 - a(2)=a2 - a(3)=0. - a(4)=0. - deltaa(1)=2.0*mode65 - deltaa(2)=2.0*mode65 - deltaa(3)=1.0 - nterms=2 !Maybe 2 is enough? - -! Start the iteration - chisqr=0. - chisqr0=1.e6 - do iter=1,100 !How many iters is enough? - do j=1,nterms - chisq1=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) - fn=0. - delta=deltaa(j) -10 a(j)=a(j)+delta - chisq2=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) - if(chisq2.eq.chisq1) go to 10 - if(chisq2.gt.chisq1) then - delta=-delta !Reverse direction - a(j)=a(j)+delta - tmp=chisq1 - chisq1=chisq2 - chisq2=tmp - endif -20 fn=fn+1.0 - a(j)=a(j)+delta - chisq3=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) - if(chisq3.lt.chisq2) then - chisq1=chisq2 - chisq2=chisq3 - go to 20 - endif - -! Find minimum of parabola defined by last three points - delta=delta*(1./(1.+(chisq1-chisq2)/(chisq3-chisq2))+0.5) - a(j)=a(j)-delta - deltaa(j)=deltaa(j)*fn/3. -! write(*,4000) iter,j,a(1:2),-chisq2 -!4000 format(2i2,4f9.4) - enddo - chisqr=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) - fdiff=chisqr/chisqr0-1.0 -! write(*,4000) 0,0,a(1:2),-chisqr,fdiff - if(abs(fdiff).lt.0.0001) exit - chisqr0=chisqr - enddo - ccfbest=ccfmax * (1378.125/fsample)**2 - dtbest=dtmax - - return -end subroutine afc65b +subroutine afc65b(cx,npts,fsample,nflip,mode65,a,ccfbest,dtbest) + +! Find delta f, f1, f2 ==> a(1:3) + + complex cx(npts) + real a(5),deltaa(5) + + a=0. + a1=0. + a2=0. + i2=8*mode65 + i1=-i2 + j2=8*mode65 + j1=-j2 + ccfmax=0. + istep=2*mode65 + do iter=1,2 + do i=i1,i2,istep + a(1)=i + do j=j1,j2,istep + a(2)=j + chisq=fchisq65(cx,npts,fsample,nflip,a,ccf,dtmax) + if(ccf.gt.ccfmax) then + a1=a(1) + a2=a(2) + ccfmax=ccf + endif +! write(81,3081) istep,i1,i2,j1,j2,i,j,ccf,ccfmax,dtmax,a1,a2 +!3081 format(7i4,5f8.2) + enddo + enddo + i1=int(a1)-istep + i2=int(a1)+istep + j1=int(a2)-istep + j2=int(a2)+istep + istep=1 + enddo + +! a(1)=0. +! a(2)=0. + a(1)=a1 + a(2)=a2 + a(3)=0. + a(4)=0. + deltaa(1)=2.0*mode65 + deltaa(2)=2.0*mode65 + deltaa(3)=1.0 + nterms=2 !Maybe 2 is enough? + +! Start the iteration + chisqr=0. + chisqr0=1.e6 + do iter=1,100 !How many iters is enough? + do j=1,nterms + chisq1=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) + fn=0. + delta=deltaa(j) +10 a(j)=a(j)+delta + chisq2=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) + if(chisq2.eq.chisq1) go to 10 + if(chisq2.gt.chisq1) then + delta=-delta !Reverse direction + a(j)=a(j)+delta + tmp=chisq1 + chisq1=chisq2 + chisq2=tmp + endif +20 fn=fn+1.0 + a(j)=a(j)+delta + chisq3=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) + if(chisq3.lt.chisq2) then + chisq1=chisq2 + chisq2=chisq3 + go to 20 + endif + +! Find minimum of parabola defined by last three points + delta=delta*(1./(1.+(chisq1-chisq2)/(chisq3-chisq2))+0.5) + a(j)=a(j)-delta + deltaa(j)=deltaa(j)*fn/3. +! write(*,4000) iter,j,a(1:2),-chisq2 +!4000 format(2i2,4f9.4) + enddo + chisqr=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) + fdiff=chisqr/chisqr0-1.0 +! write(*,4000) 0,0,a(1:2),-chisqr,fdiff + if(abs(fdiff).lt.0.0001) exit + chisqr0=chisqr + enddo + ccfbest=ccfmax * (1378.125/fsample)**2 + dtbest=dtmax + + return +end subroutine afc65b diff --git a/lib/afc9.f90 b/lib/afc9.f90 index 58305131..dd106aa4 100755 --- a/lib/afc9.f90 +++ b/lib/afc9.f90 @@ -1,81 +1,81 @@ -subroutine afc9(c3a,npts,fsample,a,syncpk) - - parameter (NZ2=1512) - complex c3a(0:NZ2-1) - complex c3(0:NZ2-1) - real a(3),deltaa(3) - - a(1)=0. !f0 - a(2)=0. !f1 - a(3)=0. !f2 - deltaa(1)=1.736 - deltaa(2)=1.736 - deltaa(3)=1.0 - nterms=3 - -! Start the iteration - chisqr=0. - chisqr0=1.e6 - c3=c3a - a3=a(3) - do iter=1,4 - do j=1,nterms - if(a(3).ne.a3) call shft(c3a,a(3),a3,c3) - chisq1=fchisq(c3,npts,fsample,a) - fn=0. - delta=deltaa(j) -10 a(j)=a(j)+delta - if(a(3).ne.a3) call shft(c3a,a(3),a3,c3) - chisq2=fchisq(c3,npts,fsample,a) - if(chisq2.eq.chisq1) go to 10 - if(chisq2.gt.chisq1) then - delta=-delta !Reverse direction - a(j)=a(j)+delta - tmp=chisq1 - chisq1=chisq2 - chisq2=tmp - endif -20 fn=fn+1.0 - a(j)=a(j)+delta - if(a(3).ne.a3) call shft(c3a,a(3),a3,c3) - chisq3=fchisq(c3,npts,fsample,a) - if(chisq3.lt.chisq2) then - chisq1=chisq2 - chisq2=chisq3 - go to 20 - endif - -! Find minimum of parabola defined by last three points - delta=delta*(1./(1.+(chisq1-chisq2)/(chisq3-chisq2))+0.5) - a(j)=a(j)-delta - if(j.lt.3) deltaa(j)=deltaa(j)*fn/3. -! write(*,4000) iter,j,a,-chisq2 -!4000 format(i1,i2,3f10.4,f11.3) - enddo - if(a(3).ne.a3) call shft(c3a,a(3),a3,c3) - chisqr=fchisq(c3,npts,fsample,a) -! write(*,4000) 0,0,a,-chisqr - if(chisqr/chisqr0.gt.0.99) exit - chisqr0=chisqr - enddo - - syncpk=-chisqr - c3a=c3 -! write(*,4001) a,syncpk -!4001 format(3x,3f10.4,f11.3) - - return -end subroutine afc9 - -subroutine shft(c3a,a3a,a3,c3) - complex c3a(0:1359) - complex c3(0:1359) - - a3=a3a - n=nint(a3) - c3=cshift(c3a,n) - if(n.gt.0) c3(1360-n:)=0.0 - if(n.lt.0) c3(:n-1)=0.0 - - return -end subroutine shft +subroutine afc9(c3a,npts,fsample,a,syncpk) + + parameter (NZ2=1512) + complex c3a(0:NZ2-1) + complex c3(0:NZ2-1) + real a(3),deltaa(3) + + a(1)=0. !f0 + a(2)=0. !f1 + a(3)=0. !f2 + deltaa(1)=1.736 + deltaa(2)=1.736 + deltaa(3)=1.0 + nterms=3 + +! Start the iteration + chisqr=0. + chisqr0=1.e6 + c3=c3a + a3=a(3) + do iter=1,4 + do j=1,nterms + if(a(3).ne.a3) call shft(c3a,a(3),a3,c3) + chisq1=fchisq(c3,npts,fsample,a) + fn=0. + delta=deltaa(j) +10 a(j)=a(j)+delta + if(a(3).ne.a3) call shft(c3a,a(3),a3,c3) + chisq2=fchisq(c3,npts,fsample,a) + if(chisq2.eq.chisq1) go to 10 + if(chisq2.gt.chisq1) then + delta=-delta !Reverse direction + a(j)=a(j)+delta + tmp=chisq1 + chisq1=chisq2 + chisq2=tmp + endif +20 fn=fn+1.0 + a(j)=a(j)+delta + if(a(3).ne.a3) call shft(c3a,a(3),a3,c3) + chisq3=fchisq(c3,npts,fsample,a) + if(chisq3.lt.chisq2) then + chisq1=chisq2 + chisq2=chisq3 + go to 20 + endif + +! Find minimum of parabola defined by last three points + delta=delta*(1./(1.+(chisq1-chisq2)/(chisq3-chisq2))+0.5) + a(j)=a(j)-delta + if(j.lt.3) deltaa(j)=deltaa(j)*fn/3. +! write(*,4000) iter,j,a,-chisq2 +!4000 format(i1,i2,3f10.4,f11.3) + enddo + if(a(3).ne.a3) call shft(c3a,a(3),a3,c3) + chisqr=fchisq(c3,npts,fsample,a) +! write(*,4000) 0,0,a,-chisqr + if(chisqr/chisqr0.gt.0.99) exit + chisqr0=chisqr + enddo + + syncpk=-chisqr + c3a=c3 +! write(*,4001) a,syncpk +!4001 format(3x,3f10.4,f11.3) + + return +end subroutine afc9 + +subroutine shft(c3a,a3a,a3,c3) + complex c3a(0:1359) + complex c3(0:1359) + + a3=a3a + n=nint(a3) + c3=cshift(c3a,n) + if(n.gt.0) c3(1360-n:)=0.0 + if(n.lt.0) c3(:n-1)=0.0 + + return +end subroutine shft diff --git a/lib/ana932.f90 b/lib/ana932.f90 index 973f7ca1..2665b7a1 100755 --- a/lib/ana932.f90 +++ b/lib/ana932.f90 @@ -1,21 +1,21 @@ -subroutine ana932(dat,npts0,cdat,npts) - - real dat(npts0) - complex cdat(262145) - - n=log(float(npts0))/log(2.0) - nfft1=2**(n+1) - nfft2=9*nfft1/32 - df932=11025.0/nfft1 - fac=2.0/nfft1 - do i=1,npts0/2 - cdat(i)=fac*cmplx(dat(2*i-1),dat(2*i)) - enddo - cdat(npts0/2+1:nfft1/2)=0. - call four2a(cdat,nfft1,1,-1,0) !Forward r2c FFT - call four2a(cdat,nfft2,1,1,1) !Inverse c2c FFT - npts=npts0*9.0/32.0 !Downsampled data length - npts2=npts - - return -end subroutine ana932 +subroutine ana932(dat,npts0,cdat,npts) + + real dat(npts0) + complex cdat(262145) + + n=log(float(npts0))/log(2.0) + nfft1=2**(n+1) + nfft2=9*nfft1/32 + df932=11025.0/nfft1 + fac=2.0/nfft1 + do i=1,npts0/2 + cdat(i)=fac*cmplx(dat(2*i-1),dat(2*i)) + enddo + cdat(npts0/2+1:nfft1/2)=0. + call four2a(cdat,nfft1,1,-1,0) !Forward r2c FFT + call four2a(cdat,nfft2,1,1,1) !Inverse c2c FFT + npts=npts0*9.0/32.0 !Downsampled data length + npts2=npts + + return +end subroutine ana932 diff --git a/lib/astrosub.f90 b/lib/astrosub.f90 index f6f618fc..e190fac1 100755 --- a/lib/astrosub.f90 +++ b/lib/astrosub.f90 @@ -1,98 +1,98 @@ -module astro_module - implicit none - - private - public :: astrosub - - logical :: initialized = .false. - integer :: azel_extra_lines = 0 - -contains - - subroutine astrosub(nyear,month,nday,uth8,freq8,mygrid_cp, & - hisgrid_cp,AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8, & - ntsky,ndop,ndop00,RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8,techo8,width1, & - width2,bTx,AzElFileName_cp,jpleph_file_name_cp) & - bind (C, name="astrosub") - - use :: types, only: dp - use :: C_interface_module, only: C_int, C_double, C_bool, C_ptr, C_string_value, assignment(=) - - integer(C_int), intent(in), value :: nyear, month, nday - real(C_double), intent(in), value :: uth8, freq8 - real(C_double), intent(out) :: AzSun8, ElSun8, AzMoon8, ElMoon8, AzMoonB8, & - ElMoonB8, Ramoon8, DecMoon8, Dgrd8, poloffset8, xnr8, techo8, width1, & - width2 - integer(C_int), intent(out) :: ntsky, ndop, ndop00 - logical(C_bool), intent(in), value :: bTx - type(C_ptr), value, intent(in) :: mygrid_cp, hisgrid_cp, AzElFileName_cp, & - jpleph_file_name_cp - - character(len=6) :: mygrid, hisgrid - character(len=:), allocatable :: AzElFileName - character(len=1) :: c1 - character(len=32) :: envvar - integer :: ih, im, imin, is, isec, nfreq, env_status - real(dp) :: AzAux, ElAux, dbMoon8, dfdt, dfdt0, doppler, doppler00, HA8, sd8, xlst8 - character*256 jpleph_file_name - common/jplcom/jpleph_file_name - - if (.not.initialized) then - call get_environment_variable ('WSJT_AZEL_EXTRA_LINES', envvar, status=env_status) - if (env_status.eq.0) read (envvar, *, iostat=env_status) azel_extra_lines - initialized = .true. - end if - - mygrid = mygrid_cp - hisgrid = hisgrid_cp - AzElFileName = C_string_value (AzElFileName_cp) - jpleph_file_name = jpleph_file_name_cp - - call astro0(nyear,month,nday,uth8,freq8,mygrid,hisgrid, & - AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & - dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, & - width1,width2,xlst8,techo8) - - if (len_trim(AzElFileName) .eq. 0) go to 999 - if(len(trim(hisgrid)).eq.0) then !If DX grid is blank, set these to zero: - AzMoonB8=0 - ElMoonB8=0 - ndop=0 - width2=0 - endif - imin=60*uth8 - isec=3600*uth8 - ih=uth8 - im=mod(imin,60) - is=mod(isec,60) - open(15,file=AzElFileName,status='unknown',err=900) - c1='R' - if(bTx) then - c1='T' - endif - AzAux=0. - ElAux=0. - nfreq=freq8/1000000 - doppler=ndop - doppler00=ndop00 - write(15,1010,err=10) ih,im,is,AzMoon8,ElMoon8, & - ih,im,is,AzSun8,ElSun8, & - ih,im,is,AzAux,ElAux, & - nfreq,doppler,dfdt,doppler00,dfdt0,c1 - if (azel_extra_lines.ge.1) write(15, 1020, err=10) poloffset8, & - xnr8,Dgrd8,width1,width2 -1010 format( & - i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Moon'/ & - i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Sun'/ & - i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Source'/ & - i5,',',f8.1,',',f8.2,',',f8.1,',',f8.2,',Doppler, ',a1) -1020 format(f8.1,',',f8.1,',',f8.1,',',f8.1,',',f8.1,',Pol') -10 close(15) - go to 999 - -900 print*,'Error opening azel.dat' - -999 return - end subroutine astrosub - -end module astro_module +module astro_module + implicit none + + private + public :: astrosub + + logical :: initialized = .false. + integer :: azel_extra_lines = 0 + +contains + + subroutine astrosub(nyear,month,nday,uth8,freq8,mygrid_cp, & + hisgrid_cp,AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8, & + ntsky,ndop,ndop00,RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8,techo8,width1, & + width2,bTx,AzElFileName_cp,jpleph_file_name_cp) & + bind (C, name="astrosub") + + use :: types, only: dp + use :: C_interface_module, only: C_int, C_double, C_bool, C_ptr, C_string_value, assignment(=) + + integer(C_int), intent(in), value :: nyear, month, nday + real(C_double), intent(in), value :: uth8, freq8 + real(C_double), intent(out) :: AzSun8, ElSun8, AzMoon8, ElMoon8, AzMoonB8, & + ElMoonB8, Ramoon8, DecMoon8, Dgrd8, poloffset8, xnr8, techo8, width1, & + width2 + integer(C_int), intent(out) :: ntsky, ndop, ndop00 + logical(C_bool), intent(in), value :: bTx + type(C_ptr), value, intent(in) :: mygrid_cp, hisgrid_cp, AzElFileName_cp, & + jpleph_file_name_cp + + character(len=6) :: mygrid, hisgrid + character(len=:), allocatable :: AzElFileName + character(len=1) :: c1 + character(len=32) :: envvar + integer :: ih, im, imin, is, isec, nfreq, env_status + real(dp) :: AzAux, ElAux, dbMoon8, dfdt, dfdt0, doppler, doppler00, HA8, sd8, xlst8 + character*256 jpleph_file_name + common/jplcom/jpleph_file_name + + if (.not.initialized) then + call get_environment_variable ('WSJT_AZEL_EXTRA_LINES', envvar, status=env_status) + if (env_status.eq.0) read (envvar, *, iostat=env_status) azel_extra_lines + initialized = .true. + end if + + mygrid = mygrid_cp + hisgrid = hisgrid_cp + AzElFileName = C_string_value (AzElFileName_cp) + jpleph_file_name = jpleph_file_name_cp + + call astro0(nyear,month,nday,uth8,freq8,mygrid,hisgrid, & + AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & + dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, & + width1,width2,xlst8,techo8) + + if (len_trim(AzElFileName) .eq. 0) go to 999 + if(len(trim(hisgrid)).eq.0) then !If DX grid is blank, set these to zero: + AzMoonB8=0 + ElMoonB8=0 + ndop=0 + width2=0 + endif + imin=60*uth8 + isec=3600*uth8 + ih=uth8 + im=mod(imin,60) + is=mod(isec,60) + open(15,file=AzElFileName,status='unknown',err=900) + c1='R' + if(bTx) then + c1='T' + endif + AzAux=0. + ElAux=0. + nfreq=freq8/1000000 + doppler=ndop + doppler00=ndop00 + write(15,1010,err=10) ih,im,is,AzMoon8,ElMoon8, & + ih,im,is,AzSun8,ElSun8, & + ih,im,is,AzAux,ElAux, & + nfreq,doppler,dfdt,doppler00,dfdt0,c1 + if (azel_extra_lines.ge.1) write(15, 1020, err=10) poloffset8, & + xnr8,Dgrd8,width1,width2 +1010 format( & + i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Moon'/ & + i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Sun'/ & + i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Source'/ & + i5,',',f8.1,',',f8.2,',',f8.1,',',f8.2,',Doppler, ',a1) +1020 format(f8.1,',',f8.1,',',f8.1,',',f8.1,',',f8.1,',Pol') +10 close(15) + go to 999 + +900 print*,'Error opening azel.dat' + +999 return + end subroutine astrosub + +end module astro_module diff --git a/lib/avecho.f90 b/lib/avecho.f90 index 7b499a05..90e828d5 100755 --- a/lib/avecho.f90 +++ b/lib/avecho.f90 @@ -1,120 +1,120 @@ -subroutine avecho(id2,ndop,nfrit,nauto,navg,nqual,f1,xlevel,snrdb, & - db_err,dfreq,width,bDiskData) - - integer TXLENGTH - parameter (TXLENGTH=27648) !27*1024 - parameter (NFFT=32768,NH=NFFT/2) - parameter (NZ=4096) - integer*2 id2(34560) !Buffer for Rx data - real sa(NZ) !Avg spectrum relative to initial Doppler echo freq - real sb(NZ) !Avg spectrum with Dither and changing Doppler removed - real, dimension (:,:), allocatable :: sax - real, dimension (:,:), allocatable :: sbx - integer nsum !Number of integrations - real dop0 !Doppler shift for initial integration (Hz) - real dop !Doppler shift for current integration (Hz) - real s(8192) - real x(NFFT) - integer ipkv(1) - logical ex - logical*1 bDiskData - complex c(0:NH) - equivalence (x,c),(ipk,ipkv) - common/echocom/nclearave,nsum,blue(NZ),red(NZ) - common/echocom2/fspread_self,fspread_dx - data navg0/-1/ - save dop0,navg0,sax,sbx - - if(navg.ne.navg0) then - if(allocated(sax)) deallocate(sax) - if(allocated(sbx)) deallocate(sbx) - allocate(sax(1:navg,1:NZ)) - allocate(sbx(1:navg,1:NZ)) - nsum=0 - navg0=navg - endif - - fspread=fspread_dx !### Use the predicted Doppler spread ### - if(bDiskData) fspread=width - if(nauto.eq.1) fspread=fspread_self - inquire(file='fspread.txt',exist=ex) - if(ex) then - open(39,file='fspread.txt',status='old') - read(39,*) fspread - close(39) - endif - fspread=min(max(0.04,fspread),700.0) - width=fspread - dop=ndop - sq=0. - do i=1,TXLENGTH - x(i)=id2(i) - sq=sq + x(i)*x(i) - enddo - xlevel=10.0*log10(sq/TXLENGTH) - - if(nclearave.ne.0) nsum=0 - if(nsum.eq.0) then - dop0=dop !Remember the initial Doppler - sax=0. !Clear the average arrays - sbx=0. - endif - - x(TXLENGTH+1:)=0. - x=x/TXLENGTH - call four2a(x,NFFT,1,-1,0) - df=12000.0/NFFT - do i=1,8192 !Get spectrum 0 - 3 kHz - s(i)=real(c(i))**2 + aimag(c(i))**2 - enddo - - fnominal=1500.0 !Nominal audio frequency w/o doppler or dither - ia=nint((fnominal+dop0-nfrit)/df) - ib=nint((f1+dop-nfrit)/df) - if(ia.lt.2048 .or. ib.lt.2048 .or. ia.gt.6144 .or. ib.gt.6144) then - snrdb=0. - db_err=0. - dfreq=0. - go to 900 - endif - - nsum=nsum+1 - j=mod(nsum-1,navg)+1 - do i=1,NZ - sax(j,i)=s(ia+i-2048) !Center at initial doppler freq - sbx(j,i)=s(ib+i-2048) !Center at expected echo freq - sa(i)=sum(sax(1:navg,i)) - sb(i)=sum(sbx(1:navg,i)) - enddo - - call echo_snr(sa,sb,fspread,blue,red,snrdb,db_err,dfreq,snr_detect) - nqual=snr_detect-2 - if(nqual.lt.0) nqual=0 - if(nqual.gt.10) nqual=10 - -! Scale for plotting - redmax=maxval(red) - fac=10.0/max(redmax,10.0) - blue=fac*blue - red=fac*red - nsmo=max(0.0,0.25*width/df) - do i=1,nsmo - call smo121(red,NZ) - call smo121(blue,NZ) - enddo - - ia=50.0/df - ib=250.0/df - call pctile(red(ia:ib),ib-ia+1,50,bred1) - call pctile(blue(ia:ib),ib-ia+1,50,bblue1) - ia=1250.0/df - ib=1450.0/df - call pctile(red(ia:ib),ib-ia+1,50,bred2) - call pctile(blue(ia:ib),ib-ia+1,50,bblue2) - - red=red-0.5*(bred1+bred2) - blue=blue-0.5*(bblue1+bblue2) - -900 call sleep_msec(10) !Avoid the "blue Decode button" syndrome - return -end subroutine avecho +subroutine avecho(id2,ndop,nfrit,nauto,navg,nqual,f1,xlevel,snrdb, & + db_err,dfreq,width,bDiskData) + + integer TXLENGTH + parameter (TXLENGTH=27648) !27*1024 + parameter (NFFT=32768,NH=NFFT/2) + parameter (NZ=4096) + integer*2 id2(34560) !Buffer for Rx data + real sa(NZ) !Avg spectrum relative to initial Doppler echo freq + real sb(NZ) !Avg spectrum with Dither and changing Doppler removed + real, dimension (:,:), allocatable :: sax + real, dimension (:,:), allocatable :: sbx + integer nsum !Number of integrations + real dop0 !Doppler shift for initial integration (Hz) + real dop !Doppler shift for current integration (Hz) + real s(8192) + real x(NFFT) + integer ipkv(1) + logical ex + logical*1 bDiskData + complex c(0:NH) + equivalence (x,c),(ipk,ipkv) + common/echocom/nclearave,nsum,blue(NZ),red(NZ) + common/echocom2/fspread_self,fspread_dx + data navg0/-1/ + save dop0,navg0,sax,sbx + + if(navg.ne.navg0) then + if(allocated(sax)) deallocate(sax) + if(allocated(sbx)) deallocate(sbx) + allocate(sax(1:navg,1:NZ)) + allocate(sbx(1:navg,1:NZ)) + nsum=0 + navg0=navg + endif + + fspread=fspread_dx !### Use the predicted Doppler spread ### + if(bDiskData) fspread=width + if(nauto.eq.1) fspread=fspread_self + inquire(file='fspread.txt',exist=ex) + if(ex) then + open(39,file='fspread.txt',status='old') + read(39,*) fspread + close(39) + endif + fspread=min(max(0.04,fspread),700.0) + width=fspread + dop=ndop + sq=0. + do i=1,TXLENGTH + x(i)=id2(i) + sq=sq + x(i)*x(i) + enddo + xlevel=10.0*log10(sq/TXLENGTH) + + if(nclearave.ne.0) nsum=0 + if(nsum.eq.0) then + dop0=dop !Remember the initial Doppler + sax=0. !Clear the average arrays + sbx=0. + endif + + x(TXLENGTH+1:)=0. + x=x/TXLENGTH + call four2a(x,NFFT,1,-1,0) + df=12000.0/NFFT + do i=1,8192 !Get spectrum 0 - 3 kHz + s(i)=real(c(i))**2 + aimag(c(i))**2 + enddo + + fnominal=1500.0 !Nominal audio frequency w/o doppler or dither + ia=nint((fnominal+dop0-nfrit)/df) + ib=nint((f1+dop-nfrit)/df) + if(ia.lt.2048 .or. ib.lt.2048 .or. ia.gt.6144 .or. ib.gt.6144) then + snrdb=0. + db_err=0. + dfreq=0. + go to 900 + endif + + nsum=nsum+1 + j=mod(nsum-1,navg)+1 + do i=1,NZ + sax(j,i)=s(ia+i-2048) !Center at initial doppler freq + sbx(j,i)=s(ib+i-2048) !Center at expected echo freq + sa(i)=sum(sax(1:navg,i)) + sb(i)=sum(sbx(1:navg,i)) + enddo + + call echo_snr(sa,sb,fspread,blue,red,snrdb,db_err,dfreq,snr_detect) + nqual=snr_detect-2 + if(nqual.lt.0) nqual=0 + if(nqual.gt.10) nqual=10 + +! Scale for plotting + redmax=maxval(red) + fac=10.0/max(redmax,10.0) + blue=fac*blue + red=fac*red + nsmo=max(0.0,0.25*width/df) + do i=1,nsmo + call smo121(red,NZ) + call smo121(blue,NZ) + enddo + + ia=50.0/df + ib=250.0/df + call pctile(red(ia:ib),ib-ia+1,50,bred1) + call pctile(blue(ia:ib),ib-ia+1,50,bblue1) + ia=1250.0/df + ib=1450.0/df + call pctile(red(ia:ib),ib-ia+1,50,bred2) + call pctile(blue(ia:ib),ib-ia+1,50,bblue2) + + red=red-0.5*(bred1+bred2) + blue=blue-0.5*(bblue1+bblue2) + +900 call sleep_msec(10) !Avoid the "blue Decode button" syndrome + return +end subroutine avecho diff --git a/lib/averms.f90 b/lib/averms.f90 index 6b9da3fd..a037c27d 100755 --- a/lib/averms.f90 +++ b/lib/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((nskip.lt.0) .or. (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((nskip.lt.0) .or. (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/lib/avg4.f90 b/lib/avg4.f90 index 0573ab6f..fc37ec05 100755 --- a/lib/avg4.f90 +++ b/lib/avg4.f90 @@ -1,2 +1,2 @@ - ! The contents of this file have been migrated to lib/jt4_decode.f90 - + ! The contents of this file have been migrated to lib/jt4_decode.f90 + diff --git a/lib/blanker.f90 b/lib/blanker.f90 index 8e4527ce..fe43931b 100755 --- a/lib/blanker.f90 +++ b/lib/blanker.f90 @@ -1,52 +1,52 @@ -subroutine blanker(iwave,nz,ndropmax,npct,c_bigfft) - - integer*2 iwave(nz) - complex c_bigfft(0:nz/2) - integer hist(0:32768) - real fblank !Fraction of points to be blanked - - fblank=0.01*npct - hist=0 - do i=1,nz -! ### NB: if iwave(i)=-32768, abs(iwave(i))=-32768 ### - if(iwave(i).eq.-32768) iwave(i)=-32767 - n=abs(iwave(i)) - hist(n)=hist(n)+1 - enddo - n=0 - do i=32768,0,-1 - n=n+hist(i) - if(n.ge.nint(nz*fblank/ndropmax)) exit - enddo - nthresh=i - ndrop=0 - ndropped=0 - - xx=0. - do i=1,nz - i0=iwave(i) - if(ndrop.gt.0) then - i0=0 - ndropped=ndropped+1 - ndrop=ndrop-1 - endif - -! Start to apply blanking - if(abs(i0).gt.nthresh) then - i0=0 - ndropped=ndropped+1 - ndrop=ndropmax - endif - -! Now copy the data into c_bigfft - if(iand(i,1).eq.1) then - xx=i0 - else - yy=i0 - j=i/2 - 1 - c_bigfft(j)=cmplx(xx,yy) - endif - enddo - - return -end subroutine blanker +subroutine blanker(iwave,nz,ndropmax,npct,c_bigfft) + + integer*2 iwave(nz) + complex c_bigfft(0:nz/2) + integer hist(0:32768) + real fblank !Fraction of points to be blanked + + fblank=0.01*npct + hist=0 + do i=1,nz +! ### NB: if iwave(i)=-32768, abs(iwave(i))=-32768 ### + if(iwave(i).eq.-32768) iwave(i)=-32767 + n=abs(iwave(i)) + hist(n)=hist(n)+1 + enddo + n=0 + do i=32768,0,-1 + n=n+hist(i) + if(n.ge.nint(nz*fblank/ndropmax)) exit + enddo + nthresh=i + ndrop=0 + ndropped=0 + + xx=0. + do i=1,nz + i0=iwave(i) + if(ndrop.gt.0) then + i0=0 + ndropped=ndropped+1 + ndrop=ndrop-1 + endif + +! Start to apply blanking + if(abs(i0).gt.nthresh) then + i0=0 + ndropped=ndropped+1 + ndrop=ndropmax + endif + +! Now copy the data into c_bigfft + if(iand(i,1).eq.1) then + xx=i0 + else + yy=i0 + j=i/2 - 1 + c_bigfft(j)=cmplx(xx,yy) + endif + enddo + + return +end subroutine blanker diff --git a/lib/bpdecode128_90.f90 b/lib/bpdecode128_90.f90 index 69136738..9e018dc7 100755 --- a/lib/bpdecode128_90.f90 +++ b/lib/bpdecode128_90.f90 @@ -1,117 +1,117 @@ -subroutine bpdecode128_90(llr,apmask,maxiterations,message77,cw,nharderror,iter) -! -! A log-domain belief propagation decoder for the (128,90) code. -! - use iso_c_binding, only: c_loc,c_size_t - use crc - integer, parameter:: N=128, K=90, M=N-K - integer*1 cw(N),apmask(N) - integer*1 decoded(K) - integer*1 message77(77) - integer Nm(11,M) - integer Mn(3,N) - integer nrw(M) - integer synd(M) - real tov(4,N) - real toc(11,M) - real tanhtoc(11,M) - real zn(N) - real llr(N) - real Tmn - - include "ldpc_128_90_reordered_parity.f90" - - decoded=0 - toc=0 - tov=0 - tanhtoc=0 -! initialize messages to checks - do j=1,M - do i=1,nrw(j) - toc(i,j)=llr((Nm(i,j))) - enddo - enddo - - ncnt=0 - nclast=0 - - do iter=0,maxiterations - -! Update bit log likelihood ratios (tov=0 in iteration 0). - do i=1,N - if( apmask(i) .ne. 1 ) then - zn(i)=llr(i)+sum(tov(1:ncw,i)) - else - zn(i)=llr(i) - endif - enddo - -! Check to see if we have a codeword (check before we do any iteration). - cw=0 - where( zn .gt. 0. ) cw=1 - ncheck=0 - do i=1,M - synd(i)=sum(cw(Nm(1:nrw(i),i))) - if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 -! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied' - enddo -! write(*,*) 'number of unsatisfied parity checks ',ncheck - if( ncheck .eq. 0 ) then ! we have a codeword - reorder the columns and return it - decoded=cw(1:K) - call chkcrc13a(decoded,nbadcrc) - if(nbadcrc.eq.0) then - message77=decoded(1:77) - nharderror=count( (2*cw-1)*llr .lt. 0.0 ) - return - endif - endif - - if( iter.gt.0 ) then ! this code block implements an early stopping criterion -! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion - nd=ncheck-nclast - if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased - ncnt=0 ! reset counter - else - ncnt=ncnt+1 - endif -! write(*,*) iter,ncheck,nd,ncnt - if( ncnt .ge. 3 .and. iter .ge. 5 .and. ncheck .gt. 10) then - nharderror=-1 - return - endif - endif - nclast=ncheck - -! Send messages from bits to check nodes - do j=1,M - do i=1,nrw(j) - ibj=Nm(i,j) - toc(i,j)=zn(ibj) - do kk=1,ncw ! subtract off what the bit had received from the check - if( Mn(kk,ibj) .eq. j ) then - toc(i,j)=toc(i,j)-tov(kk,ibj) - endif - enddo - enddo - enddo - -! send messages from check nodes to variable nodes - do i=1,M - tanhtoc(1:11,i)=tanh(-toc(1:11,i)/2) - enddo - - do j=1,N - do i=1,ncw - ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j - Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) - call platanh(-Tmn,y) -! y=atanh(-Tmn) - tov(i,j)=2*y - enddo - enddo - - enddo - nharderror=-1 - return - -end subroutine bpdecode128_90 +subroutine bpdecode128_90(llr,apmask,maxiterations,message77,cw,nharderror,iter) +! +! A log-domain belief propagation decoder for the (128,90) code. +! + use iso_c_binding, only: c_loc,c_size_t + use crc + integer, parameter:: N=128, K=90, M=N-K + integer*1 cw(N),apmask(N) + integer*1 decoded(K) + integer*1 message77(77) + integer Nm(11,M) + integer Mn(3,N) + integer nrw(M) + integer synd(M) + real tov(4,N) + real toc(11,M) + real tanhtoc(11,M) + real zn(N) + real llr(N) + real Tmn + + include "ldpc_128_90_reordered_parity.f90" + + decoded=0 + toc=0 + tov=0 + tanhtoc=0 +! initialize messages to checks + do j=1,M + do i=1,nrw(j) + toc(i,j)=llr((Nm(i,j))) + enddo + enddo + + ncnt=0 + nclast=0 + + do iter=0,maxiterations + +! Update bit log likelihood ratios (tov=0 in iteration 0). + do i=1,N + if( apmask(i) .ne. 1 ) then + zn(i)=llr(i)+sum(tov(1:ncw,i)) + else + zn(i)=llr(i) + endif + enddo + +! Check to see if we have a codeword (check before we do any iteration). + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(1:nrw(i),i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 +! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied' + enddo +! write(*,*) 'number of unsatisfied parity checks ',ncheck + if( ncheck .eq. 0 ) then ! we have a codeword - reorder the columns and return it + decoded=cw(1:K) + call chkcrc13a(decoded,nbadcrc) + if(nbadcrc.eq.0) then + message77=decoded(1:77) + nharderror=count( (2*cw-1)*llr .lt. 0.0 ) + return + endif + endif + + if( iter.gt.0 ) then ! this code block implements an early stopping criterion +! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion + nd=ncheck-nclast + if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased + ncnt=0 ! reset counter + else + ncnt=ncnt+1 + endif +! write(*,*) iter,ncheck,nd,ncnt + if( ncnt .ge. 3 .and. iter .ge. 5 .and. ncheck .gt. 10) then + nharderror=-1 + return + endif + endif + nclast=ncheck + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw(j) + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,ncw ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then + toc(i,j)=toc(i,j)-tov(kk,ibj) + endif + enddo + enddo + enddo + +! send messages from check nodes to variable nodes + do i=1,M + tanhtoc(1:11,i)=tanh(-toc(1:11,i)/2) + enddo + + do j=1,N + do i=1,ncw + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) + call platanh(-Tmn,y) +! y=atanh(-Tmn) + tov(i,j)=2*y + enddo + enddo + + enddo + nharderror=-1 + return + +end subroutine bpdecode128_90 diff --git a/lib/bpdecode128_90.f90.save b/lib/bpdecode128_90.f90.save index 12a8547b..69537afb 100755 --- a/lib/bpdecode128_90.f90.save +++ b/lib/bpdecode128_90.f90.save @@ -1,116 +1,116 @@ -subroutine bpdecode128_90(llr,apmask,maxiterations,message77,cw,nharderror,iter) -! -! A log-domain belief propagation decoder for the (128,90) code. -! - use iso_c_binding, only: c_loc,c_size_t - use crc - integer, parameter:: N=128, K=90, M=N-K - integer*1 cw(N),apmask(N) - integer*1 decoded(K) - integer*1 message77(77) - integer Nm(12,M) - integer Mn(4,N) - integer nrw(M),ncw(N) - integer synd(M) - real tov(4,N) - real toc(12,M) - real tanhtoc(12,M) - real zn(N) - real llr(N) - real Tmn - - include "ldpc_128_90_b_reordered_parity.f90" - - decoded=0 - toc=0 - tov=0 - tanhtoc=0 -! initialize messages to checks - do j=1,M - do i=1,nrw(j) - toc(i,j)=llr((Nm(i,j))) - enddo - enddo - - ncnt=0 - - do iter=0,maxiterations - -! Update bit log likelihood ratios (tov=0 in iteration 0). - do i=1,N - if( apmask(i) .ne. 1 ) then - zn(i)=llr(i)+sum(tov(1:ncw(i),i)) - else - zn(i)=llr(i) - endif - enddo - -! Check to see if we have a codeword (check before we do any iteration). - cw=0 - where( zn .gt. 0. ) cw=1 - ncheck=0 - do i=1,M - synd(i)=sum(cw(Nm(1:nrw(i),i))) - if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 -! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied' - enddo -! write(*,*) 'number of unsatisfied parity checks ',ncheck - if( ncheck .eq. 0 ) then ! we have a codeword - reorder the columns and return it - decoded=cw(1:K) - call chkcrc13a(decoded,nbadcrc) - if(nbadcrc.eq.0) then - message77=decoded(1:77) - nharderror=count( (2*cw-1)*llr .lt. 0.0 ) - return - endif - endif - - if( iter.gt.0 ) then ! this code block implements an early stopping criterion -! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion - nd=ncheck-nclast - if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased - ncnt=0 ! reset counter - else - ncnt=ncnt+1 - endif -! write(*,*) iter,ncheck,nd,ncnt - if( ncnt .ge. 3 .and. iter .ge. 5 .and. ncheck .gt. 10) then - nharderror=-1 - return - endif - endif - nclast=ncheck - -! Send messages from bits to check nodes - do j=1,M - do i=1,nrw(j) - ibj=Nm(i,j) - toc(i,j)=zn(ibj) - do kk=1,4 ! subtract off what the bit had received from the check - if( Mn(kk,ibj) .eq. j ) then - toc(i,j)=toc(i,j)-tov(kk,ibj) - endif - enddo - enddo - enddo - -! send messages from check nodes to variable nodes - do i=1,M - tanhtoc(1:12,i)=tanh(-toc(1:12,i)/2) - enddo - - do j=1,N - do i=1,ncw(j) - ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j - Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) - call platanh(-Tmn,y) -! y=atanh(-Tmn) - tov(i,j)=2*y - enddo - enddo - - enddo - nharderror=-1 - return - -end subroutine bpdecode128_90 +subroutine bpdecode128_90(llr,apmask,maxiterations,message77,cw,nharderror,iter) +! +! A log-domain belief propagation decoder for the (128,90) code. +! + use iso_c_binding, only: c_loc,c_size_t + use crc + integer, parameter:: N=128, K=90, M=N-K + integer*1 cw(N),apmask(N) + integer*1 decoded(K) + integer*1 message77(77) + integer Nm(12,M) + integer Mn(4,N) + integer nrw(M),ncw(N) + integer synd(M) + real tov(4,N) + real toc(12,M) + real tanhtoc(12,M) + real zn(N) + real llr(N) + real Tmn + + include "ldpc_128_90_b_reordered_parity.f90" + + decoded=0 + toc=0 + tov=0 + tanhtoc=0 +! initialize messages to checks + do j=1,M + do i=1,nrw(j) + toc(i,j)=llr((Nm(i,j))) + enddo + enddo + + ncnt=0 + + do iter=0,maxiterations + +! Update bit log likelihood ratios (tov=0 in iteration 0). + do i=1,N + if( apmask(i) .ne. 1 ) then + zn(i)=llr(i)+sum(tov(1:ncw(i),i)) + else + zn(i)=llr(i) + endif + enddo + +! Check to see if we have a codeword (check before we do any iteration). + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(1:nrw(i),i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 +! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied' + enddo +! write(*,*) 'number of unsatisfied parity checks ',ncheck + if( ncheck .eq. 0 ) then ! we have a codeword - reorder the columns and return it + decoded=cw(1:K) + call chkcrc13a(decoded,nbadcrc) + if(nbadcrc.eq.0) then + message77=decoded(1:77) + nharderror=count( (2*cw-1)*llr .lt. 0.0 ) + return + endif + endif + + if( iter.gt.0 ) then ! this code block implements an early stopping criterion +! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion + nd=ncheck-nclast + if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased + ncnt=0 ! reset counter + else + ncnt=ncnt+1 + endif +! write(*,*) iter,ncheck,nd,ncnt + if( ncnt .ge. 3 .and. iter .ge. 5 .and. ncheck .gt. 10) then + nharderror=-1 + return + endif + endif + nclast=ncheck + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw(j) + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,4 ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then + toc(i,j)=toc(i,j)-tov(kk,ibj) + endif + enddo + enddo + enddo + +! send messages from check nodes to variable nodes + do i=1,M + tanhtoc(1:12,i)=tanh(-toc(1:12,i)/2) + enddo + + do j=1,N + do i=1,ncw(j) + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) + call platanh(-Tmn,y) +! y=atanh(-Tmn) + tov(i,j)=2*y + enddo + enddo + + enddo + nharderror=-1 + return + +end subroutine bpdecode128_90 diff --git a/lib/bpdecode144.f90 b/lib/bpdecode144.f90 index 3189b035..8cbf9120 100755 --- a/lib/bpdecode144.f90 +++ b/lib/bpdecode144.f90 @@ -1,348 +1,348 @@ -subroutine pltanh(x,y) - isign=+1 - z=x - if( x.lt.0 ) then - isign=-1 - z=abs(x) - endif - if( z.le. 0.8 ) then - y=0.83*x - return - elseif( z.le. 1.6 ) then - y=isign*(0.322*z+0.4064) - return - elseif( z.le. 3.0 ) then - y=isign*(0.0524*z+0.8378) - return - elseif( z.lt. 7.0 ) then - y=isign*(0.0012*z+0.9914) - return - else - y=isign*0.9998 - return - endif -end subroutine pltanh - -subroutine platanh(x,y) - isign=+1 - z=x - if( x.lt.0 ) then - isign=-1 - z=abs(x) - endif - if( z.le. 0.664 ) then - y=x/0.83 - return - elseif( z.le. 0.9217 ) then - y=isign*(z-0.4064)/0.322 - return - elseif( z.le. 0.9951 ) then - y=isign*(z-0.8378)/0.0524 - return - elseif( z.le. 0.9998 ) then - y=isign*(z-0.9914)/0.0012 - return - else - y=isign*7.0 - return - endif -end subroutine platanh - -subroutine bpdecode144(llr,maxiterations,decoded,niterations) -! -! A log-domain belief propagation decoder for the msk144 code. -! The code is a regular (128,80) code with column weight 3 and row weight 8. -! k9an August, 2016 -! -integer, parameter:: N=128, K=80, M=N-K -integer*1 codeword(N),cw(N) -integer*1 colorder(N) -integer*1 decoded(K) -integer Nm(8,M) ! 8 bits per check -integer Mn(3,N) ! 3 checks per bit -integer synd(M) -real tov(3,N) ! single precision seems to be adequate in log-domain -real toc(8,M) -real tanhtoc(8,M) -real zn(N) -real llr(N) -real Tmn - -data colorder/0,1,2,3,4,5,6,7,8,9, & - 10,11,12,13,14,15,24,26,29,30, & - 32,43,44,47,60,77,79,97,101,111, & - 96,38,64,53,93,34,59,94,74,90, & - 108,123,85,57,70,25,69,62,48,49, & - 50,51,52,33,54,55,56,21,58,36, & - 16,61,23,63,20,65,66,67,68,46, & - 22,71,72,73,31,75,76,45,78,17, & - 80,81,82,83,84,42,86,87,88,89, & - 39,91,92,35,37,95,19,27,98,99, & - 100,28,102,103,104,105,106,107,40,109, & - 110,18,112,113,114,115,116,117,118,119, & - 120,121,122,41,124,125,126,127/ - -data Mn/ & - 1, 14, 38, & - 2, 4, 41, & - 3, 19, 39, & - 5, 29, 34, & - 6, 35, 40, & - 7, 20, 45, & - 8, 28, 48, & - 9, 22, 25, & - 10, 24, 36, & - 11, 12, 37, & - 13, 43, 44, & - 15, 18, 46, & - 16, 17, 47, & - 21, 32, 33, & - 23, 30, 31, & - 26, 27, 42, & - 1, 12, 46, & - 2, 36, 38, & - 3, 5, 10, & - 4, 9, 23, & - 6, 13, 39, & - 7, 15, 17, & - 8, 18, 27, & - 11, 33, 40, & - 14, 28, 44, & - 16, 29, 31, & - 19, 20, 22, & - 21, 30, 42, & - 24, 26, 47, & - 25, 37, 48, & - 32, 34, 45, & - 8, 35, 41, & - 12, 31, 43, & - 1, 19, 21, & - 2, 43, 45, & - 3, 4, 11, & - 5, 18, 33, & - 6, 25, 47, & - 7, 28, 30, & - 9, 14, 34, & - 10, 35, 42, & - 13, 15, 22, & - 16, 37, 38, & - 17, 41, 44, & - 20, 24, 29, & - 18, 23, 39, & - 12, 26, 32, & - 27, 38, 40, & - 15, 36, 48, & - 2, 30, 46, & - 1, 4, 13, & - 3, 28, 32, & - 5, 43, 47, & - 6, 34, 46, & - 7, 9, 40, & - 8, 11, 45, & - 10, 17, 23, & - 14, 31, 35, & - 16, 22, 42, & - 19, 37, 44, & - 20, 33, 48, & - 21, 24, 41, & - 25, 27, 29, & - 26, 39, 48, & - 19, 31, 36, & - 1, 5, 7, & - 2, 29, 39, & - 3, 16, 46, & - 4, 26, 37, & - 6, 28, 45, & - 8, 22, 33, & - 9, 21, 43, & - 10, 25, 38, & - 11, 14, 24, & - 12, 17, 40, & - 13, 27, 30, & - 15, 32, 35, & - 18, 44, 47, & - 20, 23, 36, & - 34, 41, 42, & - 1, 32, 48, & - 2, 3, 33, & - 4, 29, 42, & - 5, 14, 37, & - 6, 7, 36, & - 8, 9, 39, & - 10, 13, 19, & - 11, 18, 30, & - 12, 16, 20, & - 15, 29, 44, & - 17, 34, 38, & - 6, 21, 22, & - 23, 32, 40, & - 24, 27, 46, & - 25, 41, 45, & - 7, 26, 43, & - 28, 31, 47, & - 20, 35, 38, & - 1, 33, 41, & - 2, 42, 44, & - 3, 23, 48, & - 4, 31, 45, & - 5, 8, 30, & - 9, 16, 36, & - 10, 40, 47, & - 11, 17, 46, & - 12, 21, 34, & - 13, 24, 28, & - 14, 18, 43, & - 15, 25, 26, & - 19, 27, 35, & - 22, 37, 39, & - 1, 16, 18, & - 2, 6, 20, & - 3, 30, 43, & - 4, 28, 33, & - 5, 22, 23, & - 7, 39, 42, & - 8, 12, 38, & - 9, 35, 46, & - 10, 27, 32, & - 11, 15, 34, & - 13, 36, 37, & - 14, 41, 47, & - 17, 21, 25, & - 19, 29, 45, & - 24, 31, 48, & - 26, 40, 44/ - -data Nm/ & - 1, 17, 34, 51, 66, 81, 99, 113, & - 2, 18, 35, 50, 67, 82, 100, 114, & - 3, 19, 36, 52, 68, 82, 101, 115, & - 2, 20, 36, 51, 69, 83, 102, 116, & - 4, 19, 37, 53, 66, 84, 103, 117, & - 5, 21, 38, 54, 70, 85, 92, 114, & - 6, 22, 39, 55, 66, 85, 96, 118, & - 7, 23, 32, 56, 71, 86, 103, 119, & - 8, 20, 40, 55, 72, 86, 104, 120, & - 9, 19, 41, 57, 73, 87, 105, 121, & - 10, 24, 36, 56, 74, 88, 106, 122, & - 10, 17, 33, 47, 75, 89, 107, 119, & - 11, 21, 42, 51, 76, 87, 108, 123, & - 1, 25, 40, 58, 74, 84, 109, 124, & - 12, 22, 42, 49, 77, 90, 110, 122, & - 13, 26, 43, 59, 68, 89, 104, 113, & - 13, 22, 44, 57, 75, 91, 106, 125, & - 12, 23, 37, 46, 78, 88, 109, 113, & - 3, 27, 34, 60, 65, 87, 111, 126, & - 6, 27, 45, 61, 79, 89, 98, 114, & - 14, 28, 34, 62, 72, 92, 107, 125, & - 8, 27, 42, 59, 71, 92, 112, 117, & - 15, 20, 46, 57, 79, 93, 101, 117, & - 9, 29, 45, 62, 74, 94, 108, 127, & - 8, 30, 38, 63, 73, 95, 110, 125, & - 16, 29, 47, 64, 69, 96, 110, 128, & - 16, 23, 48, 63, 76, 94, 111, 121, & - 7, 25, 39, 52, 70, 97, 108, 116, & - 4, 26, 45, 63, 67, 83, 90, 126, & - 15, 28, 39, 50, 76, 88, 103, 115, & - 15, 26, 33, 58, 65, 97, 102, 127, & - 14, 31, 47, 52, 77, 81, 93, 121, & - 14, 24, 37, 61, 71, 82, 99, 116, & - 4, 31, 40, 54, 80, 91, 107, 122, & - 5, 32, 41, 58, 77, 98, 111, 120, & - 9, 18, 49, 65, 79, 85, 104, 123, & - 10, 30, 43, 60, 69, 84, 112, 123, & - 1, 18, 43, 48, 73, 91, 98, 119, & - 3, 21, 46, 64, 67, 86, 112, 118, & - 5, 24, 48, 55, 75, 93, 105, 128, & - 2, 32, 44, 62, 80, 95, 99, 124, & - 16, 28, 41, 59, 80, 83, 100, 118, & - 11, 33, 35, 53, 72, 96, 109, 115, & - 11, 25, 44, 60, 78, 90, 100, 128, & - 6, 31, 35, 56, 70, 95, 102, 126, & - 12, 17, 50, 54, 68, 94, 106, 120, & - 13, 29, 38, 53, 78, 97, 105, 124, & - 7, 30, 49, 61, 64, 81, 101, 127/ - -nrw=8 -ncw=3 - -toc=0 -tov=0 -tanhtoc=0 - -! initial messages to checks -do j=1,M - do i=1,nrw - toc(i,j)=llr((Nm(i,j))) - enddo -enddo - -ncnt=0 - -do iter=0,maxiterations - -! Update bit log likelihood ratios - do i=1,N - zn(i)=llr(i)+sum(tov(1:ncw,i)) - enddo - -! Check to see if we have a codeword - cw=0 - where( zn .gt. 0. ) cw=1 - ncheck=0 - do i=1,M - synd(i)=sum(cw(Nm(:,i))) - if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 - enddo - - if( ncheck .eq. 0 ) then ! we have a codeword - niterations=iter - codeword=cw(colorder+1) - decoded=codeword(M+1:N) - return - endif - - if( iter.gt.0 ) then ! this code block implements an early stopping criterion - nd=ncheck-nclast - if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased - ncnt=0 ! reset counter - else - ncnt=ncnt+1 - endif -! write(*,*) iter,ncheck,nd,ncnt - if( ncnt .ge. 3 .and. iter .ge. 5 .and. ncheck .gt. 10) then - niterations=-1 - return - endif - endif - nclast=ncheck - -! Send messages from bits to check nodes - do j=1,M - do i=1,nrw - ibj=Nm(i,j) - toc(i,j)=zn(ibj) - do kk=1,ncw ! subtract off what the bit had received from the check - if( Mn(kk,ibj) .eq. j ) then ! Mn(3,128) - toc(i,j)=toc(i,j)-tov(kk,ibj) - endif - enddo - enddo - enddo - -! send messages from check nodes to variable nodes - do i=1,M - tanhtoc(1:nrw,i)=tanh(-toc(1:nrw,i)/2) - enddo - - do j=1,N - do i=1,ncw - ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j - Tmn=product(tanhtoc(:,ichk),mask=Nm(:,ichk).ne.j) - call platanh(-Tmn,y) - tov(i,j)=2*y - enddo - enddo - -enddo -niterations=-1 -end subroutine bpdecode144 +subroutine pltanh(x,y) + isign=+1 + z=x + if( x.lt.0 ) then + isign=-1 + z=abs(x) + endif + if( z.le. 0.8 ) then + y=0.83*x + return + elseif( z.le. 1.6 ) then + y=isign*(0.322*z+0.4064) + return + elseif( z.le. 3.0 ) then + y=isign*(0.0524*z+0.8378) + return + elseif( z.lt. 7.0 ) then + y=isign*(0.0012*z+0.9914) + return + else + y=isign*0.9998 + return + endif +end subroutine pltanh + +subroutine platanh(x,y) + isign=+1 + z=x + if( x.lt.0 ) then + isign=-1 + z=abs(x) + endif + if( z.le. 0.664 ) then + y=x/0.83 + return + elseif( z.le. 0.9217 ) then + y=isign*(z-0.4064)/0.322 + return + elseif( z.le. 0.9951 ) then + y=isign*(z-0.8378)/0.0524 + return + elseif( z.le. 0.9998 ) then + y=isign*(z-0.9914)/0.0012 + return + else + y=isign*7.0 + return + endif +end subroutine platanh + +subroutine bpdecode144(llr,maxiterations,decoded,niterations) +! +! A log-domain belief propagation decoder for the msk144 code. +! The code is a regular (128,80) code with column weight 3 and row weight 8. +! k9an August, 2016 +! +integer, parameter:: N=128, K=80, M=N-K +integer*1 codeword(N),cw(N) +integer*1 colorder(N) +integer*1 decoded(K) +integer Nm(8,M) ! 8 bits per check +integer Mn(3,N) ! 3 checks per bit +integer synd(M) +real tov(3,N) ! single precision seems to be adequate in log-domain +real toc(8,M) +real tanhtoc(8,M) +real zn(N) +real llr(N) +real Tmn + +data colorder/0,1,2,3,4,5,6,7,8,9, & + 10,11,12,13,14,15,24,26,29,30, & + 32,43,44,47,60,77,79,97,101,111, & + 96,38,64,53,93,34,59,94,74,90, & + 108,123,85,57,70,25,69,62,48,49, & + 50,51,52,33,54,55,56,21,58,36, & + 16,61,23,63,20,65,66,67,68,46, & + 22,71,72,73,31,75,76,45,78,17, & + 80,81,82,83,84,42,86,87,88,89, & + 39,91,92,35,37,95,19,27,98,99, & + 100,28,102,103,104,105,106,107,40,109, & + 110,18,112,113,114,115,116,117,118,119, & + 120,121,122,41,124,125,126,127/ + +data Mn/ & + 1, 14, 38, & + 2, 4, 41, & + 3, 19, 39, & + 5, 29, 34, & + 6, 35, 40, & + 7, 20, 45, & + 8, 28, 48, & + 9, 22, 25, & + 10, 24, 36, & + 11, 12, 37, & + 13, 43, 44, & + 15, 18, 46, & + 16, 17, 47, & + 21, 32, 33, & + 23, 30, 31, & + 26, 27, 42, & + 1, 12, 46, & + 2, 36, 38, & + 3, 5, 10, & + 4, 9, 23, & + 6, 13, 39, & + 7, 15, 17, & + 8, 18, 27, & + 11, 33, 40, & + 14, 28, 44, & + 16, 29, 31, & + 19, 20, 22, & + 21, 30, 42, & + 24, 26, 47, & + 25, 37, 48, & + 32, 34, 45, & + 8, 35, 41, & + 12, 31, 43, & + 1, 19, 21, & + 2, 43, 45, & + 3, 4, 11, & + 5, 18, 33, & + 6, 25, 47, & + 7, 28, 30, & + 9, 14, 34, & + 10, 35, 42, & + 13, 15, 22, & + 16, 37, 38, & + 17, 41, 44, & + 20, 24, 29, & + 18, 23, 39, & + 12, 26, 32, & + 27, 38, 40, & + 15, 36, 48, & + 2, 30, 46, & + 1, 4, 13, & + 3, 28, 32, & + 5, 43, 47, & + 6, 34, 46, & + 7, 9, 40, & + 8, 11, 45, & + 10, 17, 23, & + 14, 31, 35, & + 16, 22, 42, & + 19, 37, 44, & + 20, 33, 48, & + 21, 24, 41, & + 25, 27, 29, & + 26, 39, 48, & + 19, 31, 36, & + 1, 5, 7, & + 2, 29, 39, & + 3, 16, 46, & + 4, 26, 37, & + 6, 28, 45, & + 8, 22, 33, & + 9, 21, 43, & + 10, 25, 38, & + 11, 14, 24, & + 12, 17, 40, & + 13, 27, 30, & + 15, 32, 35, & + 18, 44, 47, & + 20, 23, 36, & + 34, 41, 42, & + 1, 32, 48, & + 2, 3, 33, & + 4, 29, 42, & + 5, 14, 37, & + 6, 7, 36, & + 8, 9, 39, & + 10, 13, 19, & + 11, 18, 30, & + 12, 16, 20, & + 15, 29, 44, & + 17, 34, 38, & + 6, 21, 22, & + 23, 32, 40, & + 24, 27, 46, & + 25, 41, 45, & + 7, 26, 43, & + 28, 31, 47, & + 20, 35, 38, & + 1, 33, 41, & + 2, 42, 44, & + 3, 23, 48, & + 4, 31, 45, & + 5, 8, 30, & + 9, 16, 36, & + 10, 40, 47, & + 11, 17, 46, & + 12, 21, 34, & + 13, 24, 28, & + 14, 18, 43, & + 15, 25, 26, & + 19, 27, 35, & + 22, 37, 39, & + 1, 16, 18, & + 2, 6, 20, & + 3, 30, 43, & + 4, 28, 33, & + 5, 22, 23, & + 7, 39, 42, & + 8, 12, 38, & + 9, 35, 46, & + 10, 27, 32, & + 11, 15, 34, & + 13, 36, 37, & + 14, 41, 47, & + 17, 21, 25, & + 19, 29, 45, & + 24, 31, 48, & + 26, 40, 44/ + +data Nm/ & + 1, 17, 34, 51, 66, 81, 99, 113, & + 2, 18, 35, 50, 67, 82, 100, 114, & + 3, 19, 36, 52, 68, 82, 101, 115, & + 2, 20, 36, 51, 69, 83, 102, 116, & + 4, 19, 37, 53, 66, 84, 103, 117, & + 5, 21, 38, 54, 70, 85, 92, 114, & + 6, 22, 39, 55, 66, 85, 96, 118, & + 7, 23, 32, 56, 71, 86, 103, 119, & + 8, 20, 40, 55, 72, 86, 104, 120, & + 9, 19, 41, 57, 73, 87, 105, 121, & + 10, 24, 36, 56, 74, 88, 106, 122, & + 10, 17, 33, 47, 75, 89, 107, 119, & + 11, 21, 42, 51, 76, 87, 108, 123, & + 1, 25, 40, 58, 74, 84, 109, 124, & + 12, 22, 42, 49, 77, 90, 110, 122, & + 13, 26, 43, 59, 68, 89, 104, 113, & + 13, 22, 44, 57, 75, 91, 106, 125, & + 12, 23, 37, 46, 78, 88, 109, 113, & + 3, 27, 34, 60, 65, 87, 111, 126, & + 6, 27, 45, 61, 79, 89, 98, 114, & + 14, 28, 34, 62, 72, 92, 107, 125, & + 8, 27, 42, 59, 71, 92, 112, 117, & + 15, 20, 46, 57, 79, 93, 101, 117, & + 9, 29, 45, 62, 74, 94, 108, 127, & + 8, 30, 38, 63, 73, 95, 110, 125, & + 16, 29, 47, 64, 69, 96, 110, 128, & + 16, 23, 48, 63, 76, 94, 111, 121, & + 7, 25, 39, 52, 70, 97, 108, 116, & + 4, 26, 45, 63, 67, 83, 90, 126, & + 15, 28, 39, 50, 76, 88, 103, 115, & + 15, 26, 33, 58, 65, 97, 102, 127, & + 14, 31, 47, 52, 77, 81, 93, 121, & + 14, 24, 37, 61, 71, 82, 99, 116, & + 4, 31, 40, 54, 80, 91, 107, 122, & + 5, 32, 41, 58, 77, 98, 111, 120, & + 9, 18, 49, 65, 79, 85, 104, 123, & + 10, 30, 43, 60, 69, 84, 112, 123, & + 1, 18, 43, 48, 73, 91, 98, 119, & + 3, 21, 46, 64, 67, 86, 112, 118, & + 5, 24, 48, 55, 75, 93, 105, 128, & + 2, 32, 44, 62, 80, 95, 99, 124, & + 16, 28, 41, 59, 80, 83, 100, 118, & + 11, 33, 35, 53, 72, 96, 109, 115, & + 11, 25, 44, 60, 78, 90, 100, 128, & + 6, 31, 35, 56, 70, 95, 102, 126, & + 12, 17, 50, 54, 68, 94, 106, 120, & + 13, 29, 38, 53, 78, 97, 105, 124, & + 7, 30, 49, 61, 64, 81, 101, 127/ + +nrw=8 +ncw=3 + +toc=0 +tov=0 +tanhtoc=0 + +! initial messages to checks +do j=1,M + do i=1,nrw + toc(i,j)=llr((Nm(i,j))) + enddo +enddo + +ncnt=0 + +do iter=0,maxiterations + +! Update bit log likelihood ratios + do i=1,N + zn(i)=llr(i)+sum(tov(1:ncw,i)) + enddo + +! Check to see if we have a codeword + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(:,i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 + enddo + + if( ncheck .eq. 0 ) then ! we have a codeword + niterations=iter + codeword=cw(colorder+1) + decoded=codeword(M+1:N) + return + endif + + if( iter.gt.0 ) then ! this code block implements an early stopping criterion + nd=ncheck-nclast + if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased + ncnt=0 ! reset counter + else + ncnt=ncnt+1 + endif +! write(*,*) iter,ncheck,nd,ncnt + if( ncnt .ge. 3 .and. iter .ge. 5 .and. ncheck .gt. 10) then + niterations=-1 + return + endif + endif + nclast=ncheck + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,ncw ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then ! Mn(3,128) + toc(i,j)=toc(i,j)-tov(kk,ibj) + endif + enddo + enddo + enddo + +! send messages from check nodes to variable nodes + do i=1,M + tanhtoc(1:nrw,i)=tanh(-toc(1:nrw,i)/2) + enddo + + do j=1,N + do i=1,ncw + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(:,ichk),mask=Nm(:,ichk).ne.j) + call platanh(-Tmn,y) + tov(i,j)=2*y + enddo + enddo + +enddo +niterations=-1 +end subroutine bpdecode144 diff --git a/lib/bpdecode40.f90 b/lib/bpdecode40.f90 index 3a52ed49..3a35bab4 100755 --- a/lib/bpdecode40.f90 +++ b/lib/bpdecode40.f90 @@ -1,148 +1,148 @@ -subroutine bpdecode40(llr,maxiterations,decoded,niterations) -! -! A log-domain belief propagation decoder for the msk40 code. -! The code is a regular (32,16) code with column weight 3, row weights 5,6,7. -! k9an August, 2016 -! -integer, parameter:: N=32, K=16, M=N-K -integer*1 codeword(N),cw(N) -integer*1 colorder(N) -integer*1 decoded(K) -integer Nm(7,M) ! 5,6 or 7 bits per check -integer Mn(3,N) ! 3 checks per bit -integer synd(M) -real tov(3,N) -real toc(7,M) -real tanhtoc(7,M) -real zn(N) -real llr(N) -real Tmn -integer nrw(M) - -data colorder/ & - 4, 1, 2, 3, 0, 8, 6, 10, & - 13, 28, 20, 23, 17, 15, 27, 25, & - 16, 12, 18, 19, 7, 21, 22, 11, & - 24, 5, 26, 14, 9, 29, 30, 31/ - -data Mn/ & - 1, 6, 13, & - 2, 3, 14, & - 4, 8, 15, & - 5, 11, 12, & - 7, 10, 16, & - 6, 9, 15, & - 1, 11, 16, & - 2, 4, 5, & - 3, 7, 9, & - 8, 10, 12, & - 8, 13, 14, & - 1, 4, 12, & - 2, 6, 10, & - 3, 11, 15, & - 5, 9, 14, & - 7, 13, 15, & - 12, 14, 16, & - 1, 2, 8, & - 3, 5, 6, & - 4, 9, 11, & - 1, 7, 14, & - 5, 10, 13, & - 3, 4, 16, & - 2, 15, 16, & - 6, 7, 12, & - 7, 8, 11, & - 1, 9, 10, & - 2, 11, 13, & - 3, 12, 13, & - 4, 6, 14, & - 1, 5, 15, & - 8, 9, 16/ - -data Nm/ & -1, 7, 12, 18, 21, 27, 31, & -2, 8, 13, 18, 24, 28, 0, & -2, 9, 14, 19, 23, 29, 0, & -3, 8, 12, 20, 23, 30, 0, & -4, 8, 15, 19, 22, 31, 0, & -1, 6, 13, 19, 25, 30, 0, & -5, 9, 16, 21, 25, 26, 0, & -3, 10, 11, 18, 26, 32, 0, & -6, 9, 15, 20, 27, 32, 0,& -5, 10, 13, 22, 27, 0, 0, & -4, 7, 14, 20, 26, 28, 0, & -4, 10, 12, 17, 25, 29, 0, & -1, 11, 16, 22, 28, 29, 0, & -2, 11, 15, 17, 21, 30, 0, & -3, 6, 14, 16, 24, 31, 0, & -5, 7, 17, 23, 24, 32, 0/ - -data nrw/7,6,6,6,6,6,6,6,6,5,6,6,6,6,6,6/ - -ncw=3 - -toc=0 -tov=0 -tanhtoc=0 - -! initialize messages to checks -do j=1,M - do i=1,nrw(j) - toc(i,j)=llr((Nm(i,j))) - enddo -enddo - -do iter=0,maxiterations - -! Update bit log likelihood ratios (tov=0 in iteration 0). - do i=1,N - zn(i)=llr(i)+sum(tov(1:ncw,i)) - enddo - -! Check to see if we have a codeword (check before we do any iteration). - cw=0 - where( zn .gt. 0. ) cw=1 - ncheck=0 - do i=1,M - synd(i)=sum(cw(Nm(1:nrw(i),i))) - if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 - enddo - - if( ncheck .eq. 0 ) then ! we have a codeword - reorder the columns and return it - niterations=iter - codeword=cw(colorder+1) - decoded=codeword(M+1:N) - return - endif - -! Send messages from bits to check nodes - do j=1,M - do i=1,nrw(j) - ibj=Nm(i,j) - toc(i,j)=zn(ibj) - do kk=1,ncw ! subtract off what the bit had received from the check - if( Mn(kk,ibj) .eq. j ) then - toc(i,j)=toc(i,j)-tov(kk,ibj) - endif - enddo - enddo - enddo - -! send messages from check nodes to variable nodes - do i=1,M - tanhtoc(1:7,i)=tanh(-toc(1:7,i)/2) - enddo - - do j=1,N - do i=1,ncw - ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j - Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) - call platanh(-Tmn,y) - tov(i,j)=2*y - enddo - enddo - -enddo -niterations=-1 -return -end subroutine bpdecode40 +subroutine bpdecode40(llr,maxiterations,decoded,niterations) +! +! A log-domain belief propagation decoder for the msk40 code. +! The code is a regular (32,16) code with column weight 3, row weights 5,6,7. +! k9an August, 2016 +! +integer, parameter:: N=32, K=16, M=N-K +integer*1 codeword(N),cw(N) +integer*1 colorder(N) +integer*1 decoded(K) +integer Nm(7,M) ! 5,6 or 7 bits per check +integer Mn(3,N) ! 3 checks per bit +integer synd(M) +real tov(3,N) +real toc(7,M) +real tanhtoc(7,M) +real zn(N) +real llr(N) +real Tmn +integer nrw(M) + +data colorder/ & + 4, 1, 2, 3, 0, 8, 6, 10, & + 13, 28, 20, 23, 17, 15, 27, 25, & + 16, 12, 18, 19, 7, 21, 22, 11, & + 24, 5, 26, 14, 9, 29, 30, 31/ + +data Mn/ & + 1, 6, 13, & + 2, 3, 14, & + 4, 8, 15, & + 5, 11, 12, & + 7, 10, 16, & + 6, 9, 15, & + 1, 11, 16, & + 2, 4, 5, & + 3, 7, 9, & + 8, 10, 12, & + 8, 13, 14, & + 1, 4, 12, & + 2, 6, 10, & + 3, 11, 15, & + 5, 9, 14, & + 7, 13, 15, & + 12, 14, 16, & + 1, 2, 8, & + 3, 5, 6, & + 4, 9, 11, & + 1, 7, 14, & + 5, 10, 13, & + 3, 4, 16, & + 2, 15, 16, & + 6, 7, 12, & + 7, 8, 11, & + 1, 9, 10, & + 2, 11, 13, & + 3, 12, 13, & + 4, 6, 14, & + 1, 5, 15, & + 8, 9, 16/ + +data Nm/ & +1, 7, 12, 18, 21, 27, 31, & +2, 8, 13, 18, 24, 28, 0, & +2, 9, 14, 19, 23, 29, 0, & +3, 8, 12, 20, 23, 30, 0, & +4, 8, 15, 19, 22, 31, 0, & +1, 6, 13, 19, 25, 30, 0, & +5, 9, 16, 21, 25, 26, 0, & +3, 10, 11, 18, 26, 32, 0, & +6, 9, 15, 20, 27, 32, 0,& +5, 10, 13, 22, 27, 0, 0, & +4, 7, 14, 20, 26, 28, 0, & +4, 10, 12, 17, 25, 29, 0, & +1, 11, 16, 22, 28, 29, 0, & +2, 11, 15, 17, 21, 30, 0, & +3, 6, 14, 16, 24, 31, 0, & +5, 7, 17, 23, 24, 32, 0/ + +data nrw/7,6,6,6,6,6,6,6,6,5,6,6,6,6,6,6/ + +ncw=3 + +toc=0 +tov=0 +tanhtoc=0 + +! initialize messages to checks +do j=1,M + do i=1,nrw(j) + toc(i,j)=llr((Nm(i,j))) + enddo +enddo + +do iter=0,maxiterations + +! Update bit log likelihood ratios (tov=0 in iteration 0). + do i=1,N + zn(i)=llr(i)+sum(tov(1:ncw,i)) + enddo + +! Check to see if we have a codeword (check before we do any iteration). + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(1:nrw(i),i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 + enddo + + if( ncheck .eq. 0 ) then ! we have a codeword - reorder the columns and return it + niterations=iter + codeword=cw(colorder+1) + decoded=codeword(M+1:N) + return + endif + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw(j) + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,ncw ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then + toc(i,j)=toc(i,j)-tov(kk,ibj) + endif + enddo + enddo + enddo + +! send messages from check nodes to variable nodes + do i=1,M + tanhtoc(1:7,i)=tanh(-toc(1:7,i)/2) + enddo + + do j=1,N + do i=1,ncw + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) + call platanh(-Tmn,y) + tov(i,j)=2*y + enddo + enddo + +enddo +niterations=-1 +return +end subroutine bpdecode40 diff --git a/lib/cablog.f90 b/lib/cablog.f90 index 08fecbad..d1964502 100755 --- a/lib/cablog.f90 +++ b/lib/cablog.f90 @@ -1,142 +1,142 @@ -program cablog - - character*100 line,infile,outfile - character cband*4,cmode*2,cdate*10,cutc*4,callsign*10,mycall*10 - character csent*4,crcvd*4,dsent*4,drcvd*4,g1*4 - character*3 cmo(12) - integer icomma(20) - logical map65 - logical isgrid,gridx - data cmo/'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep', & - 'Oct','Nov','Dec'/ - - isgrid(g1)=g1(1:1).ge.'A' .and. g1(1:1).le.'R' .and. g1(2:2).ge.'A' .and. & - g1(2:2).le.'R' .and. g1(3:3).ge.'0' .and. g1(3:3).le.'9' .and. & - g1(4:4).ge.'0' .and. g1(4:4).le.'9' .and. g1(1:4).ne.'RR73' - - nargs=iargc() - if(nargs.ne.4) then - print*,"Program cablog converts file 'wsjtx.log' written by WSJT-X" - print*,"(or wsjt.log written by MAP65) to a bare-bones Cabrillo" - print*,"log for the ARRL International EME Contest. You will" - print*,"certainly need to edit the header information, and you may" - print*,"edit the log elsewhere as required." - print*,' ' - print*,'Usage: cablog ' - print*,'Examples: cablog W2ZQ -15 -16 wsjtx.log' - print*,' cablog W2ZQ O O wsjt.log' - go to 999 - endif - call getarg(1,mycall) - outfile=trim(mycall)//'.log' - call getarg(2,dsent) - gridx=isgrid(dsent) - call getarg(3,drcvd) - call getarg(4,infile) - open(10,file=trim(infile),status='old') - open(12,file=trim(outfile),status='unknown') - - write(12,1000) -1000 format('START-OF-LOG: 3.0'/ & - 'CONTEST: ARRL-EME'/ & - 'CALLSIGN: '/ & - 'CATEGORY-OPERATOR: '/ & - 'CATEGORY-BAND: '/ & - 'CATEGORY-MODE: '/ & - 'EMAIL: '/ & - 'OPERATORS: '/ & - 'CATEGORY-POWER: HIGH'/ & - 'CATEGORY-TRANSMITTER: ONE'/ & - 'CATEGORY-STATION: FIXED'/ & - 'CATEGORY-TIME: 24-HOURS'/ & - 'CATEGORY-ASSISTED: ASSISTED'/ & - 'LOCATION: SNJ'/ & - 'CLAIMED-SCORE: '/ & - 'CLUB: '/ & - 'NAME: '/ & - 'ADDRESS: '/ & - 'ADDRESS: '/ & - 'ADDRESS: '/ & - 'CREATED-BY: cablog (C) K1JT') - - n=0 - map65=.false. - - do nn=1,9999 - read(10,'(a100)',end=900) line - if(len(trim(line)).eq.0) cycle - if(line(6:6).ge.'A' .and. line(6:6).le.'Z') map65=.true. - n=n+1 - k=0 - do j=1,100 - if(line(j:j).eq.',') then - k=k+1 - icomma(k)=j - endif - enddo - cmode='DG' - if(index(line,',CW,').gt.10) cmode='CW' - - if(map65) then - do i=1,12 - if(cmo(i).eq.line(6:8)) write(cdate(6:7),'(i2.2)') i - enddo - cdate(1:5)=line(1:5) - cdate(8:10)=line(9:11) - cutc=line(13:14)//line(16:17) - i0=index(line(19:),',') - callsign=line(19:17+i0) - cband='144 ' - csent=dsent - crcvd=drcvd - else - cdate=line(1:10) - cutc=line(32:33)//line(35:36) - i0=index(line(41:),',') - callsign=line(41:39+i0) - read(line(icomma(6)+1:icomma(7)-1),*,err=10,end=10) freq - go to 20 -10 print*,'***Error at line ',n - print*,trim(line) -20 if(freq.ge.50.0 .and. freq.le.54.0) cband='50 ' - if(freq.ge.144.0 .and. freq.le.148.0) cband='144 ' - if(freq.ge.28.0 .and. freq.le.29.0) cband='144 ' - if(freq.ge.222.0 .and. freq.le.225.0) cband='222 ' - if(freq.ge.420.0 .and. freq.le.450.0) cband='432 ' - if(freq.ge.902.0 .and. freq.le.928.0) cband='902 ' - if(freq.ge.1240.0 .and. freq.le.1300.0) cband='1.2G' - if(freq.ge.2300.0 .and. freq.le.2450.0) cband='2.3G' - if(freq.ge.3300.0 .and. freq.le.3500.0) cband='3.4G' - if(freq.ge.5650.0 .and. freq.le.5925.0) cband='5.7G' - if(freq.ge.10000.0 .and. freq.le.10500.0) cband='10G ' - if(freq.ge.24000.0 .and. freq.le.24250.0) cband='24G ' - if(icomma(8).eq.icomma(9)-1) then - csent=dsent - else - csent=line(icomma(8)+1:icomma(9)-1) - endif - if(icomma(9).eq.icomma(10)-1) then - crcvd=drcvd - else - crcvd=line(icomma(9)+1:icomma(10)-1) - endif - endif - if(gridx) then - csent=dsent - crcvd=line(icomma(5)+1:icomma(6)-1) - endif - - write(12,1030) cband,cmode,cdate,cutc,mycall,csent,callsign,crcvd -1030 format('QSO: ',a4,1x,a2,1x,a10,1x,a4,1x,a6,1x,a4,4x,a10,1x,a4) - enddo - -900 write(12,1900) -1900 format('END-OF-LOG:') - write(*,1910) n,trim(outfile) -1910 format('Processed',i5,' QSOs.'/'Output file: ',a) - -999 end program cablog - -!2023-10-28,00:17:00,2023-10-28,00:21:00,G7TZZ,IO92,1296.083100,Q65,-17,-17,,,, -!2023-Nov-30,20:31,W8WN,EM77,0,Q65A - +program cablog + + character*100 line,infile,outfile + character cband*4,cmode*2,cdate*10,cutc*4,callsign*10,mycall*10 + character csent*4,crcvd*4,dsent*4,drcvd*4,g1*4 + character*3 cmo(12) + integer icomma(20) + logical map65 + logical isgrid,gridx + data cmo/'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep', & + 'Oct','Nov','Dec'/ + + isgrid(g1)=g1(1:1).ge.'A' .and. g1(1:1).le.'R' .and. g1(2:2).ge.'A' .and. & + g1(2:2).le.'R' .and. g1(3:3).ge.'0' .and. g1(3:3).le.'9' .and. & + g1(4:4).ge.'0' .and. g1(4:4).le.'9' .and. g1(1:4).ne.'RR73' + + nargs=iargc() + if(nargs.ne.4) then + print*,"Program cablog converts file 'wsjtx.log' written by WSJT-X" + print*,"(or wsjt.log written by MAP65) to a bare-bones Cabrillo" + print*,"log for the ARRL International EME Contest. You will" + print*,"certainly need to edit the header information, and you may" + print*,"edit the log elsewhere as required." + print*,' ' + print*,'Usage: cablog ' + print*,'Examples: cablog W2ZQ -15 -16 wsjtx.log' + print*,' cablog W2ZQ O O wsjt.log' + go to 999 + endif + call getarg(1,mycall) + outfile=trim(mycall)//'.log' + call getarg(2,dsent) + gridx=isgrid(dsent) + call getarg(3,drcvd) + call getarg(4,infile) + open(10,file=trim(infile),status='old') + open(12,file=trim(outfile),status='unknown') + + write(12,1000) +1000 format('START-OF-LOG: 3.0'/ & + 'CONTEST: ARRL-EME'/ & + 'CALLSIGN: '/ & + 'CATEGORY-OPERATOR: '/ & + 'CATEGORY-BAND: '/ & + 'CATEGORY-MODE: '/ & + 'EMAIL: '/ & + 'OPERATORS: '/ & + 'CATEGORY-POWER: HIGH'/ & + 'CATEGORY-TRANSMITTER: ONE'/ & + 'CATEGORY-STATION: FIXED'/ & + 'CATEGORY-TIME: 24-HOURS'/ & + 'CATEGORY-ASSISTED: ASSISTED'/ & + 'LOCATION: SNJ'/ & + 'CLAIMED-SCORE: '/ & + 'CLUB: '/ & + 'NAME: '/ & + 'ADDRESS: '/ & + 'ADDRESS: '/ & + 'ADDRESS: '/ & + 'CREATED-BY: cablog (C) K1JT') + + n=0 + map65=.false. + + do nn=1,9999 + read(10,'(a100)',end=900) line + if(len(trim(line)).eq.0) cycle + if(line(6:6).ge.'A' .and. line(6:6).le.'Z') map65=.true. + n=n+1 + k=0 + do j=1,100 + if(line(j:j).eq.',') then + k=k+1 + icomma(k)=j + endif + enddo + cmode='DG' + if(index(line,',CW,').gt.10) cmode='CW' + + if(map65) then + do i=1,12 + if(cmo(i).eq.line(6:8)) write(cdate(6:7),'(i2.2)') i + enddo + cdate(1:5)=line(1:5) + cdate(8:10)=line(9:11) + cutc=line(13:14)//line(16:17) + i0=index(line(19:),',') + callsign=line(19:17+i0) + cband='144 ' + csent=dsent + crcvd=drcvd + else + cdate=line(1:10) + cutc=line(32:33)//line(35:36) + i0=index(line(41:),',') + callsign=line(41:39+i0) + read(line(icomma(6)+1:icomma(7)-1),*,err=10,end=10) freq + go to 20 +10 print*,'***Error at line ',n + print*,trim(line) +20 if(freq.ge.50.0 .and. freq.le.54.0) cband='50 ' + if(freq.ge.144.0 .and. freq.le.148.0) cband='144 ' + if(freq.ge.28.0 .and. freq.le.29.0) cband='144 ' + if(freq.ge.222.0 .and. freq.le.225.0) cband='222 ' + if(freq.ge.420.0 .and. freq.le.450.0) cband='432 ' + if(freq.ge.902.0 .and. freq.le.928.0) cband='902 ' + if(freq.ge.1240.0 .and. freq.le.1300.0) cband='1.2G' + if(freq.ge.2300.0 .and. freq.le.2450.0) cband='2.3G' + if(freq.ge.3300.0 .and. freq.le.3500.0) cband='3.4G' + if(freq.ge.5650.0 .and. freq.le.5925.0) cband='5.7G' + if(freq.ge.10000.0 .and. freq.le.10500.0) cband='10G ' + if(freq.ge.24000.0 .and. freq.le.24250.0) cband='24G ' + if(icomma(8).eq.icomma(9)-1) then + csent=dsent + else + csent=line(icomma(8)+1:icomma(9)-1) + endif + if(icomma(9).eq.icomma(10)-1) then + crcvd=drcvd + else + crcvd=line(icomma(9)+1:icomma(10)-1) + endif + endif + if(gridx) then + csent=dsent + crcvd=line(icomma(5)+1:icomma(6)-1) + endif + + write(12,1030) cband,cmode,cdate,cutc,mycall,csent,callsign,crcvd +1030 format('QSO: ',a4,1x,a2,1x,a10,1x,a4,1x,a6,1x,a4,4x,a10,1x,a4) + enddo + +900 write(12,1900) +1900 format('END-OF-LOG:') + write(*,1910) n,trim(outfile) +1910 format('Processed',i5,' QSOs.'/'Output file: ',a) + +999 end program cablog + +!2023-10-28,00:17:00,2023-10-28,00:21:00,G7TZZ,IO92,1296.083100,Q65,-17,-17,,,, +!2023-Nov-30,20:31,W8WN,EM77,0,Q65A + diff --git a/lib/calibrate.f90 b/lib/calibrate.f90 index 9c53ba9d..76e70f2b 100755 --- a/lib/calibrate.f90 +++ b/lib/calibrate.f90 @@ -1,96 +1,96 @@ -subroutine calibrate(data_dir,iz,a,b,rms,sigmaa,sigmab,irc) - -! Average groups of frequency-calibration measurements, then fit a -! straight line for slope and intercept. - - parameter (NZ=1000) - implicit real*8 (a-h,o-z) - character*(*) data_dir - character*256 infile,outfile - character*8 cutc,cutc1 - character*1 c1 - real*8 fd(NZ),deltaf(NZ),r(NZ),rmsd(NZ) - integer nn(NZ) - - infile=trim(data_dir)//'/'//'fmt.all' - outfile=trim(data_dir)//'/'//'fcal2.out' - - open(10,file=trim(infile),status='old',err=996) - open(12,file=trim(outfile),status='unknown',err=997) - - nkhz0=0 - sum=0.d0 - sumsq=0.d0 - n=0 - j=0 - do i=1,99999 - read(10,*,end=10,err=995) cutc,nkHz,ncal,noffset,faudio,df,dblevel,snr - if((nkHz.ne.nkHz0) .and. i.ne.1) then - ave=sum/n - rms=0.d0 - if(n.gt.1) then - rms=sqrt(abs(sumsq - sum*sum/n)/(n-1.d0)) - endif - fMHz=0.001d0*nkHz0 - j=j+1 - fd(j)=fMHz - deltaf(j)=ave - r(j)=0.d0 - rmsd(j)=rms - nn(j)=n - sum=0.d0 - sumsq=0.d0 - n=0 - endif - dial_error=faudio-noffset - sum=sum + dial_error - sumsq=sumsq + dial_error**2 - n=n+1 - if(n.eq.1) then - cutc1=cutc - ncal0=ncal - endif - nkHz0=nkHz - enddo - -10 ave=sum/n - rms=0.d0 - if(n.gt.0) then - rms=sqrt((sumsq - sum*sum/n)/(n-1.d0)) - endif - fMHz=0.001d0*nkHz - j=j+1 - fd(j)=fMHz - deltaf(j)=ave - r(j)=0.d0 - rmsd(j)=rms - nn(j)=n - iz=j - if(iz.lt.2) go to 998 - - call fitcal(fd,deltaf,r,iz,a,b,sigmaa,sigmab,rms) - - write(12,1002) -1002 format(' Freq DF Meas Freq N rms Resid'/ & - ' (MHz) (Hz) (MHz) (Hz) (Hz)'/ & - '----------------------------------------------------') - irc=0 - do i=1,iz - fm=fd(i) + 1.d-6*deltaf(i) - c1=' ' - if(rmsd(i).gt.1.0d0) c1='*' - write(12,1012) fd(i),deltaf(i),fm,nn(i),rmsd(i),r(i),c1 -1012 format(f8.3,f9.3,f14.9,i4,f7.2,f9.3,1x,a1) - enddo - go to 999 - -995 irc=-4; iz=i; go to 999 -996 irc=-1; go to 999 -997 irc=-2; go to 999 -998 irc=-3 -999 continue - close(10) - close(12) - - return -end subroutine calibrate +subroutine calibrate(data_dir,iz,a,b,rms,sigmaa,sigmab,irc) + +! Average groups of frequency-calibration measurements, then fit a +! straight line for slope and intercept. + + parameter (NZ=1000) + implicit real*8 (a-h,o-z) + character*(*) data_dir + character*256 infile,outfile + character*8 cutc,cutc1 + character*1 c1 + real*8 fd(NZ),deltaf(NZ),r(NZ),rmsd(NZ) + integer nn(NZ) + + infile=trim(data_dir)//'/'//'fmt.all' + outfile=trim(data_dir)//'/'//'fcal2.out' + + open(10,file=trim(infile),status='old',err=996) + open(12,file=trim(outfile),status='unknown',err=997) + + nkhz0=0 + sum=0.d0 + sumsq=0.d0 + n=0 + j=0 + do i=1,99999 + read(10,*,end=10,err=995) cutc,nkHz,ncal,noffset,faudio,df,dblevel,snr + if((nkHz.ne.nkHz0) .and. i.ne.1) then + ave=sum/n + rms=0.d0 + if(n.gt.1) then + rms=sqrt(abs(sumsq - sum*sum/n)/(n-1.d0)) + endif + fMHz=0.001d0*nkHz0 + j=j+1 + fd(j)=fMHz + deltaf(j)=ave + r(j)=0.d0 + rmsd(j)=rms + nn(j)=n + sum=0.d0 + sumsq=0.d0 + n=0 + endif + dial_error=faudio-noffset + sum=sum + dial_error + sumsq=sumsq + dial_error**2 + n=n+1 + if(n.eq.1) then + cutc1=cutc + ncal0=ncal + endif + nkHz0=nkHz + enddo + +10 ave=sum/n + rms=0.d0 + if(n.gt.0) then + rms=sqrt((sumsq - sum*sum/n)/(n-1.d0)) + endif + fMHz=0.001d0*nkHz + j=j+1 + fd(j)=fMHz + deltaf(j)=ave + r(j)=0.d0 + rmsd(j)=rms + nn(j)=n + iz=j + if(iz.lt.2) go to 998 + + call fitcal(fd,deltaf,r,iz,a,b,sigmaa,sigmab,rms) + + write(12,1002) +1002 format(' Freq DF Meas Freq N rms Resid'/ & + ' (MHz) (Hz) (MHz) (Hz) (Hz)'/ & + '----------------------------------------------------') + irc=0 + do i=1,iz + fm=fd(i) + 1.d-6*deltaf(i) + c1=' ' + if(rmsd(i).gt.1.0d0) c1='*' + write(12,1012) fd(i),deltaf(i),fm,nn(i),rmsd(i),r(i),c1 +1012 format(f8.3,f9.3,f14.9,i4,f7.2,f9.3,1x,a1) + enddo + go to 999 + +995 irc=-4; iz=i; go to 999 +996 irc=-1; go to 999 +997 irc=-2; go to 999 +998 irc=-3 +999 continue + close(10) + close(12) + + return +end subroutine calibrate diff --git a/lib/char.h b/lib/char.h index 469dd862..cc477ec7 100755 --- a/lib/char.h +++ b/lib/char.h @@ -1,57 +1,57 @@ -/* Include file to configure the RS codec for character symbols - * - * Copyright 2002, Phil Karn, KA9Q - * May be used under the terms of the GNU General Public License (GPL) - */ -#define DTYPE unsigned char - -/* Reed-Solomon codec control block */ -struct rs { - int mm; /* Bits per symbol */ - int nn; /* Symbols per block (= (1<= rs->nn) { - x -= rs->nn; - x = (x >> rs->mm) + (x & rs->nn); - } - return x; -} -#define MODNN(x) modnn(rs,x) - -#define MM (rs->mm) -#define NN (rs->nn) -#define ALPHA_TO (rs->alpha_to) -#define INDEX_OF (rs->index_of) -#define GENPOLY (rs->genpoly) -#define NROOTS (rs->nroots) -#define FCR (rs->fcr) -#define PRIM (rs->prim) -#define IPRIM (rs->iprim) -#define PAD (rs->pad) -#define A0 (NN) - -#define ENCODE_RS encode_rs_char -#define DECODE_RS decode_rs_char -#define INIT_RS init_rs_char -#define FREE_RS free_rs_char - -void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity); -int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras); -void *INIT_RS(int symsize,int gfpoly,int fcr, - int prim,int nroots,int pad); -void FREE_RS(void *p); - - - - - +/* Include file to configure the RS codec for character symbols + * + * Copyright 2002, Phil Karn, KA9Q + * May be used under the terms of the GNU General Public License (GPL) + */ +#define DTYPE unsigned char + +/* Reed-Solomon codec control block */ +struct rs { + int mm; /* Bits per symbol */ + int nn; /* Symbols per block (= (1<= rs->nn) { + x -= rs->nn; + x = (x >> rs->mm) + (x & rs->nn); + } + return x; +} +#define MODNN(x) modnn(rs,x) + +#define MM (rs->mm) +#define NN (rs->nn) +#define ALPHA_TO (rs->alpha_to) +#define INDEX_OF (rs->index_of) +#define GENPOLY (rs->genpoly) +#define NROOTS (rs->nroots) +#define FCR (rs->fcr) +#define PRIM (rs->prim) +#define IPRIM (rs->iprim) +#define PAD (rs->pad) +#define A0 (NN) + +#define ENCODE_RS encode_rs_char +#define DECODE_RS decode_rs_char +#define INIT_RS init_rs_char +#define FREE_RS free_rs_char + +void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity); +int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras); +void *INIT_RS(int symsize,int gfpoly,int fcr, + int prim,int nroots,int pad); +void FREE_RS(void *p); + + + + + diff --git a/lib/chkfft2.f90 b/lib/chkfft2.f90 index 3cc8989c..298f3db6 100755 --- a/lib/chkfft2.f90 +++ b/lib/chkfft2.f90 @@ -1,187 +1,187 @@ -program chkfft - -! Tests and times one-dimensional FFTs computed by FFTW3 - use FFTW3 - parameter (NMAX=8*1024*1024) !Maximum FFT length - complex a(NMAX),b(NMAX),c(NMAX) - real ar(NMAX),br(NMAX),cr(NMAX) - real mflops - integer*8 plan1,plan2 !Pointers to stored plans - character infile*12,arg*8 - logical list - common/patience/npatience - equivalence (a,ar),(b,br),(c,cr) -! include 'fftw3.f90' !FFTW definitions - - nargs=iargc() - if(nargs.ne.6) then - print*,'Usage: chkfft nr nw nc np inplace' - print*,' nfft: length of FFT' - print*,' nfft=0: do lengths 2^n, n=2^4 to 2^23' - print*,' infile: name of file with nfft values, one per line' - print*,' nr: 0/1 to not read (or read) wisdom' - print*,' nw: 0/1 to not write (or write) wisdom' - print*,' nc: 0/1 for real or complex data' - print*,' np: 0-4 patience for finding best algorithm' - print*,' inplace: 1 for inplace, 0 otherwise' - go to 999 - endif - - list=.false. - nfft=-1 - call getarg(1,infile) - open(10,file=infile,status='old',err=1) - list=.true. !A valid file name was provided - go to 2 -1 read(infile,*) nfft !Take first argument to be nfft -2 call getarg(2,arg) - read(arg,*) nr - call getarg(3,arg) - read(arg,*) nw - call getarg(4,arg) - read(arg,*) ncomplex - call getarg(5,arg) - read(arg,*) npatience - call getarg(6,arg) - read(arg,*) inplace - - if(list) write(*,1000) infile,nr,nw,ncomplex,npatience -1000 format(/'infile: ',a12,' nr:',i2,' nw',i2,' nc:',i2,' np:',i2/) - if(.not.list) write(*,1002) nfft,nr,nw,ncomplex,npatience -1002 format(/'nfft: ',i10,' nr:',i2,' nw',i2,' nc:',i2,' np:',i2/) - - 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 - - open(12,file='chkfft.out',status='unknown') - open(13,file='fftwf_wisdom.dat',status='unknown') - - if(nr.ne.0) then - call import_wisdom_from_file(isuccess,13) - if(isuccess.eq.0) then - write(*,1010) -1010 format('Failed to import FFTW wisdom.') - go to 999 - endif - endif - - idum=-1 !Set random seed - ndim=1 !One-dimensional transforms - do i=1,NMAX !Set random data - x=gran() - y=gran() - b(i)=cmplx(x,y) !Generate random data - enddo - - iters=1000000 - if(list .or. (nfft.gt.0)) then - n1=1 - n2=1 - if(nfft.eq.-1) n2=999999 - write(*,1020) -1020 format(' NFFT Time rms MHz MFlops iters', & - ' tplan'/61('-')) - else - n1=4 - n2=23 - write(*,1030) -1030 format(' n N=2^n Time rms MHz MFlops iters', & - ' tplan'/63('-')) - endif - - do ii=n1,n2 !Test one or more FFT lengths - if(list) then - read(10,*,end=900) nfft !Read nfft from file - else if(n2.gt.n1) then - nfft=2**ii !Do powers of 2 - endif - - iformf=1 - iformb=1 - if(ncomplex.eq.0) then - iformf=0 !Real-to-complex transform - iformb=-1 !Complex-to-real (inverse) transform - endif - - if(nfft.gt.NMAX) go to 900 - a(1:nfft)=b(1:nfft) !Copy test data into a() - t0=second() - if(inplace.ne.0) then - if(ncomplex.ne.0) then - call sfftw_plan_dft_1d(plan1,nfft,a,a,FFTW_FORWARD,nflags) - call sfftw_plan_dft_1d(plan2,nfft,a,a,FFTW_BACKWARD,nflags) - else - call sfftw_plan_dft_r2c_1d(plan1,nfft,a,a,nflags) - call sfftw_plan_dft_c2r_1d(plan2,nfft,a,a,nflags) - endif - else - if(ncomplex.ne.0) then - call sfftw_plan_dft_1d(plan1,nfft,a,c,FFTW_FORWARD,nflags) - call sfftw_plan_dft_1d(plan2,nfft,c,a,FFTW_BACKWARD,nflags) - else - call sfftw_plan_dft_r2c_1d(plan1,nfft,a,c,nflags) - call sfftw_plan_dft_c2r_1d(plan2,nfft,c,a,nflags) - endif - endif - - t2=second() - tplan=t2-t0 !Total planning time for this length - - total=0. - do iter=1,iters !Now do many iterations - a(1:nfft)=b(1:nfft) !Copy test data into a() - t0=second() - call sfftw_execute(plan1) - call sfftw_execute(plan2) - t1=second() - total=total+t1-t0 - if(total.ge.1.0) go to 40 !Cut iterations short if t>1 s - enddo - iter=iters - -40 time=0.5*total/iter !Time for one FFT of current length - tplan=0.5*tplan-time !Planning time for one FFT - if(tplan.lt.0) tplan=0. - a(1:nfft)=a(1:nfft)/nfft - -! Compute RMS difference between original array and back-transformed array. - sq=0. - if(ncomplex.eq.1) then - do i=1,nfft - sq=sq + real(a(i)-b(i))**2 + imag(a(i)-b(i))**2 - enddo - else - do i=1,nfft - sq=sq + (ar(i)-br(i))**2 - enddo - endif - rms=sqrt(sq/nfft) - - freq=1.e-6*nfft/time - mflops=5.0/(1.e6*time/(nfft*log(float(nfft))/log(2.0))) - if(n2.eq.1 .or. n2.eq.999999) then - write(*,1050) nfft,time,rms,freq,mflops,iter,tplan - write(12,1050) nfft,time,rms,freq,mflops,iter,tplan -1050 format(i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1) - else - write(*,1060) ii,nfft,time,rms,freq,mflops,iter,tplan - write(12,1060) ii,nfft,time,rms,freq,mflops,iter,tplan -1060 format(i2,i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1) - endif - enddo - -900 continue - if(nw.eq.1) then - rewind 13 - call export_wisdom_to_file(13) -! write(*,1070) -!1070 format(/'Exported FFTW wisdom') - endif - - call sfftw_destroy_plan(plan1) - call sfftw_destroy_plan(plan2) - -999 end program chkfft +program chkfft + +! Tests and times one-dimensional FFTs computed by FFTW3 + use FFTW3 + parameter (NMAX=8*1024*1024) !Maximum FFT length + complex a(NMAX),b(NMAX),c(NMAX) + real ar(NMAX),br(NMAX),cr(NMAX) + real mflops + integer*8 plan1,plan2 !Pointers to stored plans + character infile*12,arg*8 + logical list + common/patience/npatience + equivalence (a,ar),(b,br),(c,cr) +! include 'fftw3.f90' !FFTW definitions + + nargs=iargc() + if(nargs.ne.6) then + print*,'Usage: chkfft nr nw nc np inplace' + print*,' nfft: length of FFT' + print*,' nfft=0: do lengths 2^n, n=2^4 to 2^23' + print*,' infile: name of file with nfft values, one per line' + print*,' nr: 0/1 to not read (or read) wisdom' + print*,' nw: 0/1 to not write (or write) wisdom' + print*,' nc: 0/1 for real or complex data' + print*,' np: 0-4 patience for finding best algorithm' + print*,' inplace: 1 for inplace, 0 otherwise' + go to 999 + endif + + list=.false. + nfft=-1 + call getarg(1,infile) + open(10,file=infile,status='old',err=1) + list=.true. !A valid file name was provided + go to 2 +1 read(infile,*) nfft !Take first argument to be nfft +2 call getarg(2,arg) + read(arg,*) nr + call getarg(3,arg) + read(arg,*) nw + call getarg(4,arg) + read(arg,*) ncomplex + call getarg(5,arg) + read(arg,*) npatience + call getarg(6,arg) + read(arg,*) inplace + + if(list) write(*,1000) infile,nr,nw,ncomplex,npatience +1000 format(/'infile: ',a12,' nr:',i2,' nw',i2,' nc:',i2,' np:',i2/) + if(.not.list) write(*,1002) nfft,nr,nw,ncomplex,npatience +1002 format(/'nfft: ',i10,' nr:',i2,' nw',i2,' nc:',i2,' np:',i2/) + + 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 + + open(12,file='chkfft.out',status='unknown') + open(13,file='fftwf_wisdom.dat',status='unknown') + + if(nr.ne.0) then + call import_wisdom_from_file(isuccess,13) + if(isuccess.eq.0) then + write(*,1010) +1010 format('Failed to import FFTW wisdom.') + go to 999 + endif + endif + + idum=-1 !Set random seed + ndim=1 !One-dimensional transforms + do i=1,NMAX !Set random data + x=gran() + y=gran() + b(i)=cmplx(x,y) !Generate random data + enddo + + iters=1000000 + if(list .or. (nfft.gt.0)) then + n1=1 + n2=1 + if(nfft.eq.-1) n2=999999 + write(*,1020) +1020 format(' NFFT Time rms MHz MFlops iters', & + ' tplan'/61('-')) + else + n1=4 + n2=23 + write(*,1030) +1030 format(' n N=2^n Time rms MHz MFlops iters', & + ' tplan'/63('-')) + endif + + do ii=n1,n2 !Test one or more FFT lengths + if(list) then + read(10,*,end=900) nfft !Read nfft from file + else if(n2.gt.n1) then + nfft=2**ii !Do powers of 2 + endif + + iformf=1 + iformb=1 + if(ncomplex.eq.0) then + iformf=0 !Real-to-complex transform + iformb=-1 !Complex-to-real (inverse) transform + endif + + if(nfft.gt.NMAX) go to 900 + a(1:nfft)=b(1:nfft) !Copy test data into a() + t0=second() + if(inplace.ne.0) then + if(ncomplex.ne.0) then + call sfftw_plan_dft_1d(plan1,nfft,a,a,FFTW_FORWARD,nflags) + call sfftw_plan_dft_1d(plan2,nfft,a,a,FFTW_BACKWARD,nflags) + else + call sfftw_plan_dft_r2c_1d(plan1,nfft,a,a,nflags) + call sfftw_plan_dft_c2r_1d(plan2,nfft,a,a,nflags) + endif + else + if(ncomplex.ne.0) then + call sfftw_plan_dft_1d(plan1,nfft,a,c,FFTW_FORWARD,nflags) + call sfftw_plan_dft_1d(plan2,nfft,c,a,FFTW_BACKWARD,nflags) + else + call sfftw_plan_dft_r2c_1d(plan1,nfft,a,c,nflags) + call sfftw_plan_dft_c2r_1d(plan2,nfft,c,a,nflags) + endif + endif + + t2=second() + tplan=t2-t0 !Total planning time for this length + + total=0. + do iter=1,iters !Now do many iterations + a(1:nfft)=b(1:nfft) !Copy test data into a() + t0=second() + call sfftw_execute(plan1) + call sfftw_execute(plan2) + t1=second() + total=total+t1-t0 + if(total.ge.1.0) go to 40 !Cut iterations short if t>1 s + enddo + iter=iters + +40 time=0.5*total/iter !Time for one FFT of current length + tplan=0.5*tplan-time !Planning time for one FFT + if(tplan.lt.0) tplan=0. + a(1:nfft)=a(1:nfft)/nfft + +! Compute RMS difference between original array and back-transformed array. + sq=0. + if(ncomplex.eq.1) then + do i=1,nfft + sq=sq + real(a(i)-b(i))**2 + imag(a(i)-b(i))**2 + enddo + else + do i=1,nfft + sq=sq + (ar(i)-br(i))**2 + enddo + endif + rms=sqrt(sq/nfft) + + freq=1.e-6*nfft/time + mflops=5.0/(1.e6*time/(nfft*log(float(nfft))/log(2.0))) + if(n2.eq.1 .or. n2.eq.999999) then + write(*,1050) nfft,time,rms,freq,mflops,iter,tplan + write(12,1050) nfft,time,rms,freq,mflops,iter,tplan +1050 format(i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1) + else + write(*,1060) ii,nfft,time,rms,freq,mflops,iter,tplan + write(12,1060) ii,nfft,time,rms,freq,mflops,iter,tplan +1060 format(i2,i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1) + endif + enddo + +900 continue + if(nw.eq.1) then + rewind 13 + call export_wisdom_to_file(13) +! write(*,1070) +!1070 format(/'Exported FFTW wisdom') + endif + + call sfftw_destroy_plan(plan1) + call sfftw_destroy_plan(plan2) + +999 end program chkfft diff --git a/lib/chkfft3.f90 b/lib/chkfft3.f90 index 7b6d74e1..01b3d3b4 100755 --- a/lib/chkfft3.f90 +++ b/lib/chkfft3.f90 @@ -1,177 +1,177 @@ -program chkfft - -! Tests and times one-dimensional FFTs computed by FFTW3 - use, intrinsic :: iso_c_binding - use FFTW3 - parameter (NMAX=8*1024*1024) !Maximum FFT length - complex a(NMAX),b(NMAX),c(NMAX) - real ar(NMAX),br(NMAX),cr(NMAX) - real mflops -! integer*8 plan1,plan2 !Pointers to stored plans - type(C_PTR) :: plan1,plan2 !Pointers to FFTW plans - character infile*12,arg*8 - logical list - common/patience/npatience - equivalence (a,ar),(b,br),(c,cr) -! include 'fftw3.f90' !FFTW definitions - - nargs=iargc() - if(nargs.ne.5) then - print*,'Usage: chkfft3 nr nw nc np' - print*,' nfft: length of FFT' - print*,' nfft=0: do lengths 2^n, n=2^4 to 2^23' - print*,' infile: name of file with nfft values, one per line' - print*,' nr: 0/1 to not read (or read) wisdom' - print*,' nw: 0/1 to not write (or write) wisdom' - print*,' nc: 0/1 for real or complex data' - print*,' np: 0-4 patience for finding best algorithm' - go to 999 - endif - - list=.false. - nfft=-1 - call getarg(1,infile) - open(10,file=infile,status='old',err=1) - list=.true. !A valid file name was provided - go to 2 -1 read(infile,*) nfft !Take first argument to be nfft -2 call getarg(2,arg) - read(arg,*) nr - call getarg(3,arg) - read(arg,*) nw - call getarg(4,arg) - read(arg,*) ncomplex - call getarg(5,arg) - read(arg,*) npatience - - if(list) write(*,1000) infile,nr,nw,ncomplex,npatience -1000 format(/'infile: ',a12,' nr:',i2,' nw',i2,' nc:',i2,' np:',i2/) - if(.not.list) write(*,1002) nfft,nr,nw,ncomplex,npatience -1002 format(/'nfft: ',i10,' nr:',i2,' nw',i2,' nc:',i2,' np:',i2/) - - 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 - - open(12,file='chkfft.out',status='unknown') - - if(nr.ne.0) then - isuccess=fftwf_import_wisdom_from_filename('fftwf_wisdom.dat'//char(0)) - if(isuccess.eq.1) then - write(*,1010) -1010 format('Imported FFTW wisdom.') - else - write(*,1012) -1012 format('Failed to import FFTW wisdom.') - go to 999 - endif - endif - - idum=-1 !Set random seed - ndim=1 !One-dimensional transforms - do i=1,NMAX !Set random data - x=gran() - y=gran() - b(i)=cmplx(x,y) !Generate random data - enddo - - iters=1000000 - if(list .or. (nfft.gt.0)) then - n1=1 - n2=1 - if(nfft.eq.-1) n2=999999 - write(*,1020) -1020 format(' NFFT Time rms MHz MFlops iters', & - ' tplan'/61('-')) - else - n1=4 - n2=23 - write(*,1030) -1030 format(' n N=2^n Time rms MHz MFlops iters', & - ' tplan'/63('-')) - endif - - do ii=n1,n2 !Test one or more FFT lengths - if(list) then - read(10,*,end=900) nfft !Read nfft from file - else if(n2.gt.n1) then - nfft=2**ii !Do powers of 2 - endif - - iformf=1 - iformb=1 - if(ncomplex.eq.0) then - iformf=0 !Real-to-complex transform - iformb=-1 !Complex-to-real (inverse) transform - endif - - if(nfft.gt.NMAX) go to 900 - a(1:nfft)=b(1:nfft) !Copy test data into a() - t0=second() - if(ncomplex.ne.0) then - plan1=fftwf_plan_dft_1d(nfft,a,c,-1,nflags) - plan2=fftwf_plan_dft_1d(nfft,a,c,+1,nflags) - else - plan1=fftwf_plan_dft_r2c_1d(nfft,ar,c,nflags) - plan2=fftwf_plan_dft_c2r_1d(nfft,c,ar,nflags) - endif - - t2=second() - tplan=t2-t0 !Total planning time for this length - - total=0. - do iter=1,iters !Now do many iterations - a(1:nfft)=b(1:nfft) !Copy test data into a() - t0=second() - call fftwf_execute_dft(plan1,a,c) - call fftwf_execute_dft(plan2,c,a) - t1=second() - total=total+t1-t0 - if(total.ge.1.0) go to 40 !Cut iterations short if t>1 s - enddo - iter=iters - -40 time=0.5*total/iter !Time for one FFT of current length - tplan=0.5*tplan-time !Planning time for one FFT - if(tplan.lt.0) tplan=0. - a(1:nfft)=a(1:nfft)/nfft - -! Compute RMS difference between original array and back-transformed array. - sq=0. - if(ncomplex.eq.1) then - do i=1,nfft - sq=sq + real(a(i)-b(i))**2 + imag(a(i)-b(i))**2 - enddo - else - do i=1,nfft - sq=sq + (ar(i)-br(i))**2 - enddo - endif - rms=sqrt(sq/nfft) - - freq=1.e-6*nfft/time - mflops=5.0/(1.e6*time/(nfft*log(float(nfft))/log(2.0))) - if(n2.eq.1 .or. n2.eq.999999) then - write(*,1050) nfft,time,rms,freq,mflops,iter,tplan - write(12,1050) nfft,time,rms,freq,mflops,iter,tplan -1050 format(i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1) - else - write(*,1060) ii,nfft,time,rms,freq,mflops,iter,tplan - write(12,1060) ii,nfft,time,rms,freq,mflops,iter,tplan -1060 format(i2,i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1) - endif - enddo - -900 continue - if(nw.eq.1) then - ierr=fftwf_export_wisdom_to_filename('fftwf_wisdom.dat'//char(0)) - write(*,1070) -1070 format(/'Exported FFTW wisdom') - endif - - call fftwf_destroy_plan(plan1) - call fftwf_destroy_plan(plan2) - -999 end program chkfft +program chkfft + +! Tests and times one-dimensional FFTs computed by FFTW3 + use, intrinsic :: iso_c_binding + use FFTW3 + parameter (NMAX=8*1024*1024) !Maximum FFT length + complex a(NMAX),b(NMAX),c(NMAX) + real ar(NMAX),br(NMAX),cr(NMAX) + real mflops +! integer*8 plan1,plan2 !Pointers to stored plans + type(C_PTR) :: plan1,plan2 !Pointers to FFTW plans + character infile*12,arg*8 + logical list + common/patience/npatience + equivalence (a,ar),(b,br),(c,cr) +! include 'fftw3.f90' !FFTW definitions + + nargs=iargc() + if(nargs.ne.5) then + print*,'Usage: chkfft3 nr nw nc np' + print*,' nfft: length of FFT' + print*,' nfft=0: do lengths 2^n, n=2^4 to 2^23' + print*,' infile: name of file with nfft values, one per line' + print*,' nr: 0/1 to not read (or read) wisdom' + print*,' nw: 0/1 to not write (or write) wisdom' + print*,' nc: 0/1 for real or complex data' + print*,' np: 0-4 patience for finding best algorithm' + go to 999 + endif + + list=.false. + nfft=-1 + call getarg(1,infile) + open(10,file=infile,status='old',err=1) + list=.true. !A valid file name was provided + go to 2 +1 read(infile,*) nfft !Take first argument to be nfft +2 call getarg(2,arg) + read(arg,*) nr + call getarg(3,arg) + read(arg,*) nw + call getarg(4,arg) + read(arg,*) ncomplex + call getarg(5,arg) + read(arg,*) npatience + + if(list) write(*,1000) infile,nr,nw,ncomplex,npatience +1000 format(/'infile: ',a12,' nr:',i2,' nw',i2,' nc:',i2,' np:',i2/) + if(.not.list) write(*,1002) nfft,nr,nw,ncomplex,npatience +1002 format(/'nfft: ',i10,' nr:',i2,' nw',i2,' nc:',i2,' np:',i2/) + + 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 + + open(12,file='chkfft.out',status='unknown') + + if(nr.ne.0) then + isuccess=fftwf_import_wisdom_from_filename('fftwf_wisdom.dat'//char(0)) + if(isuccess.eq.1) then + write(*,1010) +1010 format('Imported FFTW wisdom.') + else + write(*,1012) +1012 format('Failed to import FFTW wisdom.') + go to 999 + endif + endif + + idum=-1 !Set random seed + ndim=1 !One-dimensional transforms + do i=1,NMAX !Set random data + x=gran() + y=gran() + b(i)=cmplx(x,y) !Generate random data + enddo + + iters=1000000 + if(list .or. (nfft.gt.0)) then + n1=1 + n2=1 + if(nfft.eq.-1) n2=999999 + write(*,1020) +1020 format(' NFFT Time rms MHz MFlops iters', & + ' tplan'/61('-')) + else + n1=4 + n2=23 + write(*,1030) +1030 format(' n N=2^n Time rms MHz MFlops iters', & + ' tplan'/63('-')) + endif + + do ii=n1,n2 !Test one or more FFT lengths + if(list) then + read(10,*,end=900) nfft !Read nfft from file + else if(n2.gt.n1) then + nfft=2**ii !Do powers of 2 + endif + + iformf=1 + iformb=1 + if(ncomplex.eq.0) then + iformf=0 !Real-to-complex transform + iformb=-1 !Complex-to-real (inverse) transform + endif + + if(nfft.gt.NMAX) go to 900 + a(1:nfft)=b(1:nfft) !Copy test data into a() + t0=second() + if(ncomplex.ne.0) then + plan1=fftwf_plan_dft_1d(nfft,a,c,-1,nflags) + plan2=fftwf_plan_dft_1d(nfft,a,c,+1,nflags) + else + plan1=fftwf_plan_dft_r2c_1d(nfft,ar,c,nflags) + plan2=fftwf_plan_dft_c2r_1d(nfft,c,ar,nflags) + endif + + t2=second() + tplan=t2-t0 !Total planning time for this length + + total=0. + do iter=1,iters !Now do many iterations + a(1:nfft)=b(1:nfft) !Copy test data into a() + t0=second() + call fftwf_execute_dft(plan1,a,c) + call fftwf_execute_dft(plan2,c,a) + t1=second() + total=total+t1-t0 + if(total.ge.1.0) go to 40 !Cut iterations short if t>1 s + enddo + iter=iters + +40 time=0.5*total/iter !Time for one FFT of current length + tplan=0.5*tplan-time !Planning time for one FFT + if(tplan.lt.0) tplan=0. + a(1:nfft)=a(1:nfft)/nfft + +! Compute RMS difference between original array and back-transformed array. + sq=0. + if(ncomplex.eq.1) then + do i=1,nfft + sq=sq + real(a(i)-b(i))**2 + imag(a(i)-b(i))**2 + enddo + else + do i=1,nfft + sq=sq + (ar(i)-br(i))**2 + enddo + endif + rms=sqrt(sq/nfft) + + freq=1.e-6*nfft/time + mflops=5.0/(1.e6*time/(nfft*log(float(nfft))/log(2.0))) + if(n2.eq.1 .or. n2.eq.999999) then + write(*,1050) nfft,time,rms,freq,mflops,iter,tplan + write(12,1050) nfft,time,rms,freq,mflops,iter,tplan +1050 format(i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1) + else + write(*,1060) ii,nfft,time,rms,freq,mflops,iter,tplan + write(12,1060) ii,nfft,time,rms,freq,mflops,iter,tplan +1060 format(i2,i8,f11.7,f12.8,f7.2,f8.1,i8,f6.1) + endif + enddo + +900 continue + if(nw.eq.1) then + ierr=fftwf_export_wisdom_to_filename('fftwf_wisdom.dat'//char(0)) + write(*,1070) +1070 format(/'Exported FFTW wisdom') + endif + + call fftwf_destroy_plan(plan1) + call fftwf_destroy_plan(plan2) + +999 end program chkfft diff --git a/lib/code426.f90 b/lib/code426.f90 index 703a89a4..111c5492 100755 --- a/lib/code426.f90 +++ b/lib/code426.f90 @@ -1,62 +1,62 @@ -program code426 - - parameter (MZ=26) !Number of 4-FSK symbols - parameter (JZMAX=64) !Desired number of codewords - integer ic(MZ,JZMAX),icsave(MZ) - real c(MZ) - character*12 arg - - nargs=iargc() - if(nargs.ne.2) then - print*,'Usage: code426 ' - print*,'Example: code426 64 10000000' - go to 999 - endif - call getarg(1,arg) - read(arg,*) nmsgs - call getarg(2,arg) - read(arg,*) iters - - call init_random_seed() - - open(13,file='code426.out',status='unknown') - - write(*,1002) nmsgs,iters - write(13,1002) nmsgs,iters -1002 format('Nmsgs:',i4,' Iters:',i10/(66('-'))) - - do i=1,MZ !Create 4 mutually orthogonal codewords - ic(i,1)=mod(i-1,4) - ic(i,2)=mod(i,4) - ic(i,3)=mod(i+1,4) - ic(i,4)=mod(i+2,4) - enddo - - do j=1,4 !Write them out - write(*,1000) j,MZ,ic(1:MZ,j) - write(13,1000) j,MZ,ic(1:MZ,j) -1000 format(2i5,3x,26i2) - enddo - - do j=5,nmsgs !Find codewords up to j=nmsgs with maximum - npk=0 !distance from all the rest - do i=1,iters - call random_number(c) !Generate a random codeword candidate - ic(1:MZ,j)=int(4*c) !Convert real to integer -! nd=MZ -! do k=1,j-1 !Test candidate against all others in list -! n=count(ic(1:MZ,j).ne.ic(1:MZ,k)) -! nd=min(n,nd) -! enddo - call dist426(ic,j,mind) - if(mind.gt.npk) then - npk=mind - icsave=ic(1:MZ,j) !Best candidate so far, save it -! if(npk.ge.19) exit !It won't get any better... - endif - enddo - write(*,1000) j,npk,ic(1:MZ,j) - write(13,1000) j,npk,ic(1:MZ,j) - enddo - -999 end program code426 +program code426 + + parameter (MZ=26) !Number of 4-FSK symbols + parameter (JZMAX=64) !Desired number of codewords + integer ic(MZ,JZMAX),icsave(MZ) + real c(MZ) + character*12 arg + + nargs=iargc() + if(nargs.ne.2) then + print*,'Usage: code426 ' + print*,'Example: code426 64 10000000' + go to 999 + endif + call getarg(1,arg) + read(arg,*) nmsgs + call getarg(2,arg) + read(arg,*) iters + + call init_random_seed() + + open(13,file='code426.out',status='unknown') + + write(*,1002) nmsgs,iters + write(13,1002) nmsgs,iters +1002 format('Nmsgs:',i4,' Iters:',i10/(66('-'))) + + do i=1,MZ !Create 4 mutually orthogonal codewords + ic(i,1)=mod(i-1,4) + ic(i,2)=mod(i,4) + ic(i,3)=mod(i+1,4) + ic(i,4)=mod(i+2,4) + enddo + + do j=1,4 !Write them out + write(*,1000) j,MZ,ic(1:MZ,j) + write(13,1000) j,MZ,ic(1:MZ,j) +1000 format(2i5,3x,26i2) + enddo + + do j=5,nmsgs !Find codewords up to j=nmsgs with maximum + npk=0 !distance from all the rest + do i=1,iters + call random_number(c) !Generate a random codeword candidate + ic(1:MZ,j)=int(4*c) !Convert real to integer +! nd=MZ +! do k=1,j-1 !Test candidate against all others in list +! n=count(ic(1:MZ,j).ne.ic(1:MZ,k)) +! nd=min(n,nd) +! enddo + call dist426(ic,j,mind) + if(mind.gt.npk) then + npk=mind + icsave=ic(1:MZ,j) !Best candidate so far, save it +! if(npk.ge.19) exit !It won't get any better... + endif + enddo + write(*,1000) j,npk,ic(1:MZ,j) + write(13,1000) j,npk,ic(1:MZ,j) + enddo + +999 end program code426 diff --git a/lib/conv232.f90 b/lib/conv232.f90 index 839d8311..3a347e1d 100755 --- a/lib/conv232.f90 +++ b/lib/conv232.f90 @@ -1,38 +1,38 @@ -! Layland-Lushbaugh polynomials for a K=32, r=1/2 convolutional code, -! and 8-bit parity lookup table. - - data npoly1/-221228207/,npoly2/-463389625/ - integer*1 partab(0:255) - data partab/ & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 0, 1, 1, 0, 1, 0, 0, 1, & - 1, 0, 0, 1, 0, 1, 1, 0/ +! Layland-Lushbaugh polynomials for a K=32, r=1/2 convolutional code, +! and 8-bit parity lookup table. + + data npoly1/-221228207/,npoly2/-463389625/ + integer*1 partab(0:255) + data partab/ & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0/ diff --git a/lib/count4.f90 b/lib/count4.f90 index ce1af297..3c8c5ddc 100755 --- a/lib/count4.f90 +++ b/lib/count4.f90 @@ -1,54 +1,54 @@ -program count4 - - parameter(NMAX=1000) - character*47 line - real snr(NMAX) - real dt(NMAX) - real f(NMAX) - - open(10,file='/users/joe/appdata/local/wsjt-x/all.txt',status='old') - - read(10,1000,end=10) line -1000 format(a47) - - nsync1=0 - nsync2=0 - n1=0 - n2=0 - nerr=0 - - do i=1,99999 - read(10,1000,end=10) line - if(line(47:47).ne.' ') cycle !Skip average decodes - if(line(20:20).eq.'*') nsync1=nsync1+1 - if(line(20:20).eq.'#') nsync2=nsync2+1 - if(line(22:34).eq.'CQ K1ABC FN42') then - n2=n2+1 !Correlation decode - read(line,1002) snr(n2),dt(n2),f(n2) -1002 format(4x,f4.0,f5.2,f5.0) - if(line(42:42).eq.'*') n1=n1+1 !Convolutional decode - else - if(line(22:34).ne.' ') nerr=nerr+1 - endif - enddo - -10 call stats(snr,n2,snrave,snrdev) - call stats(dt,n2,dtave,dtdev) - call stats(f,n2,fave,fdev) - -write(*,1010) nsync1,nsync2,n1,n2,nerr,snrave,dtave,fave,snrdev,dtdev,fdev -1010 format(5i5,f7.1,f7.2,f7.0/25x,f7.1,f7.2,f7.0) - -end program count4 - -subroutine stats(x,nz,ave,rms) - real x(nz) - - ave=0. - rms=0. - if(nz.gt.0) ave=sum(x)/nz - x=x-ave - if(nz.gt.1) rms=sqrt(dot_product(x,x)/(nz-1)) - - return -end subroutine stats +program count4 + + parameter(NMAX=1000) + character*47 line + real snr(NMAX) + real dt(NMAX) + real f(NMAX) + + open(10,file='/users/joe/appdata/local/wsjt-x/all.txt',status='old') + + read(10,1000,end=10) line +1000 format(a47) + + nsync1=0 + nsync2=0 + n1=0 + n2=0 + nerr=0 + + do i=1,99999 + read(10,1000,end=10) line + if(line(47:47).ne.' ') cycle !Skip average decodes + if(line(20:20).eq.'*') nsync1=nsync1+1 + if(line(20:20).eq.'#') nsync2=nsync2+1 + if(line(22:34).eq.'CQ K1ABC FN42') then + n2=n2+1 !Correlation decode + read(line,1002) snr(n2),dt(n2),f(n2) +1002 format(4x,f4.0,f5.2,f5.0) + if(line(42:42).eq.'*') n1=n1+1 !Convolutional decode + else + if(line(22:34).ne.' ') nerr=nerr+1 + endif + enddo + +10 call stats(snr,n2,snrave,snrdev) + call stats(dt,n2,dtave,dtdev) + call stats(f,n2,fave,fdev) + +write(*,1010) nsync1,nsync2,n1,n2,nerr,snrave,dtave,fave,snrdev,dtdev,fdev +1010 format(5i5,f7.1,f7.2,f7.0/25x,f7.1,f7.2,f7.0) + +end program count4 + +subroutine stats(x,nz,ave,rms) + real x(nz) + + ave=0. + rms=0. + if(nz.gt.0) ave=sum(x)/nz + x=x-ave + if(nz.gt.1) rms=sqrt(dot_product(x,x)/(nz-1)) + + return +end subroutine stats diff --git a/lib/crc.f90 b/lib/crc.f90 index 0997bac8..f0cd17e3 100755 --- a/lib/crc.f90 +++ b/lib/crc.f90 @@ -1,54 +1,54 @@ -module crc - use, intrinsic :: iso_c_binding, only: c_int, c_loc, c_int8_t, c_bool, c_short - interface - - function crc14 (data, length) bind (C, name="crc14") - use, intrinsic :: iso_c_binding, only: c_short, c_ptr, c_int - implicit none - integer (c_short) :: crc14 - type (c_ptr), value :: data - integer (c_int), value :: length - end function crc14 - - function crc14_check (data, length) bind (C, name="crc14_check") - use, intrinsic :: iso_c_binding, only: c_bool, c_ptr, c_int - implicit none - logical (c_bool) :: crc14_check - type (c_ptr), value :: data - integer (c_int), value :: length - end function crc14_check - - function crc13 (data, length) bind (C, name="crc13") - use, intrinsic :: iso_c_binding, only: c_short, c_ptr, c_int - implicit none - integer (c_short) :: crc13 - type (c_ptr), value :: data - integer (c_int), value :: length - end function crc13 - - function crc13_check (data, length) bind (C, name="crc13_check") - use, intrinsic :: iso_c_binding, only: c_bool, c_ptr, c_int - implicit none - logical (c_bool) :: crc13_check - type (c_ptr), value :: data - integer (c_int), value :: length - end function crc13_check - - function crc10 (data, length) bind (C, name="crc10") - use, intrinsic :: iso_c_binding, only: c_short, c_ptr, c_int - implicit none - integer (c_short) :: crc10 - type (c_ptr), value :: data - integer (c_int), value :: length - end function crc10 - - function crc10_check (data, length) bind (C, name="crc10_check") - use, intrinsic :: iso_c_binding, only: c_bool, c_ptr, c_int - implicit none - logical (c_bool) :: crc10_check - type (c_ptr), value :: data - integer (c_int), value :: length - end function crc10_check - - end interface -end module crc +module crc + use, intrinsic :: iso_c_binding, only: c_int, c_loc, c_int8_t, c_bool, c_short + interface + + function crc14 (data, length) bind (C, name="crc14") + use, intrinsic :: iso_c_binding, only: c_short, c_ptr, c_int + implicit none + integer (c_short) :: crc14 + type (c_ptr), value :: data + integer (c_int), value :: length + end function crc14 + + function crc14_check (data, length) bind (C, name="crc14_check") + use, intrinsic :: iso_c_binding, only: c_bool, c_ptr, c_int + implicit none + logical (c_bool) :: crc14_check + type (c_ptr), value :: data + integer (c_int), value :: length + end function crc14_check + + function crc13 (data, length) bind (C, name="crc13") + use, intrinsic :: iso_c_binding, only: c_short, c_ptr, c_int + implicit none + integer (c_short) :: crc13 + type (c_ptr), value :: data + integer (c_int), value :: length + end function crc13 + + function crc13_check (data, length) bind (C, name="crc13_check") + use, intrinsic :: iso_c_binding, only: c_bool, c_ptr, c_int + implicit none + logical (c_bool) :: crc13_check + type (c_ptr), value :: data + integer (c_int), value :: length + end function crc13_check + + function crc10 (data, length) bind (C, name="crc10") + use, intrinsic :: iso_c_binding, only: c_short, c_ptr, c_int + implicit none + integer (c_short) :: crc10 + type (c_ptr), value :: data + integer (c_int), value :: length + end function crc10 + + function crc10_check (data, length) bind (C, name="crc10_check") + use, intrinsic :: iso_c_binding, only: c_bool, c_ptr, c_int + implicit none + logical (c_bool) :: crc10_check + type (c_ptr), value :: data + integer (c_int), value :: length + end function crc10_check + + end interface +end module crc diff --git a/lib/crc10.cpp b/lib/crc10.cpp index 61e45e0e..93f66493 100755 --- a/lib/crc10.cpp +++ b/lib/crc10.cpp @@ -1,31 +1,31 @@ -#include -#include - -extern "C" -{ - short crc10 (unsigned char const * data, int length); - bool crc10_check (unsigned char const * data, int length); -} - -#define POLY 0x08f - -#ifdef BOOST_NO_CXX11_CONSTEXPR -#define TRUNCATED_POLYNOMIAL POLY -#else -namespace -{ - unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; -} -#endif - -// assumes CRC is last 16 bits of the data and is set to zero -// caller should assign the returned CRC into the message in big endian byte order -short crc10 (unsigned char const * data, int length) -{ - return boost::augmented_crc<10, TRUNCATED_POLYNOMIAL> (data, length); -} - -bool crc10_check (unsigned char const * data, int length) -{ - return !boost::augmented_crc<10, TRUNCATED_POLYNOMIAL> (data, length); -} +#include +#include + +extern "C" +{ + short crc10 (unsigned char const * data, int length); + bool crc10_check (unsigned char const * data, int length); +} + +#define POLY 0x08f + +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define TRUNCATED_POLYNOMIAL POLY +#else +namespace +{ + unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; +} +#endif + +// assumes CRC is last 16 bits of the data and is set to zero +// caller should assign the returned CRC into the message in big endian byte order +short crc10 (unsigned char const * data, int length) +{ + return boost::augmented_crc<10, TRUNCATED_POLYNOMIAL> (data, length); +} + +bool crc10_check (unsigned char const * data, int length) +{ + return !boost::augmented_crc<10, TRUNCATED_POLYNOMIAL> (data, length); +} diff --git a/lib/crc13.cpp b/lib/crc13.cpp index 505f74b7..03265088 100755 --- a/lib/crc13.cpp +++ b/lib/crc13.cpp @@ -1,31 +1,31 @@ -#include -#include - -extern "C" -{ - short crc13 (unsigned char const * data, int length); - bool crc13_check (unsigned char const * data, int length); -} - -#define POLY 0x15D7 - -#ifdef BOOST_NO_CXX11_CONSTEXPR -#define TRUNCATED_POLYNOMIAL POLY -#else -namespace -{ - unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; -} -#endif - -// assumes CRC is last 13 bits of the data and is set to zero -// caller should assign the returned CRC into the message in big endian byte order -short crc13 (unsigned char const * data, int length) -{ - return boost::augmented_crc<13, TRUNCATED_POLYNOMIAL> (data, length); -} - -bool crc13_check (unsigned char const * data, int length) -{ - return !boost::augmented_crc<13, TRUNCATED_POLYNOMIAL> (data, length); -} +#include +#include + +extern "C" +{ + short crc13 (unsigned char const * data, int length); + bool crc13_check (unsigned char const * data, int length); +} + +#define POLY 0x15D7 + +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define TRUNCATED_POLYNOMIAL POLY +#else +namespace +{ + unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; +} +#endif + +// assumes CRC is last 13 bits of the data and is set to zero +// caller should assign the returned CRC into the message in big endian byte order +short crc13 (unsigned char const * data, int length) +{ + return boost::augmented_crc<13, TRUNCATED_POLYNOMIAL> (data, length); +} + +bool crc13_check (unsigned char const * data, int length) +{ + return !boost::augmented_crc<13, TRUNCATED_POLYNOMIAL> (data, length); +} diff --git a/lib/crc14.cpp b/lib/crc14.cpp index b43ea6d1..19a9ba55 100755 --- a/lib/crc14.cpp +++ b/lib/crc14.cpp @@ -1,31 +1,31 @@ -#include -#include - -extern "C" -{ - short crc14 (unsigned char const * data, int length); - bool crc14_check (unsigned char const * data, int length); -} - -#define POLY 0x2757 - -#ifdef BOOST_NO_CXX11_CONSTEXPR -#define TRUNCATED_POLYNOMIAL POLY -#else -namespace -{ - unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; -} -#endif - -// assumes CRC is last 14 bits of the data and is set to zero -// caller should assign the returned CRC into the message in big endian byte order -short crc14 (unsigned char const * data, int length) -{ - return boost::augmented_crc<14, TRUNCATED_POLYNOMIAL> (data, length); -} - -bool crc14_check (unsigned char const * data, int length) -{ - return !boost::augmented_crc<14, TRUNCATED_POLYNOMIAL> (data, length); -} +#include +#include + +extern "C" +{ + short crc14 (unsigned char const * data, int length); + bool crc14_check (unsigned char const * data, int length); +} + +#define POLY 0x2757 + +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define TRUNCATED_POLYNOMIAL POLY +#else +namespace +{ + unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; +} +#endif + +// assumes CRC is last 14 bits of the data and is set to zero +// caller should assign the returned CRC into the message in big endian byte order +short crc14 (unsigned char const * data, int length) +{ + return boost::augmented_crc<14, TRUNCATED_POLYNOMIAL> (data, length); +} + +bool crc14_check (unsigned char const * data, int length) +{ + return !boost::augmented_crc<14, TRUNCATED_POLYNOMIAL> (data, length); +} diff --git a/lib/cwsim.f90 b/lib/cwsim.f90 index e9034a9f..92300b72 100755 --- a/lib/cwsim.f90 +++ b/lib/cwsim.f90 @@ -1,235 +1,235 @@ -program cwsim - -! Generate simulated audio for a CW message sent repeatedly for 60 seconds - - use wavhdr - parameter (NMAX=60*12000) - type(hdr) h !Header for the .wav file - integer*2 iwave(NMAX) !Generated waveform (no noise) - integer icw(500) !Encoded CW message bits - complex cspread(0:NMAX-1) !Complex amplitude for Rayleigh fading - complex cdat(0:NMAX-1) !Complex waveform - real dat(NMAX) !Audio waveform - real*4 xnoise(NMAX) !Generated random noise - character*60 message - character*12 arg - - nargs=iargc() - if(nargs.ne.6) then - print*,'Usage: cwsim "message" freq bw wpm fspread snr' - print*,'Example: cwsim "CQ CQ CQ DE K1JT K1JT K1JT" 700 100 20 100 -10' - go to 999 - endif - - call getarg(1,message) - call getarg(2,arg) - read(arg,*) ifreq !Audio frequency (Hz) - call getarg(3,arg) - read(arg,*) bw !Bandwidth (Hz) - call getarg(4,arg) - read(arg,*) wpm !CW speed, words per minute - call getarg(5,arg) - read(arg,*) fspread !Doppler spread in Hz - call getarg(6,arg) - read(arg,*) snrdb !S/N in dB (2500 hz reference BW) - - rms=500.0 - bandwidth_ratio=2500.0/6000.0 - sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb) - twopi=8.0*atan(1.0) - - h=default_header(12000,NMAX) - open(10,file='000000_0000.wav',access='stream',status='unknown') - do i=1,NMAX !Generate gaussian noise - xnoise(i)=gran() - enddo - - itone=0 - call morse(message,icw,ncw) - call cwsig(icw,ncw,ifreq,wpm,sig,cdat) - nfft=NMAX - - if(fspread.ne.0) then !Apply specified Doppler spread - nh=nfft/2 - df=12000.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 - cdat=cspread*cdat !Apply Rayleigh fading - endif - - dat=aimag(cdat) + xnoise - - cdat=dat - call four2a(cdat,nfft,1,-1,1) !c2c to frequency domain - ia=max(250/df,(ifreq-0.5*bw)/df) - ib=ia+bw/df - cdat(0:ia)=0. - cdat(ib:)=0. - call four2a(cdat,nfft,1,+1,1) !c2c to time domain - fac=sqrt(5000/bw)/nfft - dat=fac*real(cdat) - - iwave=nint(rms*dat) - write(10) h,iwave - close(10) - -999 end program cwsim - -subroutine cwsig(icw,ncw,ifreq,wpm,sig,cdat) - - parameter(NMAX=60*12000) - integer icw(ncw) - complex cdat(NMAX) - complex z(NMAX) - real x(NMAX) - real y(NMAX) - real*8 dt,twopi,phi,dphi,fsample,tdit,t - - nspd=nint(1.2*12000.0/wpm) - fsample=12000.d0 !Sample rate (Hz) - dt=1.d0/fsample !Sample interval (s) - tdit=nspd*dt - twopi=8.d0*atan(1.d0) - dphi=twopi*ifreq*dt - phi=0. - k=12000 !Start audio at t = 1.0 s - t=0. - npts=59*12000 - x=0. - do i=1,npts - t=t+dt - j=nint(t/tdit) + 1 - j=mod(j-1,ncw) + 1 - phi=phi + dphi - if(phi.gt.twopi) phi=phi-twopi - xphi=phi - k=k+1 - x(k)=icw(j) - z(k)=cmplx(cos(xphi),sin(xphi)) - if(t.ge.59.5) exit - enddo - - nadd=0.004/dt - call smo(x,npts,y,nadd) - y=y/nadd - cdat=sig*y*z - - return -end subroutine cwsig - -subroutine morse(msg,idat,n) - -! Convert ascii message to a Morse code bit string. -! Dash = 3 dots -! Space between dots, dashes = 1 dot -! Space between letters = 3 dots -! Space between words = 7 dots - - character*(*) msg - integer idat(500) - integer*1 ic(21,38) - data ic/ & - 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,20, & - 1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,18, & - 1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,16, & - 1,0,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & - 1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & - 1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,14, & - 1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,16, & - 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,0,0,18, & - 1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & - 1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2, & - 1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, & - 1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & - 1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & - 1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & - 1,0,1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,14, & - 1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & - 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, & - 1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & - 1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,14, & - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2/ !Incremental word space - save - - msglen=len(trim(msg)) - idat=0 - n=6 - do k=1,msglen - jj=ichar(msg(k:k)) - if(jj.ge.97 .and. jj.le.122) jj=jj-32 !Convert lower to upper case - if(jj.ge.48 .and. jj.le.57) j=jj-48 !Numbers - if(jj.ge.65 .and. jj.le.90) j=jj-55 !Letters - if(jj.eq.47) j=36 !Slash (/) - if(jj.eq.32) j=37 !Word space - j=j+1 - -! Insert this character - nmax=ic(21,j) - if (n + nmax + 4 .gt. size (idat)) exit - do i=1,nmax - n=n+1 - idat(n)=ic(i,j) - enddo - -! Insert character space of 2 dit lengths: - n=n+1 - idat(n)=0 - n=n+1 - idat(n)=0 - enddo - -! Insert word space at end of message - do j=1,4 - n=n+1 - idat(n)=0 - enddo - - return -end subroutine morse +program cwsim + +! Generate simulated audio for a CW message sent repeatedly for 60 seconds + + use wavhdr + parameter (NMAX=60*12000) + type(hdr) h !Header for the .wav file + integer*2 iwave(NMAX) !Generated waveform (no noise) + integer icw(500) !Encoded CW message bits + complex cspread(0:NMAX-1) !Complex amplitude for Rayleigh fading + complex cdat(0:NMAX-1) !Complex waveform + real dat(NMAX) !Audio waveform + real*4 xnoise(NMAX) !Generated random noise + character*60 message + character*12 arg + + nargs=iargc() + if(nargs.ne.6) then + print*,'Usage: cwsim "message" freq bw wpm fspread snr' + print*,'Example: cwsim "CQ CQ CQ DE K1JT K1JT K1JT" 700 100 20 100 -10' + go to 999 + endif + + call getarg(1,message) + call getarg(2,arg) + read(arg,*) ifreq !Audio frequency (Hz) + call getarg(3,arg) + read(arg,*) bw !Bandwidth (Hz) + call getarg(4,arg) + read(arg,*) wpm !CW speed, words per minute + call getarg(5,arg) + read(arg,*) fspread !Doppler spread in Hz + call getarg(6,arg) + read(arg,*) snrdb !S/N in dB (2500 hz reference BW) + + rms=500.0 + bandwidth_ratio=2500.0/6000.0 + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb) + twopi=8.0*atan(1.0) + + h=default_header(12000,NMAX) + open(10,file='000000_0000.wav',access='stream',status='unknown') + do i=1,NMAX !Generate gaussian noise + xnoise(i)=gran() + enddo + + itone=0 + call morse(message,icw,ncw) + call cwsig(icw,ncw,ifreq,wpm,sig,cdat) + nfft=NMAX + + if(fspread.ne.0) then !Apply specified Doppler spread + nh=nfft/2 + df=12000.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 + cdat=cspread*cdat !Apply Rayleigh fading + endif + + dat=aimag(cdat) + xnoise + + cdat=dat + call four2a(cdat,nfft,1,-1,1) !c2c to frequency domain + ia=max(250/df,(ifreq-0.5*bw)/df) + ib=ia+bw/df + cdat(0:ia)=0. + cdat(ib:)=0. + call four2a(cdat,nfft,1,+1,1) !c2c to time domain + fac=sqrt(5000/bw)/nfft + dat=fac*real(cdat) + + iwave=nint(rms*dat) + write(10) h,iwave + close(10) + +999 end program cwsim + +subroutine cwsig(icw,ncw,ifreq,wpm,sig,cdat) + + parameter(NMAX=60*12000) + integer icw(ncw) + complex cdat(NMAX) + complex z(NMAX) + real x(NMAX) + real y(NMAX) + real*8 dt,twopi,phi,dphi,fsample,tdit,t + + nspd=nint(1.2*12000.0/wpm) + fsample=12000.d0 !Sample rate (Hz) + dt=1.d0/fsample !Sample interval (s) + tdit=nspd*dt + twopi=8.d0*atan(1.d0) + dphi=twopi*ifreq*dt + phi=0. + k=12000 !Start audio at t = 1.0 s + t=0. + npts=59*12000 + x=0. + do i=1,npts + t=t+dt + j=nint(t/tdit) + 1 + j=mod(j-1,ncw) + 1 + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + k=k+1 + x(k)=icw(j) + z(k)=cmplx(cos(xphi),sin(xphi)) + if(t.ge.59.5) exit + enddo + + nadd=0.004/dt + call smo(x,npts,y,nadd) + y=y/nadd + cdat=sig*y*z + + return +end subroutine cwsig + +subroutine morse(msg,idat,n) + +! Convert ascii message to a Morse code bit string. +! Dash = 3 dots +! Space between dots, dashes = 1 dot +! Space between letters = 3 dots +! Space between words = 7 dots + + character*(*) msg + integer idat(500) + integer*1 ic(21,38) + data ic/ & + 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,20, & + 1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,18, & + 1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,16, & + 1,0,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & + 1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & + 1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, & + 1,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,14, & + 1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,16, & + 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,0,0,18, & + 1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & + 1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,1,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, & + 1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2, & + 1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & + 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, & + 1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & + 1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & + 1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & + 1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & + 1,0,1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, & + 1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,14, & + 1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & + 1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & + 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, & + 1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & + 1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & + 1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & + 1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, & + 1,1,1,0,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,14, & + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2/ !Incremental word space + save + + msglen=len(trim(msg)) + idat=0 + n=6 + do k=1,msglen + jj=ichar(msg(k:k)) + if(jj.ge.97 .and. jj.le.122) jj=jj-32 !Convert lower to upper case + if(jj.ge.48 .and. jj.le.57) j=jj-48 !Numbers + if(jj.ge.65 .and. jj.le.90) j=jj-55 !Letters + if(jj.eq.47) j=36 !Slash (/) + if(jj.eq.32) j=37 !Word space + j=j+1 + +! Insert this character + nmax=ic(21,j) + if (n + nmax + 4 .gt. size (idat)) exit + do i=1,nmax + n=n+1 + idat(n)=ic(i,j) + enddo + +! Insert character space of 2 dit lengths: + n=n+1 + idat(n)=0 + n=n+1 + idat(n)=0 + enddo + +! Insert word space at end of message + do j=1,4 + n=n+1 + idat(n)=0 + enddo + + return +end subroutine morse diff --git a/lib/db.f90 b/lib/db.f90 index 976724ef..aa58f43f 100755 --- a/lib/db.f90 +++ b/lib/db.f90 @@ -1,5 +1,5 @@ -real function db(x) - db=-99.0 - if(x.gt.1.259e-10) db=10.0*log10(x) - return -end function db +real function db(x) + db=-99.0 + if(x.gt.1.259e-10) db=10.0*log10(x) + return +end function db diff --git a/lib/decode4.f90 b/lib/decode4.f90 index 1c064a3c..e0596ed1 100755 --- a/lib/decode4.f90 +++ b/lib/decode4.f90 @@ -1,112 +1,112 @@ -subroutine decode4(dat,npts,dtx,nfreq,flip,mode4,ndepth,neme,minw, & - mycall,hiscall,hisgrid,decoded,nfano,deepbest,qbest,ichbest) - -! Decodes JT4 data, assuming that DT and DF have already been determined. -! Input dat(npts) has already been downsampled by 2: rate = 11025/2. -! ### NB: this initial downsampling should be removed in WSJT-X, since -! it restricts the useful bandwidth to < 2.7 kHz. - - use jt4 - real dat(npts) !Raw data - character decoded*22,deepmsg*22,deepbest*22 - character*12 mycall,hiscall - character*6 hisgrid - real*8 dt,df,phi,f0,dphi,twopi,phi1,dphi1 - complex*16 cz,cz1,c0,c1 - real*4 sym(207) - - twopi=8*atan(1.d0) - dt=2.d0/11025 !Sample interval (2x downsampled data) - df=11025.d0/2520.d0 !Tone separation for JT4A mode - nsym=206 - amp=15.0 - istart=nint((dtx+0.8)/dt) !Start index for synced FFTs - if(istart.lt.0) istart=0 - nchips=0 - qbest=0. - qtop=0. - deepmsg=' ' - ichbest=-1 - c0=0. - k=istart - phi=0.d0 - phi1=0.d0 - - ich1=minw+1 - do ich=1,7 - if(nch(ich).le.mode4) ich2=ich - enddo - - do ich=ich1,ich2 - nchips=min(nch(ich),70) - nspchip=1260/nchips - k=istart - phi=0.d0 - phi1=0.d0 - fac2=1.e-8 * sqrt(float(mode4)) - do j=1,nsym+1 - if(flip.gt.0.0) then - f0=nfreq + (npr(j))*mode4*df - f1=nfreq + (2+npr(j))*mode4*df - else - f0=nfreq + (1-npr(j))*mode4*df - f1=nfreq + (3-npr(j))*mode4*df - endif - dphi=twopi*dt*f0 - dphi1=twopi*dt*f1 - sq0=0. - sq1=0. - do nc=1,nchips - phi=0.d0 - phi1=0.d0 - c0=0. - c1=0. - do i=1,nspchip - k=k+1 - phi=phi+dphi - phi1=phi1+dphi1 - cz=dcmplx(cos(phi),-sin(phi)) - cz1=dcmplx(cos(phi1),-sin(phi1)) - if(k.le.npts) then - c0=c0 + dat(k)*cz - c1=c1 + dat(k)*cz1 - endif - enddo - sq0=sq0 + real(c0)**2 + aimag(c0)**2 - sq1=sq1 + real(c1)**2 + aimag(c1)**2 - enddo - sq0=fac2*sq0 - sq1=fac2*sq1 - rsym=amp*(sq1-sq0) - if(j.ge.1) then - rsymbol(j,ich)=rsym - sym(j)=rsym - endif - enddo - - call extract4(sym,ncount,decoded) !Do the convolutional decode - nfano=0 - if(ncount.ge.0) then - nfano=1 - ichbest=ich - exit - endif - - qual=0. !Now try deep search -! if(ndepth.ge.1) then - if(iand(ndepth,32).eq.32) then - call deep4(sym(2),neme,flip,mycall,hiscall,hisgrid,deepmsg,qual) - if(qual.gt.qbest) then - qbest=qual - deepbest=deepmsg - ichbest=ich - endif - endif - enddo - if(qbest.gt.qtop) then - qtop=qbest - endif - qual=qbest - - return -end subroutine decode4 +subroutine decode4(dat,npts,dtx,nfreq,flip,mode4,ndepth,neme,minw, & + mycall,hiscall,hisgrid,decoded,nfano,deepbest,qbest,ichbest) + +! Decodes JT4 data, assuming that DT and DF have already been determined. +! Input dat(npts) has already been downsampled by 2: rate = 11025/2. +! ### NB: this initial downsampling should be removed in WSJT-X, since +! it restricts the useful bandwidth to < 2.7 kHz. + + use jt4 + real dat(npts) !Raw data + character decoded*22,deepmsg*22,deepbest*22 + character*12 mycall,hiscall + character*6 hisgrid + real*8 dt,df,phi,f0,dphi,twopi,phi1,dphi1 + complex*16 cz,cz1,c0,c1 + real*4 sym(207) + + twopi=8*atan(1.d0) + dt=2.d0/11025 !Sample interval (2x downsampled data) + df=11025.d0/2520.d0 !Tone separation for JT4A mode + nsym=206 + amp=15.0 + istart=nint((dtx+0.8)/dt) !Start index for synced FFTs + if(istart.lt.0) istart=0 + nchips=0 + qbest=0. + qtop=0. + deepmsg=' ' + ichbest=-1 + c0=0. + k=istart + phi=0.d0 + phi1=0.d0 + + ich1=minw+1 + do ich=1,7 + if(nch(ich).le.mode4) ich2=ich + enddo + + do ich=ich1,ich2 + nchips=min(nch(ich),70) + nspchip=1260/nchips + k=istart + phi=0.d0 + phi1=0.d0 + fac2=1.e-8 * sqrt(float(mode4)) + do j=1,nsym+1 + if(flip.gt.0.0) then + f0=nfreq + (npr(j))*mode4*df + f1=nfreq + (2+npr(j))*mode4*df + else + f0=nfreq + (1-npr(j))*mode4*df + f1=nfreq + (3-npr(j))*mode4*df + endif + dphi=twopi*dt*f0 + dphi1=twopi*dt*f1 + sq0=0. + sq1=0. + do nc=1,nchips + phi=0.d0 + phi1=0.d0 + c0=0. + c1=0. + do i=1,nspchip + k=k+1 + phi=phi+dphi + phi1=phi1+dphi1 + cz=dcmplx(cos(phi),-sin(phi)) + cz1=dcmplx(cos(phi1),-sin(phi1)) + if(k.le.npts) then + c0=c0 + dat(k)*cz + c1=c1 + dat(k)*cz1 + endif + enddo + sq0=sq0 + real(c0)**2 + aimag(c0)**2 + sq1=sq1 + real(c1)**2 + aimag(c1)**2 + enddo + sq0=fac2*sq0 + sq1=fac2*sq1 + rsym=amp*(sq1-sq0) + if(j.ge.1) then + rsymbol(j,ich)=rsym + sym(j)=rsym + endif + enddo + + call extract4(sym,ncount,decoded) !Do the convolutional decode + nfano=0 + if(ncount.ge.0) then + nfano=1 + ichbest=ich + exit + endif + + qual=0. !Now try deep search +! if(ndepth.ge.1) then + if(iand(ndepth,32).eq.32) then + call deep4(sym(2),neme,flip,mycall,hiscall,hisgrid,deepmsg,qual) + if(qual.gt.qbest) then + qbest=qual + deepbest=deepmsg + ichbest=ich + endif + endif + enddo + if(qbest.gt.qtop) then + qtop=qbest + endif + qual=qbest + + return +end subroutine decode4 diff --git a/lib/decode9w.f90 b/lib/decode9w.f90 index bf5aaace..2c043c72 100755 --- a/lib/decode9w.f90 +++ b/lib/decode9w.f90 @@ -1,67 +1,67 @@ -subroutine decode9w(nfqso,ntol,nsubmode,ss,id2,sync,nsnr,xdt1,f0,decoded) - -! Decode a weak signal in a wide/slow JT9 submode. - - parameter (NSMAX=6827,NZMAX=60*12000) - real ss(184,NSMAX) !Symbol spectra at 1/2-symbol steps - real ccfred(NSMAX) !Best sync vs frequency - real ccfblue(-9:18) !Sync vs time at best frequency - real a(5) !Fitted Lorentzian params - integer*2 id2(NZMAX) !Raw 16-bit data - integer*1 i1SoftSymbols(207) !Binary soft symbols - character*22 decoded !Decoded message - - df=12000.0/16384.0 !Bin spacing in ss() - nsps=6912 !Samples per 9-FSK symbol - tstep=nsps*0.5/12000.0 !Half-symbol duration - npts=52*12000 - limit=10000 !Fano timeout parameter - - ia=max(1,nint((nfqso-ntol)/df)) !Start frequency bin - ib=min(NSMAX,nint((nfqso+ntol)/df)) !End frequency bin - lag1=-int(2.5/tstep + 0.9999) !Start lag - lag2=int(5.0/tstep + 0.9999) !End lag - nhsym=184 !Number of half-symbols - -! First sync pass finds approximate Doppler spread; second pass does a -! good Lorentzian fit to determine frequency f0. - do iter=1,2 - nadd=3 - if(iter.eq.2) nadd=2*nint(0.375*a(4)) + 1 - call sync9w(ss,nhsym,lag1,lag2,ia,ib,ccfred,ccfblue,ipk,lagpk,nadd) - s=0. - sq=0. - ns=0 - do i=-9,18 - if(abs(i-lagpk).gt.3) then - s=s+ccfblue(i) - sq=sq+ccfblue(i)**2 - ns=ns+1 - endif - enddo - base=s/ns - rms=sqrt(sq/ns - base**2) - sync=(ccfblue(lagpk)-base)/rms - xdt0=lagpk*tstep - call lorentzian(ccfred(ia),ib-ia+1,a) - f0=(ia+a(3))*df - enddo - ccfblue=(ccfblue-base)/rms - - call softsym9w(id2,npts,xdt0,f0,a(4)*df,nsubmode,xdt1-1.05,snrdb,i1softsymbols) - nsnr=nint(snrdb) - call jt9fano(i1softsymbols,limit,nlim,decoded) - -!### -! do i=-9,18 -! write(81,3081) i,ccfblue(i) -!3081 format(i3,f10.3) -! enddo -! do i=1,NSMAX -! write(82,3082) i*df,ccfred(i) -!3082 format(f10.1,e12.3) -! enddo -!### - - return -end subroutine decode9w +subroutine decode9w(nfqso,ntol,nsubmode,ss,id2,sync,nsnr,xdt1,f0,decoded) + +! Decode a weak signal in a wide/slow JT9 submode. + + parameter (NSMAX=6827,NZMAX=60*12000) + real ss(184,NSMAX) !Symbol spectra at 1/2-symbol steps + real ccfred(NSMAX) !Best sync vs frequency + real ccfblue(-9:18) !Sync vs time at best frequency + real a(5) !Fitted Lorentzian params + integer*2 id2(NZMAX) !Raw 16-bit data + integer*1 i1SoftSymbols(207) !Binary soft symbols + character*22 decoded !Decoded message + + df=12000.0/16384.0 !Bin spacing in ss() + nsps=6912 !Samples per 9-FSK symbol + tstep=nsps*0.5/12000.0 !Half-symbol duration + npts=52*12000 + limit=10000 !Fano timeout parameter + + ia=max(1,nint((nfqso-ntol)/df)) !Start frequency bin + ib=min(NSMAX,nint((nfqso+ntol)/df)) !End frequency bin + lag1=-int(2.5/tstep + 0.9999) !Start lag + lag2=int(5.0/tstep + 0.9999) !End lag + nhsym=184 !Number of half-symbols + +! First sync pass finds approximate Doppler spread; second pass does a +! good Lorentzian fit to determine frequency f0. + do iter=1,2 + nadd=3 + if(iter.eq.2) nadd=2*nint(0.375*a(4)) + 1 + call sync9w(ss,nhsym,lag1,lag2,ia,ib,ccfred,ccfblue,ipk,lagpk,nadd) + s=0. + sq=0. + ns=0 + do i=-9,18 + if(abs(i-lagpk).gt.3) then + s=s+ccfblue(i) + sq=sq+ccfblue(i)**2 + ns=ns+1 + endif + enddo + base=s/ns + rms=sqrt(sq/ns - base**2) + sync=(ccfblue(lagpk)-base)/rms + xdt0=lagpk*tstep + call lorentzian(ccfred(ia),ib-ia+1,a) + f0=(ia+a(3))*df + enddo + ccfblue=(ccfblue-base)/rms + + call softsym9w(id2,npts,xdt0,f0,a(4)*df,nsubmode,xdt1-1.05,snrdb,i1softsymbols) + nsnr=nint(snrdb) + call jt9fano(i1softsymbols,limit,nlim,decoded) + +!### +! do i=-9,18 +! write(81,3081) i,ccfblue(i) +!3081 format(i3,f10.3) +! enddo +! do i=1,NSMAX +! write(82,3082) i*df,ccfred(i) +!3082 format(f10.1,e12.3) +! enddo +!### + + return +end subroutine decode9w diff --git a/lib/decode_msk144.f90 b/lib/decode_msk144.f90 index 4c8bd920..17110cf4 100755 --- a/lib/decode_msk144.f90 +++ b/lib/decode_msk144.f90 @@ -1,57 +1,57 @@ -subroutine decode_msk144(audio_samples, params, data_dir) - include 'jt9com.f90' - - ! constants - integer, parameter :: SAMPLING_RATE = 12000 - integer, parameter :: BLOCK_SIZE = 7168 - integer, parameter :: STEP_SIZE = BLOCK_SIZE / 2 - integer, parameter :: CALL_LENGTH = 12 - - ! aguments - integer*2 audio_samples(NMAX) - type(params_block) :: params - character(len = 500) :: data_dir - - ! parameters of mskrtd - integer*2 :: buffer(BLOCK_SIZE) - real :: tsec - logical :: bshmsg = .false. ! enables shorthand messages - logical :: btrain = .false. ! turns on training in MSK144 mode - real*8 :: pcoeffs(5) = (/ 0.0, 0.0, 0.0, 0.0, 0.0 /); ! phase equalization - logical :: bswl = .false. - character(len = 80) :: line - character(len = CALL_LENGTH) :: mycall - character(len = CALL_LENGTH) :: hiscall - - ! local variables - integer :: sample_count - integer :: position - integer :: message_count = 0 - - - ! decode in 0.3s blocks - sample_count = params%ntr * SAMPLING_RATE - mycall = transfer(params%mycall, mycall) ! string to char[] - hiscall = transfer(params%hiscall, hiscall) - - do position = 1, sample_count - BLOCK_SIZE + 1, STEP_SIZE - buffer = audio_samples(position : position + BLOCK_SIZE - 1) - tsec = position / REAL(SAMPLING_RATE) - - call mskrtd(buffer, params%nutc, tsec, params%ntol, params%nfqso, params%ndepth, & - mycall, hiscall, bshmsg, btrain, pcoeffs, bswl, data_dir, line) - - if (line(1:1) .ne. char(0)) then - line = line(1:index(line, char(0))-1) - write(*, 1001) line - 1001 format(a80) - message_count = message_count + 1; - end if - end do - - if (.not. params%ndiskdat) then - write(*, 1002) 0, message_count, 0 - 1002 format('', 2i4, i9) - end if - +subroutine decode_msk144(audio_samples, params, data_dir) + include 'jt9com.f90' + + ! constants + integer, parameter :: SAMPLING_RATE = 12000 + integer, parameter :: BLOCK_SIZE = 7168 + integer, parameter :: STEP_SIZE = BLOCK_SIZE / 2 + integer, parameter :: CALL_LENGTH = 12 + + ! aguments + integer*2 audio_samples(NMAX) + type(params_block) :: params + character(len = 500) :: data_dir + + ! parameters of mskrtd + integer*2 :: buffer(BLOCK_SIZE) + real :: tsec + logical :: bshmsg = .false. ! enables shorthand messages + logical :: btrain = .false. ! turns on training in MSK144 mode + real*8 :: pcoeffs(5) = (/ 0.0, 0.0, 0.0, 0.0, 0.0 /); ! phase equalization + logical :: bswl = .false. + character(len = 80) :: line + character(len = CALL_LENGTH) :: mycall + character(len = CALL_LENGTH) :: hiscall + + ! local variables + integer :: sample_count + integer :: position + integer :: message_count = 0 + + + ! decode in 0.3s blocks + sample_count = params%ntr * SAMPLING_RATE + mycall = transfer(params%mycall, mycall) ! string to char[] + hiscall = transfer(params%hiscall, hiscall) + + do position = 1, sample_count - BLOCK_SIZE + 1, STEP_SIZE + buffer = audio_samples(position : position + BLOCK_SIZE - 1) + tsec = position / REAL(SAMPLING_RATE) + + call mskrtd(buffer, params%nutc, tsec, params%ntol, params%nfqso, params%ndepth, & + mycall, hiscall, bshmsg, btrain, pcoeffs, bswl, data_dir, line) + + if (line(1:1) .ne. char(0)) then + line = line(1:index(line, char(0))-1) + write(*, 1001) line + 1001 format(a80) + message_count = message_count + 1; + end if + end do + + if (.not. params%ndiskdat) then + write(*, 1002) 0, message_count, 0 + 1002 format('', 2i4, i9) + end if + end subroutine decode_msk144 \ No newline at end of file diff --git a/lib/decode_rs.c b/lib/decode_rs.c index 6705e40f..53b441d3 100755 --- a/lib/decode_rs.c +++ b/lib/decode_rs.c @@ -1,263 +1,263 @@ -/* Reed-Solomon decoder - * Copyright 2002 Phil Karn, KA9Q - * May be used under the terms of the GNU General Public License (GPL) - */ - -#ifdef DEBUG -#include -#endif - -#include -#include - -#define min(a,b) ((a) < (b) ? (a) : (b)) - -#ifdef FIXED -#include "fixed.h" -#elif defined(BIGSYM) -#include "int.h" -#else -#include "char.h" -#endif - -int DECODE_RS( -#ifdef FIXED -DTYPE *data, int *eras_pos, int no_eras,int pad){ -#else -void *p,DTYPE *data, int *eras_pos, int no_eras){ - struct rs *rs = (struct rs *)p; -#endif - int deg_lambda, el, deg_omega; - int i, j, r,k; - DTYPE u,q,tmp,num1,num2,den,discr_r; - DTYPE lambda[NROOTS+1], s[NROOTS]; /* Err+Eras Locator poly - * and syndrome poly */ - DTYPE b[NROOTS+1], t[NROOTS+1], omega[NROOTS+1]; - DTYPE root[NROOTS], reg[NROOTS+1], loc[NROOTS]; - int syn_error, count; - -#ifdef FIXED - /* Check pad parameter for validity */ - if(pad < 0 || pad >= NN) - return -1; -#endif - - /* form the syndromes; i.e., evaluate data(x) at roots of g(x) */ - for(i=0;i 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 0; j--){ - if (reg[j] != A0) { - reg[j] = MODNN(reg[j] + j); - q ^= ALPHA_TO[reg[j]]; - } - } - if (q != 0) - continue; /* Not a root */ - /* store root (index-form) and error location number */ -#if DEBUG>=2 - printf("count %d root %d loc %d\n",count,i,k); -#endif - root[count] = i; - loc[count] = k; - /* If we've already found max possible roots, - * abort the search to save time - */ - if(++count == deg_lambda) - break; - } - if (deg_lambda != count) { - /* - * deg(lambda) unequal to number of roots => uncorrectable - * error detected - */ - count = -1; - goto finish; - } - /* - * Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo - * x**NROOTS). in index form. Also find deg(omega). - */ - deg_omega = deg_lambda-1; - for (i = 0; i <= deg_omega;i++){ - tmp = 0; - for(j=i;j >= 0; j--){ - if ((s[i - j] != A0) && (lambda[j] != A0)) - tmp ^= ALPHA_TO[MODNN(s[i - j] + lambda[j])]; - } - omega[i] = INDEX_OF[tmp]; - } - - /* - * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 = - * inv(X(l))**(FCR-1) and den = lambda_pr(inv(X(l))) all in poly-form - */ - for (j = count-1; j >=0; j--) { - num1 = 0; - for (i = deg_omega; i >= 0; i--) { - if (omega[i] != A0) - num1 ^= ALPHA_TO[MODNN(omega[i] + i * root[j])]; - } - num2 = ALPHA_TO[MODNN(root[j] * (FCR - 1) + NN)]; - den = 0; - - /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */ - for (i = min(deg_lambda,NROOTS-1) & ~1; i >= 0; i -=2) { - if(lambda[i+1] != A0) - den ^= ALPHA_TO[MODNN(lambda[i+1] + i * root[j])]; - } -#if DEBUG >= 1 - if (den == 0) { - printf("\n ERROR: denominator = 0\n"); - count = -1; - goto finish; - } -#endif - /* Apply error to data */ - if (num1 != 0 && loc[j] >= PAD) { - data[loc[j]-PAD] ^= ALPHA_TO[MODNN(INDEX_OF[num1] + INDEX_OF[num2] + NN - INDEX_OF[den])]; - } - } - finish: - if(eras_pos != NULL){ - for(i=0;i +#endif + +#include +#include + +#define min(a,b) ((a) < (b) ? (a) : (b)) + +#ifdef FIXED +#include "fixed.h" +#elif defined(BIGSYM) +#include "int.h" +#else +#include "char.h" +#endif + +int DECODE_RS( +#ifdef FIXED +DTYPE *data, int *eras_pos, int no_eras,int pad){ +#else +void *p,DTYPE *data, int *eras_pos, int no_eras){ + struct rs *rs = (struct rs *)p; +#endif + int deg_lambda, el, deg_omega; + int i, j, r,k; + DTYPE u,q,tmp,num1,num2,den,discr_r; + DTYPE lambda[NROOTS+1], s[NROOTS]; /* Err+Eras Locator poly + * and syndrome poly */ + DTYPE b[NROOTS+1], t[NROOTS+1], omega[NROOTS+1]; + DTYPE root[NROOTS], reg[NROOTS+1], loc[NROOTS]; + int syn_error, count; + +#ifdef FIXED + /* Check pad parameter for validity */ + if(pad < 0 || pad >= NN) + return -1; +#endif + + /* form the syndromes; i.e., evaluate data(x) at roots of g(x) */ + for(i=0;i 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 0; j--){ + if (reg[j] != A0) { + reg[j] = MODNN(reg[j] + j); + q ^= ALPHA_TO[reg[j]]; + } + } + if (q != 0) + continue; /* Not a root */ + /* store root (index-form) and error location number */ +#if DEBUG>=2 + printf("count %d root %d loc %d\n",count,i,k); +#endif + root[count] = i; + loc[count] = k; + /* If we've already found max possible roots, + * abort the search to save time + */ + if(++count == deg_lambda) + break; + } + if (deg_lambda != count) { + /* + * deg(lambda) unequal to number of roots => uncorrectable + * error detected + */ + count = -1; + goto finish; + } + /* + * Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo + * x**NROOTS). in index form. Also find deg(omega). + */ + deg_omega = deg_lambda-1; + for (i = 0; i <= deg_omega;i++){ + tmp = 0; + for(j=i;j >= 0; j--){ + if ((s[i - j] != A0) && (lambda[j] != A0)) + tmp ^= ALPHA_TO[MODNN(s[i - j] + lambda[j])]; + } + omega[i] = INDEX_OF[tmp]; + } + + /* + * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 = + * inv(X(l))**(FCR-1) and den = lambda_pr(inv(X(l))) all in poly-form + */ + for (j = count-1; j >=0; j--) { + num1 = 0; + for (i = deg_omega; i >= 0; i--) { + if (omega[i] != A0) + num1 ^= ALPHA_TO[MODNN(omega[i] + i * root[j])]; + } + num2 = ALPHA_TO[MODNN(root[j] * (FCR - 1) + NN)]; + den = 0; + + /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */ + for (i = min(deg_lambda,NROOTS-1) & ~1; i >= 0; i -=2) { + if(lambda[i+1] != A0) + den ^= ALPHA_TO[MODNN(lambda[i+1] + i * root[j])]; + } +#if DEBUG >= 1 + if (den == 0) { + printf("\n ERROR: denominator = 0\n"); + count = -1; + goto finish; + } +#endif + /* Apply error to data */ + if (num1 != 0 && loc[j] >= PAD) { + data[loc[j]-PAD] ^= ALPHA_TO[MODNN(INDEX_OF[num1] + INDEX_OF[num2] + NN - INDEX_OF[den])]; + } + } + finish: + if(eras_pos != NULL){ + for(i=0;i',2i4,i9) - call flush(6) - endif - close(13) - if(ncontest.eq.6) close(19) - if(params%nmode.eq.4 .or. params%nmode.eq.65 .or. params%nmode.eq.66) close(14) - return -contains - - subroutine jt4_decoded(this,snr,dt,freq,have_sync,sync,is_deep, & - decoded0,qual,ich,is_average,ave) - implicit none - class(jt4_decoder), intent(inout) :: this - integer, intent(in) :: snr - real, intent(in) :: dt - integer, intent(in) :: freq - logical, intent(in) :: have_sync - logical, intent(in) :: is_deep - character(len=1), intent(in) :: sync - character(len=22), intent(in) :: decoded0 - real, intent(in) :: qual - integer, intent(in) :: ich - logical, intent(in) :: is_average - integer, intent(in) :: ave - - character*22 decoded - character*3 cflags - - if(ich.eq.-99) stop !Silence compiler warning - if (have_sync) then - decoded=decoded0 - cflags=' ' - if(decoded.ne.' ') then - cflags='f ' - if(is_deep) then - cflags='d ' - write(cflags(2:2),'(i1)') min(int(qual),9) - if(qual.ge.10.0) cflags(2:2)='*' - if(qual.lt.3.0) decoded(22:22)='?' - endif - if(is_average) then - write(cflags(3:3),'(i1)') min(ave,9) - if(ave.ge.10) cflags(3:3)='*' - if(cflags(1:1).eq.'f') cflags=cflags(1:1)//cflags(3:3)//' ' - endif - endif - write(*,1000) params%nutc,snr,dt,freq,sync,decoded,cflags -1000 format(i4.4,i4,f5.1,i5,1x,'$',a1,1x,a22,1x,a3) - else - write(*,1000) params%nutc,snr,dt,freq - end if - - select type(this) - type is (counting_jt4_decoder) - this%decoded = this%decoded + 1 - end select - end subroutine jt4_decoded - - subroutine jt4_average (this, used, utc, sync, dt, freq, flip) - implicit none - class(jt4_decoder), intent(inout) :: this - logical, intent(in) :: used - integer, intent(in) :: utc - real, intent(in) :: sync - real, intent(in) :: dt - integer, intent(in) :: freq - logical, intent(in) :: flip - character(len=1) :: cused, csync - - cused = '.' - csync = '*' - if (used) cused = '$' - if (flip) csync = '$' - write(14,1000) cused,utc,sync,dt,freq,csync -1000 format(a1,i5.4,f6.1,f6.2,i6,1x,a1) - end subroutine jt4_average - - subroutine jt65_decoded(this,sync,snr,dt,freq,drift,nflip,width, & - decoded0,ft,qual,nsmo,nsum,minsync) - - use jt65_decode - implicit none - - class(jt65_decoder), intent(inout) :: this - real, intent(in) :: sync - integer, intent(in) :: snr - real, intent(in) :: dt - integer, intent(in) :: freq - integer, intent(in) :: drift - integer, intent(in) :: nflip - real, intent(in) :: width - character(len=22), intent(in) :: decoded0 - integer, intent(in) :: ft - integer, intent(in) :: qual - integer, intent(in) :: nsmo - integer, intent(in) :: nsum - integer, intent(in) :: minsync - - integer i,nap - logical is_deep,is_average - character decoded*22,csync*2,cflags*3 - - if(width.eq.-9999.0) stop !Silence compiler warning -!$omp critical(decode_results) - decoded=decoded0 - cflags=' ' - is_deep=ft.eq.2 - - if(ft.eq.0 .and. minsync.ge.0 .and. int(sync).lt.minsync) then - write(*,1010) params%nutc,snr,dt,freq - else - is_average=nsum.ge.2 - if(bVHF .and. ft.gt.0) then - cflags='f ' - if(is_deep) then - cflags='d ' - write(cflags(2:2),'(i1)') min(qual,9) - if(qual.ge.10) cflags(2:2)='*' - if(qual.lt.3) decoded(22:22)='?' - endif - if(is_average) then - write(cflags(3:3),'(i1)') min(nsum,9) - if(nsum.ge.10) cflags(3:3)='*' - endif - nap=ishft(ft,-2) - if(nap.ne.0) then - if(nsum.lt.2) write(cflags(1:3),'(a1,i1," ")') 'a',nap - if(nsum.ge.2) write(cflags(1:3),'(a1,2i1)') 'a',nap,min(nsum,9) - endif - endif - csync='# ' - i=0 - if(bVHF .and. nflip.ne.0 .and. & - sync.ge.max(0.0,float(minsync))) then - csync='#*' - if(nflip.eq.-1) then - csync='##' - if(decoded.ne.' ') then - do i=22,1,-1 - if(decoded(i:i).ne.' ') exit - enddo - if(i.gt.18) i=18 - decoded(i+2:i+4)='OOO' - endif - endif - endif - n=len(trim(decoded)) - if(n.eq.2 .or. n.eq.3) csync='# ' - if(cflags(1:1).eq.'f') then - cflags(2:2)=cflags(3:3) - cflags(3:3)=' ' - endif - write(*,1010) params%nutc,snr,dt,freq,csync,decoded,cflags -1010 format(i4.4,i4,f5.1,i5,1x,a2,1x,a22,1x,a3) - endif - if(ios13.eq.0) write(13,1012) params%nutc,nint(sync),snr,dt, & - float(freq),drift,decoded,ft,nsum,nsmo -1012 format(i4.4,i4,i5,f6.2,f8.0,i4,3x,a22,' JT65',3i3) - call flush(6) - -!$omp end critical(decode_results) - select type(this) - type is (counting_jt65_decoder) - this%decoded = this%decoded + 1 - end select - end subroutine jt65_decoded - - subroutine jt9_decoded (this, sync, snr, dt, freq, drift, decoded) - use jt9_decode - implicit none - - class(jt9_decoder), intent(inout) :: this - real, intent(in) :: sync - integer, intent(in) :: snr - real, intent(in) :: dt - real, intent(in) :: freq - integer, intent(in) :: drift - character(len=22), intent(in) :: decoded - - !$omp critical(decode_results) - write(*,1000) params%nutc,snr,dt,nint(freq),decoded -1000 format(i4.4,i4,f5.1,i5,1x,'@ ',1x,a22) - if(ios13.eq.0) write(13,1002) params%nutc,nint(sync),snr,dt,freq, & - drift,decoded -1002 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a22,' JT9') - call flush(6) - !$omp end critical(decode_results) - select type(this) - type is (counting_jt9_decoder) - this%decoded = this%decoded + 1 - end select - end subroutine jt9_decoded - - subroutine ft8_decoded (this,sync,snr,dt,freq,decoded,nap,qual) - use ft8_decode - implicit none - - class(ft8_decoder), intent(inout) :: this - real, intent(in) :: sync - integer, intent(in) :: snr - real, intent(in) :: dt - real, intent(in) :: freq - character(len=37), intent(in) :: decoded - character c1*12,c2*12,g2*4,w*4 - integer i0,i1,i2,i3,i4,i5,n30,nwrap - integer, intent(in) :: nap - real, intent(in) :: qual - character*2 annot - character*37 decoded0 - logical isgrid4,first,b0,b1,b2 - data first/.true./ - save - - isgrid4(w)=(len_trim(w).eq.4 .and. & - ichar(w(1:1)).ge.ichar('A') .and. ichar(w(1:1)).le.ichar('R') .and. & - ichar(w(2:2)).ge.ichar('A') .and. ichar(w(2:2)).le.ichar('R') .and. & - ichar(w(3:3)).ge.ichar('0') .and. ichar(w(3:3)).le.ichar('9') .and. & - ichar(w(4:4)).ge.ichar('0') .and. ichar(w(4:4)).le.ichar('9')) - - if(first) then - c2fox=' ' - g2fox=' ' - nsnrfox=-99 - nfreqfox=-99 - n30z=0 - nwrap=0 - nfox=0 - first=.false. - endif - - decoded0=decoded - - annot=' ' - if(nap.ne.0) then - write(annot,'(a1,i1)') 'a',nap - if(qual.lt.0.17) decoded0(37:37)='?' - endif - -! i0=index(decoded0,';') -! Always print 37 characters? Or, send i3,n3 up to here from ft8b_2 and use them -! to decide how many chars to print? -!TEMP - i0=1 - if(i0.le.0) write(*,1000) params%nutc,snr,dt,nint(freq),decoded0(1:22),annot -1000 format(i6.6,i4,f5.1,i5,' ~ ',1x,a22,1x,a2) - if(i0.gt.0) write(*,1001) params%nutc,snr,dt,nint(freq),decoded0,annot -1001 format(i6.6,i4,f5.1,i5,' ~ ',1x,a37,1x,a2) - if(ios13.eq.0) write(13,1002) params%nutc,nint(sync),snr,dt,freq,0,decoded0 -1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' FT8') - - if(ncontest.eq.6) then - i1=index(decoded0,' ') - i2=i1 + index(decoded0(i1+1:),' ') - i3=i2 + index(decoded0(i2+1:),' ') - if(i1.ge.3 .and. i2.ge.7 .and. i3.ge.10) then - c1=decoded0(1:i1-1)//' ' - c2=decoded0(i1+1:i2-1) - g2=decoded0(i2+1:i3-1) - b0=c1.eq.mycall - if(c1(1:3).eq.'DE ' .and. index(c2,'/').ge.2) b0=.true. - if(len(trim(c1)).ne.len(trim(mycall))) then - i4=index(trim(c1),trim(mycall)) - i5=index(trim(mycall),trim(c1)) - if(i4.ge.1 .or. i5.ge.1) b0=.true. - endif - b1=i3-i2.eq.5 .and. isgrid4(g2) - b2=i3-i2.eq.1 - if(b0 .and. (b1.or.b2) .and. (nint(freq).ge.1000 .or. params%b_superfox)) then - n=params%nutc - n30=(3600*(n/10000) + 60*mod((n/100),100) + mod(n,100))/30 - if(n30.lt.n30z) nwrap=nwrap+2880 !New UTC day, handle the wrap - n30z=n30 - n30=n30+nwrap - if(nfox.lt.MAXFOX) nfox=nfox+1 - c2fox(nfox)=c2 - g2fox(nfox)=g2 - nsnrfox(nfox)=snr - nfreqfox(nfox)=nint(freq) - n30fox(nfox)=n30 - endif - endif - endif - - call flush(6) - if(ios13.eq.0) call flush(13) - - select type(this) - type is (counting_ft8_decoder) - this%decoded = this%decoded + 1 - end select - - return - end subroutine ft8_decoded - - subroutine ft4_decoded (this,sync,snr,dt,freq,decoded,nap,qual) - use ft4_decode - implicit none - - class(ft4_decoder), intent(inout) :: this - real, intent(in) :: sync - integer, intent(in) :: snr - real, intent(in) :: dt - real, intent(in) :: freq - character(len=37), intent(in) :: decoded - integer, intent(in) :: nap - real, intent(in) :: qual - character*2 annot - character*37 decoded0 - - decoded0=decoded - - annot=' ' - if(nap.ne.0) then - write(annot,'(a1,i1)') 'a',nap - if(qual.lt.0.17) decoded0(37:37)='?' - endif - - write(*,1001) params%nutc,snr,dt,nint(freq),decoded0,annot -1001 format(i6.6,i4,f5.1,i5,' + ',1x,a37,1x,a2) - - if(ios13.eq.0) then - write(13,1002,err=10) params%nutc,nint(sync),snr,dt,freq,0,decoded0 -1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' FT4') - flush(13) - endif - -10 call flush(6) - - select type(this) - type is (counting_ft4_decoder) - this%decoded = this%decoded + 1 - end select - - return - end subroutine ft4_decoded - - subroutine fst4_decoded (this,nutc,sync,nsnr,dt,freq,decoded,nap, & - qual,ntrperiod,fmid,w50) - - use fst4_decode - implicit none - - class(fst4_decoder), intent(inout) :: this - integer, intent(in) :: nutc - real, intent(in) :: sync - integer, intent(in) :: nsnr - real, intent(in) :: dt - real, intent(in) :: freq - character(len=37), intent(in) :: decoded - integer, intent(in) :: nap - real, intent(in) :: qual - integer, intent(in) :: ntrperiod - real, intent(in) :: fmid - real, intent(in) :: w50 - - character*2 annot - character*37 decoded0 - character*70 line - - decoded0=decoded - annot=' ' - if(nap.ne.0) then - write(annot,'(a1,i1)') 'a',nap - if(qual.lt.0.17) decoded0(37:37)='?' - endif - - if(ntrperiod.lt.60) then - write(line,1001) nutc,nsnr,dt,nint(freq),decoded0,annot -1001 format(i6.6,i4,f5.1,i5,' ` ',1x,a37,1x,a2) - if(ios13.eq.0) write(13,1002) nutc,nint(sync),nsnr,dt,freq,0,decoded0 -1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' FST4') - else - write(line,1003) nutc,nsnr,dt,nint(freq),decoded0,annot -1003 format(i4.4,i4,f5.1,i5,' ` ',1x,a37,1x,a2,2f7.3) - if(ios13.eq.0) write(13,1004) nutc,nint(sync),nsnr,dt,freq,0,decoded0 -1004 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a37,' FST4') - endif - - if(fmid.ne.-999.0) then - if(w50.lt.0.95) write(line(65:70),'(f6.3)') w50 - if(w50.ge.0.95) write(line(65:70),'(f6.2)') w50 - endif - - write(*,1005) line -1005 format(a70) - - call flush(6) - if(ios13.eq.0) call flush(13) - - select type(this) - type is (counting_fst4_decoder) - this%decoded = this%decoded + 1 - end select - - return - end subroutine fst4_decoded - - subroutine q65_decoded (this,nutc,snr1,nsnr,dt,freq,decoded,idec, & - nused,ntrperiod) - - use q65_decode - implicit none - - class(q65_decoder), intent(inout) :: this - integer, intent(in) :: nutc - real, intent(in) :: snr1 - integer, intent(in) :: nsnr - real, intent(in) :: dt - real, intent(in) :: freq - character(len=37), intent(in) :: decoded - integer, intent(in) :: idec - integer, intent(in) :: nused - integer, intent(in) :: ntrperiod - character*3 cflags - - cflags=' ' - if(idec.ge.0) then - cflags='q ' - write(cflags(2:2),'(i1)') idec - if(nused.ge.2) write(cflags(3:3),'(i1)') nused - endif - - if(ntrperiod.lt.60) then - write(*,1001) nutc,nsnr,dt,nint(freq),decoded,cflags -1001 format(i6.6,i4,f5.1,i5,' : ',1x,a37,1x,a3) - if(ios13.eq.0) write(13,1002) nutc,nint(snr1),nsnr,dt,freq,0,decoded -1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' Q65') - else - write(*,1003) nutc,nsnr,dt,nint(freq),decoded,cflags -1003 format(i4.4,i4,f5.1,i5,' : ',1x,a37,1x,a3) - if(ios13.eq.0) write(13,1004) nutc,nint(snr1),nsnr,dt,freq,0,decoded -1004 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a37,' Q65') - - endif - call flush(6) - if(ios13.eq.0) call flush(13) - - select type(this) - type is (counting_q65_decoder) - if(idec.ge.0) this%decoded = this%decoded + 1 - end select - - return - end subroutine q65_decoded - -end subroutine multimode_decoder +subroutine multimode_decoder(ss,id2,params,nfsample) + +!$ use omp_lib + use prog_args + use timer_module, only: timer + use jt4_decode + use jt65_decode + use jt9_decode + use ft8_decode + use ft4_decode + use fst4_decode + use q65_decode + + include 'jt9com.f90' + include 'timer_common.inc' + + type, extends(jt4_decoder) :: counting_jt4_decoder + integer :: decoded + end type counting_jt4_decoder + + type, extends(jt65_decoder) :: counting_jt65_decoder + integer :: decoded + end type counting_jt65_decoder + + type, extends(jt9_decoder) :: counting_jt9_decoder + integer :: decoded + end type counting_jt9_decoder + + type, extends(ft8_decoder) :: counting_ft8_decoder + integer :: decoded + end type counting_ft8_decoder + + type, extends(ft4_decoder) :: counting_ft4_decoder + integer :: decoded + end type counting_ft4_decoder + + type, extends(fst4_decoder) :: counting_fst4_decoder + integer :: decoded + end type counting_fst4_decoder + + type, extends(q65_decoder) :: counting_q65_decoder + integer :: decoded + end type counting_q65_decoder + + real ss(184,NSMAX) + logical baddata,newdat65,newdat9,single_decode,bVHF,bad0,newdat,ex + logical lprinthash22 + integer*2 id2(NTMAX*12000) + integer nqf(20) + type(params_block) :: params + real*4 dd(NTMAX*12000) + character(len=20) :: datetime + character(len=12) :: mycall, hiscall + character(len=6) :: mygrid, hisgrid + character*60 line + data ndec8/0/,ntr0/-1/ + save + type(counting_jt4_decoder) :: my_jt4 + type(counting_jt65_decoder) :: my_jt65 + type(counting_jt9_decoder) :: my_jt9 + type(counting_ft8_decoder) :: my_ft8 + type(counting_ft4_decoder) :: my_ft4 + type(counting_fst4_decoder) :: my_fst4 + type(counting_q65_decoder) :: my_q65 + + if(.not.params%newdat .and. params%ntr.gt.ntr0) go to 800 + ntr0=params%ntr + rms=sqrt(dot_product(float(id2(1:180000)), & + float(id2(1:180000)))/180000.0) + if(rms.lt.0.5) go to 800 + + !cast C character arrays to Fortran character strings + datetime=transfer(params%datetime, datetime) + mycall=transfer(params%mycall,mycall) + hiscall=transfer(params%hiscall,hiscall) + mygrid=transfer(params%mygrid,mygrid) + hisgrid=transfer(params%hisgrid,hisgrid) + + ! initialize decode counts + my_jt4%decoded = 0 + my_jt65%decoded = 0 + my_jt9%decoded = 0 + my_ft8%decoded = 0 + my_ft4%decoded = 0 + my_fst4%decoded = 0 + my_q65%decoded = 0 + +! For testing only: return Rx messages stored in a file as decodes + inquire(file='rx_messages.txt',exist=ex) + if(ex) then + if(params%nzhsym.eq.41) then + open(39,file='rx_messages.txt',status='old') + do i=1,9999 + read(39,'(a60)',end=5) line + if(line(1:1).eq.' ' .or. line(1:1).eq.'-') go to 800 + write(*,'(a)') trim(line) + enddo +5 close(39) + endif + go to 800 + endif + + ncontest=iand(params%nexp_decode,7) + single_decode=iand(params%nexp_decode,32).ne.0 + bVHF=iand(params%nexp_decode,64).ne.0 + if(mod(params%nranera,2).eq.0) ntrials=10**(params%nranera/2) + if(mod(params%nranera,2).eq.1) ntrials=3*10**(params%nranera/2) + if(params%nranera.eq.0) ntrials=0 + + nfail=0 +10 if (params%nagain) then + open(13,file=trim(temp_dir)//'/decoded.txt',status='unknown', & + position='append',iostat=ios13) + else + open(13,file=trim(temp_dir)//'/decoded.txt',status='unknown',iostat=ios13) + endif + if(ios13.ne.0) then + nfail=nfail+1 + if(nfail.le.3) then + call sleep_msec(10) + go to 10 + endif + endif + + if(params%nmode.eq.8) then +! We're in FT8 mode + if(ncontest.eq.6) then !Fox=6, Hound=7 +! Fox mode: initialize and open houndcallers.txt + inquire(file=trim(temp_dir)//'/houndcallers.txt',exist=ex) + if(.not.ex) then + c2fox=' ' + g2fox=' ' + nsnrfox=-99 + nfreqfox=-99 + n30z=0 + nwrap=0 + nfox=0 + endif + open(19,file=trim(temp_dir)//'/houndcallers.txt',status='unknown') + endif + + if(ncontest.eq.7 .and. params%b_superfox .and. params%b_even_seq) then + if(params%nzhsym.lt.50) go to 800 +! Call the superFox decoder + call sfrx_sub(params%yymmdd,params%nutc,params%nfqso,params%ntol,id2) + else + call timer('decft8 ',0) + newdat=params%newdat + if(params%emedelay.ne.0.0) then + id2(1:156000)=id2(24001:180000) ! Drop the first 2 seconds of data + id2(156001:180000)=0 + endif + call my_ft8%decode(ft8_decoded,id2,params%nQSOProgress,params%nfqso, & + params%nftx,newdat,params%nutc,params%nfa,params%nfb, & + params%nzhsym,params%ndepth,params%emedelay,ncontest, & + logical(params%nagain),logical(params%lft8apon), & + logical(params%lapcqonly),params%napwid,mycall,hiscall, & + params%ndiskdat) + call timer('decft8 ',1) + endif + j=0 + + if(ncontest.eq.6) then +! Fox mode: save decoded Hound calls for possible selection by FoxOp + + n=params%nutc + n30=(3600*(n/10000) + 60*mod((n/100),100) + mod(n,100))/30 + if(n30.lt.n30z) nwrap=nwrap+2880 !New UTC day, handle the wrap + n30z=n30 + n30=n30+nwrap + + rewind 19 + if(nfox.eq.0) then + endfile 19 + rewind 19 + else + do i=1,nfox + n=n30fox(i) + nage=min(99,mod(n30-n+288000,2880)) + if(nage.le.4) then + j=j+1 + c2fox(j)=c2fox(i) + g2fox(j)=g2fox(i) + nsnrfox(j)=nsnrfox(i) + nfreqfox(j)=nfreqfox(i) + n30fox(j)=n + ! nage=min(99,mod(n30-n+288000,2880)) + if(len(trim(g2fox(j))).eq.4) then + call azdist(mygrid,g2fox(j)//' ',0.d0,nAz,nEl,nDmiles, & + nDkm,nHotAz,nHotABetter) + else + nDkm=9999 + endif + write(19,1004) c2fox(j),g2fox(j),nsnrfox(j),nfreqfox(j), & + nDkm,nage +1004 format(a12,1x,a4,i5,i6,i7,i3) + endif + enddo + nfox=j + flush(19) + endif + endif + go to 800 + endif + + if(params%nmode.eq.5) then + call timer('decft4 ',0) + call my_ft4%decode(ft4_decoded,id2,params%nQSOProgress,params%nfqso, & + params%nfa,params%nfb,params%ndepth, & + logical(params%lapcqonly),ncontest,mycall,hiscall) + call timer('decft4 ',1) + go to 800 + endif + + if(params%nmode.eq.66) then !NB: JT65 = 65, Q65 = 66. +! We're in Q65 mode + open(17,file=trim(temp_dir)//'/red.dat',status='unknown') + open(14,file=trim(temp_dir)//'/avemsg.txt',status='unknown') + call timer('dec_q65 ',0) + nqd=1 + call my_q65%decode(q65_decoded,id2,nqd,params%nutc,params%ntr, & + params%nsubmode,params%nfqso,params%ntol,params%ndepth, & + params%nfa,params%nfb,logical(params%nclearave), & + single_decode,logical(params%nagain),params%max_drift, & + logical(params%newdat),params%emedelay,mycall,hiscall,hisgrid, & + params%nQSOProgress,ncontest,logical(params%lapcqonly),navg0,nqf) + params%nclearave=.false. + + if(.not.params%nagain) then +! Go through identified candidates again, treating each as if it had been +! double-clicked on the waterfall. + do k=1,20 + if(nqf(k).eq.0) exit + if(params%nagain .and. abs(nqf(k)-params%nfqso).gt.params%ntol) cycle + nqd=1 + navg0=0 + ntol=5 + call my_q65%decode(q65_decoded,id2,nqd,params%nutc,params%ntr, & + params%nsubmode,nqf(k),ntol,params%ndepth, & + params%nfa,params%nfb,logical(params%nclearave), & + .true.,.true.,params%max_drift, & + .false.,params%emedelay,mycall,hiscall,hisgrid, & + params%nQSOProgress,ncontest,logical(params%lapcqonly), & + navg0,nqf) + enddo + endif + + call timer('dec_q65 ',1) + close(17) + go to 800 + endif + + if(params%nmode.eq.240) then +! We're in FST4 mode + ndepth=iand(params%ndepth,3) + iwspr=0 + lprinthash22=.false. + params%nsubmode=0 + call timer('dec_fst4',0) + call my_fst4%decode(fst4_decoded,id2,params%nutc, & + params%nQSOProgress,params%nfa,params%nfb, & + params%nfqso,ndepth,params%ntr,params%nexp_decode, & + params%ntol,params%emedelay,logical(params%nagain), & + logical(params%lapcqonly),mycall,hiscall,iwspr,lprinthash22) + call timer('dec_fst4',1) + go to 800 + endif + + if(params%nmode.eq.241 .or. params%nmode.eq.242) then +! We're in FST4W mode + ndepth=iand(params%ndepth,3) + iwspr=1 + lprinthash22=.false. + if(params%nmode.eq.242) lprinthash22=.true. + call timer('dec_fst4',0) + call my_fst4%decode(fst4_decoded,id2,params%nutc, & + params%nQSOProgress,params%nfa,params%nfb, & + params%nfqso,ndepth,params%ntr,params%nexp_decode, & + params%ntol,params%emedelay,logical(params%nagain), & + logical(params%lapcqonly),mycall,hiscall,iwspr,lprinthash22) + call timer('dec_fst4',1) + go to 800 + endif + +! Zap data at start that might come from T/R switching transient? + nadd=100 + k=0 + bad0=.false. + do i=1,240 + sq=0. + do n=1,nadd + k=k+1 + sq=sq + float(id2(k))**2 + enddo + rms=sqrt(sq/nadd) + if(rms.gt.10000.0) then + bad0=.true. + kbad=k + rmsbad=rms + endif + enddo + if(bad0) then + nz=min(NTMAX*12000,kbad+100) +! id2(1:nz)=0 ! temporarily disabled as it can breaak the JT9 decoder, maybe others + endif + + if(params%nmode.eq.4 .or. params%nmode.eq.65) open(14,file=trim(temp_dir)// & + '/avemsg.txt',status='unknown') + + if(params%nmode.eq.4) then + jz=52*nfsample + if(params%newdat) then + if(nfsample.eq.12000) call wav11(id2,jz,dd) + if(nfsample.eq.11025) dd(1:jz)=id2(1:jz) + else + jz=52*11025 + endif + call my_jt4%decode(jt4_decoded,dd,jz,params%nutc,params%nfqso, & + params%ntol,params%emedelay,params%dttol,logical(params%nagain), & + params%ndepth,logical(params%nclearave),params%minsync, & + params%minw,params%nsubmode,mycall,hiscall, & + hisgrid,params%nlist,params%listutc,jt4_average) + go to 800 + endif + + npts65=52*12000 + if(baddata(id2,npts65)) then + nsynced=0 + ndecoded=0 + go to 800 + endif + + ntol65=params%ntol !### is this OK? ### + newdat65=params%newdat + newdat9=params%newdat + +!$call omp_set_dynamic(.true.) +!$omp parallel sections num_threads(2) copyin(/timer_private/) shared(ndecoded) if(.true.) !iif() needed on Mac + +!$omp section + if(params%nmode.eq.65) then +! We're in JT65 mode + + if(newdat65) dd(1:npts65)=id2(1:npts65) + nf1=params%nfa + nf2=params%nfb + call timer('jt65a ',0) + call my_jt65%decode(jt65_decoded,dd,npts65,newdat65,params%nutc, & + nf1,nf2,params%nfqso,ntol65,params%nsubmode,params%minsync, & + logical(params%nagain),params%n2pass,logical(params%nrobust), & + ntrials,params%naggressive,params%ndepth,params%emedelay, & + logical(params%nclearave),mycall,hiscall, & + hisgrid,params%nexp_decode,params%nQSOProgress, & + logical(params%ljt65apon)) + call timer('jt65a ',1) + + else if(params%nmode.eq.9 .or. (params%nmode.eq.(65+9) .and. params%ntxmode.eq.9)) then +! We're in JT9 mode, or should do JT9 first + call timer('decjt9 ',0) + call my_jt9%decode(jt9_decoded,ss,id2,params%nfqso, & + newdat9,params%npts8,params%nfa,params%nfsplit,params%nfb, & + params%ntol,params%nzhsym,logical(params%nagain),params%ndepth, & + params%nmode,params%nsubmode,params%nexp_decode) + call timer('decjt9 ',1) + endif + +!$omp section + if(params%nmode.eq.(65+9)) then !Do the other mode (we're in dual mode) + if (params%ntxmode.eq.9) then + if(newdat65) dd(1:npts65)=id2(1:npts65) + nf1=params%nfa + nf2=params%nfb + call timer('jt65a ',0) + call my_jt65%decode(jt65_decoded,dd,npts65,newdat65,params%nutc, & + nf1,nf2,params%nfqso,ntol65,params%nsubmode,params%minsync, & + logical(params%nagain),params%n2pass,logical(params%nrobust), & + ntrials,params%naggressive,params%ndepth,params%emedelay, & + logical(params%nclearave),mycall,hiscall, & + hisgrid,params%nexp_decode,params%nQSOProgress, & + logical(params%ljt65apon)) + call timer('jt65a ',1) + else + call timer('decjt9 ',0) + call my_jt9%decode(jt9_decoded,ss,id2,params%nfqso, & + newdat9,params%npts8,params%nfa,params%nfsplit,params%nfb, & + params%ntol,params%nzhsym,logical(params%nagain), & + params%ndepth,params%nmode,params%nsubmode,params%nexp_decode) + call timer('decjt9 ',1) + end if + endif + +!$omp end parallel sections + +! JT65 is not yet producing info for nsynced, ndecoded. +800 ndecoded = my_jt4%decoded + my_jt65%decoded + my_jt9%decoded + & + my_ft8%decoded + my_ft4%decoded + my_fst4%decoded + & + my_q65%decoded + if(params%nmode.eq.8 .and. params%nzhsym.eq.41) ndec41=ndecoded + if(params%nmode.eq.8 .and. params%nzhsym.eq.47) ndec47=ndecoded + if(params%nmode.eq.8 .and. params%nzhsym.eq.50) then + ndecoded=ndec41+ndec47+ndecoded + endif + if(params%nmode.ne.8 .or. params%nzhsym.eq.50 .or. & + .not.params%ndiskdat) then + + write(*,1010) nsynced,ndecoded,navg0 +1010 format('',2i4,i9) + call flush(6) + endif + close(13) + if(ncontest.eq.6) close(19) + if(params%nmode.eq.4 .or. params%nmode.eq.65 .or. params%nmode.eq.66) close(14) + return +contains + + subroutine jt4_decoded(this,snr,dt,freq,have_sync,sync,is_deep, & + decoded0,qual,ich,is_average,ave) + implicit none + class(jt4_decoder), intent(inout) :: this + integer, intent(in) :: snr + real, intent(in) :: dt + integer, intent(in) :: freq + logical, intent(in) :: have_sync + logical, intent(in) :: is_deep + character(len=1), intent(in) :: sync + character(len=22), intent(in) :: decoded0 + real, intent(in) :: qual + integer, intent(in) :: ich + logical, intent(in) :: is_average + integer, intent(in) :: ave + + character*22 decoded + character*3 cflags + + if(ich.eq.-99) stop !Silence compiler warning + if (have_sync) then + decoded=decoded0 + cflags=' ' + if(decoded.ne.' ') then + cflags='f ' + if(is_deep) then + cflags='d ' + write(cflags(2:2),'(i1)') min(int(qual),9) + if(qual.ge.10.0) cflags(2:2)='*' + if(qual.lt.3.0) decoded(22:22)='?' + endif + if(is_average) then + write(cflags(3:3),'(i1)') min(ave,9) + if(ave.ge.10) cflags(3:3)='*' + if(cflags(1:1).eq.'f') cflags=cflags(1:1)//cflags(3:3)//' ' + endif + endif + write(*,1000) params%nutc,snr,dt,freq,sync,decoded,cflags +1000 format(i4.4,i4,f5.1,i5,1x,'$',a1,1x,a22,1x,a3) + else + write(*,1000) params%nutc,snr,dt,freq + end if + + select type(this) + type is (counting_jt4_decoder) + this%decoded = this%decoded + 1 + end select + end subroutine jt4_decoded + + subroutine jt4_average (this, used, utc, sync, dt, freq, flip) + implicit none + class(jt4_decoder), intent(inout) :: this + logical, intent(in) :: used + integer, intent(in) :: utc + real, intent(in) :: sync + real, intent(in) :: dt + integer, intent(in) :: freq + logical, intent(in) :: flip + character(len=1) :: cused, csync + + cused = '.' + csync = '*' + if (used) cused = '$' + if (flip) csync = '$' + write(14,1000) cused,utc,sync,dt,freq,csync +1000 format(a1,i5.4,f6.1,f6.2,i6,1x,a1) + end subroutine jt4_average + + subroutine jt65_decoded(this,sync,snr,dt,freq,drift,nflip,width, & + decoded0,ft,qual,nsmo,nsum,minsync) + + use jt65_decode + implicit none + + class(jt65_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + integer, intent(in) :: freq + integer, intent(in) :: drift + integer, intent(in) :: nflip + real, intent(in) :: width + character(len=22), intent(in) :: decoded0 + integer, intent(in) :: ft + integer, intent(in) :: qual + integer, intent(in) :: nsmo + integer, intent(in) :: nsum + integer, intent(in) :: minsync + + integer i,nap + logical is_deep,is_average + character decoded*22,csync*2,cflags*3 + + if(width.eq.-9999.0) stop !Silence compiler warning +!$omp critical(decode_results) + decoded=decoded0 + cflags=' ' + is_deep=ft.eq.2 + + if(ft.eq.0 .and. minsync.ge.0 .and. int(sync).lt.minsync) then + write(*,1010) params%nutc,snr,dt,freq + else + is_average=nsum.ge.2 + if(bVHF .and. ft.gt.0) then + cflags='f ' + if(is_deep) then + cflags='d ' + write(cflags(2:2),'(i1)') min(qual,9) + if(qual.ge.10) cflags(2:2)='*' + if(qual.lt.3) decoded(22:22)='?' + endif + if(is_average) then + write(cflags(3:3),'(i1)') min(nsum,9) + if(nsum.ge.10) cflags(3:3)='*' + endif + nap=ishft(ft,-2) + if(nap.ne.0) then + if(nsum.lt.2) write(cflags(1:3),'(a1,i1," ")') 'a',nap + if(nsum.ge.2) write(cflags(1:3),'(a1,2i1)') 'a',nap,min(nsum,9) + endif + endif + csync='# ' + i=0 + if(bVHF .and. nflip.ne.0 .and. & + sync.ge.max(0.0,float(minsync))) then + csync='#*' + if(nflip.eq.-1) then + csync='##' + if(decoded.ne.' ') then + do i=22,1,-1 + if(decoded(i:i).ne.' ') exit + enddo + if(i.gt.18) i=18 + decoded(i+2:i+4)='OOO' + endif + endif + endif + n=len(trim(decoded)) + if(n.eq.2 .or. n.eq.3) csync='# ' + if(cflags(1:1).eq.'f') then + cflags(2:2)=cflags(3:3) + cflags(3:3)=' ' + endif + write(*,1010) params%nutc,snr,dt,freq,csync,decoded,cflags +1010 format(i4.4,i4,f5.1,i5,1x,a2,1x,a22,1x,a3) + endif + if(ios13.eq.0) write(13,1012) params%nutc,nint(sync),snr,dt, & + float(freq),drift,decoded,ft,nsum,nsmo +1012 format(i4.4,i4,i5,f6.2,f8.0,i4,3x,a22,' JT65',3i3) + call flush(6) + +!$omp end critical(decode_results) + select type(this) + type is (counting_jt65_decoder) + this%decoded = this%decoded + 1 + end select + end subroutine jt65_decoded + + subroutine jt9_decoded (this, sync, snr, dt, freq, drift, decoded) + use jt9_decode + implicit none + + class(jt9_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + real, intent(in) :: freq + integer, intent(in) :: drift + character(len=22), intent(in) :: decoded + + !$omp critical(decode_results) + write(*,1000) params%nutc,snr,dt,nint(freq),decoded +1000 format(i4.4,i4,f5.1,i5,1x,'@ ',1x,a22) + if(ios13.eq.0) write(13,1002) params%nutc,nint(sync),snr,dt,freq, & + drift,decoded +1002 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a22,' JT9') + call flush(6) + !$omp end critical(decode_results) + select type(this) + type is (counting_jt9_decoder) + this%decoded = this%decoded + 1 + end select + end subroutine jt9_decoded + + subroutine ft8_decoded (this,sync,snr,dt,freq,decoded,nap,qual) + use ft8_decode + implicit none + + class(ft8_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=37), intent(in) :: decoded + character c1*12,c2*12,g2*4,w*4 + integer i0,i1,i2,i3,i4,i5,n30,nwrap + integer, intent(in) :: nap + real, intent(in) :: qual + character*2 annot + character*37 decoded0 + logical isgrid4,first,b0,b1,b2 + data first/.true./ + save + + isgrid4(w)=(len_trim(w).eq.4 .and. & + ichar(w(1:1)).ge.ichar('A') .and. ichar(w(1:1)).le.ichar('R') .and. & + ichar(w(2:2)).ge.ichar('A') .and. ichar(w(2:2)).le.ichar('R') .and. & + ichar(w(3:3)).ge.ichar('0') .and. ichar(w(3:3)).le.ichar('9') .and. & + ichar(w(4:4)).ge.ichar('0') .and. ichar(w(4:4)).le.ichar('9')) + + if(first) then + c2fox=' ' + g2fox=' ' + nsnrfox=-99 + nfreqfox=-99 + n30z=0 + nwrap=0 + nfox=0 + first=.false. + endif + + decoded0=decoded + + annot=' ' + if(nap.ne.0) then + write(annot,'(a1,i1)') 'a',nap + if(qual.lt.0.17) decoded0(37:37)='?' + endif + +! i0=index(decoded0,';') +! Always print 37 characters? Or, send i3,n3 up to here from ft8b_2 and use them +! to decide how many chars to print? +!TEMP + i0=1 + if(i0.le.0) write(*,1000) params%nutc,snr,dt,nint(freq),decoded0(1:22),annot +1000 format(i6.6,i4,f5.1,i5,' ~ ',1x,a22,1x,a2) + if(i0.gt.0) write(*,1001) params%nutc,snr,dt,nint(freq),decoded0,annot +1001 format(i6.6,i4,f5.1,i5,' ~ ',1x,a37,1x,a2) + if(ios13.eq.0) write(13,1002) params%nutc,nint(sync),snr,dt,freq,0,decoded0 +1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' FT8') + + if(ncontest.eq.6) then + i1=index(decoded0,' ') + i2=i1 + index(decoded0(i1+1:),' ') + i3=i2 + index(decoded0(i2+1:),' ') + if(i1.ge.3 .and. i2.ge.7 .and. i3.ge.10) then + c1=decoded0(1:i1-1)//' ' + c2=decoded0(i1+1:i2-1) + g2=decoded0(i2+1:i3-1) + b0=c1.eq.mycall + if(c1(1:3).eq.'DE ' .and. index(c2,'/').ge.2) b0=.true. + if(len(trim(c1)).ne.len(trim(mycall))) then + i4=index(trim(c1),trim(mycall)) + i5=index(trim(mycall),trim(c1)) + if(i4.ge.1 .or. i5.ge.1) b0=.true. + endif + b1=i3-i2.eq.5 .and. isgrid4(g2) + b2=i3-i2.eq.1 + if(b0 .and. (b1.or.b2) .and. (nint(freq).ge.1000 .or. params%b_superfox)) then + n=params%nutc + n30=(3600*(n/10000) + 60*mod((n/100),100) + mod(n,100))/30 + if(n30.lt.n30z) nwrap=nwrap+2880 !New UTC day, handle the wrap + n30z=n30 + n30=n30+nwrap + if(nfox.lt.MAXFOX) nfox=nfox+1 + c2fox(nfox)=c2 + g2fox(nfox)=g2 + nsnrfox(nfox)=snr + nfreqfox(nfox)=nint(freq) + n30fox(nfox)=n30 + endif + endif + endif + + call flush(6) + if(ios13.eq.0) call flush(13) + + select type(this) + type is (counting_ft8_decoder) + this%decoded = this%decoded + 1 + end select + + return + end subroutine ft8_decoded + + subroutine ft4_decoded (this,sync,snr,dt,freq,decoded,nap,qual) + use ft4_decode + implicit none + + class(ft4_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=37), intent(in) :: decoded + integer, intent(in) :: nap + real, intent(in) :: qual + character*2 annot + character*37 decoded0 + + decoded0=decoded + + annot=' ' + if(nap.ne.0) then + write(annot,'(a1,i1)') 'a',nap + if(qual.lt.0.17) decoded0(37:37)='?' + endif + + write(*,1001) params%nutc,snr,dt,nint(freq),decoded0,annot +1001 format(i6.6,i4,f5.1,i5,' + ',1x,a37,1x,a2) + + if(ios13.eq.0) then + write(13,1002,err=10) params%nutc,nint(sync),snr,dt,freq,0,decoded0 +1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' FT4') + flush(13) + endif + +10 call flush(6) + + select type(this) + type is (counting_ft4_decoder) + this%decoded = this%decoded + 1 + end select + + return + end subroutine ft4_decoded + + subroutine fst4_decoded (this,nutc,sync,nsnr,dt,freq,decoded,nap, & + qual,ntrperiod,fmid,w50) + + use fst4_decode + implicit none + + class(fst4_decoder), intent(inout) :: this + integer, intent(in) :: nutc + real, intent(in) :: sync + integer, intent(in) :: nsnr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=37), intent(in) :: decoded + integer, intent(in) :: nap + real, intent(in) :: qual + integer, intent(in) :: ntrperiod + real, intent(in) :: fmid + real, intent(in) :: w50 + + character*2 annot + character*37 decoded0 + character*70 line + + decoded0=decoded + annot=' ' + if(nap.ne.0) then + write(annot,'(a1,i1)') 'a',nap + if(qual.lt.0.17) decoded0(37:37)='?' + endif + + if(ntrperiod.lt.60) then + write(line,1001) nutc,nsnr,dt,nint(freq),decoded0,annot +1001 format(i6.6,i4,f5.1,i5,' ` ',1x,a37,1x,a2) + if(ios13.eq.0) write(13,1002) nutc,nint(sync),nsnr,dt,freq,0,decoded0 +1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' FST4') + else + write(line,1003) nutc,nsnr,dt,nint(freq),decoded0,annot +1003 format(i4.4,i4,f5.1,i5,' ` ',1x,a37,1x,a2,2f7.3) + if(ios13.eq.0) write(13,1004) nutc,nint(sync),nsnr,dt,freq,0,decoded0 +1004 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a37,' FST4') + endif + + if(fmid.ne.-999.0) then + if(w50.lt.0.95) write(line(65:70),'(f6.3)') w50 + if(w50.ge.0.95) write(line(65:70),'(f6.2)') w50 + endif + + write(*,1005) line +1005 format(a70) + + call flush(6) + if(ios13.eq.0) call flush(13) + + select type(this) + type is (counting_fst4_decoder) + this%decoded = this%decoded + 1 + end select + + return + end subroutine fst4_decoded + + subroutine q65_decoded (this,nutc,snr1,nsnr,dt,freq,decoded,idec, & + nused,ntrperiod) + + use q65_decode + implicit none + + class(q65_decoder), intent(inout) :: this + integer, intent(in) :: nutc + real, intent(in) :: snr1 + integer, intent(in) :: nsnr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=37), intent(in) :: decoded + integer, intent(in) :: idec + integer, intent(in) :: nused + integer, intent(in) :: ntrperiod + character*3 cflags + + cflags=' ' + if(idec.ge.0) then + cflags='q ' + write(cflags(2:2),'(i1)') idec + if(nused.ge.2) write(cflags(3:3),'(i1)') nused + endif + + if(ntrperiod.lt.60) then + write(*,1001) nutc,nsnr,dt,nint(freq),decoded,cflags +1001 format(i6.6,i4,f5.1,i5,' : ',1x,a37,1x,a3) + if(ios13.eq.0) write(13,1002) nutc,nint(snr1),nsnr,dt,freq,0,decoded +1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a37,' Q65') + else + write(*,1003) nutc,nsnr,dt,nint(freq),decoded,cflags +1003 format(i4.4,i4,f5.1,i5,' : ',1x,a37,1x,a3) + if(ios13.eq.0) write(13,1004) nutc,nint(snr1),nsnr,dt,freq,0,decoded +1004 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a37,' Q65') + + endif + call flush(6) + if(ios13.eq.0) call flush(13) + + select type(this) + type is (counting_q65_decoder) + if(idec.ge.0) this%decoded = this%decoded + 1 + end select + + return + end subroutine q65_decoded + +end subroutine multimode_decoder diff --git a/lib/deep4.f90 b/lib/deep4.f90 index a3ab0af4..05f6732d 100755 --- a/lib/deep4.f90 +++ b/lib/deep4.f90 @@ -1,169 +1,169 @@ -subroutine deep4(sym0,neme,flip,mycall,hiscall,hisgrid,decoded,qual) - -! Deep search routine for JT4 - - use prog_args - parameter (MAXCALLS=7000,MAXRPT=63) - real*4 sym0(206),sym(206) - character callsign*12,grid*4,message*22,hisgrid*6,ceme*3 - character*12 mycall,hiscall - character mycall0*12,hiscall0*12,hisgrid0*6 - character*22 decoded - character*22 testmsg(2*MAXCALLS + 2 + MAXRPT) - character*15 callgrid(MAXCALLS) - character*180 line - character*4 rpt(MAXRPT) - integer ncode(206) - real*4 code(206,2*MAXCALLS + 2 + MAXRPT) - real pp(2*MAXCALLS + 2 + MAXRPT) - data neme0/-99/ - data rpt/'-01','-02','-03','-04','-05', & - '-06','-07','-08','-09','-10', & - '-11','-12','-13','-14','-15', & - '-16','-17','-18','-19','-20', & - '-21','-22','-23','-24','-25', & - '-26','-27','-28','-29','-30', & - 'R-01','R-02','R-03','R-04','R-05', & - 'R-06','R-07','R-08','R-09','R-10', & - 'R-11','R-12','R-13','R-14','R-15', & - 'R-16','R-17','R-18','R-19','R-20', & - 'R-21','R-22','R-23','R-24','R-25', & - 'R-26','R-27','R-28','R-29','R-30', & - 'RO','RRR','73'/ - save mycall0,hiscall0,hisgrid0,neme0,ntot,code,testmsg - - sym=sym0 - if(mycall.eq.mycall0 .and. hiscall.eq.hiscall0 .and. & - hisgrid.eq.hisgrid0 .and. neme.eq.neme0) go to 30 - - open(23,file=trim(data_dir)//'/CALL3.TXT',status='unknown') - 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 encode4(message,ncode) - code(1:206,k)=2*ncode(1:206)-1 - if(n.ge.2) then -! Insert CQ message - if(j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid - message='CQ '//callgrid(icall) - k=k+1 - testmsg(k)=message - call encode4(message,ncode) - code(1:206,k)=2*ncode(1:206)-1 - endif - enddo -10 continue - enddo - -20 continue - close(23) - ntot=k - -30 mycall0=mycall - hiscall0=hiscall - hisgrid0=hisgrid - neme0=neme - - sq=0. - do j=1,206 - sq=sq + sym(j)**2 - enddo - rms=sqrt(sq/206.0) - sym=sym/rms - - p1=-1.e30 - p2=-1.e30 - do k=1,ntot - pp(k)=0. -! Should re-instate the following: -! if(k.ge.2 .and. k.le.64 .and. flip.gt.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 - p=0. - do j=1,206 - p=p + code(j,k)*sym(j) - enddo - pp(k)=p - if(p.gt.p1) then - p1=p - ip1=k - endif - endif - enddo - - do i=1,ntot - if(pp(i).gt.p2 .and. testmsg(i).ne.testmsg(ip1)) p2=pp(i) - enddo - - qual=p1-max(1.15*p2,70.0) - -! ### DO NOT REMOVE ### - rewind 77 - if(ip1.ge.1 .and. ip1.le.2*MAXCALLS+2+MAXRPT) write(77,1001) p1,p2,ntot, & - rms,qual,ip1,testmsg(ip1) -1001 format(2f8.2,i8,2f8.2,i6,2x,a22) - call flush(77) - - if(qual.gt.1.0) then - decoded=testmsg(ip1) - else - decoded=' ' - qual=0. - endif - -! 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 - - return -end subroutine deep4 +subroutine deep4(sym0,neme,flip,mycall,hiscall,hisgrid,decoded,qual) + +! Deep search routine for JT4 + + use prog_args + parameter (MAXCALLS=7000,MAXRPT=63) + real*4 sym0(206),sym(206) + character callsign*12,grid*4,message*22,hisgrid*6,ceme*3 + character*12 mycall,hiscall + character mycall0*12,hiscall0*12,hisgrid0*6 + character*22 decoded + character*22 testmsg(2*MAXCALLS + 2 + MAXRPT) + character*15 callgrid(MAXCALLS) + character*180 line + character*4 rpt(MAXRPT) + integer ncode(206) + real*4 code(206,2*MAXCALLS + 2 + MAXRPT) + real pp(2*MAXCALLS + 2 + MAXRPT) + data neme0/-99/ + data rpt/'-01','-02','-03','-04','-05', & + '-06','-07','-08','-09','-10', & + '-11','-12','-13','-14','-15', & + '-16','-17','-18','-19','-20', & + '-21','-22','-23','-24','-25', & + '-26','-27','-28','-29','-30', & + 'R-01','R-02','R-03','R-04','R-05', & + 'R-06','R-07','R-08','R-09','R-10', & + 'R-11','R-12','R-13','R-14','R-15', & + 'R-16','R-17','R-18','R-19','R-20', & + 'R-21','R-22','R-23','R-24','R-25', & + 'R-26','R-27','R-28','R-29','R-30', & + 'RO','RRR','73'/ + save mycall0,hiscall0,hisgrid0,neme0,ntot,code,testmsg + + sym=sym0 + if(mycall.eq.mycall0 .and. hiscall.eq.hiscall0 .and. & + hisgrid.eq.hisgrid0 .and. neme.eq.neme0) go to 30 + + open(23,file=trim(data_dir)//'/CALL3.TXT',status='unknown') + 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 encode4(message,ncode) + code(1:206,k)=2*ncode(1:206)-1 + if(n.ge.2) then +! Insert CQ message + if(j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid + message='CQ '//callgrid(icall) + k=k+1 + testmsg(k)=message + call encode4(message,ncode) + code(1:206,k)=2*ncode(1:206)-1 + endif + enddo +10 continue + enddo + +20 continue + close(23) + ntot=k + +30 mycall0=mycall + hiscall0=hiscall + hisgrid0=hisgrid + neme0=neme + + sq=0. + do j=1,206 + sq=sq + sym(j)**2 + enddo + rms=sqrt(sq/206.0) + sym=sym/rms + + p1=-1.e30 + p2=-1.e30 + do k=1,ntot + pp(k)=0. +! Should re-instate the following: +! if(k.ge.2 .and. k.le.64 .and. flip.gt.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 + p=0. + do j=1,206 + p=p + code(j,k)*sym(j) + enddo + pp(k)=p + if(p.gt.p1) then + p1=p + ip1=k + endif + endif + enddo + + do i=1,ntot + if(pp(i).gt.p2 .and. testmsg(i).ne.testmsg(ip1)) p2=pp(i) + enddo + + qual=p1-max(1.15*p2,70.0) + +! ### DO NOT REMOVE ### + rewind 77 + if(ip1.ge.1 .and. ip1.le.2*MAXCALLS+2+MAXRPT) write(77,1001) p1,p2,ntot, & + rms,qual,ip1,testmsg(ip1) +1001 format(2f8.2,i8,2f8.2,i6,2x,a22) + call flush(77) + + if(qual.gt.1.0) then + decoded=testmsg(ip1) + else + decoded=' ' + qual=0. + endif + +! 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 + + return +end subroutine deep4 diff --git a/lib/deg2grid.f90 b/lib/deg2grid.f90 index ea94c0eb..4fdc2af3 100755 --- a/lib/deg2grid.f90 +++ b/lib/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=int(60.0*(180.0-dlong)/5.0) - n1=nlong/240 !20-degree field - n2=(nlong-240*n1)/24 !2 degree square - n3=nlong-240*n1-24*n2 !5 minute subsquare - grid(1:1)=char(ichar('A')+n1) - grid(3:3)=char(ichar('0')+n2) - grid(5:5)=char(ichar('a')+n3) - -! Convert to units of 2.5 min of latitude, working north from -90 deg. - nlat=int(60.0*(dlat+90)/2.5) - n1=nlat/240 !10-degree field - n2=(nlat-240*n1)/24 !1 degree square - n3=nlat-240*n1-24*n2 !2.5 minuts subsquare - grid(2:2)=char(ichar('A')+n1) - grid(4:4)=char(ichar('0')+n2) - grid(6:6)=char(ichar('a')+n3) - - return -end subroutine deg2grid +subroutine deg2grid(dlong0,dlat,grid) + + real dlong !West longitude (deg) + real dlat !Latitude (deg) + character grid*6 + + dlong=dlong0 + if(dlong.lt.-180.0) dlong=dlong+360.0 + if(dlong.gt.180.0) dlong=dlong-360.0 + +! Convert to units of 5 min of longitude, working east from 180 deg. + nlong=int(60.0*(180.0-dlong)/5.0) + n1=nlong/240 !20-degree field + n2=(nlong-240*n1)/24 !2 degree square + n3=nlong-240*n1-24*n2 !5 minute subsquare + grid(1:1)=char(ichar('A')+n1) + grid(3:3)=char(ichar('0')+n2) + grid(5:5)=char(ichar('a')+n3) + +! Convert to units of 2.5 min of latitude, working north from -90 deg. + nlat=int(60.0*(dlat+90)/2.5) + n1=nlat/240 !10-degree field + n2=(nlat-240*n1)/24 !1 degree square + n3=nlat-240*n1-24*n2 !2.5 minuts subsquare + grid(2:2)=char(ichar('A')+n1) + grid(4:4)=char(ichar('0')+n2) + grid(6:6)=char(ichar('a')+n3) + + return +end subroutine deg2grid diff --git a/lib/degrade_snr.f90 b/lib/degrade_snr.f90 index 86c85b87..fd5db5f1 100755 --- a/lib/degrade_snr.f90 +++ b/lib/degrade_snr.f90 @@ -1,21 +1,21 @@ -subroutine degrade_snr(d2,npts,db,bw) - -! Degrade S/N by specified number of dB. - - integer*2 d2(npts) - - p0=0. - do i=1,npts - x=d2(i) - p0=p0 + x*x - enddo - p0=p0/npts - if(bw.gt.0.0) p0=p0*6000.0/bw - s=sqrt(p0*(10.0**(0.1*db) - 1.0)) - fac=sqrt(p0/(p0+s*s)) - do i=1,npts - d2(i)=nint(fac*(d2(i) + s*gran())) - enddo - - return -end subroutine degrade_snr +subroutine degrade_snr(d2,npts,db,bw) + +! Degrade S/N by specified number of dB. + + integer*2 d2(npts) + + p0=0. + do i=1,npts + x=d2(i) + p0=p0 + x*x + enddo + p0=p0/npts + if(bw.gt.0.0) p0=p0*6000.0/bw + s=sqrt(p0*(10.0**(0.1*db) - 1.0)) + fac=sqrt(p0/(p0+s*s)) + do i=1,npts + d2(i)=nint(fac*(d2(i) + s*gran())) + enddo + + return +end subroutine degrade_snr diff --git a/lib/demod64a.f90 b/lib/demod64a.f90 index 266a7654..b1176efb 100755 --- a/lib/demod64a.f90 +++ b/lib/demod64a.f90 @@ -1,61 +1,61 @@ -subroutine demod64a(s3,nadd,afac1,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),afac1 - integer mrsym(63),mrprob(63),mr2sym(63),mr2prob(63) - - if(nadd.eq.-999) return - afac=afac1 * float(nadd)**0.64 - scale=255.999 - -! Compute average spectral value - ave=sum(s3)/(64.*63.) - i1=1 !Silence warning - i2=1 - -! Compute probabilities for most reliable symbol values - do j=1,63 - s1=-1.e30 - psum=0. - do i=1,64 - x=min(afac*s3(i,j)/ave,50.d0) - psum=psum+s3(i,j) - if(s3(i,j).gt.s1) then - s1=s3(i,j) - i1=i !Most reliable - endif - enddo - if(psum.eq.0.0) psum=1.e-6 - - 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=s1/psum !Symbol metrics for ftrsd - p2=s2/psum - mrsym(j)=i1-1 - mr2sym(j)=i2-1 - mrprob(j)=scale*p1 - mr2prob(j)=scale*p2 - enddo - - nlow=0 - do j=1,63 - if(mrprob(j).le.5) nlow=nlow+1 - enddo - ntest=sum(mrprob) - - return -end subroutine demod64a +subroutine demod64a(s3,nadd,afac1,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),afac1 + integer mrsym(63),mrprob(63),mr2sym(63),mr2prob(63) + + if(nadd.eq.-999) return + afac=afac1 * float(nadd)**0.64 + scale=255.999 + +! Compute average spectral value + ave=sum(s3)/(64.*63.) + i1=1 !Silence warning + i2=1 + +! Compute probabilities for most reliable symbol values + do j=1,63 + s1=-1.e30 + psum=0. + do i=1,64 + x=min(afac*s3(i,j)/ave,50.d0) + psum=psum+s3(i,j) + if(s3(i,j).gt.s1) then + s1=s3(i,j) + i1=i !Most reliable + endif + enddo + if(psum.eq.0.0) psum=1.e-6 + + 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=s1/psum !Symbol metrics for ftrsd + p2=s2/psum + mrsym(j)=i1-1 + mr2sym(j)=i2-1 + mrprob(j)=scale*p1 + mr2prob(j)=scale*p2 + enddo + + nlow=0 + do j=1,63 + if(mrprob(j).le.5) nlow=nlow+1 + enddo + ntest=sum(mrprob) + + return +end subroutine demod64a diff --git a/lib/determ.f90 b/lib/determ.f90 index 46879190..6ae471bd 100755 --- a/lib/determ.f90 +++ b/lib/determ.f90 @@ -1,32 +1,32 @@ -real*8 function determ(array,norder) - implicit real*8 (a-h,o-z) - real*8 array(10,10) - - determ=1. - do k=1,norder - if (array(k,k).ne.0) go to 41 - do j=k,norder - if(array(k,j).ne.0) go to 31 - enddo - determ=0. - go to 60 - -31 do i=k,norder - s8=array(i,j) - array(i,j)=array(i,k) - array(i,k)=s8 - enddo - determ=-1.*determ -41 determ=determ*array(k,k) - if(k.lt.norder) then - k1=k+1 - do i=k1,norder - do j=k1,norder - array(i,j)=array(i,j)-array(i,k)*array(k,j)/array(k,k) - enddo - enddo - end if - enddo - -60 return -end function determ +real*8 function determ(array,norder) + implicit real*8 (a-h,o-z) + real*8 array(10,10) + + determ=1. + do k=1,norder + if (array(k,k).ne.0) go to 41 + do j=k,norder + if(array(k,j).ne.0) go to 31 + enddo + determ=0. + go to 60 + +31 do i=k,norder + s8=array(i,j) + array(i,j)=array(i,k) + array(i,k)=s8 + enddo + determ=-1.*determ +41 determ=determ*array(k,k) + if(k.lt.norder) then + k1=k+1 + do i=k1,norder + do j=k1,norder + array(i,j)=array(i,j)-array(i,k)*array(k,j)/array(k,k) + enddo + enddo + end if + enddo + +60 return +end function determ diff --git a/lib/digi-contest.txt b/lib/digi-contest.txt index ab0a433f..b0eafaec 100755 --- a/lib/digi-contest.txt +++ b/lib/digi-contest.txt @@ -1,277 +1,277 @@ - Possible FT8 Enhancements for Contesting - ---------------------------------------- - -In addition to all the standard FT8 messages, FT8 DXpedition Mode -defines a new message type to convey messages like this example -acknowledging completion of a QSO with K1ABC and initiating a QSO with -W9XYZ: - - K1ABC RR73; W9XYZ -11 - -With 15s T/R sequencing and otherwise using standard FT8 messages, -this feature allows QSO rates up to 120/hour with one Tx signal. The -callsign enclosed in angle brackets is sent as a 10-bit hash code. - -High QSO rates are also desirable for contest operating, but some -details are quite different from the DXpedition case. Contesting is a -many-to-many (as opposed to many-to-one) activity. We distinguish -between "Run stations" and "S+P stations" rather than between "Fox" -and "Hounds". - -An optimal sequence of messages suitable for contesting looks -something like the list in Table 1, where {exch} represents the -required contest exchange. With 15 s transmissions and a steady -stream of callers, messages like these can support QSO rates -approaching 120/hour. - -Table 1. Example sequence of FT8 contest messages -------------------------------------------------------------------------- - Run station S+P stations -------------------------------------------------------------------------- -1. CQ K1ABC -2. K1ABC W9XYZ, K1ABC G4AAA, ... -3. W9XYZ K1ABC {exch} -4. K1ABC W9XYZ {exch} -5. TU; G4AAA K1ABC {exch} -6. K1ABC G4AAA {exch} -7. TU; VE2BBB K1ABC {exch} -8. K1ABC VE2BBB {exch} -9. ... -------------------------------------------------------------------------- - -In some circumstances one or both station callsigns may safely be -taken as known by context. High-rate contest transmissions in SSB, -CW, and RTTY can therefore be considerably shortened with no resulting -ambiguity for attentive operators. CQing stations need not include -their own callsign in every transmission, while S+P stations may send -only their own callsign at first, as in line 2 of Table 2, and then -only the contest exchange, as in line 4. - -Table 2. Abbreviated contest messages -------------------------------------------------------------------------- - Run station S+P stations -------------------------------------------------------------------------- -1. CQ K1ABC -2. W9XYZ, G4AAA, ... -3. W9XYZ {exch} -4. {exch} (sent by W9XYZ) -5. TU; G4AAA {exch} -6. {exch} (sent by G4AAA) -7. TU; VE2BBB {exch} -8. {exch} (sent by VE2BBB) -9. TU; CQ K1ABC -10. ... -------------------------------------------------------------------------- - -There would be no advantage to such message brevity with FT8. FT8 -transmissions are of fixed duration, by design; and the AP decoder can -treat the home callsign and previously decoded callsigns as -hypothetically given, thereby making the effective code rate lower and -sensitivity up to 4 dB better. - -Required exchange information for some relevant contests is -illustrated in Table 3, along with a breakdown of bit requirements for -each component of the exchange. Lower-case letter-number combinations -such as r1, r3, s7,... in the table suggest the meanings and indicate -the number of bits required to convey each part of the exchange. -Further details are given below the Table. Parameter T1 is the total -number of exchange bits, and T2=T1+56 is the number of bits for the -full message, including two standard 28-bit callsigns. - -Table 3. Examples of required contest exchanges {exch} ------------------------------------------------------------------------------- -Event Exchange Example Bits T1 T2 ------------------------------------------------------------------------------- -ARRL RTTY US/Can: rpt state/prov R 579 MA r1 r3 s7 11 67 - DX: rpt serial R 559 0013 r1 r3 n12 16 72 - -Field Day US/Can: OpClass Section R 6A EMA r1 n5 c3 s7 16 72 - DX: OpClass DX R 1A DX r1 n5 c3 s7 16 72 - -CQ WPX RTTY RST + serial R 589 0013 r1 r3 n12 16 72 - -CQ WW RTTY US/Can: RST CQZ state/prov R 579 8 NJ r1 r3 z6 s6 16 72 - DX: RST + CQzone R 559 3 r1 r3 z6 10 66 - -ARRL VHF+ grid4 R FN42 r1 g15 16 72 - -EU VHF+ rpt serial grid6 R 590013 IO91NP r1 r3 n12 g25 41 97 ------------------------------------------------------------------------------- -Meaning and number of bits for each exchange component: - -c3 Operating class (A-F) -g15 grid4 -g25 grid6 -n12 Serial number -n5 Number of transmitters (0-31) -r1 acknowledgment of received exchange -r3 3-bit report (0-7 ==> -24 to +18 dB, effectively "S2 to "S9") -s6 US state or Canadian province (48+14=62) -s7 ARRL/RAC Section (83 sections) -z6 CQ zone ------------------------------------------------------------------------------- - -How best to accommodate all these possibilities within the 72+3-bit -FT8 message payload? Let i3 (aka "i3bit") denote message type, with -available range 0-7. Type 0 is already used for standard JT-style -structured messages and free text, and type 1 for DXpedition mode. -Examples of suggested new message types 2 through 6 are summarized in -the Table 4. - -Table 4. Proposed FT8 message types ------------------------------------------------------------------------------- -i3 Example message Bits i72 Total Special purpose ------------------------------------------------------------------------------- -0 K1ABC W9XYZ EN37 28 28 15 0 72 Standard message -0 FREE TEXT 71 1 72 Free text -1 K1ABC RR73; W9XYZ -11 28 28 10 6 72 DXpedition Mode -2 W9XYZ K1ABC x16 28 28 16 72 Contesting -3 TU; G4AAA K1ABC x16 28 28 16 72 Contesting with "TU;" -4 W9XYZ/R R x25 17 28 1 1 25 72 Rovers, Grid6 -5 PJ4/W9XYZ 17 49 66 Compound TxCall -6 PA9XYZ R 590003 IO91NP 28 1 3 12 24 68 EU VHF contest -7 tbd... - -The first callsign in a message can also be "CQ" and a few other -special tokens. Type 3 messages are the same as type 2 except for -including "TU;", the completion-of-QSO indicator. Message fragments -x16 and x25 represent generic contest exchanges. A "contest template" -will define the specific source encoding/decoding needed for each -event. - -Suggested message types 4 and 5 use a 17-bit hash for the first -callsign. I'm imagining that we'd start with a 32-bit crc and then -use its remainder after dividing by the prime number 131063. Values -less than 131063 will be the desired hash code, and the nine values -131063-131071 can be assigned special meanings such as CQ, QRZ, etc. -Type 4 messages identify the transmitting station as a Rover and can -also accommodate 6-digit grid locators. Type 5 messages allow the -transmitting station to send a full compound callsign with add-on -prefixes up to 4 characters and suffixes up to 3. Compound callsigns -are also permissible for the hashed callsigns in message types 4 and -5. - -Contest Operating ------------------ - -Operating in this proposed FT8 Contest Mode would be similar to that -in current RTTY contests. CQing stations will be distributed over 20 -kHz or more on each band, perhaps at ~500 Hz separation. They will -respond to callers on their own frequency +/- ~200 Hz. Thus, a CQing -station and callers should occupy no more than 500 Hz total bandwidth. -CQers might always transmit at Tx audio frequency 1750 Hz and -configure their FT8 decoders to respond to signals between 1500 and -2000 Hz. S+P stations will typically work their way up or down the -band, perhaps in steps of 2 or 3 kHz, looking for unworked CQers. The -FT8 Contest GUI will offer special features for CQ mode and S+P mode -that make such conventions easy to follow. - -Some Pertinent Questions ------------------------- - -1. FT8 is a good mode, but does it make for a good contesting mode? - -The model described above maxes out at 120 QSOs/hour. (One can -imagine SO2R or even SO3R extensions, doubling or tripling that -limit.) Should we consider T/R sequences of 10s, or even 5s, to get -potentially higher rates? Should we consider giving up synchronized, -fixed-length sequences entirely, and use operator-determined start -times and transmission lengths? That's a significant departure from -all existing WSJT-X modes. - -2. How much automation should be permissible? - -We're not aiming to make a contesting robot. We want something that -rewards operator and station performance. The recently introduced FT8 -DXpedition Mode offers the "Fox" operator a list of decoded "Hounds" -sorted by Call, Grid, S/N, Distance, or Random order. Hounds must -initiate their calls to Fox, and Fox must manually select each Hound -to be called. Otherwise, QSOs proceed with standard FT8 -"auto-sequencing". Is this model acceptable? - -3. How much bandwidth? How much sensitivity? - -RTTY signals use bandwidth ~220 Hz and require S/N around -5 dB or -better, measured in a 2500 Hz bandwidth. FT8 uses signal bandwidth 50 -Hz and reaches threshold sensitivity between -20 and -24 dB, depending -on how much a priori (AP) information is available. Shorter -transmissions conveying the same messages would increase the -bandwidth, S/N threshold, and potential QSO rate proportionally. Has -FT8 already hit the "sweet spot" of such trade-offs? - -4. Suitable power limits? - -WSJT-X modes are designed as weak-signal modes. They have strong FEC -and don't suffer from partial or corrupted copy. Sensitivity already -beats RTTY by 15-19 dB, so arguably it makes sense for an FT8 contest -or contest category to be limited to 100 W or even QRP power levels. - -5. What software should provide the operator's GUI? - -Things are described above as though WSJT-X, the software that -introduced FT8, would be used for contest operating. WSJT-X can send -QSO information to N1MM+ and other logging programs, so they could be -used in combination with WSJT-X. Alternatively, we could set things -up so that N1MM+ is the control program and FT8 encoding/decoding is -provided by a plug-in "MMFT8" similar to MMTTY. Operators already -into serious RTTY contesting would probably like the N1MM-in-control -option. However, existing FT8 users might be more comfortable with -WSJT-X in full control. Moreover, WSJT-X offers full support for -Linux and MacOS, which N1MM+ does not. - -######################################################################## - -More thinking, beyond the above... - -FT8 currently uses LDPC(174,87), where 87=72+3+12. Suggest going to -LDPC(174,91), with 91=72+5+14. This would give us 32 message types -rather than 7, and stronger suppression of false decodes. SNR penalty -would be 10log(91/87)=0.2 dB. - -MSK144 currently uses LDPC(128,80), where 80=72+8. Suggest going to -LDPC(128,87), with 87=72+5+10. SNR penalty is 0.4 dB. - -ARRL RTTY Roundup -------------------------------------------------------------------------- - Run station S+P stations -------------------------------------------------------------------------- -1. CQ K1ABC -2. K1ABC W9XYZ, K1ABC G4AAA, ... -3. W9XYZ K1ABC 579 MA -4. K1ABC W9XYZ 599 WI -5. TU; G4AAA K1ABC 559 MA -6. K1ABC G4AAA 579 0013 -7. TU; VE2BBB K1ABC 599 MA -8. K1ABC VE2BBB 599 QC -9. TU; CQ K1ABC -------------------------------------------------------------------------- - - -NA VHF Contest -------------------------------------------------------------------------- - Run station S+P station i3 -------------------------------------------------------------------------- -1. CQ K1ABC/R FN54 0 -2. K1ABC W9XYZ EN37 0 -3. W9XYZ K1ABC R FN54 2 -4. K1ABC W9XYZ RR73 0 -5. CQ K1ABC/R FN54 0 -------------------------------------------------------------------------- -1. CQ K1ABC FN42 0 -2. W9XYZ/R EN47 5 -3. W9XYZ K1ABC R FN42 0 -4. DE W9XYZ/R RR73 0 -5. CQ K1ABC FN42 0 -------------------------------------------------------------------------- - - - -EU VHF+ Contest -------------------------------------------------------------------------- - Run station S+P station i3 -------------------------------------------------------------------------- -1. CQ G4ABC IO91 0 -2. G4ABC PA9XYZ JO22 0 -3. PA9XYZ 590003 IO91NP 6 -4. G4ABC R 570007 JO22DB 6 -5. PA9XYZ G4ABC RR73 0 + Possible FT8 Enhancements for Contesting + ---------------------------------------- + +In addition to all the standard FT8 messages, FT8 DXpedition Mode +defines a new message type to convey messages like this example +acknowledging completion of a QSO with K1ABC and initiating a QSO with +W9XYZ: + + K1ABC RR73; W9XYZ -11 + +With 15s T/R sequencing and otherwise using standard FT8 messages, +this feature allows QSO rates up to 120/hour with one Tx signal. The +callsign enclosed in angle brackets is sent as a 10-bit hash code. + +High QSO rates are also desirable for contest operating, but some +details are quite different from the DXpedition case. Contesting is a +many-to-many (as opposed to many-to-one) activity. We distinguish +between "Run stations" and "S+P stations" rather than between "Fox" +and "Hounds". + +An optimal sequence of messages suitable for contesting looks +something like the list in Table 1, where {exch} represents the +required contest exchange. With 15 s transmissions and a steady +stream of callers, messages like these can support QSO rates +approaching 120/hour. + +Table 1. Example sequence of FT8 contest messages +------------------------------------------------------------------------- + Run station S+P stations +------------------------------------------------------------------------- +1. CQ K1ABC +2. K1ABC W9XYZ, K1ABC G4AAA, ... +3. W9XYZ K1ABC {exch} +4. K1ABC W9XYZ {exch} +5. TU; G4AAA K1ABC {exch} +6. K1ABC G4AAA {exch} +7. TU; VE2BBB K1ABC {exch} +8. K1ABC VE2BBB {exch} +9. ... +------------------------------------------------------------------------- + +In some circumstances one or both station callsigns may safely be +taken as known by context. High-rate contest transmissions in SSB, +CW, and RTTY can therefore be considerably shortened with no resulting +ambiguity for attentive operators. CQing stations need not include +their own callsign in every transmission, while S+P stations may send +only their own callsign at first, as in line 2 of Table 2, and then +only the contest exchange, as in line 4. + +Table 2. Abbreviated contest messages +------------------------------------------------------------------------- + Run station S+P stations +------------------------------------------------------------------------- +1. CQ K1ABC +2. W9XYZ, G4AAA, ... +3. W9XYZ {exch} +4. {exch} (sent by W9XYZ) +5. TU; G4AAA {exch} +6. {exch} (sent by G4AAA) +7. TU; VE2BBB {exch} +8. {exch} (sent by VE2BBB) +9. TU; CQ K1ABC +10. ... +------------------------------------------------------------------------- + +There would be no advantage to such message brevity with FT8. FT8 +transmissions are of fixed duration, by design; and the AP decoder can +treat the home callsign and previously decoded callsigns as +hypothetically given, thereby making the effective code rate lower and +sensitivity up to 4 dB better. + +Required exchange information for some relevant contests is +illustrated in Table 3, along with a breakdown of bit requirements for +each component of the exchange. Lower-case letter-number combinations +such as r1, r3, s7,... in the table suggest the meanings and indicate +the number of bits required to convey each part of the exchange. +Further details are given below the Table. Parameter T1 is the total +number of exchange bits, and T2=T1+56 is the number of bits for the +full message, including two standard 28-bit callsigns. + +Table 3. Examples of required contest exchanges {exch} +------------------------------------------------------------------------------ +Event Exchange Example Bits T1 T2 +------------------------------------------------------------------------------ +ARRL RTTY US/Can: rpt state/prov R 579 MA r1 r3 s7 11 67 + DX: rpt serial R 559 0013 r1 r3 n12 16 72 + +Field Day US/Can: OpClass Section R 6A EMA r1 n5 c3 s7 16 72 + DX: OpClass DX R 1A DX r1 n5 c3 s7 16 72 + +CQ WPX RTTY RST + serial R 589 0013 r1 r3 n12 16 72 + +CQ WW RTTY US/Can: RST CQZ state/prov R 579 8 NJ r1 r3 z6 s6 16 72 + DX: RST + CQzone R 559 3 r1 r3 z6 10 66 + +ARRL VHF+ grid4 R FN42 r1 g15 16 72 + +EU VHF+ rpt serial grid6 R 590013 IO91NP r1 r3 n12 g25 41 97 +------------------------------------------------------------------------------ +Meaning and number of bits for each exchange component: + +c3 Operating class (A-F) +g15 grid4 +g25 grid6 +n12 Serial number +n5 Number of transmitters (0-31) +r1 acknowledgment of received exchange +r3 3-bit report (0-7 ==> -24 to +18 dB, effectively "S2 to "S9") +s6 US state or Canadian province (48+14=62) +s7 ARRL/RAC Section (83 sections) +z6 CQ zone +------------------------------------------------------------------------------ + +How best to accommodate all these possibilities within the 72+3-bit +FT8 message payload? Let i3 (aka "i3bit") denote message type, with +available range 0-7. Type 0 is already used for standard JT-style +structured messages and free text, and type 1 for DXpedition mode. +Examples of suggested new message types 2 through 6 are summarized in +the Table 4. + +Table 4. Proposed FT8 message types +------------------------------------------------------------------------------ +i3 Example message Bits i72 Total Special purpose +------------------------------------------------------------------------------ +0 K1ABC W9XYZ EN37 28 28 15 0 72 Standard message +0 FREE TEXT 71 1 72 Free text +1 K1ABC RR73; W9XYZ -11 28 28 10 6 72 DXpedition Mode +2 W9XYZ K1ABC x16 28 28 16 72 Contesting +3 TU; G4AAA K1ABC x16 28 28 16 72 Contesting with "TU;" +4 W9XYZ/R R x25 17 28 1 1 25 72 Rovers, Grid6 +5 PJ4/W9XYZ 17 49 66 Compound TxCall +6 PA9XYZ R 590003 IO91NP 28 1 3 12 24 68 EU VHF contest +7 tbd... + +The first callsign in a message can also be "CQ" and a few other +special tokens. Type 3 messages are the same as type 2 except for +including "TU;", the completion-of-QSO indicator. Message fragments +x16 and x25 represent generic contest exchanges. A "contest template" +will define the specific source encoding/decoding needed for each +event. + +Suggested message types 4 and 5 use a 17-bit hash for the first +callsign. I'm imagining that we'd start with a 32-bit crc and then +use its remainder after dividing by the prime number 131063. Values +less than 131063 will be the desired hash code, and the nine values +131063-131071 can be assigned special meanings such as CQ, QRZ, etc. +Type 4 messages identify the transmitting station as a Rover and can +also accommodate 6-digit grid locators. Type 5 messages allow the +transmitting station to send a full compound callsign with add-on +prefixes up to 4 characters and suffixes up to 3. Compound callsigns +are also permissible for the hashed callsigns in message types 4 and +5. + +Contest Operating +----------------- + +Operating in this proposed FT8 Contest Mode would be similar to that +in current RTTY contests. CQing stations will be distributed over 20 +kHz or more on each band, perhaps at ~500 Hz separation. They will +respond to callers on their own frequency +/- ~200 Hz. Thus, a CQing +station and callers should occupy no more than 500 Hz total bandwidth. +CQers might always transmit at Tx audio frequency 1750 Hz and +configure their FT8 decoders to respond to signals between 1500 and +2000 Hz. S+P stations will typically work their way up or down the +band, perhaps in steps of 2 or 3 kHz, looking for unworked CQers. The +FT8 Contest GUI will offer special features for CQ mode and S+P mode +that make such conventions easy to follow. + +Some Pertinent Questions +------------------------ + +1. FT8 is a good mode, but does it make for a good contesting mode? + +The model described above maxes out at 120 QSOs/hour. (One can +imagine SO2R or even SO3R extensions, doubling or tripling that +limit.) Should we consider T/R sequences of 10s, or even 5s, to get +potentially higher rates? Should we consider giving up synchronized, +fixed-length sequences entirely, and use operator-determined start +times and transmission lengths? That's a significant departure from +all existing WSJT-X modes. + +2. How much automation should be permissible? + +We're not aiming to make a contesting robot. We want something that +rewards operator and station performance. The recently introduced FT8 +DXpedition Mode offers the "Fox" operator a list of decoded "Hounds" +sorted by Call, Grid, S/N, Distance, or Random order. Hounds must +initiate their calls to Fox, and Fox must manually select each Hound +to be called. Otherwise, QSOs proceed with standard FT8 +"auto-sequencing". Is this model acceptable? + +3. How much bandwidth? How much sensitivity? + +RTTY signals use bandwidth ~220 Hz and require S/N around -5 dB or +better, measured in a 2500 Hz bandwidth. FT8 uses signal bandwidth 50 +Hz and reaches threshold sensitivity between -20 and -24 dB, depending +on how much a priori (AP) information is available. Shorter +transmissions conveying the same messages would increase the +bandwidth, S/N threshold, and potential QSO rate proportionally. Has +FT8 already hit the "sweet spot" of such trade-offs? + +4. Suitable power limits? + +WSJT-X modes are designed as weak-signal modes. They have strong FEC +and don't suffer from partial or corrupted copy. Sensitivity already +beats RTTY by 15-19 dB, so arguably it makes sense for an FT8 contest +or contest category to be limited to 100 W or even QRP power levels. + +5. What software should provide the operator's GUI? + +Things are described above as though WSJT-X, the software that +introduced FT8, would be used for contest operating. WSJT-X can send +QSO information to N1MM+ and other logging programs, so they could be +used in combination with WSJT-X. Alternatively, we could set things +up so that N1MM+ is the control program and FT8 encoding/decoding is +provided by a plug-in "MMFT8" similar to MMTTY. Operators already +into serious RTTY contesting would probably like the N1MM-in-control +option. However, existing FT8 users might be more comfortable with +WSJT-X in full control. Moreover, WSJT-X offers full support for +Linux and MacOS, which N1MM+ does not. + +######################################################################## + +More thinking, beyond the above... + +FT8 currently uses LDPC(174,87), where 87=72+3+12. Suggest going to +LDPC(174,91), with 91=72+5+14. This would give us 32 message types +rather than 7, and stronger suppression of false decodes. SNR penalty +would be 10log(91/87)=0.2 dB. + +MSK144 currently uses LDPC(128,80), where 80=72+8. Suggest going to +LDPC(128,87), with 87=72+5+10. SNR penalty is 0.4 dB. + +ARRL RTTY Roundup +------------------------------------------------------------------------- + Run station S+P stations +------------------------------------------------------------------------- +1. CQ K1ABC +2. K1ABC W9XYZ, K1ABC G4AAA, ... +3. W9XYZ K1ABC 579 MA +4. K1ABC W9XYZ 599 WI +5. TU; G4AAA K1ABC 559 MA +6. K1ABC G4AAA 579 0013 +7. TU; VE2BBB K1ABC 599 MA +8. K1ABC VE2BBB 599 QC +9. TU; CQ K1ABC +------------------------------------------------------------------------- + + +NA VHF Contest +------------------------------------------------------------------------- + Run station S+P station i3 +------------------------------------------------------------------------- +1. CQ K1ABC/R FN54 0 +2. K1ABC W9XYZ EN37 0 +3. W9XYZ K1ABC R FN54 2 +4. K1ABC W9XYZ RR73 0 +5. CQ K1ABC/R FN54 0 +------------------------------------------------------------------------- +1. CQ K1ABC FN42 0 +2. W9XYZ/R EN47 5 +3. W9XYZ K1ABC R FN42 0 +4. DE W9XYZ/R RR73 0 +5. CQ K1ABC FN42 0 +------------------------------------------------------------------------- + + + +EU VHF+ Contest +------------------------------------------------------------------------- + Run station S+P station i3 +------------------------------------------------------------------------- +1. CQ G4ABC IO91 0 +2. G4ABC PA9XYZ JO22 0 +3. PA9XYZ 590003 IO91NP 6 +4. G4ABC R 570007 JO22DB 6 +5. PA9XYZ G4ABC RR73 0 diff --git a/lib/downsam9.f90 b/lib/downsam9.f90 index 4fe67349..7cd1962a 100755 --- a/lib/downsam9.f90 +++ b/lib/downsam9.f90 @@ -1,88 +1,88 @@ -subroutine downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2) - -!Downsample from id2() into c2() so as to yield nspsd samples per symbol, -!mixing from fpk down to zero frequency. The downsample factor is 432. - - use, intrinsic :: iso_c_binding - use FFTW3 - use timer_module, only: timer - - include 'constants.f90' - integer(C_SIZE_T) NMAX1 - parameter (NMAX1=653184) - parameter (NFFT1=653184,NFFT2=1512) - type(C_PTR) :: plan !Pointers plan for big FFT - integer*2 id2(0:8*npts8-1) - logical, intent(inout) :: newdat - real*4, pointer :: x1(:) - complex c1(0:NFFT1/2) - complex c2(0:NFFT2-1) - real s(5000) - logical first - common/patience/npatience,nthreads - data first/.true./ - save plan,first,c1,s,x1 - - df1=12000.0/NFFT1 - npts=8*npts8 - if(npts.gt.NFFT1) npts=NFFT1 !### Fix! ### - - 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 - - !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls - plan=fftwf_alloc_real(NMAX1) - call c_f_pointer(plan,x1,[NMAX1]) - x1(0:NMAX1-1) => x1 !remap bounds - call fftwf_plan_with_nthreads(nthreads) - plan=fftwf_plan_dft_r2c_1d(NFFT1,x1,c1,nflags) - call fftwf_plan_with_nthreads(1) - !$omp end critical(fftw) - - first=.false. - endif - - if(newdat) then - x1(0:npts-1)=id2(0:npts-1) - x1(npts:NFFT1-1)=0. !Zero the rest of x1 - call timer('FFTbig9 ',0) - call fftwf_execute_dft_r2c(plan,x1,c1) - call timer('FFTbig9 ',1) - - nadd=int(1.0/df1) - s=0. - do i=1,5000 - j=int((i-1)/df1) - do n=1,nadd - j=j+1 - s(i)=s(i)+real(c1(j))**2 + aimag(c1(j))**2 - enddo - enddo - newdat=.false. - endif - - ndown=8*nsps8/nspsd !Downsample factor = 432 - nh2=NFFT2/2 - nf=nint(fpk) - i0=int(fpk/df1) - - nw=100 - ia=max(1,nf-nw) - ib=min(5000,nf+nw) - call pctile(s(ia),ib-ia+1,40,avenoise) - - fac=sqrt(1.0/avenoise) - do i=0,NFFT2-1 - j=i0+i - if(i.gt.nh2) j=j-NFFT2 - c2(i)=fac*c1(j) - enddo - call four2a(c2,NFFT2,1,1,1) !FFT back to time domain - - return -end subroutine downsam9 +subroutine downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2) + +!Downsample from id2() into c2() so as to yield nspsd samples per symbol, +!mixing from fpk down to zero frequency. The downsample factor is 432. + + use, intrinsic :: iso_c_binding + use FFTW3 + use timer_module, only: timer + + include 'constants.f90' + integer(C_SIZE_T) NMAX1 + parameter (NMAX1=653184) + parameter (NFFT1=653184,NFFT2=1512) + type(C_PTR) :: plan !Pointers plan for big FFT + integer*2 id2(0:8*npts8-1) + logical, intent(inout) :: newdat + real*4, pointer :: x1(:) + complex c1(0:NFFT1/2) + complex c2(0:NFFT2-1) + real s(5000) + logical first + common/patience/npatience,nthreads + data first/.true./ + save plan,first,c1,s,x1 + + df1=12000.0/NFFT1 + npts=8*npts8 + if(npts.gt.NFFT1) npts=NFFT1 !### Fix! ### + + 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 + + !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls + plan=fftwf_alloc_real(NMAX1) + call c_f_pointer(plan,x1,[NMAX1]) + x1(0:NMAX1-1) => x1 !remap bounds + call fftwf_plan_with_nthreads(nthreads) + plan=fftwf_plan_dft_r2c_1d(NFFT1,x1,c1,nflags) + call fftwf_plan_with_nthreads(1) + !$omp end critical(fftw) + + first=.false. + endif + + if(newdat) then + x1(0:npts-1)=id2(0:npts-1) + x1(npts:NFFT1-1)=0. !Zero the rest of x1 + call timer('FFTbig9 ',0) + call fftwf_execute_dft_r2c(plan,x1,c1) + call timer('FFTbig9 ',1) + + nadd=int(1.0/df1) + s=0. + do i=1,5000 + j=int((i-1)/df1) + do n=1,nadd + j=j+1 + s(i)=s(i)+real(c1(j))**2 + aimag(c1(j))**2 + enddo + enddo + newdat=.false. + endif + + ndown=8*nsps8/nspsd !Downsample factor = 432 + nh2=NFFT2/2 + nf=nint(fpk) + i0=int(fpk/df1) + + nw=100 + ia=max(1,nf-nw) + ib=min(5000,nf+nw) + call pctile(s(ia),ib-ia+1,40,avenoise) + + fac=sqrt(1.0/avenoise) + do i=0,NFFT2-1 + j=i0+i + if(i.gt.nh2) j=j-NFFT2 + c2(i)=fac*c1(j) + enddo + call four2a(c2,NFFT2,1,1,1) !FFT back to time domain + + return +end subroutine downsam9 diff --git a/lib/echo_snr.f90 b/lib/echo_snr.f90 index efa6486d..fb976b73 100755 --- a/lib/echo_snr.f90 +++ b/lib/echo_snr.f90 @@ -1,51 +1,51 @@ -subroutine echo_snr(sa,sb,fspread,blue,red,snrdb,db_err,fpeak,snr_detect) - - parameter (NZ=4096) - real sa(NZ) - real sb(NZ) - real blue(NZ) - real red(NZ) - integer ipkv(1) - equivalence (ipk,ipkv) - - df=12000.0/32768.0 - wh=0.5*fspread+10.0 - i1=nint((1500.0 - 2.0*wh)/df) - 2048 - i2=nint((1500.0 - wh)/df) - 2048 - i3=nint((1500.0 + wh)/df) - 2048 - i4=nint((1500.0 + 2.0*wh)/df) - 2048 - -! call pctile(sb(i1),i2-i1,50,r0) -! call pctile(sb(i3+1),i4-i3,50,r1) -! ave=0.5*(r0+r1) -! blue=sa/ave -! red=sb/ave - - baseline=(sum(sb(i1:i2-1)) + sum(sb(i3+1:i4)))/(i2+i4-i1-i3) - blue=sa/baseline - red=sb/baseline - psig=sum(red(i2:i3)-1.0) - pnoise_2500 = 2500.0/df - snrdb=db(psig/pnoise_2500) - - smax=0. - mh=max(1,nint(0.2*fspread/df)) - do i=i2,i3 - ssum=sum(red(i-mh:i+mh)) - if(ssum.gt.smax) then - smax=ssum - ipk=i - endif - enddo - fpeak=ipk*df - 750.0 - - call averms(red(i1:i2-1),i2-i1,-1,ave1,rms1) - call averms(red(i3+1:i4),i4-i3,-1,ave2,rms2) - perr=0.707*(rms1+rms2)*sqrt(float(i2-i1+i4-i3)) - snr_detect=psig/perr - db_err=99.0 - if(psig.gt.perr) db_err=snrdb - db((psig-perr)/pnoise_2500) - if(db_err.lt.0.5) db_err=0.5 - - return -end subroutine echo_snr +subroutine echo_snr(sa,sb,fspread,blue,red,snrdb,db_err,fpeak,snr_detect) + + parameter (NZ=4096) + real sa(NZ) + real sb(NZ) + real blue(NZ) + real red(NZ) + integer ipkv(1) + equivalence (ipk,ipkv) + + df=12000.0/32768.0 + wh=0.5*fspread+10.0 + i1=nint((1500.0 - 2.0*wh)/df) - 2048 + i2=nint((1500.0 - wh)/df) - 2048 + i3=nint((1500.0 + wh)/df) - 2048 + i4=nint((1500.0 + 2.0*wh)/df) - 2048 + +! call pctile(sb(i1),i2-i1,50,r0) +! call pctile(sb(i3+1),i4-i3,50,r1) +! ave=0.5*(r0+r1) +! blue=sa/ave +! red=sb/ave + + baseline=(sum(sb(i1:i2-1)) + sum(sb(i3+1:i4)))/(i2+i4-i1-i3) + blue=sa/baseline + red=sb/baseline + psig=sum(red(i2:i3)-1.0) + pnoise_2500 = 2500.0/df + snrdb=db(psig/pnoise_2500) + + smax=0. + mh=max(1,nint(0.2*fspread/df)) + do i=i2,i3 + ssum=sum(red(i-mh:i+mh)) + if(ssum.gt.smax) then + smax=ssum + ipk=i + endif + enddo + fpeak=ipk*df - 750.0 + + call averms(red(i1:i2-1),i2-i1,-1,ave1,rms1) + call averms(red(i3+1:i4),i4-i3,-1,ave2,rms2) + perr=0.707*(rms1+rms2)*sqrt(float(i2-i1+i4-i3)) + snr_detect=psig/perr + db_err=99.0 + if(psig.gt.perr) db_err=snrdb - db((psig-perr)/pnoise_2500) + if(db_err.lt.0.5) db_err=0.5 + + return +end subroutine echo_snr diff --git a/lib/echosim.f90 b/lib/echosim.f90 index 88477a21..96854aae 100755 --- a/lib/echosim.f90 +++ b/lib/echosim.f90 @@ -1,126 +1,126 @@ -program echosim - -! Generate simulated echo-mode files -- self-echo or "measure" - - use wavhdr - parameter (NWAVE=27648,NMAX=32768,NZ=36000) - type(hdr) h !Header for .wav file - character arg*12,fname*17 - complex c0(0:NMAX-1) - complex c(0:NMAX-1) - real*4 level_1,level_2 - real*8 f0,dt,twopi,phi,dphi - real wave(NZ) - integer*2 iwave(NZ) !Generated full-length waveform - equivalence (nDop0,iwave(1)) - equivalence (nDopAudio0,iwave(3)) - equivalence (nfrit0,iwave(5)) - equivalence (f10,iwave(7)) - equivalence (fspread0,iwave(9)) - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.3 .and. nargs.ne.5) then - print*,'Usage 1: echosim f0 fdop fspread nfiles snr' - print*,'Example: echosim 1500 0.0 4.0 10 -22' - print*,'Usage 2: echosim level_1 level_2 nfiles' - print*,'Example: echosim 30.0 40.0 100' - go to 999 - endif - - call getarg(1,arg) - read(arg,*) f0 !Tone frequency - call getarg(2,arg) - read(arg,*) fdop !Doppler shift (Hz) - call getarg(3,arg) - read(arg,*) fspread !Frequency spread (Hz) (JHT Lorentzian model) - - if(nargs.eq.3) then - level_1=f0 - level_2=fdop - nfiles=fspread - snrdb=0. - go to 10 - endif - - call getarg(4,arg) - read(arg,*) nfiles !Number of files - call getarg(5,arg) - read(arg,*) snrdb !SNR_2500 - -10 twopi=8.d0*atan(1.d0) - fs=12000.0 !Sample rate (Hz) - dt=1.d0/fs !Sample interval (s) - bandwidth_ratio=2500.0/(fs/2.0) - sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) - if(snrdb.gt.90.0) sig=1.0 - dphi=twopi*(f0+fdop)*dt - - write(*,1000) -1000 format(' N f0 fDop fSpread SNR File name'/51('-')) - - do ifile=1,nfiles - wave=0. - - if(nargs.eq.5) then - phi=0.d0 - do i=0,NWAVE-1 - phi=phi + dphi - if(phi.gt.twopi) phi=phi-twopi - xphi=phi - c0(i)=cmplx(cos(xphi),sin(xphi)) - enddo - c0(NWAVE:)=0. - if(fspread.gt.0.0) call fspread_lorentz(c0,fspread) - c=sig*c0 - wave(1:NWAVE)=imag(c(1:NWAVE)) - peak=maxval(abs(wave)) - endif - - if(snrdb.lt.90) then - do i=1,NWAVE !Add gaussian noise at specified SNR - xnoise=gran() - wave(i)=wave(i) + xnoise - enddo - do i=NWAVE+1,NZ - xnoise=gran() - wave(i)=xnoise - enddo - endif - - gain=100.0 - if(nargs.eq.3) then - gain=10.0**(0.05*level_1) - if(mod((ifile-1)/10,2).eq.1) gain=10.0**(0.05*level_2) - endif - if(snrdb.lt.90.0) then - wave=gain*wave - else - datpk=maxval(abs(wave)) - fac=32766.9/datpk - wave=fac*wave - endif - if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." - iwave=nint(wave) - - nDop0=nint(fdop) - nDopAudio0=0 - nfrit0=0 - f10=f0 + fdop - fspread0=fspread - - h=default_header(12000,NMAX) - n=3*(ifile-1) - ihr=n/3600 - imin=(n-3600*ihr)/60 - isec=mod(n,60) - write(fname,1102) ihr,imin,isec -1102 format('000000_',3i2.2,'.wav') - open(10,file=fname,status='unknown',access='stream') - write(10) h,iwave !Save to *.wav file - close(10) - write(*,1110) ifile,f0,fdop,fspread,snrdb,fname -1110 format(i4,4f7.1,2x,a17) - enddo - -999 end program echosim +program echosim + +! Generate simulated echo-mode files -- self-echo or "measure" + + use wavhdr + parameter (NWAVE=27648,NMAX=32768,NZ=36000) + type(hdr) h !Header for .wav file + character arg*12,fname*17 + complex c0(0:NMAX-1) + complex c(0:NMAX-1) + real*4 level_1,level_2 + real*8 f0,dt,twopi,phi,dphi + real wave(NZ) + integer*2 iwave(NZ) !Generated full-length waveform + equivalence (nDop0,iwave(1)) + equivalence (nDopAudio0,iwave(3)) + equivalence (nfrit0,iwave(5)) + equivalence (f10,iwave(7)) + equivalence (fspread0,iwave(9)) + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.3 .and. nargs.ne.5) then + print*,'Usage 1: echosim f0 fdop fspread nfiles snr' + print*,'Example: echosim 1500 0.0 4.0 10 -22' + print*,'Usage 2: echosim level_1 level_2 nfiles' + print*,'Example: echosim 30.0 40.0 100' + go to 999 + endif + + call getarg(1,arg) + read(arg,*) f0 !Tone frequency + call getarg(2,arg) + read(arg,*) fdop !Doppler shift (Hz) + call getarg(3,arg) + read(arg,*) fspread !Frequency spread (Hz) (JHT Lorentzian model) + + if(nargs.eq.3) then + level_1=f0 + level_2=fdop + nfiles=fspread + snrdb=0. + go to 10 + endif + + call getarg(4,arg) + read(arg,*) nfiles !Number of files + call getarg(5,arg) + read(arg,*) snrdb !SNR_2500 + +10 twopi=8.d0*atan(1.d0) + fs=12000.0 !Sample rate (Hz) + dt=1.d0/fs !Sample interval (s) + bandwidth_ratio=2500.0/(fs/2.0) + sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + dphi=twopi*(f0+fdop)*dt + + write(*,1000) +1000 format(' N f0 fDop fSpread SNR File name'/51('-')) + + do ifile=1,nfiles + wave=0. + + if(nargs.eq.5) then + phi=0.d0 + do i=0,NWAVE-1 + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + c0(i)=cmplx(cos(xphi),sin(xphi)) + enddo + c0(NWAVE:)=0. + if(fspread.gt.0.0) call fspread_lorentz(c0,fspread) + c=sig*c0 + wave(1:NWAVE)=imag(c(1:NWAVE)) + peak=maxval(abs(wave)) + endif + + if(snrdb.lt.90) then + do i=1,NWAVE !Add gaussian noise at specified SNR + xnoise=gran() + wave(i)=wave(i) + xnoise + enddo + do i=NWAVE+1,NZ + xnoise=gran() + wave(i)=xnoise + enddo + endif + + gain=100.0 + if(nargs.eq.3) then + gain=10.0**(0.05*level_1) + if(mod((ifile-1)/10,2).eq.1) gain=10.0**(0.05*level_2) + endif + if(snrdb.lt.90.0) then + wave=gain*wave + else + datpk=maxval(abs(wave)) + fac=32766.9/datpk + wave=fac*wave + endif + if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." + iwave=nint(wave) + + nDop0=nint(fdop) + nDopAudio0=0 + nfrit0=0 + f10=f0 + fdop + fspread0=fspread + + h=default_header(12000,NMAX) + n=3*(ifile-1) + ihr=n/3600 + imin=(n-3600*ihr)/60 + isec=mod(n,60) + write(fname,1102) ihr,imin,isec +1102 format('000000_',3i2.2,'.wav') + open(10,file=fname,status='unknown',access='stream') + write(10) h,iwave !Save to *.wav file + close(10) + write(*,1110) ifile,f0,fdop,fspread,snrdb,fname +1110 format(i4,4f7.1,2x,a17) + enddo + +999 end program echosim diff --git a/lib/emedop.dat b/lib/emedop.dat index 944c7960..c37d5b85 100755 --- a/lib/emedop.dat +++ b/lib/emedop.dat @@ -1,8 +1,8 @@ -Lat_A 40.35417 -WLong_A 75.62500 -Lat_B 45.1875 -WLong_B -1.541667 -TxFreqMHz 143.05 -StartTime 20180907 08:00:00 -StopTime 20180907 09:00:00 -StepSec 60.0 +Lat_A 40.35417 +WLong_A 75.62500 +Lat_B 45.1875 +WLong_B -1.541667 +TxFreqMHz 143.05 +StartTime 20180907 08:00:00 +StopTime 20180907 09:00:00 +StepSec 60.0 diff --git a/lib/emedop.f90 b/lib/emedop.f90 index d67a7244..4a95fb87 100755 --- a/lib/emedop.f90 +++ b/lib/emedop.f90 @@ -1,67 +1,67 @@ -program emedop - - real*8 txfreq8 - real*8 rxfreq8 - real*4 LST - real*4 lat_a - real*4 lat_b - character*80 infile - character*256 jpleph_file_name - common/jplcom/jpleph_file_name - data jpleph_file_name/'JPLEPH'/ - - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: emedop ' - go to 999 - endif - - call getarg(1,infile) - open(10,file=infile,status='old',err=900) - read(10,1001) lat_a -1001 format(10x,f12.0) - read(10,1001) wlon_a - read(10,1001) lat_b - read(10,1001) wlon_b - read(10,1001) txfreq8 - read(10,1002) nyear,month,nday,ih,im,is -1002 format(10x,i4,2i2,1x,i2,1x,i2,1x,i2) - sec_start=3600.0*ih + 60.0*im + is - read(10,1002) nyear,month,nday,ih,im,is - sec_stop=3600.0*ih + 60.0*im + is - read(10,1001) sec_step - - write(*,1005) -1005 format(' Date UTC Tx Freq Rx Freq Doppler'/ & - '------------------------------------------------------') - - sec=sec_start - ncalc=(sec_stop - sec_start)/sec_step - - do icalc=1,ncalc - uth=sec/3600.0 - call MoonDopJPL(nyear,month,nday,uth,-wlon_a,lat_a,RAMoon,DecMoon, & - LST,HA,AzMoon,ElMoon,vr_a,techo) - - call MoonDopJPL(nyear,month,nday,uth,-wlon_b,lat_b,RAMoon,DecMoon, & - LST,HA,AzMoon,ElMoon,vr_b,techo) - - dop_a=-txfreq8*vr_a/2.99792458e5 !One-way Doppler from a - dop_b=-txfreq8*vr_b/2.99792458e5 !One-way Doppler to b - doppler=1.e6*(dop_a + dop_b) - rxfreq8=txfreq8 + dop_a + dop_b - - ih=sec/3600.0 - im=(sec-ih*3600.0)/60.0 - is=nint(mod(sec,60.0)) - write(*,1010) nyear,month,nday,ih,im,is,txFreq8,rxFreq8,doppler -1010 format(i4,2i2.2,2x,i2.2,':',i2.2,':',i2.2,2f13.7,f8.1) - - sec=sec + sec_step - enddo - go to 999 -900 print*,'Cannot open file ',trim(infile) -999 end program emedop - - - +program emedop + + real*8 txfreq8 + real*8 rxfreq8 + real*4 LST + real*4 lat_a + real*4 lat_b + character*80 infile + character*256 jpleph_file_name + common/jplcom/jpleph_file_name + data jpleph_file_name/'JPLEPH'/ + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: emedop ' + go to 999 + endif + + call getarg(1,infile) + open(10,file=infile,status='old',err=900) + read(10,1001) lat_a +1001 format(10x,f12.0) + read(10,1001) wlon_a + read(10,1001) lat_b + read(10,1001) wlon_b + read(10,1001) txfreq8 + read(10,1002) nyear,month,nday,ih,im,is +1002 format(10x,i4,2i2,1x,i2,1x,i2,1x,i2) + sec_start=3600.0*ih + 60.0*im + is + read(10,1002) nyear,month,nday,ih,im,is + sec_stop=3600.0*ih + 60.0*im + is + read(10,1001) sec_step + + write(*,1005) +1005 format(' Date UTC Tx Freq Rx Freq Doppler'/ & + '------------------------------------------------------') + + sec=sec_start + ncalc=(sec_stop - sec_start)/sec_step + + do icalc=1,ncalc + uth=sec/3600.0 + call MoonDopJPL(nyear,month,nday,uth,-wlon_a,lat_a,RAMoon,DecMoon, & + LST,HA,AzMoon,ElMoon,vr_a,techo) + + call MoonDopJPL(nyear,month,nday,uth,-wlon_b,lat_b,RAMoon,DecMoon, & + LST,HA,AzMoon,ElMoon,vr_b,techo) + + dop_a=-txfreq8*vr_a/2.99792458e5 !One-way Doppler from a + dop_b=-txfreq8*vr_b/2.99792458e5 !One-way Doppler to b + doppler=1.e6*(dop_a + dop_b) + rxfreq8=txfreq8 + dop_a + dop_b + + ih=sec/3600.0 + im=(sec-ih*3600.0)/60.0 + is=nint(mod(sec,60.0)) + write(*,1010) nyear,month,nday,ih,im,is,txFreq8,rxFreq8,doppler +1010 format(i4,2i2.2,2x,i2.2,':',i2.2,':',i2.2,2f13.7,f8.1) + + sec=sec + sec_step + enddo + go to 999 +900 print*,'Cannot open file ',trim(infile) +999 end program emedop + + + diff --git a/lib/encode232.f90 b/lib/encode232.f90 index 6ce8e5eb..491f204a 100755 --- a/lib/encode232.f90 +++ b/lib/encode232.f90 @@ -1,33 +1,33 @@ -subroutine encode232(dat,nsym,symbol) - -! Convolutional encoder for a K=32, r=1/2 code. - - integer*1 dat(13) !User data, packed 8 bits per byte - integer*1 symbol(206) !Channel symbols, one bit per byte - integer*1 i1 - include 'conv232.f90' - - nstate=0 - k=0 - do j=1,nsym - do i=7,0,-1 - i1=dat(j) - i4=i1 - if (i4.lt.0) i4=i4+256 - nstate=ior(ishft(nstate,1),iand(ishft(i4,-i),1)) - n=iand(nstate,npoly1) - n=ieor(n,ishft(n,-16)) - k=k+1 - symbol(k)=partab(iand(ieor(n,ishft(n,-8)),255)) - n=iand(nstate,npoly2) - n=ieor(n,ishft(n,-16)) - k=k+1 - symbol(k)=partab(iand(ieor(n,ishft(n,-8)),255)) - if(k.ge.nsym) go to 100 - enddo - enddo - -100 continue - - return -end subroutine encode232 +subroutine encode232(dat,nsym,symbol) + +! Convolutional encoder for a K=32, r=1/2 code. + + integer*1 dat(13) !User data, packed 8 bits per byte + integer*1 symbol(206) !Channel symbols, one bit per byte + integer*1 i1 + include 'conv232.f90' + + nstate=0 + k=0 + do j=1,nsym + do i=7,0,-1 + i1=dat(j) + i4=i1 + if (i4.lt.0) i4=i4+256 + nstate=ior(ishft(nstate,1),iand(ishft(i4,-i),1)) + n=iand(nstate,npoly1) + n=ieor(n,ishft(n,-16)) + k=k+1 + symbol(k)=partab(iand(ieor(n,ishft(n,-8)),255)) + n=iand(nstate,npoly2) + n=ieor(n,ishft(n,-16)) + k=k+1 + symbol(k)=partab(iand(ieor(n,ishft(n,-8)),255)) + if(k.ge.nsym) go to 100 + enddo + enddo + +100 continue + + return +end subroutine encode232 diff --git a/lib/encode4.f90 b/lib/encode4.f90 index dfeae11e..bf1f0a8f 100755 --- a/lib/encode4.f90 +++ b/lib/encode4.f90 @@ -1,20 +1,20 @@ -subroutine encode4(message,ncode) - - use packjt - parameter (MAXCALLS=7000,MAXRPT=63) - integer ncode(206) - character*22 message !Message to be generated - character*3 cok !' ' or 'OOO' - integer dgen(13) - integer*1 data0(13),symbol(216) - - call chkmsg(message,cok,nspecial,flip) - call packmsg(message,dgen,itype) !Pack 72-bit message into 12 six-bit symbols - call entail(dgen,data0) - call encode232(data0,206,symbol) !Convolutional encoding - call interleave4(symbol,1) !Apply JT4 interleaving - do i=1,206 - ncode(i)=symbol(i) - enddo - -end subroutine encode4 +subroutine encode4(message,ncode) + + use packjt + parameter (MAXCALLS=7000,MAXRPT=63) + integer ncode(206) + character*22 message !Message to be generated + character*3 cok !' ' or 'OOO' + integer dgen(13) + integer*1 data0(13),symbol(216) + + call chkmsg(message,cok,nspecial,flip) + call packmsg(message,dgen,itype) !Pack 72-bit message into 12 six-bit symbols + call entail(dgen,data0) + call encode232(data0,206,symbol) !Convolutional encoding + call interleave4(symbol,1) !Apply JT4 interleaving + do i=1,206 + ncode(i)=symbol(i) + enddo + +end subroutine encode4 diff --git a/lib/encode_128_90.f90 b/lib/encode_128_90.f90 index 6e535bcf..e59cf11b 100755 --- a/lib/encode_128_90.f90 +++ b/lib/encode_128_90.f90 @@ -1,58 +1,58 @@ -subroutine encode_128_90(message77,codeword) -! -! Add a 13-bit CRC to a 77-bit message and return a 128-bit codeword -! -use, intrinsic :: iso_c_binding -use iso_c_binding, only: c_loc,c_size_t -use crc - -integer, parameter:: N=128, K=90, M=N-K -character*90 tmpchar -integer*1 codeword(N) -integer*1 gen(M,K) -integer*1 message77(77),message(K) -integer*1 pchecks(M) -integer*1, target :: i1MsgBytes(12) -include "ldpc_128_90_generator.f90" -logical first -data first/.true./ -save first,gen - -if( first ) then ! fill the generator matrix - gen=0 - do i=1,M - do j=1,23 - read(g(i)(j:j),"(Z1)") istr - ibmax=4 - if(j.eq.23) ibmax=2 - do jj=1, ibmax - icol=(j-1)*4+jj - if( btest(istr,4-jj) ) gen(i,icol)=1 - enddo - enddo - enddo -first=.false. -endif - -! Add 13 bit CRC to form 90-bit message+CRC13 -write(tmpchar,'(77i1)') message77 -tmpchar(78:80)='000' -i1MsgBytes=0 -read(tmpchar,'(10b8)') i1MsgBytes(1:10) -ncrc13 = crc13 (c_loc (i1MsgBytes), 12) -write(tmpchar(78:90),'(b13)') ncrc13 -read(tmpchar,'(90i1)') message - -do i=1,M - nsum=0 - do j=1,K - nsum=nsum+message(j)*gen(i,j) - enddo - pchecks(i)=mod(nsum,2) -enddo - -codeword(1:K)=message -codeword(K+1:N)=pchecks - -return -end subroutine encode_128_90 +subroutine encode_128_90(message77,codeword) +! +! Add a 13-bit CRC to a 77-bit message and return a 128-bit codeword +! +use, intrinsic :: iso_c_binding +use iso_c_binding, only: c_loc,c_size_t +use crc + +integer, parameter:: N=128, K=90, M=N-K +character*90 tmpchar +integer*1 codeword(N) +integer*1 gen(M,K) +integer*1 message77(77),message(K) +integer*1 pchecks(M) +integer*1, target :: i1MsgBytes(12) +include "ldpc_128_90_generator.f90" +logical first +data first/.true./ +save first,gen + +if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,23 + read(g(i)(j:j),"(Z1)") istr + ibmax=4 + if(j.eq.23) ibmax=2 + do jj=1, ibmax + icol=(j-1)*4+jj + if( btest(istr,4-jj) ) gen(i,icol)=1 + enddo + enddo + enddo +first=.false. +endif + +! Add 13 bit CRC to form 90-bit message+CRC13 +write(tmpchar,'(77i1)') message77 +tmpchar(78:80)='000' +i1MsgBytes=0 +read(tmpchar,'(10b8)') i1MsgBytes(1:10) +ncrc13 = crc13 (c_loc (i1MsgBytes), 12) +write(tmpchar(78:90),'(b13)') ncrc13 +read(tmpchar,'(90i1)') message + +do i=1,M + nsum=0 + do j=1,K + nsum=nsum+message(j)*gen(i,j) + enddo + pchecks(i)=mod(nsum,2) +enddo + +codeword(1:K)=message +codeword(K+1:N)=pchecks + +return +end subroutine encode_128_90 diff --git a/lib/encode_msk40.f90 b/lib/encode_msk40.f90 index 5f1dc429..9c53255b 100755 --- a/lib/encode_msk40.f90 +++ b/lib/encode_msk40.f90 @@ -1,46 +1,46 @@ -subroutine encode_msk40(message,codeword) -! Encode a 16-bit message and return a 32-bit codeword. -! The code is a (32,16) regular ldpc code with column weight 3. -! The code was generated using the PEG algorithm. -! After creating the codeword, the columns are re-ordered according to -! "colorder" to make the codeword compatible with the parity-check -! matrix stored in Radford Neal's "pchk" format. -! -integer*1 codeword(32) -integer*1 colorder(32) -integer g(16) -integer*1 gen40(16,16) -integer*1 itmp(32) -integer*1 message(16) -integer*1 pchecks(16) -logical first -data first/.true./ -data g/Z'4428',Z'5a6b',Z'1b04',Z'2c12',Z'60c4',Z'1071',Z'be6a',Z'36dd', & - Z'c580',Z'ad9a',Z'eca2',Z'7843',Z'332e',Z'a685',Z'5906',Z'1efe'/ -data colorder/4,1,2,3,0,8,6,10,13,28,20,23,17,15,27,25, & - 16,12,18,19,7,21,22,11,24,5,26,14,9,29,30,31/ -save first,gen40 - -if( first ) then ! fill the generator matrix - gen40=0 - do i=1,16 - do j=1,16 - if( btest(g(i),16-j) ) gen40(i,j)=1 - enddo - enddo - first=.false. -endif - -do i=1,16 - nsum=0 - do j=1,16 - nsum=nsum+message(j)*gen40(i,j) - enddo - pchecks(i)=mod(nsum,2) -enddo -itmp(1:16)=pchecks -itmp(17:32)=message(1:16) -codeword(colorder+1)=itmp(1:32) - -return -end subroutine encode_msk40 +subroutine encode_msk40(message,codeword) +! Encode a 16-bit message and return a 32-bit codeword. +! The code is a (32,16) regular ldpc code with column weight 3. +! The code was generated using the PEG algorithm. +! After creating the codeword, the columns are re-ordered according to +! "colorder" to make the codeword compatible with the parity-check +! matrix stored in Radford Neal's "pchk" format. +! +integer*1 codeword(32) +integer*1 colorder(32) +integer g(16) +integer*1 gen40(16,16) +integer*1 itmp(32) +integer*1 message(16) +integer*1 pchecks(16) +logical first +data first/.true./ +data g/Z'4428',Z'5a6b',Z'1b04',Z'2c12',Z'60c4',Z'1071',Z'be6a',Z'36dd', & + Z'c580',Z'ad9a',Z'eca2',Z'7843',Z'332e',Z'a685',Z'5906',Z'1efe'/ +data colorder/4,1,2,3,0,8,6,10,13,28,20,23,17,15,27,25, & + 16,12,18,19,7,21,22,11,24,5,26,14,9,29,30,31/ +save first,gen40 + +if( first ) then ! fill the generator matrix + gen40=0 + do i=1,16 + do j=1,16 + if( btest(g(i),16-j) ) gen40(i,j)=1 + enddo + enddo + first=.false. +endif + +do i=1,16 + nsum=0 + do j=1,16 + nsum=nsum+message(j)*gen40(i,j) + enddo + pchecks(i)=mod(nsum,2) +enddo +itmp(1:16)=pchecks +itmp(17:32)=message(1:16) +codeword(colorder+1)=itmp(1:32) + +return +end subroutine encode_msk40 diff --git a/lib/encode_rs.c b/lib/encode_rs.c index 26b81c46..9d56d0bf 100755 --- a/lib/encode_rs.c +++ b/lib/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 - -#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 + +#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=0) -! ltext true if decoded message is free text -! nft 0=no decode; 1=FT decode; 2=hinted decode - - use prog_args !shm_key, exe_dir, data_dir - use packjt - use jt65_mod - use timer_module, only: timer - - real s3(64,63) - character decoded*22, apmessage*22 - character*12 mycall_12,hiscall_12 - character*6 mycall,hiscall,hisgrid - character*6 mycall0,hiscall0,hisgrid0 - integer apsymbols(7,12),ap(12) - integer nappasses(0:5) ! the number of decoding passes to use for each QSO state - integer naptypes(0:5,4) ! (nQSOProgress, decoding pass) maximum of 4 passes for now - integer dat4(12) - integer mrsym(63),mr2sym(63),mrprob(63),mr2prob(63) - integer correct(63),tmp(63) - logical first,ltext,ljt65apon - common/chansyms65/correct - data first/.true./ - save - - if(mode65.eq.-99) stop !Silence compiler warning - if(first) then - -! aptype -!------------------------ -! 1 CQ ??? ??? -! 2 MyCall ??? ??? -! 3 MyCall DxCall ??? -! 4 MyCall DxCall RRR -! 5 MyCall DxCall 73 -! 6 MyCall DxCall DxGrid -! 7 CQ DxCall DxGrid - - apsymbols=-1 - nappasses=(/3,4,2,3,3,4/) - naptypes(0,1:4)=(/1,2,6,0/) ! Tx6 - naptypes(1,1:4)=(/2,3,6,7/) ! Tx1 - naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 - naptypes(3,1:4)=(/3,4,5,0/) ! Tx3 - naptypes(4,1:4)=(/3,4,5,0/) ! Tx4 - naptypes(5,1:4)=(/2,3,4,5/) ! Tx5 - first=.false. - endif - - mycall=mycall_12(1:6) - hiscall=hiscall_12(1:6) -! Fill apsymbols array - if(ljt65apon .and. & - (mycall.ne.mycall0 .or. hiscall.ne.hiscall0 .or. hisgrid.ne.hisgrid0)) then -!write(*,*) 'initializing apsymbols ' - apsymbols=-1 - mycall0=mycall - hiscall0=hiscall - ap=-1 - apsymbols(1,1:4)=(/62,32,32,49/) ! CQ - if(len_trim(mycall).gt.0) then - apmessage=mycall//" "//mycall//" RRR" - call packmsg(apmessage,ap,itype) - if(itype.ne.1) ap=-1 - apsymbols(2,1:4)=ap(1:4) -!write(*,*) 'mycall symbols ',ap(1:4) - if(len_trim(hiscall).gt.0) then - apmessage=mycall//" "//hiscall//" RRR" - call packmsg(apmessage,ap,itype) - if(itype.ne.1) ap=-1 - apsymbols(3,1:9)=ap(1:9) - apsymbols(4,:)=ap - apmessage=mycall//" "//hiscall//" 73" - call packmsg(apmessage,ap,itype) - if(itype.ne.1) ap=-1 - apsymbols(5,:)=ap - if(len_trim(hisgrid(1:4)).gt.0) then - apmessage=mycall//' '//hiscall//' '//hisgrid(1:4) - call packmsg(apmessage,ap,itype) - if(itype.ne.1) ap=-1 - apsymbols(6,:)=ap - apmessage='CQ'//' '//hiscall//' '//hisgrid(1:4) - call packmsg(apmessage,ap,itype) - if(itype.ne.1) ap=-1 - apsymbols(7,:)=ap - endif - endif - endif - endif - - qual=0. - nbirdie=20 - npct=50 - afac1=1.1 - nft=0 - nfail=0 - decoded=' ' - call pctile(s3,4032,npct,base) - s3=s3/base - s3a=s3 !### - -! Get most reliable and second-most-reliable symbol values, and their -! probabilities -1 call demod64a(s3,nadd,afac1,mrsym,mrprob,mr2sym,mr2prob,ntest,nlow) - - call chkhist(mrsym,nhist,ipk) !Test for birdies and QRM - if(nhist.ge.nbirdie) then - nfail=nfail+1 - call pctile(s3,4032,npct,base) - 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 graycode65(mrsym,63,-1) !Remove gray code - call interleave63(mrsym,-1) !Remove interleaving - call interleave63(mrprob,-1) - - call graycode65(mr2sym,63,-1) !Remove gray code and interleaving - call interleave63(mr2sym,-1) !from second-most-reliable symbols - call interleave63(mr2prob,-1) - - npass=1 ! if ap decoding is disabled - if(ljt65apon .and. len_trim(mycall).gt.0) then - npass=1+nappasses(nQSOProgress) -!write(*,*) 'ap is on: ',npass-1,'ap passes of types ',naptypes(nQSOProgress,:) - endif - do ipass=1,npass - ap=-1 - ntype=0 - if(ipass.gt.1) then - ntype=naptypes(nQSOProgress,ipass-1) -!write(*,*) 'ap pass, type ',ntype - ap=apsymbols(ntype,:) - if(count(ap.ge.0).eq.0) cycle ! don't bother if all ap symbols are -1 -!write(*,'(12i3)') ap - endif - ntry=0 - call timer('ftrsd ',0) - param=0 - call ftrsdap(mrsym,mrprob,mr2sym,mr2prob,ap,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 - r0=0.87 - if(naggressive.eq.10) then - nd0=83 - r0=0.90 - endif - - if(ntotal.le.nd0 .and. rtt.le.r0) then - nft=1+ishft(ntype,2) - endif - - if(nft.gt.0) exit - enddo - if(nft.eq.0 .and. iand(ndepth,32).eq.32) then - qmin=2.0 - 0.1*naggressive - call timer('hint65 ',0) - call hint65(s3,mrs,mrs2,nadd,nflip,mycall,hiscall,hisgrid,qual,decoded) - if(qual.ge.qmin) then - nft=2 - ncount=0 - else - decoded=' ' - ntry=0 - endif - call timer('hint65 ',1) - go to 900 - endif - - 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 - tmp(i)=correct(64-i) - enddo - correct(1:63)=tmp(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=' ' - - return -end subroutine extract - -subroutine getpp(workdat,p) - - use jt65_mod - integer workdat(63) - integer a(63) - - a(1:63)=workdat(63:1:-1) - call interleave63(a,1) - call graycode(a,63,1,a) - - 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,mode65,ntrials,naggressive,ndepth,nflip, & + mycall_12,hiscall_12,hisgrid,nQSOProgress,ljt65apon, & + ncount,nhist,decoded,ltext,nft,qual) + +! Input: +! s3 64-point spectra for each of 63 data symbols +! nadd number of spectra summed into s3 +! nqd 0/1 to indicate decode attempt at QSO frequency + +! Output: +! ncount number of symbols requiring correction (-1 for no KV decode) +! nhist maximum number of identical symbol values +! decoded decoded message (if ncount >=0) +! ltext true if decoded message is free text +! nft 0=no decode; 1=FT decode; 2=hinted decode + + use prog_args !shm_key, exe_dir, data_dir + use packjt + use jt65_mod + use timer_module, only: timer + + real s3(64,63) + character decoded*22, apmessage*22 + character*12 mycall_12,hiscall_12 + character*6 mycall,hiscall,hisgrid + character*6 mycall0,hiscall0,hisgrid0 + integer apsymbols(7,12),ap(12) + integer nappasses(0:5) ! the number of decoding passes to use for each QSO state + integer naptypes(0:5,4) ! (nQSOProgress, decoding pass) maximum of 4 passes for now + integer dat4(12) + integer mrsym(63),mr2sym(63),mrprob(63),mr2prob(63) + integer correct(63),tmp(63) + logical first,ltext,ljt65apon + common/chansyms65/correct + data first/.true./ + save + + if(mode65.eq.-99) stop !Silence compiler warning + if(first) then + +! aptype +!------------------------ +! 1 CQ ??? ??? +! 2 MyCall ??? ??? +! 3 MyCall DxCall ??? +! 4 MyCall DxCall RRR +! 5 MyCall DxCall 73 +! 6 MyCall DxCall DxGrid +! 7 CQ DxCall DxGrid + + apsymbols=-1 + nappasses=(/3,4,2,3,3,4/) + naptypes(0,1:4)=(/1,2,6,0/) ! Tx6 + naptypes(1,1:4)=(/2,3,6,7/) ! Tx1 + naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 + naptypes(3,1:4)=(/3,4,5,0/) ! Tx3 + naptypes(4,1:4)=(/3,4,5,0/) ! Tx4 + naptypes(5,1:4)=(/2,3,4,5/) ! Tx5 + first=.false. + endif + + mycall=mycall_12(1:6) + hiscall=hiscall_12(1:6) +! Fill apsymbols array + if(ljt65apon .and. & + (mycall.ne.mycall0 .or. hiscall.ne.hiscall0 .or. hisgrid.ne.hisgrid0)) then +!write(*,*) 'initializing apsymbols ' + apsymbols=-1 + mycall0=mycall + hiscall0=hiscall + ap=-1 + apsymbols(1,1:4)=(/62,32,32,49/) ! CQ + if(len_trim(mycall).gt.0) then + apmessage=mycall//" "//mycall//" RRR" + call packmsg(apmessage,ap,itype) + if(itype.ne.1) ap=-1 + apsymbols(2,1:4)=ap(1:4) +!write(*,*) 'mycall symbols ',ap(1:4) + if(len_trim(hiscall).gt.0) then + apmessage=mycall//" "//hiscall//" RRR" + call packmsg(apmessage,ap,itype) + if(itype.ne.1) ap=-1 + apsymbols(3,1:9)=ap(1:9) + apsymbols(4,:)=ap + apmessage=mycall//" "//hiscall//" 73" + call packmsg(apmessage,ap,itype) + if(itype.ne.1) ap=-1 + apsymbols(5,:)=ap + if(len_trim(hisgrid(1:4)).gt.0) then + apmessage=mycall//' '//hiscall//' '//hisgrid(1:4) + call packmsg(apmessage,ap,itype) + if(itype.ne.1) ap=-1 + apsymbols(6,:)=ap + apmessage='CQ'//' '//hiscall//' '//hisgrid(1:4) + call packmsg(apmessage,ap,itype) + if(itype.ne.1) ap=-1 + apsymbols(7,:)=ap + endif + endif + endif + endif + + qual=0. + nbirdie=20 + npct=50 + afac1=1.1 + nft=0 + nfail=0 + decoded=' ' + call pctile(s3,4032,npct,base) + s3=s3/base + s3a=s3 !### + +! Get most reliable and second-most-reliable symbol values, and their +! probabilities +1 call demod64a(s3,nadd,afac1,mrsym,mrprob,mr2sym,mr2prob,ntest,nlow) + + call chkhist(mrsym,nhist,ipk) !Test for birdies and QRM + if(nhist.ge.nbirdie) then + nfail=nfail+1 + call pctile(s3,4032,npct,base) + 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 graycode65(mrsym,63,-1) !Remove gray code + call interleave63(mrsym,-1) !Remove interleaving + call interleave63(mrprob,-1) + + call graycode65(mr2sym,63,-1) !Remove gray code and interleaving + call interleave63(mr2sym,-1) !from second-most-reliable symbols + call interleave63(mr2prob,-1) + + npass=1 ! if ap decoding is disabled + if(ljt65apon .and. len_trim(mycall).gt.0) then + npass=1+nappasses(nQSOProgress) +!write(*,*) 'ap is on: ',npass-1,'ap passes of types ',naptypes(nQSOProgress,:) + endif + do ipass=1,npass + ap=-1 + ntype=0 + if(ipass.gt.1) then + ntype=naptypes(nQSOProgress,ipass-1) +!write(*,*) 'ap pass, type ',ntype + ap=apsymbols(ntype,:) + if(count(ap.ge.0).eq.0) cycle ! don't bother if all ap symbols are -1 +!write(*,'(12i3)') ap + endif + ntry=0 + call timer('ftrsd ',0) + param=0 + call ftrsdap(mrsym,mrprob,mr2sym,mr2prob,ap,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 + r0=0.87 + if(naggressive.eq.10) then + nd0=83 + r0=0.90 + endif + + if(ntotal.le.nd0 .and. rtt.le.r0) then + nft=1+ishft(ntype,2) + endif + + if(nft.gt.0) exit + enddo + if(nft.eq.0 .and. iand(ndepth,32).eq.32) then + qmin=2.0 - 0.1*naggressive + call timer('hint65 ',0) + call hint65(s3,mrs,mrs2,nadd,nflip,mycall,hiscall,hisgrid,qual,decoded) + if(qual.ge.qmin) then + nft=2 + ncount=0 + else + decoded=' ' + ntry=0 + endif + call timer('hint65 ',1) + go to 900 + endif + + 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 + tmp(i)=correct(64-i) + enddo + correct(1:63)=tmp(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=' ' + + return +end subroutine extract + +subroutine getpp(workdat,p) + + use jt65_mod + integer workdat(63) + integer a(63) + + a(1:63)=workdat(63:1:-1) + call interleave63(a,1) + call graycode(a,63,1,a) + + 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/lib/extract4.f90 b/lib/extract4.f90 index b198561a..ce8fb86a 100755 --- a/lib/extract4.f90 +++ b/lib/extract4.f90 @@ -1,69 +1,69 @@ -subroutine extract4(sym0,ncount,decoded) - - use packjt - real sym0(207) - real sym(207) - character decoded*22 - character*72 c72 - integer*1 symbol(207) - integer*1 data1(13) !Decoded data (8-bit bytes) - integer data4a(9) !Decoded data (8-bit bytes) - integer data4(12) !Decoded data (6-bit bytes) - integer mettab(-128:127,0:1) !Metric table - logical first - data first/.true./ - save first,mettab,ndelta - - if(first) then - call getmet4(mettab,ndelta) - first=.false. - endif - -!### Optimize these params: ... - amp=30.0 - limit=10000 - - ave0=sum(sym0)/207.0 - sym=sym0-ave0 - sq=dot_product(sym,sym) - rms0=sqrt(sq/206.0) - sym=sym/rms0 - - do j=1,207 - n=nint(amp*sym(j)) - if(n.lt.-127) n=-127 - if(n.gt.127) n=127 - symbol(j)=n - enddo - - nbits=72 - ncycles=0 - ncount=-1 - decoded=' ' - call interleave4(symbol(2),-1) !Remove the interleaving - call fano232(symbol(2),nbits+31,mettab,ndelta,limit,data1, & - ncycles,metric,ncount) - nlim=ncycles/(nbits+31) - -!### Make usage here like that in jt9fano... - if(ncount.ge.0) then - do i=1,9 - i4=data1(i) - if(i4.lt.0) i4=i4+256 - data4a(i)=i4 - enddo - write(c72,1100) (data4a(i),i=1,9) -1100 format(9b8.8) - read(c72,1102) data4 -1102 format(12b6) - - call unpackmsg(data4,decoded) - if(decoded(1:6).eq.'000AAA') then -! decoded='***WRONG MODE?***' - decoded=' ' - ncount=-1 - endif - endif - - return -end subroutine extract4 +subroutine extract4(sym0,ncount,decoded) + + use packjt + real sym0(207) + real sym(207) + character decoded*22 + character*72 c72 + integer*1 symbol(207) + integer*1 data1(13) !Decoded data (8-bit bytes) + integer data4a(9) !Decoded data (8-bit bytes) + integer data4(12) !Decoded data (6-bit bytes) + integer mettab(-128:127,0:1) !Metric table + logical first + data first/.true./ + save first,mettab,ndelta + + if(first) then + call getmet4(mettab,ndelta) + first=.false. + endif + +!### Optimize these params: ... + amp=30.0 + limit=10000 + + ave0=sum(sym0)/207.0 + sym=sym0-ave0 + sq=dot_product(sym,sym) + rms0=sqrt(sq/206.0) + sym=sym/rms0 + + do j=1,207 + n=nint(amp*sym(j)) + if(n.lt.-127) n=-127 + if(n.gt.127) n=127 + symbol(j)=n + enddo + + nbits=72 + ncycles=0 + ncount=-1 + decoded=' ' + call interleave4(symbol(2),-1) !Remove the interleaving + call fano232(symbol(2),nbits+31,mettab,ndelta,limit,data1, & + ncycles,metric,ncount) + nlim=ncycles/(nbits+31) + +!### Make usage here like that in jt9fano... + if(ncount.ge.0) then + do i=1,9 + i4=data1(i) + if(i4.lt.0) i4=i4+256 + data4a(i)=i4 + enddo + write(c72,1100) (data4a(i),i=1,9) +1100 format(9b8.8) + read(c72,1102) data4 +1102 format(12b6) + + call unpackmsg(data4,decoded) + if(decoded(1:6).eq.'000AAA') then +! decoded='***WRONG MODE?***' + decoded=' ' + ncount=-1 + endif + endif + + return +end subroutine extract4 diff --git a/lib/extractmessage77.f90 b/lib/extractmessage77.f90 index 869d951e..d2b41e32 100755 --- a/lib/extractmessage77.f90 +++ b/lib/extractmessage77.f90 @@ -1,17 +1,17 @@ -subroutine extractmessage77(decoded77,msgreceived) - use packjt - - character*22 msgreceived - character*77 cbits - integer*1 decoded77(77) - integer*4 i4Dec6BitWords(12) - - write(cbits,'(77i1)') decoded77 -!**** Temporary: For now, just handle i5bit=0. - read(cbits,'(12b6)') i4Dec6BitWords - read(cbits,'(72x,i5.5)') i5bit - if( i5bit .eq. 0 ) then - call unpackmsg(i4Dec6BitWords,msgreceived) - endif - return -end subroutine extractmessage77 +subroutine extractmessage77(decoded77,msgreceived) + use packjt + + character*22 msgreceived + character*77 cbits + integer*1 decoded77(77) + integer*4 i4Dec6BitWords(12) + + write(cbits,'(77i1)') decoded77 +!**** Temporary: For now, just handle i5bit=0. + read(cbits,'(12b6)') i4Dec6BitWords + read(cbits,'(72x,i5.5)') i5bit + if( i5bit .eq. 0 ) then + call unpackmsg(i4Dec6BitWords,msgreceived) + endif + return +end subroutine extractmessage77 diff --git a/lib/fano232.f90 b/lib/fano232.f90 index 1ab4c42f..8888624c 100755 --- a/lib/fano232.f90 +++ b/lib/fano232.f90 @@ -1,138 +1,138 @@ -subroutine fano232(symbol,nbits,mettab,ndelta,maxcycles,dat, & - ncycles,metric,ierr) - -! Sequential decoder for K=32, r=1/2 convolutional code using -! the Fano algorithm. Translated from C routine for same purpose -! written by Phil Karn, KA9Q. - - parameter (MAXBITS=103) - parameter (MAXBYTES=13) !(MAXBITS+7)/8 - integer*1 symbol(0:2*MAXBITS-1) !Soft symbols (as unsigned i*1) - integer*1 dat(MAXBYTES) !Decoded user data, 8 bits per byte - integer mettab(-128:127,0:1) !Metric table - -! These were the "node" structure in Karn's C code: - integer nstate(0:MAXBITS) !Encoder state of next node - integer gamma(0:MAXBITS) !Cumulative metric to this node - integer metrics(0:3,0:MAXBITS) !Metrics indexed by all possible Tx syms - integer tm(0:1,0:MAXBITS) !Sorted metrics for current hypotheses - integer ii(0:MAXBITS) !Current branch being tested - - logical noback - include 'conv232.f90' !Polynomials defined here - - ntail=nbits-31 - -! Compute all possible branch metrics for each symbol pair. -! This is the only place we actually look at the raw input symbols - i4a=0 - i4b=0 - do np=0,nbits-1 - j=2*np - i4a=symbol(j) - i4b=symbol(j+1) - metrics(0,np) = mettab(i4a,0) + mettab(i4b,0) - metrics(1,np) = mettab(i4a,0) + mettab(i4b,1) - metrics(2,np) = mettab(i4a,1) + mettab(i4b,0) - metrics(3,np) = mettab(i4a,1) + mettab(i4b,1) - enddo - - np=0 - nstate(np)=0 - - n=iand(nstate(np),npoly1) !Compute and sort branch metrics - n=ieor(n,ishft(n,-16)) !from the root node - lsym=partab(iand(ieor(n,ishft(n,-8)),255)) - n=iand(nstate(np),npoly2) - n=ieor(n,ishft(n,-16)) - lsym=lsym+lsym+partab(iand(ieor(n,ishft(n,-8)),255)) - m0=metrics(lsym,np) - m1=metrics(ieor(3,lsym),np) - if(m0.gt.m1) then - tm(0,np)=m0 !0-branch has better metric - tm(1,np)=m1 - else - tm(0,np)=m1 !1-branch is better - tm(1,np)=m0 - nstate(np)=nstate(np) + 1 !Set low bit - endif - - ii(np)=0 !Start with best branch - gamma(np)=0 - nt=0 - - do i=1,nbits*maxcycles !Start the Fano decoder - ngamma=gamma(np) + tm(ii(np),np) !Look forward - if(ngamma.ge.nt) then -! Node is acceptable. If first time visiting this node, tighten threshold: - if(gamma(np).lt.(nt+ndelta)) nt=nt + ndelta * ((ngamma-nt)/ndelta) - gamma(np+1)=ngamma !Move forward - nstate(np+1)=ishft(nstate(np),1) - np=np+1 - if(np.eq.nbits) go to 100 !We're done! - - n=iand(nstate(np),npoly1) - n=ieor(n,ishft(n,-16)) - lsym=partab(iand(ieor(n,ishft(n,-8)),255)) - n=iand(nstate(np),npoly2) - n=ieor(n,ishft(n,-16)) - lsym=lsym+lsym+partab(iand(ieor(n,ishft(n,-8)),255)) - - if(np.ge.ntail) then - tm(0,np)=metrics(lsym,np) !We're in the tail, now all zeros - else - m0=metrics(lsym,np) - m1=metrics(ieor(3,lsym),np) - if(m0.gt.m1) then - tm(0,np)=m0 !0-branch has better metric - tm(1,np)=m1 - else - tm(0,np)=m1 !1-branch is better - tm(1,np)=m0 - nstate(np)=nstate(np) + 1 !Set low bit - endif - endif - ii(np)=0 !Start with best branch - else - do while(.true.) - noback=.false. !Threshold violated, can't go forward - if(np.eq.0) noback=.true. - if(np.gt.0) then - if(gamma(np-1).lt.nt) noback=.true. - endif - - if(noback) then !Can't back up, either - nt=nt-ndelta !Relax threshold and look forward again - if(ii(np).ne.0) then - ii(np)=0 - nstate(np)=ieor(nstate(np),1) - endif - exit - endif - - np=np-1 !Back up - if(np.lt.ntail .and. ii(np).ne.1) then - ii(np)=ii(np)+1 !Search the next best branch - nstate(np)=ieor(nstate(np),1) - exit - endif - enddo - endif - enddo - i=nbits*maxcycles - -100 metric=gamma(np) !Final path metric - nbytes=(nbits+7)/8 !Copy decoded data to user's buffer - np=7 - do j=1,nbytes-1 - i4a=nstate(np) - dat(j)=int(i4a,1) - np=np+8 - enddo - dat(nbytes)=0 - ncycles=i+1 - ierr=0 - if(i.ge.maxcycles*nbits) ierr=-1 - - return -end subroutine fano232 +subroutine fano232(symbol,nbits,mettab,ndelta,maxcycles,dat, & + ncycles,metric,ierr) + +! Sequential decoder for K=32, r=1/2 convolutional code using +! the Fano algorithm. Translated from C routine for same purpose +! written by Phil Karn, KA9Q. + + parameter (MAXBITS=103) + parameter (MAXBYTES=13) !(MAXBITS+7)/8 + integer*1 symbol(0:2*MAXBITS-1) !Soft symbols (as unsigned i*1) + integer*1 dat(MAXBYTES) !Decoded user data, 8 bits per byte + integer mettab(-128:127,0:1) !Metric table + +! These were the "node" structure in Karn's C code: + integer nstate(0:MAXBITS) !Encoder state of next node + integer gamma(0:MAXBITS) !Cumulative metric to this node + integer metrics(0:3,0:MAXBITS) !Metrics indexed by all possible Tx syms + integer tm(0:1,0:MAXBITS) !Sorted metrics for current hypotheses + integer ii(0:MAXBITS) !Current branch being tested + + logical noback + include 'conv232.f90' !Polynomials defined here + + ntail=nbits-31 + +! Compute all possible branch metrics for each symbol pair. +! This is the only place we actually look at the raw input symbols + i4a=0 + i4b=0 + do np=0,nbits-1 + j=2*np + i4a=symbol(j) + i4b=symbol(j+1) + metrics(0,np) = mettab(i4a,0) + mettab(i4b,0) + metrics(1,np) = mettab(i4a,0) + mettab(i4b,1) + metrics(2,np) = mettab(i4a,1) + mettab(i4b,0) + metrics(3,np) = mettab(i4a,1) + mettab(i4b,1) + enddo + + np=0 + nstate(np)=0 + + n=iand(nstate(np),npoly1) !Compute and sort branch metrics + n=ieor(n,ishft(n,-16)) !from the root node + lsym=partab(iand(ieor(n,ishft(n,-8)),255)) + n=iand(nstate(np),npoly2) + n=ieor(n,ishft(n,-16)) + lsym=lsym+lsym+partab(iand(ieor(n,ishft(n,-8)),255)) + m0=metrics(lsym,np) + m1=metrics(ieor(3,lsym),np) + if(m0.gt.m1) then + tm(0,np)=m0 !0-branch has better metric + tm(1,np)=m1 + else + tm(0,np)=m1 !1-branch is better + tm(1,np)=m0 + nstate(np)=nstate(np) + 1 !Set low bit + endif + + ii(np)=0 !Start with best branch + gamma(np)=0 + nt=0 + + do i=1,nbits*maxcycles !Start the Fano decoder + ngamma=gamma(np) + tm(ii(np),np) !Look forward + if(ngamma.ge.nt) then +! Node is acceptable. If first time visiting this node, tighten threshold: + if(gamma(np).lt.(nt+ndelta)) nt=nt + ndelta * ((ngamma-nt)/ndelta) + gamma(np+1)=ngamma !Move forward + nstate(np+1)=ishft(nstate(np),1) + np=np+1 + if(np.eq.nbits) go to 100 !We're done! + + n=iand(nstate(np),npoly1) + n=ieor(n,ishft(n,-16)) + lsym=partab(iand(ieor(n,ishft(n,-8)),255)) + n=iand(nstate(np),npoly2) + n=ieor(n,ishft(n,-16)) + lsym=lsym+lsym+partab(iand(ieor(n,ishft(n,-8)),255)) + + if(np.ge.ntail) then + tm(0,np)=metrics(lsym,np) !We're in the tail, now all zeros + else + m0=metrics(lsym,np) + m1=metrics(ieor(3,lsym),np) + if(m0.gt.m1) then + tm(0,np)=m0 !0-branch has better metric + tm(1,np)=m1 + else + tm(0,np)=m1 !1-branch is better + tm(1,np)=m0 + nstate(np)=nstate(np) + 1 !Set low bit + endif + endif + ii(np)=0 !Start with best branch + else + do while(.true.) + noback=.false. !Threshold violated, can't go forward + if(np.eq.0) noback=.true. + if(np.gt.0) then + if(gamma(np-1).lt.nt) noback=.true. + endif + + if(noback) then !Can't back up, either + nt=nt-ndelta !Relax threshold and look forward again + if(ii(np).ne.0) then + ii(np)=0 + nstate(np)=ieor(nstate(np),1) + endif + exit + endif + + np=np-1 !Back up + if(np.lt.ntail .and. ii(np).ne.1) then + ii(np)=ii(np)+1 !Search the next best branch + nstate(np)=ieor(nstate(np),1) + exit + endif + enddo + endif + enddo + i=nbits*maxcycles + +100 metric=gamma(np) !Final path metric + nbytes=(nbits+7)/8 !Copy decoded data to user's buffer + np=7 + do j=1,nbytes-1 + i4a=nstate(np) + dat(j)=int(i4a,1) + np=np+8 + enddo + dat(nbytes)=0 + ncycles=i+1 + ierr=0 + if(i.ge.maxcycles*nbits) ierr=-1 + + return +end subroutine fano232 diff --git a/lib/fast9.f90 b/lib/fast9.f90 index 1dfb9773..12148624 100755 --- a/lib/fast9.f90 +++ b/lib/fast9.f90 @@ -1,191 +1,191 @@ -subroutine fast9(id2,narg,line) - -! Decoder for "fast9" modes, JT9E to JT9H. - - parameter (NMAX=30*12000,NSAVE=500) - integer*2 id2(0:NMAX) - integer narg(0:14) - integer*1 i1SoftSymbols(207) - integer*1 i1save(207,NSAVE) - integer indx(NSAVE) - integer*8 count0,count1,clkfreq - real s1(720000) !To reserve space. Logically s1(nq,jz) - real s2(240,340) !Symbol spectra at quarter-symbol steps - real ss2(0:8,85) !Folded symbol spectra - real ss3(0:7,69) !Folded spectra without sync symbols - real s(1500) - real ccfsave(NSAVE) - real t0save(NSAVE) - real t1save(NSAVE) - real freqSave(NSAVE) - real t(6) - character*22 msg !Decoded message - character*80 line(100) - data nsubmode0/-1/,ntot/0/ - save s1,nsubmode0,ntot - -! Parameters from GUI are in narg(): - nutc=narg(0) !UTC - npts=min(narg(1),NMAX) !Number of samples in id2 (12000 Hz) - nsubmode=narg(2) !0=A 1=B 2=C 3=D 4=E 5=F 6=G 7=H - if(nsubmode.lt.4) go to 900 - newdat=narg(3) !1==> new data, compute symbol spectra - minsync=narg(4) !Lower sync limit - npick=narg(5) - t0=0.001*narg(6) - t1=0.001*narg(7) - maxlines=narg(8) !Max # of decodes to return to caller - nmode=narg(9) - nrxfreq=narg(10) !Targer Rx audio frequency (Hz) - ntol=narg(11) !Search range, +/- ntol (Hz) - - tmid=npts*0.5/12000.0 - line(1:100)(1:1)=char(0) - s=0 - s2=0 - nsps=60 * 2**(7-nsubmode) !Samples per sysbol - nfft=2*nsps !FFT size - nh=nfft/2 - nq=nfft/4 - istep=nsps/4 !Symbol spectra at quarter-symbol steps - jz=npts/istep - df=12000.0/nfft !FFT bin width - db1=db(2500.0/df) - nfa=max(200,nrxfreq-ntol) !Lower frequency limit - nfb=min(nrxfreq+ntol,2500) !Upper frequency limit - nline=0 - t=0. - - if(newdat.eq.1 .or. nsubmode.ne.nsubmode0) then - call system_clock(count0,clkfreq) - call spec9f(id2,npts,nsps,s1,jz,nq) !Compute symbol spectra, s1 - call system_clock(count1,clkfreq) - t(1)=t(1)+float(count1-count0)/float(clkfreq) - endif - - nsubmode0=nsubmode - tmsg=nsps*85.0/12000.0 - limit=2000 - nlen0=0 - i1=0 - i2=0 - ccfsave=0. - do ilength=1,14 - nlen=1.4142136**(ilength-1) - if(nlen.gt.jz/340) nlen=jz/340 - if(nlen.eq.nlen0) cycle - nlen0=nlen - - db0=db(float(nlen)) - jlen=nlen*340 - jstep=jlen/4 !### Is this about right? ### - if(nsubmode.ge.6) jstep=jlen/2 - - do ja=1,jz-jlen,jstep - jb=ja+jlen-1 - call system_clock(count0,clkfreq) - call foldspec9f(s1,nq,jz,ja,jb,s2) !Fold symbol spectra into s2 - call system_clock(count1,clkfreq) - t(2)=t(2)+float(count1-count0)/float(clkfreq) - -! Find sync; put sync'ed symbol spectra into ss2 and ss3 -! Might want to do a peakup in DT and DF, then re-compute symbol spectra. - - call system_clock(count0,clkfreq) - call sync9f(s2,nq,nfa,nfb,ss2,ss3,lagpk,ipk,ccfbest) - call system_clock(count1,clkfreq) - t(3)=t(3)+float(count1-count0)/float(clkfreq) - - i1=i1+1 - if(ccfbest.lt.30.0) cycle - call system_clock(count0,clkfreq) - call softsym9f(ss2,ss3,i1SoftSymbols) !Compute soft symbols - call system_clock(count1,clkfreq) - t(4)=t(4)+float(count1-count0)/float(clkfreq) - - i2=i2+1 - ccfsave(i2)=ccfbest - i1save(1:207,i2)=i1SoftSymbols - t0=(ja-1)*istep/12000.0 - t1=(jb-1)*istep/12000.0 - t0save(i2)=t0 - t1save(i2)=t1 - freq=ipk*df - freqSave(i2)=freq - enddo - enddo - nsaved=i2 - - ccfsave(1:nsaved)=-ccfsave(1:nsaved) - call system_clock(count0,clkfreq) - indx=0 - call indexx(ccfsave,nsaved,indx) - call system_clock(count1,clkfreq) - t(5)=t(5)+float(count1-count0)/float(clkfreq) - - ccfsave(1:nsaved)=-ccfsave(1:nsaved) - - do iter=1,2 -! do isave=1,nsaved - do isave=1,50 - i2=indx(isave) - if(i2.lt.1 .or. i2.gt.nsaved) cycle !### Why needed? ### - t0=t0save(i2) - t1=t1save(i2) - if(iter.eq.1 .and. t1.lt.tmid) cycle - if(iter.eq.2 .and. t1.ge.tmid) cycle - ccfbest=ccfsave(i2) - i1SoftSymbols=i1save(1:207,i2) - freq=freqSave(i2) - call system_clock(count0,clkfreq) - call jt9fano(i1SoftSymbols,limit,nlim,msg) !Invoke Fano decoder - call system_clock(count1,clkfreq) - t(6)=t(6)+float(count1-count0)/float(clkfreq) - - i=t0*12000.0 - kz=(t1-t0)/0.02 - smax=0. - do k=1,kz - sq=0. - do n=1,240 - i=i+1 - x=id2(i) - sq=sq+x*x - enddo - s(k)=sq/240. - smax=max(s(k),smax) - enddo - call pctile(s,kz,35,base) - snr=smax/(1.1*base) - 1.0 - nsnr=-20 - if(snr.gt.0.0) nsnr=nint(db(snr)) - -! write(72,3002) nutc,iter,isave,nlen,tmid,t0,t1,ccfbest, & -! nint(freq),nlim,msg -!3002 format(i6.6,i1,i4,i3,4f6.1,i5,i7,1x,a22) - - if(msg.ne.' ') then - -! Display multiple decodes only if they differ: - do n=1,nline - if(index(line(n),msg).gt.1) go to 100 - enddo -!### Might want to use decoded message to get a complete estimate of S/N. - nline=nline+1 - write(line(nline),1000) nutc,nsnr,t0,nint(freq),msg,char(0) -1000 format(i6.6,i4,f5.1,i5,1x,'@ ',1x,a22,a1) - ntot=ntot+1 -! write(70,5001) nsaved,isave,nline,maxlines,ntot,nutc,msg -!5001 format(5i5,i7.6,1x,a22) - if(nline.ge.maxlines) go to 900 - endif -100 continue - enddo - enddo - -900 continue -! write(*,6001) t,t(6)/sum(t) -!6001 format(7f10.3) - - return -end subroutine fast9 +subroutine fast9(id2,narg,line) + +! Decoder for "fast9" modes, JT9E to JT9H. + + parameter (NMAX=30*12000,NSAVE=500) + integer*2 id2(0:NMAX) + integer narg(0:14) + integer*1 i1SoftSymbols(207) + integer*1 i1save(207,NSAVE) + integer indx(NSAVE) + integer*8 count0,count1,clkfreq + real s1(720000) !To reserve space. Logically s1(nq,jz) + real s2(240,340) !Symbol spectra at quarter-symbol steps + real ss2(0:8,85) !Folded symbol spectra + real ss3(0:7,69) !Folded spectra without sync symbols + real s(1500) + real ccfsave(NSAVE) + real t0save(NSAVE) + real t1save(NSAVE) + real freqSave(NSAVE) + real t(6) + character*22 msg !Decoded message + character*80 line(100) + data nsubmode0/-1/,ntot/0/ + save s1,nsubmode0,ntot + +! Parameters from GUI are in narg(): + nutc=narg(0) !UTC + npts=min(narg(1),NMAX) !Number of samples in id2 (12000 Hz) + nsubmode=narg(2) !0=A 1=B 2=C 3=D 4=E 5=F 6=G 7=H + if(nsubmode.lt.4) go to 900 + newdat=narg(3) !1==> new data, compute symbol spectra + minsync=narg(4) !Lower sync limit + npick=narg(5) + t0=0.001*narg(6) + t1=0.001*narg(7) + maxlines=narg(8) !Max # of decodes to return to caller + nmode=narg(9) + nrxfreq=narg(10) !Targer Rx audio frequency (Hz) + ntol=narg(11) !Search range, +/- ntol (Hz) + + tmid=npts*0.5/12000.0 + line(1:100)(1:1)=char(0) + s=0 + s2=0 + nsps=60 * 2**(7-nsubmode) !Samples per sysbol + nfft=2*nsps !FFT size + nh=nfft/2 + nq=nfft/4 + istep=nsps/4 !Symbol spectra at quarter-symbol steps + jz=npts/istep + df=12000.0/nfft !FFT bin width + db1=db(2500.0/df) + nfa=max(200,nrxfreq-ntol) !Lower frequency limit + nfb=min(nrxfreq+ntol,2500) !Upper frequency limit + nline=0 + t=0. + + if(newdat.eq.1 .or. nsubmode.ne.nsubmode0) then + call system_clock(count0,clkfreq) + call spec9f(id2,npts,nsps,s1,jz,nq) !Compute symbol spectra, s1 + call system_clock(count1,clkfreq) + t(1)=t(1)+float(count1-count0)/float(clkfreq) + endif + + nsubmode0=nsubmode + tmsg=nsps*85.0/12000.0 + limit=2000 + nlen0=0 + i1=0 + i2=0 + ccfsave=0. + do ilength=1,14 + nlen=1.4142136**(ilength-1) + if(nlen.gt.jz/340) nlen=jz/340 + if(nlen.eq.nlen0) cycle + nlen0=nlen + + db0=db(float(nlen)) + jlen=nlen*340 + jstep=jlen/4 !### Is this about right? ### + if(nsubmode.ge.6) jstep=jlen/2 + + do ja=1,jz-jlen,jstep + jb=ja+jlen-1 + call system_clock(count0,clkfreq) + call foldspec9f(s1,nq,jz,ja,jb,s2) !Fold symbol spectra into s2 + call system_clock(count1,clkfreq) + t(2)=t(2)+float(count1-count0)/float(clkfreq) + +! Find sync; put sync'ed symbol spectra into ss2 and ss3 +! Might want to do a peakup in DT and DF, then re-compute symbol spectra. + + call system_clock(count0,clkfreq) + call sync9f(s2,nq,nfa,nfb,ss2,ss3,lagpk,ipk,ccfbest) + call system_clock(count1,clkfreq) + t(3)=t(3)+float(count1-count0)/float(clkfreq) + + i1=i1+1 + if(ccfbest.lt.30.0) cycle + call system_clock(count0,clkfreq) + call softsym9f(ss2,ss3,i1SoftSymbols) !Compute soft symbols + call system_clock(count1,clkfreq) + t(4)=t(4)+float(count1-count0)/float(clkfreq) + + i2=i2+1 + ccfsave(i2)=ccfbest + i1save(1:207,i2)=i1SoftSymbols + t0=(ja-1)*istep/12000.0 + t1=(jb-1)*istep/12000.0 + t0save(i2)=t0 + t1save(i2)=t1 + freq=ipk*df + freqSave(i2)=freq + enddo + enddo + nsaved=i2 + + ccfsave(1:nsaved)=-ccfsave(1:nsaved) + call system_clock(count0,clkfreq) + indx=0 + call indexx(ccfsave,nsaved,indx) + call system_clock(count1,clkfreq) + t(5)=t(5)+float(count1-count0)/float(clkfreq) + + ccfsave(1:nsaved)=-ccfsave(1:nsaved) + + do iter=1,2 +! do isave=1,nsaved + do isave=1,50 + i2=indx(isave) + if(i2.lt.1 .or. i2.gt.nsaved) cycle !### Why needed? ### + t0=t0save(i2) + t1=t1save(i2) + if(iter.eq.1 .and. t1.lt.tmid) cycle + if(iter.eq.2 .and. t1.ge.tmid) cycle + ccfbest=ccfsave(i2) + i1SoftSymbols=i1save(1:207,i2) + freq=freqSave(i2) + call system_clock(count0,clkfreq) + call jt9fano(i1SoftSymbols,limit,nlim,msg) !Invoke Fano decoder + call system_clock(count1,clkfreq) + t(6)=t(6)+float(count1-count0)/float(clkfreq) + + i=t0*12000.0 + kz=(t1-t0)/0.02 + smax=0. + do k=1,kz + sq=0. + do n=1,240 + i=i+1 + x=id2(i) + sq=sq+x*x + enddo + s(k)=sq/240. + smax=max(s(k),smax) + enddo + call pctile(s,kz,35,base) + snr=smax/(1.1*base) - 1.0 + nsnr=-20 + if(snr.gt.0.0) nsnr=nint(db(snr)) + +! write(72,3002) nutc,iter,isave,nlen,tmid,t0,t1,ccfbest, & +! nint(freq),nlim,msg +!3002 format(i6.6,i1,i4,i3,4f6.1,i5,i7,1x,a22) + + if(msg.ne.' ') then + +! Display multiple decodes only if they differ: + do n=1,nline + if(index(line(n),msg).gt.1) go to 100 + enddo +!### Might want to use decoded message to get a complete estimate of S/N. + nline=nline+1 + write(line(nline),1000) nutc,nsnr,t0,nint(freq),msg,char(0) +1000 format(i6.6,i4,f5.1,i5,1x,'@ ',1x,a22,a1) + ntot=ntot+1 +! write(70,5001) nsaved,isave,nline,maxlines,ntot,nutc,msg +!5001 format(5i5,i7.6,1x,a22) + if(nline.ge.maxlines) go to 900 + endif +100 continue + enddo + enddo + +900 continue +! write(*,6001) t,t(6)/sum(t) +!6001 format(7f10.3) + + return +end subroutine fast9 diff --git a/lib/fast_decode.f90 b/lib/fast_decode.f90 index 6a6a826f..c4326cba 100755 --- a/lib/fast_decode.f90 +++ b/lib/fast_decode.f90 @@ -1,90 +1,90 @@ -subroutine fast_decode(id2,narg,trperiod,line,mycall_12, & - hiscall_12) - - parameter (NMAX=30*12000) - integer*2 id2(NMAX) - integer*2 id2a(NMAX) - integer*2 id2b(NMAX) - integer narg(0:14) - double precision trperiod - real dat(30*12000) - complex cdat(262145),cdat2(262145) - logical pick,first - character*6 cfile6 - character*80 line(100) - character*12 mycall_12,hiscall_12 - character*6 mycall,hiscall - data first/.true./,nutca/0/,nutcb/0/ - save npts,cdat,cdat2,id2a,id2b,nutca,nutcb - - if(first) then - id2a=0 - id2b=0 - first=.false. - endif - - mycall=mycall_12(1:6) - hiscall=hiscall_12(1:6) - nutc=narg(0) - ndat0=narg(1) - nsubmode=narg(2) - newdat=narg(3) - minsync=narg(4) - npick=narg(5) - t0=0.001*narg(6) - t1=0.001*narg(7) - tmid=0.5*(t0+t1) - maxlines=narg(8) - nmode=narg(9) - nrxfreq=narg(10) - ntol=narg(11) - nhashcalls=narg(12) - - line(1:100)(1:1)=char(0) - if(t0.gt.trperiod) go to 900 - if(t0.gt.t1) go to 900 - - if(nmode.eq.102) then - call fast9(id2,narg,line) - go to 900 - endif - - if(newdat.eq.1) then - cdat2=cdat - ndat=ndat0 - call wav11(id2,ndat,dat) - nzz=11025*int(trperiod) !beware if fractional T/R period ever used here - if(ndat.lt.nzz) dat(ndat+1:nzz)=0.0 - ndat=min(ndat,30*11025) - call ana932(dat,ndat,cdat,npts) !Make downsampled analytic signal - endif - -! Now cdat() is the downsampled analytic signal. -! New sample rate = fsample = BW = 11025 * (9/32) = 3100.78125 Hz -! NB: npts, nsps, etc., are all reduced by 9/32 - - write(cfile6,'(i6.6)') nutc - nfreeze=1 - mousedf=0 - mousebutton=0 - mode4=1 - if(nsubmode.eq.1) mode4=2 - nafc=0 - ndebug=0 - t2=0. - ia=1 - ib=npts - pick=.false. - - if(npick.gt.0) then - pick=.true. - dt=1.0/11025.0 * (32.0/9.0) - ia=t0/dt + 1. - ib=t1/dt + 1. - t2=t0 - endif - jz=ib-ia+1 - line(1:100)(1:1)=char(0) - -900 return -end subroutine fast_decode +subroutine fast_decode(id2,narg,trperiod,line,mycall_12, & + hiscall_12) + + parameter (NMAX=30*12000) + integer*2 id2(NMAX) + integer*2 id2a(NMAX) + integer*2 id2b(NMAX) + integer narg(0:14) + double precision trperiod + real dat(30*12000) + complex cdat(262145),cdat2(262145) + logical pick,first + character*6 cfile6 + character*80 line(100) + character*12 mycall_12,hiscall_12 + character*6 mycall,hiscall + data first/.true./,nutca/0/,nutcb/0/ + save npts,cdat,cdat2,id2a,id2b,nutca,nutcb + + if(first) then + id2a=0 + id2b=0 + first=.false. + endif + + mycall=mycall_12(1:6) + hiscall=hiscall_12(1:6) + nutc=narg(0) + ndat0=narg(1) + nsubmode=narg(2) + newdat=narg(3) + minsync=narg(4) + npick=narg(5) + t0=0.001*narg(6) + t1=0.001*narg(7) + tmid=0.5*(t0+t1) + maxlines=narg(8) + nmode=narg(9) + nrxfreq=narg(10) + ntol=narg(11) + nhashcalls=narg(12) + + line(1:100)(1:1)=char(0) + if(t0.gt.trperiod) go to 900 + if(t0.gt.t1) go to 900 + + if(nmode.eq.102) then + call fast9(id2,narg,line) + go to 900 + endif + + if(newdat.eq.1) then + cdat2=cdat + ndat=ndat0 + call wav11(id2,ndat,dat) + nzz=11025*int(trperiod) !beware if fractional T/R period ever used here + if(ndat.lt.nzz) dat(ndat+1:nzz)=0.0 + ndat=min(ndat,30*11025) + call ana932(dat,ndat,cdat,npts) !Make downsampled analytic signal + endif + +! Now cdat() is the downsampled analytic signal. +! New sample rate = fsample = BW = 11025 * (9/32) = 3100.78125 Hz +! NB: npts, nsps, etc., are all reduced by 9/32 + + write(cfile6,'(i6.6)') nutc + nfreeze=1 + mousedf=0 + mousebutton=0 + mode4=1 + if(nsubmode.eq.1) mode4=2 + nafc=0 + ndebug=0 + t2=0. + ia=1 + ib=npts + pick=.false. + + if(npick.gt.0) then + pick=.true. + dt=1.0/11025.0 * (32.0/9.0) + ia=t0/dt + 1. + ib=t1/dt + 1. + t2=t0 + endif + jz=ib-ia+1 + line(1:100)(1:1)=char(0) + +900 return +end subroutine fast_decode diff --git a/lib/fchisq0.f90 b/lib/fchisq0.f90 index 742df078..2c62f275 100755 --- a/lib/fchisq0.f90 +++ b/lib/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/lib/fer b/lib/fer index 9cf68fc0..7a74bf2a 100755 --- a/lib/fer +++ b/lib/fer @@ -1,41 +1,41 @@ -#!/bin/bash - -# jt65 end-to-end simulator. Run enough cases to get a given -# number of successful decodes or a given number of errors -# For better performance, copy this script and jt65, jt65sim -# executables to a ramdisk and run from there. - -mode=C -spread=4.0 - -for i in `seq 0 21`; -do -nruns=0 -ndecodes=0 -ngood=0 -nbad=0 -snr=$((-25+$i)) -#while [ $[ $nruns - $ngood ] -lt 200 ] -#while [ $ngood -lt 200 ] -while [ $nruns -lt 1000 ] -do - rm 000000_0001.wav - ./jt65sim -m $mode -n 1 -d $spread -s \\$snr > /dev/null - rm decoded.txt - ./jt65 -m $mode -a 10 -f 1500 -n 1000 -s 000000_0001.wav > decoded.txt - if [ -e decoded.txt ]; then - nd=$( wc -l < decoded.txt ) - ng=$( grep "K1ABC" decoded.txt | wc -l ) - nb=$[$nd-$ng] - ndecodes=$[$ndecodes + $nd] - ngood=$[$ngood + $ng] - nbad=$[$nbad + $nb] - fi - nruns=$[$nruns + 1] - nmissed=$[$nruns-$ngood] - pe=$( echo "scale=5; $nmissed/$nruns" | bc -l ) - ps=$( echo "scale=5; $ngood/$nruns" | bc -l ) - echo -en snr: $snr nruns: $nruns ndecodes: $ndecodes ngood: $ngood nbad: $nbad nmissed: $nmissed wer: $pe success: $ps"\r" -done -echo snr: $snr nruns: $nruns ndecodes: $ndecodes ngood: $ngood nbad: $nbad nmissed: $nmissed wer: $pe success: $ps -done +#!/bin/bash + +# jt65 end-to-end simulator. Run enough cases to get a given +# number of successful decodes or a given number of errors +# For better performance, copy this script and jt65, jt65sim +# executables to a ramdisk and run from there. + +mode=C +spread=4.0 + +for i in `seq 0 21`; +do +nruns=0 +ndecodes=0 +ngood=0 +nbad=0 +snr=$((-25+$i)) +#while [ $[ $nruns - $ngood ] -lt 200 ] +#while [ $ngood -lt 200 ] +while [ $nruns -lt 1000 ] +do + rm 000000_0001.wav + ./jt65sim -m $mode -n 1 -d $spread -s \\$snr > /dev/null + rm decoded.txt + ./jt65 -m $mode -a 10 -f 1500 -n 1000 -s 000000_0001.wav > decoded.txt + if [ -e decoded.txt ]; then + nd=$( wc -l < decoded.txt ) + ng=$( grep "K1ABC" decoded.txt | wc -l ) + nb=$[$nd-$ng] + ndecodes=$[$ndecodes + $nd] + ngood=$[$ngood + $ng] + nbad=$[$nbad + $nb] + fi + nruns=$[$nruns + 1] + nmissed=$[$nruns-$ngood] + pe=$( echo "scale=5; $nmissed/$nruns" | bc -l ) + ps=$( echo "scale=5; $ngood/$nruns" | bc -l ) + echo -en snr: $snr nruns: $nruns ndecodes: $ndecodes ngood: $ngood nbad: $nbad nmissed: $nmissed wer: $pe success: $ps"\r" +done +echo snr: $snr nruns: $nruns ndecodes: $ndecodes ngood: $ngood nbad: $nbad nmissed: $nmissed wer: $pe success: $ps +done diff --git a/lib/fer65.f90 b/lib/fer65.f90 index 10759dd6..1284fb54 100755 --- a/lib/fer65.f90 +++ b/lib/fer65.f90 @@ -1,195 +1,195 @@ -program fer65 - -! End-to-end simulator for testing JT65. - -! Options -! jt65sim jt65 -!---------------------------------------------------------------- -! -a aggressive -! -d Doppler spread -d depth -! -f Number of files -f freq -! -m (sub)mode -m (sub)mode -! -n number of generated sigs -n ntrials -! -t Time offset (s) -r robust sync -! -p Do not seed random #s -c mycall -! -x hiscall -! -g hisgrid -! -X hinted-decode flags -! -s S/N in 2500 Hz -s single-decode mode - - implicit real*8 (a-h,o-z) - real*8 s(7),sq(7) - character arg*12,cmnd*100,decoded*22,submode*1,csync*1,f1*15,f2*15 - character*12 outfile - logical syncok - - nargs=iargc() - if(nargs.ne.7) then - print*,'Usage: fer65 submode fspread snr1 snr2 Navg DS iters' - print*,'Example: fer65 C 3.0 -28 -12 8 1 1000' - go to 999 - endif - - call getarg(1,submode) - call getarg(2,arg) - read(arg,*) d - call getarg(3,arg) - read(arg,*) snr1 - call getarg(4,arg) - read(arg,*) snr2 - call getarg(5,arg) - read(arg,*) navg - call getarg(6,arg) - read(arg,*) nds - call getarg(7,arg) - read(arg,*) iters - - write(outfile,1001) submode,d,navg,nds -1001 format(a1,f6.2,'_',i2.2,'_',i1) - if(outfile(2:2).eq.' ') outfile(2:2)='0' - if(outfile(3:3).eq.' ') outfile(3:3)='0' - - ndepth=3 - if(navg.gt.1) ndepth=ndepth+16 - if(nds.ne.0) ndepth=ndepth+32 - - dfmax=3 - if(submode.eq.'b' .or. submode.eq.'B') dfmax=6 - if(submode.eq.'c' .or. submode.eq.'C') dfmax=11 - - ntrials=1000 - naggressive=10 - - open(20,file=outfile,status='unknown') - open(21,file='fer65.21',status='unknown') - - write(20,1000) submode,iters,ntrials,naggressive,d,ndepth,navg,nds -1000 format(/'JT65',a1,' Iters:',i5,' T:',i6,' Aggr:',i3, & - ' Dop:',f6.2,' Depth:',i2,' Navg:',i3,' DS:',i2) - write(20,1002) -1002 format(/' dB nsync ngood nbad sync dsnr ', & - 'DT Freq Nsum Width'/85('-')) - flush(20) - - do isnr=0,20 - snr=snr1+isnr - if(snr.gt.snr2) exit - nsync=0 - ngood=0 - nbad=0 - s=0. - sq=0. - do iter=1,iters - write(cmnd,1010) submode,d,snr,navg -1010 format('./jt65sim -n 1 -m ',a1,' -d',f7.2,' -s \\',f5.1,' -f',i3,' >devnull') - call unlink('000000_????.wav') - call system(cmnd) - if(navg.gt.1) then - do i=navg,2,-1 - j=2*i-1 - write(f1,1011) i - write(f2,1011) j -1011 format('000000_',i4.4,'.wav') - call rename(f1,f2) - enddo - endif - call unlink('decoded.txt') - call unlink('fort.13') - isync=0 - nsnr=0 - dt=0. - nfreq=0 - ndrift=0 - nwidth=0 - cmnd='./jt65 -m A -a 10 -c K1ABC -f 1500 -n 1000 -d 5 -s 000000_????.wav > decoded.txt' - cmnd(11:11)=submode - write(cmnd(47:48),'(i2)') ndepth - call system(cmnd) - open(13,file='fort.13',status='old',err=20) - do i=1,navg - read(13,1012) nutc,isync,nsnr,dt,nfreq,ndrift,nwidth,decoded, & - nft,nsum,nsmo -1012 format(i4,i4,i5,f6.2,i5,i4,i3,1x,a22,5x,3i3) - if(nft.gt.0) exit - enddo - close(13) - syncok=abs(dt).lt.0.2 .and. float(abs(nfreq-1500)).lt.dfmax - csync=' ' - if(syncok) csync='*' - write(21,1014) nutc,isync,nsnr,dt,nfreq,ndrift,nwidth, & - nft,nsum,nsmo,csync,decoded(1:16),nft,nsum,nsmo -1014 format(i4,i4,i5,f6.2,i5,i4,3x,4i3,1x,a1,1x,a16,i2,2i3) - flush(21) - - if(syncok) then - nsync=nsync+1 - s(1)=s(1) + isync - sq(1)=sq(1) + isync*isync - s(6)=s(6) + nwidth - sq(6)=sq(6) + nwidth*nwidth - if(decoded.eq.'K1ABC W9XYZ EN37 ') then - ngood=ngood+1 - s(2)=s(2) + nsnr - s(3)=s(3) + dt - s(4)=s(4) + nfreq - s(5)=s(5) + ndrift - s(7)=s(7) + nsum - - sq(2)=sq(2) + nsnr*nsnr - sq(3)=sq(3) + dt*dt - sq(4)=sq(4) + nfreq*nfreq - sq(5)=sq(5) + ndrift*ndrift - sq(7)=sq(7) + nsum*nsum - else if(decoded.ne.' ') then - nbad=nbad+1 - print*,'Nbad:',nbad,decoded - endif - endif -20 continue - fsync=float(nsync)/iter - fgood=float(ngood)/iter - fbad=float(nbad)/iter - write(*,1020) nint(snr),iter,isync,nsnr,dt,nfreq,ndrift,nwidth,fsync, & - fgood,fbad,decoded(1:16),nft,nsum,nsmo -1020 format(i3,i5,i3,i4,f6.2,i5,i3,i3,2f6.3,f7.4,1x,a16,i2,2i3) - enddo - - if(nsync.ge.1) then - xsync=s(1)/nsync - xwidth=s(6)/nsync - endif - esync=0. - if(nsync.ge.2) then - esync=sqrt(sq(1)/nsync - xsync**2) - ewidth=sqrt(sq(6)/nsync - xwidth**2) - endif - - if(ngood.ge.1) then - xsnr=s(2)/ngood - xdt=s(3)/ngood - xfreq=s(4)/ngood - xdrift=s(5)/ngood - xsum=s(7)/ngood - endif - if(ngood.ge.2) then - esnr=sqrt(sq(2)/ngood - xsnr**2) - edt=sqrt(sq(3)/ngood - xdt**2) - efreq=sqrt(sq(4)/ngood - xfreq**2) - edrift=sqrt(sq(5)/ngood - xdrift**2) - esum=sqrt(sq(7)/ngood - xsum**2) - endif - - dsnr=xsnr-snr - dfreq=xfreq-1500.0 - if(ngood.eq.0) then - dsnr=0. - dfreq=0. - endif - write(20,1100) snr,nsync,ngood,nbad,xsync,esync,dsnr,esnr, & - xdt,edt,dfreq,efreq,xsum,esum,xwidth,ewidth -1100 format(f5.1,2i6,i4,2f6.1,f6.1,f5.1,f6.2,f5.2,6f5.1) - flush(20) - if(ngood.ge.int(0.99*iters)) exit - enddo - -999 end program fer65 +program fer65 + +! End-to-end simulator for testing JT65. + +! Options +! jt65sim jt65 +!---------------------------------------------------------------- +! -a aggressive +! -d Doppler spread -d depth +! -f Number of files -f freq +! -m (sub)mode -m (sub)mode +! -n number of generated sigs -n ntrials +! -t Time offset (s) -r robust sync +! -p Do not seed random #s -c mycall +! -x hiscall +! -g hisgrid +! -X hinted-decode flags +! -s S/N in 2500 Hz -s single-decode mode + + implicit real*8 (a-h,o-z) + real*8 s(7),sq(7) + character arg*12,cmnd*100,decoded*22,submode*1,csync*1,f1*15,f2*15 + character*12 outfile + logical syncok + + nargs=iargc() + if(nargs.ne.7) then + print*,'Usage: fer65 submode fspread snr1 snr2 Navg DS iters' + print*,'Example: fer65 C 3.0 -28 -12 8 1 1000' + go to 999 + endif + + call getarg(1,submode) + call getarg(2,arg) + read(arg,*) d + call getarg(3,arg) + read(arg,*) snr1 + call getarg(4,arg) + read(arg,*) snr2 + call getarg(5,arg) + read(arg,*) navg + call getarg(6,arg) + read(arg,*) nds + call getarg(7,arg) + read(arg,*) iters + + write(outfile,1001) submode,d,navg,nds +1001 format(a1,f6.2,'_',i2.2,'_',i1) + if(outfile(2:2).eq.' ') outfile(2:2)='0' + if(outfile(3:3).eq.' ') outfile(3:3)='0' + + ndepth=3 + if(navg.gt.1) ndepth=ndepth+16 + if(nds.ne.0) ndepth=ndepth+32 + + dfmax=3 + if(submode.eq.'b' .or. submode.eq.'B') dfmax=6 + if(submode.eq.'c' .or. submode.eq.'C') dfmax=11 + + ntrials=1000 + naggressive=10 + + open(20,file=outfile,status='unknown') + open(21,file='fer65.21',status='unknown') + + write(20,1000) submode,iters,ntrials,naggressive,d,ndepth,navg,nds +1000 format(/'JT65',a1,' Iters:',i5,' T:',i6,' Aggr:',i3, & + ' Dop:',f6.2,' Depth:',i2,' Navg:',i3,' DS:',i2) + write(20,1002) +1002 format(/' dB nsync ngood nbad sync dsnr ', & + 'DT Freq Nsum Width'/85('-')) + flush(20) + + do isnr=0,20 + snr=snr1+isnr + if(snr.gt.snr2) exit + nsync=0 + ngood=0 + nbad=0 + s=0. + sq=0. + do iter=1,iters + write(cmnd,1010) submode,d,snr,navg +1010 format('./jt65sim -n 1 -m ',a1,' -d',f7.2,' -s \\',f5.1,' -f',i3,' >devnull') + call unlink('000000_????.wav') + call system(cmnd) + if(navg.gt.1) then + do i=navg,2,-1 + j=2*i-1 + write(f1,1011) i + write(f2,1011) j +1011 format('000000_',i4.4,'.wav') + call rename(f1,f2) + enddo + endif + call unlink('decoded.txt') + call unlink('fort.13') + isync=0 + nsnr=0 + dt=0. + nfreq=0 + ndrift=0 + nwidth=0 + cmnd='./jt65 -m A -a 10 -c K1ABC -f 1500 -n 1000 -d 5 -s 000000_????.wav > decoded.txt' + cmnd(11:11)=submode + write(cmnd(47:48),'(i2)') ndepth + call system(cmnd) + open(13,file='fort.13',status='old',err=20) + do i=1,navg + read(13,1012) nutc,isync,nsnr,dt,nfreq,ndrift,nwidth,decoded, & + nft,nsum,nsmo +1012 format(i4,i4,i5,f6.2,i5,i4,i3,1x,a22,5x,3i3) + if(nft.gt.0) exit + enddo + close(13) + syncok=abs(dt).lt.0.2 .and. float(abs(nfreq-1500)).lt.dfmax + csync=' ' + if(syncok) csync='*' + write(21,1014) nutc,isync,nsnr,dt,nfreq,ndrift,nwidth, & + nft,nsum,nsmo,csync,decoded(1:16),nft,nsum,nsmo +1014 format(i4,i4,i5,f6.2,i5,i4,3x,4i3,1x,a1,1x,a16,i2,2i3) + flush(21) + + if(syncok) then + nsync=nsync+1 + s(1)=s(1) + isync + sq(1)=sq(1) + isync*isync + s(6)=s(6) + nwidth + sq(6)=sq(6) + nwidth*nwidth + if(decoded.eq.'K1ABC W9XYZ EN37 ') then + ngood=ngood+1 + s(2)=s(2) + nsnr + s(3)=s(3) + dt + s(4)=s(4) + nfreq + s(5)=s(5) + ndrift + s(7)=s(7) + nsum + + sq(2)=sq(2) + nsnr*nsnr + sq(3)=sq(3) + dt*dt + sq(4)=sq(4) + nfreq*nfreq + sq(5)=sq(5) + ndrift*ndrift + sq(7)=sq(7) + nsum*nsum + else if(decoded.ne.' ') then + nbad=nbad+1 + print*,'Nbad:',nbad,decoded + endif + endif +20 continue + fsync=float(nsync)/iter + fgood=float(ngood)/iter + fbad=float(nbad)/iter + write(*,1020) nint(snr),iter,isync,nsnr,dt,nfreq,ndrift,nwidth,fsync, & + fgood,fbad,decoded(1:16),nft,nsum,nsmo +1020 format(i3,i5,i3,i4,f6.2,i5,i3,i3,2f6.3,f7.4,1x,a16,i2,2i3) + enddo + + if(nsync.ge.1) then + xsync=s(1)/nsync + xwidth=s(6)/nsync + endif + esync=0. + if(nsync.ge.2) then + esync=sqrt(sq(1)/nsync - xsync**2) + ewidth=sqrt(sq(6)/nsync - xwidth**2) + endif + + if(ngood.ge.1) then + xsnr=s(2)/ngood + xdt=s(3)/ngood + xfreq=s(4)/ngood + xdrift=s(5)/ngood + xsum=s(7)/ngood + endif + if(ngood.ge.2) then + esnr=sqrt(sq(2)/ngood - xsnr**2) + edt=sqrt(sq(3)/ngood - xdt**2) + efreq=sqrt(sq(4)/ngood - xfreq**2) + edrift=sqrt(sq(5)/ngood - xdrift**2) + esum=sqrt(sq(7)/ngood - xsum**2) + endif + + dsnr=xsnr-snr + dfreq=xfreq-1500.0 + if(ngood.eq.0) then + dsnr=0. + dfreq=0. + endif + write(20,1100) snr,nsync,ngood,nbad,xsync,esync,dsnr,esnr, & + xdt,edt,dfreq,efreq,xsum,esum,xwidth,ewidth +1100 format(f5.1,2i6,i4,2f6.1,f6.1,f5.1,f6.2,f5.2,6f5.1) + flush(20) + if(ngood.ge.int(0.99*iters)) exit + enddo + +999 end program fer65 diff --git a/lib/fersum.f90 b/lib/fersum.f90 index 479149f3..4a99561e 100755 --- a/lib/fersum.f90 +++ b/lib/fersum.f90 @@ -1,72 +1,72 @@ -program fersum - - character mode*5 - character infile*40 - real dop(0:9) - real thresh(0:9,12),threshsync(0:9,12) - data dop/0.25,0.5,1.0,2.0,4.0,8.0,16.0,32.0,64.0,128.0/ - - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: fersum ' - go to 999 - endif - call getarg(1,infile) - open(10,file=infile,status='old') - thresh=0. - threshsync=0. - - do iblk=1,999 -1 read(10,1002,end=100) mode,iters,ntot,naggr,d,navg,nds -1002 format(a5,8x,i5,4x,i6,7x,i3,6x,f6.2,17x,i3,5x,i2) - write(33,*) iblk,mode - if(mode.eq.' ') go to 1 - read(10,1002) - read(10,1002) - read(10,1002) - - nsync0=0 - ngood0=0 - xsum0=0. - do n=1,99 - read(10,1010,end=100) snr,nsync,ngood,nbad,xsync,esync,dsnr,esnr, & - xdt,edt,dfreq,efreq,xsum,esum,xwidth,ewidth -1010 format(f5.1,2i6i4,2f6.1,f6.1,f5.1,f6.2,f5.2,6f5.1) - if(snr.eq.0.0) exit - if(mode(5:5).eq.'A') nmode=1 - if(mode(5:5).eq.'B') nmode=2 - if(mode(5:5).eq.'C') nmode=3 - j=nint(log(d)/log(2.0) + 2.0) - if(navg.eq.1 .and. nds.eq.0) k=nmode - if(navg.eq.1 .and. nds.eq.1) k=nmode+3 - if(navg.gt.1 .and. nds.eq.0) k=nmode+6 - if(navg.gt.1 .and. nds.eq.1) k=nmode+9 - if(nsync0.le.iters/2 .and. nsync.ge.iters/2) then - threshsync(j,k)=snr-float(nsync-iters/2)/(nsync-nsync0) - endif - if(ngood0.le.iters/2 .and. ngood.ge.iters/2) then - threshold=snr-float(ngood-iters/2)/(ngood-ngood0) - xsumavg=max(1.0,0.5*(xsum0+xsum)) -! write(*,1020) mode,iters,ntot,naggr,d,navg,nds,threshold,xsumavg -!1020 format(a5,i7,i7,i3,f7.2,i3,i3,f7.1,f6.1) - thresh(j,k)=threshold - endif - nsync0=nsync - ngood0=ngood - xsum0=xsum - enddo - enddo - -100 write(12,1100) -1100 format(' ') - do i=0,9 - write(12,1110) dop(i),thresh(i,1:12) -1110 format(f6.2,13f6.1) - enddo - - write(12,1110) - do i=0,9 - write(12,1110) dop(i),threshsync(i,1:12) - enddo - -999 end program fersum +program fersum + + character mode*5 + character infile*40 + real dop(0:9) + real thresh(0:9,12),threshsync(0:9,12) + data dop/0.25,0.5,1.0,2.0,4.0,8.0,16.0,32.0,64.0,128.0/ + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: fersum ' + go to 999 + endif + call getarg(1,infile) + open(10,file=infile,status='old') + thresh=0. + threshsync=0. + + do iblk=1,999 +1 read(10,1002,end=100) mode,iters,ntot,naggr,d,navg,nds +1002 format(a5,8x,i5,4x,i6,7x,i3,6x,f6.2,17x,i3,5x,i2) + write(33,*) iblk,mode + if(mode.eq.' ') go to 1 + read(10,1002) + read(10,1002) + read(10,1002) + + nsync0=0 + ngood0=0 + xsum0=0. + do n=1,99 + read(10,1010,end=100) snr,nsync,ngood,nbad,xsync,esync,dsnr,esnr, & + xdt,edt,dfreq,efreq,xsum,esum,xwidth,ewidth +1010 format(f5.1,2i6i4,2f6.1,f6.1,f5.1,f6.2,f5.2,6f5.1) + if(snr.eq.0.0) exit + if(mode(5:5).eq.'A') nmode=1 + if(mode(5:5).eq.'B') nmode=2 + if(mode(5:5).eq.'C') nmode=3 + j=nint(log(d)/log(2.0) + 2.0) + if(navg.eq.1 .and. nds.eq.0) k=nmode + if(navg.eq.1 .and. nds.eq.1) k=nmode+3 + if(navg.gt.1 .and. nds.eq.0) k=nmode+6 + if(navg.gt.1 .and. nds.eq.1) k=nmode+9 + if(nsync0.le.iters/2 .and. nsync.ge.iters/2) then + threshsync(j,k)=snr-float(nsync-iters/2)/(nsync-nsync0) + endif + if(ngood0.le.iters/2 .and. ngood.ge.iters/2) then + threshold=snr-float(ngood-iters/2)/(ngood-ngood0) + xsumavg=max(1.0,0.5*(xsum0+xsum)) +! write(*,1020) mode,iters,ntot,naggr,d,navg,nds,threshold,xsumavg +!1020 format(a5,i7,i7,i3,f7.2,i3,i3,f7.1,f6.1) + thresh(j,k)=threshold + endif + nsync0=nsync + ngood0=ngood + xsum0=xsum + enddo + enddo + +100 write(12,1100) +1100 format(' ') + do i=0,9 + write(12,1110) dop(i),thresh(i,1:12) +1110 format(f6.2,13f6.1) + enddo + + write(12,1110) + do i=0,9 + write(12,1110) dop(i),threshsync(i,1:12) + enddo + +999 end program fersum diff --git a/lib/fftw3.f90 b/lib/fftw3.f90 index f1c8775b..440ccc28 100755 --- a/lib/fftw3.f90 +++ b/lib/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/lib/fftw3mod.f90 b/lib/fftw3mod.f90 index 886b6ae1..f9e5f78b 100755 --- a/lib/fftw3mod.f90 +++ b/lib/fftw3mod.f90 @@ -1,4 +1,4 @@ -module FFTW3 - use, intrinsic :: iso_c_binding - include 'fftw3.f03' -end module FFTW3 +module FFTW3 + use, intrinsic :: iso_c_binding + include 'fftw3.f03' +end module FFTW3 diff --git a/lib/fil3c.f90 b/lib/fil3c.f90 index 67eea4b8..0b4a85f1 100755 --- a/lib/fil3c.f90 +++ b/lib/fil3c.f90 @@ -1,72 +1,72 @@ -subroutine fil3c(c1,n1,c2,n2) - -! FIR complex-to-complex low-pass filter designed with ScopeFIR -! -!----------------------------------------------- -! fsample (Hz) 12000 Input sample rate -! Ntaps 113 Number of filter taps -! fc (Hz) 500 Cutoff frequency -! fstop (Hz) 750 Lower limit of stopband -! Ripple (dB) 0.2 Ripple in passband -! Stop Atten (dB) 50 Stopband attenuation -! fout (Hz) 1500 Output sample rate - -! Suggest calling with n1 = 8*n2 + 105, where n2 is the desired number -! of 1500 Hz output samples. - - parameter (NTAPS=113) - parameter (NH=56) !NTAPS/2 - parameter (NDOWN=8) !Downsample ratio = 1/8 - complex c1(n1) - complex c2(n1/NDOWN) - complex z - -! Filter coefficients: - real a(-NH:NH) - data a/ & - -0.001818142144,-0.000939132050,-0.001044063556,-0.001042685542, & - -0.000908957610,-0.000628132309,-0.000202701465, 0.000346307629, & - 0.000978154552, 0.001634336295, 0.002243121592, 0.002726064379, & - 0.003006201675, 0.003018055983, 0.002717699575, 0.002091546534, & - 0.001162489032,-0.000007904811,-0.001321554806,-0.002649908053, & - -0.003843608784,-0.004747338068,-0.005218967042,-0.005148229529, & - -0.004470167307,-0.003177923811,-0.001335998901, 0.000915924193, & - 0.003386100636, 0.005818719744, 0.007939147967, 0.009465071347, & - 0.010145641899, 0.009787447819, 0.008285915754, 0.005645995244, & - 0.001995842303,-0.002410369720,-0.007202515555,-0.011916811719, & - -0.016028350845,-0.018993391440,-0.020297455955,-0.019503792208, & - -0.016298136197,-0.010526834635,-0.002223837363, 0.008378305829, & - 0.020854478160, 0.034608532659, 0.048909701463, 0.062944127288, & - 0.075874892030, 0.086903764340, 0.095332017649, 0.100619428175, & - 0.102420526192, 0.100619428175, 0.095332017649, 0.086903764340, & - 0.075874892030, 0.062944127288, 0.048909701463, 0.034608532659, & - 0.020854478160, 0.008378305829,-0.002223837363,-0.010526834635, & - -0.016298136197,-0.019503792208,-0.020297455955,-0.018993391440, & - -0.016028350845,-0.011916811719,-0.007202515555,-0.002410369720, & - 0.001995842303, 0.005645995244, 0.008285915754, 0.009787447819, & - 0.010145641899, 0.009465071347, 0.007939147967, 0.005818719744, & - 0.003386100636, 0.000915924193,-0.001335998901,-0.003177923811, & - -0.004470167307,-0.005148229529,-0.005218967042,-0.004747338068, & - -0.003843608784,-0.002649908053,-0.001321554806,-0.000007904811, & - 0.001162489032, 0.002091546534, 0.002717699575, 0.003018055983, & - 0.003006201675, 0.002726064379, 0.002243121592, 0.001634336295, & - 0.000978154552, 0.000346307629,-0.000202701465,-0.000628132309, & - -0.000908957610,-0.001042685542,-0.001044063556,-0.000939132050, & - -0.001818142144/ - save a - - n2=(n1-NTAPS+NDOWN)/NDOWN - k0=NH-NDOWN+1 - -! Loop over all output samples - do i=1,n2 - z=0. - k=k0 + NDOWN*i - do j=-NH,NH - z=z + c1(j+k)*a(j) - enddo - c2(i)=z - enddo - - return -end subroutine fil3c +subroutine fil3c(c1,n1,c2,n2) + +! FIR complex-to-complex low-pass filter designed with ScopeFIR +! +!----------------------------------------------- +! fsample (Hz) 12000 Input sample rate +! Ntaps 113 Number of filter taps +! fc (Hz) 500 Cutoff frequency +! fstop (Hz) 750 Lower limit of stopband +! Ripple (dB) 0.2 Ripple in passband +! Stop Atten (dB) 50 Stopband attenuation +! fout (Hz) 1500 Output sample rate + +! Suggest calling with n1 = 8*n2 + 105, where n2 is the desired number +! of 1500 Hz output samples. + + parameter (NTAPS=113) + parameter (NH=56) !NTAPS/2 + parameter (NDOWN=8) !Downsample ratio = 1/8 + complex c1(n1) + complex c2(n1/NDOWN) + complex z + +! Filter coefficients: + real a(-NH:NH) + data a/ & + -0.001818142144,-0.000939132050,-0.001044063556,-0.001042685542, & + -0.000908957610,-0.000628132309,-0.000202701465, 0.000346307629, & + 0.000978154552, 0.001634336295, 0.002243121592, 0.002726064379, & + 0.003006201675, 0.003018055983, 0.002717699575, 0.002091546534, & + 0.001162489032,-0.000007904811,-0.001321554806,-0.002649908053, & + -0.003843608784,-0.004747338068,-0.005218967042,-0.005148229529, & + -0.004470167307,-0.003177923811,-0.001335998901, 0.000915924193, & + 0.003386100636, 0.005818719744, 0.007939147967, 0.009465071347, & + 0.010145641899, 0.009787447819, 0.008285915754, 0.005645995244, & + 0.001995842303,-0.002410369720,-0.007202515555,-0.011916811719, & + -0.016028350845,-0.018993391440,-0.020297455955,-0.019503792208, & + -0.016298136197,-0.010526834635,-0.002223837363, 0.008378305829, & + 0.020854478160, 0.034608532659, 0.048909701463, 0.062944127288, & + 0.075874892030, 0.086903764340, 0.095332017649, 0.100619428175, & + 0.102420526192, 0.100619428175, 0.095332017649, 0.086903764340, & + 0.075874892030, 0.062944127288, 0.048909701463, 0.034608532659, & + 0.020854478160, 0.008378305829,-0.002223837363,-0.010526834635, & + -0.016298136197,-0.019503792208,-0.020297455955,-0.018993391440, & + -0.016028350845,-0.011916811719,-0.007202515555,-0.002410369720, & + 0.001995842303, 0.005645995244, 0.008285915754, 0.009787447819, & + 0.010145641899, 0.009465071347, 0.007939147967, 0.005818719744, & + 0.003386100636, 0.000915924193,-0.001335998901,-0.003177923811, & + -0.004470167307,-0.005148229529,-0.005218967042,-0.004747338068, & + -0.003843608784,-0.002649908053,-0.001321554806,-0.000007904811, & + 0.001162489032, 0.002091546534, 0.002717699575, 0.003018055983, & + 0.003006201675, 0.002726064379, 0.002243121592, 0.001634336295, & + 0.000978154552, 0.000346307629,-0.000202701465,-0.000628132309, & + -0.000908957610,-0.001042685542,-0.001044063556,-0.000939132050, & + -0.001818142144/ + save a + + n2=(n1-NTAPS+NDOWN)/NDOWN + k0=NH-NDOWN+1 + +! Loop over all output samples + do i=1,n2 + z=0. + k=k0 + NDOWN*i + do j=-NH,NH + z=z + c1(j+k)*a(j) + enddo + c2(i)=z + enddo + + return +end subroutine fil3c diff --git a/lib/fil4.f90 b/lib/fil4.f90 index 3649bf40..4946da2f 100755 --- a/lib/fil4.f90 +++ b/lib/fil4.f90 @@ -1,49 +1,49 @@ -subroutine fil4(id1,n1,id2,n2) - -! FIR lowpass filter designed using ScopeFIR - -! fsample = 48000 Hz -! Ntaps = 49 -! fc = 4500 Hz -! fstop = 6000 Hz -! Ripple = 1 dB -! Stop Atten = 40 dB -! fout = 12000 Hz - - parameter (NTAPS=49) - parameter (NDOWN=4) !Downsample ratio - integer*2 id1(n1) - integer*2 id2(*) - real t(NTAPS) - data t/NTAPS*0.0/ - -! Filter coefficients: - real w(NTAPS) - data w/ & - 0.000861074040, 0.010051920210, 0.010161983649, 0.011363155076, & - 0.008706594219, 0.002613872664,-0.005202883094,-0.011720748164, & - -0.013752163325,-0.009431602741, 0.000539063909, 0.012636767098, & - 0.021494659597, 0.021951235065, 0.011564169382,-0.007656470131, & - -0.028965787341,-0.042637874109,-0.039203309748,-0.013153301537, & - 0.034320769178, 0.094717832646, 0.154224604789, 0.197758325022, & - 0.213715139513, 0.197758325022, 0.154224604789, 0.094717832646, & - 0.034320769178,-0.013153301537,-0.039203309748,-0.042637874109, & - -0.028965787341,-0.007656470131, 0.011564169382, 0.021951235065, & - 0.021494659597, 0.012636767098, 0.000539063909,-0.009431602741, & - -0.013752163325,-0.011720748164,-0.005202883094, 0.002613872664, & - 0.008706594219, 0.011363155076, 0.010161983649, 0.010051920210, & - 0.000861074040/ - save w,t - - n2=n1/NDOWN - if(n2*NDOWN.ne.n1) stop 'Error in fil4' - k=1-NDOWN - do i=1,n2 - k=k+NDOWN - t(1:NTAPS-NDOWN)=t(1+NDOWN:NTAPS) !Shift old data down in array t - t(1+NTAPS-NDOWN:NTAPS)=id1(k:k+NDOWN-1) !Insert new data at end of t - id2(i)=nint(dot_product(w,t)) - enddo - - return -end subroutine fil4 +subroutine fil4(id1,n1,id2,n2) + +! FIR lowpass filter designed using ScopeFIR + +! fsample = 48000 Hz +! Ntaps = 49 +! fc = 4500 Hz +! fstop = 6000 Hz +! Ripple = 1 dB +! Stop Atten = 40 dB +! fout = 12000 Hz + + parameter (NTAPS=49) + parameter (NDOWN=4) !Downsample ratio + integer*2 id1(n1) + integer*2 id2(*) + real t(NTAPS) + data t/NTAPS*0.0/ + +! Filter coefficients: + real w(NTAPS) + data w/ & + 0.000861074040, 0.010051920210, 0.010161983649, 0.011363155076, & + 0.008706594219, 0.002613872664,-0.005202883094,-0.011720748164, & + -0.013752163325,-0.009431602741, 0.000539063909, 0.012636767098, & + 0.021494659597, 0.021951235065, 0.011564169382,-0.007656470131, & + -0.028965787341,-0.042637874109,-0.039203309748,-0.013153301537, & + 0.034320769178, 0.094717832646, 0.154224604789, 0.197758325022, & + 0.213715139513, 0.197758325022, 0.154224604789, 0.094717832646, & + 0.034320769178,-0.013153301537,-0.039203309748,-0.042637874109, & + -0.028965787341,-0.007656470131, 0.011564169382, 0.021951235065, & + 0.021494659597, 0.012636767098, 0.000539063909,-0.009431602741, & + -0.013752163325,-0.011720748164,-0.005202883094, 0.002613872664, & + 0.008706594219, 0.011363155076, 0.010161983649, 0.010051920210, & + 0.000861074040/ + save w,t + + n2=n1/NDOWN + if(n2*NDOWN.ne.n1) stop 'Error in fil4' + k=1-NDOWN + do i=1,n2 + k=k+NDOWN + t(1:NTAPS-NDOWN)=t(1+NDOWN:NTAPS) !Shift old data down in array t + t(1+NTAPS-NDOWN:NTAPS)=id1(k:k+NDOWN-1) !Insert new data at end of t + id2(i)=nint(dot_product(w,t)) + enddo + + return +end subroutine fil4 diff --git a/lib/fitcal.f90 b/lib/fitcal.f90 index 9a9c3d0e..f85ccf45 100755 --- a/lib/fitcal.f90 +++ b/lib/fitcal.f90 @@ -1,34 +1,34 @@ -subroutine fitcal(x,y,r,iz,a,b,sigmaa,sigmab,rms) - implicit real*8 (a-h,o-z) - real*8 x(iz),y(iz),r(iz) - - sx=0.d0 - sy=0.d0 - sxy=0.d0 - sx2=0.d0 - do i=1,iz - sx=sx + x(i) - sy=sy + y(i) - sxy=sxy + x(i)*y(i) - sx2=sx2 + x(i)*x(i) - enddo - delta=iz*sx2 - sx*sx - a=(sx2*sy - sx*sxy)/delta - b=(iz*sxy - sx*sy)/delta - - sq=0.d0 - do i=1,iz - r(i)=y(i) - (a + b*x(i)) - sq=sq + r(i)**2 - enddo - rms=0. - sigmaa=0. - sigmab=0. - if(iz.ge.3) then - rms=sqrt(sq/(iz-2)) - sigmaa=sqrt(rms*rms*sx2/delta) - sigmab=sqrt(iz*rms*rms/delta) - endif - - return -end subroutine fitcal +subroutine fitcal(x,y,r,iz,a,b,sigmaa,sigmab,rms) + implicit real*8 (a-h,o-z) + real*8 x(iz),y(iz),r(iz) + + sx=0.d0 + sy=0.d0 + sxy=0.d0 + sx2=0.d0 + do i=1,iz + sx=sx + x(i) + sy=sy + y(i) + sxy=sxy + x(i)*y(i) + sx2=sx2 + x(i)*x(i) + enddo + delta=iz*sx2 - sx*sx + a=(sx2*sy - sx*sxy)/delta + b=(iz*sxy - sx*sy)/delta + + sq=0.d0 + do i=1,iz + r(i)=y(i) - (a + b*x(i)) + sq=sq + r(i)**2 + enddo + rms=0. + sigmaa=0. + sigmab=0. + if(iz.ge.3) then + rms=sqrt(sq/(iz-2)) + sigmaa=sqrt(rms*rms*sx2/delta) + sigmab=sqrt(iz*rms*rms/delta) + endif + + return +end subroutine fitcal diff --git a/lib/fix_contest_msg.f90 b/lib/fix_contest_msg.f90 index 601abeb8..8c0345e8 100755 --- a/lib/fix_contest_msg.f90 +++ b/lib/fix_contest_msg.f90 @@ -1,32 +1,32 @@ -subroutine fix_contest_msg(mygrid,msg) - -! If distance from mygrid to grid1 is more thsn 10000 km, change "grid1" -! to "R grid2" where grid2 is the antipodes of grid1. - - character*6 mygrid - character*22 msg - character*6 g1,g2 - logical isgrid - - isgrid(g1)=g1(1:1).ge.'A' .and. g1(1:1).le.'R' .and. g1(2:2).ge.'A' .and. & - g1(2:2).le.'R' .and. g1(3:3).ge.'0' .and. g1(3:3).le.'9' .and. & - g1(4:4).ge.'0' .and. g1(4:4).le.'9' .and. g1(1:4).ne.'RR73' - - n=len(trim(msg)) - if(n.lt.4) return - - g1=msg(n-3:n)//' ' - if(isgrid(g1)) then - call azdist(mygrid,g1,0.d0,nAz,nEl,nDmiles,nDkm,nHotAz,nHotABetter) - if(ndkm.gt.10000) then - call grid2deg(g1,dlong,dlat) - dlong=dlong+180.0 - if(dlong.gt.180.0) dlong=dlong-360.0 - dlat=-dlat - call deg2grid(dlong,dlat,g2) - msg=msg(1:n-4)//'R '//g2(1:4) - endif - endif - - return -end subroutine fix_contest_msg +subroutine fix_contest_msg(mygrid,msg) + +! If distance from mygrid to grid1 is more thsn 10000 km, change "grid1" +! to "R grid2" where grid2 is the antipodes of grid1. + + character*6 mygrid + character*22 msg + character*6 g1,g2 + logical isgrid + + isgrid(g1)=g1(1:1).ge.'A' .and. g1(1:1).le.'R' .and. g1(2:2).ge.'A' .and. & + g1(2:2).le.'R' .and. g1(3:3).ge.'0' .and. g1(3:3).le.'9' .and. & + g1(4:4).ge.'0' .and. g1(4:4).le.'9' .and. g1(1:4).ne.'RR73' + + n=len(trim(msg)) + if(n.lt.4) return + + g1=msg(n-3:n)//' ' + if(isgrid(g1)) then + call azdist(mygrid,g1,0.d0,nAz,nEl,nDmiles,nDkm,nHotAz,nHotABetter) + if(ndkm.gt.10000) then + call grid2deg(g1,dlong,dlat) + dlong=dlong+180.0 + if(dlong.gt.180.0) dlong=dlong-360.0 + dlat=-dlat + call deg2grid(dlong,dlat,g2) + msg=msg(1:n-4)//'R '//g2(1:4) + endif + endif + + return +end subroutine fix_contest_msg diff --git a/lib/fixwav.f90 b/lib/fixwav.f90 index 862c2af0..da113d24 100755 --- a/lib/fixwav.f90 +++ b/lib/fixwav.f90 @@ -1,66 +1,66 @@ -program fixwav - - use wavhdr - parameter (NBANDS=23,NMODES=11) - parameter(NMAX=120*12000) - type(hdr) h - integer*2 id2(NMAX),id(4) - character*8 mode,mode0 - character*6 band - character*12 arg - character*80 infile - character*1 c - logical ok - - nargs=iargc() - if(nargs.ne.1 .and. nargs.ne.5) then - print*,'Usage: fixwav [fMHz mode submode TRperiod] infile' - go to 999 - endif - call getarg(1,infile) - if(nargs.eq.1) go to 10 - read(infile,*) fMHz - call getarg(2,mode0) - call getarg(3,arg) - nsubmode0=-1 - do i=1,8 - if(arg(1:1).eq.char(ichar('A')-1+i)) nsubmode0=i - enddo - if(nsubmode0.lt.0) read(arg,*) nsubmode0 - call getarg(4,arg) - read(arg,*) ntrperiod0 - call getarg(5,infile) - -10 open(10,file=infile,status='old',access='stream') - read(10) h - npts=h%ndata/2 - nfsample=h%nsamrate - read(10) id2(1:npts) - write(*,1002) h%nchan2,h%nbitsam2,h%nsamrate,npts -1002 format('Channels:',i2,' Bits/sample:',i3,' Sample rate:',i6, & - ' Npts:',i8) - - call get_wsjtx_wav_params(id2,band,mode,nsubmode,ntrperiod,ok) - if(nfsample.ne.11025 .and. nfsample.ne.12000) ok=.false. - if(ok) write(*,1010) band,ntrperiod,mode,char(ichar('A')-1+id2(3)) -1010 format('Band: ',a6,' T/R period:',i4,' Mode: ',a8,1x,a1) - - if(.not.ok) write(*,'(a)') 'File has no valid WSJT-X params.' - if(ok .and. nargs.eq.1) go to 999 - - write(*,'(a)',advance='no') 'Do you want to add or change them? (Y/N): ' - read*,c - if(c.ne.'y' .and. c.ne.'Y') go to 999 - - print*,fMHz,mode0,nsubmode0,ntrperiod0 - call set_wsjtx_wav_params(fMHz,mode0,nsubmode0,ntrperiod0,id2) - band="" - mode="" - nsubmode=0 - ntrperiod=0 - call get_wsjtx_wav_params(id2,band,mode,nsubmode,ntrperiod,ok) - write(*,1010) band,ntrperiod,mode,char(ichar('A')-1+id2(3)) - rewind 10 - write(10) h,id2(1:npts) - -999 end program fixwav +program fixwav + + use wavhdr + parameter (NBANDS=23,NMODES=11) + parameter(NMAX=120*12000) + type(hdr) h + integer*2 id2(NMAX),id(4) + character*8 mode,mode0 + character*6 band + character*12 arg + character*80 infile + character*1 c + logical ok + + nargs=iargc() + if(nargs.ne.1 .and. nargs.ne.5) then + print*,'Usage: fixwav [fMHz mode submode TRperiod] infile' + go to 999 + endif + call getarg(1,infile) + if(nargs.eq.1) go to 10 + read(infile,*) fMHz + call getarg(2,mode0) + call getarg(3,arg) + nsubmode0=-1 + do i=1,8 + if(arg(1:1).eq.char(ichar('A')-1+i)) nsubmode0=i + enddo + if(nsubmode0.lt.0) read(arg,*) nsubmode0 + call getarg(4,arg) + read(arg,*) ntrperiod0 + call getarg(5,infile) + +10 open(10,file=infile,status='old',access='stream') + read(10) h + npts=h%ndata/2 + nfsample=h%nsamrate + read(10) id2(1:npts) + write(*,1002) h%nchan2,h%nbitsam2,h%nsamrate,npts +1002 format('Channels:',i2,' Bits/sample:',i3,' Sample rate:',i6, & + ' Npts:',i8) + + call get_wsjtx_wav_params(id2,band,mode,nsubmode,ntrperiod,ok) + if(nfsample.ne.11025 .and. nfsample.ne.12000) ok=.false. + if(ok) write(*,1010) band,ntrperiod,mode,char(ichar('A')-1+id2(3)) +1010 format('Band: ',a6,' T/R period:',i4,' Mode: ',a8,1x,a1) + + if(.not.ok) write(*,'(a)') 'File has no valid WSJT-X params.' + if(ok .and. nargs.eq.1) go to 999 + + write(*,'(a)',advance='no') 'Do you want to add or change them? (Y/N): ' + read*,c + if(c.ne.'y' .and. c.ne.'Y') go to 999 + + print*,fMHz,mode0,nsubmode0,ntrperiod0 + call set_wsjtx_wav_params(fMHz,mode0,nsubmode0,ntrperiod0,id2) + band="" + mode="" + nsubmode=0 + ntrperiod=0 + call get_wsjtx_wav_params(id2,band,mode,nsubmode,ntrperiod,ok) + write(*,1010) band,ntrperiod,mode,char(ichar('A')-1+id2(3)) + rewind 10 + write(10) h,id2(1:npts) + +999 end program fixwav diff --git a/lib/flat1a.f90 b/lib/flat1a.f90 index 0878b23a..b5c0b202 100755 --- a/lib/flat1a.f90 +++ b/lib/flat1a.f90 @@ -1,29 +1,29 @@ -subroutine flat1a(psavg,nsmo,s2,nh,nsteps,nhmax,nsmax) - - real psavg(nh) - real s2(nhmax,nsmax) - real x(8192) - - ia=nsmo/2 + 1 - ib=nh - nsmo/2 - 1 - do i=ia,ib - call pctile(psavg(i-nsmo/2),nsmo,50,x(i)) - enddo - do i=1,ia-1 - x(i)=x(ia) - enddo - do i=ib+1,nh - x(i)=x(ib) - enddo - - do i=1,nh - psavg(i)=psavg(i)/x(i) - do j=1,nsteps - s2(i,j)=s2(i,j)/x(i) - enddo - enddo - - return -end subroutine flat1a - - +subroutine flat1a(psavg,nsmo,s2,nh,nsteps,nhmax,nsmax) + + real psavg(nh) + real s2(nhmax,nsmax) + real x(8192) + + ia=nsmo/2 + 1 + ib=nh - nsmo/2 - 1 + do i=ia,ib + call pctile(psavg(i-nsmo/2),nsmo,50,x(i)) + enddo + do i=1,ia-1 + x(i)=x(ia) + enddo + do i=ib+1,nh + x(i)=x(ib) + enddo + + do i=1,nh + psavg(i)=psavg(i)/x(i) + do j=1,nsteps + s2(i,j)=s2(i,j)/x(i) + enddo + enddo + + return +end subroutine flat1a + + diff --git a/lib/flat1b.f90 b/lib/flat1b.f90 index 1059dbcc..bc22b855 100755 --- a/lib/flat1b.f90 +++ b/lib/flat1b.f90 @@ -1,29 +1,29 @@ -subroutine flat1b(psavg,nsmo,s2,nh,nsteps,nhmax,nsmax) - - real psavg(nh) - real s2(nhmax,nsmax) - real x(8192) - - ia=nsmo/2 + 1 - ib=nh - nsmo/2 - 1 - do i=ia,ib - call pctile(psavg(i-nsmo/2),nsmo,50,x(i)) - enddo - do i=1,ia-1 - x(i)=x(ia) - enddo - do i=ib+1,nh - x(i)=x(ib) - enddo - - do i=1,nh - psavg(i)=psavg(i)/x(i) - do j=1,nsteps - s2(i,j)=s2(i,j)/x(i) - enddo - enddo - - return -end subroutine flat1b - - +subroutine flat1b(psavg,nsmo,s2,nh,nsteps,nhmax,nsmax) + + real psavg(nh) + real s2(nhmax,nsmax) + real x(8192) + + ia=nsmo/2 + 1 + ib=nh - nsmo/2 - 1 + do i=ia,ib + call pctile(psavg(i-nsmo/2),nsmo,50,x(i)) + enddo + do i=1,ia-1 + x(i)=x(ia) + enddo + do i=ib+1,nh + x(i)=x(ib) + enddo + + do i=1,nh + psavg(i)=psavg(i)/x(i) + do j=1,nsteps + s2(i,j)=s2(i,j)/x(i) + enddo + enddo + + return +end subroutine flat1b + + diff --git a/lib/flat4.f90 b/lib/flat4.f90 index b4326590..faf15459 100755 --- a/lib/flat4.f90 +++ b/lib/flat4.f90 @@ -1,53 +1,53 @@ -subroutine flat4(s,npts0,nflatten) - -! Flatten a spectrum for optimum display -! Input: s(npts) Linear scale in power -! nflatten If nflatten=0, convert to dB but do not flatten -! Output: s(npts) Flattened, with dB scale - - - implicit real*8 (a-h,o-z) - real*4 s(6827) - real*4 base - real*8 x(1000),y(1000),a(5) - data nseg/10/,npct/10/ - - npts=min(6827,npts0) - if(s(1).gt.1.e29) go to 900 !Boundary between Rx intervals: do nothing - do i=1,npts - s(i)=10.0*log10(s(i)) !Convert to dB scale - enddo - - if(nflatten.gt.0) then - nterms=5 - if(nflatten.eq.2) nterms=1 - nlen=npts/nseg !Length of test segment - i0=npts/2 !Midpoint - k=0 - do n=1,nseg !Skip first segment, likely rolloff here - ib=n*nlen - ia=ib-nlen+1 - if(n.eq.nseg) ib=npts - call pctile(s(ia),ib-ia+1,npct,base) !Find lowest npct of points - do i=ia,ib - if(s(i).le.base) then - if (k.lt.1000) k=k+1 !Save these "lower envelope" points - x(k)=i-i0 - y(k)=s(i) - endif - enddo - enddo - kz=k - a=0. - - call polyfit(x,y,y,kz,nterms,0,a,chisqr) !Fit a low-order polynomial - - do i=1,npts - t=i-i0 - yfit=a(1)+t*(a(2)+t*(a(3)+t*(a(4)+t*(a(5))))) - s(i)=s(i)-yfit !Subtract the fitted baseline - enddo - endif - -900 return -end subroutine flat4 +subroutine flat4(s,npts0,nflatten) + +! Flatten a spectrum for optimum display +! Input: s(npts) Linear scale in power +! nflatten If nflatten=0, convert to dB but do not flatten +! Output: s(npts) Flattened, with dB scale + + + implicit real*8 (a-h,o-z) + real*4 s(6827) + real*4 base + real*8 x(1000),y(1000),a(5) + data nseg/10/,npct/10/ + + npts=min(6827,npts0) + if(s(1).gt.1.e29) go to 900 !Boundary between Rx intervals: do nothing + do i=1,npts + s(i)=10.0*log10(s(i)) !Convert to dB scale + enddo + + if(nflatten.gt.0) then + nterms=5 + if(nflatten.eq.2) nterms=1 + nlen=npts/nseg !Length of test segment + i0=npts/2 !Midpoint + k=0 + do n=1,nseg !Skip first segment, likely rolloff here + ib=n*nlen + ia=ib-nlen+1 + if(n.eq.nseg) ib=npts + call pctile(s(ia),ib-ia+1,npct,base) !Find lowest npct of points + do i=ia,ib + if(s(i).le.base) then + if (k.lt.1000) k=k+1 !Save these "lower envelope" points + x(k)=i-i0 + y(k)=s(i) + endif + enddo + enddo + kz=k + a=0. + + call polyfit(x,y,y,kz,nterms,0,a,chisqr) !Fit a low-order polynomial + + do i=1,npts + t=i-i0 + yfit=a(1)+t*(a(2)+t*(a(3)+t*(a(4)+t*(a(5))))) + s(i)=s(i)-yfit !Subtract the fitted baseline + enddo + endif + +900 return +end subroutine flat4 diff --git a/lib/fmtave.f90 b/lib/fmtave.f90 index 71879afb..e35dbe56 100755 --- a/lib/fmtave.f90 +++ b/lib/fmtave.f90 @@ -1,64 +1,64 @@ -program fmtave - -! Average groups of frequency-calibration measurements. - - implicit real*8 (a-h,o-z) - character infile*80 - character*8 cutc,cutc1 - - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: fmtave ' - print*,'Example: fmtave fmt.all' - go to 999 - endif - call getarg(1,infile) - - open(10,file=infile,status='old') - open(12,file='fmtave.out',status='unknown') - - write(*,1000) -1000 format(' Freq DF CAL N rms UTC Call'/ & - ' (kHz) (Hz) ? (Hz)'/ & - '----------------------------------------------------') - nkhz0=0 - sum=0.d0 - sumsq=0.d0 - n=0 - do i=1,99999 - read(10,*,end=10) cutc,nkHz,ncal,noffset,faudio,df,dblevel,snr - if((nkHz.ne.nkHz0) .and. i.ne.1) then - ave=sum/n - rms=0.d0 - if(n.gt.1) then - rms=sqrt(abs(sumsq - sum*sum/n)/(n-1.d0)) - endif - fMHz=0.001d0*nkHz0 - write(*,1010) fMHz,ave,ncal0,n,rms,cutc1 - write(12,1010) fMHz,ave,ncal0,n,rms,cutc1 -1010 format(f8.3,f9.3,i4,i5,f8.2,2x,a8,2x,a6) - sum=0.d0 - sumsq=0.d0 - n=0 - endif - dial_error=faudio-noffset - sum=sum + dial_error - sumsq=sumsq + dial_error**2 - n=n+1 - if(n.eq.1) then - cutc1=cutc - ncal0=ncal - endif - nkHz0=nkHz - enddo - -10 ave=sum/n - rms=0.d0 - if(n.gt.0) then - rms=sqrt((sumsq - sum*sum/n)/(n-1.d0)) - endif - fMHz=0.001d0*nkHz - write(*,1010) fMHz,ave,ncal,n,rms,cutc1 - write(12,1010) fMHz,ave,ncal,n,rms,cutc1 - -999 end program fmtave +program fmtave + +! Average groups of frequency-calibration measurements. + + implicit real*8 (a-h,o-z) + character infile*80 + character*8 cutc,cutc1 + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: fmtave ' + print*,'Example: fmtave fmt.all' + go to 999 + endif + call getarg(1,infile) + + open(10,file=infile,status='old') + open(12,file='fmtave.out',status='unknown') + + write(*,1000) +1000 format(' Freq DF CAL N rms UTC Call'/ & + ' (kHz) (Hz) ? (Hz)'/ & + '----------------------------------------------------') + nkhz0=0 + sum=0.d0 + sumsq=0.d0 + n=0 + do i=1,99999 + read(10,*,end=10) cutc,nkHz,ncal,noffset,faudio,df,dblevel,snr + if((nkHz.ne.nkHz0) .and. i.ne.1) then + ave=sum/n + rms=0.d0 + if(n.gt.1) then + rms=sqrt(abs(sumsq - sum*sum/n)/(n-1.d0)) + endif + fMHz=0.001d0*nkHz0 + write(*,1010) fMHz,ave,ncal0,n,rms,cutc1 + write(12,1010) fMHz,ave,ncal0,n,rms,cutc1 +1010 format(f8.3,f9.3,i4,i5,f8.2,2x,a8,2x,a6) + sum=0.d0 + sumsq=0.d0 + n=0 + endif + dial_error=faudio-noffset + sum=sum + dial_error + sumsq=sumsq + dial_error**2 + n=n+1 + if(n.eq.1) then + cutc1=cutc + ncal0=ncal + endif + nkHz0=nkHz + enddo + +10 ave=sum/n + rms=0.d0 + if(n.gt.0) then + rms=sqrt((sumsq - sum*sum/n)/(n-1.d0)) + endif + fMHz=0.001d0*nkHz + write(*,1010) fMHz,ave,ncal,n,rms,cutc1 + write(12,1010) fMHz,ave,ncal,n,rms,cutc1 + +999 end program fmtave diff --git a/lib/fmtmsg.f90 b/lib/fmtmsg.f90 index 611534be..81789e2a 100755 --- a/lib/fmtmsg.f90 +++ b/lib/fmtmsg.f90 @@ -1,21 +1,21 @@ -subroutine fmtmsg(msg,iz) - - character*(*) msg - -! Convert all letters to upper case - iz=len(msg) - do i=1,iz - 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,37 !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*(*) msg + +! Convert all letters to upper case + iz=len(msg) + do i=1,iz + 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,37 !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/lib/foldspec9f.f90 b/lib/foldspec9f.f90 index 9a8afd92..a6436eba 100755 --- a/lib/foldspec9f.f90 +++ b/lib/foldspec9f.f90 @@ -1,30 +1,30 @@ -subroutine foldspec9f(s1,nq,jz,ja,jb,s2) - -! Fold symbol spectra (quarter-symbol steps) from s1 into s2 - - real s1(nq,jz) - real s2(240,340) !340 = 4*85 - integer nsum(340) - - s2=0. - nsum=0 - - do j=ja,jb - k=mod(j-1,340)+1 - nsum(k)=nsum(k)+1 - do i=1,NQ - s2(i,k)=s2(i,k) + s1(i,j) - enddo - enddo - - do k=1,340 - fac=1.0 - if(nsum(k).gt.0) fac=1.0/nsum(k) - s2(1:nq,k)=fac*s2(1:nq,k) - enddo - - ave=sum(s2)/(340.0*nq) - if(ave.gt.0.0) s2=s2/ave - - return -end subroutine foldspec9f +subroutine foldspec9f(s1,nq,jz,ja,jb,s2) + +! Fold symbol spectra (quarter-symbol steps) from s1 into s2 + + real s1(nq,jz) + real s2(240,340) !340 = 4*85 + integer nsum(340) + + s2=0. + nsum=0 + + do j=ja,jb + k=mod(j-1,340)+1 + nsum(k)=nsum(k)+1 + do i=1,NQ + s2(i,k)=s2(i,k) + s1(i,j) + enddo + enddo + + do k=1,340 + fac=1.0 + if(nsum(k).gt.0) fac=1.0/nsum(k) + s2(1:nq,k)=fac*s2(1:nq,k) + enddo + + ave=sum(s2)/(340.0*nq) + if(ave.gt.0.0) s2=s2/ave + + return +end subroutine foldspec9f diff --git a/lib/four2a.f90 b/lib/four2a.f90 index 9acbc0be..52b80394 100755 --- a/lib/four2a.f90 +++ b/lib/four2a.f90 @@ -1,114 +1,114 @@ -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 number of stored plans - parameter (NSMALL=16385) !Max half complex size of "small" FFTs - complex a(nfft) !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.le.0) jz=nfft/2+1 - 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.le.0) jz=nfft/2+1 - 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 number of stored plans + parameter (NSMALL=16385) !Max half complex size of "small" FFTs + complex a(nfft) !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.le.0) jz=nfft/2+1 + 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.le.0) jz=nfft/2+1 + 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/lib/fqso_first.f90 b/lib/fqso_first.f90 index 779bfe95..e553e3e4 100755 --- a/lib/fqso_first.f90 +++ b/lib/fqso_first.f90 @@ -1,32 +1,32 @@ -subroutine fqso_first(nfqso,ntol,ca,ncand) - -! If a candidate was found within +/- ntol of nfqso, move it into ca(1). - - type candidate - real freq - real dt - real sync - real flip - end type candidate - type(candidate) ca(300),cb - - dmin=1.e30 - i0=0 - do i=1,ncand - d=abs(ca(i)%freq-nfqso) - if(d.lt.dmin) then - i0=i - dmin=d - endif - enddo - - if(dmin.lt.float(ntol)) then - cb=ca(i0) - do i=i0,2,-1 - ca(i)=ca(i-1) - enddo - ca(1)=cb - endif - - return -end subroutine fqso_first +subroutine fqso_first(nfqso,ntol,ca,ncand) + +! If a candidate was found within +/- ntol of nfqso, move it into ca(1). + + type candidate + real freq + real dt + real sync + real flip + end type candidate + type(candidate) ca(300),cb + + dmin=1.e30 + i0=0 + do i=1,ncand + d=abs(ca(i)%freq-nfqso) + if(d.lt.dmin) then + i0=i + dmin=d + endif + enddo + + if(dmin.lt.float(ntol)) then + cb=ca(i0) + do i=i0,2,-1 + ca(i)=ca(i-1) + enddo + ca(1)=cb + endif + + return +end subroutine fqso_first diff --git a/lib/fspread_lorentz.f90 b/lib/fspread_lorentz.f90 index e0493932..697d308c 100755 --- a/lib/fspread_lorentz.f90 +++ b/lib/fspread_lorentz.f90 @@ -1,47 +1,47 @@ -subroutine fspread_lorentz(cdat,fspread) - - parameter (NZ=3*12000) - complex cdat(0:NZ-1) - complex cspread(0:NZ-1) - complex z - - twopi=8.0*atan(1.0) - nfft=NZ - nh=nfft/2 - df=12000.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 - cdat=cspread*cdat !Apply Rayleigh fading - - return -end subroutine fspread_lorentz +subroutine fspread_lorentz(cdat,fspread) + + parameter (NZ=3*12000) + complex cdat(0:NZ-1) + complex cspread(0:NZ-1) + complex z + + twopi=8.0*atan(1.0) + nfft=NZ + nh=nfft/2 + df=12000.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 + cdat=cspread*cdat !Apply Rayleigh fading + + return +end subroutine fspread_lorentz diff --git a/lib/fst280_decode.f90 b/lib/fst280_decode.f90 index 6e66cb43..5969146c 100755 --- a/lib/fst280_decode.f90 +++ b/lib/fst280_decode.f90 @@ -1,562 +1,562 @@ -module fst280_decode - type :: fst280_decoder - procedure(fst280_decode_callback), pointer :: callback - contains - procedure :: decode - end type fst280_decoder - - abstract interface - subroutine fst280_decode_callback (this,nutc,sync,nsnr,dt,freq, & - decoded,nap,qual,ntrperiod) - import fst280_decoder - implicit none - class(fst280_decoder), intent(inout) :: this - integer, intent(in) :: nutc - real, intent(in) :: sync - integer, intent(in) :: nsnr - real, intent(in) :: dt - real, intent(in) :: freq - character(len=37), intent(in) :: decoded - integer, intent(in) :: nap - real, intent(in) :: qual - integer, intent(in) :: ntrperiod - end subroutine fst280_decode_callback - end interface - -contains - - subroutine decode(this,callback,iwave,nutc,nQSOProgress,nfqso, & - nfa,nfb,nsubmode,ndeep,ntrperiod,nexp_decode,ntol) - - use timer_module, only: timer - use packjt77 - include 'fst280/fst280_params.f90' - parameter (MAXCAND=100) - class(fst280_decoder), intent(inout) :: this - procedure(fst280_decode_callback) :: callback - character*37 decodes(100) - character*37 msg - character*77 c77 - complex, allocatable :: c2(:) - complex, allocatable :: cframe(:) - complex, allocatable :: c_bigfft(:) !Complex waveform - real, allocatable :: r_data(:) - real llr(280),llra(280),llrb(280),llrc(280),llrd(280) - real candidates(100,4) - real bitmetrics(328,4) - real s4(0:3,NN) - integer itone(NN) - integer hmod - integer*1 apmask(280),cw(280) - integer*1 hbits(328) - integer*1 message101(101),message74(74) - logical badsync,unpk77_success,single_decode - integer*2 iwave(300*12000) - - this%callback => callback - hmod=2**nsubmode - if(nfqso+nqsoprogress.eq.-999) return - Keff=91 - iwspr=0 - nmax=15*12000 - single_decode=iand(nexp_decode,32).eq.32 - if(ntrperiod.eq.15) then - nsps=800 - nmax=15*12000 - ndown=20/hmod - if(hmod.eq.8) ndown=2 - else if(ntrperiod.eq.30) then - nsps=1680 - nmax=30*12000 - ndown=42/hmod - if(hmod.eq.4) ndown=10 - if(hmod.eq.8) ndown=5 - else if(ntrperiod.eq.60) then - nsps=3888 - nmax=60*12000 - ndown=96/hmod - if(hmod.eq.1) ndown=108 - else if(ntrperiod.eq.120) then - nsps=8200 - nmax=120*12000 - if(hmod.eq.1) ndown=205 - ndown=100/hmod - else if(ntrperiod.eq.300) then - nsps=21168 - nmax=300*12000 - ndown=504/hmod - end if - nss=nsps/ndown - fs=12000.0 !Sample rate - fs2=fs/ndown - nspsec=nint(fs2) - dt=1.0/fs !Sample interval (s) - dt2=1.0/fs2 - tt=nsps*dt !Duration of "itone" symbols (s) - baud=1.0/tt - nfft1=2*int(nmax/2) - nh1=nfft1/2 - allocate( r_data(1:nfft1+2) ) - allocate( c_bigfft(0:nfft1/2) ) - - nfft2=nfft1/ndown - allocate( c2(0:nfft2-1) ) - allocate( cframe(0:164*nss-1) ) - - npts=nmax - if(single_decode) then - fa=max(100,nint(nfqso+1.5*hmod*baud-ntol)) - fb=min(4800,nint(nfqso+1.5*hmod*baud+ntol)) - else - fa=max(100,nfa) - fb=min(4800,nfb) - endif - - if(ndeep.eq.3) then - ntmax=4 ! number of block sizes to try - jittermax=2 - norder=3 - elseif(ndeep.eq.2) then - ntmax=3 - jittermax=2 - norder=3 - elseif(ndeep.eq.1) then - ntmax=1 - jittermax=2 - norder=2 - endif - - ! The big fft is done once and is used for calculating the smoothed spectrum -! and also for downconverting/downsampling each candidate. - r_data(1:nfft1)=iwave(1:nfft1) - r_data(nfft1+1:nfft1+2)=0.0 - call four2a(r_data,nfft1,1,-1,0) - c_bigfft=cmplx(r_data(1:nfft1+2:2),r_data(2:nfft1+2:2)) - -! Get first approximation of candidate frequencies - call get_candidates_fst280(c_bigfft,nfft1,nsps,hmod,fs,fa,fb, & - ncand,candidates,base) - - ndecodes=0 - decodes=' ' - - isbest1=0 - isbest8=0 - fc21=0. - fc28=0. - do icand=1,ncand - fc0=candidates(icand,1) - detmet=candidates(icand,2) - -! Downconvert and downsample a slice of the spectrum centered on the -! rough estimate of the candidates frequency. -! Output array c2 is complex baseband sampled at 12000/ndown Sa/sec. -! The size of the downsampled c2 array is nfft2=nfft1/ndown - - call fst280_downsample(c_bigfft,nfft1,ndown,fc0,c2) - - call timer('sync280 ',0) - do isync=0,1 - if(isync.eq.0) then - fc1=0.0 - is0=1.5*nint(fs2) - ishw=1.5*is0 - isst=4*hmod - ifhw=12 - df=.1*baud - else if(isync.eq.1) then - fc1=fc21 - if(hmod.eq.1) fc1=fc28 - is0=isbest1 - if(hmod.eq.1) is0=isbest8 - ishw=4*hmod - isst=1*hmod - ifhw=7 - df=.02*baud - endif - - smax1=0.0 - smax8=0.0 - do if=-ifhw,ifhw - fc=fc1+df*if - do istart=max(1,is0-ishw),is0+ishw,isst - call sync_fst280(c2,istart,fc,hmod,1,nfft2,nss,fs2,sync1) - call sync_fst280(c2,istart,fc,hmod,8,nfft2,nss,fs2,sync8) - if(sync8.gt.smax8) then - fc28=fc - isbest8=istart - smax8=sync8 - endif - if(sync1.gt.smax1) then - fc21=fc - isbest1=istart - smax1=sync1 - endif - enddo - enddo - enddo - call timer('sync280 ',1) - - if(smax8/smax1 .lt. 0.65 ) then - fc2=fc21 - isbest=isbest1 - if(hmod.gt.1) ntmax=1 - njitter=2 - else - fc2=fc28 - isbest=isbest8 - if(hmod.gt.1) ntmax=1 - njitter=2 - endif - fc_synced = fc0 + fc2 - dt_synced = (isbest-fs2)*dt2 !nominal dt is 1 second so frame starts at sample fs2 - candidates(icand,3)=fc_synced - candidates(icand,4)=isbest - enddo -! remove duplicate candidates - do icand=1,ncand - fc=candidates(icand,3) - isbest=nint(candidates(icand,4)) - do ic2=1,ncand - fc2=candidates(ic2,3) - isbest2=nint(candidates(ic2,4)) - if(ic2.ne.icand .and. fc2.gt.0.0) then - if(abs(fc2-fc).lt.0.05*baud) then ! same frequency - if(abs(isbest2-isbest).le.2) then - candidates(ic2,3)=-1 - endif - endif - endif - enddo - enddo - - ic=0 - do icand=1,ncand - if(candidates(icand,3).gt.0) then - ic=ic+1 - candidates(ic,:)=candidates(icand,:) - endif - enddo - ncand=ic - do icand=1,ncand - sync=candidates(icand,2) - fc_synced=candidates(icand,3) - isbest=nint(candidates(icand,4)) - xdt=(isbest-nspsec)/fs2 - - call fst280_downsample(c_bigfft,nfft1,ndown,fc_synced,c2) - - do ijitter=0,jittermax - if(ijitter.eq.0) ioffset=0 - if(ijitter.eq.1) ioffset=1 - if(ijitter.eq.2) ioffset=-1 - is0=isbest+ioffset - if(is0.lt.0) cycle - cframe=c2(is0:is0+164*nss-1) - bitmetrics=0 - call get_fst280_bitmetrics(cframe,nss,hmod,ntmax,bitmetrics,s4,badsync) - if(badsync) cycle - - hbits=0 - where(bitmetrics(:,1).ge.0) hbits=1 - ns1=count(hbits( 71: 78).eq.(/0,0,0,1,1,0,1,1/)) - ns2=count(hbits( 79: 86).eq.(/0,1,0,0,1,1,1,0/)) - ns3=count(hbits(157:164).eq.(/0,0,0,1,1,0,1,1/)) - ns4=count(hbits(165:172).eq.(/0,1,0,0,1,1,1,0/)) - ns5=count(hbits(243:250).eq.(/0,0,0,1,1,0,1,1/)) - ns6=count(hbits(251:258).eq.(/0,1,0,0,1,1,1,0/)) - nsync_qual=ns1+ns2+ns3+ns4+ns5+ns6 - if(nsync_qual.lt. 26) cycle !### Value ?? ### - - scalefac=2.83 - llra( 1: 14)=bitmetrics( 1: 14, 1) - llra( 15: 28)=bitmetrics(315:328, 1) - llra( 29: 42)=bitmetrics( 15: 28, 1) - llra( 43: 56)=bitmetrics(301:314, 1) - llra( 57: 98)=bitmetrics( 29: 70, 1) - llra( 99:168)=bitmetrics( 87:156, 1) - llra(169:238)=bitmetrics(173:242, 1) - llra(239:280)=bitmetrics(259:300, 1) - llra=scalefac*llra - llrb( 1: 14)=bitmetrics( 1: 14, 2) - llrb( 15: 28)=bitmetrics(315:328, 2) - llrb( 29: 42)=bitmetrics( 15: 28, 2) - llrb( 43: 56)=bitmetrics(301:314, 2) - llrb( 57: 98)=bitmetrics( 29: 70, 2) - llrb( 99:168)=bitmetrics( 87:156, 2) - llrb(169:238)=bitmetrics(173:242, 2) - llrb(239:280)=bitmetrics(259:300, 2) - llrb=scalefac*llrb - llrc( 1: 14)=bitmetrics( 1: 14, 3) - llrc( 15: 28)=bitmetrics(315:328, 3) - llrc( 29: 42)=bitmetrics( 15: 28, 3) - llrc( 43: 56)=bitmetrics(301:314, 3) - llrc( 57: 98)=bitmetrics( 29: 70, 3) - llrc( 99:168)=bitmetrics( 87:156, 3) - llrc(169:238)=bitmetrics(173:242, 3) - llrc(239:280)=bitmetrics(259:300, 3) - llrc=scalefac*llrc - llrd( 1: 14)=bitmetrics( 1: 14, 4) - llrd( 15: 28)=bitmetrics(315:328, 4) - llrd( 29: 42)=bitmetrics( 15: 28, 4) - llrd( 43: 56)=bitmetrics(301:314, 4) - llrd( 57: 98)=bitmetrics( 29: 70, 4) - llrd( 99:168)=bitmetrics( 87:156, 4) - llrd(169:238)=bitmetrics(173:242, 4) - llrd(239:280)=bitmetrics(259:300, 4) - llrd=scalefac*llrd - apmask=0 - - do itry=1,ntmax - if(itry.eq.1) llr=llra - if(itry.eq.2) llr=llrb - if(itry.eq.3) llr=llrc - if(itry.eq.4) llr=llrd - dmin=0.0 - nharderrors=-1 - unpk77_success=.false. - if(iwspr.eq.0) then - maxosd=2 - call timer('d280_101',0) - call decode280_101(llr,Keff,maxosd,norder,apmask,message101, & - cw,ntype,nharderrors,dmin) - call timer('d280_101',1) - else - maxosd=2 - call timer('d280_74 ',0) - call decode280_74(llr,Keff,maxosd,norder,apmask,message74,cw, & - ntype,nharderrors,dmin) - call timer('d280_74 ',1) - endif - if(nharderrors .ge.0) then - if(iwspr.eq.0) then - write(c77,'(77i1)') message101(1:77) - call unpack77(c77,0,msg,unpk77_success) - else - write(c77,'(50i1)') message74(1:50) - c77(51:77)='000000000000000000000110000' - call unpack77(c77,0,msg,unpk77_success) - endif - if(unpk77_success) then - idupe=0 - do i=1,ndecodes - if(decodes(i).eq.msg) idupe=1 - enddo - if(idupe.eq.1) exit - ndecodes=ndecodes+1 - decodes(ndecodes)=msg - if(iwspr.eq.0) then - call get_fst280_tones_from_bits(message101,itone,iwspr) - xsig=0 - do i=1,NN - xsig=xsig+s4(itone(i),i)**2 - enddo - arg=400.0*(xsig/base)-1.0 - if(arg.gt.0.0) then - xsnr=10*log10(arg)-21.0-11.7*log10(nsps/800.0) - else - xsnr=-99.9 - endif - endif - nsnr=nint(xsnr) - iaptype=0 - qual=0. - fsig=fc_synced - 1.5*hmod*baud -!write(21,'(8i4,f7.1,f7.2,3f7.1,1x,a37)') & -! nutc,icand,itry,iaptype,ijitter,ntype,nsync_qual,nharderrors,dmin,sync,xsnr,xdt,fsig,msg - call this%callback(nutc,smax1,nsnr,xdt,fsig,msg, & - iaptype,qual,ntrperiod) - goto 2002 - else - cycle - endif - endif - enddo ! metrics - enddo ! istart jitter -2002 continue - enddo !candidate list!ws - - return - end subroutine decode - - subroutine sync_fst280(cd0,i0,f0,hmod,ncoh,np,nss,fs,sync) - -! Compute sync power for a complex, downsampled FST280 signal. - - include 'fst280/fst280_params.f90' - complex cd0(0:np-1) - complex, allocatable, save :: csync(:) - complex, allocatable, save :: csynct(:) - complex ctwk(8*nss) - complex z1,z2,z3 - logical first - integer hmod,isyncword(0:7) - real f0save - data isyncword/0,1,3,2,1,0,2,3/ - data first/.true./,f0save/0.0/,nss0/-1/ - save first,twopi,dt,fac,f0save,nss0 - p(z1)=(real(z1*fac)**2 + aimag(z1*fac)**2)**0.5 !Compute power - - if(nss.ne.nss0 .and. allocated(csync)) deallocate(csync,csynct) - if(first .or. nss.ne.nss0) then - allocate( csync(8*nss) ) - allocate( csynct(8*nss) ) - twopi=8.0*atan(1.0) - dt=1/fs - k=1 - phi=0.0 - do i=0,7 - dphi=twopi*hmod*(isyncword(i)-1.5)/real(nss) - do j=1,nss - csync(k)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - k=k+1 - enddo - enddo - first=.false. - nss0=nss - fac=1.0/(8.0*nss) - endif - - if(f0.ne.f0save) then - dphi=twopi*f0*dt - phi=0.0 - do i=1,8*nss - ctwk(i)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - enddo - csynct=ctwk*csync - f0save=f0 - endif - - i1=i0+35*nss !Costas arrays - i2=i0+78*nss - i3=i0+121*nss - - s1=0.0 - s2=0.0 - s3=0.0 - nsec=8/ncoh - do i=1,nsec - is=(i-1)*ncoh*nss - z1=0 - if(i1+is.ge.1) then - z1=sum(cd0(i1+is:i1+is+ncoh*nss-1)*conjg(csynct(is+1:is+ncoh*nss))) - endif - z2=sum(cd0(i2+is:i2+is+ncoh*nss-1)*conjg(csynct(is+1:is+ncoh*nss))) - z3=0 - if(i3+is+ncoh*nss-1.le.np) then - z3=sum(cd0(i3+is:i3+is+ncoh*nss-1)*conjg(csynct(is+1:is+ncoh*nss))) - endif - s1=s1+abs(z1)/(8*nss) - s2=s2+abs(z2)/(8*nss) - s3=s3+abs(z3)/(8*nss) - enddo - - sync = s1+s2+s3 - - return - end subroutine sync_fst280 - - subroutine fst280_downsample(c_bigfft,nfft1,ndown,f0,c1) - -! Output: Complex data in c(), sampled at 12000/ndown Hz - - complex c_bigfft(0:nfft1/2) - complex c1(0:nfft1/ndown-1) - - df=12000.0/nfft1 - i0=nint(f0/df) - c1(0)=c_bigfft(i0) - nfft2=nfft1/ndown - do i=1,nfft2/2 - if(i0+i.le.nfft1/2) c1(i)=c_bigfft(i0+i) - if(i0-i.ge.0) c1(nfft2-i)=c_bigfft(i0-i) - enddo - c1=c1/nfft2 - call four2a(c1,nfft2,1,1,1) !c2c FFT back to time domain - return - - end subroutine fst280_downsample - - subroutine get_candidates_fst280(c_bigfft,nfft1,nsps,hmod,fs,fa,fb, & - ncand,candidates,base) - - complex c_bigfft(0:nfft1/2) - integer hmod - integer indx(100) - real candidates(100,4) - real candidates0(100,4) - real snr_cand(100) - real s(18000) - real s2(18000) - data nfft1z/-1/ - save nfft1z - - nh1=nfft1/2 - df1=fs/nfft1 - baud=fs/nsps - df2=baud/2.0 - nd=df2/df1 - ndh=nd/2 - ia=nint(max(100.0,fa)/df2) - ib=nint(min(4800.0,fb)/df2) - signal_bw=4*(12000.0/nsps)*hmod - analysis_bw=min(4800.0,fb)-max(100.0,fa) - noise_bw=10.0*signal_bw - if(analysis_bw.gt.noise_bw) then - ina=ia - inb=ib - else - fcenter=(fa+fb)/2.0 - fl = max(100.0,fcenter-noise_bw/2.)/df2 - fh = min(4800.0,fcenter+noise_bw/2.)/df2 - ina=nint(fl) - inb=nint(fh) - endif - s=0. - do i=ina,inb ! noise analysis window includes signal analysis window - j0=nint(i*df2/df1) - do j=j0-ndh,j0+ndh - s(i)=s(i) + real(c_bigfft(j))**2 + aimag(c_bigfft(j))**2 - enddo - enddo - ina=max(ina,1+3*hmod) - inb=min(inb,18000-3*hmod) - s2=0. - do i=ina,inb - s2(i)=s(i-hmod*3) + s(i-hmod) +s(i+hmod) +s(i+hmod*3) - enddo - call pctile(s2(ina+hmod*3:inb-hmod*3),inb-ina+1-hmod*6,30,base) - s2=s2/base - thresh=1.25 - - ncand=0 - candidates=0 - if(ia.lt.3) ia=3 - if(ib.gt.18000-2) ib=18000-2 - do i=ia,ib - if((s2(i).gt.s2(i-2)).and. & - (s2(i).gt.s2(i+2)).and. & - (s2(i).gt.thresh).and.ncand.lt.100) then - ncand=ncand+1 - candidates(ncand,1)=df2*i - candidates(ncand,2)=s2(i) - endif - enddo - - snr_cand=0. - snr_cand(1:ncand)=candidates(1:ncand,2) - call indexx(snr_cand,ncand,indx) - nmax=min(ncand,20) - do i=1,nmax - j=indx(ncand+1-i) - candidates0(i,1:4)=candidates(j,1:4) - enddo - ncand=nmax - candidates(1:ncand,1:4)=candidates0(1:ncand,1:4) - candidates(ncand+1:,1:4)=0. - return - end subroutine get_candidates_fst280 - -end module fst280_decode +module fst280_decode + type :: fst280_decoder + procedure(fst280_decode_callback), pointer :: callback + contains + procedure :: decode + end type fst280_decoder + + abstract interface + subroutine fst280_decode_callback (this,nutc,sync,nsnr,dt,freq, & + decoded,nap,qual,ntrperiod) + import fst280_decoder + implicit none + class(fst280_decoder), intent(inout) :: this + integer, intent(in) :: nutc + real, intent(in) :: sync + integer, intent(in) :: nsnr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=37), intent(in) :: decoded + integer, intent(in) :: nap + real, intent(in) :: qual + integer, intent(in) :: ntrperiod + end subroutine fst280_decode_callback + end interface + +contains + + subroutine decode(this,callback,iwave,nutc,nQSOProgress,nfqso, & + nfa,nfb,nsubmode,ndeep,ntrperiod,nexp_decode,ntol) + + use timer_module, only: timer + use packjt77 + include 'fst280/fst280_params.f90' + parameter (MAXCAND=100) + class(fst280_decoder), intent(inout) :: this + procedure(fst280_decode_callback) :: callback + character*37 decodes(100) + character*37 msg + character*77 c77 + complex, allocatable :: c2(:) + complex, allocatable :: cframe(:) + complex, allocatable :: c_bigfft(:) !Complex waveform + real, allocatable :: r_data(:) + real llr(280),llra(280),llrb(280),llrc(280),llrd(280) + real candidates(100,4) + real bitmetrics(328,4) + real s4(0:3,NN) + integer itone(NN) + integer hmod + integer*1 apmask(280),cw(280) + integer*1 hbits(328) + integer*1 message101(101),message74(74) + logical badsync,unpk77_success,single_decode + integer*2 iwave(300*12000) + + this%callback => callback + hmod=2**nsubmode + if(nfqso+nqsoprogress.eq.-999) return + Keff=91 + iwspr=0 + nmax=15*12000 + single_decode=iand(nexp_decode,32).eq.32 + if(ntrperiod.eq.15) then + nsps=800 + nmax=15*12000 + ndown=20/hmod + if(hmod.eq.8) ndown=2 + else if(ntrperiod.eq.30) then + nsps=1680 + nmax=30*12000 + ndown=42/hmod + if(hmod.eq.4) ndown=10 + if(hmod.eq.8) ndown=5 + else if(ntrperiod.eq.60) then + nsps=3888 + nmax=60*12000 + ndown=96/hmod + if(hmod.eq.1) ndown=108 + else if(ntrperiod.eq.120) then + nsps=8200 + nmax=120*12000 + if(hmod.eq.1) ndown=205 + ndown=100/hmod + else if(ntrperiod.eq.300) then + nsps=21168 + nmax=300*12000 + ndown=504/hmod + end if + nss=nsps/ndown + fs=12000.0 !Sample rate + fs2=fs/ndown + nspsec=nint(fs2) + dt=1.0/fs !Sample interval (s) + dt2=1.0/fs2 + tt=nsps*dt !Duration of "itone" symbols (s) + baud=1.0/tt + nfft1=2*int(nmax/2) + nh1=nfft1/2 + allocate( r_data(1:nfft1+2) ) + allocate( c_bigfft(0:nfft1/2) ) + + nfft2=nfft1/ndown + allocate( c2(0:nfft2-1) ) + allocate( cframe(0:164*nss-1) ) + + npts=nmax + if(single_decode) then + fa=max(100,nint(nfqso+1.5*hmod*baud-ntol)) + fb=min(4800,nint(nfqso+1.5*hmod*baud+ntol)) + else + fa=max(100,nfa) + fb=min(4800,nfb) + endif + + if(ndeep.eq.3) then + ntmax=4 ! number of block sizes to try + jittermax=2 + norder=3 + elseif(ndeep.eq.2) then + ntmax=3 + jittermax=2 + norder=3 + elseif(ndeep.eq.1) then + ntmax=1 + jittermax=2 + norder=2 + endif + + ! The big fft is done once and is used for calculating the smoothed spectrum +! and also for downconverting/downsampling each candidate. + r_data(1:nfft1)=iwave(1:nfft1) + r_data(nfft1+1:nfft1+2)=0.0 + call four2a(r_data,nfft1,1,-1,0) + c_bigfft=cmplx(r_data(1:nfft1+2:2),r_data(2:nfft1+2:2)) + +! Get first approximation of candidate frequencies + call get_candidates_fst280(c_bigfft,nfft1,nsps,hmod,fs,fa,fb, & + ncand,candidates,base) + + ndecodes=0 + decodes=' ' + + isbest1=0 + isbest8=0 + fc21=0. + fc28=0. + do icand=1,ncand + fc0=candidates(icand,1) + detmet=candidates(icand,2) + +! Downconvert and downsample a slice of the spectrum centered on the +! rough estimate of the candidates frequency. +! Output array c2 is complex baseband sampled at 12000/ndown Sa/sec. +! The size of the downsampled c2 array is nfft2=nfft1/ndown + + call fst280_downsample(c_bigfft,nfft1,ndown,fc0,c2) + + call timer('sync280 ',0) + do isync=0,1 + if(isync.eq.0) then + fc1=0.0 + is0=1.5*nint(fs2) + ishw=1.5*is0 + isst=4*hmod + ifhw=12 + df=.1*baud + else if(isync.eq.1) then + fc1=fc21 + if(hmod.eq.1) fc1=fc28 + is0=isbest1 + if(hmod.eq.1) is0=isbest8 + ishw=4*hmod + isst=1*hmod + ifhw=7 + df=.02*baud + endif + + smax1=0.0 + smax8=0.0 + do if=-ifhw,ifhw + fc=fc1+df*if + do istart=max(1,is0-ishw),is0+ishw,isst + call sync_fst280(c2,istart,fc,hmod,1,nfft2,nss,fs2,sync1) + call sync_fst280(c2,istart,fc,hmod,8,nfft2,nss,fs2,sync8) + if(sync8.gt.smax8) then + fc28=fc + isbest8=istart + smax8=sync8 + endif + if(sync1.gt.smax1) then + fc21=fc + isbest1=istart + smax1=sync1 + endif + enddo + enddo + enddo + call timer('sync280 ',1) + + if(smax8/smax1 .lt. 0.65 ) then + fc2=fc21 + isbest=isbest1 + if(hmod.gt.1) ntmax=1 + njitter=2 + else + fc2=fc28 + isbest=isbest8 + if(hmod.gt.1) ntmax=1 + njitter=2 + endif + fc_synced = fc0 + fc2 + dt_synced = (isbest-fs2)*dt2 !nominal dt is 1 second so frame starts at sample fs2 + candidates(icand,3)=fc_synced + candidates(icand,4)=isbest + enddo +! remove duplicate candidates + do icand=1,ncand + fc=candidates(icand,3) + isbest=nint(candidates(icand,4)) + do ic2=1,ncand + fc2=candidates(ic2,3) + isbest2=nint(candidates(ic2,4)) + if(ic2.ne.icand .and. fc2.gt.0.0) then + if(abs(fc2-fc).lt.0.05*baud) then ! same frequency + if(abs(isbest2-isbest).le.2) then + candidates(ic2,3)=-1 + endif + endif + endif + enddo + enddo + + ic=0 + do icand=1,ncand + if(candidates(icand,3).gt.0) then + ic=ic+1 + candidates(ic,:)=candidates(icand,:) + endif + enddo + ncand=ic + do icand=1,ncand + sync=candidates(icand,2) + fc_synced=candidates(icand,3) + isbest=nint(candidates(icand,4)) + xdt=(isbest-nspsec)/fs2 + + call fst280_downsample(c_bigfft,nfft1,ndown,fc_synced,c2) + + do ijitter=0,jittermax + if(ijitter.eq.0) ioffset=0 + if(ijitter.eq.1) ioffset=1 + if(ijitter.eq.2) ioffset=-1 + is0=isbest+ioffset + if(is0.lt.0) cycle + cframe=c2(is0:is0+164*nss-1) + bitmetrics=0 + call get_fst280_bitmetrics(cframe,nss,hmod,ntmax,bitmetrics,s4,badsync) + if(badsync) cycle + + hbits=0 + where(bitmetrics(:,1).ge.0) hbits=1 + ns1=count(hbits( 71: 78).eq.(/0,0,0,1,1,0,1,1/)) + ns2=count(hbits( 79: 86).eq.(/0,1,0,0,1,1,1,0/)) + ns3=count(hbits(157:164).eq.(/0,0,0,1,1,0,1,1/)) + ns4=count(hbits(165:172).eq.(/0,1,0,0,1,1,1,0/)) + ns5=count(hbits(243:250).eq.(/0,0,0,1,1,0,1,1/)) + ns6=count(hbits(251:258).eq.(/0,1,0,0,1,1,1,0/)) + nsync_qual=ns1+ns2+ns3+ns4+ns5+ns6 + if(nsync_qual.lt. 26) cycle !### Value ?? ### + + scalefac=2.83 + llra( 1: 14)=bitmetrics( 1: 14, 1) + llra( 15: 28)=bitmetrics(315:328, 1) + llra( 29: 42)=bitmetrics( 15: 28, 1) + llra( 43: 56)=bitmetrics(301:314, 1) + llra( 57: 98)=bitmetrics( 29: 70, 1) + llra( 99:168)=bitmetrics( 87:156, 1) + llra(169:238)=bitmetrics(173:242, 1) + llra(239:280)=bitmetrics(259:300, 1) + llra=scalefac*llra + llrb( 1: 14)=bitmetrics( 1: 14, 2) + llrb( 15: 28)=bitmetrics(315:328, 2) + llrb( 29: 42)=bitmetrics( 15: 28, 2) + llrb( 43: 56)=bitmetrics(301:314, 2) + llrb( 57: 98)=bitmetrics( 29: 70, 2) + llrb( 99:168)=bitmetrics( 87:156, 2) + llrb(169:238)=bitmetrics(173:242, 2) + llrb(239:280)=bitmetrics(259:300, 2) + llrb=scalefac*llrb + llrc( 1: 14)=bitmetrics( 1: 14, 3) + llrc( 15: 28)=bitmetrics(315:328, 3) + llrc( 29: 42)=bitmetrics( 15: 28, 3) + llrc( 43: 56)=bitmetrics(301:314, 3) + llrc( 57: 98)=bitmetrics( 29: 70, 3) + llrc( 99:168)=bitmetrics( 87:156, 3) + llrc(169:238)=bitmetrics(173:242, 3) + llrc(239:280)=bitmetrics(259:300, 3) + llrc=scalefac*llrc + llrd( 1: 14)=bitmetrics( 1: 14, 4) + llrd( 15: 28)=bitmetrics(315:328, 4) + llrd( 29: 42)=bitmetrics( 15: 28, 4) + llrd( 43: 56)=bitmetrics(301:314, 4) + llrd( 57: 98)=bitmetrics( 29: 70, 4) + llrd( 99:168)=bitmetrics( 87:156, 4) + llrd(169:238)=bitmetrics(173:242, 4) + llrd(239:280)=bitmetrics(259:300, 4) + llrd=scalefac*llrd + apmask=0 + + do itry=1,ntmax + if(itry.eq.1) llr=llra + if(itry.eq.2) llr=llrb + if(itry.eq.3) llr=llrc + if(itry.eq.4) llr=llrd + dmin=0.0 + nharderrors=-1 + unpk77_success=.false. + if(iwspr.eq.0) then + maxosd=2 + call timer('d280_101',0) + call decode280_101(llr,Keff,maxosd,norder,apmask,message101, & + cw,ntype,nharderrors,dmin) + call timer('d280_101',1) + else + maxosd=2 + call timer('d280_74 ',0) + call decode280_74(llr,Keff,maxosd,norder,apmask,message74,cw, & + ntype,nharderrors,dmin) + call timer('d280_74 ',1) + endif + if(nharderrors .ge.0) then + if(iwspr.eq.0) then + write(c77,'(77i1)') message101(1:77) + call unpack77(c77,0,msg,unpk77_success) + else + write(c77,'(50i1)') message74(1:50) + c77(51:77)='000000000000000000000110000' + call unpack77(c77,0,msg,unpk77_success) + endif + if(unpk77_success) then + idupe=0 + do i=1,ndecodes + if(decodes(i).eq.msg) idupe=1 + enddo + if(idupe.eq.1) exit + ndecodes=ndecodes+1 + decodes(ndecodes)=msg + if(iwspr.eq.0) then + call get_fst280_tones_from_bits(message101,itone,iwspr) + xsig=0 + do i=1,NN + xsig=xsig+s4(itone(i),i)**2 + enddo + arg=400.0*(xsig/base)-1.0 + if(arg.gt.0.0) then + xsnr=10*log10(arg)-21.0-11.7*log10(nsps/800.0) + else + xsnr=-99.9 + endif + endif + nsnr=nint(xsnr) + iaptype=0 + qual=0. + fsig=fc_synced - 1.5*hmod*baud +!write(21,'(8i4,f7.1,f7.2,3f7.1,1x,a37)') & +! nutc,icand,itry,iaptype,ijitter,ntype,nsync_qual,nharderrors,dmin,sync,xsnr,xdt,fsig,msg + call this%callback(nutc,smax1,nsnr,xdt,fsig,msg, & + iaptype,qual,ntrperiod) + goto 2002 + else + cycle + endif + endif + enddo ! metrics + enddo ! istart jitter +2002 continue + enddo !candidate list!ws + + return + end subroutine decode + + subroutine sync_fst280(cd0,i0,f0,hmod,ncoh,np,nss,fs,sync) + +! Compute sync power for a complex, downsampled FST280 signal. + + include 'fst280/fst280_params.f90' + complex cd0(0:np-1) + complex, allocatable, save :: csync(:) + complex, allocatable, save :: csynct(:) + complex ctwk(8*nss) + complex z1,z2,z3 + logical first + integer hmod,isyncword(0:7) + real f0save + data isyncword/0,1,3,2,1,0,2,3/ + data first/.true./,f0save/0.0/,nss0/-1/ + save first,twopi,dt,fac,f0save,nss0 + p(z1)=(real(z1*fac)**2 + aimag(z1*fac)**2)**0.5 !Compute power + + if(nss.ne.nss0 .and. allocated(csync)) deallocate(csync,csynct) + if(first .or. nss.ne.nss0) then + allocate( csync(8*nss) ) + allocate( csynct(8*nss) ) + twopi=8.0*atan(1.0) + dt=1/fs + k=1 + phi=0.0 + do i=0,7 + dphi=twopi*hmod*(isyncword(i)-1.5)/real(nss) + do j=1,nss + csync(k)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + k=k+1 + enddo + enddo + first=.false. + nss0=nss + fac=1.0/(8.0*nss) + endif + + if(f0.ne.f0save) then + dphi=twopi*f0*dt + phi=0.0 + do i=1,8*nss + ctwk(i)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + enddo + csynct=ctwk*csync + f0save=f0 + endif + + i1=i0+35*nss !Costas arrays + i2=i0+78*nss + i3=i0+121*nss + + s1=0.0 + s2=0.0 + s3=0.0 + nsec=8/ncoh + do i=1,nsec + is=(i-1)*ncoh*nss + z1=0 + if(i1+is.ge.1) then + z1=sum(cd0(i1+is:i1+is+ncoh*nss-1)*conjg(csynct(is+1:is+ncoh*nss))) + endif + z2=sum(cd0(i2+is:i2+is+ncoh*nss-1)*conjg(csynct(is+1:is+ncoh*nss))) + z3=0 + if(i3+is+ncoh*nss-1.le.np) then + z3=sum(cd0(i3+is:i3+is+ncoh*nss-1)*conjg(csynct(is+1:is+ncoh*nss))) + endif + s1=s1+abs(z1)/(8*nss) + s2=s2+abs(z2)/(8*nss) + s3=s3+abs(z3)/(8*nss) + enddo + + sync = s1+s2+s3 + + return + end subroutine sync_fst280 + + subroutine fst280_downsample(c_bigfft,nfft1,ndown,f0,c1) + +! Output: Complex data in c(), sampled at 12000/ndown Hz + + complex c_bigfft(0:nfft1/2) + complex c1(0:nfft1/ndown-1) + + df=12000.0/nfft1 + i0=nint(f0/df) + c1(0)=c_bigfft(i0) + nfft2=nfft1/ndown + do i=1,nfft2/2 + if(i0+i.le.nfft1/2) c1(i)=c_bigfft(i0+i) + if(i0-i.ge.0) c1(nfft2-i)=c_bigfft(i0-i) + enddo + c1=c1/nfft2 + call four2a(c1,nfft2,1,1,1) !c2c FFT back to time domain + return + + end subroutine fst280_downsample + + subroutine get_candidates_fst280(c_bigfft,nfft1,nsps,hmod,fs,fa,fb, & + ncand,candidates,base) + + complex c_bigfft(0:nfft1/2) + integer hmod + integer indx(100) + real candidates(100,4) + real candidates0(100,4) + real snr_cand(100) + real s(18000) + real s2(18000) + data nfft1z/-1/ + save nfft1z + + nh1=nfft1/2 + df1=fs/nfft1 + baud=fs/nsps + df2=baud/2.0 + nd=df2/df1 + ndh=nd/2 + ia=nint(max(100.0,fa)/df2) + ib=nint(min(4800.0,fb)/df2) + signal_bw=4*(12000.0/nsps)*hmod + analysis_bw=min(4800.0,fb)-max(100.0,fa) + noise_bw=10.0*signal_bw + if(analysis_bw.gt.noise_bw) then + ina=ia + inb=ib + else + fcenter=(fa+fb)/2.0 + fl = max(100.0,fcenter-noise_bw/2.)/df2 + fh = min(4800.0,fcenter+noise_bw/2.)/df2 + ina=nint(fl) + inb=nint(fh) + endif + s=0. + do i=ina,inb ! noise analysis window includes signal analysis window + j0=nint(i*df2/df1) + do j=j0-ndh,j0+ndh + s(i)=s(i) + real(c_bigfft(j))**2 + aimag(c_bigfft(j))**2 + enddo + enddo + ina=max(ina,1+3*hmod) + inb=min(inb,18000-3*hmod) + s2=0. + do i=ina,inb + s2(i)=s(i-hmod*3) + s(i-hmod) +s(i+hmod) +s(i+hmod*3) + enddo + call pctile(s2(ina+hmod*3:inb-hmod*3),inb-ina+1-hmod*6,30,base) + s2=s2/base + thresh=1.25 + + ncand=0 + candidates=0 + if(ia.lt.3) ia=3 + if(ib.gt.18000-2) ib=18000-2 + do i=ia,ib + if((s2(i).gt.s2(i-2)).and. & + (s2(i).gt.s2(i+2)).and. & + (s2(i).gt.thresh).and.ncand.lt.100) then + ncand=ncand+1 + candidates(ncand,1)=df2*i + candidates(ncand,2)=s2(i) + endif + enddo + + snr_cand=0. + snr_cand(1:ncand)=candidates(1:ncand,2) + call indexx(snr_cand,ncand,indx) + nmax=min(ncand,20) + do i=1,nmax + j=indx(ncand+1-i) + candidates0(i,1:4)=candidates(j,1:4) + enddo + ncand=nmax + candidates(1:ncand,1:4)=candidates0(1:ncand,1:4) + candidates(ncand+1:,1:4)=0. + return + end subroutine get_candidates_fst280 + +end module fst280_decode diff --git a/lib/fst4/bpdecode240_101.f90 b/lib/fst4/bpdecode240_101.f90 index 544e9ee1..1e2adbb6 100755 --- a/lib/fst4/bpdecode240_101.f90 +++ b/lib/fst4/bpdecode240_101.f90 @@ -1,111 +1,111 @@ -subroutine bpdecode240_101(llr,apmask,maxiterations,message101,cw,nharderror,iter,ncheck) -! -! A log-domain belief propagation decoder for the (240,101) code. -! - integer, parameter:: N=240, K=101, M=N-K - integer*1 cw(N),apmask(N) - integer*1 decoded(K) - integer*1 message101(101) - integer nrw(M),ncw - integer Nm(6,M) - integer Mn(3,N) ! 3 checks per bit - integer synd(M) - real tov(3,N) - real toc(6,M) - real tanhtoc(6,M) - real zn(N) - real llr(N) - real Tmn - - include "ldpc_240_101_parity.f90" - - decoded=0 - toc=0 - tov=0 - tanhtoc=0 -! initialize messages to checks - do j=1,M - do i=1,nrw(j) - toc(i,j)=llr((Nm(i,j))) - enddo - enddo - - ncnt=0 - nclast=0 - do iter=0,maxiterations -! Update bit log likelihood ratios (tov=0 in iteration 0). - do i=1,N - if( apmask(i) .ne. 1 ) then - zn(i)=llr(i)+sum(tov(1:ncw,i)) - else - zn(i)=llr(i) - endif - enddo - -! Check to see if we have a codeword (check before we do any iteration). - cw=0 - where( zn .gt. 0. ) cw=1 - ncheck=0 - do i=1,M - synd(i)=sum(cw(Nm(1:nrw(i),i))) - if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 -! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied' - enddo - if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it - decoded=cw(1:101) - call get_crc24(decoded,101,nbadcrc) - nharderror=count( (2*cw-1)*llr .lt. 0.0 ) - if(nbadcrc.eq.0) then - message101=decoded(1:101) - return - endif - endif - - if( iter.gt.0 ) then ! this code block implements an early stopping criterion -! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion - nd=ncheck-nclast - if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased - ncnt=0 ! reset counter - else - ncnt=ncnt+1 - endif -! write(*,*) iter,ncheck,nd,ncnt - if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then - nharderror=-1 - return - endif - endif - nclast=ncheck - -! Send messages from bits to check nodes - do j=1,M - do i=1,nrw(j) - ibj=Nm(i,j) - toc(i,j)=zn(ibj) - do kk=1,ncw ! subtract off what the bit had received from the check - if( Mn(kk,ibj) .eq. j ) then - toc(i,j)=toc(i,j)-tov(kk,ibj) - endif - enddo - enddo - enddo - -! send messages from check nodes to variable nodes - do i=1,M - tanhtoc(1:6,i)=tanh(-toc(1:6,i)/2) - enddo - - do j=1,N - do i=1,ncw - ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j - Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) - call platanh(-Tmn,y) -! y=atanh(-Tmn) - tov(i,j)=2*y - enddo - enddo - - enddo - nharderror=-1 - return -end subroutine bpdecode240_101 +subroutine bpdecode240_101(llr,apmask,maxiterations,message101,cw,nharderror,iter,ncheck) +! +! A log-domain belief propagation decoder for the (240,101) code. +! + integer, parameter:: N=240, K=101, M=N-K + integer*1 cw(N),apmask(N) + integer*1 decoded(K) + integer*1 message101(101) + integer nrw(M),ncw + integer Nm(6,M) + integer Mn(3,N) ! 3 checks per bit + integer synd(M) + real tov(3,N) + real toc(6,M) + real tanhtoc(6,M) + real zn(N) + real llr(N) + real Tmn + + include "ldpc_240_101_parity.f90" + + decoded=0 + toc=0 + tov=0 + tanhtoc=0 +! initialize messages to checks + do j=1,M + do i=1,nrw(j) + toc(i,j)=llr((Nm(i,j))) + enddo + enddo + + ncnt=0 + nclast=0 + do iter=0,maxiterations +! Update bit log likelihood ratios (tov=0 in iteration 0). + do i=1,N + if( apmask(i) .ne. 1 ) then + zn(i)=llr(i)+sum(tov(1:ncw,i)) + else + zn(i)=llr(i) + endif + enddo + +! Check to see if we have a codeword (check before we do any iteration). + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(1:nrw(i),i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 +! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied' + enddo + if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it + decoded=cw(1:101) + call get_crc24(decoded,101,nbadcrc) + nharderror=count( (2*cw-1)*llr .lt. 0.0 ) + if(nbadcrc.eq.0) then + message101=decoded(1:101) + return + endif + endif + + if( iter.gt.0 ) then ! this code block implements an early stopping criterion +! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion + nd=ncheck-nclast + if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased + ncnt=0 ! reset counter + else + ncnt=ncnt+1 + endif +! write(*,*) iter,ncheck,nd,ncnt + if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then + nharderror=-1 + return + endif + endif + nclast=ncheck + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw(j) + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,ncw ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then + toc(i,j)=toc(i,j)-tov(kk,ibj) + endif + enddo + enddo + enddo + +! send messages from check nodes to variable nodes + do i=1,M + tanhtoc(1:6,i)=tanh(-toc(1:6,i)/2) + enddo + + do j=1,N + do i=1,ncw + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) + call platanh(-Tmn,y) +! y=atanh(-Tmn) + tov(i,j)=2*y + enddo + enddo + + enddo + nharderror=-1 + return +end subroutine bpdecode240_101 diff --git a/lib/fst4/decode240_101.f90 b/lib/fst4/decode240_101.f90 index dd13d144..4271a464 100755 --- a/lib/fst4/decode240_101.f90 +++ b/lib/fst4/decode240_101.f90 @@ -1,155 +1,155 @@ -subroutine decode240_101(llr,Keff,maxosd,norder,apmask,message101,cw,ntype,nharderror,dmin) -! -! A hybrid bp/osd decoder for the (240,101) code. -! -! maxosd<0: do bp only -! maxosd=0: do bp and then call osd once with channel llrs -! maxosd>1: do bp and then call osd maxosd times with saved bp outputs -! norder : osd decoding depth -! - integer, parameter:: N=240, K=101, M=N-K - integer*1 cw(N),apmask(N) - integer*1 nxor(N),hdec(N) - integer*1 message101(101),m101(101) - integer nrw(M),ncw - integer Nm(6,M) - integer Mn(3,N) ! 3 checks per bit - integer synd(M) - real tov(3,N) - real toc(6,M) - real tanhtoc(6,M) - real zn(N),zsum(N),zsave(N,3) - real llr(N) - real Tmn - - include "ldpc_240_101_parity.f90" - - maxiterations=30 - nosd=0 - if(maxosd.gt.3) maxosd=3 - if(maxosd.eq.0) then ! osd with channel llrs - nosd=1 - zsave(:,1)=llr - elseif(maxosd.gt.0) then ! - nosd=maxosd - elseif(maxosd.lt.0) then ! just bp - nosd=0 - endif - - toc=0 - tov=0 - tanhtoc=0 -! initialize messages to checks - do j=1,M - do i=1,nrw(j) - toc(i,j)=llr((Nm(i,j))) - enddo - enddo - - ncnt=0 - nclast=0 - zsum=0.0 - do iter=0,maxiterations -! Update bit log likelihood ratios (tov=0 in iteration 0). - do i=1,N - if( apmask(i) .ne. 1 ) then - zn(i)=llr(i)+sum(tov(1:ncw,i)) - else - zn(i)=llr(i) - endif - enddo - zsum=zsum+zn - if(iter.gt.0 .and. iter.le.maxosd) then - zsave(:,iter)=zsum - endif - -! Check to see if we have a codeword (check before we do any iteration). - cw=0 - where( zn .gt. 0. ) cw=1 - ncheck=0 - do i=1,M - synd(i)=sum(cw(Nm(1:nrw(i),i))) - if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 - enddo - if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it - m101=0 - m101(1:101)=cw(1:101) - call get_crc24(m101,101,nbadcrc) - if(nbadcrc.eq.0) then - message101=cw(1:101) - hdec=0 - where(llr .ge. 0) hdec=1 - nxor=ieor(hdec,cw) - nharderror=sum(nxor) - dmin=sum(nxor*abs(llr)) - ntype=1 - return - endif - endif - - if( iter.gt.0 ) then ! this code block implements an early stopping criterion -! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion - nd=ncheck-nclast - if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased - ncnt=0 ! reset counter - else - ncnt=ncnt+1 - endif -! write(*,*) iter,ncheck,nd,ncnt - if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then - nharderror=-1 - exit - endif - endif - nclast=ncheck - -! Send messages from bits to check nodes - do j=1,M - do i=1,nrw(j) - ibj=Nm(i,j) - toc(i,j)=zn(ibj) - do kk=1,ncw ! subtract off what the bit had received from the check - if( Mn(kk,ibj) .eq. j ) then - toc(i,j)=toc(i,j)-tov(kk,ibj) - endif - enddo - enddo - enddo - -! send messages from check nodes to variable nodes - do i=1,M - tanhtoc(1:6,i)=tanh(-toc(1:6,i)/2) - enddo - - do j=1,N - do i=1,ncw - ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j - Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) - call platanh(-Tmn,y) -! y=atanh(-Tmn) - tov(i,j)=2*y - enddo - enddo - - enddo ! bp iterations - - do i=1,nosd - zn=zsave(:,i) - call osd240_101(zn,Keff,apmask,norder,message101,cw,nharderror,dminosd) - if(nharderror.gt.0) then - hdec=0 - where(llr .ge. 0) hdec=1 - nxor=ieor(hdec,cw) - nharderror=sum(nxor) ! re-calculate nharderror based on input llrs - dmin=sum(nxor*abs(llr)) - ntype=1+i - return - endif - enddo - - ntype=0 - nharderror=-1 - dminosd=0.0 - - return -end subroutine decode240_101 +subroutine decode240_101(llr,Keff,maxosd,norder,apmask,message101,cw,ntype,nharderror,dmin) +! +! A hybrid bp/osd decoder for the (240,101) code. +! +! maxosd<0: do bp only +! maxosd=0: do bp and then call osd once with channel llrs +! maxosd>1: do bp and then call osd maxosd times with saved bp outputs +! norder : osd decoding depth +! + integer, parameter:: N=240, K=101, M=N-K + integer*1 cw(N),apmask(N) + integer*1 nxor(N),hdec(N) + integer*1 message101(101),m101(101) + integer nrw(M),ncw + integer Nm(6,M) + integer Mn(3,N) ! 3 checks per bit + integer synd(M) + real tov(3,N) + real toc(6,M) + real tanhtoc(6,M) + real zn(N),zsum(N),zsave(N,3) + real llr(N) + real Tmn + + include "ldpc_240_101_parity.f90" + + maxiterations=30 + nosd=0 + if(maxosd.gt.3) maxosd=3 + if(maxosd.eq.0) then ! osd with channel llrs + nosd=1 + zsave(:,1)=llr + elseif(maxosd.gt.0) then ! + nosd=maxosd + elseif(maxosd.lt.0) then ! just bp + nosd=0 + endif + + toc=0 + tov=0 + tanhtoc=0 +! initialize messages to checks + do j=1,M + do i=1,nrw(j) + toc(i,j)=llr((Nm(i,j))) + enddo + enddo + + ncnt=0 + nclast=0 + zsum=0.0 + do iter=0,maxiterations +! Update bit log likelihood ratios (tov=0 in iteration 0). + do i=1,N + if( apmask(i) .ne. 1 ) then + zn(i)=llr(i)+sum(tov(1:ncw,i)) + else + zn(i)=llr(i) + endif + enddo + zsum=zsum+zn + if(iter.gt.0 .and. iter.le.maxosd) then + zsave(:,iter)=zsum + endif + +! Check to see if we have a codeword (check before we do any iteration). + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(1:nrw(i),i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 + enddo + if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it + m101=0 + m101(1:101)=cw(1:101) + call get_crc24(m101,101,nbadcrc) + if(nbadcrc.eq.0) then + message101=cw(1:101) + hdec=0 + where(llr .ge. 0) hdec=1 + nxor=ieor(hdec,cw) + nharderror=sum(nxor) + dmin=sum(nxor*abs(llr)) + ntype=1 + return + endif + endif + + if( iter.gt.0 ) then ! this code block implements an early stopping criterion +! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion + nd=ncheck-nclast + if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased + ncnt=0 ! reset counter + else + ncnt=ncnt+1 + endif +! write(*,*) iter,ncheck,nd,ncnt + if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then + nharderror=-1 + exit + endif + endif + nclast=ncheck + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw(j) + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,ncw ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then + toc(i,j)=toc(i,j)-tov(kk,ibj) + endif + enddo + enddo + enddo + +! send messages from check nodes to variable nodes + do i=1,M + tanhtoc(1:6,i)=tanh(-toc(1:6,i)/2) + enddo + + do j=1,N + do i=1,ncw + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) + call platanh(-Tmn,y) +! y=atanh(-Tmn) + tov(i,j)=2*y + enddo + enddo + + enddo ! bp iterations + + do i=1,nosd + zn=zsave(:,i) + call osd240_101(zn,Keff,apmask,norder,message101,cw,nharderror,dminosd) + if(nharderror.gt.0) then + hdec=0 + where(llr .ge. 0) hdec=1 + nxor=ieor(hdec,cw) + nharderror=sum(nxor) ! re-calculate nharderror based on input llrs + dmin=sum(nxor*abs(llr)) + ntype=1+i + return + endif + enddo + + ntype=0 + nharderror=-1 + dminosd=0.0 + + return +end subroutine decode240_101 diff --git a/lib/fst4/decode240_74.f90 b/lib/fst4/decode240_74.f90 index 60c864a0..f5aac2e1 100755 --- a/lib/fst4/decode240_74.f90 +++ b/lib/fst4/decode240_74.f90 @@ -1,161 +1,161 @@ -subroutine decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharderror,dmin) -! -! A hybrid bp/osd decoder for the (240,74) code. -! -! maxosd<0: do bp only -! maxosd=0: do bp and then call osd once with channel llrs -! maxosd>1: do bp and then call osd maxosd times with saved bp outputs -! norder : osd decoding depth -! - integer, parameter:: N=240, K=74, M=N-K - integer*1 cw(N),apmask(N) - integer*1 nxor(N),hdec(N) - integer*1 message74(74),m74(74) - integer nrw(M),ncw - integer Nm(5,M) - integer Mn(3,N) ! 3 checks per bit - integer synd(M) - real tov(3,N) - real toc(5,M) - real tanhtoc(5,M) - real zn(N),zsum(N),zsave(N,3) - real llr(N) - real Tmn - - include "ldpc_240_74_parity.f90" - - maxiterations=30 - if(Keff.eq.50) maxiterations=1 - - nosd=0 - if(maxosd.gt.3) maxosd=3 - if(maxosd.eq.0) then ! osd with channel llrs - nosd=1 - zsave(:,1)=llr - elseif(maxosd.gt.0) then ! - nosd=maxosd - elseif(maxosd.lt.0) then ! just bp - nosd=0 - endif - - if(maxosd.eq.0) goto 73 - - toc=0 - tov=0 - tanhtoc=0 -! initialize messages to checks - do j=1,M - do i=1,nrw(j) - toc(i,j)=llr((Nm(i,j))) - enddo - enddo - - ncnt=0 - nclast=0 - zsum=0.0 - do iter=0,maxiterations -! Update bit log likelihood ratios (tov=0 in iteration 0). - do i=1,N - if( apmask(i) .ne. 1 ) then - zn(i)=llr(i)+sum(tov(1:ncw,i)) - else - zn(i)=llr(i) - endif - enddo - zsum=zsum+zn - if(iter.gt.0 .and. iter.le.maxosd) then - zsave(:,iter)=zsum - endif - -! Check to see if we have a codeword (check before we do any iteration). - cw=0 - where( zn .gt. 0. ) cw=1 - ncheck=0 - do i=1,M - synd(i)=sum(cw(Nm(1:nrw(i),i))) - if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 - enddo - if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it - m74=0 - m74(1:74)=cw(1:74) - call get_crc24(m74,74,nbadcrc) - if(nbadcrc.eq.0) then - message74=cw(1:74) - hdec=0 - where(llr .ge. 0) hdec=1 - nxor=ieor(hdec,cw) - nharderror=sum(nxor) - dmin=sum(nxor*abs(llr)) - ntype=1 - return - endif - endif - - if( iter.gt.0 ) then ! this code block implements an early stopping criterion -! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion - nd=ncheck-nclast - if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased - ncnt=0 ! reset counter - else - ncnt=ncnt+1 - endif -! write(*,*) iter,ncheck,nd,ncnt - if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then - nharderror=-1 - exit - endif - endif - nclast=ncheck - -! Send messages from bits to check nodes - do j=1,M - do i=1,nrw(j) - ibj=Nm(i,j) - toc(i,j)=zn(ibj) - do kk=1,ncw ! subtract off what the bit had received from the check - if( Mn(kk,ibj) .eq. j ) then - toc(i,j)=toc(i,j)-tov(kk,ibj) - endif - enddo - enddo - enddo - -! send messages from check nodes to variable nodes - do i=1,M - tanhtoc(1:5,i)=tanh(-toc(1:5,i)/2) - enddo - - do j=1,N - do i=1,ncw - ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j - Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) - call platanh(-Tmn,y) -! y=atanh(-Tmn) - tov(i,j)=2*y - enddo - enddo - - enddo ! bp iterations - -73 continue - do i=1,nosd - zn=zsave(:,i) -! call osd240_74(zn,Keff,apmask,norder,message74,cw,nharderror,dminosd) - call fastosd240_74(zn,Keff,apmask,norder,message74,cw,nharderror,dminosd) - if(nharderror.gt.0) then - hdec=0 - where(llr .ge. 0) hdec=1 - nxor=ieor(hdec,cw) - nharderror=sum(nxor) ! nharderror based on input llrs - dmin=sum(nxor*abs(llr)) - ntype=1+i - return - endif - enddo - - ntype=0 - nharderror=-1 - dminosd=0.0 - - return -end subroutine decode240_74 +subroutine decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharderror,dmin) +! +! A hybrid bp/osd decoder for the (240,74) code. +! +! maxosd<0: do bp only +! maxosd=0: do bp and then call osd once with channel llrs +! maxosd>1: do bp and then call osd maxosd times with saved bp outputs +! norder : osd decoding depth +! + integer, parameter:: N=240, K=74, M=N-K + integer*1 cw(N),apmask(N) + integer*1 nxor(N),hdec(N) + integer*1 message74(74),m74(74) + integer nrw(M),ncw + integer Nm(5,M) + integer Mn(3,N) ! 3 checks per bit + integer synd(M) + real tov(3,N) + real toc(5,M) + real tanhtoc(5,M) + real zn(N),zsum(N),zsave(N,3) + real llr(N) + real Tmn + + include "ldpc_240_74_parity.f90" + + maxiterations=30 + if(Keff.eq.50) maxiterations=1 + + nosd=0 + if(maxosd.gt.3) maxosd=3 + if(maxosd.eq.0) then ! osd with channel llrs + nosd=1 + zsave(:,1)=llr + elseif(maxosd.gt.0) then ! + nosd=maxosd + elseif(maxosd.lt.0) then ! just bp + nosd=0 + endif + + if(maxosd.eq.0) goto 73 + + toc=0 + tov=0 + tanhtoc=0 +! initialize messages to checks + do j=1,M + do i=1,nrw(j) + toc(i,j)=llr((Nm(i,j))) + enddo + enddo + + ncnt=0 + nclast=0 + zsum=0.0 + do iter=0,maxiterations +! Update bit log likelihood ratios (tov=0 in iteration 0). + do i=1,N + if( apmask(i) .ne. 1 ) then + zn(i)=llr(i)+sum(tov(1:ncw,i)) + else + zn(i)=llr(i) + endif + enddo + zsum=zsum+zn + if(iter.gt.0 .and. iter.le.maxosd) then + zsave(:,iter)=zsum + endif + +! Check to see if we have a codeword (check before we do any iteration). + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(1:nrw(i),i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 + enddo + if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it + m74=0 + m74(1:74)=cw(1:74) + call get_crc24(m74,74,nbadcrc) + if(nbadcrc.eq.0) then + message74=cw(1:74) + hdec=0 + where(llr .ge. 0) hdec=1 + nxor=ieor(hdec,cw) + nharderror=sum(nxor) + dmin=sum(nxor*abs(llr)) + ntype=1 + return + endif + endif + + if( iter.gt.0 ) then ! this code block implements an early stopping criterion +! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion + nd=ncheck-nclast + if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased + ncnt=0 ! reset counter + else + ncnt=ncnt+1 + endif +! write(*,*) iter,ncheck,nd,ncnt + if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then + nharderror=-1 + exit + endif + endif + nclast=ncheck + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw(j) + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,ncw ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then + toc(i,j)=toc(i,j)-tov(kk,ibj) + endif + enddo + enddo + enddo + +! send messages from check nodes to variable nodes + do i=1,M + tanhtoc(1:5,i)=tanh(-toc(1:5,i)/2) + enddo + + do j=1,N + do i=1,ncw + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) + call platanh(-Tmn,y) +! y=atanh(-Tmn) + tov(i,j)=2*y + enddo + enddo + + enddo ! bp iterations + +73 continue + do i=1,nosd + zn=zsave(:,i) +! call osd240_74(zn,Keff,apmask,norder,message74,cw,nharderror,dminosd) + call fastosd240_74(zn,Keff,apmask,norder,message74,cw,nharderror,dminosd) + if(nharderror.gt.0) then + hdec=0 + where(llr .ge. 0) hdec=1 + nxor=ieor(hdec,cw) + nharderror=sum(nxor) ! nharderror based on input llrs + dmin=sum(nxor*abs(llr)) + ntype=1+i + return + endif + enddo + + ntype=0 + nharderror=-1 + dminosd=0.0 + + return +end subroutine decode240_74 diff --git a/lib/fst4/encode240_101.f90 b/lib/fst4/encode240_101.f90 index 8c50ce1a..bd16b3ca 100755 --- a/lib/fst4/encode240_101.f90 +++ b/lib/fst4/encode240_101.f90 @@ -1,44 +1,44 @@ -subroutine encode240_101(message,codeword) - use, intrinsic :: iso_c_binding - use iso_c_binding, only: c_loc,c_size_t - use crc - - integer, parameter:: N=240, K=101, M=N-K - integer*1 codeword(N) - integer*1 gen(M,K) - integer*1 message(K) - integer*1 pchecks(M) - include "ldpc_240_101_generator.f90" - logical first - data first/.true./ - save first,gen - - if( first ) then ! fill the generator matrix - gen=0 - do i=1,M - do j=1,26 - read(g(i)(j:j),"(Z1)") istr - ibmax=4 - if(j.eq.26) ibmax=1 - do jj=1, ibmax - icol=(j-1)*4+jj - if( btest(istr,4-jj) ) gen(i,icol)=1 - enddo - enddo - enddo - first=.false. - endif - - do i=1,M - nsum=0 - do j=1,K - nsum=nsum+message(j)*gen(i,j) - enddo - pchecks(i)=mod(nsum,2) - enddo - - codeword(1:K)=message - codeword(K+1:N)=pchecks - - return -end subroutine encode240_101 +subroutine encode240_101(message,codeword) + use, intrinsic :: iso_c_binding + use iso_c_binding, only: c_loc,c_size_t + use crc + + integer, parameter:: N=240, K=101, M=N-K + integer*1 codeword(N) + integer*1 gen(M,K) + integer*1 message(K) + integer*1 pchecks(M) + include "ldpc_240_101_generator.f90" + logical first + data first/.true./ + save first,gen + + if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,26 + read(g(i)(j:j),"(Z1)") istr + ibmax=4 + if(j.eq.26) ibmax=1 + do jj=1, ibmax + icol=(j-1)*4+jj + if( btest(istr,4-jj) ) gen(i,icol)=1 + enddo + enddo + enddo + first=.false. + endif + + do i=1,M + nsum=0 + do j=1,K + nsum=nsum+message(j)*gen(i,j) + enddo + pchecks(i)=mod(nsum,2) + enddo + + codeword(1:K)=message + codeword(K+1:N)=pchecks + + return +end subroutine encode240_101 diff --git a/lib/fst4/encode240_74.f90 b/lib/fst4/encode240_74.f90 index 94170f27..45904140 100755 --- a/lib/fst4/encode240_74.f90 +++ b/lib/fst4/encode240_74.f90 @@ -1,44 +1,44 @@ -subroutine encode240_74(message,codeword) - use, intrinsic :: iso_c_binding - use iso_c_binding, only: c_loc,c_size_t - use crc - - integer, parameter:: N=240, K=74, M=N-K - integer*1 codeword(N) - integer*1 gen(M,K) - integer*1 message(K) - integer*1 pchecks(M) - include "ldpc_240_74_generator.f90" - logical first - data first/.true./ - save first,gen - - if( first ) then ! fill the generator matrix - gen=0 - do i=1,M - do j=1,19 - read(g(i)(j:j),"(Z1)") istr - ibmax=4 - if(j.eq.19) ibmax=2 - do jj=1, ibmax - icol=(j-1)*4+jj - if( btest(istr,4-jj) ) gen(i,icol)=1 - enddo - enddo - enddo - first=.false. - endif - - do i=1,M - nsum=0 - do j=1,K - nsum=nsum+message(j)*gen(i,j) - enddo - pchecks(i)=mod(nsum,2) - enddo - - codeword(1:K)=message - codeword(K+1:N)=pchecks - - return -end subroutine encode240_74 +subroutine encode240_74(message,codeword) + use, intrinsic :: iso_c_binding + use iso_c_binding, only: c_loc,c_size_t + use crc + + integer, parameter:: N=240, K=74, M=N-K + integer*1 codeword(N) + integer*1 gen(M,K) + integer*1 message(K) + integer*1 pchecks(M) + include "ldpc_240_74_generator.f90" + logical first + data first/.true./ + save first,gen + + if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,19 + read(g(i)(j:j),"(Z1)") istr + ibmax=4 + if(j.eq.19) ibmax=2 + do jj=1, ibmax + icol=(j-1)*4+jj + if( btest(istr,4-jj) ) gen(i,icol)=1 + enddo + enddo + enddo + first=.false. + endif + + do i=1,M + nsum=0 + do j=1,K + nsum=nsum+message(j)*gen(i,j) + enddo + pchecks(i)=mod(nsum,2) + enddo + + codeword(1:K)=message + codeword(K+1:N)=pchecks + + return +end subroutine encode240_74 diff --git a/lib/fst4/fastosd240_74.f90 b/lib/fst4/fastosd240_74.f90 index b9d87780..3e812e0f 100755 --- a/lib/fst4/fastosd240_74.f90 +++ b/lib/fst4/fastosd240_74.f90 @@ -1,289 +1,289 @@ -subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin) -! -! An ordered-statistics decoder for the (240,74) code. -! Message payload is 50 bits. Any or all of a 24-bit CRC can be -! used for detecting incorrect codewords. The remaining CRC bits are -! cascaded with the LDPC code for the purpose of improving the -! distance spectrum of the code. -! -! If p1 (0.le.p1.le.24) is the number of CRC24 bits that are -! to be used for bad codeword detection, then the argument k should -! be set to 77+p1. -! -! Valid values for k are in the range [50,74]. -! - character*24 c24 - integer, parameter:: N=240 - integer*1 apmask(N),apmaskr(N) - integer*1, allocatable, save :: gen(:,:) - integer*1, allocatable :: genmrb(:,:),g2(:,:) - integer*1, allocatable :: temp(:),temprow(:),m0(:),me(:),mi(:) - integer indices(N),indices2(N),nxor(N) - integer*1 cw(N),ce(N),c0(N),hdec(N) - integer*1, allocatable :: decoded(:) - integer*1 message74(74) - integer*1, allocatable :: sp(:) - integer indx(N),ksave - real llr(N),rx(N),absrx(N) - - logical first - data first/.true./,ksave/64/ - save first,ksave - - allocate( genmrb(k,N), g2(N,k) ) - allocate( temp(k), temprow(n), m0(k), me(k), mi(k) ) - allocate( decoded(k) ) - - if( first .or. k.ne.ksave) then ! fill the generator matrix -! -! Create generator matrix for partial CRC cascaded with LDPC code. -! -! Let p2=74-k and p1+p2=24. -! -! The last p2 bits of the CRC24 are cascaded with the LDPC code. -! -! The first p1=k-50 CRC24 bits will be used for error detection. -! - if( allocated(gen) ) deallocate(gen) - allocate( gen(k,N) ) - gen=0 - do i=1,k - message74=0 - message74(i)=1 - if(i.le.50) then - call get_crc24(message74,74,ncrc24) - write(c24,'(b24.24)') ncrc24 - read(c24,'(24i1)') message74(51:74) - message74(51:k)=0 - endif - call encode240_74(message74,cw) - gen(i,:)=cw - enddo - - first=.false. - ksave=k - endif - -! Use best k elements from the sorted list for the first basis. For the 2nd basis replace -! the nswap lowest quality symbols with the best nswap elements from the parity symbols. - nswap=20 - - do ibasis=1,2 - rx=llr - apmaskr=apmask - -! Hard decisions on the received word. - hdec=0 - where(rx .ge. 0) hdec=1 - -! Use magnitude of received symbols as a measure of reliability. - absrx=abs(llr) - call indexx(absrx,N,indx) - -! Re-order the columns of the generator matrix in order of decreasing reliability. - do i=1,N - genmrb(1:k,i)=gen(1:k,indx(N+1-i)) - indices(i)=indx(N+1-i) - enddo - - if(ibasis.eq.2) then - do i=k-nswap+1,k - temp(1:k)=genmrb(1:k,i) - genmrb(1:k,i)=genmrb(1:k,i+nswap) - genmrb(1:k,i+nswap)=temp(1:k) - itmp=indices(i) - indices(i)=indices(i+nswap) - indices(i+nswap)=itmp - enddo - endif - -! Do gaussian elimination to create a generator matrix with the most reliable -! received bits in positions 1:k in order of decreasing reliability (more or less). - - icol=1 - indices2=0 - nskipped=0 - do id=1,k - iflag=0 - do while(iflag.eq.0) - if(genmrb(id,icol).ne.1) then - do j=id+1,k - if(genmrb(j,icol).eq.1) then - temprow=genmrb(id,:) - genmrb(id,:)=genmrb(j,:) - genmrb(j,:)=temprow - iflag=1 - endif - enddo - if(iflag.eq.0) then ! skip this column - nskipped=nskipped+1 - indices2(k+nskipped)=icol ! put icol where skipped columns go - icol=icol+1 ! look at the next column - endif - else - iflag=1 - endif - enddo - indices2(id)=icol - do j=1,k - if(id.ne.j .and. genmrb(j,icol).eq.1) then - genmrb(j,:)=ieor(genmrb(id,:),genmrb(j,:)) - endif - enddo - icol=icol+1 - enddo - do i=k+nskipped+1,240 - indices2(i)=i - enddo - genmrb(1:k,:)=genmrb(1:k,indices2) - indices=indices(indices2) - -!************************************ - g2=transpose(genmrb) - -! The hard decisions for the k MRB bits define the order 0 message, m0. -! Encode m0 using the modified generator matrix to find the "order 0" codeword. -! Flip various combinations of bits in m0 and re-encode to generate a list of -! codewords. Return the member of the list that has the smallest Euclidean -! distance to the received word. - - hdec=hdec(indices) ! hard decisions from received symbols - m0=hdec(1:k) ! zero'th order message - absrx=abs(llr) - absrx=absrx(indices) - rx=rx(indices) - apmaskr=apmaskr(indices) - - call mrbencode74(m0,c0,g2,N,k) - nxor=ieor(c0,hdec) - nhardmin=sum(nxor) - dmin=sum(nxor*absrx) - np=32 - if(ibasis.eq.1) allocate(sp(np)) - - cw=c0 - ntotal=0 - nrejected=0 - xlambda=0.0 - - if(ndeep.eq.0) goto 998 ! norder=0 - if(ndeep.gt.4) ndeep=4 - if( ndeep.eq. 1) then - nord=1 - xlambda=0.0 - nsyndmax=np - elseif(ndeep.eq.2) then - nord=2 - xlambda=0.0 - nsyndmax=np - elseif(ndeep.eq.3) then - nord=3 - xlambda=4.0 - nsyndmax=11 - elseif(ndeep.eq.4) then - nord=4 - xlambda=3.4 - nsyndmax=12 - endif - - s1=sum(absrx(1:k)) - s2=sum(absrx(k+1:N)) - rho=s1/(s1+xlambda*s2) - rhodmin=rho*dmin - do iorder=1,nord -!beta=0.0 -!if(iorder.ge.3) beta=0.4 -!spnc_order=sum(absrx(k-iorder+1:k))+beta*(N-k) -!if(dmin.lt.spnc_order) cycle - mi(1:k-iorder)=0 - mi(k-iorder+1:k)=1 - iflag=k-iorder+1 - do while(iflag .ge.0) - ntotal=ntotal+1 - me=ieor(m0,mi) - d1=sum(mi(1:k)*absrx(1:k)) - if(d1.gt.rhodmin) exit - call partial_syndrome(me,sp,np,g2,N,K) - nwhsp=sum(ieor(sp(1:np),hdec(k:k+np-1))) - if(nwhsp.le.nsyndmax) then - call mrbencode74(me,ce,g2,N,k) - nxor=ieor(ce,hdec) - dd=sum(nxor*absrx(1:N)) - if( dd .lt. dmin ) then - dmin=dd - rhodmin=rho*dmin - cw=ce - nhardmin=sum(nxor) - nwhspmin=nwhsp - endif - endif -! Get the next test error pattern, iflag will go negative -! when the last pattern with weight iorder has been generated. - call nextpat74(mi,k,iorder,iflag) - enddo - enddo -998 continue -! Re-order the codeword to [message bits][parity bits] format. - cw(indices)=cw - hdec(indices)=hdec - message74=cw(1:74) - call get_crc24(message74,74,nbadcrc) - if(nbadcrc.eq.0) exit - nhardmin=-nhardmin - enddo ! basis loop - return -end subroutine fastosd240_74 - -subroutine mrbencode74(me,codeword,g2,N,K) - integer*1 me(K),codeword(N),g2(N,K) -! fast encoding for low-weight test patterns - codeword=0 - do i=1,K - if( me(i) .eq. 1 ) then - codeword=ieor(codeword,g2(1:N,i)) - endif - enddo - return -end subroutine mrbencode74 - -subroutine partial_syndrome(me,sp,np,g2,N,K) - integer*1 me(K),sp(np),g2(N,K) -! compute partial syndrome - sp=0 - do i=1,K - if( me(i) .eq. 1 ) then - sp=ieor(sp,g2(K:K+np-1,i)) - endif - enddo - return -end subroutine partial_syndrome - -subroutine nextpat74(mi,k,iorder,iflag) - integer*1 mi(k),ms(k) -! generate the next test error pattern - ind=-1 - do i=1,k-1 - if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i - enddo - if( ind .lt. 0 ) then ! no more patterns of this order - iflag=ind - return - endif - ms=0 - ms(1:ind-1)=mi(1:ind-1) - ms(ind)=1 - ms(ind+1)=0 - if( ind+1 .lt. k ) then - nz=iorder-sum(ms) - ms(k-nz+1:k)=1 - endif - mi=ms - do i=1,k ! iflag will point to the lowest-index 1 in mi - if(mi(i).eq.1) then - iflag=i - exit - endif - enddo - return -end subroutine nextpat74 - +subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin) +! +! An ordered-statistics decoder for the (240,74) code. +! Message payload is 50 bits. Any or all of a 24-bit CRC can be +! used for detecting incorrect codewords. The remaining CRC bits are +! cascaded with the LDPC code for the purpose of improving the +! distance spectrum of the code. +! +! If p1 (0.le.p1.le.24) is the number of CRC24 bits that are +! to be used for bad codeword detection, then the argument k should +! be set to 77+p1. +! +! Valid values for k are in the range [50,74]. +! + character*24 c24 + integer, parameter:: N=240 + integer*1 apmask(N),apmaskr(N) + integer*1, allocatable, save :: gen(:,:) + integer*1, allocatable :: genmrb(:,:),g2(:,:) + integer*1, allocatable :: temp(:),temprow(:),m0(:),me(:),mi(:) + integer indices(N),indices2(N),nxor(N) + integer*1 cw(N),ce(N),c0(N),hdec(N) + integer*1, allocatable :: decoded(:) + integer*1 message74(74) + integer*1, allocatable :: sp(:) + integer indx(N),ksave + real llr(N),rx(N),absrx(N) + + logical first + data first/.true./,ksave/64/ + save first,ksave + + allocate( genmrb(k,N), g2(N,k) ) + allocate( temp(k), temprow(n), m0(k), me(k), mi(k) ) + allocate( decoded(k) ) + + if( first .or. k.ne.ksave) then ! fill the generator matrix +! +! Create generator matrix for partial CRC cascaded with LDPC code. +! +! Let p2=74-k and p1+p2=24. +! +! The last p2 bits of the CRC24 are cascaded with the LDPC code. +! +! The first p1=k-50 CRC24 bits will be used for error detection. +! + if( allocated(gen) ) deallocate(gen) + allocate( gen(k,N) ) + gen=0 + do i=1,k + message74=0 + message74(i)=1 + if(i.le.50) then + call get_crc24(message74,74,ncrc24) + write(c24,'(b24.24)') ncrc24 + read(c24,'(24i1)') message74(51:74) + message74(51:k)=0 + endif + call encode240_74(message74,cw) + gen(i,:)=cw + enddo + + first=.false. + ksave=k + endif + +! Use best k elements from the sorted list for the first basis. For the 2nd basis replace +! the nswap lowest quality symbols with the best nswap elements from the parity symbols. + nswap=20 + + do ibasis=1,2 + rx=llr + apmaskr=apmask + +! Hard decisions on the received word. + hdec=0 + where(rx .ge. 0) hdec=1 + +! Use magnitude of received symbols as a measure of reliability. + absrx=abs(llr) + call indexx(absrx,N,indx) + +! Re-order the columns of the generator matrix in order of decreasing reliability. + do i=1,N + genmrb(1:k,i)=gen(1:k,indx(N+1-i)) + indices(i)=indx(N+1-i) + enddo + + if(ibasis.eq.2) then + do i=k-nswap+1,k + temp(1:k)=genmrb(1:k,i) + genmrb(1:k,i)=genmrb(1:k,i+nswap) + genmrb(1:k,i+nswap)=temp(1:k) + itmp=indices(i) + indices(i)=indices(i+nswap) + indices(i+nswap)=itmp + enddo + endif + +! Do gaussian elimination to create a generator matrix with the most reliable +! received bits in positions 1:k in order of decreasing reliability (more or less). + + icol=1 + indices2=0 + nskipped=0 + do id=1,k + iflag=0 + do while(iflag.eq.0) + if(genmrb(id,icol).ne.1) then + do j=id+1,k + if(genmrb(j,icol).eq.1) then + temprow=genmrb(id,:) + genmrb(id,:)=genmrb(j,:) + genmrb(j,:)=temprow + iflag=1 + endif + enddo + if(iflag.eq.0) then ! skip this column + nskipped=nskipped+1 + indices2(k+nskipped)=icol ! put icol where skipped columns go + icol=icol+1 ! look at the next column + endif + else + iflag=1 + endif + enddo + indices2(id)=icol + do j=1,k + if(id.ne.j .and. genmrb(j,icol).eq.1) then + genmrb(j,:)=ieor(genmrb(id,:),genmrb(j,:)) + endif + enddo + icol=icol+1 + enddo + do i=k+nskipped+1,240 + indices2(i)=i + enddo + genmrb(1:k,:)=genmrb(1:k,indices2) + indices=indices(indices2) + +!************************************ + g2=transpose(genmrb) + +! The hard decisions for the k MRB bits define the order 0 message, m0. +! Encode m0 using the modified generator matrix to find the "order 0" codeword. +! Flip various combinations of bits in m0 and re-encode to generate a list of +! codewords. Return the member of the list that has the smallest Euclidean +! distance to the received word. + + hdec=hdec(indices) ! hard decisions from received symbols + m0=hdec(1:k) ! zero'th order message + absrx=abs(llr) + absrx=absrx(indices) + rx=rx(indices) + apmaskr=apmaskr(indices) + + call mrbencode74(m0,c0,g2,N,k) + nxor=ieor(c0,hdec) + nhardmin=sum(nxor) + dmin=sum(nxor*absrx) + np=32 + if(ibasis.eq.1) allocate(sp(np)) + + cw=c0 + ntotal=0 + nrejected=0 + xlambda=0.0 + + if(ndeep.eq.0) goto 998 ! norder=0 + if(ndeep.gt.4) ndeep=4 + if( ndeep.eq. 1) then + nord=1 + xlambda=0.0 + nsyndmax=np + elseif(ndeep.eq.2) then + nord=2 + xlambda=0.0 + nsyndmax=np + elseif(ndeep.eq.3) then + nord=3 + xlambda=4.0 + nsyndmax=11 + elseif(ndeep.eq.4) then + nord=4 + xlambda=3.4 + nsyndmax=12 + endif + + s1=sum(absrx(1:k)) + s2=sum(absrx(k+1:N)) + rho=s1/(s1+xlambda*s2) + rhodmin=rho*dmin + do iorder=1,nord +!beta=0.0 +!if(iorder.ge.3) beta=0.4 +!spnc_order=sum(absrx(k-iorder+1:k))+beta*(N-k) +!if(dmin.lt.spnc_order) cycle + mi(1:k-iorder)=0 + mi(k-iorder+1:k)=1 + iflag=k-iorder+1 + do while(iflag .ge.0) + ntotal=ntotal+1 + me=ieor(m0,mi) + d1=sum(mi(1:k)*absrx(1:k)) + if(d1.gt.rhodmin) exit + call partial_syndrome(me,sp,np,g2,N,K) + nwhsp=sum(ieor(sp(1:np),hdec(k:k+np-1))) + if(nwhsp.le.nsyndmax) then + call mrbencode74(me,ce,g2,N,k) + nxor=ieor(ce,hdec) + dd=sum(nxor*absrx(1:N)) + if( dd .lt. dmin ) then + dmin=dd + rhodmin=rho*dmin + cw=ce + nhardmin=sum(nxor) + nwhspmin=nwhsp + endif + endif +! Get the next test error pattern, iflag will go negative +! when the last pattern with weight iorder has been generated. + call nextpat74(mi,k,iorder,iflag) + enddo + enddo +998 continue +! Re-order the codeword to [message bits][parity bits] format. + cw(indices)=cw + hdec(indices)=hdec + message74=cw(1:74) + call get_crc24(message74,74,nbadcrc) + if(nbadcrc.eq.0) exit + nhardmin=-nhardmin + enddo ! basis loop + return +end subroutine fastosd240_74 + +subroutine mrbencode74(me,codeword,g2,N,K) + integer*1 me(K),codeword(N),g2(N,K) +! fast encoding for low-weight test patterns + codeword=0 + do i=1,K + if( me(i) .eq. 1 ) then + codeword=ieor(codeword,g2(1:N,i)) + endif + enddo + return +end subroutine mrbencode74 + +subroutine partial_syndrome(me,sp,np,g2,N,K) + integer*1 me(K),sp(np),g2(N,K) +! compute partial syndrome + sp=0 + do i=1,K + if( me(i) .eq. 1 ) then + sp=ieor(sp,g2(K:K+np-1,i)) + endif + enddo + return +end subroutine partial_syndrome + +subroutine nextpat74(mi,k,iorder,iflag) + integer*1 mi(k),ms(k) +! generate the next test error pattern + ind=-1 + do i=1,k-1 + if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i + enddo + if( ind .lt. 0 ) then ! no more patterns of this order + iflag=ind + return + endif + ms=0 + ms(1:ind-1)=mi(1:ind-1) + ms(ind)=1 + ms(ind+1)=0 + if( ind+1 .lt. k ) then + nz=iorder-sum(ms) + ms(k-nz+1:k)=1 + endif + mi=ms + do i=1,k ! iflag will point to the lowest-index 1 in mi + if(mi(i).eq.1) then + iflag=i + exit + endif + enddo + return +end subroutine nextpat74 + diff --git a/lib/fst4/fst4sim.f90 b/lib/fst4/fst4sim.f90 index 4bb85f42..936c4b6f 100755 --- a/lib/fst4/fst4sim.f90 +++ b/lib/fst4/fst4sim.f90 @@ -1,159 +1,159 @@ -program fst4sim - -! Generate simulated signals for experimental slow FT4 mode - - use wavhdr - use packjt77 - include 'fst4_params.f90' !Set various constants - type(hdr) h !Header for .wav file - logical*1 wspr_hint - character arg*12,fname*17 - character msg37*37,msgsent37*37,c77*77 - complex, allocatable :: c0(:) - complex, allocatable :: c(:) - real, allocatable :: wave(:) - integer hmod - integer itone(NN) - integer*1 msgbits(101) - integer*2, allocatable :: iwave(:) !Generated full-length waveform - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.9) then - print*,'Need 9 arguments, got ',nargs - print*,'Usage: fst4sim "message" TRsec f0 DT fdop del nfiles snr W' - print*,'Examples: fst4sim "K1JT K9AN EN50" 60 1500 0.0 0.1 1.0 10 -15 F' - print*,'W (T or F) argument is hint to encoder to use WSPR message when there is abiguity' - go to 999 - endif - call getarg(1,msg37) !Message to be transmitted - call getarg(2,arg) - read(arg,*) nsec !TR sequence length, seconds - call getarg(3,arg) - read(arg,*) f00 !Frequency (only used for single-signal) - call getarg(4,arg) - read(arg,*) xdt !Time offset from nominal (s) - call getarg(5,arg) - read(arg,*) fspread !Watterson frequency spread (Hz) - call getarg(6,arg) - read(arg,*) delay !Watterson delay (ms) - call getarg(7,arg) - read(arg,*) nfiles !Number of files - call getarg(8,arg) - read(arg,*) snrdb !SNR_2500 - call getarg(9,arg) - read(arg,*) wspr_hint !0:break ties as 77-bit 1:break ties as 50-bit - - nfiles=abs(nfiles) - twopi=8.0*atan(1.0) - fs=12000.0 !Sample rate (Hz) - dt=1.0/fs !Sample interval (s) - nsps=0 - if(nsec.eq.15) nsps=720 - if(nsec.eq.30) nsps=1680 - if(nsec.eq.60) nsps=3888 - if(nsec.eq.120) nsps=8200 - if(nsec.eq.300) nsps=21504 - if(nsec.eq.900) nsps=66560 - if(nsec.eq.1800) nsps=134400 - if(nsps.eq.0) then - print*,'Invalid TR sequence length.' - go to 999 - endif - baud=12000.0/nsps !Keying rate (baud) - nmax=nsec*12000 - nz=nsps*NN - txt=nz*dt !Transmission length (s) - tt=nsps*dt !Duration of symbols (s) - nwave=max(nmax,(NN+2)*nsps) - allocate( c0(0:nwave-1) ) - allocate( c(0:nwave-1) ) - allocate( wave(nwave) ) - allocate( iwave(nmax) ) - - bandwidth_ratio=2500.0/(fs/2.0) - sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) - if(snrdb.gt.90.0) sig=1.0 - - if(wspr_hint) then - i3=0 - n3=6 - else - i3=-1 - n3=-1 - endif - call pack77(msg37,i3,n3,c77) - if(i3.eq.0.and.n3.eq.6) iwspr=1 - call genfst4(msg37,0,msgsent37,msgbits,itone,iwspr) - write(*,*) - write(*,'(a9,a37,a3,L2,a7,i2)') 'Message: ',msgsent37,'W:',wspr_hint,' iwspr:',iwspr - write(*,1000) f00,xdt,txt,snrdb -1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1) - write(*,*) - if(i3.eq.1) then - write(*,*) ' mycall hiscall hisgrid' - write(*,'(28i1,1x,i1,1x,28i1,1x,i1,1x,i1,1x,15i1,1x,3i1)') msgbits(1:77) - elseif(i3.eq.0 .and. n3.eq.6) then - write(*,'(a15,37x,a5)') '50-bit message','CRC24' - write(*,'(50i1,1x,24i1)') msgbits(1:50),msgbits(51:74) - write(*,'(a50)') '01234567890123456789012345678901234567890123456789' - else - write(*,'(a14)') 'Message bits: ' - write(*,'(77i1,1x,24i1)') msgbits - endif - write(*,*) - write(*,'(a17)') 'Channel symbols: ' - write(*,'(10i1)') itone - write(*,*) - -! call sgran() - - fsample=12000.0 - hmod=1 - icmplx=1 - f0=f00+1.5*hmod*baud - call gen_fst4wave(itone,NN,nsps,nwave,fsample,hmod,f0,icmplx,c0,wave) - k=nint((xdt+1.0)/dt) - if(nsec.eq.15) k=nint((xdt+0.5)/dt) - c0=cshift(c0,-k) - if(k.gt.0) c0(0:k-1)=0.0 - if(k.lt.0) c0(nmax+k:nmax-1)=0.0 - - do ifile=1,nfiles - c=c0 - if(fspread.gt.0.0 .or. delay.ne.0.0) call watterson(c,nwave,NZ,fs,delay,fspread) - if(fspread.lt.0.0) call lorentzian_fading(c,nwave,fs,-fspread) - c=sig*c - wave=aimag(c) - if(snrdb.lt.90) then - do i=1,nmax !Add gaussian noise at specified SNR - xnoise=gran() - wave(i)=wave(i) + xnoise - enddo - endif - gain=100.0 - if(snrdb.lt.90.0) then - wave=gain*wave - else - datpk=maxval(abs(wave)) - fac=32766.9/datpk - wave=fac*wave - endif - if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." - iwave=nint(wave(:size(iwave))) - h=default_header(12000,nmax) - if(nmax/12000.le.30) then - write(fname,1102) ifile -1102 format('000000_',i6.6,'.wav') - else - write(fname,1104) ifile -1104 format('000000_',i4.4,'.wav') - endif - open(10,file=trim(fname),status='unknown',access='stream') - write(10) h,iwave !Save to *.wav file - close(10) - write(*,1110) ifile,xdt,f00,snrdb,fname -1110 format(i4,f7.2,f8.2,f7.1,2x,a17) - enddo - -999 end program fst4sim +program fst4sim + +! Generate simulated signals for experimental slow FT4 mode + + use wavhdr + use packjt77 + include 'fst4_params.f90' !Set various constants + type(hdr) h !Header for .wav file + logical*1 wspr_hint + character arg*12,fname*17 + character msg37*37,msgsent37*37,c77*77 + complex, allocatable :: c0(:) + complex, allocatable :: c(:) + real, allocatable :: wave(:) + integer hmod + integer itone(NN) + integer*1 msgbits(101) + integer*2, allocatable :: iwave(:) !Generated full-length waveform + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.9) then + print*,'Need 9 arguments, got ',nargs + print*,'Usage: fst4sim "message" TRsec f0 DT fdop del nfiles snr W' + print*,'Examples: fst4sim "K1JT K9AN EN50" 60 1500 0.0 0.1 1.0 10 -15 F' + print*,'W (T or F) argument is hint to encoder to use WSPR message when there is abiguity' + go to 999 + endif + call getarg(1,msg37) !Message to be transmitted + call getarg(2,arg) + read(arg,*) nsec !TR sequence length, seconds + call getarg(3,arg) + read(arg,*) f00 !Frequency (only used for single-signal) + call getarg(4,arg) + read(arg,*) xdt !Time offset from nominal (s) + call getarg(5,arg) + read(arg,*) fspread !Watterson frequency spread (Hz) + call getarg(6,arg) + read(arg,*) delay !Watterson delay (ms) + call getarg(7,arg) + read(arg,*) nfiles !Number of files + call getarg(8,arg) + read(arg,*) snrdb !SNR_2500 + call getarg(9,arg) + read(arg,*) wspr_hint !0:break ties as 77-bit 1:break ties as 50-bit + + nfiles=abs(nfiles) + twopi=8.0*atan(1.0) + fs=12000.0 !Sample rate (Hz) + dt=1.0/fs !Sample interval (s) + nsps=0 + if(nsec.eq.15) nsps=720 + if(nsec.eq.30) nsps=1680 + if(nsec.eq.60) nsps=3888 + if(nsec.eq.120) nsps=8200 + if(nsec.eq.300) nsps=21504 + if(nsec.eq.900) nsps=66560 + if(nsec.eq.1800) nsps=134400 + if(nsps.eq.0) then + print*,'Invalid TR sequence length.' + go to 999 + endif + baud=12000.0/nsps !Keying rate (baud) + nmax=nsec*12000 + nz=nsps*NN + txt=nz*dt !Transmission length (s) + tt=nsps*dt !Duration of symbols (s) + nwave=max(nmax,(NN+2)*nsps) + allocate( c0(0:nwave-1) ) + allocate( c(0:nwave-1) ) + allocate( wave(nwave) ) + allocate( iwave(nmax) ) + + bandwidth_ratio=2500.0/(fs/2.0) + sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + + if(wspr_hint) then + i3=0 + n3=6 + else + i3=-1 + n3=-1 + endif + call pack77(msg37,i3,n3,c77) + if(i3.eq.0.and.n3.eq.6) iwspr=1 + call genfst4(msg37,0,msgsent37,msgbits,itone,iwspr) + write(*,*) + write(*,'(a9,a37,a3,L2,a7,i2)') 'Message: ',msgsent37,'W:',wspr_hint,' iwspr:',iwspr + write(*,1000) f00,xdt,txt,snrdb +1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1) + write(*,*) + if(i3.eq.1) then + write(*,*) ' mycall hiscall hisgrid' + write(*,'(28i1,1x,i1,1x,28i1,1x,i1,1x,i1,1x,15i1,1x,3i1)') msgbits(1:77) + elseif(i3.eq.0 .and. n3.eq.6) then + write(*,'(a15,37x,a5)') '50-bit message','CRC24' + write(*,'(50i1,1x,24i1)') msgbits(1:50),msgbits(51:74) + write(*,'(a50)') '01234567890123456789012345678901234567890123456789' + else + write(*,'(a14)') 'Message bits: ' + write(*,'(77i1,1x,24i1)') msgbits + endif + write(*,*) + write(*,'(a17)') 'Channel symbols: ' + write(*,'(10i1)') itone + write(*,*) + +! call sgran() + + fsample=12000.0 + hmod=1 + icmplx=1 + f0=f00+1.5*hmod*baud + call gen_fst4wave(itone,NN,nsps,nwave,fsample,hmod,f0,icmplx,c0,wave) + k=nint((xdt+1.0)/dt) + if(nsec.eq.15) k=nint((xdt+0.5)/dt) + c0=cshift(c0,-k) + if(k.gt.0) c0(0:k-1)=0.0 + if(k.lt.0) c0(nmax+k:nmax-1)=0.0 + + do ifile=1,nfiles + c=c0 + if(fspread.gt.0.0 .or. delay.ne.0.0) call watterson(c,nwave,NZ,fs,delay,fspread) + if(fspread.lt.0.0) call lorentzian_fading(c,nwave,fs,-fspread) + c=sig*c + wave=aimag(c) + if(snrdb.lt.90) then + do i=1,nmax !Add gaussian noise at specified SNR + xnoise=gran() + wave(i)=wave(i) + xnoise + enddo + endif + gain=100.0 + if(snrdb.lt.90.0) then + wave=gain*wave + else + datpk=maxval(abs(wave)) + fac=32766.9/datpk + wave=fac*wave + endif + if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." + iwave=nint(wave(:size(iwave))) + h=default_header(12000,nmax) + if(nmax/12000.le.30) then + write(fname,1102) ifile +1102 format('000000_',i6.6,'.wav') + else + write(fname,1104) ifile +1104 format('000000_',i4.4,'.wav') + endif + open(10,file=trim(fname),status='unknown',access='stream') + write(10) h,iwave !Save to *.wav file + close(10) + write(*,1110) ifile,xdt,f00,snrdb,fname +1110 format(i4,f7.2,f8.2,f7.1,2x,a17) + enddo + +999 end program fst4sim diff --git a/lib/fst4/gen_fst4wave.f90 b/lib/fst4/gen_fst4wave.f90 index 039b82bc..74a9b34c 100755 --- a/lib/fst4/gen_fst4wave.f90 +++ b/lib/fst4/gen_fst4wave.f90 @@ -1,93 +1,93 @@ -subroutine gen_fst4wave(itone,nsym,nsps,nwave,fsample,hmod,f0, & - icmplx,cwave,wave) - - use prog_args - parameter(NTAB=65536) - real wave(nwave) - complex cwave(nwave),ctab(0:NTAB-1) - character(len=1) :: cvalue - real, allocatable, save :: pulse(:) - real, allocatable :: dphi(:) - integer hmod - integer itone(nsym) - logical first, lshape - data first/.true./ - data nsps0/-99/ - data lshape/.true./ - save first,twopi,dt,tsym,nsps0,ctab,lshape - - if(first) then - twopi=8.0*atan(1.0) - do i=0,NTAB-1 - phi=i*twopi/NTAB - ctab(i)=cmplx(cos(phi),sin(phi)) - enddo - call get_environment_variable("FST4_NOSHAPING",cvalue,nlen) - if(nlen.eq.1 .and. cvalue.eq."1") lshape=.false. - endif - - if(first.or.nsps.ne.nsps0) then - if(allocated(pulse)) deallocate(pulse) - allocate(pulse(1:3*nsps)) - dt=1.0/fsample - tsym=nsps/fsample -! Compute the smoothed frequency-deviation pulse - do i=1,3*nsps - tt=(i-1.5*nsps)/real(nsps) - pulse(i)=gfsk_pulse(2.0,tt) - enddo - first=.false. - nsps0=nsps - endif - -! Compute the smoothed frequency waveform. -! Length = (nsym+2)*nsps samples, zero-padded - allocate( dphi(0:(nsym+2)*nsps-1) ) - dphi_peak=twopi*hmod/real(nsps) - dphi=0.0 - do j=1,nsym - ib=(j-1)*nsps - ie=ib+3*nsps-1 - dphi(ib:ie) = dphi(ib:ie) + dphi_peak*pulse(1:3*nsps)*itone(j) - enddo - -! Calculate and insert the audio waveform - phi=0.0 - dphi = dphi + twopi*(f0-1.5*hmod/tsym)*dt !Shift frequency up by f0 - if(icmplx.eq.0) wave=0. - if(icmplx.eq.1) cwave=0. - k=0 - do j=nsps,(nsym+1)*nsps-1 - k=k+1 - i=phi*float(NTAB)/twopi - i=iand(i,NTAB-1) - if(icmplx.eq.0) then - wave(k)=aimag(ctab(i)) - else - cwave(k)=ctab(i) - endif - phi=phi+dphi(j) - if(phi.gt.twopi) phi=phi-twopi - enddo - -! Compute the ramp-up and ramp-down symbols - if(icmplx.eq.0) then - if(lshape) then - wave(1:nsps/4)=wave(1:nsps/4) * & - (1.0-cos(twopi*(/(i,i=0,nsps/4-1)/)/real(nsps/2)))/2.0 - k1=(nsym-1)*nsps+3*nsps/4+1 - wave(k1:k1+nsps/4)=wave(k1:k1+nsps/4) * & - (1.0+cos(twopi*(/(i,i=0,nsps/4)/)/real(nsps/2)))/2.0 - endif - else - if(lshape) then - cwave(1:nsps/4)=cwave(1:nsps/4) * & - (1.0-cos(twopi*(/(i,i=0,nsps/4-1)/)/real(nsps/2)))/2.0 - k1=(nsym-1)*nsps+3*nsps/4+1 - cwave(k1:k1+nsps/4)=cwave(k1:k1+nsps/4) * & - (1.0+cos(twopi*(/(i,i=0,nsps/4)/)/real(nsps/2)))/2.0 - endif - endif - - return -end subroutine gen_fst4wave +subroutine gen_fst4wave(itone,nsym,nsps,nwave,fsample,hmod,f0, & + icmplx,cwave,wave) + + use prog_args + parameter(NTAB=65536) + real wave(nwave) + complex cwave(nwave),ctab(0:NTAB-1) + character(len=1) :: cvalue + real, allocatable, save :: pulse(:) + real, allocatable :: dphi(:) + integer hmod + integer itone(nsym) + logical first, lshape + data first/.true./ + data nsps0/-99/ + data lshape/.true./ + save first,twopi,dt,tsym,nsps0,ctab,lshape + + if(first) then + twopi=8.0*atan(1.0) + do i=0,NTAB-1 + phi=i*twopi/NTAB + ctab(i)=cmplx(cos(phi),sin(phi)) + enddo + call get_environment_variable("FST4_NOSHAPING",cvalue,nlen) + if(nlen.eq.1 .and. cvalue.eq."1") lshape=.false. + endif + + if(first.or.nsps.ne.nsps0) then + if(allocated(pulse)) deallocate(pulse) + allocate(pulse(1:3*nsps)) + dt=1.0/fsample + tsym=nsps/fsample +! Compute the smoothed frequency-deviation pulse + do i=1,3*nsps + tt=(i-1.5*nsps)/real(nsps) + pulse(i)=gfsk_pulse(2.0,tt) + enddo + first=.false. + nsps0=nsps + endif + +! Compute the smoothed frequency waveform. +! Length = (nsym+2)*nsps samples, zero-padded + allocate( dphi(0:(nsym+2)*nsps-1) ) + dphi_peak=twopi*hmod/real(nsps) + dphi=0.0 + do j=1,nsym + ib=(j-1)*nsps + ie=ib+3*nsps-1 + dphi(ib:ie) = dphi(ib:ie) + dphi_peak*pulse(1:3*nsps)*itone(j) + enddo + +! Calculate and insert the audio waveform + phi=0.0 + dphi = dphi + twopi*(f0-1.5*hmod/tsym)*dt !Shift frequency up by f0 + if(icmplx.eq.0) wave=0. + if(icmplx.eq.1) cwave=0. + k=0 + do j=nsps,(nsym+1)*nsps-1 + k=k+1 + i=phi*float(NTAB)/twopi + i=iand(i,NTAB-1) + if(icmplx.eq.0) then + wave(k)=aimag(ctab(i)) + else + cwave(k)=ctab(i) + endif + phi=phi+dphi(j) + if(phi.gt.twopi) phi=phi-twopi + enddo + +! Compute the ramp-up and ramp-down symbols + if(icmplx.eq.0) then + if(lshape) then + wave(1:nsps/4)=wave(1:nsps/4) * & + (1.0-cos(twopi*(/(i,i=0,nsps/4-1)/)/real(nsps/2)))/2.0 + k1=(nsym-1)*nsps+3*nsps/4+1 + wave(k1:k1+nsps/4)=wave(k1:k1+nsps/4) * & + (1.0+cos(twopi*(/(i,i=0,nsps/4)/)/real(nsps/2)))/2.0 + endif + else + if(lshape) then + cwave(1:nsps/4)=cwave(1:nsps/4) * & + (1.0-cos(twopi*(/(i,i=0,nsps/4-1)/)/real(nsps/2)))/2.0 + k1=(nsym-1)*nsps+3*nsps/4+1 + cwave(k1:k1+nsps/4)=cwave(k1:k1+nsps/4) * & + (1.0+cos(twopi*(/(i,i=0,nsps/4)/)/real(nsps/2)))/2.0 + endif + endif + + return +end subroutine gen_fst4wave diff --git a/lib/fst4/genfst4.f90 b/lib/fst4/genfst4.f90 index 607f1fe4..42950554 100755 --- a/lib/fst4/genfst4.f90 +++ b/lib/fst4/genfst4.f90 @@ -1,111 +1,111 @@ -subroutine genfst4(msg0,ichk,msgsent,msgbits,i4tone,iwspr) - -! Input: -! - msg0 requested message to be transmitted -! - ichk if ichk=1, return only msgsent -! - msgsent message as it will be decoded -! - i4tone array of audio tone values, {0,1,2,3} -! - iwspr in: 0: FST4 1: FST4W -! out 0: (240,101)/crc24, 1: (240,74)/crc24 -! -! Frame structure: -! s8 d30 s8 d30 s8 d30 s8 d30 s8 - - use packjt77 - include 'fst4_params.f90' - character*37 msg0 - character*37 message !Message to be generated - character*37 msgsent !Message as it will be received - character*77 c77 - character*24 c24 - integer*4 i4tone(NN),itmp(ND) - integer*1 codeword(2*ND) - integer*1 msgbits(101),rvec(77) - integer isyncword1(8),isyncword2(8) - integer ncrc24 - logical unpk77_success - data isyncword1/0,1,3,2,1,0,2,3/ - data isyncword2/2,3,1,0,3,2,0,1/ - data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & - 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & - 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ - message=msg0 - - do i=1, 37 - if(ichar(message(i:i)).eq.0) then - message(i:37)=' ' - exit - endif - enddo - do i=1,37 !Strip leading blanks - if(message(1:1).ne.' ') exit - message=message(i+1:) - enddo - - i3=-1 - n3=-1 - if(iwspr.eq.1) then - i3=0 - n3=6 - endif - call pack77(message,i3,n3,c77) - call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent - msgbits=0 - iwspr=0 - if(i3.eq.0.and.n3.eq.6) then - iwspr=1 - read(c77,'(50i1)') msgbits(1:50) - call get_crc24(msgbits,74,ncrc24) - write(c24,'(b24.24)') ncrc24 - read(c24,'(24i1)') msgbits(51:74) - else - read(c77,'(77i1)') msgbits(1:77) - msgbits(1:77)=mod(msgbits(1:77)+rvec,2) - call get_crc24(msgbits,101,ncrc24) - write(c24,'(b24.24)') ncrc24 - read(c24,'(24i1)') msgbits(78:101) - endif - - if(ichk.eq.1) go to 999 - if(unpk77_success) go to 2 - msgbits=0 - itone=0 - msgsent='*** bad message *** ' - go to 999 - - entry get_fst4_tones_from_bits(msgbits,i4tone,iwspr) - -2 continue - if(iwspr.eq.0) then - call encode240_101(msgbits,codeword) - else - call encode240_74(msgbits(1:74),codeword) - endif - -! Grayscale mapping: -! bits tone -! 00 0 -! 01 1 -! 11 2 -! 10 3 - - do i=1,ND - is=codeword(2*i)+2*codeword(2*i-1) - if(is.le.1) itmp(i)=is - if(is.eq.2) itmp(i)=3 - if(is.eq.3) itmp(i)=2 - enddo - - i4tone( 1: 8)=isyncword1 - i4tone( 9: 38)=itmp( 1: 30) - i4tone( 39: 46)=isyncword2 - i4tone( 47: 76)=itmp( 31: 60) - i4tone( 77: 84)=isyncword1 - i4tone( 85:114)=itmp( 61: 90) - i4tone(115:122)=isyncword2 - i4tone(123:152)=itmp( 91:120) - i4tone(153:160)=isyncword1 - -999 return - -end subroutine genfst4 +subroutine genfst4(msg0,ichk,msgsent,msgbits,i4tone,iwspr) + +! Input: +! - msg0 requested message to be transmitted +! - ichk if ichk=1, return only msgsent +! - msgsent message as it will be decoded +! - i4tone array of audio tone values, {0,1,2,3} +! - iwspr in: 0: FST4 1: FST4W +! out 0: (240,101)/crc24, 1: (240,74)/crc24 +! +! Frame structure: +! s8 d30 s8 d30 s8 d30 s8 d30 s8 + + use packjt77 + include 'fst4_params.f90' + character*37 msg0 + character*37 message !Message to be generated + character*37 msgsent !Message as it will be received + character*77 c77 + character*24 c24 + integer*4 i4tone(NN),itmp(ND) + integer*1 codeword(2*ND) + integer*1 msgbits(101),rvec(77) + integer isyncword1(8),isyncword2(8) + integer ncrc24 + logical unpk77_success + data isyncword1/0,1,3,2,1,0,2,3/ + data isyncword2/2,3,1,0,3,2,0,1/ + data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & + 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & + 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ + message=msg0 + + do i=1, 37 + if(ichar(message(i:i)).eq.0) then + message(i:37)=' ' + exit + endif + enddo + do i=1,37 !Strip leading blanks + if(message(1:1).ne.' ') exit + message=message(i+1:) + enddo + + i3=-1 + n3=-1 + if(iwspr.eq.1) then + i3=0 + n3=6 + endif + call pack77(message,i3,n3,c77) + call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent + msgbits=0 + iwspr=0 + if(i3.eq.0.and.n3.eq.6) then + iwspr=1 + read(c77,'(50i1)') msgbits(1:50) + call get_crc24(msgbits,74,ncrc24) + write(c24,'(b24.24)') ncrc24 + read(c24,'(24i1)') msgbits(51:74) + else + read(c77,'(77i1)') msgbits(1:77) + msgbits(1:77)=mod(msgbits(1:77)+rvec,2) + call get_crc24(msgbits,101,ncrc24) + write(c24,'(b24.24)') ncrc24 + read(c24,'(24i1)') msgbits(78:101) + endif + + if(ichk.eq.1) go to 999 + if(unpk77_success) go to 2 + msgbits=0 + itone=0 + msgsent='*** bad message *** ' + go to 999 + + entry get_fst4_tones_from_bits(msgbits,i4tone,iwspr) + +2 continue + if(iwspr.eq.0) then + call encode240_101(msgbits,codeword) + else + call encode240_74(msgbits(1:74),codeword) + endif + +! Grayscale mapping: +! bits tone +! 00 0 +! 01 1 +! 11 2 +! 10 3 + + do i=1,ND + is=codeword(2*i)+2*codeword(2*i-1) + if(is.le.1) itmp(i)=is + if(is.eq.2) itmp(i)=3 + if(is.eq.3) itmp(i)=2 + enddo + + i4tone( 1: 8)=isyncword1 + i4tone( 9: 38)=itmp( 1: 30) + i4tone( 39: 46)=isyncword2 + i4tone( 47: 76)=itmp( 31: 60) + i4tone( 77: 84)=isyncword1 + i4tone( 85:114)=itmp( 61: 90) + i4tone(115:122)=isyncword2 + i4tone(123:152)=itmp( 91:120) + i4tone(153:160)=isyncword1 + +999 return + +end subroutine genfst4 diff --git a/lib/fst4/get_crc24.f90 b/lib/fst4/get_crc24.f90 index 0dadf6d8..cb7f3a05 100755 --- a/lib/fst4/get_crc24.f90 +++ b/lib/fst4/get_crc24.f90 @@ -1,25 +1,25 @@ -subroutine get_crc24(mc,len,ncrc) -! -! 1. To calculate 24-bit CRC, mc(1:len-24) is the message and mc(len-23:len) are zero. -! 2. To check a received CRC, mc(1:len) is the received message plus CRC. -! ncrc will be zero if the received message/CRC are consistent. -! - character c24*24 - integer*1 mc(len) - integer*1 r(25),p(25) - integer ncrc -! polynomial for 24-bit CRC 0x100065b - data p/1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,1,1,0,1,1/ - -! divide by polynomial - r=mc(1:25) - do i=0,len-25 - r(25)=mc(i+25) - r=mod(r+r(1)*p,2) - r=cshift(r,1) - enddo - - write(c24,'(24b1)') r(1:24) - read(c24,'(b24.24)') ncrc - -end subroutine get_crc24 +subroutine get_crc24(mc,len,ncrc) +! +! 1. To calculate 24-bit CRC, mc(1:len-24) is the message and mc(len-23:len) are zero. +! 2. To check a received CRC, mc(1:len) is the received message plus CRC. +! ncrc will be zero if the received message/CRC are consistent. +! + character c24*24 + integer*1 mc(len) + integer*1 r(25),p(25) + integer ncrc +! polynomial for 24-bit CRC 0x100065b + data p/1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,1,1,0,1,1/ + +! divide by polynomial + r=mc(1:25) + do i=0,len-25 + r(25)=mc(i+25) + r=mod(r+r(1)*p,2) + r=cshift(r,1) + enddo + + write(c24,'(24b1)') r(1:24) + read(c24,'(b24.24)') ncrc + +end subroutine get_crc24 diff --git a/lib/fst4/get_fst4_bitmetrics.f90 b/lib/fst4/get_fst4_bitmetrics.f90 index 00cc6e7f..0ae747c5 100755 --- a/lib/fst4/get_fst4_bitmetrics.f90 +++ b/lib/fst4/get_fst4_bitmetrics.f90 @@ -1,190 +1,190 @@ -subroutine get_fst4_bitmetrics(cd,nss,bitmetrics,s4,nsync_qual,badsync) - - use timer_module, only: timer - include 'fst4_params.f90' - complex cd(0:NN*nss-1) - complex cs(0:3,NN) - complex csymb(nss) - complex, allocatable, save :: ci(:,:) ! ideal waveforms, 20 samples per symbol, 4 tones - complex c1(4,8),c2(16,4),c4(256,2) - integer isyncword1(0:7),isyncword2(0:7) - integer graymap(0:3) - integer ip(1) - integer hbits(2*NN) - logical one(0:65535,0:15) ! 65536 8-symbol sequences, 16 bits - logical first - logical badsync - real bitmetrics(2*NN,4) - real s2(0:65535) - real s4(0:3,NN) - data isyncword1/0,1,3,2,1,0,2,3/ - data isyncword2/2,3,1,0,3,2,0,1/ - data graymap/0,1,3,2/ - data first/.true./,nss0/-1/ - save first,one,nss0 - - if(nss.ne.nss0 .and. allocated(ci)) deallocate(ci) - - if(first .or. nss.ne.nss0) then - allocate(ci(nss,0:3)) - one=.false. - do i=0,65535 - do j=0,15 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - twopi=8.0*atan(1.0) - dphi=twopi/nss - do itone=0,3 - dp=(itone-1.5)*dphi - phi=0.0 - do j=1,nss - ci(j,itone)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dp,twopi) - enddo - enddo - first=.false. - endif - - do k=1,NN - i1=(k-1)*NSS - csymb=cd(i1:i1+NSS-1) - do itone=0,3 - cs(itone,k)=sum(csymb*conjg(ci(:,itone))) - enddo - s4(0:3,k)=abs(cs(0:3,k))**2 - enddo - -! Sync quality check - is1=0 - is2=0 - is3=0 - is4=0 - is5=0 - badsync=.false. - ibmax=0 - - do k=1,8 - ip=maxloc(s4(:,k)) - if(isyncword1(k-1).eq.(ip(1)-1)) is1=is1+1 - ip=maxloc(s4(:,k+38)) - if(isyncword2(k-1).eq.(ip(1)-1)) is2=is2+1 - ip=maxloc(s4(:,k+76)) - if(isyncword1(k-1).eq.(ip(1)-1)) is3=is3+1 - ip=maxloc(s4(:,k+114)) - if(isyncword2(k-1).eq.(ip(1)-1)) is4=is4+1 - ip=maxloc(s4(:,k+152)) - if(isyncword1(k-1).eq.(ip(1)-1)) is5=is5+1 - enddo - nsync=is1+is2+is3+is4+is5 !Number of correct hard sync symbols, 0-40 - badsync=.false. - if(nsync .lt. 16) then - badsync=.true. - return - endif - - call timer('seqcorrs',0) - bitmetrics=0.0 - -! Process the frame in 8-symbol chunks. Use 1-symbol correlations to calculate -! 2-symbol correlations. Then use 2-symbol correlations to calculate 4-symbol -! correlations. Finally, use 4-symbol correlations to calculate 8-symbol corrs. -! This eliminates redundant calculations. - - do k=1,NN,8 - - do m=1,8 ! do 4 1-symbol correlations for each of 8 symbs - s2=0 - do n=1,4 - c1(n,m)=cs(graymap(n-1),k+m-1) - s2(n-1)=abs(c1(n,m)) - enddo - ipt=(k-1)*2+2*(m-1)+1 - do ib=0,1 - bm=maxval(s2(0:3),one(0:3,1-ib)) - & - maxval(s2(0:3),.not.one(0:3,1-ib)) - if(ipt+ib.gt.2*NN) cycle - bitmetrics(ipt+ib,1)=bm - enddo - enddo - - do m=1,4 ! do 16 2-symbol correlations for each of 4 2-symbol groups - s2=0 - do i=1,4 - do j=1,4 - is=(i-1)*4+j - c2(is,m)=c1(i,2*m-1)-c1(j,2*m) - s2(is-1)=abs(c2(is,m)) - enddo - enddo - ipt=(k-1)*2+4*(m-1)+1 - do ib=0,3 - bm=maxval(s2(0:15),one(0:15,3-ib)) - & - maxval(s2(0:15),.not.one(0:15,3-ib)) - if(ipt+ib.gt.2*NN) cycle - bitmetrics(ipt+ib,2)=bm - enddo - enddo - - do m=1,2 ! do 256 4-symbol corrs for each of 2 4-symbol groups - s2=0 - do i=1,16 - do j=1,16 - is=(i-1)*16+j - c4(is,m)=c2(i,2*m-1)+c2(j,2*m) - s2(is-1)=abs(c4(is,m)) - enddo - enddo - ipt=(k-1)*2+8*(m-1)+1 - do ib=0,7 - bm=maxval(s2(0:255),one(0:255,7-ib)) - & - maxval(s2(0:255),.not.one(0:255,7-ib)) - if(ipt+ib.gt.2*NN) cycle - bitmetrics(ipt+ib,3)=bm - enddo - enddo - - s2=0 ! do 65536 8-symbol correlations for the entire group - do i=1,256 - do j=1,256 - is=(i-1)*256+j - s2(is-1)=abs(c4(i,1)+c4(j,2)) - enddo - enddo - ipt=(k-1)*2+1 - do ib=0,15 - bm=maxval(s2(0:65535),one(0:65535,15-ib)) - & - maxval(s2(0:65535),.not.one(0:65535,15-ib)) - if(ipt+ib.gt.2*NN) cycle - bitmetrics(ipt+ib,4)=bm - enddo - - enddo - - call timer('seqcorrs',1) - - hbits=0 - where(bitmetrics(:,1).ge.0) hbits=1 - ns1=count(hbits( 1: 16).eq.(/0,0,0,1,1,0,1,1,0,1,0,0,1,1,1,0/)) - ns2=count(hbits( 77: 92).eq.(/1,1,1,0,0,1,0,0,1,0,1,1,0,0,0,1/)) - ns3=count(hbits(153:168).eq.(/0,0,0,1,1,0,1,1,0,1,0,0,1,1,1,0/)) - ns4=count(hbits(229:244).eq.(/1,1,1,0,0,1,0,0,1,0,1,1,0,0,0,1/)) - ns5=count(hbits(305:320).eq.(/0,0,0,1,1,0,1,1,0,1,0,0,1,1,1,0/)) - nsync_qual=ns1+ns2+ns3+ns4+ns5 - - if(nsync_qual.lt. 46) then - badsync=.true. - return - endif - - call normalizebmet(bitmetrics(:,1),2*NN) - call normalizebmet(bitmetrics(:,2),2*NN) - call normalizebmet(bitmetrics(:,3),2*NN) - call normalizebmet(bitmetrics(:,4),2*NN) - - scalefac=2.83 - bitmetrics=scalefac*bitmetrics - - return - -end subroutine get_fst4_bitmetrics +subroutine get_fst4_bitmetrics(cd,nss,bitmetrics,s4,nsync_qual,badsync) + + use timer_module, only: timer + include 'fst4_params.f90' + complex cd(0:NN*nss-1) + complex cs(0:3,NN) + complex csymb(nss) + complex, allocatable, save :: ci(:,:) ! ideal waveforms, 20 samples per symbol, 4 tones + complex c1(4,8),c2(16,4),c4(256,2) + integer isyncword1(0:7),isyncword2(0:7) + integer graymap(0:3) + integer ip(1) + integer hbits(2*NN) + logical one(0:65535,0:15) ! 65536 8-symbol sequences, 16 bits + logical first + logical badsync + real bitmetrics(2*NN,4) + real s2(0:65535) + real s4(0:3,NN) + data isyncword1/0,1,3,2,1,0,2,3/ + data isyncword2/2,3,1,0,3,2,0,1/ + data graymap/0,1,3,2/ + data first/.true./,nss0/-1/ + save first,one,nss0 + + if(nss.ne.nss0 .and. allocated(ci)) deallocate(ci) + + if(first .or. nss.ne.nss0) then + allocate(ci(nss,0:3)) + one=.false. + do i=0,65535 + do j=0,15 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + twopi=8.0*atan(1.0) + dphi=twopi/nss + do itone=0,3 + dp=(itone-1.5)*dphi + phi=0.0 + do j=1,nss + ci(j,itone)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dp,twopi) + enddo + enddo + first=.false. + endif + + do k=1,NN + i1=(k-1)*NSS + csymb=cd(i1:i1+NSS-1) + do itone=0,3 + cs(itone,k)=sum(csymb*conjg(ci(:,itone))) + enddo + s4(0:3,k)=abs(cs(0:3,k))**2 + enddo + +! Sync quality check + is1=0 + is2=0 + is3=0 + is4=0 + is5=0 + badsync=.false. + ibmax=0 + + do k=1,8 + ip=maxloc(s4(:,k)) + if(isyncword1(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s4(:,k+38)) + if(isyncword2(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s4(:,k+76)) + if(isyncword1(k-1).eq.(ip(1)-1)) is3=is3+1 + ip=maxloc(s4(:,k+114)) + if(isyncword2(k-1).eq.(ip(1)-1)) is4=is4+1 + ip=maxloc(s4(:,k+152)) + if(isyncword1(k-1).eq.(ip(1)-1)) is5=is5+1 + enddo + nsync=is1+is2+is3+is4+is5 !Number of correct hard sync symbols, 0-40 + badsync=.false. + if(nsync .lt. 16) then + badsync=.true. + return + endif + + call timer('seqcorrs',0) + bitmetrics=0.0 + +! Process the frame in 8-symbol chunks. Use 1-symbol correlations to calculate +! 2-symbol correlations. Then use 2-symbol correlations to calculate 4-symbol +! correlations. Finally, use 4-symbol correlations to calculate 8-symbol corrs. +! This eliminates redundant calculations. + + do k=1,NN,8 + + do m=1,8 ! do 4 1-symbol correlations for each of 8 symbs + s2=0 + do n=1,4 + c1(n,m)=cs(graymap(n-1),k+m-1) + s2(n-1)=abs(c1(n,m)) + enddo + ipt=(k-1)*2+2*(m-1)+1 + do ib=0,1 + bm=maxval(s2(0:3),one(0:3,1-ib)) - & + maxval(s2(0:3),.not.one(0:3,1-ib)) + if(ipt+ib.gt.2*NN) cycle + bitmetrics(ipt+ib,1)=bm + enddo + enddo + + do m=1,4 ! do 16 2-symbol correlations for each of 4 2-symbol groups + s2=0 + do i=1,4 + do j=1,4 + is=(i-1)*4+j + c2(is,m)=c1(i,2*m-1)-c1(j,2*m) + s2(is-1)=abs(c2(is,m)) + enddo + enddo + ipt=(k-1)*2+4*(m-1)+1 + do ib=0,3 + bm=maxval(s2(0:15),one(0:15,3-ib)) - & + maxval(s2(0:15),.not.one(0:15,3-ib)) + if(ipt+ib.gt.2*NN) cycle + bitmetrics(ipt+ib,2)=bm + enddo + enddo + + do m=1,2 ! do 256 4-symbol corrs for each of 2 4-symbol groups + s2=0 + do i=1,16 + do j=1,16 + is=(i-1)*16+j + c4(is,m)=c2(i,2*m-1)+c2(j,2*m) + s2(is-1)=abs(c4(is,m)) + enddo + enddo + ipt=(k-1)*2+8*(m-1)+1 + do ib=0,7 + bm=maxval(s2(0:255),one(0:255,7-ib)) - & + maxval(s2(0:255),.not.one(0:255,7-ib)) + if(ipt+ib.gt.2*NN) cycle + bitmetrics(ipt+ib,3)=bm + enddo + enddo + + s2=0 ! do 65536 8-symbol correlations for the entire group + do i=1,256 + do j=1,256 + is=(i-1)*256+j + s2(is-1)=abs(c4(i,1)+c4(j,2)) + enddo + enddo + ipt=(k-1)*2+1 + do ib=0,15 + bm=maxval(s2(0:65535),one(0:65535,15-ib)) - & + maxval(s2(0:65535),.not.one(0:65535,15-ib)) + if(ipt+ib.gt.2*NN) cycle + bitmetrics(ipt+ib,4)=bm + enddo + + enddo + + call timer('seqcorrs',1) + + hbits=0 + where(bitmetrics(:,1).ge.0) hbits=1 + ns1=count(hbits( 1: 16).eq.(/0,0,0,1,1,0,1,1,0,1,0,0,1,1,1,0/)) + ns2=count(hbits( 77: 92).eq.(/1,1,1,0,0,1,0,0,1,0,1,1,0,0,0,1/)) + ns3=count(hbits(153:168).eq.(/0,0,0,1,1,0,1,1,0,1,0,0,1,1,1,0/)) + ns4=count(hbits(229:244).eq.(/1,1,1,0,0,1,0,0,1,0,1,1,0,0,0,1/)) + ns5=count(hbits(305:320).eq.(/0,0,0,1,1,0,1,1,0,1,0,0,1,1,1,0/)) + nsync_qual=ns1+ns2+ns3+ns4+ns5 + + if(nsync_qual.lt. 46) then + badsync=.true. + return + endif + + call normalizebmet(bitmetrics(:,1),2*NN) + call normalizebmet(bitmetrics(:,2),2*NN) + call normalizebmet(bitmetrics(:,3),2*NN) + call normalizebmet(bitmetrics(:,4),2*NN) + + scalefac=2.83 + bitmetrics=scalefac*bitmetrics + + return + +end subroutine get_fst4_bitmetrics diff --git a/lib/fst4/get_fst4_bitmetrics2.f90 b/lib/fst4/get_fst4_bitmetrics2.f90 index 8aa230a0..96557d2e 100755 --- a/lib/fst4/get_fst4_bitmetrics2.f90 +++ b/lib/fst4/get_fst4_bitmetrics2.f90 @@ -1,127 +1,127 @@ -subroutine get_fst4_bitmetrics2(cd,nss,hmod,nsizes,bitmetrics,s4snr,badsync) - - include 'fst4_params.f90' - complex cd(0:NN*nss-1) - complex csymb(nss) - complex, allocatable, save :: c1(:,:) ! ideal waveforms, 4 tones - complex cp(0:3) ! accumulated phase shift over symbol types 0:3 - integer isyncword1(0:7),isyncword2(0:7) - integer graymap(0:3) - integer ip(1) - integer hmod - logical one(0:65535,0:15) ! 65536 8-symbol sequences, 16 bits - logical first - logical badsync - real bitmetrics(2*NN,4) - real s2(0:65535) - real s4(0:3,NN,4),s4snr(0:3,NN) - data isyncword1/0,1,3,2,1,0,2,3/ - data isyncword2/2,3,1,0,3,2,0,1/ - data graymap/0,1,3,2/ - data first/.true./,nss0/-1/ - save first,one,cp,nss0 - - if(nss.ne.nss0 .and. allocated(c1)) deallocate(c1) - if(first .or. nss.ne.nss0) then - allocate(c1(nss,0:3)) - one=.false. - do i=0,65535 - do j=0,15 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - twopi=8.0*atan(1.0) - dphi=twopi*hmod/nss - do itone=0,3 - dp=(itone-1.5)*dphi - phi=0.0 - do j=1,nss - c1(j,itone)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dp,twopi) - enddo - cp(itone)=cmplx(cos(phi),sin(phi)) - enddo - first=.false. - endif - - do k=1,NN - i1=(k-1)*NSS - csymb=cd(i1:i1+NSS-1) - do itone=0,3 - s4(itone,k,1)=abs(sum(csymb*conjg(c1(:,itone))))**2 - s4(itone,k,2)=abs(sum(csymb( 1:nss/2)*conjg(c1( 1:nss/2,itone))))**2 + & - abs(sum(csymb(nss/2+1: nss)*conjg(c1(nss/2+1: nss,itone))))**2 - s4(itone,k,3)=abs(sum(csymb( 1: nss/4)*conjg(c1( 1: nss/4,itone))))**2 + & - abs(sum(csymb( nss/4+1: nss/2)*conjg(c1( nss/4+1: nss/2,itone))))**2 + & - abs(sum(csymb( nss/2+1:3*nss/4)*conjg(c1( nss/2+1:3*nss/4,itone))))**2 + & - abs(sum(csymb(3*nss/4+1: nss)*conjg(c1(3*nss/4+1: nss,itone))))**2 - s4(itone,k,4)=abs(sum(csymb( 1: nss/8)*conjg(c1( 1: nss/8,itone))))**2 + & - abs(sum(csymb( nss/8+1: nss/4)*conjg(c1( nss/8+1: nss/4,itone))))**2 + & - abs(sum(csymb( nss/4+1:3*nss/8)*conjg(c1( nss/4+1:3*nss/8,itone))))**2 + & - abs(sum(csymb(3*nss/8+1: nss/2)*conjg(c1(3*nss/8+1: nss/2,itone))))**2 + & - abs(sum(csymb( nss/2+1:5*nss/8)*conjg(c1( nss/2+1:5*nss/8,itone))))**2 + & - abs(sum(csymb(5*nss/8+1:3*nss/4)*conjg(c1(5*nss/8+1:3*nss/4,itone))))**2 + & - abs(sum(csymb(3*nss/4+1:7*nss/8)*conjg(c1(3*nss/4+1:7*nss/8,itone))))**2 + & - abs(sum(csymb(7*nss/8+1: nss)*conjg(c1(7*nss/8+1: nss,itone))))**2 - - enddo - enddo - -! Sync quality check - is1=0 - is2=0 - is3=0 - is4=0 - is5=0 - badsync=.false. - ibmax=0 - - is1=0; is2=0; is3=0; is4=0; is5=0 - do k=1,8 - ip=maxloc(s4(:,k,1)) - if(isyncword1(k-1).eq.(ip(1)-1)) is1=is1+1 - ip=maxloc(s4(:,k+38,1)) - if(isyncword2(k-1).eq.(ip(1)-1)) is2=is2+1 - ip=maxloc(s4(:,k+76,1)) - if(isyncword1(k-1).eq.(ip(1)-1)) is3=is3+1 - ip=maxloc(s4(:,k+114,1)) - if(isyncword2(k-1).eq.(ip(1)-1)) is4=is4+1 - ip=maxloc(s4(:,k+152,1)) - if(isyncword1(k-1).eq.(ip(1)-1)) is5=is5+1 - enddo - nsync=is1+is2+is3+is4+is5 !Number of correct hard sync symbols, 0-40 - badsync=.false. - - if(nsync .lt. 16) then - badsync=.true. - return - endif - - bitmetrics=0.0 - do nsub=1,nsizes - do ks=1,NN - s2=0 - do i=0,3 - s2(i)=s4(graymap(i),ks,nsub) - enddo - ipt=1+(ks-1)*2 - ibmax=1 - do ib=0,ibmax - bm=maxval(s2(0:3),one(0:3,ibmax-ib)) - & - maxval(s2(0:3),.not.one(0:3,ibmax-ib)) - if(ipt+ib.gt.2*NN) cycle - bitmetrics(ipt+ib,nsub)=bm - enddo - enddo - enddo - - call normalizebmet(bitmetrics(:,1),2*NN) - call normalizebmet(bitmetrics(:,2),2*NN) - call normalizebmet(bitmetrics(:,3),2*NN) - call normalizebmet(bitmetrics(:,4),2*NN) - -! Return the s4 array corresponding to N=1. Will be used for SNR calculation - s4snr(:,:)=s4(:,:,1) - return - -end subroutine get_fst4_bitmetrics2 +subroutine get_fst4_bitmetrics2(cd,nss,hmod,nsizes,bitmetrics,s4snr,badsync) + + include 'fst4_params.f90' + complex cd(0:NN*nss-1) + complex csymb(nss) + complex, allocatable, save :: c1(:,:) ! ideal waveforms, 4 tones + complex cp(0:3) ! accumulated phase shift over symbol types 0:3 + integer isyncword1(0:7),isyncword2(0:7) + integer graymap(0:3) + integer ip(1) + integer hmod + logical one(0:65535,0:15) ! 65536 8-symbol sequences, 16 bits + logical first + logical badsync + real bitmetrics(2*NN,4) + real s2(0:65535) + real s4(0:3,NN,4),s4snr(0:3,NN) + data isyncword1/0,1,3,2,1,0,2,3/ + data isyncword2/2,3,1,0,3,2,0,1/ + data graymap/0,1,3,2/ + data first/.true./,nss0/-1/ + save first,one,cp,nss0 + + if(nss.ne.nss0 .and. allocated(c1)) deallocate(c1) + if(first .or. nss.ne.nss0) then + allocate(c1(nss,0:3)) + one=.false. + do i=0,65535 + do j=0,15 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + twopi=8.0*atan(1.0) + dphi=twopi*hmod/nss + do itone=0,3 + dp=(itone-1.5)*dphi + phi=0.0 + do j=1,nss + c1(j,itone)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dp,twopi) + enddo + cp(itone)=cmplx(cos(phi),sin(phi)) + enddo + first=.false. + endif + + do k=1,NN + i1=(k-1)*NSS + csymb=cd(i1:i1+NSS-1) + do itone=0,3 + s4(itone,k,1)=abs(sum(csymb*conjg(c1(:,itone))))**2 + s4(itone,k,2)=abs(sum(csymb( 1:nss/2)*conjg(c1( 1:nss/2,itone))))**2 + & + abs(sum(csymb(nss/2+1: nss)*conjg(c1(nss/2+1: nss,itone))))**2 + s4(itone,k,3)=abs(sum(csymb( 1: nss/4)*conjg(c1( 1: nss/4,itone))))**2 + & + abs(sum(csymb( nss/4+1: nss/2)*conjg(c1( nss/4+1: nss/2,itone))))**2 + & + abs(sum(csymb( nss/2+1:3*nss/4)*conjg(c1( nss/2+1:3*nss/4,itone))))**2 + & + abs(sum(csymb(3*nss/4+1: nss)*conjg(c1(3*nss/4+1: nss,itone))))**2 + s4(itone,k,4)=abs(sum(csymb( 1: nss/8)*conjg(c1( 1: nss/8,itone))))**2 + & + abs(sum(csymb( nss/8+1: nss/4)*conjg(c1( nss/8+1: nss/4,itone))))**2 + & + abs(sum(csymb( nss/4+1:3*nss/8)*conjg(c1( nss/4+1:3*nss/8,itone))))**2 + & + abs(sum(csymb(3*nss/8+1: nss/2)*conjg(c1(3*nss/8+1: nss/2,itone))))**2 + & + abs(sum(csymb( nss/2+1:5*nss/8)*conjg(c1( nss/2+1:5*nss/8,itone))))**2 + & + abs(sum(csymb(5*nss/8+1:3*nss/4)*conjg(c1(5*nss/8+1:3*nss/4,itone))))**2 + & + abs(sum(csymb(3*nss/4+1:7*nss/8)*conjg(c1(3*nss/4+1:7*nss/8,itone))))**2 + & + abs(sum(csymb(7*nss/8+1: nss)*conjg(c1(7*nss/8+1: nss,itone))))**2 + + enddo + enddo + +! Sync quality check + is1=0 + is2=0 + is3=0 + is4=0 + is5=0 + badsync=.false. + ibmax=0 + + is1=0; is2=0; is3=0; is4=0; is5=0 + do k=1,8 + ip=maxloc(s4(:,k,1)) + if(isyncword1(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s4(:,k+38,1)) + if(isyncword2(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s4(:,k+76,1)) + if(isyncword1(k-1).eq.(ip(1)-1)) is3=is3+1 + ip=maxloc(s4(:,k+114,1)) + if(isyncword2(k-1).eq.(ip(1)-1)) is4=is4+1 + ip=maxloc(s4(:,k+152,1)) + if(isyncword1(k-1).eq.(ip(1)-1)) is5=is5+1 + enddo + nsync=is1+is2+is3+is4+is5 !Number of correct hard sync symbols, 0-40 + badsync=.false. + + if(nsync .lt. 16) then + badsync=.true. + return + endif + + bitmetrics=0.0 + do nsub=1,nsizes + do ks=1,NN + s2=0 + do i=0,3 + s2(i)=s4(graymap(i),ks,nsub) + enddo + ipt=1+(ks-1)*2 + ibmax=1 + do ib=0,ibmax + bm=maxval(s2(0:3),one(0:3,ibmax-ib)) - & + maxval(s2(0:3),.not.one(0:3,ibmax-ib)) + if(ipt+ib.gt.2*NN) cycle + bitmetrics(ipt+ib,nsub)=bm + enddo + enddo + enddo + + call normalizebmet(bitmetrics(:,1),2*NN) + call normalizebmet(bitmetrics(:,2),2*NN) + call normalizebmet(bitmetrics(:,3),2*NN) + call normalizebmet(bitmetrics(:,4),2*NN) + +! Return the s4 array corresponding to N=1. Will be used for SNR calculation + s4snr(:,:)=s4(:,:,1) + return + +end subroutine get_fst4_bitmetrics2 diff --git a/lib/fst4/ldpc_240_101_generator.f90 b/lib/fst4/ldpc_240_101_generator.f90 index 6df6a1e8..782e0a21 100755 --- a/lib/fst4/ldpc_240_101_generator.f90 +++ b/lib/fst4/ldpc_240_101_generator.f90 @@ -1,142 +1,142 @@ -character*26 g(139) - -data g/ & - "e28df133efbc554bcd30eb1828", & - "b1adf97787f81b4ac02e0caff8", & - "e70c43adce5036f847af367560", & - "c26663f7f7acafdf5abacb6f30", & - "eba93204ddfa3bcf994aea8998", & - "126b51e33c6a740afa0d5ce990", & - "b41a1569e6fede1f2f5395cb68", & - "1d3af0bb43fddbc670a291cc70", & - "e0aebd9921e2c9e1d453ffccb0", & - "897d1370f0df94b8b27a5e4fb8", & - "5e97539338003b13fa8198ad38", & - "7276b87da4a4d777e2752fdd48", & - "989888bd3a85835e2bc6a560f8", & - "7ec4f4a56199ab0a8d6e102478", & - "207007665090258782d1b38a98", & - "1ea1f61cd7f0b7eed7dd346ab8", & - "08f150b27c7f18a027783de0e8", & - "d42324a4e21b62d548d7865858", & - "2e029656269d4fe46e167d21d0", & - "7d84acb7737b0ca6b6f2ef5eb0", & - "6674ca04528ad4782bf5e15248", & - "118ce9825f563ae4963af7a0b0", & - "fb06248cc985e314b1b36ccd38", & - "1c478b7a5aec7e1cfc9c24eb70", & - "185a0f06a84f7f4f484c455020", & - "98b840a3a70688cd58588e3e30", & - "cfb7719de83a3baf582e5b2aa0", & - "9d8cc6b5a01fdbfa307a769048", & - "ed776a728ca162d6fcc8996760", & - "8d2b068128dfb2f8d22c79db50", & - "bd2ba50007789ffb7324aa9190", & - "fd95008fe88812025e78065610", & - "3027849be8e99f9ef68eac1020", & - "88574e1ea39d87414b15e803a8", & - "89365b330e76e6dde740dced08", & - "c83f37b913ed0f6b802aaf21d8", & - "bdca7c1959caa7488b7eb13030", & - "794e0b4888e1ef42992287dd98", & - "526ac87fbaa790c6cd58864e08", & - "940518ba1a51c1da55bc8b2d70", & - "59c5e51ebfbd02ab30ff822378", & - "c81fff87866e04f8f3948c7f10", & - "7913513f3e2a3c0f76b69f6d68", & - "e43cc04da189c44803c4f740a0", & - "fdca7c1959ca85488b7eb13030", & - "95b07fce9b7b1bf4f057ca61b8", & - "d7db48a86691a0c0c9305aac90", & - "0d50bf79a59464597c43ba8058", & - "4a9c34b23fd5eaff8c9dc215e0", & - "3d5305a6f0427938eeb9d1c118", & - "55d8b6b58039f7a3a2d592a900", & - "784f349ecb74c4abbdbb073b90", & - "5973bbb2205f9d6a5c9a55c238", & - "5d2ee61006fec94f69f6b0f460", & - "9e1f52ef1e6589990dd0ce0cc8", & - "85b7b48f4b45775c9f8a36cc90", & - "ae1d6a0171168f6d70804b79f8", & - "a467aa9aa6cdc7094677c730d8", & - "dcf2f56c9ae20fb57e89b916d0", & - "3ae98d26ae96ea714c1a5146d0", & - "103c89581446805b8c71b2e638", & - "6783f3dfec835dd4e92131cc20", & - "52f88428c50f12c55876f7d8a8", & - "51fcb0e56a22fa3b7140aeaa80", & - "07c54871155603e65325f66cd8", & - "a8dd4fac47a113ee5706eef180", & - "f6cdc6f4cc1fa7e4db15bf86f8", & - "2e1c6a0171168f6d70c04a79f8", & - "2a90ab82bef6424db981752dc8", & - "845a1db59c193249d937e889d0", & - "a929d379f1769cb4baa4e41e90", & - "0c2a5829548d82223d6f566d48", & - "420087bc5c4e2f5bc139ad0220", & - "6df8d880ae7209fe52c69ede00", & - "dfbdcef29a985fd40d052d1a88", & - "8567fc332342b1ed8408f5fa00", & - "c908feb4e1866a24ca0c702a08", & - "645f5ee59f9f64fd43a5f2ec30", & - "bee56991e877baf3e9cf11b770", & - "649ea2e4194ca51be28abf3430", & - "90e7394c551bd58d00686d5420", & - "4e3cf731f8f89e8414214afaf0", & - "dcbf16aa8180a7712571e94f98", & - "9b456c015999c52b7fbd1ab390", & - "397ab76924659c4b8b3be4ac58", & - "4f5038c4f9da4b02bdfa178278", & - "4892fada978c98dd4fd363c450", & - "6c8af64b426bc474431c110c98", & - "84a553be5ef0e57390a5af05b0", & - "bed4a9347c9a2064f6d63ac0f8", & - "d973bbb2605f9d6a5c9a57c238", & - "1e3bee9a99fe10d3864ee669d8", & - "a590771ff185d807cb32f46000", & - "9a498fc4b549d81c625f80fc90", & - "28b3e72878aadee7e0e2617950", & - "96ce025d621a91396aa8f3ec20", & - "4f5a77becf838a590d6d406ea8", & - "52d3856dfb9fe78012f10e25c0", & - "b45323c2b28b4752ca0675d2e0", & - "3bae5a8452a785beb35851ad18", & - "65098832d20d915e75bea336e8", & - "5eb6f3c331098e8c0fbfa3aee0", & - "ef19d974a25540c8998fbf1df0", & - "403ea58feff08cf92d5cacc780", & - "6ba93204ddfa7bcb994aea8998", & - "653909166aa7bead4bd9c90020", & - "089cb20e639bc5a44da66f17c0", & - "10f803949961359e994f5ade88", & - "15b7ec1e6106cd55ef7d996590", & - "c99e99de9d85d2b999a17a95d8", & - "ca3e161b97148bac6dd28a6178", & - "e1ab199c992cb4c22aee115358", & - "ea8a4d0e96d3d9f827899b6d88", & - "8af4992d60223f021569a8ab60", & - "5087771abceb87a6d872291fe8", & - "d045e0812e217bb7bbdac92f30", & - "ccccd78ae5fa6e191f21c06908", & - "54545f37df6fed4734ef6509b0", & - "b0780327d899cbc03d95a81a48", & - "a4229c31f2b85e44a322273d50", & - "d182ab001c2085ea7be26a20d0", & - "1a82c30b4fba7dfaafb8d287a8", & - "d974fba598e7fb0630c1587db0", & - "b5c078a8cbab3e73728659ea20", & - "626bbf9eed1a8715c3a7d38f60", & - "c1efe9aa67130865fda93d8be8", & - "d39796dbce155df6306e7b77c0", & - "c7e7c1f032d7209b4549e84aa8", & - "d5799b30a1605baf6b9cd04960", & - "0baf2d21051a926dfd87046d70", & - "da8bf7d1e305c499b573c02cc8", & - "0ccaa7fffb9ae3e42dd0688328", & - "b951b62e18f5290ac13c195130", & - "79b006f001961fb233be80d0e8", & - "56637b6dedfd6e050f06404a48", & - "e0c4bf71a15597523bbd57bde0", & - "1312231ffa04426a34a8fab038", & - "db5f6f0455d24b8358d1cbc3d8", & - "d559e31b34d21f48e1f501af30"/ +character*26 g(139) + +data g/ & + "e28df133efbc554bcd30eb1828", & + "b1adf97787f81b4ac02e0caff8", & + "e70c43adce5036f847af367560", & + "c26663f7f7acafdf5abacb6f30", & + "eba93204ddfa3bcf994aea8998", & + "126b51e33c6a740afa0d5ce990", & + "b41a1569e6fede1f2f5395cb68", & + "1d3af0bb43fddbc670a291cc70", & + "e0aebd9921e2c9e1d453ffccb0", & + "897d1370f0df94b8b27a5e4fb8", & + "5e97539338003b13fa8198ad38", & + "7276b87da4a4d777e2752fdd48", & + "989888bd3a85835e2bc6a560f8", & + "7ec4f4a56199ab0a8d6e102478", & + "207007665090258782d1b38a98", & + "1ea1f61cd7f0b7eed7dd346ab8", & + "08f150b27c7f18a027783de0e8", & + "d42324a4e21b62d548d7865858", & + "2e029656269d4fe46e167d21d0", & + "7d84acb7737b0ca6b6f2ef5eb0", & + "6674ca04528ad4782bf5e15248", & + "118ce9825f563ae4963af7a0b0", & + "fb06248cc985e314b1b36ccd38", & + "1c478b7a5aec7e1cfc9c24eb70", & + "185a0f06a84f7f4f484c455020", & + "98b840a3a70688cd58588e3e30", & + "cfb7719de83a3baf582e5b2aa0", & + "9d8cc6b5a01fdbfa307a769048", & + "ed776a728ca162d6fcc8996760", & + "8d2b068128dfb2f8d22c79db50", & + "bd2ba50007789ffb7324aa9190", & + "fd95008fe88812025e78065610", & + "3027849be8e99f9ef68eac1020", & + "88574e1ea39d87414b15e803a8", & + "89365b330e76e6dde740dced08", & + "c83f37b913ed0f6b802aaf21d8", & + "bdca7c1959caa7488b7eb13030", & + "794e0b4888e1ef42992287dd98", & + "526ac87fbaa790c6cd58864e08", & + "940518ba1a51c1da55bc8b2d70", & + "59c5e51ebfbd02ab30ff822378", & + "c81fff87866e04f8f3948c7f10", & + "7913513f3e2a3c0f76b69f6d68", & + "e43cc04da189c44803c4f740a0", & + "fdca7c1959ca85488b7eb13030", & + "95b07fce9b7b1bf4f057ca61b8", & + "d7db48a86691a0c0c9305aac90", & + "0d50bf79a59464597c43ba8058", & + "4a9c34b23fd5eaff8c9dc215e0", & + "3d5305a6f0427938eeb9d1c118", & + "55d8b6b58039f7a3a2d592a900", & + "784f349ecb74c4abbdbb073b90", & + "5973bbb2205f9d6a5c9a55c238", & + "5d2ee61006fec94f69f6b0f460", & + "9e1f52ef1e6589990dd0ce0cc8", & + "85b7b48f4b45775c9f8a36cc90", & + "ae1d6a0171168f6d70804b79f8", & + "a467aa9aa6cdc7094677c730d8", & + "dcf2f56c9ae20fb57e89b916d0", & + "3ae98d26ae96ea714c1a5146d0", & + "103c89581446805b8c71b2e638", & + "6783f3dfec835dd4e92131cc20", & + "52f88428c50f12c55876f7d8a8", & + "51fcb0e56a22fa3b7140aeaa80", & + "07c54871155603e65325f66cd8", & + "a8dd4fac47a113ee5706eef180", & + "f6cdc6f4cc1fa7e4db15bf86f8", & + "2e1c6a0171168f6d70c04a79f8", & + "2a90ab82bef6424db981752dc8", & + "845a1db59c193249d937e889d0", & + "a929d379f1769cb4baa4e41e90", & + "0c2a5829548d82223d6f566d48", & + "420087bc5c4e2f5bc139ad0220", & + "6df8d880ae7209fe52c69ede00", & + "dfbdcef29a985fd40d052d1a88", & + "8567fc332342b1ed8408f5fa00", & + "c908feb4e1866a24ca0c702a08", & + "645f5ee59f9f64fd43a5f2ec30", & + "bee56991e877baf3e9cf11b770", & + "649ea2e4194ca51be28abf3430", & + "90e7394c551bd58d00686d5420", & + "4e3cf731f8f89e8414214afaf0", & + "dcbf16aa8180a7712571e94f98", & + "9b456c015999c52b7fbd1ab390", & + "397ab76924659c4b8b3be4ac58", & + "4f5038c4f9da4b02bdfa178278", & + "4892fada978c98dd4fd363c450", & + "6c8af64b426bc474431c110c98", & + "84a553be5ef0e57390a5af05b0", & + "bed4a9347c9a2064f6d63ac0f8", & + "d973bbb2605f9d6a5c9a57c238", & + "1e3bee9a99fe10d3864ee669d8", & + "a590771ff185d807cb32f46000", & + "9a498fc4b549d81c625f80fc90", & + "28b3e72878aadee7e0e2617950", & + "96ce025d621a91396aa8f3ec20", & + "4f5a77becf838a590d6d406ea8", & + "52d3856dfb9fe78012f10e25c0", & + "b45323c2b28b4752ca0675d2e0", & + "3bae5a8452a785beb35851ad18", & + "65098832d20d915e75bea336e8", & + "5eb6f3c331098e8c0fbfa3aee0", & + "ef19d974a25540c8998fbf1df0", & + "403ea58feff08cf92d5cacc780", & + "6ba93204ddfa7bcb994aea8998", & + "653909166aa7bead4bd9c90020", & + "089cb20e639bc5a44da66f17c0", & + "10f803949961359e994f5ade88", & + "15b7ec1e6106cd55ef7d996590", & + "c99e99de9d85d2b999a17a95d8", & + "ca3e161b97148bac6dd28a6178", & + "e1ab199c992cb4c22aee115358", & + "ea8a4d0e96d3d9f827899b6d88", & + "8af4992d60223f021569a8ab60", & + "5087771abceb87a6d872291fe8", & + "d045e0812e217bb7bbdac92f30", & + "ccccd78ae5fa6e191f21c06908", & + "54545f37df6fed4734ef6509b0", & + "b0780327d899cbc03d95a81a48", & + "a4229c31f2b85e44a322273d50", & + "d182ab001c2085ea7be26a20d0", & + "1a82c30b4fba7dfaafb8d287a8", & + "d974fba598e7fb0630c1587db0", & + "b5c078a8cbab3e73728659ea20", & + "626bbf9eed1a8715c3a7d38f60", & + "c1efe9aa67130865fda93d8be8", & + "d39796dbce155df6306e7b77c0", & + "c7e7c1f032d7209b4549e84aa8", & + "d5799b30a1605baf6b9cd04960", & + "0baf2d21051a926dfd87046d70", & + "da8bf7d1e305c499b573c02cc8", & + "0ccaa7fffb9ae3e42dd0688328", & + "b951b62e18f5290ac13c195130", & + "79b006f001961fb233be80d0e8", & + "56637b6dedfd6e050f06404a48", & + "e0c4bf71a15597523bbd57bde0", & + "1312231ffa04426a34a8fab038", & + "db5f6f0455d24b8358d1cbc3d8", & + "d559e31b34d21f48e1f501af30"/ diff --git a/lib/fst4/ldpc_240_101_parity.f90 b/lib/fst4/ldpc_240_101_parity.f90 index f789dd64..d3c1280c 100755 --- a/lib/fst4/ldpc_240_101_parity.f90 +++ b/lib/fst4/ldpc_240_101_parity.f90 @@ -1,393 +1,393 @@ -data Mn/ & - 57, 100, 134, & - 56, 99, 136, & - 1, 12, 15, & - 2, 23, 72, & - 3, 133, 137, & - 4, 93, 125, & - 5, 68, 139, & - 6, 38, 55, & - 7, 40, 78, & - 8, 30, 84, & - 9, 17, 122, & - 10, 34, 95, & - 11, 36, 138, & - 13, 90, 132, & - 14, 50, 117, & - 16, 57, 83, & - 18, 22, 121, & - 19, 60, 89, & - 20, 98, 107, & - 21, 37, 61, & - 24, 26, 75, & - 25, 88, 115, & - 27, 49, 127, & - 28, 74, 119, & - 29, 111, 114, & - 31, 91, 129, & - 32, 96, 104, & - 30, 33, 130, & - 35, 65, 135, & - 41, 42, 87, & - 44, 108, 131, & - 45, 94, 101, & - 45, 46, 97, & - 47, 102, 134, & - 48, 64, 104, & - 19, 51, 116, & - 20, 52, 67, & - 53, 104, 113, & - 12, 54, 103, & - 58, 66, 88, & - 62, 80, 124, & - 63, 70, 71, & - 73, 114, 123, & - 76, 85, 128, & - 77, 106, 109, & - 46, 79, 126, & - 61, 81, 110, & - 82, 92, 120, & - 86, 105, 112, & - 66, 100, 118, & - 23, 51, 136, & - 1, 40, 53, & - 2, 73, 81, & - 3, 63, 130, & - 4, 68, 136, & - 5, 60, 78, & - 6, 72, 131, & - 7, 115, 124, & - 8, 89, 120, & - 9, 15, 44, & - 10, 22, 93, & - 11, 49, 100, & - 13, 55, 80, & - 14, 76, 95, & - 16, 54, 111, & - 17, 41, 110, & - 18, 69, 139, & - 21, 24, 116, & - 25, 39, 71, & - 26, 69, 90, & - 27, 101, 133, & - 28, 64, 126, & - 29, 94, 103, & - 31, 56, 57, & - 32, 91, 102, & - 33, 35, 129, & - 34, 47, 128, & - 36, 86, 117, & - 37, 74, 75, & - 38, 79, 106, & - 42, 82, 123, & - 43, 77, 99, & - 48, 70, 92, & - 50, 109, 118, & - 52, 112, 119, & - 58, 62, 108, & - 59, 84, 134, & - 57, 65, 122, & - 67, 97, 113, & - 83, 127, 135, & - 85, 121, 125, & - 87, 132, 137, & - 96, 98, 105, & - 73, 107, 138, & - 1, 83, 89, & - 2, 41, 70, & - 3, 35, 131, & - 4, 111, 128, & - 5, 29, 99, & - 6, 25, 31, & - 7, 19, 96, & - 1, 39, 110, & - 2, 7, 117, & - 3, 49, 109, & - 4, 81, 96, & - 5, 100, 108, & - 6, 51, 124, & - 2, 20, 132, & - 8, 80, 137, & - 9, 56, 67, & - 10, 63, 102, & - 11, 16, 101, & - 12, 115, 122, & - 13, 32, 128, & - 14, 15, 130, & - 14, 70, 99, & - 11, 51, 69, & - 17, 89, 105, & - 18, 83, 99, & - 19, 44, 79, & - 20, 106, 133, & - 10, 21, 123, & - 22, 23, 61, & - 16, 22, 60, & - 24, 38, 114, & - 25, 37, 42, & - 26, 43, 52, & - 27, 68, 71, & - 28, 65, 139, & - 29, 62, 69, & - 30, 92, 126, & - 31, 78, 123, & - 13, 44, 78, & - 33, 40, 120, & - 7, 34, 119, & - 4, 35, 77, & - 12, 36, 52, & - 25, 98, 136, & - 5, 24, 133, & - 1, 80, 91, & - 33, 96, 97, & - 34, 41, 91, & - 32, 37, 117, & - 26, 72, 125, & - 19, 65, 75, & - 45, 131, 136, & - 46, 55, 70, & - 47, 48, 50, & - 6, 48, 94, & - 3, 74, 79, & - 39, 50, 126, & - 23, 118, 127, & - 21, 36, 113, & - 53, 77, 134, & - 30, 54, 55, & - 17, 46, 135, & - 9, 92, 102, & - 57, 85, 87, & - 58, 125, 138, & - 59, 76, 93, & - 60, 66, 107, & - 47, 132, 138, & - 29, 85, 131, & - 43, 73, 108, & - 64, 75, 129, & - 28, 38, 53, & - 61, 106, 122, & - 56, 71, 114, & - 27, 57, 120, & - 62, 67, 130, & - 54, 104, 118, & - 8, 68, 115, & - 72, 86, 111, & - 73, 74, 94, & - 49, 105, 113, & - 42, 86, 121, & - 40, 59, 109, & - 35, 88, 95, & - 31, 107, 112, & - 58, 64, 87, & - 68, 79, 104, & - 1, 5, 121, & - 15, 82, 93, & - 18, 88, 116, & - 82, 84, 119, & - 7, 71, 103, & - 4, 80, 94, & - 63, 81, 84, & - 66, 76, 137, & - 83, 124, 129, & - 90, 112, 116, & - 89, 111, 134, & - 6, 21, 120, & - 3, 16, 25, & - 12, 28, 131, & - 45, 95, 110, & - 17, 93, 124, & - 97, 121, 127, & - 98, 103, 135, & - 8, 99, 138, & - 41, 101, 139, & - 13, 24, 105, & - 14, 53, 107, & - 10, 64, 98, & - 11, 35, 78, & - 90, 100, 103, & - 9, 72, 101, & - 18, 74, 92, & - 15, 73, 87, & - 2, 88, 113, & - 20, 55, 85, & - 19, 67, 110, & - 26, 27, 95, & - 22, 50, 114, & - 29, 49, 81, & - 32, 52, 83, & - 30, 37, 77, & - 39, 128, 135, & - 23, 128, 130, & - 36, 76, 126, & - 33, 132, 139, & - 34, 89, 118, & - 38, 58, 127, & - 31, 54, 125, & - 40, 70, 75, & - 41, 109, 116, & - 43, 60, 63, & - 44, 84, 86, & - 42, 47, 62, & - 45, 82, 90, & - 43, 46, 91, & - 48, 112, 122, & - 51, 102, 133, & - 59, 61, 108, & - 65, 117, 137, & - 56, 66, 96, & - 59, 69, 104, & - 39, 69, 119, & - 97, 115, 123, & - 106, 111, 129/ - -data Nm/ & - 3, 52, 95, 102, 140, 182, & - 4, 53, 96, 103, 108, 210, & - 5, 54, 97, 104, 150, 194, & - 6, 55, 98, 105, 136, 187, & - 7, 56, 99, 106, 139, 182, & - 8, 57, 100, 107, 149, 193, & - 9, 58, 101, 103, 135, 186, & - 10, 59, 109, 172, 200, 0, & - 11, 60, 110, 157, 207, 0, & - 12, 61, 111, 122, 204, 0, & - 13, 62, 112, 117, 205, 0, & - 3, 39, 113, 137, 195, 0, & - 14, 63, 114, 133, 202, 0, & - 15, 64, 115, 116, 203, 0, & - 3, 60, 115, 183, 209, 0, & - 16, 65, 112, 124, 194, 0, & - 11, 66, 118, 156, 197, 0, & - 17, 67, 119, 184, 208, 0, & - 18, 36, 101, 120, 145, 212, & - 19, 37, 108, 121, 211, 0, & - 20, 68, 122, 153, 193, 0, & - 17, 61, 123, 124, 214, 0, & - 4, 51, 123, 152, 219, 0, & - 21, 68, 125, 139, 202, 0, & - 22, 69, 100, 126, 138, 194, & - 21, 70, 127, 144, 213, 0, & - 23, 71, 128, 169, 213, 0, & - 24, 72, 129, 166, 195, 0, & - 25, 73, 99, 130, 163, 215, & - 10, 28, 131, 155, 217, 0, & - 26, 74, 100, 132, 179, 224, & - 27, 75, 114, 143, 216, 0, & - 28, 76, 134, 141, 221, 0, & - 12, 77, 135, 142, 222, 0, & - 29, 76, 97, 136, 178, 205, & - 13, 78, 137, 153, 220, 0, & - 20, 79, 126, 143, 217, 0, & - 8, 80, 125, 166, 223, 0, & - 69, 102, 151, 218, 238, 0, & - 9, 52, 134, 177, 225, 0, & - 30, 66, 96, 142, 201, 226, & - 30, 81, 126, 176, 229, 0, & - 82, 127, 164, 227, 231, 0, & - 31, 60, 120, 133, 228, 0, & - 32, 33, 146, 196, 230, 0, & - 33, 46, 147, 156, 231, 0, & - 34, 77, 148, 162, 229, 0, & - 35, 83, 148, 149, 232, 0, & - 23, 62, 104, 175, 215, 0, & - 15, 84, 148, 151, 214, 0, & - 36, 51, 107, 117, 233, 0, & - 37, 85, 127, 137, 216, 0, & - 38, 52, 154, 166, 203, 0, & - 39, 65, 155, 171, 224, 0, & - 8, 63, 147, 155, 211, 0, & - 2, 74, 110, 168, 236, 0, & - 1, 16, 74, 88, 158, 169, & - 40, 86, 159, 180, 223, 0, & - 87, 160, 177, 234, 237, 0, & - 18, 56, 124, 161, 227, 0, & - 20, 47, 123, 167, 234, 0, & - 41, 86, 130, 170, 229, 0, & - 42, 54, 111, 188, 227, 0, & - 35, 72, 165, 180, 204, 0, & - 29, 88, 129, 145, 235, 0, & - 40, 50, 161, 189, 236, 0, & - 37, 89, 110, 170, 212, 0, & - 7, 55, 128, 172, 181, 0, & - 67, 70, 117, 130, 237, 238, & - 42, 83, 96, 116, 147, 225, & - 42, 69, 128, 168, 186, 0, & - 4, 57, 144, 173, 207, 0, & - 43, 53, 94, 164, 174, 209, & - 24, 79, 150, 174, 208, 0, & - 21, 79, 145, 165, 225, 0, & - 44, 64, 160, 189, 220, 0, & - 45, 82, 136, 154, 217, 0, & - 9, 56, 132, 133, 205, 0, & - 46, 80, 120, 150, 181, 0, & - 41, 63, 109, 140, 187, 0, & - 47, 53, 105, 188, 215, 0, & - 48, 81, 183, 185, 230, 0, & - 16, 90, 95, 119, 190, 216, & - 10, 87, 185, 188, 228, 0, & - 44, 91, 158, 163, 211, 0, & - 49, 78, 173, 176, 228, 0, & - 30, 92, 158, 180, 209, 0, & - 22, 40, 178, 184, 210, 0, & - 18, 59, 95, 118, 192, 222, & - 14, 70, 191, 206, 230, 0, & - 26, 75, 140, 142, 231, 0, & - 48, 83, 131, 157, 208, 0, & - 6, 61, 160, 183, 197, 0, & - 32, 73, 149, 174, 187, 0, & - 12, 64, 178, 196, 213, 0, & - 27, 93, 101, 105, 141, 236, & - 33, 89, 141, 198, 239, 0, & - 19, 93, 138, 199, 204, 0, & - 2, 82, 99, 116, 119, 200, & - 1, 50, 62, 106, 206, 0, & - 32, 71, 112, 201, 207, 0, & - 34, 75, 111, 157, 233, 0, & - 39, 73, 186, 199, 206, 0, & - 27, 35, 38, 171, 181, 237, & - 49, 93, 118, 175, 202, 0, & - 45, 80, 121, 167, 240, 0, & - 19, 94, 161, 179, 203, 0, & - 31, 86, 106, 164, 234, 0, & - 45, 84, 104, 177, 226, 0, & - 47, 66, 102, 196, 212, 0, & - 25, 65, 98, 173, 192, 240, & - 49, 85, 179, 191, 232, 0, & - 38, 89, 153, 175, 210, 0, & - 25, 43, 125, 168, 214, 0, & - 22, 58, 113, 172, 239, 0, & - 36, 68, 184, 191, 226, 0, & - 15, 78, 103, 143, 235, 0, & - 50, 84, 152, 171, 222, 0, & - 24, 85, 135, 185, 238, 0, & - 48, 59, 134, 169, 193, 0, & - 17, 91, 176, 182, 198, 0, & - 11, 88, 113, 167, 232, 0, & - 43, 81, 122, 132, 239, 0, & - 41, 58, 107, 190, 197, 0, & - 6, 91, 144, 159, 224, 0, & - 46, 72, 131, 151, 220, 0, & - 23, 90, 152, 198, 223, 0, & - 44, 77, 98, 114, 218, 219, & - 26, 76, 165, 190, 240, 0, & - 28, 54, 115, 170, 219, 0, & - 31, 57, 97, 146, 163, 195, & - 14, 92, 108, 162, 221, 0, & - 5, 71, 121, 139, 233, 0, & - 1, 34, 87, 154, 192, 0, & - 29, 90, 156, 199, 218, 0, & - 2, 51, 55, 138, 146, 0, & - 5, 92, 109, 189, 235, 0, & - 13, 94, 159, 162, 200, 0, & - 7, 67, 129, 201, 221, 0/ - -data nrw/ & -6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,6,5, & -5,5,5,5,6,5,5,5,6,5,6,5,5,5,6,5,5,5,5,5, & -6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,5,5,5, & -5,5,5,5,5,5,5,5,6,6,5,5,6,5,5,5,5,5,5,5, & -5,5,6,5,5,5,5,5,6,5,5,5,5,5,5,6,5,5,6,5, & -5,5,5,6,5,5,5,5,5,5,6,5,5,5,5,5,5,5,5,5, & -5,5,5,5,5,5,5,6,5,5,6,5,5,5,5,5,5,5,5/ - -ncw=3 +data Mn/ & + 57, 100, 134, & + 56, 99, 136, & + 1, 12, 15, & + 2, 23, 72, & + 3, 133, 137, & + 4, 93, 125, & + 5, 68, 139, & + 6, 38, 55, & + 7, 40, 78, & + 8, 30, 84, & + 9, 17, 122, & + 10, 34, 95, & + 11, 36, 138, & + 13, 90, 132, & + 14, 50, 117, & + 16, 57, 83, & + 18, 22, 121, & + 19, 60, 89, & + 20, 98, 107, & + 21, 37, 61, & + 24, 26, 75, & + 25, 88, 115, & + 27, 49, 127, & + 28, 74, 119, & + 29, 111, 114, & + 31, 91, 129, & + 32, 96, 104, & + 30, 33, 130, & + 35, 65, 135, & + 41, 42, 87, & + 44, 108, 131, & + 45, 94, 101, & + 45, 46, 97, & + 47, 102, 134, & + 48, 64, 104, & + 19, 51, 116, & + 20, 52, 67, & + 53, 104, 113, & + 12, 54, 103, & + 58, 66, 88, & + 62, 80, 124, & + 63, 70, 71, & + 73, 114, 123, & + 76, 85, 128, & + 77, 106, 109, & + 46, 79, 126, & + 61, 81, 110, & + 82, 92, 120, & + 86, 105, 112, & + 66, 100, 118, & + 23, 51, 136, & + 1, 40, 53, & + 2, 73, 81, & + 3, 63, 130, & + 4, 68, 136, & + 5, 60, 78, & + 6, 72, 131, & + 7, 115, 124, & + 8, 89, 120, & + 9, 15, 44, & + 10, 22, 93, & + 11, 49, 100, & + 13, 55, 80, & + 14, 76, 95, & + 16, 54, 111, & + 17, 41, 110, & + 18, 69, 139, & + 21, 24, 116, & + 25, 39, 71, & + 26, 69, 90, & + 27, 101, 133, & + 28, 64, 126, & + 29, 94, 103, & + 31, 56, 57, & + 32, 91, 102, & + 33, 35, 129, & + 34, 47, 128, & + 36, 86, 117, & + 37, 74, 75, & + 38, 79, 106, & + 42, 82, 123, & + 43, 77, 99, & + 48, 70, 92, & + 50, 109, 118, & + 52, 112, 119, & + 58, 62, 108, & + 59, 84, 134, & + 57, 65, 122, & + 67, 97, 113, & + 83, 127, 135, & + 85, 121, 125, & + 87, 132, 137, & + 96, 98, 105, & + 73, 107, 138, & + 1, 83, 89, & + 2, 41, 70, & + 3, 35, 131, & + 4, 111, 128, & + 5, 29, 99, & + 6, 25, 31, & + 7, 19, 96, & + 1, 39, 110, & + 2, 7, 117, & + 3, 49, 109, & + 4, 81, 96, & + 5, 100, 108, & + 6, 51, 124, & + 2, 20, 132, & + 8, 80, 137, & + 9, 56, 67, & + 10, 63, 102, & + 11, 16, 101, & + 12, 115, 122, & + 13, 32, 128, & + 14, 15, 130, & + 14, 70, 99, & + 11, 51, 69, & + 17, 89, 105, & + 18, 83, 99, & + 19, 44, 79, & + 20, 106, 133, & + 10, 21, 123, & + 22, 23, 61, & + 16, 22, 60, & + 24, 38, 114, & + 25, 37, 42, & + 26, 43, 52, & + 27, 68, 71, & + 28, 65, 139, & + 29, 62, 69, & + 30, 92, 126, & + 31, 78, 123, & + 13, 44, 78, & + 33, 40, 120, & + 7, 34, 119, & + 4, 35, 77, & + 12, 36, 52, & + 25, 98, 136, & + 5, 24, 133, & + 1, 80, 91, & + 33, 96, 97, & + 34, 41, 91, & + 32, 37, 117, & + 26, 72, 125, & + 19, 65, 75, & + 45, 131, 136, & + 46, 55, 70, & + 47, 48, 50, & + 6, 48, 94, & + 3, 74, 79, & + 39, 50, 126, & + 23, 118, 127, & + 21, 36, 113, & + 53, 77, 134, & + 30, 54, 55, & + 17, 46, 135, & + 9, 92, 102, & + 57, 85, 87, & + 58, 125, 138, & + 59, 76, 93, & + 60, 66, 107, & + 47, 132, 138, & + 29, 85, 131, & + 43, 73, 108, & + 64, 75, 129, & + 28, 38, 53, & + 61, 106, 122, & + 56, 71, 114, & + 27, 57, 120, & + 62, 67, 130, & + 54, 104, 118, & + 8, 68, 115, & + 72, 86, 111, & + 73, 74, 94, & + 49, 105, 113, & + 42, 86, 121, & + 40, 59, 109, & + 35, 88, 95, & + 31, 107, 112, & + 58, 64, 87, & + 68, 79, 104, & + 1, 5, 121, & + 15, 82, 93, & + 18, 88, 116, & + 82, 84, 119, & + 7, 71, 103, & + 4, 80, 94, & + 63, 81, 84, & + 66, 76, 137, & + 83, 124, 129, & + 90, 112, 116, & + 89, 111, 134, & + 6, 21, 120, & + 3, 16, 25, & + 12, 28, 131, & + 45, 95, 110, & + 17, 93, 124, & + 97, 121, 127, & + 98, 103, 135, & + 8, 99, 138, & + 41, 101, 139, & + 13, 24, 105, & + 14, 53, 107, & + 10, 64, 98, & + 11, 35, 78, & + 90, 100, 103, & + 9, 72, 101, & + 18, 74, 92, & + 15, 73, 87, & + 2, 88, 113, & + 20, 55, 85, & + 19, 67, 110, & + 26, 27, 95, & + 22, 50, 114, & + 29, 49, 81, & + 32, 52, 83, & + 30, 37, 77, & + 39, 128, 135, & + 23, 128, 130, & + 36, 76, 126, & + 33, 132, 139, & + 34, 89, 118, & + 38, 58, 127, & + 31, 54, 125, & + 40, 70, 75, & + 41, 109, 116, & + 43, 60, 63, & + 44, 84, 86, & + 42, 47, 62, & + 45, 82, 90, & + 43, 46, 91, & + 48, 112, 122, & + 51, 102, 133, & + 59, 61, 108, & + 65, 117, 137, & + 56, 66, 96, & + 59, 69, 104, & + 39, 69, 119, & + 97, 115, 123, & + 106, 111, 129/ + +data Nm/ & + 3, 52, 95, 102, 140, 182, & + 4, 53, 96, 103, 108, 210, & + 5, 54, 97, 104, 150, 194, & + 6, 55, 98, 105, 136, 187, & + 7, 56, 99, 106, 139, 182, & + 8, 57, 100, 107, 149, 193, & + 9, 58, 101, 103, 135, 186, & + 10, 59, 109, 172, 200, 0, & + 11, 60, 110, 157, 207, 0, & + 12, 61, 111, 122, 204, 0, & + 13, 62, 112, 117, 205, 0, & + 3, 39, 113, 137, 195, 0, & + 14, 63, 114, 133, 202, 0, & + 15, 64, 115, 116, 203, 0, & + 3, 60, 115, 183, 209, 0, & + 16, 65, 112, 124, 194, 0, & + 11, 66, 118, 156, 197, 0, & + 17, 67, 119, 184, 208, 0, & + 18, 36, 101, 120, 145, 212, & + 19, 37, 108, 121, 211, 0, & + 20, 68, 122, 153, 193, 0, & + 17, 61, 123, 124, 214, 0, & + 4, 51, 123, 152, 219, 0, & + 21, 68, 125, 139, 202, 0, & + 22, 69, 100, 126, 138, 194, & + 21, 70, 127, 144, 213, 0, & + 23, 71, 128, 169, 213, 0, & + 24, 72, 129, 166, 195, 0, & + 25, 73, 99, 130, 163, 215, & + 10, 28, 131, 155, 217, 0, & + 26, 74, 100, 132, 179, 224, & + 27, 75, 114, 143, 216, 0, & + 28, 76, 134, 141, 221, 0, & + 12, 77, 135, 142, 222, 0, & + 29, 76, 97, 136, 178, 205, & + 13, 78, 137, 153, 220, 0, & + 20, 79, 126, 143, 217, 0, & + 8, 80, 125, 166, 223, 0, & + 69, 102, 151, 218, 238, 0, & + 9, 52, 134, 177, 225, 0, & + 30, 66, 96, 142, 201, 226, & + 30, 81, 126, 176, 229, 0, & + 82, 127, 164, 227, 231, 0, & + 31, 60, 120, 133, 228, 0, & + 32, 33, 146, 196, 230, 0, & + 33, 46, 147, 156, 231, 0, & + 34, 77, 148, 162, 229, 0, & + 35, 83, 148, 149, 232, 0, & + 23, 62, 104, 175, 215, 0, & + 15, 84, 148, 151, 214, 0, & + 36, 51, 107, 117, 233, 0, & + 37, 85, 127, 137, 216, 0, & + 38, 52, 154, 166, 203, 0, & + 39, 65, 155, 171, 224, 0, & + 8, 63, 147, 155, 211, 0, & + 2, 74, 110, 168, 236, 0, & + 1, 16, 74, 88, 158, 169, & + 40, 86, 159, 180, 223, 0, & + 87, 160, 177, 234, 237, 0, & + 18, 56, 124, 161, 227, 0, & + 20, 47, 123, 167, 234, 0, & + 41, 86, 130, 170, 229, 0, & + 42, 54, 111, 188, 227, 0, & + 35, 72, 165, 180, 204, 0, & + 29, 88, 129, 145, 235, 0, & + 40, 50, 161, 189, 236, 0, & + 37, 89, 110, 170, 212, 0, & + 7, 55, 128, 172, 181, 0, & + 67, 70, 117, 130, 237, 238, & + 42, 83, 96, 116, 147, 225, & + 42, 69, 128, 168, 186, 0, & + 4, 57, 144, 173, 207, 0, & + 43, 53, 94, 164, 174, 209, & + 24, 79, 150, 174, 208, 0, & + 21, 79, 145, 165, 225, 0, & + 44, 64, 160, 189, 220, 0, & + 45, 82, 136, 154, 217, 0, & + 9, 56, 132, 133, 205, 0, & + 46, 80, 120, 150, 181, 0, & + 41, 63, 109, 140, 187, 0, & + 47, 53, 105, 188, 215, 0, & + 48, 81, 183, 185, 230, 0, & + 16, 90, 95, 119, 190, 216, & + 10, 87, 185, 188, 228, 0, & + 44, 91, 158, 163, 211, 0, & + 49, 78, 173, 176, 228, 0, & + 30, 92, 158, 180, 209, 0, & + 22, 40, 178, 184, 210, 0, & + 18, 59, 95, 118, 192, 222, & + 14, 70, 191, 206, 230, 0, & + 26, 75, 140, 142, 231, 0, & + 48, 83, 131, 157, 208, 0, & + 6, 61, 160, 183, 197, 0, & + 32, 73, 149, 174, 187, 0, & + 12, 64, 178, 196, 213, 0, & + 27, 93, 101, 105, 141, 236, & + 33, 89, 141, 198, 239, 0, & + 19, 93, 138, 199, 204, 0, & + 2, 82, 99, 116, 119, 200, & + 1, 50, 62, 106, 206, 0, & + 32, 71, 112, 201, 207, 0, & + 34, 75, 111, 157, 233, 0, & + 39, 73, 186, 199, 206, 0, & + 27, 35, 38, 171, 181, 237, & + 49, 93, 118, 175, 202, 0, & + 45, 80, 121, 167, 240, 0, & + 19, 94, 161, 179, 203, 0, & + 31, 86, 106, 164, 234, 0, & + 45, 84, 104, 177, 226, 0, & + 47, 66, 102, 196, 212, 0, & + 25, 65, 98, 173, 192, 240, & + 49, 85, 179, 191, 232, 0, & + 38, 89, 153, 175, 210, 0, & + 25, 43, 125, 168, 214, 0, & + 22, 58, 113, 172, 239, 0, & + 36, 68, 184, 191, 226, 0, & + 15, 78, 103, 143, 235, 0, & + 50, 84, 152, 171, 222, 0, & + 24, 85, 135, 185, 238, 0, & + 48, 59, 134, 169, 193, 0, & + 17, 91, 176, 182, 198, 0, & + 11, 88, 113, 167, 232, 0, & + 43, 81, 122, 132, 239, 0, & + 41, 58, 107, 190, 197, 0, & + 6, 91, 144, 159, 224, 0, & + 46, 72, 131, 151, 220, 0, & + 23, 90, 152, 198, 223, 0, & + 44, 77, 98, 114, 218, 219, & + 26, 76, 165, 190, 240, 0, & + 28, 54, 115, 170, 219, 0, & + 31, 57, 97, 146, 163, 195, & + 14, 92, 108, 162, 221, 0, & + 5, 71, 121, 139, 233, 0, & + 1, 34, 87, 154, 192, 0, & + 29, 90, 156, 199, 218, 0, & + 2, 51, 55, 138, 146, 0, & + 5, 92, 109, 189, 235, 0, & + 13, 94, 159, 162, 200, 0, & + 7, 67, 129, 201, 221, 0/ + +data nrw/ & +6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,6,5, & +5,5,5,5,6,5,5,5,6,5,6,5,5,5,6,5,5,5,5,5, & +6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,5,5,5, & +5,5,5,5,5,5,5,5,6,6,5,5,6,5,5,5,5,5,5,5, & +5,5,6,5,5,5,5,5,6,5,5,5,5,5,5,6,5,5,6,5, & +5,5,5,6,5,5,5,5,5,5,6,5,5,5,5,5,5,5,5,5, & +5,5,5,5,5,5,5,6,5,5,6,5,5,5,5,5,5,5,5/ + +ncw=3 diff --git a/lib/fst4/ldpc_240_74_generator.f90 b/lib/fst4/ldpc_240_74_generator.f90 index 653ef54a..0cd5db01 100755 --- a/lib/fst4/ldpc_240_74_generator.f90 +++ b/lib/fst4/ldpc_240_74_generator.f90 @@ -1,170 +1,170 @@ -character*19 g(166) - -data g/ & - "de8b3201e3c59f55a14", & - "2e06d352ebc5b74c4fc", & - "2e16d6cf5a725c3244c", & - "84f5587edca6d777de4", & - "e152b1e2b5965093ecc", & - "244b4828a2ccf2b5f58", & - "5fbbaade810e123c730", & - "6b7e92a99a918df3d44", & - "bbcec6a63ab757a7278", & - "f5f3f0b89a21ceccdb0", & - "a248c5f1ec2bc816290", & - "c84bbad839a5fe76d0c", & - "ad724129bbf4c7f4570", & - "91adb56e7623a2575cc", & - "cbe995bdf156df2c9e4", & - "92ff6ea492c08c150e0", & - "c4ddbe5a02f6a933384", & - "d2e9befc131dc483858", & - "68567543d1eebcb080c", & - "21fa61d559f9baf6abc", & - "911c4fbbafc72e3db28", & - "7c0b534af4b7d583d50", & - "12ce371b90ee9dfe72c", & - "15a604148872e251ec4", & - "3a3c9f3eb0e0f96edc0", & - "705919ffb636f96b390", & - "43daaaa8163d6bc2bd4", & - "96e11ea798b74b10e98", & - "811150609c9dee8230c", & - "be713f85ab34380f4b0", & - "5a02c4abaaccb8f24c4", & - "67bdebb8863d04768cc", & - "5a449cd90c3dbdfe844", & - "9c7a54d1c4ef7418b84", & - "cd82fefaaf9cd28cd8c", & - "ca47e847fabb0054a38", & - "f0b30cef6aab9e37f98", & - "d948d912fbcc1708710", & - "cce1a7b355053d98270", & - "4cf227c225a9063dd48", & - "2db92612e9ba1418e24", & - "3d215c04c762c3d6a28", & - "77de65500b5624ceb0c", & - "fd1a1df99ded2fb9d88", & - "2a19392c71438410fb8", & - "a9b486a9d26ed579754", & - "b698d244ac78d97a498", & - "3d7975b74d727a5e704", & - "38094225a2bce0e1940", & - "3d3e58fae40fac342b0", & - "7732e839a066e337714", & - "69356c082b7753a47b0", & - "3e868a55dc403a802ac", & - "a0157a14a6bf7fdbbcc", & - "1ab628e11a7ab4a7c44", & - "9da3a2247d7449052f4", & - "199a8a7b114816b97f4", & - "b1c5cde2542061704cc", & - "432fa8d3a153eafbdc8", & - "c4ece7e400d8a89c448", & - "316ecf74e4b983f007c", & - "6a14fa8e713bb5e8adc", & - "da4b957ded8374e3640", & - "0a804dba7c7e4533300", & - "52c342ed033f86580e0", & - "1667da8d6fcf4272470", & - "da2f7038d550fa88d8c", & - "685bcbab1d9dd2c2a44", & - "4c93008b3156b3636bc", & - "726998d6327ac797c3c", & - "44ece7e400d8a8dc448", & - "01f9add00dfe823a948", & - "dbb95f5ce9e371ad720", & - "fc746ee5c76827a8728", & - "b25408029506467f4b4", & - "9b5c9219e21126b7cf8", & - "39ae9f48ba9d1a24f04", & - "7de2699623eb507f938", & - "b9c6e903ee91dd32934", & - "397510d2c6cb5e81de8", & - "20157a14aebf7fdbbec", & - "067f76ea5817a465980", & - "9248f3cea0869feb994", & - "23cde2678004ebe5f80", & - "5b81fe6848f58e3cfa8", & - "a9099ace96bff092904", & - "4afa4b0802b33215438", & - "f4f740396b030360858", & - "fc613f77a35ee1163b8", & - "1a4dc27d7e8cc835ff4", & - "e9b056f153b39def7ec", & - "b62eb777a2f953c7efc", & - "388ae4de514b62d238c", & - "891529af40e85317160", & - "474f1afeb724dbd2ba8", & - "11d70880fd88fdd307c", & - "29f26a3acb76e6a517c", & - "df3e902ff9cadcf776c", & - "e3c42da8445965c09f0", & - "ce277a6aeccc316dc58", & - "4d7841fb71543abd9b8", & - "e63230d2d465fb44750", & - "b6e11fa798b74b14e98", & - "05f189d37c5616547b4", & - "ebdb51a81d1e883baa8", & - "bf5bc736663bcd53ae0", & - "2f8d1cc0936142c08fc", & - "436b22fc36d917b6928", & - "044b482822ccf2b5f58", & - "37b2e839a066e3b7714", & - "2a9b4b765c581f0c51c", & - "10a7d44cecf8e6628dc", & - "ad95f02df6d5502dd4c", & - "bbd34f8afd63deaf564", & - "cabddfeb01fce632788", & - "66b57babeedd6124114", & - "7813e0454fbd462be8c", & - "b6105ed6f01ea621d04", & - "9f68bbcec679d1c088c", & - "673da96e414fc7a0f40", & - "5568adb935e11084abc", & - "f6dd308de5e5c4f6fb0", & - "3b49e80d40ae596c7b4", & - "a3cde2478004ebe5f80", & - "dd8e4f309e919d5ed94", & - "5a4020d387757d7bc28", & - "64f9e02ae32362a255c", & - "630d5942d392334b0dc", & - "0bd7e9f4229b2dee210", & - "bca549a9467d3a2550c", & - "2fef7b1f578c5e28d04", & - "f35e0fdda1be4b3b35c", & - "69ed575e7cc537d2394", & - "7dfdcfbfd5ef3093680", & - "b3b2921af97f251d328", & - "5622d0fe90363522364", & - "fcd4fc7fa04a69d2ac4", & - "1119ea451502ed9ab34", & - "970ee777ec969a41754", & - "688d14f8afec76783dc", & - "4d0b8a1028578407420", & - "d3d2138d9fa268da3e8", & - "df1bdbff898e006394c", & - "8ac478a916bb0b77684", & - "93881997428e2c17a94", & - "4aa510e746245e90c08", & - "e00cb8543f85a5d58b8", & - "9100d8eb74031073044", & - "38710e4235bd1e4003c", & - "6aef311cac4c4dccfd4", & - "58430f577f51c36b3e0", & - "12082fa5d4268a95b4c", & - "7a7435a0aca071e64d0", & - "cd8250ebadc95de15b0", & - "debad40c852e99d64dc", & - "4e6caa5e7c86efef748", & - "a5d4cbb97e726e3c580", & - "7e3a0a2c73ef8553640", & - "b60bfc2fd2bd8f530dc", & - "32dbef097a5f84b0318", & - "4cc7c1cf434300be380", & - "896840945be8eabf7f0", & - "36c9b10ec694819a0a0", & - "349f46a799ef95a47c8", & - "9bdcd4ce2563e560b74", & - "b19fcd7111a335c52ec"/ - +character*19 g(166) + +data g/ & + "de8b3201e3c59f55a14", & + "2e06d352ebc5b74c4fc", & + "2e16d6cf5a725c3244c", & + "84f5587edca6d777de4", & + "e152b1e2b5965093ecc", & + "244b4828a2ccf2b5f58", & + "5fbbaade810e123c730", & + "6b7e92a99a918df3d44", & + "bbcec6a63ab757a7278", & + "f5f3f0b89a21ceccdb0", & + "a248c5f1ec2bc816290", & + "c84bbad839a5fe76d0c", & + "ad724129bbf4c7f4570", & + "91adb56e7623a2575cc", & + "cbe995bdf156df2c9e4", & + "92ff6ea492c08c150e0", & + "c4ddbe5a02f6a933384", & + "d2e9befc131dc483858", & + "68567543d1eebcb080c", & + "21fa61d559f9baf6abc", & + "911c4fbbafc72e3db28", & + "7c0b534af4b7d583d50", & + "12ce371b90ee9dfe72c", & + "15a604148872e251ec4", & + "3a3c9f3eb0e0f96edc0", & + "705919ffb636f96b390", & + "43daaaa8163d6bc2bd4", & + "96e11ea798b74b10e98", & + "811150609c9dee8230c", & + "be713f85ab34380f4b0", & + "5a02c4abaaccb8f24c4", & + "67bdebb8863d04768cc", & + "5a449cd90c3dbdfe844", & + "9c7a54d1c4ef7418b84", & + "cd82fefaaf9cd28cd8c", & + "ca47e847fabb0054a38", & + "f0b30cef6aab9e37f98", & + "d948d912fbcc1708710", & + "cce1a7b355053d98270", & + "4cf227c225a9063dd48", & + "2db92612e9ba1418e24", & + "3d215c04c762c3d6a28", & + "77de65500b5624ceb0c", & + "fd1a1df99ded2fb9d88", & + "2a19392c71438410fb8", & + "a9b486a9d26ed579754", & + "b698d244ac78d97a498", & + "3d7975b74d727a5e704", & + "38094225a2bce0e1940", & + "3d3e58fae40fac342b0", & + "7732e839a066e337714", & + "69356c082b7753a47b0", & + "3e868a55dc403a802ac", & + "a0157a14a6bf7fdbbcc", & + "1ab628e11a7ab4a7c44", & + "9da3a2247d7449052f4", & + "199a8a7b114816b97f4", & + "b1c5cde2542061704cc", & + "432fa8d3a153eafbdc8", & + "c4ece7e400d8a89c448", & + "316ecf74e4b983f007c", & + "6a14fa8e713bb5e8adc", & + "da4b957ded8374e3640", & + "0a804dba7c7e4533300", & + "52c342ed033f86580e0", & + "1667da8d6fcf4272470", & + "da2f7038d550fa88d8c", & + "685bcbab1d9dd2c2a44", & + "4c93008b3156b3636bc", & + "726998d6327ac797c3c", & + "44ece7e400d8a8dc448", & + "01f9add00dfe823a948", & + "dbb95f5ce9e371ad720", & + "fc746ee5c76827a8728", & + "b25408029506467f4b4", & + "9b5c9219e21126b7cf8", & + "39ae9f48ba9d1a24f04", & + "7de2699623eb507f938", & + "b9c6e903ee91dd32934", & + "397510d2c6cb5e81de8", & + "20157a14aebf7fdbbec", & + "067f76ea5817a465980", & + "9248f3cea0869feb994", & + "23cde2678004ebe5f80", & + "5b81fe6848f58e3cfa8", & + "a9099ace96bff092904", & + "4afa4b0802b33215438", & + "f4f740396b030360858", & + "fc613f77a35ee1163b8", & + "1a4dc27d7e8cc835ff4", & + "e9b056f153b39def7ec", & + "b62eb777a2f953c7efc", & + "388ae4de514b62d238c", & + "891529af40e85317160", & + "474f1afeb724dbd2ba8", & + "11d70880fd88fdd307c", & + "29f26a3acb76e6a517c", & + "df3e902ff9cadcf776c", & + "e3c42da8445965c09f0", & + "ce277a6aeccc316dc58", & + "4d7841fb71543abd9b8", & + "e63230d2d465fb44750", & + "b6e11fa798b74b14e98", & + "05f189d37c5616547b4", & + "ebdb51a81d1e883baa8", & + "bf5bc736663bcd53ae0", & + "2f8d1cc0936142c08fc", & + "436b22fc36d917b6928", & + "044b482822ccf2b5f58", & + "37b2e839a066e3b7714", & + "2a9b4b765c581f0c51c", & + "10a7d44cecf8e6628dc", & + "ad95f02df6d5502dd4c", & + "bbd34f8afd63deaf564", & + "cabddfeb01fce632788", & + "66b57babeedd6124114", & + "7813e0454fbd462be8c", & + "b6105ed6f01ea621d04", & + "9f68bbcec679d1c088c", & + "673da96e414fc7a0f40", & + "5568adb935e11084abc", & + "f6dd308de5e5c4f6fb0", & + "3b49e80d40ae596c7b4", & + "a3cde2478004ebe5f80", & + "dd8e4f309e919d5ed94", & + "5a4020d387757d7bc28", & + "64f9e02ae32362a255c", & + "630d5942d392334b0dc", & + "0bd7e9f4229b2dee210", & + "bca549a9467d3a2550c", & + "2fef7b1f578c5e28d04", & + "f35e0fdda1be4b3b35c", & + "69ed575e7cc537d2394", & + "7dfdcfbfd5ef3093680", & + "b3b2921af97f251d328", & + "5622d0fe90363522364", & + "fcd4fc7fa04a69d2ac4", & + "1119ea451502ed9ab34", & + "970ee777ec969a41754", & + "688d14f8afec76783dc", & + "4d0b8a1028578407420", & + "d3d2138d9fa268da3e8", & + "df1bdbff898e006394c", & + "8ac478a916bb0b77684", & + "93881997428e2c17a94", & + "4aa510e746245e90c08", & + "e00cb8543f85a5d58b8", & + "9100d8eb74031073044", & + "38710e4235bd1e4003c", & + "6aef311cac4c4dccfd4", & + "58430f577f51c36b3e0", & + "12082fa5d4268a95b4c", & + "7a7435a0aca071e64d0", & + "cd8250ebadc95de15b0", & + "debad40c852e99d64dc", & + "4e6caa5e7c86efef748", & + "a5d4cbb97e726e3c580", & + "7e3a0a2c73ef8553640", & + "b60bfc2fd2bd8f530dc", & + "32dbef097a5f84b0318", & + "4cc7c1cf434300be380", & + "896840945be8eabf7f0", & + "36c9b10ec694819a0a0", & + "349f46a799ef95a47c8", & + "9bdcd4ce2563e560b74", & + "b19fcd7111a335c52ec"/ + diff --git a/lib/fst4/ldpc_240_74_parity.f90 b/lib/fst4/ldpc_240_74_parity.f90 index efe4320d..6d41fde5 100755 --- a/lib/fst4/ldpc_240_74_parity.f90 +++ b/lib/fst4/ldpc_240_74_parity.f90 @@ -1,423 +1,423 @@ -data Mn/ & - 84, 101, 144, & - 10, 14, 138, & - 87, 148, 166, & - 1, 50, 67, & - 2, 53, 74, & - 3, 83, 113, & - 4, 90, 121, & - 5, 63, 128, & - 6, 124, 138, & - 8, 22, 108, & - 11, 28, 159, & - 12, 18, 142, & - 13, 24, 145, & - 15, 131, 149, & - 16, 44, 93, & - 17, 41, 47, & - 19, 37, 129, & - 20, 33, 94, & - 21, 100, 154, & - 23, 71, 141, & - 25, 89, 95, & - 26, 105, 153, & - 27, 36, 58, & - 29, 59, 166, & - 30, 52, 126, & - 31, 61, 77, & - 32, 84, 111, & - 34, 97, 155, & - 38, 98, 127, & - 39, 76, 143, & - 40, 55, 92, & - 42, 147, 158, & - 43, 82, 148, & - 45, 49, 109, & - 46, 70, 86, & - 48, 78, 139, & - 51, 101, 104, & - 54, 63, 96, & - 56, 81, 125, & - 57, 117, 164, & - 60, 75, 107, & - 39, 62, 132, & - 64, 110, 118, & - 24, 65, 146, & - 66, 80, 134, & - 68, 91, 114, & - 69, 123, 162, & - 72, 88, 152, & - 79, 99, 130, & - 85, 112, 124, & - 99, 103, 157, & - 106, 115, 133, & - 116, 120, 140, & - 119, 161, 165, & - 64, 122, 137, & - 34, 89, 135, & - 136, 138, 163, & - 93, 144, 159, & - 35, 130, 150, & - 62, 151, 164, & - 104, 153, 160, & - 1, 106, 166, & - 2, 132, 152, & - 3, 11, 105, & - 4, 18, 160, & - 5, 53, 91, & - 6, 109, 141, & - 7, 111, 113, & - 8, 54, 136, & - 9, 61, 92, & - 10, 40, 101, & - 12, 30, 146, & - 13, 37, 82, & - 14, 29, 95, & - 1, 47, 131, & - 2, 8, 139, & - 3, 58, 130, & - 4, 96, 115, & - 5, 119, 129, & - 6, 60, 148, & - 7, 95, 163, & - 2, 35, 56, & - 9, 67, 79, & - 10, 75, 122, & - 11, 17, 121, & - 12, 137, 145, & - 13, 36, 152, & - 14, 15, 155, & - 15, 134, 143, & - 16, 106, 125, & - 11, 106, 157, & - 18, 99, 118, & - 19, 50, 94, & - 20, 126, 158, & - 21, 41, 135, & - 22, 24, 71, & - 23, 42, 136, & - 22, 109, 161, & - 25, 39, 46, & - 26, 45, 55, & - 27, 77, 82, & - 28, 73, 166, & - 29, 69, 76, & - 30, 108, 150, & - 31, 91, 146, & - 14, 32, 147, & - 33, 35, 107, & - 34, 103, 111, & - 8, 94, 122, & - 13, 70, 151, & - 32, 37, 142, & - 3, 38, 87, & - 25, 51, 92, & - 40, 57, 72, & - 21, 108, 153, & - 23, 26, 142, & - 43, 44, 48, & - 30, 43, 62, & - 7, 45, 154, & - 16, 46, 149, & - 1, 53, 75, & - 33, 44, 160, & - 49, 86, 157, & - 19, 80, 159, & - 51, 116, 138, & - 52, 92, 98, & - 6, 12, 47, & - 54, 83, 101, & - 24, 55, 102, & - 56, 63, 120, & - 17, 57, 82, & - 38, 154, 162, & - 59, 74, 151, & - 53, 144, 164, & - 61, 85, 117, & - 62, 66, 90, & - 48, 113, 145, & - 64, 65, 128, & - 27, 29, 65, & - 58, 63, 134, & - 9, 74, 83, & - 68, 109, 113, & - 41, 61, 69, & - 36, 60, 155, & - 42, 64, 144, & - 40, 90, 130, & - 28, 110, 135, & - 20, 59, 112, & - 70, 110, 124, & - 54, 76, 105, & - 4, 77, 111, & - 78, 104, 143, & - 66, 67, 91, & - 80, 81, 88, & - 50, 101, 132, & - 71, 97, 120, & - 72, 131, 158, & - 84, 133, 141, & - 5, 85, 99, & - 49, 89, 133, & - 87, 132, 140, & - 34, 88, 104, & - 89, 105, 147, & - 6, 76, 102, & - 18, 31, 163, & - 52, 96, 140, & - 93, 102, 165, & - 79, 104, 165, & - 81, 100, 126, & - 95, 121, 152, & - 97, 123, 153, & - 37, 98, 114, & - 8, 91, 155, & - 100, 114, 160, & - 2, 26, 28, & - 93, 116, 150, & - 68, 103, 166, & - 78, 117, 125, & - 86, 107, 127, & - 4, 59, 136, & - 9, 37, 97, & - 7, 30, 75, & - 80, 148, 153, & - 73, 138, 164, & - 10, 39, 103, & - 39, 146, 156, & - 48, 129, 136, & - 5, 17, 51, & - 112, 149, 161, & - 11, 24, 126, & - 1, 70, 78, & - 14, 113, 118, & - 10, 119, 141, & - 13, 33, 105, & - 19, 57, 89, & - 12, 25, 56, & - 16, 18, 54, & - 84, 124, 162, & - 20, 41, 134, & - 15, 45, 82, & - 115, 118, 123, & - 128, 139, 149, & - 127, 156, 159, & - 21, 141, 152, & - 23, 130, 156, & - 3, 160, 164, & - 22, 90, 110, & - 35, 61, 109, & - 31, 87, 158, & - 42, 60, 106, & - 137, 140, 157, & - 27, 114, 124, & - 32, 62, 125, & - 34, 38, 128, & - 40, 123, 139, & - 29, 66, 86, & - 36, 52, 161, & - 43, 63, 133, & - 46, 73, 108, & - 44, 135, 146, & - 47, 115, 127, & - 49, 74, 116, & - 58, 102, 122, & - 55, 85, 132, & - 50, 65, 150, & - 67, 145, 162, & - 53, 71, 77, & - 69, 88, 142, & - 68, 72, 93, & - 9, 64, 95, & - 92, 94, 111, & - 81, 83, 119, & - 98, 143, 163, & - 73, 79, 96, & - 35, 129, 131, & - 99, 100, 151, & - 7, 112, 159, & - 117, 137, 156, & - 120, 147, 154, & - 107, 121, 165/ - -data Nm/ & - 4, 62, 75, 121, 191, & - 5, 63, 76, 82, 175, & - 6, 64, 77, 112, 206, & - 7, 65, 78, 151, 180, & - 8, 66, 79, 159, 188, & - 9, 67, 80, 127, 164, & - 68, 81, 119, 182, 237, & - 10, 69, 76, 109, 173, & - 70, 83, 141, 181, 230, & - 2, 71, 84, 185, 193, & - 11, 64, 85, 91, 190, & - 12, 72, 86, 127, 196, & - 13, 73, 87, 110, 194, & - 2, 74, 88, 106, 192, & - 14, 88, 89, 200, 0, & - 15, 90, 120, 197, 0, & - 16, 85, 131, 188, 0, & - 12, 65, 92, 165, 197, & - 17, 93, 124, 195, 0, & - 18, 94, 148, 199, 0, & - 19, 95, 115, 204, 0, & - 10, 96, 98, 207, 0, & - 20, 97, 116, 205, 0, & - 13, 44, 96, 129, 190, & - 21, 99, 113, 196, 0, & - 22, 100, 116, 175, 0, & - 23, 101, 139, 212, 0, & - 11, 102, 147, 175, 0, & - 24, 74, 103, 139, 216, & - 25, 72, 104, 118, 182, & - 26, 105, 165, 209, 0, & - 27, 106, 111, 213, 0, & - 18, 107, 122, 194, 0, & - 28, 56, 108, 162, 214, & - 59, 82, 107, 208, 235, & - 23, 87, 144, 217, 0, & - 17, 73, 111, 172, 181, & - 29, 112, 132, 214, 0, & - 30, 42, 99, 185, 186, & - 31, 71, 114, 146, 215, & - 16, 95, 143, 199, 0, & - 32, 97, 145, 210, 0, & - 33, 117, 118, 218, 0, & - 15, 117, 122, 220, 0, & - 34, 100, 119, 200, 0, & - 35, 99, 120, 219, 0, & - 16, 75, 127, 221, 0, & - 36, 117, 137, 187, 0, & - 34, 123, 160, 222, 0, & - 4, 93, 155, 225, 0, & - 37, 113, 125, 188, 0, & - 25, 126, 166, 217, 0, & - 5, 66, 121, 134, 227, & - 38, 69, 128, 150, 197, & - 31, 100, 129, 224, 0, & - 39, 82, 130, 196, 0, & - 40, 114, 131, 195, 0, & - 23, 77, 140, 223, 0, & - 24, 133, 148, 180, 0, & - 41, 80, 144, 210, 0, & - 26, 70, 135, 143, 208, & - 42, 60, 118, 136, 213, & - 8, 38, 130, 140, 218, & - 43, 55, 138, 145, 230, & - 44, 138, 139, 225, 0, & - 45, 136, 153, 216, 0, & - 4, 83, 153, 226, 0, & - 46, 142, 177, 229, 0, & - 47, 103, 143, 228, 0, & - 35, 110, 149, 191, 0, & - 20, 96, 156, 227, 0, & - 48, 114, 157, 229, 0, & - 102, 184, 219, 234, 0, & - 5, 133, 141, 222, 0, & - 41, 84, 121, 182, 0, & - 30, 103, 150, 164, 0, & - 26, 101, 151, 227, 0, & - 36, 152, 178, 191, 0, & - 49, 83, 168, 234, 0, & - 45, 124, 154, 183, 0, & - 39, 154, 169, 232, 0, & - 33, 73, 101, 131, 200, & - 6, 128, 141, 232, 0, & - 1, 27, 158, 198, 0, & - 50, 135, 159, 224, 0, & - 35, 123, 179, 216, 0, & - 3, 112, 161, 209, 0, & - 48, 154, 162, 228, 0, & - 21, 56, 160, 163, 195, & - 7, 136, 146, 207, 0, & - 46, 66, 105, 153, 173, & - 31, 70, 113, 126, 231, & - 15, 58, 167, 176, 229, & - 18, 93, 109, 231, 0, & - 21, 74, 81, 170, 230, & - 38, 78, 166, 234, 0, & - 28, 156, 171, 181, 0, & - 29, 126, 172, 233, 0, & - 49, 51, 92, 159, 236, & - 19, 169, 174, 236, 0, & - 1, 37, 71, 128, 155, & - 129, 164, 167, 223, 0, & - 51, 108, 177, 185, 0, & - 37, 61, 152, 162, 168, & - 22, 64, 150, 163, 194, & - 52, 62, 90, 91, 210, & - 41, 107, 179, 240, 0, & - 10, 104, 115, 219, 0, & - 34, 67, 98, 142, 208, & - 43, 147, 149, 207, 0, & - 27, 68, 108, 151, 231, & - 50, 148, 189, 237, 0, & - 6, 68, 137, 142, 192, & - 46, 172, 174, 212, 0, & - 52, 78, 201, 221, 0, & - 53, 125, 176, 222, 0, & - 40, 135, 178, 238, 0, & - 43, 92, 192, 201, 0, & - 54, 79, 193, 232, 0, & - 53, 130, 156, 239, 0, & - 7, 85, 170, 240, 0, & - 55, 84, 109, 223, 0, & - 47, 171, 201, 215, 0, & - 9, 50, 149, 198, 212, & - 39, 90, 178, 213, 0, & - 25, 94, 169, 190, 0, & - 29, 179, 203, 221, 0, & - 8, 138, 202, 214, 0, & - 17, 79, 187, 235, 0, & - 49, 59, 77, 146, 205, & - 14, 75, 157, 235, 0, & - 42, 63, 155, 161, 224, & - 52, 158, 160, 218, 0, & - 45, 89, 140, 199, 0, & - 56, 95, 147, 220, 0, & - 57, 69, 97, 180, 187, & - 55, 86, 211, 238, 0, & - 2, 9, 57, 125, 184, & - 36, 76, 202, 215, 0, & - 53, 161, 166, 211, 0, & - 20, 67, 158, 193, 204, & - 12, 111, 116, 228, 0, & - 30, 89, 152, 233, 0, & - 1, 58, 134, 145, 0, & - 13, 86, 137, 226, 0, & - 44, 72, 105, 186, 220, & - 32, 106, 163, 239, 0, & - 3, 33, 80, 183, 0, & - 14, 120, 189, 202, 0, & - 59, 104, 176, 225, 0, & - 60, 110, 133, 236, 0, & - 48, 63, 87, 170, 204, & - 22, 61, 115, 171, 183, & - 19, 119, 132, 239, 0, & - 28, 88, 144, 173, 0, & - 186, 203, 205, 238, 0, & - 51, 91, 123, 211, 0, & - 32, 94, 157, 209, 0, & - 11, 58, 124, 203, 237, & - 61, 65, 122, 174, 206, & - 54, 98, 189, 217, 0, & - 47, 132, 198, 226, 0, & - 57, 81, 165, 233, 0, & - 40, 60, 134, 184, 206, & - 54, 167, 168, 240, 0, & - 3, 24, 62, 102, 177/ - -data nrw/ & -5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,4,4,5,4,4, & -4,4,4,5,4,4,4,4,5,5,4,4,4,5,5,4,5,4,5,5, & -4,4,4,4,4,4,4,4,4,4,4,4,5,5,4,4,4,4,4,4, & -5,5,5,5,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, & -4,5,4,4,4,4,4,4,5,4,5,5,5,4,5,4,4,4,5,4, & -5,4,4,5,5,5,4,4,5,4,5,4,5,4,4,4,4,4,4,4, & -4,4,4,5,4,4,4,4,4,5,4,5,4,4,4,5,4,5,4,4, & -5,4,4,4,4,5,4,4,4,4,4,5,5,4,4,4,4,4,5,5, & -4,4,4,5,4,5/ - -ncw=3 - +data Mn/ & + 84, 101, 144, & + 10, 14, 138, & + 87, 148, 166, & + 1, 50, 67, & + 2, 53, 74, & + 3, 83, 113, & + 4, 90, 121, & + 5, 63, 128, & + 6, 124, 138, & + 8, 22, 108, & + 11, 28, 159, & + 12, 18, 142, & + 13, 24, 145, & + 15, 131, 149, & + 16, 44, 93, & + 17, 41, 47, & + 19, 37, 129, & + 20, 33, 94, & + 21, 100, 154, & + 23, 71, 141, & + 25, 89, 95, & + 26, 105, 153, & + 27, 36, 58, & + 29, 59, 166, & + 30, 52, 126, & + 31, 61, 77, & + 32, 84, 111, & + 34, 97, 155, & + 38, 98, 127, & + 39, 76, 143, & + 40, 55, 92, & + 42, 147, 158, & + 43, 82, 148, & + 45, 49, 109, & + 46, 70, 86, & + 48, 78, 139, & + 51, 101, 104, & + 54, 63, 96, & + 56, 81, 125, & + 57, 117, 164, & + 60, 75, 107, & + 39, 62, 132, & + 64, 110, 118, & + 24, 65, 146, & + 66, 80, 134, & + 68, 91, 114, & + 69, 123, 162, & + 72, 88, 152, & + 79, 99, 130, & + 85, 112, 124, & + 99, 103, 157, & + 106, 115, 133, & + 116, 120, 140, & + 119, 161, 165, & + 64, 122, 137, & + 34, 89, 135, & + 136, 138, 163, & + 93, 144, 159, & + 35, 130, 150, & + 62, 151, 164, & + 104, 153, 160, & + 1, 106, 166, & + 2, 132, 152, & + 3, 11, 105, & + 4, 18, 160, & + 5, 53, 91, & + 6, 109, 141, & + 7, 111, 113, & + 8, 54, 136, & + 9, 61, 92, & + 10, 40, 101, & + 12, 30, 146, & + 13, 37, 82, & + 14, 29, 95, & + 1, 47, 131, & + 2, 8, 139, & + 3, 58, 130, & + 4, 96, 115, & + 5, 119, 129, & + 6, 60, 148, & + 7, 95, 163, & + 2, 35, 56, & + 9, 67, 79, & + 10, 75, 122, & + 11, 17, 121, & + 12, 137, 145, & + 13, 36, 152, & + 14, 15, 155, & + 15, 134, 143, & + 16, 106, 125, & + 11, 106, 157, & + 18, 99, 118, & + 19, 50, 94, & + 20, 126, 158, & + 21, 41, 135, & + 22, 24, 71, & + 23, 42, 136, & + 22, 109, 161, & + 25, 39, 46, & + 26, 45, 55, & + 27, 77, 82, & + 28, 73, 166, & + 29, 69, 76, & + 30, 108, 150, & + 31, 91, 146, & + 14, 32, 147, & + 33, 35, 107, & + 34, 103, 111, & + 8, 94, 122, & + 13, 70, 151, & + 32, 37, 142, & + 3, 38, 87, & + 25, 51, 92, & + 40, 57, 72, & + 21, 108, 153, & + 23, 26, 142, & + 43, 44, 48, & + 30, 43, 62, & + 7, 45, 154, & + 16, 46, 149, & + 1, 53, 75, & + 33, 44, 160, & + 49, 86, 157, & + 19, 80, 159, & + 51, 116, 138, & + 52, 92, 98, & + 6, 12, 47, & + 54, 83, 101, & + 24, 55, 102, & + 56, 63, 120, & + 17, 57, 82, & + 38, 154, 162, & + 59, 74, 151, & + 53, 144, 164, & + 61, 85, 117, & + 62, 66, 90, & + 48, 113, 145, & + 64, 65, 128, & + 27, 29, 65, & + 58, 63, 134, & + 9, 74, 83, & + 68, 109, 113, & + 41, 61, 69, & + 36, 60, 155, & + 42, 64, 144, & + 40, 90, 130, & + 28, 110, 135, & + 20, 59, 112, & + 70, 110, 124, & + 54, 76, 105, & + 4, 77, 111, & + 78, 104, 143, & + 66, 67, 91, & + 80, 81, 88, & + 50, 101, 132, & + 71, 97, 120, & + 72, 131, 158, & + 84, 133, 141, & + 5, 85, 99, & + 49, 89, 133, & + 87, 132, 140, & + 34, 88, 104, & + 89, 105, 147, & + 6, 76, 102, & + 18, 31, 163, & + 52, 96, 140, & + 93, 102, 165, & + 79, 104, 165, & + 81, 100, 126, & + 95, 121, 152, & + 97, 123, 153, & + 37, 98, 114, & + 8, 91, 155, & + 100, 114, 160, & + 2, 26, 28, & + 93, 116, 150, & + 68, 103, 166, & + 78, 117, 125, & + 86, 107, 127, & + 4, 59, 136, & + 9, 37, 97, & + 7, 30, 75, & + 80, 148, 153, & + 73, 138, 164, & + 10, 39, 103, & + 39, 146, 156, & + 48, 129, 136, & + 5, 17, 51, & + 112, 149, 161, & + 11, 24, 126, & + 1, 70, 78, & + 14, 113, 118, & + 10, 119, 141, & + 13, 33, 105, & + 19, 57, 89, & + 12, 25, 56, & + 16, 18, 54, & + 84, 124, 162, & + 20, 41, 134, & + 15, 45, 82, & + 115, 118, 123, & + 128, 139, 149, & + 127, 156, 159, & + 21, 141, 152, & + 23, 130, 156, & + 3, 160, 164, & + 22, 90, 110, & + 35, 61, 109, & + 31, 87, 158, & + 42, 60, 106, & + 137, 140, 157, & + 27, 114, 124, & + 32, 62, 125, & + 34, 38, 128, & + 40, 123, 139, & + 29, 66, 86, & + 36, 52, 161, & + 43, 63, 133, & + 46, 73, 108, & + 44, 135, 146, & + 47, 115, 127, & + 49, 74, 116, & + 58, 102, 122, & + 55, 85, 132, & + 50, 65, 150, & + 67, 145, 162, & + 53, 71, 77, & + 69, 88, 142, & + 68, 72, 93, & + 9, 64, 95, & + 92, 94, 111, & + 81, 83, 119, & + 98, 143, 163, & + 73, 79, 96, & + 35, 129, 131, & + 99, 100, 151, & + 7, 112, 159, & + 117, 137, 156, & + 120, 147, 154, & + 107, 121, 165/ + +data Nm/ & + 4, 62, 75, 121, 191, & + 5, 63, 76, 82, 175, & + 6, 64, 77, 112, 206, & + 7, 65, 78, 151, 180, & + 8, 66, 79, 159, 188, & + 9, 67, 80, 127, 164, & + 68, 81, 119, 182, 237, & + 10, 69, 76, 109, 173, & + 70, 83, 141, 181, 230, & + 2, 71, 84, 185, 193, & + 11, 64, 85, 91, 190, & + 12, 72, 86, 127, 196, & + 13, 73, 87, 110, 194, & + 2, 74, 88, 106, 192, & + 14, 88, 89, 200, 0, & + 15, 90, 120, 197, 0, & + 16, 85, 131, 188, 0, & + 12, 65, 92, 165, 197, & + 17, 93, 124, 195, 0, & + 18, 94, 148, 199, 0, & + 19, 95, 115, 204, 0, & + 10, 96, 98, 207, 0, & + 20, 97, 116, 205, 0, & + 13, 44, 96, 129, 190, & + 21, 99, 113, 196, 0, & + 22, 100, 116, 175, 0, & + 23, 101, 139, 212, 0, & + 11, 102, 147, 175, 0, & + 24, 74, 103, 139, 216, & + 25, 72, 104, 118, 182, & + 26, 105, 165, 209, 0, & + 27, 106, 111, 213, 0, & + 18, 107, 122, 194, 0, & + 28, 56, 108, 162, 214, & + 59, 82, 107, 208, 235, & + 23, 87, 144, 217, 0, & + 17, 73, 111, 172, 181, & + 29, 112, 132, 214, 0, & + 30, 42, 99, 185, 186, & + 31, 71, 114, 146, 215, & + 16, 95, 143, 199, 0, & + 32, 97, 145, 210, 0, & + 33, 117, 118, 218, 0, & + 15, 117, 122, 220, 0, & + 34, 100, 119, 200, 0, & + 35, 99, 120, 219, 0, & + 16, 75, 127, 221, 0, & + 36, 117, 137, 187, 0, & + 34, 123, 160, 222, 0, & + 4, 93, 155, 225, 0, & + 37, 113, 125, 188, 0, & + 25, 126, 166, 217, 0, & + 5, 66, 121, 134, 227, & + 38, 69, 128, 150, 197, & + 31, 100, 129, 224, 0, & + 39, 82, 130, 196, 0, & + 40, 114, 131, 195, 0, & + 23, 77, 140, 223, 0, & + 24, 133, 148, 180, 0, & + 41, 80, 144, 210, 0, & + 26, 70, 135, 143, 208, & + 42, 60, 118, 136, 213, & + 8, 38, 130, 140, 218, & + 43, 55, 138, 145, 230, & + 44, 138, 139, 225, 0, & + 45, 136, 153, 216, 0, & + 4, 83, 153, 226, 0, & + 46, 142, 177, 229, 0, & + 47, 103, 143, 228, 0, & + 35, 110, 149, 191, 0, & + 20, 96, 156, 227, 0, & + 48, 114, 157, 229, 0, & + 102, 184, 219, 234, 0, & + 5, 133, 141, 222, 0, & + 41, 84, 121, 182, 0, & + 30, 103, 150, 164, 0, & + 26, 101, 151, 227, 0, & + 36, 152, 178, 191, 0, & + 49, 83, 168, 234, 0, & + 45, 124, 154, 183, 0, & + 39, 154, 169, 232, 0, & + 33, 73, 101, 131, 200, & + 6, 128, 141, 232, 0, & + 1, 27, 158, 198, 0, & + 50, 135, 159, 224, 0, & + 35, 123, 179, 216, 0, & + 3, 112, 161, 209, 0, & + 48, 154, 162, 228, 0, & + 21, 56, 160, 163, 195, & + 7, 136, 146, 207, 0, & + 46, 66, 105, 153, 173, & + 31, 70, 113, 126, 231, & + 15, 58, 167, 176, 229, & + 18, 93, 109, 231, 0, & + 21, 74, 81, 170, 230, & + 38, 78, 166, 234, 0, & + 28, 156, 171, 181, 0, & + 29, 126, 172, 233, 0, & + 49, 51, 92, 159, 236, & + 19, 169, 174, 236, 0, & + 1, 37, 71, 128, 155, & + 129, 164, 167, 223, 0, & + 51, 108, 177, 185, 0, & + 37, 61, 152, 162, 168, & + 22, 64, 150, 163, 194, & + 52, 62, 90, 91, 210, & + 41, 107, 179, 240, 0, & + 10, 104, 115, 219, 0, & + 34, 67, 98, 142, 208, & + 43, 147, 149, 207, 0, & + 27, 68, 108, 151, 231, & + 50, 148, 189, 237, 0, & + 6, 68, 137, 142, 192, & + 46, 172, 174, 212, 0, & + 52, 78, 201, 221, 0, & + 53, 125, 176, 222, 0, & + 40, 135, 178, 238, 0, & + 43, 92, 192, 201, 0, & + 54, 79, 193, 232, 0, & + 53, 130, 156, 239, 0, & + 7, 85, 170, 240, 0, & + 55, 84, 109, 223, 0, & + 47, 171, 201, 215, 0, & + 9, 50, 149, 198, 212, & + 39, 90, 178, 213, 0, & + 25, 94, 169, 190, 0, & + 29, 179, 203, 221, 0, & + 8, 138, 202, 214, 0, & + 17, 79, 187, 235, 0, & + 49, 59, 77, 146, 205, & + 14, 75, 157, 235, 0, & + 42, 63, 155, 161, 224, & + 52, 158, 160, 218, 0, & + 45, 89, 140, 199, 0, & + 56, 95, 147, 220, 0, & + 57, 69, 97, 180, 187, & + 55, 86, 211, 238, 0, & + 2, 9, 57, 125, 184, & + 36, 76, 202, 215, 0, & + 53, 161, 166, 211, 0, & + 20, 67, 158, 193, 204, & + 12, 111, 116, 228, 0, & + 30, 89, 152, 233, 0, & + 1, 58, 134, 145, 0, & + 13, 86, 137, 226, 0, & + 44, 72, 105, 186, 220, & + 32, 106, 163, 239, 0, & + 3, 33, 80, 183, 0, & + 14, 120, 189, 202, 0, & + 59, 104, 176, 225, 0, & + 60, 110, 133, 236, 0, & + 48, 63, 87, 170, 204, & + 22, 61, 115, 171, 183, & + 19, 119, 132, 239, 0, & + 28, 88, 144, 173, 0, & + 186, 203, 205, 238, 0, & + 51, 91, 123, 211, 0, & + 32, 94, 157, 209, 0, & + 11, 58, 124, 203, 237, & + 61, 65, 122, 174, 206, & + 54, 98, 189, 217, 0, & + 47, 132, 198, 226, 0, & + 57, 81, 165, 233, 0, & + 40, 60, 134, 184, 206, & + 54, 167, 168, 240, 0, & + 3, 24, 62, 102, 177/ + +data nrw/ & +5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,4,4,5,4,4, & +4,4,4,5,4,4,4,4,5,5,4,4,4,5,5,4,5,4,5,5, & +4,4,4,4,4,4,4,4,4,4,4,4,5,5,4,4,4,4,4,4, & +5,5,5,5,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, & +4,5,4,4,4,4,4,4,5,4,5,5,5,4,5,4,4,4,5,4, & +5,4,4,5,5,5,4,4,5,4,5,4,5,4,4,4,4,4,4,4, & +4,4,4,5,4,4,4,4,4,5,4,5,4,4,4,5,4,5,4,4, & +5,4,4,4,4,5,4,4,4,4,4,5,5,4,4,4,4,4,5,5, & +4,4,4,5,4,5/ + +ncw=3 + diff --git a/lib/fst4/ldpcsim240_101.f90 b/lib/fst4/ldpcsim240_101.f90 index 48e441ff..e201ac41 100755 --- a/lib/fst4/ldpcsim240_101.f90 +++ b/lib/fst4/ldpcsim240_101.f90 @@ -1,137 +1,137 @@ -program ldpcsim240_101 - -! End-to-end test of the (240,101)/crc24 encoder and decoders. - - use packjt77 - - parameter(N=240, K=101, M=N-K) - character*8 arg - character*37 msg0,msg - character*77 c77 - character*24 c24 - integer*1 msgbits(101) - integer*1 apmask(240) - integer*1 cw(240) - integer*1 codeword(N),message101(101) - integer ncrc24 - real rxdata(N),llr(N) - logical first,unpk77_success - data first/.true./ - - nargs=iargc() - if(nargs.ne.5 .and. nargs.ne.6) then - print*,'Usage: ldpcsim niter ndeep #trials s K [msg]' - print*,'e.g. ldpcsim240_101 20 5 1000 0.85 91 "K9AN K1JT FN20"' - print*,'s : if negative, then value is ignored and sigma is calculated from SNR.' - print*,'niter: is the number of BP iterations.' - print*,'ndeep: -1 is BP only, ndeep>=0 is OSD order' - print*,'K :is the number of message+CRC bits and must be in the range [77,101]' - print*,'WSPR-format message is optional' - return - endif - call getarg(1,arg) - read(arg,*) max_iterations - call getarg(2,arg) - read(arg,*) norder - call getarg(3,arg) - read(arg,*) ntrials - call getarg(4,arg) - read(arg,*) s - call getarg(5,arg) - read(arg,*) Keff - msg0='K9AN K1JT FN20 ' - if(nargs.eq.6) call getarg(6,msg0) - call pack77(msg0,i3,n3,c77) - - rate=real(Keff)/real(N) - - write(*,*) "code rate: ",rate - write(*,*) "niter : ",max_iterations - write(*,*) "norder : ",norder - write(*,*) "s : ",s - write(*,*) "K : ",Keff - - msgbits=0 - read(c77,'(77i1)') msgbits(1:77) - write(*,*) 'message' - write(*,'(77i1)') msgbits(1:77) - - call get_crc24(msgbits,101,ncrc24) - write(c24,'(b24.24)') ncrc24 - read(c24,'(24i1)') msgbits(78:101) -write(*,'(24i1)') msgbits(78:101) - write(*,*) 'message with crc24' - write(*,'(101i1)') msgbits(1:101) - call encode240_101(msgbits,codeword) - call init_random_seed() - call sgran() - - write(*,*) 'codeword' - write(*,'(77i1,1x,24i1,1x,73i1)') codeword - - write(*,*) "Eb/N0 Es/N0 ngood nundetected sigma symbol error rate" - do idb = 8,-3,-1 - db=idb/2.0-1.0 - sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) ! to make db represent Eb/No -! sigma=1/sqrt( 2*(10**(db/10.0)) ) ! db represents Es/No - ngood=0 - nue=0 - nberr=0 - do itrial=1, ntrials -! Create a realization of a noisy received word - do i=1,N - rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() - enddo - nerr=0 - do i=1,N - if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1 - enddo - nberr=nberr+nerr - - rxav=sum(rxdata)/N - rx2av=sum(rxdata*rxdata)/N - rxsig=sqrt(rx2av-rxav*rxav) - rxdata=rxdata/rxsig - if( s .lt. 0 ) then - ss=sigma - else - ss=s - endif - - llr=2.0*rxdata/(ss*ss) - apmask=0 - dmin=0.0 - maxosd=2 - call decode240_101(llr, Keff, maxosd, norder, apmask, message101, cw, ntype, nharderror, dmin) - if(nharderror.ge.0) then - n2err=0 - do i=1,N - if( cw(i).ne.codeword(i) ) n2err=n2err+1 - enddo - if(n2err.eq.0) then - ngood=ngood+1 - else - nue=nue+1 - endif - endif - enddo -! snr2500=db+10*log10(200.0/116.0/2500.0) - esn0=db+10*log10(rate) - pberr=real(nberr)/(real(ntrials*N)) - write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,8x,f5.2,8x,e10.3)") db,esn0,ngood,nue,ss,pberr - - if(first) then - write(c77,'(77i1)') message101(1:77) -write(*,'(101i1)') message101 - call unpack77(c77,0,msg,unpk77_success) - if(unpk77_success) then - write(*,1100) msg(1:37) -1100 format('Decoded message: ',a37) - else - print*,'Error unpacking message' - endif - first=.false. - endif - enddo - -end program ldpcsim240_101 +program ldpcsim240_101 + +! End-to-end test of the (240,101)/crc24 encoder and decoders. + + use packjt77 + + parameter(N=240, K=101, M=N-K) + character*8 arg + character*37 msg0,msg + character*77 c77 + character*24 c24 + integer*1 msgbits(101) + integer*1 apmask(240) + integer*1 cw(240) + integer*1 codeword(N),message101(101) + integer ncrc24 + real rxdata(N),llr(N) + logical first,unpk77_success + data first/.true./ + + nargs=iargc() + if(nargs.ne.5 .and. nargs.ne.6) then + print*,'Usage: ldpcsim niter ndeep #trials s K [msg]' + print*,'e.g. ldpcsim240_101 20 5 1000 0.85 91 "K9AN K1JT FN20"' + print*,'s : if negative, then value is ignored and sigma is calculated from SNR.' + print*,'niter: is the number of BP iterations.' + print*,'ndeep: -1 is BP only, ndeep>=0 is OSD order' + print*,'K :is the number of message+CRC bits and must be in the range [77,101]' + print*,'WSPR-format message is optional' + return + endif + call getarg(1,arg) + read(arg,*) max_iterations + call getarg(2,arg) + read(arg,*) norder + call getarg(3,arg) + read(arg,*) ntrials + call getarg(4,arg) + read(arg,*) s + call getarg(5,arg) + read(arg,*) Keff + msg0='K9AN K1JT FN20 ' + if(nargs.eq.6) call getarg(6,msg0) + call pack77(msg0,i3,n3,c77) + + rate=real(Keff)/real(N) + + write(*,*) "code rate: ",rate + write(*,*) "niter : ",max_iterations + write(*,*) "norder : ",norder + write(*,*) "s : ",s + write(*,*) "K : ",Keff + + msgbits=0 + read(c77,'(77i1)') msgbits(1:77) + write(*,*) 'message' + write(*,'(77i1)') msgbits(1:77) + + call get_crc24(msgbits,101,ncrc24) + write(c24,'(b24.24)') ncrc24 + read(c24,'(24i1)') msgbits(78:101) +write(*,'(24i1)') msgbits(78:101) + write(*,*) 'message with crc24' + write(*,'(101i1)') msgbits(1:101) + call encode240_101(msgbits,codeword) + call init_random_seed() + call sgran() + + write(*,*) 'codeword' + write(*,'(77i1,1x,24i1,1x,73i1)') codeword + + write(*,*) "Eb/N0 Es/N0 ngood nundetected sigma symbol error rate" + do idb = 8,-3,-1 + db=idb/2.0-1.0 + sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) ! to make db represent Eb/No +! sigma=1/sqrt( 2*(10**(db/10.0)) ) ! db represents Es/No + ngood=0 + nue=0 + nberr=0 + do itrial=1, ntrials +! Create a realization of a noisy received word + do i=1,N + rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() + enddo + nerr=0 + do i=1,N + if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1 + enddo + nberr=nberr+nerr + + rxav=sum(rxdata)/N + rx2av=sum(rxdata*rxdata)/N + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + if( s .lt. 0 ) then + ss=sigma + else + ss=s + endif + + llr=2.0*rxdata/(ss*ss) + apmask=0 + dmin=0.0 + maxosd=2 + call decode240_101(llr, Keff, maxosd, norder, apmask, message101, cw, ntype, nharderror, dmin) + if(nharderror.ge.0) then + n2err=0 + do i=1,N + if( cw(i).ne.codeword(i) ) n2err=n2err+1 + enddo + if(n2err.eq.0) then + ngood=ngood+1 + else + nue=nue+1 + endif + endif + enddo +! snr2500=db+10*log10(200.0/116.0/2500.0) + esn0=db+10*log10(rate) + pberr=real(nberr)/(real(ntrials*N)) + write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,8x,f5.2,8x,e10.3)") db,esn0,ngood,nue,ss,pberr + + if(first) then + write(c77,'(77i1)') message101(1:77) +write(*,'(101i1)') message101 + call unpack77(c77,0,msg,unpk77_success) + if(unpk77_success) then + write(*,1100) msg(1:37) +1100 format('Decoded message: ',a37) + else + print*,'Error unpacking message' + endif + first=.false. + endif + enddo + +end program ldpcsim240_101 diff --git a/lib/fst4/ldpcsim240_74.f90 b/lib/fst4/ldpcsim240_74.f90 index f9d951d3..d6838607 100755 --- a/lib/fst4/ldpcsim240_74.f90 +++ b/lib/fst4/ldpcsim240_74.f90 @@ -1,270 +1,270 @@ -program ldpcsim240_74 - -! End-to-end test of the (240,74)/crc24 encoder and decoders. - - use packjt77 - - parameter(N=240, NN=120) - character*8 arg - character*37 msg0,msgsent,msg - character*77 c77 - character*24 c24 - integer*1 msgbits(101) - integer*1 apmask(240) - integer*1 cw(240) - integer*1 codeword(N),message74(74) - integer ncrc24 - integer modtype, graymap(0:3) - integer*4 itone(120) - integer channeltype - integer lmax(1) - real rxdata(N) - real llr(240) - real bitmetrics(2*NN,4) - complex c1(4,8),c2(16,4),c4(256,2),cs(0:3,NN) - real s2(0:65535) - logical one(0:65535,0:15) ! 65536 8-symbol sequences, 16 bits - logical first - data first/.true./ - data graymap/0,1,3,2/ - - nargs=iargc() - if(nargs.ne.7 .and. nargs.ne.8) then - print*,'Usage: ldpcsim maxosd norder #trials s Keff modtype channel ' - print*,'e.g. ldpcsim240_74 2 4 1000 0.85 50 1 0' - print*,'s : if negative, then value is ignored and sigma is calculated from SNR.' - print*,'maxosd<0: do bp only' - print*,'maxosd=0: do bp and then call osd once with channel llrs.' - print*,'maxosd>0: do bp and then call osc maxosd times with saved bp outputs.' - print*,'norder : osd decoding depth' - print*,'Keff : # of message bits, Keff must be in the range 50:74' - print*,'modtype : 0 coherent BPSK, 1 4FSK' - print*,'channel : 0 AWGN, 1 Rayleigh (4FSK only)' - print*,'WSPR-format message is optional' - return - endif - call getarg(1,arg) - read(arg,*) maxosd - call getarg(2,arg) - read(arg,*) norder - call getarg(3,arg) - read(arg,*) ntrials - call getarg(4,arg) - read(arg,*) s - call getarg(5,arg) - read(arg,*) Keff - call getarg(6,arg) - read(arg,*) modtype - call getarg(7,arg) - read(arg,*) channeltype - call getarg(8,arg) - - msg0='K9AN EN50 20 ' - call pack77(msg0,i3,n3,c77) - - rate=real(Keff)/real(N) - - write(*,*) "code rate: ",rate - write(*,*) "maxosd : ",maxosd - write(*,*) "norder : ",norder - write(*,*) "s : ",s - write(*,*) "K : ",Keff - if(modtype.eq.0) write(*,*) "modtype : coherent BPSK" - if(modtype.eq.1) write(*,*) "modtype : noncoherent 4FSK" - if(channeltype.eq.0) write(*,*) "channel : AWGN" - if(channeltype.eq.1) write(*,*) "channel : Rayleigh" - - msgbits=0 - read(c77,'(50i1)') msgbits(1:50) - write(*,*) 'message' - write(*,'(50i1)') msgbits(1:50) - - call get_crc24(msgbits,74,ncrc24) - write(c24,'(b24.24)') ncrc24 - read(c24,'(24i1)') msgbits(51:74) - write(*,'(24i1)') msgbits(51:74) - write(*,*) 'message with crc24' - write(*,'(74i1)') msgbits(1:74) - - call encode240_74(msgbits(1:74),codeword) - do i=1,120 - is=codeword(2*i)+2*codeword(2*i-1) - itone(i)=graymap(is) - enddo - - write(*,*) 'codeword' - write(*,'(77i1,1x,24i1,1x,73i1)') codeword - -! call init_random_seed() -! call sgran() - - one=.false. - do i=0,65535 - do j=0,15 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - - write(*,*) "Eb/N0 Es/N0 ngood nundetected symbol error rate" - do idb = 24,-8,-1 - db=idb/2.0-1.0 - sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) ! to make db represent Eb/No -! sigma=1/sqrt( 2*(10**(db/10.0)) ) ! db represents Es/No - ngood=0 - nue=0 - nberr=0 - nsymerr=0 - - do itrial=1, ntrials -! Create a realization of a noisy received word - if(modtype.eq.0) then - iq = 1 ! bits per symbol - sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) ! to make db represent Eb/No - do i=1,N - rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() - enddo - nerr=0 - do i=1,N - if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1 - enddo - nberr=nberr+nerr - - rxav=sum(rxdata)/N - rx2av=sum(rxdata*rxdata)/N - rxsig=sqrt(rx2av-rxav*rxav) - rxdata=rxdata/rxsig - if( s .lt. 0 ) then - ss=sigma - else - ss=s - endif - - llr=2.0*rxdata/(ss*ss) - else -! noncoherent MFSK - iq = 2 ! bits per symbol - sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) ! to make db represent Eb/No - A=1 - do i=1,120 - do j=0,3 - if(j.eq.itone(i)) then - if(channeltype.eq.0) then - A=1.0 - elseif(channeltype.eq.1) then - xI=gran()**2+gran()**2 - A=sqrt(xI/2) - endif - cs(j,i)= A + sigma*gran() + cmplx(0,1)*sigma*gran() - elseif(j.ne.itone(i)) then - cs(j,i)= sigma*gran() + cmplx(0,1)*sigma*gran() - endif - enddo - lmax=maxloc(abs(cs(:,i))) - if(lmax(1)-1.ne.itone(i) ) nsymerr=nsymerr+1 - enddo - - do k=1,NN,8 - - do m=1,8 ! do 4 1-symbol correlations for each of 8 symbs - s2=0 - do is=1,4 - c1(is,m)=cs(graymap(is-1),k+m-1) - s2(is-1)=abs(c1(is,m)) - enddo - ipt=(k-1)*2+2*(m-1)+1 - do ib=0,1 - bm=maxval(s2(0:3),one(0:3,1-ib)) - & - maxval(s2(0:3),.not.one(0:3,1-ib)) - if(ipt+ib.gt.2*NN) cycle - bitmetrics(ipt+ib,1)=bm - enddo - enddo - - do m=1,4 ! do 16 2-symbol correlations for each of 4 2-symbol groups - s2=0 - do i=1,4 - do j=1,4 - is=(i-1)*4+j - c2(is,m)=c1(i,2*m-1)+c1(j,2*m) - s2(is-1)=abs(c2(is,m))**2 - enddo - enddo - ipt=(k-1)*2+4*(m-1)+1 - do ib=0,3 - bm=maxval(s2(0:15),one(0:15,3-ib)) - & - maxval(s2(0:15),.not.one(0:15,3-ib)) - if(ipt+ib.gt.2*NN) cycle - bitmetrics(ipt+ib,2)=bm - enddo - enddo - - do m=1,2 ! do 256 4-symbol corrs for each of 2 4-symbol groups - s2=0 - do i=1,16 - do j=1,16 - is=(i-1)*16+j - c4(is,m)=c2(i,2*m-1)+c2(j,2*m) - s2(is-1)=abs(c4(is,m)) - enddo - enddo - ipt=(k-1)*2+8*(m-1)+1 - do ib=0,7 - bm=maxval(s2(0:255),one(0:255,7-ib)) - & - maxval(s2(0:255),.not.one(0:255,7-ib)) - if(ipt+ib.gt.2*NN) cycle - bitmetrics(ipt+ib,3)=bm - enddo - enddo - - s2=0 ! do 65536 8-symbol correlations for the entire group - do i=1,256 - do j=1,256 - is=(i-1)*256+j - s2(is-1)=abs(c4(i,1)+c4(j,2)) - enddo - enddo - ipt=(k-1)*2+1 - do ib=0,15 - bm=maxval(s2(0:65535),one(0:65535,15-ib)) - & - maxval(s2(0:65535),.not.one(0:65535,15-ib)) - if(ipt+ib.gt.2*NN) cycle - bitmetrics(ipt+ib,4)=bm - enddo - - enddo - - call normalizebmet(bitmetrics(:,1),2*NN) - call normalizebmet(bitmetrics(:,2),2*NN) - call normalizebmet(bitmetrics(:,3),2*NN) - call normalizebmet(bitmetrics(:,4),2*NN) - - scalefac=2.83 - bitmetrics=scalefac*bitmetrics - - llr=bitmetrics(:,1) - endif - - apmask=0 - dmin=0.0 - call decode240_74(llr, Keff, maxosd, norder, apmask, message74, cw, ntype, nharderror, dmin) - if(nharderror.ge.0) then - n2err=0 - do i=1,N - if( cw(i).ne.codeword(i) ) n2err=n2err+1 - enddo - if(n2err.eq.0) then - ngood=ngood+1 - else - nue=nue+1 - endif - endif - enddo -! snr2500=db+10*log10(200.0/116.0/2500.0) - esn0=db+10*log10(rate*iq) - pberr=real(nberr)/real(ntrials*N) - pserr=real(nsymerr)/real(ntrials*120) - write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,8x,e10.3)") db,esn0,ngood,nue,pserr - - enddo - -end program ldpcsim240_74 +program ldpcsim240_74 + +! End-to-end test of the (240,74)/crc24 encoder and decoders. + + use packjt77 + + parameter(N=240, NN=120) + character*8 arg + character*37 msg0,msgsent,msg + character*77 c77 + character*24 c24 + integer*1 msgbits(101) + integer*1 apmask(240) + integer*1 cw(240) + integer*1 codeword(N),message74(74) + integer ncrc24 + integer modtype, graymap(0:3) + integer*4 itone(120) + integer channeltype + integer lmax(1) + real rxdata(N) + real llr(240) + real bitmetrics(2*NN,4) + complex c1(4,8),c2(16,4),c4(256,2),cs(0:3,NN) + real s2(0:65535) + logical one(0:65535,0:15) ! 65536 8-symbol sequences, 16 bits + logical first + data first/.true./ + data graymap/0,1,3,2/ + + nargs=iargc() + if(nargs.ne.7 .and. nargs.ne.8) then + print*,'Usage: ldpcsim maxosd norder #trials s Keff modtype channel ' + print*,'e.g. ldpcsim240_74 2 4 1000 0.85 50 1 0' + print*,'s : if negative, then value is ignored and sigma is calculated from SNR.' + print*,'maxosd<0: do bp only' + print*,'maxosd=0: do bp and then call osd once with channel llrs.' + print*,'maxosd>0: do bp and then call osc maxosd times with saved bp outputs.' + print*,'norder : osd decoding depth' + print*,'Keff : # of message bits, Keff must be in the range 50:74' + print*,'modtype : 0 coherent BPSK, 1 4FSK' + print*,'channel : 0 AWGN, 1 Rayleigh (4FSK only)' + print*,'WSPR-format message is optional' + return + endif + call getarg(1,arg) + read(arg,*) maxosd + call getarg(2,arg) + read(arg,*) norder + call getarg(3,arg) + read(arg,*) ntrials + call getarg(4,arg) + read(arg,*) s + call getarg(5,arg) + read(arg,*) Keff + call getarg(6,arg) + read(arg,*) modtype + call getarg(7,arg) + read(arg,*) channeltype + call getarg(8,arg) + + msg0='K9AN EN50 20 ' + call pack77(msg0,i3,n3,c77) + + rate=real(Keff)/real(N) + + write(*,*) "code rate: ",rate + write(*,*) "maxosd : ",maxosd + write(*,*) "norder : ",norder + write(*,*) "s : ",s + write(*,*) "K : ",Keff + if(modtype.eq.0) write(*,*) "modtype : coherent BPSK" + if(modtype.eq.1) write(*,*) "modtype : noncoherent 4FSK" + if(channeltype.eq.0) write(*,*) "channel : AWGN" + if(channeltype.eq.1) write(*,*) "channel : Rayleigh" + + msgbits=0 + read(c77,'(50i1)') msgbits(1:50) + write(*,*) 'message' + write(*,'(50i1)') msgbits(1:50) + + call get_crc24(msgbits,74,ncrc24) + write(c24,'(b24.24)') ncrc24 + read(c24,'(24i1)') msgbits(51:74) + write(*,'(24i1)') msgbits(51:74) + write(*,*) 'message with crc24' + write(*,'(74i1)') msgbits(1:74) + + call encode240_74(msgbits(1:74),codeword) + do i=1,120 + is=codeword(2*i)+2*codeword(2*i-1) + itone(i)=graymap(is) + enddo + + write(*,*) 'codeword' + write(*,'(77i1,1x,24i1,1x,73i1)') codeword + +! call init_random_seed() +! call sgran() + + one=.false. + do i=0,65535 + do j=0,15 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + + write(*,*) "Eb/N0 Es/N0 ngood nundetected symbol error rate" + do idb = 24,-8,-1 + db=idb/2.0-1.0 + sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) ! to make db represent Eb/No +! sigma=1/sqrt( 2*(10**(db/10.0)) ) ! db represents Es/No + ngood=0 + nue=0 + nberr=0 + nsymerr=0 + + do itrial=1, ntrials +! Create a realization of a noisy received word + if(modtype.eq.0) then + iq = 1 ! bits per symbol + sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) ! to make db represent Eb/No + do i=1,N + rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() + enddo + nerr=0 + do i=1,N + if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1 + enddo + nberr=nberr+nerr + + rxav=sum(rxdata)/N + rx2av=sum(rxdata*rxdata)/N + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + if( s .lt. 0 ) then + ss=sigma + else + ss=s + endif + + llr=2.0*rxdata/(ss*ss) + else +! noncoherent MFSK + iq = 2 ! bits per symbol + sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) ! to make db represent Eb/No + A=1 + do i=1,120 + do j=0,3 + if(j.eq.itone(i)) then + if(channeltype.eq.0) then + A=1.0 + elseif(channeltype.eq.1) then + xI=gran()**2+gran()**2 + A=sqrt(xI/2) + endif + cs(j,i)= A + sigma*gran() + cmplx(0,1)*sigma*gran() + elseif(j.ne.itone(i)) then + cs(j,i)= sigma*gran() + cmplx(0,1)*sigma*gran() + endif + enddo + lmax=maxloc(abs(cs(:,i))) + if(lmax(1)-1.ne.itone(i) ) nsymerr=nsymerr+1 + enddo + + do k=1,NN,8 + + do m=1,8 ! do 4 1-symbol correlations for each of 8 symbs + s2=0 + do is=1,4 + c1(is,m)=cs(graymap(is-1),k+m-1) + s2(is-1)=abs(c1(is,m)) + enddo + ipt=(k-1)*2+2*(m-1)+1 + do ib=0,1 + bm=maxval(s2(0:3),one(0:3,1-ib)) - & + maxval(s2(0:3),.not.one(0:3,1-ib)) + if(ipt+ib.gt.2*NN) cycle + bitmetrics(ipt+ib,1)=bm + enddo + enddo + + do m=1,4 ! do 16 2-symbol correlations for each of 4 2-symbol groups + s2=0 + do i=1,4 + do j=1,4 + is=(i-1)*4+j + c2(is,m)=c1(i,2*m-1)+c1(j,2*m) + s2(is-1)=abs(c2(is,m))**2 + enddo + enddo + ipt=(k-1)*2+4*(m-1)+1 + do ib=0,3 + bm=maxval(s2(0:15),one(0:15,3-ib)) - & + maxval(s2(0:15),.not.one(0:15,3-ib)) + if(ipt+ib.gt.2*NN) cycle + bitmetrics(ipt+ib,2)=bm + enddo + enddo + + do m=1,2 ! do 256 4-symbol corrs for each of 2 4-symbol groups + s2=0 + do i=1,16 + do j=1,16 + is=(i-1)*16+j + c4(is,m)=c2(i,2*m-1)+c2(j,2*m) + s2(is-1)=abs(c4(is,m)) + enddo + enddo + ipt=(k-1)*2+8*(m-1)+1 + do ib=0,7 + bm=maxval(s2(0:255),one(0:255,7-ib)) - & + maxval(s2(0:255),.not.one(0:255,7-ib)) + if(ipt+ib.gt.2*NN) cycle + bitmetrics(ipt+ib,3)=bm + enddo + enddo + + s2=0 ! do 65536 8-symbol correlations for the entire group + do i=1,256 + do j=1,256 + is=(i-1)*256+j + s2(is-1)=abs(c4(i,1)+c4(j,2)) + enddo + enddo + ipt=(k-1)*2+1 + do ib=0,15 + bm=maxval(s2(0:65535),one(0:65535,15-ib)) - & + maxval(s2(0:65535),.not.one(0:65535,15-ib)) + if(ipt+ib.gt.2*NN) cycle + bitmetrics(ipt+ib,4)=bm + enddo + + enddo + + call normalizebmet(bitmetrics(:,1),2*NN) + call normalizebmet(bitmetrics(:,2),2*NN) + call normalizebmet(bitmetrics(:,3),2*NN) + call normalizebmet(bitmetrics(:,4),2*NN) + + scalefac=2.83 + bitmetrics=scalefac*bitmetrics + + llr=bitmetrics(:,1) + endif + + apmask=0 + dmin=0.0 + call decode240_74(llr, Keff, maxosd, norder, apmask, message74, cw, ntype, nharderror, dmin) + if(nharderror.ge.0) then + n2err=0 + do i=1,N + if( cw(i).ne.codeword(i) ) n2err=n2err+1 + enddo + if(n2err.eq.0) then + ngood=ngood+1 + else + nue=nue+1 + endif + endif + enddo +! snr2500=db+10*log10(200.0/116.0/2500.0) + esn0=db+10*log10(rate*iq) + pberr=real(nberr)/real(ntrials*N) + pserr=real(nsymerr)/real(ntrials*120) + write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,8x,e10.3)") db,esn0,ngood,nue,pserr + + enddo + +end program ldpcsim240_74 diff --git a/lib/fst4/osd240_101.f90 b/lib/fst4/osd240_101.f90 index 446abf69..9d97e8b6 100755 --- a/lib/fst4/osd240_101.f90 +++ b/lib/fst4/osd240_101.f90 @@ -1,404 +1,404 @@ -subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin) -! -! An ordered-statistics decoder for the (240,101) code. -! Message payload is 77 bits. Any or all of a 24-bit CRC can be -! used for detecting incorrect codewords. The remaining CRC bits are -! cascaded with the LDPC code for the purpose of improving the -! distance spectrum of the code. -! -! If p1 (0.le.p1.le.24) is the number of CRC24 bits that are -! to be used for bad codeword detection, then the argument k should -! be set to 77+p1. -! -! Valid values for k are in the range [77,101]. -! - character*24 c24 - integer, parameter:: N=240 - integer*1 apmask(N),apmaskr(N) - integer*1, allocatable, save :: gen(:,:) - integer*1, allocatable :: genmrb(:,:),g2(:,:) - integer*1, allocatable :: temp(:),m0(:),me(:),mi(:),misub(:),e2sub(:),e2(:),ui(:) - integer*1, allocatable :: r2pat(:) - integer indices(N),nxor(N) - integer*1 cw(N),ce(N),c0(N),hdec(N) - integer*1, allocatable :: decoded(:) - integer*1 message101(101) - integer indx(N) - real llr(N),rx(N),absrx(N) - - logical first,reset - data first/.true./ - save first - - allocate( genmrb(k,N), g2(N,k) ) - allocate( temp(k), m0(k), me(k), mi(k), misub(k), e2sub(N-k), e2(N-k), ui(N-k) ) - allocate( r2pat(N-k), decoded(k) ) - - if( first ) then ! fill the generator matrix -! -! Create generator matrix for partial CRC cascaded with LDPC code. -! -! Let p2=101-k and p1+p2=24. -! -! The last p2 bits of the CRC24 are cascaded with the LDPC code. -! -! The first p1=k-77 CRC24 bits will be used for error detection. -! - allocate( gen(k,N) ) - gen=0 - do i=1,k - message101=0 - message101(i)=1 - if(i.le.77) then - call get_crc24(message101,101,ncrc24) - write(c24,'(b24.24)') ncrc24 - read(c24,'(24i1)') message101(78:101) - message101(78:k)=0 - endif - call encode240_101(message101,cw) - gen(i,:)=cw - enddo - - first=.false. - endif - - rx=llr - apmaskr=apmask - -! Hard decisions on the received word. - hdec=0 - where(rx .ge. 0) hdec=1 - -! Use magnitude of received symbols as a measure of reliability. - absrx=abs(rx) - call indexx(absrx,N,indx) - -! Re-order the columns of the generator matrix in order of decreasing reliability. - do i=1,N - genmrb(1:k,i)=gen(1:k,indx(N+1-i)) - indices(i)=indx(N+1-i) - enddo - -! Do gaussian elimination to create a generator matrix with the most reliable -! received bits in positions 1:k in order of decreasing reliability (more or less). - do id=1,k ! diagonal element indices - do icol=id,k+20 ! The 20 is ad hoc - beware - iflag=0 - if( genmrb(id,icol) .eq. 1 ) then - iflag=1 - if( icol .ne. id ) then ! reorder column - temp(1:k)=genmrb(1:k,id) - genmrb(1:k,id)=genmrb(1:k,icol) - genmrb(1:k,icol)=temp(1:k) - itmp=indices(id) - indices(id)=indices(icol) - indices(icol)=itmp - endif - do ii=1,k - if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then - genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) - endif - enddo - exit - endif - enddo - enddo - - g2=transpose(genmrb) - -! The hard decisions for the k MRB bits define the order 0 message, m0. -! Encode m0 using the modified generator matrix to find the "order 0" codeword. -! Flip various combinations of bits in m0 and re-encode to generate a list of -! codewords. Return the member of the list that has the smallest Euclidean -! distance to the received word. - - hdec=hdec(indices) ! hard decisions from received symbols - m0=hdec(1:k) ! zero'th order message - absrx=absrx(indices) - rx=rx(indices) - apmaskr=apmaskr(indices) - - call mrbencode101(m0,c0,g2,N,k) - nxor=ieor(c0,hdec) - nhardmin=sum(nxor) - dmin=sum(nxor*absrx) - - cw=c0 - ntotal=0 - nrejected=0 - npre1=0 - npre2=0 - nt=0 - - if(ndeep.eq.0) goto 998 ! norder=0 - if(ndeep.gt.6) ndeep=6 - if( ndeep.eq. 1) then - nord=1 - npre1=0 - npre2=0 - nt=40 - ntheta=12 - elseif(ndeep.eq.2) then - nord=1 - npre1=1 - npre2=0 - nt=40 - ntheta=12 - elseif(ndeep.eq.3) then - nord=1 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=14 - elseif(ndeep.eq.4) then - nord=2 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=17 - elseif(ndeep.eq.5) then - nord=3 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=15 - elseif(ndeep.eq.6) then - nord=4 - npre1=1 - npre2=1 - nt=95 - ntheta=12 - ntau=15 - endif - - do iorder=1,nord - misub(1:k-iorder)=0 - misub(k-iorder+1:k)=1 - iflag=k-iorder+1 - do while(iflag .ge.0) - if(iorder.eq.nord .and. npre1.eq.0) then - iend=iflag - else - iend=1 - endif - d1=0. - do n1=iflag,iend,-1 - mi=misub - mi(n1)=1 - if(any(iand(apmaskr(1:k),mi).eq.1)) cycle - ntotal=ntotal+1 - me=ieor(m0,mi) - if(n1.eq.iflag) then - call mrbencode101(me,ce,g2,N,k) - e2sub=ieor(ce(k+1:N),hdec(k+1:N)) - e2=e2sub - nd1kpt=sum(e2sub(1:nt))+1 - d1=sum(ieor(me(1:k),hdec(1:k))*absrx(1:k)) - else - e2=ieor(e2sub,g2(k+1:N,n1)) - nd1kpt=sum(e2(1:nt))+2 - endif - if(nd1kpt .le. ntheta) then - call mrbencode101(me,ce,g2,N,k) - nxor=ieor(ce,hdec) - if(n1.eq.iflag) then - dd=d1+sum(e2sub*absrx(k+1:N)) - else - dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(k+1:N)) - endif - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - nd1kptbest=nd1kpt - endif - else - nrejected=nrejected+1 - endif - enddo -! Get the next test error pattern, iflag will go negative -! when the last pattern with weight iorder has been generated. - call nextpat101(misub,k,iorder,iflag) - enddo - enddo - - if(npre2.eq.1) then - reset=.true. - ntotal=0 - do i1=k,1,-1 - do i2=i1-1,1,-1 - ntotal=ntotal+1 - mi(1:ntau)=ieor(g2(k+1:k+ntau,i1),g2(k+1:k+ntau,i2)) - call boxit101(reset,mi(1:ntau),ntau,ntotal,i1,i2) - enddo - enddo - - ncount2=0 - ntotal2=0 - reset=.true. -! Now run through again and do the second pre-processing rule - misub(1:k-nord)=0 - misub(k-nord+1:k)=1 - iflag=k-nord+1 - do while(iflag .ge.0) - me=ieor(m0,misub) - call mrbencode101(me,ce,g2,N,k) - e2sub=ieor(ce(k+1:N),hdec(k+1:N)) - do i2=0,ntau - ntotal2=ntotal2+1 - ui=0 - if(i2.gt.0) ui(i2)=1 - r2pat=ieor(e2sub,ui) -778 continue - call fetchit101(reset,r2pat(1:ntau),ntau,in1,in2) - if(in1.gt.0.and.in2.gt.0) then - ncount2=ncount2+1 - mi=misub - mi(in1)=1 - mi(in2)=1 - if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:k),mi).eq.1)) cycle - me=ieor(m0,mi) - call mrbencode101(me,ce,g2,N,k) - nxor=ieor(ce,hdec) - dd=sum(nxor*absrx) - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - endif - goto 778 - endif - enddo - call nextpat101(misub,k,nord,iflag) - enddo - endif - -998 continue -! Re-order the codeword to [message bits][parity bits] format. - cw(indices)=cw - hdec(indices)=hdec - message101=cw(1:101) - call get_crc24(message101,101,nbadcrc) - if(nbadcrc.ne.0) nhardmin=-nhardmin - - return -end subroutine osd240_101 - -subroutine mrbencode101(me,codeword,g2,N,K) - integer*1 me(K),codeword(N),g2(N,K) -! fast encoding for low-weight test patterns - codeword=0 - do i=1,K - if( me(i) .eq. 1 ) then - codeword=ieor(codeword,g2(1:N,i)) - endif - enddo - return -end subroutine mrbencode101 - -subroutine nextpat101(mi,k,iorder,iflag) - integer*1 mi(k),ms(k) -! generate the next test error pattern - ind=-1 - do i=1,k-1 - if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i - enddo - if( ind .lt. 0 ) then ! no more patterns of this order - iflag=ind - return - endif - ms=0 - ms(1:ind-1)=mi(1:ind-1) - ms(ind)=1 - ms(ind+1)=0 - if( ind+1 .lt. k ) then - nz=iorder-sum(ms) - ms(k-nz+1:k)=1 - endif - mi=ms - do i=1,k ! iflag will point to the lowest-index 1 in mi - if(mi(i).eq.1) then - iflag=i - exit - endif - enddo - return -end subroutine nextpat101 - -subroutine boxit101(reset,e2,ntau,npindex,i1,i2) - integer*1 e2(1:ntau) - integer indexes(5000,2),fp(0:525000),np(5000) - logical reset - common/boxes/indexes,fp,np - - if(reset) then - patterns=-1 - fp=-1 - np=-1 - sc=-1 - indexes=-1 - reset=.false. - endif - - indexes(npindex,1)=i1 - indexes(npindex,2)=i2 - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - - ip=fp(ipat) ! see what's currently stored in fp(ipat) - if(ip.eq.-1) then - fp(ipat)=npindex - else - do while (np(ip).ne.-1) - ip=np(ip) - enddo - np(ip)=npindex - endif - return -end subroutine boxit101 - -subroutine fetchit101(reset,e2,ntau,i1,i2) - integer indexes(5000,2),fp(0:525000),np(5000) - integer lastpat - integer*1 e2(ntau) - logical reset - common/boxes/indexes,fp,np - save lastpat,inext - - if(reset) then - lastpat=-1 - reset=.false. - endif - - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - index=fp(ipat) - - if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices - i1=indexes(index,1) - i2=indexes(index,2) - inext=np(index) - elseif(lastpat.eq.ipat .and. inext.gt.0) then - i1=indexes(inext,1) - i2=indexes(inext,2) - inext=np(inext) - else - i1=-1 - i2=-1 - inext=-1 - endif - lastpat=ipat - return -end subroutine fetchit101 - +subroutine osd240_101(llr,k,apmask,ndeep,message101,cw,nhardmin,dmin) +! +! An ordered-statistics decoder for the (240,101) code. +! Message payload is 77 bits. Any or all of a 24-bit CRC can be +! used for detecting incorrect codewords. The remaining CRC bits are +! cascaded with the LDPC code for the purpose of improving the +! distance spectrum of the code. +! +! If p1 (0.le.p1.le.24) is the number of CRC24 bits that are +! to be used for bad codeword detection, then the argument k should +! be set to 77+p1. +! +! Valid values for k are in the range [77,101]. +! + character*24 c24 + integer, parameter:: N=240 + integer*1 apmask(N),apmaskr(N) + integer*1, allocatable, save :: gen(:,:) + integer*1, allocatable :: genmrb(:,:),g2(:,:) + integer*1, allocatable :: temp(:),m0(:),me(:),mi(:),misub(:),e2sub(:),e2(:),ui(:) + integer*1, allocatable :: r2pat(:) + integer indices(N),nxor(N) + integer*1 cw(N),ce(N),c0(N),hdec(N) + integer*1, allocatable :: decoded(:) + integer*1 message101(101) + integer indx(N) + real llr(N),rx(N),absrx(N) + + logical first,reset + data first/.true./ + save first + + allocate( genmrb(k,N), g2(N,k) ) + allocate( temp(k), m0(k), me(k), mi(k), misub(k), e2sub(N-k), e2(N-k), ui(N-k) ) + allocate( r2pat(N-k), decoded(k) ) + + if( first ) then ! fill the generator matrix +! +! Create generator matrix for partial CRC cascaded with LDPC code. +! +! Let p2=101-k and p1+p2=24. +! +! The last p2 bits of the CRC24 are cascaded with the LDPC code. +! +! The first p1=k-77 CRC24 bits will be used for error detection. +! + allocate( gen(k,N) ) + gen=0 + do i=1,k + message101=0 + message101(i)=1 + if(i.le.77) then + call get_crc24(message101,101,ncrc24) + write(c24,'(b24.24)') ncrc24 + read(c24,'(24i1)') message101(78:101) + message101(78:k)=0 + endif + call encode240_101(message101,cw) + gen(i,:)=cw + enddo + + first=.false. + endif + + rx=llr + apmaskr=apmask + +! Hard decisions on the received word. + hdec=0 + where(rx .ge. 0) hdec=1 + +! Use magnitude of received symbols as a measure of reliability. + absrx=abs(rx) + call indexx(absrx,N,indx) + +! Re-order the columns of the generator matrix in order of decreasing reliability. + do i=1,N + genmrb(1:k,i)=gen(1:k,indx(N+1-i)) + indices(i)=indx(N+1-i) + enddo + +! Do gaussian elimination to create a generator matrix with the most reliable +! received bits in positions 1:k in order of decreasing reliability (more or less). + do id=1,k ! diagonal element indices + do icol=id,k+20 ! The 20 is ad hoc - beware + iflag=0 + if( genmrb(id,icol) .eq. 1 ) then + iflag=1 + if( icol .ne. id ) then ! reorder column + temp(1:k)=genmrb(1:k,id) + genmrb(1:k,id)=genmrb(1:k,icol) + genmrb(1:k,icol)=temp(1:k) + itmp=indices(id) + indices(id)=indices(icol) + indices(icol)=itmp + endif + do ii=1,k + if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then + genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) + endif + enddo + exit + endif + enddo + enddo + + g2=transpose(genmrb) + +! The hard decisions for the k MRB bits define the order 0 message, m0. +! Encode m0 using the modified generator matrix to find the "order 0" codeword. +! Flip various combinations of bits in m0 and re-encode to generate a list of +! codewords. Return the member of the list that has the smallest Euclidean +! distance to the received word. + + hdec=hdec(indices) ! hard decisions from received symbols + m0=hdec(1:k) ! zero'th order message + absrx=absrx(indices) + rx=rx(indices) + apmaskr=apmaskr(indices) + + call mrbencode101(m0,c0,g2,N,k) + nxor=ieor(c0,hdec) + nhardmin=sum(nxor) + dmin=sum(nxor*absrx) + + cw=c0 + ntotal=0 + nrejected=0 + npre1=0 + npre2=0 + nt=0 + + if(ndeep.eq.0) goto 998 ! norder=0 + if(ndeep.gt.6) ndeep=6 + if( ndeep.eq. 1) then + nord=1 + npre1=0 + npre2=0 + nt=40 + ntheta=12 + elseif(ndeep.eq.2) then + nord=1 + npre1=1 + npre2=0 + nt=40 + ntheta=12 + elseif(ndeep.eq.3) then + nord=1 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=14 + elseif(ndeep.eq.4) then + nord=2 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=17 + elseif(ndeep.eq.5) then + nord=3 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=15 + elseif(ndeep.eq.6) then + nord=4 + npre1=1 + npre2=1 + nt=95 + ntheta=12 + ntau=15 + endif + + do iorder=1,nord + misub(1:k-iorder)=0 + misub(k-iorder+1:k)=1 + iflag=k-iorder+1 + do while(iflag .ge.0) + if(iorder.eq.nord .and. npre1.eq.0) then + iend=iflag + else + iend=1 + endif + d1=0. + do n1=iflag,iend,-1 + mi=misub + mi(n1)=1 + if(any(iand(apmaskr(1:k),mi).eq.1)) cycle + ntotal=ntotal+1 + me=ieor(m0,mi) + if(n1.eq.iflag) then + call mrbencode101(me,ce,g2,N,k) + e2sub=ieor(ce(k+1:N),hdec(k+1:N)) + e2=e2sub + nd1kpt=sum(e2sub(1:nt))+1 + d1=sum(ieor(me(1:k),hdec(1:k))*absrx(1:k)) + else + e2=ieor(e2sub,g2(k+1:N,n1)) + nd1kpt=sum(e2(1:nt))+2 + endif + if(nd1kpt .le. ntheta) then + call mrbencode101(me,ce,g2,N,k) + nxor=ieor(ce,hdec) + if(n1.eq.iflag) then + dd=d1+sum(e2sub*absrx(k+1:N)) + else + dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(k+1:N)) + endif + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + nd1kptbest=nd1kpt + endif + else + nrejected=nrejected+1 + endif + enddo +! Get the next test error pattern, iflag will go negative +! when the last pattern with weight iorder has been generated. + call nextpat101(misub,k,iorder,iflag) + enddo + enddo + + if(npre2.eq.1) then + reset=.true. + ntotal=0 + do i1=k,1,-1 + do i2=i1-1,1,-1 + ntotal=ntotal+1 + mi(1:ntau)=ieor(g2(k+1:k+ntau,i1),g2(k+1:k+ntau,i2)) + call boxit101(reset,mi(1:ntau),ntau,ntotal,i1,i2) + enddo + enddo + + ncount2=0 + ntotal2=0 + reset=.true. +! Now run through again and do the second pre-processing rule + misub(1:k-nord)=0 + misub(k-nord+1:k)=1 + iflag=k-nord+1 + do while(iflag .ge.0) + me=ieor(m0,misub) + call mrbencode101(me,ce,g2,N,k) + e2sub=ieor(ce(k+1:N),hdec(k+1:N)) + do i2=0,ntau + ntotal2=ntotal2+1 + ui=0 + if(i2.gt.0) ui(i2)=1 + r2pat=ieor(e2sub,ui) +778 continue + call fetchit101(reset,r2pat(1:ntau),ntau,in1,in2) + if(in1.gt.0.and.in2.gt.0) then + ncount2=ncount2+1 + mi=misub + mi(in1)=1 + mi(in2)=1 + if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:k),mi).eq.1)) cycle + me=ieor(m0,mi) + call mrbencode101(me,ce,g2,N,k) + nxor=ieor(ce,hdec) + dd=sum(nxor*absrx) + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + endif + goto 778 + endif + enddo + call nextpat101(misub,k,nord,iflag) + enddo + endif + +998 continue +! Re-order the codeword to [message bits][parity bits] format. + cw(indices)=cw + hdec(indices)=hdec + message101=cw(1:101) + call get_crc24(message101,101,nbadcrc) + if(nbadcrc.ne.0) nhardmin=-nhardmin + + return +end subroutine osd240_101 + +subroutine mrbencode101(me,codeword,g2,N,K) + integer*1 me(K),codeword(N),g2(N,K) +! fast encoding for low-weight test patterns + codeword=0 + do i=1,K + if( me(i) .eq. 1 ) then + codeword=ieor(codeword,g2(1:N,i)) + endif + enddo + return +end subroutine mrbencode101 + +subroutine nextpat101(mi,k,iorder,iflag) + integer*1 mi(k),ms(k) +! generate the next test error pattern + ind=-1 + do i=1,k-1 + if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i + enddo + if( ind .lt. 0 ) then ! no more patterns of this order + iflag=ind + return + endif + ms=0 + ms(1:ind-1)=mi(1:ind-1) + ms(ind)=1 + ms(ind+1)=0 + if( ind+1 .lt. k ) then + nz=iorder-sum(ms) + ms(k-nz+1:k)=1 + endif + mi=ms + do i=1,k ! iflag will point to the lowest-index 1 in mi + if(mi(i).eq.1) then + iflag=i + exit + endif + enddo + return +end subroutine nextpat101 + +subroutine boxit101(reset,e2,ntau,npindex,i1,i2) + integer*1 e2(1:ntau) + integer indexes(5000,2),fp(0:525000),np(5000) + logical reset + common/boxes/indexes,fp,np + + if(reset) then + patterns=-1 + fp=-1 + np=-1 + sc=-1 + indexes=-1 + reset=.false. + endif + + indexes(npindex,1)=i1 + indexes(npindex,2)=i2 + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + + ip=fp(ipat) ! see what's currently stored in fp(ipat) + if(ip.eq.-1) then + fp(ipat)=npindex + else + do while (np(ip).ne.-1) + ip=np(ip) + enddo + np(ip)=npindex + endif + return +end subroutine boxit101 + +subroutine fetchit101(reset,e2,ntau,i1,i2) + integer indexes(5000,2),fp(0:525000),np(5000) + integer lastpat + integer*1 e2(ntau) + logical reset + common/boxes/indexes,fp,np + save lastpat,inext + + if(reset) then + lastpat=-1 + reset=.false. + endif + + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + index=fp(ipat) + + if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices + i1=indexes(index,1) + i2=indexes(index,2) + inext=np(index) + elseif(lastpat.eq.ipat .and. inext.gt.0) then + i1=indexes(inext,1) + i2=indexes(inext,2) + inext=np(inext) + else + i1=-1 + i2=-1 + inext=-1 + endif + lastpat=ipat + return +end subroutine fetchit101 + diff --git a/lib/fst4/osd240_74.f90 b/lib/fst4/osd240_74.f90 index 0088a852..a54e767b 100755 --- a/lib/fst4/osd240_74.f90 +++ b/lib/fst4/osd240_74.f90 @@ -1,404 +1,404 @@ -subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin) -! -! An ordered-statistics decoder for the (240,74) code. -! Message payload is 50 bits. Any or all of a 24-bit CRC can be -! used for detecting incorrect codewords. The remaining CRC bits are -! cascaded with the LDPC code for the purpose of improving the -! distance spectrum of the code. -! -! If p1 (0.le.p1.le.24) is the number of CRC24 bits that are -! to be used for bad codeword detection, then the argument k should -! be set to 77+p1. -! -! Valid values for k are in the range [50,74]. -! - character*24 c24 - integer, parameter:: N=240 - integer*1 apmask(N),apmaskr(N) - integer*1, allocatable, save :: gen(:,:) - integer*1, allocatable :: genmrb(:,:),g2(:,:) - integer*1, allocatable :: temp(:),m0(:),me(:),mi(:),misub(:),e2sub(:),e2(:),ui(:) - integer*1, allocatable :: r2pat(:) - integer indices(N),nxor(N) - integer*1 cw(N),ce(N),c0(N),hdec(N) - integer*1, allocatable :: decoded(:) - integer*1 message74(74) - integer indx(N) - real llr(N),rx(N),absrx(N) - - logical first,reset - data first/.true./ - save first - - allocate( genmrb(k,N), g2(N,k) ) - allocate( temp(k), m0(k), me(k), mi(k), misub(k), e2sub(N-k), e2(N-k), ui(N-k) ) - allocate( r2pat(N-k), decoded(k) ) - - if( first ) then ! fill the generator matrix -! -! Create generator matrix for partial CRC cascaded with LDPC code. -! -! Let p2=74-k and p1+p2=24. -! -! The last p2 bits of the CRC24 are cascaded with the LDPC code. -! -! The first p1=k-50 CRC24 bits will be used for error detection. -! - allocate( gen(k,N) ) - gen=0 - do i=1,k - message74=0 - message74(i)=1 - if(i.le.50) then - call get_crc24(message74,74,ncrc24) - write(c24,'(b24.24)') ncrc24 - read(c24,'(24i1)') message74(51:74) - message74(51:k)=0 - endif - call encode240_74(message74,cw) - gen(i,:)=cw - enddo - - first=.false. - endif - - rx=llr - apmaskr=apmask - -! Hard decisions on the received word. - hdec=0 - where(rx .ge. 0) hdec=1 - -! Use magnitude of received symbols as a measure of reliability. - absrx=abs(rx) - call indexx(absrx,N,indx) - -! Re-order the columns of the generator matrix in order of decreasing reliability. - do i=1,N - genmrb(1:k,i)=gen(1:k,indx(N+1-i)) - indices(i)=indx(N+1-i) - enddo - -! Do gaussian elimination to create a generator matrix with the most reliable -! received bits in positions 1:k in order of decreasing reliability (more or less). - do id=1,k ! diagonal element indices - do icol=id,k+20 ! The 20 is ad hoc - beware - iflag=0 - if( genmrb(id,icol) .eq. 1 ) then - iflag=1 - if( icol .ne. id ) then ! reorder column - temp(1:k)=genmrb(1:k,id) - genmrb(1:k,id)=genmrb(1:k,icol) - genmrb(1:k,icol)=temp(1:k) - itmp=indices(id) - indices(id)=indices(icol) - indices(icol)=itmp - endif - do ii=1,k - if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then - genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) - endif - enddo - exit - endif - enddo - enddo - - g2=transpose(genmrb) - -! The hard decisions for the k MRB bits define the order 0 message, m0. -! Encode m0 using the modified generator matrix to find the "order 0" codeword. -! Flip various combinations of bits in m0 and re-encode to generate a list of -! codewords. Return the member of the list that has the smallest Euclidean -! distance to the received word. - - hdec=hdec(indices) ! hard decisions from received symbols - m0=hdec(1:k) ! zero'th order message - absrx=absrx(indices) - rx=rx(indices) - apmaskr=apmaskr(indices) - - call mrbencode74(m0,c0,g2,N,k) - nxor=ieor(c0,hdec) - nhardmin=sum(nxor) - dmin=sum(nxor*absrx) - - cw=c0 - ntotal=0 - nrejected=0 - npre1=0 - npre2=0 - nt=0 - - if(ndeep.eq.0) goto 998 ! norder=0 - if(ndeep.gt.6) ndeep=6 - if( ndeep.eq. 1) then - nord=1 - npre1=0 - npre2=0 - nt=40 - ntheta=12 - elseif(ndeep.eq.2) then - nord=1 - npre1=1 - npre2=0 - nt=40 - ntheta=12 - elseif(ndeep.eq.3) then - nord=1 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=14 - elseif(ndeep.eq.4) then - nord=2 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=17 - elseif(ndeep.eq.5) then - nord=3 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=15 - elseif(ndeep.eq.6) then - nord=4 - npre1=1 - npre2=1 - nt=95 - ntheta=12 - ntau=15 - endif - - do iorder=1,nord - misub(1:k-iorder)=0 - misub(k-iorder+1:k)=1 - iflag=k-iorder+1 - do while(iflag .ge.0) - if(iorder.eq.nord .and. npre1.eq.0) then - iend=iflag - else - iend=1 - endif - d1=0. - do n1=iflag,iend,-1 - mi=misub - mi(n1)=1 - if(any(iand(apmaskr(1:k),mi).eq.1)) cycle - ntotal=ntotal+1 - me=ieor(m0,mi) - if(n1.eq.iflag) then - call mrbencode74(me,ce,g2,N,k) - e2sub=ieor(ce(k+1:N),hdec(k+1:N)) - e2=e2sub - nd1kpt=sum(e2sub(1:nt))+1 - d1=sum(ieor(me(1:k),hdec(1:k))*absrx(1:k)) - else - e2=ieor(e2sub,g2(k+1:N,n1)) - nd1kpt=sum(e2(1:nt))+2 - endif - if(nd1kpt .le. ntheta) then - call mrbencode74(me,ce,g2,N,k) - nxor=ieor(ce,hdec) - if(n1.eq.iflag) then - dd=d1+sum(e2sub*absrx(k+1:N)) - else - dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(k+1:N)) - endif - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - nd1kptbest=nd1kpt - endif - else - nrejected=nrejected+1 - endif - enddo -! Get the next test error pattern, iflag will go negative -! when the last pattern with weight iorder has been generated. - call nextpat74(misub,k,iorder,iflag) - enddo - enddo - - if(npre2.eq.1) then - reset=.true. - ntotal=0 - do i1=k,1,-1 - do i2=i1-1,1,-1 - ntotal=ntotal+1 - mi(1:ntau)=ieor(g2(k+1:k+ntau,i1),g2(k+1:k+ntau,i2)) - call boxit74(reset,mi(1:ntau),ntau,ntotal,i1,i2) - enddo - enddo - - ncount2=0 - ntotal2=0 - reset=.true. -! Now run through again and do the second pre-processing rule - misub(1:k-nord)=0 - misub(k-nord+1:k)=1 - iflag=k-nord+1 - do while(iflag .ge.0) - me=ieor(m0,misub) - call mrbencode74(me,ce,g2,N,k) - e2sub=ieor(ce(k+1:N),hdec(k+1:N)) - do i2=0,ntau - ntotal2=ntotal2+1 - ui=0 - if(i2.gt.0) ui(i2)=1 - r2pat=ieor(e2sub,ui) -778 continue - call fetchit74(reset,r2pat(1:ntau),ntau,in1,in2) - if(in1.gt.0.and.in2.gt.0) then - ncount2=ncount2+1 - mi=misub - mi(in1)=1 - mi(in2)=1 - if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:k),mi).eq.1)) cycle - me=ieor(m0,mi) - call mrbencode74(me,ce,g2,N,k) - nxor=ieor(ce,hdec) - dd=sum(nxor*absrx) - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - endif - goto 778 - endif - enddo - call nextpat74(misub,k,nord,iflag) - enddo - endif - -998 continue -! Re-order the codeword to [message bits][parity bits] format. - cw(indices)=cw - hdec(indices)=hdec - message74=cw(1:74) - call get_crc24(message74,74,nbadcrc) - if(nbadcrc.ne.0) nhardmin=-nhardmin - - return -end subroutine osd240_74 - -subroutine mrbencode74(me,codeword,g2,N,K) - integer*1 me(K),codeword(N),g2(N,K) -! fast encoding for low-weight test patterns - codeword=0 - do i=1,K - if( me(i) .eq. 1 ) then - codeword=ieor(codeword,g2(1:N,i)) - endif - enddo - return -end subroutine mrbencode74 - -subroutine nextpat74(mi,k,iorder,iflag) - integer*1 mi(k),ms(k) -! generate the next test error pattern - ind=-1 - do i=1,k-1 - if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i - enddo - if( ind .lt. 0 ) then ! no more patterns of this order - iflag=ind - return - endif - ms=0 - ms(1:ind-1)=mi(1:ind-1) - ms(ind)=1 - ms(ind+1)=0 - if( ind+1 .lt. k ) then - nz=iorder-sum(ms) - ms(k-nz+1:k)=1 - endif - mi=ms - do i=1,k ! iflag will point to the lowest-index 1 in mi - if(mi(i).eq.1) then - iflag=i - exit - endif - enddo - return -end subroutine nextpat74 - -subroutine boxit74(reset,e2,ntau,npindex,i1,i2) - integer*1 e2(1:ntau) - integer indexes(5000,2),fp(0:525000),np(5000) - logical reset - common/boxes/indexes,fp,np - - if(reset) then - patterns=-1 - fp=-1 - np=-1 - sc=-1 - indexes=-1 - reset=.false. - endif - - indexes(npindex,1)=i1 - indexes(npindex,2)=i2 - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - - ip=fp(ipat) ! see what's currently stored in fp(ipat) - if(ip.eq.-1) then - fp(ipat)=npindex - else - do while (np(ip).ne.-1) - ip=np(ip) - enddo - np(ip)=npindex - endif - return -end subroutine boxit74 - -subroutine fetchit74(reset,e2,ntau,i1,i2) - integer indexes(5000,2),fp(0:525000),np(5000) - integer lastpat - integer*1 e2(ntau) - logical reset - common/boxes/indexes,fp,np - save lastpat,inext - - if(reset) then - lastpat=-1 - reset=.false. - endif - - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - index=fp(ipat) - - if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices - i1=indexes(index,1) - i2=indexes(index,2) - inext=np(index) - elseif(lastpat.eq.ipat .and. inext.gt.0) then - i1=indexes(inext,1) - i2=indexes(inext,2) - inext=np(inext) - else - i1=-1 - i2=-1 - inext=-1 - endif - lastpat=ipat - return -end subroutine fetchit74 - +subroutine osd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin) +! +! An ordered-statistics decoder for the (240,74) code. +! Message payload is 50 bits. Any or all of a 24-bit CRC can be +! used for detecting incorrect codewords. The remaining CRC bits are +! cascaded with the LDPC code for the purpose of improving the +! distance spectrum of the code. +! +! If p1 (0.le.p1.le.24) is the number of CRC24 bits that are +! to be used for bad codeword detection, then the argument k should +! be set to 77+p1. +! +! Valid values for k are in the range [50,74]. +! + character*24 c24 + integer, parameter:: N=240 + integer*1 apmask(N),apmaskr(N) + integer*1, allocatable, save :: gen(:,:) + integer*1, allocatable :: genmrb(:,:),g2(:,:) + integer*1, allocatable :: temp(:),m0(:),me(:),mi(:),misub(:),e2sub(:),e2(:),ui(:) + integer*1, allocatable :: r2pat(:) + integer indices(N),nxor(N) + integer*1 cw(N),ce(N),c0(N),hdec(N) + integer*1, allocatable :: decoded(:) + integer*1 message74(74) + integer indx(N) + real llr(N),rx(N),absrx(N) + + logical first,reset + data first/.true./ + save first + + allocate( genmrb(k,N), g2(N,k) ) + allocate( temp(k), m0(k), me(k), mi(k), misub(k), e2sub(N-k), e2(N-k), ui(N-k) ) + allocate( r2pat(N-k), decoded(k) ) + + if( first ) then ! fill the generator matrix +! +! Create generator matrix for partial CRC cascaded with LDPC code. +! +! Let p2=74-k and p1+p2=24. +! +! The last p2 bits of the CRC24 are cascaded with the LDPC code. +! +! The first p1=k-50 CRC24 bits will be used for error detection. +! + allocate( gen(k,N) ) + gen=0 + do i=1,k + message74=0 + message74(i)=1 + if(i.le.50) then + call get_crc24(message74,74,ncrc24) + write(c24,'(b24.24)') ncrc24 + read(c24,'(24i1)') message74(51:74) + message74(51:k)=0 + endif + call encode240_74(message74,cw) + gen(i,:)=cw + enddo + + first=.false. + endif + + rx=llr + apmaskr=apmask + +! Hard decisions on the received word. + hdec=0 + where(rx .ge. 0) hdec=1 + +! Use magnitude of received symbols as a measure of reliability. + absrx=abs(rx) + call indexx(absrx,N,indx) + +! Re-order the columns of the generator matrix in order of decreasing reliability. + do i=1,N + genmrb(1:k,i)=gen(1:k,indx(N+1-i)) + indices(i)=indx(N+1-i) + enddo + +! Do gaussian elimination to create a generator matrix with the most reliable +! received bits in positions 1:k in order of decreasing reliability (more or less). + do id=1,k ! diagonal element indices + do icol=id,k+20 ! The 20 is ad hoc - beware + iflag=0 + if( genmrb(id,icol) .eq. 1 ) then + iflag=1 + if( icol .ne. id ) then ! reorder column + temp(1:k)=genmrb(1:k,id) + genmrb(1:k,id)=genmrb(1:k,icol) + genmrb(1:k,icol)=temp(1:k) + itmp=indices(id) + indices(id)=indices(icol) + indices(icol)=itmp + endif + do ii=1,k + if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then + genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) + endif + enddo + exit + endif + enddo + enddo + + g2=transpose(genmrb) + +! The hard decisions for the k MRB bits define the order 0 message, m0. +! Encode m0 using the modified generator matrix to find the "order 0" codeword. +! Flip various combinations of bits in m0 and re-encode to generate a list of +! codewords. Return the member of the list that has the smallest Euclidean +! distance to the received word. + + hdec=hdec(indices) ! hard decisions from received symbols + m0=hdec(1:k) ! zero'th order message + absrx=absrx(indices) + rx=rx(indices) + apmaskr=apmaskr(indices) + + call mrbencode74(m0,c0,g2,N,k) + nxor=ieor(c0,hdec) + nhardmin=sum(nxor) + dmin=sum(nxor*absrx) + + cw=c0 + ntotal=0 + nrejected=0 + npre1=0 + npre2=0 + nt=0 + + if(ndeep.eq.0) goto 998 ! norder=0 + if(ndeep.gt.6) ndeep=6 + if( ndeep.eq. 1) then + nord=1 + npre1=0 + npre2=0 + nt=40 + ntheta=12 + elseif(ndeep.eq.2) then + nord=1 + npre1=1 + npre2=0 + nt=40 + ntheta=12 + elseif(ndeep.eq.3) then + nord=1 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=14 + elseif(ndeep.eq.4) then + nord=2 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=17 + elseif(ndeep.eq.5) then + nord=3 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=15 + elseif(ndeep.eq.6) then + nord=4 + npre1=1 + npre2=1 + nt=95 + ntheta=12 + ntau=15 + endif + + do iorder=1,nord + misub(1:k-iorder)=0 + misub(k-iorder+1:k)=1 + iflag=k-iorder+1 + do while(iflag .ge.0) + if(iorder.eq.nord .and. npre1.eq.0) then + iend=iflag + else + iend=1 + endif + d1=0. + do n1=iflag,iend,-1 + mi=misub + mi(n1)=1 + if(any(iand(apmaskr(1:k),mi).eq.1)) cycle + ntotal=ntotal+1 + me=ieor(m0,mi) + if(n1.eq.iflag) then + call mrbencode74(me,ce,g2,N,k) + e2sub=ieor(ce(k+1:N),hdec(k+1:N)) + e2=e2sub + nd1kpt=sum(e2sub(1:nt))+1 + d1=sum(ieor(me(1:k),hdec(1:k))*absrx(1:k)) + else + e2=ieor(e2sub,g2(k+1:N,n1)) + nd1kpt=sum(e2(1:nt))+2 + endif + if(nd1kpt .le. ntheta) then + call mrbencode74(me,ce,g2,N,k) + nxor=ieor(ce,hdec) + if(n1.eq.iflag) then + dd=d1+sum(e2sub*absrx(k+1:N)) + else + dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(k+1:N)) + endif + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + nd1kptbest=nd1kpt + endif + else + nrejected=nrejected+1 + endif + enddo +! Get the next test error pattern, iflag will go negative +! when the last pattern with weight iorder has been generated. + call nextpat74(misub,k,iorder,iflag) + enddo + enddo + + if(npre2.eq.1) then + reset=.true. + ntotal=0 + do i1=k,1,-1 + do i2=i1-1,1,-1 + ntotal=ntotal+1 + mi(1:ntau)=ieor(g2(k+1:k+ntau,i1),g2(k+1:k+ntau,i2)) + call boxit74(reset,mi(1:ntau),ntau,ntotal,i1,i2) + enddo + enddo + + ncount2=0 + ntotal2=0 + reset=.true. +! Now run through again and do the second pre-processing rule + misub(1:k-nord)=0 + misub(k-nord+1:k)=1 + iflag=k-nord+1 + do while(iflag .ge.0) + me=ieor(m0,misub) + call mrbencode74(me,ce,g2,N,k) + e2sub=ieor(ce(k+1:N),hdec(k+1:N)) + do i2=0,ntau + ntotal2=ntotal2+1 + ui=0 + if(i2.gt.0) ui(i2)=1 + r2pat=ieor(e2sub,ui) +778 continue + call fetchit74(reset,r2pat(1:ntau),ntau,in1,in2) + if(in1.gt.0.and.in2.gt.0) then + ncount2=ncount2+1 + mi=misub + mi(in1)=1 + mi(in2)=1 + if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:k),mi).eq.1)) cycle + me=ieor(m0,mi) + call mrbencode74(me,ce,g2,N,k) + nxor=ieor(ce,hdec) + dd=sum(nxor*absrx) + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + endif + goto 778 + endif + enddo + call nextpat74(misub,k,nord,iflag) + enddo + endif + +998 continue +! Re-order the codeword to [message bits][parity bits] format. + cw(indices)=cw + hdec(indices)=hdec + message74=cw(1:74) + call get_crc24(message74,74,nbadcrc) + if(nbadcrc.ne.0) nhardmin=-nhardmin + + return +end subroutine osd240_74 + +subroutine mrbencode74(me,codeword,g2,N,K) + integer*1 me(K),codeword(N),g2(N,K) +! fast encoding for low-weight test patterns + codeword=0 + do i=1,K + if( me(i) .eq. 1 ) then + codeword=ieor(codeword,g2(1:N,i)) + endif + enddo + return +end subroutine mrbencode74 + +subroutine nextpat74(mi,k,iorder,iflag) + integer*1 mi(k),ms(k) +! generate the next test error pattern + ind=-1 + do i=1,k-1 + if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i + enddo + if( ind .lt. 0 ) then ! no more patterns of this order + iflag=ind + return + endif + ms=0 + ms(1:ind-1)=mi(1:ind-1) + ms(ind)=1 + ms(ind+1)=0 + if( ind+1 .lt. k ) then + nz=iorder-sum(ms) + ms(k-nz+1:k)=1 + endif + mi=ms + do i=1,k ! iflag will point to the lowest-index 1 in mi + if(mi(i).eq.1) then + iflag=i + exit + endif + enddo + return +end subroutine nextpat74 + +subroutine boxit74(reset,e2,ntau,npindex,i1,i2) + integer*1 e2(1:ntau) + integer indexes(5000,2),fp(0:525000),np(5000) + logical reset + common/boxes/indexes,fp,np + + if(reset) then + patterns=-1 + fp=-1 + np=-1 + sc=-1 + indexes=-1 + reset=.false. + endif + + indexes(npindex,1)=i1 + indexes(npindex,2)=i2 + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + + ip=fp(ipat) ! see what's currently stored in fp(ipat) + if(ip.eq.-1) then + fp(ipat)=npindex + else + do while (np(ip).ne.-1) + ip=np(ip) + enddo + np(ip)=npindex + endif + return +end subroutine boxit74 + +subroutine fetchit74(reset,e2,ntau,i1,i2) + integer indexes(5000,2),fp(0:525000),np(5000) + integer lastpat + integer*1 e2(ntau) + logical reset + common/boxes/indexes,fp,np + save lastpat,inext + + if(reset) then + lastpat=-1 + reset=.false. + endif + + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + index=fp(ipat) + + if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices + i1=indexes(index,1) + i2=indexes(index,2) + inext=np(index) + elseif(lastpat.eq.ipat .and. inext.gt.0) then + i1=indexes(inext,1) + i2=indexes(inext,2) + inext=np(inext) + else + i1=-1 + i2=-1 + inext=-1 + endif + lastpat=ipat + return +end subroutine fetchit74 + diff --git a/lib/fst4_decode.f90 b/lib/fst4_decode.f90 index f2ccd2da..0e7d8d67 100755 --- a/lib/fst4_decode.f90 +++ b/lib/fst4_decode.f90 @@ -1,1025 +1,1025 @@ -module fst4_decode - - type :: fst4_decoder - procedure(fst4_decode_callback), pointer :: callback - contains - procedure :: decode - end type fst4_decoder - - abstract interface - subroutine fst4_decode_callback (this,nutc,sync,nsnr,dt,freq, & - decoded,nap,qual,ntrperiod,fmid,w50) - import fst4_decoder - implicit none - class(fst4_decoder), intent(inout) :: this - integer, intent(in) :: nutc - real, intent(in) :: sync - integer, intent(in) :: nsnr - real, intent(in) :: dt - real, intent(in) :: freq - character(len=37), intent(in) :: decoded - integer, intent(in) :: nap - real, intent(in) :: qual - integer, intent(in) :: ntrperiod - real, intent(in) :: fmid - real, intent(in) :: w50 - end subroutine fst4_decode_callback - end interface - -contains - - subroutine decode(this,callback,iwave,nutc,nQSOProgress,nfa,nfb,nfqso, & - ndepth,ntrperiod,nexp_decode,ntol,emedelay,lagain,lapcqonly,mycall, & - hiscall,iwspr,lprinthash22) - - use prog_args - use timer_module, only: timer - use packjt77 - use, intrinsic :: iso_c_binding - include 'fst4/fst4_params.f90' - parameter (MAXCAND=100,MAXWCALLS=100) - class(fst4_decoder), intent(inout) :: this - procedure(fst4_decode_callback) :: callback - character*37 decodes(100) - character*37 msg,msgsent - character*20 wcalls(MAXWCALLS), wpart - character*77 c77 - character*12 mycall,hiscall - character*12 mycall0,hiscall0 - complex, allocatable :: c2(:) - complex, allocatable :: cframe(:) - complex, allocatable :: c_bigfft(:) !Complex waveform - real llr(240),llrs(240,4) - real candidates0(200,5),candidates(200,5) - real bitmetrics(320,4) - real s4(0:3,NN) - real minsync - logical lagain,lapcqonly - integer itone(NN) - integer hmod - integer*1 apmask(240),cw(240),hdec(240) - integer*1 message101(101),message74(74),message77(77) - integer*1 rvec(77) - integer apbits(240) - integer nappasses(0:5) ! # of decoding passes for QSO states 0-5 - integer naptypes(0:5,4) ! (nQSOProgress,decoding pass) - integer mcq(29),mrrr(19),m73(19),mrr73(19) - - logical badsync,unpk77_success,single_decode - logical first,nohiscall - logical new_callsign,plotspec_exists,wcalls_exists,do_k50_decode - logical decdata_exists - logical lprinthash22 - - integer*2 iwave(30*60*12000) - - data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/ - data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/ - data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/ - data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/ - data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & - 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & - 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ - data first/.true./,hmod/1/ - save first,apbits,nappasses,naptypes,mycall0,hiscall0 - save wcalls,nwcalls - - this%callback => callback - dxcall13=hiscall ! initialize for use in packjt77 - mycall13=mycall - - if(iwspr.ne.0 .and. iwspr.ne.1) return - - if(lagain) continue ! use lagain to keep compiler happy - - if(first) then -! read the fst4_calls.txt file - inquire(file=trim(data_dir)//'/fst4w_calls.txt',exist=wcalls_exists) - if( wcalls_exists ) then - open(42,file=trim(data_dir)//'/fst4w_calls.txt',status='unknown') - do i=1,MAXWCALLS - wcalls(i)='' - read(42,fmt='(a)',end=2867) wcalls(i) - wcalls(i)=adjustl(wcalls(i)) - if(len(trim(wcalls(i))).eq.0) exit - enddo -2867 nwcalls=i-1 - close(42) - endif - - mcq=2*mod(mcq+rvec(1:29),2)-1 - mrrr=2*mod(mrrr+rvec(59:77),2)-1 - m73=2*mod(m73+rvec(59:77),2)-1 - mrr73=2*mod(mrr73+rvec(59:77),2)-1 - - nappasses(0)=2 - nappasses(1)=2 - nappasses(2)=2 - nappasses(3)=2 - nappasses(4)=2 - nappasses(5)=3 - -! iaptype -!------------------------ -! 1 CQ ??? ??? (29 ap bits) -! 2 MyCall ??? ??? (29 ap bits) -! 3 MyCall DxCall ??? (58 ap bits) -! 4 MyCall DxCall RRR (77 ap bits) -! 5 MyCall DxCall 73 (77 ap bits) -! 6 MyCall DxCall RR73 (77 ap bits) -!******** - - naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ) - naptypes(1,1:4)=(/2,3,0,0/) ! Tx1 - naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 - naptypes(3,1:4)=(/3,6,0,0/) ! Tx3 - naptypes(4,1:4)=(/3,6,0,0/) ! Tx4 - naptypes(5,1:4)=(/3,1,2,0/) ! Tx5 - - mycall0='' - hiscall0='' - first=.false. - endif - - l1=index(mycall,char(0)) - if(l1.ne.0) mycall(l1:)=" " - l1=index(hiscall,char(0)) - if(l1.ne.0) hiscall(l1:)=" " - if(mycall.ne.mycall0 .or. hiscall.ne.hiscall0) then - apbits=0 - apbits(1)=99 - apbits(30)=99 - - if(len(trim(mycall)) .lt. 3) go to 10 - - nohiscall=.false. - hiscall0=hiscall - if(len(trim(hiscall0)).lt.3) then - hiscall0=mycall ! use mycall for dummy hiscall - mycall won't be hashed. - nohiscall=.true. - endif - msg=trim(mycall)//' '//trim(hiscall0)//' RR73' - i3=-1 - n3=-1 - call pack77(msg,i3,n3,c77) - call unpack77(c77,1,msgsent,unpk77_success) - if(i3.ne.1 .or. (msg.ne.msgsent) .or. .not.unpk77_success) go to 10 - read(c77,'(77i1)') message77 - message77=mod(message77+rvec,2) - apbits(1:77)=2*message77-1 - if(nohiscall) apbits(30)=99 - -10 continue - mycall0=mycall - hiscall0=hiscall - endif -!************************************ - - if(nfqso+nqsoprogress.eq.-999) return - Keff=91 - nmax=15*12000 - if(ntrperiod.eq.15) then - nsps=720 - nmax=15*12000 - ndown=18 !nss=40,80,160,400 - nfft1=int(nmax/ndown)*ndown - else if(ntrperiod.eq.30) then - nsps=1680 - nmax=30*12000 - ndown=42 !nss=40,80,168,336 - nfft1=359856 !nfft2=8568=2^3*3^2*7*17 - else if(ntrperiod.eq.60) then - nsps=3888 - nmax=60*12000 - ndown=108 - nfft1=7500*96 ! nfft2=7500=2^2*3*5^4 - else if(ntrperiod.eq.120) then - nsps=8200 - nmax=120*12000 - ndown=205 !nss=40,82,164,328 - nfft1=7200*200 ! nfft2=7200=2^5*3^2*5^2 - else if(ntrperiod.eq.300) then - nsps=21504 - nmax=300*12000 - ndown=512 !nss=42,84,168,336 - nfft1=7020*512 ! nfft2=7020=2^2*3^3*5*13 - else if(ntrperiod.eq.900) then - nsps=66560 - nmax=900*12000 - ndown=1664 !nss=40,80,160,320 - nfft1=6480*1664 ! nfft2=6480=2^4*3^4*5 - else if(ntrperiod.eq.1800) then - nsps=134400 - nmax=1800*12000 - ndown=3360 !nss=40,80,160,320 - nfft1=6426*3360 ! nfft2=6426=2*3^3*7*17 - end if - nss=nsps/ndown - fs=12000.0 !Sample rate - fs2=fs/ndown - nspsec=nint(fs2) - dt=1.0/fs !Sample interval (s) - dt2=1.0/fs2 - tt=nsps*dt !Duration of "itone" symbols (s) - baud=1.0/tt - sigbw=4.0*baud - nfft2=nfft1/ndown !make sure that nfft1 is exactly nfft2*ndown - nfft1=nfft2*ndown - nh1=nfft1/2 - - allocate( c_bigfft(0:nfft1/2) ) - allocate( c2(0:nfft2-1) ) - allocate( cframe(0:160*nss-1) ) - - jittermax=2 - do_k50_decode=.false. - if(ndepth.eq.3) then - nblock=4 - jittermax=2 - do_k50_decode=.true. - elseif(ndepth.eq.2) then - nblock=4 - jittermax=2 - do_k50_decode=.false. - elseif(ndepth.eq.1) then - nblock=4 - jittermax=0 - do_k50_decode=.false. - endif - -! Noise blanker setup - ndropmax=1 - single_decode=iand(nexp_decode,32).ne.0 - npct=0 - nb=nexp_decode/256 - 3 - if(nb.ge.0) npct=nb - inb1=20 - inb2=5 - if(nb.eq.-1) then - inb2=5 !Try NB = 0, 5, 10, 15, 20% - else if(nb.eq.-2) then - inb2=2 !Try NB = 0, 2, 4,... 20% - else if(nb.eq.-3) then - inb2=1 !Try NB = 0, 1, 2,... 20% - else - inb1=0 !Fixed NB value, 0 to 25% - endif - - -! nfa,nfb: define the noise-baseline analysis window -! fa, fb: define the signal search window -! We usually make nfafb so that noise baseline analysis -! window extends outside of the [fa,fb] window where we think the signals are. -! - if(iwspr.eq.1) then !FST4W - nfa=max(100,nfqso-ntol-100) - nfb=min(4800,nfqso+ntol+100) - fa=max(100,nint(nfqso+1.5*baud-ntol)) ! signal search window - fb=min(4800,nint(nfqso+1.5*baud+ntol)) - else if(iwspr.eq.0) then - if(single_decode) then - fa=max(100,nint(nfa+1.5*baud)) - fb=min(4800,nint(nfb+1.5*baud)) - ! extend noise fit 100 Hz outside of search window - nfa=max(100,nfa-100) - nfb=min(4800,nfb+100) - else - fa=max(100,nint(nfa+1.5*baud)) - fb=min(4800,nint(nfb+1.5*baud)) - ! extend noise fit 100 Hz outside of search window - nfa=max(100,nfa-100) - nfb=min(4800,nfb+100) - endif - endif - - ndecodes=0 - decodes=' ' - new_callsign=.false. - do inb=0,inb1,inb2 - if(nb.lt.0) npct=inb ! we are looping over blanker settings - call blanker(iwave,nfft1,ndropmax,npct,c_bigfft) - -! The big fft is done once and is used for calculating the smoothed spectrum -! and also for downconverting/downsampling each candidate. - call four2a(c_bigfft,nfft1,1,-1,0) !r2c - nhicoh=1 - nsyncoh=8 - minsync=1.20 - if(ntrperiod.eq.15) minsync=1.15 - -! Get first approximation of candidate frequencies - call get_candidates_fst4(c_bigfft,nfft1,nsps,hmod,fs,fa,fb,nfa,nfb, & - minsync,ncand,candidates0) - isbest=0 - fc2=0. - do icand=1,ncand - fc0=candidates0(icand,1) - if(iwspr.eq.0 .and. nb.lt.0 .and. npct.ne.0 .and. & - abs(fc0-(nfqso+1.5*baud)).gt.ntol) cycle ! blanker loop only near nfqso - detmet=candidates0(icand,2) - -! Downconvert and downsample a slice of the spectrum centered on the -! rough estimate of the candidates frequency. -! Output array c2 is complex baseband sampled at 12000/ndown Sa/sec. -! The size of the downsampled c2 array is nfft2=nfft1/ndown - call timer('dwnsmpl ',0) - call fst4_downsample(c_bigfft,nfft1,ndown,fc0,sigbw,c2) - call timer('dwnsmpl ',1) - - call timer('sync240 ',0) - call fst4_sync_search(c2,nfft2,hmod,fs2,nss,ntrperiod,nsyncoh,emedelay,sbest,fcbest,isbest) - call timer('sync240 ',1) - - fc_synced = fc0 + fcbest - dt_synced = (isbest-fs2)*dt2 !nominal dt is 1 second so frame starts at sample fs2 - candidates0(icand,3)=fc_synced - candidates0(icand,4)=isbest - enddo - -! remove duplicate candidates - do icand=1,ncand - fc=candidates0(icand,3) - isbest=nint(candidates0(icand,4)) - do ic2=icand+1,ncand - fc2=candidates0(ic2,3) - isbest2=nint(candidates0(ic2,4)) - if(fc2.gt.0.0) then - if(abs(fc2-fc).lt.0.10*baud) then ! same frequency - if(abs(isbest2-isbest).le.2) then - candidates0(ic2,3)=-1 - endif - endif - endif - enddo - enddo - ic=0 - do icand=1,ncand - if(candidates0(icand,3).gt.0) then - ic=ic+1 - candidates0(ic,:)=candidates0(icand,:) - endif - enddo - ncand=ic - -! If FST4 mode and Single Decode is not checked, then find candidates -! within 20 Hz of nfqso and put them at the top of the list - if(iwspr.eq.0 .and. .not.single_decode) then - nclose=count(abs(candidates0(:,3)-(nfqso+1.5*baud)).le.20) - k=0 - do i=1,ncand - if(abs(candidates0(i,3)-(nfqso+1.5*baud)).le.20) then - k=k+1 - candidates(k,:)=candidates0(i,:) - endif - enddo - do i=1,ncand - if(abs(candidates0(i,3)-(nfqso+1.5*baud)).gt.20) then - k=k+1 - candidates(k,:)=candidates0(i,:) - endif - enddo - else - candidates=candidates0 - endif - - xsnr=0. - do icand=1,ncand - sync=candidates(icand,2) - fc_synced=candidates(icand,3) - isbest=nint(candidates(icand,4)) - xdt=(isbest-nspsec)/fs2 - if(ntrperiod.eq.15) xdt=(isbest-real(nspsec)/2.0)/fs2 - call timer('dwnsmpl ',0) - call fst4_downsample(c_bigfft,nfft1,ndown,fc_synced,sigbw,c2) - call timer('dwnsmpl ',1) - - do ijitter=0,jittermax - if(ijitter.eq.0) ioffset=0 - if(ijitter.eq.1) ioffset=1 - if(ijitter.eq.2) ioffset=-1 - is0=isbest+ioffset - iend=is0+160*nss-1 - if( is0.lt.0 .or. iend.gt.(nfft2-1) ) cycle - cframe=c2(is0:iend) - bitmetrics=0 - call timer('bitmetrc',0) - call get_fst4_bitmetrics(cframe,nss,bitmetrics, & - s4,nsync_qual,badsync) - call timer('bitmetrc',1) - if(badsync) cycle - - do il=1,4 - llrs( 1: 60,il)=bitmetrics( 17: 76, il) - llrs( 61:120,il)=bitmetrics( 93:152, il) - llrs(121:180,il)=bitmetrics(169:228, il) - llrs(181:240,il)=bitmetrics(245:304, il) - enddo - - apmag=maxval(abs(llrs(:,4)))*1.1 - ntmax=nblock+nappasses(nQSOProgress) - if(lapcqonly) ntmax=nblock+1 - if(ndepth.eq.1) ntmax=nblock ! no ap for ndepth=1 - apmask=0 - - if(iwspr.eq.1) then ! 50-bit msgs, no ap decoding - nblock=4 - ntmax=nblock - endif - - do itry=1,ntmax - if(itry.eq.1) llr=llrs(:,1) - if(itry.eq.2.and.itry.le.nblock) llr=llrs(:,2) - if(itry.eq.3.and.itry.le.nblock) llr=llrs(:,3) - if(itry.eq.4.and.itry.le.nblock) llr=llrs(:,4) - if(itry.le.nblock) then - apmask=0 - iaptype=0 - endif - - if(itry.gt.nblock .and. iwspr.eq.0) then ! do ap passes - llr=llrs(:,nblock) ! Use largest blocksize as the basis for AP passes - iaptype=naptypes(nQSOProgress,itry-nblock) - if(lapcqonly) iaptype=1 - if(iaptype.ge.2 .and. apbits(1).gt.1) cycle ! No, or nonstandard, mycall - if(iaptype.ge.3 .and. apbits(30).gt.1) cycle ! No, or nonstandard, dxcall - if(iaptype.eq.1) then ! CQ - apmask=0 - apmask(1:29)=1 - llr(1:29)=apmag*mcq(1:29) - endif - - if(iaptype.eq.2) then ! MyCall ??? ??? - apmask=0 - apmask(1:29)=1 - llr(1:29)=apmag*apbits(1:29) - endif - - if(iaptype.eq.3) then ! MyCall DxCall ??? - apmask=0 - apmask(1:58)=1 - llr(1:58)=apmag*apbits(1:58) - endif - - if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype .eq.6) then - apmask=0 - apmask(1:77)=1 - llr(1:58)=apmag*apbits(1:58) - if(iaptype.eq.4) llr(59:77)=apmag*mrrr(1:19) - if(iaptype.eq.5) llr(59:77)=apmag*m73(1:19) - if(iaptype.eq.6) llr(59:77)=apmag*mrr73(1:19) - endif - endif - - dmin=0.0 - nharderrors=-1 - unpk77_success=.false. - if(iwspr.eq.0) then - maxosd=2 - Keff=91 - norder=3 - call timer('d240_101',0) - call decode240_101(llr,Keff,maxosd,norder,apmask,message101, & - cw,ntype,nharderrors,dmin) - call timer('d240_101',1) - if(count(cw.eq.1).eq.0) then - nharderrors=-nharderrors - cycle - endif - write(c77,'(77i1)') mod(message101(1:77)+rvec,2) - call unpack77(c77,1,msg,unpk77_success) - elseif(iwspr.eq.1) then -! Try decoding with Keff=66 - maxosd=2 - call timer('d240_74 ',0) - Keff=66 - norder=3 - call decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw, & - ntype,nharderrors,dmin) - call timer('d240_74 ',1) - if(nharderrors.lt.0) goto 3465 - if(count(cw.eq.1).eq.0) then - nharderrors=-nharderrors - cycle - endif - write(c77,'(50i1)') message74(1:50) - c77(51:77)='000000000000000000000110000' - call unpack77(c77,1,msg,unpk77_success) - if(lprinthash22 .and. unpk77_success .and. index(msg,'<...>').gt.0) then - read(c77,'(b22.22)') n22tmp - i1=index(msg,' ') - wpart=trim(msg(i1+1:)) - write(msg,'(a1,i7.7,a1)') '<',n22tmp,'>' - msg=trim(msg)//' '//trim(wpart) - endif - if(unpk77_success .and. do_k50_decode) then -! If decode was obtained with Keff=66, save call/grid in fst4w_calls.txt if not there already. - i1=index(msg,' ') - i2=i1+index(msg(i1+1:),' ') - wpart=trim(msg(1:i2)) -! Only save callsigns/grids from type 1 messages - if(index(wpart,'/').eq.0 .and. index(wpart,'<').eq.0) then - ifound=0 - do i=1,nwcalls - if(index(wcalls(i),wpart).ne.0) ifound=1 - enddo - - if(ifound.eq.0) then ! This is a new callsign - new_callsign=.true. - if(nwcalls.lt.MAXWCALLS) then - nwcalls=nwcalls+1 - wcalls(nwcalls)=wpart - else - wcalls(1:nwcalls-1)=wcalls(2:nwcalls) - wcalls(nwcalls)=wpart - endif - endif - endif - endif -3465 continue - -! If no decode then try Keff=50 - iaptype=0 - if( .not. unpk77_success .and. do_k50_decode ) then - maxosd=1 - call timer('d240_74 ',0) - Keff=50 - norder=4 - call decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw, & - ntype,nharderrors,dmin) - call timer('d240_74 ',1) - if(count(cw.eq.1).eq.0) then - nharderrors=-nharderrors - cycle - endif - write(c77,'(50i1)') message74(1:50) - c77(51:77)='000000000000000000000110000' - call unpack77(c77,1,msg,unpk77_success) -! No CRC in this mode, so only accept the decode if call/grid have been seen before - if(unpk77_success) then - unpk77_success=.false. - do i=1,nwcalls - if(index(msg,trim(wcalls(i))).gt.0) then - unpk77_success=.true. - endif - enddo - endif - endif - - endif - - if(nharderrors .ge.0 .and. unpk77_success) then - idupe=0 - do i=1,ndecodes - if(decodes(i).eq.msg) idupe=1 - enddo - if(idupe.eq.1) goto 800 - ndecodes=ndecodes+1 - decodes(ndecodes)=msg - - if(iwspr.eq.0) then - call get_fst4_tones_from_bits(message101,itone,0) - else - call get_fst4_tones_from_bits(message74,itone,1) - endif - inquire(file='plotspec',exist=plotspec_exists) - fmid=-999.0 - call timer('dopsprd ',0) - if(plotspec_exists) then - call dopspread(itone,iwave,nsps,nmax,ndown,hmod, & - isbest,fc_synced,fmid,w50) - endif - call timer('dopsprd ',1) - xsig=0 - do i=1,NN - xsig=xsig+s4(itone(i),i) - enddo - base=candidates(icand,5) - select case(ntrperiod) - case(15) - snr_calfac=800.0 - case(30) - snr_calfac=600.0 - case(60) - snr_calfac=430.0 - case(120) - snr_calfac=390.0 - case(300) - snr_calfac=340.0 - case(900) - snr_calfac=320.0 - case(1800) - snr_calfac=320.0 - case default - snr_calfac=430.0 - end select - arg=snr_calfac*xsig/base - 1.0 - if(arg.gt.0.0) then - xsnr=10*log10(arg)+10*log10(1.46/2500)+10*log10(8200.0/nsps) - else - xsnr=-99.9 - endif - nsnr=nint(xsnr) - qual=0.0 - fsig=fc_synced - 1.5*baud - inquire(file=trim(data_dir)//'/decdata',exist=decdata_exists) - if(decdata_exists) then - hdec=0 - where(llrs(:,1).ge.0.0) hdec=1 - nhp=count(hdec.ne.cw) ! # hard errors wrt N=1 soft symbols - hd=sum(ieor(hdec,cw)*abs(llrs(:,1))) ! weighted distance wrt N=1 symbols - open(21,file=trim(data_dir)//'/fst4_decodes.dat',status='unknown',position='append') - write(21,3021) nutc,icand,itry,nsyncoh,iaptype, & - ijitter,npct,ntype,Keff,nsync_qual,nharderrors,dmin,nhp,hd, & - sync,xsnr,xdt,fsig,w50,trim(msg) -3021 format(i6.6,i4,6i3,3i4,f6.1,i4,f6.1,f9.2,f6.1,f6.2,f7.1,f7.3,1x,a) - close(21) - endif - call this%callback(nutc,smax1,nsnr,xdt,fsig,msg, & - iaptype,qual,ntrperiod,fmid,w50) - goto 800 - endif - enddo ! metrics - enddo ! istart jitter -800 enddo !candidate list - enddo ! noise blanker loop - - if(new_callsign .and. do_k50_decode) then ! re-write the fst4w_calls.txt file - open(42,file=trim(data_dir)//'/fst4w_calls.txt',status='unknown') - do i=1,nwcalls - write(42,'(a20)') trim(wcalls(i)) - enddo - close(42) - endif - - return - end subroutine decode - - subroutine sync_fst4(cd0,i0,f0,hmod,ncoh,np,nss,ntr,fs,sync) - -! Compute sync power for a complex, downsampled FST4 signal. - - use timer_module, only: timer - include 'fst4/fst4_params.f90' - complex cd0(0:np-1) - complex csync1,csync2,csynct1,csynct2 - complex ctwk(3200) - complex z1,z2,z3,z4,z5 - integer hmod,isyncword1(0:7),isyncword2(0:7) - real f0save - common/sync240com/csync1(3200),csync2(3200),csynct1(3200),csynct2(3200) - data isyncword1/0,1,3,2,1,0,2,3/ - data isyncword2/2,3,1,0,3,2,0,1/ - data f0save/-99.9/,nss0/-1/,ntr0/-1/ - save twopi,dt,fac,f0save,nss0,ntr0 - - p(z1)=(real(z1*fac)**2 + aimag(z1*fac)**2)**0.5 !Compute power - - nz=8*nss - call timer('sync240a',0) - if(nss.ne.nss0 .or. ntr.ne.ntr0) then - twopi=8.0*atan(1.0) - dt=1/fs - k=1 - phi1=0.0 - phi2=0.0 - do i=0,7 - dphi1=twopi*hmod*(isyncword1(i)-1.5)/real(nss) - dphi2=twopi*hmod*(isyncword2(i)-1.5)/real(nss) - do j=1,nss - csync1(k)=cmplx(cos(phi1),sin(phi1)) - csync2(k)=cmplx(cos(phi2),sin(phi2)) - phi1=mod(phi1+dphi1,twopi) - phi2=mod(phi2+dphi2,twopi) - k=k+1 - enddo - enddo - fac=1.0/(8.0*nss) - nss0=nss - ntr0=ntr - f0save=-1.e30 - endif - - if(f0.ne.f0save) then - dphi=twopi*f0*dt - phi=0.0 - do i=1,nz - ctwk(i)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - enddo - csynct1(1:nz)=ctwk(1:nz)*csync1(1:nz) - csynct2(1:nz)=ctwk(1:nz)*csync2(1:nz) - f0save=f0 - nss0=nss - endif - call timer('sync240a',1) - - i1=i0 !Costas arrays - i2=i0+38*nss - i3=i0+76*nss - i4=i0+114*nss - i5=i0+152*nss - - s1=0.0 - s2=0.0 - s3=0.0 - s4=0.0 - s5=0.0 - - if(ncoh.gt.0) then - nsec=8/ncoh - do i=1,nsec - is=(i-1)*ncoh*nss - z1=0 - if(i1+is.ge.1) then - z1=sum(cd0(i1+is:i1+is+ncoh*nss-1)*conjg(csynct1(is+1:is+ncoh*nss))) - endif - z2=sum(cd0(i2+is:i2+is+ncoh*nss-1)*conjg(csynct2(is+1:is+ncoh*nss))) - z3=sum(cd0(i3+is:i3+is+ncoh*nss-1)*conjg(csynct1(is+1:is+ncoh*nss))) - z4=sum(cd0(i4+is:i4+is+ncoh*nss-1)*conjg(csynct2(is+1:is+ncoh*nss))) - z5=0 - if(i5+is+ncoh*nss-1.le.np) then - z5=sum(cd0(i5+is:i5+is+ncoh*nss-1)*conjg(csynct1(is+1:is+ncoh*nss))) - endif - s1=s1+abs(z1)/nz - s2=s2+abs(z2)/nz - s3=s3+abs(z3)/nz - s4=s4+abs(z4)/nz - s5=s5+abs(z5)/nz - enddo - else - nsub=-ncoh - nps=nss/nsub - do i=1,8 - do isub=1,nsub - is=(i-1)*nss+(isub-1)*nps - z1=0.0 - if(i1+is.ge.1) then - z1=sum(cd0(i1+is:i1+is+nps-1)*conjg(csynct1(is+1:is+nps))) - endif - z2=sum(cd0(i2+is:i2+is+nps-1)*conjg(csynct2(is+1:is+nps))) - z3=sum(cd0(i3+is:i3+is+nps-1)*conjg(csynct1(is+1:is+nps))) - z4=sum(cd0(i4+is:i4+is+nps-1)*conjg(csynct2(is+1:is+nps))) - z5=0.0 - if(i5+is+ncoh*nss-1.le.np) then - z5=sum(cd0(i5+is:i5+is+nps-1)*conjg(csynct1(is+1:is+nps))) - endif - s1=s1+abs(z1)/(8*nss) - s2=s2+abs(z2)/(8*nss) - s3=s3+abs(z3)/(8*nss) - s4=s4+abs(z4)/(8*nss) - s5=s5+abs(z5)/(8*nss) - enddo - enddo - endif - sync = s1+s2+s3+s4+s5 - return - end subroutine sync_fst4 - - subroutine fst4_downsample(c_bigfft,nfft1,ndown,f0,sigbw,c1) - -! Output: Complex data in c(), sampled at 12000/ndown Hz - - complex c_bigfft(0:nfft1/2) - complex c1(0:nfft1/ndown-1) - - df=12000.0/nfft1 - i0=nint(f0/df) - ih=nint( ( f0 + 1.3*sigbw/2.0 )/df) - nbw=ih-i0+1 - c1=0. - c1(0)=c_bigfft(i0) - nfft2=nfft1/ndown - do i=1,nbw - if(i0+i.le.nfft1/2) c1(i)=c_bigfft(i0+i) - if(i0-i.ge.0) c1(nfft2-i)=c_bigfft(i0-i) - enddo - c1=c1/nfft2 - call four2a(c1,nfft2,1,1,1) !c2c FFT back to time domain - return - - end subroutine fst4_downsample - - subroutine get_candidates_fst4(c_bigfft,nfft1,nsps,hmod,fs,fa,fb,nfa,nfb, & - minsync,ncand,candidates) - - complex c_bigfft(0:nfft1/2) !Full length FFT of raw data - integer hmod !Modulation index (submode) - integer im(1) !For maxloc - real candidates(200,5) !Candidate list - real, allocatable :: s(:) !Low resolution power spectrum - real, allocatable :: s2(:) !CCF of s() with 4 tones - real, allocatable :: sbase(:) !noise baseline estimate - real xdb(-3:3) !Model 4-tone CCF peaks - real minsync - data xdb/0.25,0.50,0.75,1.0,0.75,0.50,0.25/ - - nh1=nfft1/2 - df1=fs/nfft1 - baud=fs/nsps !Keying rate - df2=baud/2.0 - nd=df2/df1 !s() sums this many bins of big FFT - ndh=nd/2 - ia=nint(max(100.0,fa)/df2) !Low frequency search limit - ib=nint(min(4800.0,fb)/df2) !High frequency limit - ina=nint(max(100.0,real(nfa))/df2) !Low freq limit for noise baseline fit - inb=nint(min(4800.0,real(nfb))/df2) !High freq limit for noise fit - if(ia.lt.ina) ia=ina - if(ib.gt.inb) ib=inb - - nnw=nint(48000.*nsps*2./fs) - allocate (s(nnw)) - s=0. !Compute low-resolution power spectrum - do i=ina,inb ! noise analysis window includes signal analysis window - j0=nint(i*df2/df1) - do j=j0-ndh,j0+ndh - s(i)=s(i) + real(c_bigfft(j))**2 + aimag(c_bigfft(j))**2 - enddo - enddo - - ina=max(ina,1+3*hmod) !Don't run off the ends - inb=min(inb,nnw-3*hmod) - allocate (s2(nnw)) - allocate (sbase(nnw)) - s2=0. - do i=ina,inb !Compute CCF of s() and 4 tones - s2(i)=s(i-hmod*3) + s(i-hmod) +s(i+hmod) +s(i+hmod*3) - enddo - npctile=30 - call fst4_baseline(s2,nnw,ina+hmod*3,inb-hmod*3,npctile,sbase) - if(any(sbase(ina:inb).le.0.0)) return - s2(ina:inb)=s2(ina:inb)/sbase(ina:inb) !Normalize wrt noise level - - ncand=0 - candidates=0 - if(ia.lt.3) ia=3 - if(ib.gt.nnw-2) ib=nnw-2 - -! Find candidates, using the CLEAN algorithm to remove a model of each one -! from s2() after it has been found. - pval=99.99 - do while(ncand.lt.200) - im=maxloc(s2(ia:ib)) - iploc=ia+im(1)-1 !Index of CCF peak - pval=s2(iploc) !Peak value - if(pval.lt.minsync) exit - do i=-3,+3 !Remove 0.9 of a model CCF at - k=iploc+2*hmod*i !this frequency from s2() - if(k.ge.ia .and. k.le.ib) then - s2(k)=max(0.,s2(k)-0.9*pval*xdb(i)) - endif - enddo - ncand=ncand+1 - candidates(ncand,1)=df2*iploc !Candidate frequency - candidates(ncand,2)=pval !Rough estimate of SNR - candidates(ncand,5)=sbase(iploc) - enddo - return - end subroutine get_candidates_fst4 - - subroutine fst4_sync_search(c2,nfft2,hmod,fs2,nss,ntrperiod,nsyncoh,emedelay,sbest,fcbest,isbest) - complex c2(0:nfft2-1) - integer hmod - nspsec=int(fs2) - baud=fs2/real(nss) - fc1=0.0 - if(emedelay.lt.0.1) then ! search offsets from 0 s to 2 s - is0=1.5*nspsec - ishw=1.5*nspsec - else ! search plus or minus 1.5 s centered on emedelay - is0=nint((emedelay+1.0)*nspsec) - ishw=1.5*nspsec - endif - - sbest=-1.e30 - do if=-12,12 - fc=fc1 + 0.1*baud*if - do istart=max(1,is0-ishw),is0+ishw,4*hmod - call sync_fst4(c2,istart,fc,hmod,nsyncoh,nfft2,nss, & - ntrperiod,fs2,sync) - if(sync.gt.sbest) then - fcbest=fc - isbest=istart - sbest=sync - endif - enddo - enddo - - fc1=fcbest - is0=isbest - ishw=4*hmod - isst=1*hmod - - sbest=0.0 - do if=-7,7 - fc=fc1 + 0.02*baud*if - do istart=max(1,is0-ishw),is0+ishw,isst - call sync_fst4(c2,istart,fc,hmod,nsyncoh,nfft2,nss, & - ntrperiod,fs2,sync) - if(sync.gt.sbest) then - fcbest=fc - isbest=istart - sbest=sync - endif - enddo - enddo - end subroutine fst4_sync_search - - subroutine dopspread(itone,iwave,nsps,nmax,ndown,hmod,i0,fc,fmid,w50) - -! On "plotspec" special request, compute Doppler spread for a decoded signal - - include 'fst4/fst4_params.f90' - complex, allocatable :: cwave(:) !Reconstructed complex signal - complex, allocatable :: g(:) !Channel gain, g(t) in QEX paper - real,allocatable :: ss(:) !Computed power spectrum of g(t) - integer itone(160) !Tones for this message - integer*2 iwave(nmax) !Raw Rx data - integer hmod !Modulation index - data ncall/0/ - save ncall - - ncall=ncall+1 - nfft=2*nmax - nwave=max(nmax,(NN+2)*nsps) - allocate(cwave(0:nwave-1)) - allocate(g(0:nfft-1)) - wave=0 - fsample=12000.0 - call gen_fst4wave(itone,NN,nsps,nwave,fsample,hmod,fc,1,cwave,wave) - cwave=cshift(cwave,-i0*ndown) - fac=1.0/32768 - g(0:nmax-1)=fac*float(iwave)*conjg(cwave(:nmax-1)) - g(nmax:)=0. - call four2a(g,nfft,1,-1,1) !Forward c2c FFT - - df=12000.0/nfft - ia=1.0/df - smax=0. - do i=-ia,ia !Find smax in +/- 1 Hz around 0. - j=i - if(j.lt.0) j=i+nfft - s=real(g(j))**2 + aimag(g(j))**2 - smax=max(s,smax) - enddo - - ia=10.1/df - allocate(ss(-ia:ia)) !Allocate space for +/- 10 Hz - sum1=0. - sum2=0. - nns=0 - do i=-ia,ia - j=i - if(j.lt.0) j=i+nfft - ss(i)=(real(g(j))**2 + aimag(g(j))**2)/smax - f=i*df - if(f.ge.-4.0 .and. f.le.-2.0) then - sum1=sum1 + ss(i) !Power between -2 and -4 Hz - nns=nns+1 - else if(f.ge.2.0 .and. f.le.4.0) then - sum2=sum2 + ss(i) !Power between +2 and +4 Hz - endif - enddo - avg=min(sum1/nns,sum2/nns) !Compute avg from smaller sum - - sum1=0. - do i=-ia,ia - f=i*df - if(abs(f).le.1.0) sum1=sum1 + ss(i)-avg !Power in abs(f) < 1 Hz - enddo - - ia=nint(1.0/df) + 1 - sum2=0.0 - xi1=-999 - xi2=-999 - xi3=-999 - sum2z=0. - do i=-ia,ia !Find freq range that has 50% of signal power - sum2=sum2 + ss(i)-avg - if(sum2.ge.0.25*sum1 .and. xi1.eq.-999.0) then - xi1=i - 1 + (0.25*sum1-sum2)/(sum2-sum2z) - endif - if(sum2.ge.0.50*sum1 .and. xi2.eq.-999.0) then - xi2=i - 1 + (sum2-0.50*sum1)/(sum2-sum2z) - endif - if(sum2.ge.0.75*sum1) then - xi3=i - 1 + (sum2-0.75*sum1)/(sum2-sum2z) - exit - endif - sum2z=sum2 - enddo - xdiff=sqrt(1.0+(xi3-xi1)**2) !Keep small values from fluctuating too widely - w50=xdiff*df !Compute Doppler spread - fmid=xi2*df !Frequency midpoint of signal powere - - do i=-ia,ia !Save the spectrum for plotting - y=ncall-1 - j=i+nint(xi2) - if(abs(j*df).lt.10.0) y=0.99*ss(i+nint(xi2)) + ncall-1 - write(52,1010) i*df,y -1010 format(f12.6,f12.6) - enddo - - return - end subroutine dopspread - -end module fst4_decode +module fst4_decode + + type :: fst4_decoder + procedure(fst4_decode_callback), pointer :: callback + contains + procedure :: decode + end type fst4_decoder + + abstract interface + subroutine fst4_decode_callback (this,nutc,sync,nsnr,dt,freq, & + decoded,nap,qual,ntrperiod,fmid,w50) + import fst4_decoder + implicit none + class(fst4_decoder), intent(inout) :: this + integer, intent(in) :: nutc + real, intent(in) :: sync + integer, intent(in) :: nsnr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=37), intent(in) :: decoded + integer, intent(in) :: nap + real, intent(in) :: qual + integer, intent(in) :: ntrperiod + real, intent(in) :: fmid + real, intent(in) :: w50 + end subroutine fst4_decode_callback + end interface + +contains + + subroutine decode(this,callback,iwave,nutc,nQSOProgress,nfa,nfb,nfqso, & + ndepth,ntrperiod,nexp_decode,ntol,emedelay,lagain,lapcqonly,mycall, & + hiscall,iwspr,lprinthash22) + + use prog_args + use timer_module, only: timer + use packjt77 + use, intrinsic :: iso_c_binding + include 'fst4/fst4_params.f90' + parameter (MAXCAND=100,MAXWCALLS=100) + class(fst4_decoder), intent(inout) :: this + procedure(fst4_decode_callback) :: callback + character*37 decodes(100) + character*37 msg,msgsent + character*20 wcalls(MAXWCALLS), wpart + character*77 c77 + character*12 mycall,hiscall + character*12 mycall0,hiscall0 + complex, allocatable :: c2(:) + complex, allocatable :: cframe(:) + complex, allocatable :: c_bigfft(:) !Complex waveform + real llr(240),llrs(240,4) + real candidates0(200,5),candidates(200,5) + real bitmetrics(320,4) + real s4(0:3,NN) + real minsync + logical lagain,lapcqonly + integer itone(NN) + integer hmod + integer*1 apmask(240),cw(240),hdec(240) + integer*1 message101(101),message74(74),message77(77) + integer*1 rvec(77) + integer apbits(240) + integer nappasses(0:5) ! # of decoding passes for QSO states 0-5 + integer naptypes(0:5,4) ! (nQSOProgress,decoding pass) + integer mcq(29),mrrr(19),m73(19),mrr73(19) + + logical badsync,unpk77_success,single_decode + logical first,nohiscall + logical new_callsign,plotspec_exists,wcalls_exists,do_k50_decode + logical decdata_exists + logical lprinthash22 + + integer*2 iwave(30*60*12000) + + data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/ + data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/ + data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/ + data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/ + data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & + 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & + 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ + data first/.true./,hmod/1/ + save first,apbits,nappasses,naptypes,mycall0,hiscall0 + save wcalls,nwcalls + + this%callback => callback + dxcall13=hiscall ! initialize for use in packjt77 + mycall13=mycall + + if(iwspr.ne.0 .and. iwspr.ne.1) return + + if(lagain) continue ! use lagain to keep compiler happy + + if(first) then +! read the fst4_calls.txt file + inquire(file=trim(data_dir)//'/fst4w_calls.txt',exist=wcalls_exists) + if( wcalls_exists ) then + open(42,file=trim(data_dir)//'/fst4w_calls.txt',status='unknown') + do i=1,MAXWCALLS + wcalls(i)='' + read(42,fmt='(a)',end=2867) wcalls(i) + wcalls(i)=adjustl(wcalls(i)) + if(len(trim(wcalls(i))).eq.0) exit + enddo +2867 nwcalls=i-1 + close(42) + endif + + mcq=2*mod(mcq+rvec(1:29),2)-1 + mrrr=2*mod(mrrr+rvec(59:77),2)-1 + m73=2*mod(m73+rvec(59:77),2)-1 + mrr73=2*mod(mrr73+rvec(59:77),2)-1 + + nappasses(0)=2 + nappasses(1)=2 + nappasses(2)=2 + nappasses(3)=2 + nappasses(4)=2 + nappasses(5)=3 + +! iaptype +!------------------------ +! 1 CQ ??? ??? (29 ap bits) +! 2 MyCall ??? ??? (29 ap bits) +! 3 MyCall DxCall ??? (58 ap bits) +! 4 MyCall DxCall RRR (77 ap bits) +! 5 MyCall DxCall 73 (77 ap bits) +! 6 MyCall DxCall RR73 (77 ap bits) +!******** + + naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ) + naptypes(1,1:4)=(/2,3,0,0/) ! Tx1 + naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 + naptypes(3,1:4)=(/3,6,0,0/) ! Tx3 + naptypes(4,1:4)=(/3,6,0,0/) ! Tx4 + naptypes(5,1:4)=(/3,1,2,0/) ! Tx5 + + mycall0='' + hiscall0='' + first=.false. + endif + + l1=index(mycall,char(0)) + if(l1.ne.0) mycall(l1:)=" " + l1=index(hiscall,char(0)) + if(l1.ne.0) hiscall(l1:)=" " + if(mycall.ne.mycall0 .or. hiscall.ne.hiscall0) then + apbits=0 + apbits(1)=99 + apbits(30)=99 + + if(len(trim(mycall)) .lt. 3) go to 10 + + nohiscall=.false. + hiscall0=hiscall + if(len(trim(hiscall0)).lt.3) then + hiscall0=mycall ! use mycall for dummy hiscall - mycall won't be hashed. + nohiscall=.true. + endif + msg=trim(mycall)//' '//trim(hiscall0)//' RR73' + i3=-1 + n3=-1 + call pack77(msg,i3,n3,c77) + call unpack77(c77,1,msgsent,unpk77_success) + if(i3.ne.1 .or. (msg.ne.msgsent) .or. .not.unpk77_success) go to 10 + read(c77,'(77i1)') message77 + message77=mod(message77+rvec,2) + apbits(1:77)=2*message77-1 + if(nohiscall) apbits(30)=99 + +10 continue + mycall0=mycall + hiscall0=hiscall + endif +!************************************ + + if(nfqso+nqsoprogress.eq.-999) return + Keff=91 + nmax=15*12000 + if(ntrperiod.eq.15) then + nsps=720 + nmax=15*12000 + ndown=18 !nss=40,80,160,400 + nfft1=int(nmax/ndown)*ndown + else if(ntrperiod.eq.30) then + nsps=1680 + nmax=30*12000 + ndown=42 !nss=40,80,168,336 + nfft1=359856 !nfft2=8568=2^3*3^2*7*17 + else if(ntrperiod.eq.60) then + nsps=3888 + nmax=60*12000 + ndown=108 + nfft1=7500*96 ! nfft2=7500=2^2*3*5^4 + else if(ntrperiod.eq.120) then + nsps=8200 + nmax=120*12000 + ndown=205 !nss=40,82,164,328 + nfft1=7200*200 ! nfft2=7200=2^5*3^2*5^2 + else if(ntrperiod.eq.300) then + nsps=21504 + nmax=300*12000 + ndown=512 !nss=42,84,168,336 + nfft1=7020*512 ! nfft2=7020=2^2*3^3*5*13 + else if(ntrperiod.eq.900) then + nsps=66560 + nmax=900*12000 + ndown=1664 !nss=40,80,160,320 + nfft1=6480*1664 ! nfft2=6480=2^4*3^4*5 + else if(ntrperiod.eq.1800) then + nsps=134400 + nmax=1800*12000 + ndown=3360 !nss=40,80,160,320 + nfft1=6426*3360 ! nfft2=6426=2*3^3*7*17 + end if + nss=nsps/ndown + fs=12000.0 !Sample rate + fs2=fs/ndown + nspsec=nint(fs2) + dt=1.0/fs !Sample interval (s) + dt2=1.0/fs2 + tt=nsps*dt !Duration of "itone" symbols (s) + baud=1.0/tt + sigbw=4.0*baud + nfft2=nfft1/ndown !make sure that nfft1 is exactly nfft2*ndown + nfft1=nfft2*ndown + nh1=nfft1/2 + + allocate( c_bigfft(0:nfft1/2) ) + allocate( c2(0:nfft2-1) ) + allocate( cframe(0:160*nss-1) ) + + jittermax=2 + do_k50_decode=.false. + if(ndepth.eq.3) then + nblock=4 + jittermax=2 + do_k50_decode=.true. + elseif(ndepth.eq.2) then + nblock=4 + jittermax=2 + do_k50_decode=.false. + elseif(ndepth.eq.1) then + nblock=4 + jittermax=0 + do_k50_decode=.false. + endif + +! Noise blanker setup + ndropmax=1 + single_decode=iand(nexp_decode,32).ne.0 + npct=0 + nb=nexp_decode/256 - 3 + if(nb.ge.0) npct=nb + inb1=20 + inb2=5 + if(nb.eq.-1) then + inb2=5 !Try NB = 0, 5, 10, 15, 20% + else if(nb.eq.-2) then + inb2=2 !Try NB = 0, 2, 4,... 20% + else if(nb.eq.-3) then + inb2=1 !Try NB = 0, 1, 2,... 20% + else + inb1=0 !Fixed NB value, 0 to 25% + endif + + +! nfa,nfb: define the noise-baseline analysis window +! fa, fb: define the signal search window +! We usually make nfafb so that noise baseline analysis +! window extends outside of the [fa,fb] window where we think the signals are. +! + if(iwspr.eq.1) then !FST4W + nfa=max(100,nfqso-ntol-100) + nfb=min(4800,nfqso+ntol+100) + fa=max(100,nint(nfqso+1.5*baud-ntol)) ! signal search window + fb=min(4800,nint(nfqso+1.5*baud+ntol)) + else if(iwspr.eq.0) then + if(single_decode) then + fa=max(100,nint(nfa+1.5*baud)) + fb=min(4800,nint(nfb+1.5*baud)) + ! extend noise fit 100 Hz outside of search window + nfa=max(100,nfa-100) + nfb=min(4800,nfb+100) + else + fa=max(100,nint(nfa+1.5*baud)) + fb=min(4800,nint(nfb+1.5*baud)) + ! extend noise fit 100 Hz outside of search window + nfa=max(100,nfa-100) + nfb=min(4800,nfb+100) + endif + endif + + ndecodes=0 + decodes=' ' + new_callsign=.false. + do inb=0,inb1,inb2 + if(nb.lt.0) npct=inb ! we are looping over blanker settings + call blanker(iwave,nfft1,ndropmax,npct,c_bigfft) + +! The big fft is done once and is used for calculating the smoothed spectrum +! and also for downconverting/downsampling each candidate. + call four2a(c_bigfft,nfft1,1,-1,0) !r2c + nhicoh=1 + nsyncoh=8 + minsync=1.20 + if(ntrperiod.eq.15) minsync=1.15 + +! Get first approximation of candidate frequencies + call get_candidates_fst4(c_bigfft,nfft1,nsps,hmod,fs,fa,fb,nfa,nfb, & + minsync,ncand,candidates0) + isbest=0 + fc2=0. + do icand=1,ncand + fc0=candidates0(icand,1) + if(iwspr.eq.0 .and. nb.lt.0 .and. npct.ne.0 .and. & + abs(fc0-(nfqso+1.5*baud)).gt.ntol) cycle ! blanker loop only near nfqso + detmet=candidates0(icand,2) + +! Downconvert and downsample a slice of the spectrum centered on the +! rough estimate of the candidates frequency. +! Output array c2 is complex baseband sampled at 12000/ndown Sa/sec. +! The size of the downsampled c2 array is nfft2=nfft1/ndown + call timer('dwnsmpl ',0) + call fst4_downsample(c_bigfft,nfft1,ndown,fc0,sigbw,c2) + call timer('dwnsmpl ',1) + + call timer('sync240 ',0) + call fst4_sync_search(c2,nfft2,hmod,fs2,nss,ntrperiod,nsyncoh,emedelay,sbest,fcbest,isbest) + call timer('sync240 ',1) + + fc_synced = fc0 + fcbest + dt_synced = (isbest-fs2)*dt2 !nominal dt is 1 second so frame starts at sample fs2 + candidates0(icand,3)=fc_synced + candidates0(icand,4)=isbest + enddo + +! remove duplicate candidates + do icand=1,ncand + fc=candidates0(icand,3) + isbest=nint(candidates0(icand,4)) + do ic2=icand+1,ncand + fc2=candidates0(ic2,3) + isbest2=nint(candidates0(ic2,4)) + if(fc2.gt.0.0) then + if(abs(fc2-fc).lt.0.10*baud) then ! same frequency + if(abs(isbest2-isbest).le.2) then + candidates0(ic2,3)=-1 + endif + endif + endif + enddo + enddo + ic=0 + do icand=1,ncand + if(candidates0(icand,3).gt.0) then + ic=ic+1 + candidates0(ic,:)=candidates0(icand,:) + endif + enddo + ncand=ic + +! If FST4 mode and Single Decode is not checked, then find candidates +! within 20 Hz of nfqso and put them at the top of the list + if(iwspr.eq.0 .and. .not.single_decode) then + nclose=count(abs(candidates0(:,3)-(nfqso+1.5*baud)).le.20) + k=0 + do i=1,ncand + if(abs(candidates0(i,3)-(nfqso+1.5*baud)).le.20) then + k=k+1 + candidates(k,:)=candidates0(i,:) + endif + enddo + do i=1,ncand + if(abs(candidates0(i,3)-(nfqso+1.5*baud)).gt.20) then + k=k+1 + candidates(k,:)=candidates0(i,:) + endif + enddo + else + candidates=candidates0 + endif + + xsnr=0. + do icand=1,ncand + sync=candidates(icand,2) + fc_synced=candidates(icand,3) + isbest=nint(candidates(icand,4)) + xdt=(isbest-nspsec)/fs2 + if(ntrperiod.eq.15) xdt=(isbest-real(nspsec)/2.0)/fs2 + call timer('dwnsmpl ',0) + call fst4_downsample(c_bigfft,nfft1,ndown,fc_synced,sigbw,c2) + call timer('dwnsmpl ',1) + + do ijitter=0,jittermax + if(ijitter.eq.0) ioffset=0 + if(ijitter.eq.1) ioffset=1 + if(ijitter.eq.2) ioffset=-1 + is0=isbest+ioffset + iend=is0+160*nss-1 + if( is0.lt.0 .or. iend.gt.(nfft2-1) ) cycle + cframe=c2(is0:iend) + bitmetrics=0 + call timer('bitmetrc',0) + call get_fst4_bitmetrics(cframe,nss,bitmetrics, & + s4,nsync_qual,badsync) + call timer('bitmetrc',1) + if(badsync) cycle + + do il=1,4 + llrs( 1: 60,il)=bitmetrics( 17: 76, il) + llrs( 61:120,il)=bitmetrics( 93:152, il) + llrs(121:180,il)=bitmetrics(169:228, il) + llrs(181:240,il)=bitmetrics(245:304, il) + enddo + + apmag=maxval(abs(llrs(:,4)))*1.1 + ntmax=nblock+nappasses(nQSOProgress) + if(lapcqonly) ntmax=nblock+1 + if(ndepth.eq.1) ntmax=nblock ! no ap for ndepth=1 + apmask=0 + + if(iwspr.eq.1) then ! 50-bit msgs, no ap decoding + nblock=4 + ntmax=nblock + endif + + do itry=1,ntmax + if(itry.eq.1) llr=llrs(:,1) + if(itry.eq.2.and.itry.le.nblock) llr=llrs(:,2) + if(itry.eq.3.and.itry.le.nblock) llr=llrs(:,3) + if(itry.eq.4.and.itry.le.nblock) llr=llrs(:,4) + if(itry.le.nblock) then + apmask=0 + iaptype=0 + endif + + if(itry.gt.nblock .and. iwspr.eq.0) then ! do ap passes + llr=llrs(:,nblock) ! Use largest blocksize as the basis for AP passes + iaptype=naptypes(nQSOProgress,itry-nblock) + if(lapcqonly) iaptype=1 + if(iaptype.ge.2 .and. apbits(1).gt.1) cycle ! No, or nonstandard, mycall + if(iaptype.ge.3 .and. apbits(30).gt.1) cycle ! No, or nonstandard, dxcall + if(iaptype.eq.1) then ! CQ + apmask=0 + apmask(1:29)=1 + llr(1:29)=apmag*mcq(1:29) + endif + + if(iaptype.eq.2) then ! MyCall ??? ??? + apmask=0 + apmask(1:29)=1 + llr(1:29)=apmag*apbits(1:29) + endif + + if(iaptype.eq.3) then ! MyCall DxCall ??? + apmask=0 + apmask(1:58)=1 + llr(1:58)=apmag*apbits(1:58) + endif + + if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype .eq.6) then + apmask=0 + apmask(1:77)=1 + llr(1:58)=apmag*apbits(1:58) + if(iaptype.eq.4) llr(59:77)=apmag*mrrr(1:19) + if(iaptype.eq.5) llr(59:77)=apmag*m73(1:19) + if(iaptype.eq.6) llr(59:77)=apmag*mrr73(1:19) + endif + endif + + dmin=0.0 + nharderrors=-1 + unpk77_success=.false. + if(iwspr.eq.0) then + maxosd=2 + Keff=91 + norder=3 + call timer('d240_101',0) + call decode240_101(llr,Keff,maxosd,norder,apmask,message101, & + cw,ntype,nharderrors,dmin) + call timer('d240_101',1) + if(count(cw.eq.1).eq.0) then + nharderrors=-nharderrors + cycle + endif + write(c77,'(77i1)') mod(message101(1:77)+rvec,2) + call unpack77(c77,1,msg,unpk77_success) + elseif(iwspr.eq.1) then +! Try decoding with Keff=66 + maxosd=2 + call timer('d240_74 ',0) + Keff=66 + norder=3 + call decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw, & + ntype,nharderrors,dmin) + call timer('d240_74 ',1) + if(nharderrors.lt.0) goto 3465 + if(count(cw.eq.1).eq.0) then + nharderrors=-nharderrors + cycle + endif + write(c77,'(50i1)') message74(1:50) + c77(51:77)='000000000000000000000110000' + call unpack77(c77,1,msg,unpk77_success) + if(lprinthash22 .and. unpk77_success .and. index(msg,'<...>').gt.0) then + read(c77,'(b22.22)') n22tmp + i1=index(msg,' ') + wpart=trim(msg(i1+1:)) + write(msg,'(a1,i7.7,a1)') '<',n22tmp,'>' + msg=trim(msg)//' '//trim(wpart) + endif + if(unpk77_success .and. do_k50_decode) then +! If decode was obtained with Keff=66, save call/grid in fst4w_calls.txt if not there already. + i1=index(msg,' ') + i2=i1+index(msg(i1+1:),' ') + wpart=trim(msg(1:i2)) +! Only save callsigns/grids from type 1 messages + if(index(wpart,'/').eq.0 .and. index(wpart,'<').eq.0) then + ifound=0 + do i=1,nwcalls + if(index(wcalls(i),wpart).ne.0) ifound=1 + enddo + + if(ifound.eq.0) then ! This is a new callsign + new_callsign=.true. + if(nwcalls.lt.MAXWCALLS) then + nwcalls=nwcalls+1 + wcalls(nwcalls)=wpart + else + wcalls(1:nwcalls-1)=wcalls(2:nwcalls) + wcalls(nwcalls)=wpart + endif + endif + endif + endif +3465 continue + +! If no decode then try Keff=50 + iaptype=0 + if( .not. unpk77_success .and. do_k50_decode ) then + maxosd=1 + call timer('d240_74 ',0) + Keff=50 + norder=4 + call decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw, & + ntype,nharderrors,dmin) + call timer('d240_74 ',1) + if(count(cw.eq.1).eq.0) then + nharderrors=-nharderrors + cycle + endif + write(c77,'(50i1)') message74(1:50) + c77(51:77)='000000000000000000000110000' + call unpack77(c77,1,msg,unpk77_success) +! No CRC in this mode, so only accept the decode if call/grid have been seen before + if(unpk77_success) then + unpk77_success=.false. + do i=1,nwcalls + if(index(msg,trim(wcalls(i))).gt.0) then + unpk77_success=.true. + endif + enddo + endif + endif + + endif + + if(nharderrors .ge.0 .and. unpk77_success) then + idupe=0 + do i=1,ndecodes + if(decodes(i).eq.msg) idupe=1 + enddo + if(idupe.eq.1) goto 800 + ndecodes=ndecodes+1 + decodes(ndecodes)=msg + + if(iwspr.eq.0) then + call get_fst4_tones_from_bits(message101,itone,0) + else + call get_fst4_tones_from_bits(message74,itone,1) + endif + inquire(file='plotspec',exist=plotspec_exists) + fmid=-999.0 + call timer('dopsprd ',0) + if(plotspec_exists) then + call dopspread(itone,iwave,nsps,nmax,ndown,hmod, & + isbest,fc_synced,fmid,w50) + endif + call timer('dopsprd ',1) + xsig=0 + do i=1,NN + xsig=xsig+s4(itone(i),i) + enddo + base=candidates(icand,5) + select case(ntrperiod) + case(15) + snr_calfac=800.0 + case(30) + snr_calfac=600.0 + case(60) + snr_calfac=430.0 + case(120) + snr_calfac=390.0 + case(300) + snr_calfac=340.0 + case(900) + snr_calfac=320.0 + case(1800) + snr_calfac=320.0 + case default + snr_calfac=430.0 + end select + arg=snr_calfac*xsig/base - 1.0 + if(arg.gt.0.0) then + xsnr=10*log10(arg)+10*log10(1.46/2500)+10*log10(8200.0/nsps) + else + xsnr=-99.9 + endif + nsnr=nint(xsnr) + qual=0.0 + fsig=fc_synced - 1.5*baud + inquire(file=trim(data_dir)//'/decdata',exist=decdata_exists) + if(decdata_exists) then + hdec=0 + where(llrs(:,1).ge.0.0) hdec=1 + nhp=count(hdec.ne.cw) ! # hard errors wrt N=1 soft symbols + hd=sum(ieor(hdec,cw)*abs(llrs(:,1))) ! weighted distance wrt N=1 symbols + open(21,file=trim(data_dir)//'/fst4_decodes.dat',status='unknown',position='append') + write(21,3021) nutc,icand,itry,nsyncoh,iaptype, & + ijitter,npct,ntype,Keff,nsync_qual,nharderrors,dmin,nhp,hd, & + sync,xsnr,xdt,fsig,w50,trim(msg) +3021 format(i6.6,i4,6i3,3i4,f6.1,i4,f6.1,f9.2,f6.1,f6.2,f7.1,f7.3,1x,a) + close(21) + endif + call this%callback(nutc,smax1,nsnr,xdt,fsig,msg, & + iaptype,qual,ntrperiod,fmid,w50) + goto 800 + endif + enddo ! metrics + enddo ! istart jitter +800 enddo !candidate list + enddo ! noise blanker loop + + if(new_callsign .and. do_k50_decode) then ! re-write the fst4w_calls.txt file + open(42,file=trim(data_dir)//'/fst4w_calls.txt',status='unknown') + do i=1,nwcalls + write(42,'(a20)') trim(wcalls(i)) + enddo + close(42) + endif + + return + end subroutine decode + + subroutine sync_fst4(cd0,i0,f0,hmod,ncoh,np,nss,ntr,fs,sync) + +! Compute sync power for a complex, downsampled FST4 signal. + + use timer_module, only: timer + include 'fst4/fst4_params.f90' + complex cd0(0:np-1) + complex csync1,csync2,csynct1,csynct2 + complex ctwk(3200) + complex z1,z2,z3,z4,z5 + integer hmod,isyncword1(0:7),isyncword2(0:7) + real f0save + common/sync240com/csync1(3200),csync2(3200),csynct1(3200),csynct2(3200) + data isyncword1/0,1,3,2,1,0,2,3/ + data isyncword2/2,3,1,0,3,2,0,1/ + data f0save/-99.9/,nss0/-1/,ntr0/-1/ + save twopi,dt,fac,f0save,nss0,ntr0 + + p(z1)=(real(z1*fac)**2 + aimag(z1*fac)**2)**0.5 !Compute power + + nz=8*nss + call timer('sync240a',0) + if(nss.ne.nss0 .or. ntr.ne.ntr0) then + twopi=8.0*atan(1.0) + dt=1/fs + k=1 + phi1=0.0 + phi2=0.0 + do i=0,7 + dphi1=twopi*hmod*(isyncword1(i)-1.5)/real(nss) + dphi2=twopi*hmod*(isyncword2(i)-1.5)/real(nss) + do j=1,nss + csync1(k)=cmplx(cos(phi1),sin(phi1)) + csync2(k)=cmplx(cos(phi2),sin(phi2)) + phi1=mod(phi1+dphi1,twopi) + phi2=mod(phi2+dphi2,twopi) + k=k+1 + enddo + enddo + fac=1.0/(8.0*nss) + nss0=nss + ntr0=ntr + f0save=-1.e30 + endif + + if(f0.ne.f0save) then + dphi=twopi*f0*dt + phi=0.0 + do i=1,nz + ctwk(i)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + enddo + csynct1(1:nz)=ctwk(1:nz)*csync1(1:nz) + csynct2(1:nz)=ctwk(1:nz)*csync2(1:nz) + f0save=f0 + nss0=nss + endif + call timer('sync240a',1) + + i1=i0 !Costas arrays + i2=i0+38*nss + i3=i0+76*nss + i4=i0+114*nss + i5=i0+152*nss + + s1=0.0 + s2=0.0 + s3=0.0 + s4=0.0 + s5=0.0 + + if(ncoh.gt.0) then + nsec=8/ncoh + do i=1,nsec + is=(i-1)*ncoh*nss + z1=0 + if(i1+is.ge.1) then + z1=sum(cd0(i1+is:i1+is+ncoh*nss-1)*conjg(csynct1(is+1:is+ncoh*nss))) + endif + z2=sum(cd0(i2+is:i2+is+ncoh*nss-1)*conjg(csynct2(is+1:is+ncoh*nss))) + z3=sum(cd0(i3+is:i3+is+ncoh*nss-1)*conjg(csynct1(is+1:is+ncoh*nss))) + z4=sum(cd0(i4+is:i4+is+ncoh*nss-1)*conjg(csynct2(is+1:is+ncoh*nss))) + z5=0 + if(i5+is+ncoh*nss-1.le.np) then + z5=sum(cd0(i5+is:i5+is+ncoh*nss-1)*conjg(csynct1(is+1:is+ncoh*nss))) + endif + s1=s1+abs(z1)/nz + s2=s2+abs(z2)/nz + s3=s3+abs(z3)/nz + s4=s4+abs(z4)/nz + s5=s5+abs(z5)/nz + enddo + else + nsub=-ncoh + nps=nss/nsub + do i=1,8 + do isub=1,nsub + is=(i-1)*nss+(isub-1)*nps + z1=0.0 + if(i1+is.ge.1) then + z1=sum(cd0(i1+is:i1+is+nps-1)*conjg(csynct1(is+1:is+nps))) + endif + z2=sum(cd0(i2+is:i2+is+nps-1)*conjg(csynct2(is+1:is+nps))) + z3=sum(cd0(i3+is:i3+is+nps-1)*conjg(csynct1(is+1:is+nps))) + z4=sum(cd0(i4+is:i4+is+nps-1)*conjg(csynct2(is+1:is+nps))) + z5=0.0 + if(i5+is+ncoh*nss-1.le.np) then + z5=sum(cd0(i5+is:i5+is+nps-1)*conjg(csynct1(is+1:is+nps))) + endif + s1=s1+abs(z1)/(8*nss) + s2=s2+abs(z2)/(8*nss) + s3=s3+abs(z3)/(8*nss) + s4=s4+abs(z4)/(8*nss) + s5=s5+abs(z5)/(8*nss) + enddo + enddo + endif + sync = s1+s2+s3+s4+s5 + return + end subroutine sync_fst4 + + subroutine fst4_downsample(c_bigfft,nfft1,ndown,f0,sigbw,c1) + +! Output: Complex data in c(), sampled at 12000/ndown Hz + + complex c_bigfft(0:nfft1/2) + complex c1(0:nfft1/ndown-1) + + df=12000.0/nfft1 + i0=nint(f0/df) + ih=nint( ( f0 + 1.3*sigbw/2.0 )/df) + nbw=ih-i0+1 + c1=0. + c1(0)=c_bigfft(i0) + nfft2=nfft1/ndown + do i=1,nbw + if(i0+i.le.nfft1/2) c1(i)=c_bigfft(i0+i) + if(i0-i.ge.0) c1(nfft2-i)=c_bigfft(i0-i) + enddo + c1=c1/nfft2 + call four2a(c1,nfft2,1,1,1) !c2c FFT back to time domain + return + + end subroutine fst4_downsample + + subroutine get_candidates_fst4(c_bigfft,nfft1,nsps,hmod,fs,fa,fb,nfa,nfb, & + minsync,ncand,candidates) + + complex c_bigfft(0:nfft1/2) !Full length FFT of raw data + integer hmod !Modulation index (submode) + integer im(1) !For maxloc + real candidates(200,5) !Candidate list + real, allocatable :: s(:) !Low resolution power spectrum + real, allocatable :: s2(:) !CCF of s() with 4 tones + real, allocatable :: sbase(:) !noise baseline estimate + real xdb(-3:3) !Model 4-tone CCF peaks + real minsync + data xdb/0.25,0.50,0.75,1.0,0.75,0.50,0.25/ + + nh1=nfft1/2 + df1=fs/nfft1 + baud=fs/nsps !Keying rate + df2=baud/2.0 + nd=df2/df1 !s() sums this many bins of big FFT + ndh=nd/2 + ia=nint(max(100.0,fa)/df2) !Low frequency search limit + ib=nint(min(4800.0,fb)/df2) !High frequency limit + ina=nint(max(100.0,real(nfa))/df2) !Low freq limit for noise baseline fit + inb=nint(min(4800.0,real(nfb))/df2) !High freq limit for noise fit + if(ia.lt.ina) ia=ina + if(ib.gt.inb) ib=inb + + nnw=nint(48000.*nsps*2./fs) + allocate (s(nnw)) + s=0. !Compute low-resolution power spectrum + do i=ina,inb ! noise analysis window includes signal analysis window + j0=nint(i*df2/df1) + do j=j0-ndh,j0+ndh + s(i)=s(i) + real(c_bigfft(j))**2 + aimag(c_bigfft(j))**2 + enddo + enddo + + ina=max(ina,1+3*hmod) !Don't run off the ends + inb=min(inb,nnw-3*hmod) + allocate (s2(nnw)) + allocate (sbase(nnw)) + s2=0. + do i=ina,inb !Compute CCF of s() and 4 tones + s2(i)=s(i-hmod*3) + s(i-hmod) +s(i+hmod) +s(i+hmod*3) + enddo + npctile=30 + call fst4_baseline(s2,nnw,ina+hmod*3,inb-hmod*3,npctile,sbase) + if(any(sbase(ina:inb).le.0.0)) return + s2(ina:inb)=s2(ina:inb)/sbase(ina:inb) !Normalize wrt noise level + + ncand=0 + candidates=0 + if(ia.lt.3) ia=3 + if(ib.gt.nnw-2) ib=nnw-2 + +! Find candidates, using the CLEAN algorithm to remove a model of each one +! from s2() after it has been found. + pval=99.99 + do while(ncand.lt.200) + im=maxloc(s2(ia:ib)) + iploc=ia+im(1)-1 !Index of CCF peak + pval=s2(iploc) !Peak value + if(pval.lt.minsync) exit + do i=-3,+3 !Remove 0.9 of a model CCF at + k=iploc+2*hmod*i !this frequency from s2() + if(k.ge.ia .and. k.le.ib) then + s2(k)=max(0.,s2(k)-0.9*pval*xdb(i)) + endif + enddo + ncand=ncand+1 + candidates(ncand,1)=df2*iploc !Candidate frequency + candidates(ncand,2)=pval !Rough estimate of SNR + candidates(ncand,5)=sbase(iploc) + enddo + return + end subroutine get_candidates_fst4 + + subroutine fst4_sync_search(c2,nfft2,hmod,fs2,nss,ntrperiod,nsyncoh,emedelay,sbest,fcbest,isbest) + complex c2(0:nfft2-1) + integer hmod + nspsec=int(fs2) + baud=fs2/real(nss) + fc1=0.0 + if(emedelay.lt.0.1) then ! search offsets from 0 s to 2 s + is0=1.5*nspsec + ishw=1.5*nspsec + else ! search plus or minus 1.5 s centered on emedelay + is0=nint((emedelay+1.0)*nspsec) + ishw=1.5*nspsec + endif + + sbest=-1.e30 + do if=-12,12 + fc=fc1 + 0.1*baud*if + do istart=max(1,is0-ishw),is0+ishw,4*hmod + call sync_fst4(c2,istart,fc,hmod,nsyncoh,nfft2,nss, & + ntrperiod,fs2,sync) + if(sync.gt.sbest) then + fcbest=fc + isbest=istart + sbest=sync + endif + enddo + enddo + + fc1=fcbest + is0=isbest + ishw=4*hmod + isst=1*hmod + + sbest=0.0 + do if=-7,7 + fc=fc1 + 0.02*baud*if + do istart=max(1,is0-ishw),is0+ishw,isst + call sync_fst4(c2,istart,fc,hmod,nsyncoh,nfft2,nss, & + ntrperiod,fs2,sync) + if(sync.gt.sbest) then + fcbest=fc + isbest=istart + sbest=sync + endif + enddo + enddo + end subroutine fst4_sync_search + + subroutine dopspread(itone,iwave,nsps,nmax,ndown,hmod,i0,fc,fmid,w50) + +! On "plotspec" special request, compute Doppler spread for a decoded signal + + include 'fst4/fst4_params.f90' + complex, allocatable :: cwave(:) !Reconstructed complex signal + complex, allocatable :: g(:) !Channel gain, g(t) in QEX paper + real,allocatable :: ss(:) !Computed power spectrum of g(t) + integer itone(160) !Tones for this message + integer*2 iwave(nmax) !Raw Rx data + integer hmod !Modulation index + data ncall/0/ + save ncall + + ncall=ncall+1 + nfft=2*nmax + nwave=max(nmax,(NN+2)*nsps) + allocate(cwave(0:nwave-1)) + allocate(g(0:nfft-1)) + wave=0 + fsample=12000.0 + call gen_fst4wave(itone,NN,nsps,nwave,fsample,hmod,fc,1,cwave,wave) + cwave=cshift(cwave,-i0*ndown) + fac=1.0/32768 + g(0:nmax-1)=fac*float(iwave)*conjg(cwave(:nmax-1)) + g(nmax:)=0. + call four2a(g,nfft,1,-1,1) !Forward c2c FFT + + df=12000.0/nfft + ia=1.0/df + smax=0. + do i=-ia,ia !Find smax in +/- 1 Hz around 0. + j=i + if(j.lt.0) j=i+nfft + s=real(g(j))**2 + aimag(g(j))**2 + smax=max(s,smax) + enddo + + ia=10.1/df + allocate(ss(-ia:ia)) !Allocate space for +/- 10 Hz + sum1=0. + sum2=0. + nns=0 + do i=-ia,ia + j=i + if(j.lt.0) j=i+nfft + ss(i)=(real(g(j))**2 + aimag(g(j))**2)/smax + f=i*df + if(f.ge.-4.0 .and. f.le.-2.0) then + sum1=sum1 + ss(i) !Power between -2 and -4 Hz + nns=nns+1 + else if(f.ge.2.0 .and. f.le.4.0) then + sum2=sum2 + ss(i) !Power between +2 and +4 Hz + endif + enddo + avg=min(sum1/nns,sum2/nns) !Compute avg from smaller sum + + sum1=0. + do i=-ia,ia + f=i*df + if(abs(f).le.1.0) sum1=sum1 + ss(i)-avg !Power in abs(f) < 1 Hz + enddo + + ia=nint(1.0/df) + 1 + sum2=0.0 + xi1=-999 + xi2=-999 + xi3=-999 + sum2z=0. + do i=-ia,ia !Find freq range that has 50% of signal power + sum2=sum2 + ss(i)-avg + if(sum2.ge.0.25*sum1 .and. xi1.eq.-999.0) then + xi1=i - 1 + (0.25*sum1-sum2)/(sum2-sum2z) + endif + if(sum2.ge.0.50*sum1 .and. xi2.eq.-999.0) then + xi2=i - 1 + (sum2-0.50*sum1)/(sum2-sum2z) + endif + if(sum2.ge.0.75*sum1) then + xi3=i - 1 + (sum2-0.75*sum1)/(sum2-sum2z) + exit + endif + sum2z=sum2 + enddo + xdiff=sqrt(1.0+(xi3-xi1)**2) !Keep small values from fluctuating too widely + w50=xdiff*df !Compute Doppler spread + fmid=xi2*df !Frequency midpoint of signal powere + + do i=-ia,ia !Save the spectrum for plotting + y=ncall-1 + j=i+nint(xi2) + if(abs(j*df).lt.10.0) y=0.99*ss(i+nint(xi2)) + ncall-1 + write(52,1010) i*df,y +1010 format(f12.6,f12.6) + enddo + + return + end subroutine dopspread + +end module fst4_decode diff --git a/lib/ft2/cdatetime.f90 b/lib/ft2/cdatetime.f90 index f671609d..33deaf30 100755 --- a/lib/ft2/cdatetime.f90 +++ b/lib/ft2/cdatetime.f90 @@ -1,6 +1,6 @@ -character*17 function cdatetime() - character cdate*8,ctime*10 - call date_and_time(cdate,ctime) - cdatetime=cdate(3:8)//'_'//ctime - return -end function cdatetime +character*17 function cdatetime() + character cdate*8,ctime*10 + call date_and_time(cdate,ctime) + cdatetime=cdate(3:8)//'_'//ctime + return +end function cdatetime diff --git a/lib/ft2/ft2.f90 b/lib/ft2/ft2.f90 index 412f2271..e5c389f9 100755 --- a/lib/ft2/ft2.f90 +++ b/lib/ft2/ft2.f90 @@ -1,279 +1,279 @@ -program ft2 - - use packjt77 - include 'gcom1.f90' - integer ft2audio,ptt - logical allok - character*20 pttport - character*8 arg - character*80 fname - integer*2 id2(30000) - - open(12,file='all_ft2.txt',status='unknown',position='append') - nargs=iargc() - if(nargs.eq.1) then - call getarg(1,fname) - open(10,file=fname,status='old',access='stream') - read(10) id2(1:22) !Read (and ignore) the header - read(10) id2 !Read the Rx data - close(10) - call ft2_decode(fname(1:17),nfqso,id2,ndecodes,mycall,hiscall,nrx) - go to 999 - endif - - allok=.true. -! Get home-station details - open(10,file='ft2.ini',status='old',err=1) - go to 2 -1 print*,'Cannot open ft2.ini' - allok=.false. -2 read(10,*,err=3) mycall,mygrid,ndevin,ndevout,pttport,exch - go to 4 -3 print*,'Error reading ft2.ini' - allok=.false. -4 if(index(pttport,'/').lt.1) read(pttport,*) nport - hiscall=' ' - hiscall_next=' ' - idevin=ndevin - idevout=ndevout - call padevsub(idevin,idevout) - if(idevin.ne.ndevin .or. idevout.ne.ndevout) allok=.false. - i1=0 - i1=ptt(nport,1,1,iptt) - i1=ptt(nport,1,0,iptt) - if(i1.lt.0 .and. nport.ne.0) allok=.false. - if(.not.allok) then - write(*,"('Please fix setup error(s) and restart.')") - go to 999 - endif - - nright=1 - iwrite=0 - iwave=0 - nwave=NTZ - nfsample=12000 - ngo=1 - npabuf=1152 - ntxok=0 - ntransmitting=0 - tx_once=.false. - snrdb=99.0 - txmsg='CQ K1JT FN20' - ltx=.false. - lrx=.false. - autoseq=.false. - QSO_in_progress=.false. - ntxed=0 - - if(nargs.eq.3) then - call getarg(1,txmsg) - call getarg(2,arg) - read(arg,*) f0 - call getarg(3,arg) - read(arg,*) snrdb - tx_once=.true. - ftx=1500.0 - call transmit(-1,ftx,iptt) - snrdb=99.0 - endif - -! Start the audio streams - ierr=ft2audio(idevin,idevout,npabuf,nright,y1,y2,NRING,iwrite,itx, & - iwave,nwave+3*1152,nfsample,nTxOK,nTransmitting,ngo) - if(ierr.ne.0) then - print*,'Error',ierr,' starting audio input and/or output.' - endif - -999 end program ft2 - -subroutine update(total_time,ic1,ic2) - - use wavhdr - type(hdr) h - real*8 total_time - integer*8 count0,count1,clkfreq - integer ptt - integer*2 id(30000) - logical transmitted,level,ok - character*70 line - character cdatetime*17,fname*17,mode*8,band*6 - include 'gcom1.f90' - data nt0/-1/,transmitted/.false./,snr/-99.0/ - data level/.false./ - save nt0,transmitted,level,snr,iptt - - if(ic1.ne.0 .or. ic2.ne.0) then - if(ic1.eq.27 .and. ic2.eq.0) ngo=0 !ESC - if(nTxOK.eq.0 .and. ntransmitting.eq.0) then - nfunc=0 - if(ic1.eq.0 .and. ic2.eq.59) nfunc=1 !F1 - if(ic1.eq.0 .and. ic2.eq.60) nfunc=2 !F2 - if(ic1.eq.0 .and. ic2.eq.61) nfunc=3 !F3 - if(ic1.eq.0 .and. ic2.eq.62) nfunc=4 !F4 - if(ic1.eq.0 .and. ic2.eq.63) nfunc=5 !F5 - if(nfunc.eq.1 .or. (nfunc.ge.2 .and. hiscall.ne.' ')) then - ftx=1500.0 - call transmit(nfunc,ftx,iptt) - endif - endif - if(ic1.eq.13 .and. ic2.eq.0) hiscall=hiscall_next - if((ic1.eq.97 .or. ic1.eq.65) .and. ic2.eq.0) autoseq=.not.autoseq - if((ic1.eq.108 .or. ic1.eq.76) .and. ic2.eq.0) level=.not.level - endif - - if(ntransmitting.eq.1) transmitted=.true. - if(transmitted .and. ntransmitting.eq.0) then - i1=0 - if(iptt.eq.1 .and. nport.gt.0) i1=ptt(nport,0,1,iptt) - if(tx_once .and. transmitted) stop - transmitted=.false. - endif - - nt=2*total_time - if(nt.gt.nt0 .or. ic1.ne.0 .or. ic2.ne.0) then - if(level) then -! Measure and display the average level of signal plus noise in past 0.5 s - k=iwrite-6000 - if(k.lt.1) k=k+NRING - sq=0. - do i=1,6000 - k=k+1 - if(k.gt.NRING) k=k-NRING - x=y1(k) - sq=sq + x*x - enddo - sigdb=0. - if(sq.gt.0.0) sigdb=db(sq/6000.0) - n=sigdb - if(n.lt.1) n=1 - if(n.gt.70) n=70 - line=' ' - line(n:n)='*' - write(*,1030) sigdb,ntxed,autoseq,QSO_in_progress,(line(i:i),i=1,n) -1030 format(f4.1,i3,2L2,1x,70a1) -! write(*,1020) nt,total_time,iwrite,itx,ntxok,ntransmitting,ndecodes, & -! snr,sigdb,line -!1020 format(i6,f9.3,i10,i6,3i3,f6.0,f6.1,1x,a30) - endif - k=iwrite-30000 - if(k.lt.1) k=k+NRING - do i=1,30000 - k=k+1 - if(k.gt.NRING) k=k-NRING - id(i)=y1(k) - enddo - nutc=0 - nfqso=1500 - ndecodes=0 - if(maxval(abs(id)).gt.0) then - call system_clock(count0,clkfreq) - nrx=-1 - call ft2_decode(cdatetime(),nfqso,id,ndecodes,mycall,hiscall,nrx) - call system_clock(count1,clkfreq) -! tdecode=float(count1-count0)/float(clkfreq) - - if(ndecodes.ge.1) then - fMHz=7.074 - mode='FT2' - nsubmode=1 - ntrperiod=0 - h=default_header(12000,30000) - k=0 - do i=1,250 - sq=0 - do n=1,120 - k=k+1 - x=id(k) - sq=sq + x*x - enddo - write(43,3043) i,0.01*i,1.e-4*sq -3043 format(i7,f12.6,f12.3) - enddo - call set_wsjtx_wav_params(fMHz,mode,nsubmode,ntrperiod,id) - band="" - mode="" - nsubmode=-1 - ntrperiod=-1 - call get_wsjtx_wav_params(id,band,mode,nsubmode,ntrperiod,ok) -! write(*,1010) band,ntrperiod,mode,char(ichar('A')-1+id(3)) -!1010 format('Band: ',a6,' T/R period:',i4,' Mode: ',a8,1x,a1) - - fname=cdatetime() - fname(14:17)='.wav' - open(13,file=fname,status='unknown',access='stream') - write(13) h,id - close(13) - endif - if(autoseq .and.nrx.eq.2) QSO_in_progress=.true. - if(autoseq .and. QSO_in_progress .and. nrx.ge.1 .and. nrx.le.4) then - lrx(nrx)=.true. - ftx=1500.0 - if(ntxed.eq.1) then - if(nrx.eq.2) then - call transmit(3,ftx,iptt) - else - call transmit(1,ftx,iptt) - endif - endif - if(ntxed.eq.2) then - if(nrx.eq.3) then - call transmit(4,ftx,iptt) - QSO_in_progress=.false. - write(*,1032) -1032 format('QSO complete: S+P side') - else - call transmit(2,ftx,iptt) - endif - endif - if(ntxed.eq.3) then - if(nrx.eq.4) then - QSO_in_progress=.false. - write(*,1034) -1034 format('QSO complete: CQ side') - else - call transmit(3,ftx,iptt) - endif - endif - endif - endif - nt0=nt - endif - - return -end subroutine update - -character*17 function cdatetime() - character cdate*8,ctime*10 - call date_and_time(cdate,ctime) - cdatetime=cdate(3:8)//'_'//ctime - return -end function cdatetime - -subroutine transmit(nfunc,ftx,iptt) - include 'gcom1.f90' - character*17 cdatetime - integer ptt - - if(nTxOK.eq.1) return - - if(nfunc.eq.1) txmsg='CQ '//trim(mycall)//' '//mygrid - if(nfunc.eq.2) txmsg=trim(hiscall)//' '//trim(mycall)// & - ' 559 '//trim(exch) - if(nfunc.eq.3) txmsg=trim(hiscall)//' '//trim(mycall)// & - ' R 559 '//trim(exch) - if(nfunc.eq.4) txmsg=trim(hiscall)//' '//trim(mycall)//' RR73' - if(nfunc.eq.5) txmsg='TNX 73 GL' - call ft2_iwave(txmsg,ftx,snrdb,iwave) - iwave(23041:)=0 - i1=ptt(nport,1,1,iptt) - ntxok=1 - n=len(trim(txmsg)) - write(*,1010) cdatetime(),0,0.0,nint(ftx),(txmsg(i:i),i=1,n) - write(12,1010) cdatetime(),0,0.0,nint(ftx),(txmsg(i:i),i=1,n) -1010 format(a17,i4,f6.2,i5,' Tx ',37a1) - if(nfunc.ge.1 .and. nfunc.le.4) ntxed=nfunc - if(nfunc.ge.1 .and. nfunc.le.5) ltx(nfunc)=.true. - if(nfunc.eq.2 .or. nfunc.eq.3) QSO_in_progress=.true. - - return -end subroutine transmit +program ft2 + + use packjt77 + include 'gcom1.f90' + integer ft2audio,ptt + logical allok + character*20 pttport + character*8 arg + character*80 fname + integer*2 id2(30000) + + open(12,file='all_ft2.txt',status='unknown',position='append') + nargs=iargc() + if(nargs.eq.1) then + call getarg(1,fname) + open(10,file=fname,status='old',access='stream') + read(10) id2(1:22) !Read (and ignore) the header + read(10) id2 !Read the Rx data + close(10) + call ft2_decode(fname(1:17),nfqso,id2,ndecodes,mycall,hiscall,nrx) + go to 999 + endif + + allok=.true. +! Get home-station details + open(10,file='ft2.ini',status='old',err=1) + go to 2 +1 print*,'Cannot open ft2.ini' + allok=.false. +2 read(10,*,err=3) mycall,mygrid,ndevin,ndevout,pttport,exch + go to 4 +3 print*,'Error reading ft2.ini' + allok=.false. +4 if(index(pttport,'/').lt.1) read(pttport,*) nport + hiscall=' ' + hiscall_next=' ' + idevin=ndevin + idevout=ndevout + call padevsub(idevin,idevout) + if(idevin.ne.ndevin .or. idevout.ne.ndevout) allok=.false. + i1=0 + i1=ptt(nport,1,1,iptt) + i1=ptt(nport,1,0,iptt) + if(i1.lt.0 .and. nport.ne.0) allok=.false. + if(.not.allok) then + write(*,"('Please fix setup error(s) and restart.')") + go to 999 + endif + + nright=1 + iwrite=0 + iwave=0 + nwave=NTZ + nfsample=12000 + ngo=1 + npabuf=1152 + ntxok=0 + ntransmitting=0 + tx_once=.false. + snrdb=99.0 + txmsg='CQ K1JT FN20' + ltx=.false. + lrx=.false. + autoseq=.false. + QSO_in_progress=.false. + ntxed=0 + + if(nargs.eq.3) then + call getarg(1,txmsg) + call getarg(2,arg) + read(arg,*) f0 + call getarg(3,arg) + read(arg,*) snrdb + tx_once=.true. + ftx=1500.0 + call transmit(-1,ftx,iptt) + snrdb=99.0 + endif + +! Start the audio streams + ierr=ft2audio(idevin,idevout,npabuf,nright,y1,y2,NRING,iwrite,itx, & + iwave,nwave+3*1152,nfsample,nTxOK,nTransmitting,ngo) + if(ierr.ne.0) then + print*,'Error',ierr,' starting audio input and/or output.' + endif + +999 end program ft2 + +subroutine update(total_time,ic1,ic2) + + use wavhdr + type(hdr) h + real*8 total_time + integer*8 count0,count1,clkfreq + integer ptt + integer*2 id(30000) + logical transmitted,level,ok + character*70 line + character cdatetime*17,fname*17,mode*8,band*6 + include 'gcom1.f90' + data nt0/-1/,transmitted/.false./,snr/-99.0/ + data level/.false./ + save nt0,transmitted,level,snr,iptt + + if(ic1.ne.0 .or. ic2.ne.0) then + if(ic1.eq.27 .and. ic2.eq.0) ngo=0 !ESC + if(nTxOK.eq.0 .and. ntransmitting.eq.0) then + nfunc=0 + if(ic1.eq.0 .and. ic2.eq.59) nfunc=1 !F1 + if(ic1.eq.0 .and. ic2.eq.60) nfunc=2 !F2 + if(ic1.eq.0 .and. ic2.eq.61) nfunc=3 !F3 + if(ic1.eq.0 .and. ic2.eq.62) nfunc=4 !F4 + if(ic1.eq.0 .and. ic2.eq.63) nfunc=5 !F5 + if(nfunc.eq.1 .or. (nfunc.ge.2 .and. hiscall.ne.' ')) then + ftx=1500.0 + call transmit(nfunc,ftx,iptt) + endif + endif + if(ic1.eq.13 .and. ic2.eq.0) hiscall=hiscall_next + if((ic1.eq.97 .or. ic1.eq.65) .and. ic2.eq.0) autoseq=.not.autoseq + if((ic1.eq.108 .or. ic1.eq.76) .and. ic2.eq.0) level=.not.level + endif + + if(ntransmitting.eq.1) transmitted=.true. + if(transmitted .and. ntransmitting.eq.0) then + i1=0 + if(iptt.eq.1 .and. nport.gt.0) i1=ptt(nport,0,1,iptt) + if(tx_once .and. transmitted) stop + transmitted=.false. + endif + + nt=2*total_time + if(nt.gt.nt0 .or. ic1.ne.0 .or. ic2.ne.0) then + if(level) then +! Measure and display the average level of signal plus noise in past 0.5 s + k=iwrite-6000 + if(k.lt.1) k=k+NRING + sq=0. + do i=1,6000 + k=k+1 + if(k.gt.NRING) k=k-NRING + x=y1(k) + sq=sq + x*x + enddo + sigdb=0. + if(sq.gt.0.0) sigdb=db(sq/6000.0) + n=sigdb + if(n.lt.1) n=1 + if(n.gt.70) n=70 + line=' ' + line(n:n)='*' + write(*,1030) sigdb,ntxed,autoseq,QSO_in_progress,(line(i:i),i=1,n) +1030 format(f4.1,i3,2L2,1x,70a1) +! write(*,1020) nt,total_time,iwrite,itx,ntxok,ntransmitting,ndecodes, & +! snr,sigdb,line +!1020 format(i6,f9.3,i10,i6,3i3,f6.0,f6.1,1x,a30) + endif + k=iwrite-30000 + if(k.lt.1) k=k+NRING + do i=1,30000 + k=k+1 + if(k.gt.NRING) k=k-NRING + id(i)=y1(k) + enddo + nutc=0 + nfqso=1500 + ndecodes=0 + if(maxval(abs(id)).gt.0) then + call system_clock(count0,clkfreq) + nrx=-1 + call ft2_decode(cdatetime(),nfqso,id,ndecodes,mycall,hiscall,nrx) + call system_clock(count1,clkfreq) +! tdecode=float(count1-count0)/float(clkfreq) + + if(ndecodes.ge.1) then + fMHz=7.074 + mode='FT2' + nsubmode=1 + ntrperiod=0 + h=default_header(12000,30000) + k=0 + do i=1,250 + sq=0 + do n=1,120 + k=k+1 + x=id(k) + sq=sq + x*x + enddo + write(43,3043) i,0.01*i,1.e-4*sq +3043 format(i7,f12.6,f12.3) + enddo + call set_wsjtx_wav_params(fMHz,mode,nsubmode,ntrperiod,id) + band="" + mode="" + nsubmode=-1 + ntrperiod=-1 + call get_wsjtx_wav_params(id,band,mode,nsubmode,ntrperiod,ok) +! write(*,1010) band,ntrperiod,mode,char(ichar('A')-1+id(3)) +!1010 format('Band: ',a6,' T/R period:',i4,' Mode: ',a8,1x,a1) + + fname=cdatetime() + fname(14:17)='.wav' + open(13,file=fname,status='unknown',access='stream') + write(13) h,id + close(13) + endif + if(autoseq .and.nrx.eq.2) QSO_in_progress=.true. + if(autoseq .and. QSO_in_progress .and. nrx.ge.1 .and. nrx.le.4) then + lrx(nrx)=.true. + ftx=1500.0 + if(ntxed.eq.1) then + if(nrx.eq.2) then + call transmit(3,ftx,iptt) + else + call transmit(1,ftx,iptt) + endif + endif + if(ntxed.eq.2) then + if(nrx.eq.3) then + call transmit(4,ftx,iptt) + QSO_in_progress=.false. + write(*,1032) +1032 format('QSO complete: S+P side') + else + call transmit(2,ftx,iptt) + endif + endif + if(ntxed.eq.3) then + if(nrx.eq.4) then + QSO_in_progress=.false. + write(*,1034) +1034 format('QSO complete: CQ side') + else + call transmit(3,ftx,iptt) + endif + endif + endif + endif + nt0=nt + endif + + return +end subroutine update + +character*17 function cdatetime() + character cdate*8,ctime*10 + call date_and_time(cdate,ctime) + cdatetime=cdate(3:8)//'_'//ctime + return +end function cdatetime + +subroutine transmit(nfunc,ftx,iptt) + include 'gcom1.f90' + character*17 cdatetime + integer ptt + + if(nTxOK.eq.1) return + + if(nfunc.eq.1) txmsg='CQ '//trim(mycall)//' '//mygrid + if(nfunc.eq.2) txmsg=trim(hiscall)//' '//trim(mycall)// & + ' 559 '//trim(exch) + if(nfunc.eq.3) txmsg=trim(hiscall)//' '//trim(mycall)// & + ' R 559 '//trim(exch) + if(nfunc.eq.4) txmsg=trim(hiscall)//' '//trim(mycall)//' RR73' + if(nfunc.eq.5) txmsg='TNX 73 GL' + call ft2_iwave(txmsg,ftx,snrdb,iwave) + iwave(23041:)=0 + i1=ptt(nport,1,1,iptt) + ntxok=1 + n=len(trim(txmsg)) + write(*,1010) cdatetime(),0,0.0,nint(ftx),(txmsg(i:i),i=1,n) + write(12,1010) cdatetime(),0,0.0,nint(ftx),(txmsg(i:i),i=1,n) +1010 format(a17,i4,f6.2,i5,' Tx ',37a1) + if(nfunc.ge.1 .and. nfunc.le.4) ntxed=nfunc + if(nfunc.ge.1 .and. nfunc.le.5) ltx(nfunc)=.true. + if(nfunc.eq.2 .or. nfunc.eq.3) QSO_in_progress=.true. + + return +end subroutine transmit diff --git a/lib/ft2/ft2.ini b/lib/ft2/ft2.ini index 95673fc4..d66770d1 100755 --- a/lib/ft2/ft2.ini +++ b/lib/ft2/ft2.ini @@ -1,2 +1,2 @@ -K1JT FN20 1 5 0 NJ -MyCall MyGrid AudioIn AudioOut PTTport Exch +K1JT FN20 1 5 0 NJ +MyCall MyGrid AudioIn AudioOut PTTport Exch diff --git a/lib/ft2/ft2_decode.f90 b/lib/ft2/ft2_decode.f90 index 8159cb2a..1d1bb6a5 100755 --- a/lib/ft2/ft2_decode.f90 +++ b/lib/ft2/ft2_decode.f90 @@ -1,298 +1,298 @@ -subroutine ft2_decode(cdatetime0,nfqso,iwave,ndecodes,mycall,hiscall,nrx,line) - - use crc - use packjt77 - include 'ft2_params.f90' - character message*37,c77*77 - character*61 line - character*37 decodes(100) - character*120 data_dir - character*17 cdatetime0,cdatetime - character*6 mycall,hiscall,hhmmss - complex c2(0:NMAX/16-1) !Complex waveform - complex cb(0:NMAX/16-1) - complex cd(0:144*10-1) !Complex waveform - complex c1(0:9),c0(0:9) - complex ccor(0:1,144) - complex csum,cterm,cc0,cc1,csync1 - real*8 fMHz - - real a(5) - real rxdata(128),llr(128) !Soft symbols - real llr2(128) - real sbits(144),sbits1(144),sbits3(144) - real ps(0:8191),psbest(0:8191) - real candidate(3,100) - real savg(NH1) - integer*2 iwave(NMAX) !Generated full-length waveform - integer*1 message77(77),apmask(128),cw(128) - integer*1 hbits(144),hbits1(144),hbits3(144) - integer*1 s16(16) - logical unpk77_success - data s16/0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0/ - - hhmmss=cdatetime0(8:13) - fs=12000.0/NDOWN !Sample rate - dt=1/fs !Sample interval after downsample (s) - tt=NSPS*dt !Duration of "itone" symbols (s) - baud=1.0/tt !Keying rate for "itone" symbols (baud) - txt=NZ*dt !Transmission length (s) - twopi=8.0*atan(1.0) - h=0.8 !h=0.8 seems to be optimum for AWGN sensitivity (not for fading) - - dphi=twopi/2*baud*h*dt*16 ! dt*16 is samp interval after downsample - dphi0=-1*dphi - dphi1=+1*dphi - phi0=0.0 - phi1=0.0 - do i=0,9 - c1(i)=cmplx(cos(phi1),sin(phi1)) - c0(i)=cmplx(cos(phi0),sin(phi0)) - phi1=mod(phi1+dphi1,twopi) - phi0=mod(phi0+dphi0,twopi) - enddo - the=twopi*h/2.0 - cc1=cmplx(cos(the),-sin(the)) - cc0=cmplx(cos(the),sin(the)) - - data_dir="." - fMHz=7.074 - ncoh=1 - candidate=0.0 - ncand=0 - fa=375.0 - fb=3000.0 - syncmin=0.2 - maxcand=100 - nfqso=-1 - call getcandidates2a(iwave,fa,fb,maxcand,savg,candidate,ncand) - ndecodes=0 - do icand=1,ncand - f0=candidate(1,icand) - if( f0.le.375.0 .or. f0.ge.(5000.0-375.0) ) cycle - call ft2_downsample(iwave,f0,c2) ! downsample from 160s/Symbol to 10s/Symbol -! 750 samples/second here - ibest=-1 - sybest=-99. - dfbest=-1. -!### do if=-15,+15 - do if=-30,30 - df=if - a=0. - a(1)=-df - call twkfreq1(c2,NMAX/16,fs,a,cb) - do is=0,374 !DT search range is 0 - 0.5 s - csync1=0. - cterm=1 - do ib=1,16 - i1=(ib-1)*10+is - i2=i1+136*10 - if(s16(ib).eq.1) then - csync1=csync1+sum(cb(i1:i1+9)*conjg(c1(0:9)))*cterm - cterm=cterm*cc1 - else - csync1=csync1+sum(cb(i1:i1+9)*conjg(c0(0:9)))*cterm - cterm=cterm*cc0 - endif - enddo - if(abs(csync1).gt.sybest) then - ibest=is - sybest=abs(csync1) - dfbest=df - endif - enddo - enddo - - a=0. - a(1)=-dfbest - call twkfreq1(c2,NMAX/16,fs,a,cb) - ib=ibest - cd=cb(ib:ib+144*10-1) - s2=sum(real(cd*conjg(cd)))/(10*144) - cd=cd/sqrt(s2) - do nseq=1,5 - if( nseq.eq.1 ) then ! noncoherent single-symbol detection - sbits1=0.0 - do ibit=1,144 - ib=(ibit-1)*10 - ccor(1,ibit)=sum(cd(ib:ib+9)*conjg(c1(0:9))) - ccor(0,ibit)=sum(cd(ib:ib+9)*conjg(c0(0:9))) - sbits1(ibit)=abs(ccor(1,ibit))-abs(ccor(0,ibit)) - hbits1(ibit)=0 - if(sbits1(ibit).gt.0) hbits1(ibit)=1 - enddo - sbits=sbits1 - hbits=hbits1 - sbits3=sbits1 - hbits3=hbits1 - elseif( nseq.ge.2 ) then - nbit=2*nseq-1 - numseq=2**(nbit) - ps=0 - do ibit=nbit/2+1,144-nbit/2 - ps=0.0 - pmax=0.0 - do iseq=0,numseq-1 - csum=0.0 - cterm=1.0 - k=1 - do i=nbit-1,0,-1 - ibb=iand(iseq/(2**i),1) - csum=csum+ccor(ibb,ibit-(nbit/2+1)+k)*cterm - if(ibb.eq.0) cterm=cterm*cc0 - if(ibb.eq.1) cterm=cterm*cc1 - k=k+1 - enddo - ps(iseq)=abs(csum) - if( ps(iseq) .gt. pmax ) then - pmax=ps(iseq) - ibflag=1 - endif - enddo - if( ibflag .eq. 1 ) then - psbest=ps - ibflag=0 - endif - call getbitmetric(2**(nbit/2),psbest,numseq,sbits3(ibit)) - hbits3(ibit)=0 - if(sbits3(ibit).gt.0) hbits3(ibit)=1 - enddo - sbits=sbits3 - hbits=hbits3 - endif - nsync_qual=count(hbits(1:16).eq.s16) - if(nsync_qual.lt.10) exit - rxdata=sbits(17:144) - rxav=sum(rxdata(1:128))/128.0 - rx2av=sum(rxdata(1:128)*rxdata(1:128))/128.0 - rxsig=sqrt(rx2av-rxav*rxav) - rxdata=rxdata/rxsig - sigma=0.80 - llr(1:128)=2*rxdata/(sigma*sigma) - apmask=0 - max_iterations=40 - do ibias=0,0 - llr2=llr - if(ibias.eq.1) llr2=llr+0.4 - if(ibias.eq.2) llr2=llr-0.4 - call bpdecode128_90(llr2,apmask,max_iterations,message77,cw,nharderror,niterations) - if(nharderror.ge.0) exit - enddo - nhardmin=-1 - if(sum(message77).eq.0) cycle - if( nharderror.ge.0 ) then - write(c77,'(77i1)') message77(1:77) - call unpack77(c77,nrx,message,unpk77_success) - idupe=0 - do i=1,ndecodes - if(decodes(i).eq.message) idupe=1 - enddo - if(idupe.eq.1) exit - ndecodes=ndecodes+1 - decodes(ndecodes)=message - xsnr=db(sybest*sybest) - 115.0 !### Rough estimate of S/N ### - nsnr=nint(xsnr) - freq=f0+dfbest - write(line,1000) hhmmss,nsnr,ibest/750.0,nint(freq),message -1000 format(a6,i4,f5.2,i5,' + ',1x,a37) - open(24,file='all_ft2.txt',status='unknown',position='append') - write(24,1002) cdatetime0,nsnr,ibest/750.0,nint(freq),message, & - nseq,nharderror,nhardmin - if(hhmmss.eq.' ') write(*,1002) cdatetime0,nsnr, & - ibest/750.0,nint(freq),message,nseq,nharderror,nhardmin -1002 format(a17,i4,f6.2,i5,' Rx ',a37,3i5) - close(24) - -!### Temporary: assume most recent decoded message conveys "hiscall". - i0=index(message,' ') - if(i0.ge.3 .and. i0.le.7) then - hiscall=message(i0+1:i0+6) - i1=index(hiscall,' ') - if(i1.gt.0) hiscall=hiscall(1:i1) - endif - nrx=-1 - if(index(message,'CQ ').eq.1) nrx=1 - if((index(message,trim(mycall)//' ').eq.1) .and. & - (index(message,' '//trim(hiscall)//' ').ge.4)) then - if(index(message,' 559 ').gt.8) nrx=2 - if(index(message,' R 559 ').gt.8) nrx=3 - if(index(message,' RR73 ').gt.8) nrx=4 - endif -!### - exit - endif - enddo ! nseq - enddo !candidate list - - return -end subroutine ft2_decode - -subroutine getbitmetric(ib,ps,ns,xmet) - real ps(0:ns-1) - xm1=0 - xm0=0 - do i=0,ns-1 - if( iand(i/ib,1) .eq. 1 .and. ps(i) .gt. xm1 ) xm1=ps(i) - if( iand(i/ib,1) .eq. 0 .and. ps(i) .gt. xm0 ) xm0=ps(i) - enddo - xmet=xm1-xm0 - return -end subroutine getbitmetric - -subroutine downsample2(ci,f0,co) - parameter(NI=144*160,NH=NI/2,NO=NI/16) ! downsample from 200 samples per symbol to 10 - complex ci(0:NI-1),ct(0:NI-1) - complex co(0:NO-1) - fs=12000.0 - df=fs/NI - ct=ci - call four2a(ct,NI,1,-1,1) !c2c FFT to freq domain - i0=nint(f0/df) - ct=cshift(ct,i0) - co=0.0 - co(0)=ct(0) - b=8.0 - do i=1,NO/2 - arg=(i*df/b)**2 - filt=exp(-arg) - co(i)=ct(i)*filt - co(NO-i)=ct(NI-i)*filt - enddo - co=co/NO - call four2a(co,NO,1,1,1) !c2c FFT back to time domain - return -end subroutine downsample2 - -subroutine ft2_downsample(iwave,f0,c) - -! Input: i*2 data in iwave() at sample rate 12000 Hz -! Output: Complex data in c(), sampled at 1200 Hz - - include 'ft2_params.f90' - parameter (NFFT2=NMAX/16) - integer*2 iwave(NMAX) - complex c(0:NMAX/16-1) - complex c1(0:NFFT2-1) - complex cx(0:NMAX/2) - real x(NMAX) - equivalence (x,cx) - - BW=4.0*75 - df=12000.0/NMAX - x=iwave - call four2a(x,NMAX,1,-1,0) !r2c FFT to freq domain - ibw=nint(BW/df) - i0=nint(f0/df) - c1=0. - c1(0)=cx(i0) - do i=1,NFFT2/2 - arg=(i-1)*df/bw - win=exp(-arg*arg) - c1(i)=cx(i0+i)*win - c1(NFFT2-i)=cx(i0-i)*win - enddo - c1=c1/NFFT2 - call four2a(c1,NFFT2,1,1,1) !c2c FFT back to time domain - c=c1(0:NMAX/16-1) - return -end subroutine ft2_downsample +subroutine ft2_decode(cdatetime0,nfqso,iwave,ndecodes,mycall,hiscall,nrx,line) + + use crc + use packjt77 + include 'ft2_params.f90' + character message*37,c77*77 + character*61 line + character*37 decodes(100) + character*120 data_dir + character*17 cdatetime0,cdatetime + character*6 mycall,hiscall,hhmmss + complex c2(0:NMAX/16-1) !Complex waveform + complex cb(0:NMAX/16-1) + complex cd(0:144*10-1) !Complex waveform + complex c1(0:9),c0(0:9) + complex ccor(0:1,144) + complex csum,cterm,cc0,cc1,csync1 + real*8 fMHz + + real a(5) + real rxdata(128),llr(128) !Soft symbols + real llr2(128) + real sbits(144),sbits1(144),sbits3(144) + real ps(0:8191),psbest(0:8191) + real candidate(3,100) + real savg(NH1) + integer*2 iwave(NMAX) !Generated full-length waveform + integer*1 message77(77),apmask(128),cw(128) + integer*1 hbits(144),hbits1(144),hbits3(144) + integer*1 s16(16) + logical unpk77_success + data s16/0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0/ + + hhmmss=cdatetime0(8:13) + fs=12000.0/NDOWN !Sample rate + dt=1/fs !Sample interval after downsample (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + baud=1.0/tt !Keying rate for "itone" symbols (baud) + txt=NZ*dt !Transmission length (s) + twopi=8.0*atan(1.0) + h=0.8 !h=0.8 seems to be optimum for AWGN sensitivity (not for fading) + + dphi=twopi/2*baud*h*dt*16 ! dt*16 is samp interval after downsample + dphi0=-1*dphi + dphi1=+1*dphi + phi0=0.0 + phi1=0.0 + do i=0,9 + c1(i)=cmplx(cos(phi1),sin(phi1)) + c0(i)=cmplx(cos(phi0),sin(phi0)) + phi1=mod(phi1+dphi1,twopi) + phi0=mod(phi0+dphi0,twopi) + enddo + the=twopi*h/2.0 + cc1=cmplx(cos(the),-sin(the)) + cc0=cmplx(cos(the),sin(the)) + + data_dir="." + fMHz=7.074 + ncoh=1 + candidate=0.0 + ncand=0 + fa=375.0 + fb=3000.0 + syncmin=0.2 + maxcand=100 + nfqso=-1 + call getcandidates2a(iwave,fa,fb,maxcand,savg,candidate,ncand) + ndecodes=0 + do icand=1,ncand + f0=candidate(1,icand) + if( f0.le.375.0 .or. f0.ge.(5000.0-375.0) ) cycle + call ft2_downsample(iwave,f0,c2) ! downsample from 160s/Symbol to 10s/Symbol +! 750 samples/second here + ibest=-1 + sybest=-99. + dfbest=-1. +!### do if=-15,+15 + do if=-30,30 + df=if + a=0. + a(1)=-df + call twkfreq1(c2,NMAX/16,fs,a,cb) + do is=0,374 !DT search range is 0 - 0.5 s + csync1=0. + cterm=1 + do ib=1,16 + i1=(ib-1)*10+is + i2=i1+136*10 + if(s16(ib).eq.1) then + csync1=csync1+sum(cb(i1:i1+9)*conjg(c1(0:9)))*cterm + cterm=cterm*cc1 + else + csync1=csync1+sum(cb(i1:i1+9)*conjg(c0(0:9)))*cterm + cterm=cterm*cc0 + endif + enddo + if(abs(csync1).gt.sybest) then + ibest=is + sybest=abs(csync1) + dfbest=df + endif + enddo + enddo + + a=0. + a(1)=-dfbest + call twkfreq1(c2,NMAX/16,fs,a,cb) + ib=ibest + cd=cb(ib:ib+144*10-1) + s2=sum(real(cd*conjg(cd)))/(10*144) + cd=cd/sqrt(s2) + do nseq=1,5 + if( nseq.eq.1 ) then ! noncoherent single-symbol detection + sbits1=0.0 + do ibit=1,144 + ib=(ibit-1)*10 + ccor(1,ibit)=sum(cd(ib:ib+9)*conjg(c1(0:9))) + ccor(0,ibit)=sum(cd(ib:ib+9)*conjg(c0(0:9))) + sbits1(ibit)=abs(ccor(1,ibit))-abs(ccor(0,ibit)) + hbits1(ibit)=0 + if(sbits1(ibit).gt.0) hbits1(ibit)=1 + enddo + sbits=sbits1 + hbits=hbits1 + sbits3=sbits1 + hbits3=hbits1 + elseif( nseq.ge.2 ) then + nbit=2*nseq-1 + numseq=2**(nbit) + ps=0 + do ibit=nbit/2+1,144-nbit/2 + ps=0.0 + pmax=0.0 + do iseq=0,numseq-1 + csum=0.0 + cterm=1.0 + k=1 + do i=nbit-1,0,-1 + ibb=iand(iseq/(2**i),1) + csum=csum+ccor(ibb,ibit-(nbit/2+1)+k)*cterm + if(ibb.eq.0) cterm=cterm*cc0 + if(ibb.eq.1) cterm=cterm*cc1 + k=k+1 + enddo + ps(iseq)=abs(csum) + if( ps(iseq) .gt. pmax ) then + pmax=ps(iseq) + ibflag=1 + endif + enddo + if( ibflag .eq. 1 ) then + psbest=ps + ibflag=0 + endif + call getbitmetric(2**(nbit/2),psbest,numseq,sbits3(ibit)) + hbits3(ibit)=0 + if(sbits3(ibit).gt.0) hbits3(ibit)=1 + enddo + sbits=sbits3 + hbits=hbits3 + endif + nsync_qual=count(hbits(1:16).eq.s16) + if(nsync_qual.lt.10) exit + rxdata=sbits(17:144) + rxav=sum(rxdata(1:128))/128.0 + rx2av=sum(rxdata(1:128)*rxdata(1:128))/128.0 + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + sigma=0.80 + llr(1:128)=2*rxdata/(sigma*sigma) + apmask=0 + max_iterations=40 + do ibias=0,0 + llr2=llr + if(ibias.eq.1) llr2=llr+0.4 + if(ibias.eq.2) llr2=llr-0.4 + call bpdecode128_90(llr2,apmask,max_iterations,message77,cw,nharderror,niterations) + if(nharderror.ge.0) exit + enddo + nhardmin=-1 + if(sum(message77).eq.0) cycle + if( nharderror.ge.0 ) then + write(c77,'(77i1)') message77(1:77) + call unpack77(c77,nrx,message,unpk77_success) + idupe=0 + do i=1,ndecodes + if(decodes(i).eq.message) idupe=1 + enddo + if(idupe.eq.1) exit + ndecodes=ndecodes+1 + decodes(ndecodes)=message + xsnr=db(sybest*sybest) - 115.0 !### Rough estimate of S/N ### + nsnr=nint(xsnr) + freq=f0+dfbest + write(line,1000) hhmmss,nsnr,ibest/750.0,nint(freq),message +1000 format(a6,i4,f5.2,i5,' + ',1x,a37) + open(24,file='all_ft2.txt',status='unknown',position='append') + write(24,1002) cdatetime0,nsnr,ibest/750.0,nint(freq),message, & + nseq,nharderror,nhardmin + if(hhmmss.eq.' ') write(*,1002) cdatetime0,nsnr, & + ibest/750.0,nint(freq),message,nseq,nharderror,nhardmin +1002 format(a17,i4,f6.2,i5,' Rx ',a37,3i5) + close(24) + +!### Temporary: assume most recent decoded message conveys "hiscall". + i0=index(message,' ') + if(i0.ge.3 .and. i0.le.7) then + hiscall=message(i0+1:i0+6) + i1=index(hiscall,' ') + if(i1.gt.0) hiscall=hiscall(1:i1) + endif + nrx=-1 + if(index(message,'CQ ').eq.1) nrx=1 + if((index(message,trim(mycall)//' ').eq.1) .and. & + (index(message,' '//trim(hiscall)//' ').ge.4)) then + if(index(message,' 559 ').gt.8) nrx=2 + if(index(message,' R 559 ').gt.8) nrx=3 + if(index(message,' RR73 ').gt.8) nrx=4 + endif +!### + exit + endif + enddo ! nseq + enddo !candidate list + + return +end subroutine ft2_decode + +subroutine getbitmetric(ib,ps,ns,xmet) + real ps(0:ns-1) + xm1=0 + xm0=0 + do i=0,ns-1 + if( iand(i/ib,1) .eq. 1 .and. ps(i) .gt. xm1 ) xm1=ps(i) + if( iand(i/ib,1) .eq. 0 .and. ps(i) .gt. xm0 ) xm0=ps(i) + enddo + xmet=xm1-xm0 + return +end subroutine getbitmetric + +subroutine downsample2(ci,f0,co) + parameter(NI=144*160,NH=NI/2,NO=NI/16) ! downsample from 200 samples per symbol to 10 + complex ci(0:NI-1),ct(0:NI-1) + complex co(0:NO-1) + fs=12000.0 + df=fs/NI + ct=ci + call four2a(ct,NI,1,-1,1) !c2c FFT to freq domain + i0=nint(f0/df) + ct=cshift(ct,i0) + co=0.0 + co(0)=ct(0) + b=8.0 + do i=1,NO/2 + arg=(i*df/b)**2 + filt=exp(-arg) + co(i)=ct(i)*filt + co(NO-i)=ct(NI-i)*filt + enddo + co=co/NO + call four2a(co,NO,1,1,1) !c2c FFT back to time domain + return +end subroutine downsample2 + +subroutine ft2_downsample(iwave,f0,c) + +! Input: i*2 data in iwave() at sample rate 12000 Hz +! Output: Complex data in c(), sampled at 1200 Hz + + include 'ft2_params.f90' + parameter (NFFT2=NMAX/16) + integer*2 iwave(NMAX) + complex c(0:NMAX/16-1) + complex c1(0:NFFT2-1) + complex cx(0:NMAX/2) + real x(NMAX) + equivalence (x,cx) + + BW=4.0*75 + df=12000.0/NMAX + x=iwave + call four2a(x,NMAX,1,-1,0) !r2c FFT to freq domain + ibw=nint(BW/df) + i0=nint(f0/df) + c1=0. + c1(0)=cx(i0) + do i=1,NFFT2/2 + arg=(i-1)*df/bw + win=exp(-arg*arg) + c1(i)=cx(i0+i)*win + c1(NFFT2-i)=cx(i0-i)*win + enddo + c1=c1/NFFT2 + call four2a(c1,NFFT2,1,1,1) !c2c FFT back to time domain + c=c1(0:NMAX/16-1) + return +end subroutine ft2_downsample diff --git a/lib/ft2/ft2_gfsk_iwave.f90 b/lib/ft2/ft2_gfsk_iwave.f90 index f0c46ceb..2611eca0 100755 --- a/lib/ft2/ft2_gfsk_iwave.f90 +++ b/lib/ft2/ft2_gfsk_iwave.f90 @@ -1,88 +1,88 @@ -subroutine ft2_gfsk_iwave(msg37,f0,snrdb,iwave) - -! Generate waveform for experimental "FT2" mode - - use packjt77 - include 'ft2_params.f90' !Set various constants - parameter (NWAVE=(NN+2)*NSPS) - character msg37*37,msgsent37*37 - real wave(NWAVE),xnoise(NWAVE) - real dphi(NWAVE) - real pulse(480) - - integer itone(NN) - integer*2 iwave(NWAVE) !Generated full-length waveform - logical first - data first/.true./ - save pulse - - twopi=8.0*atan(1.0) - fs=12000.0 !Sample rate (Hz) - dt=1.0/fs !Sample interval (s) - hmod=0.8 !Modulation index (MSK=0.5, FSK=1.0) - tt=NSPS*dt !Duration of symbols (s) - baud=1.0/tt !Keying rate (baud) - bw=1.5*baud !Occupied bandwidth (Hz) - txt=NZ*dt !Transmission length (s) - bandwidth_ratio=2500.0/(fs/2.0) -! sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) -! if(snrdb.gt.90.0) sig=1.0 - txt=NN*NSPS/12000.0 - - if(first) then -! The filtered frequency pulse - do i=1,480 - tt=(i-240.5)/160.0 - pulse(i)=gfsk_pulse(1.0,tt) - enddo - dphi_peak=twopi*(hmod/2.0)/real(NSPS) - first=.false. - endif - -! Source-encode, then get itone(): - itype=1 - call genft2(msg37,0,msgsent37,itone,itype) - -! Create the instantaneous frequency waveform - dphi=0.0 - do j=1,NN - ib=(j-1)*160+1 - ie=ib+480-1 - dphi(ib:ie)=dphi(ib:ie)+dphi_peak*pulse*(2*itone(j)-1) - enddo - - phi=0.0 - wave=0.0 - sqrt2=sqrt(2.) - dphi=dphi+twopi*f0*dt - do j=1,NWAVE - wave(j)=sqrt2*sin(phi) - sqsig=sqsig + wave(j)**2 - phi=mod(phi+dphi(j),twopi) - enddo - wave(1:160)=wave(1:160)*(1.0-cos(twopi*(/(i,i=0,159)/)/320.0) )/2.0 - wave(145*160+1:146*160)=wave(145*160+1:146*160)*(1.0+cos(twopi*(/(i,i=0,159)/)/320.0 ))/2.0 - wave(146*160+1:)=0. - - if(snrdb.gt.90.0) then - iwave=nint((32767.0/sqrt(2.0))*wave) - return - endif - - sqnoise=1.e-30 - if(snrdb.lt.90) then - do i=1,NWAVE !Add gaussian noise at specified SNR - xnoise(i)=gran() !Noise has rms = 1.0 - enddo - endif - xnoise=xnoise*sqrt(0.5*fs/2500.0) - fac=30.0 - snr_amplitude=10.0**(0.05*snrdb) - wave=fac*(snr_amplitude*wave + xnoise) - datpk=maxval(abs(wave)) - print*,'A',snr_amplitude,datpk - - iwave=nint((30000.0/datpk)*wave) - - return -end subroutine ft2_gfsk_iwave +subroutine ft2_gfsk_iwave(msg37,f0,snrdb,iwave) + +! Generate waveform for experimental "FT2" mode + + use packjt77 + include 'ft2_params.f90' !Set various constants + parameter (NWAVE=(NN+2)*NSPS) + character msg37*37,msgsent37*37 + real wave(NWAVE),xnoise(NWAVE) + real dphi(NWAVE) + real pulse(480) + + integer itone(NN) + integer*2 iwave(NWAVE) !Generated full-length waveform + logical first + data first/.true./ + save pulse + + twopi=8.0*atan(1.0) + fs=12000.0 !Sample rate (Hz) + dt=1.0/fs !Sample interval (s) + hmod=0.8 !Modulation index (MSK=0.5, FSK=1.0) + tt=NSPS*dt !Duration of symbols (s) + baud=1.0/tt !Keying rate (baud) + bw=1.5*baud !Occupied bandwidth (Hz) + txt=NZ*dt !Transmission length (s) + bandwidth_ratio=2500.0/(fs/2.0) +! sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) +! if(snrdb.gt.90.0) sig=1.0 + txt=NN*NSPS/12000.0 + + if(first) then +! The filtered frequency pulse + do i=1,480 + tt=(i-240.5)/160.0 + pulse(i)=gfsk_pulse(1.0,tt) + enddo + dphi_peak=twopi*(hmod/2.0)/real(NSPS) + first=.false. + endif + +! Source-encode, then get itone(): + itype=1 + call genft2(msg37,0,msgsent37,itone,itype) + +! Create the instantaneous frequency waveform + dphi=0.0 + do j=1,NN + ib=(j-1)*160+1 + ie=ib+480-1 + dphi(ib:ie)=dphi(ib:ie)+dphi_peak*pulse*(2*itone(j)-1) + enddo + + phi=0.0 + wave=0.0 + sqrt2=sqrt(2.) + dphi=dphi+twopi*f0*dt + do j=1,NWAVE + wave(j)=sqrt2*sin(phi) + sqsig=sqsig + wave(j)**2 + phi=mod(phi+dphi(j),twopi) + enddo + wave(1:160)=wave(1:160)*(1.0-cos(twopi*(/(i,i=0,159)/)/320.0) )/2.0 + wave(145*160+1:146*160)=wave(145*160+1:146*160)*(1.0+cos(twopi*(/(i,i=0,159)/)/320.0 ))/2.0 + wave(146*160+1:)=0. + + if(snrdb.gt.90.0) then + iwave=nint((32767.0/sqrt(2.0))*wave) + return + endif + + sqnoise=1.e-30 + if(snrdb.lt.90) then + do i=1,NWAVE !Add gaussian noise at specified SNR + xnoise(i)=gran() !Noise has rms = 1.0 + enddo + endif + xnoise=xnoise*sqrt(0.5*fs/2500.0) + fac=30.0 + snr_amplitude=10.0**(0.05*snrdb) + wave=fac*(snr_amplitude*wave + xnoise) + datpk=maxval(abs(wave)) + print*,'A',snr_amplitude,datpk + + iwave=nint((30000.0/datpk)*wave) + + return +end subroutine ft2_gfsk_iwave diff --git a/lib/ft2/ft2_iwave.f90 b/lib/ft2/ft2_iwave.f90 index 4692b687..10b9908d 100755 --- a/lib/ft2/ft2_iwave.f90 +++ b/lib/ft2/ft2_iwave.f90 @@ -1,64 +1,64 @@ -subroutine ft2_iwave(msg37,f0,snrdb,iwave) - -! Generate waveform for experimental "FT2" mode - - use packjt77 - include 'ft2_params.f90' !Set various constants - parameter (NWAVE=NN*NSPS) - character msg37*37,msgsent37*37 - real wave(NWAVE),xnoise(NWAVE) - integer itone(NN) - integer*2 iwave(NWAVE) !Generated full-length waveform - - twopi=8.0*atan(1.0) - fs=12000.0 !Sample rate (Hz) - dt=1.0/fs !Sample interval (s) - hmod=0.8 !Modulation index (MSK=0.5, FSK=1.0) - tt=NSPS*dt !Duration of symbols (s) - baud=1.0/tt !Keying rate (baud) - bw=1.5*baud !Occupied bandwidth (Hz) - txt=NZ*dt !Transmission length (s) - bandwidth_ratio=2500.0/(fs/2.0) -! sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) -! if(snrdb.gt.90.0) sig=1.0 - txt=NN*NSPS/12000.0 - -! Source-encode, then get itone(): - itype=1 - call genft2(msg37,0,msgsent37,itone,itype) - - k=0 - phi=0.0 - sqsig=0. - do j=1,NN !Generate real waveform - dphi=twopi*(f0*dt+(hmod/2.0)*(2*itone(j)-1)/real(NSPS)) - do i=1,NSPS - k=k+1 - wave(k)=sqrt(2.0)*sin(phi) !Signal has rms = 1.0 - sqsig=sqsig + wave(k)**2 - phi=mod(phi+dphi,twopi) - enddo - enddo - - if(snrdb.gt.90.0) then - iwave=nint((32767.0/sqrt(2.0))*wave) - return - endif - - sqnoise=1.e-30 - if(snrdb.lt.90) then - do i=1,NWAVE !Add gaussian noise at specified SNR - xnoise(i)=gran() !Noise has rms = 1.0 - enddo - endif - xnoise=xnoise*sqrt(0.5*fs/2500.0) - fac=30.0 - snr_amplitude=10.0**(0.05*snrdb) - wave=fac*(snr_amplitude*wave + xnoise) - datpk=maxval(abs(wave)) - print*,'A',snr_amplitude,datpk - - iwave=nint((30000.0/datpk)*wave) - - return -end subroutine ft2_iwave +subroutine ft2_iwave(msg37,f0,snrdb,iwave) + +! Generate waveform for experimental "FT2" mode + + use packjt77 + include 'ft2_params.f90' !Set various constants + parameter (NWAVE=NN*NSPS) + character msg37*37,msgsent37*37 + real wave(NWAVE),xnoise(NWAVE) + integer itone(NN) + integer*2 iwave(NWAVE) !Generated full-length waveform + + twopi=8.0*atan(1.0) + fs=12000.0 !Sample rate (Hz) + dt=1.0/fs !Sample interval (s) + hmod=0.8 !Modulation index (MSK=0.5, FSK=1.0) + tt=NSPS*dt !Duration of symbols (s) + baud=1.0/tt !Keying rate (baud) + bw=1.5*baud !Occupied bandwidth (Hz) + txt=NZ*dt !Transmission length (s) + bandwidth_ratio=2500.0/(fs/2.0) +! sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) +! if(snrdb.gt.90.0) sig=1.0 + txt=NN*NSPS/12000.0 + +! Source-encode, then get itone(): + itype=1 + call genft2(msg37,0,msgsent37,itone,itype) + + k=0 + phi=0.0 + sqsig=0. + do j=1,NN !Generate real waveform + dphi=twopi*(f0*dt+(hmod/2.0)*(2*itone(j)-1)/real(NSPS)) + do i=1,NSPS + k=k+1 + wave(k)=sqrt(2.0)*sin(phi) !Signal has rms = 1.0 + sqsig=sqsig + wave(k)**2 + phi=mod(phi+dphi,twopi) + enddo + enddo + + if(snrdb.gt.90.0) then + iwave=nint((32767.0/sqrt(2.0))*wave) + return + endif + + sqnoise=1.e-30 + if(snrdb.lt.90) then + do i=1,NWAVE !Add gaussian noise at specified SNR + xnoise(i)=gran() !Noise has rms = 1.0 + enddo + endif + xnoise=xnoise*sqrt(0.5*fs/2500.0) + fac=30.0 + snr_amplitude=10.0**(0.05*snrdb) + wave=fac*(snr_amplitude*wave + xnoise) + datpk=maxval(abs(wave)) + print*,'A',snr_amplitude,datpk + + iwave=nint((30000.0/datpk)*wave) + + return +end subroutine ft2_iwave diff --git a/lib/ft2/ft2_params.f90 b/lib/ft2/ft2_params.f90 index ef3277cb..4751e47e 100755 --- a/lib/ft2/ft2_params.f90 +++ b/lib/ft2/ft2_params.f90 @@ -1,12 +1,12 @@ -! LDPC (128,90) code -parameter (KK=90) !Information bits (77 + CRC13) -parameter (ND=128) !Data symbols -parameter (NS=16) !Sync symbols (2x8) -parameter (NN=NS+ND) !Total channel symbols (144) -parameter (NSPS=160) !Samples per symbol at 12000 S/s -parameter (NZ=NSPS*NN) !Samples in full 1.92 s waveform (23040) -parameter (NMAX=30000) !Samples in iwave (2.5*12000) -parameter (NFFT1=400, NH1=NFFT1/2) !Length of FFTs for symbol spectra -parameter (NSTEP=NSPS/4) !Rough time-sync step size -parameter (NHSYM=NMAX/NSTEP-3) !Number of symbol spectra (1/4-sym steps) -parameter (NDOWN=16) !Downsample factor +! LDPC (128,90) code +parameter (KK=90) !Information bits (77 + CRC13) +parameter (ND=128) !Data symbols +parameter (NS=16) !Sync symbols (2x8) +parameter (NN=NS+ND) !Total channel symbols (144) +parameter (NSPS=160) !Samples per symbol at 12000 S/s +parameter (NZ=NSPS*NN) !Samples in full 1.92 s waveform (23040) +parameter (NMAX=30000) !Samples in iwave (2.5*12000) +parameter (NFFT1=400, NH1=NFFT1/2) !Length of FFTs for symbol spectra +parameter (NSTEP=NSPS/4) !Rough time-sync step size +parameter (NHSYM=NMAX/NSTEP-3) !Number of symbol spectra (1/4-sym steps) +parameter (NDOWN=16) !Downsample factor diff --git a/lib/ft2/ft2audio.c b/lib/ft2/ft2audio.c index fb8968e4..b5f19fa4 100755 --- a/lib/ft2/ft2audio.c +++ b/lib/ft2/ft2audio.c @@ -1,347 +1,347 @@ -#include -#include "portaudio.h" -#include -#include - -int iaa; -int icc; -double total_time=0.0; - -// Definition of structure pointing to the audio data -typedef struct -{ - int *iwrite; - int *itx; - int *TxOK; - int *Transmitting; - int *nwave; - int *nright; - int nring; - int nfs; - short *y1; - short *y2; - short *iwave; -} paTestData; - -// Input callback routine: -static int -SoundIn( void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData ) -{ - paTestData *data = (paTestData*)userData; - short *in = (short*)inputBuffer; - unsigned int i; - static int ia=0; - - if(*data->Transmitting) return 0; - - if(statusFlags!=0) printf("Status flags %d\n",(int)statusFlags); - - if((statusFlags&1) == 0) { - //increment buffer pointers only if data available - ia=*data->iwrite; - if(*data->nright==0) { //Use left channel for input - for(i=0; iy1[ia] = (*in++); - data->y2[ia] = (*in++); - ia++; - } - } else { //Use right channel - for(i=0; iy2[ia] = (*in++); - data->y1[ia] = (*in++); - ia++; - } - } - } - - if(ia >= data->nring) ia=0; //Wrap buffer pointer if necessary - *data->iwrite = ia; //Save buffer pointer - iaa=ia; - total_time += (double)framesPerBuffer/12000.0; - // printf("iwrite: %d\n",*data->iwrite); - return 0; -} - -// Output callback routine: -static int -SoundOut( void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData ) -{ - paTestData *data = (paTestData*)userData; - short *wptr = (short*)outputBuffer; - unsigned int i,n; - static short int n2; - static int ic=0; - static int TxOKz=0; - static clock_t tstart=-1; - static clock_t tend=-1; - static int nsent=0; - - // printf("txOK: %d %d\n",TxOKz,*data->TxOK); - - if(*data->TxOK && (!TxOKz)) ic=0; //Reset buffer pointer to start Tx - *data->Transmitting=*data->TxOK; //Set the "transmitting" flag - - if(*data->TxOK) { - if(!TxOKz) { - // Start of a transmission - tstart=clock(); - nsent=0; - // printf("Start Tx\n"); - } - TxOKz=*data->TxOK; - for(i=0 ; i < framesPerBuffer; i++ ) { - n2=data->iwave[ic]; - *wptr++ = n2; //left - *wptr++ = n2; //right - ic++; - - if(ic > *data->nwave) { - *data->TxOK = 0; - *data->Transmitting = 0; - *data->iwrite = 0; //Reset Rx buffer pointer to 0 - ic=0; - tend=clock(); - double TxT=((double)(tend-tstart))/CLOCKS_PER_SEC; - // printf("End Tx, TxT = %f nSent = %d\n",TxT,nsent); - break; - } - } - nsent += framesPerBuffer; - } else { - memset((void*)outputBuffer, 0, 2*sizeof(short)*framesPerBuffer); - } - *data->itx = icc; //Save buffer pointer - icc=ic; - return 0; -} - -/*******************************************************************/ -int ft2audio_(int *ndevin, int *ndevout, int *npabuf, int *nright, - short y1[], short y2[], int *nring, int *iwrite, - int *itx, short iwave[], int *nwave, int *nfsample, - int *TxOK, int *Transmitting, int *ngo) - -{ - paTestData data; - PaStream *instream, *outstream; - PaStreamParameters inputParameters, outputParameters; - // PaStreamInfo *streamInfo; - - int nfpb = *npabuf; - int nSampleRate = *nfsample; - int ndevice_in = *ndevin; - int ndevice_out = *ndevout; - double dSampleRate = (double) *nfsample; - PaError err_init, err_open_in, err_open_out, err_start_in, err_start_out; - PaError err = 0; - - data.iwrite = iwrite; - data.itx = itx; - data.TxOK = TxOK; - data.Transmitting = Transmitting; - data.y1 = y1; - data.y2 = y2; - data.nring = *nring; - data.nright = nright; - data.nwave = nwave; - data.iwave = iwave; - data.nfs = nSampleRate; - - err_init = Pa_Initialize(); // Initialize PortAudio - - if(err_init) { - printf("Error initializing PortAudio.\n"); - printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_init), - err_init); - Pa_Terminate(); // I don't think we need this but... - return(-1); - } - - // printf("Opening device %d for input, %d for output...\n", - // ndevice_in,ndevice_out); - - inputParameters.device = ndevice_in; - inputParameters.channelCount = 2; - inputParameters.sampleFormat = paInt16; - inputParameters.suggestedLatency = 0.2; - inputParameters.hostApiSpecificStreamInfo = NULL; - -// Test if this configuration actually works, so we do not run into an -// ugly assertion - err_open_in = Pa_IsFormatSupported(&inputParameters, NULL, dSampleRate); - - if (err_open_in == 0) { - err_open_in = Pa_OpenStream( - &instream, //address of stream - &inputParameters, - NULL, - dSampleRate, //Sample rate - nfpb, //Frames per buffer - paNoFlag, - (PaStreamCallback *)SoundIn, //Callback routine - (void *)&data); //address of data structure - - if(err_open_in) { // We should have no error here usually - printf("Error opening input audio stream:\n"); - printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_open_in), - err_open_in); - err = 1; - } else { - // printf("Successfully opened audio input.\n"); - } - } else { - printf("Error opening input audio stream.\n"); - printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_open_in), - err_open_in); - err = 1; - } - - outputParameters.device = ndevice_out; - outputParameters.channelCount = 2; - outputParameters.sampleFormat = paInt16; - outputParameters.suggestedLatency = 0.2; - outputParameters.hostApiSpecificStreamInfo = NULL; - -// Test if this configuration actually works, so we do not run into an -// ugly assertion. - err_open_out = Pa_IsFormatSupported(NULL, &outputParameters, dSampleRate); - - if (err_open_out == 0) { - err_open_out = Pa_OpenStream( - &outstream, //address of stream - NULL, - &outputParameters, - dSampleRate, //Sample rate - nfpb, //Frames per buffer - paNoFlag, - (PaStreamCallback *)SoundOut, //Callback routine - (void *)&data); //address of data structure - - if(err_open_out) { // We should have no error here usually - printf("Error opening output audio stream!\n"); - printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_open_out), - err_open_out); - err += 2; - } else { - // printf("Successfully opened audio output.\n"); - } - } else { - printf("Error opening output audio stream.\n"); - printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_open_out), - err_open_out); - err += 2; - } - - // if there was no error in opening both streams start them - if (err == 0) { - err_start_in = Pa_StartStream(instream); //Start input stream - if(err_start_in) { - printf("Error starting input audio stream!\n"); - printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_start_in), - err_start_in); - err += 4; - } - - err_start_out = Pa_StartStream(outstream); //Start output stream - if(err_start_out) { - printf("Error starting output audio stream!\n"); - printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_start_out), - err_start_out); - err += 8; - } - } - - if (err == 0) printf("Audio streams running normally.\n******************************************************************\n"); - - while( Pa_IsStreamActive(instream) && (*ngo != 0) && (err == 0) ) { - int ic1=0; - int ic2=0; - if(_kbhit()) ic1 = _getch(); - if(_kbhit()) ic2 = _getch(); - // if(ic1!=0 || ic2!=0) printf("%d %d %d\n",iaa,ic1,ic2); - update_(&total_time,&ic1,&ic2); - Pa_Sleep(100); - } - - Pa_AbortStream(instream); // Abort stream - Pa_CloseStream(instream); // Close stream, we're done. - Pa_AbortStream(outstream); // Abort stream - Pa_CloseStream(outstream); // Close stream, we're done. - - Pa_Terminate(); - - return(err); -} - - -int padevsub_(int *idevin, int *idevout) -{ - int numdev,ndefin,ndefout; - int nchin[101], nchout[101]; - int i, devIdx; - int numDevices; - const PaDeviceInfo *pdi; - PaError err; - - Pa_Initialize(); - numDevices = Pa_GetDeviceCount(); - numdev = numDevices; - - if( numDevices < 0 ) { - err = numDevices; - Pa_Terminate(); - return err; - } - - if ((devIdx = Pa_GetDefaultInputDevice()) > 0) { - ndefin = devIdx; - } else { - ndefin = 0; - } - - if ((devIdx = Pa_GetDefaultOutputDevice()) > 0) { - ndefout = devIdx; - } else { - ndefout = 0; - } - - printf("\nAudio Input Output Device Name\n"); - printf("Device Channels Channels\n"); - printf("------------------------------------------------------------------\n"); - - for( i=0; i < numDevices; i++ ) { - pdi = Pa_GetDeviceInfo(i); -// if(i == Pa_GetDefaultInputDevice()) ndefin = i; -// if(i == Pa_GetDefaultOutputDevice()) ndefout = i; - nchin[i]=pdi->maxInputChannels; - nchout[i]=pdi->maxOutputChannels; - printf(" %2d %2d %2d %s\n",i,nchin[i],nchout[i], - pdi->name); - } - - printf("\nUser requested devices: Input = %2d Output = %2d\n", - *idevin,*idevout); - printf("Default devices: Input = %2d Output = %2d\n", - ndefin,ndefout); - if((*idevin<0) || (*idevin>=numdev)) *idevin=ndefin; - if((*idevout<0) || (*idevout>=numdev)) *idevout=ndefout; - if((*idevin==0) && (*idevout==0)) { - *idevin=ndefin; - *idevout=ndefout; - } - printf("Will open devices: Input = %2d Output = %2d\n", - *idevin,*idevout); - - Pa_Terminate(); - - return 0; -} - +#include +#include "portaudio.h" +#include +#include + +int iaa; +int icc; +double total_time=0.0; + +// Definition of structure pointing to the audio data +typedef struct +{ + int *iwrite; + int *itx; + int *TxOK; + int *Transmitting; + int *nwave; + int *nright; + int nring; + int nfs; + short *y1; + short *y2; + short *iwave; +} paTestData; + +// Input callback routine: +static int +SoundIn( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData ) +{ + paTestData *data = (paTestData*)userData; + short *in = (short*)inputBuffer; + unsigned int i; + static int ia=0; + + if(*data->Transmitting) return 0; + + if(statusFlags!=0) printf("Status flags %d\n",(int)statusFlags); + + if((statusFlags&1) == 0) { + //increment buffer pointers only if data available + ia=*data->iwrite; + if(*data->nright==0) { //Use left channel for input + for(i=0; iy1[ia] = (*in++); + data->y2[ia] = (*in++); + ia++; + } + } else { //Use right channel + for(i=0; iy2[ia] = (*in++); + data->y1[ia] = (*in++); + ia++; + } + } + } + + if(ia >= data->nring) ia=0; //Wrap buffer pointer if necessary + *data->iwrite = ia; //Save buffer pointer + iaa=ia; + total_time += (double)framesPerBuffer/12000.0; + // printf("iwrite: %d\n",*data->iwrite); + return 0; +} + +// Output callback routine: +static int +SoundOut( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData ) +{ + paTestData *data = (paTestData*)userData; + short *wptr = (short*)outputBuffer; + unsigned int i,n; + static short int n2; + static int ic=0; + static int TxOKz=0; + static clock_t tstart=-1; + static clock_t tend=-1; + static int nsent=0; + + // printf("txOK: %d %d\n",TxOKz,*data->TxOK); + + if(*data->TxOK && (!TxOKz)) ic=0; //Reset buffer pointer to start Tx + *data->Transmitting=*data->TxOK; //Set the "transmitting" flag + + if(*data->TxOK) { + if(!TxOKz) { + // Start of a transmission + tstart=clock(); + nsent=0; + // printf("Start Tx\n"); + } + TxOKz=*data->TxOK; + for(i=0 ; i < framesPerBuffer; i++ ) { + n2=data->iwave[ic]; + *wptr++ = n2; //left + *wptr++ = n2; //right + ic++; + + if(ic > *data->nwave) { + *data->TxOK = 0; + *data->Transmitting = 0; + *data->iwrite = 0; //Reset Rx buffer pointer to 0 + ic=0; + tend=clock(); + double TxT=((double)(tend-tstart))/CLOCKS_PER_SEC; + // printf("End Tx, TxT = %f nSent = %d\n",TxT,nsent); + break; + } + } + nsent += framesPerBuffer; + } else { + memset((void*)outputBuffer, 0, 2*sizeof(short)*framesPerBuffer); + } + *data->itx = icc; //Save buffer pointer + icc=ic; + return 0; +} + +/*******************************************************************/ +int ft2audio_(int *ndevin, int *ndevout, int *npabuf, int *nright, + short y1[], short y2[], int *nring, int *iwrite, + int *itx, short iwave[], int *nwave, int *nfsample, + int *TxOK, int *Transmitting, int *ngo) + +{ + paTestData data; + PaStream *instream, *outstream; + PaStreamParameters inputParameters, outputParameters; + // PaStreamInfo *streamInfo; + + int nfpb = *npabuf; + int nSampleRate = *nfsample; + int ndevice_in = *ndevin; + int ndevice_out = *ndevout; + double dSampleRate = (double) *nfsample; + PaError err_init, err_open_in, err_open_out, err_start_in, err_start_out; + PaError err = 0; + + data.iwrite = iwrite; + data.itx = itx; + data.TxOK = TxOK; + data.Transmitting = Transmitting; + data.y1 = y1; + data.y2 = y2; + data.nring = *nring; + data.nright = nright; + data.nwave = nwave; + data.iwave = iwave; + data.nfs = nSampleRate; + + err_init = Pa_Initialize(); // Initialize PortAudio + + if(err_init) { + printf("Error initializing PortAudio.\n"); + printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_init), + err_init); + Pa_Terminate(); // I don't think we need this but... + return(-1); + } + + // printf("Opening device %d for input, %d for output...\n", + // ndevice_in,ndevice_out); + + inputParameters.device = ndevice_in; + inputParameters.channelCount = 2; + inputParameters.sampleFormat = paInt16; + inputParameters.suggestedLatency = 0.2; + inputParameters.hostApiSpecificStreamInfo = NULL; + +// Test if this configuration actually works, so we do not run into an +// ugly assertion + err_open_in = Pa_IsFormatSupported(&inputParameters, NULL, dSampleRate); + + if (err_open_in == 0) { + err_open_in = Pa_OpenStream( + &instream, //address of stream + &inputParameters, + NULL, + dSampleRate, //Sample rate + nfpb, //Frames per buffer + paNoFlag, + (PaStreamCallback *)SoundIn, //Callback routine + (void *)&data); //address of data structure + + if(err_open_in) { // We should have no error here usually + printf("Error opening input audio stream:\n"); + printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_open_in), + err_open_in); + err = 1; + } else { + // printf("Successfully opened audio input.\n"); + } + } else { + printf("Error opening input audio stream.\n"); + printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_open_in), + err_open_in); + err = 1; + } + + outputParameters.device = ndevice_out; + outputParameters.channelCount = 2; + outputParameters.sampleFormat = paInt16; + outputParameters.suggestedLatency = 0.2; + outputParameters.hostApiSpecificStreamInfo = NULL; + +// Test if this configuration actually works, so we do not run into an +// ugly assertion. + err_open_out = Pa_IsFormatSupported(NULL, &outputParameters, dSampleRate); + + if (err_open_out == 0) { + err_open_out = Pa_OpenStream( + &outstream, //address of stream + NULL, + &outputParameters, + dSampleRate, //Sample rate + nfpb, //Frames per buffer + paNoFlag, + (PaStreamCallback *)SoundOut, //Callback routine + (void *)&data); //address of data structure + + if(err_open_out) { // We should have no error here usually + printf("Error opening output audio stream!\n"); + printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_open_out), + err_open_out); + err += 2; + } else { + // printf("Successfully opened audio output.\n"); + } + } else { + printf("Error opening output audio stream.\n"); + printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_open_out), + err_open_out); + err += 2; + } + + // if there was no error in opening both streams start them + if (err == 0) { + err_start_in = Pa_StartStream(instream); //Start input stream + if(err_start_in) { + printf("Error starting input audio stream!\n"); + printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_start_in), + err_start_in); + err += 4; + } + + err_start_out = Pa_StartStream(outstream); //Start output stream + if(err_start_out) { + printf("Error starting output audio stream!\n"); + printf("\tErrortext: %s\n\tNumber: %d\n",Pa_GetErrorText(err_start_out), + err_start_out); + err += 8; + } + } + + if (err == 0) printf("Audio streams running normally.\n******************************************************************\n"); + + while( Pa_IsStreamActive(instream) && (*ngo != 0) && (err == 0) ) { + int ic1=0; + int ic2=0; + if(_kbhit()) ic1 = _getch(); + if(_kbhit()) ic2 = _getch(); + // if(ic1!=0 || ic2!=0) printf("%d %d %d\n",iaa,ic1,ic2); + update_(&total_time,&ic1,&ic2); + Pa_Sleep(100); + } + + Pa_AbortStream(instream); // Abort stream + Pa_CloseStream(instream); // Close stream, we're done. + Pa_AbortStream(outstream); // Abort stream + Pa_CloseStream(outstream); // Close stream, we're done. + + Pa_Terminate(); + + return(err); +} + + +int padevsub_(int *idevin, int *idevout) +{ + int numdev,ndefin,ndefout; + int nchin[101], nchout[101]; + int i, devIdx; + int numDevices; + const PaDeviceInfo *pdi; + PaError err; + + Pa_Initialize(); + numDevices = Pa_GetDeviceCount(); + numdev = numDevices; + + if( numDevices < 0 ) { + err = numDevices; + Pa_Terminate(); + return err; + } + + if ((devIdx = Pa_GetDefaultInputDevice()) > 0) { + ndefin = devIdx; + } else { + ndefin = 0; + } + + if ((devIdx = Pa_GetDefaultOutputDevice()) > 0) { + ndefout = devIdx; + } else { + ndefout = 0; + } + + printf("\nAudio Input Output Device Name\n"); + printf("Device Channels Channels\n"); + printf("------------------------------------------------------------------\n"); + + for( i=0; i < numDevices; i++ ) { + pdi = Pa_GetDeviceInfo(i); +// if(i == Pa_GetDefaultInputDevice()) ndefin = i; +// if(i == Pa_GetDefaultOutputDevice()) ndefout = i; + nchin[i]=pdi->maxInputChannels; + nchout[i]=pdi->maxOutputChannels; + printf(" %2d %2d %2d %s\n",i,nchin[i],nchout[i], + pdi->name); + } + + printf("\nUser requested devices: Input = %2d Output = %2d\n", + *idevin,*idevout); + printf("Default devices: Input = %2d Output = %2d\n", + ndefin,ndefout); + if((*idevin<0) || (*idevin>=numdev)) *idevin=ndefin; + if((*idevout<0) || (*idevout>=numdev)) *idevout=ndefout; + if((*idevin==0) && (*idevout==0)) { + *idevin=ndefin; + *idevout=ndefout; + } + printf("Will open devices: Input = %2d Output = %2d\n", + *idevin,*idevout); + + Pa_Terminate(); + + return 0; +} + diff --git a/lib/ft2/g4.cmd b/lib/ft2/g4.cmd index ff85f1f4..0894dbeb 100755 --- a/lib/ft2/g4.cmd +++ b/lib/ft2/g4.cmd @@ -1,7 +1,7 @@ -gcc -c ft2audio.c -gcc -c ptt.c -gfortran -c ../77bit/packjt77.f90 -gfortran -c ../wavhdr.f90 -gfortran -c ../crc.f90 -gfortran -o ft2 -fbounds-check -fno-second-underscore -ffpe-trap=invalid,zero -Wall -Wno-conversion -Wno-character-truncation ft2.f90 ft2_iwave.f90 ft2_decode.f90 getcandidates2.f90 ft2audio.o ptt.o /JTSDK/wsjtx-output/qt55/2.1.0/Release/build/libwsjt_fort.a /JTSDK/wsjtx-output/qt55/2.1.0/Release/build/libwsjt_cxx.a libportaudio.a ../libfftw3f_win.a -lwinmm -rm *.o *.mod +gcc -c ft2audio.c +gcc -c ptt.c +gfortran -c ../77bit/packjt77.f90 +gfortran -c ../wavhdr.f90 +gfortran -c ../crc.f90 +gfortran -o ft2 -fbounds-check -fno-second-underscore -ffpe-trap=invalid,zero -Wall -Wno-conversion -Wno-character-truncation ft2.f90 ft2_iwave.f90 ft2_decode.f90 getcandidates2.f90 ft2audio.o ptt.o /JTSDK/wsjtx-output/qt55/2.1.0/Release/build/libwsjt_fort.a /JTSDK/wsjtx-output/qt55/2.1.0/Release/build/libwsjt_cxx.a libportaudio.a ../libfftw3f_win.a -lwinmm +rm *.o *.mod diff --git a/lib/ft2/gcom1.f90 b/lib/ft2/gcom1.f90 index 1c83e992..9402f9d9 100755 --- a/lib/ft2/gcom1.f90 +++ b/lib/ft2/gcom1.f90 @@ -1,34 +1,34 @@ -! Variable Purpose -!--------------------------------------------------------------------------- -integer NRING !Length of Rx ring buffer -integer NTZ !Length of Tx waveform in samples -parameter(NRING=230400) !Ring buffer at 12000 samples/sec -parameter(NTZ=23040) !144*160 -parameter(NMAX=30000) !2.5*12000 -real snrdb -integer ndevin !Device# for audio input -integer ndevout !Device# for audio output -integer iwrite !Pointer to Rx ring buffer -integer itx !Pointer to Tx buffer -integer ngo !Set to 0 to terminate audio streams -integer nTransmitting !Actually transmitting? -integer nTxOK !OK to transmit? -integer nport !COM port for PTT -logical tx_once !Transmit one message, then exit -logical ltx !True if msg i has been transmitted -logical lrx !True if msg i has been received -logical autoseq -logical QSO_in_progress -integer*2 y1 !Ring buffer for audio channel 0 -integer*2 y2 !Ring buffer for audio channel 1 -integer*2 iwave !Data for Tx audio -character*6 mycall -character*6 hiscall -character*6 hiscall_next -character*4 mygrid -character*3 exch -character*37 txmsg - -common/gcom1/snrdb,ndevin,ndevout,iwrite,itx,ngo,nTransmitting,nTxOK,nport, & - ntxed,tx_once,y1(NRING),y2(NRING),iwave(NTZ+3*1152),ltx(5),lrx(5), & - autoseq,QSO_in_progress,mycall,hiscall,hiscall_next,mygrid,exch,txmsg +! Variable Purpose +!--------------------------------------------------------------------------- +integer NRING !Length of Rx ring buffer +integer NTZ !Length of Tx waveform in samples +parameter(NRING=230400) !Ring buffer at 12000 samples/sec +parameter(NTZ=23040) !144*160 +parameter(NMAX=30000) !2.5*12000 +real snrdb +integer ndevin !Device# for audio input +integer ndevout !Device# for audio output +integer iwrite !Pointer to Rx ring buffer +integer itx !Pointer to Tx buffer +integer ngo !Set to 0 to terminate audio streams +integer nTransmitting !Actually transmitting? +integer nTxOK !OK to transmit? +integer nport !COM port for PTT +logical tx_once !Transmit one message, then exit +logical ltx !True if msg i has been transmitted +logical lrx !True if msg i has been received +logical autoseq +logical QSO_in_progress +integer*2 y1 !Ring buffer for audio channel 0 +integer*2 y2 !Ring buffer for audio channel 1 +integer*2 iwave !Data for Tx audio +character*6 mycall +character*6 hiscall +character*6 hiscall_next +character*4 mygrid +character*3 exch +character*37 txmsg + +common/gcom1/snrdb,ndevin,ndevout,iwrite,itx,ngo,nTransmitting,nTxOK,nport, & + ntxed,tx_once,y1(NRING),y2(NRING),iwave(NTZ+3*1152),ltx(5),lrx(5), & + autoseq,QSO_in_progress,mycall,hiscall,hiscall_next,mygrid,exch,txmsg diff --git a/lib/ft2/genft2.f90 b/lib/ft2/genft2.f90 index 6d3c2d8b..2eb36bcc 100755 --- a/lib/ft2/genft2.f90 +++ b/lib/ft2/genft2.f90 @@ -1,86 +1,86 @@ -subroutine genft2(msg0,ichk,msgsent,i4tone,itype) -! s8 + 48bits + s8 + 80 bits = 144 bits (72ms message duration) -! -! Encode an MSK144 message -! Input: -! - msg0 requested message to be transmitted -! - ichk if ichk=1, return only msgsent -! if ichk.ge.10000, set imsg=ichk-10000 for short msg -! - msgsent message as it will be decoded -! - i4tone array of audio tone values, 0 or 1 -! - itype message type -! 1 = 77 bit message -! 7 = 16 bit message " Rpt" - - use iso_c_binding, only: c_loc,c_size_t - use packjt77 - character*37 msg0 - character*37 message !Message to be generated - character*37 msgsent !Message as it will be received - character*77 c77 - integer*4 i4tone(144) - integer*1 codeword(128) - integer*1 msgbits(77) - integer*1 bitseq(144) !Tone #s, data and sync (values 0-1) - integer*1 s16(16) - real*8 xi(864),xq(864),pi,twopi - data s16/0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0/ - equivalence (ihash,i1hash) - logical unpk77_success - - nsym=128 - pi=4.0*atan(1.0) - twopi=8.*atan(1.0) - - message(1:37)=' ' - itype=1 - if(msg0(1:1).eq.'@') then !Generate a fixed tone - read(msg0(2:5),*,end=1,err=1) nfreq !at specified frequency - go to 2 -1 nfreq=1000 -2 i4tone(1)=nfreq - else - message=msg0 - - do i=1, 37 - if(ichar(message(i:i)).eq.0) then - message(i:37)=' ' - exit - endif - enddo - do i=1,37 !Strip leading blanks - if(message(1:1).ne.' ') exit - message=message(i+1:) - enddo - - if(message(1:1).eq.'<') then - i2=index(message,'>') - i1=0 - if(i2.gt.0) i1=index(message(1:i2),' ') - if(i1.gt.0) then - call genmsk40(message,msgsent,ichk,i4tone,itype) - if(itype.lt.0) go to 999 - i4tone(41)=-40 - go to 999 - endif - endif - - i3=-1 - n3=-1 - call pack77(message,i3,n3,c77) - call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent - - if(ichk.eq.1) go to 999 - read(c77,"(77i1)") msgbits - call encode_128_90(msgbits,codeword) - -!Create 144-bit channel vector: - bitseq=0 - bitseq(1:16)=s16 - bitseq(17:144)=codeword - - i4tone=bitseq - endif - -999 return -end subroutine genft2 +subroutine genft2(msg0,ichk,msgsent,i4tone,itype) +! s8 + 48bits + s8 + 80 bits = 144 bits (72ms message duration) +! +! Encode an MSK144 message +! Input: +! - msg0 requested message to be transmitted +! - ichk if ichk=1, return only msgsent +! if ichk.ge.10000, set imsg=ichk-10000 for short msg +! - msgsent message as it will be decoded +! - i4tone array of audio tone values, 0 or 1 +! - itype message type +! 1 = 77 bit message +! 7 = 16 bit message " Rpt" + + use iso_c_binding, only: c_loc,c_size_t + use packjt77 + character*37 msg0 + character*37 message !Message to be generated + character*37 msgsent !Message as it will be received + character*77 c77 + integer*4 i4tone(144) + integer*1 codeword(128) + integer*1 msgbits(77) + integer*1 bitseq(144) !Tone #s, data and sync (values 0-1) + integer*1 s16(16) + real*8 xi(864),xq(864),pi,twopi + data s16/0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0/ + equivalence (ihash,i1hash) + logical unpk77_success + + nsym=128 + pi=4.0*atan(1.0) + twopi=8.*atan(1.0) + + message(1:37)=' ' + itype=1 + if(msg0(1:1).eq.'@') then !Generate a fixed tone + read(msg0(2:5),*,end=1,err=1) nfreq !at specified frequency + go to 2 +1 nfreq=1000 +2 i4tone(1)=nfreq + else + message=msg0 + + do i=1, 37 + if(ichar(message(i:i)).eq.0) then + message(i:37)=' ' + exit + endif + enddo + do i=1,37 !Strip leading blanks + if(message(1:1).ne.' ') exit + message=message(i+1:) + enddo + + if(message(1:1).eq.'<') then + i2=index(message,'>') + i1=0 + if(i2.gt.0) i1=index(message(1:i2),' ') + if(i1.gt.0) then + call genmsk40(message,msgsent,ichk,i4tone,itype) + if(itype.lt.0) go to 999 + i4tone(41)=-40 + go to 999 + endif + endif + + i3=-1 + n3=-1 + call pack77(message,i3,n3,c77) + call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent + + if(ichk.eq.1) go to 999 + read(c77,"(77i1)") msgbits + call encode_128_90(msgbits,codeword) + +!Create 144-bit channel vector: + bitseq=0 + bitseq(1:16)=s16 + bitseq(17:144)=codeword + + i4tone=bitseq + endif + +999 return +end subroutine genft2 diff --git a/lib/ft2/getcandidates2a.f90 b/lib/ft2/getcandidates2a.f90 index 33fdbc14..8e7209c9 100755 --- a/lib/ft2/getcandidates2a.f90 +++ b/lib/ft2/getcandidates2a.f90 @@ -1,64 +1,64 @@ -subroutine getcandidates2a(id,fa,fb,maxcand,savg,candidate,ncand) - -! For now, hardwired to find the largest peak in the average spectrum - - include 'ft2_params.f90' - real s(NH1,NHSYM) - real savg(NH1),savsm(NH1) - real x(NFFT1) - complex cx(0:NH1) - real candidate(3,100) - integer*2 id(NMAX) - integer*1 s8(8) - integer indx(NH1) - data s8/0,1,1,1,0,0,1,0/ - equivalence (x,cx) - -! Compute symbol spectra, stepping by NSTEP steps. - savg=0. - tstep=NSTEP/12000.0 - df=12000.0/NFFT1 !3.125 Hz - fac=1.0/300.0 - do j=1,NHSYM - ia=(j-1)*NSTEP + 1 - ib=ia+NSPS-1 - x(1:NSPS)=fac*id(ia:ib) - x(NSPS+1:)=0. - call four2a(x,NFFT1,1,-1,0) !r2c FFT - do i=1,NH1 - s(i,j)=real(cx(i))**2 + aimag(cx(i))**2 - enddo - savg=savg + s(1:NH1,j) !Average spectrum - enddo - savsm=0. - do i=2,NH1-1 - savsm(i)=sum(savg(i-1:i+1))/3. - enddo - savsm(1)=savg(1) - savsm(NH1)=savg(NH1) - - nfa=nint(fa/df) - nfb=nint(fb/df) - np=nfb-nfa+1 - indx=0 - call indexx(savsm(nfa:nfb),np,indx) - xn=savsm(nfa+indx(nint(0.3*np))) - if(xn.ne.0) savsm=savsm/xn - imax=-1 - xmax=-99. - do i=2,NH1-1 - if(savsm(i).gt.savsm(i-1).and. & - savsm(i).gt.savsm(i+1).and. & - savsm(i).gt.xmax) then - xmax=savsm(i) - imax=i - endif - enddo - f0=imax*df - if(xmax.gt.1.2) then - if(ncand.lt.maxcand) ncand=ncand+1 - candidate(1,ncand)=f0 - endif - - return -end subroutine getcandidates2a +subroutine getcandidates2a(id,fa,fb,maxcand,savg,candidate,ncand) + +! For now, hardwired to find the largest peak in the average spectrum + + include 'ft2_params.f90' + real s(NH1,NHSYM) + real savg(NH1),savsm(NH1) + real x(NFFT1) + complex cx(0:NH1) + real candidate(3,100) + integer*2 id(NMAX) + integer*1 s8(8) + integer indx(NH1) + data s8/0,1,1,1,0,0,1,0/ + equivalence (x,cx) + +! Compute symbol spectra, stepping by NSTEP steps. + savg=0. + tstep=NSTEP/12000.0 + df=12000.0/NFFT1 !3.125 Hz + fac=1.0/300.0 + do j=1,NHSYM + ia=(j-1)*NSTEP + 1 + ib=ia+NSPS-1 + x(1:NSPS)=fac*id(ia:ib) + x(NSPS+1:)=0. + call four2a(x,NFFT1,1,-1,0) !r2c FFT + do i=1,NH1 + s(i,j)=real(cx(i))**2 + aimag(cx(i))**2 + enddo + savg=savg + s(1:NH1,j) !Average spectrum + enddo + savsm=0. + do i=2,NH1-1 + savsm(i)=sum(savg(i-1:i+1))/3. + enddo + savsm(1)=savg(1) + savsm(NH1)=savg(NH1) + + nfa=nint(fa/df) + nfb=nint(fb/df) + np=nfb-nfa+1 + indx=0 + call indexx(savsm(nfa:nfb),np,indx) + xn=savsm(nfa+indx(nint(0.3*np))) + if(xn.ne.0) savsm=savsm/xn + imax=-1 + xmax=-99. + do i=2,NH1-1 + if(savsm(i).gt.savsm(i-1).and. & + savsm(i).gt.savsm(i+1).and. & + savsm(i).gt.xmax) then + xmax=savsm(i) + imax=i + endif + enddo + f0=imax*df + if(xmax.gt.1.2) then + if(ncand.lt.maxcand) ncand=ncand+1 + candidate(1,ncand)=f0 + endif + + return +end subroutine getcandidates2a diff --git a/lib/ft2/gfsk_pulse.f90 b/lib/ft2/gfsk_pulse.f90 index 461cf074..99ab78e3 100755 --- a/lib/ft2/gfsk_pulse.f90 +++ b/lib/ft2/gfsk_pulse.f90 @@ -1,6 +1,6 @@ -real function gfsk_pulse(b,t) - pi=4.*atan(1.0) - c=pi*sqrt(2.0/log(2.0)) - gfsk_pulse=0.5*(erf(c*b*(t+0.5))-erf(c*b*(t-0.5))) - return -end function gfsk_pulse +real function gfsk_pulse(b,t) + pi=4.*atan(1.0) + c=pi*sqrt(2.0/log(2.0)) + gfsk_pulse=0.5*(erf(c*b*(t+0.5))-erf(c*b*(t-0.5))) + return +end function gfsk_pulse diff --git a/lib/ft2/portaudio.h b/lib/ft2/portaudio.h index cc30a28a..250fba02 100755 --- a/lib/ft2/portaudio.h +++ b/lib/ft2/portaudio.h @@ -1,1123 +1,1123 @@ - -#ifndef PORTAUDIO_H -#define PORTAUDIO_H -/* - * $Id: portaudio.h,v 1.1 2005/11/29 21:27:24 joe Exp $ - * PortAudio Portable Real-Time Audio Library - * PortAudio API Header File - * Latest version available at: http://www.portaudio.com/ - * - * Copyright (c) 1999-2002 Ross Bencina and Phil Burk - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files - * (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Any person wishing to distribute modifications to the Software is - * requested to send the modifications to the original developer so that - * they can be incorporated into the canonical version. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/** @file - @brief The PortAudio API. -*/ - - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - - -/** Retrieve the release number of the currently running PortAudio build, - eg 1900. -*/ -int Pa_GetVersion( void ); - - -/** Retrieve a textual description of the current PortAudio build, - eg "PortAudio V19-devel 13 October 2002". -*/ -const char* Pa_GetVersionText( void ); - - -/** Error codes returned by PortAudio functions. - Note that with the exception of paNoError, all PaErrorCodes are negative. -*/ - -typedef int PaError; -typedef enum PaErrorCode -{ - paNoError = 0, - - paNotInitialized = -10000, - paUnanticipatedHostError, - paInvalidChannelCount, - paInvalidSampleRate, - paInvalidDevice, - paInvalidFlag, - paSampleFormatNotSupported, - paBadIODeviceCombination, - paInsufficientMemory, - paBufferTooBig, - paBufferTooSmall, - paNullCallback, - paBadStreamPtr, - paTimedOut, - paInternalError, - paDeviceUnavailable, - paIncompatibleHostApiSpecificStreamInfo, - paStreamIsStopped, - paStreamIsNotStopped, - paInputOverflowed, - paOutputUnderflowed, - paHostApiNotFound, - paInvalidHostApi, - paCanNotReadFromACallbackStream, /**< @todo review error code name */ - paCanNotWriteToACallbackStream, /**< @todo review error code name */ - paCanNotReadFromAnOutputOnlyStream, /**< @todo review error code name */ - paCanNotWriteToAnInputOnlyStream, /**< @todo review error code name */ - paIncompatibleStreamHostApi -} PaErrorCode; - - -/** Translate the supplied PortAudio error code into a human readable - message. -*/ -const char *Pa_GetErrorText( PaError errorCode ); - - -/** Library initialization function - call this before using PortAudio. - This function initialises internal data structures and prepares underlying - host APIs for use. This function MUST be called before using any other - PortAudio API functions. - - If Pa_Initialize() is called multiple times, each successful - call must be matched with a corresponding call to Pa_Terminate(). - Pairs of calls to Pa_Initialize()/Pa_Terminate() may overlap, and are not - required to be fully nested. - - Note that if Pa_Initialize() returns an error code, Pa_Terminate() should - NOT be called. - - @return paNoError if successful, otherwise an error code indicating the cause - of failure. - - @see Pa_Terminate -*/ -PaError Pa_Initialize( void ); - - -/** Library termination function - call this when finished using PortAudio. - This function deallocates all resources allocated by PortAudio since it was - initializied by a call to Pa_Initialize(). In cases where Pa_Initialise() has - been called multiple times, each call must be matched with a corresponding call - to Pa_Terminate(). The final matching call to Pa_Terminate() will automatically - close any PortAudio streams that are still open. - - Pa_Terminate() MUST be called before exiting a program which uses PortAudio. - Failure to do so may result in serious resource leaks, such as audio devices - not being available until the next reboot. - - @return paNoError if successful, otherwise an error code indicating the cause - of failure. - - @see Pa_Initialize -*/ -PaError Pa_Terminate( void ); - - - -/** The type used to refer to audio devices. Values of this type usually - range from 0 to (Pa_DeviceCount-1), and may also take on the PaNoDevice - and paUseHostApiSpecificDeviceSpecification values. - - @see Pa_DeviceCount, paNoDevice, paUseHostApiSpecificDeviceSpecification -*/ -typedef int PaDeviceIndex; - - -/** A special PaDeviceIndex value indicating that no device is available, - or should be used. - - @see PaDeviceIndex -*/ -#define paNoDevice ((PaDeviceIndex)-1) - - -/** A special PaDeviceIndex value indicating that the device(s) to be used - are specified in the host api specific stream info structure. - - @see PaDeviceIndex -*/ -#define paUseHostApiSpecificDeviceSpecification ((PaDeviceIndex)-2) - - -/* Host API enumeration mechanism */ - -/** The type used to enumerate to host APIs at runtime. Values of this type - range from 0 to (Pa_GetHostApiCount()-1). - - @see Pa_GetHostApiCount -*/ -typedef int PaHostApiIndex; - - -/** Retrieve the number of available host APIs. Even if a host API is - available it may have no devices available. - - @return A non-negative value indicating the number of available host APIs - or, a PaErrorCode (which are always negative) if PortAudio is not initialized - or an error is encountered. - - @see PaHostApiIndex -*/ -PaHostApiIndex Pa_GetHostApiCount( void ); - - -/** Retrieve the index of the default host API. The default host API will be - the lowest common denominator host API on the current platform and is - unlikely to provide the best performance. - - @return A non-negative value ranging from 0 to (Pa_GetHostApiCount()-1) - indicating the default host API index or, a PaErrorCode (which are always - negative) if PortAudio is not initialized or an error is encountered. -*/ -PaHostApiIndex Pa_GetDefaultHostApi( void ); - - -/** Unchanging unique identifiers for each supported host API. This type - is used in the PaHostApiInfo structure. The values are guaranteed to be - unique and to never change, thus allowing code to be written that - conditionally uses host API specific extensions. - - New type ids will be allocated when support for a host API reaches - "public alpha" status, prior to that developers should use the - paInDevelopment type id. - - @see PaHostApiInfo -*/ -typedef enum PaHostApiTypeId -{ - paInDevelopment=0, /* use while developing support for a new host API */ - paDirectSound=1, - paMME=2, - paASIO=3, - paSoundManager=4, - paCoreAudio=5, - paOSS=7, - paALSA=8, - paAL=9, - paBeOS=10, - paWDMKS=11, - paJACK=12 -} PaHostApiTypeId; - - -/** A structure containing information about a particular host API. */ - -typedef struct PaHostApiInfo -{ - /** this is struct version 1 */ - int structVersion; - /** The well known unique identifier of this host API @see PaHostApiTypeId */ - PaHostApiTypeId type; - /** A textual description of the host API for display on user interfaces. */ - const char *name; - - /** The number of devices belonging to this host API. This field may be - used in conjunction with Pa_HostApiDeviceIndexToDeviceIndex() to enumerate - all devices for this host API. - @see Pa_HostApiDeviceIndexToDeviceIndex - */ - int deviceCount; - - /** The the default input device for this host API. The value will be a - device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice - if no default input device is available. - */ - PaDeviceIndex defaultInputDevice; - - /** The the default output device for this host API. The value will be a - device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice - if no default output device is available. - */ - PaDeviceIndex defaultOutputDevice; - -} PaHostApiInfo; - - -/** Retrieve a pointer to a structure containing information about a specific - host Api. - - @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1) - - @return A pointer to an immutable PaHostApiInfo structure describing - a specific host API. If the hostApi parameter is out of range or an error - is encountered, the function returns NULL. - - The returned structure is owned by the PortAudio implementation and must not - be manipulated or freed. The pointer is only guaranteed to be valid between - calls to Pa_Initialize() and Pa_Terminate(). -*/ -const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi ); - - -/** Convert a static host API unique identifier, into a runtime - host API index. - - @param type A unique host API identifier belonging to the PaHostApiTypeId - enumeration. - - @return A valid PaHostApiIndex ranging from 0 to (Pa_GetHostApiCount()-1) or, - a PaErrorCode (which are always negative) if PortAudio is not initialized - or an error is encountered. - - The paHostApiNotFound error code indicates that the host API specified by the - type parameter is not available. - - @see PaHostApiTypeId -*/ -PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type ); - - -/** Convert a host-API-specific device index to standard PortAudio device index. - This function may be used in conjunction with the deviceCount field of - PaHostApiInfo to enumerate all devices for the specified host API. - - @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1) - - @param hostApiDeviceIndex A valid per-host device index in the range - 0 to (Pa_GetHostApiInfo(hostApi)->deviceCount-1) - - @return A non-negative PaDeviceIndex ranging from 0 to (Pa_GetDeviceCount()-1) - or, a PaErrorCode (which are always negative) if PortAudio is not initialized - or an error is encountered. - - A paInvalidHostApi error code indicates that the host API index specified by - the hostApi parameter is out of range. - - A paInvalidDevice error code indicates that the hostApiDeviceIndex parameter - is out of range. - - @see PaHostApiInfo -*/ -PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi, - int hostApiDeviceIndex ); - - - -/** Structure used to return information about a host error condition. -*/ -typedef struct PaHostErrorInfo{ - PaHostApiTypeId hostApiType; /**< the host API which returned the error code */ - long errorCode; /**< the error code returned */ - const char *errorText; /**< a textual description of the error if available, otherwise a zero-length string */ -}PaHostErrorInfo; - - -/** Return information about the last host error encountered. The error - information returned by Pa_GetLastHostErrorInfo() will never be modified - asyncronously by errors occurring in other PortAudio owned threads - (such as the thread that manages the stream callback.) - - This function is provided as a last resort, primarily to enhance debugging - by providing clients with access to all available error information. - - @return A pointer to an immutable structure constaining information about - the host error. The values in this structure will only be valid if a - PortAudio function has previously returned the paUnanticipatedHostError - error code. -*/ -const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void ); - - - -/* Device enumeration and capabilities */ - -/** Retrieve the number of available devices. The number of available devices - may be zero. - - @return A non-negative value indicating the number of available devices or, - a PaErrorCode (which are always negative) if PortAudio is not initialized - or an error is encountered. -*/ -PaDeviceIndex Pa_GetDeviceCount( void ); - - -/** Retrieve the index of the default input device. The result can be - used in the inputDevice parameter to Pa_OpenStream(). - - @return The default input device index for the default host API, or paNoDevice - if no default input device is available or an error was encountered. -*/ -PaDeviceIndex Pa_GetDefaultInputDevice( void ); - - -/** Retrieve the index of the default output device. The result can be - used in the outputDevice parameter to Pa_OpenStream(). - - @return The default output device index for the defualt host API, or paNoDevice - if no default output device is available or an error was encountered. - - @note - On the PC, the user can specify a default device by - setting an environment variable. For example, to use device #1. -
- set PA_RECOMMENDED_OUTPUT_DEVICE=1
-
- The user should first determine the available device ids by using - the supplied application "pa_devs". -*/ -PaDeviceIndex Pa_GetDefaultOutputDevice( void ); - - -/** The type used to represent monotonic time in seconds that can be used - for syncronisation. The type is used for the outTime argument to the - PaStreamCallback and as the result of Pa_GetStreamTime(). - - @see PaStreamCallback, Pa_GetStreamTime -*/ -typedef double PaTime; - - -/** A type used to specify one or more sample formats. Each value indicates - a possible format for sound data passed to and from the stream callback, - Pa_ReadStream and Pa_WriteStream. - - The standard formats paFloat32, paInt16, paInt32, paInt24, paInt8 - and aUInt8 are usually implemented by all implementations. - - The floating point representation (paFloat32) uses +1.0 and -1.0 as the - maximum and minimum respectively. - - paUInt8 is an unsigned 8 bit format where 128 is considered "ground" - - The paNonInterleaved flag indicates that a multichannel buffer is passed - as a set of non-interleaved pointers. - - @see Pa_OpenStream, Pa_OpenDefaultStream, PaDeviceInfo - @see paFloat32, paInt16, paInt32, paInt24, paInt8 - @see paUInt8, paCustomFormat, paNonInterleaved -*/ -typedef unsigned long PaSampleFormat; - - -#define paFloat32 ((PaSampleFormat) 0x00000001) /**< @see PaSampleFormat */ -#define paInt32 ((PaSampleFormat) 0x00000002) /**< @see PaSampleFormat */ -#define paInt24 ((PaSampleFormat) 0x00000004) /**< Packed 24 bit format. @see PaSampleFormat */ -#define paInt16 ((PaSampleFormat) 0x00000008) /**< @see PaSampleFormat */ -#define paInt8 ((PaSampleFormat) 0x00000010) /**< @see PaSampleFormat */ -#define paUInt8 ((PaSampleFormat) 0x00000020) /**< @see PaSampleFormat */ -#define paCustomFormat ((PaSampleFormat) 0x00010000)/**< @see PaSampleFormat */ - -#define paNonInterleaved ((PaSampleFormat) 0x80000000) - -/** A structure providing information and capabilities of PortAudio devices. - Devices may support input, output or both input and output. -*/ -typedef struct PaDeviceInfo -{ - int structVersion; /* this is struct version 2 */ - const char *name; - PaHostApiIndex hostApi; /* note this is a host API index, not a type id*/ - - int maxInputChannels; - int maxOutputChannels; - - /* Default latency values for interactive performance. */ - PaTime defaultLowInputLatency; - PaTime defaultLowOutputLatency; - /* Default latency values for robust non-interactive applications (eg. playing sound files). */ - PaTime defaultHighInputLatency; - PaTime defaultHighOutputLatency; - - double defaultSampleRate; -} PaDeviceInfo; - - -/** Retrieve a pointer to a PaDeviceInfo structure containing information - about the specified device. - @return A pointer to an immutable PaDeviceInfo structure. If the device - parameter is out of range the function returns NULL. - - @param device A valid device index in the range 0 to (Pa_GetDeviceCount()-1) - - @note PortAudio manages the memory referenced by the returned pointer, - the client must not manipulate or free the memory. The pointer is only - guaranteed to be valid between calls to Pa_Initialize() and Pa_Terminate(). - - @see PaDeviceInfo, PaDeviceIndex -*/ -const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device ); - - -/** Parameters for one direction (input or output) of a stream. -*/ -typedef struct PaStreamParameters -{ - /** A valid device index in the range 0 to (Pa_GetDeviceCount()-1) - specifying the device to be used or the special constant - paUseHostApiSpecificDeviceSpecification which indicates that the actual - device(s) to use are specified in hostApiSpecificStreamInfo. - This field must not be set to paNoDevice. - */ - PaDeviceIndex device; - - /** The number of channels of sound to be delivered to the - stream callback or accessed by Pa_ReadStream() or Pa_WriteStream(). - It can range from 1 to the value of maxInputChannels in the - PaDeviceInfo record for the device specified by the device parameter. - */ - int channelCount; - - /** The sample format of the buffer provided to the stream callback, - a_ReadStream() or Pa_WriteStream(). It may be any of the formats described - by the PaSampleFormat enumeration. - */ - PaSampleFormat sampleFormat; - - /** The desired latency in seconds. Where practical, implementations should - configure their latency based on these parameters, otherwise they may - choose the closest viable latency instead. Unless the suggested latency - is greater than the absolute upper limit for the device implementations - shouldround the suggestedLatency up to the next practial value - ie to - provide an equal or higher latency than suggestedLatency whereever possibe. - Actual latency values for an open stream may be retrieved using the - inputLatency and outputLatency fields of the PaStreamInfo structure - returned by Pa_GetStreamInfo(). - @see default*Latency in PaDeviceInfo, *Latency in PaStreamInfo - */ - PaTime suggestedLatency; - - /** An optional pointer to a host api specific data structure - containing additional information for device setup and/or stream processing. - hostApiSpecificStreamInfo is never required for correct operation, - if not used it should be set to NULL. - */ - void *hostApiSpecificStreamInfo; - -} PaStreamParameters; - - -/** Return code for Pa_IsFormatSupported indicating success. */ -#define paFormatIsSupported (0) - -/** Determine whether it would be possible to open a stream with the specified - parameters. - - @param inputParameters A structure that describes the input parameters used to - open a stream. The suggestedLatency field is ignored. See PaStreamParameters - for a description of these parameters. inputParameters must be NULL for - output-only streams. - - @param outputParameters A structure that describes the output parameters used - to open a stream. The suggestedLatency field is ignored. See PaStreamParameters - for a description of these parameters. outputParameters must be NULL for - input-only streams. - - @param sampleRate The required sampleRate. For full-duplex streams it is the - sample rate for both input and output - - @return Returns 0 if the format is supported, and an error code indicating why - the format is not supported otherwise. The constant paFormatIsSupported is - provided to compare with the return value for success. - - @see paFormatIsSupported, PaStreamParameters -*/ -PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters, - const PaStreamParameters *outputParameters, - double sampleRate ); - - - -/* Streaming types and functions */ - - -/** - A single PaStream can provide multiple channels of real-time - streaming audio input and output to a client application. A stream - provides access to audio hardware represented by one or more - PaDevices. Depending on the underlying Host API, it may be possible - to open multiple streams using the same device, however this behavior - is implementation defined. Portable applications should assume that - a PaDevice may be simultaneously used by at most one PaStream. - - Pointers to PaStream objects are passed between PortAudio functions that - operate on streams. - - @see Pa_OpenStream, Pa_OpenDefaultStream, Pa_OpenDefaultStream, Pa_CloseStream, - Pa_StartStream, Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive, - Pa_GetStreamTime, Pa_GetStreamCpuLoad - -*/ -typedef void PaStream; - - -/** Can be passed as the framesPerBuffer parameter to Pa_OpenStream() - or Pa_OpenDefaultStream() to indicate that the stream callback will - accept buffers of any size. -*/ -#define paFramesPerBufferUnspecified (0) - - -/** Flags used to control the behavior of a stream. They are passed as - parameters to Pa_OpenStream or Pa_OpenDefaultStream. Multiple flags may be - ORed together. - - @see Pa_OpenStream, Pa_OpenDefaultStream - @see paNoFlag, paClipOff, paDitherOff, paNeverDropInput, - paPrimeOutputBuffersUsingStreamCallback, paPlatformSpecificFlags -*/ -typedef unsigned long PaStreamFlags; - -/** @see PaStreamFlags */ -#define paNoFlag ((PaStreamFlags) 0) - -/** Disable default clipping of out of range samples. - @see PaStreamFlags -*/ -#define paClipOff ((PaStreamFlags) 0x00000001) - -/** Disable default dithering. - @see PaStreamFlags -*/ -#define paDitherOff ((PaStreamFlags) 0x00000002) - -/** Flag requests that where possible a full duplex stream will not discard - overflowed input samples without calling the stream callback. This flag is - only valid for full duplex callback streams and only when used in combination - with the paFramesPerBufferUnspecified (0) framesPerBuffer parameter. Using - this flag incorrectly results in a paInvalidFlag error being returned from - Pa_OpenStream and Pa_OpenDefaultStream. - - @see PaStreamFlags, paFramesPerBufferUnspecified -*/ -#define paNeverDropInput ((PaStreamFlags) 0x00000004) - -/** Call the stream callback to fill initial output buffers, rather than the - default behavior of priming the buffers with zeros (silence). This flag has - no effect for input-only and blocking read/write streams. - - @see PaStreamFlags -*/ -#define paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008) - -/** A mask specifying the platform specific bits. - @see PaStreamFlags -*/ -#define paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000) - -/** - Timing information for the buffers passed to the stream callback. -*/ -typedef struct PaStreamCallbackTimeInfo{ - PaTime inputBufferAdcTime; - PaTime currentTime; - PaTime outputBufferDacTime; -} PaStreamCallbackTimeInfo; - - -/** - Flag bit constants for the statusFlags to PaStreamCallback. - - @see paInputUnderflow, paInputOverflow, paOutputUnderflow, paOutputOverflow, - paPrimingOutput -*/ -typedef unsigned long PaStreamCallbackFlags; - -/** In a stream opened with paFramesPerBufferUnspecified, indicates that - input data is all silence (zeros) because no real data is available. In a - stream opened without paFramesPerBufferUnspecified, it indicates that one or - more zero samples have been inserted into the input buffer to compensate - for an input underflow. - @see PaStreamCallbackFlags -*/ -#define paInputUnderflow ((PaStreamCallbackFlags) 0x00000001) - -/** In a stream opened with paFramesPerBufferUnspecified, indicates that data - prior to the first sample of the input buffer was discarded due to an - overflow, possibly because the stream callback is using too much CPU time. - Otherwise indicates that data prior to one or more samples in the - input buffer was discarded. - @see PaStreamCallbackFlags -*/ -#define paInputOverflow ((PaStreamCallbackFlags) 0x00000002) - -/** Indicates that output data (or a gap) was inserted, possibly because the - stream callback is using too much CPU time. - @see PaStreamCallbackFlags -*/ -#define paOutputUnderflow ((PaStreamCallbackFlags) 0x00000004) - -/** Indicates that output data will be discarded because no room is available. - @see PaStreamCallbackFlags -*/ -#define paOutputOverflow ((PaStreamCallbackFlags) 0x00000008) - -/** Some of all of the output data will be used to prime the stream, input - data may be zero. - @see PaStreamCallbackFlags -*/ -#define paPrimingOutput ((PaStreamCallbackFlags) 0x00000010) - -/** - Allowable return values for the PaStreamCallback. - @see PaStreamCallback -*/ -typedef enum PaStreamCallbackResult -{ - paContinue=0, - paComplete=1, - paAbort=2 -} PaStreamCallbackResult; - - -/** - Functions of type PaStreamCallback are implemented by PortAudio clients. - They consume, process or generate audio in response to requests from an - active PortAudio stream. - - @param input and @param output are arrays of interleaved samples, - the format, packing and number of channels used by the buffers are - determined by parameters to Pa_OpenStream(). - - @param frameCount The number of sample frames to be processed by - the stream callback. - - @param timeInfo The time in seconds when the first sample of the input - buffer was received at the audio input, the time in seconds when the first - sample of the output buffer will begin being played at the audio output, and - the time in seconds when the stream callback was called. - See also Pa_GetStreamTime() - - @param statusFlags Flags indicating whether input and/or output buffers - have been inserted or will be dropped to overcome underflow or overflow - conditions. - - @param userData The value of a user supplied pointer passed to - Pa_OpenStream() intended for storing synthesis data etc. - - @return - The stream callback should return one of the values in the - PaStreamCallbackResult enumeration. To ensure that the callback continues - to be called, it should return paContinue (0). Either paComplete or paAbort - can be returned to finish stream processing, after either of these values is - returned the callback will not be called again. If paAbort is returned the - stream will finish as soon as possible. If paComplete is returned, the stream - will continue until all buffers generated by the callback have been played. - This may be useful in applications such as soundfile players where a specific - duration of output is required. However, it is not necessary to utilise this - mechanism as Pa_StopStream(), Pa_AbortStream() or Pa_CloseStream() can also - be used to stop the stream. The callback must always fill the entire output - buffer irrespective of its return value. - - @see Pa_OpenStream, Pa_OpenDefaultStream - - @note With the exception of Pa_GetStreamCpuLoad() it is not permissable to call - PortAudio API functions from within the stream callback. -*/ -typedef int PaStreamCallback( - const void *input, void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData ); - - -/** Opens a stream for either input, output or both. - - @param stream The address of a PaStream pointer which will receive - a pointer to the newly opened stream. - - @param inputParameters A structure that describes the input parameters used by - the opened stream. See PaStreamParameters for a description of these parameters. - inputParameters must be NULL for output-only streams. - - @param outputParameters A structure that describes the output parameters used by - the opened stream. See PaStreamParameters for a description of these parameters. - outputParameters must be NULL for input-only streams. - - @param sampleRate The desired sampleRate. For full-duplex streams it is the - sample rate for both input and output - - @param framesPerBuffer The number of frames passed to the stream callback - function, or the preferred block granularity for a blocking read/write stream. - The special value paFramesPerBufferUnspecified (0) may be used to request that - the stream callback will recieve an optimal (and possibly varying) number of - frames based on host requirements and the requested latency settings. - Note: With some host APIs, the use of non-zero framesPerBuffer for a callback - stream may introduce an additional layer of buffering which could introduce - additional latency. PortAudio guarantees that the additional latency - will be kept to the theoretical minimum however, it is strongly recommended - that a non-zero framesPerBuffer value only be used when your algorithm - requires a fixed number of frames per stream callback. - - @param streamFlags Flags which modify the behaviour of the streaming process. - This parameter may contain a combination of flags ORed together. Some flags may - only be relevant to certain buffer formats. - - @param streamCallback A pointer to a client supplied function that is responsible - for processing and filling input and output buffers. If this parameter is NULL - the stream will be opened in 'blocking read/write' mode. In blocking mode, - the client can receive sample data using Pa_ReadStream and write sample data - using Pa_WriteStream, the number of samples that may be read or written - without blocking is returned by Pa_GetStreamReadAvailable and - Pa_GetStreamWriteAvailable respectively. - - @param userData A client supplied pointer which is passed to the stream callback - function. It could for example, contain a pointer to instance data necessary - for processing the audio buffers. This parameter is ignored if streamCallback - is NULL. - - @return - Upon success Pa_OpenStream() returns paNoError and places a pointer to a - valid PaStream in the stream argument. The stream is inactive (stopped). - If a call to Pa_OpenStream() fails, a non-zero error code is returned (see - PaError for possible error codes) and the value of stream is invalid. - - @see PaStreamParameters, PaStreamCallback, Pa_ReadStream, Pa_WriteStream, - Pa_GetStreamReadAvailable, Pa_GetStreamWriteAvailable -*/ -PaError Pa_OpenStream( PaStream** stream, - const PaStreamParameters *inputParameters, - const PaStreamParameters *outputParameters, - double sampleRate, - unsigned long framesPerBuffer, - PaStreamFlags streamFlags, - PaStreamCallback *streamCallback, - void *userData ); - - -/** A simplified version of Pa_OpenStream() that opens the default input - and/or output devices. - - @param stream The address of a PaStream pointer which will receive - a pointer to the newly opened stream. - - @param numInputChannels The number of channels of sound that will be supplied - to the stream callback or returned by Pa_ReadStream. It can range from 1 to - the value of maxInputChannels in the PaDeviceInfo record for the default input - device. If 0 the stream is opened as an output-only stream. - - @param numOutputChannels The number of channels of sound to be delivered to the - stream callback or passed to Pa_WriteStream. It can range from 1 to the value - of maxOutputChannels in the PaDeviceInfo record for the default output dvice. - If 0 the stream is opened as an output-only stream. - - @param sampleFormat The sample format of both the input and output buffers - provided to the callback or passed to and from Pa_ReadStream and Pa_WriteStream. - sampleFormat may be any of the formats described by the PaSampleFormat - enumeration. - - @param sampleRate Same as Pa_OpenStream parameter of the same name. - @param framesPerBuffer Same as Pa_OpenStream parameter of the same name. - @param streamCallback Same as Pa_OpenStream parameter of the same name. - @param userData Same as Pa_OpenStream parameter of the same name. - - @return As for Pa_OpenStream - - @see Pa_OpenStream, PaStreamCallback -*/ -PaError Pa_OpenDefaultStream( PaStream** stream, - int numInputChannels, - int numOutputChannels, - PaSampleFormat sampleFormat, - double sampleRate, - unsigned long framesPerBuffer, - PaStreamCallback *streamCallback, - void *userData ); - - -/** Closes an audio stream. If the audio stream is active it - discards any pending buffers as if Pa_AbortStream() had been called. -*/ -PaError Pa_CloseStream( PaStream *stream ); - - -/** Functions of type PaStreamFinishedCallback are implemented by PortAudio - clients. They can be registered with a stream using the Pa_SetStreamFinishedCallback - function. Once registered they are called when the stream becomes inactive - (ie once a call to Pa_StopStream() will not block). - A stream will become inactive after the stream callback returns non-zero, - or when Pa_StopStream or Pa_AbortStream is called. For a stream providing audio - output, if the stream callback returns paComplete, or Pa_StopStream is called, - the stream finished callback will not be called until all generated sample data - has been played. - - @param userData The userData parameter supplied to Pa_OpenStream() - - @see Pa_SetStreamFinishedCallback -*/ -typedef void PaStreamFinishedCallback( void *userData ); - - -/** Register a stream finished callback function which will be called when the - stream becomes inactive. See the description of PaStreamFinishedCallback for - further details about when the callback will be called. - - @param stream a pointer to a PaStream that is in the stopped state - if the - stream is not stopped, the stream's finished callback will remain unchanged - and an error code will be returned. - - @param streamFinishedCallback a pointer to a function with the same signature - as PaStreamFinishedCallback, that will be called when the stream becomes - inactive. Passing NULL for this parameter will un-register a previously - registered stream finished callback function. - - @return on success returns paNoError, otherwise an error code indicating the cause - of the error. - - @see PaStreamFinishedCallback -*/ -PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback ); - - -/** Commences audio processing. -*/ -PaError Pa_StartStream( PaStream *stream ); - - -/** Terminates audio processing. It waits until all pending - audio buffers have been played before it returns. -*/ -PaError Pa_StopStream( PaStream *stream ); - - -/** Terminates audio processing immediately without waiting for pending - buffers to complete. -*/ -PaError Pa_AbortStream( PaStream *stream ); - - -/** Determine whether the stream is stopped. - A stream is considered to be stopped prior to a successful call to - Pa_StartStream and after a successful call to Pa_StopStream or Pa_AbortStream. - If a stream callback returns a value other than paContinue the stream is NOT - considered to be stopped. - - @return Returns one (1) when the stream is stopped, zero (0) when - the stream is running or, a PaErrorCode (which are always negative) if - PortAudio is not initialized or an error is encountered. - - @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive -*/ -PaError Pa_IsStreamStopped( PaStream *stream ); - - -/** Determine whether the stream is active. - A stream is active after a successful call to Pa_StartStream(), until it - becomes inactive either as a result of a call to Pa_StopStream() or - Pa_AbortStream(), or as a result of a return value other than paContinue from - the stream callback. In the latter case, the stream is considered inactive - after the last buffer has finished playing. - - @return Returns one (1) when the stream is active (ie playing or recording - audio), zero (0) when not playing or, a PaErrorCode (which are always negative) - if PortAudio is not initialized or an error is encountered. - - @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamStopped -*/ -PaError Pa_IsStreamActive( PaStream *stream ); - - - -/** A structure containing unchanging information about an open stream. - @see Pa_GetStreamInfo -*/ - -typedef struct PaStreamInfo -{ - /** this is struct version 1 */ - int structVersion; - - /** The input latency of the stream in seconds. This value provides the most - accurate estimate of input latency available to the implementation. It may - differ significantly from the suggestedLatency value passed to Pa_OpenStream(). - The value of this field will be zero (0.) for output-only streams. - @see PaTime - */ - PaTime inputLatency; - - /** The output latency of the stream in seconds. This value provides the most - accurate estimate of output latency available to the implementation. It may - differ significantly from the suggestedLatency value passed to Pa_OpenStream(). - The value of this field will be zero (0.) for input-only streams. - @see PaTime - */ - PaTime outputLatency; - - /** The sample rate of the stream in Hertz (samples per second). In cases - where the hardware sample rate is inaccurate and PortAudio is aware of it, - the value of this field may be different from the sampleRate parameter - passed to Pa_OpenStream(). If information about the actual hardware sample - rate is not available, this field will have the same value as the sampleRate - parameter passed to Pa_OpenStream(). - */ - double sampleRate; - -} PaStreamInfo; - - -/** Retrieve a pointer to a PaStreamInfo structure containing information - about the specified stream. - @return A pointer to an immutable PaStreamInfo structure. If the stream - parameter invalid, or an error is encountered, the function returns NULL. - - @param stream A pointer to an open stream previously created with Pa_OpenStream. - - @note PortAudio manages the memory referenced by the returned pointer, - the client must not manipulate or free the memory. The pointer is only - guaranteed to be valid until the specified stream is closed. - - @see PaStreamInfo -*/ -const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream ); - - -/** Determine the current time for the stream according to the same clock used - to generate buffer timestamps. This time may be used for syncronising other - events to the audio stream, for example synchronizing audio to MIDI. - - @return The stream's current time in seconds, or 0 if an error occurred. - - @see PaTime, PaStreamCallback -*/ -PaTime Pa_GetStreamTime( PaStream *stream ); - - -/** Retrieve CPU usage information for the specified stream. - The "CPU Load" is a fraction of total CPU time consumed by a callback stream's - audio processing routines including, but not limited to the client supplied - stream callback. This function does not work with blocking read/write streams. - - This function may be called from the stream callback function or the - application. - - @return - A floating point value, typically between 0.0 and 1.0, where 1.0 indicates - that the stream callback is consuming the maximum number of CPU cycles possible - to maintain real-time operation. A value of 0.5 would imply that PortAudio and - the stream callback was consuming roughly 50% of the available CPU time. The - return value may exceed 1.0. A value of 0.0 will always be returned for a - blocking read/write stream, or if an error occurrs. -*/ -double Pa_GetStreamCpuLoad( PaStream* stream ); - - -/** Read samples from an input stream. The function doesn't return until - the entire buffer has been filled - this may involve waiting for the operating - system to supply the data. - - @param stream A pointer to an open stream previously created with Pa_OpenStream. - - @param buffer A pointer to a buffer of sample frames. The buffer contains - samples in the format specified by the inputParameters->sampleFormat field - used to open the stream, and the number of channels specified by - inputParameters->numChannels. If non-interleaved samples were requested, - buffer is a pointer to the first element of an array of non-interleaved - buffer pointers, one for each channel. - - @param frames The number of frames to be read into buffer. This parameter - is not constrained to a specific range, however high performance applications - will want to match this parameter to the framesPerBuffer parameter used - when opening the stream. - - @return On success PaNoError will be returned, or PaInputOverflowed if input - data was discarded by PortAudio after the previous call and before this call. -*/ -PaError Pa_ReadStream( PaStream* stream, - void *buffer, - unsigned long frames ); - - -/** Write samples to an output stream. This function doesn't return until the - entire buffer has been consumed - this may involve waiting for the operating - system to consume the data. - - @param stream A pointer to an open stream previously created with Pa_OpenStream. - - @param buffer A pointer to a buffer of sample frames. The buffer contains - samples in the format specified by the outputParameters->sampleFormat field - used to open the stream, and the number of channels specified by - outputParameters->numChannels. If non-interleaved samples were requested, - buffer is a pointer to the first element of an array of non-interleaved - buffer pointers, one for each channel. - - @param frames The number of frames to be written from buffer. This parameter - is not constrained to a specific range, however high performance applications - will want to match this parameter to the framesPerBuffer parameter used - when opening the stream. - - @return On success PaNoError will be returned, or paOutputUnderflowed if - additional output data was inserted after the previous call and before this - call. -*/ -PaError Pa_WriteStream( PaStream* stream, - const void *buffer, - unsigned long frames ); - - -/** Retrieve the number of frames that can be read from the stream without - waiting. - - @return Returns a non-negative value representing the maximum number of frames - that can be read from the stream without blocking or busy waiting or, a - PaErrorCode (which are always negative) if PortAudio is not initialized or an - error is encountered. -*/ -signed long Pa_GetStreamReadAvailable( PaStream* stream ); - - -/** Retrieve the number of frames that can be written to the stream without - waiting. - - @return Returns a non-negative value representing the maximum number of frames - that can be written to the stream without blocking or busy waiting or, a - PaErrorCode (which are always negative) if PortAudio is not initialized or an - error is encountered. -*/ -signed long Pa_GetStreamWriteAvailable( PaStream* stream ); - - -/* Miscellaneous utilities */ - - -/** Retrieve the size of a given sample format in bytes. - - @return The size in bytes of a single sample in the specified format, - or paSampleFormatNotSupported if the format is not supported. -*/ -PaError Pa_GetSampleSize( PaSampleFormat format ); - - -/** Put the caller to sleep for at least 'msec' milliseconds. This function is - provided only as a convenience for authors of portable code (such as the tests - and examples in the PortAudio distribution.) - - The function may sleep longer than requested so don't rely on this for accurate - musical timing. -*/ -void Pa_Sleep( long msec ); - - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* PORTAUDIO_H */ + +#ifndef PORTAUDIO_H +#define PORTAUDIO_H +/* + * $Id: portaudio.h,v 1.1 2005/11/29 21:27:24 joe Exp $ + * PortAudio Portable Real-Time Audio Library + * PortAudio API Header File + * Latest version available at: http://www.portaudio.com/ + * + * Copyright (c) 1999-2002 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** @file + @brief The PortAudio API. +*/ + + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + +/** Retrieve the release number of the currently running PortAudio build, + eg 1900. +*/ +int Pa_GetVersion( void ); + + +/** Retrieve a textual description of the current PortAudio build, + eg "PortAudio V19-devel 13 October 2002". +*/ +const char* Pa_GetVersionText( void ); + + +/** Error codes returned by PortAudio functions. + Note that with the exception of paNoError, all PaErrorCodes are negative. +*/ + +typedef int PaError; +typedef enum PaErrorCode +{ + paNoError = 0, + + paNotInitialized = -10000, + paUnanticipatedHostError, + paInvalidChannelCount, + paInvalidSampleRate, + paInvalidDevice, + paInvalidFlag, + paSampleFormatNotSupported, + paBadIODeviceCombination, + paInsufficientMemory, + paBufferTooBig, + paBufferTooSmall, + paNullCallback, + paBadStreamPtr, + paTimedOut, + paInternalError, + paDeviceUnavailable, + paIncompatibleHostApiSpecificStreamInfo, + paStreamIsStopped, + paStreamIsNotStopped, + paInputOverflowed, + paOutputUnderflowed, + paHostApiNotFound, + paInvalidHostApi, + paCanNotReadFromACallbackStream, /**< @todo review error code name */ + paCanNotWriteToACallbackStream, /**< @todo review error code name */ + paCanNotReadFromAnOutputOnlyStream, /**< @todo review error code name */ + paCanNotWriteToAnInputOnlyStream, /**< @todo review error code name */ + paIncompatibleStreamHostApi +} PaErrorCode; + + +/** Translate the supplied PortAudio error code into a human readable + message. +*/ +const char *Pa_GetErrorText( PaError errorCode ); + + +/** Library initialization function - call this before using PortAudio. + This function initialises internal data structures and prepares underlying + host APIs for use. This function MUST be called before using any other + PortAudio API functions. + + If Pa_Initialize() is called multiple times, each successful + call must be matched with a corresponding call to Pa_Terminate(). + Pairs of calls to Pa_Initialize()/Pa_Terminate() may overlap, and are not + required to be fully nested. + + Note that if Pa_Initialize() returns an error code, Pa_Terminate() should + NOT be called. + + @return paNoError if successful, otherwise an error code indicating the cause + of failure. + + @see Pa_Terminate +*/ +PaError Pa_Initialize( void ); + + +/** Library termination function - call this when finished using PortAudio. + This function deallocates all resources allocated by PortAudio since it was + initializied by a call to Pa_Initialize(). In cases where Pa_Initialise() has + been called multiple times, each call must be matched with a corresponding call + to Pa_Terminate(). The final matching call to Pa_Terminate() will automatically + close any PortAudio streams that are still open. + + Pa_Terminate() MUST be called before exiting a program which uses PortAudio. + Failure to do so may result in serious resource leaks, such as audio devices + not being available until the next reboot. + + @return paNoError if successful, otherwise an error code indicating the cause + of failure. + + @see Pa_Initialize +*/ +PaError Pa_Terminate( void ); + + + +/** The type used to refer to audio devices. Values of this type usually + range from 0 to (Pa_DeviceCount-1), and may also take on the PaNoDevice + and paUseHostApiSpecificDeviceSpecification values. + + @see Pa_DeviceCount, paNoDevice, paUseHostApiSpecificDeviceSpecification +*/ +typedef int PaDeviceIndex; + + +/** A special PaDeviceIndex value indicating that no device is available, + or should be used. + + @see PaDeviceIndex +*/ +#define paNoDevice ((PaDeviceIndex)-1) + + +/** A special PaDeviceIndex value indicating that the device(s) to be used + are specified in the host api specific stream info structure. + + @see PaDeviceIndex +*/ +#define paUseHostApiSpecificDeviceSpecification ((PaDeviceIndex)-2) + + +/* Host API enumeration mechanism */ + +/** The type used to enumerate to host APIs at runtime. Values of this type + range from 0 to (Pa_GetHostApiCount()-1). + + @see Pa_GetHostApiCount +*/ +typedef int PaHostApiIndex; + + +/** Retrieve the number of available host APIs. Even if a host API is + available it may have no devices available. + + @return A non-negative value indicating the number of available host APIs + or, a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. + + @see PaHostApiIndex +*/ +PaHostApiIndex Pa_GetHostApiCount( void ); + + +/** Retrieve the index of the default host API. The default host API will be + the lowest common denominator host API on the current platform and is + unlikely to provide the best performance. + + @return A non-negative value ranging from 0 to (Pa_GetHostApiCount()-1) + indicating the default host API index or, a PaErrorCode (which are always + negative) if PortAudio is not initialized or an error is encountered. +*/ +PaHostApiIndex Pa_GetDefaultHostApi( void ); + + +/** Unchanging unique identifiers for each supported host API. This type + is used in the PaHostApiInfo structure. The values are guaranteed to be + unique and to never change, thus allowing code to be written that + conditionally uses host API specific extensions. + + New type ids will be allocated when support for a host API reaches + "public alpha" status, prior to that developers should use the + paInDevelopment type id. + + @see PaHostApiInfo +*/ +typedef enum PaHostApiTypeId +{ + paInDevelopment=0, /* use while developing support for a new host API */ + paDirectSound=1, + paMME=2, + paASIO=3, + paSoundManager=4, + paCoreAudio=5, + paOSS=7, + paALSA=8, + paAL=9, + paBeOS=10, + paWDMKS=11, + paJACK=12 +} PaHostApiTypeId; + + +/** A structure containing information about a particular host API. */ + +typedef struct PaHostApiInfo +{ + /** this is struct version 1 */ + int structVersion; + /** The well known unique identifier of this host API @see PaHostApiTypeId */ + PaHostApiTypeId type; + /** A textual description of the host API for display on user interfaces. */ + const char *name; + + /** The number of devices belonging to this host API. This field may be + used in conjunction with Pa_HostApiDeviceIndexToDeviceIndex() to enumerate + all devices for this host API. + @see Pa_HostApiDeviceIndexToDeviceIndex + */ + int deviceCount; + + /** The the default input device for this host API. The value will be a + device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice + if no default input device is available. + */ + PaDeviceIndex defaultInputDevice; + + /** The the default output device for this host API. The value will be a + device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice + if no default output device is available. + */ + PaDeviceIndex defaultOutputDevice; + +} PaHostApiInfo; + + +/** Retrieve a pointer to a structure containing information about a specific + host Api. + + @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1) + + @return A pointer to an immutable PaHostApiInfo structure describing + a specific host API. If the hostApi parameter is out of range or an error + is encountered, the function returns NULL. + + The returned structure is owned by the PortAudio implementation and must not + be manipulated or freed. The pointer is only guaranteed to be valid between + calls to Pa_Initialize() and Pa_Terminate(). +*/ +const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi ); + + +/** Convert a static host API unique identifier, into a runtime + host API index. + + @param type A unique host API identifier belonging to the PaHostApiTypeId + enumeration. + + @return A valid PaHostApiIndex ranging from 0 to (Pa_GetHostApiCount()-1) or, + a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. + + The paHostApiNotFound error code indicates that the host API specified by the + type parameter is not available. + + @see PaHostApiTypeId +*/ +PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type ); + + +/** Convert a host-API-specific device index to standard PortAudio device index. + This function may be used in conjunction with the deviceCount field of + PaHostApiInfo to enumerate all devices for the specified host API. + + @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1) + + @param hostApiDeviceIndex A valid per-host device index in the range + 0 to (Pa_GetHostApiInfo(hostApi)->deviceCount-1) + + @return A non-negative PaDeviceIndex ranging from 0 to (Pa_GetDeviceCount()-1) + or, a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. + + A paInvalidHostApi error code indicates that the host API index specified by + the hostApi parameter is out of range. + + A paInvalidDevice error code indicates that the hostApiDeviceIndex parameter + is out of range. + + @see PaHostApiInfo +*/ +PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi, + int hostApiDeviceIndex ); + + + +/** Structure used to return information about a host error condition. +*/ +typedef struct PaHostErrorInfo{ + PaHostApiTypeId hostApiType; /**< the host API which returned the error code */ + long errorCode; /**< the error code returned */ + const char *errorText; /**< a textual description of the error if available, otherwise a zero-length string */ +}PaHostErrorInfo; + + +/** Return information about the last host error encountered. The error + information returned by Pa_GetLastHostErrorInfo() will never be modified + asyncronously by errors occurring in other PortAudio owned threads + (such as the thread that manages the stream callback.) + + This function is provided as a last resort, primarily to enhance debugging + by providing clients with access to all available error information. + + @return A pointer to an immutable structure constaining information about + the host error. The values in this structure will only be valid if a + PortAudio function has previously returned the paUnanticipatedHostError + error code. +*/ +const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void ); + + + +/* Device enumeration and capabilities */ + +/** Retrieve the number of available devices. The number of available devices + may be zero. + + @return A non-negative value indicating the number of available devices or, + a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. +*/ +PaDeviceIndex Pa_GetDeviceCount( void ); + + +/** Retrieve the index of the default input device. The result can be + used in the inputDevice parameter to Pa_OpenStream(). + + @return The default input device index for the default host API, or paNoDevice + if no default input device is available or an error was encountered. +*/ +PaDeviceIndex Pa_GetDefaultInputDevice( void ); + + +/** Retrieve the index of the default output device. The result can be + used in the outputDevice parameter to Pa_OpenStream(). + + @return The default output device index for the defualt host API, or paNoDevice + if no default output device is available or an error was encountered. + + @note + On the PC, the user can specify a default device by + setting an environment variable. For example, to use device #1. +
+ set PA_RECOMMENDED_OUTPUT_DEVICE=1
+
+ The user should first determine the available device ids by using + the supplied application "pa_devs". +*/ +PaDeviceIndex Pa_GetDefaultOutputDevice( void ); + + +/** The type used to represent monotonic time in seconds that can be used + for syncronisation. The type is used for the outTime argument to the + PaStreamCallback and as the result of Pa_GetStreamTime(). + + @see PaStreamCallback, Pa_GetStreamTime +*/ +typedef double PaTime; + + +/** A type used to specify one or more sample formats. Each value indicates + a possible format for sound data passed to and from the stream callback, + Pa_ReadStream and Pa_WriteStream. + + The standard formats paFloat32, paInt16, paInt32, paInt24, paInt8 + and aUInt8 are usually implemented by all implementations. + + The floating point representation (paFloat32) uses +1.0 and -1.0 as the + maximum and minimum respectively. + + paUInt8 is an unsigned 8 bit format where 128 is considered "ground" + + The paNonInterleaved flag indicates that a multichannel buffer is passed + as a set of non-interleaved pointers. + + @see Pa_OpenStream, Pa_OpenDefaultStream, PaDeviceInfo + @see paFloat32, paInt16, paInt32, paInt24, paInt8 + @see paUInt8, paCustomFormat, paNonInterleaved +*/ +typedef unsigned long PaSampleFormat; + + +#define paFloat32 ((PaSampleFormat) 0x00000001) /**< @see PaSampleFormat */ +#define paInt32 ((PaSampleFormat) 0x00000002) /**< @see PaSampleFormat */ +#define paInt24 ((PaSampleFormat) 0x00000004) /**< Packed 24 bit format. @see PaSampleFormat */ +#define paInt16 ((PaSampleFormat) 0x00000008) /**< @see PaSampleFormat */ +#define paInt8 ((PaSampleFormat) 0x00000010) /**< @see PaSampleFormat */ +#define paUInt8 ((PaSampleFormat) 0x00000020) /**< @see PaSampleFormat */ +#define paCustomFormat ((PaSampleFormat) 0x00010000)/**< @see PaSampleFormat */ + +#define paNonInterleaved ((PaSampleFormat) 0x80000000) + +/** A structure providing information and capabilities of PortAudio devices. + Devices may support input, output or both input and output. +*/ +typedef struct PaDeviceInfo +{ + int structVersion; /* this is struct version 2 */ + const char *name; + PaHostApiIndex hostApi; /* note this is a host API index, not a type id*/ + + int maxInputChannels; + int maxOutputChannels; + + /* Default latency values for interactive performance. */ + PaTime defaultLowInputLatency; + PaTime defaultLowOutputLatency; + /* Default latency values for robust non-interactive applications (eg. playing sound files). */ + PaTime defaultHighInputLatency; + PaTime defaultHighOutputLatency; + + double defaultSampleRate; +} PaDeviceInfo; + + +/** Retrieve a pointer to a PaDeviceInfo structure containing information + about the specified device. + @return A pointer to an immutable PaDeviceInfo structure. If the device + parameter is out of range the function returns NULL. + + @param device A valid device index in the range 0 to (Pa_GetDeviceCount()-1) + + @note PortAudio manages the memory referenced by the returned pointer, + the client must not manipulate or free the memory. The pointer is only + guaranteed to be valid between calls to Pa_Initialize() and Pa_Terminate(). + + @see PaDeviceInfo, PaDeviceIndex +*/ +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device ); + + +/** Parameters for one direction (input or output) of a stream. +*/ +typedef struct PaStreamParameters +{ + /** A valid device index in the range 0 to (Pa_GetDeviceCount()-1) + specifying the device to be used or the special constant + paUseHostApiSpecificDeviceSpecification which indicates that the actual + device(s) to use are specified in hostApiSpecificStreamInfo. + This field must not be set to paNoDevice. + */ + PaDeviceIndex device; + + /** The number of channels of sound to be delivered to the + stream callback or accessed by Pa_ReadStream() or Pa_WriteStream(). + It can range from 1 to the value of maxInputChannels in the + PaDeviceInfo record for the device specified by the device parameter. + */ + int channelCount; + + /** The sample format of the buffer provided to the stream callback, + a_ReadStream() or Pa_WriteStream(). It may be any of the formats described + by the PaSampleFormat enumeration. + */ + PaSampleFormat sampleFormat; + + /** The desired latency in seconds. Where practical, implementations should + configure their latency based on these parameters, otherwise they may + choose the closest viable latency instead. Unless the suggested latency + is greater than the absolute upper limit for the device implementations + shouldround the suggestedLatency up to the next practial value - ie to + provide an equal or higher latency than suggestedLatency whereever possibe. + Actual latency values for an open stream may be retrieved using the + inputLatency and outputLatency fields of the PaStreamInfo structure + returned by Pa_GetStreamInfo(). + @see default*Latency in PaDeviceInfo, *Latency in PaStreamInfo + */ + PaTime suggestedLatency; + + /** An optional pointer to a host api specific data structure + containing additional information for device setup and/or stream processing. + hostApiSpecificStreamInfo is never required for correct operation, + if not used it should be set to NULL. + */ + void *hostApiSpecificStreamInfo; + +} PaStreamParameters; + + +/** Return code for Pa_IsFormatSupported indicating success. */ +#define paFormatIsSupported (0) + +/** Determine whether it would be possible to open a stream with the specified + parameters. + + @param inputParameters A structure that describes the input parameters used to + open a stream. The suggestedLatency field is ignored. See PaStreamParameters + for a description of these parameters. inputParameters must be NULL for + output-only streams. + + @param outputParameters A structure that describes the output parameters used + to open a stream. The suggestedLatency field is ignored. See PaStreamParameters + for a description of these parameters. outputParameters must be NULL for + input-only streams. + + @param sampleRate The required sampleRate. For full-duplex streams it is the + sample rate for both input and output + + @return Returns 0 if the format is supported, and an error code indicating why + the format is not supported otherwise. The constant paFormatIsSupported is + provided to compare with the return value for success. + + @see paFormatIsSupported, PaStreamParameters +*/ +PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters, + const PaStreamParameters *outputParameters, + double sampleRate ); + + + +/* Streaming types and functions */ + + +/** + A single PaStream can provide multiple channels of real-time + streaming audio input and output to a client application. A stream + provides access to audio hardware represented by one or more + PaDevices. Depending on the underlying Host API, it may be possible + to open multiple streams using the same device, however this behavior + is implementation defined. Portable applications should assume that + a PaDevice may be simultaneously used by at most one PaStream. + + Pointers to PaStream objects are passed between PortAudio functions that + operate on streams. + + @see Pa_OpenStream, Pa_OpenDefaultStream, Pa_OpenDefaultStream, Pa_CloseStream, + Pa_StartStream, Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive, + Pa_GetStreamTime, Pa_GetStreamCpuLoad + +*/ +typedef void PaStream; + + +/** Can be passed as the framesPerBuffer parameter to Pa_OpenStream() + or Pa_OpenDefaultStream() to indicate that the stream callback will + accept buffers of any size. +*/ +#define paFramesPerBufferUnspecified (0) + + +/** Flags used to control the behavior of a stream. They are passed as + parameters to Pa_OpenStream or Pa_OpenDefaultStream. Multiple flags may be + ORed together. + + @see Pa_OpenStream, Pa_OpenDefaultStream + @see paNoFlag, paClipOff, paDitherOff, paNeverDropInput, + paPrimeOutputBuffersUsingStreamCallback, paPlatformSpecificFlags +*/ +typedef unsigned long PaStreamFlags; + +/** @see PaStreamFlags */ +#define paNoFlag ((PaStreamFlags) 0) + +/** Disable default clipping of out of range samples. + @see PaStreamFlags +*/ +#define paClipOff ((PaStreamFlags) 0x00000001) + +/** Disable default dithering. + @see PaStreamFlags +*/ +#define paDitherOff ((PaStreamFlags) 0x00000002) + +/** Flag requests that where possible a full duplex stream will not discard + overflowed input samples without calling the stream callback. This flag is + only valid for full duplex callback streams and only when used in combination + with the paFramesPerBufferUnspecified (0) framesPerBuffer parameter. Using + this flag incorrectly results in a paInvalidFlag error being returned from + Pa_OpenStream and Pa_OpenDefaultStream. + + @see PaStreamFlags, paFramesPerBufferUnspecified +*/ +#define paNeverDropInput ((PaStreamFlags) 0x00000004) + +/** Call the stream callback to fill initial output buffers, rather than the + default behavior of priming the buffers with zeros (silence). This flag has + no effect for input-only and blocking read/write streams. + + @see PaStreamFlags +*/ +#define paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008) + +/** A mask specifying the platform specific bits. + @see PaStreamFlags +*/ +#define paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000) + +/** + Timing information for the buffers passed to the stream callback. +*/ +typedef struct PaStreamCallbackTimeInfo{ + PaTime inputBufferAdcTime; + PaTime currentTime; + PaTime outputBufferDacTime; +} PaStreamCallbackTimeInfo; + + +/** + Flag bit constants for the statusFlags to PaStreamCallback. + + @see paInputUnderflow, paInputOverflow, paOutputUnderflow, paOutputOverflow, + paPrimingOutput +*/ +typedef unsigned long PaStreamCallbackFlags; + +/** In a stream opened with paFramesPerBufferUnspecified, indicates that + input data is all silence (zeros) because no real data is available. In a + stream opened without paFramesPerBufferUnspecified, it indicates that one or + more zero samples have been inserted into the input buffer to compensate + for an input underflow. + @see PaStreamCallbackFlags +*/ +#define paInputUnderflow ((PaStreamCallbackFlags) 0x00000001) + +/** In a stream opened with paFramesPerBufferUnspecified, indicates that data + prior to the first sample of the input buffer was discarded due to an + overflow, possibly because the stream callback is using too much CPU time. + Otherwise indicates that data prior to one or more samples in the + input buffer was discarded. + @see PaStreamCallbackFlags +*/ +#define paInputOverflow ((PaStreamCallbackFlags) 0x00000002) + +/** Indicates that output data (or a gap) was inserted, possibly because the + stream callback is using too much CPU time. + @see PaStreamCallbackFlags +*/ +#define paOutputUnderflow ((PaStreamCallbackFlags) 0x00000004) + +/** Indicates that output data will be discarded because no room is available. + @see PaStreamCallbackFlags +*/ +#define paOutputOverflow ((PaStreamCallbackFlags) 0x00000008) + +/** Some of all of the output data will be used to prime the stream, input + data may be zero. + @see PaStreamCallbackFlags +*/ +#define paPrimingOutput ((PaStreamCallbackFlags) 0x00000010) + +/** + Allowable return values for the PaStreamCallback. + @see PaStreamCallback +*/ +typedef enum PaStreamCallbackResult +{ + paContinue=0, + paComplete=1, + paAbort=2 +} PaStreamCallbackResult; + + +/** + Functions of type PaStreamCallback are implemented by PortAudio clients. + They consume, process or generate audio in response to requests from an + active PortAudio stream. + + @param input and @param output are arrays of interleaved samples, + the format, packing and number of channels used by the buffers are + determined by parameters to Pa_OpenStream(). + + @param frameCount The number of sample frames to be processed by + the stream callback. + + @param timeInfo The time in seconds when the first sample of the input + buffer was received at the audio input, the time in seconds when the first + sample of the output buffer will begin being played at the audio output, and + the time in seconds when the stream callback was called. + See also Pa_GetStreamTime() + + @param statusFlags Flags indicating whether input and/or output buffers + have been inserted or will be dropped to overcome underflow or overflow + conditions. + + @param userData The value of a user supplied pointer passed to + Pa_OpenStream() intended for storing synthesis data etc. + + @return + The stream callback should return one of the values in the + PaStreamCallbackResult enumeration. To ensure that the callback continues + to be called, it should return paContinue (0). Either paComplete or paAbort + can be returned to finish stream processing, after either of these values is + returned the callback will not be called again. If paAbort is returned the + stream will finish as soon as possible. If paComplete is returned, the stream + will continue until all buffers generated by the callback have been played. + This may be useful in applications such as soundfile players where a specific + duration of output is required. However, it is not necessary to utilise this + mechanism as Pa_StopStream(), Pa_AbortStream() or Pa_CloseStream() can also + be used to stop the stream. The callback must always fill the entire output + buffer irrespective of its return value. + + @see Pa_OpenStream, Pa_OpenDefaultStream + + @note With the exception of Pa_GetStreamCpuLoad() it is not permissable to call + PortAudio API functions from within the stream callback. +*/ +typedef int PaStreamCallback( + const void *input, void *output, + unsigned long frameCount, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData ); + + +/** Opens a stream for either input, output or both. + + @param stream The address of a PaStream pointer which will receive + a pointer to the newly opened stream. + + @param inputParameters A structure that describes the input parameters used by + the opened stream. See PaStreamParameters for a description of these parameters. + inputParameters must be NULL for output-only streams. + + @param outputParameters A structure that describes the output parameters used by + the opened stream. See PaStreamParameters for a description of these parameters. + outputParameters must be NULL for input-only streams. + + @param sampleRate The desired sampleRate. For full-duplex streams it is the + sample rate for both input and output + + @param framesPerBuffer The number of frames passed to the stream callback + function, or the preferred block granularity for a blocking read/write stream. + The special value paFramesPerBufferUnspecified (0) may be used to request that + the stream callback will recieve an optimal (and possibly varying) number of + frames based on host requirements and the requested latency settings. + Note: With some host APIs, the use of non-zero framesPerBuffer for a callback + stream may introduce an additional layer of buffering which could introduce + additional latency. PortAudio guarantees that the additional latency + will be kept to the theoretical minimum however, it is strongly recommended + that a non-zero framesPerBuffer value only be used when your algorithm + requires a fixed number of frames per stream callback. + + @param streamFlags Flags which modify the behaviour of the streaming process. + This parameter may contain a combination of flags ORed together. Some flags may + only be relevant to certain buffer formats. + + @param streamCallback A pointer to a client supplied function that is responsible + for processing and filling input and output buffers. If this parameter is NULL + the stream will be opened in 'blocking read/write' mode. In blocking mode, + the client can receive sample data using Pa_ReadStream and write sample data + using Pa_WriteStream, the number of samples that may be read or written + without blocking is returned by Pa_GetStreamReadAvailable and + Pa_GetStreamWriteAvailable respectively. + + @param userData A client supplied pointer which is passed to the stream callback + function. It could for example, contain a pointer to instance data necessary + for processing the audio buffers. This parameter is ignored if streamCallback + is NULL. + + @return + Upon success Pa_OpenStream() returns paNoError and places a pointer to a + valid PaStream in the stream argument. The stream is inactive (stopped). + If a call to Pa_OpenStream() fails, a non-zero error code is returned (see + PaError for possible error codes) and the value of stream is invalid. + + @see PaStreamParameters, PaStreamCallback, Pa_ReadStream, Pa_WriteStream, + Pa_GetStreamReadAvailable, Pa_GetStreamWriteAvailable +*/ +PaError Pa_OpenStream( PaStream** stream, + const PaStreamParameters *inputParameters, + const PaStreamParameters *outputParameters, + double sampleRate, + unsigned long framesPerBuffer, + PaStreamFlags streamFlags, + PaStreamCallback *streamCallback, + void *userData ); + + +/** A simplified version of Pa_OpenStream() that opens the default input + and/or output devices. + + @param stream The address of a PaStream pointer which will receive + a pointer to the newly opened stream. + + @param numInputChannels The number of channels of sound that will be supplied + to the stream callback or returned by Pa_ReadStream. It can range from 1 to + the value of maxInputChannels in the PaDeviceInfo record for the default input + device. If 0 the stream is opened as an output-only stream. + + @param numOutputChannels The number of channels of sound to be delivered to the + stream callback or passed to Pa_WriteStream. It can range from 1 to the value + of maxOutputChannels in the PaDeviceInfo record for the default output dvice. + If 0 the stream is opened as an output-only stream. + + @param sampleFormat The sample format of both the input and output buffers + provided to the callback or passed to and from Pa_ReadStream and Pa_WriteStream. + sampleFormat may be any of the formats described by the PaSampleFormat + enumeration. + + @param sampleRate Same as Pa_OpenStream parameter of the same name. + @param framesPerBuffer Same as Pa_OpenStream parameter of the same name. + @param streamCallback Same as Pa_OpenStream parameter of the same name. + @param userData Same as Pa_OpenStream parameter of the same name. + + @return As for Pa_OpenStream + + @see Pa_OpenStream, PaStreamCallback +*/ +PaError Pa_OpenDefaultStream( PaStream** stream, + int numInputChannels, + int numOutputChannels, + PaSampleFormat sampleFormat, + double sampleRate, + unsigned long framesPerBuffer, + PaStreamCallback *streamCallback, + void *userData ); + + +/** Closes an audio stream. If the audio stream is active it + discards any pending buffers as if Pa_AbortStream() had been called. +*/ +PaError Pa_CloseStream( PaStream *stream ); + + +/** Functions of type PaStreamFinishedCallback are implemented by PortAudio + clients. They can be registered with a stream using the Pa_SetStreamFinishedCallback + function. Once registered they are called when the stream becomes inactive + (ie once a call to Pa_StopStream() will not block). + A stream will become inactive after the stream callback returns non-zero, + or when Pa_StopStream or Pa_AbortStream is called. For a stream providing audio + output, if the stream callback returns paComplete, or Pa_StopStream is called, + the stream finished callback will not be called until all generated sample data + has been played. + + @param userData The userData parameter supplied to Pa_OpenStream() + + @see Pa_SetStreamFinishedCallback +*/ +typedef void PaStreamFinishedCallback( void *userData ); + + +/** Register a stream finished callback function which will be called when the + stream becomes inactive. See the description of PaStreamFinishedCallback for + further details about when the callback will be called. + + @param stream a pointer to a PaStream that is in the stopped state - if the + stream is not stopped, the stream's finished callback will remain unchanged + and an error code will be returned. + + @param streamFinishedCallback a pointer to a function with the same signature + as PaStreamFinishedCallback, that will be called when the stream becomes + inactive. Passing NULL for this parameter will un-register a previously + registered stream finished callback function. + + @return on success returns paNoError, otherwise an error code indicating the cause + of the error. + + @see PaStreamFinishedCallback +*/ +PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback ); + + +/** Commences audio processing. +*/ +PaError Pa_StartStream( PaStream *stream ); + + +/** Terminates audio processing. It waits until all pending + audio buffers have been played before it returns. +*/ +PaError Pa_StopStream( PaStream *stream ); + + +/** Terminates audio processing immediately without waiting for pending + buffers to complete. +*/ +PaError Pa_AbortStream( PaStream *stream ); + + +/** Determine whether the stream is stopped. + A stream is considered to be stopped prior to a successful call to + Pa_StartStream and after a successful call to Pa_StopStream or Pa_AbortStream. + If a stream callback returns a value other than paContinue the stream is NOT + considered to be stopped. + + @return Returns one (1) when the stream is stopped, zero (0) when + the stream is running or, a PaErrorCode (which are always negative) if + PortAudio is not initialized or an error is encountered. + + @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive +*/ +PaError Pa_IsStreamStopped( PaStream *stream ); + + +/** Determine whether the stream is active. + A stream is active after a successful call to Pa_StartStream(), until it + becomes inactive either as a result of a call to Pa_StopStream() or + Pa_AbortStream(), or as a result of a return value other than paContinue from + the stream callback. In the latter case, the stream is considered inactive + after the last buffer has finished playing. + + @return Returns one (1) when the stream is active (ie playing or recording + audio), zero (0) when not playing or, a PaErrorCode (which are always negative) + if PortAudio is not initialized or an error is encountered. + + @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamStopped +*/ +PaError Pa_IsStreamActive( PaStream *stream ); + + + +/** A structure containing unchanging information about an open stream. + @see Pa_GetStreamInfo +*/ + +typedef struct PaStreamInfo +{ + /** this is struct version 1 */ + int structVersion; + + /** The input latency of the stream in seconds. This value provides the most + accurate estimate of input latency available to the implementation. It may + differ significantly from the suggestedLatency value passed to Pa_OpenStream(). + The value of this field will be zero (0.) for output-only streams. + @see PaTime + */ + PaTime inputLatency; + + /** The output latency of the stream in seconds. This value provides the most + accurate estimate of output latency available to the implementation. It may + differ significantly from the suggestedLatency value passed to Pa_OpenStream(). + The value of this field will be zero (0.) for input-only streams. + @see PaTime + */ + PaTime outputLatency; + + /** The sample rate of the stream in Hertz (samples per second). In cases + where the hardware sample rate is inaccurate and PortAudio is aware of it, + the value of this field may be different from the sampleRate parameter + passed to Pa_OpenStream(). If information about the actual hardware sample + rate is not available, this field will have the same value as the sampleRate + parameter passed to Pa_OpenStream(). + */ + double sampleRate; + +} PaStreamInfo; + + +/** Retrieve a pointer to a PaStreamInfo structure containing information + about the specified stream. + @return A pointer to an immutable PaStreamInfo structure. If the stream + parameter invalid, or an error is encountered, the function returns NULL. + + @param stream A pointer to an open stream previously created with Pa_OpenStream. + + @note PortAudio manages the memory referenced by the returned pointer, + the client must not manipulate or free the memory. The pointer is only + guaranteed to be valid until the specified stream is closed. + + @see PaStreamInfo +*/ +const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream ); + + +/** Determine the current time for the stream according to the same clock used + to generate buffer timestamps. This time may be used for syncronising other + events to the audio stream, for example synchronizing audio to MIDI. + + @return The stream's current time in seconds, or 0 if an error occurred. + + @see PaTime, PaStreamCallback +*/ +PaTime Pa_GetStreamTime( PaStream *stream ); + + +/** Retrieve CPU usage information for the specified stream. + The "CPU Load" is a fraction of total CPU time consumed by a callback stream's + audio processing routines including, but not limited to the client supplied + stream callback. This function does not work with blocking read/write streams. + + This function may be called from the stream callback function or the + application. + + @return + A floating point value, typically between 0.0 and 1.0, where 1.0 indicates + that the stream callback is consuming the maximum number of CPU cycles possible + to maintain real-time operation. A value of 0.5 would imply that PortAudio and + the stream callback was consuming roughly 50% of the available CPU time. The + return value may exceed 1.0. A value of 0.0 will always be returned for a + blocking read/write stream, or if an error occurrs. +*/ +double Pa_GetStreamCpuLoad( PaStream* stream ); + + +/** Read samples from an input stream. The function doesn't return until + the entire buffer has been filled - this may involve waiting for the operating + system to supply the data. + + @param stream A pointer to an open stream previously created with Pa_OpenStream. + + @param buffer A pointer to a buffer of sample frames. The buffer contains + samples in the format specified by the inputParameters->sampleFormat field + used to open the stream, and the number of channels specified by + inputParameters->numChannels. If non-interleaved samples were requested, + buffer is a pointer to the first element of an array of non-interleaved + buffer pointers, one for each channel. + + @param frames The number of frames to be read into buffer. This parameter + is not constrained to a specific range, however high performance applications + will want to match this parameter to the framesPerBuffer parameter used + when opening the stream. + + @return On success PaNoError will be returned, or PaInputOverflowed if input + data was discarded by PortAudio after the previous call and before this call. +*/ +PaError Pa_ReadStream( PaStream* stream, + void *buffer, + unsigned long frames ); + + +/** Write samples to an output stream. This function doesn't return until the + entire buffer has been consumed - this may involve waiting for the operating + system to consume the data. + + @param stream A pointer to an open stream previously created with Pa_OpenStream. + + @param buffer A pointer to a buffer of sample frames. The buffer contains + samples in the format specified by the outputParameters->sampleFormat field + used to open the stream, and the number of channels specified by + outputParameters->numChannels. If non-interleaved samples were requested, + buffer is a pointer to the first element of an array of non-interleaved + buffer pointers, one for each channel. + + @param frames The number of frames to be written from buffer. This parameter + is not constrained to a specific range, however high performance applications + will want to match this parameter to the framesPerBuffer parameter used + when opening the stream. + + @return On success PaNoError will be returned, or paOutputUnderflowed if + additional output data was inserted after the previous call and before this + call. +*/ +PaError Pa_WriteStream( PaStream* stream, + const void *buffer, + unsigned long frames ); + + +/** Retrieve the number of frames that can be read from the stream without + waiting. + + @return Returns a non-negative value representing the maximum number of frames + that can be read from the stream without blocking or busy waiting or, a + PaErrorCode (which are always negative) if PortAudio is not initialized or an + error is encountered. +*/ +signed long Pa_GetStreamReadAvailable( PaStream* stream ); + + +/** Retrieve the number of frames that can be written to the stream without + waiting. + + @return Returns a non-negative value representing the maximum number of frames + that can be written to the stream without blocking or busy waiting or, a + PaErrorCode (which are always negative) if PortAudio is not initialized or an + error is encountered. +*/ +signed long Pa_GetStreamWriteAvailable( PaStream* stream ); + + +/* Miscellaneous utilities */ + + +/** Retrieve the size of a given sample format in bytes. + + @return The size in bytes of a single sample in the specified format, + or paSampleFormatNotSupported if the format is not supported. +*/ +PaError Pa_GetSampleSize( PaSampleFormat format ); + + +/** Put the caller to sleep for at least 'msec' milliseconds. This function is + provided only as a convenience for authors of portable code (such as the tests + and examples in the PortAudio distribution.) + + The function may sleep longer than requested so don't rely on this for accurate + musical timing. +*/ +void Pa_Sleep( long msec ); + + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* PORTAUDIO_H */ diff --git a/lib/ft2/ptt.c b/lib/ft2/ptt.c index 05451d46..fdda4ff9 100755 --- a/lib/ft2/ptt.c +++ b/lib/ft2/ptt.c @@ -1,58 +1,58 @@ -#include -#include - -int ptt_(int *nport, int *ntx, int *ndtr, int *iptt) -{ - static HANDLE hFile; - static int open=0, nhold=0; - char s[10]; - int i3,i4,i5,i6,i9,i00; - - if(*nport==0) { - *iptt=*ntx; - return(0); - } - - nhold=0; - if(*nport>100) nhold=1; - - if(*ntx && (!open)) { - sprintf(s,"\\\\.\\COM%d",*nport%100); - 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%100); - return(-1); - } - open=1; - } - - if(*ntx && open) { - if(*ndtr) - EscapeCommFunction(hFile,5); //set DTR - else - EscapeCommFunction(hFile,3); //set RTS - *iptt=1; - } - - else { - if(*ndtr) - EscapeCommFunction(hFile,6); //clear DTR - else - EscapeCommFunction(hFile,4); //clear RTS - EscapeCommFunction(hFile,9); //clear BREAK - if(nhold==0) { - i00=CloseHandle(hFile); - open=0; - } - *iptt=0; - } - return(0); -} +#include +#include + +int ptt_(int *nport, int *ntx, int *ndtr, int *iptt) +{ + static HANDLE hFile; + static int open=0, nhold=0; + char s[10]; + int i3,i4,i5,i6,i9,i00; + + if(*nport==0) { + *iptt=*ntx; + return(0); + } + + nhold=0; + if(*nport>100) nhold=1; + + if(*ntx && (!open)) { + sprintf(s,"\\\\.\\COM%d",*nport%100); + 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%100); + return(-1); + } + open=1; + } + + if(*ntx && open) { + if(*ndtr) + EscapeCommFunction(hFile,5); //set DTR + else + EscapeCommFunction(hFile,3); //set RTS + *iptt=1; + } + + else { + if(*ndtr) + EscapeCommFunction(hFile,6); //clear DTR + else + EscapeCommFunction(hFile,4); //clear RTS + EscapeCommFunction(hFile,9); //clear BREAK + if(nhold==0) { + i00=CloseHandle(hFile); + open=0; + } + *iptt=0; + } + return(0); +} diff --git a/lib/ft2/ptt_unix.c b/lib/ft2/ptt_unix.c index 21eb52d3..b1638060 100755 --- a/lib/ft2/ptt_unix.c +++ b/lib/ft2/ptt_unix.c @@ -1,341 +1,341 @@ -#include -#include -#include -#include -#include -#include -//#include -//#include -//#include -//#include -//#include - -int lp_reset (int fd); -int lp_ptt (int fd, int onoff); - -#ifdef HAVE_SYS_STAT_H -# include -#endif -#if (defined(__unix__) || defined(unix)) && !defined(USG) -# include -#endif - -#include -/* 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 *ndtr, int *iptt) -{ - static int state=0; - char *p; - - /* 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(*ntx) { - ioctl(fd, TIOCMBIS, &control); /* Set DTR and RTS */ - *iptt = 1; - } else { - ioctl(fd, TIOCMBIC, &control); - *iptt = 0; - } - 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); -} +#include +#include +#include +#include +#include +#include +//#include +//#include +//#include +//#include +//#include + +int lp_reset (int fd); +int lp_ptt (int fd, int onoff); + +#ifdef HAVE_SYS_STAT_H +# include +#endif +#if (defined(__unix__) || defined(unix)) && !defined(USG) +# include +#endif + +#include +/* 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 *ndtr, int *iptt) +{ + static int state=0; + char *p; + + /* 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(*ntx) { + ioctl(fd, TIOCMBIS, &control); /* Set DTR and RTS */ + *iptt = 1; + } else { + ioctl(fd, TIOCMBIC, &control); + *iptt = 0; + } + 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/lib/ft4/clockit.f90 b/lib/ft4/clockit.f90 index 9315ae5d..eb3e7d8b 100755 --- a/lib/ft4/clockit.f90 +++ b/lib/ft4/clockit.f90 @@ -1,111 +1,111 @@ -subroutine clockit(dname,k) - -! Times procedure number n between a call with k=0 (tstart) and with -! k=1 (tstop). Accumulates sums of these times in array ut (user time). -! Also traces all calls (for debugging purposes) if limtrace.gt.0 - - character*8 dname,name(50),space,ename - character*16 sname - character*512 data_dir,fname - logical first,on(50) - real ut(50),ut0(50),dut(50),tt(2) - integer ncall(50),nlevel(50),nparent(50) - integer onlevel(0:10) - data first/.true./,eps/0.000001/,ntrace/0/ - data level/0/,nmax/0/,space/' '/ - data limtrace/0/,lu/29/,ntimer/1/ -! data limtrace/1000000/,lu/29/,ntimer/1/ - save - - if(ntimer.eq.0) return - if(lu.lt.1) lu=6 - if(k.gt.1) go to 40 !Check for "all done" (k>1) - onlevel(0)=0 - - do n=1,nmax !Check for existing name - if(name(n).eq.dname) go to 20 - enddo - - nmax=nmax+1 !This is a new one - n=nmax - ncall(n)=0 - on(n)=.false. - ut(n)=eps - name(n)=dname - -20 if(k.eq.0) then !Get start times (k=0) - if(on(n)) print*,'Error in timer: ',dname,' already on.' - level=level+1 !Increment the level - on(n)=.true. - ut0(n)=etime(tt) - ncall(n)=ncall(n)+1 - if(ncall(n).gt.1.and.nlevel(n).ne.level) then - nlevel(n)=-1 - else - nlevel(n)=level - endif - nparent(n)=onlevel(level-1) - onlevel(level)=n - - else if(k.eq.1) then !Get stop times and accumulate sums. (k=1) - if(on(n)) then - on(n)=.false. - ut1=etime(tt) - ut(n)=ut(n)+ut1-ut0(n) - endif - level=level-1 - endif - - ntrace=ntrace+1 - if(ntrace.lt.limtrace) write(28,1020) ntrace,dname,k,level,nparent(n) -1020 format(i8,': ',a8,3i5) - return - -! Write out the timer statistics - -40 open(lu,file=trim(fname),status='unknown') - write(lu,1040) -1040 format(/' name time frac dtime', & - ' dfrac calls level parent'/73('-')) - - if(k.gt.100) then - ndiv=k-100 - do i=1,nmax - ncall(i)=ncall(i)/ndiv - ut(i)=ut(i)/ndiv - enddo - endif - - total=ut(1) - sum=0. - sumf=0. - do i=1,nmax - dut(i)=ut(i) - do j=i,nmax - if(nparent(j).eq.i) dut(i)=dut(i)-ut(j) - enddo - utf=ut(i)/total - dutf=dut(i)/total - sum=sum+dut(i) - sumf=sumf+dutf - kk=nlevel(i) - sname=space(1:kk)//name(i)//space(1:8-kk) - ename=space - if(i.ge.2) ename=name(nparent(i)) - write(lu,1060) float(i),sname,ut(i),utf,dut(i),dutf, & - ncall(i),nlevel(i),ename -1060 format(f4.0,a16,2(f10.2,f6.2),i7,i5,2x,a8) - enddo - - write(lu,1070) sum,sumf -1070 format(/36x,f10.2,f6.2) - close(lu) - return - - entry clockit2(data_dir) - l1=index(data_dir,char(0))-1 - if(l1.ge.1) data_dir(l1+1:l1+1)='/' - fname=data_dir(1:l1+1)//'clockit.out' - return - -end subroutine clockit +subroutine clockit(dname,k) + +! Times procedure number n between a call with k=0 (tstart) and with +! k=1 (tstop). Accumulates sums of these times in array ut (user time). +! Also traces all calls (for debugging purposes) if limtrace.gt.0 + + character*8 dname,name(50),space,ename + character*16 sname + character*512 data_dir,fname + logical first,on(50) + real ut(50),ut0(50),dut(50),tt(2) + integer ncall(50),nlevel(50),nparent(50) + integer onlevel(0:10) + data first/.true./,eps/0.000001/,ntrace/0/ + data level/0/,nmax/0/,space/' '/ + data limtrace/0/,lu/29/,ntimer/1/ +! data limtrace/1000000/,lu/29/,ntimer/1/ + save + + if(ntimer.eq.0) return + if(lu.lt.1) lu=6 + if(k.gt.1) go to 40 !Check for "all done" (k>1) + onlevel(0)=0 + + do n=1,nmax !Check for existing name + if(name(n).eq.dname) go to 20 + enddo + + nmax=nmax+1 !This is a new one + n=nmax + ncall(n)=0 + on(n)=.false. + ut(n)=eps + name(n)=dname + +20 if(k.eq.0) then !Get start times (k=0) + if(on(n)) print*,'Error in timer: ',dname,' already on.' + level=level+1 !Increment the level + on(n)=.true. + ut0(n)=etime(tt) + ncall(n)=ncall(n)+1 + if(ncall(n).gt.1.and.nlevel(n).ne.level) then + nlevel(n)=-1 + else + nlevel(n)=level + endif + nparent(n)=onlevel(level-1) + onlevel(level)=n + + else if(k.eq.1) then !Get stop times and accumulate sums. (k=1) + if(on(n)) then + on(n)=.false. + ut1=etime(tt) + ut(n)=ut(n)+ut1-ut0(n) + endif + level=level-1 + endif + + ntrace=ntrace+1 + if(ntrace.lt.limtrace) write(28,1020) ntrace,dname,k,level,nparent(n) +1020 format(i8,': ',a8,3i5) + return + +! Write out the timer statistics + +40 open(lu,file=trim(fname),status='unknown') + write(lu,1040) +1040 format(/' name time frac dtime', & + ' dfrac calls level parent'/73('-')) + + if(k.gt.100) then + ndiv=k-100 + do i=1,nmax + ncall(i)=ncall(i)/ndiv + ut(i)=ut(i)/ndiv + enddo + endif + + total=ut(1) + sum=0. + sumf=0. + do i=1,nmax + dut(i)=ut(i) + do j=i,nmax + if(nparent(j).eq.i) dut(i)=dut(i)-ut(j) + enddo + utf=ut(i)/total + dutf=dut(i)/total + sum=sum+dut(i) + sumf=sumf+dutf + kk=nlevel(i) + sname=space(1:kk)//name(i)//space(1:8-kk) + ename=space + if(i.ge.2) ename=name(nparent(i)) + write(lu,1060) float(i),sname,ut(i),utf,dut(i),dutf, & + ncall(i),nlevel(i),ename +1060 format(f4.0,a16,2(f10.2,f6.2),i7,i5,2x,a8) + enddo + + write(lu,1070) sum,sumf +1070 format(/36x,f10.2,f6.2) + close(lu) + return + + entry clockit2(data_dir) + l1=index(data_dir,char(0))-1 + if(l1.ge.1) data_dir(l1+1:l1+1)='/' + fname=data_dir(1:l1+1)//'clockit.out' + return + +end subroutine clockit diff --git a/lib/ft4/ft4_downsample.f90 b/lib/ft4/ft4_downsample.f90 index d01986bd..a6305c83 100755 --- a/lib/ft4/ft4_downsample.f90 +++ b/lib/ft4/ft4_downsample.f90 @@ -1,48 +1,48 @@ -subroutine ft4_downsample(dd,newdata,f0,c) - - include 'ft4_params.f90' - parameter (NFFT2=NMAX/NDOWN) - real dd(NMAX) - complex c(0:NMAX/NDOWN-1) - complex c1(0:NFFT2-1) - complex cx(0:NMAX/2) - real x(NMAX), window(0:NFFT2-1) - equivalence (x,cx) - logical first, newdata - data first/.true./ - save first,window,x - - df=12000.0/NMAX - baud=12000.0/NSPS - if(first) then - bw_transition = 0.5*baud - bw_flat = 4*baud - iwt = bw_transition / df - iwf = bw_flat / df - pi=4.0*atan(1.0) - window(0:iwt-1) = 0.5*(1+cos(pi*(/(i,i=iwt-1,0,-1)/)/iwt)) - window(iwt:iwt+iwf-1)=1.0 - window(iwt+iwf:2*iwt+iwf-1) = 0.5*(1+cos(pi*(/(i,i=0,iwt-1)/)/iwt)) - window(2*iwt+iwf:)=0.0 - iws = baud / df - window=cshift(window,iws) - first=.false. - endif - - if(newdata) then - x=dd - call four2a(cx,NMAX,1,-1,0) !r2c FFT to freq domain - endif - i0=nint(f0/df) - c1=0. - if(i0.ge.0 .and. i0.le.NMAX/2) c1(0)=cx(i0) - do i=1,NFFT2/2 - if(i0+i.ge.0 .and. i0+i.le.NMAX/2) c1(i)=cx(i0+i) - if(i0-i.ge.0 .and. i0-i.le.NMAX/2) c1(NFFT2-i)=cx(i0-i) - enddo - c1=c1*window/NFFT2 - call four2a(c1,NFFT2,1,1,1) !c2c FFT back to time domain - c=c1(0:NMAX/NDOWN-1) - - return -end subroutine ft4_downsample +subroutine ft4_downsample(dd,newdata,f0,c) + + include 'ft4_params.f90' + parameter (NFFT2=NMAX/NDOWN) + real dd(NMAX) + complex c(0:NMAX/NDOWN-1) + complex c1(0:NFFT2-1) + complex cx(0:NMAX/2) + real x(NMAX), window(0:NFFT2-1) + equivalence (x,cx) + logical first, newdata + data first/.true./ + save first,window,x + + df=12000.0/NMAX + baud=12000.0/NSPS + if(first) then + bw_transition = 0.5*baud + bw_flat = 4*baud + iwt = bw_transition / df + iwf = bw_flat / df + pi=4.0*atan(1.0) + window(0:iwt-1) = 0.5*(1+cos(pi*(/(i,i=iwt-1,0,-1)/)/iwt)) + window(iwt:iwt+iwf-1)=1.0 + window(iwt+iwf:2*iwt+iwf-1) = 0.5*(1+cos(pi*(/(i,i=0,iwt-1)/)/iwt)) + window(2*iwt+iwf:)=0.0 + iws = baud / df + window=cshift(window,iws) + first=.false. + endif + + if(newdata) then + x=dd + call four2a(cx,NMAX,1,-1,0) !r2c FFT to freq domain + endif + i0=nint(f0/df) + c1=0. + if(i0.ge.0 .and. i0.le.NMAX/2) c1(0)=cx(i0) + do i=1,NFFT2/2 + if(i0+i.ge.0 .and. i0+i.le.NMAX/2) c1(i)=cx(i0+i) + if(i0-i.ge.0 .and. i0-i.le.NMAX/2) c1(NFFT2-i)=cx(i0-i) + enddo + c1=c1*window/NFFT2 + call four2a(c1,NFFT2,1,1,1) !c2c FFT back to time domain + c=c1(0:NMAX/NDOWN-1) + + return +end subroutine ft4_downsample diff --git a/lib/ft4/ft4_testmsg.f90 b/lib/ft4/ft4_testmsg.f90 index 3c00d6f6..0d700ead 100755 --- a/lib/ft4/ft4_testmsg.f90 +++ b/lib/ft4/ft4_testmsg.f90 @@ -1,50 +1,50 @@ - parameter (MAXTEST=75,NTEST=47) - character*37 testmsg(MAXTEST) - data testmsg(1:NTEST)/ & - "TNX BOB 73 GL", & ! 0.0 - "PA9XYZ 590003 IO91NP", & ! 0.2 - "G4ABC/P R 570007 JO22DB", & ! 0.2 - "K1ABC W9XYZ 6A WI", & ! 0.3 - "W9XYZ K1ABC R 17B EMA", & ! 0.3 - "123456789ABCDEF012", & ! 0.5 - "CQ K1ABC FN42", & ! 1. - "K1ABC W9XYZ EN37", & ! 1. - "W9XYZ K1ABC -11", & ! 1. - "K1ABC W9XYZ R-09", & ! 1. - "W9XYZ K1ABC RRR", & ! 1. - "K1ABC W9XYZ 73", & ! 1. - "K1ABC W9XYZ RR73", & ! 1. - "CQ FD K1ABC FN42", & ! 1. - "CQ TEST K1ABC/R FN42", & ! 1. - "K1ABC/R W9XYZ EN37", & ! 1. - "W9XYZ K1ABC/R R FN42", & ! 1. - "K1ABC/R W9XYZ RR73", & ! 1. - "CQ TEST K1ABC FN42", & ! 1. - "W9XYZ -11", & ! 1. - " W9XYZ R-09", & ! 1. - "CQ W9XYZ EN37", & ! 1. - " W9XYZ -11", & ! 1. - "W9XYZ R-09", & ! 1. - " KA1ABC", & ! 1. - "KA1ABC -11", & ! 1. - " KA1ABC R-17", & ! 1. - " KA1ABC 73", & ! 1. - "CQ G4ABC/P IO91", & ! 2. - "G4ABC/P PA9XYZ JO22", & ! 2. - "PA9XYZ G4ABC/P RR73", & ! 2. - "K1ABC W9XYZ 579 WI", & ! 3. - "W9XYZ K1ABC R 589 MA", & ! 3. - "K1ABC KA0DEF 559 MO", & ! 3. - "TU; KA0DEF K1ABC R 569 MA", & ! 3. - "KA1ABC G3AAA 529 0013", & ! 3. - "TU; G3AAA K1ABC R 559 MA", & ! 3. - "CQ KH1/KH7Z", & ! 4. - "CQ PJ4/K1ABC", & ! 4. - "PJ4/K1ABC ", & ! 4. - " PJ4/K1ABC RRR", & ! 4. - "PJ4/K1ABC 73", & ! 4. - " YW18FIFA", & ! 4. - "YW18FIFA RRR", & ! 4. - " YW18FIFA 73", & ! 4. - "CQ YW18FIFA", & ! 4. - " YW18FIFA RR73"/ + parameter (MAXTEST=75,NTEST=47) + character*37 testmsg(MAXTEST) + data testmsg(1:NTEST)/ & + "TNX BOB 73 GL", & ! 0.0 + "PA9XYZ 590003 IO91NP", & ! 0.2 + "G4ABC/P R 570007 JO22DB", & ! 0.2 + "K1ABC W9XYZ 6A WI", & ! 0.3 + "W9XYZ K1ABC R 17B EMA", & ! 0.3 + "123456789ABCDEF012", & ! 0.5 + "CQ K1ABC FN42", & ! 1. + "K1ABC W9XYZ EN37", & ! 1. + "W9XYZ K1ABC -11", & ! 1. + "K1ABC W9XYZ R-09", & ! 1. + "W9XYZ K1ABC RRR", & ! 1. + "K1ABC W9XYZ 73", & ! 1. + "K1ABC W9XYZ RR73", & ! 1. + "CQ FD K1ABC FN42", & ! 1. + "CQ TEST K1ABC/R FN42", & ! 1. + "K1ABC/R W9XYZ EN37", & ! 1. + "W9XYZ K1ABC/R R FN42", & ! 1. + "K1ABC/R W9XYZ RR73", & ! 1. + "CQ TEST K1ABC FN42", & ! 1. + "W9XYZ -11", & ! 1. + " W9XYZ R-09", & ! 1. + "CQ W9XYZ EN37", & ! 1. + " W9XYZ -11", & ! 1. + "W9XYZ R-09", & ! 1. + " KA1ABC", & ! 1. + "KA1ABC -11", & ! 1. + " KA1ABC R-17", & ! 1. + " KA1ABC 73", & ! 1. + "CQ G4ABC/P IO91", & ! 2. + "G4ABC/P PA9XYZ JO22", & ! 2. + "PA9XYZ G4ABC/P RR73", & ! 2. + "K1ABC W9XYZ 579 WI", & ! 3. + "W9XYZ K1ABC R 589 MA", & ! 3. + "K1ABC KA0DEF 559 MO", & ! 3. + "TU; KA0DEF K1ABC R 569 MA", & ! 3. + "KA1ABC G3AAA 529 0013", & ! 3. + "TU; G3AAA K1ABC R 559 MA", & ! 3. + "CQ KH1/KH7Z", & ! 4. + "CQ PJ4/K1ABC", & ! 4. + "PJ4/K1ABC ", & ! 4. + " PJ4/K1ABC RRR", & ! 4. + "PJ4/K1ABC 73", & ! 4. + " YW18FIFA", & ! 4. + "YW18FIFA RRR", & ! 4. + " YW18FIFA 73", & ! 4. + "CQ YW18FIFA", & ! 4. + " YW18FIFA RR73"/ diff --git a/lib/ft4/ft4code.f90 b/lib/ft4/ft4code.f90 index ac3d9892..1792d9a2 100755 --- a/lib/ft4/ft4code.f90 +++ b/lib/ft4/ft4code.f90 @@ -1,102 +1,102 @@ -program ft4code - -! Provides examples of message packing, LDPC(174,91) encoding, bit and -! symbol ordering, and other details of the FT8 protocol. - - use packjt77 - include 'ft4_params.f90' !Set various constants - include 'ft4_testmsg.f90' - parameter (NWAVE=NN*NSPS) - - character*37 msg,msgsent - character*77 c77 - character*9 comment - character bad*1,msgtype*18 - integer itone(NN) - integer*1 msgbits(77),rvec(77),codeword(174) - data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & - 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & - 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.1 .and. nargs.ne.3) then - print* - print*,'Program ft4code: Provides examples of message packing, ', & - 'LDPC(174,91) encoding,' - print*,'bit and symbol ordering, and other details of the FT4 protocol.' - print* - print*,'Usage: ft4code "message" # Results for specified message' - print*,' ft4code -t # Examples of all message types' - go to 999 - endif - - call getarg(1,msg) !Message to be transmitted - if(len(trim(msg)).eq.2 .and. msg(1:2).eq.'-t') then - nmsg=NTEST - else - call fmtmsg(msg,iz) !To upper case; collapse multiple blanks - nmsg=1 - endif - - write(*,1010) -1010 format(4x,'Message',31x,'Decoded',29x,'Err i3.n3'/100('-')) - - do imsg=1,nmsg - if(nmsg.gt.1) msg=testmsg(imsg) - -! Generate msgsent, msgbits, and itone - i3=-1 - n3=-1 - call pack77(msg,i3,n3,c77) - call genft4(msg,0,msgsent,msgbits,itone) - call encode174_91(msgbits,codeword) - msgtype="" - if(i3.eq.0) then - if(n3.eq.0) msgtype="Free text" - if(n3.eq.1) msgtype="DXpedition mode" - if(n3.eq.2) msgtype="EU VHF Contest" - if(n3.eq.3) msgtype="ARRL Field Day" - if(n3.eq.4) msgtype="ARRL Field Day" - if(n3.eq.5) msgtype="Telemetry" - if(n3.ge.6) msgtype="Undefined type" - endif - if(i3.eq.1) msgtype="Standard msg" - if(i3.eq.2) msgtype="EU VHF Contest" - if(i3.eq.3) msgtype="ARRL RTTY Roundup" - if(i3.eq.4) msgtype="Nonstandard calls" - if(i3.eq.5) msgtype="EU VHF Contest" - if(i3.ge.6) msgtype="Undefined msg type" - if(i3.ge.1) n3=-1 - bad=" " - comment=' ' - if(msg.ne.msgsent) bad="*" - if(n3.ge.0) then - write(*,1020) imsg,msg,msgsent,bad,i3,n3,msgtype,comment -1020 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',i1,1x,a18,1x,a9) - else - write(*,1022) imsg,msg,msgsent,bad,i3,msgtype,comment -1022 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',1x,1x,a18,1x,a9) - endif - enddo - - if(nmsg.eq.1) then - write(*,1030) ieor(msgbits,rvec) -1030 format(/'Source-encoded message before scrambling, 77 bits: ',/77i1) - write(*,1032) rvec -1032 format(/'Scrambling vector, 77 bits: ',/77i1) - write(*,1034) msgbits -1034 format(/'Source-encoded message after scrambling, 77 bits:'/77i1) - write(*,1036) codeword(78:91) -1036 format(/'14-bit CRC: ',/14i1) - write(*,1038) codeword(92:174) -1038 format(/'83 Parity bits: ',/83i1) - write(*,1040) 0,itone,0 -1040 format(/'Channel symbols (105 tones):'/ & - 'R Sync',13x,'Data',13x, & - ' Sync',13x,'Data',13x, & - ' Sync',13x,'Data',13x,' Sync R'/ & - i1,1x,4i1,1x,29i1,1x,4i1,1x,29i1,1x,4i1,1x,29i1,1x,4i1,i2) - endif - -999 end program ft4code +program ft4code + +! Provides examples of message packing, LDPC(174,91) encoding, bit and +! symbol ordering, and other details of the FT8 protocol. + + use packjt77 + include 'ft4_params.f90' !Set various constants + include 'ft4_testmsg.f90' + parameter (NWAVE=NN*NSPS) + + character*37 msg,msgsent + character*77 c77 + character*9 comment + character bad*1,msgtype*18 + integer itone(NN) + integer*1 msgbits(77),rvec(77),codeword(174) + data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & + 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & + 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.1 .and. nargs.ne.3) then + print* + print*,'Program ft4code: Provides examples of message packing, ', & + 'LDPC(174,91) encoding,' + print*,'bit and symbol ordering, and other details of the FT4 protocol.' + print* + print*,'Usage: ft4code "message" # Results for specified message' + print*,' ft4code -t # Examples of all message types' + go to 999 + endif + + call getarg(1,msg) !Message to be transmitted + if(len(trim(msg)).eq.2 .and. msg(1:2).eq.'-t') then + nmsg=NTEST + else + call fmtmsg(msg,iz) !To upper case; collapse multiple blanks + nmsg=1 + endif + + write(*,1010) +1010 format(4x,'Message',31x,'Decoded',29x,'Err i3.n3'/100('-')) + + do imsg=1,nmsg + if(nmsg.gt.1) msg=testmsg(imsg) + +! Generate msgsent, msgbits, and itone + i3=-1 + n3=-1 + call pack77(msg,i3,n3,c77) + call genft4(msg,0,msgsent,msgbits,itone) + call encode174_91(msgbits,codeword) + msgtype="" + if(i3.eq.0) then + if(n3.eq.0) msgtype="Free text" + if(n3.eq.1) msgtype="DXpedition mode" + if(n3.eq.2) msgtype="EU VHF Contest" + if(n3.eq.3) msgtype="ARRL Field Day" + if(n3.eq.4) msgtype="ARRL Field Day" + if(n3.eq.5) msgtype="Telemetry" + if(n3.ge.6) msgtype="Undefined type" + endif + if(i3.eq.1) msgtype="Standard msg" + if(i3.eq.2) msgtype="EU VHF Contest" + if(i3.eq.3) msgtype="ARRL RTTY Roundup" + if(i3.eq.4) msgtype="Nonstandard calls" + if(i3.eq.5) msgtype="EU VHF Contest" + if(i3.ge.6) msgtype="Undefined msg type" + if(i3.ge.1) n3=-1 + bad=" " + comment=' ' + if(msg.ne.msgsent) bad="*" + if(n3.ge.0) then + write(*,1020) imsg,msg,msgsent,bad,i3,n3,msgtype,comment +1020 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',i1,1x,a18,1x,a9) + else + write(*,1022) imsg,msg,msgsent,bad,i3,msgtype,comment +1022 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',1x,1x,a18,1x,a9) + endif + enddo + + if(nmsg.eq.1) then + write(*,1030) ieor(msgbits,rvec) +1030 format(/'Source-encoded message before scrambling, 77 bits: ',/77i1) + write(*,1032) rvec +1032 format(/'Scrambling vector, 77 bits: ',/77i1) + write(*,1034) msgbits +1034 format(/'Source-encoded message after scrambling, 77 bits:'/77i1) + write(*,1036) codeword(78:91) +1036 format(/'14-bit CRC: ',/14i1) + write(*,1038) codeword(92:174) +1038 format(/'83 Parity bits: ',/83i1) + write(*,1040) 0,itone,0 +1040 format(/'Channel symbols (105 tones):'/ & + 'R Sync',13x,'Data',13x, & + ' Sync',13x,'Data',13x, & + ' Sync',13x,'Data',13x,' Sync R'/ & + i1,1x,4i1,1x,29i1,1x,4i1,1x,29i1,1x,4i1,1x,29i1,1x,4i1,i2) + endif + +999 end program ft4code diff --git a/lib/ft4/ft4sim.f90 b/lib/ft4/ft4sim.f90 index e7df86e3..cef22303 100755 --- a/lib/ft4/ft4sim.f90 +++ b/lib/ft4/ft4sim.f90 @@ -1,125 +1,125 @@ -program ft4sim - -! Generate simulated signals for experimental "FT4" mode - - use wavhdr - use packjt77 - include 'ft4_params.f90' !Set various constants - type(hdr) h !Header for .wav file - character arg*12,fname*17 - character msg37*37,msgsent37*37 - character c77*77 - complex c0(0:NMAX-1) - complex c(0:NMAX-1) - real wave(NMAX) - integer itone(NN) - integer*1 msgbits(77) - integer*2 iwave(NMAX) !Generated full-length waveform - integer icos4(4) - data icos4/0,1,3,2/ - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.7) then - print*,'Usage: ft4sim "message" f0 DT fdop del nfiles snr' - print*,'Examples: ft4sim "CQ W9XYZ EN37" 1500 0.0 0.1 1.0 10 -15' - print*,' ft4sim "K1ABC W9XYZ R 539 WI" 1500 0.0 0.1 1.0 10 -15' - go to 999 - endif - call getarg(1,msg37) !Message to be transmitted - call getarg(2,arg) - read(arg,*) f0 !Frequency (only used for single-signal) - call getarg(3,arg) - read(arg,*) xdt !Time offset from nominal (s) - call getarg(4,arg) - read(arg,*) fspread !Watterson frequency spread (Hz) - call getarg(5,arg) - read(arg,*) delay !Watterson delay (ms) - call getarg(6,arg) - read(arg,*) nfiles !Number of files - call getarg(7,arg) - read(arg,*) snrdb !SNR_2500 - - nfiles=abs(nfiles) - twopi=8.0*atan(1.0) - fs=12000.0 !Sample rate (Hz) - dt=1.0/fs !Sample interval (s) - hmod=1.0 !Modulation index (0.5 is MSK, 1.0 is FSK) - tt=NSPS*dt !Duration of symbols (s) - baud=1.0/tt !Keying rate (baud) - txt=NZ2*dt !Transmission length (s) - - bandwidth_ratio=2500.0/(fs/2.0) - sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) - if(snrdb.gt.90.0) sig=1.0 - - ! Source-encode, then get itone() - i3=-1 - n3=-1 - call pack77(msg37,i3,n3,c77) - read(c77,'(77i1)') msgbits - call genft4(msg37,0,msgsent37,msgbits,itone) - write(*,*) - write(*,'(a9,a37,3x,a7,i1,a1,i1)') 'Message: ',msgsent37,'i3.n3: ',i3,'.',n3 - write(*,1000) f0,xdt,txt,snrdb -1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1) - write(*,*) - if(i3.eq.1) then - write(*,*) ' mycall hiscall hisgrid' - write(*,'(28i1,1x,i1,1x,28i1,1x,i1,1x,i1,1x,15i1,1x,3i1)') msgbits(1:77) - else - write(*,'(a14)') 'Message bits: ' - write(*,'(77i1)') msgbits - endif - write(*,*) - write(*,'(a17)') 'Channel symbols: ' - write(*,'(76i1)') itone - write(*,*) - - call sgran() - - fsample=12000.0 - icmplx=1 - call gen_ft4wave(itone,NN,NSPS,fsample,f0,c0,wave,icmplx,NMAX) - - k=nint((xdt+0.5)/dt)-NSPS - c0=cshift(c0,-k) - if(k.gt.0) c0(0:k-1)=0.0 - if(k.lt.0) c0(NMAX+k:NMAX-1)=0.0 - - do ifile=1,nfiles - c=c0 - if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c,NMAX,NZ,fs,delay,fspread) - c=sig*c - wave=real(c) - peak=maxval(abs(wave)) - nslots=1 - - if(snrdb.lt.90) then - do i=1,NMAX !Add gaussian noise at specified SNR - xnoise=gran() - wave(i)=wave(i) + xnoise - enddo - endif - - gain=100.0 - if(snrdb.lt.90.0) then - wave=gain*wave - else - datpk=maxval(abs(wave)) - fac=32766.9/datpk - wave=fac*wave - endif - if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." - iwave=nint(wave) - h=default_header(12000,NMAX) - write(fname,1102) ifile -1102 format('000000_',i6.6,'.wav') - open(10,file=fname,status='unknown',access='stream') - write(10) h,iwave !Save to *.wav file - close(10) - write(*,1110) ifile,xdt,f0,snrdb,fname -1110 format(i4,f7.2,f8.2,f7.1,2x,a17) - enddo - -999 end program ft4sim +program ft4sim + +! Generate simulated signals for experimental "FT4" mode + + use wavhdr + use packjt77 + include 'ft4_params.f90' !Set various constants + type(hdr) h !Header for .wav file + character arg*12,fname*17 + character msg37*37,msgsent37*37 + character c77*77 + complex c0(0:NMAX-1) + complex c(0:NMAX-1) + real wave(NMAX) + integer itone(NN) + integer*1 msgbits(77) + integer*2 iwave(NMAX) !Generated full-length waveform + integer icos4(4) + data icos4/0,1,3,2/ + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.7) then + print*,'Usage: ft4sim "message" f0 DT fdop del nfiles snr' + print*,'Examples: ft4sim "CQ W9XYZ EN37" 1500 0.0 0.1 1.0 10 -15' + print*,' ft4sim "K1ABC W9XYZ R 539 WI" 1500 0.0 0.1 1.0 10 -15' + go to 999 + endif + call getarg(1,msg37) !Message to be transmitted + call getarg(2,arg) + read(arg,*) f0 !Frequency (only used for single-signal) + call getarg(3,arg) + read(arg,*) xdt !Time offset from nominal (s) + call getarg(4,arg) + read(arg,*) fspread !Watterson frequency spread (Hz) + call getarg(5,arg) + read(arg,*) delay !Watterson delay (ms) + call getarg(6,arg) + read(arg,*) nfiles !Number of files + call getarg(7,arg) + read(arg,*) snrdb !SNR_2500 + + nfiles=abs(nfiles) + twopi=8.0*atan(1.0) + fs=12000.0 !Sample rate (Hz) + dt=1.0/fs !Sample interval (s) + hmod=1.0 !Modulation index (0.5 is MSK, 1.0 is FSK) + tt=NSPS*dt !Duration of symbols (s) + baud=1.0/tt !Keying rate (baud) + txt=NZ2*dt !Transmission length (s) + + bandwidth_ratio=2500.0/(fs/2.0) + sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + + ! Source-encode, then get itone() + i3=-1 + n3=-1 + call pack77(msg37,i3,n3,c77) + read(c77,'(77i1)') msgbits + call genft4(msg37,0,msgsent37,msgbits,itone) + write(*,*) + write(*,'(a9,a37,3x,a7,i1,a1,i1)') 'Message: ',msgsent37,'i3.n3: ',i3,'.',n3 + write(*,1000) f0,xdt,txt,snrdb +1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1) + write(*,*) + if(i3.eq.1) then + write(*,*) ' mycall hiscall hisgrid' + write(*,'(28i1,1x,i1,1x,28i1,1x,i1,1x,i1,1x,15i1,1x,3i1)') msgbits(1:77) + else + write(*,'(a14)') 'Message bits: ' + write(*,'(77i1)') msgbits + endif + write(*,*) + write(*,'(a17)') 'Channel symbols: ' + write(*,'(76i1)') itone + write(*,*) + + call sgran() + + fsample=12000.0 + icmplx=1 + call gen_ft4wave(itone,NN,NSPS,fsample,f0,c0,wave,icmplx,NMAX) + + k=nint((xdt+0.5)/dt)-NSPS + c0=cshift(c0,-k) + if(k.gt.0) c0(0:k-1)=0.0 + if(k.lt.0) c0(NMAX+k:NMAX-1)=0.0 + + do ifile=1,nfiles + c=c0 + if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c,NMAX,NZ,fs,delay,fspread) + c=sig*c + wave=real(c) + peak=maxval(abs(wave)) + nslots=1 + + if(snrdb.lt.90) then + do i=1,NMAX !Add gaussian noise at specified SNR + xnoise=gran() + wave(i)=wave(i) + xnoise + enddo + endif + + gain=100.0 + if(snrdb.lt.90.0) then + wave=gain*wave + else + datpk=maxval(abs(wave)) + fac=32766.9/datpk + wave=fac*wave + endif + if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." + iwave=nint(wave) + h=default_header(12000,NMAX) + write(fname,1102) ifile +1102 format('000000_',i6.6,'.wav') + open(10,file=fname,status='unknown',access='stream') + write(10) h,iwave !Save to *.wav file + close(10) + write(*,1110) ifile,xdt,f0,snrdb,fname +1110 format(i4,f7.2,f8.2,f7.1,2x,a17) + enddo + +999 end program ft4sim diff --git a/lib/ft4/ft4sim_mult.f90 b/lib/ft4/ft4sim_mult.f90 index 3eae91dc..d93978e5 100755 --- a/lib/ft4/ft4sim_mult.f90 +++ b/lib/ft4/ft4sim_mult.f90 @@ -1,103 +1,103 @@ -program ft4sim_mult - -! Generate simulated signals for experimental "FT4" mode - - use wavhdr - use packjt77 - include 'ft4_params.f90' !FT4 protocol constants - parameter (NWAVE=NN*NSPS) - parameter (NZZ=72576) !Length of .wav file (21*3456) - type(hdr) h !Header for .wav file - character arg*12,fname*17,cjunk*4 - character msg37*37,msgsent37*37,c77*77 - complex cwave0((NN+2)*NSPS) - real wave0((NN+2)*NSPS) - real wave(NZZ) - real tmp(NZZ) - integer itone(NN) - integer*1 msgbits(77) - integer*2 iwave(NZZ) !Generated full-length waveform - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.2) then - print*,'Usage: ft4sim_mult nsigs nfiles' - print*,'Example: ft4sim_mult 20 8 ' - go to 999 - endif - call getarg(1,arg) - read(arg,*) nsigs !Number of signals - call getarg(2,arg) - read(arg,*) nfiles !Number of files - - twopi=8.0*atan(1.0) - fs=12000.0 !Sample rate (Hz) - dt=1.0/fs !Sample interval (s) - hmod=1.0 !Modulation index (0.5 is MSK, 1.0 is FSK) - tt=NSPS*dt !Duration of unsmoothed symbols (s) - baud=1.0/tt !Keying rate (baud) - txt=NZ*dt !Transmission length (s) without ramp up/down - bandwidth_ratio=2500.0/(fs/2.0) - txt=NN*NSPS/12000.0 - open(10,file='messages.txt',status='old',err=998) - - do ifile=1,nfiles -1 read(10,1001,end=999) cjunk,n -1001 format(a4,i2) - if(cjunk.ne.'File' .or. n.ne.ifile) go to 1 - wave=0. - write(fname,1002) ifile -1002 format('000000_',i6.6,'.wav') - - do isig=1,nsigs - read(10,1003,end=100) cjunk,isnr,xdt0,ifreq,msg37 -1003 format(a4,30x,i3,f5.1,i5,1x,a37) - if(cjunk.eq.'File') go to 100 - if(isnr.lt.-17) isnr=-17 - f0=ifreq*960.0/576.0 - call random_number(r) - xdt=r-0.5 -! Source-encode, then get itone() - i3=-1 - n3=-1 - call pack77(msg37,i3,n3,c77) - call genft4(msg37,0,msgsent37,msgbits,itone) - nwave0=(NN+2)*NSPS - icmplx=0 - call gen_ft4wave(itone,NN,NSPS,12000.0,f0,cwave0,wave0,icmplx,nwave0) - - k0=nint((xdt+0.5)/dt) - if(k0.lt.1) k0=1 - tmp(:k0-1)=0.0 - tmp(k0:k0+nwave0-1)=wave0 - tmp(k0+nwave0:)=0.0 - - ! Insert this signal into wave() array - sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*isnr) - wave=wave + sig*tmp - write(*,1100) fname(1:13),isig,isnr,xdt,nint(f0),msg37 -1100 format(a13,i4,i5,f5.1,i6,2x,a37) - enddo ! isig - -100 backspace 10 - - do i=1,NZZ !Add gaussian noise at specified SNR - xnoise=gran() - wave(i)=wave(i) + xnoise - enddo - - gain=30.0 - wave=gain*wave - if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." - iwave=nint(wave) - h=default_header(12000,NZZ) - open(12,file=fname,status='unknown',access='stream') - write(12) h,iwave !Save to *.wav file - close(12) - print*,' ' - enddo ! ifile - go to 999 - -998 print*,'Cannot open file "messages.txt"' - -999 end program ft4sim_mult +program ft4sim_mult + +! Generate simulated signals for experimental "FT4" mode + + use wavhdr + use packjt77 + include 'ft4_params.f90' !FT4 protocol constants + parameter (NWAVE=NN*NSPS) + parameter (NZZ=72576) !Length of .wav file (21*3456) + type(hdr) h !Header for .wav file + character arg*12,fname*17,cjunk*4 + character msg37*37,msgsent37*37,c77*77 + complex cwave0((NN+2)*NSPS) + real wave0((NN+2)*NSPS) + real wave(NZZ) + real tmp(NZZ) + integer itone(NN) + integer*1 msgbits(77) + integer*2 iwave(NZZ) !Generated full-length waveform + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.2) then + print*,'Usage: ft4sim_mult nsigs nfiles' + print*,'Example: ft4sim_mult 20 8 ' + go to 999 + endif + call getarg(1,arg) + read(arg,*) nsigs !Number of signals + call getarg(2,arg) + read(arg,*) nfiles !Number of files + + twopi=8.0*atan(1.0) + fs=12000.0 !Sample rate (Hz) + dt=1.0/fs !Sample interval (s) + hmod=1.0 !Modulation index (0.5 is MSK, 1.0 is FSK) + tt=NSPS*dt !Duration of unsmoothed symbols (s) + baud=1.0/tt !Keying rate (baud) + txt=NZ*dt !Transmission length (s) without ramp up/down + bandwidth_ratio=2500.0/(fs/2.0) + txt=NN*NSPS/12000.0 + open(10,file='messages.txt',status='old',err=998) + + do ifile=1,nfiles +1 read(10,1001,end=999) cjunk,n +1001 format(a4,i2) + if(cjunk.ne.'File' .or. n.ne.ifile) go to 1 + wave=0. + write(fname,1002) ifile +1002 format('000000_',i6.6,'.wav') + + do isig=1,nsigs + read(10,1003,end=100) cjunk,isnr,xdt0,ifreq,msg37 +1003 format(a4,30x,i3,f5.1,i5,1x,a37) + if(cjunk.eq.'File') go to 100 + if(isnr.lt.-17) isnr=-17 + f0=ifreq*960.0/576.0 + call random_number(r) + xdt=r-0.5 +! Source-encode, then get itone() + i3=-1 + n3=-1 + call pack77(msg37,i3,n3,c77) + call genft4(msg37,0,msgsent37,msgbits,itone) + nwave0=(NN+2)*NSPS + icmplx=0 + call gen_ft4wave(itone,NN,NSPS,12000.0,f0,cwave0,wave0,icmplx,nwave0) + + k0=nint((xdt+0.5)/dt) + if(k0.lt.1) k0=1 + tmp(:k0-1)=0.0 + tmp(k0:k0+nwave0-1)=wave0 + tmp(k0+nwave0:)=0.0 + + ! Insert this signal into wave() array + sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*isnr) + wave=wave + sig*tmp + write(*,1100) fname(1:13),isig,isnr,xdt,nint(f0),msg37 +1100 format(a13,i4,i5,f5.1,i6,2x,a37) + enddo ! isig + +100 backspace 10 + + do i=1,NZZ !Add gaussian noise at specified SNR + xnoise=gran() + wave(i)=wave(i) + xnoise + enddo + + gain=30.0 + wave=gain*wave + if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." + iwave=nint(wave) + h=default_header(12000,NZZ) + open(12,file=fname,status='unknown',access='stream') + write(12) h,iwave !Save to *.wav file + close(12) + print*,' ' + enddo ! ifile + go to 999 + +998 print*,'Cannot open file "messages.txt"' + +999 end program ft4sim_mult diff --git a/lib/ft4/gen_ft4wave.f90 b/lib/ft4/gen_ft4wave.f90 index 23536bc2..13018242 100755 --- a/lib/ft4/gen_ft4wave.f90 +++ b/lib/ft4/gen_ft4wave.f90 @@ -1,66 +1,66 @@ -subroutine gen_ft4wave(itone,nsym,nsps,fsample,f0,cwave,wave,icmplx,nwave) - - real wave(nwave) - complex cwave(nwave) - real pulse(6912) !576*4*3 - real dphi(0:250000-1) - integer itone(nsym) - logical first - data first/.true./ - save pulse,first,twopi,dt,hmod - - if(first) then - twopi=8.0*atan(1.0) - dt=1.0/fsample - hmod=1.0 -! Compute the smoothed frequency-deviation pulse - do i=1,3*nsps - tt=(i-1.5*nsps)/real(nsps) - pulse(i)=gfsk_pulse(1.0,tt) - enddo - first=.false. - endif - -! Compute the smoothed frequency waveform. -! Length = (nsym+2)*nsps samples, zero-padded - dphi_peak=twopi*hmod/real(nsps) - dphi=0.0 - do j=1,nsym - ib=(j-1)*nsps - ie=ib+3*nsps-1 - dphi(ib:ie) = dphi(ib:ie) + dphi_peak*pulse(1:3*nsps)*itone(j) - enddo - -! Calculate and insert the audio waveform - phi=0.0 - dphi = dphi + twopi*f0*dt !Shift frequency up by f0 - wave=0. - if(icmplx.eq.1) cwave=0. - k=0 - do j=0,(nsym+2)*nsps-1 - k=k+1 - if(icmplx.eq.0) then - wave(k)=sin(phi) - else - cwave(k)=cmplx(cos(phi),sin(phi)) - endif - phi=mod(phi+dphi(j),twopi) - enddo - -! Compute the ramp-up and ramp-down symbols - if(icmplx.eq.0) then - wave(1:nsps)=wave(1:nsps) * & - (1.0-cos(twopi*(/(i,i=0,nsps-1)/)/(2.0*nsps)))/2.0 - k1=(nsym+1)*nsps+1 - wave(k1:k1+nsps-1)=wave(k1:k1+nsps-1) * & - (1.0+cos(twopi*(/(i,i=0,nsps-1)/)/(2.0*nsps)))/2.0 - else - cwave(1:nsps)=cwave(1:nsps) * & - (1.0-cos(twopi*(/(i,i=0,nsps-1)/)/(2.0*nsps)))/2.0 - k1=(nsym+1)*nsps+1 - cwave(k1:k1+nsps-1)=cwave(k1:k1+nsps-1) * & - (1.0+cos(twopi*(/(i,i=0,nsps-1)/)/(2.0*nsps)))/2.0 - endif - - return -end subroutine gen_ft4wave +subroutine gen_ft4wave(itone,nsym,nsps,fsample,f0,cwave,wave,icmplx,nwave) + + real wave(nwave) + complex cwave(nwave) + real pulse(6912) !576*4*3 + real dphi(0:250000-1) + integer itone(nsym) + logical first + data first/.true./ + save pulse,first,twopi,dt,hmod + + if(first) then + twopi=8.0*atan(1.0) + dt=1.0/fsample + hmod=1.0 +! Compute the smoothed frequency-deviation pulse + do i=1,3*nsps + tt=(i-1.5*nsps)/real(nsps) + pulse(i)=gfsk_pulse(1.0,tt) + enddo + first=.false. + endif + +! Compute the smoothed frequency waveform. +! Length = (nsym+2)*nsps samples, zero-padded + dphi_peak=twopi*hmod/real(nsps) + dphi=0.0 + do j=1,nsym + ib=(j-1)*nsps + ie=ib+3*nsps-1 + dphi(ib:ie) = dphi(ib:ie) + dphi_peak*pulse(1:3*nsps)*itone(j) + enddo + +! Calculate and insert the audio waveform + phi=0.0 + dphi = dphi + twopi*f0*dt !Shift frequency up by f0 + wave=0. + if(icmplx.eq.1) cwave=0. + k=0 + do j=0,(nsym+2)*nsps-1 + k=k+1 + if(icmplx.eq.0) then + wave(k)=sin(phi) + else + cwave(k)=cmplx(cos(phi),sin(phi)) + endif + phi=mod(phi+dphi(j),twopi) + enddo + +! Compute the ramp-up and ramp-down symbols + if(icmplx.eq.0) then + wave(1:nsps)=wave(1:nsps) * & + (1.0-cos(twopi*(/(i,i=0,nsps-1)/)/(2.0*nsps)))/2.0 + k1=(nsym+1)*nsps+1 + wave(k1:k1+nsps-1)=wave(k1:k1+nsps-1) * & + (1.0+cos(twopi*(/(i,i=0,nsps-1)/)/(2.0*nsps)))/2.0 + else + cwave(1:nsps)=cwave(1:nsps) * & + (1.0-cos(twopi*(/(i,i=0,nsps-1)/)/(2.0*nsps)))/2.0 + k1=(nsym+1)*nsps+1 + cwave(k1:k1+nsps-1)=cwave(k1:k1+nsps-1) * & + (1.0+cos(twopi*(/(i,i=0,nsps-1)/)/(2.0*nsps)))/2.0 + endif + + return +end subroutine gen_ft4wave diff --git a/lib/ft4/genft4.f90 b/lib/ft4/genft4.f90 index 96e8d7dc..66e70a61 100755 --- a/lib/ft4/genft4.f90 +++ b/lib/ft4/genft4.f90 @@ -1,90 +1,90 @@ -subroutine genft4(msg0,ichk,msgsent,msgbits,i4tone) - -! Encode an FT4 message -! Input: -! - msg0 requested message to be transmitted -! - ichk if ichk=1, return only msgsent -! - msgsent message as it will be decoded -! - i4tone array of audio tone values, {0,1,2,3} - -! Frame structure: -! s16 + 87symbols + 2 ramp up/down = 105 total channel symbols -! r1 + s4 + d29 + s4 + d29 + s4 + d29 + s4 + r1 - -! Message duration: TxT = 105*576/12000 = 5.04 s - -! use iso_c_binding, only: c_loc,c_size_t - - use packjt77 - include 'ft4_params.f90' - character*37 msg0 - character*37 message !Message to be generated - character*37 msgsent !Message as it will be received - character*77 c77 - integer*4 i4tone(NN),itmp(ND) - integer*1 codeword(2*ND) - integer*1 msgbits(77),rvec(77) - integer icos4a(4),icos4b(4),icos4c(4),icos4d(4) - logical unpk77_success - data icos4a/0,1,3,2/ - data icos4b/1,0,2,3/ - data icos4c/2,3,1,0/ - data icos4d/3,2,0,1/ - data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & - 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & - 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ - message=msg0 - - do i=1, 37 - if(ichar(message(i:i)).eq.0) then - message(i:37)=' ' - exit - endif - enddo - do i=1,37 !Strip leading blanks - if(message(1:1).ne.' ') exit - message=message(i+1:) - enddo - - i3=-1 - n3=-1 - call pack77(message,i3,n3,c77) - call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent - - if(ichk.eq.1) go to 999 - read(c77,'(77i1)',err=1) msgbits - if(unpk77_success) go to 2 -1 msgbits=0 - itone=0 - msgsent='*** bad message *** ' - go to 999 - -entry get_ft4_tones_from_77bits(msgbits,i4tone) - -2 msgbits=mod(msgbits+rvec,2) - call encode174_91(msgbits,codeword) - -! Grayscale mapping: -! bits tone -! 00 0 -! 01 1 -! 11 2 -! 10 3 - - do i=1,ND - is=codeword(2*i)+2*codeword(2*i-1) - if(is.le.1) itmp(i)=is - if(is.eq.2) itmp(i)=3 - if(is.eq.3) itmp(i)=2 - enddo - - i4tone(1:4)=icos4a - i4tone(5:33)=itmp(1:29) - i4tone(34:37)=icos4b - i4tone(38:66)=itmp(30:58) - i4tone(67:70)=icos4c - i4tone(71:99)=itmp(59:87) - i4tone(100:103)=icos4d - -999 return -end subroutine genft4 +subroutine genft4(msg0,ichk,msgsent,msgbits,i4tone) + +! Encode an FT4 message +! Input: +! - msg0 requested message to be transmitted +! - ichk if ichk=1, return only msgsent +! - msgsent message as it will be decoded +! - i4tone array of audio tone values, {0,1,2,3} + +! Frame structure: +! s16 + 87symbols + 2 ramp up/down = 105 total channel symbols +! r1 + s4 + d29 + s4 + d29 + s4 + d29 + s4 + r1 + +! Message duration: TxT = 105*576/12000 = 5.04 s + +! use iso_c_binding, only: c_loc,c_size_t + + use packjt77 + include 'ft4_params.f90' + character*37 msg0 + character*37 message !Message to be generated + character*37 msgsent !Message as it will be received + character*77 c77 + integer*4 i4tone(NN),itmp(ND) + integer*1 codeword(2*ND) + integer*1 msgbits(77),rvec(77) + integer icos4a(4),icos4b(4),icos4c(4),icos4d(4) + logical unpk77_success + data icos4a/0,1,3,2/ + data icos4b/1,0,2,3/ + data icos4c/2,3,1,0/ + data icos4d/3,2,0,1/ + data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & + 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & + 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ + message=msg0 + + do i=1, 37 + if(ichar(message(i:i)).eq.0) then + message(i:37)=' ' + exit + endif + enddo + do i=1,37 !Strip leading blanks + if(message(1:1).ne.' ') exit + message=message(i+1:) + enddo + + i3=-1 + n3=-1 + call pack77(message,i3,n3,c77) + call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent + + if(ichk.eq.1) go to 999 + read(c77,'(77i1)',err=1) msgbits + if(unpk77_success) go to 2 +1 msgbits=0 + itone=0 + msgsent='*** bad message *** ' + go to 999 + +entry get_ft4_tones_from_77bits(msgbits,i4tone) + +2 msgbits=mod(msgbits+rvec,2) + call encode174_91(msgbits,codeword) + +! Grayscale mapping: +! bits tone +! 00 0 +! 01 1 +! 11 2 +! 10 3 + + do i=1,ND + is=codeword(2*i)+2*codeword(2*i-1) + if(is.le.1) itmp(i)=is + if(is.eq.2) itmp(i)=3 + if(is.eq.3) itmp(i)=2 + enddo + + i4tone(1:4)=icos4a + i4tone(5:33)=itmp(1:29) + i4tone(34:37)=icos4b + i4tone(38:66)=itmp(30:58) + i4tone(67:70)=icos4c + i4tone(71:99)=itmp(59:87) + i4tone(100:103)=icos4d + +999 return +end subroutine genft4 diff --git a/lib/ft4/get_ft4_bitmetrics.f90 b/lib/ft4/get_ft4_bitmetrics.f90 index 5c78193b..9c8a4ab4 100755 --- a/lib/ft4/get_ft4_bitmetrics.f90 +++ b/lib/ft4/get_ft4_bitmetrics.f90 @@ -1,116 +1,116 @@ -subroutine get_ft4_bitmetrics(cd,bitmetrics,badsync) - - include 'ft4_params.f90' - parameter (NSS=NSPS/NDOWN,NDMAX=NMAX/NDOWN) - complex cd(0:NN*NSS-1) - complex cs(0:3,NN) - complex csymb(NSS) - integer icos4a(0:3),icos4b(0:3),icos4c(0:3),icos4d(0:3) - integer graymap(0:3) - integer ip(1) - logical one(0:255,0:7) ! 256 4-symbol sequences, 8 bits - logical first - logical badsync - real bitmetrics(2*NN,3) - real s2(0:255) - real s4(0:3,NN) - - data icos4a/0,1,3,2/ - data icos4b/1,0,2,3/ - data icos4c/2,3,1,0/ - data icos4d/3,2,0,1/ - data graymap/0,1,3,2/ - data first/.true./ - save first,one - - if(first) then - one=.false. - do i=0,255 - do j=0,7 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - first=.false. - endif - - do k=1,NN - i1=(k-1)*NSS - csymb=cd(i1:i1+NSS-1) - call four2a(csymb,NSS,1,-1,1) - cs(0:3,k)=csymb(1:4) - s4(0:3,k)=abs(csymb(1:4)) - enddo - -! Sync quality check - is1=0 - is2=0 - is3=0 - is4=0 - badsync=.false. - ibmax=0 - - do k=1,4 - ip=maxloc(s4(:,k)) - if(icos4a(k-1).eq.(ip(1)-1)) is1=is1+1 - ip=maxloc(s4(:,k+33)) - if(icos4b(k-1).eq.(ip(1)-1)) is2=is2+1 - ip=maxloc(s4(:,k+66)) - if(icos4c(k-1).eq.(ip(1)-1)) is3=is3+1 - ip=maxloc(s4(:,k+99)) - if(icos4d(k-1).eq.(ip(1)-1)) is4=is4+1 - enddo - nsync=is1+is2+is3+is4 !Number of correct hard sync symbols, 0-16 - if(nsync .lt. 8) then - badsync=.true. - return - endif - - do nseq=1,3 !Try coherent sequences of 1, 2, and 4 symbols - if(nseq.eq.1) nsym=1 - if(nseq.eq.2) nsym=2 - if(nseq.eq.3) nsym=4 - nt=2**(2*nsym) - do ks=1,NN-nsym+1,nsym !87+16=103 symbols. - amax=-1.0 - do i=0,nt-1 - i1=i/64 - i2=iand(i,63)/16 - i3=iand(i,15)/4 - i4=iand(i,3) - if(nsym.eq.1) then - s2(i)=abs(cs(graymap(i4),ks)) - elseif(nsym.eq.2) then - s2(i)=abs(cs(graymap(i3),ks)+cs(graymap(i4),ks+1)) - elseif(nsym.eq.4) then - s2(i)=abs(cs(graymap(i1),ks ) + & - cs(graymap(i2),ks+1) + & - cs(graymap(i3),ks+2) + & - cs(graymap(i4),ks+3) & - ) - else - print*,"Error - nsym must be 1, 2, or 4." - endif - enddo - ipt=1+(ks-1)*2 - if(nsym.eq.1) ibmax=1 - if(nsym.eq.2) ibmax=3 - if(nsym.eq.4) ibmax=7 - do ib=0,ibmax - bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) - if(ipt+ib.gt.2*NN) cycle - bitmetrics(ipt+ib,nseq)=bm - enddo - enddo - enddo - - bitmetrics(205:206,2)=bitmetrics(205:206,1) - bitmetrics(201:204,3)=bitmetrics(201:204,2) - bitmetrics(205:206,3)=bitmetrics(205:206,1) - - call normalizebmet(bitmetrics(:,1),2*NN) - call normalizebmet(bitmetrics(:,2),2*NN) - call normalizebmet(bitmetrics(:,3),2*NN) - return - -end subroutine get_ft4_bitmetrics +subroutine get_ft4_bitmetrics(cd,bitmetrics,badsync) + + include 'ft4_params.f90' + parameter (NSS=NSPS/NDOWN,NDMAX=NMAX/NDOWN) + complex cd(0:NN*NSS-1) + complex cs(0:3,NN) + complex csymb(NSS) + integer icos4a(0:3),icos4b(0:3),icos4c(0:3),icos4d(0:3) + integer graymap(0:3) + integer ip(1) + logical one(0:255,0:7) ! 256 4-symbol sequences, 8 bits + logical first + logical badsync + real bitmetrics(2*NN,3) + real s2(0:255) + real s4(0:3,NN) + + data icos4a/0,1,3,2/ + data icos4b/1,0,2,3/ + data icos4c/2,3,1,0/ + data icos4d/3,2,0,1/ + data graymap/0,1,3,2/ + data first/.true./ + save first,one + + if(first) then + one=.false. + do i=0,255 + do j=0,7 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + first=.false. + endif + + do k=1,NN + i1=(k-1)*NSS + csymb=cd(i1:i1+NSS-1) + call four2a(csymb,NSS,1,-1,1) + cs(0:3,k)=csymb(1:4) + s4(0:3,k)=abs(csymb(1:4)) + enddo + +! Sync quality check + is1=0 + is2=0 + is3=0 + is4=0 + badsync=.false. + ibmax=0 + + do k=1,4 + ip=maxloc(s4(:,k)) + if(icos4a(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s4(:,k+33)) + if(icos4b(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s4(:,k+66)) + if(icos4c(k-1).eq.(ip(1)-1)) is3=is3+1 + ip=maxloc(s4(:,k+99)) + if(icos4d(k-1).eq.(ip(1)-1)) is4=is4+1 + enddo + nsync=is1+is2+is3+is4 !Number of correct hard sync symbols, 0-16 + if(nsync .lt. 8) then + badsync=.true. + return + endif + + do nseq=1,3 !Try coherent sequences of 1, 2, and 4 symbols + if(nseq.eq.1) nsym=1 + if(nseq.eq.2) nsym=2 + if(nseq.eq.3) nsym=4 + nt=2**(2*nsym) + do ks=1,NN-nsym+1,nsym !87+16=103 symbols. + amax=-1.0 + do i=0,nt-1 + i1=i/64 + i2=iand(i,63)/16 + i3=iand(i,15)/4 + i4=iand(i,3) + if(nsym.eq.1) then + s2(i)=abs(cs(graymap(i4),ks)) + elseif(nsym.eq.2) then + s2(i)=abs(cs(graymap(i3),ks)+cs(graymap(i4),ks+1)) + elseif(nsym.eq.4) then + s2(i)=abs(cs(graymap(i1),ks ) + & + cs(graymap(i2),ks+1) + & + cs(graymap(i3),ks+2) + & + cs(graymap(i4),ks+3) & + ) + else + print*,"Error - nsym must be 1, 2, or 4." + endif + enddo + ipt=1+(ks-1)*2 + if(nsym.eq.1) ibmax=1 + if(nsym.eq.2) ibmax=3 + if(nsym.eq.4) ibmax=7 + do ib=0,ibmax + bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) + if(ipt+ib.gt.2*NN) cycle + bitmetrics(ipt+ib,nseq)=bm + enddo + enddo + enddo + + bitmetrics(205:206,2)=bitmetrics(205:206,1) + bitmetrics(201:204,3)=bitmetrics(201:204,2) + bitmetrics(205:206,3)=bitmetrics(205:206,1) + + call normalizebmet(bitmetrics(:,1),2*NN) + call normalizebmet(bitmetrics(:,2),2*NN) + call normalizebmet(bitmetrics(:,3),2*NN) + return + +end subroutine get_ft4_bitmetrics diff --git a/lib/ft4/getcandidates4.f90 b/lib/ft4/getcandidates4.f90 index 8e9fbd03..8ff80642 100755 --- a/lib/ft4/getcandidates4.f90 +++ b/lib/ft4/getcandidates4.f90 @@ -1,83 +1,83 @@ -subroutine getcandidates4(dd,fa,fb,syncmin,nfqso,maxcand,savg,candidate, & - ncand,sbase) - - include 'ft4_params.f90' - real s(NH1,NHSYM) - real savg(NH1),savsm(NH1) - real sbase(NH1) - real x(NFFT1) - real window(NFFT1) - complex cx(0:NH1) - real candidate(2,maxcand),candidatet(2,maxcand) - real dd(NMAX) - equivalence (x,cx) - logical first - data first/.true./ - save first,window - - if(first) then - first=.false. - pi=4.0*atan(1.) - window=0. - call nuttal_window(window,NFFT1) - endif - -! Compute symbol spectra, stepping by NSTEP steps. - savg=0. - df=12000.0/NFFT1 - fac=1.0/300.0 - do j=1,NHSYM - ia=(j-1)*NSTEP + 1 - ib=ia+NFFT1-1 - if(ib.gt.NMAX) exit - x=fac*dd(ia:ib)*window - call four2a(x,NFFT1,1,-1,0) !r2c FFT - s(1:NH1,j)=abs(cx(1:NH1))**2 - savg=savg + s(1:NH1,j) !Average spectrum - enddo - savg=savg/NHSYM - savsm=0. - do i=8,NH1-7 - savsm(i)=sum(savg(i-7:i+7))/15. - enddo - - nfa=fa/df - if(nfa.lt.nint(200.0/df)) nfa=nint(200.0/df) - nfb=fb/df - if(nfb.gt.nint(4910.0/df)) nfb=nint(4910.0/df) - call ft4_baseline(savg,nfa,nfb,sbase) - if(any(sbase(nfa:nfb).le.0)) return - savsm(nfa:nfb)=savsm(nfa:nfb)/sbase(nfa:nfb) - f_offset = -1.5*12000.0/NSPS - ncand=0 - candidatet=0 - do i=nfa+1,nfb-1 - if(savsm(i).ge.savsm(i-1) .and. savsm(i).ge.savsm(i+1) .and. & - savsm(i).ge.syncmin) then - den=savsm(i-1)-2*savsm(i)+savsm(i+1) - del=0. - if(den.ne.0.0) del=0.5*(savsm(i-1)-savsm(i+1))/den - fpeak=(i+del)*df+f_offset - if(fpeak.lt.200.0 .or. fpeak.gt.4910.0) cycle - speak=savsm(i) - 0.25*(savsm(i-1)-savsm(i+1))*del - ncand=ncand+1 - candidatet(1,ncand)=fpeak - candidatet(2,ncand)=speak - if(ncand.eq.maxcand) exit - endif - enddo - candidate=0 - nq=count(abs(candidatet(1,1:ncand)-nfqso).le.20.0) - n1=1 - n2=nq+1 - do i=1,ncand - if(abs(candidatet(1,i)-nfqso).le.20.0) then - candidate(1:2,n1)=candidatet(1:2,i) - n1=n1+1 - else - candidate(1:2,n2)=candidatet(1:2,i) - n2=n2+1 - endif - enddo -return -end subroutine getcandidates4 +subroutine getcandidates4(dd,fa,fb,syncmin,nfqso,maxcand,savg,candidate, & + ncand,sbase) + + include 'ft4_params.f90' + real s(NH1,NHSYM) + real savg(NH1),savsm(NH1) + real sbase(NH1) + real x(NFFT1) + real window(NFFT1) + complex cx(0:NH1) + real candidate(2,maxcand),candidatet(2,maxcand) + real dd(NMAX) + equivalence (x,cx) + logical first + data first/.true./ + save first,window + + if(first) then + first=.false. + pi=4.0*atan(1.) + window=0. + call nuttal_window(window,NFFT1) + endif + +! Compute symbol spectra, stepping by NSTEP steps. + savg=0. + df=12000.0/NFFT1 + fac=1.0/300.0 + do j=1,NHSYM + ia=(j-1)*NSTEP + 1 + ib=ia+NFFT1-1 + if(ib.gt.NMAX) exit + x=fac*dd(ia:ib)*window + call four2a(x,NFFT1,1,-1,0) !r2c FFT + s(1:NH1,j)=abs(cx(1:NH1))**2 + savg=savg + s(1:NH1,j) !Average spectrum + enddo + savg=savg/NHSYM + savsm=0. + do i=8,NH1-7 + savsm(i)=sum(savg(i-7:i+7))/15. + enddo + + nfa=fa/df + if(nfa.lt.nint(200.0/df)) nfa=nint(200.0/df) + nfb=fb/df + if(nfb.gt.nint(4910.0/df)) nfb=nint(4910.0/df) + call ft4_baseline(savg,nfa,nfb,sbase) + if(any(sbase(nfa:nfb).le.0)) return + savsm(nfa:nfb)=savsm(nfa:nfb)/sbase(nfa:nfb) + f_offset = -1.5*12000.0/NSPS + ncand=0 + candidatet=0 + do i=nfa+1,nfb-1 + if(savsm(i).ge.savsm(i-1) .and. savsm(i).ge.savsm(i+1) .and. & + savsm(i).ge.syncmin) then + den=savsm(i-1)-2*savsm(i)+savsm(i+1) + del=0. + if(den.ne.0.0) del=0.5*(savsm(i-1)-savsm(i+1))/den + fpeak=(i+del)*df+f_offset + if(fpeak.lt.200.0 .or. fpeak.gt.4910.0) cycle + speak=savsm(i) - 0.25*(savsm(i-1)-savsm(i+1))*del + ncand=ncand+1 + candidatet(1,ncand)=fpeak + candidatet(2,ncand)=speak + if(ncand.eq.maxcand) exit + endif + enddo + candidate=0 + nq=count(abs(candidatet(1,1:ncand)-nfqso).le.20.0) + n1=1 + n2=nq+1 + do i=1,ncand + if(abs(candidatet(1,i)-nfqso).le.20.0) then + candidate(1:2,n1)=candidatet(1:2,i) + n1=n1+1 + else + candidate(1:2,n2)=candidatet(1:2,i) + n2=n2+1 + endif + enddo +return +end subroutine getcandidates4 diff --git a/lib/ft4/messages.txt b/lib/ft4/messages.txt index 7c7faa8d..16329fce 100755 --- a/lib/ft4/messages.txt +++ b/lib/ft4/messages.txt @@ -1,162 +1,162 @@ -File 1 -190106_000015 7.080 Rx FT8 -15 0.2 178 N1TRK N4FKH 569 VA -190106_000015 7.080 Rx FT8 -13 -0.1 253 N1TRK KB7RUQ 539 UT -190106_000015 7.080 Rx FT8 10 0.2 389 W0ZF N3LFC RR73 -190106_000015 7.080 Rx FT8 -10 0.1 450 PY4AZ KF7YED 559 MT -190106_000015 7.080 Rx FT8 -3 0.2 507 N1TRK WA4DYD 559 GA -190106_000015 7.080 Rx FT8 14 0.2 689 KB0VHA KA1YQC R 539 MA -190106_000015 7.080 Rx FT8 -5 0.1 984 W9JA N9OY RR73 -190106_000015 7.080 Rx FT8 -12 0.1 1123 VA2CZ K8GNG RR73 -190106_000015 7.080 Rx FT8 2 0.1 1240 CQ RU K7RL CN88 -190106_000015 7.080 Rx FT8 -11 0.5 1293 K4ZMW K7VZ RR73 -190106_000015 7.080 Rx FT8 2 0.1 1387 WD9IGY KX1X 73 -190106_000015 7.080 Rx FT8 -10 0.1 1536 CQ RU W0FRC DM79 -190106_000015 7.080 Rx FT8 -2 0.1 1635 K4SQC VE3RX 549 ON -190106_000030 7.080 Rx FT8 -11 0.2 1745 CQ RU K1LOG FN56 -190106_000030 7.080 Rx FT8 3 0.8 1798 WD5DAX WS4WW 73 -190106_000030 7.080 Rx FT8 12 0.1 1895 DJ6GI KG4W 73 -190106_000030 7.080 Rx FT8 -14 0.2 2119 KF7YED KF5ZNQ 549 TX -190106_000030 7.080 Rx FT8 -5 0.1 336 CQ RU AB5XS EM12 -190106_000030 7.080 Rx FT8 0 0.0 1415 W3KIT AA8SW RR73 -190106_000030 7.080 Rx FT8 -13 0.3 1540 NI6G W7DRW 579 AZ -190106_000030 7.080 Rx FT8 -10 0.1 312 SHIFT W9JA -190106_000030 7.080 Rx FT8 -16 0.1 1447 W7BOB KJ7G 549 WA -File 2 -190106_000045 7.080 Rx FT8 -9 0.1 178 N1TRK N4FKH 569 VA -190106_000045 7.080 Rx FT8 -9 -0.1 253 N1TRK KB7RUQ RR73 -190106_000045 7.080 Rx FT8 -8 0.1 336 CQ RU AB5XS EM12 -190106_000045 7.080 Rx FT8 16 0.3 689 KB0VHA KA1YQC R 539 MA -190106_000045 7.080 Rx FT8 -3 0.1 984 CQ RU N9OY EN43 -190106_000045 7.080 Rx FT8 -10 0.1 1146 K1JT WB4HXE 559 GA -190106_000045 7.080 Rx FT8 6 0.1 1240 VE3LON K7RL R 549 WA -190106_000045 7.080 Rx FT8 -1 0.1 1386 WD9IGY KX1X 73 -190106_000045 7.080 Rx FT8 -12 0.1 1536 CQ RU W0FRC DM79 -190106_000045 7.080 Rx FT8 3 0.1 1635 K4SQC VE3RX RR73 -190106_000045 7.080 Rx FT8 -5 0.1 1688 CQ RU W1QA FN32 -190106_000045 7.080 Rx FT8 1 0.8 1797 CQ RU WS4WW FM17 -190106_000045 7.080 Rx FT8 14 0.1 1895 HB9BUN KG4W R 549 VA -190106_000100 7.080 Rx FT8 -7 0.1 2002 W9TO KN3ILZ 529 PA -190106_000100 7.080 Rx FT8 -9 0.1 312 W9JA PY2APK RRR -190106_000100 7.080 Rx FT8 -12 0.1 436 NZ7P WA7JAY 589 CA -190106_000100 7.080 Rx FT8 -13 -0.1 1380 AC6BW KR9A R 559 WI -190106_000100 7.080 Rx FT8 -17 0.1 1448 W7BOB KJ7G RR73 -190106_000100 7.080 Rx FT8 -7 0.3 1540 NI6G W7DRW 569 AZ -File 3 -190106_000115 7.080 Rx FT8 -13 0.2 178 N1TRK N4FKH 569 VA -190106_000115 7.080 Rx FT8 -14 -0.1 253 N1TRK KB7RUQ RR73 -190106_000115 7.080 Rx FT8 -5 0.1 336 CQ RU AB5XS EM12 -190106_000115 7.080 Rx FT8 -7 0.1 449 NI6G KF7YED 569 MT -190106_000115 7.080 Rx FT8 14 0.2 689 KB0VHA KA1YQC 73 -190106_000115 7.080 Rx FT8 11 0.4 852 W9TO N4QWF 569 VA -190106_000115 7.080 Rx FT8 -3 0.1 984 W4EMB N9OY R 529 WI -190106_000115 7.080 Rx FT8 -14 0.1 1117 WB4FAY K7PDW 549 UT -190106_000115 7.080 Rx FT8 3 0.2 1240 VE3LON K7RL R 559 WA -190106_000115 7.080 Rx FT8 -18 0.1 1380 AC6BW KR9A R 559 WI -190106_000115 7.080 Rx FT8 4 0.1 1475 K4KCL KB4S 559 VA -190106_000130 7.080 Rx FT8 -5 0.1 1612 K1JT WB4HXE RR73 -190106_000115 7.080 Rx FT8 -1 0.1 1688 KW4RTR W1QA R 539 MA -190106_000115 7.080 Rx FT8 -15 0.2 1745 CQ RU K1LOG FN56 -190106_000115 7.080 Rx FT8 3 0.8 1798 WA1T WS4WW R 579 VA -190106_000115 7.080 Rx FT8 14 0.1 1895 HB9BUN KG4W R 549 VA -190106_000115 7.080 Rx FT8 -9 0.2 2125 CQ RU NF3R FN20 -190106_000130 7.080 Rx FT8 -8 0.4 976 AG1T K7VZ 569 AZ -190106_000130 7.080 Rx FT8 -7 0.1 1434 Z36W N4KMC 529 FL -File 4 -190106_000145 7.080 Rx FT8 -8 0.1 335 CQ RU AB5XS EM12 -190106_000145 7.080 Rx FT8 -11 0.2 388 W0ZF WW4LL 559 ME -190106_000145 7.080 Rx FT8 -10 0.1 449 NI6G KF7YED 569 MT -190106_000145 7.080 Rx FT8 10 0.3 689 CQ RU KA1YQC FN42 -190106_000145 7.080 Rx FT8 12 0.4 852 W9TO N4QWF RR73 -190106_000145 7.080 Rx FT8 -2 0.1 984 W4EMB N9OY R 529 WI -190106_000145 7.080 Rx FT8 -12 0.1 1117 WB4FAY K7PDW 549 UT -190106_000145 7.080 Rx FT8 4 0.2 1240 VE3LON K7RL 73 -190106_000145 7.080 Rx FT8 -13 0.1 1348 WW5M KO9V 559 NC -190106_000145 7.080 Rx FT8 -14 0.1 1380 AC6BW KR9A R 559 WI -190106_000145 7.080 Rx FT8 2 0.1 1475 K4KCL KB4S RR73 -190106_000145 7.080 Rx FT8 -9 0.1 1536 KC1HTT W0FRC 73 -190106_000145 7.080 Rx FT8 1 0.1 1688 KW4RTR W1QA R 539 MA -190106_000200 7.080 Rx FT8 1 0.8 1797 WA1T WS4WW R 569 VA -190106_000200 7.080 Rx FT8 15 0.1 1895 CQ RU KG4W FM17 -190106_000200 7.080 Rx FT8 -6 0.2 2125 CQ RU NF3R FN20 -190106_000200 7.080 Rx FT8 -7 0.1 311 PD8DX PY2APK 539 0081 -190106_000200 7.080 Rx FT8 -3 0.5 976 AG1T K7VZ RR73 -190106_000200 7.080 Rx FT8 -5 0.1 1432 Z36W N4KMC 529 FL -190106_000200 7.080 Rx FT8 -7 0.3 1540 N7BT W7DRW 559 AZ -190106_000200 7.080 Rx FT8 -16 0.3 2124 N3KCR ON9COP 529 0053 -190106_000200 7.080 Rx FT8 -12 0.1 1448 K2DH KJ7G 549 WA -File 5 -190106_000215 7.080 Rx FT8 11 0.1 435 K1JT WV8WA 569 WV -190106_000215 7.080 Rx FT8 -4 0.1 335 CQ RU AB5XS EM12 -190106_000215 7.080 Rx FT8 10 0.5 689 CQ RU KA1YQC FN42 -190106_000215 7.080 Rx FT8 -10 0.1 843 CQ RU AE5JH EL07 -190106_000215 7.080 Rx FT8 -3 0.1 984 W4EMB N9OY R 529 WI -190106_000215 7.080 Rx FT8 -10 0.1 1118 WB4FAY W5MO 539 TX -190106_000215 7.080 Rx FT8 -16 0.1 1170 K1JT K8GNG 569 MI -190106_000215 7.080 Rx FT8 6 0.1 1240 CQ RU K7RL CN88 -190106_000215 7.080 Rx FT8 -8 0.1 1348 WW5M KO9V RR73 -190106_000215 7.080 Rx FT8 -12 0.1 1432 Z36W N4KMC 529 FL -190106_000215 7.080 Rx FT8 2 0.1 1490 KA6BIM KB4S 529 VA -190106_000230 7.080 Rx FT8 -1 0.1 1688 CQ RU W1QA FN32 -190106_000230 7.080 Rx FT8 15 0.1 1895 DD5ZZ KG4W R 539 VA -190106_000230 7.080 Rx FT8 -8 0.2 2125 CQ RU NF3R FN20 -190106_000230 7.080 Rx FT8 -13 0.1 1380 AC6BW KR9A R 559 WI -190106_000230 7.080 Rx FT8 -4 0.1 1536 CQ RU W0FRC DM79 -190106_000230 7.080 Rx FT8 -8 0.3 1540 N7BT W7DRW 559 AZ -File 6 -190106_000245 7.080 Rx FT8 6 0.1 635 K1JT WV8WA RR73 -190106_000245 7.080 Rx FT8 -12 0.1 335 VE3RX AB5XS R 589 TX -190106_000245 7.080 Rx FT8 -16 0.1 423 WA1T PY2APK 529 0081 -190106_000245 7.080 Rx FT8 9 0.4 507 N1TRK N4QWF RR73 -190106_000245 7.080 Rx FT8 -10 0.1 869 W7BOB W3KIT 539 MD -190106_000245 7.080 Rx FT8 -7 0.1 984 W4EMB N9OY R 529 WI -190106_000245 7.080 Rx FT8 -13 0.1 1170 K1JT K8GNG 569 MI -190106_000245 7.080 Rx FT8 5 0.1 1240 W6GMT K7RL R 569 WA -190106_000245 7.080 Rx FT8 2 0.1 1490 KA6BIM KB4S 529 VA -190106_000245 7.080 Rx FT8 -1 0.1 1688 CQ RU W1QA FN32 -190106_000245 7.080 Rx FT8 1 0.7 1798 N3KCR WS4WW R 599 VA -190106_000245 7.080 Rx FT8 17 0.1 1895 DD5ZZ KG4W 73 -190106_000300 7.080 Rx FT8 -10 0.2 2125 CQ RU NF3R FN20 -190106_000300 7.080 Rx FT8 8 0.1 546 W7BOB W4DHE 539 KY -190106_000300 7.080 Rx FT8 -9 0.2 844 CQ RU AE5JH EL07 -190106_000300 7.080 Rx FT8 -5 0.1 1536 W9WLX W0FRC R 549 CO -File 7 -190106_000315 7.080 Rx FT8 -5 0.1 335 VE3RX AB5XS 73 -190106_000315 7.080 Rx FT8 -13 0.1 424 WA1T PY2APK 529 0081 -190106_000315 7.080 Rx FT8 6 0.1 545 W7BOB W4DHE 539 KY -190106_000315 7.080 Rx FT8 -7 0.4 600 K2DH K7VZ 549 AZ -190106_000315 7.080 Rx FT8 9 0.1 689 VE3LON KA1YQC 73 -190106_000315 7.080 Rx FT8 -8 0.1 869 W7BOB W3KIT 539 MD -190106_000315 7.080 Rx FT8 -1 0.1 984 W4EMB N9OY R 529 WI -190106_000315 7.080 Rx FT8 -15 -0.1 1117 WB4FAY KB7RUQ 529 UT -190106_000315 7.080 Rx FT8 7 -0.2 1240 W6GMT K7RL 73 -190106_000315 7.080 Rx FT8 -5 0.2 1581 VA3WW WA4DYD 559 GA -190106_000315 7.080 Rx FT8 -8 0.1 1688 DD5ZZ W1QA R 569 MA -190106_000315 7.080 Rx FT8 4 0.7 1798 N3KCR WS4WW 73 -190106_000315 7.080 Rx FT8 16 0.1 1895 CQ RU KG4W FM17 -190106_000315 7.080 Rx FT8 -11 0.2 2125 CQ RU NF3R FN20 -190106_000330 7.080 Rx FT8 -8 0.1 1170 K1JT K8GNG RR73 -190106_000330 7.080 Rx FT8 -13 -0.1 454 NZ7P KM7S R 549 CA -190106_000330 7.080 Rx FT8 1 0.1 941 KW4RTR KO9V 559 NC -190106_000330 7.080 Rx FT8 -16 0.3 1034 W9JA W9OY 539 FL -190106_000330 7.080 Rx FT8 -2 0.1 1240 K2DH KD2GXL 559 NY -190106_000330 7.080 Rx FT8 -5 0.1 1536 W9WLX W0FRC 73 -190106_000330 7.080 Rx FT8 -2 -0.1 918 KF6JXM W5BT 529 TX -File 8 -190106_000345 7.080 Rx FT8 -5 0.1 335 CQ RU AB5XS EM12 -190106_000345 7.080 Rx FT8 -13 0.1 423 WA1T PY2APK 529 0081 -190106_000345 7.080 Rx FT8 6 0.2 689 CQ RU KA1YQC FN42 -190106_000345 7.080 Rx FT8 -16 0.1 852 W9TO KM4LFT RR73 -190106_000345 7.080 Rx FT8 -4 -0.1 918 KF6JXM W5BT 529 TX -190106_000345 7.080 Rx FT8 2 0.1 984 W4EMB N9OY R 529 WI -190106_000345 7.080 Rx FT8 -15 0.3 1034 W9JA W9OY RR73 -190106_000345 7.080 Rx FT8 -7 0.1 1175 K2DH KD2GXL 559 NY -190106_000345 7.080 Rx FT8 6 -0.1 1240 CQ RU K7RL CN88 -190106_000345 7.080 Rx FT8 -10 0.1 1536 CQ RU W0FRC DM79 -190106_000345 7.080 Rx FT8 -7 0.2 1581 VA3WW WA4DYD RR73 -190106_000345 7.080 Rx FT8 -9 0.1 1688 DD5ZZ W1QA 73 -190106_000345 7.080 Rx FT8 17 0.1 1895 CQ RU KG4W FM17 -190106_000345 7.080 Rx FT8 -9 0.1 2002 K2DH KN3ILZ 549 PA -190106_000400 7.080 Rx FT8 -5 0.7 2052 CQ RU WS4WW FM17 -190106_000400 7.080 Rx FT8 -9 0.2 2125 NV4G NF3R R 549 PA -190106_000400 7.080 Rx FT8 -5 0.0 941 KW4RTR KO9V RR73 -190106_000400 7.080 Rx FT8 -7 0.2 1744 KC1HTT K1LOG R 569 ME +File 1 +190106_000015 7.080 Rx FT8 -15 0.2 178 N1TRK N4FKH 569 VA +190106_000015 7.080 Rx FT8 -13 -0.1 253 N1TRK KB7RUQ 539 UT +190106_000015 7.080 Rx FT8 10 0.2 389 W0ZF N3LFC RR73 +190106_000015 7.080 Rx FT8 -10 0.1 450 PY4AZ KF7YED 559 MT +190106_000015 7.080 Rx FT8 -3 0.2 507 N1TRK WA4DYD 559 GA +190106_000015 7.080 Rx FT8 14 0.2 689 KB0VHA KA1YQC R 539 MA +190106_000015 7.080 Rx FT8 -5 0.1 984 W9JA N9OY RR73 +190106_000015 7.080 Rx FT8 -12 0.1 1123 VA2CZ K8GNG RR73 +190106_000015 7.080 Rx FT8 2 0.1 1240 CQ RU K7RL CN88 +190106_000015 7.080 Rx FT8 -11 0.5 1293 K4ZMW K7VZ RR73 +190106_000015 7.080 Rx FT8 2 0.1 1387 WD9IGY KX1X 73 +190106_000015 7.080 Rx FT8 -10 0.1 1536 CQ RU W0FRC DM79 +190106_000015 7.080 Rx FT8 -2 0.1 1635 K4SQC VE3RX 549 ON +190106_000030 7.080 Rx FT8 -11 0.2 1745 CQ RU K1LOG FN56 +190106_000030 7.080 Rx FT8 3 0.8 1798 WD5DAX WS4WW 73 +190106_000030 7.080 Rx FT8 12 0.1 1895 DJ6GI KG4W 73 +190106_000030 7.080 Rx FT8 -14 0.2 2119 KF7YED KF5ZNQ 549 TX +190106_000030 7.080 Rx FT8 -5 0.1 336 CQ RU AB5XS EM12 +190106_000030 7.080 Rx FT8 0 0.0 1415 W3KIT AA8SW RR73 +190106_000030 7.080 Rx FT8 -13 0.3 1540 NI6G W7DRW 579 AZ +190106_000030 7.080 Rx FT8 -10 0.1 312 SHIFT W9JA +190106_000030 7.080 Rx FT8 -16 0.1 1447 W7BOB KJ7G 549 WA +File 2 +190106_000045 7.080 Rx FT8 -9 0.1 178 N1TRK N4FKH 569 VA +190106_000045 7.080 Rx FT8 -9 -0.1 253 N1TRK KB7RUQ RR73 +190106_000045 7.080 Rx FT8 -8 0.1 336 CQ RU AB5XS EM12 +190106_000045 7.080 Rx FT8 16 0.3 689 KB0VHA KA1YQC R 539 MA +190106_000045 7.080 Rx FT8 -3 0.1 984 CQ RU N9OY EN43 +190106_000045 7.080 Rx FT8 -10 0.1 1146 K1JT WB4HXE 559 GA +190106_000045 7.080 Rx FT8 6 0.1 1240 VE3LON K7RL R 549 WA +190106_000045 7.080 Rx FT8 -1 0.1 1386 WD9IGY KX1X 73 +190106_000045 7.080 Rx FT8 -12 0.1 1536 CQ RU W0FRC DM79 +190106_000045 7.080 Rx FT8 3 0.1 1635 K4SQC VE3RX RR73 +190106_000045 7.080 Rx FT8 -5 0.1 1688 CQ RU W1QA FN32 +190106_000045 7.080 Rx FT8 1 0.8 1797 CQ RU WS4WW FM17 +190106_000045 7.080 Rx FT8 14 0.1 1895 HB9BUN KG4W R 549 VA +190106_000100 7.080 Rx FT8 -7 0.1 2002 W9TO KN3ILZ 529 PA +190106_000100 7.080 Rx FT8 -9 0.1 312 W9JA PY2APK RRR +190106_000100 7.080 Rx FT8 -12 0.1 436 NZ7P WA7JAY 589 CA +190106_000100 7.080 Rx FT8 -13 -0.1 1380 AC6BW KR9A R 559 WI +190106_000100 7.080 Rx FT8 -17 0.1 1448 W7BOB KJ7G RR73 +190106_000100 7.080 Rx FT8 -7 0.3 1540 NI6G W7DRW 569 AZ +File 3 +190106_000115 7.080 Rx FT8 -13 0.2 178 N1TRK N4FKH 569 VA +190106_000115 7.080 Rx FT8 -14 -0.1 253 N1TRK KB7RUQ RR73 +190106_000115 7.080 Rx FT8 -5 0.1 336 CQ RU AB5XS EM12 +190106_000115 7.080 Rx FT8 -7 0.1 449 NI6G KF7YED 569 MT +190106_000115 7.080 Rx FT8 14 0.2 689 KB0VHA KA1YQC 73 +190106_000115 7.080 Rx FT8 11 0.4 852 W9TO N4QWF 569 VA +190106_000115 7.080 Rx FT8 -3 0.1 984 W4EMB N9OY R 529 WI +190106_000115 7.080 Rx FT8 -14 0.1 1117 WB4FAY K7PDW 549 UT +190106_000115 7.080 Rx FT8 3 0.2 1240 VE3LON K7RL R 559 WA +190106_000115 7.080 Rx FT8 -18 0.1 1380 AC6BW KR9A R 559 WI +190106_000115 7.080 Rx FT8 4 0.1 1475 K4KCL KB4S 559 VA +190106_000130 7.080 Rx FT8 -5 0.1 1612 K1JT WB4HXE RR73 +190106_000115 7.080 Rx FT8 -1 0.1 1688 KW4RTR W1QA R 539 MA +190106_000115 7.080 Rx FT8 -15 0.2 1745 CQ RU K1LOG FN56 +190106_000115 7.080 Rx FT8 3 0.8 1798 WA1T WS4WW R 579 VA +190106_000115 7.080 Rx FT8 14 0.1 1895 HB9BUN KG4W R 549 VA +190106_000115 7.080 Rx FT8 -9 0.2 2125 CQ RU NF3R FN20 +190106_000130 7.080 Rx FT8 -8 0.4 976 AG1T K7VZ 569 AZ +190106_000130 7.080 Rx FT8 -7 0.1 1434 Z36W N4KMC 529 FL +File 4 +190106_000145 7.080 Rx FT8 -8 0.1 335 CQ RU AB5XS EM12 +190106_000145 7.080 Rx FT8 -11 0.2 388 W0ZF WW4LL 559 ME +190106_000145 7.080 Rx FT8 -10 0.1 449 NI6G KF7YED 569 MT +190106_000145 7.080 Rx FT8 10 0.3 689 CQ RU KA1YQC FN42 +190106_000145 7.080 Rx FT8 12 0.4 852 W9TO N4QWF RR73 +190106_000145 7.080 Rx FT8 -2 0.1 984 W4EMB N9OY R 529 WI +190106_000145 7.080 Rx FT8 -12 0.1 1117 WB4FAY K7PDW 549 UT +190106_000145 7.080 Rx FT8 4 0.2 1240 VE3LON K7RL 73 +190106_000145 7.080 Rx FT8 -13 0.1 1348 WW5M KO9V 559 NC +190106_000145 7.080 Rx FT8 -14 0.1 1380 AC6BW KR9A R 559 WI +190106_000145 7.080 Rx FT8 2 0.1 1475 K4KCL KB4S RR73 +190106_000145 7.080 Rx FT8 -9 0.1 1536 KC1HTT W0FRC 73 +190106_000145 7.080 Rx FT8 1 0.1 1688 KW4RTR W1QA R 539 MA +190106_000200 7.080 Rx FT8 1 0.8 1797 WA1T WS4WW R 569 VA +190106_000200 7.080 Rx FT8 15 0.1 1895 CQ RU KG4W FM17 +190106_000200 7.080 Rx FT8 -6 0.2 2125 CQ RU NF3R FN20 +190106_000200 7.080 Rx FT8 -7 0.1 311 PD8DX PY2APK 539 0081 +190106_000200 7.080 Rx FT8 -3 0.5 976 AG1T K7VZ RR73 +190106_000200 7.080 Rx FT8 -5 0.1 1432 Z36W N4KMC 529 FL +190106_000200 7.080 Rx FT8 -7 0.3 1540 N7BT W7DRW 559 AZ +190106_000200 7.080 Rx FT8 -16 0.3 2124 N3KCR ON9COP 529 0053 +190106_000200 7.080 Rx FT8 -12 0.1 1448 K2DH KJ7G 549 WA +File 5 +190106_000215 7.080 Rx FT8 11 0.1 435 K1JT WV8WA 569 WV +190106_000215 7.080 Rx FT8 -4 0.1 335 CQ RU AB5XS EM12 +190106_000215 7.080 Rx FT8 10 0.5 689 CQ RU KA1YQC FN42 +190106_000215 7.080 Rx FT8 -10 0.1 843 CQ RU AE5JH EL07 +190106_000215 7.080 Rx FT8 -3 0.1 984 W4EMB N9OY R 529 WI +190106_000215 7.080 Rx FT8 -10 0.1 1118 WB4FAY W5MO 539 TX +190106_000215 7.080 Rx FT8 -16 0.1 1170 K1JT K8GNG 569 MI +190106_000215 7.080 Rx FT8 6 0.1 1240 CQ RU K7RL CN88 +190106_000215 7.080 Rx FT8 -8 0.1 1348 WW5M KO9V RR73 +190106_000215 7.080 Rx FT8 -12 0.1 1432 Z36W N4KMC 529 FL +190106_000215 7.080 Rx FT8 2 0.1 1490 KA6BIM KB4S 529 VA +190106_000230 7.080 Rx FT8 -1 0.1 1688 CQ RU W1QA FN32 +190106_000230 7.080 Rx FT8 15 0.1 1895 DD5ZZ KG4W R 539 VA +190106_000230 7.080 Rx FT8 -8 0.2 2125 CQ RU NF3R FN20 +190106_000230 7.080 Rx FT8 -13 0.1 1380 AC6BW KR9A R 559 WI +190106_000230 7.080 Rx FT8 -4 0.1 1536 CQ RU W0FRC DM79 +190106_000230 7.080 Rx FT8 -8 0.3 1540 N7BT W7DRW 559 AZ +File 6 +190106_000245 7.080 Rx FT8 6 0.1 635 K1JT WV8WA RR73 +190106_000245 7.080 Rx FT8 -12 0.1 335 VE3RX AB5XS R 589 TX +190106_000245 7.080 Rx FT8 -16 0.1 423 WA1T PY2APK 529 0081 +190106_000245 7.080 Rx FT8 9 0.4 507 N1TRK N4QWF RR73 +190106_000245 7.080 Rx FT8 -10 0.1 869 W7BOB W3KIT 539 MD +190106_000245 7.080 Rx FT8 -7 0.1 984 W4EMB N9OY R 529 WI +190106_000245 7.080 Rx FT8 -13 0.1 1170 K1JT K8GNG 569 MI +190106_000245 7.080 Rx FT8 5 0.1 1240 W6GMT K7RL R 569 WA +190106_000245 7.080 Rx FT8 2 0.1 1490 KA6BIM KB4S 529 VA +190106_000245 7.080 Rx FT8 -1 0.1 1688 CQ RU W1QA FN32 +190106_000245 7.080 Rx FT8 1 0.7 1798 N3KCR WS4WW R 599 VA +190106_000245 7.080 Rx FT8 17 0.1 1895 DD5ZZ KG4W 73 +190106_000300 7.080 Rx FT8 -10 0.2 2125 CQ RU NF3R FN20 +190106_000300 7.080 Rx FT8 8 0.1 546 W7BOB W4DHE 539 KY +190106_000300 7.080 Rx FT8 -9 0.2 844 CQ RU AE5JH EL07 +190106_000300 7.080 Rx FT8 -5 0.1 1536 W9WLX W0FRC R 549 CO +File 7 +190106_000315 7.080 Rx FT8 -5 0.1 335 VE3RX AB5XS 73 +190106_000315 7.080 Rx FT8 -13 0.1 424 WA1T PY2APK 529 0081 +190106_000315 7.080 Rx FT8 6 0.1 545 W7BOB W4DHE 539 KY +190106_000315 7.080 Rx FT8 -7 0.4 600 K2DH K7VZ 549 AZ +190106_000315 7.080 Rx FT8 9 0.1 689 VE3LON KA1YQC 73 +190106_000315 7.080 Rx FT8 -8 0.1 869 W7BOB W3KIT 539 MD +190106_000315 7.080 Rx FT8 -1 0.1 984 W4EMB N9OY R 529 WI +190106_000315 7.080 Rx FT8 -15 -0.1 1117 WB4FAY KB7RUQ 529 UT +190106_000315 7.080 Rx FT8 7 -0.2 1240 W6GMT K7RL 73 +190106_000315 7.080 Rx FT8 -5 0.2 1581 VA3WW WA4DYD 559 GA +190106_000315 7.080 Rx FT8 -8 0.1 1688 DD5ZZ W1QA R 569 MA +190106_000315 7.080 Rx FT8 4 0.7 1798 N3KCR WS4WW 73 +190106_000315 7.080 Rx FT8 16 0.1 1895 CQ RU KG4W FM17 +190106_000315 7.080 Rx FT8 -11 0.2 2125 CQ RU NF3R FN20 +190106_000330 7.080 Rx FT8 -8 0.1 1170 K1JT K8GNG RR73 +190106_000330 7.080 Rx FT8 -13 -0.1 454 NZ7P KM7S R 549 CA +190106_000330 7.080 Rx FT8 1 0.1 941 KW4RTR KO9V 559 NC +190106_000330 7.080 Rx FT8 -16 0.3 1034 W9JA W9OY 539 FL +190106_000330 7.080 Rx FT8 -2 0.1 1240 K2DH KD2GXL 559 NY +190106_000330 7.080 Rx FT8 -5 0.1 1536 W9WLX W0FRC 73 +190106_000330 7.080 Rx FT8 -2 -0.1 918 KF6JXM W5BT 529 TX +File 8 +190106_000345 7.080 Rx FT8 -5 0.1 335 CQ RU AB5XS EM12 +190106_000345 7.080 Rx FT8 -13 0.1 423 WA1T PY2APK 529 0081 +190106_000345 7.080 Rx FT8 6 0.2 689 CQ RU KA1YQC FN42 +190106_000345 7.080 Rx FT8 -16 0.1 852 W9TO KM4LFT RR73 +190106_000345 7.080 Rx FT8 -4 -0.1 918 KF6JXM W5BT 529 TX +190106_000345 7.080 Rx FT8 2 0.1 984 W4EMB N9OY R 529 WI +190106_000345 7.080 Rx FT8 -15 0.3 1034 W9JA W9OY RR73 +190106_000345 7.080 Rx FT8 -7 0.1 1175 K2DH KD2GXL 559 NY +190106_000345 7.080 Rx FT8 6 -0.1 1240 CQ RU K7RL CN88 +190106_000345 7.080 Rx FT8 -10 0.1 1536 CQ RU W0FRC DM79 +190106_000345 7.080 Rx FT8 -7 0.2 1581 VA3WW WA4DYD RR73 +190106_000345 7.080 Rx FT8 -9 0.1 1688 DD5ZZ W1QA 73 +190106_000345 7.080 Rx FT8 17 0.1 1895 CQ RU KG4W FM17 +190106_000345 7.080 Rx FT8 -9 0.1 2002 K2DH KN3ILZ 549 PA +190106_000400 7.080 Rx FT8 -5 0.7 2052 CQ RU WS4WW FM17 +190106_000400 7.080 Rx FT8 -9 0.2 2125 NV4G NF3R R 549 PA +190106_000400 7.080 Rx FT8 -5 0.0 941 KW4RTR KO9V RR73 +190106_000400 7.080 Rx FT8 -7 0.2 1744 KC1HTT K1LOG R 569 ME diff --git a/lib/ft4/subtractft4.f90 b/lib/ft4/subtractft4.f90 index 136848fc..8fb16532 100755 --- a/lib/ft4/subtractft4.f90 +++ b/lib/ft4/subtractft4.f90 @@ -1,66 +1,66 @@ -subroutine subtractft4(dd,itone,f0,dt) - -! Subtract an ft4 signal -! -! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t)) -! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) ) -! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ] -! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt} - - use timer_module, only: timer - - parameter (NMAX=21*3456,NSPS=576,NFFT=NMAX,NFILT=1400) - parameter (NFRAME=(103+2)*NSPS) - real*4 dd(NMAX), window(-NFILT/2:NFILT/2), xjunk - complex cref,camp,cfilt,cw - integer itone(103) - logical first - data first/.true./ - common/heap4/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX),xjunk(NFRAME) - save first - - nstart=dt*12000+1-NSPS - nsym=103 - fs=12000.0 - icmplx=1 - bt=1.0 - nss=NSPS - call gen_ft4wave(itone,nsym,nss,fs,f0,cref,xjunk,icmplx,NFRAME) - camp=0. - do i=1,nframe - id=nstart-1+i - if(id.ge.1.and.id.le.NMAX) camp(i)=dd(id)*conjg(cref(i)) - enddo - - if(first) then -! Create and normalize the filter - pi=4.0*atan(1.0) - fac=1.0/float(nfft) - sum=0.0 - do j=-NFILT/2,NFILT/2 - window(j)=cos(pi*j/NFILT)**2 - sum=sum+window(j) - enddo - cw=0. - cw(1:NFILT+1)=window/sum - cw=cshift(cw,NFILT/2+1) - call four2a(cw,nfft,1,-1,1) - cw=cw*fac - first=.false. - endif - - cfilt=0.0 - cfilt(1:nframe)=camp(1:nframe) - call four2a(cfilt,nfft,1,-1,1) - cfilt(1:nfft)=cfilt(1:nfft)*cw(1:nfft) - call four2a(cfilt,nfft,1,1,1) - -! Subtract the reconstructed signal - do i=1,nframe - j=nstart+i-1 - if(j.ge.1 .and. j.le.NMAX) dd(j)=dd(j)-2*REAL(cfilt(i)*cref(i)) - enddo - - return -end subroutine subtractft4 - +subroutine subtractft4(dd,itone,f0,dt) + +! Subtract an ft4 signal +! +! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t)) +! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) ) +! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ] +! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt} + + use timer_module, only: timer + + parameter (NMAX=21*3456,NSPS=576,NFFT=NMAX,NFILT=1400) + parameter (NFRAME=(103+2)*NSPS) + real*4 dd(NMAX), window(-NFILT/2:NFILT/2), xjunk + complex cref,camp,cfilt,cw + integer itone(103) + logical first + data first/.true./ + common/heap4/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX),xjunk(NFRAME) + save first + + nstart=dt*12000+1-NSPS + nsym=103 + fs=12000.0 + icmplx=1 + bt=1.0 + nss=NSPS + call gen_ft4wave(itone,nsym,nss,fs,f0,cref,xjunk,icmplx,NFRAME) + camp=0. + do i=1,nframe + id=nstart-1+i + if(id.ge.1.and.id.le.NMAX) camp(i)=dd(id)*conjg(cref(i)) + enddo + + if(first) then +! Create and normalize the filter + pi=4.0*atan(1.0) + fac=1.0/float(nfft) + sum=0.0 + do j=-NFILT/2,NFILT/2 + window(j)=cos(pi*j/NFILT)**2 + sum=sum+window(j) + enddo + cw=0. + cw(1:NFILT+1)=window/sum + cw=cshift(cw,NFILT/2+1) + call four2a(cw,nfft,1,-1,1) + cw=cw*fac + first=.false. + endif + + cfilt=0.0 + cfilt(1:nframe)=camp(1:nframe) + call four2a(cfilt,nfft,1,-1,1) + cfilt(1:nfft)=cfilt(1:nfft)*cw(1:nfft) + call four2a(cfilt,nfft,1,1,1) + +! Subtract the reconstructed signal + do i=1,nframe + j=nstart+i-1 + if(j.ge.1 .and. j.le.NMAX) dd(j)=dd(j)-2*REAL(cfilt(i)*cref(i)) + enddo + + return +end subroutine subtractft4 + diff --git a/lib/ft4/sync4d.f90 b/lib/ft4/sync4d.f90 index 8d78f66a..50ae5d9f 100755 --- a/lib/ft4/sync4d.f90 +++ b/lib/ft4/sync4d.f90 @@ -1,96 +1,96 @@ -subroutine sync4d(cd0,i0,ctwk,itwk,sync) - -! Compute sync power for a complex, downsampled FT4 signal. - - include 'ft4_params.f90' - parameter(NP=NMAX/NDOWN,NSS=NSPS/NDOWN) - complex cd0(0:NP-1) - complex csynca(2*NSS),csyncb(2*NSS),csyncc(2*NSS),csyncd(2*NSS) - complex csync2(2*NSS) - complex ctwk(2*NSS) - complex z1,z2,z3,z4 - logical first - integer icos4a(0:3),icos4b(0:3),icos4c(0:3),icos4d(0:3) - data icos4a/0,1,3,2/ - data icos4b/1,0,2,3/ - data icos4c/2,3,1,0/ - data icos4d/3,2,0,1/ - data first/.true./ - save first,twopi,csynca,csyncb,csyncc,csyncd,fac - - p(z1)=(real(z1*fac)**2 + aimag(z1*fac)**2)**0.5 !Statement function for power - - if( first ) then - twopi=8.0*atan(1.0) - k=1 - phia=0.0 - phib=0.0 - phic=0.0 - phid=0.0 - do i=0,3 - dphia=2*twopi*icos4a(i)/real(NSS) - dphib=2*twopi*icos4b(i)/real(NSS) - dphic=2*twopi*icos4c(i)/real(NSS) - dphid=2*twopi*icos4d(i)/real(NSS) - do j=1,NSS/2 - csynca(k)=cmplx(cos(phia),sin(phia)) - csyncb(k)=cmplx(cos(phib),sin(phib)) - csyncc(k)=cmplx(cos(phic),sin(phic)) - csyncd(k)=cmplx(cos(phid),sin(phid)) - phia=mod(phia+dphia,twopi) - phib=mod(phib+dphib,twopi) - phic=mod(phic+dphic,twopi) - phid=mod(phid+dphid,twopi) - k=k+1 - enddo - enddo - first=.false. - fac=1.0/(2.0*NSS) - endif - - i1=i0 !four Costas arrays - i2=i0+33*NSS - i3=i0+66*NSS - i4=i0+99*NSS - - z1=0. - z2=0. - z3=0. - z4=0. - - if(itwk.eq.1) csync2=ctwk*csynca !Tweak the frequency - z1=0. - if(i1.ge.0 .and. i1+4*NSS-1.le.NP-1) then - z1=sum(cd0(i1:i1+4*NSS-1:2)*conjg(csync2)) - elseif( i1.lt.0 ) then - npts=(i1+4*NSS-1)/2 - if(npts.le.16) then - z1=0. - else - z1=sum(cd0(0:i1+4*NSS-1:2)*conjg(csync2(2*NSS-npts:))) - endif - endif - - if(itwk.eq.1) csync2=ctwk*csyncb !Tweak the frequency - if(i2.ge.0 .and. i2+4*NSS-1.le.NP-1) z2=sum(cd0(i2:i2+4*NSS-1:2)*conjg(csync2)) - - if(itwk.eq.1) csync2=ctwk*csyncc !Tweak the frequency - if(i3.ge.0 .and. i3+4*NSS-1.le.NP-1) z3=sum(cd0(i3:i3+4*NSS-1:2)*conjg(csync2)) - - if(itwk.eq.1) csync2=ctwk*csyncd !Tweak the frequency - z4=0. - if(i4.ge.0 .and. i4+4*NSS-1.le.NP-1) then - z4=sum(cd0(i4:i4+4*NSS-1:2)*conjg(csync2)) - elseif( i4+4*NSS-1.gt.NP-1 ) then - npts=(NP-1-i4+1)/2 - if(npts.le.16) then - z4=0. - else - z4=sum(cd0(i4:i4+2*npts-1:2)*conjg(csync2(1:npts))) - endif - endif - - sync = p(z1) + p(z2) + p(z3) + p(z4) - - return -end subroutine sync4d +subroutine sync4d(cd0,i0,ctwk,itwk,sync) + +! Compute sync power for a complex, downsampled FT4 signal. + + include 'ft4_params.f90' + parameter(NP=NMAX/NDOWN,NSS=NSPS/NDOWN) + complex cd0(0:NP-1) + complex csynca(2*NSS),csyncb(2*NSS),csyncc(2*NSS),csyncd(2*NSS) + complex csync2(2*NSS) + complex ctwk(2*NSS) + complex z1,z2,z3,z4 + logical first + integer icos4a(0:3),icos4b(0:3),icos4c(0:3),icos4d(0:3) + data icos4a/0,1,3,2/ + data icos4b/1,0,2,3/ + data icos4c/2,3,1,0/ + data icos4d/3,2,0,1/ + data first/.true./ + save first,twopi,csynca,csyncb,csyncc,csyncd,fac + + p(z1)=(real(z1*fac)**2 + aimag(z1*fac)**2)**0.5 !Statement function for power + + if( first ) then + twopi=8.0*atan(1.0) + k=1 + phia=0.0 + phib=0.0 + phic=0.0 + phid=0.0 + do i=0,3 + dphia=2*twopi*icos4a(i)/real(NSS) + dphib=2*twopi*icos4b(i)/real(NSS) + dphic=2*twopi*icos4c(i)/real(NSS) + dphid=2*twopi*icos4d(i)/real(NSS) + do j=1,NSS/2 + csynca(k)=cmplx(cos(phia),sin(phia)) + csyncb(k)=cmplx(cos(phib),sin(phib)) + csyncc(k)=cmplx(cos(phic),sin(phic)) + csyncd(k)=cmplx(cos(phid),sin(phid)) + phia=mod(phia+dphia,twopi) + phib=mod(phib+dphib,twopi) + phic=mod(phic+dphic,twopi) + phid=mod(phid+dphid,twopi) + k=k+1 + enddo + enddo + first=.false. + fac=1.0/(2.0*NSS) + endif + + i1=i0 !four Costas arrays + i2=i0+33*NSS + i3=i0+66*NSS + i4=i0+99*NSS + + z1=0. + z2=0. + z3=0. + z4=0. + + if(itwk.eq.1) csync2=ctwk*csynca !Tweak the frequency + z1=0. + if(i1.ge.0 .and. i1+4*NSS-1.le.NP-1) then + z1=sum(cd0(i1:i1+4*NSS-1:2)*conjg(csync2)) + elseif( i1.lt.0 ) then + npts=(i1+4*NSS-1)/2 + if(npts.le.16) then + z1=0. + else + z1=sum(cd0(0:i1+4*NSS-1:2)*conjg(csync2(2*NSS-npts:))) + endif + endif + + if(itwk.eq.1) csync2=ctwk*csyncb !Tweak the frequency + if(i2.ge.0 .and. i2+4*NSS-1.le.NP-1) z2=sum(cd0(i2:i2+4*NSS-1:2)*conjg(csync2)) + + if(itwk.eq.1) csync2=ctwk*csyncc !Tweak the frequency + if(i3.ge.0 .and. i3+4*NSS-1.le.NP-1) z3=sum(cd0(i3:i3+4*NSS-1:2)*conjg(csync2)) + + if(itwk.eq.1) csync2=ctwk*csyncd !Tweak the frequency + z4=0. + if(i4.ge.0 .and. i4+4*NSS-1.le.NP-1) then + z4=sum(cd0(i4:i4+4*NSS-1:2)*conjg(csync2)) + elseif( i4+4*NSS-1.gt.NP-1 ) then + npts=(NP-1-i4+1)/2 + if(npts.le.16) then + z4=0. + else + z4=sum(cd0(i4:i4+2*npts-1:2)*conjg(csync2(1:npts))) + endif + endif + + sync = p(z1) + p(z2) + p(z3) + p(z4) + + return +end subroutine sync4d diff --git a/lib/ft4_decode.f90 b/lib/ft4_decode.f90 index 2ff3a767..b15368a4 100755 --- a/lib/ft4_decode.f90 +++ b/lib/ft4_decode.f90 @@ -1,467 +1,467 @@ -module ft4_decode - - type :: ft4_decoder - procedure(ft4_decode_callback), pointer :: callback - contains - procedure :: decode - end type ft4_decoder - - abstract interface - subroutine ft4_decode_callback (this,sync,snr,dt,freq,decoded,nap,qual) - import ft4_decoder - implicit none - class(ft4_decoder), intent(inout) :: this - real, intent(in) :: sync - integer, intent(in) :: snr - real, intent(in) :: dt - real, intent(in) :: freq - character(len=37), intent(in) :: decoded - integer, intent(in) :: nap - real, intent(in) :: qual - end subroutine ft4_decode_callback - end interface - -contains - - subroutine decode(this,callback,iwave,nQSOProgress,nfqso, & - nfa,nfb,ndepth,lapcqonly,ncontest,mycall,hiscall) - use timer_module, only: timer - use packjt77 - include 'ft4/ft4_params.f90' - parameter (MAXCAND=100) - class(ft4_decoder), intent(inout) :: this - procedure(ft4_decode_callback) :: callback - parameter (NSS=NSPS/NDOWN,NDMAX=NMAX/NDOWN) - character message*37,msgsent*37 - character c77*77 - character*37 decodes(100) - character*17 cdatetime0 - character*12 mycall,hiscall - character*12 mycall0,hiscall0 - character*6 hhmmss - - complex cd2(0:NDMAX-1) !Complex waveform - complex cb(0:NDMAX-1) - complex cd(0:NN*NSS-1) !Complex waveform - complex ctwk(2*NSS),ctwk2(2*NSS,-16:16) - - real a(5) - real bitmetrics(2*NN,3) - real dd(NMAX) - real llr(2*ND),llra(2*ND),llrb(2*ND),llrc(2*ND),llrd(2*ND) - real candidate(2,MAXCAND) - real savg(NH1),sbase(NH1) - - integer apbits(2*ND) - integer apmy_ru(28),aphis_fd(28) - integer*2 iwave(NMAX) !Raw received data - integer*1 message77(77),rvec(77),apmask(2*ND),cw(2*ND) - integer*1 message91(91) - integer*1 hbits(2*NN) - integer i4tone(103) - integer nappasses(0:5) ! # of decoding passes for QSO States 0-5 - integer naptypes(0:5,4) ! nQSOProgress, decoding pass - integer mcq(29),mcqru(29),mcqfd(29),mcqtest(29),mcqww(29) - integer mrrr(19),m73(19),mrr73(19) - - logical nohiscall,unpk77_success - logical first, dobigfft - logical dosubtract,doosd - logical badsync - logical, intent(in) :: lapcqonly - - data first/.true./ - data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/ - data mcqru/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,1,1,0,0/ - data mcqfd/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,1,0/ - data mcqtest/0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,1,0/ - data mcqww/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,1,1,1,1,0/ - data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/ - data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/ - data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/ - data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & - 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & - 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ - save fs,dt,tt,txt,twopi,h,first,apbits,nappasses,naptypes, & - mycall0,hiscall0,ctwk2 - - this%callback => callback - hhmmss=cdatetime0(8:13) - dxcall13=hiscall ! initialize for use in packjt77 - mycall13=mycall - - smax1=0. - nd1=0 - - if(first) then - fs=12000.0/NDOWN !Sample rate after downsampling - dt=1/fs !Sample interval after downsample (s) - tt=NSPS*dt !Duration of "itone" symbols (s) - txt=NZ*dt !Transmission length (s) without ramp up/down - twopi=8.0*atan(1.0) - h=1.0 - - do idf=-16,16 - a=0. - a(1)=real(idf) - ctwk=1. - call twkfreq1(ctwk,2*NSS,fs/2.0,a,ctwk2(:,idf)) - enddo - - mcq=2*mod(mcq+rvec(1:29),2)-1 - mcqru=2*mod(mcqru+rvec(1:29),2)-1 - mcqfd=2*mod(mcqfd+rvec(1:29),2)-1 - mcqtest=2*mod(mcqtest+rvec(1:29),2)-1 - mcqww=2*mod(mcqww+rvec(1:29),2)-1 - mrrr=2*mod(mrrr+rvec(59:77),2)-1 - m73=2*mod(m73+rvec(59:77),2)-1 - mrr73=2*mod(mrr73+rvec(59:77),2)-1 - nappasses(0)=2 - nappasses(1)=2 - nappasses(2)=2 - nappasses(3)=2 - nappasses(4)=2 - nappasses(5)=3 - -! iaptype -!------------------------ -! 1 CQ ??? ??? (29 ap bits) -! 2 MyCall ??? ??? (29 ap bits) -! 3 MyCall DxCall ??? (58 ap bits) -! 4 MyCall DxCall RRR (77 ap bits) -! 5 MyCall DxCall 73 (77 ap bits) -! 6 MyCall DxCall RR73 (77 ap bits) -!******** - naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ) - naptypes(1,1:4)=(/2,3,0,0/) ! Tx1 - naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 - naptypes(3,1:4)=(/3,6,0,0/) ! Tx3 - naptypes(4,1:4)=(/3,6,0,0/) ! Tx4 - naptypes(5,1:4)=(/3,1,2,0/) ! Tx5 - - mycall0='' - hiscall0='' - first=.false. - endif - - l1=index(mycall,char(0)) - if(l1.ne.0) mycall(l1:)=" " - l1=index(hiscall,char(0)) - if(l1.ne.0) hiscall(l1:)=" " - if(mycall.ne.mycall0 .or. hiscall.ne.hiscall0) then - apbits=0 - apbits(1)=99 - apbits(30)=99 - apmy_ru=0 - aphis_fd=0 - - if(len(trim(mycall)) .lt. 3) go to 10 - - nohiscall=.false. - hiscall0=hiscall - if(len(trim(hiscall0)).lt.3) then - hiscall0=mycall ! use mycall for dummy hiscall - mycall won't be hashed. - nohiscall=.true. - endif - message=trim(mycall)//' '//trim(hiscall0)//' RR73' - i3=-1 - n3=-1 - call pack77(message,i3,n3,c77) - call unpack77(c77,1,msgsent,unpk77_success) - if(i3.ne.1 .or. (message.ne.msgsent) .or. .not.unpk77_success) go to 10 - read(c77,'(77i1)') message77 - apmy_ru=2*mod(message77(1:28)+rvec(2:29),2)-1 - aphis_fd=2*mod(message77(30:57)+rvec(29:56),2)-1 - message77=mod(message77+rvec,2) - call encode174_91(message77,cw) - apbits=2*cw-1 - if(nohiscall) apbits(30)=99 - -10 continue - mycall0=mycall - hiscall0=hiscall - endif - ndecodes=0 - decodes=' ' - fa=nfa - fb=nfb - dd=iwave - -! ndepth=3: 3 passes, bp+osd -! ndepth=2: 3 passes, bp only -! ndepth=1: 1 pass, no subtraction - - max_iterations=40 - syncmin=1.2 - dosubtract=.true. - doosd=.true. - nsp=3 - if(ndepth.eq.2) then - doosd=.false. - endif - if(ndepth.eq.1) then - nsp=1 - dosubtract=.false. - doosd=.false. - endif - - do isp = 1,nsp - if(isp.eq.2) then - if(ndecodes.eq.0) exit - nd1=ndecodes - elseif(isp.eq.3) then - nd2=ndecodes-nd1 - if(nd2.eq.0) exit - endif - - candidate=0.0 - ncand=0 - call timer('getcand4',0) - call getcandidates4(dd,fa,fb,syncmin,nfqso,MAXCAND,savg,candidate, & - ncand,sbase) - call timer('getcand4',1) - dobigfft=.true. - do icand=1,ncand - f0=candidate(1,icand) - snr=candidate(2,icand)-1.0 - call timer('ft4_down',0) - call ft4_downsample(dd,dobigfft,f0,cd2) !Downsample to 32 Sam/Sym - call timer('ft4_down',1) - if(dobigfft) dobigfft=.false. - sum2=sum(cd2*conjg(cd2))/(real(NMAX)/real(NDOWN)) - if(sum2.gt.0.0) cd2=cd2/sqrt(sum2) -! Sample rate is now 12000/18 = 666.67 samples/second - do iseg=1,3 ! DT search is done over 3 segments - do isync=1,2 - if(isync.eq.1) then - idfmin=-12 - idfmax=12 - idfstp=3 - ibmin=-344 - ibmax=1012 - if(iseg.eq.1) then - ibmin=108 - ibmax=560 - elseif(iseg.eq.2) then - smax1=smax - ibmin=560 - ibmax=1012 - elseif(iseg.eq.3) then - ibmin=-344 - ibmax=108 - endif - ibstp=4 - else - idfmin=idfbest-4 - idfmax=idfbest+4 - idfstp=1 - ibmin=ibest-5 - ibmax=ibest+5 - ibstp=1 - endif - ibest=-1 - idfbest=0 - smax=-99. - call timer('sync4d ',0) - do idf=idfmin,idfmax,idfstp - do istart=ibmin,ibmax,ibstp - call sync4d(cd2,istart,ctwk2(:,idf),1,sync) !Find sync power - if(sync.gt.smax) then - smax=sync - ibest=istart - idfbest=idf - endif - enddo - enddo - call timer('sync4d ',1) - enddo - if(iseg.eq.1) smax1=smax - if(smax.lt.1.2) cycle - if(iseg.gt.1 .and. smax.lt.smax1) cycle - f1=f0+real(idfbest) - if( f1.le.10.0 .or. f1.ge.4990.0 ) cycle - call timer('ft4down ',0) - call ft4_downsample(dd,dobigfft,f1,cb) !Final downsample, corrected f0 - call timer('ft4down ',1) - sum2=sum(abs(cb)**2)/(real(NSS)*NN) - if(sum2.gt.0.0) cb=cb/sqrt(sum2) - cd=0. - if(ibest.ge.0) then - it=min(NDMAX-1,ibest+NN*NSS-1) - np=it-ibest+1 - cd(0:np-1)=cb(ibest:it) - else - cd(-ibest:ibest+NN*NSS-1)=cb(0:NN*NSS+2*ibest-1) - endif - call timer('bitmet ',0) - call get_ft4_bitmetrics(cd,bitmetrics,badsync) - call timer('bitmet ',1) - if(badsync) cycle - hbits=0 - where(bitmetrics(:,1).ge.0) hbits=1 - ns1=count(hbits( 1: 8).eq.(/0,0,0,1,1,0,1,1/)) - ns2=count(hbits( 67: 74).eq.(/0,1,0,0,1,1,1,0/)) - ns3=count(hbits(133:140).eq.(/1,1,1,0,0,1,0,0/)) - ns4=count(hbits(199:206).eq.(/1,0,1,1,0,0,0,1/)) - nsync_qual=ns1+ns2+ns3+ns4 - if(nsync_qual.lt. 20) cycle - - scalefac=2.83 - llra( 1: 58)=bitmetrics( 9: 66, 1) - llra( 59:116)=bitmetrics( 75:132, 1) - llra(117:174)=bitmetrics(141:198, 1) - llra=scalefac*llra - llrb( 1: 58)=bitmetrics( 9: 66, 2) - llrb( 59:116)=bitmetrics( 75:132, 2) - llrb(117:174)=bitmetrics(141:198, 2) - llrb=scalefac*llrb - llrc( 1: 58)=bitmetrics( 9: 66, 3) - llrc( 59:116)=bitmetrics( 75:132, 3) - llrc(117:174)=bitmetrics(141:198, 3) - llrc=scalefac*llrc - - apmag=maxval(abs(llra))*1.1 - npasses=3+nappasses(nQSOProgress) - if(lapcqonly) npasses=4 - if(ndepth.eq.1) npasses=3 - if(ncontest.ge.6) npasses=3 ! Don't support Fox and Hound - do ipass=1,npasses - if(ipass.eq.1) llr=llra - if(ipass.eq.2) llr=llrb - if(ipass.eq.3) llr=llrc - if(ipass.le.3) then - apmask=0 - iaptype=0 - endif - - if(ipass .gt. 3) then - llrd=llrc - iaptype=naptypes(nQSOProgress,ipass-3) - if(lapcqonly) iaptype=1 - -! ncontest=0 : NONE -! 1 : NA_VHF -! 2 : EU_VHF -! 3 : FIELD DAY -! 4 : RTTY -! 5 : WW_DIGI -! 6 : FOX -! 7 : HOUND -! -! Conditions that cause us to bail out of AP decoding - napwid=80 - if(ncontest.le.5 .and. iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid) ) cycle - if(iaptype.ge.2 .and. apbits(1).gt.1) cycle ! No, or nonstandard, mycall - if(iaptype.ge.3 .and. apbits(30).gt.1) cycle ! No, or nonstandard, dxcall - - if(iaptype.eq.1) then ! CQ or CQ TEST or CQ FD or CQ RU or CQ WW - apmask=0 - apmask(1:29)=1 - if( ncontest.eq.0 ) llrd(1:29)=apmag*mcq(1:29) - if( ncontest.eq.1 ) llrd(1:29)=apmag*mcqtest(1:29) - if( ncontest.eq.2 ) llrd(1:29)=apmag*mcqtest(1:29) - if( ncontest.eq.3 ) llrd(1:29)=apmag*mcqfd(1:29) - if( ncontest.eq.4 ) llrd(1:29)=apmag*mcqru(1:29) - if( ncontest.eq.5 ) llrd(1:29)=apmag*mcqww(1:29) - endif - - if(iaptype.eq.2) then ! MyCall,???,??? - apmask=0 - if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.5) then - apmask(1:29)=1 - llrd(1:29)=apmag*apbits(1:29) - else if(ncontest.eq.2) then - apmask(1:28)=1 - llrd(1:28)=apmag*apbits(1:28) - else if(ncontest.eq.3) then - apmask(1:28)=1 - llrd(1:28)=apmag*apbits(1:28) - else if(ncontest.eq.4) then - apmask(2:29)=1 - llrd(2:29)=apmag*apmy_ru(1:28) - endif - endif - - if(iaptype.eq.3) then ! MyCall,DxCall,??? - apmask=0 - if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2.or.ncontest.eq.5) then - apmask(1:58)=1 - llrd(1:58)=apmag*apbits(1:58) - else if(ncontest.eq.3) then ! Field Day - apmask(1:56)=1 - llrd(1:28)=apmag*apbits(1:28) - llrd(29:56)=apmag*aphis_fd(1:28) - else if(ncontest.eq.4) then - apmask(2:57)=1 - llrd(2:29)=apmag*apmy_ru(1:28) - llrd(30:57)=apmag*apbits(30:57) - endif - endif - - if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then - apmask=0 - if(ncontest.le.5) then - apmask(1:77)=1 ! mycall, hiscall, RRR|73|RR73 - if(iaptype.eq.6) llrd(1:77)=apmag*apbits(1:77) - endif - endif - - llr=llrd - endif - message77=0 - dmin=0.0 - - ndeep=2 - maxosd=2 - if(abs(nfqso-f1).le.napwid) then - ndeep=2 - maxosd=3 - endif - if(.not.doosd) maxosd = -1 - call timer('dec174_91 ',0) - Keff=91 - call decode174_91(llr,Keff,maxosd,ndeep,apmask,message91,cw, & - ntype,nharderror,dmin) - message77=message91(1:77) - call timer('dec174_91 ',1) - - if(sum(message77).eq.0) cycle - if( nharderror.ge.0 ) then - message77=mod(message77+rvec,2) ! remove rvec scrambling - write(c77,'(77i1)') message77(1:77) - call unpack77(c77,1,message,unpk77_success) - if(.not.unpk77_success) exit - if(dosubtract) then - call get_ft4_tones_from_77bits(message77,i4tone) - dt=real(ibest)/666.67 - call timer('subtract',0) - call subtractft4(dd,i4tone,f1,dt) - call timer('subtract',1) - endif - idupe=0 - do i=1,ndecodes - if(decodes(i).eq.message) idupe=1 - enddo - if(idupe.eq.1) exit - ndecodes=ndecodes+1 - decodes(ndecodes)=message - if(snr.gt.0.0) then - xsnr=10*log10(snr)-14.8 - else - xsnr=-21.0 - endif - nsnr=nint(max(-21.0,xsnr)) - xdt=ibest/666.67 - 0.5 - qual=1.0-(nharderror+dmin)/60.0 - call this%callback(smax,nsnr,xdt,f1,message,iaptype,qual) - exit - endif - enddo !Sequence estimation - if(nharderror.ge.0) exit - enddo !3 DT segments - enddo !Candidate list - enddo !Subtraction loop - return - end subroutine decode - -end module ft4_decode +module ft4_decode + + type :: ft4_decoder + procedure(ft4_decode_callback), pointer :: callback + contains + procedure :: decode + end type ft4_decoder + + abstract interface + subroutine ft4_decode_callback (this,sync,snr,dt,freq,decoded,nap,qual) + import ft4_decoder + implicit none + class(ft4_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=37), intent(in) :: decoded + integer, intent(in) :: nap + real, intent(in) :: qual + end subroutine ft4_decode_callback + end interface + +contains + + subroutine decode(this,callback,iwave,nQSOProgress,nfqso, & + nfa,nfb,ndepth,lapcqonly,ncontest,mycall,hiscall) + use timer_module, only: timer + use packjt77 + include 'ft4/ft4_params.f90' + parameter (MAXCAND=100) + class(ft4_decoder), intent(inout) :: this + procedure(ft4_decode_callback) :: callback + parameter (NSS=NSPS/NDOWN,NDMAX=NMAX/NDOWN) + character message*37,msgsent*37 + character c77*77 + character*37 decodes(100) + character*17 cdatetime0 + character*12 mycall,hiscall + character*12 mycall0,hiscall0 + character*6 hhmmss + + complex cd2(0:NDMAX-1) !Complex waveform + complex cb(0:NDMAX-1) + complex cd(0:NN*NSS-1) !Complex waveform + complex ctwk(2*NSS),ctwk2(2*NSS,-16:16) + + real a(5) + real bitmetrics(2*NN,3) + real dd(NMAX) + real llr(2*ND),llra(2*ND),llrb(2*ND),llrc(2*ND),llrd(2*ND) + real candidate(2,MAXCAND) + real savg(NH1),sbase(NH1) + + integer apbits(2*ND) + integer apmy_ru(28),aphis_fd(28) + integer*2 iwave(NMAX) !Raw received data + integer*1 message77(77),rvec(77),apmask(2*ND),cw(2*ND) + integer*1 message91(91) + integer*1 hbits(2*NN) + integer i4tone(103) + integer nappasses(0:5) ! # of decoding passes for QSO States 0-5 + integer naptypes(0:5,4) ! nQSOProgress, decoding pass + integer mcq(29),mcqru(29),mcqfd(29),mcqtest(29),mcqww(29) + integer mrrr(19),m73(19),mrr73(19) + + logical nohiscall,unpk77_success + logical first, dobigfft + logical dosubtract,doosd + logical badsync + logical, intent(in) :: lapcqonly + + data first/.true./ + data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/ + data mcqru/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,1,1,0,0/ + data mcqfd/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,1,0/ + data mcqtest/0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,1,0/ + data mcqww/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,1,1,1,1,0/ + data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/ + data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/ + data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/ + data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & + 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & + 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ + save fs,dt,tt,txt,twopi,h,first,apbits,nappasses,naptypes, & + mycall0,hiscall0,ctwk2 + + this%callback => callback + hhmmss=cdatetime0(8:13) + dxcall13=hiscall ! initialize for use in packjt77 + mycall13=mycall + + smax1=0. + nd1=0 + + if(first) then + fs=12000.0/NDOWN !Sample rate after downsampling + dt=1/fs !Sample interval after downsample (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + txt=NZ*dt !Transmission length (s) without ramp up/down + twopi=8.0*atan(1.0) + h=1.0 + + do idf=-16,16 + a=0. + a(1)=real(idf) + ctwk=1. + call twkfreq1(ctwk,2*NSS,fs/2.0,a,ctwk2(:,idf)) + enddo + + mcq=2*mod(mcq+rvec(1:29),2)-1 + mcqru=2*mod(mcqru+rvec(1:29),2)-1 + mcqfd=2*mod(mcqfd+rvec(1:29),2)-1 + mcqtest=2*mod(mcqtest+rvec(1:29),2)-1 + mcqww=2*mod(mcqww+rvec(1:29),2)-1 + mrrr=2*mod(mrrr+rvec(59:77),2)-1 + m73=2*mod(m73+rvec(59:77),2)-1 + mrr73=2*mod(mrr73+rvec(59:77),2)-1 + nappasses(0)=2 + nappasses(1)=2 + nappasses(2)=2 + nappasses(3)=2 + nappasses(4)=2 + nappasses(5)=3 + +! iaptype +!------------------------ +! 1 CQ ??? ??? (29 ap bits) +! 2 MyCall ??? ??? (29 ap bits) +! 3 MyCall DxCall ??? (58 ap bits) +! 4 MyCall DxCall RRR (77 ap bits) +! 5 MyCall DxCall 73 (77 ap bits) +! 6 MyCall DxCall RR73 (77 ap bits) +!******** + naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ) + naptypes(1,1:4)=(/2,3,0,0/) ! Tx1 + naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 + naptypes(3,1:4)=(/3,6,0,0/) ! Tx3 + naptypes(4,1:4)=(/3,6,0,0/) ! Tx4 + naptypes(5,1:4)=(/3,1,2,0/) ! Tx5 + + mycall0='' + hiscall0='' + first=.false. + endif + + l1=index(mycall,char(0)) + if(l1.ne.0) mycall(l1:)=" " + l1=index(hiscall,char(0)) + if(l1.ne.0) hiscall(l1:)=" " + if(mycall.ne.mycall0 .or. hiscall.ne.hiscall0) then + apbits=0 + apbits(1)=99 + apbits(30)=99 + apmy_ru=0 + aphis_fd=0 + + if(len(trim(mycall)) .lt. 3) go to 10 + + nohiscall=.false. + hiscall0=hiscall + if(len(trim(hiscall0)).lt.3) then + hiscall0=mycall ! use mycall for dummy hiscall - mycall won't be hashed. + nohiscall=.true. + endif + message=trim(mycall)//' '//trim(hiscall0)//' RR73' + i3=-1 + n3=-1 + call pack77(message,i3,n3,c77) + call unpack77(c77,1,msgsent,unpk77_success) + if(i3.ne.1 .or. (message.ne.msgsent) .or. .not.unpk77_success) go to 10 + read(c77,'(77i1)') message77 + apmy_ru=2*mod(message77(1:28)+rvec(2:29),2)-1 + aphis_fd=2*mod(message77(30:57)+rvec(29:56),2)-1 + message77=mod(message77+rvec,2) + call encode174_91(message77,cw) + apbits=2*cw-1 + if(nohiscall) apbits(30)=99 + +10 continue + mycall0=mycall + hiscall0=hiscall + endif + ndecodes=0 + decodes=' ' + fa=nfa + fb=nfb + dd=iwave + +! ndepth=3: 3 passes, bp+osd +! ndepth=2: 3 passes, bp only +! ndepth=1: 1 pass, no subtraction + + max_iterations=40 + syncmin=1.2 + dosubtract=.true. + doosd=.true. + nsp=3 + if(ndepth.eq.2) then + doosd=.false. + endif + if(ndepth.eq.1) then + nsp=1 + dosubtract=.false. + doosd=.false. + endif + + do isp = 1,nsp + if(isp.eq.2) then + if(ndecodes.eq.0) exit + nd1=ndecodes + elseif(isp.eq.3) then + nd2=ndecodes-nd1 + if(nd2.eq.0) exit + endif + + candidate=0.0 + ncand=0 + call timer('getcand4',0) + call getcandidates4(dd,fa,fb,syncmin,nfqso,MAXCAND,savg,candidate, & + ncand,sbase) + call timer('getcand4',1) + dobigfft=.true. + do icand=1,ncand + f0=candidate(1,icand) + snr=candidate(2,icand)-1.0 + call timer('ft4_down',0) + call ft4_downsample(dd,dobigfft,f0,cd2) !Downsample to 32 Sam/Sym + call timer('ft4_down',1) + if(dobigfft) dobigfft=.false. + sum2=sum(cd2*conjg(cd2))/(real(NMAX)/real(NDOWN)) + if(sum2.gt.0.0) cd2=cd2/sqrt(sum2) +! Sample rate is now 12000/18 = 666.67 samples/second + do iseg=1,3 ! DT search is done over 3 segments + do isync=1,2 + if(isync.eq.1) then + idfmin=-12 + idfmax=12 + idfstp=3 + ibmin=-344 + ibmax=1012 + if(iseg.eq.1) then + ibmin=108 + ibmax=560 + elseif(iseg.eq.2) then + smax1=smax + ibmin=560 + ibmax=1012 + elseif(iseg.eq.3) then + ibmin=-344 + ibmax=108 + endif + ibstp=4 + else + idfmin=idfbest-4 + idfmax=idfbest+4 + idfstp=1 + ibmin=ibest-5 + ibmax=ibest+5 + ibstp=1 + endif + ibest=-1 + idfbest=0 + smax=-99. + call timer('sync4d ',0) + do idf=idfmin,idfmax,idfstp + do istart=ibmin,ibmax,ibstp + call sync4d(cd2,istart,ctwk2(:,idf),1,sync) !Find sync power + if(sync.gt.smax) then + smax=sync + ibest=istart + idfbest=idf + endif + enddo + enddo + call timer('sync4d ',1) + enddo + if(iseg.eq.1) smax1=smax + if(smax.lt.1.2) cycle + if(iseg.gt.1 .and. smax.lt.smax1) cycle + f1=f0+real(idfbest) + if( f1.le.10.0 .or. f1.ge.4990.0 ) cycle + call timer('ft4down ',0) + call ft4_downsample(dd,dobigfft,f1,cb) !Final downsample, corrected f0 + call timer('ft4down ',1) + sum2=sum(abs(cb)**2)/(real(NSS)*NN) + if(sum2.gt.0.0) cb=cb/sqrt(sum2) + cd=0. + if(ibest.ge.0) then + it=min(NDMAX-1,ibest+NN*NSS-1) + np=it-ibest+1 + cd(0:np-1)=cb(ibest:it) + else + cd(-ibest:ibest+NN*NSS-1)=cb(0:NN*NSS+2*ibest-1) + endif + call timer('bitmet ',0) + call get_ft4_bitmetrics(cd,bitmetrics,badsync) + call timer('bitmet ',1) + if(badsync) cycle + hbits=0 + where(bitmetrics(:,1).ge.0) hbits=1 + ns1=count(hbits( 1: 8).eq.(/0,0,0,1,1,0,1,1/)) + ns2=count(hbits( 67: 74).eq.(/0,1,0,0,1,1,1,0/)) + ns3=count(hbits(133:140).eq.(/1,1,1,0,0,1,0,0/)) + ns4=count(hbits(199:206).eq.(/1,0,1,1,0,0,0,1/)) + nsync_qual=ns1+ns2+ns3+ns4 + if(nsync_qual.lt. 20) cycle + + scalefac=2.83 + llra( 1: 58)=bitmetrics( 9: 66, 1) + llra( 59:116)=bitmetrics( 75:132, 1) + llra(117:174)=bitmetrics(141:198, 1) + llra=scalefac*llra + llrb( 1: 58)=bitmetrics( 9: 66, 2) + llrb( 59:116)=bitmetrics( 75:132, 2) + llrb(117:174)=bitmetrics(141:198, 2) + llrb=scalefac*llrb + llrc( 1: 58)=bitmetrics( 9: 66, 3) + llrc( 59:116)=bitmetrics( 75:132, 3) + llrc(117:174)=bitmetrics(141:198, 3) + llrc=scalefac*llrc + + apmag=maxval(abs(llra))*1.1 + npasses=3+nappasses(nQSOProgress) + if(lapcqonly) npasses=4 + if(ndepth.eq.1) npasses=3 + if(ncontest.ge.6) npasses=3 ! Don't support Fox and Hound + do ipass=1,npasses + if(ipass.eq.1) llr=llra + if(ipass.eq.2) llr=llrb + if(ipass.eq.3) llr=llrc + if(ipass.le.3) then + apmask=0 + iaptype=0 + endif + + if(ipass .gt. 3) then + llrd=llrc + iaptype=naptypes(nQSOProgress,ipass-3) + if(lapcqonly) iaptype=1 + +! ncontest=0 : NONE +! 1 : NA_VHF +! 2 : EU_VHF +! 3 : FIELD DAY +! 4 : RTTY +! 5 : WW_DIGI +! 6 : FOX +! 7 : HOUND +! +! Conditions that cause us to bail out of AP decoding + napwid=80 + if(ncontest.le.5 .and. iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid) ) cycle + if(iaptype.ge.2 .and. apbits(1).gt.1) cycle ! No, or nonstandard, mycall + if(iaptype.ge.3 .and. apbits(30).gt.1) cycle ! No, or nonstandard, dxcall + + if(iaptype.eq.1) then ! CQ or CQ TEST or CQ FD or CQ RU or CQ WW + apmask=0 + apmask(1:29)=1 + if( ncontest.eq.0 ) llrd(1:29)=apmag*mcq(1:29) + if( ncontest.eq.1 ) llrd(1:29)=apmag*mcqtest(1:29) + if( ncontest.eq.2 ) llrd(1:29)=apmag*mcqtest(1:29) + if( ncontest.eq.3 ) llrd(1:29)=apmag*mcqfd(1:29) + if( ncontest.eq.4 ) llrd(1:29)=apmag*mcqru(1:29) + if( ncontest.eq.5 ) llrd(1:29)=apmag*mcqww(1:29) + endif + + if(iaptype.eq.2) then ! MyCall,???,??? + apmask=0 + if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.5) then + apmask(1:29)=1 + llrd(1:29)=apmag*apbits(1:29) + else if(ncontest.eq.2) then + apmask(1:28)=1 + llrd(1:28)=apmag*apbits(1:28) + else if(ncontest.eq.3) then + apmask(1:28)=1 + llrd(1:28)=apmag*apbits(1:28) + else if(ncontest.eq.4) then + apmask(2:29)=1 + llrd(2:29)=apmag*apmy_ru(1:28) + endif + endif + + if(iaptype.eq.3) then ! MyCall,DxCall,??? + apmask=0 + if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2.or.ncontest.eq.5) then + apmask(1:58)=1 + llrd(1:58)=apmag*apbits(1:58) + else if(ncontest.eq.3) then ! Field Day + apmask(1:56)=1 + llrd(1:28)=apmag*apbits(1:28) + llrd(29:56)=apmag*aphis_fd(1:28) + else if(ncontest.eq.4) then + apmask(2:57)=1 + llrd(2:29)=apmag*apmy_ru(1:28) + llrd(30:57)=apmag*apbits(30:57) + endif + endif + + if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then + apmask=0 + if(ncontest.le.5) then + apmask(1:77)=1 ! mycall, hiscall, RRR|73|RR73 + if(iaptype.eq.6) llrd(1:77)=apmag*apbits(1:77) + endif + endif + + llr=llrd + endif + message77=0 + dmin=0.0 + + ndeep=2 + maxosd=2 + if(abs(nfqso-f1).le.napwid) then + ndeep=2 + maxosd=3 + endif + if(.not.doosd) maxosd = -1 + call timer('dec174_91 ',0) + Keff=91 + call decode174_91(llr,Keff,maxosd,ndeep,apmask,message91,cw, & + ntype,nharderror,dmin) + message77=message91(1:77) + call timer('dec174_91 ',1) + + if(sum(message77).eq.0) cycle + if( nharderror.ge.0 ) then + message77=mod(message77+rvec,2) ! remove rvec scrambling + write(c77,'(77i1)') message77(1:77) + call unpack77(c77,1,message,unpk77_success) + if(.not.unpk77_success) exit + if(dosubtract) then + call get_ft4_tones_from_77bits(message77,i4tone) + dt=real(ibest)/666.67 + call timer('subtract',0) + call subtractft4(dd,i4tone,f1,dt) + call timer('subtract',1) + endif + idupe=0 + do i=1,ndecodes + if(decodes(i).eq.message) idupe=1 + enddo + if(idupe.eq.1) exit + ndecodes=ndecodes+1 + decodes(ndecodes)=message + if(snr.gt.0.0) then + xsnr=10*log10(snr)-14.8 + else + xsnr=-21.0 + endif + nsnr=nint(max(-21.0,xsnr)) + xdt=ibest/666.67 - 0.5 + qual=1.0-(nharderror+dmin)/60.0 + call this%callback(smax,nsnr,xdt,f1,message,iaptype,qual) + exit + endif + enddo !Sequence estimation + if(nharderror.ge.0) exit + enddo !3 DT segments + enddo !Candidate list + enddo !Subtraction loop + return + end subroutine decode + +end module ft4_decode diff --git a/lib/ft8/bpdecode174_91.f90 b/lib/ft8/bpdecode174_91.f90 index ae1cb9da..a7c6f95b 100755 --- a/lib/ft8/bpdecode174_91.f90 +++ b/lib/ft8/bpdecode174_91.f90 @@ -1,117 +1,117 @@ -subroutine bpdecode174_91(llr,apmask,maxiterations,message77,cw,nharderror,iter,ncheck) -! -! A log-domain belief propagation decoder for the (174,91) code. -! -use iso_c_binding, only: c_loc,c_size_t -use crc -integer, parameter:: N=174, K=91, M=N-K -integer*1 cw(N),apmask(N) -integer*1 decoded(K) -integer*1 message77(77) -integer nrw(M),ncw -integer Nm(7,M) -integer Mn(3,N) ! 3 checks per bit -integer synd(M) -real tov(3,N) -real toc(7,M) -real tanhtoc(7,M) -real zn(N) -real llr(N) -real Tmn - -include "ldpc_174_91_c_parity.f90" - -decoded=0 -toc=0 -tov=0 -tanhtoc=0 -! initialize messages to checks -do j=1,M - do i=1,nrw(j) - toc(i,j)=llr((Nm(i,j))) - enddo -enddo - -ncnt=0 -nclast=0 - -do iter=0,maxiterations - -! Update bit log likelihood ratios (tov=0 in iteration 0). - do i=1,N - if( apmask(i) .ne. 1 ) then - zn(i)=llr(i)+sum(tov(1:ncw,i)) - else - zn(i)=llr(i) - endif - enddo - -! Check to see if we have a codeword (check before we do any iteration). - cw=0 - where( zn .gt. 0. ) cw=1 - ncheck=0 - do i=1,M - synd(i)=sum(cw(Nm(1:nrw(i),i))) - if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 -! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied' - enddo -! write(*,*) 'number of unsatisfied parity checks ',ncheck - if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it - decoded=cw(1:K) - call chkcrc14a(decoded,nbadcrc) - nharderror=count( (2*cw-1)*llr .lt. 0.0 ) - if(nbadcrc.eq.0) then - message77=decoded(1:77) - return - endif - endif - - if( iter.gt.0 ) then ! this code block implements an early stopping criterion -! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion - nd=ncheck-nclast - if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased - ncnt=0 ! reset counter - else - ncnt=ncnt+1 - endif -! write(*,*) iter,ncheck,nd,ncnt - if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then - nharderror=-1 - - return - endif - endif - nclast=ncheck - -! Send messages from bits to check nodes - do j=1,M - do i=1,nrw(j) - ibj=Nm(i,j) - toc(i,j)=zn(ibj) - do kk=1,ncw ! subtract off what the bit had received from the check - if( Mn(kk,ibj) .eq. j ) then - toc(i,j)=toc(i,j)-tov(kk,ibj) - endif - enddo - enddo - enddo - -! send messages from check nodes to variable nodes - do i=1,M - tanhtoc(1:7,i)=tanh(-toc(1:7,i)/2) - enddo - - do j=1,N - do i=1,ncw - ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j - Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) - call platanh(-Tmn,y) -! y=atanh(-Tmn) - tov(i,j)=2*y - enddo - enddo - -enddo -nharderror=-1 -return -end subroutine bpdecode174_91 +subroutine bpdecode174_91(llr,apmask,maxiterations,message77,cw,nharderror,iter,ncheck) +! +! A log-domain belief propagation decoder for the (174,91) code. +! +use iso_c_binding, only: c_loc,c_size_t +use crc +integer, parameter:: N=174, K=91, M=N-K +integer*1 cw(N),apmask(N) +integer*1 decoded(K) +integer*1 message77(77) +integer nrw(M),ncw +integer Nm(7,M) +integer Mn(3,N) ! 3 checks per bit +integer synd(M) +real tov(3,N) +real toc(7,M) +real tanhtoc(7,M) +real zn(N) +real llr(N) +real Tmn + +include "ldpc_174_91_c_parity.f90" + +decoded=0 +toc=0 +tov=0 +tanhtoc=0 +! initialize messages to checks +do j=1,M + do i=1,nrw(j) + toc(i,j)=llr((Nm(i,j))) + enddo +enddo + +ncnt=0 +nclast=0 + +do iter=0,maxiterations + +! Update bit log likelihood ratios (tov=0 in iteration 0). + do i=1,N + if( apmask(i) .ne. 1 ) then + zn(i)=llr(i)+sum(tov(1:ncw,i)) + else + zn(i)=llr(i) + endif + enddo + +! Check to see if we have a codeword (check before we do any iteration). + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(1:nrw(i),i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 +! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied' + enddo +! write(*,*) 'number of unsatisfied parity checks ',ncheck + if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it + decoded=cw(1:K) + call chkcrc14a(decoded,nbadcrc) + nharderror=count( (2*cw-1)*llr .lt. 0.0 ) + if(nbadcrc.eq.0) then + message77=decoded(1:77) + return + endif + endif + + if( iter.gt.0 ) then ! this code block implements an early stopping criterion +! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion + nd=ncheck-nclast + if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased + ncnt=0 ! reset counter + else + ncnt=ncnt+1 + endif +! write(*,*) iter,ncheck,nd,ncnt + if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then + nharderror=-1 + + return + endif + endif + nclast=ncheck + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw(j) + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,ncw ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then + toc(i,j)=toc(i,j)-tov(kk,ibj) + endif + enddo + enddo + enddo + +! send messages from check nodes to variable nodes + do i=1,M + tanhtoc(1:7,i)=tanh(-toc(1:7,i)/2) + enddo + + do j=1,N + do i=1,ncw + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) + call platanh(-Tmn,y) +! y=atanh(-Tmn) + tov(i,j)=2*y + enddo + enddo + +enddo +nharderror=-1 +return +end subroutine bpdecode174_91 diff --git a/lib/ft8/chkcrc13a.f90 b/lib/ft8/chkcrc13a.f90 index e35a92a1..25e14584 100755 --- a/lib/ft8/chkcrc13a.f90 +++ b/lib/ft8/chkcrc13a.f90 @@ -1,24 +1,24 @@ -subroutine chkcrc13a(decoded,nbadcrc) - - use crc - integer*1 decoded(90) - integer*1, target:: i1Dec8BitBytes(12) - character*90 cbits - -! Write decoded bits into cbits: 77-bit message plus 13-bit CRC - write(cbits,1000) decoded -1000 format(90i1) - read(cbits,1001) i1Dec8BitBytes -1001 format(12b8) - read(cbits,1002) ncrc13 !Received CRC13 -1002 format(77x,b13) - - i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),transfer(128+64+32+16+8,0_1)) - i1Dec8BitBytes(11:12)=0 - icrc13=crc13(c_loc(i1Dec8BitBytes),12) !CRC13 computed from 77 msg bits - - nbadcrc=1 - if(ncrc13.eq.icrc13) nbadcrc=0 - - return -end subroutine chkcrc13a +subroutine chkcrc13a(decoded,nbadcrc) + + use crc + integer*1 decoded(90) + integer*1, target:: i1Dec8BitBytes(12) + character*90 cbits + +! Write decoded bits into cbits: 77-bit message plus 13-bit CRC + write(cbits,1000) decoded +1000 format(90i1) + read(cbits,1001) i1Dec8BitBytes +1001 format(12b8) + read(cbits,1002) ncrc13 !Received CRC13 +1002 format(77x,b13) + + i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),transfer(128+64+32+16+8,0_1)) + i1Dec8BitBytes(11:12)=0 + icrc13=crc13(c_loc(i1Dec8BitBytes),12) !CRC13 computed from 77 msg bits + + nbadcrc=1 + if(ncrc13.eq.icrc13) nbadcrc=0 + + return +end subroutine chkcrc13a diff --git a/lib/ft8/chkcrc14a.f90 b/lib/ft8/chkcrc14a.f90 index 75eac39f..9ecda9b2 100755 --- a/lib/ft8/chkcrc14a.f90 +++ b/lib/ft8/chkcrc14a.f90 @@ -1,24 +1,24 @@ -subroutine chkcrc14a(decoded,nbadcrc) - - use crc - integer*1 decoded(91) - integer*1, target:: i1Dec8BitBytes(12) - character*91 cbits - -! Write decoded bits into cbits: 77-bit message plus 14-bit CRC - write(cbits,1000) decoded -1000 format(91i1) - read(cbits,1001) i1Dec8BitBytes -1001 format(12b8) - read(cbits,1002) ncrc14 !Received CRC14 -1002 format(77x,b14) - - i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),transfer(128+64+32+16+8,0_1)) - i1Dec8BitBytes(11:12)=0 - icrc14=crc14(c_loc(i1Dec8BitBytes),12) !CRC14 computed from 77 msg bits - - nbadcrc=1 - if(ncrc14.eq.icrc14) nbadcrc=0 - - return -end subroutine chkcrc14a +subroutine chkcrc14a(decoded,nbadcrc) + + use crc + integer*1 decoded(91) + integer*1, target:: i1Dec8BitBytes(12) + character*91 cbits + +! Write decoded bits into cbits: 77-bit message plus 14-bit CRC + write(cbits,1000) decoded +1000 format(91i1) + read(cbits,1001) i1Dec8BitBytes +1001 format(12b8) + read(cbits,1002) ncrc14 !Received CRC14 +1002 format(77x,b14) + + i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),transfer(128+64+32+16+8,0_1)) + i1Dec8BitBytes(11:12)=0 + icrc14=crc14(c_loc(i1Dec8BitBytes),12) !CRC14 computed from 77 msg bits + + nbadcrc=1 + if(ncrc14.eq.icrc14) nbadcrc=0 + + return +end subroutine chkcrc14a diff --git a/lib/ft8/chkdec.f90 b/lib/ft8/chkdec.f90 index ddd9cf7f..7a5e7618 100755 --- a/lib/ft8/chkdec.f90 +++ b/lib/ft8/chkdec.f90 @@ -1,161 +1,161 @@ -program chkdec - - parameter(NMAX=100) - character*88 line - character*37 msg(NMAX),msg0,msg1 - character*2 c2(NMAX) - character*1 c1(NMAX) - character*1 only - integer nsnr(NMAX,0:1),nf(NMAX,0:1) - real dt(NMAX,0:1) - logical found,eof - -! These files are sorted by freq within each Rx sequence - open(10,file='all.wsjtx',status='old') - open(11,file='all.jtdx',status='old') - write(20,1030) -1030 format(' iseq B w j W W+ J E B w j W', & - ' W+ J E'/80('-')) - - nutc0=-1 - nbt=0 !Both - nwt=0 !WSJT-X only - njt=0 !JTDX only - net=0 !Either - n7t=0 !a7 - eof=.false. - - do iseq=1,9999 - j=0 - msg=' ' - nsnr=-99 - nf=-99 - dt=-99 - c1=' ' - c2=' ' - do i=1,NMAX - read(10,'(a88)',end=8) line !Read from the WSJT-X file - if(line(25:30).ne.'Rx FT8') cycle !Ignore any line not an FT8 decode - read(line(8:13),*) nutc - if(nutc0.lt.0) nutc0=nutc !First time only - if(nutc.ne.nutc0) then - backspace(10) - go to 10 !Finished WSJT-X for this sequence - endif - j=j+1 - if(j.eq.1) then - nf(j,0)=-1 - j=j+1 - endif - read(line,1001) nsnr(j,0),dt(j,0),nf(j,0),msg(j),c2(j) -1001 format(30x,i7,f5.1,i5,1x,a36,2x,a2) -! if(nutc.eq.180215 .and. c2(j).eq.'a7') print*,'aaa',j,nf(j,0),c2(j) - nutc0=nutc - enddo ! i - -8 eof=.true. -10 jz=j - do i=1,NMAX - read(11,'(a88)',end=20) line !Read from the JTDX file - if(line(31:31).ne.'~') cycle !Ignore any line not an FT8 decode - read(line(10:15),*) nutc - if(nutc.ne.nutc0) then - backspace(11) - go to 20 !Finished JTDX for this sequence - endif - msg1=line(33:58) - read(line(25:29),*) nf1 - found=.false. - do j=1,jz - if(msg(j).eq.msg1) then - read(line,1002) nsnr(j,1),dt(j,1),nf(j,1),c1(j) -1002 format(15x,i4,f5.1,i5,29x,a1) - found=.true. - exit - endif - i1=index(msg(j),'<') - if(i1.gt.0) then - i2=index(msg(j),'>') - msg0=msg(j)(1:i1-1)//msg(j)(i1+1:i2-1)//msg(j)(i2+1:) - if(msg0.eq.msg1) then - read(line,1002) nsnr(j,1),dt(j,1),nf(j,1),c1(j) - found=.true. - exit - endif - endif - enddo ! j - - if(.not.found) then !Insert this one as a new message - do j=1,jz - if(nf1.ge.nf(j,0) .and. nf1.lt.nf(j+1,0)) then - jj=j+1 - exit - endif - enddo - do j=jz+1,jj+1,-1 - nsnr(j,0)=nsnr(j-1,0) - dt(j,0)=dt(j-1,0) - nf(j,0)=nf(j-1,0) - msg(j)=msg(j-1) - c1(j)=c1(j-1) - c2(j)=c2(j-1) - enddo ! j - read(line,1004) nsnr(jj,1),dt(jj,1),nf(jj,1),msg(jj),c1(jj) -1004 format(15x,i4,f5.1,i5,3x,a26,a1) - c2(jj)=' ' - nsnr(jj,0)=-99 - dt(jj,0)=-99.0 - nf(jj,0)=-99 - jz=jz+1 - endif - enddo ! i - -20 nb=0 - nw=0 - nj=0 - ne=0 - n7=0 - do j=2,jz - write(line,1020) nutc0,j,nsnr(j,:),dt(j,:),nf(j,:),msg(j)(1:26), & - c2(j),c1(j) -1020 format(i6.6,i3,1x,2i4,1x,2f6.1,1x,2i5,1x,a26,1x,a2,1x,a1) - if(c2(j).eq.'a7') n7=n7+1 - only=' ' - if(line(12:14).eq.'-99') then - line(12:14)=' ' - only='j' - nj=nj+1 -! if(c2(j).eq.'a7') print*,'aaa ',trim(line) - endif - if(line(16:18).eq.'-99') then - line(16:18)=' ' - only='w' - nw=nw+1 - endif - if(line(12:14).ne.' ' .or. line(16:19).ne.' ') ne=ne+1 - if(line(12:14).ne.' ' .and. line(16:19).ne.' ') nb=nb+1 - if(line(21:25).eq.'-99.0') line(21:25)=' ' - if(line(27:31).eq.'-99.0') line(27:31)=' ' - if(line(35:37).eq.'-99') line(35:37)=' ' - if(line(40:42).eq.'-99') line(40:42)=' ' -! if(line(12:14).ne.' ') nw=nw+1 -! if(line(16:18).ne.' ') nj=nj+1 - write(*,'(a74,1x,a1)') line(1:74),only - enddo ! j - - nbt=nbt+nb - nwt=nwt+nw - n7t=n7t+n7 - njt=njt+nj - net=net+ne - nutc0=nutc - write(*,*) - - write(20,1031) iseq,nb,nw,nj,nb+nw-n7,nb+nw,nb+nj,ne,nbt,nwt,njt, & - nbt+nwt-n7t,nbt+nwt,nbt+njt,net -1031 format(i5,2x,7i4,2x,7i6) - if(eof) exit -! if(iseq.eq.2) exit - enddo ! iseq - -end program chkdec +program chkdec + + parameter(NMAX=100) + character*88 line + character*37 msg(NMAX),msg0,msg1 + character*2 c2(NMAX) + character*1 c1(NMAX) + character*1 only + integer nsnr(NMAX,0:1),nf(NMAX,0:1) + real dt(NMAX,0:1) + logical found,eof + +! These files are sorted by freq within each Rx sequence + open(10,file='all.wsjtx',status='old') + open(11,file='all.jtdx',status='old') + write(20,1030) +1030 format(' iseq B w j W W+ J E B w j W', & + ' W+ J E'/80('-')) + + nutc0=-1 + nbt=0 !Both + nwt=0 !WSJT-X only + njt=0 !JTDX only + net=0 !Either + n7t=0 !a7 + eof=.false. + + do iseq=1,9999 + j=0 + msg=' ' + nsnr=-99 + nf=-99 + dt=-99 + c1=' ' + c2=' ' + do i=1,NMAX + read(10,'(a88)',end=8) line !Read from the WSJT-X file + if(line(25:30).ne.'Rx FT8') cycle !Ignore any line not an FT8 decode + read(line(8:13),*) nutc + if(nutc0.lt.0) nutc0=nutc !First time only + if(nutc.ne.nutc0) then + backspace(10) + go to 10 !Finished WSJT-X for this sequence + endif + j=j+1 + if(j.eq.1) then + nf(j,0)=-1 + j=j+1 + endif + read(line,1001) nsnr(j,0),dt(j,0),nf(j,0),msg(j),c2(j) +1001 format(30x,i7,f5.1,i5,1x,a36,2x,a2) +! if(nutc.eq.180215 .and. c2(j).eq.'a7') print*,'aaa',j,nf(j,0),c2(j) + nutc0=nutc + enddo ! i + +8 eof=.true. +10 jz=j + do i=1,NMAX + read(11,'(a88)',end=20) line !Read from the JTDX file + if(line(31:31).ne.'~') cycle !Ignore any line not an FT8 decode + read(line(10:15),*) nutc + if(nutc.ne.nutc0) then + backspace(11) + go to 20 !Finished JTDX for this sequence + endif + msg1=line(33:58) + read(line(25:29),*) nf1 + found=.false. + do j=1,jz + if(msg(j).eq.msg1) then + read(line,1002) nsnr(j,1),dt(j,1),nf(j,1),c1(j) +1002 format(15x,i4,f5.1,i5,29x,a1) + found=.true. + exit + endif + i1=index(msg(j),'<') + if(i1.gt.0) then + i2=index(msg(j),'>') + msg0=msg(j)(1:i1-1)//msg(j)(i1+1:i2-1)//msg(j)(i2+1:) + if(msg0.eq.msg1) then + read(line,1002) nsnr(j,1),dt(j,1),nf(j,1),c1(j) + found=.true. + exit + endif + endif + enddo ! j + + if(.not.found) then !Insert this one as a new message + do j=1,jz + if(nf1.ge.nf(j,0) .and. nf1.lt.nf(j+1,0)) then + jj=j+1 + exit + endif + enddo + do j=jz+1,jj+1,-1 + nsnr(j,0)=nsnr(j-1,0) + dt(j,0)=dt(j-1,0) + nf(j,0)=nf(j-1,0) + msg(j)=msg(j-1) + c1(j)=c1(j-1) + c2(j)=c2(j-1) + enddo ! j + read(line,1004) nsnr(jj,1),dt(jj,1),nf(jj,1),msg(jj),c1(jj) +1004 format(15x,i4,f5.1,i5,3x,a26,a1) + c2(jj)=' ' + nsnr(jj,0)=-99 + dt(jj,0)=-99.0 + nf(jj,0)=-99 + jz=jz+1 + endif + enddo ! i + +20 nb=0 + nw=0 + nj=0 + ne=0 + n7=0 + do j=2,jz + write(line,1020) nutc0,j,nsnr(j,:),dt(j,:),nf(j,:),msg(j)(1:26), & + c2(j),c1(j) +1020 format(i6.6,i3,1x,2i4,1x,2f6.1,1x,2i5,1x,a26,1x,a2,1x,a1) + if(c2(j).eq.'a7') n7=n7+1 + only=' ' + if(line(12:14).eq.'-99') then + line(12:14)=' ' + only='j' + nj=nj+1 +! if(c2(j).eq.'a7') print*,'aaa ',trim(line) + endif + if(line(16:18).eq.'-99') then + line(16:18)=' ' + only='w' + nw=nw+1 + endif + if(line(12:14).ne.' ' .or. line(16:19).ne.' ') ne=ne+1 + if(line(12:14).ne.' ' .and. line(16:19).ne.' ') nb=nb+1 + if(line(21:25).eq.'-99.0') line(21:25)=' ' + if(line(27:31).eq.'-99.0') line(27:31)=' ' + if(line(35:37).eq.'-99') line(35:37)=' ' + if(line(40:42).eq.'-99') line(40:42)=' ' +! if(line(12:14).ne.' ') nw=nw+1 +! if(line(16:18).ne.' ') nj=nj+1 + write(*,'(a74,1x,a1)') line(1:74),only + enddo ! j + + nbt=nbt+nb + nwt=nwt+nw + n7t=n7t+n7 + njt=njt+nj + net=net+ne + nutc0=nutc + write(*,*) + + write(20,1031) iseq,nb,nw,nj,nb+nw-n7,nb+nw,nb+nj,ne,nbt,nwt,njt, & + nbt+nwt-n7t,nbt+nwt,nbt+njt,net +1031 format(i5,2x,7i4,2x,7i6) + if(eof) exit +! if(iseq.eq.2) exit + enddo ! iseq + +end program chkdec diff --git a/lib/ft8/decode174_91.f90 b/lib/ft8/decode174_91.f90 index a4d82c56..134864d9 100755 --- a/lib/ft8/decode174_91.f90 +++ b/lib/ft8/decode174_91.f90 @@ -1,155 +1,155 @@ -subroutine decode174_91(llr,Keff,maxosd,norder,apmask,message91,cw,ntype,nharderror,dmin) -! -! A hybrid bp/osd decoder for the (174,91) code. -! -! maxosd<0: do bp only -! maxosd=0: do bp and then call osd once with channel llrs -! maxosd>1: do bp and then call osd maxosd times with saved bp outputs -! norder : osd decoding depth -! - integer, parameter:: N=174, K=91, M=N-K - integer*1 cw(N),apmask(N) - integer*1 nxor(N),hdec(N) - integer*1 message91(91),m96(96) - integer nrw(M),ncw - integer Nm(7,M) - integer Mn(3,N) ! 3 checks per bit - integer synd(M) - real tov(3,N) - real toc(7,M) - real tanhtoc(7,M) - real zn(N),zsum(N),zsave(N,3) - real llr(N) - real Tmn - - include "ldpc_174_91_c_parity.f90" - - maxiterations=30 - nosd=0 - if(maxosd.gt.3) maxosd=3 - if(maxosd.eq.0) then ! osd with channel llrs - nosd=1 - zsave(:,1)=llr - elseif(maxosd.gt.0) then ! - nosd=maxosd - elseif(maxosd.lt.0) then ! just bp - nosd=0 - endif - - toc=0 - tov=0 - tanhtoc=0 -! initialize messages to checks - do j=1,M - do i=1,nrw(j) - toc(i,j)=llr((Nm(i,j))) - enddo - enddo - - ncnt=0 - nclast=0 - zsum=0.0 - do iter=0,maxiterations -! Update bit log likelihood ratios (tov=0 in iteration 0). - do i=1,N - if( apmask(i) .ne. 1 ) then - zn(i)=llr(i)+sum(tov(1:ncw,i)) - else - zn(i)=llr(i) - endif - enddo - zsum=zsum+zn - if(iter.gt.0 .and. iter.le.maxosd) then - zsave(:,iter)=zsum - endif - -! Check to see if we have a codeword (check before we do any iteration). - cw=0 - where( zn .gt. 0. ) cw=1 - ncheck=0 - do i=1,M - synd(i)=sum(cw(Nm(1:nrw(i),i))) - if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 - enddo - if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it - m96=0 - m96(1:77)=cw(1:77) - m96(83:96)=cw(78:91) - call get_crc14(m96,96,nbadcrc) - nharderror=count( (2*cw-1)*llr .lt. 0.0 ) - if(nbadcrc.eq.0) then - message91=cw(1:91) - hdec=0 - where(llr .ge. 0) hdec=1 - nxor=ieor(hdec,cw) - dmin=sum(nxor*abs(llr)) - ntype=1 - return - endif - endif - - if( iter.gt.0 ) then ! this code block implements an early stopping criterion -! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion - nd=ncheck-nclast - if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased - ncnt=0 ! reset counter - else - ncnt=ncnt+1 - endif -! write(*,*) iter,ncheck,nd,ncnt - if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then - nharderror=-1 - exit - endif - endif - nclast=ncheck - -! Send messages from bits to check nodes - do j=1,M - do i=1,nrw(j) - ibj=Nm(i,j) - toc(i,j)=zn(ibj) - do kk=1,ncw ! subtract off what the bit had received from the check - if( Mn(kk,ibj) .eq. j ) then - toc(i,j)=toc(i,j)-tov(kk,ibj) - endif - enddo - enddo - enddo - -! send messages from check nodes to variable nodes - do i=1,M - tanhtoc(1:7,i)=tanh(-toc(1:7,i)/2) - enddo - - do j=1,N - do i=1,ncw - ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j - Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) - call platanh(-Tmn,y) -! y=atanh(-Tmn) - tov(i,j)=2*y - enddo - enddo - - enddo ! bp iterations - - do i=1,nosd - zn=zsave(:,i) - call osd174_91(zn,Keff,apmask,norder,message91,cw,nharderror,dminosd) - if(nharderror.gt.0) then - hdec=0 - where(llr .ge. 0) hdec=1 - nxor=ieor(hdec,cw) - dmin=sum(nxor*abs(llr)) - ntype=2 - return - endif - enddo - - ntype=0 - nharderror=-1 - dminosd=0.0 - - return -end subroutine decode174_91 +subroutine decode174_91(llr,Keff,maxosd,norder,apmask,message91,cw,ntype,nharderror,dmin) +! +! A hybrid bp/osd decoder for the (174,91) code. +! +! maxosd<0: do bp only +! maxosd=0: do bp and then call osd once with channel llrs +! maxosd>1: do bp and then call osd maxosd times with saved bp outputs +! norder : osd decoding depth +! + integer, parameter:: N=174, K=91, M=N-K + integer*1 cw(N),apmask(N) + integer*1 nxor(N),hdec(N) + integer*1 message91(91),m96(96) + integer nrw(M),ncw + integer Nm(7,M) + integer Mn(3,N) ! 3 checks per bit + integer synd(M) + real tov(3,N) + real toc(7,M) + real tanhtoc(7,M) + real zn(N),zsum(N),zsave(N,3) + real llr(N) + real Tmn + + include "ldpc_174_91_c_parity.f90" + + maxiterations=30 + nosd=0 + if(maxosd.gt.3) maxosd=3 + if(maxosd.eq.0) then ! osd with channel llrs + nosd=1 + zsave(:,1)=llr + elseif(maxosd.gt.0) then ! + nosd=maxosd + elseif(maxosd.lt.0) then ! just bp + nosd=0 + endif + + toc=0 + tov=0 + tanhtoc=0 +! initialize messages to checks + do j=1,M + do i=1,nrw(j) + toc(i,j)=llr((Nm(i,j))) + enddo + enddo + + ncnt=0 + nclast=0 + zsum=0.0 + do iter=0,maxiterations +! Update bit log likelihood ratios (tov=0 in iteration 0). + do i=1,N + if( apmask(i) .ne. 1 ) then + zn(i)=llr(i)+sum(tov(1:ncw,i)) + else + zn(i)=llr(i) + endif + enddo + zsum=zsum+zn + if(iter.gt.0 .and. iter.le.maxosd) then + zsave(:,iter)=zsum + endif + +! Check to see if we have a codeword (check before we do any iteration). + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(1:nrw(i),i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 + enddo + if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it + m96=0 + m96(1:77)=cw(1:77) + m96(83:96)=cw(78:91) + call get_crc14(m96,96,nbadcrc) + nharderror=count( (2*cw-1)*llr .lt. 0.0 ) + if(nbadcrc.eq.0) then + message91=cw(1:91) + hdec=0 + where(llr .ge. 0) hdec=1 + nxor=ieor(hdec,cw) + dmin=sum(nxor*abs(llr)) + ntype=1 + return + endif + endif + + if( iter.gt.0 ) then ! this code block implements an early stopping criterion +! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion + nd=ncheck-nclast + if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased + ncnt=0 ! reset counter + else + ncnt=ncnt+1 + endif +! write(*,*) iter,ncheck,nd,ncnt + if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then + nharderror=-1 + exit + endif + endif + nclast=ncheck + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw(j) + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,ncw ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then + toc(i,j)=toc(i,j)-tov(kk,ibj) + endif + enddo + enddo + enddo + +! send messages from check nodes to variable nodes + do i=1,M + tanhtoc(1:7,i)=tanh(-toc(1:7,i)/2) + enddo + + do j=1,N + do i=1,ncw + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) + call platanh(-Tmn,y) +! y=atanh(-Tmn) + tov(i,j)=2*y + enddo + enddo + + enddo ! bp iterations + + do i=1,nosd + zn=zsave(:,i) + call osd174_91(zn,Keff,apmask,norder,message91,cw,nharderror,dminosd) + if(nharderror.gt.0) then + hdec=0 + where(llr .ge. 0) hdec=1 + nxor=ieor(hdec,cw) + dmin=sum(nxor*abs(llr)) + ntype=2 + return + endif + enddo + + ntype=0 + nharderror=-1 + dminosd=0.0 + + return +end subroutine decode174_91 diff --git a/lib/ft8/encode174.f90 b/lib/ft8/encode174.f90 index 2a14614b..599f1064 100755 --- a/lib/ft8/encode174.f90 +++ b/lib/ft8/encode174.f90 @@ -1,50 +1,50 @@ -subroutine encode174(message,codeword) -! Encode an 87-bit message and return a 174-bit codeword. -! The generator matrix has dimensions (87,87). -! The code is a (174,87) regular ldpc code with column weight 3. -! The code was generated using the PEG algorithm. -! After creating the codeword, the columns are re-ordered according to -! "colorder" to make the codeword compatible with the parity-check matrix -! - -include "ldpc_174_87_params.f90" - -integer*1 codeword(N) -integer*1 gen(M,K) -integer*1 itmp(N) -integer*1 message(K) -integer*1 pchecks(M) -logical first -data first/.true./ - -save first,gen - -if( first ) then ! fill the generator matrix - gen=0 - do i=1,M - do j=1,11 - read(g(i)( (j-1)*2+1:(j-1)*2+2 ),"(Z2)") istr - do jj=1, 8 - icol=(j-1)*8+jj - if( icol .le. 87 ) then - if( btest(istr,8-jj) ) gen(i,icol)=1 - endif - enddo - enddo - enddo -first=.false. -endif - -do i=1,M - nsum=0 - do j=1,K - nsum=nsum+message(j)*gen(i,j) - enddo - pchecks(i)=mod(nsum,2) -enddo -itmp(1:M)=pchecks -itmp(M+1:N)=message(1:K) -codeword(colorder+1)=itmp(1:N) - -return -end subroutine encode174 +subroutine encode174(message,codeword) +! Encode an 87-bit message and return a 174-bit codeword. +! The generator matrix has dimensions (87,87). +! The code is a (174,87) regular ldpc code with column weight 3. +! The code was generated using the PEG algorithm. +! After creating the codeword, the columns are re-ordered according to +! "colorder" to make the codeword compatible with the parity-check matrix +! + +include "ldpc_174_87_params.f90" + +integer*1 codeword(N) +integer*1 gen(M,K) +integer*1 itmp(N) +integer*1 message(K) +integer*1 pchecks(M) +logical first +data first/.true./ + +save first,gen + +if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,11 + read(g(i)( (j-1)*2+1:(j-1)*2+2 ),"(Z2)") istr + do jj=1, 8 + icol=(j-1)*8+jj + if( icol .le. 87 ) then + if( btest(istr,8-jj) ) gen(i,icol)=1 + endif + enddo + enddo + enddo +first=.false. +endif + +do i=1,M + nsum=0 + do j=1,K + nsum=nsum+message(j)*gen(i,j) + enddo + pchecks(i)=mod(nsum,2) +enddo +itmp(1:M)=pchecks +itmp(M+1:N)=message(1:K) +codeword(colorder+1)=itmp(1:N) + +return +end subroutine encode174 diff --git a/lib/ft8/encode174_91.f90 b/lib/ft8/encode174_91.f90 index b94529dc..5bae7d56 100755 --- a/lib/ft8/encode174_91.f90 +++ b/lib/ft8/encode174_91.f90 @@ -1,58 +1,58 @@ -subroutine encode174_91(message77,codeword) -! -! Add a 14-bit CRC to a 77-bit message and return a 174-bit codeword -! - use, intrinsic :: iso_c_binding - use iso_c_binding, only: c_loc,c_size_t - use crc - - integer, parameter:: N=174, K=91, M=N-K - character*91 tmpchar - integer*1 codeword(N) - integer*1 gen(M,K) - integer*1 message77(77),message(K) - integer*1 pchecks(M) - integer*1, target :: i1MsgBytes(12) - include "ldpc_174_91_c_generator.f90" - logical first - data first/.true./ - save first,gen - - if( first ) then ! fill the generator matrix - gen=0 - do i=1,M - do j=1,23 - read(g(i)(j:j),"(Z1)") istr - ibmax=4 - if(j.eq.23) ibmax=3 - do jj=1, ibmax - icol=(j-1)*4+jj - if( btest(istr,4-jj) ) gen(i,icol)=1 - enddo - enddo - enddo - first=.false. - endif - -! Add 14-bit CRC to form 91-bit message+CRC14 - write(tmpchar,'(77i1)') message77 - tmpchar(78:80)='000' - i1MsgBytes=0 - read(tmpchar,'(10b8)') i1MsgBytes(1:10) - ncrc14 = crc14 (c_loc (i1MsgBytes), 12) - write(tmpchar(78:91),'(b14)') ncrc14 - read(tmpchar,'(91i1)') message - - do i=1,M - nsum=0 - do j=1,K - nsum=nsum+message(j)*gen(i,j) - enddo - pchecks(i)=mod(nsum,2) - enddo - - codeword(1:K)=message - codeword(K+1:N)=pchecks - - return -end subroutine encode174_91 +subroutine encode174_91(message77,codeword) +! +! Add a 14-bit CRC to a 77-bit message and return a 174-bit codeword +! + use, intrinsic :: iso_c_binding + use iso_c_binding, only: c_loc,c_size_t + use crc + + integer, parameter:: N=174, K=91, M=N-K + character*91 tmpchar + integer*1 codeword(N) + integer*1 gen(M,K) + integer*1 message77(77),message(K) + integer*1 pchecks(M) + integer*1, target :: i1MsgBytes(12) + include "ldpc_174_91_c_generator.f90" + logical first + data first/.true./ + save first,gen + + if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,23 + read(g(i)(j:j),"(Z1)") istr + ibmax=4 + if(j.eq.23) ibmax=3 + do jj=1, ibmax + icol=(j-1)*4+jj + if( btest(istr,4-jj) ) gen(i,icol)=1 + enddo + enddo + enddo + first=.false. + endif + +! Add 14-bit CRC to form 91-bit message+CRC14 + write(tmpchar,'(77i1)') message77 + tmpchar(78:80)='000' + i1MsgBytes=0 + read(tmpchar,'(10b8)') i1MsgBytes(1:10) + ncrc14 = crc14 (c_loc (i1MsgBytes), 12) + write(tmpchar(78:91),'(b14)') ncrc14 + read(tmpchar,'(91i1)') message + + do i=1,M + nsum=0 + do j=1,K + nsum=nsum+message(j)*gen(i,j) + enddo + pchecks(i)=mod(nsum,2) + enddo + + codeword(1:K)=message + codeword(K+1:N)=pchecks + + return +end subroutine encode174_91 diff --git a/lib/ft8/encode174_91_nocrc.f90 b/lib/ft8/encode174_91_nocrc.f90 index 1a05425e..82d1669d 100755 --- a/lib/ft8/encode174_91_nocrc.f90 +++ b/lib/ft8/encode174_91_nocrc.f90 @@ -1,47 +1,47 @@ -subroutine encode174_91_nocrc(message,codeword) -! -! Encode a 91-bit message and return a 174-bit codeword. -! - use, intrinsic :: iso_c_binding - use iso_c_binding, only: c_loc,c_size_t - use crc - - integer, parameter:: N=174, K=91, M=N-K - integer*1 codeword(N) - integer*1 gen(M,K) - integer*1 message(K) - integer*1 pchecks(M) - include "ldpc_174_91_c_generator.f90" - logical first - data first/.true./ - save first,gen - - if( first ) then ! fill the generator matrix - gen=0 - do i=1,M - do j=1,23 - read(g(i)(j:j),"(Z1)") istr - ibmax=4 - if(j.eq.23) ibmax=3 - do jj=1, ibmax - icol=(j-1)*4+jj - if( btest(istr,4-jj) ) gen(i,icol)=1 - enddo - enddo - enddo - first=.false. - endif - - do i=1,M - nsum=0 - do j=1,K - nsum=nsum+message(j)*gen(i,j) - enddo - pchecks(i)=mod(nsum,2) - enddo - - codeword(1:K)=message - codeword(K+1:N)=pchecks - - return -end subroutine encode174_91_nocrc +subroutine encode174_91_nocrc(message,codeword) +! +! Encode a 91-bit message and return a 174-bit codeword. +! + use, intrinsic :: iso_c_binding + use iso_c_binding, only: c_loc,c_size_t + use crc + + integer, parameter:: N=174, K=91, M=N-K + integer*1 codeword(N) + integer*1 gen(M,K) + integer*1 message(K) + integer*1 pchecks(M) + include "ldpc_174_91_c_generator.f90" + logical first + data first/.true./ + save first,gen + + if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,23 + read(g(i)(j:j),"(Z1)") istr + ibmax=4 + if(j.eq.23) ibmax=3 + do jj=1, ibmax + icol=(j-1)*4+jj + if( btest(istr,4-jj) ) gen(i,icol)=1 + enddo + enddo + enddo + first=.false. + endif + + do i=1,M + nsum=0 + do j=1,K + nsum=nsum+message(j)*gen(i,j) + enddo + pchecks(i)=mod(nsum,2) + enddo + + codeword(1:K)=message + codeword(K+1:N)=pchecks + + return +end subroutine encode174_91_nocrc diff --git a/lib/ft8/ft8_a7.f90 b/lib/ft8/ft8_a7.f90 index a7af8c81..56217601 100755 --- a/lib/ft8/ft8_a7.f90 +++ b/lib/ft8/ft8_a7.f90 @@ -1,378 +1,378 @@ -module ft8_a7 - - parameter(MAXDEC=200) - -! For the following three arrays -! First index i=decode number in this sequence -! Second index j=0 or 1 for even or odd sequence -! Third index k=0 or 1 for previous or current tally for this j - real dt0(MAXDEC,0:1,0:1) !dt0(i,j,k) - real f0(MAXDEC,0:1,0:1) !f0(i,j,k) - character*37 msg0(MAXDEC,0:1,0:1) !msg0(i,j,k) - - integer itone_a7(79) - integer jseq !even=0, odd=1 - integer ndec(0:1,0:1) !ndec(j,k) - data ndec/4*0/,jseq/0/ - -contains - -subroutine ft8_a7_save(nutc,dt,f,msg) - - use packjt77 - character*37 msg,msg1 - character*13 w(19) - character*4 g4 - integer nw(19) - logical isgrid4 - -! Statement function: - isgrid4(g4)=(len_trim(g4).eq.4 .and. & - ichar(g4(1:1)).ge.ichar('A') .and. ichar(g4(1:1)).le.ichar('R') .and. & - ichar(g4(2:2)).ge.ichar('A') .and. ichar(g4(2:2)).le.ichar('R') .and. & - ichar(g4(3:3)).ge.ichar('0') .and. ichar(g4(3:3)).le.ichar('9') .and. & - ichar(g4(4:4)).ge.ichar('0') .and. ichar(g4(4:4)).le.ichar('9')) - - if(index(msg,'/').ge.1 .or. index(msg,'<').ge.1) go to 999 - call split77(msg,nwords,nw,w) !Parse msg into words - if(nwords.lt.1) go to 999 - if(w(1)(1:3).eq.'CQ_') go to 999 - j=mod(nutc/5,2) !j is 0 or 1 for odd/even sequence - jseq=j - -! Add this decode to current table for this sequence - ndec(j,1)=ndec(j,1)+1 !Number of decodes in this sequence - i=ndec(j,1) !i is index of a new table entry - if(i.gt.MAXDEC) return !Prevent table overflow (indexes start at 1) - - dt0(i,j,1)=dt !Save dt in table - f0(i,j,1)=f !Save f in table - msg0(i,j,1)=trim(w(1))//' '//trim(w(2)) !Save "call_1 call_2" - if(w(1)(1:3).eq.'CQ ' .and. nw(2).le.2) then - msg0(i,j,1)='CQ '//trim(w(2))//' '//trim(w(3)) !Save "CQ DX Call_2" - endif - msg1=msg0(i,j,1) !Message without grid - nn=len(trim(msg1)) !Message length without grid -! Include grid as part of message - if(isgrid4(w(nwords))) msg0(i,j,1)=trim(msg0(i,j,1))//' '//trim(w(nwords)) - -! If a transmission at this frequency with message fragment "call_1 call_2" -! was decoded in the previous sequence, flag it as "DO NOT USE" because -! we have already decoded and subtracted that station's next transmission. - - call split77(msg0(i,j,1),nwords,nw,w) !Parse msg into words - do i=1,ndec(j,0) - if(f0(i,j,0).le.-98.0) cycle - i2=index(msg0(i,j,0),' '//trim(w(2))) - if(abs(f-f0(i,j,0)).le.3.0 .and. i2.ge.3) then - f0(i,j,0)=-98.0 !Flag as "do not use" for a potential a7 decode - endif - enddo - -999 return -end subroutine ft8_a7_save - -subroutine ft8_a7d(dd0,newdat,call_1,call_2,grid4,xdt,f1,xbase,nharderrors,dmin, & - msg37,xsnr) - -! Examine the raw data in dd0() for possible "a7" decodes. - - use crc - use timer_module, only: timer - use packjt77 - include 'ft8_params.f90' - parameter(NP2=2812) - character*37 msg37,msg,msgsent,msgbest - character*12 call_1,call_2 - character*4 grid4 - real a(5) - real s8(0:7,NN) - real s2(0:511) - real dmm(206) - real bmeta(174),bmetb(174),bmetc(174),bmetd(174) - real llra(174),llrb(174),llrc(174),llrd(174) !Soft symbols - real dd0(15*12000) - real ss(9) - real rcw(174) - integer*1 cw(174) - integer*1 msgbits(77) - integer*1 nxor(174),hdec(174) - integer itone(NN) - integer icos7(0:6),ip(1) - logical one(0:511,0:8) - integer graymap(0:7) - integer iloc(1) - complex cd0(0:3199) - complex ctwk(32) - complex csymb(32) - complex cs(0:7,NN) - logical std_1,std_2 - logical first,newdat - data icos7/3,1,4,0,6,5,2/ !Sync array - data first/.true./ - data graymap/0,1,3,2,5,6,4,7/ - save one - - if(first) then - one=.false. - do i=0,511 - do j=0,8 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - first=.false. - endif - - call stdcall(call_1,std_1) - if(call_1(1:3).eq.'CQ ') std_1=.true. - call stdcall(call_2,std_2) - - fs2=12000.0/NDOWN - dt2=1.0/fs2 - twopi=8.0*atan(1.0) - delfbest=0. - ibest=0 - - call timer('ft8_down',0) - call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample - call timer('ft8_down',1) - - i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal - smax=0.0 - do idt=i0-10,i0+10 !Search over +/- one quarter symbol - call sync8d(cd0,idt,ctwk,0,sync) !NB: ctwk not used here - if(sync.gt.smax) then - smax=sync - ibest=idt - endif - enddo - -! Peak up in frequency - smax=0.0 - do ifr=-5,5 !Search over +/- 2.5 Hz - delf=ifr*0.5 - dphi=twopi*delf*dt2 - phi=0.0 - do i=1,32 - ctwk(i)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - enddo - call sync8d(cd0,ibest,ctwk,1,sync) - if( sync .gt. smax ) then - smax=sync - delfbest=delf - endif - enddo - a=0.0 - a(1)=-delfbest - call twkfreq1(cd0,NP2,fs2,a,cd0) - f1=f1+delfbest !Improved estimate of DF - - call timer('ft8_down',0) - call ft8_downsample(dd0,.false.,f1,cd0) !Mix f1 to baseband and downsample - call timer('ft8_down',1) - - smax=0.0 - do idt=-4,4 !Search over +/- one quarter symbol - call sync8d(cd0,ibest+idt,ctwk,0,sync) - ss(idt+5)=sync - enddo - smax=maxval(ss) - iloc=maxloc(ss) - ibest=iloc(1)-5+ibest - xdt=(ibest-1)*dt2 - 0.5 - sync=smax - - do k=1,NN - i1=ibest+(k-1)*32 - csymb=cmplx(0.0,0.0) - if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) - call four2a(csymb,32,1,-1,1) - cs(0:7,k)=csymb(1:8)/1e3 - s8(0:7,k)=abs(csymb(1:8)) - enddo - -! sync quality check - is1=0 - is2=0 - is3=0 - do k=1,7 - ip=maxloc(s8(:,k)) - if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 - ip=maxloc(s8(:,k+36)) - if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 - ip=maxloc(s8(:,k+72)) - if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 - enddo -! hard sync sum - max is 21 - nsync=is1+is2+is3 -! if(nsync .le. 6) return ! bail out - - do nsym=1,3 - nt=2**(3*nsym) - do ihalf=1,2 - do k=1,29,nsym - if(ihalf.eq.1) ks=k+7 - if(ihalf.eq.2) ks=k+43 - amax=-1.0 - do i=0,nt-1 - i1=i/64 - i2=iand(i,63)/8 - i3=iand(i,7) - if(nsym.eq.1) then - s2(i)=abs(cs(graymap(i3),ks)) - elseif(nsym.eq.2) then - s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) - elseif(nsym.eq.3) then - s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) - else - print*,"Error - nsym must be 1, 2, or 3." - endif - enddo - i32=1+(k-1)*3+(ihalf-1)*87 - if(nsym.eq.1) ibmax=2 - if(nsym.eq.2) ibmax=5 - if(nsym.eq.3) ibmax=8 - do ib=0,ibmax - bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) - if(i32+ib .gt.174) cycle - if(nsym.eq.1) then - bmeta(i32+ib)=bm - den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) - if(den.gt.0.0) then - cm=bm/den - else ! erase it - cm=0.0 - endif - bmetd(i32+ib)=cm - elseif(nsym.eq.2) then - bmetb(i32+ib)=bm - elseif(nsym.eq.3) then - bmetc(i32+ib)=bm - endif - enddo - enddo - enddo - enddo - call normalizebmet(bmeta,174) - call normalizebmet(bmetb,174) - call normalizebmet(bmetc,174) - call normalizebmet(bmetd,174) - - scalefac=2.83 - llra=scalefac*bmeta - llrb=scalefac*bmetb - llrc=scalefac*bmetc - llrd=scalefac*bmetd - -! apmag=maxval(abs(llra))*1.01 - - MAXMSG=206 - pbest=0. - dmin=1.e30 - nharderrors=-1 - - do imsg=1,MAXMSG - msg=trim(call_1)//' '//trim(call_2) - i=imsg - if(call_1(1:3).eq.'CQ ' .and. i.ne.5) msg='QU1RK '//trim(call_2) - if(.not.std_1) then - if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' - else if(.not.std_2) then - if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' - endif - j0=len(trim(msg))+2 - if(i.eq.2) msg(j0:j0+2)='RRR' - if(i.eq.3) msg(j0:j0+3)='RR73' - if(i.eq.4) msg(j0:j0+1)='73' - if(i.eq.5) then - if(std_2) then - msg='CQ '//trim(call_2) - if(call_1(3:3).eq.'_') msg=trim(call_1)//' '//trim(call_2) - if(grid4.ne.'RR73') msg=trim(msg)//' '//grid4 - endif - if(.not.std_2) msg='CQ '//trim(call_2) - endif - if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 - if(i.ge.7) then - isnr = -50 + (i-7)/2 - if(iand(i,1).eq.1) then - write(msg(j0:j0+2),'(i3.2)') isnr - if(msg(j0:j0).eq.' ') msg(j0:j0)='+' - else - write(msg(j0:j0+3),'("R",i3.2)') isnr - if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' - endif - endif - - i3=-1 - n3=-1 - call genft8(msg,i3,n3,msgsent,msgbits,itone) !Source-encode this message - call encode174_91(msgbits,cw) !Get codeword for this message - rcw=2*cw-1 - pow=0.0 - do i=1,79 - pow=pow+s8(itone(i),i)**2 - enddo - - hdec=0 - where(llra.ge.0.0) hdec=1 - nxor=ieor(hdec,cw) - da=sum(nxor*abs(llra)) - - hdec=0 - where(llrb.ge.0.0) hdec=1 - nxor=ieor(hdec,cw) - dbb=sum(nxor*abs(llrb)) - - hdec=0 - where(llrc.ge.0.0) hdec=1 - nxor=ieor(hdec,cw) - dc=sum(nxor*abs(llrc)) - - hdec=0 - where(llrd.ge.0.0) hdec=1 - nxor=ieor(hdec,cw) - dd=sum(nxor*abs(llrd)) - - dm=min(da,dbb,dc,dd) - dmm(imsg)=dm - if(dm.lt.dmin) then - dmin=dm - msgbest=msgsent - pbest=pow - if(dm.eq.da) then - nharderrors=count((2*cw-1)*llra.lt.0.0) - else if(dm.eq.dbb) then - nharderrors=count((2*cw-1)*llrb.lt.0.0) - else if(dm.eq.dc) then - nharderrors=count((2*cw-1)*llrc.lt.0.0) - else if(dm.eq.dd) then - nharderrors=count((2*cw-1)*llrd.lt.0.0) - endif - endif - - enddo ! imsg - - iloc=minloc(dmm) - dmm(iloc(1))=1.e30 - iloc=minloc(dmm) - dmin2=dmm(iloc(1)) - xsnr=-24. - arg=pbest/xbase/3.0e6-1.0 - if(arg.gt.0.0) xsnr=max(-24.0,db(arg)-27.0) -! write(41,3041) nharderrors,dmin,dmin2,dmin2/dmin,xsnr,trim(msgbest) -!3041 format(i3,2f7.1,f7.2,f7.1,1x,a) - if(dmin.gt.100.0 .or. dmin2/dmin.lt.1.3) nharderrors=-1 - msg37=msgbest - if(msg37(1:3).eq.'CQ ' .and. std_2 .and. grid4.eq.' ') nharderrors=-1 - if(msg37(1:6).eq.'QU1RK ') nharderrors=-1 - - return -end subroutine ft8_a7d - -end module ft8_a7 +module ft8_a7 + + parameter(MAXDEC=200) + +! For the following three arrays +! First index i=decode number in this sequence +! Second index j=0 or 1 for even or odd sequence +! Third index k=0 or 1 for previous or current tally for this j + real dt0(MAXDEC,0:1,0:1) !dt0(i,j,k) + real f0(MAXDEC,0:1,0:1) !f0(i,j,k) + character*37 msg0(MAXDEC,0:1,0:1) !msg0(i,j,k) + + integer itone_a7(79) + integer jseq !even=0, odd=1 + integer ndec(0:1,0:1) !ndec(j,k) + data ndec/4*0/,jseq/0/ + +contains + +subroutine ft8_a7_save(nutc,dt,f,msg) + + use packjt77 + character*37 msg,msg1 + character*13 w(19) + character*4 g4 + integer nw(19) + logical isgrid4 + +! Statement function: + isgrid4(g4)=(len_trim(g4).eq.4 .and. & + ichar(g4(1:1)).ge.ichar('A') .and. ichar(g4(1:1)).le.ichar('R') .and. & + ichar(g4(2:2)).ge.ichar('A') .and. ichar(g4(2:2)).le.ichar('R') .and. & + ichar(g4(3:3)).ge.ichar('0') .and. ichar(g4(3:3)).le.ichar('9') .and. & + ichar(g4(4:4)).ge.ichar('0') .and. ichar(g4(4:4)).le.ichar('9')) + + if(index(msg,'/').ge.1 .or. index(msg,'<').ge.1) go to 999 + call split77(msg,nwords,nw,w) !Parse msg into words + if(nwords.lt.1) go to 999 + if(w(1)(1:3).eq.'CQ_') go to 999 + j=mod(nutc/5,2) !j is 0 or 1 for odd/even sequence + jseq=j + +! Add this decode to current table for this sequence + ndec(j,1)=ndec(j,1)+1 !Number of decodes in this sequence + i=ndec(j,1) !i is index of a new table entry + if(i.gt.MAXDEC) return !Prevent table overflow (indexes start at 1) + + dt0(i,j,1)=dt !Save dt in table + f0(i,j,1)=f !Save f in table + msg0(i,j,1)=trim(w(1))//' '//trim(w(2)) !Save "call_1 call_2" + if(w(1)(1:3).eq.'CQ ' .and. nw(2).le.2) then + msg0(i,j,1)='CQ '//trim(w(2))//' '//trim(w(3)) !Save "CQ DX Call_2" + endif + msg1=msg0(i,j,1) !Message without grid + nn=len(trim(msg1)) !Message length without grid +! Include grid as part of message + if(isgrid4(w(nwords))) msg0(i,j,1)=trim(msg0(i,j,1))//' '//trim(w(nwords)) + +! If a transmission at this frequency with message fragment "call_1 call_2" +! was decoded in the previous sequence, flag it as "DO NOT USE" because +! we have already decoded and subtracted that station's next transmission. + + call split77(msg0(i,j,1),nwords,nw,w) !Parse msg into words + do i=1,ndec(j,0) + if(f0(i,j,0).le.-98.0) cycle + i2=index(msg0(i,j,0),' '//trim(w(2))) + if(abs(f-f0(i,j,0)).le.3.0 .and. i2.ge.3) then + f0(i,j,0)=-98.0 !Flag as "do not use" for a potential a7 decode + endif + enddo + +999 return +end subroutine ft8_a7_save + +subroutine ft8_a7d(dd0,newdat,call_1,call_2,grid4,xdt,f1,xbase,nharderrors,dmin, & + msg37,xsnr) + +! Examine the raw data in dd0() for possible "a7" decodes. + + use crc + use timer_module, only: timer + use packjt77 + include 'ft8_params.f90' + parameter(NP2=2812) + character*37 msg37,msg,msgsent,msgbest + character*12 call_1,call_2 + character*4 grid4 + real a(5) + real s8(0:7,NN) + real s2(0:511) + real dmm(206) + real bmeta(174),bmetb(174),bmetc(174),bmetd(174) + real llra(174),llrb(174),llrc(174),llrd(174) !Soft symbols + real dd0(15*12000) + real ss(9) + real rcw(174) + integer*1 cw(174) + integer*1 msgbits(77) + integer*1 nxor(174),hdec(174) + integer itone(NN) + integer icos7(0:6),ip(1) + logical one(0:511,0:8) + integer graymap(0:7) + integer iloc(1) + complex cd0(0:3199) + complex ctwk(32) + complex csymb(32) + complex cs(0:7,NN) + logical std_1,std_2 + logical first,newdat + data icos7/3,1,4,0,6,5,2/ !Sync array + data first/.true./ + data graymap/0,1,3,2,5,6,4,7/ + save one + + if(first) then + one=.false. + do i=0,511 + do j=0,8 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + first=.false. + endif + + call stdcall(call_1,std_1) + if(call_1(1:3).eq.'CQ ') std_1=.true. + call stdcall(call_2,std_2) + + fs2=12000.0/NDOWN + dt2=1.0/fs2 + twopi=8.0*atan(1.0) + delfbest=0. + ibest=0 + + call timer('ft8_down',0) + call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal + smax=0.0 + do idt=i0-10,i0+10 !Search over +/- one quarter symbol + call sync8d(cd0,idt,ctwk,0,sync) !NB: ctwk not used here + if(sync.gt.smax) then + smax=sync + ibest=idt + endif + enddo + +! Peak up in frequency + smax=0.0 + do ifr=-5,5 !Search over +/- 2.5 Hz + delf=ifr*0.5 + dphi=twopi*delf*dt2 + phi=0.0 + do i=1,32 + ctwk(i)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + enddo + call sync8d(cd0,ibest,ctwk,1,sync) + if( sync .gt. smax ) then + smax=sync + delfbest=delf + endif + enddo + a=0.0 + a(1)=-delfbest + call twkfreq1(cd0,NP2,fs2,a,cd0) + f1=f1+delfbest !Improved estimate of DF + + call timer('ft8_down',0) + call ft8_downsample(dd0,.false.,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + smax=0.0 + do idt=-4,4 !Search over +/- one quarter symbol + call sync8d(cd0,ibest+idt,ctwk,0,sync) + ss(idt+5)=sync + enddo + smax=maxval(ss) + iloc=maxloc(ss) + ibest=iloc(1)-5+ibest + xdt=(ibest-1)*dt2 - 0.5 + sync=smax + + do k=1,NN + i1=ibest+(k-1)*32 + csymb=cmplx(0.0,0.0) + if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) + call four2a(csymb,32,1,-1,1) + cs(0:7,k)=csymb(1:8)/1e3 + s8(0:7,k)=abs(csymb(1:8)) + enddo + +! sync quality check + is1=0 + is2=0 + is3=0 + do k=1,7 + ip=maxloc(s8(:,k)) + if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s8(:,k+36)) + if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s8(:,k+72)) + if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 + enddo +! hard sync sum - max is 21 + nsync=is1+is2+is3 +! if(nsync .le. 6) return ! bail out + + do nsym=1,3 + nt=2**(3*nsym) + do ihalf=1,2 + do k=1,29,nsym + if(ihalf.eq.1) ks=k+7 + if(ihalf.eq.2) ks=k+43 + amax=-1.0 + do i=0,nt-1 + i1=i/64 + i2=iand(i,63)/8 + i3=iand(i,7) + if(nsym.eq.1) then + s2(i)=abs(cs(graymap(i3),ks)) + elseif(nsym.eq.2) then + s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) + elseif(nsym.eq.3) then + s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) + else + print*,"Error - nsym must be 1, 2, or 3." + endif + enddo + i32=1+(k-1)*3+(ihalf-1)*87 + if(nsym.eq.1) ibmax=2 + if(nsym.eq.2) ibmax=5 + if(nsym.eq.3) ibmax=8 + do ib=0,ibmax + bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) + if(i32+ib .gt.174) cycle + if(nsym.eq.1) then + bmeta(i32+ib)=bm + den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) + if(den.gt.0.0) then + cm=bm/den + else ! erase it + cm=0.0 + endif + bmetd(i32+ib)=cm + elseif(nsym.eq.2) then + bmetb(i32+ib)=bm + elseif(nsym.eq.3) then + bmetc(i32+ib)=bm + endif + enddo + enddo + enddo + enddo + call normalizebmet(bmeta,174) + call normalizebmet(bmetb,174) + call normalizebmet(bmetc,174) + call normalizebmet(bmetd,174) + + scalefac=2.83 + llra=scalefac*bmeta + llrb=scalefac*bmetb + llrc=scalefac*bmetc + llrd=scalefac*bmetd + +! apmag=maxval(abs(llra))*1.01 + + MAXMSG=206 + pbest=0. + dmin=1.e30 + nharderrors=-1 + + do imsg=1,MAXMSG + msg=trim(call_1)//' '//trim(call_2) + i=imsg + if(call_1(1:3).eq.'CQ ' .and. i.ne.5) msg='QU1RK '//trim(call_2) + if(.not.std_1) then + if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' + else if(.not.std_2) then + if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' + endif + j0=len(trim(msg))+2 + if(i.eq.2) msg(j0:j0+2)='RRR' + if(i.eq.3) msg(j0:j0+3)='RR73' + if(i.eq.4) msg(j0:j0+1)='73' + if(i.eq.5) then + if(std_2) then + msg='CQ '//trim(call_2) + if(call_1(3:3).eq.'_') msg=trim(call_1)//' '//trim(call_2) + if(grid4.ne.'RR73') msg=trim(msg)//' '//grid4 + endif + if(.not.std_2) msg='CQ '//trim(call_2) + endif + if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 + if(i.ge.7) then + isnr = -50 + (i-7)/2 + if(iand(i,1).eq.1) then + write(msg(j0:j0+2),'(i3.2)') isnr + if(msg(j0:j0).eq.' ') msg(j0:j0)='+' + else + write(msg(j0:j0+3),'("R",i3.2)') isnr + if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' + endif + endif + + i3=-1 + n3=-1 + call genft8(msg,i3,n3,msgsent,msgbits,itone) !Source-encode this message + call encode174_91(msgbits,cw) !Get codeword for this message + rcw=2*cw-1 + pow=0.0 + do i=1,79 + pow=pow+s8(itone(i),i)**2 + enddo + + hdec=0 + where(llra.ge.0.0) hdec=1 + nxor=ieor(hdec,cw) + da=sum(nxor*abs(llra)) + + hdec=0 + where(llrb.ge.0.0) hdec=1 + nxor=ieor(hdec,cw) + dbb=sum(nxor*abs(llrb)) + + hdec=0 + where(llrc.ge.0.0) hdec=1 + nxor=ieor(hdec,cw) + dc=sum(nxor*abs(llrc)) + + hdec=0 + where(llrd.ge.0.0) hdec=1 + nxor=ieor(hdec,cw) + dd=sum(nxor*abs(llrd)) + + dm=min(da,dbb,dc,dd) + dmm(imsg)=dm + if(dm.lt.dmin) then + dmin=dm + msgbest=msgsent + pbest=pow + if(dm.eq.da) then + nharderrors=count((2*cw-1)*llra.lt.0.0) + else if(dm.eq.dbb) then + nharderrors=count((2*cw-1)*llrb.lt.0.0) + else if(dm.eq.dc) then + nharderrors=count((2*cw-1)*llrc.lt.0.0) + else if(dm.eq.dd) then + nharderrors=count((2*cw-1)*llrd.lt.0.0) + endif + endif + + enddo ! imsg + + iloc=minloc(dmm) + dmm(iloc(1))=1.e30 + iloc=minloc(dmm) + dmin2=dmm(iloc(1)) + xsnr=-24. + arg=pbest/xbase/3.0e6-1.0 + if(arg.gt.0.0) xsnr=max(-24.0,db(arg)-27.0) +! write(41,3041) nharderrors,dmin,dmin2,dmin2/dmin,xsnr,trim(msgbest) +!3041 format(i3,2f7.1,f7.2,f7.1,1x,a) + if(dmin.gt.100.0 .or. dmin2/dmin.lt.1.3) nharderrors=-1 + msg37=msgbest + if(msg37(1:3).eq.'CQ ' .and. std_2 .and. grid4.eq.' ') nharderrors=-1 + if(msg37(1:6).eq.'QU1RK ') nharderrors=-1 + + return +end subroutine ft8_a7d + +end module ft8_a7 diff --git a/lib/ft8/ft8_testmsg.f90 b/lib/ft8/ft8_testmsg.f90 index 931df4f5..253641d2 100755 --- a/lib/ft8/ft8_testmsg.f90 +++ b/lib/ft8/ft8_testmsg.f90 @@ -1,51 +1,51 @@ - parameter (MAXTEST=75,NTEST=48) - character*37 testmsg(MAXTEST) - data testmsg(1:NTEST)/ & - "TNX BOB 73 GL", & ! 0.0 - "K1ABC RR73; W9XYZ -08", & ! 0.1 - "PA9XYZ 590003 IO91NP", & ! 0.2 - "G4ABC/P R 570007 JO22DB", & ! 0.2 - "K1ABC W9XYZ 6A WI", & ! 0.3 - "W9XYZ K1ABC R 17B EMA", & ! 0.3 - "123456789ABCDEF012", & ! 0.5 - "CQ K1ABC FN42", & ! 1. - "K1ABC W9XYZ EN37", & ! 1. - "W9XYZ K1ABC -11", & ! 1. - "K1ABC W9XYZ R-09", & ! 1. - "W9XYZ K1ABC RRR", & ! 1. - "K1ABC W9XYZ 73", & ! 1. - "K1ABC W9XYZ RR73", & ! 1. - "CQ FD K1ABC FN42", & ! 1. - "CQ TEST K1ABC/R FN42", & ! 1. - "K1ABC/R W9XYZ EN37", & ! 1. - "W9XYZ K1ABC/R R FN42", & ! 1. - "K1ABC/R W9XYZ RR73", & ! 1. - "CQ TEST K1ABC FN42", & ! 1. - "W9XYZ -11", & ! 1. - " W9XYZ R-09", & ! 1. - "CQ W9XYZ EN37", & ! 1. - " W9XYZ -11", & ! 1. - "W9XYZ R-09", & ! 1. - " KA1ABC", & ! 1. - "KA1ABC -11", & ! 1. - " KA1ABC R-17", & ! 1. - " KA1ABC 73", & ! 1. - "CQ G4ABC/P IO91", & ! 2. - "G4ABC/P PA9XYZ JO22", & ! 2. - "PA9XYZ G4ABC/P RR73", & ! 2. - "K1ABC W9XYZ 579 WI", & ! 3. - "W9XYZ K1ABC R 589 MA", & ! 3. - "K1ABC KA0DEF 559 MO", & ! 3. - "TU; KA0DEF K1ABC R 569 MA", & ! 3. - "KA1ABC G3AAA 529 0013", & ! 3. - "TU; G3AAA K1ABC R 559 MA", & ! 3. - "CQ KH1/KH7Z", & ! 4. - "CQ PJ4/K1ABC", & ! 4. - "PJ4/K1ABC ", & ! 4. - " PJ4/K1ABC RRR", & ! 4. - "PJ4/K1ABC 73", & ! 4. - " YW18FIFA", & ! 4. - "YW18FIFA RRR", & ! 4. - " YW18FIFA 73", & ! 4. - "CQ YW18FIFA", & ! 4. - " YW18FIFA RR73"/ + parameter (MAXTEST=75,NTEST=48) + character*37 testmsg(MAXTEST) + data testmsg(1:NTEST)/ & + "TNX BOB 73 GL", & ! 0.0 + "K1ABC RR73; W9XYZ -08", & ! 0.1 + "PA9XYZ 590003 IO91NP", & ! 0.2 + "G4ABC/P R 570007 JO22DB", & ! 0.2 + "K1ABC W9XYZ 6A WI", & ! 0.3 + "W9XYZ K1ABC R 17B EMA", & ! 0.3 + "123456789ABCDEF012", & ! 0.5 + "CQ K1ABC FN42", & ! 1. + "K1ABC W9XYZ EN37", & ! 1. + "W9XYZ K1ABC -11", & ! 1. + "K1ABC W9XYZ R-09", & ! 1. + "W9XYZ K1ABC RRR", & ! 1. + "K1ABC W9XYZ 73", & ! 1. + "K1ABC W9XYZ RR73", & ! 1. + "CQ FD K1ABC FN42", & ! 1. + "CQ TEST K1ABC/R FN42", & ! 1. + "K1ABC/R W9XYZ EN37", & ! 1. + "W9XYZ K1ABC/R R FN42", & ! 1. + "K1ABC/R W9XYZ RR73", & ! 1. + "CQ TEST K1ABC FN42", & ! 1. + "W9XYZ -11", & ! 1. + " W9XYZ R-09", & ! 1. + "CQ W9XYZ EN37", & ! 1. + " W9XYZ -11", & ! 1. + "W9XYZ R-09", & ! 1. + " KA1ABC", & ! 1. + "KA1ABC -11", & ! 1. + " KA1ABC R-17", & ! 1. + " KA1ABC 73", & ! 1. + "CQ G4ABC/P IO91", & ! 2. + "G4ABC/P PA9XYZ JO22", & ! 2. + "PA9XYZ G4ABC/P RR73", & ! 2. + "K1ABC W9XYZ 579 WI", & ! 3. + "W9XYZ K1ABC R 589 MA", & ! 3. + "K1ABC KA0DEF 559 MO", & ! 3. + "TU; KA0DEF K1ABC R 569 MA", & ! 3. + "KA1ABC G3AAA 529 0013", & ! 3. + "TU; G3AAA K1ABC R 559 MA", & ! 3. + "CQ KH1/KH7Z", & ! 4. + "CQ PJ4/K1ABC", & ! 4. + "PJ4/K1ABC ", & ! 4. + " PJ4/K1ABC RRR", & ! 4. + "PJ4/K1ABC 73", & ! 4. + " YW18FIFA", & ! 4. + "YW18FIFA RRR", & ! 4. + " YW18FIFA 73", & ! 4. + "CQ YW18FIFA", & ! 4. + " YW18FIFA RR73"/ diff --git a/lib/ft8/ft8apset.f90 b/lib/ft8/ft8apset.f90 index 64b22128..73a224ec 100755 --- a/lib/ft8/ft8apset.f90 +++ b/lib/ft8/ft8apset.f90 @@ -1,62 +1,62 @@ -subroutine ft8apset(mycall12,hiscall12,ncontest,apsym,aph10) - use packjt77 - character*77 c77 - character*37 msg,msgchk - character*12 mycall12,hiscall12,hiscall - character*13 hc13 - character*10 c10 - integer apsym(58),aph10(10) - logical nohiscall,unpk77_success,std - - apsym=0 - apsym(1)=99 - apsym(30)=99 - aph10=0 - aph10(1)=99 - if(len(trim(mycall12)).lt.3) return - - nohiscall=.false. - hiscall=hiscall12 - if(len(trim(hiscall)).lt.3) then - hiscall='KA1ABC' !Use a dummy hiscall - nohiscall=.true. - else - hc13=hiscall - n10=0 - n12=0 - n22=0 - call save_hash_call(hc13,n10,n12,n22) - write(c10,'(b10.10)') iand(n10,Z'3FF') - read(c10,'(10i1.1)',err=1) aph10 - aph10=2*aph10-1 - endif - -! Encode a dummy standard message: i3=1, 28 1 28 1 1 15 -! - msg=trim(mycall12)//' '//trim(hiscall)//' RRR' - call stdcall(mycall12,std) - if(.not.std) msg='<'//trim(mycall12)//'> '//trim(hiscall)//' RRR' - i3=0 - n3=0 - call pack77(msg,i3,n3,c77) - call unpack77(c77,1,msgchk,unpk77_success) - if(ncontest.eq.7.and. (i3.ne.1 .or. .not.unpk77_success)) return - if(ncontest.le.5.and. (i3.ne.1 .or. msg.ne.msgchk .or. .not.unpk77_success)) return - - read(c77,'(58i1)',err=2) apsym(1:58) - apsym=2*apsym-1 - if(nohiscall) then - apsym(30)=99 - aph10(1)=99 - endif - return - -1 aph10=0 - aph10(1)=99 - return -2 apsym=0 - apsym(1)=99 - apsym(30)=99 - return - -end subroutine ft8apset +subroutine ft8apset(mycall12,hiscall12,ncontest,apsym,aph10) + use packjt77 + character*77 c77 + character*37 msg,msgchk + character*12 mycall12,hiscall12,hiscall + character*13 hc13 + character*10 c10 + integer apsym(58),aph10(10) + logical nohiscall,unpk77_success,std + + apsym=0 + apsym(1)=99 + apsym(30)=99 + aph10=0 + aph10(1)=99 + if(len(trim(mycall12)).lt.3) return + + nohiscall=.false. + hiscall=hiscall12 + if(len(trim(hiscall)).lt.3) then + hiscall='KA1ABC' !Use a dummy hiscall + nohiscall=.true. + else + hc13=hiscall + n10=0 + n12=0 + n22=0 + call save_hash_call(hc13,n10,n12,n22) + write(c10,'(b10.10)') iand(n10,Z'3FF') + read(c10,'(10i1.1)',err=1) aph10 + aph10=2*aph10-1 + endif + +! Encode a dummy standard message: i3=1, 28 1 28 1 1 15 +! + msg=trim(mycall12)//' '//trim(hiscall)//' RRR' + call stdcall(mycall12,std) + if(.not.std) msg='<'//trim(mycall12)//'> '//trim(hiscall)//' RRR' + i3=0 + n3=0 + call pack77(msg,i3,n3,c77) + call unpack77(c77,1,msgchk,unpk77_success) + if(ncontest.eq.7.and. (i3.ne.1 .or. .not.unpk77_success)) return + if(ncontest.le.5.and. (i3.ne.1 .or. msg.ne.msgchk .or. .not.unpk77_success)) return + + read(c77,'(58i1)',err=2) apsym(1:58) + apsym=2*apsym-1 + if(nohiscall) then + apsym(30)=99 + aph10(1)=99 + endif + return + +1 aph10=0 + aph10(1)=99 + return +2 apsym=0 + apsym(1)=99 + apsym(30)=99 + return + +end subroutine ft8apset diff --git a/lib/ft8/ft8b.f90 b/lib/ft8/ft8b.f90 index 75b17adf..30cd95c8 100755 --- a/lib/ft8/ft8b.f90 +++ b/lib/ft8/ft8b.f90 @@ -1,503 +1,503 @@ -subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & - lapcqonly,napwid,lsubtract,nagain,ncontest,iaptype,mycall12,hiscall12, & - f1,xdt,xbase,apsym,aph10,nharderrors,dmin,nbadcrc,ipass, & - msg37,xsnr,itone) - - use crc - use timer_module, only: timer - use packjt77 - include 'ft8_params.f90' - parameter(NP2=2812) - character*37 msg37 - character*12 mycall12,hiscall12 - character*77 c77 - real a(5) - real s8(0:7,NN) - real s2(0:511) - real bmeta(174),bmetb(174),bmetc(174),bmetd(174) - real llra(174),llrb(174),llrc(174),llrd(174),llrz(174) !Soft symbols - real dd0(15*12000) - real ss(9) - integer*1 message77(77),message91(91),apmask(174),cw(174) - integer apsym(58),aph10(10) - integer mcq(29),mcqru(29),mcqfd(29),mcqtest(29),mcqww(29) - integer mrrr(19),m73(19),mrr73(19) - integer itone(NN) - integer icos7(0:6),ip(1) - integer nappasses(0:5) !Number of decoding passes to use for each QSO state - integer naptypes(0:5,4) ! (nQSOProgress, decoding pass) maximum of 4 passes for now - integer ncontest,ncontest0 - logical one(0:511,0:8) - integer graymap(0:7) - integer iloc(1) - complex cd0(0:3199) - complex ctwk(32) - complex csymb(32) - complex cs(0:7,NN) - logical first,newdat,lsubtract,lapon,lapcqonly,nagain,unpk77_success - data icos7/3,1,4,0,6,5,2/ ! Flipped w.r.t. original FT8 sync array - data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/ - data mcqru/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,1,1,0,0/ - data mcqfd/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,1,0/ - data mcqtest/0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,1,0/ - data mcqww/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,1,1,1,1,0/ - data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/ - data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/ - data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/ - data first/.true./ - data graymap/0,1,3,2,5,6,4,7/ - save nappasses,naptypes,ncontest0,one - - if(first.or.(ncontest.ne.ncontest0)) then - mcq=2*mcq-1 - mcqfd=2*mcqfd-1 - mcqru=2*mcqru-1 - mcqtest=2*mcqtest-1 - mcqww=2*mcqww-1 - mrrr=2*mrrr-1 - m73=2*m73-1 - mrr73=2*mrr73-1 - nappasses(0)=2 - nappasses(1)=2 - nappasses(2)=2 - nappasses(3)=4 - nappasses(4)=4 - nappasses(5)=3 - -! iaptype -!------------------------ -! 1 CQ ??? ??? (29+3=32 ap bits) -! 2 MyCall ??? ??? (29+3=32 ap bits) -! 3 MyCall DxCall ??? (58+3=61 ap bits) -! 4 MyCall DxCall RRR (77 ap bits) -! 5 MyCall DxCall 73 (77 ap bits) -! 6 MyCall DxCall RR73 (77 ap bits) - - naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ) - naptypes(1,1:4)=(/2,3,0,0/) ! Tx1 - naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 - naptypes(3,1:4)=(/3,4,5,6/) ! Tx3 - naptypes(4,1:4)=(/3,4,5,6/) ! Tx4 - naptypes(5,1:4)=(/3,1,2,0/) ! Tx5 - - one=.false. - do i=0,511 - do j=0,8 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - first=.false. - ncontest0=ncontest - endif - - dxcall13=hiscall12 ! initialize for use in packjt77 - mycall13=mycall12 - - max_iterations=30 - nharderrors=-1 - fs2=12000.0/NDOWN - dt2=1.0/fs2 - twopi=8.0*atan(1.0) - delfbest=0. - ibest=0 - - call timer('ft8_down',0) - call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample - call timer('ft8_down',1) - - i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal - smax=0.0 - do idt=i0-10,i0+10 !Search over +/- one quarter symbol - call sync8d(cd0,idt,ctwk,0,sync) - if(sync.gt.smax) then - smax=sync - ibest=idt - endif - enddo - -! Now peak up in frequency - smax=0.0 - do ifr=-5,5 !Search over +/- 2.5 Hz - delf=ifr*0.5 - dphi=twopi*delf*dt2 - phi=0.0 - do i=1,32 - ctwk(i)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - enddo - call sync8d(cd0,ibest,ctwk,1,sync) - if( sync .gt. smax ) then - smax=sync - delfbest=delf - endif - enddo - a=0.0 - a(1)=-delfbest - call twkfreq1(cd0,NP2,fs2,a,cd0) - f1=f1+delfbest !Improved estimate of DF - - call timer('ft8_down',0) - call ft8_downsample(dd0,.false.,f1,cd0) !Mix f1 to baseband and downsample - call timer('ft8_down',1) - - smax=0.0 - do idt=-4,4 !Search over +/- one quarter symbol - call sync8d(cd0,ibest+idt,ctwk,0,sync) - ss(idt+5)=sync - enddo - smax=maxval(ss) - iloc=maxloc(ss) - ibest=iloc(1)-5+ibest - xdt=(ibest-1)*dt2 - sync=smax - - do k=1,NN - i1=ibest+(k-1)*32 - csymb=cmplx(0.0,0.0) - if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) - call four2a(csymb,32,1,-1,1) - cs(0:7,k)=csymb(1:8)/1e3 - s8(0:7,k)=abs(csymb(1:8)) - enddo - -! sync quality check - is1=0 - is2=0 - is3=0 - do k=1,7 - ip=maxloc(s8(:,k)) - if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 - ip=maxloc(s8(:,k+36)) - if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 - ip=maxloc(s8(:,k+72)) - if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 - enddo -! hard sync sum - max is 21 - nsync=is1+is2+is3 - if(nsync .le. 6) then ! bail out - nbadcrc=1 - return - endif - - do nsym=1,3 - nt=2**(3*nsym) - do ihalf=1,2 - do k=1,29,nsym - if(ihalf.eq.1) ks=k+7 - if(ihalf.eq.2) ks=k+43 - amax=-1.0 - do i=0,nt-1 - i1=i/64 - i2=iand(i,63)/8 - i3=iand(i,7) - if(nsym.eq.1) then - s2(i)=abs(cs(graymap(i3),ks)) - elseif(nsym.eq.2) then - s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) - elseif(nsym.eq.3) then - s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) - else - print*,"Error - nsym must be 1, 2, or 3." - endif - enddo - i32=1+(k-1)*3+(ihalf-1)*87 - if(nsym.eq.1) ibmax=2 - if(nsym.eq.2) ibmax=5 - if(nsym.eq.3) ibmax=8 - do ib=0,ibmax - bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) - if(i32+ib .gt.174) cycle - if(nsym.eq.1) then - bmeta(i32+ib)=bm - den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) - if(den.gt.0.0) then - cm=bm/den - else ! erase it - cm=0.0 - endif - bmetd(i32+ib)=cm - elseif(nsym.eq.2) then - bmetb(i32+ib)=bm - elseif(nsym.eq.3) then - bmetc(i32+ib)=bm - endif - enddo - enddo - enddo - enddo - call normalizebmet(bmeta,174) - call normalizebmet(bmetb,174) - call normalizebmet(bmetc,174) - call normalizebmet(bmetd,174) - - scalefac=2.83 - llra=scalefac*bmeta - llrb=scalefac*bmetb - llrc=scalefac*bmetc - llrd=scalefac*bmetd - - apmag=maxval(abs(llra))*1.01 - -! pass # -!------------------------------ -! 1 regular decoding, nsym=1 -! 2 regular decoding, nsym=2 -! 3 regular decoding, nsym=3 -! 4 regular decoding, nsym=1, bit-by-bit normalized -! 5 ap pass 1, nsym=1 -! 6 ap pass 2 -! 7 ap pass 3 -! 8 ap pass 4 - - if(lapon.or.ncontest.eq.7) then !Hounds always use AP - if(.not.lapcqonly) then - npasses=4+nappasses(nQSOProgress) - else - npasses=5 - endif - else - npasses=4 - endif - if(nzhsym.lt.50) npasses=4 - - do ipass=1,npasses - llrz=llra - if(ipass.eq.2) llrz=llrb - if(ipass.eq.3) llrz=llrc - if(ipass.eq.4) llrz=llrd - if(ipass.le.4) then - apmask=0 - iaptype=0 - endif - if(ipass .gt. 4) then - llrz=llra - if(.not.lapcqonly) then - iaptype=naptypes(nQSOProgress,ipass-4) - else - iaptype=1 - endif - -! ncontest=0 : NONE -! 1 : NA_VHF -! 2 : EU_VHF -! 3 : FIELD DAY -! 4 : RTTY -! 5 : WW_DIGI -! 6 : FOX -! 7 : HOUND -! 8 : ARRL_DIGI -! -! Conditions that cause us to bail out of AP decoding - if(ncontest.le.5 .and. iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid .and. abs(f1-nftx).gt.napwid) ) cycle - if(ncontest.eq.6) cycle ! No AP for Foxes - if(ncontest.eq.7.and.f1.gt.950.0) cycle ! Hounds use AP only for signals below 950 Hz - if(iaptype.ge.2 .and. apsym(1).gt.1) cycle ! No, or nonstandard, mycall - if(ncontest.eq.7 .and. iaptype.ge.2 .and. aph10(1).gt.1) cycle - if(iaptype.ge.3 .and. apsym(30).gt.1) cycle ! No, or nonstandard, dxcall - - if(iaptype.eq.1) then ! CQ or CQ RU or CQ TEST or CQ FD - apmask=0 - apmask(1:29)=1 - if(ncontest.eq.0) llrz(1:29)=apmag*mcq(1:29) - if(ncontest.eq.1) llrz(1:29)=apmag*mcqtest(1:29) - if(ncontest.eq.2) llrz(1:29)=apmag*mcqtest(1:29) - if(ncontest.eq.3) llrz(1:29)=apmag*mcqfd(1:29) - if(ncontest.eq.4) llrz(1:29)=apmag*mcqru(1:29) - if(ncontest.eq.5) llrz(1:29)=apmag*mcqww(1:29) - if(ncontest.eq.7) llrz(1:29)=apmag*mcq(1:29) - if(ncontest.eq.8) llrz(1:29)=apmag*mcqtest(1:29) - apmask(75:77)=1 - llrz(75:76)=apmag*(-1) - llrz(77)=apmag*(+1) - endif - - if(iaptype.eq.2) then ! MyCall,???,??? - apmask=0 - if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.5.or.ncontest.eq.8) then - apmask(1:29)=1 - llrz(1:29)=apmag*apsym(1:29) - apmask(75:77)=1 - llrz(75:76)=apmag*(-1) - llrz(77)=apmag*(+1) - else if(ncontest.eq.2) then - apmask(1:28)=1 - llrz(1:28)=apmag*apsym(1:28) - apmask(72:74)=1 - llrz(72)=apmag*(-1) - llrz(73)=apmag*(+1) - llrz(74)=apmag*(-1) - apmask(75:77)=1 - llrz(75:77)=apmag*(-1) - else if(ncontest.eq.3) then - apmask(1:28)=1 - llrz(1:28)=apmag*apsym(1:28) - apmask(75:77)=1 - llrz(75:77)=apmag*(-1) - else if(ncontest.eq.4) then - apmask(2:29)=1 - llrz(2:29)=apmag*apsym(1:28) - apmask(75:77)=1 - llrz(75)=apmag*(-1) - llrz(76:77)=apmag*(+1) - else if(ncontest.eq.7) then ! ??? RR73; MyCall ??? - apmask(29:56)=1 - llrz(29:56)=apmag*apsym(1:28) - apmask(57:66)=1 - llrz(57:66)=apmag*aph10(1:10) - apmask(72:77)=1 - llrz(72:73)=apmag*(-1) - llrz(74)=apmag*(+1) - llrz(75:77)=apmag*(-1) - endif - endif - - if(iaptype.eq.3) then ! MyCall,DxCall,??? - apmask=0 - if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2.or.ncontest.eq.5.or.ncontest.eq.7.or.ncontest.eq.8) then - apmask(1:58)=1 - llrz(1:58)=apmag*apsym - apmask(75:77)=1 - llrz(75:76)=apmag*(-1) - llrz(77)=apmag*(+1) - else if(ncontest.eq.3) then ! Field Day - apmask(1:56)=1 - llrz(1:28)=apmag*apsym(1:28) - llrz(29:56)=apmag*apsym(30:57) - apmask(72:74)=1 - apmask(75:77)=1 - llrz(75:77)=apmag*(-1) - else if(ncontest.eq.4) then - apmask(2:57)=1 - llrz(2:29)=apmag*apsym(1:28) - llrz(30:57)=apmag*apsym(30:57) - apmask(75:77)=1 - llrz(75)=apmag*(-1) - llrz(76:77)=apmag*(+1) - endif - endif - - if(iaptype.eq.5.and.ncontest.eq.7) cycle !Hound - if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then - apmask=0 - if(ncontest.le.5 .or. (ncontest.eq.7.and.iaptype.eq.6) .or. ncontest.eq.8) then - apmask(1:77)=1 ! mycall, hiscall, RRR|73|RR73 - llrz(1:58)=apmag*apsym - if(iaptype.eq.4) llrz(59:77)=apmag*mrrr - if(iaptype.eq.5) llrz(59:77)=apmag*m73 - if(iaptype.eq.6) llrz(59:77)=apmag*mrr73 - else if(ncontest.eq.7.and.iaptype.eq.4) then ! Hound listens for MyCall RR73;... - apmask(1:28)=1 - llrz(1:28)=apmag*apsym(1:28) - apmask(57:66)=1 - llrz(57:66)=apmag*aph10(1:10) - apmask(72:77)=1 - llrz(72:73)=apmag*(-1) - llrz(74)=apmag*(1) - llrz(75:77)=apmag*(-1) - endif - endif - endif - - cw=0 - dmin=0.0 - norder=2 - maxosd=2 - if(ndepth.eq.1) maxosd=-1 ! BP only - if(ndepth.eq.2) maxosd=0 ! uncoupled BP+OSD - if(ndepth.eq.3 .and. & - (abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid .or. ncontest.eq.7)) then - maxosd=2 - endif - call timer('dec174_91 ',0) - Keff=91 - call decode174_91(llrz,Keff,maxosd,norder,apmask,message91,cw, & - ntype,nharderrors,dmin) - if(nharderrors.ge.0) message77=message91(1:77) - call timer('dec174_91 ',1) - - msg37=' ' - nbadcrc=1 - if(nharderrors.lt.0 .or. nharderrors.gt.36) cycle - if(count(cw.eq.0).eq.174) cycle !Reject the all-zero codeword - write(c77,'(77i1)') message77 - read(c77(72:74),'(b3)') n3 - read(c77(75:77),'(b3)') i3 - if(i3.gt.5 .or. (i3.eq.0.and.n3.gt.6)) cycle - if(i3.eq.0 .and. n3.eq.2) cycle - call unpack77(c77,1,msg37,unpk77_success) - if(.not.unpk77_success) cycle - nbadcrc=0 ! If we get this far: valid codeword, valid (i3,n3), nonquirky message. - call get_ft8_tones_from_77bits(message77,itone) - if(lsubtract) then - call timer('sub_ft8a',0) - call subtractft8(dd0,itone,f1,xdt,.false.) - call timer('sub_ft8a',1) - endif - xsig=0.0 - xnoi=0.0 - do i=1,79 - xsig=xsig+s8(itone(i),i)**2 - ios=mod(itone(i)+4,7) - xnoi=xnoi+s8(ios,i)**2 - enddo - xsnr=0.001 - xsnr2=0.001 - arg=xsig/xnoi-1.0 - if(arg.gt.0.1) xsnr=arg - arg=xsig/xbase/3.0e6-1.0 - if(arg.gt.0.1) xsnr2=arg - xsnr=10.0*log10(xsnr)-27.0 - xsnr2=10.0*log10(xsnr2)-27.0 - if(.not.nagain) then - xsnr=xsnr2 - endif - if(nsync.le.10 .and. xsnr.lt.-24.0) then !bail out, likely false decode - nbadcrc=1 - return - endif - if(xsnr .lt. -24.0) xsnr=-24.0 - return - enddo - return -end subroutine ft8b - -subroutine normalizebmet(bmet,n) - real bmet(n) - - bmetav=sum(bmet)/real(n) - bmet2av=sum(bmet*bmet)/real(n) - var=bmet2av-bmetav*bmetav - if( var .gt. 0.0 ) then - bmetsig=sqrt(var) - else - bmetsig=sqrt(bmet2av) - endif - bmet=bmet/bmetsig - return -end subroutine normalizebmet - - -function bessi0(x) -! From Numerical Recipes - real bessi0,x - double precision p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9,y - save p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9 - data p1,p2,p3,p4,p5,p6,p7/1.0d0,3.5156229d0,3.0899424d0,1.2067492d0, & - 0.2659732d0,0.360768d-1,0.45813d-2/ - data q1,q2,q3,q4,q5,q6,q7,q8,q9/0.39894228d0,0.1328592d-1, & - 0.225319d-2,-0.157565d-2,0.916281d-2,-0.2057706d-1, & - 0.2635537d-1,-0.1647633d-1,0.392377d-2/ - - if (abs(x).lt.3.75) then - y=(x/3.75)**2 - bessi0=p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7))))) - else - ax=abs(x) - y=3.75/ax - bessi0=(exp(ax)/sqrt(ax))*(q1+y*(q2+y*(q3+y*(q4 & - +y*(q5+y*(q6+y*(q7+y*(q8+y*q9)))))))) - endif - return -end function bessi0 +subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & + lapcqonly,napwid,lsubtract,nagain,ncontest,iaptype,mycall12,hiscall12, & + f1,xdt,xbase,apsym,aph10,nharderrors,dmin,nbadcrc,ipass, & + msg37,xsnr,itone) + + use crc + use timer_module, only: timer + use packjt77 + include 'ft8_params.f90' + parameter(NP2=2812) + character*37 msg37 + character*12 mycall12,hiscall12 + character*77 c77 + real a(5) + real s8(0:7,NN) + real s2(0:511) + real bmeta(174),bmetb(174),bmetc(174),bmetd(174) + real llra(174),llrb(174),llrc(174),llrd(174),llrz(174) !Soft symbols + real dd0(15*12000) + real ss(9) + integer*1 message77(77),message91(91),apmask(174),cw(174) + integer apsym(58),aph10(10) + integer mcq(29),mcqru(29),mcqfd(29),mcqtest(29),mcqww(29) + integer mrrr(19),m73(19),mrr73(19) + integer itone(NN) + integer icos7(0:6),ip(1) + integer nappasses(0:5) !Number of decoding passes to use for each QSO state + integer naptypes(0:5,4) ! (nQSOProgress, decoding pass) maximum of 4 passes for now + integer ncontest,ncontest0 + logical one(0:511,0:8) + integer graymap(0:7) + integer iloc(1) + complex cd0(0:3199) + complex ctwk(32) + complex csymb(32) + complex cs(0:7,NN) + logical first,newdat,lsubtract,lapon,lapcqonly,nagain,unpk77_success + data icos7/3,1,4,0,6,5,2/ ! Flipped w.r.t. original FT8 sync array + data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/ + data mcqru/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,1,1,0,0/ + data mcqfd/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,1,0/ + data mcqtest/0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,1,0/ + data mcqww/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,1,1,1,1,0/ + data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/ + data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/ + data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/ + data first/.true./ + data graymap/0,1,3,2,5,6,4,7/ + save nappasses,naptypes,ncontest0,one + + if(first.or.(ncontest.ne.ncontest0)) then + mcq=2*mcq-1 + mcqfd=2*mcqfd-1 + mcqru=2*mcqru-1 + mcqtest=2*mcqtest-1 + mcqww=2*mcqww-1 + mrrr=2*mrrr-1 + m73=2*m73-1 + mrr73=2*mrr73-1 + nappasses(0)=2 + nappasses(1)=2 + nappasses(2)=2 + nappasses(3)=4 + nappasses(4)=4 + nappasses(5)=3 + +! iaptype +!------------------------ +! 1 CQ ??? ??? (29+3=32 ap bits) +! 2 MyCall ??? ??? (29+3=32 ap bits) +! 3 MyCall DxCall ??? (58+3=61 ap bits) +! 4 MyCall DxCall RRR (77 ap bits) +! 5 MyCall DxCall 73 (77 ap bits) +! 6 MyCall DxCall RR73 (77 ap bits) + + naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ) + naptypes(1,1:4)=(/2,3,0,0/) ! Tx1 + naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 + naptypes(3,1:4)=(/3,4,5,6/) ! Tx3 + naptypes(4,1:4)=(/3,4,5,6/) ! Tx4 + naptypes(5,1:4)=(/3,1,2,0/) ! Tx5 + + one=.false. + do i=0,511 + do j=0,8 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + first=.false. + ncontest0=ncontest + endif + + dxcall13=hiscall12 ! initialize for use in packjt77 + mycall13=mycall12 + + max_iterations=30 + nharderrors=-1 + fs2=12000.0/NDOWN + dt2=1.0/fs2 + twopi=8.0*atan(1.0) + delfbest=0. + ibest=0 + + call timer('ft8_down',0) + call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal + smax=0.0 + do idt=i0-10,i0+10 !Search over +/- one quarter symbol + call sync8d(cd0,idt,ctwk,0,sync) + if(sync.gt.smax) then + smax=sync + ibest=idt + endif + enddo + +! Now peak up in frequency + smax=0.0 + do ifr=-5,5 !Search over +/- 2.5 Hz + delf=ifr*0.5 + dphi=twopi*delf*dt2 + phi=0.0 + do i=1,32 + ctwk(i)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + enddo + call sync8d(cd0,ibest,ctwk,1,sync) + if( sync .gt. smax ) then + smax=sync + delfbest=delf + endif + enddo + a=0.0 + a(1)=-delfbest + call twkfreq1(cd0,NP2,fs2,a,cd0) + f1=f1+delfbest !Improved estimate of DF + + call timer('ft8_down',0) + call ft8_downsample(dd0,.false.,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + smax=0.0 + do idt=-4,4 !Search over +/- one quarter symbol + call sync8d(cd0,ibest+idt,ctwk,0,sync) + ss(idt+5)=sync + enddo + smax=maxval(ss) + iloc=maxloc(ss) + ibest=iloc(1)-5+ibest + xdt=(ibest-1)*dt2 + sync=smax + + do k=1,NN + i1=ibest+(k-1)*32 + csymb=cmplx(0.0,0.0) + if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) + call four2a(csymb,32,1,-1,1) + cs(0:7,k)=csymb(1:8)/1e3 + s8(0:7,k)=abs(csymb(1:8)) + enddo + +! sync quality check + is1=0 + is2=0 + is3=0 + do k=1,7 + ip=maxloc(s8(:,k)) + if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s8(:,k+36)) + if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s8(:,k+72)) + if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 + enddo +! hard sync sum - max is 21 + nsync=is1+is2+is3 + if(nsync .le. 6) then ! bail out + nbadcrc=1 + return + endif + + do nsym=1,3 + nt=2**(3*nsym) + do ihalf=1,2 + do k=1,29,nsym + if(ihalf.eq.1) ks=k+7 + if(ihalf.eq.2) ks=k+43 + amax=-1.0 + do i=0,nt-1 + i1=i/64 + i2=iand(i,63)/8 + i3=iand(i,7) + if(nsym.eq.1) then + s2(i)=abs(cs(graymap(i3),ks)) + elseif(nsym.eq.2) then + s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) + elseif(nsym.eq.3) then + s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) + else + print*,"Error - nsym must be 1, 2, or 3." + endif + enddo + i32=1+(k-1)*3+(ihalf-1)*87 + if(nsym.eq.1) ibmax=2 + if(nsym.eq.2) ibmax=5 + if(nsym.eq.3) ibmax=8 + do ib=0,ibmax + bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) + if(i32+ib .gt.174) cycle + if(nsym.eq.1) then + bmeta(i32+ib)=bm + den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) + if(den.gt.0.0) then + cm=bm/den + else ! erase it + cm=0.0 + endif + bmetd(i32+ib)=cm + elseif(nsym.eq.2) then + bmetb(i32+ib)=bm + elseif(nsym.eq.3) then + bmetc(i32+ib)=bm + endif + enddo + enddo + enddo + enddo + call normalizebmet(bmeta,174) + call normalizebmet(bmetb,174) + call normalizebmet(bmetc,174) + call normalizebmet(bmetd,174) + + scalefac=2.83 + llra=scalefac*bmeta + llrb=scalefac*bmetb + llrc=scalefac*bmetc + llrd=scalefac*bmetd + + apmag=maxval(abs(llra))*1.01 + +! pass # +!------------------------------ +! 1 regular decoding, nsym=1 +! 2 regular decoding, nsym=2 +! 3 regular decoding, nsym=3 +! 4 regular decoding, nsym=1, bit-by-bit normalized +! 5 ap pass 1, nsym=1 +! 6 ap pass 2 +! 7 ap pass 3 +! 8 ap pass 4 + + if(lapon.or.ncontest.eq.7) then !Hounds always use AP + if(.not.lapcqonly) then + npasses=4+nappasses(nQSOProgress) + else + npasses=5 + endif + else + npasses=4 + endif + if(nzhsym.lt.50) npasses=4 + + do ipass=1,npasses + llrz=llra + if(ipass.eq.2) llrz=llrb + if(ipass.eq.3) llrz=llrc + if(ipass.eq.4) llrz=llrd + if(ipass.le.4) then + apmask=0 + iaptype=0 + endif + if(ipass .gt. 4) then + llrz=llra + if(.not.lapcqonly) then + iaptype=naptypes(nQSOProgress,ipass-4) + else + iaptype=1 + endif + +! ncontest=0 : NONE +! 1 : NA_VHF +! 2 : EU_VHF +! 3 : FIELD DAY +! 4 : RTTY +! 5 : WW_DIGI +! 6 : FOX +! 7 : HOUND +! 8 : ARRL_DIGI +! +! Conditions that cause us to bail out of AP decoding + if(ncontest.le.5 .and. iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid .and. abs(f1-nftx).gt.napwid) ) cycle + if(ncontest.eq.6) cycle ! No AP for Foxes + if(ncontest.eq.7.and.f1.gt.950.0) cycle ! Hounds use AP only for signals below 950 Hz + if(iaptype.ge.2 .and. apsym(1).gt.1) cycle ! No, or nonstandard, mycall + if(ncontest.eq.7 .and. iaptype.ge.2 .and. aph10(1).gt.1) cycle + if(iaptype.ge.3 .and. apsym(30).gt.1) cycle ! No, or nonstandard, dxcall + + if(iaptype.eq.1) then ! CQ or CQ RU or CQ TEST or CQ FD + apmask=0 + apmask(1:29)=1 + if(ncontest.eq.0) llrz(1:29)=apmag*mcq(1:29) + if(ncontest.eq.1) llrz(1:29)=apmag*mcqtest(1:29) + if(ncontest.eq.2) llrz(1:29)=apmag*mcqtest(1:29) + if(ncontest.eq.3) llrz(1:29)=apmag*mcqfd(1:29) + if(ncontest.eq.4) llrz(1:29)=apmag*mcqru(1:29) + if(ncontest.eq.5) llrz(1:29)=apmag*mcqww(1:29) + if(ncontest.eq.7) llrz(1:29)=apmag*mcq(1:29) + if(ncontest.eq.8) llrz(1:29)=apmag*mcqtest(1:29) + apmask(75:77)=1 + llrz(75:76)=apmag*(-1) + llrz(77)=apmag*(+1) + endif + + if(iaptype.eq.2) then ! MyCall,???,??? + apmask=0 + if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.5.or.ncontest.eq.8) then + apmask(1:29)=1 + llrz(1:29)=apmag*apsym(1:29) + apmask(75:77)=1 + llrz(75:76)=apmag*(-1) + llrz(77)=apmag*(+1) + else if(ncontest.eq.2) then + apmask(1:28)=1 + llrz(1:28)=apmag*apsym(1:28) + apmask(72:74)=1 + llrz(72)=apmag*(-1) + llrz(73)=apmag*(+1) + llrz(74)=apmag*(-1) + apmask(75:77)=1 + llrz(75:77)=apmag*(-1) + else if(ncontest.eq.3) then + apmask(1:28)=1 + llrz(1:28)=apmag*apsym(1:28) + apmask(75:77)=1 + llrz(75:77)=apmag*(-1) + else if(ncontest.eq.4) then + apmask(2:29)=1 + llrz(2:29)=apmag*apsym(1:28) + apmask(75:77)=1 + llrz(75)=apmag*(-1) + llrz(76:77)=apmag*(+1) + else if(ncontest.eq.7) then ! ??? RR73; MyCall ??? + apmask(29:56)=1 + llrz(29:56)=apmag*apsym(1:28) + apmask(57:66)=1 + llrz(57:66)=apmag*aph10(1:10) + apmask(72:77)=1 + llrz(72:73)=apmag*(-1) + llrz(74)=apmag*(+1) + llrz(75:77)=apmag*(-1) + endif + endif + + if(iaptype.eq.3) then ! MyCall,DxCall,??? + apmask=0 + if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2.or.ncontest.eq.5.or.ncontest.eq.7.or.ncontest.eq.8) then + apmask(1:58)=1 + llrz(1:58)=apmag*apsym + apmask(75:77)=1 + llrz(75:76)=apmag*(-1) + llrz(77)=apmag*(+1) + else if(ncontest.eq.3) then ! Field Day + apmask(1:56)=1 + llrz(1:28)=apmag*apsym(1:28) + llrz(29:56)=apmag*apsym(30:57) + apmask(72:74)=1 + apmask(75:77)=1 + llrz(75:77)=apmag*(-1) + else if(ncontest.eq.4) then + apmask(2:57)=1 + llrz(2:29)=apmag*apsym(1:28) + llrz(30:57)=apmag*apsym(30:57) + apmask(75:77)=1 + llrz(75)=apmag*(-1) + llrz(76:77)=apmag*(+1) + endif + endif + + if(iaptype.eq.5.and.ncontest.eq.7) cycle !Hound + if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then + apmask=0 + if(ncontest.le.5 .or. (ncontest.eq.7.and.iaptype.eq.6) .or. ncontest.eq.8) then + apmask(1:77)=1 ! mycall, hiscall, RRR|73|RR73 + llrz(1:58)=apmag*apsym + if(iaptype.eq.4) llrz(59:77)=apmag*mrrr + if(iaptype.eq.5) llrz(59:77)=apmag*m73 + if(iaptype.eq.6) llrz(59:77)=apmag*mrr73 + else if(ncontest.eq.7.and.iaptype.eq.4) then ! Hound listens for MyCall RR73;... + apmask(1:28)=1 + llrz(1:28)=apmag*apsym(1:28) + apmask(57:66)=1 + llrz(57:66)=apmag*aph10(1:10) + apmask(72:77)=1 + llrz(72:73)=apmag*(-1) + llrz(74)=apmag*(1) + llrz(75:77)=apmag*(-1) + endif + endif + endif + + cw=0 + dmin=0.0 + norder=2 + maxosd=2 + if(ndepth.eq.1) maxosd=-1 ! BP only + if(ndepth.eq.2) maxosd=0 ! uncoupled BP+OSD + if(ndepth.eq.3 .and. & + (abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid .or. ncontest.eq.7)) then + maxosd=2 + endif + call timer('dec174_91 ',0) + Keff=91 + call decode174_91(llrz,Keff,maxosd,norder,apmask,message91,cw, & + ntype,nharderrors,dmin) + if(nharderrors.ge.0) message77=message91(1:77) + call timer('dec174_91 ',1) + + msg37=' ' + nbadcrc=1 + if(nharderrors.lt.0 .or. nharderrors.gt.36) cycle + if(count(cw.eq.0).eq.174) cycle !Reject the all-zero codeword + write(c77,'(77i1)') message77 + read(c77(72:74),'(b3)') n3 + read(c77(75:77),'(b3)') i3 + if(i3.gt.5 .or. (i3.eq.0.and.n3.gt.6)) cycle + if(i3.eq.0 .and. n3.eq.2) cycle + call unpack77(c77,1,msg37,unpk77_success) + if(.not.unpk77_success) cycle + nbadcrc=0 ! If we get this far: valid codeword, valid (i3,n3), nonquirky message. + call get_ft8_tones_from_77bits(message77,itone) + if(lsubtract) then + call timer('sub_ft8a',0) + call subtractft8(dd0,itone,f1,xdt,.false.) + call timer('sub_ft8a',1) + endif + xsig=0.0 + xnoi=0.0 + do i=1,79 + xsig=xsig+s8(itone(i),i)**2 + ios=mod(itone(i)+4,7) + xnoi=xnoi+s8(ios,i)**2 + enddo + xsnr=0.001 + xsnr2=0.001 + arg=xsig/xnoi-1.0 + if(arg.gt.0.1) xsnr=arg + arg=xsig/xbase/3.0e6-1.0 + if(arg.gt.0.1) xsnr2=arg + xsnr=10.0*log10(xsnr)-27.0 + xsnr2=10.0*log10(xsnr2)-27.0 + if(.not.nagain) then + xsnr=xsnr2 + endif + if(nsync.le.10 .and. xsnr.lt.-24.0) then !bail out, likely false decode + nbadcrc=1 + return + endif + if(xsnr .lt. -24.0) xsnr=-24.0 + return + enddo + return +end subroutine ft8b + +subroutine normalizebmet(bmet,n) + real bmet(n) + + bmetav=sum(bmet)/real(n) + bmet2av=sum(bmet*bmet)/real(n) + var=bmet2av-bmetav*bmetav + if( var .gt. 0.0 ) then + bmetsig=sqrt(var) + else + bmetsig=sqrt(bmet2av) + endif + bmet=bmet/bmetsig + return +end subroutine normalizebmet + + +function bessi0(x) +! From Numerical Recipes + real bessi0,x + double precision p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9,y + save p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9 + data p1,p2,p3,p4,p5,p6,p7/1.0d0,3.5156229d0,3.0899424d0,1.2067492d0, & + 0.2659732d0,0.360768d-1,0.45813d-2/ + data q1,q2,q3,q4,q5,q6,q7,q8,q9/0.39894228d0,0.1328592d-1, & + 0.225319d-2,-0.157565d-2,0.916281d-2,-0.2057706d-1, & + 0.2635537d-1,-0.1647633d-1,0.392377d-2/ + + if (abs(x).lt.3.75) then + y=(x/3.75)**2 + bessi0=p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7))))) + else + ax=abs(x) + y=3.75/ax + bessi0=(exp(ax)/sqrt(ax))*(q1+y*(q2+y*(q3+y*(q4 & + +y*(q5+y*(q6+y*(q7+y*(q8+y*q9)))))))) + endif + return +end function bessi0 diff --git a/lib/ft8/ft8c.f90 b/lib/ft8/ft8c.f90 index 87dc76ac..a7d1ccb9 100755 --- a/lib/ft8/ft8c.f90 +++ b/lib/ft8/ft8c.f90 @@ -1,261 +1,261 @@ -subroutine ft8c(dd0,newdat,call_1,call_2,grid4,xdt,f1,nharderrors,dmin, & - msg37,xsnr) - - use crc - use timer_module, only: timer - use packjt77 - include 'ft8_params.f90' - parameter(NP2=2812) - character*37 msg37,msg,msgsent,msgbest - character*12 call_1,call_2 - character*4 grid4 - real a(5) - real s8(0:7,NN) - real s2(0:511) - real bmeta(174),bmetb(174),bmetc(174),bmetd(174) - real llra(174),llrb(174),llrc(174),llrd(174),llrbest(174) !Soft symbols - real dd0(15*12000) - real ss(9) - real rcw(174) - integer*1 cw(174) - integer*1 msgbits(77) - integer*1 nxor(174),hdec(174) - integer itone(NN) - integer icos7(0:6),ip(1) - logical one(0:511,0:8) - integer graymap(0:7) - integer iloc(1) - complex cd0(0:3199) - complex ctwk(32) - complex csymb(32) - complex cs(0:7,NN) - logical std_1,std_2 - logical first,newdat - data icos7/3,1,4,0,6,5,2/ ! Flipped w.r.t. original FT8 sync array - data first/.true./ - data graymap/0,1,3,2,5,6,4,7/ - save one - - if(first) then - one=.false. - do i=0,511 - do j=0,8 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - first=.false. - endif - - call stdcall(call_1,std_1) - if(call_1(1:3).eq.'CQ ') std_1=.true. - call stdcall(call_2,std_2) - - nharderrors=-1 - fs2=12000.0/NDOWN - dt2=1.0/fs2 - twopi=8.0*atan(1.0) - delfbest=0. - ibest=0 - - call timer('ft8_down',0) - call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample - call timer('ft8_down',1) - - i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal - smax=0.0 - do idt=i0-10,i0+10 !Search over +/- one quarter symbol - call sync8d(cd0,idt,ctwk,0,sync) - if(sync.gt.smax) then - smax=sync - ibest=idt - endif - enddo - -! Now peak up in frequency - smax=0.0 - do ifr=-5,5 !Search over +/- 2.5 Hz - delf=ifr*0.5 - dphi=twopi*delf*dt2 - phi=0.0 - do i=1,32 - ctwk(i)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - enddo - call sync8d(cd0,ibest,ctwk,1,sync) - if( sync .gt. smax ) then - smax=sync - delfbest=delf - endif - enddo - a=0.0 - a(1)=-delfbest - call twkfreq1(cd0,NP2,fs2,a,cd0) - f1=f1+delfbest !Improved estimate of DF - - call timer('ft8_down',0) - call ft8_downsample(dd0,.false.,f1,cd0) !Mix f1 to baseband and downsample - call timer('ft8_down',1) - - smax=0.0 - do idt=-4,4 !Search over +/- one quarter symbol - call sync8d(cd0,ibest+idt,ctwk,0,sync) - ss(idt+5)=sync - enddo - smax=maxval(ss) - iloc=maxloc(ss) - ibest=iloc(1)-5+ibest - xdt=(ibest-1)*dt2 - 0.5 - sync=smax - - do k=1,NN - i1=ibest+(k-1)*32 - csymb=cmplx(0.0,0.0) - if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) - call four2a(csymb,32,1,-1,1) - cs(0:7,k)=csymb(1:8)/1e3 - s8(0:7,k)=abs(csymb(1:8)) - enddo - -! sync quality check - is1=0 - is2=0 - is3=0 - do k=1,7 - ip=maxloc(s8(:,k)) - if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 - ip=maxloc(s8(:,k+36)) - if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 - ip=maxloc(s8(:,k+72)) - if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 - enddo -! hard sync sum - max is 21 - nsync=is1+is2+is3 -! if(nsync .le. 6) return ! bail out - - do nsym=1,3 - nt=2**(3*nsym) - do ihalf=1,2 - do k=1,29,nsym - if(ihalf.eq.1) ks=k+7 - if(ihalf.eq.2) ks=k+43 - amax=-1.0 - do i=0,nt-1 - i1=i/64 - i2=iand(i,63)/8 - i3=iand(i,7) - if(nsym.eq.1) then - s2(i)=abs(cs(graymap(i3),ks)) - elseif(nsym.eq.2) then - s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) - elseif(nsym.eq.3) then - s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) - else - print*,"Error - nsym must be 1, 2, or 3." - endif - enddo - i32=1+(k-1)*3+(ihalf-1)*87 - if(nsym.eq.1) ibmax=2 - if(nsym.eq.2) ibmax=5 - if(nsym.eq.3) ibmax=8 - do ib=0,ibmax - bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) - if(i32+ib .gt.174) cycle - if(nsym.eq.1) then - bmeta(i32+ib)=bm - den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) - if(den.gt.0.0) then - cm=bm/den - else ! erase it - cm=0.0 - endif - bmetd(i32+ib)=cm - elseif(nsym.eq.2) then - bmetb(i32+ib)=bm - elseif(nsym.eq.3) then - bmetc(i32+ib)=bm - endif - enddo - enddo - enddo - enddo - call normalizebmet(bmeta,174) - call normalizebmet(bmetb,174) - call normalizebmet(bmetc,174) - call normalizebmet(bmetd,174) - - scalefac=2.83 - llra=scalefac*bmeta - llrb=scalefac*bmetb - llrc=scalefac*bmetc - llrd=scalefac*bmetd - -! apmag=maxval(abs(llra))*1.01 - - MAXMSG=206 - pbest=0. - do imsg=1,MAXMSG - msg=trim(call_1)//' '//trim(call_2) - i=imsg - if(call_1(1:3).eq.'CQ ' .and. i.ne.5) msg='QQ0XYZ '//trim(call_2) - if(.not.std_1) then - if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' - else if(.not.std_2) then - if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' - endif - j0=len(trim(msg))+2 - if(i.eq.2) msg(j0:j0+2)='RRR' - if(i.eq.3) msg(j0:j0+3)='RR73' - if(i.eq.4) msg(j0:j0+1)='73' - if(i.eq.5) then - if(std_2) then - msg='CQ '//trim(call_2) - if(call_1(3:3).eq.'_') msg=trim(call_1)//' '//trim(call_2) - if(grid4.ne.'RR73') msg=trim(msg)//' '//grid4 - endif - if(.not.std_2) msg='CQ '//trim(call_2) - endif - if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 - if(i.ge.7) then - isnr = -50 + (i-7)/2 - if(iand(i,1).eq.1) then - write(msg(j0:j0+2),'(i3.2)') isnr - if(msg(j0:j0).eq.' ') msg(j0:j0)='+' - else - write(msg(j0:j0+3),'("R",i3.2)') isnr - if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' - endif - endif - -! Source-encode, then get codeword - i3=-1 - n3=-1 - call genft8(msg,i3,n3,msgsent,msgbits,itone) - call encode174_91(msgbits,cw) - rcw=2*cw-1 - pa=sum(llra*rcw) - pb=sum(llrb*rcw) - pc=sum(llrc*rcw) - pd=sum(llrd*rcw) - - if(pa.gt.pbest) then - pbest=pa - msgbest=msgsent - llrbest=llra - nharderrors=count((2*cw-1)*llra.lt.0.0) - hdec=0 - where(llra.ge.0.0) hdec=1 - nxor=ieor(hdec,cw) - dmin=sum(nxor*abs(llra)) - endif - enddo ! imsg - -! write(*,4001) pbest,nharderrors,dmin,trim(msgbest) -!4001 format('$$$',f7.1,i4,f7.1,2x,a) - msg37=msgbest - - return -end subroutine ft8c +subroutine ft8c(dd0,newdat,call_1,call_2,grid4,xdt,f1,nharderrors,dmin, & + msg37,xsnr) + + use crc + use timer_module, only: timer + use packjt77 + include 'ft8_params.f90' + parameter(NP2=2812) + character*37 msg37,msg,msgsent,msgbest + character*12 call_1,call_2 + character*4 grid4 + real a(5) + real s8(0:7,NN) + real s2(0:511) + real bmeta(174),bmetb(174),bmetc(174),bmetd(174) + real llra(174),llrb(174),llrc(174),llrd(174),llrbest(174) !Soft symbols + real dd0(15*12000) + real ss(9) + real rcw(174) + integer*1 cw(174) + integer*1 msgbits(77) + integer*1 nxor(174),hdec(174) + integer itone(NN) + integer icos7(0:6),ip(1) + logical one(0:511,0:8) + integer graymap(0:7) + integer iloc(1) + complex cd0(0:3199) + complex ctwk(32) + complex csymb(32) + complex cs(0:7,NN) + logical std_1,std_2 + logical first,newdat + data icos7/3,1,4,0,6,5,2/ ! Flipped w.r.t. original FT8 sync array + data first/.true./ + data graymap/0,1,3,2,5,6,4,7/ + save one + + if(first) then + one=.false. + do i=0,511 + do j=0,8 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + first=.false. + endif + + call stdcall(call_1,std_1) + if(call_1(1:3).eq.'CQ ') std_1=.true. + call stdcall(call_2,std_2) + + nharderrors=-1 + fs2=12000.0/NDOWN + dt2=1.0/fs2 + twopi=8.0*atan(1.0) + delfbest=0. + ibest=0 + + call timer('ft8_down',0) + call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal + smax=0.0 + do idt=i0-10,i0+10 !Search over +/- one quarter symbol + call sync8d(cd0,idt,ctwk,0,sync) + if(sync.gt.smax) then + smax=sync + ibest=idt + endif + enddo + +! Now peak up in frequency + smax=0.0 + do ifr=-5,5 !Search over +/- 2.5 Hz + delf=ifr*0.5 + dphi=twopi*delf*dt2 + phi=0.0 + do i=1,32 + ctwk(i)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + enddo + call sync8d(cd0,ibest,ctwk,1,sync) + if( sync .gt. smax ) then + smax=sync + delfbest=delf + endif + enddo + a=0.0 + a(1)=-delfbest + call twkfreq1(cd0,NP2,fs2,a,cd0) + f1=f1+delfbest !Improved estimate of DF + + call timer('ft8_down',0) + call ft8_downsample(dd0,.false.,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + smax=0.0 + do idt=-4,4 !Search over +/- one quarter symbol + call sync8d(cd0,ibest+idt,ctwk,0,sync) + ss(idt+5)=sync + enddo + smax=maxval(ss) + iloc=maxloc(ss) + ibest=iloc(1)-5+ibest + xdt=(ibest-1)*dt2 - 0.5 + sync=smax + + do k=1,NN + i1=ibest+(k-1)*32 + csymb=cmplx(0.0,0.0) + if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) + call four2a(csymb,32,1,-1,1) + cs(0:7,k)=csymb(1:8)/1e3 + s8(0:7,k)=abs(csymb(1:8)) + enddo + +! sync quality check + is1=0 + is2=0 + is3=0 + do k=1,7 + ip=maxloc(s8(:,k)) + if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s8(:,k+36)) + if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s8(:,k+72)) + if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 + enddo +! hard sync sum - max is 21 + nsync=is1+is2+is3 +! if(nsync .le. 6) return ! bail out + + do nsym=1,3 + nt=2**(3*nsym) + do ihalf=1,2 + do k=1,29,nsym + if(ihalf.eq.1) ks=k+7 + if(ihalf.eq.2) ks=k+43 + amax=-1.0 + do i=0,nt-1 + i1=i/64 + i2=iand(i,63)/8 + i3=iand(i,7) + if(nsym.eq.1) then + s2(i)=abs(cs(graymap(i3),ks)) + elseif(nsym.eq.2) then + s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) + elseif(nsym.eq.3) then + s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) + else + print*,"Error - nsym must be 1, 2, or 3." + endif + enddo + i32=1+(k-1)*3+(ihalf-1)*87 + if(nsym.eq.1) ibmax=2 + if(nsym.eq.2) ibmax=5 + if(nsym.eq.3) ibmax=8 + do ib=0,ibmax + bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) + if(i32+ib .gt.174) cycle + if(nsym.eq.1) then + bmeta(i32+ib)=bm + den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) + if(den.gt.0.0) then + cm=bm/den + else ! erase it + cm=0.0 + endif + bmetd(i32+ib)=cm + elseif(nsym.eq.2) then + bmetb(i32+ib)=bm + elseif(nsym.eq.3) then + bmetc(i32+ib)=bm + endif + enddo + enddo + enddo + enddo + call normalizebmet(bmeta,174) + call normalizebmet(bmetb,174) + call normalizebmet(bmetc,174) + call normalizebmet(bmetd,174) + + scalefac=2.83 + llra=scalefac*bmeta + llrb=scalefac*bmetb + llrc=scalefac*bmetc + llrd=scalefac*bmetd + +! apmag=maxval(abs(llra))*1.01 + + MAXMSG=206 + pbest=0. + do imsg=1,MAXMSG + msg=trim(call_1)//' '//trim(call_2) + i=imsg + if(call_1(1:3).eq.'CQ ' .and. i.ne.5) msg='QQ0XYZ '//trim(call_2) + if(.not.std_1) then + if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' + else if(.not.std_2) then + if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' + endif + j0=len(trim(msg))+2 + if(i.eq.2) msg(j0:j0+2)='RRR' + if(i.eq.3) msg(j0:j0+3)='RR73' + if(i.eq.4) msg(j0:j0+1)='73' + if(i.eq.5) then + if(std_2) then + msg='CQ '//trim(call_2) + if(call_1(3:3).eq.'_') msg=trim(call_1)//' '//trim(call_2) + if(grid4.ne.'RR73') msg=trim(msg)//' '//grid4 + endif + if(.not.std_2) msg='CQ '//trim(call_2) + endif + if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 + if(i.ge.7) then + isnr = -50 + (i-7)/2 + if(iand(i,1).eq.1) then + write(msg(j0:j0+2),'(i3.2)') isnr + if(msg(j0:j0).eq.' ') msg(j0:j0)='+' + else + write(msg(j0:j0+3),'("R",i3.2)') isnr + if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' + endif + endif + +! Source-encode, then get codeword + i3=-1 + n3=-1 + call genft8(msg,i3,n3,msgsent,msgbits,itone) + call encode174_91(msgbits,cw) + rcw=2*cw-1 + pa=sum(llra*rcw) + pb=sum(llrb*rcw) + pc=sum(llrc*rcw) + pd=sum(llrd*rcw) + + if(pa.gt.pbest) then + pbest=pa + msgbest=msgsent + llrbest=llra + nharderrors=count((2*cw-1)*llra.lt.0.0) + hdec=0 + where(llra.ge.0.0) hdec=1 + nxor=ieor(hdec,cw) + dmin=sum(nxor*abs(llra)) + endif + enddo ! imsg + +! write(*,4001) pbest,nharderrors,dmin,trim(msgbest) +!4001 format('$$$',f7.1,i4,f7.1,2x,a) + msg37=msgbest + + return +end subroutine ft8c diff --git a/lib/ft8/ft8code.f90 b/lib/ft8/ft8code.f90 index 45b0b6a6..53371ff4 100755 --- a/lib/ft8/ft8code.f90 +++ b/lib/ft8/ft8code.f90 @@ -1,105 +1,105 @@ -program ft8code - -! Provides examples of message packing, LDPC(174,91) encoding, bit and -! symbol ordering, and other details of the FT8 protocol. - - use packjt77 - include 'ft8_params.f90' !Set various constants - include 'ft8_testmsg.f90' - parameter (NWAVE=NN*NSPS) - - character*37 msg,msgsent - character*9 comment - character bad*1,msgtype*18 - integer itone(NN) - integer*1 msgbits(77),codeword(174) - logical short - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.1 .and. nargs.ne.3) then - print* - print*,'Program ft8code: Provides examples of message packing, ', & - 'LDPC(174,91) encoding,' - print*,'bit and symbol ordering, and other details of the FT8 protocol.' - print* - print*,'Usage: ft8code "message" # Results for specified message' - print*,' ft8code -T # Examples of all message types' - print*,' ft8code -t # Short format examples' - go to 999 - endif - - call getarg(1,msg) !Message to be transmitted - short=.false. - if(len(trim(msg)).eq.2 .and. (msg(1:2).eq.'-T' .or. msg(1:2).eq.'-t')) then - nmsg=NTEST - short=msg(1:2).eq.'-t' - else - call fmtmsg(msg,iz) !To upper case; collapse multiple blanks - nmsg=1 - endif - - if(.not.short) write(*,1010) -1010 format(4x,'Message',31x,'Decoded',29x,'Err i3.n3'/100('-')) - - do imsg=1,nmsg - if(nmsg.gt.1) msg=testmsg(imsg) - -! Generate msgsent, msgbits, and itone - i3=-1 - n3=-1 - call genft8(msg,i3,n3,msgsent,msgbits,itone) - call encode174_91(msgbits,codeword) - msgtype="" - if(i3.eq.0) then - if(n3.eq.0) msgtype="Free text" - if(n3.eq.1) msgtype="DXpedition mode" - if(n3.eq.2) msgtype="EU VHF Contest" - if(n3.eq.3) msgtype="ARRL Field Day" - if(n3.eq.4) msgtype="ARRL Field Day" - if(n3.eq.5) msgtype="Telemetry" - if(n3.ge.6) msgtype="Undefined type" - endif - if(i3.eq.1) msgtype="Standard msg" - if(i3.eq.2) msgtype="EU VHF Contest" - if(i3.eq.3) msgtype="ARRL RTTY Roundup" - if(i3.eq.4) msgtype="Nonstandard call" - if(i3.eq.5) msgtype="EU VHF Contest" - if(i3.ge.6) msgtype="Undefined type" - if(i3.ge.1) n3=-1 - bad=" " - comment=' ' - if(msg.ne.msgsent) bad="*" - if(short) then - if(n3.ge.0) then - write(*,1020) i3,n3,msg,bad,msgtype -1020 format(i1,'.',i1,2x,a37,1x,a1,1x,a18) - else - write(*,1022) i3,msg,bad,msgtype -1022 format(i1,'.',3x,a37,1x,a1,1x,a18) - endif - else - if(n3.ge.0) then - write(*,1024) imsg,msg,msgsent,bad,i3,n3,msgtype,comment -1024 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',i1,1x,a18,1x,a9) - else - write(*,1026) imsg,msg,msgsent,bad,i3,msgtype,comment -1026 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',1x,1x,a18,1x,a9) - endif - endif - enddo - - if(nmsg.eq.1) then - write(*,1030) msgbits -1030 format(/'Source-encoded message, 77 bits: ',/77i1) - write(*,1031) codeword(78:91) -1031 format(/'14-bit CRC: ',/14i1) - write(*,1032) codeword(92:174) -1032 format(/'83 Parity bits: ',/83i1) - write(*,1034) itone -1034 format(/'Channel symbols (79 tones):'/ & - ' Sync ',14x,'Data',15x,'Sync',15x,'Data',15x,'Sync'/ & - 7i1,1x,29i1,1x,7i1,1x,29i1,1x,7i1) - endif - -999 end program ft8code +program ft8code + +! Provides examples of message packing, LDPC(174,91) encoding, bit and +! symbol ordering, and other details of the FT8 protocol. + + use packjt77 + include 'ft8_params.f90' !Set various constants + include 'ft8_testmsg.f90' + parameter (NWAVE=NN*NSPS) + + character*37 msg,msgsent + character*9 comment + character bad*1,msgtype*18 + integer itone(NN) + integer*1 msgbits(77),codeword(174) + logical short + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.1 .and. nargs.ne.3) then + print* + print*,'Program ft8code: Provides examples of message packing, ', & + 'LDPC(174,91) encoding,' + print*,'bit and symbol ordering, and other details of the FT8 protocol.' + print* + print*,'Usage: ft8code "message" # Results for specified message' + print*,' ft8code -T # Examples of all message types' + print*,' ft8code -t # Short format examples' + go to 999 + endif + + call getarg(1,msg) !Message to be transmitted + short=.false. + if(len(trim(msg)).eq.2 .and. (msg(1:2).eq.'-T' .or. msg(1:2).eq.'-t')) then + nmsg=NTEST + short=msg(1:2).eq.'-t' + else + call fmtmsg(msg,iz) !To upper case; collapse multiple blanks + nmsg=1 + endif + + if(.not.short) write(*,1010) +1010 format(4x,'Message',31x,'Decoded',29x,'Err i3.n3'/100('-')) + + do imsg=1,nmsg + if(nmsg.gt.1) msg=testmsg(imsg) + +! Generate msgsent, msgbits, and itone + i3=-1 + n3=-1 + call genft8(msg,i3,n3,msgsent,msgbits,itone) + call encode174_91(msgbits,codeword) + msgtype="" + if(i3.eq.0) then + if(n3.eq.0) msgtype="Free text" + if(n3.eq.1) msgtype="DXpedition mode" + if(n3.eq.2) msgtype="EU VHF Contest" + if(n3.eq.3) msgtype="ARRL Field Day" + if(n3.eq.4) msgtype="ARRL Field Day" + if(n3.eq.5) msgtype="Telemetry" + if(n3.ge.6) msgtype="Undefined type" + endif + if(i3.eq.1) msgtype="Standard msg" + if(i3.eq.2) msgtype="EU VHF Contest" + if(i3.eq.3) msgtype="ARRL RTTY Roundup" + if(i3.eq.4) msgtype="Nonstandard call" + if(i3.eq.5) msgtype="EU VHF Contest" + if(i3.ge.6) msgtype="Undefined type" + if(i3.ge.1) n3=-1 + bad=" " + comment=' ' + if(msg.ne.msgsent) bad="*" + if(short) then + if(n3.ge.0) then + write(*,1020) i3,n3,msg,bad,msgtype +1020 format(i1,'.',i1,2x,a37,1x,a1,1x,a18) + else + write(*,1022) i3,msg,bad,msgtype +1022 format(i1,'.',3x,a37,1x,a1,1x,a18) + endif + else + if(n3.ge.0) then + write(*,1024) imsg,msg,msgsent,bad,i3,n3,msgtype,comment +1024 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',i1,1x,a18,1x,a9) + else + write(*,1026) imsg,msg,msgsent,bad,i3,msgtype,comment +1026 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',1x,1x,a18,1x,a9) + endif + endif + enddo + + if(nmsg.eq.1) then + write(*,1030) msgbits +1030 format(/'Source-encoded message, 77 bits: ',/77i1) + write(*,1031) codeword(78:91) +1031 format(/'14-bit CRC: ',/14i1) + write(*,1032) codeword(92:174) +1032 format(/'83 Parity bits: ',/83i1) + write(*,1034) itone +1034 format(/'Channel symbols (79 tones):'/ & + ' Sync ',14x,'Data',15x,'Sync',15x,'Data',15x,'Sync'/ & + 7i1,1x,29i1,1x,7i1,1x,29i1,1x,7i1) + endif + +999 end program ft8code diff --git a/lib/ft8/ft8d.f90 b/lib/ft8/ft8d.f90 index 28af93d1..4d107135 100755 --- a/lib/ft8/ft8d.f90 +++ b/lib/ft8/ft8d.f90 @@ -1,63 +1,63 @@ -program ft8d - -! Decode FT8 data read from *.wav files. - - include 'ft8_params.f90' - character*12 arg - character infile*80,datetime*13,message*22 - real s(NH1,NHSYM) - real candidate(3,100) - integer ihdr(11) - integer*2 iwave(NMAX) !Generated full-length waveform - real dd(NMAX) - - nargs=iargc() - if(nargs.lt.3) then - print*,'Usage: ft8d MaxIt Norder file1 [file2 ...]' - print*,'Example ft8d 40 2 *.wav' - go to 999 - endif - call getarg(1,arg) - read(arg,*) max_iterations - call getarg(2,arg) - read(arg,*) norder - nfiles=nargs-2 - - twopi=8.0*atan(1.0) - fs=12000.0 !Sample rate - dt=1.0/fs !Sample interval (s) - tt=NSPS*dt !Duration of "itone" symbols (s) - ts=2*NSPS*dt !Duration of OQPSK symbols (s) - baud=1.0/tt !Keying rate (baud) - txt=NZ*dt !Transmission length (s) - nfa=100.0 - nfb=3000.0 - nfqso=1500.0 - - do ifile=1,nfiles - call getarg(ifile+2,infile) - open(10,file=infile,status='old',access='stream') - read(10,end=999) ihdr,iwave - close(10) - j2=index(infile,'.wav') - read(infile(j2-6:j2-1),*) nutc - datetime=infile(j2-13:j2-1) - call sync8(iwave,NMAX,nfa,nfb,nfqso,s,candidate,ncand) - syncmin=2.0 - dd=iwave - do icand=1,ncand - sync=candidate(3,icand) - if( sync.lt.syncmin) cycle - f1=candidate(1,icand) - xdt=candidate(2,icand) - nsnr=min(99,nint(10.0*log10(sync)-25.5)) - call ft8b(dd,nfqso,f1,xdt,nharderrors,dmin,nbadcrc,message,xsnr) - nsnr=xsnr - xdt=xdt-0.6 - write(*,1110) datetime,0,nsnr,xdt,f1,message,nharderrors,dmin -1110 format(a13,2i4,f6.2,f7.1,' ~ ',a22,i6,f7.1) - enddo - enddo ! ifile loop - -999 end program ft8d - +program ft8d + +! Decode FT8 data read from *.wav files. + + include 'ft8_params.f90' + character*12 arg + character infile*80,datetime*13,message*22 + real s(NH1,NHSYM) + real candidate(3,100) + integer ihdr(11) + integer*2 iwave(NMAX) !Generated full-length waveform + real dd(NMAX) + + nargs=iargc() + if(nargs.lt.3) then + print*,'Usage: ft8d MaxIt Norder file1 [file2 ...]' + print*,'Example ft8d 40 2 *.wav' + go to 999 + endif + call getarg(1,arg) + read(arg,*) max_iterations + call getarg(2,arg) + read(arg,*) norder + nfiles=nargs-2 + + twopi=8.0*atan(1.0) + fs=12000.0 !Sample rate + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + ts=2*NSPS*dt !Duration of OQPSK symbols (s) + baud=1.0/tt !Keying rate (baud) + txt=NZ*dt !Transmission length (s) + nfa=100.0 + nfb=3000.0 + nfqso=1500.0 + + do ifile=1,nfiles + call getarg(ifile+2,infile) + open(10,file=infile,status='old',access='stream') + read(10,end=999) ihdr,iwave + close(10) + j2=index(infile,'.wav') + read(infile(j2-6:j2-1),*) nutc + datetime=infile(j2-13:j2-1) + call sync8(iwave,NMAX,nfa,nfb,nfqso,s,candidate,ncand) + syncmin=2.0 + dd=iwave + do icand=1,ncand + sync=candidate(3,icand) + if( sync.lt.syncmin) cycle + f1=candidate(1,icand) + xdt=candidate(2,icand) + nsnr=min(99,nint(10.0*log10(sync)-25.5)) + call ft8b(dd,nfqso,f1,xdt,nharderrors,dmin,nbadcrc,message,xsnr) + nsnr=xsnr + xdt=xdt-0.6 + write(*,1110) datetime,0,nsnr,xdt,f1,message,nharderrors,dmin +1110 format(a13,2i4,f6.2,f7.1,' ~ ',a22,i6,f7.1) + enddo + enddo ! ifile loop + +999 end program ft8d + diff --git a/lib/ft8/ft8q3.f90 b/lib/ft8/ft8q3.f90 index 74f8a763..122e49c9 100755 --- a/lib/ft8/ft8q3.f90 +++ b/lib/ft8/ft8q3.f90 @@ -1,109 +1,109 @@ -subroutine ft8q3(cd,xdt,f0,call_1,call_2,grid4,msgbest,snr) - -! Get q3-style decodes for FT8. - - use packjt77 - parameter(NN=79,NSPS=32) - parameter(NWAVE=NN*NSPS) !2528 - parameter(NZ=3200,NLAGS=NZ-NWAVE) - character*12 call_1,call_2 - character*4 grid4 - character*37 msg,msgbest,msgsent - character c77*77 - complex cwave(0:NWAVE-1) - complex cd(0:NZ-1) - complex z - real xjunk(NWAVE) - real ccf(0:NLAGS-1) - real ccfmsg(206) - integer itone(NN) - integer*1 msgbits(77) - logical std_1,std_2 - - if(xdt.eq.-99.0) return !Silence compiler warning - call stdcall(call_1,std_1) - call stdcall(call_2,std_2) - - fs=200.0 !Sample rate (Hz) - dt=1.0/fs !Sample interval (s) - bt=2.0 - ccfbest=0. - lagbest=-1 - - do imsg=1,206 - msg=trim(call_1)//' '//trim(call_2) - i=imsg - if(.not.std_1) then - if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' - else if(.not.std_2) then - if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' - endif - j0=len(trim(msg))+2 - if(i.eq.2) msg(j0:j0+2)='RRR' - if(i.eq.3) msg(j0:j0+3)='RR73' - if(i.eq.4) msg(j0:j0+1)='73' - if(i.eq.5) then - if(std_2) msg='CQ '//trim(call_2)//' '//grid4 - if(.not.std_2) msg='CQ '//trim(call_2) - endif - if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 - if(i.ge.7 .and. i.le.206) then - isnr = -50 + (i-7)/2 - if(iand(i,1).eq.1) then - write(msg(j0:j0+2),'(i3.2)') isnr - if(msg(j0:j0).eq.' ') msg(j0:j0)='+' - else - write(msg(j0:j0+3),'("R",i3.2)') isnr - if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' - endif - endif - -! Source-encode, then get itone() - i3=-1 - n3=-1 - call pack77(msg,i3,n3,c77) - call genft8(msg,i3,n3,msgsent,msgbits,itone) -! Generate complex cwave - call gen_ft8wave(itone,NN,NSPS,bt,fs,f0,cwave,xjunk,1,NWAVE) - - lagmax=-1 - ccfmax=0. - nsum=32*2 - do lag=0,nlags-1 - z=0. - s=0. - do i=0,NWAVE-1 - z=z + cd(i+lag)*conjg(cwave(i)) - if(mod(i,nsum).eq.nsum-1 .or. i.eq.NWAVE-1) then - s=s + abs(z) - z=0. - endif - enddo - ccf(lag)=s - if(ccf(lag).gt.ccfmax) then - ccfmax=ccf(lag) - lagmax=lag - endif - enddo ! lag - ccfmsg(imsg)=ccfmax - if(ccfmax.gt.ccfbest) then - ccfbest=ccfmax - lagbest=lagmax - msgbest=msg - endif - enddo ! imsg - - call pctile(ccfmsg,207,50,base) - call pctile(ccfmsg,207,67,sigma) - sigma=sigma-base - ccfmsg=(ccfmsg-base)/sigma -! do imsg=1,207 -! write(44,3044) imsg,ccfmsg(imsg) -!3044 format(i5,f10.3) -! enddo - snr=maxval(ccfmsg) - - return -end subroutine ft8q3 +subroutine ft8q3(cd,xdt,f0,call_1,call_2,grid4,msgbest,snr) + +! Get q3-style decodes for FT8. + + use packjt77 + parameter(NN=79,NSPS=32) + parameter(NWAVE=NN*NSPS) !2528 + parameter(NZ=3200,NLAGS=NZ-NWAVE) + character*12 call_1,call_2 + character*4 grid4 + character*37 msg,msgbest,msgsent + character c77*77 + complex cwave(0:NWAVE-1) + complex cd(0:NZ-1) + complex z + real xjunk(NWAVE) + real ccf(0:NLAGS-1) + real ccfmsg(206) + integer itone(NN) + integer*1 msgbits(77) + logical std_1,std_2 + + if(xdt.eq.-99.0) return !Silence compiler warning + call stdcall(call_1,std_1) + call stdcall(call_2,std_2) + + fs=200.0 !Sample rate (Hz) + dt=1.0/fs !Sample interval (s) + bt=2.0 + ccfbest=0. + lagbest=-1 + + do imsg=1,206 + msg=trim(call_1)//' '//trim(call_2) + i=imsg + if(.not.std_1) then + if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' + else if(.not.std_2) then + if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' + endif + j0=len(trim(msg))+2 + if(i.eq.2) msg(j0:j0+2)='RRR' + if(i.eq.3) msg(j0:j0+3)='RR73' + if(i.eq.4) msg(j0:j0+1)='73' + if(i.eq.5) then + if(std_2) msg='CQ '//trim(call_2)//' '//grid4 + if(.not.std_2) msg='CQ '//trim(call_2) + endif + if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 + if(i.ge.7 .and. i.le.206) then + isnr = -50 + (i-7)/2 + if(iand(i,1).eq.1) then + write(msg(j0:j0+2),'(i3.2)') isnr + if(msg(j0:j0).eq.' ') msg(j0:j0)='+' + else + write(msg(j0:j0+3),'("R",i3.2)') isnr + if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' + endif + endif + +! Source-encode, then get itone() + i3=-1 + n3=-1 + call pack77(msg,i3,n3,c77) + call genft8(msg,i3,n3,msgsent,msgbits,itone) +! Generate complex cwave + call gen_ft8wave(itone,NN,NSPS,bt,fs,f0,cwave,xjunk,1,NWAVE) + + lagmax=-1 + ccfmax=0. + nsum=32*2 + do lag=0,nlags-1 + z=0. + s=0. + do i=0,NWAVE-1 + z=z + cd(i+lag)*conjg(cwave(i)) + if(mod(i,nsum).eq.nsum-1 .or. i.eq.NWAVE-1) then + s=s + abs(z) + z=0. + endif + enddo + ccf(lag)=s + if(ccf(lag).gt.ccfmax) then + ccfmax=ccf(lag) + lagmax=lag + endif + enddo ! lag + ccfmsg(imsg)=ccfmax + if(ccfmax.gt.ccfbest) then + ccfbest=ccfmax + lagbest=lagmax + msgbest=msg + endif + enddo ! imsg + + call pctile(ccfmsg,207,50,base) + call pctile(ccfmsg,207,67,sigma) + sigma=sigma-base + ccfmsg=(ccfmsg-base)/sigma +! do imsg=1,207 +! write(44,3044) imsg,ccfmsg(imsg) +!3044 format(i5,f10.3) +! enddo + snr=maxval(ccfmsg) + + return +end subroutine ft8q3 diff --git a/lib/ft8/ft8sim.f90 b/lib/ft8/ft8sim.f90 index 693542be..5943bd08 100755 --- a/lib/ft8/ft8sim.f90 +++ b/lib/ft8/ft8sim.f90 @@ -1,141 +1,141 @@ -program ft8sim_gfsk - -! Generate simulated "type 2" ft8 files -! Output is saved to a *.wav file. - - use wavhdr - use packjt77 - include 'ft8_params.f90' !Set various constants - parameter (NWAVE=NN*NSPS) - type(hdr) h !Header for .wav file - character arg*12,fname*17 - character msg37*37,msgsent37*37 - character c77*77 - complex c0(0:NMAX-1) - complex c(0:NMAX-1) - complex cwave(0:NWAVE-1) - real wave(NMAX) - real xjunk(NWAVE) - integer itone(NN) - integer*1 msgbits(77) - integer*2 iwave(NMAX) !Generated full-length waveform - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.7) then - print*,'Usage: ft8sim "message" f0 DT fdop del nfiles snr' - print*,'Examples: ft8sim "K1ABC W9XYZ EN37" 1500.0 0.0 0.1 1.0 10 -18' - print*,' ft8sim "WA9XYZ/R KA1ABC/R FN42" 1500.0 0.0 0.1 1.0 10 -18' - print*,' ft8sim "K1ABC RR73; W9XYZ -11" 300 0 0 0 25 1 -10' - print*,' ft8sim " R 570007 JO22DB" 1500 0 0 0 1 -10' - go to 999 - endif - call getarg(1,msg37) !Message to be transmitted - call getarg(2,arg) - read(arg,*) f0 !Frequency (only used for single-signal) - call getarg(3,arg) - read(arg,*) xdt !Time offset from nominal (s) - call getarg(4,arg) - read(arg,*) fspread !Watterson frequency spread (Hz) - call getarg(5,arg) - read(arg,*) delay !Watterson delay (ms) - call getarg(6,arg) - read(arg,*) nfiles !Number of files - call getarg(7,arg) - read(arg,*) snrdb !SNR_2500 - - nsig=1 - if(f0.lt.100.0) then - nsig=f0 - f0=1500 - endif - - nfiles=abs(nfiles) - twopi=8.0*atan(1.0) - fs=12000.0 !Sample rate (Hz) - dt=1.0/fs !Sample interval (s) - tt=NSPS*dt !Duration of symbols (s) - baud=1.0/tt !Keying rate (baud) - bw=8*baud !Occupied bandwidth (Hz) - txt=NZ*dt !Transmission length (s) - bt=2.0 - bandwidth_ratio=2500.0/(fs/2.0) - sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) - if(snrdb.gt.90.0) sig=1.0 - txt=NN*NSPS/12000.0 - - ! Source-encode, then get itone() - i3=-1 - n3=-1 - call pack77(msg37,i3,n3,c77) - call genft8(msg37,i3,n3,msgsent37,msgbits,itone) - call gen_ft8wave(itone,NN,NSPS,bt,fs,f0,cwave,xjunk,1,NWAVE) !Generate complex cwave - - write(*,*) - write(*,'(a23,a37,3x,a7,i1,a1,i1)') 'Decoded message: ',msgsent37,'i3.n3: ',i3,'.',n3 - write(*,1000) f0,xdt,txt,snrdb,bw -1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1, & - ' BW:',f4.1) - write(*,*) - if(i3.eq.1) then - write(*,*) ' mycall hiscall hisgrid' - write(*,'(28i1,1x,i1,1x,28i1,1x,i1,1x,i1,1x,15i1,1x,3i1)') msgbits(1:77) - else - write(*,'(a14)') 'Message bits: ' - write(*,'(77i1)') msgbits - endif - write(*,*) - write(*,'(a17)') 'Channel symbols: ' - write(*,'(79i1)') itone - write(*,*) - - call sgran() - - do ifile=1,nfiles - c0=0. - c0(0:NWAVE-1)=cwave - c0=cshift(c0,-nint((xdt+0.5)/dt)) - if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c0,NMAX,NWAVE,fs,delay,fspread) - c=sig*c0 - - wave=imag(c) - peak=maxval(abs(wave)) - nslots=1 - - psig=0. - pnoise=0. - if(snrdb.lt.90) then - do i=1,NMAX !Add gaussian noise at specified SNR - xnoise=gran() - if(i.ge.6001 .and. i.le.157692) then - psig=psig + wave(i)*wave(i) !Signal power - pnoise=pnoise + xnoise*xnoise !Noise power in signal interval - endif - wave(i)=wave(i) + xnoise - enddo - endif - -! Noise power in signal interval and 2500 Hz bandwidth: - pnoise=bandwidth_ratio*pnoise - snr_2500=db(psig/pnoise) !SNR in 2500 Hz bandwidth - - gain=100.0 - if(snrdb.lt.90.0) then - wave=gain*wave - else - datpk=maxval(abs(wave)) - fac=32766.9/datpk - wave=fac*wave - endif - if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." - iwave=nint(wave) - h=default_header(12000,NMAX) - write(fname,1102) ifile -1102 format('000000_',i6.6,'.wav') - open(10,file=fname,status='unknown',access='stream') - write(10) h,iwave !Save to *.wav file - close(10) - write(*,1110) ifile,xdt,f0,snrdb,fname,snr_2500 -1110 format(i4,f7.2,f8.2,f7.1,2x,a17,f8.2) - enddo -999 end program ft8sim_gfsk +program ft8sim_gfsk + +! Generate simulated "type 2" ft8 files +! Output is saved to a *.wav file. + + use wavhdr + use packjt77 + include 'ft8_params.f90' !Set various constants + parameter (NWAVE=NN*NSPS) + type(hdr) h !Header for .wav file + character arg*12,fname*17 + character msg37*37,msgsent37*37 + character c77*77 + complex c0(0:NMAX-1) + complex c(0:NMAX-1) + complex cwave(0:NWAVE-1) + real wave(NMAX) + real xjunk(NWAVE) + integer itone(NN) + integer*1 msgbits(77) + integer*2 iwave(NMAX) !Generated full-length waveform + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.7) then + print*,'Usage: ft8sim "message" f0 DT fdop del nfiles snr' + print*,'Examples: ft8sim "K1ABC W9XYZ EN37" 1500.0 0.0 0.1 1.0 10 -18' + print*,' ft8sim "WA9XYZ/R KA1ABC/R FN42" 1500.0 0.0 0.1 1.0 10 -18' + print*,' ft8sim "K1ABC RR73; W9XYZ -11" 300 0 0 0 25 1 -10' + print*,' ft8sim " R 570007 JO22DB" 1500 0 0 0 1 -10' + go to 999 + endif + call getarg(1,msg37) !Message to be transmitted + call getarg(2,arg) + read(arg,*) f0 !Frequency (only used for single-signal) + call getarg(3,arg) + read(arg,*) xdt !Time offset from nominal (s) + call getarg(4,arg) + read(arg,*) fspread !Watterson frequency spread (Hz) + call getarg(5,arg) + read(arg,*) delay !Watterson delay (ms) + call getarg(6,arg) + read(arg,*) nfiles !Number of files + call getarg(7,arg) + read(arg,*) snrdb !SNR_2500 + + nsig=1 + if(f0.lt.100.0) then + nsig=f0 + f0=1500 + endif + + nfiles=abs(nfiles) + twopi=8.0*atan(1.0) + fs=12000.0 !Sample rate (Hz) + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of symbols (s) + baud=1.0/tt !Keying rate (baud) + bw=8*baud !Occupied bandwidth (Hz) + txt=NZ*dt !Transmission length (s) + bt=2.0 + bandwidth_ratio=2500.0/(fs/2.0) + sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + txt=NN*NSPS/12000.0 + + ! Source-encode, then get itone() + i3=-1 + n3=-1 + call pack77(msg37,i3,n3,c77) + call genft8(msg37,i3,n3,msgsent37,msgbits,itone) + call gen_ft8wave(itone,NN,NSPS,bt,fs,f0,cwave,xjunk,1,NWAVE) !Generate complex cwave + + write(*,*) + write(*,'(a23,a37,3x,a7,i1,a1,i1)') 'Decoded message: ',msgsent37,'i3.n3: ',i3,'.',n3 + write(*,1000) f0,xdt,txt,snrdb,bw +1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1, & + ' BW:',f4.1) + write(*,*) + if(i3.eq.1) then + write(*,*) ' mycall hiscall hisgrid' + write(*,'(28i1,1x,i1,1x,28i1,1x,i1,1x,i1,1x,15i1,1x,3i1)') msgbits(1:77) + else + write(*,'(a14)') 'Message bits: ' + write(*,'(77i1)') msgbits + endif + write(*,*) + write(*,'(a17)') 'Channel symbols: ' + write(*,'(79i1)') itone + write(*,*) + + call sgran() + + do ifile=1,nfiles + c0=0. + c0(0:NWAVE-1)=cwave + c0=cshift(c0,-nint((xdt+0.5)/dt)) + if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c0,NMAX,NWAVE,fs,delay,fspread) + c=sig*c0 + + wave=imag(c) + peak=maxval(abs(wave)) + nslots=1 + + psig=0. + pnoise=0. + if(snrdb.lt.90) then + do i=1,NMAX !Add gaussian noise at specified SNR + xnoise=gran() + if(i.ge.6001 .and. i.le.157692) then + psig=psig + wave(i)*wave(i) !Signal power + pnoise=pnoise + xnoise*xnoise !Noise power in signal interval + endif + wave(i)=wave(i) + xnoise + enddo + endif + +! Noise power in signal interval and 2500 Hz bandwidth: + pnoise=bandwidth_ratio*pnoise + snr_2500=db(psig/pnoise) !SNR in 2500 Hz bandwidth + + gain=100.0 + if(snrdb.lt.90.0) then + wave=gain*wave + else + datpk=maxval(abs(wave)) + fac=32766.9/datpk + wave=fac*wave + endif + if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." + iwave=nint(wave) + h=default_header(12000,NMAX) + write(fname,1102) ifile +1102 format('000000_',i6.6,'.wav') + open(10,file=fname,status='unknown',access='stream') + write(10) h,iwave !Save to *.wav file + close(10) + write(*,1110) ifile,xdt,f0,snrdb,fname,snr_2500 +1110 format(i4,f7.2,f8.2,f7.1,2x,a17,f8.2) + enddo +999 end program ft8sim_gfsk diff --git a/lib/ft8/gen_ft8wave.f90 b/lib/ft8/gen_ft8wave.f90 index 1d395520..c7be0915 100755 --- a/lib/ft8/gen_ft8wave.f90 +++ b/lib/ft8/gen_ft8wave.f90 @@ -1,83 +1,83 @@ -subroutine gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) -! -! generate ft8 waveform using Gaussian-filtered frequency pulses. -! - use timer_module, only: timer - parameter(MAX_SECONDS=20,NTAB=65536) - real wave(nwave) - complex cwave(nwave),ctab(0:NTAB-1) - real pulse(23040) - real dphi(0:(nsym+2)*nsps-1) - integer itone(nsym) - data fchk0/0.0/ - save pulse,twopi,dt,hmod,fchk0,ctab - - ibt=nint(10*bt) - fchk=nsym+nsps+bt+fsample - if(fchk.ne.fchk0) then - twopi=8.0*atan(1.0) - dt=1.0/fsample - hmod=1.0 -! Compute the frequency-smoothing pulse - do i=1,3*nsps - tt=(i-1.5*nsps)/real(nsps) - pulse(i)=gfsk_pulse(bt,tt) - enddo - do i=0,NTAB-1 - phi=i*twopi/NTAB - ctab(i)=cmplx(cos(phi),sin(phi)) - enddo - fchk0=fchk - endif - -! Compute the smoothed frequency waveform. -! Length = (nsym+2)*nsps samples, first and last symbols extended - dphi_peak=twopi*hmod/real(nsps) - dphi=0.0 - do j=1,nsym - ib=(j-1)*nsps - ie=ib+3*nsps-1 - dphi(ib:ie) = dphi(ib:ie) + dphi_peak*pulse(1:3*nsps)*itone(j) - enddo -! Add dummy symbols at beginning and end with tone values equal to 1st and last symbol, respectively - dphi(0:2*nsps-1)=dphi(0:2*nsps-1)+dphi_peak*itone(1)*pulse(nsps+1:3*nsps) - dphi(nsym*nsps:(nsym+2)*nsps-1)=dphi(nsym*nsps:(nsym+2)*nsps-1)+dphi_peak*itone(nsym)*pulse(1:2*nsps) - -! Calculate and insert the audio waveform - phi=0.0 - dphi = dphi + twopi*f0*dt !Shift frequency up by f0 - if(icmplx .eq. 0) wave=0. - if(icmplx .ne. 0) cwave=0. !Avoid writing to memory we may not have access to - - call timer('gen_loop',0) - k=0 - do j=nsps,nsps+nwave-1 !Don't include dummy symbols - k=k+1 - if(icmplx.eq.0) then - wave(k)=sin(phi) - else - i=phi*float(NTAB)/twopi - cwave(k)=ctab(i) - endif - phi=mod(phi+dphi(j),twopi) - enddo - call timer('gen_loop',1) - -! Apply envelope shaping to the first and last symbols - nramp=nint(nsps/8.0) - if(icmplx.eq.0) then - wave(1:nramp)=wave(1:nramp) * & - (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - k1=nsym*nsps-nramp+1 - wave(k1:k1+nramp-1)=wave(k1:k1+nramp-1) * & - (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - else - cwave(1:nramp)=cwave(1:nramp) * & - (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - k1=nsym*nsps-nramp+1 - cwave(k1:k1+nramp-1)=cwave(k1:k1+nramp-1) * & - (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - endif - - return -end subroutine gen_ft8wave +subroutine gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) +! +! generate ft8 waveform using Gaussian-filtered frequency pulses. +! + use timer_module, only: timer + parameter(MAX_SECONDS=20,NTAB=65536) + real wave(nwave) + complex cwave(nwave),ctab(0:NTAB-1) + real pulse(23040) + real dphi(0:(nsym+2)*nsps-1) + integer itone(nsym) + data fchk0/0.0/ + save pulse,twopi,dt,hmod,fchk0,ctab + + ibt=nint(10*bt) + fchk=nsym+nsps+bt+fsample + if(fchk.ne.fchk0) then + twopi=8.0*atan(1.0) + dt=1.0/fsample + hmod=1.0 +! Compute the frequency-smoothing pulse + do i=1,3*nsps + tt=(i-1.5*nsps)/real(nsps) + pulse(i)=gfsk_pulse(bt,tt) + enddo + do i=0,NTAB-1 + phi=i*twopi/NTAB + ctab(i)=cmplx(cos(phi),sin(phi)) + enddo + fchk0=fchk + endif + +! Compute the smoothed frequency waveform. +! Length = (nsym+2)*nsps samples, first and last symbols extended + dphi_peak=twopi*hmod/real(nsps) + dphi=0.0 + do j=1,nsym + ib=(j-1)*nsps + ie=ib+3*nsps-1 + dphi(ib:ie) = dphi(ib:ie) + dphi_peak*pulse(1:3*nsps)*itone(j) + enddo +! Add dummy symbols at beginning and end with tone values equal to 1st and last symbol, respectively + dphi(0:2*nsps-1)=dphi(0:2*nsps-1)+dphi_peak*itone(1)*pulse(nsps+1:3*nsps) + dphi(nsym*nsps:(nsym+2)*nsps-1)=dphi(nsym*nsps:(nsym+2)*nsps-1)+dphi_peak*itone(nsym)*pulse(1:2*nsps) + +! Calculate and insert the audio waveform + phi=0.0 + dphi = dphi + twopi*f0*dt !Shift frequency up by f0 + if(icmplx .eq. 0) wave=0. + if(icmplx .ne. 0) cwave=0. !Avoid writing to memory we may not have access to + + call timer('gen_loop',0) + k=0 + do j=nsps,nsps+nwave-1 !Don't include dummy symbols + k=k+1 + if(icmplx.eq.0) then + wave(k)=sin(phi) + else + i=phi*float(NTAB)/twopi + cwave(k)=ctab(i) + endif + phi=mod(phi+dphi(j),twopi) + enddo + call timer('gen_loop',1) + +! Apply envelope shaping to the first and last symbols + nramp=nint(nsps/8.0) + if(icmplx.eq.0) then + wave(1:nramp)=wave(1:nramp) * & + (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + k1=nsym*nsps-nramp+1 + wave(k1:k1+nramp-1)=wave(k1:k1+nramp-1) * & + (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + else + cwave(1:nramp)=cwave(1:nramp) * & + (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + k1=nsym*nsps-nramp+1 + cwave(k1:k1+nramp-1)=cwave(k1:k1+nramp-1) * & + (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + endif + + return +end subroutine gen_ft8wave diff --git a/lib/ft8/genft8.f90 b/lib/ft8/genft8.f90 index 9a926d50..a03c3e58 100755 --- a/lib/ft8/genft8.f90 +++ b/lib/ft8/genft8.f90 @@ -1,46 +1,46 @@ -subroutine genft8(msg,i3,n3,msgsent,msgbits,itone) - -! Encode an FT8 message, producing array itone(). - - use packjt77 - include 'ft8_params.f90' - character msg*37,msgsent*37 - character*77 c77 - integer*1 msgbits(77),codeword(174) - integer itone(79) - integer icos7(0:6) - integer graymap(0:7) - logical unpk77_success - data icos7/3,1,4,0,6,5,2/ !Costas 7x7 tone pattern - data graymap/0,1,3,2,5,6,4,7/ - - i3=-1 - n3=-1 - call pack77(msg,i3,n3,c77) - call unpack77(c77,0,msgsent,unpk77_success) - read(c77,'(77i1)',err=1) msgbits - if(unpk77_success) go to 2 -1 msgbits=0 - itone=0 - msgsent='*** bad message *** ' - go to 900 - -entry get_ft8_tones_from_77bits(msgbits,itone) - -2 call encode174_91(msgbits,codeword) !Encode the test message - -! Message structure: S7 D29 S7 D29 S7 - itone(1:7)=icos7 - itone(36+1:36+7)=icos7 - itone(NN-6:NN)=icos7 - k=7 - do j=1,ND - i=3*j -2 - k=k+1 - if(j.eq.30) k=k+7 - indx=codeword(i)*4 + codeword(i+1)*2 + codeword(i+2) - itone(k)=graymap(indx) - enddo - -900 return -end subroutine genft8 +subroutine genft8(msg,i3,n3,msgsent,msgbits,itone) + +! Encode an FT8 message, producing array itone(). + + use packjt77 + include 'ft8_params.f90' + character msg*37,msgsent*37 + character*77 c77 + integer*1 msgbits(77),codeword(174) + integer itone(79) + integer icos7(0:6) + integer graymap(0:7) + logical unpk77_success + data icos7/3,1,4,0,6,5,2/ !Costas 7x7 tone pattern + data graymap/0,1,3,2,5,6,4,7/ + + i3=-1 + n3=-1 + call pack77(msg,i3,n3,c77) + call unpack77(c77,0,msgsent,unpk77_success) + read(c77,'(77i1)',err=1) msgbits + if(unpk77_success) go to 2 +1 msgbits=0 + itone=0 + msgsent='*** bad message *** ' + go to 900 + +entry get_ft8_tones_from_77bits(msgbits,itone) + +2 call encode174_91(msgbits,codeword) !Encode the test message + +! Message structure: S7 D29 S7 D29 S7 + itone(1:7)=icos7 + itone(36+1:36+7)=icos7 + itone(NN-6:NN)=icos7 + k=7 + do j=1,ND + i=3*j -2 + k=k+1 + if(j.eq.30) k=k+7 + indx=codeword(i)*4 + codeword(i+1)*2 + codeword(i+2) + itone(k)=graymap(indx) + enddo + +900 return +end subroutine genft8 diff --git a/lib/ft8/genft8refsig.f90 b/lib/ft8/genft8refsig.f90 index 2951165c..cd1468c1 100755 --- a/lib/ft8/genft8refsig.f90 +++ b/lib/ft8/genft8refsig.f90 @@ -1,23 +1,23 @@ -subroutine genft8refsig(itone,cref,f0) - complex cref(79*1920) - integer itone(79) -! real*8 twopi,phi,dphi,dt,xnsps - real twopi,phi,dphi,dt,xnsps - data twopi/0.d0/ - save twopi - if( twopi .lt. 0.1 ) twopi=8.d0*atan(1.d0) - - xnsps=1920.d0 - dt=1.d0/12000.d0 - phi=0.d0 - k=1 - do i=1,79 - dphi=twopi*(f0*dt+itone(i)/xnsps) - do is=1,1920 - cref(k)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - k=k+1 - enddo - enddo - return -end subroutine genft8refsig +subroutine genft8refsig(itone,cref,f0) + complex cref(79*1920) + integer itone(79) +! real*8 twopi,phi,dphi,dt,xnsps + real twopi,phi,dphi,dt,xnsps + data twopi/0.d0/ + save twopi + if( twopi .lt. 0.1 ) twopi=8.d0*atan(1.d0) + + xnsps=1920.d0 + dt=1.d0/12000.d0 + phi=0.d0 + k=1 + do i=1,79 + dphi=twopi*(f0*dt+itone(i)/xnsps) + do is=1,1920 + cref(k)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + k=k+1 + enddo + enddo + return +end subroutine genft8refsig diff --git a/lib/ft8/get_crc14.f90 b/lib/ft8/get_crc14.f90 index 8124082f..63580897 100755 --- a/lib/ft8/get_crc14.f90 +++ b/lib/ft8/get_crc14.f90 @@ -1,25 +1,25 @@ -subroutine get_crc14(mc,len,ncrc) -! -! 1. To calculate 14-bit CRC, mc(1:len-14) is the message and mc(len-13:len) are zero. -! 2. To check a received CRC, mc(1:len is the received message plus CRC. -! ncrc will be zero if the received message/CRC are consistent -! - character c14*14 - integer*1 mc(len) - integer*1 r(15),p(15) - integer ncrc -! polynomial for 14-bit CRC 0x6757 - data p/1,1,0,0,1,1,1,0,1,0,1,0,1,1,1/ - -! divide by polynomial - r=mc(1:15) - do i=0,len-15 - r(15)=mc(i+15) - r=mod(r+r(1)*p,2) - r=cshift(r,1) - enddo - - write(c14,'(14b1)') r(1:14) - read(c14,'(b14.14)') ncrc - -end subroutine get_crc14 +subroutine get_crc14(mc,len,ncrc) +! +! 1. To calculate 14-bit CRC, mc(1:len-14) is the message and mc(len-13:len) are zero. +! 2. To check a received CRC, mc(1:len is the received message plus CRC. +! ncrc will be zero if the received message/CRC are consistent +! + character c14*14 + integer*1 mc(len) + integer*1 r(15),p(15) + integer ncrc +! polynomial for 14-bit CRC 0x6757 + data p/1,1,0,0,1,1,1,0,1,0,1,0,1,1,1/ + +! divide by polynomial + r=mc(1:15) + do i=0,len-15 + r(15)=mc(i+15) + r=mod(r+r(1)*p,2) + r=cshift(r,1) + enddo + + write(c14,'(14b1)') r(1:14) + read(c14,'(b14.14)') ncrc + +end subroutine get_crc14 diff --git a/lib/ft8/ldpc_174_87_params.f90 b/lib/ft8/ldpc_174_87_params.f90 index 4e20ad0a..35af9b81 100755 --- a/lib/ft8/ldpc_174_87_params.f90 +++ b/lib/ft8/ldpc_174_87_params.f90 @@ -1,102 +1,102 @@ -integer, parameter:: N=174, K=87, M=N-K -character*22 g(87) -integer colorder(N) -data g/ & !parity generator matrix for (174,87) code -"23bba830e23b6b6f50982e", & -"1f8e55da218c5df3309052", & -"ca7b3217cd92bd59a5ae20", & -"56f78313537d0f4382964e", & -"29c29dba9c545e267762fe", & -"6be396b5e2e819e373340c", & -"293548a138858328af4210", & -"cb6c6afcdc28bb3f7c6e86", & -"3f2a86f5c5bd225c961150", & -"849dd2d63673481860f62c", & -"56cdaec6e7ae14b43feeee", & -"04ef5cfa3766ba778f45a4", & -"c525ae4bd4f627320a3974", & -"fe37802941d66dde02b99c", & -"41fd9520b2e4abeb2f989c", & -"40907b01280f03c0323946", & -"7fb36c24085a34d8c1dbc4", & -"40fc3e44bb7d2bb2756e44", & -"d38ab0a1d2e52a8ec3bc76", & -"3d0f929ef3949bd84d4734", & -"45d3814f504064f80549ae", & -"f14dbf263825d0bd04b05e", & -"f08a91fb2e1f78290619a8", & -"7a8dec79a51e8ac5388022", & -"ca4186dd44c3121565cf5c", & -"db714f8f64e8ac7af1a76e", & -"8d0274de71e7c1a8055eb0", & -"51f81573dd4049b082de14", & -"d037db825175d851f3af00", & -"d8f937f31822e57c562370", & -"1bf1490607c54032660ede", & -"1616d78018d0b4745ca0f2", & -"a9fa8e50bcb032c85e3304", & -"83f640f1a48a8ebc0443ea", & -"eca9afa0f6b01d92305edc", & -"3776af54ccfbae916afde6", & -"6abb212d9739dfc02580f2", & -"05209a0abb530b9e7e34b0", & -"612f63acc025b6ab476f7c", & -"0af7723161ec223080be86", & -"a8fc906976c35669e79ce0", & -"45b7ab6242b77474d9f11a", & -"b274db8abd3c6f396ea356", & -"9059dfa2bb20ef7ef73ad4", & -"3d188ea477f6fa41317a4e", & -"8d9071b7e7a6a2eed6965e", & -"a377253773ea678367c3f6", & -"ecbd7c73b9cd34c3720c8a", & -"b6537f417e61d1a7085336", & -"6c280d2a0523d9c4bc5946", & -"d36d662a69ae24b74dcbd8", & -"d747bfc5fd65ef70fbd9bc", & -"a9fa2eefa6f8796a355772", & -"cc9da55fe046d0cb3a770c", & -"f6ad4824b87c80ebfce466", & -"cc6de59755420925f90ed2", & -"164cc861bdd803c547f2ac", & -"c0fc3ec4fb7d2bb2756644", & -"0dbd816fba1543f721dc72", & -"a0c0033a52ab6299802fd2", & -"bf4f56e073271f6ab4bf80", & -"57da6d13cb96a7689b2790", & -"81cfc6f18c35b1e1f17114", & -"481a2a0df8a23583f82d6c", & -"1ac4672b549cd6dba79bcc", & -"c87af9a5d5206abca532a8", & -"97d4169cb33e7435718d90", & -"a6573f3dc8b16c9d19f746", & -"2c4142bf42b01e71076acc", & -"081c29a10d468ccdbcecb6", & -"5b0f7742bca86b8012609a", & -"012dee2198eba82b19a1da", & -"f1627701a2d692fd9449e6", & -"35ad3fb0faeb5f1b0c30dc", & -"b1ca4ea2e3d173bad4379c", & -"37d8e0af9258b9e8c5f9b2", & -"cd921fdf59e882683763f6", & -"6114e08483043fd3f38a8a", & -"2e547dd7a05f6597aac516", & -"95e45ecd0135aca9d6e6ae", & -"b33ec97be83ce413f9acc8", & -"c8b5dffc335095dcdcaf2a", & -"3dd01a59d86310743ec752", & -"14cd0f642fc0c5fe3a65ca", & -"3a0a1dfd7eee29c2e827e0", & -"8abdb889efbe39a510a118", & -"3f231f212055371cf3e2a2"/ -data colorder/ & - 0, 1, 2, 3, 30, 4, 5, 6, 7, 8, 9, 10, 11, 32, 12, 40, 13, 14, 15, 16,& - 17, 18, 37, 45, 29, 19, 20, 21, 41, 22, 42, 31, 33, 34, 44, 35, 47, 51, 50, 43,& - 36, 52, 63, 46, 25, 55, 27, 24, 23, 53, 39, 49, 59, 38, 48, 61, 60, 57, 28, 62,& - 56, 58, 65, 66, 26, 70, 64, 69, 68, 67, 74, 71, 54, 76, 72, 75, 78, 77, 80, 79,& - 73, 83, 84, 81, 82, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,& - 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,& - 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,& - 140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,& - 160,161,162,163,164,165,166,167,168,169,170,171,172,173/ - +integer, parameter:: N=174, K=87, M=N-K +character*22 g(87) +integer colorder(N) +data g/ & !parity generator matrix for (174,87) code +"23bba830e23b6b6f50982e", & +"1f8e55da218c5df3309052", & +"ca7b3217cd92bd59a5ae20", & +"56f78313537d0f4382964e", & +"29c29dba9c545e267762fe", & +"6be396b5e2e819e373340c", & +"293548a138858328af4210", & +"cb6c6afcdc28bb3f7c6e86", & +"3f2a86f5c5bd225c961150", & +"849dd2d63673481860f62c", & +"56cdaec6e7ae14b43feeee", & +"04ef5cfa3766ba778f45a4", & +"c525ae4bd4f627320a3974", & +"fe37802941d66dde02b99c", & +"41fd9520b2e4abeb2f989c", & +"40907b01280f03c0323946", & +"7fb36c24085a34d8c1dbc4", & +"40fc3e44bb7d2bb2756e44", & +"d38ab0a1d2e52a8ec3bc76", & +"3d0f929ef3949bd84d4734", & +"45d3814f504064f80549ae", & +"f14dbf263825d0bd04b05e", & +"f08a91fb2e1f78290619a8", & +"7a8dec79a51e8ac5388022", & +"ca4186dd44c3121565cf5c", & +"db714f8f64e8ac7af1a76e", & +"8d0274de71e7c1a8055eb0", & +"51f81573dd4049b082de14", & +"d037db825175d851f3af00", & +"d8f937f31822e57c562370", & +"1bf1490607c54032660ede", & +"1616d78018d0b4745ca0f2", & +"a9fa8e50bcb032c85e3304", & +"83f640f1a48a8ebc0443ea", & +"eca9afa0f6b01d92305edc", & +"3776af54ccfbae916afde6", & +"6abb212d9739dfc02580f2", & +"05209a0abb530b9e7e34b0", & +"612f63acc025b6ab476f7c", & +"0af7723161ec223080be86", & +"a8fc906976c35669e79ce0", & +"45b7ab6242b77474d9f11a", & +"b274db8abd3c6f396ea356", & +"9059dfa2bb20ef7ef73ad4", & +"3d188ea477f6fa41317a4e", & +"8d9071b7e7a6a2eed6965e", & +"a377253773ea678367c3f6", & +"ecbd7c73b9cd34c3720c8a", & +"b6537f417e61d1a7085336", & +"6c280d2a0523d9c4bc5946", & +"d36d662a69ae24b74dcbd8", & +"d747bfc5fd65ef70fbd9bc", & +"a9fa2eefa6f8796a355772", & +"cc9da55fe046d0cb3a770c", & +"f6ad4824b87c80ebfce466", & +"cc6de59755420925f90ed2", & +"164cc861bdd803c547f2ac", & +"c0fc3ec4fb7d2bb2756644", & +"0dbd816fba1543f721dc72", & +"a0c0033a52ab6299802fd2", & +"bf4f56e073271f6ab4bf80", & +"57da6d13cb96a7689b2790", & +"81cfc6f18c35b1e1f17114", & +"481a2a0df8a23583f82d6c", & +"1ac4672b549cd6dba79bcc", & +"c87af9a5d5206abca532a8", & +"97d4169cb33e7435718d90", & +"a6573f3dc8b16c9d19f746", & +"2c4142bf42b01e71076acc", & +"081c29a10d468ccdbcecb6", & +"5b0f7742bca86b8012609a", & +"012dee2198eba82b19a1da", & +"f1627701a2d692fd9449e6", & +"35ad3fb0faeb5f1b0c30dc", & +"b1ca4ea2e3d173bad4379c", & +"37d8e0af9258b9e8c5f9b2", & +"cd921fdf59e882683763f6", & +"6114e08483043fd3f38a8a", & +"2e547dd7a05f6597aac516", & +"95e45ecd0135aca9d6e6ae", & +"b33ec97be83ce413f9acc8", & +"c8b5dffc335095dcdcaf2a", & +"3dd01a59d86310743ec752", & +"14cd0f642fc0c5fe3a65ca", & +"3a0a1dfd7eee29c2e827e0", & +"8abdb889efbe39a510a118", & +"3f231f212055371cf3e2a2"/ +data colorder/ & + 0, 1, 2, 3, 30, 4, 5, 6, 7, 8, 9, 10, 11, 32, 12, 40, 13, 14, 15, 16,& + 17, 18, 37, 45, 29, 19, 20, 21, 41, 22, 42, 31, 33, 34, 44, 35, 47, 51, 50, 43,& + 36, 52, 63, 46, 25, 55, 27, 24, 23, 53, 39, 49, 59, 38, 48, 61, 60, 57, 28, 62,& + 56, 58, 65, 66, 26, 70, 64, 69, 68, 67, 74, 71, 54, 76, 72, 75, 78, 77, 80, 79,& + 73, 83, 84, 81, 82, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,& + 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,& + 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,& + 140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,& + 160,161,162,163,164,165,166,167,168,169,170,171,172,173/ + diff --git a/lib/ft8/ldpc_174_91_c_colorder.f90 b/lib/ft8/ldpc_174_91_c_colorder.f90 index 91380187..a83de09d 100755 --- a/lib/ft8/ldpc_174_91_c_colorder.f90 +++ b/lib/ft8/ldpc_174_91_c_colorder.f90 @@ -1,11 +1,11 @@ -data colorder/ & - 0, 1, 2, 3, 28, 4, 5, 6, 7, 8, 9, 10, 11, 34, 12, 32, 13, 14, 15, 16, & - 17, 18, 36, 29, 43, 19, 20, 42, 21, 40, 30, 37, 22, 47, 61, 45, 44, 23, 41, 39, & - 49, 24, 46, 50, 48, 26, 31, 33, 51, 38, 52, 59, 55, 66, 57, 27, 60, 35, 54, 58, & - 25, 56, 62, 64, 67, 69, 63, 68, 70, 72, 65, 73, 75, 74, 71, 77, 78, 76, 79, 80, & - 53, 81, 83, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, & -100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119, & -120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139, & -140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, & -160,161,162,163,164,165,166,167,168,169,170,171,172,173/ - +data colorder/ & + 0, 1, 2, 3, 28, 4, 5, 6, 7, 8, 9, 10, 11, 34, 12, 32, 13, 14, 15, 16, & + 17, 18, 36, 29, 43, 19, 20, 42, 21, 40, 30, 37, 22, 47, 61, 45, 44, 23, 41, 39, & + 49, 24, 46, 50, 48, 26, 31, 33, 51, 38, 52, 59, 55, 66, 57, 27, 60, 35, 54, 58, & + 25, 56, 62, 64, 67, 69, 63, 68, 70, 72, 65, 73, 75, 74, 71, 77, 78, 76, 79, 80, & + 53, 81, 83, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, & +100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119, & +120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139, & +140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, & +160,161,162,163,164,165,166,167,168,169,170,171,172,173/ + diff --git a/lib/ft8/ldpc_174_91_c_generator.f90 b/lib/ft8/ldpc_174_91_c_generator.f90 index d513422f..675bae57 100755 --- a/lib/ft8/ldpc_174_91_c_generator.f90 +++ b/lib/ft8/ldpc_174_91_c_generator.f90 @@ -1,86 +1,86 @@ -character*23 g(83) - -data g/ & - "8329ce11bf31eaf509f27fc", & - "761c264e25c259335493132", & - "dc265902fb277c6410a1bdc", & - "1b3f417858cd2dd33ec7f62", & - "09fda4fee04195fd034783a", & - "077cccc11b8873ed5c3d48a", & - "29b62afe3ca036f4fe1a9da", & - "6054faf5f35d96d3b0c8c3e", & - "e20798e4310eed27884ae90", & - "775c9c08e80e26ddae56318", & - "b0b811028c2bf997213487c", & - "18a0c9231fc60adf5c5ea32", & - "76471e8302a0721e01b12b8", & - "ffbccb80ca8341fafb47b2e", & - "66a72a158f9325a2bf67170", & - "c4243689fe85b1c51363a18", & - "0dff739414d1a1b34b1c270", & - "15b48830636c8b99894972e", & - "29a89c0d3de81d665489b0e", & - "4f126f37fa51cbe61bd6b94", & - "99c47239d0d97d3c84e0940", & - "1919b75119765621bb4f1e8", & - "09db12d731faee0b86df6b8", & - "488fc33df43fbdeea4eafb4", & - "827423ee40b675f756eb5fe", & - "abe197c484cb74757144a9a", & - "2b500e4bc0ec5a6d2bdbdd0", & - "c474aa53d70218761669360", & - "8eba1a13db3390bd6718cec", & - "753844673a27782cc42012e", & - "06ff83a145c37035a5c1268", & - "3b37417858cc2dd33ec3f62", & - "9a4a5a28ee17ca9c324842c", & - "bc29f465309c977e89610a4", & - "2663ae6ddf8b5ce2bb29488", & - "46f231efe457034c1814418", & - "3fb2ce85abe9b0c72e06fbe", & - "de87481f282c153971a0a2e", & - "fcd7ccf23c69fa99bba1412", & - "f0261447e9490ca8e474cec", & - "4410115818196f95cdd7012", & - "088fc31df4bfbde2a4eafb4", & - "b8fef1b6307729fb0a078c0", & - "5afea7acccb77bbc9d99a90", & - "49a7016ac653f65ecdc9076", & - "1944d085be4e7da8d6cc7d0", & - "251f62adc4032f0ee714002", & - "56471f8702a0721e00b12b8", & - "2b8e4923f2dd51e2d537fa0", & - "6b550a40a66f4755de95c26", & - "a18ad28d4e27fe92a4f6c84", & - "10c2e586388cb82a3d80758", & - "ef34a41817ee02133db2eb0", & - "7e9c0c54325a9c15836e000", & - "3693e572d1fde4cdf079e86", & - "bfb2cec5abe1b0c72e07fbe", & - "7ee18230c583cccc57d4b08", & - "a066cb2fedafc9f52664126", & - "bb23725abc47cc5f4cc4cd2", & - "ded9dba3bee40c59b5609b4", & - "d9a7016ac653e6decdc9036", & - "9ad46aed5f707f280ab5fc4", & - "e5921c77822587316d7d3c2", & - "4f14da8242a8b86dca73352", & - "8b8b507ad467d4441df770e", & - "22831c9cf1169467ad04b68", & - "213b838fe2ae54c38ee7180", & - "5d926b6dd71f085181a4e12", & - "66ab79d4b29ee6e69509e56", & - "958148682d748a38dd68baa", & - "b8ce020cf069c32a723ab14", & - "f4331d6d461607e95752746", & - "6da23ba424b9596133cf9c8", & - "a636bcbc7b30c5fbeae67fe", & - "5cb0d86a07df654a9089a20", & - "f11f106848780fc9ecdd80a", & - "1fbb5364fb8d2c9d730d5ba", & - "fcb86bc70a50c9d02a5d034", & - "a534433029eac15f322e34c", & - "c989d9c7c3d3b8c55d75130", & - "7bb38b2f0186d46643ae962", & - "2644ebadeb44b9467d1f42c", & - "608cc857594bfbb55d69600"/ +character*23 g(83) + +data g/ & + "8329ce11bf31eaf509f27fc", & + "761c264e25c259335493132", & + "dc265902fb277c6410a1bdc", & + "1b3f417858cd2dd33ec7f62", & + "09fda4fee04195fd034783a", & + "077cccc11b8873ed5c3d48a", & + "29b62afe3ca036f4fe1a9da", & + "6054faf5f35d96d3b0c8c3e", & + "e20798e4310eed27884ae90", & + "775c9c08e80e26ddae56318", & + "b0b811028c2bf997213487c", & + "18a0c9231fc60adf5c5ea32", & + "76471e8302a0721e01b12b8", & + "ffbccb80ca8341fafb47b2e", & + "66a72a158f9325a2bf67170", & + "c4243689fe85b1c51363a18", & + "0dff739414d1a1b34b1c270", & + "15b48830636c8b99894972e", & + "29a89c0d3de81d665489b0e", & + "4f126f37fa51cbe61bd6b94", & + "99c47239d0d97d3c84e0940", & + "1919b75119765621bb4f1e8", & + "09db12d731faee0b86df6b8", & + "488fc33df43fbdeea4eafb4", & + "827423ee40b675f756eb5fe", & + "abe197c484cb74757144a9a", & + "2b500e4bc0ec5a6d2bdbdd0", & + "c474aa53d70218761669360", & + "8eba1a13db3390bd6718cec", & + "753844673a27782cc42012e", & + "06ff83a145c37035a5c1268", & + "3b37417858cc2dd33ec3f62", & + "9a4a5a28ee17ca9c324842c", & + "bc29f465309c977e89610a4", & + "2663ae6ddf8b5ce2bb29488", & + "46f231efe457034c1814418", & + "3fb2ce85abe9b0c72e06fbe", & + "de87481f282c153971a0a2e", & + "fcd7ccf23c69fa99bba1412", & + "f0261447e9490ca8e474cec", & + "4410115818196f95cdd7012", & + "088fc31df4bfbde2a4eafb4", & + "b8fef1b6307729fb0a078c0", & + "5afea7acccb77bbc9d99a90", & + "49a7016ac653f65ecdc9076", & + "1944d085be4e7da8d6cc7d0", & + "251f62adc4032f0ee714002", & + "56471f8702a0721e00b12b8", & + "2b8e4923f2dd51e2d537fa0", & + "6b550a40a66f4755de95c26", & + "a18ad28d4e27fe92a4f6c84", & + "10c2e586388cb82a3d80758", & + "ef34a41817ee02133db2eb0", & + "7e9c0c54325a9c15836e000", & + "3693e572d1fde4cdf079e86", & + "bfb2cec5abe1b0c72e07fbe", & + "7ee18230c583cccc57d4b08", & + "a066cb2fedafc9f52664126", & + "bb23725abc47cc5f4cc4cd2", & + "ded9dba3bee40c59b5609b4", & + "d9a7016ac653e6decdc9036", & + "9ad46aed5f707f280ab5fc4", & + "e5921c77822587316d7d3c2", & + "4f14da8242a8b86dca73352", & + "8b8b507ad467d4441df770e", & + "22831c9cf1169467ad04b68", & + "213b838fe2ae54c38ee7180", & + "5d926b6dd71f085181a4e12", & + "66ab79d4b29ee6e69509e56", & + "958148682d748a38dd68baa", & + "b8ce020cf069c32a723ab14", & + "f4331d6d461607e95752746", & + "6da23ba424b9596133cf9c8", & + "a636bcbc7b30c5fbeae67fe", & + "5cb0d86a07df654a9089a20", & + "f11f106848780fc9ecdd80a", & + "1fbb5364fb8d2c9d730d5ba", & + "fcb86bc70a50c9d02a5d034", & + "a534433029eac15f322e34c", & + "c989d9c7c3d3b8c55d75130", & + "7bb38b2f0186d46643ae962", & + "2644ebadeb44b9467d1f42c", & + "608cc857594bfbb55d69600"/ diff --git a/lib/ft8/ldpc_174_91_c_parity.f90 b/lib/ft8/ldpc_174_91_c_parity.f90 index 135c9de9..2309ad8e 100755 --- a/lib/ft8/ldpc_174_91_c_parity.f90 +++ b/lib/ft8/ldpc_174_91_c_parity.f90 @@ -1,270 +1,270 @@ -data Mn/ & - 16, 45, 73, & - 25, 51, 62, & - 33, 58, 78, & - 1, 44, 45, & - 2, 7, 61, & - 3, 6, 54, & - 4, 35, 48, & - 5, 13, 21, & - 8, 56, 79, & - 9, 64, 69, & - 10, 19, 66, & - 11, 36, 60, & - 12, 37, 58, & - 14, 32, 43, & - 15, 63, 80, & - 17, 28, 77, & - 18, 74, 83, & - 22, 53, 81, & - 23, 30, 34, & - 24, 31, 40, & - 26, 41, 76, & - 27, 57, 70, & - 29, 49, 65, & - 3, 38, 78, & - 5, 39, 82, & - 46, 50, 73, & - 51, 52, 74, & - 55, 71, 72, & - 44, 67, 72, & - 43, 68, 78, & - 1, 32, 59, & - 2, 6, 71, & - 4, 16, 54, & - 7, 65, 67, & - 8, 30, 42, & - 9, 22, 31, & - 10, 18, 76, & - 11, 23, 82, & - 12, 28, 61, & - 13, 52, 79, & - 14, 50, 51, & - 15, 81, 83, & - 17, 29, 60, & - 19, 33, 64, & - 20, 26, 73, & - 21, 34, 40, & - 24, 27, 77, & - 25, 55, 58, & - 35, 53, 66, & - 36, 48, 68, & - 37, 46, 75, & - 38, 45, 47, & - 39, 57, 69, & - 41, 56, 62, & - 20, 49, 53, & - 46, 52, 63, & - 45, 70, 75, & - 27, 35, 80, & - 1, 15, 30, & - 2, 68, 80, & - 3, 36, 51, & - 4, 28, 51, & - 5, 31, 56, & - 6, 20, 37, & - 7, 40, 82, & - 8, 60, 69, & - 9, 10, 49, & - 11, 44, 57, & - 12, 39, 59, & - 13, 24, 55, & - 14, 21, 65, & - 16, 71, 78, & - 17, 30, 76, & - 18, 25, 80, & - 19, 61, 83, & - 22, 38, 77, & - 23, 41, 50, & - 7, 26, 58, & - 29, 32, 81, & - 33, 40, 73, & - 18, 34, 48, & - 13, 42, 64, & - 5, 26, 43, & - 47, 69, 72, & - 54, 55, 70, & - 45, 62, 68, & - 10, 63, 67, & - 14, 66, 72, & - 22, 60, 74, & - 35, 39, 79, & - 1, 46, 64, & - 1, 24, 66, & - 2, 5, 70, & - 3, 31, 65, & - 4, 49, 58, & - 1, 4, 5, & - 6, 60, 67, & - 7, 32, 75, & - 8, 48, 82, & - 9, 35, 41, & - 10, 39, 62, & - 11, 14, 61, & - 12, 71, 74, & - 13, 23, 78, & - 11, 35, 55, & - 15, 16, 79, & - 7, 9, 16, & - 17, 54, 63, & - 18, 50, 57, & - 19, 30, 47, & - 20, 64, 80, & - 21, 28, 69, & - 22, 25, 43, & - 13, 22, 37, & - 2, 47, 51, & - 23, 54, 74, & - 26, 34, 72, & - 27, 36, 37, & - 21, 36, 63, & - 29, 40, 44, & - 19, 26, 57, & - 3, 46, 82, & - 14, 15, 58, & - 33, 52, 53, & - 30, 43, 52, & - 6, 9, 52, & - 27, 33, 65, & - 25, 69, 73, & - 38, 55, 83, & - 20, 39, 77, & - 18, 29, 56, & - 32, 48, 71, & - 42, 51, 59, & - 28, 44, 79, & - 34, 60, 62, & - 31, 45, 61, & - 46, 68, 77, & - 6, 24, 76, & - 8, 10, 78, & - 40, 41, 70, & - 17, 50, 53, & - 42, 66, 68, & - 4, 22, 72, & - 36, 64, 81, & - 13, 29, 47, & - 2, 8, 81, & - 56, 67, 73, & - 5, 38, 50, & - 12, 38, 64, & - 59, 72, 80, & - 3, 26, 79, & - 45, 76, 81, & - 1, 65, 74, & - 7, 18, 77, & - 11, 56, 59, & - 14, 39, 54, & - 16, 37, 66, & - 10, 28, 55, & - 15, 60, 70, & - 17, 25, 82, & - 20, 30, 31, & - 12, 67, 68, & - 23, 75, 80, & - 27, 32, 62, & - 24, 69, 75, & - 19, 21, 71, & - 34, 53, 61, & - 35, 46, 47, & - 33, 59, 76, & - 40, 43, 83, & - 41, 42, 63, & - 49, 75, 83, & - 20, 44, 48, & - 42, 49, 57/ - -data Nm/ & - 4, 31, 59, 91, 92, 96, 153, & - 5, 32, 60, 93, 115, 146, 0, & - 6, 24, 61, 94, 122, 151, 0, & - 7, 33, 62, 95, 96, 143, 0, & - 8, 25, 63, 83, 93, 96, 148, & - 6, 32, 64, 97, 126, 138, 0, & - 5, 34, 65, 78, 98, 107, 154, & - 9, 35, 66, 99, 139, 146, 0, & - 10, 36, 67, 100, 107, 126, 0, & - 11, 37, 67, 87, 101, 139, 158, & - 12, 38, 68, 102, 105, 155, 0, & - 13, 39, 69, 103, 149, 162, 0, & - 8, 40, 70, 82, 104, 114, 145, & - 14, 41, 71, 88, 102, 123, 156, & - 15, 42, 59, 106, 123, 159, 0, & - 1, 33, 72, 106, 107, 157, 0, & - 16, 43, 73, 108, 141, 160, 0, & - 17, 37, 74, 81, 109, 131, 154, & - 11, 44, 75, 110, 121, 166, 0, & - 45, 55, 64, 111, 130, 161, 173, & - 8, 46, 71, 112, 119, 166, 0, & - 18, 36, 76, 89, 113, 114, 143, & - 19, 38, 77, 104, 116, 163, 0, & - 20, 47, 70, 92, 138, 165, 0, & - 2, 48, 74, 113, 128, 160, 0, & - 21, 45, 78, 83, 117, 121, 151, & - 22, 47, 58, 118, 127, 164, 0, & - 16, 39, 62, 112, 134, 158, 0, & - 23, 43, 79, 120, 131, 145, 0, & - 19, 35, 59, 73, 110, 125, 161, & - 20, 36, 63, 94, 136, 161, 0, & - 14, 31, 79, 98, 132, 164, 0, & - 3, 44, 80, 124, 127, 169, 0, & - 19, 46, 81, 117, 135, 167, 0, & - 7, 49, 58, 90, 100, 105, 168, & - 12, 50, 61, 118, 119, 144, 0, & - 13, 51, 64, 114, 118, 157, 0, & - 24, 52, 76, 129, 148, 149, 0, & - 25, 53, 69, 90, 101, 130, 156, & - 20, 46, 65, 80, 120, 140, 170, & - 21, 54, 77, 100, 140, 171, 0, & - 35, 82, 133, 142, 171, 174, 0, & - 14, 30, 83, 113, 125, 170, 0, & - 4, 29, 68, 120, 134, 173, 0, & - 1, 4, 52, 57, 86, 136, 152, & - 26, 51, 56, 91, 122, 137, 168, & - 52, 84, 110, 115, 145, 168, 0, & - 7, 50, 81, 99, 132, 173, 0, & - 23, 55, 67, 95, 172, 174, 0, & - 26, 41, 77, 109, 141, 148, 0, & - 2, 27, 41, 61, 62, 115, 133, & - 27, 40, 56, 124, 125, 126, 0, & - 18, 49, 55, 124, 141, 167, 0, & - 6, 33, 85, 108, 116, 156, 0, & - 28, 48, 70, 85, 105, 129, 158, & - 9, 54, 63, 131, 147, 155, 0, & - 22, 53, 68, 109, 121, 174, 0, & - 3, 13, 48, 78, 95, 123, 0, & - 31, 69, 133, 150, 155, 169, 0, & - 12, 43, 66, 89, 97, 135, 159, & - 5, 39, 75, 102, 136, 167, 0, & - 2, 54, 86, 101, 135, 164, 0, & - 15, 56, 87, 108, 119, 171, 0, & - 10, 44, 82, 91, 111, 144, 149, & - 23, 34, 71, 94, 127, 153, 0, & - 11, 49, 88, 92, 142, 157, 0, & - 29, 34, 87, 97, 147, 162, 0, & - 30, 50, 60, 86, 137, 142, 162, & - 10, 53, 66, 84, 112, 128, 165, & - 22, 57, 85, 93, 140, 159, 0, & - 28, 32, 72, 103, 132, 166, 0, & - 28, 29, 84, 88, 117, 143, 150, & - 1, 26, 45, 80, 128, 147, 0, & - 17, 27, 89, 103, 116, 153, 0, & - 51, 57, 98, 163, 165, 172, 0, & - 21, 37, 73, 138, 152, 169, 0, & - 16, 47, 76, 130, 137, 154, 0, & - 3, 24, 30, 72, 104, 139, 0, & - 9, 40, 90, 106, 134, 151, 0, & - 15, 58, 60, 74, 111, 150, 163, & - 18, 42, 79, 144, 146, 152, 0, & - 25, 38, 65, 99, 122, 160, 0, & - 17, 42, 75, 129, 170, 172, 0/ - -data nrw/ & -7,6,6,6,7,6,7,6,6,7,6,6,7,7,6,6, & -6,7,6,7,6,7,6,6,6,7,6,6,6,7,6,6, & -6,6,7,6,6,6,7,7,6,6,6,6,7,7,6,6, & -6,6,7,6,6,6,7,6,6,6,6,7,6,6,6,7, & -6,6,6,7,7,6,6,7,6,6,6,6,6,6,6,7, & -6,6,6/ - -ncw=3 +data Mn/ & + 16, 45, 73, & + 25, 51, 62, & + 33, 58, 78, & + 1, 44, 45, & + 2, 7, 61, & + 3, 6, 54, & + 4, 35, 48, & + 5, 13, 21, & + 8, 56, 79, & + 9, 64, 69, & + 10, 19, 66, & + 11, 36, 60, & + 12, 37, 58, & + 14, 32, 43, & + 15, 63, 80, & + 17, 28, 77, & + 18, 74, 83, & + 22, 53, 81, & + 23, 30, 34, & + 24, 31, 40, & + 26, 41, 76, & + 27, 57, 70, & + 29, 49, 65, & + 3, 38, 78, & + 5, 39, 82, & + 46, 50, 73, & + 51, 52, 74, & + 55, 71, 72, & + 44, 67, 72, & + 43, 68, 78, & + 1, 32, 59, & + 2, 6, 71, & + 4, 16, 54, & + 7, 65, 67, & + 8, 30, 42, & + 9, 22, 31, & + 10, 18, 76, & + 11, 23, 82, & + 12, 28, 61, & + 13, 52, 79, & + 14, 50, 51, & + 15, 81, 83, & + 17, 29, 60, & + 19, 33, 64, & + 20, 26, 73, & + 21, 34, 40, & + 24, 27, 77, & + 25, 55, 58, & + 35, 53, 66, & + 36, 48, 68, & + 37, 46, 75, & + 38, 45, 47, & + 39, 57, 69, & + 41, 56, 62, & + 20, 49, 53, & + 46, 52, 63, & + 45, 70, 75, & + 27, 35, 80, & + 1, 15, 30, & + 2, 68, 80, & + 3, 36, 51, & + 4, 28, 51, & + 5, 31, 56, & + 6, 20, 37, & + 7, 40, 82, & + 8, 60, 69, & + 9, 10, 49, & + 11, 44, 57, & + 12, 39, 59, & + 13, 24, 55, & + 14, 21, 65, & + 16, 71, 78, & + 17, 30, 76, & + 18, 25, 80, & + 19, 61, 83, & + 22, 38, 77, & + 23, 41, 50, & + 7, 26, 58, & + 29, 32, 81, & + 33, 40, 73, & + 18, 34, 48, & + 13, 42, 64, & + 5, 26, 43, & + 47, 69, 72, & + 54, 55, 70, & + 45, 62, 68, & + 10, 63, 67, & + 14, 66, 72, & + 22, 60, 74, & + 35, 39, 79, & + 1, 46, 64, & + 1, 24, 66, & + 2, 5, 70, & + 3, 31, 65, & + 4, 49, 58, & + 1, 4, 5, & + 6, 60, 67, & + 7, 32, 75, & + 8, 48, 82, & + 9, 35, 41, & + 10, 39, 62, & + 11, 14, 61, & + 12, 71, 74, & + 13, 23, 78, & + 11, 35, 55, & + 15, 16, 79, & + 7, 9, 16, & + 17, 54, 63, & + 18, 50, 57, & + 19, 30, 47, & + 20, 64, 80, & + 21, 28, 69, & + 22, 25, 43, & + 13, 22, 37, & + 2, 47, 51, & + 23, 54, 74, & + 26, 34, 72, & + 27, 36, 37, & + 21, 36, 63, & + 29, 40, 44, & + 19, 26, 57, & + 3, 46, 82, & + 14, 15, 58, & + 33, 52, 53, & + 30, 43, 52, & + 6, 9, 52, & + 27, 33, 65, & + 25, 69, 73, & + 38, 55, 83, & + 20, 39, 77, & + 18, 29, 56, & + 32, 48, 71, & + 42, 51, 59, & + 28, 44, 79, & + 34, 60, 62, & + 31, 45, 61, & + 46, 68, 77, & + 6, 24, 76, & + 8, 10, 78, & + 40, 41, 70, & + 17, 50, 53, & + 42, 66, 68, & + 4, 22, 72, & + 36, 64, 81, & + 13, 29, 47, & + 2, 8, 81, & + 56, 67, 73, & + 5, 38, 50, & + 12, 38, 64, & + 59, 72, 80, & + 3, 26, 79, & + 45, 76, 81, & + 1, 65, 74, & + 7, 18, 77, & + 11, 56, 59, & + 14, 39, 54, & + 16, 37, 66, & + 10, 28, 55, & + 15, 60, 70, & + 17, 25, 82, & + 20, 30, 31, & + 12, 67, 68, & + 23, 75, 80, & + 27, 32, 62, & + 24, 69, 75, & + 19, 21, 71, & + 34, 53, 61, & + 35, 46, 47, & + 33, 59, 76, & + 40, 43, 83, & + 41, 42, 63, & + 49, 75, 83, & + 20, 44, 48, & + 42, 49, 57/ + +data Nm/ & + 4, 31, 59, 91, 92, 96, 153, & + 5, 32, 60, 93, 115, 146, 0, & + 6, 24, 61, 94, 122, 151, 0, & + 7, 33, 62, 95, 96, 143, 0, & + 8, 25, 63, 83, 93, 96, 148, & + 6, 32, 64, 97, 126, 138, 0, & + 5, 34, 65, 78, 98, 107, 154, & + 9, 35, 66, 99, 139, 146, 0, & + 10, 36, 67, 100, 107, 126, 0, & + 11, 37, 67, 87, 101, 139, 158, & + 12, 38, 68, 102, 105, 155, 0, & + 13, 39, 69, 103, 149, 162, 0, & + 8, 40, 70, 82, 104, 114, 145, & + 14, 41, 71, 88, 102, 123, 156, & + 15, 42, 59, 106, 123, 159, 0, & + 1, 33, 72, 106, 107, 157, 0, & + 16, 43, 73, 108, 141, 160, 0, & + 17, 37, 74, 81, 109, 131, 154, & + 11, 44, 75, 110, 121, 166, 0, & + 45, 55, 64, 111, 130, 161, 173, & + 8, 46, 71, 112, 119, 166, 0, & + 18, 36, 76, 89, 113, 114, 143, & + 19, 38, 77, 104, 116, 163, 0, & + 20, 47, 70, 92, 138, 165, 0, & + 2, 48, 74, 113, 128, 160, 0, & + 21, 45, 78, 83, 117, 121, 151, & + 22, 47, 58, 118, 127, 164, 0, & + 16, 39, 62, 112, 134, 158, 0, & + 23, 43, 79, 120, 131, 145, 0, & + 19, 35, 59, 73, 110, 125, 161, & + 20, 36, 63, 94, 136, 161, 0, & + 14, 31, 79, 98, 132, 164, 0, & + 3, 44, 80, 124, 127, 169, 0, & + 19, 46, 81, 117, 135, 167, 0, & + 7, 49, 58, 90, 100, 105, 168, & + 12, 50, 61, 118, 119, 144, 0, & + 13, 51, 64, 114, 118, 157, 0, & + 24, 52, 76, 129, 148, 149, 0, & + 25, 53, 69, 90, 101, 130, 156, & + 20, 46, 65, 80, 120, 140, 170, & + 21, 54, 77, 100, 140, 171, 0, & + 35, 82, 133, 142, 171, 174, 0, & + 14, 30, 83, 113, 125, 170, 0, & + 4, 29, 68, 120, 134, 173, 0, & + 1, 4, 52, 57, 86, 136, 152, & + 26, 51, 56, 91, 122, 137, 168, & + 52, 84, 110, 115, 145, 168, 0, & + 7, 50, 81, 99, 132, 173, 0, & + 23, 55, 67, 95, 172, 174, 0, & + 26, 41, 77, 109, 141, 148, 0, & + 2, 27, 41, 61, 62, 115, 133, & + 27, 40, 56, 124, 125, 126, 0, & + 18, 49, 55, 124, 141, 167, 0, & + 6, 33, 85, 108, 116, 156, 0, & + 28, 48, 70, 85, 105, 129, 158, & + 9, 54, 63, 131, 147, 155, 0, & + 22, 53, 68, 109, 121, 174, 0, & + 3, 13, 48, 78, 95, 123, 0, & + 31, 69, 133, 150, 155, 169, 0, & + 12, 43, 66, 89, 97, 135, 159, & + 5, 39, 75, 102, 136, 167, 0, & + 2, 54, 86, 101, 135, 164, 0, & + 15, 56, 87, 108, 119, 171, 0, & + 10, 44, 82, 91, 111, 144, 149, & + 23, 34, 71, 94, 127, 153, 0, & + 11, 49, 88, 92, 142, 157, 0, & + 29, 34, 87, 97, 147, 162, 0, & + 30, 50, 60, 86, 137, 142, 162, & + 10, 53, 66, 84, 112, 128, 165, & + 22, 57, 85, 93, 140, 159, 0, & + 28, 32, 72, 103, 132, 166, 0, & + 28, 29, 84, 88, 117, 143, 150, & + 1, 26, 45, 80, 128, 147, 0, & + 17, 27, 89, 103, 116, 153, 0, & + 51, 57, 98, 163, 165, 172, 0, & + 21, 37, 73, 138, 152, 169, 0, & + 16, 47, 76, 130, 137, 154, 0, & + 3, 24, 30, 72, 104, 139, 0, & + 9, 40, 90, 106, 134, 151, 0, & + 15, 58, 60, 74, 111, 150, 163, & + 18, 42, 79, 144, 146, 152, 0, & + 25, 38, 65, 99, 122, 160, 0, & + 17, 42, 75, 129, 170, 172, 0/ + +data nrw/ & +7,6,6,6,7,6,7,6,6,7,6,6,7,7,6,6, & +6,7,6,7,6,7,6,6,6,7,6,6,6,7,6,6, & +6,6,7,6,6,6,7,7,6,6,6,6,7,7,6,6, & +6,6,7,6,6,6,7,6,6,6,6,7,6,6,6,7, & +6,6,6,7,7,6,6,7,6,6,6,6,6,6,6,7, & +6,6,6/ + +ncw=3 diff --git a/lib/ft8/ldpcsim174_91.f90 b/lib/ft8/ldpcsim174_91.f90 index ae16fa43..4e30859a 100755 --- a/lib/ft8/ldpcsim174_91.f90 +++ b/lib/ft8/ldpcsim174_91.f90 @@ -1,269 +1,269 @@ -program ldpcsim174_91 -! End to end test of the (174,91)/crc14 encoder and decoder. - use packjt77 - - integer, parameter:: N=174, K=91, M=N-K, NN=58 - character*37 msg,msgsent - character*77 c77 - character*8 arg - integer*1, allocatable :: codeword(:), decoded(:), message(:) - integer*1 msgbits(77) - integer*1 message91(91) - integer*1 apmask(N), cw(N) - integer lmax(1) - integer modtype, itone(79), itonecw(58), graymap(0:7) - integer nerrtot(0:N),nerrdec(0:N) - integer channeltype - logical unpk77_success - logical one(0:511,0:8) - real*8, allocatable :: rxdata(:) - real llr(174),llra(174),llrb(174),llrc(174),llrd(174) - real bmeta(174),bmetb(174),bmetc(174),bmetd(174) - complex cs(0:7,NN) - real s2(0:511) - data graymap/0,1,3,2,5,6,4,7/ - - nerrtot=0 - nerrdec=0 - -! - - nargs=iargc() - if(nargs.ne.7) then - print*,'Usage: ldpcsim maxosd norder #trials s Keff modtype channel' - print*,'eg: ldpcsim 10 2 1000 0.84 91 1 0' - print*,' maxosd<0: do bp only' - print*,' maxosd=0: do bp and then call osd once with channel llrs' - print*,' maxosd>1: do bp and then call osd maxosd times with saved bp outputs' - print*,' norder : osd decoding depth' - print*,' s : BPSK only, noise sigma, if s<0 value is ignored and sigma is calculated from SNR.' - print*,' Keff : Keff must be in the range [77,91]; Keff-77 is the # of bits to use as CRC.' - print*,' modtype : 0, coherent BPSK; 1 noncoherent 8FSK' - print*,' channel : 0, AWGN; 1, block Rayleigh (Rayleigh only works with 8FSK!)' - return - endif - call getarg(1,arg) - read(arg,*) maxosd - call getarg(2,arg) - read(arg,*) norder - call getarg(3,arg) - read(arg,*) ntrials - call getarg(4,arg) - read(arg,*) s - call getarg(5,arg) - read(arg,*) Keff - call getarg(6,arg) - read(arg,*) modtype - call getarg(7,arg) - read(arg,*) channeltype - -! scale Eb/No for a (174,91) code - rate=real(K)/real(N) - - write(*,*) "rate: ",rate - - allocate ( codeword(N), decoded(K), message(K) ) - allocate ( rxdata(N) ) - - one=.false. - do i=0,511 - do j=0,8 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - - msg="K9ABC K1ABC FN20" - i3=0 - n3=1 - call pack77(msg,i3,n3,c77) !Pack into 12 6-bit bytes - call unpack77(c77,1,msgsent,unpk77_success) !Unpack to get msgsent - write(*,*) "message sent ",msgsent - - read(c77,'(77i1)') msgbits(1:77) - write(*,*) 'message' - write(*,'(a71,1x,a3,1x,a3)') c77(1:71),c77(72:74),c77(75:77) - - call init_random_seed() - - iq=1 - if(modtype.gt.0) then ! MFSK - get tones - i3=-1 - n3=-1 - call genft8(msg,i3,n3,msgsent,msgbits,itone) - write(*,*) 'message tones' - write(*,'(79(i1,1x))') itone - itonecw(1:29)=itone(8:36) - itonecw(30:58)=itone(44:72) - iq=3 ! bits per symbol - endif - call encode174_91(msgbits,codeword) - write(*,*) 'crc14' - write(*,'(14i1)') codeword(78:91) - write(*,*) 'codeword' - write(*,'(22(8i1,1x))') codeword - write(*,*) 'Eb/N0 Es/N0 SNR2500 ngood nundetected sigma psymerr pbiterr' - do idb = 20,-4,-1 - nsymerr=0 - nbiterr=0 - db=idb/2.0-1.0 - sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) - ngood=0 - nue=0 - nsumerr=0 - do itrial=1, ntrials -! Create a realization of a noisy received word - if(modtype.eq.0) then - do i=1,N - rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() - enddo - nerr=0 - do i=1,N - if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1 - enddo - if(nerr.ge.1) nerrtot(nerr)=nerrtot(nerr)+1 - - rxav=sum(rxdata)/N - rx2av=sum(rxdata*rxdata)/N - rxsig=sqrt(rx2av-rxav*rxav) - rxdata=rxdata/rxsig - if( s .lt. 0 ) then - ss=sigma - else - ss=s - endif - llr=2.0*rxdata/(ss*ss) - else -! noncoherent MFSK - do i=1,58 - do j=0,7 - if(j.eq.itonecw(i)) then - if(channeltype.eq.0) then - A=1.0 - elseif(channeltype.eq.1) then - xI=gran()**2 + gran()**2 - A=sqrt(xI/2) - endif - cs(j,i)= A + sigma*gran() + cmplx(0,1)*sigma*gran() - elseif(j.ne.itonecw(i)) then - cs(j,i)= sigma*gran() + cmplx(0,1)*sigma*gran() - endif - enddo - lmax=maxloc(abs(cs(:,i))) - if(lmax(1)-1.ne.itonecw(i) ) nsymerr=nsymerr+1 - enddo - do nsym=1,3 - nt=2**(3*nsym) - do ks=1,58,nsym - amax=-1.0 - do i=0,nt-1 - i1=i/64 - i2=iand(i,63)/8 - i3=iand(i,7) - if(nsym.eq.1) then - s2(i)=abs(cs(graymap(i3),ks)) - elseif(nsym.eq.2) then - s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) - elseif(nsym.eq.3) then - if(ks.ne.58) then - s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) - else - s2(i)=abs(cs(graymap(i1),ks)) - endif - else - print*,"Error - nsym must be 1, 2, or 3." - endif - enddo - - i32=1+(ks-1)*3 - if(nsym.eq.1) ibmax=2 - if(nsym.eq.2) ibmax=5 - if(nsym.eq.3) ibmax=8 - do ib=0,ibmax - bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) - if(i32+ib .gt.174) cycle - if(nsym.eq.1) then - bmeta(i32+ib)=bm - den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) - if(den.gt.0.0) then - cm=bm/den - else ! erase it - cm=0.0 - endif - bmetd(i32+ib)=cm - elseif(nsym.eq.2) then - bmetb(i32+ib)=bm - elseif(nsym.eq.3) then - bmetc(i32+ib)=bm - endif - enddo - enddo - enddo - call normalizebmet(bmeta,174) - call normalizebmet(bmetb,174) - call normalizebmet(bmetc,174) - call normalizebmet(bmetd,174) - - scalefac=2.83 - llra=scalefac*bmeta - llrb=scalefac*bmetb - llrc=scalefac*bmetc - llrd=scalefac*bmetd - - llr=llrc - endif - - do i=1, 174 - if(llr(i)*(codeword(i)-0.5).lt.0) nbiterr=nbiterr+1 - enddo - - nap=0 ! number of AP bits - llr(1:nap)=5*(2.0*msgbits(1:nap)-1.0) - apmask=0 - apmask(1:nap)=1 - call decode174_91(llr,Keff,maxosd,norder,apmask,message91,cw,ntype,nharderrors,dmin) -! If the decoder finds a valid codeword, nharderrors will be .ge. 0. - if( nharderrors.ge.0 ) then - nhw=count(cw.ne.codeword) - if(nhw.eq.0) then ! this is a good decode - ngood=ngood+1 - nerrdec(nerr)=nerrdec(nerr)+1 - else - nue=nue+1 - endif - endif - nsumerr=nsumerr+nerr - enddo - - esn0=db+10.0*log10(iq*rate) ! iq=3 bits per symbol for 8FSK - snr2500=esn0-10.0*log10(2500/6.25) -! pberr=real(nsumerr)/(real(ntrials*N)) - psymerr=real(nsymerr)/(ntrials*174.0/iq) - pbiterr=real(nbiterr)/(ntrials*174.0) - write(*,"(f4.1,4x,f5.1,4x,f5.1,1x,i8,1x,i8,8x,f5.2,8x,e10.3,8x,e10.3)") db,esn0,snr2500,ngood,nue,ss,psymerr,pbiterr - - enddo - - open(unit=23,file='nerrhisto.dat',status='unknown') - do i=1,174 - write(23,'(i4,2x,i10,i10,f10.2)') i,nerrdec(i),nerrtot(i),real(nerrdec(i))/real(nerrtot(i)+1e-10) - enddo - close(23) - -end program ldpcsim174_91 - -subroutine normalizebmet(bmet,n) - real bmet(n) - - bmetav=sum(bmet)/real(n) - bmet2av=sum(bmet*bmet)/real(n) - var=bmet2av-bmetav*bmetav - if( var .gt. 0.0 ) then - bmetsig=sqrt(var) - else - bmetsig=sqrt(bmet2av) - endif - bmet=bmet/bmetsig - return -end subroutine normalizebmet +program ldpcsim174_91 +! End to end test of the (174,91)/crc14 encoder and decoder. + use packjt77 + + integer, parameter:: N=174, K=91, M=N-K, NN=58 + character*37 msg,msgsent + character*77 c77 + character*8 arg + integer*1, allocatable :: codeword(:), decoded(:), message(:) + integer*1 msgbits(77) + integer*1 message91(91) + integer*1 apmask(N), cw(N) + integer lmax(1) + integer modtype, itone(79), itonecw(58), graymap(0:7) + integer nerrtot(0:N),nerrdec(0:N) + integer channeltype + logical unpk77_success + logical one(0:511,0:8) + real*8, allocatable :: rxdata(:) + real llr(174),llra(174),llrb(174),llrc(174),llrd(174) + real bmeta(174),bmetb(174),bmetc(174),bmetd(174) + complex cs(0:7,NN) + real s2(0:511) + data graymap/0,1,3,2,5,6,4,7/ + + nerrtot=0 + nerrdec=0 + +! + + nargs=iargc() + if(nargs.ne.7) then + print*,'Usage: ldpcsim maxosd norder #trials s Keff modtype channel' + print*,'eg: ldpcsim 10 2 1000 0.84 91 1 0' + print*,' maxosd<0: do bp only' + print*,' maxosd=0: do bp and then call osd once with channel llrs' + print*,' maxosd>1: do bp and then call osd maxosd times with saved bp outputs' + print*,' norder : osd decoding depth' + print*,' s : BPSK only, noise sigma, if s<0 value is ignored and sigma is calculated from SNR.' + print*,' Keff : Keff must be in the range [77,91]; Keff-77 is the # of bits to use as CRC.' + print*,' modtype : 0, coherent BPSK; 1 noncoherent 8FSK' + print*,' channel : 0, AWGN; 1, block Rayleigh (Rayleigh only works with 8FSK!)' + return + endif + call getarg(1,arg) + read(arg,*) maxosd + call getarg(2,arg) + read(arg,*) norder + call getarg(3,arg) + read(arg,*) ntrials + call getarg(4,arg) + read(arg,*) s + call getarg(5,arg) + read(arg,*) Keff + call getarg(6,arg) + read(arg,*) modtype + call getarg(7,arg) + read(arg,*) channeltype + +! scale Eb/No for a (174,91) code + rate=real(K)/real(N) + + write(*,*) "rate: ",rate + + allocate ( codeword(N), decoded(K), message(K) ) + allocate ( rxdata(N) ) + + one=.false. + do i=0,511 + do j=0,8 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + + msg="K9ABC K1ABC FN20" + i3=0 + n3=1 + call pack77(msg,i3,n3,c77) !Pack into 12 6-bit bytes + call unpack77(c77,1,msgsent,unpk77_success) !Unpack to get msgsent + write(*,*) "message sent ",msgsent + + read(c77,'(77i1)') msgbits(1:77) + write(*,*) 'message' + write(*,'(a71,1x,a3,1x,a3)') c77(1:71),c77(72:74),c77(75:77) + + call init_random_seed() + + iq=1 + if(modtype.gt.0) then ! MFSK - get tones + i3=-1 + n3=-1 + call genft8(msg,i3,n3,msgsent,msgbits,itone) + write(*,*) 'message tones' + write(*,'(79(i1,1x))') itone + itonecw(1:29)=itone(8:36) + itonecw(30:58)=itone(44:72) + iq=3 ! bits per symbol + endif + call encode174_91(msgbits,codeword) + write(*,*) 'crc14' + write(*,'(14i1)') codeword(78:91) + write(*,*) 'codeword' + write(*,'(22(8i1,1x))') codeword + write(*,*) 'Eb/N0 Es/N0 SNR2500 ngood nundetected sigma psymerr pbiterr' + do idb = 20,-4,-1 + nsymerr=0 + nbiterr=0 + db=idb/2.0-1.0 + sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) + ngood=0 + nue=0 + nsumerr=0 + do itrial=1, ntrials +! Create a realization of a noisy received word + if(modtype.eq.0) then + do i=1,N + rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() + enddo + nerr=0 + do i=1,N + if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1 + enddo + if(nerr.ge.1) nerrtot(nerr)=nerrtot(nerr)+1 + + rxav=sum(rxdata)/N + rx2av=sum(rxdata*rxdata)/N + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + if( s .lt. 0 ) then + ss=sigma + else + ss=s + endif + llr=2.0*rxdata/(ss*ss) + else +! noncoherent MFSK + do i=1,58 + do j=0,7 + if(j.eq.itonecw(i)) then + if(channeltype.eq.0) then + A=1.0 + elseif(channeltype.eq.1) then + xI=gran()**2 + gran()**2 + A=sqrt(xI/2) + endif + cs(j,i)= A + sigma*gran() + cmplx(0,1)*sigma*gran() + elseif(j.ne.itonecw(i)) then + cs(j,i)= sigma*gran() + cmplx(0,1)*sigma*gran() + endif + enddo + lmax=maxloc(abs(cs(:,i))) + if(lmax(1)-1.ne.itonecw(i) ) nsymerr=nsymerr+1 + enddo + do nsym=1,3 + nt=2**(3*nsym) + do ks=1,58,nsym + amax=-1.0 + do i=0,nt-1 + i1=i/64 + i2=iand(i,63)/8 + i3=iand(i,7) + if(nsym.eq.1) then + s2(i)=abs(cs(graymap(i3),ks)) + elseif(nsym.eq.2) then + s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) + elseif(nsym.eq.3) then + if(ks.ne.58) then + s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) + else + s2(i)=abs(cs(graymap(i1),ks)) + endif + else + print*,"Error - nsym must be 1, 2, or 3." + endif + enddo + + i32=1+(ks-1)*3 + if(nsym.eq.1) ibmax=2 + if(nsym.eq.2) ibmax=5 + if(nsym.eq.3) ibmax=8 + do ib=0,ibmax + bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) + if(i32+ib .gt.174) cycle + if(nsym.eq.1) then + bmeta(i32+ib)=bm + den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) + if(den.gt.0.0) then + cm=bm/den + else ! erase it + cm=0.0 + endif + bmetd(i32+ib)=cm + elseif(nsym.eq.2) then + bmetb(i32+ib)=bm + elseif(nsym.eq.3) then + bmetc(i32+ib)=bm + endif + enddo + enddo + enddo + call normalizebmet(bmeta,174) + call normalizebmet(bmetb,174) + call normalizebmet(bmetc,174) + call normalizebmet(bmetd,174) + + scalefac=2.83 + llra=scalefac*bmeta + llrb=scalefac*bmetb + llrc=scalefac*bmetc + llrd=scalefac*bmetd + + llr=llrc + endif + + do i=1, 174 + if(llr(i)*(codeword(i)-0.5).lt.0) nbiterr=nbiterr+1 + enddo + + nap=0 ! number of AP bits + llr(1:nap)=5*(2.0*msgbits(1:nap)-1.0) + apmask=0 + apmask(1:nap)=1 + call decode174_91(llr,Keff,maxosd,norder,apmask,message91,cw,ntype,nharderrors,dmin) +! If the decoder finds a valid codeword, nharderrors will be .ge. 0. + if( nharderrors.ge.0 ) then + nhw=count(cw.ne.codeword) + if(nhw.eq.0) then ! this is a good decode + ngood=ngood+1 + nerrdec(nerr)=nerrdec(nerr)+1 + else + nue=nue+1 + endif + endif + nsumerr=nsumerr+nerr + enddo + + esn0=db+10.0*log10(iq*rate) ! iq=3 bits per symbol for 8FSK + snr2500=esn0-10.0*log10(2500/6.25) +! pberr=real(nsumerr)/(real(ntrials*N)) + psymerr=real(nsymerr)/(ntrials*174.0/iq) + pbiterr=real(nbiterr)/(ntrials*174.0) + write(*,"(f4.1,4x,f5.1,4x,f5.1,1x,i8,1x,i8,8x,f5.2,8x,e10.3,8x,e10.3)") db,esn0,snr2500,ngood,nue,ss,psymerr,pbiterr + + enddo + + open(unit=23,file='nerrhisto.dat',status='unknown') + do i=1,174 + write(23,'(i4,2x,i10,i10,f10.2)') i,nerrdec(i),nerrtot(i),real(nerrdec(i))/real(nerrtot(i)+1e-10) + enddo + close(23) + +end program ldpcsim174_91 + +subroutine normalizebmet(bmet,n) + real bmet(n) + + bmetav=sum(bmet)/real(n) + bmet2av=sum(bmet*bmet)/real(n) + var=bmet2av-bmetav*bmetav + if( var .gt. 0.0 ) then + bmetsig=sqrt(var) + else + bmetsig=sqrt(bmet2av) + endif + bmet=bmet/bmetsig + return +end subroutine normalizebmet diff --git a/lib/ft8/osd174_91.f90 b/lib/ft8/osd174_91.f90 index ca99fd62..89677ebe 100755 --- a/lib/ft8/osd174_91.f90 +++ b/lib/ft8/osd174_91.f90 @@ -1,409 +1,409 @@ -subroutine osd174_91(llr,k,apmask,ndeep,message91,cw,nhardmin,dmin) -! -! An ordered-statistics decoder for the (174,91) code. -! Message payload is 77 bits. Any or all of a 14-bit CRC can be -! used for detecting incorrect codewords. The remaining CRC bits are -! cascaded with the LDPC code for the purpose of improving the -! distance spectrum of the code. -! -! If p1 (0.le.p1.le.14) is the number of CRC14 bits that are -! to be used for bad codeword detection, then the argument k should -! be set to 77+p1. -! -! Valid values for k are in the range [77,91]. -! - character*14 c14 - integer, parameter:: N=174 - integer*1 apmask(N),apmaskr(N) - integer*1, allocatable, save :: gen(:,:) - integer*1, allocatable :: genmrb(:,:),g2(:,:) - integer*1, allocatable :: temp(:),m0(:),me(:),mi(:),misub(:),e2sub(:),e2(:),ui(:) - integer*1, allocatable :: r2pat(:) - integer indices(N),nxor(N) - integer*1 cw(N),ce(N),c0(N),hdec(N) - integer*1, allocatable :: decoded(:) - integer*1 message91(91),m96(96) - integer indx(N) - real llr(N),rx(N),absrx(N) - - logical first,reset - data first/.true./ - save first - - allocate( genmrb(k,N), g2(N,k) ) - allocate( temp(k), m0(k), me(k), mi(k), misub(k), e2sub(N-k), e2(N-k), ui(N-k) ) - allocate( r2pat(N-k), decoded(k) ) - - if( first ) then ! fill the generator matrix -! -! Create generator matrix for partial CRC cascaded with LDPC code. -! -! Let p2=91-k and p1+p2=14. -! -! The last p2 bits of the CRC14 are cascaded with the LDPC code. -! -! The first p1=k-77 CRC14 bits will be used for error detection. -! - allocate( gen(k,N) ) - gen=0 - do i=1,k - message91=0 - message91(i)=1 - if(i.le.77) then - m96=0 - m96(1:91)=message91 - call get_crc14(m96,96,ncrc14) - write(c14,'(b14.14)') ncrc14 - read(c14,'(14i1)') message91(78:91) - message91(78:k)=0 - endif - call encode174_91_nocrc(message91,cw) - gen(i,:)=cw - enddo - - first=.false. - endif - - rx=llr - apmaskr=apmask - -! Hard decisions on the received word. - hdec=0 - where(rx .ge. 0) hdec=1 - -! Use magnitude of received symbols as a measure of reliability. - absrx=abs(rx) - call indexx(absrx,N,indx) - -! Re-order the columns of the generator matrix in order of decreasing reliability. - do i=1,N - genmrb(1:k,i)=gen(1:k,indx(N+1-i)) - indices(i)=indx(N+1-i) - enddo - -! Do gaussian elimination to create a generator matrix with the most reliable -! received bits in positions 1:k in order of decreasing reliability (more or less). - do id=1,k ! diagonal element indices - do icol=id,k+20 ! The 20 is ad hoc - beware - iflag=0 - if( genmrb(id,icol) .eq. 1 ) then - iflag=1 - if( icol .ne. id ) then ! reorder column - temp(1:k)=genmrb(1:k,id) - genmrb(1:k,id)=genmrb(1:k,icol) - genmrb(1:k,icol)=temp(1:k) - itmp=indices(id) - indices(id)=indices(icol) - indices(icol)=itmp - endif - do ii=1,k - if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then - genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) - endif - enddo - exit - endif - enddo - enddo - - g2=transpose(genmrb) - -! The hard decisions for the k MRB bits define the order 0 message, m0. -! Encode m0 using the modified generator matrix to find the "order 0" codeword. -! Flip various combinations of bits in m0 and re-encode to generate a list of -! codewords. Return the member of the list that has the smallest Euclidean -! distance to the received word. - - hdec=hdec(indices) ! hard decisions from received symbols - m0=hdec(1:k) ! zero'th order message - absrx=absrx(indices) - rx=rx(indices) - apmaskr=apmaskr(indices) - - call mrbencode91(m0,c0,g2,N,k) - nxor=ieor(c0,hdec) - nhardmin=sum(nxor) - dmin=sum(nxor*absrx) - - cw=c0 - ntotal=0 - nrejected=0 - npre1=0 - npre2=0 - - if(ndeep.eq.0) goto 998 ! norder=0 - if(ndeep.gt.6) ndeep=6 - if( ndeep.eq. 1) then - nord=1 - npre1=0 - npre2=0 - nt=40 - ntheta=12 - elseif(ndeep.eq.2) then - nord=1 - npre1=1 - npre2=0 - nt=40 -! ntheta=12 - ntheta=10 - elseif(ndeep.eq.3) then - nord=1 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=14 - elseif(ndeep.eq.4) then - nord=2 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=17 - elseif(ndeep.eq.5) then - nord=3 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=15 - else !ndeep=6 - nord=4 - npre1=1 - npre2=1 - nt=95 - ntheta=12 - ntau=15 - endif - - do iorder=1,nord - misub(1:k-iorder)=0 - misub(k-iorder+1:k)=1 - iflag=k-iorder+1 - do while(iflag .ge.0) - if(iorder.eq.nord .and. npre1.eq.0) then - iend=iflag - else - iend=1 - endif - d1=0. - do n1=iflag,iend,-1 - mi=misub - mi(n1)=1 - if(any(iand(apmaskr(1:k),mi).eq.1)) cycle - ntotal=ntotal+1 - me=ieor(m0,mi) - if(n1.eq.iflag) then - call mrbencode91(me,ce,g2,N,k) - e2sub=ieor(ce(k+1:N),hdec(k+1:N)) - e2=e2sub - nd1kpt=sum(e2sub(1:nt))+1 - d1=sum(ieor(me(1:k),hdec(1:k))*absrx(1:k)) - else - e2=ieor(e2sub,g2(k+1:N,n1)) - nd1kpt=sum(e2(1:nt))+2 - endif - if(nd1kpt .le. ntheta) then - call mrbencode91(me,ce,g2,N,k) - nxor=ieor(ce,hdec) - if(n1.eq.iflag) then - dd=d1+sum(e2sub*absrx(k+1:N)) - else - dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(k+1:N)) - endif - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - nd1kptbest=nd1kpt - endif - else - nrejected=nrejected+1 - endif - enddo -! Get the next test error pattern, iflag will go negative -! when the last pattern with weight iorder has been generated. - call nextpat91(misub,k,iorder,iflag) - enddo - enddo - - if(npre2.eq.1) then - reset=.true. - ntotal=0 - do i1=k,1,-1 - do i2=i1-1,1,-1 - ntotal=ntotal+1 - mi(1:ntau)=ieor(g2(k+1:k+ntau,i1),g2(k+1:k+ntau,i2)) - call boxit91(reset,mi(1:ntau),ntau,ntotal,i1,i2) - enddo - enddo - - ncount2=0 - ntotal2=0 - reset=.true. -! Now run through again and do the second pre-processing rule - misub(1:k-nord)=0 - misub(k-nord+1:k)=1 - iflag=k-nord+1 - do while(iflag .ge.0) - me=ieor(m0,misub) - call mrbencode91(me,ce,g2,N,k) - e2sub=ieor(ce(k+1:N),hdec(k+1:N)) - do i2=0,ntau - ntotal2=ntotal2+1 - ui=0 - if(i2.gt.0) ui(i2)=1 - r2pat=ieor(e2sub,ui) -778 continue - call fetchit91(reset,r2pat(1:ntau),ntau,in1,in2) - if(in1.gt.0.and.in2.gt.0) then - ncount2=ncount2+1 - mi=misub - mi(in1)=1 - mi(in2)=1 - if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:k),mi).eq.1)) cycle - me=ieor(m0,mi) - call mrbencode91(me,ce,g2,N,k) - nxor=ieor(ce,hdec) - dd=sum(nxor*absrx) - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - endif - goto 778 - endif - enddo - call nextpat91(misub,k,nord,iflag) - enddo - endif - -998 continue -! Re-order the codeword to [message bits][parity bits] format. - cw(indices)=cw - hdec(indices)=hdec - message91=cw(1:91) - m96=0 - m96(1:77)=cw(1:77) - m96(83:96)=cw(78:91) - call get_crc14(m96,96,nbadcrc) - if(nbadcrc.ne.0) nhardmin=-nhardmin - - return -end subroutine osd174_91 - -subroutine mrbencode91(me,codeword,g2,N,K) - integer*1 me(K),codeword(N),g2(N,K) -! fast encoding for low-weight test patterns - codeword=0 - do i=1,K - if( me(i) .eq. 1 ) then - codeword=ieor(codeword,g2(1:N,i)) - endif - enddo - return -end subroutine mrbencode91 - -subroutine nextpat91(mi,k,iorder,iflag) - integer*1 mi(k),ms(k) -! generate the next test error pattern - ind=-1 - do i=1,k-1 - if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i - enddo - if( ind .lt. 0 ) then ! no more patterns of this order - iflag=ind - return - endif - ms=0 - ms(1:ind-1)=mi(1:ind-1) - ms(ind)=1 - ms(ind+1)=0 - if( ind+1 .lt. k ) then - nz=iorder-sum(ms) - ms(k-nz+1:k)=1 - endif - mi=ms - do i=1,k ! iflag will point to the lowest-index 1 in mi - if(mi(i).eq.1) then - iflag=i - exit - endif - enddo - return -end subroutine nextpat91 - -subroutine boxit91(reset,e2,ntau,npindex,i1,i2) - integer*1 e2(1:ntau) - integer indexes(5000,2),fp(0:525000),np(5000) - logical reset - common/boxes/indexes,fp,np - - if(reset) then - patterns=-1 - fp=-1 - np=-1 - sc=-1 - indexes=-1 - reset=.false. - endif - - indexes(npindex,1)=i1 - indexes(npindex,2)=i2 - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - - ip=fp(ipat) ! see what's currently stored in fp(ipat) - if(ip.eq.-1) then - fp(ipat)=npindex - else - do while (np(ip).ne.-1) - ip=np(ip) - enddo - np(ip)=npindex - endif - return -end subroutine boxit91 - -subroutine fetchit91(reset,e2,ntau,i1,i2) - integer indexes(5000,2),fp(0:525000),np(5000) - integer lastpat - integer*1 e2(ntau) - logical reset - common/boxes/indexes,fp,np - save lastpat,inext - - if(reset) then - lastpat=-1 - reset=.false. - endif - - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - index=fp(ipat) - - if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices - i1=indexes(index,1) - i2=indexes(index,2) - inext=np(index) - elseif(lastpat.eq.ipat .and. inext.gt.0) then - i1=indexes(inext,1) - i2=indexes(inext,2) - inext=np(inext) - else - i1=-1 - i2=-1 - inext=-1 - endif - lastpat=ipat - return -end subroutine fetchit91 - +subroutine osd174_91(llr,k,apmask,ndeep,message91,cw,nhardmin,dmin) +! +! An ordered-statistics decoder for the (174,91) code. +! Message payload is 77 bits. Any or all of a 14-bit CRC can be +! used for detecting incorrect codewords. The remaining CRC bits are +! cascaded with the LDPC code for the purpose of improving the +! distance spectrum of the code. +! +! If p1 (0.le.p1.le.14) is the number of CRC14 bits that are +! to be used for bad codeword detection, then the argument k should +! be set to 77+p1. +! +! Valid values for k are in the range [77,91]. +! + character*14 c14 + integer, parameter:: N=174 + integer*1 apmask(N),apmaskr(N) + integer*1, allocatable, save :: gen(:,:) + integer*1, allocatable :: genmrb(:,:),g2(:,:) + integer*1, allocatable :: temp(:),m0(:),me(:),mi(:),misub(:),e2sub(:),e2(:),ui(:) + integer*1, allocatable :: r2pat(:) + integer indices(N),nxor(N) + integer*1 cw(N),ce(N),c0(N),hdec(N) + integer*1, allocatable :: decoded(:) + integer*1 message91(91),m96(96) + integer indx(N) + real llr(N),rx(N),absrx(N) + + logical first,reset + data first/.true./ + save first + + allocate( genmrb(k,N), g2(N,k) ) + allocate( temp(k), m0(k), me(k), mi(k), misub(k), e2sub(N-k), e2(N-k), ui(N-k) ) + allocate( r2pat(N-k), decoded(k) ) + + if( first ) then ! fill the generator matrix +! +! Create generator matrix for partial CRC cascaded with LDPC code. +! +! Let p2=91-k and p1+p2=14. +! +! The last p2 bits of the CRC14 are cascaded with the LDPC code. +! +! The first p1=k-77 CRC14 bits will be used for error detection. +! + allocate( gen(k,N) ) + gen=0 + do i=1,k + message91=0 + message91(i)=1 + if(i.le.77) then + m96=0 + m96(1:91)=message91 + call get_crc14(m96,96,ncrc14) + write(c14,'(b14.14)') ncrc14 + read(c14,'(14i1)') message91(78:91) + message91(78:k)=0 + endif + call encode174_91_nocrc(message91,cw) + gen(i,:)=cw + enddo + + first=.false. + endif + + rx=llr + apmaskr=apmask + +! Hard decisions on the received word. + hdec=0 + where(rx .ge. 0) hdec=1 + +! Use magnitude of received symbols as a measure of reliability. + absrx=abs(rx) + call indexx(absrx,N,indx) + +! Re-order the columns of the generator matrix in order of decreasing reliability. + do i=1,N + genmrb(1:k,i)=gen(1:k,indx(N+1-i)) + indices(i)=indx(N+1-i) + enddo + +! Do gaussian elimination to create a generator matrix with the most reliable +! received bits in positions 1:k in order of decreasing reliability (more or less). + do id=1,k ! diagonal element indices + do icol=id,k+20 ! The 20 is ad hoc - beware + iflag=0 + if( genmrb(id,icol) .eq. 1 ) then + iflag=1 + if( icol .ne. id ) then ! reorder column + temp(1:k)=genmrb(1:k,id) + genmrb(1:k,id)=genmrb(1:k,icol) + genmrb(1:k,icol)=temp(1:k) + itmp=indices(id) + indices(id)=indices(icol) + indices(icol)=itmp + endif + do ii=1,k + if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then + genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) + endif + enddo + exit + endif + enddo + enddo + + g2=transpose(genmrb) + +! The hard decisions for the k MRB bits define the order 0 message, m0. +! Encode m0 using the modified generator matrix to find the "order 0" codeword. +! Flip various combinations of bits in m0 and re-encode to generate a list of +! codewords. Return the member of the list that has the smallest Euclidean +! distance to the received word. + + hdec=hdec(indices) ! hard decisions from received symbols + m0=hdec(1:k) ! zero'th order message + absrx=absrx(indices) + rx=rx(indices) + apmaskr=apmaskr(indices) + + call mrbencode91(m0,c0,g2,N,k) + nxor=ieor(c0,hdec) + nhardmin=sum(nxor) + dmin=sum(nxor*absrx) + + cw=c0 + ntotal=0 + nrejected=0 + npre1=0 + npre2=0 + + if(ndeep.eq.0) goto 998 ! norder=0 + if(ndeep.gt.6) ndeep=6 + if( ndeep.eq. 1) then + nord=1 + npre1=0 + npre2=0 + nt=40 + ntheta=12 + elseif(ndeep.eq.2) then + nord=1 + npre1=1 + npre2=0 + nt=40 +! ntheta=12 + ntheta=10 + elseif(ndeep.eq.3) then + nord=1 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=14 + elseif(ndeep.eq.4) then + nord=2 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=17 + elseif(ndeep.eq.5) then + nord=3 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=15 + else !ndeep=6 + nord=4 + npre1=1 + npre2=1 + nt=95 + ntheta=12 + ntau=15 + endif + + do iorder=1,nord + misub(1:k-iorder)=0 + misub(k-iorder+1:k)=1 + iflag=k-iorder+1 + do while(iflag .ge.0) + if(iorder.eq.nord .and. npre1.eq.0) then + iend=iflag + else + iend=1 + endif + d1=0. + do n1=iflag,iend,-1 + mi=misub + mi(n1)=1 + if(any(iand(apmaskr(1:k),mi).eq.1)) cycle + ntotal=ntotal+1 + me=ieor(m0,mi) + if(n1.eq.iflag) then + call mrbencode91(me,ce,g2,N,k) + e2sub=ieor(ce(k+1:N),hdec(k+1:N)) + e2=e2sub + nd1kpt=sum(e2sub(1:nt))+1 + d1=sum(ieor(me(1:k),hdec(1:k))*absrx(1:k)) + else + e2=ieor(e2sub,g2(k+1:N,n1)) + nd1kpt=sum(e2(1:nt))+2 + endif + if(nd1kpt .le. ntheta) then + call mrbencode91(me,ce,g2,N,k) + nxor=ieor(ce,hdec) + if(n1.eq.iflag) then + dd=d1+sum(e2sub*absrx(k+1:N)) + else + dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(k+1:N)) + endif + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + nd1kptbest=nd1kpt + endif + else + nrejected=nrejected+1 + endif + enddo +! Get the next test error pattern, iflag will go negative +! when the last pattern with weight iorder has been generated. + call nextpat91(misub,k,iorder,iflag) + enddo + enddo + + if(npre2.eq.1) then + reset=.true. + ntotal=0 + do i1=k,1,-1 + do i2=i1-1,1,-1 + ntotal=ntotal+1 + mi(1:ntau)=ieor(g2(k+1:k+ntau,i1),g2(k+1:k+ntau,i2)) + call boxit91(reset,mi(1:ntau),ntau,ntotal,i1,i2) + enddo + enddo + + ncount2=0 + ntotal2=0 + reset=.true. +! Now run through again and do the second pre-processing rule + misub(1:k-nord)=0 + misub(k-nord+1:k)=1 + iflag=k-nord+1 + do while(iflag .ge.0) + me=ieor(m0,misub) + call mrbencode91(me,ce,g2,N,k) + e2sub=ieor(ce(k+1:N),hdec(k+1:N)) + do i2=0,ntau + ntotal2=ntotal2+1 + ui=0 + if(i2.gt.0) ui(i2)=1 + r2pat=ieor(e2sub,ui) +778 continue + call fetchit91(reset,r2pat(1:ntau),ntau,in1,in2) + if(in1.gt.0.and.in2.gt.0) then + ncount2=ncount2+1 + mi=misub + mi(in1)=1 + mi(in2)=1 + if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:k),mi).eq.1)) cycle + me=ieor(m0,mi) + call mrbencode91(me,ce,g2,N,k) + nxor=ieor(ce,hdec) + dd=sum(nxor*absrx) + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + endif + goto 778 + endif + enddo + call nextpat91(misub,k,nord,iflag) + enddo + endif + +998 continue +! Re-order the codeword to [message bits][parity bits] format. + cw(indices)=cw + hdec(indices)=hdec + message91=cw(1:91) + m96=0 + m96(1:77)=cw(1:77) + m96(83:96)=cw(78:91) + call get_crc14(m96,96,nbadcrc) + if(nbadcrc.ne.0) nhardmin=-nhardmin + + return +end subroutine osd174_91 + +subroutine mrbencode91(me,codeword,g2,N,K) + integer*1 me(K),codeword(N),g2(N,K) +! fast encoding for low-weight test patterns + codeword=0 + do i=1,K + if( me(i) .eq. 1 ) then + codeword=ieor(codeword,g2(1:N,i)) + endif + enddo + return +end subroutine mrbencode91 + +subroutine nextpat91(mi,k,iorder,iflag) + integer*1 mi(k),ms(k) +! generate the next test error pattern + ind=-1 + do i=1,k-1 + if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i + enddo + if( ind .lt. 0 ) then ! no more patterns of this order + iflag=ind + return + endif + ms=0 + ms(1:ind-1)=mi(1:ind-1) + ms(ind)=1 + ms(ind+1)=0 + if( ind+1 .lt. k ) then + nz=iorder-sum(ms) + ms(k-nz+1:k)=1 + endif + mi=ms + do i=1,k ! iflag will point to the lowest-index 1 in mi + if(mi(i).eq.1) then + iflag=i + exit + endif + enddo + return +end subroutine nextpat91 + +subroutine boxit91(reset,e2,ntau,npindex,i1,i2) + integer*1 e2(1:ntau) + integer indexes(5000,2),fp(0:525000),np(5000) + logical reset + common/boxes/indexes,fp,np + + if(reset) then + patterns=-1 + fp=-1 + np=-1 + sc=-1 + indexes=-1 + reset=.false. + endif + + indexes(npindex,1)=i1 + indexes(npindex,2)=i2 + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + + ip=fp(ipat) ! see what's currently stored in fp(ipat) + if(ip.eq.-1) then + fp(ipat)=npindex + else + do while (np(ip).ne.-1) + ip=np(ip) + enddo + np(ip)=npindex + endif + return +end subroutine boxit91 + +subroutine fetchit91(reset,e2,ntau,i1,i2) + integer indexes(5000,2),fp(0:525000),np(5000) + integer lastpat + integer*1 e2(ntau) + logical reset + common/boxes/indexes,fp,np + save lastpat,inext + + if(reset) then + lastpat=-1 + reset=.false. + endif + + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + index=fp(ipat) + + if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices + i1=indexes(index,1) + i2=indexes(index,2) + inext=np(index) + elseif(lastpat.eq.ipat .and. inext.gt.0) then + i1=indexes(inext,1) + i2=indexes(inext,2) + inext=np(inext) + else + i1=-1 + i2=-1 + inext=-1 + endif + lastpat=ipat + return +end subroutine fetchit91 + diff --git a/lib/ft8/subtractft8.f90 b/lib/ft8/subtractft8.f90 index 137d8616..40657e7e 100755 --- a/lib/ft8/subtractft8.f90 +++ b/lib/ft8/subtractft8.f90 @@ -1,106 +1,106 @@ -subroutine subtractft8(dd0,itone,f0,dt,lrefinedt) - -! Subtract an ft8 signal -! -! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t)) -! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) ) -! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ] -! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt} - - parameter (NMAX=15*12000,NFRAME=1920*79) - parameter (NFFT=NMAX,NFILT=4000) - real dd(NMAX),dd0(NMAX) - real window(-NFILT/2:NFILT/2) - real x(NFFT+2) - real endcorrection(NFILT/2+1) - complex cx(0:NFFT/2) - complex cref,camp,cfilt,cw,z - integer itone(79) - logical first,lrefinedt,ldt - data first/.true./ - common/heap8/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX) - equivalence (x,cx) - save first,/heap8/,endcorrection - - if(first) then ! Create and normalize the filter - pi=4.0*atan(1.0) - fac=1.0/float(nfft) - sumw=0.0 - do j=-NFILT/2,NFILT/2 - window(j)=cos(pi*j/NFILT)**2 - sumw=sumw+window(j) - enddo - cw=0. - cw(1:NFILT+1)=window/sumw - cw=cshift(cw,NFILT/2+1) - call four2a(cw,nfft,1,-1,1) - cw=cw*fac - first=.false. - do j=1,NFILT/2+1 - endcorrection(j)=1.0/(1.0-sum(window(j-1:NFILT/2))/sumw) - enddo - endif - -! Generate complex reference waveform cref - call gen_ft8wave(itone,79,1920,2.0,12000.0,f0,cref,xjunk,1,NFRAME) - - ldt=lrefinedt - if(ldt) then !Are we refining DT ? - sqa=sqf(-90) - sqb=sqf(+90) - sq0=sqf(0) - call peakup(sqa,sq0,sqb,dx) - if(abs(dx).gt.1.0) return !No acceptable minimum: do not subtract - i2=nint(90.0*dx) !Best estimate of idt - ldt=.false. - sq0=sqf(i2) !Do the subtraction with idt=i2 - else - sq0=sqf(0) !Do the subtraction with idt=0 - endif - dd0=dd !Return dd0 with this signal subtracted -! write(44,3044) nint(f0),dt-0.5,1.e-8*sum(dd*dd) -!3044 format(i4,f7.2,f10.6) - return - -contains - - real function sqf(idt) !Internal function: all variables accessible - nstart=dt*12000+1 + idt - camp=0. - dd=dd0 - do i=1,nframe - j=nstart-1+i - if(j.ge.1.and.j.le.NMAX) camp(i)=dd(j)*conjg(cref(i)) - enddo - - cfilt(1:nframe)=camp(1:nframe) - cfilt(nframe+1:)=0.0 - call four2a(cfilt,nfft,1,-1,1) - cfilt(1:nfft)=cfilt(1:nfft)*cw(1:nfft) - call four2a(cfilt,nfft,1,1,1) - cfilt(1:NFILT/2+1)=cfilt(1:NFILT/2+1)*endcorrection - cfilt(nframe:nframe-NFILT/2:-1)=cfilt(nframe:nframe-NFILT/2:-1)*endcorrection - x=0. - do i=1,nframe - j=nstart+i-1 - if(j.ge.1 .and. j.le.NMAX) then - z=cfilt(i)*cref(i) - dd(j)=dd(j)-2.0*real(z) !Subtract the reconstructed signal - x(i)=dd(j) - endif - enddo - sqq=0. - if(ldt) then - call four2a(cx,NFFT,1,-1,0) !Forward FFT, r2c - df=12000.0/NFFT - ia=(f0-1.5*6.25)/df - ib=(f0+8.5*6.25)/df - do i=ia,ib - sqq=sqq + real(cx(i))*real(cx(i)) + aimag(cx(i))*aimag(cx(i)) - enddo - endif - sqf=sqq - return - end function sqf - -end subroutine subtractft8 +subroutine subtractft8(dd0,itone,f0,dt,lrefinedt) + +! Subtract an ft8 signal +! +! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t)) +! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) ) +! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ] +! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt} + + parameter (NMAX=15*12000,NFRAME=1920*79) + parameter (NFFT=NMAX,NFILT=4000) + real dd(NMAX),dd0(NMAX) + real window(-NFILT/2:NFILT/2) + real x(NFFT+2) + real endcorrection(NFILT/2+1) + complex cx(0:NFFT/2) + complex cref,camp,cfilt,cw,z + integer itone(79) + logical first,lrefinedt,ldt + data first/.true./ + common/heap8/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX) + equivalence (x,cx) + save first,/heap8/,endcorrection + + if(first) then ! Create and normalize the filter + pi=4.0*atan(1.0) + fac=1.0/float(nfft) + sumw=0.0 + do j=-NFILT/2,NFILT/2 + window(j)=cos(pi*j/NFILT)**2 + sumw=sumw+window(j) + enddo + cw=0. + cw(1:NFILT+1)=window/sumw + cw=cshift(cw,NFILT/2+1) + call four2a(cw,nfft,1,-1,1) + cw=cw*fac + first=.false. + do j=1,NFILT/2+1 + endcorrection(j)=1.0/(1.0-sum(window(j-1:NFILT/2))/sumw) + enddo + endif + +! Generate complex reference waveform cref + call gen_ft8wave(itone,79,1920,2.0,12000.0,f0,cref,xjunk,1,NFRAME) + + ldt=lrefinedt + if(ldt) then !Are we refining DT ? + sqa=sqf(-90) + sqb=sqf(+90) + sq0=sqf(0) + call peakup(sqa,sq0,sqb,dx) + if(abs(dx).gt.1.0) return !No acceptable minimum: do not subtract + i2=nint(90.0*dx) !Best estimate of idt + ldt=.false. + sq0=sqf(i2) !Do the subtraction with idt=i2 + else + sq0=sqf(0) !Do the subtraction with idt=0 + endif + dd0=dd !Return dd0 with this signal subtracted +! write(44,3044) nint(f0),dt-0.5,1.e-8*sum(dd*dd) +!3044 format(i4,f7.2,f10.6) + return + +contains + + real function sqf(idt) !Internal function: all variables accessible + nstart=dt*12000+1 + idt + camp=0. + dd=dd0 + do i=1,nframe + j=nstart-1+i + if(j.ge.1.and.j.le.NMAX) camp(i)=dd(j)*conjg(cref(i)) + enddo + + cfilt(1:nframe)=camp(1:nframe) + cfilt(nframe+1:)=0.0 + call four2a(cfilt,nfft,1,-1,1) + cfilt(1:nfft)=cfilt(1:nfft)*cw(1:nfft) + call four2a(cfilt,nfft,1,1,1) + cfilt(1:NFILT/2+1)=cfilt(1:NFILT/2+1)*endcorrection + cfilt(nframe:nframe-NFILT/2:-1)=cfilt(nframe:nframe-NFILT/2:-1)*endcorrection + x=0. + do i=1,nframe + j=nstart+i-1 + if(j.ge.1 .and. j.le.NMAX) then + z=cfilt(i)*cref(i) + dd(j)=dd(j)-2.0*real(z) !Subtract the reconstructed signal + x(i)=dd(j) + endif + enddo + sqq=0. + if(ldt) then + call four2a(cx,NFFT,1,-1,0) !Forward FFT, r2c + df=12000.0/NFFT + ia=(f0-1.5*6.25)/df + ib=(f0+8.5*6.25)/df + do i=ia,ib + sqq=sqq + real(cx(i))*real(cx(i)) + aimag(cx(i))*aimag(cx(i)) + enddo + endif + sqf=sqq + return + end function sqf + +end subroutine subtractft8 diff --git a/lib/ft8/test_ft8q3.f90 b/lib/ft8/test_ft8q3.f90 index 00871e61..4a3802c3 100755 --- a/lib/ft8/test_ft8q3.f90 +++ b/lib/ft8/test_ft8q3.f90 @@ -1,41 +1,41 @@ -program test_ft8q3 - -! Test q3-style decodes for FT8. - - use packjt77 - parameter(NN=79,NSPS=32) - parameter(NWAVE=NN*NSPS) !2528 - parameter(NZ=3200,NLAGS=NZ-NWAVE) - character arg*12 - character*37 msg - character*12 call_1,call_2 - character*4 grid4 - complex cd(0:NZ-1) - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.4 .and. nargs.ne.5) then - print*,'Usage: ft8q3 DT f0 call_1 call_2 [grid4]' - go to 999 - endif - call getarg(1,arg) - read(arg,*) xdt !Time offset from nominal (s) - call getarg(2,arg) - read(arg,*) f0 !Frequency (Hz) - call getarg(3,call_1) !First callsign - call getarg(4,call_2) !Second callsign - grid4=' ' - if(nargs.eq.5) call getarg(5,grid4) !Locator for call_2 - - do i=0,NZ-1 - read(40,3040) cd(i) -3040 format(17x,2f10.3) - enddo - - call sec0(0,t) - call ft8q3(cd,xdt,f0,call_1,call_2,grid4,msg,snr) - call sec0(1,t) - write(*,1100) t,snr,trim(msg) -1100 format('Time:',f6.2,' S/N:',f6.1,' msg: ',a) - -999 end program test_ft8q3 +program test_ft8q3 + +! Test q3-style decodes for FT8. + + use packjt77 + parameter(NN=79,NSPS=32) + parameter(NWAVE=NN*NSPS) !2528 + parameter(NZ=3200,NLAGS=NZ-NWAVE) + character arg*12 + character*37 msg + character*12 call_1,call_2 + character*4 grid4 + complex cd(0:NZ-1) + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.4 .and. nargs.ne.5) then + print*,'Usage: ft8q3 DT f0 call_1 call_2 [grid4]' + go to 999 + endif + call getarg(1,arg) + read(arg,*) xdt !Time offset from nominal (s) + call getarg(2,arg) + read(arg,*) f0 !Frequency (Hz) + call getarg(3,call_1) !First callsign + call getarg(4,call_2) !Second callsign + grid4=' ' + if(nargs.eq.5) call getarg(5,grid4) !Locator for call_2 + + do i=0,NZ-1 + read(40,3040) cd(i) +3040 format(17x,2f10.3) + enddo + + call sec0(0,t) + call ft8q3(cd,xdt,f0,call_1,call_2,grid4,msg,snr) + call sec0(1,t) + write(*,1100) t,snr,trim(msg) +1100 format('Time:',f6.2,' S/N:',f6.1,' msg: ',a) + +999 end program test_ft8q3 diff --git a/lib/ft8_decode.f90 b/lib/ft8_decode.f90 index 71e6476e..9b87114e 100755 --- a/lib/ft8_decode.f90 +++ b/lib/ft8_decode.f90 @@ -1,300 +1,300 @@ -module ft8_decode - - parameter (MAXFOX=1000) - character*12 c2fox(MAXFOX) - character*4 g2fox(MAXFOX) - integer nsnrfox(MAXFOX) - integer nfreqfox(MAXFOX) - integer n30fox(MAXFOX) - integer n30z - integer nfox - - type :: ft8_decoder - procedure(ft8_decode_callback), pointer :: callback - contains - procedure :: decode - end type ft8_decoder - - abstract interface - subroutine ft8_decode_callback (this,sync,snr,dt,freq,decoded,nap,qual) - import ft8_decoder - implicit none - class(ft8_decoder), intent(inout) :: this - real, intent(in) :: sync - integer, intent(in) :: snr - real, intent(in) :: dt - real, intent(in) :: freq - character(len=37), intent(in) :: decoded - integer, intent(in) :: nap - real, intent(in) :: qual - end subroutine ft8_decode_callback - end interface - -contains - - subroutine decode(this,callback,iwave,nQSOProgress,nfqso,nftx,newdat, & - nutc,nfa,nfb,nzhsym,ndepth,emedelay,ncontest,nagain,lft8apon, & - lapcqonly,napwid,mycall12,hiscall12,ldiskdat) - use iso_c_binding, only: c_bool, c_int - use timer_module, only: timer - use shmem, only: shmem_lock, shmem_unlock - use ft8_a7 - - include 'ft8/ft8_params.f90' - - class(ft8_decoder), intent(inout) :: this - procedure(ft8_decode_callback) :: callback - parameter (MAXCAND=600,MAX_EARLY=200,NPTS=15*12000) - real*8 tsec,tseq - real sbase(NH1) - real candidate(3,MAXCAND) - real dd(NPTS),dd1(NPTS) - logical, intent(in) :: lft8apon,lapcqonly,nagain - logical newdat,lsubtract,ldupe,lrefinedt - logical*1 ldiskdat - logical lsubtracted(MAX_EARLY) - character*12 mycall12,hiscall12,call_1,call_2 - character*4 grid4 - integer*2 iwave(NPTS) - integer apsym2(58),aph10(10) - character datetime*13,msg37*37 - character*37 allmessages(MAX_EARLY) - character*12 ctime - integer allsnrs(MAX_EARLY) - integer itone(NN) - integer itone_save(NN,MAX_EARLY) - real f1_save(MAX_EARLY) - real xdt_save(MAX_EARLY) - data nutc0/-1/ - - save dd,dd1,nutc0,ndec_early,itone_save,f1_save,xdt_save,lsubtracted, & - allmessages - - this%callback => callback - write(datetime,1001) nutc !### TEMPORARY ### -1001 format("000000_",i6.6) - - if(nutc0.eq.-1) then - msg0=' ' - dt0=0. - f0=0. - endif -!Added 41==nzhsym to force a reset if the same wav file is processed twice or more in a row, -!in which case nutc.eq.nutc0 and ndec(jseq,1) doesn't get reset - if(nzhsym==41 .or. (nutc.ne.nutc0)) then -! New UTC. Move previously saved 'a7' data from k=1 to k=0 - iz=ndec(jseq,1) - dt0(1:iz,jseq,0) = dt0(1:iz,jseq,1) - f0(1:iz,jseq,0) = f0(1:iz,jseq,1) - msg0(1:iz,jseq,0) = msg0(1:iz,jseq,1) - ndec(jseq,0)=iz - ndec(jseq,1)=0 - nutc0=nutc - dt0(:,jseq,1)=0. - f0(:,jseq,1)=0. - endif - - if(ndepth.eq.1 .and. nzhsym.lt.50) then - ndec_early=0 - return - endif - if(ndepth.eq.1 .and. nzhsym.eq.50) then - dd=iwave - endif - - call ft8apset(mycall12,hiscall12,ncontest,apsym2,aph10) - - if(nzhsym.le.47) then - dd=iwave - dd1=dd - endif - - if(nzhsym.eq.41) then - ndecodes=0 - allmessages=' ' - allsnrs=0 - else - ndecodes=ndec_early - endif - - if(nzhsym.eq.47 .and. ndec_early.eq.0) then - dd1=dd - go to 800 - endif - - if(nzhsym.eq.47 .and. ndec_early.ge.1) then - lsubtracted=.false. - lrefinedt=.true. - if(ndepth.le.2) lrefinedt=.false. - call timer('sub_ft8b',0) - do i=1,ndec_early - if(xdt_save(i)-0.5.lt.0.396) then - call subtractft8(dd,itone_save(1,i),f1_save(i),xdt_save(i), & - lrefinedt) - lsubtracted(i)=.true. - endif - call timestamp(tsec,tseq,ctime) - if(.not.ldiskdat .and. tseq.ge.14.3d0) then !Bail out before done - call timer('sub_ft8b',1) - dd1=dd - go to 800 - endif - enddo - call timer('sub_ft8b',1) - dd1=dd - go to 900 - endif - - if(nzhsym.eq.50 .and. ndec_early.ge.1 .and. .not.nagain) then - n=47*3456 - dd(1:n)=dd1(1:n) - dd(n+1:)=iwave(n+1:) - call timer('sub_ft8c',0) - do i=1,ndec_early - if(lsubtracted(i)) cycle - call subtractft8(dd,itone_save(1,i),f1_save(i),xdt_save(i),.true.) - enddo - call timer('sub_ft8c',1) - endif - - ifa=nfa - ifb=nfb - if(nzhsym.eq.50 .and. nagain) then - dd=iwave - ifa=nfqso-20 - ifb=nfqso+20 - endif - -! For now: -! ndepth=1: 1 pass, bp -! ndepth=2: subtraction, 3 passes, bp+osd (no subtract refinement) -! ndepth=3: subtraction, 3 passes, bp+osd - npass=3 - if(ndepth.eq.1) npass=2 - do ipass=1,npass - newdat=.true. - syncmin=1.3 - if(ndepth.le.2) syncmin=1.6 - if(nzhsym.eq.41) syncmin=2.0 - if(ipass.eq.1) then - lsubtract=.true. - ndeep=ndepth - if(ndepth.eq.3) ndeep=2 - elseif(ipass.eq.2) then - n2=ndecodes - if(ndecodes.eq.0) cycle - lsubtract=.true. - ndeep=ndepth - elseif(ipass.eq.3) then - if((ndecodes-n2).eq.0) cycle - lsubtract=.true. - ndeep=ndepth - endif - call timer('sync8 ',0) - maxc=MAXCAND - call sync8(dd,NPTS,ifa,ifb,syncmin,nfqso,maxc,candidate,ncand,sbase) - call timer('sync8 ',1) - do icand=1,ncand - sync=candidate(3,icand) - f1=candidate(1,icand) - xdt=candidate(2,icand) - xbase=10.0**(0.1*(sbase(nint(f1/3.125))-40.0)) - msg37=' ' - call timer('ft8b ',0) - call ft8b(dd,newdat,nQSOProgress,nfqso,nftx,ndeep,nzhsym,lft8apon, & - lapcqonly,napwid,lsubtract,nagain,ncontest,iaptype,mycall12, & - hiscall12,f1,xdt,xbase,apsym2,aph10,nharderrors,dmin, & - nbadcrc,iappass,msg37,xsnr,itone) - call timer('ft8b ',1) - nsnr=nint(xsnr) - xdt=xdt-0.5 - hd=nharderrors+dmin - if(nbadcrc.eq.0) then - ldupe=.false. - do id=1,ndecodes - if(msg37.eq.allmessages(id)) ldupe=.true. - enddo - if(.not.ldupe) then - if(ndecodes.ge.MAX_EARLY) then - cycle - endif - ndecodes=ndecodes+1 - allmessages(ndecodes)=msg37 - allsnrs(ndecodes)=nsnr - f1_save(ndecodes)=f1 - xdt_save(ndecodes)=xdt+0.5 - itone_save(1:NN,ndecodes)=itone - endif - if(.not.ldupe .and. associated(this%callback)) then - qual=1.0-(nharderrors+dmin)/60.0 ! scale qual to [0.0,1.0] - if(emedelay.ne.0) xdt=xdt+2.0 - call this%callback(sync,nsnr,xdt,f1,msg37,iaptype,qual) - call ft8_a7_save(nutc,xdt,f1,msg37) !Enter decode in table - endif - endif - call timestamp(tsec,tseq,ctime) - if(.not.ldiskdat .and. nzhsym.eq.41 .and. & - tseq.ge.13.4d0) go to 800 !Bail out before done - enddo ! icand - enddo ! ipass - -800 ndec_early=0 - if(nzhsym.lt.50) ndec_early=ndecodes - -900 continue - if(lft8apon .and. ncontest.ne.6 .and. ncontest.ne.7 .and. nzhsym.eq.50 .and. ndec(jseq,0).ge.1) then - newdat=.true. - do i=1,ndec(jseq,0) - if(f0(i,jseq,0).eq.-99.0) exit - if(f0(i,jseq,0).eq.-98.0) cycle - if(index(msg0(i,jseq,0),'<').ge.1) cycle !### Temporary ### - msg37=msg0(i,jseq,0) - i1=index(msg37,' ') - i2=index(msg37(i1+1:),' ') + i1 - call_1=msg37(1:i1-1) - call_2=msg37(i1+1:i2-1) - grid4=msg37(i2+1:i2+4) - if(grid4.eq.'RR73' .or. index(grid4,'+').gt.0 .or. & - index(grid4,'-').gt.0) grid4=' ' - xdt=dt0(i,jseq,0) - f1=f0(i,jseq,0) - xbase=10.0**(0.1*(sbase(max(1,nint(f1/3.125)))-40.0)) - msg37=' ' - call timer('ft8_a7d ',0) - call ft8_a7d(dd,newdat,call_1,call_2,grid4,xdt,f1,xbase,nharderrors, & - dmin,msg37,xsnr) - call timer('ft8_a7d ',1) - - if(nharderrors.ge.0) then - if(associated(this%callback)) then - nsnr=xsnr - iaptype=7 - qual=1.0 - call this%callback(sync,nsnr,xdt,f1,msg37,iaptype,qual) - call ft8_a7_save(nutc,xdt,f1,msg37) !Enter decode in table - endif - endif - enddo - endif - - return -end subroutine decode - -subroutine timestamp(tsec,tseq,ctime) - real*8 tsec,tseq - character*12 ctime - integer itime(8) - call date_and_time(values=itime) - tsec=3600.d0*(itime(5)-itime(4)/60.d0) + 60.d0*itime(6) + & - itime(7) + 0.001d0*itime(8) - tsec=mod(tsec+2*86400.d0,86400.d0) - tseq=mod(itime(7)+0.001d0*itime(8),15.d0) - if(tseq.lt.10.d0) tseq=tseq+15.d0 - sec=itime(7)+0.001*itime(8) - write(ctime,1000) itime(5)-itime(4)/60,itime(6),sec -1000 format(i2.2,':',i2.2,':',f6.3) - if(ctime(7:7).eq.' ') ctime(7:7)='0' - return -end subroutine timestamp - -end module ft8_decode +module ft8_decode + + parameter (MAXFOX=1000) + character*12 c2fox(MAXFOX) + character*4 g2fox(MAXFOX) + integer nsnrfox(MAXFOX) + integer nfreqfox(MAXFOX) + integer n30fox(MAXFOX) + integer n30z + integer nfox + + type :: ft8_decoder + procedure(ft8_decode_callback), pointer :: callback + contains + procedure :: decode + end type ft8_decoder + + abstract interface + subroutine ft8_decode_callback (this,sync,snr,dt,freq,decoded,nap,qual) + import ft8_decoder + implicit none + class(ft8_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=37), intent(in) :: decoded + integer, intent(in) :: nap + real, intent(in) :: qual + end subroutine ft8_decode_callback + end interface + +contains + + subroutine decode(this,callback,iwave,nQSOProgress,nfqso,nftx,newdat, & + nutc,nfa,nfb,nzhsym,ndepth,emedelay,ncontest,nagain,lft8apon, & + lapcqonly,napwid,mycall12,hiscall12,ldiskdat) + use iso_c_binding, only: c_bool, c_int + use timer_module, only: timer + use shmem, only: shmem_lock, shmem_unlock + use ft8_a7 + + include 'ft8/ft8_params.f90' + + class(ft8_decoder), intent(inout) :: this + procedure(ft8_decode_callback) :: callback + parameter (MAXCAND=600,MAX_EARLY=200,NPTS=15*12000) + real*8 tsec,tseq + real sbase(NH1) + real candidate(3,MAXCAND) + real dd(NPTS),dd1(NPTS) + logical, intent(in) :: lft8apon,lapcqonly,nagain + logical newdat,lsubtract,ldupe,lrefinedt + logical*1 ldiskdat + logical lsubtracted(MAX_EARLY) + character*12 mycall12,hiscall12,call_1,call_2 + character*4 grid4 + integer*2 iwave(NPTS) + integer apsym2(58),aph10(10) + character datetime*13,msg37*37 + character*37 allmessages(MAX_EARLY) + character*12 ctime + integer allsnrs(MAX_EARLY) + integer itone(NN) + integer itone_save(NN,MAX_EARLY) + real f1_save(MAX_EARLY) + real xdt_save(MAX_EARLY) + data nutc0/-1/ + + save dd,dd1,nutc0,ndec_early,itone_save,f1_save,xdt_save,lsubtracted, & + allmessages + + this%callback => callback + write(datetime,1001) nutc !### TEMPORARY ### +1001 format("000000_",i6.6) + + if(nutc0.eq.-1) then + msg0=' ' + dt0=0. + f0=0. + endif +!Added 41==nzhsym to force a reset if the same wav file is processed twice or more in a row, +!in which case nutc.eq.nutc0 and ndec(jseq,1) doesn't get reset + if(nzhsym==41 .or. (nutc.ne.nutc0)) then +! New UTC. Move previously saved 'a7' data from k=1 to k=0 + iz=ndec(jseq,1) + dt0(1:iz,jseq,0) = dt0(1:iz,jseq,1) + f0(1:iz,jseq,0) = f0(1:iz,jseq,1) + msg0(1:iz,jseq,0) = msg0(1:iz,jseq,1) + ndec(jseq,0)=iz + ndec(jseq,1)=0 + nutc0=nutc + dt0(:,jseq,1)=0. + f0(:,jseq,1)=0. + endif + + if(ndepth.eq.1 .and. nzhsym.lt.50) then + ndec_early=0 + return + endif + if(ndepth.eq.1 .and. nzhsym.eq.50) then + dd=iwave + endif + + call ft8apset(mycall12,hiscall12,ncontest,apsym2,aph10) + + if(nzhsym.le.47) then + dd=iwave + dd1=dd + endif + + if(nzhsym.eq.41) then + ndecodes=0 + allmessages=' ' + allsnrs=0 + else + ndecodes=ndec_early + endif + + if(nzhsym.eq.47 .and. ndec_early.eq.0) then + dd1=dd + go to 800 + endif + + if(nzhsym.eq.47 .and. ndec_early.ge.1) then + lsubtracted=.false. + lrefinedt=.true. + if(ndepth.le.2) lrefinedt=.false. + call timer('sub_ft8b',0) + do i=1,ndec_early + if(xdt_save(i)-0.5.lt.0.396) then + call subtractft8(dd,itone_save(1,i),f1_save(i),xdt_save(i), & + lrefinedt) + lsubtracted(i)=.true. + endif + call timestamp(tsec,tseq,ctime) + if(.not.ldiskdat .and. tseq.ge.14.3d0) then !Bail out before done + call timer('sub_ft8b',1) + dd1=dd + go to 800 + endif + enddo + call timer('sub_ft8b',1) + dd1=dd + go to 900 + endif + + if(nzhsym.eq.50 .and. ndec_early.ge.1 .and. .not.nagain) then + n=47*3456 + dd(1:n)=dd1(1:n) + dd(n+1:)=iwave(n+1:) + call timer('sub_ft8c',0) + do i=1,ndec_early + if(lsubtracted(i)) cycle + call subtractft8(dd,itone_save(1,i),f1_save(i),xdt_save(i),.true.) + enddo + call timer('sub_ft8c',1) + endif + + ifa=nfa + ifb=nfb + if(nzhsym.eq.50 .and. nagain) then + dd=iwave + ifa=nfqso-20 + ifb=nfqso+20 + endif + +! For now: +! ndepth=1: 1 pass, bp +! ndepth=2: subtraction, 3 passes, bp+osd (no subtract refinement) +! ndepth=3: subtraction, 3 passes, bp+osd + npass=3 + if(ndepth.eq.1) npass=2 + do ipass=1,npass + newdat=.true. + syncmin=1.3 + if(ndepth.le.2) syncmin=1.6 + if(nzhsym.eq.41) syncmin=2.0 + if(ipass.eq.1) then + lsubtract=.true. + ndeep=ndepth + if(ndepth.eq.3) ndeep=2 + elseif(ipass.eq.2) then + n2=ndecodes + if(ndecodes.eq.0) cycle + lsubtract=.true. + ndeep=ndepth + elseif(ipass.eq.3) then + if((ndecodes-n2).eq.0) cycle + lsubtract=.true. + ndeep=ndepth + endif + call timer('sync8 ',0) + maxc=MAXCAND + call sync8(dd,NPTS,ifa,ifb,syncmin,nfqso,maxc,candidate,ncand,sbase) + call timer('sync8 ',1) + do icand=1,ncand + sync=candidate(3,icand) + f1=candidate(1,icand) + xdt=candidate(2,icand) + xbase=10.0**(0.1*(sbase(nint(f1/3.125))-40.0)) + msg37=' ' + call timer('ft8b ',0) + call ft8b(dd,newdat,nQSOProgress,nfqso,nftx,ndeep,nzhsym,lft8apon, & + lapcqonly,napwid,lsubtract,nagain,ncontest,iaptype,mycall12, & + hiscall12,f1,xdt,xbase,apsym2,aph10,nharderrors,dmin, & + nbadcrc,iappass,msg37,xsnr,itone) + call timer('ft8b ',1) + nsnr=nint(xsnr) + xdt=xdt-0.5 + hd=nharderrors+dmin + if(nbadcrc.eq.0) then + ldupe=.false. + do id=1,ndecodes + if(msg37.eq.allmessages(id)) ldupe=.true. + enddo + if(.not.ldupe) then + if(ndecodes.ge.MAX_EARLY) then + cycle + endif + ndecodes=ndecodes+1 + allmessages(ndecodes)=msg37 + allsnrs(ndecodes)=nsnr + f1_save(ndecodes)=f1 + xdt_save(ndecodes)=xdt+0.5 + itone_save(1:NN,ndecodes)=itone + endif + if(.not.ldupe .and. associated(this%callback)) then + qual=1.0-(nharderrors+dmin)/60.0 ! scale qual to [0.0,1.0] + if(emedelay.ne.0) xdt=xdt+2.0 + call this%callback(sync,nsnr,xdt,f1,msg37,iaptype,qual) + call ft8_a7_save(nutc,xdt,f1,msg37) !Enter decode in table + endif + endif + call timestamp(tsec,tseq,ctime) + if(.not.ldiskdat .and. nzhsym.eq.41 .and. & + tseq.ge.13.4d0) go to 800 !Bail out before done + enddo ! icand + enddo ! ipass + +800 ndec_early=0 + if(nzhsym.lt.50) ndec_early=ndecodes + +900 continue + if(lft8apon .and. ncontest.ne.6 .and. ncontest.ne.7 .and. nzhsym.eq.50 .and. ndec(jseq,0).ge.1) then + newdat=.true. + do i=1,ndec(jseq,0) + if(f0(i,jseq,0).eq.-99.0) exit + if(f0(i,jseq,0).eq.-98.0) cycle + if(index(msg0(i,jseq,0),'<').ge.1) cycle !### Temporary ### + msg37=msg0(i,jseq,0) + i1=index(msg37,' ') + i2=index(msg37(i1+1:),' ') + i1 + call_1=msg37(1:i1-1) + call_2=msg37(i1+1:i2-1) + grid4=msg37(i2+1:i2+4) + if(grid4.eq.'RR73' .or. index(grid4,'+').gt.0 .or. & + index(grid4,'-').gt.0) grid4=' ' + xdt=dt0(i,jseq,0) + f1=f0(i,jseq,0) + xbase=10.0**(0.1*(sbase(max(1,nint(f1/3.125)))-40.0)) + msg37=' ' + call timer('ft8_a7d ',0) + call ft8_a7d(dd,newdat,call_1,call_2,grid4,xdt,f1,xbase,nharderrors, & + dmin,msg37,xsnr) + call timer('ft8_a7d ',1) + + if(nharderrors.ge.0) then + if(associated(this%callback)) then + nsnr=xsnr + iaptype=7 + qual=1.0 + call this%callback(sync,nsnr,xdt,f1,msg37,iaptype,qual) + call ft8_a7_save(nutc,xdt,f1,msg37) !Enter decode in table + endif + endif + enddo + endif + + return +end subroutine decode + +subroutine timestamp(tsec,tseq,ctime) + real*8 tsec,tseq + character*12 ctime + integer itime(8) + call date_and_time(values=itime) + tsec=3600.d0*(itime(5)-itime(4)/60.d0) + 60.d0*itime(6) + & + itime(7) + 0.001d0*itime(8) + tsec=mod(tsec+2*86400.d0,86400.d0) + tseq=mod(itime(7)+0.001d0*itime(8),15.d0) + if(tseq.lt.10.d0) tseq=tseq+15.d0 + sec=itime(7)+0.001*itime(8) + write(ctime,1000) itime(5)-itime(4)/60,itime(6),sec +1000 format(i2.2,':',i2.2,':',f6.3) + if(ctime(7:7).eq.' ') ctime(7:7)='0' + return +end subroutine timestamp + +end module ft8_decode diff --git a/lib/ftrsd/Makefile b/lib/ftrsd/Makefile index 46486498..61b1357e 100755 --- a/lib/ftrsd/Makefile +++ b/lib/ftrsd/Makefile @@ -1,53 +1,53 @@ -# Makefile for Windows in JTSDK-PY environment - -# Re-direct stdout and stderr: cmd.exe bash -# make > junk 2>&1 make &> junk - -CC = gcc -FC = gfortran - -FFLAGS = -O2 -DWIN32 -fbounds-check -fno-second-underscore -Wall \ - -Wno-conversion -Wno-character-truncation -CFLAGS = -I. -DWIN32 -DWin32 -DBIGSYM -DHAVE_STRUCT_TIMESPEC - -# 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: libftrsd.a - -OBJS1 = extract2.o ftrsd2.o init_rs_int.o encode_rs_int.o decode_rs_int.o -libftrsd.a: $(OBJS1) - ar cr libftrsd.a $(OBJS1) - ranlib libftrsd.a - cp libftrsd.a .. - -# Build rsdtest -OBJS2 = rsdtest.o -rsdtest: $(OBJS2) ../libjt.a - $(FC) -o rsdtest $(OBJS2) libftrsd.a ../libjt.a ../libpthreadGC2.a - -ftrsd: ftrsd.o encode_rs_int.o decode_rs_int.o init_rs_int.o - gcc -g -o $@ $^ - -encode_rs_int.o: encode_rs.c - gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ - -decode_rs_int.o: decode_rs.c - gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ - -init_rs_int.o: init_rs.c - gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ - -.PHONY : clean - -clean: - rm -rf *.o libjt.a rsdtest ftrsd +# Makefile for Windows in JTSDK-PY environment + +# Re-direct stdout and stderr: cmd.exe bash +# make > junk 2>&1 make &> junk + +CC = gcc +FC = gfortran + +FFLAGS = -O2 -DWIN32 -fbounds-check -fno-second-underscore -Wall \ + -Wno-conversion -Wno-character-truncation +CFLAGS = -I. -DWIN32 -DWin32 -DBIGSYM -DHAVE_STRUCT_TIMESPEC + +# 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: libftrsd.a + +OBJS1 = extract2.o ftrsd2.o init_rs_int.o encode_rs_int.o decode_rs_int.o +libftrsd.a: $(OBJS1) + ar cr libftrsd.a $(OBJS1) + ranlib libftrsd.a + cp libftrsd.a .. + +# Build rsdtest +OBJS2 = rsdtest.o +rsdtest: $(OBJS2) ../libjt.a + $(FC) -o rsdtest $(OBJS2) libftrsd.a ../libjt.a ../libpthreadGC2.a + +ftrsd: ftrsd.o encode_rs_int.o decode_rs_int.o init_rs_int.o + gcc -g -o $@ $^ + +encode_rs_int.o: encode_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +decode_rs_int.o: decode_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +init_rs_int.o: init_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +.PHONY : clean + +clean: + rm -rf *.o libjt.a rsdtest ftrsd diff --git a/lib/ftrsd/Makefile.sfrsd b/lib/ftrsd/Makefile.sfrsd index fe859532..3f68f7ed 100755 --- a/lib/ftrsd/Makefile.sfrsd +++ b/lib/ftrsd/Makefile.sfrsd @@ -1,30 +1,30 @@ -srcdir = . -prefix = /usr/local -exec_prefix=${prefix} -CC=gcc - -CFLAGS=-I/usr/local/include -Wall -O2 - -all: encode_rs_int.o decode_rs_int.o init_rs_int.o sfrsd2.o sfrsd.o sfrsd - -encode_rs_int.o: encode_rs.c - gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ - -decode_rs_int.o: decode_rs.c - gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ - -init_rs_int.o: init_rs.c - gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ - -sfrsd2.o: sfrsd2.c - gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ - -sfrsd.o: sfrsd.c - gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ - -sfrsd: sfrsd.o encode_rs_int.o decode_rs_int.o init_rs_int.o sfrsd2.o - gcc -g -o $@ $^ - -clean: - rm -f *.o *.a sfrsd - +srcdir = . +prefix = /usr/local +exec_prefix=${prefix} +CC=gcc + +CFLAGS=-I/usr/local/include -Wall -O2 + +all: encode_rs_int.o decode_rs_int.o init_rs_int.o sfrsd2.o sfrsd.o sfrsd + +encode_rs_int.o: encode_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +decode_rs_int.o: decode_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +init_rs_int.o: init_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +sfrsd2.o: sfrsd2.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +sfrsd.o: sfrsd.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +sfrsd: sfrsd.o encode_rs_int.o decode_rs_int.o init_rs_int.o sfrsd2.o + gcc -g -o $@ $^ + +clean: + rm -f *.o *.a sfrsd + diff --git a/lib/ftrsd/Makefile.sfrsd3 b/lib/ftrsd/Makefile.sfrsd3 index 2e4d1900..93023f31 100755 --- a/lib/ftrsd/Makefile.sfrsd3 +++ b/lib/ftrsd/Makefile.sfrsd3 @@ -1,38 +1,38 @@ -# Makefile for Windows in JTSDK-PY environment - -# Re-direct stdout and stderr: cmd.exe bash -# make > junk 2>&1 make &> junk - -CC = gcc -FC = gfortran - -FFLAGS = -O2 -DWIN32 -fbounds-check -fno-second-underscore -Wall \ - -Wno-conversion -Wno-character-truncation -CFLAGS = -I. -DWIN32 -DWin32 -DBIGSYM -DHAVE_STRUCT_TIMESPEC - -# 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: rsdtest - -# Build rsdtest -OBJS2 = rsdtest.o extract2.o demod64b.o sfrsd3.o -rsdtest: $(OBJS2) ../libjt.a - $(FC) -o rsdtest $(OBJS2) ../libjt.a ../libpthreadGC2.a - -sfrsd: sfrsd.o encode_rs_int.o decode_rs_int.o init_rs_int.o - gcc -g -o $@ $^ - -.PHONY : clean - -clean: - rm -rf *.o libjt.a rsdtest sfrsd +# Makefile for Windows in JTSDK-PY environment + +# Re-direct stdout and stderr: cmd.exe bash +# make > junk 2>&1 make &> junk + +CC = gcc +FC = gfortran + +FFLAGS = -O2 -DWIN32 -fbounds-check -fno-second-underscore -Wall \ + -Wno-conversion -Wno-character-truncation +CFLAGS = -I. -DWIN32 -DWin32 -DBIGSYM -DHAVE_STRUCT_TIMESPEC + +# 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: rsdtest + +# Build rsdtest +OBJS2 = rsdtest.o extract2.o demod64b.o sfrsd3.o +rsdtest: $(OBJS2) ../libjt.a + $(FC) -o rsdtest $(OBJS2) ../libjt.a ../libpthreadGC2.a + +sfrsd: sfrsd.o encode_rs_int.o decode_rs_int.o init_rs_int.o + gcc -g -o $@ $^ + +.PHONY : clean + +clean: + rm -rf *.o libjt.a rsdtest sfrsd diff --git a/lib/ftrsd/decode_rs.c b/lib/ftrsd/decode_rs.c index 04e26825..990b687a 100755 --- a/lib/ftrsd/decode_rs.c +++ b/lib/ftrsd/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 -#endif - -#include -#include - -#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 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 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 +#endif + +#include +#include + +#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 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 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 - -#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 + +#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 -#include -#include -#include -#include -#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= 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 +#include +#include +#include +#include +#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= 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/lib/ftrsd/ftrsd_paper/Makefile b/lib/ftrsd/ftrsd_paper/Makefile index 924948ab..a594397a 100755 --- a/lib/ftrsd/ftrsd_paper/Makefile +++ b/lib/ftrsd/ftrsd_paper/Makefile @@ -1,40 +1,40 @@ -CC = gcc -FC = gfortran - -# 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: mfsk probs.out - -OBJS1 = prob.o binomial_subs.o -prob: $(OBJS1) - $(FC) -o prob $(OBJS1) - -OBJS2 = mfsk.o binomial_subs.o -mfsk: $(OBJS2) - $(FC) -o mfsk $(OBJS2) - -OBJS3 = bodide.o binomial_subs.o -bodide: $(OBJS3) - $(FC) -o bodide $(OBJS3) - - -probs.out: prob -# x N X s - prob 35 63 40 40 > probs.out - prob 37 63 40 45 >> probs.out - prob 37 53 40 45 >> probs.out - prob 38 53 40 47 >> probs.out - -clean: - rm -rf *.o prob probs.out - +CC = gcc +FC = gfortran + +# 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: mfsk probs.out + +OBJS1 = prob.o binomial_subs.o +prob: $(OBJS1) + $(FC) -o prob $(OBJS1) + +OBJS2 = mfsk.o binomial_subs.o +mfsk: $(OBJS2) + $(FC) -o mfsk $(OBJS2) + +OBJS3 = bodide.o binomial_subs.o +bodide: $(OBJS3) + $(FC) -o bodide $(OBJS3) + + +probs.out: prob +# x N X s + prob 35 63 40 40 > probs.out + prob 37 63 40 45 >> probs.out + prob 37 53 40 45 >> probs.out + prob 38 53 40 47 >> probs.out + +clean: + rm -rf *.o prob probs.out + diff --git a/lib/ftrsd/ftrsd_paper/binomial.c b/lib/ftrsd/ftrsd_paper/binomial.c index c4180250..fcbdafd9 100755 --- a/lib/ftrsd/ftrsd_paper/binomial.c +++ b/lib/ftrsd/ftrsd_paper/binomial.c @@ -1,69 +1,69 @@ -#include -#include - -/* Original code copied from - http://rosettacode.org/wiki/Evaluate_binomial_coefficients -*/ - -/* We go to some effort to handle overflow situations */ - -static unsigned long gcd_ui(unsigned long x, unsigned long y) { - unsigned long t; - if (y < x) { t = x; x = y; y = t; } - while (y > 0) { - t = y; y = x % y; x = t; /* y1 <- x0 % y0 ; x1 <- y0 */ - } - return x; -} - -unsigned long binomial(unsigned long n, unsigned long k) { - unsigned long d, g, r = 1; - if (k == 0) return 1; - if (k == 1) return n; - if (k >= n) return (k == n); - if (k > n/2) k = n-k; - for (d = 1; d <= k; d++) { - if (r >= ULONG_MAX/n) { /* Possible overflow */ - unsigned long nr, dr; /* reduced numerator / denominator */ - g = gcd_ui(n, d); nr = n/g; dr = d/g; - g = gcd_ui(r, dr); r = r/g; dr = dr/g; - if (r >= ULONG_MAX/nr) return 0; /* Unavoidable overflow */ - r *= nr; - r /= dr; - n--; - } else { - r *= n--; - r /= d; - } - } - return r; -} - -int main() { - - //Get test results - printf("%lu\n", binomial(5, 3)); // 10 - printf("%lu\n", binomial(40, 19)); // 131282408400 - printf("%lu\n", binomial(67, 31)); // 11923179284862717872 - - // Compute special cases for paper on TF soft-decision RS decoder: - double a,b,c,p; - a=(double)binomial(40, 35); - b=(double)binomial(23, 5); - c=(double)binomial(63, 40); - p=a*b/c; - printf("%e %e %e %e\n",a,b,c,p); - - a=(double)binomial(40, 36); - b=(double)binomial(23, 4); - c=(double)binomial(63, 40); - p=a*b/c; - printf("%e %e %e %e\n",a,b,c,p); - - a=(double)binomial(40, 37); - b=(double)binomial(23, 8); - c=(double)binomial(63, 45); - p=a*b/c; - printf("%e %e %e %e\n",a,b,c,p); - return 0; -} +#include +#include + +/* Original code copied from + http://rosettacode.org/wiki/Evaluate_binomial_coefficients +*/ + +/* We go to some effort to handle overflow situations */ + +static unsigned long gcd_ui(unsigned long x, unsigned long y) { + unsigned long t; + if (y < x) { t = x; x = y; y = t; } + while (y > 0) { + t = y; y = x % y; x = t; /* y1 <- x0 % y0 ; x1 <- y0 */ + } + return x; +} + +unsigned long binomial(unsigned long n, unsigned long k) { + unsigned long d, g, r = 1; + if (k == 0) return 1; + if (k == 1) return n; + if (k >= n) return (k == n); + if (k > n/2) k = n-k; + for (d = 1; d <= k; d++) { + if (r >= ULONG_MAX/n) { /* Possible overflow */ + unsigned long nr, dr; /* reduced numerator / denominator */ + g = gcd_ui(n, d); nr = n/g; dr = d/g; + g = gcd_ui(r, dr); r = r/g; dr = dr/g; + if (r >= ULONG_MAX/nr) return 0; /* Unavoidable overflow */ + r *= nr; + r /= dr; + n--; + } else { + r *= n--; + r /= d; + } + } + return r; +} + +int main() { + + //Get test results + printf("%lu\n", binomial(5, 3)); // 10 + printf("%lu\n", binomial(40, 19)); // 131282408400 + printf("%lu\n", binomial(67, 31)); // 11923179284862717872 + + // Compute special cases for paper on TF soft-decision RS decoder: + double a,b,c,p; + a=(double)binomial(40, 35); + b=(double)binomial(23, 5); + c=(double)binomial(63, 40); + p=a*b/c; + printf("%e %e %e %e\n",a,b,c,p); + + a=(double)binomial(40, 36); + b=(double)binomial(23, 4); + c=(double)binomial(63, 40); + p=a*b/c; + printf("%e %e %e %e\n",a,b,c,p); + + a=(double)binomial(40, 37); + b=(double)binomial(23, 8); + c=(double)binomial(63, 45); + p=a*b/c; + printf("%e %e %e %e\n",a,b,c,p); + return 0; +} diff --git a/lib/ftrsd/ftrsd_paper/binomial_subs.c b/lib/ftrsd/ftrsd_paper/binomial_subs.c index e32f5046..be4a0ae5 100755 --- a/lib/ftrsd/ftrsd_paper/binomial_subs.c +++ b/lib/ftrsd/ftrsd_paper/binomial_subs.c @@ -1,55 +1,55 @@ -#include -#include - -/* Original code copied from - http://rosettacode.org/wiki/Evaluate_binomial_coefficients -*/ - -/* We go to some effort to handle overflow situations */ - -static unsigned long long gcd_ui(unsigned long long x, unsigned long long y) { - unsigned long long t; - if (y < x) { t = x; x = y; y = t; } - while (y > 0) { - t = y; y = x % y; x = t; /* y1 <- x0 % y0 ; x1 <- y0 */ - } - return x; -} - -unsigned long long binomial(unsigned long long n, unsigned long long k) { - unsigned long long d, g, r = 1; - if (k == 0) return 1; - if (k == 1) return n; - if (k >= n) return (k == n); - if (k > n/2) k = n-k; - for (d = 1; d <= k; d++) { - if (r >= ULLONG_MAX/n) { /* Possible overflow */ - unsigned long long nr, dr; /* reduced numerator / denominator */ - g = gcd_ui(n, d); nr = n/g; dr = d/g; - g = gcd_ui(r, dr); r = r/g; dr = dr/g; - if (r >= ULLONG_MAX/nr) return 0; /* Unavoidable overflow */ - r *= nr; - r /= dr; - n--; - } else { - r *= n--; - r /= d; - } - } - return r; -} - -unsigned long long binomial_(int *n, int *k) -{ - // printf("n=%d k=%d %lu\n",*n,*k,binomial(*n,*k)); - return binomial(*n,*k); -} - -double hypergeo_(int *x, int *NN, int *XX, int *s) -{ - double a,b,c; - a=(double)binomial(*XX, *x); - b=(double)binomial(*NN-*XX, *s-*x); - c=(double)binomial(*NN, *s); - return a*b/c; -} +#include +#include + +/* Original code copied from + http://rosettacode.org/wiki/Evaluate_binomial_coefficients +*/ + +/* We go to some effort to handle overflow situations */ + +static unsigned long long gcd_ui(unsigned long long x, unsigned long long y) { + unsigned long long t; + if (y < x) { t = x; x = y; y = t; } + while (y > 0) { + t = y; y = x % y; x = t; /* y1 <- x0 % y0 ; x1 <- y0 */ + } + return x; +} + +unsigned long long binomial(unsigned long long n, unsigned long long k) { + unsigned long long d, g, r = 1; + if (k == 0) return 1; + if (k == 1) return n; + if (k >= n) return (k == n); + if (k > n/2) k = n-k; + for (d = 1; d <= k; d++) { + if (r >= ULLONG_MAX/n) { /* Possible overflow */ + unsigned long long nr, dr; /* reduced numerator / denominator */ + g = gcd_ui(n, d); nr = n/g; dr = d/g; + g = gcd_ui(r, dr); r = r/g; dr = dr/g; + if (r >= ULLONG_MAX/nr) return 0; /* Unavoidable overflow */ + r *= nr; + r /= dr; + n--; + } else { + r *= n--; + r /= d; + } + } + return r; +} + +unsigned long long binomial_(int *n, int *k) +{ + // printf("n=%d k=%d %lu\n",*n,*k,binomial(*n,*k)); + return binomial(*n,*k); +} + +double hypergeo_(int *x, int *NN, int *XX, int *s) +{ + double a,b,c; + a=(double)binomial(*XX, *x); + b=(double)binomial(*NN-*XX, *s-*x); + c=(double)binomial(*NN, *s); + return a*b/c; +} diff --git a/lib/ftrsd/ftrsd_paper/bmdata-rf.dat b/lib/ftrsd/ftrsd_paper/bmdata-rf.dat index 443804be..17d53312 100755 --- a/lib/ftrsd/ftrsd_paper/bmdata-rf.dat +++ b/lib/ftrsd/ftrsd_paper/bmdata-rf.dat @@ -1,11 +1,11 @@ -fspread0 0.2, BM (ntrials=0) --22.0 0.09 --21.5 0.20 --21.0 0.36 --20.5 0.55 --20.0 0.69 --19.5 0.83 --19.0 0.91 --18.5 0.960 --18.0 0.978 --17.5 0.987 +fspread0 0.2, BM (ntrials=0) +-22.0 0.09 +-21.5 0.20 +-21.0 0.36 +-20.5 0.55 +-20.0 0.69 +-19.5 0.83 +-19.0 0.91 +-18.5 0.960 +-18.0 0.978 +-17.5 0.987 diff --git a/lib/ftrsd/ftrsd_paper/bmdata.dat b/lib/ftrsd/ftrsd_paper/bmdata.dat index 053c9024..987bbbba 100755 --- a/lib/ftrsd/ftrsd_paper/bmdata.dat +++ b/lib/ftrsd/ftrsd_paper/bmdata.dat @@ -1,8 +1,8 @@ --24.5 0.000 --24.0 0.006 --23.5 0.046 0.066 --23.0 0.250 0.305 --22.5 0.630 0.701 --22.0 0.900 0.945 --21.5 0.992 0.9974 --21.0 0.99987 +-24.5 0.000 +-24.0 0.006 +-23.5 0.046 0.066 +-23.0 0.250 0.305 +-22.5 0.630 0.701 +-22.0 0.900 0.945 +-21.5 0.992 0.9974 +-21.0 0.99987 diff --git a/lib/ftrsd/ftrsd_paper/bmtheory25.dat b/lib/ftrsd/ftrsd_paper/bmtheory25.dat index cd5bac0f..de854562 100755 --- a/lib/ftrsd/ftrsd_paper/bmtheory25.dat +++ b/lib/ftrsd/ftrsd_paper/bmtheory25.dat @@ -1,43 +1,43 @@ -Es/No P(word error) ----------------------- - 0.0 0.9008E+00 0.1000E+01 - 0.5 0.8877E+00 0.1000E+01 - 1.0 0.8724E+00 0.1000E+01 - 1.5 0.8545E+00 0.1000E+01 - 2.0 0.8338E+00 0.1000E+01 - 2.5 0.8096E+00 0.1000E+01 - 3.0 0.7817E+00 0.1000E+01 - 3.5 0.7496E+00 0.1000E+01 - 4.0 0.7128E+00 0.1000E+01 - 4.5 0.6712E+00 0.1000E+01 - 5.0 0.6246E+00 0.9998E+00 - 5.5 0.5731E+00 0.9964E+00 - 6.0 0.5170E+00 0.9629E+00 - 6.5 0.4572E+00 0.7979E+00 - 7.0 0.3949E+00 0.4327E+00 - 7.5 0.3316E+00 0.1100E+00 - 8.0 0.2696E+00 0.9707E-02 - 8.5 0.2109E+00 0.2303E-03 - 9.0 0.1578E+00 0.1170E-05 - 9.5 0.1121E+00 0.1027E-08 -10.0 0.7499E-01 0.1263E-12 -10.5 0.4684E-01 0.1768E-17 -11.0 0.2703E-01 0.2282E-23 -11.5 0.1426E-01 0.2200E-30 -12.0 0.6789E-02 -.1348E-32 -12.5 0.2879E-02 -.1733E-32 -13.0 0.1072E-02 -.2119E-32 -13.5 0.3448E-03 0.3081E-32 -14.0 0.9421E-04 0.3852E-33 -14.5 0.2148E-04 -.1156E-32 -15.0 0.4006E-05 -.1733E-32 -15.5 0.5984E-06 0.2215E-32 -16.0 0.6994E-07 -.4430E-32 -16.5 0.6230E-08 -.3081E-32 -17.0 0.4105E-09 -.2889E-32 -17.5 0.1934E-10 -.1926E-33 -18.0 0.6266E-12 0.3852E-32 -18.5 0.1335E-13 -.1926E-33 -19.0 0.1777E-15 0.2119E-32 -19.5 0.1396E-17 0.1733E-32 -20.0 0.6076E-20 -.3852E-33 +Es/No P(word error) +---------------------- + 0.0 0.9008E+00 0.1000E+01 + 0.5 0.8877E+00 0.1000E+01 + 1.0 0.8724E+00 0.1000E+01 + 1.5 0.8545E+00 0.1000E+01 + 2.0 0.8338E+00 0.1000E+01 + 2.5 0.8096E+00 0.1000E+01 + 3.0 0.7817E+00 0.1000E+01 + 3.5 0.7496E+00 0.1000E+01 + 4.0 0.7128E+00 0.1000E+01 + 4.5 0.6712E+00 0.1000E+01 + 5.0 0.6246E+00 0.9998E+00 + 5.5 0.5731E+00 0.9964E+00 + 6.0 0.5170E+00 0.9629E+00 + 6.5 0.4572E+00 0.7979E+00 + 7.0 0.3949E+00 0.4327E+00 + 7.5 0.3316E+00 0.1100E+00 + 8.0 0.2696E+00 0.9707E-02 + 8.5 0.2109E+00 0.2303E-03 + 9.0 0.1578E+00 0.1170E-05 + 9.5 0.1121E+00 0.1027E-08 +10.0 0.7499E-01 0.1263E-12 +10.5 0.4684E-01 0.1768E-17 +11.0 0.2703E-01 0.2282E-23 +11.5 0.1426E-01 0.2200E-30 +12.0 0.6789E-02 -.1348E-32 +12.5 0.2879E-02 -.1733E-32 +13.0 0.1072E-02 -.2119E-32 +13.5 0.3448E-03 0.3081E-32 +14.0 0.9421E-04 0.3852E-33 +14.5 0.2148E-04 -.1156E-32 +15.0 0.4006E-05 -.1733E-32 +15.5 0.5984E-06 0.2215E-32 +16.0 0.6994E-07 -.4430E-32 +16.5 0.6230E-08 -.3081E-32 +17.0 0.4105E-09 -.2889E-32 +17.5 0.1934E-10 -.1926E-33 +18.0 0.6266E-12 0.3852E-32 +18.5 0.1335E-13 -.1926E-33 +19.0 0.1777E-15 0.2119E-32 +19.5 0.1396E-17 0.1733E-32 +20.0 0.6076E-20 -.3852E-33 diff --git a/lib/ftrsd/ftrsd_paper/bmtheory40.dat b/lib/ftrsd/ftrsd_paper/bmtheory40.dat index 473509d0..4903ef5c 100755 --- a/lib/ftrsd/ftrsd_paper/bmtheory40.dat +++ b/lib/ftrsd/ftrsd_paper/bmtheory40.dat @@ -1,43 +1,43 @@ -Es/No P(word error) ----------------------- - 0.0 0.9008E+00 0.1000E+01 - 0.5 0.8877E+00 0.1000E+01 - 1.0 0.8724E+00 0.1000E+01 - 1.5 0.8545E+00 0.1000E+01 - 2.0 0.8338E+00 0.9999E+00 - 2.5 0.8096E+00 0.9991E+00 - 3.0 0.7817E+00 0.9944E+00 - 3.5 0.7496E+00 0.9713E+00 - 4.0 0.7128E+00 0.8887E+00 - 4.5 0.6712E+00 0.6883E+00 - 5.0 0.6246E+00 0.3865E+00 - 5.5 0.5731E+00 0.1310E+00 - 6.0 0.5170E+00 0.2215E-01 - 6.5 0.4572E+00 0.1536E-02 - 7.0 0.3949E+00 0.3562E-04 - 7.5 0.3316E+00 0.2223E-06 - 8.0 0.2696E+00 0.2951E-09 - 8.5 0.2109E+00 0.6449E-13 - 9.0 0.1578E+00 0.1758E-17 - 9.5 0.1121E+00 0.4426E-23 -10.0 0.7499E-01 0.7428E-30 -10.5 0.4684E-01 -.1733E-32 -11.0 0.2703E-01 0.1348E-32 -11.5 0.1426E-01 0.2985E-32 -12.0 0.6789E-02 -.1348E-32 -12.5 0.2879E-02 -.1733E-32 -13.0 0.1072E-02 -.2119E-32 -13.5 0.3448E-03 0.3081E-32 -14.0 0.9421E-04 0.3852E-33 -14.5 0.2148E-04 -.1156E-32 -15.0 0.4006E-05 -.1733E-32 -15.5 0.5984E-06 0.2215E-32 -16.0 0.6994E-07 -.4430E-32 -16.5 0.6230E-08 -.3081E-32 -17.0 0.4105E-09 -.2889E-32 -17.5 0.1934E-10 -.1926E-33 -18.0 0.6266E-12 0.3852E-32 -18.5 0.1335E-13 -.1926E-33 -19.0 0.1777E-15 0.2119E-32 -19.5 0.1396E-17 0.1733E-32 -20.0 0.6076E-20 -.3852E-33 +Es/No P(word error) +---------------------- + 0.0 0.9008E+00 0.1000E+01 + 0.5 0.8877E+00 0.1000E+01 + 1.0 0.8724E+00 0.1000E+01 + 1.5 0.8545E+00 0.1000E+01 + 2.0 0.8338E+00 0.9999E+00 + 2.5 0.8096E+00 0.9991E+00 + 3.0 0.7817E+00 0.9944E+00 + 3.5 0.7496E+00 0.9713E+00 + 4.0 0.7128E+00 0.8887E+00 + 4.5 0.6712E+00 0.6883E+00 + 5.0 0.6246E+00 0.3865E+00 + 5.5 0.5731E+00 0.1310E+00 + 6.0 0.5170E+00 0.2215E-01 + 6.5 0.4572E+00 0.1536E-02 + 7.0 0.3949E+00 0.3562E-04 + 7.5 0.3316E+00 0.2223E-06 + 8.0 0.2696E+00 0.2951E-09 + 8.5 0.2109E+00 0.6449E-13 + 9.0 0.1578E+00 0.1758E-17 + 9.5 0.1121E+00 0.4426E-23 +10.0 0.7499E-01 0.7428E-30 +10.5 0.4684E-01 -.1733E-32 +11.0 0.2703E-01 0.1348E-32 +11.5 0.1426E-01 0.2985E-32 +12.0 0.6789E-02 -.1348E-32 +12.5 0.2879E-02 -.1733E-32 +13.0 0.1072E-02 -.2119E-32 +13.5 0.3448E-03 0.3081E-32 +14.0 0.9421E-04 0.3852E-33 +14.5 0.2148E-04 -.1156E-32 +15.0 0.4006E-05 -.1733E-32 +15.5 0.5984E-06 0.2215E-32 +16.0 0.6994E-07 -.4430E-32 +16.5 0.6230E-08 -.3081E-32 +17.0 0.4105E-09 -.2889E-32 +17.5 0.1934E-10 -.1926E-33 +18.0 0.6266E-12 0.3852E-32 +18.5 0.1335E-13 -.1926E-33 +19.0 0.1777E-15 0.2119E-32 +19.5 0.1396E-17 0.1733E-32 +20.0 0.6076E-20 -.3852E-33 diff --git a/lib/ftrsd/ftrsd_paper/bmtheory43.dat b/lib/ftrsd/ftrsd_paper/bmtheory43.dat index c0e552be..b22ab8d8 100755 --- a/lib/ftrsd/ftrsd_paper/bmtheory43.dat +++ b/lib/ftrsd/ftrsd_paper/bmtheory43.dat @@ -1,43 +1,43 @@ -Es/No P(word error) ----------------------- - 0.0 0.9008E+00 0.1000E+01 - 0.5 0.8877E+00 0.1000E+01 - 1.0 0.8724E+00 0.9999E+00 - 1.5 0.8545E+00 0.9996E+00 - 2.0 0.8338E+00 0.9977E+00 - 2.5 0.8096E+00 0.9889E+00 - 3.0 0.7817E+00 0.9559E+00 - 3.5 0.7496E+00 0.8599E+00 - 4.0 0.7128E+00 0.6586E+00 - 4.5 0.6712E+00 0.3780E+00 - 5.0 0.6246E+00 0.1397E+00 - 5.5 0.5731E+00 0.2826E-01 - 6.0 0.5170E+00 0.2632E-02 - 6.5 0.4572E+00 0.9396E-04 - 7.0 0.3949E+00 0.1052E-05 - 7.5 0.3316E+00 0.2965E-08 - 8.0 0.2696E+00 0.1650E-11 - 8.5 0.2109E+00 0.1388E-15 - 9.0 0.1578E+00 0.1316E-20 - 9.5 0.1121E+00 0.1021E-26 -10.0 0.7499E-01 -.9630E-33 -10.5 0.4684E-01 -.1733E-32 -11.0 0.2703E-01 0.1348E-32 -11.5 0.1426E-01 0.2985E-32 -12.0 0.6789E-02 -.1348E-32 -12.5 0.2879E-02 -.1733E-32 -13.0 0.1072E-02 -.2119E-32 -13.5 0.3448E-03 0.3081E-32 -14.0 0.9421E-04 0.3852E-33 -14.5 0.2148E-04 -.1156E-32 -15.0 0.4006E-05 -.1733E-32 -15.5 0.5984E-06 0.2215E-32 -16.0 0.6994E-07 -.4430E-32 -16.5 0.6230E-08 -.3081E-32 -17.0 0.4105E-09 -.2889E-32 -17.5 0.1934E-10 -.1926E-33 -18.0 0.6266E-12 0.3852E-32 -18.5 0.1335E-13 -.1926E-33 -19.0 0.1777E-15 0.2119E-32 -19.5 0.1396E-17 0.1733E-32 -20.0 0.6076E-20 -.3852E-33 +Es/No P(word error) +---------------------- + 0.0 0.9008E+00 0.1000E+01 + 0.5 0.8877E+00 0.1000E+01 + 1.0 0.8724E+00 0.9999E+00 + 1.5 0.8545E+00 0.9996E+00 + 2.0 0.8338E+00 0.9977E+00 + 2.5 0.8096E+00 0.9889E+00 + 3.0 0.7817E+00 0.9559E+00 + 3.5 0.7496E+00 0.8599E+00 + 4.0 0.7128E+00 0.6586E+00 + 4.5 0.6712E+00 0.3780E+00 + 5.0 0.6246E+00 0.1397E+00 + 5.5 0.5731E+00 0.2826E-01 + 6.0 0.5170E+00 0.2632E-02 + 6.5 0.4572E+00 0.9396E-04 + 7.0 0.3949E+00 0.1052E-05 + 7.5 0.3316E+00 0.2965E-08 + 8.0 0.2696E+00 0.1650E-11 + 8.5 0.2109E+00 0.1388E-15 + 9.0 0.1578E+00 0.1316E-20 + 9.5 0.1121E+00 0.1021E-26 +10.0 0.7499E-01 -.9630E-33 +10.5 0.4684E-01 -.1733E-32 +11.0 0.2703E-01 0.1348E-32 +11.5 0.1426E-01 0.2985E-32 +12.0 0.6789E-02 -.1348E-32 +12.5 0.2879E-02 -.1733E-32 +13.0 0.1072E-02 -.2119E-32 +13.5 0.3448E-03 0.3081E-32 +14.0 0.9421E-04 0.3852E-33 +14.5 0.2148E-04 -.1156E-32 +15.0 0.4006E-05 -.1733E-32 +15.5 0.5984E-06 0.2215E-32 +16.0 0.6994E-07 -.4430E-32 +16.5 0.6230E-08 -.3081E-32 +17.0 0.4105E-09 -.2889E-32 +17.5 0.1934E-10 -.1926E-33 +18.0 0.6266E-12 0.3852E-32 +18.5 0.1335E-13 -.1926E-33 +19.0 0.1777E-15 0.2119E-32 +19.5 0.1396E-17 0.1733E-32 +20.0 0.6076E-20 -.3852E-33 diff --git a/lib/ftrsd/ftrsd_paper/bodide.f90 b/lib/ftrsd/ftrsd_paper/bodide.f90 index 248cb890..72e0f137 100755 --- a/lib/ftrsd/ftrsd_paper/bodide.f90 +++ b/lib/ftrsd/ftrsd_paper/bodide.f90 @@ -1,54 +1,54 @@ -program bodide -! Compute probability of word error for a bounded distance decoder. -! Hardwired for non-coherent 64-FSK and the JT65 RS (63,12) code on GF(64). -! -! Let ps be symbol error probability. -! The probability of getting an error pattern with e symbol errors is: -! ps^e * (1-ps)*(n-e) -! The number of error patterns with e errors is binomial(63,e) -! Overall probability of getting a word with e errors is: -! P(e)= binomial(63,e)* ps^e * (1-ps)*(n-e) -! Probability that word is correct is P(0 to 25 errors) = sum{e=0}^{25} P(e) -! Probability that word is wrong is 1-P(0 to 25 errors) -! P_word_error=1-( sum_{e=0}^{t} P(e) ) -! - implicit real*16 (a-h,o-z) - - integer*8 binomial - integer x,s,XX,NN,M - character arg*8 - - nargs=iargc() - if(nargs.ne.1) then - print*,'Probability of word error for noncoherent 64-FSK with bounded distance decoding' - print*,'Usage: bounded_distance D' - print*,'Example: bounded_distance 25' - go to 999 - endif - call getarg(1,arg) - read(arg,*) nt - M=64 - write(*,1012) -1012 format('Es/No P(word error)'/ & - '----------------------') - do isnr=0,40 - esno=10**(isnr/2.0/10.0) - hsum=0.d0 - do k=1,M-1 - h=binomial(M-1,k) - h=h*((-1)**(k+1))/(k+1) - h=h*exp(-esno*k/(k+1)) - hsum=hsum + h - enddo - ps=hsum - hsum=0.d0 - do i=0,nt - h=binomial(63,i) - h=h*ps**i - h=h*(1-ps)**(63-i) - hsum=hsum+h - enddo - pw=1-hsum - write(*,'(f4.1,4x,e10.4,4x,e10.4)') isnr/2.0, ps, pw - enddo -999 end program bodide +program bodide +! Compute probability of word error for a bounded distance decoder. +! Hardwired for non-coherent 64-FSK and the JT65 RS (63,12) code on GF(64). +! +! Let ps be symbol error probability. +! The probability of getting an error pattern with e symbol errors is: +! ps^e * (1-ps)*(n-e) +! The number of error patterns with e errors is binomial(63,e) +! Overall probability of getting a word with e errors is: +! P(e)= binomial(63,e)* ps^e * (1-ps)*(n-e) +! Probability that word is correct is P(0 to 25 errors) = sum{e=0}^{25} P(e) +! Probability that word is wrong is 1-P(0 to 25 errors) +! P_word_error=1-( sum_{e=0}^{t} P(e) ) +! + implicit real*16 (a-h,o-z) + + integer*8 binomial + integer x,s,XX,NN,M + character arg*8 + + nargs=iargc() + if(nargs.ne.1) then + print*,'Probability of word error for noncoherent 64-FSK with bounded distance decoding' + print*,'Usage: bounded_distance D' + print*,'Example: bounded_distance 25' + go to 999 + endif + call getarg(1,arg) + read(arg,*) nt + M=64 + write(*,1012) +1012 format('Es/No P(word error)'/ & + '----------------------') + do isnr=0,40 + esno=10**(isnr/2.0/10.0) + hsum=0.d0 + do k=1,M-1 + h=binomial(M-1,k) + h=h*((-1)**(k+1))/(k+1) + h=h*exp(-esno*k/(k+1)) + hsum=hsum + h + enddo + ps=hsum + hsum=0.d0 + do i=0,nt + h=binomial(63,i) + h=h*ps**i + h=h*(1-ps)**(63-i) + hsum=hsum+h + enddo + pw=1-hsum + write(*,'(f4.1,4x,e10.4,4x,e10.4)') isnr/2.0, ps, pw + enddo +999 end program bodide diff --git a/lib/ftrsd/ftrsd_paper/bodide.lab b/lib/ftrsd/ftrsd_paper/bodide.lab index 2847dae9..6fa108e0 100755 --- a/lib/ftrsd/ftrsd_paper/bodide.lab +++ b/lib/ftrsd/ftrsd_paper/bodide.lab @@ -1,4 +1,4 @@ -7.5 0.05 BM -6.9 0.015 Theory -5.55 0.05 KV -5.3 0.005 FT +7.5 0.05 BM +6.9 0.015 Theory +5.55 0.05 KV +5.3 0.005 FT diff --git a/lib/ftrsd/ftrsd_paper/fig_bodide.gnuplot b/lib/ftrsd/ftrsd_paper/fig_bodide.gnuplot index 6c367d0c..b8bb0ada 100755 --- a/lib/ftrsd/ftrsd_paper/fig_bodide.gnuplot +++ b/lib/ftrsd/ftrsd_paper/fig_bodide.gnuplot @@ -1,24 +1,24 @@ -# gnuplot script for comparison to theoretical word error rate for -# bounded distance decoding - -# run: gnuplot fig_bodide.gnuplot -# then: pdflatex fig_bodide.tex - -set term epslatex standalone size 6in,2*6/3in -set output "fig_bodide.tex" -set xlabel "$E_b/N_0$ (dB)" -set ylabel "Word Error Rate" -set style func linespoints -set key off -set tics in -set mxtics 2 -set mytics 10 -set grid -set logscale y -plot [3:9] [1e-4:1] \ - "bmdata.dat" using ($1+29.1):(1-$2) with linespoints lt 2 lw 2 pt 2, \ - "ftdata-100000.dat" using ($1+29.1):(1-$3) with linespoints lt 1 lw 2 pt 7, \ - "bmtheory25.dat" using ($1-0.6):3 with linespoints lt 1 pt 5, \ - "kvasd-15.dat" using ($1+29.1):(1-$3) with linespoints lt 4 pt 6, \ - "bodide.lab" with labels - +# gnuplot script for comparison to theoretical word error rate for +# bounded distance decoding + +# run: gnuplot fig_bodide.gnuplot +# then: pdflatex fig_bodide.tex + +set term epslatex standalone size 6in,2*6/3in +set output "fig_bodide.tex" +set xlabel "$E_b/N_0$ (dB)" +set ylabel "Word Error Rate" +set style func linespoints +set key off +set tics in +set mxtics 2 +set mytics 10 +set grid +set logscale y +plot [3:9] [1e-4:1] \ + "bmdata.dat" using ($1+29.1):(1-$2) with linespoints lt 2 lw 2 pt 2, \ + "ftdata-100000.dat" using ($1+29.1):(1-$3) with linespoints lt 1 lw 2 pt 7, \ + "bmtheory25.dat" using ($1-0.6):3 with linespoints lt 1 pt 5, \ + "kvasd-15.dat" using ($1+29.1):(1-$3) with linespoints lt 4 pt 6, \ + "bodide.lab" with labels + diff --git a/lib/ftrsd/ftrsd_paper/fig_ntrials_vs_nhard.gnuplot b/lib/ftrsd/ftrsd_paper/fig_ntrials_vs_nhard.gnuplot index febcb993..9a6c9b08 100755 --- a/lib/ftrsd/ftrsd_paper/fig_ntrials_vs_nhard.gnuplot +++ b/lib/ftrsd/ftrsd_paper/fig_ntrials_vs_nhard.gnuplot @@ -1,14 +1,14 @@ -# gnuplot script for "ntrials_vs_nhard" figure -# run: gnuplot fig_ntrials_vs_nhard.gnuplot -# then: pdflatex fig_ntrials_vs_nhard.tex -# -set term epslatex standalone size 6in,2*6/3in -set output "fig_ntrials_vs_nhard.tex" -set xlabel "Errors in received word, $X$" -set ylabel "Number of trials" -set tics in -set mxtics 5 -set mytics 10 -#set grid -set logscale y -plot "stats-100000-24db-3.dat" using 1:4 pt 12 notitle +# gnuplot script for "ntrials_vs_nhard" figure +# run: gnuplot fig_ntrials_vs_nhard.gnuplot +# then: pdflatex fig_ntrials_vs_nhard.tex +# +set term epslatex standalone size 6in,2*6/3in +set output "fig_ntrials_vs_nhard.tex" +set xlabel "Errors in received word, $X$" +set ylabel "Number of trials" +set tics in +set mxtics 5 +set mytics 10 +#set grid +set logscale y +plot "stats-100000-24db-3.dat" using 1:4 pt 12 notitle diff --git a/lib/ftrsd/ftrsd_paper/fig_psuccess.gnuplot b/lib/ftrsd/ftrsd_paper/fig_psuccess.gnuplot index 785925c1..3718e29f 100755 --- a/lib/ftrsd/ftrsd_paper/fig_psuccess.gnuplot +++ b/lib/ftrsd/ftrsd_paper/fig_psuccess.gnuplot @@ -1,25 +1,25 @@ -# gnuplot script for "Percent copy" figure -# run: gnuplot fig_psuccess.gnuplot -# then: pdflatex fig_psuccess.tex -# -set term epslatex standalone size 6in,4in -set output "fig_psuccess.tex" -set xlabel "SNR in 2500 Hz Bandwidth (dB)" -set ylabel "Percent copy" -set style func linespoints -set key off -set tics in -set mxtics 2 -set mytics 2 -set grid -plot [-30:-18] [0:105] \ - "stats_0.0" using 1:($4)/10.0 with linespoints lt 2 lw 2 pt 2, \ - "stats_0.0" using 1:($5)/10.0 with linespoints lt 1 lw 2 pt 3, \ - "stats_0.0" using 1:($6)/10.0 with linespoints lt 3 lw 2 pt 4, \ - "stats_0.2" using 1:($4)/10.0 with linespoints lt 2 pt 2, \ - "stats_0.2" using 1:($5)/10.0 with linespoints lt 1 pt 3, \ - "stats_0.2" using 1:($6)/10.0 with linespoints lt 3 pt 4, \ - "stats_1.0" using 1:($4)/10.0 with linespoints lt 2 pt 2, \ - "stats_1.0" using 1:($5)/10.0 with linespoints lt 1 pt 3, \ - "stats_1.0" using 1:($6)/10.0 with linespoints lt 3 pt 4, \ - "psuccess.lab" with labels +# gnuplot script for "Percent copy" figure +# run: gnuplot fig_psuccess.gnuplot +# then: pdflatex fig_psuccess.tex +# +set term epslatex standalone size 6in,4in +set output "fig_psuccess.tex" +set xlabel "SNR in 2500 Hz Bandwidth (dB)" +set ylabel "Percent copy" +set style func linespoints +set key off +set tics in +set mxtics 2 +set mytics 2 +set grid +plot [-30:-18] [0:105] \ + "stats_0.0" using 1:($4)/10.0 with linespoints lt 2 lw 2 pt 2, \ + "stats_0.0" using 1:($5)/10.0 with linespoints lt 1 lw 2 pt 3, \ + "stats_0.0" using 1:($6)/10.0 with linespoints lt 3 lw 2 pt 4, \ + "stats_0.2" using 1:($4)/10.0 with linespoints lt 2 pt 2, \ + "stats_0.2" using 1:($5)/10.0 with linespoints lt 1 pt 3, \ + "stats_0.2" using 1:($6)/10.0 with linespoints lt 3 pt 4, \ + "stats_1.0" using 1:($4)/10.0 with linespoints lt 2 pt 2, \ + "stats_1.0" using 1:($5)/10.0 with linespoints lt 1 pt 3, \ + "stats_1.0" using 1:($6)/10.0 with linespoints lt 3 pt 4, \ + "psuccess.lab" with labels diff --git a/lib/ftrsd/ftrsd_paper/fig_wer.gnuplot b/lib/ftrsd/ftrsd_paper/fig_wer.gnuplot index 7a312743..bff05333 100755 --- a/lib/ftrsd/ftrsd_paper/fig_wer.gnuplot +++ b/lib/ftrsd/ftrsd_paper/fig_wer.gnuplot @@ -1,23 +1,23 @@ -# gnuplot script for "Percent copy" figure -# run: gnuplot fig_wer.gnuplot -# then: pdflatex fig_wer.tex -# -set term epslatex standalone size 6in,4in -set output "fig_wer.tex" -set xlabel "$E_b/N_0$ (dB)" -set ylabel "Word Error Rate" -set style func linespoints -set key off -set tics in -set mxtics 2 -set mytics 10 -set grid -set logscale y -plot [3:7] "ftdata-100000.dat" using ($1+29.1):(1-$2) with linespoints lt 1 pt 7 title 'FT-100K', \ - "ftdata-10000.dat" using ($1+29.1):(1-$2) with linespoints lt 1 pt 7 title 'FT-10K', \ - "ftdata-1000.dat" using ($1+29.1):(1-$2) with linespoints lt 1 pt 7 title 'FT-1K', \ - "kvasd-8.dat" using ($1+29.1):(1-$2) with linespoints lt 2 pt 8 title 'KV-8', \ - "kvasd-12.dat" using ($1+29.1):(1-$2) with linespoints lt 2 pt 8 title 'KV-12', \ - "kvasd-15.dat" using ($1+29.1):(1-$2) with linespoints lt 2 pt 8 title 'KV-15', \ - "bmdata.dat" using ($1+29.1):(1-$2) with linespoints pt 7 title 'BM', \ - "wer.lab" with labels +# gnuplot script for "Percent copy" figure +# run: gnuplot fig_wer.gnuplot +# then: pdflatex fig_wer.tex +# +set term epslatex standalone size 6in,4in +set output "fig_wer.tex" +set xlabel "$E_b/N_0$ (dB)" +set ylabel "Word Error Rate" +set style func linespoints +set key off +set tics in +set mxtics 2 +set mytics 10 +set grid +set logscale y +plot [3:7] "ftdata-100000.dat" using ($1+29.1):(1-$2) with linespoints lt 1 pt 7 title 'FT-100K', \ + "ftdata-10000.dat" using ($1+29.1):(1-$2) with linespoints lt 1 pt 7 title 'FT-10K', \ + "ftdata-1000.dat" using ($1+29.1):(1-$2) with linespoints lt 1 pt 7 title 'FT-1K', \ + "kvasd-8.dat" using ($1+29.1):(1-$2) with linespoints lt 2 pt 8 title 'KV-8', \ + "kvasd-12.dat" using ($1+29.1):(1-$2) with linespoints lt 2 pt 8 title 'KV-12', \ + "kvasd-15.dat" using ($1+29.1):(1-$2) with linespoints lt 2 pt 8 title 'KV-15', \ + "bmdata.dat" using ($1+29.1):(1-$2) with linespoints pt 7 title 'BM', \ + "wer.lab" with labels diff --git a/lib/ftrsd/ftrsd_paper/fig_wer2.gnuplot b/lib/ftrsd/ftrsd_paper/fig_wer2.gnuplot index b79bf3a7..dc8edc98 100755 --- a/lib/ftrsd/ftrsd_paper/fig_wer2.gnuplot +++ b/lib/ftrsd/ftrsd_paper/fig_wer2.gnuplot @@ -1,23 +1,23 @@ -# gnuplot script for "Percent copy" figure -# run: gnuplot fig_wer2.gnuplot -# then: pdflatex fig_wer2.tex -# -set term epslatex standalone size 6in,6*2/3in -set output "fig_wer2.tex" -set xlabel "SNR in 2500 Hz Bandwidth (dB)" -set ylabel "Percent Copy" -set style func linespoints -set key off -set tics in -set mxtics 2 -set mytics 5 -set grid -plot [-27:-22] [0:110] \ - "ftdata-100000.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ - "ftdata-10000.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ - "ftdata-1000.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ - "ftdata-100.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ - "ftdata-10.dat" using 1:(100*$2) with linespoints lt 1 lw 2 pt 7, \ - "kvasd-15.dat" using 1:(100*$2) with linespoints lt 4 pt 6, \ - "bmdata.dat" using 1:(100*$2) with linespoints lt 2 lw 2 pt 2, \ - "wer2.lab" with labels +# gnuplot script for "Percent copy" figure +# run: gnuplot fig_wer2.gnuplot +# then: pdflatex fig_wer2.tex +# +set term epslatex standalone size 6in,6*2/3in +set output "fig_wer2.tex" +set xlabel "SNR in 2500 Hz Bandwidth (dB)" +set ylabel "Percent Copy" +set style func linespoints +set key off +set tics in +set mxtics 2 +set mytics 5 +set grid +plot [-27:-22] [0:110] \ + "ftdata-100000.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ + "ftdata-10000.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ + "ftdata-1000.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ + "ftdata-100.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ + "ftdata-10.dat" using 1:(100*$2) with linespoints lt 1 lw 2 pt 7, \ + "kvasd-15.dat" using 1:(100*$2) with linespoints lt 4 pt 6, \ + "bmdata.dat" using 1:(100*$2) with linespoints lt 2 lw 2 pt 2, \ + "wer2.lab" with labels diff --git a/lib/ftrsd/ftrsd_paper/fig_wer3.gnuplot b/lib/ftrsd/ftrsd_paper/fig_wer3.gnuplot index 605ef777..f3c9d273 100755 --- a/lib/ftrsd/ftrsd_paper/fig_wer3.gnuplot +++ b/lib/ftrsd/ftrsd_paper/fig_wer3.gnuplot @@ -1,21 +1,21 @@ -# gnuplot script for "Percent copy" figure -# run: gnuplot fig_wer3.gnuplot -# then: pdflatex fig_wer3.tex -# -set term epslatex standalone size 6in,6*2/3in -set output "fig_wer3.tex" -set xlabel "SNR in 2500 Hz Bandwidth (dB)" -set ylabel "Percent Copy" -set style func linespoints -set key off -set tics in -set mxtics 2 -set mytics 10 -set grid -set label "r6315" at -25.25,30 -set label "r6330" at -26.0,30 -set label "$T=10^5$" at -22.8,15 -set label "$d=0.0$" at -22.8,10 -plot [-27:-22] [0:110] \ - "ftdata-100000.dat" using 1:(100*$3) with linespoints lt 1 pt 7 title 'FT-100K', \ - "ftdata-100000.dat" using 1:(100*$2) with linespoints lt 1 pt 7 title 'FT-100K' +# gnuplot script for "Percent copy" figure +# run: gnuplot fig_wer3.gnuplot +# then: pdflatex fig_wer3.tex +# +set term epslatex standalone size 6in,6*2/3in +set output "fig_wer3.tex" +set xlabel "SNR in 2500 Hz Bandwidth (dB)" +set ylabel "Percent Copy" +set style func linespoints +set key off +set tics in +set mxtics 2 +set mytics 10 +set grid +set label "r6315" at -25.25,30 +set label "r6330" at -26.0,30 +set label "$T=10^5$" at -22.8,15 +set label "$d=0.0$" at -22.8,10 +plot [-27:-22] [0:110] \ + "ftdata-100000.dat" using 1:(100*$3) with linespoints lt 1 pt 7 title 'FT-100K', \ + "ftdata-100000.dat" using 1:(100*$2) with linespoints lt 1 pt 7 title 'FT-100K' diff --git a/lib/ftrsd/ftrsd_paper/ftdata-10.dat b/lib/ftrsd/ftrsd_paper/ftdata-10.dat index cd72a7c7..467be382 100755 --- a/lib/ftrsd/ftrsd_paper/ftdata-10.dat +++ b/lib/ftrsd/ftrsd_paper/ftdata-10.dat @@ -1,10 +1,10 @@ - snr psuccess ntrials 10, r6321, r6333 --26.0 0.0 --25.5 0.007 --25.0 0.039 --24.5 0.157 0.14 --24.0 0.362 --23.5 0.701 0.681 --23.0 0.914 --22.5 0.985 0.988 --22.0 1.0 1.0 + snr psuccess ntrials 10, r6321, r6333 +-26.0 0.0 +-25.5 0.007 +-25.0 0.039 +-24.5 0.157 0.14 +-24.0 0.362 +-23.5 0.701 0.681 +-23.0 0.914 +-22.5 0.985 0.988 +-22.0 1.0 1.0 diff --git a/lib/ftrsd/ftrsd_paper/ftdata-100.dat b/lib/ftrsd/ftrsd_paper/ftdata-100.dat index 80365aed..a5d547c3 100755 --- a/lib/ftrsd/ftrsd_paper/ftdata-100.dat +++ b/lib/ftrsd/ftrsd_paper/ftdata-100.dat @@ -1,10 +1,10 @@ - snr psuccess ntrials 100, r6321, r6333 --26.0 0.003 0.003 --25.5 0.033 0.037 --25.0 0.113 0.113 --24.5 0.315 0.330 --24.0 0.635 0.670 --23.5 0.908 0.903 --23.0 0.977 0.984 --22.5 0.9986 0.999 --22.0 1.0 1.0 + snr psuccess ntrials 100, r6321, r6333 +-26.0 0.003 0.003 +-25.5 0.033 0.037 +-25.0 0.113 0.113 +-24.5 0.315 0.330 +-24.0 0.635 0.670 +-23.5 0.908 0.903 +-23.0 0.977 0.984 +-22.5 0.9986 0.999 +-22.0 1.0 1.0 diff --git a/lib/ftrsd/ftrsd_paper/ftdata-1000.dat b/lib/ftrsd/ftrsd_paper/ftdata-1000.dat index 2d1dd2b1..156a0b3b 100755 --- a/lib/ftrsd/ftrsd_paper/ftdata-1000.dat +++ b/lib/ftrsd/ftrsd_paper/ftdata-1000.dat @@ -1,9 +1,9 @@ - snr psuccess ntrials 1000, r6315, r6333 --26.0 0.010 0.022 --25.5 0.052 0.097 --25.0 0.22 0.262 --24.5 0.51 0.535 --24.0 0.80 0.844 --23.5 0.956 0.968 --23.0 0.9958 0.9963 --22.5 1.0 1.0 + snr psuccess ntrials 1000, r6315, r6333 +-26.0 0.010 0.022 +-25.5 0.052 0.097 +-25.0 0.22 0.262 +-24.5 0.51 0.535 +-24.0 0.80 0.844 +-23.5 0.956 0.968 +-23.0 0.9958 0.9963 +-22.5 1.0 1.0 diff --git a/lib/ftrsd/ftrsd_paper/ftdata-10000.dat b/lib/ftrsd/ftrsd_paper/ftdata-10000.dat index b6f15ca1..99d48597 100755 --- a/lib/ftrsd/ftrsd_paper/ftdata-10000.dat +++ b/lib/ftrsd/ftrsd_paper/ftdata-10000.dat @@ -1,11 +1,11 @@ - snr psuccess ntrials 10000 r6315, r6330 --27.0 0.000 0.001 --26.5 0.004 0.014 --26.0 0.03 0.066 --25.5 0.107 0.208 0.19 --25.0 0.353 0.424 0.40 (2) --24.5 0.653 0.725 --24.0 0.913 0.913 --23.5 0.983 0.988 --23.0 0.998 0.999 --22.0 1.0 1.0 + snr psuccess ntrials 10000 r6315, r6330 +-27.0 0.000 0.001 +-26.5 0.004 0.014 +-26.0 0.03 0.066 +-25.5 0.107 0.208 0.19 +-25.0 0.353 0.424 0.40 (2) +-24.5 0.653 0.725 +-24.0 0.913 0.913 +-23.5 0.983 0.988 +-23.0 0.998 0.999 +-22.0 1.0 1.0 diff --git a/lib/ftrsd/ftrsd_paper/ftdata-100000.dat b/lib/ftrsd/ftrsd_paper/ftdata-100000.dat index dffd774f..e2db520d 100755 --- a/lib/ftrsd/ftrsd_paper/ftdata-100000.dat +++ b/lib/ftrsd/ftrsd_paper/ftdata-100000.dat @@ -1,11 +1,11 @@ -snr psuccess 100000 trials r6315, r6330, --27.0 0.0 0.011 --26.5 0.007 0.035 --26.0 0.057 0.135 --25.5 0.207 0.326 --25.0 0.531 0.568 --24.5 0.822 0.836 --24.0 0.953 0.966 --23.5 0.99423 0.996 --23.0 0.99967 0.99974 302956/303056, 218991/219046 - +snr psuccess 100000 trials r6315, r6330, +-27.0 0.0 0.011 +-26.5 0.007 0.035 +-26.0 0.057 0.135 +-25.5 0.207 0.326 +-25.0 0.531 0.568 +-24.5 0.822 0.836 +-24.0 0.953 0.966 +-23.5 0.99423 0.996 +-23.0 0.99967 0.99974 302956/303056, 218991/219046 + diff --git a/lib/ftrsd/ftrsd_paper/ftrsd.lyx b/lib/ftrsd/ftrsd_paper/ftrsd.lyx index 8139ce1a..4549c768 100755 --- a/lib/ftrsd/ftrsd_paper/ftrsd.lyx +++ b/lib/ftrsd/ftrsd_paper/ftrsd.lyx @@ -1,3289 +1,3289 @@ -#LyX 2.1 created this file. For more info see http://www.lyx.org/ -\lyxformat 474 -\begin_document -\begin_header -\textclass paper -\begin_preamble -\usepackage{ragged2e} -\exhyphenpenalty=10000\hyphenpenalty=10000 - -\fancyhf{} -\fancyhead[L]{Franke \& Taylor: {\it Open Source Soft-Decision Decoder \ldots}} -\fancyhead[R]{\thepage} -\makeatletter -\let\ps@plain\ps@fancy % Plain page style = fancy page style -\makeatother - -\usepackage{nomencl} -\usepackage{overcite} - -\renewcommand{\nomname}{Sidebar: Glossary of Specialized Terms} -\end_preamble -\use_default_options true -\begin_modules -boxedfloat -\end_modules -\maintain_unincluded_children false -\language english -\language_package default -\inputencoding auto -\fontencoding global -\font_roman lmodern -\font_sans lmss -\font_typewriter lmtt -\font_math auto -\font_default_family default -\use_non_tex_fonts false -\font_sc false -\font_osf false -\font_sf_scale 100 -\font_tt_scale 100 -\graphics default -\default_output_format default -\output_sync 0 -\bibtex_command default -\index_command default -\float_placement H -\paperfontsize 12 -\spacing onehalf -\use_hyperref false -\papersize default -\use_geometry true -\use_package amsmath 1 -\use_package amssymb 1 -\use_package cancel 1 -\use_package esint 1 -\use_package mathdots 1 -\use_package mathtools 1 -\use_package mhchem 1 -\use_package stackrel 1 -\use_package stmaryrd 1 -\use_package undertilde 1 -\cite_engine basic -\cite_engine_type default -\biblio_style plain -\use_bibtopic false -\use_indices false -\paperorientation portrait -\suppress_date false -\justification false -\use_refstyle 1 -\index Index -\shortcut idx -\color #008000 -\end_index -\leftmargin 1in -\topmargin 1in -\rightmargin 1in -\bottommargin 1in -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation skip -\defskip bigskip -\quotes_language english -\papercolumns 1 -\papersides 1 -\paperpagestyle fancy -\tracking_changes false -\output_changes false -\html_math_output 0 -\html_css_as_file 0 -\html_be_strict false -\end_header - -\begin_body - -\begin_layout Title -Open Source Soft-Decision Decoder for the JT65 (63,12) Reed-Solomon Code -\end_layout - -\begin_layout SubTitle - -\emph on -Under-the-hood description of the JT65 decoding procedure, including a wholly - new algorithm for its powerful error-correcting code. -\end_layout - -\begin_layout Author -Steven J. - Franke, K9AN and Joseph H. - Taylor, K1JT -\end_layout - -\begin_layout Section -\begin_inset CommandInset label -LatexCommand label -name "sec:Introduction-and-Motivation" - -\end_inset - -Background and Motivation -\end_layout - -\begin_layout Standard -\begin_inset ERT -status open - -\begin_layout Plain Layout - - -\backslash -RaggedRight -\end_layout - -\end_inset - - The JT65 protocol has revolutionized amateur-radio weak-signal communication - by enabling operators with small or compromise antennas and relatively - low-power transmitters to communicate over propagation paths not usable - with traditional technologies. - The protocol was developed in 2003 for Earth-Moon-Earth (EME, or -\begin_inset Quotes eld -\end_inset - -moonbounce -\begin_inset Quotes erd -\end_inset - -) communication -\begin_inset CommandInset citation -LatexCommand cite -key "jt65_protocol" - -\end_inset - -, where the scattered return signals are always weak. - It was soon found that JT65 also enables worldwide communication on the - HF bands with low power, modest antennas, and efficient spectral usage. - Thousands of amateurs now use JT65 on a regular basis, making contacts - on all bands from 160 meters through microwaves. -\end_layout - -\begin_layout Standard -JT65 uses timed transmitting and receiving sequences one minute long. - Messages are short and structured so as to streamline minimal exchanges - between two amateur operators over potentially difficult radio paths. - Most messages contain two callsigns and a grid locator, signal report, - acknowledgment, or sign-off; one of the tokens CQ, QRZ, or DE may be substitute -d for the first callsign. - Alternatively, a message may contain up to 13 Latin characters of arbitrary - text. - All messages are efficiently compressed into exactly 72 bits of digital - information. - It should be obvious that the JT65 protocol is intended for the basic purpose - of completing legitimate, documented two-way contacts, but not for extended - conversations. - Full details of the message structure and encoding procedure were presented - in an earlier publication -\begin_inset CommandInset citation -LatexCommand cite -key "jt65_protocol" - -\end_inset - -. - For a concise description of the overall process of transmitting and receiving - a JT65 message, see the accompanying sidebar -\series bold -JT65 Message Processing -\series default -. -\end_layout - -\begin_layout Standard -A major reason for the success and popularity of JT65 is its use of a strong - error-correction code. - Before transmission, each 72-bit message is divided into 12 six-bit -\emph on -symbols -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Symbol: }" -description "The information carried in one signalling interval, usually an integral number of bits. JT65 uses 6-bit symbols." - -\end_inset - - -\emph default - and augmented with 51 additional symbols of error-correcting information. - These 51 -\emph on -parity symbols -\emph default - are computed according to information-theory rules that maximize the probabilit -y of correctly decoding the message, even if many symbols are received incorrect -ly. - The JT65 code is properly described as a short block-length, low-rate Reed-Solo -mon code based on a 64-symbol -\emph on -alphabet. - -\emph default - -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Alphabet: }" -description "A sequence of possible symbol values used for signaling. JT65 uses a 64-character alphabet, values in the range 0 to 63." - -\end_inset - - Characters in this alphabet are mapped onto 64 different frequencies for - transmission. - -\end_layout - -\begin_layout Standard -Reed Solomon codes are widely used to ensure reliability in data transmission - and storage. - In hardware implementations, decoding is generally accomplished with a - procedure such as the Berlekamp-Massey (BM) algorithm, based on -\emph on -hard decisions -\emph default - -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Hard decision: }" -description "Received symbols are assigned definite values by the demodulator." - -\end_inset - - for each of the symbol values received. - -\emph on -Soft decisions -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Soft decision: }" -description "Received symbols are assigned tentative values (most probable, second most probable, etc.) and quality indicators." - -\end_inset - - -\emph default - are potentially more powerful, however. - For each received JT65 symbol we can estimate not only the value most likely - to be correct, but also the second, third, etc., most likely. - Most importantly, we can also estimate the probability that each of those - possible values is the correct one. - Decoders that make use of such information are called -\emph on -soft-decision decoders. -\end_layout - -\begin_layout Standard -Until now, nearly all programs implementing JT65 have used the patented - Kötter-Vardy (KV) algebraic soft-decision decoder -\begin_inset CommandInset citation -LatexCommand cite -key "kv2001" - -\end_inset - -, licensed to and implemented by K1JT as a closed-source executable for - use only in amateur radio applications. - Since 2001 the KV decoder has been considered the best available soft-decision - decoder for Reed Solomon codes. -\end_layout - -\begin_layout Standard -We describe here a new open-source alternative called the Franke-Taylor - (FT, or K9AN-K1JT) soft-decision decoding algorithm. - It is conceptually simple, built on top of the BM hard-decision decoder, - and in this application it performs even better than the KV decoder. - The FT algorithm is implemented in the popular programs -\emph on -WSJT -\emph default -, -\emph on -MAP65 -\emph default -, and -\emph on -WSJT-X -\emph default -, widely used for amateur weak-signal communication using JT65 and other - specialized digital protocols. - These programs are open-source, freely available -\begin_inset CommandInset citation -LatexCommand cite -key "wsjt" - -\end_inset - -, and licensed under the GNU General Public License. -\end_layout - -\begin_layout Standard -The JT65 protocol specifies transmissions that start one second into a UTC - minute and last for 46.8 seconds. - Receiving software therefore has as much as ten seconds to decode a message - before the start of the next minute, when the operator will send a reply. - With today's personal computers, this relatively long time encourages experimen -tation with decoders of high computational complexity. - With time to spare, the FT algorithm lowers the decoding threshold on a - typical fading channel by many dB over the hard-decision BM decoder, and - by a meaningful amount over the KV decoder. - In addition to its excellent performance, the new algorithm has other desirable - properties, not least of which is its conceptual simplicity. - Decoding performance and computational complexity scale in a convenient - way, providing steadily increasing soft-decision decoding gain as a tunable - parameter is increased over more than five orders of magnitude. - Appreciable gain is available from our decoder even on very simple (and - relatively slow) computers. - On the other hand, because the algorithm benefits from a large number of - independent decoding trials, further performance gains should be achievable - through parallelization on high-performance computers. -\end_layout - -\begin_layout Standard -The remainder of this paper is organized as follows. - Section 2 presents a brief overview of the nature of Reed Solomon codes - and their error-correcting capabilities. - Section 3 provides statistical motivation for the FT algorithm, and Section - 4 describes the algorithm in full detail. - Material in these two sections is important because it documents our approach - and underlines its fundamental technical contributions. - These sections are heavier in formal mathematics than common in -\emph on -QEX -\emph default -; for this reason, some readers may choose to skip or skim them and proceed - more quickly to the results. - Most readers will benefit by reviewing the original paper on the JT65 protocol - -\begin_inset CommandInset citation -LatexCommand cite -key "jt65_protocol" - -\end_inset - -. - A procedure for -\emph on -hinted decoding -\emph default ---- determining which one, if any, of a list of likely messages matches - the one that was received --- is outlined in Section 5. - Finally, in Section 6 we present performance measurements of the FT and - hinted decoding algorithms and make explicit comparisons to the BM and - KV decoders familiar to users of older versions of -\emph on -WSJT -\emph default -, -\emph on -MAP65 -\emph default - and -\emph on -WSJT-X -\emph default -. - Section 7 summarizes some on-the-air experiences with the new decoder. - Refer to the sidebar -\series bold -Glossary of Specialized Terms -\series default - for brief definitions of some potentially unfamiliar language. -\end_layout - -\begin_layout Section -\begin_inset CommandInset label -LatexCommand label -name "sec:JT65-messages-and" - -\end_inset - -JT65 Messages and Reed Solomon Codes -\end_layout - -\begin_layout Standard -The JT65 message frame consists of a short, compressed 72-bit message encoded - for transmission with a Reed-Solomon code. - Reed-Solomon codes are -\emph on -block codes -\emph default - -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Block code: }" -description "An error-correcting code that treats data in blocks of fixed size." - -\end_inset - - characterized by -\begin_inset Formula $n$ -\end_inset - -, the length of their -\emph on -codewords -\emph default -; -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Codeword:}" -description "For the JT65 code, a vector of 63 symbol values each in the range 0 to 63." - -\end_inset - - -\begin_inset Formula $k$ -\end_inset - -, the number of message symbols conveyed by the codeword; and the transmission - alphabet, or number of possible values for each symbol in a codeword. - The codeword length and the number of message symbols are specified with - the notation -\begin_inset Formula $(n,k)$ -\end_inset - -. - JT65 uses a (63,12) Reed-Solomon code with an alphabet of 64 possible values - for each symbol. - Each of the 12 message symbols represents -\begin_inset Formula $\log_{2}64=6$ -\end_inset - - message bits. - The source-encoded -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Source encoding: }" -description "Compression of a message to use a minimum number or bits. JT65 source-encodes all messages to 72 bits." - -\end_inset - - message conveyed by a 63-symbol JT65 frame thus consists of 72 information - bits. - The JT65 code is -\emph on -systematic -\emph default -, which means that the 12 message symbols are embedded in the codeword without - modification and another 51 parity symbols derived from the message symbols - are added to form a codeword of 63 symbols. - -\end_layout - -\begin_layout Standard -In coding theory the concept of -\emph on -Hamming distance -\emph default - -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Hamming distance: }" -description "The Hamming distance between two codewords, or between a received word and a codeword, is equal to the number of symbol positions in which they differ." - -\end_inset - - is used as a measure of disagreement between different codewords, or between - a received word -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Received word: }" -description "A vector of symbol values, possibly accompanied by soft information on individual reliabilities." - -\end_inset - - and a codeword. - Hamming distance is the number of code symbols that differ in two words - being compared. - Reed-Solomon codes have guaranteed minimum Hamming distance -\begin_inset Formula $d$ -\end_inset - -, where -\begin_inset Formula -\begin{equation} -d=n-k+1.\label{eq:minimum_distance} -\end{equation} - -\end_inset - -With -\begin_inset Formula $n=63$ -\end_inset - - and -\begin_inset Formula $k=12$ -\end_inset - - the minimum Hamming distance of the JT65 code is -\begin_inset Formula $d=52$ -\end_inset - -. - With 72 information bits in each message, JT65 can transmit any one of - -\begin_inset Formula $2^{72}\approx4.7\times10^{21}$ -\end_inset - - possible messages. - The codeword for any message differs from every other codeword in at least - 52 of the 63 symbol positions. -\end_layout - -\begin_layout Standard -A received word containing some -\emph on -errors -\emph default - (incorrect symbols) can be decoded into the correct codeword using a determinis -tic, -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Deterministic algorithm: }" -description "A series of computational steps that for the same input always produces the same output." - -\end_inset - - algebraic algorithm provided that no more than -\begin_inset Formula $t$ -\end_inset - - symbols were received incorrectly, where -\begin_inset Formula -\begin{equation} -t=\left\lfloor \frac{n-k}{2}\right\rfloor .\label{eq:t} -\end{equation} - -\end_inset - -For the JT65 code -\begin_inset Formula $t=25$ -\end_inset - -, so it is always possible to decode a received word having 25 or fewer - symbol errors. - Any one of several well-known algebraic algorithms, such as the BM algorithm, - can carry out this hard-decision decoding. - Two steps are necessarily involved in this process. - We must (1) determine which symbols were received incorrectly, and (2) - find the correct value of the incorrect symbols. - If we somehow know that certain symbols are incorrect, that information - can be used to reduce the work involved in step 1 and allow step 2 to correct - more than -\begin_inset Formula $t$ -\end_inset - - errors. - In the unlikely event that the location of every error is known, and if - no correct symbols are accidentally labeled as errors, the BM algorithm - can correct up to -\begin_inset Formula $d-1=n-k$ -\end_inset - - errors. - -\end_layout - -\begin_layout Standard -The FT algorithm creates lists of symbols suspected of being incorrect and - sends them to the BM decoder. - Symbols flagged in this way are called -\emph on -erasures -\emph default - -\begin_inset CommandInset nomenclature -LatexCommand nomenclature -symbol "{\\bf Erasure: }" -description "A received symbol may be ``erased'' when confidence in its value is so low that it is unlikely to provide useful information. " - -\end_inset - -. - With perfect erasure information up to -\begin_inset Formula $n-k=51$ -\end_inset - - incorrect symbols can be corrected for the JT65 code. - Imperfect erasure information means that some erased symbols may be correct, - and some other symbols in error. - If -\begin_inset Formula $s$ -\end_inset - - symbols are erased and the remaining -\begin_inset Formula $n-s$ -\end_inset - - symbols contain -\begin_inset Formula $e$ -\end_inset - - errors, the BM algorithm can find the correct codeword as long as -\begin_inset Formula -\begin{equation} -s+2e\le d-1.\label{eq:erasures_and_errors} -\end{equation} - -\end_inset - -If -\begin_inset Formula $s=0$ -\end_inset - -, the decoder is said to be an -\emph on -errors-only -\emph default - decoder. - If -\begin_inset Formula $0=x|N,X,s) '/ & - '-------------------------------') - - hsum=0.d0 - do ix=x,XX - h=hypergeo(ix,NN,XX,s) - hsum=hsum + h - write(*,1020) ix,h,hsum -1020 format(i3,2d13.4) - enddo - -999 end program prob +program prob + + implicit real*8 (a-h,o-z) + integer*8 binomial + integer x,s,XX,NN + real*8 hypergeo + character arg*8 + + nargs=iargc() + if(nargs.ne.4) then + print*,'Usage: prob x N X s' + print*,'Example: prob 35 63 40 40' + go to 999 + endif + call getarg(1,arg) + read(arg,*) x + call getarg(2,arg) + read(arg,*) NN + call getarg(3,arg) + read(arg,*) XX + call getarg(4,arg) + read(arg,*) s + +! print*,binomial(5, 3) ! 10 +! print*,binomial(40, 19) ! 131282408400 + + write(*,1010) x,NN,XX,s +1010 format(//' x=',i2,' N=',i2,' X=',i2,' s=',i2) + write(*,1012) +1012 format(/' x P(x|N,X,s) P(>=x|N,X,s) '/ & + '-------------------------------') + + hsum=0.d0 + do ix=x,XX + h=hypergeo(ix,NN,XX,s) + hsum=hsum + h + write(*,1020) ix,h,hsum +1020 format(i3,2d13.4) + enddo + +999 end program prob diff --git a/lib/ftrsd/ftrsd_paper/psuccess.lab b/lib/ftrsd/ftrsd_paper/psuccess.lab index 9959793f..21ed9734 100755 --- a/lib/ftrsd/ftrsd_paper/psuccess.lab +++ b/lib/ftrsd/ftrsd_paper/psuccess.lab @@ -1,14 +1,14 @@ --21.5 55 BM --24.5 50 FT --27.0 68 DS --25.2 25 0 --25.7 37 0.2 --24.6 16 1.0 --22.6 35 0 --20.9 29 0.2 --19.5 35 1.0 --28.5 25 1.0 --28.2 56 0.2 --28.5 72 0 - - +-21.5 55 BM +-24.5 50 FT +-27.0 68 DS +-25.2 25 0 +-25.7 37 0.2 +-24.6 16 1.0 +-22.6 35 0 +-20.9 29 0.2 +-19.5 35 1.0 +-28.5 25 1.0 +-28.2 56 0.2 +-28.5 72 0 + + diff --git a/lib/ftrsd/ftrsd_paper/stats-100000-24db-3.dat b/lib/ftrsd/ftrsd_paper/stats-100000-24db-3.dat index c7191960..bd2a10f4 100755 --- a/lib/ftrsd/ftrsd_paper/stats-100000-24db-3.dat +++ b/lib/ftrsd/ftrsd_paper/stats-100000-24db-3.dat @@ -1,930 +1,930 @@ - 35 19 45 12 - 34 20 46 6 - 35 27 43 4519 - 33 21 44 11 - 32 22 39 8 - 34 21 48 333 - 30 20 42 2 - 38 25 43 12 - 38 25 49 2958 - 28 20 43 10 - 41 29 44 4070 - 32 19 44 1 - 28 19 43 2 - 38 28 43 10421 - 25 0 0 0 - 36 24 42 8 - 38 25 42 243 - 39 25 45 81 - 33 17 39 2 - 38 25 39 157 - 37 27 45 1 - 31 18 39 8 - 35 22 41 2 - 31 20 45 32 - 40 30 45 11123 - 34 25 48 516 - 37 22 49 73 - 32 19 45 2 - 39 25 43 49 - 35 25 42 12 - 43 32 45 3645 - 35 21 45 124 - 39 26 48 31 - 40 26 48 23 - 36 25 43 169 - 33 21 41 8 - 31 21 49 3 - 37 23 46 2 - 32 27 41 8 - 36 23 43 2112 - 29 19 49 4 - 34 24 41 170 - 27 15 44 1 - 34 21 43 2 - 39 25 47 28 - 30 18 43 10 - 37 22 40 8 - 42 33 48 64709 - 36 25 43 10 - 35 20 51 17 - 37 28 45 301 - 34 18 40 9 - 34 25 47 23 - 39 28 43 4856 - 36 24 45 7057 - 35 25 47 769 - 38 28 47 208 - 39 27 47 52290 - 35 22 44 85 - 34 23 48 7 - 37 21 47 82 - 42 25 39 1677 - 29 17 41 8 - 41 24 46 656 - 35 24 43 2 - 38 22 45 10400 - 36 20 42 14 - 33 22 46 2 - 25 0 0 0 - 33 20 45 12 - 30 17 45 1 - 34 20 43 40 - 32 21 42 14 - 28 15 44 1 - 37 23 42 8 - 32 21 40 8 - 39 28 44 65 - 30 17 41 2 - 32 25 44 134 - 38 24 43 12 - 38 23 47 153 - 39 26 42 8 - 37 20 47 35 - 39 27 47 1003 - 36 23 45 215 - 38 28 49 46 - 34 24 47 200 - 35 23 40 8 - 30 19 44 1 - 38 25 43 32 - 32 22 39 103 - 33 23 42 2 - 34 24 47 6 - 33 22 43 13 - 42 28 43 2127 - 34 22 41 113 - 39 30 41 517 - 30 17 42 8 - 32 20 45 1 - 34 20 51 17 - 32 15 39 9 - 37 23 47 223 - 28 15 43 1 - 38 24 42 251 - 41 26 45 2 - 39 25 49 7 - 35 26 47 237 - 32 18 43 25 - 33 23 43 8 - 41 29 43 2667 - 28 17 45 1 - 34 23 47 53 - 32 19 39 9 - 34 24 42 59 - 36 22 44 8 - 34 20 45 59 - 37 24 45 12 - 28 17 44 1 - 41 29 43 24865 - 32 19 46 6 - 33 22 47 6 - 36 20 47 143 - 36 22 47 34 - 33 19 39 9 - 38 22 44 523 - 34 24 42 737 - 36 24 39 170 - 35 22 43 2 - 32 19 48 22 - 33 20 49 76 - 42 24 49 6910 - 37 22 47 94 - 40 24 43 6 - 35 25 45 33 - 29 22 41 2 - 40 24 46 2096 - 37 20 45 135 - 36 26 43 113 - 36 21 43 13 - 37 24 47 49 - 35 24 43 54 - 37 22 43 8 - 35 23 44 2 - 30 20 43 11 - 39 30 47 2870 - 42 33 44 585 - 26 17 45 2 - 41 29 47 79 - 40 24 46 836 - 33 19 45 201 - 34 21 39 13 - 33 21 49 60 - 35 24 44 248 - 33 24 43 24 - 39 29 44 151 - 31 23 46 1 - 36 23 46 1 - 41 27 47 5565 - 42 26 47 378 - 35 27 45 4571 - 40 30 47 6422 - 32 20 42 8 - 38 28 45 449 - 38 26 47 595 - 39 24 47 1555 - 41 25 49 645 - 32 19 40 8 - 35 25 45 97 - 25 0 0 0 - 30 19 44 25 - 31 18 45 1 - 41 24 51 6915 - 34 23 46 1917 - 30 19 43 2 - 35 22 47 20 - 38 23 43 882 - 30 20 48 5 - 37 25 44 919 - 34 20 45 74 - 38 25 46 394 - 39 21 49 738 - 35 20 47 22 - 40 30 47 190 - 41 27 45 1515 - 39 27 49 55 - 35 25 41 994 - 39 27 47 7117 - 37 22 46 19 - 33 21 41 2 - 34 18 47 19 - 30 20 46 6 - 31 21 46 1 - 36 24 47 98 - 40 24 43 39 - 38 25 45 138 - 41 27 47 33 - 40 29 49 2510 - 36 26 43 2 - 34 21 45 1 - 40 26 49 1924 - 36 17 43 2 - 38 27 45 68 - 34 22 45 61 - 32 22 40 8 - 37 19 43 4784 - 32 16 43 8 - 38 27 50 46 - 35 21 43 38 - 35 22 49 4 - 38 27 49 31 - 39 28 47 4677 - 30 18 45 2 - 43 28 47 8235 - 38 28 43 830 - 32 21 47 15 - 37 24 42 10 - 37 23 45 259 - 37 25 45 35 - 40 24 45 524 - 35 19 44 1 - 36 23 45 84 - 36 24 50 17 - 31 20 46 1 - 35 24 42 74 - 42 27 47 1445 - 40 28 48 31 - 36 23 45 151 - 34 22 46 6 - 33 24 49 16 - 30 20 45 2 - 38 22 43 125 - 40 25 49 64 - 35 23 49 86 - 38 24 46 613 - 42 25 47 4232 - 34 24 43 31 - 32 18 41 2 - 37 26 43 70 - 37 27 41 14 - 37 22 39 129 - 38 27 49 3 - 32 22 47 15 - 41 27 41 472 - 38 24 43 25 - 35 28 43 309 - 41 25 47 82 - 40 23 43 8 - 40 21 43 1716 - 38 22 48 5 - 37 20 47 22 - 42 28 43 315 - 32 23 43 79 - 25 0 0 0 - 42 23 47 2245 - 35 24 45 2 - 41 25 44 12 - 36 23 43 1 - 36 19 45 151 - 41 28 45 2207 - 40 27 45 76 - 34 20 47 6 - 41 28 46 370 - 38 20 45 12 - 32 20 43 8 - 39 24 45 8 - 41 27 47 26941 - 35 23 46 3 - 34 25 41 14 - 43 27 47 26905 - 35 25 45 2 - 32 20 50 3 - 31 17 41 2 - 38 26 47 4157 - 33 24 41 2 - 41 29 43 26513 - 35 22 45 297 - 37 26 44 99 - 33 19 43 10 - 39 23 45 138 - 39 26 47 1320 - 33 22 42 2 - 42 32 45 791 - 33 23 51 3 - 38 25 43 8 - 40 27 49 1210 - 43 27 45 32969 - 37 26 49 108 - 38 18 45 1268 - 40 28 49 7810 - 36 25 44 47 - 38 27 48 20 - 34 20 44 10 - 41 27 45 429 - 33 18 43 8 - 29 17 45 1 - 40 25 42 9 - 30 21 49 4 - 37 22 45 10 - 23 0 0 0 - 36 15 45 2509 - 29 21 45 18 - 33 23 45 53 - 43 27 49 7533 - 37 28 45 2652 - 36 24 49 31 - 32 20 43 25 - 42 27 49 1500 - 41 26 45 8 - 40 25 47 152 - 37 26 45 151 - 37 27 43 139 - 34 20 47 4 - 31 21 43 44 - 37 28 45 241 - 35 25 45 422 - 33 22 45 6 - 39 26 48 23 - 38 27 49 359 - 42 26 45 1430 - 36 28 47 116 - 33 23 41 232 - 38 25 47 73 - 35 24 43 16 - 42 29 47 398 - 38 27 49 2203 - 32 20 47 3 - 32 18 48 3 - 36 23 47 44 - 37 24 48 147 - 39 22 45 31 - 31 20 44 1 - 34 21 43 8 - 39 27 47 201 - 34 23 44 12 - 34 24 43 8 - 36 17 46 2 - 41 27 47 8709 - 41 26 45 112 - 37 23 47 216 - 38 24 45 93 - 32 19 45 44 - 34 22 45 8 - 33 24 41 14 - 34 22 41 9 - 35 23 42 136 - 36 26 43 3272 - 34 18 44 40 - 38 25 43 316 - 29 23 39 9 - 35 23 45 2 - 41 29 42 136 - 37 26 43 12 - 34 21 46 43 - 39 21 47 23 - 40 29 49 14666 - 36 19 45 400 - 37 24 43 8 - 35 19 44 2 - 36 26 45 14 - 36 22 43 103 - 33 19 45 6 - 35 24 43 1 - 31 22 43 80 - 35 23 46 22 - 28 18 41 2 - 35 24 45 31 - 34 24 47 46 - 37 24 42 2 - 37 27 43 525 - 31 16 41 9 - 30 18 45 2 - 39 25 47 1416 - 37 24 46 23 - 40 28 49 5 - 39 26 46 2071 - 28 13 42 8 - 31 17 47 3 - 34 22 49 3 - 42 23 47 61 - 30 21 41 2 - 40 23 47 208 - 38 22 48 6 - 35 17 40 8 - 36 20 45 32 - 37 22 47 1116 - 41 28 47 14145 - 43 28 49 96342 - 35 19 45 102 - 31 23 43 8 - 33 20 43 1 - 30 19 46 90 - 41 27 45 19090 - 35 26 45 2942 - 40 25 47 127 - 35 23 45 12 - 37 26 46 76 - 31 19 44 32 - 42 31 49 4951 - 43 30 44 38924 - 35 19 51 17 - 41 31 44 6637 - 33 22 42 2 - 33 25 46 12 - 31 24 44 10 - 27 16 49 4 - 39 24 45 16 - 33 20 40 8 - 39 31 48 5073 - 39 21 47 72 - 35 21 47 3 - 38 27 41 1168 - 35 22 43 8 - 28 18 45 1 - 38 28 40 776 - 33 22 51 3 - 34 22 41 370 - 37 25 43 3210 - 32 24 43 8 - 35 24 46 3 - 39 20 45 41 - 35 17 43 49 - 39 29 46 20 - 31 21 44 1 - 43 24 48 4400 - 36 23 48 350 - 38 29 47 520 - 36 24 45 49 - 39 27 43 493 - 34 15 45 6 - 41 31 43 59993 - 34 24 42 27 - 31 14 41 1 - 40 30 47 13295 - 35 23 47 202 - 36 22 47 35 - 38 26 45 18576 - 34 26 43 54 - 40 30 51 173 - 43 29 47 105 - 34 24 39 9 - 33 20 43 8 - 35 27 45 65 - 31 18 42 2 - 31 21 45 6 - 40 27 45 979 - 36 21 47 3 - 29 14 43 1 - 37 24 47 432 - 39 24 50 4778 - 33 20 44 2 - 40 27 44 7398 - 36 22 47 148 - 35 21 44 11 - 35 22 45 206 - 30 18 42 8 - 40 30 43 8 - 30 22 42 9 - 29 21 39 9 - 41 26 43 1248 - 39 24 43 14 - 38 24 49 605 - 35 20 42 155 - 33 22 47 53 - 34 20 43 10 - 35 26 49 21 - 31 18 45 1 - 32 19 39 9 - 31 20 43 19 - 41 23 41 157 - 36 23 42 9 - 28 19 45 1 - 33 19 43 10 - 38 22 44 25 - 29 19 41 2 - 34 19 42 8 - 35 21 39 9 - 34 23 45 2 - 41 30 47 71025 - 40 26 48 3059 - 36 24 45 1346 - 35 19 47 34 - 36 25 45 112 - 39 27 41 7065 - 38 24 47 4 - 29 18 42 1 - 30 20 41 2 - 32 22 49 3 - 40 29 45 4589 - 38 25 42 234 - 42 28 49 3171 - 35 22 45 34 - 39 24 41 5693 - 29 20 43 2 - 29 16 44 14 - 37 25 45 19 - 36 18 44 8 - 36 27 45 1224 - 38 28 47 8906 - 29 15 51 3 - 33 20 47 46 - 33 17 41 9 - 40 22 45 1775 - 32 22 45 8 - 35 21 43 8 - 38 24 41 9 - 41 22 47 10005 - 36 27 43 12 - 33 21 47 35 - 35 21 39 9 - 34 22 44 2 - 34 17 45 67 - 31 18 45 1 - 34 21 46 32 - 35 26 44 1 - 34 23 44 8 - 31 24 47 3 - 43 23 49 9210 - 40 20 48 114 - 36 25 42 8 - 37 24 46 336 - 37 23 43 138 - 38 26 47 89 - 38 24 47 6494 - 30 18 45 1 - 43 28 47 677 - 31 23 48 3 - 32 19 43 1 - 36 23 44 19 - 43 30 47 81276 - 37 22 48 106 - 37 24 45 12 - 37 22 45 68 - 28 17 43 24 - 43 28 45 1446 - 40 30 46 2753 - 35 23 44 1 - 28 16 43 2 - 29 19 42 2 - 31 21 42 2 - 39 26 48 98 - 41 30 47 21848 - 35 22 47 5 - 40 31 45 448 - 34 23 45 94 - 29 17 42 8 - 39 30 46 1231 - 41 22 47 49 - 30 15 51 7 - 35 26 41 9 - 29 17 49 7 - 33 22 43 12 - 33 19 46 5 - 35 24 45 12 - 33 22 42 9 - 34 18 43 13 - 36 21 43 63 - 37 27 45 32 - 37 23 49 474 - 31 17 46 19 - 38 24 41 2 - 40 28 47 1621 - 39 25 47 214 - 32 21 42 19 - 34 22 47 105 - 35 26 42 2 - 35 21 44 13 - 40 25 47 556 - 39 27 49 3 - 36 25 45 32 - 39 27 41 10 - 35 20 45 1 - 28 17 45 1 - 35 23 47 6 - 33 20 50 137 - 34 22 43 177 - 30 19 41 9 - 33 23 47 579 - 33 22 39 9 - 39 20 42 74 - 42 28 47 112 - 40 29 44 197 - 36 23 43 2 - 30 17 49 3 - 37 27 45 3815 - 35 24 43 74 - 35 22 47 24 - 40 27 46 82 - 36 25 41 366 - 33 23 44 1 - 37 21 40 131 - 34 22 45 16 - 36 24 45 306 - 39 26 47 82 - 29 17 45 1 - 36 23 48 3 - 35 20 44 63 - 35 23 46 5 - 39 25 43 792 - 32 22 49 5 - 35 23 41 9 - 37 24 41 12711 - 41 32 43 36575 - 34 23 42 8 - 31 21 43 2 - 35 24 41 2 - 35 24 39 8 - 37 23 48 75 - 35 19 43 12 - 40 25 49 914 - 38 22 49 60 - 34 19 42 10 - 42 33 44 9038 - 37 27 45 1849 - 29 20 42 138 - 37 27 43 332 - 36 26 45 36 - 32 18 45 6 - 37 25 46 4676 - 29 18 45 6 - 34 22 43 8 - 41 32 45 1966 - 30 18 42 12 - 33 20 45 1 - 31 23 45 6 - 30 21 46 1 - 36 21 43 14 - 34 18 45 37 - 42 32 47 3508 - 41 32 41 13 - 37 25 45 719 - 33 20 45 111 - 38 28 42 8 - 35 23 43 14 - 39 23 47 123 - 28 13 44 1 - 34 19 41 38 - 35 21 43 8 - 33 26 47 124 - 30 18 41 9 - 43 30 46 11935 - 40 28 48 2329 - 35 19 45 286 - 30 21 43 80 - 37 21 49 474 - 41 27 49 1560 - 42 24 46 1802 - 38 28 42 6807 - 38 24 43 63 - 33 24 49 35 - 41 27 41 9795 - 29 16 41 2 - 29 17 43 2 - 34 21 45 125 - 39 28 45 1008 - 34 21 42 8 - 36 23 45 2 - 34 22 41 8 - 34 21 41 74 - 37 21 43 262 - 30 18 41 8 - 33 22 49 3 - 33 21 42 1 - 35 28 49 21 - 31 19 43 1 - 36 24 44 10 - 40 23 49 583 - 33 19 37 9 - 32 21 45 6 - 38 24 47 15 - 42 27 47 2847 - 36 28 45 106 - 39 28 43 53 - 30 16 42 2 - 28 18 49 3 - 33 21 44 1 - 36 24 45 3050 - 37 27 40 8 - 35 19 43 12 - 41 29 43 19008 - 21 0 0 0 - 38 26 41 762 - 33 21 46 12 - 41 26 47 14517 - 33 24 49 3 - 41 31 47 287 - 35 24 51 17 - 37 27 42 38 - 34 22 43 24 - 39 26 46 135 - 38 26 41 493 - 35 22 42 8 - 38 24 41 1082 - 32 23 42 1 - 33 24 40 8 - 37 25 48 640 - 28 14 39 9 - 39 20 45 212 - 37 29 45 610 - 34 26 47 57 - 29 21 41 8 - 35 16 45 53 - 35 21 44 2 - 38 26 48 188 - 34 25 41 10 - 36 23 44 8 - 35 21 45 8 - 35 26 41 8 - 37 26 40 9 - 28 12 43 1 - 34 22 51 3 - 35 25 44 13 - 32 16 44 32 - 32 19 45 143 - 29 17 43 1 - 35 22 43 93 - 38 21 43 99 - 36 26 49 242 - 34 22 45 8 - 40 24 45 136 - 40 24 48 88 - 38 21 46 49 - 40 27 49 116 - 41 26 44 3696 - 35 23 42 8 - 28 15 45 104 - 33 21 43 106 - 35 25 45 31 - 33 24 40 113 - 36 24 46 23 - 37 25 45 334 - 32 21 46 12 - 35 21 41 2 - 36 22 45 8 - 37 18 43 13 - 37 26 47 48 - 39 25 46 400 - 37 27 43 174 - 37 23 47 41 - 40 21 47 1811 - 38 26 45 79 - 26 15 43 1 - 39 27 49 19 - 31 19 44 1 - 37 22 43 8 - 32 24 38 9 - 34 23 48 3 - 37 24 51 22 - 27 18 42 2 - 31 22 47 5 - 33 17 41 2 - 40 28 45 14534 - 37 21 47 5 - 27 15 43 2 - 43 26 47 46658 - 39 22 43 8 - 36 23 41 2 - 31 19 43 12 - 36 24 43 10 - 33 20 43 149 - 30 19 47 3 - 39 27 51 1236 - 41 26 45 4744 - 39 22 47 100 - 32 18 44 6 - 32 21 43 54 - 40 30 46 777 - 35 25 43 355 - 36 24 41 138 - 40 30 47 3056 - 39 28 46 19 - 34 21 46 6 - 34 18 46 52 - 36 27 41 232 - 35 25 51 3 - 36 28 44 110 - 33 23 45 1 - 37 22 46 64301 - 39 23 49 41 - 39 30 40 25 - 36 23 48 6 - 29 17 42 2 - 36 23 44 1 - 32 17 43 40 - 32 16 49 86 - 29 19 49 5 - 38 26 41 9 - 40 28 43 56710 - 41 29 45 1711 - 36 23 49 345 - 35 25 43 8 - 35 24 46 19 - 37 23 41 648 - 30 18 45 1 - 30 21 43 1 - 34 20 45 12 - 42 25 47 431 - 40 27 41 15878 - 34 22 43 8 - 41 29 48 49 - 32 21 43 2 - 37 22 43 2 - 39 28 49 86 - 43 28 45 8032 - 41 30 49 15674 - 34 22 48 17 - 36 24 48 107 - 28 20 44 1 - 43 28 48 1986 - 40 25 47 2585 - 38 21 43 59 - 38 28 41 167 - 34 22 39 9 - 43 27 48 4196 - 32 20 44 120 - 33 25 45 99 - 26 12 42 2 - 26 15 47 4 - 37 21 42 10 - 35 25 49 3 - 42 30 49 11151 - 33 20 44 2 - 39 26 45 65238 - 31 16 40 2 - 38 26 39 8 - 36 22 45 82 - 32 22 49 7 - 33 20 45 2 - 40 24 43 12 - 32 18 50 3 - 31 21 40 2 - 34 18 44 2 - 38 28 46 194 - 36 21 43 12 - 32 20 43 8 - 30 18 42 2 - 37 21 47 31 - 36 23 47 15 - 36 21 45 113 - 34 23 44 1 - 43 29 49 3889 - 37 24 47 32 - 41 22 43 243 - 38 25 47 707 - 35 22 43 18399 - 33 22 45 123 - 37 24 42 8 - 39 25 47 1087 - 34 23 47 107 - 32 21 42 2 - 42 25 47 106 - 39 24 42 13560 - 42 29 49 52387 - 38 27 43 59 - 31 18 39 9 - 40 28 48 41 - 37 25 45 11 - 30 23 45 242 - 38 23 47 1673 - 36 23 45 751 - 29 22 41 2 - 36 19 48 3 - 36 22 45 12 - 35 18 47 20 - 40 28 49 17369 - 29 19 46 2 - 36 26 42 25 - 42 30 49 4767 - 30 20 45 6 - 35 24 44 12 - 41 24 42 1537 - 38 25 47 629 - 31 21 44 2 - 34 22 43 1 - 33 20 47 3 - 34 20 43 8 - 40 26 49 4320 - 31 16 43 9 - 34 22 45 8 - 32 22 46 124 - 32 20 43 13 - 40 28 47 1185 - 41 24 45 30643 - 39 23 43 1658 - 33 23 44 8 - 36 22 46 23 - 41 25 47 114 - 36 21 42 12 - 33 19 48 31 - 42 28 48 76 - 29 22 39 9 - 36 21 47 3 - 37 27 45 282 - 42 29 46 24995 - 36 26 39 9 - 40 25 46 123 - 39 26 41 8 - 41 30 45 3143 - 34 20 41 27 - 38 31 42 17297 - 40 24 51 3052 - 36 28 45 190 - 31 23 42 8 - 42 26 42 68 - 39 31 45 37327 - 37 27 41 8 - 36 20 45 76 - 38 26 42 10 - 36 21 45 63 - 40 31 43 140 - 40 27 49 21 - 31 22 36 9 - 34 22 39 9 - 29 17 43 2 - 36 26 45 61 - 38 23 45 15 - 31 21 43 54 - 36 22 41 93 - 31 18 43 2 - 35 25 49 108 - 41 29 45 18292 - 37 25 45 104 - 28 20 41 2 - 35 26 46 35 - 34 20 46 19 - 38 22 51 183 - 34 14 43 8 - 32 23 43 16 - 27 17 44 1 - 29 15 42 2 - 37 26 41 129 + 35 19 45 12 + 34 20 46 6 + 35 27 43 4519 + 33 21 44 11 + 32 22 39 8 + 34 21 48 333 + 30 20 42 2 + 38 25 43 12 + 38 25 49 2958 + 28 20 43 10 + 41 29 44 4070 + 32 19 44 1 + 28 19 43 2 + 38 28 43 10421 + 25 0 0 0 + 36 24 42 8 + 38 25 42 243 + 39 25 45 81 + 33 17 39 2 + 38 25 39 157 + 37 27 45 1 + 31 18 39 8 + 35 22 41 2 + 31 20 45 32 + 40 30 45 11123 + 34 25 48 516 + 37 22 49 73 + 32 19 45 2 + 39 25 43 49 + 35 25 42 12 + 43 32 45 3645 + 35 21 45 124 + 39 26 48 31 + 40 26 48 23 + 36 25 43 169 + 33 21 41 8 + 31 21 49 3 + 37 23 46 2 + 32 27 41 8 + 36 23 43 2112 + 29 19 49 4 + 34 24 41 170 + 27 15 44 1 + 34 21 43 2 + 39 25 47 28 + 30 18 43 10 + 37 22 40 8 + 42 33 48 64709 + 36 25 43 10 + 35 20 51 17 + 37 28 45 301 + 34 18 40 9 + 34 25 47 23 + 39 28 43 4856 + 36 24 45 7057 + 35 25 47 769 + 38 28 47 208 + 39 27 47 52290 + 35 22 44 85 + 34 23 48 7 + 37 21 47 82 + 42 25 39 1677 + 29 17 41 8 + 41 24 46 656 + 35 24 43 2 + 38 22 45 10400 + 36 20 42 14 + 33 22 46 2 + 25 0 0 0 + 33 20 45 12 + 30 17 45 1 + 34 20 43 40 + 32 21 42 14 + 28 15 44 1 + 37 23 42 8 + 32 21 40 8 + 39 28 44 65 + 30 17 41 2 + 32 25 44 134 + 38 24 43 12 + 38 23 47 153 + 39 26 42 8 + 37 20 47 35 + 39 27 47 1003 + 36 23 45 215 + 38 28 49 46 + 34 24 47 200 + 35 23 40 8 + 30 19 44 1 + 38 25 43 32 + 32 22 39 103 + 33 23 42 2 + 34 24 47 6 + 33 22 43 13 + 42 28 43 2127 + 34 22 41 113 + 39 30 41 517 + 30 17 42 8 + 32 20 45 1 + 34 20 51 17 + 32 15 39 9 + 37 23 47 223 + 28 15 43 1 + 38 24 42 251 + 41 26 45 2 + 39 25 49 7 + 35 26 47 237 + 32 18 43 25 + 33 23 43 8 + 41 29 43 2667 + 28 17 45 1 + 34 23 47 53 + 32 19 39 9 + 34 24 42 59 + 36 22 44 8 + 34 20 45 59 + 37 24 45 12 + 28 17 44 1 + 41 29 43 24865 + 32 19 46 6 + 33 22 47 6 + 36 20 47 143 + 36 22 47 34 + 33 19 39 9 + 38 22 44 523 + 34 24 42 737 + 36 24 39 170 + 35 22 43 2 + 32 19 48 22 + 33 20 49 76 + 42 24 49 6910 + 37 22 47 94 + 40 24 43 6 + 35 25 45 33 + 29 22 41 2 + 40 24 46 2096 + 37 20 45 135 + 36 26 43 113 + 36 21 43 13 + 37 24 47 49 + 35 24 43 54 + 37 22 43 8 + 35 23 44 2 + 30 20 43 11 + 39 30 47 2870 + 42 33 44 585 + 26 17 45 2 + 41 29 47 79 + 40 24 46 836 + 33 19 45 201 + 34 21 39 13 + 33 21 49 60 + 35 24 44 248 + 33 24 43 24 + 39 29 44 151 + 31 23 46 1 + 36 23 46 1 + 41 27 47 5565 + 42 26 47 378 + 35 27 45 4571 + 40 30 47 6422 + 32 20 42 8 + 38 28 45 449 + 38 26 47 595 + 39 24 47 1555 + 41 25 49 645 + 32 19 40 8 + 35 25 45 97 + 25 0 0 0 + 30 19 44 25 + 31 18 45 1 + 41 24 51 6915 + 34 23 46 1917 + 30 19 43 2 + 35 22 47 20 + 38 23 43 882 + 30 20 48 5 + 37 25 44 919 + 34 20 45 74 + 38 25 46 394 + 39 21 49 738 + 35 20 47 22 + 40 30 47 190 + 41 27 45 1515 + 39 27 49 55 + 35 25 41 994 + 39 27 47 7117 + 37 22 46 19 + 33 21 41 2 + 34 18 47 19 + 30 20 46 6 + 31 21 46 1 + 36 24 47 98 + 40 24 43 39 + 38 25 45 138 + 41 27 47 33 + 40 29 49 2510 + 36 26 43 2 + 34 21 45 1 + 40 26 49 1924 + 36 17 43 2 + 38 27 45 68 + 34 22 45 61 + 32 22 40 8 + 37 19 43 4784 + 32 16 43 8 + 38 27 50 46 + 35 21 43 38 + 35 22 49 4 + 38 27 49 31 + 39 28 47 4677 + 30 18 45 2 + 43 28 47 8235 + 38 28 43 830 + 32 21 47 15 + 37 24 42 10 + 37 23 45 259 + 37 25 45 35 + 40 24 45 524 + 35 19 44 1 + 36 23 45 84 + 36 24 50 17 + 31 20 46 1 + 35 24 42 74 + 42 27 47 1445 + 40 28 48 31 + 36 23 45 151 + 34 22 46 6 + 33 24 49 16 + 30 20 45 2 + 38 22 43 125 + 40 25 49 64 + 35 23 49 86 + 38 24 46 613 + 42 25 47 4232 + 34 24 43 31 + 32 18 41 2 + 37 26 43 70 + 37 27 41 14 + 37 22 39 129 + 38 27 49 3 + 32 22 47 15 + 41 27 41 472 + 38 24 43 25 + 35 28 43 309 + 41 25 47 82 + 40 23 43 8 + 40 21 43 1716 + 38 22 48 5 + 37 20 47 22 + 42 28 43 315 + 32 23 43 79 + 25 0 0 0 + 42 23 47 2245 + 35 24 45 2 + 41 25 44 12 + 36 23 43 1 + 36 19 45 151 + 41 28 45 2207 + 40 27 45 76 + 34 20 47 6 + 41 28 46 370 + 38 20 45 12 + 32 20 43 8 + 39 24 45 8 + 41 27 47 26941 + 35 23 46 3 + 34 25 41 14 + 43 27 47 26905 + 35 25 45 2 + 32 20 50 3 + 31 17 41 2 + 38 26 47 4157 + 33 24 41 2 + 41 29 43 26513 + 35 22 45 297 + 37 26 44 99 + 33 19 43 10 + 39 23 45 138 + 39 26 47 1320 + 33 22 42 2 + 42 32 45 791 + 33 23 51 3 + 38 25 43 8 + 40 27 49 1210 + 43 27 45 32969 + 37 26 49 108 + 38 18 45 1268 + 40 28 49 7810 + 36 25 44 47 + 38 27 48 20 + 34 20 44 10 + 41 27 45 429 + 33 18 43 8 + 29 17 45 1 + 40 25 42 9 + 30 21 49 4 + 37 22 45 10 + 23 0 0 0 + 36 15 45 2509 + 29 21 45 18 + 33 23 45 53 + 43 27 49 7533 + 37 28 45 2652 + 36 24 49 31 + 32 20 43 25 + 42 27 49 1500 + 41 26 45 8 + 40 25 47 152 + 37 26 45 151 + 37 27 43 139 + 34 20 47 4 + 31 21 43 44 + 37 28 45 241 + 35 25 45 422 + 33 22 45 6 + 39 26 48 23 + 38 27 49 359 + 42 26 45 1430 + 36 28 47 116 + 33 23 41 232 + 38 25 47 73 + 35 24 43 16 + 42 29 47 398 + 38 27 49 2203 + 32 20 47 3 + 32 18 48 3 + 36 23 47 44 + 37 24 48 147 + 39 22 45 31 + 31 20 44 1 + 34 21 43 8 + 39 27 47 201 + 34 23 44 12 + 34 24 43 8 + 36 17 46 2 + 41 27 47 8709 + 41 26 45 112 + 37 23 47 216 + 38 24 45 93 + 32 19 45 44 + 34 22 45 8 + 33 24 41 14 + 34 22 41 9 + 35 23 42 136 + 36 26 43 3272 + 34 18 44 40 + 38 25 43 316 + 29 23 39 9 + 35 23 45 2 + 41 29 42 136 + 37 26 43 12 + 34 21 46 43 + 39 21 47 23 + 40 29 49 14666 + 36 19 45 400 + 37 24 43 8 + 35 19 44 2 + 36 26 45 14 + 36 22 43 103 + 33 19 45 6 + 35 24 43 1 + 31 22 43 80 + 35 23 46 22 + 28 18 41 2 + 35 24 45 31 + 34 24 47 46 + 37 24 42 2 + 37 27 43 525 + 31 16 41 9 + 30 18 45 2 + 39 25 47 1416 + 37 24 46 23 + 40 28 49 5 + 39 26 46 2071 + 28 13 42 8 + 31 17 47 3 + 34 22 49 3 + 42 23 47 61 + 30 21 41 2 + 40 23 47 208 + 38 22 48 6 + 35 17 40 8 + 36 20 45 32 + 37 22 47 1116 + 41 28 47 14145 + 43 28 49 96342 + 35 19 45 102 + 31 23 43 8 + 33 20 43 1 + 30 19 46 90 + 41 27 45 19090 + 35 26 45 2942 + 40 25 47 127 + 35 23 45 12 + 37 26 46 76 + 31 19 44 32 + 42 31 49 4951 + 43 30 44 38924 + 35 19 51 17 + 41 31 44 6637 + 33 22 42 2 + 33 25 46 12 + 31 24 44 10 + 27 16 49 4 + 39 24 45 16 + 33 20 40 8 + 39 31 48 5073 + 39 21 47 72 + 35 21 47 3 + 38 27 41 1168 + 35 22 43 8 + 28 18 45 1 + 38 28 40 776 + 33 22 51 3 + 34 22 41 370 + 37 25 43 3210 + 32 24 43 8 + 35 24 46 3 + 39 20 45 41 + 35 17 43 49 + 39 29 46 20 + 31 21 44 1 + 43 24 48 4400 + 36 23 48 350 + 38 29 47 520 + 36 24 45 49 + 39 27 43 493 + 34 15 45 6 + 41 31 43 59993 + 34 24 42 27 + 31 14 41 1 + 40 30 47 13295 + 35 23 47 202 + 36 22 47 35 + 38 26 45 18576 + 34 26 43 54 + 40 30 51 173 + 43 29 47 105 + 34 24 39 9 + 33 20 43 8 + 35 27 45 65 + 31 18 42 2 + 31 21 45 6 + 40 27 45 979 + 36 21 47 3 + 29 14 43 1 + 37 24 47 432 + 39 24 50 4778 + 33 20 44 2 + 40 27 44 7398 + 36 22 47 148 + 35 21 44 11 + 35 22 45 206 + 30 18 42 8 + 40 30 43 8 + 30 22 42 9 + 29 21 39 9 + 41 26 43 1248 + 39 24 43 14 + 38 24 49 605 + 35 20 42 155 + 33 22 47 53 + 34 20 43 10 + 35 26 49 21 + 31 18 45 1 + 32 19 39 9 + 31 20 43 19 + 41 23 41 157 + 36 23 42 9 + 28 19 45 1 + 33 19 43 10 + 38 22 44 25 + 29 19 41 2 + 34 19 42 8 + 35 21 39 9 + 34 23 45 2 + 41 30 47 71025 + 40 26 48 3059 + 36 24 45 1346 + 35 19 47 34 + 36 25 45 112 + 39 27 41 7065 + 38 24 47 4 + 29 18 42 1 + 30 20 41 2 + 32 22 49 3 + 40 29 45 4589 + 38 25 42 234 + 42 28 49 3171 + 35 22 45 34 + 39 24 41 5693 + 29 20 43 2 + 29 16 44 14 + 37 25 45 19 + 36 18 44 8 + 36 27 45 1224 + 38 28 47 8906 + 29 15 51 3 + 33 20 47 46 + 33 17 41 9 + 40 22 45 1775 + 32 22 45 8 + 35 21 43 8 + 38 24 41 9 + 41 22 47 10005 + 36 27 43 12 + 33 21 47 35 + 35 21 39 9 + 34 22 44 2 + 34 17 45 67 + 31 18 45 1 + 34 21 46 32 + 35 26 44 1 + 34 23 44 8 + 31 24 47 3 + 43 23 49 9210 + 40 20 48 114 + 36 25 42 8 + 37 24 46 336 + 37 23 43 138 + 38 26 47 89 + 38 24 47 6494 + 30 18 45 1 + 43 28 47 677 + 31 23 48 3 + 32 19 43 1 + 36 23 44 19 + 43 30 47 81276 + 37 22 48 106 + 37 24 45 12 + 37 22 45 68 + 28 17 43 24 + 43 28 45 1446 + 40 30 46 2753 + 35 23 44 1 + 28 16 43 2 + 29 19 42 2 + 31 21 42 2 + 39 26 48 98 + 41 30 47 21848 + 35 22 47 5 + 40 31 45 448 + 34 23 45 94 + 29 17 42 8 + 39 30 46 1231 + 41 22 47 49 + 30 15 51 7 + 35 26 41 9 + 29 17 49 7 + 33 22 43 12 + 33 19 46 5 + 35 24 45 12 + 33 22 42 9 + 34 18 43 13 + 36 21 43 63 + 37 27 45 32 + 37 23 49 474 + 31 17 46 19 + 38 24 41 2 + 40 28 47 1621 + 39 25 47 214 + 32 21 42 19 + 34 22 47 105 + 35 26 42 2 + 35 21 44 13 + 40 25 47 556 + 39 27 49 3 + 36 25 45 32 + 39 27 41 10 + 35 20 45 1 + 28 17 45 1 + 35 23 47 6 + 33 20 50 137 + 34 22 43 177 + 30 19 41 9 + 33 23 47 579 + 33 22 39 9 + 39 20 42 74 + 42 28 47 112 + 40 29 44 197 + 36 23 43 2 + 30 17 49 3 + 37 27 45 3815 + 35 24 43 74 + 35 22 47 24 + 40 27 46 82 + 36 25 41 366 + 33 23 44 1 + 37 21 40 131 + 34 22 45 16 + 36 24 45 306 + 39 26 47 82 + 29 17 45 1 + 36 23 48 3 + 35 20 44 63 + 35 23 46 5 + 39 25 43 792 + 32 22 49 5 + 35 23 41 9 + 37 24 41 12711 + 41 32 43 36575 + 34 23 42 8 + 31 21 43 2 + 35 24 41 2 + 35 24 39 8 + 37 23 48 75 + 35 19 43 12 + 40 25 49 914 + 38 22 49 60 + 34 19 42 10 + 42 33 44 9038 + 37 27 45 1849 + 29 20 42 138 + 37 27 43 332 + 36 26 45 36 + 32 18 45 6 + 37 25 46 4676 + 29 18 45 6 + 34 22 43 8 + 41 32 45 1966 + 30 18 42 12 + 33 20 45 1 + 31 23 45 6 + 30 21 46 1 + 36 21 43 14 + 34 18 45 37 + 42 32 47 3508 + 41 32 41 13 + 37 25 45 719 + 33 20 45 111 + 38 28 42 8 + 35 23 43 14 + 39 23 47 123 + 28 13 44 1 + 34 19 41 38 + 35 21 43 8 + 33 26 47 124 + 30 18 41 9 + 43 30 46 11935 + 40 28 48 2329 + 35 19 45 286 + 30 21 43 80 + 37 21 49 474 + 41 27 49 1560 + 42 24 46 1802 + 38 28 42 6807 + 38 24 43 63 + 33 24 49 35 + 41 27 41 9795 + 29 16 41 2 + 29 17 43 2 + 34 21 45 125 + 39 28 45 1008 + 34 21 42 8 + 36 23 45 2 + 34 22 41 8 + 34 21 41 74 + 37 21 43 262 + 30 18 41 8 + 33 22 49 3 + 33 21 42 1 + 35 28 49 21 + 31 19 43 1 + 36 24 44 10 + 40 23 49 583 + 33 19 37 9 + 32 21 45 6 + 38 24 47 15 + 42 27 47 2847 + 36 28 45 106 + 39 28 43 53 + 30 16 42 2 + 28 18 49 3 + 33 21 44 1 + 36 24 45 3050 + 37 27 40 8 + 35 19 43 12 + 41 29 43 19008 + 21 0 0 0 + 38 26 41 762 + 33 21 46 12 + 41 26 47 14517 + 33 24 49 3 + 41 31 47 287 + 35 24 51 17 + 37 27 42 38 + 34 22 43 24 + 39 26 46 135 + 38 26 41 493 + 35 22 42 8 + 38 24 41 1082 + 32 23 42 1 + 33 24 40 8 + 37 25 48 640 + 28 14 39 9 + 39 20 45 212 + 37 29 45 610 + 34 26 47 57 + 29 21 41 8 + 35 16 45 53 + 35 21 44 2 + 38 26 48 188 + 34 25 41 10 + 36 23 44 8 + 35 21 45 8 + 35 26 41 8 + 37 26 40 9 + 28 12 43 1 + 34 22 51 3 + 35 25 44 13 + 32 16 44 32 + 32 19 45 143 + 29 17 43 1 + 35 22 43 93 + 38 21 43 99 + 36 26 49 242 + 34 22 45 8 + 40 24 45 136 + 40 24 48 88 + 38 21 46 49 + 40 27 49 116 + 41 26 44 3696 + 35 23 42 8 + 28 15 45 104 + 33 21 43 106 + 35 25 45 31 + 33 24 40 113 + 36 24 46 23 + 37 25 45 334 + 32 21 46 12 + 35 21 41 2 + 36 22 45 8 + 37 18 43 13 + 37 26 47 48 + 39 25 46 400 + 37 27 43 174 + 37 23 47 41 + 40 21 47 1811 + 38 26 45 79 + 26 15 43 1 + 39 27 49 19 + 31 19 44 1 + 37 22 43 8 + 32 24 38 9 + 34 23 48 3 + 37 24 51 22 + 27 18 42 2 + 31 22 47 5 + 33 17 41 2 + 40 28 45 14534 + 37 21 47 5 + 27 15 43 2 + 43 26 47 46658 + 39 22 43 8 + 36 23 41 2 + 31 19 43 12 + 36 24 43 10 + 33 20 43 149 + 30 19 47 3 + 39 27 51 1236 + 41 26 45 4744 + 39 22 47 100 + 32 18 44 6 + 32 21 43 54 + 40 30 46 777 + 35 25 43 355 + 36 24 41 138 + 40 30 47 3056 + 39 28 46 19 + 34 21 46 6 + 34 18 46 52 + 36 27 41 232 + 35 25 51 3 + 36 28 44 110 + 33 23 45 1 + 37 22 46 64301 + 39 23 49 41 + 39 30 40 25 + 36 23 48 6 + 29 17 42 2 + 36 23 44 1 + 32 17 43 40 + 32 16 49 86 + 29 19 49 5 + 38 26 41 9 + 40 28 43 56710 + 41 29 45 1711 + 36 23 49 345 + 35 25 43 8 + 35 24 46 19 + 37 23 41 648 + 30 18 45 1 + 30 21 43 1 + 34 20 45 12 + 42 25 47 431 + 40 27 41 15878 + 34 22 43 8 + 41 29 48 49 + 32 21 43 2 + 37 22 43 2 + 39 28 49 86 + 43 28 45 8032 + 41 30 49 15674 + 34 22 48 17 + 36 24 48 107 + 28 20 44 1 + 43 28 48 1986 + 40 25 47 2585 + 38 21 43 59 + 38 28 41 167 + 34 22 39 9 + 43 27 48 4196 + 32 20 44 120 + 33 25 45 99 + 26 12 42 2 + 26 15 47 4 + 37 21 42 10 + 35 25 49 3 + 42 30 49 11151 + 33 20 44 2 + 39 26 45 65238 + 31 16 40 2 + 38 26 39 8 + 36 22 45 82 + 32 22 49 7 + 33 20 45 2 + 40 24 43 12 + 32 18 50 3 + 31 21 40 2 + 34 18 44 2 + 38 28 46 194 + 36 21 43 12 + 32 20 43 8 + 30 18 42 2 + 37 21 47 31 + 36 23 47 15 + 36 21 45 113 + 34 23 44 1 + 43 29 49 3889 + 37 24 47 32 + 41 22 43 243 + 38 25 47 707 + 35 22 43 18399 + 33 22 45 123 + 37 24 42 8 + 39 25 47 1087 + 34 23 47 107 + 32 21 42 2 + 42 25 47 106 + 39 24 42 13560 + 42 29 49 52387 + 38 27 43 59 + 31 18 39 9 + 40 28 48 41 + 37 25 45 11 + 30 23 45 242 + 38 23 47 1673 + 36 23 45 751 + 29 22 41 2 + 36 19 48 3 + 36 22 45 12 + 35 18 47 20 + 40 28 49 17369 + 29 19 46 2 + 36 26 42 25 + 42 30 49 4767 + 30 20 45 6 + 35 24 44 12 + 41 24 42 1537 + 38 25 47 629 + 31 21 44 2 + 34 22 43 1 + 33 20 47 3 + 34 20 43 8 + 40 26 49 4320 + 31 16 43 9 + 34 22 45 8 + 32 22 46 124 + 32 20 43 13 + 40 28 47 1185 + 41 24 45 30643 + 39 23 43 1658 + 33 23 44 8 + 36 22 46 23 + 41 25 47 114 + 36 21 42 12 + 33 19 48 31 + 42 28 48 76 + 29 22 39 9 + 36 21 47 3 + 37 27 45 282 + 42 29 46 24995 + 36 26 39 9 + 40 25 46 123 + 39 26 41 8 + 41 30 45 3143 + 34 20 41 27 + 38 31 42 17297 + 40 24 51 3052 + 36 28 45 190 + 31 23 42 8 + 42 26 42 68 + 39 31 45 37327 + 37 27 41 8 + 36 20 45 76 + 38 26 42 10 + 36 21 45 63 + 40 31 43 140 + 40 27 49 21 + 31 22 36 9 + 34 22 39 9 + 29 17 43 2 + 36 26 45 61 + 38 23 45 15 + 31 21 43 54 + 36 22 41 93 + 31 18 43 2 + 35 25 49 108 + 41 29 45 18292 + 37 25 45 104 + 28 20 41 2 + 35 26 46 35 + 34 20 46 19 + 38 22 51 183 + 34 14 43 8 + 32 23 43 16 + 27 17 44 1 + 29 15 42 2 + 37 26 41 129 diff --git a/lib/ftrsd/ftrsd_paper/stats_0.0 b/lib/ftrsd/ftrsd_paper/stats_0.0 index f051da94..75c97780 100755 --- a/lib/ftrsd/ftrsd_paper/stats_0.0 +++ b/lib/ftrsd/ftrsd_paper/stats_0.0 @@ -1,27 +1,27 @@ - SNR Files Sync BM FT Hint Total False BadSync --------------------------------------------------------- --18.0 1000 1000 1000 1000 1000 1000 0 0 --18.5 1000 1000 1000 1000 1000 1000 0 0 --19.0 1000 1000 1000 1000 1000 1000 0 0 --19.5 1000 1000 1000 1000 1000 1000 0 0 --20.0 1000 1000 1000 1000 1000 1000 0 0 --20.5 1000 1000 1000 1000 1000 1000 0 0 --21.0 1000 1000 1000 1000 1000 1000 0 0 --21.5 1000 1000 991 1000 1000 1000 0 0 --22.0 1000 1000 918 1000 1000 1000 0 0 --22.5 1000 1000 631 1000 1000 1000 0 0 --23.0 1000 1000 261 1000 1000 1000 0 0 --23.5 1000 1000 57 990 1000 1000 0 0 --24.0 1000 1000 0 925 1000 1000 0 0 --24.5 1000 1000 0 737 1000 1000 0 0 --25.0 1000 999 0 445 999 999 1 ? --25.5 1000 996 0 191 996 996 2 ? --26.0 1000 980 0 68 985 985 3 ? --26.5 1000 953 0 18 975 975 3 ? --27.0 1000 904 0 3 926 926 4 ? --27.5 1000 816 0 2 874 874 3 ? --28.0 1000 722 0 0 786 786 7 ? --28.5 1000 590 0 0 616 616 12 ? --29.0 1000 451 0 0 479 479 15 ? --29.5 1000 355 0 0 303 303 27 ? --30.0 1000 277 0 0 173 173 28 ? + SNR Files Sync BM FT Hint Total False BadSync +-------------------------------------------------------- +-18.0 1000 1000 1000 1000 1000 1000 0 0 +-18.5 1000 1000 1000 1000 1000 1000 0 0 +-19.0 1000 1000 1000 1000 1000 1000 0 0 +-19.5 1000 1000 1000 1000 1000 1000 0 0 +-20.0 1000 1000 1000 1000 1000 1000 0 0 +-20.5 1000 1000 1000 1000 1000 1000 0 0 +-21.0 1000 1000 1000 1000 1000 1000 0 0 +-21.5 1000 1000 991 1000 1000 1000 0 0 +-22.0 1000 1000 918 1000 1000 1000 0 0 +-22.5 1000 1000 631 1000 1000 1000 0 0 +-23.0 1000 1000 261 1000 1000 1000 0 0 +-23.5 1000 1000 57 990 1000 1000 0 0 +-24.0 1000 1000 0 925 1000 1000 0 0 +-24.5 1000 1000 0 737 1000 1000 0 0 +-25.0 1000 999 0 445 999 999 1 ? +-25.5 1000 996 0 191 996 996 2 ? +-26.0 1000 980 0 68 985 985 3 ? +-26.5 1000 953 0 18 975 975 3 ? +-27.0 1000 904 0 3 926 926 4 ? +-27.5 1000 816 0 2 874 874 3 ? +-28.0 1000 722 0 0 786 786 7 ? +-28.5 1000 590 0 0 616 616 12 ? +-29.0 1000 451 0 0 479 479 15 ? +-29.5 1000 355 0 0 303 303 27 ? +-30.0 1000 277 0 0 173 173 28 ? diff --git a/lib/ftrsd/ftrsd_paper/stats_0.2 b/lib/ftrsd/ftrsd_paper/stats_0.2 index 7a26d992..1e0cb00c 100755 --- a/lib/ftrsd/ftrsd_paper/stats_0.2 +++ b/lib/ftrsd/ftrsd_paper/stats_0.2 @@ -1,27 +1,27 @@ - SNR Files Sync BM FT Hint Total False BadSync --------------------------------------------------------- --18.0 1000 998 973 998 998 998 0 2 --18.5 1000 1000 960 1000 1000 1000 0 0 --19.0 1000 1000 917 1000 1000 1000 0 0 --19.5 1000 1000 849 1000 1000 1000 0 0 --20.0 1000 1000 725 1000 1000 1000 0 0 --20.5 1000 1000 549 1000 1000 1000 0 0 --21.0 1000 1000 373 1000 1000 1000 0 0 --21.5 1000 1000 216 1000 1000 1000 0 0 --22.0 1000 1000 100 998 1000 1000 0 0 --22.5 1000 1000 32 998 1000 1000 0 0 --23.0 1000 1000 12 991 1000 1000 0 0 --23.5 1000 998 2 958 1000 1000 0 2 --24.0 1000 992 0 878 998 998 1 8 --24.5 1000 986 0 739 995 995 0 14 --25.0 1000 977 0 533 991 991 0 23 --25.5 1000 959 0 324 975 975 3 41 --26.0 1000 930 0 153 953 953 1 70 --26.5 1000 874 0 51 924 924 8 126 --27.0 1000 808 0 14 866 866 6 192 --27.5 1000 716 0 3 799 799 10 284 --28.0 1000 610 0 1 689 689 14 390 --28.5 1000 497 0 0 596 596 19 503 --29.0 1000 399 0 0 451 451 21 601 --29.5 1000 300 0 0 270 270 27 700 --30.0 1000 243 0 0 172 172 26 757 + SNR Files Sync BM FT Hint Total False BadSync +-------------------------------------------------------- +-18.0 1000 998 973 998 998 998 0 2 +-18.5 1000 1000 960 1000 1000 1000 0 0 +-19.0 1000 1000 917 1000 1000 1000 0 0 +-19.5 1000 1000 849 1000 1000 1000 0 0 +-20.0 1000 1000 725 1000 1000 1000 0 0 +-20.5 1000 1000 549 1000 1000 1000 0 0 +-21.0 1000 1000 373 1000 1000 1000 0 0 +-21.5 1000 1000 216 1000 1000 1000 0 0 +-22.0 1000 1000 100 998 1000 1000 0 0 +-22.5 1000 1000 32 998 1000 1000 0 0 +-23.0 1000 1000 12 991 1000 1000 0 0 +-23.5 1000 998 2 958 1000 1000 0 2 +-24.0 1000 992 0 878 998 998 1 8 +-24.5 1000 986 0 739 995 995 0 14 +-25.0 1000 977 0 533 991 991 0 23 +-25.5 1000 959 0 324 975 975 3 41 +-26.0 1000 930 0 153 953 953 1 70 +-26.5 1000 874 0 51 924 924 8 126 +-27.0 1000 808 0 14 866 866 6 192 +-27.5 1000 716 0 3 799 799 10 284 +-28.0 1000 610 0 1 689 689 14 390 +-28.5 1000 497 0 0 596 596 19 503 +-29.0 1000 399 0 0 451 451 21 601 +-29.5 1000 300 0 0 270 270 27 700 +-30.0 1000 243 0 0 172 172 26 757 diff --git a/lib/ftrsd/ftrsd_paper/stats_1.0 b/lib/ftrsd/ftrsd_paper/stats_1.0 index df5e789e..34f94c62 100755 --- a/lib/ftrsd/ftrsd_paper/stats_1.0 +++ b/lib/ftrsd/ftrsd_paper/stats_1.0 @@ -1,27 +1,27 @@ - SNR Files Sync BM FT Hint Total False BadSync --------------------------------------------------------- --18.0 1000 998 917 998 998 998 1 2 --18.5 1000 998 824 998 998 998 0 2 --19.0 1000 999 695 999 999 999 0 1 --19.5 1000 999 504 999 999 999 0 1 --20.0 1000 1000 300 1000 1000 1000 0 0 --20.5 1000 1000 148 1000 1000 1000 0 0 --21.0 1000 1000 56 1000 1000 1000 0 0 --21.5 1000 1000 10 1000 1000 1000 0 0 --22.0 1000 999 3 995 1000 1000 0 1 --22.5 1000 998 0 972 1000 1000 0 2 --23.0 1000 997 0 899 999 999 0 3 --23.5 1000 996 0 758 999 999 0 4 --24.0 1000 990 0 545 999 999 0 10 --24.5 1000 981 0 305 988 988 2 19 --25.0 1000 964 0 128 987 987 0 36 --25.5 1000 930 0 43 956 956 4 70 --26.0 1000 870 0 15 932 932 4 130 --26.5 1000 810 0 4 889 889 8 190 --27.0 1000 737 0 0 798 798 9 263 --27.5 1000 632 0 0 650 650 10 368 --28.0 1000 522 0 0 526 526 15 478 --28.5 1000 426 0 0 383 383 19 574 --29.0 1000 332 0 0 226 226 34 668 --29.5 1000 260 0 0 136 136 32 740 --30.0 1000 209 0 0 64 64 47 791 + SNR Files Sync BM FT Hint Total False BadSync +-------------------------------------------------------- +-18.0 1000 998 917 998 998 998 1 2 +-18.5 1000 998 824 998 998 998 0 2 +-19.0 1000 999 695 999 999 999 0 1 +-19.5 1000 999 504 999 999 999 0 1 +-20.0 1000 1000 300 1000 1000 1000 0 0 +-20.5 1000 1000 148 1000 1000 1000 0 0 +-21.0 1000 1000 56 1000 1000 1000 0 0 +-21.5 1000 1000 10 1000 1000 1000 0 0 +-22.0 1000 999 3 995 1000 1000 0 1 +-22.5 1000 998 0 972 1000 1000 0 2 +-23.0 1000 997 0 899 999 999 0 3 +-23.5 1000 996 0 758 999 999 0 4 +-24.0 1000 990 0 545 999 999 0 10 +-24.5 1000 981 0 305 988 988 2 19 +-25.0 1000 964 0 128 987 987 0 36 +-25.5 1000 930 0 43 956 956 4 70 +-26.0 1000 870 0 15 932 932 4 130 +-26.5 1000 810 0 4 889 889 8 190 +-27.0 1000 737 0 0 798 798 9 263 +-27.5 1000 632 0 0 650 650 10 368 +-28.0 1000 522 0 0 526 526 15 478 +-28.5 1000 426 0 0 383 383 19 574 +-29.0 1000 332 0 0 226 226 34 668 +-29.5 1000 260 0 0 136 136 32 740 +-30.0 1000 209 0 0 64 64 47 791 diff --git a/lib/ftrsd/ftrsd_paper/wer2.lab b/lib/ftrsd/ftrsd_paper/wer2.lab index e0ce7e49..b3440f83 100755 --- a/lib/ftrsd/ftrsd_paper/wer2.lab +++ b/lib/ftrsd/ftrsd_paper/wer2.lab @@ -1,7 +1,7 @@ --25.7 30 $10^5$ --25.25 36 $10^4$ --24.5 44 $10^3$ --24.15 48 $10^2$ --23.7 44 10 --22.5 48 BM +-25.7 30 $10^5$ +-25.25 36 $10^4$ +-24.5 44 $10^3$ +-24.15 48 $10^2$ +-23.7 44 10 +-22.5 48 BM -25.2 24 KV \ No newline at end of file diff --git a/lib/ftrsd/ftrsdap.c b/lib/ftrsd/ftrsdap.c index bb9d2f17..b2b85ddd 100755 --- a/lib/ftrsd/ftrsdap.c +++ b/lib/ftrsd/ftrsdap.c @@ -1,227 +1,227 @@ -/* - ftrsdap.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 -#include -#include -#include -#include -#include "../ftrsd/rs2.h" - -static void *rs; -void getpp_(int workdat[], float *pp); - -void ftrsdap_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[], - int ap[], 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]; - } - -// Set ap symbols and ap mask - for (i=0; i<12; i++) { - if(ap[i]>=0) { - rxdat[11-i]=ap[i]; - rxprob2[11-i]=-1; - } - } - -// 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=0 ) { - ratio = (float)rxprob2[j]/((float)rxprob[j]+0.01); - ii = 7.999*ratio; - jj = (62-i)/8; - thresh0[i] = 1.3*perr[ii][jj]; - } else { - thresh0[i] = 0.0; - } -//printf("%d %d %d\n",i,j,rxdat[i]); - } - - 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= 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]=1000.0*pp2/pp1; - 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; -} +/* + ftrsdap.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 +#include +#include +#include +#include +#include "../ftrsd/rs2.h" + +static void *rs; +void getpp_(int workdat[], float *pp); + +void ftrsdap_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[], + int ap[], 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]; + } + +// Set ap symbols and ap mask + for (i=0; i<12; i++) { + if(ap[i]>=0) { + rxdat[11-i]=ap[i]; + rxprob2[11-i]=-1; + } + } + +// 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=0 ) { + ratio = (float)rxprob2[j]/((float)rxprob[j]+0.01); + ii = 7.999*ratio; + jj = (62-i)/8; + thresh0[i] = 1.3*perr[ii][jj]; + } else { + thresh0[i] = 0.0; + } +//printf("%d %d %d\n",i,j,rxdat[i]); + } + + 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= 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]=1000.0*pp2/pp1; + 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/lib/ftrsd/init_rs.c b/lib/ftrsd/init_rs.c index 528b8db3..4b1d1edb 100755 --- a/lib/ftrsd/init_rs.c +++ b/lib/ftrsd/init_rs.c @@ -1,119 +1,119 @@ -/* Initialize a RS codec - * - * Copyright 2002 Phil Karn, KA9Q - * May be used under the terms of the GNU General Public License (GPL) - */ -#include - -#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; - - if(symsize > 8*sizeof(DTYPE)) - return NULL; /* Need version with ints rather than chars */ - - if(fcr >= (1<= (1<= (1<mm = symsize; - rs->nn = (1<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;inn;i++){ - rs->index_of[sr] = i; - rs->alpha_to[i] = sr; - sr <<= 1; - if(sr & (1<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 + +#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; + + if(symsize > 8*sizeof(DTYPE)) + return NULL; /* Need version with ints rather than chars */ + + if(fcr >= (1<= (1<= (1<mm = symsize; + rs->nn = (1<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;inn;i++){ + rs->index_of[sr] = i; + rs->alpha_to[i] = sr; + sr <<= 1; + if(sr & (1<nn; + } + if(sr != 1){ + /* field generator polynomial is not primitive! */ + free(rs->alpha_to); + free(rs->index_of); + free(rs); + return NULL; + } + + /* Form RS code generator polynomial from its roots */ + rs->genpoly = (DTYPE *)malloc(sizeof(DTYPE)*(nroots+1)); + if(rs->genpoly == NULL){ + free(rs->alpha_to); + free(rs->index_of); + free(rs); + return NULL; + } + rs->fcr = fcr; + rs->prim = prim; + rs->nroots = nroots; + + /* Find prim-th root of 1, used in decoding */ + for(iprim=1;(iprim % prim) != 0;iprim += rs->nn) + ; + rs->iprim = iprim / prim; + + rs->genpoly[0] = 1; + for (i = 0,root=fcr*prim; i < nroots; i++,root += prim) { + rs->genpoly[i+1] = 1; + + /* Multiply rs->genpoly[] by @**(root + x) */ + for (j = i; j > 0; j--){ + if (rs->genpoly[j] != 0) + rs->genpoly[j] = rs->genpoly[j-1] ^ rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[j]] + root)]; + else + rs->genpoly[j] = rs->genpoly[j-1]; + } + /* rs->genpoly[0] can never be zero */ + rs->genpoly[0] = rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[0]] + root)]; + } + /* convert rs->genpoly[] to index form for quicker encoding */ + for (i = 0; i <= nroots; i++) + rs->genpoly[i] = rs->index_of[rs->genpoly[i]]; + + return rs; +} diff --git a/lib/ftrsd/int.h b/lib/ftrsd/int.h index 3c4f26a6..ada5bfd4 100755 --- a/lib/ftrsd/int.h +++ b/lib/ftrsd/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<= 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<= 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/lib/ftrsd/rs2.h b/lib/ftrsd/rs2.h index ab65fb01..c2b807d1 100755 --- a/lib/ftrsd/rs2.h +++ b/lib/ftrsd/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/lib/ftrsd/rsdtest.f90 b/lib/ftrsd/rsdtest.f90 index 1de8aadb..2c862e5a 100755 --- a/lib/ftrsd/rsdtest.f90 +++ b/lib/ftrsd/rsdtest.f90 @@ -1,34 +1,34 @@ -program rsdtest - - real s3(64,63) - character msg*22,arg*12 - integer param(0:7) - - nargs=iargc() - if(nargs.ne.2) then - print*,'Usage: rsdtest ntrials nfiles' - go to 999 - endif - call getarg(1,arg) - read(arg,*) ntrials - call getarg(2,arg) - read(arg,*) nfiles - - open(10,file='s3_1000.bin',access='stream', status='old') - open(22,file='kvasd.dat',access='direct',recl=1024,status='unknown') - - nadd=1 - ifile0=0 - if(nfiles.lt.0) then - ifile0=-nfiles - nfiles=99999 - endif - - do ifile=1,nfiles - read(10,end=999) s3 - if(ifile.lt.ifile0) cycle - call extract2(s3,nadd,ntrials,param,msg) - if(ifile.eq.ifile0) exit - enddo - -999 end program rsdtest +program rsdtest + + real s3(64,63) + character msg*22,arg*12 + integer param(0:7) + + nargs=iargc() + if(nargs.ne.2) then + print*,'Usage: rsdtest ntrials nfiles' + go to 999 + endif + call getarg(1,arg) + read(arg,*) ntrials + call getarg(2,arg) + read(arg,*) nfiles + + open(10,file='s3_1000.bin',access='stream', status='old') + open(22,file='kvasd.dat',access='direct',recl=1024,status='unknown') + + nadd=1 + ifile0=0 + if(nfiles.lt.0) then + ifile0=-nfiles + nfiles=99999 + endif + + do ifile=1,nfiles + read(10,end=999) s3 + if(ifile.lt.ifile0) cycle + call extract2(s3,nadd,ntrials,param,msg) + if(ifile.eq.ifile0) exit + enddo + +999 end program rsdtest diff --git a/lib/ftrsd/sfrsd.c b/lib/ftrsd/sfrsd.c index e6b80181..e64dfc96 100755 --- a/lib/ftrsd/sfrsd.c +++ b/lib/ftrsd/sfrsd.c @@ -1,137 +1,137 @@ -/* - sfrsd.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, Urbana IL, September 2015 - */ - -#include -#include -#include -#include -#include -#include "sfrsd2.h" - -//*************************************************************************** -void usage(void) -{ - printf("Usage: sfrsd [options...] \n"); - printf(" input file should be in kvasd format\n"); - printf("\n"); - printf("Options:\n"); - printf(" -n number of random erasure vectors to try\n"); - printf(" -v verbose\n"); -} - -int main(int argc, char *argv[]){ - - extern char *optarg; - extern int optind; - - int correct[63], indx[63], param[8]; - int c,i; - char *infile; - - FILE *datfile, *logfile; - int nsec, maxe, nads; - float xlambda; - int mrsym[63],mrprob[63],mr2sym[63],mr2prob[63]; - int nsec2,ncount,dat4[12]; - int ntrials, nverbose, ntry; - int nhard; - double tt; - - ntrials=10000; - nverbose=1; - - while ( (c = getopt(argc, argv, "n:qv")) !=-1 ) { - switch (c) { - case 'n': - ntrials=(int)strtof(optarg,NULL); - printf("ntrials set to %d\n",ntrials); - break; - case 'v': - nverbose=1; - break; - case 'q': //accept (and ignore) -q option for WSJT10 compatibility - break; - case '?': - usage(); - exit(1); - } - } - - if( optind+1 > argc) { - // usage(); - // exit(1); - infile="kvasd.dat"; - } else { - infile=argv[optind]; - } - - logfile=fopen("/tmp/sfrsd.log","a"); - if( !logfile ) { - printf("Unable to open sfrsd.log\n"); - exit(1); - } - - datfile=fopen(infile,"rb"); - if( !datfile ) { - printf("Unable to open kvasd.dat\n"); - exit(1); - } else { - fread(&nsec,sizeof(int),1,datfile); - fread(&xlambda,sizeof(float),1,datfile); - fread(&maxe,sizeof(int),1,datfile); - fread(&nads,sizeof(int),1,datfile); - fread(&mrsym,sizeof(int),63,datfile); - fread(&mrprob,sizeof(int),63,datfile); - fread(&mr2sym,sizeof(int),63,datfile); - fread(&mr2prob,sizeof(int),63,datfile); - fread(&nsec2,sizeof(int),1,datfile); - fread(&ncount,sizeof(int),1,datfile); - fread(&dat4,sizeof(int),12,datfile); - fclose(datfile); - } - - sfrsd2_(mrsym,mrprob,mr2sym,mr2prob,&ntrials,&nverbose,correct,param,indx,&tt,&ntry); - nhard=param[1]; - if( nhard>=0 ) { - for (i=0; i<12; i++) { - dat4[i]=correct[11-i]; - } - } else { - nhard=-1; - memset(dat4,0,12*sizeof(int)); - } - datfile=fopen(infile,"wb"); - if( !datfile ) { - printf("Unable to open kvasd.dat\n"); - return 1; - } else { - fwrite(&nsec,sizeof(int),1,datfile); - fwrite(&xlambda,sizeof(float),1,datfile); - fwrite(&maxe,sizeof(int),1,datfile); - fwrite(&nads,sizeof(int),1,datfile); - fwrite(&mrsym,sizeof(int),63,datfile); - fwrite(&mrprob,sizeof(int),63,datfile); - fwrite(&mr2sym,sizeof(int),63,datfile); - fwrite(&mr2prob,sizeof(int),63,datfile); - fwrite(&nsec2,sizeof(int),1,datfile); - fwrite(&nhard,sizeof(int),1,datfile); - fwrite(&dat4,sizeof(int),12,datfile); - fclose(datfile); - } - exit(0); -} - - +/* + sfrsd.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, Urbana IL, September 2015 + */ + +#include +#include +#include +#include +#include +#include "sfrsd2.h" + +//*************************************************************************** +void usage(void) +{ + printf("Usage: sfrsd [options...] \n"); + printf(" input file should be in kvasd format\n"); + printf("\n"); + printf("Options:\n"); + printf(" -n number of random erasure vectors to try\n"); + printf(" -v verbose\n"); +} + +int main(int argc, char *argv[]){ + + extern char *optarg; + extern int optind; + + int correct[63], indx[63], param[8]; + int c,i; + char *infile; + + FILE *datfile, *logfile; + int nsec, maxe, nads; + float xlambda; + int mrsym[63],mrprob[63],mr2sym[63],mr2prob[63]; + int nsec2,ncount,dat4[12]; + int ntrials, nverbose, ntry; + int nhard; + double tt; + + ntrials=10000; + nverbose=1; + + while ( (c = getopt(argc, argv, "n:qv")) !=-1 ) { + switch (c) { + case 'n': + ntrials=(int)strtof(optarg,NULL); + printf("ntrials set to %d\n",ntrials); + break; + case 'v': + nverbose=1; + break; + case 'q': //accept (and ignore) -q option for WSJT10 compatibility + break; + case '?': + usage(); + exit(1); + } + } + + if( optind+1 > argc) { + // usage(); + // exit(1); + infile="kvasd.dat"; + } else { + infile=argv[optind]; + } + + logfile=fopen("/tmp/sfrsd.log","a"); + if( !logfile ) { + printf("Unable to open sfrsd.log\n"); + exit(1); + } + + datfile=fopen(infile,"rb"); + if( !datfile ) { + printf("Unable to open kvasd.dat\n"); + exit(1); + } else { + fread(&nsec,sizeof(int),1,datfile); + fread(&xlambda,sizeof(float),1,datfile); + fread(&maxe,sizeof(int),1,datfile); + fread(&nads,sizeof(int),1,datfile); + fread(&mrsym,sizeof(int),63,datfile); + fread(&mrprob,sizeof(int),63,datfile); + fread(&mr2sym,sizeof(int),63,datfile); + fread(&mr2prob,sizeof(int),63,datfile); + fread(&nsec2,sizeof(int),1,datfile); + fread(&ncount,sizeof(int),1,datfile); + fread(&dat4,sizeof(int),12,datfile); + fclose(datfile); + } + + sfrsd2_(mrsym,mrprob,mr2sym,mr2prob,&ntrials,&nverbose,correct,param,indx,&tt,&ntry); + nhard=param[1]; + if( nhard>=0 ) { + for (i=0; i<12; i++) { + dat4[i]=correct[11-i]; + } + } else { + nhard=-1; + memset(dat4,0,12*sizeof(int)); + } + datfile=fopen(infile,"wb"); + if( !datfile ) { + printf("Unable to open kvasd.dat\n"); + return 1; + } else { + fwrite(&nsec,sizeof(int),1,datfile); + fwrite(&xlambda,sizeof(float),1,datfile); + fwrite(&maxe,sizeof(int),1,datfile); + fwrite(&nads,sizeof(int),1,datfile); + fwrite(&mrsym,sizeof(int),63,datfile); + fwrite(&mrprob,sizeof(int),63,datfile); + fwrite(&mr2sym,sizeof(int),63,datfile); + fwrite(&mr2prob,sizeof(int),63,datfile); + fwrite(&nsec2,sizeof(int),1,datfile); + fwrite(&nhard,sizeof(int),1,datfile); + fwrite(&dat4,sizeof(int),12,datfile); + fclose(datfile); + } + exit(0); +} + + diff --git a/lib/ftrsd/sfrsd2.h b/lib/ftrsd/sfrsd2.h index 39eb4877..4ef7ab47 100755 --- a/lib/ftrsd/sfrsd2.h +++ b/lib/ftrsd/sfrsd2.h @@ -1,3 +1,3 @@ -void ftrsd2_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[], - int* ntrials0, int* verbose0, int correct[], int param[], - int indexes[], double tt[], int ntry[]); +void ftrsd2_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[], + int* ntrials0, int* verbose0, int correct[], int param[], + int indexes[], double tt[], int ntry[]); diff --git a/lib/ftrsd/sfrsd3.c b/lib/ftrsd/sfrsd3.c index 164389d4..f117dcca 100755 --- a/lib/ftrsd/sfrsd3.c +++ b/lib/ftrsd/sfrsd3.c @@ -1,243 +1,243 @@ -/* - sfrsd2.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 -#include -#include -#include -#include -#include "rs2.h" - -static void *rs; - -void sfrsd2_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[], - int* ntrials0, int* verbose0, int correct[], int param[], - int indexes[], double tt[], int ntry[]) -{ - int rxdat[63], rxprob[63], rxdat2[63], rxprob2[63]; - int workdat[63],workdat2[63]; - int era_pos[51]; - int c, i, j, numera, nmr2, nerr, nn=63, kk=12; - FILE *datfile, *logfile; - int ntrials = *ntrials0; - int verbose = *verbose0; - int nhard=0,nhard_min=32768,nsoft=0,nsoft_min=32768, ncandidates; - int ngmd,nera_best; - clock_t t0=0,t1=0; - int perr[8][8] = { - 12, 31, 44, 52, 60, 57, 50, 50, - 28, 38, 49, 58, 65, 69, 64, 80, - 40, 41, 53, 62, 66, 73, 76, 81, - 50, 53, 53, 64, 70, 76, 77, 81, - 50, 50, 52, 60, 71, 72, 77, 84, - 50, 50, 56, 62, 67, 73, 81, 85, - 50, 50, 71, 62, 70, 77, 80, 85, - 50, 50, 62, 64, 71, 75, 82, 87}; - - int pmr2[8][8] = { - 4, 8, 9, 7, 6, 0, 0, 0, - 13, 18, 15, 11, 9, 7, 5, 0, - 0, 23, 21, 15, 12, 10, 7, 4, - 0, 34, 28, 20, 16, 14, 11, 7, - 0, 20, 26, 25, 19, 14, 12, 9, - 0, 0, 28, 27, 22, 19, 14, 11, - 0, 0, 40, 29, 29, 23, 18, 12, - 0, 0, 40, 35, 31, 21, 20, 13}; - - if(verbose) { - logfile=fopen("sfrsd.log","a"); - if( !logfile ) { - printf("Unable to open sfrsd.log\n"); - exit(1); - } - } - -// 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 vector 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 the mrsym probabilities to find 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 ) { - if(verbose) fprintf(logfile," BM decode nerrors= %3d : ",nerr); - memcpy(correct,workdat,63*sizeof(int)); - ngmd=-1; - param[0]=0; - param[1]=0; - param[2]=0; - param[3]=0; - param[4]=0; - return; - } - -/* -Generate random erasure-locator vectors and see if any of them -decode. This will generate a list of potential codewords. The -"soft" distance between each codeword and the received word is -used to decide which codeword is "best". -*/ - -#ifdef WIN32 - srand(0xdeadbeef); -#else - srandom(0xdeadbeef); -#endif - - float ratio, ratio0[63]; - int threshe, thresh2, nsum; - int thresh0[63],thresh1[63], mr2flag; - ncandidates=0; - nsum=0; - int ii,jj; - for (i=0; i= 0 ) { - 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; - if((nsoft < 33) && (nhard < 43) && (nhard+nsoft) < 74) { //??? - if( (nsoft < nsoft_min) ) { - nsoft_min=nsoft; - nhard_min=nhard; - memcpy(correct,workdat,63*sizeof(int)); - ngmd=0; - nera_best=numera; - ntry[0]=k; - } - } - if(nsoft_min < 27) break; - if((nsoft_min < 32) && (nhard_min < 43) && - (nhard_min+nsoft_min) < 74) break; - } - if(k == ntrials-1) ntry[0]=k+1; - } - - if(verbose) fprintf(logfile, - "%d trials and %d candidates after stochastic loop\n",k,ncandidates); - - if( (ncandidates >= 0) && (nsoft_min < 36) && (nhard_min < 44) ) { - if(verbose) { - for (i=0; i<63; i++) { - fprintf(logfile,"%3d %3d %3d %3d %3d %3d\n",i,correct[i], - rxdat[i],rxprob[i],rxdat2[i],rxprob2[i]); - } - fprintf(logfile,"**** ncandidates %d nhard %d nsoft %d nsum %d\n", - ncandidates,nhard_min,nsoft_min,nsum); - } - } else { - nhard_min=-1; - } - - if(verbose) { - fprintf(logfile,"exiting sfrsd\n"); - fclose(logfile); - } - param[0]=ncandidates; - param[1]=nhard_min; - param[2]=nsoft_min; - param[3]=nera_best; - param[4]=ngmd; - if(param[0]==0) param[2]=-1; - return; -} +/* + sfrsd2.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 +#include +#include +#include +#include +#include "rs2.h" + +static void *rs; + +void sfrsd2_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[], + int* ntrials0, int* verbose0, int correct[], int param[], + int indexes[], double tt[], int ntry[]) +{ + int rxdat[63], rxprob[63], rxdat2[63], rxprob2[63]; + int workdat[63],workdat2[63]; + int era_pos[51]; + int c, i, j, numera, nmr2, nerr, nn=63, kk=12; + FILE *datfile, *logfile; + int ntrials = *ntrials0; + int verbose = *verbose0; + int nhard=0,nhard_min=32768,nsoft=0,nsoft_min=32768, ncandidates; + int ngmd,nera_best; + clock_t t0=0,t1=0; + int perr[8][8] = { + 12, 31, 44, 52, 60, 57, 50, 50, + 28, 38, 49, 58, 65, 69, 64, 80, + 40, 41, 53, 62, 66, 73, 76, 81, + 50, 53, 53, 64, 70, 76, 77, 81, + 50, 50, 52, 60, 71, 72, 77, 84, + 50, 50, 56, 62, 67, 73, 81, 85, + 50, 50, 71, 62, 70, 77, 80, 85, + 50, 50, 62, 64, 71, 75, 82, 87}; + + int pmr2[8][8] = { + 4, 8, 9, 7, 6, 0, 0, 0, + 13, 18, 15, 11, 9, 7, 5, 0, + 0, 23, 21, 15, 12, 10, 7, 4, + 0, 34, 28, 20, 16, 14, 11, 7, + 0, 20, 26, 25, 19, 14, 12, 9, + 0, 0, 28, 27, 22, 19, 14, 11, + 0, 0, 40, 29, 29, 23, 18, 12, + 0, 0, 40, 35, 31, 21, 20, 13}; + + if(verbose) { + logfile=fopen("sfrsd.log","a"); + if( !logfile ) { + printf("Unable to open sfrsd.log\n"); + exit(1); + } + } + +// 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 vector 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 the mrsym probabilities to find 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 ) { + if(verbose) fprintf(logfile," BM decode nerrors= %3d : ",nerr); + memcpy(correct,workdat,63*sizeof(int)); + ngmd=-1; + param[0]=0; + param[1]=0; + param[2]=0; + param[3]=0; + param[4]=0; + return; + } + +/* +Generate random erasure-locator vectors and see if any of them +decode. This will generate a list of potential codewords. The +"soft" distance between each codeword and the received word is +used to decide which codeword is "best". +*/ + +#ifdef WIN32 + srand(0xdeadbeef); +#else + srandom(0xdeadbeef); +#endif + + float ratio, ratio0[63]; + int threshe, thresh2, nsum; + int thresh0[63],thresh1[63], mr2flag; + ncandidates=0; + nsum=0; + int ii,jj; + for (i=0; i= 0 ) { + 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; + if((nsoft < 33) && (nhard < 43) && (nhard+nsoft) < 74) { //??? + if( (nsoft < nsoft_min) ) { + nsoft_min=nsoft; + nhard_min=nhard; + memcpy(correct,workdat,63*sizeof(int)); + ngmd=0; + nera_best=numera; + ntry[0]=k; + } + } + if(nsoft_min < 27) break; + if((nsoft_min < 32) && (nhard_min < 43) && + (nhard_min+nsoft_min) < 74) break; + } + if(k == ntrials-1) ntry[0]=k+1; + } + + if(verbose) fprintf(logfile, + "%d trials and %d candidates after stochastic loop\n",k,ncandidates); + + if( (ncandidates >= 0) && (nsoft_min < 36) && (nhard_min < 44) ) { + if(verbose) { + for (i=0; i<63; i++) { + fprintf(logfile,"%3d %3d %3d %3d %3d %3d\n",i,correct[i], + rxdat[i],rxprob[i],rxdat2[i],rxprob2[i]); + } + fprintf(logfile,"**** ncandidates %d nhard %d nsoft %d nsum %d\n", + ncandidates,nhard_min,nsoft_min,nsum); + } + } else { + nhard_min=-1; + } + + if(verbose) { + fprintf(logfile,"exiting sfrsd\n"); + fclose(logfile); + } + param[0]=ncandidates; + param[1]=nhard_min; + param[2]=nsoft_min; + param[3]=nera_best; + param[4]=ngmd; + if(param[0]==0) param[2]=-1; + return; +} diff --git a/lib/g1 b/lib/g1 index d2846b7e..52f76160 100755 --- a/lib/g1 +++ b/lib/g1 @@ -1,4 +1,4 @@ -gcc -c gran.c -gfortran -c four2a.f90 -gfortran -c f77_wisdom.f90 -gfortran -o chkfft chkfft.f90 four2a.o f77_wisdom.o gran.o -lfftw3f +gcc -c gran.c +gfortran -c four2a.f90 +gfortran -c f77_wisdom.f90 +gfortran -o chkfft chkfft.f90 four2a.o f77_wisdom.o gran.o -lfftw3f diff --git a/lib/g1.bat b/lib/g1.bat index 2195ded3..6242f25f 100755 --- a/lib/g1.bat +++ b/lib/g1.bat @@ -1,4 +1,4 @@ -gcc -c gran.c -gfortran -c four2a.f90 -gfortran -c f77_wisdom.f90 -gfortran -o chkfft chkfft.f90 four2a.o f77_wisdom.o gran.o /JTSDK-QT/appsupport/runtime/libfftw3f-3.dll +gcc -c gran.c +gfortran -c four2a.f90 +gfortran -c f77_wisdom.f90 +gfortran -o chkfft chkfft.f90 four2a.o f77_wisdom.o gran.o /JTSDK-QT/appsupport/runtime/libfftw3f-3.dll diff --git a/lib/g2.bat b/lib/g2.bat index 4a7ed6cd..4067107e 100755 --- a/lib/g2.bat +++ b/lib/g2.bat @@ -1,4 +1,4 @@ -gcc -c gran.c -gfortran -c fftw3mod.f90 -gfortran -c f77_wisdom.f90 -gfortran -o chkfft2 chkfft2.f90 f77_wisdom.o gran.o /JTSDK-QT/appsupport/runtime/libfftw3f-3.dll +gcc -c gran.c +gfortran -c fftw3mod.f90 +gfortran -c f77_wisdom.f90 +gfortran -o chkfft2 chkfft2.f90 f77_wisdom.o gran.o /JTSDK-QT/appsupport/runtime/libfftw3f-3.dll diff --git a/lib/g3.bat b/lib/g3.bat index be20525a..904fce9d 100755 --- a/lib/g3.bat +++ b/lib/g3.bat @@ -1,4 +1,4 @@ -gcc -c gran.c -gfortran -c fftw3mod.f90 -gfortran -c f77_wisdom.f90 -gfortran -o chkfft3 chkfft3.f90 f77_wisdom.o gran.o /JTSDK-QT/appsupport/runtime/libfftw3f-3.dll +gcc -c gran.c +gfortran -c fftw3mod.f90 +gfortran -c f77_wisdom.f90 +gfortran -o chkfft3 chkfft3.f90 f77_wisdom.o gran.o /JTSDK-QT/appsupport/runtime/libfftw3f-3.dll diff --git a/lib/g4.bat b/lib/g4.bat index 1b2f5ed8..6475dad7 100755 --- a/lib/g4.bat +++ b/lib/g4.bat @@ -1,3 +1,3 @@ -gcc -c gran.c -gfortran -c -Wall fftw3mod.f90 -gfortran -o timefft -Wall timefft.f90 timefft_opts.f90 gran.o libfftw3f-3.dll +gcc -c gran.c +gfortran -c -Wall fftw3mod.f90 +gfortran -o timefft -Wall timefft.f90 timefft_opts.f90 gran.o libfftw3f-3.dll diff --git a/lib/gen4.f90 b/lib/gen4.f90 index 1913fb3f..b94789d2 100755 --- a/lib/gen4.f90 +++ b/lib/gen4.f90 @@ -1,43 +1,43 @@ -subroutine gen4(msg0,ichk,msgsent,itone,itype) - -! Encode a JT4 message. Returns msgsent, the message as it will be -! decoded, an integer array itone(206) of 4-FSK tons values in the -! range 0-3; and itype, the JT message type. - - use jt4 - use packjt - character*22 msg0 - character*22 message !Message to be generated - character*22 msgsent !Message as it will be received - character*1 c - integer itone(206) - integer*4 i4Msg6BitWords(13) !72-bit message as 6-bit words - integer mettab(-128:127,0:1) - save - - if(msg0(1:1).eq.'@') then - read(msg0(2:5),*,end=1,err=1) nfreq - go to 2 -1 nfreq=1000 -2 itone(1)=nfreq - msgsent=msg0 - else - call getmet4(mettab,ndelta) - - message=msg0 - call fmtmsg(message,iz) - call packmsg(message,i4Msg6BitWords,itype) !Pack into 12 6-bit bytes - call unpackmsg(i4Msg6BitWords,msgsent) !Unpack to get msgsent - if(ichk.ne.0) go to 999 - call encode4(message,itone) !Encode the information bits - i1=index(message,'-') - c=message(i1+1:i1+1) - if(i1.ge.9 .and. c.ge.'0' .and. c.le.'3') then - itone=2*itone + (1-npr(2:)) !Inverted '#' sync - else - itone=2*itone + npr(2:) !Data = MSB, sync = LSB - endif - endif - -999 return -end subroutine gen4 +subroutine gen4(msg0,ichk,msgsent,itone,itype) + +! Encode a JT4 message. Returns msgsent, the message as it will be +! decoded, an integer array itone(206) of 4-FSK tons values in the +! range 0-3; and itype, the JT message type. + + use jt4 + use packjt + character*22 msg0 + character*22 message !Message to be generated + character*22 msgsent !Message as it will be received + character*1 c + integer itone(206) + integer*4 i4Msg6BitWords(13) !72-bit message as 6-bit words + integer mettab(-128:127,0:1) + save + + if(msg0(1:1).eq.'@') then + read(msg0(2:5),*,end=1,err=1) nfreq + go to 2 +1 nfreq=1000 +2 itone(1)=nfreq + msgsent=msg0 + else + call getmet4(mettab,ndelta) + + message=msg0 + call fmtmsg(message,iz) + call packmsg(message,i4Msg6BitWords,itype) !Pack into 12 6-bit bytes + call unpackmsg(i4Msg6BitWords,msgsent) !Unpack to get msgsent + if(ichk.ne.0) go to 999 + call encode4(message,itone) !Encode the information bits + i1=index(message,'-') + c=message(i1+1:i1+1) + if(i1.ge.9 .and. c.ge.'0' .and. c.le.'3') then + itone=2*itone + (1-npr(2:)) !Inverted '#' sync + else + itone=2*itone + npr(2:) !Data = MSB, sync = LSB + endif + endif + +999 return +end subroutine gen4 diff --git a/lib/genmet.f90 b/lib/genmet.f90 index e15ee947..81f2e56d 100755 --- a/lib/genmet.f90 +++ b/lib/genmet.f90 @@ -1,90 +1,90 @@ -program genmet - -! Generate metric table for M-FSK modulation. - - character*12 arg - real*4 r(0:255) - integer hist(2,-128:128) - data hist/514*0/,idum/-1/ - - lim(x)=min(127,max(-128,nint(scale*x))) - - nargs=iargc() - if(nargs.ne.5) then - print*,'Usage: genmet ncoh nadd m0 snr iters' - go to 999 - endif - call getarg(1,arg) - read(arg,*) ncoh - call getarg(2,arg) - read(arg,*) nadd - call getarg(3,arg) - read(arg,*) m0 - call getarg(4,arg) - read(arg,*) snr - call getarg(5,arg) - read(arg,*) iters - - ntones=2**m0 - xm0=m0 - scale=5.0 - fac=sqrt(1.0/nadd) - s=sqrt(10.0**(0.1*snr)) - hist=0 - nerr=0 - - call sgran() - - do iter=1,iters - do i=0,ntones-1 - r(i)=0. - do n=1,nadd - x1=0.707*gran() - y1=0.707*gran() - if(i.eq.0) x1=x1+s - if(ncoh.eq.0) r(i)=r(i) + x1*x1 + y1*y1 - if(ncoh.ne.0) r(i)=r(i) + x1 - enddo - r(i)=fac*r(i) - enddo - do m=0,m0-1 - n=2**m - r1=0. - r2=0. - do i=0,ntones-1 - if(iand(i,n).ne.0) r1=max(r1,r(i)) - if(iand(i,n).eq.0) r2=max(r2,r(i)) - enddo - don=r2-r1 - doff=r1-r2 - if(don.lt.0.0) nerr=nerr+1 - j1=lim(doff) - hist(1,j1)=hist(1,j1)+1 - j2=lim(don) - hist(2,j2)=hist(2,j2)+1 - enddo - enddo - - do i=-128,127 - write(13,1010) i/scale,hist(1,i)/(xm0*iters),hist(2,i)/(xm0*iters) -1010 format(f8.3,2f12.9) - enddo - - ber=nerr/(xm0*iters) - write(*,1020) nadd,m0,snr,ber -1020 format('nadd:',i3,' m0:',i2,' snr: 'f5.1,' BER:',f8.3) - - xln2=log(2.0) - do i=-128,127 - p1=hist(2,i)/(xm0*iters) - p0=hist(1,i)/(xm0*iters) - if(p0+p1.eq.0.0 .and. i.lt.0) p0=1.e-6 - if(p0+p1.eq.0.0 .and. i.gt.0) p1=1.e-6 - xlhd0=log(max(0.001,2.0*p0/(p0+p1)))/xln2 - xlhd1=log(max(0.001,2.0*p1/(p0+p1)))/xln2 - write(14,1012) i/scale,xlhd0,xlhd1,p0/(p0+p1),p1/(p0+p1) -1012 format(f7.1,2f8.3,2f9.6) - enddo - -999 end program genmet - +program genmet + +! Generate metric table for M-FSK modulation. + + character*12 arg + real*4 r(0:255) + integer hist(2,-128:128) + data hist/514*0/,idum/-1/ + + lim(x)=min(127,max(-128,nint(scale*x))) + + nargs=iargc() + if(nargs.ne.5) then + print*,'Usage: genmet ncoh nadd m0 snr iters' + go to 999 + endif + call getarg(1,arg) + read(arg,*) ncoh + call getarg(2,arg) + read(arg,*) nadd + call getarg(3,arg) + read(arg,*) m0 + call getarg(4,arg) + read(arg,*) snr + call getarg(5,arg) + read(arg,*) iters + + ntones=2**m0 + xm0=m0 + scale=5.0 + fac=sqrt(1.0/nadd) + s=sqrt(10.0**(0.1*snr)) + hist=0 + nerr=0 + + call sgran() + + do iter=1,iters + do i=0,ntones-1 + r(i)=0. + do n=1,nadd + x1=0.707*gran() + y1=0.707*gran() + if(i.eq.0) x1=x1+s + if(ncoh.eq.0) r(i)=r(i) + x1*x1 + y1*y1 + if(ncoh.ne.0) r(i)=r(i) + x1 + enddo + r(i)=fac*r(i) + enddo + do m=0,m0-1 + n=2**m + r1=0. + r2=0. + do i=0,ntones-1 + if(iand(i,n).ne.0) r1=max(r1,r(i)) + if(iand(i,n).eq.0) r2=max(r2,r(i)) + enddo + don=r2-r1 + doff=r1-r2 + if(don.lt.0.0) nerr=nerr+1 + j1=lim(doff) + hist(1,j1)=hist(1,j1)+1 + j2=lim(don) + hist(2,j2)=hist(2,j2)+1 + enddo + enddo + + do i=-128,127 + write(13,1010) i/scale,hist(1,i)/(xm0*iters),hist(2,i)/(xm0*iters) +1010 format(f8.3,2f12.9) + enddo + + ber=nerr/(xm0*iters) + write(*,1020) nadd,m0,snr,ber +1020 format('nadd:',i3,' m0:',i2,' snr: 'f5.1,' BER:',f8.3) + + xln2=log(2.0) + do i=-128,127 + p1=hist(2,i)/(xm0*iters) + p0=hist(1,i)/(xm0*iters) + if(p0+p1.eq.0.0 .and. i.lt.0) p0=1.e-6 + if(p0+p1.eq.0.0 .and. i.gt.0) p1=1.e-6 + xlhd0=log(max(0.001,2.0*p0/(p0+p1)))/xln2 + xlhd1=log(max(0.001,2.0*p1/(p0+p1)))/xln2 + write(14,1012) i/scale,xlhd0,xlhd1,p0/(p0+p1),p1/(p0+p1) +1012 format(f7.1,2f8.3,2f9.6) + enddo + +999 end program genmet + diff --git a/lib/genmsk_128_90.f90 b/lib/genmsk_128_90.f90 index 23e5d7c5..6e35d725 100755 --- a/lib/genmsk_128_90.f90 +++ b/lib/genmsk_128_90.f90 @@ -1,120 +1,120 @@ -subroutine genmsk_128_90(msg0,ichk,msgsent,i4tone,itype) -! s8 + 48bits + s8 + 80 bits = 144 bits (72ms message duration) -! -! Encode an MSK144 message -! Input: -! - msg0 requested message to be transmitted -! - ichk if ichk=1, return only msgsent -! if ichk.ge.10000, set imsg=ichk-10000 for short msg -! - msgsent message as it will be decoded -! - i4tone array of audio tone values, 0 or 1 -! - itype message type -! 1 = standard message "Call_1 Call_2 Grid/Rpt" -! 2 = type 1 prefix -! 3 = type 1 suffix -! 4 = type 2 prefix -! 5 = type 2 suffix -! 6 = free text (up to 13 characters) -! 7 = short message " Rpt" - - use iso_c_binding, only: c_loc,c_size_t - use packjt77 - character*37 msg0 - character*37 message !Message to be generated - character*37 msgsent !Message as it will be received - character*77 c77 - integer*4 i4tone(144) - integer*1 codeword(128) - integer*1 msgbits(77) - integer*1 bitseq(144) !Tone #s, data and sync (values 0-1) - integer*1 s8(8) - real*8 pp(12) - real*8 xi(864),xq(864),pi,twopi - data s8/0,1,1,1,0,0,1,0/ - equivalence (ihash,i1hash) - logical first,unpk77_success - data first/.true./ - save - - if(first) then - first=.false. - nsym=128 - pi=4.0*atan(1.0) - twopi=8.*atan(1.0) - do i=1,12 - pp(i)=sin((i-1)*pi/12) - enddo - endif - - message(1:37)=' ' - itype=1 - if(msg0(1:1).eq.'@') then !Generate a fixed tone - read(msg0(2:5),*,end=1,err=1) nfreq !at specified frequency - go to 2 -1 nfreq=1000 -2 i4tone(1)=nfreq - else - message=msg0 - - do i=1, 37 - if(ichar(message(i:i)).eq.0) then - message(i:37)=' ' - exit - endif - enddo - do i=1,37 !Strip leading blanks - if(message(1:1).ne.' ') exit - message=message(i+1:) - enddo - - if(message(1:1).eq.'<') then - i2=index(message,'>') - i1=0 - if(i2.gt.0) i1=index(message(1:i2),' ') - if(i1.gt.0) then - call genmsk40(message,msgsent,ichk,i4tone,itype) - if(itype.lt.0) go to 999 - i4tone(41)=-40 - go to 999 - endif - endif - - i3=-1 - n3=-1 - call pack77(message,i3,n3,c77) - call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent - if(ichk.eq.1) go to 999 - read(c77,"(77i1)") msgbits - call encode_128_90(msgbits,codeword) - -!Create 144-bit channel vector: -!8-bit sync word + 48 bits + 8-bit sync word + 80 bits - bitseq=0 - bitseq(1:8)=s8 - bitseq(9:56)=codeword(1:48) - bitseq(57:64)=s8 - bitseq(65:144)=codeword(49:128) - bitseq=2*bitseq-1 - - xq(1:6)=bitseq(1)*pp(7:12) !first bit is mapped to 1st half-symbol on q - do i=1,71 - is=(i-1)*12+7 - xq(is:is+11)=bitseq(2*i+1)*pp - enddo - xq(864-5:864)=bitseq(1)*pp(1:6) !last half symbol - do i=1,72 - is=(i-1)*12+1 - xi(is:is+11)=bitseq(2*i)*pp - enddo -! Map I and Q to tones. - i4tone=0 - do i=1,72 - i4tone(2*i-1)=(bitseq(2*i)*bitseq(2*i-1)+1)/2; - i4tone(2*i)=-(bitseq(2*i)*bitseq(mod(2*i,144)+1)-1)/2; - enddo - endif - -! Flip polarity - i4tone=-i4tone+1 -999 return -end subroutine genmsk_128_90 +subroutine genmsk_128_90(msg0,ichk,msgsent,i4tone,itype) +! s8 + 48bits + s8 + 80 bits = 144 bits (72ms message duration) +! +! Encode an MSK144 message +! Input: +! - msg0 requested message to be transmitted +! - ichk if ichk=1, return only msgsent +! if ichk.ge.10000, set imsg=ichk-10000 for short msg +! - msgsent message as it will be decoded +! - i4tone array of audio tone values, 0 or 1 +! - itype message type +! 1 = standard message "Call_1 Call_2 Grid/Rpt" +! 2 = type 1 prefix +! 3 = type 1 suffix +! 4 = type 2 prefix +! 5 = type 2 suffix +! 6 = free text (up to 13 characters) +! 7 = short message " Rpt" + + use iso_c_binding, only: c_loc,c_size_t + use packjt77 + character*37 msg0 + character*37 message !Message to be generated + character*37 msgsent !Message as it will be received + character*77 c77 + integer*4 i4tone(144) + integer*1 codeword(128) + integer*1 msgbits(77) + integer*1 bitseq(144) !Tone #s, data and sync (values 0-1) + integer*1 s8(8) + real*8 pp(12) + real*8 xi(864),xq(864),pi,twopi + data s8/0,1,1,1,0,0,1,0/ + equivalence (ihash,i1hash) + logical first,unpk77_success + data first/.true./ + save + + if(first) then + first=.false. + nsym=128 + pi=4.0*atan(1.0) + twopi=8.*atan(1.0) + do i=1,12 + pp(i)=sin((i-1)*pi/12) + enddo + endif + + message(1:37)=' ' + itype=1 + if(msg0(1:1).eq.'@') then !Generate a fixed tone + read(msg0(2:5),*,end=1,err=1) nfreq !at specified frequency + go to 2 +1 nfreq=1000 +2 i4tone(1)=nfreq + else + message=msg0 + + do i=1, 37 + if(ichar(message(i:i)).eq.0) then + message(i:37)=' ' + exit + endif + enddo + do i=1,37 !Strip leading blanks + if(message(1:1).ne.' ') exit + message=message(i+1:) + enddo + + if(message(1:1).eq.'<') then + i2=index(message,'>') + i1=0 + if(i2.gt.0) i1=index(message(1:i2),' ') + if(i1.gt.0) then + call genmsk40(message,msgsent,ichk,i4tone,itype) + if(itype.lt.0) go to 999 + i4tone(41)=-40 + go to 999 + endif + endif + + i3=-1 + n3=-1 + call pack77(message,i3,n3,c77) + call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent + if(ichk.eq.1) go to 999 + read(c77,"(77i1)") msgbits + call encode_128_90(msgbits,codeword) + +!Create 144-bit channel vector: +!8-bit sync word + 48 bits + 8-bit sync word + 80 bits + bitseq=0 + bitseq(1:8)=s8 + bitseq(9:56)=codeword(1:48) + bitseq(57:64)=s8 + bitseq(65:144)=codeword(49:128) + bitseq=2*bitseq-1 + + xq(1:6)=bitseq(1)*pp(7:12) !first bit is mapped to 1st half-symbol on q + do i=1,71 + is=(i-1)*12+7 + xq(is:is+11)=bitseq(2*i+1)*pp + enddo + xq(864-5:864)=bitseq(1)*pp(1:6) !last half symbol + do i=1,72 + is=(i-1)*12+1 + xi(is:is+11)=bitseq(2*i)*pp + enddo +! Map I and Q to tones. + i4tone=0 + do i=1,72 + i4tone(2*i-1)=(bitseq(2*i)*bitseq(2*i-1)+1)/2; + i4tone(2*i)=-(bitseq(2*i)*bitseq(mod(2*i,144)+1)-1)/2; + enddo + endif + +! Flip polarity + i4tone=-i4tone+1 +999 return +end subroutine genmsk_128_90 diff --git a/lib/genqra64.f90 b/lib/genqra64.f90 index 30e86d9e..8426b883 100755 --- a/lib/genqra64.f90 +++ b/lib/genqra64.f90 @@ -1,70 +1,70 @@ -subroutine genqra64(msg0,ichk,msgsent,itone,itype) - -! Encodes a QRA64 message to yield itone(1:84) or a QRA65 msg, itone(1:85) - - use packjt - character*22 msg0 - character*22 message !Message to be generated - character*22 msgsent !Message as it will be received - integer itone(85) !QRA64 uses only 84 - character*3 cok !' ' or 'OOO' - integer dgen(13) - integer sent(63) - integer isync(22) - integer icos7(0:6) - data icos7/2,5,6,0,4,1,3/ !Defines a 7x7 Costas array - data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ - save - - if(msg0(1:1).eq.'@') then - read(msg0(2:5),*,end=1,err=1) nfreq - go to 2 -1 nfreq=1000 -2 itone(1)=nfreq - write(msgsent,1000) nfreq -1000 format(i5,' Hz') - else - message=msg0 - do i=1,22 - if(ichar(message(i:i)).eq.0) then - message(i:)=' ' - exit - endif - enddo - - do i=1,22 !Strip leading blanks - if(message(1:1).ne.' ') exit - message=message(i+1:) - enddo - - call chkmsg(message,cok,nspecial,flip) - call packmsg(message,dgen,itype) !Pack message into 72 bits - call unpackmsg(dgen,msgsent) !Unpack to get message sent - if(ichk.eq.1) go to 999 !Return if checking only - call qra64_enc(dgen,sent) !Encode using QRA64 - - if(ichk.eq.65) then -! Experimental QRA65 mode - j=1 - k=0 - do i=1,85 - if(i.eq.isync(j)) then - j=j+1 !Index for next sync symbol - itone(i)=0 !Insert a sync symbol - else - k=k+1 - itone(i)=sent(k) + 1 - endif - enddo - else -! Original QRA64 mode - itone(1:7)=10*icos7 !Insert 7x7 Costas array in 3 places - itone(8:39)=sent(1:32) - itone(40:46)=10*icos7 - itone(47:77)=sent(33:63) - itone(78:84)=10*icos7 - endif - endif - -999 return -end subroutine genqra64 +subroutine genqra64(msg0,ichk,msgsent,itone,itype) + +! Encodes a QRA64 message to yield itone(1:84) or a QRA65 msg, itone(1:85) + + use packjt + character*22 msg0 + character*22 message !Message to be generated + character*22 msgsent !Message as it will be received + integer itone(85) !QRA64 uses only 84 + character*3 cok !' ' or 'OOO' + integer dgen(13) + integer sent(63) + integer isync(22) + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ !Defines a 7x7 Costas array + data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ + save + + if(msg0(1:1).eq.'@') then + read(msg0(2:5),*,end=1,err=1) nfreq + go to 2 +1 nfreq=1000 +2 itone(1)=nfreq + write(msgsent,1000) nfreq +1000 format(i5,' Hz') + else + message=msg0 + do i=1,22 + if(ichar(message(i:i)).eq.0) then + message(i:)=' ' + exit + endif + enddo + + do i=1,22 !Strip leading blanks + if(message(1:1).ne.' ') exit + message=message(i+1:) + enddo + + call chkmsg(message,cok,nspecial,flip) + call packmsg(message,dgen,itype) !Pack message into 72 bits + call unpackmsg(dgen,msgsent) !Unpack to get message sent + if(ichk.eq.1) go to 999 !Return if checking only + call qra64_enc(dgen,sent) !Encode using QRA64 + + if(ichk.eq.65) then +! Experimental QRA65 mode + j=1 + k=0 + do i=1,85 + if(i.eq.isync(j)) then + j=j+1 !Index for next sync symbol + itone(i)=0 !Insert a sync symbol + else + k=k+1 + itone(i)=sent(k) + 1 + endif + enddo + else +! Original QRA64 mode + itone(1:7)=10*icos7 !Insert 7x7 Costas array in 3 places + itone(8:39)=sent(1:32) + itone(40:46)=10*icos7 + itone(47:77)=sent(33:63) + itone(78:84)=10*icos7 + endif + endif + +999 return +end subroutine genqra64 diff --git a/lib/genwave.f90 b/lib/genwave.f90 index 8cd47269..7db4cc7d 100755 --- a/lib/genwave.f90 +++ b/lib/genwave.f90 @@ -1,52 +1,52 @@ -subroutine genwave(itone,nsym,nsps,nwave,fsample,hmod,f0,icmplx,cwave,wave) - - real wave(nwave) - complex cwave(nwave) - integer hmod - integer itone(nsym) - logical ex - real*8 dt,phi,dphi,twopi,freq,baud - - dt=1.d0/fsample - twopi=8.d0*atan(1.d0) - baud=fsample/nsps - -! Calculate the audio waveform - phi=0.d0 - if(icmplx.le.0) wave=0. - if(icmplx.eq.1) cwave=0. - k=0 - do j=1,nsym - freq=f0 + itone(j)*hmod*baud - dphi=twopi*freq*dt - do i=1,nsps - k=k+1 - if(icmplx.eq.1) then - cwave(k)=cmplx(cos(phi),sin(phi)) - else - wave(k)=sin(phi) - endif - phi=phi+dphi - if(phi.gt.twopi) phi=phi-twopi - enddo - enddo - -!### TEMPORARY code to allow transmitting both A and B submodes - inquire(file='Q65_Tx2',exist=ex) - if(ex) then - k=0 - do j=1,nsym - freq=f0 + itone(j)*2.d0*hmod*baud + 500.d0 - dphi=twopi*freq*dt - do i=1,nsps - k=k+1 - wave(k)=0.5*(wave(k)+sin(phi)) - phi=phi+dphi - if(phi.gt.twopi) phi=phi-twopi - enddo - enddo - endif -!### - - return -end subroutine genwave +subroutine genwave(itone,nsym,nsps,nwave,fsample,hmod,f0,icmplx,cwave,wave) + + real wave(nwave) + complex cwave(nwave) + integer hmod + integer itone(nsym) + logical ex + real*8 dt,phi,dphi,twopi,freq,baud + + dt=1.d0/fsample + twopi=8.d0*atan(1.d0) + baud=fsample/nsps + +! Calculate the audio waveform + phi=0.d0 + if(icmplx.le.0) wave=0. + if(icmplx.eq.1) cwave=0. + k=0 + do j=1,nsym + freq=f0 + itone(j)*hmod*baud + dphi=twopi*freq*dt + do i=1,nsps + k=k+1 + if(icmplx.eq.1) then + cwave(k)=cmplx(cos(phi),sin(phi)) + else + wave(k)=sin(phi) + endif + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + enddo + enddo + +!### TEMPORARY code to allow transmitting both A and B submodes + inquire(file='Q65_Tx2',exist=ex) + if(ex) then + k=0 + do j=1,nsym + freq=f0 + itone(j)*2.d0*hmod*baud + 500.d0 + dphi=twopi*freq*dt + do i=1,nsps + k=k+1 + wave(k)=0.5*(wave(k)+sin(phi)) + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + enddo + enddo + endif +!### + + return +end subroutine genwave diff --git a/lib/genwspr.f90 b/lib/genwspr.f90 index c31cb8a3..d1d5183b 100755 --- a/lib/genwspr.f90 +++ b/lib/genwspr.f90 @@ -1,30 +1,30 @@ -subroutine genwspr(message,msgsent,itone) -! Encode a WSPR message and generate the array of channel symbols. - - character*22 message,msgsent - parameter (MAXSYM=176) - integer*1 symbol(MAXSYM) - integer*1 data0(11) - integer*4 itone(162) - integer npr3(162) - data npr3/ & - 1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, & - 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, & - 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, & - 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, & - 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, & - 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, & - 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, & - 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, & - 0,0/ - - call wqencode(message,ntype,data0) !Source encoding - call encode232(data0,162,symbol) !Convolutional encoding - call inter_wspr(symbol,1) !Interleaving - do i=1,162 - itone(i)=npr3(i) + 2*symbol(i) - enddo - msgsent=message !### To be fixed... ?? ### - - return -end subroutine genwspr +subroutine genwspr(message,msgsent,itone) +! Encode a WSPR message and generate the array of channel symbols. + + character*22 message,msgsent + parameter (MAXSYM=176) + integer*1 symbol(MAXSYM) + integer*1 data0(11) + integer*4 itone(162) + integer npr3(162) + data npr3/ & + 1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, & + 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, & + 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, & + 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, & + 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, & + 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, & + 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, & + 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, & + 0,0/ + + call wqencode(message,ntype,data0) !Source encoding + call encode232(data0,162,symbol) !Convolutional encoding + call inter_wspr(symbol,1) !Interleaving + do i=1,162 + itone(i)=npr3(i) + 2*symbol(i) + enddo + msgsent=message !### To be fixed... ?? ### + + return +end subroutine genwspr diff --git a/lib/get_q3list.f90 b/lib/get_q3list.f90 index 54199148..a6b6de81 100755 --- a/lib/get_q3list.f90 +++ b/lib/get_q3list.f90 @@ -1,132 +1,132 @@ -subroutine get_q3list(fname,bDiskData,nlist,list) - - type q3list - character*6 call - character*4 grid - integer nsec - integer nfreq - integer moonel - end type q3list - - parameter (MAX_CALLERS=40) - character*(*) fname - character*36 list(40) - character*8 grid6 - logical*1 bDiskData - integer time - integer nt(8) - integer indx(MAX_CALLERS) - type(q3list) ctmp(MAX_CALLERS),callers(MAX_CALLERS) - character*256 jpleph_file_name,file24name - common/jplcom/jpleph_file_name - common/lu24com/file24name - - nhist2=0 - open(24,file=fname,status='unknown',form='unformatted') - read(24,end=1) nhist2 - if(nhist2.ge.1 .and. nhist2.le.40) then - read(24,end=1) ctmp(1:nhist2) - else - nhist2=0 - endif -1 rewind 24 - if(nhist2.eq.0) go to 900 - - now=time() - call date_and_time(values=nt) - uth=nt(5) + (nt(6)-nt(4))/60.0 + nt(7)/3600.0 - j=0 - - do i=1,nhist2 - age=(now - ctmp(i)%nsec)/3600.0 - if(age.gt.24.0) cycle - grid6=ctmp(i)%grid//'mm' - call grid2deg(grid6,xlon,xlat) - call sun(nt(1),nt(2),nt(3),uth,-xlon,xlat,RASun,DecSun,xLST, & - AzSun,ElSun,mjd,day) - call moondopjpl(nt(1),nt(2),nt(3),uth,-xlon,xlat,RAMoon,DecMoon, & - xLST,HA,AzMoon,ElMoon,vr,techo) - if(ElMoon.lt.-5.0 .and. (.not.bDiskData)) cycle - j=j+1 !Keep this one... - callers(j)=ctmp(i) - callers(j)%moonel=nint(ElMoon) !... and save its current moonel - enddo - - nhist2=j - write(24) nhist2 - write(24) callers(1:nhist2) - - call indexx(callers(1:nhist2)%nfreq,nhist2,indx) - do i=1,nhist2 - j=indx(i) - moon_el=nint(ElMoon) - age=(now - callers(j)%nsec)/3600.0 - write(list(i),1000) i,callers(j)%nfreq,callers(j)%call, & - callers(j)%grid,callers(j)%moonel,age,char(0) -1000 format(i2,'.',i6,2x,a6,2x,a4,i5,f7.1,a1) - -! h1=mod(now,86400)/3600.0 -! h2=mod(callers(i)%nsec,86400)/3600.0 -! hd=h1-h2 -! if(hd.lt.0.0) hd=hd+24.0 -! write(*,3301) i,callers(i)%call,now,callers(i)%nsec,h1,h2,hd -!3301 format(i3,2x,a6,2i12,3f10.6) - - enddo - -900 close(24) - nlist=nhist2 - file24name=fname - - return -end subroutine get_q3list - -subroutine rm_q3list(dxcall0) - - parameter (MAX_CALLERS=40) - type q3list - character*6 call - character*4 grid - integer nsec - integer nfreq - integer moonel - end type q3list - character*(*) dxcall0 - character*6 dxcall - character*256 file24name - type(q3list) callers(MAX_CALLERS) - common/lu24com/file24name - - dxcall=dxcall0 - open(24,file=trim(file24name),status='unknown',form='unformatted') - read(24) nhist2 - read(24) callers(1:nhist2) - - if(nhist2.eq.MAX_CALLERS .and. dxcall.eq.callers(nhist2)%call) then - nhist2=MAX_CALLERS - 1 - go to 10 - endif - - iz=nhist2 - do i=1,iz - if(callers(i)%call .eq. dxcall) then - nhist2=nhist2-1 - callers(i:nhist2)=callers(i+1:nhist2+1) !Remove dxcall from q3list - exit - endif - enddo - -10 rewind 24 - write(24) nhist2 - write(24) callers(1:nhist2) - close(24) - - return -end subroutine rm_q3list - -subroutine jpl_setup(fname) - character*256 fname,jpleph_file_name - common/jplcom/jpleph_file_name - jpleph_file_name=fname - return -end subroutine jpl_setup +subroutine get_q3list(fname,bDiskData,nlist,list) + + type q3list + character*6 call + character*4 grid + integer nsec + integer nfreq + integer moonel + end type q3list + + parameter (MAX_CALLERS=40) + character*(*) fname + character*36 list(40) + character*8 grid6 + logical*1 bDiskData + integer time + integer nt(8) + integer indx(MAX_CALLERS) + type(q3list) ctmp(MAX_CALLERS),callers(MAX_CALLERS) + character*256 jpleph_file_name,file24name + common/jplcom/jpleph_file_name + common/lu24com/file24name + + nhist2=0 + open(24,file=fname,status='unknown',form='unformatted') + read(24,end=1) nhist2 + if(nhist2.ge.1 .and. nhist2.le.40) then + read(24,end=1) ctmp(1:nhist2) + else + nhist2=0 + endif +1 rewind 24 + if(nhist2.eq.0) go to 900 + + now=time() + call date_and_time(values=nt) + uth=nt(5) + (nt(6)-nt(4))/60.0 + nt(7)/3600.0 + j=0 + + do i=1,nhist2 + age=(now - ctmp(i)%nsec)/3600.0 + if(age.gt.24.0) cycle + grid6=ctmp(i)%grid//'mm' + call grid2deg(grid6,xlon,xlat) + call sun(nt(1),nt(2),nt(3),uth,-xlon,xlat,RASun,DecSun,xLST, & + AzSun,ElSun,mjd,day) + call moondopjpl(nt(1),nt(2),nt(3),uth,-xlon,xlat,RAMoon,DecMoon, & + xLST,HA,AzMoon,ElMoon,vr,techo) + if(ElMoon.lt.-5.0 .and. (.not.bDiskData)) cycle + j=j+1 !Keep this one... + callers(j)=ctmp(i) + callers(j)%moonel=nint(ElMoon) !... and save its current moonel + enddo + + nhist2=j + write(24) nhist2 + write(24) callers(1:nhist2) + + call indexx(callers(1:nhist2)%nfreq,nhist2,indx) + do i=1,nhist2 + j=indx(i) + moon_el=nint(ElMoon) + age=(now - callers(j)%nsec)/3600.0 + write(list(i),1000) i,callers(j)%nfreq,callers(j)%call, & + callers(j)%grid,callers(j)%moonel,age,char(0) +1000 format(i2,'.',i6,2x,a6,2x,a4,i5,f7.1,a1) + +! h1=mod(now,86400)/3600.0 +! h2=mod(callers(i)%nsec,86400)/3600.0 +! hd=h1-h2 +! if(hd.lt.0.0) hd=hd+24.0 +! write(*,3301) i,callers(i)%call,now,callers(i)%nsec,h1,h2,hd +!3301 format(i3,2x,a6,2i12,3f10.6) + + enddo + +900 close(24) + nlist=nhist2 + file24name=fname + + return +end subroutine get_q3list + +subroutine rm_q3list(dxcall0) + + parameter (MAX_CALLERS=40) + type q3list + character*6 call + character*4 grid + integer nsec + integer nfreq + integer moonel + end type q3list + character*(*) dxcall0 + character*6 dxcall + character*256 file24name + type(q3list) callers(MAX_CALLERS) + common/lu24com/file24name + + dxcall=dxcall0 + open(24,file=trim(file24name),status='unknown',form='unformatted') + read(24) nhist2 + read(24) callers(1:nhist2) + + if(nhist2.eq.MAX_CALLERS .and. dxcall.eq.callers(nhist2)%call) then + nhist2=MAX_CALLERS - 1 + go to 10 + endif + + iz=nhist2 + do i=1,iz + if(callers(i)%call .eq. dxcall) then + nhist2=nhist2-1 + callers(i:nhist2)=callers(i+1:nhist2+1) !Remove dxcall from q3list + exit + endif + enddo + +10 rewind 24 + write(24) nhist2 + write(24) callers(1:nhist2) + close(24) + + return +end subroutine rm_q3list + +subroutine jpl_setup(fname) + character*256 fname,jpleph_file_name + common/jplcom/jpleph_file_name + jpleph_file_name=fname + return +end subroutine jpl_setup diff --git a/lib/getmet4.f90 b/lib/getmet4.f90 index 9133fa08..73789357 100755 --- a/lib/getmet4.f90 +++ b/lib/getmet4.f90 @@ -1,56 +1,56 @@ -subroutine getmet4(mettab,ndelta) - -! Return appropriate metric table for soft-decision convolutional decoder. - -! Metric table (RxSymbol,TxSymbol) -! integer mettab(0:255,0:1) - integer mettab(-128:127,0:1) - real*4 xx0(0:255) - data xx0/ & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 0.988, 1.000, 0.991, 0.993, 1.000, 0.995, 1.000, 0.991, & - 1.000, 0.991, 0.992, 0.991, 0.990, 0.990, 0.992, 0.996, & - 0.990, 0.994, 0.993, 0.991, 0.992, 0.989, 0.991, 0.987, & - 0.985, 0.989, 0.984, 0.983, 0.979, 0.977, 0.971, 0.975, & - 0.974, 0.970, 0.970, 0.970, 0.967, 0.962, 0.960, 0.957, & - 0.956, 0.953, 0.942, 0.946, 0.937, 0.933, 0.929, 0.920, & - 0.917, 0.911, 0.903, 0.895, 0.884, 0.877, 0.869, 0.858, & - 0.846, 0.834, 0.821, 0.806, 0.790, 0.775, 0.755, 0.737, & - 0.713, 0.691, 0.667, 0.640, 0.612, 0.581, 0.548, 0.510, & - 0.472, 0.425, 0.378, 0.328, 0.274, 0.212, 0.146, 0.075, & - 0.000,-0.079,-0.163,-0.249,-0.338,-0.425,-0.514,-0.606, & - -0.706,-0.796,-0.895,-0.987,-1.084,-1.181,-1.280,-1.376, & - -1.473,-1.587,-1.678,-1.790,-1.882,-1.992,-2.096,-2.201, & - -2.301,-2.411,-2.531,-2.608,-2.690,-2.829,-2.939,-3.058, & - -3.164,-3.212,-3.377,-3.463,-3.550,-3.768,-3.677,-3.975, & - -4.062,-4.098,-4.186,-4.261,-4.472,-4.621,-4.623,-4.608, & - -4.822,-4.870,-4.652,-4.954,-5.108,-5.377,-5.544,-5.995, & - -5.632,-5.826,-6.304,-6.002,-6.559,-6.369,-6.658,-7.016, & - -6.184,-7.332,-6.534,-6.152,-6.113,-6.288,-6.426,-6.313, & - -9.966,-6.371,-9.966,-7.055,-9.966,-6.629,-6.313,-9.966, & - -5.858,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966/ - save - - bias=0.5 - scale=50 - ndelta=nint(3.4*scale) - do i=0,255 - xx=xx0(i) - if(i.ge.160) xx=xx0(160) - (i-160)*6.822/65.3 - mettab(i-128,0)=nint(scale*(xx-bias)) - if(i.ge.1) mettab(128-i,1)=mettab(i-128,0) - enddo - mettab(-128,1)=mettab(-127,1) - - return -end subroutine getmet4 +subroutine getmet4(mettab,ndelta) + +! Return appropriate metric table for soft-decision convolutional decoder. + +! Metric table (RxSymbol,TxSymbol) +! integer mettab(0:255,0:1) + integer mettab(-128:127,0:1) + real*4 xx0(0:255) + data xx0/ & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 0.988, 1.000, 0.991, 0.993, 1.000, 0.995, 1.000, 0.991, & + 1.000, 0.991, 0.992, 0.991, 0.990, 0.990, 0.992, 0.996, & + 0.990, 0.994, 0.993, 0.991, 0.992, 0.989, 0.991, 0.987, & + 0.985, 0.989, 0.984, 0.983, 0.979, 0.977, 0.971, 0.975, & + 0.974, 0.970, 0.970, 0.970, 0.967, 0.962, 0.960, 0.957, & + 0.956, 0.953, 0.942, 0.946, 0.937, 0.933, 0.929, 0.920, & + 0.917, 0.911, 0.903, 0.895, 0.884, 0.877, 0.869, 0.858, & + 0.846, 0.834, 0.821, 0.806, 0.790, 0.775, 0.755, 0.737, & + 0.713, 0.691, 0.667, 0.640, 0.612, 0.581, 0.548, 0.510, & + 0.472, 0.425, 0.378, 0.328, 0.274, 0.212, 0.146, 0.075, & + 0.000,-0.079,-0.163,-0.249,-0.338,-0.425,-0.514,-0.606, & + -0.706,-0.796,-0.895,-0.987,-1.084,-1.181,-1.280,-1.376, & + -1.473,-1.587,-1.678,-1.790,-1.882,-1.992,-2.096,-2.201, & + -2.301,-2.411,-2.531,-2.608,-2.690,-2.829,-2.939,-3.058, & + -3.164,-3.212,-3.377,-3.463,-3.550,-3.768,-3.677,-3.975, & + -4.062,-4.098,-4.186,-4.261,-4.472,-4.621,-4.623,-4.608, & + -4.822,-4.870,-4.652,-4.954,-5.108,-5.377,-5.544,-5.995, & + -5.632,-5.826,-6.304,-6.002,-6.559,-6.369,-6.658,-7.016, & + -6.184,-7.332,-6.534,-6.152,-6.113,-6.288,-6.426,-6.313, & + -9.966,-6.371,-9.966,-7.055,-9.966,-6.629,-6.313,-9.966, & + -5.858,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966/ + save + + bias=0.5 + scale=50 + ndelta=nint(3.4*scale) + do i=0,255 + xx=xx0(i) + if(i.ge.160) xx=xx0(160) - (i-160)*6.822/65.3 + mettab(i-128,0)=nint(scale*(xx-bias)) + if(i.ge.1) mettab(128-i,1)=mettab(i-128,0) + enddo + mettab(-128,1)=mettab(-127,1) + + return +end subroutine getmet4 diff --git a/lib/gran.c b/lib/gran.c index 3ed39287..ac41c7fe 100755 --- a/lib/gran.c +++ b/lib/gran.c @@ -1,34 +1,34 @@ -#include -#include - -/* 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; -} - -/* Generates evenly distributed numbers between 0 and 1. */ -float rran_() -{ - return (float)rand()/(float)RAND_MAX; -} +#include +#include + +/* 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; +} + +/* Generates evenly distributed numbers between 0 and 1. */ +float rran_() +{ + return (float)rand()/(float)RAND_MAX; +} diff --git a/lib/graycode.f90 b/lib/graycode.f90 index 9e76c5a4..21c1f908 100755 --- a/lib/graycode.f90 +++ b/lib/graycode.f90 @@ -1,9 +1,9 @@ -subroutine graycode(ia,n,idir,ib) - - integer ia(n),ib(n) - do i=1,n - ib(i)=igray(ia(i),idir) - enddo - - return -end subroutine graycode +subroutine graycode(ia,n,idir,ib) + + integer ia(n),ib(n) + do i=1,n + ib(i)=igray(ia(i),idir) + enddo + + return +end subroutine graycode diff --git a/lib/grayline.f90 b/lib/grayline.f90 index 9aa72be1..cc1aeeea 100755 --- a/lib/grayline.f90 +++ b/lib/grayline.f90 @@ -1,32 +1,32 @@ -subroutine grayline(nyear,month,nday,uth,mygrid,nduration,isun) - - character*6 mygrid - real LST - real lat,lon - - call grid2deg(MyGrid,elon,lat) - lon=-elon - - uth0=uth-0.5*nduration/60.0 - uth1=uth+0.5*nduration/60.0 - - call sun(nyear,month,nday,uth0,lon,lat,RASun,DecSun,LST, & - AzSun,ElSun0,mjd,day) - call sun(nyear,month,nday,uth1,lon,lat,RASun,DecSun,LST, & - AzSun,ElSun1,mjd,day) - - elchk=-0.8333 - isun=-1 - if(elsun0.lt.elchk .and. elsun1.ge.elchk) then - isun=0 - else if(elsun0.gt.elchk .and. elsun1.le.elchk) then - isun=2 - else if(elsun1.gt.elchk) then - isun=1 - else - isun=3 - endif - - return -end subroutine grayline - +subroutine grayline(nyear,month,nday,uth,mygrid,nduration,isun) + + character*6 mygrid + real LST + real lat,lon + + call grid2deg(MyGrid,elon,lat) + lon=-elon + + uth0=uth-0.5*nduration/60.0 + uth1=uth+0.5*nduration/60.0 + + call sun(nyear,month,nday,uth0,lon,lat,RASun,DecSun,LST, & + AzSun,ElSun0,mjd,day) + call sun(nyear,month,nday,uth1,lon,lat,RASun,DecSun,LST, & + AzSun,ElSun1,mjd,day) + + elchk=-0.8333 + isun=-1 + if(elsun0.lt.elchk .and. elsun1.ge.elchk) then + isun=0 + else if(elsun0.gt.elchk .and. elsun1.le.elchk) then + isun=2 + else if(elsun1.gt.elchk) then + isun=1 + else + isun=3 + endif + + return +end subroutine grayline + diff --git a/lib/grid2deg.f90 b/lib/grid2deg.f90 index 415da64a..a7ec1c89 100755 --- a/lib/grid2deg.f90 +++ b/lib/grid2deg.f90 @@ -1,39 +1,39 @@ -subroutine grid2deg(grid0,dlong,dlat) - -! Converts Maidenhead grid locator to degrees of West longitude -! and North latitude. - - character*(*) grid0 - character*6 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*(*) grid0 + character*6 grid + character*1 g1,g2,g3,g4,g5,g6 + + grid=grid0 + i=ichar(grid(5:5)) + if(grid(5:5).eq.' ' .or. i.le.64 .or. i.ge.128) grid(5:6)='mm' + + if(grid(1:1).ge.'a' .and. grid(1:1).le.'z') grid(1:1)= & + char(ichar(grid(1:1))+ichar('A')-ichar('a')) + if(grid(2:2).ge.'a' .and. grid(2:2).le.'z') grid(2:2)= & + char(ichar(grid(2:2))+ichar('A')-ichar('a')) + if(grid(5:5).ge.'A' .and. grid(5:5).le.'Z') grid(5:5)= & + char(ichar(grid(5:5))-ichar('A')+ichar('a')) + if(grid(6:6).ge.'A' .and. grid(6:6).le.'Z') grid(6:6)= & + char(ichar(grid(6:6))-ichar('A')+ichar('a')) + + g1=grid(1:1) + g2=grid(2:2) + g3=grid(3:3) + g4=grid(4:4) + g5=grid(5:5) + g6=grid(6:6) + + nlong = 180 - 20*(ichar(g1)-ichar('A')) + n20d = 2*(ichar(g3)-ichar('0')) + xminlong = 5*(ichar(g5)-ichar('a')+0.5) + dlong = nlong - n20d - xminlong/60.0 + nlat = -90+10*(ichar(g2)-ichar('A')) + ichar(g4)-ichar('0') + xminlat = 2.5*(ichar(g6)-ichar('a')+0.5) + dlat = nlat + xminlat/60.0 + + return +end subroutine grid2deg diff --git a/lib/hash.f90 b/lib/hash.f90 index c75e2e7c..37598390 100755 --- a/lib/hash.f90 +++ b/lib/hash.f90 @@ -1,10 +1,10 @@ -subroutine hash(string,len,ihash) - use iso_c_binding, only: c_loc,c_size_t - use hashing - parameter (MASK15=32767) -! character*(*), target :: string - character*1, target :: string - i=nhash(c_loc(string),int(len,c_size_t),146) - ihash=iand(i,MASK15) - return -end subroutine hash +subroutine hash(string,len,ihash) + use iso_c_binding, only: c_loc,c_size_t + use hashing + parameter (MASK15=32767) +! character*(*), target :: string + character*1, target :: string + i=nhash(c_loc(string),int(len,c_size_t),146) + ihash=iand(i,MASK15) + return +end subroutine hash diff --git a/lib/hashing.f90 b/lib/hashing.f90 index 84fbda61..5534fa92 100755 --- a/lib/hashing.f90 +++ b/lib/hashing.f90 @@ -1,10 +1,10 @@ -module hashing - interface - integer(c_int32_t) function nhash (key, length, initval) bind(C, name="nhash") - use iso_c_binding, only: c_ptr, c_size_t, c_int32_t - type(c_ptr), intent(in), value :: key - integer(c_size_t), intent(in), value :: length - integer(c_int32_t), intent(in), value :: initval - end function nhash - end interface -end module hashing +module hashing + interface + integer(c_int32_t) function nhash (key, length, initval) bind(C, name="nhash") + use iso_c_binding, only: c_ptr, c_size_t, c_int32_t + type(c_ptr), intent(in), value :: key + integer(c_size_t), intent(in), value :: length + integer(c_int32_t), intent(in), value :: initval + end function nhash + end interface +end module hashing diff --git a/lib/hint65.f90 b/lib/hint65.f90 index 2242c94c..00eaf40c 100755 --- a/lib/hint65.f90 +++ b/lib/hint65.f90 @@ -1,154 +1,154 @@ -subroutine hint65(s3,mrs,mrs2,nadd,nflip,mycall,hiscall,hisgrid,qual,decoded) - - use packjt - use prog_args - parameter (MAXCALLS=10000,MAXRPT=63) - parameter (MAXMSG=2*MAXCALLS + 2 + MAXRPT) - real s3(64,63) - integer*1 sym1(0:62,MAXMSG) - integer*1 sym2(0:62,MAXMSG) - integer mrs(63),mrs2(63) - integer dgen(12),sym(0:62),sym_rev(0:62) - character*6 mycall,hiscall,hisgrid,call2(MAXCALLS) - character*4 grid2(MAXCALLS),rpt(MAXRPT) - character callsign*12,grid*4 - character*180 line - character ceme*3,msg*22,msg00*22 - character*22 msg0(MAXMSG),decoded - logical*1 eme(MAXCALLS) - logical first - data first/.true./ - 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 first,sym1,nused,msg0,sym2 - - first=.true. !### For now, at least: always recompute hypothetical messages - if(first) then - neme=0 - open(23,file=trim(data_dir)//'/CALL3.TXT',status='unknown') - icall=0 - j=0 - do i=1,MAXCALLS - read(23,1002,end=10) line -1002 format(a80) - if(line(1:4).eq.'ZZZZ') cycle - if(line(1:2).eq.'//') cycle - i1=index(line,',') - if(i1.lt.4) cycle - i2=index(line(i1+1:),',') - if(i2.lt.5) cycle - 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:i1+4) - ceme=line(i2+1:i3-1) - eme(i)=ceme.eq.'EME' - if(neme.eq.1 .and. (.not.eme(i))) cycle - j=j+1 - call2(j)=callsign(1:6) !### Fix for compound callsigns! - grid2(j)=grid - enddo -10 ncalls=j - close(23) - -! NB: generation of test messages is not yet complete! - j=0 - do i=-1,ncalls - if(i.eq.0 .and. hiscall.eq.' ' .and. hisgrid(1:4).eq.' ') cycle - mz=2 - if(i.eq.-1) mz=1 - if(i.eq.0) mz=65 - do m=1,mz - j=j+1 - if(i.eq.-1) then - msg='0123456789ABC' - else if(i.eq.0) then - if(m.eq.1) msg=mycall//' '//hiscall//' '//hisgrid(1:4) - if(m.eq.2) msg='CQ '//hiscall//' '//hisgrid(1:4) - if(m.ge.3) msg=mycall//' '//hiscall//' '//rpt(m-2) - else - if(m.eq.1) msg=mycall//' '//call2(i)//' '//grid2(i) - if(m.eq.2) msg='CQ '//call2(i)//' '//grid2(i) - endif - call fmtmsg(msg,iz) - call packmsg(msg,dgen,itype) !Pack message into 72 bits - call rs_encode(dgen,sym_rev) !RS encode - sym(0:62)=sym_rev(62:0:-1) - sym1(0:62,j)=sym - - call interleave63(sym_rev,1) !Interleave channel symbols - call graycode(sym_rev,63,1,sym_rev) !Apply Gray code - sym2(0:62,j)=sym_rev(0:62) - msg0(j)=msg - enddo - enddo - nused=j - first=.false. - endif - - ref0=0. - do j=1,63 - ref0=ref0 + s3(mrs(j)+1,j) - enddo - - u1=0. - u1=-99.0 - u2=u1 - -! Find u1 and u2 (best and second-best) codeword from a list, using -! a bank of matched filters on the symbol spectra s3(i,j). - ipk=1 - ipk2=0 - msg00=' ' - do k=1,nused - if(k.ge.2 .and. k.le.64 .and. nflip.lt.0) cycle -! Test all messages if nflip=+1; skip the CQ messages if nflip=-1. - if(nflip.gt.0 .or. msg0(k)(1:3).ne.'CQ ') then - psum=0. - ref=ref0 - do j=1,63 - i=sym2(j-1,k)+1 - psum=psum + s3(i,j) - if(i.eq.mrs(j)+1) ref=ref - s3(i,j) + s3(mrs2(j)+1,j) - enddo - p=psum/ref - - if(p.gt.u1) then - if(msg0(k).ne.msg00) then - ipk2=ipk - u2=u1 - endif - u1=p - ipk=k - msg00=msg0(k) - endif - if(msg0(k).ne.msg00 .and. p.gt.u2) then - u2=p - ipk2=k - endif - endif - enddo - - decoded=' ' - bias=max(1.12*u2,0.35) - if(nadd.ge.4) bias=max(1.08*u2,0.45) - if(nadd.ge.8) bias=max(1.04*u2,0.60) - qual=100.0*(u1-bias) - qmin=1.0 - if(qual.ge.qmin) decoded=msg0(ipk) - - return -end subroutine hint65 +subroutine hint65(s3,mrs,mrs2,nadd,nflip,mycall,hiscall,hisgrid,qual,decoded) + + use packjt + use prog_args + parameter (MAXCALLS=10000,MAXRPT=63) + parameter (MAXMSG=2*MAXCALLS + 2 + MAXRPT) + real s3(64,63) + integer*1 sym1(0:62,MAXMSG) + integer*1 sym2(0:62,MAXMSG) + integer mrs(63),mrs2(63) + integer dgen(12),sym(0:62),sym_rev(0:62) + character*6 mycall,hiscall,hisgrid,call2(MAXCALLS) + character*4 grid2(MAXCALLS),rpt(MAXRPT) + character callsign*12,grid*4 + character*180 line + character ceme*3,msg*22,msg00*22 + character*22 msg0(MAXMSG),decoded + logical*1 eme(MAXCALLS) + logical first + data first/.true./ + 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 first,sym1,nused,msg0,sym2 + + first=.true. !### For now, at least: always recompute hypothetical messages + if(first) then + neme=0 + open(23,file=trim(data_dir)//'/CALL3.TXT',status='unknown') + icall=0 + j=0 + do i=1,MAXCALLS + read(23,1002,end=10) line +1002 format(a80) + if(line(1:4).eq.'ZZZZ') cycle + if(line(1:2).eq.'//') cycle + i1=index(line,',') + if(i1.lt.4) cycle + i2=index(line(i1+1:),',') + if(i2.lt.5) cycle + 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:i1+4) + ceme=line(i2+1:i3-1) + eme(i)=ceme.eq.'EME' + if(neme.eq.1 .and. (.not.eme(i))) cycle + j=j+1 + call2(j)=callsign(1:6) !### Fix for compound callsigns! + grid2(j)=grid + enddo +10 ncalls=j + close(23) + +! NB: generation of test messages is not yet complete! + j=0 + do i=-1,ncalls + if(i.eq.0 .and. hiscall.eq.' ' .and. hisgrid(1:4).eq.' ') cycle + mz=2 + if(i.eq.-1) mz=1 + if(i.eq.0) mz=65 + do m=1,mz + j=j+1 + if(i.eq.-1) then + msg='0123456789ABC' + else if(i.eq.0) then + if(m.eq.1) msg=mycall//' '//hiscall//' '//hisgrid(1:4) + if(m.eq.2) msg='CQ '//hiscall//' '//hisgrid(1:4) + if(m.ge.3) msg=mycall//' '//hiscall//' '//rpt(m-2) + else + if(m.eq.1) msg=mycall//' '//call2(i)//' '//grid2(i) + if(m.eq.2) msg='CQ '//call2(i)//' '//grid2(i) + endif + call fmtmsg(msg,iz) + call packmsg(msg,dgen,itype) !Pack message into 72 bits + call rs_encode(dgen,sym_rev) !RS encode + sym(0:62)=sym_rev(62:0:-1) + sym1(0:62,j)=sym + + call interleave63(sym_rev,1) !Interleave channel symbols + call graycode(sym_rev,63,1,sym_rev) !Apply Gray code + sym2(0:62,j)=sym_rev(0:62) + msg0(j)=msg + enddo + enddo + nused=j + first=.false. + endif + + ref0=0. + do j=1,63 + ref0=ref0 + s3(mrs(j)+1,j) + enddo + + u1=0. + u1=-99.0 + u2=u1 + +! Find u1 and u2 (best and second-best) codeword from a list, using +! a bank of matched filters on the symbol spectra s3(i,j). + ipk=1 + ipk2=0 + msg00=' ' + do k=1,nused + if(k.ge.2 .and. k.le.64 .and. nflip.lt.0) cycle +! Test all messages if nflip=+1; skip the CQ messages if nflip=-1. + if(nflip.gt.0 .or. msg0(k)(1:3).ne.'CQ ') then + psum=0. + ref=ref0 + do j=1,63 + i=sym2(j-1,k)+1 + psum=psum + s3(i,j) + if(i.eq.mrs(j)+1) ref=ref - s3(i,j) + s3(mrs2(j)+1,j) + enddo + p=psum/ref + + if(p.gt.u1) then + if(msg0(k).ne.msg00) then + ipk2=ipk + u2=u1 + endif + u1=p + ipk=k + msg00=msg0(k) + endif + if(msg0(k).ne.msg00 .and. p.gt.u2) then + u2=p + ipk2=k + endif + endif + enddo + + decoded=' ' + bias=max(1.12*u2,0.35) + if(nadd.ge.4) bias=max(1.08*u2,0.45) + if(nadd.ge.8) bias=max(1.04*u2,0.60) + qual=100.0*(u1-bias) + qmin=1.0 + if(qual.ge.qmin) decoded=msg0(ipk) + + return +end subroutine hint65 diff --git a/lib/hspec.f90 b/lib/hspec.f90 index 6dd8539a..216f2ddf 100755 --- a/lib/hspec.f90 +++ b/lib/hspec.f90 @@ -1,111 +1,111 @@ -subroutine hspec(id2,k,nutc0,ntrpdepth,nrxfreq,ntol,bmsk144, & - btrain,pcoeffs,ingain,mycall,hiscall,bshmsg,bswl,datadir,green,s, & - jh,pxmax,dbNoGain,line1) - -! Input: -! k pointer to the most recent new data -! nutc0 UTC for display of decode(s) -! ntrpdepth TR period and 1000*ndepth -! nrxfreq Rx audio center frequency -! ntol Decoding range is +/- ntol -! ncontest Contest type (0=NONE 1=NA_VHF 2=EU_VHF 3=FIELD_DAY 4=RTTY 5=WW_DIGI) -! bmsk144 Boolean, true if in MSK144 mode -! btrain Boolean, turns on training in MSK144 mode -! ingain Relative gain for spectra - -! Output: -! green() power -! s() spectrum for horizontal spectrogram -! jh index of most recent data in green(), s() - - parameter (JZ=703) - character*(*) line1 - character*80 line0 - character*(*) datadir - character*(*) mycall,hiscall - integer*2 id2(0:120*12000-1) - logical*1 bmsk144,bshmsg,btrain,bswl - real green(0:JZ-1) - real s(0:63,0:JZ-1) - real x(512) - real*8 pcoeffs(5) - complex cx(0:256) - data rms/999.0/,k0/99999999/ - equivalence (x,cx) - save ja,rms0 - - ndepth=ntrpdepth/1000 - ntrperiod=ntrpdepth - 1000*ndepth - gain=10.0**(0.1*ingain) - nfft=512 - nstep=nfft - nblks=7 - if(ntrperiod.lt.30) then - nstep=256 - nblks=14 - endif - - if(k.gt.30*12000) go to 900 - if(k.lt.nfft) then - jh=0 - go to 900 !Wait for enough samples to start - endif - - if(k.lt.k0) then !Start a new data block - ja=-nstep - jh=-1 - rms0=0.0 - endif - - pxmax = 0; - do iblk=1,nblks - if(jh.lt.JZ-1) jh=jh+1 - ja=ja+nstep - jb=ja+nfft-1 - x=id2(ja:jb) - sq=dot_product(x,x) - xmax = maxval(x); - xmin = abs(minval(x)); - if (xmin > xmax) xmax = xmin; - if (xmax.gt.0.0) pxmax=20.0*log10(xmax); - rms=sqrt(gain*sq/nfft) - rms2=sqrt(sq/nfft); - green(jh)=0. - if(rms.gt.0.0) then - green(jh)=20.0*log10(rms) - dbNoGain=20.0*log10(rms2); - endif - call four2a(x,nfft,1,-1,0) !Real-to-complex FFT - df=12000.0/nfft - fac=(1.0/nfft)**2 - do i=1,64 - j=2*i - sx=real(cx(j))**2 + aimag(cx(j))**2 + real(cx(j-1))**2 + & - aimag(cx(j-1))**2 - s(i-1,jh)=fac*gain*sx - enddo - if(ja+2*nfft.gt.k) exit - enddo - k0=k - - if(bmsk144) then - if(k.ge.7168) then - tsec=(k-7168)/12000.0 - k0=k-7168 - tt1=sum(float(abs(id2(k0:k0+3583)))) - k0=k-3584 - tt2=sum(float(abs(id2(k0:k0+3583)))) - if(tt1.ne.0.0 .and. tt2.ne.0) then - call mskrtd(id2(k-7168+1:k),nutc0,tsec,ntol,nrxfreq,ndepth, & - mycall,hiscall,bshmsg,btrain,pcoeffs,bswl,datadir,line0) - if(line0(1:1).eq.char(0)) then - line1(1:1)=char(0) - else - line1(1:62)=line0(1:62) - endif - endif - endif - endif - -900 return -end subroutine hspec +subroutine hspec(id2,k,nutc0,ntrpdepth,nrxfreq,ntol,bmsk144, & + btrain,pcoeffs,ingain,mycall,hiscall,bshmsg,bswl,datadir,green,s, & + jh,pxmax,dbNoGain,line1) + +! Input: +! k pointer to the most recent new data +! nutc0 UTC for display of decode(s) +! ntrpdepth TR period and 1000*ndepth +! nrxfreq Rx audio center frequency +! ntol Decoding range is +/- ntol +! ncontest Contest type (0=NONE 1=NA_VHF 2=EU_VHF 3=FIELD_DAY 4=RTTY 5=WW_DIGI) +! bmsk144 Boolean, true if in MSK144 mode +! btrain Boolean, turns on training in MSK144 mode +! ingain Relative gain for spectra + +! Output: +! green() power +! s() spectrum for horizontal spectrogram +! jh index of most recent data in green(), s() + + parameter (JZ=703) + character*(*) line1 + character*80 line0 + character*(*) datadir + character*(*) mycall,hiscall + integer*2 id2(0:120*12000-1) + logical*1 bmsk144,bshmsg,btrain,bswl + real green(0:JZ-1) + real s(0:63,0:JZ-1) + real x(512) + real*8 pcoeffs(5) + complex cx(0:256) + data rms/999.0/,k0/99999999/ + equivalence (x,cx) + save ja,rms0 + + ndepth=ntrpdepth/1000 + ntrperiod=ntrpdepth - 1000*ndepth + gain=10.0**(0.1*ingain) + nfft=512 + nstep=nfft + nblks=7 + if(ntrperiod.lt.30) then + nstep=256 + nblks=14 + endif + + if(k.gt.30*12000) go to 900 + if(k.lt.nfft) then + jh=0 + go to 900 !Wait for enough samples to start + endif + + if(k.lt.k0) then !Start a new data block + ja=-nstep + jh=-1 + rms0=0.0 + endif + + pxmax = 0; + do iblk=1,nblks + if(jh.lt.JZ-1) jh=jh+1 + ja=ja+nstep + jb=ja+nfft-1 + x=id2(ja:jb) + sq=dot_product(x,x) + xmax = maxval(x); + xmin = abs(minval(x)); + if (xmin > xmax) xmax = xmin; + if (xmax.gt.0.0) pxmax=20.0*log10(xmax); + rms=sqrt(gain*sq/nfft) + rms2=sqrt(sq/nfft); + green(jh)=0. + if(rms.gt.0.0) then + green(jh)=20.0*log10(rms) + dbNoGain=20.0*log10(rms2); + endif + call four2a(x,nfft,1,-1,0) !Real-to-complex FFT + df=12000.0/nfft + fac=(1.0/nfft)**2 + do i=1,64 + j=2*i + sx=real(cx(j))**2 + aimag(cx(j))**2 + real(cx(j-1))**2 + & + aimag(cx(j-1))**2 + s(i-1,jh)=fac*gain*sx + enddo + if(ja+2*nfft.gt.k) exit + enddo + k0=k + + if(bmsk144) then + if(k.ge.7168) then + tsec=(k-7168)/12000.0 + k0=k-7168 + tt1=sum(float(abs(id2(k0:k0+3583)))) + k0=k-3584 + tt2=sum(float(abs(id2(k0:k0+3583)))) + if(tt1.ne.0.0 .and. tt2.ne.0) then + call mskrtd(id2(k-7168+1:k),nutc0,tsec,ntol,nrxfreq,ndepth, & + mycall,hiscall,bshmsg,btrain,pcoeffs,bswl,datadir,line0) + if(line0(1:1).eq.char(0)) then + line1(1:1)=char(0) + else + line1(1:62)=line0(1:62) + endif + endif + endif + endif + +900 return +end subroutine hspec diff --git a/lib/igray.c b/lib/igray.c index 490b38ab..4646898b 100755 --- a/lib/igray.c +++ b/lib/igray.c @@ -1,18 +1,18 @@ -int igray_(int *n0, int *idir) -{ - int n; - unsigned long sh; - unsigned long nn; - n=*n0; - - if(*idir>0) return (n ^ (n >> 1)); - - sh = 1; - nn = (n >> sh); - while (nn > 0) { - n ^= nn; - sh <<= 1; - nn = (n >> sh); - } - return (n); -} +int igray_(int *n0, int *idir) +{ + int n; + unsigned long sh; + unsigned long nn; + n=*n0; + + if(*idir>0) return (n ^ (n >> 1)); + + sh = 1; + nn = (n >> sh); + while (nn > 0) { + n ^= nn; + sh <<= 1; + nn = (n >> sh); + } + return (n); +} diff --git a/lib/image.f90 b/lib/image.f90 index f8cf9880..db1d7e13 100755 --- a/lib/image.f90 +++ b/lib/image.f90 @@ -1,336 +1,336 @@ -subroutine imopen(plotfile) - character*(*) plotfile - common/imcom/ lu,npage - - lu=80 - open(lu,file=plotfile,status='unknown') - write(lu,1000) -1000 format('%!PS-Adobe-2.0'/ & - '/rightshow { dup stringwidth pop neg 0 rmoveto show } def'/ & - '/centershow { dup stringwidth pop neg 2 div ', & - '0 rmoveto show } def'/ & - '/lt { lineto } def'/'%%Page: 1 1') - npage=1 - - return -end subroutine imopen - -subroutine impalette(palette) - character*(*) palette - integer r(0:8),g(0:8),b(0:8) - integer rr,gg,bb - common/imcom/ lu,npage - common/imcom2/rr(0:255),gg(0:255),bb(0:255) - - if(palette.eq.'afmhot') then - do i=0,255 - j=255-i - rr(i)=min(255,2*j) - gg(i)=max(0,min(255,2*j-128)) - bb(i)=max(0,min(255,2*j-256)) - enddo - else if(palette.eq.'hot') then - do i=0,255 - j=255-i - rr(i)=min(255,3*j) - gg(i)=max(0,min(255,3*j-256)) - bb(i)=max(0,min(255,3*j-512)) - enddo - else - open(11,file="Palettes/"//palette,status="old") - do j=0,8 - read(11,*) r(j),g(j),b(j) - enddo - close(11) - do i=0,255 - j0=i/32 - j1=j0+1 - k=i-32*j0 - rr(i)=r(j0) + int((k*(r(j1)-r(j0)))/31 + 0.5) - gg(i)=g(j0) + int((k*(g(j1)-g(j0)))/31 + 0.5) - bb(i)=b(j0) + int((k*(b(j1)-b(j0)))/31 + 0.5) - enddo - - endif - - return -end subroutine impalette - -subroutine imclose - common/imcom/ lu,npage - write(lu,1000) -1000 format('showpage'/'%%Trailer') - close(lu) - return -end subroutine imclose - -subroutine imnewpage - common/imcom/ lu,npage - npage=npage+1 - write(lu,1000) npage,npage -1000 format('showpage'/'%%Page:',2i4) - return -end subroutine imnewpage - -subroutine imxline(x,y,dx) -! Draw a line from (x,y) to (x+dx,y) integer r,g,b - common/imcom/ lu,npage - write(lu,1000) 72.0*x,72.0*y,72.0*dx -1000 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto stroke') - return -end subroutine imxline - -subroutine imyline(x,y,dy) -! Draw a line from (x,y) to (x,y+dy) - common/imcom/ lu,npage - write(lu,1000) 72.0*x,72.0*y,72.0*dy -1000 format('newpath',2f7.1,' moveto 0',f7.1,' rlineto stroke') - return -end subroutine imyline - -subroutine imwidth(width) - common/imcom/ lu,npage - write(lu,1000) width -1000 format(f7.1,' setlinewidth') - return -end subroutine imwidth - -subroutine imfont(fontname,npoints) - character*(*) fontname - common/imcom/ lu,npage - write(lu,1000) fontname,npoints -1000 format('/',a,' findfont',i4,' scalefont setfont') - return -end subroutine imfont - -subroutine imstring(string,x,y,just,ndeg) - character*(*) string - common/imcom/ lu,npage - write(lu,1000) 72.0*x,72.0*y,ndeg,string -1000 format(2f7.1,' moveto',i4,' rotate'/'(',a,')') - if(just.eq.1) write(lu,*) 'rightshow' - if(just.eq.2) write(lu,*) 'centershow' - if(just.eq.3) write(lu,*) 'show' - write(lu,1010) -ndeg -1010 format(i4,' rotate'/) - return -end subroutine imstring - -subroutine imr4mat(z,IP,JP,imax,jmax,zz1,zz2,x,y,dx,dy,nbox) - real z(IP,JP) - integer idat(2048) - common/imcom/ lu,npage - - z1=zz1 - z2=zz2 - if(z1.eq.0.0 .and. z2.eq.0.0) then - z1=z(1,1) - z2=z1 - do i=1,imax - do j=1,jmax - z1=min(z(i,j),z1) - z2=max(z(i,j),z2) - enddo - enddo - endif - scale=255.99/(z2-z1) - - write(lu,1002) 72.0*x,72.0*y,72.0*dx,72.0*dy -1002 format(2f7.1,' translate',2f7.1,' scale') - write(lu,*) imax,jmax,8,' [',imax,0,0,jmax,0,0,']' - write(lu,*) '{<' - - do j=1,jmax - do i=1,imax - idat(i)=scale*(z(i,j)-z1) - idat(i)=max(idat(i),0) - idat(i)=min(idat(i),255) - idat(i)=255-idat(i) - enddo - write(lu,1004) (idat(i),i=1,imax) -1004 format(30z2.2) - enddo - write(lu,*) '>} image' - write(lu,1006) 1.0/(72.0*dx),1.0/(72.0*dy),-72.0*x,-72.0*y -1006 format(2f9.6,' scale',2f7.1,' translate') - - if(nbox.ne.0) then - write(lu,1010) 72.0*x,72.0*y,72.0*dx,72.0*dy,-72*dx -1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & - f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') - endif - - return -end subroutine imr4mat - -subroutine imr4mat_color(z,IP,JP,imax,jmax,zz1,zz2,x,y,dx,dy,nbox) - real z(IP,JP) - integer idat(2048,3) - integer rr,gg,bb - common/imcom/ lu,npage - common/imcom2/rr(0:255),gg(0:255),bb(0:255) - - z1=zz1 - z2=zz2 - if(z1.eq.0.0 .and. z2.eq.0.0) then - z1=z(1,1) - z2=z1 - do i=1,imax - do j=1,jmax - z1=min(z(i,j),z1) - z2=max(z(i,j),z2) - enddo - enddo - endif - scale=255.99/(z2-z1) - - write(lu,1002) 72.0*x,72.0*y,72.0*dx,72.0*dy -1002 format(2f7.1,' translate',2f7.1,' scale') - write(lu,1003) imax,jmax,8,imax,0,0,jmax,0,0 -1003 format(3i5,' [',6i4,']') - write(lu,1004) imax -1004 format('{currentfile 3',i4,' mul string readhexstring pop} bind'/ & - 'false 3 colorimage') - - do j=1,jmax - do i=1,imax - n=scale*(z(i,j)-z1) - n=max(n,0) - n=min(n,255) - idat(i,1)=rr(n) - idat(i,2)=gg(n) - idat(i,3)=bb(n) - enddo - write(lu,1005) (idat(i,1),idat(i,2),idat(i,3),i=1,imax) -1005 format(30z2.2) - enddo - - write(lu,1006) 1.0/(72.0*dx),1.0/(72.0*dy),-72.0*x,-72.0*y -1006 format(2f9.6,' scale',2f7.1,' translate') - - if(nbox.ne.0) then - write(lu,1010) 72.0*x,72.0*y,72.0*dx,72.0*dy,-72*dx -1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & - f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') - endif - - return -end subroutine imr4mat_color - -subroutine imr4pro(p,imax,yy1,yy2,x,y,dx,dy,nbox) - real p(imax) - common/imcom/ lu,npage - - y1=yy1 - y2=yy2 - if(y1.eq.0.0 .and. y2.eq.0.0) then - y1=p(1) - y2=y1 - do i=1,imax - y1=min(p(i),y1) - y2=max(p(i),y2) - enddo - endif - - xscale=72.0*dx/imax - xoff=72.0*x - yscale=72.0*dy - if(y1.ne.y2) yscale=yscale/(y2-y1) - yoff=72.0*y - - write(lu,*) '1.416 setmiterlimit' - write(lu,1002) xoff+0.5*xscale,yoff+yscale*(p(1)-y1) -1002 format('newpath',2f7.1,' moveto') - - do i=2,imax - write(lu,1004) xoff+(i-0.5)*xscale,yoff+yscale*(p(i)-y1) -1004 format(2f6.1,' lt') - enddo - write(lu,*) 'stroke' - - if(nbox.ne.0) then - write(lu,1010) xoff,yoff,72.0*dx,72.0*dy,-72*dx -1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & - f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') - endif - - return -end subroutine imr4pro - -subroutine imline(x1,y1,x2,y2) - common/imcom/ lu,npage - write(lu,1000) 72*x1,72*y1,72*x2,72*y2 -1000 format('newpath',2f7.1,' moveto',2f7.1,' lineto stroke') - return -end subroutine imline - -subroutine imcircle(x,y,radius,shade) - common/imcom/ lu,npage - write(lu,1000) shade -1000 format(f7.1,' setgray') - write(lu,1002) 72*x,72*y,72*radius -1002 format('newpath',3f7.1,' 0 360 arc fill') - write(lu,1000) 0.0 - write(lu,1004) 72*x,72*y,72*radius -1004 format('newpath',3f7.1,' 0 360 arc stroke') - return -end subroutine imcircle - -subroutine imtriangle(x,y,rr,shade) - common/imcom/ lu,npage - write(lu,1000) shade -1000 format(f7.1,' setgray') - write(lu,1002) 72*x,72*(y+rr) -1002 format('newpath',2f7.1,' moveto ') - write(lu,1004) 72*(x-rr),72*(y-rr) -1004 format(2f7.1,' lineto ') - write(lu,1004) 72*(x+rr),72*(y-rr) - write(lu,*) 'closepath fill 0 setgray' - write(lu,1002) 72*x,72*(y+rr) - write(lu,1004) 72*(x-rr),72*(y-rr) - write(lu,1004) 72*(x+rr),72*(y-rr) - write(lu,*) 'closepath stroke' - - return -end subroutine imtriangle - -subroutine imr4prov(p,jmax,xx1,xx2,x,y,dx,dy,nbox) - real p(jmax) - common/imcom/ lu,npage - - x1=xx1 - x2=xx2 - if(x1.eq.0.0 .and. x2.eq.0.0) then - x1=p(1) - x2=x1 - do j=1,jmax - x1=min(p(j),x1) - x2=max(p(j),x2) - enddo - endif - - xscale=72.0*dx - xoff=72.0*x - if(x1.ne.x2) xscale=xscale/(x2-x1) - - yscale=72.0*dy/jmax - yoff=72.0*y - - write(lu,*) '1.416 setmiterlimit' - write(lu,1002) xoff+xscale*(x2-p(1)),yoff+0.5*yscale -1002 format('newpath',2f7.1,' moveto') - - do j=2,jmax - write(lu,1004) xoff+xscale*(x2-p(j)),yoff+(j-0.5)*yscale -1004 format(2f6.1,' lt') - enddo - write(lu,*) 'stroke' - - if(nbox.ne.0) then - write(lu,1010) xoff,yoff,72.0*dx,72.0*dy,-72*dx -1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & - f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') - endif - - return -end subroutine imr4prov +subroutine imopen(plotfile) + character*(*) plotfile + common/imcom/ lu,npage + + lu=80 + open(lu,file=plotfile,status='unknown') + write(lu,1000) +1000 format('%!PS-Adobe-2.0'/ & + '/rightshow { dup stringwidth pop neg 0 rmoveto show } def'/ & + '/centershow { dup stringwidth pop neg 2 div ', & + '0 rmoveto show } def'/ & + '/lt { lineto } def'/'%%Page: 1 1') + npage=1 + + return +end subroutine imopen + +subroutine impalette(palette) + character*(*) palette + integer r(0:8),g(0:8),b(0:8) + integer rr,gg,bb + common/imcom/ lu,npage + common/imcom2/rr(0:255),gg(0:255),bb(0:255) + + if(palette.eq.'afmhot') then + do i=0,255 + j=255-i + rr(i)=min(255,2*j) + gg(i)=max(0,min(255,2*j-128)) + bb(i)=max(0,min(255,2*j-256)) + enddo + else if(palette.eq.'hot') then + do i=0,255 + j=255-i + rr(i)=min(255,3*j) + gg(i)=max(0,min(255,3*j-256)) + bb(i)=max(0,min(255,3*j-512)) + enddo + else + open(11,file="Palettes/"//palette,status="old") + do j=0,8 + read(11,*) r(j),g(j),b(j) + enddo + close(11) + do i=0,255 + j0=i/32 + j1=j0+1 + k=i-32*j0 + rr(i)=r(j0) + int((k*(r(j1)-r(j0)))/31 + 0.5) + gg(i)=g(j0) + int((k*(g(j1)-g(j0)))/31 + 0.5) + bb(i)=b(j0) + int((k*(b(j1)-b(j0)))/31 + 0.5) + enddo + + endif + + return +end subroutine impalette + +subroutine imclose + common/imcom/ lu,npage + write(lu,1000) +1000 format('showpage'/'%%Trailer') + close(lu) + return +end subroutine imclose + +subroutine imnewpage + common/imcom/ lu,npage + npage=npage+1 + write(lu,1000) npage,npage +1000 format('showpage'/'%%Page:',2i4) + return +end subroutine imnewpage + +subroutine imxline(x,y,dx) +! Draw a line from (x,y) to (x+dx,y) integer r,g,b + common/imcom/ lu,npage + write(lu,1000) 72.0*x,72.0*y,72.0*dx +1000 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto stroke') + return +end subroutine imxline + +subroutine imyline(x,y,dy) +! Draw a line from (x,y) to (x,y+dy) + common/imcom/ lu,npage + write(lu,1000) 72.0*x,72.0*y,72.0*dy +1000 format('newpath',2f7.1,' moveto 0',f7.1,' rlineto stroke') + return +end subroutine imyline + +subroutine imwidth(width) + common/imcom/ lu,npage + write(lu,1000) width +1000 format(f7.1,' setlinewidth') + return +end subroutine imwidth + +subroutine imfont(fontname,npoints) + character*(*) fontname + common/imcom/ lu,npage + write(lu,1000) fontname,npoints +1000 format('/',a,' findfont',i4,' scalefont setfont') + return +end subroutine imfont + +subroutine imstring(string,x,y,just,ndeg) + character*(*) string + common/imcom/ lu,npage + write(lu,1000) 72.0*x,72.0*y,ndeg,string +1000 format(2f7.1,' moveto',i4,' rotate'/'(',a,')') + if(just.eq.1) write(lu,*) 'rightshow' + if(just.eq.2) write(lu,*) 'centershow' + if(just.eq.3) write(lu,*) 'show' + write(lu,1010) -ndeg +1010 format(i4,' rotate'/) + return +end subroutine imstring + +subroutine imr4mat(z,IP,JP,imax,jmax,zz1,zz2,x,y,dx,dy,nbox) + real z(IP,JP) + integer idat(2048) + common/imcom/ lu,npage + + z1=zz1 + z2=zz2 + if(z1.eq.0.0 .and. z2.eq.0.0) then + z1=z(1,1) + z2=z1 + do i=1,imax + do j=1,jmax + z1=min(z(i,j),z1) + z2=max(z(i,j),z2) + enddo + enddo + endif + scale=255.99/(z2-z1) + + write(lu,1002) 72.0*x,72.0*y,72.0*dx,72.0*dy +1002 format(2f7.1,' translate',2f7.1,' scale') + write(lu,*) imax,jmax,8,' [',imax,0,0,jmax,0,0,']' + write(lu,*) '{<' + + do j=1,jmax + do i=1,imax + idat(i)=scale*(z(i,j)-z1) + idat(i)=max(idat(i),0) + idat(i)=min(idat(i),255) + idat(i)=255-idat(i) + enddo + write(lu,1004) (idat(i),i=1,imax) +1004 format(30z2.2) + enddo + write(lu,*) '>} image' + write(lu,1006) 1.0/(72.0*dx),1.0/(72.0*dy),-72.0*x,-72.0*y +1006 format(2f9.6,' scale',2f7.1,' translate') + + if(nbox.ne.0) then + write(lu,1010) 72.0*x,72.0*y,72.0*dx,72.0*dy,-72*dx +1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & + f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') + endif + + return +end subroutine imr4mat + +subroutine imr4mat_color(z,IP,JP,imax,jmax,zz1,zz2,x,y,dx,dy,nbox) + real z(IP,JP) + integer idat(2048,3) + integer rr,gg,bb + common/imcom/ lu,npage + common/imcom2/rr(0:255),gg(0:255),bb(0:255) + + z1=zz1 + z2=zz2 + if(z1.eq.0.0 .and. z2.eq.0.0) then + z1=z(1,1) + z2=z1 + do i=1,imax + do j=1,jmax + z1=min(z(i,j),z1) + z2=max(z(i,j),z2) + enddo + enddo + endif + scale=255.99/(z2-z1) + + write(lu,1002) 72.0*x,72.0*y,72.0*dx,72.0*dy +1002 format(2f7.1,' translate',2f7.1,' scale') + write(lu,1003) imax,jmax,8,imax,0,0,jmax,0,0 +1003 format(3i5,' [',6i4,']') + write(lu,1004) imax +1004 format('{currentfile 3',i4,' mul string readhexstring pop} bind'/ & + 'false 3 colorimage') + + do j=1,jmax + do i=1,imax + n=scale*(z(i,j)-z1) + n=max(n,0) + n=min(n,255) + idat(i,1)=rr(n) + idat(i,2)=gg(n) + idat(i,3)=bb(n) + enddo + write(lu,1005) (idat(i,1),idat(i,2),idat(i,3),i=1,imax) +1005 format(30z2.2) + enddo + + write(lu,1006) 1.0/(72.0*dx),1.0/(72.0*dy),-72.0*x,-72.0*y +1006 format(2f9.6,' scale',2f7.1,' translate') + + if(nbox.ne.0) then + write(lu,1010) 72.0*x,72.0*y,72.0*dx,72.0*dy,-72*dx +1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & + f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') + endif + + return +end subroutine imr4mat_color + +subroutine imr4pro(p,imax,yy1,yy2,x,y,dx,dy,nbox) + real p(imax) + common/imcom/ lu,npage + + y1=yy1 + y2=yy2 + if(y1.eq.0.0 .and. y2.eq.0.0) then + y1=p(1) + y2=y1 + do i=1,imax + y1=min(p(i),y1) + y2=max(p(i),y2) + enddo + endif + + xscale=72.0*dx/imax + xoff=72.0*x + yscale=72.0*dy + if(y1.ne.y2) yscale=yscale/(y2-y1) + yoff=72.0*y + + write(lu,*) '1.416 setmiterlimit' + write(lu,1002) xoff+0.5*xscale,yoff+yscale*(p(1)-y1) +1002 format('newpath',2f7.1,' moveto') + + do i=2,imax + write(lu,1004) xoff+(i-0.5)*xscale,yoff+yscale*(p(i)-y1) +1004 format(2f6.1,' lt') + enddo + write(lu,*) 'stroke' + + if(nbox.ne.0) then + write(lu,1010) xoff,yoff,72.0*dx,72.0*dy,-72*dx +1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & + f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') + endif + + return +end subroutine imr4pro + +subroutine imline(x1,y1,x2,y2) + common/imcom/ lu,npage + write(lu,1000) 72*x1,72*y1,72*x2,72*y2 +1000 format('newpath',2f7.1,' moveto',2f7.1,' lineto stroke') + return +end subroutine imline + +subroutine imcircle(x,y,radius,shade) + common/imcom/ lu,npage + write(lu,1000) shade +1000 format(f7.1,' setgray') + write(lu,1002) 72*x,72*y,72*radius +1002 format('newpath',3f7.1,' 0 360 arc fill') + write(lu,1000) 0.0 + write(lu,1004) 72*x,72*y,72*radius +1004 format('newpath',3f7.1,' 0 360 arc stroke') + return +end subroutine imcircle + +subroutine imtriangle(x,y,rr,shade) + common/imcom/ lu,npage + write(lu,1000) shade +1000 format(f7.1,' setgray') + write(lu,1002) 72*x,72*(y+rr) +1002 format('newpath',2f7.1,' moveto ') + write(lu,1004) 72*(x-rr),72*(y-rr) +1004 format(2f7.1,' lineto ') + write(lu,1004) 72*(x+rr),72*(y-rr) + write(lu,*) 'closepath fill 0 setgray' + write(lu,1002) 72*x,72*(y+rr) + write(lu,1004) 72*(x-rr),72*(y-rr) + write(lu,1004) 72*(x+rr),72*(y-rr) + write(lu,*) 'closepath stroke' + + return +end subroutine imtriangle + +subroutine imr4prov(p,jmax,xx1,xx2,x,y,dx,dy,nbox) + real p(jmax) + common/imcom/ lu,npage + + x1=xx1 + x2=xx2 + if(x1.eq.0.0 .and. x2.eq.0.0) then + x1=p(1) + x2=x1 + do j=1,jmax + x1=min(p(j),x1) + x2=max(p(j),x2) + enddo + endif + + xscale=72.0*dx + xoff=72.0*x + if(x1.ne.x2) xscale=xscale/(x2-x1) + + yscale=72.0*dy/jmax + yoff=72.0*y + + write(lu,*) '1.416 setmiterlimit' + write(lu,1002) xoff+xscale*(x2-p(1)),yoff+0.5*yscale +1002 format('newpath',2f7.1,' moveto') + + do j=2,jmax + write(lu,1004) xoff+xscale*(x2-p(j)),yoff+(j-0.5)*yscale +1004 format(2f6.1,' lt') + enddo + write(lu,*) 'stroke' + + if(nbox.ne.0) then + write(lu,1010) xoff,yoff,72.0*dx,72.0*dy,-72*dx +1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & + f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') + endif + + return +end subroutine imr4prov diff --git a/lib/indexx.f90 b/lib/indexx.f90 index c14587bb..7a35f53b 100755 --- a/lib/indexx.f90 +++ b/lib/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/lib/init_random_seed.c b/lib/init_random_seed.c index 7b606cd1..7e6ed889 100755 --- a/lib/init_random_seed.c +++ b/lib/init_random_seed.c @@ -1,82 +1,82 @@ -#include "init_random_seed.h" - -#include -#include -#include -#include -#include -#include - -/* basic PRNG to use for improving the basic seed selection */ -static unsigned lcg (uint64_t seed) -{ - if (0 ==seed) - { - seed = UINT64_C(104729); - } - else - { - seed %= UINT64_C(4294967296); - } - seed = (seed * UINT64_C(279470273)) % UINT64_C(4294967291); - return seed % UINT64_MAX; -} - -/* Generate a good PRNG seed value */ -void init_random_seed(void) -{ - unsigned seed = 0u; - int have_seed = 0; - - // try /dev/urandom for an initial seed - int random_source; - if ((random_source = open ("/dev/urandom", O_RDONLY)) >= 0) - { - size_t random_data_length = 0; - have_seed = -1; - while (random_data_length < sizeof seed) - { - ssize_t result = read (random_source, &seed + random_data_length, (sizeof seed) - random_data_length); - if (result < 0) - { - // error, unable to read /dev/random - have_seed = 0; - } - random_data_length += result; - } - close (random_source); - } - if (!have_seed) - { - // fallback to combining the time and PID in a fairly random way - pid_t pid = getpid (); - struct timeval tv; - gettimeofday (&tv, NULL); - seed = (unsigned)(((unsigned)pid << 16) - ^ (unsigned)pid - ^ (unsigned)tv.tv_sec - ^ (unsigned)tv.tv_usec); - seed = lcg (seed); - } - srand (seed); -} - -#ifdef TEST -#include - -int main (int argc, char * argv[]) -{ - init_random_seed (); - int i, j; - int r[10][4]; - for (i = 0; i < 10; ++i) - { - for (j = 0; j < 4; ++j) - { - printf ("%10d ", rand ()); - } - printf ("\n"); - } - return 0; -} -#endif +#include "init_random_seed.h" + +#include +#include +#include +#include +#include +#include + +/* basic PRNG to use for improving the basic seed selection */ +static unsigned lcg (uint64_t seed) +{ + if (0 ==seed) + { + seed = UINT64_C(104729); + } + else + { + seed %= UINT64_C(4294967296); + } + seed = (seed * UINT64_C(279470273)) % UINT64_C(4294967291); + return seed % UINT64_MAX; +} + +/* Generate a good PRNG seed value */ +void init_random_seed(void) +{ + unsigned seed = 0u; + int have_seed = 0; + + // try /dev/urandom for an initial seed + int random_source; + if ((random_source = open ("/dev/urandom", O_RDONLY)) >= 0) + { + size_t random_data_length = 0; + have_seed = -1; + while (random_data_length < sizeof seed) + { + ssize_t result = read (random_source, &seed + random_data_length, (sizeof seed) - random_data_length); + if (result < 0) + { + // error, unable to read /dev/random + have_seed = 0; + } + random_data_length += result; + } + close (random_source); + } + if (!have_seed) + { + // fallback to combining the time and PID in a fairly random way + pid_t pid = getpid (); + struct timeval tv; + gettimeofday (&tv, NULL); + seed = (unsigned)(((unsigned)pid << 16) + ^ (unsigned)pid + ^ (unsigned)tv.tv_sec + ^ (unsigned)tv.tv_usec); + seed = lcg (seed); + } + srand (seed); +} + +#ifdef TEST +#include + +int main (int argc, char * argv[]) +{ + init_random_seed (); + int i, j; + int r[10][4]; + for (i = 0; i < 10; ++i) + { + for (j = 0; j < 4; ++j) + { + printf ("%10d ", rand ()); + } + printf ("\n"); + } + return 0; +} +#endif diff --git a/lib/init_random_seed.f90 b/lib/init_random_seed.f90 index 0d716d4c..7d85f9dd 100755 --- a/lib/init_random_seed.f90 +++ b/lib/init_random_seed.f90 @@ -1,55 +1,55 @@ -! -! Generate a seed for the RANDOM_NUMBER PRNG that is guaranteed to be -! unique even if many processes are started simultaneously -! -subroutine init_random_seed() - use iso_fortran_env, only: int64 - implicit none - integer, allocatable :: seed(:) - integer :: i, n, un, istat, dt(8), pid - integer(int64) :: t - - call random_seed(size = n) - allocate(seed(n)) - ! First try if the OS provides a random number generator - open(newunit=un, file="/dev/urandom", access="stream", & - form="unformatted", action="read", status="old", iostat=istat) - if (istat == 0) then - read(un) seed - close(un) - else - ! Fallback to XOR:ing the current time and pid. The PID is - ! useful in case one launches multiple instances of the same - ! program in parallel. - call system_clock(t) - if (t == 0) then - call date_and_time(values=dt) - t = (dt(1) - 1970) * 365_int64 * 24 * 60 * 60 * 1000 & - + dt(2) * 31_int64 * 24 * 60 * 60 * 1000 & - + dt(3) * 24_int64 * 60 * 60 * 1000 & - + dt(5) * 60 * 60 * 1000 & - + dt(6) * 60 * 1000 + dt(7) * 1000 & - + dt(8) - end if - pid = getpid() - t = ieor(t, int(pid, kind(t))) - do i = 1, n - seed(i) = lcg(t) - end do - end if - call random_seed(put=seed) -contains - ! This simple PRNG might not be good enough for real work, but is - ! sufficient for seeding a better PRNG. - function lcg(s) - integer :: lcg - integer(int64) :: s - if (s == 0) then - s = 104729 - else - s = mod(s, 4294967296_int64) - end if - s = mod(s * 279470273_int64, 4294967291_int64) - lcg = int(mod(s, int(huge(0), int64)), kind(0)) - end function lcg -end subroutine init_random_seed +! +! Generate a seed for the RANDOM_NUMBER PRNG that is guaranteed to be +! unique even if many processes are started simultaneously +! +subroutine init_random_seed() + use iso_fortran_env, only: int64 + implicit none + integer, allocatable :: seed(:) + integer :: i, n, un, istat, dt(8), pid + integer(int64) :: t + + call random_seed(size = n) + allocate(seed(n)) + ! First try if the OS provides a random number generator + open(newunit=un, file="/dev/urandom", access="stream", & + form="unformatted", action="read", status="old", iostat=istat) + if (istat == 0) then + read(un) seed + close(un) + else + ! Fallback to XOR:ing the current time and pid. The PID is + ! useful in case one launches multiple instances of the same + ! program in parallel. + call system_clock(t) + if (t == 0) then + call date_and_time(values=dt) + t = (dt(1) - 1970) * 365_int64 * 24 * 60 * 60 * 1000 & + + dt(2) * 31_int64 * 24 * 60 * 60 * 1000 & + + dt(3) * 24_int64 * 60 * 60 * 1000 & + + dt(5) * 60 * 60 * 1000 & + + dt(6) * 60 * 1000 + dt(7) * 1000 & + + dt(8) + end if + pid = getpid() + t = ieor(t, int(pid, kind(t))) + do i = 1, n + seed(i) = lcg(t) + end do + end if + call random_seed(put=seed) +contains + ! This simple PRNG might not be good enough for real work, but is + ! sufficient for seeding a better PRNG. + function lcg(s) + integer :: lcg + integer(int64) :: s + if (s == 0) then + s = 104729 + else + s = mod(s, 4294967296_int64) + end if + s = mod(s * 279470273_int64, 4294967291_int64) + lcg = int(mod(s, int(huge(0), int64)), kind(0)) + end function lcg +end subroutine init_random_seed diff --git a/lib/init_random_seed.h b/lib/init_random_seed.h index fdb7e0d7..01480338 100755 --- a/lib/init_random_seed.h +++ b/lib/init_random_seed.h @@ -1,20 +1,20 @@ -#ifndef INIT_RANDOM_SEED_H__ -#define INIT_RANDOM_SEED_H__ - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Generate a seed for the RANDOM_NUMBER PRNG that is guaranteed to - * be unique even if many processes are started simultaneously - * - * Not suitable for multi-threaded requirements - */ - void init_random_seed (void); - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef INIT_RANDOM_SEED_H__ +#define INIT_RANDOM_SEED_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * Generate a seed for the RANDOM_NUMBER PRNG that is guaranteed to + * be unique even if many processes are started simultaneously + * + * Not suitable for multi-threaded requirements + */ + void init_random_seed (void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/init_rs.c b/lib/init_rs.c index 679f5486..876819f8 100755 --- a/lib/init_rs.c +++ b/lib/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 - -#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<= (1<= (1<mm = symsize; - rs->nn = (1<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;inn;i++){ - rs->index_of[sr] = i; - rs->alpha_to[i] = sr; - sr <<= 1; - if(sr & (1<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 + +#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<= (1<= (1<mm = symsize; + rs->nn = (1<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;inn;i++){ + rs->index_of[sr] = i; + rs->alpha_to[i] = sr; + sr <<= 1; + if(sr & (1<nn; + } + if(sr != 1){ + /* field generator polynomial is not primitive! */ + free(rs->alpha_to); + free(rs->index_of); + free(rs); + return NULL; + } + + /* Form RS code generator polynomial from its roots */ + rs->genpoly = (DTYPE *)malloc(sizeof(DTYPE)*(nroots+1)); + if(rs->genpoly == NULL){ + free(rs->alpha_to); + free(rs->index_of); + free(rs); + return NULL; + } + rs->fcr = fcr; + rs->prim = prim; + rs->nroots = nroots; + + /* Find prim-th root of 1, used in decoding */ + for(iprim=1;(iprim % prim) != 0;iprim += rs->nn) + ; + rs->iprim = iprim / prim; + + rs->genpoly[0] = 1; + for (i = 0,root=fcr*prim; i < nroots; i++,root += prim) { + rs->genpoly[i+1] = 1; + + /* Multiply rs->genpoly[] by @**(root + x) */ + for (j = i; j > 0; j--){ + if (rs->genpoly[j] != 0) + rs->genpoly[j] = rs->genpoly[j-1] ^ rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[j]] + root)]; + else + rs->genpoly[j] = rs->genpoly[j-1]; + } + /* rs->genpoly[0] can never be zero */ + rs->genpoly[0] = rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[0]] + root)]; + } + /* convert rs->genpoly[] to index form for quicker encoding */ + for (i = 0; i <= nroots; i++) + rs->genpoly[i] = rs->index_of[rs->genpoly[i]]; + + return rs; +} diff --git a/lib/int.h b/lib/int.h index 0591b118..056241e1 100755 --- a/lib/int.h +++ b/lib/int.h @@ -1,57 +1,57 @@ -/* Include file to configure the RS codec for integer symbols - * - * Copyright 2002, Phil Karn, KA9Q - * May be used under the terms of the GNU General Public License (GPL) - */ -#define DTYPE int - -/* Reed-Solomon codec control block */ -struct rs { - int mm; /* Bits per symbol */ - int nn; /* Symbols per block (= (1<= rs->nn) { - x -= rs->nn; - x = (x >> rs->mm) + (x & rs->nn); - } - return x; -} -#define MODNN(x) modnn(rs,x) - -#define MM (rs->mm) -#define NN (rs->nn) -#define ALPHA_TO (rs->alpha_to) -#define INDEX_OF (rs->index_of) -#define GENPOLY (rs->genpoly) -//#define NROOTS (rs->nroots) -#define NROOTS (51) -#define FCR (rs->fcr) -#define PRIM (rs->prim) -#define IPRIM (rs->iprim) -#define PAD (rs->pad) -#define A0 (NN) - -#define ENCODE_RS encode_rs_int -#define DECODE_RS decode_rs_int -#define INIT_RS init_rs_int -#define FREE_RS free_rs_int - -void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity); -int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras); -void *INIT_RS(int symsize,int gfpoly,int fcr, - int prim,int nroots,int pad); -void FREE_RS(void *p); - - - - +/* Include file to configure the RS codec for integer symbols + * + * Copyright 2002, Phil Karn, KA9Q + * May be used under the terms of the GNU General Public License (GPL) + */ +#define DTYPE int + +/* Reed-Solomon codec control block */ +struct rs { + int mm; /* Bits per symbol */ + int nn; /* Symbols per block (= (1<= rs->nn) { + x -= rs->nn; + x = (x >> rs->mm) + (x & rs->nn); + } + return x; +} +#define MODNN(x) modnn(rs,x) + +#define MM (rs->mm) +#define NN (rs->nn) +#define ALPHA_TO (rs->alpha_to) +#define INDEX_OF (rs->index_of) +#define GENPOLY (rs->genpoly) +//#define NROOTS (rs->nroots) +#define NROOTS (51) +#define FCR (rs->fcr) +#define PRIM (rs->prim) +#define IPRIM (rs->iprim) +#define PAD (rs->pad) +#define A0 (NN) + +#define ENCODE_RS encode_rs_int +#define DECODE_RS decode_rs_int +#define INIT_RS init_rs_int +#define FREE_RS free_rs_int + +void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity); +int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras); +void *INIT_RS(int symsize,int gfpoly,int fcr, + int prim,int nroots,int pad); +void FREE_RS(void *p); + + + + diff --git a/lib/inter_wspr.f90 b/lib/inter_wspr.f90 index 276b4439..9f980454 100755 --- a/lib/inter_wspr.f90 +++ b/lib/inter_wspr.f90 @@ -1,45 +1,45 @@ -subroutine inter_wspr(id,ndir) - -! Interleave (ndir=1) or de-interleave (ndir=-1) the array id. - - integer*1 id(0:161),itmp(0:161) - integer j0(0:161) - logical first - data first/.true./ - save - - if(first) then -! Compute the interleave table using bit reversal. - k=-1 - do i=0,255 - n=0 - ii=i - do j=0,7 - n=n+n - if(iand(ii,1).ne.0) n=n+1 - ii=ii/2 - enddo - if(n.le.161) then - k=k+1 - j0(k)=n - endif - enddo - first=.false. - endif - - if(ndir.eq.1) then - do i=0,161 - itmp(j0(i))=id(i) - enddo - else - do i=0,161 - itmp(i)=id(j0(i)) - enddo - endif - - do i=0,161 - id(i)=itmp(i) - enddo - - return -end subroutine inter_wspr +subroutine inter_wspr(id,ndir) + +! Interleave (ndir=1) or de-interleave (ndir=-1) the array id. + + integer*1 id(0:161),itmp(0:161) + integer j0(0:161) + logical first + data first/.true./ + save + + if(first) then +! Compute the interleave table using bit reversal. + k=-1 + do i=0,255 + n=0 + ii=i + do j=0,7 + n=n+n + if(iand(ii,1).ne.0) n=n+1 + ii=ii/2 + enddo + if(n.le.161) then + k=k+1 + j0(k)=n + endif + enddo + first=.false. + endif + + if(ndir.eq.1) then + do i=0,161 + itmp(j0(i))=id(i) + enddo + else + do i=0,161 + itmp(i)=id(j0(i)) + enddo + endif + + do i=0,161 + id(i)=itmp(i) + enddo + + return +end subroutine inter_wspr diff --git a/lib/interleave4.f90 b/lib/interleave4.f90 index dd666cc6..db57ec32 100755 --- a/lib/interleave4.f90 +++ b/lib/interleave4.f90 @@ -1,43 +1,43 @@ -subroutine interleave4(id,ndir) - integer*1 id(0:205),itmp(0:205) - integer j0(0:205) - logical first - data first/.true./ - save first,j0 - - if(first) then - k=-1 - do i=0,255 - m=i - n=iand(m,1) - n=2*n + iand(m/2,1) - n=2*n + iand(m/4,1) - n=2*n + iand(m/8,1) - n=2*n + iand(m/16,1) - n=2*n + iand(m/32,1) - n=2*n + iand(m/64,1) - n=2*n + iand(m/128,1) - if(n.le.205) then - k=k+1 - j0(k)=n - endif - enddo - first=.false. - endif - - if(ndir.eq.1) then - do i=0,205 - itmp(j0(i))=id(i) - enddo - else - do i=0,205 - itmp(i)=id(j0(i)) - enddo - endif - - do i=0,205 - id(i)=itmp(i) - enddo - - return -end subroutine interleave4 +subroutine interleave4(id,ndir) + integer*1 id(0:205),itmp(0:205) + integer j0(0:205) + logical first + data first/.true./ + save first,j0 + + if(first) then + k=-1 + do i=0,255 + m=i + n=iand(m,1) + n=2*n + iand(m/2,1) + n=2*n + iand(m/4,1) + n=2*n + iand(m/8,1) + n=2*n + iand(m/16,1) + n=2*n + iand(m/32,1) + n=2*n + iand(m/64,1) + n=2*n + iand(m/128,1) + if(n.le.205) then + k=k+1 + j0(k)=n + endif + enddo + first=.false. + endif + + if(ndir.eq.1) then + do i=0,205 + itmp(j0(i))=id(i) + enddo + else + do i=0,205 + itmp(i)=id(j0(i)) + enddo + endif + + do i=0,205 + id(i)=itmp(i) + enddo + + return +end subroutine interleave4 diff --git a/lib/iso_c_utilities.f90 b/lib/iso_c_utilities.f90 index 021c7cde..cdcc1a74 100755 --- a/lib/iso_c_utilities.f90 +++ b/lib/iso_c_utilities.f90 @@ -1,87 +1,87 @@ -module iso_c_utilities - - use, intrinsic :: iso_c_binding, only: c_ptr, c_char, c_f_pointer, c_associated - implicit none - - public :: c_to_f_string, c_f_dyn_string - - private - - character(c_char), dimension(1), save, target :: dummy_string = "?" - - interface ! strlen is a standard C function from - ! int strlen(char *string) - function strlen (string) result (len) bind (c, name="strlen") - use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t - implicit none - type(c_ptr), value :: string - integer(kind=c_size_t) :: len - end function strlen - - ! void free(void * p) - subroutine c_free (p) bind (c, name="free") - use, intrinsic :: iso_c_binding, only: c_ptr - implicit none - type(c_ptr), value :: p - end subroutine c_free - end interface - -contains - - ! - ! Cast C string pointer to Fortran string pointer - ! - ! Warning! - C data must outlive result scope - ! - function c_to_f_string (c_str) result (f_str) - use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer, c_char - implicit none - type(c_ptr), intent(in) :: c_str - character(kind=c_char, len=:), pointer :: f_str - character(kind=c_char), pointer :: arr(:) - interface ! strlen is a standard C function from - ! int strlen(char *string) - function strlen (string) result (len) bind (c, name="strlen") - use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t - implicit none - type(c_ptr), value :: string - integer(kind=c_size_t) :: len - end function strlen - end interface - call c_f_pointer (c_str, arr, [strlen (c_str)]) - call get_scalar_pointer (size (arr), arr, f_str) - end function c_to_f_string - - subroutine get_scalar_pointer (scalar_len, scalar, fptr) - ! Convert a null-terminated C string into a Fortran character pointer - use, intrinsic :: iso_c_binding, only: c_char - integer, intent(in) :: scalar_len - character(kind=c_char, len=scalar_len), intent(in), target :: scalar(1) - character(kind=c_char, len=:), pointer :: fptr - fptr => scalar(1) - end subroutine get_scalar_pointer - - function c_f_dyn_string (cptr) result (fstr) - ! Convert a null-terminated malloc'ed C string into a Fortran character array - type(c_ptr), intent(in) :: cptr ! The C address - character(kind=c_char), allocatable :: fstr(:) - character(kind=c_char), pointer :: fptr(:) - interface ! strlen is a standard C function from - ! void free(void * p) - subroutine c_free (p) bind (c, name="free") - use, intrinsic :: iso_c_binding, only: c_ptr - implicit none - type(c_ptr), value :: p - end subroutine c_free - end interface - if (c_associated (cptr)) then - call c_f_pointer (fptr=fptr, cptr=cptr, shape=[strlen(cptr)]) - else - ! To avoid segfaults, associate FPTR with a dummy target: - fptr => dummy_string - end if - fstr = fptr - call c_free (cptr) - end function c_f_dyn_string - -end module +module iso_c_utilities + + use, intrinsic :: iso_c_binding, only: c_ptr, c_char, c_f_pointer, c_associated + implicit none + + public :: c_to_f_string, c_f_dyn_string + + private + + character(c_char), dimension(1), save, target :: dummy_string = "?" + + interface ! strlen is a standard C function from + ! int strlen(char *string) + function strlen (string) result (len) bind (c, name="strlen") + use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t + implicit none + type(c_ptr), value :: string + integer(kind=c_size_t) :: len + end function strlen + + ! void free(void * p) + subroutine c_free (p) bind (c, name="free") + use, intrinsic :: iso_c_binding, only: c_ptr + implicit none + type(c_ptr), value :: p + end subroutine c_free + end interface + +contains + + ! + ! Cast C string pointer to Fortran string pointer + ! + ! Warning! - C data must outlive result scope + ! + function c_to_f_string (c_str) result (f_str) + use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer, c_char + implicit none + type(c_ptr), intent(in) :: c_str + character(kind=c_char, len=:), pointer :: f_str + character(kind=c_char), pointer :: arr(:) + interface ! strlen is a standard C function from + ! int strlen(char *string) + function strlen (string) result (len) bind (c, name="strlen") + use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t + implicit none + type(c_ptr), value :: string + integer(kind=c_size_t) :: len + end function strlen + end interface + call c_f_pointer (c_str, arr, [strlen (c_str)]) + call get_scalar_pointer (size (arr), arr, f_str) + end function c_to_f_string + + subroutine get_scalar_pointer (scalar_len, scalar, fptr) + ! Convert a null-terminated C string into a Fortran character pointer + use, intrinsic :: iso_c_binding, only: c_char + integer, intent(in) :: scalar_len + character(kind=c_char, len=scalar_len), intent(in), target :: scalar(1) + character(kind=c_char, len=:), pointer :: fptr + fptr => scalar(1) + end subroutine get_scalar_pointer + + function c_f_dyn_string (cptr) result (fstr) + ! Convert a null-terminated malloc'ed C string into a Fortran character array + type(c_ptr), intent(in) :: cptr ! The C address + character(kind=c_char), allocatable :: fstr(:) + character(kind=c_char), pointer :: fptr(:) + interface ! strlen is a standard C function from + ! void free(void * p) + subroutine c_free (p) bind (c, name="free") + use, intrinsic :: iso_c_binding, only: c_ptr + implicit none + type(c_ptr), value :: p + end subroutine c_free + end interface + if (c_associated (cptr)) then + call c_f_pointer (fptr=fptr, cptr=cptr, shape=[strlen(cptr)]) + else + ! To avoid segfaults, associate FPTR with a dummy target: + fptr => dummy_string + end if + fstr = fptr + call c_free (cptr) + end function c_f_dyn_string + +end module diff --git a/lib/jplsubs.f b/lib/jplsubs.f index 0920bc3a..6dcd1c9b 100755 --- a/lib/jplsubs.f +++ b/lib/jplsubs.f @@ -1,899 +1,899 @@ -C++++++++++++++++++++++++ -C - SUBROUTINE FSIZER1(NRECL,KSIZE,NRFILE,NAMFIL) -C -C++++++++++++++++++++++++ -C -C Version 1.0 uses the INQUIRE statement to find out the the record length -C of the direct access file before opening it. This procedure is non-standard, -C but seems to work for VAX machines. -C -C THE SUBROUTINE ALSO SETS THE VALUES OF NRECL, NRFILE, AND NAMFIL. - -C ***************************************************************** -C ***************************************************************** -C -C THE PARAMETERS NAMFIL, NRECL, AND NRFILE ARE TO BE SET BY THE USER -C -C ***************************************************************** - -C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE - - CHARACTER*256 NAMFIL - -c NAMFIL='JPLEPH' - -C ***************************************************************** - -C NRECL=1 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN S.P. WORDS -C NRECL=4 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN BYTES -C (for a VAX, it is probably 1) -C - NRECL=4 - -C ***************************************************************** - -C NRFILE IS THE INTERNAL UNIT NUMBER USED FOR THE EPHEMERIS FILE - -c NRFILE=12 - -C ***************************************************************** - -C FIND THE RECORD SIZE USING THE INQUIRE STATEMENT - - -c IRECSZ=0 - - INQUIRE(FILE=NAMFIL,RECL=IRECSZ) - -C IF 'INQUIRE' DOES NOT WORK, USUALLY IRECSZ WILL BE LEFT AT 0 - - IF(IRECSZ .LE. 0) write(*,*) - . ' INQUIRE STATEMENT PROBABLY DID NOT WORK' - - KSIZE=IRECSZ/NRECL - if(nrfile.eq.-99) stop !silence compiler warning - - RETURN - - END -C++++++++++++++++++++++++ -C - SUBROUTINE FSIZER2(NRECL,KSIZE,NRFILE,NAMFIL) -C -C++++++++++++++++++++++++ -C THIS SUBROUTINE OPENS THE FILE, 'NAMFIL', WITH A PHONY RECORD LENGTH, READS -C THE FIRST RECORD, AND USES THE INFO TO COMPUTE KSIZE, THE NUMBER OF SINGLE -C PRECISION WORDS IN A RECORD. -C -C THE SUBROUTINE ALSO SETS THE VALUES OF NRECL, NRFILE, AND NAMFIL. - - IMPLICIT DOUBLE PRECISION(A-H,O-Z) - - SAVE - - INTEGER OLDMAX - PARAMETER (OLDMAX = 400) - INTEGER NMAX - PARAMETER (NMAX = 1000) - CHARACTER*6 TTL(14,3),CNAM(NMAX) - CHARACTER*256 NAMFIL,jpleph_file_name - DIMENSION SS(3) - INTEGER IPT(3,13) - common/jplcom/jpleph_file_name - -C ***************************************************************** -C ***************************************************************** -C -C THE PARAMETERS NRECL, NRFILE, AND NAMFIL ARE TO BE SET BY THE USER -C -C ***************************************************************** - -C NRECL=1 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN S.P. WORDS -C NRECL=4 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN BYTES -C (for UNIX, it is probably 4) -C - NRECL=4 - -C NRFILE IS THE INTERNAL UNIT NUMBER USED FOR THE EPHEMERIS FILE - - NRFILE=12 - -C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE - -! NAMFIL='JPLEPH' - NAMFIL=jpleph_file_name - -C ***************************************************************** -C ***************************************************************** - -C ** OPEN THE DIRECT-ACCESS FILE AND GET THE POINTERS IN ORDER TO -C ** DETERMINE THE SIZE OF THE EPHEMERIS RECORD - - MRECL=NRECL*1000 - - OPEN(NRFILE, - * FILE=NAMFIL, - * ACCESS='DIRECT', - * FORM='UNFORMATTED', - * RECL=MRECL, - * STATUS='OLD') - - READ(NRFILE,REC=1)TTL,(CNAM(K),K=1,OLDMAX),SS,NCON,AU,EMRAT, - & ((IPT(I,J),I=1,3),J=1,12),NUMDE,(IPT(I,13),I=1,3) - - CLOSE(NRFILE) - -C FIND THE NUMBER OF EPHEMERIS COEFFICIENTS FROM THE POINTERS - - KMX = 0 - KHI = 0 - - DO I = 1,13 - IF (IPT(1,I) .GT. KMX) THEN - KMX = IPT(1,I) - KHI = I - ENDIF - ENDDO - - ND = 3 - IF (KHI .EQ. 12) ND=2 - - KSIZE = 2*(IPT(1,KHI)+ND*IPT(2,KHI)*IPT(3,KHI)-1) - - RETURN - - END -C++++++++++++++++++++++++ -C - SUBROUTINE FSIZER3(NRECL,KSIZE,NRFILE,NAMFIL) -C -C++++++++++++++++++++++++ -C -C THE SUBROUTINE SETS THE VALUES OF NRECL, KSIZE, NRFILE, AND NAMFIL. - - SAVE - CHARACTER*256 NAMFIL,jpleph_file_name - common/jplcom/jpleph_file_name - -C ***************************************************************** -C ***************************************************************** -C -C THE PARAMETERS NRECL, NRFILE, AND NAMFIL ARE TO BE SET BY THE USER - -C ***************************************************************** - -C NRECL=1 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN S.P. WORDS -C NRECL=4 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN BYTES - - NRECL=4 - -C ***************************************************************** - -C NRFILE IS THE INTERNAL UNIT NUMBER USED FOR THE EPHEMERIS FILE (DEFAULT: 12) - - NRFILE=12 - -C ***************************************************************** - -C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE - -! NAMFIL='JPLEPH' - NAMFIL=jpleph_file_name - -C ***************************************************************** - -C KSIZE must be set by the user according to the ephemeris to be read - -C For de200, set KSIZE to 1652 -C For de405, set KSIZE to 2036 -C For de406, set KSIZE to 1456 -C For de414, set KSIZE to 2036 -C For de418, set KSIZE to 2036 -C For de421, set KSIZE to 2036 -C For de422, set KSIZE to 2036 -C For de423, set KSIZE to 2036 -C For de424, set KSIZE to 2036 -C For de430, set KSIZE to 2036 - - KSIZE = 2036 - -C ******************************************************************* - - RETURN - - END -C++++++++++++++++++++++++++ -C - SUBROUTINE PLEPH ( ET, NTARG, NCENT, RRD ) -C -C++++++++++++++++++++++++++ -C NOTE : Over the years, different versions of PLEPH have had a fifth argument: -C sometimes, an error return statement number; sometimes, a logical denoting -C whether or not the requested date is covered by the ephemeris. We apologize -C for this inconsistency; in this present version, we use only the four necessary -C arguments and do the testing outside of the subroutine. -C -C THIS SUBROUTINE READS THE JPL PLANETARY EPHEMERIS -C AND GIVES THE POSITION AND VELOCITY OF THE POINT 'NTARG' -C WITH RESPECT TO 'NCENT'. -C -C CALLING SEQUENCE PARAMETERS: -C -C ET = D.P. JULIAN EPHEMERIS DATE AT WHICH INTERPOLATION -C IS WANTED. -C -C ** NOTE THE ENTRY DPLEPH FOR A DOUBLY-DIMENSIONED TIME ** -C THE REASON FOR THIS OPTION IS DISCUSSED IN THE -C SUBROUTINE STATE -C -C NTARG = INTEGER NUMBER OF 'TARGET' POINT. -C -C NCENT = INTEGER NUMBER OF CENTER POINT. -C -C THE NUMBERING CONVENTION FOR 'NTARG' AND 'NCENT' IS: -C -C 1 = MERCURY 8 = NEPTUNE -C 2 = VENUS 9 = PLUTO -C 3 = EARTH 10 = MOON -C 4 = MARS 11 = SUN -C 5 = JUPITER 12 = SOLAR-SYSTEM BARYCENTER -C 6 = SATURN 13 = EARTH-MOON BARYCENTER -C 7 = URANUS 14 = NUTATIONS (LONGITUDE AND OBLIQ) -C 15 = LIBRATIONS, IF ON EPH FILE -C -C (IF NUTATIONS ARE WANTED, SET NTARG = 14. FOR LIBRATIONS, -C SET NTARG = 15. SET NCENT=0.) -C -C RRD = OUTPUT 6-WORD D.P. ARRAY CONTAINING POSITION AND VELOCITY -C OF POINT 'NTARG' RELATIVE TO 'NCENT'. THE UNITS ARE AU AND -C AU/DAY. FOR LIBRATIONS THE UNITS ARE RADIANS AND RADIANS -C PER DAY. IN THE CASE OF NUTATIONS THE FIRST FOUR WORDS OF -C RRD WILL BE SET TO NUTATIONS AND RATES, HAVING UNITS OF -C RADIANS AND RADIANS/DAY. -C -C The option is available to have the units in km and km/sec. -C For this, set km=.true. in the STCOMX common block. -C - - IMPLICIT DOUBLE PRECISION (A-H,O-Z) - - INTEGER NMAX - PARAMETER (NMAX = 1000) - - DIMENSION RRD(6),ET2Z(2),ET2(2),PV(6,13) - DIMENSION PVST(6,11),PNUT(4) - DIMENSION SS(3),CVAL(NMAX),PVSUN(6),ZIPS(2) - DATA ZIPS/2*0.d0/ - - LOGICAL BSAVE,KM,BARY - LOGICAL FIRST - DATA FIRST/.TRUE./ - - INTEGER LIST(12),IPT(39),DENUM - COMMON/EPHHDR/CVAL,SS,AU,EMRAT,DENUM,NCON,IPT - COMMON/STCOMX/KM,BARY,PVSUN - -C INITIALIZE ET2 FOR 'STATE' AND SET UP COMPONENT COUNT -C - ET2(1)=ET - ET2(2)=0.D0 - GO TO 11 - -C ENTRY POINT 'DPLEPH' FOR DOUBLY-DIMENSIONED TIME ARGUMENT -C (SEE THE DISCUSSION IN THE SUBROUTINE STATE) - - ENTRY DPLEPH(ET2Z,NTARG,NCENT,RRD) - - ET2(1)=ET2Z(1) - ET2(2)=ET2Z(2) - - 11 IF(FIRST) CALL STATE(ZIPS,LIST,PVST,PNUT) - FIRST=.FALSE. - - IF(NTARG .EQ. NCENT) RETURN - - DO I=1,12 - LIST(I)=0 - ENDDO - -C CHECK FOR NUTATION CALL - - IF(NTARG.NE.14) GO TO 97 - IF(IPT(35).GT.0) THEN - LIST(11)=2 - CALL STATE(ET2,LIST,PVST,PNUT) - DO I=1,4 - RRD(I)=PNUT(I) - ENDDO - RRD(5) = 0.d0 - RRD(6) = 0.d0 - RETURN - ELSE - DO I=1,4 - RRD(I)=0.d0 - ENDDO - WRITE(6,297) - 297 FORMAT(' ***** NO NUTATIONS ON THE EPHEMERIS FILE *****') - STOP - ENDIF - -C CHECK FOR LIBRATIONS - - 97 CONTINUE - DO I=1,6 - RRD(I)=0.d0 - ENDDO - - IF(NTARG.NE.15) GO TO 98 - IF(IPT(38).GT.0) THEN - LIST(12)=2 - CALL STATE(ET2,LIST,PVST,PNUT) - DO I=1,6 - RRD(I)=PVST(I,11) - ENDDO - RETURN - ELSE - WRITE(6,298) - 298 FORMAT(' ***** NO LIBRATIONS ON THE EPHEMERIS FILE *****') - STOP - ENDIF - -C FORCE BARYCENTRIC OUTPUT BY 'STATE' - - 98 BSAVE=BARY - BARY=.TRUE. - -C SET UP PROPER ENTRIES IN 'LIST' ARRAY FOR STATE CALL - - DO I=1,2 - K=NTARG - IF(I .EQ. 2) K=NCENT - IF(K .LE. 10) LIST(K)=2 - IF(K .EQ. 10) LIST(3)=2 - IF(K .EQ. 3) LIST(10)=2 - IF(K .EQ. 13) LIST(3)=2 - ENDDO - -C MAKE CALL TO STATE - - CALL STATE(ET2,LIST,PVST,PNUT) - - DO I=1,10 - DO J = 1,6 - PV(J,I) = PVST(J,I) - ENDDO - ENDDO - - IF(NTARG .EQ. 11 .OR. NCENT .EQ. 11) THEN - DO I=1,6 - PV(I,11)=PVSUN(I) - ENDDO - ENDIF - - IF(NTARG .EQ. 12 .OR. NCENT .EQ. 12) THEN - DO I=1,6 - PV(I,12)=0.D0 - ENDDO - ENDIF - - IF(NTARG .EQ. 13 .OR. NCENT .EQ. 13) THEN - DO I=1,6 - PV(I,13) = PVST(I,3) - ENDDO - ENDIF - - IF(NTARG*NCENT .EQ. 30 .AND. NTARG+NCENT .EQ. 13) THEN - DO I=1,6 - PV(I,3)=0.D0 - ENDDO - GO TO 99 - ENDIF - - IF(LIST(3) .EQ. 2) THEN - DO I=1,6 - PV(I,3)=PVST(I,3)-PVST(I,10)/(1.D0+EMRAT) - ENDDO - ENDIF - - IF(LIST(10) .EQ. 2) THEN - DO I=1,6 - PV(I,10) = PV(I,3)+PVST(I,10) - ENDDO - ENDIF - - 99 DO I=1,6 - RRD(I)=PV(I,NTARG)-PV(I,NCENT) - ENDDO - - BARY=BSAVE - - RETURN - END -C+++++++++++++++++++++++++++++++++ -C - SUBROUTINE INTERP(BUF,T,NCF,NCM,NA,IFL,PV) -C -C+++++++++++++++++++++++++++++++++ -C -C THIS SUBROUTINE DIFFERENTIATES AND INTERPOLATES A -C SET OF CHEBYSHEV COEFFICIENTS TO GIVE POSITION AND VELOCITY -C -C CALLING SEQUENCE PARAMETERS: -C -C INPUT: -C -C BUF 1ST LOCATION OF ARRAY OF D.P. CHEBYSHEV COEFFICIENTS OF POSITION -C -C T T(1) IS DP FRACTIONAL TIME IN INTERVAL COVERED BY -C COEFFICIENTS AT WHICH INTERPOLATION IS WANTED -C (0 .LE. T(1) .LE. 1). T(2) IS DP LENGTH OF WHOLE -C INTERVAL IN INPUT TIME UNITS. -C -C NCF # OF COEFFICIENTS PER COMPONENT -C -C NCM # OF COMPONENTS PER SET OF COEFFICIENTS -C -C NA # OF SETS OF COEFFICIENTS IN FULL ARRAY -C (I.E., # OF SUB-INTERVALS IN FULL INTERVAL) -C -C IFL INTEGER FLAG: =1 FOR POSITIONS ONLY -C =2 FOR POS AND VEL -C -C -C OUTPUT: -C -C PV INTERPOLATED QUANTITIES REQUESTED. DIMENSION -C EXPECTED IS PV(NCM,IFL), DP. -C -C - IMPLICIT DOUBLE PRECISION (A-H,O-Z) -C - SAVE -C - DOUBLE PRECISION BUF(NCF,NCM,*),T(2),PV(NCM,*),PC(18),VC(18) - -C - DATA NP/2/ - DATA NV/3/ - DATA TWOT/0.D0/ - DATA PC(1),PC(2)/1.D0,0.D0/ - DATA VC(2)/1.D0/ -C -C ENTRY POINT. GET CORRECT SUB-INTERVAL NUMBER FOR THIS SET -C OF COEFFICIENTS AND THEN GET NORMALIZED CHEBYSHEV TIME -C WITHIN THAT SUBINTERVAL. -C - DNA=DBLE(NA) - DT1=DINT(T(1)) - TEMP=DNA*T(1) - L=IDINT(TEMP-DT1)+1 - -C TC IS THE NORMALIZED CHEBYSHEV TIME (-1 .LE. TC .LE. 1) - - TC=2.D0*(DMOD(TEMP,1.D0)+DT1)-1.D0 - -C CHECK TO SEE WHETHER CHEBYSHEV TIME HAS CHANGED, -C AND COMPUTE NEW POLYNOMIAL VALUES IF IT HAS. -C (THE ELEMENT PC(2) IS THE VALUE OF T1(TC) AND HENCE -C CONTAINS THE VALUE OF TC ON THE PREVIOUS CALL.) - - IF(TC.NE.PC(2)) THEN - NP=2 - NV=3 - PC(2)=TC - TWOT=TC+TC - ENDIF -C -C BE SURE THAT AT LEAST 'NCF' POLYNOMIALS HAVE BEEN EVALUATED -C AND ARE STORED IN THE ARRAY 'PC'. -C - IF(NP.LT.NCF) THEN - DO 1 I=NP+1,NCF - PC(I)=TWOT*PC(I-1)-PC(I-2) - 1 CONTINUE - NP=NCF - ENDIF -C -C INTERPOLATE TO GET POSITION FOR EACH COMPONENT -C - DO 2 I=1,NCM - PV(I,1)=0.D0 - DO 3 J=NCF,1,-1 - PV(I,1)=PV(I,1)+PC(J)*BUF(J,I,L) - 3 CONTINUE - 2 CONTINUE - IF(IFL.LE.1) RETURN -C -C IF VELOCITY INTERPOLATION IS WANTED, BE SURE ENOUGH -C DERIVATIVE POLYNOMIALS HAVE BEEN GENERATED AND STORED. -C - VFAC=(DNA+DNA)/T(2) - VC(3)=TWOT+TWOT - IF(NV.LT.NCF) THEN - DO 4 I=NV+1,NCF - VC(I)=TWOT*VC(I-1)+PC(I-1)+PC(I-1)-VC(I-2) - 4 CONTINUE - NV=NCF - ENDIF -C -C INTERPOLATE TO GET VELOCITY FOR EACH COMPONENT -C - DO 5 I=1,NCM - PV(I,2)=0.D0 - DO 6 J=NCF,2,-1 - PV(I,2)=PV(I,2)+VC(J)*BUF(J,I,L) - 6 CONTINUE - PV(I,2)=PV(I,2)*VFAC - 5 CONTINUE -C - RETURN -C - END - -C+++++++++++++++++++++++++ -C - SUBROUTINE SPLIT(TT,FR) -C -C+++++++++++++++++++++++++ -C -C THIS SUBROUTINE BREAKS A D.P. NUMBER INTO A D.P. INTEGER -C AND A D.P. FRACTIONAL PART. -C -C CALLING SEQUENCE PARAMETERS: -C -C TT = D.P. INPUT NUMBER -C -C FR = D.P. 2-WORD OUTPUT ARRAY. -C FR(1) CONTAINS INTEGER PART -C FR(2) CONTAINS FRACTIONAL PART -C -C FOR NEGATIVE INPUT NUMBERS, FR(1) CONTAINS THE NEXT -C MORE NEGATIVE INTEGER; FR(2) CONTAINS A POSITIVE FRACTION. -C -C CALLING SEQUENCE DECLARATIONS -C - IMPLICIT DOUBLE PRECISION (A-H,O-Z) - - DIMENSION FR(2) - -C MAIN ENTRY -- GET INTEGER AND FRACTIONAL PARTS - - FR(1)=DINT(TT) - FR(2)=TT-FR(1) - - IF(TT.GE.0.D0 .OR. FR(2).EQ.0.D0) RETURN - -C MAKE ADJUSTMENTS FOR NEGATIVE INPUT NUMBER - - FR(1)=FR(1)-1.D0 - FR(2)=FR(2)+1.D0 - - RETURN - - END - - -C++++++++++++++++++++++++++++++++ -C - SUBROUTINE STATE(ET2,LIST,PV,PNUT) -C -C++++++++++++++++++++++++++++++++ -C -C THIS SUBROUTINE READS AND INTERPOLATES THE JPL PLANETARY EPHEMERIS FILE -C -C CALLING SEQUENCE PARAMETERS: -C -C INPUT: -C -C ET2 DP 2-WORD JULIAN EPHEMERIS EPOCH AT WHICH INTERPOLATION -C IS WANTED. ANY COMBINATION OF ET2(1)+ET2(2) WHICH FALLS -C WITHIN THE TIME SPAN ON THE FILE IS A PERMISSIBLE EPOCH. -C -C A. FOR EASE IN PROGRAMMING, THE USER MAY PUT THE -C ENTIRE EPOCH IN ET2(1) AND SET ET2(2)=0. -C -C B. FOR MAXIMUM INTERPOLATION ACCURACY, SET ET2(1) = -C THE MOST RECENT MIDNIGHT AT OR BEFORE INTERPOLATION -C EPOCH AND SET ET2(2) = FRACTIONAL PART OF A DAY -C ELAPSED BETWEEN ET2(1) AND EPOCH. -C -C C. AS AN ALTERNATIVE, IT MAY PROVE CONVENIENT TO SET -C ET2(1) = SOME FIXED EPOCH, SUCH AS START OF INTEGRATION, -C AND ET2(2) = ELAPSED INTERVAL BETWEEN THEN AND EPOCH. -C -C LIST 12-WORD INTEGER ARRAY SPECIFYING WHAT INTERPOLATION -C IS WANTED FOR EACH OF THE BODIES ON THE FILE. -C -C LIST(I)=0, NO INTERPOLATION FOR BODY I -C =1, POSITION ONLY -C =2, POSITION AND VELOCITY -C -C THE DESIGNATION OF THE ASTRONOMICAL BODIES BY I IS: -C -C I = 1: MERCURY -C = 2: VENUS -C = 3: EARTH-MOON BARYCENTER -C = 4: MARS -C = 5: JUPITER -C = 6: SATURN -C = 7: URANUS -C = 8: NEPTUNE -C = 9: PLUTO -C =10: GEOCENTRIC MOON -C =11: NUTATIONS IN LONGITUDE AND OBLIQUITY -C =12: LUNAR LIBRATIONS (IF ON FILE) -C -C OUTPUT: -C -C PV DP 6 X 11 ARRAY THAT WILL CONTAIN REQUESTED INTERPOLATED -C QUANTITIES (OTHER THAN NUTATION, STOERD IN PNUT). -C THE BODY SPECIFIED BY LIST(I) WILL HAVE ITS -C STATE IN THE ARRAY STARTING AT PV(1,I). -C (ON ANY GIVEN CALL, ONLY THOSE WORDS IN 'PV' WHICH ARE -C AFFECTED BY THE FIRST 10 'LIST' ENTRIES, AND BY LIST(12) -C IF LIBRATIONS ARE ON THE FILE, ARE SET. -C THE REST OF THE 'PV' ARRAYIS UNTOUCHED.) -C THE ORDER OF COMPONENTS STARTING IN PV(1,I) IS: X,Y,Z,DX,DY,DZ. -C -C ALL OUTPUT VECTORS ARE REFERENCED TO THE EARTH MEAN -C EQUATOR AND EQUINOX OF J2000 IF THE DE NUMBER IS 200 OR -C GREATER; OF B1950 IF THE DE NUMBER IS LESS THAN 200. -C -C THE MOON STATE IS ALWAYS GEOCENTRIC; THE OTHER NINE STATES -C ARE EITHER HELIOCENTRIC OR SOLAR-SYSTEM BARYCENTRIC, -C DEPENDING ON THE SETTING OF COMMON FLAGS (SEE BELOW). -C -C LUNAR LIBRATIONS, IF ON FILE, ARE PUT INTO PV(K,11) IF -C LIST(12) IS 1 OR 2. -C -C NUT DP 4-WORD ARRAY THAT WILL CONTAIN NUTATIONS AND RATES, -C DEPENDING ON THE SETTING OF LIST(11). THE ORDER OF -C QUANTITIES IN NUT IS: -C -C D PSI (NUTATION IN LONGITUDE) -C D EPSILON (NUTATION IN OBLIQUITY) -C D PSI DOT -C D EPSILON DOT -C -C * STATEMENT # FOR ERROR RETURN, IN CASE OF EPOCH OUT OF -C RANGE OR I/O ERRORS. -C -C COMMON AREA STCOMX: -C -C KM LOGICAL FLAG DEFINING PHYSICAL UNITS OF THE OUTPUT -C STATES. KM = .TRUE., KM AND KM/SEC -C = .FALSE., AU AND AU/DAY -C DEFAULT VALUE = .FALSE. (KM DETERMINES TIME UNIT -C FOR NUTATIONS AND LIBRATIONS. ANGLE UNIT IS ALWAYS RADIANS.) -C -C BARY LOGICAL FLAG DEFINING OUTPUT CENTER. -C ONLY THE 9 PLANETS ARE AFFECTED. -C BARY = .TRUE. =\ CENTER IS SOLAR-SYSTEM BARYCENTER -C = .FALSE. =\ CENTER IS SUN -C DEFAULT VALUE = .FALSE. -C -C PVSUN DP 6-WORD ARRAY CONTAINING THE BARYCENTRIC POSITION AND -C VELOCITY OF THE SUN. -C -C - IMPLICIT DOUBLE PRECISION (A-H,O-Z) - - SAVE - - INTEGER OLDMAX - PARAMETER ( OLDMAX = 400) - INTEGER NMAX - PARAMETER ( NMAX = 1000) - - DIMENSION ET2(2),PV(6,11),PNUT(4),T(2),PJD(4),BUF(1500), - . SS(3),CVAL(NMAX),PVSUN(6) - - INTEGER LIST(12),IPT(3,13) - - LOGICAL FIRST - DATA FIRST/.TRUE./ - - CHARACTER*6 TTL(14,3),CNAM(NMAX) - CHARACTER*256 NAMFIL - - LOGICAL KM,BARY - - COMMON/EPHHDR/CVAL,SS,AU,EMRAT,NUMDE,NCON,IPT - COMMON/CHRHDR/CNAM,TTL - COMMON/STCOMX/KM,BARY,PVSUN - -C -C ENTRY POINT - 1ST TIME IN, GET POINTER DATA, ETC., FROM EPH FILE -C - IF(FIRST) THEN - FIRST=.FALSE. - -C ************************************************************************ -C ************************************************************************ - -C THE USER MUST SELECT ONE OF THE FOLLOWING BY DELETING THE 'C' IN COLUMN 1 - -C ************************************************************************ - -C CALL FSIZER1(NRECL,KSIZE,NRFILE,NAMFIL) -C CALL FSIZER2(NRECL,KSIZE,NRFILE,NAMFIL) - CALL FSIZER3(NRECL,KSIZE,NRFILE,NAMFIL) - - IF(NRECL .EQ. 0) WRITE(*,*)' ***** FSIZER IS NOT WORKING *****' - -C ************************************************************************ -C ************************************************************************ - - IRECSZ=NRECL*KSIZE - NCOEFFS=KSIZE/2 - - OPEN(NRFILE, - * FILE=NAMFIL, - * ACCESS='DIRECT', - * FORM='UNFORMATTED', - * RECL=IRECSZ, - * STATUS='OLD') - - READ(NRFILE,REC=1)TTL,(CNAM(K),K=1,OLDMAX),SS,NCON,AU,EMRAT, - & ((IPT(I,J),I=1,3),J=1,12),NUMDE,(IPT(I,13),I=1,3) - & ,(CNAM(L),L=OLDMAX+1,NCON) - - IF(NCON .LE. OLDMAX)THEN - READ(NRFILE,REC=2)(CVAL(I),I=1,OLDMAX) - ELSE - READ(NRFILE,REC=2)(CVAL(I),I=1,NCON) - ENDIF - - NRL=0 - - ENDIF - -C ********** MAIN ENTRY POINT ********** - - IF(ET2(1) .EQ. 0.D0) RETURN - - S=ET2(1)-.5D0 - CALL SPLIT(S,PJD(1)) - CALL SPLIT(ET2(2),PJD(3)) - PJD(1)=PJD(1)+PJD(3)+.5D0 - PJD(2)=PJD(2)+PJD(4) - CALL SPLIT(PJD(2),PJD(3)) - PJD(1)=PJD(1)+PJD(3) - -C ERROR RETURN FOR EPOCH OUT OF RANGE - - IF(PJD(1)+PJD(4).LT.SS(1) .OR. PJD(1)+PJD(4).GT.SS(2)) GO TO 98 - -C CALCULATE RECORD # AND RELATIVE TIME IN INTERVAL - - NR=IDINT((PJD(1)-SS(1))/SS(3))+3 - IF(PJD(1).EQ.SS(2)) NR=NR-1 - - tmp1 = DBLE(NR-3)*SS(3) + SS(1) - tmp2 = PJD(1) - tmp1 - T(1) = (tmp2 + PJD(4))/SS(3) - -C READ CORRECT RECORD IF NOT IN CORE - - IF(NR.NE.NRL) THEN - NRL=NR - READ(NRFILE,REC=NR,ERR=99)(BUF(K),K=1,NCOEFFS) - ENDIF - - IF(KM) THEN - T(2)=SS(3)*86400.D0 - AUFAC=1.D0 - ELSE - T(2)=SS(3) - AUFAC=1.D0/AU - ENDIF - -C INTERPOLATE SSBARY SUN - - CALL INTERP(BUF(IPT(1,11)),T,IPT(2,11),3,IPT(3,11),2,PVSUN) - - DO I=1,6 - PVSUN(I)=PVSUN(I)*AUFAC - ENDDO - -C CHECK AND INTERPOLATE WHICHEVER BODIES ARE REQUESTED - - DO 4 I=1,10 - IF(LIST(I).EQ.0) GO TO 4 - - CALL INTERP(BUF(IPT(1,I)),T,IPT(2,I),3,IPT(3,I), - & LIST(I),PV(1,I)) - - DO J=1,6 - IF(I.LE.9 .AND. .NOT.BARY) THEN - PV(J,I)=PV(J,I)*AUFAC-PVSUN(J) - ELSE - PV(J,I)=PV(J,I)*AUFAC - ENDIF - ENDDO - - 4 CONTINUE - -C DO NUTATIONS IF REQUESTED (AND IF ON FILE) - - IF(LIST(11).GT.0 .AND. IPT(2,12).GT.0) - * CALL INTERP(BUF(IPT(1,12)),T,IPT(2,12),2,IPT(3,12), - * LIST(11),PNUT) - -C GET LIBRATIONS IF REQUESTED (AND IF ON FILE) - - IF(LIST(12).GT.0 .AND. IPT(2,13).GT.0) - * CALL INTERP(BUF(IPT(1,13)),T,IPT(2,13),3,IPT(3,13), - * LIST(12),PV(1,11)) - - RETURN - - 98 WRITE(*,198)ET2(1)+ET2(2),SS(1),SS(2) - 198 FORMAT(' *** Requested JED,',f12.2, - * ' not within ephemeris limits,',2f12.2,' ***') - - STOP - - 99 WRITE(*,'(2F12.2,A80)')ET2,'ERROR RETURN IN STATE' - - STOP - - END -C+++++++++++++++++++++++++++++ -C - SUBROUTINE CONST(NAM,VAL,SSS,N) -C -C+++++++++++++++++++++++++++++ -C -C THIS ENTRY OBTAINS THE CONSTANTS FROM THE EPHEMERIS FILE -C -C CALLING SEQEUNCE PARAMETERS (ALL OUTPUT): -C -C NAM = CHARACTER*6 ARRAY OF CONSTANT NAMES -C -C VAL = D.P. ARRAY OF VALUES OF CONSTANTS -C -C SSS = D.P. JD START, JD STOP, STEP OF EPHEMERIS -C -C N = INTEGER NUMBER OF ENTRIES IN 'NAM' AND 'VAL' ARRAYS -C - IMPLICIT DOUBLE PRECISION (A-H,O-Z) - - SAVE - - INTEGER NMAX - PARAMETER (NMAX = 1000) - - CHARACTER*6 NAM(*),TTL(14,3),CNAM(NMAX) - - DOUBLE PRECISION VAL(*),SSS(3),SS(3),CVAL(NMAX),ZIPS(2) - DOUBLE PRECISION PVST(6,11),PNUT(4) - DATA ZIPS/2*0.d0/ - - INTEGER IPT(3,13),DENUM,LIST(12) - logical first - data first/.true./ - - COMMON/EPHHDR/CVAL,SS,AU,EMRAT,DENUM,NCON,IPT - COMMON/CHRHDR/CNAM,TTL - -C CALL STATE TO INITIALIZE THE EPHEMERIS AND READ IN THE CONSTANTS - - IF(FIRST) CALL STATE(ZIPS,LIST,PVST,PNUT) - first=.false. - - N=NCON - - DO I=1,3 - SSS(I)=SS(I) - ENDDO - - DO I=1,N - NAM(I)=CNAM(I) - VAL(I)=CVAL(I) - ENDDO - - RETURN - - END +C++++++++++++++++++++++++ +C + SUBROUTINE FSIZER1(NRECL,KSIZE,NRFILE,NAMFIL) +C +C++++++++++++++++++++++++ +C +C Version 1.0 uses the INQUIRE statement to find out the the record length +C of the direct access file before opening it. This procedure is non-standard, +C but seems to work for VAX machines. +C +C THE SUBROUTINE ALSO SETS THE VALUES OF NRECL, NRFILE, AND NAMFIL. + +C ***************************************************************** +C ***************************************************************** +C +C THE PARAMETERS NAMFIL, NRECL, AND NRFILE ARE TO BE SET BY THE USER +C +C ***************************************************************** + +C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE + + CHARACTER*256 NAMFIL + +c NAMFIL='JPLEPH' + +C ***************************************************************** + +C NRECL=1 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN S.P. WORDS +C NRECL=4 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN BYTES +C (for a VAX, it is probably 1) +C + NRECL=4 + +C ***************************************************************** + +C NRFILE IS THE INTERNAL UNIT NUMBER USED FOR THE EPHEMERIS FILE + +c NRFILE=12 + +C ***************************************************************** + +C FIND THE RECORD SIZE USING THE INQUIRE STATEMENT + + +c IRECSZ=0 + + INQUIRE(FILE=NAMFIL,RECL=IRECSZ) + +C IF 'INQUIRE' DOES NOT WORK, USUALLY IRECSZ WILL BE LEFT AT 0 + + IF(IRECSZ .LE. 0) write(*,*) + . ' INQUIRE STATEMENT PROBABLY DID NOT WORK' + + KSIZE=IRECSZ/NRECL + if(nrfile.eq.-99) stop !silence compiler warning + + RETURN + + END +C++++++++++++++++++++++++ +C + SUBROUTINE FSIZER2(NRECL,KSIZE,NRFILE,NAMFIL) +C +C++++++++++++++++++++++++ +C THIS SUBROUTINE OPENS THE FILE, 'NAMFIL', WITH A PHONY RECORD LENGTH, READS +C THE FIRST RECORD, AND USES THE INFO TO COMPUTE KSIZE, THE NUMBER OF SINGLE +C PRECISION WORDS IN A RECORD. +C +C THE SUBROUTINE ALSO SETS THE VALUES OF NRECL, NRFILE, AND NAMFIL. + + IMPLICIT DOUBLE PRECISION(A-H,O-Z) + + SAVE + + INTEGER OLDMAX + PARAMETER (OLDMAX = 400) + INTEGER NMAX + PARAMETER (NMAX = 1000) + CHARACTER*6 TTL(14,3),CNAM(NMAX) + CHARACTER*256 NAMFIL,jpleph_file_name + DIMENSION SS(3) + INTEGER IPT(3,13) + common/jplcom/jpleph_file_name + +C ***************************************************************** +C ***************************************************************** +C +C THE PARAMETERS NRECL, NRFILE, AND NAMFIL ARE TO BE SET BY THE USER +C +C ***************************************************************** + +C NRECL=1 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN S.P. WORDS +C NRECL=4 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN BYTES +C (for UNIX, it is probably 4) +C + NRECL=4 + +C NRFILE IS THE INTERNAL UNIT NUMBER USED FOR THE EPHEMERIS FILE + + NRFILE=12 + +C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE + +! NAMFIL='JPLEPH' + NAMFIL=jpleph_file_name + +C ***************************************************************** +C ***************************************************************** + +C ** OPEN THE DIRECT-ACCESS FILE AND GET THE POINTERS IN ORDER TO +C ** DETERMINE THE SIZE OF THE EPHEMERIS RECORD + + MRECL=NRECL*1000 + + OPEN(NRFILE, + * FILE=NAMFIL, + * ACCESS='DIRECT', + * FORM='UNFORMATTED', + * RECL=MRECL, + * STATUS='OLD') + + READ(NRFILE,REC=1)TTL,(CNAM(K),K=1,OLDMAX),SS,NCON,AU,EMRAT, + & ((IPT(I,J),I=1,3),J=1,12),NUMDE,(IPT(I,13),I=1,3) + + CLOSE(NRFILE) + +C FIND THE NUMBER OF EPHEMERIS COEFFICIENTS FROM THE POINTERS + + KMX = 0 + KHI = 0 + + DO I = 1,13 + IF (IPT(1,I) .GT. KMX) THEN + KMX = IPT(1,I) + KHI = I + ENDIF + ENDDO + + ND = 3 + IF (KHI .EQ. 12) ND=2 + + KSIZE = 2*(IPT(1,KHI)+ND*IPT(2,KHI)*IPT(3,KHI)-1) + + RETURN + + END +C++++++++++++++++++++++++ +C + SUBROUTINE FSIZER3(NRECL,KSIZE,NRFILE,NAMFIL) +C +C++++++++++++++++++++++++ +C +C THE SUBROUTINE SETS THE VALUES OF NRECL, KSIZE, NRFILE, AND NAMFIL. + + SAVE + CHARACTER*256 NAMFIL,jpleph_file_name + common/jplcom/jpleph_file_name + +C ***************************************************************** +C ***************************************************************** +C +C THE PARAMETERS NRECL, NRFILE, AND NAMFIL ARE TO BE SET BY THE USER + +C ***************************************************************** + +C NRECL=1 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN S.P. WORDS +C NRECL=4 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN BYTES + + NRECL=4 + +C ***************************************************************** + +C NRFILE IS THE INTERNAL UNIT NUMBER USED FOR THE EPHEMERIS FILE (DEFAULT: 12) + + NRFILE=12 + +C ***************************************************************** + +C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE + +! NAMFIL='JPLEPH' + NAMFIL=jpleph_file_name + +C ***************************************************************** + +C KSIZE must be set by the user according to the ephemeris to be read + +C For de200, set KSIZE to 1652 +C For de405, set KSIZE to 2036 +C For de406, set KSIZE to 1456 +C For de414, set KSIZE to 2036 +C For de418, set KSIZE to 2036 +C For de421, set KSIZE to 2036 +C For de422, set KSIZE to 2036 +C For de423, set KSIZE to 2036 +C For de424, set KSIZE to 2036 +C For de430, set KSIZE to 2036 + + KSIZE = 2036 + +C ******************************************************************* + + RETURN + + END +C++++++++++++++++++++++++++ +C + SUBROUTINE PLEPH ( ET, NTARG, NCENT, RRD ) +C +C++++++++++++++++++++++++++ +C NOTE : Over the years, different versions of PLEPH have had a fifth argument: +C sometimes, an error return statement number; sometimes, a logical denoting +C whether or not the requested date is covered by the ephemeris. We apologize +C for this inconsistency; in this present version, we use only the four necessary +C arguments and do the testing outside of the subroutine. +C +C THIS SUBROUTINE READS THE JPL PLANETARY EPHEMERIS +C AND GIVES THE POSITION AND VELOCITY OF THE POINT 'NTARG' +C WITH RESPECT TO 'NCENT'. +C +C CALLING SEQUENCE PARAMETERS: +C +C ET = D.P. JULIAN EPHEMERIS DATE AT WHICH INTERPOLATION +C IS WANTED. +C +C ** NOTE THE ENTRY DPLEPH FOR A DOUBLY-DIMENSIONED TIME ** +C THE REASON FOR THIS OPTION IS DISCUSSED IN THE +C SUBROUTINE STATE +C +C NTARG = INTEGER NUMBER OF 'TARGET' POINT. +C +C NCENT = INTEGER NUMBER OF CENTER POINT. +C +C THE NUMBERING CONVENTION FOR 'NTARG' AND 'NCENT' IS: +C +C 1 = MERCURY 8 = NEPTUNE +C 2 = VENUS 9 = PLUTO +C 3 = EARTH 10 = MOON +C 4 = MARS 11 = SUN +C 5 = JUPITER 12 = SOLAR-SYSTEM BARYCENTER +C 6 = SATURN 13 = EARTH-MOON BARYCENTER +C 7 = URANUS 14 = NUTATIONS (LONGITUDE AND OBLIQ) +C 15 = LIBRATIONS, IF ON EPH FILE +C +C (IF NUTATIONS ARE WANTED, SET NTARG = 14. FOR LIBRATIONS, +C SET NTARG = 15. SET NCENT=0.) +C +C RRD = OUTPUT 6-WORD D.P. ARRAY CONTAINING POSITION AND VELOCITY +C OF POINT 'NTARG' RELATIVE TO 'NCENT'. THE UNITS ARE AU AND +C AU/DAY. FOR LIBRATIONS THE UNITS ARE RADIANS AND RADIANS +C PER DAY. IN THE CASE OF NUTATIONS THE FIRST FOUR WORDS OF +C RRD WILL BE SET TO NUTATIONS AND RATES, HAVING UNITS OF +C RADIANS AND RADIANS/DAY. +C +C The option is available to have the units in km and km/sec. +C For this, set km=.true. in the STCOMX common block. +C + + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + + INTEGER NMAX + PARAMETER (NMAX = 1000) + + DIMENSION RRD(6),ET2Z(2),ET2(2),PV(6,13) + DIMENSION PVST(6,11),PNUT(4) + DIMENSION SS(3),CVAL(NMAX),PVSUN(6),ZIPS(2) + DATA ZIPS/2*0.d0/ + + LOGICAL BSAVE,KM,BARY + LOGICAL FIRST + DATA FIRST/.TRUE./ + + INTEGER LIST(12),IPT(39),DENUM + COMMON/EPHHDR/CVAL,SS,AU,EMRAT,DENUM,NCON,IPT + COMMON/STCOMX/KM,BARY,PVSUN + +C INITIALIZE ET2 FOR 'STATE' AND SET UP COMPONENT COUNT +C + ET2(1)=ET + ET2(2)=0.D0 + GO TO 11 + +C ENTRY POINT 'DPLEPH' FOR DOUBLY-DIMENSIONED TIME ARGUMENT +C (SEE THE DISCUSSION IN THE SUBROUTINE STATE) + + ENTRY DPLEPH(ET2Z,NTARG,NCENT,RRD) + + ET2(1)=ET2Z(1) + ET2(2)=ET2Z(2) + + 11 IF(FIRST) CALL STATE(ZIPS,LIST,PVST,PNUT) + FIRST=.FALSE. + + IF(NTARG .EQ. NCENT) RETURN + + DO I=1,12 + LIST(I)=0 + ENDDO + +C CHECK FOR NUTATION CALL + + IF(NTARG.NE.14) GO TO 97 + IF(IPT(35).GT.0) THEN + LIST(11)=2 + CALL STATE(ET2,LIST,PVST,PNUT) + DO I=1,4 + RRD(I)=PNUT(I) + ENDDO + RRD(5) = 0.d0 + RRD(6) = 0.d0 + RETURN + ELSE + DO I=1,4 + RRD(I)=0.d0 + ENDDO + WRITE(6,297) + 297 FORMAT(' ***** NO NUTATIONS ON THE EPHEMERIS FILE *****') + STOP + ENDIF + +C CHECK FOR LIBRATIONS + + 97 CONTINUE + DO I=1,6 + RRD(I)=0.d0 + ENDDO + + IF(NTARG.NE.15) GO TO 98 + IF(IPT(38).GT.0) THEN + LIST(12)=2 + CALL STATE(ET2,LIST,PVST,PNUT) + DO I=1,6 + RRD(I)=PVST(I,11) + ENDDO + RETURN + ELSE + WRITE(6,298) + 298 FORMAT(' ***** NO LIBRATIONS ON THE EPHEMERIS FILE *****') + STOP + ENDIF + +C FORCE BARYCENTRIC OUTPUT BY 'STATE' + + 98 BSAVE=BARY + BARY=.TRUE. + +C SET UP PROPER ENTRIES IN 'LIST' ARRAY FOR STATE CALL + + DO I=1,2 + K=NTARG + IF(I .EQ. 2) K=NCENT + IF(K .LE. 10) LIST(K)=2 + IF(K .EQ. 10) LIST(3)=2 + IF(K .EQ. 3) LIST(10)=2 + IF(K .EQ. 13) LIST(3)=2 + ENDDO + +C MAKE CALL TO STATE + + CALL STATE(ET2,LIST,PVST,PNUT) + + DO I=1,10 + DO J = 1,6 + PV(J,I) = PVST(J,I) + ENDDO + ENDDO + + IF(NTARG .EQ. 11 .OR. NCENT .EQ. 11) THEN + DO I=1,6 + PV(I,11)=PVSUN(I) + ENDDO + ENDIF + + IF(NTARG .EQ. 12 .OR. NCENT .EQ. 12) THEN + DO I=1,6 + PV(I,12)=0.D0 + ENDDO + ENDIF + + IF(NTARG .EQ. 13 .OR. NCENT .EQ. 13) THEN + DO I=1,6 + PV(I,13) = PVST(I,3) + ENDDO + ENDIF + + IF(NTARG*NCENT .EQ. 30 .AND. NTARG+NCENT .EQ. 13) THEN + DO I=1,6 + PV(I,3)=0.D0 + ENDDO + GO TO 99 + ENDIF + + IF(LIST(3) .EQ. 2) THEN + DO I=1,6 + PV(I,3)=PVST(I,3)-PVST(I,10)/(1.D0+EMRAT) + ENDDO + ENDIF + + IF(LIST(10) .EQ. 2) THEN + DO I=1,6 + PV(I,10) = PV(I,3)+PVST(I,10) + ENDDO + ENDIF + + 99 DO I=1,6 + RRD(I)=PV(I,NTARG)-PV(I,NCENT) + ENDDO + + BARY=BSAVE + + RETURN + END +C+++++++++++++++++++++++++++++++++ +C + SUBROUTINE INTERP(BUF,T,NCF,NCM,NA,IFL,PV) +C +C+++++++++++++++++++++++++++++++++ +C +C THIS SUBROUTINE DIFFERENTIATES AND INTERPOLATES A +C SET OF CHEBYSHEV COEFFICIENTS TO GIVE POSITION AND VELOCITY +C +C CALLING SEQUENCE PARAMETERS: +C +C INPUT: +C +C BUF 1ST LOCATION OF ARRAY OF D.P. CHEBYSHEV COEFFICIENTS OF POSITION +C +C T T(1) IS DP FRACTIONAL TIME IN INTERVAL COVERED BY +C COEFFICIENTS AT WHICH INTERPOLATION IS WANTED +C (0 .LE. T(1) .LE. 1). T(2) IS DP LENGTH OF WHOLE +C INTERVAL IN INPUT TIME UNITS. +C +C NCF # OF COEFFICIENTS PER COMPONENT +C +C NCM # OF COMPONENTS PER SET OF COEFFICIENTS +C +C NA # OF SETS OF COEFFICIENTS IN FULL ARRAY +C (I.E., # OF SUB-INTERVALS IN FULL INTERVAL) +C +C IFL INTEGER FLAG: =1 FOR POSITIONS ONLY +C =2 FOR POS AND VEL +C +C +C OUTPUT: +C +C PV INTERPOLATED QUANTITIES REQUESTED. DIMENSION +C EXPECTED IS PV(NCM,IFL), DP. +C +C + IMPLICIT DOUBLE PRECISION (A-H,O-Z) +C + SAVE +C + DOUBLE PRECISION BUF(NCF,NCM,*),T(2),PV(NCM,*),PC(18),VC(18) + +C + DATA NP/2/ + DATA NV/3/ + DATA TWOT/0.D0/ + DATA PC(1),PC(2)/1.D0,0.D0/ + DATA VC(2)/1.D0/ +C +C ENTRY POINT. GET CORRECT SUB-INTERVAL NUMBER FOR THIS SET +C OF COEFFICIENTS AND THEN GET NORMALIZED CHEBYSHEV TIME +C WITHIN THAT SUBINTERVAL. +C + DNA=DBLE(NA) + DT1=DINT(T(1)) + TEMP=DNA*T(1) + L=IDINT(TEMP-DT1)+1 + +C TC IS THE NORMALIZED CHEBYSHEV TIME (-1 .LE. TC .LE. 1) + + TC=2.D0*(DMOD(TEMP,1.D0)+DT1)-1.D0 + +C CHECK TO SEE WHETHER CHEBYSHEV TIME HAS CHANGED, +C AND COMPUTE NEW POLYNOMIAL VALUES IF IT HAS. +C (THE ELEMENT PC(2) IS THE VALUE OF T1(TC) AND HENCE +C CONTAINS THE VALUE OF TC ON THE PREVIOUS CALL.) + + IF(TC.NE.PC(2)) THEN + NP=2 + NV=3 + PC(2)=TC + TWOT=TC+TC + ENDIF +C +C BE SURE THAT AT LEAST 'NCF' POLYNOMIALS HAVE BEEN EVALUATED +C AND ARE STORED IN THE ARRAY 'PC'. +C + IF(NP.LT.NCF) THEN + DO 1 I=NP+1,NCF + PC(I)=TWOT*PC(I-1)-PC(I-2) + 1 CONTINUE + NP=NCF + ENDIF +C +C INTERPOLATE TO GET POSITION FOR EACH COMPONENT +C + DO 2 I=1,NCM + PV(I,1)=0.D0 + DO 3 J=NCF,1,-1 + PV(I,1)=PV(I,1)+PC(J)*BUF(J,I,L) + 3 CONTINUE + 2 CONTINUE + IF(IFL.LE.1) RETURN +C +C IF VELOCITY INTERPOLATION IS WANTED, BE SURE ENOUGH +C DERIVATIVE POLYNOMIALS HAVE BEEN GENERATED AND STORED. +C + VFAC=(DNA+DNA)/T(2) + VC(3)=TWOT+TWOT + IF(NV.LT.NCF) THEN + DO 4 I=NV+1,NCF + VC(I)=TWOT*VC(I-1)+PC(I-1)+PC(I-1)-VC(I-2) + 4 CONTINUE + NV=NCF + ENDIF +C +C INTERPOLATE TO GET VELOCITY FOR EACH COMPONENT +C + DO 5 I=1,NCM + PV(I,2)=0.D0 + DO 6 J=NCF,2,-1 + PV(I,2)=PV(I,2)+VC(J)*BUF(J,I,L) + 6 CONTINUE + PV(I,2)=PV(I,2)*VFAC + 5 CONTINUE +C + RETURN +C + END + +C+++++++++++++++++++++++++ +C + SUBROUTINE SPLIT(TT,FR) +C +C+++++++++++++++++++++++++ +C +C THIS SUBROUTINE BREAKS A D.P. NUMBER INTO A D.P. INTEGER +C AND A D.P. FRACTIONAL PART. +C +C CALLING SEQUENCE PARAMETERS: +C +C TT = D.P. INPUT NUMBER +C +C FR = D.P. 2-WORD OUTPUT ARRAY. +C FR(1) CONTAINS INTEGER PART +C FR(2) CONTAINS FRACTIONAL PART +C +C FOR NEGATIVE INPUT NUMBERS, FR(1) CONTAINS THE NEXT +C MORE NEGATIVE INTEGER; FR(2) CONTAINS A POSITIVE FRACTION. +C +C CALLING SEQUENCE DECLARATIONS +C + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + + DIMENSION FR(2) + +C MAIN ENTRY -- GET INTEGER AND FRACTIONAL PARTS + + FR(1)=DINT(TT) + FR(2)=TT-FR(1) + + IF(TT.GE.0.D0 .OR. FR(2).EQ.0.D0) RETURN + +C MAKE ADJUSTMENTS FOR NEGATIVE INPUT NUMBER + + FR(1)=FR(1)-1.D0 + FR(2)=FR(2)+1.D0 + + RETURN + + END + + +C++++++++++++++++++++++++++++++++ +C + SUBROUTINE STATE(ET2,LIST,PV,PNUT) +C +C++++++++++++++++++++++++++++++++ +C +C THIS SUBROUTINE READS AND INTERPOLATES THE JPL PLANETARY EPHEMERIS FILE +C +C CALLING SEQUENCE PARAMETERS: +C +C INPUT: +C +C ET2 DP 2-WORD JULIAN EPHEMERIS EPOCH AT WHICH INTERPOLATION +C IS WANTED. ANY COMBINATION OF ET2(1)+ET2(2) WHICH FALLS +C WITHIN THE TIME SPAN ON THE FILE IS A PERMISSIBLE EPOCH. +C +C A. FOR EASE IN PROGRAMMING, THE USER MAY PUT THE +C ENTIRE EPOCH IN ET2(1) AND SET ET2(2)=0. +C +C B. FOR MAXIMUM INTERPOLATION ACCURACY, SET ET2(1) = +C THE MOST RECENT MIDNIGHT AT OR BEFORE INTERPOLATION +C EPOCH AND SET ET2(2) = FRACTIONAL PART OF A DAY +C ELAPSED BETWEEN ET2(1) AND EPOCH. +C +C C. AS AN ALTERNATIVE, IT MAY PROVE CONVENIENT TO SET +C ET2(1) = SOME FIXED EPOCH, SUCH AS START OF INTEGRATION, +C AND ET2(2) = ELAPSED INTERVAL BETWEEN THEN AND EPOCH. +C +C LIST 12-WORD INTEGER ARRAY SPECIFYING WHAT INTERPOLATION +C IS WANTED FOR EACH OF THE BODIES ON THE FILE. +C +C LIST(I)=0, NO INTERPOLATION FOR BODY I +C =1, POSITION ONLY +C =2, POSITION AND VELOCITY +C +C THE DESIGNATION OF THE ASTRONOMICAL BODIES BY I IS: +C +C I = 1: MERCURY +C = 2: VENUS +C = 3: EARTH-MOON BARYCENTER +C = 4: MARS +C = 5: JUPITER +C = 6: SATURN +C = 7: URANUS +C = 8: NEPTUNE +C = 9: PLUTO +C =10: GEOCENTRIC MOON +C =11: NUTATIONS IN LONGITUDE AND OBLIQUITY +C =12: LUNAR LIBRATIONS (IF ON FILE) +C +C OUTPUT: +C +C PV DP 6 X 11 ARRAY THAT WILL CONTAIN REQUESTED INTERPOLATED +C QUANTITIES (OTHER THAN NUTATION, STOERD IN PNUT). +C THE BODY SPECIFIED BY LIST(I) WILL HAVE ITS +C STATE IN THE ARRAY STARTING AT PV(1,I). +C (ON ANY GIVEN CALL, ONLY THOSE WORDS IN 'PV' WHICH ARE +C AFFECTED BY THE FIRST 10 'LIST' ENTRIES, AND BY LIST(12) +C IF LIBRATIONS ARE ON THE FILE, ARE SET. +C THE REST OF THE 'PV' ARRAYIS UNTOUCHED.) +C THE ORDER OF COMPONENTS STARTING IN PV(1,I) IS: X,Y,Z,DX,DY,DZ. +C +C ALL OUTPUT VECTORS ARE REFERENCED TO THE EARTH MEAN +C EQUATOR AND EQUINOX OF J2000 IF THE DE NUMBER IS 200 OR +C GREATER; OF B1950 IF THE DE NUMBER IS LESS THAN 200. +C +C THE MOON STATE IS ALWAYS GEOCENTRIC; THE OTHER NINE STATES +C ARE EITHER HELIOCENTRIC OR SOLAR-SYSTEM BARYCENTRIC, +C DEPENDING ON THE SETTING OF COMMON FLAGS (SEE BELOW). +C +C LUNAR LIBRATIONS, IF ON FILE, ARE PUT INTO PV(K,11) IF +C LIST(12) IS 1 OR 2. +C +C NUT DP 4-WORD ARRAY THAT WILL CONTAIN NUTATIONS AND RATES, +C DEPENDING ON THE SETTING OF LIST(11). THE ORDER OF +C QUANTITIES IN NUT IS: +C +C D PSI (NUTATION IN LONGITUDE) +C D EPSILON (NUTATION IN OBLIQUITY) +C D PSI DOT +C D EPSILON DOT +C +C * STATEMENT # FOR ERROR RETURN, IN CASE OF EPOCH OUT OF +C RANGE OR I/O ERRORS. +C +C COMMON AREA STCOMX: +C +C KM LOGICAL FLAG DEFINING PHYSICAL UNITS OF THE OUTPUT +C STATES. KM = .TRUE., KM AND KM/SEC +C = .FALSE., AU AND AU/DAY +C DEFAULT VALUE = .FALSE. (KM DETERMINES TIME UNIT +C FOR NUTATIONS AND LIBRATIONS. ANGLE UNIT IS ALWAYS RADIANS.) +C +C BARY LOGICAL FLAG DEFINING OUTPUT CENTER. +C ONLY THE 9 PLANETS ARE AFFECTED. +C BARY = .TRUE. =\ CENTER IS SOLAR-SYSTEM BARYCENTER +C = .FALSE. =\ CENTER IS SUN +C DEFAULT VALUE = .FALSE. +C +C PVSUN DP 6-WORD ARRAY CONTAINING THE BARYCENTRIC POSITION AND +C VELOCITY OF THE SUN. +C +C + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + + SAVE + + INTEGER OLDMAX + PARAMETER ( OLDMAX = 400) + INTEGER NMAX + PARAMETER ( NMAX = 1000) + + DIMENSION ET2(2),PV(6,11),PNUT(4),T(2),PJD(4),BUF(1500), + . SS(3),CVAL(NMAX),PVSUN(6) + + INTEGER LIST(12),IPT(3,13) + + LOGICAL FIRST + DATA FIRST/.TRUE./ + + CHARACTER*6 TTL(14,3),CNAM(NMAX) + CHARACTER*256 NAMFIL + + LOGICAL KM,BARY + + COMMON/EPHHDR/CVAL,SS,AU,EMRAT,NUMDE,NCON,IPT + COMMON/CHRHDR/CNAM,TTL + COMMON/STCOMX/KM,BARY,PVSUN + +C +C ENTRY POINT - 1ST TIME IN, GET POINTER DATA, ETC., FROM EPH FILE +C + IF(FIRST) THEN + FIRST=.FALSE. + +C ************************************************************************ +C ************************************************************************ + +C THE USER MUST SELECT ONE OF THE FOLLOWING BY DELETING THE 'C' IN COLUMN 1 + +C ************************************************************************ + +C CALL FSIZER1(NRECL,KSIZE,NRFILE,NAMFIL) +C CALL FSIZER2(NRECL,KSIZE,NRFILE,NAMFIL) + CALL FSIZER3(NRECL,KSIZE,NRFILE,NAMFIL) + + IF(NRECL .EQ. 0) WRITE(*,*)' ***** FSIZER IS NOT WORKING *****' + +C ************************************************************************ +C ************************************************************************ + + IRECSZ=NRECL*KSIZE + NCOEFFS=KSIZE/2 + + OPEN(NRFILE, + * FILE=NAMFIL, + * ACCESS='DIRECT', + * FORM='UNFORMATTED', + * RECL=IRECSZ, + * STATUS='OLD') + + READ(NRFILE,REC=1)TTL,(CNAM(K),K=1,OLDMAX),SS,NCON,AU,EMRAT, + & ((IPT(I,J),I=1,3),J=1,12),NUMDE,(IPT(I,13),I=1,3) + & ,(CNAM(L),L=OLDMAX+1,NCON) + + IF(NCON .LE. OLDMAX)THEN + READ(NRFILE,REC=2)(CVAL(I),I=1,OLDMAX) + ELSE + READ(NRFILE,REC=2)(CVAL(I),I=1,NCON) + ENDIF + + NRL=0 + + ENDIF + +C ********** MAIN ENTRY POINT ********** + + IF(ET2(1) .EQ. 0.D0) RETURN + + S=ET2(1)-.5D0 + CALL SPLIT(S,PJD(1)) + CALL SPLIT(ET2(2),PJD(3)) + PJD(1)=PJD(1)+PJD(3)+.5D0 + PJD(2)=PJD(2)+PJD(4) + CALL SPLIT(PJD(2),PJD(3)) + PJD(1)=PJD(1)+PJD(3) + +C ERROR RETURN FOR EPOCH OUT OF RANGE + + IF(PJD(1)+PJD(4).LT.SS(1) .OR. PJD(1)+PJD(4).GT.SS(2)) GO TO 98 + +C CALCULATE RECORD # AND RELATIVE TIME IN INTERVAL + + NR=IDINT((PJD(1)-SS(1))/SS(3))+3 + IF(PJD(1).EQ.SS(2)) NR=NR-1 + + tmp1 = DBLE(NR-3)*SS(3) + SS(1) + tmp2 = PJD(1) - tmp1 + T(1) = (tmp2 + PJD(4))/SS(3) + +C READ CORRECT RECORD IF NOT IN CORE + + IF(NR.NE.NRL) THEN + NRL=NR + READ(NRFILE,REC=NR,ERR=99)(BUF(K),K=1,NCOEFFS) + ENDIF + + IF(KM) THEN + T(2)=SS(3)*86400.D0 + AUFAC=1.D0 + ELSE + T(2)=SS(3) + AUFAC=1.D0/AU + ENDIF + +C INTERPOLATE SSBARY SUN + + CALL INTERP(BUF(IPT(1,11)),T,IPT(2,11),3,IPT(3,11),2,PVSUN) + + DO I=1,6 + PVSUN(I)=PVSUN(I)*AUFAC + ENDDO + +C CHECK AND INTERPOLATE WHICHEVER BODIES ARE REQUESTED + + DO 4 I=1,10 + IF(LIST(I).EQ.0) GO TO 4 + + CALL INTERP(BUF(IPT(1,I)),T,IPT(2,I),3,IPT(3,I), + & LIST(I),PV(1,I)) + + DO J=1,6 + IF(I.LE.9 .AND. .NOT.BARY) THEN + PV(J,I)=PV(J,I)*AUFAC-PVSUN(J) + ELSE + PV(J,I)=PV(J,I)*AUFAC + ENDIF + ENDDO + + 4 CONTINUE + +C DO NUTATIONS IF REQUESTED (AND IF ON FILE) + + IF(LIST(11).GT.0 .AND. IPT(2,12).GT.0) + * CALL INTERP(BUF(IPT(1,12)),T,IPT(2,12),2,IPT(3,12), + * LIST(11),PNUT) + +C GET LIBRATIONS IF REQUESTED (AND IF ON FILE) + + IF(LIST(12).GT.0 .AND. IPT(2,13).GT.0) + * CALL INTERP(BUF(IPT(1,13)),T,IPT(2,13),3,IPT(3,13), + * LIST(12),PV(1,11)) + + RETURN + + 98 WRITE(*,198)ET2(1)+ET2(2),SS(1),SS(2) + 198 FORMAT(' *** Requested JED,',f12.2, + * ' not within ephemeris limits,',2f12.2,' ***') + + STOP + + 99 WRITE(*,'(2F12.2,A80)')ET2,'ERROR RETURN IN STATE' + + STOP + + END +C+++++++++++++++++++++++++++++ +C + SUBROUTINE CONST(NAM,VAL,SSS,N) +C +C+++++++++++++++++++++++++++++ +C +C THIS ENTRY OBTAINS THE CONSTANTS FROM THE EPHEMERIS FILE +C +C CALLING SEQEUNCE PARAMETERS (ALL OUTPUT): +C +C NAM = CHARACTER*6 ARRAY OF CONSTANT NAMES +C +C VAL = D.P. ARRAY OF VALUES OF CONSTANTS +C +C SSS = D.P. JD START, JD STOP, STEP OF EPHEMERIS +C +C N = INTEGER NUMBER OF ENTRIES IN 'NAM' AND 'VAL' ARRAYS +C + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + + SAVE + + INTEGER NMAX + PARAMETER (NMAX = 1000) + + CHARACTER*6 NAM(*),TTL(14,3),CNAM(NMAX) + + DOUBLE PRECISION VAL(*),SSS(3),SS(3),CVAL(NMAX),ZIPS(2) + DOUBLE PRECISION PVST(6,11),PNUT(4) + DATA ZIPS/2*0.d0/ + + INTEGER IPT(3,13),DENUM,LIST(12) + logical first + data first/.true./ + + COMMON/EPHHDR/CVAL,SS,AU,EMRAT,DENUM,NCON,IPT + COMMON/CHRHDR/CNAM,TTL + +C CALL STATE TO INITIALIZE THE EPHEMERIS AND READ IN THE CONSTANTS + + IF(FIRST) CALL STATE(ZIPS,LIST,PVST,PNUT) + first=.false. + + N=NCON + + DO I=1,3 + SSS(I)=SS(I) + ENDDO + + DO I=1,N + NAM(I)=CNAM(I) + VAL(I)=CVAL(I) + ENDDO + + RETURN + + END diff --git a/lib/jt4.f90 b/lib/jt4.f90 index 3ccbf93b..21407255 100755 --- a/lib/jt4.f90 +++ b/lib/jt4.f90 @@ -1,26 +1,26 @@ -module jt4 - parameter (MAXAVE=64) - integer iutc(MAXAVE) - integer nfsave(MAXAVE) - integer listutc(10) - real ppsave(207,7,MAXAVE) !Accumulated data for message averaging - real rsymbol(207,7) - real dtsave(MAXAVE) - real syncsave(MAXAVE) - real flipsave(MAXAVE) - real zz(1260,65,7) - - integer nsave,nlist,ich1,ich2 - integer nch(7) - integer npr(207) - data rsymbol/1449*0.0/ - data nch/1,2,4,9,18,36,72/ - data npr/ & - 0,0,0,0,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0, & - 0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,0,0, & - 1,0,0,1,0,0,1,1,1,1,1,0,0,0,1,0,1,0,0,0,1,1,1,1,0,1,1,0,0,1, & - 0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1,0,1,0,1, & - 0,1,1,1,0,0,1,0,1,1,0,1,1,1,1,0,0,0,0,1,1,0,1,1,0,0,0,1,1,1, & - 0,1,1,1,0,1,1,1,0,0,1,0,0,0,1,1,0,1,1,0,0,1,0,0,0,1,1,1,1,1, & - 1,0,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,1,0,1,1,1,1,0,1,0,1/ -end module jt4 +module jt4 + parameter (MAXAVE=64) + integer iutc(MAXAVE) + integer nfsave(MAXAVE) + integer listutc(10) + real ppsave(207,7,MAXAVE) !Accumulated data for message averaging + real rsymbol(207,7) + real dtsave(MAXAVE) + real syncsave(MAXAVE) + real flipsave(MAXAVE) + real zz(1260,65,7) + + integer nsave,nlist,ich1,ich2 + integer nch(7) + integer npr(207) + data rsymbol/1449*0.0/ + data nch/1,2,4,9,18,36,72/ + data npr/ & + 0,0,0,0,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0, & + 0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,0,0, & + 1,0,0,1,0,0,1,1,1,1,1,0,0,0,1,0,1,0,0,0,1,1,1,1,0,1,1,0,0,1, & + 0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1,0,1,0,1, & + 0,1,1,1,0,0,1,0,1,1,0,1,1,1,1,0,0,0,0,1,1,0,1,1,0,0,0,1,1,1, & + 0,1,1,1,0,1,1,1,0,0,1,0,0,0,1,1,0,1,1,0,0,1,0,0,0,1,1,1,1,1, & + 1,0,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,1,0,1,1,1,1,0,1,0,1/ +end module jt4 diff --git a/lib/jt4_decode.f90 b/lib/jt4_decode.f90 index ccbf6927..0b825990 100755 --- a/lib/jt4_decode.f90 +++ b/lib/jt4_decode.f90 @@ -1,412 +1,412 @@ -module jt4_decode - type :: jt4_decoder - procedure(jt4_decode_callback), pointer :: decode_callback => null () - procedure(jt4_average_callback), pointer :: average_callback => null () - contains - procedure :: decode - procedure, private :: wsjt4, avg4 - end type jt4_decoder - -! Callback function to be called with each decode - abstract interface - subroutine jt4_decode_callback (this, snr, dt, freq, have_sync, & - sync, is_deep, decoded, qual, ich, is_average, ave) - import jt4_decoder - implicit none - class(jt4_decoder), intent(inout) :: this - integer, intent(in) :: snr - real, intent(in) :: dt - integer, intent(in) :: freq - logical, intent(in) :: have_sync - logical, intent(in) :: is_deep - character(len=1), intent(in) :: sync - character(len=22), intent(in) :: decoded - real, intent(in) :: qual - integer, intent(in) :: ich - logical, intent(in) :: is_average - integer, intent(in) :: ave - end subroutine jt4_decode_callback - end interface - -! Callback function to be called with each average result - abstract interface - subroutine jt4_average_callback (this, used, utc, sync, dt, freq, flip) - import jt4_decoder - implicit none - class(jt4_decoder), intent(inout) :: this - logical, intent(in) :: used - integer, intent(in) :: utc - real, intent(in) :: sync - real, intent(in) :: dt - integer, intent(in) :: freq - logical, intent(in) :: flip - end subroutine jt4_average_callback - end interface - -contains - - subroutine decode(this,decode_callback,dd,jz,nutc,nfqso,ntol0,emedelay, & - dttol,nagain,ndepth,nclearave,minsync,minw,nsubmode,mycall,hiscall, & - hisgrid,nlist0,listutc0,average_callback) - - use jt4 - use timer_module, only: timer - - class(jt4_decoder), intent(inout) :: this - procedure(jt4_decode_callback) :: decode_callback - integer, intent(in) :: jz,nutc,nfqso,ntol0,ndepth,minsync,minw,nsubmode, & - nlist0,listutc0(10) - real, intent(in) :: dd(jz),emedelay,dttol - logical, intent(in) :: nagain, nclearave - character(len=12), intent(in) :: mycall,hiscall - character(len=6), intent(in) :: hisgrid - procedure(jt4_average_callback), optional :: average_callback - - real*4 dat(30*11025) - character*6 cfile6 - - this%decode_callback => decode_callback - if (present (average_callback)) then - this%average_callback => average_callback - end if - mode4=nch(nsubmode+1) - ntol=ntol0 - neme=0 - lumsg=6 !### temp ? ### - ndiag=1 - nlist=nlist0 - listutc=listutc0 - - ! Lowpass filter and decimate by 2 - call timer('lpf1 ',0) - call lpf1(dd,jz,dat,jz2) - call timer('lpf1 ',1) - - write(cfile6(1:4),1000) nutc -1000 format(i4.4) - cfile6(5:6)=' ' - - call timer('wsjt4 ',0) - call this%wsjt4(dat,jz2,nutc,NClearAve,minsync,ntol,emedelay,dttol,mode4, & - minw,mycall,hiscall,hisgrid,nfqso,NAgain,ndepth,neme) - call timer('wsjt4 ',1) - - return - end subroutine decode - - subroutine wsjt4(this,dat,npts,nutc,NClearAve,minsync,ntol,emedelay,dttol, & - mode4,minw,mycall,hiscall,hisgrid,nfqso,NAgain,ndepth,neme) - -! Orchestrates the process of decoding JT4 messages. Note that JT4 -! always operates as if in "Single Decode" mode; it looks for only one -! decodable signal in the FTol range. - - use jt4 - use timer_module, only: timer - - class(jt4_decoder), intent(inout) :: this - integer, intent(in) :: npts,nutc,minsync,ntol,mode4,minw, & - nfqso,ndepth,neme - logical, intent(in) :: NAgain,NClearAve - character(len=12), intent(in) :: mycall,hiscall - character(len=6), intent(in) :: hisgrid - real, intent(in) :: dat(npts) !Raw data - logical first,prtavg - character decoded*22,special*5 - character*22 avemsg,deepmsg,deepave,blank,deepmsg0,deepave1 - character csync*1 - data first/.true./,nutc0/-999/,nfreq0/-999999/ - save - - if(first) then - nsave=0 - first=.false. - blank=' ' -! Silence compiler warnings - if(dttol.eq.-99.0 .and. emedelay.eq.-99.0 .and. nagain) stop - endif - - zz=0. -! syncmin=3.0 + minsync - syncmin=1.0+minsync - naggressive=0 - if(ndepth.ge.2) naggressive=1 - nq1=3 - nq2=6 - if(naggressive.eq.1) nq1=1 - if(NClearAve) then - nsave=0 - iutc=-1 - nfsave=0. - listutc=0 - ppsave=0. - rsymbol=0. - dtsave=0. - syncsave=0. - nfanoave=0 - ndeepave=0 - endif - -! Attempt to synchronize: look for sync pattern, get DF and DT. - call timer('sync4 ',0) - call sync4(dat,npts,ntol,nfqso,4,mode4,minw+1,dtx,dfx, & - snrx,snrsync,flip,width) - sync=snrsync - dtxz=dtx-0.8 - nfreqz=nint(dfx) - call timer('sync4 ',1) - - nsnr=-26 - if(sync.lt.syncmin) then - if (associated (this%decode_callback)) then - call this%decode_callback(nsnr,dtxz,nfreqz,.false.,csync, & - .false.,decoded,0.,ich,.false.,0) - end if - go to 990 - endif - -! We have achieved sync - nsnr=nint(snrsync - 22.9) - decoded=blank - deepmsg=blank - special=' ' - nsync=sync - nsnrlim=-33 - csync='*' - if(flip.lt.0.0) csync='#' - qbest=0. - qabest=0. - prtavg=.false. - - do idt=-2,2 - dtx=dtxz + 0.03*idt - nfreq=nfreqz + 2*idf - -! Attempt a single-sequence decode, including deep4 if Fano fails. - call timer('decode4 ',0) - call decode4(dat,npts,dtx,nfreq,flip,mode4,ndepth,neme,minw, & - mycall,hiscall,hisgrid,decoded,nfano,deepmsg,qual,ich) - call timer('decode4 ',1) - - if(nfano.gt.0) then -! Fano succeeded: report the message and return !Fano OK - if (associated (this%decode_callback)) then - call this%decode_callback(nsnr,dtx,nfreq,.true.,csync, & - .false.,decoded,99.,ich,.false.,0) - end if -!### nsave=0 - go to 990 - - else !Fano failed - if(qual.gt.qbest) then - dtx0=dtx - nfreq0=nfreq - deepmsg0=deepmsg - ich0=ich - qbest=qual - endif - endif - - if(idt.ne.0) cycle -! Single-sequence Fano decode failed, so try for an average Fano decode: - qave=0. -! If we're doing averaging, call avg4 - if(iand(ndepth,16).eq.16 .and. (.not.prtavg)) then - if(nutc.ne.nutc0 .or. abs(nfreq-nfreq0).gt.ntol) then -! This is a new minute or a new frequency, so call avg4. - nutc0=nutc !Try decoding average - nfreq0=nfreq - nsave=nsave+1 - nsave=mod(nsave-1,64)+1 - call timer('avg4 ',0) - call this%avg4(nutc,sync,dtx,flip,nfreq,mode4,ntol,ndepth,neme, & - mycall,hiscall,hisgrid,nfanoave,avemsg,qave,deepave,ich, & - ndeepave) - call timer('avg4 ',1) - endif - - if(nfanoave.gt.0) then -! Fano succeeded: report the message AVG FANO OK - if (associated (this%decode_callback)) then - call this%decode_callback(nsnr,dtx,nfreq,.true.,csync, & - .false.,avemsg,99.,ich,.true.,nfanoave) - end if - prtavg=.true. - cycle - else - if(qave.gt.qabest) then - dtx1=dtx - nfreq1=nfreq - deepave1=deepave - ich1=ich - qabest=qave - endif - endif - endif - enddo - - dtx=dtx0 - nfreq=nfreq0 - deepmsg=deepmsg0 - ich=ich0 - qual=qbest - - if (associated (this%decode_callback)) then - if(int(qual).ge.nq1) then - call this%decode_callback(nsnr,dtx,nfreqz,.true.,csync,.true., & - deepmsg,qual,ich,.false.,0) - else - call this%decode_callback(nsnr,dtxz,nfreqz,.true.,csync, & - .false.,blank,0.,ich,.false.,0) - endif - end if - - dtx=dtx1 - nfreq=nfreq1 - deepave=deepave1 - ich=ich1 - qave=qabest - - if (associated (this%decode_callback) .and. ndeepave.ge.2) then - if(int(qave).ge.nq1) then - call this%decode_callback(nsnr,dtx,nfreq,.true.,csync,.true., & - deepave,qave,ich,.true.,ndeepave) - endif - end if - -990 return - end subroutine wsjt4 - - subroutine avg4(this,nutc,snrsync,dtxx,flip,nfreq,mode4,ntol,ndepth,neme, & - mycall,hiscall,hisgrid,nfanoave,avemsg,qave,deepave,ichbest,ndeepave) - -! Decodes averaged JT4 data - - use jt4 - class(jt4_decoder), intent(inout) :: this - - character*22 avemsg,deepave,deepbest - character mycall*12,hiscall*12,hisgrid*6 - character*1 csync,cused(64) - real sym(207,7) - integer iused(64) - logical first - data first/.true./ - save - - if(first) then - iutc=-1 - nfsave=0 - dtdiff=0.2 - first=.false. - nsave=1 ! ### Should this be here? ### - endif - - do i=1,64 - if(nutc.eq.iutc(i) .and. abs(nfreq-nfsave(i)).le.ntol) go to 10 - enddo - -! Save data for message averaging - iutc(nsave)=nutc - syncsave(nsave)=snrsync - dtsave(nsave)=dtxx - nfsave(nsave)=nfreq - flipsave(nsave)=flip - ppsave(1:207,1:7,nsave)=rsymbol(1:207,1:7) - -10 sym=0. - syncsum=0. - dtsum=0. - nfsum=0 - nsum=0 - - do i=1,64 - cused(i)='.' - if(iutc(i).lt.0) cycle - if(mod(iutc(i),2).ne.mod(nutc,2)) cycle !Use only same sequence - if(abs(dtxx-dtsave(i)).gt.dtdiff) cycle !DT must match - if(abs(nfreq-nfsave(i)).gt.ntol) cycle !Freq must match - if(flip.ne.flipsave(i)) cycle !Sync (*/#) must match - sym(1:207,1:7)=sym(1:207,1:7) + ppsave(1:207,1:7,i) - syncsum=syncsum + syncsave(i) - dtsum=dtsum + dtsave(i) - nfsum=nfsum + nfsave(i) - cused(i)='$' - nsum=nsum+1 - iused(nsum)=i - enddo - if(nsum.lt.64) iused(nsum+1)=0 - - syncave=0. - dtave=0. - fave=0. - if(nsum.gt.0) then - sym=sym/nsum - syncave=syncsum/nsum - dtave=dtsum/nsum - fave=float(nfsum)/nsum - endif - - do i=1,nsave - csync='*' - if(flipsave(i).lt.0.0) csync='#' - if (associated (this%average_callback)) then - call this%average_callback(cused(i) .eq. '$',iutc(i), & - syncsave(i),dtsave(i),nfsave(i),flipsave(i).lt.0.) - end if - enddo - - sqt=0. - sqf=0. - do j=1,64 - i=iused(j) - if(i.eq.0) exit - csync='*' - if(flipsave(i).lt.0.0) csync='#' - sqt=sqt + (dtsave(i)-dtave)**2 - sqf=sqf + (nfsave(i)-fave)**2 - enddo - rmst=0. - rmsf=0. - if(nsum.ge.2) then - rmst=sqrt(sqt/(nsum-1)) - rmsf=sqrt(sqf/(nsum-1)) - endif - kbest=ich1 - do k=ich1,ich2 - call extract4(sym(1,k),ncount,avemsg) !Do the Fano decode - nfanoave=0 - if(ncount.ge.0) then - ichbest=k - nfanoave=nsum - go to 900 - endif - if(nch(k).ge.mode4) exit - enddo - - deepave=' ' - qave=0. - -! Possibly should pass nadd=nused, also ? - if(iand(ndepth,32).eq.32) then - flipx=1.0 !Normal flip not relevant for ave msg - qbest=0. - do k=ich1,ich2 - call deep4(sym(2,k),neme,flipx,mycall,hiscall,hisgrid,deepave,qave) - if(qave.gt.qbest) then - qbest=qave - deepbest=deepave - kbest=k - ndeepave=nsum - endif - if(nch(k).ge.mode4) exit - enddo - - deepave=deepbest - qave=qbest - ichbest=kbest - endif - -900 return - end subroutine avg4 -end module jt4_decode +module jt4_decode + type :: jt4_decoder + procedure(jt4_decode_callback), pointer :: decode_callback => null () + procedure(jt4_average_callback), pointer :: average_callback => null () + contains + procedure :: decode + procedure, private :: wsjt4, avg4 + end type jt4_decoder + +! Callback function to be called with each decode + abstract interface + subroutine jt4_decode_callback (this, snr, dt, freq, have_sync, & + sync, is_deep, decoded, qual, ich, is_average, ave) + import jt4_decoder + implicit none + class(jt4_decoder), intent(inout) :: this + integer, intent(in) :: snr + real, intent(in) :: dt + integer, intent(in) :: freq + logical, intent(in) :: have_sync + logical, intent(in) :: is_deep + character(len=1), intent(in) :: sync + character(len=22), intent(in) :: decoded + real, intent(in) :: qual + integer, intent(in) :: ich + logical, intent(in) :: is_average + integer, intent(in) :: ave + end subroutine jt4_decode_callback + end interface + +! Callback function to be called with each average result + abstract interface + subroutine jt4_average_callback (this, used, utc, sync, dt, freq, flip) + import jt4_decoder + implicit none + class(jt4_decoder), intent(inout) :: this + logical, intent(in) :: used + integer, intent(in) :: utc + real, intent(in) :: sync + real, intent(in) :: dt + integer, intent(in) :: freq + logical, intent(in) :: flip + end subroutine jt4_average_callback + end interface + +contains + + subroutine decode(this,decode_callback,dd,jz,nutc,nfqso,ntol0,emedelay, & + dttol,nagain,ndepth,nclearave,minsync,minw,nsubmode,mycall,hiscall, & + hisgrid,nlist0,listutc0,average_callback) + + use jt4 + use timer_module, only: timer + + class(jt4_decoder), intent(inout) :: this + procedure(jt4_decode_callback) :: decode_callback + integer, intent(in) :: jz,nutc,nfqso,ntol0,ndepth,minsync,minw,nsubmode, & + nlist0,listutc0(10) + real, intent(in) :: dd(jz),emedelay,dttol + logical, intent(in) :: nagain, nclearave + character(len=12), intent(in) :: mycall,hiscall + character(len=6), intent(in) :: hisgrid + procedure(jt4_average_callback), optional :: average_callback + + real*4 dat(30*11025) + character*6 cfile6 + + this%decode_callback => decode_callback + if (present (average_callback)) then + this%average_callback => average_callback + end if + mode4=nch(nsubmode+1) + ntol=ntol0 + neme=0 + lumsg=6 !### temp ? ### + ndiag=1 + nlist=nlist0 + listutc=listutc0 + + ! Lowpass filter and decimate by 2 + call timer('lpf1 ',0) + call lpf1(dd,jz,dat,jz2) + call timer('lpf1 ',1) + + write(cfile6(1:4),1000) nutc +1000 format(i4.4) + cfile6(5:6)=' ' + + call timer('wsjt4 ',0) + call this%wsjt4(dat,jz2,nutc,NClearAve,minsync,ntol,emedelay,dttol,mode4, & + minw,mycall,hiscall,hisgrid,nfqso,NAgain,ndepth,neme) + call timer('wsjt4 ',1) + + return + end subroutine decode + + subroutine wsjt4(this,dat,npts,nutc,NClearAve,minsync,ntol,emedelay,dttol, & + mode4,minw,mycall,hiscall,hisgrid,nfqso,NAgain,ndepth,neme) + +! Orchestrates the process of decoding JT4 messages. Note that JT4 +! always operates as if in "Single Decode" mode; it looks for only one +! decodable signal in the FTol range. + + use jt4 + use timer_module, only: timer + + class(jt4_decoder), intent(inout) :: this + integer, intent(in) :: npts,nutc,minsync,ntol,mode4,minw, & + nfqso,ndepth,neme + logical, intent(in) :: NAgain,NClearAve + character(len=12), intent(in) :: mycall,hiscall + character(len=6), intent(in) :: hisgrid + real, intent(in) :: dat(npts) !Raw data + logical first,prtavg + character decoded*22,special*5 + character*22 avemsg,deepmsg,deepave,blank,deepmsg0,deepave1 + character csync*1 + data first/.true./,nutc0/-999/,nfreq0/-999999/ + save + + if(first) then + nsave=0 + first=.false. + blank=' ' +! Silence compiler warnings + if(dttol.eq.-99.0 .and. emedelay.eq.-99.0 .and. nagain) stop + endif + + zz=0. +! syncmin=3.0 + minsync + syncmin=1.0+minsync + naggressive=0 + if(ndepth.ge.2) naggressive=1 + nq1=3 + nq2=6 + if(naggressive.eq.1) nq1=1 + if(NClearAve) then + nsave=0 + iutc=-1 + nfsave=0. + listutc=0 + ppsave=0. + rsymbol=0. + dtsave=0. + syncsave=0. + nfanoave=0 + ndeepave=0 + endif + +! Attempt to synchronize: look for sync pattern, get DF and DT. + call timer('sync4 ',0) + call sync4(dat,npts,ntol,nfqso,4,mode4,minw+1,dtx,dfx, & + snrx,snrsync,flip,width) + sync=snrsync + dtxz=dtx-0.8 + nfreqz=nint(dfx) + call timer('sync4 ',1) + + nsnr=-26 + if(sync.lt.syncmin) then + if (associated (this%decode_callback)) then + call this%decode_callback(nsnr,dtxz,nfreqz,.false.,csync, & + .false.,decoded,0.,ich,.false.,0) + end if + go to 990 + endif + +! We have achieved sync + nsnr=nint(snrsync - 22.9) + decoded=blank + deepmsg=blank + special=' ' + nsync=sync + nsnrlim=-33 + csync='*' + if(flip.lt.0.0) csync='#' + qbest=0. + qabest=0. + prtavg=.false. + + do idt=-2,2 + dtx=dtxz + 0.03*idt + nfreq=nfreqz + 2*idf + +! Attempt a single-sequence decode, including deep4 if Fano fails. + call timer('decode4 ',0) + call decode4(dat,npts,dtx,nfreq,flip,mode4,ndepth,neme,minw, & + mycall,hiscall,hisgrid,decoded,nfano,deepmsg,qual,ich) + call timer('decode4 ',1) + + if(nfano.gt.0) then +! Fano succeeded: report the message and return !Fano OK + if (associated (this%decode_callback)) then + call this%decode_callback(nsnr,dtx,nfreq,.true.,csync, & + .false.,decoded,99.,ich,.false.,0) + end if +!### nsave=0 + go to 990 + + else !Fano failed + if(qual.gt.qbest) then + dtx0=dtx + nfreq0=nfreq + deepmsg0=deepmsg + ich0=ich + qbest=qual + endif + endif + + if(idt.ne.0) cycle +! Single-sequence Fano decode failed, so try for an average Fano decode: + qave=0. +! If we're doing averaging, call avg4 + if(iand(ndepth,16).eq.16 .and. (.not.prtavg)) then + if(nutc.ne.nutc0 .or. abs(nfreq-nfreq0).gt.ntol) then +! This is a new minute or a new frequency, so call avg4. + nutc0=nutc !Try decoding average + nfreq0=nfreq + nsave=nsave+1 + nsave=mod(nsave-1,64)+1 + call timer('avg4 ',0) + call this%avg4(nutc,sync,dtx,flip,nfreq,mode4,ntol,ndepth,neme, & + mycall,hiscall,hisgrid,nfanoave,avemsg,qave,deepave,ich, & + ndeepave) + call timer('avg4 ',1) + endif + + if(nfanoave.gt.0) then +! Fano succeeded: report the message AVG FANO OK + if (associated (this%decode_callback)) then + call this%decode_callback(nsnr,dtx,nfreq,.true.,csync, & + .false.,avemsg,99.,ich,.true.,nfanoave) + end if + prtavg=.true. + cycle + else + if(qave.gt.qabest) then + dtx1=dtx + nfreq1=nfreq + deepave1=deepave + ich1=ich + qabest=qave + endif + endif + endif + enddo + + dtx=dtx0 + nfreq=nfreq0 + deepmsg=deepmsg0 + ich=ich0 + qual=qbest + + if (associated (this%decode_callback)) then + if(int(qual).ge.nq1) then + call this%decode_callback(nsnr,dtx,nfreqz,.true.,csync,.true., & + deepmsg,qual,ich,.false.,0) + else + call this%decode_callback(nsnr,dtxz,nfreqz,.true.,csync, & + .false.,blank,0.,ich,.false.,0) + endif + end if + + dtx=dtx1 + nfreq=nfreq1 + deepave=deepave1 + ich=ich1 + qave=qabest + + if (associated (this%decode_callback) .and. ndeepave.ge.2) then + if(int(qave).ge.nq1) then + call this%decode_callback(nsnr,dtx,nfreq,.true.,csync,.true., & + deepave,qave,ich,.true.,ndeepave) + endif + end if + +990 return + end subroutine wsjt4 + + subroutine avg4(this,nutc,snrsync,dtxx,flip,nfreq,mode4,ntol,ndepth,neme, & + mycall,hiscall,hisgrid,nfanoave,avemsg,qave,deepave,ichbest,ndeepave) + +! Decodes averaged JT4 data + + use jt4 + class(jt4_decoder), intent(inout) :: this + + character*22 avemsg,deepave,deepbest + character mycall*12,hiscall*12,hisgrid*6 + character*1 csync,cused(64) + real sym(207,7) + integer iused(64) + logical first + data first/.true./ + save + + if(first) then + iutc=-1 + nfsave=0 + dtdiff=0.2 + first=.false. + nsave=1 ! ### Should this be here? ### + endif + + do i=1,64 + if(nutc.eq.iutc(i) .and. abs(nfreq-nfsave(i)).le.ntol) go to 10 + enddo + +! Save data for message averaging + iutc(nsave)=nutc + syncsave(nsave)=snrsync + dtsave(nsave)=dtxx + nfsave(nsave)=nfreq + flipsave(nsave)=flip + ppsave(1:207,1:7,nsave)=rsymbol(1:207,1:7) + +10 sym=0. + syncsum=0. + dtsum=0. + nfsum=0 + nsum=0 + + do i=1,64 + cused(i)='.' + if(iutc(i).lt.0) cycle + if(mod(iutc(i),2).ne.mod(nutc,2)) cycle !Use only same sequence + if(abs(dtxx-dtsave(i)).gt.dtdiff) cycle !DT must match + if(abs(nfreq-nfsave(i)).gt.ntol) cycle !Freq must match + if(flip.ne.flipsave(i)) cycle !Sync (*/#) must match + sym(1:207,1:7)=sym(1:207,1:7) + ppsave(1:207,1:7,i) + syncsum=syncsum + syncsave(i) + dtsum=dtsum + dtsave(i) + nfsum=nfsum + nfsave(i) + cused(i)='$' + nsum=nsum+1 + iused(nsum)=i + enddo + if(nsum.lt.64) iused(nsum+1)=0 + + syncave=0. + dtave=0. + fave=0. + if(nsum.gt.0) then + sym=sym/nsum + syncave=syncsum/nsum + dtave=dtsum/nsum + fave=float(nfsum)/nsum + endif + + do i=1,nsave + csync='*' + if(flipsave(i).lt.0.0) csync='#' + if (associated (this%average_callback)) then + call this%average_callback(cused(i) .eq. '$',iutc(i), & + syncsave(i),dtsave(i),nfsave(i),flipsave(i).lt.0.) + end if + enddo + + sqt=0. + sqf=0. + do j=1,64 + i=iused(j) + if(i.eq.0) exit + csync='*' + if(flipsave(i).lt.0.0) csync='#' + sqt=sqt + (dtsave(i)-dtave)**2 + sqf=sqf + (nfsave(i)-fave)**2 + enddo + rmst=0. + rmsf=0. + if(nsum.ge.2) then + rmst=sqrt(sqt/(nsum-1)) + rmsf=sqrt(sqf/(nsum-1)) + endif + kbest=ich1 + do k=ich1,ich2 + call extract4(sym(1,k),ncount,avemsg) !Do the Fano decode + nfanoave=0 + if(ncount.ge.0) then + ichbest=k + nfanoave=nsum + go to 900 + endif + if(nch(k).ge.mode4) exit + enddo + + deepave=' ' + qave=0. + +! Possibly should pass nadd=nused, also ? + if(iand(ndepth,32).eq.32) then + flipx=1.0 !Normal flip not relevant for ave msg + qbest=0. + do k=ich1,ich2 + call deep4(sym(2,k),neme,flipx,mycall,hiscall,hisgrid,deepave,qave) + if(qave.gt.qbest) then + qbest=qave + deepbest=deepave + kbest=k + ndeepave=nsum + endif + if(nch(k).ge.mode4) exit + enddo + + deepave=deepbest + qave=qbest + ichbest=kbest + endif + +900 return + end subroutine avg4 +end module jt4_decode diff --git a/lib/jt4a.f90 b/lib/jt4a.f90 index 0573ab6f..fc37ec05 100755 --- a/lib/jt4a.f90 +++ b/lib/jt4a.f90 @@ -1,2 +1,2 @@ - ! The contents of this file have been migrated to lib/jt4_decode.f90 - + ! The contents of this file have been migrated to lib/jt4_decode.f90 + diff --git a/lib/jt4code.f90 b/lib/jt4code.f90 index 9d709571..e11f6144 100755 --- a/lib/jt4code.f90 +++ b/lib/jt4code.f90 @@ -1,50 +1,50 @@ -program jt4code - -! Provides examples of message packing, bit and symbol ordering, -! convolutional encoding, and other necessary details of the JT4 -! protocol. - - use jt4 - use packjt - character*22 msg,decoded,bad*1,msgtype*13 - integer i4tone(206) - include 'testmsg.f90' - - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: jt4code "message"' - print*,' jt4code -t' - go to 999 - endif - - call getarg(1,msg) - nmsg=1 - if(msg(1:2).eq."-t") nmsg=NTEST - - write(*,1010) -1010 format(" Message Decoded Err? Type"/ & - 74("-")) - do imsg=1,nmsg - if(nmsg.gt.1) msg=testmsg(imsg) - call fmtmsg(msg,iz) !To upper case, collapse multiple blanks - ichk=0 - call gen4(msg,ichk,decoded,i4tone,itype) - - msgtype="" - if(itype.eq.1) msgtype="Std Msg" - if(itype.eq.2) msgtype="Type 1 prefix" - if(itype.eq.3) msgtype="Type 1 suffix" - if(itype.eq.4) msgtype="Type 2 prefix" - if(itype.eq.5) msgtype="Type 2 suffix" - if(itype.eq.6) msgtype="Free text" - - bad=" " - if(decoded.ne.msg) bad="*" - write(*,1020) imsg,msg,decoded,bad,itype,msgtype -1020 format(i2,'.',2x,a22,2x,a22,3x,a1,i3,": ",a13) - enddo - - if(nmsg.eq.1) write(*,1030) i4tone -1030 format(/'Channel symbols'/(30i2)) - -999 end program jt4code +program jt4code + +! Provides examples of message packing, bit and symbol ordering, +! convolutional encoding, and other necessary details of the JT4 +! protocol. + + use jt4 + use packjt + character*22 msg,decoded,bad*1,msgtype*13 + integer i4tone(206) + include 'testmsg.f90' + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: jt4code "message"' + print*,' jt4code -t' + go to 999 + endif + + call getarg(1,msg) + nmsg=1 + if(msg(1:2).eq."-t") nmsg=NTEST + + write(*,1010) +1010 format(" Message Decoded Err? Type"/ & + 74("-")) + do imsg=1,nmsg + if(nmsg.gt.1) msg=testmsg(imsg) + call fmtmsg(msg,iz) !To upper case, collapse multiple blanks + ichk=0 + call gen4(msg,ichk,decoded,i4tone,itype) + + msgtype="" + if(itype.eq.1) msgtype="Std Msg" + if(itype.eq.2) msgtype="Type 1 prefix" + if(itype.eq.3) msgtype="Type 1 suffix" + if(itype.eq.4) msgtype="Type 2 prefix" + if(itype.eq.5) msgtype="Type 2 suffix" + if(itype.eq.6) msgtype="Free text" + + bad=" " + if(decoded.ne.msg) bad="*" + write(*,1020) imsg,msg,decoded,bad,itype,msgtype +1020 format(i2,'.',2x,a22,2x,a22,3x,a1,i3,": ",a13) + enddo + + if(nmsg.eq.1) write(*,1030) i4tone +1030 format(/'Channel symbols'/(30i2)) + +999 end program jt4code diff --git a/lib/jt4sim.f90 b/lib/jt4sim.f90 index a8e02986..73edabf7 100755 --- a/lib/jt4sim.f90 +++ b/lib/jt4sim.f90 @@ -1,181 +1,181 @@ -program jt4sim - -! Generate simulated jt4 data for testing the decoder using new fading models -! Based on qra64sim with appropriate changes for JT4 -! Includes option to generate 1000Hz single tone with "ST" as the message - - use wavhdr - use packjt - use jt4 - parameter (NMAX=60*12000) ! = 648,000 - parameter (NFFT=10*65536,NH=NFFT/2) - type(hdr) h !Header for .wav file - integer*2 iwave(NMAX) !Generated waveform - integer*4 itone(206) !Channel symbols (values 0-8) - real*4 xnoise(NMAX) !Generated random noise - real*4 dat(NMAX) !Generated real data - complex cdat(NMAX) !Generated complex waveform - complex cspread(0:NFFT-1) !Complex amplitude for Rayleigh fading - complex z - real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq - character message*22,fname*11,csubmode*1,arg*12 - character msgsent*22 - - nargs=iargc() - if(nargs.ne. 7) then - print *, 'Usage: jt4sim "msg" A-E Nsigs fDop DT Nfiles SNR' - print *, 'Example jt4sim "K1ABC W9XYZ EN37" A 10 0.2 0.0 1 0' - print *, 'Example jt4sim "ST" A 10 0.2 0.0 1 0' - go to 999 - endif - call getarg(1,message) - call fmtmsg(message, iz) - call getarg(2,csubmode) - mode4=ichar(csubmode) - ichar('A') + 1 - call getarg(3,arg) - read(arg,*) nsigs - call getarg(4,arg) - read(arg,*) fspread - call getarg(5,arg) - read(arg,*) xdt - call getarg(6,arg) - read(arg,*) nfiles - call getarg(7,arg) - read(arg,*) snrdb - - if(mode4.ge.8) nsigs=1 ! temporary - will need sorting out - rms=100. - fsample=12000.d0 !Sample rate (Hz) - dt=1.d0/fsample !Sample interval (s) - twopi=8.d0*atan(1.d0) - npts=60*12000 !Total samples in .wav file - nsps=12000.d0/4.375d0 - baud=12000.d0/nsps !Keying rate = 1.7361111111 - nsym=206 !Number of channel symbols - h=default_header(12000,npts) - dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz) - ichk=0 - - write(*,1000) -1000 format('File Sig Freq A-E S/N DT Dop Message'/60('-')) - - do ifile=1,nfiles !Loop over requested number of files - write(fname,1002) ifile !Output filename -1002 format('000000_',i4.4) - open(10,file=fname//'.wav',access='stream',status='unknown') - xnoise=0. - cdat=0. - if(snrdb.lt.90) then - do i=1,npts - xnoise(i)=gran() !Generate gaussian noise - enddo - endif - - do isig=1,nsigs !Generate requested number of sigs - if(mod(nsigs,2).eq.0) f0=1500.0 + dfsig*(isig-0.5-nsigs/2) - if(mod(nsigs,2).eq.1) f0=1500.0 + dfsig*(isig-(nsigs+1)/2) - if(nsigs.eq.1) f0=1000.0 - xsnr=snrdb - if(snrdb.eq.0.0) xsnr=-20 - isig - - call gen4(message,ichk,msgsent,itone,itype) - - bandwidth_ratio=2500.0/6000.0 - sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*xsnr) - if(xsnr.gt.90.0) sig=1.0 - write(*,1020) ifile,isig,f0,csubmode,xsnr,xdt,fspread,message -1020 format(i4,i4,f10.3,2x,a1,2x,f5.1,f6.2,f6.1,1x,a22) - - phi=0.d0 - dphi=0.d0 - k=(xdt+1.0)*12000 !Start audio at t = xdt + 1.0 s - isym0=-99 - - do i=1,npts !Add this signal into cdat() - isym=i/nsps + 1 - if(isym.gt.nsym) exit - if(isym.ne.isym0) then - if(message(1:2).eq.'ST') then !Finds ST in message string for single tone - freq=1000 !1000Hz for single tone - else - freq=f0 + itone(isym)*baud*nch(mode4) - endif - dphi=twopi*freq*dt - isym0=isym - - endif - phi=phi + dphi - if(phi.gt.twopi) phi=phi-twopi - xphi=phi - z=cmplx(cos(xphi),sin(xphi)) - k=k+1 - if(k.ge.1) cdat(k)=cdat(k) + sig*z - enddo - enddo - - if(fspread.ne.0) then !Apply specified Doppler spread - df=12000.0/nfft - twopi=8*atan(1.0) - cspread(0)=1.0 - cspread(NH)=0. - b=6.0 !Lorenzian 3/28 onward - 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 - call random_number(r1) - phi1=twopi*r1 - z=a*cmplx(cos(phi1),sin(phi1)) - endif - cspread(i)=z - z=0. - if(x.lt.50.0) then - call random_number(r2) - phi2=twopi*r2 - z=a*cmplx(cos(phi2),sin(phi2)) - endif - cspread(NFFT-i)=z - enddo - - do i=0,NFFT-1 - f=i*df - if(i.gt.NH) f=(i-nfft)*df - s=real(cspread(i))**2 + aimag(cspread(i))**2 -! write(13,3000) i,f,s,cspread(i) -!3000 format(i5,f10.3,3f12.6) - enddo -! s=real(cspread(0))**2 + aimag(cspread(0))**2 -! write(13,3000) 1024,0.0,s,cspread(0) - - 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 - cdat(1:NFFT)=cspread*cdat(1:NFFT) !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 - - endif - - dat=aimag(cdat) + xnoise !Add the generated noise - fac=32767.0/nsigs - if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts)) - if(snrdb.lt.90.0) iwave(1:npts)=nint(rms*dat(1:npts)) - write(10) h,iwave(1:npts) !Save the .wav file - close(10) - enddo - -999 end program jt4sim +program jt4sim + +! Generate simulated jt4 data for testing the decoder using new fading models +! Based on qra64sim with appropriate changes for JT4 +! Includes option to generate 1000Hz single tone with "ST" as the message + + use wavhdr + use packjt + use jt4 + parameter (NMAX=60*12000) ! = 648,000 + parameter (NFFT=10*65536,NH=NFFT/2) + type(hdr) h !Header for .wav file + integer*2 iwave(NMAX) !Generated waveform + integer*4 itone(206) !Channel symbols (values 0-8) + real*4 xnoise(NMAX) !Generated random noise + real*4 dat(NMAX) !Generated real data + complex cdat(NMAX) !Generated complex waveform + complex cspread(0:NFFT-1) !Complex amplitude for Rayleigh fading + complex z + real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq + character message*22,fname*11,csubmode*1,arg*12 + character msgsent*22 + + nargs=iargc() + if(nargs.ne. 7) then + print *, 'Usage: jt4sim "msg" A-E Nsigs fDop DT Nfiles SNR' + print *, 'Example jt4sim "K1ABC W9XYZ EN37" A 10 0.2 0.0 1 0' + print *, 'Example jt4sim "ST" A 10 0.2 0.0 1 0' + go to 999 + endif + call getarg(1,message) + call fmtmsg(message, iz) + call getarg(2,csubmode) + mode4=ichar(csubmode) - ichar('A') + 1 + call getarg(3,arg) + read(arg,*) nsigs + call getarg(4,arg) + read(arg,*) fspread + call getarg(5,arg) + read(arg,*) xdt + call getarg(6,arg) + read(arg,*) nfiles + call getarg(7,arg) + read(arg,*) snrdb + + if(mode4.ge.8) nsigs=1 ! temporary - will need sorting out + rms=100. + fsample=12000.d0 !Sample rate (Hz) + dt=1.d0/fsample !Sample interval (s) + twopi=8.d0*atan(1.d0) + npts=60*12000 !Total samples in .wav file + nsps=12000.d0/4.375d0 + baud=12000.d0/nsps !Keying rate = 1.7361111111 + nsym=206 !Number of channel symbols + h=default_header(12000,npts) + dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz) + ichk=0 + + write(*,1000) +1000 format('File Sig Freq A-E S/N DT Dop Message'/60('-')) + + do ifile=1,nfiles !Loop over requested number of files + write(fname,1002) ifile !Output filename +1002 format('000000_',i4.4) + open(10,file=fname//'.wav',access='stream',status='unknown') + xnoise=0. + cdat=0. + if(snrdb.lt.90) then + do i=1,npts + xnoise(i)=gran() !Generate gaussian noise + enddo + endif + + do isig=1,nsigs !Generate requested number of sigs + if(mod(nsigs,2).eq.0) f0=1500.0 + dfsig*(isig-0.5-nsigs/2) + if(mod(nsigs,2).eq.1) f0=1500.0 + dfsig*(isig-(nsigs+1)/2) + if(nsigs.eq.1) f0=1000.0 + xsnr=snrdb + if(snrdb.eq.0.0) xsnr=-20 - isig + + call gen4(message,ichk,msgsent,itone,itype) + + bandwidth_ratio=2500.0/6000.0 + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*xsnr) + if(xsnr.gt.90.0) sig=1.0 + write(*,1020) ifile,isig,f0,csubmode,xsnr,xdt,fspread,message +1020 format(i4,i4,f10.3,2x,a1,2x,f5.1,f6.2,f6.1,1x,a22) + + phi=0.d0 + dphi=0.d0 + k=(xdt+1.0)*12000 !Start audio at t = xdt + 1.0 s + isym0=-99 + + do i=1,npts !Add this signal into cdat() + isym=i/nsps + 1 + if(isym.gt.nsym) exit + if(isym.ne.isym0) then + if(message(1:2).eq.'ST') then !Finds ST in message string for single tone + freq=1000 !1000Hz for single tone + else + freq=f0 + itone(isym)*baud*nch(mode4) + endif + dphi=twopi*freq*dt + isym0=isym + + endif + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + z=cmplx(cos(xphi),sin(xphi)) + k=k+1 + if(k.ge.1) cdat(k)=cdat(k) + sig*z + enddo + enddo + + if(fspread.ne.0) then !Apply specified Doppler spread + df=12000.0/nfft + twopi=8*atan(1.0) + cspread(0)=1.0 + cspread(NH)=0. + b=6.0 !Lorenzian 3/28 onward + 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 + call random_number(r1) + phi1=twopi*r1 + z=a*cmplx(cos(phi1),sin(phi1)) + endif + cspread(i)=z + z=0. + if(x.lt.50.0) then + call random_number(r2) + phi2=twopi*r2 + z=a*cmplx(cos(phi2),sin(phi2)) + endif + cspread(NFFT-i)=z + enddo + + do i=0,NFFT-1 + f=i*df + if(i.gt.NH) f=(i-nfft)*df + s=real(cspread(i))**2 + aimag(cspread(i))**2 +! write(13,3000) i,f,s,cspread(i) +!3000 format(i5,f10.3,3f12.6) + enddo +! s=real(cspread(0))**2 + aimag(cspread(0))**2 +! write(13,3000) 1024,0.0,s,cspread(0) + + 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 + cdat(1:NFFT)=cspread*cdat(1:NFFT) !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 + + endif + + dat=aimag(cdat) + xnoise !Add the generated noise + fac=32767.0/nsigs + if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts)) + if(snrdb.lt.90.0) iwave(1:npts)=nint(rms*dat(1:npts)) + write(10) h,iwave(1:npts) !Save the .wav file + close(10) + enddo + +999 end program jt4sim diff --git a/lib/jt65.f90 b/lib/jt65.f90 index 4137c3f4..bce3a4f1 100755 --- a/lib/jt65.f90 +++ b/lib/jt65.f90 @@ -1,143 +1,143 @@ -program jt65 - - ! Test the JT65 decoder for WSJT-X - - use options - use timer_module, only: timer - use timer_impl, only: init_timer - use jt65_test - use readwav - - character c,mode - logical :: display_help=.false.,nrobust=.false.,single_decode=.false., ljt65apon=.false. - type(wav_header) :: wav - integer*2 id2(NZMAX) - real*4 dd(NZMAX) - character*80 infile - character(len=500) optarg - character*12 mycall,hiscall - character*6 hisgrid - - type (option) :: long_options(12) = [ & - option ('aggressive',.true.,'a','aggressiveness [0-10], default AGGR=0','AGGR'), & - option ('depth',.true.,'d','depth=5 hinted decoding, default DEPTH=0','DEPTH'), & - option ('freq',.true.,'f','signal frequency, default FREQ=1270','FREQ'), & - option ('help',.false.,'h','Display this help message',''), & - option ('mode',.true.,'m','Mode A, B, C. Default is A.','MODE'), & - option ('ntrials',.true.,'n','number of trials, default TRIALS=10000','TRIALS'), & - option ('robust-sync',.false.,'r','robust sync',''), & - option ('my-call',.true.,'c','my callsign',''), & - option ('his-call',.true.,'x','his callsign',''), & - option ('his-grid',.true.,'g','his grid locator',''), & - option ('experience-decoding',.true.,'X' & - ,'experience decoding options (1..n), default FLAGS=0','FLAGS'), & - option ('single-signal-mode',.false.,'s','decode at signal frequency only','') ] - - naggressive=10 - nfqso=1500 - ntrials=100000 - nexp_decode=0 - ntol=20 - nsubmode=0 - nlow=200 - nhigh=4000 - n2pass=1 - ndepth=1 - nQSOProgress=6 - - do - call getopt('a:d:f:hm:n:rc:x:g:X:s',long_options,c,optarg,narglen,nstat,noffset,nremain,.true.) - if( nstat .ne. 0 ) then - exit - end if - select case (c) - case ('a') - read (optarg(:narglen), *) naggressive - case ('d') - read (optarg(:narglen), *) ndepth - case ('f') - read (optarg(:narglen), *) nfqso - case ('h') - display_help = .true. - case ('m') - read (optarg(:narglen), *) mode - if( mode .eq. 'b' .or. mode .eq. 'B' ) then - nsubmode=1 - endif - if( mode .eq. 'c' .or. mode .eq. 'C' ) then - nsubmode=2 - endif - case ('n') - read (optarg(:narglen), *) ntrials - case ('r') - nrobust=.true. - case ('c') - read (optarg(:narglen), *) mycall - case ('x') - read (optarg(:narglen), *) hiscall - case ('g') - read (optarg(:narglen), *) hisgrid - case ('X') - read (optarg(:narglen), *) nexp_decode - case ('s') - single_decode=.true. - ntol=100 - nlow=nfqso-ntol - nhigh=nfqso+ntol - n2pass=1 - end select - end do - - if(single_decode) nexp_decode=ior(nexp_decode,32) - if(display_help .or. nstat.lt.0 .or. nremain.lt.1) then - print *, '' - print *, 'Usage: jt65 [OPTIONS] file1 [file2 ...]' - print *, '' - print *, ' JT65 decode pre-recorded .WAV file(s)' - print *, '' - print *, 'OPTIONS:' - print *, '' - do i = 1, size (long_options) - call long_options(i) % print (6) - end do - go to 999 - endif - - call init_timer ('timer.out') - call timer('jt65 ',0) - - ndecoded=0 - do ifile=noffset+1,noffset+nremain - nfa=nlow - nfb=nhigh - minsync=0 - call get_command_argument(ifile,optarg,narglen) - infile=optarg(:narglen) - call timer('read ',0) - call wav%read (infile) - i1=index(infile,'.wav') - if( i1 .eq. 0 ) i1=index(infile,'.WAV') - read(infile(i1-4:i1-1),*,err=998) nutc - npts=52*12000 - read(unit=wav%lun) id2(1:npts) - close(unit=wav%lun) - call timer('read ',1) - dd(1:npts)=id2(1:npts) - dd(npts+1:)=0. - call test(dd,nutc,nfa,nfb,nfqso,ntol,nsubmode, & - n2pass,nrobust,ntrials,naggressive,ndepth, & - mycall,hiscall,hisgrid,nexp_decode,nQSOProgress,ljt65apon) -! if(nft.gt.0) exit - enddo - - call timer('jt65 ',1) - call timer('jt65 ',101) - ! call four2a(a,-1,1,1,1) !Free the memory used for plans - ! call filbig(a,-1,1,0.0,0,0,0,0,0) ! (ditto) - go to 999 - -998 print*,'Cannot read from file:' - print*,infile - -999 continue -end program jt65 +program jt65 + + ! Test the JT65 decoder for WSJT-X + + use options + use timer_module, only: timer + use timer_impl, only: init_timer + use jt65_test + use readwav + + character c,mode + logical :: display_help=.false.,nrobust=.false.,single_decode=.false., ljt65apon=.false. + type(wav_header) :: wav + integer*2 id2(NZMAX) + real*4 dd(NZMAX) + character*80 infile + character(len=500) optarg + character*12 mycall,hiscall + character*6 hisgrid + + type (option) :: long_options(12) = [ & + option ('aggressive',.true.,'a','aggressiveness [0-10], default AGGR=0','AGGR'), & + option ('depth',.true.,'d','depth=5 hinted decoding, default DEPTH=0','DEPTH'), & + option ('freq',.true.,'f','signal frequency, default FREQ=1270','FREQ'), & + option ('help',.false.,'h','Display this help message',''), & + option ('mode',.true.,'m','Mode A, B, C. Default is A.','MODE'), & + option ('ntrials',.true.,'n','number of trials, default TRIALS=10000','TRIALS'), & + option ('robust-sync',.false.,'r','robust sync',''), & + option ('my-call',.true.,'c','my callsign',''), & + option ('his-call',.true.,'x','his callsign',''), & + option ('his-grid',.true.,'g','his grid locator',''), & + option ('experience-decoding',.true.,'X' & + ,'experience decoding options (1..n), default FLAGS=0','FLAGS'), & + option ('single-signal-mode',.false.,'s','decode at signal frequency only','') ] + + naggressive=10 + nfqso=1500 + ntrials=100000 + nexp_decode=0 + ntol=20 + nsubmode=0 + nlow=200 + nhigh=4000 + n2pass=1 + ndepth=1 + nQSOProgress=6 + + do + call getopt('a:d:f:hm:n:rc:x:g:X:s',long_options,c,optarg,narglen,nstat,noffset,nremain,.true.) + if( nstat .ne. 0 ) then + exit + end if + select case (c) + case ('a') + read (optarg(:narglen), *) naggressive + case ('d') + read (optarg(:narglen), *) ndepth + case ('f') + read (optarg(:narglen), *) nfqso + case ('h') + display_help = .true. + case ('m') + read (optarg(:narglen), *) mode + if( mode .eq. 'b' .or. mode .eq. 'B' ) then + nsubmode=1 + endif + if( mode .eq. 'c' .or. mode .eq. 'C' ) then + nsubmode=2 + endif + case ('n') + read (optarg(:narglen), *) ntrials + case ('r') + nrobust=.true. + case ('c') + read (optarg(:narglen), *) mycall + case ('x') + read (optarg(:narglen), *) hiscall + case ('g') + read (optarg(:narglen), *) hisgrid + case ('X') + read (optarg(:narglen), *) nexp_decode + case ('s') + single_decode=.true. + ntol=100 + nlow=nfqso-ntol + nhigh=nfqso+ntol + n2pass=1 + end select + end do + + if(single_decode) nexp_decode=ior(nexp_decode,32) + if(display_help .or. nstat.lt.0 .or. nremain.lt.1) then + print *, '' + print *, 'Usage: jt65 [OPTIONS] file1 [file2 ...]' + print *, '' + print *, ' JT65 decode pre-recorded .WAV file(s)' + print *, '' + print *, 'OPTIONS:' + print *, '' + do i = 1, size (long_options) + call long_options(i) % print (6) + end do + go to 999 + endif + + call init_timer ('timer.out') + call timer('jt65 ',0) + + ndecoded=0 + do ifile=noffset+1,noffset+nremain + nfa=nlow + nfb=nhigh + minsync=0 + call get_command_argument(ifile,optarg,narglen) + infile=optarg(:narglen) + call timer('read ',0) + call wav%read (infile) + i1=index(infile,'.wav') + if( i1 .eq. 0 ) i1=index(infile,'.WAV') + read(infile(i1-4:i1-1),*,err=998) nutc + npts=52*12000 + read(unit=wav%lun) id2(1:npts) + close(unit=wav%lun) + call timer('read ',1) + dd(1:npts)=id2(1:npts) + dd(npts+1:)=0. + call test(dd,nutc,nfa,nfb,nfqso,ntol,nsubmode, & + n2pass,nrobust,ntrials,naggressive,ndepth, & + mycall,hiscall,hisgrid,nexp_decode,nQSOProgress,ljt65apon) +! if(nft.gt.0) exit + enddo + + call timer('jt65 ',1) + call timer('jt65 ',101) + ! call four2a(a,-1,1,1,1) !Free the memory used for plans + ! call filbig(a,-1,1,0.0,0,0,0,0,0) ! (ditto) + go to 999 + +998 print*,'Cannot read from file:' + print*,infile + +999 continue +end program jt65 diff --git a/lib/jt65_decode.f90 b/lib/jt65_decode.f90 index c23ff8fe..4e73ee7b 100755 --- a/lib/jt65_decode.f90 +++ b/lib/jt65_decode.f90 @@ -1,522 +1,522 @@ -module jt65_decode - - integer, parameter :: NSZ=3413, NZMAX=60*12000 - - type :: jt65_decoder - procedure(jt65_decode_callback), pointer :: callback => null() - contains - procedure :: decode - end type jt65_decoder - -! Callback function to be called with each decode - abstract interface - subroutine jt65_decode_callback(this,sync,snr,dt,freq,drift, & - nflip,width,decoded,ft,qual,nsmo,nsum,minsync) - - import jt65_decoder - implicit none - class(jt65_decoder), intent(inout) :: this - real, intent(in) :: sync - integer, intent(in) :: snr - real, intent(in) :: dt - integer, intent(in) :: freq - integer, intent(in) :: drift - integer, intent(in) :: nflip - real, intent(in) :: width - character(len=22), intent(in) :: decoded - integer, intent(in) :: ft - integer, intent(in) :: qual - integer, intent(in) :: nsmo - integer, intent(in) :: nsum - integer, intent(in) :: minsync - - end subroutine jt65_decode_callback - end interface - -contains - - subroutine decode(this,callback,dd0,npts,newdat,nutc,nf1,nf2,nfqso, & - ntol,nsubmode,minsync,nagain,n2pass,nrobust,ntrials,naggressive, & - ndepth,emedelay,clearave,mycall,hiscall,hisgrid,nexp_decode, & - nQSOProgress,ljt65apon) - -! Process dd0() data to find and decode JT65 signals. - - use jt65_mod - use timer_module, only: timer - - include 'constants.f90' - - class(jt65_decoder), intent(inout) :: this - procedure(jt65_decode_callback) :: callback - real, intent(in) :: dd0(NZMAX),emedelay - integer, intent(in) :: npts, nutc, nf1, nf2, nfqso, ntol & - , nsubmode, minsync, n2pass, ntrials, naggressive, ndepth & - , nexp_decode, nQSOProgress - logical, intent(in) :: newdat, nagain, nrobust, clearave, ljt65apon - character(len=12), intent(in) :: mycall, hiscall - character(len=6), intent(in) :: hisgrid - - real dd(NZMAX) - real ss(552,NSZ) - real savg(NSZ) - real a(5) - character*22 decoded,decoded0,avemsg,deepave - type candidate - real freq - real dt - real sync - real flip - end type candidate - type(candidate) ca(300) - type accepted_decode - real freq - real dt - real sync - character*22 decoded - end type accepted_decode - type(accepted_decode) dec(50) - logical :: first_time,prtavg,single_decode,bVHF,clear_avg65 - - integer h0(0:11),d0(0:11) - real r0(0:11) - common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano - common/steve/thresh0 - common/sync/ss - -! 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 nutc0/-999/,nfreq0/-999/,nsave/0/,clear_avg65/.true./ - save - - this%callback => callback - first_time=nrobust .and. (emedelay.eq.-999.9) !Silence compiler warning - first_time=newdat - dd=dd0 - ndecoded=0 - ndecoded0=0 - single_decode=iand(nexp_decode,32).ne.0 .or. nagain - bVHF=iand(nexp_decode,64).ne.0 - - if(bVHF) then - nvec=ntrials - npass=1 - if(n2pass.gt.1) npass=2 - else - nvec=1000 - if(ndepth.eq.1) then - npass=2 - nvec=100 - elseif(ndepth.eq.2) then - npass=2 - nvec=1000 - else - npass=4 - nvec=1000 - endif - endif - do ipass=1,npass - first_time=.true. - if(ipass.eq.1) then !First-pass parameters - thresh0=2.5 - nsubtract=1 - nrob=0 - elseif( ipass.eq.2 ) then !Second-pass parameters - thresh0=2.0 - nsubtract=1 - nrob=0 - elseif( ipass.eq.3 ) then - thresh0=2.0 - nsubtract=1 - nrob=0 - elseif( ipass.eq.4 ) then - thresh0=2.0 - nsubtract=0 - nrob=1 - endif - if(npass.eq.1) then - nsubtract=0 - thresh0=2.0 - endif - - call timer('symsp65 ',0) - ss=0. - call symspec65(dd,npts,nqsym,savg) !Get normalized symbol spectra - call timer('symsp65 ',1) - nfa=nf1 - nfb=nf2 - -!### Q: should either of the next two uses of "single_decode" be "bVHF" instead? - if(single_decode .or. (bVHF .and. ntol.lt.1000)) then - nfa=max(200,nfqso-ntol) - nfb=min(4000,nfqso+ntol) - thresh0=1.0 - endif - df=12000.0/8192.0 !df = 1.465 Hz - if(bVHF) then - ia=max(1,nint((nfa-100)/df)) - ib=min(NSZ,nint((nfb+100)/df)) - nz=ib-ia+1 - if(nz.lt.50) go to 900 - if(isnan(sum(savg(ia:ia+nz-1)))) go to 900 - call lorentzian(savg(ia),nz,a) - baseline=a(1) - amp=a(2) - f0=(a(3)+ia-1)*df - width=a(4)*df - endif - - ncand=0 - call timer('sync65 ',0) - call sync65(nfa,nfb,ntol,nqsym,ca,ncand,nrob,bVHF) - ncand=min(ncand,50/ipass) - call timer('sync65 ',1) - - mode65=2**nsubmode - nflip=1 - nqd=0 - decoded=' ' - decoded0="" - freq0=0. - prtavg=.false. - if(.not.nagain) nsum=0 - if(clearave) then - nsum=0 - nsave=0 - clear_avg65=.true. - endif - - if(bVHF) then -! Be sure to search for shorthand message at nfqso +/- ntol - if(ncand.lt.300) ncand=ncand+1 - ca(ncand)%sync=5.0 - ca(ncand)%dt=2.5 - ca(ncand)%freq=nfqso - ca(ncand)%flip=0 - endif - do icand=1,ncand - sync1=ca(icand)%sync - dtx=ca(icand)%dt - freq=ca(icand)%freq - if(bVHF) then - flip=ca(icand)%flip - nflip=int(flip) - endif - if(sync1.lt.float(minsync)) nflip=0 - if(ipass.eq.1) ntry65a=ntry65a + 1 - if(ipass.eq.2) ntry65b=ntry65b + 1 - call timer('decod65a',0) - nft=0 - nspecial=0 - call decode65a(dd,npts,first_time,nqd,freq,nflip,mode65,nvec, & - naggressive,ndepth,ntol,mycall,hiscall,hisgrid,nQSOProgress, & - ljt65apon,bVHF,sync2,a,dtx,nft,nspecial,qual, & - nhist,nsmo,decoded) - call timer('decod65a',1) - - if(.not.bVHF) then - if(abs(a(1)).gt.10.0/ipass) cycle - ibad=0 - if(abs(a(1)).gt.5.0) ibad=1 - if(abs(a(2)).gt.2.0) ibad=ibad+1 - if(abs(dtx-1.0).gt.2.5) ibad=ibad+1 - if(ibad.ge.2) cycle - endif - - if(nspecial.eq.0 .and. sync1.eq.5.0 .and. dtx.eq.2.5) cycle - if(nspecial.eq.2) decoded='RO' - if(nspecial.eq.3) decoded='RRR' - if(nspecial.eq.4) decoded='73' - if(sync1.lt.float(minsync) .and. & - decoded.eq.' ') nflip=0 - if(nft.ne.0) nsum=1 - - nhard_min=param(1) - nrtt1000=param(4) - ntotal_min=param(5) - nsmo=param(9) - - nfreq=nint(freq+a(1)) - ndrift=nint(2.0*a(2)) - if(bVHF) then - xtmp=10**((sync1+16.0)/10.0) ! sync comes to us in dB - s2db=1.1*db(xtmp)+1.4*(dB(width)-4.3)-52.0 -! s2db=sync1 - 30.0 + db(width/3.3) !### VHF/UHF/microwave - if(nspecial.gt.0) s2db=sync2 - else - s2db=10.0*log10(sync2) - 35 !### Empirical (HF) - endif - nsnr=nint(s2db) - if(nsnr.lt.-30) nsnr=-30 - if(nsnr.gt.-1) nsnr=-1 - nftt=0 -!********* DOES THIS STILL WORK WHEN NFT INCLUDES # OF AP SYMBOLS USED?? - if(nft.ne.1 .and. iand(ndepth,16).eq.16 .and. & - sync1.ge.float(minsync) .and. (.not.prtavg)) then -! Single-sequence FT decode failed, so try for an average FT decode. - if(nutc.ne.nutc0 .or. abs(nfreq-nfreq0).gt.ntol) then -! This is a new minute or a new frequency, so call avg65. - nutc0=nutc - nfreq0=nfreq - nsave=nsave+1 - nsave=mod(nsave-1,64)+1 - call avg65(nutc,nsave,sync1,dtx,nflip,nfreq,mode65,ntol, & - ndepth,nagain,ntrials,naggressive,clear_avg65,neme, & - mycall,hiscall,hisgrid,nftt,avemsg,qave,deepave,nsum, & - ndeepave,nQSOProgress,ljt65apon) - nsmo=param(9) - nqave=int(qave) - - if (associated(this%callback) .and.nftt.ge.1 .and. nsum.ge.2) then -! Display a decoded message obtained by averaging 2 or more transmissions - call this%callback(sync1,nsnr,dtx-1.0,nfreq,ndrift, & - nflip,width,avemsg,nftt,nqave,nsmo,nsum,minsync) - prtavg=.true. - end if - - endif - endif - - if(nftt.eq.0) go to 5 -! if(nftt.eq.1) then -!! nft=1 -! decoded=avemsg -! go to 5 -! endif - n=naggressive - rtt=0.001*nrtt1000 - if(nft.lt.2 .and. minsync.ge.0 .and. nspecial.eq.0 .and. .not.bVHF) then - if(nhard_min.gt.50) cycle - if(nhard_min.gt.h0(n)) cycle - if(ntotal_min.gt.d0(n)) cycle - if(rtt.gt.r0(n)) cycle - endif - -5 continue - if(decoded.eq.decoded0 .and. abs(freq-freq0).lt. 3.0 .and. & - minsync.ge.0) cycle !Don't display dupes -! if(decoded.ne.' ' .or. minsync.lt.0) then - if(decoded.ne.' ' .or. bVHF) then - if(nsubtract.eq.1) then - call timer('subtr65 ',0) - call subtract65(dd,npts,freq,dtx) - call timer('subtr65 ',1) - endif - - ndupe=0 ! de-dedupe - do i=1, ndecoded - if(decoded==dec(i)%decoded) then - ndupe=1 - exit - endif - enddo - if(ndupe.ne.1 .and. ((sync1.ge.float(minsync)) .or. bVHF)) then - if(ipass.eq.1) n65a=n65a + 1 - if(ipass.eq.2) n65b=n65b + 1 - if(ndecoded.lt.50) ndecoded=ndecoded+1 - dec(ndecoded)%freq=freq+a(1) - dec(ndecoded)%dt=dtx - dec(ndecoded)%sync=sync2 - dec(ndecoded)%decoded=decoded - nqual=min(int(qual),9999) - - if(associated(this%callback)) then - call this%callback(sync1,nsnr,dtx-1.0,nfreq,ndrift, & - nflip,width,decoded,nft,nqual,nsmo,1,minsync) - end if - endif - decoded0=decoded - freq0=freq - if(decoded0.eq.' ') decoded0='*' - if(single_decode .and. ndecoded.gt.0) go to 900 - endif - enddo ! icand - if(ipass.gt.1 .and. ndecoded.eq.ndecoded0) exit - ndecoded0=ndecoded - enddo ! ipass -900 return - end subroutine decode - - subroutine avg65(nutc,nsave,snrsync,dtxx,nflip,nfreq,mode65,ntol,ndepth, & - nagain, ntrials,naggressive,clear_avg65,neme,mycall,hiscall,hisgrid, & - nftt,avemsg,qave,deepave,nsum,ndeepave,nQSOProgress,ljt65apon) - -! Decodes averaged JT65 data - - use jt65_mod - parameter (MAXAVE=64) - character*22 avemsg,deepave,deepbest - character mycall*12,hiscall*12,hisgrid*6 - character*1 csync,cused(64) - logical nagain - integer iused(64) -! Accumulated data for message averaging - integer iutc(MAXAVE) - integer nfsave(MAXAVE) - integer nflipsave(MAXAVE) - real s1b(-255:256,126) - real s1save(-255:256,126,MAXAVE) - real s2(66,126) - real s3save(64,63,MAXAVE) - real s3b(64,63) - real s3c(64,63) - real dtsave(MAXAVE) - real syncsave(MAXAVE) - logical first,clear_avg65,ljt65apon - data first/.true./ - save - - if(first .or. clear_avg65) then - iutc=-1 - nfsave=0 - dtdiff=0.2 - s3save=0. - s1save=0. - nsave=1 !### ??? -! Silence compiler warnings - if(nagain .and. ndeepave.eq.-99 .and. neme.eq.-99) stop - first=.false. - clear_avg65=.false. - endif - - do i=1,64 - if(iutc(i).lt.0) exit - if(nutc.eq.iutc(i) .and. abs(nfreq-nfsave(i)).le.ntol) go to 10 - enddo - -! Save data for message averaging - iutc(nsave)=nutc - syncsave(nsave)=snrsync - dtsave(nsave)=dtxx - nfsave(nsave)=nfreq - nflipsave(nsave)=nflip - s1save(-255:256,1:126,nsave)=s1 - s3save(1:64,1:63,nsave)=s3a - avemsg=' ' - deepbest=' ' - nfttbest=0 - -10 syncsum=0. - dtsum=0. - nfsum=0 - nsum=0 - s1b=0. - s3b=0. - s3c=0. - - do i=1,MAXAVE !Consider all saved spectra - cused(i)='.' - if(iutc(i).lt.0) exit - if(mod(iutc(i),2).ne.mod(nutc,2)) cycle !Use only same (odd/even) seq - if(abs(dtxx-dtsave(i)).gt.dtdiff) cycle !DT must match - if(abs(nfreq-nfsave(i)).gt.ntol) cycle !Freq must match - if(nflipsave(i).eq.0) cycle !No sync - if(nflip.ne.nflipsave(i)) cycle !Sync type (*/#) must match - - s3b=s3b + s3save(1:64,1:63,i) - s1b=s1b + s1save(-255:256,1:126,i) - syncsum=syncsum + syncsave(i) - dtsum=dtsum + dtsave(i) - nfsum=nfsum + nfsave(i) - cused(i)='$' - nsum=nsum+1 - iused(nsum)=i - enddo - if(nsum.lt.64) iused(nsum+1)=0 - - syncave=0. - dtave=0. - fave=0. - if(nsum.gt.0) then - syncave=syncsum/nsum - dtave=dtsum/nsum - fave=float(nfsum)/nsum - endif - - do i=1,nsave - csync=' ' - if(nflipsave(i).lt.0.0) csync='#' - if(nflipsave(i).gt.0.0) csync='*' - write(14,1000) cused(i),iutc(i),syncsave(i),dtsave(i)-1.0,nfsave(i),csync -1000 format(a1,i5.4,f6.1,f6.2,i6,1x,a1) - enddo - if(nsum.lt.2) go to 900 - - df=1378.125/512.0 - -! Do the smoothing loop - qualbest=0. - minsmo=0 - maxsmo=0 - if(mode65.ge.2) then - minsmo=nint(width/df) - maxsmo=2*minsmo - endif - nn=0 - do ismo=minsmo,maxsmo - nftt=0 - if(ismo.gt.0) then - do j=1,126 - call smo121(s1b(-255,j),512) - if(j.eq.1) nn=nn+1 - if(nn.ge.4) then - call smo121(s1b(-255,j),512) - if(j.eq.1) nn=nn+1 - endif - enddo - endif - - do i=1,66 - jj=i - if(mode65.eq.2) jj=2*i-1 - if(mode65.eq.4) then - ff=4*(i-1)*df - 355.297852 - jj=nint(ff/df)+1 - endif - s2(i,1:126)=s1b(jj,1:126) - enddo - - do j=1,63 - k=mdat(j) !Points to data symbol - if(nflip.lt.0) k=mdat2(j) - do i=1,64 - s3c(i,j)=4.e-5*s2(i+2,k) - enddo - enddo - - nadd=nsum*ismo - call extract(s3c,nadd,mode65,ntrials,naggressive,ndepth,nflip,mycall, & - hiscall,hisgrid,nQSOProgress,ljt65apon,ncount,nhist, & - avemsg,ltext,nftt,qual) - if(nftt.eq.1) then - nsmo=ismo - param(9)=nsmo - go to 900 - else if(nftt.ge.2) then - if(qual.gt.qualbest) then - deepbest=avemsg - qualbest=qual - nnbest=nn - nsmobest=ismo - nfttbest=nftt - endif - endif - enddo - if(nfttbest.eq.2) then - avemsg=deepbest !### ??? - deepave=deepbest - qave=qualbest - nsmo=nsmobest - param(9)=nsmo - nftt=nfttbest - endif -900 continue - - return - end subroutine avg65 - -end module jt65_decode +module jt65_decode + + integer, parameter :: NSZ=3413, NZMAX=60*12000 + + type :: jt65_decoder + procedure(jt65_decode_callback), pointer :: callback => null() + contains + procedure :: decode + end type jt65_decoder + +! Callback function to be called with each decode + abstract interface + subroutine jt65_decode_callback(this,sync,snr,dt,freq,drift, & + nflip,width,decoded,ft,qual,nsmo,nsum,minsync) + + import jt65_decoder + implicit none + class(jt65_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + integer, intent(in) :: freq + integer, intent(in) :: drift + integer, intent(in) :: nflip + real, intent(in) :: width + character(len=22), intent(in) :: decoded + integer, intent(in) :: ft + integer, intent(in) :: qual + integer, intent(in) :: nsmo + integer, intent(in) :: nsum + integer, intent(in) :: minsync + + end subroutine jt65_decode_callback + end interface + +contains + + subroutine decode(this,callback,dd0,npts,newdat,nutc,nf1,nf2,nfqso, & + ntol,nsubmode,minsync,nagain,n2pass,nrobust,ntrials,naggressive, & + ndepth,emedelay,clearave,mycall,hiscall,hisgrid,nexp_decode, & + nQSOProgress,ljt65apon) + +! Process dd0() data to find and decode JT65 signals. + + use jt65_mod + use timer_module, only: timer + + include 'constants.f90' + + class(jt65_decoder), intent(inout) :: this + procedure(jt65_decode_callback) :: callback + real, intent(in) :: dd0(NZMAX),emedelay + integer, intent(in) :: npts, nutc, nf1, nf2, nfqso, ntol & + , nsubmode, minsync, n2pass, ntrials, naggressive, ndepth & + , nexp_decode, nQSOProgress + logical, intent(in) :: newdat, nagain, nrobust, clearave, ljt65apon + character(len=12), intent(in) :: mycall, hiscall + character(len=6), intent(in) :: hisgrid + + real dd(NZMAX) + real ss(552,NSZ) + real savg(NSZ) + real a(5) + character*22 decoded,decoded0,avemsg,deepave + type candidate + real freq + real dt + real sync + real flip + end type candidate + type(candidate) ca(300) + type accepted_decode + real freq + real dt + real sync + character*22 decoded + end type accepted_decode + type(accepted_decode) dec(50) + logical :: first_time,prtavg,single_decode,bVHF,clear_avg65 + + integer h0(0:11),d0(0:11) + real r0(0:11) + common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano + common/steve/thresh0 + common/sync/ss + +! 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 nutc0/-999/,nfreq0/-999/,nsave/0/,clear_avg65/.true./ + save + + this%callback => callback + first_time=nrobust .and. (emedelay.eq.-999.9) !Silence compiler warning + first_time=newdat + dd=dd0 + ndecoded=0 + ndecoded0=0 + single_decode=iand(nexp_decode,32).ne.0 .or. nagain + bVHF=iand(nexp_decode,64).ne.0 + + if(bVHF) then + nvec=ntrials + npass=1 + if(n2pass.gt.1) npass=2 + else + nvec=1000 + if(ndepth.eq.1) then + npass=2 + nvec=100 + elseif(ndepth.eq.2) then + npass=2 + nvec=1000 + else + npass=4 + nvec=1000 + endif + endif + do ipass=1,npass + first_time=.true. + if(ipass.eq.1) then !First-pass parameters + thresh0=2.5 + nsubtract=1 + nrob=0 + elseif( ipass.eq.2 ) then !Second-pass parameters + thresh0=2.0 + nsubtract=1 + nrob=0 + elseif( ipass.eq.3 ) then + thresh0=2.0 + nsubtract=1 + nrob=0 + elseif( ipass.eq.4 ) then + thresh0=2.0 + nsubtract=0 + nrob=1 + endif + if(npass.eq.1) then + nsubtract=0 + thresh0=2.0 + endif + + call timer('symsp65 ',0) + ss=0. + call symspec65(dd,npts,nqsym,savg) !Get normalized symbol spectra + call timer('symsp65 ',1) + nfa=nf1 + nfb=nf2 + +!### Q: should either of the next two uses of "single_decode" be "bVHF" instead? + if(single_decode .or. (bVHF .and. ntol.lt.1000)) then + nfa=max(200,nfqso-ntol) + nfb=min(4000,nfqso+ntol) + thresh0=1.0 + endif + df=12000.0/8192.0 !df = 1.465 Hz + if(bVHF) then + ia=max(1,nint((nfa-100)/df)) + ib=min(NSZ,nint((nfb+100)/df)) + nz=ib-ia+1 + if(nz.lt.50) go to 900 + if(isnan(sum(savg(ia:ia+nz-1)))) go to 900 + call lorentzian(savg(ia),nz,a) + baseline=a(1) + amp=a(2) + f0=(a(3)+ia-1)*df + width=a(4)*df + endif + + ncand=0 + call timer('sync65 ',0) + call sync65(nfa,nfb,ntol,nqsym,ca,ncand,nrob,bVHF) + ncand=min(ncand,50/ipass) + call timer('sync65 ',1) + + mode65=2**nsubmode + nflip=1 + nqd=0 + decoded=' ' + decoded0="" + freq0=0. + prtavg=.false. + if(.not.nagain) nsum=0 + if(clearave) then + nsum=0 + nsave=0 + clear_avg65=.true. + endif + + if(bVHF) then +! Be sure to search for shorthand message at nfqso +/- ntol + if(ncand.lt.300) ncand=ncand+1 + ca(ncand)%sync=5.0 + ca(ncand)%dt=2.5 + ca(ncand)%freq=nfqso + ca(ncand)%flip=0 + endif + do icand=1,ncand + sync1=ca(icand)%sync + dtx=ca(icand)%dt + freq=ca(icand)%freq + if(bVHF) then + flip=ca(icand)%flip + nflip=int(flip) + endif + if(sync1.lt.float(minsync)) nflip=0 + if(ipass.eq.1) ntry65a=ntry65a + 1 + if(ipass.eq.2) ntry65b=ntry65b + 1 + call timer('decod65a',0) + nft=0 + nspecial=0 + call decode65a(dd,npts,first_time,nqd,freq,nflip,mode65,nvec, & + naggressive,ndepth,ntol,mycall,hiscall,hisgrid,nQSOProgress, & + ljt65apon,bVHF,sync2,a,dtx,nft,nspecial,qual, & + nhist,nsmo,decoded) + call timer('decod65a',1) + + if(.not.bVHF) then + if(abs(a(1)).gt.10.0/ipass) cycle + ibad=0 + if(abs(a(1)).gt.5.0) ibad=1 + if(abs(a(2)).gt.2.0) ibad=ibad+1 + if(abs(dtx-1.0).gt.2.5) ibad=ibad+1 + if(ibad.ge.2) cycle + endif + + if(nspecial.eq.0 .and. sync1.eq.5.0 .and. dtx.eq.2.5) cycle + if(nspecial.eq.2) decoded='RO' + if(nspecial.eq.3) decoded='RRR' + if(nspecial.eq.4) decoded='73' + if(sync1.lt.float(minsync) .and. & + decoded.eq.' ') nflip=0 + if(nft.ne.0) nsum=1 + + nhard_min=param(1) + nrtt1000=param(4) + ntotal_min=param(5) + nsmo=param(9) + + nfreq=nint(freq+a(1)) + ndrift=nint(2.0*a(2)) + if(bVHF) then + xtmp=10**((sync1+16.0)/10.0) ! sync comes to us in dB + s2db=1.1*db(xtmp)+1.4*(dB(width)-4.3)-52.0 +! s2db=sync1 - 30.0 + db(width/3.3) !### VHF/UHF/microwave + if(nspecial.gt.0) s2db=sync2 + else + s2db=10.0*log10(sync2) - 35 !### Empirical (HF) + endif + nsnr=nint(s2db) + if(nsnr.lt.-30) nsnr=-30 + if(nsnr.gt.-1) nsnr=-1 + nftt=0 +!********* DOES THIS STILL WORK WHEN NFT INCLUDES # OF AP SYMBOLS USED?? + if(nft.ne.1 .and. iand(ndepth,16).eq.16 .and. & + sync1.ge.float(minsync) .and. (.not.prtavg)) then +! Single-sequence FT decode failed, so try for an average FT decode. + if(nutc.ne.nutc0 .or. abs(nfreq-nfreq0).gt.ntol) then +! This is a new minute or a new frequency, so call avg65. + nutc0=nutc + nfreq0=nfreq + nsave=nsave+1 + nsave=mod(nsave-1,64)+1 + call avg65(nutc,nsave,sync1,dtx,nflip,nfreq,mode65,ntol, & + ndepth,nagain,ntrials,naggressive,clear_avg65,neme, & + mycall,hiscall,hisgrid,nftt,avemsg,qave,deepave,nsum, & + ndeepave,nQSOProgress,ljt65apon) + nsmo=param(9) + nqave=int(qave) + + if (associated(this%callback) .and.nftt.ge.1 .and. nsum.ge.2) then +! Display a decoded message obtained by averaging 2 or more transmissions + call this%callback(sync1,nsnr,dtx-1.0,nfreq,ndrift, & + nflip,width,avemsg,nftt,nqave,nsmo,nsum,minsync) + prtavg=.true. + end if + + endif + endif + + if(nftt.eq.0) go to 5 +! if(nftt.eq.1) then +!! nft=1 +! decoded=avemsg +! go to 5 +! endif + n=naggressive + rtt=0.001*nrtt1000 + if(nft.lt.2 .and. minsync.ge.0 .and. nspecial.eq.0 .and. .not.bVHF) then + if(nhard_min.gt.50) cycle + if(nhard_min.gt.h0(n)) cycle + if(ntotal_min.gt.d0(n)) cycle + if(rtt.gt.r0(n)) cycle + endif + +5 continue + if(decoded.eq.decoded0 .and. abs(freq-freq0).lt. 3.0 .and. & + minsync.ge.0) cycle !Don't display dupes +! if(decoded.ne.' ' .or. minsync.lt.0) then + if(decoded.ne.' ' .or. bVHF) then + if(nsubtract.eq.1) then + call timer('subtr65 ',0) + call subtract65(dd,npts,freq,dtx) + call timer('subtr65 ',1) + endif + + ndupe=0 ! de-dedupe + do i=1, ndecoded + if(decoded==dec(i)%decoded) then + ndupe=1 + exit + endif + enddo + if(ndupe.ne.1 .and. ((sync1.ge.float(minsync)) .or. bVHF)) then + if(ipass.eq.1) n65a=n65a + 1 + if(ipass.eq.2) n65b=n65b + 1 + if(ndecoded.lt.50) ndecoded=ndecoded+1 + dec(ndecoded)%freq=freq+a(1) + dec(ndecoded)%dt=dtx + dec(ndecoded)%sync=sync2 + dec(ndecoded)%decoded=decoded + nqual=min(int(qual),9999) + + if(associated(this%callback)) then + call this%callback(sync1,nsnr,dtx-1.0,nfreq,ndrift, & + nflip,width,decoded,nft,nqual,nsmo,1,minsync) + end if + endif + decoded0=decoded + freq0=freq + if(decoded0.eq.' ') decoded0='*' + if(single_decode .and. ndecoded.gt.0) go to 900 + endif + enddo ! icand + if(ipass.gt.1 .and. ndecoded.eq.ndecoded0) exit + ndecoded0=ndecoded + enddo ! ipass +900 return + end subroutine decode + + subroutine avg65(nutc,nsave,snrsync,dtxx,nflip,nfreq,mode65,ntol,ndepth, & + nagain, ntrials,naggressive,clear_avg65,neme,mycall,hiscall,hisgrid, & + nftt,avemsg,qave,deepave,nsum,ndeepave,nQSOProgress,ljt65apon) + +! Decodes averaged JT65 data + + use jt65_mod + parameter (MAXAVE=64) + character*22 avemsg,deepave,deepbest + character mycall*12,hiscall*12,hisgrid*6 + character*1 csync,cused(64) + logical nagain + integer iused(64) +! Accumulated data for message averaging + integer iutc(MAXAVE) + integer nfsave(MAXAVE) + integer nflipsave(MAXAVE) + real s1b(-255:256,126) + real s1save(-255:256,126,MAXAVE) + real s2(66,126) + real s3save(64,63,MAXAVE) + real s3b(64,63) + real s3c(64,63) + real dtsave(MAXAVE) + real syncsave(MAXAVE) + logical first,clear_avg65,ljt65apon + data first/.true./ + save + + if(first .or. clear_avg65) then + iutc=-1 + nfsave=0 + dtdiff=0.2 + s3save=0. + s1save=0. + nsave=1 !### ??? +! Silence compiler warnings + if(nagain .and. ndeepave.eq.-99 .and. neme.eq.-99) stop + first=.false. + clear_avg65=.false. + endif + + do i=1,64 + if(iutc(i).lt.0) exit + if(nutc.eq.iutc(i) .and. abs(nfreq-nfsave(i)).le.ntol) go to 10 + enddo + +! Save data for message averaging + iutc(nsave)=nutc + syncsave(nsave)=snrsync + dtsave(nsave)=dtxx + nfsave(nsave)=nfreq + nflipsave(nsave)=nflip + s1save(-255:256,1:126,nsave)=s1 + s3save(1:64,1:63,nsave)=s3a + avemsg=' ' + deepbest=' ' + nfttbest=0 + +10 syncsum=0. + dtsum=0. + nfsum=0 + nsum=0 + s1b=0. + s3b=0. + s3c=0. + + do i=1,MAXAVE !Consider all saved spectra + cused(i)='.' + if(iutc(i).lt.0) exit + if(mod(iutc(i),2).ne.mod(nutc,2)) cycle !Use only same (odd/even) seq + if(abs(dtxx-dtsave(i)).gt.dtdiff) cycle !DT must match + if(abs(nfreq-nfsave(i)).gt.ntol) cycle !Freq must match + if(nflipsave(i).eq.0) cycle !No sync + if(nflip.ne.nflipsave(i)) cycle !Sync type (*/#) must match + + s3b=s3b + s3save(1:64,1:63,i) + s1b=s1b + s1save(-255:256,1:126,i) + syncsum=syncsum + syncsave(i) + dtsum=dtsum + dtsave(i) + nfsum=nfsum + nfsave(i) + cused(i)='$' + nsum=nsum+1 + iused(nsum)=i + enddo + if(nsum.lt.64) iused(nsum+1)=0 + + syncave=0. + dtave=0. + fave=0. + if(nsum.gt.0) then + syncave=syncsum/nsum + dtave=dtsum/nsum + fave=float(nfsum)/nsum + endif + + do i=1,nsave + csync=' ' + if(nflipsave(i).lt.0.0) csync='#' + if(nflipsave(i).gt.0.0) csync='*' + write(14,1000) cused(i),iutc(i),syncsave(i),dtsave(i)-1.0,nfsave(i),csync +1000 format(a1,i5.4,f6.1,f6.2,i6,1x,a1) + enddo + if(nsum.lt.2) go to 900 + + df=1378.125/512.0 + +! Do the smoothing loop + qualbest=0. + minsmo=0 + maxsmo=0 + if(mode65.ge.2) then + minsmo=nint(width/df) + maxsmo=2*minsmo + endif + nn=0 + do ismo=minsmo,maxsmo + nftt=0 + if(ismo.gt.0) then + do j=1,126 + call smo121(s1b(-255,j),512) + if(j.eq.1) nn=nn+1 + if(nn.ge.4) then + call smo121(s1b(-255,j),512) + if(j.eq.1) nn=nn+1 + endif + enddo + endif + + do i=1,66 + jj=i + if(mode65.eq.2) jj=2*i-1 + if(mode65.eq.4) then + ff=4*(i-1)*df - 355.297852 + jj=nint(ff/df)+1 + endif + s2(i,1:126)=s1b(jj,1:126) + enddo + + do j=1,63 + k=mdat(j) !Points to data symbol + if(nflip.lt.0) k=mdat2(j) + do i=1,64 + s3c(i,j)=4.e-5*s2(i+2,k) + enddo + enddo + + nadd=nsum*ismo + call extract(s3c,nadd,mode65,ntrials,naggressive,ndepth,nflip,mycall, & + hiscall,hisgrid,nQSOProgress,ljt65apon,ncount,nhist, & + avemsg,ltext,nftt,qual) + if(nftt.eq.1) then + nsmo=ismo + param(9)=nsmo + go to 900 + else if(nftt.ge.2) then + if(qual.gt.qualbest) then + deepbest=avemsg + qualbest=qual + nnbest=nn + nsmobest=ismo + nfttbest=nftt + endif + endif + enddo + if(nfttbest.eq.2) then + avemsg=deepbest !### ??? + deepave=deepbest + qave=qualbest + nsmo=nsmobest + param(9)=nsmo + nftt=nfttbest + endif +900 continue + + return + end subroutine avg65 + +end module jt65_decode diff --git a/lib/jt65_test.f90 b/lib/jt65_test.f90 index 1802a636..d6a80a2e 100755 --- a/lib/jt65_test.f90 +++ b/lib/jt65_test.f90 @@ -1,78 +1,78 @@ -module jt65_test - - ! Test the JT65 decoder for WSJT-X - - implicit none - - public :: test - integer, parameter, public :: NZMAX=60*12000 - integer, public :: nft - -contains - - subroutine test (dd,nutc,nflow,nfhigh,nfqso,ntol,nsubmode,n2pass,nrobust & - ,ntrials,naggressive,ndepth,mycall,hiscall,hisgrid,nexp_decode, & - nQSOProgress,ljt65apon) - use timer_module, only: timer - use jt65_decode - implicit none - - include 'constants.f90' - real, intent(in) :: dd(NZMAX) - integer, intent(in) :: nutc, nflow, nfhigh, nfqso, ntol, nsubmode, n2pass & - , ntrials, naggressive, ndepth, nexp_decode, nQSOProgress - logical, intent(in) :: nrobust,ljt65apon - character(len=12), intent(in) :: mycall, hiscall - character(len=6), intent(in) :: hisgrid - type(jt65_decoder) :: my_decoder - logical nclearave !### Should be a dummy arg? - nclearave=.false. - - call timer('jt65a ',0) - call my_decoder%decode(my_callback,dd,npts=52*12000,newdat=.true., & - nutc=nutc,nf1=nflow,nf2=nfhigh,nfqso=nfqso,ntol=ntol, & - nsubmode=nsubmode, minsync=-1,nagain=.false.,n2pass=n2pass, & - nrobust=nrobust,ntrials=ntrials,naggressive=naggressive, & - ndepth=ndepth,emedelay=0.0,clearave=nclearave,mycall=mycall, & - hiscall=hiscall,hisgrid=hisgrid,nexp_decode=nexp_decode, & - nQSOProgress=nQSOProgress,ljt65apon=ljt65apon) - call timer('jt65a ',1) - end subroutine test - - subroutine my_callback (this,sync,snr,dt,freq,drift,nflip,width, & - decoded,ft,qual,smo,sum,minsync) - use jt65_decode - implicit none - - class(jt65_decoder), intent(inout) :: this - real, intent(in) :: sync - integer, intent(in) :: snr - real, intent(in) :: dt - integer, intent(in) :: freq - integer, intent(in) :: drift - integer, intent(in) :: nflip - real, intent(in) :: width - character(len=22), intent(in) :: decoded - integer, intent(in) :: ft - integer, intent(in) :: qual - integer, intent(in) :: smo - integer, intent(in) :: sum - integer, intent(in) :: minsync - - integer nwidth - real t - - if(minsync+nflip+qual.eq.-9999) stop !Silence compiler warning - t=max(0.0,width*width-7.2) - nwidth=max(nint(sqrt(t)),2) -!### deal with nflip here! ### -!### also single_decode, csync, etc... ### - write(*,1012) nint(sync),snr,dt,freq,drift,nwidth, & - decoded,ft,sum,smo -1012 format(i4,i5,f6.2,i5,i4,i3,1x,a22,' JT65',3i3) - nft=ft - call flush(6) - - end subroutine my_callback - -end module jt65_test +module jt65_test + + ! Test the JT65 decoder for WSJT-X + + implicit none + + public :: test + integer, parameter, public :: NZMAX=60*12000 + integer, public :: nft + +contains + + subroutine test (dd,nutc,nflow,nfhigh,nfqso,ntol,nsubmode,n2pass,nrobust & + ,ntrials,naggressive,ndepth,mycall,hiscall,hisgrid,nexp_decode, & + nQSOProgress,ljt65apon) + use timer_module, only: timer + use jt65_decode + implicit none + + include 'constants.f90' + real, intent(in) :: dd(NZMAX) + integer, intent(in) :: nutc, nflow, nfhigh, nfqso, ntol, nsubmode, n2pass & + , ntrials, naggressive, ndepth, nexp_decode, nQSOProgress + logical, intent(in) :: nrobust,ljt65apon + character(len=12), intent(in) :: mycall, hiscall + character(len=6), intent(in) :: hisgrid + type(jt65_decoder) :: my_decoder + logical nclearave !### Should be a dummy arg? + nclearave=.false. + + call timer('jt65a ',0) + call my_decoder%decode(my_callback,dd,npts=52*12000,newdat=.true., & + nutc=nutc,nf1=nflow,nf2=nfhigh,nfqso=nfqso,ntol=ntol, & + nsubmode=nsubmode, minsync=-1,nagain=.false.,n2pass=n2pass, & + nrobust=nrobust,ntrials=ntrials,naggressive=naggressive, & + ndepth=ndepth,emedelay=0.0,clearave=nclearave,mycall=mycall, & + hiscall=hiscall,hisgrid=hisgrid,nexp_decode=nexp_decode, & + nQSOProgress=nQSOProgress,ljt65apon=ljt65apon) + call timer('jt65a ',1) + end subroutine test + + subroutine my_callback (this,sync,snr,dt,freq,drift,nflip,width, & + decoded,ft,qual,smo,sum,minsync) + use jt65_decode + implicit none + + class(jt65_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + integer, intent(in) :: freq + integer, intent(in) :: drift + integer, intent(in) :: nflip + real, intent(in) :: width + character(len=22), intent(in) :: decoded + integer, intent(in) :: ft + integer, intent(in) :: qual + integer, intent(in) :: smo + integer, intent(in) :: sum + integer, intent(in) :: minsync + + integer nwidth + real t + + if(minsync+nflip+qual.eq.-9999) stop !Silence compiler warning + t=max(0.0,width*width-7.2) + nwidth=max(nint(sqrt(t)),2) +!### deal with nflip here! ### +!### also single_decode, csync, etc... ### + write(*,1012) nint(sync),snr,dt,freq,drift,nwidth, & + decoded,ft,sum,smo +1012 format(i4,i5,f6.2,i5,i4,i3,1x,a22,' JT65',3i3) + nft=ft + call flush(6) + + end subroutine my_callback + +end module jt65_test diff --git a/lib/jt65code.f90 b/lib/jt65code.f90 index 1d7070bd..d3dac07d 100755 --- a/lib/jt65code.f90 +++ b/lib/jt65code.f90 @@ -1,103 +1,103 @@ -program JT65code - -! Provides examples of message packing, bit and symbol ordering, -! Reed Solomon encoding, and other necessary details of the JT65 -! protocol. - - use packjt - character*22 msg,msgchk,msg0,msg1,decoded,cok*3,bad*1,msgtype*10,expected - integer dgen(12),sent(63),tmp(63),recd(12),era(51) - include 'testmsg.f90' - - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: jt65code "message"' - print*,' jt65code -t' - go to 999 - endif - - call getarg(1,msg) !Get message from command line - msgchk=msg - call fmtmsg(msgchk,iz) - nmsg=1 - if(msg(1:2).eq."-t") then - if (NTEST+5 > MAXTEST) then - write(*,*) "NTEST exceed MAXTEST" - endif - testmsg(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" - testmsg(NTEST+2)="KA1ABC WB9XYZ OOO" - testmsg(NTEST+3)="RO" - testmsg(NTEST+4)="RRR" - testmsg(NTEST+5)="73" - testmsgchk(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" - testmsgchk(NTEST+2)="KA1ABC WB9XYZ OOO" - testmsgchk(NTEST+3)="RO" - testmsgchk(NTEST+4)="RRR" - testmsgchk(NTEST+5)="73" - nmsg=NTEST+5 - endif - - write(*,1010) -1010 format(" Message Decoded Err? Type Expected"/ & - 76("-")) - - do imsg=1,nmsg - if(nmsg.gt.1) then - msg=testmsg(imsg) - msgchk=testmsgchk(imsg) - endif - - call fmtmsg(msg,iz) !To upper, collapse mult blanks - msg0=msg !Input message - call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report - msg1=msg !Message without "OOO" - - if(nspecial.gt.0) then !or is a shorthand message - if(nspecial.eq.2) decoded="RO" - if(nspecial.eq.3) decoded="RRR" - if(nspecial.eq.4) decoded="73" - itype=-1 - msgtype="Shorthand" - go to 10 - endif - - call packmsg(msg1,dgen,itype) !Pack message into 12 six-bit bytes - msgtype="" - if(itype.eq.1) msgtype="Std Msg" - if(itype.eq.2) msgtype="Type 1 pfx" - if(itype.eq.3) msgtype="Type 1 sfx" - if(itype.eq.4) msgtype="Type 2 pfx" - if(itype.eq.5) msgtype="Type 2 sfx" - if(itype.eq.6) msgtype="Free text" - - call rs_encode(dgen,sent) !RS encode - call interleave63(sent,1) !Interleave channel symbols - call graycode(sent,63,1,sent) !Apply Gray code - - call graycode(sent,63,-1,tmp) !Remove Gray code - call interleave63(tmp,-1) !Remove interleaving - call rs_decode(tmp,era,0,recd,nerr) !Decode the message - call unpackmsg(recd,decoded) !Unpack the user message - if(cok.eq."OOO") decoded(20:22)=cok - call fmtmsg(decoded,iz) - -10 bad=" " - expected = 'EXACT' - if(decoded.ne.msg0) then - bad="*" - if(decoded(1:13).eq.msg0(1:13) .and. & - decoded(14:22).eq. ' ') expected = 'TRUNCATED' - endif - write(*,1020) imsg,msg0,decoded,bad,itype,msgtype,expected -1020 format(i2,'.',1x,a22,1x,a22,1x,a1,i3,":",a10,2x,a22) - enddo - - if(nmsg.eq.1 .and. nspecial.eq.0) then - write(*,1030) dgen -1030 format(/'Packed message, 6-bit symbols ',12i3) !Display packed symbols - - write(*,1040) sent -1040 format(/'Information-carrying channel symbols'/(i5,20i3)) - endif - -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. + + use packjt + character*22 msg,msgchk,msg0,msg1,decoded,cok*3,bad*1,msgtype*10,expected + integer dgen(12),sent(63),tmp(63),recd(12),era(51) + include 'testmsg.f90' + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: jt65code "message"' + print*,' jt65code -t' + go to 999 + endif + + call getarg(1,msg) !Get message from command line + msgchk=msg + call fmtmsg(msgchk,iz) + nmsg=1 + if(msg(1:2).eq."-t") then + if (NTEST+5 > MAXTEST) then + write(*,*) "NTEST exceed MAXTEST" + endif + testmsg(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" + testmsg(NTEST+2)="KA1ABC WB9XYZ OOO" + testmsg(NTEST+3)="RO" + testmsg(NTEST+4)="RRR" + testmsg(NTEST+5)="73" + testmsgchk(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" + testmsgchk(NTEST+2)="KA1ABC WB9XYZ OOO" + testmsgchk(NTEST+3)="RO" + testmsgchk(NTEST+4)="RRR" + testmsgchk(NTEST+5)="73" + nmsg=NTEST+5 + endif + + write(*,1010) +1010 format(" Message Decoded Err? Type Expected"/ & + 76("-")) + + do imsg=1,nmsg + if(nmsg.gt.1) then + msg=testmsg(imsg) + msgchk=testmsgchk(imsg) + endif + + call fmtmsg(msg,iz) !To upper, collapse mult blanks + msg0=msg !Input message + call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report + msg1=msg !Message without "OOO" + + if(nspecial.gt.0) then !or is a shorthand message + if(nspecial.eq.2) decoded="RO" + if(nspecial.eq.3) decoded="RRR" + if(nspecial.eq.4) decoded="73" + itype=-1 + msgtype="Shorthand" + go to 10 + endif + + call packmsg(msg1,dgen,itype) !Pack message into 12 six-bit bytes + msgtype="" + if(itype.eq.1) msgtype="Std Msg" + if(itype.eq.2) msgtype="Type 1 pfx" + if(itype.eq.3) msgtype="Type 1 sfx" + if(itype.eq.4) msgtype="Type 2 pfx" + if(itype.eq.5) msgtype="Type 2 sfx" + if(itype.eq.6) msgtype="Free text" + + call rs_encode(dgen,sent) !RS encode + call interleave63(sent,1) !Interleave channel symbols + call graycode(sent,63,1,sent) !Apply Gray code + + call graycode(sent,63,-1,tmp) !Remove Gray code + call interleave63(tmp,-1) !Remove interleaving + call rs_decode(tmp,era,0,recd,nerr) !Decode the message + call unpackmsg(recd,decoded) !Unpack the user message + if(cok.eq."OOO") decoded(20:22)=cok + call fmtmsg(decoded,iz) + +10 bad=" " + expected = 'EXACT' + if(decoded.ne.msg0) then + bad="*" + if(decoded(1:13).eq.msg0(1:13) .and. & + decoded(14:22).eq. ' ') expected = 'TRUNCATED' + endif + write(*,1020) imsg,msg0,decoded,bad,itype,msgtype,expected +1020 format(i2,'.',1x,a22,1x,a22,1x,a1,i3,":",a10,2x,a22) + enddo + + if(nmsg.eq.1 .and. nspecial.eq.0) then + write(*,1030) dgen +1030 format(/'Packed message, 6-bit symbols ',12i3) !Display packed symbols + + write(*,1040) sent +1040 format(/'Information-carrying channel symbols'/(i5,20i3)) + endif + +999 end program JT65code diff --git a/lib/jt65sim.f90 b/lib/jt65sim.f90 index bec27409..623a0fca 100755 --- a/lib/jt65sim.f90 +++ b/lib/jt65sim.f90 @@ -1,312 +1,312 @@ -program jt65sim - -! Generate simulated JT65 data for testing WSJT-X - - use wavhdr - use packjt - use options - parameter (NMAX=54*12000) ! = 648,000 @12kHz - parameter (NFFT=10*65536,NH=NFFT/2) - type(hdr) h !Header for .wav file - integer*2 iwave(NMAX) !Generated waveform - integer*4 itone(126) !Channel symbols (values 0-65) - integer dgen(12) !Twelve 6-bit data symbols - integer sent(63) !RS(63,12) codeword - real*4 xnoise(NMAX) !Generated random noise - real*4 dat(NMAX) !Generated real data - complex cdat(NMAX) !Generated complex waveform - complex cspread(0:NFFT-1) !Complex amplitude for Rayleigh fading - complex z - real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq,sps - character msg*22,fname*11,csubmode*1,c,optarg*500,numbuf*32 -! character call1*5,call2*5 - logical :: display_help=.false.,seed_prngs=.true. - type (option) :: long_options(13) = [ & - option ('help',.false.,'h','Display this help message',''), & - option ('sub-mode',.true.,'m','sub mode, default MODE=A','MODE'), & - option ('num-sigs',.true.,'n','number of signals per file, default SIGNALS=10','SIGNALS'), & - option ('f0',.true.,'F','base frequency offset, default F0=1500.0','F0'), & - option ('doppler-spread',.true.,'d','Doppler spread, default SPREAD=0.0','SPREAD'), & - option ('drift per min',.true.,'D','Frequency drift (Hz/min), default DRIFT=0.0','DRIFT'), & - option ('time-offset',.true.,'t','Time delta, default SECONDS=0.0','SECONDS'), & - option ('num-files',.true.,'f','Number of files to generate, default FILES=1','FILES'), & - option ('no-prng-seed',.false.,'p','Do not seed PRNGs (use for reproducible tests)',''), & - option ('strength',.true.,'s','S/N in dB (2500Hz reference b/w), default SNR=0','SNR'), & - option ('11025',.false.,'S','Generate at 11025Hz sample rate, default 12000Hz',''), & - option ('gain-offset',.true.,'G','Gain offset in dB, default GAIN=0dB','GAIN'), & - option ('message',.true.,'M','Message text','Message') ] - - integer nprc(126) !Sync pattern - 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/ - -! Default parameters: - csubmode='A' - mode65=1 - nsigs=10 - bf0=1500. - fspread=0. - drift=0. - xdt=0. - snrdb=0. - nfiles=1 - nsample_rate=12000 - gain_offset=0. - msg="K1ABC W9XYZ EN37" - - do - call getopt('hm:n:F:d:D:t:f:ps:SG:M:',long_options,c,optarg,narglen,nstat,noffset,nremain,.true.) - if( nstat .ne. 0 ) then - exit - end if - select case (c) - case ('h') - display_help = .true. - case ('m') - read (optarg(:narglen), *) csubmode - if(csubmode.eq.'A') mode65=1 - if(csubmode.eq.'B') mode65=2 - if(csubmode.eq.'C') mode65=4 - case ('n') - read (optarg(:narglen), *,err=10) nsigs - case ('F') - read (optarg(:narglen), *,err=10) bf0 - case ('d') - read (optarg(:narglen), *,err=10) fspread - case ('D') - read (optarg(:narglen), *,err=10) drift - case ('t') - read (optarg(:narglen), *) numbuf - if (numbuf(1:1) == '\') then !'\' - read (numbuf(2:), *,err=10) xdt - else - read (numbuf, *,err=10) xdt - end if - case ('f') - read (optarg(:narglen), *,err=10) nfiles - case ('p') - seed_prngs=.false. - case ('s') - read (optarg(:narglen), *) numbuf - if (numbuf(1:1) == '\') then !'\' - read (numbuf(2:), *,err=10) snrdb - else - read (numbuf, *,err=10) snrdb - end if - case ('S') - nsample_rate=11025 - case ('G') - read (optarg(:narglen), *) numbuf - if (numbuf(1:1) == '\') then !'\' - read (numbuf(2:), *, err=10) gain_offset - else - read (numbuf, *, err=10) gain_offset - end if - case ('M') - read (optarg(:narglen), '(A)',err=10) msg - end select - cycle -10 display_help=.true. - print *, 'Optional argument format error for option -', c - end do - - if(display_help .or. nstat.lt.0 .or. nremain.ge.1) then - print *, '' - print *, 'Usage: jt65sim [OPTIONS]' - print *, '' - print *, ' Generate one or more simulated JT65 signals in .WAV file(s)' - print *, '' - print *, 'Example: jt65sim -m B -n 10 -d 0.2 -s \\-24.5 -t 0.0 -f 4' - print *, '' - print *, 'OPTIONS: NB Use \ (\\ on *nix shells) to escape -ve arguments' - print *, '' - do i = 1, size (long_options) - call long_options(i) % print (6) - end do - go to 999 - endif - - if (seed_prngs) then - call init_random_seed() ! seed Fortran RANDOM_NUMBER generator - call sgran() ! see C rand generator (used in gran) - end if - - rms=100. * 10. ** (gain_offset / 20.) - - fsample=nsample_rate !Sample rate (Hz) - dt=1.d0/fsample !Sample interval (s) - twopi=8.d0*atan(1.d0) - npts=54*nsample_rate !Total samples in .wav file - baud=11025.d0/4096.d0 !Keying rate - sps=real(nsample_rate)/baud !Samples per symbol, at fsample=NSAMPLE_RATE Hz - nsym=126 !Number of channel symbols - h=default_header(nsample_rate,npts) - dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz) - - do ifile=1,nfiles !Loop over requested number of files - write(fname,1002) ifile !Output filename -1002 format('000000_',i4.4) - open(10,file=fname//'.wav',access='stream',status='unknown') - - xnoise=0. - cdat=0. - if(snrdb.lt.90) then - do i=1,npts - xnoise(i)=gran() !Generate gaussian noise - enddo - endif - - do isig=1,nsigs !Generate requested number of sigs - if(mod(nsigs,2).eq.0) f0=bf0 + dfsig*(isig-0.5-nsigs/2) - if(mod(nsigs,2).eq.1) f0=bf0 + dfsig*(isig-(nsigs+1)/2) - xsnr=snrdb - if(snrdb.eq.0.0) xsnr=-19 - isig - if(csubmode.eq.'B' .and. snrdb.eq.0.0) xsnr=-21 - isig - if(csubmode.eq.'C' .and. snrdb.eq.0.0) xsnr=-21 - isig - - call packmsg(msg,dgen,itype) !Pack message into 12 six-bit bytes - call rs_encode(dgen,sent) !Encode using RS(63,12) - call interleave63(sent,1) !Interleave channel symbols - call graycode65(sent,63,1) !Apply Gray code - - nprc_test=0 - i1=len(trim(msg)) - if(i1.gt.10) then - if(msg(i1-3:i1).eq.' OOO') nprc_test=1 - endif - k=0 - do j=1,nsym !Insert sync and data into itone() - if(nprc(j).eq.nprc_test) then - k=k+1 - itone(j)=sent(k)+2 - else - itone(j)=0 - endif - enddo - - if(len(trim(msg)).eq.2.or.len(trim(msg)).eq.3) then - nshorthand=0 - if(msg(1:2).eq.'RO') nshorthand=2 - if(msg(1:3).eq.'RRR') nshorthand=3 - if(msg(1:2).eq.'73') nshorthand=4 - if(nshorthand.gt.0) then - ntoggle=0 - do i=1,nsym,4 - itone(i)=ntoggle*10*nshorthand - if(i+1.le.126) itone(i+1)=ntoggle*10*nshorthand - if(i+2.le.126) itone(i+2)=ntoggle*10*nshorthand - if(i+3.le.126) itone(i+3)=ntoggle*10*nshorthand - ntoggle=mod(ntoggle+1,2) - enddo - endif - endif - - bandwidth_ratio=2500.0/(fsample/2.0) - sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*xsnr) - if(xsnr.gt.90.0) sig=1.0 - write(*,1020) ifile,isig,f0,csubmode,xsnr,xdt,fspread,msg -1020 format(i4,i4,f10.3,2x,a1,2x,f5.1,f6.2,f5.1,1x,a22) - - phi=0.d0 - dphi=0.d0 - k=nsample_rate + xdt*nsample_rate !Start audio at t = xdt + 1.0 s - isym0=-99 - do i=1,npts !Add this signal into cdat() - isym=floor(i/sps)+1 - if(isym.gt.nsym) exit - freq=f0 + (drift/60.0)*(i-npts/2)*dt + itone(isym)*baud*mode65 - dphi=twopi*freq*dt - phi=phi + dphi - if(phi.gt.twopi) phi=phi-twopi - xphi=phi - z=cmplx(cos(xphi),sin(xphi)) - k=k+1 - if(k.ge.1) cdat(k)=cdat(k) + sig*z - enddo - enddo - - if(fspread.ne.0) then !Apply specified Doppler spread - df=real(nsample_rate)/nfft - twopi=8*atan(1.0) - cspread(0)=1.0 - cspread(NH)=0. - -! The following options were added 3/15/2016 to make the half-power tone -! widths equal to the requested Doppler spread. (Previously we effectively -! used b=1.0 and Gaussian shape, which made the tones 1.665 times wider.) -! b=2.0*sqrt(log(2.0)) !Gaussian (before 3/15/2016) -! b=2.0 !Lorenzian 3/15 - 3/27 - b=6.0 !Lorenzian 3/28 onward - - 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(exp(-x*x)) !Gaussian - a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian - call random_number(r1) - phi1=twopi*r1 - z=a*cmplx(cos(phi1),sin(phi1)) - endif - cspread(i)=z - z=0. - if(x.lt.50.0) then - call random_number(r2) - phi2=twopi*r2 - z=a*cmplx(cos(phi2),sin(phi2)) - endif - cspread(NFFT-i)=z - enddo - - do i=0,NFFT-1 - f=i*df - if(i.gt.NH) f=(i-nfft)*df - s=real(cspread(i))**2 + aimag(cspread(i))**2 -! write(13,3000) i,f,s,cspread(i) -!3000 format(i5,f10.3,3f12.6) - enddo -! s=real(cspread(0))**2 + aimag(cspread(0))**2 -! write(13,3000) 1024,0.0,s,cspread(0) - - 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 - cdat(1:npts)=cspread(1:npts)*cdat(1:npts) !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 - - endif - - dat(1:npts)=aimag(cdat(1:npts)) + xnoise(1:npts) !Add the generated noise - if(snrdb.lt.90.0) then - dat(1:npts)=rms*dat(1:npts) - else - datpk=maxval(abs(dat(1:npts))) - fac=32766.9/datpk - dat(1:npts)=fac*dat(1:npts) - endif - if(any(abs(dat(1:npts)).gt.32767.0)) print*,"Warning - data will be clipped." - iwave(1:npts)=nint(dat(1:npts)) - write(10) h,iwave(1:npts) !Save the .wav file - close(10) - enddo - -999 end program jt65sim +program jt65sim + +! Generate simulated JT65 data for testing WSJT-X + + use wavhdr + use packjt + use options + parameter (NMAX=54*12000) ! = 648,000 @12kHz + parameter (NFFT=10*65536,NH=NFFT/2) + type(hdr) h !Header for .wav file + integer*2 iwave(NMAX) !Generated waveform + integer*4 itone(126) !Channel symbols (values 0-65) + integer dgen(12) !Twelve 6-bit data symbols + integer sent(63) !RS(63,12) codeword + real*4 xnoise(NMAX) !Generated random noise + real*4 dat(NMAX) !Generated real data + complex cdat(NMAX) !Generated complex waveform + complex cspread(0:NFFT-1) !Complex amplitude for Rayleigh fading + complex z + real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq,sps + character msg*22,fname*11,csubmode*1,c,optarg*500,numbuf*32 +! character call1*5,call2*5 + logical :: display_help=.false.,seed_prngs=.true. + type (option) :: long_options(13) = [ & + option ('help',.false.,'h','Display this help message',''), & + option ('sub-mode',.true.,'m','sub mode, default MODE=A','MODE'), & + option ('num-sigs',.true.,'n','number of signals per file, default SIGNALS=10','SIGNALS'), & + option ('f0',.true.,'F','base frequency offset, default F0=1500.0','F0'), & + option ('doppler-spread',.true.,'d','Doppler spread, default SPREAD=0.0','SPREAD'), & + option ('drift per min',.true.,'D','Frequency drift (Hz/min), default DRIFT=0.0','DRIFT'), & + option ('time-offset',.true.,'t','Time delta, default SECONDS=0.0','SECONDS'), & + option ('num-files',.true.,'f','Number of files to generate, default FILES=1','FILES'), & + option ('no-prng-seed',.false.,'p','Do not seed PRNGs (use for reproducible tests)',''), & + option ('strength',.true.,'s','S/N in dB (2500Hz reference b/w), default SNR=0','SNR'), & + option ('11025',.false.,'S','Generate at 11025Hz sample rate, default 12000Hz',''), & + option ('gain-offset',.true.,'G','Gain offset in dB, default GAIN=0dB','GAIN'), & + option ('message',.true.,'M','Message text','Message') ] + + integer nprc(126) !Sync pattern + 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/ + +! Default parameters: + csubmode='A' + mode65=1 + nsigs=10 + bf0=1500. + fspread=0. + drift=0. + xdt=0. + snrdb=0. + nfiles=1 + nsample_rate=12000 + gain_offset=0. + msg="K1ABC W9XYZ EN37" + + do + call getopt('hm:n:F:d:D:t:f:ps:SG:M:',long_options,c,optarg,narglen,nstat,noffset,nremain,.true.) + if( nstat .ne. 0 ) then + exit + end if + select case (c) + case ('h') + display_help = .true. + case ('m') + read (optarg(:narglen), *) csubmode + if(csubmode.eq.'A') mode65=1 + if(csubmode.eq.'B') mode65=2 + if(csubmode.eq.'C') mode65=4 + case ('n') + read (optarg(:narglen), *,err=10) nsigs + case ('F') + read (optarg(:narglen), *,err=10) bf0 + case ('d') + read (optarg(:narglen), *,err=10) fspread + case ('D') + read (optarg(:narglen), *,err=10) drift + case ('t') + read (optarg(:narglen), *) numbuf + if (numbuf(1:1) == '\') then !'\' + read (numbuf(2:), *,err=10) xdt + else + read (numbuf, *,err=10) xdt + end if + case ('f') + read (optarg(:narglen), *,err=10) nfiles + case ('p') + seed_prngs=.false. + case ('s') + read (optarg(:narglen), *) numbuf + if (numbuf(1:1) == '\') then !'\' + read (numbuf(2:), *,err=10) snrdb + else + read (numbuf, *,err=10) snrdb + end if + case ('S') + nsample_rate=11025 + case ('G') + read (optarg(:narglen), *) numbuf + if (numbuf(1:1) == '\') then !'\' + read (numbuf(2:), *, err=10) gain_offset + else + read (numbuf, *, err=10) gain_offset + end if + case ('M') + read (optarg(:narglen), '(A)',err=10) msg + end select + cycle +10 display_help=.true. + print *, 'Optional argument format error for option -', c + end do + + if(display_help .or. nstat.lt.0 .or. nremain.ge.1) then + print *, '' + print *, 'Usage: jt65sim [OPTIONS]' + print *, '' + print *, ' Generate one or more simulated JT65 signals in .WAV file(s)' + print *, '' + print *, 'Example: jt65sim -m B -n 10 -d 0.2 -s \\-24.5 -t 0.0 -f 4' + print *, '' + print *, 'OPTIONS: NB Use \ (\\ on *nix shells) to escape -ve arguments' + print *, '' + do i = 1, size (long_options) + call long_options(i) % print (6) + end do + go to 999 + endif + + if (seed_prngs) then + call init_random_seed() ! seed Fortran RANDOM_NUMBER generator + call sgran() ! see C rand generator (used in gran) + end if + + rms=100. * 10. ** (gain_offset / 20.) + + fsample=nsample_rate !Sample rate (Hz) + dt=1.d0/fsample !Sample interval (s) + twopi=8.d0*atan(1.d0) + npts=54*nsample_rate !Total samples in .wav file + baud=11025.d0/4096.d0 !Keying rate + sps=real(nsample_rate)/baud !Samples per symbol, at fsample=NSAMPLE_RATE Hz + nsym=126 !Number of channel symbols + h=default_header(nsample_rate,npts) + dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz) + + do ifile=1,nfiles !Loop over requested number of files + write(fname,1002) ifile !Output filename +1002 format('000000_',i4.4) + open(10,file=fname//'.wav',access='stream',status='unknown') + + xnoise=0. + cdat=0. + if(snrdb.lt.90) then + do i=1,npts + xnoise(i)=gran() !Generate gaussian noise + enddo + endif + + do isig=1,nsigs !Generate requested number of sigs + if(mod(nsigs,2).eq.0) f0=bf0 + dfsig*(isig-0.5-nsigs/2) + if(mod(nsigs,2).eq.1) f0=bf0 + dfsig*(isig-(nsigs+1)/2) + xsnr=snrdb + if(snrdb.eq.0.0) xsnr=-19 - isig + if(csubmode.eq.'B' .and. snrdb.eq.0.0) xsnr=-21 - isig + if(csubmode.eq.'C' .and. snrdb.eq.0.0) xsnr=-21 - isig + + call packmsg(msg,dgen,itype) !Pack message into 12 six-bit bytes + call rs_encode(dgen,sent) !Encode using RS(63,12) + call interleave63(sent,1) !Interleave channel symbols + call graycode65(sent,63,1) !Apply Gray code + + nprc_test=0 + i1=len(trim(msg)) + if(i1.gt.10) then + if(msg(i1-3:i1).eq.' OOO') nprc_test=1 + endif + k=0 + do j=1,nsym !Insert sync and data into itone() + if(nprc(j).eq.nprc_test) then + k=k+1 + itone(j)=sent(k)+2 + else + itone(j)=0 + endif + enddo + + if(len(trim(msg)).eq.2.or.len(trim(msg)).eq.3) then + nshorthand=0 + if(msg(1:2).eq.'RO') nshorthand=2 + if(msg(1:3).eq.'RRR') nshorthand=3 + if(msg(1:2).eq.'73') nshorthand=4 + if(nshorthand.gt.0) then + ntoggle=0 + do i=1,nsym,4 + itone(i)=ntoggle*10*nshorthand + if(i+1.le.126) itone(i+1)=ntoggle*10*nshorthand + if(i+2.le.126) itone(i+2)=ntoggle*10*nshorthand + if(i+3.le.126) itone(i+3)=ntoggle*10*nshorthand + ntoggle=mod(ntoggle+1,2) + enddo + endif + endif + + bandwidth_ratio=2500.0/(fsample/2.0) + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*xsnr) + if(xsnr.gt.90.0) sig=1.0 + write(*,1020) ifile,isig,f0,csubmode,xsnr,xdt,fspread,msg +1020 format(i4,i4,f10.3,2x,a1,2x,f5.1,f6.2,f5.1,1x,a22) + + phi=0.d0 + dphi=0.d0 + k=nsample_rate + xdt*nsample_rate !Start audio at t = xdt + 1.0 s + isym0=-99 + do i=1,npts !Add this signal into cdat() + isym=floor(i/sps)+1 + if(isym.gt.nsym) exit + freq=f0 + (drift/60.0)*(i-npts/2)*dt + itone(isym)*baud*mode65 + dphi=twopi*freq*dt + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + z=cmplx(cos(xphi),sin(xphi)) + k=k+1 + if(k.ge.1) cdat(k)=cdat(k) + sig*z + enddo + enddo + + if(fspread.ne.0) then !Apply specified Doppler spread + df=real(nsample_rate)/nfft + twopi=8*atan(1.0) + cspread(0)=1.0 + cspread(NH)=0. + +! The following options were added 3/15/2016 to make the half-power tone +! widths equal to the requested Doppler spread. (Previously we effectively +! used b=1.0 and Gaussian shape, which made the tones 1.665 times wider.) +! b=2.0*sqrt(log(2.0)) !Gaussian (before 3/15/2016) +! b=2.0 !Lorenzian 3/15 - 3/27 + b=6.0 !Lorenzian 3/28 onward + + 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(exp(-x*x)) !Gaussian + a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian + call random_number(r1) + phi1=twopi*r1 + z=a*cmplx(cos(phi1),sin(phi1)) + endif + cspread(i)=z + z=0. + if(x.lt.50.0) then + call random_number(r2) + phi2=twopi*r2 + z=a*cmplx(cos(phi2),sin(phi2)) + endif + cspread(NFFT-i)=z + enddo + + do i=0,NFFT-1 + f=i*df + if(i.gt.NH) f=(i-nfft)*df + s=real(cspread(i))**2 + aimag(cspread(i))**2 +! write(13,3000) i,f,s,cspread(i) +!3000 format(i5,f10.3,3f12.6) + enddo +! s=real(cspread(0))**2 + aimag(cspread(0))**2 +! write(13,3000) 1024,0.0,s,cspread(0) + + 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 + cdat(1:npts)=cspread(1:npts)*cdat(1:npts) !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 + + endif + + dat(1:npts)=aimag(cdat(1:npts)) + xnoise(1:npts) !Add the generated noise + if(snrdb.lt.90.0) then + dat(1:npts)=rms*dat(1:npts) + else + datpk=maxval(abs(dat(1:npts))) + fac=32766.9/datpk + dat(1:npts)=fac*dat(1:npts) + endif + if(any(abs(dat(1:npts)).gt.32767.0)) print*,"Warning - data will be clipped." + iwave(1:npts)=nint(dat(1:npts)) + write(10) h,iwave(1:npts) !Save the .wav file + close(10) + enddo + +999 end program jt65sim diff --git a/lib/jt9.f90 b/lib/jt9.f90 index d7dedf43..d284f6dd 100755 --- a/lib/jt9.f90 +++ b/lib/jt9.f90 @@ -1,381 +1,381 @@ -program jt9 - -! Decoder for JT9. Can run stand-alone, reading data from *.wav files; -! or as the back end of wsjt-x, with data placed in a shared memory region. - - use options - use prog_args - use, intrinsic :: iso_c_binding - use FFTW3 - use timer_module, only: timer - use timer_impl, only: init_timer, fini_timer - use readwav - - include 'jt9com.f90' - - integer*2 id2a(180000) - integer(C_INT) iret - type(wav_header) wav - real*4 s(NSMAX) - real*8 TRperiod - character c - character(len=500) optarg, infile - character wisfile*256 -!### ndepth was defined as 60001. Why??? - integer :: arglen,stat,offset,remain,mode=0,flow=200,fsplit=2700, & - fhigh=4000,nrxfreq=1500,ndepth=1,nexp_decode=0,nQSOProg=0 - logical :: read_files = .true., tx9 = .false., display_help = .false., & - bLowSidelobes = .false., nexp_decode_set = .false., & - have_ntol = .false. - type (option) :: long_options(33) = [ & - option ('help', .false., 'h', 'Display this help message', ''), & - option ('shmem',.true.,'s','Use shared memory for sample data','KEY'), & - option ('tr-period', .true., 'p', 'Tx/Rx period, default SECONDS=60', & - 'SECONDS'), & - option ('executable-path', .true., 'e', & - 'Location of subordinate executables (KVASD) default PATH="."', & - 'PATH'), & - option ('data-path', .true., 'a', & - 'Location of writeable data files, default PATH="."', 'PATH'), & - option ('temp-path', .true., 't', & - 'Temporary files path, default PATH="."', 'PATH'), & - option ('lowest', .true., 'L', & - 'Lowest frequency decoded (JT65), default HERTZ=200', 'HERTZ'), & - option ('highest', .true., 'H', & - 'Highest frequency decoded, default HERTZ=4007', 'HERTZ'), & - option ('split', .true., 'S', & - 'Lowest JT9 frequency decoded, default HERTZ=2700', 'HERTZ'), & - option ('rx-frequency', .true., 'f', & - 'Receive frequency offset, default HERTZ=1500', 'HERTZ'), & - option ('freq-tolerance', .true., 'F', & - 'Receive frequency tolerance, default HERTZ=20', 'HERTZ'), & - option ('patience', .true., 'w', & - 'FFTW3 planing patience (0-4), default PATIENCE=1', 'PATIENCE'), & - option ('fft-threads', .true., 'm', & - 'Number of threads to process large FFTs, default THREADS=1', & - 'THREADS'), & - option ('q65', .false., '3', 'Q65 mode', ''), & - option ('jt4', .false., '4', 'JT4 mode', ''), & - option ('ft4', .false., '5', 'FT4 mode', ''), & - option ('jt65', .false.,'6', 'JT65 mode', ''), & - option ('fst4', .false., '7', 'FST4 mode', ''), & - option ('fst4w', .false., 'W', 'FST4W mode', ''), & - option ('fst4w', .false., 'Y', 'FST4W mode, print hash22 values', ''), & - option ('ft8', .false., '8', 'FT8 mode', ''), & - option ('jt9', .false., '9', 'JT9 mode', ''), & - option ('qra64', .false., 'q', 'QRA64 mode', ''), & - option ('msk144', .false., 'k', 'MSK144 mode', ''), & - option ('QSOprog', .true., 'Q', 'QSO progress (0-5), default PROGRESS=1',& - 'QSOprogress'), & - option ('sub-mode', .true., 'b', 'Sub mode, default SUBMODE=A', 'A'), & - option ('depth', .true., 'd', & - 'Decoding depth (1-3), default DEPTH=1', 'DEPTH'), & - option ('tx-jt9', .false., 'T', 'Tx mode is JT9', ''), & - option ('my-call', .true., 'c', 'my callsign', 'CALL'), & - option ('my-grid', .true., 'G', 'my grid locator', 'GRID'), & - option ('his-call', .true., 'x', 'his callsign', 'CALL'), & - option ('his-grid', .true., 'g', 'his grid locator', 'GRID'), & - option ('experience-decode', .true., 'X', & - 'experience based decoding flags (1..n), default FLAGS=0', & - 'FLAGS') ] - - type(dec_data), allocatable :: shared_data - character(len=20) :: datetime='' - character(len=12) :: mycall='K1ABC', hiscall='W9XYZ' - character(len=6) :: mygrid='', hisgrid='EN37' - common/patience/npatience,nthreads - common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano - data npatience/1/,nthreads/1/,wisfile/' '/ - - nsubmode = 0 - ntol = 20 - TRperiod=60.d0 - - do - call getopt('hs:e:a:b:r:m:p:d:f:F:w:t:9876543WYqkTL:S:H:c:G:x:g:X:Q:', & - long_options,c,optarg,arglen,stat,offset,remain,.true.) - if (stat .ne. 0) then - exit - end if - select case (c) - case ('h') - display_help = .true. - case ('s') - read_files = .false. - shm_key = optarg(:arglen) - case ('e') - exe_dir = optarg(:arglen) - case ('a') - data_dir = optarg(:arglen) - case ('b') - nsubmode = ichar (optarg(:1)) - ichar ('A') - case ('t') - temp_dir = optarg(:arglen) - case ('m') - read (optarg(:arglen), *) nthreads - case ('p') - read (optarg(:arglen), *) TRperiod - case ('d') - read (optarg(:arglen), *) ndepth - case ('f') - read (optarg(:arglen), *) nrxfreq - case ('F') - read (optarg(:arglen), *) ntol - have_ntol = .true. - case ('L') - read (optarg(:arglen), *) flow - case ('S') - read (optarg(:arglen), *) fsplit - case ('H') - read (optarg(:arglen), *) fhigh - case ('q') - mode = 164 - case ('k') - mode = 144 - case ('Q') - read (optarg(:arglen), *) nQSOProg - case ('3') - mode = 66 - case ('4') - mode = 4 - case ('5') - mode = 5 - case ('6') - if (mode.lt.65) mode = mode + 65 - case ('7') - mode = 240 - case ('8') - mode = 8 - case ('9') - if (mode.lt.9.or.mode.eq.65) mode = mode + 9 - case ('T') - tx9 = .true. - case ('w') - read (optarg(:arglen), *) npatience - case ('W') - mode = 241 - case ('Y') - mode = 242 - case ('c') - read (optarg(:arglen), *) mycall - case ('G') - read (optarg(:arglen), *) mygrid - case ('x') - read (optarg(:arglen), *) hiscall - case ('g') - read (optarg(:arglen), *) hisgrid - case ('X') - read (optarg(:arglen), *) nexp_decode - nexp_decode_set = .true. - end select - end do - - if (display_help .or. stat .lt. 0 & - .or. (.not. read_files .and. remain .gt. 0) & - .or. (read_files .and. remain .lt. 1)) then - - print *, 'Usage: jt9 [OPTIONS] file1 [file2 ...]' - print *, ' Reads data from *.wav files.' - print *, '' - print *, ' jt9 -s [-w patience] [-m threads] [-e path] [-a path] [-t path]' - print *, ' Gets data from shared memory region with key==' - print *, '' - print *, 'OPTIONS:' - print *, '' - do i = 1, size (long_options) - call long_options(i) % print (6) - end do - go to 999 - endif - - 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(data_dir)//'/jt9_wisdom.dat'// C_NULL_CHAR - iret=fftwf_import_wisdom_from_filename(wisfile) - - ntry65a=0 - ntry65b=0 - n65a=0 - n65b=0 - num9=0 - numfano=0 - - if (.not. read_files) then - call jt9a() !We're running under control of WSJT-X - go to 999 - endif - - if(mycall.eq.'b') mycall=' ' - if(hiscall.eq.'b') then - hiscall=' ' - hisgrid=' ' - endif - - if (mode .eq. 241 .or. mode .eq. 242) then - ntol = min (ntol, 100) - else if (mode .eq. 65 + 9 .and. .not. have_ntol) then - ntol = 20 - else if (mode .eq. 66 .and. .not. have_ntol) then - ntol = 10 - else - ntol = min (ntol, 1000) - end if - if (.not. nexp_decode_set) then - if (mode .eq. 240 .or. mode .eq. 241 .or. mode .eq. 242) then - nexp_decode = 3 * 256 ! single decode off and nb=0 - end if - end if - allocate(shared_data) - nflatten=0 - do iarg = offset + 1, offset + remain - call get_command_argument (iarg, optarg, arglen) - infile = optarg(:arglen) - call wav%read (infile) - nfsample=wav%audio_format%sample_rate - i1=index(infile,'.wav') - if(i1.lt.1) i1=index(infile,'.WAV') - if(infile(i1-5:i1-5).eq.'_') then - read(infile(i1-4:i1-1),*,err=1) nutc - else - read(infile(i1-6:i1-1),*,err=1) nutc - endif - go to 2 -1 nutc=0 -2 nsps=6912 - npts=TRperiod*12000.d0 - kstep=nsps/2 - k=0 - nhsym=0 - nhsym0=-999 - if(iarg .eq. offset + 1) then - call init_timer (trim(data_dir)//'/timer.out') - call timer('jt9 ',0) - endif - shared_data%id2=0 !??? Why is this necessary ??? - if(mode.eq.5) npts=21*3456 - if(mode.eq.66) npts=TRperiod*12000 - do iblk=1,npts/kstep - k=iblk*kstep - if(mode.eq.8 .and. k.gt.179712) exit - call timer('read_wav',0) - read(unit=wav%lun,end=3) shared_data%id2(k-kstep+1:k) - go to 4 -3 call timer('read_wav',1) - print*,'EOF on input file ',trim(infile) - exit -4 call timer('read_wav',1) - nhsym=(k-2048)/kstep - if(nhsym.ge.1 .and. nhsym.ne.nhsym0) then - if(mode.eq.9 .or. mode.eq.74) then -! Compute rough symbol spectra for the JT9 decoder - ingain=0 - call timer('symspec ',0) - nminw=1 - call symspec(shared_data,k,Tperiod,nsps,ingain, & - bLowSidelobes,nminw,pxdb,s,df3,ihsym,npts8,pxdbmax) - call timer('symspec ',1) - endif - nhsym0=nhsym - if(nhsym.ge.181 .and. mode.ne.240 .and. mode.ne.241 .and. & - mode.ne.242 .and. mode.ne.66) exit - endif - enddo - close(unit=wav%lun) - shared_data%params%nutc=nutc - shared_data%params%ndiskdat=.true. - shared_data%params%ntr=TRperiod - shared_data%params%nfqso=nrxfreq - shared_data%params%newdat=.true. - shared_data%params%npts8=74736 - shared_data%params%nfa=flow - shared_data%params%nfsplit=fsplit - shared_data%params%nfb=fhigh - shared_data%params%ntol=ntol - shared_data%params%kin=64800 - if(mode.eq.240) shared_data%params%kin=720000 !### 60 s periods ### - shared_data%params%nzhsym=nhsym - shared_data%params%ndepth=ndepth - shared_data%params%lft8apon=.true. - shared_data%params%ljt65apon=.true. - shared_data%params%napwid=75 - shared_data%params%dttol=3. - if(mode.eq.164 .and. nsubmode.lt.100) nsubmode=nsubmode+100 - shared_data%params%nagain=.false. - shared_data%params%nclearave=.false. - shared_data%params%lapcqonly=.false. - shared_data%params%naggressive=0 - shared_data%params%n2pass=2 - shared_data%params%nQSOprogress=nQSOProg - shared_data%params%nranera=6 !### ntrials=3000 - shared_data%params%nrobust=.false. - shared_data%params%nexp_decode=nexp_decode - shared_data%params%mycall=transfer(mycall,shared_data%params%mycall) - shared_data%params%mygrid=transfer(mygrid,shared_data%params%mygrid) - shared_data%params%hiscall=transfer(hiscall,shared_data%params%hiscall) - shared_data%params%hisgrid=transfer(hisgrid,shared_data%params%hisgrid) - if (tx9) then - shared_data%params%ntxmode=9 - else - shared_data%params%ntxmode=65 - end if - if (mode.eq.0) then - shared_data%params%nmode=65+9 - else - shared_data%params%nmode=mode - end if - shared_data%params%nsubmode=nsubmode - -!### temporary, for MAP65: - if(mode.eq.66 .and. TRperiod.eq.60) shared_data%params%emedelay=2.5 - - datetime="2013-Apr-16 15:13" !### Temp - shared_data%params%datetime=transfer(datetime,shared_data%params%datetime) - if(mode.eq.9 .and. fsplit.ne.2700) shared_data%params%nfa=fsplit - if(mode.eq.8) then -! "Early" decoding pass, FT8 only, when jt9 reads data from disk - nearly=41 - shared_data%params%nzhsym=nearly - id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456) - id2a(nearly*3456+1:)=0 - call multimode_decoder(shared_data%ss,id2a, & - shared_data%params,nfsample) - nearly=47 - shared_data%params%nzhsym=nearly - id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456) - id2a(nearly*3456+1:)=0 - call multimode_decoder(shared_data%ss,id2a, & - shared_data%params,nfsample) - id2a(nearly*3456+1:50*3456)=shared_data%id2(nearly*3456+1:50*3456) - id2a(50*3456+1:)=0 - shared_data%params%nzhsym=50 - call multimode_decoder(shared_data%ss,id2a, & - shared_data%params,nfsample) - cycle - - ! MSK144 - else if (mode .eq. 144) then - call decode_msk144(shared_data%id2, shared_data%params, data_dir) - endif - -! Normal decoding pass - call multimode_decoder(shared_data%ss,shared_data%id2, & - shared_data%params,nfsample) - enddo - - call timer('jt9 ',1) - call timer('jt9 ',101) - -999 continue -! Output decoder statistics - call fini_timer () -! Save FFTW wisdom and free memory - 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() -end program jt9 +program jt9 + +! Decoder for JT9. Can run stand-alone, reading data from *.wav files; +! or as the back end of wsjt-x, with data placed in a shared memory region. + + use options + use prog_args + use, intrinsic :: iso_c_binding + use FFTW3 + use timer_module, only: timer + use timer_impl, only: init_timer, fini_timer + use readwav + + include 'jt9com.f90' + + integer*2 id2a(180000) + integer(C_INT) iret + type(wav_header) wav + real*4 s(NSMAX) + real*8 TRperiod + character c + character(len=500) optarg, infile + character wisfile*256 +!### ndepth was defined as 60001. Why??? + integer :: arglen,stat,offset,remain,mode=0,flow=200,fsplit=2700, & + fhigh=4000,nrxfreq=1500,ndepth=1,nexp_decode=0,nQSOProg=0 + logical :: read_files = .true., tx9 = .false., display_help = .false., & + bLowSidelobes = .false., nexp_decode_set = .false., & + have_ntol = .false. + type (option) :: long_options(33) = [ & + option ('help', .false., 'h', 'Display this help message', ''), & + option ('shmem',.true.,'s','Use shared memory for sample data','KEY'), & + option ('tr-period', .true., 'p', 'Tx/Rx period, default SECONDS=60', & + 'SECONDS'), & + option ('executable-path', .true., 'e', & + 'Location of subordinate executables (KVASD) default PATH="."', & + 'PATH'), & + option ('data-path', .true., 'a', & + 'Location of writeable data files, default PATH="."', 'PATH'), & + option ('temp-path', .true., 't', & + 'Temporary files path, default PATH="."', 'PATH'), & + option ('lowest', .true., 'L', & + 'Lowest frequency decoded (JT65), default HERTZ=200', 'HERTZ'), & + option ('highest', .true., 'H', & + 'Highest frequency decoded, default HERTZ=4007', 'HERTZ'), & + option ('split', .true., 'S', & + 'Lowest JT9 frequency decoded, default HERTZ=2700', 'HERTZ'), & + option ('rx-frequency', .true., 'f', & + 'Receive frequency offset, default HERTZ=1500', 'HERTZ'), & + option ('freq-tolerance', .true., 'F', & + 'Receive frequency tolerance, default HERTZ=20', 'HERTZ'), & + option ('patience', .true., 'w', & + 'FFTW3 planing patience (0-4), default PATIENCE=1', 'PATIENCE'), & + option ('fft-threads', .true., 'm', & + 'Number of threads to process large FFTs, default THREADS=1', & + 'THREADS'), & + option ('q65', .false., '3', 'Q65 mode', ''), & + option ('jt4', .false., '4', 'JT4 mode', ''), & + option ('ft4', .false., '5', 'FT4 mode', ''), & + option ('jt65', .false.,'6', 'JT65 mode', ''), & + option ('fst4', .false., '7', 'FST4 mode', ''), & + option ('fst4w', .false., 'W', 'FST4W mode', ''), & + option ('fst4w', .false., 'Y', 'FST4W mode, print hash22 values', ''), & + option ('ft8', .false., '8', 'FT8 mode', ''), & + option ('jt9', .false., '9', 'JT9 mode', ''), & + option ('qra64', .false., 'q', 'QRA64 mode', ''), & + option ('msk144', .false., 'k', 'MSK144 mode', ''), & + option ('QSOprog', .true., 'Q', 'QSO progress (0-5), default PROGRESS=1',& + 'QSOprogress'), & + option ('sub-mode', .true., 'b', 'Sub mode, default SUBMODE=A', 'A'), & + option ('depth', .true., 'd', & + 'Decoding depth (1-3), default DEPTH=1', 'DEPTH'), & + option ('tx-jt9', .false., 'T', 'Tx mode is JT9', ''), & + option ('my-call', .true., 'c', 'my callsign', 'CALL'), & + option ('my-grid', .true., 'G', 'my grid locator', 'GRID'), & + option ('his-call', .true., 'x', 'his callsign', 'CALL'), & + option ('his-grid', .true., 'g', 'his grid locator', 'GRID'), & + option ('experience-decode', .true., 'X', & + 'experience based decoding flags (1..n), default FLAGS=0', & + 'FLAGS') ] + + type(dec_data), allocatable :: shared_data + character(len=20) :: datetime='' + character(len=12) :: mycall='K1ABC', hiscall='W9XYZ' + character(len=6) :: mygrid='', hisgrid='EN37' + common/patience/npatience,nthreads + common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano + data npatience/1/,nthreads/1/,wisfile/' '/ + + nsubmode = 0 + ntol = 20 + TRperiod=60.d0 + + do + call getopt('hs:e:a:b:r:m:p:d:f:F:w:t:9876543WYqkTL:S:H:c:G:x:g:X:Q:', & + long_options,c,optarg,arglen,stat,offset,remain,.true.) + if (stat .ne. 0) then + exit + end if + select case (c) + case ('h') + display_help = .true. + case ('s') + read_files = .false. + shm_key = optarg(:arglen) + case ('e') + exe_dir = optarg(:arglen) + case ('a') + data_dir = optarg(:arglen) + case ('b') + nsubmode = ichar (optarg(:1)) - ichar ('A') + case ('t') + temp_dir = optarg(:arglen) + case ('m') + read (optarg(:arglen), *) nthreads + case ('p') + read (optarg(:arglen), *) TRperiod + case ('d') + read (optarg(:arglen), *) ndepth + case ('f') + read (optarg(:arglen), *) nrxfreq + case ('F') + read (optarg(:arglen), *) ntol + have_ntol = .true. + case ('L') + read (optarg(:arglen), *) flow + case ('S') + read (optarg(:arglen), *) fsplit + case ('H') + read (optarg(:arglen), *) fhigh + case ('q') + mode = 164 + case ('k') + mode = 144 + case ('Q') + read (optarg(:arglen), *) nQSOProg + case ('3') + mode = 66 + case ('4') + mode = 4 + case ('5') + mode = 5 + case ('6') + if (mode.lt.65) mode = mode + 65 + case ('7') + mode = 240 + case ('8') + mode = 8 + case ('9') + if (mode.lt.9.or.mode.eq.65) mode = mode + 9 + case ('T') + tx9 = .true. + case ('w') + read (optarg(:arglen), *) npatience + case ('W') + mode = 241 + case ('Y') + mode = 242 + case ('c') + read (optarg(:arglen), *) mycall + case ('G') + read (optarg(:arglen), *) mygrid + case ('x') + read (optarg(:arglen), *) hiscall + case ('g') + read (optarg(:arglen), *) hisgrid + case ('X') + read (optarg(:arglen), *) nexp_decode + nexp_decode_set = .true. + end select + end do + + if (display_help .or. stat .lt. 0 & + .or. (.not. read_files .and. remain .gt. 0) & + .or. (read_files .and. remain .lt. 1)) then + + print *, 'Usage: jt9 [OPTIONS] file1 [file2 ...]' + print *, ' Reads data from *.wav files.' + print *, '' + print *, ' jt9 -s [-w patience] [-m threads] [-e path] [-a path] [-t path]' + print *, ' Gets data from shared memory region with key==' + print *, '' + print *, 'OPTIONS:' + print *, '' + do i = 1, size (long_options) + call long_options(i) % print (6) + end do + go to 999 + endif + + 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(data_dir)//'/jt9_wisdom.dat'// C_NULL_CHAR + iret=fftwf_import_wisdom_from_filename(wisfile) + + ntry65a=0 + ntry65b=0 + n65a=0 + n65b=0 + num9=0 + numfano=0 + + if (.not. read_files) then + call jt9a() !We're running under control of WSJT-X + go to 999 + endif + + if(mycall.eq.'b') mycall=' ' + if(hiscall.eq.'b') then + hiscall=' ' + hisgrid=' ' + endif + + if (mode .eq. 241 .or. mode .eq. 242) then + ntol = min (ntol, 100) + else if (mode .eq. 65 + 9 .and. .not. have_ntol) then + ntol = 20 + else if (mode .eq. 66 .and. .not. have_ntol) then + ntol = 10 + else + ntol = min (ntol, 1000) + end if + if (.not. nexp_decode_set) then + if (mode .eq. 240 .or. mode .eq. 241 .or. mode .eq. 242) then + nexp_decode = 3 * 256 ! single decode off and nb=0 + end if + end if + allocate(shared_data) + nflatten=0 + do iarg = offset + 1, offset + remain + call get_command_argument (iarg, optarg, arglen) + infile = optarg(:arglen) + call wav%read (infile) + nfsample=wav%audio_format%sample_rate + i1=index(infile,'.wav') + if(i1.lt.1) i1=index(infile,'.WAV') + if(infile(i1-5:i1-5).eq.'_') then + read(infile(i1-4:i1-1),*,err=1) nutc + else + read(infile(i1-6:i1-1),*,err=1) nutc + endif + go to 2 +1 nutc=0 +2 nsps=6912 + npts=TRperiod*12000.d0 + kstep=nsps/2 + k=0 + nhsym=0 + nhsym0=-999 + if(iarg .eq. offset + 1) then + call init_timer (trim(data_dir)//'/timer.out') + call timer('jt9 ',0) + endif + shared_data%id2=0 !??? Why is this necessary ??? + if(mode.eq.5) npts=21*3456 + if(mode.eq.66) npts=TRperiod*12000 + do iblk=1,npts/kstep + k=iblk*kstep + if(mode.eq.8 .and. k.gt.179712) exit + call timer('read_wav',0) + read(unit=wav%lun,end=3) shared_data%id2(k-kstep+1:k) + go to 4 +3 call timer('read_wav',1) + print*,'EOF on input file ',trim(infile) + exit +4 call timer('read_wav',1) + nhsym=(k-2048)/kstep + if(nhsym.ge.1 .and. nhsym.ne.nhsym0) then + if(mode.eq.9 .or. mode.eq.74) then +! Compute rough symbol spectra for the JT9 decoder + ingain=0 + call timer('symspec ',0) + nminw=1 + call symspec(shared_data,k,Tperiod,nsps,ingain, & + bLowSidelobes,nminw,pxdb,s,df3,ihsym,npts8,pxdbmax) + call timer('symspec ',1) + endif + nhsym0=nhsym + if(nhsym.ge.181 .and. mode.ne.240 .and. mode.ne.241 .and. & + mode.ne.242 .and. mode.ne.66) exit + endif + enddo + close(unit=wav%lun) + shared_data%params%nutc=nutc + shared_data%params%ndiskdat=.true. + shared_data%params%ntr=TRperiod + shared_data%params%nfqso=nrxfreq + shared_data%params%newdat=.true. + shared_data%params%npts8=74736 + shared_data%params%nfa=flow + shared_data%params%nfsplit=fsplit + shared_data%params%nfb=fhigh + shared_data%params%ntol=ntol + shared_data%params%kin=64800 + if(mode.eq.240) shared_data%params%kin=720000 !### 60 s periods ### + shared_data%params%nzhsym=nhsym + shared_data%params%ndepth=ndepth + shared_data%params%lft8apon=.true. + shared_data%params%ljt65apon=.true. + shared_data%params%napwid=75 + shared_data%params%dttol=3. + if(mode.eq.164 .and. nsubmode.lt.100) nsubmode=nsubmode+100 + shared_data%params%nagain=.false. + shared_data%params%nclearave=.false. + shared_data%params%lapcqonly=.false. + shared_data%params%naggressive=0 + shared_data%params%n2pass=2 + shared_data%params%nQSOprogress=nQSOProg + shared_data%params%nranera=6 !### ntrials=3000 + shared_data%params%nrobust=.false. + shared_data%params%nexp_decode=nexp_decode + shared_data%params%mycall=transfer(mycall,shared_data%params%mycall) + shared_data%params%mygrid=transfer(mygrid,shared_data%params%mygrid) + shared_data%params%hiscall=transfer(hiscall,shared_data%params%hiscall) + shared_data%params%hisgrid=transfer(hisgrid,shared_data%params%hisgrid) + if (tx9) then + shared_data%params%ntxmode=9 + else + shared_data%params%ntxmode=65 + end if + if (mode.eq.0) then + shared_data%params%nmode=65+9 + else + shared_data%params%nmode=mode + end if + shared_data%params%nsubmode=nsubmode + +!### temporary, for MAP65: + if(mode.eq.66 .and. TRperiod.eq.60) shared_data%params%emedelay=2.5 + + datetime="2013-Apr-16 15:13" !### Temp + shared_data%params%datetime=transfer(datetime,shared_data%params%datetime) + if(mode.eq.9 .and. fsplit.ne.2700) shared_data%params%nfa=fsplit + if(mode.eq.8) then +! "Early" decoding pass, FT8 only, when jt9 reads data from disk + nearly=41 + shared_data%params%nzhsym=nearly + id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456) + id2a(nearly*3456+1:)=0 + call multimode_decoder(shared_data%ss,id2a, & + shared_data%params,nfsample) + nearly=47 + shared_data%params%nzhsym=nearly + id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456) + id2a(nearly*3456+1:)=0 + call multimode_decoder(shared_data%ss,id2a, & + shared_data%params,nfsample) + id2a(nearly*3456+1:50*3456)=shared_data%id2(nearly*3456+1:50*3456) + id2a(50*3456+1:)=0 + shared_data%params%nzhsym=50 + call multimode_decoder(shared_data%ss,id2a, & + shared_data%params,nfsample) + cycle + + ! MSK144 + else if (mode .eq. 144) then + call decode_msk144(shared_data%id2, shared_data%params, data_dir) + endif + +! Normal decoding pass + call multimode_decoder(shared_data%ss,shared_data%id2, & + shared_data%params,nfsample) + enddo + + call timer('jt9 ',1) + call timer('jt9 ',101) + +999 continue +! Output decoder statistics + call fini_timer () +! Save FFTW wisdom and free memory + 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() +end program jt9 diff --git a/lib/jt9_decode.f90 b/lib/jt9_decode.f90 index 7e20b823..d862504a 100755 --- a/lib/jt9_decode.f90 +++ b/lib/jt9_decode.f90 @@ -1,172 +1,172 @@ -module jt9_decode - - type :: jt9_decoder - procedure(jt9_decode_callback), pointer :: callback - contains - procedure :: decode - end type jt9_decoder - - abstract interface - subroutine jt9_decode_callback (this, sync, snr, dt, freq, drift, & - decoded) - import jt9_decoder - implicit none - class(jt9_decoder), intent(inout) :: this - real, intent(in) :: sync - integer, intent(in) :: snr - real, intent(in) :: dt - real, intent(in) :: freq - integer, intent(in) :: drift - character(len=22), intent(in) :: decoded - end subroutine jt9_decode_callback - end interface - -contains - - subroutine decode(this,callback,ss,id2,nfqso,newdat,npts8,nfa, & - nfsplit,nfb,ntol,nzhsym,nagain,ndepth,nmode,nsubmode,nexp_decode) - use timer_module, only: timer - - include 'constants.f90' - class(jt9_decoder), intent(inout) :: this - procedure(jt9_decode_callback) :: callback - real ss(184,NSMAX) - logical, intent(in) :: newdat, nagain - character*22 msg - real*4 ccfred(NSMAX) - real*4 red2(NSMAX) - logical ccfok(NSMAX) - logical done(NSMAX) - integer*2 id2(NTMAX*12000) - integer*1 i1SoftSymbols(207) - common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano - save ccfred,red2 - - if(nexp_decode.eq.-99) stop !Silence compiler warning - this%callback => callback - if(nmode.eq.9 .and. nsubmode.ge.1) then - call decode9w(nfqso,ntol,nsubmode,ss,id2,sync,nsnr,xdt,freq,msg) - if (associated(this%callback)) then - ndrift=0 - call this%callback(sync,nsnr,xdt,freq,ndrift,msg) - end if - go to 999 - endif - - nsynced=0 - ndecoded=0 - nsps=6912 !Params for JT9-1 - df3=1500.0/2048.0 - - tstep=0.5*nsps/12000.0 !Half-symbol step (seconds) - done=.false. - - nf0=0 - nf1=nfa - if(nmode.eq.65+9) nf1=nfsplit - ia=max(1,nint((nf1-nf0)/df3)) - ib=min(NSMAX,nint((nfb-nf0)/df3)) - lag1=-int(2.5/tstep + 0.9999) - lag2=int(5.0/tstep + 0.9999) - if(newdat) then - call timer('sync9 ',0) - call sync9(ss,nzhsym,lag1,lag2,ia,ib,ccfred,red2,ipk) - call timer('sync9 ',1) - endif - - nsps8=nsps/8 - df8=1500.0/nsps8 - dblim=db(864.0/nsps8) - 26.2 - - ia1=1 !quel compiler gripe - ib1=1 !quel compiler gripe - do nqd=1,0,-1 - limit=5000 - ccflim=3.0 - red2lim=1.6 - schklim=2.2 - if(iand(ndepth,7).eq.2) then - limit=10000 - ccflim=2.7 - endif - if(iand(ndepth,7).eq.3 .or. nqd.eq.1) then - limit=30000 - ccflim=2.5 - schklim=2.0 - endif - if(nagain) then - limit=100000 - ccflim=2.4 - schklim=1.8 - endif - ccfok=.false. - - if(nqd.eq.1) then - nfa1=nfqso-ntol - nfb1=nfqso+ntol - ia=max(1,nint((nfa1-nf0)/df3)) - ib=min(NSMAX,nint((nfb1-nf0)/df3)) - ccfok(ia:ib)=(ccfred(ia:ib).gt.(ccflim-2.0)) .and. & - (red2(ia:ib).gt.(red2lim-1.0)) - ia1=ia - ib1=ib - else - nfa1=nf1 - nfb1=nfb - ia=max(1,nint((nfa1-nf0)/df3)) - ib=min(NSMAX,nint((nfb1-nf0)/df3)) - do i=ia,ib - ccfok(i)=ccfred(i).gt.ccflim .and. red2(i).gt.red2lim - enddo - ccfok(ia1:ib1)=.false. - endif - - fgood=0. - do i=ia,ib - if(done(i) .or. (.not.ccfok(i))) cycle - f=(i-1)*df3 - if(nqd.eq.1 .or. & - (ccfred(i).ge.ccflim .and. abs(f-fgood).gt.10.0*df8)) then - - call timer('softsym ',0) - fpk=nf0 + df3*(i-1) - call softsym(id2,npts8,nsps8,newdat,fpk,syncpk,snrdb,xdt, & - freq,drift,a3,schk,i1SoftSymbols) - call timer('softsym ',1) - - sync=(syncpk+1)/4.0 - if(nqd.eq.1 .and. ((sync.lt.0.5) .or. (schk.lt.1.0))) cycle - if(nqd.ne.1 .and. ((sync.lt.1.0) .or. (schk.lt.1.5))) cycle - - call timer('jt9fano ',0) - call jt9fano(i1SoftSymbols,limit,nlim,msg) - call timer('jt9fano ',1) - - if(sync.lt.0.0 .or. snrdb.lt.dblim-2.0) sync=0.0 - nsync=int(sync) - if(nsync.gt.10) nsync=10 - nsnr=nint(snrdb) - ndrift=nint(drift/df3) - num9=num9+1 - - if(msg.ne.' ') then - numfano=numfano+1 - if (associated(this%callback)) then - call this%callback(sync,nsnr,xdt,freq,ndrift,msg) - end if - iaa=max(1,i-1) - ibb=min(NSMAX,i+22) - fgood=f - nsynced=1 - ndecoded=1 - ccfok(iaa:ibb)=.false. - done(iaa:ibb)=.true. - endif - endif - enddo - if(nagain) exit - enddo - -999 return - end subroutine decode -end module jt9_decode +module jt9_decode + + type :: jt9_decoder + procedure(jt9_decode_callback), pointer :: callback + contains + procedure :: decode + end type jt9_decoder + + abstract interface + subroutine jt9_decode_callback (this, sync, snr, dt, freq, drift, & + decoded) + import jt9_decoder + implicit none + class(jt9_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + real, intent(in) :: freq + integer, intent(in) :: drift + character(len=22), intent(in) :: decoded + end subroutine jt9_decode_callback + end interface + +contains + + subroutine decode(this,callback,ss,id2,nfqso,newdat,npts8,nfa, & + nfsplit,nfb,ntol,nzhsym,nagain,ndepth,nmode,nsubmode,nexp_decode) + use timer_module, only: timer + + include 'constants.f90' + class(jt9_decoder), intent(inout) :: this + procedure(jt9_decode_callback) :: callback + real ss(184,NSMAX) + logical, intent(in) :: newdat, nagain + character*22 msg + real*4 ccfred(NSMAX) + real*4 red2(NSMAX) + logical ccfok(NSMAX) + logical done(NSMAX) + integer*2 id2(NTMAX*12000) + integer*1 i1SoftSymbols(207) + common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano + save ccfred,red2 + + if(nexp_decode.eq.-99) stop !Silence compiler warning + this%callback => callback + if(nmode.eq.9 .and. nsubmode.ge.1) then + call decode9w(nfqso,ntol,nsubmode,ss,id2,sync,nsnr,xdt,freq,msg) + if (associated(this%callback)) then + ndrift=0 + call this%callback(sync,nsnr,xdt,freq,ndrift,msg) + end if + go to 999 + endif + + nsynced=0 + ndecoded=0 + nsps=6912 !Params for JT9-1 + df3=1500.0/2048.0 + + tstep=0.5*nsps/12000.0 !Half-symbol step (seconds) + done=.false. + + nf0=0 + nf1=nfa + if(nmode.eq.65+9) nf1=nfsplit + ia=max(1,nint((nf1-nf0)/df3)) + ib=min(NSMAX,nint((nfb-nf0)/df3)) + lag1=-int(2.5/tstep + 0.9999) + lag2=int(5.0/tstep + 0.9999) + if(newdat) then + call timer('sync9 ',0) + call sync9(ss,nzhsym,lag1,lag2,ia,ib,ccfred,red2,ipk) + call timer('sync9 ',1) + endif + + nsps8=nsps/8 + df8=1500.0/nsps8 + dblim=db(864.0/nsps8) - 26.2 + + ia1=1 !quel compiler gripe + ib1=1 !quel compiler gripe + do nqd=1,0,-1 + limit=5000 + ccflim=3.0 + red2lim=1.6 + schklim=2.2 + if(iand(ndepth,7).eq.2) then + limit=10000 + ccflim=2.7 + endif + if(iand(ndepth,7).eq.3 .or. nqd.eq.1) then + limit=30000 + ccflim=2.5 + schklim=2.0 + endif + if(nagain) then + limit=100000 + ccflim=2.4 + schklim=1.8 + endif + ccfok=.false. + + if(nqd.eq.1) then + nfa1=nfqso-ntol + nfb1=nfqso+ntol + ia=max(1,nint((nfa1-nf0)/df3)) + ib=min(NSMAX,nint((nfb1-nf0)/df3)) + ccfok(ia:ib)=(ccfred(ia:ib).gt.(ccflim-2.0)) .and. & + (red2(ia:ib).gt.(red2lim-1.0)) + ia1=ia + ib1=ib + else + nfa1=nf1 + nfb1=nfb + ia=max(1,nint((nfa1-nf0)/df3)) + ib=min(NSMAX,nint((nfb1-nf0)/df3)) + do i=ia,ib + ccfok(i)=ccfred(i).gt.ccflim .and. red2(i).gt.red2lim + enddo + ccfok(ia1:ib1)=.false. + endif + + fgood=0. + do i=ia,ib + if(done(i) .or. (.not.ccfok(i))) cycle + f=(i-1)*df3 + if(nqd.eq.1 .or. & + (ccfred(i).ge.ccflim .and. abs(f-fgood).gt.10.0*df8)) then + + call timer('softsym ',0) + fpk=nf0 + df3*(i-1) + call softsym(id2,npts8,nsps8,newdat,fpk,syncpk,snrdb,xdt, & + freq,drift,a3,schk,i1SoftSymbols) + call timer('softsym ',1) + + sync=(syncpk+1)/4.0 + if(nqd.eq.1 .and. ((sync.lt.0.5) .or. (schk.lt.1.0))) cycle + if(nqd.ne.1 .and. ((sync.lt.1.0) .or. (schk.lt.1.5))) cycle + + call timer('jt9fano ',0) + call jt9fano(i1SoftSymbols,limit,nlim,msg) + call timer('jt9fano ',1) + + if(sync.lt.0.0 .or. snrdb.lt.dblim-2.0) sync=0.0 + nsync=int(sync) + if(nsync.gt.10) nsync=10 + nsnr=nint(snrdb) + ndrift=nint(drift/df3) + num9=num9+1 + + if(msg.ne.' ') then + numfano=numfano+1 + if (associated(this%callback)) then + call this%callback(sync,nsnr,xdt,freq,ndrift,msg) + end if + iaa=max(1,i-1) + ibb=min(NSMAX,i+22) + fgood=f + nsynced=1 + ndecoded=1 + ccfok(iaa:ibb)=.false. + done(iaa:ibb)=.true. + endif + endif + enddo + if(nagain) exit + enddo + +999 return + end subroutine decode +end module jt9_decode diff --git a/lib/jt9a.f90 b/lib/jt9a.f90 index aa81efd8..546ef924 100755 --- a/lib/jt9a.f90 +++ b/lib/jt9a.f90 @@ -1,102 +1,102 @@ -subroutine jt9a() - use, intrinsic :: iso_c_binding, only: c_f_pointer, c_null_char, c_bool - use prog_args - use timer_module, only: timer - use timer_impl, only: init_timer !, limtrace - use shmem - - include 'jt9com.f90' - - integer*2 id2a(180000) -! Multiple instances: - type(dec_data), pointer, volatile :: shared_data !also makes target volatile - type(params_block) :: local_params - logical(c_bool) :: ok - - call init_timer (trim(data_dir)//'/timer.out') -! open(23,file=trim(data_dir)//'/CALL3.TXT',status='unknown') - -! limtrace=-1 !Disable all calls to timer() - -! Multiple instances: set the shared memory key before attaching - call shmem_setkey(trim(shm_key)//c_null_char) - ok=shmem_attach() - if(.not.ok) call abort - msdelay=30 - call c_f_pointer(shmem_address(),shared_data) - -! Terminate if ipc(2) is 999 -10 ok=shmem_lock() - if(.not.ok) call abort - if(shared_data%ipc(2).eq.999.0) then - ok=shmem_unlock() - ok=shmem_detach() - go to 999 - endif -! Wait here until GUI has set ipc(2) to 1 - if(shared_data%ipc(2).ne.1) then - ok=shmem_unlock() - if(.not.ok) call abort - call sleep_msec(msdelay) - go to 10 - endif - shared_data%ipc(2)=0 - - nbytes=shmem_size() - if(nbytes.le.0) then - ok=shmem_unlock() - ok=shmem_detach() - print*,'jt9a: Shared memory does not exist.' - print*,"Must start 'jt9 -s ' from within WSJT-X." - go to 999 - endif - local_params=shared_data%params !save a copy because wsjtx carries on accessing - ok=shmem_unlock() - if(.not.ok) call abort - call flush(6) - call timer('decoder ',0) - if(local_params%nmode.eq.8 .and. local_params%ndiskdat .and. & - .not. local_params%nagain) then -! Early decoding pass, FT8 only, when wsjtx reads from disk - nearly=41 - local_params%nzhsym=nearly - id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456) - id2a(nearly*3456+1:)=0 - call multimode_decoder(shared_data%ss,id2a,local_params,12000) - nearly=47 - local_params%nzhsym=nearly - id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456) - id2a(nearly*3456+1:)=0 - call multimode_decoder(shared_data%ss,id2a,local_params,12000) - local_params%nzhsym=50 - endif - - if(local_params%nmode .eq. 144) then - ! MSK144 - call decode_msk144(shared_data%id2, shared_data%params, data_dir) - else - ! Normal decoding pass - call multimode_decoder(shared_data%ss,shared_data%id2,local_params,12000) - endif - - call timer('decoder ',1) - - -! Wait here until GUI routine decodeDone() has set ipc(3) to 1 -100 ok=shmem_lock() - if(.not.ok) call abort - if(shared_data%ipc(3).ne.1) then - ok=shmem_unlock() - if(.not.ok) call abort - call sleep_msec(msdelay) - go to 100 - endif - shared_data%ipc(3)=0 - ok=shmem_unlock() - if(.not.ok) call abort - go to 10 - -999 call timer('decoder ',101) - - return -end subroutine jt9a +subroutine jt9a() + use, intrinsic :: iso_c_binding, only: c_f_pointer, c_null_char, c_bool + use prog_args + use timer_module, only: timer + use timer_impl, only: init_timer !, limtrace + use shmem + + include 'jt9com.f90' + + integer*2 id2a(180000) +! Multiple instances: + type(dec_data), pointer, volatile :: shared_data !also makes target volatile + type(params_block) :: local_params + logical(c_bool) :: ok + + call init_timer (trim(data_dir)//'/timer.out') +! open(23,file=trim(data_dir)//'/CALL3.TXT',status='unknown') + +! limtrace=-1 !Disable all calls to timer() + +! Multiple instances: set the shared memory key before attaching + call shmem_setkey(trim(shm_key)//c_null_char) + ok=shmem_attach() + if(.not.ok) call abort + msdelay=30 + call c_f_pointer(shmem_address(),shared_data) + +! Terminate if ipc(2) is 999 +10 ok=shmem_lock() + if(.not.ok) call abort + if(shared_data%ipc(2).eq.999.0) then + ok=shmem_unlock() + ok=shmem_detach() + go to 999 + endif +! Wait here until GUI has set ipc(2) to 1 + if(shared_data%ipc(2).ne.1) then + ok=shmem_unlock() + if(.not.ok) call abort + call sleep_msec(msdelay) + go to 10 + endif + shared_data%ipc(2)=0 + + nbytes=shmem_size() + if(nbytes.le.0) then + ok=shmem_unlock() + ok=shmem_detach() + print*,'jt9a: Shared memory does not exist.' + print*,"Must start 'jt9 -s ' from within WSJT-X." + go to 999 + endif + local_params=shared_data%params !save a copy because wsjtx carries on accessing + ok=shmem_unlock() + if(.not.ok) call abort + call flush(6) + call timer('decoder ',0) + if(local_params%nmode.eq.8 .and. local_params%ndiskdat .and. & + .not. local_params%nagain) then +! Early decoding pass, FT8 only, when wsjtx reads from disk + nearly=41 + local_params%nzhsym=nearly + id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456) + id2a(nearly*3456+1:)=0 + call multimode_decoder(shared_data%ss,id2a,local_params,12000) + nearly=47 + local_params%nzhsym=nearly + id2a(1:nearly*3456)=shared_data%id2(1:nearly*3456) + id2a(nearly*3456+1:)=0 + call multimode_decoder(shared_data%ss,id2a,local_params,12000) + local_params%nzhsym=50 + endif + + if(local_params%nmode .eq. 144) then + ! MSK144 + call decode_msk144(shared_data%id2, shared_data%params, data_dir) + else + ! Normal decoding pass + call multimode_decoder(shared_data%ss,shared_data%id2,local_params,12000) + endif + + call timer('decoder ',1) + + +! Wait here until GUI routine decodeDone() has set ipc(3) to 1 +100 ok=shmem_lock() + if(.not.ok) call abort + if(shared_data%ipc(3).ne.1) then + ok=shmem_unlock() + if(.not.ok) call abort + call sleep_msec(msdelay) + go to 100 + endif + shared_data%ipc(3)=0 + ok=shmem_unlock() + if(.not.ok) call abort + go to 10 + +999 call timer('decoder ',101) + + return +end subroutine jt9a diff --git a/lib/jt9code.f90 b/lib/jt9code.f90 index 927e0e00..0ab96d85 100755 --- a/lib/jt9code.f90 +++ b/lib/jt9code.f90 @@ -1,86 +1,86 @@ -program jt9code - -! Generate simulated data for testing of WSJT-X - - character*22 msg,msgchk,msg0,msg1,decoded,cok*3,bad*1,msgtype*10,expected - integer*4 i4tone(85) !Channel symbols (values 0-8) - include 'testmsg.f90' - include 'jt9sync.f90' - - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: jt9code "message"' - print*,' jt9code -t' - go to 999 - endif - - call getarg(1,msg) - nmsg=1 - if(msg(1:2).eq."-t") then - if (NTEST+5 > MAXTEST) then - write(*,*) "NTEST exceed MAXTEST" - endif - testmsg(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" - testmsg(NTEST+2)="KA1ABC WB9XYZ OOO" - testmsg(NTEST+3)="RO" - testmsg(NTEST+4)="RRR" - testmsg(NTEST+5)="73" - testmsgchk(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" - testmsgchk(NTEST+2)="KA1ABC WB9XYZ OOO" - testmsgchk(NTEST+3)="RO" - testmsgchk(NTEST+4)="RRR" - testmsgchk(NTEST+5)="73" - nmsg=NTEST+5 - endif - - write(*,1010) -1010 format(" Message Decoded Err? Type Expected"/ & - 76("-")) - do imsg=1,nmsg - if(nmsg.gt.1) then - msg=testmsg(imsg) - msgchk=testmsgchk(imsg) - endif - call fmtmsg(msg,iz) !To upper case, collapse multiple blanks - msg0=msg - ichk=0 - call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report - msg1=msg !Message without "OOO" - - if(nspecial.gt.0) then !or is a shorthand message - if(nspecial.eq.2) decoded="RO" - if(nspecial.eq.3) decoded="RRR" - if(nspecial.eq.4) decoded="73" - itype=-1 - msgtype="Shorthand" - go to 10 - endif - - call gen9(msg,ichk,decoded,i4tone,itype) !Encode message into tone #s - - msgtype="" - if(itype.eq.1) msgtype="Std Msg" - if(itype.eq.2) msgtype="Type 1 pfx" - if(itype.eq.3) msgtype="Type 1 sfx" - if(itype.eq.4) msgtype="Type 2 pfx" - if(itype.eq.5) msgtype="Type 2 sfx" - if(itype.eq.6) msgtype="Free text" - - if(cok.eq."OOO") decoded(20:22)=cok - call fmtmsg(decoded,iz) - -10 bad=" " - expected = 'EXACT' - if(decoded.ne.msg0) then - bad="*" - if(decoded(1:13).eq.msg0(1:13) .and. & - decoded(14:22).eq. ' ') expected = 'TRUNCATED' - endif - write(*,1020) imsg,msg0,decoded,bad,itype,msgtype,expected -1020 format(i2,'.',1x,a22,1x,a22,1x,a1,i3,":",a10,2x,a22) - enddo - - if(nmsg.eq.1) write(*,1030) i4tone -1030 format(/'Channel symbols'/(30i2)) - -999 end program jt9code +program jt9code + +! Generate simulated data for testing of WSJT-X + + character*22 msg,msgchk,msg0,msg1,decoded,cok*3,bad*1,msgtype*10,expected + integer*4 i4tone(85) !Channel symbols (values 0-8) + include 'testmsg.f90' + include 'jt9sync.f90' + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: jt9code "message"' + print*,' jt9code -t' + go to 999 + endif + + call getarg(1,msg) + nmsg=1 + if(msg(1:2).eq."-t") then + if (NTEST+5 > MAXTEST) then + write(*,*) "NTEST exceed MAXTEST" + endif + testmsg(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" + testmsg(NTEST+2)="KA1ABC WB9XYZ OOO" + testmsg(NTEST+3)="RO" + testmsg(NTEST+4)="RRR" + testmsg(NTEST+5)="73" + testmsgchk(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" + testmsgchk(NTEST+2)="KA1ABC WB9XYZ OOO" + testmsgchk(NTEST+3)="RO" + testmsgchk(NTEST+4)="RRR" + testmsgchk(NTEST+5)="73" + nmsg=NTEST+5 + endif + + write(*,1010) +1010 format(" Message Decoded Err? Type Expected"/ & + 76("-")) + do imsg=1,nmsg + if(nmsg.gt.1) then + msg=testmsg(imsg) + msgchk=testmsgchk(imsg) + endif + call fmtmsg(msg,iz) !To upper case, collapse multiple blanks + msg0=msg + ichk=0 + call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report + msg1=msg !Message without "OOO" + + if(nspecial.gt.0) then !or is a shorthand message + if(nspecial.eq.2) decoded="RO" + if(nspecial.eq.3) decoded="RRR" + if(nspecial.eq.4) decoded="73" + itype=-1 + msgtype="Shorthand" + go to 10 + endif + + call gen9(msg,ichk,decoded,i4tone,itype) !Encode message into tone #s + + msgtype="" + if(itype.eq.1) msgtype="Std Msg" + if(itype.eq.2) msgtype="Type 1 pfx" + if(itype.eq.3) msgtype="Type 1 sfx" + if(itype.eq.4) msgtype="Type 2 pfx" + if(itype.eq.5) msgtype="Type 2 sfx" + if(itype.eq.6) msgtype="Free text" + + if(cok.eq."OOO") decoded(20:22)=cok + call fmtmsg(decoded,iz) + +10 bad=" " + expected = 'EXACT' + if(decoded.ne.msg0) then + bad="*" + if(decoded(1:13).eq.msg0(1:13) .and. & + decoded(14:22).eq. ' ') expected = 'TRUNCATED' + endif + write(*,1020) imsg,msg0,decoded,bad,itype,msgtype,expected +1020 format(i2,'.',1x,a22,1x,a22,1x,a1,i3,":",a10,2x,a22) + enddo + + if(nmsg.eq.1) write(*,1030) i4tone +1030 format(/'Channel symbols'/(30i2)) + +999 end program jt9code diff --git a/lib/jt9com.f90 b/lib/jt9com.f90 index 2e044422..3012a424 100755 --- a/lib/jt9com.f90 +++ b/lib/jt9com.f90 @@ -1,62 +1,62 @@ - use, intrinsic :: iso_c_binding, only: c_int, c_short, c_float, c_char, c_bool - - include 'constants.f90' - - ! - ! these structures must be kept in sync with ../commons.h - ! - type, bind(C) :: params_block - integer(c_int) :: nutc - logical(c_bool) :: ndiskdat - integer(c_int) :: ntr - integer(c_int) :: nQSOProgress ! See MainWindow::m_QSOProgress for values - integer(c_int) :: nfqso - integer(c_int) :: nftx - logical(c_bool) :: newdat - integer(c_int) :: npts8 - integer(c_int) :: nfa - integer(c_int) :: nfsplit - integer(c_int) :: nfb - integer(c_int) :: ntol - integer(c_int) :: kin - integer(c_int) :: nzhsym - integer(c_int) :: nsubmode - logical(c_bool) :: nagain - integer(c_int) :: ndepth - logical(c_bool) :: lft8apon - logical(c_bool) :: lapcqonly - logical(c_bool) :: ljt65apon - integer(c_int) :: napwid - integer(c_int) :: ntxmode - integer(c_int) :: nmode - integer(c_int) :: minw - logical(c_bool) :: nclearave - integer(c_int) :: minsync - real(c_float) :: emedelay - real(c_float) :: dttol - integer(c_int) :: nlist - integer(c_int) :: listutc(10) - integer(c_int) :: n2pass - integer(c_int) :: nranera - integer(c_int) :: naggressive - logical(c_bool) :: nrobust - integer(c_int) :: nexp_decode - integer(c_int) :: max_drift - character(kind=c_char) :: datetime(20) - character(kind=c_char) :: mycall(12) - character(kind=c_char) :: mygrid(6) - character(kind=c_char) :: hiscall(12) - character(kind=c_char) :: hisgrid(6) - logical(c_bool) :: b_even_seq - logical(c_bool) :: b_superfox - integer(c_int) :: yymmdd - end type params_block - - type, bind(C) :: dec_data - integer(c_int) :: ipc(3) - real(c_float) :: ss(184,NSMAX) - real(c_float) :: savg(NSMAX) - real(c_float) :: sred(5760) - integer(c_short) :: id2(NMAX) - type(params_block) :: params - end type dec_data + use, intrinsic :: iso_c_binding, only: c_int, c_short, c_float, c_char, c_bool + + include 'constants.f90' + + ! + ! these structures must be kept in sync with ../commons.h + ! + type, bind(C) :: params_block + integer(c_int) :: nutc + logical(c_bool) :: ndiskdat + integer(c_int) :: ntr + integer(c_int) :: nQSOProgress ! See MainWindow::m_QSOProgress for values + integer(c_int) :: nfqso + integer(c_int) :: nftx + logical(c_bool) :: newdat + integer(c_int) :: npts8 + integer(c_int) :: nfa + integer(c_int) :: nfsplit + integer(c_int) :: nfb + integer(c_int) :: ntol + integer(c_int) :: kin + integer(c_int) :: nzhsym + integer(c_int) :: nsubmode + logical(c_bool) :: nagain + integer(c_int) :: ndepth + logical(c_bool) :: lft8apon + logical(c_bool) :: lapcqonly + logical(c_bool) :: ljt65apon + integer(c_int) :: napwid + integer(c_int) :: ntxmode + integer(c_int) :: nmode + integer(c_int) :: minw + logical(c_bool) :: nclearave + integer(c_int) :: minsync + real(c_float) :: emedelay + real(c_float) :: dttol + integer(c_int) :: nlist + integer(c_int) :: listutc(10) + integer(c_int) :: n2pass + integer(c_int) :: nranera + integer(c_int) :: naggressive + logical(c_bool) :: nrobust + integer(c_int) :: nexp_decode + integer(c_int) :: max_drift + character(kind=c_char) :: datetime(20) + character(kind=c_char) :: mycall(12) + character(kind=c_char) :: mygrid(6) + character(kind=c_char) :: hiscall(12) + character(kind=c_char) :: hisgrid(6) + logical(c_bool) :: b_even_seq + logical(c_bool) :: b_superfox + integer(c_int) :: yymmdd + end type params_block + + type, bind(C) :: dec_data + integer(c_int) :: ipc(3) + real(c_float) :: ss(184,NSMAX) + real(c_float) :: savg(NSMAX) + real(c_float) :: sred(5760) + integer(c_short) :: id2(NMAX) + type(params_block) :: params + end type dec_data diff --git a/lib/jt9w.f90 b/lib/jt9w.f90 index c4cd4039..47623e7b 100755 --- a/lib/jt9w.f90 +++ b/lib/jt9w.f90 @@ -1,28 +1,28 @@ -program jt9w - - parameter (NSMAX=6827,NZMAX=60*12000) - real ss(184,NSMAX) - real ref(NSMAX) - integer*2 id2(NZMAX) - character*12 arg - character*22 decoded - - call getarg(1,arg) - read(arg,*) iutc - - open(20,file='refspec.dat',status='old') - do i=1,NSMAX - read(20,*) j,freq,ref(i) - enddo - - do ifile=1,999 - read(60,end=999) nutc,nfqso,ntol,ndepth,nmode,nsubmode,ss,id2 - if(nutc.ne.iutc) cycle - ntol=100 - call decode9w(nutc,nfqso,ntol,nsubmode,ss,id2,sync,nsnr,xdt,freq,decoded) - write(*,1100) nutc,nsnr,xdt1-1.0,nint(freq),decoded -1100 format(i4.4,i4,f5.1,i5,1x,'@',1x,a22) - exit - enddo - -999 end program jt9w +program jt9w + + parameter (NSMAX=6827,NZMAX=60*12000) + real ss(184,NSMAX) + real ref(NSMAX) + integer*2 id2(NZMAX) + character*12 arg + character*22 decoded + + call getarg(1,arg) + read(arg,*) iutc + + open(20,file='refspec.dat',status='old') + do i=1,NSMAX + read(20,*) j,freq,ref(i) + enddo + + do ifile=1,999 + read(60,end=999) nutc,nfqso,ntol,ndepth,nmode,nsubmode,ss,id2 + if(nutc.ne.iutc) cycle + ntol=100 + call decode9w(nutc,nfqso,ntol,nsubmode,ss,id2,sync,nsnr,xdt,freq,decoded) + write(*,1100) nutc,nsnr,xdt1-1.0,nint(freq),decoded +1100 format(i4.4,i4,f5.1,i5,1x,'@',1x,a22) + exit + enddo + +999 end program jt9w diff --git a/lib/ldpc_128_90_b_generator.f90 b/lib/ldpc_128_90_b_generator.f90 index 3082b290..97cb2b85 100755 --- a/lib/ldpc_128_90_b_generator.f90 +++ b/lib/ldpc_128_90_b_generator.f90 @@ -1,41 +1,41 @@ -character*23 g(38) - -data g/ & - "c555076254d8161b5cf0d3c", & - "de721b14e8339ab48de8e54", & - "e72d0efb6ca44934a896ca0", & - "631b7cc783a5e626c360598", & - "7050206b9b2e40439d17d94", & - "2f31c22ab472282d65cde44", & - "822baa20e8bcd6487d34268", & - "f9a85b9d103459b8ac34830", & - "60335e63618f9e59e031a5c", & - "b106c464771df41ab75884c", & - "3936fcebf87320d200e6b1c", & - "00135e63218f1c59c031e5c", & - "554abf55a1605425b8e8248", & - "2211850e5b32c02e42c85ec", & - "853e66d64fdf2f5cf4237a8", & - "90592d932a0c8e8190e6c50", & - "d0cdf8954d48457b6a43df0", & - "83714b5735b5bcd718887f0", & - "3146c024731df43a3750844", & - "a231a50e5232c0ae40c8dac", & - "8f5f0d73fab5d0d57bb9c48", & - "5650a8094847925466e560c", & - "5842d5c55ff32151f36ca3c", & - "0f571d7bfab4d0c57bfbcc8", & - "bb68edb9987ea6a4f56a214", & - "9d7cb35b100c0e8d07cff80", & - "6774a36c46e8d7b518780b0", & - "b07ca6f22cc3db62ca73fac", & - "d6610575c99c82edcddd028", & - "e64c7bb5d67de03d1fb0824", & - "e9bb04fe35bb65a16e856ec", & - "6c5c41bc591174e3b81e950", & - "49b480238e0623d1dd61e08", & - "c48ae6d581d94c8c2b4a8a0", & - "a16ace594ec778f95e5020c", & - "ef2cd3309b2a4e8e9a98614", & - "06008a62f368d236fbf2998", & - "015fe1f7dd017a9f67be59c"/ +character*23 g(38) + +data g/ & + "c555076254d8161b5cf0d3c", & + "de721b14e8339ab48de8e54", & + "e72d0efb6ca44934a896ca0", & + "631b7cc783a5e626c360598", & + "7050206b9b2e40439d17d94", & + "2f31c22ab472282d65cde44", & + "822baa20e8bcd6487d34268", & + "f9a85b9d103459b8ac34830", & + "60335e63618f9e59e031a5c", & + "b106c464771df41ab75884c", & + "3936fcebf87320d200e6b1c", & + "00135e63218f1c59c031e5c", & + "554abf55a1605425b8e8248", & + "2211850e5b32c02e42c85ec", & + "853e66d64fdf2f5cf4237a8", & + "90592d932a0c8e8190e6c50", & + "d0cdf8954d48457b6a43df0", & + "83714b5735b5bcd718887f0", & + "3146c024731df43a3750844", & + "a231a50e5232c0ae40c8dac", & + "8f5f0d73fab5d0d57bb9c48", & + "5650a8094847925466e560c", & + "5842d5c55ff32151f36ca3c", & + "0f571d7bfab4d0c57bfbcc8", & + "bb68edb9987ea6a4f56a214", & + "9d7cb35b100c0e8d07cff80", & + "6774a36c46e8d7b518780b0", & + "b07ca6f22cc3db62ca73fac", & + "d6610575c99c82edcddd028", & + "e64c7bb5d67de03d1fb0824", & + "e9bb04fe35bb65a16e856ec", & + "6c5c41bc591174e3b81e950", & + "49b480238e0623d1dd61e08", & + "c48ae6d581d94c8c2b4a8a0", & + "a16ace594ec778f95e5020c", & + "ef2cd3309b2a4e8e9a98614", & + "06008a62f368d236fbf2998", & + "015fe1f7dd017a9f67be59c"/ diff --git a/lib/ldpc_128_90_b_reordered_parity.f90 b/lib/ldpc_128_90_b_reordered_parity.f90 index 680c320b..c46719b4 100755 --- a/lib/ldpc_128_90_b_reordered_parity.f90 +++ b/lib/ldpc_128_90_b_reordered_parity.f90 @@ -1,184 +1,184 @@ -data Mn/ & - 10, 25, 37, 0, & - 1, 19, 20, 0, & - 20, 27, 29, 0, & - 3, 22, 36, 0, & - 4, 26, 30, 0, & - 5, 15, 28, 0, & - 6, 21, 23, 0, & - 7, 16, 32, 0, & - 9, 31, 38, 0, & - 10, 13, 18, 0, & - 11, 20, 37, 0, & - 12, 24, 33, 0, & - 14, 25, 33, 0, & - 15, 17, 32, 0, & - 1, 9, 14, 0, & - 2, 16, 17, 0, & - 3, 5, 18, 0, & - 4, 23, 38, 0, & - 6, 24, 37, 0, & - 7, 25, 35, 0, & - 8, 29, 33, 0, & - 10, 30, 36, 0, & - 11, 27, 28, 0, & - 12, 22, 32, 0, & - 13, 17, 21, 0, & - 10, 19, 31, 0, & - 18, 26, 34, 0, & - 1, 5, 30, 0, & - 2, 19, 25, 0, & - 3, 9, 21, 0, & - 4, 8, 11, 0, & - 6, 35, 38, 0, & - 7, 13, 29, 0, & - 12, 20, 26, 0, & - 14, 24, 27, 0, & - 15, 23, 34, 0, & - 16, 31, 37, 0, & - 10, 22, 28, 0, & - 28, 34, 36, 0, & - 1, 37, 38, 0, & - 2, 5, 13, 0, & - 3, 7, 14, 0, & - 4, 16, 19, 0, & - 6, 18, 29, 0, & - 8, 17, 23, 0, & - 9, 33, 36, 0, & - 11, 12, 35, 0, & - 15, 25, 27, 0, & - 20, 30, 32, 0, & - 21, 24, 26, 0, & - 22, 31, 33, 0, & - 1, 3, 17, 0, & - 2, 8, 36, 0, & - 4, 14, 34, 0, & - 5, 20, 24, 0, & - 6, 12, 30, 0, & - 7, 19, 37, 0, & - 9, 22, 23, 0, & - 10, 27, 35, 0, & - 11, 25, 38, 0, & - 13, 28, 31, 0, & - 11, 15, 29, 0, & - 16, 18, 21, 0, & - 26, 27, 32, 0, & - 1, 4, 10, 0, & - 2, 9, 29, 32, & - 3, 6, 20, 33, & - 5, 21, 31, 34, & - 7, 8, 15, 30, & - 12, 13, 14, 16, & - 17, 22, 26, 37, & - 15, 18, 36, 38, & - 19, 22, 24, 35, & - 12, 23, 25, 28, & - 1, 13, 32, 33, & - 2, 11, 14, 18, & - 3, 10, 26, 38, & - 4, 24, 31, 32, & - 5, 6, 17, 25, & - 7, 9, 24, 28, & - 8, 9, 34, 37, & - 16, 20, 23, 35, & - 19, 21, 27, 30, & - 16, 26, 29, 36, & - 1, 22, 25, 29, & - 2, 3, 15, 37, & - 4, 12, 21, 36, & - 5, 8, 14, 19, & - 6, 7, 10, 34, & - 11, 17, 19, 33, & - 1, 12, 31, 0, & - 2, 4, 33, 0, & - 3, 16, 30, 0, & - 1, 2, 24, 0, & - 5, 23, 27, 0, & - 6, 28, 32, 0, & - 7, 17, 36, 0, & - 8, 22, 38, 0, & - 9, 18, 20, 0, & - 10, 21, 29, 0, & - 11, 13, 34, 0, & - 4, 20, 22, 0, & - 7, 11, 21, 0, & - 14, 35, 37, 0, & - 15, 19, 26, 0, & - 3, 28, 29, 0, & - 9, 13, 35, 0, & - 14, 17, 30, 0, & - 10, 15, 33, 0, & - 5, 12, 37, 0, & - 18, 25, 32, 0, & - 8, 16, 27, 0, & - 19, 34, 38, 0, & - 24, 25, 36, 0, & - 2, 28, 35, 0, & - 19, 23, 36, 0, & - 3, 12, 34, 0, & - 9, 15, 16, 0, & - 4, 5, 7, 0, & - 1, 8, 21, 0, & - 6, 13, 22, 0, & - 11, 24, 30, 0, & - 8, 26, 35, 0, & - 6, 26, 31, 0, & - 14, 32, 38, 0, & - 18, 23, 33, 0, & - 2, 27, 34, 0, & - 17, 29, 31, 0/ - -data Nm/ & - 2, 15, 28, 40, 52, 65, 75, 85, 91, 94, 120, 0, & - 16, 29, 41, 53, 66, 76, 86, 92, 94, 115, 127, 0, & - 4, 17, 30, 42, 52, 67, 77, 86, 93, 106, 117, 0, & - 5, 18, 31, 43, 54, 65, 78, 87, 92, 102, 119, 0, & - 6, 17, 28, 41, 55, 68, 79, 88, 95, 110, 119, 0, & - 7, 19, 32, 44, 56, 67, 79, 89, 96, 121, 124, 0, & - 8, 20, 33, 42, 57, 69, 80, 89, 97, 103, 119, 0, & - 21, 31, 45, 53, 69, 81, 88, 98, 112, 120, 123, 0, & - 9, 15, 30, 46, 58, 66, 80, 81, 99, 107, 118, 0, & - 1, 10, 22, 26, 38, 59, 65, 77, 89, 100, 109, 0, & - 11, 23, 31, 47, 60, 62, 76, 90, 101, 103, 122, 0, & - 12, 24, 34, 47, 56, 70, 74, 87, 91, 110, 117, 0, & - 10, 25, 33, 41, 61, 70, 75, 101, 107, 121, 0, 0, & - 13, 15, 35, 42, 54, 70, 76, 88, 104, 108, 125, 0, & - 6, 14, 36, 48, 62, 69, 72, 86, 105, 109, 118, 0, & - 8, 16, 37, 43, 63, 70, 82, 84, 93, 112, 118, 0, & - 14, 16, 25, 45, 52, 71, 79, 90, 97, 108, 128, 0, & - 10, 17, 27, 44, 63, 72, 76, 99, 111, 126, 0, 0, & - 2, 26, 29, 43, 57, 73, 83, 88, 90, 105, 113, 116, & - 2, 3, 11, 34, 49, 55, 67, 82, 99, 102, 0, 0, & - 7, 25, 30, 50, 63, 68, 83, 87, 100, 103, 120, 0, & - 4, 24, 38, 51, 58, 71, 73, 85, 98, 102, 121, 0, & - 7, 18, 36, 45, 58, 74, 82, 95, 116, 126, 0, 0, & - 12, 19, 35, 50, 55, 73, 78, 80, 94, 114, 122, 0, & - 1, 13, 20, 29, 48, 60, 74, 79, 85, 111, 114, 0, & - 5, 27, 34, 50, 64, 71, 77, 84, 105, 123, 124, 0, & - 3, 23, 35, 48, 59, 64, 83, 95, 112, 127, 0, 0, & - 6, 23, 38, 39, 61, 74, 80, 96, 106, 115, 0, 0, & - 3, 21, 33, 44, 62, 66, 84, 85, 100, 106, 128, 0, & - 5, 22, 28, 49, 56, 69, 83, 93, 108, 122, 0, 0, & - 9, 26, 37, 51, 61, 68, 78, 91, 124, 128, 0, 0, & - 8, 14, 24, 49, 64, 66, 75, 78, 96, 111, 125, 0, & - 12, 13, 21, 46, 51, 67, 75, 90, 92, 109, 126, 0, & - 27, 36, 39, 54, 68, 81, 89, 101, 113, 117, 127, 0, & - 20, 32, 47, 59, 73, 82, 104, 107, 115, 123, 0, 0, & - 4, 22, 39, 46, 53, 72, 84, 87, 97, 114, 116, 0, & - 1, 11, 19, 37, 40, 57, 71, 81, 86, 104, 110, 0, & - 9, 18, 32, 40, 60, 72, 77, 98, 113, 125, 0, 0/ - -data nrw/ & -11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11, & -11,10,12,10,11,11,10,11,11,11,10,10,11,10,10,11, & -11,11,10,11,11,10/ - -data ncw/ & -3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, & -3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, & -3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, & -3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, & -3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, & -4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3, & -3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, & -3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3/ +data Mn/ & + 10, 25, 37, 0, & + 1, 19, 20, 0, & + 20, 27, 29, 0, & + 3, 22, 36, 0, & + 4, 26, 30, 0, & + 5, 15, 28, 0, & + 6, 21, 23, 0, & + 7, 16, 32, 0, & + 9, 31, 38, 0, & + 10, 13, 18, 0, & + 11, 20, 37, 0, & + 12, 24, 33, 0, & + 14, 25, 33, 0, & + 15, 17, 32, 0, & + 1, 9, 14, 0, & + 2, 16, 17, 0, & + 3, 5, 18, 0, & + 4, 23, 38, 0, & + 6, 24, 37, 0, & + 7, 25, 35, 0, & + 8, 29, 33, 0, & + 10, 30, 36, 0, & + 11, 27, 28, 0, & + 12, 22, 32, 0, & + 13, 17, 21, 0, & + 10, 19, 31, 0, & + 18, 26, 34, 0, & + 1, 5, 30, 0, & + 2, 19, 25, 0, & + 3, 9, 21, 0, & + 4, 8, 11, 0, & + 6, 35, 38, 0, & + 7, 13, 29, 0, & + 12, 20, 26, 0, & + 14, 24, 27, 0, & + 15, 23, 34, 0, & + 16, 31, 37, 0, & + 10, 22, 28, 0, & + 28, 34, 36, 0, & + 1, 37, 38, 0, & + 2, 5, 13, 0, & + 3, 7, 14, 0, & + 4, 16, 19, 0, & + 6, 18, 29, 0, & + 8, 17, 23, 0, & + 9, 33, 36, 0, & + 11, 12, 35, 0, & + 15, 25, 27, 0, & + 20, 30, 32, 0, & + 21, 24, 26, 0, & + 22, 31, 33, 0, & + 1, 3, 17, 0, & + 2, 8, 36, 0, & + 4, 14, 34, 0, & + 5, 20, 24, 0, & + 6, 12, 30, 0, & + 7, 19, 37, 0, & + 9, 22, 23, 0, & + 10, 27, 35, 0, & + 11, 25, 38, 0, & + 13, 28, 31, 0, & + 11, 15, 29, 0, & + 16, 18, 21, 0, & + 26, 27, 32, 0, & + 1, 4, 10, 0, & + 2, 9, 29, 32, & + 3, 6, 20, 33, & + 5, 21, 31, 34, & + 7, 8, 15, 30, & + 12, 13, 14, 16, & + 17, 22, 26, 37, & + 15, 18, 36, 38, & + 19, 22, 24, 35, & + 12, 23, 25, 28, & + 1, 13, 32, 33, & + 2, 11, 14, 18, & + 3, 10, 26, 38, & + 4, 24, 31, 32, & + 5, 6, 17, 25, & + 7, 9, 24, 28, & + 8, 9, 34, 37, & + 16, 20, 23, 35, & + 19, 21, 27, 30, & + 16, 26, 29, 36, & + 1, 22, 25, 29, & + 2, 3, 15, 37, & + 4, 12, 21, 36, & + 5, 8, 14, 19, & + 6, 7, 10, 34, & + 11, 17, 19, 33, & + 1, 12, 31, 0, & + 2, 4, 33, 0, & + 3, 16, 30, 0, & + 1, 2, 24, 0, & + 5, 23, 27, 0, & + 6, 28, 32, 0, & + 7, 17, 36, 0, & + 8, 22, 38, 0, & + 9, 18, 20, 0, & + 10, 21, 29, 0, & + 11, 13, 34, 0, & + 4, 20, 22, 0, & + 7, 11, 21, 0, & + 14, 35, 37, 0, & + 15, 19, 26, 0, & + 3, 28, 29, 0, & + 9, 13, 35, 0, & + 14, 17, 30, 0, & + 10, 15, 33, 0, & + 5, 12, 37, 0, & + 18, 25, 32, 0, & + 8, 16, 27, 0, & + 19, 34, 38, 0, & + 24, 25, 36, 0, & + 2, 28, 35, 0, & + 19, 23, 36, 0, & + 3, 12, 34, 0, & + 9, 15, 16, 0, & + 4, 5, 7, 0, & + 1, 8, 21, 0, & + 6, 13, 22, 0, & + 11, 24, 30, 0, & + 8, 26, 35, 0, & + 6, 26, 31, 0, & + 14, 32, 38, 0, & + 18, 23, 33, 0, & + 2, 27, 34, 0, & + 17, 29, 31, 0/ + +data Nm/ & + 2, 15, 28, 40, 52, 65, 75, 85, 91, 94, 120, 0, & + 16, 29, 41, 53, 66, 76, 86, 92, 94, 115, 127, 0, & + 4, 17, 30, 42, 52, 67, 77, 86, 93, 106, 117, 0, & + 5, 18, 31, 43, 54, 65, 78, 87, 92, 102, 119, 0, & + 6, 17, 28, 41, 55, 68, 79, 88, 95, 110, 119, 0, & + 7, 19, 32, 44, 56, 67, 79, 89, 96, 121, 124, 0, & + 8, 20, 33, 42, 57, 69, 80, 89, 97, 103, 119, 0, & + 21, 31, 45, 53, 69, 81, 88, 98, 112, 120, 123, 0, & + 9, 15, 30, 46, 58, 66, 80, 81, 99, 107, 118, 0, & + 1, 10, 22, 26, 38, 59, 65, 77, 89, 100, 109, 0, & + 11, 23, 31, 47, 60, 62, 76, 90, 101, 103, 122, 0, & + 12, 24, 34, 47, 56, 70, 74, 87, 91, 110, 117, 0, & + 10, 25, 33, 41, 61, 70, 75, 101, 107, 121, 0, 0, & + 13, 15, 35, 42, 54, 70, 76, 88, 104, 108, 125, 0, & + 6, 14, 36, 48, 62, 69, 72, 86, 105, 109, 118, 0, & + 8, 16, 37, 43, 63, 70, 82, 84, 93, 112, 118, 0, & + 14, 16, 25, 45, 52, 71, 79, 90, 97, 108, 128, 0, & + 10, 17, 27, 44, 63, 72, 76, 99, 111, 126, 0, 0, & + 2, 26, 29, 43, 57, 73, 83, 88, 90, 105, 113, 116, & + 2, 3, 11, 34, 49, 55, 67, 82, 99, 102, 0, 0, & + 7, 25, 30, 50, 63, 68, 83, 87, 100, 103, 120, 0, & + 4, 24, 38, 51, 58, 71, 73, 85, 98, 102, 121, 0, & + 7, 18, 36, 45, 58, 74, 82, 95, 116, 126, 0, 0, & + 12, 19, 35, 50, 55, 73, 78, 80, 94, 114, 122, 0, & + 1, 13, 20, 29, 48, 60, 74, 79, 85, 111, 114, 0, & + 5, 27, 34, 50, 64, 71, 77, 84, 105, 123, 124, 0, & + 3, 23, 35, 48, 59, 64, 83, 95, 112, 127, 0, 0, & + 6, 23, 38, 39, 61, 74, 80, 96, 106, 115, 0, 0, & + 3, 21, 33, 44, 62, 66, 84, 85, 100, 106, 128, 0, & + 5, 22, 28, 49, 56, 69, 83, 93, 108, 122, 0, 0, & + 9, 26, 37, 51, 61, 68, 78, 91, 124, 128, 0, 0, & + 8, 14, 24, 49, 64, 66, 75, 78, 96, 111, 125, 0, & + 12, 13, 21, 46, 51, 67, 75, 90, 92, 109, 126, 0, & + 27, 36, 39, 54, 68, 81, 89, 101, 113, 117, 127, 0, & + 20, 32, 47, 59, 73, 82, 104, 107, 115, 123, 0, 0, & + 4, 22, 39, 46, 53, 72, 84, 87, 97, 114, 116, 0, & + 1, 11, 19, 37, 40, 57, 71, 81, 86, 104, 110, 0, & + 9, 18, 32, 40, 60, 72, 77, 98, 113, 125, 0, 0/ + +data nrw/ & +11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11, & +11,10,12,10,11,11,10,11,11,11,10,10,11,10,10,11, & +11,11,10,11,11,10/ + +data ncw/ & +3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, & +3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, & +3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, & +3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, & +3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, & +4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3, & +3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, & +3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3/ diff --git a/lib/ldpc_128_90_generator.f90 b/lib/ldpc_128_90_generator.f90 index a1012922..200d1703 100755 --- a/lib/ldpc_128_90_generator.f90 +++ b/lib/ldpc_128_90_generator.f90 @@ -1,41 +1,41 @@ -character*23 g(38) - -data g/ & - "a08ea80879050a5e94da994", & - "59f3b48040ca089c81ee880", & - "e4070262802e31b7b17d3dc", & - "95cbcbaf032dc3d960bacc8", & - "c4d79b5dcc21161a254ffbc", & - "93fde9cdbf2622a70868424", & - "e73b888bb1b01167379ba28", & - "45a0d0a0f39a7ad2439949c", & - "759acef19444bcad79c4964", & - "71eb4dddf4f5ed9e2ea17e0", & - "80f0ad76fb247d6b4ca8d38", & - "184fff3aa1b82dc66640104", & - "ca4e320bb382ed14cbb1094", & - "52514447b90e25b9e459e28", & - "dd10c1666e071956bd0df38", & - "99c332a0b792a2da8ef1ba8", & - "7bd9f688e7ed402e231aaac", & - "00fcad76eb647d6a0ca8c38", & - "6ac8d0499c43b02eed78d70", & - "2c2c764baf795b4788db010", & - "0e907bf9e280d2624823dd0", & - "b857a6e315afd8c1c925e64", & - "8deb58e22d73a141cae3778", & - "22d3cb80d92d6ac132dfe08", & - "754763877b28c187746855c", & - "1d1bb7cf6953732e04ebca4", & - "2c65e0ea4466ab9f5e1deec", & - "6dc530ca37fc916d1f84870", & - "49bccbbee152355be7ac984", & - "e8387f3f4367cf45a150448", & - "8ce25e03d67d51091c81884", & - "b798012ffa40a93852752c8", & - "2e43307933adfca37adc3c8", & - "ca06e0a42ca1ec782d6c06c", & - "c02b762927556a7039e638c", & - "4a3e9b7d08b6807f8619fac", & - "45e8030f68997bb68544424", & - "7e79362c16773efc6482e30"/ +character*23 g(38) + +data g/ & + "a08ea80879050a5e94da994", & + "59f3b48040ca089c81ee880", & + "e4070262802e31b7b17d3dc", & + "95cbcbaf032dc3d960bacc8", & + "c4d79b5dcc21161a254ffbc", & + "93fde9cdbf2622a70868424", & + "e73b888bb1b01167379ba28", & + "45a0d0a0f39a7ad2439949c", & + "759acef19444bcad79c4964", & + "71eb4dddf4f5ed9e2ea17e0", & + "80f0ad76fb247d6b4ca8d38", & + "184fff3aa1b82dc66640104", & + "ca4e320bb382ed14cbb1094", & + "52514447b90e25b9e459e28", & + "dd10c1666e071956bd0df38", & + "99c332a0b792a2da8ef1ba8", & + "7bd9f688e7ed402e231aaac", & + "00fcad76eb647d6a0ca8c38", & + "6ac8d0499c43b02eed78d70", & + "2c2c764baf795b4788db010", & + "0e907bf9e280d2624823dd0", & + "b857a6e315afd8c1c925e64", & + "8deb58e22d73a141cae3778", & + "22d3cb80d92d6ac132dfe08", & + "754763877b28c187746855c", & + "1d1bb7cf6953732e04ebca4", & + "2c65e0ea4466ab9f5e1deec", & + "6dc530ca37fc916d1f84870", & + "49bccbbee152355be7ac984", & + "e8387f3f4367cf45a150448", & + "8ce25e03d67d51091c81884", & + "b798012ffa40a93852752c8", & + "2e43307933adfca37adc3c8", & + "ca06e0a42ca1ec782d6c06c", & + "c02b762927556a7039e638c", & + "4a3e9b7d08b6807f8619fac", & + "45e8030f68997bb68544424", & + "7e79362c16773efc6482e30"/ diff --git a/lib/ldpc_128_90_reordered_parity.f90 b/lib/ldpc_128_90_reordered_parity.f90 index b505741d..b3a5e9b8 100755 --- a/lib/ldpc_128_90_reordered_parity.f90 +++ b/lib/ldpc_128_90_reordered_parity.f90 @@ -1,176 +1,176 @@ -data Mn/ & - 21, 34, 36, & - 1, 8, 28, & - 2, 9, 37, & - 3, 7, 19, & - 4, 16, 32, & - 2, 5, 22, & - 6, 13, 25, & - 10, 31, 33, & - 11, 24, 27, & - 12, 15, 23, & - 14, 18, 26, & - 17, 20, 29, & - 17, 30, 34, & - 6, 34, 35, & - 1, 10, 30, & - 3, 18, 23, & - 4, 12, 25, & - 5, 28, 36, & - 7, 14, 21, & - 8, 15, 31, & - 9, 27, 32, & - 11, 19, 35, & - 13, 16, 37, & - 20, 24, 38, & - 21, 22, 26, & - 12, 29, 33, & - 1, 17, 35, & - 2, 28, 30, & - 3, 10, 32, & - 4, 8, 36, & - 5, 19, 29, & - 6, 20, 27, & - 7, 22, 37, & - 9, 11, 33, & - 13, 24, 26, & - 14, 31, 34, & - 15, 16, 25, & - 13, 18, 38, & - 8, 20, 23, & - 1, 32, 33, & - 2, 17, 19, & - 3, 24, 34, & - 4, 7, 38, & - 5, 11, 31, & - 6, 18, 21, & - 9, 15, 36, & - 10, 16, 28, & - 12, 26, 30, & - 14, 27, 29, & - 22, 25, 35, & - 23, 30, 32, & - 4, 11, 37, & - 1, 14, 23, & - 2, 8, 25, & - 3, 13, 27, & - 5, 10, 37, & - 6, 16, 31, & - 7, 15, 18, & - 9, 22, 24, & - 12, 19, 36, & - 17, 26, 38, & - 20, 21, 33, & - 20, 28, 35, & - 4, 29, 34, & - 1, 26, 36, & - 2, 23, 34, & - 3, 9, 38, & - 5, 6, 17, & - 7, 27, 35, & - 8, 14, 32, & - 10, 15, 22, & - 11, 18, 29, & - 12, 13, 28, & - 16, 19, 33, & - 21, 25, 31, & - 24, 30, 37, & - 1, 3, 21, & - 2, 18, 31, & - 4, 6, 9, & - 5, 8, 33, & - 7, 29, 32, & - 10, 13, 19, & - 11, 22, 23, & - 12, 27, 34, & - 14, 15, 30, & - 16, 27, 38, & - 17, 28, 37, & - 20, 25, 26, & - 5, 24, 35, & - 3, 6, 36, & - 1, 12, 31, & - 2, 4, 33, & - 3, 16, 30, & - 1, 2, 24, & - 5, 23, 27, & - 6, 28, 32, & - 7, 17, 36, & - 8, 22, 38, & - 9, 18, 20, & - 10, 21, 29, & - 11, 13, 34, & - 4, 14, 20, & - 11, 30, 38, & - 14, 35, 37, & - 15, 19, 26, & - 3, 28, 29, & - 7, 8, 9, & - 5, 18, 34, & - 13, 15, 17, & - 12, 16, 35, & - 10, 23, 25, & - 19, 21, 37, & - 17, 27, 31, & - 24, 25, 36, & - 1, 18, 19, & - 6, 26, 33, & - 22, 31, 32, & - 3, 20, 22, & - 4, 21, 27, & - 2, 13, 29, & - 6, 7, 12, & - 15, 24, 32, & - 9, 25, 30, & - 23, 37, 38, & - 5, 16, 26, & - 11, 14, 28, & - 33, 36, 38, & - 8, 10, 35/ - -data Nm/ & - 2, 15, 27, 40, 53, 65, 77, 91, 94, 115, 0, & - 3, 6, 28, 41, 54, 66, 78, 92, 94, 120, 0, & - 4, 16, 29, 42, 55, 67, 77, 90, 93, 106, 118, & - 5, 17, 30, 43, 52, 64, 79, 92, 102, 119, 0, & - 6, 18, 31, 44, 56, 68, 80, 89, 95, 108, 125, & - 7, 14, 32, 45, 57, 68, 79, 90, 96, 116, 121, & - 4, 19, 33, 43, 58, 69, 81, 97, 107, 121, 0, & - 2, 20, 30, 39, 54, 70, 80, 98, 107, 128, 0, & - 3, 21, 34, 46, 59, 67, 79, 99, 107, 123, 0, & - 8, 15, 29, 47, 56, 71, 82, 100, 111, 128, 0, & - 9, 22, 34, 44, 52, 72, 83, 101, 103, 126, 0, & - 10, 17, 26, 48, 60, 73, 84, 91, 110, 121, 0, & - 7, 23, 35, 38, 55, 73, 82, 101, 109, 120, 0, & - 11, 19, 36, 49, 53, 70, 85, 102, 104, 126, 0, & - 10, 20, 37, 46, 58, 71, 85, 105, 109, 122, 0, & - 5, 23, 37, 47, 57, 74, 86, 93, 110, 125, 0, & - 12, 13, 27, 41, 61, 68, 87, 97, 109, 113, 0, & - 11, 16, 38, 45, 58, 72, 78, 99, 108, 115, 0, & - 4, 22, 31, 41, 60, 74, 82, 105, 112, 115, 0, & - 12, 24, 32, 39, 62, 63, 88, 99, 102, 118, 0, & - 1, 19, 25, 45, 62, 75, 77, 100, 112, 119, 0, & - 6, 25, 33, 50, 59, 71, 83, 98, 117, 118, 0, & - 10, 16, 39, 51, 53, 66, 83, 95, 111, 124, 0, & - 9, 24, 35, 42, 59, 76, 89, 94, 114, 122, 0, & - 7, 17, 37, 50, 54, 75, 88, 111, 114, 123, 0, & - 11, 25, 35, 48, 61, 65, 88, 105, 116, 125, 0, & - 9, 21, 32, 49, 55, 69, 84, 86, 95, 113, 119, & - 2, 18, 28, 47, 63, 73, 87, 96, 106, 126, 0, & - 12, 26, 31, 49, 64, 72, 81, 100, 106, 120, 0, & - 13, 15, 28, 48, 51, 76, 85, 93, 103, 123, 0, & - 8, 20, 36, 44, 57, 75, 78, 91, 113, 117, 0, & - 5, 21, 29, 40, 51, 70, 81, 96, 117, 122, 0, & - 8, 26, 34, 40, 62, 74, 80, 92, 116, 127, 0, & - 1, 13, 14, 36, 42, 64, 66, 84, 101, 108, 0, & - 14, 22, 27, 50, 63, 69, 89, 104, 110, 128, 0, & - 1, 18, 30, 46, 60, 65, 90, 97, 114, 127, 0, & - 3, 23, 33, 52, 56, 76, 87, 104, 112, 124, 0, & - 24, 38, 43, 61, 67, 86, 98, 103, 124, 127, 0/ - -data nrw/ & -10,10,11,10,11,11,10,10,10,10,10,10,10,10,10,10,10,10, & -10,10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,10, & -10,10/ - -ncw=3 +data Mn/ & + 21, 34, 36, & + 1, 8, 28, & + 2, 9, 37, & + 3, 7, 19, & + 4, 16, 32, & + 2, 5, 22, & + 6, 13, 25, & + 10, 31, 33, & + 11, 24, 27, & + 12, 15, 23, & + 14, 18, 26, & + 17, 20, 29, & + 17, 30, 34, & + 6, 34, 35, & + 1, 10, 30, & + 3, 18, 23, & + 4, 12, 25, & + 5, 28, 36, & + 7, 14, 21, & + 8, 15, 31, & + 9, 27, 32, & + 11, 19, 35, & + 13, 16, 37, & + 20, 24, 38, & + 21, 22, 26, & + 12, 29, 33, & + 1, 17, 35, & + 2, 28, 30, & + 3, 10, 32, & + 4, 8, 36, & + 5, 19, 29, & + 6, 20, 27, & + 7, 22, 37, & + 9, 11, 33, & + 13, 24, 26, & + 14, 31, 34, & + 15, 16, 25, & + 13, 18, 38, & + 8, 20, 23, & + 1, 32, 33, & + 2, 17, 19, & + 3, 24, 34, & + 4, 7, 38, & + 5, 11, 31, & + 6, 18, 21, & + 9, 15, 36, & + 10, 16, 28, & + 12, 26, 30, & + 14, 27, 29, & + 22, 25, 35, & + 23, 30, 32, & + 4, 11, 37, & + 1, 14, 23, & + 2, 8, 25, & + 3, 13, 27, & + 5, 10, 37, & + 6, 16, 31, & + 7, 15, 18, & + 9, 22, 24, & + 12, 19, 36, & + 17, 26, 38, & + 20, 21, 33, & + 20, 28, 35, & + 4, 29, 34, & + 1, 26, 36, & + 2, 23, 34, & + 3, 9, 38, & + 5, 6, 17, & + 7, 27, 35, & + 8, 14, 32, & + 10, 15, 22, & + 11, 18, 29, & + 12, 13, 28, & + 16, 19, 33, & + 21, 25, 31, & + 24, 30, 37, & + 1, 3, 21, & + 2, 18, 31, & + 4, 6, 9, & + 5, 8, 33, & + 7, 29, 32, & + 10, 13, 19, & + 11, 22, 23, & + 12, 27, 34, & + 14, 15, 30, & + 16, 27, 38, & + 17, 28, 37, & + 20, 25, 26, & + 5, 24, 35, & + 3, 6, 36, & + 1, 12, 31, & + 2, 4, 33, & + 3, 16, 30, & + 1, 2, 24, & + 5, 23, 27, & + 6, 28, 32, & + 7, 17, 36, & + 8, 22, 38, & + 9, 18, 20, & + 10, 21, 29, & + 11, 13, 34, & + 4, 14, 20, & + 11, 30, 38, & + 14, 35, 37, & + 15, 19, 26, & + 3, 28, 29, & + 7, 8, 9, & + 5, 18, 34, & + 13, 15, 17, & + 12, 16, 35, & + 10, 23, 25, & + 19, 21, 37, & + 17, 27, 31, & + 24, 25, 36, & + 1, 18, 19, & + 6, 26, 33, & + 22, 31, 32, & + 3, 20, 22, & + 4, 21, 27, & + 2, 13, 29, & + 6, 7, 12, & + 15, 24, 32, & + 9, 25, 30, & + 23, 37, 38, & + 5, 16, 26, & + 11, 14, 28, & + 33, 36, 38, & + 8, 10, 35/ + +data Nm/ & + 2, 15, 27, 40, 53, 65, 77, 91, 94, 115, 0, & + 3, 6, 28, 41, 54, 66, 78, 92, 94, 120, 0, & + 4, 16, 29, 42, 55, 67, 77, 90, 93, 106, 118, & + 5, 17, 30, 43, 52, 64, 79, 92, 102, 119, 0, & + 6, 18, 31, 44, 56, 68, 80, 89, 95, 108, 125, & + 7, 14, 32, 45, 57, 68, 79, 90, 96, 116, 121, & + 4, 19, 33, 43, 58, 69, 81, 97, 107, 121, 0, & + 2, 20, 30, 39, 54, 70, 80, 98, 107, 128, 0, & + 3, 21, 34, 46, 59, 67, 79, 99, 107, 123, 0, & + 8, 15, 29, 47, 56, 71, 82, 100, 111, 128, 0, & + 9, 22, 34, 44, 52, 72, 83, 101, 103, 126, 0, & + 10, 17, 26, 48, 60, 73, 84, 91, 110, 121, 0, & + 7, 23, 35, 38, 55, 73, 82, 101, 109, 120, 0, & + 11, 19, 36, 49, 53, 70, 85, 102, 104, 126, 0, & + 10, 20, 37, 46, 58, 71, 85, 105, 109, 122, 0, & + 5, 23, 37, 47, 57, 74, 86, 93, 110, 125, 0, & + 12, 13, 27, 41, 61, 68, 87, 97, 109, 113, 0, & + 11, 16, 38, 45, 58, 72, 78, 99, 108, 115, 0, & + 4, 22, 31, 41, 60, 74, 82, 105, 112, 115, 0, & + 12, 24, 32, 39, 62, 63, 88, 99, 102, 118, 0, & + 1, 19, 25, 45, 62, 75, 77, 100, 112, 119, 0, & + 6, 25, 33, 50, 59, 71, 83, 98, 117, 118, 0, & + 10, 16, 39, 51, 53, 66, 83, 95, 111, 124, 0, & + 9, 24, 35, 42, 59, 76, 89, 94, 114, 122, 0, & + 7, 17, 37, 50, 54, 75, 88, 111, 114, 123, 0, & + 11, 25, 35, 48, 61, 65, 88, 105, 116, 125, 0, & + 9, 21, 32, 49, 55, 69, 84, 86, 95, 113, 119, & + 2, 18, 28, 47, 63, 73, 87, 96, 106, 126, 0, & + 12, 26, 31, 49, 64, 72, 81, 100, 106, 120, 0, & + 13, 15, 28, 48, 51, 76, 85, 93, 103, 123, 0, & + 8, 20, 36, 44, 57, 75, 78, 91, 113, 117, 0, & + 5, 21, 29, 40, 51, 70, 81, 96, 117, 122, 0, & + 8, 26, 34, 40, 62, 74, 80, 92, 116, 127, 0, & + 1, 13, 14, 36, 42, 64, 66, 84, 101, 108, 0, & + 14, 22, 27, 50, 63, 69, 89, 104, 110, 128, 0, & + 1, 18, 30, 46, 60, 65, 90, 97, 114, 127, 0, & + 3, 23, 33, 52, 56, 76, 87, 104, 112, 124, 0, & + 24, 38, 43, 61, 67, 86, 98, 103, 124, 127, 0/ + +data nrw/ & +10,10,11,10,11,11,10,10,10,10,10,10,10,10,10,10,10,10, & +10,10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,10, & +10,10/ + +ncw=3 diff --git a/lib/ldpcsim128_90.f90 b/lib/ldpcsim128_90.f90 index c1d15e24..28e7fef0 100755 --- a/lib/ldpcsim128_90.f90 +++ b/lib/ldpcsim128_90.f90 @@ -1,142 +1,142 @@ -program ldpcsim128_90 - -! Simulate the performance of the (128,90) code that is used in -! the second incarnation of MSK144. - - use packjt77 - integer, parameter:: N=128, K=90, M=N-K -! character*12 recent_calls(NRECENT) - character*37 msg,msgsent,msgreceived - character*77 c77 - character*8 arg - integer*1 codeword(N), message77(77) - integer*1 apmask(N),cw(N) - integer*1 msgbits(77) - integer*4 i4Msg6BitWords(13) - integer nerrtot(0:N),nerrdec(0:N) - logical unpk77_success - real*8 rxdata(N), rxavgd(N) - real llr(N),llra(N) - - do i=1,MAXNRECENT - recent_calls(i)=' ' - enddo - nerrtot=0 - nerrdec=0 - - nargs=iargc() - if(nargs.ne.5) then - print*,'Usage: ldpcsim niter ndeep navg #trials s ' - print*,'eg: ldpcsim 10 2 1 1000 0.75' - return - endif - call getarg(1,arg) - read(arg,*) max_iterations - call getarg(2,arg) - read(arg,*) ndeep - call getarg(3,arg) - read(arg,*) navg - call getarg(4,arg) - read(arg,*) ntrials - call getarg(5,arg) - read(arg,*) s - - rate=real(77)/real(N) - - write(*,*) "rate: ",rate - write(*,*) "niter= ",max_iterations," navg= ",navg," s= ",s - - msg="K1ABC RR73; W9XYZ -12" - i3=0 - n3=1 - call pack77(msg,i3,n3,c77) - call unpack77(c77,0,msgsent,unpk77_success) - read(c77,'(77i1)') msgbits - - write(*,*) "message sent ",msgsent - - write(*,*) 'msgbits' - write(*,'(77i1)') msgbits - -! msgbits is the 77-bit message, codeword is 128 bits - call encode_128_90(msgbits,codeword) - -! call init_random_seed() - - write(*,*) "Eb/N0 SNR2500 ngood nundetected sigma psymerr" - do idb = 6,6,-1 - db=idb/2.0-1.0 - sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) - ngood=0 - nue=0 - nbadcrc=0 - nsumerr=0 - - do itrial=1, ntrials - rxavgd=0d0 - do iav=1,navg -! call sgran() -! Create a realization of a noisy received word - do i=1,N - rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() - enddo - rxavgd=rxavgd+rxdata - enddo - rxdata=rxavgd - nerr=0 - do i=1,N - if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1 - enddo - nerrtot(nerr)=nerrtot(nerr)+1 - - rxav=sum(rxdata)/N - rx2av=sum(rxdata*rxdata)/N - rxsig=sqrt(rx2av-rxav*rxav) - rxdata=rxdata/rxsig -! The s parameter can be tuned to trade a few tenth's dB of threshold for an order of -! magnitude in UER - if( s .lt. 0 ) then - ss=sigma - else - ss=s - endif - - llr=2.0*rxdata/(ss*ss) - - apmask=0 -! max_iterations is max number of belief propagation iterations - - call bpdecode128_90(llr, apmask, max_iterations, message77, cw, nharderrors, niterations) - - if(ndeep.ge.0 .and. nharderrors.lt.0) then - call osd128_90(llr, apmask, ndeep, message77, cw, nharderrors, dmin) - endif - -! If the decoder finds a valid codeword, nharderrors will be .ge. 0. - if( nharderrors .ge. 0 ) then - write(c77,'(77i1)') message77 - call unpack77(c77,1,msgreceived,unpk77_success) - nhw=count(cw.ne.codeword) - if(nhw.eq.0) then ! this is a good decode - ngood=ngood+1 - nerrdec(nerr)=nerrdec(nerr)+1 - else ! this is an undetected error - nue=nue+1 - endif - endif - nsumerr=nsumerr+nerr - enddo - - snr2500=db+10*log10(rate*2000.0/2500.0) ! symbol rate is 2000 s^-1 and ref BW is 2500 Hz. - pberr=real(nsumerr)/real(ntrials*N) - write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,7x,f5.2,3x,e10.3)") db,snr2500,ngood,nue,ss,pberr - - enddo - - open(unit=23,file='nerrhisto.dat',status='unknown') - do i=0,N - write(23,'(i4,2x,i10,i10,f10.2)') i,nerrdec(i),nerrtot(i),real(nerrdec(i))/real(nerrtot(i)+1e-10) - enddo - close(23) - -end program ldpcsim128_90 +program ldpcsim128_90 + +! Simulate the performance of the (128,90) code that is used in +! the second incarnation of MSK144. + + use packjt77 + integer, parameter:: N=128, K=90, M=N-K +! character*12 recent_calls(NRECENT) + character*37 msg,msgsent,msgreceived + character*77 c77 + character*8 arg + integer*1 codeword(N), message77(77) + integer*1 apmask(N),cw(N) + integer*1 msgbits(77) + integer*4 i4Msg6BitWords(13) + integer nerrtot(0:N),nerrdec(0:N) + logical unpk77_success + real*8 rxdata(N), rxavgd(N) + real llr(N),llra(N) + + do i=1,MAXNRECENT + recent_calls(i)=' ' + enddo + nerrtot=0 + nerrdec=0 + + nargs=iargc() + if(nargs.ne.5) then + print*,'Usage: ldpcsim niter ndeep navg #trials s ' + print*,'eg: ldpcsim 10 2 1 1000 0.75' + return + endif + call getarg(1,arg) + read(arg,*) max_iterations + call getarg(2,arg) + read(arg,*) ndeep + call getarg(3,arg) + read(arg,*) navg + call getarg(4,arg) + read(arg,*) ntrials + call getarg(5,arg) + read(arg,*) s + + rate=real(77)/real(N) + + write(*,*) "rate: ",rate + write(*,*) "niter= ",max_iterations," navg= ",navg," s= ",s + + msg="K1ABC RR73; W9XYZ -12" + i3=0 + n3=1 + call pack77(msg,i3,n3,c77) + call unpack77(c77,0,msgsent,unpk77_success) + read(c77,'(77i1)') msgbits + + write(*,*) "message sent ",msgsent + + write(*,*) 'msgbits' + write(*,'(77i1)') msgbits + +! msgbits is the 77-bit message, codeword is 128 bits + call encode_128_90(msgbits,codeword) + +! call init_random_seed() + + write(*,*) "Eb/N0 SNR2500 ngood nundetected sigma psymerr" + do idb = 6,6,-1 + db=idb/2.0-1.0 + sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) + ngood=0 + nue=0 + nbadcrc=0 + nsumerr=0 + + do itrial=1, ntrials + rxavgd=0d0 + do iav=1,navg +! call sgran() +! Create a realization of a noisy received word + do i=1,N + rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() + enddo + rxavgd=rxavgd+rxdata + enddo + rxdata=rxavgd + nerr=0 + do i=1,N + if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1 + enddo + nerrtot(nerr)=nerrtot(nerr)+1 + + rxav=sum(rxdata)/N + rx2av=sum(rxdata*rxdata)/N + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig +! The s parameter can be tuned to trade a few tenth's dB of threshold for an order of +! magnitude in UER + if( s .lt. 0 ) then + ss=sigma + else + ss=s + endif + + llr=2.0*rxdata/(ss*ss) + + apmask=0 +! max_iterations is max number of belief propagation iterations + + call bpdecode128_90(llr, apmask, max_iterations, message77, cw, nharderrors, niterations) + + if(ndeep.ge.0 .and. nharderrors.lt.0) then + call osd128_90(llr, apmask, ndeep, message77, cw, nharderrors, dmin) + endif + +! If the decoder finds a valid codeword, nharderrors will be .ge. 0. + if( nharderrors .ge. 0 ) then + write(c77,'(77i1)') message77 + call unpack77(c77,1,msgreceived,unpk77_success) + nhw=count(cw.ne.codeword) + if(nhw.eq.0) then ! this is a good decode + ngood=ngood+1 + nerrdec(nerr)=nerrdec(nerr)+1 + else ! this is an undetected error + nue=nue+1 + endif + endif + nsumerr=nsumerr+nerr + enddo + + snr2500=db+10*log10(rate*2000.0/2500.0) ! symbol rate is 2000 s^-1 and ref BW is 2500 Hz. + pberr=real(nsumerr)/real(ntrials*N) + write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,7x,f5.2,3x,e10.3)") db,snr2500,ngood,nue,ss,pberr + + enddo + + open(unit=23,file='nerrhisto.dat',status='unknown') + do i=0,N + write(23,'(i4,2x,i10,i10,f10.2)') i,nerrdec(i),nerrtot(i),real(nerrdec(i))/real(nerrtot(i)+1e-10) + enddo + close(23) + +end program ldpcsim128_90 diff --git a/lib/ldpcsim40.f90 b/lib/ldpcsim40.f90 index b4d7849c..b9c15e4d 100755 --- a/lib/ldpcsim40.f90 +++ b/lib/ldpcsim40.f90 @@ -1,138 +1,138 @@ -program ldpcsim - -use, intrinsic :: iso_c_binding -use hashing -use packjt - -character*22 msg,msgsent,msgreceived -character*8 arg -integer*1, allocatable :: codeword(:), decoded(:), message(:) -real*8, allocatable :: rxdata(:), rxavgd(:) -real, allocatable :: llr(:) -integer ihash -integer*1 hardbits(32) - -nargs=iargc() -if(nargs.ne.4) then - print*,'Usage: ldpcsim niter navg #trials s ' - print*,'eg: ldpcsim 10 1 1000 0.75' - return -endif -call getarg(1,arg) -read(arg,*) max_iterations -call getarg(2,arg) -read(arg,*) navg -call getarg(3,arg) -read(arg,*) ntrials -call getarg(4,arg) -read(arg,*) s - -K=16 -N=32 -!rate=real(K)/real(N) -! don't count hash bits as data bits -rate=4.0/real(N) -write(*,*) "rate: ",rate -write(*,*) "niter= ",max_iterations,"navg= ",navg," s= ",s - -allocate ( codeword(N), decoded(K), message(K) ) -allocate ( rxdata(N), rxavgd(N), llr(N) ) - -msg="K1JT K9AN" -call fmtmsg(msg,iz) -call hash(msg,22,ihash) -irpt=14 -ihash=iand(ihash,4095) !12-bit hash -ig=16*ihash + irpt !4-bit report -write(*,*) irpt,ihash,ig - -do i=1,16 - message(i)=iand(1,ishft(ig,1-i)) -enddo -write(*,'(16i1)') message -call encode_msk40(message,codeword) -write(*,'(32i1)') codeword -call init_random_seed() - -write(*,*) "Eb/N0 SNR2500 ngood nundetected nbadhash" -do idb = 0, 30 - db=idb/2.0 - sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) - ngood=0 - nue=0 - nbadhash=0 - - itsum=0 - do itrial=1, ntrials - rxavgd=0d0 - do iav=1,navg - call sgran() -! Create a realization of a noisy received word - do i=1,N - rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() - enddo - rxavgd=rxavgd+rxdata - enddo - rxdata=rxavgd - -! Correct signal normalization is important for this decoder. - rxav=sum(rxdata)/N - rx2av=sum(rxdata*rxdata)/N - rxsig=sqrt(rx2av-rxav*rxav) - rxdata=rxdata/rxsig - if( s .le. 0 ) then - ss=sigma - else - ss=s - endif - - llr=2.0*rxdata/(ss*ss) - - call bpdecode40(llr, max_iterations, decoded, niterations) -! If the decoder finds a valid codeword, niterations will be .ge. 0. - if( niterations .ge. 0 ) then - nueflag=0 - nhashflag=0 - imsg=0 - do i=1,16 - imsg=ishft(imsg,1)+iand(1,decoded(17-i)) - enddo - nrxrpt=iand(imsg,15) - nrxhash=(imsg-nrxrpt)/16 - if( nrxhash .ne. ihash ) then - nbadhash=nbadhash+1 - nhashflag=1 - endif - -! Check the message plus hash against what was sent. - do i=1,K - if( message(i) .ne. decoded(i) ) then - nueflag=1 - endif - enddo - - if( nhashflag .eq. 0 .and. nueflag .eq. 0 ) then - ngood=ngood+1 - itsum=itsum+niterations - else if( nhashflag .eq. 0 .and. nueflag .eq. 1 ) then - nue=nue+1; - endif - else - hardbits=0 - where(llr .gt. 0) hardbits=1 -! write(*,'(32i1)') hardbits -! write(*,'(32i1)') codeword - isum=0 - do i=1,32 - if( hardbits(i) .ne. codeword(i) ) isum=isum+1 - enddo -! write(*,*) 'number of errors ',isum - endif - enddo - avits=real(itsum)/real(ngood+0.1) - snr2500=db-10.0 - write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,1x,i8,1x,f8.2,1x,f8.1)") db,snr2500,ngood,nue,nbadhash,ss,avits - -enddo - -end program ldpcsim +program ldpcsim + +use, intrinsic :: iso_c_binding +use hashing +use packjt + +character*22 msg,msgsent,msgreceived +character*8 arg +integer*1, allocatable :: codeword(:), decoded(:), message(:) +real*8, allocatable :: rxdata(:), rxavgd(:) +real, allocatable :: llr(:) +integer ihash +integer*1 hardbits(32) + +nargs=iargc() +if(nargs.ne.4) then + print*,'Usage: ldpcsim niter navg #trials s ' + print*,'eg: ldpcsim 10 1 1000 0.75' + return +endif +call getarg(1,arg) +read(arg,*) max_iterations +call getarg(2,arg) +read(arg,*) navg +call getarg(3,arg) +read(arg,*) ntrials +call getarg(4,arg) +read(arg,*) s + +K=16 +N=32 +!rate=real(K)/real(N) +! don't count hash bits as data bits +rate=4.0/real(N) +write(*,*) "rate: ",rate +write(*,*) "niter= ",max_iterations,"navg= ",navg," s= ",s + +allocate ( codeword(N), decoded(K), message(K) ) +allocate ( rxdata(N), rxavgd(N), llr(N) ) + +msg="K1JT K9AN" +call fmtmsg(msg,iz) +call hash(msg,22,ihash) +irpt=14 +ihash=iand(ihash,4095) !12-bit hash +ig=16*ihash + irpt !4-bit report +write(*,*) irpt,ihash,ig + +do i=1,16 + message(i)=iand(1,ishft(ig,1-i)) +enddo +write(*,'(16i1)') message +call encode_msk40(message,codeword) +write(*,'(32i1)') codeword +call init_random_seed() + +write(*,*) "Eb/N0 SNR2500 ngood nundetected nbadhash" +do idb = 0, 30 + db=idb/2.0 + sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) + ngood=0 + nue=0 + nbadhash=0 + + itsum=0 + do itrial=1, ntrials + rxavgd=0d0 + do iav=1,navg + call sgran() +! Create a realization of a noisy received word + do i=1,N + rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() + enddo + rxavgd=rxavgd+rxdata + enddo + rxdata=rxavgd + +! Correct signal normalization is important for this decoder. + rxav=sum(rxdata)/N + rx2av=sum(rxdata*rxdata)/N + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + if( s .le. 0 ) then + ss=sigma + else + ss=s + endif + + llr=2.0*rxdata/(ss*ss) + + call bpdecode40(llr, max_iterations, decoded, niterations) +! If the decoder finds a valid codeword, niterations will be .ge. 0. + if( niterations .ge. 0 ) then + nueflag=0 + nhashflag=0 + imsg=0 + do i=1,16 + imsg=ishft(imsg,1)+iand(1,decoded(17-i)) + enddo + nrxrpt=iand(imsg,15) + nrxhash=(imsg-nrxrpt)/16 + if( nrxhash .ne. ihash ) then + nbadhash=nbadhash+1 + nhashflag=1 + endif + +! Check the message plus hash against what was sent. + do i=1,K + if( message(i) .ne. decoded(i) ) then + nueflag=1 + endif + enddo + + if( nhashflag .eq. 0 .and. nueflag .eq. 0 ) then + ngood=ngood+1 + itsum=itsum+niterations + else if( nhashflag .eq. 0 .and. nueflag .eq. 1 ) then + nue=nue+1; + endif + else + hardbits=0 + where(llr .gt. 0) hardbits=1 +! write(*,'(32i1)') hardbits +! write(*,'(32i1)') codeword + isum=0 + do i=1,32 + if( hardbits(i) .ne. codeword(i) ) isum=isum+1 + enddo +! write(*,*) 'number of errors ',isum + endif + enddo + avits=real(itsum)/real(ngood+0.1) + snr2500=db-10.0 + write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,1x,i8,1x,f8.2,1x,f8.1)") db,snr2500,ngood,nue,nbadhash,ss,avits + +enddo + +end program ldpcsim diff --git a/lib/libration.f90 b/lib/libration.f90 index a9026119..7330d049 100755 --- a/lib/libration.f90 +++ b/lib/libration.f90 @@ -1,38 +1,38 @@ -subroutine libration(jd,RA,Dec,xl,b) - -! Compute optical libration of moon at jd: that is, the sub-observer -! point (xl,b) in selenographic coordinates. RA and Dec are -! topocentric values. - - implicit real*8 (a-h,o-z) - parameter (RADS=0.0174532925199433d0) - parameter (TWOPI=6.28318530717959d0) - real*8 jd,j2000,mjd,lambda - - j2000=2451545.0d0 - RA2000=RA - Dec2000=Dec - year=2000.0d0 + (jd-j2000)/365.25d0 - mjd=jd-2400000.d0 - call sla_PRECES('FK5',year,2000.d0,RA2000,Dec2000) - call sla_EQECL(RA2000,Dec2000,mjd,lambda,beta) - day=jd - j2000 - t = day / 36525.d0 - xi = 1.54242 * RADS - ft = 93.2720993 + 483202.0175273 * t - .0034029 * t * t - b= ft / 360 - a = 360 * (b - floor(b)) - if (a.lt.0.d0) a = 360 + a; - f=a/57.2957795131d0 - omega=sla_dranrm(2.182439196d0 - t*33.7570446085d0 + t*t*3.6236526d-5) - w = lambda - omega - y = sin(w) * cos(beta) * cos(xi) - sin(beta) * sin(xi) - x = cos(w) * cos(beta) - a = sla_dranrm(atan2(y, x)) - xl = a - f - if(xl.lt.-0.25*TWOPI) xl=xl+TWOPI !Fix 'round the back' angles - if(xl.gt.0.25*TWOPI) xl=xl-TWOPI - b = asin(-sin(w) * cos(beta) * sin(xi) - sin(beta) * cos(xi)) - - return -end subroutine libration +subroutine libration(jd,RA,Dec,xl,b) + +! Compute optical libration of moon at jd: that is, the sub-observer +! point (xl,b) in selenographic coordinates. RA and Dec are +! topocentric values. + + implicit real*8 (a-h,o-z) + parameter (RADS=0.0174532925199433d0) + parameter (TWOPI=6.28318530717959d0) + real*8 jd,j2000,mjd,lambda + + j2000=2451545.0d0 + RA2000=RA + Dec2000=Dec + year=2000.0d0 + (jd-j2000)/365.25d0 + mjd=jd-2400000.d0 + call sla_PRECES('FK5',year,2000.d0,RA2000,Dec2000) + call sla_EQECL(RA2000,Dec2000,mjd,lambda,beta) + day=jd - j2000 + t = day / 36525.d0 + xi = 1.54242 * RADS + ft = 93.2720993 + 483202.0175273 * t - .0034029 * t * t + b= ft / 360 + a = 360 * (b - floor(b)) + if (a.lt.0.d0) a = 360 + a; + f=a/57.2957795131d0 + omega=sla_dranrm(2.182439196d0 - t*33.7570446085d0 + t*t*3.6236526d-5) + w = lambda - omega + y = sin(w) * cos(beta) * cos(xi) - sin(beta) * sin(xi) + x = cos(w) * cos(beta) + a = sla_dranrm(atan2(y, x)) + xl = a - f + if(xl.lt.-0.25*TWOPI) xl=xl+TWOPI !Fix 'round the back' angles + if(xl.gt.0.25*TWOPI) xl=xl-TWOPI + b = asin(-sin(w) * cos(beta) * sin(xi) - sin(beta) * cos(xi)) + + return +end subroutine libration diff --git a/lib/lorentzian.f90 b/lib/lorentzian.f90 index c87b683f..f3f4e14e 100755 --- a/lib/lorentzian.f90 +++ b/lib/lorentzian.f90 @@ -1,102 +1,102 @@ -subroutine lorentzian(y,npts,a) - -! Input: y(npts); assume x(i)=i, i=1,npts -! Output: a(1: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(1: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/lib/lpf1.f90 b/lib/lpf1.f90 index 96897651..a620e9a5 100755 --- a/lib/lpf1.f90 +++ b/lib/lpf1.f90 @@ -1,29 +1,29 @@ -subroutine lpf1(dd,jz,dat,jz2) - - parameter (NFFT1=64*11025,NFFT2=32*11025) - real dd(jz) - real dat(jz) - real x(NFFT1) - complex cx(0:NFFT1/2) - equivalence (x,cx) - save x,cx - - fac=1.0/float(NFFT1) - x(1:jz)=fac*dd(1:jz) - x(jz+1:NFFT1)=0.0 - call four2a(cx,NFFT1,1,-1,0) !Forwarxd FFT, r2c - cx(NFFT2/2:)=0.0 - -! df=11025.0/NFFT1 -! do i=1,NFFT1/2 -! sx=real(cx(i))**2 + aimag(cx(i))**2 -! write(50,3000) i*df,sx -!3000 format(f15.6,e12.3) -! enddo - - call four2a(cx,NFFT2,1,1,-1) !Inverse FFT, c2r - jz2=jz/2 - dat(1:jz2)=x(1:jz2) - - return -end subroutine lpf1 +subroutine lpf1(dd,jz,dat,jz2) + + parameter (NFFT1=64*11025,NFFT2=32*11025) + real dd(jz) + real dat(jz) + real x(NFFT1) + complex cx(0:NFFT1/2) + equivalence (x,cx) + save x,cx + + fac=1.0/float(NFFT1) + x(1:jz)=fac*dd(1:jz) + x(jz+1:NFFT1)=0.0 + call four2a(cx,NFFT1,1,-1,0) !Forwarxd FFT, r2c + cx(NFFT2/2:)=0.0 + +! df=11025.0/NFFT1 +! do i=1,NFFT1/2 +! sx=real(cx(i))**2 + aimag(cx(i))**2 +! write(50,3000) i*df,sx +!3000 format(f15.6,e12.3) +! enddo + + call four2a(cx,NFFT2,1,1,-1) !Inverse FFT, c2r + jz2=jz/2 + dat(1:jz2)=x(1:jz2) + + return +end subroutine lpf1 diff --git a/lib/makepings.f90 b/lib/makepings.f90 index 325a3c4d..0d42df00 100755 --- a/lib/makepings.f90 +++ b/lib/makepings.f90 @@ -1,25 +1,25 @@ -subroutine makepings(pings,nTRperiod,npts,width,sig) - - real pings(npts) - real*8 t - real t0(29) - - dt=1.0/12000.0 - do i=1,nTRperiod-1 - t0(i)=i !Make pings at t=1, 2, ... 14 s. - enddo - amp=sig - - do i=1,npts - iping=min(max(1,i/12000),nTRperiod-1) - t=(i*dt-t0(iping))/width - if(t.lt.0.d0 .or. t.gt.10.0) then - fac=0. - else - fac=2.718*t*dexp(-t) - endif - pings(i)=fac*amp - enddo - - return -end subroutine makepings +subroutine makepings(pings,nTRperiod,npts,width,sig) + + real pings(npts) + real*8 t + real t0(29) + + dt=1.0/12000.0 + do i=1,nTRperiod-1 + t0(i)=i !Make pings at t=1, 2, ... 14 s. + enddo + amp=sig + + do i=1,npts + iping=min(max(1,i/12000),nTRperiod-1) + t=(i*dt-t0(iping))/width + if(t.lt.0.d0 .or. t.gt.10.0) then + fac=0. + else + fac=2.718*t*dexp(-t) + endif + pings(i)=fac*amp + enddo + + return +end subroutine makepings diff --git a/lib/map65_mmdec.f90 b/lib/map65_mmdec.f90 index 7d592d33..14871857 100755 --- a/lib/map65_mmdec.f90 +++ b/lib/map65_mmdec.f90 @@ -1,90 +1,90 @@ -subroutine map65_mmdec(nutc,id2,nqd,ntrperiod, nsubmode,nfa,nfb,nfqso, & - ntol,newdat,nagain,max_drift,ndepth,mycall,hiscall,hisgrid) - - use prog_args - use timer_module, only: timer - use q65_decode - - include 'jt9com.f90' - include 'timer_common.inc' - - type, extends(q65_decoder) :: counting_q65_decoder - integer :: decoded - end type counting_q65_decoder - - logical single_decode,bVHF,lnewdat,lagain,lclearave,lapcqonly - integer*2 id2(300*12000) - integer nqf(20) -! type(params_block) :: params - character(len=12) :: mycall, hiscall - character(len=6) :: hisgrid - data ntr0/-1/ - save - type(counting_q65_decoder) :: my_q65 - -! Cast C character arrays to Fortran character strings -! datetime=transfer(params%datetime, datetime) -! mycall=transfer(params%mycall,mycall) -! hiscall=transfer(params%hiscall,hiscall) -! mygrid=transfer(params%mygrid,mygrid) -! hisgrid=transfer(params%hisgrid,hisgrid) - - my_q65%decoded = 0 - ncontest=0 - nQSOprogress=0 - lclearave=.false. - single_decode=.false. - lapcqonly=.false. - lnewdat=(newdat.ne.0) - lagain=(nagain.ne.0) - bVHF=.true. - emedelay=2.5 -! ntrperiod=60 - - call timer('dec_q65 ',0) - call my_q65%decode(q65_decoded,id2,nqd,nutc,ntrperiod,nsubmode,nfqso, & - ntol,ndepth,nfa,nfb,lclearave,single_decode,lagain,max_drift,lnewdat, & - emedelay,mycall,hiscall,hisgrid,nQSOProgress,ncontest,lapcqonly,navg0,nqf) - call timer('dec_q65 ',1) - - return - -contains - - subroutine q65_decoded (this,nutc,snr1,nsnr,dt,freq,decoded,idec, & - nused,ntrperiod) - - use q65_decode - implicit none - - class(q65_decoder), intent(inout) :: this - integer, intent(in) :: nutc - real, intent(in) :: snr1 - integer, intent(in) :: nsnr - real, intent(in) :: dt - real, intent(in) :: freq - character(len=37), intent(in) :: decoded - integer, intent(in) :: idec - integer, intent(in) :: nused - integer, intent(in) :: ntrperiod - - if(nutc+snr1+nsnr+dt+freq+idec+nused+ntrperiod.eq.-999) stop - if(decoded.eq.'-999') stop - - cq0='q ' - write(cq0(2:2),'(i1)') idec - if(nused.ge.2) write(cq0(3:3),'(i1)') nused - nsnr0=nsnr - xdt0=dt - nfreq0=nint(freq) - msg0=decoded - - select type(this) - type is (counting_q65_decoder) - if(idec.ge.0) this%decoded = this%decoded + 1 - end select - - return - end subroutine q65_decoded - -end subroutine map65_mmdec +subroutine map65_mmdec(nutc,id2,nqd,ntrperiod, nsubmode,nfa,nfb,nfqso, & + ntol,newdat,nagain,max_drift,ndepth,mycall,hiscall,hisgrid) + + use prog_args + use timer_module, only: timer + use q65_decode + + include 'jt9com.f90' + include 'timer_common.inc' + + type, extends(q65_decoder) :: counting_q65_decoder + integer :: decoded + end type counting_q65_decoder + + logical single_decode,bVHF,lnewdat,lagain,lclearave,lapcqonly + integer*2 id2(300*12000) + integer nqf(20) +! type(params_block) :: params + character(len=12) :: mycall, hiscall + character(len=6) :: hisgrid + data ntr0/-1/ + save + type(counting_q65_decoder) :: my_q65 + +! Cast C character arrays to Fortran character strings +! datetime=transfer(params%datetime, datetime) +! mycall=transfer(params%mycall,mycall) +! hiscall=transfer(params%hiscall,hiscall) +! mygrid=transfer(params%mygrid,mygrid) +! hisgrid=transfer(params%hisgrid,hisgrid) + + my_q65%decoded = 0 + ncontest=0 + nQSOprogress=0 + lclearave=.false. + single_decode=.false. + lapcqonly=.false. + lnewdat=(newdat.ne.0) + lagain=(nagain.ne.0) + bVHF=.true. + emedelay=2.5 +! ntrperiod=60 + + call timer('dec_q65 ',0) + call my_q65%decode(q65_decoded,id2,nqd,nutc,ntrperiod,nsubmode,nfqso, & + ntol,ndepth,nfa,nfb,lclearave,single_decode,lagain,max_drift,lnewdat, & + emedelay,mycall,hiscall,hisgrid,nQSOProgress,ncontest,lapcqonly,navg0,nqf) + call timer('dec_q65 ',1) + + return + +contains + + subroutine q65_decoded (this,nutc,snr1,nsnr,dt,freq,decoded,idec, & + nused,ntrperiod) + + use q65_decode + implicit none + + class(q65_decoder), intent(inout) :: this + integer, intent(in) :: nutc + real, intent(in) :: snr1 + integer, intent(in) :: nsnr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=37), intent(in) :: decoded + integer, intent(in) :: idec + integer, intent(in) :: nused + integer, intent(in) :: ntrperiod + + if(nutc+snr1+nsnr+dt+freq+idec+nused+ntrperiod.eq.-999) stop + if(decoded.eq.'-999') stop + + cq0='q ' + write(cq0(2:2),'(i1)') idec + if(nused.ge.2) write(cq0(3:3),'(i1)') nused + nsnr0=nsnr + xdt0=dt + nfreq0=nint(freq) + msg0=decoded + + select type(this) + type is (counting_q65_decoder) + if(idec.ge.0) this%decoded = this%decoded + 1 + end select + + return + end subroutine q65_decoded + +end subroutine map65_mmdec diff --git a/lib/met8.21 b/lib/met8.21 index 955d34fd..a5d3006e 100755 --- a/lib/met8.21 +++ b/lib/met8.21 @@ -1,256 +1,256 @@ - -25.6 1.000 -9.966 1.000000 0.000000 - -25.4 1.000 -9.966 1.000000 0.000000 - -25.2 1.000 -9.966 1.000000 0.000000 - -25.0 1.000 -9.966 1.000000 0.000000 - -24.8 1.000 -9.966 1.000000 0.000000 - -24.6 1.000 -9.966 1.000000 0.000000 - -24.4 1.000 -9.966 1.000000 0.000000 - -24.2 1.000 -9.966 1.000000 0.000000 - -24.0 1.000 -9.966 1.000000 0.000000 - -23.8 1.000 -9.966 1.000000 0.000000 - -23.6 1.000 -9.966 1.000000 0.000000 - -23.4 1.000 -9.966 1.000000 0.000000 - -23.2 1.000 -9.966 1.000000 0.000000 - -23.0 1.000 -9.966 1.000000 0.000000 - -22.8 1.000 -9.966 1.000000 0.000000 - -22.6 1.000 -9.966 1.000000 0.000000 - -22.4 1.000 -9.966 1.000000 0.000000 - -22.2 1.000 -9.966 1.000000 0.000000 - -22.0 1.000 -9.966 1.000000 0.000000 - -21.8 1.000 -9.966 1.000000 0.000000 - -21.6 1.000 -9.966 1.000000 0.000000 - -21.4 1.000 -9.966 1.000000 0.000000 - -21.2 1.000 -9.966 1.000000 0.000000 - -21.0 1.000 -9.966 1.000000 0.000000 - -20.8 1.000 -9.966 1.000000 0.000000 - -20.6 1.000 -9.966 1.000000 0.000000 - -20.4 1.000 -9.966 1.000000 0.000000 - -20.2 1.000 -9.966 1.000000 0.000000 - -20.0 1.000 -9.966 1.000000 0.000000 - -19.8 1.000 -9.966 1.000000 0.000000 - -19.6 1.000 -9.966 1.000000 0.000000 - -19.4 1.000 -9.966 1.000000 0.000000 - -19.2 1.000 -9.966 1.000000 0.000000 - -19.0 1.000 -9.966 1.000000 0.000000 - -18.8 1.000 -9.966 1.000000 0.000000 - -18.6 1.000 -9.966 1.000000 0.000000 - -18.4 1.000 -9.966 1.000000 0.000000 - -18.2 1.000 -9.966 1.000000 0.000000 - -18.0 1.000 -9.966 1.000000 0.000000 - -17.8 1.000 -9.966 1.000000 0.000000 - -17.6 1.000 -9.966 1.000000 0.000000 - -17.4 1.000 -9.966 1.000000 0.000000 - -17.2 1.000 -9.966 1.000000 0.000000 - -17.0 1.000 -9.966 1.000000 0.000000 - -16.8 1.000 -9.966 1.000000 0.000000 - -16.6 1.000 -9.966 1.000000 0.000000 - -16.4 1.000 -9.966 1.000000 0.000000 - -16.2 1.000 -9.966 1.000000 0.000000 - -16.0 0.988 -5.858 0.991379 0.008621 - -15.8 1.000 -9.966 1.000000 0.000000 - -15.6 0.991 -6.313 0.993711 0.006289 - -15.4 0.993 -6.629 0.994950 0.005051 - -15.2 1.000 -9.966 1.000000 0.000000 - -15.0 0.995 -7.055 0.996241 0.003759 - -14.8 1.000 -9.966 1.000000 0.000000 - -14.6 0.991 -6.371 0.993958 0.006042 - -14.4 1.000 -9.966 1.000000 0.000000 - -14.2 0.991 -6.313 0.993711 0.006289 - -14.0 0.992 -6.426 0.994186 0.005814 - -13.8 0.991 -6.288 0.993600 0.006400 - -13.6 0.990 -6.113 0.992775 0.007225 - -13.4 0.990 -6.152 0.992968 0.007032 - -13.2 0.992 -6.534 0.994606 0.005394 - -13.0 0.996 -7.332 0.996898 0.003102 - -12.8 0.990 -6.184 0.993121 0.006879 - -12.6 0.994 -7.016 0.996136 0.003864 - -12.4 0.993 -6.658 0.995049 0.004950 - -12.2 0.991 -6.369 0.993953 0.006047 - -12.0 0.992 -6.559 0.994699 0.005301 - -11.8 0.989 -6.002 0.992197 0.007803 - -11.6 0.991 -6.304 0.993671 0.006329 - -11.4 0.987 -5.826 0.991188 0.008812 - -11.2 0.985 -5.632 0.989919 0.010081 - -11.0 0.989 -5.995 0.992162 0.007838 - -10.8 0.984 -5.544 0.989284 0.010717 - -10.6 0.983 -5.377 0.987966 0.012034 - -10.4 0.979 -5.108 0.985502 0.014498 - -10.2 0.977 -4.954 0.983869 0.016131 - -10.0 0.971 -4.652 0.980118 0.019882 - -9.8 0.975 -4.870 0.982896 0.017104 - -9.6 0.974 -4.822 0.982324 0.017676 - -9.4 0.970 -4.608 0.979490 0.020510 - -9.2 0.970 -4.623 0.979702 0.020298 - -9.0 0.970 -4.621 0.979679 0.020321 - -8.8 0.967 -4.472 0.977465 0.022535 - -8.6 0.962 -4.261 0.973915 0.026085 - -8.4 0.960 -4.186 0.972538 0.027462 - -8.2 0.957 -4.098 0.970806 0.029194 - -8.0 0.956 -4.062 0.970061 0.029939 - -7.8 0.953 -3.975 0.968209 0.031791 - -7.6 0.942 -3.677 0.960918 0.039082 - -7.4 0.946 -3.768 0.963301 0.036699 - -7.2 0.937 -3.550 0.957308 0.042692 - -7.0 0.933 -3.463 0.954652 0.045348 - -6.8 0.929 -3.377 0.951866 0.048134 - -6.6 0.920 -3.212 0.946042 0.053958 - -6.4 0.917 -3.164 0.944202 0.055798 - -6.2 0.911 -3.058 0.939981 0.060019 - -6.0 0.903 -2.939 0.934818 0.065182 - -5.8 0.895 -2.829 0.929642 0.070358 - -5.6 0.884 -2.690 0.922540 0.077459 - -5.4 0.877 -2.608 0.917972 0.082028 - -5.2 0.869 -2.531 0.913509 0.086491 - -5.0 0.858 -2.411 0.905967 0.094033 - -4.8 0.846 -2.301 0.898525 0.101475 - -4.6 0.834 -2.201 0.891269 0.108731 - -4.4 0.821 -2.096 0.883085 0.116915 - -4.2 0.806 -1.992 0.874340 0.125660 - -4.0 0.790 -1.882 0.864307 0.135693 - -3.8 0.775 -1.790 0.855445 0.144555 - -3.6 0.755 -1.678 0.843726 0.156274 - -3.4 0.737 -1.587 0.833538 0.166462 - -3.2 0.713 -1.473 0.819841 0.180159 - -3.0 0.691 -1.376 0.807345 0.192655 - -2.8 0.667 -1.280 0.794093 0.205907 - -2.6 0.640 -1.181 0.779404 0.220596 - -2.4 0.612 -1.084 0.764178 0.235822 - -2.2 0.581 -0.987 0.747708 0.252292 - -2.0 0.548 -0.895 0.731037 0.268963 - -1.8 0.510 -0.796 0.712035 0.287965 - -1.6 0.472 -0.706 0.693474 0.306526 - -1.4 0.425 -0.606 0.671514 0.328486 - -1.2 0.378 -0.514 0.649948 0.350053 - -1.0 0.328 -0.425 0.627452 0.372548 - -0.8 0.274 -0.338 0.604549 0.395451 - -0.6 0.212 -0.249 0.579151 0.420849 - -0.4 0.146 -0.163 0.553389 0.446611 - -0.2 0.075 -0.079 0.526648 0.473352 - 0.0 0.000 0.000 0.500000 0.500000 - 0.2 -0.079 0.075 0.473352 0.526648 - 0.4 -0.163 0.146 0.446611 0.553389 - 0.6 -0.249 0.212 0.420849 0.579151 - 0.8 -0.338 0.274 0.395451 0.604549 - 1.0 -0.425 0.328 0.372548 0.627452 - 1.2 -0.514 0.378 0.350053 0.649948 - 1.4 -0.606 0.425 0.328486 0.671514 - 1.6 -0.706 0.472 0.306526 0.693474 - 1.8 -0.796 0.510 0.287965 0.712035 - 2.0 -0.895 0.548 0.268963 0.731037 - 2.2 -0.987 0.581 0.252292 0.747708 - 2.4 -1.084 0.612 0.235822 0.764178 - 2.6 -1.181 0.640 0.220596 0.779404 - 2.8 -1.280 0.667 0.205907 0.794093 - 3.0 -1.376 0.691 0.192655 0.807345 - 3.2 -1.473 0.713 0.180159 0.819841 - 3.4 -1.587 0.737 0.166462 0.833538 - 3.6 -1.678 0.755 0.156274 0.843726 - 3.8 -1.790 0.775 0.144555 0.855445 - 4.0 -1.882 0.790 0.135693 0.864307 - 4.2 -1.992 0.806 0.125660 0.874340 - 4.4 -2.096 0.821 0.116915 0.883085 - 4.6 -2.201 0.834 0.108731 0.891269 - 4.8 -2.301 0.846 0.101475 0.898525 - 5.0 -2.411 0.858 0.094033 0.905967 - 5.2 -2.531 0.869 0.086491 0.913509 - 5.4 -2.608 0.877 0.082028 0.917972 - 5.6 -2.690 0.884 0.077459 0.922540 - 5.8 -2.829 0.895 0.070358 0.929642 - 6.0 -2.939 0.903 0.065182 0.934818 - 6.2 -3.058 0.911 0.060019 0.939981 - 6.4 -3.164 0.917 0.055798 0.944202 - 6.6 -3.212 0.920 0.053958 0.946042 - 6.8 -3.377 0.929 0.048134 0.951866 - 7.0 -3.463 0.933 0.045348 0.954652 - 7.2 -3.550 0.937 0.042692 0.957308 - 7.4 -3.768 0.946 0.036699 0.963301 - 7.6 -3.677 0.942 0.039082 0.960918 - 7.8 -3.975 0.953 0.031791 0.968210 - 8.0 -4.062 0.956 0.029939 0.970061 - 8.2 -4.098 0.957 0.029194 0.970806 - 8.4 -4.186 0.960 0.027462 0.972538 - 8.6 -4.261 0.962 0.026085 0.973915 - 8.8 -4.472 0.967 0.022535 0.977465 - 9.0 -4.621 0.970 0.020321 0.979679 - 9.2 -4.623 0.970 0.020298 0.979702 - 9.4 -4.608 0.970 0.020510 0.979490 - 9.6 -4.822 0.974 0.017676 0.982324 - 9.8 -4.870 0.975 0.017104 0.982896 - 10.0 -4.652 0.971 0.019882 0.980118 - 10.2 -4.954 0.977 0.016131 0.983869 - 10.4 -5.108 0.979 0.014498 0.985502 - 10.6 -5.377 0.983 0.012034 0.987966 - 10.8 -5.544 0.984 0.010717 0.989284 - 11.0 -5.995 0.989 0.007838 0.992162 - 11.2 -5.632 0.985 0.010081 0.989919 - 11.4 -5.826 0.987 0.008812 0.991188 - 11.6 -6.304 0.991 0.006329 0.993671 - 11.8 -6.002 0.989 0.007803 0.992197 - 12.0 -6.559 0.992 0.005301 0.994699 - 12.2 -6.369 0.991 0.006047 0.993953 - 12.4 -6.658 0.993 0.004950 0.995049 - 12.6 -7.016 0.994 0.003864 0.996136 - 12.8 -6.184 0.990 0.006879 0.993121 - 13.0 -7.332 0.996 0.003102 0.996898 - 13.2 -6.534 0.992 0.005394 0.994606 - 13.4 -6.152 0.990 0.007032 0.992968 - 13.6 -6.113 0.990 0.007225 0.992775 - 13.8 -6.288 0.991 0.006400 0.993600 - 14.0 -6.426 0.992 0.005814 0.994186 - 14.2 -6.313 0.991 0.006289 0.993711 - 14.4 -9.966 1.000 0.000000 1.000000 - 14.6 -6.371 0.991 0.006042 0.993958 - 14.8 -9.966 1.000 0.000000 1.000000 - 15.0 -7.055 0.995 0.003759 0.996241 - 15.2 -9.966 1.000 0.000000 1.000000 - 15.4 -6.629 0.993 0.005051 0.994949 - 15.6 -6.313 0.991 0.006289 0.993711 - 15.8 -9.966 1.000 0.000000 1.000000 - 16.0 -5.858 0.988 0.008621 0.991379 - 16.2 -9.966 1.000 0.000000 1.000000 - 16.4 -9.966 1.000 0.000000 1.000000 - 16.6 -9.966 1.000 0.000000 1.000000 - 16.8 -9.966 1.000 0.000000 1.000000 - 17.0 -9.966 1.000 0.000000 1.000000 - 17.2 -9.966 1.000 0.000000 1.000000 - 17.4 -9.966 1.000 0.000000 1.000000 - 17.6 -9.966 1.000 0.000000 1.000000 - 17.8 -9.966 1.000 0.000000 1.000000 - 18.0 -9.966 1.000 0.000000 1.000000 - 18.2 -9.966 1.000 0.000000 1.000000 - 18.4 -9.966 1.000 0.000000 1.000000 - 18.6 -9.966 1.000 0.000000 1.000000 - 18.8 -9.966 1.000 0.000000 1.000000 - 19.0 -9.966 1.000 0.000000 1.000000 - 19.2 -9.966 1.000 0.000000 1.000000 - 19.4 -9.966 1.000 0.000000 1.000000 - 19.6 -9.966 1.000 0.000000 1.000000 - 19.8 -9.966 1.000 0.000000 1.000000 - 20.0 -9.966 1.000 0.000000 1.000000 - 20.2 -9.966 1.000 0.000000 1.000000 - 20.4 -9.966 1.000 0.000000 1.000000 - 20.6 -9.966 1.000 0.000000 1.000000 - 20.8 -9.966 1.000 0.000000 1.000000 - 21.0 -9.966 1.000 0.000000 1.000000 - 21.2 -9.966 1.000 0.000000 1.000000 - 21.4 -9.966 1.000 0.000000 1.000000 - 21.6 -9.966 1.000 0.000000 1.000000 - 21.8 -9.966 1.000 0.000000 1.000000 - 22.0 -9.966 1.000 0.000000 1.000000 - 22.2 -9.966 1.000 0.000000 1.000000 - 22.4 -9.966 1.000 0.000000 1.000000 - 22.6 -9.966 1.000 0.000000 1.000000 - 22.8 -9.966 1.000 0.000000 1.000000 - 23.0 -9.966 1.000 0.000000 1.000000 - 23.2 -9.966 1.000 0.000000 1.000000 - 23.4 -9.966 1.000 0.000000 1.000000 - 23.6 -9.966 1.000 0.000000 1.000000 - 23.8 -9.966 1.000 0.000000 1.000000 - 24.0 -9.966 1.000 0.000000 1.000000 - 24.2 -9.966 1.000 0.000000 1.000000 - 24.4 -9.966 1.000 0.000000 1.000000 - 24.6 -9.966 1.000 0.000000 1.000000 - 24.8 -9.966 1.000 0.000000 1.000000 - 25.0 -9.966 1.000 0.000000 1.000000 - 25.2 -9.966 1.000 0.000000 1.000000 - 25.4 -9.966 1.000 0.000000 1.000000 + -25.6 1.000 -9.966 1.000000 0.000000 + -25.4 1.000 -9.966 1.000000 0.000000 + -25.2 1.000 -9.966 1.000000 0.000000 + -25.0 1.000 -9.966 1.000000 0.000000 + -24.8 1.000 -9.966 1.000000 0.000000 + -24.6 1.000 -9.966 1.000000 0.000000 + -24.4 1.000 -9.966 1.000000 0.000000 + -24.2 1.000 -9.966 1.000000 0.000000 + -24.0 1.000 -9.966 1.000000 0.000000 + -23.8 1.000 -9.966 1.000000 0.000000 + -23.6 1.000 -9.966 1.000000 0.000000 + -23.4 1.000 -9.966 1.000000 0.000000 + -23.2 1.000 -9.966 1.000000 0.000000 + -23.0 1.000 -9.966 1.000000 0.000000 + -22.8 1.000 -9.966 1.000000 0.000000 + -22.6 1.000 -9.966 1.000000 0.000000 + -22.4 1.000 -9.966 1.000000 0.000000 + -22.2 1.000 -9.966 1.000000 0.000000 + -22.0 1.000 -9.966 1.000000 0.000000 + -21.8 1.000 -9.966 1.000000 0.000000 + -21.6 1.000 -9.966 1.000000 0.000000 + -21.4 1.000 -9.966 1.000000 0.000000 + -21.2 1.000 -9.966 1.000000 0.000000 + -21.0 1.000 -9.966 1.000000 0.000000 + -20.8 1.000 -9.966 1.000000 0.000000 + -20.6 1.000 -9.966 1.000000 0.000000 + -20.4 1.000 -9.966 1.000000 0.000000 + -20.2 1.000 -9.966 1.000000 0.000000 + -20.0 1.000 -9.966 1.000000 0.000000 + -19.8 1.000 -9.966 1.000000 0.000000 + -19.6 1.000 -9.966 1.000000 0.000000 + -19.4 1.000 -9.966 1.000000 0.000000 + -19.2 1.000 -9.966 1.000000 0.000000 + -19.0 1.000 -9.966 1.000000 0.000000 + -18.8 1.000 -9.966 1.000000 0.000000 + -18.6 1.000 -9.966 1.000000 0.000000 + -18.4 1.000 -9.966 1.000000 0.000000 + -18.2 1.000 -9.966 1.000000 0.000000 + -18.0 1.000 -9.966 1.000000 0.000000 + -17.8 1.000 -9.966 1.000000 0.000000 + -17.6 1.000 -9.966 1.000000 0.000000 + -17.4 1.000 -9.966 1.000000 0.000000 + -17.2 1.000 -9.966 1.000000 0.000000 + -17.0 1.000 -9.966 1.000000 0.000000 + -16.8 1.000 -9.966 1.000000 0.000000 + -16.6 1.000 -9.966 1.000000 0.000000 + -16.4 1.000 -9.966 1.000000 0.000000 + -16.2 1.000 -9.966 1.000000 0.000000 + -16.0 0.988 -5.858 0.991379 0.008621 + -15.8 1.000 -9.966 1.000000 0.000000 + -15.6 0.991 -6.313 0.993711 0.006289 + -15.4 0.993 -6.629 0.994950 0.005051 + -15.2 1.000 -9.966 1.000000 0.000000 + -15.0 0.995 -7.055 0.996241 0.003759 + -14.8 1.000 -9.966 1.000000 0.000000 + -14.6 0.991 -6.371 0.993958 0.006042 + -14.4 1.000 -9.966 1.000000 0.000000 + -14.2 0.991 -6.313 0.993711 0.006289 + -14.0 0.992 -6.426 0.994186 0.005814 + -13.8 0.991 -6.288 0.993600 0.006400 + -13.6 0.990 -6.113 0.992775 0.007225 + -13.4 0.990 -6.152 0.992968 0.007032 + -13.2 0.992 -6.534 0.994606 0.005394 + -13.0 0.996 -7.332 0.996898 0.003102 + -12.8 0.990 -6.184 0.993121 0.006879 + -12.6 0.994 -7.016 0.996136 0.003864 + -12.4 0.993 -6.658 0.995049 0.004950 + -12.2 0.991 -6.369 0.993953 0.006047 + -12.0 0.992 -6.559 0.994699 0.005301 + -11.8 0.989 -6.002 0.992197 0.007803 + -11.6 0.991 -6.304 0.993671 0.006329 + -11.4 0.987 -5.826 0.991188 0.008812 + -11.2 0.985 -5.632 0.989919 0.010081 + -11.0 0.989 -5.995 0.992162 0.007838 + -10.8 0.984 -5.544 0.989284 0.010717 + -10.6 0.983 -5.377 0.987966 0.012034 + -10.4 0.979 -5.108 0.985502 0.014498 + -10.2 0.977 -4.954 0.983869 0.016131 + -10.0 0.971 -4.652 0.980118 0.019882 + -9.8 0.975 -4.870 0.982896 0.017104 + -9.6 0.974 -4.822 0.982324 0.017676 + -9.4 0.970 -4.608 0.979490 0.020510 + -9.2 0.970 -4.623 0.979702 0.020298 + -9.0 0.970 -4.621 0.979679 0.020321 + -8.8 0.967 -4.472 0.977465 0.022535 + -8.6 0.962 -4.261 0.973915 0.026085 + -8.4 0.960 -4.186 0.972538 0.027462 + -8.2 0.957 -4.098 0.970806 0.029194 + -8.0 0.956 -4.062 0.970061 0.029939 + -7.8 0.953 -3.975 0.968209 0.031791 + -7.6 0.942 -3.677 0.960918 0.039082 + -7.4 0.946 -3.768 0.963301 0.036699 + -7.2 0.937 -3.550 0.957308 0.042692 + -7.0 0.933 -3.463 0.954652 0.045348 + -6.8 0.929 -3.377 0.951866 0.048134 + -6.6 0.920 -3.212 0.946042 0.053958 + -6.4 0.917 -3.164 0.944202 0.055798 + -6.2 0.911 -3.058 0.939981 0.060019 + -6.0 0.903 -2.939 0.934818 0.065182 + -5.8 0.895 -2.829 0.929642 0.070358 + -5.6 0.884 -2.690 0.922540 0.077459 + -5.4 0.877 -2.608 0.917972 0.082028 + -5.2 0.869 -2.531 0.913509 0.086491 + -5.0 0.858 -2.411 0.905967 0.094033 + -4.8 0.846 -2.301 0.898525 0.101475 + -4.6 0.834 -2.201 0.891269 0.108731 + -4.4 0.821 -2.096 0.883085 0.116915 + -4.2 0.806 -1.992 0.874340 0.125660 + -4.0 0.790 -1.882 0.864307 0.135693 + -3.8 0.775 -1.790 0.855445 0.144555 + -3.6 0.755 -1.678 0.843726 0.156274 + -3.4 0.737 -1.587 0.833538 0.166462 + -3.2 0.713 -1.473 0.819841 0.180159 + -3.0 0.691 -1.376 0.807345 0.192655 + -2.8 0.667 -1.280 0.794093 0.205907 + -2.6 0.640 -1.181 0.779404 0.220596 + -2.4 0.612 -1.084 0.764178 0.235822 + -2.2 0.581 -0.987 0.747708 0.252292 + -2.0 0.548 -0.895 0.731037 0.268963 + -1.8 0.510 -0.796 0.712035 0.287965 + -1.6 0.472 -0.706 0.693474 0.306526 + -1.4 0.425 -0.606 0.671514 0.328486 + -1.2 0.378 -0.514 0.649948 0.350053 + -1.0 0.328 -0.425 0.627452 0.372548 + -0.8 0.274 -0.338 0.604549 0.395451 + -0.6 0.212 -0.249 0.579151 0.420849 + -0.4 0.146 -0.163 0.553389 0.446611 + -0.2 0.075 -0.079 0.526648 0.473352 + 0.0 0.000 0.000 0.500000 0.500000 + 0.2 -0.079 0.075 0.473352 0.526648 + 0.4 -0.163 0.146 0.446611 0.553389 + 0.6 -0.249 0.212 0.420849 0.579151 + 0.8 -0.338 0.274 0.395451 0.604549 + 1.0 -0.425 0.328 0.372548 0.627452 + 1.2 -0.514 0.378 0.350053 0.649948 + 1.4 -0.606 0.425 0.328486 0.671514 + 1.6 -0.706 0.472 0.306526 0.693474 + 1.8 -0.796 0.510 0.287965 0.712035 + 2.0 -0.895 0.548 0.268963 0.731037 + 2.2 -0.987 0.581 0.252292 0.747708 + 2.4 -1.084 0.612 0.235822 0.764178 + 2.6 -1.181 0.640 0.220596 0.779404 + 2.8 -1.280 0.667 0.205907 0.794093 + 3.0 -1.376 0.691 0.192655 0.807345 + 3.2 -1.473 0.713 0.180159 0.819841 + 3.4 -1.587 0.737 0.166462 0.833538 + 3.6 -1.678 0.755 0.156274 0.843726 + 3.8 -1.790 0.775 0.144555 0.855445 + 4.0 -1.882 0.790 0.135693 0.864307 + 4.2 -1.992 0.806 0.125660 0.874340 + 4.4 -2.096 0.821 0.116915 0.883085 + 4.6 -2.201 0.834 0.108731 0.891269 + 4.8 -2.301 0.846 0.101475 0.898525 + 5.0 -2.411 0.858 0.094033 0.905967 + 5.2 -2.531 0.869 0.086491 0.913509 + 5.4 -2.608 0.877 0.082028 0.917972 + 5.6 -2.690 0.884 0.077459 0.922540 + 5.8 -2.829 0.895 0.070358 0.929642 + 6.0 -2.939 0.903 0.065182 0.934818 + 6.2 -3.058 0.911 0.060019 0.939981 + 6.4 -3.164 0.917 0.055798 0.944202 + 6.6 -3.212 0.920 0.053958 0.946042 + 6.8 -3.377 0.929 0.048134 0.951866 + 7.0 -3.463 0.933 0.045348 0.954652 + 7.2 -3.550 0.937 0.042692 0.957308 + 7.4 -3.768 0.946 0.036699 0.963301 + 7.6 -3.677 0.942 0.039082 0.960918 + 7.8 -3.975 0.953 0.031791 0.968210 + 8.0 -4.062 0.956 0.029939 0.970061 + 8.2 -4.098 0.957 0.029194 0.970806 + 8.4 -4.186 0.960 0.027462 0.972538 + 8.6 -4.261 0.962 0.026085 0.973915 + 8.8 -4.472 0.967 0.022535 0.977465 + 9.0 -4.621 0.970 0.020321 0.979679 + 9.2 -4.623 0.970 0.020298 0.979702 + 9.4 -4.608 0.970 0.020510 0.979490 + 9.6 -4.822 0.974 0.017676 0.982324 + 9.8 -4.870 0.975 0.017104 0.982896 + 10.0 -4.652 0.971 0.019882 0.980118 + 10.2 -4.954 0.977 0.016131 0.983869 + 10.4 -5.108 0.979 0.014498 0.985502 + 10.6 -5.377 0.983 0.012034 0.987966 + 10.8 -5.544 0.984 0.010717 0.989284 + 11.0 -5.995 0.989 0.007838 0.992162 + 11.2 -5.632 0.985 0.010081 0.989919 + 11.4 -5.826 0.987 0.008812 0.991188 + 11.6 -6.304 0.991 0.006329 0.993671 + 11.8 -6.002 0.989 0.007803 0.992197 + 12.0 -6.559 0.992 0.005301 0.994699 + 12.2 -6.369 0.991 0.006047 0.993953 + 12.4 -6.658 0.993 0.004950 0.995049 + 12.6 -7.016 0.994 0.003864 0.996136 + 12.8 -6.184 0.990 0.006879 0.993121 + 13.0 -7.332 0.996 0.003102 0.996898 + 13.2 -6.534 0.992 0.005394 0.994606 + 13.4 -6.152 0.990 0.007032 0.992968 + 13.6 -6.113 0.990 0.007225 0.992775 + 13.8 -6.288 0.991 0.006400 0.993600 + 14.0 -6.426 0.992 0.005814 0.994186 + 14.2 -6.313 0.991 0.006289 0.993711 + 14.4 -9.966 1.000 0.000000 1.000000 + 14.6 -6.371 0.991 0.006042 0.993958 + 14.8 -9.966 1.000 0.000000 1.000000 + 15.0 -7.055 0.995 0.003759 0.996241 + 15.2 -9.966 1.000 0.000000 1.000000 + 15.4 -6.629 0.993 0.005051 0.994949 + 15.6 -6.313 0.991 0.006289 0.993711 + 15.8 -9.966 1.000 0.000000 1.000000 + 16.0 -5.858 0.988 0.008621 0.991379 + 16.2 -9.966 1.000 0.000000 1.000000 + 16.4 -9.966 1.000 0.000000 1.000000 + 16.6 -9.966 1.000 0.000000 1.000000 + 16.8 -9.966 1.000 0.000000 1.000000 + 17.0 -9.966 1.000 0.000000 1.000000 + 17.2 -9.966 1.000 0.000000 1.000000 + 17.4 -9.966 1.000 0.000000 1.000000 + 17.6 -9.966 1.000 0.000000 1.000000 + 17.8 -9.966 1.000 0.000000 1.000000 + 18.0 -9.966 1.000 0.000000 1.000000 + 18.2 -9.966 1.000 0.000000 1.000000 + 18.4 -9.966 1.000 0.000000 1.000000 + 18.6 -9.966 1.000 0.000000 1.000000 + 18.8 -9.966 1.000 0.000000 1.000000 + 19.0 -9.966 1.000 0.000000 1.000000 + 19.2 -9.966 1.000 0.000000 1.000000 + 19.4 -9.966 1.000 0.000000 1.000000 + 19.6 -9.966 1.000 0.000000 1.000000 + 19.8 -9.966 1.000 0.000000 1.000000 + 20.0 -9.966 1.000 0.000000 1.000000 + 20.2 -9.966 1.000 0.000000 1.000000 + 20.4 -9.966 1.000 0.000000 1.000000 + 20.6 -9.966 1.000 0.000000 1.000000 + 20.8 -9.966 1.000 0.000000 1.000000 + 21.0 -9.966 1.000 0.000000 1.000000 + 21.2 -9.966 1.000 0.000000 1.000000 + 21.4 -9.966 1.000 0.000000 1.000000 + 21.6 -9.966 1.000 0.000000 1.000000 + 21.8 -9.966 1.000 0.000000 1.000000 + 22.0 -9.966 1.000 0.000000 1.000000 + 22.2 -9.966 1.000 0.000000 1.000000 + 22.4 -9.966 1.000 0.000000 1.000000 + 22.6 -9.966 1.000 0.000000 1.000000 + 22.8 -9.966 1.000 0.000000 1.000000 + 23.0 -9.966 1.000 0.000000 1.000000 + 23.2 -9.966 1.000 0.000000 1.000000 + 23.4 -9.966 1.000 0.000000 1.000000 + 23.6 -9.966 1.000 0.000000 1.000000 + 23.8 -9.966 1.000 0.000000 1.000000 + 24.0 -9.966 1.000 0.000000 1.000000 + 24.2 -9.966 1.000 0.000000 1.000000 + 24.4 -9.966 1.000 0.000000 1.000000 + 24.6 -9.966 1.000 0.000000 1.000000 + 24.8 -9.966 1.000 0.000000 1.000000 + 25.0 -9.966 1.000 0.000000 1.000000 + 25.2 -9.966 1.000 0.000000 1.000000 + 25.4 -9.966 1.000 0.000000 1.000000 diff --git a/lib/mixlpf.f90 b/lib/mixlpf.f90 index 1e7319f2..cd775ab8 100755 --- a/lib/mixlpf.f90 +++ b/lib/mixlpf.f90 @@ -1,25 +1,25 @@ -subroutine mixlpf(x1,nbfo,c0) - - real*4 x1(512) - real*8 twopi,phi,dphi - complex c1(512),c2(105+512) - complex c0(64) - data phi/0.d0/ - save phi,c2 - - twopi=8.d0*atan(1.d0) - dphi=twopi*nbfo/12000.d0 - - do i=1,512 - phi=phi+dphi - if(phi.gt.twopi) phi=phi-twopi - xphi=phi - c1(i)=x1(i)*cmplx(cos(xphi),sin(xphi)) - enddo - c2(106:105+512)=c1 - - call fil3c(c2,105+512,c0,n2) - c2(1:105)=c1(512-104:512) !Save 105 trailing samples - - return -end subroutine mixlpf +subroutine mixlpf(x1,nbfo,c0) + + real*4 x1(512) + real*8 twopi,phi,dphi + complex c1(512),c2(105+512) + complex c0(64) + data phi/0.d0/ + save phi,c2 + + twopi=8.d0*atan(1.d0) + dphi=twopi*nbfo/12000.d0 + + do i=1,512 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + c1(i)=x1(i)*cmplx(cos(xphi),sin(xphi)) + enddo + c2(106:105+512)=c1 + + call fil3c(c2,105+512,c0,n2) + c2(1:105)=c1(512-104:512) !Save 105 trailing samples + + return +end subroutine mixlpf diff --git a/lib/morse.f90 b/lib/morse.f90 index 69edf14c..7b428958 100755 --- a/lib/morse.f90 +++ b/lib/morse.f90 @@ -1,87 +1,87 @@ -subroutine morse(msg,idat,n) - -! Convert ascii message to a Morse code bit string. -! Dash = 3 dots -! Space between dots, dashes = 1 dot -! Space between letters = 3 dots -! Space between words = 7 dots - - character*(*) msg - integer idat(250) - integer*1 ic(21,38) - data ic/ & - 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,20, & - 1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,18, & - 1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,16, & - 1,0,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & - 1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & - 1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,14, & - 1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,16, & - 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,0,0,18, & - 1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & - 1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2, & - 1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, & - 1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & - 1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & - 1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & - 1,0,1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,14, & - 1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & - 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, & - 1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & - 1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,14, & - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2/ !Incremental word space - save - - msglen=len(msg) - idat=0 - n=6 - do k=1,msglen - jj=ichar(msg(k:k)) - if(jj.ge.97 .and. jj.le.122) jj=jj-32 !Convert lower to upper case - if(jj.ge.48 .and. jj.le.57) j=jj-48 !Numbers - if(jj.ge.65 .and. jj.le.90) j=jj-55 !Letters - if(jj.eq.47) j=36 !Slash (/) - if(jj.eq.32) j=37 !Word space - j=j+1 - -! Insert this character - nmax=ic(21,j) - if (n + nmax + 4 .gt. size (idat)) exit - do i=1,nmax - n=n+1 - idat(n)=ic(i,j) - enddo - -! Insert character space of 2 dit lengths: - n=n+1 - idat(n)=0 - n=n+1 - idat(n)=0 - enddo - -! Insert word space at end of message - do j=1,4 - n=n+1 - idat(n)=0 - enddo - - return -end subroutine morse +subroutine morse(msg,idat,n) + +! Convert ascii message to a Morse code bit string. +! Dash = 3 dots +! Space between dots, dashes = 1 dot +! Space between letters = 3 dots +! Space between words = 7 dots + + character*(*) msg + integer idat(250) + integer*1 ic(21,38) + data ic/ & + 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,20, & + 1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,18, & + 1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,16, & + 1,0,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & + 1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & + 1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, & + 1,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,14, & + 1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,16, & + 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,0,0,18, & + 1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & + 1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,1,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, & + 1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2, & + 1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & + 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, & + 1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & + 1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & + 1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & + 1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & + 1,0,1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, & + 1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,14, & + 1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & + 1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & + 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, & + 1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & + 1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & + 1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & + 1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & + 1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, & + 1,1,1,0,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,14, & + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2/ !Incremental word space + save + + msglen=len(msg) + idat=0 + n=6 + do k=1,msglen + jj=ichar(msg(k:k)) + if(jj.ge.97 .and. jj.le.122) jj=jj-32 !Convert lower to upper case + if(jj.ge.48 .and. jj.le.57) j=jj-48 !Numbers + if(jj.ge.65 .and. jj.le.90) j=jj-55 !Letters + if(jj.eq.47) j=36 !Slash (/) + if(jj.eq.32) j=37 !Word space + j=j+1 + +! Insert this character + nmax=ic(21,j) + if (n + nmax + 4 .gt. size (idat)) exit + do i=1,nmax + n=n+1 + idat(n)=ic(i,j) + enddo + +! Insert character space of 2 dit lengths: + n=n+1 + idat(n)=0 + n=n+1 + idat(n)=0 + enddo + +! Insert word space at end of message + do j=1,4 + n=n+1 + idat(n)=0 + enddo + + return +end subroutine morse diff --git a/lib/msk144_freq_search.f90 b/lib/msk144_freq_search.f90 index ebfeebf2..5029816a 100755 --- a/lib/msk144_freq_search.f90 +++ b/lib/msk144_freq_search.f90 @@ -1,50 +1,50 @@ -subroutine msk144_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & - cdat2,xmax,bestf,cs,xccs) - - parameter (NSPM=864,NZ=7*NSPM) - complex cdat(NZ) - complex cdat2(NZ) - complex c(NSPM) !Coherently averaged complex data - complex ct2(2*NSPM) - complex cs(NSPM) - complex cb(42) !Complex waveform for sync word - complex cc(0:NSPM-1) - real xcc(0:NSPM-1) - real xccs(0:NSPM-1) - integer navmask(nframes) !Tells which frames to average - - navg=sum(navmask) - n=nframes*NSPM - fac=1.0/(48.0*sqrt(float(navg))) - - do ifr=if1,if2 !Find freq that maximizes sync - ferr=ifr*delf - call tweak1(cdat,n,-(fc+ferr),cdat2) - c=0 - sumw=0. - do i=1,nframes - ib=(i-1)*NSPM+1 - ie=ib+NSPM-1 - if(navmask(i).eq.1) c=c + cdat2(ib:ie) - enddo - - cc=0 - ct2(1:NSPM)=c - ct2(NSPM+1:2*NSPM)=c - - do ish=0,NSPM-1 - cc(ish)=dot_product(ct2(1+ish:42+ish)+ct2(337+ish:378+ish),cb(1:42)) - enddo - - xcc=abs(cc) - xb=maxval(xcc)*fac - if(xb.gt.xmax) then - xmax=xb - bestf=ferr - cs=c - xccs=xcc - endif - enddo - - return -end subroutine msk144_freq_search +subroutine msk144_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & + cdat2,xmax,bestf,cs,xccs) + + parameter (NSPM=864,NZ=7*NSPM) + complex cdat(NZ) + complex cdat2(NZ) + complex c(NSPM) !Coherently averaged complex data + complex ct2(2*NSPM) + complex cs(NSPM) + complex cb(42) !Complex waveform for sync word + complex cc(0:NSPM-1) + real xcc(0:NSPM-1) + real xccs(0:NSPM-1) + integer navmask(nframes) !Tells which frames to average + + navg=sum(navmask) + n=nframes*NSPM + fac=1.0/(48.0*sqrt(float(navg))) + + do ifr=if1,if2 !Find freq that maximizes sync + ferr=ifr*delf + call tweak1(cdat,n,-(fc+ferr),cdat2) + c=0 + sumw=0. + do i=1,nframes + ib=(i-1)*NSPM+1 + ie=ib+NSPM-1 + if(navmask(i).eq.1) c=c + cdat2(ib:ie) + enddo + + cc=0 + ct2(1:NSPM)=c + ct2(NSPM+1:2*NSPM)=c + + do ish=0,NSPM-1 + cc(ish)=dot_product(ct2(1+ish:42+ish)+ct2(337+ish:378+ish),cb(1:42)) + enddo + + xcc=abs(cc) + xb=maxval(xcc)*fac + if(xb.gt.xmax) then + xmax=xb + bestf=ferr + cs=c + xccs=xcc + endif + enddo + + return +end subroutine msk144_freq_search diff --git a/lib/msk144_testmsg.f90 b/lib/msk144_testmsg.f90 index 3ec9e165..e1cff131 100755 --- a/lib/msk144_testmsg.f90 +++ b/lib/msk144_testmsg.f90 @@ -1,47 +1,47 @@ - parameter (MAXTEST=75,NTEST=43) - character*37 testmsg(MAXTEST) - data testmsg(1:NTEST)/ & - "CQ K1ABC FN42", & - "K1ABC W9XYZ EN37", & - "W9XYZ K1ABC -11", & - "K1ABC W9XYZ R-09", & - "W9XYZ K1ABC RRR", & - "K1ABC W9XYZ 73", & - "K1ABC W9XYZ RR73", & - "CQ KH1/KH7Z", & - "CQ TEST K1ABC/R FN42", & - "K1ABC/R W9XYZ EN37", & - "W9XYZ K1ABC/R R FN42", & - "K1ABC/R W9XYZ RR73", & - "CQ TEST K1ABC FN42", & - "K1ABC/R W9XYZ/R R FN42", & - "CQ G4ABC/P IO91", & - "G4ABC/P PA9XYZ JO22", & - "PA9XYZ 590003 IO91NP", & - "G4ABC/P R 570007 JO22DB", & - "PA9XYZ G4ABC/P RR73", & - "CQ PJ4/K1ABC", & - "PJ4/K1ABC ", & - "W9XYZ -11", & - " W9XYZ R-09", & - " PJ4/K1ABC RRR", & - "PJ4/K1ABC 73", & - "CQ W9XYZ EN37", & - " YW18FIFA", & - " W9XYZ -11", & - "W9XYZ R-09", & - "YW18FIFA RRR", & - " YW18FIFA 73", & - "TNX BOB 73 GL", & - "CQ YW18FIFA", & - " KA1ABC", & - "KA1ABC -11", & - " KA1ABC R-17", & - " YW18FIFA RR73", & - " KA1ABC 73", & - "123456789ABCDEF012", & - " -03", & - " R+03", & - " RRR", & - " 73"/ - + parameter (MAXTEST=75,NTEST=43) + character*37 testmsg(MAXTEST) + data testmsg(1:NTEST)/ & + "CQ K1ABC FN42", & + "K1ABC W9XYZ EN37", & + "W9XYZ K1ABC -11", & + "K1ABC W9XYZ R-09", & + "W9XYZ K1ABC RRR", & + "K1ABC W9XYZ 73", & + "K1ABC W9XYZ RR73", & + "CQ KH1/KH7Z", & + "CQ TEST K1ABC/R FN42", & + "K1ABC/R W9XYZ EN37", & + "W9XYZ K1ABC/R R FN42", & + "K1ABC/R W9XYZ RR73", & + "CQ TEST K1ABC FN42", & + "K1ABC/R W9XYZ/R R FN42", & + "CQ G4ABC/P IO91", & + "G4ABC/P PA9XYZ JO22", & + "PA9XYZ 590003 IO91NP", & + "G4ABC/P R 570007 JO22DB", & + "PA9XYZ G4ABC/P RR73", & + "CQ PJ4/K1ABC", & + "PJ4/K1ABC ", & + "W9XYZ -11", & + " W9XYZ R-09", & + " PJ4/K1ABC RRR", & + "PJ4/K1ABC 73", & + "CQ W9XYZ EN37", & + " YW18FIFA", & + " W9XYZ -11", & + "W9XYZ R-09", & + "YW18FIFA RRR", & + " YW18FIFA 73", & + "TNX BOB 73 GL", & + "CQ YW18FIFA", & + " KA1ABC", & + "KA1ABC -11", & + " KA1ABC R-17", & + " YW18FIFA RR73", & + " KA1ABC 73", & + "123456789ABCDEF012", & + " -03", & + " R+03", & + " RRR", & + " 73"/ + diff --git a/lib/msk144code.f90 b/lib/msk144code.f90 index 71e5cde3..2cb4d6a4 100755 --- a/lib/msk144code.f90 +++ b/lib/msk144code.f90 @@ -1,83 +1,83 @@ -program msk144code - -! Provides examples of message packing, bit and symbol ordering, -! LDPC encoding, and other necessary details of the MSK144 protocol. - - use packjt77 - character*77 c77 - character msg*37,msgsent*37,bad*1,msgtype*18 - integer*4 i4tone(144) - include 'msk144_testmsg.f90' - - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: msk144code "message"' - print*,' msk144code -t' - print*,' ' - print*,'Examples:' - print*,' msk144code "KA1ABC WB9XYZ EN37"' - print*,' msk144code " R-03"' - print*,' msk144code "KA1ABC WB9XYZ R EN37"' - go to 999 - endif - - call getarg(1,msg) - nmsg=1 - if(msg(1:2).eq."-t") then - nmsg=NTEST - endif - - write(*,1010) -1010 format(4x,"Message",31x,"Decoded",29x,"Err i3.n3"/100("-")) - - do imsg=1,nmsg - if(nmsg.gt.1) msg=testmsg(imsg) - call fmtmsg(msg,iz) !To upper case, collapse multiple blanks - call genmsk_128_90(msg,ichk,msgsent,i4tone,itype) - i3=-1 - n3=-1 - call pack77(msg,i3,n3,c77) - msgtype="" - if(i3.eq.0) then - if(n3.eq.0) msgtype="Free text" - if(n3.eq.1) msgtype="DXpedition mode" - if(n3.eq.2) msgtype="EU VHF Contest" - if(n3.eq.3) msgtype="ARRL Field Day" - if(n3.eq.4) msgtype="ARRL Field Day" - if(n3.eq.5) msgtype="Telemetry" - if(n3.ge.6) msgtype="Undefined type" - endif - if(i3.eq.1) msgtype="Standard msg" - if(i3.eq.2) msgtype="EU VHF Contest" - if(i3.eq.3) msgtype="ARRL RTTY Roundup" - if(i3.eq.4) msgtype="Nonstandard calls" - if(i3.eq.5) msgtype="EU VHF Contest" - if(i3.ge.6) msgtype="Undefined msg type" - if(i3.ge.1) n3=-1 - if(i4tone(41).lt.0) then - msgtype="Sh msg" - i3=-1 - endif - bad=" " - if(msg.ne.msgsent) bad="*" - if(i3.eq.0.and.n3.ge.0) then - write(*,1020) imsg,msg,msgsent,bad,i3,n3,msgtype -1020 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',i1,1x,a18) - elseif(i3.ge.1) then - write(*,1022) imsg,msg,msgsent,bad,i3,msgtype -1022 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',1x,1x,a18) - elseif(i3.lt.0) then - write(*,1024) imsg,msg,msgsent,bad,msgtype -1024 format(i2,'.',1x,a37,1x,a37,1x,a1,6x,a18) - endif - - enddo - - if(nmsg.eq.1) then - n=144 - if(i4tone(41).lt.0) n=40 - write(*,1030) i4tone(1:n) -1030 format(/'Channel symbols'/(72i1)) - endif - -999 end program msk144code +program msk144code + +! Provides examples of message packing, bit and symbol ordering, +! LDPC encoding, and other necessary details of the MSK144 protocol. + + use packjt77 + character*77 c77 + character msg*37,msgsent*37,bad*1,msgtype*18 + integer*4 i4tone(144) + include 'msk144_testmsg.f90' + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: msk144code "message"' + print*,' msk144code -t' + print*,' ' + print*,'Examples:' + print*,' msk144code "KA1ABC WB9XYZ EN37"' + print*,' msk144code " R-03"' + print*,' msk144code "KA1ABC WB9XYZ R EN37"' + go to 999 + endif + + call getarg(1,msg) + nmsg=1 + if(msg(1:2).eq."-t") then + nmsg=NTEST + endif + + write(*,1010) +1010 format(4x,"Message",31x,"Decoded",29x,"Err i3.n3"/100("-")) + + do imsg=1,nmsg + if(nmsg.gt.1) msg=testmsg(imsg) + call fmtmsg(msg,iz) !To upper case, collapse multiple blanks + call genmsk_128_90(msg,ichk,msgsent,i4tone,itype) + i3=-1 + n3=-1 + call pack77(msg,i3,n3,c77) + msgtype="" + if(i3.eq.0) then + if(n3.eq.0) msgtype="Free text" + if(n3.eq.1) msgtype="DXpedition mode" + if(n3.eq.2) msgtype="EU VHF Contest" + if(n3.eq.3) msgtype="ARRL Field Day" + if(n3.eq.4) msgtype="ARRL Field Day" + if(n3.eq.5) msgtype="Telemetry" + if(n3.ge.6) msgtype="Undefined type" + endif + if(i3.eq.1) msgtype="Standard msg" + if(i3.eq.2) msgtype="EU VHF Contest" + if(i3.eq.3) msgtype="ARRL RTTY Roundup" + if(i3.eq.4) msgtype="Nonstandard calls" + if(i3.eq.5) msgtype="EU VHF Contest" + if(i3.ge.6) msgtype="Undefined msg type" + if(i3.ge.1) n3=-1 + if(i4tone(41).lt.0) then + msgtype="Sh msg" + i3=-1 + endif + bad=" " + if(msg.ne.msgsent) bad="*" + if(i3.eq.0.and.n3.ge.0) then + write(*,1020) imsg,msg,msgsent,bad,i3,n3,msgtype +1020 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',i1,1x,a18) + elseif(i3.ge.1) then + write(*,1022) imsg,msg,msgsent,bad,i3,msgtype +1022 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',1x,1x,a18) + elseif(i3.lt.0) then + write(*,1024) imsg,msg,msgsent,bad,msgtype +1024 format(i2,'.',1x,a37,1x,a37,1x,a1,6x,a18) + endif + + enddo + + if(nmsg.eq.1) then + n=144 + if(i4tone(41).lt.0) n=40 + write(*,1030) i4tone(1:n) +1030 format(/'Channel symbols'/(72i1)) + endif + +999 end program msk144code diff --git a/lib/msk144decodeframe.f90 b/lib/msk144decodeframe.f90 index 9592accb..b8bdba28 100755 --- a/lib/msk144decodeframe.f90 +++ b/lib/msk144decodeframe.f90 @@ -1,112 +1,112 @@ -subroutine msk144decodeframe(c,softbits,msgreceived,nsuccess) -! use timer_module, only: timer - use packjt77 - parameter (NSPM=864) - character*37 msgreceived - character*77 c77 - complex cb(42) - complex cfac,cca,ccb - complex c(NSPM) - integer*1 decoded77(77),apmask(128),cw(128) - integer s8(8),hardbits(144) - real*8 dt, fs, pi, twopi - real cbi(42),cbq(42) - real pp(12) - real softbits(144) - real llr(128) - logical first,unpk77_success - data first/.true./ - data s8/0,1,1,1,0,0,1,0/ - save first,cb,fs,pi,twopi,dt,s8,pp - - if(first) then -! define half-sine pulse and raised-cosine edge window - pi=4d0*datan(1d0) - twopi=8d0*datan(1d0) - fs=12000.0 - dt=1.0/fs - - do i=1,12 - angle=(i-1)*pi/12.0 - pp(i)=sin(angle) - enddo - -! define the sync word waveforms - s8=2*s8-1 - cbq(1:6)=pp(7:12)*s8(1) - cbq(7:18)=pp*s8(3) - cbq(19:30)=pp*s8(5) - cbq(31:42)=pp*s8(7) - cbi(1:12)=pp*s8(2) - cbi(13:24)=pp*s8(4) - cbi(25:36)=pp*s8(6) - cbi(37:42)=pp(1:6)*s8(8) - cb=cmplx(cbi,cbq) - first=.false. - endif - - nsuccess=0 - msgreceived=' ' - -! Estimate carrier phase. - cca=sum(c(1:1+41)*conjg(cb)) - ccb=sum(c(1+56*6:1+56*6+41)*conjg(cb)) - cfac=ccb*conjg(cca) - phase0=atan2(imag(cca+ccb),real(cca+ccb)) - -! Remove phase error - want constellation rotated so that sample points lie on I/Q axes - cfac=cmplx(cos(phase0),sin(phase0)) - c=c*conjg(cfac) - -! matched filter - - softbits(1)=sum(imag(c(1:6))*pp(7:12))+sum(imag(c(864-5:864))*pp(1:6)) - softbits(2)=sum(real(c(1:12))*pp) - do i=2,72 - softbits(2*i-1)=sum(imag(c(1+(i-1)*12-6:1+(i-1)*12+5))*pp) - softbits(2*i)=sum(real(c(7+(i-1)*12-6:7+(i-1)*12+5))*pp) - enddo - -! sync word hard error weight is used as a discriminator for -! frames that have reasonable probability of decoding - hardbits=0 - do i=1,144 - if( softbits(i) .ge. 0.0 ) then - hardbits(i)=1 - endif - enddo - nbadsync1=(8-sum( (2*hardbits(1:8)-1)*s8 ) )/2 - nbadsync2=(8-sum( (2*hardbits(1+56:8+56)-1)*s8 ) )/2 - nbadsync=nbadsync1+nbadsync2 - if( nbadsync .gt. 4 ) then - return - endif - -! normalize the softsymbols before submitting to decoder - sav=sum(softbits)/144 - s2av=sum(softbits*softbits)/144 - ssig=sqrt(s2av-sav*sav) - softbits=softbits/ssig - - sigma=0.60 - llr(1:48)=softbits(9:9+47) - llr(49:128)=softbits(65:65+80-1) - llr=2.0*llr/(sigma*sigma) - - max_iterations=10 - apmask=0 - dmin=0.0 - call bpdecode128_90(llr,apmask,max_iterations,decoded77,cw,nharderror,niterations) - if( nharderror .ge. 0 .and. nharderror .lt. 18 ) then - nsuccess=1 - write(c77,'(77i1)') decoded77 - read(c77(72:77),'(2b3)') n3,i3 - if( (i3.eq.0.and.(n3.eq.1 .or. n3.eq.3 .or. n3.eq.4 .or. n3.gt.5)) .or. i3.eq.3 .or. i3.gt.5 ) then - nsuccess=0 - else - call unpack77(c77,1,msgreceived,unpk77_success) - if(.not.unpk77_success) nsuccess=0 - endif - endif - - return -end subroutine msk144decodeframe +subroutine msk144decodeframe(c,softbits,msgreceived,nsuccess) +! use timer_module, only: timer + use packjt77 + parameter (NSPM=864) + character*37 msgreceived + character*77 c77 + complex cb(42) + complex cfac,cca,ccb + complex c(NSPM) + integer*1 decoded77(77),apmask(128),cw(128) + integer s8(8),hardbits(144) + real*8 dt, fs, pi, twopi + real cbi(42),cbq(42) + real pp(12) + real softbits(144) + real llr(128) + logical first,unpk77_success + data first/.true./ + data s8/0,1,1,1,0,0,1,0/ + save first,cb,fs,pi,twopi,dt,s8,pp + + if(first) then +! define half-sine pulse and raised-cosine edge window + pi=4d0*datan(1d0) + twopi=8d0*datan(1d0) + fs=12000.0 + dt=1.0/fs + + do i=1,12 + angle=(i-1)*pi/12.0 + pp(i)=sin(angle) + enddo + +! define the sync word waveforms + s8=2*s8-1 + cbq(1:6)=pp(7:12)*s8(1) + cbq(7:18)=pp*s8(3) + cbq(19:30)=pp*s8(5) + cbq(31:42)=pp*s8(7) + cbi(1:12)=pp*s8(2) + cbi(13:24)=pp*s8(4) + cbi(25:36)=pp*s8(6) + cbi(37:42)=pp(1:6)*s8(8) + cb=cmplx(cbi,cbq) + first=.false. + endif + + nsuccess=0 + msgreceived=' ' + +! Estimate carrier phase. + cca=sum(c(1:1+41)*conjg(cb)) + ccb=sum(c(1+56*6:1+56*6+41)*conjg(cb)) + cfac=ccb*conjg(cca) + phase0=atan2(imag(cca+ccb),real(cca+ccb)) + +! Remove phase error - want constellation rotated so that sample points lie on I/Q axes + cfac=cmplx(cos(phase0),sin(phase0)) + c=c*conjg(cfac) + +! matched filter - + softbits(1)=sum(imag(c(1:6))*pp(7:12))+sum(imag(c(864-5:864))*pp(1:6)) + softbits(2)=sum(real(c(1:12))*pp) + do i=2,72 + softbits(2*i-1)=sum(imag(c(1+(i-1)*12-6:1+(i-1)*12+5))*pp) + softbits(2*i)=sum(real(c(7+(i-1)*12-6:7+(i-1)*12+5))*pp) + enddo + +! sync word hard error weight is used as a discriminator for +! frames that have reasonable probability of decoding + hardbits=0 + do i=1,144 + if( softbits(i) .ge. 0.0 ) then + hardbits(i)=1 + endif + enddo + nbadsync1=(8-sum( (2*hardbits(1:8)-1)*s8 ) )/2 + nbadsync2=(8-sum( (2*hardbits(1+56:8+56)-1)*s8 ) )/2 + nbadsync=nbadsync1+nbadsync2 + if( nbadsync .gt. 4 ) then + return + endif + +! normalize the softsymbols before submitting to decoder + sav=sum(softbits)/144 + s2av=sum(softbits*softbits)/144 + ssig=sqrt(s2av-sav*sav) + softbits=softbits/ssig + + sigma=0.60 + llr(1:48)=softbits(9:9+47) + llr(49:128)=softbits(65:65+80-1) + llr=2.0*llr/(sigma*sigma) + + max_iterations=10 + apmask=0 + dmin=0.0 + call bpdecode128_90(llr,apmask,max_iterations,decoded77,cw,nharderror,niterations) + if( nharderror .ge. 0 .and. nharderror .lt. 18 ) then + nsuccess=1 + write(c77,'(77i1)') decoded77 + read(c77(72:77),'(2b3)') n3,i3 + if( (i3.eq.0.and.(n3.eq.1 .or. n3.eq.3 .or. n3.eq.4 .or. n3.gt.5)) .or. i3.eq.3 .or. i3.gt.5 ) then + nsuccess=0 + else + call unpack77(c77,1,msgreceived,unpk77_success) + if(.not.unpk77_success) nsuccess=0 + endif + endif + + return +end subroutine msk144decodeframe diff --git a/lib/msk144signalquality.f90 b/lib/msk144signalquality.f90 index 978d3cbd..c2ba5f6c 100755 --- a/lib/msk144signalquality.f90 +++ b/lib/msk144signalquality.f90 @@ -1,213 +1,213 @@ -subroutine msk144signalquality(cframe,snr,freq,t0,softbits,msg,dxcall, & - btrain,datadir,nbiterrors,eyeopening,pcoeffs) - - character*37 msg,msgsent - character*12 dxcall - character*12 training_dxcall - character*12 trained_dxcall - character*512 pcoeff_filename - character*8 date - character*10 time - character*5 zone - character*(*) datadir - - complex cframe(864) - complex cross(864) - complex cross_avg(864) - complex canalytic(1024) - complex cmodel(1024) - - integer i4tone(144) - integer hardbits(144) - integer msgbits(144) - integer values(8) - - logical*1 btrain - logical*1 first - logical*1 currently_training - logical*1 msg_has_dxcall - logical*1 is_training_frame - - real softbits(144) - real waveform(0:863) - real d(1024) - real phase(864) - real twopi,freq,phi,dphi0,dphi1,dphi - real*8 x(145),y(145),pp(145),sigmay(145),a(5),chisqr - real*8 pcoeffs(5) - - parameter (NFREQLOW=500,NFREQHIGH=2500) - data first/.true./ - save cross_avg,wt_avg,first,currently_training, & - navg,tlast,training_dxcall,trained_dxcall - - if (first) then - navg=0 - cross=cmplx(0.0,0.0) - cross_avg=cmplx(0.0,0.0) - wt_avg=0.0 - tlast=0.0 - trained_dxcall(1:12)=' ' - training_dxcall(1:12)=' ' - currently_training=.false. - first=.false. - endif - - if( (currently_training .and. (dxcall .ne. training_dxcall)) .or. & - (navg .gt. 10 )) then !reset and retrain - navg=0 - cross=cmplx(0.0,0.0) - cross_avg=cmplx(0.0,0.0) - wt_avg=0.0 - tlast=0.0 - trained_dxcall(1:12)=' ' - currently_training=.false. - training_dxcall(1:12)=' ' - trained_dxcall(1:12)=' ' -!write(*,*) 'reset to untrained state ' - endif - - indx_dxcall=index(msg,trim(dxcall)) - msg_has_dxcall = indx_dxcall .ge. 4 - - if( btrain .and. msg_has_dxcall .and. (.not. currently_training) ) then - currently_training=.true. - training_dxcall=trim(dxcall) - trained_dxcall(1:12)=' ' -!write(*,*) 'start training on call ',training_dxcall - endif - - if( msg_has_dxcall .and. currently_training ) then - trained_dxcall(1:12)=' ' - training_dxcall=dxcall - endif - -! use decoded message to figure out how many bit errors in the frame - do i=1, 144 - hardbits(i)=0 - if(softbits(i) .gt. 0 ) hardbits(i)=1 - enddo - -! generate tones from decoded message - ichk=0 - call genmsk_128_90(msg,ichk,msgsent,i4tone,itype) - -! reconstruct message bits from tones - msgbits(1)=0 - do i=1,143 - if( i4tone(i) .eq. 0 ) then - if( mod(i,2) .eq. 1 ) then - msgbits(i+1)=msgbits(i) - else - msgbits(i+1)=mod(msgbits(i)+1,2) - endif - else - if( mod(i,2) .eq. 1 ) then - msgbits(i+1)=mod(msgbits(i)+1,2) - else - msgbits(i+1)=msgbits(i) - endif - endif - enddo - - nbiterrors=0 - do i=1,144 - if( hardbits(i) .ne. msgbits(i) ) nbiterrors=nbiterrors+1 - enddo - - nplus=0 - nminus=0 - eyetop=1 - eyebot=-1 - do i=1,144 - if( msgbits(i) .eq. 1 ) then - if( softbits(i) .lt. eyetop ) eyetop=softbits(i) - else - if( softbits(i) .gt. eyebot ) eyebot=softbits(i) - endif - enddo - eyeopening=eyetop-eyebot - - is_training_frame = & - (snr.gt.5.0 .and.(nbiterrors.lt.7)) .and. & - (abs(t0-tlast) .gt. 0.072) .and. & - msg_has_dxcall - if( currently_training .and. is_training_frame ) then - twopi=8.0*atan(1.0) - nsym=144 - if( i4tone(41) .lt. 0 ) nsym=40 - dphi0=twopi*(freq-500)/12000.0 - dphi1=twopi*(freq+500)/12000.0 - phi=-twopi/8 - indx=0 - do i=1,nsym - if( i4tone(i) .eq. 0 ) then - dphi=dphi0 - else - dphi=dphi1 - endif - do j=1,6 - waveform(indx)=cos(phi); - indx=indx+1 - phi=mod(phi+dphi,twopi) - enddo - enddo -! convert the passband waveform to complex baseband - npts=864 - nfft=1024 - d=0 - d(1:864)=waveform(0:863) - call analytic(d,npts,nfft,canalytic,pcoeffs,.false.) ! don't equalize the model - call tweak1(canalytic,nfft,-freq,cmodel) - call four2a(cframe(1:864),864,1,-1,1) - call four2a(cmodel(1:864),864,1,-1,1) - -! Cross spectra from different messages can be averaged -! as long as all messages originate from dxcall. - cross=cmodel(1:864)*conjg(cframe)/1000.0 - cross=cshift(cross,864/2) - cross_avg=cross_avg+10**(snr/20.0)*cross - wt_avg=wt_avg+10**(snr/20.0) - navg=navg+1 - tlast=t0 - phase=atan2(imag(cross_avg),real(cross_avg)) - df=12000.0/864.0 - nm=145 - do i=1,145 - x(i)=(i-73)*df/1000.0 - enddo - y=phase((864/2-nm/2):(864/2+nm/2)) - sigmay=wt_avg/abs(cross_avg((864/2-nm/2):(864/2+nm/2))) - mode=1 - npts=145 - nterms=5 - call polyfit(x,y,sigmay,npts,nterms,mode,a,chisqr) - pp=a(1)+x*(a(2)+x*(a(3)+x*(a(4)+x*a(5)))) - rmsdiff=sum( (pp-phase((864/2-nm/2):(864/2+nm/2)))**2 )/145.0 -!write(*,*) 'training ',navg,sqrt(chisqr),rmsdiff - if( (sqrt(chisqr).lt.1.8) .and. (rmsdiff.lt.0.5) .and. (navg.ge.5) ) then - trained_dxcall=dxcall - call date_and_time(date,time,zone,values) - write(pcoeff_filename,'(i2.2,i2.2,i2.2,"_",i2.2,i2.2,i2.2)') & - values(1)-2000,values(2),values(3),values(5),values(6),values(7) - pcoeff_filename=trim(trained_dxcall)//"_"//trim(pcoeff_filename)//".pcoeff" - pcoeff_filename=datadir//'/'//trim(pcoeff_filename) -!write(*,*) 'trained - writing coefficients to: ',pcoeff_filename - open(17,file=pcoeff_filename,status='new') - write(17,'(i4,2f10.2,3i5,5e25.16)') navg,sqrt(chisqr),rmsdiff,NFREQLOW,NFREQHIGH,nterms,a - do i=1, 145 - write(17,*) x(i),pp(i),y(i),sigmay(i) - enddo - do i=1,864 - write(17,*) i,real(cframe(i)),imag(cframe(i)),real(cross_avg(i)),imag(cross_avg(i)) - enddo - close(17) - training_dxcall(1:12)=' ' - currently_training=.false. - btrain=.false. - navg=0 - endif - endif - - return - end subroutine msk144signalquality +subroutine msk144signalquality(cframe,snr,freq,t0,softbits,msg,dxcall, & + btrain,datadir,nbiterrors,eyeopening,pcoeffs) + + character*37 msg,msgsent + character*12 dxcall + character*12 training_dxcall + character*12 trained_dxcall + character*512 pcoeff_filename + character*8 date + character*10 time + character*5 zone + character*(*) datadir + + complex cframe(864) + complex cross(864) + complex cross_avg(864) + complex canalytic(1024) + complex cmodel(1024) + + integer i4tone(144) + integer hardbits(144) + integer msgbits(144) + integer values(8) + + logical*1 btrain + logical*1 first + logical*1 currently_training + logical*1 msg_has_dxcall + logical*1 is_training_frame + + real softbits(144) + real waveform(0:863) + real d(1024) + real phase(864) + real twopi,freq,phi,dphi0,dphi1,dphi + real*8 x(145),y(145),pp(145),sigmay(145),a(5),chisqr + real*8 pcoeffs(5) + + parameter (NFREQLOW=500,NFREQHIGH=2500) + data first/.true./ + save cross_avg,wt_avg,first,currently_training, & + navg,tlast,training_dxcall,trained_dxcall + + if (first) then + navg=0 + cross=cmplx(0.0,0.0) + cross_avg=cmplx(0.0,0.0) + wt_avg=0.0 + tlast=0.0 + trained_dxcall(1:12)=' ' + training_dxcall(1:12)=' ' + currently_training=.false. + first=.false. + endif + + if( (currently_training .and. (dxcall .ne. training_dxcall)) .or. & + (navg .gt. 10 )) then !reset and retrain + navg=0 + cross=cmplx(0.0,0.0) + cross_avg=cmplx(0.0,0.0) + wt_avg=0.0 + tlast=0.0 + trained_dxcall(1:12)=' ' + currently_training=.false. + training_dxcall(1:12)=' ' + trained_dxcall(1:12)=' ' +!write(*,*) 'reset to untrained state ' + endif + + indx_dxcall=index(msg,trim(dxcall)) + msg_has_dxcall = indx_dxcall .ge. 4 + + if( btrain .and. msg_has_dxcall .and. (.not. currently_training) ) then + currently_training=.true. + training_dxcall=trim(dxcall) + trained_dxcall(1:12)=' ' +!write(*,*) 'start training on call ',training_dxcall + endif + + if( msg_has_dxcall .and. currently_training ) then + trained_dxcall(1:12)=' ' + training_dxcall=dxcall + endif + +! use decoded message to figure out how many bit errors in the frame + do i=1, 144 + hardbits(i)=0 + if(softbits(i) .gt. 0 ) hardbits(i)=1 + enddo + +! generate tones from decoded message + ichk=0 + call genmsk_128_90(msg,ichk,msgsent,i4tone,itype) + +! reconstruct message bits from tones + msgbits(1)=0 + do i=1,143 + if( i4tone(i) .eq. 0 ) then + if( mod(i,2) .eq. 1 ) then + msgbits(i+1)=msgbits(i) + else + msgbits(i+1)=mod(msgbits(i)+1,2) + endif + else + if( mod(i,2) .eq. 1 ) then + msgbits(i+1)=mod(msgbits(i)+1,2) + else + msgbits(i+1)=msgbits(i) + endif + endif + enddo + + nbiterrors=0 + do i=1,144 + if( hardbits(i) .ne. msgbits(i) ) nbiterrors=nbiterrors+1 + enddo + + nplus=0 + nminus=0 + eyetop=1 + eyebot=-1 + do i=1,144 + if( msgbits(i) .eq. 1 ) then + if( softbits(i) .lt. eyetop ) eyetop=softbits(i) + else + if( softbits(i) .gt. eyebot ) eyebot=softbits(i) + endif + enddo + eyeopening=eyetop-eyebot + + is_training_frame = & + (snr.gt.5.0 .and.(nbiterrors.lt.7)) .and. & + (abs(t0-tlast) .gt. 0.072) .and. & + msg_has_dxcall + if( currently_training .and. is_training_frame ) then + twopi=8.0*atan(1.0) + nsym=144 + if( i4tone(41) .lt. 0 ) nsym=40 + dphi0=twopi*(freq-500)/12000.0 + dphi1=twopi*(freq+500)/12000.0 + phi=-twopi/8 + indx=0 + do i=1,nsym + if( i4tone(i) .eq. 0 ) then + dphi=dphi0 + else + dphi=dphi1 + endif + do j=1,6 + waveform(indx)=cos(phi); + indx=indx+1 + phi=mod(phi+dphi,twopi) + enddo + enddo +! convert the passband waveform to complex baseband + npts=864 + nfft=1024 + d=0 + d(1:864)=waveform(0:863) + call analytic(d,npts,nfft,canalytic,pcoeffs,.false.) ! don't equalize the model + call tweak1(canalytic,nfft,-freq,cmodel) + call four2a(cframe(1:864),864,1,-1,1) + call four2a(cmodel(1:864),864,1,-1,1) + +! Cross spectra from different messages can be averaged +! as long as all messages originate from dxcall. + cross=cmodel(1:864)*conjg(cframe)/1000.0 + cross=cshift(cross,864/2) + cross_avg=cross_avg+10**(snr/20.0)*cross + wt_avg=wt_avg+10**(snr/20.0) + navg=navg+1 + tlast=t0 + phase=atan2(imag(cross_avg),real(cross_avg)) + df=12000.0/864.0 + nm=145 + do i=1,145 + x(i)=(i-73)*df/1000.0 + enddo + y=phase((864/2-nm/2):(864/2+nm/2)) + sigmay=wt_avg/abs(cross_avg((864/2-nm/2):(864/2+nm/2))) + mode=1 + npts=145 + nterms=5 + call polyfit(x,y,sigmay,npts,nterms,mode,a,chisqr) + pp=a(1)+x*(a(2)+x*(a(3)+x*(a(4)+x*a(5)))) + rmsdiff=sum( (pp-phase((864/2-nm/2):(864/2+nm/2)))**2 )/145.0 +!write(*,*) 'training ',navg,sqrt(chisqr),rmsdiff + if( (sqrt(chisqr).lt.1.8) .and. (rmsdiff.lt.0.5) .and. (navg.ge.5) ) then + trained_dxcall=dxcall + call date_and_time(date,time,zone,values) + write(pcoeff_filename,'(i2.2,i2.2,i2.2,"_",i2.2,i2.2,i2.2)') & + values(1)-2000,values(2),values(3),values(5),values(6),values(7) + pcoeff_filename=trim(trained_dxcall)//"_"//trim(pcoeff_filename)//".pcoeff" + pcoeff_filename=datadir//'/'//trim(pcoeff_filename) +!write(*,*) 'trained - writing coefficients to: ',pcoeff_filename + open(17,file=pcoeff_filename,status='new') + write(17,'(i4,2f10.2,3i5,5e25.16)') navg,sqrt(chisqr),rmsdiff,NFREQLOW,NFREQHIGH,nterms,a + do i=1, 145 + write(17,*) x(i),pp(i),y(i),sigmay(i) + enddo + do i=1,864 + write(17,*) i,real(cframe(i)),imag(cframe(i)),real(cross_avg(i)),imag(cross_avg(i)) + enddo + close(17) + training_dxcall(1:12)=' ' + currently_training=.false. + btrain=.false. + navg=0 + endif + endif + + return + end subroutine msk144signalquality diff --git a/lib/msk144sim.f90 b/lib/msk144sim.f90 index 20a62c8a..5a4f3cb5 100755 --- a/lib/msk144sim.f90 +++ b/lib/msk144sim.f90 @@ -1,106 +1,106 @@ -program msk144sim - - use wavhdr - parameter (NMAX=30*12000) - real pings(0:NMAX-1) - real waveform(0:NMAX-1) - character arg*8,msg*37,msgsent*37,fname*40 - real wave(0:NMAX-1) !Simulated received waveform - real*8 twopi,freq,phi,dphi0,dphi1,dphi - type(hdr) h !Header for .wav file - integer*2 iwave(0:NMAX-1) - integer itone(144) !Message bits - - nargs=iargc() - if(nargs.ne.6) then - print*,'Usage: msk144sim message TRp freq width snr nfiles' - print*,'Example: msk144sim "K1ABC W9XYZ EN37" 15 1500 0.12 2 1' - print*,' msk144sim "K1ABC W9XYZ EN37" 30 1500 2.5 15 1' - go to 999 - endif - call getarg(1,msg) - call getarg(2,arg) - read(arg,*) nTRperiod - call getarg(3,arg) - read(arg,*) freq - call getarg(4,arg) - read(arg,*) width - call getarg(5,arg) - read(arg,*) snrdb - call getarg(6,arg) - read(arg,*) nfiles - -!sig is the peak amplitude of the ping. - sig=sqrt(2.0)*10.0**(0.05*snrdb) - npts=nTRperiod*12000 - h=default_header(12000,npts) - i1=len(trim(msg))-5 - ichk=0 - itype=1 - call fmtmsg(msg,iz) - call genmsk_128_90(msg,ichk,msgsent,itone,itype) - write(*,*) 'Requested message: ',msg - write(*,*) 'Message sent : ',msgsent - write(*,*) 'Tones: ' - if(itone(41).ge.0) then - write(*,'(1x,72i1)') itone(1:72) - write(*,'(1x,72i1)') itone(73:144) - else - write(*,'(1x,40i1)') itone(1:40) - endif - - twopi=8.d0*atan(1.d0) - nsym=144 - nsps=6 - if( itone(41) .lt. 0 ) nsym=40 - baud=2000.d0 - dphi0=twopi*(freq-0.25d0*baud)/12000.d0 - dphi1=twopi*(freq+0.25d0*baud)/12000.d0 - phi=0.0 - k=0 - nreps=npts/(nsym*nsps) - - do jrep=1,nreps - do i=1,nsym - if( itone(i) .eq. 0 ) then - dphi=dphi0 - else - dphi=dphi1 - endif - do j=1,nsps - waveform(k)=cos(phi) - k=k+1 - phi=mod(phi+dphi,twopi) - enddo - enddo - enddo - - if(itype.lt.1 .or. itype.gt.7) then - print*,'Illegal message' - go to 999 - endif - - call makepings(pings,nTRperiod,npts,width,sig) - -! call sgran() - do ifile=1,nfiles !Loop over requested number of files - write(fname,1002) ifile !Output filename -1002 format('000000_',i6.6) - open(10,file=fname(1:13)//'.wav',access='stream',status='unknown') - - wave=0.0 - iwave=0 - fac=sqrt(6000.0/2500.0) - do i=0,npts-1 - xx=gran() - wave(i)=pings(i)*waveform(i) + fac*xx - iwave(i)=30.0*wave(i) - enddo - - write(10) h,iwave(0:npts-1) !Save the .wav file - endfile(10) - close(10) - - enddo - -999 end program msk144sim +program msk144sim + + use wavhdr + parameter (NMAX=30*12000) + real pings(0:NMAX-1) + real waveform(0:NMAX-1) + character arg*8,msg*37,msgsent*37,fname*40 + real wave(0:NMAX-1) !Simulated received waveform + real*8 twopi,freq,phi,dphi0,dphi1,dphi + type(hdr) h !Header for .wav file + integer*2 iwave(0:NMAX-1) + integer itone(144) !Message bits + + nargs=iargc() + if(nargs.ne.6) then + print*,'Usage: msk144sim message TRp freq width snr nfiles' + print*,'Example: msk144sim "K1ABC W9XYZ EN37" 15 1500 0.12 2 1' + print*,' msk144sim "K1ABC W9XYZ EN37" 30 1500 2.5 15 1' + go to 999 + endif + call getarg(1,msg) + call getarg(2,arg) + read(arg,*) nTRperiod + call getarg(3,arg) + read(arg,*) freq + call getarg(4,arg) + read(arg,*) width + call getarg(5,arg) + read(arg,*) snrdb + call getarg(6,arg) + read(arg,*) nfiles + +!sig is the peak amplitude of the ping. + sig=sqrt(2.0)*10.0**(0.05*snrdb) + npts=nTRperiod*12000 + h=default_header(12000,npts) + i1=len(trim(msg))-5 + ichk=0 + itype=1 + call fmtmsg(msg,iz) + call genmsk_128_90(msg,ichk,msgsent,itone,itype) + write(*,*) 'Requested message: ',msg + write(*,*) 'Message sent : ',msgsent + write(*,*) 'Tones: ' + if(itone(41).ge.0) then + write(*,'(1x,72i1)') itone(1:72) + write(*,'(1x,72i1)') itone(73:144) + else + write(*,'(1x,40i1)') itone(1:40) + endif + + twopi=8.d0*atan(1.d0) + nsym=144 + nsps=6 + if( itone(41) .lt. 0 ) nsym=40 + baud=2000.d0 + dphi0=twopi*(freq-0.25d0*baud)/12000.d0 + dphi1=twopi*(freq+0.25d0*baud)/12000.d0 + phi=0.0 + k=0 + nreps=npts/(nsym*nsps) + + do jrep=1,nreps + do i=1,nsym + if( itone(i) .eq. 0 ) then + dphi=dphi0 + else + dphi=dphi1 + endif + do j=1,nsps + waveform(k)=cos(phi) + k=k+1 + phi=mod(phi+dphi,twopi) + enddo + enddo + enddo + + if(itype.lt.1 .or. itype.gt.7) then + print*,'Illegal message' + go to 999 + endif + + call makepings(pings,nTRperiod,npts,width,sig) + +! call sgran() + do ifile=1,nfiles !Loop over requested number of files + write(fname,1002) ifile !Output filename +1002 format('000000_',i6.6) + open(10,file=fname(1:13)//'.wav',access='stream',status='unknown') + + wave=0.0 + iwave=0 + fac=sqrt(6000.0/2500.0) + do i=0,npts-1 + xx=gran() + wave(i)=pings(i)*waveform(i) + fac*xx + iwave(i)=30.0*wave(i) + enddo + + write(10) h,iwave(0:npts-1) !Save the .wav file + endfile(10) + close(10) + + enddo + +999 end program msk144sim diff --git a/lib/msk144spd.f90 b/lib/msk144spd.f90 index 69327125..2bc6dcfe 100755 --- a/lib/msk144spd.f90 +++ b/lib/msk144spd.f90 @@ -1,196 +1,196 @@ -subroutine msk144spd(cbig,n,ntol,nsuccess,msgreceived,fc,fret,tret,navg,ct, & - softbits) - -! MSK144 short-ping-decoder - - use packjt77 - use timer_module, only: timer - - parameter (NSPM=864, MAXSTEPS=100, NFFT=NSPM, MAXCAND=5, NPATTERNS=6) - character*37 msgreceived - complex cbig(n) - complex cdat(3*NSPM) !Analytic signal - complex c(NSPM) - complex ct(NSPM) - complex ctmp(NFFT) - integer, dimension(1) :: iloc - integer indices(MAXSTEPS) - integer npkloc(10) - integer navpatterns(3,NPATTERNS) - integer navmask(3) - integer nstart(MAXCAND) - logical ismask(NFFT) - real detmet(-2:MAXSTEPS+3) - real detmet2(-2:MAXSTEPS+3) - real detfer(MAXSTEPS) - real rcw(12) - real ferrs(MAXCAND) - real snrs(MAXCAND) - real softbits(144) - real tonespec(NFFT) - real tpat(NPATTERNS) - real*8 dt, df, fs, pi, twopi - logical first - data first/.true./ - data navpatterns/ & - 0,1,0, & - 1,0,0, & - 0,0,1, & - 1,1,0, & - 0,1,1, & - 1,1,1/ - data tpat/1.5,0.5,2.5,1.0,2.0,1.5/ - - save df,first,fs,pi,twopi,dt,tframe,rcw - - if(first) then - nmatchedfilter=1 -! define half-sine pulse and raised-cosine edge window - pi=4d0*datan(1d0) - twopi=8d0*datan(1d0) - fs=12000.0 - dt=1.0/fs - df=fs/NFFT - tframe=NSPM/fs - - do i=1,12 - angle=(i-1)*pi/12.0 - rcw(i)=(1-cos(angle))/2 - enddo - - first=.false. - endif - - ! fill the detmet, detferr arrays - nstep=(n-NSPM)/216 ! 72ms/4=18ms steps - detmet=0 - detmet2=0 - detfer=-999.99 - nfhi=2*(fc+500) - nflo=2*(fc-500) - ihlo=nint((nfhi-2*ntol)/df) + 1 - ihhi=nint((nfhi+2*ntol)/df) + 1 - illo=nint((nflo-2*ntol)/df) + 1 - ilhi=nint((nflo+2*ntol)/df) + 1 - i2000=nint(nflo/df) + 1 - i4000=nint(nfhi/df) + 1 - do istp=1,nstep - ns=1+216*(istp-1) - ne=ns+NSPM-1 - if( ne .gt. n ) exit - ctmp=cmplx(0.0,0.0) - ctmp(1:NSPM)=cbig(ns:ne) - -! Coarse carrier frequency sync - seek tones at 2000 Hz and 4000 Hz in -! squared signal spectrum. - - ctmp=ctmp**2 - ctmp(1:12)=ctmp(1:12)*rcw - ctmp(NSPM-11:NSPM)=ctmp(NSPM-11:NSPM)*rcw(12:1:-1) - call four2a(ctmp,NFFT,1,-1,1) - tonespec=abs(ctmp)**2 - - ismask=.false. - ismask(ihlo:ihhi)=.true. ! high tone search window - iloc=maxloc(tonespec,ismask) - ihpk=iloc(1) - deltah=-real( (ctmp(ihpk-1)-ctmp(ihpk+1)) / (2*ctmp(ihpk)-ctmp(ihpk-1)-ctmp(ihpk+1)) ) - ah=tonespec(ihpk) - ahavp=(sum(tonespec,ismask)-ah)/count(ismask) - trath=ah/(ahavp+0.01) - ismask=.false. - ismask(illo:ilhi)=.true. ! window for low tone - iloc=maxloc(tonespec,ismask) - ilpk=iloc(1) - deltal=-real( (ctmp(ilpk-1)-ctmp(ilpk+1)) / (2*ctmp(ilpk)-ctmp(ilpk-1)-ctmp(ilpk+1)) ) - al=tonespec(ilpk) - alavp=(sum(tonespec,ismask)-al)/count(ismask) - tratl=al/(alavp+0.01) - fdiff=(ihpk+deltah-ilpk-deltal)*df - ferrh=(ihpk+deltah-i4000)*df/2.0 - ferrl=(ilpk+deltal-i2000)*df/2.0 - if( ah .ge. al ) then - ferr=ferrh - else - ferr=ferrl - endif - detmet(istp)=max(ah,al) - detmet2(istp)=max(trath,tratl) - detfer(istp)=ferr - enddo ! end of detection-metric and frequency error estimation loop - - call indexx(detmet(1:nstep),nstep,indices) !find median of detection metric vector - xmed=detmet(indices(nstep/4)) - detmet=detmet/xmed ! noise floor of detection metric is 1.0 - ndet=0 - - do ip=1,MAXCAND ! Find candidates - iloc=maxloc(detmet(1:nstep)) - il=iloc(1) - if( (detmet(il) .lt. 3.0) ) exit - if( abs(detfer(il)) .le. ntol ) then - ndet=ndet+1 - nstart(ndet)=1+(il-1)*216+1 - ferrs(ndet)=detfer(il) - snrs(ndet)=12.0*log10(detmet(il))/2-9.0 - endif - detmet(il)=0.0 - enddo - - if( ndet .lt. 3 ) then - do ip=1,MAXCAND-ndet ! Find candidates - iloc=maxloc(detmet2(1:nstep)) - il=iloc(1) - if( (detmet2(il) .lt. 12.0) ) exit - if( abs(detfer(il)) .le. ntol ) then - ndet=ndet+1 - nstart(ndet)=1+(il-1)*216+1 - ferrs(ndet)=detfer(il) - snrs(ndet)=12.0*log10(detmet2(il))/2-9.0 - endif - detmet2(il)=0.0 - enddo - endif - - nsuccess=0 - msgreceived=' ' - npeaks=2 - ntol0=8 - deltaf=2.0 - do icand=1,ndet ! Try to sync/demod/decode each candidate. - ib=max(1,nstart(icand)-NSPM) - ie=ib-1+3*NSPM - if( ie .gt. n ) then - ie=n - ib=ie-3*NSPM+1 - endif - cdat=cbig(ib:ie) - fo=fc+ferrs(icand) - do iav=1,NPATTERNS - navmask=navpatterns(1:3,iav) - call msk144sync(cdat,3,ntol0,deltaf,navmask,npeaks,fo,fest,npkloc, & - nsyncsuccess,xmax,c) - - if( nsyncsuccess .eq. 0 ) cycle - - do ipk=1,npeaks - do is=1,3 - ic0=npkloc(ipk) - if( is.eq.2) ic0=max(1,ic0-1) - if( is.eq.3) ic0=min(NSPM,ic0+1) - ct=cshift(c,ic0-1) - call msk144decodeframe(ct,softbits,msgreceived,ndecodesuccess) - if( ndecodesuccess .gt. 0 ) then - tret=(nstart(icand)+NSPM/2)/fs - fret=fest - navg=sum(navmask) - nsuccess=1 - return - endif - enddo - enddo - enddo - enddo ! candidate loop - - return -end subroutine msk144spd +subroutine msk144spd(cbig,n,ntol,nsuccess,msgreceived,fc,fret,tret,navg,ct, & + softbits) + +! MSK144 short-ping-decoder + + use packjt77 + use timer_module, only: timer + + parameter (NSPM=864, MAXSTEPS=100, NFFT=NSPM, MAXCAND=5, NPATTERNS=6) + character*37 msgreceived + complex cbig(n) + complex cdat(3*NSPM) !Analytic signal + complex c(NSPM) + complex ct(NSPM) + complex ctmp(NFFT) + integer, dimension(1) :: iloc + integer indices(MAXSTEPS) + integer npkloc(10) + integer navpatterns(3,NPATTERNS) + integer navmask(3) + integer nstart(MAXCAND) + logical ismask(NFFT) + real detmet(-2:MAXSTEPS+3) + real detmet2(-2:MAXSTEPS+3) + real detfer(MAXSTEPS) + real rcw(12) + real ferrs(MAXCAND) + real snrs(MAXCAND) + real softbits(144) + real tonespec(NFFT) + real tpat(NPATTERNS) + real*8 dt, df, fs, pi, twopi + logical first + data first/.true./ + data navpatterns/ & + 0,1,0, & + 1,0,0, & + 0,0,1, & + 1,1,0, & + 0,1,1, & + 1,1,1/ + data tpat/1.5,0.5,2.5,1.0,2.0,1.5/ + + save df,first,fs,pi,twopi,dt,tframe,rcw + + if(first) then + nmatchedfilter=1 +! define half-sine pulse and raised-cosine edge window + pi=4d0*datan(1d0) + twopi=8d0*datan(1d0) + fs=12000.0 + dt=1.0/fs + df=fs/NFFT + tframe=NSPM/fs + + do i=1,12 + angle=(i-1)*pi/12.0 + rcw(i)=(1-cos(angle))/2 + enddo + + first=.false. + endif + + ! fill the detmet, detferr arrays + nstep=(n-NSPM)/216 ! 72ms/4=18ms steps + detmet=0 + detmet2=0 + detfer=-999.99 + nfhi=2*(fc+500) + nflo=2*(fc-500) + ihlo=nint((nfhi-2*ntol)/df) + 1 + ihhi=nint((nfhi+2*ntol)/df) + 1 + illo=nint((nflo-2*ntol)/df) + 1 + ilhi=nint((nflo+2*ntol)/df) + 1 + i2000=nint(nflo/df) + 1 + i4000=nint(nfhi/df) + 1 + do istp=1,nstep + ns=1+216*(istp-1) + ne=ns+NSPM-1 + if( ne .gt. n ) exit + ctmp=cmplx(0.0,0.0) + ctmp(1:NSPM)=cbig(ns:ne) + +! Coarse carrier frequency sync - seek tones at 2000 Hz and 4000 Hz in +! squared signal spectrum. + + ctmp=ctmp**2 + ctmp(1:12)=ctmp(1:12)*rcw + ctmp(NSPM-11:NSPM)=ctmp(NSPM-11:NSPM)*rcw(12:1:-1) + call four2a(ctmp,NFFT,1,-1,1) + tonespec=abs(ctmp)**2 + + ismask=.false. + ismask(ihlo:ihhi)=.true. ! high tone search window + iloc=maxloc(tonespec,ismask) + ihpk=iloc(1) + deltah=-real( (ctmp(ihpk-1)-ctmp(ihpk+1)) / (2*ctmp(ihpk)-ctmp(ihpk-1)-ctmp(ihpk+1)) ) + ah=tonespec(ihpk) + ahavp=(sum(tonespec,ismask)-ah)/count(ismask) + trath=ah/(ahavp+0.01) + ismask=.false. + ismask(illo:ilhi)=.true. ! window for low tone + iloc=maxloc(tonespec,ismask) + ilpk=iloc(1) + deltal=-real( (ctmp(ilpk-1)-ctmp(ilpk+1)) / (2*ctmp(ilpk)-ctmp(ilpk-1)-ctmp(ilpk+1)) ) + al=tonespec(ilpk) + alavp=(sum(tonespec,ismask)-al)/count(ismask) + tratl=al/(alavp+0.01) + fdiff=(ihpk+deltah-ilpk-deltal)*df + ferrh=(ihpk+deltah-i4000)*df/2.0 + ferrl=(ilpk+deltal-i2000)*df/2.0 + if( ah .ge. al ) then + ferr=ferrh + else + ferr=ferrl + endif + detmet(istp)=max(ah,al) + detmet2(istp)=max(trath,tratl) + detfer(istp)=ferr + enddo ! end of detection-metric and frequency error estimation loop + + call indexx(detmet(1:nstep),nstep,indices) !find median of detection metric vector + xmed=detmet(indices(nstep/4)) + detmet=detmet/xmed ! noise floor of detection metric is 1.0 + ndet=0 + + do ip=1,MAXCAND ! Find candidates + iloc=maxloc(detmet(1:nstep)) + il=iloc(1) + if( (detmet(il) .lt. 3.0) ) exit + if( abs(detfer(il)) .le. ntol ) then + ndet=ndet+1 + nstart(ndet)=1+(il-1)*216+1 + ferrs(ndet)=detfer(il) + snrs(ndet)=12.0*log10(detmet(il))/2-9.0 + endif + detmet(il)=0.0 + enddo + + if( ndet .lt. 3 ) then + do ip=1,MAXCAND-ndet ! Find candidates + iloc=maxloc(detmet2(1:nstep)) + il=iloc(1) + if( (detmet2(il) .lt. 12.0) ) exit + if( abs(detfer(il)) .le. ntol ) then + ndet=ndet+1 + nstart(ndet)=1+(il-1)*216+1 + ferrs(ndet)=detfer(il) + snrs(ndet)=12.0*log10(detmet2(il))/2-9.0 + endif + detmet2(il)=0.0 + enddo + endif + + nsuccess=0 + msgreceived=' ' + npeaks=2 + ntol0=8 + deltaf=2.0 + do icand=1,ndet ! Try to sync/demod/decode each candidate. + ib=max(1,nstart(icand)-NSPM) + ie=ib-1+3*NSPM + if( ie .gt. n ) then + ie=n + ib=ie-3*NSPM+1 + endif + cdat=cbig(ib:ie) + fo=fc+ferrs(icand) + do iav=1,NPATTERNS + navmask=navpatterns(1:3,iav) + call msk144sync(cdat,3,ntol0,deltaf,navmask,npeaks,fo,fest,npkloc, & + nsyncsuccess,xmax,c) + + if( nsyncsuccess .eq. 0 ) cycle + + do ipk=1,npeaks + do is=1,3 + ic0=npkloc(ipk) + if( is.eq.2) ic0=max(1,ic0-1) + if( is.eq.3) ic0=min(NSPM,ic0+1) + ct=cshift(c,ic0-1) + call msk144decodeframe(ct,softbits,msgreceived,ndecodesuccess) + if( ndecodesuccess .gt. 0 ) then + tret=(nstart(icand)+NSPM/2)/fs + fret=fest + navg=sum(navmask) + nsuccess=1 + return + endif + enddo + enddo + enddo + enddo ! candidate loop + + return +end subroutine msk144spd diff --git a/lib/msk144sync.f90 b/lib/msk144sync.f90 index 5d5bdac5..cfcd8c92 100755 --- a/lib/msk144sync.f90 +++ b/lib/msk144sync.f90 @@ -1,101 +1,101 @@ -subroutine msk144sync(cdat,nframes,ntol,delf,navmask,npeaks,fc,fest, & - npklocs,nsuccess,xmax,c) - -!$ use omp_lib - - parameter (NSPM=864) - complex cdat(NSPM*nframes) - complex cdat2(NSPM*nframes,8) - complex c(NSPM) !Coherently averaged complex data - complex cs(NSPM,8) - complex cb(42) !Complex waveform for sync word - - integer s8(8) - integer iloc(1) - integer npklocs(npeaks) - integer navmask(nframes) ! defines which frames to average - - real cbi(42),cbq(42) - real pkamps(npeaks) - real xcc(0:NSPM-1) - real xccs(0:NSPM-1,8) - real xm(8) - real bf(8) - real pp(12) !Half-sine pulse shape - logical first - data first/.true./ - data s8/0,1,1,1,0,0,1,0/ - save first,cb,fs,pi,twopi,dt,s8,pp - - if(first) then - pi=4.0*atan(1.0) - twopi=8.0*atan(1.0) - fs=12000.0 - dt=1.0/fs - - do i=1,12 !Define half-sine pulse - angle=(i-1)*pi/12.0 - pp(i)=sin(angle) - enddo - -! Define the sync word waveforms - s8=2*s8-1 - cbq(1:6)=pp(7:12)*s8(1) - cbq(7:18)=pp*s8(3) - cbq(19:30)=pp*s8(5) - cbq(31:42)=pp*s8(7) - cbi(1:12)=pp*s8(2) - cbi(13:24)=pp*s8(4) - cbi(25:36)=pp*s8(6) - cbi(37:42)=pp(1:6)*s8(8) - cb=cmplx(cbi,cbq) - - first=.false. - endif - - nfreqs=2*nint(ntol/delf) + 1 - xm=0.0 - bf=0.0 - nthreads=1 -!$ nthreads=min(4,int(OMP_GET_MAX_THREADS(),4)) - nstep=nfreqs/nthreads - -!$OMP PARALLEL NUM_THREADS(nthreads) PRIVATE(id,if1,if2) - id=1 -!$ id=OMP_GET_THREAD_NUM() + 1 !Thread id = 1,2,... - if1=-nint(ntol/delf) + (id-1)*nstep - if2=if1+nstep-1 - if(id.eq.nthreads) if2=nint(ntol/delf) - call msk144_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & - cdat2(1,id),xm(id),bf(id),cs(1,id),xccs(1,id)) -!$OMP END PARALLEL - - xmax=xm(1) - fest=fc+bf(1) - c=cs(1:NSPM,1) - xcc=xccs(0:NSPM-1,1) - if(nthreads.gt.1) then - do i=2,nthreads - if(xm(i).gt.xmax) then - xmax=xm(i) - fest=fc+bf(i) - c=cs(1:NSPM,i) - xcc=xccs(0:NSPM-1,i) - endif - enddo - endif - -! Find npeaks largest peaks - do ipk=1,npeaks - iloc=maxloc(xcc) - ic2=iloc(1) - npklocs(ipk)=ic2 - pkamps(ipk)=xcc(ic2-1) - xcc(max(0,ic2-7):min(NSPM-1,ic2+7))=0.0 - enddo - - nsuccess=0 - if(xmax.ge.1.3) nsuccess=1 - - return -end subroutine msk144sync +subroutine msk144sync(cdat,nframes,ntol,delf,navmask,npeaks,fc,fest, & + npklocs,nsuccess,xmax,c) + +!$ use omp_lib + + parameter (NSPM=864) + complex cdat(NSPM*nframes) + complex cdat2(NSPM*nframes,8) + complex c(NSPM) !Coherently averaged complex data + complex cs(NSPM,8) + complex cb(42) !Complex waveform for sync word + + integer s8(8) + integer iloc(1) + integer npklocs(npeaks) + integer navmask(nframes) ! defines which frames to average + + real cbi(42),cbq(42) + real pkamps(npeaks) + real xcc(0:NSPM-1) + real xccs(0:NSPM-1,8) + real xm(8) + real bf(8) + real pp(12) !Half-sine pulse shape + logical first + data first/.true./ + data s8/0,1,1,1,0,0,1,0/ + save first,cb,fs,pi,twopi,dt,s8,pp + + if(first) then + pi=4.0*atan(1.0) + twopi=8.0*atan(1.0) + fs=12000.0 + dt=1.0/fs + + do i=1,12 !Define half-sine pulse + angle=(i-1)*pi/12.0 + pp(i)=sin(angle) + enddo + +! Define the sync word waveforms + s8=2*s8-1 + cbq(1:6)=pp(7:12)*s8(1) + cbq(7:18)=pp*s8(3) + cbq(19:30)=pp*s8(5) + cbq(31:42)=pp*s8(7) + cbi(1:12)=pp*s8(2) + cbi(13:24)=pp*s8(4) + cbi(25:36)=pp*s8(6) + cbi(37:42)=pp(1:6)*s8(8) + cb=cmplx(cbi,cbq) + + first=.false. + endif + + nfreqs=2*nint(ntol/delf) + 1 + xm=0.0 + bf=0.0 + nthreads=1 +!$ nthreads=min(4,int(OMP_GET_MAX_THREADS(),4)) + nstep=nfreqs/nthreads + +!$OMP PARALLEL NUM_THREADS(nthreads) PRIVATE(id,if1,if2) + id=1 +!$ id=OMP_GET_THREAD_NUM() + 1 !Thread id = 1,2,... + if1=-nint(ntol/delf) + (id-1)*nstep + if2=if1+nstep-1 + if(id.eq.nthreads) if2=nint(ntol/delf) + call msk144_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & + cdat2(1,id),xm(id),bf(id),cs(1,id),xccs(1,id)) +!$OMP END PARALLEL + + xmax=xm(1) + fest=fc+bf(1) + c=cs(1:NSPM,1) + xcc=xccs(0:NSPM-1,1) + if(nthreads.gt.1) then + do i=2,nthreads + if(xm(i).gt.xmax) then + xmax=xm(i) + fest=fc+bf(i) + c=cs(1:NSPM,i) + xcc=xccs(0:NSPM-1,i) + endif + enddo + endif + +! Find npeaks largest peaks + do ipk=1,npeaks + iloc=maxloc(xcc) + ic2=iloc(1) + npklocs(ipk)=ic2 + pkamps(ipk)=xcc(ic2-1) + xcc(max(0,ic2-7):min(NSPM-1,ic2+7))=0.0 + enddo + + nsuccess=0 + if(xmax.ge.1.3) nsuccess=1 + + return +end subroutine msk144sync diff --git a/lib/msk40_freq_search.f90 b/lib/msk40_freq_search.f90 index ff6bef2b..97f74f5e 100755 --- a/lib/msk40_freq_search.f90 +++ b/lib/msk40_freq_search.f90 @@ -1,53 +1,53 @@ -subroutine msk40_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & - cdat2,xmax,bestf,cs,xccs) - - parameter (NSPM=240,NZ=7*NSPM) - complex cdat(NZ) - complex cdat2(NZ) - complex c(NSPM) !Coherently averaged complex data - complex ct2(2*NSPM) - complex cs(NSPM) - complex cb(42) !Complex waveform for sync word - complex cc(0:NSPM-1) - real xcc(0:NSPM-1) - real xccs(0:NSPM-1) - integer navmask(nframes) !Tells which frames to average - - navg=sum(navmask) - n=nframes*NSPM -! fac=1.0/(48.0*sqrt(float(navg))) - fac=1.0/(24.0*sqrt(float(navg))) - - do ifr=if1,if2 !Find freq that maximizes sync - ferr=ifr*delf - call tweak1(cdat,n,-(fc+ferr),cdat2) - c=0 - do i=1,nframes - ib=(i-1)*NSPM+1 - ie=ib+NSPM-1 - if( navmask(i) .eq. 1 ) c=c+cdat2(ib:ie) - enddo - - cc=0 - ct2(1:NSPM)=c - ct2(NSPM+1:2*NSPM)=c - - do ish=0,NSPM-1 - cc(ish)=dot_product(ct2(1+ish:42+ish),cb(1:42)) - enddo - - xcc=abs(cc) - xb=maxval(xcc)*fac - if(xb.gt.xmax) then - xmax=xb - bestf=ferr - cs=c - xccs=xcc - endif - enddo - -! write(71,3001) fc,delf,if1,if2,nframes,bestf,xmax -!3001 format(2f8.3,3i5,2f8.3) - - return -end subroutine msk40_freq_search +subroutine msk40_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & + cdat2,xmax,bestf,cs,xccs) + + parameter (NSPM=240,NZ=7*NSPM) + complex cdat(NZ) + complex cdat2(NZ) + complex c(NSPM) !Coherently averaged complex data + complex ct2(2*NSPM) + complex cs(NSPM) + complex cb(42) !Complex waveform for sync word + complex cc(0:NSPM-1) + real xcc(0:NSPM-1) + real xccs(0:NSPM-1) + integer navmask(nframes) !Tells which frames to average + + navg=sum(navmask) + n=nframes*NSPM +! fac=1.0/(48.0*sqrt(float(navg))) + fac=1.0/(24.0*sqrt(float(navg))) + + do ifr=if1,if2 !Find freq that maximizes sync + ferr=ifr*delf + call tweak1(cdat,n,-(fc+ferr),cdat2) + c=0 + do i=1,nframes + ib=(i-1)*NSPM+1 + ie=ib+NSPM-1 + if( navmask(i) .eq. 1 ) c=c+cdat2(ib:ie) + enddo + + cc=0 + ct2(1:NSPM)=c + ct2(NSPM+1:2*NSPM)=c + + do ish=0,NSPM-1 + cc(ish)=dot_product(ct2(1+ish:42+ish),cb(1:42)) + enddo + + xcc=abs(cc) + xb=maxval(xcc)*fac + if(xb.gt.xmax) then + xmax=xb + bestf=ferr + cs=c + xccs=xcc + endif + enddo + +! write(71,3001) fc,delf,if1,if2,nframes,bestf,xmax +!3001 format(2f8.3,3i5,2f8.3) + + return +end subroutine msk40_freq_search diff --git a/lib/msk40decodeframe.f90 b/lib/msk40decodeframe.f90 index f763cbaa..277f89de 100755 --- a/lib/msk40decodeframe.f90 +++ b/lib/msk40decodeframe.f90 @@ -1,163 +1,163 @@ -subroutine msk40decodeframe(c,mycall,hiscall,xsnr,bswl,nhasharray, & - msgreceived,nsuccess) -! use timer_module, only: timer - use packjt77 - - parameter (NSPM=240) - character*4 rpt(0:15) - character*12 mycall,hiscall,mycall0,hiscall0 - character*37 hashmsg,msgreceived - complex cb(42) - complex cfac,cca - complex c(NSPM) - integer*1 cw(32) - integer*1 decoded(16) - integer s8r(8),hardbits(40) - integer nhasharray(MAXRECENT,MAXRECENT) - real*8 dt, fs, pi, twopi - real cbi(42),cbq(42) - real pp(12) - real softbits(40) - real llr(32) - logical first - logical*1 bswl - data first/.true./ - data s8r/1,0,1,1,0,0,0,1/ - data mycall0/'dummy'/,hiscall0/'dummy'/ - data rpt/"-03 ","+00 ","+03 ","+06 ","+10 ","+13 ","+16 ", & - "R-03","R+00","R+03","R+06","R+10","R+13","R+16", & - "RRR ","73 "/ - save first,cb,fs,pi,twopi,dt,s8r,pp,rpt,mycall0,hiscall0,ihash - - if(first) then -! define half-sine pulse and raised-cosine edge window - pi=4d0*datan(1d0) - twopi=8d0*datan(1d0) - fs=12000.0 - dt=1.0/fs - - do i=1,12 - angle=(i-1)*pi/12.0 - pp(i)=sin(angle) - enddo - -! define the sync word waveforms - s8r=2*s8r-1 - cbq(1:6)=pp(7:12)*s8r(1) - cbq(7:18)=pp*s8r(3) - cbq(19:30)=pp*s8r(5) - cbq(31:42)=pp*s8r(7) - cbi(1:12)=pp*s8r(2) - cbi(13:24)=pp*s8r(4) - cbi(25:36)=pp*s8r(6) - cbi(37:42)=pp(1:6)*s8r(8) - cb=cmplx(cbi,cbq) - first=.false. - endif - - if(mycall.ne.mycall0 .or. hiscall.ne.hiscall0) then - hashmsg=trim(mycall)//' '//trim(hiscall) - if( hashmsg .ne. ' ' .and. hiscall .ne. '' ) then ! protect against blank mycall/hiscall - call fmtmsg(hashmsg,iz) - call hash(hashmsg,37,ihash) - ihash=iand(ihash,4095) - else - ihash=9999 ! so that it can never match a received hash - endif - mycall0=mycall - hiscall0=hiscall - endif - - nsuccess=0 - msgreceived=' ' - -! Estimate carrier phase. - cca=sum(c(1:1+41)*conjg(cb)) - phase0=atan2(imag(cca),real(cca)) - -! Remove phase error - want constellation rotated so that sample points lie on I/Q axes - cfac=cmplx(cos(phase0),sin(phase0)) - c=c*conjg(cfac) - -! Matched filter. - softbits(1)=sum(imag(c(1:6))*pp(7:12))+sum(imag(c(NSPM-5:NSPM))*pp(1:6)) - softbits(2)=sum(real(c(1:12))*pp) - do i=2,20 - softbits(2*i-1)=sum(imag(c(1+(i-1)*12-6:1+(i-1)*12+5))*pp) - softbits(2*i)=sum(real(c(7+(i-1)*12-6:7+(i-1)*12+5))*pp) - enddo - -! Sync word hard error weight is used to reject frames that -! are unlikely to decode. - hardbits=0 - do i=1,40 - if( softbits(i) .ge. 0.0 ) then - hardbits(i)=1 - endif - enddo - nbadsync1=(8-sum( (2*hardbits(1:8)-1)*s8r ) )/2 - nbadsync=nbadsync1 - if( nbadsync .gt. 3 ) then - return - endif - -! Normalize the softsymbols before submitting to decoder. - sav=sum(softbits)/40 - s2av=sum(softbits*softbits)/40 - ssig=sqrt(s2av-sav*sav) - softbits=softbits/ssig - - sigma=0.75 -! if(xsnr.lt.0.0) sigma=0.75-0.0875*xsnr - if(xsnr.lt.0.0) sigma=0.75-0.11*xsnr - llr(1:32)=softbits(9:40) - llr=2.0*llr/(sigma*sigma) - - max_iterations=5 - call bpdecode40(llr,max_iterations,decoded,niterations) - if( niterations .ge. 0.0 ) then - call encode_msk40(decoded,cw) - nhammd=0 - cord=0.0 - do i=1,32 - if( cw(i) .ne. hardbits(i+8) ) then - nhammd=nhammd+1 - cord=cord+abs(softbits(i+8)) - endif - enddo - - imsg=0 - do i=1,16 - imsg=ishft(imsg,1)+iand(1_1,decoded(17-i)) - enddo - nrxrpt=iand(imsg,15) - nrxhash=(imsg-nrxrpt)/16 - if(nhammd.le.4 .and. cord .lt. 0.65 .and. & - nrxhash.eq.ihash .and. nrxrpt.ge.7) then - nsuccess=1 - write(msgreceived,'(a1,a,1x,a,a1,1x,a4)') "<",trim(mycall), & - trim(hiscall),">",rpt(nrxrpt) - return - elseif(bswl .and. nhammd.le.4 .and. cord.lt.0.65 .and. nrxrpt.ge.7 ) then - do i=1,MAXRECENT - do j=i+1,MAXRECENT - if( nrxhash .eq. nhasharray(i,j) ) then - nsuccess=2 - write(msgreceived,'(a1,a,1x,a,a1,1x,a4)') "<",trim(recent_calls(i)), & - trim(recent_calls(j)),">",rpt(nrxrpt) - elseif( nrxhash .eq. nhasharray(j,i) ) then - nsuccess=2 - write(msgreceived,'(a1,a,1x,a,a1,1x,a4)') "<",trim(recent_calls(j)), & - trim(recent_calls(i)),">",rpt(nrxrpt) - endif - enddo - enddo - if(nsuccess.eq.0) then - nsuccess=3 - write(msgreceived,'(a1,i4.4,a1,1x,a4)') "<",nrxhash,">",rpt(nrxrpt) - endif - endif - endif - - return -end subroutine msk40decodeframe +subroutine msk40decodeframe(c,mycall,hiscall,xsnr,bswl,nhasharray, & + msgreceived,nsuccess) +! use timer_module, only: timer + use packjt77 + + parameter (NSPM=240) + character*4 rpt(0:15) + character*12 mycall,hiscall,mycall0,hiscall0 + character*37 hashmsg,msgreceived + complex cb(42) + complex cfac,cca + complex c(NSPM) + integer*1 cw(32) + integer*1 decoded(16) + integer s8r(8),hardbits(40) + integer nhasharray(MAXRECENT,MAXRECENT) + real*8 dt, fs, pi, twopi + real cbi(42),cbq(42) + real pp(12) + real softbits(40) + real llr(32) + logical first + logical*1 bswl + data first/.true./ + data s8r/1,0,1,1,0,0,0,1/ + data mycall0/'dummy'/,hiscall0/'dummy'/ + data rpt/"-03 ","+00 ","+03 ","+06 ","+10 ","+13 ","+16 ", & + "R-03","R+00","R+03","R+06","R+10","R+13","R+16", & + "RRR ","73 "/ + save first,cb,fs,pi,twopi,dt,s8r,pp,rpt,mycall0,hiscall0,ihash + + if(first) then +! define half-sine pulse and raised-cosine edge window + pi=4d0*datan(1d0) + twopi=8d0*datan(1d0) + fs=12000.0 + dt=1.0/fs + + do i=1,12 + angle=(i-1)*pi/12.0 + pp(i)=sin(angle) + enddo + +! define the sync word waveforms + s8r=2*s8r-1 + cbq(1:6)=pp(7:12)*s8r(1) + cbq(7:18)=pp*s8r(3) + cbq(19:30)=pp*s8r(5) + cbq(31:42)=pp*s8r(7) + cbi(1:12)=pp*s8r(2) + cbi(13:24)=pp*s8r(4) + cbi(25:36)=pp*s8r(6) + cbi(37:42)=pp(1:6)*s8r(8) + cb=cmplx(cbi,cbq) + first=.false. + endif + + if(mycall.ne.mycall0 .or. hiscall.ne.hiscall0) then + hashmsg=trim(mycall)//' '//trim(hiscall) + if( hashmsg .ne. ' ' .and. hiscall .ne. '' ) then ! protect against blank mycall/hiscall + call fmtmsg(hashmsg,iz) + call hash(hashmsg,37,ihash) + ihash=iand(ihash,4095) + else + ihash=9999 ! so that it can never match a received hash + endif + mycall0=mycall + hiscall0=hiscall + endif + + nsuccess=0 + msgreceived=' ' + +! Estimate carrier phase. + cca=sum(c(1:1+41)*conjg(cb)) + phase0=atan2(imag(cca),real(cca)) + +! Remove phase error - want constellation rotated so that sample points lie on I/Q axes + cfac=cmplx(cos(phase0),sin(phase0)) + c=c*conjg(cfac) + +! Matched filter. + softbits(1)=sum(imag(c(1:6))*pp(7:12))+sum(imag(c(NSPM-5:NSPM))*pp(1:6)) + softbits(2)=sum(real(c(1:12))*pp) + do i=2,20 + softbits(2*i-1)=sum(imag(c(1+(i-1)*12-6:1+(i-1)*12+5))*pp) + softbits(2*i)=sum(real(c(7+(i-1)*12-6:7+(i-1)*12+5))*pp) + enddo + +! Sync word hard error weight is used to reject frames that +! are unlikely to decode. + hardbits=0 + do i=1,40 + if( softbits(i) .ge. 0.0 ) then + hardbits(i)=1 + endif + enddo + nbadsync1=(8-sum( (2*hardbits(1:8)-1)*s8r ) )/2 + nbadsync=nbadsync1 + if( nbadsync .gt. 3 ) then + return + endif + +! Normalize the softsymbols before submitting to decoder. + sav=sum(softbits)/40 + s2av=sum(softbits*softbits)/40 + ssig=sqrt(s2av-sav*sav) + softbits=softbits/ssig + + sigma=0.75 +! if(xsnr.lt.0.0) sigma=0.75-0.0875*xsnr + if(xsnr.lt.0.0) sigma=0.75-0.11*xsnr + llr(1:32)=softbits(9:40) + llr=2.0*llr/(sigma*sigma) + + max_iterations=5 + call bpdecode40(llr,max_iterations,decoded,niterations) + if( niterations .ge. 0.0 ) then + call encode_msk40(decoded,cw) + nhammd=0 + cord=0.0 + do i=1,32 + if( cw(i) .ne. hardbits(i+8) ) then + nhammd=nhammd+1 + cord=cord+abs(softbits(i+8)) + endif + enddo + + imsg=0 + do i=1,16 + imsg=ishft(imsg,1)+iand(1_1,decoded(17-i)) + enddo + nrxrpt=iand(imsg,15) + nrxhash=(imsg-nrxrpt)/16 + if(nhammd.le.4 .and. cord .lt. 0.65 .and. & + nrxhash.eq.ihash .and. nrxrpt.ge.7) then + nsuccess=1 + write(msgreceived,'(a1,a,1x,a,a1,1x,a4)') "<",trim(mycall), & + trim(hiscall),">",rpt(nrxrpt) + return + elseif(bswl .and. nhammd.le.4 .and. cord.lt.0.65 .and. nrxrpt.ge.7 ) then + do i=1,MAXRECENT + do j=i+1,MAXRECENT + if( nrxhash .eq. nhasharray(i,j) ) then + nsuccess=2 + write(msgreceived,'(a1,a,1x,a,a1,1x,a4)') "<",trim(recent_calls(i)), & + trim(recent_calls(j)),">",rpt(nrxrpt) + elseif( nrxhash .eq. nhasharray(j,i) ) then + nsuccess=2 + write(msgreceived,'(a1,a,1x,a,a1,1x,a4)') "<",trim(recent_calls(j)), & + trim(recent_calls(i)),">",rpt(nrxrpt) + endif + enddo + enddo + if(nsuccess.eq.0) then + nsuccess=3 + write(msgreceived,'(a1,i4.4,a1,1x,a4)') "<",nrxhash,">",rpt(nrxrpt) + endif + endif + endif + + return +end subroutine msk40decodeframe diff --git a/lib/msk40spd.f90 b/lib/msk40spd.f90 index f10f6cb8..63532ae9 100755 --- a/lib/msk40spd.f90 +++ b/lib/msk40spd.f90 @@ -1,198 +1,198 @@ -subroutine msk40spd(cbig,n,ntol,mycall,hiscall,bswl,nhasharray, & - nsuccess,msgreceived,fc,fret,tret,navg) -! msk40 short-ping-decoder - - use packjt77 - use timer_module, only: timer - - parameter (NSPM=240, MAXSTEPS=150, NFFT=NSPM, MAXCAND=5, NPATTERNS=6) - character*12 mycall,hiscall - character*37 msgreceived - complex cbig(n) - complex cdat(3*NSPM) !Analytic signal - complex c(NSPM) - complex ct(NSPM) - complex ctmp(NFFT) - integer, dimension(1) :: iloc - integer indices(MAXSTEPS) - integer npkloc(10) - integer navpatterns(3,NPATTERNS) - integer navmask(3) - integer nstart(MAXCAND) - logical ismask(NFFT) - logical*1 bswl - real detmet(-2:MAXSTEPS+3) - real detmet2(-2:MAXSTEPS+3) - real detfer(MAXSTEPS) - real rcw(12) - real ferrs(MAXCAND) - real snrs(MAXCAND) - real tonespec(NFFT) - real tpat(NPATTERNS) - real*8 dt, df, fs, pi, twopi - logical first - data first/.true./ - data navpatterns/ & - 0,1,0, & - 1,0,0, & - 0,0,1, & - 1,1,0, & - 0,1,1, & - 1,1,1/ - data tpat/1.5,0.5,2.5,1.0,2.0,1.5/ - save df,first,fs,pi,twopi,dt,tframe,rcw - - if(first) then - nmatchedfilter=1 -! define half-sine pulse and raised-cosine edge window - pi=4d0*datan(1d0) - twopi=8d0*datan(1d0) - fs=12000.0 - dt=1.0/fs - df=fs/NFFT - tframe=NSPM/fs - - do i=1,12 - angle=(i-1)*pi/12.0 - rcw(i)=(1-cos(angle))/2 - enddo - - first=.false. - endif - - - ! fill the detmet, detferr arrays - nstep=(n-NSPM)/60 ! 20ms/4=5ms steps - detmet=0 - detmet2=0 - detfer=-999.99 - nfhi=2*(fc+500) - nflo=2*(fc-500) - ihlo=nint((nfhi-2*ntol)/df)+1 - ihhi=nint((nfhi+2*ntol)/df)+1 - illo=nint((nflo-2*ntol)/df)+1 - ilhi=nint((nflo+2*ntol)/df)+1 - i2000=nint(nflo/df)+1 - i4000=nint(nfhi/df)+1 - do istp=1,nstep - ns=1+60*(istp-1) - ne=ns+NSPM-1 - if( ne .gt. n ) exit - ctmp=cmplx(0.0,0.0) - ctmp(1:NSPM)=cbig(ns:ne) - -! Coarse carrier frequency sync - seek tones at 2000 Hz and 4000 Hz in -! squared signal spectrum. - - ctmp=ctmp**2 - ctmp(1:12)=ctmp(1:12)*rcw - ctmp(NSPM-11:NSPM)=ctmp(NSPM-11:NSPM)*rcw(12:1:-1) - call four2a(ctmp,NFFT,1,-1,1) - tonespec=abs(ctmp)**2 - - ismask=.false. - ismask(ihlo:ihhi)=.true. ! high tone search window - iloc=maxloc(tonespec,ismask) - ihpk=iloc(1) - deltah=-real( (ctmp(ihpk-1)-ctmp(ihpk+1)) / (2*ctmp(ihpk)-ctmp(ihpk-1)-ctmp(ihpk+1)) ) - ah=tonespec(ihpk) - ahavp=(sum(tonespec,ismask)-ah)/count(ismask) - trath=ah/(ahavp+0.01) - ismask=.false. - ismask(illo:ilhi)=.true. ! window for low tone - iloc=maxloc(tonespec,ismask) - ilpk=iloc(1) - deltal=-real( (ctmp(ilpk-1)-ctmp(ilpk+1)) / (2*ctmp(ilpk)-ctmp(ilpk-1)-ctmp(ilpk+1)) ) - al=tonespec(ilpk) - alavp=(sum(tonespec,ismask)-al)/count(ismask) - tratl=al/(alavp+0.01) - fdiff=(ihpk+deltah-ilpk-deltal)*df - ferrh=(ihpk+deltah-i4000)*df/2.0 - ferrl=(ilpk+deltal-i2000)*df/2.0 - if( ah .ge. al ) then - ferr=ferrh - else - ferr=ferrl - endif - detmet(istp)=max(ah,al) - detmet2(istp)=max(trath,tratl) - detfer(istp)=ferr - enddo ! end of detection-metric and frequency error estimation loop - - call indexx(detmet(1:nstep),nstep,indices) !find median of detection metric vector - xmed=detmet(indices(nstep/4)) - detmet=detmet/xmed ! noise floor of detection metric is 1.0 - ndet=0 - - do ip=1,MAXCAND ! Find candidates - iloc=maxloc(detmet(1:nstep)) - il=iloc(1) - if( (detmet(il) .lt. 3.5) ) exit - if( abs(detfer(il)) .le. ntol ) then - ndet=ndet+1 - nstart(ndet)=1+(il-1)*60+1 - ferrs(ndet)=detfer(il) - snrs(ndet)=12.0*log10(detmet(il))/2-9.0 - endif - detmet(il)=0.0 - enddo - - if( ndet .lt. 3 ) then - do ip=1,MAXCAND-ndet ! Find candidates - iloc=maxloc(detmet2(1:nstep)) - il=iloc(1) - if( (detmet2(il) .lt. 12.0) ) exit - if( abs(detfer(il)) .le. ntol ) then - ndet=ndet+1 - nstart(ndet)=1+(il-1)*60+1 - ferrs(ndet)=detfer(il) - snrs(ndet)=12.0*log10(detmet2(il))/2-9.0 - endif - detmet2(il)=0.0 - enddo - endif - - nsuccess=0 - msgreceived=' ' - npeaks=2 - ntol0=29 - deltaf=7.2 - do icand=1,ndet ! Try to sync/demod/decode each candidate. - ib=max(1,nstart(icand)-NSPM) - ie=ib-1+3*NSPM - if( ie .gt. n ) then - ie=n - ib=ie-3*NSPM+1 - endif - cdat=cbig(ib:ie) - fo=fc+ferrs(icand) - xsnr=snrs(icand) - do iav=1,NPATTERNS - navmask=navpatterns(1:3,iav) - call msk40sync(cdat,3,ntol0,deltaf,navmask,npeaks,fo,fest,npkloc, & - nsyncsuccess,c) - if( nsyncsuccess .eq. 0 ) cycle - - do ipk=1,npeaks - do is=1,3 - ic0=npkloc(ipk) - if( is.eq.2) ic0=max(1,ic0-1) - if( is.eq.3) ic0=min(NSPM,ic0+1) - ct=cshift(c,ic0-1) - call msk40decodeframe(ct,mycall,hiscall,xsnr,bswl,nhasharray, & - msgreceived,ndecodesuccess) - if( ndecodesuccess .gt. 0 ) then -!write(*,*) icand, iav, ipk, is, tret, fret, msgreceived - tret=(nstart(icand)+NSPM/2)/fs - fret=fest - navg=sum(navmask) - nsuccess=ndecodesuccess - return - endif - enddo - enddo - enddo - enddo ! candidate loop - - return -end subroutine msk40spd +subroutine msk40spd(cbig,n,ntol,mycall,hiscall,bswl,nhasharray, & + nsuccess,msgreceived,fc,fret,tret,navg) +! msk40 short-ping-decoder + + use packjt77 + use timer_module, only: timer + + parameter (NSPM=240, MAXSTEPS=150, NFFT=NSPM, MAXCAND=5, NPATTERNS=6) + character*12 mycall,hiscall + character*37 msgreceived + complex cbig(n) + complex cdat(3*NSPM) !Analytic signal + complex c(NSPM) + complex ct(NSPM) + complex ctmp(NFFT) + integer, dimension(1) :: iloc + integer indices(MAXSTEPS) + integer npkloc(10) + integer navpatterns(3,NPATTERNS) + integer navmask(3) + integer nstart(MAXCAND) + logical ismask(NFFT) + logical*1 bswl + real detmet(-2:MAXSTEPS+3) + real detmet2(-2:MAXSTEPS+3) + real detfer(MAXSTEPS) + real rcw(12) + real ferrs(MAXCAND) + real snrs(MAXCAND) + real tonespec(NFFT) + real tpat(NPATTERNS) + real*8 dt, df, fs, pi, twopi + logical first + data first/.true./ + data navpatterns/ & + 0,1,0, & + 1,0,0, & + 0,0,1, & + 1,1,0, & + 0,1,1, & + 1,1,1/ + data tpat/1.5,0.5,2.5,1.0,2.0,1.5/ + save df,first,fs,pi,twopi,dt,tframe,rcw + + if(first) then + nmatchedfilter=1 +! define half-sine pulse and raised-cosine edge window + pi=4d0*datan(1d0) + twopi=8d0*datan(1d0) + fs=12000.0 + dt=1.0/fs + df=fs/NFFT + tframe=NSPM/fs + + do i=1,12 + angle=(i-1)*pi/12.0 + rcw(i)=(1-cos(angle))/2 + enddo + + first=.false. + endif + + + ! fill the detmet, detferr arrays + nstep=(n-NSPM)/60 ! 20ms/4=5ms steps + detmet=0 + detmet2=0 + detfer=-999.99 + nfhi=2*(fc+500) + nflo=2*(fc-500) + ihlo=nint((nfhi-2*ntol)/df)+1 + ihhi=nint((nfhi+2*ntol)/df)+1 + illo=nint((nflo-2*ntol)/df)+1 + ilhi=nint((nflo+2*ntol)/df)+1 + i2000=nint(nflo/df)+1 + i4000=nint(nfhi/df)+1 + do istp=1,nstep + ns=1+60*(istp-1) + ne=ns+NSPM-1 + if( ne .gt. n ) exit + ctmp=cmplx(0.0,0.0) + ctmp(1:NSPM)=cbig(ns:ne) + +! Coarse carrier frequency sync - seek tones at 2000 Hz and 4000 Hz in +! squared signal spectrum. + + ctmp=ctmp**2 + ctmp(1:12)=ctmp(1:12)*rcw + ctmp(NSPM-11:NSPM)=ctmp(NSPM-11:NSPM)*rcw(12:1:-1) + call four2a(ctmp,NFFT,1,-1,1) + tonespec=abs(ctmp)**2 + + ismask=.false. + ismask(ihlo:ihhi)=.true. ! high tone search window + iloc=maxloc(tonespec,ismask) + ihpk=iloc(1) + deltah=-real( (ctmp(ihpk-1)-ctmp(ihpk+1)) / (2*ctmp(ihpk)-ctmp(ihpk-1)-ctmp(ihpk+1)) ) + ah=tonespec(ihpk) + ahavp=(sum(tonespec,ismask)-ah)/count(ismask) + trath=ah/(ahavp+0.01) + ismask=.false. + ismask(illo:ilhi)=.true. ! window for low tone + iloc=maxloc(tonespec,ismask) + ilpk=iloc(1) + deltal=-real( (ctmp(ilpk-1)-ctmp(ilpk+1)) / (2*ctmp(ilpk)-ctmp(ilpk-1)-ctmp(ilpk+1)) ) + al=tonespec(ilpk) + alavp=(sum(tonespec,ismask)-al)/count(ismask) + tratl=al/(alavp+0.01) + fdiff=(ihpk+deltah-ilpk-deltal)*df + ferrh=(ihpk+deltah-i4000)*df/2.0 + ferrl=(ilpk+deltal-i2000)*df/2.0 + if( ah .ge. al ) then + ferr=ferrh + else + ferr=ferrl + endif + detmet(istp)=max(ah,al) + detmet2(istp)=max(trath,tratl) + detfer(istp)=ferr + enddo ! end of detection-metric and frequency error estimation loop + + call indexx(detmet(1:nstep),nstep,indices) !find median of detection metric vector + xmed=detmet(indices(nstep/4)) + detmet=detmet/xmed ! noise floor of detection metric is 1.0 + ndet=0 + + do ip=1,MAXCAND ! Find candidates + iloc=maxloc(detmet(1:nstep)) + il=iloc(1) + if( (detmet(il) .lt. 3.5) ) exit + if( abs(detfer(il)) .le. ntol ) then + ndet=ndet+1 + nstart(ndet)=1+(il-1)*60+1 + ferrs(ndet)=detfer(il) + snrs(ndet)=12.0*log10(detmet(il))/2-9.0 + endif + detmet(il)=0.0 + enddo + + if( ndet .lt. 3 ) then + do ip=1,MAXCAND-ndet ! Find candidates + iloc=maxloc(detmet2(1:nstep)) + il=iloc(1) + if( (detmet2(il) .lt. 12.0) ) exit + if( abs(detfer(il)) .le. ntol ) then + ndet=ndet+1 + nstart(ndet)=1+(il-1)*60+1 + ferrs(ndet)=detfer(il) + snrs(ndet)=12.0*log10(detmet2(il))/2-9.0 + endif + detmet2(il)=0.0 + enddo + endif + + nsuccess=0 + msgreceived=' ' + npeaks=2 + ntol0=29 + deltaf=7.2 + do icand=1,ndet ! Try to sync/demod/decode each candidate. + ib=max(1,nstart(icand)-NSPM) + ie=ib-1+3*NSPM + if( ie .gt. n ) then + ie=n + ib=ie-3*NSPM+1 + endif + cdat=cbig(ib:ie) + fo=fc+ferrs(icand) + xsnr=snrs(icand) + do iav=1,NPATTERNS + navmask=navpatterns(1:3,iav) + call msk40sync(cdat,3,ntol0,deltaf,navmask,npeaks,fo,fest,npkloc, & + nsyncsuccess,c) + if( nsyncsuccess .eq. 0 ) cycle + + do ipk=1,npeaks + do is=1,3 + ic0=npkloc(ipk) + if( is.eq.2) ic0=max(1,ic0-1) + if( is.eq.3) ic0=min(NSPM,ic0+1) + ct=cshift(c,ic0-1) + call msk40decodeframe(ct,mycall,hiscall,xsnr,bswl,nhasharray, & + msgreceived,ndecodesuccess) + if( ndecodesuccess .gt. 0 ) then +!write(*,*) icand, iav, ipk, is, tret, fret, msgreceived + tret=(nstart(icand)+NSPM/2)/fs + fret=fest + navg=sum(navmask) + nsuccess=ndecodesuccess + return + endif + enddo + enddo + enddo + enddo ! candidate loop + + return +end subroutine msk40spd diff --git a/lib/msk40sync.f90 b/lib/msk40sync.f90 index a1e699fe..5a2ca1e7 100755 --- a/lib/msk40sync.f90 +++ b/lib/msk40sync.f90 @@ -1,103 +1,103 @@ -subroutine msk40sync(cdat,nframes,ntol,delf,navmask,npeaks,fc,fest, & - npklocs,nsuccess,c) - - !$ use omp_lib - - parameter (NSPM=240) - complex cdat(NSPM*nframes) - complex cdat2(NSPM*nframes,8) - complex c(NSPM) !Coherently averaged complex data - complex cs(NSPM,8) - complex cb(42) !Complex waveform for sync word - - integer s8r(8) - integer iloc(1) - integer npklocs(npeaks) - integer navmask(nframes) ! defines which frames to average - - real cbi(42),cbq(42) - real pkamps(npeaks) - real xcc(0:NSPM-1) - real xccs(0:NSPM-1,8) - real xm(8) - real bf(8) - real pp(12) !Half-sine pulse shape - logical first - data first/.true./ - data s8r/1,0,1,1,0,0,0,1/ - save first,cb,fs,pi,twopi,dt,s8r,pp - - if(first) then - pi=4.0*atan(1.0) - twopi=8.0*atan(1.0) - fs=12000.0 - dt=1.0/fs - - do i=1,12 !Define half-sine pulse - angle=(i-1)*pi/12.0 - pp(i)=sin(angle) - enddo - -! Define the sync word waveforms - s8r=2*s8r-1 - cbq(1:6)=pp(7:12)*s8r(1) - cbq(7:18)=pp*s8r(3) - cbq(19:30)=pp*s8r(5) - cbq(31:42)=pp*s8r(7) - cbi(1:12)=pp*s8r(2) - cbi(13:24)=pp*s8r(4) - cbi(25:36)=pp*s8r(6) - cbi(37:42)=pp(1:6)*s8r(8) - cb=cmplx(cbi,cbq) - - first=.false. - endif - - nfreqs=2*nint(ntol/delf) + 1 - xm=0.0 - bf=0.0 - nthreads=1 - !$ nthreads=min(8,int(OMP_GET_MAX_THREADS(),4)) - nstep=nfreqs/nthreads - - !$OMP PARALLEL NUM_THREADS(nthreads) PRIVATE(id,if1,if2) - id=1 - !$ id=OMP_GET_THREAD_NUM() + 1 !Thread id = 1,2,... - if1=-nint(ntol/delf) + (id-1)*nstep - if2=if1+nstep-1 - if(id.eq.nthreads) if2=nint(ntol/delf) - call msk40_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & - cdat2(1,id),xm(id),bf(id),cs(1,id),xccs(1,id)) -! write(73,3002) id,if1,if2,nfreqs,nthreads,bf(id),xm(id) -!3002 format(5i5,2f10.3) - !$OMP END PARALLEL - - xmax=xm(1) - fest=fc+bf(1) - c=cs(1:NSPM,1) - xcc=xccs(0:NSPM-1,1) - if(nthreads.gt.1) then - do i=2,nthreads - if(xm(i).gt.xmax) then - xmax=xm(i) - fest=fc+bf(i) - c=cs(1:NSPM,i) - xcc=xccs(0:NSPM-1,i) - endif - enddo - endif - -! Find npeaks largest peaks - do ipk=1,npeaks - iloc=maxloc(xcc) - ic2=iloc(1) - npklocs(ipk)=ic2 - pkamps(ipk)=xcc(ic2-1) - xcc(max(0,ic2-7):min(NSPM-1,ic2+7))=0.0 - enddo - - nsuccess=0 - if( xmax .ge. 1.3 ) nsuccess=1 - - return -end subroutine msk40sync +subroutine msk40sync(cdat,nframes,ntol,delf,navmask,npeaks,fc,fest, & + npklocs,nsuccess,c) + + !$ use omp_lib + + parameter (NSPM=240) + complex cdat(NSPM*nframes) + complex cdat2(NSPM*nframes,8) + complex c(NSPM) !Coherently averaged complex data + complex cs(NSPM,8) + complex cb(42) !Complex waveform for sync word + + integer s8r(8) + integer iloc(1) + integer npklocs(npeaks) + integer navmask(nframes) ! defines which frames to average + + real cbi(42),cbq(42) + real pkamps(npeaks) + real xcc(0:NSPM-1) + real xccs(0:NSPM-1,8) + real xm(8) + real bf(8) + real pp(12) !Half-sine pulse shape + logical first + data first/.true./ + data s8r/1,0,1,1,0,0,0,1/ + save first,cb,fs,pi,twopi,dt,s8r,pp + + if(first) then + pi=4.0*atan(1.0) + twopi=8.0*atan(1.0) + fs=12000.0 + dt=1.0/fs + + do i=1,12 !Define half-sine pulse + angle=(i-1)*pi/12.0 + pp(i)=sin(angle) + enddo + +! Define the sync word waveforms + s8r=2*s8r-1 + cbq(1:6)=pp(7:12)*s8r(1) + cbq(7:18)=pp*s8r(3) + cbq(19:30)=pp*s8r(5) + cbq(31:42)=pp*s8r(7) + cbi(1:12)=pp*s8r(2) + cbi(13:24)=pp*s8r(4) + cbi(25:36)=pp*s8r(6) + cbi(37:42)=pp(1:6)*s8r(8) + cb=cmplx(cbi,cbq) + + first=.false. + endif + + nfreqs=2*nint(ntol/delf) + 1 + xm=0.0 + bf=0.0 + nthreads=1 + !$ nthreads=min(8,int(OMP_GET_MAX_THREADS(),4)) + nstep=nfreqs/nthreads + + !$OMP PARALLEL NUM_THREADS(nthreads) PRIVATE(id,if1,if2) + id=1 + !$ id=OMP_GET_THREAD_NUM() + 1 !Thread id = 1,2,... + if1=-nint(ntol/delf) + (id-1)*nstep + if2=if1+nstep-1 + if(id.eq.nthreads) if2=nint(ntol/delf) + call msk40_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & + cdat2(1,id),xm(id),bf(id),cs(1,id),xccs(1,id)) +! write(73,3002) id,if1,if2,nfreqs,nthreads,bf(id),xm(id) +!3002 format(5i5,2f10.3) + !$OMP END PARALLEL + + xmax=xm(1) + fest=fc+bf(1) + c=cs(1:NSPM,1) + xcc=xccs(0:NSPM-1,1) + if(nthreads.gt.1) then + do i=2,nthreads + if(xm(i).gt.xmax) then + xmax=xm(i) + fest=fc+bf(i) + c=cs(1:NSPM,i) + xcc=xccs(0:NSPM-1,i) + endif + enddo + endif + +! Find npeaks largest peaks + do ipk=1,npeaks + iloc=maxloc(xcc) + ic2=iloc(1) + npklocs(ipk)=ic2 + pkamps(ipk)=xcc(ic2-1) + xcc(max(0,ic2-7):min(NSPM-1,ic2+7))=0.0 + enddo + + nsuccess=0 + if( xmax .ge. 1.3 ) nsuccess=1 + + return +end subroutine msk40sync diff --git a/lib/mskber.f90 b/lib/mskber.f90 index c79db6e7..4b31127c 100755 --- a/lib/mskber.f90 +++ b/lib/mskber.f90 @@ -1,146 +1,146 @@ -program mskber - -! Generate an MSK waveform, pass it through an AWGN channel, apply coherent -! MSK receiver, and count number of errors at each Eb/No. - - parameter (MAXSYM=1000*1000) - parameter (NSPS=5) !Samples per symbol - real ct(-NSPS:NSPS*MAXSYM-1) !cos(pi*t/2T) - real st(-NSPS:NSPS*MAXSYM-1) !sin(pi*t/2T) - real r(0:MAXSYM-1) !Random numbers to set test bits - real xsym(0:MAXSYM-1) !Soft Rx symbols - - complex xt(-NSPS:NSPS*MAXSYM-1) !Complex baseband Tx waveform - complex nt(-NSPS:NSPS*MAXSYM-1) !Generated AWGN channel noise - complex yt(-NSPS:NSPS*MAXSYM-1) !Received signal, yt = xt + fac*nt - complex cwave(-NSPS:NSPS*MAXSYM-1) !Audio waveform, Tx real part - complex z - - integer sym0(0:MAXSYM-1) !Generated test bits - integer sym(0:MAXSYM-1) !Hard-copy received bits - integer sym1(0:7) - - character*12 arg - data sym1/1,1,0,0,0,1,1,1/ - - nargs=iargc() - if(nargs.ne.2) then - print*,'Usage: mskber nsym EbNo' - go to 999 - endif - call getarg(1,arg) - read(arg,*) nsym - call getarg(2,arg) - read(arg,*) EbNo - - pi=4.0*atan(1.0) - - do i=-NSPS,NSPS*nsym-1 !Define ct, st arrays - t=i*pi/(2.0*NSPS) - ct(i)=cos(t) - st(i)=sin(t) - enddo - fac=1.0/sqrt(float(NSPS)) - - do iEbNo=0,10 !Loop over a range of Eb/No - sym0=0 - call random_number(r) - where(r(0:nsym-1).gt.0.5) sym0(0:nsym-1)=1 !Generate random data bits - if(nsym.eq.8) sym0(0:nsym-1)=sym1 - call mskmod(sym0,nsym,NSPS,ct,st,xt,cwave) !Generate Tx waveform - - do i=-NSPS,NSPS*nsym-1 !Generate Gaussian noise - xx=0.707*gran() - yy=0.707*gran() - nt(i)=cmplx(xx,yy) - enddo - fac_noise=10.0**(-iEbNo/20.0) - if(EbNo.ne.0.0) fac_noise=10.0**(-EbNo/20.0) - yt=xt + fac_noise*nt !Rx signal, with noise - - call mskdemod(yt,nsym,NSPS,ct,st,xsym) !MSK demodulator - - sym=0 - where(xsym.gt.0.0) sym=1 - - if(nsym.le.160 .and. EbNo.ne.0.0) then - write(*,1012) sym0(0:nsym-1) - if(nsym.gt.50) write(*,1012) - write(*,1012) sym(0:nsym-1) -1012 format(50i1) - do i=-nsps,nsps*nsym-1 - phi=i*2.0*pi*1500/12000.0 - z=cwave(i)*cmplx(cos(phi),sin(phi)) !Mix back to baseband - write(51,1014) float(i)/nsps,xt(i),abs(xt(i)),cwave(i),z -1014 format(8f8.4) - enddo - endif - -! Count the hard errors - nerr=count(sym(0:nsym-1).ne.sym0(0:nsym-1)) - thber=0.5*erfc(10.0**(iEbNo/20.0)) - xEbNo=iEbNo - if(EbNo.ne.0.0) xEbNo=EbNo - write(*,1000) xEbNo,thber,float(nerr)/nsym -1000 format(f6.1,2f10.6) - if(EbNo.ne.0.0) exit - enddo - -999 end program mskber - -subroutine mskmod(sym,nsym,nsps,ct,st,xt,cwave) - -! Generate MSK Tx waveform at baseband. - - integer sym(0:nsym-1) !Hard-copy received bits - complex xt(-nsps:nsps*nsym-1) !Complex baseband Tx waveform - complex cwave(-nsps:nsps*nsym-1) !Audio waveform, fc=1500 Hz. - real ct(-nsps:nsps*nsym-1) !cos(pi*t/2T) - real st(-nsps:nsps*nsym-1) !sin(pi*t/2T) - real ai(-nsps:nsps*nsym-1) !Rectangular pulses for even symbols - real aq(-nsps:nsps*nsym-1) !Rectangular pulses for odd symbols - - ai=0. - aq=0. - fac=1.0/sqrt(float(nsps)) - do j=0,nsym-1,2 - ia=(j-1)*nsps - ib=ia+2*nsps-1 - ai(ia:ib)=2*sym(j)-1 !Even bits as rectangular pulses - aq(ia+nsps:ib+nsps)=2*sym(j+1)-1 !Odd bits as rectangular pulses - enddo - xt=fac*cmplx(ai*ct,aq*st) !Baseband Tx waveform - - twopi=8.0*atan(1.0) - do i=-nsps,nsps*nsym-1 - phi=i*twopi*1500/12000.0 - cwave(i)=xt(i)*cmplx(cos(phi),-sin(phi)) - enddo - - return -end subroutine mskmod - -subroutine mskdemod(yt,nsym,nsps,ct,st,xsym) - -! MSK demodulator -! Rx phase must be known and stable; symbol sync must be established. - - complex yt(-nsps:nsps*nsym-1) !Received signal - real ct(-nsps:nsps*nsym-1) !cos(pi*t/2T) - real st(-nsps:nsps*nsym-1) !sin(pi*t/2T) - real xe(-nsps:nsps*nsym-1) !Temp array for received even symbols - real xo(-nsps:nsps*nsym-1) !Temp array for received odd symbols - real xsym(0:nsym-1) !Soft Rx symbols - - iz=nsps*(nsym+1) - xe(-nsps:nsps*nsym-1)=real(yt)*ct !Apply matched filters - xo(-nsps:nsps*nsym-1)=aimag(yt)*st - do j=0,nsym-1,2 - ia=(j-1)*nsps - ib=ia+2*nsps-1 - xsym(j)=sum(xe(ia:ib)) !Integrate over 2 symbol lengths - xsym(j+1)=sum(xo(ia+nsps:ib+nsps)) - enddo - - return -end subroutine mskdemod +program mskber + +! Generate an MSK waveform, pass it through an AWGN channel, apply coherent +! MSK receiver, and count number of errors at each Eb/No. + + parameter (MAXSYM=1000*1000) + parameter (NSPS=5) !Samples per symbol + real ct(-NSPS:NSPS*MAXSYM-1) !cos(pi*t/2T) + real st(-NSPS:NSPS*MAXSYM-1) !sin(pi*t/2T) + real r(0:MAXSYM-1) !Random numbers to set test bits + real xsym(0:MAXSYM-1) !Soft Rx symbols + + complex xt(-NSPS:NSPS*MAXSYM-1) !Complex baseband Tx waveform + complex nt(-NSPS:NSPS*MAXSYM-1) !Generated AWGN channel noise + complex yt(-NSPS:NSPS*MAXSYM-1) !Received signal, yt = xt + fac*nt + complex cwave(-NSPS:NSPS*MAXSYM-1) !Audio waveform, Tx real part + complex z + + integer sym0(0:MAXSYM-1) !Generated test bits + integer sym(0:MAXSYM-1) !Hard-copy received bits + integer sym1(0:7) + + character*12 arg + data sym1/1,1,0,0,0,1,1,1/ + + nargs=iargc() + if(nargs.ne.2) then + print*,'Usage: mskber nsym EbNo' + go to 999 + endif + call getarg(1,arg) + read(arg,*) nsym + call getarg(2,arg) + read(arg,*) EbNo + + pi=4.0*atan(1.0) + + do i=-NSPS,NSPS*nsym-1 !Define ct, st arrays + t=i*pi/(2.0*NSPS) + ct(i)=cos(t) + st(i)=sin(t) + enddo + fac=1.0/sqrt(float(NSPS)) + + do iEbNo=0,10 !Loop over a range of Eb/No + sym0=0 + call random_number(r) + where(r(0:nsym-1).gt.0.5) sym0(0:nsym-1)=1 !Generate random data bits + if(nsym.eq.8) sym0(0:nsym-1)=sym1 + call mskmod(sym0,nsym,NSPS,ct,st,xt,cwave) !Generate Tx waveform + + do i=-NSPS,NSPS*nsym-1 !Generate Gaussian noise + xx=0.707*gran() + yy=0.707*gran() + nt(i)=cmplx(xx,yy) + enddo + fac_noise=10.0**(-iEbNo/20.0) + if(EbNo.ne.0.0) fac_noise=10.0**(-EbNo/20.0) + yt=xt + fac_noise*nt !Rx signal, with noise + + call mskdemod(yt,nsym,NSPS,ct,st,xsym) !MSK demodulator + + sym=0 + where(xsym.gt.0.0) sym=1 + + if(nsym.le.160 .and. EbNo.ne.0.0) then + write(*,1012) sym0(0:nsym-1) + if(nsym.gt.50) write(*,1012) + write(*,1012) sym(0:nsym-1) +1012 format(50i1) + do i=-nsps,nsps*nsym-1 + phi=i*2.0*pi*1500/12000.0 + z=cwave(i)*cmplx(cos(phi),sin(phi)) !Mix back to baseband + write(51,1014) float(i)/nsps,xt(i),abs(xt(i)),cwave(i),z +1014 format(8f8.4) + enddo + endif + +! Count the hard errors + nerr=count(sym(0:nsym-1).ne.sym0(0:nsym-1)) + thber=0.5*erfc(10.0**(iEbNo/20.0)) + xEbNo=iEbNo + if(EbNo.ne.0.0) xEbNo=EbNo + write(*,1000) xEbNo,thber,float(nerr)/nsym +1000 format(f6.1,2f10.6) + if(EbNo.ne.0.0) exit + enddo + +999 end program mskber + +subroutine mskmod(sym,nsym,nsps,ct,st,xt,cwave) + +! Generate MSK Tx waveform at baseband. + + integer sym(0:nsym-1) !Hard-copy received bits + complex xt(-nsps:nsps*nsym-1) !Complex baseband Tx waveform + complex cwave(-nsps:nsps*nsym-1) !Audio waveform, fc=1500 Hz. + real ct(-nsps:nsps*nsym-1) !cos(pi*t/2T) + real st(-nsps:nsps*nsym-1) !sin(pi*t/2T) + real ai(-nsps:nsps*nsym-1) !Rectangular pulses for even symbols + real aq(-nsps:nsps*nsym-1) !Rectangular pulses for odd symbols + + ai=0. + aq=0. + fac=1.0/sqrt(float(nsps)) + do j=0,nsym-1,2 + ia=(j-1)*nsps + ib=ia+2*nsps-1 + ai(ia:ib)=2*sym(j)-1 !Even bits as rectangular pulses + aq(ia+nsps:ib+nsps)=2*sym(j+1)-1 !Odd bits as rectangular pulses + enddo + xt=fac*cmplx(ai*ct,aq*st) !Baseband Tx waveform + + twopi=8.0*atan(1.0) + do i=-nsps,nsps*nsym-1 + phi=i*twopi*1500/12000.0 + cwave(i)=xt(i)*cmplx(cos(phi),-sin(phi)) + enddo + + return +end subroutine mskmod + +subroutine mskdemod(yt,nsym,nsps,ct,st,xsym) + +! MSK demodulator +! Rx phase must be known and stable; symbol sync must be established. + + complex yt(-nsps:nsps*nsym-1) !Received signal + real ct(-nsps:nsps*nsym-1) !cos(pi*t/2T) + real st(-nsps:nsps*nsym-1) !sin(pi*t/2T) + real xe(-nsps:nsps*nsym-1) !Temp array for received even symbols + real xo(-nsps:nsps*nsym-1) !Temp array for received odd symbols + real xsym(0:nsym-1) !Soft Rx symbols + + iz=nsps*(nsym+1) + xe(-nsps:nsps*nsym-1)=real(yt)*ct !Apply matched filters + xo(-nsps:nsps*nsym-1)=aimag(yt)*st + do j=0,nsym-1,2 + ia=(j-1)*nsps + ib=ia+2*nsps-1 + xsym(j)=sum(xe(ia:ib)) !Integrate over 2 symbol lengths + xsym(j+1)=sum(xo(ia+nsps:ib+nsps)) + enddo + + return +end subroutine mskdemod diff --git a/lib/mskdt.f90 b/lib/mskdt.f90 index 5da39430..bca83599 100755 --- a/lib/mskdt.f90 +++ b/lib/mskdt.f90 @@ -1,78 +1,78 @@ -subroutine mskdt(d,npts,ty,yellow,nyel) - - parameter (NFFT=1024,NH=NFFT/2) - real d(npts) - real x(0:NFFT-1) - real green(703) - real yellow(703) !703 = 30*12000/512 - real ty(703) - real y2(175) - real ty2(175) - integer indx(703) - logical ok - complex c(0:NH) - equivalence (x,c) - - df=12000.0/NFFT - i1=nint(300.0/df) - i2=nint(800.0/df) - i3=nint(2200.0/df) - i4=nint(2700.0/df) - nblks=npts/NH - 1 - - do j=1,nblks - ib=(j+1)*NH - ia=ib-NFFT+1 - x=d(ia:ib) - call four2a(x,NFFT,1,-1,0) !r2c FFT - sqlow=0. - do i=i1,i2 - sqlow=sqlow + real(c(i))**2 + aimag(c(i))**2 - enddo - sqmid=0. - do i=i2,i3 - sqmid=sqmid + real(c(i))**2 + aimag(c(i))**2 - enddo - sqhigh=0. - do i=i3,i4 - sqhigh=sqhigh + real(c(i))**2 + aimag(c(i))**2 - enddo - green(j)=db(sqlow+sqmid+sqhigh) - yellow(j)=db(sqmid/(sqlow+sqhigh)) - ty(j)=j*512.0/12000.0 - enddo - - npct=20 - call pctile(green,nblks,npct,base) - green(1:nblks)=green(1:nblks) - base - 0.3 - call pctile(yellow,nblks,npct,base) - yellow(1:nblks)=yellow(1:nblks) - base - 0.6 - call indexx(yellow,nblks,indx) - - do j=1,nblks/4 - k=indx(nblks+1-j) - ty(j)=ty(k) - yellow(j)=yellow(k) - if(yellow(j).lt.1.5) exit - enddo - nyel=j-1 - k=1 - y2(1)=yellow(1) - ty2(1)=ty(1) - do j=2,nyel - ok=.true. - do i=1,j-1 - if(abs(ty(i)-ty(j)).lt.0.117) ok=.false. - enddo - if(ok) then - k=k+1 - y2(k)=yellow(j) - ty2(k)=ty(j) - endif - enddo - nyel=k - yellow(1:nyel)=y2(1:nyel) - ty(1:nyel)=ty2(1:nyel) - - return -end subroutine mskdt +subroutine mskdt(d,npts,ty,yellow,nyel) + + parameter (NFFT=1024,NH=NFFT/2) + real d(npts) + real x(0:NFFT-1) + real green(703) + real yellow(703) !703 = 30*12000/512 + real ty(703) + real y2(175) + real ty2(175) + integer indx(703) + logical ok + complex c(0:NH) + equivalence (x,c) + + df=12000.0/NFFT + i1=nint(300.0/df) + i2=nint(800.0/df) + i3=nint(2200.0/df) + i4=nint(2700.0/df) + nblks=npts/NH - 1 + + do j=1,nblks + ib=(j+1)*NH + ia=ib-NFFT+1 + x=d(ia:ib) + call four2a(x,NFFT,1,-1,0) !r2c FFT + sqlow=0. + do i=i1,i2 + sqlow=sqlow + real(c(i))**2 + aimag(c(i))**2 + enddo + sqmid=0. + do i=i2,i3 + sqmid=sqmid + real(c(i))**2 + aimag(c(i))**2 + enddo + sqhigh=0. + do i=i3,i4 + sqhigh=sqhigh + real(c(i))**2 + aimag(c(i))**2 + enddo + green(j)=db(sqlow+sqmid+sqhigh) + yellow(j)=db(sqmid/(sqlow+sqhigh)) + ty(j)=j*512.0/12000.0 + enddo + + npct=20 + call pctile(green,nblks,npct,base) + green(1:nblks)=green(1:nblks) - base - 0.3 + call pctile(yellow,nblks,npct,base) + yellow(1:nblks)=yellow(1:nblks) - base - 0.6 + call indexx(yellow,nblks,indx) + + do j=1,nblks/4 + k=indx(nblks+1-j) + ty(j)=ty(k) + yellow(j)=yellow(k) + if(yellow(j).lt.1.5) exit + enddo + nyel=j-1 + k=1 + y2(1)=yellow(1) + ty2(1)=ty(1) + do j=2,nyel + ok=.true. + do i=1,j-1 + if(abs(ty(i)-ty(j)).lt.0.117) ok=.false. + enddo + if(ok) then + k=k+1 + y2(k)=yellow(j) + ty2(k)=ty(j) + endif + enddo + nyel=k + yellow(1:nyel)=y2(1:nyel) + ty(1:nyel)=ty2(1:nyel) + + return +end subroutine mskdt diff --git a/lib/mskrtd.f90 b/lib/mskrtd.f90 index 068f6c40..b81e7f8a 100755 --- a/lib/mskrtd.f90 +++ b/lib/mskrtd.f90 @@ -1,261 +1,261 @@ -subroutine mskrtd(id2,nutc0,tsec,ntol,nrxfreq,ndepth,mycall,hiscall, & - bshmsg,btrain,pcoeffs,bswl,datadir,line) - -! Real-time decoder for MSK144. -! Analysis block size = NZ = 7168 samples, t_block = 0.597333 s -! Called from hspec() at half-block increments, about 0.3 s - - use packjt77 - - parameter (NZ=7168) !Block size - parameter (NSPM=864) !Number of samples per message frame - parameter (NFFT1=8192) !FFT size for making analytic signal - parameter (NPATTERNS=4) !Number of frame averaging patterns to try - parameter (NSHMEM=50) !Number of recent SWL messages to remember - - character*4 decsym !"&" for mskspd or "^" for long averages - character*37 msgreceived !Decoded message - character*37 msglast,msglastswl !Used for dupechecking - character*(*) line !Formatted line with UTC dB T Freq Msg - character*(*) mycall,hiscall - character*37 recent_shmsgs(NSHMEM) - character*(*) datadir - - complex cdat(NFFT1) !Analytic signal - complex c(NSPM) !Coherently averaged complex data - complex ct(NSPM) - - integer*2 id2(NZ) !Raw 16-bit data - integer iavmask(8) - integer iavpatterns(8,NPATTERNS) - integer npkloc(10) - integer nhasharray(MAXRECENT,MAXRECENT) - integer nsnrlast,nsnrlastswl - - real d(NFFT1) - real pow(8) - real softbits(144) - real xmc(NPATTERNS) - real*8 pcoeffs(5) - - logical*1 bshmsg,btrain,bswl - logical*1 first - logical*1 bshdecode - logical*1 seenb4 - logical*1 bflag - logical*1 bvar - - data first/.true./ - data iavpatterns/ & - 1,1,1,1,0,0,0,0, & - 0,0,1,1,1,1,0,0, & - 1,1,1,1,1,0,0,0, & - 1,1,1,1,1,1,1,0/ - data xmc/2.0,4.5,2.5,3.5/ !Used to set time at center of averaging mask - save first,tsec0,nutc00,pnoise,cdat,msglast,msglastswl, & - nsnrlast,nsnrlastswl,nhasharray,recent_shmsgs -! nsnrlast,nsnrlastswl,nhasharray,recent_shmsgs,mycall13 - - if(first) then - tsec0=tsec - nutc00=nutc0 - pnoise=-1.0 - do i=1,MAXRECENT - recent_calls(i)(1:13)=' ' - enddo - do i=1,nshmem - recent_shmsgs(i)(1:37)=' ' - enddo - msglast=' ' - msglastswl=' ' - nsnrlast=-99 - nsnrlastswl=-99 -! mycall13=mycall//' ' -! dxcall13=hiscall//' ' - mycall13=' ' - dxcall13=' ' - mycall13(1:12)=mycall(1:12) - dxcall13(1:12)=hiscall(1:12) - first=.false. - endif - - fc=nrxfreq - -! Reset if mycall or dxcall changes - if(mycall13(1:12).ne.mycall(1:12) .or. dxcall13(1:12).ne.hiscall(1:12)) first=.true. - -! Dupe checking setup - if(nutc00.ne.nutc0 .or. tsec.lt.tsec0) then ! reset dupe checker - msglast=' ' - msglastswl=' ' - nsnrlast=-99 - nsnrlastswl=-99 - nutc00=nutc0 - endif - - tframe=float(NSPM)/12000.0 - line(1:1)=char(0) - msgreceived=' ' - max_iterations=10 - niterations=0 - d(1:NZ)=id2 - rms=sqrt(sum(d(1:NZ)*d(1:NZ))/NZ) - if(rms.lt.1.0) go to 999 - fac=1.0/rms - d(1:NZ)=fac*d(1:NZ) - d(NZ+1:NFFT1)=0. - bvar=.true. - if( btrain ) bvar=.false. ! if training, turn off rx eq - call analytic(d,NZ,NFFT1,cdat,pcoeffs,bvar) - -! Calculate average power for each frame and for the entire block. -! If decode is successful, largest power will be taken as signal+noise. -! If no decode, entire-block average will be used to update noise estimate. - pmax=-99 - do i=1,8 - ib=(i-1)*NSPM+1 - ie=ib+NSPM-1 - pow(i)=real(dot_product(cdat(ib:ie),cdat(ib:ie)))*rms**2 - pmax=max(pmax,pow(i)) - enddo - pavg=sum(pow)/8.0 - -! Short ping decoder uses squared-signal spectrum to determine where to -! center a 3-frame analysis window and attempts to decode each of the -! 3 frames along with 2- and 3-frame averages. - np=8*NSPM - call msk144spd(cdat,np,ntol,ndecodesuccess,msgreceived,fc,fest,tdec,navg,ct, & - softbits) - bshdecode=.false. - if(ndecodesuccess.eq.0 .and. (bshmsg.or.bswl)) then - call msk40spd(cdat,np,ntol,mycall,hiscall,bswl,nhasharray, & - ndecodesuccess,msgreceived,fc,fest,tdec,navg) - if(ndecodesuccess .ge.1) bshdecode=.true. - endif - if( ndecodesuccess .ge. 1 ) then - tdec=tsec+tdec - ipk=0 - is=0 - goto 900 - endif - -! If short ping decoder doesn't find a decode, -! Fast - short ping decoder only. -! Normal - try 4-frame averages -! Deep - try 4-, 5- and 7-frame averages. - npat=NPATTERNS - if( ndepth .eq. 1 ) npat=0 - if( ndepth .eq. 2 ) npat=2 - do iavg=1,npat - iavmask=iavpatterns(1:8,iavg) - navg=sum(iavmask) - deltaf=10.0/real(navg) ! search increment for frequency sync - npeaks=2 - call msk144sync(cdat(1:8*NSPM),8,ntol,deltaf,iavmask,npeaks,fc, & - fest,npkloc,nsyncsuccess,xmax,c) - if( nsyncsuccess .eq. 0 ) cycle - - do ipk=1,npeaks - do is=1,3 - ic0=npkloc(ipk) - if(is.eq.2) ic0=max(1,ic0-1) - if(is.eq.3) ic0=min(NSPM,ic0+1) - ct=cshift(c,ic0-1) - call msk144decodeframe(ct,softbits,msgreceived,ndecodesuccess) - if(ndecodesuccess .gt. 0) then - tdec=tsec+xmc(iavg)*tframe - goto 900 - endif - enddo !Slicer dither - enddo !Peak loop - enddo - - - msgreceived=' ' - -! no decode - update noise level used for calculating displayed snr. - if( pnoise .lt. 0 ) then ! initialize noise level - pnoise=pavg - elseif( pavg .gt. pnoise ) then ! noise level is slow to rise - pnoise=0.9*pnoise+0.1*pavg - elseif( pavg .lt. pnoise ) then ! and quick to fall - pnoise=pavg - endif - go to 999 - -900 continue -! Successful decode - estimate snr - if( pnoise .gt. 0.0 ) then - snr0=10.0*log10(pmax/pnoise-1.0) - else - snr0=0.0 - endif - nsnr=nint(snr0) - - if(.not. bshdecode) then - call msk144signalquality(ct,snr0,fest,tdec,softbits,msgreceived,hiscall, & - btrain,datadir,ncorrected,eyeopening,pcoeffs) - endif - - decsym=' & ' - if( btrain ) decsym=' ^ ' - if( bshdecode ) then - ncorrected=0 - eyeopening=0.0 - endif - - if( nsnr .lt. -8 ) nsnr=-8 - if( nsnr .gt. 24 ) nsnr=24 - -! Dupe check. - bflag=ndecodesuccess.eq.1 .and. & - (msgreceived.ne.msglast .or. nsnr.gt.nsnrlast .or. tsec.lt.tsec0) - if(bflag) then - msglast=msgreceived - nsnrlast=nsnr - if(.not. bshdecode) then - call update_msk40_hasharray(nhasharray) - endif - write(line,1021) nutc0,nsnr,tdec,nint(fest),decsym,msgreceived,char(0) -1021 format(i6.6,i4,f5.1,i5,a4,a37,a1) - elseif(bswl .and. ndecodesuccess.ge.2) then - seenb4=.false. - do i=1,nshmem - if( msgreceived .eq. recent_shmsgs(i) ) then - seenb4=.true. - endif - enddo - call update_recent_shmsgs(msgreceived,recent_shmsgs,nshmem) - bflag=seenb4 .and. & - (msgreceived.ne.msglastswl .or. nsnr.gt.nsnrlastswl .or. tsec.lt.tsec0) & - .and. nsnr.gt.-6 - if(bflag) then - msglastswl=msgreceived - nsnrlastswl=nsnr - write(line,1021) nutc0,nsnr,tdec,nint(fest),decsym,msgreceived,char(0) - endif - endif -999 tsec0=tsec - - return -end subroutine mskrtd - -subroutine update_recent_shmsgs(message,msgs,nsize) - character*37 msgs(nsize) - character*37 message - logical*1 seen - - seen=.false. - do i=1,nsize - if( msgs(i) .eq. message ) seen=.true. - enddo - - if( .not. seen ) then - do i=nsize,2,-1 - msgs(i)=msgs(i-1) - enddo - msgs(1)=message - endif - - return -end subroutine update_recent_shmsgs +subroutine mskrtd(id2,nutc0,tsec,ntol,nrxfreq,ndepth,mycall,hiscall, & + bshmsg,btrain,pcoeffs,bswl,datadir,line) + +! Real-time decoder for MSK144. +! Analysis block size = NZ = 7168 samples, t_block = 0.597333 s +! Called from hspec() at half-block increments, about 0.3 s + + use packjt77 + + parameter (NZ=7168) !Block size + parameter (NSPM=864) !Number of samples per message frame + parameter (NFFT1=8192) !FFT size for making analytic signal + parameter (NPATTERNS=4) !Number of frame averaging patterns to try + parameter (NSHMEM=50) !Number of recent SWL messages to remember + + character*4 decsym !"&" for mskspd or "^" for long averages + character*37 msgreceived !Decoded message + character*37 msglast,msglastswl !Used for dupechecking + character*(*) line !Formatted line with UTC dB T Freq Msg + character*(*) mycall,hiscall + character*37 recent_shmsgs(NSHMEM) + character*(*) datadir + + complex cdat(NFFT1) !Analytic signal + complex c(NSPM) !Coherently averaged complex data + complex ct(NSPM) + + integer*2 id2(NZ) !Raw 16-bit data + integer iavmask(8) + integer iavpatterns(8,NPATTERNS) + integer npkloc(10) + integer nhasharray(MAXRECENT,MAXRECENT) + integer nsnrlast,nsnrlastswl + + real d(NFFT1) + real pow(8) + real softbits(144) + real xmc(NPATTERNS) + real*8 pcoeffs(5) + + logical*1 bshmsg,btrain,bswl + logical*1 first + logical*1 bshdecode + logical*1 seenb4 + logical*1 bflag + logical*1 bvar + + data first/.true./ + data iavpatterns/ & + 1,1,1,1,0,0,0,0, & + 0,0,1,1,1,1,0,0, & + 1,1,1,1,1,0,0,0, & + 1,1,1,1,1,1,1,0/ + data xmc/2.0,4.5,2.5,3.5/ !Used to set time at center of averaging mask + save first,tsec0,nutc00,pnoise,cdat,msglast,msglastswl, & + nsnrlast,nsnrlastswl,nhasharray,recent_shmsgs +! nsnrlast,nsnrlastswl,nhasharray,recent_shmsgs,mycall13 + + if(first) then + tsec0=tsec + nutc00=nutc0 + pnoise=-1.0 + do i=1,MAXRECENT + recent_calls(i)(1:13)=' ' + enddo + do i=1,nshmem + recent_shmsgs(i)(1:37)=' ' + enddo + msglast=' ' + msglastswl=' ' + nsnrlast=-99 + nsnrlastswl=-99 +! mycall13=mycall//' ' +! dxcall13=hiscall//' ' + mycall13=' ' + dxcall13=' ' + mycall13(1:12)=mycall(1:12) + dxcall13(1:12)=hiscall(1:12) + first=.false. + endif + + fc=nrxfreq + +! Reset if mycall or dxcall changes + if(mycall13(1:12).ne.mycall(1:12) .or. dxcall13(1:12).ne.hiscall(1:12)) first=.true. + +! Dupe checking setup + if(nutc00.ne.nutc0 .or. tsec.lt.tsec0) then ! reset dupe checker + msglast=' ' + msglastswl=' ' + nsnrlast=-99 + nsnrlastswl=-99 + nutc00=nutc0 + endif + + tframe=float(NSPM)/12000.0 + line(1:1)=char(0) + msgreceived=' ' + max_iterations=10 + niterations=0 + d(1:NZ)=id2 + rms=sqrt(sum(d(1:NZ)*d(1:NZ))/NZ) + if(rms.lt.1.0) go to 999 + fac=1.0/rms + d(1:NZ)=fac*d(1:NZ) + d(NZ+1:NFFT1)=0. + bvar=.true. + if( btrain ) bvar=.false. ! if training, turn off rx eq + call analytic(d,NZ,NFFT1,cdat,pcoeffs,bvar) + +! Calculate average power for each frame and for the entire block. +! If decode is successful, largest power will be taken as signal+noise. +! If no decode, entire-block average will be used to update noise estimate. + pmax=-99 + do i=1,8 + ib=(i-1)*NSPM+1 + ie=ib+NSPM-1 + pow(i)=real(dot_product(cdat(ib:ie),cdat(ib:ie)))*rms**2 + pmax=max(pmax,pow(i)) + enddo + pavg=sum(pow)/8.0 + +! Short ping decoder uses squared-signal spectrum to determine where to +! center a 3-frame analysis window and attempts to decode each of the +! 3 frames along with 2- and 3-frame averages. + np=8*NSPM + call msk144spd(cdat,np,ntol,ndecodesuccess,msgreceived,fc,fest,tdec,navg,ct, & + softbits) + bshdecode=.false. + if(ndecodesuccess.eq.0 .and. (bshmsg.or.bswl)) then + call msk40spd(cdat,np,ntol,mycall,hiscall,bswl,nhasharray, & + ndecodesuccess,msgreceived,fc,fest,tdec,navg) + if(ndecodesuccess .ge.1) bshdecode=.true. + endif + if( ndecodesuccess .ge. 1 ) then + tdec=tsec+tdec + ipk=0 + is=0 + goto 900 + endif + +! If short ping decoder doesn't find a decode, +! Fast - short ping decoder only. +! Normal - try 4-frame averages +! Deep - try 4-, 5- and 7-frame averages. + npat=NPATTERNS + if( ndepth .eq. 1 ) npat=0 + if( ndepth .eq. 2 ) npat=2 + do iavg=1,npat + iavmask=iavpatterns(1:8,iavg) + navg=sum(iavmask) + deltaf=10.0/real(navg) ! search increment for frequency sync + npeaks=2 + call msk144sync(cdat(1:8*NSPM),8,ntol,deltaf,iavmask,npeaks,fc, & + fest,npkloc,nsyncsuccess,xmax,c) + if( nsyncsuccess .eq. 0 ) cycle + + do ipk=1,npeaks + do is=1,3 + ic0=npkloc(ipk) + if(is.eq.2) ic0=max(1,ic0-1) + if(is.eq.3) ic0=min(NSPM,ic0+1) + ct=cshift(c,ic0-1) + call msk144decodeframe(ct,softbits,msgreceived,ndecodesuccess) + if(ndecodesuccess .gt. 0) then + tdec=tsec+xmc(iavg)*tframe + goto 900 + endif + enddo !Slicer dither + enddo !Peak loop + enddo + + + msgreceived=' ' + +! no decode - update noise level used for calculating displayed snr. + if( pnoise .lt. 0 ) then ! initialize noise level + pnoise=pavg + elseif( pavg .gt. pnoise ) then ! noise level is slow to rise + pnoise=0.9*pnoise+0.1*pavg + elseif( pavg .lt. pnoise ) then ! and quick to fall + pnoise=pavg + endif + go to 999 + +900 continue +! Successful decode - estimate snr + if( pnoise .gt. 0.0 ) then + snr0=10.0*log10(pmax/pnoise-1.0) + else + snr0=0.0 + endif + nsnr=nint(snr0) + + if(.not. bshdecode) then + call msk144signalquality(ct,snr0,fest,tdec,softbits,msgreceived,hiscall, & + btrain,datadir,ncorrected,eyeopening,pcoeffs) + endif + + decsym=' & ' + if( btrain ) decsym=' ^ ' + if( bshdecode ) then + ncorrected=0 + eyeopening=0.0 + endif + + if( nsnr .lt. -8 ) nsnr=-8 + if( nsnr .gt. 24 ) nsnr=24 + +! Dupe check. + bflag=ndecodesuccess.eq.1 .and. & + (msgreceived.ne.msglast .or. nsnr.gt.nsnrlast .or. tsec.lt.tsec0) + if(bflag) then + msglast=msgreceived + nsnrlast=nsnr + if(.not. bshdecode) then + call update_msk40_hasharray(nhasharray) + endif + write(line,1021) nutc0,nsnr,tdec,nint(fest),decsym,msgreceived,char(0) +1021 format(i6.6,i4,f5.1,i5,a4,a37,a1) + elseif(bswl .and. ndecodesuccess.ge.2) then + seenb4=.false. + do i=1,nshmem + if( msgreceived .eq. recent_shmsgs(i) ) then + seenb4=.true. + endif + enddo + call update_recent_shmsgs(msgreceived,recent_shmsgs,nshmem) + bflag=seenb4 .and. & + (msgreceived.ne.msglastswl .or. nsnr.gt.nsnrlastswl .or. tsec.lt.tsec0) & + .and. nsnr.gt.-6 + if(bflag) then + msglastswl=msgreceived + nsnrlastswl=nsnr + write(line,1021) nutc0,nsnr,tdec,nint(fest),decsym,msgreceived,char(0) + endif + endif +999 tsec0=tsec + + return +end subroutine mskrtd + +subroutine update_recent_shmsgs(message,msgs,nsize) + character*37 msgs(nsize) + character*37 message + logical*1 seen + + seen=.false. + do i=1,nsize + if( msgs(i) .eq. message ) seen=.true. + enddo + + if( .not. seen ) then + do i=nsize,2,-1 + msgs(i)=msgs(i-1) + enddo + msgs(1)=message + endif + + return +end subroutine update_recent_shmsgs diff --git a/lib/nfft.dat b/lib/nfft.dat index 99213f15..6378e64e 100755 --- a/lib/nfft.dat +++ b/lib/nfft.dat @@ -1,2067 +1,2067 @@ - 8 2 2 2 - 9 3 3 - 10 2 5 - 12 2 2 3 - 14 2 7 - 15 3 5 - 16 2 2 2 2 - 18 2 3 3 - 20 2 2 5 - 21 3 7 - 24 2 2 2 3 - 25 5 5 - 27 3 3 3 - 28 2 2 7 - 30 2 3 5 - 32 2 2 2 2 2 - 35 5 7 - 36 2 2 3 3 - 40 2 2 2 5 - 42 2 3 7 - 45 3 3 5 - 48 2 2 2 2 3 - 49 7 7 - 50 2 5 5 - 54 2 3 3 3 - 56 2 2 2 7 - 60 2 2 3 5 - 63 3 3 7 - 64 2 2 2 2 2 2 - 70 2 5 7 - 72 2 2 2 3 3 - 75 3 5 5 - 80 2 2 2 2 5 - 81 3 3 3 3 - 84 2 2 3 7 - 90 2 3 3 5 - 96 2 2 2 2 2 3 - 98 2 7 7 - 100 2 2 5 5 - 105 3 5 7 - 108 2 2 3 3 3 - 112 2 2 2 2 7 - 120 2 2 2 3 5 - 125 5 5 5 - 126 2 3 3 7 - 128 2 2 2 2 2 2 2 - 135 3 3 3 5 - 140 2 2 5 7 - 144 2 2 2 2 3 3 - 147 3 7 7 - 150 2 3 5 5 - 160 2 2 2 2 2 5 - 162 2 3 3 3 3 - 168 2 2 2 3 7 - 175 5 5 7 - 180 2 2 3 3 5 - 189 3 3 3 7 - 192 2 2 2 2 2 2 3 - 196 2 2 7 7 - 200 2 2 2 5 5 - 210 2 3 5 7 - 216 2 2 2 3 3 3 - 224 2 2 2 2 2 7 - 225 3 3 5 5 - 240 2 2 2 2 3 5 - 243 3 3 3 3 3 - 245 5 7 7 - 250 2 5 5 5 - 252 2 2 3 3 7 - 256 2 2 2 2 2 2 2 2 - 270 2 3 3 3 5 - 280 2 2 2 5 7 - 288 2 2 2 2 2 3 3 - 294 2 3 7 7 - 300 2 2 3 5 5 - 315 3 3 5 7 - 320 2 2 2 2 2 2 5 - 324 2 2 3 3 3 3 - 336 2 2 2 2 3 7 - 343 7 7 7 - 350 2 5 5 7 - 360 2 2 2 3 3 5 - 375 3 5 5 5 - 378 2 3 3 3 7 - 384 2 2 2 2 2 2 2 3 - 392 2 2 2 7 7 - 400 2 2 2 2 5 5 - 405 3 3 3 3 5 - 420 2 2 3 5 7 - 432 2 2 2 2 3 3 3 - 441 3 3 7 7 - 448 2 2 2 2 2 2 7 - 450 2 3 3 5 5 - 480 2 2 2 2 2 3 5 - 486 2 3 3 3 3 3 - 490 2 5 7 7 - 500 2 2 5 5 5 - 504 2 2 2 3 3 7 - 512 2 2 2 2 2 2 2 2 2 - 525 3 5 5 7 - 540 2 2 3 3 3 5 - 560 2 2 2 2 5 7 - 567 3 3 3 3 7 - 576 2 2 2 2 2 2 3 3 - 588 2 2 3 7 7 - 600 2 2 2 3 5 5 - 625 5 5 5 5 - 630 2 3 3 5 7 - 640 2 2 2 2 2 2 2 5 - 648 2 2 2 3 3 3 3 - 672 2 2 2 2 2 3 7 - 675 3 3 3 5 5 - 686 2 7 7 7 - 700 2 2 5 5 7 - 720 2 2 2 2 3 3 5 - 729 3 3 3 3 3 3 - 735 3 5 7 7 - 750 2 3 5 5 5 - 756 2 2 3 3 3 7 - 768 2 2 2 2 2 2 2 2 3 - 784 2 2 2 2 7 7 - 800 2 2 2 2 2 5 5 - 810 2 3 3 3 3 5 - 840 2 2 2 3 5 7 - 864 2 2 2 2 2 3 3 3 - 875 5 5 5 7 - 882 2 3 3 7 7 - 896 2 2 2 2 2 2 2 7 - 900 2 2 3 3 5 5 - 945 3 3 3 5 7 - 960 2 2 2 2 2 2 3 5 - 972 2 2 3 3 3 3 3 - 980 2 2 5 7 7 - 1000 2 2 2 5 5 5 - 1008 2 2 2 2 3 3 7 - 1024 2 2 2 2 2 2 2 2 2 2 - 1029 3 7 7 7 - 1050 2 3 5 5 7 - 1080 2 2 2 3 3 3 5 - 1120 2 2 2 2 2 5 7 - 1125 3 3 5 5 5 - 1134 2 3 3 3 3 7 - 1152 2 2 2 2 2 2 2 3 3 - 1176 2 2 2 3 7 7 - 1200 2 2 2 2 3 5 5 - 1215 3 3 3 3 3 5 - 1225 5 5 7 7 - 1250 2 5 5 5 5 - 1260 2 2 3 3 5 7 - 1280 2 2 2 2 2 2 2 2 5 - 1296 2 2 2 2 3 3 3 3 - 1323 3 3 3 7 7 - 1344 2 2 2 2 2 2 3 7 - 1350 2 3 3 3 5 5 - 1372 2 2 7 7 7 - 1400 2 2 2 5 5 7 - 1440 2 2 2 2 2 3 3 5 - 1458 2 3 3 3 3 3 3 - 1470 2 3 5 7 7 - 1500 2 2 3 5 5 5 - 1512 2 2 2 3 3 3 7 - 1536 2 2 2 2 2 2 2 2 2 3 - 1568 2 2 2 2 2 7 7 - 1575 3 3 5 5 7 - 1600 2 2 2 2 2 2 5 5 - 1620 2 2 3 3 3 3 5 - 1680 2 2 2 2 3 5 7 - 1701 3 3 3 3 3 7 - 1715 5 7 7 7 - 1728 2 2 2 2 2 2 3 3 3 - 1750 2 5 5 5 7 - 1764 2 2 3 3 7 7 - 1792 2 2 2 2 2 2 2 2 7 - 1800 2 2 2 3 3 5 5 - 1875 3 5 5 5 5 - 1890 2 3 3 3 5 7 - 1920 2 2 2 2 2 2 2 3 5 - 1944 2 2 2 3 3 3 3 3 - 1960 2 2 2 5 7 7 - 2000 2 2 2 2 5 5 5 - 2016 2 2 2 2 2 3 3 7 - 2025 3 3 3 3 5 5 - 2048 2 2 2 2 2 2 2 2 2 2 2 - 2058 2 3 7 7 7 - 2100 2 2 3 5 5 7 - 2160 2 2 2 2 3 3 3 5 - 2187 3 3 3 3 3 3 3 - 2205 3 3 5 7 7 - 2240 2 2 2 2 2 2 5 7 - 2250 2 3 3 5 5 5 - 2268 2 2 3 3 3 3 7 - 2304 2 2 2 2 2 2 2 2 3 3 - 2352 2 2 2 2 3 7 7 - 2400 2 2 2 2 2 3 5 5 - 2401 7 7 7 7 - 2430 2 3 3 3 3 3 5 - 2450 2 5 5 7 7 - 2500 2 2 5 5 5 5 - 2520 2 2 2 3 3 5 7 - 2560 2 2 2 2 2 2 2 2 2 5 - 2592 2 2 2 2 2 3 3 3 3 - 2625 3 5 5 5 7 - 2646 2 3 3 3 7 7 - 2688 2 2 2 2 2 2 2 3 7 - 2700 2 2 3 3 3 5 5 - 2744 2 2 2 7 7 7 - 2800 2 2 2 2 5 5 7 - 2835 3 3 3 3 5 7 - 2880 2 2 2 2 2 2 3 3 5 - 2916 2 2 3 3 3 3 3 3 - 2940 2 2 3 5 7 7 - 3000 2 2 2 3 5 5 5 - 3024 2 2 2 2 3 3 3 7 - 3072 2 2 2 2 2 2 2 2 2 2 3 - 3087 3 3 7 7 7 - 3125 5 5 5 5 5 - 3136 2 2 2 2 2 2 7 7 - 3150 2 3 3 5 5 7 - 3200 2 2 2 2 2 2 2 5 5 - 3240 2 2 2 3 3 3 3 5 - 3360 2 2 2 2 2 3 5 7 - 3375 3 3 3 5 5 5 - 3402 2 3 3 3 3 3 7 - 3430 2 5 7 7 7 - 3456 2 2 2 2 2 2 2 3 3 3 - 3500 2 2 5 5 5 7 - 3528 2 2 2 3 3 7 7 - 3584 2 2 2 2 2 2 2 2 2 7 - 3600 2 2 2 2 3 3 5 5 - 3645 3 3 3 3 3 3 5 - 3675 3 5 5 7 7 - 3750 2 3 5 5 5 5 - 3780 2 2 3 3 3 5 7 - 3840 2 2 2 2 2 2 2 2 3 5 - 3888 2 2 2 2 3 3 3 3 3 - 3920 2 2 2 2 5 7 7 - 3969 3 3 3 3 7 7 - 4000 2 2 2 2 2 5 5 5 - 4032 2 2 2 2 2 2 3 3 7 - 4050 2 3 3 3 3 5 5 - 4096 2 2 2 2 2 2 2 2 2 2 2 2 - 4116 2 2 3 7 7 7 - 4200 2 2 2 3 5 5 7 - 4320 2 2 2 2 2 3 3 3 5 - 4374 2 3 3 3 3 3 3 3 - 4375 5 5 5 5 7 - 4410 2 3 3 5 7 7 - 4480 2 2 2 2 2 2 2 5 7 - 4500 2 2 3 3 5 5 5 - 4536 2 2 2 3 3 3 3 7 - 4608 2 2 2 2 2 2 2 2 2 3 3 - 4704 2 2 2 2 2 3 7 7 - 4725 3 3 3 5 5 7 - 4800 2 2 2 2 2 2 3 5 5 - 4802 2 7 7 7 7 - 4860 2 2 3 3 3 3 3 5 - 4900 2 2 5 5 7 7 - 5000 2 2 2 5 5 5 5 - 5040 2 2 2 2 3 3 5 7 - 5103 3 3 3 3 3 3 7 - 5120 2 2 2 2 2 2 2 2 2 2 5 - 5145 3 5 7 7 7 - 5184 2 2 2 2 2 2 3 3 3 3 - 5250 2 3 5 5 5 7 - 5292 2 2 3 3 3 7 7 - 5376 2 2 2 2 2 2 2 2 3 7 - 5400 2 2 2 3 3 3 5 5 - 5488 2 2 2 2 7 7 7 - 5600 2 2 2 2 2 5 5 7 - 5625 3 3 5 5 5 5 - 5670 2 3 3 3 3 5 7 - 5760 2 2 2 2 2 2 2 3 3 5 - 5832 2 2 2 3 3 3 3 3 3 - 5880 2 2 2 3 5 7 7 - 6000 2 2 2 2 3 5 5 5 - 6048 2 2 2 2 2 3 3 3 7 - 6075 3 3 3 3 3 5 5 - 6125 5 5 5 7 7 - 6144 2 2 2 2 2 2 2 2 2 2 2 3 - 6174 2 3 3 7 7 7 - 6250 2 5 5 5 5 5 - 6272 2 2 2 2 2 2 2 7 7 - 6300 2 2 3 3 5 5 7 - 6400 2 2 2 2 2 2 2 2 5 5 - 6480 2 2 2 2 3 3 3 3 5 - 6561 3 3 3 3 3 3 3 3 - 6615 3 3 3 5 7 7 - 6720 2 2 2 2 2 2 3 5 7 - 6750 2 3 3 3 5 5 5 - 6804 2 2 3 3 3 3 3 7 - 6860 2 2 5 7 7 7 - 6912 2 2 2 2 2 2 2 2 3 3 3 - 7000 2 2 2 5 5 5 7 - 7056 2 2 2 2 3 3 7 7 - 7168 2 2 2 2 2 2 2 2 2 2 7 - 7200 2 2 2 2 2 3 3 5 5 - 7203 3 7 7 7 7 - 7290 2 3 3 3 3 3 3 5 - 7350 2 3 5 5 7 7 - 7500 2 2 3 5 5 5 5 - 7560 2 2 2 3 3 3 5 7 - 7680 2 2 2 2 2 2 2 2 2 3 5 - 7776 2 2 2 2 2 3 3 3 3 3 - 7840 2 2 2 2 2 5 7 7 - 7875 3 3 5 5 5 7 - 7938 2 3 3 3 3 7 7 - 8000 2 2 2 2 2 2 5 5 5 - 8064 2 2 2 2 2 2 2 3 3 7 - 8100 2 2 3 3 3 3 5 5 - 8192 2 2 2 2 2 2 2 2 2 2 2 2 2 - 8232 2 2 2 3 7 7 7 - 8400 2 2 2 2 3 5 5 7 - 8505 3 3 3 3 3 5 7 - 8575 5 5 7 7 7 - 8640 2 2 2 2 2 2 3 3 3 5 - 8748 2 2 3 3 3 3 3 3 3 - 8750 2 5 5 5 5 7 - 8820 2 2 3 3 5 7 7 - 8960 2 2 2 2 2 2 2 2 5 7 - 9000 2 2 2 3 3 5 5 5 - 9072 2 2 2 2 3 3 3 3 7 - 9216 2 2 2 2 2 2 2 2 2 2 3 3 - 9261 3 3 3 7 7 7 - 9375 3 5 5 5 5 5 - 9408 2 2 2 2 2 2 3 7 7 - 9450 2 3 3 3 5 5 7 - 9600 2 2 2 2 2 2 2 3 5 5 - 9604 2 2 7 7 7 7 - 9720 2 2 2 3 3 3 3 3 5 - 9800 2 2 2 5 5 7 7 - 10000 2 2 2 2 5 5 5 5 - 10080 2 2 2 2 2 3 3 5 7 - 10125 3 3 3 3 5 5 5 - 10206 2 3 3 3 3 3 3 7 - 10240 2 2 2 2 2 2 2 2 2 2 2 5 - 10290 2 3 5 7 7 7 - 10368 2 2 2 2 2 2 2 3 3 3 3 - 10500 2 2 3 5 5 5 7 - 10584 2 2 2 3 3 3 7 7 - 10752 2 2 2 2 2 2 2 2 2 3 7 - 10800 2 2 2 2 3 3 3 5 5 - 10935 3 3 3 3 3 3 3 5 - 10976 2 2 2 2 2 7 7 7 - 11025 3 3 5 5 7 7 - 11200 2 2 2 2 2 2 5 5 7 - 11250 2 3 3 5 5 5 5 - 11340 2 2 3 3 3 3 5 7 - 11520 2 2 2 2 2 2 2 2 3 3 5 - 11664 2 2 2 2 3 3 3 3 3 3 - 11760 2 2 2 2 3 5 7 7 - 11907 3 3 3 3 3 7 7 - 12000 2 2 2 2 2 3 5 5 5 - 12005 5 7 7 7 7 - 12096 2 2 2 2 2 2 3 3 3 7 - 12150 2 3 3 3 3 3 5 5 - 12250 2 5 5 5 7 7 - 12288 2 2 2 2 2 2 2 2 2 2 2 2 3 - 12348 2 2 3 3 7 7 7 - 12500 2 2 5 5 5 5 5 - 12544 2 2 2 2 2 2 2 2 7 7 - 12600 2 2 2 3 3 5 5 7 - 12800 2 2 2 2 2 2 2 2 2 5 5 - 12960 2 2 2 2 2 3 3 3 3 5 - 13122 2 3 3 3 3 3 3 3 3 - 13125 3 5 5 5 5 7 - 13230 2 3 3 3 5 7 7 - 13440 2 2 2 2 2 2 2 3 5 7 - 13500 2 2 3 3 3 5 5 5 - 13608 2 2 2 3 3 3 3 3 7 - 13720 2 2 2 5 7 7 7 - 13824 2 2 2 2 2 2 2 2 2 3 3 3 - 14000 2 2 2 2 5 5 5 7 - 14112 2 2 2 2 2 3 3 7 7 - 14175 3 3 3 3 5 5 7 - 14336 2 2 2 2 2 2 2 2 2 2 2 7 - 14400 2 2 2 2 2 2 3 3 5 5 - 14406 2 3 7 7 7 7 - 14580 2 2 3 3 3 3 3 3 5 - 14700 2 2 3 5 5 7 7 - 15000 2 2 2 3 5 5 5 5 - 15120 2 2 2 2 3 3 3 5 7 - 15309 3 3 3 3 3 3 3 7 - 15360 2 2 2 2 2 2 2 2 2 2 3 5 - 15435 3 3 5 7 7 7 - 15552 2 2 2 2 2 2 3 3 3 3 3 - 15625 5 5 5 5 5 5 - 15680 2 2 2 2 2 2 5 7 7 - 15750 2 3 3 5 5 5 7 - 15876 2 2 3 3 3 3 7 7 - 16000 2 2 2 2 2 2 2 5 5 5 - 16128 2 2 2 2 2 2 2 2 3 3 7 - 16200 2 2 2 3 3 3 3 5 5 - 16384 2 2 2 2 2 2 2 2 2 2 2 2 2 2 - 16464 2 2 2 2 3 7 7 7 - 16800 2 2 2 2 2 3 5 5 7 - 16807 7 7 7 7 7 - 16875 3 3 3 5 5 5 5 - 17010 2 3 3 3 3 3 5 7 - 17150 2 5 5 7 7 7 - 17280 2 2 2 2 2 2 2 3 3 3 5 - 17496 2 2 2 3 3 3 3 3 3 3 - 17500 2 2 5 5 5 5 7 - 17640 2 2 2 3 3 5 7 7 - 17920 2 2 2 2 2 2 2 2 2 5 7 - 18000 2 2 2 2 3 3 5 5 5 - 18144 2 2 2 2 2 3 3 3 3 7 - 18225 3 3 3 3 3 3 5 5 - 18375 3 5 5 5 7 7 - 18432 2 2 2 2 2 2 2 2 2 2 2 3 3 - 18522 2 3 3 3 7 7 7 - 18750 2 3 5 5 5 5 5 - 18816 2 2 2 2 2 2 2 3 7 7 - 18900 2 2 3 3 3 5 5 7 - 19200 2 2 2 2 2 2 2 2 3 5 5 - 19208 2 2 2 7 7 7 7 - 19440 2 2 2 2 3 3 3 3 3 5 - 19600 2 2 2 2 5 5 7 7 - 19683 3 3 3 3 3 3 3 3 3 - 19845 3 3 3 3 5 7 7 - 20000 2 2 2 2 2 5 5 5 5 - 20160 2 2 2 2 2 2 3 3 5 7 - 20250 2 3 3 3 3 5 5 5 - 20412 2 2 3 3 3 3 3 3 7 - 20480 2 2 2 2 2 2 2 2 2 2 2 2 5 - 20580 2 2 3 5 7 7 7 - 20736 2 2 2 2 2 2 2 2 3 3 3 3 - 21000 2 2 2 3 5 5 5 7 - 21168 2 2 2 2 3 3 3 7 7 - 21504 2 2 2 2 2 2 2 2 2 2 3 7 - 21600 2 2 2 2 2 3 3 3 5 5 - 21609 3 3 7 7 7 7 - 21870 2 3 3 3 3 3 3 3 5 - 21875 5 5 5 5 5 7 - 21952 2 2 2 2 2 2 7 7 7 - 22050 2 3 3 5 5 7 7 - 22400 2 2 2 2 2 2 2 5 5 7 - 22500 2 2 3 3 5 5 5 5 - 22680 2 2 2 3 3 3 3 5 7 - 23040 2 2 2 2 2 2 2 2 2 3 3 5 - 23328 2 2 2 2 2 3 3 3 3 3 3 - 23520 2 2 2 2 2 3 5 7 7 - 23625 3 3 3 5 5 5 7 - 23814 2 3 3 3 3 3 7 7 - 24000 2 2 2 2 2 2 3 5 5 5 - 24010 2 5 7 7 7 7 - 24192 2 2 2 2 2 2 2 3 3 3 7 - 24300 2 2 3 3 3 3 3 5 5 - 24500 2 2 5 5 5 7 7 - 24576 2 2 2 2 2 2 2 2 2 2 2 2 2 3 - 24696 2 2 2 3 3 7 7 7 - 25000 2 2 2 5 5 5 5 5 - 25088 2 2 2 2 2 2 2 2 2 7 7 - 25200 2 2 2 2 3 3 5 5 7 - 25515 3 3 3 3 3 3 5 7 - 25600 2 2 2 2 2 2 2 2 2 2 5 5 - 25725 3 5 5 7 7 7 - 25920 2 2 2 2 2 2 3 3 3 3 5 - 26244 2 2 3 3 3 3 3 3 3 3 - 26250 2 3 5 5 5 5 7 - 26460 2 2 3 3 3 5 7 7 - 26880 2 2 2 2 2 2 2 2 3 5 7 - 27000 2 2 2 3 3 3 5 5 5 - 27216 2 2 2 2 3 3 3 3 3 7 - 27440 2 2 2 2 5 7 7 7 - 27648 2 2 2 2 2 2 2 2 2 2 3 3 3 - 27783 3 3 3 3 7 7 7 - 28000 2 2 2 2 2 5 5 5 7 - 28125 3 3 5 5 5 5 5 - 28224 2 2 2 2 2 2 3 3 7 7 - 28350 2 3 3 3 3 5 5 7 - 28672 2 2 2 2 2 2 2 2 2 2 2 2 7 - 28800 2 2 2 2 2 2 2 3 3 5 5 - 28812 2 2 3 7 7 7 7 - 29160 2 2 2 3 3 3 3 3 3 5 - 29400 2 2 2 3 5 5 7 7 - 30000 2 2 2 2 3 5 5 5 5 - 30240 2 2 2 2 2 3 3 3 5 7 - 30375 3 3 3 3 3 5 5 5 - 30618 2 3 3 3 3 3 3 3 7 - 30625 5 5 5 5 7 7 - 30720 2 2 2 2 2 2 2 2 2 2 2 3 5 - 30870 2 3 3 5 7 7 7 - 31104 2 2 2 2 2 2 2 3 3 3 3 3 - 31250 2 5 5 5 5 5 5 - 31360 2 2 2 2 2 2 2 5 7 7 - 31500 2 2 3 3 5 5 5 7 - 31752 2 2 2 3 3 3 3 7 7 - 32000 2 2 2 2 2 2 2 2 5 5 5 - 32256 2 2 2 2 2 2 2 2 2 3 3 7 - 32400 2 2 2 2 3 3 3 3 5 5 - 32768 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 - 32805 3 3 3 3 3 3 3 3 5 - 32928 2 2 2 2 2 3 7 7 7 - 33075 3 3 3 5 5 7 7 - 33600 2 2 2 2 2 2 3 5 5 7 - 33614 2 7 7 7 7 7 - 33750 2 3 3 3 5 5 5 5 - 34020 2 2 3 3 3 3 3 5 7 - 34300 2 2 5 5 7 7 7 - 34560 2 2 2 2 2 2 2 2 3 3 3 5 - 34992 2 2 2 2 3 3 3 3 3 3 3 - 35000 2 2 2 5 5 5 5 7 - 35280 2 2 2 2 3 3 5 7 7 - 35721 3 3 3 3 3 3 7 7 - 35840 2 2 2 2 2 2 2 2 2 2 5 7 - 36000 2 2 2 2 2 3 3 5 5 5 - 36015 3 5 7 7 7 7 - 36288 2 2 2 2 2 2 3 3 3 3 7 - 36450 2 3 3 3 3 3 3 5 5 - 36750 2 3 5 5 5 7 7 - 36864 2 2 2 2 2 2 2 2 2 2 2 2 3 3 - 37044 2 2 3 3 3 7 7 7 - 37500 2 2 3 5 5 5 5 5 - 37632 2 2 2 2 2 2 2 2 3 7 7 - 37800 2 2 2 3 3 3 5 5 7 - 38400 2 2 2 2 2 2 2 2 2 3 5 5 - 38416 2 2 2 2 7 7 7 7 - 38880 2 2 2 2 2 3 3 3 3 3 5 - 39200 2 2 2 2 2 5 5 7 7 - 39366 2 3 3 3 3 3 3 3 3 3 - 39375 3 3 5 5 5 5 7 - 39690 2 3 3 3 3 5 7 7 - 40000 2 2 2 2 2 2 5 5 5 5 - 40320 2 2 2 2 2 2 2 3 3 5 7 - 40500 2 2 3 3 3 3 5 5 5 - 40824 2 2 2 3 3 3 3 3 3 7 - 40960 2 2 2 2 2 2 2 2 2 2 2 2 2 5 - 41160 2 2 2 3 5 7 7 7 - 41472 2 2 2 2 2 2 2 2 2 3 3 3 3 - 42000 2 2 2 2 3 5 5 5 7 - 42336 2 2 2 2 2 3 3 3 7 7 - 42525 3 3 3 3 3 5 5 7 - 42875 5 5 5 7 7 7 - 43008 2 2 2 2 2 2 2 2 2 2 2 3 7 - 43200 2 2 2 2 2 2 3 3 3 5 5 - 43218 2 3 3 7 7 7 7 - 43740 2 2 3 3 3 3 3 3 3 5 - 43750 2 5 5 5 5 5 7 - 43904 2 2 2 2 2 2 2 7 7 7 - 44100 2 2 3 3 5 5 7 7 - 44800 2 2 2 2 2 2 2 2 5 5 7 - 45000 2 2 2 3 3 5 5 5 5 - 45360 2 2 2 2 3 3 3 3 5 7 - 45927 3 3 3 3 3 3 3 3 7 - 46080 2 2 2 2 2 2 2 2 2 2 3 3 5 - 46305 3 3 3 5 7 7 7 - 46656 2 2 2 2 2 2 3 3 3 3 3 3 - 46875 3 5 5 5 5 5 5 - 47040 2 2 2 2 2 2 3 5 7 7 - 47250 2 3 3 3 5 5 5 7 - 47628 2 2 3 3 3 3 3 7 7 - 48000 2 2 2 2 2 2 2 3 5 5 5 - 48020 2 2 5 7 7 7 7 - 48384 2 2 2 2 2 2 2 2 3 3 3 7 - 48600 2 2 2 3 3 3 3 3 5 5 - 49000 2 2 2 5 5 5 7 7 - 49152 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 - 49392 2 2 2 2 3 3 7 7 7 - 50000 2 2 2 2 5 5 5 5 5 - 50176 2 2 2 2 2 2 2 2 2 2 7 7 - 50400 2 2 2 2 2 3 3 5 5 7 - 50421 3 7 7 7 7 7 - 50625 3 3 3 3 5 5 5 5 - 51030 2 3 3 3 3 3 3 5 7 - 51200 2 2 2 2 2 2 2 2 2 2 2 5 5 - 51450 2 3 5 5 7 7 7 - 51840 2 2 2 2 2 2 2 3 3 3 3 5 - 52488 2 2 2 3 3 3 3 3 3 3 3 - 52500 2 2 3 5 5 5 5 7 - 52920 2 2 2 3 3 3 5 7 7 - 53760 2 2 2 2 2 2 2 2 2 3 5 7 - 54000 2 2 2 2 3 3 3 5 5 5 - 54432 2 2 2 2 2 3 3 3 3 3 7 - 54675 3 3 3 3 3 3 3 5 5 - 54880 2 2 2 2 2 5 7 7 7 - 55125 3 3 5 5 5 7 7 - 55296 2 2 2 2 2 2 2 2 2 2 2 3 3 3 - 55566 2 3 3 3 3 7 7 7 - 56000 2 2 2 2 2 2 5 5 5 7 - 56250 2 3 3 5 5 5 5 5 - 56448 2 2 2 2 2 2 2 3 3 7 7 - 56700 2 2 3 3 3 3 5 5 7 - 57344 2 2 2 2 2 2 2 2 2 2 2 2 2 7 - 57600 2 2 2 2 2 2 2 2 3 3 5 5 - 57624 2 2 2 3 7 7 7 7 - 58320 2 2 2 2 3 3 3 3 3 3 5 - 58800 2 2 2 2 3 5 5 7 7 - 59049 3 3 3 3 3 3 3 3 3 3 - 59535 3 3 3 3 3 5 7 7 - 60000 2 2 2 2 2 3 5 5 5 5 - 60025 5 5 7 7 7 7 - 60480 2 2 2 2 2 2 3 3 3 5 7 - 60750 2 3 3 3 3 3 5 5 5 - 61236 2 2 3 3 3 3 3 3 3 7 - 61250 2 5 5 5 5 7 7 - 61440 2 2 2 2 2 2 2 2 2 2 2 2 3 5 - 61740 2 2 3 3 5 7 7 7 - 62208 2 2 2 2 2 2 2 2 3 3 3 3 3 - 62500 2 2 5 5 5 5 5 5 - 62720 2 2 2 2 2 2 2 2 5 7 7 - 63000 2 2 2 3 3 5 5 5 7 - 63504 2 2 2 2 3 3 3 3 7 7 - 64000 2 2 2 2 2 2 2 2 2 5 5 5 - 64512 2 2 2 2 2 2 2 2 2 2 3 3 7 - 64800 2 2 2 2 2 3 3 3 3 5 5 - 64827 3 3 3 7 7 7 7 - 65536 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 - 65610 2 3 3 3 3 3 3 3 3 5 - 65625 3 5 5 5 5 5 7 - 65856 2 2 2 2 2 2 3 7 7 7 - 66150 2 3 3 3 5 5 7 7 - 67200 2 2 2 2 2 2 2 3 5 5 7 - 67228 2 2 7 7 7 7 7 - 67500 2 2 3 3 3 5 5 5 5 - 68040 2 2 2 3 3 3 3 3 5 7 - 68600 2 2 2 5 5 7 7 7 - 69120 2 2 2 2 2 2 2 2 2 3 3 3 5 - 69984 2 2 2 2 2 3 3 3 3 3 3 3 - 70000 2 2 2 2 5 5 5 5 7 - 70560 2 2 2 2 2 3 3 5 7 7 - 70875 3 3 3 3 5 5 5 7 - 71442 2 3 3 3 3 3 3 7 7 - 71680 2 2 2 2 2 2 2 2 2 2 2 5 7 - 72000 2 2 2 2 2 2 3 3 5 5 5 - 72030 2 3 5 7 7 7 7 - 72576 2 2 2 2 2 2 2 3 3 3 3 7 - 72900 2 2 3 3 3 3 3 3 5 5 - 73500 2 2 3 5 5 5 7 7 - 73728 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 - 74088 2 2 2 3 3 3 7 7 7 - 75000 2 2 2 3 5 5 5 5 5 - 75264 2 2 2 2 2 2 2 2 2 3 7 7 - 75600 2 2 2 2 3 3 3 5 5 7 - 76545 3 3 3 3 3 3 3 5 7 - 76800 2 2 2 2 2 2 2 2 2 2 3 5 5 - 76832 2 2 2 2 2 7 7 7 7 - 77175 3 3 5 5 7 7 7 - 77760 2 2 2 2 2 2 3 3 3 3 3 5 - 78125 5 5 5 5 5 5 5 - 78400 2 2 2 2 2 2 5 5 7 7 - 78732 2 2 3 3 3 3 3 3 3 3 3 - 78750 2 3 3 5 5 5 5 7 - 79380 2 2 3 3 3 3 5 7 7 - 80000 2 2 2 2 2 2 2 5 5 5 5 - 80640 2 2 2 2 2 2 2 2 3 3 5 7 - 81000 2 2 2 3 3 3 3 5 5 5 - 81648 2 2 2 2 3 3 3 3 3 3 7 - 81920 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 - 82320 2 2 2 2 3 5 7 7 7 - 82944 2 2 2 2 2 2 2 2 2 2 3 3 3 3 - 83349 3 3 3 3 3 7 7 7 - 84000 2 2 2 2 2 3 5 5 5 7 - 84035 5 7 7 7 7 7 - 84375 3 3 3 5 5 5 5 5 - 84672 2 2 2 2 2 2 3 3 3 7 7 - 85050 2 3 3 3 3 3 5 5 7 - 85750 2 5 5 5 7 7 7 - 86016 2 2 2 2 2 2 2 2 2 2 2 2 3 7 - 86400 2 2 2 2 2 2 2 3 3 3 5 5 - 86436 2 2 3 3 7 7 7 7 - 87480 2 2 2 3 3 3 3 3 3 3 5 - 87500 2 2 5 5 5 5 5 7 - 87808 2 2 2 2 2 2 2 2 7 7 7 - 88200 2 2 2 3 3 5 5 7 7 - 89600 2 2 2 2 2 2 2 2 2 5 5 7 - 90000 2 2 2 2 3 3 5 5 5 5 - 90720 2 2 2 2 2 3 3 3 3 5 7 - 91125 3 3 3 3 3 3 5 5 5 - 91854 2 3 3 3 3 3 3 3 3 7 - 91875 3 5 5 5 5 7 7 - 92160 2 2 2 2 2 2 2 2 2 2 2 3 3 5 - 92610 2 3 3 3 5 7 7 7 - 93312 2 2 2 2 2 2 2 3 3 3 3 3 3 - 93750 2 3 5 5 5 5 5 5 - 94080 2 2 2 2 2 2 2 3 5 7 7 - 94500 2 2 3 3 3 5 5 5 7 - 95256 2 2 2 3 3 3 3 3 7 7 - 96000 2 2 2 2 2 2 2 2 3 5 5 5 - 96040 2 2 2 5 7 7 7 7 - 96768 2 2 2 2 2 2 2 2 2 3 3 3 7 - 97200 2 2 2 2 3 3 3 3 3 5 5 - 98000 2 2 2 2 5 5 5 7 7 - 98304 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 - 98415 3 3 3 3 3 3 3 3 3 5 - 98784 2 2 2 2 2 3 3 7 7 7 - 99225 3 3 3 3 5 5 7 7 - 100000 2 2 2 2 2 5 5 5 5 5 - 100352 2 2 2 2 2 2 2 2 2 2 2 7 7 - 100800 2 2 2 2 2 2 3 3 5 5 7 - 100842 2 3 7 7 7 7 7 - 101250 2 3 3 3 3 5 5 5 5 - 102060 2 2 3 3 3 3 3 3 5 7 - 102400 2 2 2 2 2 2 2 2 2 2 2 2 5 5 - 102900 2 2 3 5 5 7 7 7 - 103680 2 2 2 2 2 2 2 2 3 3 3 3 5 - 104976 2 2 2 2 3 3 3 3 3 3 3 3 - 105000 2 2 2 3 5 5 5 5 7 - 105840 2 2 2 2 3 3 3 5 7 7 - 107163 3 3 3 3 3 3 3 7 7 - 107520 2 2 2 2 2 2 2 2 2 2 3 5 7 - 108000 2 2 2 2 2 3 3 3 5 5 5 - 108045 3 3 5 7 7 7 7 - 108864 2 2 2 2 2 2 3 3 3 3 3 7 - 109350 2 3 3 3 3 3 3 3 5 5 - 109375 5 5 5 5 5 5 7 - 109760 2 2 2 2 2 2 5 7 7 7 - 110250 2 3 3 5 5 5 7 7 - 110592 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 - 111132 2 2 3 3 3 3 7 7 7 - 112000 2 2 2 2 2 2 2 5 5 5 7 - 112500 2 2 3 3 5 5 5 5 5 - 112896 2 2 2 2 2 2 2 2 3 3 7 7 - 113400 2 2 2 3 3 3 3 5 5 7 - 114688 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 - 115200 2 2 2 2 2 2 2 2 2 3 3 5 5 - 115248 2 2 2 2 3 7 7 7 7 - 116640 2 2 2 2 2 3 3 3 3 3 3 5 - 117600 2 2 2 2 2 3 5 5 7 7 - 117649 7 7 7 7 7 7 - 118098 2 3 3 3 3 3 3 3 3 3 3 - 118125 3 3 3 5 5 5 5 7 - 119070 2 3 3 3 3 3 5 7 7 - 120000 2 2 2 2 2 2 3 5 5 5 5 - 120050 2 5 5 7 7 7 7 - 120960 2 2 2 2 2 2 2 3 3 3 5 7 - 121500 2 2 3 3 3 3 3 5 5 5 - 122472 2 2 2 3 3 3 3 3 3 3 7 - 122500 2 2 5 5 5 5 7 7 - 122880 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 - 123480 2 2 2 3 3 5 7 7 7 - 124416 2 2 2 2 2 2 2 2 2 3 3 3 3 3 - 125000 2 2 2 5 5 5 5 5 5 - 125440 2 2 2 2 2 2 2 2 2 5 7 7 - 126000 2 2 2 2 3 3 5 5 5 7 - 127008 2 2 2 2 2 3 3 3 3 7 7 - 127575 3 3 3 3 3 3 5 5 7 - 128000 2 2 2 2 2 2 2 2 2 2 5 5 5 - 128625 3 5 5 5 7 7 7 - 129024 2 2 2 2 2 2 2 2 2 2 2 3 3 7 - 129600 2 2 2 2 2 2 3 3 3 3 5 5 - 129654 2 3 3 3 7 7 7 7 - 131072 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 - 131220 2 2 3 3 3 3 3 3 3 3 5 - 131250 2 3 5 5 5 5 5 7 - 131712 2 2 2 2 2 2 2 3 7 7 7 - 132300 2 2 3 3 3 5 5 7 7 - 134400 2 2 2 2 2 2 2 2 3 5 5 7 - 134456 2 2 2 7 7 7 7 7 - 135000 2 2 2 3 3 3 5 5 5 5 - 136080 2 2 2 2 3 3 3 3 3 5 7 - 137200 2 2 2 2 5 5 7 7 7 - 137781 3 3 3 3 3 3 3 3 3 7 - 138240 2 2 2 2 2 2 2 2 2 2 3 3 3 5 - 138915 3 3 3 3 5 7 7 7 - 139968 2 2 2 2 2 2 3 3 3 3 3 3 3 - 140000 2 2 2 2 2 5 5 5 5 7 - 140625 3 3 5 5 5 5 5 5 - 141120 2 2 2 2 2 2 3 3 5 7 7 - 141750 2 3 3 3 3 5 5 5 7 - 142884 2 2 3 3 3 3 3 3 7 7 - 143360 2 2 2 2 2 2 2 2 2 2 2 2 5 7 - 144000 2 2 2 2 2 2 2 3 3 5 5 5 - 144060 2 2 3 5 7 7 7 7 - 145152 2 2 2 2 2 2 2 2 3 3 3 3 7 - 145800 2 2 2 3 3 3 3 3 3 5 5 - 147000 2 2 2 3 5 5 5 7 7 - 147456 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 - 148176 2 2 2 2 3 3 3 7 7 7 - 150000 2 2 2 2 3 5 5 5 5 5 - 150528 2 2 2 2 2 2 2 2 2 2 3 7 7 - 151200 2 2 2 2 2 3 3 3 5 5 7 - 151263 3 3 7 7 7 7 7 - 151875 3 3 3 3 3 5 5 5 5 - 153090 2 3 3 3 3 3 3 3 5 7 - 153125 5 5 5 5 5 7 7 - 153600 2 2 2 2 2 2 2 2 2 2 2 3 5 5 - 153664 2 2 2 2 2 2 7 7 7 7 - 154350 2 3 3 5 5 7 7 7 - 155520 2 2 2 2 2 2 2 3 3 3 3 3 5 - 156250 2 5 5 5 5 5 5 5 - 156800 2 2 2 2 2 2 2 5 5 7 7 - 157464 2 2 2 3 3 3 3 3 3 3 3 3 - 157500 2 2 3 3 5 5 5 5 7 - 158760 2 2 2 3 3 3 3 5 7 7 - 160000 2 2 2 2 2 2 2 2 5 5 5 5 - 161280 2 2 2 2 2 2 2 2 2 3 3 5 7 - 162000 2 2 2 2 3 3 3 3 5 5 5 - 163296 2 2 2 2 2 3 3 3 3 3 3 7 - 163840 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 - 164025 3 3 3 3 3 3 3 3 5 5 - 164640 2 2 2 2 2 3 5 7 7 7 - 165375 3 3 3 5 5 5 7 7 - 165888 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 - 166698 2 3 3 3 3 3 7 7 7 - 168000 2 2 2 2 2 2 3 5 5 5 7 - 168070 2 5 7 7 7 7 7 - 168750 2 3 3 3 5 5 5 5 5 - 169344 2 2 2 2 2 2 2 3 3 3 7 7 - 170100 2 2 3 3 3 3 3 5 5 7 - 171500 2 2 5 5 5 7 7 7 - 172032 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 - 172800 2 2 2 2 2 2 2 2 3 3 3 5 5 - 172872 2 2 2 3 3 7 7 7 7 - 174960 2 2 2 2 3 3 3 3 3 3 3 5 - 175000 2 2 2 5 5 5 5 5 7 - 175616 2 2 2 2 2 2 2 2 2 7 7 7 - 176400 2 2 2 2 3 3 5 5 7 7 - 177147 3 3 3 3 3 3 3 3 3 3 3 - 178605 3 3 3 3 3 3 5 7 7 - 179200 2 2 2 2 2 2 2 2 2 2 5 5 7 - 180000 2 2 2 2 2 3 3 5 5 5 5 - 180075 3 5 5 7 7 7 7 - 181440 2 2 2 2 2 2 3 3 3 3 5 7 - 182250 2 3 3 3 3 3 3 5 5 5 - 183708 2 2 3 3 3 3 3 3 3 3 7 - 183750 2 3 5 5 5 5 7 7 - 184320 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 - 185220 2 2 3 3 3 5 7 7 7 - 186624 2 2 2 2 2 2 2 2 3 3 3 3 3 3 - 187500 2 2 3 5 5 5 5 5 5 - 188160 2 2 2 2 2 2 2 2 3 5 7 7 - 189000 2 2 2 3 3 3 5 5 5 7 - 190512 2 2 2 2 3 3 3 3 3 7 7 - 192000 2 2 2 2 2 2 2 2 2 3 5 5 5 - 192080 2 2 2 2 5 7 7 7 7 - 193536 2 2 2 2 2 2 2 2 2 2 3 3 3 7 - 194400 2 2 2 2 2 3 3 3 3 3 5 5 - 194481 3 3 3 3 7 7 7 7 - 196000 2 2 2 2 2 5 5 5 7 7 - 196608 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 - 196830 2 3 3 3 3 3 3 3 3 3 5 - 196875 3 3 5 5 5 5 5 7 - 197568 2 2 2 2 2 2 3 3 7 7 7 - 198450 2 3 3 3 3 5 5 7 7 - 200000 2 2 2 2 2 2 5 5 5 5 5 - 200704 2 2 2 2 2 2 2 2 2 2 2 2 7 7 - 201600 2 2 2 2 2 2 2 3 3 5 5 7 - 201684 2 2 3 7 7 7 7 7 - 202500 2 2 3 3 3 3 5 5 5 5 - 204120 2 2 2 3 3 3 3 3 3 5 7 - 204800 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 - 205800 2 2 2 3 5 5 7 7 7 - 207360 2 2 2 2 2 2 2 2 2 3 3 3 3 5 - 209952 2 2 2 2 2 3 3 3 3 3 3 3 3 - 210000 2 2 2 2 3 5 5 5 5 7 - 211680 2 2 2 2 2 3 3 3 5 7 7 - 212625 3 3 3 3 3 5 5 5 7 - 214326 2 3 3 3 3 3 3 3 7 7 - 214375 5 5 5 5 7 7 7 - 215040 2 2 2 2 2 2 2 2 2 2 2 3 5 7 - 216000 2 2 2 2 2 2 3 3 3 5 5 5 - 216090 2 3 3 5 7 7 7 7 - 217728 2 2 2 2 2 2 2 3 3 3 3 3 7 - 218700 2 2 3 3 3 3 3 3 3 5 5 - 218750 2 5 5 5 5 5 5 7 - 219520 2 2 2 2 2 2 2 5 7 7 7 - 220500 2 2 3 3 5 5 5 7 7 - 221184 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 - 222264 2 2 2 3 3 3 3 7 7 7 - 224000 2 2 2 2 2 2 2 2 5 5 5 7 - 225000 2 2 2 3 3 5 5 5 5 5 - 225792 2 2 2 2 2 2 2 2 2 3 3 7 7 - 226800 2 2 2 2 3 3 3 3 5 5 7 - 229376 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 - 229635 3 3 3 3 3 3 3 3 5 7 - 230400 2 2 2 2 2 2 2 2 2 2 3 3 5 5 - 230496 2 2 2 2 2 3 7 7 7 7 - 231525 3 3 3 5 5 7 7 7 - 233280 2 2 2 2 2 2 3 3 3 3 3 3 5 - 234375 3 5 5 5 5 5 5 5 - 235200 2 2 2 2 2 2 3 5 5 7 7 - 235298 2 7 7 7 7 7 7 - 236196 2 2 3 3 3 3 3 3 3 3 3 3 - 236250 2 3 3 3 5 5 5 5 7 - 238140 2 2 3 3 3 3 3 5 7 7 - 240000 2 2 2 2 2 2 2 3 5 5 5 5 - 240100 2 2 5 5 7 7 7 7 - 241920 2 2 2 2 2 2 2 2 3 3 3 5 7 - 243000 2 2 2 3 3 3 3 3 5 5 5 - 244944 2 2 2 2 3 3 3 3 3 3 3 7 - 245000 2 2 2 5 5 5 5 7 7 - 245760 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 - 246960 2 2 2 2 3 3 5 7 7 7 - 248832 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 - 250000 2 2 2 2 5 5 5 5 5 5 - 250047 3 3 3 3 3 3 7 7 7 - 250880 2 2 2 2 2 2 2 2 2 2 5 7 7 - 252000 2 2 2 2 2 3 3 5 5 5 7 - 252105 3 5 7 7 7 7 7 - 253125 3 3 3 3 5 5 5 5 5 - 254016 2 2 2 2 2 2 3 3 3 3 7 7 - 255150 2 3 3 3 3 3 3 5 5 7 - 256000 2 2 2 2 2 2 2 2 2 2 2 5 5 5 - 257250 2 3 5 5 5 7 7 7 - 258048 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 - 259200 2 2 2 2 2 2 2 3 3 3 3 5 5 - 259308 2 2 3 3 3 7 7 7 7 - 262144 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 - 262440 2 2 2 3 3 3 3 3 3 3 3 5 - 262500 2 2 3 5 5 5 5 5 7 - 263424 2 2 2 2 2 2 2 2 3 7 7 7 - 264600 2 2 2 3 3 3 5 5 7 7 - 268800 2 2 2 2 2 2 2 2 2 3 5 5 7 - 268912 2 2 2 2 7 7 7 7 7 - 270000 2 2 2 2 3 3 3 5 5 5 5 - 272160 2 2 2 2 2 3 3 3 3 3 5 7 - 273375 3 3 3 3 3 3 3 5 5 5 - 274400 2 2 2 2 2 5 5 7 7 7 - 275562 2 3 3 3 3 3 3 3 3 3 7 - 275625 3 3 5 5 5 5 7 7 - 276480 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 - 277830 2 3 3 3 3 5 7 7 7 - 279936 2 2 2 2 2 2 2 3 3 3 3 3 3 3 - 280000 2 2 2 2 2 2 5 5 5 5 7 - 281250 2 3 3 5 5 5 5 5 5 - 282240 2 2 2 2 2 2 2 3 3 5 7 7 - 283500 2 2 3 3 3 3 5 5 5 7 - 285768 2 2 2 3 3 3 3 3 3 7 7 - 286720 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 - 288000 2 2 2 2 2 2 2 2 3 3 5 5 5 - 288120 2 2 2 3 5 7 7 7 7 - 290304 2 2 2 2 2 2 2 2 2 3 3 3 3 7 - 291600 2 2 2 2 3 3 3 3 3 3 5 5 - 294000 2 2 2 2 3 5 5 5 7 7 - 294912 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 - 295245 3 3 3 3 3 3 3 3 3 3 5 - 296352 2 2 2 2 2 3 3 3 7 7 7 - 297675 3 3 3 3 3 5 5 7 7 - 300000 2 2 2 2 2 3 5 5 5 5 5 - 300125 5 5 5 7 7 7 7 - 301056 2 2 2 2 2 2 2 2 2 2 2 3 7 7 - 302400 2 2 2 2 2 2 3 3 3 5 5 7 - 302526 2 3 3 7 7 7 7 7 - 303750 2 3 3 3 3 3 5 5 5 5 - 306180 2 2 3 3 3 3 3 3 3 5 7 - 306250 2 5 5 5 5 5 7 7 - 307200 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 - 307328 2 2 2 2 2 2 2 7 7 7 7 - 308700 2 2 3 3 5 5 7 7 7 - 311040 2 2 2 2 2 2 2 2 3 3 3 3 3 5 - 312500 2 2 5 5 5 5 5 5 5 - 313600 2 2 2 2 2 2 2 2 5 5 7 7 - 314928 2 2 2 2 3 3 3 3 3 3 3 3 3 - 315000 2 2 2 3 3 5 5 5 5 7 - 317520 2 2 2 2 3 3 3 3 5 7 7 - 320000 2 2 2 2 2 2 2 2 2 5 5 5 5 - 321489 3 3 3 3 3 3 3 3 7 7 - 322560 2 2 2 2 2 2 2 2 2 2 3 3 5 7 - 324000 2 2 2 2 2 3 3 3 3 5 5 5 - 324135 3 3 3 5 7 7 7 7 - 326592 2 2 2 2 2 2 3 3 3 3 3 3 7 - 327680 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 - 328050 2 3 3 3 3 3 3 3 3 5 5 - 328125 3 5 5 5 5 5 5 7 - 329280 2 2 2 2 2 2 3 5 7 7 7 - 330750 2 3 3 3 5 5 5 7 7 - 331776 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 - 333396 2 2 3 3 3 3 3 7 7 7 - 336000 2 2 2 2 2 2 2 3 5 5 5 7 - 336140 2 2 5 7 7 7 7 7 - 337500 2 2 3 3 3 5 5 5 5 5 - 338688 2 2 2 2 2 2 2 2 3 3 3 7 7 - 340200 2 2 2 3 3 3 3 3 5 5 7 - 343000 2 2 2 5 5 5 7 7 7 - 344064 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 - 345600 2 2 2 2 2 2 2 2 2 3 3 3 5 5 - 345744 2 2 2 2 3 3 7 7 7 7 - 349920 2 2 2 2 2 3 3 3 3 3 3 3 5 - 350000 2 2 2 2 5 5 5 5 5 7 - 351232 2 2 2 2 2 2 2 2 2 2 7 7 7 - 352800 2 2 2 2 2 3 3 5 5 7 7 - 352947 3 7 7 7 7 7 7 - 354294 2 3 3 3 3 3 3 3 3 3 3 3 - 354375 3 3 3 3 5 5 5 5 7 - 357210 2 3 3 3 3 3 3 5 7 7 - 358400 2 2 2 2 2 2 2 2 2 2 2 5 5 7 - 360000 2 2 2 2 2 2 3 3 5 5 5 5 - 360150 2 3 5 5 7 7 7 7 - 362880 2 2 2 2 2 2 2 3 3 3 3 5 7 - 364500 2 2 3 3 3 3 3 3 5 5 5 - 367416 2 2 2 3 3 3 3 3 3 3 3 7 - 367500 2 2 3 5 5 5 5 7 7 - 368640 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 - 370440 2 2 2 3 3 3 5 7 7 7 - 373248 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 - 375000 2 2 2 3 5 5 5 5 5 5 - 376320 2 2 2 2 2 2 2 2 2 3 5 7 7 - 378000 2 2 2 2 3 3 3 5 5 5 7 - 381024 2 2 2 2 2 3 3 3 3 3 7 7 - 382725 3 3 3 3 3 3 3 5 5 7 - 384000 2 2 2 2 2 2 2 2 2 2 3 5 5 5 - 384160 2 2 2 2 2 5 7 7 7 7 - 385875 3 3 5 5 5 7 7 7 - 387072 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 - 388800 2 2 2 2 2 2 3 3 3 3 3 5 5 - 388962 2 3 3 3 3 7 7 7 7 - 390625 5 5 5 5 5 5 5 5 - 392000 2 2 2 2 2 2 5 5 5 7 7 - 393216 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 - 393660 2 2 3 3 3 3 3 3 3 3 3 5 - 393750 2 3 3 5 5 5 5 5 7 - 395136 2 2 2 2 2 2 2 3 3 7 7 7 - 396900 2 2 3 3 3 3 5 5 7 7 - 400000 2 2 2 2 2 2 2 5 5 5 5 5 - 401408 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 - 403200 2 2 2 2 2 2 2 2 3 3 5 5 7 - 403368 2 2 2 3 7 7 7 7 7 - 405000 2 2 2 3 3 3 3 5 5 5 5 - 408240 2 2 2 2 3 3 3 3 3 3 5 7 - 409600 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 - 411600 2 2 2 2 3 5 5 7 7 7 - 413343 3 3 3 3 3 3 3 3 3 3 7 - 414720 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 - 416745 3 3 3 3 3 5 7 7 7 - 419904 2 2 2 2 2 2 3 3 3 3 3 3 3 3 - 420000 2 2 2 2 2 3 5 5 5 5 7 - 420175 5 5 7 7 7 7 7 - 421875 3 3 3 5 5 5 5 5 5 - 423360 2 2 2 2 2 2 3 3 3 5 7 7 - 425250 2 3 3 3 3 3 5 5 5 7 - 428652 2 2 3 3 3 3 3 3 3 7 7 - 428750 2 5 5 5 5 7 7 7 - 430080 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 - 432000 2 2 2 2 2 2 2 3 3 3 5 5 5 - 432180 2 2 3 3 5 7 7 7 7 - 435456 2 2 2 2 2 2 2 2 3 3 3 3 3 7 - 437400 2 2 2 3 3 3 3 3 3 3 5 5 - 437500 2 2 5 5 5 5 5 5 7 - 439040 2 2 2 2 2 2 2 2 5 7 7 7 - 441000 2 2 2 3 3 5 5 5 7 7 - 442368 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 - 444528 2 2 2 2 3 3 3 3 7 7 7 - 448000 2 2 2 2 2 2 2 2 2 5 5 5 7 - 450000 2 2 2 2 3 3 5 5 5 5 5 - 451584 2 2 2 2 2 2 2 2 2 2 3 3 7 7 - 453600 2 2 2 2 2 3 3 3 3 5 5 7 - 453789 3 3 3 7 7 7 7 7 - 455625 3 3 3 3 3 3 5 5 5 5 - 458752 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 - 459270 2 3 3 3 3 3 3 3 3 5 7 - 459375 3 5 5 5 5 5 7 7 - 460800 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 - 460992 2 2 2 2 2 2 3 7 7 7 7 - 463050 2 3 3 3 5 5 7 7 7 - 466560 2 2 2 2 2 2 2 3 3 3 3 3 3 5 - 468750 2 3 5 5 5 5 5 5 5 - 470400 2 2 2 2 2 2 2 3 5 5 7 7 - 470596 2 2 7 7 7 7 7 7 - 472392 2 2 2 3 3 3 3 3 3 3 3 3 3 - 472500 2 2 3 3 3 5 5 5 5 7 - 476280 2 2 2 3 3 3 3 3 5 7 7 - 480000 2 2 2 2 2 2 2 2 3 5 5 5 5 - 480200 2 2 2 5 5 7 7 7 7 - 483840 2 2 2 2 2 2 2 2 2 3 3 3 5 7 - 486000 2 2 2 2 3 3 3 3 3 5 5 5 - 489888 2 2 2 2 2 3 3 3 3 3 3 3 7 - 490000 2 2 2 2 5 5 5 5 7 7 - 491520 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 - 492075 3 3 3 3 3 3 3 3 3 5 5 - 493920 2 2 2 2 2 3 3 5 7 7 7 - 496125 3 3 3 3 5 5 5 7 7 - 497664 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 - 500000 2 2 2 2 2 5 5 5 5 5 5 - 500094 2 3 3 3 3 3 3 7 7 7 - 501760 2 2 2 2 2 2 2 2 2 2 2 5 7 7 - 504000 2 2 2 2 2 2 3 3 5 5 5 7 - 504210 2 3 5 7 7 7 7 7 - 506250 2 3 3 3 3 5 5 5 5 5 - 508032 2 2 2 2 2 2 2 3 3 3 3 7 7 - 510300 2 2 3 3 3 3 3 3 5 5 7 - 512000 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 - 514500 2 2 3 5 5 5 7 7 7 - 516096 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 - 518400 2 2 2 2 2 2 2 2 3 3 3 3 5 5 - 518616 2 2 2 3 3 3 7 7 7 7 - 524288 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 - 524880 2 2 2 2 3 3 3 3 3 3 3 3 5 - 525000 2 2 2 3 5 5 5 5 5 7 - 526848 2 2 2 2 2 2 2 2 2 3 7 7 7 - 529200 2 2 2 2 3 3 3 5 5 7 7 - 531441 3 3 3 3 3 3 3 3 3 3 3 3 - 535815 3 3 3 3 3 3 3 5 7 7 - 537600 2 2 2 2 2 2 2 2 2 2 3 5 5 7 - 537824 2 2 2 2 2 7 7 7 7 7 - 540000 2 2 2 2 2 3 3 3 5 5 5 5 - 540225 3 3 5 5 7 7 7 7 - 544320 2 2 2 2 2 2 3 3 3 3 3 5 7 - 546750 2 3 3 3 3 3 3 3 5 5 5 - 546875 5 5 5 5 5 5 5 7 - 548800 2 2 2 2 2 2 5 5 7 7 7 - 551124 2 2 3 3 3 3 3 3 3 3 3 7 - 551250 2 3 3 5 5 5 5 7 7 - 552960 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 - 555660 2 2 3 3 3 3 5 7 7 7 - 559872 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 - 560000 2 2 2 2 2 2 2 5 5 5 5 7 - 562500 2 2 3 3 5 5 5 5 5 5 - 564480 2 2 2 2 2 2 2 2 3 3 5 7 7 - 567000 2 2 2 3 3 3 3 5 5 5 7 - 571536 2 2 2 2 3 3 3 3 3 3 7 7 - 573440 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 - 576000 2 2 2 2 2 2 2 2 2 3 3 5 5 5 - 576240 2 2 2 2 3 5 7 7 7 7 - 580608 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 - 583200 2 2 2 2 2 3 3 3 3 3 3 5 5 - 583443 3 3 3 3 3 7 7 7 7 - 588000 2 2 2 2 2 3 5 5 5 7 7 - 588245 5 7 7 7 7 7 7 - 589824 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 - 590490 2 3 3 3 3 3 3 3 3 3 3 5 - 590625 3 3 3 5 5 5 5 5 7 - 592704 2 2 2 2 2 2 3 3 3 7 7 7 - 595350 2 3 3 3 3 3 5 5 7 7 - 600000 2 2 2 2 2 2 3 5 5 5 5 5 - 600250 2 5 5 5 7 7 7 7 - 602112 2 2 2 2 2 2 2 2 2 2 2 2 3 7 7 - 604800 2 2 2 2 2 2 2 3 3 3 5 5 7 - 605052 2 2 3 3 7 7 7 7 7 - 607500 2 2 3 3 3 3 3 5 5 5 5 - 612360 2 2 2 3 3 3 3 3 3 3 5 7 - 612500 2 2 5 5 5 5 5 7 7 - 614400 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 - 614656 2 2 2 2 2 2 2 2 7 7 7 7 - 617400 2 2 2 3 3 5 5 7 7 7 - 622080 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 - 625000 2 2 2 5 5 5 5 5 5 5 - 627200 2 2 2 2 2 2 2 2 2 5 5 7 7 - 629856 2 2 2 2 2 3 3 3 3 3 3 3 3 3 - 630000 2 2 2 2 3 3 5 5 5 5 7 - 635040 2 2 2 2 2 3 3 3 3 5 7 7 - 637875 3 3 3 3 3 3 5 5 5 7 - 640000 2 2 2 2 2 2 2 2 2 2 5 5 5 5 - 642978 2 3 3 3 3 3 3 3 3 7 7 - 643125 3 5 5 5 5 7 7 7 - 645120 2 2 2 2 2 2 2 2 2 2 2 3 3 5 7 - 648000 2 2 2 2 2 2 3 3 3 3 5 5 5 - 648270 2 3 3 3 5 7 7 7 7 - 653184 2 2 2 2 2 2 2 3 3 3 3 3 3 7 - 655360 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 - 656100 2 2 3 3 3 3 3 3 3 3 5 5 - 656250 2 3 5 5 5 5 5 5 7 - 658560 2 2 2 2 2 2 2 3 5 7 7 7 - 661500 2 2 3 3 3 5 5 5 7 7 - 663552 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 - 666792 2 2 2 3 3 3 3 3 7 7 7 - 672000 2 2 2 2 2 2 2 2 3 5 5 5 7 - 672280 2 2 2 5 7 7 7 7 7 - 675000 2 2 2 3 3 3 5 5 5 5 5 - 677376 2 2 2 2 2 2 2 2 2 3 3 3 7 7 - 680400 2 2 2 2 3 3 3 3 3 5 5 7 - 686000 2 2 2 2 5 5 5 7 7 7 - 688128 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 - 688905 3 3 3 3 3 3 3 3 3 5 7 - 691200 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 - 691488 2 2 2 2 2 3 3 7 7 7 7 - 694575 3 3 3 3 5 5 7 7 7 - 699840 2 2 2 2 2 2 3 3 3 3 3 3 3 5 - 700000 2 2 2 2 2 5 5 5 5 5 7 - 702464 2 2 2 2 2 2 2 2 2 2 2 7 7 7 - 703125 3 3 5 5 5 5 5 5 5 - 705600 2 2 2 2 2 2 3 3 5 5 7 7 - 705894 2 3 7 7 7 7 7 7 - 708588 2 2 3 3 3 3 3 3 3 3 3 3 3 - 708750 2 3 3 3 3 5 5 5 5 7 - 714420 2 2 3 3 3 3 3 3 5 7 7 - 716800 2 2 2 2 2 2 2 2 2 2 2 2 5 5 7 - 720000 2 2 2 2 2 2 2 3 3 5 5 5 5 - 720300 2 2 3 5 5 7 7 7 7 - 725760 2 2 2 2 2 2 2 2 3 3 3 3 5 7 - 729000 2 2 2 3 3 3 3 3 3 5 5 5 - 734832 2 2 2 2 3 3 3 3 3 3 3 3 7 - 735000 2 2 2 3 5 5 5 5 7 7 - 737280 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 - 740880 2 2 2 2 3 3 3 5 7 7 7 - 746496 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 - 750000 2 2 2 2 3 5 5 5 5 5 5 - 750141 3 3 3 3 3 3 3 7 7 7 - 752640 2 2 2 2 2 2 2 2 2 2 3 5 7 7 - 756000 2 2 2 2 2 3 3 3 5 5 5 7 - 756315 3 3 5 7 7 7 7 7 - 759375 3 3 3 3 3 5 5 5 5 5 - 762048 2 2 2 2 2 2 3 3 3 3 3 7 7 - 765450 2 3 3 3 3 3 3 3 5 5 7 - 765625 5 5 5 5 5 5 7 7 - 768000 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 - 768320 2 2 2 2 2 2 5 7 7 7 7 - 771750 2 3 3 5 5 5 7 7 7 - 774144 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 - 777600 2 2 2 2 2 2 2 3 3 3 3 3 5 5 - 777924 2 2 3 3 3 3 7 7 7 7 - 781250 2 5 5 5 5 5 5 5 5 - 784000 2 2 2 2 2 2 2 5 5 5 7 7 - 786432 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 - 787320 2 2 2 3 3 3 3 3 3 3 3 3 5 - 787500 2 2 3 3 5 5 5 5 5 7 - 790272 2 2 2 2 2 2 2 2 3 3 7 7 7 - 793800 2 2 2 3 3 3 3 5 5 7 7 - 800000 2 2 2 2 2 2 2 2 5 5 5 5 5 - 802816 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 - 806400 2 2 2 2 2 2 2 2 2 3 3 5 5 7 - 806736 2 2 2 2 3 7 7 7 7 7 - 810000 2 2 2 2 3 3 3 3 5 5 5 5 - 816480 2 2 2 2 2 3 3 3 3 3 3 5 7 - 819200 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 - 820125 3 3 3 3 3 3 3 3 5 5 5 - 823200 2 2 2 2 2 3 5 5 7 7 7 - 823543 7 7 7 7 7 7 7 - 826686 2 3 3 3 3 3 3 3 3 3 3 7 - 826875 3 3 3 5 5 5 5 7 7 - 829440 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 - 833490 2 3 3 3 3 3 5 7 7 7 - 839808 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 - 840000 2 2 2 2 2 2 3 5 5 5 5 7 - 840350 2 5 5 7 7 7 7 7 - 843750 2 3 3 3 5 5 5 5 5 5 - 846720 2 2 2 2 2 2 2 3 3 3 5 7 7 - 850500 2 2 3 3 3 3 3 5 5 5 7 - 857304 2 2 2 3 3 3 3 3 3 3 7 7 - 857500 2 2 5 5 5 5 7 7 7 - 860160 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 - 864000 2 2 2 2 2 2 2 2 3 3 3 5 5 5 - 864360 2 2 2 3 3 5 7 7 7 7 - 870912 2 2 2 2 2 2 2 2 2 3 3 3 3 3 7 - 874800 2 2 2 2 3 3 3 3 3 3 3 5 5 - 875000 2 2 2 5 5 5 5 5 5 7 - 878080 2 2 2 2 2 2 2 2 2 5 7 7 7 - 882000 2 2 2 2 3 3 5 5 5 7 7 - 884736 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 - 885735 3 3 3 3 3 3 3 3 3 3 3 5 - 889056 2 2 2 2 2 3 3 3 3 7 7 7 - 893025 3 3 3 3 3 3 5 5 7 7 - 896000 2 2 2 2 2 2 2 2 2 2 5 5 5 7 - 900000 2 2 2 2 2 3 3 5 5 5 5 5 - 900375 3 5 5 5 7 7 7 7 - 903168 2 2 2 2 2 2 2 2 2 2 2 3 3 7 7 - 907200 2 2 2 2 2 2 3 3 3 3 5 5 7 - 907578 2 3 3 3 7 7 7 7 7 - 911250 2 3 3 3 3 3 3 5 5 5 5 - 917504 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 - 918540 2 2 3 3 3 3 3 3 3 3 5 7 - 918750 2 3 5 5 5 5 5 7 7 - 921600 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 - 921984 2 2 2 2 2 2 2 3 7 7 7 7 - 926100 2 2 3 3 3 5 5 7 7 7 - 933120 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 - 937500 2 2 3 5 5 5 5 5 5 5 - 940800 2 2 2 2 2 2 2 2 3 5 5 7 7 - 941192 2 2 2 7 7 7 7 7 7 - 944784 2 2 2 2 3 3 3 3 3 3 3 3 3 3 - 945000 2 2 2 3 3 3 5 5 5 5 7 - 952560 2 2 2 2 3 3 3 3 3 5 7 7 - 960000 2 2 2 2 2 2 2 2 2 3 5 5 5 5 - 960400 2 2 2 2 5 5 7 7 7 7 - 964467 3 3 3 3 3 3 3 3 3 7 7 - 967680 2 2 2 2 2 2 2 2 2 2 3 3 3 5 7 - 972000 2 2 2 2 2 3 3 3 3 3 5 5 5 - 972405 3 3 3 3 5 7 7 7 7 - 979776 2 2 2 2 2 2 3 3 3 3 3 3 3 7 - 980000 2 2 2 2 2 5 5 5 5 7 7 - 983040 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 - 984150 2 3 3 3 3 3 3 3 3 3 5 5 - 984375 3 3 5 5 5 5 5 5 7 - 987840 2 2 2 2 2 2 3 3 5 7 7 7 - 992250 2 3 3 3 3 5 5 5 7 7 - 995328 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 - 1000000 2 2 2 2 2 2 5 5 5 5 5 5 - 1000188 2 2 3 3 3 3 3 3 7 7 7 - 1003520 2 2 2 2 2 2 2 2 2 2 2 2 5 7 7 - 1008000 2 2 2 2 2 2 2 3 3 5 5 5 7 - 1008420 2 2 3 5 7 7 7 7 7 - 1012500 2 2 3 3 3 3 5 5 5 5 5 - 1016064 2 2 2 2 2 2 2 2 3 3 3 3 7 7 - 1020600 2 2 2 3 3 3 3 3 3 5 5 7 - 1024000 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 - 1029000 2 2 2 3 5 5 5 7 7 7 - 1032192 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 - 1036800 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 - 1037232 2 2 2 2 3 3 3 7 7 7 7 - 1048576 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 - 1049760 2 2 2 2 2 3 3 3 3 3 3 3 3 5 - 1050000 2 2 2 2 3 5 5 5 5 5 7 - 1053696 2 2 2 2 2 2 2 2 2 2 3 7 7 7 - 1058400 2 2 2 2 2 3 3 3 5 5 7 7 - 1058841 3 3 7 7 7 7 7 7 - 1062882 2 3 3 3 3 3 3 3 3 3 3 3 3 - 1063125 3 3 3 3 3 5 5 5 5 7 - 1071630 2 3 3 3 3 3 3 3 5 7 7 - 1071875 5 5 5 5 5 7 7 7 - 1075200 2 2 2 2 2 2 2 2 2 2 2 3 5 5 7 - 1075648 2 2 2 2 2 2 7 7 7 7 7 - 1080000 2 2 2 2 2 2 3 3 3 5 5 5 5 - 1080450 2 3 3 5 5 7 7 7 7 - 1088640 2 2 2 2 2 2 2 3 3 3 3 3 5 7 - 1093500 2 2 3 3 3 3 3 3 3 5 5 5 - 1093750 2 5 5 5 5 5 5 5 7 - 1097600 2 2 2 2 2 2 2 5 5 7 7 7 - 1102248 2 2 2 3 3 3 3 3 3 3 3 3 7 - 1102500 2 2 3 3 5 5 5 5 7 7 - 1105920 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 - 1111320 2 2 2 3 3 3 3 5 7 7 7 - 1119744 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 - 1120000 2 2 2 2 2 2 2 2 5 5 5 5 7 - 1125000 2 2 2 3 3 5 5 5 5 5 5 - 1128960 2 2 2 2 2 2 2 2 2 3 3 5 7 7 - 1134000 2 2 2 2 3 3 3 3 5 5 5 7 - 1143072 2 2 2 2 2 3 3 3 3 3 3 7 7 - 1146880 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 - 1148175 3 3 3 3 3 3 3 3 5 5 7 - 1152000 2 2 2 2 2 2 2 2 2 2 3 3 5 5 5 - 1152480 2 2 2 2 2 3 5 7 7 7 7 - 1157625 3 3 3 5 5 5 7 7 7 - 1161216 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 - 1166400 2 2 2 2 2 2 3 3 3 3 3 3 5 5 - 1166886 2 3 3 3 3 3 7 7 7 7 - 1171875 3 5 5 5 5 5 5 5 5 - 1176000 2 2 2 2 2 2 3 5 5 5 7 7 - 1176490 2 5 7 7 7 7 7 7 - 1179648 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 - 1180980 2 2 3 3 3 3 3 3 3 3 3 3 5 - 1181250 2 3 3 3 5 5 5 5 5 7 - 1185408 2 2 2 2 2 2 2 3 3 3 7 7 7 - 1190700 2 2 3 3 3 3 3 5 5 7 7 - 1200000 2 2 2 2 2 2 2 3 5 5 5 5 5 - 1200500 2 2 5 5 5 7 7 7 7 - 1204224 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 7 - 1209600 2 2 2 2 2 2 2 2 3 3 3 5 5 7 - 1210104 2 2 2 3 3 7 7 7 7 7 - 1215000 2 2 2 3 3 3 3 3 5 5 5 5 - 1224720 2 2 2 2 3 3 3 3 3 3 3 5 7 - 1225000 2 2 2 5 5 5 5 5 7 7 - 1228800 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 - 1229312 2 2 2 2 2 2 2 2 2 7 7 7 7 - 1234800 2 2 2 2 3 3 5 5 7 7 7 - 1240029 3 3 3 3 3 3 3 3 3 3 3 7 - 1244160 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 - 1250000 2 2 2 2 5 5 5 5 5 5 5 - 1250235 3 3 3 3 3 3 5 7 7 7 - 1254400 2 2 2 2 2 2 2 2 2 2 5 5 7 7 - 1259712 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 - 1260000 2 2 2 2 2 3 3 5 5 5 5 7 - 1260525 3 5 5 7 7 7 7 7 - 1265625 3 3 3 3 5 5 5 5 5 5 - 1270080 2 2 2 2 2 2 3 3 3 3 5 7 7 - 1275750 2 3 3 3 3 3 3 5 5 5 7 - 1280000 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 - 1285956 2 2 3 3 3 3 3 3 3 3 7 7 - 1286250 2 3 5 5 5 5 7 7 7 - 1290240 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 7 - 1296000 2 2 2 2 2 2 2 3 3 3 3 5 5 5 - 1296540 2 2 3 3 3 5 7 7 7 7 - 1306368 2 2 2 2 2 2 2 2 3 3 3 3 3 3 7 - 1310720 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 - 1312200 2 2 2 3 3 3 3 3 3 3 3 5 5 - 1312500 2 2 3 5 5 5 5 5 5 7 - 1317120 2 2 2 2 2 2 2 2 3 5 7 7 7 - 1323000 2 2 2 3 3 3 5 5 5 7 7 - 1327104 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 - 1333584 2 2 2 2 3 3 3 3 3 7 7 7 - 1344000 2 2 2 2 2 2 2 2 2 3 5 5 5 7 - 1344560 2 2 2 2 5 7 7 7 7 7 - 1350000 2 2 2 2 3 3 3 5 5 5 5 5 - 1354752 2 2 2 2 2 2 2 2 2 2 3 3 3 7 7 - 1360800 2 2 2 2 2 3 3 3 3 3 5 5 7 - 1361367 3 3 3 3 7 7 7 7 7 - 1366875 3 3 3 3 3 3 3 5 5 5 5 - 1372000 2 2 2 2 2 5 5 5 7 7 7 - 1376256 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 - 1377810 2 3 3 3 3 3 3 3 3 3 5 7 - 1378125 3 3 5 5 5 5 5 7 7 - 1382400 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 - 1382976 2 2 2 2 2 2 3 3 7 7 7 7 - 1389150 2 3 3 3 3 5 5 7 7 7 - 1399680 2 2 2 2 2 2 2 3 3 3 3 3 3 3 5 - 1400000 2 2 2 2 2 2 5 5 5 5 5 7 - 1404928 2 2 2 2 2 2 2 2 2 2 2 2 7 7 7 - 1406250 2 3 3 5 5 5 5 5 5 5 - 1411200 2 2 2 2 2 2 2 3 3 5 5 7 7 - 1411788 2 2 3 7 7 7 7 7 7 - 1417176 2 2 2 3 3 3 3 3 3 3 3 3 3 3 - 1417500 2 2 3 3 3 3 5 5 5 5 7 - 1428840 2 2 2 3 3 3 3 3 3 5 7 7 - 1433600 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 7 - 1440000 2 2 2 2 2 2 2 2 3 3 5 5 5 5 - 1440600 2 2 2 3 5 5 7 7 7 7 - 1451520 2 2 2 2 2 2 2 2 2 3 3 3 3 5 7 - 1458000 2 2 2 2 3 3 3 3 3 3 5 5 5 - 1469664 2 2 2 2 2 3 3 3 3 3 3 3 3 7 - 1470000 2 2 2 2 3 5 5 5 5 7 7 - 1474560 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 - 1476225 3 3 3 3 3 3 3 3 3 3 5 5 - 1481760 2 2 2 2 2 3 3 3 5 7 7 7 - 1488375 3 3 3 3 3 5 5 5 7 7 - 1492992 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 - 1500000 2 2 2 2 2 3 5 5 5 5 5 5 - 1500282 2 3 3 3 3 3 3 3 7 7 7 - 1500625 5 5 5 5 7 7 7 7 - 1505280 2 2 2 2 2 2 2 2 2 2 2 3 5 7 7 - 1512000 2 2 2 2 2 2 3 3 3 5 5 5 7 - 1512630 2 3 3 5 7 7 7 7 7 - 1518750 2 3 3 3 3 3 5 5 5 5 5 - 1524096 2 2 2 2 2 2 2 3 3 3 3 3 7 7 - 1530900 2 2 3 3 3 3 3 3 3 5 5 7 - 1531250 2 5 5 5 5 5 5 7 7 - 1536000 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 - 1536640 2 2 2 2 2 2 2 5 7 7 7 7 - 1543500 2 2 3 3 5 5 5 7 7 7 - 1548288 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 - 1555200 2 2 2 2 2 2 2 2 3 3 3 3 3 5 5 - 1555848 2 2 2 3 3 3 3 7 7 7 7 - 1562500 2 2 5 5 5 5 5 5 5 5 - 1568000 2 2 2 2 2 2 2 2 5 5 5 7 7 - 1572864 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 - 1574640 2 2 2 2 3 3 3 3 3 3 3 3 3 5 - 1575000 2 2 2 3 3 5 5 5 5 5 7 - 1580544 2 2 2 2 2 2 2 2 2 3 3 7 7 7 - 1587600 2 2 2 2 3 3 3 3 5 5 7 7 - 1594323 3 3 3 3 3 3 3 3 3 3 3 3 3 - 1600000 2 2 2 2 2 2 2 2 2 5 5 5 5 5 - 1605632 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 - 1607445 3 3 3 3 3 3 3 3 5 7 7 - 1612800 2 2 2 2 2 2 2 2 2 2 3 3 5 5 7 - 1613472 2 2 2 2 2 3 7 7 7 7 7 - 1620000 2 2 2 2 2 3 3 3 3 5 5 5 5 - 1620675 3 3 3 5 5 7 7 7 7 - 1632960 2 2 2 2 2 2 3 3 3 3 3 3 5 7 - 1638400 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 - 1640250 2 3 3 3 3 3 3 3 3 5 5 5 - 1640625 3 5 5 5 5 5 5 5 7 - 1646400 2 2 2 2 2 2 3 5 5 7 7 7 - 1647086 2 7 7 7 7 7 7 7 - 1653372 2 2 3 3 3 3 3 3 3 3 3 3 7 - 1653750 2 3 3 3 5 5 5 5 7 7 - 1658880 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 - 1666980 2 2 3 3 3 3 3 5 7 7 7 - 1679616 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 - 1680000 2 2 2 2 2 2 2 3 5 5 5 5 7 - 1680700 2 2 5 5 7 7 7 7 7 - 1687500 2 2 3 3 3 5 5 5 5 5 5 - 1693440 2 2 2 2 2 2 2 2 3 3 3 5 7 7 - 1701000 2 2 2 3 3 3 3 3 5 5 5 7 - 1714608 2 2 2 2 3 3 3 3 3 3 3 7 7 - 1715000 2 2 2 5 5 5 5 7 7 7 - 1720320 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 - 1728000 2 2 2 2 2 2 2 2 2 3 3 3 5 5 5 - 1728720 2 2 2 2 3 3 5 7 7 7 7 - 1741824 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 7 - 1749600 2 2 2 2 2 3 3 3 3 3 3 3 5 5 - 1750000 2 2 2 2 5 5 5 5 5 5 7 - 1750329 3 3 3 3 3 3 7 7 7 7 - 1756160 2 2 2 2 2 2 2 2 2 2 5 7 7 7 - 1764000 2 2 2 2 2 3 3 5 5 5 7 7 - 1764735 3 5 7 7 7 7 7 7 - 1769472 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 - 1771470 2 3 3 3 3 3 3 3 3 3 3 3 5 - 1771875 3 3 3 3 5 5 5 5 5 7 - 1778112 2 2 2 2 2 2 3 3 3 3 7 7 7 - 1786050 2 3 3 3 3 3 3 5 5 7 7 - 1792000 2 2 2 2 2 2 2 2 2 2 2 5 5 5 7 - 1800000 2 2 2 2 2 2 3 3 5 5 5 5 5 - 1800750 2 3 5 5 5 7 7 7 7 - 1806336 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 7 - 1814400 2 2 2 2 2 2 2 3 3 3 3 5 5 7 - 1815156 2 2 3 3 3 7 7 7 7 7 - 1822500 2 2 3 3 3 3 3 3 5 5 5 5 - 1835008 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 - 1837080 2 2 2 3 3 3 3 3 3 3 3 5 7 - 1837500 2 2 3 5 5 5 5 5 7 7 - 1843200 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 - 1843968 2 2 2 2 2 2 2 2 3 7 7 7 7 - 1852200 2 2 2 3 3 3 5 5 7 7 7 - 1866240 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 - 1875000 2 2 2 3 5 5 5 5 5 5 5 - 1881600 2 2 2 2 2 2 2 2 2 3 5 5 7 7 - 1882384 2 2 2 2 7 7 7 7 7 7 - 1889568 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 - 1890000 2 2 2 2 3 3 3 5 5 5 5 7 - 1905120 2 2 2 2 2 3 3 3 3 3 5 7 7 - 1913625 3 3 3 3 3 3 3 5 5 5 7 - 1920000 2 2 2 2 2 2 2 2 2 2 3 5 5 5 5 - 1920800 2 2 2 2 2 5 5 7 7 7 7 - 1928934 2 3 3 3 3 3 3 3 3 3 7 7 - 1929375 3 3 5 5 5 5 7 7 7 - 1935360 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 7 - 1944000 2 2 2 2 2 2 3 3 3 3 3 5 5 5 - 1944810 2 3 3 3 3 5 7 7 7 7 - 1953125 5 5 5 5 5 5 5 5 5 - 1959552 2 2 2 2 2 2 2 3 3 3 3 3 3 3 7 - 1960000 2 2 2 2 2 2 5 5 5 5 7 7 - 1966080 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 - 1968300 2 2 3 3 3 3 3 3 3 3 3 5 5 - 1968750 2 3 3 5 5 5 5 5 5 7 - 1975680 2 2 2 2 2 2 2 3 3 5 7 7 7 - 1984500 2 2 3 3 3 3 5 5 5 7 7 - 1990656 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 - 2000000 2 2 2 2 2 2 2 5 5 5 5 5 5 - 2000376 2 2 2 3 3 3 3 3 3 7 7 7 - 2007040 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 7 - 2016000 2 2 2 2 2 2 2 2 3 3 5 5 5 7 - 2016840 2 2 2 3 5 7 7 7 7 7 - 2025000 2 2 2 3 3 3 3 5 5 5 5 5 - 2032128 2 2 2 2 2 2 2 2 2 3 3 3 3 7 7 - 2041200 2 2 2 2 3 3 3 3 3 3 5 5 7 - 2048000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 - 2058000 2 2 2 2 3 5 5 5 7 7 7 - 2064384 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 - 2066715 3 3 3 3 3 3 3 3 3 3 5 7 - 2073600 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 - 2074464 2 2 2 2 2 3 3 3 7 7 7 7 - 2083725 3 3 3 3 3 5 5 7 7 7 - 2097152 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 - 2099520 2 2 2 2 2 2 3 3 3 3 3 3 3 3 5 - 2100000 2 2 2 2 2 3 5 5 5 5 5 7 - 2100875 5 5 5 7 7 7 7 7 - 2107392 2 2 2 2 2 2 2 2 2 2 2 3 7 7 7 - 2109375 3 3 3 5 5 5 5 5 5 5 - 2116800 2 2 2 2 2 2 3 3 3 5 5 7 7 - 2117682 2 3 3 7 7 7 7 7 7 - 2125764 2 2 3 3 3 3 3 3 3 3 3 3 3 3 - 2126250 2 3 3 3 3 3 5 5 5 5 7 - 2143260 2 2 3 3 3 3 3 3 3 5 7 7 - 2143750 2 5 5 5 5 5 7 7 7 - 2150400 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 7 - 2151296 2 2 2 2 2 2 2 7 7 7 7 7 - 2160000 2 2 2 2 2 2 2 3 3 3 5 5 5 5 - 2160900 2 2 3 3 5 5 7 7 7 7 - 2177280 2 2 2 2 2 2 2 2 3 3 3 3 3 5 7 - 2187000 2 2 2 3 3 3 3 3 3 3 5 5 5 - 2187500 2 2 5 5 5 5 5 5 5 7 - 2195200 2 2 2 2 2 2 2 2 5 5 7 7 7 - 2204496 2 2 2 2 3 3 3 3 3 3 3 3 3 7 - 2205000 2 2 2 3 3 5 5 5 5 7 7 - 2211840 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 - 2222640 2 2 2 2 3 3 3 3 5 7 7 7 - 2239488 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 - 2240000 2 2 2 2 2 2 2 2 2 5 5 5 5 7 - 2250000 2 2 2 2 3 3 5 5 5 5 5 5 - 2250423 3 3 3 3 3 3 3 3 7 7 7 - 2257920 2 2 2 2 2 2 2 2 2 2 3 3 5 7 7 - 2268000 2 2 2 2 2 3 3 3 3 5 5 5 7 - 2268945 3 3 3 5 7 7 7 7 7 - 2278125 3 3 3 3 3 3 5 5 5 5 5 - 2286144 2 2 2 2 2 2 3 3 3 3 3 3 7 7 - 2293760 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 - 2296350 2 3 3 3 3 3 3 3 3 5 5 7 - 2296875 3 5 5 5 5 5 5 7 7 - 2304000 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 5 - 2304960 2 2 2 2 2 2 3 5 7 7 7 7 - 2315250 2 3 3 3 5 5 5 7 7 7 - 2322432 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 - 2332800 2 2 2 2 2 2 2 3 3 3 3 3 3 5 5 - 2333772 2 2 3 3 3 3 3 7 7 7 7 - 2343750 2 3 5 5 5 5 5 5 5 5 - 2352000 2 2 2 2 2 2 2 3 5 5 5 7 7 - 2352980 2 2 5 7 7 7 7 7 7 - 2359296 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 - 2361960 2 2 2 3 3 3 3 3 3 3 3 3 3 5 - 2362500 2 2 3 3 3 5 5 5 5 5 7 - 2370816 2 2 2 2 2 2 2 2 3 3 3 7 7 7 - 2381400 2 2 2 3 3 3 3 3 5 5 7 7 - 2400000 2 2 2 2 2 2 2 2 3 5 5 5 5 5 - 2401000 2 2 2 5 5 5 7 7 7 7 - 2408448 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 7 - 2419200 2 2 2 2 2 2 2 2 2 3 3 3 5 5 7 - 2420208 2 2 2 2 3 3 7 7 7 7 7 - 2430000 2 2 2 2 3 3 3 3 3 5 5 5 5 - 2449440 2 2 2 2 2 3 3 3 3 3 3 3 5 7 - 2450000 2 2 2 2 5 5 5 5 5 7 7 - 2457600 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 - 2458624 2 2 2 2 2 2 2 2 2 2 7 7 7 7 - 2460375 3 3 3 3 3 3 3 3 3 5 5 5 - 2469600 2 2 2 2 2 3 3 5 5 7 7 7 - 2470629 3 7 7 7 7 7 7 7 - 2480058 2 3 3 3 3 3 3 3 3 3 3 3 7 - 2480625 3 3 3 3 5 5 5 5 7 7 - 2488320 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 - 2500000 2 2 2 2 2 5 5 5 5 5 5 5 - 2500470 2 3 3 3 3 3 3 5 7 7 7 - 2508800 2 2 2 2 2 2 2 2 2 2 2 5 5 7 7 - 2519424 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 - 2520000 2 2 2 2 2 2 3 3 5 5 5 5 7 - 2521050 2 3 5 5 7 7 7 7 7 - 2531250 2 3 3 3 3 5 5 5 5 5 5 - 2540160 2 2 2 2 2 2 2 3 3 3 3 5 7 7 - 2551500 2 2 3 3 3 3 3 3 5 5 5 7 - 2560000 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 - 2571912 2 2 2 3 3 3 3 3 3 3 3 7 7 - 2572500 2 2 3 5 5 5 5 7 7 7 - 2580480 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 7 - 2592000 2 2 2 2 2 2 2 2 3 3 3 3 5 5 5 - 2593080 2 2 2 3 3 3 5 7 7 7 7 - 2612736 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 7 - 2621440 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 - 2624400 2 2 2 2 3 3 3 3 3 3 3 3 5 5 - 2625000 2 2 2 3 5 5 5 5 5 5 7 - 2634240 2 2 2 2 2 2 2 2 2 3 5 7 7 7 - 2646000 2 2 2 2 3 3 3 5 5 5 7 7 - 2654208 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 - 2657205 3 3 3 3 3 3 3 3 3 3 3 3 5 - 2667168 2 2 2 2 2 3 3 3 3 3 7 7 7 - 2679075 3 3 3 3 3 3 3 5 5 7 7 - 2688000 2 2 2 2 2 2 2 2 2 2 3 5 5 5 7 - 2689120 2 2 2 2 2 5 7 7 7 7 7 - 2700000 2 2 2 2 2 3 3 3 5 5 5 5 5 - 2701125 3 3 5 5 5 7 7 7 7 - 2709504 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 7 - 2721600 2 2 2 2 2 2 3 3 3 3 3 5 5 7 - 2722734 2 3 3 3 3 7 7 7 7 7 - 2733750 2 3 3 3 3 3 3 3 5 5 5 5 - 2734375 5 5 5 5 5 5 5 5 7 - 2744000 2 2 2 2 2 2 5 5 5 7 7 7 - 2752512 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 - 2755620 2 2 3 3 3 3 3 3 3 3 3 5 7 - 2756250 2 3 3 5 5 5 5 5 7 7 - 2764800 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 - 2765952 2 2 2 2 2 2 2 3 3 7 7 7 7 - 2778300 2 2 3 3 3 3 5 5 7 7 7 - 2799360 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 5 - 2800000 2 2 2 2 2 2 2 5 5 5 5 5 7 - 2809856 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 7 - 2812500 2 2 3 3 5 5 5 5 5 5 5 - 2822400 2 2 2 2 2 2 2 2 3 3 5 5 7 7 - 2823576 2 2 2 3 7 7 7 7 7 7 - 2834352 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 - 2835000 2 2 2 3 3 3 3 5 5 5 5 7 - 2857680 2 2 2 2 3 3 3 3 3 3 5 7 7 - 2867200 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 7 - 2880000 2 2 2 2 2 2 2 2 2 3 3 5 5 5 5 - 2881200 2 2 2 2 3 5 5 7 7 7 7 - 2893401 3 3 3 3 3 3 3 3 3 3 7 7 - 2903040 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 7 - 2916000 2 2 2 2 2 3 3 3 3 3 3 5 5 5 - 2917215 3 3 3 3 3 5 7 7 7 7 - 2939328 2 2 2 2 2 2 3 3 3 3 3 3 3 3 7 - 2940000 2 2 2 2 2 3 5 5 5 5 7 7 - 2941225 5 5 7 7 7 7 7 7 - 2949120 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 - 2952450 2 3 3 3 3 3 3 3 3 3 3 5 5 - 2953125 3 3 3 5 5 5 5 5 5 7 - 2963520 2 2 2 2 2 2 3 3 3 5 7 7 7 - 2976750 2 3 3 3 3 3 5 5 5 7 7 - 2985984 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 - 3000000 2 2 2 2 2 2 3 5 5 5 5 5 5 - 3000564 2 2 3 3 3 3 3 3 3 7 7 7 - 3001250 2 5 5 5 5 7 7 7 7 - 3010560 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 7 - 3024000 2 2 2 2 2 2 2 3 3 3 5 5 5 7 - 3025260 2 2 3 3 5 7 7 7 7 7 - 3037500 2 2 3 3 3 3 3 5 5 5 5 5 - 3048192 2 2 2 2 2 2 2 2 3 3 3 3 3 7 7 - 3061800 2 2 2 3 3 3 3 3 3 3 5 5 7 - 3062500 2 2 5 5 5 5 5 5 7 7 - 3072000 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 - 3073280 2 2 2 2 2 2 2 2 5 7 7 7 7 - 3087000 2 2 2 3 3 5 5 5 7 7 7 - 3096576 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 - 3110400 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 5 - 3111696 2 2 2 2 3 3 3 3 7 7 7 7 - 3125000 2 2 2 5 5 5 5 5 5 5 5 - 3136000 2 2 2 2 2 2 2 2 2 5 5 5 7 7 - 3145728 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 - 3149280 2 2 2 2 2 3 3 3 3 3 3 3 3 3 5 - 3150000 2 2 2 2 3 3 5 5 5 5 5 7 - 3161088 2 2 2 2 2 2 2 2 2 2 3 3 7 7 7 - 3175200 2 2 2 2 2 3 3 3 3 5 5 7 7 - 3176523 3 3 3 7 7 7 7 7 7 - 3188646 2 3 3 3 3 3 3 3 3 3 3 3 3 3 - 3189375 3 3 3 3 3 3 5 5 5 5 7 - 3200000 2 2 2 2 2 2 2 2 2 2 5 5 5 5 5 - 3211264 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 - 3214890 2 3 3 3 3 3 3 3 3 5 7 7 - 3215625 3 5 5 5 5 5 7 7 7 - 3225600 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 7 - 3226944 2 2 2 2 2 2 3 7 7 7 7 7 - 3240000 2 2 2 2 2 2 3 3 3 3 5 5 5 5 - 3241350 2 3 3 3 5 5 7 7 7 7 - 3265920 2 2 2 2 2 2 2 3 3 3 3 3 3 5 7 - 3276800 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 - 3280500 2 2 3 3 3 3 3 3 3 3 5 5 5 - 3281250 2 3 5 5 5 5 5 5 5 7 - 3292800 2 2 2 2 2 2 2 3 5 5 7 7 7 - 3294172 2 2 7 7 7 7 7 7 7 - 3306744 2 2 2 3 3 3 3 3 3 3 3 3 3 7 - 3307500 2 2 3 3 3 5 5 5 5 7 7 - 3317760 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 - 3333960 2 2 2 3 3 3 3 3 5 7 7 7 - 3359232 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 - 3360000 2 2 2 2 2 2 2 2 3 5 5 5 5 7 - 3361400 2 2 2 5 5 7 7 7 7 7 - 3375000 2 2 2 3 3 3 5 5 5 5 5 5 - 3386880 2 2 2 2 2 2 2 2 2 3 3 3 5 7 7 - 3402000 2 2 2 2 3 3 3 3 3 5 5 5 7 - 3429216 2 2 2 2 2 3 3 3 3 3 3 3 7 7 - 3430000 2 2 2 2 5 5 5 5 7 7 7 - 3440640 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 - 3444525 3 3 3 3 3 3 3 3 3 5 5 7 - 3456000 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 5 - 3457440 2 2 2 2 2 3 3 5 7 7 7 7 - 3472875 3 3 3 3 5 5 5 7 7 7 - 3483648 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 7 - 3499200 2 2 2 2 2 2 3 3 3 3 3 3 3 5 5 - 3500000 2 2 2 2 2 5 5 5 5 5 5 7 - 3500658 2 3 3 3 3 3 3 7 7 7 7 - 3512320 2 2 2 2 2 2 2 2 2 2 2 5 7 7 7 - 3515625 3 3 5 5 5 5 5 5 5 5 - 3528000 2 2 2 2 2 2 3 3 5 5 5 7 7 - 3529470 2 3 5 7 7 7 7 7 7 - 3538944 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 - 3542940 2 2 3 3 3 3 3 3 3 3 3 3 3 5 - 3543750 2 3 3 3 3 5 5 5 5 5 7 - 3556224 2 2 2 2 2 2 2 3 3 3 3 7 7 7 - 3572100 2 2 3 3 3 3 3 3 5 5 7 7 - 3584000 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 7 - 3600000 2 2 2 2 2 2 2 3 3 5 5 5 5 5 - 3601500 2 2 3 5 5 5 7 7 7 7 - 3612672 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 7 - 3628800 2 2 2 2 2 2 2 2 3 3 3 3 5 5 7 - 3630312 2 2 2 3 3 3 7 7 7 7 7 - 3645000 2 2 2 3 3 3 3 3 3 5 5 5 5 - 3670016 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 - 3674160 2 2 2 2 3 3 3 3 3 3 3 3 5 7 - 3675000 2 2 2 3 5 5 5 5 5 7 7 - 3686400 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 - 3687936 2 2 2 2 2 2 2 2 2 3 7 7 7 7 - 3704400 2 2 2 2 3 3 3 5 5 7 7 7 - 3720087 3 3 3 3 3 3 3 3 3 3 3 3 7 - 3732480 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 - 3750000 2 2 2 2 3 5 5 5 5 5 5 5 - 3750705 3 3 3 3 3 3 3 5 7 7 7 - 3763200 2 2 2 2 2 2 2 2 2 2 3 5 5 7 7 - 3764768 2 2 2 2 2 7 7 7 7 7 7 - 3779136 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 - 3780000 2 2 2 2 2 3 3 3 5 5 5 5 7 - 3781575 3 3 5 5 7 7 7 7 7 - 3796875 3 3 3 3 3 5 5 5 5 5 5 - 3810240 2 2 2 2 2 2 3 3 3 3 3 5 7 7 - 3827250 2 3 3 3 3 3 3 3 5 5 5 7 - 3828125 5 5 5 5 5 5 5 7 7 - 3840000 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 5 - 3841600 2 2 2 2 2 2 5 5 7 7 7 7 - 3857868 2 2 3 3 3 3 3 3 3 3 3 7 7 - 3858750 2 3 3 5 5 5 5 7 7 7 - 3870720 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 7 - 3888000 2 2 2 2 2 2 2 3 3 3 3 3 5 5 5 - 3889620 2 2 3 3 3 3 5 7 7 7 7 - 3906250 2 5 5 5 5 5 5 5 5 5 - 3919104 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 7 - 3920000 2 2 2 2 2 2 2 5 5 5 5 7 7 - 3932160 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 - 3936600 2 2 2 3 3 3 3 3 3 3 3 3 5 5 - 3937500 2 2 3 3 5 5 5 5 5 5 7 - 3951360 2 2 2 2 2 2 2 2 3 3 5 7 7 7 - 3969000 2 2 2 3 3 3 3 5 5 5 7 7 - 3981312 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 - 4000000 2 2 2 2 2 2 2 2 5 5 5 5 5 5 - 4000752 2 2 2 2 3 3 3 3 3 3 7 7 7 - 4014080 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 7 - 4032000 2 2 2 2 2 2 2 2 2 3 3 5 5 5 7 - 4033680 2 2 2 2 3 5 7 7 7 7 7 - 4050000 2 2 2 2 3 3 3 3 5 5 5 5 5 - 4064256 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 7 - 4082400 2 2 2 2 2 3 3 3 3 3 3 5 5 7 - 4084101 3 3 3 3 3 7 7 7 7 7 - 4096000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 - 4100625 3 3 3 3 3 3 3 3 5 5 5 5 - 4116000 2 2 2 2 2 3 5 5 5 7 7 7 - 4117715 5 7 7 7 7 7 7 7 - 4128768 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 - 4133430 2 3 3 3 3 3 3 3 3 3 3 5 7 - 4134375 3 3 3 5 5 5 5 5 7 7 - 4147200 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 - 4148928 2 2 2 2 2 2 3 3 3 7 7 7 7 - 4167450 2 3 3 3 3 3 5 5 7 7 7 - 4194304 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 - 4199040 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 5 - 4200000 2 2 2 2 2 2 3 5 5 5 5 5 7 - 4201750 2 5 5 5 7 7 7 7 7 - 4214784 2 2 2 2 2 2 2 2 2 2 2 2 3 7 7 7 - 4218750 2 3 3 3 5 5 5 5 5 5 5 - 4233600 2 2 2 2 2 2 2 3 3 3 5 5 7 7 - 4235364 2 2 3 3 7 7 7 7 7 7 - 4251528 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 - 4252500 2 2 3 3 3 3 3 5 5 5 5 7 - 4286520 2 2 2 3 3 3 3 3 3 3 5 7 7 - 4287500 2 2 5 5 5 5 5 7 7 7 - 4300800 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 7 - 4302592 2 2 2 2 2 2 2 2 7 7 7 7 7 - 4320000 2 2 2 2 2 2 2 2 3 3 3 5 5 5 5 - 4321800 2 2 2 3 3 5 5 7 7 7 7 - 4354560 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 7 - 4374000 2 2 2 2 3 3 3 3 3 3 3 5 5 5 - 4375000 2 2 2 5 5 5 5 5 5 5 7 - 4390400 2 2 2 2 2 2 2 2 2 5 5 7 7 7 - 4408992 2 2 2 2 2 3 3 3 3 3 3 3 3 3 7 - 4410000 2 2 2 2 3 3 5 5 5 5 7 7 - 4423680 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 - 4428675 3 3 3 3 3 3 3 3 3 3 3 5 5 - 4445280 2 2 2 2 2 3 3 3 3 5 7 7 7 - 4465125 3 3 3 3 3 3 5 5 5 7 7 - 4478976 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 - 4480000 2 2 2 2 2 2 2 2 2 2 5 5 5 5 7 - 4500000 2 2 2 2 2 3 3 5 5 5 5 5 5 - 4500846 2 3 3 3 3 3 3 3 3 7 7 7 - 4501875 3 5 5 5 5 7 7 7 7 - 4515840 2 2 2 2 2 2 2 2 2 2 2 3 3 5 7 7 - 4536000 2 2 2 2 2 2 3 3 3 3 5 5 5 7 - 4537890 2 3 3 3 5 7 7 7 7 7 - 4556250 2 3 3 3 3 3 3 5 5 5 5 5 - 4572288 2 2 2 2 2 2 2 3 3 3 3 3 3 7 7 - 4587520 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 - 4592700 2 2 3 3 3 3 3 3 3 3 5 5 7 - 4593750 2 3 5 5 5 5 5 5 7 7 - 4608000 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 5 - 4609920 2 2 2 2 2 2 2 3 5 7 7 7 7 - 4630500 2 2 3 3 3 5 5 5 7 7 7 - 4644864 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 - 4665600 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 5 - 4667544 2 2 2 3 3 3 3 3 7 7 7 7 - 4687500 2 2 3 5 5 5 5 5 5 5 5 - 4704000 2 2 2 2 2 2 2 2 3 5 5 5 7 7 - 4705960 2 2 2 5 7 7 7 7 7 7 - 4718592 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 - 4723920 2 2 2 2 3 3 3 3 3 3 3 3 3 3 5 - 4725000 2 2 2 3 3 3 5 5 5 5 5 7 - 4741632 2 2 2 2 2 2 2 2 2 3 3 3 7 7 7 - 4762800 2 2 2 2 3 3 3 3 3 5 5 7 7 - 4782969 3 3 3 3 3 3 3 3 3 3 3 3 3 3 - 4800000 2 2 2 2 2 2 2 2 2 3 5 5 5 5 5 - 4802000 2 2 2 2 5 5 5 7 7 7 7 - 4816896 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 7 - 4822335 3 3 3 3 3 3 3 3 3 5 7 7 - 4838400 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 7 - 4840416 2 2 2 2 2 3 3 7 7 7 7 7 - 4860000 2 2 2 2 2 3 3 3 3 3 5 5 5 5 - 4862025 3 3 3 3 5 5 7 7 7 7 - 4898880 2 2 2 2 2 2 3 3 3 3 3 3 3 5 7 - 4900000 2 2 2 2 2 5 5 5 5 5 7 7 - 4915200 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 - 4917248 2 2 2 2 2 2 2 2 2 2 2 7 7 7 7 - 4920750 2 3 3 3 3 3 3 3 3 3 5 5 5 - 4921875 3 3 5 5 5 5 5 5 5 7 - 4939200 2 2 2 2 2 2 3 3 5 5 7 7 7 - 4941258 2 3 7 7 7 7 7 7 7 - 4960116 2 2 3 3 3 3 3 3 3 3 3 3 3 7 - 4961250 2 3 3 3 3 5 5 5 5 7 7 - 4976640 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 - 5000000 2 2 2 2 2 2 5 5 5 5 5 5 5 - 5000940 2 2 3 3 3 3 3 3 5 7 7 7 - 5017600 2 2 2 2 2 2 2 2 2 2 2 2 5 5 7 7 - 5038848 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 - 5040000 2 2 2 2 2 2 2 3 3 5 5 5 5 7 - 5042100 2 2 3 5 5 7 7 7 7 7 - 5062500 2 2 3 3 3 3 5 5 5 5 5 5 - 5080320 2 2 2 2 2 2 2 2 3 3 3 3 5 7 7 - 5103000 2 2 2 3 3 3 3 3 3 5 5 5 7 - 5120000 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 - 5143824 2 2 2 2 3 3 3 3 3 3 3 3 7 7 - 5145000 2 2 2 3 5 5 5 5 7 7 7 - 5160960 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 7 - 5184000 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 5 - 5186160 2 2 2 2 3 3 3 5 7 7 7 7 - 5225472 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 7 - 5242880 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 - 5248800 2 2 2 2 2 3 3 3 3 3 3 3 3 5 5 - 5250000 2 2 2 2 3 5 5 5 5 5 5 7 - 5250987 3 3 3 3 3 3 3 7 7 7 7 - 5268480 2 2 2 2 2 2 2 2 2 2 3 5 7 7 7 - 5292000 2 2 2 2 2 3 3 3 5 5 5 7 7 - 5294205 3 3 5 7 7 7 7 7 7 - 5308416 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 - 5314410 2 3 3 3 3 3 3 3 3 3 3 3 3 5 - 5315625 3 3 3 3 3 5 5 5 5 5 7 - 5334336 2 2 2 2 2 2 3 3 3 3 3 7 7 7 - 5358150 2 3 3 3 3 3 3 3 5 5 7 7 - 5359375 5 5 5 5 5 5 7 7 7 - 5376000 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 7 - 5378240 2 2 2 2 2 2 5 7 7 7 7 7 - 5400000 2 2 2 2 2 2 3 3 3 5 5 5 5 5 - 5402250 2 3 3 5 5 5 7 7 7 7 - 5419008 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 7 - 5443200 2 2 2 2 2 2 2 3 3 3 3 3 5 5 7 - 5445468 2 2 3 3 3 3 7 7 7 7 7 - 5467500 2 2 3 3 3 3 3 3 3 5 5 5 5 - 5468750 2 5 5 5 5 5 5 5 5 7 - 5488000 2 2 2 2 2 2 2 5 5 5 7 7 7 - 5505024 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 - 5511240 2 2 2 3 3 3 3 3 3 3 3 3 5 7 - 5512500 2 2 3 3 5 5 5 5 5 7 7 - 5529600 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 - 5531904 2 2 2 2 2 2 2 2 3 3 7 7 7 7 - 5556600 2 2 2 3 3 3 3 5 5 7 7 7 - 5598720 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 5 - 5600000 2 2 2 2 2 2 2 2 5 5 5 5 5 7 - 5619712 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 7 - 5625000 2 2 2 3 3 5 5 5 5 5 5 5 - 5644800 2 2 2 2 2 2 2 2 2 3 3 5 5 7 7 - 5647152 2 2 2 2 3 7 7 7 7 7 7 - 5668704 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 - 5670000 2 2 2 2 3 3 3 3 5 5 5 5 7 - 5715360 2 2 2 2 2 3 3 3 3 3 3 5 7 7 - 5734400 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 7 - 5740875 3 3 3 3 3 3 3 3 5 5 5 7 - 5760000 2 2 2 2 2 2 2 2 2 2 3 3 5 5 5 5 - 5762400 2 2 2 2 2 3 5 5 7 7 7 7 - 5764801 7 7 7 7 7 7 7 7 - 5786802 2 3 3 3 3 3 3 3 3 3 3 7 7 - 5788125 3 3 3 5 5 5 5 7 7 7 - 5806080 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 7 - 5832000 2 2 2 2 2 2 3 3 3 3 3 3 5 5 5 - 5834430 2 3 3 3 3 3 5 7 7 7 7 - 5859375 3 5 5 5 5 5 5 5 5 5 - 5878656 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 7 - 5880000 2 2 2 2 2 2 3 5 5 5 5 7 7 - 5882450 2 5 5 7 7 7 7 7 7 - 5898240 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 - 5904900 2 2 3 3 3 3 3 3 3 3 3 3 5 5 - 5906250 2 3 3 3 5 5 5 5 5 5 7 - 5927040 2 2 2 2 2 2 2 3 3 3 5 7 7 7 - 5953500 2 2 3 3 3 3 3 5 5 5 7 7 - 5971968 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 - 6000000 2 2 2 2 2 2 2 3 5 5 5 5 5 5 - 6001128 2 2 2 3 3 3 3 3 3 3 7 7 7 - 6002500 2 2 5 5 5 5 7 7 7 7 - 6021120 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 7 - 6048000 2 2 2 2 2 2 2 2 3 3 3 5 5 5 7 - 6050520 2 2 2 3 3 5 7 7 7 7 7 - 6075000 2 2 2 3 3 3 3 3 5 5 5 5 5 - 6096384 2 2 2 2 2 2 2 2 2 3 3 3 3 3 7 7 - 6123600 2 2 2 2 3 3 3 3 3 3 3 5 5 7 - 6125000 2 2 2 5 5 5 5 5 5 7 7 - 6144000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 - 6146560 2 2 2 2 2 2 2 2 2 5 7 7 7 7 - 6174000 2 2 2 2 3 3 5 5 5 7 7 7 - 6193152 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 - 6200145 3 3 3 3 3 3 3 3 3 3 3 5 7 - 6220800 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 5 - 6223392 2 2 2 2 2 3 3 3 3 7 7 7 7 - 6250000 2 2 2 2 5 5 5 5 5 5 5 5 - 6251175 3 3 3 3 3 3 5 5 7 7 7 - 6272000 2 2 2 2 2 2 2 2 2 2 5 5 5 7 7 - 6291456 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 - 6298560 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 5 - 6300000 2 2 2 2 2 3 3 5 5 5 5 5 7 - 6302625 3 5 5 5 7 7 7 7 7 - 6322176 2 2 2 2 2 2 2 2 2 2 2 3 3 7 7 7 - 6328125 3 3 3 3 5 5 5 5 5 5 5 - 6350400 2 2 2 2 2 2 3 3 3 3 5 5 7 7 - 6353046 2 3 3 3 7 7 7 7 7 7 - 6377292 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 - 6378750 2 3 3 3 3 3 3 5 5 5 5 7 - 6400000 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 5 - 6422528 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 - 6429780 2 2 3 3 3 3 3 3 3 3 5 7 7 - 6431250 2 3 5 5 5 5 5 7 7 7 - 6451200 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 7 - 6453888 2 2 2 2 2 2 2 3 7 7 7 7 7 - 6480000 2 2 2 2 2 2 2 3 3 3 3 5 5 5 5 - 6482700 2 2 3 3 3 5 5 7 7 7 7 - 6531840 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 7 - 6553600 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 - 6561000 2 2 2 3 3 3 3 3 3 3 3 5 5 5 - 6562500 2 2 3 5 5 5 5 5 5 5 7 - 6585600 2 2 2 2 2 2 2 2 3 5 5 7 7 7 - 6588344 2 2 2 7 7 7 7 7 7 7 - 6613488 2 2 2 2 3 3 3 3 3 3 3 3 3 3 7 - 6615000 2 2 2 3 3 3 5 5 5 5 7 7 - 6635520 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 - 6667920 2 2 2 2 3 3 3 3 3 5 7 7 7 - 6718464 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 - 6720000 2 2 2 2 2 2 2 2 2 3 5 5 5 5 7 - 6722800 2 2 2 2 5 5 7 7 7 7 7 - 6750000 2 2 2 2 3 3 3 5 5 5 5 5 5 - 6751269 3 3 3 3 3 3 3 3 3 7 7 7 - 6773760 2 2 2 2 2 2 2 2 2 2 3 3 3 5 7 7 - 6804000 2 2 2 2 2 3 3 3 3 3 5 5 5 7 - 6806835 3 3 3 3 5 7 7 7 7 7 - 6834375 3 3 3 3 3 3 3 5 5 5 5 5 - 6858432 2 2 2 2 2 2 3 3 3 3 3 3 3 7 7 - 6860000 2 2 2 2 2 5 5 5 5 7 7 7 - 6881280 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 - 6889050 2 3 3 3 3 3 3 3 3 3 5 5 7 - 6890625 3 3 5 5 5 5 5 5 7 7 - 6912000 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 5 - 6914880 2 2 2 2 2 2 3 3 5 7 7 7 7 - 6945750 2 3 3 3 3 5 5 5 7 7 7 - 6967296 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 7 - 6998400 2 2 2 2 2 2 2 3 3 3 3 3 3 3 5 5 - 7000000 2 2 2 2 2 2 5 5 5 5 5 5 7 - 7001316 2 2 3 3 3 3 3 3 7 7 7 7 - 7024640 2 2 2 2 2 2 2 2 2 2 2 2 5 7 7 7 - 7031250 2 3 3 5 5 5 5 5 5 5 5 - 7056000 2 2 2 2 2 2 2 3 3 5 5 5 7 7 - 7058940 2 2 3 5 7 7 7 7 7 7 - 7077888 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 - 7085880 2 2 2 3 3 3 3 3 3 3 3 3 3 3 5 - 7087500 2 2 3 3 3 3 5 5 5 5 5 7 - 7112448 2 2 2 2 2 2 2 2 3 3 3 3 7 7 7 - 7144200 2 2 2 3 3 3 3 3 3 5 5 7 7 - 7168000 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 7 - 7200000 2 2 2 2 2 2 2 2 3 3 5 5 5 5 5 - 7203000 2 2 2 3 5 5 5 7 7 7 7 - 7225344 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 7 - 7257600 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 7 - 7260624 2 2 2 2 3 3 3 7 7 7 7 7 - 7290000 2 2 2 2 3 3 3 3 3 3 5 5 5 5 - 7340032 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 - 7348320 2 2 2 2 2 3 3 3 3 3 3 3 3 5 7 - 7350000 2 2 2 2 3 5 5 5 5 5 7 7 - 7372800 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 - 7375872 2 2 2 2 2 2 2 2 2 2 3 7 7 7 7 - 7381125 3 3 3 3 3 3 3 3 3 3 5 5 5 - 7408800 2 2 2 2 2 3 3 3 5 5 7 7 7 - 7411887 3 3 7 7 7 7 7 7 7 - 7440174 2 3 3 3 3 3 3 3 3 3 3 3 3 7 - 7441875 3 3 3 3 3 5 5 5 5 7 7 - 7464960 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 - 7500000 2 2 2 2 2 3 5 5 5 5 5 5 5 - 7501410 2 3 3 3 3 3 3 3 5 7 7 7 - 7503125 5 5 5 5 5 7 7 7 7 - 7526400 2 2 2 2 2 2 2 2 2 2 2 3 5 5 7 7 - 7529536 2 2 2 2 2 2 7 7 7 7 7 7 - 7558272 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 - 7560000 2 2 2 2 2 2 3 3 3 5 5 5 5 7 - 7563150 2 3 3 5 5 7 7 7 7 7 - 7593750 2 3 3 3 3 3 5 5 5 5 5 5 - 7620480 2 2 2 2 2 2 2 3 3 3 3 3 5 7 7 - 7654500 2 2 3 3 3 3 3 3 3 5 5 5 7 - 7656250 2 5 5 5 5 5 5 5 7 7 - 7680000 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 5 - 7683200 2 2 2 2 2 2 2 5 5 7 7 7 7 - 7715736 2 2 2 3 3 3 3 3 3 3 3 3 7 7 - 7717500 2 2 3 3 5 5 5 5 7 7 7 - 7741440 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 7 - 7776000 2 2 2 2 2 2 2 2 3 3 3 3 3 5 5 5 - 7779240 2 2 2 3 3 3 3 5 7 7 7 7 - 7812500 2 2 5 5 5 5 5 5 5 5 5 - 7838208 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 7 - 7840000 2 2 2 2 2 2 2 2 5 5 5 5 7 7 - 7864320 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 - 7873200 2 2 2 2 3 3 3 3 3 3 3 3 3 5 5 - 7875000 2 2 2 3 3 5 5 5 5 5 5 7 - 7902720 2 2 2 2 2 2 2 2 2 3 3 5 7 7 7 - 7938000 2 2 2 2 3 3 3 3 5 5 5 7 7 - 7962624 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 - 7971615 3 3 3 3 3 3 3 3 3 3 3 3 3 5 - 8000000 2 2 2 2 2 2 2 2 2 5 5 5 5 5 5 - 8001504 2 2 2 2 2 3 3 3 3 3 3 7 7 7 - 8028160 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 7 - 8037225 3 3 3 3 3 3 3 3 5 5 7 7 - 8064000 2 2 2 2 2 2 2 2 2 2 3 3 5 5 5 7 - 8067360 2 2 2 2 2 3 5 7 7 7 7 7 - 8100000 2 2 2 2 2 3 3 3 3 5 5 5 5 5 - 8103375 3 3 3 5 5 5 7 7 7 7 - 8128512 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 7 - 8164800 2 2 2 2 2 2 3 3 3 3 3 3 5 5 7 - 8168202 2 3 3 3 3 3 7 7 7 7 7 - 8192000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 - 8201250 2 3 3 3 3 3 3 3 3 5 5 5 5 - 8203125 3 5 5 5 5 5 5 5 5 7 - 8232000 2 2 2 2 2 2 3 5 5 5 7 7 7 - 8235430 2 5 7 7 7 7 7 7 7 - 8257536 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 - 8266860 2 2 3 3 3 3 3 3 3 3 3 3 5 7 - 8268750 2 3 3 3 5 5 5 5 5 7 7 - 8294400 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 - 8297856 2 2 2 2 2 2 2 3 3 3 7 7 7 7 - 8334900 2 2 3 3 3 3 3 5 5 7 7 7 - 8388608 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 8 2 2 2 + 9 3 3 + 10 2 5 + 12 2 2 3 + 14 2 7 + 15 3 5 + 16 2 2 2 2 + 18 2 3 3 + 20 2 2 5 + 21 3 7 + 24 2 2 2 3 + 25 5 5 + 27 3 3 3 + 28 2 2 7 + 30 2 3 5 + 32 2 2 2 2 2 + 35 5 7 + 36 2 2 3 3 + 40 2 2 2 5 + 42 2 3 7 + 45 3 3 5 + 48 2 2 2 2 3 + 49 7 7 + 50 2 5 5 + 54 2 3 3 3 + 56 2 2 2 7 + 60 2 2 3 5 + 63 3 3 7 + 64 2 2 2 2 2 2 + 70 2 5 7 + 72 2 2 2 3 3 + 75 3 5 5 + 80 2 2 2 2 5 + 81 3 3 3 3 + 84 2 2 3 7 + 90 2 3 3 5 + 96 2 2 2 2 2 3 + 98 2 7 7 + 100 2 2 5 5 + 105 3 5 7 + 108 2 2 3 3 3 + 112 2 2 2 2 7 + 120 2 2 2 3 5 + 125 5 5 5 + 126 2 3 3 7 + 128 2 2 2 2 2 2 2 + 135 3 3 3 5 + 140 2 2 5 7 + 144 2 2 2 2 3 3 + 147 3 7 7 + 150 2 3 5 5 + 160 2 2 2 2 2 5 + 162 2 3 3 3 3 + 168 2 2 2 3 7 + 175 5 5 7 + 180 2 2 3 3 5 + 189 3 3 3 7 + 192 2 2 2 2 2 2 3 + 196 2 2 7 7 + 200 2 2 2 5 5 + 210 2 3 5 7 + 216 2 2 2 3 3 3 + 224 2 2 2 2 2 7 + 225 3 3 5 5 + 240 2 2 2 2 3 5 + 243 3 3 3 3 3 + 245 5 7 7 + 250 2 5 5 5 + 252 2 2 3 3 7 + 256 2 2 2 2 2 2 2 2 + 270 2 3 3 3 5 + 280 2 2 2 5 7 + 288 2 2 2 2 2 3 3 + 294 2 3 7 7 + 300 2 2 3 5 5 + 315 3 3 5 7 + 320 2 2 2 2 2 2 5 + 324 2 2 3 3 3 3 + 336 2 2 2 2 3 7 + 343 7 7 7 + 350 2 5 5 7 + 360 2 2 2 3 3 5 + 375 3 5 5 5 + 378 2 3 3 3 7 + 384 2 2 2 2 2 2 2 3 + 392 2 2 2 7 7 + 400 2 2 2 2 5 5 + 405 3 3 3 3 5 + 420 2 2 3 5 7 + 432 2 2 2 2 3 3 3 + 441 3 3 7 7 + 448 2 2 2 2 2 2 7 + 450 2 3 3 5 5 + 480 2 2 2 2 2 3 5 + 486 2 3 3 3 3 3 + 490 2 5 7 7 + 500 2 2 5 5 5 + 504 2 2 2 3 3 7 + 512 2 2 2 2 2 2 2 2 2 + 525 3 5 5 7 + 540 2 2 3 3 3 5 + 560 2 2 2 2 5 7 + 567 3 3 3 3 7 + 576 2 2 2 2 2 2 3 3 + 588 2 2 3 7 7 + 600 2 2 2 3 5 5 + 625 5 5 5 5 + 630 2 3 3 5 7 + 640 2 2 2 2 2 2 2 5 + 648 2 2 2 3 3 3 3 + 672 2 2 2 2 2 3 7 + 675 3 3 3 5 5 + 686 2 7 7 7 + 700 2 2 5 5 7 + 720 2 2 2 2 3 3 5 + 729 3 3 3 3 3 3 + 735 3 5 7 7 + 750 2 3 5 5 5 + 756 2 2 3 3 3 7 + 768 2 2 2 2 2 2 2 2 3 + 784 2 2 2 2 7 7 + 800 2 2 2 2 2 5 5 + 810 2 3 3 3 3 5 + 840 2 2 2 3 5 7 + 864 2 2 2 2 2 3 3 3 + 875 5 5 5 7 + 882 2 3 3 7 7 + 896 2 2 2 2 2 2 2 7 + 900 2 2 3 3 5 5 + 945 3 3 3 5 7 + 960 2 2 2 2 2 2 3 5 + 972 2 2 3 3 3 3 3 + 980 2 2 5 7 7 + 1000 2 2 2 5 5 5 + 1008 2 2 2 2 3 3 7 + 1024 2 2 2 2 2 2 2 2 2 2 + 1029 3 7 7 7 + 1050 2 3 5 5 7 + 1080 2 2 2 3 3 3 5 + 1120 2 2 2 2 2 5 7 + 1125 3 3 5 5 5 + 1134 2 3 3 3 3 7 + 1152 2 2 2 2 2 2 2 3 3 + 1176 2 2 2 3 7 7 + 1200 2 2 2 2 3 5 5 + 1215 3 3 3 3 3 5 + 1225 5 5 7 7 + 1250 2 5 5 5 5 + 1260 2 2 3 3 5 7 + 1280 2 2 2 2 2 2 2 2 5 + 1296 2 2 2 2 3 3 3 3 + 1323 3 3 3 7 7 + 1344 2 2 2 2 2 2 3 7 + 1350 2 3 3 3 5 5 + 1372 2 2 7 7 7 + 1400 2 2 2 5 5 7 + 1440 2 2 2 2 2 3 3 5 + 1458 2 3 3 3 3 3 3 + 1470 2 3 5 7 7 + 1500 2 2 3 5 5 5 + 1512 2 2 2 3 3 3 7 + 1536 2 2 2 2 2 2 2 2 2 3 + 1568 2 2 2 2 2 7 7 + 1575 3 3 5 5 7 + 1600 2 2 2 2 2 2 5 5 + 1620 2 2 3 3 3 3 5 + 1680 2 2 2 2 3 5 7 + 1701 3 3 3 3 3 7 + 1715 5 7 7 7 + 1728 2 2 2 2 2 2 3 3 3 + 1750 2 5 5 5 7 + 1764 2 2 3 3 7 7 + 1792 2 2 2 2 2 2 2 2 7 + 1800 2 2 2 3 3 5 5 + 1875 3 5 5 5 5 + 1890 2 3 3 3 5 7 + 1920 2 2 2 2 2 2 2 3 5 + 1944 2 2 2 3 3 3 3 3 + 1960 2 2 2 5 7 7 + 2000 2 2 2 2 5 5 5 + 2016 2 2 2 2 2 3 3 7 + 2025 3 3 3 3 5 5 + 2048 2 2 2 2 2 2 2 2 2 2 2 + 2058 2 3 7 7 7 + 2100 2 2 3 5 5 7 + 2160 2 2 2 2 3 3 3 5 + 2187 3 3 3 3 3 3 3 + 2205 3 3 5 7 7 + 2240 2 2 2 2 2 2 5 7 + 2250 2 3 3 5 5 5 + 2268 2 2 3 3 3 3 7 + 2304 2 2 2 2 2 2 2 2 3 3 + 2352 2 2 2 2 3 7 7 + 2400 2 2 2 2 2 3 5 5 + 2401 7 7 7 7 + 2430 2 3 3 3 3 3 5 + 2450 2 5 5 7 7 + 2500 2 2 5 5 5 5 + 2520 2 2 2 3 3 5 7 + 2560 2 2 2 2 2 2 2 2 2 5 + 2592 2 2 2 2 2 3 3 3 3 + 2625 3 5 5 5 7 + 2646 2 3 3 3 7 7 + 2688 2 2 2 2 2 2 2 3 7 + 2700 2 2 3 3 3 5 5 + 2744 2 2 2 7 7 7 + 2800 2 2 2 2 5 5 7 + 2835 3 3 3 3 5 7 + 2880 2 2 2 2 2 2 3 3 5 + 2916 2 2 3 3 3 3 3 3 + 2940 2 2 3 5 7 7 + 3000 2 2 2 3 5 5 5 + 3024 2 2 2 2 3 3 3 7 + 3072 2 2 2 2 2 2 2 2 2 2 3 + 3087 3 3 7 7 7 + 3125 5 5 5 5 5 + 3136 2 2 2 2 2 2 7 7 + 3150 2 3 3 5 5 7 + 3200 2 2 2 2 2 2 2 5 5 + 3240 2 2 2 3 3 3 3 5 + 3360 2 2 2 2 2 3 5 7 + 3375 3 3 3 5 5 5 + 3402 2 3 3 3 3 3 7 + 3430 2 5 7 7 7 + 3456 2 2 2 2 2 2 2 3 3 3 + 3500 2 2 5 5 5 7 + 3528 2 2 2 3 3 7 7 + 3584 2 2 2 2 2 2 2 2 2 7 + 3600 2 2 2 2 3 3 5 5 + 3645 3 3 3 3 3 3 5 + 3675 3 5 5 7 7 + 3750 2 3 5 5 5 5 + 3780 2 2 3 3 3 5 7 + 3840 2 2 2 2 2 2 2 2 3 5 + 3888 2 2 2 2 3 3 3 3 3 + 3920 2 2 2 2 5 7 7 + 3969 3 3 3 3 7 7 + 4000 2 2 2 2 2 5 5 5 + 4032 2 2 2 2 2 2 3 3 7 + 4050 2 3 3 3 3 5 5 + 4096 2 2 2 2 2 2 2 2 2 2 2 2 + 4116 2 2 3 7 7 7 + 4200 2 2 2 3 5 5 7 + 4320 2 2 2 2 2 3 3 3 5 + 4374 2 3 3 3 3 3 3 3 + 4375 5 5 5 5 7 + 4410 2 3 3 5 7 7 + 4480 2 2 2 2 2 2 2 5 7 + 4500 2 2 3 3 5 5 5 + 4536 2 2 2 3 3 3 3 7 + 4608 2 2 2 2 2 2 2 2 2 3 3 + 4704 2 2 2 2 2 3 7 7 + 4725 3 3 3 5 5 7 + 4800 2 2 2 2 2 2 3 5 5 + 4802 2 7 7 7 7 + 4860 2 2 3 3 3 3 3 5 + 4900 2 2 5 5 7 7 + 5000 2 2 2 5 5 5 5 + 5040 2 2 2 2 3 3 5 7 + 5103 3 3 3 3 3 3 7 + 5120 2 2 2 2 2 2 2 2 2 2 5 + 5145 3 5 7 7 7 + 5184 2 2 2 2 2 2 3 3 3 3 + 5250 2 3 5 5 5 7 + 5292 2 2 3 3 3 7 7 + 5376 2 2 2 2 2 2 2 2 3 7 + 5400 2 2 2 3 3 3 5 5 + 5488 2 2 2 2 7 7 7 + 5600 2 2 2 2 2 5 5 7 + 5625 3 3 5 5 5 5 + 5670 2 3 3 3 3 5 7 + 5760 2 2 2 2 2 2 2 3 3 5 + 5832 2 2 2 3 3 3 3 3 3 + 5880 2 2 2 3 5 7 7 + 6000 2 2 2 2 3 5 5 5 + 6048 2 2 2 2 2 3 3 3 7 + 6075 3 3 3 3 3 5 5 + 6125 5 5 5 7 7 + 6144 2 2 2 2 2 2 2 2 2 2 2 3 + 6174 2 3 3 7 7 7 + 6250 2 5 5 5 5 5 + 6272 2 2 2 2 2 2 2 7 7 + 6300 2 2 3 3 5 5 7 + 6400 2 2 2 2 2 2 2 2 5 5 + 6480 2 2 2 2 3 3 3 3 5 + 6561 3 3 3 3 3 3 3 3 + 6615 3 3 3 5 7 7 + 6720 2 2 2 2 2 2 3 5 7 + 6750 2 3 3 3 5 5 5 + 6804 2 2 3 3 3 3 3 7 + 6860 2 2 5 7 7 7 + 6912 2 2 2 2 2 2 2 2 3 3 3 + 7000 2 2 2 5 5 5 7 + 7056 2 2 2 2 3 3 7 7 + 7168 2 2 2 2 2 2 2 2 2 2 7 + 7200 2 2 2 2 2 3 3 5 5 + 7203 3 7 7 7 7 + 7290 2 3 3 3 3 3 3 5 + 7350 2 3 5 5 7 7 + 7500 2 2 3 5 5 5 5 + 7560 2 2 2 3 3 3 5 7 + 7680 2 2 2 2 2 2 2 2 2 3 5 + 7776 2 2 2 2 2 3 3 3 3 3 + 7840 2 2 2 2 2 5 7 7 + 7875 3 3 5 5 5 7 + 7938 2 3 3 3 3 7 7 + 8000 2 2 2 2 2 2 5 5 5 + 8064 2 2 2 2 2 2 2 3 3 7 + 8100 2 2 3 3 3 3 5 5 + 8192 2 2 2 2 2 2 2 2 2 2 2 2 2 + 8232 2 2 2 3 7 7 7 + 8400 2 2 2 2 3 5 5 7 + 8505 3 3 3 3 3 5 7 + 8575 5 5 7 7 7 + 8640 2 2 2 2 2 2 3 3 3 5 + 8748 2 2 3 3 3 3 3 3 3 + 8750 2 5 5 5 5 7 + 8820 2 2 3 3 5 7 7 + 8960 2 2 2 2 2 2 2 2 5 7 + 9000 2 2 2 3 3 5 5 5 + 9072 2 2 2 2 3 3 3 3 7 + 9216 2 2 2 2 2 2 2 2 2 2 3 3 + 9261 3 3 3 7 7 7 + 9375 3 5 5 5 5 5 + 9408 2 2 2 2 2 2 3 7 7 + 9450 2 3 3 3 5 5 7 + 9600 2 2 2 2 2 2 2 3 5 5 + 9604 2 2 7 7 7 7 + 9720 2 2 2 3 3 3 3 3 5 + 9800 2 2 2 5 5 7 7 + 10000 2 2 2 2 5 5 5 5 + 10080 2 2 2 2 2 3 3 5 7 + 10125 3 3 3 3 5 5 5 + 10206 2 3 3 3 3 3 3 7 + 10240 2 2 2 2 2 2 2 2 2 2 2 5 + 10290 2 3 5 7 7 7 + 10368 2 2 2 2 2 2 2 3 3 3 3 + 10500 2 2 3 5 5 5 7 + 10584 2 2 2 3 3 3 7 7 + 10752 2 2 2 2 2 2 2 2 2 3 7 + 10800 2 2 2 2 3 3 3 5 5 + 10935 3 3 3 3 3 3 3 5 + 10976 2 2 2 2 2 7 7 7 + 11025 3 3 5 5 7 7 + 11200 2 2 2 2 2 2 5 5 7 + 11250 2 3 3 5 5 5 5 + 11340 2 2 3 3 3 3 5 7 + 11520 2 2 2 2 2 2 2 2 3 3 5 + 11664 2 2 2 2 3 3 3 3 3 3 + 11760 2 2 2 2 3 5 7 7 + 11907 3 3 3 3 3 7 7 + 12000 2 2 2 2 2 3 5 5 5 + 12005 5 7 7 7 7 + 12096 2 2 2 2 2 2 3 3 3 7 + 12150 2 3 3 3 3 3 5 5 + 12250 2 5 5 5 7 7 + 12288 2 2 2 2 2 2 2 2 2 2 2 2 3 + 12348 2 2 3 3 7 7 7 + 12500 2 2 5 5 5 5 5 + 12544 2 2 2 2 2 2 2 2 7 7 + 12600 2 2 2 3 3 5 5 7 + 12800 2 2 2 2 2 2 2 2 2 5 5 + 12960 2 2 2 2 2 3 3 3 3 5 + 13122 2 3 3 3 3 3 3 3 3 + 13125 3 5 5 5 5 7 + 13230 2 3 3 3 5 7 7 + 13440 2 2 2 2 2 2 2 3 5 7 + 13500 2 2 3 3 3 5 5 5 + 13608 2 2 2 3 3 3 3 3 7 + 13720 2 2 2 5 7 7 7 + 13824 2 2 2 2 2 2 2 2 2 3 3 3 + 14000 2 2 2 2 5 5 5 7 + 14112 2 2 2 2 2 3 3 7 7 + 14175 3 3 3 3 5 5 7 + 14336 2 2 2 2 2 2 2 2 2 2 2 7 + 14400 2 2 2 2 2 2 3 3 5 5 + 14406 2 3 7 7 7 7 + 14580 2 2 3 3 3 3 3 3 5 + 14700 2 2 3 5 5 7 7 + 15000 2 2 2 3 5 5 5 5 + 15120 2 2 2 2 3 3 3 5 7 + 15309 3 3 3 3 3 3 3 7 + 15360 2 2 2 2 2 2 2 2 2 2 3 5 + 15435 3 3 5 7 7 7 + 15552 2 2 2 2 2 2 3 3 3 3 3 + 15625 5 5 5 5 5 5 + 15680 2 2 2 2 2 2 5 7 7 + 15750 2 3 3 5 5 5 7 + 15876 2 2 3 3 3 3 7 7 + 16000 2 2 2 2 2 2 2 5 5 5 + 16128 2 2 2 2 2 2 2 2 3 3 7 + 16200 2 2 2 3 3 3 3 5 5 + 16384 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 16464 2 2 2 2 3 7 7 7 + 16800 2 2 2 2 2 3 5 5 7 + 16807 7 7 7 7 7 + 16875 3 3 3 5 5 5 5 + 17010 2 3 3 3 3 3 5 7 + 17150 2 5 5 7 7 7 + 17280 2 2 2 2 2 2 2 3 3 3 5 + 17496 2 2 2 3 3 3 3 3 3 3 + 17500 2 2 5 5 5 5 7 + 17640 2 2 2 3 3 5 7 7 + 17920 2 2 2 2 2 2 2 2 2 5 7 + 18000 2 2 2 2 3 3 5 5 5 + 18144 2 2 2 2 2 3 3 3 3 7 + 18225 3 3 3 3 3 3 5 5 + 18375 3 5 5 5 7 7 + 18432 2 2 2 2 2 2 2 2 2 2 2 3 3 + 18522 2 3 3 3 7 7 7 + 18750 2 3 5 5 5 5 5 + 18816 2 2 2 2 2 2 2 3 7 7 + 18900 2 2 3 3 3 5 5 7 + 19200 2 2 2 2 2 2 2 2 3 5 5 + 19208 2 2 2 7 7 7 7 + 19440 2 2 2 2 3 3 3 3 3 5 + 19600 2 2 2 2 5 5 7 7 + 19683 3 3 3 3 3 3 3 3 3 + 19845 3 3 3 3 5 7 7 + 20000 2 2 2 2 2 5 5 5 5 + 20160 2 2 2 2 2 2 3 3 5 7 + 20250 2 3 3 3 3 5 5 5 + 20412 2 2 3 3 3 3 3 3 7 + 20480 2 2 2 2 2 2 2 2 2 2 2 2 5 + 20580 2 2 3 5 7 7 7 + 20736 2 2 2 2 2 2 2 2 3 3 3 3 + 21000 2 2 2 3 5 5 5 7 + 21168 2 2 2 2 3 3 3 7 7 + 21504 2 2 2 2 2 2 2 2 2 2 3 7 + 21600 2 2 2 2 2 3 3 3 5 5 + 21609 3 3 7 7 7 7 + 21870 2 3 3 3 3 3 3 3 5 + 21875 5 5 5 5 5 7 + 21952 2 2 2 2 2 2 7 7 7 + 22050 2 3 3 5 5 7 7 + 22400 2 2 2 2 2 2 2 5 5 7 + 22500 2 2 3 3 5 5 5 5 + 22680 2 2 2 3 3 3 3 5 7 + 23040 2 2 2 2 2 2 2 2 2 3 3 5 + 23328 2 2 2 2 2 3 3 3 3 3 3 + 23520 2 2 2 2 2 3 5 7 7 + 23625 3 3 3 5 5 5 7 + 23814 2 3 3 3 3 3 7 7 + 24000 2 2 2 2 2 2 3 5 5 5 + 24010 2 5 7 7 7 7 + 24192 2 2 2 2 2 2 2 3 3 3 7 + 24300 2 2 3 3 3 3 3 5 5 + 24500 2 2 5 5 5 7 7 + 24576 2 2 2 2 2 2 2 2 2 2 2 2 2 3 + 24696 2 2 2 3 3 7 7 7 + 25000 2 2 2 5 5 5 5 5 + 25088 2 2 2 2 2 2 2 2 2 7 7 + 25200 2 2 2 2 3 3 5 5 7 + 25515 3 3 3 3 3 3 5 7 + 25600 2 2 2 2 2 2 2 2 2 2 5 5 + 25725 3 5 5 7 7 7 + 25920 2 2 2 2 2 2 3 3 3 3 5 + 26244 2 2 3 3 3 3 3 3 3 3 + 26250 2 3 5 5 5 5 7 + 26460 2 2 3 3 3 5 7 7 + 26880 2 2 2 2 2 2 2 2 3 5 7 + 27000 2 2 2 3 3 3 5 5 5 + 27216 2 2 2 2 3 3 3 3 3 7 + 27440 2 2 2 2 5 7 7 7 + 27648 2 2 2 2 2 2 2 2 2 2 3 3 3 + 27783 3 3 3 3 7 7 7 + 28000 2 2 2 2 2 5 5 5 7 + 28125 3 3 5 5 5 5 5 + 28224 2 2 2 2 2 2 3 3 7 7 + 28350 2 3 3 3 3 5 5 7 + 28672 2 2 2 2 2 2 2 2 2 2 2 2 7 + 28800 2 2 2 2 2 2 2 3 3 5 5 + 28812 2 2 3 7 7 7 7 + 29160 2 2 2 3 3 3 3 3 3 5 + 29400 2 2 2 3 5 5 7 7 + 30000 2 2 2 2 3 5 5 5 5 + 30240 2 2 2 2 2 3 3 3 5 7 + 30375 3 3 3 3 3 5 5 5 + 30618 2 3 3 3 3 3 3 3 7 + 30625 5 5 5 5 7 7 + 30720 2 2 2 2 2 2 2 2 2 2 2 3 5 + 30870 2 3 3 5 7 7 7 + 31104 2 2 2 2 2 2 2 3 3 3 3 3 + 31250 2 5 5 5 5 5 5 + 31360 2 2 2 2 2 2 2 5 7 7 + 31500 2 2 3 3 5 5 5 7 + 31752 2 2 2 3 3 3 3 7 7 + 32000 2 2 2 2 2 2 2 2 5 5 5 + 32256 2 2 2 2 2 2 2 2 2 3 3 7 + 32400 2 2 2 2 3 3 3 3 5 5 + 32768 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 32805 3 3 3 3 3 3 3 3 5 + 32928 2 2 2 2 2 3 7 7 7 + 33075 3 3 3 5 5 7 7 + 33600 2 2 2 2 2 2 3 5 5 7 + 33614 2 7 7 7 7 7 + 33750 2 3 3 3 5 5 5 5 + 34020 2 2 3 3 3 3 3 5 7 + 34300 2 2 5 5 7 7 7 + 34560 2 2 2 2 2 2 2 2 3 3 3 5 + 34992 2 2 2 2 3 3 3 3 3 3 3 + 35000 2 2 2 5 5 5 5 7 + 35280 2 2 2 2 3 3 5 7 7 + 35721 3 3 3 3 3 3 7 7 + 35840 2 2 2 2 2 2 2 2 2 2 5 7 + 36000 2 2 2 2 2 3 3 5 5 5 + 36015 3 5 7 7 7 7 + 36288 2 2 2 2 2 2 3 3 3 3 7 + 36450 2 3 3 3 3 3 3 5 5 + 36750 2 3 5 5 5 7 7 + 36864 2 2 2 2 2 2 2 2 2 2 2 2 3 3 + 37044 2 2 3 3 3 7 7 7 + 37500 2 2 3 5 5 5 5 5 + 37632 2 2 2 2 2 2 2 2 3 7 7 + 37800 2 2 2 3 3 3 5 5 7 + 38400 2 2 2 2 2 2 2 2 2 3 5 5 + 38416 2 2 2 2 7 7 7 7 + 38880 2 2 2 2 2 3 3 3 3 3 5 + 39200 2 2 2 2 2 5 5 7 7 + 39366 2 3 3 3 3 3 3 3 3 3 + 39375 3 3 5 5 5 5 7 + 39690 2 3 3 3 3 5 7 7 + 40000 2 2 2 2 2 2 5 5 5 5 + 40320 2 2 2 2 2 2 2 3 3 5 7 + 40500 2 2 3 3 3 3 5 5 5 + 40824 2 2 2 3 3 3 3 3 3 7 + 40960 2 2 2 2 2 2 2 2 2 2 2 2 2 5 + 41160 2 2 2 3 5 7 7 7 + 41472 2 2 2 2 2 2 2 2 2 3 3 3 3 + 42000 2 2 2 2 3 5 5 5 7 + 42336 2 2 2 2 2 3 3 3 7 7 + 42525 3 3 3 3 3 5 5 7 + 42875 5 5 5 7 7 7 + 43008 2 2 2 2 2 2 2 2 2 2 2 3 7 + 43200 2 2 2 2 2 2 3 3 3 5 5 + 43218 2 3 3 7 7 7 7 + 43740 2 2 3 3 3 3 3 3 3 5 + 43750 2 5 5 5 5 5 7 + 43904 2 2 2 2 2 2 2 7 7 7 + 44100 2 2 3 3 5 5 7 7 + 44800 2 2 2 2 2 2 2 2 5 5 7 + 45000 2 2 2 3 3 5 5 5 5 + 45360 2 2 2 2 3 3 3 3 5 7 + 45927 3 3 3 3 3 3 3 3 7 + 46080 2 2 2 2 2 2 2 2 2 2 3 3 5 + 46305 3 3 3 5 7 7 7 + 46656 2 2 2 2 2 2 3 3 3 3 3 3 + 46875 3 5 5 5 5 5 5 + 47040 2 2 2 2 2 2 3 5 7 7 + 47250 2 3 3 3 5 5 5 7 + 47628 2 2 3 3 3 3 3 7 7 + 48000 2 2 2 2 2 2 2 3 5 5 5 + 48020 2 2 5 7 7 7 7 + 48384 2 2 2 2 2 2 2 2 3 3 3 7 + 48600 2 2 2 3 3 3 3 3 5 5 + 49000 2 2 2 5 5 5 7 7 + 49152 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 + 49392 2 2 2 2 3 3 7 7 7 + 50000 2 2 2 2 5 5 5 5 5 + 50176 2 2 2 2 2 2 2 2 2 2 7 7 + 50400 2 2 2 2 2 3 3 5 5 7 + 50421 3 7 7 7 7 7 + 50625 3 3 3 3 5 5 5 5 + 51030 2 3 3 3 3 3 3 5 7 + 51200 2 2 2 2 2 2 2 2 2 2 2 5 5 + 51450 2 3 5 5 7 7 7 + 51840 2 2 2 2 2 2 2 3 3 3 3 5 + 52488 2 2 2 3 3 3 3 3 3 3 3 + 52500 2 2 3 5 5 5 5 7 + 52920 2 2 2 3 3 3 5 7 7 + 53760 2 2 2 2 2 2 2 2 2 3 5 7 + 54000 2 2 2 2 3 3 3 5 5 5 + 54432 2 2 2 2 2 3 3 3 3 3 7 + 54675 3 3 3 3 3 3 3 5 5 + 54880 2 2 2 2 2 5 7 7 7 + 55125 3 3 5 5 5 7 7 + 55296 2 2 2 2 2 2 2 2 2 2 2 3 3 3 + 55566 2 3 3 3 3 7 7 7 + 56000 2 2 2 2 2 2 5 5 5 7 + 56250 2 3 3 5 5 5 5 5 + 56448 2 2 2 2 2 2 2 3 3 7 7 + 56700 2 2 3 3 3 3 5 5 7 + 57344 2 2 2 2 2 2 2 2 2 2 2 2 2 7 + 57600 2 2 2 2 2 2 2 2 3 3 5 5 + 57624 2 2 2 3 7 7 7 7 + 58320 2 2 2 2 3 3 3 3 3 3 5 + 58800 2 2 2 2 3 5 5 7 7 + 59049 3 3 3 3 3 3 3 3 3 3 + 59535 3 3 3 3 3 5 7 7 + 60000 2 2 2 2 2 3 5 5 5 5 + 60025 5 5 7 7 7 7 + 60480 2 2 2 2 2 2 3 3 3 5 7 + 60750 2 3 3 3 3 3 5 5 5 + 61236 2 2 3 3 3 3 3 3 3 7 + 61250 2 5 5 5 5 7 7 + 61440 2 2 2 2 2 2 2 2 2 2 2 2 3 5 + 61740 2 2 3 3 5 7 7 7 + 62208 2 2 2 2 2 2 2 2 3 3 3 3 3 + 62500 2 2 5 5 5 5 5 5 + 62720 2 2 2 2 2 2 2 2 5 7 7 + 63000 2 2 2 3 3 5 5 5 7 + 63504 2 2 2 2 3 3 3 3 7 7 + 64000 2 2 2 2 2 2 2 2 2 5 5 5 + 64512 2 2 2 2 2 2 2 2 2 2 3 3 7 + 64800 2 2 2 2 2 3 3 3 3 5 5 + 64827 3 3 3 7 7 7 7 + 65536 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 65610 2 3 3 3 3 3 3 3 3 5 + 65625 3 5 5 5 5 5 7 + 65856 2 2 2 2 2 2 3 7 7 7 + 66150 2 3 3 3 5 5 7 7 + 67200 2 2 2 2 2 2 2 3 5 5 7 + 67228 2 2 7 7 7 7 7 + 67500 2 2 3 3 3 5 5 5 5 + 68040 2 2 2 3 3 3 3 3 5 7 + 68600 2 2 2 5 5 7 7 7 + 69120 2 2 2 2 2 2 2 2 2 3 3 3 5 + 69984 2 2 2 2 2 3 3 3 3 3 3 3 + 70000 2 2 2 2 5 5 5 5 7 + 70560 2 2 2 2 2 3 3 5 7 7 + 70875 3 3 3 3 5 5 5 7 + 71442 2 3 3 3 3 3 3 7 7 + 71680 2 2 2 2 2 2 2 2 2 2 2 5 7 + 72000 2 2 2 2 2 2 3 3 5 5 5 + 72030 2 3 5 7 7 7 7 + 72576 2 2 2 2 2 2 2 3 3 3 3 7 + 72900 2 2 3 3 3 3 3 3 5 5 + 73500 2 2 3 5 5 5 7 7 + 73728 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 + 74088 2 2 2 3 3 3 7 7 7 + 75000 2 2 2 3 5 5 5 5 5 + 75264 2 2 2 2 2 2 2 2 2 3 7 7 + 75600 2 2 2 2 3 3 3 5 5 7 + 76545 3 3 3 3 3 3 3 5 7 + 76800 2 2 2 2 2 2 2 2 2 2 3 5 5 + 76832 2 2 2 2 2 7 7 7 7 + 77175 3 3 5 5 7 7 7 + 77760 2 2 2 2 2 2 3 3 3 3 3 5 + 78125 5 5 5 5 5 5 5 + 78400 2 2 2 2 2 2 5 5 7 7 + 78732 2 2 3 3 3 3 3 3 3 3 3 + 78750 2 3 3 5 5 5 5 7 + 79380 2 2 3 3 3 3 5 7 7 + 80000 2 2 2 2 2 2 2 5 5 5 5 + 80640 2 2 2 2 2 2 2 2 3 3 5 7 + 81000 2 2 2 3 3 3 3 5 5 5 + 81648 2 2 2 2 3 3 3 3 3 3 7 + 81920 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 + 82320 2 2 2 2 3 5 7 7 7 + 82944 2 2 2 2 2 2 2 2 2 2 3 3 3 3 + 83349 3 3 3 3 3 7 7 7 + 84000 2 2 2 2 2 3 5 5 5 7 + 84035 5 7 7 7 7 7 + 84375 3 3 3 5 5 5 5 5 + 84672 2 2 2 2 2 2 3 3 3 7 7 + 85050 2 3 3 3 3 3 5 5 7 + 85750 2 5 5 5 7 7 7 + 86016 2 2 2 2 2 2 2 2 2 2 2 2 3 7 + 86400 2 2 2 2 2 2 2 3 3 3 5 5 + 86436 2 2 3 3 7 7 7 7 + 87480 2 2 2 3 3 3 3 3 3 3 5 + 87500 2 2 5 5 5 5 5 7 + 87808 2 2 2 2 2 2 2 2 7 7 7 + 88200 2 2 2 3 3 5 5 7 7 + 89600 2 2 2 2 2 2 2 2 2 5 5 7 + 90000 2 2 2 2 3 3 5 5 5 5 + 90720 2 2 2 2 2 3 3 3 3 5 7 + 91125 3 3 3 3 3 3 5 5 5 + 91854 2 3 3 3 3 3 3 3 3 7 + 91875 3 5 5 5 5 7 7 + 92160 2 2 2 2 2 2 2 2 2 2 2 3 3 5 + 92610 2 3 3 3 5 7 7 7 + 93312 2 2 2 2 2 2 2 3 3 3 3 3 3 + 93750 2 3 5 5 5 5 5 5 + 94080 2 2 2 2 2 2 2 3 5 7 7 + 94500 2 2 3 3 3 5 5 5 7 + 95256 2 2 2 3 3 3 3 3 7 7 + 96000 2 2 2 2 2 2 2 2 3 5 5 5 + 96040 2 2 2 5 7 7 7 7 + 96768 2 2 2 2 2 2 2 2 2 3 3 3 7 + 97200 2 2 2 2 3 3 3 3 3 5 5 + 98000 2 2 2 2 5 5 5 7 7 + 98304 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 + 98415 3 3 3 3 3 3 3 3 3 5 + 98784 2 2 2 2 2 3 3 7 7 7 + 99225 3 3 3 3 5 5 7 7 + 100000 2 2 2 2 2 5 5 5 5 5 + 100352 2 2 2 2 2 2 2 2 2 2 2 7 7 + 100800 2 2 2 2 2 2 3 3 5 5 7 + 100842 2 3 7 7 7 7 7 + 101250 2 3 3 3 3 5 5 5 5 + 102060 2 2 3 3 3 3 3 3 5 7 + 102400 2 2 2 2 2 2 2 2 2 2 2 2 5 5 + 102900 2 2 3 5 5 7 7 7 + 103680 2 2 2 2 2 2 2 2 3 3 3 3 5 + 104976 2 2 2 2 3 3 3 3 3 3 3 3 + 105000 2 2 2 3 5 5 5 5 7 + 105840 2 2 2 2 3 3 3 5 7 7 + 107163 3 3 3 3 3 3 3 7 7 + 107520 2 2 2 2 2 2 2 2 2 2 3 5 7 + 108000 2 2 2 2 2 3 3 3 5 5 5 + 108045 3 3 5 7 7 7 7 + 108864 2 2 2 2 2 2 3 3 3 3 3 7 + 109350 2 3 3 3 3 3 3 3 5 5 + 109375 5 5 5 5 5 5 7 + 109760 2 2 2 2 2 2 5 7 7 7 + 110250 2 3 3 5 5 5 7 7 + 110592 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 + 111132 2 2 3 3 3 3 7 7 7 + 112000 2 2 2 2 2 2 2 5 5 5 7 + 112500 2 2 3 3 5 5 5 5 5 + 112896 2 2 2 2 2 2 2 2 3 3 7 7 + 113400 2 2 2 3 3 3 3 5 5 7 + 114688 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 + 115200 2 2 2 2 2 2 2 2 2 3 3 5 5 + 115248 2 2 2 2 3 7 7 7 7 + 116640 2 2 2 2 2 3 3 3 3 3 3 5 + 117600 2 2 2 2 2 3 5 5 7 7 + 117649 7 7 7 7 7 7 + 118098 2 3 3 3 3 3 3 3 3 3 3 + 118125 3 3 3 5 5 5 5 7 + 119070 2 3 3 3 3 3 5 7 7 + 120000 2 2 2 2 2 2 3 5 5 5 5 + 120050 2 5 5 7 7 7 7 + 120960 2 2 2 2 2 2 2 3 3 3 5 7 + 121500 2 2 3 3 3 3 3 5 5 5 + 122472 2 2 2 3 3 3 3 3 3 3 7 + 122500 2 2 5 5 5 5 7 7 + 122880 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 + 123480 2 2 2 3 3 5 7 7 7 + 124416 2 2 2 2 2 2 2 2 2 3 3 3 3 3 + 125000 2 2 2 5 5 5 5 5 5 + 125440 2 2 2 2 2 2 2 2 2 5 7 7 + 126000 2 2 2 2 3 3 5 5 5 7 + 127008 2 2 2 2 2 3 3 3 3 7 7 + 127575 3 3 3 3 3 3 5 5 7 + 128000 2 2 2 2 2 2 2 2 2 2 5 5 5 + 128625 3 5 5 5 7 7 7 + 129024 2 2 2 2 2 2 2 2 2 2 2 3 3 7 + 129600 2 2 2 2 2 2 3 3 3 3 5 5 + 129654 2 3 3 3 7 7 7 7 + 131072 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 131220 2 2 3 3 3 3 3 3 3 3 5 + 131250 2 3 5 5 5 5 5 7 + 131712 2 2 2 2 2 2 2 3 7 7 7 + 132300 2 2 3 3 3 5 5 7 7 + 134400 2 2 2 2 2 2 2 2 3 5 5 7 + 134456 2 2 2 7 7 7 7 7 + 135000 2 2 2 3 3 3 5 5 5 5 + 136080 2 2 2 2 3 3 3 3 3 5 7 + 137200 2 2 2 2 5 5 7 7 7 + 137781 3 3 3 3 3 3 3 3 3 7 + 138240 2 2 2 2 2 2 2 2 2 2 3 3 3 5 + 138915 3 3 3 3 5 7 7 7 + 139968 2 2 2 2 2 2 3 3 3 3 3 3 3 + 140000 2 2 2 2 2 5 5 5 5 7 + 140625 3 3 5 5 5 5 5 5 + 141120 2 2 2 2 2 2 3 3 5 7 7 + 141750 2 3 3 3 3 5 5 5 7 + 142884 2 2 3 3 3 3 3 3 7 7 + 143360 2 2 2 2 2 2 2 2 2 2 2 2 5 7 + 144000 2 2 2 2 2 2 2 3 3 5 5 5 + 144060 2 2 3 5 7 7 7 7 + 145152 2 2 2 2 2 2 2 2 3 3 3 3 7 + 145800 2 2 2 3 3 3 3 3 3 5 5 + 147000 2 2 2 3 5 5 5 7 7 + 147456 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 + 148176 2 2 2 2 3 3 3 7 7 7 + 150000 2 2 2 2 3 5 5 5 5 5 + 150528 2 2 2 2 2 2 2 2 2 2 3 7 7 + 151200 2 2 2 2 2 3 3 3 5 5 7 + 151263 3 3 7 7 7 7 7 + 151875 3 3 3 3 3 5 5 5 5 + 153090 2 3 3 3 3 3 3 3 5 7 + 153125 5 5 5 5 5 7 7 + 153600 2 2 2 2 2 2 2 2 2 2 2 3 5 5 + 153664 2 2 2 2 2 2 7 7 7 7 + 154350 2 3 3 5 5 7 7 7 + 155520 2 2 2 2 2 2 2 3 3 3 3 3 5 + 156250 2 5 5 5 5 5 5 5 + 156800 2 2 2 2 2 2 2 5 5 7 7 + 157464 2 2 2 3 3 3 3 3 3 3 3 3 + 157500 2 2 3 3 5 5 5 5 7 + 158760 2 2 2 3 3 3 3 5 7 7 + 160000 2 2 2 2 2 2 2 2 5 5 5 5 + 161280 2 2 2 2 2 2 2 2 2 3 3 5 7 + 162000 2 2 2 2 3 3 3 3 5 5 5 + 163296 2 2 2 2 2 3 3 3 3 3 3 7 + 163840 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 + 164025 3 3 3 3 3 3 3 3 5 5 + 164640 2 2 2 2 2 3 5 7 7 7 + 165375 3 3 3 5 5 5 7 7 + 165888 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 + 166698 2 3 3 3 3 3 7 7 7 + 168000 2 2 2 2 2 2 3 5 5 5 7 + 168070 2 5 7 7 7 7 7 + 168750 2 3 3 3 5 5 5 5 5 + 169344 2 2 2 2 2 2 2 3 3 3 7 7 + 170100 2 2 3 3 3 3 3 5 5 7 + 171500 2 2 5 5 5 7 7 7 + 172032 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 + 172800 2 2 2 2 2 2 2 2 3 3 3 5 5 + 172872 2 2 2 3 3 7 7 7 7 + 174960 2 2 2 2 3 3 3 3 3 3 3 5 + 175000 2 2 2 5 5 5 5 5 7 + 175616 2 2 2 2 2 2 2 2 2 7 7 7 + 176400 2 2 2 2 3 3 5 5 7 7 + 177147 3 3 3 3 3 3 3 3 3 3 3 + 178605 3 3 3 3 3 3 5 7 7 + 179200 2 2 2 2 2 2 2 2 2 2 5 5 7 + 180000 2 2 2 2 2 3 3 5 5 5 5 + 180075 3 5 5 7 7 7 7 + 181440 2 2 2 2 2 2 3 3 3 3 5 7 + 182250 2 3 3 3 3 3 3 5 5 5 + 183708 2 2 3 3 3 3 3 3 3 3 7 + 183750 2 3 5 5 5 5 7 7 + 184320 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 + 185220 2 2 3 3 3 5 7 7 7 + 186624 2 2 2 2 2 2 2 2 3 3 3 3 3 3 + 187500 2 2 3 5 5 5 5 5 5 + 188160 2 2 2 2 2 2 2 2 3 5 7 7 + 189000 2 2 2 3 3 3 5 5 5 7 + 190512 2 2 2 2 3 3 3 3 3 7 7 + 192000 2 2 2 2 2 2 2 2 2 3 5 5 5 + 192080 2 2 2 2 5 7 7 7 7 + 193536 2 2 2 2 2 2 2 2 2 2 3 3 3 7 + 194400 2 2 2 2 2 3 3 3 3 3 5 5 + 194481 3 3 3 3 7 7 7 7 + 196000 2 2 2 2 2 5 5 5 7 7 + 196608 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 + 196830 2 3 3 3 3 3 3 3 3 3 5 + 196875 3 3 5 5 5 5 5 7 + 197568 2 2 2 2 2 2 3 3 7 7 7 + 198450 2 3 3 3 3 5 5 7 7 + 200000 2 2 2 2 2 2 5 5 5 5 5 + 200704 2 2 2 2 2 2 2 2 2 2 2 2 7 7 + 201600 2 2 2 2 2 2 2 3 3 5 5 7 + 201684 2 2 3 7 7 7 7 7 + 202500 2 2 3 3 3 3 5 5 5 5 + 204120 2 2 2 3 3 3 3 3 3 5 7 + 204800 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 + 205800 2 2 2 3 5 5 7 7 7 + 207360 2 2 2 2 2 2 2 2 2 3 3 3 3 5 + 209952 2 2 2 2 2 3 3 3 3 3 3 3 3 + 210000 2 2 2 2 3 5 5 5 5 7 + 211680 2 2 2 2 2 3 3 3 5 7 7 + 212625 3 3 3 3 3 5 5 5 7 + 214326 2 3 3 3 3 3 3 3 7 7 + 214375 5 5 5 5 7 7 7 + 215040 2 2 2 2 2 2 2 2 2 2 2 3 5 7 + 216000 2 2 2 2 2 2 3 3 3 5 5 5 + 216090 2 3 3 5 7 7 7 7 + 217728 2 2 2 2 2 2 2 3 3 3 3 3 7 + 218700 2 2 3 3 3 3 3 3 3 5 5 + 218750 2 5 5 5 5 5 5 7 + 219520 2 2 2 2 2 2 2 5 7 7 7 + 220500 2 2 3 3 5 5 5 7 7 + 221184 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 + 222264 2 2 2 3 3 3 3 7 7 7 + 224000 2 2 2 2 2 2 2 2 5 5 5 7 + 225000 2 2 2 3 3 5 5 5 5 5 + 225792 2 2 2 2 2 2 2 2 2 3 3 7 7 + 226800 2 2 2 2 3 3 3 3 5 5 7 + 229376 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 + 229635 3 3 3 3 3 3 3 3 5 7 + 230400 2 2 2 2 2 2 2 2 2 2 3 3 5 5 + 230496 2 2 2 2 2 3 7 7 7 7 + 231525 3 3 3 5 5 7 7 7 + 233280 2 2 2 2 2 2 3 3 3 3 3 3 5 + 234375 3 5 5 5 5 5 5 5 + 235200 2 2 2 2 2 2 3 5 5 7 7 + 235298 2 7 7 7 7 7 7 + 236196 2 2 3 3 3 3 3 3 3 3 3 3 + 236250 2 3 3 3 5 5 5 5 7 + 238140 2 2 3 3 3 3 3 5 7 7 + 240000 2 2 2 2 2 2 2 3 5 5 5 5 + 240100 2 2 5 5 7 7 7 7 + 241920 2 2 2 2 2 2 2 2 3 3 3 5 7 + 243000 2 2 2 3 3 3 3 3 5 5 5 + 244944 2 2 2 2 3 3 3 3 3 3 3 7 + 245000 2 2 2 5 5 5 5 7 7 + 245760 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 + 246960 2 2 2 2 3 3 5 7 7 7 + 248832 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 + 250000 2 2 2 2 5 5 5 5 5 5 + 250047 3 3 3 3 3 3 7 7 7 + 250880 2 2 2 2 2 2 2 2 2 2 5 7 7 + 252000 2 2 2 2 2 3 3 5 5 5 7 + 252105 3 5 7 7 7 7 7 + 253125 3 3 3 3 5 5 5 5 5 + 254016 2 2 2 2 2 2 3 3 3 3 7 7 + 255150 2 3 3 3 3 3 3 5 5 7 + 256000 2 2 2 2 2 2 2 2 2 2 2 5 5 5 + 257250 2 3 5 5 5 7 7 7 + 258048 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 + 259200 2 2 2 2 2 2 2 3 3 3 3 5 5 + 259308 2 2 3 3 3 7 7 7 7 + 262144 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 262440 2 2 2 3 3 3 3 3 3 3 3 5 + 262500 2 2 3 5 5 5 5 5 7 + 263424 2 2 2 2 2 2 2 2 3 7 7 7 + 264600 2 2 2 3 3 3 5 5 7 7 + 268800 2 2 2 2 2 2 2 2 2 3 5 5 7 + 268912 2 2 2 2 7 7 7 7 7 + 270000 2 2 2 2 3 3 3 5 5 5 5 + 272160 2 2 2 2 2 3 3 3 3 3 5 7 + 273375 3 3 3 3 3 3 3 5 5 5 + 274400 2 2 2 2 2 5 5 7 7 7 + 275562 2 3 3 3 3 3 3 3 3 3 7 + 275625 3 3 5 5 5 5 7 7 + 276480 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 + 277830 2 3 3 3 3 5 7 7 7 + 279936 2 2 2 2 2 2 2 3 3 3 3 3 3 3 + 280000 2 2 2 2 2 2 5 5 5 5 7 + 281250 2 3 3 5 5 5 5 5 5 + 282240 2 2 2 2 2 2 2 3 3 5 7 7 + 283500 2 2 3 3 3 3 5 5 5 7 + 285768 2 2 2 3 3 3 3 3 3 7 7 + 286720 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 + 288000 2 2 2 2 2 2 2 2 3 3 5 5 5 + 288120 2 2 2 3 5 7 7 7 7 + 290304 2 2 2 2 2 2 2 2 2 3 3 3 3 7 + 291600 2 2 2 2 3 3 3 3 3 3 5 5 + 294000 2 2 2 2 3 5 5 5 7 7 + 294912 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 + 295245 3 3 3 3 3 3 3 3 3 3 5 + 296352 2 2 2 2 2 3 3 3 7 7 7 + 297675 3 3 3 3 3 5 5 7 7 + 300000 2 2 2 2 2 3 5 5 5 5 5 + 300125 5 5 5 7 7 7 7 + 301056 2 2 2 2 2 2 2 2 2 2 2 3 7 7 + 302400 2 2 2 2 2 2 3 3 3 5 5 7 + 302526 2 3 3 7 7 7 7 7 + 303750 2 3 3 3 3 3 5 5 5 5 + 306180 2 2 3 3 3 3 3 3 3 5 7 + 306250 2 5 5 5 5 5 7 7 + 307200 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 + 307328 2 2 2 2 2 2 2 7 7 7 7 + 308700 2 2 3 3 5 5 7 7 7 + 311040 2 2 2 2 2 2 2 2 3 3 3 3 3 5 + 312500 2 2 5 5 5 5 5 5 5 + 313600 2 2 2 2 2 2 2 2 5 5 7 7 + 314928 2 2 2 2 3 3 3 3 3 3 3 3 3 + 315000 2 2 2 3 3 5 5 5 5 7 + 317520 2 2 2 2 3 3 3 3 5 7 7 + 320000 2 2 2 2 2 2 2 2 2 5 5 5 5 + 321489 3 3 3 3 3 3 3 3 7 7 + 322560 2 2 2 2 2 2 2 2 2 2 3 3 5 7 + 324000 2 2 2 2 2 3 3 3 3 5 5 5 + 324135 3 3 3 5 7 7 7 7 + 326592 2 2 2 2 2 2 3 3 3 3 3 3 7 + 327680 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 + 328050 2 3 3 3 3 3 3 3 3 5 5 + 328125 3 5 5 5 5 5 5 7 + 329280 2 2 2 2 2 2 3 5 7 7 7 + 330750 2 3 3 3 5 5 5 7 7 + 331776 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 + 333396 2 2 3 3 3 3 3 7 7 7 + 336000 2 2 2 2 2 2 2 3 5 5 5 7 + 336140 2 2 5 7 7 7 7 7 + 337500 2 2 3 3 3 5 5 5 5 5 + 338688 2 2 2 2 2 2 2 2 3 3 3 7 7 + 340200 2 2 2 3 3 3 3 3 5 5 7 + 343000 2 2 2 5 5 5 7 7 7 + 344064 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 + 345600 2 2 2 2 2 2 2 2 2 3 3 3 5 5 + 345744 2 2 2 2 3 3 7 7 7 7 + 349920 2 2 2 2 2 3 3 3 3 3 3 3 5 + 350000 2 2 2 2 5 5 5 5 5 7 + 351232 2 2 2 2 2 2 2 2 2 2 7 7 7 + 352800 2 2 2 2 2 3 3 5 5 7 7 + 352947 3 7 7 7 7 7 7 + 354294 2 3 3 3 3 3 3 3 3 3 3 3 + 354375 3 3 3 3 5 5 5 5 7 + 357210 2 3 3 3 3 3 3 5 7 7 + 358400 2 2 2 2 2 2 2 2 2 2 2 5 5 7 + 360000 2 2 2 2 2 2 3 3 5 5 5 5 + 360150 2 3 5 5 7 7 7 7 + 362880 2 2 2 2 2 2 2 3 3 3 3 5 7 + 364500 2 2 3 3 3 3 3 3 5 5 5 + 367416 2 2 2 3 3 3 3 3 3 3 3 7 + 367500 2 2 3 5 5 5 5 7 7 + 368640 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 + 370440 2 2 2 3 3 3 5 7 7 7 + 373248 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 + 375000 2 2 2 3 5 5 5 5 5 5 + 376320 2 2 2 2 2 2 2 2 2 3 5 7 7 + 378000 2 2 2 2 3 3 3 5 5 5 7 + 381024 2 2 2 2 2 3 3 3 3 3 7 7 + 382725 3 3 3 3 3 3 3 5 5 7 + 384000 2 2 2 2 2 2 2 2 2 2 3 5 5 5 + 384160 2 2 2 2 2 5 7 7 7 7 + 385875 3 3 5 5 5 7 7 7 + 387072 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 + 388800 2 2 2 2 2 2 3 3 3 3 3 5 5 + 388962 2 3 3 3 3 7 7 7 7 + 390625 5 5 5 5 5 5 5 5 + 392000 2 2 2 2 2 2 5 5 5 7 7 + 393216 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 + 393660 2 2 3 3 3 3 3 3 3 3 3 5 + 393750 2 3 3 5 5 5 5 5 7 + 395136 2 2 2 2 2 2 2 3 3 7 7 7 + 396900 2 2 3 3 3 3 5 5 7 7 + 400000 2 2 2 2 2 2 2 5 5 5 5 5 + 401408 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 + 403200 2 2 2 2 2 2 2 2 3 3 5 5 7 + 403368 2 2 2 3 7 7 7 7 7 + 405000 2 2 2 3 3 3 3 5 5 5 5 + 408240 2 2 2 2 3 3 3 3 3 3 5 7 + 409600 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 + 411600 2 2 2 2 3 5 5 7 7 7 + 413343 3 3 3 3 3 3 3 3 3 3 7 + 414720 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 + 416745 3 3 3 3 3 5 7 7 7 + 419904 2 2 2 2 2 2 3 3 3 3 3 3 3 3 + 420000 2 2 2 2 2 3 5 5 5 5 7 + 420175 5 5 7 7 7 7 7 + 421875 3 3 3 5 5 5 5 5 5 + 423360 2 2 2 2 2 2 3 3 3 5 7 7 + 425250 2 3 3 3 3 3 5 5 5 7 + 428652 2 2 3 3 3 3 3 3 3 7 7 + 428750 2 5 5 5 5 7 7 7 + 430080 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 + 432000 2 2 2 2 2 2 2 3 3 3 5 5 5 + 432180 2 2 3 3 5 7 7 7 7 + 435456 2 2 2 2 2 2 2 2 3 3 3 3 3 7 + 437400 2 2 2 3 3 3 3 3 3 3 5 5 + 437500 2 2 5 5 5 5 5 5 7 + 439040 2 2 2 2 2 2 2 2 5 7 7 7 + 441000 2 2 2 3 3 5 5 5 7 7 + 442368 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 + 444528 2 2 2 2 3 3 3 3 7 7 7 + 448000 2 2 2 2 2 2 2 2 2 5 5 5 7 + 450000 2 2 2 2 3 3 5 5 5 5 5 + 451584 2 2 2 2 2 2 2 2 2 2 3 3 7 7 + 453600 2 2 2 2 2 3 3 3 3 5 5 7 + 453789 3 3 3 7 7 7 7 7 + 455625 3 3 3 3 3 3 5 5 5 5 + 458752 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 + 459270 2 3 3 3 3 3 3 3 3 5 7 + 459375 3 5 5 5 5 5 7 7 + 460800 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 + 460992 2 2 2 2 2 2 3 7 7 7 7 + 463050 2 3 3 3 5 5 7 7 7 + 466560 2 2 2 2 2 2 2 3 3 3 3 3 3 5 + 468750 2 3 5 5 5 5 5 5 5 + 470400 2 2 2 2 2 2 2 3 5 5 7 7 + 470596 2 2 7 7 7 7 7 7 + 472392 2 2 2 3 3 3 3 3 3 3 3 3 3 + 472500 2 2 3 3 3 5 5 5 5 7 + 476280 2 2 2 3 3 3 3 3 5 7 7 + 480000 2 2 2 2 2 2 2 2 3 5 5 5 5 + 480200 2 2 2 5 5 7 7 7 7 + 483840 2 2 2 2 2 2 2 2 2 3 3 3 5 7 + 486000 2 2 2 2 3 3 3 3 3 5 5 5 + 489888 2 2 2 2 2 3 3 3 3 3 3 3 7 + 490000 2 2 2 2 5 5 5 5 7 7 + 491520 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 + 492075 3 3 3 3 3 3 3 3 3 5 5 + 493920 2 2 2 2 2 3 3 5 7 7 7 + 496125 3 3 3 3 5 5 5 7 7 + 497664 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 + 500000 2 2 2 2 2 5 5 5 5 5 5 + 500094 2 3 3 3 3 3 3 7 7 7 + 501760 2 2 2 2 2 2 2 2 2 2 2 5 7 7 + 504000 2 2 2 2 2 2 3 3 5 5 5 7 + 504210 2 3 5 7 7 7 7 7 + 506250 2 3 3 3 3 5 5 5 5 5 + 508032 2 2 2 2 2 2 2 3 3 3 3 7 7 + 510300 2 2 3 3 3 3 3 3 5 5 7 + 512000 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 + 514500 2 2 3 5 5 5 7 7 7 + 516096 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 + 518400 2 2 2 2 2 2 2 2 3 3 3 3 5 5 + 518616 2 2 2 3 3 3 7 7 7 7 + 524288 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 524880 2 2 2 2 3 3 3 3 3 3 3 3 5 + 525000 2 2 2 3 5 5 5 5 5 7 + 526848 2 2 2 2 2 2 2 2 2 3 7 7 7 + 529200 2 2 2 2 3 3 3 5 5 7 7 + 531441 3 3 3 3 3 3 3 3 3 3 3 3 + 535815 3 3 3 3 3 3 3 5 7 7 + 537600 2 2 2 2 2 2 2 2 2 2 3 5 5 7 + 537824 2 2 2 2 2 7 7 7 7 7 + 540000 2 2 2 2 2 3 3 3 5 5 5 5 + 540225 3 3 5 5 7 7 7 7 + 544320 2 2 2 2 2 2 3 3 3 3 3 5 7 + 546750 2 3 3 3 3 3 3 3 5 5 5 + 546875 5 5 5 5 5 5 5 7 + 548800 2 2 2 2 2 2 5 5 7 7 7 + 551124 2 2 3 3 3 3 3 3 3 3 3 7 + 551250 2 3 3 5 5 5 5 7 7 + 552960 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 + 555660 2 2 3 3 3 3 5 7 7 7 + 559872 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 + 560000 2 2 2 2 2 2 2 5 5 5 5 7 + 562500 2 2 3 3 5 5 5 5 5 5 + 564480 2 2 2 2 2 2 2 2 3 3 5 7 7 + 567000 2 2 2 3 3 3 3 5 5 5 7 + 571536 2 2 2 2 3 3 3 3 3 3 7 7 + 573440 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 + 576000 2 2 2 2 2 2 2 2 2 3 3 5 5 5 + 576240 2 2 2 2 3 5 7 7 7 7 + 580608 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 + 583200 2 2 2 2 2 3 3 3 3 3 3 5 5 + 583443 3 3 3 3 3 7 7 7 7 + 588000 2 2 2 2 2 3 5 5 5 7 7 + 588245 5 7 7 7 7 7 7 + 589824 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 + 590490 2 3 3 3 3 3 3 3 3 3 3 5 + 590625 3 3 3 5 5 5 5 5 7 + 592704 2 2 2 2 2 2 3 3 3 7 7 7 + 595350 2 3 3 3 3 3 5 5 7 7 + 600000 2 2 2 2 2 2 3 5 5 5 5 5 + 600250 2 5 5 5 7 7 7 7 + 602112 2 2 2 2 2 2 2 2 2 2 2 2 3 7 7 + 604800 2 2 2 2 2 2 2 3 3 3 5 5 7 + 605052 2 2 3 3 7 7 7 7 7 + 607500 2 2 3 3 3 3 3 5 5 5 5 + 612360 2 2 2 3 3 3 3 3 3 3 5 7 + 612500 2 2 5 5 5 5 5 7 7 + 614400 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 + 614656 2 2 2 2 2 2 2 2 7 7 7 7 + 617400 2 2 2 3 3 5 5 7 7 7 + 622080 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 + 625000 2 2 2 5 5 5 5 5 5 5 + 627200 2 2 2 2 2 2 2 2 2 5 5 7 7 + 629856 2 2 2 2 2 3 3 3 3 3 3 3 3 3 + 630000 2 2 2 2 3 3 5 5 5 5 7 + 635040 2 2 2 2 2 3 3 3 3 5 7 7 + 637875 3 3 3 3 3 3 5 5 5 7 + 640000 2 2 2 2 2 2 2 2 2 2 5 5 5 5 + 642978 2 3 3 3 3 3 3 3 3 7 7 + 643125 3 5 5 5 5 7 7 7 + 645120 2 2 2 2 2 2 2 2 2 2 2 3 3 5 7 + 648000 2 2 2 2 2 2 3 3 3 3 5 5 5 + 648270 2 3 3 3 5 7 7 7 7 + 653184 2 2 2 2 2 2 2 3 3 3 3 3 3 7 + 655360 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 + 656100 2 2 3 3 3 3 3 3 3 3 5 5 + 656250 2 3 5 5 5 5 5 5 7 + 658560 2 2 2 2 2 2 2 3 5 7 7 7 + 661500 2 2 3 3 3 5 5 5 7 7 + 663552 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 + 666792 2 2 2 3 3 3 3 3 7 7 7 + 672000 2 2 2 2 2 2 2 2 3 5 5 5 7 + 672280 2 2 2 5 7 7 7 7 7 + 675000 2 2 2 3 3 3 5 5 5 5 5 + 677376 2 2 2 2 2 2 2 2 2 3 3 3 7 7 + 680400 2 2 2 2 3 3 3 3 3 5 5 7 + 686000 2 2 2 2 5 5 5 7 7 7 + 688128 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 + 688905 3 3 3 3 3 3 3 3 3 5 7 + 691200 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 + 691488 2 2 2 2 2 3 3 7 7 7 7 + 694575 3 3 3 3 5 5 7 7 7 + 699840 2 2 2 2 2 2 3 3 3 3 3 3 3 5 + 700000 2 2 2 2 2 5 5 5 5 5 7 + 702464 2 2 2 2 2 2 2 2 2 2 2 7 7 7 + 703125 3 3 5 5 5 5 5 5 5 + 705600 2 2 2 2 2 2 3 3 5 5 7 7 + 705894 2 3 7 7 7 7 7 7 + 708588 2 2 3 3 3 3 3 3 3 3 3 3 3 + 708750 2 3 3 3 3 5 5 5 5 7 + 714420 2 2 3 3 3 3 3 3 5 7 7 + 716800 2 2 2 2 2 2 2 2 2 2 2 2 5 5 7 + 720000 2 2 2 2 2 2 2 3 3 5 5 5 5 + 720300 2 2 3 5 5 7 7 7 7 + 725760 2 2 2 2 2 2 2 2 3 3 3 3 5 7 + 729000 2 2 2 3 3 3 3 3 3 5 5 5 + 734832 2 2 2 2 3 3 3 3 3 3 3 3 7 + 735000 2 2 2 3 5 5 5 5 7 7 + 737280 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 + 740880 2 2 2 2 3 3 3 5 7 7 7 + 746496 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 + 750000 2 2 2 2 3 5 5 5 5 5 5 + 750141 3 3 3 3 3 3 3 7 7 7 + 752640 2 2 2 2 2 2 2 2 2 2 3 5 7 7 + 756000 2 2 2 2 2 3 3 3 5 5 5 7 + 756315 3 3 5 7 7 7 7 7 + 759375 3 3 3 3 3 5 5 5 5 5 + 762048 2 2 2 2 2 2 3 3 3 3 3 7 7 + 765450 2 3 3 3 3 3 3 3 5 5 7 + 765625 5 5 5 5 5 5 7 7 + 768000 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 + 768320 2 2 2 2 2 2 5 7 7 7 7 + 771750 2 3 3 5 5 5 7 7 7 + 774144 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 + 777600 2 2 2 2 2 2 2 3 3 3 3 3 5 5 + 777924 2 2 3 3 3 3 7 7 7 7 + 781250 2 5 5 5 5 5 5 5 5 + 784000 2 2 2 2 2 2 2 5 5 5 7 7 + 786432 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 + 787320 2 2 2 3 3 3 3 3 3 3 3 3 5 + 787500 2 2 3 3 5 5 5 5 5 7 + 790272 2 2 2 2 2 2 2 2 3 3 7 7 7 + 793800 2 2 2 3 3 3 3 5 5 7 7 + 800000 2 2 2 2 2 2 2 2 5 5 5 5 5 + 802816 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 + 806400 2 2 2 2 2 2 2 2 2 3 3 5 5 7 + 806736 2 2 2 2 3 7 7 7 7 7 + 810000 2 2 2 2 3 3 3 3 5 5 5 5 + 816480 2 2 2 2 2 3 3 3 3 3 3 5 7 + 819200 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 + 820125 3 3 3 3 3 3 3 3 5 5 5 + 823200 2 2 2 2 2 3 5 5 7 7 7 + 823543 7 7 7 7 7 7 7 + 826686 2 3 3 3 3 3 3 3 3 3 3 7 + 826875 3 3 3 5 5 5 5 7 7 + 829440 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 + 833490 2 3 3 3 3 3 5 7 7 7 + 839808 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 + 840000 2 2 2 2 2 2 3 5 5 5 5 7 + 840350 2 5 5 7 7 7 7 7 + 843750 2 3 3 3 5 5 5 5 5 5 + 846720 2 2 2 2 2 2 2 3 3 3 5 7 7 + 850500 2 2 3 3 3 3 3 5 5 5 7 + 857304 2 2 2 3 3 3 3 3 3 3 7 7 + 857500 2 2 5 5 5 5 7 7 7 + 860160 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 + 864000 2 2 2 2 2 2 2 2 3 3 3 5 5 5 + 864360 2 2 2 3 3 5 7 7 7 7 + 870912 2 2 2 2 2 2 2 2 2 3 3 3 3 3 7 + 874800 2 2 2 2 3 3 3 3 3 3 3 5 5 + 875000 2 2 2 5 5 5 5 5 5 7 + 878080 2 2 2 2 2 2 2 2 2 5 7 7 7 + 882000 2 2 2 2 3 3 5 5 5 7 7 + 884736 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 + 885735 3 3 3 3 3 3 3 3 3 3 3 5 + 889056 2 2 2 2 2 3 3 3 3 7 7 7 + 893025 3 3 3 3 3 3 5 5 7 7 + 896000 2 2 2 2 2 2 2 2 2 2 5 5 5 7 + 900000 2 2 2 2 2 3 3 5 5 5 5 5 + 900375 3 5 5 5 7 7 7 7 + 903168 2 2 2 2 2 2 2 2 2 2 2 3 3 7 7 + 907200 2 2 2 2 2 2 3 3 3 3 5 5 7 + 907578 2 3 3 3 7 7 7 7 7 + 911250 2 3 3 3 3 3 3 5 5 5 5 + 917504 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 + 918540 2 2 3 3 3 3 3 3 3 3 5 7 + 918750 2 3 5 5 5 5 5 7 7 + 921600 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 + 921984 2 2 2 2 2 2 2 3 7 7 7 7 + 926100 2 2 3 3 3 5 5 7 7 7 + 933120 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 + 937500 2 2 3 5 5 5 5 5 5 5 + 940800 2 2 2 2 2 2 2 2 3 5 5 7 7 + 941192 2 2 2 7 7 7 7 7 7 + 944784 2 2 2 2 3 3 3 3 3 3 3 3 3 3 + 945000 2 2 2 3 3 3 5 5 5 5 7 + 952560 2 2 2 2 3 3 3 3 3 5 7 7 + 960000 2 2 2 2 2 2 2 2 2 3 5 5 5 5 + 960400 2 2 2 2 5 5 7 7 7 7 + 964467 3 3 3 3 3 3 3 3 3 7 7 + 967680 2 2 2 2 2 2 2 2 2 2 3 3 3 5 7 + 972000 2 2 2 2 2 3 3 3 3 3 5 5 5 + 972405 3 3 3 3 5 7 7 7 7 + 979776 2 2 2 2 2 2 3 3 3 3 3 3 3 7 + 980000 2 2 2 2 2 5 5 5 5 7 7 + 983040 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 + 984150 2 3 3 3 3 3 3 3 3 3 5 5 + 984375 3 3 5 5 5 5 5 5 7 + 987840 2 2 2 2 2 2 3 3 5 7 7 7 + 992250 2 3 3 3 3 5 5 5 7 7 + 995328 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 + 1000000 2 2 2 2 2 2 5 5 5 5 5 5 + 1000188 2 2 3 3 3 3 3 3 7 7 7 + 1003520 2 2 2 2 2 2 2 2 2 2 2 2 5 7 7 + 1008000 2 2 2 2 2 2 2 3 3 5 5 5 7 + 1008420 2 2 3 5 7 7 7 7 7 + 1012500 2 2 3 3 3 3 5 5 5 5 5 + 1016064 2 2 2 2 2 2 2 2 3 3 3 3 7 7 + 1020600 2 2 2 3 3 3 3 3 3 5 5 7 + 1024000 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 + 1029000 2 2 2 3 5 5 5 7 7 7 + 1032192 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 + 1036800 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 + 1037232 2 2 2 2 3 3 3 7 7 7 7 + 1048576 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 1049760 2 2 2 2 2 3 3 3 3 3 3 3 3 5 + 1050000 2 2 2 2 3 5 5 5 5 5 7 + 1053696 2 2 2 2 2 2 2 2 2 2 3 7 7 7 + 1058400 2 2 2 2 2 3 3 3 5 5 7 7 + 1058841 3 3 7 7 7 7 7 7 + 1062882 2 3 3 3 3 3 3 3 3 3 3 3 3 + 1063125 3 3 3 3 3 5 5 5 5 7 + 1071630 2 3 3 3 3 3 3 3 5 7 7 + 1071875 5 5 5 5 5 7 7 7 + 1075200 2 2 2 2 2 2 2 2 2 2 2 3 5 5 7 + 1075648 2 2 2 2 2 2 7 7 7 7 7 + 1080000 2 2 2 2 2 2 3 3 3 5 5 5 5 + 1080450 2 3 3 5 5 7 7 7 7 + 1088640 2 2 2 2 2 2 2 3 3 3 3 3 5 7 + 1093500 2 2 3 3 3 3 3 3 3 5 5 5 + 1093750 2 5 5 5 5 5 5 5 7 + 1097600 2 2 2 2 2 2 2 5 5 7 7 7 + 1102248 2 2 2 3 3 3 3 3 3 3 3 3 7 + 1102500 2 2 3 3 5 5 5 5 7 7 + 1105920 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 + 1111320 2 2 2 3 3 3 3 5 7 7 7 + 1119744 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 + 1120000 2 2 2 2 2 2 2 2 5 5 5 5 7 + 1125000 2 2 2 3 3 5 5 5 5 5 5 + 1128960 2 2 2 2 2 2 2 2 2 3 3 5 7 7 + 1134000 2 2 2 2 3 3 3 3 5 5 5 7 + 1143072 2 2 2 2 2 3 3 3 3 3 3 7 7 + 1146880 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 + 1148175 3 3 3 3 3 3 3 3 5 5 7 + 1152000 2 2 2 2 2 2 2 2 2 2 3 3 5 5 5 + 1152480 2 2 2 2 2 3 5 7 7 7 7 + 1157625 3 3 3 5 5 5 7 7 7 + 1161216 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 + 1166400 2 2 2 2 2 2 3 3 3 3 3 3 5 5 + 1166886 2 3 3 3 3 3 7 7 7 7 + 1171875 3 5 5 5 5 5 5 5 5 + 1176000 2 2 2 2 2 2 3 5 5 5 7 7 + 1176490 2 5 7 7 7 7 7 7 + 1179648 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 + 1180980 2 2 3 3 3 3 3 3 3 3 3 3 5 + 1181250 2 3 3 3 5 5 5 5 5 7 + 1185408 2 2 2 2 2 2 2 3 3 3 7 7 7 + 1190700 2 2 3 3 3 3 3 5 5 7 7 + 1200000 2 2 2 2 2 2 2 3 5 5 5 5 5 + 1200500 2 2 5 5 5 7 7 7 7 + 1204224 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 7 + 1209600 2 2 2 2 2 2 2 2 3 3 3 5 5 7 + 1210104 2 2 2 3 3 7 7 7 7 7 + 1215000 2 2 2 3 3 3 3 3 5 5 5 5 + 1224720 2 2 2 2 3 3 3 3 3 3 3 5 7 + 1225000 2 2 2 5 5 5 5 5 7 7 + 1228800 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 + 1229312 2 2 2 2 2 2 2 2 2 7 7 7 7 + 1234800 2 2 2 2 3 3 5 5 7 7 7 + 1240029 3 3 3 3 3 3 3 3 3 3 3 7 + 1244160 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 + 1250000 2 2 2 2 5 5 5 5 5 5 5 + 1250235 3 3 3 3 3 3 5 7 7 7 + 1254400 2 2 2 2 2 2 2 2 2 2 5 5 7 7 + 1259712 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 + 1260000 2 2 2 2 2 3 3 5 5 5 5 7 + 1260525 3 5 5 7 7 7 7 7 + 1265625 3 3 3 3 5 5 5 5 5 5 + 1270080 2 2 2 2 2 2 3 3 3 3 5 7 7 + 1275750 2 3 3 3 3 3 3 5 5 5 7 + 1280000 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 + 1285956 2 2 3 3 3 3 3 3 3 3 7 7 + 1286250 2 3 5 5 5 5 7 7 7 + 1290240 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 7 + 1296000 2 2 2 2 2 2 2 3 3 3 3 5 5 5 + 1296540 2 2 3 3 3 5 7 7 7 7 + 1306368 2 2 2 2 2 2 2 2 3 3 3 3 3 3 7 + 1310720 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 + 1312200 2 2 2 3 3 3 3 3 3 3 3 5 5 + 1312500 2 2 3 5 5 5 5 5 5 7 + 1317120 2 2 2 2 2 2 2 2 3 5 7 7 7 + 1323000 2 2 2 3 3 3 5 5 5 7 7 + 1327104 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 + 1333584 2 2 2 2 3 3 3 3 3 7 7 7 + 1344000 2 2 2 2 2 2 2 2 2 3 5 5 5 7 + 1344560 2 2 2 2 5 7 7 7 7 7 + 1350000 2 2 2 2 3 3 3 5 5 5 5 5 + 1354752 2 2 2 2 2 2 2 2 2 2 3 3 3 7 7 + 1360800 2 2 2 2 2 3 3 3 3 3 5 5 7 + 1361367 3 3 3 3 7 7 7 7 7 + 1366875 3 3 3 3 3 3 3 5 5 5 5 + 1372000 2 2 2 2 2 5 5 5 7 7 7 + 1376256 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 + 1377810 2 3 3 3 3 3 3 3 3 3 5 7 + 1378125 3 3 5 5 5 5 5 7 7 + 1382400 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 + 1382976 2 2 2 2 2 2 3 3 7 7 7 7 + 1389150 2 3 3 3 3 5 5 7 7 7 + 1399680 2 2 2 2 2 2 2 3 3 3 3 3 3 3 5 + 1400000 2 2 2 2 2 2 5 5 5 5 5 7 + 1404928 2 2 2 2 2 2 2 2 2 2 2 2 7 7 7 + 1406250 2 3 3 5 5 5 5 5 5 5 + 1411200 2 2 2 2 2 2 2 3 3 5 5 7 7 + 1411788 2 2 3 7 7 7 7 7 7 + 1417176 2 2 2 3 3 3 3 3 3 3 3 3 3 3 + 1417500 2 2 3 3 3 3 5 5 5 5 7 + 1428840 2 2 2 3 3 3 3 3 3 5 7 7 + 1433600 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 7 + 1440000 2 2 2 2 2 2 2 2 3 3 5 5 5 5 + 1440600 2 2 2 3 5 5 7 7 7 7 + 1451520 2 2 2 2 2 2 2 2 2 3 3 3 3 5 7 + 1458000 2 2 2 2 3 3 3 3 3 3 5 5 5 + 1469664 2 2 2 2 2 3 3 3 3 3 3 3 3 7 + 1470000 2 2 2 2 3 5 5 5 5 7 7 + 1474560 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 + 1476225 3 3 3 3 3 3 3 3 3 3 5 5 + 1481760 2 2 2 2 2 3 3 3 5 7 7 7 + 1488375 3 3 3 3 3 5 5 5 7 7 + 1492992 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 + 1500000 2 2 2 2 2 3 5 5 5 5 5 5 + 1500282 2 3 3 3 3 3 3 3 7 7 7 + 1500625 5 5 5 5 7 7 7 7 + 1505280 2 2 2 2 2 2 2 2 2 2 2 3 5 7 7 + 1512000 2 2 2 2 2 2 3 3 3 5 5 5 7 + 1512630 2 3 3 5 7 7 7 7 7 + 1518750 2 3 3 3 3 3 5 5 5 5 5 + 1524096 2 2 2 2 2 2 2 3 3 3 3 3 7 7 + 1530900 2 2 3 3 3 3 3 3 3 5 5 7 + 1531250 2 5 5 5 5 5 5 7 7 + 1536000 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 + 1536640 2 2 2 2 2 2 2 5 7 7 7 7 + 1543500 2 2 3 3 5 5 5 7 7 7 + 1548288 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 + 1555200 2 2 2 2 2 2 2 2 3 3 3 3 3 5 5 + 1555848 2 2 2 3 3 3 3 7 7 7 7 + 1562500 2 2 5 5 5 5 5 5 5 5 + 1568000 2 2 2 2 2 2 2 2 5 5 5 7 7 + 1572864 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 + 1574640 2 2 2 2 3 3 3 3 3 3 3 3 3 5 + 1575000 2 2 2 3 3 5 5 5 5 5 7 + 1580544 2 2 2 2 2 2 2 2 2 3 3 7 7 7 + 1587600 2 2 2 2 3 3 3 3 5 5 7 7 + 1594323 3 3 3 3 3 3 3 3 3 3 3 3 3 + 1600000 2 2 2 2 2 2 2 2 2 5 5 5 5 5 + 1605632 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 + 1607445 3 3 3 3 3 3 3 3 5 7 7 + 1612800 2 2 2 2 2 2 2 2 2 2 3 3 5 5 7 + 1613472 2 2 2 2 2 3 7 7 7 7 7 + 1620000 2 2 2 2 2 3 3 3 3 5 5 5 5 + 1620675 3 3 3 5 5 7 7 7 7 + 1632960 2 2 2 2 2 2 3 3 3 3 3 3 5 7 + 1638400 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 + 1640250 2 3 3 3 3 3 3 3 3 5 5 5 + 1640625 3 5 5 5 5 5 5 5 7 + 1646400 2 2 2 2 2 2 3 5 5 7 7 7 + 1647086 2 7 7 7 7 7 7 7 + 1653372 2 2 3 3 3 3 3 3 3 3 3 3 7 + 1653750 2 3 3 3 5 5 5 5 7 7 + 1658880 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 + 1666980 2 2 3 3 3 3 3 5 7 7 7 + 1679616 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 + 1680000 2 2 2 2 2 2 2 3 5 5 5 5 7 + 1680700 2 2 5 5 7 7 7 7 7 + 1687500 2 2 3 3 3 5 5 5 5 5 5 + 1693440 2 2 2 2 2 2 2 2 3 3 3 5 7 7 + 1701000 2 2 2 3 3 3 3 3 5 5 5 7 + 1714608 2 2 2 2 3 3 3 3 3 3 3 7 7 + 1715000 2 2 2 5 5 5 5 7 7 7 + 1720320 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 + 1728000 2 2 2 2 2 2 2 2 2 3 3 3 5 5 5 + 1728720 2 2 2 2 3 3 5 7 7 7 7 + 1741824 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 7 + 1749600 2 2 2 2 2 3 3 3 3 3 3 3 5 5 + 1750000 2 2 2 2 5 5 5 5 5 5 7 + 1750329 3 3 3 3 3 3 7 7 7 7 + 1756160 2 2 2 2 2 2 2 2 2 2 5 7 7 7 + 1764000 2 2 2 2 2 3 3 5 5 5 7 7 + 1764735 3 5 7 7 7 7 7 7 + 1769472 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 + 1771470 2 3 3 3 3 3 3 3 3 3 3 3 5 + 1771875 3 3 3 3 5 5 5 5 5 7 + 1778112 2 2 2 2 2 2 3 3 3 3 7 7 7 + 1786050 2 3 3 3 3 3 3 5 5 7 7 + 1792000 2 2 2 2 2 2 2 2 2 2 2 5 5 5 7 + 1800000 2 2 2 2 2 2 3 3 5 5 5 5 5 + 1800750 2 3 5 5 5 7 7 7 7 + 1806336 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 7 + 1814400 2 2 2 2 2 2 2 3 3 3 3 5 5 7 + 1815156 2 2 3 3 3 7 7 7 7 7 + 1822500 2 2 3 3 3 3 3 3 5 5 5 5 + 1835008 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 + 1837080 2 2 2 3 3 3 3 3 3 3 3 5 7 + 1837500 2 2 3 5 5 5 5 5 7 7 + 1843200 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 + 1843968 2 2 2 2 2 2 2 2 3 7 7 7 7 + 1852200 2 2 2 3 3 3 5 5 7 7 7 + 1866240 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 + 1875000 2 2 2 3 5 5 5 5 5 5 5 + 1881600 2 2 2 2 2 2 2 2 2 3 5 5 7 7 + 1882384 2 2 2 2 7 7 7 7 7 7 + 1889568 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 + 1890000 2 2 2 2 3 3 3 5 5 5 5 7 + 1905120 2 2 2 2 2 3 3 3 3 3 5 7 7 + 1913625 3 3 3 3 3 3 3 5 5 5 7 + 1920000 2 2 2 2 2 2 2 2 2 2 3 5 5 5 5 + 1920800 2 2 2 2 2 5 5 7 7 7 7 + 1928934 2 3 3 3 3 3 3 3 3 3 7 7 + 1929375 3 3 5 5 5 5 7 7 7 + 1935360 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 7 + 1944000 2 2 2 2 2 2 3 3 3 3 3 5 5 5 + 1944810 2 3 3 3 3 5 7 7 7 7 + 1953125 5 5 5 5 5 5 5 5 5 + 1959552 2 2 2 2 2 2 2 3 3 3 3 3 3 3 7 + 1960000 2 2 2 2 2 2 5 5 5 5 7 7 + 1966080 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 + 1968300 2 2 3 3 3 3 3 3 3 3 3 5 5 + 1968750 2 3 3 5 5 5 5 5 5 7 + 1975680 2 2 2 2 2 2 2 3 3 5 7 7 7 + 1984500 2 2 3 3 3 3 5 5 5 7 7 + 1990656 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 + 2000000 2 2 2 2 2 2 2 5 5 5 5 5 5 + 2000376 2 2 2 3 3 3 3 3 3 7 7 7 + 2007040 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 7 + 2016000 2 2 2 2 2 2 2 2 3 3 5 5 5 7 + 2016840 2 2 2 3 5 7 7 7 7 7 + 2025000 2 2 2 3 3 3 3 5 5 5 5 5 + 2032128 2 2 2 2 2 2 2 2 2 3 3 3 3 7 7 + 2041200 2 2 2 2 3 3 3 3 3 3 5 5 7 + 2048000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 + 2058000 2 2 2 2 3 5 5 5 7 7 7 + 2064384 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 + 2066715 3 3 3 3 3 3 3 3 3 3 5 7 + 2073600 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 + 2074464 2 2 2 2 2 3 3 3 7 7 7 7 + 2083725 3 3 3 3 3 5 5 7 7 7 + 2097152 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 2099520 2 2 2 2 2 2 3 3 3 3 3 3 3 3 5 + 2100000 2 2 2 2 2 3 5 5 5 5 5 7 + 2100875 5 5 5 7 7 7 7 7 + 2107392 2 2 2 2 2 2 2 2 2 2 2 3 7 7 7 + 2109375 3 3 3 5 5 5 5 5 5 5 + 2116800 2 2 2 2 2 2 3 3 3 5 5 7 7 + 2117682 2 3 3 7 7 7 7 7 7 + 2125764 2 2 3 3 3 3 3 3 3 3 3 3 3 3 + 2126250 2 3 3 3 3 3 5 5 5 5 7 + 2143260 2 2 3 3 3 3 3 3 3 5 7 7 + 2143750 2 5 5 5 5 5 7 7 7 + 2150400 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 7 + 2151296 2 2 2 2 2 2 2 7 7 7 7 7 + 2160000 2 2 2 2 2 2 2 3 3 3 5 5 5 5 + 2160900 2 2 3 3 5 5 7 7 7 7 + 2177280 2 2 2 2 2 2 2 2 3 3 3 3 3 5 7 + 2187000 2 2 2 3 3 3 3 3 3 3 5 5 5 + 2187500 2 2 5 5 5 5 5 5 5 7 + 2195200 2 2 2 2 2 2 2 2 5 5 7 7 7 + 2204496 2 2 2 2 3 3 3 3 3 3 3 3 3 7 + 2205000 2 2 2 3 3 5 5 5 5 7 7 + 2211840 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 + 2222640 2 2 2 2 3 3 3 3 5 7 7 7 + 2239488 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 + 2240000 2 2 2 2 2 2 2 2 2 5 5 5 5 7 + 2250000 2 2 2 2 3 3 5 5 5 5 5 5 + 2250423 3 3 3 3 3 3 3 3 7 7 7 + 2257920 2 2 2 2 2 2 2 2 2 2 3 3 5 7 7 + 2268000 2 2 2 2 2 3 3 3 3 5 5 5 7 + 2268945 3 3 3 5 7 7 7 7 7 + 2278125 3 3 3 3 3 3 5 5 5 5 5 + 2286144 2 2 2 2 2 2 3 3 3 3 3 3 7 7 + 2293760 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 + 2296350 2 3 3 3 3 3 3 3 3 5 5 7 + 2296875 3 5 5 5 5 5 5 7 7 + 2304000 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 5 + 2304960 2 2 2 2 2 2 3 5 7 7 7 7 + 2315250 2 3 3 3 5 5 5 7 7 7 + 2322432 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 + 2332800 2 2 2 2 2 2 2 3 3 3 3 3 3 5 5 + 2333772 2 2 3 3 3 3 3 7 7 7 7 + 2343750 2 3 5 5 5 5 5 5 5 5 + 2352000 2 2 2 2 2 2 2 3 5 5 5 7 7 + 2352980 2 2 5 7 7 7 7 7 7 + 2359296 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 + 2361960 2 2 2 3 3 3 3 3 3 3 3 3 3 5 + 2362500 2 2 3 3 3 5 5 5 5 5 7 + 2370816 2 2 2 2 2 2 2 2 3 3 3 7 7 7 + 2381400 2 2 2 3 3 3 3 3 5 5 7 7 + 2400000 2 2 2 2 2 2 2 2 3 5 5 5 5 5 + 2401000 2 2 2 5 5 5 7 7 7 7 + 2408448 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 7 + 2419200 2 2 2 2 2 2 2 2 2 3 3 3 5 5 7 + 2420208 2 2 2 2 3 3 7 7 7 7 7 + 2430000 2 2 2 2 3 3 3 3 3 5 5 5 5 + 2449440 2 2 2 2 2 3 3 3 3 3 3 3 5 7 + 2450000 2 2 2 2 5 5 5 5 5 7 7 + 2457600 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 + 2458624 2 2 2 2 2 2 2 2 2 2 7 7 7 7 + 2460375 3 3 3 3 3 3 3 3 3 5 5 5 + 2469600 2 2 2 2 2 3 3 5 5 7 7 7 + 2470629 3 7 7 7 7 7 7 7 + 2480058 2 3 3 3 3 3 3 3 3 3 3 3 7 + 2480625 3 3 3 3 5 5 5 5 7 7 + 2488320 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 + 2500000 2 2 2 2 2 5 5 5 5 5 5 5 + 2500470 2 3 3 3 3 3 3 5 7 7 7 + 2508800 2 2 2 2 2 2 2 2 2 2 2 5 5 7 7 + 2519424 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 + 2520000 2 2 2 2 2 2 3 3 5 5 5 5 7 + 2521050 2 3 5 5 7 7 7 7 7 + 2531250 2 3 3 3 3 5 5 5 5 5 5 + 2540160 2 2 2 2 2 2 2 3 3 3 3 5 7 7 + 2551500 2 2 3 3 3 3 3 3 5 5 5 7 + 2560000 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 + 2571912 2 2 2 3 3 3 3 3 3 3 3 7 7 + 2572500 2 2 3 5 5 5 5 7 7 7 + 2580480 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 7 + 2592000 2 2 2 2 2 2 2 2 3 3 3 3 5 5 5 + 2593080 2 2 2 3 3 3 5 7 7 7 7 + 2612736 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 7 + 2621440 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 + 2624400 2 2 2 2 3 3 3 3 3 3 3 3 5 5 + 2625000 2 2 2 3 5 5 5 5 5 5 7 + 2634240 2 2 2 2 2 2 2 2 2 3 5 7 7 7 + 2646000 2 2 2 2 3 3 3 5 5 5 7 7 + 2654208 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 + 2657205 3 3 3 3 3 3 3 3 3 3 3 3 5 + 2667168 2 2 2 2 2 3 3 3 3 3 7 7 7 + 2679075 3 3 3 3 3 3 3 5 5 7 7 + 2688000 2 2 2 2 2 2 2 2 2 2 3 5 5 5 7 + 2689120 2 2 2 2 2 5 7 7 7 7 7 + 2700000 2 2 2 2 2 3 3 3 5 5 5 5 5 + 2701125 3 3 5 5 5 7 7 7 7 + 2709504 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 7 + 2721600 2 2 2 2 2 2 3 3 3 3 3 5 5 7 + 2722734 2 3 3 3 3 7 7 7 7 7 + 2733750 2 3 3 3 3 3 3 3 5 5 5 5 + 2734375 5 5 5 5 5 5 5 5 7 + 2744000 2 2 2 2 2 2 5 5 5 7 7 7 + 2752512 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 + 2755620 2 2 3 3 3 3 3 3 3 3 3 5 7 + 2756250 2 3 3 5 5 5 5 5 7 7 + 2764800 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 + 2765952 2 2 2 2 2 2 2 3 3 7 7 7 7 + 2778300 2 2 3 3 3 3 5 5 7 7 7 + 2799360 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 5 + 2800000 2 2 2 2 2 2 2 5 5 5 5 5 7 + 2809856 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 7 + 2812500 2 2 3 3 5 5 5 5 5 5 5 + 2822400 2 2 2 2 2 2 2 2 3 3 5 5 7 7 + 2823576 2 2 2 3 7 7 7 7 7 7 + 2834352 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 + 2835000 2 2 2 3 3 3 3 5 5 5 5 7 + 2857680 2 2 2 2 3 3 3 3 3 3 5 7 7 + 2867200 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 7 + 2880000 2 2 2 2 2 2 2 2 2 3 3 5 5 5 5 + 2881200 2 2 2 2 3 5 5 7 7 7 7 + 2893401 3 3 3 3 3 3 3 3 3 3 7 7 + 2903040 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 7 + 2916000 2 2 2 2 2 3 3 3 3 3 3 5 5 5 + 2917215 3 3 3 3 3 5 7 7 7 7 + 2939328 2 2 2 2 2 2 3 3 3 3 3 3 3 3 7 + 2940000 2 2 2 2 2 3 5 5 5 5 7 7 + 2941225 5 5 7 7 7 7 7 7 + 2949120 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 + 2952450 2 3 3 3 3 3 3 3 3 3 3 5 5 + 2953125 3 3 3 5 5 5 5 5 5 7 + 2963520 2 2 2 2 2 2 3 3 3 5 7 7 7 + 2976750 2 3 3 3 3 3 5 5 5 7 7 + 2985984 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 + 3000000 2 2 2 2 2 2 3 5 5 5 5 5 5 + 3000564 2 2 3 3 3 3 3 3 3 7 7 7 + 3001250 2 5 5 5 5 7 7 7 7 + 3010560 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 7 + 3024000 2 2 2 2 2 2 2 3 3 3 5 5 5 7 + 3025260 2 2 3 3 5 7 7 7 7 7 + 3037500 2 2 3 3 3 3 3 5 5 5 5 5 + 3048192 2 2 2 2 2 2 2 2 3 3 3 3 3 7 7 + 3061800 2 2 2 3 3 3 3 3 3 3 5 5 7 + 3062500 2 2 5 5 5 5 5 5 7 7 + 3072000 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 + 3073280 2 2 2 2 2 2 2 2 5 7 7 7 7 + 3087000 2 2 2 3 3 5 5 5 7 7 7 + 3096576 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 + 3110400 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 5 + 3111696 2 2 2 2 3 3 3 3 7 7 7 7 + 3125000 2 2 2 5 5 5 5 5 5 5 5 + 3136000 2 2 2 2 2 2 2 2 2 5 5 5 7 7 + 3145728 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 + 3149280 2 2 2 2 2 3 3 3 3 3 3 3 3 3 5 + 3150000 2 2 2 2 3 3 5 5 5 5 5 7 + 3161088 2 2 2 2 2 2 2 2 2 2 3 3 7 7 7 + 3175200 2 2 2 2 2 3 3 3 3 5 5 7 7 + 3176523 3 3 3 7 7 7 7 7 7 + 3188646 2 3 3 3 3 3 3 3 3 3 3 3 3 3 + 3189375 3 3 3 3 3 3 5 5 5 5 7 + 3200000 2 2 2 2 2 2 2 2 2 2 5 5 5 5 5 + 3211264 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 + 3214890 2 3 3 3 3 3 3 3 3 5 7 7 + 3215625 3 5 5 5 5 5 7 7 7 + 3225600 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 7 + 3226944 2 2 2 2 2 2 3 7 7 7 7 7 + 3240000 2 2 2 2 2 2 3 3 3 3 5 5 5 5 + 3241350 2 3 3 3 5 5 7 7 7 7 + 3265920 2 2 2 2 2 2 2 3 3 3 3 3 3 5 7 + 3276800 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 + 3280500 2 2 3 3 3 3 3 3 3 3 5 5 5 + 3281250 2 3 5 5 5 5 5 5 5 7 + 3292800 2 2 2 2 2 2 2 3 5 5 7 7 7 + 3294172 2 2 7 7 7 7 7 7 7 + 3306744 2 2 2 3 3 3 3 3 3 3 3 3 3 7 + 3307500 2 2 3 3 3 5 5 5 5 7 7 + 3317760 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 + 3333960 2 2 2 3 3 3 3 3 5 7 7 7 + 3359232 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 + 3360000 2 2 2 2 2 2 2 2 3 5 5 5 5 7 + 3361400 2 2 2 5 5 7 7 7 7 7 + 3375000 2 2 2 3 3 3 5 5 5 5 5 5 + 3386880 2 2 2 2 2 2 2 2 2 3 3 3 5 7 7 + 3402000 2 2 2 2 3 3 3 3 3 5 5 5 7 + 3429216 2 2 2 2 2 3 3 3 3 3 3 3 7 7 + 3430000 2 2 2 2 5 5 5 5 7 7 7 + 3440640 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 + 3444525 3 3 3 3 3 3 3 3 3 5 5 7 + 3456000 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 5 + 3457440 2 2 2 2 2 3 3 5 7 7 7 7 + 3472875 3 3 3 3 5 5 5 7 7 7 + 3483648 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 7 + 3499200 2 2 2 2 2 2 3 3 3 3 3 3 3 5 5 + 3500000 2 2 2 2 2 5 5 5 5 5 5 7 + 3500658 2 3 3 3 3 3 3 7 7 7 7 + 3512320 2 2 2 2 2 2 2 2 2 2 2 5 7 7 7 + 3515625 3 3 5 5 5 5 5 5 5 5 + 3528000 2 2 2 2 2 2 3 3 5 5 5 7 7 + 3529470 2 3 5 7 7 7 7 7 7 + 3538944 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 + 3542940 2 2 3 3 3 3 3 3 3 3 3 3 3 5 + 3543750 2 3 3 3 3 5 5 5 5 5 7 + 3556224 2 2 2 2 2 2 2 3 3 3 3 7 7 7 + 3572100 2 2 3 3 3 3 3 3 5 5 7 7 + 3584000 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 7 + 3600000 2 2 2 2 2 2 2 3 3 5 5 5 5 5 + 3601500 2 2 3 5 5 5 7 7 7 7 + 3612672 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 7 + 3628800 2 2 2 2 2 2 2 2 3 3 3 3 5 5 7 + 3630312 2 2 2 3 3 3 7 7 7 7 7 + 3645000 2 2 2 3 3 3 3 3 3 5 5 5 5 + 3670016 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 + 3674160 2 2 2 2 3 3 3 3 3 3 3 3 5 7 + 3675000 2 2 2 3 5 5 5 5 5 7 7 + 3686400 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 + 3687936 2 2 2 2 2 2 2 2 2 3 7 7 7 7 + 3704400 2 2 2 2 3 3 3 5 5 7 7 7 + 3720087 3 3 3 3 3 3 3 3 3 3 3 3 7 + 3732480 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 + 3750000 2 2 2 2 3 5 5 5 5 5 5 5 + 3750705 3 3 3 3 3 3 3 5 7 7 7 + 3763200 2 2 2 2 2 2 2 2 2 2 3 5 5 7 7 + 3764768 2 2 2 2 2 7 7 7 7 7 7 + 3779136 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 + 3780000 2 2 2 2 2 3 3 3 5 5 5 5 7 + 3781575 3 3 5 5 7 7 7 7 7 + 3796875 3 3 3 3 3 5 5 5 5 5 5 + 3810240 2 2 2 2 2 2 3 3 3 3 3 5 7 7 + 3827250 2 3 3 3 3 3 3 3 5 5 5 7 + 3828125 5 5 5 5 5 5 5 7 7 + 3840000 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 5 + 3841600 2 2 2 2 2 2 5 5 7 7 7 7 + 3857868 2 2 3 3 3 3 3 3 3 3 3 7 7 + 3858750 2 3 3 5 5 5 5 7 7 7 + 3870720 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 7 + 3888000 2 2 2 2 2 2 2 3 3 3 3 3 5 5 5 + 3889620 2 2 3 3 3 3 5 7 7 7 7 + 3906250 2 5 5 5 5 5 5 5 5 5 + 3919104 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 7 + 3920000 2 2 2 2 2 2 2 5 5 5 5 7 7 + 3932160 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 + 3936600 2 2 2 3 3 3 3 3 3 3 3 3 5 5 + 3937500 2 2 3 3 5 5 5 5 5 5 7 + 3951360 2 2 2 2 2 2 2 2 3 3 5 7 7 7 + 3969000 2 2 2 3 3 3 3 5 5 5 7 7 + 3981312 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 + 4000000 2 2 2 2 2 2 2 2 5 5 5 5 5 5 + 4000752 2 2 2 2 3 3 3 3 3 3 7 7 7 + 4014080 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 7 + 4032000 2 2 2 2 2 2 2 2 2 3 3 5 5 5 7 + 4033680 2 2 2 2 3 5 7 7 7 7 7 + 4050000 2 2 2 2 3 3 3 3 5 5 5 5 5 + 4064256 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 7 + 4082400 2 2 2 2 2 3 3 3 3 3 3 5 5 7 + 4084101 3 3 3 3 3 7 7 7 7 7 + 4096000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 + 4100625 3 3 3 3 3 3 3 3 5 5 5 5 + 4116000 2 2 2 2 2 3 5 5 5 7 7 7 + 4117715 5 7 7 7 7 7 7 7 + 4128768 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 + 4133430 2 3 3 3 3 3 3 3 3 3 3 5 7 + 4134375 3 3 3 5 5 5 5 5 7 7 + 4147200 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 + 4148928 2 2 2 2 2 2 3 3 3 7 7 7 7 + 4167450 2 3 3 3 3 3 5 5 7 7 7 + 4194304 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 4199040 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 5 + 4200000 2 2 2 2 2 2 3 5 5 5 5 5 7 + 4201750 2 5 5 5 7 7 7 7 7 + 4214784 2 2 2 2 2 2 2 2 2 2 2 2 3 7 7 7 + 4218750 2 3 3 3 5 5 5 5 5 5 5 + 4233600 2 2 2 2 2 2 2 3 3 3 5 5 7 7 + 4235364 2 2 3 3 7 7 7 7 7 7 + 4251528 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 + 4252500 2 2 3 3 3 3 3 5 5 5 5 7 + 4286520 2 2 2 3 3 3 3 3 3 3 5 7 7 + 4287500 2 2 5 5 5 5 5 7 7 7 + 4300800 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 7 + 4302592 2 2 2 2 2 2 2 2 7 7 7 7 7 + 4320000 2 2 2 2 2 2 2 2 3 3 3 5 5 5 5 + 4321800 2 2 2 3 3 5 5 7 7 7 7 + 4354560 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 7 + 4374000 2 2 2 2 3 3 3 3 3 3 3 5 5 5 + 4375000 2 2 2 5 5 5 5 5 5 5 7 + 4390400 2 2 2 2 2 2 2 2 2 5 5 7 7 7 + 4408992 2 2 2 2 2 3 3 3 3 3 3 3 3 3 7 + 4410000 2 2 2 2 3 3 5 5 5 5 7 7 + 4423680 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 + 4428675 3 3 3 3 3 3 3 3 3 3 3 5 5 + 4445280 2 2 2 2 2 3 3 3 3 5 7 7 7 + 4465125 3 3 3 3 3 3 5 5 5 7 7 + 4478976 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 + 4480000 2 2 2 2 2 2 2 2 2 2 5 5 5 5 7 + 4500000 2 2 2 2 2 3 3 5 5 5 5 5 5 + 4500846 2 3 3 3 3 3 3 3 3 7 7 7 + 4501875 3 5 5 5 5 7 7 7 7 + 4515840 2 2 2 2 2 2 2 2 2 2 2 3 3 5 7 7 + 4536000 2 2 2 2 2 2 3 3 3 3 5 5 5 7 + 4537890 2 3 3 3 5 7 7 7 7 7 + 4556250 2 3 3 3 3 3 3 5 5 5 5 5 + 4572288 2 2 2 2 2 2 2 3 3 3 3 3 3 7 7 + 4587520 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 + 4592700 2 2 3 3 3 3 3 3 3 3 5 5 7 + 4593750 2 3 5 5 5 5 5 5 7 7 + 4608000 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 5 + 4609920 2 2 2 2 2 2 2 3 5 7 7 7 7 + 4630500 2 2 3 3 3 5 5 5 7 7 7 + 4644864 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 + 4665600 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 5 + 4667544 2 2 2 3 3 3 3 3 7 7 7 7 + 4687500 2 2 3 5 5 5 5 5 5 5 5 + 4704000 2 2 2 2 2 2 2 2 3 5 5 5 7 7 + 4705960 2 2 2 5 7 7 7 7 7 7 + 4718592 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 + 4723920 2 2 2 2 3 3 3 3 3 3 3 3 3 3 5 + 4725000 2 2 2 3 3 3 5 5 5 5 5 7 + 4741632 2 2 2 2 2 2 2 2 2 3 3 3 7 7 7 + 4762800 2 2 2 2 3 3 3 3 3 5 5 7 7 + 4782969 3 3 3 3 3 3 3 3 3 3 3 3 3 3 + 4800000 2 2 2 2 2 2 2 2 2 3 5 5 5 5 5 + 4802000 2 2 2 2 5 5 5 7 7 7 7 + 4816896 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 7 + 4822335 3 3 3 3 3 3 3 3 3 5 7 7 + 4838400 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 7 + 4840416 2 2 2 2 2 3 3 7 7 7 7 7 + 4860000 2 2 2 2 2 3 3 3 3 3 5 5 5 5 + 4862025 3 3 3 3 5 5 7 7 7 7 + 4898880 2 2 2 2 2 2 3 3 3 3 3 3 3 5 7 + 4900000 2 2 2 2 2 5 5 5 5 5 7 7 + 4915200 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 + 4917248 2 2 2 2 2 2 2 2 2 2 2 7 7 7 7 + 4920750 2 3 3 3 3 3 3 3 3 3 5 5 5 + 4921875 3 3 5 5 5 5 5 5 5 7 + 4939200 2 2 2 2 2 2 3 3 5 5 7 7 7 + 4941258 2 3 7 7 7 7 7 7 7 + 4960116 2 2 3 3 3 3 3 3 3 3 3 3 3 7 + 4961250 2 3 3 3 3 5 5 5 5 7 7 + 4976640 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 + 5000000 2 2 2 2 2 2 5 5 5 5 5 5 5 + 5000940 2 2 3 3 3 3 3 3 5 7 7 7 + 5017600 2 2 2 2 2 2 2 2 2 2 2 2 5 5 7 7 + 5038848 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 + 5040000 2 2 2 2 2 2 2 3 3 5 5 5 5 7 + 5042100 2 2 3 5 5 7 7 7 7 7 + 5062500 2 2 3 3 3 3 5 5 5 5 5 5 + 5080320 2 2 2 2 2 2 2 2 3 3 3 3 5 7 7 + 5103000 2 2 2 3 3 3 3 3 3 5 5 5 7 + 5120000 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 + 5143824 2 2 2 2 3 3 3 3 3 3 3 3 7 7 + 5145000 2 2 2 3 5 5 5 5 7 7 7 + 5160960 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 7 + 5184000 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 5 + 5186160 2 2 2 2 3 3 3 5 7 7 7 7 + 5225472 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 7 + 5242880 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 + 5248800 2 2 2 2 2 3 3 3 3 3 3 3 3 5 5 + 5250000 2 2 2 2 3 5 5 5 5 5 5 7 + 5250987 3 3 3 3 3 3 3 7 7 7 7 + 5268480 2 2 2 2 2 2 2 2 2 2 3 5 7 7 7 + 5292000 2 2 2 2 2 3 3 3 5 5 5 7 7 + 5294205 3 3 5 7 7 7 7 7 7 + 5308416 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 + 5314410 2 3 3 3 3 3 3 3 3 3 3 3 3 5 + 5315625 3 3 3 3 3 5 5 5 5 5 7 + 5334336 2 2 2 2 2 2 3 3 3 3 3 7 7 7 + 5358150 2 3 3 3 3 3 3 3 5 5 7 7 + 5359375 5 5 5 5 5 5 7 7 7 + 5376000 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 7 + 5378240 2 2 2 2 2 2 5 7 7 7 7 7 + 5400000 2 2 2 2 2 2 3 3 3 5 5 5 5 5 + 5402250 2 3 3 5 5 5 7 7 7 7 + 5419008 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 7 + 5443200 2 2 2 2 2 2 2 3 3 3 3 3 5 5 7 + 5445468 2 2 3 3 3 3 7 7 7 7 7 + 5467500 2 2 3 3 3 3 3 3 3 5 5 5 5 + 5468750 2 5 5 5 5 5 5 5 5 7 + 5488000 2 2 2 2 2 2 2 5 5 5 7 7 7 + 5505024 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 7 + 5511240 2 2 2 3 3 3 3 3 3 3 3 3 5 7 + 5512500 2 2 3 3 5 5 5 5 5 7 7 + 5529600 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 + 5531904 2 2 2 2 2 2 2 2 3 3 7 7 7 7 + 5556600 2 2 2 3 3 3 3 5 5 7 7 7 + 5598720 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 5 + 5600000 2 2 2 2 2 2 2 2 5 5 5 5 5 7 + 5619712 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 7 + 5625000 2 2 2 3 3 5 5 5 5 5 5 5 + 5644800 2 2 2 2 2 2 2 2 2 3 3 5 5 7 7 + 5647152 2 2 2 2 3 7 7 7 7 7 7 + 5668704 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 + 5670000 2 2 2 2 3 3 3 3 5 5 5 5 7 + 5715360 2 2 2 2 2 3 3 3 3 3 3 5 7 7 + 5734400 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 7 + 5740875 3 3 3 3 3 3 3 3 5 5 5 7 + 5760000 2 2 2 2 2 2 2 2 2 2 3 3 5 5 5 5 + 5762400 2 2 2 2 2 3 5 5 7 7 7 7 + 5764801 7 7 7 7 7 7 7 7 + 5786802 2 3 3 3 3 3 3 3 3 3 3 7 7 + 5788125 3 3 3 5 5 5 5 7 7 7 + 5806080 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 7 + 5832000 2 2 2 2 2 2 3 3 3 3 3 3 5 5 5 + 5834430 2 3 3 3 3 3 5 7 7 7 7 + 5859375 3 5 5 5 5 5 5 5 5 5 + 5878656 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 7 + 5880000 2 2 2 2 2 2 3 5 5 5 5 7 7 + 5882450 2 5 5 7 7 7 7 7 7 + 5898240 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 + 5904900 2 2 3 3 3 3 3 3 3 3 3 3 5 5 + 5906250 2 3 3 3 5 5 5 5 5 5 7 + 5927040 2 2 2 2 2 2 2 3 3 3 5 7 7 7 + 5953500 2 2 3 3 3 3 3 5 5 5 7 7 + 5971968 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 + 6000000 2 2 2 2 2 2 2 3 5 5 5 5 5 5 + 6001128 2 2 2 3 3 3 3 3 3 3 7 7 7 + 6002500 2 2 5 5 5 5 7 7 7 7 + 6021120 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 7 + 6048000 2 2 2 2 2 2 2 2 3 3 3 5 5 5 7 + 6050520 2 2 2 3 3 5 7 7 7 7 7 + 6075000 2 2 2 3 3 3 3 3 5 5 5 5 5 + 6096384 2 2 2 2 2 2 2 2 2 3 3 3 3 3 7 7 + 6123600 2 2 2 2 3 3 3 3 3 3 3 5 5 7 + 6125000 2 2 2 5 5 5 5 5 5 7 7 + 6144000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 + 6146560 2 2 2 2 2 2 2 2 2 5 7 7 7 7 + 6174000 2 2 2 2 3 3 5 5 5 7 7 7 + 6193152 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 7 + 6200145 3 3 3 3 3 3 3 3 3 3 3 5 7 + 6220800 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 5 5 + 6223392 2 2 2 2 2 3 3 3 3 7 7 7 7 + 6250000 2 2 2 2 5 5 5 5 5 5 5 5 + 6251175 3 3 3 3 3 3 5 5 7 7 7 + 6272000 2 2 2 2 2 2 2 2 2 2 5 5 5 7 7 + 6291456 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 + 6298560 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 5 + 6300000 2 2 2 2 2 3 3 5 5 5 5 5 7 + 6302625 3 5 5 5 7 7 7 7 7 + 6322176 2 2 2 2 2 2 2 2 2 2 2 3 3 7 7 7 + 6328125 3 3 3 3 5 5 5 5 5 5 5 + 6350400 2 2 2 2 2 2 3 3 3 3 5 5 7 7 + 6353046 2 3 3 3 7 7 7 7 7 7 + 6377292 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 + 6378750 2 3 3 3 3 3 3 5 5 5 5 7 + 6400000 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 5 + 6422528 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 + 6429780 2 2 3 3 3 3 3 3 3 3 5 7 7 + 6431250 2 3 5 5 5 5 5 7 7 7 + 6451200 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 7 + 6453888 2 2 2 2 2 2 2 3 7 7 7 7 7 + 6480000 2 2 2 2 2 2 2 3 3 3 3 5 5 5 5 + 6482700 2 2 3 3 3 5 5 7 7 7 7 + 6531840 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 7 + 6553600 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 + 6561000 2 2 2 3 3 3 3 3 3 3 3 5 5 5 + 6562500 2 2 3 5 5 5 5 5 5 5 7 + 6585600 2 2 2 2 2 2 2 2 3 5 5 7 7 7 + 6588344 2 2 2 7 7 7 7 7 7 7 + 6613488 2 2 2 2 3 3 3 3 3 3 3 3 3 3 7 + 6615000 2 2 2 3 3 3 5 5 5 5 7 7 + 6635520 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 + 6667920 2 2 2 2 3 3 3 3 3 5 7 7 7 + 6718464 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 + 6720000 2 2 2 2 2 2 2 2 2 3 5 5 5 5 7 + 6722800 2 2 2 2 5 5 7 7 7 7 7 + 6750000 2 2 2 2 3 3 3 5 5 5 5 5 5 + 6751269 3 3 3 3 3 3 3 3 3 7 7 7 + 6773760 2 2 2 2 2 2 2 2 2 2 3 3 3 5 7 7 + 6804000 2 2 2 2 2 3 3 3 3 3 5 5 5 7 + 6806835 3 3 3 3 5 7 7 7 7 7 + 6834375 3 3 3 3 3 3 3 5 5 5 5 5 + 6858432 2 2 2 2 2 2 3 3 3 3 3 3 3 7 7 + 6860000 2 2 2 2 2 5 5 5 5 7 7 7 + 6881280 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 7 + 6889050 2 3 3 3 3 3 3 3 3 3 5 5 7 + 6890625 3 3 5 5 5 5 5 5 7 7 + 6912000 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 5 5 + 6914880 2 2 2 2 2 2 3 3 5 7 7 7 7 + 6945750 2 3 3 3 3 5 5 5 7 7 7 + 6967296 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 7 + 6998400 2 2 2 2 2 2 2 3 3 3 3 3 3 3 5 5 + 7000000 2 2 2 2 2 2 5 5 5 5 5 5 7 + 7001316 2 2 3 3 3 3 3 3 7 7 7 7 + 7024640 2 2 2 2 2 2 2 2 2 2 2 2 5 7 7 7 + 7031250 2 3 3 5 5 5 5 5 5 5 5 + 7056000 2 2 2 2 2 2 2 3 3 5 5 5 7 7 + 7058940 2 2 3 5 7 7 7 7 7 7 + 7077888 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 + 7085880 2 2 2 3 3 3 3 3 3 3 3 3 3 3 5 + 7087500 2 2 3 3 3 3 5 5 5 5 5 7 + 7112448 2 2 2 2 2 2 2 2 3 3 3 3 7 7 7 + 7144200 2 2 2 3 3 3 3 3 3 5 5 7 7 + 7168000 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 7 + 7200000 2 2 2 2 2 2 2 2 3 3 5 5 5 5 5 + 7203000 2 2 2 3 5 5 5 7 7 7 7 + 7225344 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 7 + 7257600 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 7 + 7260624 2 2 2 2 3 3 3 7 7 7 7 7 + 7290000 2 2 2 2 3 3 3 3 3 3 5 5 5 5 + 7340032 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 + 7348320 2 2 2 2 2 3 3 3 3 3 3 3 3 5 7 + 7350000 2 2 2 2 3 5 5 5 5 5 7 7 + 7372800 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 5 5 + 7375872 2 2 2 2 2 2 2 2 2 2 3 7 7 7 7 + 7381125 3 3 3 3 3 3 3 3 3 3 5 5 5 + 7408800 2 2 2 2 2 3 3 3 5 5 7 7 7 + 7411887 3 3 7 7 7 7 7 7 7 + 7440174 2 3 3 3 3 3 3 3 3 3 3 3 3 7 + 7441875 3 3 3 3 3 5 5 5 5 7 7 + 7464960 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 5 + 7500000 2 2 2 2 2 3 5 5 5 5 5 5 5 + 7501410 2 3 3 3 3 3 3 3 5 7 7 7 + 7503125 5 5 5 5 5 7 7 7 7 + 7526400 2 2 2 2 2 2 2 2 2 2 2 3 5 5 7 7 + 7529536 2 2 2 2 2 2 7 7 7 7 7 7 + 7558272 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 + 7560000 2 2 2 2 2 2 3 3 3 5 5 5 5 7 + 7563150 2 3 3 5 5 7 7 7 7 7 + 7593750 2 3 3 3 3 3 5 5 5 5 5 5 + 7620480 2 2 2 2 2 2 2 3 3 3 3 3 5 7 7 + 7654500 2 2 3 3 3 3 3 3 3 5 5 5 7 + 7656250 2 5 5 5 5 5 5 5 7 7 + 7680000 2 2 2 2 2 2 2 2 2 2 2 2 3 5 5 5 5 + 7683200 2 2 2 2 2 2 2 5 5 7 7 7 7 + 7715736 2 2 2 3 3 3 3 3 3 3 3 3 7 7 + 7717500 2 2 3 3 5 5 5 5 7 7 7 + 7741440 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 5 7 + 7776000 2 2 2 2 2 2 2 2 3 3 3 3 3 5 5 5 + 7779240 2 2 2 3 3 3 3 5 7 7 7 7 + 7812500 2 2 5 5 5 5 5 5 5 5 5 + 7838208 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 7 + 7840000 2 2 2 2 2 2 2 2 5 5 5 5 7 7 + 7864320 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 5 + 7873200 2 2 2 2 3 3 3 3 3 3 3 3 3 5 5 + 7875000 2 2 2 3 3 5 5 5 5 5 5 7 + 7902720 2 2 2 2 2 2 2 2 2 3 3 5 7 7 7 + 7938000 2 2 2 2 3 3 3 3 5 5 5 7 7 + 7962624 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 + 7971615 3 3 3 3 3 3 3 3 3 3 3 3 3 5 + 8000000 2 2 2 2 2 2 2 2 2 5 5 5 5 5 5 + 8001504 2 2 2 2 2 3 3 3 3 3 3 7 7 7 + 8028160 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 7 7 + 8037225 3 3 3 3 3 3 3 3 5 5 7 7 + 8064000 2 2 2 2 2 2 2 2 2 2 3 3 5 5 5 7 + 8067360 2 2 2 2 2 3 5 7 7 7 7 7 + 8100000 2 2 2 2 2 3 3 3 3 5 5 5 5 5 + 8103375 3 3 3 5 5 5 7 7 7 7 + 8128512 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 7 7 + 8164800 2 2 2 2 2 2 3 3 3 3 3 3 5 5 7 + 8168202 2 3 3 3 3 3 7 7 7 7 7 + 8192000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 + 8201250 2 3 3 3 3 3 3 3 3 5 5 5 5 + 8203125 3 5 5 5 5 5 5 5 5 7 + 8232000 2 2 2 2 2 2 3 5 5 5 7 7 7 + 8235430 2 5 7 7 7 7 7 7 7 + 8257536 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 7 + 8266860 2 2 3 3 3 3 3 3 3 3 3 3 5 7 + 8268750 2 3 3 3 5 5 5 5 5 7 7 + 8294400 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 5 5 + 8297856 2 2 2 2 2 2 2 3 3 3 7 7 7 7 + 8334900 2 2 3 3 3 3 3 5 5 7 7 7 + 8388608 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 diff --git a/lib/nuttal_window.f90 b/lib/nuttal_window.f90 index 25e2cddf..aa813b15 100755 --- a/lib/nuttal_window.f90 +++ b/lib/nuttal_window.f90 @@ -1,15 +1,15 @@ -subroutine nuttal_window(win,n) - real win(n) - - pi=4.0*atan(1.0) - a0=0.3635819 - a1=-0.4891775; - a2=0.1365995; - a3=-0.0106411; - do i=1,n - win(i)=a0+a1*cos(2*pi*(i-1)/(n))+ & - a2*cos(4*pi*(i-1)/(n))+ & - a3*cos(6*pi*(i-1)/(n)) - enddo - return -end subroutine nuttal_window +subroutine nuttal_window(win,n) + real win(n) + + pi=4.0*atan(1.0) + a0=0.3635819 + a1=-0.4891775; + a2=0.1365995; + a3=-0.0106411; + do i=1,n + win(i)=a0+a1*cos(2*pi*(i-1)/(n))+ & + a2*cos(4*pi*(i-1)/(n))+ & + a3*cos(6*pi*(i-1)/(n)) + enddo + return +end subroutine nuttal_window diff --git a/lib/osd128_90.f90 b/lib/osd128_90.f90 index 849a3b6f..75082bf5 100755 --- a/lib/osd128_90.f90 +++ b/lib/osd128_90.f90 @@ -1,375 +1,375 @@ -subroutine osd128_90(llr,apmask,ndeep,message77,cw,nhardmin,dmin) - -! Ordered-statistics decoder for the (128,90) code. - - integer, parameter:: N=128, K=90, M=N-K - integer*1 apmask(N),apmaskr(N) - integer*1 gen(K,N) - integer*1 genmrb(K,N),g2(N,K) - integer*1 temp(K),m0(K),me(K),mi(K),misub(K),e2sub(N-K),e2(N-K),ui(N-K) - integer*1 r2pat(N-K) - integer indices(N),nxor(N) - integer*1 cw(N),ce(N),c0(N),hdec(N) - integer*1 decoded(K) - integer*1 message77(77) - integer indx(N) - real llr(N),rx(N),absrx(N) - - include "ldpc_128_90_generator.f90" - - logical first,reset - data first/.true./ - save first,gen - - if( first ) then ! fill the generator matrix - gen=0 - do i=1,M - do j=1,23 - read(g(i)(j:j),"(Z1)") istr - ibmax=4 - if(j.eq.23) ibmax=2 - do jj=1, ibmax - irow=(j-1)*4+jj - if( btest(istr,4-jj) ) gen(irow,K+i)=1 - enddo - enddo - enddo - do irow=1,K - gen(irow,irow)=1 - enddo - first=.false. - endif - - rx=llr - apmaskr=apmask - d1=0. - ntheta=0 - npre1=0 - npre2=0 - nt=0 - -! Hard decisions on the received word. - hdec=0 - where(rx .ge. 0) hdec=1 - -! Use magnitude of received symbols as a measure of reliability. - absrx=abs(rx) - call indexx(absrx,N,indx) - -! Re-order columns of generator matrix in order of decreasing reliability. - do i=1,N - genmrb(1:K,i)=gen(1:K,indx(N+1-i)) - indices(i)=indx(N+1-i) - enddo - -! Do gaussian elimination to create a generator matrix with the most reliable -! received bits in positions 1:K in order of decreasing reliability (more or less). - do id=1,K ! diagonal element indices - do icol=id,K+20 ! The 20 is ad hoc - beware - iflag=0 - if( genmrb(id,icol) .eq. 1 ) then - iflag=1 - if( icol .ne. id ) then ! reorder column - temp(1:K)=genmrb(1:K,id) - genmrb(1:K,id)=genmrb(1:K,icol) - genmrb(1:K,icol)=temp(1:K) - itmp=indices(id) - indices(id)=indices(icol) - indices(icol)=itmp - endif - do ii=1,K - if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then - genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) - endif - enddo - exit - endif - enddo - enddo - - g2=transpose(genmrb) - -! The hard decisions for the K MRB bits define the order 0 message, m0. -! Encode m0 using the modified generator matrix to find the "order 0" codeword. -! Flip various combinations of bits in m0 and re-encode to generate a list of -! codewords. Return the member of the list that has the smallest Euclidean -! distance to the received word. - - hdec=hdec(indices) ! hard decisions from received symbols - m0=hdec(1:K) ! zero'th order message - absrx=absrx(indices) - rx=rx(indices) - apmaskr=apmaskr(indices) - - call mrbencode90(m0,c0,g2,N,K) - nxor=ieor(c0,hdec) - nhardmin=sum(nxor) - dmin=sum(nxor*absrx) - - cw=c0 - ntotal=0 - nrejected=0 - - if(ndeep.eq.0) goto 998 ! norder=0 - if(ndeep.gt.5) ndeep=5 - if( ndeep.eq. 1) then - nord=1 - npre1=0 - npre2=0 - nt=12 - ntheta=3 - elseif(ndeep.eq.2) then - nord=1 - npre1=1 - npre2=0 - nt=18 - ntheta=4 - elseif(ndeep.eq.3) then - nord=1 - npre1=1 - npre2=0 - nt=12 - ntheta=4 - elseif(ndeep.eq.4) then - nord=1 - npre1=1 - npre2=1 - nt=12 - ntheta=4 - ntau=15 - elseif(ndeep.eq.5) then - nord=1 - npre1=1 - npre2=1 - nt=12 - ntheta=4 - ntau=5 - endif - - do iorder=1,nord - misub(1:K-iorder)=0 - misub(K-iorder+1:K)=1 - iflag=K-iorder+1 - do while(iflag .ge.0) - if(iorder.eq.nord .and. npre1.eq.0) then - iend=iflag - else - iend=1 - endif - do n1=iflag,iend,-1 - mi=misub - mi(n1)=1 - if(any(iand(apmaskr(1:K),mi).eq.1)) cycle - ntotal=ntotal+1 - me=ieor(m0,mi) - if(n1.eq.iflag) then - call mrbencode90(me,ce,g2,N,K) - e2sub=ieor(ce(K+1:N),hdec(K+1:N)) - e2=e2sub - nd1Kpt=sum(e2sub(1:nt))+1 - d1=sum(ieor(me(1:K),hdec(1:K))*absrx(1:K)) - else - e2=ieor(e2sub,g2(K+1:N,n1)) - nd1Kpt=sum(e2(1:nt))+2 - endif - if(nd1Kpt .le. ntheta) then - call mrbencode90(me,ce,g2,N,K) - nxor=ieor(ce,hdec) - if(n1.eq.iflag) then - dd=d1+sum(e2sub*absrx(K+1:N)) - else - dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(K+1:N)) - endif - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - nd1Kptbest=nd1Kpt - endif - else - nrejected=nrejected+1 - endif - enddo -! Get the next test error pattern, iflag will go negative -! when the last pattern with weight iorder has been generated. - call nextpat90(misub,k,iorder,iflag) - enddo - enddo - - if(npre2.eq.1) then - reset=.true. - ntotal=0 - do i1=K,1,-1 - do i2=i1-1,1,-1 - ntotal=ntotal+1 - mi(1:ntau)=ieor(g2(K+1:K+ntau,i1),g2(K+1:K+ntau,i2)) - call boxit90(reset,mi(1:ntau),ntau,ntotal,i1,i2) - enddo - enddo - - ncount2=0 - ntotal2=0 - reset=.true. -! Now run through again and do the second pre-processing rule - misub(1:K-nord)=0 - misub(K-nord+1:K)=1 - iflag=K-nord+1 - do while(iflag .ge.0) - me=ieor(m0,misub) - call mrbencode90(me,ce,g2,N,K) - e2sub=ieor(ce(K+1:N),hdec(K+1:N)) - do i2=0,ntau - ntotal2=ntotal2+1 - ui=0 - if(i2.gt.0) ui(i2)=1 - r2pat=ieor(e2sub,ui) -778 continue - call fetchit90(reset,r2pat(1:ntau),ntau,in1,in2) - if(in1.gt.0.and.in2.gt.0) then - ncount2=ncount2+1 - mi=misub - mi(in1)=1 - mi(in2)=1 - if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:K),mi).eq.1)) cycle - me=ieor(m0,mi) - call mrbencode90(me,ce,g2,N,K) - nxor=ieor(ce,hdec) - dd=sum(nxor*absrx) - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - endif - goto 778 - endif - enddo - call nextpat90(misub,K,nord,iflag) - enddo - endif - -998 continue -! Re-order the codeword to [message bits][parity bits] format. - cw(indices)=cw - hdec(indices)=hdec - decoded=cw(1:K) - call chkcrc13a(decoded,nbadcrc) - message77=decoded(1:77) - if(nbadcrc.eq.1) nhardmin=-nhardmin - - return -end subroutine osd128_90 - -subroutine mrbencode90(me,codeword,g2,N,K) - integer*1 me(K),codeword(N),g2(N,K) -! fast encoding for low-weight test patterns - codeword=0 - do i=1,K - if( me(i) .eq. 1 ) then - codeword=ieor(codeword,g2(1:N,i)) - endif - enddo - return -end subroutine mrbencode90 - -subroutine nextpat90(mi,k,iorder,iflag) - integer*1 mi(k),ms(k) -! generate the next test error pattern - ind=-1 - do i=1,k-1 - if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i - enddo - if( ind .lt. 0 ) then ! no more patterns of this order - iflag=ind - return - endif - ms=0 - ms(1:ind-1)=mi(1:ind-1) - ms(ind)=1 - ms(ind+1)=0 - if( ind+1 .lt. k ) then - nz=iorder-sum(ms) - ms(k-nz+1:k)=1 - endif - mi=ms - do i=1,k ! iflag will point to the lowest-index 1 in mi - if(mi(i).eq.1) then - iflag=i - exit - endif - enddo - return -end subroutine nextpat90 - -subroutine boxit90(reset,e2,ntau,npindex,i1,i2) - integer*1 e2(1:ntau) - integer indexes(5000,2),fp(0:525000),np(5000) - logical reset - common/boxes/indexes,fp,np - - if(reset) then - patterns=-1 - fp=-1 - np=-1 - sc=-1 - indexes=-1 - reset=.false. - endif - - indexes(npindex,1)=i1 - indexes(npindex,2)=i2 - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - - ip=fp(ipat) ! see what's currently stored in fp(ipat) - if(ip.eq.-1) then - fp(ipat)=npindex - else - do while (np(ip).ne.-1) - ip=np(ip) - enddo - np(ip)=npindex - endif - return -end subroutine boxit90 - -subroutine fetchit90(reset,e2,ntau,i1,i2) - integer indexes(5000,2),fp(0:525000),np(5000) - integer lastpat - integer*1 e2(ntau) - logical reset - common/boxes/indexes,fp,np - save lastpat,inext - - if(reset) then - lastpat=-1 - reset=.false. - endif - - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - index=fp(ipat) - - if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices - i1=indexes(index,1) - i2=indexes(index,2) - inext=np(index) - elseif(lastpat.eq.ipat .and. inext.gt.0) then - i1=indexes(inext,1) - i2=indexes(inext,2) - inext=np(inext) - else - i1=-1 - i2=-1 - inext=-1 - endif - lastpat=ipat - return -end subroutine fetchit90 +subroutine osd128_90(llr,apmask,ndeep,message77,cw,nhardmin,dmin) + +! Ordered-statistics decoder for the (128,90) code. + + integer, parameter:: N=128, K=90, M=N-K + integer*1 apmask(N),apmaskr(N) + integer*1 gen(K,N) + integer*1 genmrb(K,N),g2(N,K) + integer*1 temp(K),m0(K),me(K),mi(K),misub(K),e2sub(N-K),e2(N-K),ui(N-K) + integer*1 r2pat(N-K) + integer indices(N),nxor(N) + integer*1 cw(N),ce(N),c0(N),hdec(N) + integer*1 decoded(K) + integer*1 message77(77) + integer indx(N) + real llr(N),rx(N),absrx(N) + + include "ldpc_128_90_generator.f90" + + logical first,reset + data first/.true./ + save first,gen + + if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,23 + read(g(i)(j:j),"(Z1)") istr + ibmax=4 + if(j.eq.23) ibmax=2 + do jj=1, ibmax + irow=(j-1)*4+jj + if( btest(istr,4-jj) ) gen(irow,K+i)=1 + enddo + enddo + enddo + do irow=1,K + gen(irow,irow)=1 + enddo + first=.false. + endif + + rx=llr + apmaskr=apmask + d1=0. + ntheta=0 + npre1=0 + npre2=0 + nt=0 + +! Hard decisions on the received word. + hdec=0 + where(rx .ge. 0) hdec=1 + +! Use magnitude of received symbols as a measure of reliability. + absrx=abs(rx) + call indexx(absrx,N,indx) + +! Re-order columns of generator matrix in order of decreasing reliability. + do i=1,N + genmrb(1:K,i)=gen(1:K,indx(N+1-i)) + indices(i)=indx(N+1-i) + enddo + +! Do gaussian elimination to create a generator matrix with the most reliable +! received bits in positions 1:K in order of decreasing reliability (more or less). + do id=1,K ! diagonal element indices + do icol=id,K+20 ! The 20 is ad hoc - beware + iflag=0 + if( genmrb(id,icol) .eq. 1 ) then + iflag=1 + if( icol .ne. id ) then ! reorder column + temp(1:K)=genmrb(1:K,id) + genmrb(1:K,id)=genmrb(1:K,icol) + genmrb(1:K,icol)=temp(1:K) + itmp=indices(id) + indices(id)=indices(icol) + indices(icol)=itmp + endif + do ii=1,K + if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then + genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) + endif + enddo + exit + endif + enddo + enddo + + g2=transpose(genmrb) + +! The hard decisions for the K MRB bits define the order 0 message, m0. +! Encode m0 using the modified generator matrix to find the "order 0" codeword. +! Flip various combinations of bits in m0 and re-encode to generate a list of +! codewords. Return the member of the list that has the smallest Euclidean +! distance to the received word. + + hdec=hdec(indices) ! hard decisions from received symbols + m0=hdec(1:K) ! zero'th order message + absrx=absrx(indices) + rx=rx(indices) + apmaskr=apmaskr(indices) + + call mrbencode90(m0,c0,g2,N,K) + nxor=ieor(c0,hdec) + nhardmin=sum(nxor) + dmin=sum(nxor*absrx) + + cw=c0 + ntotal=0 + nrejected=0 + + if(ndeep.eq.0) goto 998 ! norder=0 + if(ndeep.gt.5) ndeep=5 + if( ndeep.eq. 1) then + nord=1 + npre1=0 + npre2=0 + nt=12 + ntheta=3 + elseif(ndeep.eq.2) then + nord=1 + npre1=1 + npre2=0 + nt=18 + ntheta=4 + elseif(ndeep.eq.3) then + nord=1 + npre1=1 + npre2=0 + nt=12 + ntheta=4 + elseif(ndeep.eq.4) then + nord=1 + npre1=1 + npre2=1 + nt=12 + ntheta=4 + ntau=15 + elseif(ndeep.eq.5) then + nord=1 + npre1=1 + npre2=1 + nt=12 + ntheta=4 + ntau=5 + endif + + do iorder=1,nord + misub(1:K-iorder)=0 + misub(K-iorder+1:K)=1 + iflag=K-iorder+1 + do while(iflag .ge.0) + if(iorder.eq.nord .and. npre1.eq.0) then + iend=iflag + else + iend=1 + endif + do n1=iflag,iend,-1 + mi=misub + mi(n1)=1 + if(any(iand(apmaskr(1:K),mi).eq.1)) cycle + ntotal=ntotal+1 + me=ieor(m0,mi) + if(n1.eq.iflag) then + call mrbencode90(me,ce,g2,N,K) + e2sub=ieor(ce(K+1:N),hdec(K+1:N)) + e2=e2sub + nd1Kpt=sum(e2sub(1:nt))+1 + d1=sum(ieor(me(1:K),hdec(1:K))*absrx(1:K)) + else + e2=ieor(e2sub,g2(K+1:N,n1)) + nd1Kpt=sum(e2(1:nt))+2 + endif + if(nd1Kpt .le. ntheta) then + call mrbencode90(me,ce,g2,N,K) + nxor=ieor(ce,hdec) + if(n1.eq.iflag) then + dd=d1+sum(e2sub*absrx(K+1:N)) + else + dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(K+1:N)) + endif + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + nd1Kptbest=nd1Kpt + endif + else + nrejected=nrejected+1 + endif + enddo +! Get the next test error pattern, iflag will go negative +! when the last pattern with weight iorder has been generated. + call nextpat90(misub,k,iorder,iflag) + enddo + enddo + + if(npre2.eq.1) then + reset=.true. + ntotal=0 + do i1=K,1,-1 + do i2=i1-1,1,-1 + ntotal=ntotal+1 + mi(1:ntau)=ieor(g2(K+1:K+ntau,i1),g2(K+1:K+ntau,i2)) + call boxit90(reset,mi(1:ntau),ntau,ntotal,i1,i2) + enddo + enddo + + ncount2=0 + ntotal2=0 + reset=.true. +! Now run through again and do the second pre-processing rule + misub(1:K-nord)=0 + misub(K-nord+1:K)=1 + iflag=K-nord+1 + do while(iflag .ge.0) + me=ieor(m0,misub) + call mrbencode90(me,ce,g2,N,K) + e2sub=ieor(ce(K+1:N),hdec(K+1:N)) + do i2=0,ntau + ntotal2=ntotal2+1 + ui=0 + if(i2.gt.0) ui(i2)=1 + r2pat=ieor(e2sub,ui) +778 continue + call fetchit90(reset,r2pat(1:ntau),ntau,in1,in2) + if(in1.gt.0.and.in2.gt.0) then + ncount2=ncount2+1 + mi=misub + mi(in1)=1 + mi(in2)=1 + if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:K),mi).eq.1)) cycle + me=ieor(m0,mi) + call mrbencode90(me,ce,g2,N,K) + nxor=ieor(ce,hdec) + dd=sum(nxor*absrx) + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + endif + goto 778 + endif + enddo + call nextpat90(misub,K,nord,iflag) + enddo + endif + +998 continue +! Re-order the codeword to [message bits][parity bits] format. + cw(indices)=cw + hdec(indices)=hdec + decoded=cw(1:K) + call chkcrc13a(decoded,nbadcrc) + message77=decoded(1:77) + if(nbadcrc.eq.1) nhardmin=-nhardmin + + return +end subroutine osd128_90 + +subroutine mrbencode90(me,codeword,g2,N,K) + integer*1 me(K),codeword(N),g2(N,K) +! fast encoding for low-weight test patterns + codeword=0 + do i=1,K + if( me(i) .eq. 1 ) then + codeword=ieor(codeword,g2(1:N,i)) + endif + enddo + return +end subroutine mrbencode90 + +subroutine nextpat90(mi,k,iorder,iflag) + integer*1 mi(k),ms(k) +! generate the next test error pattern + ind=-1 + do i=1,k-1 + if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i + enddo + if( ind .lt. 0 ) then ! no more patterns of this order + iflag=ind + return + endif + ms=0 + ms(1:ind-1)=mi(1:ind-1) + ms(ind)=1 + ms(ind+1)=0 + if( ind+1 .lt. k ) then + nz=iorder-sum(ms) + ms(k-nz+1:k)=1 + endif + mi=ms + do i=1,k ! iflag will point to the lowest-index 1 in mi + if(mi(i).eq.1) then + iflag=i + exit + endif + enddo + return +end subroutine nextpat90 + +subroutine boxit90(reset,e2,ntau,npindex,i1,i2) + integer*1 e2(1:ntau) + integer indexes(5000,2),fp(0:525000),np(5000) + logical reset + common/boxes/indexes,fp,np + + if(reset) then + patterns=-1 + fp=-1 + np=-1 + sc=-1 + indexes=-1 + reset=.false. + endif + + indexes(npindex,1)=i1 + indexes(npindex,2)=i2 + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + + ip=fp(ipat) ! see what's currently stored in fp(ipat) + if(ip.eq.-1) then + fp(ipat)=npindex + else + do while (np(ip).ne.-1) + ip=np(ip) + enddo + np(ip)=npindex + endif + return +end subroutine boxit90 + +subroutine fetchit90(reset,e2,ntau,i1,i2) + integer indexes(5000,2),fp(0:525000),np(5000) + integer lastpat + integer*1 e2(ntau) + logical reset + common/boxes/indexes,fp,np + save lastpat,inext + + if(reset) then + lastpat=-1 + reset=.false. + endif + + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + index=fp(ipat) + + if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices + i1=indexes(index,1) + i2=indexes(index,2) + inext=np(index) + elseif(lastpat.eq.ipat .and. inext.gt.0) then + i1=indexes(inext,1) + i2=indexes(inext,2) + inext=np(inext) + else + i1=-1 + i2=-1 + inext=-1 + endif + lastpat=ipat + return +end subroutine fetchit90 diff --git a/lib/packjt.f90 b/lib/packjt.f90 index 8b471a0f..5557214f 100755 --- a/lib/packjt.f90 +++ b/lib/packjt.f90 @@ -1,1033 +1,1033 @@ -module packjt - -! These variables are accessible from outside via "use packjt": - integer jt_itype,jt_nc1,jt_nc2,jt_ng,jt_k1,jt_k2 - character*6 jt_c1,jt_c2,jt_c3 - - 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) - - ! Work-around for Guinea prefixes: - if(callsign(1:2).eq.'3X' .and. callsign(3:3).ge.'A' .and. & - callsign(3:3).le.'Z') callsign='Q'//callsign(3: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:) - if(word(1:1).eq.'Q' .and. word(2:2).ge.'A' .and. & - word(2:2).le.'Z') word='3X'//word(2:) - - 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 - - itype=1 - msg=msg0 - - call fmtmsg(msg,iz) - if(msg(1:3).eq.'CQ ' .and. msg(4:4).ge.'0' .and. msg(4:4).le.'9' & - .and. msg(5:5).eq.' ') msg='CQ 00'//msg(4:) - - 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 ' .and. (.not.text3)) nc1=262178563 + k2 - if(c1(1:4).eq.'QRZ ' .and. (.not.text3)) nc1=264002072 + k2 - if(c1(1:3).eq.'DE ' .and. (.not.text3)) nc1=265825581 + k2 - else if(nv2b.eq.5) then - if(c1(1:3).eq.'CQ ' .and. (.not.text3)) nc1=267649090 + k2 - if(c1(1:4).eq.'QRZ ' .and. (.not.text3)) nc1=267698375 + k2 - if(c1(1:3).eq.'DE ' .and. (.not.text3)) 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) - jt_itype=itype - jt_c1=c1(1:6) - jt_c2=c2(1:6) - jt_c3=c3 - jt_k1=k1 - jt_k2=k2 - jt_nc1=nc1 - jt_nc2=nc2 - jt_ng=ng - 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) then - grid6=grid//'ma' - call grid2k(grid6,k) - if(k.ge.451 .and. k.le.900) then - call getpfx2(k,c2) - n2=len_trim(c2) - msg='DE '//c2(:n2) - else - msg='DE '//c2(:n2)//' '//grid - endif - endif - 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:) - - if(msg(1:5).eq.'CQ 00' .and. msg(6:6).ge.'0' .and. & - msg(6:6).le.'9') msg='CQ '//msg(6:) - - return - end subroutine unpackmsg - - subroutine packtext(msg,nc1,nc2,nc3) - - parameter (MASK28=2**28 - 1) - character*22 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(nc1a,nc2a,nc3a,msg) - - character*22 msg - character*44 c - data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ +-./?'/ - - nc1=nc1a - nc2=nc2a - nc3=iand(nc3a,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 + +! These variables are accessible from outside via "use packjt": + integer jt_itype,jt_nc1,jt_nc2,jt_ng,jt_k1,jt_k2 + character*6 jt_c1,jt_c2,jt_c3 + + 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) + + ! Work-around for Guinea prefixes: + if(callsign(1:2).eq.'3X' .and. callsign(3:3).ge.'A' .and. & + callsign(3:3).le.'Z') callsign='Q'//callsign(3: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:) + if(word(1:1).eq.'Q' .and. word(2:2).ge.'A' .and. & + word(2:2).le.'Z') word='3X'//word(2:) + + 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 + + itype=1 + msg=msg0 + + call fmtmsg(msg,iz) + if(msg(1:3).eq.'CQ ' .and. msg(4:4).ge.'0' .and. msg(4:4).le.'9' & + .and. msg(5:5).eq.' ') msg='CQ 00'//msg(4:) + + 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 ' .and. (.not.text3)) nc1=262178563 + k2 + if(c1(1:4).eq.'QRZ ' .and. (.not.text3)) nc1=264002072 + k2 + if(c1(1:3).eq.'DE ' .and. (.not.text3)) nc1=265825581 + k2 + else if(nv2b.eq.5) then + if(c1(1:3).eq.'CQ ' .and. (.not.text3)) nc1=267649090 + k2 + if(c1(1:4).eq.'QRZ ' .and. (.not.text3)) nc1=267698375 + k2 + if(c1(1:3).eq.'DE ' .and. (.not.text3)) 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) + jt_itype=itype + jt_c1=c1(1:6) + jt_c2=c2(1:6) + jt_c3=c3 + jt_k1=k1 + jt_k2=k2 + jt_nc1=nc1 + jt_nc2=nc2 + jt_ng=ng + 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) then + grid6=grid//'ma' + call grid2k(grid6,k) + if(k.ge.451 .and. k.le.900) then + call getpfx2(k,c2) + n2=len_trim(c2) + msg='DE '//c2(:n2) + else + msg='DE '//c2(:n2)//' '//grid + endif + endif + 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:) + + if(msg(1:5).eq.'CQ 00' .and. msg(6:6).ge.'0' .and. & + msg(6:6).le.'9') msg='CQ '//msg(6:) + + return + end subroutine unpackmsg + + subroutine packtext(msg,nc1,nc2,nc3) + + parameter (MASK28=2**28 - 1) + character*22 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(nc1a,nc2a,nc3a,msg) + + character*22 msg + character*44 c + data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ +-./?'/ + + nc1=nc1a + nc2=nc2a + nc3=iand(nc3a,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/lib/pctile.f90 b/lib/pctile.f90 index e5458ed9..a980deaa 100755 --- a/lib/pctile.f90 +++ b/lib/pctile.f90 @@ -1,21 +1,21 @@ -subroutine pctile(x,npts,npct,xpct) - - real x(npts) - real,allocatable :: tmp(:) - - if(npts.lt.0 .or. npct.lt.0 .or. npct.gt.100) then - xpct=1.0 - go to 900 - endif - allocate(tmp(npts)) - - tmp=x - call shell(npts,tmp) - j=nint(npts*0.01*npct) - if(j.lt.1) j=1 - if(j.gt.npts) j=npts - xpct=tmp(j) - deallocate(tmp) - -900 return -end subroutine pctile +subroutine pctile(x,npts,npct,xpct) + + real x(npts) + real,allocatable :: tmp(:) + + if(npts.lt.0 .or. npct.lt.0 .or. npct.gt.100) then + xpct=1.0 + go to 900 + endif + allocate(tmp(npts)) + + tmp=x + call shell(npts,tmp) + j=nint(npts*0.01*npct) + if(j.lt.1) j=1 + if(j.gt.npts) j=npts + xpct=tmp(j) + deallocate(tmp) + +900 return +end subroutine pctile diff --git a/lib/peakup.f90 b/lib/peakup.f90 index 8e5aedaf..92327ab6 100755 --- a/lib/peakup.f90 +++ b/lib/peakup.f90 @@ -1,8 +1,8 @@ -subroutine peakup(ym,y0,yp,dx) - - b=(yp-ym)/2.0 - c=(yp+ym-2.0*y0)/2.0 - dx=-b/(2.0*c) - - return -end subroutine peakup +subroutine peakup(ym,y0,yp,dx) + + b=(yp-ym)/2.0 + c=(yp+ym-2.0*y0)/2.0 + dx=-b/(2.0*c) + + return +end subroutine peakup diff --git a/lib/pfx.f90 b/lib/pfx.f90 index 4e7b8a7b..eb81fef8 100755 --- a/lib/pfx.f90 +++ b/lib/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/lib/platanh.f90 b/lib/platanh.f90 index d81135be..e610366d 100755 --- a/lib/platanh.f90 +++ b/lib/platanh.f90 @@ -1,24 +1,24 @@ -subroutine platanh(x,y) - isign=+1 - z=x - if( x.lt.0 ) then - isign=-1 - z=abs(x) - endif - if( z.le. 0.664 ) then - y=x/0.83 - return - elseif( z.le. 0.9217 ) then - y=isign*(z-0.4064)/0.322 - return - elseif( z.le. 0.9951 ) then - y=isign*(z-0.8378)/0.0524 - return - elseif( z.le. 0.9998 ) then - y=isign*(z-0.9914)/0.0012 - return - else - y=isign*7.0 - return - endif -end subroutine platanh +subroutine platanh(x,y) + isign=+1 + z=x + if( x.lt.0 ) then + isign=-1 + z=abs(x) + endif + if( z.le. 0.664 ) then + y=x/0.83 + return + elseif( z.le. 0.9217 ) then + y=isign*(z-0.4064)/0.322 + return + elseif( z.le. 0.9951 ) then + y=isign*(z-0.8378)/0.0524 + return + elseif( z.le. 0.9998 ) then + y=isign*(z-0.9914)/0.0012 + return + else + y=isign*7.0 + return + endif +end subroutine platanh diff --git a/lib/pltanh.f90 b/lib/pltanh.f90 index 60c17c8a..4c6c2b6d 100755 --- a/lib/pltanh.f90 +++ b/lib/pltanh.f90 @@ -1,24 +1,24 @@ -subroutine pltanh(x,y) - isign=+1 - z=x - if( x.lt.0 ) then - isign=-1 - z=abs(x) - endif - if( z.le. 0.8 ) then - y=0.83*x - return - elseif( z.le. 1.6 ) then - y=isign*(0.322*z+0.4064) - return - elseif( z.le. 3.0 ) then - y=isign*(0.0524*z+0.8378) - return - elseif( z.lt. 7.0 ) then - y=isign*(0.0012*z+0.9914) - return - else - y=isign*0.9998 - return - endif -end subroutine pltanh +subroutine pltanh(x,y) + isign=+1 + z=x + if( x.lt.0 ) then + isign=-1 + z=abs(x) + endif + if( z.le. 0.8 ) then + y=0.83*x + return + elseif( z.le. 1.6 ) then + y=isign*(0.322*z+0.4064) + return + elseif( z.le. 3.0 ) then + y=isign*(0.0524*z+0.8378) + return + elseif( z.lt. 7.0 ) then + y=isign*(0.0012*z+0.9914) + return + else + y=isign*0.9998 + return + endif +end subroutine pltanh diff --git a/lib/polyfit.f90 b/lib/polyfit.f90 index 55651411..63222304 100755 --- a/lib/polyfit.f90 +++ b/lib/polyfit.f90 @@ -1,72 +1,72 @@ -subroutine polyfit(x,y,sigmay,npts,nterms,mode,a,chisqr) - implicit real*8 (a-h,o-z) - real*8 x(npts), y(npts), sigmay(npts), a(nterms) - real*8 sumx(10), sumy(10), array(10,10) - -! Accumulate weighted sums - nmax = 2*nterms-1 - sumx=0. - sumy=0. - chisq=0. - do i=1,npts - xi=x(i) - yi=y(i) - if(mode.lt.0) then - weight=1./abs(yi) - else if(mode.eq.0) then - weight=1 - else - weight=1./sigmay(i)**2 - end if - xterm=weight - do n=1,nmax - sumx(n)=sumx(n)+xterm - xterm=xterm*xi - enddo - yterm=weight*yi - do n=1,nterms - sumy(n)=sumy(n)+yterm - yterm=yterm*xi - enddo - chisq=chisq+weight*yi**2 - enddo - -! Construct matrices and calculate coefficients - do j=1,nterms - do k=1,nterms - n=j+k-1 - array(j,k)=sumx(n) - enddo - enddo - - delta=determ(array,nterms) - if(delta.eq.0) then - chisqr=0. - a=0. - else - do l=1,nterms - do j=1,nterms - do k=1,nterms - n=j+k-1 - array(j,k)=sumx(n) - enddo - array(j,l)=sumy(j) - enddo - a(l)=determ(array,nterms)/delta - enddo - -! Calculate chi square - - do j=1,nterms - chisq=chisq-2*a(j)*sumy(j) - do k=1,nterms - n=j+k-1 - chisq=chisq+a(j)*a(k)*sumx(n) - enddo - enddo - free=npts-nterms - chisqr=chisq/free - end if - - return -end subroutine polyfit +subroutine polyfit(x,y,sigmay,npts,nterms,mode,a,chisqr) + implicit real*8 (a-h,o-z) + real*8 x(npts), y(npts), sigmay(npts), a(nterms) + real*8 sumx(10), sumy(10), array(10,10) + +! Accumulate weighted sums + nmax = 2*nterms-1 + sumx=0. + sumy=0. + chisq=0. + do i=1,npts + xi=x(i) + yi=y(i) + if(mode.lt.0) then + weight=1./abs(yi) + else if(mode.eq.0) then + weight=1 + else + weight=1./sigmay(i)**2 + end if + xterm=weight + do n=1,nmax + sumx(n)=sumx(n)+xterm + xterm=xterm*xi + enddo + yterm=weight*yi + do n=1,nterms + sumy(n)=sumy(n)+yterm + yterm=yterm*xi + enddo + chisq=chisq+weight*yi**2 + enddo + +! Construct matrices and calculate coefficients + do j=1,nterms + do k=1,nterms + n=j+k-1 + array(j,k)=sumx(n) + enddo + enddo + + delta=determ(array,nterms) + if(delta.eq.0) then + chisqr=0. + a=0. + else + do l=1,nterms + do j=1,nterms + do k=1,nterms + n=j+k-1 + array(j,k)=sumx(n) + enddo + array(j,l)=sumy(j) + enddo + a(l)=determ(array,nterms)/delta + enddo + +! Calculate chi square + + do j=1,nterms + chisq=chisq-2*a(j)*sumy(j) + do k=1,nterms + n=j+k-1 + chisq=chisq+a(j)*a(k)*sumx(n) + enddo + enddo + free=npts-nterms + chisqr=chisq/free + end if + + return +end subroutine polyfit diff --git a/lib/prcom.f90 b/lib/prcom.f90 index eb4f88a9..ac333b6d 100755 --- a/lib/prcom.f90 +++ b/lib/prcom.f90 @@ -1 +1 @@ - common/prcom/pr(126),mdat(126),mref(126,2),mdat2(126),mref2(126,2) + common/prcom/pr(126),mdat(126),mref(126,2),mdat2(126),mref2(126,2) diff --git a/lib/prog_args.f90 b/lib/prog_args.f90 index 0b94c4b3..63cdb792 100755 --- a/lib/prog_args.f90 +++ b/lib/prog_args.f90 @@ -1,4 +1,4 @@ -MODULE prog_args - CHARACTER(len=80) :: shm_key - CHARACTER(len=500) :: exe_dir = '.', data_dir = '.', temp_dir = '.' -END MODULE prog_args +MODULE prog_args + CHARACTER(len=80) :: shm_key + CHARACTER(len=500) :: exe_dir = '.', data_dir = '.', temp_dir = '.' +END MODULE prog_args diff --git a/lib/ps4.f90 b/lib/ps4.f90 index 7ed1ae72..782ab50d 100755 --- a/lib/ps4.f90 +++ b/lib/ps4.f90 @@ -1,27 +1,27 @@ -subroutine ps4(dat,nfft,s) - - parameter (NMAX=2520+2) - parameter (NHMAX=NMAX/2-1) - real dat(nfft) - real dat2(NMAX) - real s(NHMAX) - complex c(0:NMAX) - equivalence(dat2,c) - - nh=nfft/2 - do i=1,nh - dat2(i)=dat(i)/128.0 !### Why 128 ?? - enddo - do i=nh+1,nfft - dat2(i)=0. - enddo - - call four2a(c,nfft,1,-1,0) - - fac=1.0/nfft - do i=1,nh - s(i)=fac*(real(c(i))**2 + aimag(c(i))**2) - enddo - - return -end subroutine ps4 +subroutine ps4(dat,nfft,s) + + parameter (NMAX=2520+2) + parameter (NHMAX=NMAX/2-1) + real dat(nfft) + real dat2(NMAX) + real s(NHMAX) + complex c(0:NMAX) + equivalence(dat2,c) + + nh=nfft/2 + do i=1,nh + dat2(i)=dat(i)/128.0 !### Why 128 ?? + enddo + do i=nh+1,nfft + dat2(i)=0. + enddo + + call four2a(c,nfft,1,-1,0) + + fac=1.0/nfft + do i=1,nh + s(i)=fac*(real(c(i))**2 + aimag(c(i))**2) + enddo + + return +end subroutine ps4 diff --git a/lib/psk_parse.f90 b/lib/psk_parse.f90 index e4a09922..5f97732c 100755 --- a/lib/psk_parse.f90 +++ b/lib/psk_parse.f90 @@ -1,108 +1,108 @@ -program psk_parse - - character line*256,callsign*12,callsign0*12,progname*30 - integer nc(6),ntot(6),nsingle(6) - logical zap - data callsign0/' '/ - - open(10,file='jt65-2',status='old') - nc=0 - ntot=0 - ncalls=0 - nsingle=0 - zap=.false. - - do iline=1,9999999 - read(10,'(a256)',end=900) line - n=len(trim(line)) - i1=0 - i2=0 - i3=0 - do i=1,n - if(ichar(line(i:i)).eq.9) then - if(i1.eq.0) then - i1=i - cycle - endif - if(i2.eq.0) then - i2=i - cycle - endif - if(i3.eq.0) then - i3=i - exit - endif - endif - enddo - callsign=line(1:i1-1) - - if(zap) then - if(callsign(1:1).ge.'0' .and. callsign(1:1).le.'9' .and. & - callsign(2:2).ge.'0' .and. callsign(2:2).le.'9' .and. & - callsign(3:3).ge.'0' .and. callsign(3:3).le.'9') cycle - - if(callsign(1:1).ge.'A' .and. callsign(1:1).le.'Z' .and. & - callsign(2:2).ge.'A' .and. callsign(2:2).le.'Z' .and. & - callsign(3:3).ge.'A' .and. callsign(3:3).le.'Z' .and. & - callsign(4:4).ge.'A' .and. callsign(4:4).le.'Z') cycle - - if(callsign(1:1).eq.'N' .and. & - callsign(2:2).ge.'0' .and. callsign(2:2).le.'9' .and. & - callsign(3:3).ge.'0' .and. callsign(3:3).le.'9') cycle - - endif - - progname=line(i1+1:i2-1) - do i=1,len(trim(progname)) - if(progname(i:i).eq.' ') progname(i:i)='_' - enddo - read(line(i2+1:i3-1),*) ndecodes - read(line(i3+1:),*) nreporters - - j=6 - if(index(progname,'WSJT-X').gt.0) j=1 - if(index(progname,'HB9HQX').gt.0) j=2 - if(index(progname,'JTDX').gt.0) j=3 - if(index(progname,'Comfort').gt.0) j=4 - if(index(progname,'COMFORT').gt.0) j=4 - if(index(progname,'JT65-HF').gt.0 .and. j.eq.6) j=5 - - nctot=sum(nc) - if(callsign.ne.callsign0 .and. nctot.gt.0) then - write(13,1000) callsign0,nc,nctot -1000 format(a12,6i8,i10) - if(nctot.eq.1) nsingle(j)=nsingle(j)+1 - nc=0 - callsign0=callsign - ncalls=ncalls+1 - endif - nc(j)=nc(j) + ndecodes - ntot(j)=ntot(j) + ndecodes - write(12,1010) iline,callsign,ndecodes,nreporters,progname -1010 format(i8,2x,a12,2x,2i8,2x,a30) - enddo - -900 nctot=sum(nc) - if(nctot.gt.0) write(13,1000) callsign0,nc,nctot - - write(*,1018) -1018 format(' Total WSJT-X HB9HQX JTDX Comfort JT65-HF Other'/ & - '----------------------------------------------------------') - write(*,1019) -1019 format('Spots reported; fraction of total:') - write(*,1020) sum(ntot),ntot -1020 format(i8,2x,6i8) - fac=1.0/sum(ntot) - write(*,1030) 1.0000,fac*ntot -1030 format(f8.4,2x,6f8.4,f10.4) - - write(*,1038) -1038 format(/'Singletons; as fraction of spots by same program') - write(*,1040) sum(nsingle),nsingle -1040 format(i8,2x,6i8) - write(*,1030) float(sum(nsingle))/sum(ntot),float(nsingle)/ntot - - write(*,1050) ncalls -1050 format(/'Distinct calls spotted:',i6) - -end program psk_parse +program psk_parse + + character line*256,callsign*12,callsign0*12,progname*30 + integer nc(6),ntot(6),nsingle(6) + logical zap + data callsign0/' '/ + + open(10,file='jt65-2',status='old') + nc=0 + ntot=0 + ncalls=0 + nsingle=0 + zap=.false. + + do iline=1,9999999 + read(10,'(a256)',end=900) line + n=len(trim(line)) + i1=0 + i2=0 + i3=0 + do i=1,n + if(ichar(line(i:i)).eq.9) then + if(i1.eq.0) then + i1=i + cycle + endif + if(i2.eq.0) then + i2=i + cycle + endif + if(i3.eq.0) then + i3=i + exit + endif + endif + enddo + callsign=line(1:i1-1) + + if(zap) then + if(callsign(1:1).ge.'0' .and. callsign(1:1).le.'9' .and. & + callsign(2:2).ge.'0' .and. callsign(2:2).le.'9' .and. & + callsign(3:3).ge.'0' .and. callsign(3:3).le.'9') cycle + + if(callsign(1:1).ge.'A' .and. callsign(1:1).le.'Z' .and. & + callsign(2:2).ge.'A' .and. callsign(2:2).le.'Z' .and. & + callsign(3:3).ge.'A' .and. callsign(3:3).le.'Z' .and. & + callsign(4:4).ge.'A' .and. callsign(4:4).le.'Z') cycle + + if(callsign(1:1).eq.'N' .and. & + callsign(2:2).ge.'0' .and. callsign(2:2).le.'9' .and. & + callsign(3:3).ge.'0' .and. callsign(3:3).le.'9') cycle + + endif + + progname=line(i1+1:i2-1) + do i=1,len(trim(progname)) + if(progname(i:i).eq.' ') progname(i:i)='_' + enddo + read(line(i2+1:i3-1),*) ndecodes + read(line(i3+1:),*) nreporters + + j=6 + if(index(progname,'WSJT-X').gt.0) j=1 + if(index(progname,'HB9HQX').gt.0) j=2 + if(index(progname,'JTDX').gt.0) j=3 + if(index(progname,'Comfort').gt.0) j=4 + if(index(progname,'COMFORT').gt.0) j=4 + if(index(progname,'JT65-HF').gt.0 .and. j.eq.6) j=5 + + nctot=sum(nc) + if(callsign.ne.callsign0 .and. nctot.gt.0) then + write(13,1000) callsign0,nc,nctot +1000 format(a12,6i8,i10) + if(nctot.eq.1) nsingle(j)=nsingle(j)+1 + nc=0 + callsign0=callsign + ncalls=ncalls+1 + endif + nc(j)=nc(j) + ndecodes + ntot(j)=ntot(j) + ndecodes + write(12,1010) iline,callsign,ndecodes,nreporters,progname +1010 format(i8,2x,a12,2x,2i8,2x,a30) + enddo + +900 nctot=sum(nc) + if(nctot.gt.0) write(13,1000) callsign0,nc,nctot + + write(*,1018) +1018 format(' Total WSJT-X HB9HQX JTDX Comfort JT65-HF Other'/ & + '----------------------------------------------------------') + write(*,1019) +1019 format('Spots reported; fraction of total:') + write(*,1020) sum(ntot),ntot +1020 format(i8,2x,6i8) + fac=1.0/sum(ntot) + write(*,1030) 1.0000,fac*ntot +1030 format(f8.4,2x,6f8.4,f10.4) + + write(*,1038) +1038 format(/'Singletons; as fraction of spots by same program') + write(*,1040) sum(nsingle),nsingle +1040 format(i8,2x,6i8) + write(*,1030) float(sum(nsingle))/sum(ntot),float(nsingle)/ntot + + write(*,1050) ncalls +1050 format(/'Distinct calls spotted:',i6) + +end program psk_parse diff --git a/lib/ptt.c b/lib/ptt.c index 81ab11ce..902193fd 100755 --- a/lib/ptt.c +++ b/lib/ptt.c @@ -1,50 +1,50 @@ -#include -#include - -int ptt_(int *nport, int *ntx, int *iptt) -{ - static HANDLE hFile; - static int open=0; - char s[10]; - int i3=1,i4=1,i5=1,i6=1,i9=1,i00=1; - - if(*nport==0) { - *iptt=*ntx; - return(0); - } - - if(*ntx && (!open)) { - sprintf(s,"\\\\.\\COM%d",*nport); - hFile=CreateFile(TEXT(s),GENERIC_WRITE,0,NULL,OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL,NULL); - if(hFile==INVALID_HANDLE_VALUE) { - // printf("PTT: Cannot open COM port %d.\n",*nport); - return 1; - } - open=1; - } - - if(*ntx && open) { - i3=EscapeCommFunction(hFile,3); - i5=EscapeCommFunction(hFile,5); - *iptt=1; - } - - else { - i4=EscapeCommFunction(hFile,4); - i6=EscapeCommFunction(hFile,6); - i9=EscapeCommFunction(hFile,9); - i00=CloseHandle(hFile); - *iptt=0; - open=0; - } - /* - if(i3==0) return 3; - if(i4==0) return 4; - if(i5==0) return 5; - if(i6==0) return 6; - if(i9==0) return 9; - if(i00==0) return 10; - */ - return 0; -} +#include +#include + +int ptt_(int *nport, int *ntx, int *iptt) +{ + static HANDLE hFile; + static int open=0; + char s[10]; + int i3=1,i4=1,i5=1,i6=1,i9=1,i00=1; + + if(*nport==0) { + *iptt=*ntx; + return(0); + } + + if(*ntx && (!open)) { + sprintf(s,"\\\\.\\COM%d",*nport); + hFile=CreateFile(TEXT(s),GENERIC_WRITE,0,NULL,OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL,NULL); + if(hFile==INVALID_HANDLE_VALUE) { + // printf("PTT: Cannot open COM port %d.\n",*nport); + return 1; + } + open=1; + } + + if(*ntx && open) { + i3=EscapeCommFunction(hFile,3); + i5=EscapeCommFunction(hFile,5); + *iptt=1; + } + + else { + i4=EscapeCommFunction(hFile,4); + i6=EscapeCommFunction(hFile,6); + i9=EscapeCommFunction(hFile,9); + i00=CloseHandle(hFile); + *iptt=0; + open=0; + } + /* + if(i3==0) return 3; + if(i4==0) return 4; + if(i5==0) return 5; + if(i6==0) return 6; + if(i9==0) return 9; + if(i00==0) return 10; + */ + return 0; +} diff --git a/lib/q65_decode.f90 b/lib/q65_decode.f90 index 47b25765..e3495ee2 100755 --- a/lib/q65_decode.f90 +++ b/lib/q65_decode.f90 @@ -1,505 +1,505 @@ -module q65_decode - - integer nsnr0,nfreq0 - real xdt0 - character msg0*37,cq0*3 - - type :: q65_decoder - procedure(q65_decode_callback), pointer :: callback - contains - procedure :: decode - end type q65_decoder - - abstract interface - subroutine q65_decode_callback (this,nutc,snr1,nsnr,dt,freq, & - decoded,idec,nused,ntrperiod) - import q65_decoder - implicit none - class(q65_decoder), intent(inout) :: this - integer, intent(in) :: nutc - real, intent(in) :: snr1 - integer, intent(in) :: nsnr - real, intent(in) :: dt - real, intent(in) :: freq - character(len=37), intent(in) :: decoded - integer, intent(in) :: idec - integer, intent(in) :: nused - integer, intent(in) :: ntrperiod - end subroutine q65_decode_callback - end interface - -contains - - subroutine decode(this,callback,iwave,nqd0,nutc,ntrperiod,nsubmode,nfqso, & - ntol,ndepth,nfa0,nfb0,lclearave,single_decode,lagain,max_drift0, & - lnewdat0,emedelay,mycall,hiscall,hisgrid,nQSOprogress,ncontest, & - lapcqonly,navg0,nqf) - -! Top-level routine that organizes the decoding of Q65 signals -! Input: iwave Raw data, i*2 -! nutc UTC for time-tagging the decode -! ntrperiod T/R sequence length (s) -! nsubmode Tone-spacing indicator, 0-4 for A-E -! nfqso Target signal frequency (Hz) -! ntol Search range around nfqso (Hz) -! ndepth Optional decoding level -! lclearave Flag to clear the message-averaging arrays -! emedelay Sync search extended to cover EME delays -! nQSOprogress Auto-sequencing state for the present QSO -! ncontest Supported contest type -! lapcqonly Flag to use AP only for CQ calls -! Output: sent to the callback routine for display to user - - use timer_module, only: timer - use packjt77 - use, intrinsic :: iso_c_binding - use q65 !Shared variables - use prog_args - use types - - parameter (NMAX=300*12000) !Max TRperiod is 300 s - parameter (MAX_CALLERS=40) !For multiple q3 decodes in NA VHf Contest mode - - class(q65_decoder), intent(inout) :: this - - procedure(q65_decode_callback) :: callback - character(len=12) :: mycall, hiscall !Used for AP decoding - character(len=6) :: hisgrid - character*37 decoded !Decoded message - character*37 decodes(100) - character*77 c77 - character*78 c78 - character*6 cutc - character c6*6,c4*4,cmode*4 - character*80 fmt - integer*2 iwave(NMAX) !Raw data - real, allocatable :: dd(:) !Raw data - real xdtdecodes(100) - real f0decodes(100) - integer dat4(13) !Decoded message as 12 6-bit integers - integer dgen(13) - integer nqf(20) - integer stageno !Added by W3SZ - integer time - logical lclearave,lnewdat0,lapcqonly,unpk77_success - logical single_decode,lagain - complex, allocatable :: c00(:) !Analytic signal, 6000 Sa/s - complex, allocatable :: c0(:) !Analytic signal, 6000 Sa/s - type(q3list) callers(MAX_CALLERS) - -! Start by setting some parameters and allocating storage for large arrays - call sec0(0,tdecode) - stageno=0 - ndecodes=0 - decodes=' ' - f0decodes=0. - xdtdecodes=0. - nfa=nfa0 - nfb=nfb0 - nqd=nqd0 - lnewdat=lnewdat0 - max_drift=max_drift0 - idec=-1 - idf=0 - idt=0 - nrc=-2 - mode_q65=2**nsubmode - npts=ntrperiod*12000 - nfft1=ntrperiod*12000 - nfft2=ntrperiod*6000 - npasses=1 - nhist2=0 - if(lagain) ndepth=ior(ndepth,3) !Use 'Deep' for manual Q65 decodes - dxcall13=hiscall ! initialize for use in packjt77 - mycall13=mycall - if(ncontest.eq.1) then -! NA VHF, WW-Digi, or ARRL Digi Contest - open(24,file=trim(data_dir)//'/tsil.3q',status='unknown', & - form='unformatted') - read(24,end=2) nhist2 - if(nhist2.ge.1 .and. nhist2.le.40) then - read(24,end=2) callers(1:nhist2) - now=time() - do i=1,nhist2 - hours=(now - callers(i)%nsec)/3600.0 - if(hours.gt.24.0) then - callers(i:nhist2-1)=callers(i+1:nhist2) - nhist2=nhist2-1 - endif - enddo - else - nhist2=0 - endif -2 close(24) - endif - -! Determine the T/R sequence: iseq=0 (even), or iseq=1 (odd) - n=nutc - if(ntrperiod.ge.60 .and. nutc.le.2359) n=100*n - write(cutc,'(i6.6)') n - read(cutc,'(3i2)') ih,im,is - nsec=3600*ih + 60*im + is - iseq=mod(nsec/ntrperiod,2) - - if(lclearave) call q65_clravg - allocate(dd(npts)) - allocate (c00(0:nfft1-1)) - allocate (c0(0:nfft1-1)) - - if(lagain) then - call q65_hist(nfqso,dxcall=hiscall,dxgrid=hisgrid) - endif - - nsps=1800 - if(ntrperiod.eq.30) then - nsps=3600 - else if(ntrperiod.eq.60) then - nsps=7200 - else if(ntrperiod.eq.120) then - nsps=16000 - else if(ntrperiod.eq.300) then - nsps=41472 - endif - - baud=12000.0/nsps - this%callback => callback - nFadingModel=1 - -! ibwa=max(1,int(1.8*log(baud*mode_q65)) + 5) -!### This needs work! - ibwa=1 !Q65-60A - if(mode_q65.eq.2) ibwa=3 !Q65-60B - if(mode_q65.eq.4) ibwa=8 !Q65-60C - if(mode_q65.eq.8) ibwa=8 !Q65-60D - if(mode_q65.eq.16) ibwa=8 !Q65-60E -!### - -! ibwb=min(15,ibwa+4) - ibwb=min(15,ibwa+6) - maxiters=40 - if(iand(ndepth,3).eq.2) maxiters=60 - if(iand(ndepth,3).eq.3) then - ibwa=max(1,ibwa-2) - ibwb=min(15,ibwb+2) - maxiters=100 - endif - -! Generate codewords for full-AP list decoding - if(ichar(hiscall(1:1)).eq.0) hiscall=' ' - if(ichar(hisgrid(1:1)).eq.0) hisgrid=' ' - ncw=0 - if(nqd.eq.1 .or. lagain .or. ncontest.eq.1) then - if(ncontest.eq.1) then - call q65_set_list2(mycall,hiscall,hisgrid,callers,nhist2, & - codewords,ncw) - else - call q65_set_list(mycall,hiscall,hisgrid,codewords,ncw) - endif - endif - dgen=0 - call q65_enc(dgen,codewords) !Initialize the Q65 codec - nused=1 - iavg=0 - -! W3SZ patch: Initialize AP params here, rather than afer the call to ana64(). - call ft8apset(mycall,hiscall,ncontest,apsym0,aph10) ! Generate ap symbols - where(apsym0.eq.-1) apsym0=0 - npasses=2 - if(nQSOprogress.eq.5) npasses=3 - - call timer('q65_dec0',0) -! Call top-level routine in q65 module: establish sync and try for a -! q3 or q0 decode. - call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, & - emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) - call timer('q65_dec0',1) - - if(idec.ge.0) then - dtdec=xdt !We have a q3 or q0 decode at nfqso - f0dec=f0 - go to 100 - endif - - if(ncontest.eq.1 .and. lagain .and. iand(ndepth,16).eq.16) go to 50 - if(ncontest.eq.1 .and. lagain .and. iand(ndepth,16).eq.0) go to 100 - -! Prepare for a single-period decode with iaptype = 0, 1, 2, or 4 - jpk0=(xdt+1.0)*6000 !Index of nominal start of signal - if(ntrperiod.le.30) jpk0=(xdt+0.5)*6000 !For shortest sequences - if(jpk0.lt.0) jpk0=0 - call ana64(iwave,npts,c00) !Convert to complex c00() at 6000 Sa/s - if(lapcqonly) npasses=1 - iaptype=0 - do ipass=0,npasses !Loop over AP passes - apmask=0 !Try first with no AP information - apsymbols=0 - if(ipass.ge.1) then - ! Subsequent passes use AP information appropiate for nQSOprogress - call q65_ap(nQSOprogress,ipass,ncontest,lapcqonly,iaptype, & - apsym0,apmask1,apsymbols1) - write(c78,1050) apmask1 -1050 format(78i1) - read(c78,1060) apmask -1060 format(13b6.6) - write(c78,1050) apsymbols1 - read(c78,1060) apsymbols - endif - - call timer('q65loop1',0) - call q65_loops(c00,npts/2,nsps/2,nsubmode,ndepth,jpk0, & - xdt,f0,iaptype,xdt1,f1,snr2,dat4,idec) - call timer('q65loop1',1) - if(idec.ge.0) then - dtdec=xdt1 - f0dec=f1 - go to 100 !Successful decode, we're done - endif - enddo ! ipass - - if(iand(ndepth,16).eq.0 .or. navg(iseq).lt.2) go to 100 - -! There was no single-transmission decode. Try for an average 'q3n' decode. -50 iavg=1 - call timer('list_avg',0) -! Call top-level routine in q65 module: establish sync and try for a q3 -! decode, this time using the cumulative 's1a' symbol spectra. - call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, & - emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) - call timer('list_avg',1) - - if(idec.ge.0) then - dtdec=xdt !We have a list-decode result from averaged data - f0dec=f0 - nused=navg(iseq) - go to 100 - endif - -! There was no 'q3n' decode. Try for a 'q[0124]n' decode. -! Call top-level routine in q65 module: establish sync and try for a q[012]n -! decode, this time using the cumulative 's1a' symbol spectra. - - call timer('q65_avg ',0) - iavg=2 - call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, & - emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) - call timer('q65_avg ',1) - if(idec.ge.0) then - dtdec=xdt !We have a q[012]n result - f0dec=f0 - nused=navg(iseq) - endif - -100 if(idec.lt.0 .and. max_drift.eq.50) then - stageno = 5 - call timer('q65_dec0',0) - ! Call top-level routine in q65 module: establish sync and try for a - ! q3 or q0 decode. - call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, & - emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) - call timer('q65_dec0',1) - if(idec.ge.0) then - dtdec=xdt !We have a q[012]n result - f0dec=f0 - endif - endif ! if(idec.lt.0) - - decoded=' ' - if(idec.ge.0) then -! idec Meaning -! ------------------------------------------------------ -! -1: No decode -! 0: Decode without AP information -! 1: Decode with AP for "CQ ? ?" -! 2: Decode with AP for "MyCall ? ?" -! 3: Decode with AP for "MyCall DxCall ?" - -! Unpack decoded message for display to user - write(c77,1000) dat4(1:12),dat4(13)/2 -1000 format(12b6.6,b5.5) - call unpack77(c77,1,decoded,unpk77_success) !Unpack to get decoded - idupe=0 - do i=1,ndecodes - if(decodes(i).eq.decoded) idupe=1 - enddo - if(idupe.eq.0) then - ndecodes=min(ndecodes+1,100) - decodes(ndecodes)=decoded - f0decodes(ndecodes)=f0dec - xdtdecodes(ndecodes)=dtdec - call q65_snr(dat4,dtdec,f0dec,mode_q65,snr2) - nsnr=nint(snr2) - call this%callback(nutc,snr1,nsnr,dtdec,f0dec,decoded, & - idec,nused,ntrperiod) - if(ncontest.eq.1) then - call q65_hist2(nint(f0dec),decoded,callers,nhist2) - else - call q65_hist(nint(f0dec),msg0=decoded) - endif - if(iand(ndepth,128).ne.0 .and. .not.lagain .and. & - int(abs(f0dec-nfqso)).le.ntol ) call q65_clravg !AutoClrAvg - call sec0(1,tdecode) - open(22,file=trim(data_dir)//'/q65_decodes.txt',status='unknown', & - position='append',iostat=ios) - if(ios.eq.0) then -! Save decoding parameters to q65_decoded.dat, for later analysis. - write(cmode,'(i3)') ntrperiod - cmode(4:4)=char(ichar('A')+nsubmode) - c6=hiscall(1:6) - if(c6.eq.' ') c6=' ' - c4=hisgrid(1:4) - if(c4.eq.' ') c4=' ' - fmt='(i6.4,1x,a4,i5,4i2,8i3,i4,f6.2,f7.1,f6.1,f7.1,f6.2,'// & - '1x,a6,1x,a6,1x,a4,1x,a)' - if(ntrperiod.le.30) fmt(5:5)='6' - if(idec.eq.3) nrc=0 - write(22,fmt) nutc,cmode,nfqso,nQSOprogress,idec,idfbest,idtbest, & - ibwa,ibwb,ibw,ndistbest,nused,icand,ncand,nrc,ndepth,xdt, & - f0,snr2,plog,tdecode,mycall(1:6),c6,c4,trim(decoded) - close(22) - endif - endif - endif - navg0=1000*navg(0) + navg(1) - if(single_decode .or. lagain) go to 900 - - do icand=1,ncand -! Prepare for single-period candidate decodes with iaptype = 0, 1, 2, or 4 - snr1=candidates(icand,1) - xdt= candidates(icand,2) - f0 = candidates(icand,3) - do i=1,ndecodes - fdiff=f0-f0decodes(i) - if(fdiff.gt.-baud*mode_q65 .and. fdiff.lt.65*baud*mode_q65) go to 800 - enddo - -!### TEST REGION - if(ncontest.eq.-1) then - call timer('q65_dec0',0) -! Call top-level routine in q65 module: establish sync and try for a -! q3 or q0 decode. - call q65_dec0(iavg,iwave,ntrperiod,nint(f0),ntol,lclearave, & - emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) - call timer('q65_dec0',1) - if(idec.ge.0) then - dtdec=xdt !We have a q3 or q0 decode at f0 - f0dec=f0 - go to 200 - endif - endif -!### - jpk0=(xdt+1.0)*6000 !Index of nominal start of signal - if(ntrperiod.le.30) jpk0=(xdt+0.5)*6000 !For shortest sequences - if(jpk0.lt.0) jpk0=0 - call ana64(iwave,npts,c00) !Convert to complex c00() at 6000 Sa/s - call ft8apset(mycall,hiscall,ncontest,apsym0,aph10) ! Generate ap symbols - where(apsym0.eq.-1) apsym0=0 - - npasses=2 - if(nQSOprogress.eq.5) npasses=3 - if(lapcqonly) npasses=1 - iaptype=0 - do ipass=0,npasses !Loop over AP passes -! write(*,3001) nutc,icand,ipass,f0,xdt,snr1 -!3001 format('a',i5.4,2i3,3f7.1) - apmask=0 !Try first with no AP information - apsymbols=0 - if(ipass.ge.1) then - ! Subsequent passes use AP information appropiate for nQSOprogress - call q65_ap(nQSOprogress,ipass,ncontest,lapcqonly,iaptype, & - apsym0,apmask1,apsymbols1) - write(c78,1050) apmask1 - read(c78,1060) apmask - write(c78,1050) apsymbols1 - read(c78,1060) apsymbols - endif - - call timer('q65loop2',0) - call q65_loops(c00,npts/2,nsps/2,nsubmode,ndepth,jpk0, & - xdt,f0,iaptype,xdt1,f1,snr2,dat4,idec) - call timer('q65loop2',1) -! write(*,3001) '=e',nfqso,ntol,ndepth,xdt,f0,idec - if(idec.ge.0) then - dtdec=xdt1 - f0dec=f1 - go to 200 !Successful decode, we're done - endif - enddo ! ipass - -200 decoded=' ' - if(idec.ge.0) then -! Unpack decoded message for display to user - write(c77,1000) dat4(1:12),dat4(13)/2 - call unpack77(c77,1,decoded,unpk77_success) !Unpack to get decoded - idupe=0 - do i=1,ndecodes - if(decodes(i).eq.decoded) idupe=1 - enddo - if(idupe.eq.0) then - ndecodes=min(ndecodes+1,100) - decodes(ndecodes)=decoded - f0decodes(ndecodes)=f0dec - call q65_snr(dat4,dtdec,f0dec,mode_q65,snr2) - nsnr=nint(snr2) - call this%callback(nutc,snr1,nsnr,dtdec,f0dec,decoded, & - idec,nused,ntrperiod) - if(ncontest.eq.1) then - call q65_hist2(nint(f0dec),decoded,callers,nhist2) - else - call q65_hist(nint(f0dec),msg0=decoded) - endif - if(iand(ndepth,128).ne.0 .and. .not.lagain .and. & - int(abs(f0dec-nfqso)).le.ntol ) call q65_clravg !AutoClrAvg - call sec0(1,tdecode) - ios=1 - open(22,file=trim(data_dir)//'/q65_decodes.txt',status='unknown',& - position='append',iostat=ios) - if(ios.eq.0) then -! Save decoding parameters to q65_decoded.dat, for later analysis. - write(cmode,'(i3)') ntrperiod - cmode(4:4)=char(ichar('A')+nsubmode) - c6=hiscall(1:6) - if(c6.eq.' ') c6=' ' - c4=hisgrid(1:4) - if(c4.eq.' ') c4=' ' - fmt='(i6.4,1x,a4,i5,4i2,8i3,i4,f6.2,f7.1,f6.1,f7.1,f6.2,'// & - '1x,a6,1x,a6,1x,a4,1x,a)' - if(ntrperiod.le.30) fmt(5:5)='6' - if(idec.eq.3) nrc=0 - write(22,fmt) nutc,cmode,nfqso,nQSOprogress,idec,idfbest, & - idtbest,ibwa,ibwb,ibw,ndistbest,nused,icand,ncand,nrc, & - ndepth,xdt,f0,snr2,plog,tdecode,mycall(1:6),c6,c4, & - trim(decoded) - close(22) - endif - endif - endif -800 continue - enddo ! icand - if(iavg.eq.0 .and.navg(iseq).ge.2 .and. iand(ndepth,16).ne.0) go to 50 - -900 if(ncontest.ne.1 .or. lagain) go to 999 - if(ntrperiod.ne.60 .or. nsubmode.ne.0) go to 999 - -! This is first time here, and we're running Q65-60A in NA VHF Contest mode. -! Return a list of potential sync frequencies at which to try q3 decoding. - - k=0 - nqf=0 - bw=baud*mode_q65*65 - do i=1,ncand -! snr1=candidates(i,1) -! xdt= candidates(i,2) - f0 = candidates(i,3) - do j=1,ndecodes ! Already decoded one at or near this frequency? - fj=f0decodes(j) - if(f0.gt.fj-5.0 .and. f0.lt.fj+bw+5.0) go to 990 - enddo - k=k+1 - nqf(k)=nint(f0) -990 continue - enddo - -999 return - end subroutine decode - -end module q65_decode +module q65_decode + + integer nsnr0,nfreq0 + real xdt0 + character msg0*37,cq0*3 + + type :: q65_decoder + procedure(q65_decode_callback), pointer :: callback + contains + procedure :: decode + end type q65_decoder + + abstract interface + subroutine q65_decode_callback (this,nutc,snr1,nsnr,dt,freq, & + decoded,idec,nused,ntrperiod) + import q65_decoder + implicit none + class(q65_decoder), intent(inout) :: this + integer, intent(in) :: nutc + real, intent(in) :: snr1 + integer, intent(in) :: nsnr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=37), intent(in) :: decoded + integer, intent(in) :: idec + integer, intent(in) :: nused + integer, intent(in) :: ntrperiod + end subroutine q65_decode_callback + end interface + +contains + + subroutine decode(this,callback,iwave,nqd0,nutc,ntrperiod,nsubmode,nfqso, & + ntol,ndepth,nfa0,nfb0,lclearave,single_decode,lagain,max_drift0, & + lnewdat0,emedelay,mycall,hiscall,hisgrid,nQSOprogress,ncontest, & + lapcqonly,navg0,nqf) + +! Top-level routine that organizes the decoding of Q65 signals +! Input: iwave Raw data, i*2 +! nutc UTC for time-tagging the decode +! ntrperiod T/R sequence length (s) +! nsubmode Tone-spacing indicator, 0-4 for A-E +! nfqso Target signal frequency (Hz) +! ntol Search range around nfqso (Hz) +! ndepth Optional decoding level +! lclearave Flag to clear the message-averaging arrays +! emedelay Sync search extended to cover EME delays +! nQSOprogress Auto-sequencing state for the present QSO +! ncontest Supported contest type +! lapcqonly Flag to use AP only for CQ calls +! Output: sent to the callback routine for display to user + + use timer_module, only: timer + use packjt77 + use, intrinsic :: iso_c_binding + use q65 !Shared variables + use prog_args + use types + + parameter (NMAX=300*12000) !Max TRperiod is 300 s + parameter (MAX_CALLERS=40) !For multiple q3 decodes in NA VHf Contest mode + + class(q65_decoder), intent(inout) :: this + + procedure(q65_decode_callback) :: callback + character(len=12) :: mycall, hiscall !Used for AP decoding + character(len=6) :: hisgrid + character*37 decoded !Decoded message + character*37 decodes(100) + character*77 c77 + character*78 c78 + character*6 cutc + character c6*6,c4*4,cmode*4 + character*80 fmt + integer*2 iwave(NMAX) !Raw data + real, allocatable :: dd(:) !Raw data + real xdtdecodes(100) + real f0decodes(100) + integer dat4(13) !Decoded message as 12 6-bit integers + integer dgen(13) + integer nqf(20) + integer stageno !Added by W3SZ + integer time + logical lclearave,lnewdat0,lapcqonly,unpk77_success + logical single_decode,lagain + complex, allocatable :: c00(:) !Analytic signal, 6000 Sa/s + complex, allocatable :: c0(:) !Analytic signal, 6000 Sa/s + type(q3list) callers(MAX_CALLERS) + +! Start by setting some parameters and allocating storage for large arrays + call sec0(0,tdecode) + stageno=0 + ndecodes=0 + decodes=' ' + f0decodes=0. + xdtdecodes=0. + nfa=nfa0 + nfb=nfb0 + nqd=nqd0 + lnewdat=lnewdat0 + max_drift=max_drift0 + idec=-1 + idf=0 + idt=0 + nrc=-2 + mode_q65=2**nsubmode + npts=ntrperiod*12000 + nfft1=ntrperiod*12000 + nfft2=ntrperiod*6000 + npasses=1 + nhist2=0 + if(lagain) ndepth=ior(ndepth,3) !Use 'Deep' for manual Q65 decodes + dxcall13=hiscall ! initialize for use in packjt77 + mycall13=mycall + if(ncontest.eq.1) then +! NA VHF, WW-Digi, or ARRL Digi Contest + open(24,file=trim(data_dir)//'/tsil.3q',status='unknown', & + form='unformatted') + read(24,end=2) nhist2 + if(nhist2.ge.1 .and. nhist2.le.40) then + read(24,end=2) callers(1:nhist2) + now=time() + do i=1,nhist2 + hours=(now - callers(i)%nsec)/3600.0 + if(hours.gt.24.0) then + callers(i:nhist2-1)=callers(i+1:nhist2) + nhist2=nhist2-1 + endif + enddo + else + nhist2=0 + endif +2 close(24) + endif + +! Determine the T/R sequence: iseq=0 (even), or iseq=1 (odd) + n=nutc + if(ntrperiod.ge.60 .and. nutc.le.2359) n=100*n + write(cutc,'(i6.6)') n + read(cutc,'(3i2)') ih,im,is + nsec=3600*ih + 60*im + is + iseq=mod(nsec/ntrperiod,2) + + if(lclearave) call q65_clravg + allocate(dd(npts)) + allocate (c00(0:nfft1-1)) + allocate (c0(0:nfft1-1)) + + if(lagain) then + call q65_hist(nfqso,dxcall=hiscall,dxgrid=hisgrid) + endif + + nsps=1800 + if(ntrperiod.eq.30) then + nsps=3600 + else if(ntrperiod.eq.60) then + nsps=7200 + else if(ntrperiod.eq.120) then + nsps=16000 + else if(ntrperiod.eq.300) then + nsps=41472 + endif + + baud=12000.0/nsps + this%callback => callback + nFadingModel=1 + +! ibwa=max(1,int(1.8*log(baud*mode_q65)) + 5) +!### This needs work! + ibwa=1 !Q65-60A + if(mode_q65.eq.2) ibwa=3 !Q65-60B + if(mode_q65.eq.4) ibwa=8 !Q65-60C + if(mode_q65.eq.8) ibwa=8 !Q65-60D + if(mode_q65.eq.16) ibwa=8 !Q65-60E +!### + +! ibwb=min(15,ibwa+4) + ibwb=min(15,ibwa+6) + maxiters=40 + if(iand(ndepth,3).eq.2) maxiters=60 + if(iand(ndepth,3).eq.3) then + ibwa=max(1,ibwa-2) + ibwb=min(15,ibwb+2) + maxiters=100 + endif + +! Generate codewords for full-AP list decoding + if(ichar(hiscall(1:1)).eq.0) hiscall=' ' + if(ichar(hisgrid(1:1)).eq.0) hisgrid=' ' + ncw=0 + if(nqd.eq.1 .or. lagain .or. ncontest.eq.1) then + if(ncontest.eq.1) then + call q65_set_list2(mycall,hiscall,hisgrid,callers,nhist2, & + codewords,ncw) + else + call q65_set_list(mycall,hiscall,hisgrid,codewords,ncw) + endif + endif + dgen=0 + call q65_enc(dgen,codewords) !Initialize the Q65 codec + nused=1 + iavg=0 + +! W3SZ patch: Initialize AP params here, rather than afer the call to ana64(). + call ft8apset(mycall,hiscall,ncontest,apsym0,aph10) ! Generate ap symbols + where(apsym0.eq.-1) apsym0=0 + npasses=2 + if(nQSOprogress.eq.5) npasses=3 + + call timer('q65_dec0',0) +! Call top-level routine in q65 module: establish sync and try for a +! q3 or q0 decode. + call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, & + emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) + call timer('q65_dec0',1) + + if(idec.ge.0) then + dtdec=xdt !We have a q3 or q0 decode at nfqso + f0dec=f0 + go to 100 + endif + + if(ncontest.eq.1 .and. lagain .and. iand(ndepth,16).eq.16) go to 50 + if(ncontest.eq.1 .and. lagain .and. iand(ndepth,16).eq.0) go to 100 + +! Prepare for a single-period decode with iaptype = 0, 1, 2, or 4 + jpk0=(xdt+1.0)*6000 !Index of nominal start of signal + if(ntrperiod.le.30) jpk0=(xdt+0.5)*6000 !For shortest sequences + if(jpk0.lt.0) jpk0=0 + call ana64(iwave,npts,c00) !Convert to complex c00() at 6000 Sa/s + if(lapcqonly) npasses=1 + iaptype=0 + do ipass=0,npasses !Loop over AP passes + apmask=0 !Try first with no AP information + apsymbols=0 + if(ipass.ge.1) then + ! Subsequent passes use AP information appropiate for nQSOprogress + call q65_ap(nQSOprogress,ipass,ncontest,lapcqonly,iaptype, & + apsym0,apmask1,apsymbols1) + write(c78,1050) apmask1 +1050 format(78i1) + read(c78,1060) apmask +1060 format(13b6.6) + write(c78,1050) apsymbols1 + read(c78,1060) apsymbols + endif + + call timer('q65loop1',0) + call q65_loops(c00,npts/2,nsps/2,nsubmode,ndepth,jpk0, & + xdt,f0,iaptype,xdt1,f1,snr2,dat4,idec) + call timer('q65loop1',1) + if(idec.ge.0) then + dtdec=xdt1 + f0dec=f1 + go to 100 !Successful decode, we're done + endif + enddo ! ipass + + if(iand(ndepth,16).eq.0 .or. navg(iseq).lt.2) go to 100 + +! There was no single-transmission decode. Try for an average 'q3n' decode. +50 iavg=1 + call timer('list_avg',0) +! Call top-level routine in q65 module: establish sync and try for a q3 +! decode, this time using the cumulative 's1a' symbol spectra. + call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, & + emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) + call timer('list_avg',1) + + if(idec.ge.0) then + dtdec=xdt !We have a list-decode result from averaged data + f0dec=f0 + nused=navg(iseq) + go to 100 + endif + +! There was no 'q3n' decode. Try for a 'q[0124]n' decode. +! Call top-level routine in q65 module: establish sync and try for a q[012]n +! decode, this time using the cumulative 's1a' symbol spectra. + + call timer('q65_avg ',0) + iavg=2 + call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, & + emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) + call timer('q65_avg ',1) + if(idec.ge.0) then + dtdec=xdt !We have a q[012]n result + f0dec=f0 + nused=navg(iseq) + endif + +100 if(idec.lt.0 .and. max_drift.eq.50) then + stageno = 5 + call timer('q65_dec0',0) + ! Call top-level routine in q65 module: establish sync and try for a + ! q3 or q0 decode. + call q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, & + emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) + call timer('q65_dec0',1) + if(idec.ge.0) then + dtdec=xdt !We have a q[012]n result + f0dec=f0 + endif + endif ! if(idec.lt.0) + + decoded=' ' + if(idec.ge.0) then +! idec Meaning +! ------------------------------------------------------ +! -1: No decode +! 0: Decode without AP information +! 1: Decode with AP for "CQ ? ?" +! 2: Decode with AP for "MyCall ? ?" +! 3: Decode with AP for "MyCall DxCall ?" + +! Unpack decoded message for display to user + write(c77,1000) dat4(1:12),dat4(13)/2 +1000 format(12b6.6,b5.5) + call unpack77(c77,1,decoded,unpk77_success) !Unpack to get decoded + idupe=0 + do i=1,ndecodes + if(decodes(i).eq.decoded) idupe=1 + enddo + if(idupe.eq.0) then + ndecodes=min(ndecodes+1,100) + decodes(ndecodes)=decoded + f0decodes(ndecodes)=f0dec + xdtdecodes(ndecodes)=dtdec + call q65_snr(dat4,dtdec,f0dec,mode_q65,snr2) + nsnr=nint(snr2) + call this%callback(nutc,snr1,nsnr,dtdec,f0dec,decoded, & + idec,nused,ntrperiod) + if(ncontest.eq.1) then + call q65_hist2(nint(f0dec),decoded,callers,nhist2) + else + call q65_hist(nint(f0dec),msg0=decoded) + endif + if(iand(ndepth,128).ne.0 .and. .not.lagain .and. & + int(abs(f0dec-nfqso)).le.ntol ) call q65_clravg !AutoClrAvg + call sec0(1,tdecode) + open(22,file=trim(data_dir)//'/q65_decodes.txt',status='unknown', & + position='append',iostat=ios) + if(ios.eq.0) then +! Save decoding parameters to q65_decoded.dat, for later analysis. + write(cmode,'(i3)') ntrperiod + cmode(4:4)=char(ichar('A')+nsubmode) + c6=hiscall(1:6) + if(c6.eq.' ') c6=' ' + c4=hisgrid(1:4) + if(c4.eq.' ') c4=' ' + fmt='(i6.4,1x,a4,i5,4i2,8i3,i4,f6.2,f7.1,f6.1,f7.1,f6.2,'// & + '1x,a6,1x,a6,1x,a4,1x,a)' + if(ntrperiod.le.30) fmt(5:5)='6' + if(idec.eq.3) nrc=0 + write(22,fmt) nutc,cmode,nfqso,nQSOprogress,idec,idfbest,idtbest, & + ibwa,ibwb,ibw,ndistbest,nused,icand,ncand,nrc,ndepth,xdt, & + f0,snr2,plog,tdecode,mycall(1:6),c6,c4,trim(decoded) + close(22) + endif + endif + endif + navg0=1000*navg(0) + navg(1) + if(single_decode .or. lagain) go to 900 + + do icand=1,ncand +! Prepare for single-period candidate decodes with iaptype = 0, 1, 2, or 4 + snr1=candidates(icand,1) + xdt= candidates(icand,2) + f0 = candidates(icand,3) + do i=1,ndecodes + fdiff=f0-f0decodes(i) + if(fdiff.gt.-baud*mode_q65 .and. fdiff.lt.65*baud*mode_q65) go to 800 + enddo + +!### TEST REGION + if(ncontest.eq.-1) then + call timer('q65_dec0',0) +! Call top-level routine in q65 module: establish sync and try for a +! q3 or q0 decode. + call q65_dec0(iavg,iwave,ntrperiod,nint(f0),ntol,lclearave, & + emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) + call timer('q65_dec0',1) + if(idec.ge.0) then + dtdec=xdt !We have a q3 or q0 decode at f0 + f0dec=f0 + go to 200 + endif + endif +!### + jpk0=(xdt+1.0)*6000 !Index of nominal start of signal + if(ntrperiod.le.30) jpk0=(xdt+0.5)*6000 !For shortest sequences + if(jpk0.lt.0) jpk0=0 + call ana64(iwave,npts,c00) !Convert to complex c00() at 6000 Sa/s + call ft8apset(mycall,hiscall,ncontest,apsym0,aph10) ! Generate ap symbols + where(apsym0.eq.-1) apsym0=0 + + npasses=2 + if(nQSOprogress.eq.5) npasses=3 + if(lapcqonly) npasses=1 + iaptype=0 + do ipass=0,npasses !Loop over AP passes +! write(*,3001) nutc,icand,ipass,f0,xdt,snr1 +!3001 format('a',i5.4,2i3,3f7.1) + apmask=0 !Try first with no AP information + apsymbols=0 + if(ipass.ge.1) then + ! Subsequent passes use AP information appropiate for nQSOprogress + call q65_ap(nQSOprogress,ipass,ncontest,lapcqonly,iaptype, & + apsym0,apmask1,apsymbols1) + write(c78,1050) apmask1 + read(c78,1060) apmask + write(c78,1050) apsymbols1 + read(c78,1060) apsymbols + endif + + call timer('q65loop2',0) + call q65_loops(c00,npts/2,nsps/2,nsubmode,ndepth,jpk0, & + xdt,f0,iaptype,xdt1,f1,snr2,dat4,idec) + call timer('q65loop2',1) +! write(*,3001) '=e',nfqso,ntol,ndepth,xdt,f0,idec + if(idec.ge.0) then + dtdec=xdt1 + f0dec=f1 + go to 200 !Successful decode, we're done + endif + enddo ! ipass + +200 decoded=' ' + if(idec.ge.0) then +! Unpack decoded message for display to user + write(c77,1000) dat4(1:12),dat4(13)/2 + call unpack77(c77,1,decoded,unpk77_success) !Unpack to get decoded + idupe=0 + do i=1,ndecodes + if(decodes(i).eq.decoded) idupe=1 + enddo + if(idupe.eq.0) then + ndecodes=min(ndecodes+1,100) + decodes(ndecodes)=decoded + f0decodes(ndecodes)=f0dec + call q65_snr(dat4,dtdec,f0dec,mode_q65,snr2) + nsnr=nint(snr2) + call this%callback(nutc,snr1,nsnr,dtdec,f0dec,decoded, & + idec,nused,ntrperiod) + if(ncontest.eq.1) then + call q65_hist2(nint(f0dec),decoded,callers,nhist2) + else + call q65_hist(nint(f0dec),msg0=decoded) + endif + if(iand(ndepth,128).ne.0 .and. .not.lagain .and. & + int(abs(f0dec-nfqso)).le.ntol ) call q65_clravg !AutoClrAvg + call sec0(1,tdecode) + ios=1 + open(22,file=trim(data_dir)//'/q65_decodes.txt',status='unknown',& + position='append',iostat=ios) + if(ios.eq.0) then +! Save decoding parameters to q65_decoded.dat, for later analysis. + write(cmode,'(i3)') ntrperiod + cmode(4:4)=char(ichar('A')+nsubmode) + c6=hiscall(1:6) + if(c6.eq.' ') c6=' ' + c4=hisgrid(1:4) + if(c4.eq.' ') c4=' ' + fmt='(i6.4,1x,a4,i5,4i2,8i3,i4,f6.2,f7.1,f6.1,f7.1,f6.2,'// & + '1x,a6,1x,a6,1x,a4,1x,a)' + if(ntrperiod.le.30) fmt(5:5)='6' + if(idec.eq.3) nrc=0 + write(22,fmt) nutc,cmode,nfqso,nQSOprogress,idec,idfbest, & + idtbest,ibwa,ibwb,ibw,ndistbest,nused,icand,ncand,nrc, & + ndepth,xdt,f0,snr2,plog,tdecode,mycall(1:6),c6,c4, & + trim(decoded) + close(22) + endif + endif + endif +800 continue + enddo ! icand + if(iavg.eq.0 .and.navg(iseq).ge.2 .and. iand(ndepth,16).ne.0) go to 50 + +900 if(ncontest.ne.1 .or. lagain) go to 999 + if(ntrperiod.ne.60 .or. nsubmode.ne.0) go to 999 + +! This is first time here, and we're running Q65-60A in NA VHF Contest mode. +! Return a list of potential sync frequencies at which to try q3 decoding. + + k=0 + nqf=0 + bw=baud*mode_q65*65 + do i=1,ncand +! snr1=candidates(i,1) +! xdt= candidates(i,2) + f0 = candidates(i,3) + do j=1,ndecodes ! Already decoded one at or near this frequency? + fj=f0decodes(j) + if(f0.gt.fj-5.0 .and. f0.lt.fj+bw+5.0) go to 990 + enddo + k=k+1 + nqf(k)=nint(f0) +990 continue + enddo + +999 return + end subroutine decode + +end module q65_decode diff --git a/lib/q65params.f90 b/lib/q65params.f90 index 345a1c8f..932dcfb3 100755 --- a/lib/q65params.f90 +++ b/lib/q65params.f90 @@ -1,32 +1,32 @@ -program q65params - - integer ntrp(5) - integer nsps(5) - data ntrp/15,30,60,120,300/ - data nsps/1800,3600,7200,16000,41472/ - - write(*,1000) -1000 format('T/R tsym baud BW TxT SNR'/39('-')) - do i=1,5 - baud=12000.0/nsps(i) - bw=65.0*baud - tsym=1.0/baud - txt=85.0*tsym - snr=-27.0 + 10.0*log10(7200.0/nsps(i)) - write(*,1010) ntrp(i),tsym,baud,bw,txt,snr -1010 format(i3,2f7.3,3f7.1) - enddo - - do j=1,5 - write(*,1020) char(ichar('A')+j-1) -1020 format(/a1,' T/R baud BW'/20('-')) - do i=1,5 - baud=12000.0/nsps(i) - spacing=baud*2**(j-1) - bw=65.0*spacing - write(*,1030) ntrp(i),spacing,nint(bw) -1030 format(i6,f7.2,i6) - enddo - enddo - -end program q65params +program q65params + + integer ntrp(5) + integer nsps(5) + data ntrp/15,30,60,120,300/ + data nsps/1800,3600,7200,16000,41472/ + + write(*,1000) +1000 format('T/R tsym baud BW TxT SNR'/39('-')) + do i=1,5 + baud=12000.0/nsps(i) + bw=65.0*baud + tsym=1.0/baud + txt=85.0*tsym + snr=-27.0 + 10.0*log10(7200.0/nsps(i)) + write(*,1010) ntrp(i),tsym,baud,bw,txt,snr +1010 format(i3,2f7.3,3f7.1) + enddo + + do j=1,5 + write(*,1020) char(ichar('A')+j-1) +1020 format(/a1,' T/R baud BW'/20('-')) + do i=1,5 + baud=12000.0/nsps(i) + spacing=baud*2**(j-1) + bw=65.0*spacing + write(*,1030) ntrp(i),spacing,nint(bw) +1030 format(i6,f7.2,i6) + enddo + enddo + +end program q65params diff --git a/lib/qra/q65/Makefile.Win b/lib/qra/q65/Makefile.Win index ba4bc513..8f2214d9 100755 --- a/lib/qra/q65/Makefile.Win +++ b/lib/qra/q65/Makefile.Win @@ -1,40 +1,40 @@ -CC = gcc -CFLAGS = -O2 -Wall -I. -D_WIN32 -FC = gfortran -FFLAGS = -Wall -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: libq65.a q65.exe q65_ftn_test.exe - -OBJS1 = normrnd.o npfwht.o pdmath.o qra15_65_64_irr_e23.o \ - q65.o qracodes.o - -libq65.a: $(OBJS1) - ar cr libq65.a $(OBJS1) - ranlib libq65.a - -OBJS2 = q65test.o - -q65.exe: $(OBJS2) - ${CC} -o q65.exe $(OBJS2) libq65.a -lm - -OBJS3 = q65_ftn_test.o q65_subs.o - -q65_ftn_test.exe: $(OBJS3) - ${FC} -o q65_ftn_test.exe $(OBJS3) libq65.a -lm - -.PHONY : clean - -clean: - $(RM) *.o libq65.a q65.exe +CC = gcc +CFLAGS = -O2 -Wall -I. -D_WIN32 +FC = gfortran +FFLAGS = -Wall -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: libq65.a q65.exe q65_ftn_test.exe + +OBJS1 = normrnd.o npfwht.o pdmath.o qra15_65_64_irr_e23.o \ + q65.o qracodes.o + +libq65.a: $(OBJS1) + ar cr libq65.a $(OBJS1) + ranlib libq65.a + +OBJS2 = q65test.o + +q65.exe: $(OBJS2) + ${CC} -o q65.exe $(OBJS2) libq65.a -lm + +OBJS3 = q65_ftn_test.o q65_subs.o + +q65_ftn_test.exe: $(OBJS3) + ${FC} -o q65_ftn_test.exe $(OBJS3) libq65.a -lm + +.PHONY : clean + +clean: + $(RM) *.o libq65.a q65.exe diff --git a/lib/qra/q65/build.sh b/lib/qra/q65/build.sh index 6a8a362b..3d7d76f1 100755 --- a/lib/qra/q65/build.sh +++ b/lib/qra/q65/build.sh @@ -1,2 +1,2 @@ -gcc -Wall -march=native -pthread -O3 *.c -lpthread -lm -o q65 - +gcc -Wall -march=native -pthread -O3 *.c -lpthread -lm -o q65 + diff --git a/lib/qra/q65/ebnovalues.txt b/lib/qra/q65/ebnovalues.txt index 42a6f41c..06a3f585 100755 --- a/lib/qra/q65/ebnovalues.txt +++ b/lib/qra/q65/ebnovalues.txt @@ -1,17 +1,17 @@ -# Eb/No Values to be used during the Q65 codec simulation -# Each line of this file indicates the Eb/No value to be simulated (in dB) -# and the number of errors that should be detected by the decoder -# -# Be careful that the simulation takes a long time to complete -# if the number of errors is large for the specified Eb/No -# (this is particularly true if AP decoding is used) -# --30 100 -0.5 1000 -1.0 1000 -1.5 1000 -2.0 1000 -2.5 1000 -3.0 1000 -3.5 1000 +# Eb/No Values to be used during the Q65 codec simulation +# Each line of this file indicates the Eb/No value to be simulated (in dB) +# and the number of errors that should be detected by the decoder +# +# Be careful that the simulation takes a long time to complete +# if the number of errors is large for the specified Eb/No +# (this is particularly true if AP decoding is used) +# +-30 100 +0.5 1000 +1.0 1000 +1.5 1000 +2.0 1000 +2.5 1000 +3.0 1000 +3.5 1000 4.0 1000 \ No newline at end of file diff --git a/lib/qra/q65/fadengauss.c b/lib/qra/q65/fadengauss.c index c229626f..f6ca2725 100755 --- a/lib/qra/q65/fadengauss.c +++ b/lib/qra/q65/fadengauss.c @@ -1,302 +1,302 @@ -// Gaussian energy fading tables for QRA64 -static const int glen_tab_gauss[64] = { - 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, - 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 5, 5, 5, 6, - 6, 6, 7, 7, 8, 8, 9, 10, - 10, 11, 12, 13, 14, 15, 17, 18, - 19, 21, 23, 25, 27, 29, 32, 34, - 37, 41, 44, 48, 52, 57, 62, 65 -}; -static const float ggauss1[2] = { -0.0296f, 0.9101f -}; -static const float ggauss2[2] = { -0.0350f, 0.8954f -}; -static const float ggauss3[2] = { -0.0411f, 0.8787f -}; -static const float ggauss4[2] = { -0.0483f, 0.8598f -}; -static const float ggauss5[2] = { -0.0566f, 0.8387f -}; -static const float ggauss6[2] = { -0.0660f, 0.8154f -}; -static const float ggauss7[2] = { -0.0767f, 0.7898f -}; -static const float ggauss8[2] = { -0.0886f, 0.7621f -}; -static const float ggauss9[2] = { -0.1017f, 0.7325f -}; -static const float ggauss10[2] = { -0.1159f, 0.7012f -}; -static const float ggauss11[2] = { -0.1310f, 0.6687f -}; -static const float ggauss12[2] = { -0.1465f, 0.6352f -}; -static const float ggauss13[2] = { -0.1621f, 0.6013f -}; -static const float ggauss14[2] = { -0.1771f, 0.5674f -}; -static const float ggauss15[2] = { -0.1911f, 0.5339f -}; -static const float ggauss16[2] = { -0.2034f, 0.5010f -}; -static const float ggauss17[3] = { -0.0299f, 0.2135f, 0.4690f -}; -static const float ggauss18[3] = { -0.0369f, 0.2212f, 0.4383f -}; -static const float ggauss19[3] = { -0.0454f, 0.2263f, 0.4088f -}; -static const float ggauss20[3] = { -0.0552f, 0.2286f, 0.3806f -}; -static const float ggauss21[3] = { -0.0658f, 0.2284f, 0.3539f -}; -static const float ggauss22[3] = { -0.0766f, 0.2258f, 0.3287f -}; -static const float ggauss23[3] = { -0.0869f, 0.2212f, 0.3049f -}; -static const float ggauss24[3] = { -0.0962f, 0.2148f, 0.2826f -}; -static const float ggauss25[4] = { -0.0351f, 0.1041f, 0.2071f, 0.2616f -}; -static const float ggauss26[4] = { -0.0429f, 0.1102f, 0.1984f, 0.2420f -}; -static const float ggauss27[4] = { -0.0508f, 0.1145f, 0.1890f, 0.2237f -}; -static const float ggauss28[4] = { -0.0582f, 0.1169f, 0.1791f, 0.2067f -}; -static const float ggauss29[5] = { -0.0289f, 0.0648f, 0.1176f, 0.1689f, 0.1908f -}; -static const float ggauss30[5] = { -0.0351f, 0.0703f, 0.1168f, 0.1588f, 0.1760f -}; -static const float ggauss31[5] = { -0.0411f, 0.0745f, 0.1146f, 0.1488f, 0.1623f -}; -static const float ggauss32[6] = { -0.0246f, 0.0466f, 0.0773f, 0.1115f, 0.1390f, 0.1497f -}; -static const float ggauss33[6] = { -0.0297f, 0.0512f, 0.0788f, 0.1075f, 0.1295f, 0.1379f -}; -static const float ggauss34[6] = { -0.0345f, 0.0549f, 0.0791f, 0.1029f, 0.1205f, 0.1270f -}; -static const float ggauss35[7] = { -0.0240f, 0.0387f, 0.0575f, 0.0784f, 0.0979f, 0.1118f, 0.1169f -}; -static const float ggauss36[7] = { -0.0281f, 0.0422f, 0.0590f, 0.0767f, 0.0926f, 0.1037f, 0.1076f -}; -static const float ggauss37[8] = { -0.0212f, 0.0318f, 0.0449f, 0.0596f, 0.0744f, 0.0872f, 0.0960f, 0.0991f -}; -static const float ggauss38[8] = { -0.0247f, 0.0348f, 0.0467f, 0.0593f, 0.0716f, 0.0819f, 0.0887f, 0.0911f -}; -static const float ggauss39[9] = { -0.0199f, 0.0278f, 0.0372f, 0.0476f, 0.0584f, 0.0684f, 0.0766f, 0.0819f, -0.0838f -}; -static const float ggauss40[10] = { -0.0166f, 0.0228f, 0.0303f, 0.0388f, 0.0478f, 0.0568f, 0.0649f, 0.0714f, -0.0756f, 0.0771f -}; -static const float ggauss41[10] = { -0.0193f, 0.0254f, 0.0322f, 0.0397f, 0.0474f, 0.0548f, 0.0613f, 0.0664f, -0.0697f, 0.0709f -}; -static const float ggauss42[11] = { -0.0168f, 0.0217f, 0.0273f, 0.0335f, 0.0399f, 0.0464f, 0.0524f, 0.0576f, -0.0617f, 0.0643f, 0.0651f -}; -static const float ggauss43[12] = { -0.0151f, 0.0191f, 0.0237f, 0.0288f, 0.0342f, 0.0396f, 0.0449f, 0.0498f, -0.0540f, 0.0572f, 0.0592f, 0.0599f -}; -static const float ggauss44[13] = { -0.0138f, 0.0171f, 0.0210f, 0.0252f, 0.0297f, 0.0343f, 0.0388f, 0.0432f, -0.0471f, 0.0504f, 0.0529f, 0.0545f, 0.0550f -}; -static const float ggauss45[14] = { -0.0128f, 0.0157f, 0.0189f, 0.0224f, 0.0261f, 0.0300f, 0.0339f, 0.0377f, -0.0412f, 0.0444f, 0.0470f, 0.0489f, 0.0501f, 0.0505f -}; -static const float ggauss46[15] = { -0.0121f, 0.0146f, 0.0173f, 0.0202f, 0.0234f, 0.0266f, 0.0299f, 0.0332f, -0.0363f, 0.0391f, 0.0416f, 0.0437f, 0.0452f, 0.0461f, 0.0464f -}; -static const float ggauss47[17] = { -0.0097f, 0.0116f, 0.0138f, 0.0161f, 0.0186f, 0.0212f, 0.0239f, 0.0267f, -0.0294f, 0.0321f, 0.0346f, 0.0369f, 0.0389f, 0.0405f, 0.0417f, 0.0424f, -0.0427f -}; -static const float ggauss48[18] = { -0.0096f, 0.0113f, 0.0131f, 0.0151f, 0.0172f, 0.0194f, 0.0217f, 0.0241f, -0.0264f, 0.0287f, 0.0308f, 0.0329f, 0.0347f, 0.0362f, 0.0375f, 0.0384f, -0.0390f, 0.0392f -}; -static const float ggauss49[19] = { -0.0095f, 0.0110f, 0.0126f, 0.0143f, 0.0161f, 0.0180f, 0.0199f, 0.0219f, -0.0239f, 0.0258f, 0.0277f, 0.0294f, 0.0310f, 0.0325f, 0.0337f, 0.0347f, -0.0354f, 0.0358f, 0.0360f -}; -static const float ggauss50[21] = { -0.0083f, 0.0095f, 0.0108f, 0.0122f, 0.0136f, 0.0152f, 0.0168f, 0.0184f, -0.0201f, 0.0217f, 0.0234f, 0.0250f, 0.0265f, 0.0279f, 0.0292f, 0.0303f, -0.0313f, 0.0320f, 0.0326f, 0.0329f, 0.0330f -}; -static const float ggauss51[23] = { -0.0074f, 0.0084f, 0.0095f, 0.0106f, 0.0118f, 0.0131f, 0.0144f, 0.0157f, -0.0171f, 0.0185f, 0.0199f, 0.0213f, 0.0227f, 0.0240f, 0.0252f, 0.0263f, -0.0273f, 0.0282f, 0.0290f, 0.0296f, 0.0300f, 0.0303f, 0.0303f -}; -static const float ggauss52[25] = { -0.0068f, 0.0076f, 0.0085f, 0.0094f, 0.0104f, 0.0115f, 0.0126f, 0.0137f, -0.0149f, 0.0160f, 0.0172f, 0.0184f, 0.0196f, 0.0207f, 0.0218f, 0.0228f, -0.0238f, 0.0247f, 0.0255f, 0.0262f, 0.0268f, 0.0273f, 0.0276f, 0.0278f, -0.0279f -}; -static const float ggauss53[27] = { -0.0063f, 0.0070f, 0.0078f, 0.0086f, 0.0094f, 0.0103f, 0.0112f, 0.0121f, -0.0131f, 0.0141f, 0.0151f, 0.0161f, 0.0170f, 0.0180f, 0.0190f, 0.0199f, -0.0208f, 0.0216f, 0.0224f, 0.0231f, 0.0237f, 0.0243f, 0.0247f, 0.0251f, -0.0254f, 0.0255f, 0.0256f -}; -static const float ggauss54[29] = { -0.0060f, 0.0066f, 0.0072f, 0.0079f, 0.0086f, 0.0093f, 0.0101f, 0.0109f, -0.0117f, 0.0125f, 0.0133f, 0.0142f, 0.0150f, 0.0159f, 0.0167f, 0.0175f, -0.0183f, 0.0190f, 0.0197f, 0.0204f, 0.0210f, 0.0216f, 0.0221f, 0.0225f, -0.0228f, 0.0231f, 0.0233f, 0.0234f, 0.0235f -}; -static const float ggauss55[32] = { -0.0053f, 0.0058f, 0.0063f, 0.0068f, 0.0074f, 0.0080f, 0.0086f, 0.0093f, -0.0099f, 0.0106f, 0.0113f, 0.0120f, 0.0127f, 0.0134f, 0.0141f, 0.0148f, -0.0155f, 0.0162f, 0.0168f, 0.0174f, 0.0180f, 0.0186f, 0.0191f, 0.0196f, -0.0201f, 0.0204f, 0.0208f, 0.0211f, 0.0213f, 0.0214f, 0.0215f, 0.0216f -}; -static const float ggauss56[34] = { -0.0052f, 0.0056f, 0.0060f, 0.0065f, 0.0070f, 0.0075f, 0.0080f, 0.0086f, -0.0091f, 0.0097f, 0.0103f, 0.0109f, 0.0115f, 0.0121f, 0.0127f, 0.0133f, -0.0138f, 0.0144f, 0.0150f, 0.0155f, 0.0161f, 0.0166f, 0.0170f, 0.0175f, -0.0179f, 0.0183f, 0.0186f, 0.0189f, 0.0192f, 0.0194f, 0.0196f, 0.0197f, -0.0198f, 0.0198f -}; -static const float ggauss57[37] = { -0.0047f, 0.0051f, 0.0055f, 0.0058f, 0.0063f, 0.0067f, 0.0071f, 0.0076f, -0.0080f, 0.0085f, 0.0090f, 0.0095f, 0.0100f, 0.0105f, 0.0110f, 0.0115f, -0.0120f, 0.0125f, 0.0130f, 0.0134f, 0.0139f, 0.0144f, 0.0148f, 0.0152f, -0.0156f, 0.0160f, 0.0164f, 0.0167f, 0.0170f, 0.0173f, 0.0175f, 0.0177f, -0.0179f, 0.0180f, 0.0181f, 0.0181f, 0.0182f -}; -static const float ggauss58[41] = { -0.0041f, 0.0044f, 0.0047f, 0.0050f, 0.0054f, 0.0057f, 0.0060f, 0.0064f, -0.0068f, 0.0072f, 0.0076f, 0.0080f, 0.0084f, 0.0088f, 0.0092f, 0.0096f, -0.0101f, 0.0105f, 0.0109f, 0.0113f, 0.0117f, 0.0121f, 0.0125f, 0.0129f, -0.0133f, 0.0137f, 0.0140f, 0.0144f, 0.0147f, 0.0150f, 0.0153f, 0.0155f, -0.0158f, 0.0160f, 0.0162f, 0.0163f, 0.0164f, 0.0165f, 0.0166f, 0.0167f, -0.0167f -}; -static const float ggauss59[44] = { -0.0039f, 0.0042f, 0.0044f, 0.0047f, 0.0050f, 0.0053f, 0.0056f, 0.0059f, -0.0062f, 0.0065f, 0.0068f, 0.0072f, 0.0075f, 0.0079f, 0.0082f, 0.0086f, -0.0089f, 0.0093f, 0.0096f, 0.0100f, 0.0104f, 0.0107f, 0.0110f, 0.0114f, -0.0117f, 0.0120f, 0.0124f, 0.0127f, 0.0130f, 0.0132f, 0.0135f, 0.0138f, -0.0140f, 0.0142f, 0.0144f, 0.0146f, 0.0148f, 0.0149f, 0.0150f, 0.0151f, -0.0152f, 0.0153f, 0.0153f, 0.0153f -}; -static const float ggauss60[48] = { -0.0036f, 0.0038f, 0.0040f, 0.0042f, 0.0044f, 0.0047f, 0.0049f, 0.0052f, -0.0055f, 0.0057f, 0.0060f, 0.0063f, 0.0066f, 0.0068f, 0.0071f, 0.0074f, -0.0077f, 0.0080f, 0.0083f, 0.0086f, 0.0089f, 0.0092f, 0.0095f, 0.0098f, -0.0101f, 0.0104f, 0.0107f, 0.0109f, 0.0112f, 0.0115f, 0.0117f, 0.0120f, -0.0122f, 0.0124f, 0.0126f, 0.0128f, 0.0130f, 0.0132f, 0.0134f, 0.0135f, -0.0136f, 0.0137f, 0.0138f, 0.0139f, 0.0140f, 0.0140f, 0.0140f, 0.0140f -}; -static const float ggauss61[52] = { -0.0033f, 0.0035f, 0.0037f, 0.0039f, 0.0041f, 0.0043f, 0.0045f, 0.0047f, -0.0049f, 0.0051f, 0.0053f, 0.0056f, 0.0058f, 0.0060f, 0.0063f, 0.0065f, -0.0068f, 0.0070f, 0.0073f, 0.0075f, 0.0078f, 0.0080f, 0.0083f, 0.0085f, -0.0088f, 0.0090f, 0.0093f, 0.0095f, 0.0098f, 0.0100f, 0.0102f, 0.0105f, -0.0107f, 0.0109f, 0.0111f, 0.0113f, 0.0115f, 0.0116f, 0.0118f, 0.0120f, -0.0121f, 0.0122f, 0.0124f, 0.0125f, 0.0126f, 0.0126f, 0.0127f, 0.0128f, -0.0128f, 0.0129f, 0.0129f, 0.0129f -}; -static const float ggauss62[57] = { -0.0030f, 0.0031f, 0.0033f, 0.0034f, 0.0036f, 0.0038f, 0.0039f, 0.0041f, -0.0043f, 0.0045f, 0.0047f, 0.0048f, 0.0050f, 0.0052f, 0.0054f, 0.0056f, -0.0058f, 0.0060f, 0.0063f, 0.0065f, 0.0067f, 0.0069f, 0.0071f, 0.0073f, -0.0075f, 0.0077f, 0.0080f, 0.0082f, 0.0084f, 0.0086f, 0.0088f, 0.0090f, -0.0092f, 0.0094f, 0.0096f, 0.0097f, 0.0099f, 0.0101f, 0.0103f, 0.0104f, -0.0106f, 0.0107f, 0.0108f, 0.0110f, 0.0111f, 0.0112f, 0.0113f, 0.0114f, -0.0115f, 0.0116f, 0.0116f, 0.0117f, 0.0117f, 0.0118f, 0.0118f, 0.0118f, -0.0118f -}; -static const float ggauss63[62] = { -0.0027f, 0.0029f, 0.0030f, 0.0031f, 0.0032f, 0.0034f, 0.0035f, 0.0037f, -0.0038f, 0.0040f, 0.0041f, 0.0043f, 0.0045f, 0.0046f, 0.0048f, 0.0049f, -0.0051f, 0.0053f, 0.0055f, 0.0056f, 0.0058f, 0.0060f, 0.0062f, 0.0063f, -0.0065f, 0.0067f, 0.0069f, 0.0071f, 0.0072f, 0.0074f, 0.0076f, 0.0078f, -0.0079f, 0.0081f, 0.0083f, 0.0084f, 0.0086f, 0.0088f, 0.0089f, 0.0091f, -0.0092f, 0.0094f, 0.0095f, 0.0096f, 0.0098f, 0.0099f, 0.0100f, 0.0101f, -0.0102f, 0.0103f, 0.0104f, 0.0105f, 0.0105f, 0.0106f, 0.0107f, 0.0107f, -0.0108f, 0.0108f, 0.0108f, 0.0108f, 0.0109f, 0.0109f -}; -static const float ggauss64[65] = { -0.0028f, 0.0029f, 0.0030f, 0.0031f, 0.0032f, 0.0034f, 0.0035f, 0.0036f, -0.0037f, 0.0039f, 0.0040f, 0.0041f, 0.0043f, 0.0044f, 0.0046f, 0.0047f, -0.0048f, 0.0050f, 0.0051f, 0.0053f, 0.0054f, 0.0056f, 0.0057f, 0.0059f, -0.0060f, 0.0062f, 0.0063f, 0.0065f, 0.0066f, 0.0068f, 0.0069f, 0.0071f, -0.0072f, 0.0074f, 0.0075f, 0.0077f, 0.0078f, 0.0079f, 0.0081f, 0.0082f, -0.0083f, 0.0084f, 0.0086f, 0.0087f, 0.0088f, 0.0089f, 0.0090f, 0.0091f, -0.0092f, 0.0093f, 0.0094f, 0.0094f, 0.0095f, 0.0096f, 0.0097f, 0.0097f, -0.0098f, 0.0098f, 0.0099f, 0.0099f, 0.0099f, 0.0099f, 0.0100f, 0.0100f, -0.0100f -}; -static const float *gptr_tab_gauss[64] = { -ggauss1, ggauss2, ggauss3, ggauss4, -ggauss5, ggauss6, ggauss7, ggauss8, -ggauss9, ggauss10, ggauss11, ggauss12, -ggauss13, ggauss14, ggauss15, ggauss16, -ggauss17, ggauss18, ggauss19, ggauss20, -ggauss21, ggauss22, ggauss23, ggauss24, -ggauss25, ggauss26, ggauss27, ggauss28, -ggauss29, ggauss30, ggauss31, ggauss32, -ggauss33, ggauss34, ggauss35, ggauss36, -ggauss37, ggauss38, ggauss39, ggauss40, -ggauss41, ggauss42, ggauss43, ggauss44, -ggauss45, ggauss46, ggauss47, ggauss48, -ggauss49, ggauss50, ggauss51, ggauss52, -ggauss53, ggauss54, ggauss55, ggauss56, -ggauss57, ggauss58, ggauss59, ggauss60, -ggauss61, ggauss62, ggauss63, ggauss64 -}; +// Gaussian energy fading tables for QRA64 +static const int glen_tab_gauss[64] = { + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, 5, 5, 5, 6, + 6, 6, 7, 7, 8, 8, 9, 10, + 10, 11, 12, 13, 14, 15, 17, 18, + 19, 21, 23, 25, 27, 29, 32, 34, + 37, 41, 44, 48, 52, 57, 62, 65 +}; +static const float ggauss1[2] = { +0.0296f, 0.9101f +}; +static const float ggauss2[2] = { +0.0350f, 0.8954f +}; +static const float ggauss3[2] = { +0.0411f, 0.8787f +}; +static const float ggauss4[2] = { +0.0483f, 0.8598f +}; +static const float ggauss5[2] = { +0.0566f, 0.8387f +}; +static const float ggauss6[2] = { +0.0660f, 0.8154f +}; +static const float ggauss7[2] = { +0.0767f, 0.7898f +}; +static const float ggauss8[2] = { +0.0886f, 0.7621f +}; +static const float ggauss9[2] = { +0.1017f, 0.7325f +}; +static const float ggauss10[2] = { +0.1159f, 0.7012f +}; +static const float ggauss11[2] = { +0.1310f, 0.6687f +}; +static const float ggauss12[2] = { +0.1465f, 0.6352f +}; +static const float ggauss13[2] = { +0.1621f, 0.6013f +}; +static const float ggauss14[2] = { +0.1771f, 0.5674f +}; +static const float ggauss15[2] = { +0.1911f, 0.5339f +}; +static const float ggauss16[2] = { +0.2034f, 0.5010f +}; +static const float ggauss17[3] = { +0.0299f, 0.2135f, 0.4690f +}; +static const float ggauss18[3] = { +0.0369f, 0.2212f, 0.4383f +}; +static const float ggauss19[3] = { +0.0454f, 0.2263f, 0.4088f +}; +static const float ggauss20[3] = { +0.0552f, 0.2286f, 0.3806f +}; +static const float ggauss21[3] = { +0.0658f, 0.2284f, 0.3539f +}; +static const float ggauss22[3] = { +0.0766f, 0.2258f, 0.3287f +}; +static const float ggauss23[3] = { +0.0869f, 0.2212f, 0.3049f +}; +static const float ggauss24[3] = { +0.0962f, 0.2148f, 0.2826f +}; +static const float ggauss25[4] = { +0.0351f, 0.1041f, 0.2071f, 0.2616f +}; +static const float ggauss26[4] = { +0.0429f, 0.1102f, 0.1984f, 0.2420f +}; +static const float ggauss27[4] = { +0.0508f, 0.1145f, 0.1890f, 0.2237f +}; +static const float ggauss28[4] = { +0.0582f, 0.1169f, 0.1791f, 0.2067f +}; +static const float ggauss29[5] = { +0.0289f, 0.0648f, 0.1176f, 0.1689f, 0.1908f +}; +static const float ggauss30[5] = { +0.0351f, 0.0703f, 0.1168f, 0.1588f, 0.1760f +}; +static const float ggauss31[5] = { +0.0411f, 0.0745f, 0.1146f, 0.1488f, 0.1623f +}; +static const float ggauss32[6] = { +0.0246f, 0.0466f, 0.0773f, 0.1115f, 0.1390f, 0.1497f +}; +static const float ggauss33[6] = { +0.0297f, 0.0512f, 0.0788f, 0.1075f, 0.1295f, 0.1379f +}; +static const float ggauss34[6] = { +0.0345f, 0.0549f, 0.0791f, 0.1029f, 0.1205f, 0.1270f +}; +static const float ggauss35[7] = { +0.0240f, 0.0387f, 0.0575f, 0.0784f, 0.0979f, 0.1118f, 0.1169f +}; +static const float ggauss36[7] = { +0.0281f, 0.0422f, 0.0590f, 0.0767f, 0.0926f, 0.1037f, 0.1076f +}; +static const float ggauss37[8] = { +0.0212f, 0.0318f, 0.0449f, 0.0596f, 0.0744f, 0.0872f, 0.0960f, 0.0991f +}; +static const float ggauss38[8] = { +0.0247f, 0.0348f, 0.0467f, 0.0593f, 0.0716f, 0.0819f, 0.0887f, 0.0911f +}; +static const float ggauss39[9] = { +0.0199f, 0.0278f, 0.0372f, 0.0476f, 0.0584f, 0.0684f, 0.0766f, 0.0819f, +0.0838f +}; +static const float ggauss40[10] = { +0.0166f, 0.0228f, 0.0303f, 0.0388f, 0.0478f, 0.0568f, 0.0649f, 0.0714f, +0.0756f, 0.0771f +}; +static const float ggauss41[10] = { +0.0193f, 0.0254f, 0.0322f, 0.0397f, 0.0474f, 0.0548f, 0.0613f, 0.0664f, +0.0697f, 0.0709f +}; +static const float ggauss42[11] = { +0.0168f, 0.0217f, 0.0273f, 0.0335f, 0.0399f, 0.0464f, 0.0524f, 0.0576f, +0.0617f, 0.0643f, 0.0651f +}; +static const float ggauss43[12] = { +0.0151f, 0.0191f, 0.0237f, 0.0288f, 0.0342f, 0.0396f, 0.0449f, 0.0498f, +0.0540f, 0.0572f, 0.0592f, 0.0599f +}; +static const float ggauss44[13] = { +0.0138f, 0.0171f, 0.0210f, 0.0252f, 0.0297f, 0.0343f, 0.0388f, 0.0432f, +0.0471f, 0.0504f, 0.0529f, 0.0545f, 0.0550f +}; +static const float ggauss45[14] = { +0.0128f, 0.0157f, 0.0189f, 0.0224f, 0.0261f, 0.0300f, 0.0339f, 0.0377f, +0.0412f, 0.0444f, 0.0470f, 0.0489f, 0.0501f, 0.0505f +}; +static const float ggauss46[15] = { +0.0121f, 0.0146f, 0.0173f, 0.0202f, 0.0234f, 0.0266f, 0.0299f, 0.0332f, +0.0363f, 0.0391f, 0.0416f, 0.0437f, 0.0452f, 0.0461f, 0.0464f +}; +static const float ggauss47[17] = { +0.0097f, 0.0116f, 0.0138f, 0.0161f, 0.0186f, 0.0212f, 0.0239f, 0.0267f, +0.0294f, 0.0321f, 0.0346f, 0.0369f, 0.0389f, 0.0405f, 0.0417f, 0.0424f, +0.0427f +}; +static const float ggauss48[18] = { +0.0096f, 0.0113f, 0.0131f, 0.0151f, 0.0172f, 0.0194f, 0.0217f, 0.0241f, +0.0264f, 0.0287f, 0.0308f, 0.0329f, 0.0347f, 0.0362f, 0.0375f, 0.0384f, +0.0390f, 0.0392f +}; +static const float ggauss49[19] = { +0.0095f, 0.0110f, 0.0126f, 0.0143f, 0.0161f, 0.0180f, 0.0199f, 0.0219f, +0.0239f, 0.0258f, 0.0277f, 0.0294f, 0.0310f, 0.0325f, 0.0337f, 0.0347f, +0.0354f, 0.0358f, 0.0360f +}; +static const float ggauss50[21] = { +0.0083f, 0.0095f, 0.0108f, 0.0122f, 0.0136f, 0.0152f, 0.0168f, 0.0184f, +0.0201f, 0.0217f, 0.0234f, 0.0250f, 0.0265f, 0.0279f, 0.0292f, 0.0303f, +0.0313f, 0.0320f, 0.0326f, 0.0329f, 0.0330f +}; +static const float ggauss51[23] = { +0.0074f, 0.0084f, 0.0095f, 0.0106f, 0.0118f, 0.0131f, 0.0144f, 0.0157f, +0.0171f, 0.0185f, 0.0199f, 0.0213f, 0.0227f, 0.0240f, 0.0252f, 0.0263f, +0.0273f, 0.0282f, 0.0290f, 0.0296f, 0.0300f, 0.0303f, 0.0303f +}; +static const float ggauss52[25] = { +0.0068f, 0.0076f, 0.0085f, 0.0094f, 0.0104f, 0.0115f, 0.0126f, 0.0137f, +0.0149f, 0.0160f, 0.0172f, 0.0184f, 0.0196f, 0.0207f, 0.0218f, 0.0228f, +0.0238f, 0.0247f, 0.0255f, 0.0262f, 0.0268f, 0.0273f, 0.0276f, 0.0278f, +0.0279f +}; +static const float ggauss53[27] = { +0.0063f, 0.0070f, 0.0078f, 0.0086f, 0.0094f, 0.0103f, 0.0112f, 0.0121f, +0.0131f, 0.0141f, 0.0151f, 0.0161f, 0.0170f, 0.0180f, 0.0190f, 0.0199f, +0.0208f, 0.0216f, 0.0224f, 0.0231f, 0.0237f, 0.0243f, 0.0247f, 0.0251f, +0.0254f, 0.0255f, 0.0256f +}; +static const float ggauss54[29] = { +0.0060f, 0.0066f, 0.0072f, 0.0079f, 0.0086f, 0.0093f, 0.0101f, 0.0109f, +0.0117f, 0.0125f, 0.0133f, 0.0142f, 0.0150f, 0.0159f, 0.0167f, 0.0175f, +0.0183f, 0.0190f, 0.0197f, 0.0204f, 0.0210f, 0.0216f, 0.0221f, 0.0225f, +0.0228f, 0.0231f, 0.0233f, 0.0234f, 0.0235f +}; +static const float ggauss55[32] = { +0.0053f, 0.0058f, 0.0063f, 0.0068f, 0.0074f, 0.0080f, 0.0086f, 0.0093f, +0.0099f, 0.0106f, 0.0113f, 0.0120f, 0.0127f, 0.0134f, 0.0141f, 0.0148f, +0.0155f, 0.0162f, 0.0168f, 0.0174f, 0.0180f, 0.0186f, 0.0191f, 0.0196f, +0.0201f, 0.0204f, 0.0208f, 0.0211f, 0.0213f, 0.0214f, 0.0215f, 0.0216f +}; +static const float ggauss56[34] = { +0.0052f, 0.0056f, 0.0060f, 0.0065f, 0.0070f, 0.0075f, 0.0080f, 0.0086f, +0.0091f, 0.0097f, 0.0103f, 0.0109f, 0.0115f, 0.0121f, 0.0127f, 0.0133f, +0.0138f, 0.0144f, 0.0150f, 0.0155f, 0.0161f, 0.0166f, 0.0170f, 0.0175f, +0.0179f, 0.0183f, 0.0186f, 0.0189f, 0.0192f, 0.0194f, 0.0196f, 0.0197f, +0.0198f, 0.0198f +}; +static const float ggauss57[37] = { +0.0047f, 0.0051f, 0.0055f, 0.0058f, 0.0063f, 0.0067f, 0.0071f, 0.0076f, +0.0080f, 0.0085f, 0.0090f, 0.0095f, 0.0100f, 0.0105f, 0.0110f, 0.0115f, +0.0120f, 0.0125f, 0.0130f, 0.0134f, 0.0139f, 0.0144f, 0.0148f, 0.0152f, +0.0156f, 0.0160f, 0.0164f, 0.0167f, 0.0170f, 0.0173f, 0.0175f, 0.0177f, +0.0179f, 0.0180f, 0.0181f, 0.0181f, 0.0182f +}; +static const float ggauss58[41] = { +0.0041f, 0.0044f, 0.0047f, 0.0050f, 0.0054f, 0.0057f, 0.0060f, 0.0064f, +0.0068f, 0.0072f, 0.0076f, 0.0080f, 0.0084f, 0.0088f, 0.0092f, 0.0096f, +0.0101f, 0.0105f, 0.0109f, 0.0113f, 0.0117f, 0.0121f, 0.0125f, 0.0129f, +0.0133f, 0.0137f, 0.0140f, 0.0144f, 0.0147f, 0.0150f, 0.0153f, 0.0155f, +0.0158f, 0.0160f, 0.0162f, 0.0163f, 0.0164f, 0.0165f, 0.0166f, 0.0167f, +0.0167f +}; +static const float ggauss59[44] = { +0.0039f, 0.0042f, 0.0044f, 0.0047f, 0.0050f, 0.0053f, 0.0056f, 0.0059f, +0.0062f, 0.0065f, 0.0068f, 0.0072f, 0.0075f, 0.0079f, 0.0082f, 0.0086f, +0.0089f, 0.0093f, 0.0096f, 0.0100f, 0.0104f, 0.0107f, 0.0110f, 0.0114f, +0.0117f, 0.0120f, 0.0124f, 0.0127f, 0.0130f, 0.0132f, 0.0135f, 0.0138f, +0.0140f, 0.0142f, 0.0144f, 0.0146f, 0.0148f, 0.0149f, 0.0150f, 0.0151f, +0.0152f, 0.0153f, 0.0153f, 0.0153f +}; +static const float ggauss60[48] = { +0.0036f, 0.0038f, 0.0040f, 0.0042f, 0.0044f, 0.0047f, 0.0049f, 0.0052f, +0.0055f, 0.0057f, 0.0060f, 0.0063f, 0.0066f, 0.0068f, 0.0071f, 0.0074f, +0.0077f, 0.0080f, 0.0083f, 0.0086f, 0.0089f, 0.0092f, 0.0095f, 0.0098f, +0.0101f, 0.0104f, 0.0107f, 0.0109f, 0.0112f, 0.0115f, 0.0117f, 0.0120f, +0.0122f, 0.0124f, 0.0126f, 0.0128f, 0.0130f, 0.0132f, 0.0134f, 0.0135f, +0.0136f, 0.0137f, 0.0138f, 0.0139f, 0.0140f, 0.0140f, 0.0140f, 0.0140f +}; +static const float ggauss61[52] = { +0.0033f, 0.0035f, 0.0037f, 0.0039f, 0.0041f, 0.0043f, 0.0045f, 0.0047f, +0.0049f, 0.0051f, 0.0053f, 0.0056f, 0.0058f, 0.0060f, 0.0063f, 0.0065f, +0.0068f, 0.0070f, 0.0073f, 0.0075f, 0.0078f, 0.0080f, 0.0083f, 0.0085f, +0.0088f, 0.0090f, 0.0093f, 0.0095f, 0.0098f, 0.0100f, 0.0102f, 0.0105f, +0.0107f, 0.0109f, 0.0111f, 0.0113f, 0.0115f, 0.0116f, 0.0118f, 0.0120f, +0.0121f, 0.0122f, 0.0124f, 0.0125f, 0.0126f, 0.0126f, 0.0127f, 0.0128f, +0.0128f, 0.0129f, 0.0129f, 0.0129f +}; +static const float ggauss62[57] = { +0.0030f, 0.0031f, 0.0033f, 0.0034f, 0.0036f, 0.0038f, 0.0039f, 0.0041f, +0.0043f, 0.0045f, 0.0047f, 0.0048f, 0.0050f, 0.0052f, 0.0054f, 0.0056f, +0.0058f, 0.0060f, 0.0063f, 0.0065f, 0.0067f, 0.0069f, 0.0071f, 0.0073f, +0.0075f, 0.0077f, 0.0080f, 0.0082f, 0.0084f, 0.0086f, 0.0088f, 0.0090f, +0.0092f, 0.0094f, 0.0096f, 0.0097f, 0.0099f, 0.0101f, 0.0103f, 0.0104f, +0.0106f, 0.0107f, 0.0108f, 0.0110f, 0.0111f, 0.0112f, 0.0113f, 0.0114f, +0.0115f, 0.0116f, 0.0116f, 0.0117f, 0.0117f, 0.0118f, 0.0118f, 0.0118f, +0.0118f +}; +static const float ggauss63[62] = { +0.0027f, 0.0029f, 0.0030f, 0.0031f, 0.0032f, 0.0034f, 0.0035f, 0.0037f, +0.0038f, 0.0040f, 0.0041f, 0.0043f, 0.0045f, 0.0046f, 0.0048f, 0.0049f, +0.0051f, 0.0053f, 0.0055f, 0.0056f, 0.0058f, 0.0060f, 0.0062f, 0.0063f, +0.0065f, 0.0067f, 0.0069f, 0.0071f, 0.0072f, 0.0074f, 0.0076f, 0.0078f, +0.0079f, 0.0081f, 0.0083f, 0.0084f, 0.0086f, 0.0088f, 0.0089f, 0.0091f, +0.0092f, 0.0094f, 0.0095f, 0.0096f, 0.0098f, 0.0099f, 0.0100f, 0.0101f, +0.0102f, 0.0103f, 0.0104f, 0.0105f, 0.0105f, 0.0106f, 0.0107f, 0.0107f, +0.0108f, 0.0108f, 0.0108f, 0.0108f, 0.0109f, 0.0109f +}; +static const float ggauss64[65] = { +0.0028f, 0.0029f, 0.0030f, 0.0031f, 0.0032f, 0.0034f, 0.0035f, 0.0036f, +0.0037f, 0.0039f, 0.0040f, 0.0041f, 0.0043f, 0.0044f, 0.0046f, 0.0047f, +0.0048f, 0.0050f, 0.0051f, 0.0053f, 0.0054f, 0.0056f, 0.0057f, 0.0059f, +0.0060f, 0.0062f, 0.0063f, 0.0065f, 0.0066f, 0.0068f, 0.0069f, 0.0071f, +0.0072f, 0.0074f, 0.0075f, 0.0077f, 0.0078f, 0.0079f, 0.0081f, 0.0082f, +0.0083f, 0.0084f, 0.0086f, 0.0087f, 0.0088f, 0.0089f, 0.0090f, 0.0091f, +0.0092f, 0.0093f, 0.0094f, 0.0094f, 0.0095f, 0.0096f, 0.0097f, 0.0097f, +0.0098f, 0.0098f, 0.0099f, 0.0099f, 0.0099f, 0.0099f, 0.0100f, 0.0100f, +0.0100f +}; +static const float *gptr_tab_gauss[64] = { +ggauss1, ggauss2, ggauss3, ggauss4, +ggauss5, ggauss6, ggauss7, ggauss8, +ggauss9, ggauss10, ggauss11, ggauss12, +ggauss13, ggauss14, ggauss15, ggauss16, +ggauss17, ggauss18, ggauss19, ggauss20, +ggauss21, ggauss22, ggauss23, ggauss24, +ggauss25, ggauss26, ggauss27, ggauss28, +ggauss29, ggauss30, ggauss31, ggauss32, +ggauss33, ggauss34, ggauss35, ggauss36, +ggauss37, ggauss38, ggauss39, ggauss40, +ggauss41, ggauss42, ggauss43, ggauss44, +ggauss45, ggauss46, ggauss47, ggauss48, +ggauss49, ggauss50, ggauss51, ggauss52, +ggauss53, ggauss54, ggauss55, ggauss56, +ggauss57, ggauss58, ggauss59, ggauss60, +ggauss61, ggauss62, ggauss63, ggauss64 +}; diff --git a/lib/qra/q65/fadenlorentz.c b/lib/qra/q65/fadenlorentz.c index 673a8903..22329f65 100755 --- a/lib/qra/q65/fadenlorentz.c +++ b/lib/qra/q65/fadenlorentz.c @@ -1,304 +1,304 @@ -// Lorentz energy fading tables for QRA64 -static const int glen_tab_lorentz[64] = { - 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 3, 3, - 3, 3, 3, 3, 3, 4, 4, 4, - 4, 4, 5, 5, 5, 5, 6, 6, - 7, 7, 7, 8, 8, 9, 10, 10, - 11, 12, 13, 14, 15, 16, 17, 19, - 20, 22, 23, 25, 27, 30, 32, 35, - 38, 41, 45, 49, 53, 57, 62, 65 -}; -static const float glorentz1[2] = { -0.0214f, 0.9107f -}; -static const float glorentz2[2] = { -0.0244f, 0.9030f -}; -static const float glorentz3[2] = { -0.0280f, 0.8950f -}; -static const float glorentz4[2] = { -0.0314f, 0.8865f -}; -static const float glorentz5[2] = { -0.0349f, 0.8773f -}; -static const float glorentz6[2] = { -0.0388f, 0.8675f -}; -static const float glorentz7[2] = { -0.0426f, 0.8571f -}; -static const float glorentz8[2] = { -0.0463f, 0.8459f -}; -static const float glorentz9[2] = { -0.0500f, 0.8339f -}; -static const float glorentz10[2] = { -0.0538f, 0.8210f -}; -static const float glorentz11[2] = { -0.0579f, 0.8074f -}; -static const float glorentz12[2] = { -0.0622f, 0.7930f -}; -static const float glorentz13[2] = { -0.0668f, 0.7777f -}; -static const float glorentz14[2] = { -0.0715f, 0.7616f -}; -static const float glorentz15[3] = { -0.0196f, 0.0765f, 0.7445f -}; -static const float glorentz16[3] = { -0.0210f, 0.0816f, 0.7267f -}; -static const float glorentz17[3] = { -0.0226f, 0.0870f, 0.7080f -}; -static const float glorentz18[3] = { -0.0242f, 0.0925f, 0.6885f -}; -static const float glorentz19[3] = { -0.0259f, 0.0981f, 0.6682f -}; -static const float glorentz20[3] = { -0.0277f, 0.1039f, 0.6472f -}; -static const float glorentz21[3] = { -0.0296f, 0.1097f, 0.6255f -}; -static const float glorentz22[4] = { -0.0143f, 0.0316f, 0.1155f, 0.6031f -}; -static const float glorentz23[4] = { -0.0153f, 0.0337f, 0.1213f, 0.5803f -}; -static const float glorentz24[4] = { -0.0163f, 0.0358f, 0.1270f, 0.5570f -}; -static const float glorentz25[4] = { -0.0174f, 0.0381f, 0.1325f, 0.5333f -}; -static const float glorentz26[4] = { -0.0186f, 0.0405f, 0.1378f, 0.5095f -}; -static const float glorentz27[5] = { -0.0113f, 0.0198f, 0.0429f, 0.1428f, 0.4855f -}; -static const float glorentz28[5] = { -0.0120f, 0.0211f, 0.0455f, 0.1473f, 0.4615f -}; -static const float glorentz29[5] = { -0.0129f, 0.0225f, 0.0481f, 0.1514f, 0.4376f -}; -static const float glorentz30[5] = { -0.0137f, 0.0239f, 0.0508f, 0.1549f, 0.4140f -}; -static const float glorentz31[6] = { -0.0095f, 0.0147f, 0.0254f, 0.0536f, 0.1578f, 0.3907f -}; -static const float glorentz32[6] = { -0.0101f, 0.0156f, 0.0270f, 0.0564f, 0.1600f, 0.3680f -}; -static const float glorentz33[7] = { -0.0076f, 0.0109f, 0.0167f, 0.0287f, 0.0592f, 0.1614f, 0.3458f -}; -static const float glorentz34[7] = { -0.0081f, 0.0116f, 0.0178f, 0.0305f, 0.0621f, 0.1620f, 0.3243f -}; -static const float glorentz35[7] = { -0.0087f, 0.0124f, 0.0190f, 0.0324f, 0.0649f, 0.1618f, 0.3035f -}; -static const float glorentz36[8] = { -0.0069f, 0.0093f, 0.0133f, 0.0203f, 0.0343f, 0.0676f, 0.1607f, 0.2836f -}; -static const float glorentz37[8] = { -0.0074f, 0.0100f, 0.0142f, 0.0216f, 0.0362f, 0.0702f, 0.1588f, 0.2645f -}; -static const float glorentz38[9] = { -0.0061f, 0.0080f, 0.0107f, 0.0152f, 0.0230f, 0.0382f, 0.0726f, 0.1561f, -0.2464f -}; -static const float glorentz39[10] = { -0.0052f, 0.0066f, 0.0086f, 0.0115f, 0.0162f, 0.0244f, 0.0402f, 0.0747f, -0.1526f, 0.2291f -}; -static const float glorentz40[10] = { -0.0056f, 0.0071f, 0.0092f, 0.0123f, 0.0173f, 0.0259f, 0.0422f, 0.0766f, -0.1484f, 0.2128f -}; -static const float glorentz41[11] = { -0.0049f, 0.0061f, 0.0076f, 0.0098f, 0.0132f, 0.0184f, 0.0274f, 0.0441f, -0.0780f, 0.1437f, 0.1975f -}; -static const float glorentz42[12] = { -0.0044f, 0.0053f, 0.0065f, 0.0082f, 0.0106f, 0.0141f, 0.0196f, 0.0290f, -0.0460f, 0.0791f, 0.1384f, 0.1831f -}; -static const float glorentz43[13] = { -0.0040f, 0.0048f, 0.0057f, 0.0070f, 0.0088f, 0.0113f, 0.0150f, 0.0209f, -0.0305f, 0.0477f, 0.0797f, 0.1327f, 0.1695f -}; -static const float glorentz44[14] = { -0.0037f, 0.0043f, 0.0051f, 0.0062f, 0.0075f, 0.0094f, 0.0121f, 0.0160f, -0.0221f, 0.0321f, 0.0493f, 0.0799f, 0.1267f, 0.1568f -}; -static const float glorentz45[15] = { -0.0035f, 0.0040f, 0.0047f, 0.0055f, 0.0066f, 0.0081f, 0.0101f, 0.0129f, -0.0171f, 0.0234f, 0.0335f, 0.0506f, 0.0795f, 0.1204f, 0.1450f -}; -static const float glorentz46[16] = { -0.0033f, 0.0037f, 0.0043f, 0.0050f, 0.0059f, 0.0071f, 0.0087f, 0.0108f, -0.0138f, 0.0181f, 0.0246f, 0.0349f, 0.0517f, 0.0786f, 0.1141f, 0.1340f -}; -static const float glorentz47[17] = { -0.0031f, 0.0035f, 0.0040f, 0.0046f, 0.0054f, 0.0064f, 0.0077f, 0.0093f, -0.0116f, 0.0147f, 0.0192f, 0.0259f, 0.0362f, 0.0525f, 0.0773f, 0.1076f, -0.1237f -}; -static const float glorentz48[19] = { -0.0027f, 0.0030f, 0.0034f, 0.0038f, 0.0043f, 0.0050f, 0.0058f, 0.0069f, -0.0082f, 0.0100f, 0.0123f, 0.0156f, 0.0203f, 0.0271f, 0.0374f, 0.0530f, -0.0755f, 0.1013f, 0.1141f -}; -static const float glorentz49[20] = { -0.0026f, 0.0029f, 0.0032f, 0.0036f, 0.0041f, 0.0047f, 0.0054f, 0.0063f, -0.0074f, 0.0088f, 0.0107f, 0.0131f, 0.0165f, 0.0213f, 0.0282f, 0.0383f, -0.0531f, 0.0734f, 0.0950f, 0.1053f -}; -static const float glorentz50[22] = { -0.0023f, 0.0025f, 0.0028f, 0.0031f, 0.0035f, 0.0039f, 0.0044f, 0.0050f, -0.0058f, 0.0067f, 0.0079f, 0.0094f, 0.0114f, 0.0139f, 0.0175f, 0.0223f, -0.0292f, 0.0391f, 0.0529f, 0.0709f, 0.0889f, 0.0971f -}; -static const float glorentz51[23] = { -0.0023f, 0.0025f, 0.0027f, 0.0030f, 0.0034f, 0.0037f, 0.0042f, 0.0048f, -0.0054f, 0.0062f, 0.0072f, 0.0085f, 0.0100f, 0.0121f, 0.0148f, 0.0184f, -0.0233f, 0.0301f, 0.0396f, 0.0524f, 0.0681f, 0.0829f, 0.0894f -}; -static const float glorentz52[25] = { -0.0021f, 0.0023f, 0.0025f, 0.0027f, 0.0030f, 0.0033f, 0.0036f, 0.0040f, -0.0045f, 0.0051f, 0.0058f, 0.0067f, 0.0077f, 0.0090f, 0.0107f, 0.0128f, -0.0156f, 0.0192f, 0.0242f, 0.0308f, 0.0398f, 0.0515f, 0.0650f, 0.0772f, -0.0824f -}; -static const float glorentz53[27] = { -0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0027f, 0.0029f, 0.0032f, 0.0035f, -0.0039f, 0.0044f, 0.0049f, 0.0055f, 0.0062f, 0.0072f, 0.0083f, 0.0096f, -0.0113f, 0.0135f, 0.0164f, 0.0201f, 0.0249f, 0.0314f, 0.0398f, 0.0502f, -0.0619f, 0.0718f, 0.0759f -}; -static const float glorentz54[30] = { -0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0026f, 0.0029f, -0.0031f, 0.0034f, 0.0038f, 0.0042f, 0.0047f, 0.0052f, 0.0059f, 0.0067f, -0.0076f, 0.0088f, 0.0102f, 0.0120f, 0.0143f, 0.0171f, 0.0208f, 0.0256f, -0.0317f, 0.0395f, 0.0488f, 0.0586f, 0.0666f, 0.0698f -}; -static const float glorentz55[32] = { -0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0026f, -0.0028f, 0.0031f, 0.0034f, 0.0037f, 0.0041f, 0.0045f, 0.0050f, 0.0056f, -0.0063f, 0.0071f, 0.0081f, 0.0094f, 0.0108f, 0.0127f, 0.0149f, 0.0178f, -0.0214f, 0.0261f, 0.0318f, 0.0389f, 0.0470f, 0.0553f, 0.0618f, 0.0643f -}; -static const float glorentz56[35] = { -0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0020f, 0.0021f, 0.0023f, -0.0024f, 0.0026f, 0.0028f, 0.0031f, 0.0033f, 0.0036f, 0.0040f, 0.0044f, -0.0049f, 0.0054f, 0.0060f, 0.0067f, 0.0076f, 0.0087f, 0.0099f, 0.0114f, -0.0133f, 0.0156f, 0.0184f, 0.0220f, 0.0264f, 0.0318f, 0.0381f, 0.0451f, -0.0520f, 0.0572f, 0.0591f -}; -static const float glorentz57[38] = { -0.0013f, 0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, -0.0021f, 0.0023f, 0.0024f, 0.0026f, 0.0028f, 0.0031f, 0.0033f, 0.0036f, -0.0039f, 0.0043f, 0.0047f, 0.0052f, 0.0058f, 0.0064f, 0.0072f, 0.0081f, -0.0092f, 0.0104f, 0.0120f, 0.0139f, 0.0162f, 0.0190f, 0.0224f, 0.0265f, -0.0315f, 0.0371f, 0.0431f, 0.0487f, 0.0529f, 0.0544f -}; -static const float glorentz58[41] = { -0.0012f, 0.0013f, 0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, -0.0019f, 0.0020f, 0.0022f, 0.0023f, 0.0025f, 0.0026f, 0.0028f, 0.0030f, -0.0033f, 0.0036f, 0.0039f, 0.0042f, 0.0046f, 0.0050f, 0.0056f, 0.0061f, -0.0068f, 0.0076f, 0.0086f, 0.0097f, 0.0110f, 0.0125f, 0.0144f, 0.0167f, -0.0194f, 0.0226f, 0.0265f, 0.0309f, 0.0359f, 0.0409f, 0.0455f, 0.0488f, -0.0500f -}; -static const float glorentz59[45] = { -0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, 0.0015f, 0.0016f, -0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0023f, 0.0025f, -0.0026f, 0.0028f, 0.0030f, 0.0033f, 0.0035f, 0.0038f, 0.0041f, 0.0045f, -0.0049f, 0.0054f, 0.0059f, 0.0065f, 0.0072f, 0.0081f, 0.0090f, 0.0102f, -0.0115f, 0.0130f, 0.0149f, 0.0171f, 0.0197f, 0.0227f, 0.0263f, 0.0302f, -0.0345f, 0.0387f, 0.0425f, 0.0451f, 0.0460f -}; -static const float glorentz60[49] = { -0.0010f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, -0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, 0.0021f, -0.0022f, 0.0024f, 0.0025f, 0.0027f, 0.0028f, 0.0030f, 0.0033f, 0.0035f, -0.0038f, 0.0041f, 0.0044f, 0.0048f, 0.0052f, 0.0057f, 0.0063f, 0.0069f, -0.0077f, 0.0085f, 0.0095f, 0.0106f, 0.0119f, 0.0135f, 0.0153f, 0.0174f, -0.0199f, 0.0227f, 0.0259f, 0.0293f, 0.0330f, 0.0365f, 0.0395f, 0.0415f, -0.0423f -}; -static const float glorentz61[53] = { -0.0009f, 0.0010f, 0.0010f, 0.0011f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, -0.0013f, 0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0016f, 0.0017f, 0.0018f, -0.0019f, 0.0020f, 0.0021f, 0.0023f, 0.0024f, 0.0025f, 0.0027f, 0.0029f, -0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0041f, 0.0044f, 0.0047f, 0.0051f, -0.0056f, 0.0061f, 0.0067f, 0.0073f, 0.0081f, 0.0089f, 0.0099f, 0.0110f, -0.0124f, 0.0139f, 0.0156f, 0.0176f, 0.0199f, 0.0225f, 0.0253f, 0.0283f, -0.0314f, 0.0343f, 0.0367f, 0.0383f, 0.0389f -}; -static const float glorentz62[57] = { -0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, 0.0011f, 0.0011f, 0.0011f, -0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, 0.0015f, 0.0015f, 0.0016f, -0.0017f, 0.0018f, 0.0019f, 0.0020f, 0.0021f, 0.0022f, 0.0023f, 0.0024f, -0.0026f, 0.0027f, 0.0029f, 0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0040f, -0.0043f, 0.0047f, 0.0050f, 0.0055f, 0.0059f, 0.0064f, 0.0070f, 0.0077f, -0.0085f, 0.0093f, 0.0103f, 0.0114f, 0.0127f, 0.0142f, 0.0158f, 0.0177f, -0.0198f, 0.0221f, 0.0246f, 0.0272f, 0.0297f, 0.0321f, 0.0340f, 0.0353f, -0.0357f -}; -static const float glorentz63[62] = { -0.0008f, 0.0008f, 0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, 0.0010f, -0.0011f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, -0.0015f, 0.0015f, 0.0016f, 0.0017f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, -0.0021f, 0.0022f, 0.0023f, 0.0025f, 0.0026f, 0.0028f, 0.0029f, 0.0031f, -0.0033f, 0.0035f, 0.0038f, 0.0040f, 0.0043f, 0.0046f, 0.0050f, 0.0053f, -0.0058f, 0.0062f, 0.0068f, 0.0074f, 0.0081f, 0.0088f, 0.0097f, 0.0106f, -0.0117f, 0.0130f, 0.0144f, 0.0159f, 0.0176f, 0.0195f, 0.0216f, 0.0237f, -0.0259f, 0.0280f, 0.0299f, 0.0315f, 0.0325f, 0.0328f -}; -static const float glorentz64[65] = { -0.0008f, 0.0008f, 0.0008f, 0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, -0.0010f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, -0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, -0.0020f, 0.0021f, 0.0022f, 0.0023f, 0.0024f, 0.0025f, 0.0027f, 0.0028f, -0.0030f, 0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0040f, 0.0043f, 0.0046f, -0.0049f, 0.0052f, 0.0056f, 0.0061f, 0.0066f, 0.0071f, 0.0077f, 0.0084f, -0.0091f, 0.0100f, 0.0109f, 0.0120f, 0.0132f, 0.0145f, 0.0159f, 0.0175f, -0.0192f, 0.0209f, 0.0228f, 0.0246f, 0.0264f, 0.0279f, 0.0291f, 0.0299f, -0.0301f -}; -static const float *gptr_tab_lorentz[64] = { -glorentz1, glorentz2, glorentz3, glorentz4, -glorentz5, glorentz6, glorentz7, glorentz8, -glorentz9, glorentz10, glorentz11, glorentz12, -glorentz13, glorentz14, glorentz15, glorentz16, -glorentz17, glorentz18, glorentz19, glorentz20, -glorentz21, glorentz22, glorentz23, glorentz24, -glorentz25, glorentz26, glorentz27, glorentz28, -glorentz29, glorentz30, glorentz31, glorentz32, -glorentz33, glorentz34, glorentz35, glorentz36, -glorentz37, glorentz38, glorentz39, glorentz40, -glorentz41, glorentz42, glorentz43, glorentz44, -glorentz45, glorentz46, glorentz47, glorentz48, -glorentz49, glorentz50, glorentz51, glorentz52, -glorentz53, glorentz54, glorentz55, glorentz56, -glorentz57, glorentz58, glorentz59, glorentz60, -glorentz61, glorentz62, glorentz63, glorentz64 -}; +// Lorentz energy fading tables for QRA64 +static const int glen_tab_lorentz[64] = { + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 4, 4, 4, + 4, 4, 5, 5, 5, 5, 6, 6, + 7, 7, 7, 8, 8, 9, 10, 10, + 11, 12, 13, 14, 15, 16, 17, 19, + 20, 22, 23, 25, 27, 30, 32, 35, + 38, 41, 45, 49, 53, 57, 62, 65 +}; +static const float glorentz1[2] = { +0.0214f, 0.9107f +}; +static const float glorentz2[2] = { +0.0244f, 0.9030f +}; +static const float glorentz3[2] = { +0.0280f, 0.8950f +}; +static const float glorentz4[2] = { +0.0314f, 0.8865f +}; +static const float glorentz5[2] = { +0.0349f, 0.8773f +}; +static const float glorentz6[2] = { +0.0388f, 0.8675f +}; +static const float glorentz7[2] = { +0.0426f, 0.8571f +}; +static const float glorentz8[2] = { +0.0463f, 0.8459f +}; +static const float glorentz9[2] = { +0.0500f, 0.8339f +}; +static const float glorentz10[2] = { +0.0538f, 0.8210f +}; +static const float glorentz11[2] = { +0.0579f, 0.8074f +}; +static const float glorentz12[2] = { +0.0622f, 0.7930f +}; +static const float glorentz13[2] = { +0.0668f, 0.7777f +}; +static const float glorentz14[2] = { +0.0715f, 0.7616f +}; +static const float glorentz15[3] = { +0.0196f, 0.0765f, 0.7445f +}; +static const float glorentz16[3] = { +0.0210f, 0.0816f, 0.7267f +}; +static const float glorentz17[3] = { +0.0226f, 0.0870f, 0.7080f +}; +static const float glorentz18[3] = { +0.0242f, 0.0925f, 0.6885f +}; +static const float glorentz19[3] = { +0.0259f, 0.0981f, 0.6682f +}; +static const float glorentz20[3] = { +0.0277f, 0.1039f, 0.6472f +}; +static const float glorentz21[3] = { +0.0296f, 0.1097f, 0.6255f +}; +static const float glorentz22[4] = { +0.0143f, 0.0316f, 0.1155f, 0.6031f +}; +static const float glorentz23[4] = { +0.0153f, 0.0337f, 0.1213f, 0.5803f +}; +static const float glorentz24[4] = { +0.0163f, 0.0358f, 0.1270f, 0.5570f +}; +static const float glorentz25[4] = { +0.0174f, 0.0381f, 0.1325f, 0.5333f +}; +static const float glorentz26[4] = { +0.0186f, 0.0405f, 0.1378f, 0.5095f +}; +static const float glorentz27[5] = { +0.0113f, 0.0198f, 0.0429f, 0.1428f, 0.4855f +}; +static const float glorentz28[5] = { +0.0120f, 0.0211f, 0.0455f, 0.1473f, 0.4615f +}; +static const float glorentz29[5] = { +0.0129f, 0.0225f, 0.0481f, 0.1514f, 0.4376f +}; +static const float glorentz30[5] = { +0.0137f, 0.0239f, 0.0508f, 0.1549f, 0.4140f +}; +static const float glorentz31[6] = { +0.0095f, 0.0147f, 0.0254f, 0.0536f, 0.1578f, 0.3907f +}; +static const float glorentz32[6] = { +0.0101f, 0.0156f, 0.0270f, 0.0564f, 0.1600f, 0.3680f +}; +static const float glorentz33[7] = { +0.0076f, 0.0109f, 0.0167f, 0.0287f, 0.0592f, 0.1614f, 0.3458f +}; +static const float glorentz34[7] = { +0.0081f, 0.0116f, 0.0178f, 0.0305f, 0.0621f, 0.1620f, 0.3243f +}; +static const float glorentz35[7] = { +0.0087f, 0.0124f, 0.0190f, 0.0324f, 0.0649f, 0.1618f, 0.3035f +}; +static const float glorentz36[8] = { +0.0069f, 0.0093f, 0.0133f, 0.0203f, 0.0343f, 0.0676f, 0.1607f, 0.2836f +}; +static const float glorentz37[8] = { +0.0074f, 0.0100f, 0.0142f, 0.0216f, 0.0362f, 0.0702f, 0.1588f, 0.2645f +}; +static const float glorentz38[9] = { +0.0061f, 0.0080f, 0.0107f, 0.0152f, 0.0230f, 0.0382f, 0.0726f, 0.1561f, +0.2464f +}; +static const float glorentz39[10] = { +0.0052f, 0.0066f, 0.0086f, 0.0115f, 0.0162f, 0.0244f, 0.0402f, 0.0747f, +0.1526f, 0.2291f +}; +static const float glorentz40[10] = { +0.0056f, 0.0071f, 0.0092f, 0.0123f, 0.0173f, 0.0259f, 0.0422f, 0.0766f, +0.1484f, 0.2128f +}; +static const float glorentz41[11] = { +0.0049f, 0.0061f, 0.0076f, 0.0098f, 0.0132f, 0.0184f, 0.0274f, 0.0441f, +0.0780f, 0.1437f, 0.1975f +}; +static const float glorentz42[12] = { +0.0044f, 0.0053f, 0.0065f, 0.0082f, 0.0106f, 0.0141f, 0.0196f, 0.0290f, +0.0460f, 0.0791f, 0.1384f, 0.1831f +}; +static const float glorentz43[13] = { +0.0040f, 0.0048f, 0.0057f, 0.0070f, 0.0088f, 0.0113f, 0.0150f, 0.0209f, +0.0305f, 0.0477f, 0.0797f, 0.1327f, 0.1695f +}; +static const float glorentz44[14] = { +0.0037f, 0.0043f, 0.0051f, 0.0062f, 0.0075f, 0.0094f, 0.0121f, 0.0160f, +0.0221f, 0.0321f, 0.0493f, 0.0799f, 0.1267f, 0.1568f +}; +static const float glorentz45[15] = { +0.0035f, 0.0040f, 0.0047f, 0.0055f, 0.0066f, 0.0081f, 0.0101f, 0.0129f, +0.0171f, 0.0234f, 0.0335f, 0.0506f, 0.0795f, 0.1204f, 0.1450f +}; +static const float glorentz46[16] = { +0.0033f, 0.0037f, 0.0043f, 0.0050f, 0.0059f, 0.0071f, 0.0087f, 0.0108f, +0.0138f, 0.0181f, 0.0246f, 0.0349f, 0.0517f, 0.0786f, 0.1141f, 0.1340f +}; +static const float glorentz47[17] = { +0.0031f, 0.0035f, 0.0040f, 0.0046f, 0.0054f, 0.0064f, 0.0077f, 0.0093f, +0.0116f, 0.0147f, 0.0192f, 0.0259f, 0.0362f, 0.0525f, 0.0773f, 0.1076f, +0.1237f +}; +static const float glorentz48[19] = { +0.0027f, 0.0030f, 0.0034f, 0.0038f, 0.0043f, 0.0050f, 0.0058f, 0.0069f, +0.0082f, 0.0100f, 0.0123f, 0.0156f, 0.0203f, 0.0271f, 0.0374f, 0.0530f, +0.0755f, 0.1013f, 0.1141f +}; +static const float glorentz49[20] = { +0.0026f, 0.0029f, 0.0032f, 0.0036f, 0.0041f, 0.0047f, 0.0054f, 0.0063f, +0.0074f, 0.0088f, 0.0107f, 0.0131f, 0.0165f, 0.0213f, 0.0282f, 0.0383f, +0.0531f, 0.0734f, 0.0950f, 0.1053f +}; +static const float glorentz50[22] = { +0.0023f, 0.0025f, 0.0028f, 0.0031f, 0.0035f, 0.0039f, 0.0044f, 0.0050f, +0.0058f, 0.0067f, 0.0079f, 0.0094f, 0.0114f, 0.0139f, 0.0175f, 0.0223f, +0.0292f, 0.0391f, 0.0529f, 0.0709f, 0.0889f, 0.0971f +}; +static const float glorentz51[23] = { +0.0023f, 0.0025f, 0.0027f, 0.0030f, 0.0034f, 0.0037f, 0.0042f, 0.0048f, +0.0054f, 0.0062f, 0.0072f, 0.0085f, 0.0100f, 0.0121f, 0.0148f, 0.0184f, +0.0233f, 0.0301f, 0.0396f, 0.0524f, 0.0681f, 0.0829f, 0.0894f +}; +static const float glorentz52[25] = { +0.0021f, 0.0023f, 0.0025f, 0.0027f, 0.0030f, 0.0033f, 0.0036f, 0.0040f, +0.0045f, 0.0051f, 0.0058f, 0.0067f, 0.0077f, 0.0090f, 0.0107f, 0.0128f, +0.0156f, 0.0192f, 0.0242f, 0.0308f, 0.0398f, 0.0515f, 0.0650f, 0.0772f, +0.0824f +}; +static const float glorentz53[27] = { +0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0027f, 0.0029f, 0.0032f, 0.0035f, +0.0039f, 0.0044f, 0.0049f, 0.0055f, 0.0062f, 0.0072f, 0.0083f, 0.0096f, +0.0113f, 0.0135f, 0.0164f, 0.0201f, 0.0249f, 0.0314f, 0.0398f, 0.0502f, +0.0619f, 0.0718f, 0.0759f +}; +static const float glorentz54[30] = { +0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0026f, 0.0029f, +0.0031f, 0.0034f, 0.0038f, 0.0042f, 0.0047f, 0.0052f, 0.0059f, 0.0067f, +0.0076f, 0.0088f, 0.0102f, 0.0120f, 0.0143f, 0.0171f, 0.0208f, 0.0256f, +0.0317f, 0.0395f, 0.0488f, 0.0586f, 0.0666f, 0.0698f +}; +static const float glorentz55[32] = { +0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0026f, +0.0028f, 0.0031f, 0.0034f, 0.0037f, 0.0041f, 0.0045f, 0.0050f, 0.0056f, +0.0063f, 0.0071f, 0.0081f, 0.0094f, 0.0108f, 0.0127f, 0.0149f, 0.0178f, +0.0214f, 0.0261f, 0.0318f, 0.0389f, 0.0470f, 0.0553f, 0.0618f, 0.0643f +}; +static const float glorentz56[35] = { +0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0020f, 0.0021f, 0.0023f, +0.0024f, 0.0026f, 0.0028f, 0.0031f, 0.0033f, 0.0036f, 0.0040f, 0.0044f, +0.0049f, 0.0054f, 0.0060f, 0.0067f, 0.0076f, 0.0087f, 0.0099f, 0.0114f, +0.0133f, 0.0156f, 0.0184f, 0.0220f, 0.0264f, 0.0318f, 0.0381f, 0.0451f, +0.0520f, 0.0572f, 0.0591f +}; +static const float glorentz57[38] = { +0.0013f, 0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, +0.0021f, 0.0023f, 0.0024f, 0.0026f, 0.0028f, 0.0031f, 0.0033f, 0.0036f, +0.0039f, 0.0043f, 0.0047f, 0.0052f, 0.0058f, 0.0064f, 0.0072f, 0.0081f, +0.0092f, 0.0104f, 0.0120f, 0.0139f, 0.0162f, 0.0190f, 0.0224f, 0.0265f, +0.0315f, 0.0371f, 0.0431f, 0.0487f, 0.0529f, 0.0544f +}; +static const float glorentz58[41] = { +0.0012f, 0.0013f, 0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, +0.0019f, 0.0020f, 0.0022f, 0.0023f, 0.0025f, 0.0026f, 0.0028f, 0.0030f, +0.0033f, 0.0036f, 0.0039f, 0.0042f, 0.0046f, 0.0050f, 0.0056f, 0.0061f, +0.0068f, 0.0076f, 0.0086f, 0.0097f, 0.0110f, 0.0125f, 0.0144f, 0.0167f, +0.0194f, 0.0226f, 0.0265f, 0.0309f, 0.0359f, 0.0409f, 0.0455f, 0.0488f, +0.0500f +}; +static const float glorentz59[45] = { +0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, 0.0015f, 0.0016f, +0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0023f, 0.0025f, +0.0026f, 0.0028f, 0.0030f, 0.0033f, 0.0035f, 0.0038f, 0.0041f, 0.0045f, +0.0049f, 0.0054f, 0.0059f, 0.0065f, 0.0072f, 0.0081f, 0.0090f, 0.0102f, +0.0115f, 0.0130f, 0.0149f, 0.0171f, 0.0197f, 0.0227f, 0.0263f, 0.0302f, +0.0345f, 0.0387f, 0.0425f, 0.0451f, 0.0460f +}; +static const float glorentz60[49] = { +0.0010f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, +0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, 0.0021f, +0.0022f, 0.0024f, 0.0025f, 0.0027f, 0.0028f, 0.0030f, 0.0033f, 0.0035f, +0.0038f, 0.0041f, 0.0044f, 0.0048f, 0.0052f, 0.0057f, 0.0063f, 0.0069f, +0.0077f, 0.0085f, 0.0095f, 0.0106f, 0.0119f, 0.0135f, 0.0153f, 0.0174f, +0.0199f, 0.0227f, 0.0259f, 0.0293f, 0.0330f, 0.0365f, 0.0395f, 0.0415f, +0.0423f +}; +static const float glorentz61[53] = { +0.0009f, 0.0010f, 0.0010f, 0.0011f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, +0.0013f, 0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0016f, 0.0017f, 0.0018f, +0.0019f, 0.0020f, 0.0021f, 0.0023f, 0.0024f, 0.0025f, 0.0027f, 0.0029f, +0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0041f, 0.0044f, 0.0047f, 0.0051f, +0.0056f, 0.0061f, 0.0067f, 0.0073f, 0.0081f, 0.0089f, 0.0099f, 0.0110f, +0.0124f, 0.0139f, 0.0156f, 0.0176f, 0.0199f, 0.0225f, 0.0253f, 0.0283f, +0.0314f, 0.0343f, 0.0367f, 0.0383f, 0.0389f +}; +static const float glorentz62[57] = { +0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, 0.0011f, 0.0011f, 0.0011f, +0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, 0.0015f, 0.0015f, 0.0016f, +0.0017f, 0.0018f, 0.0019f, 0.0020f, 0.0021f, 0.0022f, 0.0023f, 0.0024f, +0.0026f, 0.0027f, 0.0029f, 0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0040f, +0.0043f, 0.0047f, 0.0050f, 0.0055f, 0.0059f, 0.0064f, 0.0070f, 0.0077f, +0.0085f, 0.0093f, 0.0103f, 0.0114f, 0.0127f, 0.0142f, 0.0158f, 0.0177f, +0.0198f, 0.0221f, 0.0246f, 0.0272f, 0.0297f, 0.0321f, 0.0340f, 0.0353f, +0.0357f +}; +static const float glorentz63[62] = { +0.0008f, 0.0008f, 0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, 0.0010f, +0.0011f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, +0.0015f, 0.0015f, 0.0016f, 0.0017f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, +0.0021f, 0.0022f, 0.0023f, 0.0025f, 0.0026f, 0.0028f, 0.0029f, 0.0031f, +0.0033f, 0.0035f, 0.0038f, 0.0040f, 0.0043f, 0.0046f, 0.0050f, 0.0053f, +0.0058f, 0.0062f, 0.0068f, 0.0074f, 0.0081f, 0.0088f, 0.0097f, 0.0106f, +0.0117f, 0.0130f, 0.0144f, 0.0159f, 0.0176f, 0.0195f, 0.0216f, 0.0237f, +0.0259f, 0.0280f, 0.0299f, 0.0315f, 0.0325f, 0.0328f +}; +static const float glorentz64[65] = { +0.0008f, 0.0008f, 0.0008f, 0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, +0.0010f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, +0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, +0.0020f, 0.0021f, 0.0022f, 0.0023f, 0.0024f, 0.0025f, 0.0027f, 0.0028f, +0.0030f, 0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0040f, 0.0043f, 0.0046f, +0.0049f, 0.0052f, 0.0056f, 0.0061f, 0.0066f, 0.0071f, 0.0077f, 0.0084f, +0.0091f, 0.0100f, 0.0109f, 0.0120f, 0.0132f, 0.0145f, 0.0159f, 0.0175f, +0.0192f, 0.0209f, 0.0228f, 0.0246f, 0.0264f, 0.0279f, 0.0291f, 0.0299f, +0.0301f +}; +static const float *gptr_tab_lorentz[64] = { +glorentz1, glorentz2, glorentz3, glorentz4, +glorentz5, glorentz6, glorentz7, glorentz8, +glorentz9, glorentz10, glorentz11, glorentz12, +glorentz13, glorentz14, glorentz15, glorentz16, +glorentz17, glorentz18, glorentz19, glorentz20, +glorentz21, glorentz22, glorentz23, glorentz24, +glorentz25, glorentz26, glorentz27, glorentz28, +glorentz29, glorentz30, glorentz31, glorentz32, +glorentz33, glorentz34, glorentz35, glorentz36, +glorentz37, glorentz38, glorentz39, glorentz40, +glorentz41, glorentz42, glorentz43, glorentz44, +glorentz45, glorentz46, glorentz47, glorentz48, +glorentz49, glorentz50, glorentz51, glorentz52, +glorentz53, glorentz54, glorentz55, glorentz56, +glorentz57, glorentz58, glorentz59, glorentz60, +glorentz61, glorentz62, glorentz63, glorentz64 +}; diff --git a/lib/qra/q65/genq65.f90 b/lib/qra/q65/genq65.f90 index 2da3f414..4c555748 100755 --- a/lib/qra/q65/genq65.f90 +++ b/lib/qra/q65/genq65.f90 @@ -1,51 +1,51 @@ -subroutine genq65(msg0,ichk,msgsent,itone,i3,n3) - -! Encodes a Q65 message to yield itone(1:85) - - use packjt77 - character*37 msg0 !Message to be generated - character*37 msgsent !Message as it will be received - character*77 c77 - logical unpk77_success - integer itone(85) !QRA64 uses only 84 - integer dgen(13) - integer sent(63) - integer isync(22) - data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ - save - - if(msg0(1:1).eq.'@') then - read(msg0(2:5),*,end=1,err=1) nfreq - go to 2 -1 nfreq=1000 -2 itone(1)=nfreq - write(msgsent,1000) nfreq -1000 format(i5,' Hz') - goto 999 - endif - i3=-1 - n3=-1 - call pack77(msg0,i3,n3,c77) - read(c77(60:74),'(b15)') ng15 - if(ng15.eq.32373) c77(60:74)='111111010010011' !Message is RR73 - call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent - read(c77,1001) dgen -1001 format(12b6.6,b5.5) - dgen(13)=2*dgen(13) !Convert 77-bit to 78-bit payload - if(ichk.eq.1) go to 999 !Return if checking only - call q65_enc(dgen,sent) !Encode message, dgen(1:13) ==> sent(1:63) - - j=1 - k=0 - do i=1,85 - if(i.eq.isync(j)) then - j=j+1 !Index for next sync symbol - itone(i)=0 !Insert sync symbol at tone 0 - else - k=k+1 - itone(i)=sent(k) + 1 !Q65 symbol=0 is transmitted at tone 1, etc. - endif - enddo - -999 return -end subroutine genq65 +subroutine genq65(msg0,ichk,msgsent,itone,i3,n3) + +! Encodes a Q65 message to yield itone(1:85) + + use packjt77 + character*37 msg0 !Message to be generated + character*37 msgsent !Message as it will be received + character*77 c77 + logical unpk77_success + integer itone(85) !QRA64 uses only 84 + integer dgen(13) + integer sent(63) + integer isync(22) + data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ + save + + if(msg0(1:1).eq.'@') then + read(msg0(2:5),*,end=1,err=1) nfreq + go to 2 +1 nfreq=1000 +2 itone(1)=nfreq + write(msgsent,1000) nfreq +1000 format(i5,' Hz') + goto 999 + endif + i3=-1 + n3=-1 + call pack77(msg0,i3,n3,c77) + read(c77(60:74),'(b15)') ng15 + if(ng15.eq.32373) c77(60:74)='111111010010011' !Message is RR73 + call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent + read(c77,1001) dgen +1001 format(12b6.6,b5.5) + dgen(13)=2*dgen(13) !Convert 77-bit to 78-bit payload + if(ichk.eq.1) go to 999 !Return if checking only + call q65_enc(dgen,sent) !Encode message, dgen(1:13) ==> sent(1:63) + + j=1 + k=0 + do i=1,85 + if(i.eq.isync(j)) then + j=j+1 !Index for next sync symbol + itone(i)=0 !Insert sync symbol at tone 0 + else + k=k+1 + itone(i)=sent(k) + 1 !Q65 symbol=0 is transmitted at tone 1, etc. + endif + enddo + +999 return +end subroutine genq65 diff --git a/lib/qra/q65/normrnd.c b/lib/qra/q65/normrnd.c index d30765ec..90abfa42 100755 --- a/lib/qra/q65/normrnd.c +++ b/lib/qra/q65/normrnd.c @@ -1,82 +1,82 @@ -// normrnd.c -// functions to generate gaussian distributed numbers -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// -// Credits to Andrea Montefusco - IW0HDV for his help on adapting the sources -// to OSs other than MS Windows -// -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - - -#include "normrnd.h" - -#if _WIN32 // note the underscore: without it, it's not msdn official! - // Windows (x64 and x86) - #include // required only for GetTickCount(...) - #define K_RAND_MAX UINT_MAX -#elif _SVID_SOURCE || _XOPEN_SOURCE || __unix__ || (defined (__APPLE__) && defined(__MACH__)) /* POSIX or Unix or Apple */ - #include - #define rand_s(x) (*x)=(unsigned int)lrand48() // returns unsigned integers in the range 0..0x7FFFFFFF - #define K_RAND_MAX 0x7FFFFFFF // that's the max number - // generated by lrand48 -#else - #error "No good quality PRNG found" -#endif - - -// use MS rand_s(...) function -void normrnd_s(float *dst, int nitems, float mean, float stdev) -{ - unsigned int r; - float phi=0, u=0; - int set = 0; - - while (nitems--) - if (set==1) { - *dst++ = (float)sin(phi)*u*stdev+mean; - set = 0; - } - else { - rand_s((unsigned int*)&r); phi = (M_2PI/(1.0f+K_RAND_MAX))*r; - rand_s((unsigned int*)&r); u = (float)sqrt(-2.0f* log( (1.0f/(1.0f+K_RAND_MAX))*(1.0f+r) ) ); - *dst++ = (float)cos(phi)*u*stdev+mean; - set=1; - } -} - -/* NOT USED -// use MS rand() function -void normrnd(float *dst, int nitems, float mean, float stdev) -{ - float phi=0, u=0; - int set = 0; - - while (nitems--) - if (set==1) { - *dst++ = (float)sin(phi)*u*stdev+mean; - set = 0; - } - else { - phi = (M_2PI/(1.0f+RAND_MAX))*rand(); - u = (float)sqrt(-2.0f* log( (1.0f/(1.0f+RAND_MAX))*(1.0f+rand()) ) ); - *dst++ = (float)cos(phi)*u*stdev+mean; - set=1; - } -} -*/ +// normrnd.c +// functions to generate gaussian distributed numbers +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// +// Credits to Andrea Montefusco - IW0HDV for his help on adapting the sources +// to OSs other than MS Windows +// +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + + +#include "normrnd.h" + +#if _WIN32 // note the underscore: without it, it's not msdn official! + // Windows (x64 and x86) + #include // required only for GetTickCount(...) + #define K_RAND_MAX UINT_MAX +#elif _SVID_SOURCE || _XOPEN_SOURCE || __unix__ || (defined (__APPLE__) && defined(__MACH__)) /* POSIX or Unix or Apple */ + #include + #define rand_s(x) (*x)=(unsigned int)lrand48() // returns unsigned integers in the range 0..0x7FFFFFFF + #define K_RAND_MAX 0x7FFFFFFF // that's the max number + // generated by lrand48 +#else + #error "No good quality PRNG found" +#endif + + +// use MS rand_s(...) function +void normrnd_s(float *dst, int nitems, float mean, float stdev) +{ + unsigned int r; + float phi=0, u=0; + int set = 0; + + while (nitems--) + if (set==1) { + *dst++ = (float)sin(phi)*u*stdev+mean; + set = 0; + } + else { + rand_s((unsigned int*)&r); phi = (M_2PI/(1.0f+K_RAND_MAX))*r; + rand_s((unsigned int*)&r); u = (float)sqrt(-2.0f* log( (1.0f/(1.0f+K_RAND_MAX))*(1.0f+r) ) ); + *dst++ = (float)cos(phi)*u*stdev+mean; + set=1; + } +} + +/* NOT USED +// use MS rand() function +void normrnd(float *dst, int nitems, float mean, float stdev) +{ + float phi=0, u=0; + int set = 0; + + while (nitems--) + if (set==1) { + *dst++ = (float)sin(phi)*u*stdev+mean; + set = 0; + } + else { + phi = (M_2PI/(1.0f+RAND_MAX))*rand(); + u = (float)sqrt(-2.0f* log( (1.0f/(1.0f+RAND_MAX))*(1.0f+rand()) ) ); + *dst++ = (float)cos(phi)*u*stdev+mean; + set=1; + } +} +*/ diff --git a/lib/qra/q65/normrnd.h b/lib/qra/q65/normrnd.h index 04bbf01a..dd4b65bb 100755 --- a/lib/qra/q65/normrnd.h +++ b/lib/qra/q65/normrnd.h @@ -1,51 +1,51 @@ -// normrnd.h -// Functions to generate gaussian distributed numbers -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#ifndef _normrnd_h_ -#define _normrnd_h_ - -#define _CRT_RAND_S -#include - -#define _USE_MATH_DEFINES -#include -#define M_2PI (2.0f*(float)M_PI) - -#ifdef __cplusplus -extern "C" { -#endif - -void normrnd_s(float *dst, int nitems, float mean, float stdev); -// generate a random array of numbers with a gaussian distribution of given mean and stdev -// use MS rand_s(...) function - -/* not used -void normrnd(float *dst, int nitems, float mean, float stdev); -// generate a random array of numbers with a gaussian distribution of given mean and stdev -// use MS rand() function -*/ - -#ifdef __cplusplus -} -#endif - -#endif // _normrnd_h_ - +// normrnd.h +// Functions to generate gaussian distributed numbers +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#ifndef _normrnd_h_ +#define _normrnd_h_ + +#define _CRT_RAND_S +#include + +#define _USE_MATH_DEFINES +#include +#define M_2PI (2.0f*(float)M_PI) + +#ifdef __cplusplus +extern "C" { +#endif + +void normrnd_s(float *dst, int nitems, float mean, float stdev); +// generate a random array of numbers with a gaussian distribution of given mean and stdev +// use MS rand_s(...) function + +/* not used +void normrnd(float *dst, int nitems, float mean, float stdev); +// generate a random array of numbers with a gaussian distribution of given mean and stdev +// use MS rand() function +*/ + +#ifdef __cplusplus +} +#endif + +#endif // _normrnd_h_ + diff --git a/lib/qra/q65/npfwht.c b/lib/qra/q65/npfwht.c index 0f8fa428..5732ce91 100755 --- a/lib/qra/q65/npfwht.c +++ b/lib/qra/q65/npfwht.c @@ -1,216 +1,216 @@ -// npfwht.c -// Basic implementation of the Fast Walsh-Hadamard Transforms -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#include "npfwht.h" - -#define WHBFY(dst,src,base,offs,dist) { dst[base+offs]=src[base+offs]+src[base+offs+dist]; dst[base+offs+dist]=src[base+offs]-src[base+offs+dist]; } - -typedef void (*pnp_fwht)(float*,float*); - -static void np_fwht2(float *dst, float *src); - -static void np_fwht1(float *dst, float *src); -static void np_fwht2(float *dst, float *src); -static void np_fwht4(float *dst, float *src); -static void np_fwht8(float *dst, float *src); -static void np_fwht16(float *dst, float *src); -static void np_fwht32(float *dst, float *src); -static void np_fwht64(float *dst, float *src); - -static pnp_fwht np_fwht_tab[7] = { - np_fwht1, - np_fwht2, - np_fwht4, - np_fwht8, - np_fwht16, - np_fwht32, - np_fwht64 -}; - -void np_fwht(int nlogdim, float *dst, float *src) -{ - np_fwht_tab[nlogdim](dst,src); -} - -static void np_fwht1(float *dst, float *src) -{ - dst[0] = src[0]; -} - - -static void np_fwht2(float *dst, float *src) -{ - float t[2]; - - WHBFY(t,src,0,0,1); - dst[0]= t[0]; - dst[1]= t[1]; -} - -static void np_fwht4(float *dst, float *src) -{ - float t[4]; - - // group 1 - WHBFY(t,src,0,0,2); WHBFY(t,src,0,1,2); - // group 2 - WHBFY(dst,t,0,0,1); WHBFY(dst,t,2,0,1); -}; - - -static void np_fwht8(float *dst, float *src) -{ - float t[16]; - float *t1=t, *t2=t+8; - - // group 1 - WHBFY(t1,src,0,0,4); WHBFY(t1,src,0,1,4); WHBFY(t1,src,0,2,4); WHBFY(t1,src,0,3,4); - // group 2 - WHBFY(t2,t1,0,0,2); WHBFY(t2,t1,0,1,2); WHBFY(t2,t1,4,0,2); WHBFY(t2,t1,4,1,2); - // group 3 - WHBFY(dst,t2,0,0,1); WHBFY(dst,t2,2,0,1); WHBFY(dst,t2,4,0,1); WHBFY(dst,t2,6,0,1); -}; - - -static void np_fwht16(float *dst, float *src) -{ - float t[32]; - float *t1=t, *t2=t+16; - - // group 1 - WHBFY(t1,src,0,0,8); WHBFY(t1,src,0,1,8); WHBFY(t1,src,0,2,8); WHBFY(t1,src,0,3,8); - WHBFY(t1,src,0,4,8); WHBFY(t1,src,0,5,8); WHBFY(t1,src,0,6,8); WHBFY(t1,src,0,7,8); - // group 2 - WHBFY(t2,t1,0,0,4); WHBFY(t2,t1,0,1,4); WHBFY(t2,t1,0,2,4); WHBFY(t2,t1,0,3,4); - WHBFY(t2,t1,8,0,4); WHBFY(t2,t1,8,1,4); WHBFY(t2,t1,8,2,4); WHBFY(t2,t1,8,3,4); - // group 3 - WHBFY(t1,t2,0,0,2); WHBFY(t1,t2,0,1,2); WHBFY(t1,t2,4,0,2); WHBFY(t1,t2,4,1,2); - WHBFY(t1,t2,8,0,2); WHBFY(t1,t2,8,1,2); WHBFY(t1,t2,12,0,2); WHBFY(t1,t2,12,1,2); - // group 4 - WHBFY(dst,t1,0,0,1); WHBFY(dst,t1,2,0,1); WHBFY(dst,t1,4,0,1); WHBFY(dst,t1,6,0,1); - WHBFY(dst,t1,8,0,1); WHBFY(dst,t1,10,0,1); WHBFY(dst,t1,12,0,1); WHBFY(dst,t1,14,0,1); - -} - -static void np_fwht32(float *dst, float *src) -{ - float t[64]; - float *t1=t, *t2=t+32; - - // group 1 - WHBFY(t1,src,0,0,16); WHBFY(t1,src,0,1,16); WHBFY(t1,src,0,2,16); WHBFY(t1,src,0,3,16); - WHBFY(t1,src,0,4,16); WHBFY(t1,src,0,5,16); WHBFY(t1,src,0,6,16); WHBFY(t1,src,0,7,16); - WHBFY(t1,src,0,8,16); WHBFY(t1,src,0,9,16); WHBFY(t1,src,0,10,16); WHBFY(t1,src,0,11,16); - WHBFY(t1,src,0,12,16); WHBFY(t1,src,0,13,16); WHBFY(t1,src,0,14,16); WHBFY(t1,src,0,15,16); - - // group 2 - WHBFY(t2,t1,0,0,8); WHBFY(t2,t1,0,1,8); WHBFY(t2,t1,0,2,8); WHBFY(t2,t1,0,3,8); - WHBFY(t2,t1,0,4,8); WHBFY(t2,t1,0,5,8); WHBFY(t2,t1,0,6,8); WHBFY(t2,t1,0,7,8); - WHBFY(t2,t1,16,0,8); WHBFY(t2,t1,16,1,8); WHBFY(t2,t1,16,2,8); WHBFY(t2,t1,16,3,8); - WHBFY(t2,t1,16,4,8); WHBFY(t2,t1,16,5,8); WHBFY(t2,t1,16,6,8); WHBFY(t2,t1,16,7,8); - - // group 3 - WHBFY(t1,t2,0,0,4); WHBFY(t1,t2,0,1,4); WHBFY(t1,t2,0,2,4); WHBFY(t1,t2,0,3,4); - WHBFY(t1,t2,8,0,4); WHBFY(t1,t2,8,1,4); WHBFY(t1,t2,8,2,4); WHBFY(t1,t2,8,3,4); - WHBFY(t1,t2,16,0,4); WHBFY(t1,t2,16,1,4); WHBFY(t1,t2,16,2,4); WHBFY(t1,t2,16,3,4); - WHBFY(t1,t2,24,0,4); WHBFY(t1,t2,24,1,4); WHBFY(t1,t2,24,2,4); WHBFY(t1,t2,24,3,4); - - // group 4 - WHBFY(t2,t1,0,0,2); WHBFY(t2,t1,0,1,2); WHBFY(t2,t1,4,0,2); WHBFY(t2,t1,4,1,2); - WHBFY(t2,t1,8,0,2); WHBFY(t2,t1,8,1,2); WHBFY(t2,t1,12,0,2); WHBFY(t2,t1,12,1,2); - WHBFY(t2,t1,16,0,2); WHBFY(t2,t1,16,1,2); WHBFY(t2,t1,20,0,2); WHBFY(t2,t1,20,1,2); - WHBFY(t2,t1,24,0,2); WHBFY(t2,t1,24,1,2); WHBFY(t2,t1,28,0,2); WHBFY(t2,t1,28,1,2); - - // group 5 - WHBFY(dst,t2,0,0,1); WHBFY(dst,t2,2,0,1); WHBFY(dst,t2,4,0,1); WHBFY(dst,t2,6,0,1); - WHBFY(dst,t2,8,0,1); WHBFY(dst,t2,10,0,1); WHBFY(dst,t2,12,0,1); WHBFY(dst,t2,14,0,1); - WHBFY(dst,t2,16,0,1); WHBFY(dst,t2,18,0,1); WHBFY(dst,t2,20,0,1); WHBFY(dst,t2,22,0,1); - WHBFY(dst,t2,24,0,1); WHBFY(dst,t2,26,0,1); WHBFY(dst,t2,28,0,1); WHBFY(dst,t2,30,0,1); - -} - -static void np_fwht64(float *dst, float *src) -{ - float t[128]; - float *t1=t, *t2=t+64; - - - // group 1 - WHBFY(t1,src,0,0,32); WHBFY(t1,src,0,1,32); WHBFY(t1,src,0,2,32); WHBFY(t1,src,0,3,32); - WHBFY(t1,src,0,4,32); WHBFY(t1,src,0,5,32); WHBFY(t1,src,0,6,32); WHBFY(t1,src,0,7,32); - WHBFY(t1,src,0,8,32); WHBFY(t1,src,0,9,32); WHBFY(t1,src,0,10,32); WHBFY(t1,src,0,11,32); - WHBFY(t1,src,0,12,32); WHBFY(t1,src,0,13,32); WHBFY(t1,src,0,14,32); WHBFY(t1,src,0,15,32); - WHBFY(t1,src,0,16,32); WHBFY(t1,src,0,17,32); WHBFY(t1,src,0,18,32); WHBFY(t1,src,0,19,32); - WHBFY(t1,src,0,20,32); WHBFY(t1,src,0,21,32); WHBFY(t1,src,0,22,32); WHBFY(t1,src,0,23,32); - WHBFY(t1,src,0,24,32); WHBFY(t1,src,0,25,32); WHBFY(t1,src,0,26,32); WHBFY(t1,src,0,27,32); - WHBFY(t1,src,0,28,32); WHBFY(t1,src,0,29,32); WHBFY(t1,src,0,30,32); WHBFY(t1,src,0,31,32); - - // group 2 - WHBFY(t2,t1,0,0,16); WHBFY(t2,t1,0,1,16); WHBFY(t2,t1,0,2,16); WHBFY(t2,t1,0,3,16); - WHBFY(t2,t1,0,4,16); WHBFY(t2,t1,0,5,16); WHBFY(t2,t1,0,6,16); WHBFY(t2,t1,0,7,16); - WHBFY(t2,t1,0,8,16); WHBFY(t2,t1,0,9,16); WHBFY(t2,t1,0,10,16); WHBFY(t2,t1,0,11,16); - WHBFY(t2,t1,0,12,16); WHBFY(t2,t1,0,13,16); WHBFY(t2,t1,0,14,16); WHBFY(t2,t1,0,15,16); - - WHBFY(t2,t1,32,0,16); WHBFY(t2,t1,32,1,16); WHBFY(t2,t1,32,2,16); WHBFY(t2,t1,32,3,16); - WHBFY(t2,t1,32,4,16); WHBFY(t2,t1,32,5,16); WHBFY(t2,t1,32,6,16); WHBFY(t2,t1,32,7,16); - WHBFY(t2,t1,32,8,16); WHBFY(t2,t1,32,9,16); WHBFY(t2,t1,32,10,16); WHBFY(t2,t1,32,11,16); - WHBFY(t2,t1,32,12,16); WHBFY(t2,t1,32,13,16); WHBFY(t2,t1,32,14,16); WHBFY(t2,t1,32,15,16); - - // group 3 - WHBFY(t1,t2,0,0,8); WHBFY(t1,t2,0,1,8); WHBFY(t1,t2,0,2,8); WHBFY(t1,t2,0,3,8); - WHBFY(t1,t2,0,4,8); WHBFY(t1,t2,0,5,8); WHBFY(t1,t2,0,6,8); WHBFY(t1,t2,0,7,8); - WHBFY(t1,t2,16,0,8); WHBFY(t1,t2,16,1,8); WHBFY(t1,t2,16,2,8); WHBFY(t1,t2,16,3,8); - WHBFY(t1,t2,16,4,8); WHBFY(t1,t2,16,5,8); WHBFY(t1,t2,16,6,8); WHBFY(t1,t2,16,7,8); - WHBFY(t1,t2,32,0,8); WHBFY(t1,t2,32,1,8); WHBFY(t1,t2,32,2,8); WHBFY(t1,t2,32,3,8); - WHBFY(t1,t2,32,4,8); WHBFY(t1,t2,32,5,8); WHBFY(t1,t2,32,6,8); WHBFY(t1,t2,32,7,8); - WHBFY(t1,t2,48,0,8); WHBFY(t1,t2,48,1,8); WHBFY(t1,t2,48,2,8); WHBFY(t1,t2,48,3,8); - WHBFY(t1,t2,48,4,8); WHBFY(t1,t2,48,5,8); WHBFY(t1,t2,48,6,8); WHBFY(t1,t2,48,7,8); - - // group 4 - WHBFY(t2,t1,0,0,4); WHBFY(t2,t1,0,1,4); WHBFY(t2,t1,0,2,4); WHBFY(t2,t1,0,3,4); - WHBFY(t2,t1,8,0,4); WHBFY(t2,t1,8,1,4); WHBFY(t2,t1,8,2,4); WHBFY(t2,t1,8,3,4); - WHBFY(t2,t1,16,0,4); WHBFY(t2,t1,16,1,4); WHBFY(t2,t1,16,2,4); WHBFY(t2,t1,16,3,4); - WHBFY(t2,t1,24,0,4); WHBFY(t2,t1,24,1,4); WHBFY(t2,t1,24,2,4); WHBFY(t2,t1,24,3,4); - WHBFY(t2,t1,32,0,4); WHBFY(t2,t1,32,1,4); WHBFY(t2,t1,32,2,4); WHBFY(t2,t1,32,3,4); - WHBFY(t2,t1,40,0,4); WHBFY(t2,t1,40,1,4); WHBFY(t2,t1,40,2,4); WHBFY(t2,t1,40,3,4); - WHBFY(t2,t1,48,0,4); WHBFY(t2,t1,48,1,4); WHBFY(t2,t1,48,2,4); WHBFY(t2,t1,48,3,4); - WHBFY(t2,t1,56,0,4); WHBFY(t2,t1,56,1,4); WHBFY(t2,t1,56,2,4); WHBFY(t2,t1,56,3,4); - - // group 5 - WHBFY(t1,t2,0,0,2); WHBFY(t1,t2,0,1,2); WHBFY(t1,t2,4,0,2); WHBFY(t1,t2,4,1,2); - WHBFY(t1,t2,8,0,2); WHBFY(t1,t2,8,1,2); WHBFY(t1,t2,12,0,2); WHBFY(t1,t2,12,1,2); - WHBFY(t1,t2,16,0,2); WHBFY(t1,t2,16,1,2); WHBFY(t1,t2,20,0,2); WHBFY(t1,t2,20,1,2); - WHBFY(t1,t2,24,0,2); WHBFY(t1,t2,24,1,2); WHBFY(t1,t2,28,0,2); WHBFY(t1,t2,28,1,2); - WHBFY(t1,t2,32,0,2); WHBFY(t1,t2,32,1,2); WHBFY(t1,t2,36,0,2); WHBFY(t1,t2,36,1,2); - WHBFY(t1,t2,40,0,2); WHBFY(t1,t2,40,1,2); WHBFY(t1,t2,44,0,2); WHBFY(t1,t2,44,1,2); - WHBFY(t1,t2,48,0,2); WHBFY(t1,t2,48,1,2); WHBFY(t1,t2,52,0,2); WHBFY(t1,t2,52,1,2); - WHBFY(t1,t2,56,0,2); WHBFY(t1,t2,56,1,2); WHBFY(t1,t2,60,0,2); WHBFY(t1,t2,60,1,2); - - // group 6 - WHBFY(dst,t1,0,0,1); WHBFY(dst,t1,2,0,1); WHBFY(dst,t1,4,0,1); WHBFY(dst,t1,6,0,1); - WHBFY(dst,t1,8,0,1); WHBFY(dst,t1,10,0,1); WHBFY(dst,t1,12,0,1); WHBFY(dst,t1,14,0,1); - WHBFY(dst,t1,16,0,1); WHBFY(dst,t1,18,0,1); WHBFY(dst,t1,20,0,1); WHBFY(dst,t1,22,0,1); - WHBFY(dst,t1,24,0,1); WHBFY(dst,t1,26,0,1); WHBFY(dst,t1,28,0,1); WHBFY(dst,t1,30,0,1); - WHBFY(dst,t1,32,0,1); WHBFY(dst,t1,34,0,1); WHBFY(dst,t1,36,0,1); WHBFY(dst,t1,38,0,1); - WHBFY(dst,t1,40,0,1); WHBFY(dst,t1,42,0,1); WHBFY(dst,t1,44,0,1); WHBFY(dst,t1,46,0,1); - WHBFY(dst,t1,48,0,1); WHBFY(dst,t1,50,0,1); WHBFY(dst,t1,52,0,1); WHBFY(dst,t1,54,0,1); - WHBFY(dst,t1,56,0,1); WHBFY(dst,t1,58,0,1); WHBFY(dst,t1,60,0,1); WHBFY(dst,t1,62,0,1); +// npfwht.c +// Basic implementation of the Fast Walsh-Hadamard Transforms +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#include "npfwht.h" + +#define WHBFY(dst,src,base,offs,dist) { dst[base+offs]=src[base+offs]+src[base+offs+dist]; dst[base+offs+dist]=src[base+offs]-src[base+offs+dist]; } + +typedef void (*pnp_fwht)(float*,float*); + +static void np_fwht2(float *dst, float *src); + +static void np_fwht1(float *dst, float *src); +static void np_fwht2(float *dst, float *src); +static void np_fwht4(float *dst, float *src); +static void np_fwht8(float *dst, float *src); +static void np_fwht16(float *dst, float *src); +static void np_fwht32(float *dst, float *src); +static void np_fwht64(float *dst, float *src); + +static pnp_fwht np_fwht_tab[7] = { + np_fwht1, + np_fwht2, + np_fwht4, + np_fwht8, + np_fwht16, + np_fwht32, + np_fwht64 +}; + +void np_fwht(int nlogdim, float *dst, float *src) +{ + np_fwht_tab[nlogdim](dst,src); +} + +static void np_fwht1(float *dst, float *src) +{ + dst[0] = src[0]; +} + + +static void np_fwht2(float *dst, float *src) +{ + float t[2]; + + WHBFY(t,src,0,0,1); + dst[0]= t[0]; + dst[1]= t[1]; +} + +static void np_fwht4(float *dst, float *src) +{ + float t[4]; + + // group 1 + WHBFY(t,src,0,0,2); WHBFY(t,src,0,1,2); + // group 2 + WHBFY(dst,t,0,0,1); WHBFY(dst,t,2,0,1); +}; + + +static void np_fwht8(float *dst, float *src) +{ + float t[16]; + float *t1=t, *t2=t+8; + + // group 1 + WHBFY(t1,src,0,0,4); WHBFY(t1,src,0,1,4); WHBFY(t1,src,0,2,4); WHBFY(t1,src,0,3,4); + // group 2 + WHBFY(t2,t1,0,0,2); WHBFY(t2,t1,0,1,2); WHBFY(t2,t1,4,0,2); WHBFY(t2,t1,4,1,2); + // group 3 + WHBFY(dst,t2,0,0,1); WHBFY(dst,t2,2,0,1); WHBFY(dst,t2,4,0,1); WHBFY(dst,t2,6,0,1); +}; + + +static void np_fwht16(float *dst, float *src) +{ + float t[32]; + float *t1=t, *t2=t+16; + + // group 1 + WHBFY(t1,src,0,0,8); WHBFY(t1,src,0,1,8); WHBFY(t1,src,0,2,8); WHBFY(t1,src,0,3,8); + WHBFY(t1,src,0,4,8); WHBFY(t1,src,0,5,8); WHBFY(t1,src,0,6,8); WHBFY(t1,src,0,7,8); + // group 2 + WHBFY(t2,t1,0,0,4); WHBFY(t2,t1,0,1,4); WHBFY(t2,t1,0,2,4); WHBFY(t2,t1,0,3,4); + WHBFY(t2,t1,8,0,4); WHBFY(t2,t1,8,1,4); WHBFY(t2,t1,8,2,4); WHBFY(t2,t1,8,3,4); + // group 3 + WHBFY(t1,t2,0,0,2); WHBFY(t1,t2,0,1,2); WHBFY(t1,t2,4,0,2); WHBFY(t1,t2,4,1,2); + WHBFY(t1,t2,8,0,2); WHBFY(t1,t2,8,1,2); WHBFY(t1,t2,12,0,2); WHBFY(t1,t2,12,1,2); + // group 4 + WHBFY(dst,t1,0,0,1); WHBFY(dst,t1,2,0,1); WHBFY(dst,t1,4,0,1); WHBFY(dst,t1,6,0,1); + WHBFY(dst,t1,8,0,1); WHBFY(dst,t1,10,0,1); WHBFY(dst,t1,12,0,1); WHBFY(dst,t1,14,0,1); + +} + +static void np_fwht32(float *dst, float *src) +{ + float t[64]; + float *t1=t, *t2=t+32; + + // group 1 + WHBFY(t1,src,0,0,16); WHBFY(t1,src,0,1,16); WHBFY(t1,src,0,2,16); WHBFY(t1,src,0,3,16); + WHBFY(t1,src,0,4,16); WHBFY(t1,src,0,5,16); WHBFY(t1,src,0,6,16); WHBFY(t1,src,0,7,16); + WHBFY(t1,src,0,8,16); WHBFY(t1,src,0,9,16); WHBFY(t1,src,0,10,16); WHBFY(t1,src,0,11,16); + WHBFY(t1,src,0,12,16); WHBFY(t1,src,0,13,16); WHBFY(t1,src,0,14,16); WHBFY(t1,src,0,15,16); + + // group 2 + WHBFY(t2,t1,0,0,8); WHBFY(t2,t1,0,1,8); WHBFY(t2,t1,0,2,8); WHBFY(t2,t1,0,3,8); + WHBFY(t2,t1,0,4,8); WHBFY(t2,t1,0,5,8); WHBFY(t2,t1,0,6,8); WHBFY(t2,t1,0,7,8); + WHBFY(t2,t1,16,0,8); WHBFY(t2,t1,16,1,8); WHBFY(t2,t1,16,2,8); WHBFY(t2,t1,16,3,8); + WHBFY(t2,t1,16,4,8); WHBFY(t2,t1,16,5,8); WHBFY(t2,t1,16,6,8); WHBFY(t2,t1,16,7,8); + + // group 3 + WHBFY(t1,t2,0,0,4); WHBFY(t1,t2,0,1,4); WHBFY(t1,t2,0,2,4); WHBFY(t1,t2,0,3,4); + WHBFY(t1,t2,8,0,4); WHBFY(t1,t2,8,1,4); WHBFY(t1,t2,8,2,4); WHBFY(t1,t2,8,3,4); + WHBFY(t1,t2,16,0,4); WHBFY(t1,t2,16,1,4); WHBFY(t1,t2,16,2,4); WHBFY(t1,t2,16,3,4); + WHBFY(t1,t2,24,0,4); WHBFY(t1,t2,24,1,4); WHBFY(t1,t2,24,2,4); WHBFY(t1,t2,24,3,4); + + // group 4 + WHBFY(t2,t1,0,0,2); WHBFY(t2,t1,0,1,2); WHBFY(t2,t1,4,0,2); WHBFY(t2,t1,4,1,2); + WHBFY(t2,t1,8,0,2); WHBFY(t2,t1,8,1,2); WHBFY(t2,t1,12,0,2); WHBFY(t2,t1,12,1,2); + WHBFY(t2,t1,16,0,2); WHBFY(t2,t1,16,1,2); WHBFY(t2,t1,20,0,2); WHBFY(t2,t1,20,1,2); + WHBFY(t2,t1,24,0,2); WHBFY(t2,t1,24,1,2); WHBFY(t2,t1,28,0,2); WHBFY(t2,t1,28,1,2); + + // group 5 + WHBFY(dst,t2,0,0,1); WHBFY(dst,t2,2,0,1); WHBFY(dst,t2,4,0,1); WHBFY(dst,t2,6,0,1); + WHBFY(dst,t2,8,0,1); WHBFY(dst,t2,10,0,1); WHBFY(dst,t2,12,0,1); WHBFY(dst,t2,14,0,1); + WHBFY(dst,t2,16,0,1); WHBFY(dst,t2,18,0,1); WHBFY(dst,t2,20,0,1); WHBFY(dst,t2,22,0,1); + WHBFY(dst,t2,24,0,1); WHBFY(dst,t2,26,0,1); WHBFY(dst,t2,28,0,1); WHBFY(dst,t2,30,0,1); + +} + +static void np_fwht64(float *dst, float *src) +{ + float t[128]; + float *t1=t, *t2=t+64; + + + // group 1 + WHBFY(t1,src,0,0,32); WHBFY(t1,src,0,1,32); WHBFY(t1,src,0,2,32); WHBFY(t1,src,0,3,32); + WHBFY(t1,src,0,4,32); WHBFY(t1,src,0,5,32); WHBFY(t1,src,0,6,32); WHBFY(t1,src,0,7,32); + WHBFY(t1,src,0,8,32); WHBFY(t1,src,0,9,32); WHBFY(t1,src,0,10,32); WHBFY(t1,src,0,11,32); + WHBFY(t1,src,0,12,32); WHBFY(t1,src,0,13,32); WHBFY(t1,src,0,14,32); WHBFY(t1,src,0,15,32); + WHBFY(t1,src,0,16,32); WHBFY(t1,src,0,17,32); WHBFY(t1,src,0,18,32); WHBFY(t1,src,0,19,32); + WHBFY(t1,src,0,20,32); WHBFY(t1,src,0,21,32); WHBFY(t1,src,0,22,32); WHBFY(t1,src,0,23,32); + WHBFY(t1,src,0,24,32); WHBFY(t1,src,0,25,32); WHBFY(t1,src,0,26,32); WHBFY(t1,src,0,27,32); + WHBFY(t1,src,0,28,32); WHBFY(t1,src,0,29,32); WHBFY(t1,src,0,30,32); WHBFY(t1,src,0,31,32); + + // group 2 + WHBFY(t2,t1,0,0,16); WHBFY(t2,t1,0,1,16); WHBFY(t2,t1,0,2,16); WHBFY(t2,t1,0,3,16); + WHBFY(t2,t1,0,4,16); WHBFY(t2,t1,0,5,16); WHBFY(t2,t1,0,6,16); WHBFY(t2,t1,0,7,16); + WHBFY(t2,t1,0,8,16); WHBFY(t2,t1,0,9,16); WHBFY(t2,t1,0,10,16); WHBFY(t2,t1,0,11,16); + WHBFY(t2,t1,0,12,16); WHBFY(t2,t1,0,13,16); WHBFY(t2,t1,0,14,16); WHBFY(t2,t1,0,15,16); + + WHBFY(t2,t1,32,0,16); WHBFY(t2,t1,32,1,16); WHBFY(t2,t1,32,2,16); WHBFY(t2,t1,32,3,16); + WHBFY(t2,t1,32,4,16); WHBFY(t2,t1,32,5,16); WHBFY(t2,t1,32,6,16); WHBFY(t2,t1,32,7,16); + WHBFY(t2,t1,32,8,16); WHBFY(t2,t1,32,9,16); WHBFY(t2,t1,32,10,16); WHBFY(t2,t1,32,11,16); + WHBFY(t2,t1,32,12,16); WHBFY(t2,t1,32,13,16); WHBFY(t2,t1,32,14,16); WHBFY(t2,t1,32,15,16); + + // group 3 + WHBFY(t1,t2,0,0,8); WHBFY(t1,t2,0,1,8); WHBFY(t1,t2,0,2,8); WHBFY(t1,t2,0,3,8); + WHBFY(t1,t2,0,4,8); WHBFY(t1,t2,0,5,8); WHBFY(t1,t2,0,6,8); WHBFY(t1,t2,0,7,8); + WHBFY(t1,t2,16,0,8); WHBFY(t1,t2,16,1,8); WHBFY(t1,t2,16,2,8); WHBFY(t1,t2,16,3,8); + WHBFY(t1,t2,16,4,8); WHBFY(t1,t2,16,5,8); WHBFY(t1,t2,16,6,8); WHBFY(t1,t2,16,7,8); + WHBFY(t1,t2,32,0,8); WHBFY(t1,t2,32,1,8); WHBFY(t1,t2,32,2,8); WHBFY(t1,t2,32,3,8); + WHBFY(t1,t2,32,4,8); WHBFY(t1,t2,32,5,8); WHBFY(t1,t2,32,6,8); WHBFY(t1,t2,32,7,8); + WHBFY(t1,t2,48,0,8); WHBFY(t1,t2,48,1,8); WHBFY(t1,t2,48,2,8); WHBFY(t1,t2,48,3,8); + WHBFY(t1,t2,48,4,8); WHBFY(t1,t2,48,5,8); WHBFY(t1,t2,48,6,8); WHBFY(t1,t2,48,7,8); + + // group 4 + WHBFY(t2,t1,0,0,4); WHBFY(t2,t1,0,1,4); WHBFY(t2,t1,0,2,4); WHBFY(t2,t1,0,3,4); + WHBFY(t2,t1,8,0,4); WHBFY(t2,t1,8,1,4); WHBFY(t2,t1,8,2,4); WHBFY(t2,t1,8,3,4); + WHBFY(t2,t1,16,0,4); WHBFY(t2,t1,16,1,4); WHBFY(t2,t1,16,2,4); WHBFY(t2,t1,16,3,4); + WHBFY(t2,t1,24,0,4); WHBFY(t2,t1,24,1,4); WHBFY(t2,t1,24,2,4); WHBFY(t2,t1,24,3,4); + WHBFY(t2,t1,32,0,4); WHBFY(t2,t1,32,1,4); WHBFY(t2,t1,32,2,4); WHBFY(t2,t1,32,3,4); + WHBFY(t2,t1,40,0,4); WHBFY(t2,t1,40,1,4); WHBFY(t2,t1,40,2,4); WHBFY(t2,t1,40,3,4); + WHBFY(t2,t1,48,0,4); WHBFY(t2,t1,48,1,4); WHBFY(t2,t1,48,2,4); WHBFY(t2,t1,48,3,4); + WHBFY(t2,t1,56,0,4); WHBFY(t2,t1,56,1,4); WHBFY(t2,t1,56,2,4); WHBFY(t2,t1,56,3,4); + + // group 5 + WHBFY(t1,t2,0,0,2); WHBFY(t1,t2,0,1,2); WHBFY(t1,t2,4,0,2); WHBFY(t1,t2,4,1,2); + WHBFY(t1,t2,8,0,2); WHBFY(t1,t2,8,1,2); WHBFY(t1,t2,12,0,2); WHBFY(t1,t2,12,1,2); + WHBFY(t1,t2,16,0,2); WHBFY(t1,t2,16,1,2); WHBFY(t1,t2,20,0,2); WHBFY(t1,t2,20,1,2); + WHBFY(t1,t2,24,0,2); WHBFY(t1,t2,24,1,2); WHBFY(t1,t2,28,0,2); WHBFY(t1,t2,28,1,2); + WHBFY(t1,t2,32,0,2); WHBFY(t1,t2,32,1,2); WHBFY(t1,t2,36,0,2); WHBFY(t1,t2,36,1,2); + WHBFY(t1,t2,40,0,2); WHBFY(t1,t2,40,1,2); WHBFY(t1,t2,44,0,2); WHBFY(t1,t2,44,1,2); + WHBFY(t1,t2,48,0,2); WHBFY(t1,t2,48,1,2); WHBFY(t1,t2,52,0,2); WHBFY(t1,t2,52,1,2); + WHBFY(t1,t2,56,0,2); WHBFY(t1,t2,56,1,2); WHBFY(t1,t2,60,0,2); WHBFY(t1,t2,60,1,2); + + // group 6 + WHBFY(dst,t1,0,0,1); WHBFY(dst,t1,2,0,1); WHBFY(dst,t1,4,0,1); WHBFY(dst,t1,6,0,1); + WHBFY(dst,t1,8,0,1); WHBFY(dst,t1,10,0,1); WHBFY(dst,t1,12,0,1); WHBFY(dst,t1,14,0,1); + WHBFY(dst,t1,16,0,1); WHBFY(dst,t1,18,0,1); WHBFY(dst,t1,20,0,1); WHBFY(dst,t1,22,0,1); + WHBFY(dst,t1,24,0,1); WHBFY(dst,t1,26,0,1); WHBFY(dst,t1,28,0,1); WHBFY(dst,t1,30,0,1); + WHBFY(dst,t1,32,0,1); WHBFY(dst,t1,34,0,1); WHBFY(dst,t1,36,0,1); WHBFY(dst,t1,38,0,1); + WHBFY(dst,t1,40,0,1); WHBFY(dst,t1,42,0,1); WHBFY(dst,t1,44,0,1); WHBFY(dst,t1,46,0,1); + WHBFY(dst,t1,48,0,1); WHBFY(dst,t1,50,0,1); WHBFY(dst,t1,52,0,1); WHBFY(dst,t1,54,0,1); + WHBFY(dst,t1,56,0,1); WHBFY(dst,t1,58,0,1); WHBFY(dst,t1,60,0,1); WHBFY(dst,t1,62,0,1); } \ No newline at end of file diff --git a/lib/qra/q65/npfwht.h b/lib/qra/q65/npfwht.h index 212b0af2..9452e207 100755 --- a/lib/qra/q65/npfwht.h +++ b/lib/qra/q65/npfwht.h @@ -1,45 +1,45 @@ -// np_fwht.h -// Basic implementation of the Fast Walsh-Hadamard Transforms -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#ifndef _npfwht_h_ -#define _npfwht_h_ - -#ifdef __cplusplus -extern "C" { -#endif - -void np_fwht(int nlogdim, float *dst, float *src); -// Compute the Walsh-Hadamard transform of the given data up to a -// 64-dimensional transform -// -// Input parameters: -// nlogdim: log2 of the transform size. Must be in the range [0..6] -// src : pointer to the input data buffer. -// dst : pointer to the output data buffer. -// -// src and dst must point to preallocated data buffers of size 2^nlogdim*sizeof(float) -// src and dst buffers can overlap - -#ifdef __cplusplus -} -#endif - -#endif // _npfwht_ +// np_fwht.h +// Basic implementation of the Fast Walsh-Hadamard Transforms +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#ifndef _npfwht_h_ +#define _npfwht_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +void np_fwht(int nlogdim, float *dst, float *src); +// Compute the Walsh-Hadamard transform of the given data up to a +// 64-dimensional transform +// +// Input parameters: +// nlogdim: log2 of the transform size. Must be in the range [0..6] +// src : pointer to the input data buffer. +// dst : pointer to the output data buffer. +// +// src and dst must point to preallocated data buffers of size 2^nlogdim*sizeof(float) +// src and dst buffers can overlap + +#ifdef __cplusplus +} +#endif + +#endif // _npfwht_ diff --git a/lib/qra/q65/pdmath.c b/lib/qra/q65/pdmath.c index 2c55e41b..47ecab91 100755 --- a/lib/qra/q65/pdmath.c +++ b/lib/qra/q65/pdmath.c @@ -1,385 +1,385 @@ -// pdmath.c -// Elementary math on probability distributions -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#include "pdmath.h" - -typedef const float *ppd_uniform; -typedef void (*ppd_imul)(float*,const float*); -typedef float (*ppd_norm)(float*); - -// define vector size in function of its logarithm in base 2 -static const int pd_log2dim[7] = { - 1,2,4,8,16,32,64 -}; - -// define uniform distributions of given size -static const float pd_uniform1[1] = { - 1. -}; -static const float pd_uniform2[2] = { - 1./2., 1./2. -}; -static const float pd_uniform4[4] = { - 1./4., 1./4.,1./4., 1./4. -}; -static const float pd_uniform8[8] = { - 1./8., 1./8.,1./8., 1./8.,1./8., 1./8.,1./8., 1./8. -}; -static const float pd_uniform16[16] = { - 1./16., 1./16., 1./16., 1./16.,1./16., 1./16.,1./16., 1./16., - 1./16., 1./16., 1./16., 1./16.,1./16., 1./16.,1./16., 1./16. -}; -static const float pd_uniform32[32] = { - 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., - 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., - 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., - 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32. -}; -static const float pd_uniform64[64] = { - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64. - -}; - -static const ppd_uniform pd_uniform_tab[7] = { - pd_uniform1, - pd_uniform2, - pd_uniform4, - pd_uniform8, - pd_uniform16, - pd_uniform32, - pd_uniform64 -}; - -// returns a pointer to the uniform distribution of the given logsize -const float *pd_uniform(int nlogdim) -{ - return pd_uniform_tab[nlogdim]; -} - -// in-place multiplication functions -// compute dst = dst*src for any element of the distrib - -static void pd_imul1(float *dst, const float *src) -{ - dst[0] *= src[0]; -} - -static void pd_imul2(float *dst, const float *src) -{ - dst[0] *= src[0]; dst[1] *= src[1]; -} -static void pd_imul4(float *dst, const float *src) -{ - dst[0] *= src[0]; dst[1] *= src[1]; - dst[2] *= src[2]; dst[3] *= src[3]; -} -static void pd_imul8(float *dst, const float *src) -{ - dst[0] *= src[0]; dst[1] *= src[1]; dst[2] *= src[2]; dst[3] *= src[3]; - dst[4] *= src[4]; dst[5] *= src[5]; dst[6] *= src[6]; dst[7] *= src[7]; -} -static void pd_imul16(float *dst, const float *src) -{ - dst[0] *= src[0]; dst[1] *= src[1]; dst[2] *= src[2]; dst[3] *= src[3]; - dst[4] *= src[4]; dst[5] *= src[5]; dst[6] *= src[6]; dst[7] *= src[7]; - dst[8] *= src[8]; dst[9] *= src[9]; dst[10]*= src[10]; dst[11]*= src[11]; - dst[12]*= src[12]; dst[13]*= src[13]; dst[14]*= src[14]; dst[15]*= src[15]; -} -static void pd_imul32(float *dst, const float *src) -{ - pd_imul16(dst,src); - pd_imul16(dst+16,src+16); -} -static void pd_imul64(float *dst, const float *src) -{ - pd_imul16(dst, src); - pd_imul16(dst+16, src+16); - pd_imul16(dst+32, src+32); - pd_imul16(dst+48, src+48); -} - -static const ppd_imul pd_imul_tab[7] = { - pd_imul1, - pd_imul2, - pd_imul4, - pd_imul8, - pd_imul16, - pd_imul32, - pd_imul64 -}; - -// in place multiplication -// compute dst = dst*src for any element of the distrib give their log2 size -// arguments must be pointers to array of floats of the given size -void pd_imul(float *dst, const float *src, int nlogdim) -{ - pd_imul_tab[nlogdim](dst,src); -} - -static float pd_norm1(float *ppd) -{ - float t = ppd[0]; - ppd[0] = 1.f; - return t; -} - -static float pd_norm2(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; - - if (t<=0) { - pd_init(ppd,pd_uniform(1),pd_log2dim[1]); - return t; - } - - to = t; - t = 1.f/t; - ppd[0] *=t; ppd[1] *=t; - return to; - -} - -static float pd_norm4(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; - - if (t<=0) { - pd_init(ppd,pd_uniform(2),pd_log2dim[2]); - return t; - } - - to = t; - t = 1.f/t; - ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; - return to; -} - -static float pd_norm8(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; - t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; - - if (t<=0) { - pd_init(ppd,pd_uniform(3),pd_log2dim[3]); - return t; - } - - to = t; - t = 1.f/t; - ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; - ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; - return to; -} -static float pd_norm16(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; - t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; - t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; - t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; - - if (t<=0) { - pd_init(ppd,pd_uniform(4),pd_log2dim[4]); - return t; - } - - to = t; - t = 1.f/t; - ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; - ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; - ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; - ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; - - return to; -} -static float pd_norm32(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; - t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; - t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; - t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; - t +=ppd[16]; t +=ppd[17]; t +=ppd[18]; t +=ppd[19]; - t +=ppd[20]; t +=ppd[21]; t +=ppd[22]; t +=ppd[23]; - t +=ppd[24]; t +=ppd[25]; t +=ppd[26]; t +=ppd[27]; - t +=ppd[28]; t +=ppd[29]; t +=ppd[30]; t +=ppd[31]; - - if (t<=0) { - pd_init(ppd,pd_uniform(5),pd_log2dim[5]); - return t; - } - - to = t; - t = 1.f/t; - ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; - ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; - ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; - ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; - ppd[16] *=t; ppd[17] *=t; ppd[18] *=t; ppd[19] *=t; - ppd[20] *=t; ppd[21] *=t; ppd[22] *=t; ppd[23] *=t; - ppd[24] *=t; ppd[25] *=t; ppd[26] *=t; ppd[27] *=t; - ppd[28] *=t; ppd[29] *=t; ppd[30] *=t; ppd[31] *=t; - - return to; -} - -static float pd_norm64(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; - t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; - t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; - t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; - t +=ppd[16]; t +=ppd[17]; t +=ppd[18]; t +=ppd[19]; - t +=ppd[20]; t +=ppd[21]; t +=ppd[22]; t +=ppd[23]; - t +=ppd[24]; t +=ppd[25]; t +=ppd[26]; t +=ppd[27]; - t +=ppd[28]; t +=ppd[29]; t +=ppd[30]; t +=ppd[31]; - - t +=ppd[32]; t +=ppd[33]; t +=ppd[34]; t +=ppd[35]; - t +=ppd[36]; t +=ppd[37]; t +=ppd[38]; t +=ppd[39]; - t +=ppd[40]; t +=ppd[41]; t +=ppd[42]; t +=ppd[43]; - t +=ppd[44]; t +=ppd[45]; t +=ppd[46]; t +=ppd[47]; - t +=ppd[48]; t +=ppd[49]; t +=ppd[50]; t +=ppd[51]; - t +=ppd[52]; t +=ppd[53]; t +=ppd[54]; t +=ppd[55]; - t +=ppd[56]; t +=ppd[57]; t +=ppd[58]; t +=ppd[59]; - t +=ppd[60]; t +=ppd[61]; t +=ppd[62]; t +=ppd[63]; - - if (t<=0) { - pd_init(ppd,pd_uniform(6),pd_log2dim[6]); - return t; - } - - to = t; - t = 1.0f/t; - ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; - ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; - ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; - ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; - ppd[16] *=t; ppd[17] *=t; ppd[18] *=t; ppd[19] *=t; - ppd[20] *=t; ppd[21] *=t; ppd[22] *=t; ppd[23] *=t; - ppd[24] *=t; ppd[25] *=t; ppd[26] *=t; ppd[27] *=t; - ppd[28] *=t; ppd[29] *=t; ppd[30] *=t; ppd[31] *=t; - - ppd[32] *=t; ppd[33] *=t; ppd[34] *=t; ppd[35] *=t; - ppd[36] *=t; ppd[37] *=t; ppd[38] *=t; ppd[39] *=t; - ppd[40] *=t; ppd[41] *=t; ppd[42] *=t; ppd[43] *=t; - ppd[44] *=t; ppd[45] *=t; ppd[46] *=t; ppd[47] *=t; - ppd[48] *=t; ppd[49] *=t; ppd[50] *=t; ppd[51] *=t; - ppd[52] *=t; ppd[53] *=t; ppd[54] *=t; ppd[55] *=t; - ppd[56] *=t; ppd[57] *=t; ppd[58] *=t; ppd[59] *=t; - ppd[60] *=t; ppd[61] *=t; ppd[62] *=t; ppd[63] *=t; - - return to; -} - - -static const ppd_norm pd_norm_tab[7] = { - pd_norm1, - pd_norm2, - pd_norm4, - pd_norm8, - pd_norm16, - pd_norm32, - pd_norm64 -}; - -float pd_norm(float *pd, int nlogdim) -{ - return pd_norm_tab[nlogdim](pd); -} - -void pd_memset(float *dst, const float *src, int ndim, int nitems) -{ - int size = PD_SIZE(ndim); - while(nitems--) { - memcpy(dst,src,size); - dst +=ndim; - } -} - -void pd_fwdperm(float *dst, float *src, const int *perm, int ndim) -{ - // TODO: non-loop implementation - while (ndim--) - dst[ndim] = src[perm[ndim]]; -} - -void pd_bwdperm(float *dst, float *src, const int *perm, int ndim) -{ - // TODO: non-loop implementation - while (ndim--) - dst[perm[ndim]] = src[ndim]; -} - -float pd_max(float *src, int ndim) -{ - // TODO: faster implementation - - float cmax=0; // we assume that prob distributions are always positive - float cval; - - while (ndim--) { - cval = src[ndim]; - if (cval>=cmax) { - cmax = cval; - } - } - - return cmax; -} - -int pd_argmax(float *pmax, float *src, int ndim) -{ - // TODO: faster implementation - - float cmax=0; // we assume that prob distributions are always positive - float cval; - int idxmax=-1; // indicates that all pd elements are <0 - - while (ndim--) { - cval = src[ndim]; - if (cval>=cmax) { - cmax = cval; - idxmax = ndim; - } - } - - if (pmax) - *pmax = cmax; - - return idxmax; -} +// pdmath.c +// Elementary math on probability distributions +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#include "pdmath.h" + +typedef const float *ppd_uniform; +typedef void (*ppd_imul)(float*,const float*); +typedef float (*ppd_norm)(float*); + +// define vector size in function of its logarithm in base 2 +static const int pd_log2dim[7] = { + 1,2,4,8,16,32,64 +}; + +// define uniform distributions of given size +static const float pd_uniform1[1] = { + 1. +}; +static const float pd_uniform2[2] = { + 1./2., 1./2. +}; +static const float pd_uniform4[4] = { + 1./4., 1./4.,1./4., 1./4. +}; +static const float pd_uniform8[8] = { + 1./8., 1./8.,1./8., 1./8.,1./8., 1./8.,1./8., 1./8. +}; +static const float pd_uniform16[16] = { + 1./16., 1./16., 1./16., 1./16.,1./16., 1./16.,1./16., 1./16., + 1./16., 1./16., 1./16., 1./16.,1./16., 1./16.,1./16., 1./16. +}; +static const float pd_uniform32[32] = { + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32. +}; +static const float pd_uniform64[64] = { + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64. + +}; + +static const ppd_uniform pd_uniform_tab[7] = { + pd_uniform1, + pd_uniform2, + pd_uniform4, + pd_uniform8, + pd_uniform16, + pd_uniform32, + pd_uniform64 +}; + +// returns a pointer to the uniform distribution of the given logsize +const float *pd_uniform(int nlogdim) +{ + return pd_uniform_tab[nlogdim]; +} + +// in-place multiplication functions +// compute dst = dst*src for any element of the distrib + +static void pd_imul1(float *dst, const float *src) +{ + dst[0] *= src[0]; +} + +static void pd_imul2(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; +} +static void pd_imul4(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; + dst[2] *= src[2]; dst[3] *= src[3]; +} +static void pd_imul8(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; dst[2] *= src[2]; dst[3] *= src[3]; + dst[4] *= src[4]; dst[5] *= src[5]; dst[6] *= src[6]; dst[7] *= src[7]; +} +static void pd_imul16(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; dst[2] *= src[2]; dst[3] *= src[3]; + dst[4] *= src[4]; dst[5] *= src[5]; dst[6] *= src[6]; dst[7] *= src[7]; + dst[8] *= src[8]; dst[9] *= src[9]; dst[10]*= src[10]; dst[11]*= src[11]; + dst[12]*= src[12]; dst[13]*= src[13]; dst[14]*= src[14]; dst[15]*= src[15]; +} +static void pd_imul32(float *dst, const float *src) +{ + pd_imul16(dst,src); + pd_imul16(dst+16,src+16); +} +static void pd_imul64(float *dst, const float *src) +{ + pd_imul16(dst, src); + pd_imul16(dst+16, src+16); + pd_imul16(dst+32, src+32); + pd_imul16(dst+48, src+48); +} + +static const ppd_imul pd_imul_tab[7] = { + pd_imul1, + pd_imul2, + pd_imul4, + pd_imul8, + pd_imul16, + pd_imul32, + pd_imul64 +}; + +// in place multiplication +// compute dst = dst*src for any element of the distrib give their log2 size +// arguments must be pointers to array of floats of the given size +void pd_imul(float *dst, const float *src, int nlogdim) +{ + pd_imul_tab[nlogdim](dst,src); +} + +static float pd_norm1(float *ppd) +{ + float t = ppd[0]; + ppd[0] = 1.f; + return t; +} + +static float pd_norm2(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; + + if (t<=0) { + pd_init(ppd,pd_uniform(1),pd_log2dim[1]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; + return to; + +} + +static float pd_norm4(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + + if (t<=0) { + pd_init(ppd,pd_uniform(2),pd_log2dim[2]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + return to; +} + +static float pd_norm8(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + + if (t<=0) { + pd_init(ppd,pd_uniform(3),pd_log2dim[3]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + return to; +} +static float pd_norm16(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; + t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; + + if (t<=0) { + pd_init(ppd,pd_uniform(4),pd_log2dim[4]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; + ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; + + return to; +} +static float pd_norm32(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; + t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; + t +=ppd[16]; t +=ppd[17]; t +=ppd[18]; t +=ppd[19]; + t +=ppd[20]; t +=ppd[21]; t +=ppd[22]; t +=ppd[23]; + t +=ppd[24]; t +=ppd[25]; t +=ppd[26]; t +=ppd[27]; + t +=ppd[28]; t +=ppd[29]; t +=ppd[30]; t +=ppd[31]; + + if (t<=0) { + pd_init(ppd,pd_uniform(5),pd_log2dim[5]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; + ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; + ppd[16] *=t; ppd[17] *=t; ppd[18] *=t; ppd[19] *=t; + ppd[20] *=t; ppd[21] *=t; ppd[22] *=t; ppd[23] *=t; + ppd[24] *=t; ppd[25] *=t; ppd[26] *=t; ppd[27] *=t; + ppd[28] *=t; ppd[29] *=t; ppd[30] *=t; ppd[31] *=t; + + return to; +} + +static float pd_norm64(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; + t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; + t +=ppd[16]; t +=ppd[17]; t +=ppd[18]; t +=ppd[19]; + t +=ppd[20]; t +=ppd[21]; t +=ppd[22]; t +=ppd[23]; + t +=ppd[24]; t +=ppd[25]; t +=ppd[26]; t +=ppd[27]; + t +=ppd[28]; t +=ppd[29]; t +=ppd[30]; t +=ppd[31]; + + t +=ppd[32]; t +=ppd[33]; t +=ppd[34]; t +=ppd[35]; + t +=ppd[36]; t +=ppd[37]; t +=ppd[38]; t +=ppd[39]; + t +=ppd[40]; t +=ppd[41]; t +=ppd[42]; t +=ppd[43]; + t +=ppd[44]; t +=ppd[45]; t +=ppd[46]; t +=ppd[47]; + t +=ppd[48]; t +=ppd[49]; t +=ppd[50]; t +=ppd[51]; + t +=ppd[52]; t +=ppd[53]; t +=ppd[54]; t +=ppd[55]; + t +=ppd[56]; t +=ppd[57]; t +=ppd[58]; t +=ppd[59]; + t +=ppd[60]; t +=ppd[61]; t +=ppd[62]; t +=ppd[63]; + + if (t<=0) { + pd_init(ppd,pd_uniform(6),pd_log2dim[6]); + return t; + } + + to = t; + t = 1.0f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; + ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; + ppd[16] *=t; ppd[17] *=t; ppd[18] *=t; ppd[19] *=t; + ppd[20] *=t; ppd[21] *=t; ppd[22] *=t; ppd[23] *=t; + ppd[24] *=t; ppd[25] *=t; ppd[26] *=t; ppd[27] *=t; + ppd[28] *=t; ppd[29] *=t; ppd[30] *=t; ppd[31] *=t; + + ppd[32] *=t; ppd[33] *=t; ppd[34] *=t; ppd[35] *=t; + ppd[36] *=t; ppd[37] *=t; ppd[38] *=t; ppd[39] *=t; + ppd[40] *=t; ppd[41] *=t; ppd[42] *=t; ppd[43] *=t; + ppd[44] *=t; ppd[45] *=t; ppd[46] *=t; ppd[47] *=t; + ppd[48] *=t; ppd[49] *=t; ppd[50] *=t; ppd[51] *=t; + ppd[52] *=t; ppd[53] *=t; ppd[54] *=t; ppd[55] *=t; + ppd[56] *=t; ppd[57] *=t; ppd[58] *=t; ppd[59] *=t; + ppd[60] *=t; ppd[61] *=t; ppd[62] *=t; ppd[63] *=t; + + return to; +} + + +static const ppd_norm pd_norm_tab[7] = { + pd_norm1, + pd_norm2, + pd_norm4, + pd_norm8, + pd_norm16, + pd_norm32, + pd_norm64 +}; + +float pd_norm(float *pd, int nlogdim) +{ + return pd_norm_tab[nlogdim](pd); +} + +void pd_memset(float *dst, const float *src, int ndim, int nitems) +{ + int size = PD_SIZE(ndim); + while(nitems--) { + memcpy(dst,src,size); + dst +=ndim; + } +} + +void pd_fwdperm(float *dst, float *src, const int *perm, int ndim) +{ + // TODO: non-loop implementation + while (ndim--) + dst[ndim] = src[perm[ndim]]; +} + +void pd_bwdperm(float *dst, float *src, const int *perm, int ndim) +{ + // TODO: non-loop implementation + while (ndim--) + dst[perm[ndim]] = src[ndim]; +} + +float pd_max(float *src, int ndim) +{ + // TODO: faster implementation + + float cmax=0; // we assume that prob distributions are always positive + float cval; + + while (ndim--) { + cval = src[ndim]; + if (cval>=cmax) { + cmax = cval; + } + } + + return cmax; +} + +int pd_argmax(float *pmax, float *src, int ndim) +{ + // TODO: faster implementation + + float cmax=0; // we assume that prob distributions are always positive + float cval; + int idxmax=-1; // indicates that all pd elements are <0 + + while (ndim--) { + cval = src[ndim]; + if (cval>=cmax) { + cmax = cval; + idxmax = ndim; + } + } + + if (pmax) + *pmax = cmax; + + return idxmax; +} diff --git a/lib/qra/q65/pdmath.h b/lib/qra/q65/pdmath.h index bd441e08..bbd1210c 100755 --- a/lib/qra/q65/pdmath.h +++ b/lib/qra/q65/pdmath.h @@ -1,85 +1,85 @@ -// pdmath.h -// Elementary math on probability distributions -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - - -#ifndef _pdmath_h_ -#define _pdmath_h_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define PD_NDIM(nlogdim) ((1<<(nlogdim)) -#define PD_SIZE(ndim) ((ndim)*sizeof(float)) -#define PD_ROWADDR(fp,ndim,idx) (fp+((ndim)*(idx))) - -const float *pd_uniform(int nlogdim); -// Returns a pointer to a (constant) uniform distribution of the given log2 size - -#define pd_init(dst,src,ndim) memcpy(dst,src,PD_SIZE(ndim)) -// Distribution copy - -void pd_memset(float *dst, const float *src, int ndim, int nitems); -// Copy the distribution pointed by src to the array of distributions dst -// src is a pointer to the input distribution (a vector of size ndim) -// dst is a pointer to a linear array of distributions (a vector of size ndim*nitems) - -void pd_imul(float *dst, const float *src, int nlogdim); -// In place multiplication -// Compute dst = dst*src for any element of the distrib give their log2 size -// src and dst arguments must be pointers to array of floats of the given size - -float pd_norm(float *pd, int nlogdim); -// In place normalizazion -// Normalizes the input vector so that the sum of its components are one -// pd must be a pointer to an array of floats of the given size. -// If the norm of the input vector is non-positive the vector components -// are replaced with a uniform distribution -// Returns the norm of the distribution prior to the normalization - -void pd_fwdperm(float *dst, float *src, const int *perm, int ndim); -// Forward permutation of a distribution -// Computes dst[k] = src[perm[k]] for every element in the distribution -// perm must be a pointer to an array of integers of length ndim - -void pd_bwdperm(float *dst, float *src, const int *perm, int ndim); -// Backward permutation of a distribution -// Computes dst[perm[k]] = src[k] for every element in the distribution -// perm must be a pointer to an array of integers of length ndim - -float pd_max(float *src, int ndim); -// Return the maximum of the elements of the given distribution -// Assumes that the input vector is a probability distribution and that each element in the -// distribution is non negative - -int pd_argmax(float *pmax, float *src, int ndim); -// Return the index of the maximum element of the given distribution -// The maximum is stored in the variable pointed by pmax if pmax is not null -// Same note of pd_max applies. -// Return -1 if all the elements in the distribution are negative - -#ifdef __cplusplus -} -#endif - -#endif // _pdmath_h_ +// pdmath.h +// Elementary math on probability distributions +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + + +#ifndef _pdmath_h_ +#define _pdmath_h_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PD_NDIM(nlogdim) ((1<<(nlogdim)) +#define PD_SIZE(ndim) ((ndim)*sizeof(float)) +#define PD_ROWADDR(fp,ndim,idx) (fp+((ndim)*(idx))) + +const float *pd_uniform(int nlogdim); +// Returns a pointer to a (constant) uniform distribution of the given log2 size + +#define pd_init(dst,src,ndim) memcpy(dst,src,PD_SIZE(ndim)) +// Distribution copy + +void pd_memset(float *dst, const float *src, int ndim, int nitems); +// Copy the distribution pointed by src to the array of distributions dst +// src is a pointer to the input distribution (a vector of size ndim) +// dst is a pointer to a linear array of distributions (a vector of size ndim*nitems) + +void pd_imul(float *dst, const float *src, int nlogdim); +// In place multiplication +// Compute dst = dst*src for any element of the distrib give their log2 size +// src and dst arguments must be pointers to array of floats of the given size + +float pd_norm(float *pd, int nlogdim); +// In place normalizazion +// Normalizes the input vector so that the sum of its components are one +// pd must be a pointer to an array of floats of the given size. +// If the norm of the input vector is non-positive the vector components +// are replaced with a uniform distribution +// Returns the norm of the distribution prior to the normalization + +void pd_fwdperm(float *dst, float *src, const int *perm, int ndim); +// Forward permutation of a distribution +// Computes dst[k] = src[perm[k]] for every element in the distribution +// perm must be a pointer to an array of integers of length ndim + +void pd_bwdperm(float *dst, float *src, const int *perm, int ndim); +// Backward permutation of a distribution +// Computes dst[perm[k]] = src[k] for every element in the distribution +// perm must be a pointer to an array of integers of length ndim + +float pd_max(float *src, int ndim); +// Return the maximum of the elements of the given distribution +// Assumes that the input vector is a probability distribution and that each element in the +// distribution is non negative + +int pd_argmax(float *pmax, float *src, int ndim); +// Return the index of the maximum element of the given distribution +// The maximum is stored in the variable pointed by pmax if pmax is not null +// Same note of pd_max applies. +// Return -1 if all the elements in the distribution are negative + +#ifdef __cplusplus +} +#endif + +#endif // _pdmath_h_ diff --git a/lib/qra/q65/q65.c b/lib/qra/q65/q65.c index 853a0696..10d756d8 100755 --- a/lib/qra/q65/q65.c +++ b/lib/qra/q65/q65.c @@ -1,889 +1,889 @@ -// q65.c -// q65 modes encoding/decoding functions -// -// (c) 2020 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#include -#include -#include - -#include "q65.h" -#include "pdmath.h" - -// Minimum codeword loglikelihood for decoding -#define Q65_LLH_THRESHOLD -260.0f - -// This value produce the same WER performance in decode_fullaplist -// #define Q65_LLH_THRESHOLD -262.0f - - -static int _q65_crc6(int *x, int sz); -static void _q65_crc12(int *y, int *x, int sz); - -float q65_llh; - -int q65_init(q65_codec_ds *pCodec, const qracode *pqracode) -{ - // Eb/No value for which we optimize the decoder metric (AWGN/Rayleigh cases) - const float EbNodBMetric = 2.8f; - const float EbNoMetric = (float)pow(10,EbNodBMetric/10); - - float R; // code effective rate (after puncturing) - int nm; // bits per symbol - - if (!pCodec) - return -1; // why do you called me? - - if (!pqracode) - return -2; // invalid qra code - - if (pqracode->M!=64) - return -3; // q65 supports only codes over GF(64) - - pCodec->pQraCode = pqracode; - - // allocate buffers used by encoding/decoding functions - pCodec->x = (int*)malloc(pqracode->K*sizeof(int)); - pCodec->y = (int*)malloc(pqracode->N*sizeof(int)); - pCodec->qra_v2cmsg = (float*)malloc(pqracode->NMSG*pqracode->M*sizeof(float)); - pCodec->qra_c2vmsg = (float*)malloc(pqracode->NMSG*pqracode->M*sizeof(float)); - pCodec->ix = (float*)malloc(pqracode->N*pqracode->M*sizeof(float)); - pCodec->ex = (float*)malloc(pqracode->N*pqracode->M*sizeof(float)); - - if (pCodec->x== NULL || - pCodec->y== NULL || - pCodec->qra_v2cmsg== NULL || - pCodec->qra_c2vmsg== NULL || - pCodec->ix== NULL || - pCodec->ex== NULL) { - q65_free(pCodec); - return -4; // out of memory - } - - // compute and store the AWGN/Rayleigh Es/No ratio for which we optimize - // the decoder metric - nm = _q65_get_bits_per_symbol(pqracode); - R = _q65_get_code_rate(pqracode); - pCodec->decoderEsNoMetric = 1.0f*nm*R*EbNoMetric; - - return 1; -} - -void q65_free(q65_codec_ds *pCodec) -{ - if (!pCodec) - return; - - // free internal buffers - if (pCodec->x!=NULL) - free(pCodec->x); - - if (pCodec->y!=NULL) - free(pCodec->y); - - if (pCodec->qra_v2cmsg!=NULL) - free(pCodec->qra_v2cmsg); - - if (pCodec->qra_c2vmsg!=NULL) - free(pCodec->qra_c2vmsg); - - if (pCodec->ix!=NULL) - free(pCodec->ix); - - if (pCodec->ex!=NULL) - free(pCodec->ex); - - pCodec->pQraCode = NULL; - pCodec->x = NULL; - pCodec->y = NULL; - pCodec->qra_v2cmsg = NULL; - pCodec->qra_c2vmsg = NULL; - pCodec->qra_v2cmsg = NULL; - pCodec->ix = NULL; - pCodec->ex = NULL; - - return; -} - -int q65_encode(const q65_codec_ds *pCodec, int *pOutputCodeword, const int *pInputMsg) -{ - const qracode *pQraCode; - int *px; - int *py; - int nK; - int nN; - - if (!pCodec) - return -1; // which codec? - - pQraCode = pCodec->pQraCode; - px = pCodec->x; - py = pCodec->y; - nK = _q65_get_message_length(pQraCode); - nN = _q65_get_codeword_length(pQraCode); - - // copy the information symbols into the internal buffer - memcpy(px,pInputMsg,nK*sizeof(int)); - - // compute and append the appropriate CRC if required - switch (pQraCode->type) { - case QRATYPE_NORMAL: - break; - case QRATYPE_CRC: - case QRATYPE_CRCPUNCTURED: - px[nK] = _q65_crc6(px,nK); - break; - case QRATYPE_CRCPUNCTURED2: - _q65_crc12(px+nK,px,nK); - break; - default: - return -2; // code type not supported - } - - // encode with the given qra code - qra_encode(pQraCode,py,px); - - // puncture the CRC symbols as required - // and copy the result to the destination buffer - switch (pQraCode->type) { - case QRATYPE_NORMAL: - case QRATYPE_CRC: - // no puncturing - memcpy(pOutputCodeword,py,nN*sizeof(int)); - break; - case QRATYPE_CRCPUNCTURED: - // strip the single CRC symbol from the encoded codeword - memcpy(pOutputCodeword,py,nK*sizeof(int)); // copy the systematic symbols - memcpy(pOutputCodeword+nK,py+nK+1,(nN-nK)*sizeof(int)); // copy the check symbols skipping the CRC symbol - break; - case QRATYPE_CRCPUNCTURED2: - // strip the 2 CRC symbols from the encoded codeword - memcpy(pOutputCodeword,py,nK*sizeof(int)); // copy the systematic symbols - memcpy(pOutputCodeword+nK,py+nK+2,(nN-nK)*sizeof(int)); // copy the check symbols skipping the two CRC symbols - break; - default: - return -2; // code type unsupported - } - - return 1; // ok -} - -int q65_intrinsics(q65_codec_ds *pCodec, float *pIntrinsics, const float *pInputEnergies) -{ - // compute observations intrinsics probabilities - // for the AWGN/Rayleigh channels - - // NOTE: - // A true Rayleigh channel metric would require that the channel gains were known - // for each symbol in the codeword. Such gains cannot be estimated reliably when - // the Es/No ratio is small. Therefore we compute intrinsic probabilities assuming - // that, on average, these channel gains are unitary. - // In general it is even difficult to estimate the Es/No ratio for the AWGN channel - // Therefore we always compute the intrinsic probabilities assuming that the Es/No - // ratio is known and equal to the constant decoderEsNoMetric. This assumption will - // generate the true intrinsic probabilities only when the actual Eb/No ratio is - // equal to this constant. As in all the other cases the probabilities are evaluated - // with a wrong scaling constant we can expect that the decoder performance at different - // Es/No will be worse. Anyway, since the EsNoMetric constant has been chosen so that the - // decoder error rate is about 50%, we obtain almost optimal error rates down to - // any useful Es/No ratio. - - const qracode *pQraCode; - int nN, nBits; - float EsNoMetric; - - if (pCodec==NULL) - return -1; // which codec? - - pQraCode = pCodec->pQraCode; - nN = _q65_get_codeword_length(pQraCode); - nBits = pQraCode->m; - - EsNoMetric = pCodec->decoderEsNoMetric; - qra_mfskbesselmetric(pIntrinsics,pInputEnergies,nBits,nN,EsNoMetric); - - return 1; // success -} - -int q65_esnodb(const q65_codec_ds *pCodec, float *pEsNodB, const int *ydec, const float *pInputEnergies) -{ - // compute average Es/No for the AWGN/Rayleigh channel cases - - int k,j; - float sigplusnoise=0; - float noise=0; - int nN, nM; - const float *pIn = pInputEnergies; - const int *py = ydec; - float EsNodB; - - nN = q65_get_codeword_length(pCodec); - nM = q65_get_alphabet_size(pCodec); - - for (k=0;k4) - return Q65_DECODE_INVPARAMS; // invalid submode - - // As the symbol duration in q65 is different than in QRA64, - // the fading tables continue to be valid if the B90Ts parameter - // is properly scaled to the QRA64 symbol interval - // Compute index to most appropriate weighting function coefficients - B90 = B90Ts/TS_QRA64; - hidx = (int)(logf(B90)/logf(1.09f) - 0.499f); - - // Unlike in QRA64 we accept any B90, anyway limiting it to - // the extreme cases (0.9 to 210 Hz approx.) - if (hidx<0) - hidx = 0; - else - if (hidx > 63) //Changed by K1JT: previously max was 64. - hidx=63; //Changed by K1JT: previously max was 64. - - // select the appropriate weighting fading coefficients array - if (fadingModel==0) { // gaussian fading model - // point to gaussian energy weighting taps - hlen = glen_tab_gauss[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) - hptr = gptr_tab_gauss[hidx]; // pointer to the first (L+1)/2 coefficients of w fun - } - else if (fadingModel==1) { - // point to lorentzian energy weighting taps - hlen = glen_tab_lorentz[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) - hptr = gptr_tab_lorentz[hidx]; // pointer to the first (L+1)/2 coefficients of w fun - } - else - return Q65_DECODE_INVPARAMS; // invalid fading model - - // compute (euristically) the optimal decoder metric accordingly the given spread amount - // We assume that the decoder 50% decoding threshold is: - // Es/No(dB) = Es/No(AWGN)(dB) + 8*log(B90)/log(240)(dB) - // that's to say, at the maximum Doppler spread bandwidth (240 Hz for QRA64) - // there's a ~8 dB Es/No degradation over the AWGN case - fTemp = 8.0f*logf(B90)/logf(240.0f); // assumed Es/No degradation for the given fading bandwidth - EsNoMetric = pCodec->decoderEsNoMetric*powf(10.0f,fTemp/10.0f); - - nM = q65_get_alphabet_size(pCodec); - nN = q65_get_codeword_length(pCodec); - nBinsPerTone = 1<ffNoiseVar = fNoiseVar; - pCodec->ffEsNoMetric = EsNoMetric; - pCodec->nBinsPerTone = nBinsPerTone; - pCodec->nBinsPerSymbol = nBinsPerSymbol; - pCodec->nWeights = hlen; - weight = pCodec->ffWeight; - - // compute the fast fading weights accordingly to the Es/No ratio - // for which we compute the exact intrinsics probabilities - for (k=0;kmaxlogp) // keep track of the max - maxlogp = fTemp; - pCurIx[k]=fTemp; - - pCurBin += nBinsPerTone; // next tone - } - - // exponentiate and accumulate the normalization constant - sumix = 0.0f; - for (k=0;k 85.0) x= 85.0; - fTemp = expf(x); - pCurIx[k]=fTemp; - sumix +=fTemp; - } - - // scale to a probability distribution - sumix = 1.0f/sumix; - for (k=0;knBinsPerTone; - nBinsPerSymbol = pCodec->nBinsPerSymbol; - nWeights = pCodec->nWeights; - ffNoiseVar = pCodec->ffNoiseVar; - ffEsNoMetric = pCodec->ffEsNoMetric; - nTotWeights = 2*nWeights-1; - - // compute symbols energy (noise included) summing the - // energies pertaining to the decoded symbols in the codeword - - EsPlusWNo = 0.0f; - pCurSym = pInputEnergies + nM; // point to first central bin of first symbol tone - for (n=0;npQraCode; - ix = pCodec->ix; - ex = pCodec->ex; - - nK = _q65_get_message_length(pQraCode); - nN = _q65_get_codeword_length(pQraCode); - nM = pQraCode->M; - nBits = pQraCode->m; - - px = pCodec->x; - py = pCodec->y; - - // Depuncture intrinsics observations as required by the code type - switch (pQraCode->type) { - case QRATYPE_CRCPUNCTURED: - memcpy(ix,pIntrinsics,nK*nM*sizeof(float)); // information symbols - pd_init(PD_ROWADDR(ix,nM,nK),pd_uniform(nBits),nM); // crc - memcpy(ix+(nK+1)*nM,pIntrinsics+nK*nM,(nN-nK)*nM*sizeof(float)); // parity checks - break; - case QRATYPE_CRCPUNCTURED2: - memcpy(ix,pIntrinsics,nK*nM*sizeof(float)); // information symbols - pd_init(PD_ROWADDR(ix,nM,nK),pd_uniform(nBits),nM); // crc - pd_init(PD_ROWADDR(ix,nM,nK+1),pd_uniform(nBits),nM); // crc - memcpy(ix+(nK+2)*nM,pIntrinsics+nK*nM,(nN-nK)*nM*sizeof(float)); // parity checks - break; - case QRATYPE_NORMAL: - case QRATYPE_CRC: - default: - // no puncturing - memcpy(ix,pIntrinsics,nN*nM*sizeof(float)); // as they are - } - - // mask the intrinsics with the available a priori knowledge - if (pAPMask!=NULL) - _q65_mask(pQraCode,ix,pAPMask,pAPSymbols); - - - // Compute the extrinsic symbols probabilities with the message-passing algorithm - // Stop if the extrinsics information does not converges to unity - // within the given number of iterations - rc = qra_extrinsic( pQraCode, - ex, - ix, - maxiters, - pCodec->qra_v2cmsg, - pCodec->qra_c2vmsg); - - if (rc<0) - // failed to converge to a solution - return Q65_DECODE_FAILED; - - // decode the information symbols (punctured information symbols included) - qra_mapdecode(pQraCode,px,ex,ix); - - // verify CRC match - - switch (pQraCode->type) { - case QRATYPE_CRC: - case QRATYPE_CRCPUNCTURED: - crc6=_q65_crc6(px,nK); // compute crc-6 - if (crc6!=px[nK]) - return Q65_DECODE_CRCMISMATCH; // crc doesn't match - break; - case QRATYPE_CRCPUNCTURED2: - _q65_crc12(crc12, px,nK); // compute crc-12 - if (crc12[0]!=px[nK] || - crc12[1]!=px[nK+1]) - return Q65_DECODE_CRCMISMATCH; // crc doesn't match - break; - case QRATYPE_NORMAL: - default: - // nothing to check - break; - } - - // copy the decoded msg to the user buffer (excluding punctured symbols) - if (pDecodedMsg) - memcpy(pDecodedMsg,px,nK*sizeof(int)); - -#ifndef Q65_CHECKLLH - if (pDecodedCodeword==NULL) // user is not interested in the decoded codeword - return rc; // return the number of iterations required to decode -#else - if (pDecodedCodeword==NULL) // we must have a buffer - return Q65_DECODE_INVPARAMS; // return error -#endif - - // crc matches therefore we can reconstruct the transmitted codeword - // reencoding the information available in px... - - qra_encode(pQraCode, py, px); - - // ...and strip the punctured symbols from the codeword - switch (pQraCode->type) { - case QRATYPE_CRCPUNCTURED: - memcpy(pDecodedCodeword,py,nK*sizeof(int)); - memcpy(pDecodedCodeword+nK,py+nK+1,(nN-nK)*sizeof(int)); // puncture crc-6 symbol - break; - case QRATYPE_CRCPUNCTURED2: - memcpy(pDecodedCodeword,py,nK*sizeof(int)); - memcpy(pDecodedCodeword+nK,py+nK+2,(nN-nK)*sizeof(int)); // puncture crc-12 symbols - break; - case QRATYPE_CRC: - case QRATYPE_NORMAL: - default: - memcpy(pDecodedCodeword,py,nN*sizeof(int)); // no puncturing - } - -#ifdef Q65_CHECKLLH - if (q65_check_llh(NULL,pDecodedCodeword, nN, nM, pIntrinsics)==0) // llh less than threshold - return Q65_DECODE_LLHLOW; -#endif - - return rc; // return the number of iterations required to decode - -} - - -// Compute and verify the loglikelihood of the decoded codeword -int q65_check_llh(float *llh, const int* ydec, const int nN, const int nM, const float *pIntrin) -{ - int k; - float t = 0; - - for (k=0;k=Q65_LLH_THRESHOLD); -} - -// Full AP decoding from a list of codewords -int q65_decode_fullaplist(q65_codec_ds *codec, - int *ydec, - int *xdec, - const float *pIntrinsics, - const int *pCodewords, - const int nCodewords) -{ - int k; - int nK, nN, nM; - - float llh, maxllh, llh_threshold; - int maxcw = -1; // index of the most likely codeword - const int *pCw; - - if (nCodewords<1 || nCodewords>Q65_FULLAPLIST_SIZE) - return Q65_DECODE_INVPARAMS; // invalid list length - - nK = q65_get_message_length(codec); - nN = q65_get_codeword_length(codec); - nM = q65_get_alphabet_size(codec); - - // we adjust the llh threshold in order to mantain the - // same false decode rate independently from the size - // of the list - llh_threshold = Q65_LLH_THRESHOLD + logf(1.0f*nCodewords/3); - maxllh = llh_threshold; // at least one llh should be larger than the threshold - - // compute codewords log likelihoods and find max - pCw = pCodewords; // start from the first codeword - for (k=0;kmaxllh) { - maxllh = llh; - maxcw = k; - } - // printf("BBB %d %f\n",k,llh); - // point to next codeword - pCw+=nN; - } - - q65_llh=maxllh; // save for Joe's use - - if (maxcw<0) // no llh larger than threshold found - return Q65_DECODE_FAILED; - - pCw = pCodewords+nN*maxcw; - memcpy(ydec,pCw,nN*sizeof(int)); - memcpy(xdec,pCw,nK*sizeof(int)); - - return maxcw; // index to the decoded message (>=0) - -} - - -// helper functions ------------------------------------------------------------- - -int _q65_get_message_length(const qracode *pCode) -{ - // return the actual information message length (in symbols) - // excluding any punctured symbol - - int nMsgLength; - - switch (pCode->type) { - case QRATYPE_NORMAL: - nMsgLength = pCode->K; - break; - case QRATYPE_CRC: - case QRATYPE_CRCPUNCTURED: - // one information symbol of the underlying qra code is reserved for CRC - nMsgLength = pCode->K-1; - break; - case QRATYPE_CRCPUNCTURED2: - // two code information symbols are reserved for CRC - nMsgLength = pCode->K-2; - break; - default: - nMsgLength = -1; - } - - return nMsgLength; -} - -int _q65_get_codeword_length(const qracode *pCode) -{ - // return the actual codeword length (in symbols) - // excluding any punctured symbol - - int nCwLength; - - switch (pCode->type) { - case QRATYPE_NORMAL: - case QRATYPE_CRC: - // no puncturing - nCwLength = pCode->N; - break; - case QRATYPE_CRCPUNCTURED: - // the CRC symbol is punctured - nCwLength = pCode->N-1; - break; - case QRATYPE_CRCPUNCTURED2: - // the two CRC symbols are punctured - nCwLength = pCode->N-2; - break; - default: - nCwLength = -1; - } - - return nCwLength; -} - -float _q65_get_code_rate(const qracode *pCode) -{ - return 1.0f*_q65_get_message_length(pCode)/_q65_get_codeword_length(pCode); -} - -int _q65_get_alphabet_size(const qracode *pCode) -{ - return pCode->M; -} -int _q65_get_bits_per_symbol(const qracode *pCode) -{ - return pCode->m; -} -static void _q65_mask(const qracode *pcode, float *ix, const int *mask, const int *x) -{ - // mask intrinsic information ix with available a priori knowledge - - int k,kk, smask; - const int nM=pcode->M; - const int nm=pcode->m; - int nK; - - // Exclude from masking the symbols which have been punctured. - // nK is the length of the mask and x arrays, which do - // not include any punctured symbol - nK = _q65_get_message_length(pcode); - - // for each symbol set to zero the probability - // of the values which are not allowed by - // the a priori information - - for (k=0;k>1) ^ CRC6_GEN_POL; - else - sr = (sr>>1); - t>>=1; - } - } - - return sr; -} - -static void _q65_crc12(int *y, int *x, int sz) -{ - int k,j,t,sr = 0; - for (k=0;k>1) ^ CRC12_GEN_POL; - else - sr = (sr>>1); - t>>=1; - } - } - - y[0] = sr&0x3F; - y[1] = (sr>>6); -} +// q65.c +// q65 modes encoding/decoding functions +// +// (c) 2020 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#include +#include +#include + +#include "q65.h" +#include "pdmath.h" + +// Minimum codeword loglikelihood for decoding +#define Q65_LLH_THRESHOLD -260.0f + +// This value produce the same WER performance in decode_fullaplist +// #define Q65_LLH_THRESHOLD -262.0f + + +static int _q65_crc6(int *x, int sz); +static void _q65_crc12(int *y, int *x, int sz); + +float q65_llh; + +int q65_init(q65_codec_ds *pCodec, const qracode *pqracode) +{ + // Eb/No value for which we optimize the decoder metric (AWGN/Rayleigh cases) + const float EbNodBMetric = 2.8f; + const float EbNoMetric = (float)pow(10,EbNodBMetric/10); + + float R; // code effective rate (after puncturing) + int nm; // bits per symbol + + if (!pCodec) + return -1; // why do you called me? + + if (!pqracode) + return -2; // invalid qra code + + if (pqracode->M!=64) + return -3; // q65 supports only codes over GF(64) + + pCodec->pQraCode = pqracode; + + // allocate buffers used by encoding/decoding functions + pCodec->x = (int*)malloc(pqracode->K*sizeof(int)); + pCodec->y = (int*)malloc(pqracode->N*sizeof(int)); + pCodec->qra_v2cmsg = (float*)malloc(pqracode->NMSG*pqracode->M*sizeof(float)); + pCodec->qra_c2vmsg = (float*)malloc(pqracode->NMSG*pqracode->M*sizeof(float)); + pCodec->ix = (float*)malloc(pqracode->N*pqracode->M*sizeof(float)); + pCodec->ex = (float*)malloc(pqracode->N*pqracode->M*sizeof(float)); + + if (pCodec->x== NULL || + pCodec->y== NULL || + pCodec->qra_v2cmsg== NULL || + pCodec->qra_c2vmsg== NULL || + pCodec->ix== NULL || + pCodec->ex== NULL) { + q65_free(pCodec); + return -4; // out of memory + } + + // compute and store the AWGN/Rayleigh Es/No ratio for which we optimize + // the decoder metric + nm = _q65_get_bits_per_symbol(pqracode); + R = _q65_get_code_rate(pqracode); + pCodec->decoderEsNoMetric = 1.0f*nm*R*EbNoMetric; + + return 1; +} + +void q65_free(q65_codec_ds *pCodec) +{ + if (!pCodec) + return; + + // free internal buffers + if (pCodec->x!=NULL) + free(pCodec->x); + + if (pCodec->y!=NULL) + free(pCodec->y); + + if (pCodec->qra_v2cmsg!=NULL) + free(pCodec->qra_v2cmsg); + + if (pCodec->qra_c2vmsg!=NULL) + free(pCodec->qra_c2vmsg); + + if (pCodec->ix!=NULL) + free(pCodec->ix); + + if (pCodec->ex!=NULL) + free(pCodec->ex); + + pCodec->pQraCode = NULL; + pCodec->x = NULL; + pCodec->y = NULL; + pCodec->qra_v2cmsg = NULL; + pCodec->qra_c2vmsg = NULL; + pCodec->qra_v2cmsg = NULL; + pCodec->ix = NULL; + pCodec->ex = NULL; + + return; +} + +int q65_encode(const q65_codec_ds *pCodec, int *pOutputCodeword, const int *pInputMsg) +{ + const qracode *pQraCode; + int *px; + int *py; + int nK; + int nN; + + if (!pCodec) + return -1; // which codec? + + pQraCode = pCodec->pQraCode; + px = pCodec->x; + py = pCodec->y; + nK = _q65_get_message_length(pQraCode); + nN = _q65_get_codeword_length(pQraCode); + + // copy the information symbols into the internal buffer + memcpy(px,pInputMsg,nK*sizeof(int)); + + // compute and append the appropriate CRC if required + switch (pQraCode->type) { + case QRATYPE_NORMAL: + break; + case QRATYPE_CRC: + case QRATYPE_CRCPUNCTURED: + px[nK] = _q65_crc6(px,nK); + break; + case QRATYPE_CRCPUNCTURED2: + _q65_crc12(px+nK,px,nK); + break; + default: + return -2; // code type not supported + } + + // encode with the given qra code + qra_encode(pQraCode,py,px); + + // puncture the CRC symbols as required + // and copy the result to the destination buffer + switch (pQraCode->type) { + case QRATYPE_NORMAL: + case QRATYPE_CRC: + // no puncturing + memcpy(pOutputCodeword,py,nN*sizeof(int)); + break; + case QRATYPE_CRCPUNCTURED: + // strip the single CRC symbol from the encoded codeword + memcpy(pOutputCodeword,py,nK*sizeof(int)); // copy the systematic symbols + memcpy(pOutputCodeword+nK,py+nK+1,(nN-nK)*sizeof(int)); // copy the check symbols skipping the CRC symbol + break; + case QRATYPE_CRCPUNCTURED2: + // strip the 2 CRC symbols from the encoded codeword + memcpy(pOutputCodeword,py,nK*sizeof(int)); // copy the systematic symbols + memcpy(pOutputCodeword+nK,py+nK+2,(nN-nK)*sizeof(int)); // copy the check symbols skipping the two CRC symbols + break; + default: + return -2; // code type unsupported + } + + return 1; // ok +} + +int q65_intrinsics(q65_codec_ds *pCodec, float *pIntrinsics, const float *pInputEnergies) +{ + // compute observations intrinsics probabilities + // for the AWGN/Rayleigh channels + + // NOTE: + // A true Rayleigh channel metric would require that the channel gains were known + // for each symbol in the codeword. Such gains cannot be estimated reliably when + // the Es/No ratio is small. Therefore we compute intrinsic probabilities assuming + // that, on average, these channel gains are unitary. + // In general it is even difficult to estimate the Es/No ratio for the AWGN channel + // Therefore we always compute the intrinsic probabilities assuming that the Es/No + // ratio is known and equal to the constant decoderEsNoMetric. This assumption will + // generate the true intrinsic probabilities only when the actual Eb/No ratio is + // equal to this constant. As in all the other cases the probabilities are evaluated + // with a wrong scaling constant we can expect that the decoder performance at different + // Es/No will be worse. Anyway, since the EsNoMetric constant has been chosen so that the + // decoder error rate is about 50%, we obtain almost optimal error rates down to + // any useful Es/No ratio. + + const qracode *pQraCode; + int nN, nBits; + float EsNoMetric; + + if (pCodec==NULL) + return -1; // which codec? + + pQraCode = pCodec->pQraCode; + nN = _q65_get_codeword_length(pQraCode); + nBits = pQraCode->m; + + EsNoMetric = pCodec->decoderEsNoMetric; + qra_mfskbesselmetric(pIntrinsics,pInputEnergies,nBits,nN,EsNoMetric); + + return 1; // success +} + +int q65_esnodb(const q65_codec_ds *pCodec, float *pEsNodB, const int *ydec, const float *pInputEnergies) +{ + // compute average Es/No for the AWGN/Rayleigh channel cases + + int k,j; + float sigplusnoise=0; + float noise=0; + int nN, nM; + const float *pIn = pInputEnergies; + const int *py = ydec; + float EsNodB; + + nN = q65_get_codeword_length(pCodec); + nM = q65_get_alphabet_size(pCodec); + + for (k=0;k4) + return Q65_DECODE_INVPARAMS; // invalid submode + + // As the symbol duration in q65 is different than in QRA64, + // the fading tables continue to be valid if the B90Ts parameter + // is properly scaled to the QRA64 symbol interval + // Compute index to most appropriate weighting function coefficients + B90 = B90Ts/TS_QRA64; + hidx = (int)(logf(B90)/logf(1.09f) - 0.499f); + + // Unlike in QRA64 we accept any B90, anyway limiting it to + // the extreme cases (0.9 to 210 Hz approx.) + if (hidx<0) + hidx = 0; + else + if (hidx > 63) //Changed by K1JT: previously max was 64. + hidx=63; //Changed by K1JT: previously max was 64. + + // select the appropriate weighting fading coefficients array + if (fadingModel==0) { // gaussian fading model + // point to gaussian energy weighting taps + hlen = glen_tab_gauss[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) + hptr = gptr_tab_gauss[hidx]; // pointer to the first (L+1)/2 coefficients of w fun + } + else if (fadingModel==1) { + // point to lorentzian energy weighting taps + hlen = glen_tab_lorentz[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) + hptr = gptr_tab_lorentz[hidx]; // pointer to the first (L+1)/2 coefficients of w fun + } + else + return Q65_DECODE_INVPARAMS; // invalid fading model + + // compute (euristically) the optimal decoder metric accordingly the given spread amount + // We assume that the decoder 50% decoding threshold is: + // Es/No(dB) = Es/No(AWGN)(dB) + 8*log(B90)/log(240)(dB) + // that's to say, at the maximum Doppler spread bandwidth (240 Hz for QRA64) + // there's a ~8 dB Es/No degradation over the AWGN case + fTemp = 8.0f*logf(B90)/logf(240.0f); // assumed Es/No degradation for the given fading bandwidth + EsNoMetric = pCodec->decoderEsNoMetric*powf(10.0f,fTemp/10.0f); + + nM = q65_get_alphabet_size(pCodec); + nN = q65_get_codeword_length(pCodec); + nBinsPerTone = 1<ffNoiseVar = fNoiseVar; + pCodec->ffEsNoMetric = EsNoMetric; + pCodec->nBinsPerTone = nBinsPerTone; + pCodec->nBinsPerSymbol = nBinsPerSymbol; + pCodec->nWeights = hlen; + weight = pCodec->ffWeight; + + // compute the fast fading weights accordingly to the Es/No ratio + // for which we compute the exact intrinsics probabilities + for (k=0;kmaxlogp) // keep track of the max + maxlogp = fTemp; + pCurIx[k]=fTemp; + + pCurBin += nBinsPerTone; // next tone + } + + // exponentiate and accumulate the normalization constant + sumix = 0.0f; + for (k=0;k 85.0) x= 85.0; + fTemp = expf(x); + pCurIx[k]=fTemp; + sumix +=fTemp; + } + + // scale to a probability distribution + sumix = 1.0f/sumix; + for (k=0;knBinsPerTone; + nBinsPerSymbol = pCodec->nBinsPerSymbol; + nWeights = pCodec->nWeights; + ffNoiseVar = pCodec->ffNoiseVar; + ffEsNoMetric = pCodec->ffEsNoMetric; + nTotWeights = 2*nWeights-1; + + // compute symbols energy (noise included) summing the + // energies pertaining to the decoded symbols in the codeword + + EsPlusWNo = 0.0f; + pCurSym = pInputEnergies + nM; // point to first central bin of first symbol tone + for (n=0;npQraCode; + ix = pCodec->ix; + ex = pCodec->ex; + + nK = _q65_get_message_length(pQraCode); + nN = _q65_get_codeword_length(pQraCode); + nM = pQraCode->M; + nBits = pQraCode->m; + + px = pCodec->x; + py = pCodec->y; + + // Depuncture intrinsics observations as required by the code type + switch (pQraCode->type) { + case QRATYPE_CRCPUNCTURED: + memcpy(ix,pIntrinsics,nK*nM*sizeof(float)); // information symbols + pd_init(PD_ROWADDR(ix,nM,nK),pd_uniform(nBits),nM); // crc + memcpy(ix+(nK+1)*nM,pIntrinsics+nK*nM,(nN-nK)*nM*sizeof(float)); // parity checks + break; + case QRATYPE_CRCPUNCTURED2: + memcpy(ix,pIntrinsics,nK*nM*sizeof(float)); // information symbols + pd_init(PD_ROWADDR(ix,nM,nK),pd_uniform(nBits),nM); // crc + pd_init(PD_ROWADDR(ix,nM,nK+1),pd_uniform(nBits),nM); // crc + memcpy(ix+(nK+2)*nM,pIntrinsics+nK*nM,(nN-nK)*nM*sizeof(float)); // parity checks + break; + case QRATYPE_NORMAL: + case QRATYPE_CRC: + default: + // no puncturing + memcpy(ix,pIntrinsics,nN*nM*sizeof(float)); // as they are + } + + // mask the intrinsics with the available a priori knowledge + if (pAPMask!=NULL) + _q65_mask(pQraCode,ix,pAPMask,pAPSymbols); + + + // Compute the extrinsic symbols probabilities with the message-passing algorithm + // Stop if the extrinsics information does not converges to unity + // within the given number of iterations + rc = qra_extrinsic( pQraCode, + ex, + ix, + maxiters, + pCodec->qra_v2cmsg, + pCodec->qra_c2vmsg); + + if (rc<0) + // failed to converge to a solution + return Q65_DECODE_FAILED; + + // decode the information symbols (punctured information symbols included) + qra_mapdecode(pQraCode,px,ex,ix); + + // verify CRC match + + switch (pQraCode->type) { + case QRATYPE_CRC: + case QRATYPE_CRCPUNCTURED: + crc6=_q65_crc6(px,nK); // compute crc-6 + if (crc6!=px[nK]) + return Q65_DECODE_CRCMISMATCH; // crc doesn't match + break; + case QRATYPE_CRCPUNCTURED2: + _q65_crc12(crc12, px,nK); // compute crc-12 + if (crc12[0]!=px[nK] || + crc12[1]!=px[nK+1]) + return Q65_DECODE_CRCMISMATCH; // crc doesn't match + break; + case QRATYPE_NORMAL: + default: + // nothing to check + break; + } + + // copy the decoded msg to the user buffer (excluding punctured symbols) + if (pDecodedMsg) + memcpy(pDecodedMsg,px,nK*sizeof(int)); + +#ifndef Q65_CHECKLLH + if (pDecodedCodeword==NULL) // user is not interested in the decoded codeword + return rc; // return the number of iterations required to decode +#else + if (pDecodedCodeword==NULL) // we must have a buffer + return Q65_DECODE_INVPARAMS; // return error +#endif + + // crc matches therefore we can reconstruct the transmitted codeword + // reencoding the information available in px... + + qra_encode(pQraCode, py, px); + + // ...and strip the punctured symbols from the codeword + switch (pQraCode->type) { + case QRATYPE_CRCPUNCTURED: + memcpy(pDecodedCodeword,py,nK*sizeof(int)); + memcpy(pDecodedCodeword+nK,py+nK+1,(nN-nK)*sizeof(int)); // puncture crc-6 symbol + break; + case QRATYPE_CRCPUNCTURED2: + memcpy(pDecodedCodeword,py,nK*sizeof(int)); + memcpy(pDecodedCodeword+nK,py+nK+2,(nN-nK)*sizeof(int)); // puncture crc-12 symbols + break; + case QRATYPE_CRC: + case QRATYPE_NORMAL: + default: + memcpy(pDecodedCodeword,py,nN*sizeof(int)); // no puncturing + } + +#ifdef Q65_CHECKLLH + if (q65_check_llh(NULL,pDecodedCodeword, nN, nM, pIntrinsics)==0) // llh less than threshold + return Q65_DECODE_LLHLOW; +#endif + + return rc; // return the number of iterations required to decode + +} + + +// Compute and verify the loglikelihood of the decoded codeword +int q65_check_llh(float *llh, const int* ydec, const int nN, const int nM, const float *pIntrin) +{ + int k; + float t = 0; + + for (k=0;k=Q65_LLH_THRESHOLD); +} + +// Full AP decoding from a list of codewords +int q65_decode_fullaplist(q65_codec_ds *codec, + int *ydec, + int *xdec, + const float *pIntrinsics, + const int *pCodewords, + const int nCodewords) +{ + int k; + int nK, nN, nM; + + float llh, maxllh, llh_threshold; + int maxcw = -1; // index of the most likely codeword + const int *pCw; + + if (nCodewords<1 || nCodewords>Q65_FULLAPLIST_SIZE) + return Q65_DECODE_INVPARAMS; // invalid list length + + nK = q65_get_message_length(codec); + nN = q65_get_codeword_length(codec); + nM = q65_get_alphabet_size(codec); + + // we adjust the llh threshold in order to mantain the + // same false decode rate independently from the size + // of the list + llh_threshold = Q65_LLH_THRESHOLD + logf(1.0f*nCodewords/3); + maxllh = llh_threshold; // at least one llh should be larger than the threshold + + // compute codewords log likelihoods and find max + pCw = pCodewords; // start from the first codeword + for (k=0;kmaxllh) { + maxllh = llh; + maxcw = k; + } + // printf("BBB %d %f\n",k,llh); + // point to next codeword + pCw+=nN; + } + + q65_llh=maxllh; // save for Joe's use + + if (maxcw<0) // no llh larger than threshold found + return Q65_DECODE_FAILED; + + pCw = pCodewords+nN*maxcw; + memcpy(ydec,pCw,nN*sizeof(int)); + memcpy(xdec,pCw,nK*sizeof(int)); + + return maxcw; // index to the decoded message (>=0) + +} + + +// helper functions ------------------------------------------------------------- + +int _q65_get_message_length(const qracode *pCode) +{ + // return the actual information message length (in symbols) + // excluding any punctured symbol + + int nMsgLength; + + switch (pCode->type) { + case QRATYPE_NORMAL: + nMsgLength = pCode->K; + break; + case QRATYPE_CRC: + case QRATYPE_CRCPUNCTURED: + // one information symbol of the underlying qra code is reserved for CRC + nMsgLength = pCode->K-1; + break; + case QRATYPE_CRCPUNCTURED2: + // two code information symbols are reserved for CRC + nMsgLength = pCode->K-2; + break; + default: + nMsgLength = -1; + } + + return nMsgLength; +} + +int _q65_get_codeword_length(const qracode *pCode) +{ + // return the actual codeword length (in symbols) + // excluding any punctured symbol + + int nCwLength; + + switch (pCode->type) { + case QRATYPE_NORMAL: + case QRATYPE_CRC: + // no puncturing + nCwLength = pCode->N; + break; + case QRATYPE_CRCPUNCTURED: + // the CRC symbol is punctured + nCwLength = pCode->N-1; + break; + case QRATYPE_CRCPUNCTURED2: + // the two CRC symbols are punctured + nCwLength = pCode->N-2; + break; + default: + nCwLength = -1; + } + + return nCwLength; +} + +float _q65_get_code_rate(const qracode *pCode) +{ + return 1.0f*_q65_get_message_length(pCode)/_q65_get_codeword_length(pCode); +} + +int _q65_get_alphabet_size(const qracode *pCode) +{ + return pCode->M; +} +int _q65_get_bits_per_symbol(const qracode *pCode) +{ + return pCode->m; +} +static void _q65_mask(const qracode *pcode, float *ix, const int *mask, const int *x) +{ + // mask intrinsic information ix with available a priori knowledge + + int k,kk, smask; + const int nM=pcode->M; + const int nm=pcode->m; + int nK; + + // Exclude from masking the symbols which have been punctured. + // nK is the length of the mask and x arrays, which do + // not include any punctured symbol + nK = _q65_get_message_length(pcode); + + // for each symbol set to zero the probability + // of the values which are not allowed by + // the a priori information + + for (k=0;k>1) ^ CRC6_GEN_POL; + else + sr = (sr>>1); + t>>=1; + } + } + + return sr; +} + +static void _q65_crc12(int *y, int *x, int sz) +{ + int k,j,t,sr = 0; + for (k=0;k>1) ^ CRC12_GEN_POL; + else + sr = (sr>>1); + t>>=1; + } + } + + y[0] = sr&0x3F; + y[1] = (sr>>6); +} diff --git a/lib/qra/q65/q65.f90 b/lib/qra/q65/q65.f90 index fa5c6abf..f93fca50 100755 --- a/lib/qra/q65/q65.f90 +++ b/lib/qra/q65/q65.f90 @@ -1,912 +1,912 @@ -module q65 - - parameter (NSTEP=8) !Number of time bins per symbol in s1, s1a, s1b - parameter (PLOG_MIN=-242.0) !List decoding threshold - integer iz0,jz0 -! integer listutc(10) - integer apsym0(58),aph10(10) - integer apmask1(78),apsymbols1(78) - integer apmask(13),apsymbols(13) - integer,dimension(22) :: isync = (/1,9,12,13,15,22,23,26,27,33,35, & - 38,46,50,55,60,62,66,69,74,76,85/) - integer codewords(63,206) - integer ibwa,ibwb,ncw,nsps,mode_q65,nfa,nfb,nqd - integer idfbest,idtbest,ibw,ndistbest,maxiters,max_drift - integer istep,nsmo,lag1,lag2,npasses,iseq,ncand,nrc - integer i0,j0 - integer navg(0:1) - logical lnewdat - real candidates(20,3) !snr, xdt, and f0 of top candidates - real, allocatable :: s1(:,:) !Symbol spectra w/suppressed peaks - real, allocatable :: s1w(:,:) !Symbol spectra w/suppressed peaks (W3SZ) - real, allocatable,save :: s1a(:,:,:) !Cumulative symbol spectra - real, allocatable,save :: ccf2(:) !Max CCF(freq) at any lag (orange curve) - real, allocatable,save :: ccf2_avg(:) !Like ccf2, but for avg (red curve) - real sync(85) !sync vector - real df,dtstep,dtdec,f0dec,ftol,plog,drift - -contains - -subroutine q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, & - emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) - -! Top-level routine in q65 module -! - Compute symbol spectra -! - Attempt sync and q3 decode using all 85 symbols -! - If that fails, try sync with 22 symbols and standard q[0124] decode - -! Input: iavg 0 for single-period decode, 1 for average -! iwave(0:nmax-1) Raw data -! ntrperiod T/R sequence length (s) -! nfqso Target frequency (Hz) -! ntol Search range around nfqso (Hz) -! lclearave Flag to clear the accumulating array -! emedelay Extra delay for EME signals -! Output: xdt Time offset from nominal (s) -! f0 Frequency of sync tone -! snr1 Relative SNR of sync signal -! width Estimated Doppler spread -! dat4(13) Decoded message as 13 six-bit integers -! snr2 Estimated SNR of decoded signal -! idec Flag for decoding results -! -1 No decode -! 0 No AP -! 1 "CQ ? ?" -! 2 "Mycall ? ?" -! 3 "MyCall HisCall ?" - - use packjt77 - use timer_module, only: timer - - parameter (LN=2176*63) !LN=LL*NN; LL=64*(mode_q65+2), NN=63 - integer*2 iwave(0:12000*ntrperiod-1) !Raw data - integer dat4(13) - character*37 decoded - logical first,lclearave - real, allocatable :: s3(:,:) !Data-symbol energies s3(LL,63) - real, allocatable :: ccf1(:) !CCF(freq) at fixed lag (red) - data first/.true./ - save first,LL0 - - integer w3t - integer w3f - integer mm - integer stageno - - NN=63 - -! Set some parameters and allocate storage for large arrays - irc=-2 - nrc=-2 - idec=-1 - snr1=0. - dat4=0 - LL=64*(2+mode_q65) - nfft=nsps - df=12000.0/nfft !Freq resolution = baud - istep=nsps/NSTEP - iz=5000.0/df !Uppermost frequency bin, at 5000 Hz - txt=85.0*nsps/12000.0 - jz=(txt+1.0)*12000.0/istep !Number of symbol/NSTEP bins - if(nsps.ge.6912) jz=(txt+2.0)*12000.0/istep !For TR 60 s and higher - ftol=ntol - ia=ntol/df - ia2=max(ia,10*mode_q65,nint(100.0/df)) -! nsmo=int(0.7*mode_q65*mode_q65) - nsmo=int(0.5*mode_q65*mode_q65) - if(nsmo.lt.1) nsmo=1 - if(first) then !Generate the sync vector - sync=-22.0/63.0 !Sync tone OFF - do k=1,22 - sync(isync(k))=1.0 !Sync tone ON - enddo - endif - - allocate(s3(-64:LL-65,63)) - allocate(ccf1(-ia2:ia2)) - if(LL.ne.LL0 .or. iz.ne.iz0 .or. jz.ne.jz0 .or. lclearave) then - if(allocated(s1)) deallocate(s1) - allocate(s1(iz,jz)) - if(allocated(s1a)) deallocate(s1a) - allocate(s1a(iz,jz,0:1)) - if(allocated(ccf2)) deallocate(ccf2) - allocate(ccf2(iz)) - if(allocated(ccf2_avg)) deallocate(ccf2_avg) - allocate(ccf2_avg(iz)) - s1=0. - s1a=0. - navg=0 - LL0=LL - iz0=iz - jz0=jz - lclearave=.false. - endif - ccf1=0. - if(iavg.eq.0) ccf2=0. - dtstep=nsps/(NSTEP*12000.0) !Step size in seconds - lag1=-1.0/dtstep - lag2=1.0/dtstep + 0.9999 - if(nsps.ge.3600 .and. emedelay.gt.0) lag2=5.5/dtstep + 0.9999 !Include EME - j0=0.5/dtstep - if(nsps.ge.7200) j0=1.0/dtstep !Nominal start-signal index - - s3=0. -! if(iavg.eq.0 .and. lnewdat) then - if(iavg.eq.0) then - call timer('q65_syms',0) -! Compute symbol spectra with NSTEP time bins per symbol - call q65_symspec(iwave,ntrperiod*12000,iz,jz,s1) - call timer('q65_syms',1) -! lnewdat=.false. - else - s1=s1a(:,:,iseq) - endif - - i0=nint(nfqso/df) !Target QSO frequency - dat4=0 - if(ncw.gt.0 .and. iavg.le.1) then -! Try list decoding via "Deep Likelihood". - call timer('ccf_85 ',0) -! Try to synchronize using all 85 symbols - call q65_ccf_85(s1,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best, & - better,ccf1) - call timer('ccf_85 ',1) - - if(better.ge.1.10 .or. mode_q65.ge.8) then - call timer('list_dec',0) - call q65_dec_q3(s1,iz,jz,s3,LL,ipk,jpk,snr2,dat4,idec,decoded) - call timer('list_dec',1) - endif -! If idec=3 we have a q3 decode. Continue to compute sync curve for plotting. - endif - -! Get 2d CCF and ccf2 using sync symbols only - if(iavg.eq.0) then - call timer('ccf_22a ',0) - call q65_ccf_22(s1,iz,jz,nfqso,ntol,iavg,ipk,jpk, & - f0a,xdta,ccf2) - call timer('ccf_22a ',1) - endif - -! Get 2d CCF and ccf2_avg using sync symbols only - if(iavg.ge.1) then - call timer('ccf_22b ',0) - call q65_ccf_22(s1,iz,jz,nfqso,ntol,iavg,ipk,jpk, & - f0a,xdta,ccf2_avg) - call timer('ccf_22b ',1) - endif - if(idec.lt.0) then - f0=f0a - xdt=xdta - endif - -! Estimate rms on ccf2 baseline - call q65_sync_curve(ccf2,1,iz,rms2) - smax=maxval(ccf2) - snr1=0. - if(rms2.gt.0) snr1=smax/rms2 - - if(idec.le.0) then -! The q3 decode attempt failed. Copy synchronized symbol energies from s1 -! into s3 and prepare to try a more general decode. - call q65_s1_to_s3(s1,iz,jz,ipk,jpk,LL,mode_q65,sync,s3) - endif - - smax=maxval(ccf1) - -! Estimate frequency spread - i1=-9999 - i2=-9999 - do i=-ia,ia - if(i1.eq.-9999 .and. ccf1(i).ge.0.5*smax) i1=i - if(i2.eq.-9999 .and. ccf1(-i).ge.0.5*smax) i2=-i - enddo - width=df*(i2-i1) - if(ncw.eq.0) ccf1=0. - call q65_write_red(iz,xdt,ccf2_avg,ccf2) !### Need this call for WSJT-X - - if(idec.lt.0 .and. (iavg.eq.0 .or. iavg.eq.2)) then - call q65_dec_q012(s3,LL,snr2,dat4,idec,decoded) - endif - - if(idec.lt.0 .and. max_drift.eq.50 .and. stageno.eq.5) then - - if(allocated(s1w)) deallocate(s1w) ! w3sz - allocate(s1w(iz,jz)) ! w3sz - - s1w=s1 - do w3t=1,jz - do w3f=1,iz - mm=w3f + nint(drift*w3t/(jz*df)) - if(mm.ge.1 .and. mm.le.iz) then - s1w(w3f,w3t)=s1(mm,w3t) - endif - end do - end do - - if(ncw.gt.0 .and. iavg.le.1) then - ! Try list decoding via "Deep Likelihood". - call timer('ccf_85 ',0) - ! Try to synchronize using all 85 symbols - call q65_ccf_85(s1w,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best, & - better,ccf1) - call timer('ccf_85 ',1) - -! nsubmode is Tone-spacing indicator, 0-4 for A-E: a 0; b 1; c 2; d 3; e 4. -! and mode_q65=2**nsubmode - if(better.ge.1.10) then - ! if(better.ge.1.04 .or. mode_q65.ge.8) then - ! if(better.ge.1.10 .or. mode_q65.ge.8) then ORIGINAL - call timer('list_dec',0) - call q65_dec_q3(s1w,iz,jz,s3,LL,ipk,jpk,snr2,dat4,idec,decoded) - call timer('list_dec',1) - endif ! if(better.ge.1.10) - endif ! if(ncw.gt.0 .and. iavg.le.1) - ! If idec=3 we have a q3 decode. Continue to compute sync curve for plotting. - - if(idec.eq.3) then - idec=5 - endif - - endif ! if(idec.lt.0 .and. max_drift.eq.50 .and. stageno.eq.5) - - return -end subroutine q65_dec0 - -subroutine q65_clravg - -! Clear the averaging array to start a new average. - - if(allocated(s1a)) s1a(:,:,iseq)=0. - navg(iseq)=0 - - return -end subroutine q65_clravg - -subroutine q65_symspec(iwave,nmax,iz,jz,s1) - -! Compute symbol spectra with NSTEP time-steps per symbol. - - integer*2 iwave(0:nmax-1) !Raw data - real s1(iz,jz) - complex, allocatable :: c0(:) !Complex spectrum of symbol - - allocate(c0(0:nsps-1)) - nfft=nsps - fac=1/32767.0 - do j=1,jz,2 !Compute symbol spectra at 2*step size - i1=(j-1)*istep - i2=i1+nsps-1 - k=-1 - do i=i1,i2,2 !Load iwave data into complex array c0, for r2c FFT - xx=iwave(i) - yy=iwave(i+1) - k=k+1 - c0(k)=fac*cmplx(xx,yy) - enddo - c0(k+1:)=0. - call four2a(c0,nfft,1,-1,0) !r2c FFT - do i=1,iz - s1(i,j)=real(c0(i))**2 + aimag(c0(i))**2 - enddo -! For large Doppler spreads, should we smooth the spectra here? - if(nsmo.le.1) nsmo=0 - do i=1,nsmo - call smo121(s1(1:iz,j),iz) - enddo -! Interpolate to fill in the skipped-over spectra. - if(j.ge.3) s1(1:iz,j-1)=0.5*(s1(1:iz,j-2)+s1(1:iz,j)) - enddo - if(lnewdat) then - navg(iseq)=navg(iseq) + 1 - ntc=min(navg(iseq),4) !Averaging time constant in sequences - u=1.0/ntc - s1a(:,:,iseq)=u*s1 + (1.0-u)*s1a(:,:,iseq) - endif - - return -end subroutine q65_symspec - -subroutine q65_dec_q3(s1,iz,jz,s3,LL,ipk,jpk,snr2,dat4,idec,decoded) - -! Copy synchronized symbol energies from s1 into s3, then attempt a q3 decode. - - character*37 decoded - integer dat4(13) - real s1(iz,jz) - real s3(-64:LL-65,63) - - call q65_s1_to_s3(s1,iz,jz,ipk,jpk,LL,mode_q65,sync,s3) - - nsubmode=0 - if(mode_q65.eq.2) nsubmode=1 - if(mode_q65.eq.4) nsubmode=2 - if(mode_q65.eq.8) nsubmode=3 - if(mode_q65.eq.16) nsubmode=4 - if(mode_q65.eq.32) nsubmode=5 - baud=12000.0/nsps - - do ibw=ibwa,ibwb - b90=1.72**ibw - b90ts=b90/baud - call q65_dec1(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) - nrc=irc - if(irc.ge.0) then - snr2=esnodb - db(2500.0/baud) + 3.0 !Empirical adjustment - idec=3 - exit - endif - enddo - - return -end subroutine q65_dec_q3 - -subroutine q65_dec_q012(s3,LL,snr2,dat4,idec,decoded) - -! Do separate passes attempting q0, q1, q2 decodes. - - character*37 decoded - character*78 c78 - integer dat4(13) - real s3(-64:LL-65,63) - logical lapcqonly - - nsubmode=0 - if(mode_q65.eq.2) nsubmode=1 - if(mode_q65.eq.4) nsubmode=2 - if(mode_q65.eq.8) nsubmode=3 - if(mode_q65.eq.16) nsubmode=4 - - baud=12000.0/nsps - iaptype=0 - nQSOprogress=0 !### TEMPORARY ? ### - ncontest=0 - lapcqonly=.false. - - do ipass=0,npasses !Loop over AP passes - apmask=0 !Try first with no AP information - apsymbols=0 - if(ipass.ge.1) then - ! Subsequent passes use AP information appropiate for nQSOprogress - call q65_ap(nQSOprogress,ipass,ncontest,lapcqonly,iaptype, & - apsym0,apmask1,apsymbols1) - write(c78,1050) apmask1 -1050 format(78i1) - read(c78,1060) apmask -1060 format(13b6.6) - write(c78,1050) apsymbols1 - read(c78,1060) apsymbols - endif - - do ibw=ibwa,ibwb - b90=1.72**ibw - b90ts=b90/baud - call q65_dec2(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) - nrc=irc - if(irc.ge.0) then - snr2=esnodb - db(2500.0/baud) + 3.0 !Empirical adjustment - idec=iaptype - go to 100 - endif - enddo - enddo - -100 return -end subroutine q65_dec_q012 - -subroutine q65_ccf_85(s1,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best, & - better,ccf1) - -! Attempt synchronization using all 85 symbols, in advance of an -! attempt at q3 decoding. Return ccf1 for the "red sync curve". - - real s1(iz,jz) - real, allocatable :: ccf(:,:) !CCF(freq,lag) - real, allocatable :: best(:) !best(imsg) -- for checking 2nd best - real ccf1(-ia2:ia2) - integer ijpk(2) - integer itone(85) - - allocate(ccf(-ia2:ia2,-53:214)) - allocate(best(ncw)) - ipk=0 - jpk=0 - ccf_best=0. - imsg_best=-1 - do imsg=1,ncw - i=1 - k=0 - do j=1,85 - if(j.eq.isync(i)) then - i=i+1 - itone(j)=0 - else - k=k+1 - itone(j)=codewords(k,imsg) + 1 - endif - enddo - -! Compute 2D ccf using all 85 symbols in the list message - ccf=0. - iia=200.0/df - - do lag=lag1,lag2 - do k=1,85 - j=j0 + NSTEP*(k-1) + 1 + lag - if(j.ge.1 .and. j.le.jz) then - do i=-ia2,ia2 - ii=i0+mode_q65*itone(k)+i - if(ii.ge.iia .and. ii.le.iz) ccf(i,lag)=ccf(i,lag) + s1(ii,j) - enddo - endif - enddo - enddo - - ccfmax=maxval(ccf(-ia:ia,:)) - if(ccfmax.gt.ccf_best) then - ccf_best=ccfmax - ijpk=maxloc(ccf(-ia:ia,:)) - ipk=ijpk(1)-ia-1 - jpk=ijpk(2)-53-1 - f0=nfqso + ipk*df - xdt=jpk*dtstep - imsg_best=imsg - ccf1=ccf(:,jpk) - endif - best(imsg)=ccfmax - enddo ! imsg - - deallocate(ccf) - better=0. - if(imsg_best.gt.0) then - best(imsg_best)=0. - better=ccf_best/maxval(best) - endif - - return -end subroutine q65_ccf_85 - -subroutine q65_ccf_22(s1,iz,jz,nfqso,ntol,iavg,ipk,jpk, & - f0,xdt,ccf2) - -! Attempt synchronization using only the 22 sync symbols. Return ccf2 -! for the "orange sync curve". - - real s1(iz,jz) - real ccf2(iz) !Orange sync curve - real tmp(20,3) - real, allocatable :: xdt2(:) - real, allocatable :: s1avg(:) - integer, allocatable :: indx(:) - - allocate(xdt2(iz)) - allocate(s1avg(iz)) - allocate(indx(iz)) - - ia=max(nfa,100)/df - ib=min(nfb,4900)/df -! if(nqd.ne.1 .or. iavg.ne.0) max_drift=0 !### Disabled March 22, 2023 - if(max_drift.ne.0) then - ia=max(nint(100/df),nint((nfqso-ntol)/df)) - ib=min(nint(4900/df),nint((nfqso+ntol)/df)) - endif - if(ia.ge.ib) ia=ib-ntol/df !Protect against wacky settings - - do i=ia,ib - s1avg(i)=sum(s1(i,1:jz)) - enddo - - ccfbest=0. - ibest=0 - lagpk=0 - lagbest=0 - idrift_max=0 - idrift_best=0 - - do i=ia,ib - ccfmax=0. - do lag=lag1,lag2 - do idrift=-max_drift,max_drift - ccft=0. - do kk=1,22 - k=isync(kk) - ii=i + nint(idrift*(k-43)/85.0) - if(ii.lt.1 .or. ii.gt.iz) cycle - n=NSTEP*(k-1) + 1 - j=n+lag+j0 - if(j.ge.1 .and. j.le.jz) ccft=ccft + s1(ii,j) - enddo ! kk - ccft=ccft - (22.0/jz)*s1avg(i) - if(ccft.gt.ccfmax) then - ccfmax=ccft - lagpk=lag - idrift_max=idrift - endif - enddo ! idrift - enddo ! lag - - ccf2(i)=ccfmax - xdt2(i)=lagpk*dtstep - - if(ccfmax.gt.ccfbest .and. abs(i*df-nfqso).le.ftol) then - ccfbest=ccfmax - snrbest=snr - ibest=i - lagbest=lagpk - idrift_best=idrift_max - endif - enddo ! i - -! Parameters for the top candidate: - ipk=ibest - i0 - jpk=lagbest - f0=nfqso + ipk*df - xdt=jpk*dtstep - drift=df*idrift_best - ccf2(:ia)=0. - ccf2(ib:)=0. - -! Save parameters for best candidates - jzz=ib-ia+1 - call indexx(ccf2(ia:ib),jzz,indx) - - call pctile(ccf2(ia:ib),jzz,50,ave) - call pctile(ccf2(ia:ib),jzz,84,base) - rms=base-ave - ncand=0 - maxcand=20 - do j=1,20 - k=jzz-j+1 - if(k.lt.1 .or. k.gt.iz) cycle - i=indx(k)+ia-1 - f=i*df - i3=max(1, i-mode_q65) - i4=min(iz,i+mode_q65) - biggest=maxval(ccf2(i3:i4)) - if(ccf2(i).ne.biggest) cycle - snr=(ccf2(i)-ave)/rms - if(snr.lt.6.0) exit - ncand=ncand+1 - candidates(ncand,1)=snr - candidates(ncand,2)=xdt2(i) - candidates(ncand,3)=f - if(ncand.ge.maxcand) exit - enddo - -! Resort the candidates back into frequency order - tmp(1:ncand,1:3)=candidates(1:ncand,1:3) - candidates=0. - call indexx(tmp(1:ncand,3),ncand,indx) - do i=1,ncand - candidates(i,1:3)=tmp(indx(i),1:3) - enddo - - return -end subroutine q65_ccf_22 - -subroutine q65_dec1(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) - -! Attmpt a full-AP list decode. - - use packjt77 - real s3(1,1) !Silence compiler warning that wants to see a 2D array - real s3prob(0:63,63) !Symbol-value probabilities - integer dat4(13) - character c77*77,decoded*37 - logical unpk77_success - - nFadingModel=1 - decoded=' ' - call q65_intrinsics_ff(s3,nsubmode,b90ts,nFadingModel,s3prob) - call q65_dec_fullaplist(s3,s3prob,codewords,ncw,esnodb,dat4,plog,irc) - if(sum(dat4).le.0) irc=-2 - if(irc.ge.0 .and. plog.gt.PLOG_MIN) then - write(c77,1000) dat4(1:12),dat4(13)/2 -1000 format(12b6.6,b5.5) - call unpack77(c77,0,decoded,unpk77_success) !Unpack to get msgsent - else - irc=-1 - endif - nrc=irc - - return -end subroutine q65_dec1 - -subroutine q65_dec2(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) - -! Attempt a q0, q1, or q2 decode using spcified AP information. - - use packjt77 - real s3(iz0,jz0) !Silence compiler warning that wants to see a 2D array - real s3prob(0:63,63) !Symbol-value probabilities - integer dat4(13) - character c77*77,decoded*37 - logical unpk77_success - - nFadingModel=1 - decoded=' ' - call q65_intrinsics_ff(s3,nsubmode,b90ts,nFadingModel,s3prob) - call q65_dec(s3,s3prob,APmask,APsymbols,maxiters,esnodb,dat4,irc) - if(sum(dat4).le.0) irc=-2 - nrc=irc - if(irc.ge.0) then - write(c77,1000) dat4(1:12),dat4(13)/2 -1000 format(12b6.6,b5.5) - call unpack77(c77,0,decoded,unpk77_success) !Unpack to get msgsent - endif - - return -end subroutine q65_dec2 - -subroutine q65_s1_to_s3(s1,iz,jz,ipk,jpk,LL,mode_q65,sync,s3) - -! Copy synchronized symbol energies from s1 (or s1a) into s3. - - real s1(iz,jz) - real s3(-64:LL-65,63) - real sync(85) !sync vector - - i1=i0+ipk-64 + mode_q65 - i2=i1+LL-1 - if(i1.ge.1 .and. i2.le.iz) then - j=j0+jpk-7 - n=0 - do k=1,85 - j=j+8 - if(sync(k).gt.0.0) then - cycle - endif - n=n+1 - if(j.ge.1 .and. j.le.jz) s3(-64:LL-65,n)=s1(i1:i2,j) - enddo - endif - call q65_bzap(s3,LL) !Zap birdies - - return -end subroutine q65_s1_to_s3 - -subroutine q65_write_red(iz,xdt,ccf2_avg,ccf2) - -! Write data for the red and orange sync curves to LU 17. - - real ccf2_avg(iz) - real ccf2(iz) - - call q65_sync_curve(ccf2_avg,1,iz,rms1) - call q65_sync_curve(ccf2,1,iz,rms2) - - i1=max(1,nint(nfa/df)) - i2=min(iz,int(nfb/df)) - y0=minval(ccf2(i1:i2)) - y0_avg=minval(ccf2_avg(i1:i2)) - g=0.4 - g_avg=0. - if(navg(iseq).ge.2) g_avg=g - rewind 17 - write(17,1000) xdt,g_avg*minval(ccf2_avg),g_avg*maxval(ccf2_avg) - do i=i1,i2 - freq=i*df - y1=g_avg*(ccf2_avg(i)-y0_avg) - y2=g*(ccf2(i)-y0) - write(17,1000) freq,y1,y2 -1000 format(f10.3,2f15.6) - enddo - flush(17) - - return -end subroutine q65_write_red - -subroutine q65_sync_curve(ccf1,ia,ib,rms1) - -! Condition the red or orange sync curve for plotting. - - real ccf1(ia:ib) - - ic=(ib-ia)/8; - nsum=2*(ic+1) - - base1=(sum(ccf1(ia:ia+ic)) + sum(ccf1(ib-ic:ib)))/nsum - ccf1=ccf1-base1 - sq=dot_product(ccf1(ia:ia+ic),ccf1(ia:ia+ic)) + & - dot_product(ccf1(ib-ic:ib),ccf1(ib-ic:ib)) - rms1=0. - if(nsum.gt.0) rms1=sqrt(sq/nsum) - if(rms1.gt.0.0) ccf1=ccf1/rms1 -! smax1=maxval(ccf1) -! if(smax1.gt.10.0) ccf1=10.0*ccf1/smax1 - - return -end subroutine q65_sync_curve - -subroutine q65_bzap(s3,LL) - - parameter (NBZAP=15) - real s3(-64:LL-65,63) - integer ipk1(1) - integer, allocatable :: hist(:) - - allocate(hist(-64:LL-65)) - hist=0 - do j=1,63 - ipk1=maxloc(s3(:,j)) - i=ipk1(1) - 65 - hist(i)=hist(i)+1 - enddo - if(maxval(hist).gt.NBZAP) then - do i=-64,LL-65 - if(hist(i).gt.NBZAP) s3(i,1:63)=1.0 - enddo - endif - - return -end subroutine q65_bzap - -subroutine q65_snr(dat4,dtdec,f0dec,mode_q65,snr2) - -! Estimate SNR of a decoded transmission by aligning the spectra of -! all 85 symbols. - - integer dat4(13) - integer codeword(63) - integer itone(85) - real, allocatable :: spec(:) - - allocate(spec(iz0)) - call q65_enc(dat4,codeword) - i=1 - k=0 - do j=1,85 - if(j.eq.isync(i)) then - i=i+1 - itone(j)=0 - else - k=k+1 - itone(j)=codeword(k) + 1 - endif - enddo - - spec=0. - lagpk=nint(dtdec/dtstep) - do k=1,85 - j=j0 + NSTEP*(k-1) + 1 + lagpk - if(j.ge.1 .and. j.le.jz0) then - do i=1,iz0 - ii=i+mode_q65*itone(k) - if(ii.ge.1 .and. ii.le.iz0) spec(i)=spec(i) + s1(ii,j) - enddo - endif - enddo - - i0=nint(f0dec/df) - nsum=max(10*mode_q65,nint(50.0/df)) - ia=max(1,i0-2*nsum) - ib=min(iz0,i0+2*nsum) - sum1=sum(spec(ia:ia+nsum-1)) - sum2=sum(spec(ib-nsum+1:ib)) - avg=(sum1+sum2)/(2.0*nsum) - spec=spec/avg !Baseline level is now 1.0 - smax=maxval(spec(ia:ib)) - sig_area=sum(spec(ia+nsum:ib-nsum)-1.0) - w_equiv=sig_area/(smax-1.0) - snr2=db(max(1.0,sig_area)) - db(2500.0/df) - - return -end subroutine q65_snr - -subroutine q65_hist(if0,msg0,dxcall,dxgrid) - -! Save the MAXHIST most receent decodes, and their f0 values; or, if -! dxcall is present, look up the most recent dxcall and dxgrid at the -! specified f0. - - parameter (MAXHIST=100) - integer,intent(in) :: if0 !Audio freq of decode - character(len=37),intent(in),optional :: msg0 !Decoded message - character(len=12),intent(out),optional :: dxcall !Second callsign in message - character(len=6),intent(out),optional :: dxgrid !Third word in msg, if grid - - character*6 g1 - character*37 msg(MAXHIST) !Saved messages - integer nf0(MAXHIST) !Saved frequencies - logical isgrid !Statement function - data nhist/0/ - save nhist,nf0,msg - - isgrid(g1)=g1(1:1).ge.'A' .and. g1(1:1).le.'R' .and. g1(2:2).ge.'A' .and. & - g1(2:2).le.'R' .and. g1(3:3).ge.'0' .and. g1(3:3).le.'9' .and. & - g1(4:4).ge.'0' .and. g1(4:4).le.'9' .and. g1(1:4).ne.'RR73' - - if(present(dxcall)) go to 100 !This is a lookup request - - if(nhist.eq.MAXHIST) then - nf0(1:MAXHIST-1)=nf0(2:MAXHIST) !List is full, must make room - msg(1:MAXHIST-1)=msg(2:MAXHIST) - nhist=MAXHIST-1 - endif - nhist=nhist+1 !Insert msg0 at end of list - nf0(nhist)=if0 - msg(nhist)=msg0 - go to 900 - -100 if(dxcall(1:3).ne.' ') go to 900 - dxcall=' ' !This is a lookup request - dxgrid=' ' -! Look for a decode close to if0, starting with most recent ones - do i=nhist,1,-1 - if(abs(nf0(i)-if0).gt.10) cycle - i1=index(msg(i),' ') - if(i1.ge.4 .and. i1.le.13) then - i2=index(msg(i)(i1+1:),' ') + i1 - dxcall=msg(i)(i1+1:i2-1) !Extract dxcall - g1=msg(i)(i2+1:i2+4) - if(isgrid(g1)) dxgrid=g1(1:4) !Extract dxgrid - exit - endif - enddo - -900 return -end subroutine q65_hist - -subroutine q65_hist2(nfreq,msg0,callers,nhist2) - - use types - use prog_args - parameter (MAX_CALLERS=40) !For multiple q3 decodes in NA VHf Contest mode - character*37 msg0,msg - type(q3list) callers(MAX_CALLERS) - character*6 c6 - character*4 g4 - logical newcall,isgrid - - isgrid(g4)=g4(1:1).ge.'A' .and. g4(1:1).le.'R' .and. g4(2:2).ge.'A' .and. & - g4(2:2).le.'R' .and. g4(3:3).ge.'0' .and. g4(3:3).le.'9' .and. & - g4(4:4).ge.'0' .and. g4(4:4).le.'9' .and. g4(1:4).ne.'RR73' - - msg=msg0 - if(index(msg,'/').gt.0) goto 900 !Ignore messages with compound calls - i0=index(msg,' R ') - if(i0.ge.7) msg=msg(1:i0)//msg(i0+3:) - i1=index(msg,' ') - c6=' ' - g4=' ' - if(i1.ge.4 .and. i1.le.13) then - i2=index(msg(i1+1:),' ') + i1 - c6=msg(i1+1:i2-1) !Extract DX call - g4=msg(i2+1:i2+4) !Extract DX grid - endif - - newcall=.true. - do i=1,nhist2 - if(callers(i)%call .eq. c6) then - newcall=.false. - callers(i)%nsec=time() - callers(i)%nfreq=nfreq - exit - endif - enddo - - if(newcall .and. isgrid(g4)) then - if(nhist2.eq.MAX_CALLERS) then -! Purge the oldest caller - callers(1:MAX_CALLERS-1)=callers(2:MAX_CALLERS) - nhist2=nhist2-1 - endif - nhist2=nhist2+1 - callers(nhist2)%call=c6 - callers(nhist2)%grid=g4 - callers(nhist2)%nsec=time() - callers(nhist2)%nfreq=nfreq - endif - - if(nhist2.ge.1 .and. nhist2.le.40) then - open(24,file=trim(data_dir)//'/tsil.3q',status='unknown', & - form='unformatted') - write(24) nhist2 - write(24) callers(1:nhist2) - close(24) - endif - -900 return -end subroutine q65_hist2 - -end module q65 +module q65 + + parameter (NSTEP=8) !Number of time bins per symbol in s1, s1a, s1b + parameter (PLOG_MIN=-242.0) !List decoding threshold + integer iz0,jz0 +! integer listutc(10) + integer apsym0(58),aph10(10) + integer apmask1(78),apsymbols1(78) + integer apmask(13),apsymbols(13) + integer,dimension(22) :: isync = (/1,9,12,13,15,22,23,26,27,33,35, & + 38,46,50,55,60,62,66,69,74,76,85/) + integer codewords(63,206) + integer ibwa,ibwb,ncw,nsps,mode_q65,nfa,nfb,nqd + integer idfbest,idtbest,ibw,ndistbest,maxiters,max_drift + integer istep,nsmo,lag1,lag2,npasses,iseq,ncand,nrc + integer i0,j0 + integer navg(0:1) + logical lnewdat + real candidates(20,3) !snr, xdt, and f0 of top candidates + real, allocatable :: s1(:,:) !Symbol spectra w/suppressed peaks + real, allocatable :: s1w(:,:) !Symbol spectra w/suppressed peaks (W3SZ) + real, allocatable,save :: s1a(:,:,:) !Cumulative symbol spectra + real, allocatable,save :: ccf2(:) !Max CCF(freq) at any lag (orange curve) + real, allocatable,save :: ccf2_avg(:) !Like ccf2, but for avg (red curve) + real sync(85) !sync vector + real df,dtstep,dtdec,f0dec,ftol,plog,drift + +contains + +subroutine q65_dec0(iavg,iwave,ntrperiod,nfqso,ntol,lclearave, & + emedelay,xdt,f0,snr1,width,dat4,snr2,idec,stageno) + +! Top-level routine in q65 module +! - Compute symbol spectra +! - Attempt sync and q3 decode using all 85 symbols +! - If that fails, try sync with 22 symbols and standard q[0124] decode + +! Input: iavg 0 for single-period decode, 1 for average +! iwave(0:nmax-1) Raw data +! ntrperiod T/R sequence length (s) +! nfqso Target frequency (Hz) +! ntol Search range around nfqso (Hz) +! lclearave Flag to clear the accumulating array +! emedelay Extra delay for EME signals +! Output: xdt Time offset from nominal (s) +! f0 Frequency of sync tone +! snr1 Relative SNR of sync signal +! width Estimated Doppler spread +! dat4(13) Decoded message as 13 six-bit integers +! snr2 Estimated SNR of decoded signal +! idec Flag for decoding results +! -1 No decode +! 0 No AP +! 1 "CQ ? ?" +! 2 "Mycall ? ?" +! 3 "MyCall HisCall ?" + + use packjt77 + use timer_module, only: timer + + parameter (LN=2176*63) !LN=LL*NN; LL=64*(mode_q65+2), NN=63 + integer*2 iwave(0:12000*ntrperiod-1) !Raw data + integer dat4(13) + character*37 decoded + logical first,lclearave + real, allocatable :: s3(:,:) !Data-symbol energies s3(LL,63) + real, allocatable :: ccf1(:) !CCF(freq) at fixed lag (red) + data first/.true./ + save first,LL0 + + integer w3t + integer w3f + integer mm + integer stageno + + NN=63 + +! Set some parameters and allocate storage for large arrays + irc=-2 + nrc=-2 + idec=-1 + snr1=0. + dat4=0 + LL=64*(2+mode_q65) + nfft=nsps + df=12000.0/nfft !Freq resolution = baud + istep=nsps/NSTEP + iz=5000.0/df !Uppermost frequency bin, at 5000 Hz + txt=85.0*nsps/12000.0 + jz=(txt+1.0)*12000.0/istep !Number of symbol/NSTEP bins + if(nsps.ge.6912) jz=(txt+2.0)*12000.0/istep !For TR 60 s and higher + ftol=ntol + ia=ntol/df + ia2=max(ia,10*mode_q65,nint(100.0/df)) +! nsmo=int(0.7*mode_q65*mode_q65) + nsmo=int(0.5*mode_q65*mode_q65) + if(nsmo.lt.1) nsmo=1 + if(first) then !Generate the sync vector + sync=-22.0/63.0 !Sync tone OFF + do k=1,22 + sync(isync(k))=1.0 !Sync tone ON + enddo + endif + + allocate(s3(-64:LL-65,63)) + allocate(ccf1(-ia2:ia2)) + if(LL.ne.LL0 .or. iz.ne.iz0 .or. jz.ne.jz0 .or. lclearave) then + if(allocated(s1)) deallocate(s1) + allocate(s1(iz,jz)) + if(allocated(s1a)) deallocate(s1a) + allocate(s1a(iz,jz,0:1)) + if(allocated(ccf2)) deallocate(ccf2) + allocate(ccf2(iz)) + if(allocated(ccf2_avg)) deallocate(ccf2_avg) + allocate(ccf2_avg(iz)) + s1=0. + s1a=0. + navg=0 + LL0=LL + iz0=iz + jz0=jz + lclearave=.false. + endif + ccf1=0. + if(iavg.eq.0) ccf2=0. + dtstep=nsps/(NSTEP*12000.0) !Step size in seconds + lag1=-1.0/dtstep + lag2=1.0/dtstep + 0.9999 + if(nsps.ge.3600 .and. emedelay.gt.0) lag2=5.5/dtstep + 0.9999 !Include EME + j0=0.5/dtstep + if(nsps.ge.7200) j0=1.0/dtstep !Nominal start-signal index + + s3=0. +! if(iavg.eq.0 .and. lnewdat) then + if(iavg.eq.0) then + call timer('q65_syms',0) +! Compute symbol spectra with NSTEP time bins per symbol + call q65_symspec(iwave,ntrperiod*12000,iz,jz,s1) + call timer('q65_syms',1) +! lnewdat=.false. + else + s1=s1a(:,:,iseq) + endif + + i0=nint(nfqso/df) !Target QSO frequency + dat4=0 + if(ncw.gt.0 .and. iavg.le.1) then +! Try list decoding via "Deep Likelihood". + call timer('ccf_85 ',0) +! Try to synchronize using all 85 symbols + call q65_ccf_85(s1,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best, & + better,ccf1) + call timer('ccf_85 ',1) + + if(better.ge.1.10 .or. mode_q65.ge.8) then + call timer('list_dec',0) + call q65_dec_q3(s1,iz,jz,s3,LL,ipk,jpk,snr2,dat4,idec,decoded) + call timer('list_dec',1) + endif +! If idec=3 we have a q3 decode. Continue to compute sync curve for plotting. + endif + +! Get 2d CCF and ccf2 using sync symbols only + if(iavg.eq.0) then + call timer('ccf_22a ',0) + call q65_ccf_22(s1,iz,jz,nfqso,ntol,iavg,ipk,jpk, & + f0a,xdta,ccf2) + call timer('ccf_22a ',1) + endif + +! Get 2d CCF and ccf2_avg using sync symbols only + if(iavg.ge.1) then + call timer('ccf_22b ',0) + call q65_ccf_22(s1,iz,jz,nfqso,ntol,iavg,ipk,jpk, & + f0a,xdta,ccf2_avg) + call timer('ccf_22b ',1) + endif + if(idec.lt.0) then + f0=f0a + xdt=xdta + endif + +! Estimate rms on ccf2 baseline + call q65_sync_curve(ccf2,1,iz,rms2) + smax=maxval(ccf2) + snr1=0. + if(rms2.gt.0) snr1=smax/rms2 + + if(idec.le.0) then +! The q3 decode attempt failed. Copy synchronized symbol energies from s1 +! into s3 and prepare to try a more general decode. + call q65_s1_to_s3(s1,iz,jz,ipk,jpk,LL,mode_q65,sync,s3) + endif + + smax=maxval(ccf1) + +! Estimate frequency spread + i1=-9999 + i2=-9999 + do i=-ia,ia + if(i1.eq.-9999 .and. ccf1(i).ge.0.5*smax) i1=i + if(i2.eq.-9999 .and. ccf1(-i).ge.0.5*smax) i2=-i + enddo + width=df*(i2-i1) + if(ncw.eq.0) ccf1=0. + call q65_write_red(iz,xdt,ccf2_avg,ccf2) !### Need this call for WSJT-X + + if(idec.lt.0 .and. (iavg.eq.0 .or. iavg.eq.2)) then + call q65_dec_q012(s3,LL,snr2,dat4,idec,decoded) + endif + + if(idec.lt.0 .and. max_drift.eq.50 .and. stageno.eq.5) then + + if(allocated(s1w)) deallocate(s1w) ! w3sz + allocate(s1w(iz,jz)) ! w3sz + + s1w=s1 + do w3t=1,jz + do w3f=1,iz + mm=w3f + nint(drift*w3t/(jz*df)) + if(mm.ge.1 .and. mm.le.iz) then + s1w(w3f,w3t)=s1(mm,w3t) + endif + end do + end do + + if(ncw.gt.0 .and. iavg.le.1) then + ! Try list decoding via "Deep Likelihood". + call timer('ccf_85 ',0) + ! Try to synchronize using all 85 symbols + call q65_ccf_85(s1w,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best, & + better,ccf1) + call timer('ccf_85 ',1) + +! nsubmode is Tone-spacing indicator, 0-4 for A-E: a 0; b 1; c 2; d 3; e 4. +! and mode_q65=2**nsubmode + if(better.ge.1.10) then + ! if(better.ge.1.04 .or. mode_q65.ge.8) then + ! if(better.ge.1.10 .or. mode_q65.ge.8) then ORIGINAL + call timer('list_dec',0) + call q65_dec_q3(s1w,iz,jz,s3,LL,ipk,jpk,snr2,dat4,idec,decoded) + call timer('list_dec',1) + endif ! if(better.ge.1.10) + endif ! if(ncw.gt.0 .and. iavg.le.1) + ! If idec=3 we have a q3 decode. Continue to compute sync curve for plotting. + + if(idec.eq.3) then + idec=5 + endif + + endif ! if(idec.lt.0 .and. max_drift.eq.50 .and. stageno.eq.5) + + return +end subroutine q65_dec0 + +subroutine q65_clravg + +! Clear the averaging array to start a new average. + + if(allocated(s1a)) s1a(:,:,iseq)=0. + navg(iseq)=0 + + return +end subroutine q65_clravg + +subroutine q65_symspec(iwave,nmax,iz,jz,s1) + +! Compute symbol spectra with NSTEP time-steps per symbol. + + integer*2 iwave(0:nmax-1) !Raw data + real s1(iz,jz) + complex, allocatable :: c0(:) !Complex spectrum of symbol + + allocate(c0(0:nsps-1)) + nfft=nsps + fac=1/32767.0 + do j=1,jz,2 !Compute symbol spectra at 2*step size + i1=(j-1)*istep + i2=i1+nsps-1 + k=-1 + do i=i1,i2,2 !Load iwave data into complex array c0, for r2c FFT + xx=iwave(i) + yy=iwave(i+1) + k=k+1 + c0(k)=fac*cmplx(xx,yy) + enddo + c0(k+1:)=0. + call four2a(c0,nfft,1,-1,0) !r2c FFT + do i=1,iz + s1(i,j)=real(c0(i))**2 + aimag(c0(i))**2 + enddo +! For large Doppler spreads, should we smooth the spectra here? + if(nsmo.le.1) nsmo=0 + do i=1,nsmo + call smo121(s1(1:iz,j),iz) + enddo +! Interpolate to fill in the skipped-over spectra. + if(j.ge.3) s1(1:iz,j-1)=0.5*(s1(1:iz,j-2)+s1(1:iz,j)) + enddo + if(lnewdat) then + navg(iseq)=navg(iseq) + 1 + ntc=min(navg(iseq),4) !Averaging time constant in sequences + u=1.0/ntc + s1a(:,:,iseq)=u*s1 + (1.0-u)*s1a(:,:,iseq) + endif + + return +end subroutine q65_symspec + +subroutine q65_dec_q3(s1,iz,jz,s3,LL,ipk,jpk,snr2,dat4,idec,decoded) + +! Copy synchronized symbol energies from s1 into s3, then attempt a q3 decode. + + character*37 decoded + integer dat4(13) + real s1(iz,jz) + real s3(-64:LL-65,63) + + call q65_s1_to_s3(s1,iz,jz,ipk,jpk,LL,mode_q65,sync,s3) + + nsubmode=0 + if(mode_q65.eq.2) nsubmode=1 + if(mode_q65.eq.4) nsubmode=2 + if(mode_q65.eq.8) nsubmode=3 + if(mode_q65.eq.16) nsubmode=4 + if(mode_q65.eq.32) nsubmode=5 + baud=12000.0/nsps + + do ibw=ibwa,ibwb + b90=1.72**ibw + b90ts=b90/baud + call q65_dec1(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) + nrc=irc + if(irc.ge.0) then + snr2=esnodb - db(2500.0/baud) + 3.0 !Empirical adjustment + idec=3 + exit + endif + enddo + + return +end subroutine q65_dec_q3 + +subroutine q65_dec_q012(s3,LL,snr2,dat4,idec,decoded) + +! Do separate passes attempting q0, q1, q2 decodes. + + character*37 decoded + character*78 c78 + integer dat4(13) + real s3(-64:LL-65,63) + logical lapcqonly + + nsubmode=0 + if(mode_q65.eq.2) nsubmode=1 + if(mode_q65.eq.4) nsubmode=2 + if(mode_q65.eq.8) nsubmode=3 + if(mode_q65.eq.16) nsubmode=4 + + baud=12000.0/nsps + iaptype=0 + nQSOprogress=0 !### TEMPORARY ? ### + ncontest=0 + lapcqonly=.false. + + do ipass=0,npasses !Loop over AP passes + apmask=0 !Try first with no AP information + apsymbols=0 + if(ipass.ge.1) then + ! Subsequent passes use AP information appropiate for nQSOprogress + call q65_ap(nQSOprogress,ipass,ncontest,lapcqonly,iaptype, & + apsym0,apmask1,apsymbols1) + write(c78,1050) apmask1 +1050 format(78i1) + read(c78,1060) apmask +1060 format(13b6.6) + write(c78,1050) apsymbols1 + read(c78,1060) apsymbols + endif + + do ibw=ibwa,ibwb + b90=1.72**ibw + b90ts=b90/baud + call q65_dec2(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) + nrc=irc + if(irc.ge.0) then + snr2=esnodb - db(2500.0/baud) + 3.0 !Empirical adjustment + idec=iaptype + go to 100 + endif + enddo + enddo + +100 return +end subroutine q65_dec_q012 + +subroutine q65_ccf_85(s1,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best, & + better,ccf1) + +! Attempt synchronization using all 85 symbols, in advance of an +! attempt at q3 decoding. Return ccf1 for the "red sync curve". + + real s1(iz,jz) + real, allocatable :: ccf(:,:) !CCF(freq,lag) + real, allocatable :: best(:) !best(imsg) -- for checking 2nd best + real ccf1(-ia2:ia2) + integer ijpk(2) + integer itone(85) + + allocate(ccf(-ia2:ia2,-53:214)) + allocate(best(ncw)) + ipk=0 + jpk=0 + ccf_best=0. + imsg_best=-1 + do imsg=1,ncw + i=1 + k=0 + do j=1,85 + if(j.eq.isync(i)) then + i=i+1 + itone(j)=0 + else + k=k+1 + itone(j)=codewords(k,imsg) + 1 + endif + enddo + +! Compute 2D ccf using all 85 symbols in the list message + ccf=0. + iia=200.0/df + + do lag=lag1,lag2 + do k=1,85 + j=j0 + NSTEP*(k-1) + 1 + lag + if(j.ge.1 .and. j.le.jz) then + do i=-ia2,ia2 + ii=i0+mode_q65*itone(k)+i + if(ii.ge.iia .and. ii.le.iz) ccf(i,lag)=ccf(i,lag) + s1(ii,j) + enddo + endif + enddo + enddo + + ccfmax=maxval(ccf(-ia:ia,:)) + if(ccfmax.gt.ccf_best) then + ccf_best=ccfmax + ijpk=maxloc(ccf(-ia:ia,:)) + ipk=ijpk(1)-ia-1 + jpk=ijpk(2)-53-1 + f0=nfqso + ipk*df + xdt=jpk*dtstep + imsg_best=imsg + ccf1=ccf(:,jpk) + endif + best(imsg)=ccfmax + enddo ! imsg + + deallocate(ccf) + better=0. + if(imsg_best.gt.0) then + best(imsg_best)=0. + better=ccf_best/maxval(best) + endif + + return +end subroutine q65_ccf_85 + +subroutine q65_ccf_22(s1,iz,jz,nfqso,ntol,iavg,ipk,jpk, & + f0,xdt,ccf2) + +! Attempt synchronization using only the 22 sync symbols. Return ccf2 +! for the "orange sync curve". + + real s1(iz,jz) + real ccf2(iz) !Orange sync curve + real tmp(20,3) + real, allocatable :: xdt2(:) + real, allocatable :: s1avg(:) + integer, allocatable :: indx(:) + + allocate(xdt2(iz)) + allocate(s1avg(iz)) + allocate(indx(iz)) + + ia=max(nfa,100)/df + ib=min(nfb,4900)/df +! if(nqd.ne.1 .or. iavg.ne.0) max_drift=0 !### Disabled March 22, 2023 + if(max_drift.ne.0) then + ia=max(nint(100/df),nint((nfqso-ntol)/df)) + ib=min(nint(4900/df),nint((nfqso+ntol)/df)) + endif + if(ia.ge.ib) ia=ib-ntol/df !Protect against wacky settings + + do i=ia,ib + s1avg(i)=sum(s1(i,1:jz)) + enddo + + ccfbest=0. + ibest=0 + lagpk=0 + lagbest=0 + idrift_max=0 + idrift_best=0 + + do i=ia,ib + ccfmax=0. + do lag=lag1,lag2 + do idrift=-max_drift,max_drift + ccft=0. + do kk=1,22 + k=isync(kk) + ii=i + nint(idrift*(k-43)/85.0) + if(ii.lt.1 .or. ii.gt.iz) cycle + n=NSTEP*(k-1) + 1 + j=n+lag+j0 + if(j.ge.1 .and. j.le.jz) ccft=ccft + s1(ii,j) + enddo ! kk + ccft=ccft - (22.0/jz)*s1avg(i) + if(ccft.gt.ccfmax) then + ccfmax=ccft + lagpk=lag + idrift_max=idrift + endif + enddo ! idrift + enddo ! lag + + ccf2(i)=ccfmax + xdt2(i)=lagpk*dtstep + + if(ccfmax.gt.ccfbest .and. abs(i*df-nfqso).le.ftol) then + ccfbest=ccfmax + snrbest=snr + ibest=i + lagbest=lagpk + idrift_best=idrift_max + endif + enddo ! i + +! Parameters for the top candidate: + ipk=ibest - i0 + jpk=lagbest + f0=nfqso + ipk*df + xdt=jpk*dtstep + drift=df*idrift_best + ccf2(:ia)=0. + ccf2(ib:)=0. + +! Save parameters for best candidates + jzz=ib-ia+1 + call indexx(ccf2(ia:ib),jzz,indx) + + call pctile(ccf2(ia:ib),jzz,50,ave) + call pctile(ccf2(ia:ib),jzz,84,base) + rms=base-ave + ncand=0 + maxcand=20 + do j=1,20 + k=jzz-j+1 + if(k.lt.1 .or. k.gt.iz) cycle + i=indx(k)+ia-1 + f=i*df + i3=max(1, i-mode_q65) + i4=min(iz,i+mode_q65) + biggest=maxval(ccf2(i3:i4)) + if(ccf2(i).ne.biggest) cycle + snr=(ccf2(i)-ave)/rms + if(snr.lt.6.0) exit + ncand=ncand+1 + candidates(ncand,1)=snr + candidates(ncand,2)=xdt2(i) + candidates(ncand,3)=f + if(ncand.ge.maxcand) exit + enddo + +! Resort the candidates back into frequency order + tmp(1:ncand,1:3)=candidates(1:ncand,1:3) + candidates=0. + call indexx(tmp(1:ncand,3),ncand,indx) + do i=1,ncand + candidates(i,1:3)=tmp(indx(i),1:3) + enddo + + return +end subroutine q65_ccf_22 + +subroutine q65_dec1(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) + +! Attmpt a full-AP list decode. + + use packjt77 + real s3(1,1) !Silence compiler warning that wants to see a 2D array + real s3prob(0:63,63) !Symbol-value probabilities + integer dat4(13) + character c77*77,decoded*37 + logical unpk77_success + + nFadingModel=1 + decoded=' ' + call q65_intrinsics_ff(s3,nsubmode,b90ts,nFadingModel,s3prob) + call q65_dec_fullaplist(s3,s3prob,codewords,ncw,esnodb,dat4,plog,irc) + if(sum(dat4).le.0) irc=-2 + if(irc.ge.0 .and. plog.gt.PLOG_MIN) then + write(c77,1000) dat4(1:12),dat4(13)/2 +1000 format(12b6.6,b5.5) + call unpack77(c77,0,decoded,unpk77_success) !Unpack to get msgsent + else + irc=-1 + endif + nrc=irc + + return +end subroutine q65_dec1 + +subroutine q65_dec2(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) + +! Attempt a q0, q1, or q2 decode using spcified AP information. + + use packjt77 + real s3(iz0,jz0) !Silence compiler warning that wants to see a 2D array + real s3prob(0:63,63) !Symbol-value probabilities + integer dat4(13) + character c77*77,decoded*37 + logical unpk77_success + + nFadingModel=1 + decoded=' ' + call q65_intrinsics_ff(s3,nsubmode,b90ts,nFadingModel,s3prob) + call q65_dec(s3,s3prob,APmask,APsymbols,maxiters,esnodb,dat4,irc) + if(sum(dat4).le.0) irc=-2 + nrc=irc + if(irc.ge.0) then + write(c77,1000) dat4(1:12),dat4(13)/2 +1000 format(12b6.6,b5.5) + call unpack77(c77,0,decoded,unpk77_success) !Unpack to get msgsent + endif + + return +end subroutine q65_dec2 + +subroutine q65_s1_to_s3(s1,iz,jz,ipk,jpk,LL,mode_q65,sync,s3) + +! Copy synchronized symbol energies from s1 (or s1a) into s3. + + real s1(iz,jz) + real s3(-64:LL-65,63) + real sync(85) !sync vector + + i1=i0+ipk-64 + mode_q65 + i2=i1+LL-1 + if(i1.ge.1 .and. i2.le.iz) then + j=j0+jpk-7 + n=0 + do k=1,85 + j=j+8 + if(sync(k).gt.0.0) then + cycle + endif + n=n+1 + if(j.ge.1 .and. j.le.jz) s3(-64:LL-65,n)=s1(i1:i2,j) + enddo + endif + call q65_bzap(s3,LL) !Zap birdies + + return +end subroutine q65_s1_to_s3 + +subroutine q65_write_red(iz,xdt,ccf2_avg,ccf2) + +! Write data for the red and orange sync curves to LU 17. + + real ccf2_avg(iz) + real ccf2(iz) + + call q65_sync_curve(ccf2_avg,1,iz,rms1) + call q65_sync_curve(ccf2,1,iz,rms2) + + i1=max(1,nint(nfa/df)) + i2=min(iz,int(nfb/df)) + y0=minval(ccf2(i1:i2)) + y0_avg=minval(ccf2_avg(i1:i2)) + g=0.4 + g_avg=0. + if(navg(iseq).ge.2) g_avg=g + rewind 17 + write(17,1000) xdt,g_avg*minval(ccf2_avg),g_avg*maxval(ccf2_avg) + do i=i1,i2 + freq=i*df + y1=g_avg*(ccf2_avg(i)-y0_avg) + y2=g*(ccf2(i)-y0) + write(17,1000) freq,y1,y2 +1000 format(f10.3,2f15.6) + enddo + flush(17) + + return +end subroutine q65_write_red + +subroutine q65_sync_curve(ccf1,ia,ib,rms1) + +! Condition the red or orange sync curve for plotting. + + real ccf1(ia:ib) + + ic=(ib-ia)/8; + nsum=2*(ic+1) + + base1=(sum(ccf1(ia:ia+ic)) + sum(ccf1(ib-ic:ib)))/nsum + ccf1=ccf1-base1 + sq=dot_product(ccf1(ia:ia+ic),ccf1(ia:ia+ic)) + & + dot_product(ccf1(ib-ic:ib),ccf1(ib-ic:ib)) + rms1=0. + if(nsum.gt.0) rms1=sqrt(sq/nsum) + if(rms1.gt.0.0) ccf1=ccf1/rms1 +! smax1=maxval(ccf1) +! if(smax1.gt.10.0) ccf1=10.0*ccf1/smax1 + + return +end subroutine q65_sync_curve + +subroutine q65_bzap(s3,LL) + + parameter (NBZAP=15) + real s3(-64:LL-65,63) + integer ipk1(1) + integer, allocatable :: hist(:) + + allocate(hist(-64:LL-65)) + hist=0 + do j=1,63 + ipk1=maxloc(s3(:,j)) + i=ipk1(1) - 65 + hist(i)=hist(i)+1 + enddo + if(maxval(hist).gt.NBZAP) then + do i=-64,LL-65 + if(hist(i).gt.NBZAP) s3(i,1:63)=1.0 + enddo + endif + + return +end subroutine q65_bzap + +subroutine q65_snr(dat4,dtdec,f0dec,mode_q65,snr2) + +! Estimate SNR of a decoded transmission by aligning the spectra of +! all 85 symbols. + + integer dat4(13) + integer codeword(63) + integer itone(85) + real, allocatable :: spec(:) + + allocate(spec(iz0)) + call q65_enc(dat4,codeword) + i=1 + k=0 + do j=1,85 + if(j.eq.isync(i)) then + i=i+1 + itone(j)=0 + else + k=k+1 + itone(j)=codeword(k) + 1 + endif + enddo + + spec=0. + lagpk=nint(dtdec/dtstep) + do k=1,85 + j=j0 + NSTEP*(k-1) + 1 + lagpk + if(j.ge.1 .and. j.le.jz0) then + do i=1,iz0 + ii=i+mode_q65*itone(k) + if(ii.ge.1 .and. ii.le.iz0) spec(i)=spec(i) + s1(ii,j) + enddo + endif + enddo + + i0=nint(f0dec/df) + nsum=max(10*mode_q65,nint(50.0/df)) + ia=max(1,i0-2*nsum) + ib=min(iz0,i0+2*nsum) + sum1=sum(spec(ia:ia+nsum-1)) + sum2=sum(spec(ib-nsum+1:ib)) + avg=(sum1+sum2)/(2.0*nsum) + spec=spec/avg !Baseline level is now 1.0 + smax=maxval(spec(ia:ib)) + sig_area=sum(spec(ia+nsum:ib-nsum)-1.0) + w_equiv=sig_area/(smax-1.0) + snr2=db(max(1.0,sig_area)) - db(2500.0/df) + + return +end subroutine q65_snr + +subroutine q65_hist(if0,msg0,dxcall,dxgrid) + +! Save the MAXHIST most receent decodes, and their f0 values; or, if +! dxcall is present, look up the most recent dxcall and dxgrid at the +! specified f0. + + parameter (MAXHIST=100) + integer,intent(in) :: if0 !Audio freq of decode + character(len=37),intent(in),optional :: msg0 !Decoded message + character(len=12),intent(out),optional :: dxcall !Second callsign in message + character(len=6),intent(out),optional :: dxgrid !Third word in msg, if grid + + character*6 g1 + character*37 msg(MAXHIST) !Saved messages + integer nf0(MAXHIST) !Saved frequencies + logical isgrid !Statement function + data nhist/0/ + save nhist,nf0,msg + + isgrid(g1)=g1(1:1).ge.'A' .and. g1(1:1).le.'R' .and. g1(2:2).ge.'A' .and. & + g1(2:2).le.'R' .and. g1(3:3).ge.'0' .and. g1(3:3).le.'9' .and. & + g1(4:4).ge.'0' .and. g1(4:4).le.'9' .and. g1(1:4).ne.'RR73' + + if(present(dxcall)) go to 100 !This is a lookup request + + if(nhist.eq.MAXHIST) then + nf0(1:MAXHIST-1)=nf0(2:MAXHIST) !List is full, must make room + msg(1:MAXHIST-1)=msg(2:MAXHIST) + nhist=MAXHIST-1 + endif + nhist=nhist+1 !Insert msg0 at end of list + nf0(nhist)=if0 + msg(nhist)=msg0 + go to 900 + +100 if(dxcall(1:3).ne.' ') go to 900 + dxcall=' ' !This is a lookup request + dxgrid=' ' +! Look for a decode close to if0, starting with most recent ones + do i=nhist,1,-1 + if(abs(nf0(i)-if0).gt.10) cycle + i1=index(msg(i),' ') + if(i1.ge.4 .and. i1.le.13) then + i2=index(msg(i)(i1+1:),' ') + i1 + dxcall=msg(i)(i1+1:i2-1) !Extract dxcall + g1=msg(i)(i2+1:i2+4) + if(isgrid(g1)) dxgrid=g1(1:4) !Extract dxgrid + exit + endif + enddo + +900 return +end subroutine q65_hist + +subroutine q65_hist2(nfreq,msg0,callers,nhist2) + + use types + use prog_args + parameter (MAX_CALLERS=40) !For multiple q3 decodes in NA VHf Contest mode + character*37 msg0,msg + type(q3list) callers(MAX_CALLERS) + character*6 c6 + character*4 g4 + logical newcall,isgrid + + isgrid(g4)=g4(1:1).ge.'A' .and. g4(1:1).le.'R' .and. g4(2:2).ge.'A' .and. & + g4(2:2).le.'R' .and. g4(3:3).ge.'0' .and. g4(3:3).le.'9' .and. & + g4(4:4).ge.'0' .and. g4(4:4).le.'9' .and. g4(1:4).ne.'RR73' + + msg=msg0 + if(index(msg,'/').gt.0) goto 900 !Ignore messages with compound calls + i0=index(msg,' R ') + if(i0.ge.7) msg=msg(1:i0)//msg(i0+3:) + i1=index(msg,' ') + c6=' ' + g4=' ' + if(i1.ge.4 .and. i1.le.13) then + i2=index(msg(i1+1:),' ') + i1 + c6=msg(i1+1:i2-1) !Extract DX call + g4=msg(i2+1:i2+4) !Extract DX grid + endif + + newcall=.true. + do i=1,nhist2 + if(callers(i)%call .eq. c6) then + newcall=.false. + callers(i)%nsec=time() + callers(i)%nfreq=nfreq + exit + endif + enddo + + if(newcall .and. isgrid(g4)) then + if(nhist2.eq.MAX_CALLERS) then +! Purge the oldest caller + callers(1:MAX_CALLERS-1)=callers(2:MAX_CALLERS) + nhist2=nhist2-1 + endif + nhist2=nhist2+1 + callers(nhist2)%call=c6 + callers(nhist2)%grid=g4 + callers(nhist2)%nsec=time() + callers(nhist2)%nfreq=nfreq + endif + + if(nhist2.ge.1 .and. nhist2.le.40) then + open(24,file=trim(data_dir)//'/tsil.3q',status='unknown', & + form='unformatted') + write(24) nhist2 + write(24) callers(1:nhist2) + close(24) + endif + +900 return +end subroutine q65_hist2 + +end module q65 diff --git a/lib/qra/q65/q65.h b/lib/qra/q65/q65.h index 05022649..d0a04d4e 100755 --- a/lib/qra/q65/q65.h +++ b/lib/qra/q65/q65.h @@ -1,123 +1,123 @@ -// q65.h -// Q65 modes encoding/decoding functions -// -// (c) 2020 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#ifndef _q65_h -#define _q65_h - -#include "qracodes.h" - -// Error codes returned by q65_decode(...) -#define Q65_DECODE_INVPARAMS -1 -#define Q65_DECODE_FAILED -2 -#define Q65_DECODE_CRCMISMATCH -3 -#define Q65_DECODE_LLHLOW -4 -#define Q65_DECODE_UNDETERR -5 - -// Verify loglikelihood after successful decoding -#define Q65_CHECKLLH -// Max codeword list size in q65_decode_fullaplist -#define Q65_FULLAPLIST_SIZE 256 - -// maximum number of weights for the fast-fading metric evaluation -#define Q65_FASTFADING_MAXWEIGTHS 65 - -extern float q65_llh; - -typedef struct { - const qracode *pQraCode; // qra code to be used by the codec - float decoderEsNoMetric; // value for which we optimize the decoder metric - int *x; // codec input - int *y; // codec output - float *qra_v2cmsg; // decoder v->c messages - float *qra_c2vmsg; // decoder c->v messages - float *ix; // decoder intrinsic information - float *ex; // decoder extrinsic information - // variables used to compute the intrinsics in the fast-fading case - int nBinsPerTone; - int nBinsPerSymbol; - float ffNoiseVar; - float ffEsNoMetric; - int nWeights; - float ffWeight[Q65_FASTFADING_MAXWEIGTHS]; -} q65_codec_ds; - -int q65_init(q65_codec_ds *pCodec, const qracode *pQraCode); -void q65_free(q65_codec_ds *pCodec); - -int q65_encode(const q65_codec_ds *pCodec, int *pOutputCodeword, const int *pInputMsg); - -int q65_intrinsics(q65_codec_ds *pCodec, float *pIntrinsics, const float *pInputEnergies); - -int q65_intrinsics_fastfading(q65_codec_ds *pCodec, - float *pIntrinsics, // intrinsic symbol probabilities output - const float *pInputEnergies, // received energies input - const int submode, // submode idx (0=A ... 4=E) - const float B90Ts, // normalized spread bandwidth (90% fractional energy) - const int fadingModel); // 0=Gaussian 1=Lorentzian fade model - - -int q65_decode(q65_codec_ds *pCodec, - int* pDecodedCodeword, - int *pDecodedMsg, - const float *pIntrinsics, - const int *pAPMask, - const int *pAPSymbols, - const int maxiters); - -int q65_decode_fullaplist(q65_codec_ds *codec, - int *ydec, - int *xdec, - const float *pIntrinsics, - const int *pCodewords, - const int nCodewords); - -int q65_esnodb(const q65_codec_ds *pCodec, - float *pEsNodB, - const int *ydec, - const float *pInputEnergies); - -int q65_esnodb_fastfading( - const q65_codec_ds *pCodec, - float *pEsNodB, - const int *ydec, - const float *pInputEnergies); - - -// helper functions -#define q65_get_message_length(pCodec) _q65_get_message_length((pCodec)->pQraCode) -#define q65_get_codeword_length(pCodec) _q65_get_codeword_length((pCodec)->pQraCode) -#define q65_get_code_rate(pCodec) _q65_get_code_rate((pCodec)->pQraCode) -#define q65_get_alphabet_size(pCodec) _q65_get_alphabet_size((pCodec)->pQraCode) -#define q65_get_bits_per_symbol(pCodec) _q65_get_bits_per_symbol((pCodec)->pQraCode) - - -// internally used but made public for the above defines -int _q65_get_message_length(const qracode *pCode); -int _q65_get_codeword_length(const qracode *pCode); -float _q65_get_code_rate(const qracode *pCode); -static void _q65_mask(const qracode *pcode, float *ix, const int *mask, const int *x); -int _q65_get_alphabet_size(const qracode *pCode); -int _q65_get_bits_per_symbol(const qracode *pCode); - -// internally used but made public for threshold optimization -int q65_check_llh(float *llh, const int* ydec, const int nN, const int nM, const float *pIntrin); - -#endif // _qra65_h +// q65.h +// Q65 modes encoding/decoding functions +// +// (c) 2020 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#ifndef _q65_h +#define _q65_h + +#include "qracodes.h" + +// Error codes returned by q65_decode(...) +#define Q65_DECODE_INVPARAMS -1 +#define Q65_DECODE_FAILED -2 +#define Q65_DECODE_CRCMISMATCH -3 +#define Q65_DECODE_LLHLOW -4 +#define Q65_DECODE_UNDETERR -5 + +// Verify loglikelihood after successful decoding +#define Q65_CHECKLLH +// Max codeword list size in q65_decode_fullaplist +#define Q65_FULLAPLIST_SIZE 256 + +// maximum number of weights for the fast-fading metric evaluation +#define Q65_FASTFADING_MAXWEIGTHS 65 + +extern float q65_llh; + +typedef struct { + const qracode *pQraCode; // qra code to be used by the codec + float decoderEsNoMetric; // value for which we optimize the decoder metric + int *x; // codec input + int *y; // codec output + float *qra_v2cmsg; // decoder v->c messages + float *qra_c2vmsg; // decoder c->v messages + float *ix; // decoder intrinsic information + float *ex; // decoder extrinsic information + // variables used to compute the intrinsics in the fast-fading case + int nBinsPerTone; + int nBinsPerSymbol; + float ffNoiseVar; + float ffEsNoMetric; + int nWeights; + float ffWeight[Q65_FASTFADING_MAXWEIGTHS]; +} q65_codec_ds; + +int q65_init(q65_codec_ds *pCodec, const qracode *pQraCode); +void q65_free(q65_codec_ds *pCodec); + +int q65_encode(const q65_codec_ds *pCodec, int *pOutputCodeword, const int *pInputMsg); + +int q65_intrinsics(q65_codec_ds *pCodec, float *pIntrinsics, const float *pInputEnergies); + +int q65_intrinsics_fastfading(q65_codec_ds *pCodec, + float *pIntrinsics, // intrinsic symbol probabilities output + const float *pInputEnergies, // received energies input + const int submode, // submode idx (0=A ... 4=E) + const float B90Ts, // normalized spread bandwidth (90% fractional energy) + const int fadingModel); // 0=Gaussian 1=Lorentzian fade model + + +int q65_decode(q65_codec_ds *pCodec, + int* pDecodedCodeword, + int *pDecodedMsg, + const float *pIntrinsics, + const int *pAPMask, + const int *pAPSymbols, + const int maxiters); + +int q65_decode_fullaplist(q65_codec_ds *codec, + int *ydec, + int *xdec, + const float *pIntrinsics, + const int *pCodewords, + const int nCodewords); + +int q65_esnodb(const q65_codec_ds *pCodec, + float *pEsNodB, + const int *ydec, + const float *pInputEnergies); + +int q65_esnodb_fastfading( + const q65_codec_ds *pCodec, + float *pEsNodB, + const int *ydec, + const float *pInputEnergies); + + +// helper functions +#define q65_get_message_length(pCodec) _q65_get_message_length((pCodec)->pQraCode) +#define q65_get_codeword_length(pCodec) _q65_get_codeword_length((pCodec)->pQraCode) +#define q65_get_code_rate(pCodec) _q65_get_code_rate((pCodec)->pQraCode) +#define q65_get_alphabet_size(pCodec) _q65_get_alphabet_size((pCodec)->pQraCode) +#define q65_get_bits_per_symbol(pCodec) _q65_get_bits_per_symbol((pCodec)->pQraCode) + + +// internally used but made public for the above defines +int _q65_get_message_length(const qracode *pCode); +int _q65_get_codeword_length(const qracode *pCode); +float _q65_get_code_rate(const qracode *pCode); +static void _q65_mask(const qracode *pcode, float *ix, const int *mask, const int *x); +int _q65_get_alphabet_size(const qracode *pCode); +int _q65_get_bits_per_symbol(const qracode *pCode); + +// internally used but made public for threshold optimization +int q65_check_llh(float *llh, const int* ydec, const int nN, const int nM, const float *pIntrin); + +#endif // _qra65_h diff --git a/lib/qra/q65/q65.sln b/lib/qra/q65/q65.sln index d45e8096..1ac03a6a 100755 --- a/lib/qra/q65/q65.sln +++ b/lib/qra/q65/q65.sln @@ -1,20 +1,20 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "q65", "q65.vcproj", "{933A58F6-199B-4723-ACFE-3013E6DD9D0A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {933A58F6-199B-4723-ACFE-3013E6DD9D0A}.Debug|Win32.ActiveCfg = Debug|Win32 - {933A58F6-199B-4723-ACFE-3013E6DD9D0A}.Debug|Win32.Build.0 = Debug|Win32 - {933A58F6-199B-4723-ACFE-3013E6DD9D0A}.Release|Win32.ActiveCfg = Release|Win32 - {933A58F6-199B-4723-ACFE-3013E6DD9D0A}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "q65", "q65.vcproj", "{933A58F6-199B-4723-ACFE-3013E6DD9D0A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {933A58F6-199B-4723-ACFE-3013E6DD9D0A}.Debug|Win32.ActiveCfg = Debug|Win32 + {933A58F6-199B-4723-ACFE-3013E6DD9D0A}.Debug|Win32.Build.0 = Debug|Win32 + {933A58F6-199B-4723-ACFE-3013E6DD9D0A}.Release|Win32.ActiveCfg = Release|Win32 + {933A58F6-199B-4723-ACFE-3013E6DD9D0A}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/lib/qra/q65/q65.vcproj b/lib/qra/q65/q65.vcproj index f6a332ed..36b3235e 100755 --- a/lib/qra/q65/q65.vcproj +++ b/lib/qra/q65/q65.vcproj @@ -1,255 +1,255 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/qra/q65/q65_ap.f90 b/lib/qra/q65/q65_ap.f90 index 1fce663c..32e26a4e 100755 --- a/lib/qra/q65/q65_ap.f90 +++ b/lib/qra/q65/q65_ap.f90 @@ -1,166 +1,166 @@ -subroutine q65_ap(nQSOprogress,ipass,ncontest,lapcqonly,iaptype, & - apsym0,apmask,apsymbols) - - integer apsym0(58),aph10(10) - integer apmask(78),apsymbols(78) - integer naptypes(0:5,4) ! (nQSOProgress, ipass) maximum of 4 passes for now - integer mcqru(29),mcqfd(29),mcqtest(29),mcqww(29) - integer mcq(29),mrrr(19),m73(19),mrr73(19) - logical lapcqonly,first - data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/ - data mcqru/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,1,1,0,0/ - data mcqfd/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,1,0/ - data mcqtest/0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,1,0/ - data mcqww/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,1,1,1,1,0/ - data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/ - data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/ - data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/ - data ncontest0/99/ - data first/.true./ - save naptypes,ncontest0 - -! nQSOprogress -! 0 CALLING -! 1 REPLYING -! 2 REPORT -! 3 ROGER_REPORT -! 4 ROGERS -! 5 SIGNOFF - - if(first.or.(ncontest.ne.ncontest0)) then -! iaptype -!------------------------ -! 1 CQ ??? ??? (29+4=33 ap bits) -! 2 MyCall ??? ??? (29+4=33 ap bits) -! 3 MyCall DxCall ??? (58+4=62 ap bits) -! 4 MyCall DxCall RRR (78 ap bits) -! 5 MyCall DxCall 73 (78 ap bits) -! 6 MyCall DxCall RR73 (78 ap bits) - - naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ) - naptypes(1,1:4)=(/2,3,0,0/) ! Tx1 - naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 - naptypes(3,1:4)=(/3,4,5,6/) ! Tx3 - naptypes(4,1:4)=(/3,4,5,6/) ! Tx4 - naptypes(5,1:4)=(/3,1,2,0/) ! Tx5 - first=.false. - ncontest0=ncontest - endif - - apsymbols=0 - iaptype=naptypes(nQSOProgress,ipass) - if(lapcqonly) iaptype=1 - -! ncontest=0 : NONE -! 1 : NA_VHF -! 2 : EU_VHF -! 3 : FIELD DAY -! 4 : RTTY -! 5 : WW_DIGI -! 6 : FOX -! 7 : HOUND - -! Conditions that cause us to bail out of AP decoding -! if(ncontest.le.5 .and. iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid .and. abs(f1-nftx).gt.napwid) ) goto 900 -! if(ncontest.eq.6) goto 900 !No AP for Foxes -! if(ncontest.eq.7.and.f1.gt.950.0) goto 900 !Hounds use AP only below 950 Hz - if(ncontest.ge.6) goto 900 - if(iaptype.ge.2 .and. apsym0(1).gt.1) goto 900 !No, or nonstandard, mycall - if(ncontest.eq.7 .and. iaptype.ge.2 .and. aph10(1).gt.1) goto 900 - if(iaptype.ge.3 .and. apsym0(30).gt.1) goto 900 !No, or nonstandard, dxcall - - if(iaptype.eq.1) then ! CQ or CQ RU or CQ TEST or CQ FD - apmask=0 - apmask(1:29)=1 - if(ncontest.eq.0) apsymbols(1:29)=mcq - if(ncontest.eq.1) apsymbols(1:29)=mcqtest - if(ncontest.eq.2) apsymbols(1:29)=mcqtest - if(ncontest.eq.3) apsymbols(1:29)=mcqfd - if(ncontest.eq.4) apsymbols(1:29)=mcqru - if(ncontest.eq.5) apsymbols(1:29)=mcqww - if(ncontest.eq.7) apsymbols(1:29)=mcq - apmask(75:78)=1 - apsymbols(75:78)=(/0,0,1,0/) - endif - - if(iaptype.eq.2) then ! MyCall,???,??? - apmask=0 - if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.5) then - apmask(1:29)=1 - apsymbols(1:29)=apsym0(1:29) - apmask(75:78)=1 - apsymbols(75:78)=(/0,0,1,0/) - else if(ncontest.eq.2) then - apmask(1:28)=1 - apsymbols(1:28)=apsym0(1:28) - apmask(72:74)=1 - apsymbols(72)=0 - apsymbols(73)=(+1) - apsymbols(74)=0 - apmask(75:78)=1 - apsymbols(75:78)=0 - else if(ncontest.eq.3) then - apmask(1:28)=1 - apsymbols(1:28)=apsym0(1:28) - apmask(75:78)=1 - apsymbols(75:78)=0 - else if(ncontest.eq.4) then - apmask(2:29)=1 - apsymbols(2:29)=apsym0(1:28) - apmask(75:78)=1 - apsymbols(75:78)=(/0,0,1,0/) - else if(ncontest.eq.7) then ! ??? RR73; MyCall ??? - apmask(29:56)=1 - apsymbols(29:56)=apsym0(1:28) - apmask(57:66)=1 - apsymbols(57:66)=aph10(1:10) - apmask(72:78)=1 - apsymbols(72:74)=(/0,0,1/) - apsymbols(75:78)=0 - endif - endif - - if(iaptype.eq.3) then ! MyCall,DxCall,??? - apmask=0 - if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2.or.ncontest.eq.5.or.ncontest.eq.7) then - apmask(1:58)=1 - apsymbols(1:58)=apsym0 - apmask(75:78)=1 - apsymbols(75:78)=(/0,0,1,0/) - else if(ncontest.eq.3) then ! Field Day - apmask(1:56)=1 - apsymbols(1:28)=apsym0(1:28) - apsymbols(29:56)=apsym0(30:57) - apmask(72:78)=1 - apsymbols(75:78)=0 - else if(ncontest.eq.4) then - apmask(2:57)=1 - apsymbols(2:29)=apsym0(1:28) - apsymbols(30:57)=apsym0(30:57) - apmask(75:78)=1 - apsymbols(75:78)=(/0,0,1,0/) - endif - endif - - if(iaptype.eq.5.and.ncontest.eq.7) goto 900 !Hound - if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then - apmask=0 - if(ncontest.le.5 .or. (ncontest.eq.7.and.iaptype.eq.6)) then - apmask(1:78)=1 !MyCall, HisCall, RRR|73|RR73 - apmask(72:74)=0 !Check for , RRR, RR73, 73 - apsymbols(1:58)=apsym0 - if(iaptype.eq.4) apsymbols(59:77)=mrrr - if(iaptype.eq.5) apsymbols(59:77)=m73 - if(iaptype.eq.6) apsymbols(59:77)=mrr73 - else if(ncontest.eq.7.and.iaptype.eq.4) then ! Hound listens for MyCall RR73;... - apmask(1:28)=1 - apsymbols(1:28)=apsym0(1:28) - apmask(57:66)=1 - apsymbols(57:66)=aph10(1:10) - apmask(72:78)=1 - apsymbols(72:78)=(/0,0,1,0,0,0,0/) - endif - endif - -900 return -end subroutine q65_ap +subroutine q65_ap(nQSOprogress,ipass,ncontest,lapcqonly,iaptype, & + apsym0,apmask,apsymbols) + + integer apsym0(58),aph10(10) + integer apmask(78),apsymbols(78) + integer naptypes(0:5,4) ! (nQSOProgress, ipass) maximum of 4 passes for now + integer mcqru(29),mcqfd(29),mcqtest(29),mcqww(29) + integer mcq(29),mrrr(19),m73(19),mrr73(19) + logical lapcqonly,first + data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/ + data mcqru/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,1,1,0,0/ + data mcqfd/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,1,0/ + data mcqtest/0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,1,0/ + data mcqww/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,1,1,1,1,0/ + data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/ + data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/ + data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/ + data ncontest0/99/ + data first/.true./ + save naptypes,ncontest0 + +! nQSOprogress +! 0 CALLING +! 1 REPLYING +! 2 REPORT +! 3 ROGER_REPORT +! 4 ROGERS +! 5 SIGNOFF + + if(first.or.(ncontest.ne.ncontest0)) then +! iaptype +!------------------------ +! 1 CQ ??? ??? (29+4=33 ap bits) +! 2 MyCall ??? ??? (29+4=33 ap bits) +! 3 MyCall DxCall ??? (58+4=62 ap bits) +! 4 MyCall DxCall RRR (78 ap bits) +! 5 MyCall DxCall 73 (78 ap bits) +! 6 MyCall DxCall RR73 (78 ap bits) + + naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ) + naptypes(1,1:4)=(/2,3,0,0/) ! Tx1 + naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 + naptypes(3,1:4)=(/3,4,5,6/) ! Tx3 + naptypes(4,1:4)=(/3,4,5,6/) ! Tx4 + naptypes(5,1:4)=(/3,1,2,0/) ! Tx5 + first=.false. + ncontest0=ncontest + endif + + apsymbols=0 + iaptype=naptypes(nQSOProgress,ipass) + if(lapcqonly) iaptype=1 + +! ncontest=0 : NONE +! 1 : NA_VHF +! 2 : EU_VHF +! 3 : FIELD DAY +! 4 : RTTY +! 5 : WW_DIGI +! 6 : FOX +! 7 : HOUND + +! Conditions that cause us to bail out of AP decoding +! if(ncontest.le.5 .and. iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid .and. abs(f1-nftx).gt.napwid) ) goto 900 +! if(ncontest.eq.6) goto 900 !No AP for Foxes +! if(ncontest.eq.7.and.f1.gt.950.0) goto 900 !Hounds use AP only below 950 Hz + if(ncontest.ge.6) goto 900 + if(iaptype.ge.2 .and. apsym0(1).gt.1) goto 900 !No, or nonstandard, mycall + if(ncontest.eq.7 .and. iaptype.ge.2 .and. aph10(1).gt.1) goto 900 + if(iaptype.ge.3 .and. apsym0(30).gt.1) goto 900 !No, or nonstandard, dxcall + + if(iaptype.eq.1) then ! CQ or CQ RU or CQ TEST or CQ FD + apmask=0 + apmask(1:29)=1 + if(ncontest.eq.0) apsymbols(1:29)=mcq + if(ncontest.eq.1) apsymbols(1:29)=mcqtest + if(ncontest.eq.2) apsymbols(1:29)=mcqtest + if(ncontest.eq.3) apsymbols(1:29)=mcqfd + if(ncontest.eq.4) apsymbols(1:29)=mcqru + if(ncontest.eq.5) apsymbols(1:29)=mcqww + if(ncontest.eq.7) apsymbols(1:29)=mcq + apmask(75:78)=1 + apsymbols(75:78)=(/0,0,1,0/) + endif + + if(iaptype.eq.2) then ! MyCall,???,??? + apmask=0 + if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.5) then + apmask(1:29)=1 + apsymbols(1:29)=apsym0(1:29) + apmask(75:78)=1 + apsymbols(75:78)=(/0,0,1,0/) + else if(ncontest.eq.2) then + apmask(1:28)=1 + apsymbols(1:28)=apsym0(1:28) + apmask(72:74)=1 + apsymbols(72)=0 + apsymbols(73)=(+1) + apsymbols(74)=0 + apmask(75:78)=1 + apsymbols(75:78)=0 + else if(ncontest.eq.3) then + apmask(1:28)=1 + apsymbols(1:28)=apsym0(1:28) + apmask(75:78)=1 + apsymbols(75:78)=0 + else if(ncontest.eq.4) then + apmask(2:29)=1 + apsymbols(2:29)=apsym0(1:28) + apmask(75:78)=1 + apsymbols(75:78)=(/0,0,1,0/) + else if(ncontest.eq.7) then ! ??? RR73; MyCall ??? + apmask(29:56)=1 + apsymbols(29:56)=apsym0(1:28) + apmask(57:66)=1 + apsymbols(57:66)=aph10(1:10) + apmask(72:78)=1 + apsymbols(72:74)=(/0,0,1/) + apsymbols(75:78)=0 + endif + endif + + if(iaptype.eq.3) then ! MyCall,DxCall,??? + apmask=0 + if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2.or.ncontest.eq.5.or.ncontest.eq.7) then + apmask(1:58)=1 + apsymbols(1:58)=apsym0 + apmask(75:78)=1 + apsymbols(75:78)=(/0,0,1,0/) + else if(ncontest.eq.3) then ! Field Day + apmask(1:56)=1 + apsymbols(1:28)=apsym0(1:28) + apsymbols(29:56)=apsym0(30:57) + apmask(72:78)=1 + apsymbols(75:78)=0 + else if(ncontest.eq.4) then + apmask(2:57)=1 + apsymbols(2:29)=apsym0(1:28) + apsymbols(30:57)=apsym0(30:57) + apmask(75:78)=1 + apsymbols(75:78)=(/0,0,1,0/) + endif + endif + + if(iaptype.eq.5.and.ncontest.eq.7) goto 900 !Hound + if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then + apmask=0 + if(ncontest.le.5 .or. (ncontest.eq.7.and.iaptype.eq.6)) then + apmask(1:78)=1 !MyCall, HisCall, RRR|73|RR73 + apmask(72:74)=0 !Check for , RRR, RR73, 73 + apsymbols(1:58)=apsym0 + if(iaptype.eq.4) apsymbols(59:77)=mrrr + if(iaptype.eq.5) apsymbols(59:77)=m73 + if(iaptype.eq.6) apsymbols(59:77)=mrr73 + else if(ncontest.eq.7.and.iaptype.eq.4) then ! Hound listens for MyCall RR73;... + apmask(1:28)=1 + apsymbols(1:28)=apsym0(1:28) + apmask(57:66)=1 + apsymbols(57:66)=aph10(1:10) + apmask(72:78)=1 + apsymbols(72:78)=(/0,0,1,0,0,0,0/) + endif + endif + +900 return +end subroutine q65_ap diff --git a/lib/qra/q65/q65_encoding_modules.f90 b/lib/qra/q65/q65_encoding_modules.f90 index c1f765df..4988dd4d 100755 --- a/lib/qra/q65/q65_encoding_modules.f90 +++ b/lib/qra/q65/q65_encoding_modules.f90 @@ -1,221 +1,221 @@ -module gf64math -! add and subtract in GF(2^6) based on primitive polynomial x^6+x+1 - - implicit none - integer, private :: gf64log(0:63) - integer, private :: gf64antilog(0:62) - -! table of the logarithms of the elements of GF(M) (log(0) never used) - data gf64log/ & - -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, & - 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, & - 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, & - 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, & - 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, & - 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, & - 20, 59, 57, 58/ - -! table of GF(M) elements given their logarithm - data gf64antilog/ & - 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, & - 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, & - 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, & - 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, & - 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, & - 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, & - 57, 49, 33/ - -contains - - integer function gf64_add(i1,i2) - implicit none - integer::i1 - integer::i2 - gf64_add=iand(ieor(i1,i2),63) - end function gf64_add - - integer function gf64_mult(i1,i2) - implicit none - integer::i1 - integer::i2 - integer::j - - if(i1.eq.0 .or. i2.eq.0) then - gf64_mult=0 - elseif(i1.eq.1) then - gf64_mult=i2 - elseif(i2.eq.1) then - gf64_mult=i1 - else - j=mod(gf64log(i1)+gf64log(i2),63) - gf64_mult=gf64antilog(j) - endif - end function gf64_mult - -end module gf64math - -module q65_generator - - integer generator(15,50) - data generator/ & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, & - 0,20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, & - 0,20, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, & - 0,20, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, & - 0,20, 0, 1, 1, 0, 0, 0,10, 0, 0, 0, 0, 1, 0, & - 0,20, 0, 1, 1, 0, 0, 0,10, 0, 0, 0,44, 1, 0, & - 0,20, 0, 1, 1, 0, 0, 0,10, 1, 0, 0,44, 1, 0, & - 0,20, 0, 1, 1, 0, 0, 0,10, 1, 0, 0,44, 1,14, & - 0,20, 0, 1, 1, 0, 0, 0,10, 1,31, 0,44, 1,14, & - 0,20, 0, 1, 1,33, 0, 0,10, 1,31, 0,44, 1,14, & - 56,20, 0, 1, 1,33, 0, 0,10, 1,31, 0,44, 1,14, & - 56,20, 0, 1, 1,33, 0, 1,10, 1,31, 0,44, 1,14, & - 56, 1, 0, 1, 1,33, 0, 1,10, 1,31, 0,44, 1,14, & - 56, 1, 0, 1, 1,33, 0, 1,10, 1,31,36,44, 1,14, & - 56, 1, 0, 1, 1,33, 0, 1,43, 1,31,36,44, 1,14, & - 56, 1, 0, 1, 1,33, 0, 1,43,17,31,36,44, 1,14, & - 56, 1, 0, 1, 1,33, 0, 1,43,17,31,36,36, 1,14, & - 56, 1, 0, 1, 1,33,53, 1,43,17,31,36,36, 1,14, & - 56, 1, 0,35, 1,33,53, 1,43,17,31,36,36, 1,14, & - 56, 1, 0,35, 1,33,53, 1,43,17,30,36,36, 1,14, & - 56, 1, 0,35, 1,33,53,52,43,17,30,36,36, 1,14, & - 56, 1, 0,35, 1,32,53,52,43,17,30,36,36, 1,14, & - 56, 1,60,35, 1,32,53,52,43,17,30,36,36, 1,14, & - 56, 1,60,35, 1,32,53,52,43,17,30,36,36,49,14, & - 56, 1,60,35, 1,32,53,52,43,17,30,36,37,49,14, & - 56, 1,60,35,54,32,53,52,43,17,30,36,37,49,14, & - 56, 1,60,35,54,32,53,52, 1,17,30,36,37,49,14, & - 1, 1,60,35,54,32,53,52, 1,17,30,36,37,49,14, & - 1, 0,60,35,54,32,53,52, 1,17,30,36,37,49,14, & - 1, 0,60,35,54,32,53,52, 1,17,30,37,37,49,14, & - 1, 0,61,35,54,32,53,52, 1,17,30,37,37,49,14, & - 1, 0,61,35,54,32,53,52, 1,48,30,37,37,49,14, & - 1, 0,61,35,54,32,53,52, 1,48,30,37,37,49,15, & - 1, 0,61,35,54, 0,53,52, 1,48,30,37,37,49,15, & - 1, 0,61,35,54, 0,52,52, 1,48,30,37,37,49,15, & - 1, 0,61,35,54, 0,52,52, 1,48,30,37,37, 0,15, & - 1, 0,61,35,54, 0,52,34, 1,48,30,37,37, 0,15, & - 1, 0,61,35,54, 0,52,34, 1,48,30,37, 0, 0,15, & - 1, 0,61,35,54, 0,52,34, 1,48,30,20, 0, 0,15, & - 1, 0, 0,35,54, 0,52,34, 1,48,30,20, 0, 0,15, & - 1, 0, 0,35,54, 0,52,34, 1, 0,30,20, 0, 0,15, & - 0, 0, 0,35,54, 0,52,34, 1, 0,30,20, 0, 0,15, & - 0, 0, 0,35,54, 0,52,34, 1, 0,38,20, 0, 0,15, & - 0, 0, 0,35, 0, 0,52,34, 1, 0,38,20, 0, 0,15, & - 0, 0, 0,35, 0, 0,52, 0, 1, 0,38,20, 0, 0,15, & - 0, 0, 0,35, 0, 0,52, 0, 1, 0,38,20, 0, 0, 0, & - 0, 0, 0,35, 0, 0,52, 0, 0, 0,38,20, 0, 0, 0, & - 0, 0, 0,35, 0, 0,52, 0, 0, 0,38, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0,52, 0, 0, 0,38, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,38, 0, 0, 0, 0/ - -end module q65_generator - -module q65_encoding - -contains - -subroutine q65_encode(message,codeword) - use gf64math - use q65_generator - integer message(15) - integer codeword(65) - integer i,j - - codeword=0 - codeword(1:15)=message - do i=1,15 - do j=16,65 - codeword(j)=gf64_add(codeword(j),gf64_mult(message(i),generator(i,j-15))) - enddo - enddo - - return -end - -subroutine get_q65crc12(mc2,ncrc1,ncrc2) -! - character c6*6 - integer*1 mc(90),mc2(90),tmp(6) - integer*1 r(13),p(13) -! polynomial for 12-bit CRC 0xF01 - data p/1,1,0,0,0,0,0,0,0,1,1,1,1/ - -! flip bit order of each 6-bit symbol for consistency with Nico's calculation - do i=0,14 - tmp=mc2(i*6+1:i*6+6) - mc(i*6+1:i*6+6)=tmp(6:1:-1) - enddo - -! divide by polynomial - r=mc(1:13) - do i=0,77 - r(13)=mc(i+13) - r=mod(r+r(1)*p,2) - r=cshift(r,1) - enddo - - write(c6,'(6b1)') r(6:1:-1) - read(c6,'(b6.6)') ncrc1 - read(c6,'(6b1)') mc2(79:84) - write(c6,'(6b1)') r(12:7:-1) - read(c6,'(b6.6)') ncrc2 - read(c6,'(6b1)') mc2(85:90) - -end subroutine get_q65crc12 - -subroutine get_q65_tones(msg37,codeword,itone) - use packjt77 - implicit none - character*37 msg37 - character*77 c77 - character*6 c6 - integer codeword(65) - integer sync(22) - integer message(15) - integer shortcodeword(63) - integer itone(85) - integer i,j,k - integer*1 mbits(90) - integer i3,n3,ncrc1,ncrc2 - data sync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ - - i3=-1 - n3=-1 - call pack77(msg37,i3,n3,c77) - mbits=0 - read(c77,'(77i1)') mbits(1:77) - -! Message is 77 bits long. Add a 0 bit to create a 78-bit message and pad with -! 12 zeros to create 90-bit mbit array for CRC calculation. - call get_q65crc12(mbits,ncrc1,ncrc2) - -! Now have message in bits 1:78 and CRC in bits 79:90. -! Group message bits into 15 6-bit symbols: - do i=0,14 - write(c6,'(6i1)') mbits( (i*6+1):(i*6+6) ) - read(c6,'(b6.6)') message(i+1) - enddo - -! Encode to create a 65-symbol codeword - call q65_encode(message,codeword) - -!Shorten the codeword by omitting the CRC symbols (symbols 14 and 15) - shortcodeword(1:13)=codeword(1:13) - shortcodeword(14:63)=codeword(16:65) - -!Insert sync symbols to create array of channel symbols - j=1 - k=0 - do i=1,85 - if(i.eq.sync(j)) then - j=j+1 - itone(i)=0 - else - k=k+1 - itone(i)=shortcodeword(k)+1 - endif - enddo -end subroutine get_q65_tones - -end module q65_encoding +module gf64math +! add and subtract in GF(2^6) based on primitive polynomial x^6+x+1 + + implicit none + integer, private :: gf64log(0:63) + integer, private :: gf64antilog(0:62) + +! table of the logarithms of the elements of GF(M) (log(0) never used) + data gf64log/ & + -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, & + 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, & + 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, & + 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, & + 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, & + 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, & + 20, 59, 57, 58/ + +! table of GF(M) elements given their logarithm + data gf64antilog/ & + 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, & + 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, & + 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, & + 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, & + 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, & + 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, & + 57, 49, 33/ + +contains + + integer function gf64_add(i1,i2) + implicit none + integer::i1 + integer::i2 + gf64_add=iand(ieor(i1,i2),63) + end function gf64_add + + integer function gf64_mult(i1,i2) + implicit none + integer::i1 + integer::i2 + integer::j + + if(i1.eq.0 .or. i2.eq.0) then + gf64_mult=0 + elseif(i1.eq.1) then + gf64_mult=i2 + elseif(i2.eq.1) then + gf64_mult=i1 + else + j=mod(gf64log(i1)+gf64log(i2),63) + gf64_mult=gf64antilog(j) + endif + end function gf64_mult + +end module gf64math + +module q65_generator + + integer generator(15,50) + data generator/ & + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, & + 0,20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, & + 0,20, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, & + 0,20, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, & + 0,20, 0, 1, 1, 0, 0, 0,10, 0, 0, 0, 0, 1, 0, & + 0,20, 0, 1, 1, 0, 0, 0,10, 0, 0, 0,44, 1, 0, & + 0,20, 0, 1, 1, 0, 0, 0,10, 1, 0, 0,44, 1, 0, & + 0,20, 0, 1, 1, 0, 0, 0,10, 1, 0, 0,44, 1,14, & + 0,20, 0, 1, 1, 0, 0, 0,10, 1,31, 0,44, 1,14, & + 0,20, 0, 1, 1,33, 0, 0,10, 1,31, 0,44, 1,14, & + 56,20, 0, 1, 1,33, 0, 0,10, 1,31, 0,44, 1,14, & + 56,20, 0, 1, 1,33, 0, 1,10, 1,31, 0,44, 1,14, & + 56, 1, 0, 1, 1,33, 0, 1,10, 1,31, 0,44, 1,14, & + 56, 1, 0, 1, 1,33, 0, 1,10, 1,31,36,44, 1,14, & + 56, 1, 0, 1, 1,33, 0, 1,43, 1,31,36,44, 1,14, & + 56, 1, 0, 1, 1,33, 0, 1,43,17,31,36,44, 1,14, & + 56, 1, 0, 1, 1,33, 0, 1,43,17,31,36,36, 1,14, & + 56, 1, 0, 1, 1,33,53, 1,43,17,31,36,36, 1,14, & + 56, 1, 0,35, 1,33,53, 1,43,17,31,36,36, 1,14, & + 56, 1, 0,35, 1,33,53, 1,43,17,30,36,36, 1,14, & + 56, 1, 0,35, 1,33,53,52,43,17,30,36,36, 1,14, & + 56, 1, 0,35, 1,32,53,52,43,17,30,36,36, 1,14, & + 56, 1,60,35, 1,32,53,52,43,17,30,36,36, 1,14, & + 56, 1,60,35, 1,32,53,52,43,17,30,36,36,49,14, & + 56, 1,60,35, 1,32,53,52,43,17,30,36,37,49,14, & + 56, 1,60,35,54,32,53,52,43,17,30,36,37,49,14, & + 56, 1,60,35,54,32,53,52, 1,17,30,36,37,49,14, & + 1, 1,60,35,54,32,53,52, 1,17,30,36,37,49,14, & + 1, 0,60,35,54,32,53,52, 1,17,30,36,37,49,14, & + 1, 0,60,35,54,32,53,52, 1,17,30,37,37,49,14, & + 1, 0,61,35,54,32,53,52, 1,17,30,37,37,49,14, & + 1, 0,61,35,54,32,53,52, 1,48,30,37,37,49,14, & + 1, 0,61,35,54,32,53,52, 1,48,30,37,37,49,15, & + 1, 0,61,35,54, 0,53,52, 1,48,30,37,37,49,15, & + 1, 0,61,35,54, 0,52,52, 1,48,30,37,37,49,15, & + 1, 0,61,35,54, 0,52,52, 1,48,30,37,37, 0,15, & + 1, 0,61,35,54, 0,52,34, 1,48,30,37,37, 0,15, & + 1, 0,61,35,54, 0,52,34, 1,48,30,37, 0, 0,15, & + 1, 0,61,35,54, 0,52,34, 1,48,30,20, 0, 0,15, & + 1, 0, 0,35,54, 0,52,34, 1,48,30,20, 0, 0,15, & + 1, 0, 0,35,54, 0,52,34, 1, 0,30,20, 0, 0,15, & + 0, 0, 0,35,54, 0,52,34, 1, 0,30,20, 0, 0,15, & + 0, 0, 0,35,54, 0,52,34, 1, 0,38,20, 0, 0,15, & + 0, 0, 0,35, 0, 0,52,34, 1, 0,38,20, 0, 0,15, & + 0, 0, 0,35, 0, 0,52, 0, 1, 0,38,20, 0, 0,15, & + 0, 0, 0,35, 0, 0,52, 0, 1, 0,38,20, 0, 0, 0, & + 0, 0, 0,35, 0, 0,52, 0, 0, 0,38,20, 0, 0, 0, & + 0, 0, 0,35, 0, 0,52, 0, 0, 0,38, 0, 0, 0, 0, & + 0, 0, 0, 0, 0, 0,52, 0, 0, 0,38, 0, 0, 0, 0, & + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,38, 0, 0, 0, 0/ + +end module q65_generator + +module q65_encoding + +contains + +subroutine q65_encode(message,codeword) + use gf64math + use q65_generator + integer message(15) + integer codeword(65) + integer i,j + + codeword=0 + codeword(1:15)=message + do i=1,15 + do j=16,65 + codeword(j)=gf64_add(codeword(j),gf64_mult(message(i),generator(i,j-15))) + enddo + enddo + + return +end + +subroutine get_q65crc12(mc2,ncrc1,ncrc2) +! + character c6*6 + integer*1 mc(90),mc2(90),tmp(6) + integer*1 r(13),p(13) +! polynomial for 12-bit CRC 0xF01 + data p/1,1,0,0,0,0,0,0,0,1,1,1,1/ + +! flip bit order of each 6-bit symbol for consistency with Nico's calculation + do i=0,14 + tmp=mc2(i*6+1:i*6+6) + mc(i*6+1:i*6+6)=tmp(6:1:-1) + enddo + +! divide by polynomial + r=mc(1:13) + do i=0,77 + r(13)=mc(i+13) + r=mod(r+r(1)*p,2) + r=cshift(r,1) + enddo + + write(c6,'(6b1)') r(6:1:-1) + read(c6,'(b6.6)') ncrc1 + read(c6,'(6b1)') mc2(79:84) + write(c6,'(6b1)') r(12:7:-1) + read(c6,'(b6.6)') ncrc2 + read(c6,'(6b1)') mc2(85:90) + +end subroutine get_q65crc12 + +subroutine get_q65_tones(msg37,codeword,itone) + use packjt77 + implicit none + character*37 msg37 + character*77 c77 + character*6 c6 + integer codeword(65) + integer sync(22) + integer message(15) + integer shortcodeword(63) + integer itone(85) + integer i,j,k + integer*1 mbits(90) + integer i3,n3,ncrc1,ncrc2 + data sync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ + + i3=-1 + n3=-1 + call pack77(msg37,i3,n3,c77) + mbits=0 + read(c77,'(77i1)') mbits(1:77) + +! Message is 77 bits long. Add a 0 bit to create a 78-bit message and pad with +! 12 zeros to create 90-bit mbit array for CRC calculation. + call get_q65crc12(mbits,ncrc1,ncrc2) + +! Now have message in bits 1:78 and CRC in bits 79:90. +! Group message bits into 15 6-bit symbols: + do i=0,14 + write(c6,'(6i1)') mbits( (i*6+1):(i*6+6) ) + read(c6,'(b6.6)') message(i+1) + enddo + +! Encode to create a 65-symbol codeword + call q65_encode(message,codeword) + +!Shorten the codeword by omitting the CRC symbols (symbols 14 and 15) + shortcodeword(1:13)=codeword(1:13) + shortcodeword(14:63)=codeword(16:65) + +!Insert sync symbols to create array of channel symbols + j=1 + k=0 + do i=1,85 + if(i.eq.sync(j)) then + j=j+1 + itone(i)=0 + else + k=k+1 + itone(i)=shortcodeword(k)+1 + endif + enddo +end subroutine get_q65_tones + +end module q65_encoding diff --git a/lib/qra/q65/q65_ftn_test.f90 b/lib/qra/q65/q65_ftn_test.f90 index 5f4ac8a1..607d0f5b 100755 --- a/lib/qra/q65/q65_ftn_test.f90 +++ b/lib/qra/q65/q65_ftn_test.f90 @@ -1,51 +1,51 @@ -program q65_ftn_test - - use packjt77 - parameter (LL=192,NN=63) - integer x(13) !User's 78-bit message as 13 six-bit integers - integer y(63) !Q65 codeword for x - integer xdec(13) !Decoded message - integer APmask(13) - integer APsymbols(13) - real s3(0:LL-1,NN) - real s3prob(0:LL-1,NN) - character*37 msg0,msg,msgsent - character*77 c77 - logical unpk77_success - - narg=iargc() - if(narg.ne.1) then - print*,'Usage: q65_ftn_test "message"' - print*,'Example: q65_ftn_test "K1ABC W9XYZ EN37"' - go to 999 - endif - call getarg(1,msg0) - call pack77(msg0,i3,n3,c77) - call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent - read(c77,1000) x -1000 format(12b6.6,b5.5) - - call q65_enc(x,y) !Encode message, x(1:13) ==> y(1:63) - - write(*,1010) x,msg0 -1010 format('User message:'/13i3,2x,a) - write(*,1020) y -1020 format(/'Generated codeword:'/(20i3)) - - s3=0. - s3prob=0. - do j=1,NN - s3(y(j)+64,j)=1.0 - enddo - APmask=0 - APsymbols=0 - nsubmode=0 - b90=1.0 - nFadingModel=1 - call q65_dec(s3,APmask,APsymbols,nsubmode,b90,nFadingModel,s3prob,snr2500,xdec,irc) - write(c77,1000) xdec - call unpack77(c77,0,msg,unpk77_success) !Unpack to get msgsent - write(*,1100) xdec,trim(msg) -1100 format(/'Decoded message:'/13i3,2x,a) - -999 end program q65_ftn_test +program q65_ftn_test + + use packjt77 + parameter (LL=192,NN=63) + integer x(13) !User's 78-bit message as 13 six-bit integers + integer y(63) !Q65 codeword for x + integer xdec(13) !Decoded message + integer APmask(13) + integer APsymbols(13) + real s3(0:LL-1,NN) + real s3prob(0:LL-1,NN) + character*37 msg0,msg,msgsent + character*77 c77 + logical unpk77_success + + narg=iargc() + if(narg.ne.1) then + print*,'Usage: q65_ftn_test "message"' + print*,'Example: q65_ftn_test "K1ABC W9XYZ EN37"' + go to 999 + endif + call getarg(1,msg0) + call pack77(msg0,i3,n3,c77) + call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent + read(c77,1000) x +1000 format(12b6.6,b5.5) + + call q65_enc(x,y) !Encode message, x(1:13) ==> y(1:63) + + write(*,1010) x,msg0 +1010 format('User message:'/13i3,2x,a) + write(*,1020) y +1020 format(/'Generated codeword:'/(20i3)) + + s3=0. + s3prob=0. + do j=1,NN + s3(y(j)+64,j)=1.0 + enddo + APmask=0 + APsymbols=0 + nsubmode=0 + b90=1.0 + nFadingModel=1 + call q65_dec(s3,APmask,APsymbols,nsubmode,b90,nFadingModel,s3prob,snr2500,xdec,irc) + write(c77,1000) xdec + call unpack77(c77,0,msg,unpk77_success) !Unpack to get msgsent + write(*,1100) xdec,trim(msg) +1100 format(/'Decoded message:'/13i3,2x,a) + +999 end program q65_ftn_test diff --git a/lib/qra/q65/q65_loops.f90 b/lib/qra/q65/q65_loops.f90 index c4f3f2f6..3220648e 100755 --- a/lib/qra/q65/q65_loops.f90 +++ b/lib/qra/q65/q65_loops.f90 @@ -1,101 +1,101 @@ -subroutine q65_loops(c00,npts2,nsps2,nsubmode,ndepth,jpk0, & - xdt0,f0,iaptype,xdt1,f1,snr2,dat4,idec) - - use packjt77 - use timer_module, only: timer - use q65 - - parameter (NN=63) - parameter (LN=2176*63) !LN=LL*NN; LL=64*(mode_q65+2), NN=63 - complex c00(0:npts2-1) !Analytic representation of dd(), 6000 Hz - complex ,allocatable :: c0(:) !Ditto, with freq shift - character decoded*37 - real a(3) !twkfreq params f,f1,f2 - real,allocatable :: s3(:) !Symbol spectra - integer dat4(13) !Decoded message (as 13 six-bit integers) - integer nap(0:11) !AP return codes - data nap/0,2,3,2,3,4,2,3,6,4,6,6/ - - LL=64*(mode_q65+2) - allocate(s3(LL*NN)) - allocate(c0(0:npts2-1)) - idec=-1 - ircbest=9999 - irc=-99 - s3lim=20. - baud=6000.0/nsps2 - - idfmax=1 - idtmax=1 - maxdist=4 - ibw0=(ibwa+ibwb)/2 - if(iand(ndepth,3).eq.2) then - idfmax=3 - idtmax=3 - maxdist=5 - endif - if(iand(ndepth,3).eq.3) then - idfmax=5 - idtmax=5 - maxdist=5 - endif - - napmin=99 - xdt1=xdt0 - f1=f0 - idfbest=0 - idtbest=0 - ndistbest=0 - - do idf=1,idfmax - ndf=idf/2 - if(mod(idf,2).eq.0) ndf=-ndf - a=0. - a(1)=-(f0+0.5*baud*ndf) -! Variable 'drift' is frequency increase over full TxT. Therefore we want: - a(2)=-0.5*drift - call twkfreq(c00,c0,npts2,6000.0,a) - do idt=1,idtmax - ndt=idt/2 - if(mod(idt,2).eq.0) ndt=-ndt - jpk=jpk0 + nsps2*ndt/16 !tsym/16 - jpk=max(0,jpk) - jpk=min(29000,jpk) - call spec64(c0,npts2,nsps2,mode_q65,jpk,s3,LL,NN) - call pctile(s3,LL*NN,40,base) - s3=s3/base - where(s3(1:LL*NN)>s3lim) s3(1:LL*NN)=s3lim - call q65_bzap(s3,LL) !Zap birdies - do ibw=ibwa,ibwb - ndist=ndf**2 + ndt**2 + (ibw-ibw0)**2 - if(ndist.gt.maxdist) cycle - b90=1.72**ibw - if(b90.gt.345.0) cycle - b90ts = b90/baud - call timer('dec2 ',0) - call q65_dec2(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) - call timer('dec2 ',1) - ! irc > 0 ==> number of iterations required to decode - ! -1 = invalid params - ! -2 = decode failed - ! -3 = CRC mismatch - if(irc.ge.0) then - idfbest=idf - idtbest=idt - ndistbest=ndist - nrc=irc - go to 100 - endif - enddo ! ibw (b90 loop) - enddo ! idt (DT loop) - enddo ! idf (f0 loop) - -100 if(irc.ge.0) then - idec=iaptype - snr2=esnodb - db(2500.0/baud) - xdt1=xdt0 + nsps2*ndt/(16.0*6000.0) - f1=f0 + 0.5*baud*ndf - endif - - return -end subroutine q65_loops +subroutine q65_loops(c00,npts2,nsps2,nsubmode,ndepth,jpk0, & + xdt0,f0,iaptype,xdt1,f1,snr2,dat4,idec) + + use packjt77 + use timer_module, only: timer + use q65 + + parameter (NN=63) + parameter (LN=2176*63) !LN=LL*NN; LL=64*(mode_q65+2), NN=63 + complex c00(0:npts2-1) !Analytic representation of dd(), 6000 Hz + complex ,allocatable :: c0(:) !Ditto, with freq shift + character decoded*37 + real a(3) !twkfreq params f,f1,f2 + real,allocatable :: s3(:) !Symbol spectra + integer dat4(13) !Decoded message (as 13 six-bit integers) + integer nap(0:11) !AP return codes + data nap/0,2,3,2,3,4,2,3,6,4,6,6/ + + LL=64*(mode_q65+2) + allocate(s3(LL*NN)) + allocate(c0(0:npts2-1)) + idec=-1 + ircbest=9999 + irc=-99 + s3lim=20. + baud=6000.0/nsps2 + + idfmax=1 + idtmax=1 + maxdist=4 + ibw0=(ibwa+ibwb)/2 + if(iand(ndepth,3).eq.2) then + idfmax=3 + idtmax=3 + maxdist=5 + endif + if(iand(ndepth,3).eq.3) then + idfmax=5 + idtmax=5 + maxdist=5 + endif + + napmin=99 + xdt1=xdt0 + f1=f0 + idfbest=0 + idtbest=0 + ndistbest=0 + + do idf=1,idfmax + ndf=idf/2 + if(mod(idf,2).eq.0) ndf=-ndf + a=0. + a(1)=-(f0+0.5*baud*ndf) +! Variable 'drift' is frequency increase over full TxT. Therefore we want: + a(2)=-0.5*drift + call twkfreq(c00,c0,npts2,6000.0,a) + do idt=1,idtmax + ndt=idt/2 + if(mod(idt,2).eq.0) ndt=-ndt + jpk=jpk0 + nsps2*ndt/16 !tsym/16 + jpk=max(0,jpk) + jpk=min(29000,jpk) + call spec64(c0,npts2,nsps2,mode_q65,jpk,s3,LL,NN) + call pctile(s3,LL*NN,40,base) + s3=s3/base + where(s3(1:LL*NN)>s3lim) s3(1:LL*NN)=s3lim + call q65_bzap(s3,LL) !Zap birdies + do ibw=ibwa,ibwb + ndist=ndf**2 + ndt**2 + (ibw-ibw0)**2 + if(ndist.gt.maxdist) cycle + b90=1.72**ibw + if(b90.gt.345.0) cycle + b90ts = b90/baud + call timer('dec2 ',0) + call q65_dec2(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) + call timer('dec2 ',1) + ! irc > 0 ==> number of iterations required to decode + ! -1 = invalid params + ! -2 = decode failed + ! -3 = CRC mismatch + if(irc.ge.0) then + idfbest=idf + idtbest=idt + ndistbest=ndist + nrc=irc + go to 100 + endif + enddo ! ibw (b90 loop) + enddo ! idt (DT loop) + enddo ! idf (f0 loop) + +100 if(irc.ge.0) then + idec=iaptype + snr2=esnodb - db(2500.0/baud) + xdt1=xdt0 + nsps2*ndt/(16.0*6000.0) + f1=f0 + 0.5*baud*ndf + endif + + return +end subroutine q65_loops diff --git a/lib/qra/q65/q65_set_list.f90 b/lib/qra/q65/q65_set_list.f90 index 0debe2c6..0b836bde 100755 --- a/lib/qra/q65/q65_set_list.f90 +++ b/lib/qra/q65/q65_set_list.f90 @@ -1,97 +1,97 @@ -subroutine q65_set_list(mycall,hiscall,hisgrid,codewords,ncw) - - parameter (MAX_NCW=206) - character*12 mycall,hiscall - character*6 hisgrid - character*37 msg,msgsent - logical my_std,his_std - integer codewords(63,MAX_NCW) - integer itone(85) - integer isync(22) - data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ - - ncw=0 - if(hiscall(1:1).eq. ' ') return - call stdcall(mycall,my_std) - call stdcall(hiscall,his_std) - - ncw=MAX_NCW - do i=1,ncw - msg=trim(mycall)//' '//trim(hiscall) - if(.not.my_std) then - if(i.eq.1 .or. i.ge.6) msg='<'//trim(mycall)//'> '//trim(hiscall) - if(i.ge.2 .and. i.le.4) msg=trim(mycall)//' <'//trim(hiscall)//'>' - else if(.not.his_std) then - if(i.le.4 .or. i.eq.6) msg='<'//trim(mycall)//'> '//trim(hiscall) - if(i.ge.7) msg=trim(mycall)//' <'//trim(hiscall)//'>' - endif - j0=len(trim(msg))+2 - if(i.eq.2) msg(j0:j0+2)='RRR' - if(i.eq.3) msg(j0:j0+3)='RR73' - if(i.eq.4) msg(j0:j0+1)='73' - if(i.eq.5) then - if(his_std) msg='CQ '//trim(hiscall)//' '//hisgrid(1:4) - if(.not.his_std) msg='CQ '//trim(hiscall) - endif - if(i.eq.6 .and. his_std) msg(j0:j0+3)=hisgrid(1:4) - if(i.ge.7 .and. i.le.206) then - isnr = -50 + (i-7)/2 - if(iand(i,1).eq.1) then - write(msg(j0:j0+2),'(i3.2)') isnr - if(msg(j0:j0).eq.' ') msg(j0:j0)='+' - else - write(msg(j0:j0+3),'("R",i3.2)') isnr - if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' - endif - endif - - call genq65(msg,0,msgsent,itone,i3,n3) - i0=1 - j=0 - do k=1,85 - if(k.eq.isync(i0)) then - i0=i0+1 - cycle - endif - j=j+1 - codewords(j,i)=itone(k) - 1 - enddo -! write(71,3001) i,isnr,codewords(1:13,i),trim(msg) -!3001 format(i3,2x,i3.2,2x,13i3,2x,a) - enddo - - return -end subroutine q65_set_list - -subroutine stdcall(callsign,std) - - character*12 callsign - character*1 c - logical is_digit,is_letter,std -!Statement functions: - is_digit(c)=c.ge.'0' .and. c.le.'9' - is_letter(c)=c.ge.'A' .and. c.le.'Z' - -! Check for standard callsign - iarea=-1 - n=len(trim(callsign)) - do i=n,2,-1 - if(is_digit(callsign(i:i))) exit - enddo - iarea=i !Right-most digit (call area) - npdig=0 !Digits before call area - nplet=0 !Letters before call area - do i=1,iarea-1 - if(is_digit(callsign(i:i))) npdig=npdig+1 - if(is_letter(callsign(i:i))) nplet=nplet+1 - enddo - nslet=0 !Letters in suffix - do i=iarea+1,n - if(is_letter(callsign(i:i))) nslet=nslet+1 - enddo - std=.true. - if(iarea.lt.2 .or. iarea.gt.3 .or. nplet.eq.0 .or. & - npdig.ge.iarea-1 .or. nslet.gt.3) std=.false. - - return -end subroutine stdcall +subroutine q65_set_list(mycall,hiscall,hisgrid,codewords,ncw) + + parameter (MAX_NCW=206) + character*12 mycall,hiscall + character*6 hisgrid + character*37 msg,msgsent + logical my_std,his_std + integer codewords(63,MAX_NCW) + integer itone(85) + integer isync(22) + data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ + + ncw=0 + if(hiscall(1:1).eq. ' ') return + call stdcall(mycall,my_std) + call stdcall(hiscall,his_std) + + ncw=MAX_NCW + do i=1,ncw + msg=trim(mycall)//' '//trim(hiscall) + if(.not.my_std) then + if(i.eq.1 .or. i.ge.6) msg='<'//trim(mycall)//'> '//trim(hiscall) + if(i.ge.2 .and. i.le.4) msg=trim(mycall)//' <'//trim(hiscall)//'>' + else if(.not.his_std) then + if(i.le.4 .or. i.eq.6) msg='<'//trim(mycall)//'> '//trim(hiscall) + if(i.ge.7) msg=trim(mycall)//' <'//trim(hiscall)//'>' + endif + j0=len(trim(msg))+2 + if(i.eq.2) msg(j0:j0+2)='RRR' + if(i.eq.3) msg(j0:j0+3)='RR73' + if(i.eq.4) msg(j0:j0+1)='73' + if(i.eq.5) then + if(his_std) msg='CQ '//trim(hiscall)//' '//hisgrid(1:4) + if(.not.his_std) msg='CQ '//trim(hiscall) + endif + if(i.eq.6 .and. his_std) msg(j0:j0+3)=hisgrid(1:4) + if(i.ge.7 .and. i.le.206) then + isnr = -50 + (i-7)/2 + if(iand(i,1).eq.1) then + write(msg(j0:j0+2),'(i3.2)') isnr + if(msg(j0:j0).eq.' ') msg(j0:j0)='+' + else + write(msg(j0:j0+3),'("R",i3.2)') isnr + if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' + endif + endif + + call genq65(msg,0,msgsent,itone,i3,n3) + i0=1 + j=0 + do k=1,85 + if(k.eq.isync(i0)) then + i0=i0+1 + cycle + endif + j=j+1 + codewords(j,i)=itone(k) - 1 + enddo +! write(71,3001) i,isnr,codewords(1:13,i),trim(msg) +!3001 format(i3,2x,i3.2,2x,13i3,2x,a) + enddo + + return +end subroutine q65_set_list + +subroutine stdcall(callsign,std) + + character*12 callsign + character*1 c + logical is_digit,is_letter,std +!Statement functions: + is_digit(c)=c.ge.'0' .and. c.le.'9' + is_letter(c)=c.ge.'A' .and. c.le.'Z' + +! Check for standard callsign + iarea=-1 + n=len(trim(callsign)) + do i=n,2,-1 + if(is_digit(callsign(i:i))) exit + enddo + iarea=i !Right-most digit (call area) + npdig=0 !Digits before call area + nplet=0 !Letters before call area + do i=1,iarea-1 + if(is_digit(callsign(i:i))) npdig=npdig+1 + if(is_letter(callsign(i:i))) nplet=nplet+1 + enddo + nslet=0 !Letters in suffix + do i=iarea+1,n + if(is_letter(callsign(i:i))) nslet=nslet+1 + enddo + std=.true. + if(iarea.lt.2 .or. iarea.gt.3 .or. nplet.eq.0 .or. & + npdig.ge.iarea-1 .or. nslet.gt.3) std=.false. + + return +end subroutine stdcall diff --git a/lib/qra/q65/q65_set_list2.f90 b/lib/qra/q65/q65_set_list2.f90 index 76797a0e..39147e61 100755 --- a/lib/qra/q65/q65_set_list2.f90 +++ b/lib/qra/q65/q65_set_list2.f90 @@ -1,70 +1,70 @@ -subroutine q65_set_list2(mycall,hiscall,hisgrid,callers,nhist2,codewords,ncw) - - use types - parameter (MAX_NCW=206) - parameter (MAX_CALLERS=40) !For multiple q3 decodes in NA VHf Contest mode - character*12 mycall,hiscall - character*6 hisgrid,c6 - character*4 g4 - character*37 msg,msgsent - logical std,isgrid - integer codewords(63,MAX_NCW) - integer itone(85) - integer isync(22) - type(q3list) callers(MAX_CALLERS) - - data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ - - isgrid(g4)=g4(1:1).ge.'A' .and. g4(1:1).le.'R' .and. g4(2:2).ge.'A' .and. & - g4(2:2).le.'R' .and. g4(3:3).ge.'0' .and. g4(3:3).le.'9' .and. & - g4(4:4).ge.'0' .and. g4(4:4).le.'9' .and. g4(1:4).ne.'RR73' - - call stdcall(hiscall,std) - jmax=nhist2 - if(std .and. isgrid(hisgrid(1:4))) then - jmax=min(MAX_CALLERS,nhist2+1) - do j=1,nhist2 - if(callers(j)%call .eq. hiscall(1:6)) then - jmax=nhist2 - exit - endif - enddo - endif - - codewords(:,1)=0 - i=1 - do j=1,jmax - c6=callers(j)%call - g4=callers(j)%grid - if(j.eq.nhist2+1) then - c6=hiscall(1:6) - g4=hisgrid(1:4) - endif - do k=1,5 - i=i+1 - msg=trim(mycall)//' '//trim(c6) - j0=len(trim(msg))+1 - if(k.eq.1) msg=msg(1:j0)//g4 - if(k.eq.2) msg=msg(1:j0)//'R '//g4 - if(k.eq.3) msg(j0:j0+3)=' RRR' - if(k.eq.4) msg(j0:j0+4)=' RR73' - if(k.eq.5) msg(j0:j0+2)=' 73' - call genq65(msg,0,msgsent,itone,i3,n3) - i0=1 - jj=0 - do kk=1,85 - if(kk.eq.isync(i0)) then - i0=i0+1 - cycle - endif - jj=jj+1 - codewords(jj,i)=itone(kk) - 1 - enddo -! write(71,3001) i,j,k,codewords(1:13,i),trim(msg) -!3001 format(3i3,2x,13i3,2x,a) - enddo - enddo - ncw=i - - return -end subroutine q65_set_list2 +subroutine q65_set_list2(mycall,hiscall,hisgrid,callers,nhist2,codewords,ncw) + + use types + parameter (MAX_NCW=206) + parameter (MAX_CALLERS=40) !For multiple q3 decodes in NA VHf Contest mode + character*12 mycall,hiscall + character*6 hisgrid,c6 + character*4 g4 + character*37 msg,msgsent + logical std,isgrid + integer codewords(63,MAX_NCW) + integer itone(85) + integer isync(22) + type(q3list) callers(MAX_CALLERS) + + data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ + + isgrid(g4)=g4(1:1).ge.'A' .and. g4(1:1).le.'R' .and. g4(2:2).ge.'A' .and. & + g4(2:2).le.'R' .and. g4(3:3).ge.'0' .and. g4(3:3).le.'9' .and. & + g4(4:4).ge.'0' .and. g4(4:4).le.'9' .and. g4(1:4).ne.'RR73' + + call stdcall(hiscall,std) + jmax=nhist2 + if(std .and. isgrid(hisgrid(1:4))) then + jmax=min(MAX_CALLERS,nhist2+1) + do j=1,nhist2 + if(callers(j)%call .eq. hiscall(1:6)) then + jmax=nhist2 + exit + endif + enddo + endif + + codewords(:,1)=0 + i=1 + do j=1,jmax + c6=callers(j)%call + g4=callers(j)%grid + if(j.eq.nhist2+1) then + c6=hiscall(1:6) + g4=hisgrid(1:4) + endif + do k=1,5 + i=i+1 + msg=trim(mycall)//' '//trim(c6) + j0=len(trim(msg))+1 + if(k.eq.1) msg=msg(1:j0)//g4 + if(k.eq.2) msg=msg(1:j0)//'R '//g4 + if(k.eq.3) msg(j0:j0+3)=' RRR' + if(k.eq.4) msg(j0:j0+4)=' RR73' + if(k.eq.5) msg(j0:j0+2)=' 73' + call genq65(msg,0,msgsent,itone,i3,n3) + i0=1 + jj=0 + do kk=1,85 + if(kk.eq.isync(i0)) then + i0=i0+1 + cycle + endif + jj=jj+1 + codewords(jj,i)=itone(kk) - 1 + enddo +! write(71,3001) i,j,k,codewords(1:13,i),trim(msg) +!3001 format(3i3,2x,13i3,2x,a) + enddo + enddo + ncw=i + + return +end subroutine q65_set_list2 diff --git a/lib/qra/q65/q65_subs.c b/lib/qra/q65/q65_subs.c index 6b744e0d..4311ba39 100755 --- a/lib/qra/q65/q65_subs.c +++ b/lib/qra/q65/q65_subs.c @@ -1,147 +1,147 @@ -// q65_subs.c - -/* Fortran interface for Q65 codec - - To encode a Q65 message: - - integer x(13) !Message payload, 78 bits as 13 six-bit integers - integer y(63) !Codeword, 63 six-bit integers - call q65_enc(imsg,icodeword) - - To decode a Q65 message: - - parameter (LL=64,NN=63) - real s3(LL,NN) !Received energies - real s3prob(LL,NN) !Symbol-value probabilities - integer APmask(13) - integer APsymbols(13) - real snr2500 - integer xdec(13) !Decoded 78-bit message as 13 six-bit integers - integer irc !Return code from q65_decode() - - call q65_dec(s3,APmask,APsymbols,s3prob,snr2500,xdec,irc) -*/ - -#include "qra15_65_64_irr_e23.h" // QRA code used by Q65 -#include "q65.h" -#include -#include - -static q65_codec_ds codec; - -void q65_enc_(int x[], int y[]) -{ - - static int first=1; - if (first) { - // Set the QRA code, allocate memory, and initialize - int rc = q65_init(&codec,&qra15_65_64_irr_e23); - if (rc<0) { - printf("error in q65_init()\n"); - exit(0); - } - first=0; - } - // Encode message x[13], producing codeword y[63] - q65_encode(&codec,y,x); -} - -void q65_intrinsics_ff_(float s3[], int* submode, float* B90Ts, - int* fadingModel, float s3prob[]) -{ - -/* Input: s3[LL,NN] Received energies - * submode 0=A, 4=E - * B90 Spread bandwidth, 90% fractional energy - * fadingModel 0=Gaussian, 1=Lorentzian - * Output: s3prob[LL,NN] Symbol-value intrinsic probabilities - */ - - int rc; - static int first=1; - - if (first) { - // Set the QRA code, allocate memory, and initialize - int rc = q65_init(&codec,&qra15_65_64_irr_e23); - if (rc<0) { - printf("error in q65_init()\n"); - exit(0); - } - first=0; - } - rc = q65_intrinsics_fastfading(&codec,s3prob,s3,*submode,*B90Ts,*fadingModel); - if(rc<0) { - printf("error in q65_intrinsics()\n"); - exit(0); - } -} - -void q65_dec_(float s3[], float s3prob[], int APmask[], int APsymbols[], - int* maxiters0, float* esnodb0, int xdec[], int* rc0) -{ - -/* Input: s3[LL,NN] Symbol spectra - * s3prob[LL,NN] Symbol-value intrinsic probabilities - * APmask[13] AP information to be used in decoding - * APsymbols[13] Available AP informtion - * Output: - * esnodb0 Estimated Es/No (dB) - * xdec[13] Decoded 78-bit message as 13 six-bit integers - * rc0 Return code from q65_decode() - */ - - int rc; - int ydec[63]; - float esnodb; - int maxiters=*maxiters0; - - rc = q65_decode(&codec,ydec,xdec,s3prob,APmask,APsymbols,maxiters); - *rc0=rc; - // rc = -1: Invalid params - // rc = -2: Decode failed - // rc = -3: CRC mismatch - *esnodb0 = 0.0; //Default Es/No for a failed decode - if(rc<0) return; - - rc = q65_esnodb_fastfading(&codec,&esnodb,ydec,s3); - if(rc<0) { - printf("error in q65_esnodb_fastfading()\n"); - exit(0); - } - *esnodb0 = esnodb; -} - -void q65_dec_fullaplist_(float s3[], float s3prob[], int codewords[], - int* ncw, float* esnodb0, int xdec[], float* plog, int* rc0) -{ -/* Input: s3[LL,NN] Symbol spectra - * s3prob[LL,NN] Symbol-value intrinsic probabilities - * codewords[63,ncw] Full codewords to search for - * ncw Number of codewords - * Output: - * esnodb0 Estimated Es/No (dB) - * xdec[13] Decoded 78-bit message as 13 six-bit integers - * rc0 Return code from q65_decode() - */ - - int rc; - int ydec[63]; - float esnodb; - - rc = q65_decode_fullaplist(&codec,ydec,xdec,s3prob,codewords,*ncw); - *plog=q65_llh; - *rc0=rc; - - // rc = -1: Invalid params - // rc = -2: Decode failed - // rc = -3: CRC mismatch - *esnodb0 = 0.0; //Default Es/No for a failed decode - if(rc<0) return; - - rc = q65_esnodb_fastfading(&codec,&esnodb,ydec,s3); - if(rc<0) { - printf("error in q65_esnodb_fastfading()\n"); - exit(0); - } - *esnodb0 = esnodb; -} +// q65_subs.c + +/* Fortran interface for Q65 codec + + To encode a Q65 message: + + integer x(13) !Message payload, 78 bits as 13 six-bit integers + integer y(63) !Codeword, 63 six-bit integers + call q65_enc(imsg,icodeword) + + To decode a Q65 message: + + parameter (LL=64,NN=63) + real s3(LL,NN) !Received energies + real s3prob(LL,NN) !Symbol-value probabilities + integer APmask(13) + integer APsymbols(13) + real snr2500 + integer xdec(13) !Decoded 78-bit message as 13 six-bit integers + integer irc !Return code from q65_decode() + + call q65_dec(s3,APmask,APsymbols,s3prob,snr2500,xdec,irc) +*/ + +#include "qra15_65_64_irr_e23.h" // QRA code used by Q65 +#include "q65.h" +#include +#include + +static q65_codec_ds codec; + +void q65_enc_(int x[], int y[]) +{ + + static int first=1; + if (first) { + // Set the QRA code, allocate memory, and initialize + int rc = q65_init(&codec,&qra15_65_64_irr_e23); + if (rc<0) { + printf("error in q65_init()\n"); + exit(0); + } + first=0; + } + // Encode message x[13], producing codeword y[63] + q65_encode(&codec,y,x); +} + +void q65_intrinsics_ff_(float s3[], int* submode, float* B90Ts, + int* fadingModel, float s3prob[]) +{ + +/* Input: s3[LL,NN] Received energies + * submode 0=A, 4=E + * B90 Spread bandwidth, 90% fractional energy + * fadingModel 0=Gaussian, 1=Lorentzian + * Output: s3prob[LL,NN] Symbol-value intrinsic probabilities + */ + + int rc; + static int first=1; + + if (first) { + // Set the QRA code, allocate memory, and initialize + int rc = q65_init(&codec,&qra15_65_64_irr_e23); + if (rc<0) { + printf("error in q65_init()\n"); + exit(0); + } + first=0; + } + rc = q65_intrinsics_fastfading(&codec,s3prob,s3,*submode,*B90Ts,*fadingModel); + if(rc<0) { + printf("error in q65_intrinsics()\n"); + exit(0); + } +} + +void q65_dec_(float s3[], float s3prob[], int APmask[], int APsymbols[], + int* maxiters0, float* esnodb0, int xdec[], int* rc0) +{ + +/* Input: s3[LL,NN] Symbol spectra + * s3prob[LL,NN] Symbol-value intrinsic probabilities + * APmask[13] AP information to be used in decoding + * APsymbols[13] Available AP informtion + * Output: + * esnodb0 Estimated Es/No (dB) + * xdec[13] Decoded 78-bit message as 13 six-bit integers + * rc0 Return code from q65_decode() + */ + + int rc; + int ydec[63]; + float esnodb; + int maxiters=*maxiters0; + + rc = q65_decode(&codec,ydec,xdec,s3prob,APmask,APsymbols,maxiters); + *rc0=rc; + // rc = -1: Invalid params + // rc = -2: Decode failed + // rc = -3: CRC mismatch + *esnodb0 = 0.0; //Default Es/No for a failed decode + if(rc<0) return; + + rc = q65_esnodb_fastfading(&codec,&esnodb,ydec,s3); + if(rc<0) { + printf("error in q65_esnodb_fastfading()\n"); + exit(0); + } + *esnodb0 = esnodb; +} + +void q65_dec_fullaplist_(float s3[], float s3prob[], int codewords[], + int* ncw, float* esnodb0, int xdec[], float* plog, int* rc0) +{ +/* Input: s3[LL,NN] Symbol spectra + * s3prob[LL,NN] Symbol-value intrinsic probabilities + * codewords[63,ncw] Full codewords to search for + * ncw Number of codewords + * Output: + * esnodb0 Estimated Es/No (dB) + * xdec[13] Decoded 78-bit message as 13 six-bit integers + * rc0 Return code from q65_decode() + */ + + int rc; + int ydec[63]; + float esnodb; + + rc = q65_decode_fullaplist(&codec,ydec,xdec,s3prob,codewords,*ncw); + *plog=q65_llh; + *rc0=rc; + + // rc = -1: Invalid params + // rc = -2: Decode failed + // rc = -3: CRC mismatch + *esnodb0 = 0.0; //Default Es/No for a failed decode + if(rc<0) return; + + rc = q65_esnodb_fastfading(&codec,&esnodb,ydec,s3); + if(rc<0) { + printf("error in q65_esnodb_fastfading()\n"); + exit(0); + } + *esnodb0 = esnodb; +} diff --git a/lib/qra/q65/q65code.f90 b/lib/qra/q65/q65code.f90 index 9f5515b0..d61cba91 100755 --- a/lib/qra/q65/q65code.f90 +++ b/lib/qra/q65/q65code.f90 @@ -1,29 +1,29 @@ -program q65code - use q65_encoding - - implicit none - character*37 msg37 - integer nargs - integer codeword(65),tones(85) - - nargs=iargc() - if(nargs .ne. 1) then - print*,'Usage: q65code "msg"' - goto 999 - endif - call getarg(1,msg37) - - call get_q65_tones(msg37,codeword,tones) - - write(*,*) 'Generated message plus CRC (90 bits)' - write(*,'(a8,15i4)') '6 bit : ',codeword(1:15) - write(*,'(a8,15b6.6)') 'binary: ',codeword(1:15) - write(*,*) ' ' - write(*,*) 'Codeword with CRC symbols (65 symbols)' - write(*,'(20i3)') codeword - - write(*,*) ' ' - write(*,*) 'Channel symbols (85 total)' - write(*,'(20i3)') tones - -999 end program q65code +program q65code + use q65_encoding + + implicit none + character*37 msg37 + integer nargs + integer codeword(65),tones(85) + + nargs=iargc() + if(nargs .ne. 1) then + print*,'Usage: q65code "msg"' + goto 999 + endif + call getarg(1,msg37) + + call get_q65_tones(msg37,codeword,tones) + + write(*,*) 'Generated message plus CRC (90 bits)' + write(*,'(a8,15i4)') '6 bit : ',codeword(1:15) + write(*,'(a8,15b6.6)') 'binary: ',codeword(1:15) + write(*,*) ' ' + write(*,*) 'Codeword with CRC symbols (65 symbols)' + write(*,'(20i3)') codeword + + write(*,*) ' ' + write(*,*) 'Channel symbols (85 total)' + write(*,'(20i3)') tones + +999 end program q65code diff --git a/lib/qra/q65/q65sim.f90 b/lib/qra/q65/q65sim.f90 index 04c064e3..cfe3a02d 100755 --- a/lib/qra/q65/q65sim.f90 +++ b/lib/qra/q65/q65sim.f90 @@ -1,247 +1,247 @@ -program q65sim - -! Generate simulated Q65 data for testing the decoder. - - use wavhdr - use packjt - parameter (NMAX=300*12000) !Total samples in .wav file - type(hdr) h !Header for .wav file - integer*2 iwave(NMAX) !Generated waveform - integer itone(85) !Channel symbols (values 0-65) - integer ntone(85,10) !Channel symbols for up to 10 messages - integer y(63) !Codeword - integer istart !averaging compatible start seconds - integer imins !minutes for 15s period timestamp - integer isecs !seconds for 15s period timestamp - real*4 xnoise(NMAX) !Generated random noise - real*4 dat(NMAX) !Generated real data - complex cdat(NMAX) !Generated complex waveform - complex cspread(0:NMAX-1) !Complex amplitude for Rayleigh fading - complex z - real*8 f00,f0,dt,twopi,phi,dphi,baud,fsample,freq - character fname*17,csubmode*1,arg*12,c2*2 - character*37 msg,msgsent,imsg(10) - - nargs=iargc() - if(nargs.ne.11) then - print*,'Usage: q65sim "msg" A-E freq fDop DT f1 Stp TRp Nsig Nfile SNR' - print*,'Example: q65sim "K1ABC W9XYZ EN37" A 1500 0.0 0.0 0.0 1 60 1 1 -26' - print*,'Example: q65sim "ST" A 1500 0.0 0.0 0.0 1 60 1 -26' - print*,' fDop = Doppler spread' - print*,' f1 = Drift or Doppler rate (Hz/min)' - print*,' Stp = Step size (Hz)' - print*,' Stp = 0 implies no Doppler tracking' - print*,' Nsig = number of generated signals, 1 - 10' - print*,' Creates filenames which increment to permit averaging in first period' - print*,' If msg = ST program produces a single tone at freq' - go to 999 - endif - call getarg(1,msg) - call getarg(2,csubmode) - mode65=2**(ichar(csubmode)-ichar('A')) - call getarg(3,arg) - read(arg,*) f00 - call getarg(4,arg) - read(arg,*) fspread - call getarg(5,arg) - read(arg,*) xdt - call getarg(6,arg) - read(arg,*) f1 - call getarg(7,arg) - read(arg,*) nstp - call getarg(8,arg) - read(arg,*) ntrperiod - call getarg(9,arg) - read(arg,*) nsig - call getarg(10,arg) - read(arg,*) nfiles - call getarg(11,arg) - read(arg,*) snrdb - - if(ntrperiod.eq.15) then - nsps=1800 - else if(ntrperiod.eq.30) then - nsps=3600 - else if(ntrperiod.eq.60) then - nsps=7200 - else if(ntrperiod.eq.120) then - nsps=16000 - else if(ntrperiod.eq.300) then - nsps=41472 - else - print*,'Invalid TR period' - go to 999 - endif - - rms=100. - fsample=12000.d0 !Sample rate (Hz) - npts=fsample*ntrperiod !Total samples in .wav file - nfft=npts - nh=nfft/2 - dt=1.d0/fsample !Sample interval (s) - twopi=8.d0*atan(1.d0) - nsym=85 !Number of channel symbols - mode65=2**(ichar(csubmode) - ichar('A')) - - - imsg(1)=msg - if(nsig.ge.2) then - i0=index(msg,' ') - i0=i0 + index(msg(i0+1:),' ')-2 - do i=1,nsig - c2=char(ichar('A')+i-1)//char(ichar('A')+i-1) - imsg(i)=msg(1:i0-1)//c2//msg(i0+2:) - enddo - endif - - ichk=0 - do i=1,nsig - msg=imsg(i) - call genq65(msg,ichk,msgsent,itone,i3,n3) - ntone(:,i)=itone - enddo - - if(nsig.eq.1) then - j=0 - do i=1,85 - if(itone(i).gt.0) then - j=j+1 - y(j)=itone(i)-1 - endif - enddo - write(*,1001) y(1:13),y(1:13) -1001 format('Generated message'/'6-bit: ',13i3/'binary: ',13b6.6) - write(*,1002) y -1002 format(/'Codeword:'/(20i3)) - write(*,1003) itone -1003 format(/'Channel symbols:'/(20i3)) - endif - - baud=12000.d0/nsps !Keying rate (6.67 baud fot 15-s sequences) - h=default_header(12000,npts) - - write(*,1004) -1004 format('File TR Freq Mode S/N Dop DT f1 Stp Message'/70('-')) - - do ifile=1,nfiles !Loop over requested number of files - istart = (ifile*ntrperiod*2) - (ntrperiod*2) - if(ntrperiod.lt.30) then !wdg was 60 - imins=istart/60 - isecs=istart-(60*imins) - write(fname,1005) imins,isecs !Construction of output filename for 15s periods with averaging -1005 format('000000_',i4.4, i2.2,'.wav') - else - write(fname,1106) istart/60 !Output filename to be compatible with averaging 30-300s periods -1106 format('000000_',i4.4,'.wav') - endif - - open(10,file=trim(fname),access='stream',status='unknown') - xnoise=0. - if(snrdb.lt.90) then - do i=1,npts - xnoise(i)=gran() !Generate gaussian noise - enddo - endif - cdat=0. - - bandwidth_ratio=2500.0/6000.0 - sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb) - if(snrdb.gt.90.0) sig=1.0 - write(*,1020) ifile,ntrperiod,f00,csubmode,snrdb,fspread,xdt,f1,nstp,trim(msgsent) -1020 format(i4,i6,f7.1,2x,a1,2x,f5.1,1x,f6.2,2f6.1,i4,2x,a) - - n=65.0*baud*mode65/100.0 + 0.9999 - nfstep=100*n - nf1=1500 - nfstep*(nsig-1)/2 - do n=1,nsig - f0=f00 - if(nsig.ge.2) then - f0=nf1 + (n-1)*nfstep - itone=ntone(:,n) - endif - phi=0.d0 - dphi=0.d0 - k=(xdt+0.5)*12000 !Start audio at t=xdt+0.5 s (TR=15 and 30 s) - if(ntrperiod.ge.60) k=(xdt+1.0)*12000 !TR 60+ at t = xdt + 1.0 s - isym0=-99 - do i=1,npts !Add this signal into cdat() - isym=i/nsps + 1 - if(isym.gt.nsym) exit - if(isym.ne.isym0) then - freq_drift=f1*i*dt/60.0 - if(nstp.ne.0) freq_drift=freq_drift - nstp*nint(freq_drift/nstp) - if (msg(1:2).eq.'ST') then - freq = f0 + freq_drift - else - freq = f0 + freq_drift + itone(isym)*baud*mode65 - endif - dphi=twopi*freq*dt - isym0=isym - endif - phi=phi + dphi - if(phi.gt.twopi) phi=phi-twopi - xphi=phi - z=cmplx(cos(xphi),sin(xphi)) - k=k+1 - if(k.ge.1) cdat(k)=cdat(k) + sig*z - enddo - enddo - - if(fspread.ne.0) then !Apply specified Doppler spread - df=12000.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 - cdat=cspread*cdat !Apply Rayleigh fading - endif - -! psig=0. -! pnoise=0. -! do i=1,npts -! if(i.gt.12000 .and. i.lt.624000) then -! psig=psig + aimag(cdat(i))**2 -! pnoise=pnoise + xnoise(i)*xnoise(i) -! endif -! enddo -! pnoise=pnoise*bandwidth_ratio -! snr_2500=db(psig/pnoise) !Calibration confirmation! -! print*,'SNR_2500:',snr_2500 - - dat=aimag(cdat) + xnoise !Add generated AWGN noise - fac=32767.0 - if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts)) - if(snrdb.lt.90.0) iwave(1:npts)=nint(rms*dat(1:npts)) - write(10) h,iwave(1:npts) !Save the .wav file - close(10) - enddo - -999 end program q65sim +program q65sim + +! Generate simulated Q65 data for testing the decoder. + + use wavhdr + use packjt + parameter (NMAX=300*12000) !Total samples in .wav file + type(hdr) h !Header for .wav file + integer*2 iwave(NMAX) !Generated waveform + integer itone(85) !Channel symbols (values 0-65) + integer ntone(85,10) !Channel symbols for up to 10 messages + integer y(63) !Codeword + integer istart !averaging compatible start seconds + integer imins !minutes for 15s period timestamp + integer isecs !seconds for 15s period timestamp + real*4 xnoise(NMAX) !Generated random noise + real*4 dat(NMAX) !Generated real data + complex cdat(NMAX) !Generated complex waveform + complex cspread(0:NMAX-1) !Complex amplitude for Rayleigh fading + complex z + real*8 f00,f0,dt,twopi,phi,dphi,baud,fsample,freq + character fname*17,csubmode*1,arg*12,c2*2 + character*37 msg,msgsent,imsg(10) + + nargs=iargc() + if(nargs.ne.11) then + print*,'Usage: q65sim "msg" A-E freq fDop DT f1 Stp TRp Nsig Nfile SNR' + print*,'Example: q65sim "K1ABC W9XYZ EN37" A 1500 0.0 0.0 0.0 1 60 1 1 -26' + print*,'Example: q65sim "ST" A 1500 0.0 0.0 0.0 1 60 1 -26' + print*,' fDop = Doppler spread' + print*,' f1 = Drift or Doppler rate (Hz/min)' + print*,' Stp = Step size (Hz)' + print*,' Stp = 0 implies no Doppler tracking' + print*,' Nsig = number of generated signals, 1 - 10' + print*,' Creates filenames which increment to permit averaging in first period' + print*,' If msg = ST program produces a single tone at freq' + go to 999 + endif + call getarg(1,msg) + call getarg(2,csubmode) + mode65=2**(ichar(csubmode)-ichar('A')) + call getarg(3,arg) + read(arg,*) f00 + call getarg(4,arg) + read(arg,*) fspread + call getarg(5,arg) + read(arg,*) xdt + call getarg(6,arg) + read(arg,*) f1 + call getarg(7,arg) + read(arg,*) nstp + call getarg(8,arg) + read(arg,*) ntrperiod + call getarg(9,arg) + read(arg,*) nsig + call getarg(10,arg) + read(arg,*) nfiles + call getarg(11,arg) + read(arg,*) snrdb + + if(ntrperiod.eq.15) then + nsps=1800 + else if(ntrperiod.eq.30) then + nsps=3600 + else if(ntrperiod.eq.60) then + nsps=7200 + else if(ntrperiod.eq.120) then + nsps=16000 + else if(ntrperiod.eq.300) then + nsps=41472 + else + print*,'Invalid TR period' + go to 999 + endif + + rms=100. + fsample=12000.d0 !Sample rate (Hz) + npts=fsample*ntrperiod !Total samples in .wav file + nfft=npts + nh=nfft/2 + dt=1.d0/fsample !Sample interval (s) + twopi=8.d0*atan(1.d0) + nsym=85 !Number of channel symbols + mode65=2**(ichar(csubmode) - ichar('A')) + + + imsg(1)=msg + if(nsig.ge.2) then + i0=index(msg,' ') + i0=i0 + index(msg(i0+1:),' ')-2 + do i=1,nsig + c2=char(ichar('A')+i-1)//char(ichar('A')+i-1) + imsg(i)=msg(1:i0-1)//c2//msg(i0+2:) + enddo + endif + + ichk=0 + do i=1,nsig + msg=imsg(i) + call genq65(msg,ichk,msgsent,itone,i3,n3) + ntone(:,i)=itone + enddo + + if(nsig.eq.1) then + j=0 + do i=1,85 + if(itone(i).gt.0) then + j=j+1 + y(j)=itone(i)-1 + endif + enddo + write(*,1001) y(1:13),y(1:13) +1001 format('Generated message'/'6-bit: ',13i3/'binary: ',13b6.6) + write(*,1002) y +1002 format(/'Codeword:'/(20i3)) + write(*,1003) itone +1003 format(/'Channel symbols:'/(20i3)) + endif + + baud=12000.d0/nsps !Keying rate (6.67 baud fot 15-s sequences) + h=default_header(12000,npts) + + write(*,1004) +1004 format('File TR Freq Mode S/N Dop DT f1 Stp Message'/70('-')) + + do ifile=1,nfiles !Loop over requested number of files + istart = (ifile*ntrperiod*2) - (ntrperiod*2) + if(ntrperiod.lt.30) then !wdg was 60 + imins=istart/60 + isecs=istart-(60*imins) + write(fname,1005) imins,isecs !Construction of output filename for 15s periods with averaging +1005 format('000000_',i4.4, i2.2,'.wav') + else + write(fname,1106) istart/60 !Output filename to be compatible with averaging 30-300s periods +1106 format('000000_',i4.4,'.wav') + endif + + open(10,file=trim(fname),access='stream',status='unknown') + xnoise=0. + if(snrdb.lt.90) then + do i=1,npts + xnoise(i)=gran() !Generate gaussian noise + enddo + endif + cdat=0. + + bandwidth_ratio=2500.0/6000.0 + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + write(*,1020) ifile,ntrperiod,f00,csubmode,snrdb,fspread,xdt,f1,nstp,trim(msgsent) +1020 format(i4,i6,f7.1,2x,a1,2x,f5.1,1x,f6.2,2f6.1,i4,2x,a) + + n=65.0*baud*mode65/100.0 + 0.9999 + nfstep=100*n + nf1=1500 - nfstep*(nsig-1)/2 + do n=1,nsig + f0=f00 + if(nsig.ge.2) then + f0=nf1 + (n-1)*nfstep + itone=ntone(:,n) + endif + phi=0.d0 + dphi=0.d0 + k=(xdt+0.5)*12000 !Start audio at t=xdt+0.5 s (TR=15 and 30 s) + if(ntrperiod.ge.60) k=(xdt+1.0)*12000 !TR 60+ at t = xdt + 1.0 s + isym0=-99 + do i=1,npts !Add this signal into cdat() + isym=i/nsps + 1 + if(isym.gt.nsym) exit + if(isym.ne.isym0) then + freq_drift=f1*i*dt/60.0 + if(nstp.ne.0) freq_drift=freq_drift - nstp*nint(freq_drift/nstp) + if (msg(1:2).eq.'ST') then + freq = f0 + freq_drift + else + freq = f0 + freq_drift + itone(isym)*baud*mode65 + endif + dphi=twopi*freq*dt + isym0=isym + endif + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + z=cmplx(cos(xphi),sin(xphi)) + k=k+1 + if(k.ge.1) cdat(k)=cdat(k) + sig*z + enddo + enddo + + if(fspread.ne.0) then !Apply specified Doppler spread + df=12000.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 + cdat=cspread*cdat !Apply Rayleigh fading + endif + +! psig=0. +! pnoise=0. +! do i=1,npts +! if(i.gt.12000 .and. i.lt.624000) then +! psig=psig + aimag(cdat(i))**2 +! pnoise=pnoise + xnoise(i)*xnoise(i) +! endif +! enddo +! pnoise=pnoise*bandwidth_ratio +! snr_2500=db(psig/pnoise) !Calibration confirmation! +! print*,'SNR_2500:',snr_2500 + + dat=aimag(cdat) + xnoise !Add generated AWGN noise + fac=32767.0 + if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts)) + if(snrdb.lt.90.0) iwave(1:npts)=nint(rms*dat(1:npts)) + write(10) h,iwave(1:npts) !Save the .wav file + close(10) + enddo + +999 end program q65sim diff --git a/lib/qra/q65/q65test.c b/lib/qra/q65/q65test.c index 6c9d9fd8..e9079280 100755 --- a/lib/qra/q65/q65test.c +++ b/lib/qra/q65/q65test.c @@ -1,910 +1,910 @@ -// q65test.c -// Word Error Rate test example for the Q65 mode -// Multi-threaded simulator version - -// (c) 2020 - Nico Palermo, IV3NWV -// -// -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// Dependencies: -// q65test.c - this file -// normrnd.c/.h - random gaussian number generator -// npfwht.c/.h - Fast Walsh-Hadamard Transforms -// pdmath.c/.h - Elementary math on probability distributions -// qra15_65_64_irr_e23.c/.h - Tables for the QRA(15,65) irregular RA code used by Q65 -// qracodes.c/.h - QRA codes encoding/decoding functions -// fadengauss.c - fading coefficients tables for gaussian shaped fast fading channels -// fadenlorenz.c - fading coefficients tables for lorenzian shaped fast fading channels -// -// ------------------------------------------------------------------------------- -// -// This 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . -// -// ------------------------------------------------------------------------------ - -// OS dependent defines and includes -------------------------------------------- - -#if _WIN32 // note the underscore: without it, it's not msdn official! - // Windows (x64 and x86) - #define _CRT_SECURE_NO_WARNINGS // we don't need warnings for sprintf/fopen function usage - #include // required only for GetTickCount(...) - #include // _beginthread -#endif - -#if defined(__linux__) - -// remove unwanted macros -#define __cdecl - -// implements Windows API -#include - - unsigned int GetTickCount(void) { - struct timespec ts; - unsigned int theTick = 0U; - clock_gettime( CLOCK_REALTIME, &ts ); - theTick = ts.tv_nsec / 1000000; - theTick += ts.tv_sec * 1000; - return theTick; -} - -// Convert Windows millisecond sleep -// -// VOID WINAPI Sleep(_In_ DWORD dwMilliseconds); -// -// to Posix usleep (in microseconds) -// -// int usleep(useconds_t usec); -// -#include -#define Sleep(x) usleep(x*1000) - -#endif - -#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) ) -#include -#endif - -#if __APPLE__ -#endif - -#include -#include - -#include "qracodes.h" // basic qra encoding/decoding functions -#include "normrnd.h" // gaussian numbers generator -#include "pdmath.h" // operations on probability distributions - -#include "qra15_65_64_irr_e23.h" // QRA code used by Q65 -#include "q65.h" - -#define Q65_TS 0.640f // Q65 symbol time interval in seconds -#define Q65_REFBW 2500.0f // reference bandwidth in Hz for SNR estimates - -// ----------------------------------------------------------------------------------- - -#define NTHREADS_MAX 160 // if you have some big enterprise hardware - -// channel types -#define CHANNEL_AWGN 0 -#define CHANNEL_RAYLEIGH 1 -#define CHANNEL_FASTFADING 2 - -// amount of a-priori information provided to the decoder -#define AP_NONE 0 -#define AP_MYCALL 1 -#define AP_HISCALL 2 -#define AP_BOTHCALL 3 -#define AP_FULL 4 -#define AP_LAST AP_FULL - -const char ap_str[AP_LAST+1][16] = { - "None", - "32 bit", - "32 bit", - "62 bit", - "78 bit", -}; -const char fnameout_sfx[AP_LAST+1][64] = { - "-ap00.txt", - "-ap32m.txt", - "-ap32h.txt", - "-ap62.txt", - "-ap78.txt" -}; - -const char fnameout_pfx[3][64] = { - "wer-awgn-", - "wer-rayl-", - "wer-ff-" -}; - -// AP masks are computed assuming that the source message has been packed in 13 symbols s[0]..[s12] -// in a little indian format, that's to say: - -// s[0] = {src5 src4 src3 src2 src1 src0} -// s[1] = {src11 src10 src9 src8 src7 src6} -// ... -// s[12]= {src78 src77 src76 src75 src74 src73} -// -// where srcj is the j-th bit of the source message. -// -// It is also assumed that the source message is as indicated by the protocol specification of wsjt-x -// structured messages. src78 should be always set to a value known by the decoder (and masked as an AP bit) -// With this convention the field i3 of the structured message is mapped to bits src77 src76 src75, -// that's to say to the 3rd,4th and 5th bit of s[12]. -// Therefore, if i3 is known in advance, since src78 is always known, -// the AP mask for s[12] is 0x3C (4 most significant bits of s[12] are known) - -const int ap_masks_q65[AP_LAST+1][13] = { -// AP0 Mask -{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, -// Mask first(c28 r1) .... i3 src78 (AP32my MyCall ? ? StdMsg) -{ 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C}, -// Mask second(c28 r1) .... i3 src78 (AP32his ? HisCall ? StdMsg) -{ 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x0F, 0x00, 0x00, 0x3C}, -// Mask (c28 r1 c28 r1) ... i3 src78 (AP62 MyCall HisCall ? StdMsg) -{ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x0F, 0x00, 0x00, 0x3C}, -// Mask All (c28 r1 c28 r1 R g15 StdMsg src78) (AP78) -{ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, -}; - -int verbose = 0; - -void printword(char *msg, int *x, int size) -{ - int k; - printf("\n%s ",msg); - for (k=0;kchannel_type; - - rc = q65_init(&codec,pdata->pcode); - - if (rc<0) { - printf("error in qra65_init\n"); - goto term_thread; - } - - nK = q65_get_message_length(&codec); - nN = q65_get_codeword_length(&codec); - nM = q65_get_alphabet_size(&codec); - nm = q65_get_bits_per_symbol(&codec); - R = q65_get_code_rate(&codec); - - nSamples = nN*nM; - - x = (int*)malloc(nK*sizeof(int)); - xdec = (int*)malloc(nK*sizeof(int)); - y = (int*)malloc(nN*sizeof(int)); - ydec = (int*)malloc(nN*sizeof(int)); - rsquared = (float*)malloc(nSamples*sizeof(float)); - pIntrinsics = (float*)malloc(nSamples*sizeof(float)); - - // sets the AP mask to be used for this simulation - if (pdata->ap_index==AP_NONE) - apMask = NULL; // we simply avoid masking if ap-index specifies no AP - else - apMask = ap_masks_q65[pdata->ap_index]; - - // Channel simulation variables -------------------- - rp = (float*)malloc(nSamples*sizeof(float)); - rq = (float*)malloc(nSamples*sizeof(float)); - chp = (float*)malloc(nN*sizeof(float)); - chq = (float*)malloc(nN*sizeof(float)); - - EbNo = (float)powf(10,pdata->EbNodB/10); - EsNo = 1.0f*nm*R*EbNo; - Es = EsNo*No; - A = (float)sqrt(Es); - - // Generate a (meaningless) test message - for (k=0;kstop==0) { - - // Channel simulation -------------------------------------------- - // Generate AWGN noise - normrnd_s(rp,nSamples,0,sigma); - normrnd_s(rq,nSamples,0,sigma); - - if (channel_type == CHANNEL_AWGN) - // add symbol amplitudes - for (k=0;k0 && verbose==1) { - float EbNodBestimated; - float SNRdBestimated; - q65_esnodb(&codec, &EsNodBestimated, ydec,rsquared); - EbNodBestimated = EsNodBestimated -10.0f*log10f(R*nm); - SNRdBestimated = EsNodBestimated -10.0f*log10f(Q65_TS*Q65_REFBW); - printf("\nEstimated Eb/No=%5.1fdB SNR2500=%5.1fdB", - EbNodBestimated, - SNRdBestimated); - } - - nt = nt+1; - pdata->nt=nt; - pdata->nerrs=nerrs; - pdata->ncrcwrong = ncrcwrong; - } - -term_thread: - - free(x); - free(xdec); - free(y); - free(ydec); - free(rsquared); - free(pIntrinsics); - - free(rp); - free(rq); - free(chp); - free(chq); - - q65_free(&codec); - - // signal the calling thread we are quitting - pdata->done=1; - #if _WIN32 - _endthread(); - #endif -} - -void wer_test_thread_ff(wer_test_ds *pdata) -{ - // We don't do a realistic simulation of the fading-channel here - // If required give a look to the simulator used in the QRA64 mode. - // For the purpose of testing the formal correctness of the Q65 decoder - // fast-fadind routines here we simulate the channel as a Rayleigh channel - // with no frequency spread but use the q65....-fastfading routines - // to check that they produce correct results also in this case. - - const int submode = 2; // Assume that we are using the Q65C tone spacing - const float B90 = 4.0f; // Configure the Q65 fast-fading decoder for a the given freq. spread - const int fadingModel = 1; // Assume a lorenzian frequency spread - - int nt = 0; // transmitted codewords - int nerrs = 0; // total number of errors - int ncrcwrong = 0; // number of decodes with wrong crc - - q65_codec_ds codec; - - int rc, k; - int nK, nN, nM, nm, nSamples; - int *x, *y, *xdec, *ydec; - const int *apMask; - float R; - float *rsquared, *pIntrinsics; - float EsNodBestimated; - - int nBinsPerTone, nBinsPerSymbol; - - - // for channel simulation - const float No = 1.0f; // noise spectral density - const float sigma = sqrtf(No/2.0f); // std dev of I/Q noise components - const float sigmach = sqrtf(1/2.0f); // std dev of I/Q channel gains (Rayleigh channel) - float EbNo, EsNo, Es, A; - float *rp, *rq, *chp, *chq; - int channel_type = pdata->channel_type; - - rc = q65_init(&codec,pdata->pcode); - - if (rc<0) { - printf("error in q65_init\n"); - goto term_thread; - } - - nK = q65_get_message_length(&codec); - nN = q65_get_codeword_length(&codec); - nM = q65_get_alphabet_size(&codec); - nm = q65_get_bits_per_symbol(&codec); - R = q65_get_code_rate(&codec); - - - nBinsPerTone = 1<ap_index==AP_NONE) - apMask = NULL; // we simply avoid masking if ap-index specifies no AP - else - apMask = ap_masks_q65[pdata->ap_index]; - - - x = (int*)malloc(nK*sizeof(int)); - xdec = (int*)malloc(nK*sizeof(int)); - y = (int*)malloc(nN*sizeof(int)); - ydec = (int*)malloc(nN*sizeof(int)); - rsquared = (float*)malloc(nSamples*sizeof(float)); - pIntrinsics = (float*)malloc(nN*nM*sizeof(float)); - - // Channel simulation variables -------------------- - rp = (float*)malloc(nSamples*sizeof(float)); - rq = (float*)malloc(nSamples*sizeof(float)); - chp = (float*)malloc(nN*sizeof(float)); - chq = (float*)malloc(nN*sizeof(float)); - - EbNo = (float)powf(10,pdata->EbNodB/10); - EsNo = 1.0f*nm*R*EbNo; - Es = EsNo*No; - A = (float)sqrt(Es); - // ------------------------------------------------- - - // generate a test message - for (k=0;kstop==0) { - - // Channel simulation -------------------------------------------- - // generate AWGN noise - normrnd_s(rp,nSamples,0,sigma); - normrnd_s(rq,nSamples,0,sigma); - - - // Generate Rayleigh distributed symbol amplitudes - normrnd_s(chp,nN,0,sigmach); - normrnd_s(chq,nN,0,sigmach); - // Don't simulate a really frequency spreaded signal. - // Just place the tones in the appropriate central bins - // ot the received signal - for (k=0;k0 && verbose==1) { - float EbNodBestimated; - float SNRdBestimated; - // use the fastfading version - q65_esnodb_fastfading(&codec, &EsNodBestimated, ydec,rsquared); - EbNodBestimated = EsNodBestimated -10.0f*log10f(R*nm); - SNRdBestimated = EsNodBestimated -10.0f*log10f(Q65_TS*Q65_REFBW); - printf("\nEstimated Eb/No=%5.1fdB SNR2500=%5.1fdB", - EbNodBestimated, - SNRdBestimated); - } - - nt = nt+1; - pdata->nt=nt; - pdata->nerrs=nerrs; - pdata->ncrcwrong = ncrcwrong; - } - -term_thread: - - free(x); - free(xdec); - free(y); - free(ydec); - free(rsquared); - free(pIntrinsics); - - free(rp); - free(rq); - free(chp); - free(chq); - - q65_free(&codec); - - // signal the calling thread we are quitting - pdata->done=1; - #if _WIN32 - _endthread(); - #endif -} - - -#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) ) - -void *wer_test_pthread_awgnrayl(void *p) -{ - wer_test_thread_awgnrayl((wer_test_ds *)p); - return 0; -} - -void *wer_test_pthread_ff(void *p) -{ - wer_test_thread_ff((wer_test_ds *)p); - return 0; -} - -#endif - - -int wer_test_proc(const qracode *pcode, int nthreads, int chtype, int ap_index, float *EbNodB, int *nerrstgt, int nitems) -{ - int k,j,nt,nerrs,nerrsu,ncrcwrong,nd; - int cini,cend; - char fnameout[128]; - FILE *fout; - wer_test_ds wt[NTHREADS_MAX]; - float pe,peu,avgt; - - if (nthreads>NTHREADS_MAX) { - printf("Error: nthreads should be <=%d\n",NTHREADS_MAX); - return -1; - } - - sprintf(fnameout,"%s%s%s", - fnameout_pfx[chtype], - pcode->name, - fnameout_sfx[ap_index]); - - fout = fopen(fnameout,"w"); - fprintf(fout,"#Code Name: %s\n",pcode->name); - fprintf(fout,"#ChannelType (0=AWGN,1=Rayleigh,2=Fast-Fading)\n#Eb/No (dB)\n#Transmitted Codewords\n#Errors\n#CRC Errors\n#Undetected\n#Avg dec. time (ms)\n#WER\n#UER\n"); - - printf("\nTesting the code %s\nSimulation data will be saved to %s\n", - pcode->name, - fnameout); - fflush (stdout); - - // init fixed thread parameters and preallocate buffers - for (j=0;j=nerrstgt[k]) { - for (j=0;j] [-t] [-c] [-a] [-f[-h]\n"); - printf("Options: \n"); - printf(" -q: code to simulate. 0=qra_15_65_64_irr_e23 (default)\n"); - printf(" -t : number of threads to be used for the simulation [1..24]\n"); - printf(" (default=8)\n"); - printf(" -c : channel_type. 0=AWGN 1=Rayleigh 2=Fast-Fading\n"); - printf(" (default=AWGN)\n"); - printf(" -a : amount of a-priori information provided to decoder. \n"); - printf(" 0= No a-priori (default)\n"); - printf(" 1= 32 bit (Mycall)\n"); - printf(" 2= 32 bit (Hiscall)\n"); - printf(" 3= 62 bit (Bothcalls\n"); - printf(" 4= 78 bit (full AP)\n"); - printf(" -v : verbose (output SNRs of decoded messages\n"); - - printf(" -f : name of the file containing the Eb/No values to be simulated\n"); - printf(" (default=ebnovalues.txt)\n"); - printf(" This file should contain lines in this format:\n"); - printf(" # Eb/No(dB) Target Errors\n"); - printf(" 0.1 5000\n"); - printf(" 0.6 5000\n"); - printf(" 1.1 1000\n"); - printf(" 1.6 1000\n"); - printf(" ...\n"); - printf(" (lines beginning with a # are treated as comments\n\n"); -} - -#define SIM_POINTS_MAX 20 - -int main(int argc, char* argv[]) -{ - - float EbNodB[SIM_POINTS_MAX]; - int nerrstgt[SIM_POINTS_MAX]; - FILE *fin; - - char fnamein[128]= "ebnovalues.txt"; - char buf[128]; - - int nitems = 0; - int code_idx = 0; - int nthreads = 8; - int ch_type = CHANNEL_AWGN; - int ap_index = AP_NONE; - - // parse command line - while(--argc) { - argv++; - if (strncmp(*argv,"-h",2)==0) { - syntax(); - return 0; - } - else - if (strncmp(*argv,"-q",2)==0) { - code_idx = (int)atoi((*argv)+2); - if (code_idx>7) { - printf("Invalid code index\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-t",2)==0) { - nthreads = (int)atoi((*argv)+2); - -// printf("nthreads = %d\n",nthreads); - - if (nthreads>NTHREADS_MAX) { - printf("Invalid number of threads\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-c",2)==0) { - ch_type = (int)atoi((*argv)+2); - if (ch_type>CHANNEL_FASTFADING) { - printf("Invalid channel type\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-a",2)==0) { - ap_index = (int)atoi((*argv)+2); - if (ap_index>AP_LAST) { - printf("Invalid a-priori information index\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-f",2)==0) { - strncpy(fnamein,(*argv)+2,127); - } - else - if (strncmp(*argv,"-h",2)==0) { - syntax(); - return -1; - } - else - if (strncmp(*argv,"-v",2)==0) - verbose = TRUE; - else { - printf("Invalid option\n"); - syntax(); - return -1; - } - } - - // parse points to be simulated from the input file - fin = fopen(fnamein,"r"); - if (!fin) { - printf("Can't open file: %s\n",fnamein); - syntax(); - return -1; - } - - while (fgets(buf,128,fin)!=0) - if (*buf=='#' || *buf=='\n' ) - continue; - else - if (nitems==SIM_POINTS_MAX) - break; - else - if (sscanf(buf,"%f %u",&EbNodB[nitems],&nerrstgt[nitems])!=2) { - printf("Invalid input file format\n"); - syntax(); - return -1; - } - else - nitems++; - - fclose(fin); - - if (nitems==0) { - printf("No Eb/No point specified in file %s\n",fnamein); - syntax(); - return -1; - } - - printf("\nQ65 Word Error Rate Simulator\n"); - printf("(c) 2016-2020, Nico Palermo - IV3NWV\n\n"); - - printf("Nthreads = %d\n",nthreads); - switch(ch_type) { - case CHANNEL_AWGN: - printf("Channel = AWGN\n"); - break; - case CHANNEL_RAYLEIGH: - printf("Channel = Rayleigh\n"); - break; - case CHANNEL_FASTFADING: - printf("Channel = Fast Fading\n"); - break; - } - printf("Codename = %s\n",codetotest[code_idx]->name); - printf("A-priori = %s\n",ap_str[ap_index]); - printf("Eb/No input file = %s\n\n",fnamein); - - wer_test_proc(codetotest[code_idx], nthreads, ch_type, ap_index, EbNodB, nerrstgt, nitems); - - printf("\n\n\n"); - return 0; -} - +// q65test.c +// Word Error Rate test example for the Q65 mode +// Multi-threaded simulator version + +// (c) 2020 - Nico Palermo, IV3NWV +// +// +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// Dependencies: +// q65test.c - this file +// normrnd.c/.h - random gaussian number generator +// npfwht.c/.h - Fast Walsh-Hadamard Transforms +// pdmath.c/.h - Elementary math on probability distributions +// qra15_65_64_irr_e23.c/.h - Tables for the QRA(15,65) irregular RA code used by Q65 +// qracodes.c/.h - QRA codes encoding/decoding functions +// fadengauss.c - fading coefficients tables for gaussian shaped fast fading channels +// fadenlorenz.c - fading coefficients tables for lorenzian shaped fast fading channels +// +// ------------------------------------------------------------------------------- +// +// This 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . +// +// ------------------------------------------------------------------------------ + +// OS dependent defines and includes -------------------------------------------- + +#if _WIN32 // note the underscore: without it, it's not msdn official! + // Windows (x64 and x86) + #define _CRT_SECURE_NO_WARNINGS // we don't need warnings for sprintf/fopen function usage + #include // required only for GetTickCount(...) + #include // _beginthread +#endif + +#if defined(__linux__) + +// remove unwanted macros +#define __cdecl + +// implements Windows API +#include + + unsigned int GetTickCount(void) { + struct timespec ts; + unsigned int theTick = 0U; + clock_gettime( CLOCK_REALTIME, &ts ); + theTick = ts.tv_nsec / 1000000; + theTick += ts.tv_sec * 1000; + return theTick; +} + +// Convert Windows millisecond sleep +// +// VOID WINAPI Sleep(_In_ DWORD dwMilliseconds); +// +// to Posix usleep (in microseconds) +// +// int usleep(useconds_t usec); +// +#include +#define Sleep(x) usleep(x*1000) + +#endif + +#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) ) +#include +#endif + +#if __APPLE__ +#endif + +#include +#include + +#include "qracodes.h" // basic qra encoding/decoding functions +#include "normrnd.h" // gaussian numbers generator +#include "pdmath.h" // operations on probability distributions + +#include "qra15_65_64_irr_e23.h" // QRA code used by Q65 +#include "q65.h" + +#define Q65_TS 0.640f // Q65 symbol time interval in seconds +#define Q65_REFBW 2500.0f // reference bandwidth in Hz for SNR estimates + +// ----------------------------------------------------------------------------------- + +#define NTHREADS_MAX 160 // if you have some big enterprise hardware + +// channel types +#define CHANNEL_AWGN 0 +#define CHANNEL_RAYLEIGH 1 +#define CHANNEL_FASTFADING 2 + +// amount of a-priori information provided to the decoder +#define AP_NONE 0 +#define AP_MYCALL 1 +#define AP_HISCALL 2 +#define AP_BOTHCALL 3 +#define AP_FULL 4 +#define AP_LAST AP_FULL + +const char ap_str[AP_LAST+1][16] = { + "None", + "32 bit", + "32 bit", + "62 bit", + "78 bit", +}; +const char fnameout_sfx[AP_LAST+1][64] = { + "-ap00.txt", + "-ap32m.txt", + "-ap32h.txt", + "-ap62.txt", + "-ap78.txt" +}; + +const char fnameout_pfx[3][64] = { + "wer-awgn-", + "wer-rayl-", + "wer-ff-" +}; + +// AP masks are computed assuming that the source message has been packed in 13 symbols s[0]..[s12] +// in a little indian format, that's to say: + +// s[0] = {src5 src4 src3 src2 src1 src0} +// s[1] = {src11 src10 src9 src8 src7 src6} +// ... +// s[12]= {src78 src77 src76 src75 src74 src73} +// +// where srcj is the j-th bit of the source message. +// +// It is also assumed that the source message is as indicated by the protocol specification of wsjt-x +// structured messages. src78 should be always set to a value known by the decoder (and masked as an AP bit) +// With this convention the field i3 of the structured message is mapped to bits src77 src76 src75, +// that's to say to the 3rd,4th and 5th bit of s[12]. +// Therefore, if i3 is known in advance, since src78 is always known, +// the AP mask for s[12] is 0x3C (4 most significant bits of s[12] are known) + +const int ap_masks_q65[AP_LAST+1][13] = { +// AP0 Mask +{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, +// Mask first(c28 r1) .... i3 src78 (AP32my MyCall ? ? StdMsg) +{ 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C}, +// Mask second(c28 r1) .... i3 src78 (AP32his ? HisCall ? StdMsg) +{ 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x0F, 0x00, 0x00, 0x3C}, +// Mask (c28 r1 c28 r1) ... i3 src78 (AP62 MyCall HisCall ? StdMsg) +{ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x0F, 0x00, 0x00, 0x3C}, +// Mask All (c28 r1 c28 r1 R g15 StdMsg src78) (AP78) +{ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, +}; + +int verbose = 0; + +void printword(char *msg, int *x, int size) +{ + int k; + printf("\n%s ",msg); + for (k=0;kchannel_type; + + rc = q65_init(&codec,pdata->pcode); + + if (rc<0) { + printf("error in qra65_init\n"); + goto term_thread; + } + + nK = q65_get_message_length(&codec); + nN = q65_get_codeword_length(&codec); + nM = q65_get_alphabet_size(&codec); + nm = q65_get_bits_per_symbol(&codec); + R = q65_get_code_rate(&codec); + + nSamples = nN*nM; + + x = (int*)malloc(nK*sizeof(int)); + xdec = (int*)malloc(nK*sizeof(int)); + y = (int*)malloc(nN*sizeof(int)); + ydec = (int*)malloc(nN*sizeof(int)); + rsquared = (float*)malloc(nSamples*sizeof(float)); + pIntrinsics = (float*)malloc(nSamples*sizeof(float)); + + // sets the AP mask to be used for this simulation + if (pdata->ap_index==AP_NONE) + apMask = NULL; // we simply avoid masking if ap-index specifies no AP + else + apMask = ap_masks_q65[pdata->ap_index]; + + // Channel simulation variables -------------------- + rp = (float*)malloc(nSamples*sizeof(float)); + rq = (float*)malloc(nSamples*sizeof(float)); + chp = (float*)malloc(nN*sizeof(float)); + chq = (float*)malloc(nN*sizeof(float)); + + EbNo = (float)powf(10,pdata->EbNodB/10); + EsNo = 1.0f*nm*R*EbNo; + Es = EsNo*No; + A = (float)sqrt(Es); + + // Generate a (meaningless) test message + for (k=0;kstop==0) { + + // Channel simulation -------------------------------------------- + // Generate AWGN noise + normrnd_s(rp,nSamples,0,sigma); + normrnd_s(rq,nSamples,0,sigma); + + if (channel_type == CHANNEL_AWGN) + // add symbol amplitudes + for (k=0;k0 && verbose==1) { + float EbNodBestimated; + float SNRdBestimated; + q65_esnodb(&codec, &EsNodBestimated, ydec,rsquared); + EbNodBestimated = EsNodBestimated -10.0f*log10f(R*nm); + SNRdBestimated = EsNodBestimated -10.0f*log10f(Q65_TS*Q65_REFBW); + printf("\nEstimated Eb/No=%5.1fdB SNR2500=%5.1fdB", + EbNodBestimated, + SNRdBestimated); + } + + nt = nt+1; + pdata->nt=nt; + pdata->nerrs=nerrs; + pdata->ncrcwrong = ncrcwrong; + } + +term_thread: + + free(x); + free(xdec); + free(y); + free(ydec); + free(rsquared); + free(pIntrinsics); + + free(rp); + free(rq); + free(chp); + free(chq); + + q65_free(&codec); + + // signal the calling thread we are quitting + pdata->done=1; + #if _WIN32 + _endthread(); + #endif +} + +void wer_test_thread_ff(wer_test_ds *pdata) +{ + // We don't do a realistic simulation of the fading-channel here + // If required give a look to the simulator used in the QRA64 mode. + // For the purpose of testing the formal correctness of the Q65 decoder + // fast-fadind routines here we simulate the channel as a Rayleigh channel + // with no frequency spread but use the q65....-fastfading routines + // to check that they produce correct results also in this case. + + const int submode = 2; // Assume that we are using the Q65C tone spacing + const float B90 = 4.0f; // Configure the Q65 fast-fading decoder for a the given freq. spread + const int fadingModel = 1; // Assume a lorenzian frequency spread + + int nt = 0; // transmitted codewords + int nerrs = 0; // total number of errors + int ncrcwrong = 0; // number of decodes with wrong crc + + q65_codec_ds codec; + + int rc, k; + int nK, nN, nM, nm, nSamples; + int *x, *y, *xdec, *ydec; + const int *apMask; + float R; + float *rsquared, *pIntrinsics; + float EsNodBestimated; + + int nBinsPerTone, nBinsPerSymbol; + + + // for channel simulation + const float No = 1.0f; // noise spectral density + const float sigma = sqrtf(No/2.0f); // std dev of I/Q noise components + const float sigmach = sqrtf(1/2.0f); // std dev of I/Q channel gains (Rayleigh channel) + float EbNo, EsNo, Es, A; + float *rp, *rq, *chp, *chq; + int channel_type = pdata->channel_type; + + rc = q65_init(&codec,pdata->pcode); + + if (rc<0) { + printf("error in q65_init\n"); + goto term_thread; + } + + nK = q65_get_message_length(&codec); + nN = q65_get_codeword_length(&codec); + nM = q65_get_alphabet_size(&codec); + nm = q65_get_bits_per_symbol(&codec); + R = q65_get_code_rate(&codec); + + + nBinsPerTone = 1<ap_index==AP_NONE) + apMask = NULL; // we simply avoid masking if ap-index specifies no AP + else + apMask = ap_masks_q65[pdata->ap_index]; + + + x = (int*)malloc(nK*sizeof(int)); + xdec = (int*)malloc(nK*sizeof(int)); + y = (int*)malloc(nN*sizeof(int)); + ydec = (int*)malloc(nN*sizeof(int)); + rsquared = (float*)malloc(nSamples*sizeof(float)); + pIntrinsics = (float*)malloc(nN*nM*sizeof(float)); + + // Channel simulation variables -------------------- + rp = (float*)malloc(nSamples*sizeof(float)); + rq = (float*)malloc(nSamples*sizeof(float)); + chp = (float*)malloc(nN*sizeof(float)); + chq = (float*)malloc(nN*sizeof(float)); + + EbNo = (float)powf(10,pdata->EbNodB/10); + EsNo = 1.0f*nm*R*EbNo; + Es = EsNo*No; + A = (float)sqrt(Es); + // ------------------------------------------------- + + // generate a test message + for (k=0;kstop==0) { + + // Channel simulation -------------------------------------------- + // generate AWGN noise + normrnd_s(rp,nSamples,0,sigma); + normrnd_s(rq,nSamples,0,sigma); + + + // Generate Rayleigh distributed symbol amplitudes + normrnd_s(chp,nN,0,sigmach); + normrnd_s(chq,nN,0,sigmach); + // Don't simulate a really frequency spreaded signal. + // Just place the tones in the appropriate central bins + // ot the received signal + for (k=0;k0 && verbose==1) { + float EbNodBestimated; + float SNRdBestimated; + // use the fastfading version + q65_esnodb_fastfading(&codec, &EsNodBestimated, ydec,rsquared); + EbNodBestimated = EsNodBestimated -10.0f*log10f(R*nm); + SNRdBestimated = EsNodBestimated -10.0f*log10f(Q65_TS*Q65_REFBW); + printf("\nEstimated Eb/No=%5.1fdB SNR2500=%5.1fdB", + EbNodBestimated, + SNRdBestimated); + } + + nt = nt+1; + pdata->nt=nt; + pdata->nerrs=nerrs; + pdata->ncrcwrong = ncrcwrong; + } + +term_thread: + + free(x); + free(xdec); + free(y); + free(ydec); + free(rsquared); + free(pIntrinsics); + + free(rp); + free(rq); + free(chp); + free(chq); + + q65_free(&codec); + + // signal the calling thread we are quitting + pdata->done=1; + #if _WIN32 + _endthread(); + #endif +} + + +#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) ) + +void *wer_test_pthread_awgnrayl(void *p) +{ + wer_test_thread_awgnrayl((wer_test_ds *)p); + return 0; +} + +void *wer_test_pthread_ff(void *p) +{ + wer_test_thread_ff((wer_test_ds *)p); + return 0; +} + +#endif + + +int wer_test_proc(const qracode *pcode, int nthreads, int chtype, int ap_index, float *EbNodB, int *nerrstgt, int nitems) +{ + int k,j,nt,nerrs,nerrsu,ncrcwrong,nd; + int cini,cend; + char fnameout[128]; + FILE *fout; + wer_test_ds wt[NTHREADS_MAX]; + float pe,peu,avgt; + + if (nthreads>NTHREADS_MAX) { + printf("Error: nthreads should be <=%d\n",NTHREADS_MAX); + return -1; + } + + sprintf(fnameout,"%s%s%s", + fnameout_pfx[chtype], + pcode->name, + fnameout_sfx[ap_index]); + + fout = fopen(fnameout,"w"); + fprintf(fout,"#Code Name: %s\n",pcode->name); + fprintf(fout,"#ChannelType (0=AWGN,1=Rayleigh,2=Fast-Fading)\n#Eb/No (dB)\n#Transmitted Codewords\n#Errors\n#CRC Errors\n#Undetected\n#Avg dec. time (ms)\n#WER\n#UER\n"); + + printf("\nTesting the code %s\nSimulation data will be saved to %s\n", + pcode->name, + fnameout); + fflush (stdout); + + // init fixed thread parameters and preallocate buffers + for (j=0;j=nerrstgt[k]) { + for (j=0;j] [-t] [-c] [-a] [-f[-h]\n"); + printf("Options: \n"); + printf(" -q: code to simulate. 0=qra_15_65_64_irr_e23 (default)\n"); + printf(" -t : number of threads to be used for the simulation [1..24]\n"); + printf(" (default=8)\n"); + printf(" -c : channel_type. 0=AWGN 1=Rayleigh 2=Fast-Fading\n"); + printf(" (default=AWGN)\n"); + printf(" -a : amount of a-priori information provided to decoder. \n"); + printf(" 0= No a-priori (default)\n"); + printf(" 1= 32 bit (Mycall)\n"); + printf(" 2= 32 bit (Hiscall)\n"); + printf(" 3= 62 bit (Bothcalls\n"); + printf(" 4= 78 bit (full AP)\n"); + printf(" -v : verbose (output SNRs of decoded messages\n"); + + printf(" -f : name of the file containing the Eb/No values to be simulated\n"); + printf(" (default=ebnovalues.txt)\n"); + printf(" This file should contain lines in this format:\n"); + printf(" # Eb/No(dB) Target Errors\n"); + printf(" 0.1 5000\n"); + printf(" 0.6 5000\n"); + printf(" 1.1 1000\n"); + printf(" 1.6 1000\n"); + printf(" ...\n"); + printf(" (lines beginning with a # are treated as comments\n\n"); +} + +#define SIM_POINTS_MAX 20 + +int main(int argc, char* argv[]) +{ + + float EbNodB[SIM_POINTS_MAX]; + int nerrstgt[SIM_POINTS_MAX]; + FILE *fin; + + char fnamein[128]= "ebnovalues.txt"; + char buf[128]; + + int nitems = 0; + int code_idx = 0; + int nthreads = 8; + int ch_type = CHANNEL_AWGN; + int ap_index = AP_NONE; + + // parse command line + while(--argc) { + argv++; + if (strncmp(*argv,"-h",2)==0) { + syntax(); + return 0; + } + else + if (strncmp(*argv,"-q",2)==0) { + code_idx = (int)atoi((*argv)+2); + if (code_idx>7) { + printf("Invalid code index\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-t",2)==0) { + nthreads = (int)atoi((*argv)+2); + +// printf("nthreads = %d\n",nthreads); + + if (nthreads>NTHREADS_MAX) { + printf("Invalid number of threads\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-c",2)==0) { + ch_type = (int)atoi((*argv)+2); + if (ch_type>CHANNEL_FASTFADING) { + printf("Invalid channel type\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-a",2)==0) { + ap_index = (int)atoi((*argv)+2); + if (ap_index>AP_LAST) { + printf("Invalid a-priori information index\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-f",2)==0) { + strncpy(fnamein,(*argv)+2,127); + } + else + if (strncmp(*argv,"-h",2)==0) { + syntax(); + return -1; + } + else + if (strncmp(*argv,"-v",2)==0) + verbose = TRUE; + else { + printf("Invalid option\n"); + syntax(); + return -1; + } + } + + // parse points to be simulated from the input file + fin = fopen(fnamein,"r"); + if (!fin) { + printf("Can't open file: %s\n",fnamein); + syntax(); + return -1; + } + + while (fgets(buf,128,fin)!=0) + if (*buf=='#' || *buf=='\n' ) + continue; + else + if (nitems==SIM_POINTS_MAX) + break; + else + if (sscanf(buf,"%f %u",&EbNodB[nitems],&nerrstgt[nitems])!=2) { + printf("Invalid input file format\n"); + syntax(); + return -1; + } + else + nitems++; + + fclose(fin); + + if (nitems==0) { + printf("No Eb/No point specified in file %s\n",fnamein); + syntax(); + return -1; + } + + printf("\nQ65 Word Error Rate Simulator\n"); + printf("(c) 2016-2020, Nico Palermo - IV3NWV\n\n"); + + printf("Nthreads = %d\n",nthreads); + switch(ch_type) { + case CHANNEL_AWGN: + printf("Channel = AWGN\n"); + break; + case CHANNEL_RAYLEIGH: + printf("Channel = Rayleigh\n"); + break; + case CHANNEL_FASTFADING: + printf("Channel = Fast Fading\n"); + break; + } + printf("Codename = %s\n",codetotest[code_idx]->name); + printf("A-priori = %s\n",ap_str[ap_index]); + printf("Eb/No input file = %s\n\n",fnamein); + + wer_test_proc(codetotest[code_idx], nthreads, ch_type, ap_index, EbNodB, nerrstgt, nitems); + + printf("\n\n\n"); + return 0; +} + diff --git a/lib/qra/q65/qra15_65_64_irr_e23.c b/lib/qra/q65/qra15_65_64_irr_e23.c index 4cdc5650..88667169 100755 --- a/lib/qra/q65/qra15_65_64_irr_e23.c +++ b/lib/qra/q65/qra15_65_64_irr_e23.c @@ -1,558 +1,558 @@ -// qra15_65_64_irr_e23.c -// Encoding/Decoding tables for Q-ary RA code (15,65) over GF(64) -// Code Name: qra15_65_64_irr_e23 -// (15,65) RA Code over GF(64) - -// (c) 2020 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy - -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#include "qra15_65_64_irr_e23.h" - -// File generated by npiwnarsavehc.m - -#define qra_K 15 // number of information symbols -#define qra_N 65 // codeword length in symbols -#define qra_m 6 // bits/symbol -#define qra_M 64 // Symbol alphabet cardinality -#define qra_a 1 // grouping factor -#define qra_NC 50 // number of check symbols (N-K) - -// Defines used by the message passing decoder -------- - -#define qra_V 65 // number of variables in the code graph (N) -#define qra_C 116 // number of factors in the code graph (N +(N-K)+1) -#define qra_NMSG 216 // number of msgs in the code graph -#define qra_MAXVDEG 5 // maximum variable degree -#define qra_MAXCDEG 3 // maximum factor degree -#define qra_R 0.23077f // code rate (K/N) -#define CODE_NAME "qra15_65_64_irr_e23" // code name - -// table of the systematic symbols indexes in the accumulator chain -static const int qra_acc_input_idx[qra_NC+1] = { - 13, 1, 3, 4, 8, 12, 9, 14, 10, 5, - 0, 7, 1, 11, 8, 9, 12, 6, 3, 10, - 7, 5, 2, 13, 12, 4, 8, 0, 1, 11, - 2, 9, 14, 5, 6, 13, 7, 12, 11, 2, - 9, 0, 10, 4, 7, 14, 8, 11, 3, 6, - 10 -}; - -// table of the systematic symbols weight logarithms over GF(M) -static const int qra_acc_input_wlog[qra_NC+1] = { - 0, 14, 0, 0, 13, 37, 0, 27, 56, 62, - 29, 0, 52, 34, 62, 4, 3, 22, 25, 0, - 22, 0, 20, 10, 0, 43, 53, 60, 0, 0, - 0, 62, 0, 5, 0, 61, 36, 31, 61, 59, - 10, 0, 29, 39, 25, 18, 0, 14, 11, 50, - 17 -}; - -// table of the logarithms of the elements of GF(M) (log(0) never used) -static const int qra_log[qra_M] = { - -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, - 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, - 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, - 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, - 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, - 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, - 20, 59, 57, 58 -}; - -// table of GF(M) elements given their logarithm -static const int qra_exp[qra_M-1] = { - 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, - 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, - 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, - 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, - 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, - 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, - 57, 49, 33 -}; - -// table of the messages weight logarithms over GF(M) -static const int qra_msgw[qra_NMSG] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 14, 0, 0, 13, - 37, 0, 27, 56, 62, 29, 0, 52, 34, 62, - 4, 3, 22, 25, 0, 22, 0, 20, 10, 0, - 43, 53, 60, 0, 0, 0, 62, 0, 5, 0, - 61, 36, 31, 61, 59, 10, 0, 29, 39, 25, - 18, 0, 14, 11, 50, 17, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 -}; - -// table of the degrees of the variable nodes -static const int qra_vdeg[qra_V] = { - 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, - 5, 5, 5, 4, 4, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3 -}; - -// table of the degrees of the factor nodes -static const int qra_cdeg[qra_C] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 2, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 2 -}; - -// table (uncompressed) of the v->c message indexes (-1=unused entry) -static const int qra_v2cmidx[qra_V*qra_MAXVDEG] = { - 0, 75, 92, 106, -1, - 1, 66, 77, 93, -1, - 2, 87, 95, 104, -1, - 3, 67, 83, 113, -1, - 4, 68, 90, 108, -1, - 5, 74, 86, 98, -1, - 6, 82, 99, 114, -1, - 7, 76, 85, 101, 109, - 8, 69, 79, 91, 111, - 9, 71, 80, 96, 105, - 10, 73, 84, 107, 115, - 11, 78, 94, 103, 112, - 12, 70, 81, 89, 102, - 13, 65, 88, 100, -1, - 14, 72, 97, 110, -1, - 15, 116, 117, -1, -1, - 16, 118, 119, -1, -1, - 17, 120, 121, -1, -1, - 18, 122, 123, -1, -1, - 19, 124, 125, -1, -1, - 20, 126, 127, -1, -1, - 21, 128, 129, -1, -1, - 22, 130, 131, -1, -1, - 23, 132, 133, -1, -1, - 24, 134, 135, -1, -1, - 25, 136, 137, -1, -1, - 26, 138, 139, -1, -1, - 27, 140, 141, -1, -1, - 28, 142, 143, -1, -1, - 29, 144, 145, -1, -1, - 30, 146, 147, -1, -1, - 31, 148, 149, -1, -1, - 32, 150, 151, -1, -1, - 33, 152, 153, -1, -1, - 34, 154, 155, -1, -1, - 35, 156, 157, -1, -1, - 36, 158, 159, -1, -1, - 37, 160, 161, -1, -1, - 38, 162, 163, -1, -1, - 39, 164, 165, -1, -1, - 40, 166, 167, -1, -1, - 41, 168, 169, -1, -1, - 42, 170, 171, -1, -1, - 43, 172, 173, -1, -1, - 44, 174, 175, -1, -1, - 45, 176, 177, -1, -1, - 46, 178, 179, -1, -1, - 47, 180, 181, -1, -1, - 48, 182, 183, -1, -1, - 49, 184, 185, -1, -1, - 50, 186, 187, -1, -1, - 51, 188, 189, -1, -1, - 52, 190, 191, -1, -1, - 53, 192, 193, -1, -1, - 54, 194, 195, -1, -1, - 55, 196, 197, -1, -1, - 56, 198, 199, -1, -1, - 57, 200, 201, -1, -1, - 58, 202, 203, -1, -1, - 59, 204, 205, -1, -1, - 60, 206, 207, -1, -1, - 61, 208, 209, -1, -1, - 62, 210, 211, -1, -1, - 63, 212, 213, -1, -1, - 64, 214, 215, -1, -1 -}; - -// table (uncompressed) of the c->v message indexes (-1=unused entry) -static const int qra_c2vmidx[qra_C*qra_MAXCDEG] = { - 0, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1, - 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1, - 8, -1, -1, 9, -1, -1, 10, -1, -1, 11, -1, -1, - 12, -1, -1, 13, -1, -1, 14, -1, -1, 15, -1, -1, - 16, -1, -1, 17, -1, -1, 18, -1, -1, 19, -1, -1, - 20, -1, -1, 21, -1, -1, 22, -1, -1, 23, -1, -1, - 24, -1, -1, 25, -1, -1, 26, -1, -1, 27, -1, -1, - 28, -1, -1, 29, -1, -1, 30, -1, -1, 31, -1, -1, - 32, -1, -1, 33, -1, -1, 34, -1, -1, 35, -1, -1, - 36, -1, -1, 37, -1, -1, 38, -1, -1, 39, -1, -1, - 40, -1, -1, 41, -1, -1, 42, -1, -1, 43, -1, -1, - 44, -1, -1, 45, -1, -1, 46, -1, -1, 47, -1, -1, - 48, -1, -1, 49, -1, -1, 50, -1, -1, 51, -1, -1, - 52, -1, -1, 53, -1, -1, 54, -1, -1, 55, -1, -1, - 56, -1, -1, 57, -1, -1, 58, -1, -1, 59, -1, -1, - 60, -1, -1, 61, -1, -1, 62, -1, -1, 63, -1, -1, - 64, -1, -1, 65, 116, -1, 66, 117, 118, 67, 119, 120, - 68, 121, 122, 69, 123, 124, 70, 125, 126, 71, 127, 128, - 72, 129, 130, 73, 131, 132, 74, 133, 134, 75, 135, 136, - 76, 137, 138, 77, 139, 140, 78, 141, 142, 79, 143, 144, - 80, 145, 146, 81, 147, 148, 82, 149, 150, 83, 151, 152, - 84, 153, 154, 85, 155, 156, 86, 157, 158, 87, 159, 160, - 88, 161, 162, 89, 163, 164, 90, 165, 166, 91, 167, 168, - 92, 169, 170, 93, 171, 172, 94, 173, 174, 95, 175, 176, - 96, 177, 178, 97, 179, 180, 98, 181, 182, 99, 183, 184, -100, 185, 186, 101, 187, 188, 102, 189, 190, 103, 191, 192, -104, 193, 194, 105, 195, 196, 106, 197, 198, 107, 199, 200, -108, 201, 202, 109, 203, 204, 110, 205, 206, 111, 207, 208, -112, 209, 210, 113, 211, 212, 114, 213, 214, 115, 215, -1 -}; - -// permutation matrix to compute Prob(x*alfa^logw) -static const int qra_pmat[qra_M*qra_M] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 0, 33, 1, 32, 2, 35, 3, 34, 4, 37, 5, 36, 6, 39, 7, 38, - 8, 41, 9, 40, 10, 43, 11, 42, 12, 45, 13, 44, 14, 47, 15, 46, - 16, 49, 17, 48, 18, 51, 19, 50, 20, 53, 21, 52, 22, 55, 23, 54, - 24, 57, 25, 56, 26, 59, 27, 58, 28, 61, 29, 60, 30, 63, 31, 62, - 0, 49, 33, 16, 1, 48, 32, 17, 2, 51, 35, 18, 3, 50, 34, 19, - 4, 53, 37, 20, 5, 52, 36, 21, 6, 55, 39, 22, 7, 54, 38, 23, - 8, 57, 41, 24, 9, 56, 40, 25, 10, 59, 43, 26, 11, 58, 42, 27, - 12, 61, 45, 28, 13, 60, 44, 29, 14, 63, 47, 30, 15, 62, 46, 31, - 0, 57, 49, 8, 33, 24, 16, 41, 1, 56, 48, 9, 32, 25, 17, 40, - 2, 59, 51, 10, 35, 26, 18, 43, 3, 58, 50, 11, 34, 27, 19, 42, - 4, 61, 53, 12, 37, 28, 20, 45, 5, 60, 52, 13, 36, 29, 21, 44, - 6, 63, 55, 14, 39, 30, 22, 47, 7, 62, 54, 15, 38, 31, 23, 46, - 0, 61, 57, 4, 49, 12, 8, 53, 33, 28, 24, 37, 16, 45, 41, 20, - 1, 60, 56, 5, 48, 13, 9, 52, 32, 29, 25, 36, 17, 44, 40, 21, - 2, 63, 59, 6, 51, 14, 10, 55, 35, 30, 26, 39, 18, 47, 43, 22, - 3, 62, 58, 7, 50, 15, 11, 54, 34, 31, 27, 38, 19, 46, 42, 23, - 0, 63, 61, 2, 57, 6, 4, 59, 49, 14, 12, 51, 8, 55, 53, 10, - 33, 30, 28, 35, 24, 39, 37, 26, 16, 47, 45, 18, 41, 22, 20, 43, - 1, 62, 60, 3, 56, 7, 5, 58, 48, 15, 13, 50, 9, 54, 52, 11, - 32, 31, 29, 34, 25, 38, 36, 27, 17, 46, 44, 19, 40, 23, 21, 42, - 0, 62, 63, 1, 61, 3, 2, 60, 57, 7, 6, 56, 4, 58, 59, 5, - 49, 15, 14, 48, 12, 50, 51, 13, 8, 54, 55, 9, 53, 11, 10, 52, - 33, 31, 30, 32, 28, 34, 35, 29, 24, 38, 39, 25, 37, 27, 26, 36, - 16, 46, 47, 17, 45, 19, 18, 44, 41, 23, 22, 40, 20, 42, 43, 21, - 0, 31, 62, 33, 63, 32, 1, 30, 61, 34, 3, 28, 2, 29, 60, 35, - 57, 38, 7, 24, 6, 25, 56, 39, 4, 27, 58, 37, 59, 36, 5, 26, - 49, 46, 15, 16, 14, 17, 48, 47, 12, 19, 50, 45, 51, 44, 13, 18, - 8, 23, 54, 41, 55, 40, 9, 22, 53, 42, 11, 20, 10, 21, 52, 43, - 0, 46, 31, 49, 62, 16, 33, 15, 63, 17, 32, 14, 1, 47, 30, 48, - 61, 19, 34, 12, 3, 45, 28, 50, 2, 44, 29, 51, 60, 18, 35, 13, - 57, 23, 38, 8, 7, 41, 24, 54, 6, 40, 25, 55, 56, 22, 39, 9, - 4, 42, 27, 53, 58, 20, 37, 11, 59, 21, 36, 10, 5, 43, 26, 52, - 0, 23, 46, 57, 31, 8, 49, 38, 62, 41, 16, 7, 33, 54, 15, 24, - 63, 40, 17, 6, 32, 55, 14, 25, 1, 22, 47, 56, 30, 9, 48, 39, - 61, 42, 19, 4, 34, 53, 12, 27, 3, 20, 45, 58, 28, 11, 50, 37, - 2, 21, 44, 59, 29, 10, 51, 36, 60, 43, 18, 5, 35, 52, 13, 26, - 0, 42, 23, 61, 46, 4, 57, 19, 31, 53, 8, 34, 49, 27, 38, 12, - 62, 20, 41, 3, 16, 58, 7, 45, 33, 11, 54, 28, 15, 37, 24, 50, - 63, 21, 40, 2, 17, 59, 6, 44, 32, 10, 55, 29, 14, 36, 25, 51, - 1, 43, 22, 60, 47, 5, 56, 18, 30, 52, 9, 35, 48, 26, 39, 13, - 0, 21, 42, 63, 23, 2, 61, 40, 46, 59, 4, 17, 57, 44, 19, 6, - 31, 10, 53, 32, 8, 29, 34, 55, 49, 36, 27, 14, 38, 51, 12, 25, - 62, 43, 20, 1, 41, 60, 3, 22, 16, 5, 58, 47, 7, 18, 45, 56, - 33, 52, 11, 30, 54, 35, 28, 9, 15, 26, 37, 48, 24, 13, 50, 39, - 0, 43, 21, 62, 42, 1, 63, 20, 23, 60, 2, 41, 61, 22, 40, 3, - 46, 5, 59, 16, 4, 47, 17, 58, 57, 18, 44, 7, 19, 56, 6, 45, - 31, 52, 10, 33, 53, 30, 32, 11, 8, 35, 29, 54, 34, 9, 55, 28, - 49, 26, 36, 15, 27, 48, 14, 37, 38, 13, 51, 24, 12, 39, 25, 50, - 0, 52, 43, 31, 21, 33, 62, 10, 42, 30, 1, 53, 63, 11, 20, 32, - 23, 35, 60, 8, 2, 54, 41, 29, 61, 9, 22, 34, 40, 28, 3, 55, - 46, 26, 5, 49, 59, 15, 16, 36, 4, 48, 47, 27, 17, 37, 58, 14, - 57, 13, 18, 38, 44, 24, 7, 51, 19, 39, 56, 12, 6, 50, 45, 25, - 0, 26, 52, 46, 43, 49, 31, 5, 21, 15, 33, 59, 62, 36, 10, 16, - 42, 48, 30, 4, 1, 27, 53, 47, 63, 37, 11, 17, 20, 14, 32, 58, - 23, 13, 35, 57, 60, 38, 8, 18, 2, 24, 54, 44, 41, 51, 29, 7, - 61, 39, 9, 19, 22, 12, 34, 56, 40, 50, 28, 6, 3, 25, 55, 45, - 0, 13, 26, 23, 52, 57, 46, 35, 43, 38, 49, 60, 31, 18, 5, 8, - 21, 24, 15, 2, 33, 44, 59, 54, 62, 51, 36, 41, 10, 7, 16, 29, - 42, 39, 48, 61, 30, 19, 4, 9, 1, 12, 27, 22, 53, 56, 47, 34, - 63, 50, 37, 40, 11, 6, 17, 28, 20, 25, 14, 3, 32, 45, 58, 55, - 0, 39, 13, 42, 26, 61, 23, 48, 52, 19, 57, 30, 46, 9, 35, 4, - 43, 12, 38, 1, 49, 22, 60, 27, 31, 56, 18, 53, 5, 34, 8, 47, - 21, 50, 24, 63, 15, 40, 2, 37, 33, 6, 44, 11, 59, 28, 54, 17, - 62, 25, 51, 20, 36, 3, 41, 14, 10, 45, 7, 32, 16, 55, 29, 58, - 0, 50, 39, 21, 13, 63, 42, 24, 26, 40, 61, 15, 23, 37, 48, 2, - 52, 6, 19, 33, 57, 11, 30, 44, 46, 28, 9, 59, 35, 17, 4, 54, - 43, 25, 12, 62, 38, 20, 1, 51, 49, 3, 22, 36, 60, 14, 27, 41, - 31, 45, 56, 10, 18, 32, 53, 7, 5, 55, 34, 16, 8, 58, 47, 29, - 0, 25, 50, 43, 39, 62, 21, 12, 13, 20, 63, 38, 42, 51, 24, 1, - 26, 3, 40, 49, 61, 36, 15, 22, 23, 14, 37, 60, 48, 41, 2, 27, - 52, 45, 6, 31, 19, 10, 33, 56, 57, 32, 11, 18, 30, 7, 44, 53, - 46, 55, 28, 5, 9, 16, 59, 34, 35, 58, 17, 8, 4, 29, 54, 47, - 0, 45, 25, 52, 50, 31, 43, 6, 39, 10, 62, 19, 21, 56, 12, 33, - 13, 32, 20, 57, 63, 18, 38, 11, 42, 7, 51, 30, 24, 53, 1, 44, - 26, 55, 3, 46, 40, 5, 49, 28, 61, 16, 36, 9, 15, 34, 22, 59, - 23, 58, 14, 35, 37, 8, 60, 17, 48, 29, 41, 4, 2, 47, 27, 54, - 0, 55, 45, 26, 25, 46, 52, 3, 50, 5, 31, 40, 43, 28, 6, 49, - 39, 16, 10, 61, 62, 9, 19, 36, 21, 34, 56, 15, 12, 59, 33, 22, - 13, 58, 32, 23, 20, 35, 57, 14, 63, 8, 18, 37, 38, 17, 11, 60, - 42, 29, 7, 48, 51, 4, 30, 41, 24, 47, 53, 2, 1, 54, 44, 27, - 0, 58, 55, 13, 45, 23, 26, 32, 25, 35, 46, 20, 52, 14, 3, 57, - 50, 8, 5, 63, 31, 37, 40, 18, 43, 17, 28, 38, 6, 60, 49, 11, - 39, 29, 16, 42, 10, 48, 61, 7, 62, 4, 9, 51, 19, 41, 36, 30, - 21, 47, 34, 24, 56, 2, 15, 53, 12, 54, 59, 1, 33, 27, 22, 44, - 0, 29, 58, 39, 55, 42, 13, 16, 45, 48, 23, 10, 26, 7, 32, 61, - 25, 4, 35, 62, 46, 51, 20, 9, 52, 41, 14, 19, 3, 30, 57, 36, - 50, 47, 8, 21, 5, 24, 63, 34, 31, 2, 37, 56, 40, 53, 18, 15, - 43, 54, 17, 12, 28, 1, 38, 59, 6, 27, 60, 33, 49, 44, 11, 22, - 0, 47, 29, 50, 58, 21, 39, 8, 55, 24, 42, 5, 13, 34, 16, 63, - 45, 2, 48, 31, 23, 56, 10, 37, 26, 53, 7, 40, 32, 15, 61, 18, - 25, 54, 4, 43, 35, 12, 62, 17, 46, 1, 51, 28, 20, 59, 9, 38, - 52, 27, 41, 6, 14, 33, 19, 60, 3, 44, 30, 49, 57, 22, 36, 11, - 0, 54, 47, 25, 29, 43, 50, 4, 58, 12, 21, 35, 39, 17, 8, 62, - 55, 1, 24, 46, 42, 28, 5, 51, 13, 59, 34, 20, 16, 38, 63, 9, - 45, 27, 2, 52, 48, 6, 31, 41, 23, 33, 56, 14, 10, 60, 37, 19, - 26, 44, 53, 3, 7, 49, 40, 30, 32, 22, 15, 57, 61, 11, 18, 36, - 0, 27, 54, 45, 47, 52, 25, 2, 29, 6, 43, 48, 50, 41, 4, 31, - 58, 33, 12, 23, 21, 14, 35, 56, 39, 60, 17, 10, 8, 19, 62, 37, - 55, 44, 1, 26, 24, 3, 46, 53, 42, 49, 28, 7, 5, 30, 51, 40, - 13, 22, 59, 32, 34, 57, 20, 15, 16, 11, 38, 61, 63, 36, 9, 18, - 0, 44, 27, 55, 54, 26, 45, 1, 47, 3, 52, 24, 25, 53, 2, 46, - 29, 49, 6, 42, 43, 7, 48, 28, 50, 30, 41, 5, 4, 40, 31, 51, - 58, 22, 33, 13, 12, 32, 23, 59, 21, 57, 14, 34, 35, 15, 56, 20, - 39, 11, 60, 16, 17, 61, 10, 38, 8, 36, 19, 63, 62, 18, 37, 9, - 0, 22, 44, 58, 27, 13, 55, 33, 54, 32, 26, 12, 45, 59, 1, 23, - 47, 57, 3, 21, 52, 34, 24, 14, 25, 15, 53, 35, 2, 20, 46, 56, - 29, 11, 49, 39, 6, 16, 42, 60, 43, 61, 7, 17, 48, 38, 28, 10, - 50, 36, 30, 8, 41, 63, 5, 19, 4, 18, 40, 62, 31, 9, 51, 37, - 0, 11, 22, 29, 44, 39, 58, 49, 27, 16, 13, 6, 55, 60, 33, 42, - 54, 61, 32, 43, 26, 17, 12, 7, 45, 38, 59, 48, 1, 10, 23, 28, - 47, 36, 57, 50, 3, 8, 21, 30, 52, 63, 34, 41, 24, 19, 14, 5, - 25, 18, 15, 4, 53, 62, 35, 40, 2, 9, 20, 31, 46, 37, 56, 51, - 0, 36, 11, 47, 22, 50, 29, 57, 44, 8, 39, 3, 58, 30, 49, 21, - 27, 63, 16, 52, 13, 41, 6, 34, 55, 19, 60, 24, 33, 5, 42, 14, - 54, 18, 61, 25, 32, 4, 43, 15, 26, 62, 17, 53, 12, 40, 7, 35, - 45, 9, 38, 2, 59, 31, 48, 20, 1, 37, 10, 46, 23, 51, 28, 56, - 0, 18, 36, 54, 11, 25, 47, 61, 22, 4, 50, 32, 29, 15, 57, 43, - 44, 62, 8, 26, 39, 53, 3, 17, 58, 40, 30, 12, 49, 35, 21, 7, - 27, 9, 63, 45, 16, 2, 52, 38, 13, 31, 41, 59, 6, 20, 34, 48, - 55, 37, 19, 1, 60, 46, 24, 10, 33, 51, 5, 23, 42, 56, 14, 28, - 0, 9, 18, 27, 36, 45, 54, 63, 11, 2, 25, 16, 47, 38, 61, 52, - 22, 31, 4, 13, 50, 59, 32, 41, 29, 20, 15, 6, 57, 48, 43, 34, - 44, 37, 62, 55, 8, 1, 26, 19, 39, 46, 53, 60, 3, 10, 17, 24, - 58, 51, 40, 33, 30, 23, 12, 5, 49, 56, 35, 42, 21, 28, 7, 14, - 0, 37, 9, 44, 18, 55, 27, 62, 36, 1, 45, 8, 54, 19, 63, 26, - 11, 46, 2, 39, 25, 60, 16, 53, 47, 10, 38, 3, 61, 24, 52, 17, - 22, 51, 31, 58, 4, 33, 13, 40, 50, 23, 59, 30, 32, 5, 41, 12, - 29, 56, 20, 49, 15, 42, 6, 35, 57, 28, 48, 21, 43, 14, 34, 7, - 0, 51, 37, 22, 9, 58, 44, 31, 18, 33, 55, 4, 27, 40, 62, 13, - 36, 23, 1, 50, 45, 30, 8, 59, 54, 5, 19, 32, 63, 12, 26, 41, - 11, 56, 46, 29, 2, 49, 39, 20, 25, 42, 60, 15, 16, 35, 53, 6, - 47, 28, 10, 57, 38, 21, 3, 48, 61, 14, 24, 43, 52, 7, 17, 34, - 0, 56, 51, 11, 37, 29, 22, 46, 9, 49, 58, 2, 44, 20, 31, 39, - 18, 42, 33, 25, 55, 15, 4, 60, 27, 35, 40, 16, 62, 6, 13, 53, - 36, 28, 23, 47, 1, 57, 50, 10, 45, 21, 30, 38, 8, 48, 59, 3, - 54, 14, 5, 61, 19, 43, 32, 24, 63, 7, 12, 52, 26, 34, 41, 17, - 0, 28, 56, 36, 51, 47, 11, 23, 37, 57, 29, 1, 22, 10, 46, 50, - 9, 21, 49, 45, 58, 38, 2, 30, 44, 48, 20, 8, 31, 3, 39, 59, - 18, 14, 42, 54, 33, 61, 25, 5, 55, 43, 15, 19, 4, 24, 60, 32, - 27, 7, 35, 63, 40, 52, 16, 12, 62, 34, 6, 26, 13, 17, 53, 41, - 0, 14, 28, 18, 56, 54, 36, 42, 51, 61, 47, 33, 11, 5, 23, 25, - 37, 43, 57, 55, 29, 19, 1, 15, 22, 24, 10, 4, 46, 32, 50, 60, - 9, 7, 21, 27, 49, 63, 45, 35, 58, 52, 38, 40, 2, 12, 30, 16, - 44, 34, 48, 62, 20, 26, 8, 6, 31, 17, 3, 13, 39, 41, 59, 53, - 0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45, - 51, 52, 61, 58, 47, 40, 33, 38, 11, 12, 5, 2, 23, 16, 25, 30, - 37, 34, 43, 44, 57, 62, 55, 48, 29, 26, 19, 20, 1, 6, 15, 8, - 22, 17, 24, 31, 10, 13, 4, 3, 46, 41, 32, 39, 50, 53, 60, 59, - 0, 34, 7, 37, 14, 44, 9, 43, 28, 62, 27, 57, 18, 48, 21, 55, - 56, 26, 63, 29, 54, 20, 49, 19, 36, 6, 35, 1, 42, 8, 45, 15, - 51, 17, 52, 22, 61, 31, 58, 24, 47, 13, 40, 10, 33, 3, 38, 4, - 11, 41, 12, 46, 5, 39, 2, 32, 23, 53, 16, 50, 25, 59, 30, 60, - 0, 17, 34, 51, 7, 22, 37, 52, 14, 31, 44, 61, 9, 24, 43, 58, - 28, 13, 62, 47, 27, 10, 57, 40, 18, 3, 48, 33, 21, 4, 55, 38, - 56, 41, 26, 11, 63, 46, 29, 12, 54, 39, 20, 5, 49, 32, 19, 2, - 36, 53, 6, 23, 35, 50, 1, 16, 42, 59, 8, 25, 45, 60, 15, 30, - 0, 41, 17, 56, 34, 11, 51, 26, 7, 46, 22, 63, 37, 12, 52, 29, - 14, 39, 31, 54, 44, 5, 61, 20, 9, 32, 24, 49, 43, 2, 58, 19, - 28, 53, 13, 36, 62, 23, 47, 6, 27, 50, 10, 35, 57, 16, 40, 1, - 18, 59, 3, 42, 48, 25, 33, 8, 21, 60, 4, 45, 55, 30, 38, 15, - 0, 53, 41, 28, 17, 36, 56, 13, 34, 23, 11, 62, 51, 6, 26, 47, - 7, 50, 46, 27, 22, 35, 63, 10, 37, 16, 12, 57, 52, 1, 29, 40, - 14, 59, 39, 18, 31, 42, 54, 3, 44, 25, 5, 48, 61, 8, 20, 33, - 9, 60, 32, 21, 24, 45, 49, 4, 43, 30, 2, 55, 58, 15, 19, 38, - 0, 59, 53, 14, 41, 18, 28, 39, 17, 42, 36, 31, 56, 3, 13, 54, - 34, 25, 23, 44, 11, 48, 62, 5, 51, 8, 6, 61, 26, 33, 47, 20, - 7, 60, 50, 9, 46, 21, 27, 32, 22, 45, 35, 24, 63, 4, 10, 49, - 37, 30, 16, 43, 12, 55, 57, 2, 52, 15, 1, 58, 29, 38, 40, 19, - 0, 60, 59, 7, 53, 9, 14, 50, 41, 21, 18, 46, 28, 32, 39, 27, - 17, 45, 42, 22, 36, 24, 31, 35, 56, 4, 3, 63, 13, 49, 54, 10, - 34, 30, 25, 37, 23, 43, 44, 16, 11, 55, 48, 12, 62, 2, 5, 57, - 51, 15, 8, 52, 6, 58, 61, 1, 26, 38, 33, 29, 47, 19, 20, 40, - 0, 30, 60, 34, 59, 37, 7, 25, 53, 43, 9, 23, 14, 16, 50, 44, - 41, 55, 21, 11, 18, 12, 46, 48, 28, 2, 32, 62, 39, 57, 27, 5, - 17, 15, 45, 51, 42, 52, 22, 8, 36, 58, 24, 6, 31, 1, 35, 61, - 56, 38, 4, 26, 3, 29, 63, 33, 13, 19, 49, 47, 54, 40, 10, 20, - 0, 15, 30, 17, 60, 51, 34, 45, 59, 52, 37, 42, 7, 8, 25, 22, - 53, 58, 43, 36, 9, 6, 23, 24, 14, 1, 16, 31, 50, 61, 44, 35, - 41, 38, 55, 56, 21, 26, 11, 4, 18, 29, 12, 3, 46, 33, 48, 63, - 28, 19, 2, 13, 32, 47, 62, 49, 39, 40, 57, 54, 27, 20, 5, 10, - 0, 38, 15, 41, 30, 56, 17, 55, 60, 26, 51, 21, 34, 4, 45, 11, - 59, 29, 52, 18, 37, 3, 42, 12, 7, 33, 8, 46, 25, 63, 22, 48, - 53, 19, 58, 28, 43, 13, 36, 2, 9, 47, 6, 32, 23, 49, 24, 62, - 14, 40, 1, 39, 16, 54, 31, 57, 50, 20, 61, 27, 44, 10, 35, 5, - 0, 19, 38, 53, 15, 28, 41, 58, 30, 13, 56, 43, 17, 2, 55, 36, - 60, 47, 26, 9, 51, 32, 21, 6, 34, 49, 4, 23, 45, 62, 11, 24, - 59, 40, 29, 14, 52, 39, 18, 1, 37, 54, 3, 16, 42, 57, 12, 31, - 7, 20, 33, 50, 8, 27, 46, 61, 25, 10, 63, 44, 22, 5, 48, 35, - 0, 40, 19, 59, 38, 14, 53, 29, 15, 39, 28, 52, 41, 1, 58, 18, - 30, 54, 13, 37, 56, 16, 43, 3, 17, 57, 2, 42, 55, 31, 36, 12, - 60, 20, 47, 7, 26, 50, 9, 33, 51, 27, 32, 8, 21, 61, 6, 46, - 34, 10, 49, 25, 4, 44, 23, 63, 45, 5, 62, 22, 11, 35, 24, 48, - 0, 20, 40, 60, 19, 7, 59, 47, 38, 50, 14, 26, 53, 33, 29, 9, - 15, 27, 39, 51, 28, 8, 52, 32, 41, 61, 1, 21, 58, 46, 18, 6, - 30, 10, 54, 34, 13, 25, 37, 49, 56, 44, 16, 4, 43, 63, 3, 23, - 17, 5, 57, 45, 2, 22, 42, 62, 55, 35, 31, 11, 36, 48, 12, 24, - 0, 10, 20, 30, 40, 34, 60, 54, 19, 25, 7, 13, 59, 49, 47, 37, - 38, 44, 50, 56, 14, 4, 26, 16, 53, 63, 33, 43, 29, 23, 9, 3, - 15, 5, 27, 17, 39, 45, 51, 57, 28, 22, 8, 2, 52, 62, 32, 42, - 41, 35, 61, 55, 1, 11, 21, 31, 58, 48, 46, 36, 18, 24, 6, 12, - 0, 5, 10, 15, 20, 17, 30, 27, 40, 45, 34, 39, 60, 57, 54, 51, - 19, 22, 25, 28, 7, 2, 13, 8, 59, 62, 49, 52, 47, 42, 37, 32, - 38, 35, 44, 41, 50, 55, 56, 61, 14, 11, 4, 1, 26, 31, 16, 21, - 53, 48, 63, 58, 33, 36, 43, 46, 29, 24, 23, 18, 9, 12, 3, 6, - 0, 35, 5, 38, 10, 41, 15, 44, 20, 55, 17, 50, 30, 61, 27, 56, - 40, 11, 45, 14, 34, 1, 39, 4, 60, 31, 57, 26, 54, 21, 51, 16, - 19, 48, 22, 53, 25, 58, 28, 63, 7, 36, 2, 33, 13, 46, 8, 43, - 59, 24, 62, 29, 49, 18, 52, 23, 47, 12, 42, 9, 37, 6, 32, 3, - 0, 48, 35, 19, 5, 53, 38, 22, 10, 58, 41, 25, 15, 63, 44, 28, - 20, 36, 55, 7, 17, 33, 50, 2, 30, 46, 61, 13, 27, 43, 56, 8, - 40, 24, 11, 59, 45, 29, 14, 62, 34, 18, 1, 49, 39, 23, 4, 52, - 60, 12, 31, 47, 57, 9, 26, 42, 54, 6, 21, 37, 51, 3, 16, 32, - 0, 24, 48, 40, 35, 59, 19, 11, 5, 29, 53, 45, 38, 62, 22, 14, - 10, 18, 58, 34, 41, 49, 25, 1, 15, 23, 63, 39, 44, 52, 28, 4, - 20, 12, 36, 60, 55, 47, 7, 31, 17, 9, 33, 57, 50, 42, 2, 26, - 30, 6, 46, 54, 61, 37, 13, 21, 27, 3, 43, 51, 56, 32, 8, 16, - 0, 12, 24, 20, 48, 60, 40, 36, 35, 47, 59, 55, 19, 31, 11, 7, - 5, 9, 29, 17, 53, 57, 45, 33, 38, 42, 62, 50, 22, 26, 14, 2, - 10, 6, 18, 30, 58, 54, 34, 46, 41, 37, 49, 61, 25, 21, 1, 13, - 15, 3, 23, 27, 63, 51, 39, 43, 44, 32, 52, 56, 28, 16, 4, 8, - 0, 6, 12, 10, 24, 30, 20, 18, 48, 54, 60, 58, 40, 46, 36, 34, - 35, 37, 47, 41, 59, 61, 55, 49, 19, 21, 31, 25, 11, 13, 7, 1, - 5, 3, 9, 15, 29, 27, 17, 23, 53, 51, 57, 63, 45, 43, 33, 39, - 38, 32, 42, 44, 62, 56, 50, 52, 22, 16, 26, 28, 14, 8, 2, 4, - 0, 3, 6, 5, 12, 15, 10, 9, 24, 27, 30, 29, 20, 23, 18, 17, - 48, 51, 54, 53, 60, 63, 58, 57, 40, 43, 46, 45, 36, 39, 34, 33, - 35, 32, 37, 38, 47, 44, 41, 42, 59, 56, 61, 62, 55, 52, 49, 50, - 19, 16, 21, 22, 31, 28, 25, 26, 11, 8, 13, 14, 7, 4, 1, 2, - 0, 32, 3, 35, 6, 38, 5, 37, 12, 44, 15, 47, 10, 42, 9, 41, - 24, 56, 27, 59, 30, 62, 29, 61, 20, 52, 23, 55, 18, 50, 17, 49, - 48, 16, 51, 19, 54, 22, 53, 21, 60, 28, 63, 31, 58, 26, 57, 25, - 40, 8, 43, 11, 46, 14, 45, 13, 36, 4, 39, 7, 34, 2, 33, 1, - 0, 16, 32, 48, 3, 19, 35, 51, 6, 22, 38, 54, 5, 21, 37, 53, - 12, 28, 44, 60, 15, 31, 47, 63, 10, 26, 42, 58, 9, 25, 41, 57, - 24, 8, 56, 40, 27, 11, 59, 43, 30, 14, 62, 46, 29, 13, 61, 45, - 20, 4, 52, 36, 23, 7, 55, 39, 18, 2, 50, 34, 17, 1, 49, 33, - 0, 8, 16, 24, 32, 40, 48, 56, 3, 11, 19, 27, 35, 43, 51, 59, - 6, 14, 22, 30, 38, 46, 54, 62, 5, 13, 21, 29, 37, 45, 53, 61, - 12, 4, 28, 20, 44, 36, 60, 52, 15, 7, 31, 23, 47, 39, 63, 55, - 10, 2, 26, 18, 42, 34, 58, 50, 9, 1, 25, 17, 41, 33, 57, 49, - 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, - 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, - 6, 2, 14, 10, 22, 18, 30, 26, 38, 34, 46, 42, 54, 50, 62, 58, - 5, 1, 13, 9, 21, 17, 29, 25, 37, 33, 45, 41, 53, 49, 61, 57, - 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, - 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, - 3, 1, 7, 5, 11, 9, 15, 13, 19, 17, 23, 21, 27, 25, 31, 29, - 35, 33, 39, 37, 43, 41, 47, 45, 51, 49, 55, 53, 59, 57, 63, 61 -}; -/* -// SO array -static const int SO[qra_N-qra_K+1] = { - 14, 2, 4, 5, 9, 13, 10, 15, 11, 6, 1, 8, 2, 12, 9, 10, - 13, 7, 4, 11, 8, 6, 3, 14, 13, 5, 9, 1, 2, 12, 3, 10, - 15, 6, 7, 14, 8, 13, 12, 3, 10, 1, 11, 5, 8, 15, 9, 12, - 4, 7, 11 -}; - -// LOGWO array -static const int LOGWO[qra_N-qra_K+1] = { - 0, 14, 0, 0, 13, 37, 0, 27, 56, 62, 29, 0, 52, 34, 62, 4, - 3, 22, 25, 0, 22, 0, 20, 10, 0, 43, 53, 60, 0, 0, 0, 62, - 0, 5, 0, 61, 36, 31, 61, 59, 10, 0, 29, 39, 25, 18, 0, 14, - 11, 50, 17 -}; - -// repfact array -static const int repfact[qra_K] = { - 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3 -}; -*/ - -const qracode qra15_65_64_irr_e23 = { - qra_K, - qra_N, - qra_m, - qra_M, - qra_a, - qra_NC, - qra_V, - qra_C, - qra_NMSG, - qra_MAXVDEG, - qra_MAXCDEG, - QRATYPE_CRCPUNCTURED2, - qra_R, - CODE_NAME, - qra_acc_input_idx, - qra_acc_input_wlog, - qra_log, - qra_exp, - qra_msgw, - qra_vdeg, - qra_cdeg, - qra_v2cmidx, - qra_c2vmidx, - qra_pmat -}; -#undef qra_K -#undef qra_N -#undef qra_m -#undef qra_M -#undef qra_a -#undef qra_NC -#undef qra_V -#undef qra_C -#undef qra_NMSG -#undef qra_MAXVDEG -#undef qra_MAXCDEG -#undef qra_R -#undef CODE_NAME +// qra15_65_64_irr_e23.c +// Encoding/Decoding tables for Q-ary RA code (15,65) over GF(64) +// Code Name: qra15_65_64_irr_e23 +// (15,65) RA Code over GF(64) + +// (c) 2020 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy + +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#include "qra15_65_64_irr_e23.h" + +// File generated by npiwnarsavehc.m + +#define qra_K 15 // number of information symbols +#define qra_N 65 // codeword length in symbols +#define qra_m 6 // bits/symbol +#define qra_M 64 // Symbol alphabet cardinality +#define qra_a 1 // grouping factor +#define qra_NC 50 // number of check symbols (N-K) + +// Defines used by the message passing decoder -------- + +#define qra_V 65 // number of variables in the code graph (N) +#define qra_C 116 // number of factors in the code graph (N +(N-K)+1) +#define qra_NMSG 216 // number of msgs in the code graph +#define qra_MAXVDEG 5 // maximum variable degree +#define qra_MAXCDEG 3 // maximum factor degree +#define qra_R 0.23077f // code rate (K/N) +#define CODE_NAME "qra15_65_64_irr_e23" // code name + +// table of the systematic symbols indexes in the accumulator chain +static const int qra_acc_input_idx[qra_NC+1] = { + 13, 1, 3, 4, 8, 12, 9, 14, 10, 5, + 0, 7, 1, 11, 8, 9, 12, 6, 3, 10, + 7, 5, 2, 13, 12, 4, 8, 0, 1, 11, + 2, 9, 14, 5, 6, 13, 7, 12, 11, 2, + 9, 0, 10, 4, 7, 14, 8, 11, 3, 6, + 10 +}; + +// table of the systematic symbols weight logarithms over GF(M) +static const int qra_acc_input_wlog[qra_NC+1] = { + 0, 14, 0, 0, 13, 37, 0, 27, 56, 62, + 29, 0, 52, 34, 62, 4, 3, 22, 25, 0, + 22, 0, 20, 10, 0, 43, 53, 60, 0, 0, + 0, 62, 0, 5, 0, 61, 36, 31, 61, 59, + 10, 0, 29, 39, 25, 18, 0, 14, 11, 50, + 17 +}; + +// table of the logarithms of the elements of GF(M) (log(0) never used) +static const int qra_log[qra_M] = { + -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, + 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, + 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, + 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, + 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, + 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, + 20, 59, 57, 58 +}; + +// table of GF(M) elements given their logarithm +static const int qra_exp[qra_M-1] = { + 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, + 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, + 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, + 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, + 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, + 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, + 57, 49, 33 +}; + +// table of the messages weight logarithms over GF(M) +static const int qra_msgw[qra_NMSG] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 14, 0, 0, 13, + 37, 0, 27, 56, 62, 29, 0, 52, 34, 62, + 4, 3, 22, 25, 0, 22, 0, 20, 10, 0, + 43, 53, 60, 0, 0, 0, 62, 0, 5, 0, + 61, 36, 31, 61, 59, 10, 0, 29, 39, 25, + 18, 0, 14, 11, 50, 17, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; + +// table of the degrees of the variable nodes +static const int qra_vdeg[qra_V] = { + 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, + 5, 5, 5, 4, 4, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3 +}; + +// table of the degrees of the factor nodes +static const int qra_cdeg[qra_C] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 2 +}; + +// table (uncompressed) of the v->c message indexes (-1=unused entry) +static const int qra_v2cmidx[qra_V*qra_MAXVDEG] = { + 0, 75, 92, 106, -1, + 1, 66, 77, 93, -1, + 2, 87, 95, 104, -1, + 3, 67, 83, 113, -1, + 4, 68, 90, 108, -1, + 5, 74, 86, 98, -1, + 6, 82, 99, 114, -1, + 7, 76, 85, 101, 109, + 8, 69, 79, 91, 111, + 9, 71, 80, 96, 105, + 10, 73, 84, 107, 115, + 11, 78, 94, 103, 112, + 12, 70, 81, 89, 102, + 13, 65, 88, 100, -1, + 14, 72, 97, 110, -1, + 15, 116, 117, -1, -1, + 16, 118, 119, -1, -1, + 17, 120, 121, -1, -1, + 18, 122, 123, -1, -1, + 19, 124, 125, -1, -1, + 20, 126, 127, -1, -1, + 21, 128, 129, -1, -1, + 22, 130, 131, -1, -1, + 23, 132, 133, -1, -1, + 24, 134, 135, -1, -1, + 25, 136, 137, -1, -1, + 26, 138, 139, -1, -1, + 27, 140, 141, -1, -1, + 28, 142, 143, -1, -1, + 29, 144, 145, -1, -1, + 30, 146, 147, -1, -1, + 31, 148, 149, -1, -1, + 32, 150, 151, -1, -1, + 33, 152, 153, -1, -1, + 34, 154, 155, -1, -1, + 35, 156, 157, -1, -1, + 36, 158, 159, -1, -1, + 37, 160, 161, -1, -1, + 38, 162, 163, -1, -1, + 39, 164, 165, -1, -1, + 40, 166, 167, -1, -1, + 41, 168, 169, -1, -1, + 42, 170, 171, -1, -1, + 43, 172, 173, -1, -1, + 44, 174, 175, -1, -1, + 45, 176, 177, -1, -1, + 46, 178, 179, -1, -1, + 47, 180, 181, -1, -1, + 48, 182, 183, -1, -1, + 49, 184, 185, -1, -1, + 50, 186, 187, -1, -1, + 51, 188, 189, -1, -1, + 52, 190, 191, -1, -1, + 53, 192, 193, -1, -1, + 54, 194, 195, -1, -1, + 55, 196, 197, -1, -1, + 56, 198, 199, -1, -1, + 57, 200, 201, -1, -1, + 58, 202, 203, -1, -1, + 59, 204, 205, -1, -1, + 60, 206, 207, -1, -1, + 61, 208, 209, -1, -1, + 62, 210, 211, -1, -1, + 63, 212, 213, -1, -1, + 64, 214, 215, -1, -1 +}; + +// table (uncompressed) of the c->v message indexes (-1=unused entry) +static const int qra_c2vmidx[qra_C*qra_MAXCDEG] = { + 0, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1, + 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1, + 8, -1, -1, 9, -1, -1, 10, -1, -1, 11, -1, -1, + 12, -1, -1, 13, -1, -1, 14, -1, -1, 15, -1, -1, + 16, -1, -1, 17, -1, -1, 18, -1, -1, 19, -1, -1, + 20, -1, -1, 21, -1, -1, 22, -1, -1, 23, -1, -1, + 24, -1, -1, 25, -1, -1, 26, -1, -1, 27, -1, -1, + 28, -1, -1, 29, -1, -1, 30, -1, -1, 31, -1, -1, + 32, -1, -1, 33, -1, -1, 34, -1, -1, 35, -1, -1, + 36, -1, -1, 37, -1, -1, 38, -1, -1, 39, -1, -1, + 40, -1, -1, 41, -1, -1, 42, -1, -1, 43, -1, -1, + 44, -1, -1, 45, -1, -1, 46, -1, -1, 47, -1, -1, + 48, -1, -1, 49, -1, -1, 50, -1, -1, 51, -1, -1, + 52, -1, -1, 53, -1, -1, 54, -1, -1, 55, -1, -1, + 56, -1, -1, 57, -1, -1, 58, -1, -1, 59, -1, -1, + 60, -1, -1, 61, -1, -1, 62, -1, -1, 63, -1, -1, + 64, -1, -1, 65, 116, -1, 66, 117, 118, 67, 119, 120, + 68, 121, 122, 69, 123, 124, 70, 125, 126, 71, 127, 128, + 72, 129, 130, 73, 131, 132, 74, 133, 134, 75, 135, 136, + 76, 137, 138, 77, 139, 140, 78, 141, 142, 79, 143, 144, + 80, 145, 146, 81, 147, 148, 82, 149, 150, 83, 151, 152, + 84, 153, 154, 85, 155, 156, 86, 157, 158, 87, 159, 160, + 88, 161, 162, 89, 163, 164, 90, 165, 166, 91, 167, 168, + 92, 169, 170, 93, 171, 172, 94, 173, 174, 95, 175, 176, + 96, 177, 178, 97, 179, 180, 98, 181, 182, 99, 183, 184, +100, 185, 186, 101, 187, 188, 102, 189, 190, 103, 191, 192, +104, 193, 194, 105, 195, 196, 106, 197, 198, 107, 199, 200, +108, 201, 202, 109, 203, 204, 110, 205, 206, 111, 207, 208, +112, 209, 210, 113, 211, 212, 114, 213, 214, 115, 215, -1 +}; + +// permutation matrix to compute Prob(x*alfa^logw) +static const int qra_pmat[qra_M*qra_M] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 33, 1, 32, 2, 35, 3, 34, 4, 37, 5, 36, 6, 39, 7, 38, + 8, 41, 9, 40, 10, 43, 11, 42, 12, 45, 13, 44, 14, 47, 15, 46, + 16, 49, 17, 48, 18, 51, 19, 50, 20, 53, 21, 52, 22, 55, 23, 54, + 24, 57, 25, 56, 26, 59, 27, 58, 28, 61, 29, 60, 30, 63, 31, 62, + 0, 49, 33, 16, 1, 48, 32, 17, 2, 51, 35, 18, 3, 50, 34, 19, + 4, 53, 37, 20, 5, 52, 36, 21, 6, 55, 39, 22, 7, 54, 38, 23, + 8, 57, 41, 24, 9, 56, 40, 25, 10, 59, 43, 26, 11, 58, 42, 27, + 12, 61, 45, 28, 13, 60, 44, 29, 14, 63, 47, 30, 15, 62, 46, 31, + 0, 57, 49, 8, 33, 24, 16, 41, 1, 56, 48, 9, 32, 25, 17, 40, + 2, 59, 51, 10, 35, 26, 18, 43, 3, 58, 50, 11, 34, 27, 19, 42, + 4, 61, 53, 12, 37, 28, 20, 45, 5, 60, 52, 13, 36, 29, 21, 44, + 6, 63, 55, 14, 39, 30, 22, 47, 7, 62, 54, 15, 38, 31, 23, 46, + 0, 61, 57, 4, 49, 12, 8, 53, 33, 28, 24, 37, 16, 45, 41, 20, + 1, 60, 56, 5, 48, 13, 9, 52, 32, 29, 25, 36, 17, 44, 40, 21, + 2, 63, 59, 6, 51, 14, 10, 55, 35, 30, 26, 39, 18, 47, 43, 22, + 3, 62, 58, 7, 50, 15, 11, 54, 34, 31, 27, 38, 19, 46, 42, 23, + 0, 63, 61, 2, 57, 6, 4, 59, 49, 14, 12, 51, 8, 55, 53, 10, + 33, 30, 28, 35, 24, 39, 37, 26, 16, 47, 45, 18, 41, 22, 20, 43, + 1, 62, 60, 3, 56, 7, 5, 58, 48, 15, 13, 50, 9, 54, 52, 11, + 32, 31, 29, 34, 25, 38, 36, 27, 17, 46, 44, 19, 40, 23, 21, 42, + 0, 62, 63, 1, 61, 3, 2, 60, 57, 7, 6, 56, 4, 58, 59, 5, + 49, 15, 14, 48, 12, 50, 51, 13, 8, 54, 55, 9, 53, 11, 10, 52, + 33, 31, 30, 32, 28, 34, 35, 29, 24, 38, 39, 25, 37, 27, 26, 36, + 16, 46, 47, 17, 45, 19, 18, 44, 41, 23, 22, 40, 20, 42, 43, 21, + 0, 31, 62, 33, 63, 32, 1, 30, 61, 34, 3, 28, 2, 29, 60, 35, + 57, 38, 7, 24, 6, 25, 56, 39, 4, 27, 58, 37, 59, 36, 5, 26, + 49, 46, 15, 16, 14, 17, 48, 47, 12, 19, 50, 45, 51, 44, 13, 18, + 8, 23, 54, 41, 55, 40, 9, 22, 53, 42, 11, 20, 10, 21, 52, 43, + 0, 46, 31, 49, 62, 16, 33, 15, 63, 17, 32, 14, 1, 47, 30, 48, + 61, 19, 34, 12, 3, 45, 28, 50, 2, 44, 29, 51, 60, 18, 35, 13, + 57, 23, 38, 8, 7, 41, 24, 54, 6, 40, 25, 55, 56, 22, 39, 9, + 4, 42, 27, 53, 58, 20, 37, 11, 59, 21, 36, 10, 5, 43, 26, 52, + 0, 23, 46, 57, 31, 8, 49, 38, 62, 41, 16, 7, 33, 54, 15, 24, + 63, 40, 17, 6, 32, 55, 14, 25, 1, 22, 47, 56, 30, 9, 48, 39, + 61, 42, 19, 4, 34, 53, 12, 27, 3, 20, 45, 58, 28, 11, 50, 37, + 2, 21, 44, 59, 29, 10, 51, 36, 60, 43, 18, 5, 35, 52, 13, 26, + 0, 42, 23, 61, 46, 4, 57, 19, 31, 53, 8, 34, 49, 27, 38, 12, + 62, 20, 41, 3, 16, 58, 7, 45, 33, 11, 54, 28, 15, 37, 24, 50, + 63, 21, 40, 2, 17, 59, 6, 44, 32, 10, 55, 29, 14, 36, 25, 51, + 1, 43, 22, 60, 47, 5, 56, 18, 30, 52, 9, 35, 48, 26, 39, 13, + 0, 21, 42, 63, 23, 2, 61, 40, 46, 59, 4, 17, 57, 44, 19, 6, + 31, 10, 53, 32, 8, 29, 34, 55, 49, 36, 27, 14, 38, 51, 12, 25, + 62, 43, 20, 1, 41, 60, 3, 22, 16, 5, 58, 47, 7, 18, 45, 56, + 33, 52, 11, 30, 54, 35, 28, 9, 15, 26, 37, 48, 24, 13, 50, 39, + 0, 43, 21, 62, 42, 1, 63, 20, 23, 60, 2, 41, 61, 22, 40, 3, + 46, 5, 59, 16, 4, 47, 17, 58, 57, 18, 44, 7, 19, 56, 6, 45, + 31, 52, 10, 33, 53, 30, 32, 11, 8, 35, 29, 54, 34, 9, 55, 28, + 49, 26, 36, 15, 27, 48, 14, 37, 38, 13, 51, 24, 12, 39, 25, 50, + 0, 52, 43, 31, 21, 33, 62, 10, 42, 30, 1, 53, 63, 11, 20, 32, + 23, 35, 60, 8, 2, 54, 41, 29, 61, 9, 22, 34, 40, 28, 3, 55, + 46, 26, 5, 49, 59, 15, 16, 36, 4, 48, 47, 27, 17, 37, 58, 14, + 57, 13, 18, 38, 44, 24, 7, 51, 19, 39, 56, 12, 6, 50, 45, 25, + 0, 26, 52, 46, 43, 49, 31, 5, 21, 15, 33, 59, 62, 36, 10, 16, + 42, 48, 30, 4, 1, 27, 53, 47, 63, 37, 11, 17, 20, 14, 32, 58, + 23, 13, 35, 57, 60, 38, 8, 18, 2, 24, 54, 44, 41, 51, 29, 7, + 61, 39, 9, 19, 22, 12, 34, 56, 40, 50, 28, 6, 3, 25, 55, 45, + 0, 13, 26, 23, 52, 57, 46, 35, 43, 38, 49, 60, 31, 18, 5, 8, + 21, 24, 15, 2, 33, 44, 59, 54, 62, 51, 36, 41, 10, 7, 16, 29, + 42, 39, 48, 61, 30, 19, 4, 9, 1, 12, 27, 22, 53, 56, 47, 34, + 63, 50, 37, 40, 11, 6, 17, 28, 20, 25, 14, 3, 32, 45, 58, 55, + 0, 39, 13, 42, 26, 61, 23, 48, 52, 19, 57, 30, 46, 9, 35, 4, + 43, 12, 38, 1, 49, 22, 60, 27, 31, 56, 18, 53, 5, 34, 8, 47, + 21, 50, 24, 63, 15, 40, 2, 37, 33, 6, 44, 11, 59, 28, 54, 17, + 62, 25, 51, 20, 36, 3, 41, 14, 10, 45, 7, 32, 16, 55, 29, 58, + 0, 50, 39, 21, 13, 63, 42, 24, 26, 40, 61, 15, 23, 37, 48, 2, + 52, 6, 19, 33, 57, 11, 30, 44, 46, 28, 9, 59, 35, 17, 4, 54, + 43, 25, 12, 62, 38, 20, 1, 51, 49, 3, 22, 36, 60, 14, 27, 41, + 31, 45, 56, 10, 18, 32, 53, 7, 5, 55, 34, 16, 8, 58, 47, 29, + 0, 25, 50, 43, 39, 62, 21, 12, 13, 20, 63, 38, 42, 51, 24, 1, + 26, 3, 40, 49, 61, 36, 15, 22, 23, 14, 37, 60, 48, 41, 2, 27, + 52, 45, 6, 31, 19, 10, 33, 56, 57, 32, 11, 18, 30, 7, 44, 53, + 46, 55, 28, 5, 9, 16, 59, 34, 35, 58, 17, 8, 4, 29, 54, 47, + 0, 45, 25, 52, 50, 31, 43, 6, 39, 10, 62, 19, 21, 56, 12, 33, + 13, 32, 20, 57, 63, 18, 38, 11, 42, 7, 51, 30, 24, 53, 1, 44, + 26, 55, 3, 46, 40, 5, 49, 28, 61, 16, 36, 9, 15, 34, 22, 59, + 23, 58, 14, 35, 37, 8, 60, 17, 48, 29, 41, 4, 2, 47, 27, 54, + 0, 55, 45, 26, 25, 46, 52, 3, 50, 5, 31, 40, 43, 28, 6, 49, + 39, 16, 10, 61, 62, 9, 19, 36, 21, 34, 56, 15, 12, 59, 33, 22, + 13, 58, 32, 23, 20, 35, 57, 14, 63, 8, 18, 37, 38, 17, 11, 60, + 42, 29, 7, 48, 51, 4, 30, 41, 24, 47, 53, 2, 1, 54, 44, 27, + 0, 58, 55, 13, 45, 23, 26, 32, 25, 35, 46, 20, 52, 14, 3, 57, + 50, 8, 5, 63, 31, 37, 40, 18, 43, 17, 28, 38, 6, 60, 49, 11, + 39, 29, 16, 42, 10, 48, 61, 7, 62, 4, 9, 51, 19, 41, 36, 30, + 21, 47, 34, 24, 56, 2, 15, 53, 12, 54, 59, 1, 33, 27, 22, 44, + 0, 29, 58, 39, 55, 42, 13, 16, 45, 48, 23, 10, 26, 7, 32, 61, + 25, 4, 35, 62, 46, 51, 20, 9, 52, 41, 14, 19, 3, 30, 57, 36, + 50, 47, 8, 21, 5, 24, 63, 34, 31, 2, 37, 56, 40, 53, 18, 15, + 43, 54, 17, 12, 28, 1, 38, 59, 6, 27, 60, 33, 49, 44, 11, 22, + 0, 47, 29, 50, 58, 21, 39, 8, 55, 24, 42, 5, 13, 34, 16, 63, + 45, 2, 48, 31, 23, 56, 10, 37, 26, 53, 7, 40, 32, 15, 61, 18, + 25, 54, 4, 43, 35, 12, 62, 17, 46, 1, 51, 28, 20, 59, 9, 38, + 52, 27, 41, 6, 14, 33, 19, 60, 3, 44, 30, 49, 57, 22, 36, 11, + 0, 54, 47, 25, 29, 43, 50, 4, 58, 12, 21, 35, 39, 17, 8, 62, + 55, 1, 24, 46, 42, 28, 5, 51, 13, 59, 34, 20, 16, 38, 63, 9, + 45, 27, 2, 52, 48, 6, 31, 41, 23, 33, 56, 14, 10, 60, 37, 19, + 26, 44, 53, 3, 7, 49, 40, 30, 32, 22, 15, 57, 61, 11, 18, 36, + 0, 27, 54, 45, 47, 52, 25, 2, 29, 6, 43, 48, 50, 41, 4, 31, + 58, 33, 12, 23, 21, 14, 35, 56, 39, 60, 17, 10, 8, 19, 62, 37, + 55, 44, 1, 26, 24, 3, 46, 53, 42, 49, 28, 7, 5, 30, 51, 40, + 13, 22, 59, 32, 34, 57, 20, 15, 16, 11, 38, 61, 63, 36, 9, 18, + 0, 44, 27, 55, 54, 26, 45, 1, 47, 3, 52, 24, 25, 53, 2, 46, + 29, 49, 6, 42, 43, 7, 48, 28, 50, 30, 41, 5, 4, 40, 31, 51, + 58, 22, 33, 13, 12, 32, 23, 59, 21, 57, 14, 34, 35, 15, 56, 20, + 39, 11, 60, 16, 17, 61, 10, 38, 8, 36, 19, 63, 62, 18, 37, 9, + 0, 22, 44, 58, 27, 13, 55, 33, 54, 32, 26, 12, 45, 59, 1, 23, + 47, 57, 3, 21, 52, 34, 24, 14, 25, 15, 53, 35, 2, 20, 46, 56, + 29, 11, 49, 39, 6, 16, 42, 60, 43, 61, 7, 17, 48, 38, 28, 10, + 50, 36, 30, 8, 41, 63, 5, 19, 4, 18, 40, 62, 31, 9, 51, 37, + 0, 11, 22, 29, 44, 39, 58, 49, 27, 16, 13, 6, 55, 60, 33, 42, + 54, 61, 32, 43, 26, 17, 12, 7, 45, 38, 59, 48, 1, 10, 23, 28, + 47, 36, 57, 50, 3, 8, 21, 30, 52, 63, 34, 41, 24, 19, 14, 5, + 25, 18, 15, 4, 53, 62, 35, 40, 2, 9, 20, 31, 46, 37, 56, 51, + 0, 36, 11, 47, 22, 50, 29, 57, 44, 8, 39, 3, 58, 30, 49, 21, + 27, 63, 16, 52, 13, 41, 6, 34, 55, 19, 60, 24, 33, 5, 42, 14, + 54, 18, 61, 25, 32, 4, 43, 15, 26, 62, 17, 53, 12, 40, 7, 35, + 45, 9, 38, 2, 59, 31, 48, 20, 1, 37, 10, 46, 23, 51, 28, 56, + 0, 18, 36, 54, 11, 25, 47, 61, 22, 4, 50, 32, 29, 15, 57, 43, + 44, 62, 8, 26, 39, 53, 3, 17, 58, 40, 30, 12, 49, 35, 21, 7, + 27, 9, 63, 45, 16, 2, 52, 38, 13, 31, 41, 59, 6, 20, 34, 48, + 55, 37, 19, 1, 60, 46, 24, 10, 33, 51, 5, 23, 42, 56, 14, 28, + 0, 9, 18, 27, 36, 45, 54, 63, 11, 2, 25, 16, 47, 38, 61, 52, + 22, 31, 4, 13, 50, 59, 32, 41, 29, 20, 15, 6, 57, 48, 43, 34, + 44, 37, 62, 55, 8, 1, 26, 19, 39, 46, 53, 60, 3, 10, 17, 24, + 58, 51, 40, 33, 30, 23, 12, 5, 49, 56, 35, 42, 21, 28, 7, 14, + 0, 37, 9, 44, 18, 55, 27, 62, 36, 1, 45, 8, 54, 19, 63, 26, + 11, 46, 2, 39, 25, 60, 16, 53, 47, 10, 38, 3, 61, 24, 52, 17, + 22, 51, 31, 58, 4, 33, 13, 40, 50, 23, 59, 30, 32, 5, 41, 12, + 29, 56, 20, 49, 15, 42, 6, 35, 57, 28, 48, 21, 43, 14, 34, 7, + 0, 51, 37, 22, 9, 58, 44, 31, 18, 33, 55, 4, 27, 40, 62, 13, + 36, 23, 1, 50, 45, 30, 8, 59, 54, 5, 19, 32, 63, 12, 26, 41, + 11, 56, 46, 29, 2, 49, 39, 20, 25, 42, 60, 15, 16, 35, 53, 6, + 47, 28, 10, 57, 38, 21, 3, 48, 61, 14, 24, 43, 52, 7, 17, 34, + 0, 56, 51, 11, 37, 29, 22, 46, 9, 49, 58, 2, 44, 20, 31, 39, + 18, 42, 33, 25, 55, 15, 4, 60, 27, 35, 40, 16, 62, 6, 13, 53, + 36, 28, 23, 47, 1, 57, 50, 10, 45, 21, 30, 38, 8, 48, 59, 3, + 54, 14, 5, 61, 19, 43, 32, 24, 63, 7, 12, 52, 26, 34, 41, 17, + 0, 28, 56, 36, 51, 47, 11, 23, 37, 57, 29, 1, 22, 10, 46, 50, + 9, 21, 49, 45, 58, 38, 2, 30, 44, 48, 20, 8, 31, 3, 39, 59, + 18, 14, 42, 54, 33, 61, 25, 5, 55, 43, 15, 19, 4, 24, 60, 32, + 27, 7, 35, 63, 40, 52, 16, 12, 62, 34, 6, 26, 13, 17, 53, 41, + 0, 14, 28, 18, 56, 54, 36, 42, 51, 61, 47, 33, 11, 5, 23, 25, + 37, 43, 57, 55, 29, 19, 1, 15, 22, 24, 10, 4, 46, 32, 50, 60, + 9, 7, 21, 27, 49, 63, 45, 35, 58, 52, 38, 40, 2, 12, 30, 16, + 44, 34, 48, 62, 20, 26, 8, 6, 31, 17, 3, 13, 39, 41, 59, 53, + 0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45, + 51, 52, 61, 58, 47, 40, 33, 38, 11, 12, 5, 2, 23, 16, 25, 30, + 37, 34, 43, 44, 57, 62, 55, 48, 29, 26, 19, 20, 1, 6, 15, 8, + 22, 17, 24, 31, 10, 13, 4, 3, 46, 41, 32, 39, 50, 53, 60, 59, + 0, 34, 7, 37, 14, 44, 9, 43, 28, 62, 27, 57, 18, 48, 21, 55, + 56, 26, 63, 29, 54, 20, 49, 19, 36, 6, 35, 1, 42, 8, 45, 15, + 51, 17, 52, 22, 61, 31, 58, 24, 47, 13, 40, 10, 33, 3, 38, 4, + 11, 41, 12, 46, 5, 39, 2, 32, 23, 53, 16, 50, 25, 59, 30, 60, + 0, 17, 34, 51, 7, 22, 37, 52, 14, 31, 44, 61, 9, 24, 43, 58, + 28, 13, 62, 47, 27, 10, 57, 40, 18, 3, 48, 33, 21, 4, 55, 38, + 56, 41, 26, 11, 63, 46, 29, 12, 54, 39, 20, 5, 49, 32, 19, 2, + 36, 53, 6, 23, 35, 50, 1, 16, 42, 59, 8, 25, 45, 60, 15, 30, + 0, 41, 17, 56, 34, 11, 51, 26, 7, 46, 22, 63, 37, 12, 52, 29, + 14, 39, 31, 54, 44, 5, 61, 20, 9, 32, 24, 49, 43, 2, 58, 19, + 28, 53, 13, 36, 62, 23, 47, 6, 27, 50, 10, 35, 57, 16, 40, 1, + 18, 59, 3, 42, 48, 25, 33, 8, 21, 60, 4, 45, 55, 30, 38, 15, + 0, 53, 41, 28, 17, 36, 56, 13, 34, 23, 11, 62, 51, 6, 26, 47, + 7, 50, 46, 27, 22, 35, 63, 10, 37, 16, 12, 57, 52, 1, 29, 40, + 14, 59, 39, 18, 31, 42, 54, 3, 44, 25, 5, 48, 61, 8, 20, 33, + 9, 60, 32, 21, 24, 45, 49, 4, 43, 30, 2, 55, 58, 15, 19, 38, + 0, 59, 53, 14, 41, 18, 28, 39, 17, 42, 36, 31, 56, 3, 13, 54, + 34, 25, 23, 44, 11, 48, 62, 5, 51, 8, 6, 61, 26, 33, 47, 20, + 7, 60, 50, 9, 46, 21, 27, 32, 22, 45, 35, 24, 63, 4, 10, 49, + 37, 30, 16, 43, 12, 55, 57, 2, 52, 15, 1, 58, 29, 38, 40, 19, + 0, 60, 59, 7, 53, 9, 14, 50, 41, 21, 18, 46, 28, 32, 39, 27, + 17, 45, 42, 22, 36, 24, 31, 35, 56, 4, 3, 63, 13, 49, 54, 10, + 34, 30, 25, 37, 23, 43, 44, 16, 11, 55, 48, 12, 62, 2, 5, 57, + 51, 15, 8, 52, 6, 58, 61, 1, 26, 38, 33, 29, 47, 19, 20, 40, + 0, 30, 60, 34, 59, 37, 7, 25, 53, 43, 9, 23, 14, 16, 50, 44, + 41, 55, 21, 11, 18, 12, 46, 48, 28, 2, 32, 62, 39, 57, 27, 5, + 17, 15, 45, 51, 42, 52, 22, 8, 36, 58, 24, 6, 31, 1, 35, 61, + 56, 38, 4, 26, 3, 29, 63, 33, 13, 19, 49, 47, 54, 40, 10, 20, + 0, 15, 30, 17, 60, 51, 34, 45, 59, 52, 37, 42, 7, 8, 25, 22, + 53, 58, 43, 36, 9, 6, 23, 24, 14, 1, 16, 31, 50, 61, 44, 35, + 41, 38, 55, 56, 21, 26, 11, 4, 18, 29, 12, 3, 46, 33, 48, 63, + 28, 19, 2, 13, 32, 47, 62, 49, 39, 40, 57, 54, 27, 20, 5, 10, + 0, 38, 15, 41, 30, 56, 17, 55, 60, 26, 51, 21, 34, 4, 45, 11, + 59, 29, 52, 18, 37, 3, 42, 12, 7, 33, 8, 46, 25, 63, 22, 48, + 53, 19, 58, 28, 43, 13, 36, 2, 9, 47, 6, 32, 23, 49, 24, 62, + 14, 40, 1, 39, 16, 54, 31, 57, 50, 20, 61, 27, 44, 10, 35, 5, + 0, 19, 38, 53, 15, 28, 41, 58, 30, 13, 56, 43, 17, 2, 55, 36, + 60, 47, 26, 9, 51, 32, 21, 6, 34, 49, 4, 23, 45, 62, 11, 24, + 59, 40, 29, 14, 52, 39, 18, 1, 37, 54, 3, 16, 42, 57, 12, 31, + 7, 20, 33, 50, 8, 27, 46, 61, 25, 10, 63, 44, 22, 5, 48, 35, + 0, 40, 19, 59, 38, 14, 53, 29, 15, 39, 28, 52, 41, 1, 58, 18, + 30, 54, 13, 37, 56, 16, 43, 3, 17, 57, 2, 42, 55, 31, 36, 12, + 60, 20, 47, 7, 26, 50, 9, 33, 51, 27, 32, 8, 21, 61, 6, 46, + 34, 10, 49, 25, 4, 44, 23, 63, 45, 5, 62, 22, 11, 35, 24, 48, + 0, 20, 40, 60, 19, 7, 59, 47, 38, 50, 14, 26, 53, 33, 29, 9, + 15, 27, 39, 51, 28, 8, 52, 32, 41, 61, 1, 21, 58, 46, 18, 6, + 30, 10, 54, 34, 13, 25, 37, 49, 56, 44, 16, 4, 43, 63, 3, 23, + 17, 5, 57, 45, 2, 22, 42, 62, 55, 35, 31, 11, 36, 48, 12, 24, + 0, 10, 20, 30, 40, 34, 60, 54, 19, 25, 7, 13, 59, 49, 47, 37, + 38, 44, 50, 56, 14, 4, 26, 16, 53, 63, 33, 43, 29, 23, 9, 3, + 15, 5, 27, 17, 39, 45, 51, 57, 28, 22, 8, 2, 52, 62, 32, 42, + 41, 35, 61, 55, 1, 11, 21, 31, 58, 48, 46, 36, 18, 24, 6, 12, + 0, 5, 10, 15, 20, 17, 30, 27, 40, 45, 34, 39, 60, 57, 54, 51, + 19, 22, 25, 28, 7, 2, 13, 8, 59, 62, 49, 52, 47, 42, 37, 32, + 38, 35, 44, 41, 50, 55, 56, 61, 14, 11, 4, 1, 26, 31, 16, 21, + 53, 48, 63, 58, 33, 36, 43, 46, 29, 24, 23, 18, 9, 12, 3, 6, + 0, 35, 5, 38, 10, 41, 15, 44, 20, 55, 17, 50, 30, 61, 27, 56, + 40, 11, 45, 14, 34, 1, 39, 4, 60, 31, 57, 26, 54, 21, 51, 16, + 19, 48, 22, 53, 25, 58, 28, 63, 7, 36, 2, 33, 13, 46, 8, 43, + 59, 24, 62, 29, 49, 18, 52, 23, 47, 12, 42, 9, 37, 6, 32, 3, + 0, 48, 35, 19, 5, 53, 38, 22, 10, 58, 41, 25, 15, 63, 44, 28, + 20, 36, 55, 7, 17, 33, 50, 2, 30, 46, 61, 13, 27, 43, 56, 8, + 40, 24, 11, 59, 45, 29, 14, 62, 34, 18, 1, 49, 39, 23, 4, 52, + 60, 12, 31, 47, 57, 9, 26, 42, 54, 6, 21, 37, 51, 3, 16, 32, + 0, 24, 48, 40, 35, 59, 19, 11, 5, 29, 53, 45, 38, 62, 22, 14, + 10, 18, 58, 34, 41, 49, 25, 1, 15, 23, 63, 39, 44, 52, 28, 4, + 20, 12, 36, 60, 55, 47, 7, 31, 17, 9, 33, 57, 50, 42, 2, 26, + 30, 6, 46, 54, 61, 37, 13, 21, 27, 3, 43, 51, 56, 32, 8, 16, + 0, 12, 24, 20, 48, 60, 40, 36, 35, 47, 59, 55, 19, 31, 11, 7, + 5, 9, 29, 17, 53, 57, 45, 33, 38, 42, 62, 50, 22, 26, 14, 2, + 10, 6, 18, 30, 58, 54, 34, 46, 41, 37, 49, 61, 25, 21, 1, 13, + 15, 3, 23, 27, 63, 51, 39, 43, 44, 32, 52, 56, 28, 16, 4, 8, + 0, 6, 12, 10, 24, 30, 20, 18, 48, 54, 60, 58, 40, 46, 36, 34, + 35, 37, 47, 41, 59, 61, 55, 49, 19, 21, 31, 25, 11, 13, 7, 1, + 5, 3, 9, 15, 29, 27, 17, 23, 53, 51, 57, 63, 45, 43, 33, 39, + 38, 32, 42, 44, 62, 56, 50, 52, 22, 16, 26, 28, 14, 8, 2, 4, + 0, 3, 6, 5, 12, 15, 10, 9, 24, 27, 30, 29, 20, 23, 18, 17, + 48, 51, 54, 53, 60, 63, 58, 57, 40, 43, 46, 45, 36, 39, 34, 33, + 35, 32, 37, 38, 47, 44, 41, 42, 59, 56, 61, 62, 55, 52, 49, 50, + 19, 16, 21, 22, 31, 28, 25, 26, 11, 8, 13, 14, 7, 4, 1, 2, + 0, 32, 3, 35, 6, 38, 5, 37, 12, 44, 15, 47, 10, 42, 9, 41, + 24, 56, 27, 59, 30, 62, 29, 61, 20, 52, 23, 55, 18, 50, 17, 49, + 48, 16, 51, 19, 54, 22, 53, 21, 60, 28, 63, 31, 58, 26, 57, 25, + 40, 8, 43, 11, 46, 14, 45, 13, 36, 4, 39, 7, 34, 2, 33, 1, + 0, 16, 32, 48, 3, 19, 35, 51, 6, 22, 38, 54, 5, 21, 37, 53, + 12, 28, 44, 60, 15, 31, 47, 63, 10, 26, 42, 58, 9, 25, 41, 57, + 24, 8, 56, 40, 27, 11, 59, 43, 30, 14, 62, 46, 29, 13, 61, 45, + 20, 4, 52, 36, 23, 7, 55, 39, 18, 2, 50, 34, 17, 1, 49, 33, + 0, 8, 16, 24, 32, 40, 48, 56, 3, 11, 19, 27, 35, 43, 51, 59, + 6, 14, 22, 30, 38, 46, 54, 62, 5, 13, 21, 29, 37, 45, 53, 61, + 12, 4, 28, 20, 44, 36, 60, 52, 15, 7, 31, 23, 47, 39, 63, 55, + 10, 2, 26, 18, 42, 34, 58, 50, 9, 1, 25, 17, 41, 33, 57, 49, + 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, + 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, + 6, 2, 14, 10, 22, 18, 30, 26, 38, 34, 46, 42, 54, 50, 62, 58, + 5, 1, 13, 9, 21, 17, 29, 25, 37, 33, 45, 41, 53, 49, 61, 57, + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, + 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, + 3, 1, 7, 5, 11, 9, 15, 13, 19, 17, 23, 21, 27, 25, 31, 29, + 35, 33, 39, 37, 43, 41, 47, 45, 51, 49, 55, 53, 59, 57, 63, 61 +}; +/* +// SO array +static const int SO[qra_N-qra_K+1] = { + 14, 2, 4, 5, 9, 13, 10, 15, 11, 6, 1, 8, 2, 12, 9, 10, + 13, 7, 4, 11, 8, 6, 3, 14, 13, 5, 9, 1, 2, 12, 3, 10, + 15, 6, 7, 14, 8, 13, 12, 3, 10, 1, 11, 5, 8, 15, 9, 12, + 4, 7, 11 +}; + +// LOGWO array +static const int LOGWO[qra_N-qra_K+1] = { + 0, 14, 0, 0, 13, 37, 0, 27, 56, 62, 29, 0, 52, 34, 62, 4, + 3, 22, 25, 0, 22, 0, 20, 10, 0, 43, 53, 60, 0, 0, 0, 62, + 0, 5, 0, 61, 36, 31, 61, 59, 10, 0, 29, 39, 25, 18, 0, 14, + 11, 50, 17 +}; + +// repfact array +static const int repfact[qra_K] = { + 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3 +}; +*/ + +const qracode qra15_65_64_irr_e23 = { + qra_K, + qra_N, + qra_m, + qra_M, + qra_a, + qra_NC, + qra_V, + qra_C, + qra_NMSG, + qra_MAXVDEG, + qra_MAXCDEG, + QRATYPE_CRCPUNCTURED2, + qra_R, + CODE_NAME, + qra_acc_input_idx, + qra_acc_input_wlog, + qra_log, + qra_exp, + qra_msgw, + qra_vdeg, + qra_cdeg, + qra_v2cmidx, + qra_c2vmidx, + qra_pmat +}; +#undef qra_K +#undef qra_N +#undef qra_m +#undef qra_M +#undef qra_a +#undef qra_NC +#undef qra_V +#undef qra_C +#undef qra_NMSG +#undef qra_MAXVDEG +#undef qra_MAXCDEG +#undef qra_R +#undef CODE_NAME diff --git a/lib/qra/q65/qra15_65_64_irr_e23.h b/lib/qra/q65/qra15_65_64_irr_e23.h index 79dd5d2a..4e4f601c 100755 --- a/lib/qra/q65/qra15_65_64_irr_e23.h +++ b/lib/qra/q65/qra15_65_64_irr_e23.h @@ -1,41 +1,41 @@ -// qra15_65_64_irr_e23.h -// Code tables and defines for Q-ary RA code (15,65) over GF(64) -// Code Name: qra15_65_64_irr_e23 -// (15,65) RA Code over GF(64) - -// (c) 2020 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy - -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#ifndef _qra15_65_64_irr_e23_h -#define _qra15_65_64_irr_e23_h - -// File generated by npiwnarsavehc.m - -#include "qracodes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern const qracode qra15_65_64_irr_e23; - -#ifdef __cplusplus -} -#endif - -#endif // _qra15_65_64_irr_e23_h +// qra15_65_64_irr_e23.h +// Code tables and defines for Q-ary RA code (15,65) over GF(64) +// Code Name: qra15_65_64_irr_e23 +// (15,65) RA Code over GF(64) + +// (c) 2020 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy + +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#ifndef _qra15_65_64_irr_e23_h +#define _qra15_65_64_irr_e23_h + +// File generated by npiwnarsavehc.m + +#include "qracodes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const qracode qra15_65_64_irr_e23; + +#ifdef __cplusplus +} +#endif + +#endif // _qra15_65_64_irr_e23_h diff --git a/lib/qra/q65/qracodes.c b/lib/qra/q65/qracodes.c index 06576c5e..748a9c9c 100755 --- a/lib/qra/q65/qracodes.c +++ b/lib/qra/q65/qracodes.c @@ -1,474 +1,474 @@ -// qracodes.c -// Q-ary RA codes encoding/decoding functions -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#include -#include - -#include "npfwht.h" -#include "pdmath.h" - -#include "qracodes.h" - -int qra_encode(const qracode *pcode, int *y, const int *x) -{ - int k,j,kk,jj; - int t, chk = 0; - - const int K = pcode->K; - const int M = pcode->M; - const int NC= pcode->NC; - const int a = pcode->a; - const int *acc_input_idx = pcode->acc_input_idx; - const int *acc_input_wlog = pcode->acc_input_wlog; - const int *gflog = pcode->gflog; - const int *gfexp = pcode->gfexp; - - // copy the systematic symbols to destination - memcpy(y,x,K*sizeof(int)); - - y = y+K; // point to check symbols - - // compute the code check symbols as a weighted accumulation of a permutated - // sequence of the (repeated) systematic input symbols: - // chk(k+1) = x(idx(k))*alfa^(logw(k)) + chk(k) - // (all operations performed over GF(M)) - - if (a==1) { // grouping factor = 1 - for (k=0;k 1 - for (k=0;k80.f) // avoid floating point exp() overflows - v=80.f; - - src[nitems] = (float)exp(v); - } -} - - -float qra_mfskbesselmetric(float *pix, const float *rsq, const int m, const int N, float EsNoMetric) -{ - // Computes the codeword symbols intrinsic probabilities - // given the square of the received input amplitudes. - - // The input vector rqs must be a linear array of size M*N, where M=2^m, - // containing the squared amplitudes (rp*rp+rq*rq) of the input samples - - // First symbol amplitudes should be stored in the first M positions, - // second symbol amplitudes stored at positions [M ... 2*M-1], and so on. - - // Output vector is the intrinsic symbol metric (the probability distribution) - // assuming that symbols are transmitted using a M-FSK modulation - // and incoherent demodulation. - - // As the input Es/No is generally unknown (as it cannot be exstimated accurately - // when the codeword length is few tens symbols) but an exact metric requires it - // we simply fix it to a predefined EsNoMetric value so that the metric is what - // expected at that specific value. - // The metric computed in this way is optimal only at this predefined Es/No value, - // nevertheless it is usually better than a generic parameter-free metric which - // makes no assumptions on the input Es/No. - - // returns the estimated noise standard deviation - - int k; - float rsum = 0.f; - float sigmaest, cmetric; - - const int M = 1<M; - const int qra_m = pcode->m; - const int qra_V = pcode->V; - const int qra_MAXVDEG = pcode->MAXVDEG; - const int *qra_vdeg = pcode->vdeg; - const int qra_C = pcode->C; - const int qra_MAXCDEG = pcode->MAXCDEG; - const int *qra_cdeg = pcode->cdeg; - const int *qra_v2cmidx = pcode->v2cmidx; - const int *qra_c2vmidx = pcode->c2vmidx; - const int *qra_pmat = pcode->gfpmat; - const int *qra_msgw = pcode->msgw; - -// float msgout[qra_M]; // buffer to store temporary results - float msgout[QRACODE_MAX_M]; // we use a fixed size in order to avoid mallocs - - float totex; // total extrinsic information - int nit; // current iteration - int nv; // current variable - int nc; // current check - int k,kk; // loop indexes - - int ndeg; // current node degree - int msgbase; // current offset in the table of msg indexes - int imsg; // current message index - int wmsg; // current message weight - - int rc = -1; // rc>=0 extrinsic converged to 1 at iteration rc (rc=0..maxiter-1) - // rc=-1 no convergence in the given number of iterations - // rc=-2 error in the code tables (code checks degrees must be >1) - // rc=-3 M is larger than QRACODE_MAX_M - - - - if (qra_M>QRACODE_MAX_M) - return -3; - - // message initialization ------------------------------------------------------- - - // init c->v variable intrinsic msgs - pd_init(C2VMSG(0),pix,qra_M*qra_V); - - // init the v->c messages directed to code factors (k=1..ndeg) with the intrinsic info - for (nv=0;nvc - for (k=1;kv step ----------------------------------------------------- - // Computes messages from code checks to code variables. - // As the first qra_V checks are associated with intrinsic information - // (the code tables have been constructed in this way) - // we need to do this step only for code checks in the range [qra_V..qra_C) - - // The convolutions of probability distributions over the alphabet of a finite field GF(qra_M) - // are performed with a fast convolution algorithm over the given field. - // - // I.e. given the code check x1+x2+x3 = 0 (with x1,x2,x3 in GF(2^m)) - // and given Prob(x2) and Prob(x3), we have that: - // Prob(x1=X1) = Prob((x2+x3)=X1) = sum((Prob(x2=X2)*Prob(x3=(X1+X2))) for all the X2s in the field - // This translates to Prob(x1) = IWHT(WHT(Prob(x2))*WHT(Prob(x3))) - // where WHT and IWHT are the direct and inverse Walsh-Hadamard transforms of the argument. - // Note that the WHT and the IWHF differs only by a multiplicative coefficent and since in this step - // we don't need that the output distribution is normalized we use the relationship - // Prob(x1) =(proportional to) WH(WH(Prob(x2))*WH(Prob(x3))) - - // In general given the check code x1+x2+x3+..+xm = 0 - // the output distribution of a variable given the distributions of the other m-1 variables - // is the inverse WHT of the product of the WHTs of the distribution of the other m-1 variables - // The complexity of this algorithm scales with M*log2(M) instead of the M^2 complexity of - // the brute force approach (M=size of the alphabet) - - for (nc=qra_V;nc1) - return -2; // bad code tables - - msgbase = nc*qra_MAXCDEG; // base to msg index row for the current node - - // transforms inputs in the Walsh-Hadamard "frequency" domain - // v->c -> fwht(v->c) - for (k=0;kv = prod(fwht(v->c)) - // TODO: we assume that checks degrees are not larger than three but - // if they are larger the products can be computed more efficiently - for (kk=0;kkc steps when multipling - // small fp numbers - msgout[0]+=1E-7f; // TODO: define the bias accordingly to the field size - - np_fwht(qra_m,msgout,msgout); - - // inverse weight and output - imsg = qra_c2vmidx[msgbase+k]; // current output msg index - wmsg = qra_msgw[imsg]; // current msg weight - - if (wmsg==0) - pd_init(C2VMSG(imsg),msgout,qra_M); - else - // output p(alfa^(-w)*x) - pd_bwdperm(C2VMSG(imsg),msgout, MSGPERM(wmsg), qra_M); - - } // for (k=0;kc step ----------------------------------------------------- - for (nv=0;nvc msg = prod(c->v) - // TODO: factor factors to reduce the number of computations for high degree nodes - for (kk=0;kkc are null - // normalize output to a probability distribution - if (pd_norm(msgout,qra_m)<=0) { - // dump msgin; - printf("warning: v->c pd with invalid norm. nit=%d nv=%d k=%d\n",nit,nv,k); - for (kk=0;kk(1.*(qra_V)-0.01)) { - // the total maximum extrinsic information of each symbol in the codeword - // is very close to one. This means that we have reached the (1,1) point in the - // code EXIT chart(s) and we have successfully decoded the input. - rc = nit; - break; // remove the break to evaluate the decoder speed performance as a function of the max iterations number) - } - - } // for (nit=0;nitM; - const int qra_m = pcode->m; - const int qra_K = pcode->K; - - int k; - - for (k=0;k. + +#include +#include + +#include "npfwht.h" +#include "pdmath.h" + +#include "qracodes.h" + +int qra_encode(const qracode *pcode, int *y, const int *x) +{ + int k,j,kk,jj; + int t, chk = 0; + + const int K = pcode->K; + const int M = pcode->M; + const int NC= pcode->NC; + const int a = pcode->a; + const int *acc_input_idx = pcode->acc_input_idx; + const int *acc_input_wlog = pcode->acc_input_wlog; + const int *gflog = pcode->gflog; + const int *gfexp = pcode->gfexp; + + // copy the systematic symbols to destination + memcpy(y,x,K*sizeof(int)); + + y = y+K; // point to check symbols + + // compute the code check symbols as a weighted accumulation of a permutated + // sequence of the (repeated) systematic input symbols: + // chk(k+1) = x(idx(k))*alfa^(logw(k)) + chk(k) + // (all operations performed over GF(M)) + + if (a==1) { // grouping factor = 1 + for (k=0;k 1 + for (k=0;k80.f) // avoid floating point exp() overflows + v=80.f; + + src[nitems] = (float)exp(v); + } +} + + +float qra_mfskbesselmetric(float *pix, const float *rsq, const int m, const int N, float EsNoMetric) +{ + // Computes the codeword symbols intrinsic probabilities + // given the square of the received input amplitudes. + + // The input vector rqs must be a linear array of size M*N, where M=2^m, + // containing the squared amplitudes (rp*rp+rq*rq) of the input samples + + // First symbol amplitudes should be stored in the first M positions, + // second symbol amplitudes stored at positions [M ... 2*M-1], and so on. + + // Output vector is the intrinsic symbol metric (the probability distribution) + // assuming that symbols are transmitted using a M-FSK modulation + // and incoherent demodulation. + + // As the input Es/No is generally unknown (as it cannot be exstimated accurately + // when the codeword length is few tens symbols) but an exact metric requires it + // we simply fix it to a predefined EsNoMetric value so that the metric is what + // expected at that specific value. + // The metric computed in this way is optimal only at this predefined Es/No value, + // nevertheless it is usually better than a generic parameter-free metric which + // makes no assumptions on the input Es/No. + + // returns the estimated noise standard deviation + + int k; + float rsum = 0.f; + float sigmaest, cmetric; + + const int M = 1<M; + const int qra_m = pcode->m; + const int qra_V = pcode->V; + const int qra_MAXVDEG = pcode->MAXVDEG; + const int *qra_vdeg = pcode->vdeg; + const int qra_C = pcode->C; + const int qra_MAXCDEG = pcode->MAXCDEG; + const int *qra_cdeg = pcode->cdeg; + const int *qra_v2cmidx = pcode->v2cmidx; + const int *qra_c2vmidx = pcode->c2vmidx; + const int *qra_pmat = pcode->gfpmat; + const int *qra_msgw = pcode->msgw; + +// float msgout[qra_M]; // buffer to store temporary results + float msgout[QRACODE_MAX_M]; // we use a fixed size in order to avoid mallocs + + float totex; // total extrinsic information + int nit; // current iteration + int nv; // current variable + int nc; // current check + int k,kk; // loop indexes + + int ndeg; // current node degree + int msgbase; // current offset in the table of msg indexes + int imsg; // current message index + int wmsg; // current message weight + + int rc = -1; // rc>=0 extrinsic converged to 1 at iteration rc (rc=0..maxiter-1) + // rc=-1 no convergence in the given number of iterations + // rc=-2 error in the code tables (code checks degrees must be >1) + // rc=-3 M is larger than QRACODE_MAX_M + + + + if (qra_M>QRACODE_MAX_M) + return -3; + + // message initialization ------------------------------------------------------- + + // init c->v variable intrinsic msgs + pd_init(C2VMSG(0),pix,qra_M*qra_V); + + // init the v->c messages directed to code factors (k=1..ndeg) with the intrinsic info + for (nv=0;nvc + for (k=1;kv step ----------------------------------------------------- + // Computes messages from code checks to code variables. + // As the first qra_V checks are associated with intrinsic information + // (the code tables have been constructed in this way) + // we need to do this step only for code checks in the range [qra_V..qra_C) + + // The convolutions of probability distributions over the alphabet of a finite field GF(qra_M) + // are performed with a fast convolution algorithm over the given field. + // + // I.e. given the code check x1+x2+x3 = 0 (with x1,x2,x3 in GF(2^m)) + // and given Prob(x2) and Prob(x3), we have that: + // Prob(x1=X1) = Prob((x2+x3)=X1) = sum((Prob(x2=X2)*Prob(x3=(X1+X2))) for all the X2s in the field + // This translates to Prob(x1) = IWHT(WHT(Prob(x2))*WHT(Prob(x3))) + // where WHT and IWHT are the direct and inverse Walsh-Hadamard transforms of the argument. + // Note that the WHT and the IWHF differs only by a multiplicative coefficent and since in this step + // we don't need that the output distribution is normalized we use the relationship + // Prob(x1) =(proportional to) WH(WH(Prob(x2))*WH(Prob(x3))) + + // In general given the check code x1+x2+x3+..+xm = 0 + // the output distribution of a variable given the distributions of the other m-1 variables + // is the inverse WHT of the product of the WHTs of the distribution of the other m-1 variables + // The complexity of this algorithm scales with M*log2(M) instead of the M^2 complexity of + // the brute force approach (M=size of the alphabet) + + for (nc=qra_V;nc1) + return -2; // bad code tables + + msgbase = nc*qra_MAXCDEG; // base to msg index row for the current node + + // transforms inputs in the Walsh-Hadamard "frequency" domain + // v->c -> fwht(v->c) + for (k=0;kv = prod(fwht(v->c)) + // TODO: we assume that checks degrees are not larger than three but + // if they are larger the products can be computed more efficiently + for (kk=0;kkc steps when multipling + // small fp numbers + msgout[0]+=1E-7f; // TODO: define the bias accordingly to the field size + + np_fwht(qra_m,msgout,msgout); + + // inverse weight and output + imsg = qra_c2vmidx[msgbase+k]; // current output msg index + wmsg = qra_msgw[imsg]; // current msg weight + + if (wmsg==0) + pd_init(C2VMSG(imsg),msgout,qra_M); + else + // output p(alfa^(-w)*x) + pd_bwdperm(C2VMSG(imsg),msgout, MSGPERM(wmsg), qra_M); + + } // for (k=0;kc step ----------------------------------------------------- + for (nv=0;nvc msg = prod(c->v) + // TODO: factor factors to reduce the number of computations for high degree nodes + for (kk=0;kkc are null + // normalize output to a probability distribution + if (pd_norm(msgout,qra_m)<=0) { + // dump msgin; + printf("warning: v->c pd with invalid norm. nit=%d nv=%d k=%d\n",nit,nv,k); + for (kk=0;kk(1.*(qra_V)-0.01)) { + // the total maximum extrinsic information of each symbol in the codeword + // is very close to one. This means that we have reached the (1,1) point in the + // code EXIT chart(s) and we have successfully decoded the input. + rc = nit; + break; // remove the break to evaluate the decoder speed performance as a function of the max iterations number) + } + + } // for (nit=0;nitM; + const int qra_m = pcode->m; + const int qra_K = pcode->K; + + int k; + + for (k=0;k. - -#ifndef _qracodes_h_ -#define _qracodes_h_ - -// type of codes -#define QRATYPE_NORMAL 0x00 // normal code -#define QRATYPE_CRC 0x01 // code with crc - last information symbol is a CRC-6 -#define QRATYPE_CRCPUNCTURED 0x02 // the CRC-6 symbol is punctured (not sent along the channel) -#define QRATYPE_CRCPUNCTURED2 0x03 // code with CRC-12. The two crc symbols are punctured - - -typedef struct { - // code parameters - const int K; // number of information symbols - const int N; // codeword length in symbols - const int m; // bits/symbol - const int M; // Symbol alphabet cardinality (2^m) - const int a; // code grouping factor - const int NC; // number of check symbols (N-K) - const int V; // number of variables in the code graph (N) - const int C; // number of factors in the code graph (N +(N-K)+1) - const int NMSG; // number of msgs in the code graph - const int MAXVDEG; // maximum variable degree - const int MAXCDEG; // maximum factor degree - const int type; // see QRATYPE_xx defines - const float R; // code rate (K/N) - const char name[64]; // code name - // tables used by the encoder - const int *acc_input_idx; - const int *acc_input_wlog; - const int *gflog; - const int *gfexp; - // tables used by the decoder ------------------------- - const int *msgw; - const int *vdeg; - const int *cdeg; - const int *v2cmidx; - const int *c2vmidx; - const int *gfpmat; -} qracode; -// Uncomment the header file of the code which needs to be tested - -//#include "qra12_63_64_irr_b.h" // irregular code (12,63) over GF(64) -//#include "qra13_64_64_irr_e.h" // irregular code with good performance and best UER protection at AP56 -//#include "qra13_64_64_reg_a.h" // regular code with good UER but perf. inferior to that of code qra12_63_64_irr_b - -#ifdef __cplusplus -extern "C" { -#endif - -int qra_encode(const qracode *pcode, int *y, const int *x); -float qra_mfskbesselmetric(float *pix, const float *rsq, const int m, const int N, float EsNoMetric); -int qra_extrinsic(const qracode *pcode, float *pex, const float *pix, int maxiter,float *qra_v2cmsg,float *qra_c2vmsg); -void qra_mapdecode(const qracode *pcode, int *xdec, float *pex, const float *pix); - -#ifdef __cplusplus -} -#endif - -#endif // _qracodes_h_ +// qracodes.h +// Q-ary RA codes encoding/decoding functions +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#ifndef _qracodes_h_ +#define _qracodes_h_ + +// type of codes +#define QRATYPE_NORMAL 0x00 // normal code +#define QRATYPE_CRC 0x01 // code with crc - last information symbol is a CRC-6 +#define QRATYPE_CRCPUNCTURED 0x02 // the CRC-6 symbol is punctured (not sent along the channel) +#define QRATYPE_CRCPUNCTURED2 0x03 // code with CRC-12. The two crc symbols are punctured + + +typedef struct { + // code parameters + const int K; // number of information symbols + const int N; // codeword length in symbols + const int m; // bits/symbol + const int M; // Symbol alphabet cardinality (2^m) + const int a; // code grouping factor + const int NC; // number of check symbols (N-K) + const int V; // number of variables in the code graph (N) + const int C; // number of factors in the code graph (N +(N-K)+1) + const int NMSG; // number of msgs in the code graph + const int MAXVDEG; // maximum variable degree + const int MAXCDEG; // maximum factor degree + const int type; // see QRATYPE_xx defines + const float R; // code rate (K/N) + const char name[64]; // code name + // tables used by the encoder + const int *acc_input_idx; + const int *acc_input_wlog; + const int *gflog; + const int *gfexp; + // tables used by the decoder ------------------------- + const int *msgw; + const int *vdeg; + const int *cdeg; + const int *v2cmidx; + const int *c2vmidx; + const int *gfpmat; +} qracode; +// Uncomment the header file of the code which needs to be tested + +//#include "qra12_63_64_irr_b.h" // irregular code (12,63) over GF(64) +//#include "qra13_64_64_irr_e.h" // irregular code with good performance and best UER protection at AP56 +//#include "qra13_64_64_reg_a.h" // regular code with good UER but perf. inferior to that of code qra12_63_64_irr_b + +#ifdef __cplusplus +extern "C" { +#endif + +int qra_encode(const qracode *pcode, int *y, const int *x); +float qra_mfskbesselmetric(float *pix, const float *rsq, const int m, const int N, float EsNoMetric); +int qra_extrinsic(const qracode *pcode, float *pex, const float *pix, int maxiter,float *qra_v2cmsg,float *qra_c2vmsg); +void qra_mapdecode(const qracode *pcode, int *xdec, float *pex, const float *pix); + +#ifdef __cplusplus +} +#endif + +#endif // _qracodes_h_ diff --git a/lib/qra/q65/wer-ff-qra15_65_64_irr_e23-ap00.txt b/lib/qra/q65/wer-ff-qra15_65_64_irr_e23-ap00.txt index 646721eb..b087ad9f 100755 --- a/lib/qra/q65/wer-ff-qra15_65_64_irr_e23-ap00.txt +++ b/lib/qra/q65/wer-ff-qra15_65_64_irr_e23-ap00.txt @@ -1,19 +1,19 @@ -#Code Name: qra15_65_64_irr_e23 -#ChannelType (0=AWGN,1=Rayleigh,2=Fast-Fading) -#Eb/No (dB) -#Transmitted Codewords -#Errors -#CRC Errors -#Undetected -#Avg dec. time (ms) -#WER -#UER -2 -30.00 106 106 0 0 4.87 1.00e+000 0.00e+000 -2 0.50 1006 1006 0 0 4.91 1.00e+000 0.00e+000 -2 1.00 1007 1006 0 0 4.98 9.99e-001 0.00e+000 -2 1.50 1009 1007 0 0 4.97 9.98e-001 0.00e+000 -2 2.00 1017 1007 1 0 4.84 9.90e-001 2.40e-007 -2 2.50 1047 1006 1 0 4.79 9.61e-001 2.33e-007 -2 3.00 1148 1006 3 0 4.61 8.76e-001 6.38e-007 -2 3.50 1338 1006 6 0 4.43 7.52e-001 1.10e-006 -2 4.00 1902 1006 7 0 3.94 5.29e-001 8.99e-007 +#Code Name: qra15_65_64_irr_e23 +#ChannelType (0=AWGN,1=Rayleigh,2=Fast-Fading) +#Eb/No (dB) +#Transmitted Codewords +#Errors +#CRC Errors +#Undetected +#Avg dec. time (ms) +#WER +#UER +2 -30.00 106 106 0 0 4.87 1.00e+000 0.00e+000 +2 0.50 1006 1006 0 0 4.91 1.00e+000 0.00e+000 +2 1.00 1007 1006 0 0 4.98 9.99e-001 0.00e+000 +2 1.50 1009 1007 0 0 4.97 9.98e-001 0.00e+000 +2 2.00 1017 1007 1 0 4.84 9.90e-001 2.40e-007 +2 2.50 1047 1006 1 0 4.79 9.61e-001 2.33e-007 +2 3.00 1148 1006 3 0 4.61 8.76e-001 6.38e-007 +2 3.50 1338 1006 6 0 4.43 7.52e-001 1.10e-006 +2 4.00 1902 1006 7 0 3.94 5.29e-001 8.99e-007 diff --git a/lib/qra/qracodes/Makefile.Win b/lib/qra/qracodes/Makefile.Win index 670770f0..fb30504e 100755 --- a/lib/qra/qracodes/Makefile.Win +++ b/lib/qra/qracodes/Makefile.Win @@ -1,33 +1,33 @@ -CC = gcc -CFLAGS = -O2 -Wall -I. -D_WIN32 - -# 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: libqra64.a qracodes.exe - -OBJS1 = normrnd.o npfwht.o pdmath.o qra12_63_64_irr_b.o \ - qra13_64_64_irr_e.o qracodes.o - -libqra64.a: $(OBJS1) - ar cr libqra64.a $(OBJS1) - ranlib libqra64.a - -OBJS2 = main.o - -qracodes.exe: $(OBJS2) - ${CC} -o qracodes.exe $(OBJS2) libqra64.a -lm - -.PHONY : clean - -clean: - $(RM) *.o libqra64.a qracodes.exe +CC = gcc +CFLAGS = -O2 -Wall -I. -D_WIN32 + +# 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: libqra64.a qracodes.exe + +OBJS1 = normrnd.o npfwht.o pdmath.o qra12_63_64_irr_b.o \ + qra13_64_64_irr_e.o qracodes.o + +libqra64.a: $(OBJS1) + ar cr libqra64.a $(OBJS1) + ranlib libqra64.a + +OBJS2 = main.o + +qracodes.exe: $(OBJS2) + ${CC} -o qracodes.exe $(OBJS2) libqra64.a -lm + +.PHONY : clean + +clean: + $(RM) *.o libqra64.a qracodes.exe diff --git a/lib/qra/qracodes/ebno10000.txt b/lib/qra/qracodes/ebno10000.txt index a41ee2a7..c41174b9 100755 --- a/lib/qra/qracodes/ebno10000.txt +++ b/lib/qra/qracodes/ebno10000.txt @@ -1,7 +1,7 @@ -# Eb/No Values to be used during the code simulation -# Each line of this file indicates the Eb/No value to be simulated (in dB) -# and the number of errors to be detected by the decoder -0.6 10000 -1.1 10000 -1.6 10000 -2.1 10000 +# Eb/No Values to be used during the code simulation +# Each line of this file indicates the Eb/No value to be simulated (in dB) +# and the number of errors to be detected by the decoder +0.6 10000 +1.1 10000 +1.6 10000 +2.1 10000 diff --git a/lib/qra/qracodes/ebnovalues.txt b/lib/qra/qracodes/ebnovalues.txt index a26d7efd..7dba138f 100755 --- a/lib/qra/qracodes/ebnovalues.txt +++ b/lib/qra/qracodes/ebnovalues.txt @@ -1,15 +1,15 @@ -# Eb/No Values to be used during the code simulation -# Each line of this file indicates the Eb/No value to be simulated (in dB) -# and the number of errors to be detected by the decoder -1.1 1000 -1.6 1000 -2.1 1000 -2.6 1000 -3.1 1000 -3.6 1000 -4.1 1000 -4.6 1000 -5.1 500 -5.6 200 -6.1 100 +# Eb/No Values to be used during the code simulation +# Each line of this file indicates the Eb/No value to be simulated (in dB) +# and the number of errors to be detected by the decoder +1.1 1000 +1.6 1000 +2.1 1000 +2.6 1000 +3.1 1000 +3.6 1000 +4.1 1000 +4.6 1000 +5.1 500 +5.6 200 +6.1 100 6.6 50 \ No newline at end of file diff --git a/lib/qra/qracodes/ebnovaluesfast.txt b/lib/qra/qracodes/ebnovaluesfast.txt index 84d030ac..b057b312 100755 --- a/lib/qra/qracodes/ebnovaluesfast.txt +++ b/lib/qra/qracodes/ebnovaluesfast.txt @@ -1,11 +1,11 @@ -# Eb/No Values to be used during the code simulation -# Each line of this file indicates the Eb/No value to be simulated (in dB) -# and the number of errors to be detected by the decoder -1.1 500 -1.6 500 -2.1 500 -2.6 500 -3.1 500 -3.6 500 -4.1 200 -4.6 50 +# Eb/No Values to be used during the code simulation +# Each line of this file indicates the Eb/No value to be simulated (in dB) +# and the number of errors to be detected by the decoder +1.1 500 +1.6 500 +2.1 500 +2.6 500 +3.1 500 +3.6 500 +4.1 200 +4.6 50 diff --git a/lib/qra/qracodes/main.c b/lib/qra/qracodes/main.c index 3c00d052..5f9f067d 100755 --- a/lib/qra/qracodes/main.c +++ b/lib/qra/qracodes/main.c @@ -1,737 +1,737 @@ -// main.c -// Word Error Rate test example for Q-ary RA codes over GF(64) -// -// (c) 2016 - Nico Palermo, IV3NWV -// -// Thanks to Andrea Montefusco IW0HDV for his help on adapting the sources -// to OSs other than MS Windows -// -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// Files in this package: -// main.c - this file -// normrnd.c/.h - random gaussian number generator -// npfwht.c/.h - Fast Walsh-Hadamard Transforms -// pdmath.c/.h - Elementary math on probability distributions -// qra12_63_64_irr_b.c/.h - Tables for a QRA(12,63) irregular RA code over GF(64) -// qra13_64_64_irr_e.c/.h - Tables for a QRA(13,64) irregular RA code " " -// qracodes.c/.h - QRA codes encoding/decoding functions -// -// ------------------------------------------------------------------------------- -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -// ----------------------------------------------------------------------------- - -// Two codes are available for simulations in this sowftware release: - -// QRA12_63_64_IRR_B: K=12 N=63 Q=64 irregular QRA code (defined in qra12_63_64_irr_b.h /.c) -// QRA13_64_64_IRR_E: K=13 N=64 Q=64 irregular QRA code (defined in qra13_64_64_irr_b.h /.c) - -// Codes with K=13 are designed to include a CRC as the 13th information symbol -// and improve the code UER (Undetected Error Rate). -// The CRC symbol is not sent along the channel (the codes are punctured) and the -// resulting code is still a (12,63) code with an effective code rate of R = 12/63. - -// ------------------------------------------------------------------------------ - -// OS dependent defines and includes -------------------------------------------- - -#if _WIN32 // note the underscore: without it, it's not msdn official! - // Windows (x64 and x86) - #include // required only for GetTickCount(...) - #include // _beginthread -#endif - -#if defined(__linux__) - -// remove unwanted macros -#define __cdecl - -// implements Windows API -#include - - unsigned int GetTickCount(void) { - struct timespec ts; - unsigned int theTick = 0U; - clock_gettime( CLOCK_REALTIME, &ts ); - theTick = ts.tv_nsec / 1000000; - theTick += ts.tv_sec * 1000; - return theTick; -} - -// Convert Windows millisecond sleep -// -// VOID WINAPI Sleep(_In_ DWORD dwMilliseconds); -// -// to Posix usleep (in microseconds) -// -// int usleep(useconds_t usec); -// -#include -#define Sleep(x) usleep(x*1000) - -#endif - -#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) ) -#include -#endif - -#if __APPLE__ -#endif - -#include -#include - -#include "qracodes.h" -#include "normrnd.h" // gaussian numbers generator -#include "pdmath.h" // operations on probability distributions - -// defined codes -#include "qra12_63_64_irr_b.h" -#include "qra13_64_64_irr_e.h" - -// ----------------------------------------------------------------------------------- - -#define NTHREADS_MAX 160 - -// channel types -#define CHANNEL_AWGN 0 -#define CHANNEL_RAYLEIGH 1 - -// amount of a-priori information provided to the decoder -#define AP_NONE 0 -#define AP_28 1 -#define AP_44 2 -#define AP_56 3 - -const char ap_str[4][16] = { - "None", - "28 bit", - "44 bit", - "56 bit" -}; - -const char fnameout_pfx[2][64] = { - "wer-awgn-", - "wer-rayleigh-" -}; -const char fnameout_sfx[4][64] = { - "-ap00.txt", - "-ap28.txt", - "-ap44.txt", - "-ap56.txt" -}; - -const int ap_masks_jt65[4][13] = { -// Each row must be 13 entries long (to handle puntc. codes 13,64) -// The mask of 13th symbol (crc) is alway initializated to 0 - // AP0 - no a-priori knowledge - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - // AP28 - 1st field known [cq ? ?] or [dst ? ?] - {0x3F,0x3F,0x3F,0x3F,0x3C, 0, 0, 0, 0, 0, 0, 0}, - // AP44 - 1st and 3rd fields known [cq ? 0] or [dst ? 0] - {0x3F,0x3F,0x3F,0x3F,0x3C, 0, 0, 0, 0,0x0F,0x3F,0x3F}, - // AP56 - 1st and 2nd fields known [dst src ?] - {0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x30, 0, 0} -}; - -void ix_mask(const qracode *pcode, float *r, const int *mask, const int *x); - -void printword(char *msg, int *x, int size) -{ - int k; - printf("\n%s ",msg); - for (k=0;kc msg buffer - float *qra_c2vmsg; //[qra_NMSG*qra_M]; MP decoder c->v msg buffer - float *rp; // [qra_N*qra_M]; received samples (real component) buffer - float *rq; // [qra_N*qra_M]; received samples (imag component) buffer - float *chp; //[qra_N]; channel gains (real component) buffer - float *chq; //[qra_N]; channel gains (imag component) buffer - float *r; //[qra_N*qra_M]; received samples (amplitude) buffer - float *ix; // [qra_N*qra_M]; // intrinsic information to the MP algorithm - float *ex; // [qra_N*qra_M]; // extrinsic information from the MP algorithm - -} wer_test_ds; - -typedef void( __cdecl *pwer_test_thread)(wer_test_ds*); - -// crc-6 generator polynomial -// g(x) = x^6 + a5*x^5 + ... + a1*x + a0 - -// g(x) = x^6 + x + 1 -#define CRC6_GEN_POL 0x30 // MSB=a0 LSB=a5 - -// g(x) = x^6 + x^2 + x + 1 (as suggested by Joe. See: https://users.ece.cmu.edu/~koopman/crc/) -// #define CRC6_GEN_POL 0x38 // MSB=a0 LSB=a5. Simulation results are similar - -int calc_crc6(int *x, int sz) -{ - int k,j,t,sr = 0; - for (k=0;k>1) ^ CRC6_GEN_POL; - else - sr = (sr>>1); - t>>=1; - } - } - return sr; -} - -void wer_test_thread(wer_test_ds *pdata) -{ - const qracode *pcode=pdata->pcode; - const int qra_K = pcode->K; - const int qra_N = pcode->N; - const int qra_M = pcode->M; - const int qra_m = pcode->m; - const int NSAMPLES = pcode->N*pcode->M; - - const float No = 1.0f; // noise spectral density - const float sigma = (float)sqrt(No/2.0f); // std dev of noise I/Q components - const float sigmach = (float)sqrt(1/2.0f); // std dev of channel I/Q gains - - // Eb/No value for which we optimize the bessel metric - const float EbNodBMetric = 2.8f; - const float EbNoMetric = (float)pow(10,EbNodBMetric/10); - - int k,t,j,diff; - float R; - float EsNoMetric; - float EbNo, EsNo, Es, A; - int channel_type, code_type; - int nt=0; // transmitted codewords - int nerrs = 0; // total number of errors - int nerrsu = 0; // number of undetected errors - int rc; - - - // inizialize pointer to required buffers - int *x=pdata->x; // message buffer - int *y=pdata->y, *ydec=pdata->ydec; // encoded/decoded codeword buffers - float *qra_v2cmsg=pdata->qra_v2cmsg; // table of the v->c messages - float *qra_c2vmsg=pdata->qra_c2vmsg; // table of the c->v messages - float *rp=pdata->rp; // received samples (real component) - float *rq=pdata->rq; // received samples (imag component) - float *chp=pdata->chp; // channel gains (real component) - float *chq=pdata->chq; // channel gains (imag component) - float *r=pdata->r; // received samples amplitudes - float *ix=pdata->ix; // intrinsic information to the MP algorithm - float *ex=pdata->ex; // extrinsic information from the MP algorithm - - channel_type = pdata->channel_type; - code_type = pcode->type; - - // define the (true) code rate accordingly to the code type - switch(code_type) { - case QRATYPE_CRC: - R = 1.0f*(qra_K-1)/qra_N; - break; - case QRATYPE_CRCPUNCTURED: - R = 1.0f*(qra_K-1)/(qra_N-1); - break; - case QRATYPE_NORMAL: - default: - R = 1.0f*(qra_K)/(qra_N); - } - - EsNoMetric = 1.0f*qra_m*R*EbNoMetric; - - EbNo = (float)pow(10,pdata->EbNodB/10); - EsNo = 1.0f*qra_m*R*EbNo; - Es = EsNo*No; - A = (float)sqrt(Es); - - - // encode the input - if (code_type==QRATYPE_CRC || code_type==QRATYPE_CRCPUNCTURED) { - // compute the information message symbol check as the (negated) xor of all the - // information message symbols - for (k=0;k<(qra_K-1);k++) - x[k]=k%qra_M; - x[k]=calc_crc6(x,qra_K-1); - } - else - for (k=0;kstop==0) { - - // simulate the channel - // NOTE: in the case that the code is punctured, for simplicity - // we compute the channel outputs and the metric also for the crc symbol - // then we ignore its observation. - normrnd_s(rp,NSAMPLES,0,sigma); - normrnd_s(rq,NSAMPLES,0,sigma); - - if (channel_type == CHANNEL_AWGN) { - for (k=0;kdone = 1; - return; // unknown channel type - } - - // compute the squares of the amplitudes of the received samples - for (k=0;km,pcode->N,EsNoMetric); - - if (code_type==QRATYPE_CRCPUNCTURED) { - // ignore observations of the CRC symbol as it is not actually sent - // over the channel - pd_init(PD_ROWADDR(ix,qra_M,qra_K),pd_uniform(qra_m),qra_M); - } - - - if (pdata->ap_index!=0) - // mask channel observations with a priori knowledge - ix_mask(pcode,ix,ap_masks_jt65[pdata->ap_index],x); - - - // compute the extrinsic symbols probabilities with the message-passing algorithm - // stop if extrinsic information does not converges to 1 within the given number of iterations - rc = qra_extrinsic(pcode,ex,ix,100,qra_v2cmsg,qra_c2vmsg); - - if (rc>=0) { // the MP algorithm converged to Iex~1 in rc iterations - - // decode the codeword - qra_mapdecode(pcode,ydec,ex,ix); - - // look for undetected errors - if (code_type==QRATYPE_CRC || code_type==QRATYPE_CRCPUNCTURED) { - - j = 0; diff = 0; - for (k=0;k<(qra_K-1);k++) - diff |= (ydec[k]!=x[k]); - t = calc_crc6(ydec,qra_K-1); - if (t!=ydec[k]) // error detected - crc doesn't matches - nerrs += 1; - else - if (diff) { // decoded message is not equal to the transmitted one but - // the crc test passed - // add as undetected error - nerrsu += 1; - nerrs += 1; - // uncomment to see what the undetected error pattern looks like - //printword("U", ydec); - } - } - else - for (k=0;knt=nt; - pdata->nerrs=nerrs; - pdata->nerrsu=nerrsu; - - } - - pdata->done=1; - - #if _WIN32 - _endthread(); - #endif -} - -#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) ) - -void *wer_test_pthread(void *p) -{ - wer_test_thread ((wer_test_ds *)p); - return 0; -} - -#endif - -void ix_mask(const qracode *pcode, float *r, const int *mask, const int *x) -{ - // mask intrinsic information (channel observations) with a priori knowledge - - int k,kk, smask; - const int qra_K=pcode->K; - const int qra_M=pcode->M; - const int qra_m=pcode->m; - - for (k=0;kNTHREADS_MAX) { - printf("Error: nthreads should be <=%d\n",NTHREADS_MAX); - return -1; - } - - sprintf(fnameout,"%s%s%s", - fnameout_pfx[chtype], - pcode->name, - fnameout_sfx[ap_index]); - - fout = fopen(fnameout,"w"); - fprintf(fout,"# Channel (0=AWGN,1=Rayleigh), Eb/No (dB), Transmitted codewords, Errors, Undetected Errors, Avg dec. time (ms), WER\n"); - - printf("\nTesting the code %s over the %s channel\nSimulation data will be saved to %s\n", - pcode->name, - chtype==CHANNEL_AWGN?"AWGN":"Rayleigh", - fnameout); - fflush (stdout); - - // init fixed thread parameters and preallocate buffers - for (j=0;jK*sizeof(int)); - wt[j].y = (int*)malloc(pcode->N*sizeof(int)); - wt[j].ydec = (int*)malloc(pcode->N*sizeof(int)); - wt[j].qra_v2cmsg = (float*)malloc(pcode->NMSG*pcode->M*sizeof(float)); - wt[j].qra_c2vmsg = (float*)malloc(pcode->NMSG*pcode->M*sizeof(float)); - wt[j].rp = (float*)malloc(pcode->N*pcode->M*sizeof(float)); - wt[j].rq = (float*)malloc(pcode->N*pcode->M*sizeof(float)); - wt[j].chp = (float*)malloc(pcode->N*sizeof(float)); - wt[j].chq = (float*)malloc(pcode->N*sizeof(float)); - wt[j].r = (float*)malloc(pcode->N*pcode->M*sizeof(float)); - wt[j].ix = (float*)malloc(pcode->N*pcode->M*sizeof(float)); - wt[j].ex = (float*)malloc(pcode->N*pcode->M*sizeof(float)); - } - - - for (k=0;k=nerrstgt[k]) { - for (j=0;j] [-t] [-c] [-a] [-f[-h]\n"); - printf("Options: \n"); - printf(" -q: code to simulate. 0=qra_12_63_64_irr_b\n"); - printf(" 1=qra_13_64_64_irr_e (default)\n"); - printf(" -t : number of threads to be used for the simulation [1..24]\n"); - printf(" (default=8)\n"); - printf(" -c : channel_type. 0=AWGN 1=Rayleigh \n"); - printf(" (default=AWGN)\n"); - printf(" -a : amount of a-priori information provided to decoder. \n"); - printf(" 0= No a-priori (default)\n"); - printf(" 1= 28 bit \n"); - printf(" 2= 44 bit \n"); - printf(" 3= 56 bit \n"); - printf(" -f : name of the file containing the Eb/No values to be simulated\n"); - printf(" (default=ebnovalues.txt)\n"); - printf(" This file should contain lines in this format:\n"); - printf(" # Eb/No(dB) Target Errors\n"); - printf(" 0.1 5000\n"); - printf(" 0.6 5000\n"); - printf(" 1.1 1000\n"); - printf(" 1.6 1000\n"); - printf(" ...\n"); - printf(" (lines beginning with a # are treated as comments\n\n"); -} - -#define SIM_POINTS_MAX 20 - -int main(int argc, char* argv[]) -{ - - float EbNodB[SIM_POINTS_MAX]; - int nerrstgt[SIM_POINTS_MAX]; - FILE *fin; - - char fnamein[128]= "ebnovalues.txt"; - char buf[128]; - - int nitems = 0; - int code_idx = 1; - int nthreads = 8; - int ch_type = CHANNEL_AWGN; - int ap_index = AP_NONE; - - // parse command line - while(--argc) { - argv++; - if (strncmp(*argv,"-h",2)==0) { - syntax(); - return 0; - } - else - if (strncmp(*argv,"-q",2)==0) { - code_idx = (int)atoi((*argv)+2); - if (code_idx>1) { - printf("Invalid code index\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-t",2)==0) { - nthreads = (int)atoi((*argv)+2); - printf("nthreads = %d\n",nthreads); - if (nthreads>NTHREADS_MAX) { - printf("Invalid number of threads\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-c",2)==0) { - ch_type = (int)atoi((*argv)+2); - if (ch_type>CHANNEL_RAYLEIGH) { - printf("Invalid channel type\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-a",2)==0) { - ap_index = (int)atoi((*argv)+2); - if (ap_index>AP_56) { - printf("Invalid a-priori information index\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-f",2)==0) { - strncpy(fnamein,(*argv)+2,127); - } - else - if (strncmp(*argv,"-h",2)==0) { - syntax(); - return -1; - } - else { - printf("Invalid option\n"); - syntax(); - return -1; - } - } - - // parse points to be simulated from the input file - fin = fopen(fnamein,"r"); - if (!fin) { - printf("Can't open file: %s\n",fnamein); - syntax(); - } - - while (fgets(buf,128,fin)!=0) - if (*buf=='#' || *buf=='\n' ) - continue; - else - if (nitems==SIM_POINTS_MAX) - break; - else - if (sscanf(buf,"%f %u",&EbNodB[nitems],&nerrstgt[nitems])!=2) { - printf("Invalid input file format\n"); - syntax(); - return -1; - } - else - nitems++; - - fclose(fin); - - if (nitems==0) { - printf("No Eb/No point specified in file %s\n",fnamein); - syntax(); - return -1; - } - - printf("\nQ-ary Repeat-Accumulate Code Word Error Rate Simulator\n"); - printf("2016, Nico Palermo - IV3NWV\n\n"); - - printf("Nthreads = %d\n",nthreads); - printf("Channel = %s\n",ch_type==CHANNEL_AWGN?"AWGN":"Rayleigh"); - printf("Codename = %s\n",codetotest[code_idx]->name); - printf("A-priori = %s\n",ap_str[ap_index]); - printf("Eb/No input file = %s\n\n",fnamein); - - wer_test_proc(codetotest[code_idx], nthreads, ch_type, ap_index, EbNodB, nerrstgt, nitems); - - return 0; -} - +// main.c +// Word Error Rate test example for Q-ary RA codes over GF(64) +// +// (c) 2016 - Nico Palermo, IV3NWV +// +// Thanks to Andrea Montefusco IW0HDV for his help on adapting the sources +// to OSs other than MS Windows +// +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// Files in this package: +// main.c - this file +// normrnd.c/.h - random gaussian number generator +// npfwht.c/.h - Fast Walsh-Hadamard Transforms +// pdmath.c/.h - Elementary math on probability distributions +// qra12_63_64_irr_b.c/.h - Tables for a QRA(12,63) irregular RA code over GF(64) +// qra13_64_64_irr_e.c/.h - Tables for a QRA(13,64) irregular RA code " " +// qracodes.c/.h - QRA codes encoding/decoding functions +// +// ------------------------------------------------------------------------------- +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +// ----------------------------------------------------------------------------- + +// Two codes are available for simulations in this sowftware release: + +// QRA12_63_64_IRR_B: K=12 N=63 Q=64 irregular QRA code (defined in qra12_63_64_irr_b.h /.c) +// QRA13_64_64_IRR_E: K=13 N=64 Q=64 irregular QRA code (defined in qra13_64_64_irr_b.h /.c) + +// Codes with K=13 are designed to include a CRC as the 13th information symbol +// and improve the code UER (Undetected Error Rate). +// The CRC symbol is not sent along the channel (the codes are punctured) and the +// resulting code is still a (12,63) code with an effective code rate of R = 12/63. + +// ------------------------------------------------------------------------------ + +// OS dependent defines and includes -------------------------------------------- + +#if _WIN32 // note the underscore: without it, it's not msdn official! + // Windows (x64 and x86) + #include // required only for GetTickCount(...) + #include // _beginthread +#endif + +#if defined(__linux__) + +// remove unwanted macros +#define __cdecl + +// implements Windows API +#include + + unsigned int GetTickCount(void) { + struct timespec ts; + unsigned int theTick = 0U; + clock_gettime( CLOCK_REALTIME, &ts ); + theTick = ts.tv_nsec / 1000000; + theTick += ts.tv_sec * 1000; + return theTick; +} + +// Convert Windows millisecond sleep +// +// VOID WINAPI Sleep(_In_ DWORD dwMilliseconds); +// +// to Posix usleep (in microseconds) +// +// int usleep(useconds_t usec); +// +#include +#define Sleep(x) usleep(x*1000) + +#endif + +#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) ) +#include +#endif + +#if __APPLE__ +#endif + +#include +#include + +#include "qracodes.h" +#include "normrnd.h" // gaussian numbers generator +#include "pdmath.h" // operations on probability distributions + +// defined codes +#include "qra12_63_64_irr_b.h" +#include "qra13_64_64_irr_e.h" + +// ----------------------------------------------------------------------------------- + +#define NTHREADS_MAX 160 + +// channel types +#define CHANNEL_AWGN 0 +#define CHANNEL_RAYLEIGH 1 + +// amount of a-priori information provided to the decoder +#define AP_NONE 0 +#define AP_28 1 +#define AP_44 2 +#define AP_56 3 + +const char ap_str[4][16] = { + "None", + "28 bit", + "44 bit", + "56 bit" +}; + +const char fnameout_pfx[2][64] = { + "wer-awgn-", + "wer-rayleigh-" +}; +const char fnameout_sfx[4][64] = { + "-ap00.txt", + "-ap28.txt", + "-ap44.txt", + "-ap56.txt" +}; + +const int ap_masks_jt65[4][13] = { +// Each row must be 13 entries long (to handle puntc. codes 13,64) +// The mask of 13th symbol (crc) is alway initializated to 0 + // AP0 - no a-priori knowledge + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // AP28 - 1st field known [cq ? ?] or [dst ? ?] + {0x3F,0x3F,0x3F,0x3F,0x3C, 0, 0, 0, 0, 0, 0, 0}, + // AP44 - 1st and 3rd fields known [cq ? 0] or [dst ? 0] + {0x3F,0x3F,0x3F,0x3F,0x3C, 0, 0, 0, 0,0x0F,0x3F,0x3F}, + // AP56 - 1st and 2nd fields known [dst src ?] + {0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x30, 0, 0} +}; + +void ix_mask(const qracode *pcode, float *r, const int *mask, const int *x); + +void printword(char *msg, int *x, int size) +{ + int k; + printf("\n%s ",msg); + for (k=0;kc msg buffer + float *qra_c2vmsg; //[qra_NMSG*qra_M]; MP decoder c->v msg buffer + float *rp; // [qra_N*qra_M]; received samples (real component) buffer + float *rq; // [qra_N*qra_M]; received samples (imag component) buffer + float *chp; //[qra_N]; channel gains (real component) buffer + float *chq; //[qra_N]; channel gains (imag component) buffer + float *r; //[qra_N*qra_M]; received samples (amplitude) buffer + float *ix; // [qra_N*qra_M]; // intrinsic information to the MP algorithm + float *ex; // [qra_N*qra_M]; // extrinsic information from the MP algorithm + +} wer_test_ds; + +typedef void( __cdecl *pwer_test_thread)(wer_test_ds*); + +// crc-6 generator polynomial +// g(x) = x^6 + a5*x^5 + ... + a1*x + a0 + +// g(x) = x^6 + x + 1 +#define CRC6_GEN_POL 0x30 // MSB=a0 LSB=a5 + +// g(x) = x^6 + x^2 + x + 1 (as suggested by Joe. See: https://users.ece.cmu.edu/~koopman/crc/) +// #define CRC6_GEN_POL 0x38 // MSB=a0 LSB=a5. Simulation results are similar + +int calc_crc6(int *x, int sz) +{ + int k,j,t,sr = 0; + for (k=0;k>1) ^ CRC6_GEN_POL; + else + sr = (sr>>1); + t>>=1; + } + } + return sr; +} + +void wer_test_thread(wer_test_ds *pdata) +{ + const qracode *pcode=pdata->pcode; + const int qra_K = pcode->K; + const int qra_N = pcode->N; + const int qra_M = pcode->M; + const int qra_m = pcode->m; + const int NSAMPLES = pcode->N*pcode->M; + + const float No = 1.0f; // noise spectral density + const float sigma = (float)sqrt(No/2.0f); // std dev of noise I/Q components + const float sigmach = (float)sqrt(1/2.0f); // std dev of channel I/Q gains + + // Eb/No value for which we optimize the bessel metric + const float EbNodBMetric = 2.8f; + const float EbNoMetric = (float)pow(10,EbNodBMetric/10); + + int k,t,j,diff; + float R; + float EsNoMetric; + float EbNo, EsNo, Es, A; + int channel_type, code_type; + int nt=0; // transmitted codewords + int nerrs = 0; // total number of errors + int nerrsu = 0; // number of undetected errors + int rc; + + + // inizialize pointer to required buffers + int *x=pdata->x; // message buffer + int *y=pdata->y, *ydec=pdata->ydec; // encoded/decoded codeword buffers + float *qra_v2cmsg=pdata->qra_v2cmsg; // table of the v->c messages + float *qra_c2vmsg=pdata->qra_c2vmsg; // table of the c->v messages + float *rp=pdata->rp; // received samples (real component) + float *rq=pdata->rq; // received samples (imag component) + float *chp=pdata->chp; // channel gains (real component) + float *chq=pdata->chq; // channel gains (imag component) + float *r=pdata->r; // received samples amplitudes + float *ix=pdata->ix; // intrinsic information to the MP algorithm + float *ex=pdata->ex; // extrinsic information from the MP algorithm + + channel_type = pdata->channel_type; + code_type = pcode->type; + + // define the (true) code rate accordingly to the code type + switch(code_type) { + case QRATYPE_CRC: + R = 1.0f*(qra_K-1)/qra_N; + break; + case QRATYPE_CRCPUNCTURED: + R = 1.0f*(qra_K-1)/(qra_N-1); + break; + case QRATYPE_NORMAL: + default: + R = 1.0f*(qra_K)/(qra_N); + } + + EsNoMetric = 1.0f*qra_m*R*EbNoMetric; + + EbNo = (float)pow(10,pdata->EbNodB/10); + EsNo = 1.0f*qra_m*R*EbNo; + Es = EsNo*No; + A = (float)sqrt(Es); + + + // encode the input + if (code_type==QRATYPE_CRC || code_type==QRATYPE_CRCPUNCTURED) { + // compute the information message symbol check as the (negated) xor of all the + // information message symbols + for (k=0;k<(qra_K-1);k++) + x[k]=k%qra_M; + x[k]=calc_crc6(x,qra_K-1); + } + else + for (k=0;kstop==0) { + + // simulate the channel + // NOTE: in the case that the code is punctured, for simplicity + // we compute the channel outputs and the metric also for the crc symbol + // then we ignore its observation. + normrnd_s(rp,NSAMPLES,0,sigma); + normrnd_s(rq,NSAMPLES,0,sigma); + + if (channel_type == CHANNEL_AWGN) { + for (k=0;kdone = 1; + return; // unknown channel type + } + + // compute the squares of the amplitudes of the received samples + for (k=0;km,pcode->N,EsNoMetric); + + if (code_type==QRATYPE_CRCPUNCTURED) { + // ignore observations of the CRC symbol as it is not actually sent + // over the channel + pd_init(PD_ROWADDR(ix,qra_M,qra_K),pd_uniform(qra_m),qra_M); + } + + + if (pdata->ap_index!=0) + // mask channel observations with a priori knowledge + ix_mask(pcode,ix,ap_masks_jt65[pdata->ap_index],x); + + + // compute the extrinsic symbols probabilities with the message-passing algorithm + // stop if extrinsic information does not converges to 1 within the given number of iterations + rc = qra_extrinsic(pcode,ex,ix,100,qra_v2cmsg,qra_c2vmsg); + + if (rc>=0) { // the MP algorithm converged to Iex~1 in rc iterations + + // decode the codeword + qra_mapdecode(pcode,ydec,ex,ix); + + // look for undetected errors + if (code_type==QRATYPE_CRC || code_type==QRATYPE_CRCPUNCTURED) { + + j = 0; diff = 0; + for (k=0;k<(qra_K-1);k++) + diff |= (ydec[k]!=x[k]); + t = calc_crc6(ydec,qra_K-1); + if (t!=ydec[k]) // error detected - crc doesn't matches + nerrs += 1; + else + if (diff) { // decoded message is not equal to the transmitted one but + // the crc test passed + // add as undetected error + nerrsu += 1; + nerrs += 1; + // uncomment to see what the undetected error pattern looks like + //printword("U", ydec); + } + } + else + for (k=0;knt=nt; + pdata->nerrs=nerrs; + pdata->nerrsu=nerrsu; + + } + + pdata->done=1; + + #if _WIN32 + _endthread(); + #endif +} + +#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) ) + +void *wer_test_pthread(void *p) +{ + wer_test_thread ((wer_test_ds *)p); + return 0; +} + +#endif + +void ix_mask(const qracode *pcode, float *r, const int *mask, const int *x) +{ + // mask intrinsic information (channel observations) with a priori knowledge + + int k,kk, smask; + const int qra_K=pcode->K; + const int qra_M=pcode->M; + const int qra_m=pcode->m; + + for (k=0;kNTHREADS_MAX) { + printf("Error: nthreads should be <=%d\n",NTHREADS_MAX); + return -1; + } + + sprintf(fnameout,"%s%s%s", + fnameout_pfx[chtype], + pcode->name, + fnameout_sfx[ap_index]); + + fout = fopen(fnameout,"w"); + fprintf(fout,"# Channel (0=AWGN,1=Rayleigh), Eb/No (dB), Transmitted codewords, Errors, Undetected Errors, Avg dec. time (ms), WER\n"); + + printf("\nTesting the code %s over the %s channel\nSimulation data will be saved to %s\n", + pcode->name, + chtype==CHANNEL_AWGN?"AWGN":"Rayleigh", + fnameout); + fflush (stdout); + + // init fixed thread parameters and preallocate buffers + for (j=0;jK*sizeof(int)); + wt[j].y = (int*)malloc(pcode->N*sizeof(int)); + wt[j].ydec = (int*)malloc(pcode->N*sizeof(int)); + wt[j].qra_v2cmsg = (float*)malloc(pcode->NMSG*pcode->M*sizeof(float)); + wt[j].qra_c2vmsg = (float*)malloc(pcode->NMSG*pcode->M*sizeof(float)); + wt[j].rp = (float*)malloc(pcode->N*pcode->M*sizeof(float)); + wt[j].rq = (float*)malloc(pcode->N*pcode->M*sizeof(float)); + wt[j].chp = (float*)malloc(pcode->N*sizeof(float)); + wt[j].chq = (float*)malloc(pcode->N*sizeof(float)); + wt[j].r = (float*)malloc(pcode->N*pcode->M*sizeof(float)); + wt[j].ix = (float*)malloc(pcode->N*pcode->M*sizeof(float)); + wt[j].ex = (float*)malloc(pcode->N*pcode->M*sizeof(float)); + } + + + for (k=0;k=nerrstgt[k]) { + for (j=0;j] [-t] [-c] [-a] [-f[-h]\n"); + printf("Options: \n"); + printf(" -q: code to simulate. 0=qra_12_63_64_irr_b\n"); + printf(" 1=qra_13_64_64_irr_e (default)\n"); + printf(" -t : number of threads to be used for the simulation [1..24]\n"); + printf(" (default=8)\n"); + printf(" -c : channel_type. 0=AWGN 1=Rayleigh \n"); + printf(" (default=AWGN)\n"); + printf(" -a : amount of a-priori information provided to decoder. \n"); + printf(" 0= No a-priori (default)\n"); + printf(" 1= 28 bit \n"); + printf(" 2= 44 bit \n"); + printf(" 3= 56 bit \n"); + printf(" -f : name of the file containing the Eb/No values to be simulated\n"); + printf(" (default=ebnovalues.txt)\n"); + printf(" This file should contain lines in this format:\n"); + printf(" # Eb/No(dB) Target Errors\n"); + printf(" 0.1 5000\n"); + printf(" 0.6 5000\n"); + printf(" 1.1 1000\n"); + printf(" 1.6 1000\n"); + printf(" ...\n"); + printf(" (lines beginning with a # are treated as comments\n\n"); +} + +#define SIM_POINTS_MAX 20 + +int main(int argc, char* argv[]) +{ + + float EbNodB[SIM_POINTS_MAX]; + int nerrstgt[SIM_POINTS_MAX]; + FILE *fin; + + char fnamein[128]= "ebnovalues.txt"; + char buf[128]; + + int nitems = 0; + int code_idx = 1; + int nthreads = 8; + int ch_type = CHANNEL_AWGN; + int ap_index = AP_NONE; + + // parse command line + while(--argc) { + argv++; + if (strncmp(*argv,"-h",2)==0) { + syntax(); + return 0; + } + else + if (strncmp(*argv,"-q",2)==0) { + code_idx = (int)atoi((*argv)+2); + if (code_idx>1) { + printf("Invalid code index\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-t",2)==0) { + nthreads = (int)atoi((*argv)+2); + printf("nthreads = %d\n",nthreads); + if (nthreads>NTHREADS_MAX) { + printf("Invalid number of threads\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-c",2)==0) { + ch_type = (int)atoi((*argv)+2); + if (ch_type>CHANNEL_RAYLEIGH) { + printf("Invalid channel type\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-a",2)==0) { + ap_index = (int)atoi((*argv)+2); + if (ap_index>AP_56) { + printf("Invalid a-priori information index\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-f",2)==0) { + strncpy(fnamein,(*argv)+2,127); + } + else + if (strncmp(*argv,"-h",2)==0) { + syntax(); + return -1; + } + else { + printf("Invalid option\n"); + syntax(); + return -1; + } + } + + // parse points to be simulated from the input file + fin = fopen(fnamein,"r"); + if (!fin) { + printf("Can't open file: %s\n",fnamein); + syntax(); + } + + while (fgets(buf,128,fin)!=0) + if (*buf=='#' || *buf=='\n' ) + continue; + else + if (nitems==SIM_POINTS_MAX) + break; + else + if (sscanf(buf,"%f %u",&EbNodB[nitems],&nerrstgt[nitems])!=2) { + printf("Invalid input file format\n"); + syntax(); + return -1; + } + else + nitems++; + + fclose(fin); + + if (nitems==0) { + printf("No Eb/No point specified in file %s\n",fnamein); + syntax(); + return -1; + } + + printf("\nQ-ary Repeat-Accumulate Code Word Error Rate Simulator\n"); + printf("2016, Nico Palermo - IV3NWV\n\n"); + + printf("Nthreads = %d\n",nthreads); + printf("Channel = %s\n",ch_type==CHANNEL_AWGN?"AWGN":"Rayleigh"); + printf("Codename = %s\n",codetotest[code_idx]->name); + printf("A-priori = %s\n",ap_str[ap_index]); + printf("Eb/No input file = %s\n\n",fnamein); + + wer_test_proc(codetotest[code_idx], nthreads, ch_type, ap_index, EbNodB, nerrstgt, nitems); + + return 0; +} + diff --git a/lib/qra/qracodes/normrnd.c b/lib/qra/qracodes/normrnd.c index d30765ec..90abfa42 100755 --- a/lib/qra/qracodes/normrnd.c +++ b/lib/qra/qracodes/normrnd.c @@ -1,82 +1,82 @@ -// normrnd.c -// functions to generate gaussian distributed numbers -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// -// Credits to Andrea Montefusco - IW0HDV for his help on adapting the sources -// to OSs other than MS Windows -// -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - - -#include "normrnd.h" - -#if _WIN32 // note the underscore: without it, it's not msdn official! - // Windows (x64 and x86) - #include // required only for GetTickCount(...) - #define K_RAND_MAX UINT_MAX -#elif _SVID_SOURCE || _XOPEN_SOURCE || __unix__ || (defined (__APPLE__) && defined(__MACH__)) /* POSIX or Unix or Apple */ - #include - #define rand_s(x) (*x)=(unsigned int)lrand48() // returns unsigned integers in the range 0..0x7FFFFFFF - #define K_RAND_MAX 0x7FFFFFFF // that's the max number - // generated by lrand48 -#else - #error "No good quality PRNG found" -#endif - - -// use MS rand_s(...) function -void normrnd_s(float *dst, int nitems, float mean, float stdev) -{ - unsigned int r; - float phi=0, u=0; - int set = 0; - - while (nitems--) - if (set==1) { - *dst++ = (float)sin(phi)*u*stdev+mean; - set = 0; - } - else { - rand_s((unsigned int*)&r); phi = (M_2PI/(1.0f+K_RAND_MAX))*r; - rand_s((unsigned int*)&r); u = (float)sqrt(-2.0f* log( (1.0f/(1.0f+K_RAND_MAX))*(1.0f+r) ) ); - *dst++ = (float)cos(phi)*u*stdev+mean; - set=1; - } -} - -/* NOT USED -// use MS rand() function -void normrnd(float *dst, int nitems, float mean, float stdev) -{ - float phi=0, u=0; - int set = 0; - - while (nitems--) - if (set==1) { - *dst++ = (float)sin(phi)*u*stdev+mean; - set = 0; - } - else { - phi = (M_2PI/(1.0f+RAND_MAX))*rand(); - u = (float)sqrt(-2.0f* log( (1.0f/(1.0f+RAND_MAX))*(1.0f+rand()) ) ); - *dst++ = (float)cos(phi)*u*stdev+mean; - set=1; - } -} -*/ +// normrnd.c +// functions to generate gaussian distributed numbers +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// +// Credits to Andrea Montefusco - IW0HDV for his help on adapting the sources +// to OSs other than MS Windows +// +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + + +#include "normrnd.h" + +#if _WIN32 // note the underscore: without it, it's not msdn official! + // Windows (x64 and x86) + #include // required only for GetTickCount(...) + #define K_RAND_MAX UINT_MAX +#elif _SVID_SOURCE || _XOPEN_SOURCE || __unix__ || (defined (__APPLE__) && defined(__MACH__)) /* POSIX or Unix or Apple */ + #include + #define rand_s(x) (*x)=(unsigned int)lrand48() // returns unsigned integers in the range 0..0x7FFFFFFF + #define K_RAND_MAX 0x7FFFFFFF // that's the max number + // generated by lrand48 +#else + #error "No good quality PRNG found" +#endif + + +// use MS rand_s(...) function +void normrnd_s(float *dst, int nitems, float mean, float stdev) +{ + unsigned int r; + float phi=0, u=0; + int set = 0; + + while (nitems--) + if (set==1) { + *dst++ = (float)sin(phi)*u*stdev+mean; + set = 0; + } + else { + rand_s((unsigned int*)&r); phi = (M_2PI/(1.0f+K_RAND_MAX))*r; + rand_s((unsigned int*)&r); u = (float)sqrt(-2.0f* log( (1.0f/(1.0f+K_RAND_MAX))*(1.0f+r) ) ); + *dst++ = (float)cos(phi)*u*stdev+mean; + set=1; + } +} + +/* NOT USED +// use MS rand() function +void normrnd(float *dst, int nitems, float mean, float stdev) +{ + float phi=0, u=0; + int set = 0; + + while (nitems--) + if (set==1) { + *dst++ = (float)sin(phi)*u*stdev+mean; + set = 0; + } + else { + phi = (M_2PI/(1.0f+RAND_MAX))*rand(); + u = (float)sqrt(-2.0f* log( (1.0f/(1.0f+RAND_MAX))*(1.0f+rand()) ) ); + *dst++ = (float)cos(phi)*u*stdev+mean; + set=1; + } +} +*/ diff --git a/lib/qra/qracodes/normrnd.h b/lib/qra/qracodes/normrnd.h index 04bbf01a..dd4b65bb 100755 --- a/lib/qra/qracodes/normrnd.h +++ b/lib/qra/qracodes/normrnd.h @@ -1,51 +1,51 @@ -// normrnd.h -// Functions to generate gaussian distributed numbers -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#ifndef _normrnd_h_ -#define _normrnd_h_ - -#define _CRT_RAND_S -#include - -#define _USE_MATH_DEFINES -#include -#define M_2PI (2.0f*(float)M_PI) - -#ifdef __cplusplus -extern "C" { -#endif - -void normrnd_s(float *dst, int nitems, float mean, float stdev); -// generate a random array of numbers with a gaussian distribution of given mean and stdev -// use MS rand_s(...) function - -/* not used -void normrnd(float *dst, int nitems, float mean, float stdev); -// generate a random array of numbers with a gaussian distribution of given mean and stdev -// use MS rand() function -*/ - -#ifdef __cplusplus -} -#endif - -#endif // _normrnd_h_ - +// normrnd.h +// Functions to generate gaussian distributed numbers +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#ifndef _normrnd_h_ +#define _normrnd_h_ + +#define _CRT_RAND_S +#include + +#define _USE_MATH_DEFINES +#include +#define M_2PI (2.0f*(float)M_PI) + +#ifdef __cplusplus +extern "C" { +#endif + +void normrnd_s(float *dst, int nitems, float mean, float stdev); +// generate a random array of numbers with a gaussian distribution of given mean and stdev +// use MS rand_s(...) function + +/* not used +void normrnd(float *dst, int nitems, float mean, float stdev); +// generate a random array of numbers with a gaussian distribution of given mean and stdev +// use MS rand() function +*/ + +#ifdef __cplusplus +} +#endif + +#endif // _normrnd_h_ + diff --git a/lib/qra/qracodes/npfwht.c b/lib/qra/qracodes/npfwht.c index 0f8fa428..5732ce91 100755 --- a/lib/qra/qracodes/npfwht.c +++ b/lib/qra/qracodes/npfwht.c @@ -1,216 +1,216 @@ -// npfwht.c -// Basic implementation of the Fast Walsh-Hadamard Transforms -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#include "npfwht.h" - -#define WHBFY(dst,src,base,offs,dist) { dst[base+offs]=src[base+offs]+src[base+offs+dist]; dst[base+offs+dist]=src[base+offs]-src[base+offs+dist]; } - -typedef void (*pnp_fwht)(float*,float*); - -static void np_fwht2(float *dst, float *src); - -static void np_fwht1(float *dst, float *src); -static void np_fwht2(float *dst, float *src); -static void np_fwht4(float *dst, float *src); -static void np_fwht8(float *dst, float *src); -static void np_fwht16(float *dst, float *src); -static void np_fwht32(float *dst, float *src); -static void np_fwht64(float *dst, float *src); - -static pnp_fwht np_fwht_tab[7] = { - np_fwht1, - np_fwht2, - np_fwht4, - np_fwht8, - np_fwht16, - np_fwht32, - np_fwht64 -}; - -void np_fwht(int nlogdim, float *dst, float *src) -{ - np_fwht_tab[nlogdim](dst,src); -} - -static void np_fwht1(float *dst, float *src) -{ - dst[0] = src[0]; -} - - -static void np_fwht2(float *dst, float *src) -{ - float t[2]; - - WHBFY(t,src,0,0,1); - dst[0]= t[0]; - dst[1]= t[1]; -} - -static void np_fwht4(float *dst, float *src) -{ - float t[4]; - - // group 1 - WHBFY(t,src,0,0,2); WHBFY(t,src,0,1,2); - // group 2 - WHBFY(dst,t,0,0,1); WHBFY(dst,t,2,0,1); -}; - - -static void np_fwht8(float *dst, float *src) -{ - float t[16]; - float *t1=t, *t2=t+8; - - // group 1 - WHBFY(t1,src,0,0,4); WHBFY(t1,src,0,1,4); WHBFY(t1,src,0,2,4); WHBFY(t1,src,0,3,4); - // group 2 - WHBFY(t2,t1,0,0,2); WHBFY(t2,t1,0,1,2); WHBFY(t2,t1,4,0,2); WHBFY(t2,t1,4,1,2); - // group 3 - WHBFY(dst,t2,0,0,1); WHBFY(dst,t2,2,0,1); WHBFY(dst,t2,4,0,1); WHBFY(dst,t2,6,0,1); -}; - - -static void np_fwht16(float *dst, float *src) -{ - float t[32]; - float *t1=t, *t2=t+16; - - // group 1 - WHBFY(t1,src,0,0,8); WHBFY(t1,src,0,1,8); WHBFY(t1,src,0,2,8); WHBFY(t1,src,0,3,8); - WHBFY(t1,src,0,4,8); WHBFY(t1,src,0,5,8); WHBFY(t1,src,0,6,8); WHBFY(t1,src,0,7,8); - // group 2 - WHBFY(t2,t1,0,0,4); WHBFY(t2,t1,0,1,4); WHBFY(t2,t1,0,2,4); WHBFY(t2,t1,0,3,4); - WHBFY(t2,t1,8,0,4); WHBFY(t2,t1,8,1,4); WHBFY(t2,t1,8,2,4); WHBFY(t2,t1,8,3,4); - // group 3 - WHBFY(t1,t2,0,0,2); WHBFY(t1,t2,0,1,2); WHBFY(t1,t2,4,0,2); WHBFY(t1,t2,4,1,2); - WHBFY(t1,t2,8,0,2); WHBFY(t1,t2,8,1,2); WHBFY(t1,t2,12,0,2); WHBFY(t1,t2,12,1,2); - // group 4 - WHBFY(dst,t1,0,0,1); WHBFY(dst,t1,2,0,1); WHBFY(dst,t1,4,0,1); WHBFY(dst,t1,6,0,1); - WHBFY(dst,t1,8,0,1); WHBFY(dst,t1,10,0,1); WHBFY(dst,t1,12,0,1); WHBFY(dst,t1,14,0,1); - -} - -static void np_fwht32(float *dst, float *src) -{ - float t[64]; - float *t1=t, *t2=t+32; - - // group 1 - WHBFY(t1,src,0,0,16); WHBFY(t1,src,0,1,16); WHBFY(t1,src,0,2,16); WHBFY(t1,src,0,3,16); - WHBFY(t1,src,0,4,16); WHBFY(t1,src,0,5,16); WHBFY(t1,src,0,6,16); WHBFY(t1,src,0,7,16); - WHBFY(t1,src,0,8,16); WHBFY(t1,src,0,9,16); WHBFY(t1,src,0,10,16); WHBFY(t1,src,0,11,16); - WHBFY(t1,src,0,12,16); WHBFY(t1,src,0,13,16); WHBFY(t1,src,0,14,16); WHBFY(t1,src,0,15,16); - - // group 2 - WHBFY(t2,t1,0,0,8); WHBFY(t2,t1,0,1,8); WHBFY(t2,t1,0,2,8); WHBFY(t2,t1,0,3,8); - WHBFY(t2,t1,0,4,8); WHBFY(t2,t1,0,5,8); WHBFY(t2,t1,0,6,8); WHBFY(t2,t1,0,7,8); - WHBFY(t2,t1,16,0,8); WHBFY(t2,t1,16,1,8); WHBFY(t2,t1,16,2,8); WHBFY(t2,t1,16,3,8); - WHBFY(t2,t1,16,4,8); WHBFY(t2,t1,16,5,8); WHBFY(t2,t1,16,6,8); WHBFY(t2,t1,16,7,8); - - // group 3 - WHBFY(t1,t2,0,0,4); WHBFY(t1,t2,0,1,4); WHBFY(t1,t2,0,2,4); WHBFY(t1,t2,0,3,4); - WHBFY(t1,t2,8,0,4); WHBFY(t1,t2,8,1,4); WHBFY(t1,t2,8,2,4); WHBFY(t1,t2,8,3,4); - WHBFY(t1,t2,16,0,4); WHBFY(t1,t2,16,1,4); WHBFY(t1,t2,16,2,4); WHBFY(t1,t2,16,3,4); - WHBFY(t1,t2,24,0,4); WHBFY(t1,t2,24,1,4); WHBFY(t1,t2,24,2,4); WHBFY(t1,t2,24,3,4); - - // group 4 - WHBFY(t2,t1,0,0,2); WHBFY(t2,t1,0,1,2); WHBFY(t2,t1,4,0,2); WHBFY(t2,t1,4,1,2); - WHBFY(t2,t1,8,0,2); WHBFY(t2,t1,8,1,2); WHBFY(t2,t1,12,0,2); WHBFY(t2,t1,12,1,2); - WHBFY(t2,t1,16,0,2); WHBFY(t2,t1,16,1,2); WHBFY(t2,t1,20,0,2); WHBFY(t2,t1,20,1,2); - WHBFY(t2,t1,24,0,2); WHBFY(t2,t1,24,1,2); WHBFY(t2,t1,28,0,2); WHBFY(t2,t1,28,1,2); - - // group 5 - WHBFY(dst,t2,0,0,1); WHBFY(dst,t2,2,0,1); WHBFY(dst,t2,4,0,1); WHBFY(dst,t2,6,0,1); - WHBFY(dst,t2,8,0,1); WHBFY(dst,t2,10,0,1); WHBFY(dst,t2,12,0,1); WHBFY(dst,t2,14,0,1); - WHBFY(dst,t2,16,0,1); WHBFY(dst,t2,18,0,1); WHBFY(dst,t2,20,0,1); WHBFY(dst,t2,22,0,1); - WHBFY(dst,t2,24,0,1); WHBFY(dst,t2,26,0,1); WHBFY(dst,t2,28,0,1); WHBFY(dst,t2,30,0,1); - -} - -static void np_fwht64(float *dst, float *src) -{ - float t[128]; - float *t1=t, *t2=t+64; - - - // group 1 - WHBFY(t1,src,0,0,32); WHBFY(t1,src,0,1,32); WHBFY(t1,src,0,2,32); WHBFY(t1,src,0,3,32); - WHBFY(t1,src,0,4,32); WHBFY(t1,src,0,5,32); WHBFY(t1,src,0,6,32); WHBFY(t1,src,0,7,32); - WHBFY(t1,src,0,8,32); WHBFY(t1,src,0,9,32); WHBFY(t1,src,0,10,32); WHBFY(t1,src,0,11,32); - WHBFY(t1,src,0,12,32); WHBFY(t1,src,0,13,32); WHBFY(t1,src,0,14,32); WHBFY(t1,src,0,15,32); - WHBFY(t1,src,0,16,32); WHBFY(t1,src,0,17,32); WHBFY(t1,src,0,18,32); WHBFY(t1,src,0,19,32); - WHBFY(t1,src,0,20,32); WHBFY(t1,src,0,21,32); WHBFY(t1,src,0,22,32); WHBFY(t1,src,0,23,32); - WHBFY(t1,src,0,24,32); WHBFY(t1,src,0,25,32); WHBFY(t1,src,0,26,32); WHBFY(t1,src,0,27,32); - WHBFY(t1,src,0,28,32); WHBFY(t1,src,0,29,32); WHBFY(t1,src,0,30,32); WHBFY(t1,src,0,31,32); - - // group 2 - WHBFY(t2,t1,0,0,16); WHBFY(t2,t1,0,1,16); WHBFY(t2,t1,0,2,16); WHBFY(t2,t1,0,3,16); - WHBFY(t2,t1,0,4,16); WHBFY(t2,t1,0,5,16); WHBFY(t2,t1,0,6,16); WHBFY(t2,t1,0,7,16); - WHBFY(t2,t1,0,8,16); WHBFY(t2,t1,0,9,16); WHBFY(t2,t1,0,10,16); WHBFY(t2,t1,0,11,16); - WHBFY(t2,t1,0,12,16); WHBFY(t2,t1,0,13,16); WHBFY(t2,t1,0,14,16); WHBFY(t2,t1,0,15,16); - - WHBFY(t2,t1,32,0,16); WHBFY(t2,t1,32,1,16); WHBFY(t2,t1,32,2,16); WHBFY(t2,t1,32,3,16); - WHBFY(t2,t1,32,4,16); WHBFY(t2,t1,32,5,16); WHBFY(t2,t1,32,6,16); WHBFY(t2,t1,32,7,16); - WHBFY(t2,t1,32,8,16); WHBFY(t2,t1,32,9,16); WHBFY(t2,t1,32,10,16); WHBFY(t2,t1,32,11,16); - WHBFY(t2,t1,32,12,16); WHBFY(t2,t1,32,13,16); WHBFY(t2,t1,32,14,16); WHBFY(t2,t1,32,15,16); - - // group 3 - WHBFY(t1,t2,0,0,8); WHBFY(t1,t2,0,1,8); WHBFY(t1,t2,0,2,8); WHBFY(t1,t2,0,3,8); - WHBFY(t1,t2,0,4,8); WHBFY(t1,t2,0,5,8); WHBFY(t1,t2,0,6,8); WHBFY(t1,t2,0,7,8); - WHBFY(t1,t2,16,0,8); WHBFY(t1,t2,16,1,8); WHBFY(t1,t2,16,2,8); WHBFY(t1,t2,16,3,8); - WHBFY(t1,t2,16,4,8); WHBFY(t1,t2,16,5,8); WHBFY(t1,t2,16,6,8); WHBFY(t1,t2,16,7,8); - WHBFY(t1,t2,32,0,8); WHBFY(t1,t2,32,1,8); WHBFY(t1,t2,32,2,8); WHBFY(t1,t2,32,3,8); - WHBFY(t1,t2,32,4,8); WHBFY(t1,t2,32,5,8); WHBFY(t1,t2,32,6,8); WHBFY(t1,t2,32,7,8); - WHBFY(t1,t2,48,0,8); WHBFY(t1,t2,48,1,8); WHBFY(t1,t2,48,2,8); WHBFY(t1,t2,48,3,8); - WHBFY(t1,t2,48,4,8); WHBFY(t1,t2,48,5,8); WHBFY(t1,t2,48,6,8); WHBFY(t1,t2,48,7,8); - - // group 4 - WHBFY(t2,t1,0,0,4); WHBFY(t2,t1,0,1,4); WHBFY(t2,t1,0,2,4); WHBFY(t2,t1,0,3,4); - WHBFY(t2,t1,8,0,4); WHBFY(t2,t1,8,1,4); WHBFY(t2,t1,8,2,4); WHBFY(t2,t1,8,3,4); - WHBFY(t2,t1,16,0,4); WHBFY(t2,t1,16,1,4); WHBFY(t2,t1,16,2,4); WHBFY(t2,t1,16,3,4); - WHBFY(t2,t1,24,0,4); WHBFY(t2,t1,24,1,4); WHBFY(t2,t1,24,2,4); WHBFY(t2,t1,24,3,4); - WHBFY(t2,t1,32,0,4); WHBFY(t2,t1,32,1,4); WHBFY(t2,t1,32,2,4); WHBFY(t2,t1,32,3,4); - WHBFY(t2,t1,40,0,4); WHBFY(t2,t1,40,1,4); WHBFY(t2,t1,40,2,4); WHBFY(t2,t1,40,3,4); - WHBFY(t2,t1,48,0,4); WHBFY(t2,t1,48,1,4); WHBFY(t2,t1,48,2,4); WHBFY(t2,t1,48,3,4); - WHBFY(t2,t1,56,0,4); WHBFY(t2,t1,56,1,4); WHBFY(t2,t1,56,2,4); WHBFY(t2,t1,56,3,4); - - // group 5 - WHBFY(t1,t2,0,0,2); WHBFY(t1,t2,0,1,2); WHBFY(t1,t2,4,0,2); WHBFY(t1,t2,4,1,2); - WHBFY(t1,t2,8,0,2); WHBFY(t1,t2,8,1,2); WHBFY(t1,t2,12,0,2); WHBFY(t1,t2,12,1,2); - WHBFY(t1,t2,16,0,2); WHBFY(t1,t2,16,1,2); WHBFY(t1,t2,20,0,2); WHBFY(t1,t2,20,1,2); - WHBFY(t1,t2,24,0,2); WHBFY(t1,t2,24,1,2); WHBFY(t1,t2,28,0,2); WHBFY(t1,t2,28,1,2); - WHBFY(t1,t2,32,0,2); WHBFY(t1,t2,32,1,2); WHBFY(t1,t2,36,0,2); WHBFY(t1,t2,36,1,2); - WHBFY(t1,t2,40,0,2); WHBFY(t1,t2,40,1,2); WHBFY(t1,t2,44,0,2); WHBFY(t1,t2,44,1,2); - WHBFY(t1,t2,48,0,2); WHBFY(t1,t2,48,1,2); WHBFY(t1,t2,52,0,2); WHBFY(t1,t2,52,1,2); - WHBFY(t1,t2,56,0,2); WHBFY(t1,t2,56,1,2); WHBFY(t1,t2,60,0,2); WHBFY(t1,t2,60,1,2); - - // group 6 - WHBFY(dst,t1,0,0,1); WHBFY(dst,t1,2,0,1); WHBFY(dst,t1,4,0,1); WHBFY(dst,t1,6,0,1); - WHBFY(dst,t1,8,0,1); WHBFY(dst,t1,10,0,1); WHBFY(dst,t1,12,0,1); WHBFY(dst,t1,14,0,1); - WHBFY(dst,t1,16,0,1); WHBFY(dst,t1,18,0,1); WHBFY(dst,t1,20,0,1); WHBFY(dst,t1,22,0,1); - WHBFY(dst,t1,24,0,1); WHBFY(dst,t1,26,0,1); WHBFY(dst,t1,28,0,1); WHBFY(dst,t1,30,0,1); - WHBFY(dst,t1,32,0,1); WHBFY(dst,t1,34,0,1); WHBFY(dst,t1,36,0,1); WHBFY(dst,t1,38,0,1); - WHBFY(dst,t1,40,0,1); WHBFY(dst,t1,42,0,1); WHBFY(dst,t1,44,0,1); WHBFY(dst,t1,46,0,1); - WHBFY(dst,t1,48,0,1); WHBFY(dst,t1,50,0,1); WHBFY(dst,t1,52,0,1); WHBFY(dst,t1,54,0,1); - WHBFY(dst,t1,56,0,1); WHBFY(dst,t1,58,0,1); WHBFY(dst,t1,60,0,1); WHBFY(dst,t1,62,0,1); +// npfwht.c +// Basic implementation of the Fast Walsh-Hadamard Transforms +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#include "npfwht.h" + +#define WHBFY(dst,src,base,offs,dist) { dst[base+offs]=src[base+offs]+src[base+offs+dist]; dst[base+offs+dist]=src[base+offs]-src[base+offs+dist]; } + +typedef void (*pnp_fwht)(float*,float*); + +static void np_fwht2(float *dst, float *src); + +static void np_fwht1(float *dst, float *src); +static void np_fwht2(float *dst, float *src); +static void np_fwht4(float *dst, float *src); +static void np_fwht8(float *dst, float *src); +static void np_fwht16(float *dst, float *src); +static void np_fwht32(float *dst, float *src); +static void np_fwht64(float *dst, float *src); + +static pnp_fwht np_fwht_tab[7] = { + np_fwht1, + np_fwht2, + np_fwht4, + np_fwht8, + np_fwht16, + np_fwht32, + np_fwht64 +}; + +void np_fwht(int nlogdim, float *dst, float *src) +{ + np_fwht_tab[nlogdim](dst,src); +} + +static void np_fwht1(float *dst, float *src) +{ + dst[0] = src[0]; +} + + +static void np_fwht2(float *dst, float *src) +{ + float t[2]; + + WHBFY(t,src,0,0,1); + dst[0]= t[0]; + dst[1]= t[1]; +} + +static void np_fwht4(float *dst, float *src) +{ + float t[4]; + + // group 1 + WHBFY(t,src,0,0,2); WHBFY(t,src,0,1,2); + // group 2 + WHBFY(dst,t,0,0,1); WHBFY(dst,t,2,0,1); +}; + + +static void np_fwht8(float *dst, float *src) +{ + float t[16]; + float *t1=t, *t2=t+8; + + // group 1 + WHBFY(t1,src,0,0,4); WHBFY(t1,src,0,1,4); WHBFY(t1,src,0,2,4); WHBFY(t1,src,0,3,4); + // group 2 + WHBFY(t2,t1,0,0,2); WHBFY(t2,t1,0,1,2); WHBFY(t2,t1,4,0,2); WHBFY(t2,t1,4,1,2); + // group 3 + WHBFY(dst,t2,0,0,1); WHBFY(dst,t2,2,0,1); WHBFY(dst,t2,4,0,1); WHBFY(dst,t2,6,0,1); +}; + + +static void np_fwht16(float *dst, float *src) +{ + float t[32]; + float *t1=t, *t2=t+16; + + // group 1 + WHBFY(t1,src,0,0,8); WHBFY(t1,src,0,1,8); WHBFY(t1,src,0,2,8); WHBFY(t1,src,0,3,8); + WHBFY(t1,src,0,4,8); WHBFY(t1,src,0,5,8); WHBFY(t1,src,0,6,8); WHBFY(t1,src,0,7,8); + // group 2 + WHBFY(t2,t1,0,0,4); WHBFY(t2,t1,0,1,4); WHBFY(t2,t1,0,2,4); WHBFY(t2,t1,0,3,4); + WHBFY(t2,t1,8,0,4); WHBFY(t2,t1,8,1,4); WHBFY(t2,t1,8,2,4); WHBFY(t2,t1,8,3,4); + // group 3 + WHBFY(t1,t2,0,0,2); WHBFY(t1,t2,0,1,2); WHBFY(t1,t2,4,0,2); WHBFY(t1,t2,4,1,2); + WHBFY(t1,t2,8,0,2); WHBFY(t1,t2,8,1,2); WHBFY(t1,t2,12,0,2); WHBFY(t1,t2,12,1,2); + // group 4 + WHBFY(dst,t1,0,0,1); WHBFY(dst,t1,2,0,1); WHBFY(dst,t1,4,0,1); WHBFY(dst,t1,6,0,1); + WHBFY(dst,t1,8,0,1); WHBFY(dst,t1,10,0,1); WHBFY(dst,t1,12,0,1); WHBFY(dst,t1,14,0,1); + +} + +static void np_fwht32(float *dst, float *src) +{ + float t[64]; + float *t1=t, *t2=t+32; + + // group 1 + WHBFY(t1,src,0,0,16); WHBFY(t1,src,0,1,16); WHBFY(t1,src,0,2,16); WHBFY(t1,src,0,3,16); + WHBFY(t1,src,0,4,16); WHBFY(t1,src,0,5,16); WHBFY(t1,src,0,6,16); WHBFY(t1,src,0,7,16); + WHBFY(t1,src,0,8,16); WHBFY(t1,src,0,9,16); WHBFY(t1,src,0,10,16); WHBFY(t1,src,0,11,16); + WHBFY(t1,src,0,12,16); WHBFY(t1,src,0,13,16); WHBFY(t1,src,0,14,16); WHBFY(t1,src,0,15,16); + + // group 2 + WHBFY(t2,t1,0,0,8); WHBFY(t2,t1,0,1,8); WHBFY(t2,t1,0,2,8); WHBFY(t2,t1,0,3,8); + WHBFY(t2,t1,0,4,8); WHBFY(t2,t1,0,5,8); WHBFY(t2,t1,0,6,8); WHBFY(t2,t1,0,7,8); + WHBFY(t2,t1,16,0,8); WHBFY(t2,t1,16,1,8); WHBFY(t2,t1,16,2,8); WHBFY(t2,t1,16,3,8); + WHBFY(t2,t1,16,4,8); WHBFY(t2,t1,16,5,8); WHBFY(t2,t1,16,6,8); WHBFY(t2,t1,16,7,8); + + // group 3 + WHBFY(t1,t2,0,0,4); WHBFY(t1,t2,0,1,4); WHBFY(t1,t2,0,2,4); WHBFY(t1,t2,0,3,4); + WHBFY(t1,t2,8,0,4); WHBFY(t1,t2,8,1,4); WHBFY(t1,t2,8,2,4); WHBFY(t1,t2,8,3,4); + WHBFY(t1,t2,16,0,4); WHBFY(t1,t2,16,1,4); WHBFY(t1,t2,16,2,4); WHBFY(t1,t2,16,3,4); + WHBFY(t1,t2,24,0,4); WHBFY(t1,t2,24,1,4); WHBFY(t1,t2,24,2,4); WHBFY(t1,t2,24,3,4); + + // group 4 + WHBFY(t2,t1,0,0,2); WHBFY(t2,t1,0,1,2); WHBFY(t2,t1,4,0,2); WHBFY(t2,t1,4,1,2); + WHBFY(t2,t1,8,0,2); WHBFY(t2,t1,8,1,2); WHBFY(t2,t1,12,0,2); WHBFY(t2,t1,12,1,2); + WHBFY(t2,t1,16,0,2); WHBFY(t2,t1,16,1,2); WHBFY(t2,t1,20,0,2); WHBFY(t2,t1,20,1,2); + WHBFY(t2,t1,24,0,2); WHBFY(t2,t1,24,1,2); WHBFY(t2,t1,28,0,2); WHBFY(t2,t1,28,1,2); + + // group 5 + WHBFY(dst,t2,0,0,1); WHBFY(dst,t2,2,0,1); WHBFY(dst,t2,4,0,1); WHBFY(dst,t2,6,0,1); + WHBFY(dst,t2,8,0,1); WHBFY(dst,t2,10,0,1); WHBFY(dst,t2,12,0,1); WHBFY(dst,t2,14,0,1); + WHBFY(dst,t2,16,0,1); WHBFY(dst,t2,18,0,1); WHBFY(dst,t2,20,0,1); WHBFY(dst,t2,22,0,1); + WHBFY(dst,t2,24,0,1); WHBFY(dst,t2,26,0,1); WHBFY(dst,t2,28,0,1); WHBFY(dst,t2,30,0,1); + +} + +static void np_fwht64(float *dst, float *src) +{ + float t[128]; + float *t1=t, *t2=t+64; + + + // group 1 + WHBFY(t1,src,0,0,32); WHBFY(t1,src,0,1,32); WHBFY(t1,src,0,2,32); WHBFY(t1,src,0,3,32); + WHBFY(t1,src,0,4,32); WHBFY(t1,src,0,5,32); WHBFY(t1,src,0,6,32); WHBFY(t1,src,0,7,32); + WHBFY(t1,src,0,8,32); WHBFY(t1,src,0,9,32); WHBFY(t1,src,0,10,32); WHBFY(t1,src,0,11,32); + WHBFY(t1,src,0,12,32); WHBFY(t1,src,0,13,32); WHBFY(t1,src,0,14,32); WHBFY(t1,src,0,15,32); + WHBFY(t1,src,0,16,32); WHBFY(t1,src,0,17,32); WHBFY(t1,src,0,18,32); WHBFY(t1,src,0,19,32); + WHBFY(t1,src,0,20,32); WHBFY(t1,src,0,21,32); WHBFY(t1,src,0,22,32); WHBFY(t1,src,0,23,32); + WHBFY(t1,src,0,24,32); WHBFY(t1,src,0,25,32); WHBFY(t1,src,0,26,32); WHBFY(t1,src,0,27,32); + WHBFY(t1,src,0,28,32); WHBFY(t1,src,0,29,32); WHBFY(t1,src,0,30,32); WHBFY(t1,src,0,31,32); + + // group 2 + WHBFY(t2,t1,0,0,16); WHBFY(t2,t1,0,1,16); WHBFY(t2,t1,0,2,16); WHBFY(t2,t1,0,3,16); + WHBFY(t2,t1,0,4,16); WHBFY(t2,t1,0,5,16); WHBFY(t2,t1,0,6,16); WHBFY(t2,t1,0,7,16); + WHBFY(t2,t1,0,8,16); WHBFY(t2,t1,0,9,16); WHBFY(t2,t1,0,10,16); WHBFY(t2,t1,0,11,16); + WHBFY(t2,t1,0,12,16); WHBFY(t2,t1,0,13,16); WHBFY(t2,t1,0,14,16); WHBFY(t2,t1,0,15,16); + + WHBFY(t2,t1,32,0,16); WHBFY(t2,t1,32,1,16); WHBFY(t2,t1,32,2,16); WHBFY(t2,t1,32,3,16); + WHBFY(t2,t1,32,4,16); WHBFY(t2,t1,32,5,16); WHBFY(t2,t1,32,6,16); WHBFY(t2,t1,32,7,16); + WHBFY(t2,t1,32,8,16); WHBFY(t2,t1,32,9,16); WHBFY(t2,t1,32,10,16); WHBFY(t2,t1,32,11,16); + WHBFY(t2,t1,32,12,16); WHBFY(t2,t1,32,13,16); WHBFY(t2,t1,32,14,16); WHBFY(t2,t1,32,15,16); + + // group 3 + WHBFY(t1,t2,0,0,8); WHBFY(t1,t2,0,1,8); WHBFY(t1,t2,0,2,8); WHBFY(t1,t2,0,3,8); + WHBFY(t1,t2,0,4,8); WHBFY(t1,t2,0,5,8); WHBFY(t1,t2,0,6,8); WHBFY(t1,t2,0,7,8); + WHBFY(t1,t2,16,0,8); WHBFY(t1,t2,16,1,8); WHBFY(t1,t2,16,2,8); WHBFY(t1,t2,16,3,8); + WHBFY(t1,t2,16,4,8); WHBFY(t1,t2,16,5,8); WHBFY(t1,t2,16,6,8); WHBFY(t1,t2,16,7,8); + WHBFY(t1,t2,32,0,8); WHBFY(t1,t2,32,1,8); WHBFY(t1,t2,32,2,8); WHBFY(t1,t2,32,3,8); + WHBFY(t1,t2,32,4,8); WHBFY(t1,t2,32,5,8); WHBFY(t1,t2,32,6,8); WHBFY(t1,t2,32,7,8); + WHBFY(t1,t2,48,0,8); WHBFY(t1,t2,48,1,8); WHBFY(t1,t2,48,2,8); WHBFY(t1,t2,48,3,8); + WHBFY(t1,t2,48,4,8); WHBFY(t1,t2,48,5,8); WHBFY(t1,t2,48,6,8); WHBFY(t1,t2,48,7,8); + + // group 4 + WHBFY(t2,t1,0,0,4); WHBFY(t2,t1,0,1,4); WHBFY(t2,t1,0,2,4); WHBFY(t2,t1,0,3,4); + WHBFY(t2,t1,8,0,4); WHBFY(t2,t1,8,1,4); WHBFY(t2,t1,8,2,4); WHBFY(t2,t1,8,3,4); + WHBFY(t2,t1,16,0,4); WHBFY(t2,t1,16,1,4); WHBFY(t2,t1,16,2,4); WHBFY(t2,t1,16,3,4); + WHBFY(t2,t1,24,0,4); WHBFY(t2,t1,24,1,4); WHBFY(t2,t1,24,2,4); WHBFY(t2,t1,24,3,4); + WHBFY(t2,t1,32,0,4); WHBFY(t2,t1,32,1,4); WHBFY(t2,t1,32,2,4); WHBFY(t2,t1,32,3,4); + WHBFY(t2,t1,40,0,4); WHBFY(t2,t1,40,1,4); WHBFY(t2,t1,40,2,4); WHBFY(t2,t1,40,3,4); + WHBFY(t2,t1,48,0,4); WHBFY(t2,t1,48,1,4); WHBFY(t2,t1,48,2,4); WHBFY(t2,t1,48,3,4); + WHBFY(t2,t1,56,0,4); WHBFY(t2,t1,56,1,4); WHBFY(t2,t1,56,2,4); WHBFY(t2,t1,56,3,4); + + // group 5 + WHBFY(t1,t2,0,0,2); WHBFY(t1,t2,0,1,2); WHBFY(t1,t2,4,0,2); WHBFY(t1,t2,4,1,2); + WHBFY(t1,t2,8,0,2); WHBFY(t1,t2,8,1,2); WHBFY(t1,t2,12,0,2); WHBFY(t1,t2,12,1,2); + WHBFY(t1,t2,16,0,2); WHBFY(t1,t2,16,1,2); WHBFY(t1,t2,20,0,2); WHBFY(t1,t2,20,1,2); + WHBFY(t1,t2,24,0,2); WHBFY(t1,t2,24,1,2); WHBFY(t1,t2,28,0,2); WHBFY(t1,t2,28,1,2); + WHBFY(t1,t2,32,0,2); WHBFY(t1,t2,32,1,2); WHBFY(t1,t2,36,0,2); WHBFY(t1,t2,36,1,2); + WHBFY(t1,t2,40,0,2); WHBFY(t1,t2,40,1,2); WHBFY(t1,t2,44,0,2); WHBFY(t1,t2,44,1,2); + WHBFY(t1,t2,48,0,2); WHBFY(t1,t2,48,1,2); WHBFY(t1,t2,52,0,2); WHBFY(t1,t2,52,1,2); + WHBFY(t1,t2,56,0,2); WHBFY(t1,t2,56,1,2); WHBFY(t1,t2,60,0,2); WHBFY(t1,t2,60,1,2); + + // group 6 + WHBFY(dst,t1,0,0,1); WHBFY(dst,t1,2,0,1); WHBFY(dst,t1,4,0,1); WHBFY(dst,t1,6,0,1); + WHBFY(dst,t1,8,0,1); WHBFY(dst,t1,10,0,1); WHBFY(dst,t1,12,0,1); WHBFY(dst,t1,14,0,1); + WHBFY(dst,t1,16,0,1); WHBFY(dst,t1,18,0,1); WHBFY(dst,t1,20,0,1); WHBFY(dst,t1,22,0,1); + WHBFY(dst,t1,24,0,1); WHBFY(dst,t1,26,0,1); WHBFY(dst,t1,28,0,1); WHBFY(dst,t1,30,0,1); + WHBFY(dst,t1,32,0,1); WHBFY(dst,t1,34,0,1); WHBFY(dst,t1,36,0,1); WHBFY(dst,t1,38,0,1); + WHBFY(dst,t1,40,0,1); WHBFY(dst,t1,42,0,1); WHBFY(dst,t1,44,0,1); WHBFY(dst,t1,46,0,1); + WHBFY(dst,t1,48,0,1); WHBFY(dst,t1,50,0,1); WHBFY(dst,t1,52,0,1); WHBFY(dst,t1,54,0,1); + WHBFY(dst,t1,56,0,1); WHBFY(dst,t1,58,0,1); WHBFY(dst,t1,60,0,1); WHBFY(dst,t1,62,0,1); } \ No newline at end of file diff --git a/lib/qra/qracodes/npfwht.h b/lib/qra/qracodes/npfwht.h index 212b0af2..9452e207 100755 --- a/lib/qra/qracodes/npfwht.h +++ b/lib/qra/qracodes/npfwht.h @@ -1,45 +1,45 @@ -// np_fwht.h -// Basic implementation of the Fast Walsh-Hadamard Transforms -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#ifndef _npfwht_h_ -#define _npfwht_h_ - -#ifdef __cplusplus -extern "C" { -#endif - -void np_fwht(int nlogdim, float *dst, float *src); -// Compute the Walsh-Hadamard transform of the given data up to a -// 64-dimensional transform -// -// Input parameters: -// nlogdim: log2 of the transform size. Must be in the range [0..6] -// src : pointer to the input data buffer. -// dst : pointer to the output data buffer. -// -// src and dst must point to preallocated data buffers of size 2^nlogdim*sizeof(float) -// src and dst buffers can overlap - -#ifdef __cplusplus -} -#endif - -#endif // _npfwht_ +// np_fwht.h +// Basic implementation of the Fast Walsh-Hadamard Transforms +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#ifndef _npfwht_h_ +#define _npfwht_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +void np_fwht(int nlogdim, float *dst, float *src); +// Compute the Walsh-Hadamard transform of the given data up to a +// 64-dimensional transform +// +// Input parameters: +// nlogdim: log2 of the transform size. Must be in the range [0..6] +// src : pointer to the input data buffer. +// dst : pointer to the output data buffer. +// +// src and dst must point to preallocated data buffers of size 2^nlogdim*sizeof(float) +// src and dst buffers can overlap + +#ifdef __cplusplus +} +#endif + +#endif // _npfwht_ diff --git a/lib/qra/qracodes/pdmath.c b/lib/qra/qracodes/pdmath.c index 2c55e41b..47ecab91 100755 --- a/lib/qra/qracodes/pdmath.c +++ b/lib/qra/qracodes/pdmath.c @@ -1,385 +1,385 @@ -// pdmath.c -// Elementary math on probability distributions -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#include "pdmath.h" - -typedef const float *ppd_uniform; -typedef void (*ppd_imul)(float*,const float*); -typedef float (*ppd_norm)(float*); - -// define vector size in function of its logarithm in base 2 -static const int pd_log2dim[7] = { - 1,2,4,8,16,32,64 -}; - -// define uniform distributions of given size -static const float pd_uniform1[1] = { - 1. -}; -static const float pd_uniform2[2] = { - 1./2., 1./2. -}; -static const float pd_uniform4[4] = { - 1./4., 1./4.,1./4., 1./4. -}; -static const float pd_uniform8[8] = { - 1./8., 1./8.,1./8., 1./8.,1./8., 1./8.,1./8., 1./8. -}; -static const float pd_uniform16[16] = { - 1./16., 1./16., 1./16., 1./16.,1./16., 1./16.,1./16., 1./16., - 1./16., 1./16., 1./16., 1./16.,1./16., 1./16.,1./16., 1./16. -}; -static const float pd_uniform32[32] = { - 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., - 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., - 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., - 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32. -}; -static const float pd_uniform64[64] = { - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., - 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64. - -}; - -static const ppd_uniform pd_uniform_tab[7] = { - pd_uniform1, - pd_uniform2, - pd_uniform4, - pd_uniform8, - pd_uniform16, - pd_uniform32, - pd_uniform64 -}; - -// returns a pointer to the uniform distribution of the given logsize -const float *pd_uniform(int nlogdim) -{ - return pd_uniform_tab[nlogdim]; -} - -// in-place multiplication functions -// compute dst = dst*src for any element of the distrib - -static void pd_imul1(float *dst, const float *src) -{ - dst[0] *= src[0]; -} - -static void pd_imul2(float *dst, const float *src) -{ - dst[0] *= src[0]; dst[1] *= src[1]; -} -static void pd_imul4(float *dst, const float *src) -{ - dst[0] *= src[0]; dst[1] *= src[1]; - dst[2] *= src[2]; dst[3] *= src[3]; -} -static void pd_imul8(float *dst, const float *src) -{ - dst[0] *= src[0]; dst[1] *= src[1]; dst[2] *= src[2]; dst[3] *= src[3]; - dst[4] *= src[4]; dst[5] *= src[5]; dst[6] *= src[6]; dst[7] *= src[7]; -} -static void pd_imul16(float *dst, const float *src) -{ - dst[0] *= src[0]; dst[1] *= src[1]; dst[2] *= src[2]; dst[3] *= src[3]; - dst[4] *= src[4]; dst[5] *= src[5]; dst[6] *= src[6]; dst[7] *= src[7]; - dst[8] *= src[8]; dst[9] *= src[9]; dst[10]*= src[10]; dst[11]*= src[11]; - dst[12]*= src[12]; dst[13]*= src[13]; dst[14]*= src[14]; dst[15]*= src[15]; -} -static void pd_imul32(float *dst, const float *src) -{ - pd_imul16(dst,src); - pd_imul16(dst+16,src+16); -} -static void pd_imul64(float *dst, const float *src) -{ - pd_imul16(dst, src); - pd_imul16(dst+16, src+16); - pd_imul16(dst+32, src+32); - pd_imul16(dst+48, src+48); -} - -static const ppd_imul pd_imul_tab[7] = { - pd_imul1, - pd_imul2, - pd_imul4, - pd_imul8, - pd_imul16, - pd_imul32, - pd_imul64 -}; - -// in place multiplication -// compute dst = dst*src for any element of the distrib give their log2 size -// arguments must be pointers to array of floats of the given size -void pd_imul(float *dst, const float *src, int nlogdim) -{ - pd_imul_tab[nlogdim](dst,src); -} - -static float pd_norm1(float *ppd) -{ - float t = ppd[0]; - ppd[0] = 1.f; - return t; -} - -static float pd_norm2(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; - - if (t<=0) { - pd_init(ppd,pd_uniform(1),pd_log2dim[1]); - return t; - } - - to = t; - t = 1.f/t; - ppd[0] *=t; ppd[1] *=t; - return to; - -} - -static float pd_norm4(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; - - if (t<=0) { - pd_init(ppd,pd_uniform(2),pd_log2dim[2]); - return t; - } - - to = t; - t = 1.f/t; - ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; - return to; -} - -static float pd_norm8(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; - t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; - - if (t<=0) { - pd_init(ppd,pd_uniform(3),pd_log2dim[3]); - return t; - } - - to = t; - t = 1.f/t; - ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; - ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; - return to; -} -static float pd_norm16(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; - t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; - t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; - t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; - - if (t<=0) { - pd_init(ppd,pd_uniform(4),pd_log2dim[4]); - return t; - } - - to = t; - t = 1.f/t; - ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; - ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; - ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; - ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; - - return to; -} -static float pd_norm32(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; - t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; - t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; - t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; - t +=ppd[16]; t +=ppd[17]; t +=ppd[18]; t +=ppd[19]; - t +=ppd[20]; t +=ppd[21]; t +=ppd[22]; t +=ppd[23]; - t +=ppd[24]; t +=ppd[25]; t +=ppd[26]; t +=ppd[27]; - t +=ppd[28]; t +=ppd[29]; t +=ppd[30]; t +=ppd[31]; - - if (t<=0) { - pd_init(ppd,pd_uniform(5),pd_log2dim[5]); - return t; - } - - to = t; - t = 1.f/t; - ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; - ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; - ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; - ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; - ppd[16] *=t; ppd[17] *=t; ppd[18] *=t; ppd[19] *=t; - ppd[20] *=t; ppd[21] *=t; ppd[22] *=t; ppd[23] *=t; - ppd[24] *=t; ppd[25] *=t; ppd[26] *=t; ppd[27] *=t; - ppd[28] *=t; ppd[29] *=t; ppd[30] *=t; ppd[31] *=t; - - return to; -} - -static float pd_norm64(float *ppd) -{ - float t,to; - - t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; - t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; - t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; - t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; - t +=ppd[16]; t +=ppd[17]; t +=ppd[18]; t +=ppd[19]; - t +=ppd[20]; t +=ppd[21]; t +=ppd[22]; t +=ppd[23]; - t +=ppd[24]; t +=ppd[25]; t +=ppd[26]; t +=ppd[27]; - t +=ppd[28]; t +=ppd[29]; t +=ppd[30]; t +=ppd[31]; - - t +=ppd[32]; t +=ppd[33]; t +=ppd[34]; t +=ppd[35]; - t +=ppd[36]; t +=ppd[37]; t +=ppd[38]; t +=ppd[39]; - t +=ppd[40]; t +=ppd[41]; t +=ppd[42]; t +=ppd[43]; - t +=ppd[44]; t +=ppd[45]; t +=ppd[46]; t +=ppd[47]; - t +=ppd[48]; t +=ppd[49]; t +=ppd[50]; t +=ppd[51]; - t +=ppd[52]; t +=ppd[53]; t +=ppd[54]; t +=ppd[55]; - t +=ppd[56]; t +=ppd[57]; t +=ppd[58]; t +=ppd[59]; - t +=ppd[60]; t +=ppd[61]; t +=ppd[62]; t +=ppd[63]; - - if (t<=0) { - pd_init(ppd,pd_uniform(6),pd_log2dim[6]); - return t; - } - - to = t; - t = 1.0f/t; - ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; - ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; - ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; - ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; - ppd[16] *=t; ppd[17] *=t; ppd[18] *=t; ppd[19] *=t; - ppd[20] *=t; ppd[21] *=t; ppd[22] *=t; ppd[23] *=t; - ppd[24] *=t; ppd[25] *=t; ppd[26] *=t; ppd[27] *=t; - ppd[28] *=t; ppd[29] *=t; ppd[30] *=t; ppd[31] *=t; - - ppd[32] *=t; ppd[33] *=t; ppd[34] *=t; ppd[35] *=t; - ppd[36] *=t; ppd[37] *=t; ppd[38] *=t; ppd[39] *=t; - ppd[40] *=t; ppd[41] *=t; ppd[42] *=t; ppd[43] *=t; - ppd[44] *=t; ppd[45] *=t; ppd[46] *=t; ppd[47] *=t; - ppd[48] *=t; ppd[49] *=t; ppd[50] *=t; ppd[51] *=t; - ppd[52] *=t; ppd[53] *=t; ppd[54] *=t; ppd[55] *=t; - ppd[56] *=t; ppd[57] *=t; ppd[58] *=t; ppd[59] *=t; - ppd[60] *=t; ppd[61] *=t; ppd[62] *=t; ppd[63] *=t; - - return to; -} - - -static const ppd_norm pd_norm_tab[7] = { - pd_norm1, - pd_norm2, - pd_norm4, - pd_norm8, - pd_norm16, - pd_norm32, - pd_norm64 -}; - -float pd_norm(float *pd, int nlogdim) -{ - return pd_norm_tab[nlogdim](pd); -} - -void pd_memset(float *dst, const float *src, int ndim, int nitems) -{ - int size = PD_SIZE(ndim); - while(nitems--) { - memcpy(dst,src,size); - dst +=ndim; - } -} - -void pd_fwdperm(float *dst, float *src, const int *perm, int ndim) -{ - // TODO: non-loop implementation - while (ndim--) - dst[ndim] = src[perm[ndim]]; -} - -void pd_bwdperm(float *dst, float *src, const int *perm, int ndim) -{ - // TODO: non-loop implementation - while (ndim--) - dst[perm[ndim]] = src[ndim]; -} - -float pd_max(float *src, int ndim) -{ - // TODO: faster implementation - - float cmax=0; // we assume that prob distributions are always positive - float cval; - - while (ndim--) { - cval = src[ndim]; - if (cval>=cmax) { - cmax = cval; - } - } - - return cmax; -} - -int pd_argmax(float *pmax, float *src, int ndim) -{ - // TODO: faster implementation - - float cmax=0; // we assume that prob distributions are always positive - float cval; - int idxmax=-1; // indicates that all pd elements are <0 - - while (ndim--) { - cval = src[ndim]; - if (cval>=cmax) { - cmax = cval; - idxmax = ndim; - } - } - - if (pmax) - *pmax = cmax; - - return idxmax; -} +// pdmath.c +// Elementary math on probability distributions +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#include "pdmath.h" + +typedef const float *ppd_uniform; +typedef void (*ppd_imul)(float*,const float*); +typedef float (*ppd_norm)(float*); + +// define vector size in function of its logarithm in base 2 +static const int pd_log2dim[7] = { + 1,2,4,8,16,32,64 +}; + +// define uniform distributions of given size +static const float pd_uniform1[1] = { + 1. +}; +static const float pd_uniform2[2] = { + 1./2., 1./2. +}; +static const float pd_uniform4[4] = { + 1./4., 1./4.,1./4., 1./4. +}; +static const float pd_uniform8[8] = { + 1./8., 1./8.,1./8., 1./8.,1./8., 1./8.,1./8., 1./8. +}; +static const float pd_uniform16[16] = { + 1./16., 1./16., 1./16., 1./16.,1./16., 1./16.,1./16., 1./16., + 1./16., 1./16., 1./16., 1./16.,1./16., 1./16.,1./16., 1./16. +}; +static const float pd_uniform32[32] = { + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32. +}; +static const float pd_uniform64[64] = { + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64. + +}; + +static const ppd_uniform pd_uniform_tab[7] = { + pd_uniform1, + pd_uniform2, + pd_uniform4, + pd_uniform8, + pd_uniform16, + pd_uniform32, + pd_uniform64 +}; + +// returns a pointer to the uniform distribution of the given logsize +const float *pd_uniform(int nlogdim) +{ + return pd_uniform_tab[nlogdim]; +} + +// in-place multiplication functions +// compute dst = dst*src for any element of the distrib + +static void pd_imul1(float *dst, const float *src) +{ + dst[0] *= src[0]; +} + +static void pd_imul2(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; +} +static void pd_imul4(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; + dst[2] *= src[2]; dst[3] *= src[3]; +} +static void pd_imul8(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; dst[2] *= src[2]; dst[3] *= src[3]; + dst[4] *= src[4]; dst[5] *= src[5]; dst[6] *= src[6]; dst[7] *= src[7]; +} +static void pd_imul16(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; dst[2] *= src[2]; dst[3] *= src[3]; + dst[4] *= src[4]; dst[5] *= src[5]; dst[6] *= src[6]; dst[7] *= src[7]; + dst[8] *= src[8]; dst[9] *= src[9]; dst[10]*= src[10]; dst[11]*= src[11]; + dst[12]*= src[12]; dst[13]*= src[13]; dst[14]*= src[14]; dst[15]*= src[15]; +} +static void pd_imul32(float *dst, const float *src) +{ + pd_imul16(dst,src); + pd_imul16(dst+16,src+16); +} +static void pd_imul64(float *dst, const float *src) +{ + pd_imul16(dst, src); + pd_imul16(dst+16, src+16); + pd_imul16(dst+32, src+32); + pd_imul16(dst+48, src+48); +} + +static const ppd_imul pd_imul_tab[7] = { + pd_imul1, + pd_imul2, + pd_imul4, + pd_imul8, + pd_imul16, + pd_imul32, + pd_imul64 +}; + +// in place multiplication +// compute dst = dst*src for any element of the distrib give their log2 size +// arguments must be pointers to array of floats of the given size +void pd_imul(float *dst, const float *src, int nlogdim) +{ + pd_imul_tab[nlogdim](dst,src); +} + +static float pd_norm1(float *ppd) +{ + float t = ppd[0]; + ppd[0] = 1.f; + return t; +} + +static float pd_norm2(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; + + if (t<=0) { + pd_init(ppd,pd_uniform(1),pd_log2dim[1]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; + return to; + +} + +static float pd_norm4(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + + if (t<=0) { + pd_init(ppd,pd_uniform(2),pd_log2dim[2]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + return to; +} + +static float pd_norm8(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + + if (t<=0) { + pd_init(ppd,pd_uniform(3),pd_log2dim[3]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + return to; +} +static float pd_norm16(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; + t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; + + if (t<=0) { + pd_init(ppd,pd_uniform(4),pd_log2dim[4]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; + ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; + + return to; +} +static float pd_norm32(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; + t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; + t +=ppd[16]; t +=ppd[17]; t +=ppd[18]; t +=ppd[19]; + t +=ppd[20]; t +=ppd[21]; t +=ppd[22]; t +=ppd[23]; + t +=ppd[24]; t +=ppd[25]; t +=ppd[26]; t +=ppd[27]; + t +=ppd[28]; t +=ppd[29]; t +=ppd[30]; t +=ppd[31]; + + if (t<=0) { + pd_init(ppd,pd_uniform(5),pd_log2dim[5]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; + ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; + ppd[16] *=t; ppd[17] *=t; ppd[18] *=t; ppd[19] *=t; + ppd[20] *=t; ppd[21] *=t; ppd[22] *=t; ppd[23] *=t; + ppd[24] *=t; ppd[25] *=t; ppd[26] *=t; ppd[27] *=t; + ppd[28] *=t; ppd[29] *=t; ppd[30] *=t; ppd[31] *=t; + + return to; +} + +static float pd_norm64(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; + t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; + t +=ppd[16]; t +=ppd[17]; t +=ppd[18]; t +=ppd[19]; + t +=ppd[20]; t +=ppd[21]; t +=ppd[22]; t +=ppd[23]; + t +=ppd[24]; t +=ppd[25]; t +=ppd[26]; t +=ppd[27]; + t +=ppd[28]; t +=ppd[29]; t +=ppd[30]; t +=ppd[31]; + + t +=ppd[32]; t +=ppd[33]; t +=ppd[34]; t +=ppd[35]; + t +=ppd[36]; t +=ppd[37]; t +=ppd[38]; t +=ppd[39]; + t +=ppd[40]; t +=ppd[41]; t +=ppd[42]; t +=ppd[43]; + t +=ppd[44]; t +=ppd[45]; t +=ppd[46]; t +=ppd[47]; + t +=ppd[48]; t +=ppd[49]; t +=ppd[50]; t +=ppd[51]; + t +=ppd[52]; t +=ppd[53]; t +=ppd[54]; t +=ppd[55]; + t +=ppd[56]; t +=ppd[57]; t +=ppd[58]; t +=ppd[59]; + t +=ppd[60]; t +=ppd[61]; t +=ppd[62]; t +=ppd[63]; + + if (t<=0) { + pd_init(ppd,pd_uniform(6),pd_log2dim[6]); + return t; + } + + to = t; + t = 1.0f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; + ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; + ppd[16] *=t; ppd[17] *=t; ppd[18] *=t; ppd[19] *=t; + ppd[20] *=t; ppd[21] *=t; ppd[22] *=t; ppd[23] *=t; + ppd[24] *=t; ppd[25] *=t; ppd[26] *=t; ppd[27] *=t; + ppd[28] *=t; ppd[29] *=t; ppd[30] *=t; ppd[31] *=t; + + ppd[32] *=t; ppd[33] *=t; ppd[34] *=t; ppd[35] *=t; + ppd[36] *=t; ppd[37] *=t; ppd[38] *=t; ppd[39] *=t; + ppd[40] *=t; ppd[41] *=t; ppd[42] *=t; ppd[43] *=t; + ppd[44] *=t; ppd[45] *=t; ppd[46] *=t; ppd[47] *=t; + ppd[48] *=t; ppd[49] *=t; ppd[50] *=t; ppd[51] *=t; + ppd[52] *=t; ppd[53] *=t; ppd[54] *=t; ppd[55] *=t; + ppd[56] *=t; ppd[57] *=t; ppd[58] *=t; ppd[59] *=t; + ppd[60] *=t; ppd[61] *=t; ppd[62] *=t; ppd[63] *=t; + + return to; +} + + +static const ppd_norm pd_norm_tab[7] = { + pd_norm1, + pd_norm2, + pd_norm4, + pd_norm8, + pd_norm16, + pd_norm32, + pd_norm64 +}; + +float pd_norm(float *pd, int nlogdim) +{ + return pd_norm_tab[nlogdim](pd); +} + +void pd_memset(float *dst, const float *src, int ndim, int nitems) +{ + int size = PD_SIZE(ndim); + while(nitems--) { + memcpy(dst,src,size); + dst +=ndim; + } +} + +void pd_fwdperm(float *dst, float *src, const int *perm, int ndim) +{ + // TODO: non-loop implementation + while (ndim--) + dst[ndim] = src[perm[ndim]]; +} + +void pd_bwdperm(float *dst, float *src, const int *perm, int ndim) +{ + // TODO: non-loop implementation + while (ndim--) + dst[perm[ndim]] = src[ndim]; +} + +float pd_max(float *src, int ndim) +{ + // TODO: faster implementation + + float cmax=0; // we assume that prob distributions are always positive + float cval; + + while (ndim--) { + cval = src[ndim]; + if (cval>=cmax) { + cmax = cval; + } + } + + return cmax; +} + +int pd_argmax(float *pmax, float *src, int ndim) +{ + // TODO: faster implementation + + float cmax=0; // we assume that prob distributions are always positive + float cval; + int idxmax=-1; // indicates that all pd elements are <0 + + while (ndim--) { + cval = src[ndim]; + if (cval>=cmax) { + cmax = cval; + idxmax = ndim; + } + } + + if (pmax) + *pmax = cmax; + + return idxmax; +} diff --git a/lib/qra/qracodes/pdmath.h b/lib/qra/qracodes/pdmath.h index bd441e08..bbd1210c 100755 --- a/lib/qra/qracodes/pdmath.h +++ b/lib/qra/qracodes/pdmath.h @@ -1,85 +1,85 @@ -// pdmath.h -// Elementary math on probability distributions -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - - -#ifndef _pdmath_h_ -#define _pdmath_h_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define PD_NDIM(nlogdim) ((1<<(nlogdim)) -#define PD_SIZE(ndim) ((ndim)*sizeof(float)) -#define PD_ROWADDR(fp,ndim,idx) (fp+((ndim)*(idx))) - -const float *pd_uniform(int nlogdim); -// Returns a pointer to a (constant) uniform distribution of the given log2 size - -#define pd_init(dst,src,ndim) memcpy(dst,src,PD_SIZE(ndim)) -// Distribution copy - -void pd_memset(float *dst, const float *src, int ndim, int nitems); -// Copy the distribution pointed by src to the array of distributions dst -// src is a pointer to the input distribution (a vector of size ndim) -// dst is a pointer to a linear array of distributions (a vector of size ndim*nitems) - -void pd_imul(float *dst, const float *src, int nlogdim); -// In place multiplication -// Compute dst = dst*src for any element of the distrib give their log2 size -// src and dst arguments must be pointers to array of floats of the given size - -float pd_norm(float *pd, int nlogdim); -// In place normalizazion -// Normalizes the input vector so that the sum of its components are one -// pd must be a pointer to an array of floats of the given size. -// If the norm of the input vector is non-positive the vector components -// are replaced with a uniform distribution -// Returns the norm of the distribution prior to the normalization - -void pd_fwdperm(float *dst, float *src, const int *perm, int ndim); -// Forward permutation of a distribution -// Computes dst[k] = src[perm[k]] for every element in the distribution -// perm must be a pointer to an array of integers of length ndim - -void pd_bwdperm(float *dst, float *src, const int *perm, int ndim); -// Backward permutation of a distribution -// Computes dst[perm[k]] = src[k] for every element in the distribution -// perm must be a pointer to an array of integers of length ndim - -float pd_max(float *src, int ndim); -// Return the maximum of the elements of the given distribution -// Assumes that the input vector is a probability distribution and that each element in the -// distribution is non negative - -int pd_argmax(float *pmax, float *src, int ndim); -// Return the index of the maximum element of the given distribution -// The maximum is stored in the variable pointed by pmax if pmax is not null -// Same note of pd_max applies. -// Return -1 if all the elements in the distribution are negative - -#ifdef __cplusplus -} -#endif - -#endif // _pdmath_h_ +// pdmath.h +// Elementary math on probability distributions +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + + +#ifndef _pdmath_h_ +#define _pdmath_h_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PD_NDIM(nlogdim) ((1<<(nlogdim)) +#define PD_SIZE(ndim) ((ndim)*sizeof(float)) +#define PD_ROWADDR(fp,ndim,idx) (fp+((ndim)*(idx))) + +const float *pd_uniform(int nlogdim); +// Returns a pointer to a (constant) uniform distribution of the given log2 size + +#define pd_init(dst,src,ndim) memcpy(dst,src,PD_SIZE(ndim)) +// Distribution copy + +void pd_memset(float *dst, const float *src, int ndim, int nitems); +// Copy the distribution pointed by src to the array of distributions dst +// src is a pointer to the input distribution (a vector of size ndim) +// dst is a pointer to a linear array of distributions (a vector of size ndim*nitems) + +void pd_imul(float *dst, const float *src, int nlogdim); +// In place multiplication +// Compute dst = dst*src for any element of the distrib give their log2 size +// src and dst arguments must be pointers to array of floats of the given size + +float pd_norm(float *pd, int nlogdim); +// In place normalizazion +// Normalizes the input vector so that the sum of its components are one +// pd must be a pointer to an array of floats of the given size. +// If the norm of the input vector is non-positive the vector components +// are replaced with a uniform distribution +// Returns the norm of the distribution prior to the normalization + +void pd_fwdperm(float *dst, float *src, const int *perm, int ndim); +// Forward permutation of a distribution +// Computes dst[k] = src[perm[k]] for every element in the distribution +// perm must be a pointer to an array of integers of length ndim + +void pd_bwdperm(float *dst, float *src, const int *perm, int ndim); +// Backward permutation of a distribution +// Computes dst[perm[k]] = src[k] for every element in the distribution +// perm must be a pointer to an array of integers of length ndim + +float pd_max(float *src, int ndim); +// Return the maximum of the elements of the given distribution +// Assumes that the input vector is a probability distribution and that each element in the +// distribution is non negative + +int pd_argmax(float *pmax, float *src, int ndim); +// Return the index of the maximum element of the given distribution +// The maximum is stored in the variable pointed by pmax if pmax is not null +// Same note of pd_max applies. +// Return -1 if all the elements in the distribution are negative + +#ifdef __cplusplus +} +#endif + +#endif // _pdmath_h_ diff --git a/lib/qra/qracodes/qra12_63_64_irr_b.c b/lib/qra/qracodes/qra12_63_64_irr_b.c index 1118520c..d69443b8 100755 --- a/lib/qra/qracodes/qra12_63_64_irr_b.c +++ b/lib/qra/qracodes/qra12_63_64_irr_b.c @@ -1,534 +1,534 @@ -// qra12_63_64_irr_b.c -// Encoding/Decoding tables for Q-ary RA code (12,63) over GF(64) -// Code Name: qra12_63_64_irr_b -// (12,63) RA Code over GF(64) - RF=333344455567 - -// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy - -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#include "qra12_63_64_irr_b.h" - -#define qra_K 12 // number of information symbols -#define qra_N 63 // codeword length in symbols -#define qra_m 6 // bits/symbol -#define qra_M 64 // Symbol alphabet cardinality -#define qra_a 1 // grouping factor -#define qra_NC 51 // number of check symbols (N-K) - -// Defines used by the message passing decoder -------- - -#define qra_V 63 // number of variables in the code graph (N) -#define qra_C 115 // number of factors in the code graph (N +(N-K)+1) -#define qra_NMSG 217 // number of msgs in the code graph -#define qra_MAXVDEG 8 // maximum variable degree -#define qra_MAXCDEG 3 // maximum factor degree -#define qra_R 0.19048f // code rate (K/N) -#define CODE_NAME "qra_12_63_64_irr_b" - - -// table of the systematic symbols indexes in the accumulator chain -static const int qra_acc_input_idx[qra_NC+1] = { - 3, 11, 0, 1, 7, 8, 6, 5, 10, 4, - 11, 9, 0, 2, 6, 7, 8, 4, 11, 5, - 10, 2, 1, 9, 3, 8, 4, 11, 5, 7, - 10, 9, 6, 3, 11, 5, 8, 10, 0, 7, - 9, 11, 4, 2, 10, 6, 8, 1, 9, 7, - 11, 10 -}; - -// table of the systematic symbols weight logarithms over GF(M) -static const int qra_acc_input_wlog[qra_NC+1] = { - 39, 0, 34, 16, 25, 0, 34, 48, 19, 13, - 29, 56, 0, 5, 39, 42, 31, 0, 10, 0, - 57, 62, 33, 43, 0, 14, 22, 48, 28, 20, - 5, 45, 16, 43, 17, 4, 32, 0, 31, 0, - 0, 28, 57, 0, 18, 0, 60, 0, 10, 31, - 57, 27 -}; - -// table of the logarithms of the elements of GF(M) (log(0) never used) -static const int qra_log[qra_M] = { - -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, - 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, - 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, - 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, - 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, - 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, - 20, 59, 57, 58 -}; - -// table of GF(M) elements given their logarithm -static const int qra_exp[qra_M-1] = { - 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, - 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, - 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, - 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, - 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, - 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, - 57, 49, 33 -}; - -// table of the messages weight logarithms over GF(M) -static const int qra_msgw[qra_NMSG] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 39, 0, 34, 16, 25, 0, 34, - 48, 19, 13, 29, 56, 0, 5, 39, 42, 31, - 0, 10, 0, 57, 62, 33, 43, 0, 14, 22, - 48, 28, 20, 5, 45, 16, 43, 17, 4, 32, - 0, 31, 0, 0, 28, 57, 0, 18, 0, 60, - 0, 10, 31, 57, 27, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0 -}; - -// table of the degrees of the variable nodes -static const int qra_vdeg[qra_V] = { - 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, - 7, 8, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3 -}; - -// table of the degrees of the factor nodes -static const int qra_cdeg[qra_C] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 2, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 2 -}; - -// table (uncompressed) of the v->c message indexes (-1=unused entry) -static const int qra_v2cmidx[qra_V*qra_MAXVDEG] = { - 0, 65, 75, 101, -1, -1, -1, -1, - 1, 66, 85, 110, -1, -1, -1, -1, - 2, 76, 84, 106, -1, -1, -1, -1, - 3, 63, 87, 96, -1, -1, -1, -1, - 4, 72, 80, 89, 105, -1, -1, -1, - 5, 70, 82, 91, 98, -1, -1, -1, - 6, 69, 77, 95, 108, -1, -1, -1, - 7, 67, 78, 92, 102, 112, -1, -1, - 8, 68, 79, 88, 99, 109, -1, -1, - 9, 74, 86, 94, 103, 111, -1, -1, - 10, 71, 83, 93, 100, 107, 114, -1, - 11, 64, 73, 81, 90, 97, 104, 113, - 12, 115, 116, -1, -1, -1, -1, -1, - 13, 117, 118, -1, -1, -1, -1, -1, - 14, 119, 120, -1, -1, -1, -1, -1, - 15, 121, 122, -1, -1, -1, -1, -1, - 16, 123, 124, -1, -1, -1, -1, -1, - 17, 125, 126, -1, -1, -1, -1, -1, - 18, 127, 128, -1, -1, -1, -1, -1, - 19, 129, 130, -1, -1, -1, -1, -1, - 20, 131, 132, -1, -1, -1, -1, -1, - 21, 133, 134, -1, -1, -1, -1, -1, - 22, 135, 136, -1, -1, -1, -1, -1, - 23, 137, 138, -1, -1, -1, -1, -1, - 24, 139, 140, -1, -1, -1, -1, -1, - 25, 141, 142, -1, -1, -1, -1, -1, - 26, 143, 144, -1, -1, -1, -1, -1, - 27, 145, 146, -1, -1, -1, -1, -1, - 28, 147, 148, -1, -1, -1, -1, -1, - 29, 149, 150, -1, -1, -1, -1, -1, - 30, 151, 152, -1, -1, -1, -1, -1, - 31, 153, 154, -1, -1, -1, -1, -1, - 32, 155, 156, -1, -1, -1, -1, -1, - 33, 157, 158, -1, -1, -1, -1, -1, - 34, 159, 160, -1, -1, -1, -1, -1, - 35, 161, 162, -1, -1, -1, -1, -1, - 36, 163, 164, -1, -1, -1, -1, -1, - 37, 165, 166, -1, -1, -1, -1, -1, - 38, 167, 168, -1, -1, -1, -1, -1, - 39, 169, 170, -1, -1, -1, -1, -1, - 40, 171, 172, -1, -1, -1, -1, -1, - 41, 173, 174, -1, -1, -1, -1, -1, - 42, 175, 176, -1, -1, -1, -1, -1, - 43, 177, 178, -1, -1, -1, -1, -1, - 44, 179, 180, -1, -1, -1, -1, -1, - 45, 181, 182, -1, -1, -1, -1, -1, - 46, 183, 184, -1, -1, -1, -1, -1, - 47, 185, 186, -1, -1, -1, -1, -1, - 48, 187, 188, -1, -1, -1, -1, -1, - 49, 189, 190, -1, -1, -1, -1, -1, - 50, 191, 192, -1, -1, -1, -1, -1, - 51, 193, 194, -1, -1, -1, -1, -1, - 52, 195, 196, -1, -1, -1, -1, -1, - 53, 197, 198, -1, -1, -1, -1, -1, - 54, 199, 200, -1, -1, -1, -1, -1, - 55, 201, 202, -1, -1, -1, -1, -1, - 56, 203, 204, -1, -1, -1, -1, -1, - 57, 205, 206, -1, -1, -1, -1, -1, - 58, 207, 208, -1, -1, -1, -1, -1, - 59, 209, 210, -1, -1, -1, -1, -1, - 60, 211, 212, -1, -1, -1, -1, -1, - 61, 213, 214, -1, -1, -1, -1, -1, - 62, 215, 216, -1, -1, -1, -1, -1 -}; - -// table (uncompressed) of the c->v message indexes (-1=unused entry) -static const int qra_c2vmidx[qra_C*qra_MAXCDEG] = { - 0, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1, - 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1, - 8, -1, -1, 9, -1, -1, 10, -1, -1, 11, -1, -1, - 12, -1, -1, 13, -1, -1, 14, -1, -1, 15, -1, -1, - 16, -1, -1, 17, -1, -1, 18, -1, -1, 19, -1, -1, - 20, -1, -1, 21, -1, -1, 22, -1, -1, 23, -1, -1, - 24, -1, -1, 25, -1, -1, 26, -1, -1, 27, -1, -1, - 28, -1, -1, 29, -1, -1, 30, -1, -1, 31, -1, -1, - 32, -1, -1, 33, -1, -1, 34, -1, -1, 35, -1, -1, - 36, -1, -1, 37, -1, -1, 38, -1, -1, 39, -1, -1, - 40, -1, -1, 41, -1, -1, 42, -1, -1, 43, -1, -1, - 44, -1, -1, 45, -1, -1, 46, -1, -1, 47, -1, -1, - 48, -1, -1, 49, -1, -1, 50, -1, -1, 51, -1, -1, - 52, -1, -1, 53, -1, -1, 54, -1, -1, 55, -1, -1, - 56, -1, -1, 57, -1, -1, 58, -1, -1, 59, -1, -1, - 60, -1, -1, 61, -1, -1, 62, -1, -1, 63, 115, -1, - 64, 116, 117, 65, 118, 119, 66, 120, 121, 67, 122, 123, - 68, 124, 125, 69, 126, 127, 70, 128, 129, 71, 130, 131, - 72, 132, 133, 73, 134, 135, 74, 136, 137, 75, 138, 139, - 76, 140, 141, 77, 142, 143, 78, 144, 145, 79, 146, 147, - 80, 148, 149, 81, 150, 151, 82, 152, 153, 83, 154, 155, - 84, 156, 157, 85, 158, 159, 86, 160, 161, 87, 162, 163, - 88, 164, 165, 89, 166, 167, 90, 168, 169, 91, 170, 171, - 92, 172, 173, 93, 174, 175, 94, 176, 177, 95, 178, 179, - 96, 180, 181, 97, 182, 183, 98, 184, 185, 99, 186, 187, -100, 188, 189, 101, 190, 191, 102, 192, 193, 103, 194, 195, -104, 196, 197, 105, 198, 199, 106, 200, 201, 107, 202, 203, -108, 204, 205, 109, 206, 207, 110, 208, 209, 111, 210, 211, -112, 212, 213, 113, 214, 215, 114, 216, -1 -}; - -// permutation matrix to compute Prob(x*alfa^logw) -static const int qra_pmat[qra_M*qra_M] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 0, 33, 1, 32, 2, 35, 3, 34, 4, 37, 5, 36, 6, 39, 7, 38, - 8, 41, 9, 40, 10, 43, 11, 42, 12, 45, 13, 44, 14, 47, 15, 46, - 16, 49, 17, 48, 18, 51, 19, 50, 20, 53, 21, 52, 22, 55, 23, 54, - 24, 57, 25, 56, 26, 59, 27, 58, 28, 61, 29, 60, 30, 63, 31, 62, - 0, 49, 33, 16, 1, 48, 32, 17, 2, 51, 35, 18, 3, 50, 34, 19, - 4, 53, 37, 20, 5, 52, 36, 21, 6, 55, 39, 22, 7, 54, 38, 23, - 8, 57, 41, 24, 9, 56, 40, 25, 10, 59, 43, 26, 11, 58, 42, 27, - 12, 61, 45, 28, 13, 60, 44, 29, 14, 63, 47, 30, 15, 62, 46, 31, - 0, 57, 49, 8, 33, 24, 16, 41, 1, 56, 48, 9, 32, 25, 17, 40, - 2, 59, 51, 10, 35, 26, 18, 43, 3, 58, 50, 11, 34, 27, 19, 42, - 4, 61, 53, 12, 37, 28, 20, 45, 5, 60, 52, 13, 36, 29, 21, 44, - 6, 63, 55, 14, 39, 30, 22, 47, 7, 62, 54, 15, 38, 31, 23, 46, - 0, 61, 57, 4, 49, 12, 8, 53, 33, 28, 24, 37, 16, 45, 41, 20, - 1, 60, 56, 5, 48, 13, 9, 52, 32, 29, 25, 36, 17, 44, 40, 21, - 2, 63, 59, 6, 51, 14, 10, 55, 35, 30, 26, 39, 18, 47, 43, 22, - 3, 62, 58, 7, 50, 15, 11, 54, 34, 31, 27, 38, 19, 46, 42, 23, - 0, 63, 61, 2, 57, 6, 4, 59, 49, 14, 12, 51, 8, 55, 53, 10, - 33, 30, 28, 35, 24, 39, 37, 26, 16, 47, 45, 18, 41, 22, 20, 43, - 1, 62, 60, 3, 56, 7, 5, 58, 48, 15, 13, 50, 9, 54, 52, 11, - 32, 31, 29, 34, 25, 38, 36, 27, 17, 46, 44, 19, 40, 23, 21, 42, - 0, 62, 63, 1, 61, 3, 2, 60, 57, 7, 6, 56, 4, 58, 59, 5, - 49, 15, 14, 48, 12, 50, 51, 13, 8, 54, 55, 9, 53, 11, 10, 52, - 33, 31, 30, 32, 28, 34, 35, 29, 24, 38, 39, 25, 37, 27, 26, 36, - 16, 46, 47, 17, 45, 19, 18, 44, 41, 23, 22, 40, 20, 42, 43, 21, - 0, 31, 62, 33, 63, 32, 1, 30, 61, 34, 3, 28, 2, 29, 60, 35, - 57, 38, 7, 24, 6, 25, 56, 39, 4, 27, 58, 37, 59, 36, 5, 26, - 49, 46, 15, 16, 14, 17, 48, 47, 12, 19, 50, 45, 51, 44, 13, 18, - 8, 23, 54, 41, 55, 40, 9, 22, 53, 42, 11, 20, 10, 21, 52, 43, - 0, 46, 31, 49, 62, 16, 33, 15, 63, 17, 32, 14, 1, 47, 30, 48, - 61, 19, 34, 12, 3, 45, 28, 50, 2, 44, 29, 51, 60, 18, 35, 13, - 57, 23, 38, 8, 7, 41, 24, 54, 6, 40, 25, 55, 56, 22, 39, 9, - 4, 42, 27, 53, 58, 20, 37, 11, 59, 21, 36, 10, 5, 43, 26, 52, - 0, 23, 46, 57, 31, 8, 49, 38, 62, 41, 16, 7, 33, 54, 15, 24, - 63, 40, 17, 6, 32, 55, 14, 25, 1, 22, 47, 56, 30, 9, 48, 39, - 61, 42, 19, 4, 34, 53, 12, 27, 3, 20, 45, 58, 28, 11, 50, 37, - 2, 21, 44, 59, 29, 10, 51, 36, 60, 43, 18, 5, 35, 52, 13, 26, - 0, 42, 23, 61, 46, 4, 57, 19, 31, 53, 8, 34, 49, 27, 38, 12, - 62, 20, 41, 3, 16, 58, 7, 45, 33, 11, 54, 28, 15, 37, 24, 50, - 63, 21, 40, 2, 17, 59, 6, 44, 32, 10, 55, 29, 14, 36, 25, 51, - 1, 43, 22, 60, 47, 5, 56, 18, 30, 52, 9, 35, 48, 26, 39, 13, - 0, 21, 42, 63, 23, 2, 61, 40, 46, 59, 4, 17, 57, 44, 19, 6, - 31, 10, 53, 32, 8, 29, 34, 55, 49, 36, 27, 14, 38, 51, 12, 25, - 62, 43, 20, 1, 41, 60, 3, 22, 16, 5, 58, 47, 7, 18, 45, 56, - 33, 52, 11, 30, 54, 35, 28, 9, 15, 26, 37, 48, 24, 13, 50, 39, - 0, 43, 21, 62, 42, 1, 63, 20, 23, 60, 2, 41, 61, 22, 40, 3, - 46, 5, 59, 16, 4, 47, 17, 58, 57, 18, 44, 7, 19, 56, 6, 45, - 31, 52, 10, 33, 53, 30, 32, 11, 8, 35, 29, 54, 34, 9, 55, 28, - 49, 26, 36, 15, 27, 48, 14, 37, 38, 13, 51, 24, 12, 39, 25, 50, - 0, 52, 43, 31, 21, 33, 62, 10, 42, 30, 1, 53, 63, 11, 20, 32, - 23, 35, 60, 8, 2, 54, 41, 29, 61, 9, 22, 34, 40, 28, 3, 55, - 46, 26, 5, 49, 59, 15, 16, 36, 4, 48, 47, 27, 17, 37, 58, 14, - 57, 13, 18, 38, 44, 24, 7, 51, 19, 39, 56, 12, 6, 50, 45, 25, - 0, 26, 52, 46, 43, 49, 31, 5, 21, 15, 33, 59, 62, 36, 10, 16, - 42, 48, 30, 4, 1, 27, 53, 47, 63, 37, 11, 17, 20, 14, 32, 58, - 23, 13, 35, 57, 60, 38, 8, 18, 2, 24, 54, 44, 41, 51, 29, 7, - 61, 39, 9, 19, 22, 12, 34, 56, 40, 50, 28, 6, 3, 25, 55, 45, - 0, 13, 26, 23, 52, 57, 46, 35, 43, 38, 49, 60, 31, 18, 5, 8, - 21, 24, 15, 2, 33, 44, 59, 54, 62, 51, 36, 41, 10, 7, 16, 29, - 42, 39, 48, 61, 30, 19, 4, 9, 1, 12, 27, 22, 53, 56, 47, 34, - 63, 50, 37, 40, 11, 6, 17, 28, 20, 25, 14, 3, 32, 45, 58, 55, - 0, 39, 13, 42, 26, 61, 23, 48, 52, 19, 57, 30, 46, 9, 35, 4, - 43, 12, 38, 1, 49, 22, 60, 27, 31, 56, 18, 53, 5, 34, 8, 47, - 21, 50, 24, 63, 15, 40, 2, 37, 33, 6, 44, 11, 59, 28, 54, 17, - 62, 25, 51, 20, 36, 3, 41, 14, 10, 45, 7, 32, 16, 55, 29, 58, - 0, 50, 39, 21, 13, 63, 42, 24, 26, 40, 61, 15, 23, 37, 48, 2, - 52, 6, 19, 33, 57, 11, 30, 44, 46, 28, 9, 59, 35, 17, 4, 54, - 43, 25, 12, 62, 38, 20, 1, 51, 49, 3, 22, 36, 60, 14, 27, 41, - 31, 45, 56, 10, 18, 32, 53, 7, 5, 55, 34, 16, 8, 58, 47, 29, - 0, 25, 50, 43, 39, 62, 21, 12, 13, 20, 63, 38, 42, 51, 24, 1, - 26, 3, 40, 49, 61, 36, 15, 22, 23, 14, 37, 60, 48, 41, 2, 27, - 52, 45, 6, 31, 19, 10, 33, 56, 57, 32, 11, 18, 30, 7, 44, 53, - 46, 55, 28, 5, 9, 16, 59, 34, 35, 58, 17, 8, 4, 29, 54, 47, - 0, 45, 25, 52, 50, 31, 43, 6, 39, 10, 62, 19, 21, 56, 12, 33, - 13, 32, 20, 57, 63, 18, 38, 11, 42, 7, 51, 30, 24, 53, 1, 44, - 26, 55, 3, 46, 40, 5, 49, 28, 61, 16, 36, 9, 15, 34, 22, 59, - 23, 58, 14, 35, 37, 8, 60, 17, 48, 29, 41, 4, 2, 47, 27, 54, - 0, 55, 45, 26, 25, 46, 52, 3, 50, 5, 31, 40, 43, 28, 6, 49, - 39, 16, 10, 61, 62, 9, 19, 36, 21, 34, 56, 15, 12, 59, 33, 22, - 13, 58, 32, 23, 20, 35, 57, 14, 63, 8, 18, 37, 38, 17, 11, 60, - 42, 29, 7, 48, 51, 4, 30, 41, 24, 47, 53, 2, 1, 54, 44, 27, - 0, 58, 55, 13, 45, 23, 26, 32, 25, 35, 46, 20, 52, 14, 3, 57, - 50, 8, 5, 63, 31, 37, 40, 18, 43, 17, 28, 38, 6, 60, 49, 11, - 39, 29, 16, 42, 10, 48, 61, 7, 62, 4, 9, 51, 19, 41, 36, 30, - 21, 47, 34, 24, 56, 2, 15, 53, 12, 54, 59, 1, 33, 27, 22, 44, - 0, 29, 58, 39, 55, 42, 13, 16, 45, 48, 23, 10, 26, 7, 32, 61, - 25, 4, 35, 62, 46, 51, 20, 9, 52, 41, 14, 19, 3, 30, 57, 36, - 50, 47, 8, 21, 5, 24, 63, 34, 31, 2, 37, 56, 40, 53, 18, 15, - 43, 54, 17, 12, 28, 1, 38, 59, 6, 27, 60, 33, 49, 44, 11, 22, - 0, 47, 29, 50, 58, 21, 39, 8, 55, 24, 42, 5, 13, 34, 16, 63, - 45, 2, 48, 31, 23, 56, 10, 37, 26, 53, 7, 40, 32, 15, 61, 18, - 25, 54, 4, 43, 35, 12, 62, 17, 46, 1, 51, 28, 20, 59, 9, 38, - 52, 27, 41, 6, 14, 33, 19, 60, 3, 44, 30, 49, 57, 22, 36, 11, - 0, 54, 47, 25, 29, 43, 50, 4, 58, 12, 21, 35, 39, 17, 8, 62, - 55, 1, 24, 46, 42, 28, 5, 51, 13, 59, 34, 20, 16, 38, 63, 9, - 45, 27, 2, 52, 48, 6, 31, 41, 23, 33, 56, 14, 10, 60, 37, 19, - 26, 44, 53, 3, 7, 49, 40, 30, 32, 22, 15, 57, 61, 11, 18, 36, - 0, 27, 54, 45, 47, 52, 25, 2, 29, 6, 43, 48, 50, 41, 4, 31, - 58, 33, 12, 23, 21, 14, 35, 56, 39, 60, 17, 10, 8, 19, 62, 37, - 55, 44, 1, 26, 24, 3, 46, 53, 42, 49, 28, 7, 5, 30, 51, 40, - 13, 22, 59, 32, 34, 57, 20, 15, 16, 11, 38, 61, 63, 36, 9, 18, - 0, 44, 27, 55, 54, 26, 45, 1, 47, 3, 52, 24, 25, 53, 2, 46, - 29, 49, 6, 42, 43, 7, 48, 28, 50, 30, 41, 5, 4, 40, 31, 51, - 58, 22, 33, 13, 12, 32, 23, 59, 21, 57, 14, 34, 35, 15, 56, 20, - 39, 11, 60, 16, 17, 61, 10, 38, 8, 36, 19, 63, 62, 18, 37, 9, - 0, 22, 44, 58, 27, 13, 55, 33, 54, 32, 26, 12, 45, 59, 1, 23, - 47, 57, 3, 21, 52, 34, 24, 14, 25, 15, 53, 35, 2, 20, 46, 56, - 29, 11, 49, 39, 6, 16, 42, 60, 43, 61, 7, 17, 48, 38, 28, 10, - 50, 36, 30, 8, 41, 63, 5, 19, 4, 18, 40, 62, 31, 9, 51, 37, - 0, 11, 22, 29, 44, 39, 58, 49, 27, 16, 13, 6, 55, 60, 33, 42, - 54, 61, 32, 43, 26, 17, 12, 7, 45, 38, 59, 48, 1, 10, 23, 28, - 47, 36, 57, 50, 3, 8, 21, 30, 52, 63, 34, 41, 24, 19, 14, 5, - 25, 18, 15, 4, 53, 62, 35, 40, 2, 9, 20, 31, 46, 37, 56, 51, - 0, 36, 11, 47, 22, 50, 29, 57, 44, 8, 39, 3, 58, 30, 49, 21, - 27, 63, 16, 52, 13, 41, 6, 34, 55, 19, 60, 24, 33, 5, 42, 14, - 54, 18, 61, 25, 32, 4, 43, 15, 26, 62, 17, 53, 12, 40, 7, 35, - 45, 9, 38, 2, 59, 31, 48, 20, 1, 37, 10, 46, 23, 51, 28, 56, - 0, 18, 36, 54, 11, 25, 47, 61, 22, 4, 50, 32, 29, 15, 57, 43, - 44, 62, 8, 26, 39, 53, 3, 17, 58, 40, 30, 12, 49, 35, 21, 7, - 27, 9, 63, 45, 16, 2, 52, 38, 13, 31, 41, 59, 6, 20, 34, 48, - 55, 37, 19, 1, 60, 46, 24, 10, 33, 51, 5, 23, 42, 56, 14, 28, - 0, 9, 18, 27, 36, 45, 54, 63, 11, 2, 25, 16, 47, 38, 61, 52, - 22, 31, 4, 13, 50, 59, 32, 41, 29, 20, 15, 6, 57, 48, 43, 34, - 44, 37, 62, 55, 8, 1, 26, 19, 39, 46, 53, 60, 3, 10, 17, 24, - 58, 51, 40, 33, 30, 23, 12, 5, 49, 56, 35, 42, 21, 28, 7, 14, - 0, 37, 9, 44, 18, 55, 27, 62, 36, 1, 45, 8, 54, 19, 63, 26, - 11, 46, 2, 39, 25, 60, 16, 53, 47, 10, 38, 3, 61, 24, 52, 17, - 22, 51, 31, 58, 4, 33, 13, 40, 50, 23, 59, 30, 32, 5, 41, 12, - 29, 56, 20, 49, 15, 42, 6, 35, 57, 28, 48, 21, 43, 14, 34, 7, - 0, 51, 37, 22, 9, 58, 44, 31, 18, 33, 55, 4, 27, 40, 62, 13, - 36, 23, 1, 50, 45, 30, 8, 59, 54, 5, 19, 32, 63, 12, 26, 41, - 11, 56, 46, 29, 2, 49, 39, 20, 25, 42, 60, 15, 16, 35, 53, 6, - 47, 28, 10, 57, 38, 21, 3, 48, 61, 14, 24, 43, 52, 7, 17, 34, - 0, 56, 51, 11, 37, 29, 22, 46, 9, 49, 58, 2, 44, 20, 31, 39, - 18, 42, 33, 25, 55, 15, 4, 60, 27, 35, 40, 16, 62, 6, 13, 53, - 36, 28, 23, 47, 1, 57, 50, 10, 45, 21, 30, 38, 8, 48, 59, 3, - 54, 14, 5, 61, 19, 43, 32, 24, 63, 7, 12, 52, 26, 34, 41, 17, - 0, 28, 56, 36, 51, 47, 11, 23, 37, 57, 29, 1, 22, 10, 46, 50, - 9, 21, 49, 45, 58, 38, 2, 30, 44, 48, 20, 8, 31, 3, 39, 59, - 18, 14, 42, 54, 33, 61, 25, 5, 55, 43, 15, 19, 4, 24, 60, 32, - 27, 7, 35, 63, 40, 52, 16, 12, 62, 34, 6, 26, 13, 17, 53, 41, - 0, 14, 28, 18, 56, 54, 36, 42, 51, 61, 47, 33, 11, 5, 23, 25, - 37, 43, 57, 55, 29, 19, 1, 15, 22, 24, 10, 4, 46, 32, 50, 60, - 9, 7, 21, 27, 49, 63, 45, 35, 58, 52, 38, 40, 2, 12, 30, 16, - 44, 34, 48, 62, 20, 26, 8, 6, 31, 17, 3, 13, 39, 41, 59, 53, - 0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45, - 51, 52, 61, 58, 47, 40, 33, 38, 11, 12, 5, 2, 23, 16, 25, 30, - 37, 34, 43, 44, 57, 62, 55, 48, 29, 26, 19, 20, 1, 6, 15, 8, - 22, 17, 24, 31, 10, 13, 4, 3, 46, 41, 32, 39, 50, 53, 60, 59, - 0, 34, 7, 37, 14, 44, 9, 43, 28, 62, 27, 57, 18, 48, 21, 55, - 56, 26, 63, 29, 54, 20, 49, 19, 36, 6, 35, 1, 42, 8, 45, 15, - 51, 17, 52, 22, 61, 31, 58, 24, 47, 13, 40, 10, 33, 3, 38, 4, - 11, 41, 12, 46, 5, 39, 2, 32, 23, 53, 16, 50, 25, 59, 30, 60, - 0, 17, 34, 51, 7, 22, 37, 52, 14, 31, 44, 61, 9, 24, 43, 58, - 28, 13, 62, 47, 27, 10, 57, 40, 18, 3, 48, 33, 21, 4, 55, 38, - 56, 41, 26, 11, 63, 46, 29, 12, 54, 39, 20, 5, 49, 32, 19, 2, - 36, 53, 6, 23, 35, 50, 1, 16, 42, 59, 8, 25, 45, 60, 15, 30, - 0, 41, 17, 56, 34, 11, 51, 26, 7, 46, 22, 63, 37, 12, 52, 29, - 14, 39, 31, 54, 44, 5, 61, 20, 9, 32, 24, 49, 43, 2, 58, 19, - 28, 53, 13, 36, 62, 23, 47, 6, 27, 50, 10, 35, 57, 16, 40, 1, - 18, 59, 3, 42, 48, 25, 33, 8, 21, 60, 4, 45, 55, 30, 38, 15, - 0, 53, 41, 28, 17, 36, 56, 13, 34, 23, 11, 62, 51, 6, 26, 47, - 7, 50, 46, 27, 22, 35, 63, 10, 37, 16, 12, 57, 52, 1, 29, 40, - 14, 59, 39, 18, 31, 42, 54, 3, 44, 25, 5, 48, 61, 8, 20, 33, - 9, 60, 32, 21, 24, 45, 49, 4, 43, 30, 2, 55, 58, 15, 19, 38, - 0, 59, 53, 14, 41, 18, 28, 39, 17, 42, 36, 31, 56, 3, 13, 54, - 34, 25, 23, 44, 11, 48, 62, 5, 51, 8, 6, 61, 26, 33, 47, 20, - 7, 60, 50, 9, 46, 21, 27, 32, 22, 45, 35, 24, 63, 4, 10, 49, - 37, 30, 16, 43, 12, 55, 57, 2, 52, 15, 1, 58, 29, 38, 40, 19, - 0, 60, 59, 7, 53, 9, 14, 50, 41, 21, 18, 46, 28, 32, 39, 27, - 17, 45, 42, 22, 36, 24, 31, 35, 56, 4, 3, 63, 13, 49, 54, 10, - 34, 30, 25, 37, 23, 43, 44, 16, 11, 55, 48, 12, 62, 2, 5, 57, - 51, 15, 8, 52, 6, 58, 61, 1, 26, 38, 33, 29, 47, 19, 20, 40, - 0, 30, 60, 34, 59, 37, 7, 25, 53, 43, 9, 23, 14, 16, 50, 44, - 41, 55, 21, 11, 18, 12, 46, 48, 28, 2, 32, 62, 39, 57, 27, 5, - 17, 15, 45, 51, 42, 52, 22, 8, 36, 58, 24, 6, 31, 1, 35, 61, - 56, 38, 4, 26, 3, 29, 63, 33, 13, 19, 49, 47, 54, 40, 10, 20, - 0, 15, 30, 17, 60, 51, 34, 45, 59, 52, 37, 42, 7, 8, 25, 22, - 53, 58, 43, 36, 9, 6, 23, 24, 14, 1, 16, 31, 50, 61, 44, 35, - 41, 38, 55, 56, 21, 26, 11, 4, 18, 29, 12, 3, 46, 33, 48, 63, - 28, 19, 2, 13, 32, 47, 62, 49, 39, 40, 57, 54, 27, 20, 5, 10, - 0, 38, 15, 41, 30, 56, 17, 55, 60, 26, 51, 21, 34, 4, 45, 11, - 59, 29, 52, 18, 37, 3, 42, 12, 7, 33, 8, 46, 25, 63, 22, 48, - 53, 19, 58, 28, 43, 13, 36, 2, 9, 47, 6, 32, 23, 49, 24, 62, - 14, 40, 1, 39, 16, 54, 31, 57, 50, 20, 61, 27, 44, 10, 35, 5, - 0, 19, 38, 53, 15, 28, 41, 58, 30, 13, 56, 43, 17, 2, 55, 36, - 60, 47, 26, 9, 51, 32, 21, 6, 34, 49, 4, 23, 45, 62, 11, 24, - 59, 40, 29, 14, 52, 39, 18, 1, 37, 54, 3, 16, 42, 57, 12, 31, - 7, 20, 33, 50, 8, 27, 46, 61, 25, 10, 63, 44, 22, 5, 48, 35, - 0, 40, 19, 59, 38, 14, 53, 29, 15, 39, 28, 52, 41, 1, 58, 18, - 30, 54, 13, 37, 56, 16, 43, 3, 17, 57, 2, 42, 55, 31, 36, 12, - 60, 20, 47, 7, 26, 50, 9, 33, 51, 27, 32, 8, 21, 61, 6, 46, - 34, 10, 49, 25, 4, 44, 23, 63, 45, 5, 62, 22, 11, 35, 24, 48, - 0, 20, 40, 60, 19, 7, 59, 47, 38, 50, 14, 26, 53, 33, 29, 9, - 15, 27, 39, 51, 28, 8, 52, 32, 41, 61, 1, 21, 58, 46, 18, 6, - 30, 10, 54, 34, 13, 25, 37, 49, 56, 44, 16, 4, 43, 63, 3, 23, - 17, 5, 57, 45, 2, 22, 42, 62, 55, 35, 31, 11, 36, 48, 12, 24, - 0, 10, 20, 30, 40, 34, 60, 54, 19, 25, 7, 13, 59, 49, 47, 37, - 38, 44, 50, 56, 14, 4, 26, 16, 53, 63, 33, 43, 29, 23, 9, 3, - 15, 5, 27, 17, 39, 45, 51, 57, 28, 22, 8, 2, 52, 62, 32, 42, - 41, 35, 61, 55, 1, 11, 21, 31, 58, 48, 46, 36, 18, 24, 6, 12, - 0, 5, 10, 15, 20, 17, 30, 27, 40, 45, 34, 39, 60, 57, 54, 51, - 19, 22, 25, 28, 7, 2, 13, 8, 59, 62, 49, 52, 47, 42, 37, 32, - 38, 35, 44, 41, 50, 55, 56, 61, 14, 11, 4, 1, 26, 31, 16, 21, - 53, 48, 63, 58, 33, 36, 43, 46, 29, 24, 23, 18, 9, 12, 3, 6, - 0, 35, 5, 38, 10, 41, 15, 44, 20, 55, 17, 50, 30, 61, 27, 56, - 40, 11, 45, 14, 34, 1, 39, 4, 60, 31, 57, 26, 54, 21, 51, 16, - 19, 48, 22, 53, 25, 58, 28, 63, 7, 36, 2, 33, 13, 46, 8, 43, - 59, 24, 62, 29, 49, 18, 52, 23, 47, 12, 42, 9, 37, 6, 32, 3, - 0, 48, 35, 19, 5, 53, 38, 22, 10, 58, 41, 25, 15, 63, 44, 28, - 20, 36, 55, 7, 17, 33, 50, 2, 30, 46, 61, 13, 27, 43, 56, 8, - 40, 24, 11, 59, 45, 29, 14, 62, 34, 18, 1, 49, 39, 23, 4, 52, - 60, 12, 31, 47, 57, 9, 26, 42, 54, 6, 21, 37, 51, 3, 16, 32, - 0, 24, 48, 40, 35, 59, 19, 11, 5, 29, 53, 45, 38, 62, 22, 14, - 10, 18, 58, 34, 41, 49, 25, 1, 15, 23, 63, 39, 44, 52, 28, 4, - 20, 12, 36, 60, 55, 47, 7, 31, 17, 9, 33, 57, 50, 42, 2, 26, - 30, 6, 46, 54, 61, 37, 13, 21, 27, 3, 43, 51, 56, 32, 8, 16, - 0, 12, 24, 20, 48, 60, 40, 36, 35, 47, 59, 55, 19, 31, 11, 7, - 5, 9, 29, 17, 53, 57, 45, 33, 38, 42, 62, 50, 22, 26, 14, 2, - 10, 6, 18, 30, 58, 54, 34, 46, 41, 37, 49, 61, 25, 21, 1, 13, - 15, 3, 23, 27, 63, 51, 39, 43, 44, 32, 52, 56, 28, 16, 4, 8, - 0, 6, 12, 10, 24, 30, 20, 18, 48, 54, 60, 58, 40, 46, 36, 34, - 35, 37, 47, 41, 59, 61, 55, 49, 19, 21, 31, 25, 11, 13, 7, 1, - 5, 3, 9, 15, 29, 27, 17, 23, 53, 51, 57, 63, 45, 43, 33, 39, - 38, 32, 42, 44, 62, 56, 50, 52, 22, 16, 26, 28, 14, 8, 2, 4, - 0, 3, 6, 5, 12, 15, 10, 9, 24, 27, 30, 29, 20, 23, 18, 17, - 48, 51, 54, 53, 60, 63, 58, 57, 40, 43, 46, 45, 36, 39, 34, 33, - 35, 32, 37, 38, 47, 44, 41, 42, 59, 56, 61, 62, 55, 52, 49, 50, - 19, 16, 21, 22, 31, 28, 25, 26, 11, 8, 13, 14, 7, 4, 1, 2, - 0, 32, 3, 35, 6, 38, 5, 37, 12, 44, 15, 47, 10, 42, 9, 41, - 24, 56, 27, 59, 30, 62, 29, 61, 20, 52, 23, 55, 18, 50, 17, 49, - 48, 16, 51, 19, 54, 22, 53, 21, 60, 28, 63, 31, 58, 26, 57, 25, - 40, 8, 43, 11, 46, 14, 45, 13, 36, 4, 39, 7, 34, 2, 33, 1, - 0, 16, 32, 48, 3, 19, 35, 51, 6, 22, 38, 54, 5, 21, 37, 53, - 12, 28, 44, 60, 15, 31, 47, 63, 10, 26, 42, 58, 9, 25, 41, 57, - 24, 8, 56, 40, 27, 11, 59, 43, 30, 14, 62, 46, 29, 13, 61, 45, - 20, 4, 52, 36, 23, 7, 55, 39, 18, 2, 50, 34, 17, 1, 49, 33, - 0, 8, 16, 24, 32, 40, 48, 56, 3, 11, 19, 27, 35, 43, 51, 59, - 6, 14, 22, 30, 38, 46, 54, 62, 5, 13, 21, 29, 37, 45, 53, 61, - 12, 4, 28, 20, 44, 36, 60, 52, 15, 7, 31, 23, 47, 39, 63, 55, - 10, 2, 26, 18, 42, 34, 58, 50, 9, 1, 25, 17, 41, 33, 57, 49, - 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, - 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, - 6, 2, 14, 10, 22, 18, 30, 26, 38, 34, 46, 42, 54, 50, 62, 58, - 5, 1, 13, 9, 21, 17, 29, 25, 37, 33, 45, 41, 53, 49, 61, 57, - 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, - 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, - 3, 1, 7, 5, 11, 9, 15, 13, 19, 17, 23, 21, 27, 25, 31, 29, - 35, 33, 39, 37, 43, 41, 47, 45, 51, 49, 55, 53, 59, 57, 63, 61 -}; - -const qracode qra_12_63_64_irr_b = { - qra_K, - qra_N, - qra_m, - qra_M, - qra_a, - qra_NC, - qra_V, - qra_C, - qra_NMSG, - qra_MAXVDEG, - qra_MAXCDEG, - QRATYPE_NORMAL, - qra_R, - CODE_NAME, - qra_acc_input_idx, - qra_acc_input_wlog, - qra_log, - qra_exp, - qra_msgw, - qra_vdeg, - qra_cdeg, - qra_v2cmidx, - qra_c2vmidx, - qra_pmat -}; - -#undef qra_K -#undef qra_N -#undef qra_m -#undef qra_M -#undef qra_a -#undef qra_NC -#undef qra_V -#undef qra_C -#undef qra_NMSG -#undef qra_MAXVDEG -#undef qra_MAXCDEG -#undef qra_R +// qra12_63_64_irr_b.c +// Encoding/Decoding tables for Q-ary RA code (12,63) over GF(64) +// Code Name: qra12_63_64_irr_b +// (12,63) RA Code over GF(64) - RF=333344455567 + +// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy + +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#include "qra12_63_64_irr_b.h" + +#define qra_K 12 // number of information symbols +#define qra_N 63 // codeword length in symbols +#define qra_m 6 // bits/symbol +#define qra_M 64 // Symbol alphabet cardinality +#define qra_a 1 // grouping factor +#define qra_NC 51 // number of check symbols (N-K) + +// Defines used by the message passing decoder -------- + +#define qra_V 63 // number of variables in the code graph (N) +#define qra_C 115 // number of factors in the code graph (N +(N-K)+1) +#define qra_NMSG 217 // number of msgs in the code graph +#define qra_MAXVDEG 8 // maximum variable degree +#define qra_MAXCDEG 3 // maximum factor degree +#define qra_R 0.19048f // code rate (K/N) +#define CODE_NAME "qra_12_63_64_irr_b" + + +// table of the systematic symbols indexes in the accumulator chain +static const int qra_acc_input_idx[qra_NC+1] = { + 3, 11, 0, 1, 7, 8, 6, 5, 10, 4, + 11, 9, 0, 2, 6, 7, 8, 4, 11, 5, + 10, 2, 1, 9, 3, 8, 4, 11, 5, 7, + 10, 9, 6, 3, 11, 5, 8, 10, 0, 7, + 9, 11, 4, 2, 10, 6, 8, 1, 9, 7, + 11, 10 +}; + +// table of the systematic symbols weight logarithms over GF(M) +static const int qra_acc_input_wlog[qra_NC+1] = { + 39, 0, 34, 16, 25, 0, 34, 48, 19, 13, + 29, 56, 0, 5, 39, 42, 31, 0, 10, 0, + 57, 62, 33, 43, 0, 14, 22, 48, 28, 20, + 5, 45, 16, 43, 17, 4, 32, 0, 31, 0, + 0, 28, 57, 0, 18, 0, 60, 0, 10, 31, + 57, 27 +}; + +// table of the logarithms of the elements of GF(M) (log(0) never used) +static const int qra_log[qra_M] = { + -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, + 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, + 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, + 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, + 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, + 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, + 20, 59, 57, 58 +}; + +// table of GF(M) elements given their logarithm +static const int qra_exp[qra_M-1] = { + 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, + 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, + 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, + 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, + 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, + 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, + 57, 49, 33 +}; + +// table of the messages weight logarithms over GF(M) +static const int qra_msgw[qra_NMSG] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 39, 0, 34, 16, 25, 0, 34, + 48, 19, 13, 29, 56, 0, 5, 39, 42, 31, + 0, 10, 0, 57, 62, 33, 43, 0, 14, 22, + 48, 28, 20, 5, 45, 16, 43, 17, 4, 32, + 0, 31, 0, 0, 28, 57, 0, 18, 0, 60, + 0, 10, 31, 57, 27, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0 +}; + +// table of the degrees of the variable nodes +static const int qra_vdeg[qra_V] = { + 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, + 7, 8, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3 +}; + +// table of the degrees of the factor nodes +static const int qra_cdeg[qra_C] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 2, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 2 +}; + +// table (uncompressed) of the v->c message indexes (-1=unused entry) +static const int qra_v2cmidx[qra_V*qra_MAXVDEG] = { + 0, 65, 75, 101, -1, -1, -1, -1, + 1, 66, 85, 110, -1, -1, -1, -1, + 2, 76, 84, 106, -1, -1, -1, -1, + 3, 63, 87, 96, -1, -1, -1, -1, + 4, 72, 80, 89, 105, -1, -1, -1, + 5, 70, 82, 91, 98, -1, -1, -1, + 6, 69, 77, 95, 108, -1, -1, -1, + 7, 67, 78, 92, 102, 112, -1, -1, + 8, 68, 79, 88, 99, 109, -1, -1, + 9, 74, 86, 94, 103, 111, -1, -1, + 10, 71, 83, 93, 100, 107, 114, -1, + 11, 64, 73, 81, 90, 97, 104, 113, + 12, 115, 116, -1, -1, -1, -1, -1, + 13, 117, 118, -1, -1, -1, -1, -1, + 14, 119, 120, -1, -1, -1, -1, -1, + 15, 121, 122, -1, -1, -1, -1, -1, + 16, 123, 124, -1, -1, -1, -1, -1, + 17, 125, 126, -1, -1, -1, -1, -1, + 18, 127, 128, -1, -1, -1, -1, -1, + 19, 129, 130, -1, -1, -1, -1, -1, + 20, 131, 132, -1, -1, -1, -1, -1, + 21, 133, 134, -1, -1, -1, -1, -1, + 22, 135, 136, -1, -1, -1, -1, -1, + 23, 137, 138, -1, -1, -1, -1, -1, + 24, 139, 140, -1, -1, -1, -1, -1, + 25, 141, 142, -1, -1, -1, -1, -1, + 26, 143, 144, -1, -1, -1, -1, -1, + 27, 145, 146, -1, -1, -1, -1, -1, + 28, 147, 148, -1, -1, -1, -1, -1, + 29, 149, 150, -1, -1, -1, -1, -1, + 30, 151, 152, -1, -1, -1, -1, -1, + 31, 153, 154, -1, -1, -1, -1, -1, + 32, 155, 156, -1, -1, -1, -1, -1, + 33, 157, 158, -1, -1, -1, -1, -1, + 34, 159, 160, -1, -1, -1, -1, -1, + 35, 161, 162, -1, -1, -1, -1, -1, + 36, 163, 164, -1, -1, -1, -1, -1, + 37, 165, 166, -1, -1, -1, -1, -1, + 38, 167, 168, -1, -1, -1, -1, -1, + 39, 169, 170, -1, -1, -1, -1, -1, + 40, 171, 172, -1, -1, -1, -1, -1, + 41, 173, 174, -1, -1, -1, -1, -1, + 42, 175, 176, -1, -1, -1, -1, -1, + 43, 177, 178, -1, -1, -1, -1, -1, + 44, 179, 180, -1, -1, -1, -1, -1, + 45, 181, 182, -1, -1, -1, -1, -1, + 46, 183, 184, -1, -1, -1, -1, -1, + 47, 185, 186, -1, -1, -1, -1, -1, + 48, 187, 188, -1, -1, -1, -1, -1, + 49, 189, 190, -1, -1, -1, -1, -1, + 50, 191, 192, -1, -1, -1, -1, -1, + 51, 193, 194, -1, -1, -1, -1, -1, + 52, 195, 196, -1, -1, -1, -1, -1, + 53, 197, 198, -1, -1, -1, -1, -1, + 54, 199, 200, -1, -1, -1, -1, -1, + 55, 201, 202, -1, -1, -1, -1, -1, + 56, 203, 204, -1, -1, -1, -1, -1, + 57, 205, 206, -1, -1, -1, -1, -1, + 58, 207, 208, -1, -1, -1, -1, -1, + 59, 209, 210, -1, -1, -1, -1, -1, + 60, 211, 212, -1, -1, -1, -1, -1, + 61, 213, 214, -1, -1, -1, -1, -1, + 62, 215, 216, -1, -1, -1, -1, -1 +}; + +// table (uncompressed) of the c->v message indexes (-1=unused entry) +static const int qra_c2vmidx[qra_C*qra_MAXCDEG] = { + 0, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1, + 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1, + 8, -1, -1, 9, -1, -1, 10, -1, -1, 11, -1, -1, + 12, -1, -1, 13, -1, -1, 14, -1, -1, 15, -1, -1, + 16, -1, -1, 17, -1, -1, 18, -1, -1, 19, -1, -1, + 20, -1, -1, 21, -1, -1, 22, -1, -1, 23, -1, -1, + 24, -1, -1, 25, -1, -1, 26, -1, -1, 27, -1, -1, + 28, -1, -1, 29, -1, -1, 30, -1, -1, 31, -1, -1, + 32, -1, -1, 33, -1, -1, 34, -1, -1, 35, -1, -1, + 36, -1, -1, 37, -1, -1, 38, -1, -1, 39, -1, -1, + 40, -1, -1, 41, -1, -1, 42, -1, -1, 43, -1, -1, + 44, -1, -1, 45, -1, -1, 46, -1, -1, 47, -1, -1, + 48, -1, -1, 49, -1, -1, 50, -1, -1, 51, -1, -1, + 52, -1, -1, 53, -1, -1, 54, -1, -1, 55, -1, -1, + 56, -1, -1, 57, -1, -1, 58, -1, -1, 59, -1, -1, + 60, -1, -1, 61, -1, -1, 62, -1, -1, 63, 115, -1, + 64, 116, 117, 65, 118, 119, 66, 120, 121, 67, 122, 123, + 68, 124, 125, 69, 126, 127, 70, 128, 129, 71, 130, 131, + 72, 132, 133, 73, 134, 135, 74, 136, 137, 75, 138, 139, + 76, 140, 141, 77, 142, 143, 78, 144, 145, 79, 146, 147, + 80, 148, 149, 81, 150, 151, 82, 152, 153, 83, 154, 155, + 84, 156, 157, 85, 158, 159, 86, 160, 161, 87, 162, 163, + 88, 164, 165, 89, 166, 167, 90, 168, 169, 91, 170, 171, + 92, 172, 173, 93, 174, 175, 94, 176, 177, 95, 178, 179, + 96, 180, 181, 97, 182, 183, 98, 184, 185, 99, 186, 187, +100, 188, 189, 101, 190, 191, 102, 192, 193, 103, 194, 195, +104, 196, 197, 105, 198, 199, 106, 200, 201, 107, 202, 203, +108, 204, 205, 109, 206, 207, 110, 208, 209, 111, 210, 211, +112, 212, 213, 113, 214, 215, 114, 216, -1 +}; + +// permutation matrix to compute Prob(x*alfa^logw) +static const int qra_pmat[qra_M*qra_M] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 33, 1, 32, 2, 35, 3, 34, 4, 37, 5, 36, 6, 39, 7, 38, + 8, 41, 9, 40, 10, 43, 11, 42, 12, 45, 13, 44, 14, 47, 15, 46, + 16, 49, 17, 48, 18, 51, 19, 50, 20, 53, 21, 52, 22, 55, 23, 54, + 24, 57, 25, 56, 26, 59, 27, 58, 28, 61, 29, 60, 30, 63, 31, 62, + 0, 49, 33, 16, 1, 48, 32, 17, 2, 51, 35, 18, 3, 50, 34, 19, + 4, 53, 37, 20, 5, 52, 36, 21, 6, 55, 39, 22, 7, 54, 38, 23, + 8, 57, 41, 24, 9, 56, 40, 25, 10, 59, 43, 26, 11, 58, 42, 27, + 12, 61, 45, 28, 13, 60, 44, 29, 14, 63, 47, 30, 15, 62, 46, 31, + 0, 57, 49, 8, 33, 24, 16, 41, 1, 56, 48, 9, 32, 25, 17, 40, + 2, 59, 51, 10, 35, 26, 18, 43, 3, 58, 50, 11, 34, 27, 19, 42, + 4, 61, 53, 12, 37, 28, 20, 45, 5, 60, 52, 13, 36, 29, 21, 44, + 6, 63, 55, 14, 39, 30, 22, 47, 7, 62, 54, 15, 38, 31, 23, 46, + 0, 61, 57, 4, 49, 12, 8, 53, 33, 28, 24, 37, 16, 45, 41, 20, + 1, 60, 56, 5, 48, 13, 9, 52, 32, 29, 25, 36, 17, 44, 40, 21, + 2, 63, 59, 6, 51, 14, 10, 55, 35, 30, 26, 39, 18, 47, 43, 22, + 3, 62, 58, 7, 50, 15, 11, 54, 34, 31, 27, 38, 19, 46, 42, 23, + 0, 63, 61, 2, 57, 6, 4, 59, 49, 14, 12, 51, 8, 55, 53, 10, + 33, 30, 28, 35, 24, 39, 37, 26, 16, 47, 45, 18, 41, 22, 20, 43, + 1, 62, 60, 3, 56, 7, 5, 58, 48, 15, 13, 50, 9, 54, 52, 11, + 32, 31, 29, 34, 25, 38, 36, 27, 17, 46, 44, 19, 40, 23, 21, 42, + 0, 62, 63, 1, 61, 3, 2, 60, 57, 7, 6, 56, 4, 58, 59, 5, + 49, 15, 14, 48, 12, 50, 51, 13, 8, 54, 55, 9, 53, 11, 10, 52, + 33, 31, 30, 32, 28, 34, 35, 29, 24, 38, 39, 25, 37, 27, 26, 36, + 16, 46, 47, 17, 45, 19, 18, 44, 41, 23, 22, 40, 20, 42, 43, 21, + 0, 31, 62, 33, 63, 32, 1, 30, 61, 34, 3, 28, 2, 29, 60, 35, + 57, 38, 7, 24, 6, 25, 56, 39, 4, 27, 58, 37, 59, 36, 5, 26, + 49, 46, 15, 16, 14, 17, 48, 47, 12, 19, 50, 45, 51, 44, 13, 18, + 8, 23, 54, 41, 55, 40, 9, 22, 53, 42, 11, 20, 10, 21, 52, 43, + 0, 46, 31, 49, 62, 16, 33, 15, 63, 17, 32, 14, 1, 47, 30, 48, + 61, 19, 34, 12, 3, 45, 28, 50, 2, 44, 29, 51, 60, 18, 35, 13, + 57, 23, 38, 8, 7, 41, 24, 54, 6, 40, 25, 55, 56, 22, 39, 9, + 4, 42, 27, 53, 58, 20, 37, 11, 59, 21, 36, 10, 5, 43, 26, 52, + 0, 23, 46, 57, 31, 8, 49, 38, 62, 41, 16, 7, 33, 54, 15, 24, + 63, 40, 17, 6, 32, 55, 14, 25, 1, 22, 47, 56, 30, 9, 48, 39, + 61, 42, 19, 4, 34, 53, 12, 27, 3, 20, 45, 58, 28, 11, 50, 37, + 2, 21, 44, 59, 29, 10, 51, 36, 60, 43, 18, 5, 35, 52, 13, 26, + 0, 42, 23, 61, 46, 4, 57, 19, 31, 53, 8, 34, 49, 27, 38, 12, + 62, 20, 41, 3, 16, 58, 7, 45, 33, 11, 54, 28, 15, 37, 24, 50, + 63, 21, 40, 2, 17, 59, 6, 44, 32, 10, 55, 29, 14, 36, 25, 51, + 1, 43, 22, 60, 47, 5, 56, 18, 30, 52, 9, 35, 48, 26, 39, 13, + 0, 21, 42, 63, 23, 2, 61, 40, 46, 59, 4, 17, 57, 44, 19, 6, + 31, 10, 53, 32, 8, 29, 34, 55, 49, 36, 27, 14, 38, 51, 12, 25, + 62, 43, 20, 1, 41, 60, 3, 22, 16, 5, 58, 47, 7, 18, 45, 56, + 33, 52, 11, 30, 54, 35, 28, 9, 15, 26, 37, 48, 24, 13, 50, 39, + 0, 43, 21, 62, 42, 1, 63, 20, 23, 60, 2, 41, 61, 22, 40, 3, + 46, 5, 59, 16, 4, 47, 17, 58, 57, 18, 44, 7, 19, 56, 6, 45, + 31, 52, 10, 33, 53, 30, 32, 11, 8, 35, 29, 54, 34, 9, 55, 28, + 49, 26, 36, 15, 27, 48, 14, 37, 38, 13, 51, 24, 12, 39, 25, 50, + 0, 52, 43, 31, 21, 33, 62, 10, 42, 30, 1, 53, 63, 11, 20, 32, + 23, 35, 60, 8, 2, 54, 41, 29, 61, 9, 22, 34, 40, 28, 3, 55, + 46, 26, 5, 49, 59, 15, 16, 36, 4, 48, 47, 27, 17, 37, 58, 14, + 57, 13, 18, 38, 44, 24, 7, 51, 19, 39, 56, 12, 6, 50, 45, 25, + 0, 26, 52, 46, 43, 49, 31, 5, 21, 15, 33, 59, 62, 36, 10, 16, + 42, 48, 30, 4, 1, 27, 53, 47, 63, 37, 11, 17, 20, 14, 32, 58, + 23, 13, 35, 57, 60, 38, 8, 18, 2, 24, 54, 44, 41, 51, 29, 7, + 61, 39, 9, 19, 22, 12, 34, 56, 40, 50, 28, 6, 3, 25, 55, 45, + 0, 13, 26, 23, 52, 57, 46, 35, 43, 38, 49, 60, 31, 18, 5, 8, + 21, 24, 15, 2, 33, 44, 59, 54, 62, 51, 36, 41, 10, 7, 16, 29, + 42, 39, 48, 61, 30, 19, 4, 9, 1, 12, 27, 22, 53, 56, 47, 34, + 63, 50, 37, 40, 11, 6, 17, 28, 20, 25, 14, 3, 32, 45, 58, 55, + 0, 39, 13, 42, 26, 61, 23, 48, 52, 19, 57, 30, 46, 9, 35, 4, + 43, 12, 38, 1, 49, 22, 60, 27, 31, 56, 18, 53, 5, 34, 8, 47, + 21, 50, 24, 63, 15, 40, 2, 37, 33, 6, 44, 11, 59, 28, 54, 17, + 62, 25, 51, 20, 36, 3, 41, 14, 10, 45, 7, 32, 16, 55, 29, 58, + 0, 50, 39, 21, 13, 63, 42, 24, 26, 40, 61, 15, 23, 37, 48, 2, + 52, 6, 19, 33, 57, 11, 30, 44, 46, 28, 9, 59, 35, 17, 4, 54, + 43, 25, 12, 62, 38, 20, 1, 51, 49, 3, 22, 36, 60, 14, 27, 41, + 31, 45, 56, 10, 18, 32, 53, 7, 5, 55, 34, 16, 8, 58, 47, 29, + 0, 25, 50, 43, 39, 62, 21, 12, 13, 20, 63, 38, 42, 51, 24, 1, + 26, 3, 40, 49, 61, 36, 15, 22, 23, 14, 37, 60, 48, 41, 2, 27, + 52, 45, 6, 31, 19, 10, 33, 56, 57, 32, 11, 18, 30, 7, 44, 53, + 46, 55, 28, 5, 9, 16, 59, 34, 35, 58, 17, 8, 4, 29, 54, 47, + 0, 45, 25, 52, 50, 31, 43, 6, 39, 10, 62, 19, 21, 56, 12, 33, + 13, 32, 20, 57, 63, 18, 38, 11, 42, 7, 51, 30, 24, 53, 1, 44, + 26, 55, 3, 46, 40, 5, 49, 28, 61, 16, 36, 9, 15, 34, 22, 59, + 23, 58, 14, 35, 37, 8, 60, 17, 48, 29, 41, 4, 2, 47, 27, 54, + 0, 55, 45, 26, 25, 46, 52, 3, 50, 5, 31, 40, 43, 28, 6, 49, + 39, 16, 10, 61, 62, 9, 19, 36, 21, 34, 56, 15, 12, 59, 33, 22, + 13, 58, 32, 23, 20, 35, 57, 14, 63, 8, 18, 37, 38, 17, 11, 60, + 42, 29, 7, 48, 51, 4, 30, 41, 24, 47, 53, 2, 1, 54, 44, 27, + 0, 58, 55, 13, 45, 23, 26, 32, 25, 35, 46, 20, 52, 14, 3, 57, + 50, 8, 5, 63, 31, 37, 40, 18, 43, 17, 28, 38, 6, 60, 49, 11, + 39, 29, 16, 42, 10, 48, 61, 7, 62, 4, 9, 51, 19, 41, 36, 30, + 21, 47, 34, 24, 56, 2, 15, 53, 12, 54, 59, 1, 33, 27, 22, 44, + 0, 29, 58, 39, 55, 42, 13, 16, 45, 48, 23, 10, 26, 7, 32, 61, + 25, 4, 35, 62, 46, 51, 20, 9, 52, 41, 14, 19, 3, 30, 57, 36, + 50, 47, 8, 21, 5, 24, 63, 34, 31, 2, 37, 56, 40, 53, 18, 15, + 43, 54, 17, 12, 28, 1, 38, 59, 6, 27, 60, 33, 49, 44, 11, 22, + 0, 47, 29, 50, 58, 21, 39, 8, 55, 24, 42, 5, 13, 34, 16, 63, + 45, 2, 48, 31, 23, 56, 10, 37, 26, 53, 7, 40, 32, 15, 61, 18, + 25, 54, 4, 43, 35, 12, 62, 17, 46, 1, 51, 28, 20, 59, 9, 38, + 52, 27, 41, 6, 14, 33, 19, 60, 3, 44, 30, 49, 57, 22, 36, 11, + 0, 54, 47, 25, 29, 43, 50, 4, 58, 12, 21, 35, 39, 17, 8, 62, + 55, 1, 24, 46, 42, 28, 5, 51, 13, 59, 34, 20, 16, 38, 63, 9, + 45, 27, 2, 52, 48, 6, 31, 41, 23, 33, 56, 14, 10, 60, 37, 19, + 26, 44, 53, 3, 7, 49, 40, 30, 32, 22, 15, 57, 61, 11, 18, 36, + 0, 27, 54, 45, 47, 52, 25, 2, 29, 6, 43, 48, 50, 41, 4, 31, + 58, 33, 12, 23, 21, 14, 35, 56, 39, 60, 17, 10, 8, 19, 62, 37, + 55, 44, 1, 26, 24, 3, 46, 53, 42, 49, 28, 7, 5, 30, 51, 40, + 13, 22, 59, 32, 34, 57, 20, 15, 16, 11, 38, 61, 63, 36, 9, 18, + 0, 44, 27, 55, 54, 26, 45, 1, 47, 3, 52, 24, 25, 53, 2, 46, + 29, 49, 6, 42, 43, 7, 48, 28, 50, 30, 41, 5, 4, 40, 31, 51, + 58, 22, 33, 13, 12, 32, 23, 59, 21, 57, 14, 34, 35, 15, 56, 20, + 39, 11, 60, 16, 17, 61, 10, 38, 8, 36, 19, 63, 62, 18, 37, 9, + 0, 22, 44, 58, 27, 13, 55, 33, 54, 32, 26, 12, 45, 59, 1, 23, + 47, 57, 3, 21, 52, 34, 24, 14, 25, 15, 53, 35, 2, 20, 46, 56, + 29, 11, 49, 39, 6, 16, 42, 60, 43, 61, 7, 17, 48, 38, 28, 10, + 50, 36, 30, 8, 41, 63, 5, 19, 4, 18, 40, 62, 31, 9, 51, 37, + 0, 11, 22, 29, 44, 39, 58, 49, 27, 16, 13, 6, 55, 60, 33, 42, + 54, 61, 32, 43, 26, 17, 12, 7, 45, 38, 59, 48, 1, 10, 23, 28, + 47, 36, 57, 50, 3, 8, 21, 30, 52, 63, 34, 41, 24, 19, 14, 5, + 25, 18, 15, 4, 53, 62, 35, 40, 2, 9, 20, 31, 46, 37, 56, 51, + 0, 36, 11, 47, 22, 50, 29, 57, 44, 8, 39, 3, 58, 30, 49, 21, + 27, 63, 16, 52, 13, 41, 6, 34, 55, 19, 60, 24, 33, 5, 42, 14, + 54, 18, 61, 25, 32, 4, 43, 15, 26, 62, 17, 53, 12, 40, 7, 35, + 45, 9, 38, 2, 59, 31, 48, 20, 1, 37, 10, 46, 23, 51, 28, 56, + 0, 18, 36, 54, 11, 25, 47, 61, 22, 4, 50, 32, 29, 15, 57, 43, + 44, 62, 8, 26, 39, 53, 3, 17, 58, 40, 30, 12, 49, 35, 21, 7, + 27, 9, 63, 45, 16, 2, 52, 38, 13, 31, 41, 59, 6, 20, 34, 48, + 55, 37, 19, 1, 60, 46, 24, 10, 33, 51, 5, 23, 42, 56, 14, 28, + 0, 9, 18, 27, 36, 45, 54, 63, 11, 2, 25, 16, 47, 38, 61, 52, + 22, 31, 4, 13, 50, 59, 32, 41, 29, 20, 15, 6, 57, 48, 43, 34, + 44, 37, 62, 55, 8, 1, 26, 19, 39, 46, 53, 60, 3, 10, 17, 24, + 58, 51, 40, 33, 30, 23, 12, 5, 49, 56, 35, 42, 21, 28, 7, 14, + 0, 37, 9, 44, 18, 55, 27, 62, 36, 1, 45, 8, 54, 19, 63, 26, + 11, 46, 2, 39, 25, 60, 16, 53, 47, 10, 38, 3, 61, 24, 52, 17, + 22, 51, 31, 58, 4, 33, 13, 40, 50, 23, 59, 30, 32, 5, 41, 12, + 29, 56, 20, 49, 15, 42, 6, 35, 57, 28, 48, 21, 43, 14, 34, 7, + 0, 51, 37, 22, 9, 58, 44, 31, 18, 33, 55, 4, 27, 40, 62, 13, + 36, 23, 1, 50, 45, 30, 8, 59, 54, 5, 19, 32, 63, 12, 26, 41, + 11, 56, 46, 29, 2, 49, 39, 20, 25, 42, 60, 15, 16, 35, 53, 6, + 47, 28, 10, 57, 38, 21, 3, 48, 61, 14, 24, 43, 52, 7, 17, 34, + 0, 56, 51, 11, 37, 29, 22, 46, 9, 49, 58, 2, 44, 20, 31, 39, + 18, 42, 33, 25, 55, 15, 4, 60, 27, 35, 40, 16, 62, 6, 13, 53, + 36, 28, 23, 47, 1, 57, 50, 10, 45, 21, 30, 38, 8, 48, 59, 3, + 54, 14, 5, 61, 19, 43, 32, 24, 63, 7, 12, 52, 26, 34, 41, 17, + 0, 28, 56, 36, 51, 47, 11, 23, 37, 57, 29, 1, 22, 10, 46, 50, + 9, 21, 49, 45, 58, 38, 2, 30, 44, 48, 20, 8, 31, 3, 39, 59, + 18, 14, 42, 54, 33, 61, 25, 5, 55, 43, 15, 19, 4, 24, 60, 32, + 27, 7, 35, 63, 40, 52, 16, 12, 62, 34, 6, 26, 13, 17, 53, 41, + 0, 14, 28, 18, 56, 54, 36, 42, 51, 61, 47, 33, 11, 5, 23, 25, + 37, 43, 57, 55, 29, 19, 1, 15, 22, 24, 10, 4, 46, 32, 50, 60, + 9, 7, 21, 27, 49, 63, 45, 35, 58, 52, 38, 40, 2, 12, 30, 16, + 44, 34, 48, 62, 20, 26, 8, 6, 31, 17, 3, 13, 39, 41, 59, 53, + 0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45, + 51, 52, 61, 58, 47, 40, 33, 38, 11, 12, 5, 2, 23, 16, 25, 30, + 37, 34, 43, 44, 57, 62, 55, 48, 29, 26, 19, 20, 1, 6, 15, 8, + 22, 17, 24, 31, 10, 13, 4, 3, 46, 41, 32, 39, 50, 53, 60, 59, + 0, 34, 7, 37, 14, 44, 9, 43, 28, 62, 27, 57, 18, 48, 21, 55, + 56, 26, 63, 29, 54, 20, 49, 19, 36, 6, 35, 1, 42, 8, 45, 15, + 51, 17, 52, 22, 61, 31, 58, 24, 47, 13, 40, 10, 33, 3, 38, 4, + 11, 41, 12, 46, 5, 39, 2, 32, 23, 53, 16, 50, 25, 59, 30, 60, + 0, 17, 34, 51, 7, 22, 37, 52, 14, 31, 44, 61, 9, 24, 43, 58, + 28, 13, 62, 47, 27, 10, 57, 40, 18, 3, 48, 33, 21, 4, 55, 38, + 56, 41, 26, 11, 63, 46, 29, 12, 54, 39, 20, 5, 49, 32, 19, 2, + 36, 53, 6, 23, 35, 50, 1, 16, 42, 59, 8, 25, 45, 60, 15, 30, + 0, 41, 17, 56, 34, 11, 51, 26, 7, 46, 22, 63, 37, 12, 52, 29, + 14, 39, 31, 54, 44, 5, 61, 20, 9, 32, 24, 49, 43, 2, 58, 19, + 28, 53, 13, 36, 62, 23, 47, 6, 27, 50, 10, 35, 57, 16, 40, 1, + 18, 59, 3, 42, 48, 25, 33, 8, 21, 60, 4, 45, 55, 30, 38, 15, + 0, 53, 41, 28, 17, 36, 56, 13, 34, 23, 11, 62, 51, 6, 26, 47, + 7, 50, 46, 27, 22, 35, 63, 10, 37, 16, 12, 57, 52, 1, 29, 40, + 14, 59, 39, 18, 31, 42, 54, 3, 44, 25, 5, 48, 61, 8, 20, 33, + 9, 60, 32, 21, 24, 45, 49, 4, 43, 30, 2, 55, 58, 15, 19, 38, + 0, 59, 53, 14, 41, 18, 28, 39, 17, 42, 36, 31, 56, 3, 13, 54, + 34, 25, 23, 44, 11, 48, 62, 5, 51, 8, 6, 61, 26, 33, 47, 20, + 7, 60, 50, 9, 46, 21, 27, 32, 22, 45, 35, 24, 63, 4, 10, 49, + 37, 30, 16, 43, 12, 55, 57, 2, 52, 15, 1, 58, 29, 38, 40, 19, + 0, 60, 59, 7, 53, 9, 14, 50, 41, 21, 18, 46, 28, 32, 39, 27, + 17, 45, 42, 22, 36, 24, 31, 35, 56, 4, 3, 63, 13, 49, 54, 10, + 34, 30, 25, 37, 23, 43, 44, 16, 11, 55, 48, 12, 62, 2, 5, 57, + 51, 15, 8, 52, 6, 58, 61, 1, 26, 38, 33, 29, 47, 19, 20, 40, + 0, 30, 60, 34, 59, 37, 7, 25, 53, 43, 9, 23, 14, 16, 50, 44, + 41, 55, 21, 11, 18, 12, 46, 48, 28, 2, 32, 62, 39, 57, 27, 5, + 17, 15, 45, 51, 42, 52, 22, 8, 36, 58, 24, 6, 31, 1, 35, 61, + 56, 38, 4, 26, 3, 29, 63, 33, 13, 19, 49, 47, 54, 40, 10, 20, + 0, 15, 30, 17, 60, 51, 34, 45, 59, 52, 37, 42, 7, 8, 25, 22, + 53, 58, 43, 36, 9, 6, 23, 24, 14, 1, 16, 31, 50, 61, 44, 35, + 41, 38, 55, 56, 21, 26, 11, 4, 18, 29, 12, 3, 46, 33, 48, 63, + 28, 19, 2, 13, 32, 47, 62, 49, 39, 40, 57, 54, 27, 20, 5, 10, + 0, 38, 15, 41, 30, 56, 17, 55, 60, 26, 51, 21, 34, 4, 45, 11, + 59, 29, 52, 18, 37, 3, 42, 12, 7, 33, 8, 46, 25, 63, 22, 48, + 53, 19, 58, 28, 43, 13, 36, 2, 9, 47, 6, 32, 23, 49, 24, 62, + 14, 40, 1, 39, 16, 54, 31, 57, 50, 20, 61, 27, 44, 10, 35, 5, + 0, 19, 38, 53, 15, 28, 41, 58, 30, 13, 56, 43, 17, 2, 55, 36, + 60, 47, 26, 9, 51, 32, 21, 6, 34, 49, 4, 23, 45, 62, 11, 24, + 59, 40, 29, 14, 52, 39, 18, 1, 37, 54, 3, 16, 42, 57, 12, 31, + 7, 20, 33, 50, 8, 27, 46, 61, 25, 10, 63, 44, 22, 5, 48, 35, + 0, 40, 19, 59, 38, 14, 53, 29, 15, 39, 28, 52, 41, 1, 58, 18, + 30, 54, 13, 37, 56, 16, 43, 3, 17, 57, 2, 42, 55, 31, 36, 12, + 60, 20, 47, 7, 26, 50, 9, 33, 51, 27, 32, 8, 21, 61, 6, 46, + 34, 10, 49, 25, 4, 44, 23, 63, 45, 5, 62, 22, 11, 35, 24, 48, + 0, 20, 40, 60, 19, 7, 59, 47, 38, 50, 14, 26, 53, 33, 29, 9, + 15, 27, 39, 51, 28, 8, 52, 32, 41, 61, 1, 21, 58, 46, 18, 6, + 30, 10, 54, 34, 13, 25, 37, 49, 56, 44, 16, 4, 43, 63, 3, 23, + 17, 5, 57, 45, 2, 22, 42, 62, 55, 35, 31, 11, 36, 48, 12, 24, + 0, 10, 20, 30, 40, 34, 60, 54, 19, 25, 7, 13, 59, 49, 47, 37, + 38, 44, 50, 56, 14, 4, 26, 16, 53, 63, 33, 43, 29, 23, 9, 3, + 15, 5, 27, 17, 39, 45, 51, 57, 28, 22, 8, 2, 52, 62, 32, 42, + 41, 35, 61, 55, 1, 11, 21, 31, 58, 48, 46, 36, 18, 24, 6, 12, + 0, 5, 10, 15, 20, 17, 30, 27, 40, 45, 34, 39, 60, 57, 54, 51, + 19, 22, 25, 28, 7, 2, 13, 8, 59, 62, 49, 52, 47, 42, 37, 32, + 38, 35, 44, 41, 50, 55, 56, 61, 14, 11, 4, 1, 26, 31, 16, 21, + 53, 48, 63, 58, 33, 36, 43, 46, 29, 24, 23, 18, 9, 12, 3, 6, + 0, 35, 5, 38, 10, 41, 15, 44, 20, 55, 17, 50, 30, 61, 27, 56, + 40, 11, 45, 14, 34, 1, 39, 4, 60, 31, 57, 26, 54, 21, 51, 16, + 19, 48, 22, 53, 25, 58, 28, 63, 7, 36, 2, 33, 13, 46, 8, 43, + 59, 24, 62, 29, 49, 18, 52, 23, 47, 12, 42, 9, 37, 6, 32, 3, + 0, 48, 35, 19, 5, 53, 38, 22, 10, 58, 41, 25, 15, 63, 44, 28, + 20, 36, 55, 7, 17, 33, 50, 2, 30, 46, 61, 13, 27, 43, 56, 8, + 40, 24, 11, 59, 45, 29, 14, 62, 34, 18, 1, 49, 39, 23, 4, 52, + 60, 12, 31, 47, 57, 9, 26, 42, 54, 6, 21, 37, 51, 3, 16, 32, + 0, 24, 48, 40, 35, 59, 19, 11, 5, 29, 53, 45, 38, 62, 22, 14, + 10, 18, 58, 34, 41, 49, 25, 1, 15, 23, 63, 39, 44, 52, 28, 4, + 20, 12, 36, 60, 55, 47, 7, 31, 17, 9, 33, 57, 50, 42, 2, 26, + 30, 6, 46, 54, 61, 37, 13, 21, 27, 3, 43, 51, 56, 32, 8, 16, + 0, 12, 24, 20, 48, 60, 40, 36, 35, 47, 59, 55, 19, 31, 11, 7, + 5, 9, 29, 17, 53, 57, 45, 33, 38, 42, 62, 50, 22, 26, 14, 2, + 10, 6, 18, 30, 58, 54, 34, 46, 41, 37, 49, 61, 25, 21, 1, 13, + 15, 3, 23, 27, 63, 51, 39, 43, 44, 32, 52, 56, 28, 16, 4, 8, + 0, 6, 12, 10, 24, 30, 20, 18, 48, 54, 60, 58, 40, 46, 36, 34, + 35, 37, 47, 41, 59, 61, 55, 49, 19, 21, 31, 25, 11, 13, 7, 1, + 5, 3, 9, 15, 29, 27, 17, 23, 53, 51, 57, 63, 45, 43, 33, 39, + 38, 32, 42, 44, 62, 56, 50, 52, 22, 16, 26, 28, 14, 8, 2, 4, + 0, 3, 6, 5, 12, 15, 10, 9, 24, 27, 30, 29, 20, 23, 18, 17, + 48, 51, 54, 53, 60, 63, 58, 57, 40, 43, 46, 45, 36, 39, 34, 33, + 35, 32, 37, 38, 47, 44, 41, 42, 59, 56, 61, 62, 55, 52, 49, 50, + 19, 16, 21, 22, 31, 28, 25, 26, 11, 8, 13, 14, 7, 4, 1, 2, + 0, 32, 3, 35, 6, 38, 5, 37, 12, 44, 15, 47, 10, 42, 9, 41, + 24, 56, 27, 59, 30, 62, 29, 61, 20, 52, 23, 55, 18, 50, 17, 49, + 48, 16, 51, 19, 54, 22, 53, 21, 60, 28, 63, 31, 58, 26, 57, 25, + 40, 8, 43, 11, 46, 14, 45, 13, 36, 4, 39, 7, 34, 2, 33, 1, + 0, 16, 32, 48, 3, 19, 35, 51, 6, 22, 38, 54, 5, 21, 37, 53, + 12, 28, 44, 60, 15, 31, 47, 63, 10, 26, 42, 58, 9, 25, 41, 57, + 24, 8, 56, 40, 27, 11, 59, 43, 30, 14, 62, 46, 29, 13, 61, 45, + 20, 4, 52, 36, 23, 7, 55, 39, 18, 2, 50, 34, 17, 1, 49, 33, + 0, 8, 16, 24, 32, 40, 48, 56, 3, 11, 19, 27, 35, 43, 51, 59, + 6, 14, 22, 30, 38, 46, 54, 62, 5, 13, 21, 29, 37, 45, 53, 61, + 12, 4, 28, 20, 44, 36, 60, 52, 15, 7, 31, 23, 47, 39, 63, 55, + 10, 2, 26, 18, 42, 34, 58, 50, 9, 1, 25, 17, 41, 33, 57, 49, + 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, + 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, + 6, 2, 14, 10, 22, 18, 30, 26, 38, 34, 46, 42, 54, 50, 62, 58, + 5, 1, 13, 9, 21, 17, 29, 25, 37, 33, 45, 41, 53, 49, 61, 57, + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, + 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, + 3, 1, 7, 5, 11, 9, 15, 13, 19, 17, 23, 21, 27, 25, 31, 29, + 35, 33, 39, 37, 43, 41, 47, 45, 51, 49, 55, 53, 59, 57, 63, 61 +}; + +const qracode qra_12_63_64_irr_b = { + qra_K, + qra_N, + qra_m, + qra_M, + qra_a, + qra_NC, + qra_V, + qra_C, + qra_NMSG, + qra_MAXVDEG, + qra_MAXCDEG, + QRATYPE_NORMAL, + qra_R, + CODE_NAME, + qra_acc_input_idx, + qra_acc_input_wlog, + qra_log, + qra_exp, + qra_msgw, + qra_vdeg, + qra_cdeg, + qra_v2cmidx, + qra_c2vmidx, + qra_pmat +}; + +#undef qra_K +#undef qra_N +#undef qra_m +#undef qra_M +#undef qra_a +#undef qra_NC +#undef qra_V +#undef qra_C +#undef qra_NMSG +#undef qra_MAXVDEG +#undef qra_MAXCDEG +#undef qra_R #undef CODE_NAME \ No newline at end of file diff --git a/lib/qra/qracodes/qra12_63_64_irr_b.h b/lib/qra/qracodes/qra12_63_64_irr_b.h index 3641e4d8..bf70b360 100755 --- a/lib/qra/qracodes/qra12_63_64_irr_b.h +++ b/lib/qra/qracodes/qra12_63_64_irr_b.h @@ -1,39 +1,39 @@ -// qra12_63_64_irr_b.h -// Code tables and defines for Q-ary RA code (12,63) over GF(64) -// Code Name: qra12_63_64_irr_b -// (12,63) RA Code over GF(64) - RF=333344455567 - -// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy - -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#ifndef _qra12_63_64_irr_b_h -#define _qra12_63_64_irr_b_h - -#include "qracodes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern const qracode qra_12_63_64_irr_b; - -#ifdef __cplusplus -} -#endif - -#endif // _qra12_63_64_irr_b_h +// qra12_63_64_irr_b.h +// Code tables and defines for Q-ary RA code (12,63) over GF(64) +// Code Name: qra12_63_64_irr_b +// (12,63) RA Code over GF(64) - RF=333344455567 + +// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy + +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#ifndef _qra12_63_64_irr_b_h +#define _qra12_63_64_irr_b_h + +#include "qracodes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const qracode qra_12_63_64_irr_b; + +#ifdef __cplusplus +} +#endif + +#endif // _qra12_63_64_irr_b_h diff --git a/lib/qra/qracodes/qra13_64_64_irr_e.c b/lib/qra/qracodes/qra13_64_64_irr_e.c index 07dac350..7adf22fe 100755 --- a/lib/qra/qracodes/qra13_64_64_irr_e.c +++ b/lib/qra/qracodes/qra13_64_64_irr_e.c @@ -1,534 +1,534 @@ -// qra13_64_64_irr_e.c -// Encoding/Decoding tables for Q-ary RA code (13,64) over GF(64) -// Code Name: qra13_64_64_irr_e -// (13,64) RA Code over GF(64) RF=[3x4 4x4 6x1 3x2 5x1 7x1]/18 - -// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy - -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#include "qra13_64_64_irr_e.h" - -#define qra_K 13 // number of information symbols -#define qra_N 64 // codeword length in symbols -#define qra_m 6 // bits/symbol -#define qra_M 64 // Symbol alphabet cardinality -#define qra_a 1 // grouping factor -#define qra_NC 51 // number of check symbols (N-K) - -// Defines used by the message passing decoder -------- - -#define qra_V 64 // number of variables in the code graph (N) -#define qra_C 116 // number of factors in the code graph (N +(N-K)+1) -#define qra_NMSG 218 // number of msgs in the code graph -#define qra_MAXVDEG 8 // maximum variable degree -#define qra_MAXCDEG 3 // maximum factor degree -#define qra_R 0.20313f // code rate (K/N) -#define CODE_NAME "qra_13_64_64_irr_e" - -// table of the systematic symbols indexes in the accumulator chain -static const int qra_acc_input_idx[qra_NC+1] = { - 12, 4, 3, 9, 0, 11, 6, 8, 12, 1, - 2, 7, 4, 11, 3, 5, 9, 8, 12, 7, - 2, 4, 10, 3, 5, 11, 12, 8, 9, 6, - 7, 2, 5, 4, 12, 8, 11, 1, 6, 7, - 0, 10, 12, 8, 11, 5, 6, 1, 0, 10, - 12, 8 -}; - -// table of the systematic symbols weight logarithms over GF(M) -static const int qra_acc_input_wlog[qra_NC+1] = { - 0, 27, 0, 0, 0, 31, 28, 61, 31, 0, - 0, 52, 22, 7, 19, 47, 44, 62, 32, 50, - 52, 42, 48, 56, 40, 50, 51, 37, 37, 0, - 5, 14, 0, 0, 18, 2, 0, 45, 21, 0, - 62, 8, 11, 60, 36, 32, 17, 9, 5, 0, - 53, 0 -}; - -// table of the logarithms of the elements of GF(M) (log(0) never used) -static const int qra_log[qra_M] = { - -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, - 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, - 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, - 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, - 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, - 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, - 20, 59, 57, 58 -}; - -// table of GF(M) elements given their logarithm -static const int qra_exp[qra_M-1] = { - 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, - 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, - 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, - 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, - 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, - 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, - 57, 49, 33 -}; - -// table of the messages weight logarithms over GF(M) -static const int qra_msgw[qra_NMSG] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 27, 0, 0, 0, 31, - 28, 61, 31, 0, 0, 52, 22, 7, 19, 47, - 44, 62, 32, 50, 52, 42, 48, 56, 40, 50, - 51, 37, 37, 0, 5, 14, 0, 0, 18, 2, - 0, 45, 21, 0, 62, 8, 11, 60, 36, 32, - 17, 9, 5, 0, 53, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; - -// table of the degrees of the variable nodes -static const int qra_vdeg[qra_V] = { - 4, 4, 4, 4, 5, 5, 5, 5, 7, 4, - 4, 6, 8, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3 -}; - -// table of the degrees of the factor nodes -static const int qra_cdeg[qra_C] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 2, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 2 -}; - -// table (uncompressed) of the v->c message indexes (-1=unused entry) -static const int qra_v2cmidx[qra_V*qra_MAXVDEG] = { - 0, 68, 104, 112, -1, -1, -1, -1, - 1, 73, 101, 111, -1, -1, -1, -1, - 2, 74, 84, 95, -1, -1, -1, -1, - 3, 66, 78, 87, -1, -1, -1, -1, - 4, 65, 76, 85, 97, -1, -1, -1, - 5, 79, 88, 96, 109, -1, -1, -1, - 6, 70, 93, 102, 110, -1, -1, -1, - 7, 75, 83, 94, 103, -1, -1, -1, - 8, 71, 81, 91, 99, 107, 115, -1, - 9, 67, 80, 92, -1, -1, -1, -1, - 10, 86, 105, 113, -1, -1, -1, -1, - 11, 69, 77, 89, 100, 108, -1, -1, - 12, 64, 72, 82, 90, 98, 106, 114, - 13, 116, 117, -1, -1, -1, -1, -1, - 14, 118, 119, -1, -1, -1, -1, -1, - 15, 120, 121, -1, -1, -1, -1, -1, - 16, 122, 123, -1, -1, -1, -1, -1, - 17, 124, 125, -1, -1, -1, -1, -1, - 18, 126, 127, -1, -1, -1, -1, -1, - 19, 128, 129, -1, -1, -1, -1, -1, - 20, 130, 131, -1, -1, -1, -1, -1, - 21, 132, 133, -1, -1, -1, -1, -1, - 22, 134, 135, -1, -1, -1, -1, -1, - 23, 136, 137, -1, -1, -1, -1, -1, - 24, 138, 139, -1, -1, -1, -1, -1, - 25, 140, 141, -1, -1, -1, -1, -1, - 26, 142, 143, -1, -1, -1, -1, -1, - 27, 144, 145, -1, -1, -1, -1, -1, - 28, 146, 147, -1, -1, -1, -1, -1, - 29, 148, 149, -1, -1, -1, -1, -1, - 30, 150, 151, -1, -1, -1, -1, -1, - 31, 152, 153, -1, -1, -1, -1, -1, - 32, 154, 155, -1, -1, -1, -1, -1, - 33, 156, 157, -1, -1, -1, -1, -1, - 34, 158, 159, -1, -1, -1, -1, -1, - 35, 160, 161, -1, -1, -1, -1, -1, - 36, 162, 163, -1, -1, -1, -1, -1, - 37, 164, 165, -1, -1, -1, -1, -1, - 38, 166, 167, -1, -1, -1, -1, -1, - 39, 168, 169, -1, -1, -1, -1, -1, - 40, 170, 171, -1, -1, -1, -1, -1, - 41, 172, 173, -1, -1, -1, -1, -1, - 42, 174, 175, -1, -1, -1, -1, -1, - 43, 176, 177, -1, -1, -1, -1, -1, - 44, 178, 179, -1, -1, -1, -1, -1, - 45, 180, 181, -1, -1, -1, -1, -1, - 46, 182, 183, -1, -1, -1, -1, -1, - 47, 184, 185, -1, -1, -1, -1, -1, - 48, 186, 187, -1, -1, -1, -1, -1, - 49, 188, 189, -1, -1, -1, -1, -1, - 50, 190, 191, -1, -1, -1, -1, -1, - 51, 192, 193, -1, -1, -1, -1, -1, - 52, 194, 195, -1, -1, -1, -1, -1, - 53, 196, 197, -1, -1, -1, -1, -1, - 54, 198, 199, -1, -1, -1, -1, -1, - 55, 200, 201, -1, -1, -1, -1, -1, - 56, 202, 203, -1, -1, -1, -1, -1, - 57, 204, 205, -1, -1, -1, -1, -1, - 58, 206, 207, -1, -1, -1, -1, -1, - 59, 208, 209, -1, -1, -1, -1, -1, - 60, 210, 211, -1, -1, -1, -1, -1, - 61, 212, 213, -1, -1, -1, -1, -1, - 62, 214, 215, -1, -1, -1, -1, -1, - 63, 216, 217, -1, -1, -1, -1, -1 -}; - -// table (uncompressed) of the c->v message indexes (-1=unused entry) -static const int qra_c2vmidx[qra_C*qra_MAXCDEG] = { - 0, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1, - 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1, - 8, -1, -1, 9, -1, -1, 10, -1, -1, 11, -1, -1, - 12, -1, -1, 13, -1, -1, 14, -1, -1, 15, -1, -1, - 16, -1, -1, 17, -1, -1, 18, -1, -1, 19, -1, -1, - 20, -1, -1, 21, -1, -1, 22, -1, -1, 23, -1, -1, - 24, -1, -1, 25, -1, -1, 26, -1, -1, 27, -1, -1, - 28, -1, -1, 29, -1, -1, 30, -1, -1, 31, -1, -1, - 32, -1, -1, 33, -1, -1, 34, -1, -1, 35, -1, -1, - 36, -1, -1, 37, -1, -1, 38, -1, -1, 39, -1, -1, - 40, -1, -1, 41, -1, -1, 42, -1, -1, 43, -1, -1, - 44, -1, -1, 45, -1, -1, 46, -1, -1, 47, -1, -1, - 48, -1, -1, 49, -1, -1, 50, -1, -1, 51, -1, -1, - 52, -1, -1, 53, -1, -1, 54, -1, -1, 55, -1, -1, - 56, -1, -1, 57, -1, -1, 58, -1, -1, 59, -1, -1, - 60, -1, -1, 61, -1, -1, 62, -1, -1, 63, -1, -1, - 64, 116, -1, 65, 117, 118, 66, 119, 120, 67, 121, 122, - 68, 123, 124, 69, 125, 126, 70, 127, 128, 71, 129, 130, - 72, 131, 132, 73, 133, 134, 74, 135, 136, 75, 137, 138, - 76, 139, 140, 77, 141, 142, 78, 143, 144, 79, 145, 146, - 80, 147, 148, 81, 149, 150, 82, 151, 152, 83, 153, 154, - 84, 155, 156, 85, 157, 158, 86, 159, 160, 87, 161, 162, - 88, 163, 164, 89, 165, 166, 90, 167, 168, 91, 169, 170, - 92, 171, 172, 93, 173, 174, 94, 175, 176, 95, 177, 178, - 96, 179, 180, 97, 181, 182, 98, 183, 184, 99, 185, 186, -100, 187, 188, 101, 189, 190, 102, 191, 192, 103, 193, 194, -104, 195, 196, 105, 197, 198, 106, 199, 200, 107, 201, 202, -108, 203, 204, 109, 205, 206, 110, 207, 208, 111, 209, 210, -112, 211, 212, 113, 213, 214, 114, 215, 216, 115, 217, -1 -}; - -// permutation matrix to compute Prob(x*alfa^logw) -static const int qra_pmat[qra_M*qra_M] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 0, 33, 1, 32, 2, 35, 3, 34, 4, 37, 5, 36, 6, 39, 7, 38, - 8, 41, 9, 40, 10, 43, 11, 42, 12, 45, 13, 44, 14, 47, 15, 46, - 16, 49, 17, 48, 18, 51, 19, 50, 20, 53, 21, 52, 22, 55, 23, 54, - 24, 57, 25, 56, 26, 59, 27, 58, 28, 61, 29, 60, 30, 63, 31, 62, - 0, 49, 33, 16, 1, 48, 32, 17, 2, 51, 35, 18, 3, 50, 34, 19, - 4, 53, 37, 20, 5, 52, 36, 21, 6, 55, 39, 22, 7, 54, 38, 23, - 8, 57, 41, 24, 9, 56, 40, 25, 10, 59, 43, 26, 11, 58, 42, 27, - 12, 61, 45, 28, 13, 60, 44, 29, 14, 63, 47, 30, 15, 62, 46, 31, - 0, 57, 49, 8, 33, 24, 16, 41, 1, 56, 48, 9, 32, 25, 17, 40, - 2, 59, 51, 10, 35, 26, 18, 43, 3, 58, 50, 11, 34, 27, 19, 42, - 4, 61, 53, 12, 37, 28, 20, 45, 5, 60, 52, 13, 36, 29, 21, 44, - 6, 63, 55, 14, 39, 30, 22, 47, 7, 62, 54, 15, 38, 31, 23, 46, - 0, 61, 57, 4, 49, 12, 8, 53, 33, 28, 24, 37, 16, 45, 41, 20, - 1, 60, 56, 5, 48, 13, 9, 52, 32, 29, 25, 36, 17, 44, 40, 21, - 2, 63, 59, 6, 51, 14, 10, 55, 35, 30, 26, 39, 18, 47, 43, 22, - 3, 62, 58, 7, 50, 15, 11, 54, 34, 31, 27, 38, 19, 46, 42, 23, - 0, 63, 61, 2, 57, 6, 4, 59, 49, 14, 12, 51, 8, 55, 53, 10, - 33, 30, 28, 35, 24, 39, 37, 26, 16, 47, 45, 18, 41, 22, 20, 43, - 1, 62, 60, 3, 56, 7, 5, 58, 48, 15, 13, 50, 9, 54, 52, 11, - 32, 31, 29, 34, 25, 38, 36, 27, 17, 46, 44, 19, 40, 23, 21, 42, - 0, 62, 63, 1, 61, 3, 2, 60, 57, 7, 6, 56, 4, 58, 59, 5, - 49, 15, 14, 48, 12, 50, 51, 13, 8, 54, 55, 9, 53, 11, 10, 52, - 33, 31, 30, 32, 28, 34, 35, 29, 24, 38, 39, 25, 37, 27, 26, 36, - 16, 46, 47, 17, 45, 19, 18, 44, 41, 23, 22, 40, 20, 42, 43, 21, - 0, 31, 62, 33, 63, 32, 1, 30, 61, 34, 3, 28, 2, 29, 60, 35, - 57, 38, 7, 24, 6, 25, 56, 39, 4, 27, 58, 37, 59, 36, 5, 26, - 49, 46, 15, 16, 14, 17, 48, 47, 12, 19, 50, 45, 51, 44, 13, 18, - 8, 23, 54, 41, 55, 40, 9, 22, 53, 42, 11, 20, 10, 21, 52, 43, - 0, 46, 31, 49, 62, 16, 33, 15, 63, 17, 32, 14, 1, 47, 30, 48, - 61, 19, 34, 12, 3, 45, 28, 50, 2, 44, 29, 51, 60, 18, 35, 13, - 57, 23, 38, 8, 7, 41, 24, 54, 6, 40, 25, 55, 56, 22, 39, 9, - 4, 42, 27, 53, 58, 20, 37, 11, 59, 21, 36, 10, 5, 43, 26, 52, - 0, 23, 46, 57, 31, 8, 49, 38, 62, 41, 16, 7, 33, 54, 15, 24, - 63, 40, 17, 6, 32, 55, 14, 25, 1, 22, 47, 56, 30, 9, 48, 39, - 61, 42, 19, 4, 34, 53, 12, 27, 3, 20, 45, 58, 28, 11, 50, 37, - 2, 21, 44, 59, 29, 10, 51, 36, 60, 43, 18, 5, 35, 52, 13, 26, - 0, 42, 23, 61, 46, 4, 57, 19, 31, 53, 8, 34, 49, 27, 38, 12, - 62, 20, 41, 3, 16, 58, 7, 45, 33, 11, 54, 28, 15, 37, 24, 50, - 63, 21, 40, 2, 17, 59, 6, 44, 32, 10, 55, 29, 14, 36, 25, 51, - 1, 43, 22, 60, 47, 5, 56, 18, 30, 52, 9, 35, 48, 26, 39, 13, - 0, 21, 42, 63, 23, 2, 61, 40, 46, 59, 4, 17, 57, 44, 19, 6, - 31, 10, 53, 32, 8, 29, 34, 55, 49, 36, 27, 14, 38, 51, 12, 25, - 62, 43, 20, 1, 41, 60, 3, 22, 16, 5, 58, 47, 7, 18, 45, 56, - 33, 52, 11, 30, 54, 35, 28, 9, 15, 26, 37, 48, 24, 13, 50, 39, - 0, 43, 21, 62, 42, 1, 63, 20, 23, 60, 2, 41, 61, 22, 40, 3, - 46, 5, 59, 16, 4, 47, 17, 58, 57, 18, 44, 7, 19, 56, 6, 45, - 31, 52, 10, 33, 53, 30, 32, 11, 8, 35, 29, 54, 34, 9, 55, 28, - 49, 26, 36, 15, 27, 48, 14, 37, 38, 13, 51, 24, 12, 39, 25, 50, - 0, 52, 43, 31, 21, 33, 62, 10, 42, 30, 1, 53, 63, 11, 20, 32, - 23, 35, 60, 8, 2, 54, 41, 29, 61, 9, 22, 34, 40, 28, 3, 55, - 46, 26, 5, 49, 59, 15, 16, 36, 4, 48, 47, 27, 17, 37, 58, 14, - 57, 13, 18, 38, 44, 24, 7, 51, 19, 39, 56, 12, 6, 50, 45, 25, - 0, 26, 52, 46, 43, 49, 31, 5, 21, 15, 33, 59, 62, 36, 10, 16, - 42, 48, 30, 4, 1, 27, 53, 47, 63, 37, 11, 17, 20, 14, 32, 58, - 23, 13, 35, 57, 60, 38, 8, 18, 2, 24, 54, 44, 41, 51, 29, 7, - 61, 39, 9, 19, 22, 12, 34, 56, 40, 50, 28, 6, 3, 25, 55, 45, - 0, 13, 26, 23, 52, 57, 46, 35, 43, 38, 49, 60, 31, 18, 5, 8, - 21, 24, 15, 2, 33, 44, 59, 54, 62, 51, 36, 41, 10, 7, 16, 29, - 42, 39, 48, 61, 30, 19, 4, 9, 1, 12, 27, 22, 53, 56, 47, 34, - 63, 50, 37, 40, 11, 6, 17, 28, 20, 25, 14, 3, 32, 45, 58, 55, - 0, 39, 13, 42, 26, 61, 23, 48, 52, 19, 57, 30, 46, 9, 35, 4, - 43, 12, 38, 1, 49, 22, 60, 27, 31, 56, 18, 53, 5, 34, 8, 47, - 21, 50, 24, 63, 15, 40, 2, 37, 33, 6, 44, 11, 59, 28, 54, 17, - 62, 25, 51, 20, 36, 3, 41, 14, 10, 45, 7, 32, 16, 55, 29, 58, - 0, 50, 39, 21, 13, 63, 42, 24, 26, 40, 61, 15, 23, 37, 48, 2, - 52, 6, 19, 33, 57, 11, 30, 44, 46, 28, 9, 59, 35, 17, 4, 54, - 43, 25, 12, 62, 38, 20, 1, 51, 49, 3, 22, 36, 60, 14, 27, 41, - 31, 45, 56, 10, 18, 32, 53, 7, 5, 55, 34, 16, 8, 58, 47, 29, - 0, 25, 50, 43, 39, 62, 21, 12, 13, 20, 63, 38, 42, 51, 24, 1, - 26, 3, 40, 49, 61, 36, 15, 22, 23, 14, 37, 60, 48, 41, 2, 27, - 52, 45, 6, 31, 19, 10, 33, 56, 57, 32, 11, 18, 30, 7, 44, 53, - 46, 55, 28, 5, 9, 16, 59, 34, 35, 58, 17, 8, 4, 29, 54, 47, - 0, 45, 25, 52, 50, 31, 43, 6, 39, 10, 62, 19, 21, 56, 12, 33, - 13, 32, 20, 57, 63, 18, 38, 11, 42, 7, 51, 30, 24, 53, 1, 44, - 26, 55, 3, 46, 40, 5, 49, 28, 61, 16, 36, 9, 15, 34, 22, 59, - 23, 58, 14, 35, 37, 8, 60, 17, 48, 29, 41, 4, 2, 47, 27, 54, - 0, 55, 45, 26, 25, 46, 52, 3, 50, 5, 31, 40, 43, 28, 6, 49, - 39, 16, 10, 61, 62, 9, 19, 36, 21, 34, 56, 15, 12, 59, 33, 22, - 13, 58, 32, 23, 20, 35, 57, 14, 63, 8, 18, 37, 38, 17, 11, 60, - 42, 29, 7, 48, 51, 4, 30, 41, 24, 47, 53, 2, 1, 54, 44, 27, - 0, 58, 55, 13, 45, 23, 26, 32, 25, 35, 46, 20, 52, 14, 3, 57, - 50, 8, 5, 63, 31, 37, 40, 18, 43, 17, 28, 38, 6, 60, 49, 11, - 39, 29, 16, 42, 10, 48, 61, 7, 62, 4, 9, 51, 19, 41, 36, 30, - 21, 47, 34, 24, 56, 2, 15, 53, 12, 54, 59, 1, 33, 27, 22, 44, - 0, 29, 58, 39, 55, 42, 13, 16, 45, 48, 23, 10, 26, 7, 32, 61, - 25, 4, 35, 62, 46, 51, 20, 9, 52, 41, 14, 19, 3, 30, 57, 36, - 50, 47, 8, 21, 5, 24, 63, 34, 31, 2, 37, 56, 40, 53, 18, 15, - 43, 54, 17, 12, 28, 1, 38, 59, 6, 27, 60, 33, 49, 44, 11, 22, - 0, 47, 29, 50, 58, 21, 39, 8, 55, 24, 42, 5, 13, 34, 16, 63, - 45, 2, 48, 31, 23, 56, 10, 37, 26, 53, 7, 40, 32, 15, 61, 18, - 25, 54, 4, 43, 35, 12, 62, 17, 46, 1, 51, 28, 20, 59, 9, 38, - 52, 27, 41, 6, 14, 33, 19, 60, 3, 44, 30, 49, 57, 22, 36, 11, - 0, 54, 47, 25, 29, 43, 50, 4, 58, 12, 21, 35, 39, 17, 8, 62, - 55, 1, 24, 46, 42, 28, 5, 51, 13, 59, 34, 20, 16, 38, 63, 9, - 45, 27, 2, 52, 48, 6, 31, 41, 23, 33, 56, 14, 10, 60, 37, 19, - 26, 44, 53, 3, 7, 49, 40, 30, 32, 22, 15, 57, 61, 11, 18, 36, - 0, 27, 54, 45, 47, 52, 25, 2, 29, 6, 43, 48, 50, 41, 4, 31, - 58, 33, 12, 23, 21, 14, 35, 56, 39, 60, 17, 10, 8, 19, 62, 37, - 55, 44, 1, 26, 24, 3, 46, 53, 42, 49, 28, 7, 5, 30, 51, 40, - 13, 22, 59, 32, 34, 57, 20, 15, 16, 11, 38, 61, 63, 36, 9, 18, - 0, 44, 27, 55, 54, 26, 45, 1, 47, 3, 52, 24, 25, 53, 2, 46, - 29, 49, 6, 42, 43, 7, 48, 28, 50, 30, 41, 5, 4, 40, 31, 51, - 58, 22, 33, 13, 12, 32, 23, 59, 21, 57, 14, 34, 35, 15, 56, 20, - 39, 11, 60, 16, 17, 61, 10, 38, 8, 36, 19, 63, 62, 18, 37, 9, - 0, 22, 44, 58, 27, 13, 55, 33, 54, 32, 26, 12, 45, 59, 1, 23, - 47, 57, 3, 21, 52, 34, 24, 14, 25, 15, 53, 35, 2, 20, 46, 56, - 29, 11, 49, 39, 6, 16, 42, 60, 43, 61, 7, 17, 48, 38, 28, 10, - 50, 36, 30, 8, 41, 63, 5, 19, 4, 18, 40, 62, 31, 9, 51, 37, - 0, 11, 22, 29, 44, 39, 58, 49, 27, 16, 13, 6, 55, 60, 33, 42, - 54, 61, 32, 43, 26, 17, 12, 7, 45, 38, 59, 48, 1, 10, 23, 28, - 47, 36, 57, 50, 3, 8, 21, 30, 52, 63, 34, 41, 24, 19, 14, 5, - 25, 18, 15, 4, 53, 62, 35, 40, 2, 9, 20, 31, 46, 37, 56, 51, - 0, 36, 11, 47, 22, 50, 29, 57, 44, 8, 39, 3, 58, 30, 49, 21, - 27, 63, 16, 52, 13, 41, 6, 34, 55, 19, 60, 24, 33, 5, 42, 14, - 54, 18, 61, 25, 32, 4, 43, 15, 26, 62, 17, 53, 12, 40, 7, 35, - 45, 9, 38, 2, 59, 31, 48, 20, 1, 37, 10, 46, 23, 51, 28, 56, - 0, 18, 36, 54, 11, 25, 47, 61, 22, 4, 50, 32, 29, 15, 57, 43, - 44, 62, 8, 26, 39, 53, 3, 17, 58, 40, 30, 12, 49, 35, 21, 7, - 27, 9, 63, 45, 16, 2, 52, 38, 13, 31, 41, 59, 6, 20, 34, 48, - 55, 37, 19, 1, 60, 46, 24, 10, 33, 51, 5, 23, 42, 56, 14, 28, - 0, 9, 18, 27, 36, 45, 54, 63, 11, 2, 25, 16, 47, 38, 61, 52, - 22, 31, 4, 13, 50, 59, 32, 41, 29, 20, 15, 6, 57, 48, 43, 34, - 44, 37, 62, 55, 8, 1, 26, 19, 39, 46, 53, 60, 3, 10, 17, 24, - 58, 51, 40, 33, 30, 23, 12, 5, 49, 56, 35, 42, 21, 28, 7, 14, - 0, 37, 9, 44, 18, 55, 27, 62, 36, 1, 45, 8, 54, 19, 63, 26, - 11, 46, 2, 39, 25, 60, 16, 53, 47, 10, 38, 3, 61, 24, 52, 17, - 22, 51, 31, 58, 4, 33, 13, 40, 50, 23, 59, 30, 32, 5, 41, 12, - 29, 56, 20, 49, 15, 42, 6, 35, 57, 28, 48, 21, 43, 14, 34, 7, - 0, 51, 37, 22, 9, 58, 44, 31, 18, 33, 55, 4, 27, 40, 62, 13, - 36, 23, 1, 50, 45, 30, 8, 59, 54, 5, 19, 32, 63, 12, 26, 41, - 11, 56, 46, 29, 2, 49, 39, 20, 25, 42, 60, 15, 16, 35, 53, 6, - 47, 28, 10, 57, 38, 21, 3, 48, 61, 14, 24, 43, 52, 7, 17, 34, - 0, 56, 51, 11, 37, 29, 22, 46, 9, 49, 58, 2, 44, 20, 31, 39, - 18, 42, 33, 25, 55, 15, 4, 60, 27, 35, 40, 16, 62, 6, 13, 53, - 36, 28, 23, 47, 1, 57, 50, 10, 45, 21, 30, 38, 8, 48, 59, 3, - 54, 14, 5, 61, 19, 43, 32, 24, 63, 7, 12, 52, 26, 34, 41, 17, - 0, 28, 56, 36, 51, 47, 11, 23, 37, 57, 29, 1, 22, 10, 46, 50, - 9, 21, 49, 45, 58, 38, 2, 30, 44, 48, 20, 8, 31, 3, 39, 59, - 18, 14, 42, 54, 33, 61, 25, 5, 55, 43, 15, 19, 4, 24, 60, 32, - 27, 7, 35, 63, 40, 52, 16, 12, 62, 34, 6, 26, 13, 17, 53, 41, - 0, 14, 28, 18, 56, 54, 36, 42, 51, 61, 47, 33, 11, 5, 23, 25, - 37, 43, 57, 55, 29, 19, 1, 15, 22, 24, 10, 4, 46, 32, 50, 60, - 9, 7, 21, 27, 49, 63, 45, 35, 58, 52, 38, 40, 2, 12, 30, 16, - 44, 34, 48, 62, 20, 26, 8, 6, 31, 17, 3, 13, 39, 41, 59, 53, - 0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45, - 51, 52, 61, 58, 47, 40, 33, 38, 11, 12, 5, 2, 23, 16, 25, 30, - 37, 34, 43, 44, 57, 62, 55, 48, 29, 26, 19, 20, 1, 6, 15, 8, - 22, 17, 24, 31, 10, 13, 4, 3, 46, 41, 32, 39, 50, 53, 60, 59, - 0, 34, 7, 37, 14, 44, 9, 43, 28, 62, 27, 57, 18, 48, 21, 55, - 56, 26, 63, 29, 54, 20, 49, 19, 36, 6, 35, 1, 42, 8, 45, 15, - 51, 17, 52, 22, 61, 31, 58, 24, 47, 13, 40, 10, 33, 3, 38, 4, - 11, 41, 12, 46, 5, 39, 2, 32, 23, 53, 16, 50, 25, 59, 30, 60, - 0, 17, 34, 51, 7, 22, 37, 52, 14, 31, 44, 61, 9, 24, 43, 58, - 28, 13, 62, 47, 27, 10, 57, 40, 18, 3, 48, 33, 21, 4, 55, 38, - 56, 41, 26, 11, 63, 46, 29, 12, 54, 39, 20, 5, 49, 32, 19, 2, - 36, 53, 6, 23, 35, 50, 1, 16, 42, 59, 8, 25, 45, 60, 15, 30, - 0, 41, 17, 56, 34, 11, 51, 26, 7, 46, 22, 63, 37, 12, 52, 29, - 14, 39, 31, 54, 44, 5, 61, 20, 9, 32, 24, 49, 43, 2, 58, 19, - 28, 53, 13, 36, 62, 23, 47, 6, 27, 50, 10, 35, 57, 16, 40, 1, - 18, 59, 3, 42, 48, 25, 33, 8, 21, 60, 4, 45, 55, 30, 38, 15, - 0, 53, 41, 28, 17, 36, 56, 13, 34, 23, 11, 62, 51, 6, 26, 47, - 7, 50, 46, 27, 22, 35, 63, 10, 37, 16, 12, 57, 52, 1, 29, 40, - 14, 59, 39, 18, 31, 42, 54, 3, 44, 25, 5, 48, 61, 8, 20, 33, - 9, 60, 32, 21, 24, 45, 49, 4, 43, 30, 2, 55, 58, 15, 19, 38, - 0, 59, 53, 14, 41, 18, 28, 39, 17, 42, 36, 31, 56, 3, 13, 54, - 34, 25, 23, 44, 11, 48, 62, 5, 51, 8, 6, 61, 26, 33, 47, 20, - 7, 60, 50, 9, 46, 21, 27, 32, 22, 45, 35, 24, 63, 4, 10, 49, - 37, 30, 16, 43, 12, 55, 57, 2, 52, 15, 1, 58, 29, 38, 40, 19, - 0, 60, 59, 7, 53, 9, 14, 50, 41, 21, 18, 46, 28, 32, 39, 27, - 17, 45, 42, 22, 36, 24, 31, 35, 56, 4, 3, 63, 13, 49, 54, 10, - 34, 30, 25, 37, 23, 43, 44, 16, 11, 55, 48, 12, 62, 2, 5, 57, - 51, 15, 8, 52, 6, 58, 61, 1, 26, 38, 33, 29, 47, 19, 20, 40, - 0, 30, 60, 34, 59, 37, 7, 25, 53, 43, 9, 23, 14, 16, 50, 44, - 41, 55, 21, 11, 18, 12, 46, 48, 28, 2, 32, 62, 39, 57, 27, 5, - 17, 15, 45, 51, 42, 52, 22, 8, 36, 58, 24, 6, 31, 1, 35, 61, - 56, 38, 4, 26, 3, 29, 63, 33, 13, 19, 49, 47, 54, 40, 10, 20, - 0, 15, 30, 17, 60, 51, 34, 45, 59, 52, 37, 42, 7, 8, 25, 22, - 53, 58, 43, 36, 9, 6, 23, 24, 14, 1, 16, 31, 50, 61, 44, 35, - 41, 38, 55, 56, 21, 26, 11, 4, 18, 29, 12, 3, 46, 33, 48, 63, - 28, 19, 2, 13, 32, 47, 62, 49, 39, 40, 57, 54, 27, 20, 5, 10, - 0, 38, 15, 41, 30, 56, 17, 55, 60, 26, 51, 21, 34, 4, 45, 11, - 59, 29, 52, 18, 37, 3, 42, 12, 7, 33, 8, 46, 25, 63, 22, 48, - 53, 19, 58, 28, 43, 13, 36, 2, 9, 47, 6, 32, 23, 49, 24, 62, - 14, 40, 1, 39, 16, 54, 31, 57, 50, 20, 61, 27, 44, 10, 35, 5, - 0, 19, 38, 53, 15, 28, 41, 58, 30, 13, 56, 43, 17, 2, 55, 36, - 60, 47, 26, 9, 51, 32, 21, 6, 34, 49, 4, 23, 45, 62, 11, 24, - 59, 40, 29, 14, 52, 39, 18, 1, 37, 54, 3, 16, 42, 57, 12, 31, - 7, 20, 33, 50, 8, 27, 46, 61, 25, 10, 63, 44, 22, 5, 48, 35, - 0, 40, 19, 59, 38, 14, 53, 29, 15, 39, 28, 52, 41, 1, 58, 18, - 30, 54, 13, 37, 56, 16, 43, 3, 17, 57, 2, 42, 55, 31, 36, 12, - 60, 20, 47, 7, 26, 50, 9, 33, 51, 27, 32, 8, 21, 61, 6, 46, - 34, 10, 49, 25, 4, 44, 23, 63, 45, 5, 62, 22, 11, 35, 24, 48, - 0, 20, 40, 60, 19, 7, 59, 47, 38, 50, 14, 26, 53, 33, 29, 9, - 15, 27, 39, 51, 28, 8, 52, 32, 41, 61, 1, 21, 58, 46, 18, 6, - 30, 10, 54, 34, 13, 25, 37, 49, 56, 44, 16, 4, 43, 63, 3, 23, - 17, 5, 57, 45, 2, 22, 42, 62, 55, 35, 31, 11, 36, 48, 12, 24, - 0, 10, 20, 30, 40, 34, 60, 54, 19, 25, 7, 13, 59, 49, 47, 37, - 38, 44, 50, 56, 14, 4, 26, 16, 53, 63, 33, 43, 29, 23, 9, 3, - 15, 5, 27, 17, 39, 45, 51, 57, 28, 22, 8, 2, 52, 62, 32, 42, - 41, 35, 61, 55, 1, 11, 21, 31, 58, 48, 46, 36, 18, 24, 6, 12, - 0, 5, 10, 15, 20, 17, 30, 27, 40, 45, 34, 39, 60, 57, 54, 51, - 19, 22, 25, 28, 7, 2, 13, 8, 59, 62, 49, 52, 47, 42, 37, 32, - 38, 35, 44, 41, 50, 55, 56, 61, 14, 11, 4, 1, 26, 31, 16, 21, - 53, 48, 63, 58, 33, 36, 43, 46, 29, 24, 23, 18, 9, 12, 3, 6, - 0, 35, 5, 38, 10, 41, 15, 44, 20, 55, 17, 50, 30, 61, 27, 56, - 40, 11, 45, 14, 34, 1, 39, 4, 60, 31, 57, 26, 54, 21, 51, 16, - 19, 48, 22, 53, 25, 58, 28, 63, 7, 36, 2, 33, 13, 46, 8, 43, - 59, 24, 62, 29, 49, 18, 52, 23, 47, 12, 42, 9, 37, 6, 32, 3, - 0, 48, 35, 19, 5, 53, 38, 22, 10, 58, 41, 25, 15, 63, 44, 28, - 20, 36, 55, 7, 17, 33, 50, 2, 30, 46, 61, 13, 27, 43, 56, 8, - 40, 24, 11, 59, 45, 29, 14, 62, 34, 18, 1, 49, 39, 23, 4, 52, - 60, 12, 31, 47, 57, 9, 26, 42, 54, 6, 21, 37, 51, 3, 16, 32, - 0, 24, 48, 40, 35, 59, 19, 11, 5, 29, 53, 45, 38, 62, 22, 14, - 10, 18, 58, 34, 41, 49, 25, 1, 15, 23, 63, 39, 44, 52, 28, 4, - 20, 12, 36, 60, 55, 47, 7, 31, 17, 9, 33, 57, 50, 42, 2, 26, - 30, 6, 46, 54, 61, 37, 13, 21, 27, 3, 43, 51, 56, 32, 8, 16, - 0, 12, 24, 20, 48, 60, 40, 36, 35, 47, 59, 55, 19, 31, 11, 7, - 5, 9, 29, 17, 53, 57, 45, 33, 38, 42, 62, 50, 22, 26, 14, 2, - 10, 6, 18, 30, 58, 54, 34, 46, 41, 37, 49, 61, 25, 21, 1, 13, - 15, 3, 23, 27, 63, 51, 39, 43, 44, 32, 52, 56, 28, 16, 4, 8, - 0, 6, 12, 10, 24, 30, 20, 18, 48, 54, 60, 58, 40, 46, 36, 34, - 35, 37, 47, 41, 59, 61, 55, 49, 19, 21, 31, 25, 11, 13, 7, 1, - 5, 3, 9, 15, 29, 27, 17, 23, 53, 51, 57, 63, 45, 43, 33, 39, - 38, 32, 42, 44, 62, 56, 50, 52, 22, 16, 26, 28, 14, 8, 2, 4, - 0, 3, 6, 5, 12, 15, 10, 9, 24, 27, 30, 29, 20, 23, 18, 17, - 48, 51, 54, 53, 60, 63, 58, 57, 40, 43, 46, 45, 36, 39, 34, 33, - 35, 32, 37, 38, 47, 44, 41, 42, 59, 56, 61, 62, 55, 52, 49, 50, - 19, 16, 21, 22, 31, 28, 25, 26, 11, 8, 13, 14, 7, 4, 1, 2, - 0, 32, 3, 35, 6, 38, 5, 37, 12, 44, 15, 47, 10, 42, 9, 41, - 24, 56, 27, 59, 30, 62, 29, 61, 20, 52, 23, 55, 18, 50, 17, 49, - 48, 16, 51, 19, 54, 22, 53, 21, 60, 28, 63, 31, 58, 26, 57, 25, - 40, 8, 43, 11, 46, 14, 45, 13, 36, 4, 39, 7, 34, 2, 33, 1, - 0, 16, 32, 48, 3, 19, 35, 51, 6, 22, 38, 54, 5, 21, 37, 53, - 12, 28, 44, 60, 15, 31, 47, 63, 10, 26, 42, 58, 9, 25, 41, 57, - 24, 8, 56, 40, 27, 11, 59, 43, 30, 14, 62, 46, 29, 13, 61, 45, - 20, 4, 52, 36, 23, 7, 55, 39, 18, 2, 50, 34, 17, 1, 49, 33, - 0, 8, 16, 24, 32, 40, 48, 56, 3, 11, 19, 27, 35, 43, 51, 59, - 6, 14, 22, 30, 38, 46, 54, 62, 5, 13, 21, 29, 37, 45, 53, 61, - 12, 4, 28, 20, 44, 36, 60, 52, 15, 7, 31, 23, 47, 39, 63, 55, - 10, 2, 26, 18, 42, 34, 58, 50, 9, 1, 25, 17, 41, 33, 57, 49, - 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, - 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, - 6, 2, 14, 10, 22, 18, 30, 26, 38, 34, 46, 42, 54, 50, 62, 58, - 5, 1, 13, 9, 21, 17, 29, 25, 37, 33, 45, 41, 53, 49, 61, 57, - 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, - 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, - 3, 1, 7, 5, 11, 9, 15, 13, 19, 17, 23, 21, 27, 25, 31, 29, - 35, 33, 39, 37, 43, 41, 47, 45, 51, 49, 55, 53, 59, 57, 63, 61 -}; - -const qracode qra_13_64_64_irr_e = { - qra_K, - qra_N, - qra_m, - qra_M, - qra_a, - qra_NC, - qra_V, - qra_C, - qra_NMSG, - qra_MAXVDEG, - qra_MAXCDEG, - QRATYPE_CRCPUNCTURED, - qra_R, - CODE_NAME, - qra_acc_input_idx, - qra_acc_input_wlog, - qra_log, - qra_exp, - qra_msgw, - qra_vdeg, - qra_cdeg, - qra_v2cmidx, - qra_c2vmidx, - qra_pmat -}; - -#undef qra_K -#undef qra_N -#undef qra_m -#undef qra_M -#undef qra_a -#undef qra_NC -#undef qra_V -#undef qra_C -#undef qra_NMSG -#undef qra_MAXVDEG -#undef qra_MAXCDEG -#undef qra_R +// qra13_64_64_irr_e.c +// Encoding/Decoding tables for Q-ary RA code (13,64) over GF(64) +// Code Name: qra13_64_64_irr_e +// (13,64) RA Code over GF(64) RF=[3x4 4x4 6x1 3x2 5x1 7x1]/18 + +// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy + +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#include "qra13_64_64_irr_e.h" + +#define qra_K 13 // number of information symbols +#define qra_N 64 // codeword length in symbols +#define qra_m 6 // bits/symbol +#define qra_M 64 // Symbol alphabet cardinality +#define qra_a 1 // grouping factor +#define qra_NC 51 // number of check symbols (N-K) + +// Defines used by the message passing decoder -------- + +#define qra_V 64 // number of variables in the code graph (N) +#define qra_C 116 // number of factors in the code graph (N +(N-K)+1) +#define qra_NMSG 218 // number of msgs in the code graph +#define qra_MAXVDEG 8 // maximum variable degree +#define qra_MAXCDEG 3 // maximum factor degree +#define qra_R 0.20313f // code rate (K/N) +#define CODE_NAME "qra_13_64_64_irr_e" + +// table of the systematic symbols indexes in the accumulator chain +static const int qra_acc_input_idx[qra_NC+1] = { + 12, 4, 3, 9, 0, 11, 6, 8, 12, 1, + 2, 7, 4, 11, 3, 5, 9, 8, 12, 7, + 2, 4, 10, 3, 5, 11, 12, 8, 9, 6, + 7, 2, 5, 4, 12, 8, 11, 1, 6, 7, + 0, 10, 12, 8, 11, 5, 6, 1, 0, 10, + 12, 8 +}; + +// table of the systematic symbols weight logarithms over GF(M) +static const int qra_acc_input_wlog[qra_NC+1] = { + 0, 27, 0, 0, 0, 31, 28, 61, 31, 0, + 0, 52, 22, 7, 19, 47, 44, 62, 32, 50, + 52, 42, 48, 56, 40, 50, 51, 37, 37, 0, + 5, 14, 0, 0, 18, 2, 0, 45, 21, 0, + 62, 8, 11, 60, 36, 32, 17, 9, 5, 0, + 53, 0 +}; + +// table of the logarithms of the elements of GF(M) (log(0) never used) +static const int qra_log[qra_M] = { + -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, + 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, + 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, + 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, + 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, + 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, + 20, 59, 57, 58 +}; + +// table of GF(M) elements given their logarithm +static const int qra_exp[qra_M-1] = { + 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, + 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, + 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, + 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, + 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, + 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, + 57, 49, 33 +}; + +// table of the messages weight logarithms over GF(M) +static const int qra_msgw[qra_NMSG] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 27, 0, 0, 0, 31, + 28, 61, 31, 0, 0, 52, 22, 7, 19, 47, + 44, 62, 32, 50, 52, 42, 48, 56, 40, 50, + 51, 37, 37, 0, 5, 14, 0, 0, 18, 2, + 0, 45, 21, 0, 62, 8, 11, 60, 36, 32, + 17, 9, 5, 0, 53, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; + +// table of the degrees of the variable nodes +static const int qra_vdeg[qra_V] = { + 4, 4, 4, 4, 5, 5, 5, 5, 7, 4, + 4, 6, 8, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3 +}; + +// table of the degrees of the factor nodes +static const int qra_cdeg[qra_C] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 2, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 2 +}; + +// table (uncompressed) of the v->c message indexes (-1=unused entry) +static const int qra_v2cmidx[qra_V*qra_MAXVDEG] = { + 0, 68, 104, 112, -1, -1, -1, -1, + 1, 73, 101, 111, -1, -1, -1, -1, + 2, 74, 84, 95, -1, -1, -1, -1, + 3, 66, 78, 87, -1, -1, -1, -1, + 4, 65, 76, 85, 97, -1, -1, -1, + 5, 79, 88, 96, 109, -1, -1, -1, + 6, 70, 93, 102, 110, -1, -1, -1, + 7, 75, 83, 94, 103, -1, -1, -1, + 8, 71, 81, 91, 99, 107, 115, -1, + 9, 67, 80, 92, -1, -1, -1, -1, + 10, 86, 105, 113, -1, -1, -1, -1, + 11, 69, 77, 89, 100, 108, -1, -1, + 12, 64, 72, 82, 90, 98, 106, 114, + 13, 116, 117, -1, -1, -1, -1, -1, + 14, 118, 119, -1, -1, -1, -1, -1, + 15, 120, 121, -1, -1, -1, -1, -1, + 16, 122, 123, -1, -1, -1, -1, -1, + 17, 124, 125, -1, -1, -1, -1, -1, + 18, 126, 127, -1, -1, -1, -1, -1, + 19, 128, 129, -1, -1, -1, -1, -1, + 20, 130, 131, -1, -1, -1, -1, -1, + 21, 132, 133, -1, -1, -1, -1, -1, + 22, 134, 135, -1, -1, -1, -1, -1, + 23, 136, 137, -1, -1, -1, -1, -1, + 24, 138, 139, -1, -1, -1, -1, -1, + 25, 140, 141, -1, -1, -1, -1, -1, + 26, 142, 143, -1, -1, -1, -1, -1, + 27, 144, 145, -1, -1, -1, -1, -1, + 28, 146, 147, -1, -1, -1, -1, -1, + 29, 148, 149, -1, -1, -1, -1, -1, + 30, 150, 151, -1, -1, -1, -1, -1, + 31, 152, 153, -1, -1, -1, -1, -1, + 32, 154, 155, -1, -1, -1, -1, -1, + 33, 156, 157, -1, -1, -1, -1, -1, + 34, 158, 159, -1, -1, -1, -1, -1, + 35, 160, 161, -1, -1, -1, -1, -1, + 36, 162, 163, -1, -1, -1, -1, -1, + 37, 164, 165, -1, -1, -1, -1, -1, + 38, 166, 167, -1, -1, -1, -1, -1, + 39, 168, 169, -1, -1, -1, -1, -1, + 40, 170, 171, -1, -1, -1, -1, -1, + 41, 172, 173, -1, -1, -1, -1, -1, + 42, 174, 175, -1, -1, -1, -1, -1, + 43, 176, 177, -1, -1, -1, -1, -1, + 44, 178, 179, -1, -1, -1, -1, -1, + 45, 180, 181, -1, -1, -1, -1, -1, + 46, 182, 183, -1, -1, -1, -1, -1, + 47, 184, 185, -1, -1, -1, -1, -1, + 48, 186, 187, -1, -1, -1, -1, -1, + 49, 188, 189, -1, -1, -1, -1, -1, + 50, 190, 191, -1, -1, -1, -1, -1, + 51, 192, 193, -1, -1, -1, -1, -1, + 52, 194, 195, -1, -1, -1, -1, -1, + 53, 196, 197, -1, -1, -1, -1, -1, + 54, 198, 199, -1, -1, -1, -1, -1, + 55, 200, 201, -1, -1, -1, -1, -1, + 56, 202, 203, -1, -1, -1, -1, -1, + 57, 204, 205, -1, -1, -1, -1, -1, + 58, 206, 207, -1, -1, -1, -1, -1, + 59, 208, 209, -1, -1, -1, -1, -1, + 60, 210, 211, -1, -1, -1, -1, -1, + 61, 212, 213, -1, -1, -1, -1, -1, + 62, 214, 215, -1, -1, -1, -1, -1, + 63, 216, 217, -1, -1, -1, -1, -1 +}; + +// table (uncompressed) of the c->v message indexes (-1=unused entry) +static const int qra_c2vmidx[qra_C*qra_MAXCDEG] = { + 0, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1, + 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1, + 8, -1, -1, 9, -1, -1, 10, -1, -1, 11, -1, -1, + 12, -1, -1, 13, -1, -1, 14, -1, -1, 15, -1, -1, + 16, -1, -1, 17, -1, -1, 18, -1, -1, 19, -1, -1, + 20, -1, -1, 21, -1, -1, 22, -1, -1, 23, -1, -1, + 24, -1, -1, 25, -1, -1, 26, -1, -1, 27, -1, -1, + 28, -1, -1, 29, -1, -1, 30, -1, -1, 31, -1, -1, + 32, -1, -1, 33, -1, -1, 34, -1, -1, 35, -1, -1, + 36, -1, -1, 37, -1, -1, 38, -1, -1, 39, -1, -1, + 40, -1, -1, 41, -1, -1, 42, -1, -1, 43, -1, -1, + 44, -1, -1, 45, -1, -1, 46, -1, -1, 47, -1, -1, + 48, -1, -1, 49, -1, -1, 50, -1, -1, 51, -1, -1, + 52, -1, -1, 53, -1, -1, 54, -1, -1, 55, -1, -1, + 56, -1, -1, 57, -1, -1, 58, -1, -1, 59, -1, -1, + 60, -1, -1, 61, -1, -1, 62, -1, -1, 63, -1, -1, + 64, 116, -1, 65, 117, 118, 66, 119, 120, 67, 121, 122, + 68, 123, 124, 69, 125, 126, 70, 127, 128, 71, 129, 130, + 72, 131, 132, 73, 133, 134, 74, 135, 136, 75, 137, 138, + 76, 139, 140, 77, 141, 142, 78, 143, 144, 79, 145, 146, + 80, 147, 148, 81, 149, 150, 82, 151, 152, 83, 153, 154, + 84, 155, 156, 85, 157, 158, 86, 159, 160, 87, 161, 162, + 88, 163, 164, 89, 165, 166, 90, 167, 168, 91, 169, 170, + 92, 171, 172, 93, 173, 174, 94, 175, 176, 95, 177, 178, + 96, 179, 180, 97, 181, 182, 98, 183, 184, 99, 185, 186, +100, 187, 188, 101, 189, 190, 102, 191, 192, 103, 193, 194, +104, 195, 196, 105, 197, 198, 106, 199, 200, 107, 201, 202, +108, 203, 204, 109, 205, 206, 110, 207, 208, 111, 209, 210, +112, 211, 212, 113, 213, 214, 114, 215, 216, 115, 217, -1 +}; + +// permutation matrix to compute Prob(x*alfa^logw) +static const int qra_pmat[qra_M*qra_M] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 33, 1, 32, 2, 35, 3, 34, 4, 37, 5, 36, 6, 39, 7, 38, + 8, 41, 9, 40, 10, 43, 11, 42, 12, 45, 13, 44, 14, 47, 15, 46, + 16, 49, 17, 48, 18, 51, 19, 50, 20, 53, 21, 52, 22, 55, 23, 54, + 24, 57, 25, 56, 26, 59, 27, 58, 28, 61, 29, 60, 30, 63, 31, 62, + 0, 49, 33, 16, 1, 48, 32, 17, 2, 51, 35, 18, 3, 50, 34, 19, + 4, 53, 37, 20, 5, 52, 36, 21, 6, 55, 39, 22, 7, 54, 38, 23, + 8, 57, 41, 24, 9, 56, 40, 25, 10, 59, 43, 26, 11, 58, 42, 27, + 12, 61, 45, 28, 13, 60, 44, 29, 14, 63, 47, 30, 15, 62, 46, 31, + 0, 57, 49, 8, 33, 24, 16, 41, 1, 56, 48, 9, 32, 25, 17, 40, + 2, 59, 51, 10, 35, 26, 18, 43, 3, 58, 50, 11, 34, 27, 19, 42, + 4, 61, 53, 12, 37, 28, 20, 45, 5, 60, 52, 13, 36, 29, 21, 44, + 6, 63, 55, 14, 39, 30, 22, 47, 7, 62, 54, 15, 38, 31, 23, 46, + 0, 61, 57, 4, 49, 12, 8, 53, 33, 28, 24, 37, 16, 45, 41, 20, + 1, 60, 56, 5, 48, 13, 9, 52, 32, 29, 25, 36, 17, 44, 40, 21, + 2, 63, 59, 6, 51, 14, 10, 55, 35, 30, 26, 39, 18, 47, 43, 22, + 3, 62, 58, 7, 50, 15, 11, 54, 34, 31, 27, 38, 19, 46, 42, 23, + 0, 63, 61, 2, 57, 6, 4, 59, 49, 14, 12, 51, 8, 55, 53, 10, + 33, 30, 28, 35, 24, 39, 37, 26, 16, 47, 45, 18, 41, 22, 20, 43, + 1, 62, 60, 3, 56, 7, 5, 58, 48, 15, 13, 50, 9, 54, 52, 11, + 32, 31, 29, 34, 25, 38, 36, 27, 17, 46, 44, 19, 40, 23, 21, 42, + 0, 62, 63, 1, 61, 3, 2, 60, 57, 7, 6, 56, 4, 58, 59, 5, + 49, 15, 14, 48, 12, 50, 51, 13, 8, 54, 55, 9, 53, 11, 10, 52, + 33, 31, 30, 32, 28, 34, 35, 29, 24, 38, 39, 25, 37, 27, 26, 36, + 16, 46, 47, 17, 45, 19, 18, 44, 41, 23, 22, 40, 20, 42, 43, 21, + 0, 31, 62, 33, 63, 32, 1, 30, 61, 34, 3, 28, 2, 29, 60, 35, + 57, 38, 7, 24, 6, 25, 56, 39, 4, 27, 58, 37, 59, 36, 5, 26, + 49, 46, 15, 16, 14, 17, 48, 47, 12, 19, 50, 45, 51, 44, 13, 18, + 8, 23, 54, 41, 55, 40, 9, 22, 53, 42, 11, 20, 10, 21, 52, 43, + 0, 46, 31, 49, 62, 16, 33, 15, 63, 17, 32, 14, 1, 47, 30, 48, + 61, 19, 34, 12, 3, 45, 28, 50, 2, 44, 29, 51, 60, 18, 35, 13, + 57, 23, 38, 8, 7, 41, 24, 54, 6, 40, 25, 55, 56, 22, 39, 9, + 4, 42, 27, 53, 58, 20, 37, 11, 59, 21, 36, 10, 5, 43, 26, 52, + 0, 23, 46, 57, 31, 8, 49, 38, 62, 41, 16, 7, 33, 54, 15, 24, + 63, 40, 17, 6, 32, 55, 14, 25, 1, 22, 47, 56, 30, 9, 48, 39, + 61, 42, 19, 4, 34, 53, 12, 27, 3, 20, 45, 58, 28, 11, 50, 37, + 2, 21, 44, 59, 29, 10, 51, 36, 60, 43, 18, 5, 35, 52, 13, 26, + 0, 42, 23, 61, 46, 4, 57, 19, 31, 53, 8, 34, 49, 27, 38, 12, + 62, 20, 41, 3, 16, 58, 7, 45, 33, 11, 54, 28, 15, 37, 24, 50, + 63, 21, 40, 2, 17, 59, 6, 44, 32, 10, 55, 29, 14, 36, 25, 51, + 1, 43, 22, 60, 47, 5, 56, 18, 30, 52, 9, 35, 48, 26, 39, 13, + 0, 21, 42, 63, 23, 2, 61, 40, 46, 59, 4, 17, 57, 44, 19, 6, + 31, 10, 53, 32, 8, 29, 34, 55, 49, 36, 27, 14, 38, 51, 12, 25, + 62, 43, 20, 1, 41, 60, 3, 22, 16, 5, 58, 47, 7, 18, 45, 56, + 33, 52, 11, 30, 54, 35, 28, 9, 15, 26, 37, 48, 24, 13, 50, 39, + 0, 43, 21, 62, 42, 1, 63, 20, 23, 60, 2, 41, 61, 22, 40, 3, + 46, 5, 59, 16, 4, 47, 17, 58, 57, 18, 44, 7, 19, 56, 6, 45, + 31, 52, 10, 33, 53, 30, 32, 11, 8, 35, 29, 54, 34, 9, 55, 28, + 49, 26, 36, 15, 27, 48, 14, 37, 38, 13, 51, 24, 12, 39, 25, 50, + 0, 52, 43, 31, 21, 33, 62, 10, 42, 30, 1, 53, 63, 11, 20, 32, + 23, 35, 60, 8, 2, 54, 41, 29, 61, 9, 22, 34, 40, 28, 3, 55, + 46, 26, 5, 49, 59, 15, 16, 36, 4, 48, 47, 27, 17, 37, 58, 14, + 57, 13, 18, 38, 44, 24, 7, 51, 19, 39, 56, 12, 6, 50, 45, 25, + 0, 26, 52, 46, 43, 49, 31, 5, 21, 15, 33, 59, 62, 36, 10, 16, + 42, 48, 30, 4, 1, 27, 53, 47, 63, 37, 11, 17, 20, 14, 32, 58, + 23, 13, 35, 57, 60, 38, 8, 18, 2, 24, 54, 44, 41, 51, 29, 7, + 61, 39, 9, 19, 22, 12, 34, 56, 40, 50, 28, 6, 3, 25, 55, 45, + 0, 13, 26, 23, 52, 57, 46, 35, 43, 38, 49, 60, 31, 18, 5, 8, + 21, 24, 15, 2, 33, 44, 59, 54, 62, 51, 36, 41, 10, 7, 16, 29, + 42, 39, 48, 61, 30, 19, 4, 9, 1, 12, 27, 22, 53, 56, 47, 34, + 63, 50, 37, 40, 11, 6, 17, 28, 20, 25, 14, 3, 32, 45, 58, 55, + 0, 39, 13, 42, 26, 61, 23, 48, 52, 19, 57, 30, 46, 9, 35, 4, + 43, 12, 38, 1, 49, 22, 60, 27, 31, 56, 18, 53, 5, 34, 8, 47, + 21, 50, 24, 63, 15, 40, 2, 37, 33, 6, 44, 11, 59, 28, 54, 17, + 62, 25, 51, 20, 36, 3, 41, 14, 10, 45, 7, 32, 16, 55, 29, 58, + 0, 50, 39, 21, 13, 63, 42, 24, 26, 40, 61, 15, 23, 37, 48, 2, + 52, 6, 19, 33, 57, 11, 30, 44, 46, 28, 9, 59, 35, 17, 4, 54, + 43, 25, 12, 62, 38, 20, 1, 51, 49, 3, 22, 36, 60, 14, 27, 41, + 31, 45, 56, 10, 18, 32, 53, 7, 5, 55, 34, 16, 8, 58, 47, 29, + 0, 25, 50, 43, 39, 62, 21, 12, 13, 20, 63, 38, 42, 51, 24, 1, + 26, 3, 40, 49, 61, 36, 15, 22, 23, 14, 37, 60, 48, 41, 2, 27, + 52, 45, 6, 31, 19, 10, 33, 56, 57, 32, 11, 18, 30, 7, 44, 53, + 46, 55, 28, 5, 9, 16, 59, 34, 35, 58, 17, 8, 4, 29, 54, 47, + 0, 45, 25, 52, 50, 31, 43, 6, 39, 10, 62, 19, 21, 56, 12, 33, + 13, 32, 20, 57, 63, 18, 38, 11, 42, 7, 51, 30, 24, 53, 1, 44, + 26, 55, 3, 46, 40, 5, 49, 28, 61, 16, 36, 9, 15, 34, 22, 59, + 23, 58, 14, 35, 37, 8, 60, 17, 48, 29, 41, 4, 2, 47, 27, 54, + 0, 55, 45, 26, 25, 46, 52, 3, 50, 5, 31, 40, 43, 28, 6, 49, + 39, 16, 10, 61, 62, 9, 19, 36, 21, 34, 56, 15, 12, 59, 33, 22, + 13, 58, 32, 23, 20, 35, 57, 14, 63, 8, 18, 37, 38, 17, 11, 60, + 42, 29, 7, 48, 51, 4, 30, 41, 24, 47, 53, 2, 1, 54, 44, 27, + 0, 58, 55, 13, 45, 23, 26, 32, 25, 35, 46, 20, 52, 14, 3, 57, + 50, 8, 5, 63, 31, 37, 40, 18, 43, 17, 28, 38, 6, 60, 49, 11, + 39, 29, 16, 42, 10, 48, 61, 7, 62, 4, 9, 51, 19, 41, 36, 30, + 21, 47, 34, 24, 56, 2, 15, 53, 12, 54, 59, 1, 33, 27, 22, 44, + 0, 29, 58, 39, 55, 42, 13, 16, 45, 48, 23, 10, 26, 7, 32, 61, + 25, 4, 35, 62, 46, 51, 20, 9, 52, 41, 14, 19, 3, 30, 57, 36, + 50, 47, 8, 21, 5, 24, 63, 34, 31, 2, 37, 56, 40, 53, 18, 15, + 43, 54, 17, 12, 28, 1, 38, 59, 6, 27, 60, 33, 49, 44, 11, 22, + 0, 47, 29, 50, 58, 21, 39, 8, 55, 24, 42, 5, 13, 34, 16, 63, + 45, 2, 48, 31, 23, 56, 10, 37, 26, 53, 7, 40, 32, 15, 61, 18, + 25, 54, 4, 43, 35, 12, 62, 17, 46, 1, 51, 28, 20, 59, 9, 38, + 52, 27, 41, 6, 14, 33, 19, 60, 3, 44, 30, 49, 57, 22, 36, 11, + 0, 54, 47, 25, 29, 43, 50, 4, 58, 12, 21, 35, 39, 17, 8, 62, + 55, 1, 24, 46, 42, 28, 5, 51, 13, 59, 34, 20, 16, 38, 63, 9, + 45, 27, 2, 52, 48, 6, 31, 41, 23, 33, 56, 14, 10, 60, 37, 19, + 26, 44, 53, 3, 7, 49, 40, 30, 32, 22, 15, 57, 61, 11, 18, 36, + 0, 27, 54, 45, 47, 52, 25, 2, 29, 6, 43, 48, 50, 41, 4, 31, + 58, 33, 12, 23, 21, 14, 35, 56, 39, 60, 17, 10, 8, 19, 62, 37, + 55, 44, 1, 26, 24, 3, 46, 53, 42, 49, 28, 7, 5, 30, 51, 40, + 13, 22, 59, 32, 34, 57, 20, 15, 16, 11, 38, 61, 63, 36, 9, 18, + 0, 44, 27, 55, 54, 26, 45, 1, 47, 3, 52, 24, 25, 53, 2, 46, + 29, 49, 6, 42, 43, 7, 48, 28, 50, 30, 41, 5, 4, 40, 31, 51, + 58, 22, 33, 13, 12, 32, 23, 59, 21, 57, 14, 34, 35, 15, 56, 20, + 39, 11, 60, 16, 17, 61, 10, 38, 8, 36, 19, 63, 62, 18, 37, 9, + 0, 22, 44, 58, 27, 13, 55, 33, 54, 32, 26, 12, 45, 59, 1, 23, + 47, 57, 3, 21, 52, 34, 24, 14, 25, 15, 53, 35, 2, 20, 46, 56, + 29, 11, 49, 39, 6, 16, 42, 60, 43, 61, 7, 17, 48, 38, 28, 10, + 50, 36, 30, 8, 41, 63, 5, 19, 4, 18, 40, 62, 31, 9, 51, 37, + 0, 11, 22, 29, 44, 39, 58, 49, 27, 16, 13, 6, 55, 60, 33, 42, + 54, 61, 32, 43, 26, 17, 12, 7, 45, 38, 59, 48, 1, 10, 23, 28, + 47, 36, 57, 50, 3, 8, 21, 30, 52, 63, 34, 41, 24, 19, 14, 5, + 25, 18, 15, 4, 53, 62, 35, 40, 2, 9, 20, 31, 46, 37, 56, 51, + 0, 36, 11, 47, 22, 50, 29, 57, 44, 8, 39, 3, 58, 30, 49, 21, + 27, 63, 16, 52, 13, 41, 6, 34, 55, 19, 60, 24, 33, 5, 42, 14, + 54, 18, 61, 25, 32, 4, 43, 15, 26, 62, 17, 53, 12, 40, 7, 35, + 45, 9, 38, 2, 59, 31, 48, 20, 1, 37, 10, 46, 23, 51, 28, 56, + 0, 18, 36, 54, 11, 25, 47, 61, 22, 4, 50, 32, 29, 15, 57, 43, + 44, 62, 8, 26, 39, 53, 3, 17, 58, 40, 30, 12, 49, 35, 21, 7, + 27, 9, 63, 45, 16, 2, 52, 38, 13, 31, 41, 59, 6, 20, 34, 48, + 55, 37, 19, 1, 60, 46, 24, 10, 33, 51, 5, 23, 42, 56, 14, 28, + 0, 9, 18, 27, 36, 45, 54, 63, 11, 2, 25, 16, 47, 38, 61, 52, + 22, 31, 4, 13, 50, 59, 32, 41, 29, 20, 15, 6, 57, 48, 43, 34, + 44, 37, 62, 55, 8, 1, 26, 19, 39, 46, 53, 60, 3, 10, 17, 24, + 58, 51, 40, 33, 30, 23, 12, 5, 49, 56, 35, 42, 21, 28, 7, 14, + 0, 37, 9, 44, 18, 55, 27, 62, 36, 1, 45, 8, 54, 19, 63, 26, + 11, 46, 2, 39, 25, 60, 16, 53, 47, 10, 38, 3, 61, 24, 52, 17, + 22, 51, 31, 58, 4, 33, 13, 40, 50, 23, 59, 30, 32, 5, 41, 12, + 29, 56, 20, 49, 15, 42, 6, 35, 57, 28, 48, 21, 43, 14, 34, 7, + 0, 51, 37, 22, 9, 58, 44, 31, 18, 33, 55, 4, 27, 40, 62, 13, + 36, 23, 1, 50, 45, 30, 8, 59, 54, 5, 19, 32, 63, 12, 26, 41, + 11, 56, 46, 29, 2, 49, 39, 20, 25, 42, 60, 15, 16, 35, 53, 6, + 47, 28, 10, 57, 38, 21, 3, 48, 61, 14, 24, 43, 52, 7, 17, 34, + 0, 56, 51, 11, 37, 29, 22, 46, 9, 49, 58, 2, 44, 20, 31, 39, + 18, 42, 33, 25, 55, 15, 4, 60, 27, 35, 40, 16, 62, 6, 13, 53, + 36, 28, 23, 47, 1, 57, 50, 10, 45, 21, 30, 38, 8, 48, 59, 3, + 54, 14, 5, 61, 19, 43, 32, 24, 63, 7, 12, 52, 26, 34, 41, 17, + 0, 28, 56, 36, 51, 47, 11, 23, 37, 57, 29, 1, 22, 10, 46, 50, + 9, 21, 49, 45, 58, 38, 2, 30, 44, 48, 20, 8, 31, 3, 39, 59, + 18, 14, 42, 54, 33, 61, 25, 5, 55, 43, 15, 19, 4, 24, 60, 32, + 27, 7, 35, 63, 40, 52, 16, 12, 62, 34, 6, 26, 13, 17, 53, 41, + 0, 14, 28, 18, 56, 54, 36, 42, 51, 61, 47, 33, 11, 5, 23, 25, + 37, 43, 57, 55, 29, 19, 1, 15, 22, 24, 10, 4, 46, 32, 50, 60, + 9, 7, 21, 27, 49, 63, 45, 35, 58, 52, 38, 40, 2, 12, 30, 16, + 44, 34, 48, 62, 20, 26, 8, 6, 31, 17, 3, 13, 39, 41, 59, 53, + 0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45, + 51, 52, 61, 58, 47, 40, 33, 38, 11, 12, 5, 2, 23, 16, 25, 30, + 37, 34, 43, 44, 57, 62, 55, 48, 29, 26, 19, 20, 1, 6, 15, 8, + 22, 17, 24, 31, 10, 13, 4, 3, 46, 41, 32, 39, 50, 53, 60, 59, + 0, 34, 7, 37, 14, 44, 9, 43, 28, 62, 27, 57, 18, 48, 21, 55, + 56, 26, 63, 29, 54, 20, 49, 19, 36, 6, 35, 1, 42, 8, 45, 15, + 51, 17, 52, 22, 61, 31, 58, 24, 47, 13, 40, 10, 33, 3, 38, 4, + 11, 41, 12, 46, 5, 39, 2, 32, 23, 53, 16, 50, 25, 59, 30, 60, + 0, 17, 34, 51, 7, 22, 37, 52, 14, 31, 44, 61, 9, 24, 43, 58, + 28, 13, 62, 47, 27, 10, 57, 40, 18, 3, 48, 33, 21, 4, 55, 38, + 56, 41, 26, 11, 63, 46, 29, 12, 54, 39, 20, 5, 49, 32, 19, 2, + 36, 53, 6, 23, 35, 50, 1, 16, 42, 59, 8, 25, 45, 60, 15, 30, + 0, 41, 17, 56, 34, 11, 51, 26, 7, 46, 22, 63, 37, 12, 52, 29, + 14, 39, 31, 54, 44, 5, 61, 20, 9, 32, 24, 49, 43, 2, 58, 19, + 28, 53, 13, 36, 62, 23, 47, 6, 27, 50, 10, 35, 57, 16, 40, 1, + 18, 59, 3, 42, 48, 25, 33, 8, 21, 60, 4, 45, 55, 30, 38, 15, + 0, 53, 41, 28, 17, 36, 56, 13, 34, 23, 11, 62, 51, 6, 26, 47, + 7, 50, 46, 27, 22, 35, 63, 10, 37, 16, 12, 57, 52, 1, 29, 40, + 14, 59, 39, 18, 31, 42, 54, 3, 44, 25, 5, 48, 61, 8, 20, 33, + 9, 60, 32, 21, 24, 45, 49, 4, 43, 30, 2, 55, 58, 15, 19, 38, + 0, 59, 53, 14, 41, 18, 28, 39, 17, 42, 36, 31, 56, 3, 13, 54, + 34, 25, 23, 44, 11, 48, 62, 5, 51, 8, 6, 61, 26, 33, 47, 20, + 7, 60, 50, 9, 46, 21, 27, 32, 22, 45, 35, 24, 63, 4, 10, 49, + 37, 30, 16, 43, 12, 55, 57, 2, 52, 15, 1, 58, 29, 38, 40, 19, + 0, 60, 59, 7, 53, 9, 14, 50, 41, 21, 18, 46, 28, 32, 39, 27, + 17, 45, 42, 22, 36, 24, 31, 35, 56, 4, 3, 63, 13, 49, 54, 10, + 34, 30, 25, 37, 23, 43, 44, 16, 11, 55, 48, 12, 62, 2, 5, 57, + 51, 15, 8, 52, 6, 58, 61, 1, 26, 38, 33, 29, 47, 19, 20, 40, + 0, 30, 60, 34, 59, 37, 7, 25, 53, 43, 9, 23, 14, 16, 50, 44, + 41, 55, 21, 11, 18, 12, 46, 48, 28, 2, 32, 62, 39, 57, 27, 5, + 17, 15, 45, 51, 42, 52, 22, 8, 36, 58, 24, 6, 31, 1, 35, 61, + 56, 38, 4, 26, 3, 29, 63, 33, 13, 19, 49, 47, 54, 40, 10, 20, + 0, 15, 30, 17, 60, 51, 34, 45, 59, 52, 37, 42, 7, 8, 25, 22, + 53, 58, 43, 36, 9, 6, 23, 24, 14, 1, 16, 31, 50, 61, 44, 35, + 41, 38, 55, 56, 21, 26, 11, 4, 18, 29, 12, 3, 46, 33, 48, 63, + 28, 19, 2, 13, 32, 47, 62, 49, 39, 40, 57, 54, 27, 20, 5, 10, + 0, 38, 15, 41, 30, 56, 17, 55, 60, 26, 51, 21, 34, 4, 45, 11, + 59, 29, 52, 18, 37, 3, 42, 12, 7, 33, 8, 46, 25, 63, 22, 48, + 53, 19, 58, 28, 43, 13, 36, 2, 9, 47, 6, 32, 23, 49, 24, 62, + 14, 40, 1, 39, 16, 54, 31, 57, 50, 20, 61, 27, 44, 10, 35, 5, + 0, 19, 38, 53, 15, 28, 41, 58, 30, 13, 56, 43, 17, 2, 55, 36, + 60, 47, 26, 9, 51, 32, 21, 6, 34, 49, 4, 23, 45, 62, 11, 24, + 59, 40, 29, 14, 52, 39, 18, 1, 37, 54, 3, 16, 42, 57, 12, 31, + 7, 20, 33, 50, 8, 27, 46, 61, 25, 10, 63, 44, 22, 5, 48, 35, + 0, 40, 19, 59, 38, 14, 53, 29, 15, 39, 28, 52, 41, 1, 58, 18, + 30, 54, 13, 37, 56, 16, 43, 3, 17, 57, 2, 42, 55, 31, 36, 12, + 60, 20, 47, 7, 26, 50, 9, 33, 51, 27, 32, 8, 21, 61, 6, 46, + 34, 10, 49, 25, 4, 44, 23, 63, 45, 5, 62, 22, 11, 35, 24, 48, + 0, 20, 40, 60, 19, 7, 59, 47, 38, 50, 14, 26, 53, 33, 29, 9, + 15, 27, 39, 51, 28, 8, 52, 32, 41, 61, 1, 21, 58, 46, 18, 6, + 30, 10, 54, 34, 13, 25, 37, 49, 56, 44, 16, 4, 43, 63, 3, 23, + 17, 5, 57, 45, 2, 22, 42, 62, 55, 35, 31, 11, 36, 48, 12, 24, + 0, 10, 20, 30, 40, 34, 60, 54, 19, 25, 7, 13, 59, 49, 47, 37, + 38, 44, 50, 56, 14, 4, 26, 16, 53, 63, 33, 43, 29, 23, 9, 3, + 15, 5, 27, 17, 39, 45, 51, 57, 28, 22, 8, 2, 52, 62, 32, 42, + 41, 35, 61, 55, 1, 11, 21, 31, 58, 48, 46, 36, 18, 24, 6, 12, + 0, 5, 10, 15, 20, 17, 30, 27, 40, 45, 34, 39, 60, 57, 54, 51, + 19, 22, 25, 28, 7, 2, 13, 8, 59, 62, 49, 52, 47, 42, 37, 32, + 38, 35, 44, 41, 50, 55, 56, 61, 14, 11, 4, 1, 26, 31, 16, 21, + 53, 48, 63, 58, 33, 36, 43, 46, 29, 24, 23, 18, 9, 12, 3, 6, + 0, 35, 5, 38, 10, 41, 15, 44, 20, 55, 17, 50, 30, 61, 27, 56, + 40, 11, 45, 14, 34, 1, 39, 4, 60, 31, 57, 26, 54, 21, 51, 16, + 19, 48, 22, 53, 25, 58, 28, 63, 7, 36, 2, 33, 13, 46, 8, 43, + 59, 24, 62, 29, 49, 18, 52, 23, 47, 12, 42, 9, 37, 6, 32, 3, + 0, 48, 35, 19, 5, 53, 38, 22, 10, 58, 41, 25, 15, 63, 44, 28, + 20, 36, 55, 7, 17, 33, 50, 2, 30, 46, 61, 13, 27, 43, 56, 8, + 40, 24, 11, 59, 45, 29, 14, 62, 34, 18, 1, 49, 39, 23, 4, 52, + 60, 12, 31, 47, 57, 9, 26, 42, 54, 6, 21, 37, 51, 3, 16, 32, + 0, 24, 48, 40, 35, 59, 19, 11, 5, 29, 53, 45, 38, 62, 22, 14, + 10, 18, 58, 34, 41, 49, 25, 1, 15, 23, 63, 39, 44, 52, 28, 4, + 20, 12, 36, 60, 55, 47, 7, 31, 17, 9, 33, 57, 50, 42, 2, 26, + 30, 6, 46, 54, 61, 37, 13, 21, 27, 3, 43, 51, 56, 32, 8, 16, + 0, 12, 24, 20, 48, 60, 40, 36, 35, 47, 59, 55, 19, 31, 11, 7, + 5, 9, 29, 17, 53, 57, 45, 33, 38, 42, 62, 50, 22, 26, 14, 2, + 10, 6, 18, 30, 58, 54, 34, 46, 41, 37, 49, 61, 25, 21, 1, 13, + 15, 3, 23, 27, 63, 51, 39, 43, 44, 32, 52, 56, 28, 16, 4, 8, + 0, 6, 12, 10, 24, 30, 20, 18, 48, 54, 60, 58, 40, 46, 36, 34, + 35, 37, 47, 41, 59, 61, 55, 49, 19, 21, 31, 25, 11, 13, 7, 1, + 5, 3, 9, 15, 29, 27, 17, 23, 53, 51, 57, 63, 45, 43, 33, 39, + 38, 32, 42, 44, 62, 56, 50, 52, 22, 16, 26, 28, 14, 8, 2, 4, + 0, 3, 6, 5, 12, 15, 10, 9, 24, 27, 30, 29, 20, 23, 18, 17, + 48, 51, 54, 53, 60, 63, 58, 57, 40, 43, 46, 45, 36, 39, 34, 33, + 35, 32, 37, 38, 47, 44, 41, 42, 59, 56, 61, 62, 55, 52, 49, 50, + 19, 16, 21, 22, 31, 28, 25, 26, 11, 8, 13, 14, 7, 4, 1, 2, + 0, 32, 3, 35, 6, 38, 5, 37, 12, 44, 15, 47, 10, 42, 9, 41, + 24, 56, 27, 59, 30, 62, 29, 61, 20, 52, 23, 55, 18, 50, 17, 49, + 48, 16, 51, 19, 54, 22, 53, 21, 60, 28, 63, 31, 58, 26, 57, 25, + 40, 8, 43, 11, 46, 14, 45, 13, 36, 4, 39, 7, 34, 2, 33, 1, + 0, 16, 32, 48, 3, 19, 35, 51, 6, 22, 38, 54, 5, 21, 37, 53, + 12, 28, 44, 60, 15, 31, 47, 63, 10, 26, 42, 58, 9, 25, 41, 57, + 24, 8, 56, 40, 27, 11, 59, 43, 30, 14, 62, 46, 29, 13, 61, 45, + 20, 4, 52, 36, 23, 7, 55, 39, 18, 2, 50, 34, 17, 1, 49, 33, + 0, 8, 16, 24, 32, 40, 48, 56, 3, 11, 19, 27, 35, 43, 51, 59, + 6, 14, 22, 30, 38, 46, 54, 62, 5, 13, 21, 29, 37, 45, 53, 61, + 12, 4, 28, 20, 44, 36, 60, 52, 15, 7, 31, 23, 47, 39, 63, 55, + 10, 2, 26, 18, 42, 34, 58, 50, 9, 1, 25, 17, 41, 33, 57, 49, + 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, + 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, + 6, 2, 14, 10, 22, 18, 30, 26, 38, 34, 46, 42, 54, 50, 62, 58, + 5, 1, 13, 9, 21, 17, 29, 25, 37, 33, 45, 41, 53, 49, 61, 57, + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, + 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, + 3, 1, 7, 5, 11, 9, 15, 13, 19, 17, 23, 21, 27, 25, 31, 29, + 35, 33, 39, 37, 43, 41, 47, 45, 51, 49, 55, 53, 59, 57, 63, 61 +}; + +const qracode qra_13_64_64_irr_e = { + qra_K, + qra_N, + qra_m, + qra_M, + qra_a, + qra_NC, + qra_V, + qra_C, + qra_NMSG, + qra_MAXVDEG, + qra_MAXCDEG, + QRATYPE_CRCPUNCTURED, + qra_R, + CODE_NAME, + qra_acc_input_idx, + qra_acc_input_wlog, + qra_log, + qra_exp, + qra_msgw, + qra_vdeg, + qra_cdeg, + qra_v2cmidx, + qra_c2vmidx, + qra_pmat +}; + +#undef qra_K +#undef qra_N +#undef qra_m +#undef qra_M +#undef qra_a +#undef qra_NC +#undef qra_V +#undef qra_C +#undef qra_NMSG +#undef qra_MAXVDEG +#undef qra_MAXCDEG +#undef qra_R #undef CODE_NAME \ No newline at end of file diff --git a/lib/qra/qracodes/qra13_64_64_irr_e.h b/lib/qra/qracodes/qra13_64_64_irr_e.h index f40611d6..d24421d2 100755 --- a/lib/qra/qracodes/qra13_64_64_irr_e.h +++ b/lib/qra/qracodes/qra13_64_64_irr_e.h @@ -1,39 +1,39 @@ -// qra13_64_64_irr_e.h -// Code tables and defines for Q-ary RA code (13,64) over GF(64) -// Code Name: qra13_64_64_irr_e -// (13,64) RA Code over GF(64) RF=[3x4 4x4 6x1 3x2 5x1 7x1]/18 - -// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy - -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#ifndef _qra13_64_64_irr_e_h -#define _qra13_64_64_irr_e_h - -#include "qracodes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern const qracode qra_13_64_64_irr_e; - -#ifdef __cplusplus -} -#endif - -#endif // _qra13_64_64_irr_e_h +// qra13_64_64_irr_e.h +// Code tables and defines for Q-ary RA code (13,64) over GF(64) +// Code Name: qra13_64_64_irr_e +// (13,64) RA Code over GF(64) RF=[3x4 4x4 6x1 3x2 5x1 7x1]/18 + +// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy + +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#ifndef _qra13_64_64_irr_e_h +#define _qra13_64_64_irr_e_h + +#include "qracodes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const qracode qra_13_64_64_irr_e; + +#ifdef __cplusplus +} +#endif + +#endif // _qra13_64_64_irr_e_h diff --git a/lib/qra/qracodes/qracodes.c b/lib/qra/qracodes/qracodes.c index 06576c5e..748a9c9c 100755 --- a/lib/qra/qracodes/qracodes.c +++ b/lib/qra/qracodes/qracodes.c @@ -1,474 +1,474 @@ -// qracodes.c -// Q-ary RA codes encoding/decoding functions -// -// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes 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 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#include -#include - -#include "npfwht.h" -#include "pdmath.h" - -#include "qracodes.h" - -int qra_encode(const qracode *pcode, int *y, const int *x) -{ - int k,j,kk,jj; - int t, chk = 0; - - const int K = pcode->K; - const int M = pcode->M; - const int NC= pcode->NC; - const int a = pcode->a; - const int *acc_input_idx = pcode->acc_input_idx; - const int *acc_input_wlog = pcode->acc_input_wlog; - const int *gflog = pcode->gflog; - const int *gfexp = pcode->gfexp; - - // copy the systematic symbols to destination - memcpy(y,x,K*sizeof(int)); - - y = y+K; // point to check symbols - - // compute the code check symbols as a weighted accumulation of a permutated - // sequence of the (repeated) systematic input symbols: - // chk(k+1) = x(idx(k))*alfa^(logw(k)) + chk(k) - // (all operations performed over GF(M)) - - if (a==1) { // grouping factor = 1 - for (k=0;k 1 - for (k=0;k80.f) // avoid floating point exp() overflows - v=80.f; - - src[nitems] = (float)exp(v); - } -} - - -float qra_mfskbesselmetric(float *pix, const float *rsq, const int m, const int N, float EsNoMetric) -{ - // Computes the codeword symbols intrinsic probabilities - // given the square of the received input amplitudes. - - // The input vector rqs must be a linear array of size M*N, where M=2^m, - // containing the squared amplitudes (rp*rp+rq*rq) of the input samples - - // First symbol amplitudes should be stored in the first M positions, - // second symbol amplitudes stored at positions [M ... 2*M-1], and so on. - - // Output vector is the intrinsic symbol metric (the probability distribution) - // assuming that symbols are transmitted using a M-FSK modulation - // and incoherent demodulation. - - // As the input Es/No is generally unknown (as it cannot be exstimated accurately - // when the codeword length is few tens symbols) but an exact metric requires it - // we simply fix it to a predefined EsNoMetric value so that the metric is what - // expected at that specific value. - // The metric computed in this way is optimal only at this predefined Es/No value, - // nevertheless it is usually better than a generic parameter-free metric which - // makes no assumptions on the input Es/No. - - // returns the estimated noise standard deviation - - int k; - float rsum = 0.f; - float sigmaest, cmetric; - - const int M = 1<M; - const int qra_m = pcode->m; - const int qra_V = pcode->V; - const int qra_MAXVDEG = pcode->MAXVDEG; - const int *qra_vdeg = pcode->vdeg; - const int qra_C = pcode->C; - const int qra_MAXCDEG = pcode->MAXCDEG; - const int *qra_cdeg = pcode->cdeg; - const int *qra_v2cmidx = pcode->v2cmidx; - const int *qra_c2vmidx = pcode->c2vmidx; - const int *qra_pmat = pcode->gfpmat; - const int *qra_msgw = pcode->msgw; - -// float msgout[qra_M]; // buffer to store temporary results - float msgout[QRACODE_MAX_M]; // we use a fixed size in order to avoid mallocs - - float totex; // total extrinsic information - int nit; // current iteration - int nv; // current variable - int nc; // current check - int k,kk; // loop indexes - - int ndeg; // current node degree - int msgbase; // current offset in the table of msg indexes - int imsg; // current message index - int wmsg; // current message weight - - int rc = -1; // rc>=0 extrinsic converged to 1 at iteration rc (rc=0..maxiter-1) - // rc=-1 no convergence in the given number of iterations - // rc=-2 error in the code tables (code checks degrees must be >1) - // rc=-3 M is larger than QRACODE_MAX_M - - - - if (qra_M>QRACODE_MAX_M) - return -3; - - // message initialization ------------------------------------------------------- - - // init c->v variable intrinsic msgs - pd_init(C2VMSG(0),pix,qra_M*qra_V); - - // init the v->c messages directed to code factors (k=1..ndeg) with the intrinsic info - for (nv=0;nvc - for (k=1;kv step ----------------------------------------------------- - // Computes messages from code checks to code variables. - // As the first qra_V checks are associated with intrinsic information - // (the code tables have been constructed in this way) - // we need to do this step only for code checks in the range [qra_V..qra_C) - - // The convolutions of probability distributions over the alphabet of a finite field GF(qra_M) - // are performed with a fast convolution algorithm over the given field. - // - // I.e. given the code check x1+x2+x3 = 0 (with x1,x2,x3 in GF(2^m)) - // and given Prob(x2) and Prob(x3), we have that: - // Prob(x1=X1) = Prob((x2+x3)=X1) = sum((Prob(x2=X2)*Prob(x3=(X1+X2))) for all the X2s in the field - // This translates to Prob(x1) = IWHT(WHT(Prob(x2))*WHT(Prob(x3))) - // where WHT and IWHT are the direct and inverse Walsh-Hadamard transforms of the argument. - // Note that the WHT and the IWHF differs only by a multiplicative coefficent and since in this step - // we don't need that the output distribution is normalized we use the relationship - // Prob(x1) =(proportional to) WH(WH(Prob(x2))*WH(Prob(x3))) - - // In general given the check code x1+x2+x3+..+xm = 0 - // the output distribution of a variable given the distributions of the other m-1 variables - // is the inverse WHT of the product of the WHTs of the distribution of the other m-1 variables - // The complexity of this algorithm scales with M*log2(M) instead of the M^2 complexity of - // the brute force approach (M=size of the alphabet) - - for (nc=qra_V;nc1) - return -2; // bad code tables - - msgbase = nc*qra_MAXCDEG; // base to msg index row for the current node - - // transforms inputs in the Walsh-Hadamard "frequency" domain - // v->c -> fwht(v->c) - for (k=0;kv = prod(fwht(v->c)) - // TODO: we assume that checks degrees are not larger than three but - // if they are larger the products can be computed more efficiently - for (kk=0;kkc steps when multipling - // small fp numbers - msgout[0]+=1E-7f; // TODO: define the bias accordingly to the field size - - np_fwht(qra_m,msgout,msgout); - - // inverse weight and output - imsg = qra_c2vmidx[msgbase+k]; // current output msg index - wmsg = qra_msgw[imsg]; // current msg weight - - if (wmsg==0) - pd_init(C2VMSG(imsg),msgout,qra_M); - else - // output p(alfa^(-w)*x) - pd_bwdperm(C2VMSG(imsg),msgout, MSGPERM(wmsg), qra_M); - - } // for (k=0;kc step ----------------------------------------------------- - for (nv=0;nvc msg = prod(c->v) - // TODO: factor factors to reduce the number of computations for high degree nodes - for (kk=0;kkc are null - // normalize output to a probability distribution - if (pd_norm(msgout,qra_m)<=0) { - // dump msgin; - printf("warning: v->c pd with invalid norm. nit=%d nv=%d k=%d\n",nit,nv,k); - for (kk=0;kk(1.*(qra_V)-0.01)) { - // the total maximum extrinsic information of each symbol in the codeword - // is very close to one. This means that we have reached the (1,1) point in the - // code EXIT chart(s) and we have successfully decoded the input. - rc = nit; - break; // remove the break to evaluate the decoder speed performance as a function of the max iterations number) - } - - } // for (nit=0;nitM; - const int qra_m = pcode->m; - const int qra_K = pcode->K; - - int k; - - for (k=0;k. + +#include +#include + +#include "npfwht.h" +#include "pdmath.h" + +#include "qracodes.h" + +int qra_encode(const qracode *pcode, int *y, const int *x) +{ + int k,j,kk,jj; + int t, chk = 0; + + const int K = pcode->K; + const int M = pcode->M; + const int NC= pcode->NC; + const int a = pcode->a; + const int *acc_input_idx = pcode->acc_input_idx; + const int *acc_input_wlog = pcode->acc_input_wlog; + const int *gflog = pcode->gflog; + const int *gfexp = pcode->gfexp; + + // copy the systematic symbols to destination + memcpy(y,x,K*sizeof(int)); + + y = y+K; // point to check symbols + + // compute the code check symbols as a weighted accumulation of a permutated + // sequence of the (repeated) systematic input symbols: + // chk(k+1) = x(idx(k))*alfa^(logw(k)) + chk(k) + // (all operations performed over GF(M)) + + if (a==1) { // grouping factor = 1 + for (k=0;k 1 + for (k=0;k80.f) // avoid floating point exp() overflows + v=80.f; + + src[nitems] = (float)exp(v); + } +} + + +float qra_mfskbesselmetric(float *pix, const float *rsq, const int m, const int N, float EsNoMetric) +{ + // Computes the codeword symbols intrinsic probabilities + // given the square of the received input amplitudes. + + // The input vector rqs must be a linear array of size M*N, where M=2^m, + // containing the squared amplitudes (rp*rp+rq*rq) of the input samples + + // First symbol amplitudes should be stored in the first M positions, + // second symbol amplitudes stored at positions [M ... 2*M-1], and so on. + + // Output vector is the intrinsic symbol metric (the probability distribution) + // assuming that symbols are transmitted using a M-FSK modulation + // and incoherent demodulation. + + // As the input Es/No is generally unknown (as it cannot be exstimated accurately + // when the codeword length is few tens symbols) but an exact metric requires it + // we simply fix it to a predefined EsNoMetric value so that the metric is what + // expected at that specific value. + // The metric computed in this way is optimal only at this predefined Es/No value, + // nevertheless it is usually better than a generic parameter-free metric which + // makes no assumptions on the input Es/No. + + // returns the estimated noise standard deviation + + int k; + float rsum = 0.f; + float sigmaest, cmetric; + + const int M = 1<M; + const int qra_m = pcode->m; + const int qra_V = pcode->V; + const int qra_MAXVDEG = pcode->MAXVDEG; + const int *qra_vdeg = pcode->vdeg; + const int qra_C = pcode->C; + const int qra_MAXCDEG = pcode->MAXCDEG; + const int *qra_cdeg = pcode->cdeg; + const int *qra_v2cmidx = pcode->v2cmidx; + const int *qra_c2vmidx = pcode->c2vmidx; + const int *qra_pmat = pcode->gfpmat; + const int *qra_msgw = pcode->msgw; + +// float msgout[qra_M]; // buffer to store temporary results + float msgout[QRACODE_MAX_M]; // we use a fixed size in order to avoid mallocs + + float totex; // total extrinsic information + int nit; // current iteration + int nv; // current variable + int nc; // current check + int k,kk; // loop indexes + + int ndeg; // current node degree + int msgbase; // current offset in the table of msg indexes + int imsg; // current message index + int wmsg; // current message weight + + int rc = -1; // rc>=0 extrinsic converged to 1 at iteration rc (rc=0..maxiter-1) + // rc=-1 no convergence in the given number of iterations + // rc=-2 error in the code tables (code checks degrees must be >1) + // rc=-3 M is larger than QRACODE_MAX_M + + + + if (qra_M>QRACODE_MAX_M) + return -3; + + // message initialization ------------------------------------------------------- + + // init c->v variable intrinsic msgs + pd_init(C2VMSG(0),pix,qra_M*qra_V); + + // init the v->c messages directed to code factors (k=1..ndeg) with the intrinsic info + for (nv=0;nvc + for (k=1;kv step ----------------------------------------------------- + // Computes messages from code checks to code variables. + // As the first qra_V checks are associated with intrinsic information + // (the code tables have been constructed in this way) + // we need to do this step only for code checks in the range [qra_V..qra_C) + + // The convolutions of probability distributions over the alphabet of a finite field GF(qra_M) + // are performed with a fast convolution algorithm over the given field. + // + // I.e. given the code check x1+x2+x3 = 0 (with x1,x2,x3 in GF(2^m)) + // and given Prob(x2) and Prob(x3), we have that: + // Prob(x1=X1) = Prob((x2+x3)=X1) = sum((Prob(x2=X2)*Prob(x3=(X1+X2))) for all the X2s in the field + // This translates to Prob(x1) = IWHT(WHT(Prob(x2))*WHT(Prob(x3))) + // where WHT and IWHT are the direct and inverse Walsh-Hadamard transforms of the argument. + // Note that the WHT and the IWHF differs only by a multiplicative coefficent and since in this step + // we don't need that the output distribution is normalized we use the relationship + // Prob(x1) =(proportional to) WH(WH(Prob(x2))*WH(Prob(x3))) + + // In general given the check code x1+x2+x3+..+xm = 0 + // the output distribution of a variable given the distributions of the other m-1 variables + // is the inverse WHT of the product of the WHTs of the distribution of the other m-1 variables + // The complexity of this algorithm scales with M*log2(M) instead of the M^2 complexity of + // the brute force approach (M=size of the alphabet) + + for (nc=qra_V;nc1) + return -2; // bad code tables + + msgbase = nc*qra_MAXCDEG; // base to msg index row for the current node + + // transforms inputs in the Walsh-Hadamard "frequency" domain + // v->c -> fwht(v->c) + for (k=0;kv = prod(fwht(v->c)) + // TODO: we assume that checks degrees are not larger than three but + // if they are larger the products can be computed more efficiently + for (kk=0;kkc steps when multipling + // small fp numbers + msgout[0]+=1E-7f; // TODO: define the bias accordingly to the field size + + np_fwht(qra_m,msgout,msgout); + + // inverse weight and output + imsg = qra_c2vmidx[msgbase+k]; // current output msg index + wmsg = qra_msgw[imsg]; // current msg weight + + if (wmsg==0) + pd_init(C2VMSG(imsg),msgout,qra_M); + else + // output p(alfa^(-w)*x) + pd_bwdperm(C2VMSG(imsg),msgout, MSGPERM(wmsg), qra_M); + + } // for (k=0;kc step ----------------------------------------------------- + for (nv=0;nvc msg = prod(c->v) + // TODO: factor factors to reduce the number of computations for high degree nodes + for (kk=0;kkc are null + // normalize output to a probability distribution + if (pd_norm(msgout,qra_m)<=0) { + // dump msgin; + printf("warning: v->c pd with invalid norm. nit=%d nv=%d k=%d\n",nit,nv,k); + for (kk=0;kk(1.*(qra_V)-0.01)) { + // the total maximum extrinsic information of each symbol in the codeword + // is very close to one. This means that we have reached the (1,1) point in the + // code EXIT chart(s) and we have successfully decoded the input. + rc = nit; + break; // remove the break to evaluate the decoder speed performance as a function of the max iterations number) + } + + } // for (nit=0;nitM; + const int qra_m = pcode->m; + const int qra_K = pcode->K; + + int k; + + for (k=0;k. - -#ifndef _qracodes_h_ -#define _qracodes_h_ - -// type of codes -#define QRATYPE_NORMAL 0x00 // normal code -#define QRATYPE_CRC 0x01 // code with crc - last information symbol is a CRC -#define QRATYPE_CRCPUNCTURED 0x02 // the CRC symbol is punctured (not sent along the channel) - - -typedef struct { - // code parameters - const int K; // number of information symbols - const int N; // codeword length in symbols - const int m; // bits/symbol - const int M; // Symbol alphabet cardinality (2^m) - const int a; // code grouping factor - const int NC; // number of check symbols (N-K) - const int V; // number of variables in the code graph (N) - const int C; // number of factors in the code graph (N +(N-K)+1) - const int NMSG; // number of msgs in the code graph - const int MAXVDEG; // maximum variable degree - const int MAXCDEG; // maximum factor degree - const int type; // see QRATYPE_xx defines - const float R; // code rate (K/N) - const char name[64]; // code name - // tables used by the encoder - const int *acc_input_idx; - const int *acc_input_wlog; - const int *gflog; - const int *gfexp; - // tables used by the decoder ------------------------- - const int *msgw; - const int *vdeg; - const int *cdeg; - const int *v2cmidx; - const int *c2vmidx; - const int *gfpmat; -} qracode; -// Uncomment the header file of the code which needs to be tested - -//#include "qra12_63_64_irr_b.h" // irregular code (12,63) over GF(64) -//#include "qra13_64_64_irr_e.h" // irregular code with good performance and best UER protection at AP56 -//#include "qra13_64_64_reg_a.h" // regular code with good UER but perf. inferior to that of code qra12_63_64_irr_b - -#ifdef __cplusplus -extern "C" { -#endif - -int qra_encode(const qracode *pcode, int *y, const int *x); -float qra_mfskbesselmetric(float *pix, const float *rsq, const int m, const int N, float EsNoMetric); -int qra_extrinsic(const qracode *pcode, float *pex, const float *pix, int maxiter,float *qra_v2cmsg,float *qra_c2vmsg); -void qra_mapdecode(const qracode *pcode, int *xdec, float *pex, const float *pix); - -#ifdef __cplusplus -} -#endif - -#endif // _qracodes_h_ +// qracodes.h +// Q-ary RA codes encoding/decoding functions +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 3 of the License, or +// (at your option) any later version. +// qracodes is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with qracodes source distribution. +// If not, see . + +#ifndef _qracodes_h_ +#define _qracodes_h_ + +// type of codes +#define QRATYPE_NORMAL 0x00 // normal code +#define QRATYPE_CRC 0x01 // code with crc - last information symbol is a CRC +#define QRATYPE_CRCPUNCTURED 0x02 // the CRC symbol is punctured (not sent along the channel) + + +typedef struct { + // code parameters + const int K; // number of information symbols + const int N; // codeword length in symbols + const int m; // bits/symbol + const int M; // Symbol alphabet cardinality (2^m) + const int a; // code grouping factor + const int NC; // number of check symbols (N-K) + const int V; // number of variables in the code graph (N) + const int C; // number of factors in the code graph (N +(N-K)+1) + const int NMSG; // number of msgs in the code graph + const int MAXVDEG; // maximum variable degree + const int MAXCDEG; // maximum factor degree + const int type; // see QRATYPE_xx defines + const float R; // code rate (K/N) + const char name[64]; // code name + // tables used by the encoder + const int *acc_input_idx; + const int *acc_input_wlog; + const int *gflog; + const int *gfexp; + // tables used by the decoder ------------------------- + const int *msgw; + const int *vdeg; + const int *cdeg; + const int *v2cmidx; + const int *c2vmidx; + const int *gfpmat; +} qracode; +// Uncomment the header file of the code which needs to be tested + +//#include "qra12_63_64_irr_b.h" // irregular code (12,63) over GF(64) +//#include "qra13_64_64_irr_e.h" // irregular code with good performance and best UER protection at AP56 +//#include "qra13_64_64_reg_a.h" // regular code with good UER but perf. inferior to that of code qra12_63_64_irr_b + +#ifdef __cplusplus +extern "C" { +#endif + +int qra_encode(const qracode *pcode, int *y, const int *x); +float qra_mfskbesselmetric(float *pix, const float *rsq, const int m, const int N, float EsNoMetric); +int qra_extrinsic(const qracode *pcode, float *pex, const float *pix, int maxiter,float *qra_v2cmsg,float *qra_c2vmsg); +void qra_mapdecode(const qracode *pcode, int *xdec, float *pex, const float *pix); + +#ifdef __cplusplus +} +#endif + +#endif // _qracodes_h_ diff --git a/lib/qra64code.f90 b/lib/qra64code.f90 index 34bfcdc4..188b5f0b 100755 --- a/lib/qra64code.f90 +++ b/lib/qra64code.f90 @@ -1,64 +1,64 @@ -program QRA64code - -! Provides examples of message packing, bit and symbol ordering, -! QRA (63,12) encoding, and other necessary details of the QRA64 -! protocol. - - use packjt - character*22 msg,msg0,msg1,decoded,cok*3,msgtype*10 - integer dgen(12),sent(63) - integer icos7(0:6) - data icos7/2,5,6,0,4,1,3/ !Defines a 7x7 Costas array - - include 'testmsg.f90' - - nargs=iargc() - if(nargs.lt.1) then - print*,'Usage: qra64code "message"' - print*,' qra64code -t' - go to 999 - endif - - call getarg(1,msg) !Get message from command line - nmsg=1 - if(msg(1:2).eq."-t") nmsg=NTEST - - write(*,1010) -1010 format(" Message Decoded Err? Type"/74("-")) - - do imsg=1,nmsg - if(nmsg.gt.1) msg=testmsg(imsg) - call fmtmsg(msg,iz) !To upper, collapse mult blanks - msg0=msg !Input message - call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report - msg1=msg !Message without "OOO" - call packmsg(msg1,dgen,itype) !Pack message into 12 six-bit bytes - msgtype="" - if(itype.eq.1) msgtype="Std Msg" - if(itype.eq.2) msgtype="Type 1 pfx" - if(itype.eq.3) msgtype="Type 1 sfx" - if(itype.eq.4) msgtype="Type 2 pfx" - if(itype.eq.5) msgtype="Type 2 sfx" - if(itype.eq.6) msgtype="Free text" - - call qra64_enc(dgen,sent) !Encode using QRA64 - - call unpackmsg(dgen,decoded) !Unpack the user message - call fmtmsg(decoded,iz) - ii=imsg - write(*,1020) ii,msg0,decoded,itype,msgtype -1020 format(i4,1x,a22,2x,a22,4x,i3,": ",a13) - enddo - - if(nmsg.eq.1) then - write(*,1030) dgen -1030 format(/'Packed message, 6-bit symbols ',12i3) !Display packed symbols - - write(*,1040) sent -1040 format(/'Information-carrying channel symbols'/(i5,29i3)) - - write(*,1050) 10*icos7,sent(1:32),10*icos7,sent(33:63),10*icos7 -1050 format(/'Channel symbols including sync'/(i5,29i3)) - endif - -999 end program QRA64code +program QRA64code + +! Provides examples of message packing, bit and symbol ordering, +! QRA (63,12) encoding, and other necessary details of the QRA64 +! protocol. + + use packjt + character*22 msg,msg0,msg1,decoded,cok*3,msgtype*10 + integer dgen(12),sent(63) + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ !Defines a 7x7 Costas array + + include 'testmsg.f90' + + nargs=iargc() + if(nargs.lt.1) then + print*,'Usage: qra64code "message"' + print*,' qra64code -t' + go to 999 + endif + + call getarg(1,msg) !Get message from command line + nmsg=1 + if(msg(1:2).eq."-t") nmsg=NTEST + + write(*,1010) +1010 format(" Message Decoded Err? Type"/74("-")) + + do imsg=1,nmsg + if(nmsg.gt.1) msg=testmsg(imsg) + call fmtmsg(msg,iz) !To upper, collapse mult blanks + msg0=msg !Input message + call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report + msg1=msg !Message without "OOO" + call packmsg(msg1,dgen,itype) !Pack message into 12 six-bit bytes + msgtype="" + if(itype.eq.1) msgtype="Std Msg" + if(itype.eq.2) msgtype="Type 1 pfx" + if(itype.eq.3) msgtype="Type 1 sfx" + if(itype.eq.4) msgtype="Type 2 pfx" + if(itype.eq.5) msgtype="Type 2 sfx" + if(itype.eq.6) msgtype="Free text" + + call qra64_enc(dgen,sent) !Encode using QRA64 + + call unpackmsg(dgen,decoded) !Unpack the user message + call fmtmsg(decoded,iz) + ii=imsg + write(*,1020) ii,msg0,decoded,itype,msgtype +1020 format(i4,1x,a22,2x,a22,4x,i3,": ",a13) + enddo + + if(nmsg.eq.1) then + write(*,1030) dgen +1030 format(/'Packed message, 6-bit symbols ',12i3) !Display packed symbols + + write(*,1040) sent +1040 format(/'Information-carrying channel symbols'/(i5,29i3)) + + write(*,1050) 10*icos7,sent(1:32),10*icos7,sent(33:63),10*icos7 +1050 format(/'Channel symbols including sync'/(i5,29i3)) + endif + +999 end program QRA64code diff --git a/lib/qratest.f90 b/lib/qratest.f90 index 2ea16c13..8e46c805 100755 --- a/lib/qratest.f90 +++ b/lib/qratest.f90 @@ -1,54 +1,54 @@ -program qratest - - parameter (NMAX=60*12000) - real dd(NMAX) - character arg*8,mycall*12,hiscall*12,hisgrid*6,decoded*22 - character c*1 - logical loop - - nargs=iargc() - if(nargs.lt.1 .or. nargs.gt.4) then - print*,'Usage: qratest nfile [sync f0 fTol]' - go to 999 - endif - call getarg(1,arg) - read(arg,*) nfile - loop=arg(1:1).eq.'+' - minsync0=-1 - nfqso0=-1 - ntol0=-1 - if(nargs.gt.1) then - call getarg(2,arg) - read(arg,*) minsync0 - call getarg(3,arg) - read(arg,*) nfqso0 - call getarg(4,arg) - read(arg,*) ntol0 - endif - ndepth=3 - nft=99 - - open(60,file='qra64_data.bin',access='stream') - - do ifile=1,999 - read(60,end=999) dd,npts,nutc,nf1,nf2,nfqso,ntol,mode64,minsync,ndepth, & - mycall,hiscall,hisgrid - if(ifile.lt.nfile) cycle - - if(minsync0.ne.-1) minsync=minsync0 - if(nfqso0.ne.-1) nfqso=nfqso0 - if(ntol0.ne.-1) ntol=ntol0 - - call qra64a(dd,npts,nf1,nf2,nfqso,ntol,mode64,minsync,ndepth, & - mycall,hiscall,hisgrid,sync,nsnr,dtx,nfreq,decoded,nft) - c='a' - if(mode64.eq.2) c='b' - if(mode64.eq.4) c='c' - if(mode64.eq.8) c='d' - if(mode64.eq.16) c='e' - write(*,1000) ifile,c,nutc,nsnr,dtx,nfreq,decoded,nft-100,sync-3.4 -1000 format(i4,1x,a1,1x,i4.4,i4,f6.2,i5,1x,a22,i3,f6.2) - if(ifile.eq.nfile .and. (.not.loop)) exit - enddo - -999 end program qratest +program qratest + + parameter (NMAX=60*12000) + real dd(NMAX) + character arg*8,mycall*12,hiscall*12,hisgrid*6,decoded*22 + character c*1 + logical loop + + nargs=iargc() + if(nargs.lt.1 .or. nargs.gt.4) then + print*,'Usage: qratest nfile [sync f0 fTol]' + go to 999 + endif + call getarg(1,arg) + read(arg,*) nfile + loop=arg(1:1).eq.'+' + minsync0=-1 + nfqso0=-1 + ntol0=-1 + if(nargs.gt.1) then + call getarg(2,arg) + read(arg,*) minsync0 + call getarg(3,arg) + read(arg,*) nfqso0 + call getarg(4,arg) + read(arg,*) ntol0 + endif + ndepth=3 + nft=99 + + open(60,file='qra64_data.bin',access='stream') + + do ifile=1,999 + read(60,end=999) dd,npts,nutc,nf1,nf2,nfqso,ntol,mode64,minsync,ndepth, & + mycall,hiscall,hisgrid + if(ifile.lt.nfile) cycle + + if(minsync0.ne.-1) minsync=minsync0 + if(nfqso0.ne.-1) nfqso=nfqso0 + if(ntol0.ne.-1) ntol=ntol0 + + call qra64a(dd,npts,nf1,nf2,nfqso,ntol,mode64,minsync,ndepth, & + mycall,hiscall,hisgrid,sync,nsnr,dtx,nfreq,decoded,nft) + c='a' + if(mode64.eq.2) c='b' + if(mode64.eq.4) c='c' + if(mode64.eq.8) c='d' + if(mode64.eq.16) c='e' + write(*,1000) ifile,c,nutc,nsnr,dtx,nfreq,decoded,nft-100,sync-3.4 +1000 format(i4,1x,a1,1x,i4.4,i4,f6.2,i5,1x,a22,i3,f6.2) + if(ifile.eq.nfile .and. (.not.loop)) exit + enddo + +999 end program qratest diff --git a/lib/readwav.f90 b/lib/readwav.f90 index 0784d0a8..25369049 100755 --- a/lib/readwav.f90 +++ b/lib/readwav.f90 @@ -1,73 +1,73 @@ -! -! readwav - open and read the header of a WAV format file -! -! On successful exit the file is left positioned at the start of the -! data. -! -! Example of usage: -! -! use readwav -! integer*2 sample -! type(wav_header) wav -! call wav%read ('file.wav') -! write (*,*) 'Sample rate is: ', wav%audio_format%sample_rate -! do i=0,wav%data_size -! read (unit=wav%lun) sample -! ! process sample -! end do -! -module readwav - implicit none - - type format_chunk - integer*2 audio_format - integer*2 num_channels - integer sample_rate - integer byte_rate - integer*2 block_align - integer*2 bits_per_sample - end type format_chunk - - type, public :: wav_header - integer :: lun - type(format_chunk) :: audio_format - integer :: data_size - contains - procedure :: read - end type wav_header - - private -contains - subroutine read (this, filename) - implicit none - - type riff_descriptor - character(len=4) :: id - integer :: size - end type riff_descriptor - - class(wav_header), intent(inout) :: this - character(len=*), intent(in) :: filename - - integer :: filepos - type(riff_descriptor) :: desc - character(len=4) :: riff_type - - this%lun=26 - open (unit=this%lun, file=filename, access='stream',status='old') - read (unit=this%lun) desc,riff_type - inquire (unit=this%lun, pos=filepos) - do - read (unit=this%lun, pos=filepos) desc - inquire (unit=this%lun, pos=filepos) - if (desc%id .eq. 'fmt ') then - read (unit=this%lun) this%audio_format - else if (desc%id .eq. 'data') then - this%data_size = desc%size - exit - end if - filepos = filepos + (desc%size + 1) / 2 * 2 ! pad to even alignment - end do - return - end subroutine read -end module readwav +! +! readwav - open and read the header of a WAV format file +! +! On successful exit the file is left positioned at the start of the +! data. +! +! Example of usage: +! +! use readwav +! integer*2 sample +! type(wav_header) wav +! call wav%read ('file.wav') +! write (*,*) 'Sample rate is: ', wav%audio_format%sample_rate +! do i=0,wav%data_size +! read (unit=wav%lun) sample +! ! process sample +! end do +! +module readwav + implicit none + + type format_chunk + integer*2 audio_format + integer*2 num_channels + integer sample_rate + integer byte_rate + integer*2 block_align + integer*2 bits_per_sample + end type format_chunk + + type, public :: wav_header + integer :: lun + type(format_chunk) :: audio_format + integer :: data_size + contains + procedure :: read + end type wav_header + + private +contains + subroutine read (this, filename) + implicit none + + type riff_descriptor + character(len=4) :: id + integer :: size + end type riff_descriptor + + class(wav_header), intent(inout) :: this + character(len=*), intent(in) :: filename + + integer :: filepos + type(riff_descriptor) :: desc + character(len=4) :: riff_type + + this%lun=26 + open (unit=this%lun, file=filename, access='stream',status='old') + read (unit=this%lun) desc,riff_type + inquire (unit=this%lun, pos=filepos) + do + read (unit=this%lun, pos=filepos) desc + inquire (unit=this%lun, pos=filepos) + if (desc%id .eq. 'fmt ') then + read (unit=this%lun) this%audio_format + else if (desc%id .eq. 'data') then + this%data_size = desc%size + exit + end if + filepos = filepos + (desc%size + 1) / 2 * 2 ! pad to even alignment + end do + return + end subroutine read +end module readwav diff --git a/lib/rectify_msk.f90 b/lib/rectify_msk.f90 index f48ee211..ff5ee497 100755 --- a/lib/rectify_msk.f90 +++ b/lib/rectify_msk.f90 @@ -1,64 +1,64 @@ -subroutine rectify_msk(c,msg0,imsg,freq2) - - parameter (NSPM=1404) - complex c(0:NSPM-1) !Received data - complex cmsg(0:NSPM-1) !Message waveform - complex c1(0:NSPM-1) !Rectified signal - complex c2(0:NSPM-1) !Integral of rectified signal - complex c3(0:2*NSPM-1) !FFT of rectified signal - complex cfac - character*22 msg0,msg,msgsent - integer i4tone(234) - - ichk=0 - msg=msg0 - nsym=234 - if(imsg.ge.0) then - ichk=10000+imsg - msg=" 73" - nsym=35 - endif - call genmsk(msg,ichk,msgsent,i4tone,itype) !Get tone sequence for msg - - twopi=8.0*atan(1.0) - dt=1.0/12000.0 - f0=1000.0 - f1=2000.0 - phi=0. - dphi=0. - k=-1 - c2=0. - do j=1,nsym !Generate Tx waveform for msg - if(i4tone(j).eq.0) dphi=twopi*f0*dt - if(i4tone(j).eq.1) dphi=twopi*f1*dt - do i=1,6 - k=k+1 - phi=phi+dphi - cmsg(k)=cmplx(cos(phi),sin(phi)) - c1(k)=conjg(cmsg(k))*c(k) - if(k.ge.1) c2(k)=c2(k-1) + c1(k) - enddo - enddo - c2(0)=c2(1) - pha=atan2(aimag(c2(NSPM-1)),real(c2(NSPM-1))) - cfac=cmplx(cos(pha),-sin(pha)) - c1=cfac*c1 - c2=cfac*c2 - nfft=2*NSPM - c3(0:NSPM-1)=c2 - c3(NSPM:nfft-1)=0. - df=12000.0/nfft - call four2a(c3,nfft,1,-1,1) - smax=0. - do i=0,nfft-1 - f=i*df - if(i.gt.nfft/2) f=f-12000.0 - s=1.e-10*(real(c3(i))**2 + aimag(c3(i))**2) - if(s.gt.smax) then - smax=s - freq2=1500.0 + f - endif - enddo - - return -end subroutine rectify_msk +subroutine rectify_msk(c,msg0,imsg,freq2) + + parameter (NSPM=1404) + complex c(0:NSPM-1) !Received data + complex cmsg(0:NSPM-1) !Message waveform + complex c1(0:NSPM-1) !Rectified signal + complex c2(0:NSPM-1) !Integral of rectified signal + complex c3(0:2*NSPM-1) !FFT of rectified signal + complex cfac + character*22 msg0,msg,msgsent + integer i4tone(234) + + ichk=0 + msg=msg0 + nsym=234 + if(imsg.ge.0) then + ichk=10000+imsg + msg=" 73" + nsym=35 + endif + call genmsk(msg,ichk,msgsent,i4tone,itype) !Get tone sequence for msg + + twopi=8.0*atan(1.0) + dt=1.0/12000.0 + f0=1000.0 + f1=2000.0 + phi=0. + dphi=0. + k=-1 + c2=0. + do j=1,nsym !Generate Tx waveform for msg + if(i4tone(j).eq.0) dphi=twopi*f0*dt + if(i4tone(j).eq.1) dphi=twopi*f1*dt + do i=1,6 + k=k+1 + phi=phi+dphi + cmsg(k)=cmplx(cos(phi),sin(phi)) + c1(k)=conjg(cmsg(k))*c(k) + if(k.ge.1) c2(k)=c2(k-1) + c1(k) + enddo + enddo + c2(0)=c2(1) + pha=atan2(aimag(c2(NSPM-1)),real(c2(NSPM-1))) + cfac=cmplx(cos(pha),-sin(pha)) + c1=cfac*c1 + c2=cfac*c2 + nfft=2*NSPM + c3(0:NSPM-1)=c2 + c3(NSPM:nfft-1)=0. + df=12000.0/nfft + call four2a(c3,nfft,1,-1,1) + smax=0. + do i=0,nfft-1 + f=i*df + if(i.gt.nfft/2) f=f-12000.0 + s=1.e-10*(real(c3(i))**2 + aimag(c3(i))**2) + if(s.gt.smax) then + smax=s + freq2=1500.0 + f + endif + enddo + + return +end subroutine rectify_msk diff --git a/lib/refspectrum.f90 b/lib/refspectrum.f90 index 67c0cb2b..68b514f9 100755 --- a/lib/refspectrum.f90 +++ b/lib/refspectrum.f90 @@ -1,158 +1,158 @@ -subroutine refspectrum(id2,bclear,brefspec,buseref,fname) - -! Input: -! id2 i*2 Raw 16-bit integer data, 12000 Hz sample rate -! brefspec logical True when accumulating a reference spectrum - - parameter (NFFT=6912,NH=NFFT/2,NPOLYLOW=400,NPOLYHIGH=2600) - integer*2 id2(NFFT) - logical*1 bclear,brefspec,buseref,blastuse - - real xs(0:NH-1) !Saved upper half of input chunk convolved with h(t) - real x(0:NFFT-1) !Work array - real*4 w(0:NFFT-1) !Window function - real*4 s(0:NH) !Average spectrum - real*4 fil(0:NH) - real*8 xfit(1500),yfit(1500),sigmay(1500),a(5),chisqr !Polyfit arrays - logical first - complex cx(0:NH) !Complex frequency-domain work array - complex cfil(0:NH) - character*(*) fname - common/spectra/syellow(6827),ref(0:NH),filter(0:NH) - equivalence(x,cx) - data first/.true./,blastuse/.false./ - save - - if(first) then - pi=4.0*atan(1.0) - do i=0,NFFT-1 - ww=sin(i*pi/NFFT) - w(i)=ww*ww/NFFT - enddo - nsave=0 - s=0.0 - filter=1.0 - xs=0. - first=.false. - endif - if(bclear) s=0. - - if(brefspec) then - x(0:NH-1)=0.001*id2(1:NH) - x(NH:NFFT-1)=0.0 - call four2a(cx,NFFT,1,-1,0) !r2c FFT - - do i=1,NH - s(i)=s(i) + real(cx(i))**2 + aimag(cx(i))**2 - enddo - nsave=nsave+1 - - fac0=0.9 - if(mod(nsave,4).eq.0) then - df=12000.0/NFFT - ia=nint(1000.0/df) - ib=nint(2000.0/df) - avemid=sum(s(ia:ib))/(ib-ia+1) - do i=0,NH - fil(i)=0. - if(s(i).gt.0.0) then - fil(i)=sqrt(avemid/s(i)) - endif - enddo - -! Default range is 240 - 4000 Hz. For narrower filters, use frequencies -! at which gain is -20 dB relative to 1500 Hz. - ia=nint(240.0/df) - ib=nint(4000.0/df) - i0=nint(1500.0/df) - do i=i0,ia,-1 - if(s(i)/s(i0).lt.0.01) exit - enddo - ia=i - do i=i0,ib,1 - if(s(i)/s(i0).lt.0.01) exit - enddo - ib=i - - fac=fac0 - do i=ia,1,-1 - fac=fac*fac0 - fil(i)=fac*fil(i) - enddo - - fac=fac0 - do i=ib,NH - fac=fac*fac0 - fil(i)=fac*fil(i) - enddo - - do iter=1,100 !### ??? ### - call smo121(fil,NH) - enddo - - do i=0,NH - filter(i)=-60.0 - if(s(i).gt.0.0) filter(i)=20.0*log10(fil(i)) - enddo - - il=nint(NPOLYLOW/df) - ih=nint(NPOLYHIGH/df) - nfit=ih-il+1 - mode=0 - nterms=5 - do i=1,nfit - xfit(i)=((i+il-1)*df-1500.0)/1000.0 - yfit(i)=fil(i+il-1) - sigmay(i)=1.0 - enddo - call polyfit(xfit,yfit,sigmay,nfit,nterms,mode,a,chisqr) - - open(16,file=fname,status='unknown') - write(16,1003) NPOLYLOW,NPOLYHIGH,nterms,a -1003 format(3i5,5e25.16) - do i=1,NH - freq=i*df - ref(i)=db(s(i)/avemid) - write(16,1005) freq,s(i),ref(i),fil(i),filter(i) -1005 format(f10.3,e12.3,f12.6,e12.3,f12.6) - enddo - close(16) - endif - return - endif - - if(buseref) then - if(blastuse.neqv.buseref) then !just enabled so read filter - fil=1.0 - open(16,file=fname,status='old',err=999) - read(16,1003,err=20,end=999) ndummy,ndummy,nterms,a - goto 30 -20 rewind(16) !allow for old style refspec.dat with no header -30 do i=1,NH - read(16,1005,err=999,end=999) freq,s(i),ref(i),fil(i),filter(i) - enddo -! Make the filter causal for overlap and add. - cx(0)=0.0 - cx(1:NH)=fil(1:NH)/NFFT - call four2a(cx,NFFT,1,1,-1) - x=cshift(x,-400) - x(800:NH)=0.0 - call four2a(cx,NFFT,1,-1,0) - cfil=cx - close(16) - endif -! Use overlap and add method to apply causal reference filter. - x(0:NH-1)=id2(1:NH) - x(NH:NFFT-1)=0.0 - x=x/NFFT - call four2a(cx,NFFT,1,-1,0) - cx=cfil*cx - call four2a(cx,NFFT,1,1,-1) - x(0:NH-1)=x(0:NH-1)+xs - xs=x(NH:NFFT-1) - id2(1:NH)=nint(x(0:NH-1)) - endif - blastuse=buseref - -999 return -end subroutine refspectrum +subroutine refspectrum(id2,bclear,brefspec,buseref,fname) + +! Input: +! id2 i*2 Raw 16-bit integer data, 12000 Hz sample rate +! brefspec logical True when accumulating a reference spectrum + + parameter (NFFT=6912,NH=NFFT/2,NPOLYLOW=400,NPOLYHIGH=2600) + integer*2 id2(NFFT) + logical*1 bclear,brefspec,buseref,blastuse + + real xs(0:NH-1) !Saved upper half of input chunk convolved with h(t) + real x(0:NFFT-1) !Work array + real*4 w(0:NFFT-1) !Window function + real*4 s(0:NH) !Average spectrum + real*4 fil(0:NH) + real*8 xfit(1500),yfit(1500),sigmay(1500),a(5),chisqr !Polyfit arrays + logical first + complex cx(0:NH) !Complex frequency-domain work array + complex cfil(0:NH) + character*(*) fname + common/spectra/syellow(6827),ref(0:NH),filter(0:NH) + equivalence(x,cx) + data first/.true./,blastuse/.false./ + save + + if(first) then + pi=4.0*atan(1.0) + do i=0,NFFT-1 + ww=sin(i*pi/NFFT) + w(i)=ww*ww/NFFT + enddo + nsave=0 + s=0.0 + filter=1.0 + xs=0. + first=.false. + endif + if(bclear) s=0. + + if(brefspec) then + x(0:NH-1)=0.001*id2(1:NH) + x(NH:NFFT-1)=0.0 + call four2a(cx,NFFT,1,-1,0) !r2c FFT + + do i=1,NH + s(i)=s(i) + real(cx(i))**2 + aimag(cx(i))**2 + enddo + nsave=nsave+1 + + fac0=0.9 + if(mod(nsave,4).eq.0) then + df=12000.0/NFFT + ia=nint(1000.0/df) + ib=nint(2000.0/df) + avemid=sum(s(ia:ib))/(ib-ia+1) + do i=0,NH + fil(i)=0. + if(s(i).gt.0.0) then + fil(i)=sqrt(avemid/s(i)) + endif + enddo + +! Default range is 240 - 4000 Hz. For narrower filters, use frequencies +! at which gain is -20 dB relative to 1500 Hz. + ia=nint(240.0/df) + ib=nint(4000.0/df) + i0=nint(1500.0/df) + do i=i0,ia,-1 + if(s(i)/s(i0).lt.0.01) exit + enddo + ia=i + do i=i0,ib,1 + if(s(i)/s(i0).lt.0.01) exit + enddo + ib=i + + fac=fac0 + do i=ia,1,-1 + fac=fac*fac0 + fil(i)=fac*fil(i) + enddo + + fac=fac0 + do i=ib,NH + fac=fac*fac0 + fil(i)=fac*fil(i) + enddo + + do iter=1,100 !### ??? ### + call smo121(fil,NH) + enddo + + do i=0,NH + filter(i)=-60.0 + if(s(i).gt.0.0) filter(i)=20.0*log10(fil(i)) + enddo + + il=nint(NPOLYLOW/df) + ih=nint(NPOLYHIGH/df) + nfit=ih-il+1 + mode=0 + nterms=5 + do i=1,nfit + xfit(i)=((i+il-1)*df-1500.0)/1000.0 + yfit(i)=fil(i+il-1) + sigmay(i)=1.0 + enddo + call polyfit(xfit,yfit,sigmay,nfit,nterms,mode,a,chisqr) + + open(16,file=fname,status='unknown') + write(16,1003) NPOLYLOW,NPOLYHIGH,nterms,a +1003 format(3i5,5e25.16) + do i=1,NH + freq=i*df + ref(i)=db(s(i)/avemid) + write(16,1005) freq,s(i),ref(i),fil(i),filter(i) +1005 format(f10.3,e12.3,f12.6,e12.3,f12.6) + enddo + close(16) + endif + return + endif + + if(buseref) then + if(blastuse.neqv.buseref) then !just enabled so read filter + fil=1.0 + open(16,file=fname,status='old',err=999) + read(16,1003,err=20,end=999) ndummy,ndummy,nterms,a + goto 30 +20 rewind(16) !allow for old style refspec.dat with no header +30 do i=1,NH + read(16,1005,err=999,end=999) freq,s(i),ref(i),fil(i),filter(i) + enddo +! Make the filter causal for overlap and add. + cx(0)=0.0 + cx(1:NH)=fil(1:NH)/NFFT + call four2a(cx,NFFT,1,1,-1) + x=cshift(x,-400) + x(800:NH)=0.0 + call four2a(cx,NFFT,1,-1,0) + cfil=cx + close(16) + endif +! Use overlap and add method to apply causal reference filter. + x(0:NH-1)=id2(1:NH) + x(NH:NFFT-1)=0.0 + x=x/NFFT + call four2a(cx,NFFT,1,-1,0) + cx=cfil*cx + call four2a(cx,NFFT,1,1,-1) + x(0:NH-1)=x(0:NH-1)+xs + xs=x(NH:NFFT-1) + id2(1:NH)=nint(x(0:NH-1)) + endif + blastuse=buseref + +999 return +end subroutine refspectrum diff --git a/lib/rig_control.c b/lib/rig_control.c index 3baa01a2..7c8b2f62 100755 --- a/lib/rig_control.c +++ b/lib/rig_control.c @@ -1,99 +1,99 @@ -#include "config.h" -#include -#include -#include -#include "tstrig.h" - -RIG *my_rig; // handle to rig - -int set_conf(RIG *my_rig, char *conf_parms); - -//------------------------------------------------------------------------ -int set_conf(RIG *my_rig, char *conf_parms) -{ - char *p, *q, *n; - int iret; - - p = conf_parms; - while (p && *p != '\0') { - /* FIXME: left hand value of = cannot be null */ - q = strchr(p, '='); - if ( !q ) - return -RIG_EINVAL; - *q++ = '\0'; - n = strchr(q, ','); - if (n) *n++ = '\0'; - iret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q); - if (iret != RIG_OK) - return iret; - p = n; - } - return RIG_OK; -} - -//------------------------------------------------------------------------ -int rigOpen(int verbose, rig_model_t my_model, const char* rig_file, - int serial_rate, const char* conf_parms2) -{ - int iret; /* generic return code from functions */ - char *civaddr = NULL; /* NULL means no need to set conf */ - // const char *rig_file; - // const char *conf_parms2; - // int serial_rate; - - rig_set_debug(verbose); - my_rig=rig_init(my_model); - - if (!my_rig) { - // fprintf(stderr, "Unknown rig num %d, or initialization error.\n",my_model); - return -1; - } - - // rig_file="COM1"; - // serial_rate=4800; - // conf_parms2="data_bits=8,stop_bits=2,serial_handshake=Hardware"; - - iret=set_conf(my_rig, conf_parms2); - if (iret!=RIG_OK) { - // fprintf(stderr, "Config parameter error: %s\n", rigerror(iret)); - return -2; - } - - if (rig_file) - strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); - - if (serial_rate!=0) - my_rig->state.rigport.parm.serial.rate = serial_rate; - - if (civaddr) - rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr); - - iret = rig_open(my_rig); - if(iret!=0) return -3; - return 0; -} - -int rigSetFreq(int fHz) -{ - return rig_set_freq(my_rig,RIG_VFO_CURR,fHz); -} - -int rigFreq(int *fHz) -{ - int iret=0; - freq_t freq; - iret=rig_get_freq(my_rig, RIG_VFO_CURR, &freq); - *fHz=freq; - return iret; -} - -int rigSetPTT(int iptt) -{ - return rig_set_ptt(my_rig, RIG_VFO_CURR, iptt); -} - -void rigClose() -{ - rig_close(my_rig); - rig_cleanup(my_rig); -} +#include "config.h" +#include +#include +#include +#include "tstrig.h" + +RIG *my_rig; // handle to rig + +int set_conf(RIG *my_rig, char *conf_parms); + +//------------------------------------------------------------------------ +int set_conf(RIG *my_rig, char *conf_parms) +{ + char *p, *q, *n; + int iret; + + p = conf_parms; + while (p && *p != '\0') { + /* FIXME: left hand value of = cannot be null */ + q = strchr(p, '='); + if ( !q ) + return -RIG_EINVAL; + *q++ = '\0'; + n = strchr(q, ','); + if (n) *n++ = '\0'; + iret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q); + if (iret != RIG_OK) + return iret; + p = n; + } + return RIG_OK; +} + +//------------------------------------------------------------------------ +int rigOpen(int verbose, rig_model_t my_model, const char* rig_file, + int serial_rate, const char* conf_parms2) +{ + int iret; /* generic return code from functions */ + char *civaddr = NULL; /* NULL means no need to set conf */ + // const char *rig_file; + // const char *conf_parms2; + // int serial_rate; + + rig_set_debug(verbose); + my_rig=rig_init(my_model); + + if (!my_rig) { + // fprintf(stderr, "Unknown rig num %d, or initialization error.\n",my_model); + return -1; + } + + // rig_file="COM1"; + // serial_rate=4800; + // conf_parms2="data_bits=8,stop_bits=2,serial_handshake=Hardware"; + + iret=set_conf(my_rig, conf_parms2); + if (iret!=RIG_OK) { + // fprintf(stderr, "Config parameter error: %s\n", rigerror(iret)); + return -2; + } + + if (rig_file) + strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); + + if (serial_rate!=0) + my_rig->state.rigport.parm.serial.rate = serial_rate; + + if (civaddr) + rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr); + + iret = rig_open(my_rig); + if(iret!=0) return -3; + return 0; +} + +int rigSetFreq(int fHz) +{ + return rig_set_freq(my_rig,RIG_VFO_CURR,fHz); +} + +int rigFreq(int *fHz) +{ + int iret=0; + freq_t freq; + iret=rig_get_freq(my_rig, RIG_VFO_CURR, &freq); + *fHz=freq; + return iret; +} + +int rigSetPTT(int iptt) +{ + return rig_set_ptt(my_rig, RIG_VFO_CURR, iptt); +} + +void rigClose() +{ + rig_close(my_rig); + rig_cleanup(my_rig); +} diff --git a/lib/rs.h b/lib/rs.h index 6f153146..06cbe344 100755 --- a/lib/rs.h +++ b/lib/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/lib/rtty_spec.f90 b/lib/rtty_spec.f90 index eca272e3..2ddc802f 100755 --- a/lib/rtty_spec.f90 +++ b/lib/rtty_spec.f90 @@ -1,102 +1,102 @@ -program rtty_spec - -! Generate simulated data for standard RTTY and WSJT-X modes FT8, FT4 - - use wavhdr - use packjt - parameter (NMAX=15*12000) - type(hdr) h - complex cwave(NMAX) - real wave(NMAX) - real*4 dat(NMAX) !Generated waveform - integer*2 iwave(NMAX) !Generated waveform - integer itone(680) !Channel symbols (values 0-1, 0-3, 0-7) - integer*1 msgbits(77) - character*37 msg37,msgsent37 - character*8 arg - - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: rtty_spec ' - go to 999 - endif - call getarg(1,arg) - read(arg,*) snrdb !S/N in dB (2500 hz reference BW) - - rmsdb=25. - rms=10.0**(0.05*rmsdb) - sig=10.0**(0.05*snrdb) - npts=NMAX - - do i=1,NMAX !Generate gaussian noise - dat(i)=gran() - enddo - -! Add the RTTY signal - fsample=12000.0 !Sample rate (Hz) - dt=1.0/fsample !Sample interval (s) - twopi=8.0*atan(1.0) - phi=0. - dphi=0. - j0=-1 - do i=6001,NMAX-6000 - j=nint(i*dt/0.022) - if(j.ne.j0) then - f0=1415.0 - call random_number(rr) - if(rr.gt.0.5) f0=1585.0 - dphi=twopi*f0*dt - j0=j - endif - phi=phi+dphi - if(phi.gt.twopi) phi=phi-twopi - dat(i)=dat(i) + sig*sin(phi) - enddo - -! FT8 signal (FSK) - i3=0 - n3=0 - msg37='WB9XYZ KA2ABC FN42' - call genft8(msg37,i3,n3,msgsent37,msgbits,itone) - nsym=79 - nsps=1920 - bt=99.0 - f0=3500.0 - icmplx=0 - nwave=nsym*nsps - call gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) - dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave) - -! FT8 signal (GFSK) - i3=0 - n3=0 - msg37='WB9XYZ KA2ABC FN42' - call genft8(msg37,i3,n3,msgsent37,msgbits,itone) - nsym=79 - nsps=1920 - bt=2.0 - f0=4000.0 - icmplx=0 - nwave=nsym*nsps - call gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) - dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave) - -! Add the FT4 signal - ichk=0 - call genft4(msg37,ichk,msgsent37,msgbits,itone) - nsym=103 - nsps=576 - f0=4500.0 - icmplx=0 - nwave=(nsym+2)*nsps - call gen_ft4wave(itone,nsym,nsps,fsample,f0,cwave,wave,icmplx,nwave) - dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave) - - h=default_header(12000,NMAX) - datmax=maxval(abs(dat)) - iwave=nint(32767.0*dat/datmax) - open(10,file='000000_000001.wav',access='stream',status='unknown') - write(10) h,iwave - close(10) - -999 end program rtty_spec +program rtty_spec + +! Generate simulated data for standard RTTY and WSJT-X modes FT8, FT4 + + use wavhdr + use packjt + parameter (NMAX=15*12000) + type(hdr) h + complex cwave(NMAX) + real wave(NMAX) + real*4 dat(NMAX) !Generated waveform + integer*2 iwave(NMAX) !Generated waveform + integer itone(680) !Channel symbols (values 0-1, 0-3, 0-7) + integer*1 msgbits(77) + character*37 msg37,msgsent37 + character*8 arg + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: rtty_spec ' + go to 999 + endif + call getarg(1,arg) + read(arg,*) snrdb !S/N in dB (2500 hz reference BW) + + rmsdb=25. + rms=10.0**(0.05*rmsdb) + sig=10.0**(0.05*snrdb) + npts=NMAX + + do i=1,NMAX !Generate gaussian noise + dat(i)=gran() + enddo + +! Add the RTTY signal + fsample=12000.0 !Sample rate (Hz) + dt=1.0/fsample !Sample interval (s) + twopi=8.0*atan(1.0) + phi=0. + dphi=0. + j0=-1 + do i=6001,NMAX-6000 + j=nint(i*dt/0.022) + if(j.ne.j0) then + f0=1415.0 + call random_number(rr) + if(rr.gt.0.5) f0=1585.0 + dphi=twopi*f0*dt + j0=j + endif + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + dat(i)=dat(i) + sig*sin(phi) + enddo + +! FT8 signal (FSK) + i3=0 + n3=0 + msg37='WB9XYZ KA2ABC FN42' + call genft8(msg37,i3,n3,msgsent37,msgbits,itone) + nsym=79 + nsps=1920 + bt=99.0 + f0=3500.0 + icmplx=0 + nwave=nsym*nsps + call gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) + dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave) + +! FT8 signal (GFSK) + i3=0 + n3=0 + msg37='WB9XYZ KA2ABC FN42' + call genft8(msg37,i3,n3,msgsent37,msgbits,itone) + nsym=79 + nsps=1920 + bt=2.0 + f0=4000.0 + icmplx=0 + nwave=nsym*nsps + call gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) + dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave) + +! Add the FT4 signal + ichk=0 + call genft4(msg37,ichk,msgsent37,msgbits,itone) + nsym=103 + nsps=576 + f0=4500.0 + icmplx=0 + nwave=(nsym+2)*nsps + call gen_ft4wave(itone,nsym,nsps,fsample,f0,cwave,wave,icmplx,nwave) + dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave) + + h=default_header(12000,NMAX) + datmax=maxval(abs(dat)) + iwave=nint(32767.0*dat/datmax) + open(10,file='000000_000001.wav',access='stream',status='unknown') + write(10) h,iwave + close(10) + +999 end program rtty_spec diff --git a/lib/save_dxbase.f90 b/lib/save_dxbase.f90 index 4645125f..206dfd5e 100755 --- a/lib/save_dxbase.f90 +++ b/lib/save_dxbase.f90 @@ -1,9 +1,9 @@ -subroutine save_dxbase(dxbase0) - - use packjt77 - character*6 dxbase0 - - dxbase=dxbase0 - - return -end subroutine save_dxbase +subroutine save_dxbase(dxbase0) + + use packjt77 + character*6 dxbase0 + + dxbase=dxbase0 + + return +end subroutine save_dxbase diff --git a/lib/save_echo_params.f90 b/lib/save_echo_params.f90 index 500a997c..56930ba8 100755 --- a/lib/save_echo_params.f90 +++ b/lib/save_echo_params.f90 @@ -1,29 +1,29 @@ -subroutine save_echo_params(nDopTotal,nDopAudio,nfrit,f1,fspread,id2,idir) - - integer*2 id2(10) - integer*2 id2a(10) - equivalence (nDopTotal0,id2a(1)) - equivalence (nDopAudio0,id2a(3)) - equivalence (nfrit0,id2a(5)) - equivalence (f10,id2a(7)) - equivalence (fspread0,id2a(9)) - - if(idir.gt.0) then - nDopTotal0=nDopTotal - nDopAudio0=nDopAudio - nfrit0=nfrit - f10=f1 - fspread0=fspread - id2=id2a - else - id2a=id2 - id2(1:10)=0 - nDopTotal=nDopTotal0 - nDopAudio=nDopAudio0 - nfrit=nfrit0 - f1=f10 - fspread=fspread0 - endif - - return -end subroutine save_echo_params +subroutine save_echo_params(nDopTotal,nDopAudio,nfrit,f1,fspread,id2,idir) + + integer*2 id2(10) + integer*2 id2a(10) + equivalence (nDopTotal0,id2a(1)) + equivalence (nDopAudio0,id2a(3)) + equivalence (nfrit0,id2a(5)) + equivalence (f10,id2a(7)) + equivalence (fspread0,id2a(9)) + + if(idir.gt.0) then + nDopTotal0=nDopTotal + nDopAudio0=nDopAudio + nfrit0=nfrit + f10=f1 + fspread0=fspread + id2=id2a + else + id2a=id2 + id2(1:10)=0 + nDopTotal=nDopTotal0 + nDopAudio=nDopAudio0 + nfrit=nfrit0 + f1=f10 + fspread=fspread0 + endif + + return +end subroutine save_echo_params diff --git a/lib/savec2.f90 b/lib/savec2.f90 index 6be9c06f..6435a215 100755 --- a/lib/savec2.f90 +++ b/lib/savec2.f90 @@ -1,55 +1,55 @@ -integer function savec2(c2name,ntrseconds,f0m1500) - -! Array c0() has complex samples at 1500 Hz sample rate. -! WSPR-2: downsample by 1/4 to produce c2, centered at 1500 Hz -! WSPR-15: downsample by 1/32 to produce c2, centered at 1612.5 Hz - - parameter (NDMAX=120*1500) !Sample intervals at 1500 Hz rate - parameter (MAXFFT=256*1024) - - character*(*) c2name - character*14 outfile - real*8 f0m1500 - complex c0 - complex c1(0:MAXFFT-1) - complex c2(0:65535) - common/c0com/c0(0:NDMAX-1) - - ntrminutes=ntrseconds/60 - npts=114*1500 - nfft1=262144 - if(ntrminutes.eq.15) then - npts=890*1500 - nfft1=MAXFFT - endif - df1=1500.0/nfft1 - fac=1.0/nfft1 - c1(0:npts-1)=fac*c0(0:npts-1) - c1(npts:nfft1-1)=0. - - call four2a(c1,nfft1,1,1,1) !Complex FFT to frequency domain - -! Select the desired frequency range - nfft2=65536 - nh2=nfft2/2 - if(ntrminutes.eq.2) then - c2(0:nh2)=c1(0:nh2) - c2(nh2+1:nfft2-1)=c1(nfft1-nh2+1:nfft1-1) - else - i0=nint(112.5/df1) - c2(0:nh2)=c1(i0:i0+nh2) - c2(nh2+1:nfft2-1)=c1(i0-nh2+1:i0-1) - endif - - call four2a(c2,nfft2,1,-1,1) !Shorter complex FFT, back to time domain - -! Write complex time-domain data to disk. - i1=index(c2name,'.c2') - outfile=c2name(i1-11:i1+2) - open(18,file=c2name,status='unknown',access='stream', iostat=ioerr) - if (ioerr.eq.0) then - write(18) outfile,ntrminutes,f0m1500,c2(0:45000-1) - close(18) - endif - savec2 = ioerr -end function savec2 +integer function savec2(c2name,ntrseconds,f0m1500) + +! Array c0() has complex samples at 1500 Hz sample rate. +! WSPR-2: downsample by 1/4 to produce c2, centered at 1500 Hz +! WSPR-15: downsample by 1/32 to produce c2, centered at 1612.5 Hz + + parameter (NDMAX=120*1500) !Sample intervals at 1500 Hz rate + parameter (MAXFFT=256*1024) + + character*(*) c2name + character*14 outfile + real*8 f0m1500 + complex c0 + complex c1(0:MAXFFT-1) + complex c2(0:65535) + common/c0com/c0(0:NDMAX-1) + + ntrminutes=ntrseconds/60 + npts=114*1500 + nfft1=262144 + if(ntrminutes.eq.15) then + npts=890*1500 + nfft1=MAXFFT + endif + df1=1500.0/nfft1 + fac=1.0/nfft1 + c1(0:npts-1)=fac*c0(0:npts-1) + c1(npts:nfft1-1)=0. + + call four2a(c1,nfft1,1,1,1) !Complex FFT to frequency domain + +! Select the desired frequency range + nfft2=65536 + nh2=nfft2/2 + if(ntrminutes.eq.2) then + c2(0:nh2)=c1(0:nh2) + c2(nh2+1:nfft2-1)=c1(nfft1-nh2+1:nfft1-1) + else + i0=nint(112.5/df1) + c2(0:nh2)=c1(i0:i0+nh2) + c2(nh2+1:nfft2-1)=c1(i0-nh2+1:i0-1) + endif + + call four2a(c2,nfft2,1,-1,1) !Shorter complex FFT, back to time domain + +! Write complex time-domain data to disk. + i1=index(c2name,'.c2') + outfile=c2name(i1-11:i1+2) + open(18,file=c2name,status='unknown',access='stream', iostat=ioerr) + if (ioerr.eq.0) then + write(18) outfile,ntrminutes,f0m1500,c2(0:45000-1) + close(18) + endif + savec2 = ioerr +end function savec2 diff --git a/lib/sec0.f90 b/lib/sec0.f90 index 4f04f590..1ced602e 100755 --- a/lib/sec0.f90 +++ b/lib/sec0.f90 @@ -1,21 +1,21 @@ -subroutine sec0(n,t) - - ! Simple execution timer. - ! call sec0(0,t) - ! ... statements to be timed ... - ! call sec0(1,t) - ! print*,'Execution time:',t - - integer*8 count0,count1,clkfreq - save count0 - - call system_clock(count1,clkfreq) - if(n.eq.0) then - count0=count1 - return - else - t=float(count1-count0)/float(clkfreq) - endif - - return -end subroutine sec0 +subroutine sec0(n,t) + + ! Simple execution timer. + ! call sec0(0,t) + ! ... statements to be timed ... + ! call sec0(1,t) + ! print*,'Execution time:',t + + integer*8 count0,count1,clkfreq + save count0 + + call system_clock(count1,clkfreq) + if(n.eq.0) then + count0=count1 + return + else + t=float(count1-count0)/float(clkfreq) + endif + + return +end subroutine sec0 diff --git a/lib/sec_midn.f90 b/lib/sec_midn.f90 index db6328e8..0bbe62c2 100755 --- a/lib/sec_midn.f90 +++ b/lib/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/lib/sfrsd.f90 b/lib/sfrsd.f90 index 68fb161a..49dc7bca 100755 --- a/lib/sfrsd.f90 +++ b/lib/sfrsd.f90 @@ -1,121 +1,121 @@ -subroutine sfrsd(mrsym,mrprob,mr2sym,mr2prob,ntrials,correct,indexes, & - param,ntry) - - integer mrsym(0:62),mrprob(0:62),mr2sym(0:62),mr2prob(0:62) - integer correct(0:62),indexes(0:62),probs(0:62),thresh0(0:62) - integer rxdat(0:62),rxdat2(0:62),rxprob(0:62),rxprob2(0:62) - integer workdat(0:62),era_pos(0:50) - integer perr(0:7,0:7) - integer param(0:7) - real ratio0(0:62) - - call init_rs_int() - do i=0,62 - rxdat(i)=mrsym(62-i) - rxdat2(i)=mr2sym(62-i) - rxprob(i)=mrprob(62-i) - rxprob2(i)=mr2prob(62-i) - enddo - - do i=0,62 - indexes(i)=i - probs(i)=rxprob(i) - enddo - - do ip=1,62 - do k=0,63-ip - if(probs(k).lt.probs(k+1)) then - ntmp=probs(k) - probs(k)=probs(k+1) - probs(k+1)=ntmp - ntmp=indexes(k) - indexes(k)=indexes(k+1) - indexes(k+1)=ntmp - endif - enddo - enddo - - era_pos=0 - numera=0 - workdat=rxdat - call decode_rs_int() - if(nerr.ge.0) then - correct=workdat - param=0 - return - endif - - call random_seed() - - ncandidates=0 - nsum=0 - do i=0,62 - nsum=nsum+rxprob(i) - j=indexes(62-i) - ratio0(i)=float(rxprob2(j))/(float(rxprob(j))+0.01) - ii=int(7.999*ratio0(i)) - jj=(62-i)/8 - thresh0(i)=nint(1.3*perr(jj,ii)) - enddo - if(nsum.eq.0) return - - do k=0,ntrials - era_pos=0 - workdat=rxdat - numera=0 - do i=0,62 - j=indexes(62-i) - thresh=thresh0(i) - ir=rand() - if(...) then - era_pos(numera)=j - numera=numera+1 - endif - enddo - - call decode_rs_int() - if(nerr.ge.0) then - ncandidates=ncandidates+1 - nhard=0 - nsoft=0 - nsofter=0 - do i=0,62 - if(workdat(i).ne.rxdat(i)) then - nhard=nhard+1 - nsofter=nsofter+rxprob(i) - if(workdat(i).ne.rxdat2(i)) nsoft=nsoft+rxprob(i) - else - nsofter=nsofter-rxprob(i) - endif - enddo - nsoft=63*nsoft/nsum - nsofter=63*nsofter/nsum - ntotal=nsoft+nhard - if(ntotal.lt.ntotal_min) then - nsoft_min=nsoft - nhard_min=nhard - nsofter_min=nsofter - ntotal_min=ntotal - correct=workdat - nera_best=numera - ntry=k - endif - if(ntotal_min.lt.72 .and. nhard_min.lt.42) exit - endif - if(k.eq.ntrials-1) ntry=k+1 - enddo - - if(ntotal_min.ge.76 .or. nhard.ge.44) nhard_min=-1 - - param(0)=ncandidates - param(1)=nhard_min - param(2)=nsoft_min - param(3)=nera_best - param(4)=nsofter_min - if(param(0).eq.0) param(2)=-1 - - return -end subroutine sfrsd - - - +subroutine sfrsd(mrsym,mrprob,mr2sym,mr2prob,ntrials,correct,indexes, & + param,ntry) + + integer mrsym(0:62),mrprob(0:62),mr2sym(0:62),mr2prob(0:62) + integer correct(0:62),indexes(0:62),probs(0:62),thresh0(0:62) + integer rxdat(0:62),rxdat2(0:62),rxprob(0:62),rxprob2(0:62) + integer workdat(0:62),era_pos(0:50) + integer perr(0:7,0:7) + integer param(0:7) + real ratio0(0:62) + + call init_rs_int() + do i=0,62 + rxdat(i)=mrsym(62-i) + rxdat2(i)=mr2sym(62-i) + rxprob(i)=mrprob(62-i) + rxprob2(i)=mr2prob(62-i) + enddo + + do i=0,62 + indexes(i)=i + probs(i)=rxprob(i) + enddo + + do ip=1,62 + do k=0,63-ip + if(probs(k).lt.probs(k+1)) then + ntmp=probs(k) + probs(k)=probs(k+1) + probs(k+1)=ntmp + ntmp=indexes(k) + indexes(k)=indexes(k+1) + indexes(k+1)=ntmp + endif + enddo + enddo + + era_pos=0 + numera=0 + workdat=rxdat + call decode_rs_int() + if(nerr.ge.0) then + correct=workdat + param=0 + return + endif + + call random_seed() + + ncandidates=0 + nsum=0 + do i=0,62 + nsum=nsum+rxprob(i) + j=indexes(62-i) + ratio0(i)=float(rxprob2(j))/(float(rxprob(j))+0.01) + ii=int(7.999*ratio0(i)) + jj=(62-i)/8 + thresh0(i)=nint(1.3*perr(jj,ii)) + enddo + if(nsum.eq.0) return + + do k=0,ntrials + era_pos=0 + workdat=rxdat + numera=0 + do i=0,62 + j=indexes(62-i) + thresh=thresh0(i) + ir=rand() + if(...) then + era_pos(numera)=j + numera=numera+1 + endif + enddo + + call decode_rs_int() + if(nerr.ge.0) then + ncandidates=ncandidates+1 + nhard=0 + nsoft=0 + nsofter=0 + do i=0,62 + if(workdat(i).ne.rxdat(i)) then + nhard=nhard+1 + nsofter=nsofter+rxprob(i) + if(workdat(i).ne.rxdat2(i)) nsoft=nsoft+rxprob(i) + else + nsofter=nsofter-rxprob(i) + endif + enddo + nsoft=63*nsoft/nsum + nsofter=63*nsofter/nsum + ntotal=nsoft+nhard + if(ntotal.lt.ntotal_min) then + nsoft_min=nsoft + nhard_min=nhard + nsofter_min=nsofter + ntotal_min=ntotal + correct=workdat + nera_best=numera + ntry=k + endif + if(ntotal_min.lt.72 .and. nhard_min.lt.42) exit + endif + if(k.eq.ntrials-1) ntry=k+1 + enddo + + if(ntotal_min.ge.76 .or. nhard.ge.44) nhard_min=-1 + + param(0)=ncandidates + param(1)=nhard_min + param(2)=nsoft_min + param(3)=nera_best + param(4)=nsofter_min + if(param(0).eq.0) param(2)=-1 + + return +end subroutine sfrsd + + + diff --git a/lib/sgran.c b/lib/sgran.c index 834315da..b48222e9 100755 --- a/lib/sgran.c +++ b/lib/sgran.c @@ -1,7 +1,7 @@ -#include "init_random_seed.h" - -/* Fortran wrapper to seed the C library rand */ -void sgran_(void) -{ - init_random_seed(); -} +#include "init_random_seed.h" + +/* Fortran wrapper to seed the C library rand */ +void sgran_(void) +{ + init_random_seed(); +} diff --git a/lib/sh65.f90 b/lib/sh65.f90 index bcbdcfa5..09bef9c2 100755 --- a/lib/sh65.f90 +++ b/lib/sh65.f90 @@ -1,94 +1,94 @@ -subroutine sh65(cx,n5,mode65,ntol,xdf,nspecial,snrdb) - parameter(NFFT=2048,NH=NFFT/2) - complex cx(n5) !Centered on nfqso, sample rate 1378.125 - complex c(0:NFFT-1) - real s(-NH+1:NH) - real ss(-NH+1:NH,16) - real sigmax(16) - integer ipk(16) - - ss=0. - - jstep=NFFT/8 - nblks=272 - ia=-jstep+1 - do iblk=1,nblks - n=mod(iblk-1,16) + 1 - ia=ia+jstep - ib=ia+NFFT-1 - c=cx(ia:ib) - call four2a(c,nfft,1,1,1) !c2c FFT - do i=0,NFFT-1 - j=i - if(j.gt.NH) j=j-NFFT - ss(j,n)=ss(j,n) + real(c(i))**2 + aimag(c(i))**2 - enddo - enddo - - s=1.e-5*s - ss=1.e-5*ss - df=1378.1285/NFFT - nfac=40*mode65 - dtstep=0.25/df - - do i=1,2*mode65 - call smo121(ss,16*NFFT) - enddo - -! do i=-NH+1,NH -! write(72,3072) i*df,(ss(i,j),j=1,16) -!3072 format(17f7.1) -! enddo - -! Define freq range to be searched. Upper tone is at sync freq + 4*nfac*df Hz - fa=-ntol - fb=ntol - ia2=max(-NH+1,nint(fa/df)) - ib2=min(NH,nint(fb/df + 4.1*nfac)) - -! Find strongest line in each of the 16 phases - sbest=0. - snrbest=0. - nbest=1 - ipk=0 - do n=1,16 - sigmax(n)=0. - do i=ia2,ib2 - sig=ss(i,n) - if(sig.ge.sigmax(n)) then - ipk(n)=i - sigmax(n)=sig - if(sig.ge.sbest) then - sbest=sig - nbest=n - endif - endif - enddo - enddo - n2best=nbest+8 - if(n2best.gt.16) n2best=nbest-8 - xdf=min(ipk(nbest),ipk(n2best))*df - nspecial=0 - if(abs(xdf).le.ntol) then - idiff=abs(ipk(nbest)-ipk(n2best)) - xk=float(idiff)/nfac - k=nint(xk) - iderr=nint((xk-k)*nfac) -! maxerr=nint(0.008*abs(idiff) + 0.51) - maxerr=nint(0.02*abs(idiff) + 0.51) !### Better test ??? ### -! write(71,3001) nbest,n2best,idiff,iderr,maxerr,k, & -! ipk(nbest)*df,ipk(n2best)*df,sbest -!3001 format(6i4,2f7.1,f7.2) - if(abs(iderr).le.maxerr .and. k.ge.2 .and. k.le.4) nspecial=k - snrdb=-30.0 - if(nspecial.gt.0) then - call sh65snr(ss(ia2,nbest),ib2-ia2+1,snr1) - call sh65snr(ss(ia2,n2best),ib2-ia2+1,snr2) - snr=0.5*(snr1+snr2) - snrdb=db(snr) - db(2500.0/df) - db(sqrt(nblks/4.0)) + 8.0 - endif - if(snr1.lt.4.0 .or. snr2.lt.4.0 .or. snr.lt.5.0) nspecial=0 - endif - - return -end subroutine sh65 +subroutine sh65(cx,n5,mode65,ntol,xdf,nspecial,snrdb) + parameter(NFFT=2048,NH=NFFT/2) + complex cx(n5) !Centered on nfqso, sample rate 1378.125 + complex c(0:NFFT-1) + real s(-NH+1:NH) + real ss(-NH+1:NH,16) + real sigmax(16) + integer ipk(16) + + ss=0. + + jstep=NFFT/8 + nblks=272 + ia=-jstep+1 + do iblk=1,nblks + n=mod(iblk-1,16) + 1 + ia=ia+jstep + ib=ia+NFFT-1 + c=cx(ia:ib) + call four2a(c,nfft,1,1,1) !c2c FFT + do i=0,NFFT-1 + j=i + if(j.gt.NH) j=j-NFFT + ss(j,n)=ss(j,n) + real(c(i))**2 + aimag(c(i))**2 + enddo + enddo + + s=1.e-5*s + ss=1.e-5*ss + df=1378.1285/NFFT + nfac=40*mode65 + dtstep=0.25/df + + do i=1,2*mode65 + call smo121(ss,16*NFFT) + enddo + +! do i=-NH+1,NH +! write(72,3072) i*df,(ss(i,j),j=1,16) +!3072 format(17f7.1) +! enddo + +! Define freq range to be searched. Upper tone is at sync freq + 4*nfac*df Hz + fa=-ntol + fb=ntol + ia2=max(-NH+1,nint(fa/df)) + ib2=min(NH,nint(fb/df + 4.1*nfac)) + +! Find strongest line in each of the 16 phases + sbest=0. + snrbest=0. + nbest=1 + ipk=0 + do n=1,16 + sigmax(n)=0. + do i=ia2,ib2 + sig=ss(i,n) + if(sig.ge.sigmax(n)) then + ipk(n)=i + sigmax(n)=sig + if(sig.ge.sbest) then + sbest=sig + nbest=n + endif + endif + enddo + enddo + n2best=nbest+8 + if(n2best.gt.16) n2best=nbest-8 + xdf=min(ipk(nbest),ipk(n2best))*df + nspecial=0 + if(abs(xdf).le.ntol) then + idiff=abs(ipk(nbest)-ipk(n2best)) + xk=float(idiff)/nfac + k=nint(xk) + iderr=nint((xk-k)*nfac) +! maxerr=nint(0.008*abs(idiff) + 0.51) + maxerr=nint(0.02*abs(idiff) + 0.51) !### Better test ??? ### +! write(71,3001) nbest,n2best,idiff,iderr,maxerr,k, & +! ipk(nbest)*df,ipk(n2best)*df,sbest +!3001 format(6i4,2f7.1,f7.2) + if(abs(iderr).le.maxerr .and. k.ge.2 .and. k.le.4) nspecial=k + snrdb=-30.0 + if(nspecial.gt.0) then + call sh65snr(ss(ia2,nbest),ib2-ia2+1,snr1) + call sh65snr(ss(ia2,n2best),ib2-ia2+1,snr2) + snr=0.5*(snr1+snr2) + snrdb=db(snr) - db(2500.0/df) - db(sqrt(nblks/4.0)) + 8.0 + endif + if(snr1.lt.4.0 .or. snr2.lt.4.0 .or. snr.lt.5.0) nspecial=0 + endif + + return +end subroutine sh65 diff --git a/lib/sh65snr.f90 b/lib/sh65snr.f90 index bc4cab7d..3d449010 100755 --- a/lib/sh65snr.f90 +++ b/lib/sh65snr.f90 @@ -1,36 +1,36 @@ -subroutine sh65snr(x,nz,snr) - - real x(nz) - - ipk=0 !Shut up compiler warnings. -db - smax=-1.e30 - do i=1,nz - if(x(i).gt.smax) then - ipk=i - smax=x(i) - endif - s=s+x(i) - enddo - - s=0. - ns=0 - do i=1,nz - if(abs(i-ipk).ge.3) then - s=s+x(i) - ns=ns+1 - endif - enddo - ave=s/ns - - sq=0. - do i=1,nz - if(abs(i-ipk).ge.3) then - sq=sq+(x(i)-ave)**2 - ns=ns+1 - endif - enddo - rms=sqrt(sq/(nz-2)) - snr=(smax-ave)/rms - - return -end subroutine sh65snr +subroutine sh65snr(x,nz,snr) + + real x(nz) + + ipk=0 !Shut up compiler warnings. -db + smax=-1.e30 + do i=1,nz + if(x(i).gt.smax) then + ipk=i + smax=x(i) + endif + s=s+x(i) + enddo + + s=0. + ns=0 + do i=1,nz + if(abs(i-ipk).ge.3) then + s=s+x(i) + ns=ns+1 + endif + enddo + ave=s/ns + + sq=0. + do i=1,nz + if(abs(i-ipk).ge.3) then + sq=sq+(x(i)-ave)**2 + ns=ns+1 + endif + enddo + rms=sqrt(sq/(nz-2)) + snr=(smax-ave)/rms + + return +end subroutine sh65snr diff --git a/lib/shell.f90 b/lib/shell.f90 index 1e9b4488..d7365bfc 100755 --- a/lib/shell.f90 +++ b/lib/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/lib/shmem.cpp b/lib/shmem.cpp index 5c8461da..95a86614 100755 --- a/lib/shmem.cpp +++ b/lib/shmem.cpp @@ -1,20 +1,20 @@ -#include -#include - -// Multiple instances: KK1D, 17 Jul 2013 -QSharedMemory shmem; - -struct jt9com; - -// C wrappers for a QSharedMemory class instance -extern "C" -{ - bool shmem_create (int nsize) {return shmem.create(nsize);} - void shmem_setkey (char * const mykey) {shmem.setKey(QLatin1String{mykey});} - bool shmem_attach () {return shmem.attach();} - int shmem_size () {return static_cast (shmem.size());} - struct jt9com * shmem_address () {return reinterpret_cast(shmem.data());} - bool shmem_lock () {return shmem.lock();} - bool shmem_unlock () {return shmem.unlock();} - bool shmem_detach () {return shmem.detach();} -} +#include +#include + +// Multiple instances: KK1D, 17 Jul 2013 +QSharedMemory shmem; + +struct jt9com; + +// C wrappers for a QSharedMemory class instance +extern "C" +{ + bool shmem_create (int nsize) {return shmem.create(nsize);} + void shmem_setkey (char * const mykey) {shmem.setKey(QLatin1String{mykey});} + bool shmem_attach () {return shmem.attach();} + int shmem_size () {return static_cast (shmem.size());} + struct jt9com * shmem_address () {return reinterpret_cast(shmem.data());} + bool shmem_lock () {return shmem.lock();} + bool shmem_unlock () {return shmem.unlock();} + bool shmem_detach () {return shmem.detach();} +} diff --git a/lib/shmem.f90 b/lib/shmem.f90 index 1faacbf6..8d9db7d6 100755 --- a/lib/shmem.f90 +++ b/lib/shmem.f90 @@ -1,45 +1,45 @@ -module shmem - ! external routines wrapping the Qt QSharedMemory class - interface - function shmem_create (size) bind(C, name="shmem_create") - use iso_c_binding, only: c_bool, c_int - logical(c_bool) :: shmem_create - integer(c_int), value, intent(in) :: size - end function shmem_create - - subroutine shmem_setkey (key) bind(C, name="shmem_setkey") - use iso_c_binding, only: c_bool, c_char - character(kind=c_char), intent(in) :: key(*) - end subroutine shmem_setkey - - function shmem_attach () bind(C, name="shmem_attach") - use iso_c_binding, only: c_bool - logical(c_bool) :: shmem_attach - end function shmem_attach - - function shmem_address() bind(C, name="shmem_address") - use, intrinsic :: iso_c_binding, only: c_ptr - type(c_ptr) :: shmem_address - end function shmem_address - - function shmem_size() bind(C, name="shmem_size") - use, intrinsic :: iso_c_binding, only: c_int - integer(c_int) :: shmem_size - end function shmem_size - - function shmem_lock () bind(C, name="shmem_lock") - use iso_c_binding, only: c_bool - logical(c_bool) :: shmem_lock - end function shmem_lock - - function shmem_unlock () bind(C, name="shmem_unlock") - use iso_c_binding, only: c_bool - logical(c_bool) :: shmem_unlock - end function shmem_unlock - - function shmem_detach () bind(C, name="shmem_detach") - use iso_c_binding, only: c_bool - logical(c_bool) :: shmem_detach - end function shmem_detach - end interface -end module shmem +module shmem + ! external routines wrapping the Qt QSharedMemory class + interface + function shmem_create (size) bind(C, name="shmem_create") + use iso_c_binding, only: c_bool, c_int + logical(c_bool) :: shmem_create + integer(c_int), value, intent(in) :: size + end function shmem_create + + subroutine shmem_setkey (key) bind(C, name="shmem_setkey") + use iso_c_binding, only: c_bool, c_char + character(kind=c_char), intent(in) :: key(*) + end subroutine shmem_setkey + + function shmem_attach () bind(C, name="shmem_attach") + use iso_c_binding, only: c_bool + logical(c_bool) :: shmem_attach + end function shmem_attach + + function shmem_address() bind(C, name="shmem_address") + use, intrinsic :: iso_c_binding, only: c_ptr + type(c_ptr) :: shmem_address + end function shmem_address + + function shmem_size() bind(C, name="shmem_size") + use, intrinsic :: iso_c_binding, only: c_int + integer(c_int) :: shmem_size + end function shmem_size + + function shmem_lock () bind(C, name="shmem_lock") + use iso_c_binding, only: c_bool + logical(c_bool) :: shmem_lock + end function shmem_lock + + function shmem_unlock () bind(C, name="shmem_unlock") + use iso_c_binding, only: c_bool + logical(c_bool) :: shmem_unlock + end function shmem_unlock + + function shmem_detach () bind(C, name="shmem_detach") + use iso_c_binding, only: c_bool + logical(c_bool) :: shmem_detach + end function shmem_detach + end interface +end module shmem diff --git a/lib/slasubs.f b/lib/slasubs.f index d237aa0e..30ba6dd8 100755 --- a/lib/slasubs.f +++ b/lib/slasubs.f @@ -1,3400 +1,3400 @@ - SUBROUTINE sla_CLDJ (IY, IM, ID, DJM, J) -*+ -* - - - - - -* C L D J -* - - - - - -* -* Gregorian Calendar to Modified Julian Date -* -* Given: -* IY,IM,ID int year, month, day in Gregorian calendar -* -* Returned: -* DJM dp modified Julian Date (JD-2400000.5) for 0 hrs -* J int status: -* 0 = OK -* 1 = bad year (MJD not computed) -* 2 = bad month (MJD not computed) -* 3 = bad day (MJD computed) -* -* The year must be -4699 (i.e. 4700BC) or later. -* -* The algorithm is adapted from Hatcher 1984 (QJRAS 25, 53-55). -* -* Last revision: 27 July 2004 -* -* Copyright P.T.Wallace. All rights reserved. -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - INTEGER IY,IM,ID - DOUBLE PRECISION DJM - INTEGER J - -* Month lengths in days - INTEGER MTAB(12) - DATA MTAB / 31,28,31,30,31,30,31,31,30,31,30,31 / - - - -* Preset status. - J = 0 - -* Validate year. - IF ( IY .LT. -4699 ) THEN - J = 1 - ELSE - -* Validate month. - IF ( IM.GE.1 .AND. IM.LE.12 ) THEN - -* Allow for leap year. - IF ( MOD(IY,4) .EQ. 0 ) THEN - MTAB(2) = 29 - ELSE - MTAB(2) = 28 - END IF - IF ( MOD(IY,100).EQ.0 .AND. MOD(IY,400).NE.0 ) - : MTAB(2) = 28 - -* Validate day. - IF ( ID.LT.1 .OR. ID.GT.MTAB(IM) ) J=3 - -* Modified Julian Date. - DJM = DBLE ( ( 1461 * ( IY - (12-IM)/10 + 4712 ) ) / 4 - : + ( 306 * MOD ( IM+9, 12 ) + 5 ) / 10 - : - ( 3 * ( ( IY - (12-IM)/10 + 4900 ) / 100 ) ) / 4 - : + ID - 2399904 ) - -* Bad month. - ELSE - J=2 - END IF - - END IF - - END - DOUBLE PRECISION FUNCTION sla_DAT (UTC) -*+ -* - - - - -* D A T -* - - - - -* -* Increment to be applied to Coordinated Universal Time UTC to give -* International Atomic Time TAI (double precision) -* -* Given: -* UTC d UTC date as a modified JD (JD-2400000.5) -* -* Result: TAI-UTC in seconds -* -* Notes: -* -* 1 The UTC is specified to be a date rather than a time to indicate -* that care needs to be taken not to specify an instant which lies -* within a leap second. Though in most cases UTC can include the -* fractional part, correct behaviour on the day of a leap second -* can only be guaranteed up to the end of the second 23:59:59. -* -* 2 For epochs from 1961 January 1 onwards, the expressions from the -* file ftp://maia.usno.navy.mil/ser7/tai-utc.dat are used. -* -* 3 The 5ms time step at 1961 January 1 is taken from 2.58.1 (p87) of -* the 1992 Explanatory Supplement. -* -* 4 UTC began at 1960 January 1.0 (JD 2436934.5) and it is improper -* to call the routine with an earlier epoch. However, if this -* is attempted, the TAI-UTC expression for the year 1960 is used. -* -* -* :-----------------------------------------: -* : : -* : IMPORTANT : -* : : -* : This routine must be updated on each : -* : occasion that a leap second is : -* : announced : -* : : -* : Latest leap second: 2015 July 1 : -* : : -* :-----------------------------------------: -* -* Last revision: 5 July 2008 -* -* Copyright P.T.Wallace. All rights reserved. -*- - - IMPLICIT NONE - - DOUBLE PRECISION UTC - - DOUBLE PRECISION DT - - - - IF (.FALSE.) THEN - -* - - - - - - - - - - - - - - - - - - - - - - * -* Add new code here on each occasion that a * -* leap second is announced, and update the * -* preamble comments appropriately. * -* - - - - - - - - - - - - - - - - - - - - - - * - -* 2017 January 1 - ELSE IF (UTC.GE.57754D0) THEN - DT=37D0 - -* 2015 July 1 - ELSE IF (UTC.GE.57204D0) THEN - DT=36D0 - -* 2012 July 1 - ELSE IF (UTC.GE.56109D0) THEN - DT=35D0 - -* 2009 January 1 - ELSE IF (UTC.GE.54832D0) THEN - DT=34D0 - -* 2006 January 1 - ELSE IF (UTC.GE.53736D0) THEN - DT=33D0 - -* 1999 January 1 - ELSE IF (UTC.GE.51179D0) THEN - DT=32D0 - -* 1997 July 1 - ELSE IF (UTC.GE.50630D0) THEN - DT=31D0 - -* 1996 January 1 - ELSE IF (UTC.GE.50083D0) THEN - DT=30D0 - -* 1994 July 1 - ELSE IF (UTC.GE.49534D0) THEN - DT=29D0 - -* 1993 July 1 - ELSE IF (UTC.GE.49169D0) THEN - DT=28D0 - -* 1992 July 1 - ELSE IF (UTC.GE.48804D0) THEN - DT=27D0 - -* 1991 January 1 - ELSE IF (UTC.GE.48257D0) THEN - DT=26D0 - -* 1990 January 1 - ELSE IF (UTC.GE.47892D0) THEN - DT=25D0 - -* 1988 January 1 - ELSE IF (UTC.GE.47161D0) THEN - DT=24D0 - -* 1985 July 1 - ELSE IF (UTC.GE.46247D0) THEN - DT=23D0 - -* 1983 July 1 - ELSE IF (UTC.GE.45516D0) THEN - DT=22D0 - -* 1982 July 1 - ELSE IF (UTC.GE.45151D0) THEN - DT=21D0 - -* 1981 July 1 - ELSE IF (UTC.GE.44786D0) THEN - DT=20D0 - -* 1980 January 1 - ELSE IF (UTC.GE.44239D0) THEN - DT=19D0 - -* 1979 January 1 - ELSE IF (UTC.GE.43874D0) THEN - DT=18D0 - -* 1978 January 1 - ELSE IF (UTC.GE.43509D0) THEN - DT=17D0 - -* 1977 January 1 - ELSE IF (UTC.GE.43144D0) THEN - DT=16D0 - -* 1976 January 1 - ELSE IF (UTC.GE.42778D0) THEN - DT=15D0 - -* 1975 January 1 - ELSE IF (UTC.GE.42413D0) THEN - DT=14D0 - -* 1974 January 1 - ELSE IF (UTC.GE.42048D0) THEN - DT=13D0 - -* 1973 January 1 - ELSE IF (UTC.GE.41683D0) THEN - DT=12D0 - -* 1972 July 1 - ELSE IF (UTC.GE.41499D0) THEN - DT=11D0 - -* 1972 January 1 - ELSE IF (UTC.GE.41317D0) THEN - DT=10D0 - -* 1968 February 1 - ELSE IF (UTC.GE.39887D0) THEN - DT=4.2131700D0+(UTC-39126D0)*0.002592D0 - -* 1966 January 1 - ELSE IF (UTC.GE.39126D0) THEN - DT=4.3131700D0+(UTC-39126D0)*0.002592D0 - -* 1965 September 1 - ELSE IF (UTC.GE.39004D0) THEN - DT=3.8401300D0+(UTC-38761D0)*0.001296D0 - -* 1965 July 1 - ELSE IF (UTC.GE.38942D0) THEN - DT=3.7401300D0+(UTC-38761D0)*0.001296D0 - -* 1965 March 1 - ELSE IF (UTC.GE.38820D0) THEN - DT=3.6401300D0+(UTC-38761D0)*0.001296D0 - -* 1965 January 1 - ELSE IF (UTC.GE.38761D0) THEN - DT=3.5401300D0+(UTC-38761D0)*0.001296D0 - -* 1964 September 1 - ELSE IF (UTC.GE.38639D0) THEN - DT=3.4401300D0+(UTC-38761D0)*0.001296D0 - -* 1964 April 1 - ELSE IF (UTC.GE.38486D0) THEN - DT=3.3401300D0+(UTC-38761D0)*0.001296D0 - -* 1964 January 1 - ELSE IF (UTC.GE.38395D0) THEN - DT=3.2401300D0+(UTC-38761D0)*0.001296D0 - -* 1963 November 1 - ELSE IF (UTC.GE.38334D0) THEN - DT=1.9458580D0+(UTC-37665D0)*0.0011232D0 - -* 1962 January 1 - ELSE IF (UTC.GE.37665D0) THEN - DT=1.8458580D0+(UTC-37665D0)*0.0011232D0 - -* 1961 August 1 - ELSE IF (UTC.GE.37512D0) THEN - DT=1.3728180D0+(UTC-37300D0)*0.001296D0 - -* 1961 January 1 - ELSE IF (UTC.GE.37300D0) THEN - DT=1.4228180D0+(UTC-37300D0)*0.001296D0 - -* Before that - ELSE - DT=1.4178180D0+(UTC-37300D0)*0.001296D0 - - END IF - - sla_DAT=DT - - END - SUBROUTINE sla_DC62S (V, A, B, R, AD, BD, RD) -*+ -* - - - - - - -* D C 6 2 S -* - - - - - - -* -* Conversion of position & velocity in Cartesian coordinates -* to spherical coordinates (double precision) -* -* Given: -* V d(6) Cartesian position & velocity vector -* -* Returned: -* A d longitude (radians) -* B d latitude (radians) -* R d radial coordinate -* AD d longitude derivative (radians per unit time) -* BD d latitude derivative (radians per unit time) -* RD d radial derivative -* -* P.T.Wallace Starlink 28 April 1996 -* -* Copyright (C) 1996 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION V(6),A,B,R,AD,BD,RD - - DOUBLE PRECISION X,Y,Z,XD,YD,ZD,RXY2,RXY,R2,XYP - - - -* Components of position/velocity vector - X=V(1) - Y=V(2) - Z=V(3) - XD=V(4) - YD=V(5) - ZD=V(6) - -* Component of R in XY plane squared - RXY2=X*X+Y*Y - -* Modulus squared - R2=RXY2+Z*Z - -* Protection against null vector - IF (R2.EQ.0D0) THEN - X=XD - Y=YD - Z=ZD - RXY2=X*X+Y*Y - R2=RXY2+Z*Z - END IF - -* Position and velocity in spherical coordinates - RXY=SQRT(RXY2) - XYP=X*XD+Y*YD - IF (RXY2.NE.0D0) THEN - A=ATAN2(Y,X) - B=ATAN2(Z,RXY) - AD=(X*YD-Y*XD)/RXY2 - BD=(ZD*RXY2-Z*XYP)/(R2*RXY) - ELSE - A=0D0 - IF (Z.NE.0D0) THEN - B=ATAN2(Z,RXY) - ELSE - B=0D0 - END IF - AD=0D0 - BD=0D0 - END IF - R=SQRT(R2) - IF (R.NE.0D0) THEN - RD=(XYP+Z*ZD)/R - ELSE - RD=0D0 - END IF - - END - SUBROUTINE sla_DCC2S (V, A, B) -*+ -* - - - - - - -* D C C 2 S -* - - - - - - -* -* Cartesian to spherical coordinates (double precision) -* -* Given: -* V d(3) x,y,z vector -* -* Returned: -* A,B d spherical coordinates in radians -* -* The spherical coordinates are longitude (+ve anticlockwise looking -* from the +ve latitude pole) and latitude. The Cartesian coordinates -* are right handed, with the x axis at zero longitude and latitude, and -* the z axis at the +ve latitude pole. -* -* If V is null, zero A and B are returned. At either pole, zero A is -* returned. -* -* Last revision: 22 July 2004 -* -* Copyright P.T.Wallace. All rights reserved. -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION V(3),A,B - - DOUBLE PRECISION X,Y,Z,R - - - X = V(1) - Y = V(2) - Z = V(3) - R = SQRT(X*X+Y*Y) - - IF (R.EQ.0D0) THEN - A = 0D0 - ELSE - A = ATAN2(Y,X) - END IF - - IF (Z.EQ.0D0) THEN - B = 0D0 - ELSE - B = ATAN2(Z,R) - END IF - - END - SUBROUTINE sla_DCS2C (A, B, V) -*+ -* - - - - - - -* D C S 2 C -* - - - - - - -* -* Spherical coordinates to direction cosines (double precision) -* -* Given: -* A,B d spherical coordinates in radians -* (RA,Dec), (long,lat) etc. -* -* Returned: -* V d(3) x,y,z unit vector -* -* The spherical coordinates are longitude (+ve anticlockwise looking -* from the +ve latitude pole) and latitude. The Cartesian coordinates -* are right handed, with the x axis at zero longitude and latitude, and -* the z axis at the +ve latitude pole. -* -* Last revision: 26 December 2004 -* -* Copyright P.T.Wallace. All rights reserved. -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION A,B,V(3) - - DOUBLE PRECISION COSB - - - COSB = COS(B) - - V(1) = COS(A)*COSB - V(2) = SIN(A)*COSB - V(3) = SIN(B) - - END - SUBROUTINE sla_DE2H (HA, DEC, PHI, AZ, EL) -*+ -* - - - - - -* D E 2 H -* - - - - - -* -* Equatorial to horizon coordinates: HA,Dec to Az,El -* -* (double precision) -* -* Given: -* HA d hour angle -* DEC d declination -* PHI d observatory latitude -* -* Returned: -* AZ d azimuth -* EL d elevation -* -* Notes: -* -* 1) All the arguments are angles in radians. -* -* 2) Azimuth is returned in the range 0-2pi; north is zero, -* and east is +pi/2. Elevation is returned in the range -* +/-pi/2. -* -* 3) The latitude must be geodetic. In critical applications, -* corrections for polar motion should be applied. -* -* 4) In some applications it will be important to specify the -* correct type of hour angle and declination in order to -* produce the required type of azimuth and elevation. In -* particular, it may be important to distinguish between -* elevation as affected by refraction, which would -* require the "observed" HA,Dec, and the elevation -* in vacuo, which would require the "topocentric" HA,Dec. -* If the effects of diurnal aberration can be neglected, the -* "apparent" HA,Dec may be used instead of the topocentric -* HA,Dec. -* -* 5) No range checking of arguments is carried out. -* -* 6) In applications which involve many such calculations, rather -* than calling the present routine it will be more efficient to -* use inline code, having previously computed fixed terms such -* as sine and cosine of latitude, and (for tracking a star) -* sine and cosine of declination. -* -* P.T.Wallace Starlink 9 July 1994 -* -* Copyright (C) 1995 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION HA,DEC,PHI,AZ,EL - - DOUBLE PRECISION D2PI - PARAMETER (D2PI=6.283185307179586476925286766559D0) - - DOUBLE PRECISION SH,CH,SD,CD,SP,CP,X,Y,Z,R,A - - -* Useful trig functions - SH=SIN(HA) - CH=COS(HA) - SD=SIN(DEC) - CD=COS(DEC) - SP=SIN(PHI) - CP=COS(PHI) - -* Az,El as x,y,z - X=-CH*CD*SP+SD*CP - Y=-SH*CD - Z=CH*CD*CP+SD*SP - -* To spherical - R=SQRT(X*X+Y*Y) - IF (R.EQ.0D0) THEN - A=0D0 - ELSE - A=ATAN2(Y,X) - END IF - IF (A.LT.0D0) A=A+D2PI - AZ=A - EL=ATAN2(Z,R) - - END - SUBROUTINE sla_DEULER (ORDER, PHI, THETA, PSI, RMAT) -*+ -* - - - - - - - -* D E U L E R -* - - - - - - - -* -* Form a rotation matrix from the Euler angles - three successive -* rotations about specified Cartesian axes (double precision) -* -* Given: -* ORDER c*(*) specifies about which axes the rotations occur -* PHI d 1st rotation (radians) -* THETA d 2nd rotation ( " ) -* PSI d 3rd rotation ( " ) -* -* Returned: -* RMAT d(3,3) rotation matrix -* -* A rotation is positive when the reference frame rotates -* anticlockwise as seen looking towards the origin from the -* positive region of the specified axis. -* -* The characters of ORDER define which axes the three successive -* rotations are about. A typical value is 'ZXZ', indicating that -* RMAT is to become the direction cosine matrix corresponding to -* rotations of the reference frame through PHI radians about the -* old Z-axis, followed by THETA radians about the resulting X-axis, -* then PSI radians about the resulting Z-axis. -* -* The axis names can be any of the following, in any order or -* combination: X, Y, Z, uppercase or lowercase, 1, 2, 3. Normal -* axis labelling/numbering conventions apply; the xyz (=123) -* triad is right-handed. Thus, the 'ZXZ' example given above -* could be written 'zxz' or '313' (or even 'ZxZ' or '3xZ'). ORDER -* is terminated by length or by the first unrecognized character. -* -* Fewer than three rotations are acceptable, in which case the later -* angle arguments are ignored. If all rotations are zero, the -* identity matrix is produced. -* -* P.T.Wallace Starlink 23 May 1997 -* -* Copyright (C) 1997 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - CHARACTER*(*) ORDER - DOUBLE PRECISION PHI,THETA,PSI,RMAT(3,3) - - INTEGER J,I,L,N,K - DOUBLE PRECISION RESULT(3,3),ROTN(3,3),ANGLE,S,C,W,WM(3,3) - CHARACTER AXIS - - - -* Initialize result matrix - DO J=1,3 - DO I=1,3 - IF (I.NE.J) THEN - RESULT(I,J) = 0D0 - ELSE - RESULT(I,J) = 1D0 - END IF - END DO - END DO - -* Establish length of axis string - L = LEN(ORDER) - -* Look at each character of axis string until finished - DO N=1,3 - IF (N.LE.L) THEN - -* Initialize rotation matrix for the current rotation - DO J=1,3 - DO I=1,3 - IF (I.NE.J) THEN - ROTN(I,J) = 0D0 - ELSE - ROTN(I,J) = 1D0 - END IF - END DO - END DO - -* Pick up the appropriate Euler angle and take sine & cosine - IF (N.EQ.1) THEN - ANGLE = PHI - ELSE IF (N.EQ.2) THEN - ANGLE = THETA - ELSE - ANGLE = PSI - END IF - S = SIN(ANGLE) - C = COS(ANGLE) - -* Identify the axis - AXIS = ORDER(N:N) - IF (AXIS.EQ.'X'.OR. - : AXIS.EQ.'x'.OR. - : AXIS.EQ.'1') THEN - -* Matrix for x-rotation - ROTN(2,2) = C - ROTN(2,3) = S - ROTN(3,2) = -S - ROTN(3,3) = C - - ELSE IF (AXIS.EQ.'Y'.OR. - : AXIS.EQ.'y'.OR. - : AXIS.EQ.'2') THEN - -* Matrix for y-rotation - ROTN(1,1) = C - ROTN(1,3) = -S - ROTN(3,1) = S - ROTN(3,3) = C - - ELSE IF (AXIS.EQ.'Z'.OR. - : AXIS.EQ.'z'.OR. - : AXIS.EQ.'3') THEN - -* Matrix for z-rotation - ROTN(1,1) = C - ROTN(1,2) = S - ROTN(2,1) = -S - ROTN(2,2) = C - - ELSE - -* Unrecognized character - fake end of string - L = 0 - - END IF - -* Apply the current rotation (matrix ROTN x matrix RESULT) - DO I=1,3 - DO J=1,3 - W = 0D0 - DO K=1,3 - W = W+ROTN(I,K)*RESULT(K,J) - END DO - WM(I,J) = W - END DO - END DO - DO J=1,3 - DO I=1,3 - RESULT(I,J) = WM(I,J) - END DO - END DO - - END IF - - END DO - -* Copy the result - DO J=1,3 - DO I=1,3 - RMAT(I,J) = RESULT(I,J) - END DO - END DO - - END - SUBROUTINE sla_DMOON (DATE, PV) -*+ -* - - - - - - -* D M O O N -* - - - - - - -* -* Approximate geocentric position and velocity of the Moon -* (double precision) -* -* Given: -* DATE D TDB (loosely ET) as a Modified Julian Date -* (JD-2400000.5) -* -* Returned: -* PV D(6) Moon x,y,z,xdot,ydot,zdot, mean equator and -* equinox of date (AU, AU/s) -* -* Notes: -* -* 1 This routine is a full implementation of the algorithm -* published by Meeus (see reference). -* -* 2 Meeus quotes accuracies of 10 arcsec in longitude, 3 arcsec in -* latitude and 0.2 arcsec in HP (equivalent to about 20 km in -* distance). Comparison with JPL DE200 over the interval -* 1960-2025 gives RMS errors of 3.7 arcsec and 83 mas/hour in -* longitude, 2.3 arcsec and 48 mas/hour in latitude, 11 km -* and 81 mm/s in distance. The maximum errors over the same -* interval are 18 arcsec and 0.50 arcsec/hour in longitude, -* 11 arcsec and 0.24 arcsec/hour in latitude, 40 km and 0.29 m/s -* in distance. -* -* 3 The original algorithm is expressed in terms of the obsolete -* timescale Ephemeris Time. Either TDB or TT can be used, but -* not UT without incurring significant errors (30 arcsec at -* the present time) due to the Moon's 0.5 arcsec/sec movement. -* -* 4 The algorithm is based on pre IAU 1976 standards. However, -* the result has been moved onto the new (FK5) equinox, an -* adjustment which is in any case much smaller than the -* intrinsic accuracy of the procedure. -* -* 5 Velocity is obtained by a complete analytical differentiation -* of the Meeus model. -* -* Reference: -* Meeus, l'Astronomie, June 1984, p348. -* -* P.T.Wallace Starlink 22 January 1998 -* -* Copyright (C) 1998 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION DATE,PV(6) - -* Degrees, arcseconds and seconds of time to radians - DOUBLE PRECISION D2R,DAS2R,DS2R - PARAMETER (D2R=0.0174532925199432957692369D0, - : DAS2R=4.848136811095359935899141D-6, - : DS2R=7.272205216643039903848712D-5) - -* Seconds per Julian century (86400*36525) - DOUBLE PRECISION CJ - PARAMETER (CJ=3155760000D0) - -* Julian epoch of B1950 - DOUBLE PRECISION B1950 - PARAMETER (B1950=1949.9997904423D0) - -* Earth equatorial radius in AU ( = 6378.137 / 149597870 ) - DOUBLE PRECISION ERADAU - PARAMETER (ERADAU=4.2635212653763D-5) - - DOUBLE PRECISION T,THETA,SINOM,COSOM,DOMCOM,WA,DWA,WB,DWB,WOM, - : DWOM,SINWOM,COSWOM,V,DV,COEFF,EMN,EMPN,DN,FN,EN, - : DEN,DTHETA,FTHETA,EL,DEL,B,DB,BF,DBF,P,DP,SP,R, - : DR,X,Y,Z,XD,YD,ZD,SEL,CEL,SB,CB,RCB,RBD,W,EPJ, - : EQCOR,EPS,SINEPS,COSEPS,ES,EC - INTEGER N,I - -* -* Coefficients for fundamental arguments -* -* at J1900: T**0, T**1, T**2, T**3 -* at epoch: T**0, T**1 -* -* Units are degrees for position and Julian centuries for time -* - -* Moon's mean longitude - DOUBLE PRECISION ELP0,ELP1,ELP2,ELP3,ELP,DELP - PARAMETER (ELP0=270.434164D0, - : ELP1=481267.8831D0, - : ELP2=-0.001133D0, - : ELP3=0.0000019D0) - -* Sun's mean anomaly - DOUBLE PRECISION EM0,EM1,EM2,EM3,EM,DEM - PARAMETER (EM0=358.475833D0, - : EM1=35999.0498D0, - : EM2=-0.000150D0, - : EM3=-0.0000033D0) - -* Moon's mean anomaly - DOUBLE PRECISION EMP0,EMP1,EMP2,EMP3,EMP,DEMP - PARAMETER (EMP0=296.104608D0, - : EMP1=477198.8491D0, - : EMP2=0.009192D0, - : EMP3=0.0000144D0) - -* Moon's mean elongation - DOUBLE PRECISION D0,D1,D2,D3,D,DD - PARAMETER (D0=350.737486D0, - : D1=445267.1142D0, - : D2=-0.001436D0, - : D3=0.0000019D0) - -* Mean distance of the Moon from its ascending node - DOUBLE PRECISION F0,F1,F2,F3,F,DF - PARAMETER (F0=11.250889D0, - : F1=483202.0251D0, - : F2=-0.003211D0, - : F3=-0.0000003D0) - -* Longitude of the Moon's ascending node - DOUBLE PRECISION OM0,OM1,OM2,OM3,OM,DOM - PARAMETER (OM0=259.183275D0, - : OM1=-1934.1420D0, - : OM2=0.002078D0, - : OM3=0.0000022D0) - -* Coefficients for (dimensionless) E factor - DOUBLE PRECISION E1,E2,E,DE,ESQ,DESQ - PARAMETER (E1=-0.002495D0,E2=-0.00000752D0) - -* Coefficients for periodic variations etc - DOUBLE PRECISION PAC,PA0,PA1 - PARAMETER (PAC=0.000233D0,PA0=51.2D0,PA1=20.2D0) - DOUBLE PRECISION PBC - PARAMETER (PBC=-0.001778D0) - DOUBLE PRECISION PCC - PARAMETER (PCC=0.000817D0) - DOUBLE PRECISION PDC - PARAMETER (PDC=0.002011D0) - DOUBLE PRECISION PEC,PE0,PE1,PE2 - PARAMETER (PEC=0.003964D0, - : PE0=346.560D0,PE1=132.870D0,PE2=-0.0091731D0) - DOUBLE PRECISION PFC - PARAMETER (PFC=0.001964D0) - DOUBLE PRECISION PGC - PARAMETER (PGC=0.002541D0) - DOUBLE PRECISION PHC - PARAMETER (PHC=0.001964D0) - DOUBLE PRECISION PIC - PARAMETER (PIC=-0.024691D0) - DOUBLE PRECISION PJC,PJ0,PJ1 - PARAMETER (PJC=-0.004328D0,PJ0=275.05D0,PJ1=-2.30D0) - DOUBLE PRECISION CW1 - PARAMETER (CW1=0.0004664D0) - DOUBLE PRECISION CW2 - PARAMETER (CW2=0.0000754D0) - -* -* Coefficients for Moon position -* -* Tx(N) = coefficient of L, B or P term (deg) -* ITx(N,1-5) = coefficients of M, M', D, F, E**n in argument -* - INTEGER NL,NB,NP - PARAMETER (NL=50,NB=45,NP=31) - DOUBLE PRECISION TL(NL),TB(NB),TP(NP) - INTEGER ITL(5,NL),ITB(5,NB),ITP(5,NP) -* -* Longitude -* M M' D F n - DATA TL( 1)/ +6.288750D0 /, - : (ITL(I, 1),I=1,5)/ +0, +1, +0, +0, 0 / - DATA TL( 2)/ +1.274018D0 /, - : (ITL(I, 2),I=1,5)/ +0, -1, +2, +0, 0 / - DATA TL( 3)/ +0.658309D0 /, - : (ITL(I, 3),I=1,5)/ +0, +0, +2, +0, 0 / - DATA TL( 4)/ +0.213616D0 /, - : (ITL(I, 4),I=1,5)/ +0, +2, +0, +0, 0 / - DATA TL( 5)/ -0.185596D0 /, - : (ITL(I, 5),I=1,5)/ +1, +0, +0, +0, 1 / - DATA TL( 6)/ -0.114336D0 /, - : (ITL(I, 6),I=1,5)/ +0, +0, +0, +2, 0 / - DATA TL( 7)/ +0.058793D0 /, - : (ITL(I, 7),I=1,5)/ +0, -2, +2, +0, 0 / - DATA TL( 8)/ +0.057212D0 /, - : (ITL(I, 8),I=1,5)/ -1, -1, +2, +0, 1 / - DATA TL( 9)/ +0.053320D0 /, - : (ITL(I, 9),I=1,5)/ +0, +1, +2, +0, 0 / - DATA TL(10)/ +0.045874D0 /, - : (ITL(I,10),I=1,5)/ -1, +0, +2, +0, 1 / - DATA TL(11)/ +0.041024D0 /, - : (ITL(I,11),I=1,5)/ -1, +1, +0, +0, 1 / - DATA TL(12)/ -0.034718D0 /, - : (ITL(I,12),I=1,5)/ +0, +0, +1, +0, 0 / - DATA TL(13)/ -0.030465D0 /, - : (ITL(I,13),I=1,5)/ +1, +1, +0, +0, 1 / - DATA TL(14)/ +0.015326D0 /, - : (ITL(I,14),I=1,5)/ +0, +0, +2, -2, 0 / - DATA TL(15)/ -0.012528D0 /, - : (ITL(I,15),I=1,5)/ +0, +1, +0, +2, 0 / - DATA TL(16)/ -0.010980D0 /, - : (ITL(I,16),I=1,5)/ +0, -1, +0, +2, 0 / - DATA TL(17)/ +0.010674D0 /, - : (ITL(I,17),I=1,5)/ +0, -1, +4, +0, 0 / - DATA TL(18)/ +0.010034D0 /, - : (ITL(I,18),I=1,5)/ +0, +3, +0, +0, 0 / - DATA TL(19)/ +0.008548D0 /, - : (ITL(I,19),I=1,5)/ +0, -2, +4, +0, 0 / - DATA TL(20)/ -0.007910D0 /, - : (ITL(I,20),I=1,5)/ +1, -1, +2, +0, 1 / - DATA TL(21)/ -0.006783D0 /, - : (ITL(I,21),I=1,5)/ +1, +0, +2, +0, 1 / - DATA TL(22)/ +0.005162D0 /, - : (ITL(I,22),I=1,5)/ +0, +1, -1, +0, 0 / - DATA TL(23)/ +0.005000D0 /, - : (ITL(I,23),I=1,5)/ +1, +0, +1, +0, 1 / - DATA TL(24)/ +0.004049D0 /, - : (ITL(I,24),I=1,5)/ -1, +1, +2, +0, 1 / - DATA TL(25)/ +0.003996D0 /, - : (ITL(I,25),I=1,5)/ +0, +2, +2, +0, 0 / - DATA TL(26)/ +0.003862D0 /, - : (ITL(I,26),I=1,5)/ +0, +0, +4, +0, 0 / - DATA TL(27)/ +0.003665D0 /, - : (ITL(I,27),I=1,5)/ +0, -3, +2, +0, 0 / - DATA TL(28)/ +0.002695D0 /, - : (ITL(I,28),I=1,5)/ -1, +2, +0, +0, 1 / - DATA TL(29)/ +0.002602D0 /, - : (ITL(I,29),I=1,5)/ +0, +1, -2, -2, 0 / - DATA TL(30)/ +0.002396D0 /, - : (ITL(I,30),I=1,5)/ -1, -2, +2, +0, 1 / - DATA TL(31)/ -0.002349D0 /, - : (ITL(I,31),I=1,5)/ +0, +1, +1, +0, 0 / - DATA TL(32)/ +0.002249D0 /, - : (ITL(I,32),I=1,5)/ -2, +0, +2, +0, 2 / - DATA TL(33)/ -0.002125D0 /, - : (ITL(I,33),I=1,5)/ +1, +2, +0, +0, 1 / - DATA TL(34)/ -0.002079D0 /, - : (ITL(I,34),I=1,5)/ +2, +0, +0, +0, 2 / - DATA TL(35)/ +0.002059D0 /, - : (ITL(I,35),I=1,5)/ -2, -1, +2, +0, 2 / - DATA TL(36)/ -0.001773D0 /, - : (ITL(I,36),I=1,5)/ +0, +1, +2, -2, 0 / - DATA TL(37)/ -0.001595D0 /, - : (ITL(I,37),I=1,5)/ +0, +0, +2, +2, 0 / - DATA TL(38)/ +0.001220D0 /, - : (ITL(I,38),I=1,5)/ -1, -1, +4, +0, 1 / - DATA TL(39)/ -0.001110D0 /, - : (ITL(I,39),I=1,5)/ +0, +2, +0, +2, 0 / - DATA TL(40)/ +0.000892D0 /, - : (ITL(I,40),I=1,5)/ +0, +1, -3, +0, 0 / - DATA TL(41)/ -0.000811D0 /, - : (ITL(I,41),I=1,5)/ +1, +1, +2, +0, 1 / - DATA TL(42)/ +0.000761D0 /, - : (ITL(I,42),I=1,5)/ -1, -2, +4, +0, 1 / - DATA TL(43)/ +0.000717D0 /, - : (ITL(I,43),I=1,5)/ -2, +1, +0, +0, 2 / - DATA TL(44)/ +0.000704D0 /, - : (ITL(I,44),I=1,5)/ -2, +1, -2, +0, 2 / - DATA TL(45)/ +0.000693D0 /, - : (ITL(I,45),I=1,5)/ +1, -2, +2, +0, 1 / - DATA TL(46)/ +0.000598D0 /, - : (ITL(I,46),I=1,5)/ -1, +0, +2, -2, 1 / - DATA TL(47)/ +0.000550D0 /, - : (ITL(I,47),I=1,5)/ +0, +1, +4, +0, 0 / - DATA TL(48)/ +0.000538D0 /, - : (ITL(I,48),I=1,5)/ +0, +4, +0, +0, 0 / - DATA TL(49)/ +0.000521D0 /, - : (ITL(I,49),I=1,5)/ -1, +0, +4, +0, 1 / - DATA TL(50)/ +0.000486D0 /, - : (ITL(I,50),I=1,5)/ +0, +2, -1, +0, 0 / -* -* Latitude -* M M' D F n - DATA TB( 1)/ +5.128189D0 /, - : (ITB(I, 1),I=1,5)/ +0, +0, +0, +1, 0 / - DATA TB( 2)/ +0.280606D0 /, - : (ITB(I, 2),I=1,5)/ +0, +1, +0, +1, 0 / - DATA TB( 3)/ +0.277693D0 /, - : (ITB(I, 3),I=1,5)/ +0, +1, +0, -1, 0 / - DATA TB( 4)/ +0.173238D0 /, - : (ITB(I, 4),I=1,5)/ +0, +0, +2, -1, 0 / - DATA TB( 5)/ +0.055413D0 /, - : (ITB(I, 5),I=1,5)/ +0, -1, +2, +1, 0 / - DATA TB( 6)/ +0.046272D0 /, - : (ITB(I, 6),I=1,5)/ +0, -1, +2, -1, 0 / - DATA TB( 7)/ +0.032573D0 /, - : (ITB(I, 7),I=1,5)/ +0, +0, +2, +1, 0 / - DATA TB( 8)/ +0.017198D0 /, - : (ITB(I, 8),I=1,5)/ +0, +2, +0, +1, 0 / - DATA TB( 9)/ +0.009267D0 /, - : (ITB(I, 9),I=1,5)/ +0, +1, +2, -1, 0 / - DATA TB(10)/ +0.008823D0 /, - : (ITB(I,10),I=1,5)/ +0, +2, +0, -1, 0 / - DATA TB(11)/ +0.008247D0 /, - : (ITB(I,11),I=1,5)/ -1, +0, +2, -1, 1 / - DATA TB(12)/ +0.004323D0 /, - : (ITB(I,12),I=1,5)/ +0, -2, +2, -1, 0 / - DATA TB(13)/ +0.004200D0 /, - : (ITB(I,13),I=1,5)/ +0, +1, +2, +1, 0 / - DATA TB(14)/ +0.003372D0 /, - : (ITB(I,14),I=1,5)/ -1, +0, -2, +1, 1 / - DATA TB(15)/ +0.002472D0 /, - : (ITB(I,15),I=1,5)/ -1, -1, +2, +1, 1 / - DATA TB(16)/ +0.002222D0 /, - : (ITB(I,16),I=1,5)/ -1, +0, +2, +1, 1 / - DATA TB(17)/ +0.002072D0 /, - : (ITB(I,17),I=1,5)/ -1, -1, +2, -1, 1 / - DATA TB(18)/ +0.001877D0 /, - : (ITB(I,18),I=1,5)/ -1, +1, +0, +1, 1 / - DATA TB(19)/ +0.001828D0 /, - : (ITB(I,19),I=1,5)/ +0, -1, +4, -1, 0 / - DATA TB(20)/ -0.001803D0 /, - : (ITB(I,20),I=1,5)/ +1, +0, +0, +1, 1 / - DATA TB(21)/ -0.001750D0 /, - : (ITB(I,21),I=1,5)/ +0, +0, +0, +3, 0 / - DATA TB(22)/ +0.001570D0 /, - : (ITB(I,22),I=1,5)/ -1, +1, +0, -1, 1 / - DATA TB(23)/ -0.001487D0 /, - : (ITB(I,23),I=1,5)/ +0, +0, +1, +1, 0 / - DATA TB(24)/ -0.001481D0 /, - : (ITB(I,24),I=1,5)/ +1, +1, +0, +1, 1 / - DATA TB(25)/ +0.001417D0 /, - : (ITB(I,25),I=1,5)/ -1, -1, +0, +1, 1 / - DATA TB(26)/ +0.001350D0 /, - : (ITB(I,26),I=1,5)/ -1, +0, +0, +1, 1 / - DATA TB(27)/ +0.001330D0 /, - : (ITB(I,27),I=1,5)/ +0, +0, -1, +1, 0 / - DATA TB(28)/ +0.001106D0 /, - : (ITB(I,28),I=1,5)/ +0, +3, +0, +1, 0 / - DATA TB(29)/ +0.001020D0 /, - : (ITB(I,29),I=1,5)/ +0, +0, +4, -1, 0 / - DATA TB(30)/ +0.000833D0 /, - : (ITB(I,30),I=1,5)/ +0, -1, +4, +1, 0 / - DATA TB(31)/ +0.000781D0 /, - : (ITB(I,31),I=1,5)/ +0, +1, +0, -3, 0 / - DATA TB(32)/ +0.000670D0 /, - : (ITB(I,32),I=1,5)/ +0, -2, +4, +1, 0 / - DATA TB(33)/ +0.000606D0 /, - : (ITB(I,33),I=1,5)/ +0, +0, +2, -3, 0 / - DATA TB(34)/ +0.000597D0 /, - : (ITB(I,34),I=1,5)/ +0, +2, +2, -1, 0 / - DATA TB(35)/ +0.000492D0 /, - : (ITB(I,35),I=1,5)/ -1, +1, +2, -1, 1 / - DATA TB(36)/ +0.000450D0 /, - : (ITB(I,36),I=1,5)/ +0, +2, -2, -1, 0 / - DATA TB(37)/ +0.000439D0 /, - : (ITB(I,37),I=1,5)/ +0, +3, +0, -1, 0 / - DATA TB(38)/ +0.000423D0 /, - : (ITB(I,38),I=1,5)/ +0, +2, +2, +1, 0 / - DATA TB(39)/ +0.000422D0 /, - : (ITB(I,39),I=1,5)/ +0, -3, +2, -1, 0 / - DATA TB(40)/ -0.000367D0 /, - : (ITB(I,40),I=1,5)/ +1, -1, +2, +1, 1 / - DATA TB(41)/ -0.000353D0 /, - : (ITB(I,41),I=1,5)/ +1, +0, +2, +1, 1 / - DATA TB(42)/ +0.000331D0 /, - : (ITB(I,42),I=1,5)/ +0, +0, +4, +1, 0 / - DATA TB(43)/ +0.000317D0 /, - : (ITB(I,43),I=1,5)/ -1, +1, +2, +1, 1 / - DATA TB(44)/ +0.000306D0 /, - : (ITB(I,44),I=1,5)/ -2, +0, +2, -1, 2 / - DATA TB(45)/ -0.000283D0 /, - : (ITB(I,45),I=1,5)/ +0, +1, +0, +3, 0 / -* -* Parallax -* M M' D F n - DATA TP( 1)/ +0.950724D0 /, - : (ITP(I, 1),I=1,5)/ +0, +0, +0, +0, 0 / - DATA TP( 2)/ +0.051818D0 /, - : (ITP(I, 2),I=1,5)/ +0, +1, +0, +0, 0 / - DATA TP( 3)/ +0.009531D0 /, - : (ITP(I, 3),I=1,5)/ +0, -1, +2, +0, 0 / - DATA TP( 4)/ +0.007843D0 /, - : (ITP(I, 4),I=1,5)/ +0, +0, +2, +0, 0 / - DATA TP( 5)/ +0.002824D0 /, - : (ITP(I, 5),I=1,5)/ +0, +2, +0, +0, 0 / - DATA TP( 6)/ +0.000857D0 /, - : (ITP(I, 6),I=1,5)/ +0, +1, +2, +0, 0 / - DATA TP( 7)/ +0.000533D0 /, - : (ITP(I, 7),I=1,5)/ -1, +0, +2, +0, 1 / - DATA TP( 8)/ +0.000401D0 /, - : (ITP(I, 8),I=1,5)/ -1, -1, +2, +0, 1 / - DATA TP( 9)/ +0.000320D0 /, - : (ITP(I, 9),I=1,5)/ -1, +1, +0, +0, 1 / - DATA TP(10)/ -0.000271D0 /, - : (ITP(I,10),I=1,5)/ +0, +0, +1, +0, 0 / - DATA TP(11)/ -0.000264D0 /, - : (ITP(I,11),I=1,5)/ +1, +1, +0, +0, 1 / - DATA TP(12)/ -0.000198D0 /, - : (ITP(I,12),I=1,5)/ +0, -1, +0, +2, 0 / - DATA TP(13)/ +0.000173D0 /, - : (ITP(I,13),I=1,5)/ +0, +3, +0, +0, 0 / - DATA TP(14)/ +0.000167D0 /, - : (ITP(I,14),I=1,5)/ +0, -1, +4, +0, 0 / - DATA TP(15)/ -0.000111D0 /, - : (ITP(I,15),I=1,5)/ +1, +0, +0, +0, 1 / - DATA TP(16)/ +0.000103D0 /, - : (ITP(I,16),I=1,5)/ +0, -2, +4, +0, 0 / - DATA TP(17)/ -0.000084D0 /, - : (ITP(I,17),I=1,5)/ +0, +2, -2, +0, 0 / - DATA TP(18)/ -0.000083D0 /, - : (ITP(I,18),I=1,5)/ +1, +0, +2, +0, 1 / - DATA TP(19)/ +0.000079D0 /, - : (ITP(I,19),I=1,5)/ +0, +2, +2, +0, 0 / - DATA TP(20)/ +0.000072D0 /, - : (ITP(I,20),I=1,5)/ +0, +0, +4, +0, 0 / - DATA TP(21)/ +0.000064D0 /, - : (ITP(I,21),I=1,5)/ -1, +1, +2, +0, 1 / - DATA TP(22)/ -0.000063D0 /, - : (ITP(I,22),I=1,5)/ +1, -1, +2, +0, 1 / - DATA TP(23)/ +0.000041D0 /, - : (ITP(I,23),I=1,5)/ +1, +0, +1, +0, 1 / - DATA TP(24)/ +0.000035D0 /, - : (ITP(I,24),I=1,5)/ -1, +2, +0, +0, 1 / - DATA TP(25)/ -0.000033D0 /, - : (ITP(I,25),I=1,5)/ +0, +3, -2, +0, 0 / - DATA TP(26)/ -0.000030D0 /, - : (ITP(I,26),I=1,5)/ +0, +1, +1, +0, 0 / - DATA TP(27)/ -0.000029D0 /, - : (ITP(I,27),I=1,5)/ +0, +0, -2, +2, 0 / - DATA TP(28)/ -0.000029D0 /, - : (ITP(I,28),I=1,5)/ +1, +2, +0, +0, 1 / - DATA TP(29)/ +0.000026D0 /, - : (ITP(I,29),I=1,5)/ -2, +0, +2, +0, 2 / - DATA TP(30)/ -0.000023D0 /, - : (ITP(I,30),I=1,5)/ +0, +1, -2, +2, 0 / - DATA TP(31)/ +0.000019D0 /, - : (ITP(I,31),I=1,5)/ -1, -1, +4, +0, 1 / - - - -* Centuries since J1900 - T=(DATE-15019.5D0)/36525D0 - -* -* Fundamental arguments (radians) and derivatives (radians per -* Julian century) for the current epoch -* - -* Moon's mean longitude - ELP=D2R*MOD(ELP0+(ELP1+(ELP2+ELP3*T)*T)*T,360D0) - DELP=D2R*(ELP1+(2D0*ELP2+3D0*ELP3*T)*T) - -* Sun's mean anomaly - EM=D2R*MOD(EM0+(EM1+(EM2+EM3*T)*T)*T,360D0) - DEM=D2R*(EM1+(2D0*EM2+3D0*EM3*T)*T) - -* Moon's mean anomaly - EMP=D2R*MOD(EMP0+(EMP1+(EMP2+EMP3*T)*T)*T,360D0) - DEMP=D2R*(EMP1+(2D0*EMP2+3D0*EMP3*T)*T) - -* Moon's mean elongation - D=D2R*MOD(D0+(D1+(D2+D3*T)*T)*T,360D0) - DD=D2R*(D1+(2D0*D2+3D0*D3*T)*T) - -* Mean distance of the Moon from its ascending node - F=D2R*MOD(F0+(F1+(F2+F3*T)*T)*T,360D0) - DF=D2R*(F1+(2D0*F2+3D0*F3*T)*T) - -* Longitude of the Moon's ascending node - OM=D2R*MOD(OM0+(OM1+(OM2+OM3*T)*T)*T,360D0) - DOM=D2R*(OM1+(2D0*OM2+3D0*OM3*T)*T) - SINOM=SIN(OM) - COSOM=COS(OM) - DOMCOM=DOM*COSOM - -* Add the periodic variations - THETA=D2R*(PA0+PA1*T) - WA=SIN(THETA) - DWA=D2R*PA1*COS(THETA) - THETA=D2R*(PE0+(PE1+PE2*T)*T) - WB=PEC*SIN(THETA) - DWB=D2R*PEC*(PE1+2D0*PE2*T)*COS(THETA) - ELP=ELP+D2R*(PAC*WA+WB+PFC*SINOM) - DELP=DELP+D2R*(PAC*DWA+DWB+PFC*DOMCOM) - EM=EM+D2R*PBC*WA - DEM=DEM+D2R*PBC*DWA - EMP=EMP+D2R*(PCC*WA+WB+PGC*SINOM) - DEMP=DEMP+D2R*(PCC*DWA+DWB+PGC*DOMCOM) - D=D+D2R*(PDC*WA+WB+PHC*SINOM) - DD=DD+D2R*(PDC*DWA+DWB+PHC*DOMCOM) - WOM=OM+D2R*(PJ0+PJ1*T) - DWOM=DOM+D2R*PJ1 - SINWOM=SIN(WOM) - COSWOM=COS(WOM) - F=F+D2R*(WB+PIC*SINOM+PJC*SINWOM) - DF=DF+D2R*(DWB+PIC*DOMCOM+PJC*DWOM*COSWOM) - -* E-factor, and square - E=1D0+(E1+E2*T)*T - DE=E1+2D0*E2*T - ESQ=E*E - DESQ=2D0*E*DE - -* -* Series expansions -* - -* Longitude - V=0D0 - DV=0D0 - DO N=NL,1,-1 - COEFF=TL(N) - EMN=DBLE(ITL(1,N)) - EMPN=DBLE(ITL(2,N)) - DN=DBLE(ITL(3,N)) - FN=DBLE(ITL(4,N)) - I=ITL(5,N) - IF (I.EQ.0) THEN - EN=1D0 - DEN=0D0 - ELSE IF (I.EQ.1) THEN - EN=E - DEN=DE - ELSE - EN=ESQ - DEN=DESQ - END IF - THETA=EMN*EM+EMPN*EMP+DN*D+FN*F - DTHETA=EMN*DEM+EMPN*DEMP+DN*DD+FN*DF - FTHETA=SIN(THETA) - V=V+COEFF*FTHETA*EN - DV=DV+COEFF*(COS(THETA)*DTHETA*EN+FTHETA*DEN) - END DO - EL=ELP+D2R*V - DEL=(DELP+D2R*DV)/CJ - -* Latitude - V=0D0 - DV=0D0 - DO N=NB,1,-1 - COEFF=TB(N) - EMN=DBLE(ITB(1,N)) - EMPN=DBLE(ITB(2,N)) - DN=DBLE(ITB(3,N)) - FN=DBLE(ITB(4,N)) - I=ITB(5,N) - IF (I.EQ.0) THEN - EN=1D0 - DEN=0D0 - ELSE IF (I.EQ.1) THEN - EN=E - DEN=DE - ELSE - EN=ESQ - DEN=DESQ - END IF - THETA=EMN*EM+EMPN*EMP+DN*D+FN*F - DTHETA=EMN*DEM+EMPN*DEMP+DN*DD+FN*DF - FTHETA=SIN(THETA) - V=V+COEFF*FTHETA*EN - DV=DV+COEFF*(COS(THETA)*DTHETA*EN+FTHETA*DEN) - END DO - BF=1D0-CW1*COSOM-CW2*COSWOM - DBF=CW1*DOM*SINOM+CW2*DWOM*SINWOM - B=D2R*V*BF - DB=D2R*(DV*BF+V*DBF)/CJ - -* Parallax - V=0D0 - DV=0D0 - DO N=NP,1,-1 - COEFF=TP(N) - EMN=DBLE(ITP(1,N)) - EMPN=DBLE(ITP(2,N)) - DN=DBLE(ITP(3,N)) - FN=DBLE(ITP(4,N)) - I=ITP(5,N) - IF (I.EQ.0) THEN - EN=1D0 - DEN=0D0 - ELSE IF (I.EQ.1) THEN - EN=E - DEN=DE - ELSE - EN=ESQ - DEN=DESQ - END IF - THETA=EMN*EM+EMPN*EMP+DN*D+FN*F - DTHETA=EMN*DEM+EMPN*DEMP+DN*DD+FN*DF - FTHETA=COS(THETA) - V=V+COEFF*FTHETA*EN - DV=DV+COEFF*(-SIN(THETA)*DTHETA*EN+FTHETA*DEN) - END DO - P=D2R*V - DP=D2R*DV/CJ - -* -* Transformation into final form -* - -* Parallax to distance (AU, AU/sec) - SP=SIN(P) - R=ERADAU/SP - DR=-R*DP*COS(P)/SP - -* Longitude, latitude to x,y,z (AU) - SEL=SIN(EL) - CEL=COS(EL) - SB=SIN(B) - CB=COS(B) - RCB=R*CB - RBD=R*DB - W=RBD*SB-CB*DR - X=RCB*CEL - Y=RCB*SEL - Z=R*SB - XD=-Y*DEL-W*CEL - YD=X*DEL-W*SEL - ZD=RBD*CB+SB*DR - -* Julian centuries since J2000 - T=(DATE-51544.5D0)/36525D0 - -* Fricke equinox correction - EPJ=2000D0+T*100D0 - EQCOR=DS2R*(0.035D0+0.00085D0*(EPJ-B1950)) - -* Mean obliquity (IAU 1976) - EPS=DAS2R*(84381.448D0+(-46.8150D0+(-0.00059D0+0.001813D0*T)*T)*T) - -* To the equatorial system, mean of date, FK5 system - SINEPS=SIN(EPS) - COSEPS=COS(EPS) - ES=EQCOR*SINEPS - EC=EQCOR*COSEPS - PV(1)=X-EC*Y+ES*Z - PV(2)=EQCOR*X+Y*COSEPS-Z*SINEPS - PV(3)=Y*SINEPS+Z*COSEPS - PV(4)=XD-EC*YD+ES*ZD - PV(5)=EQCOR*XD+YD*COSEPS-ZD*SINEPS - PV(6)=YD*SINEPS+ZD*COSEPS - - END - SUBROUTINE sla_DMXV (DM, VA, VB) -*+ -* - - - - - -* D M X V -* - - - - - -* -* Performs the 3-D forward unitary transformation: -* -* vector VB = matrix DM * vector VA -* -* (double precision) -* -* Given: -* DM dp(3,3) matrix -* VA dp(3) vector -* -* Returned: -* VB dp(3) result vector -* -* To comply with the ANSI Fortran 77 standard, VA and VB must be -* different arrays. However, the routine is coded so as to work -* properly on many platforms even if this rule is violated. -* -* Last revision: 26 December 2004 -* -* Copyright P.T.Wallace. All rights reserved. -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION DM(3,3),VA(3),VB(3) - - INTEGER I,J - DOUBLE PRECISION W,VW(3) - - -* Matrix DM * vector VA -> vector VW - DO J=1,3 - W=0D0 - DO I=1,3 - W=W+DM(J,I)*VA(I) - END DO - VW(J)=W - END DO - -* Vector VW -> vector VB - DO J=1,3 - VB(J)=VW(J) - END DO - - END - DOUBLE PRECISION FUNCTION sla_DRANGE (ANGLE) -*+ -* - - - - - - - -* D R A N G E -* - - - - - - - -* -* Normalize angle into range +/- pi (double precision) -* -* Given: -* ANGLE dp the angle in radians -* -* The result (double precision) is ANGLE expressed in the range +/- pi. -* -* P.T.Wallace Starlink 23 November 1995 -* -* Copyright (C) 1995 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION ANGLE - - DOUBLE PRECISION DPI,D2PI - PARAMETER (DPI=3.141592653589793238462643D0) - PARAMETER (D2PI=6.283185307179586476925287D0) - - - sla_DRANGE=MOD(ANGLE,D2PI) - IF (ABS(sla_DRANGE).GE.DPI) - : sla_DRANGE=sla_DRANGE-SIGN(D2PI,ANGLE) - - END - DOUBLE PRECISION FUNCTION sla_DRANRM (ANGLE) -*+ -* - - - - - - - -* D R A N R M -* - - - - - - - -* -* Normalize angle into range 0-2 pi (double precision) -* -* Given: -* ANGLE dp the angle in radians -* -* The result is ANGLE expressed in the range 0-2 pi. -* -* Last revision: 22 July 2004 -* -* Copyright P.T.Wallace. All rights reserved. -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION ANGLE - - DOUBLE PRECISION D2PI - PARAMETER (D2PI=6.283185307179586476925286766559D0) - - - sla_DRANRM = MOD(ANGLE,D2PI) - IF (sla_DRANRM.LT.0D0) sla_DRANRM = sla_DRANRM+D2PI - - END - DOUBLE PRECISION FUNCTION sla_DTT (UTC) -*+ -* - - - - -* D T T -* - - - - -* -* Increment to be applied to Coordinated Universal Time UTC to give -* Terrestrial Time TT (formerly Ephemeris Time ET) -* -* (double precision) -* -* Given: -* UTC d UTC date as a modified JD (JD-2400000.5) -* -* Result: TT-UTC in seconds -* -* Notes: -* -* 1 The UTC is specified to be a date rather than a time to indicate -* that care needs to be taken not to specify an instant which lies -* within a leap second. Though in most cases UTC can include the -* fractional part, correct behaviour on the day of a leap second -* can only be guaranteed up to the end of the second 23:59:59. -* -* 2 Pre 1972 January 1 a fixed value of 10 + ET-TAI is returned. -* -* 3 See also the routine sla_DT, which roughly estimates ET-UT for -* historical epochs. -* -* Called: sla_DAT -* -* P.T.Wallace Starlink 6 December 1994 -* -* Copyright (C) 1995 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION UTC - - DOUBLE PRECISION sla_DAT - - - sla_DTT=32.184D0+sla_DAT(UTC) - - END - SUBROUTINE sla_ECMAT (DATE, RMAT) -*+ -* - - - - - - -* E C M A T -* - - - - - - -* -* Form the equatorial to ecliptic rotation matrix - IAU 1980 theory -* (double precision) -* -* Given: -* DATE dp TDB (loosely ET) as Modified Julian Date -* (JD-2400000.5) -* Returned: -* RMAT dp(3,3) matrix -* -* Reference: -* Murray,C.A., Vectorial Astrometry, section 4.3. -* -* Note: -* The matrix is in the sense V(ecl) = RMAT * V(equ); the -* equator, equinox and ecliptic are mean of date. -* -* Called: sla_DEULER -* -* P.T.Wallace Starlink 23 August 1996 -* -* Copyright (C) 1996 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION DATE,RMAT(3,3) - -* Arc seconds to radians - DOUBLE PRECISION AS2R - PARAMETER (AS2R=0.484813681109535994D-5) - - DOUBLE PRECISION T,EPS0 - - - -* Interval between basic epoch J2000.0 and current epoch (JC) - T = (DATE-51544.5D0)/36525D0 - -* Mean obliquity - EPS0 = AS2R* - : (84381.448D0+(-46.8150D0+(-0.00059D0+0.001813D0*T)*T)*T) - -* Matrix - CALL sla_DEULER('X',EPS0,0D0,0D0,RMAT) - - END - DOUBLE PRECISION FUNCTION sla_EPJ (DATE) -*+ -* - - - - -* E P J -* - - - - -* -* Conversion of Modified Julian Date to Julian Epoch (double precision) -* -* Given: -* DATE dp Modified Julian Date (JD - 2400000.5) -* -* The result is the Julian Epoch. -* -* Reference: -* Lieske,J.H., 1979. Astron.Astrophys.,73,282. -* -* P.T.Wallace Starlink February 1984 -* -* Copyright (C) 1995 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION DATE - - - sla_EPJ = 2000D0 + (DATE-51544.5D0)/365.25D0 - - END - SUBROUTINE sla_EQECL (DR, DD, DATE, DL, DB) -*+ -* - - - - - - -* E Q E C L -* - - - - - - -* -* Transformation from J2000.0 equatorial coordinates to -* ecliptic coordinates (double precision) -* -* Given: -* DR,DD dp J2000.0 mean RA,Dec (radians) -* DATE dp TDB (loosely ET) as Modified Julian Date -* (JD-2400000.5) -* Returned: -* DL,DB dp ecliptic longitude and latitude -* (mean of date, IAU 1980 theory, radians) -* -* Called: -* sla_DCS2C, sla_PREC, sla_EPJ, sla_DMXV, sla_ECMAT, sla_DCC2S, -* sla_DRANRM, sla_DRANGE -* -* P.T.Wallace Starlink March 1986 -* -* Copyright (C) 1995 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION DR,DD,DATE,DL,DB - - DOUBLE PRECISION sla_EPJ,sla_DRANRM,sla_DRANGE - - DOUBLE PRECISION RMAT(3,3),V1(3),V2(3) - - - -* Spherical to Cartesian - CALL sla_DCS2C(DR,DD,V1) - -* Mean J2000 to mean of date - CALL sla_PREC(2000D0,sla_EPJ(DATE),RMAT) - CALL sla_DMXV(RMAT,V1,V2) - -* Equatorial to ecliptic - CALL sla_ECMAT(DATE,RMAT) - CALL sla_DMXV(RMAT,V2,V1) - -* Cartesian to spherical - CALL sla_DCC2S(V1,DL,DB) - -* Express in conventional ranges - DL=sla_DRANRM(DL) - DB=sla_DRANGE(DB) - - END - DOUBLE PRECISION FUNCTION sla_EQEQX (DATE) -*+ -* - - - - - - -* E Q E Q X -* - - - - - - -* -* Equation of the equinoxes (IAU 1994, double precision) -* -* Given: -* DATE dp TDB (loosely ET) as Modified Julian Date -* (JD-2400000.5) -* -* The result is the equation of the equinoxes (double precision) -* in radians: -* -* Greenwich apparent ST = GMST + sla_EQEQX -* -* References: IAU Resolution C7, Recommendation 3 (1994) -* Capitaine, N. & Gontier, A.-M., Astron. Astrophys., -* 275, 645-650 (1993) -* -* Called: sla_NUTC -* -* Patrick Wallace Starlink 23 August 1996 -* -* Copyright (C) 1996 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION DATE - -* Turns to arc seconds and arc seconds to radians - DOUBLE PRECISION T2AS,AS2R - PARAMETER (T2AS=1296000D0, - : AS2R=0.484813681109535994D-5) - - DOUBLE PRECISION T,OM,DPSI,DEPS,EPS0 - - - -* Interval between basic epoch J2000.0 and current epoch (JC) - T=(DATE-51544.5D0)/36525D0 - -* Longitude of the mean ascending node of the lunar orbit on the -* ecliptic, measured from the mean equinox of date - OM=AS2R*(450160.280D0+(-5D0*T2AS-482890.539D0 - : +(7.455D0+0.008D0*T)*T)*T) - -* Nutation - CALL sla_NUTC(DATE,DPSI,DEPS,EPS0) - -* Equation of the equinoxes - sla_EQEQX=DPSI*COS(EPS0)+AS2R*(0.00264D0*SIN(OM)+ - : 0.000063D0*SIN(OM+OM)) - - END - SUBROUTINE sla_GEOC (P, H, R, Z) -*+ -* - - - - - -* G E O C -* - - - - - -* -* Convert geodetic position to geocentric (double precision) -* -* Given: -* P dp latitude (geodetic, radians) -* H dp height above reference spheroid (geodetic, metres) -* -* Returned: -* R dp distance from Earth axis (AU) -* Z dp distance from plane of Earth equator (AU) -* -* Notes: -* -* 1 Geocentric latitude can be obtained by evaluating ATAN2(Z,R). -* -* 2 IAU 1976 constants are used. -* -* Reference: -* -* Green,R.M., Spherical Astronomy, CUP 1985, p98. -* -* Last revision: 22 July 2004 -* -* Copyright P.T.Wallace. All rights reserved. -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION P,H,R,Z - -* Earth equatorial radius (metres) - DOUBLE PRECISION A0 - PARAMETER (A0=6378140D0) - -* Reference spheroid flattening factor and useful function - DOUBLE PRECISION F,B - PARAMETER (F=1D0/298.257D0,B=(1D0-F)**2) - -* Astronomical unit in metres - DOUBLE PRECISION AU - PARAMETER (AU=1.49597870D11) - - DOUBLE PRECISION SP,CP,C,S - - - -* Geodetic to geocentric conversion - SP = SIN(P) - CP = COS(P) - C = 1D0/SQRT(CP*CP+B*SP*SP) - S = B*C - R = (A0*C+H)*CP/AU - Z = (A0*S+H)*SP/AU - - END - DOUBLE PRECISION FUNCTION sla_GMST (UT1) -*+ -* - - - - - -* G M S T -* - - - - - -* -* Conversion from universal time to sidereal time (double precision) -* -* Given: -* UT1 dp universal time (strictly UT1) expressed as -* modified Julian Date (JD-2400000.5) -* -* The result is the Greenwich mean sidereal time (double -* precision, radians). -* -* The IAU 1982 expression (see page S15 of 1984 Astronomical Almanac) -* is used, but rearranged to reduce rounding errors. This expression -* is always described as giving the GMST at 0 hours UT. In fact, it -* gives the difference between the GMST and the UT, which happens to -* equal the GMST (modulo 24 hours) at 0 hours UT each day. In this -* routine, the entire UT is used directly as the argument for the -* standard formula, and the fractional part of the UT is added -* separately. Note that the factor 1.0027379... does not appear in the -* IAU 1982 expression explicitly but in the form of the coefficient -* 8640184.812866, which is 86400x36525x0.0027379... -* -* See also the routine sla_GMSTA, which delivers better numerical -* precision by accepting the UT date and time as separate arguments. -* -* Called: sla_DRANRM -* -* P.T.Wallace Starlink 14 October 2001 -* -* Copyright (C) 2001 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION UT1 - - DOUBLE PRECISION sla_DRANRM - - DOUBLE PRECISION D2PI,S2R - PARAMETER (D2PI=6.283185307179586476925286766559D0, - : S2R=7.272205216643039903848711535369D-5) - - DOUBLE PRECISION TU - - - -* Julian centuries from fundamental epoch J2000 to this UT - TU=(UT1-51544.5D0)/36525D0 - -* GMST at this UT - sla_GMST=sla_DRANRM(MOD(UT1,1D0)*D2PI+ - : (24110.54841D0+ - : (8640184.812866D0+ - : (0.093104D0-6.2D-6*TU)*TU)*TU)*S2R) - - END - SUBROUTINE sla_NUTC (DATE, DPSI, DEPS, EPS0) -*+ -* - - - - - -* N U T C -* - - - - - -* -* Nutation: longitude & obliquity components and mean obliquity, -* using the Shirai & Fukushima (2001) theory. -* -* Given: -* DATE d TDB (loosely ET) as Modified Julian Date -* (JD-2400000.5) -* Returned: -* DPSI,DEPS d nutation in longitude,obliquity -* EPS0 d mean obliquity -* -* Notes: -* -* 1 The routine predicts forced nutation (but not free core nutation) -* plus corrections to the IAU 1976 precession model. -* -* 2 Earth attitude predictions made by combining the present nutation -* model with IAU 1976 precession are accurate to 1 mas (with respect -* to the ICRF) for a few decades around 2000. -* -* 3 The sla_NUTC80 routine is the equivalent of the present routine -* but using the IAU 1980 nutation theory. The older theory is less -* accurate, leading to errors as large as 350 mas over the interval -* 1900-2100, mainly because of the error in the IAU 1976 precession. -* -* References: -* -* Shirai, T. & Fukushima, T., Astron.J. 121, 3270-3283 (2001). -* -* Fukushima, T., Astron.Astrophys. 244, L11 (1991). -* -* Simon, J. L., Bretagnon, P., Chapront, J., Chapront-Touze, M., -* Francou, G. & Laskar, J., Astron.Astrophys. 282, 663 (1994). -* -* This revision: 24 November 2005 -* -* Copyright P.T.Wallace. All rights reserved. -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION DATE,DPSI,DEPS,EPS0 - -* Degrees to radians - DOUBLE PRECISION DD2R - PARAMETER (DD2R=1.745329251994329576923691D-2) - -* Arc seconds to radians - DOUBLE PRECISION DAS2R - PARAMETER (DAS2R=4.848136811095359935899141D-6) - -* Arc seconds in a full circle - DOUBLE PRECISION TURNAS - PARAMETER (TURNAS=1296000D0) - -* Reference epoch (J2000), MJD - DOUBLE PRECISION DJM0 - PARAMETER (DJM0=51544.5D0 ) - -* Days per Julian century - DOUBLE PRECISION DJC - PARAMETER (DJC=36525D0) - - INTEGER I,J - DOUBLE PRECISION T,EL,ELP,F,D,OM,VE,MA,JU,SA,THETA,C,S,DP,DE - -* Number of terms in the nutation model - INTEGER NTERMS - PARAMETER (NTERMS=194) - -* The SF2001 forced nutation model - INTEGER NA(9,NTERMS) - DOUBLE PRECISION PSI(4,NTERMS), EPS(4,NTERMS) - -* Coefficients of fundamental angles - DATA ( ( NA(I,J), I=1,9 ), J=1,10 ) / - : 0, 0, 0, 0, -1, 0, 0, 0, 0, - : 0, 0, 2, -2, 2, 0, 0, 0, 0, - : 0, 0, 2, 0, 2, 0, 0, 0, 0, - : 0, 0, 0, 0, -2, 0, 0, 0, 0, - : 0, 1, 0, 0, 0, 0, 0, 0, 0, - : 0, 1, 2, -2, 2, 0, 0, 0, 0, - : 1, 0, 0, 0, 0, 0, 0, 0, 0, - : 0, 0, 2, 0, 1, 0, 0, 0, 0, - : 1, 0, 2, 0, 2, 0, 0, 0, 0, - : 0, -1, 2, -2, 2, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=11,20 ) / - : 0, 0, 2, -2, 1, 0, 0, 0, 0, - : -1, 0, 2, 0, 2, 0, 0, 0, 0, - : -1, 0, 0, 2, 0, 0, 0, 0, 0, - : 1, 0, 0, 0, 1, 0, 0, 0, 0, - : 1, 0, 0, 0, -1, 0, 0, 0, 0, - : -1, 0, 2, 2, 2, 0, 0, 0, 0, - : 1, 0, 2, 0, 1, 0, 0, 0, 0, - : -2, 0, 2, 0, 1, 0, 0, 0, 0, - : 0, 0, 0, 2, 0, 0, 0, 0, 0, - : 0, 0, 2, 2, 2, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=21,30 ) / - : 2, 0, 0, -2, 0, 0, 0, 0, 0, - : 2, 0, 2, 0, 2, 0, 0, 0, 0, - : 1, 0, 2, -2, 2, 0, 0, 0, 0, - : -1, 0, 2, 0, 1, 0, 0, 0, 0, - : 2, 0, 0, 0, 0, 0, 0, 0, 0, - : 0, 0, 2, 0, 0, 0, 0, 0, 0, - : 0, 1, 0, 0, 1, 0, 0, 0, 0, - : -1, 0, 0, 2, 1, 0, 0, 0, 0, - : 0, 2, 2, -2, 2, 0, 0, 0, 0, - : 0, 0, 2, -2, 0, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=31,40 ) / - : -1, 0, 0, 2, -1, 0, 0, 0, 0, - : 0, 1, 0, 0, -1, 0, 0, 0, 0, - : 0, 2, 0, 0, 0, 0, 0, 0, 0, - : -1, 0, 2, 2, 1, 0, 0, 0, 0, - : 1, 0, 2, 2, 2, 0, 0, 0, 0, - : 0, 1, 2, 0, 2, 0, 0, 0, 0, - : -2, 0, 2, 0, 0, 0, 0, 0, 0, - : 0, 0, 2, 2, 1, 0, 0, 0, 0, - : 0, -1, 2, 0, 2, 0, 0, 0, 0, - : 0, 0, 0, 2, 1, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=41,50 ) / - : 1, 0, 2, -2, 1, 0, 0, 0, 0, - : 2, 0, 0, -2, -1, 0, 0, 0, 0, - : 2, 0, 2, -2, 2, 0, 0, 0, 0, - : 2, 0, 2, 0, 1, 0, 0, 0, 0, - : 0, 0, 0, 2, -1, 0, 0, 0, 0, - : 0, -1, 2, -2, 1, 0, 0, 0, 0, - : -1, -1, 0, 2, 0, 0, 0, 0, 0, - : 2, 0, 0, -2, 1, 0, 0, 0, 0, - : 1, 0, 0, 2, 0, 0, 0, 0, 0, - : 0, 1, 2, -2, 1, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=51,60 ) / - : 1, -1, 0, 0, 0, 0, 0, 0, 0, - : -2, 0, 2, 0, 2, 0, 0, 0, 0, - : 0, -1, 0, 2, 0, 0, 0, 0, 0, - : 3, 0, 2, 0, 2, 0, 0, 0, 0, - : 0, 0, 0, 1, 0, 0, 0, 0, 0, - : 1, -1, 2, 0, 2, 0, 0, 0, 0, - : 1, 0, 0, -1, 0, 0, 0, 0, 0, - : -1, -1, 2, 2, 2, 0, 0, 0, 0, - : -1, 0, 2, 0, 0, 0, 0, 0, 0, - : 2, 0, 0, 0, -1, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=61,70 ) / - : 0, -1, 2, 2, 2, 0, 0, 0, 0, - : 1, 1, 2, 0, 2, 0, 0, 0, 0, - : 2, 0, 0, 0, 1, 0, 0, 0, 0, - : 1, 1, 0, 0, 0, 0, 0, 0, 0, - : 1, 0, -2, 2, -1, 0, 0, 0, 0, - : 1, 0, 2, 0, 0, 0, 0, 0, 0, - : -1, 1, 0, 1, 0, 0, 0, 0, 0, - : 1, 0, 0, 0, 2, 0, 0, 0, 0, - : -1, 0, 1, 0, 1, 0, 0, 0, 0, - : 0, 0, 2, 1, 2, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=71,80 ) / - : -1, 1, 0, 1, 1, 0, 0, 0, 0, - : -1, 0, 2, 4, 2, 0, 0, 0, 0, - : 0, -2, 2, -2, 1, 0, 0, 0, 0, - : 1, 0, 2, 2, 1, 0, 0, 0, 0, - : 1, 0, 0, 0, -2, 0, 0, 0, 0, - : -2, 0, 2, 2, 2, 0, 0, 0, 0, - : 1, 1, 2, -2, 2, 0, 0, 0, 0, - : -2, 0, 2, 4, 2, 0, 0, 0, 0, - : -1, 0, 4, 0, 2, 0, 0, 0, 0, - : 2, 0, 2, -2, 1, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=81,90 ) / - : 1, 0, 0, -1, -1, 0, 0, 0, 0, - : 2, 0, 2, 2, 2, 0, 0, 0, 0, - : 1, 0, 0, 2, 1, 0, 0, 0, 0, - : 3, 0, 0, 0, 0, 0, 0, 0, 0, - : 0, 0, 2, -2, -1, 0, 0, 0, 0, - : 3, 0, 2, -2, 2, 0, 0, 0, 0, - : 0, 0, 4, -2, 2, 0, 0, 0, 0, - : -1, 0, 0, 4, 0, 0, 0, 0, 0, - : 0, 1, 2, 0, 1, 0, 0, 0, 0, - : 0, 0, 2, -2, 3, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=91,100 ) / - : -2, 0, 0, 4, 0, 0, 0, 0, 0, - : -1, -1, 0, 2, 1, 0, 0, 0, 0, - : -2, 0, 2, 0, -1, 0, 0, 0, 0, - : 0, 0, 2, 0, -1, 0, 0, 0, 0, - : 0, -1, 2, 0, 1, 0, 0, 0, 0, - : 0, 1, 0, 0, 2, 0, 0, 0, 0, - : 0, 0, 2, -1, 2, 0, 0, 0, 0, - : 2, 1, 0, -2, 0, 0, 0, 0, 0, - : 0, 0, 2, 4, 2, 0, 0, 0, 0, - : -1, -1, 0, 2, -1, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=101,110 ) / - : -1, 1, 0, 2, 0, 0, 0, 0, 0, - : 1, -1, 0, 0, 1, 0, 0, 0, 0, - : 0, -1, 2, -2, 0, 0, 0, 0, 0, - : 0, 1, 0, 0, -2, 0, 0, 0, 0, - : 1, -1, 2, 2, 2, 0, 0, 0, 0, - : 1, 0, 0, 2, -1, 0, 0, 0, 0, - : -1, 1, 2, 2, 2, 0, 0, 0, 0, - : 3, 0, 2, 0, 1, 0, 0, 0, 0, - : 0, 1, 2, 2, 2, 0, 0, 0, 0, - : 1, 0, 2, -2, 0, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=111,120 ) / - : -1, 0, -2, 4, -1, 0, 0, 0, 0, - : -1, -1, 2, 2, 1, 0, 0, 0, 0, - : 0, -1, 2, 2, 1, 0, 0, 0, 0, - : 2, -1, 2, 0, 2, 0, 0, 0, 0, - : 0, 0, 0, 2, 2, 0, 0, 0, 0, - : 1, -1, 2, 0, 1, 0, 0, 0, 0, - : -1, 1, 2, 0, 2, 0, 0, 0, 0, - : 0, 1, 0, 2, 0, 0, 0, 0, 0, - : 0, 1, 2, -2, 0, 0, 0, 0, 0, - : 0, 3, 2, -2, 2, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=121,130 ) / - : 0, 0, 0, 1, 1, 0, 0, 0, 0, - : -1, 0, 2, 2, 0, 0, 0, 0, 0, - : 2, 1, 2, 0, 2, 0, 0, 0, 0, - : 1, 1, 0, 0, 1, 0, 0, 0, 0, - : 2, 0, 0, 2, 0, 0, 0, 0, 0, - : 1, 1, 2, 0, 1, 0, 0, 0, 0, - : -1, 0, 0, 2, 2, 0, 0, 0, 0, - : 1, 0, -2, 2, 0, 0, 0, 0, 0, - : 0, -1, 0, 2, -1, 0, 0, 0, 0, - : -1, 0, 1, 0, 2, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=131,140 ) / - : 0, 1, 0, 1, 0, 0, 0, 0, 0, - : 1, 0, -2, 2, -2, 0, 0, 0, 0, - : 0, 0, 0, 1, -1, 0, 0, 0, 0, - : 1, -1, 0, 0, -1, 0, 0, 0, 0, - : 0, 0, 0, 4, 0, 0, 0, 0, 0, - : 1, -1, 0, 2, 0, 0, 0, 0, 0, - : 1, 0, 2, 1, 2, 0, 0, 0, 0, - : 1, 0, 2, -1, 2, 0, 0, 0, 0, - : -1, 0, 0, 2, -2, 0, 0, 0, 0, - : 0, 0, 2, 1, 1, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=141,150 ) / - : -1, 0, 2, 0, -1, 0, 0, 0, 0, - : -1, 0, 2, 4, 1, 0, 0, 0, 0, - : 0, 0, 2, 2, 0, 0, 0, 0, 0, - : 1, 1, 2, -2, 1, 0, 0, 0, 0, - : 0, 0, 1, 0, 1, 0, 0, 0, 0, - : -1, 0, 2, -1, 1, 0, 0, 0, 0, - : -2, 0, 2, 2, 1, 0, 0, 0, 0, - : 2, -1, 0, 0, 0, 0, 0, 0, 0, - : 4, 0, 2, 0, 2, 0, 0, 0, 0, - : 2, 1, 2, -2, 2, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=151,160 ) / - : 0, 1, 2, 1, 2, 0, 0, 0, 0, - : 1, 0, 4, -2, 2, 0, 0, 0, 0, - : 1, 1, 0, 0, -1, 0, 0, 0, 0, - : -2, 0, 2, 4, 1, 0, 0, 0, 0, - : 2, 0, 2, 0, 0, 0, 0, 0, 0, - : -1, 0, 1, 0, 0, 0, 0, 0, 0, - : 1, 0, 0, 1, 0, 0, 0, 0, 0, - : 0, 1, 0, 2, 1, 0, 0, 0, 0, - : -1, 0, 4, 0, 1, 0, 0, 0, 0, - : -1, 0, 0, 4, 1, 0, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=161,170 ) / - : 2, 0, 2, 2, 1, 0, 0, 0, 0, - : 2, 1, 0, 0, 0, 0, 0, 0, 0, - : 0, 0, 5, -5, 5, -3, 0, 0, 0, - : 0, 0, 0, 0, 0, 0, 0, 2, 0, - : 0, 0, 1, -1, 1, 0, 0, -1, 0, - : 0, 0, -1, 1, -1, 1, 0, 0, 0, - : 0, 0, -1, 1, 0, 0, 2, 0, 0, - : 0, 0, 3, -3, 3, 0, 0, -1, 0, - : 0, 0, -8, 8, -7, 5, 0, 0, 0, - : 0, 0, -1, 1, -1, 0, 2, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=171,180 ) / - : 0, 0, -2, 2, -2, 2, 0, 0, 0, - : 0, 0, -6, 6, -6, 4, 0, 0, 0, - : 0, 0, -2, 2, -2, 0, 8, -3, 0, - : 0, 0, 6, -6, 6, 0, -8, 3, 0, - : 0, 0, 4, -4, 4, -2, 0, 0, 0, - : 0, 0, -3, 3, -3, 2, 0, 0, 0, - : 0, 0, 4, -4, 3, 0, -8, 3, 0, - : 0, 0, -4, 4, -5, 0, 8, -3, 0, - : 0, 0, 0, 0, 0, 2, 0, 0, 0, - : 0, 0, -4, 4, -4, 3, 0, 0, 0 / - DATA ( ( NA(I,J), I=1,9 ), J=181,190 ) / - : 0, 1, -1, 1, -1, 0, 0, 1, 0, - : 0, 0, 0, 0, 0, 0, 0, 1, 0, - : 0, 0, 1, -1, 1, 1, 0, 0, 0, - : 0, 0, 2, -2, 2, 0, -2, 0, 0, - : 0, -1, -7, 7, -7, 5, 0, 0, 0, - : -2, 0, 2, 0, 2, 0, 0, -2, 0, - : -2, 0, 2, 0, 1, 0, 0, -3, 0, - : 0, 0, 2, -2, 2, 0, 0, -2, 0, - : 0, 0, 1, -1, 1, 0, 0, 1, 0, - : 0, 0, 0, 0, 0, 0, 0, 0, 2 / - DATA ( ( NA(I,J), I=1,9 ), J=191,NTERMS ) / - : 0, 0, 0, 0, 0, 0, 0, 0, 1, - : 2, 0, -2, 0, -2, 0, 0, 3, 0, - : 0, 0, 1, -1, 1, 0, 0, -2, 0, - : 0, 0, -7, 7, -7, 5, 0, 0, 0 / - -* Nutation series: longitude - DATA ( ( PSI(I,J), I=1,4 ), J=1,10 ) / - : 3341.5D0, 17206241.8D0, 3.1D0, 17409.5D0, - : -1716.8D0, -1317185.3D0, 1.4D0, -156.8D0, - : 285.7D0, -227667.0D0, 0.3D0, -23.5D0, - : -68.6D0, -207448.0D0, 0.0D0, -21.4D0, - : 950.3D0, 147607.9D0, -2.3D0, -355.0D0, - : -66.7D0, -51689.1D0, 0.2D0, 122.6D0, - : -108.6D0, 71117.6D0, 0.0D0, 7.0D0, - : 35.6D0, -38740.2D0, 0.1D0, -36.2D0, - : 85.4D0, -30127.6D0, 0.0D0, -3.1D0, - : 9.0D0, 21583.0D0, 0.1D0, -50.3D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=11,20 ) / - : 22.1D0, 12822.8D0, 0.0D0, 13.3D0, - : 3.4D0, 12350.8D0, 0.0D0, 1.3D0, - : -21.1D0, 15699.4D0, 0.0D0, 1.6D0, - : 4.2D0, 6313.8D0, 0.0D0, 6.2D0, - : -22.8D0, 5796.9D0, 0.0D0, 6.1D0, - : 15.7D0, -5961.1D0, 0.0D0, -0.6D0, - : 13.1D0, -5159.1D0, 0.0D0, -4.6D0, - : 1.8D0, 4592.7D0, 0.0D0, 4.5D0, - : -17.5D0, 6336.0D0, 0.0D0, 0.7D0, - : 16.3D0, -3851.1D0, 0.0D0, -0.4D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=21,30 ) / - : -2.8D0, 4771.7D0, 0.0D0, 0.5D0, - : 13.8D0, -3099.3D0, 0.0D0, -0.3D0, - : 0.2D0, 2860.3D0, 0.0D0, 0.3D0, - : 1.4D0, 2045.3D0, 0.0D0, 2.0D0, - : -8.6D0, 2922.6D0, 0.0D0, 0.3D0, - : -7.7D0, 2587.9D0, 0.0D0, 0.2D0, - : 8.8D0, -1408.1D0, 0.0D0, 3.7D0, - : 1.4D0, 1517.5D0, 0.0D0, 1.5D0, - : -1.9D0, -1579.7D0, 0.0D0, 7.7D0, - : 1.3D0, -2178.6D0, 0.0D0, -0.2D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=31,40 ) / - : -4.8D0, 1286.8D0, 0.0D0, 1.3D0, - : 6.3D0, 1267.2D0, 0.0D0, -4.0D0, - : -1.0D0, 1669.3D0, 0.0D0, -8.3D0, - : 2.4D0, -1020.0D0, 0.0D0, -0.9D0, - : 4.5D0, -766.9D0, 0.0D0, 0.0D0, - : -1.1D0, 756.5D0, 0.0D0, -1.7D0, - : -1.4D0, -1097.3D0, 0.0D0, -0.5D0, - : 2.6D0, -663.0D0, 0.0D0, -0.6D0, - : 0.8D0, -714.1D0, 0.0D0, 1.6D0, - : 0.4D0, -629.9D0, 0.0D0, -0.6D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=41,50 ) / - : 0.3D0, 580.4D0, 0.0D0, 0.6D0, - : -1.6D0, 577.3D0, 0.0D0, 0.5D0, - : -0.9D0, 644.4D0, 0.0D0, 0.0D0, - : 2.2D0, -534.0D0, 0.0D0, -0.5D0, - : -2.5D0, 493.3D0, 0.0D0, 0.5D0, - : -0.1D0, -477.3D0, 0.0D0, -2.4D0, - : -0.9D0, 735.0D0, 0.0D0, -1.7D0, - : 0.7D0, 406.2D0, 0.0D0, 0.4D0, - : -2.8D0, 656.9D0, 0.0D0, 0.0D0, - : 0.6D0, 358.0D0, 0.0D0, 2.0D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=51,60 ) / - : -0.7D0, 472.5D0, 0.0D0, -1.1D0, - : -0.1D0, -300.5D0, 0.0D0, 0.0D0, - : -1.2D0, 435.1D0, 0.0D0, -1.0D0, - : 1.8D0, -289.4D0, 0.0D0, 0.0D0, - : 0.6D0, -422.6D0, 0.0D0, 0.0D0, - : 0.8D0, -287.6D0, 0.0D0, 0.6D0, - : -38.6D0, -392.3D0, 0.0D0, 0.0D0, - : 0.7D0, -281.8D0, 0.0D0, 0.6D0, - : 0.6D0, -405.7D0, 0.0D0, 0.0D0, - : -1.2D0, 229.0D0, 0.0D0, 0.2D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=61,70 ) / - : 1.1D0, -264.3D0, 0.0D0, 0.5D0, - : -0.7D0, 247.9D0, 0.0D0, -0.5D0, - : -0.2D0, 218.0D0, 0.0D0, 0.2D0, - : 0.6D0, -339.0D0, 0.0D0, 0.8D0, - : -0.7D0, 198.7D0, 0.0D0, 0.2D0, - : -1.5D0, 334.0D0, 0.0D0, 0.0D0, - : 0.1D0, 334.0D0, 0.0D0, 0.0D0, - : -0.1D0, -198.1D0, 0.0D0, 0.0D0, - : -106.6D0, 0.0D0, 0.0D0, 0.0D0, - : -0.5D0, 165.8D0, 0.0D0, 0.0D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=71,80 ) / - : 0.0D0, 134.8D0, 0.0D0, 0.0D0, - : 0.9D0, -151.6D0, 0.0D0, 0.0D0, - : 0.0D0, -129.7D0, 0.0D0, 0.0D0, - : 0.8D0, -132.8D0, 0.0D0, -0.1D0, - : 0.5D0, -140.7D0, 0.0D0, 0.0D0, - : -0.1D0, 138.4D0, 0.0D0, 0.0D0, - : 0.0D0, 129.0D0, 0.0D0, -0.3D0, - : 0.5D0, -121.2D0, 0.0D0, 0.0D0, - : -0.3D0, 114.5D0, 0.0D0, 0.0D0, - : -0.1D0, 101.8D0, 0.0D0, 0.0D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=81,90 ) / - : -3.6D0, -101.9D0, 0.0D0, 0.0D0, - : 0.8D0, -109.4D0, 0.0D0, 0.0D0, - : 0.2D0, -97.0D0, 0.0D0, 0.0D0, - : -0.7D0, 157.3D0, 0.0D0, 0.0D0, - : 0.2D0, -83.3D0, 0.0D0, 0.0D0, - : -0.3D0, 93.3D0, 0.0D0, 0.0D0, - : -0.1D0, 92.1D0, 0.0D0, 0.0D0, - : -0.5D0, 133.6D0, 0.0D0, 0.0D0, - : -0.1D0, 81.5D0, 0.0D0, 0.0D0, - : 0.0D0, 123.9D0, 0.0D0, 0.0D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=91,100 ) / - : -0.3D0, 128.1D0, 0.0D0, 0.0D0, - : 0.1D0, 74.1D0, 0.0D0, -0.3D0, - : -0.2D0, -70.3D0, 0.0D0, 0.0D0, - : -0.4D0, 66.6D0, 0.0D0, 0.0D0, - : 0.1D0, -66.7D0, 0.0D0, 0.0D0, - : -0.7D0, 69.3D0, 0.0D0, -0.3D0, - : 0.0D0, -70.4D0, 0.0D0, 0.0D0, - : -0.1D0, 101.5D0, 0.0D0, 0.0D0, - : 0.5D0, -69.1D0, 0.0D0, 0.0D0, - : -0.2D0, 58.5D0, 0.0D0, 0.2D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=101,110 ) / - : 0.1D0, -94.9D0, 0.0D0, 0.2D0, - : 0.0D0, 52.9D0, 0.0D0, -0.2D0, - : 0.1D0, 86.7D0, 0.0D0, -0.2D0, - : -0.1D0, -59.2D0, 0.0D0, 0.2D0, - : 0.3D0, -58.8D0, 0.0D0, 0.1D0, - : -0.3D0, 49.0D0, 0.0D0, 0.0D0, - : -0.2D0, 56.9D0, 0.0D0, -0.1D0, - : 0.3D0, -50.2D0, 0.0D0, 0.0D0, - : -0.2D0, 53.4D0, 0.0D0, -0.1D0, - : 0.1D0, -76.5D0, 0.0D0, 0.0D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=111,120 ) / - : -0.2D0, 45.3D0, 0.0D0, 0.0D0, - : 0.1D0, -46.8D0, 0.0D0, 0.0D0, - : 0.2D0, -44.6D0, 0.0D0, 0.0D0, - : 0.2D0, -48.7D0, 0.0D0, 0.0D0, - : 0.1D0, -46.8D0, 0.0D0, 0.0D0, - : 0.1D0, -42.0D0, 0.0D0, 0.0D0, - : 0.0D0, 46.4D0, 0.0D0, -0.1D0, - : 0.2D0, -67.3D0, 0.0D0, 0.1D0, - : 0.0D0, -65.8D0, 0.0D0, 0.2D0, - : -0.1D0, -43.9D0, 0.0D0, 0.3D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=121,130 ) / - : 0.0D0, -38.9D0, 0.0D0, 0.0D0, - : -0.3D0, 63.9D0, 0.0D0, 0.0D0, - : -0.2D0, 41.2D0, 0.0D0, 0.0D0, - : 0.0D0, -36.1D0, 0.0D0, 0.2D0, - : -0.3D0, 58.5D0, 0.0D0, 0.0D0, - : -0.1D0, 36.1D0, 0.0D0, 0.0D0, - : 0.0D0, -39.7D0, 0.0D0, 0.0D0, - : 0.1D0, -57.7D0, 0.0D0, 0.0D0, - : -0.2D0, 33.4D0, 0.0D0, 0.0D0, - : 36.4D0, 0.0D0, 0.0D0, 0.0D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=131,140 ) / - : -0.1D0, 55.7D0, 0.0D0, -0.1D0, - : 0.1D0, -35.4D0, 0.0D0, 0.0D0, - : 0.1D0, -31.0D0, 0.0D0, 0.0D0, - : -0.1D0, 30.1D0, 0.0D0, 0.0D0, - : -0.3D0, 49.2D0, 0.0D0, 0.0D0, - : -0.2D0, 49.1D0, 0.0D0, 0.0D0, - : -0.1D0, 33.6D0, 0.0D0, 0.0D0, - : 0.1D0, -33.5D0, 0.0D0, 0.0D0, - : 0.1D0, -31.0D0, 0.0D0, 0.0D0, - : -0.1D0, 28.0D0, 0.0D0, 0.0D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=141,150 ) / - : 0.1D0, -25.2D0, 0.0D0, 0.0D0, - : 0.1D0, -26.2D0, 0.0D0, 0.0D0, - : -0.2D0, 41.5D0, 0.0D0, 0.0D0, - : 0.0D0, 24.5D0, 0.0D0, 0.1D0, - : -16.2D0, 0.0D0, 0.0D0, 0.0D0, - : 0.0D0, -22.3D0, 0.0D0, 0.0D0, - : 0.0D0, 23.1D0, 0.0D0, 0.0D0, - : -0.1D0, 37.5D0, 0.0D0, 0.0D0, - : 0.2D0, -25.7D0, 0.0D0, 0.0D0, - : 0.0D0, 25.2D0, 0.0D0, 0.0D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=151,160 ) / - : 0.1D0, -24.5D0, 0.0D0, 0.0D0, - : -0.1D0, 24.3D0, 0.0D0, 0.0D0, - : 0.1D0, -20.7D0, 0.0D0, 0.0D0, - : 0.1D0, -20.8D0, 0.0D0, 0.0D0, - : -0.2D0, 33.4D0, 0.0D0, 0.0D0, - : 32.9D0, 0.0D0, 0.0D0, 0.0D0, - : 0.1D0, -32.6D0, 0.0D0, 0.0D0, - : 0.0D0, 19.9D0, 0.0D0, 0.0D0, - : -0.1D0, 19.6D0, 0.0D0, 0.0D0, - : 0.0D0, -18.7D0, 0.0D0, 0.0D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=161,170 ) / - : 0.1D0, -19.0D0, 0.0D0, 0.0D0, - : 0.1D0, -28.6D0, 0.0D0, 0.0D0, - : 4.0D0, 178.8D0,-11.8D0, 0.3D0, - : 39.8D0, -107.3D0, -5.6D0, -1.0D0, - : 9.9D0, 164.0D0, -4.1D0, 0.1D0, - : -4.8D0, -135.3D0, -3.4D0, -0.1D0, - : 50.5D0, 75.0D0, 1.4D0, -1.2D0, - : -1.1D0, -53.5D0, 1.3D0, 0.0D0, - : -45.0D0, -2.4D0, -0.4D0, 6.6D0, - : -11.5D0, -61.0D0, -0.9D0, 0.4D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=171,180 ) / - : 4.4D0, -68.4D0, -3.4D0, 0.0D0, - : 7.7D0, -47.1D0, -4.7D0, -1.0D0, - : -42.9D0, -12.6D0, -1.2D0, 4.2D0, - : -42.8D0, 12.7D0, -1.2D0, -4.2D0, - : -7.6D0, -44.1D0, 2.1D0, -0.5D0, - : -64.1D0, 1.7D0, 0.2D0, 4.5D0, - : 36.4D0, -10.4D0, 1.0D0, 3.5D0, - : 35.6D0, 10.2D0, 1.0D0, -3.5D0, - : -1.7D0, 39.5D0, 2.0D0, 0.0D0, - : 50.9D0, -8.2D0, -0.8D0, -5.0D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=181,190 ) / - : 0.0D0, 52.3D0, 1.2D0, 0.0D0, - : -42.9D0, -17.8D0, 0.4D0, 0.0D0, - : 2.6D0, 34.3D0, 0.8D0, 0.0D0, - : -0.8D0, -48.6D0, 2.4D0, -0.1D0, - : -4.9D0, 30.5D0, 3.7D0, 0.7D0, - : 0.0D0, -43.6D0, 2.1D0, 0.0D0, - : 0.0D0, -25.4D0, 1.2D0, 0.0D0, - : 2.0D0, 40.9D0, -2.0D0, 0.0D0, - : -2.1D0, 26.1D0, 0.6D0, 0.0D0, - : 22.6D0, -3.2D0, -0.5D0, -0.5D0 / - DATA ( ( PSI(I,J), I=1,4 ), J=191,NTERMS ) / - : -7.6D0, 24.9D0, -0.4D0, -0.2D0, - : -6.2D0, 34.9D0, 1.7D0, 0.3D0, - : 2.0D0, 17.4D0, -0.4D0, 0.1D0, - : -3.9D0, 20.5D0, 2.4D0, 0.6D0 / - -* Nutation series: obliquity - DATA ( ( EPS(I,J), I=1,4 ), J=1,10 ) / - : 9205365.8D0, -1506.2D0, 885.7D0, -0.2D0, - : 573095.9D0, -570.2D0, -305.0D0, -0.3D0, - : 97845.5D0, 147.8D0, -48.8D0, -0.2D0, - : -89753.6D0, 28.0D0, 46.9D0, 0.0D0, - : 7406.7D0, -327.1D0, -18.2D0, 0.8D0, - : 22442.3D0, -22.3D0, -67.6D0, 0.0D0, - : -683.6D0, 46.8D0, 0.0D0, 0.0D0, - : 20070.7D0, 36.0D0, 1.6D0, 0.0D0, - : 12893.8D0, 39.5D0, -6.2D0, 0.0D0, - : -9593.2D0, 14.4D0, 30.2D0, -0.1D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=11,20 ) / - : -6899.5D0, 4.8D0, -0.6D0, 0.0D0, - : -5332.5D0, -0.1D0, 2.7D0, 0.0D0, - : -125.2D0, 10.5D0, 0.0D0, 0.0D0, - : -3323.4D0, -0.9D0, -0.3D0, 0.0D0, - : 3142.3D0, 8.9D0, 0.3D0, 0.0D0, - : 2552.5D0, 7.3D0, -1.2D0, 0.0D0, - : 2634.4D0, 8.8D0, 0.2D0, 0.0D0, - : -2424.4D0, 1.6D0, -0.4D0, 0.0D0, - : -123.3D0, 3.9D0, 0.0D0, 0.0D0, - : 1642.4D0, 7.3D0, -0.8D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=21,30 ) / - : 47.9D0, 3.2D0, 0.0D0, 0.0D0, - : 1321.2D0, 6.2D0, -0.6D0, 0.0D0, - : -1234.1D0, -0.3D0, 0.6D0, 0.0D0, - : -1076.5D0, -0.3D0, 0.0D0, 0.0D0, - : -61.6D0, 1.8D0, 0.0D0, 0.0D0, - : -55.4D0, 1.6D0, 0.0D0, 0.0D0, - : 856.9D0, -4.9D0, -2.1D0, 0.0D0, - : -800.7D0, -0.1D0, 0.0D0, 0.0D0, - : 685.1D0, -0.6D0, -3.8D0, 0.0D0, - : -16.9D0, -1.5D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=31,40 ) / - : 695.7D0, 1.8D0, 0.0D0, 0.0D0, - : 642.2D0, -2.6D0, -1.6D0, 0.0D0, - : 13.3D0, 1.1D0, -0.1D0, 0.0D0, - : 521.9D0, 1.6D0, 0.0D0, 0.0D0, - : 325.8D0, 2.0D0, -0.1D0, 0.0D0, - : -325.1D0, -0.5D0, 0.9D0, 0.0D0, - : 10.1D0, 0.3D0, 0.0D0, 0.0D0, - : 334.5D0, 1.6D0, 0.0D0, 0.0D0, - : 307.1D0, 0.4D0, -0.9D0, 0.0D0, - : 327.2D0, 0.5D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=41,50 ) / - : -304.6D0, -0.1D0, 0.0D0, 0.0D0, - : 304.0D0, 0.6D0, 0.0D0, 0.0D0, - : -276.8D0, -0.5D0, 0.1D0, 0.0D0, - : 268.9D0, 1.3D0, 0.0D0, 0.0D0, - : 271.8D0, 1.1D0, 0.0D0, 0.0D0, - : 271.5D0, -0.4D0, -0.8D0, 0.0D0, - : -5.2D0, 0.5D0, 0.0D0, 0.0D0, - : -220.5D0, 0.1D0, 0.0D0, 0.0D0, - : -20.1D0, 0.3D0, 0.0D0, 0.0D0, - : -191.0D0, 0.1D0, 0.5D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=51,60 ) / - : -4.1D0, 0.3D0, 0.0D0, 0.0D0, - : 130.6D0, -0.1D0, 0.0D0, 0.0D0, - : 3.0D0, 0.3D0, 0.0D0, 0.0D0, - : 122.9D0, 0.8D0, 0.0D0, 0.0D0, - : 3.7D0, -0.3D0, 0.0D0, 0.0D0, - : 123.1D0, 0.4D0, -0.3D0, 0.0D0, - : -52.7D0, 15.3D0, 0.0D0, 0.0D0, - : 120.7D0, 0.3D0, -0.3D0, 0.0D0, - : 4.0D0, -0.3D0, 0.0D0, 0.0D0, - : 126.5D0, 0.5D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=61,70 ) / - : 112.7D0, 0.5D0, -0.3D0, 0.0D0, - : -106.1D0, -0.3D0, 0.3D0, 0.0D0, - : -112.9D0, -0.2D0, 0.0D0, 0.0D0, - : 3.6D0, -0.2D0, 0.0D0, 0.0D0, - : 107.4D0, 0.3D0, 0.0D0, 0.0D0, - : -10.9D0, 0.2D0, 0.0D0, 0.0D0, - : -0.9D0, 0.0D0, 0.0D0, 0.0D0, - : 85.4D0, 0.0D0, 0.0D0, 0.0D0, - : 0.0D0, -88.8D0, 0.0D0, 0.0D0, - : -71.0D0, -0.2D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=71,80 ) / - : -70.3D0, 0.0D0, 0.0D0, 0.0D0, - : 64.5D0, 0.4D0, 0.0D0, 0.0D0, - : 69.8D0, 0.0D0, 0.0D0, 0.0D0, - : 66.1D0, 0.4D0, 0.0D0, 0.0D0, - : -61.0D0, -0.2D0, 0.0D0, 0.0D0, - : -59.5D0, -0.1D0, 0.0D0, 0.0D0, - : -55.6D0, 0.0D0, 0.2D0, 0.0D0, - : 51.7D0, 0.2D0, 0.0D0, 0.0D0, - : -49.0D0, -0.1D0, 0.0D0, 0.0D0, - : -52.7D0, -0.1D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=81,90 ) / - : -49.6D0, 1.4D0, 0.0D0, 0.0D0, - : 46.3D0, 0.4D0, 0.0D0, 0.0D0, - : 49.6D0, 0.1D0, 0.0D0, 0.0D0, - : -5.1D0, 0.1D0, 0.0D0, 0.0D0, - : -44.0D0, -0.1D0, 0.0D0, 0.0D0, - : -39.9D0, -0.1D0, 0.0D0, 0.0D0, - : -39.5D0, -0.1D0, 0.0D0, 0.0D0, - : -3.9D0, 0.1D0, 0.0D0, 0.0D0, - : -42.1D0, -0.1D0, 0.0D0, 0.0D0, - : -17.2D0, 0.1D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=91,100 ) / - : -2.3D0, 0.1D0, 0.0D0, 0.0D0, - : -39.2D0, 0.0D0, 0.0D0, 0.0D0, - : -38.4D0, 0.1D0, 0.0D0, 0.0D0, - : 36.8D0, 0.2D0, 0.0D0, 0.0D0, - : 34.6D0, 0.1D0, 0.0D0, 0.0D0, - : -32.7D0, 0.3D0, 0.0D0, 0.0D0, - : 30.4D0, 0.0D0, 0.0D0, 0.0D0, - : 0.4D0, 0.1D0, 0.0D0, 0.0D0, - : 29.3D0, 0.2D0, 0.0D0, 0.0D0, - : 31.6D0, 0.1D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=101,110 ) / - : 0.8D0, -0.1D0, 0.0D0, 0.0D0, - : -27.9D0, 0.0D0, 0.0D0, 0.0D0, - : 2.9D0, 0.0D0, 0.0D0, 0.0D0, - : -25.3D0, 0.0D0, 0.0D0, 0.0D0, - : 25.0D0, 0.1D0, 0.0D0, 0.0D0, - : 27.5D0, 0.1D0, 0.0D0, 0.0D0, - : -24.4D0, -0.1D0, 0.0D0, 0.0D0, - : 24.9D0, 0.2D0, 0.0D0, 0.0D0, - : -22.8D0, -0.1D0, 0.0D0, 0.0D0, - : 0.9D0, -0.1D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=111,120 ) / - : 24.4D0, 0.1D0, 0.0D0, 0.0D0, - : 23.9D0, 0.1D0, 0.0D0, 0.0D0, - : 22.5D0, 0.1D0, 0.0D0, 0.0D0, - : 20.8D0, 0.1D0, 0.0D0, 0.0D0, - : 20.1D0, 0.0D0, 0.0D0, 0.0D0, - : 21.5D0, 0.1D0, 0.0D0, 0.0D0, - : -20.0D0, 0.0D0, 0.0D0, 0.0D0, - : 1.4D0, 0.0D0, 0.0D0, 0.0D0, - : -0.2D0, -0.1D0, 0.0D0, 0.0D0, - : 19.0D0, 0.0D0, -0.1D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=121,130 ) / - : 20.5D0, 0.0D0, 0.0D0, 0.0D0, - : -2.0D0, 0.0D0, 0.0D0, 0.0D0, - : -17.6D0, -0.1D0, 0.0D0, 0.0D0, - : 19.0D0, 0.0D0, 0.0D0, 0.0D0, - : -2.4D0, 0.0D0, 0.0D0, 0.0D0, - : -18.4D0, -0.1D0, 0.0D0, 0.0D0, - : 17.1D0, 0.0D0, 0.0D0, 0.0D0, - : 0.4D0, 0.0D0, 0.0D0, 0.0D0, - : 18.4D0, 0.1D0, 0.0D0, 0.0D0, - : 0.0D0, 17.4D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=131,140 ) / - : -0.6D0, 0.0D0, 0.0D0, 0.0D0, - : -15.4D0, 0.0D0, 0.0D0, 0.0D0, - : -16.8D0, -0.1D0, 0.0D0, 0.0D0, - : 16.3D0, 0.0D0, 0.0D0, 0.0D0, - : -2.0D0, 0.0D0, 0.0D0, 0.0D0, - : -1.5D0, 0.0D0, 0.0D0, 0.0D0, - : -14.3D0, -0.1D0, 0.0D0, 0.0D0, - : 14.4D0, 0.0D0, 0.0D0, 0.0D0, - : -13.4D0, 0.0D0, 0.0D0, 0.0D0, - : -14.3D0, -0.1D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=141,150 ) / - : -13.7D0, 0.0D0, 0.0D0, 0.0D0, - : 13.1D0, 0.1D0, 0.0D0, 0.0D0, - : -1.7D0, 0.0D0, 0.0D0, 0.0D0, - : -12.8D0, 0.0D0, 0.0D0, 0.0D0, - : 0.0D0, -14.4D0, 0.0D0, 0.0D0, - : 12.4D0, 0.0D0, 0.0D0, 0.0D0, - : -12.0D0, 0.0D0, 0.0D0, 0.0D0, - : -0.8D0, 0.0D0, 0.0D0, 0.0D0, - : 10.9D0, 0.1D0, 0.0D0, 0.0D0, - : -10.8D0, 0.0D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=151,160 ) / - : 10.5D0, 0.0D0, 0.0D0, 0.0D0, - : -10.4D0, 0.0D0, 0.0D0, 0.0D0, - : -11.2D0, 0.0D0, 0.0D0, 0.0D0, - : 10.5D0, 0.1D0, 0.0D0, 0.0D0, - : -1.4D0, 0.0D0, 0.0D0, 0.0D0, - : 0.0D0, 0.1D0, 0.0D0, 0.0D0, - : 0.7D0, 0.0D0, 0.0D0, 0.0D0, - : -10.3D0, 0.0D0, 0.0D0, 0.0D0, - : -10.0D0, 0.0D0, 0.0D0, 0.0D0, - : 9.6D0, 0.0D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=161,170 ) / - : 9.4D0, 0.1D0, 0.0D0, 0.0D0, - : 0.6D0, 0.0D0, 0.0D0, 0.0D0, - : -87.7D0, 4.4D0, -0.4D0, -6.3D0, - : 46.3D0, 22.4D0, 0.5D0, -2.4D0, - : 15.6D0, -3.4D0, 0.1D0, 0.4D0, - : 5.2D0, 5.8D0, 0.2D0, -0.1D0, - : -30.1D0, 26.9D0, 0.7D0, 0.0D0, - : 23.2D0, -0.5D0, 0.0D0, 0.6D0, - : 1.0D0, 23.2D0, 3.4D0, 0.0D0, - : -12.2D0, -4.3D0, 0.0D0, 0.0D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=171,180 ) / - : -2.1D0, -3.7D0, -0.2D0, 0.1D0, - : -18.6D0, -3.8D0, -0.4D0, 1.8D0, - : 5.5D0, -18.7D0, -1.8D0, -0.5D0, - : -5.5D0, -18.7D0, 1.8D0, -0.5D0, - : 18.4D0, -3.6D0, 0.3D0, 0.9D0, - : -0.6D0, 1.3D0, 0.0D0, 0.0D0, - : -5.6D0, -19.5D0, 1.9D0, 0.0D0, - : 5.5D0, -19.1D0, -1.9D0, 0.0D0, - : -17.3D0, -0.8D0, 0.0D0, 0.9D0, - : -3.2D0, -8.3D0, -0.8D0, 0.3D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=181,190 ) / - : -0.1D0, 0.0D0, 0.0D0, 0.0D0, - : -5.4D0, 7.8D0, -0.3D0, 0.0D0, - : -14.8D0, 1.4D0, 0.0D0, 0.3D0, - : -3.8D0, 0.4D0, 0.0D0, -0.2D0, - : 12.6D0, 3.2D0, 0.5D0, -1.5D0, - : 0.1D0, 0.0D0, 0.0D0, 0.0D0, - : -13.6D0, 2.4D0, -0.1D0, 0.0D0, - : 0.9D0, 1.2D0, 0.0D0, 0.0D0, - : -11.9D0, -0.5D0, 0.0D0, 0.3D0, - : 0.4D0, 12.0D0, 0.3D0, -0.2D0 / - DATA ( ( EPS(I,J), I=1,4 ), J=191,NTERMS ) / - : 8.3D0, 6.1D0, -0.1D0, 0.1D0, - : 0.0D0, 0.0D0, 0.0D0, 0.0D0, - : 0.4D0, -10.8D0, 0.3D0, 0.0D0, - : 9.6D0, 2.2D0, 0.3D0, -1.2D0 / - - - -* Interval between fundamental epoch J2000.0 and given epoch (JC). - T = (DATE-DJM0)/DJC - -* Mean anomaly of the Moon. - EL = 134.96340251D0*DD2R+ - : MOD(T*(1717915923.2178D0+ - : T*( 31.8792D0+ - : T*( 0.051635D0+ - : T*( - 0.00024470D0)))),TURNAS)*DAS2R - -* Mean anomaly of the Sun. - ELP = 357.52910918D0*DD2R+ - : MOD(T*( 129596581.0481D0+ - : T*( - 0.5532D0+ - : T*( 0.000136D0+ - : T*( - 0.00001149D0)))),TURNAS)*DAS2R - -* Mean argument of the latitude of the Moon. - F = 93.27209062D0*DD2R+ - : MOD(T*(1739527262.8478D0+ - : T*( - 12.7512D0+ - : T*( - 0.001037D0+ - : T*( 0.00000417D0)))),TURNAS)*DAS2R - -* Mean elongation of the Moon from the Sun. - D = 297.85019547D0*DD2R+ - : MOD(T*(1602961601.2090D0+ - : T*( - 6.3706D0+ - : T*( 0.006539D0+ - : T*( - 0.00003169D0)))),TURNAS)*DAS2R - -* Mean longitude of the ascending node of the Moon. - OM = 125.04455501D0*DD2R+ - : MOD(T*( - 6962890.5431D0+ - : T*( 7.4722D0+ - : T*( 0.007702D0+ - : T*( - 0.00005939D0)))),TURNAS)*DAS2R - -* Mean longitude of Venus. - VE = 181.97980085D0*DD2R+MOD(210664136.433548D0*T,TURNAS)*DAS2R - -* Mean longitude of Mars. - MA = 355.43299958D0*DD2R+MOD( 68905077.493988D0*T,TURNAS)*DAS2R - -* Mean longitude of Jupiter. - JU = 34.35151874D0*DD2R+MOD( 10925660.377991D0*T,TURNAS)*DAS2R - -* Mean longitude of Saturn. - SA = 50.07744430D0*DD2R+MOD( 4399609.855732D0*T,TURNAS)*DAS2R - -* Geodesic nutation (Fukushima 1991) in microarcsec. - DP = -153.1D0*SIN(ELP)-1.9D0*SIN(2D0*ELP) - DE = 0D0 - -* Shirai & Fukushima (2001) nutation series. - DO J=NTERMS,1,-1 - THETA = DBLE(NA(1,J))*EL+ - : DBLE(NA(2,J))*ELP+ - : DBLE(NA(3,J))*F+ - : DBLE(NA(4,J))*D+ - : DBLE(NA(5,J))*OM+ - : DBLE(NA(6,J))*VE+ - : DBLE(NA(7,J))*MA+ - : DBLE(NA(8,J))*JU+ - : DBLE(NA(9,J))*SA - C = COS(THETA) - S = SIN(THETA) - DP = DP+(PSI(1,J)+PSI(3,J)*T)*C+(PSI(2,J)+PSI(4,J)*T)*S - DE = DE+(EPS(1,J)+EPS(3,J)*T)*C+(EPS(2,J)+EPS(4,J)*T)*S - END DO - -* Change of units, and addition of the precession correction. - DPSI = (DP*1D-6-0.042888D0-0.29856D0*T)*DAS2R - DEPS = (DE*1D-6-0.005171D0-0.02408D0*T)*DAS2R - -* Mean obliquity of date (Simon et al. 1994). - EPS0 = (84381.412D0+ - : (-46.80927D0+ - : (-0.000152D0+ - : (0.0019989D0+ - : (-0.00000051D0+ - : (-0.000000025D0)*T)*T)*T)*T)*T)*DAS2R - - END - SUBROUTINE sla_NUT (DATE, RMATN) -*+ -* - - - - -* N U T -* - - - - -* -* Form the matrix of nutation for a given date - Shirai & Fukushima -* 2001 theory (double precision) -* -* Reference: -* Shirai, T. & Fukushima, T., Astron.J. 121, 3270-3283 (2001). -* -* Given: -* DATE d TDB (loosely ET) as Modified Julian Date -* (=JD-2400000.5) -* Returned: -* RMATN d(3,3) nutation matrix -* -* Notes: -* -* 1 The matrix is in the sense v(true) = rmatn * v(mean) . -* where v(true) is the star vector relative to the true equator and -* equinox of date and v(mean) is the star vector relative to the -* mean equator and equinox of date. -* -* 2 The matrix represents forced nutation (but not free core -* nutation) plus corrections to the IAU~1976 precession model. -* -* 3 Earth attitude predictions made by combining the present nutation -* matrix with IAU~1976 precession are accurate to 1~mas (with -* respect to the ICRS) for a few decades around 2000. -* -* 4 The distinction between the required TDB and TT is always -* negligible. Moreover, for all but the most critical applications -* UTC is adequate. -* -* Called: sla_NUTC, sla_DEULER -* -* Last revision: 1 December 2005 -* -* Copyright P.T.Wallace. All rights reserved. -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION DATE,RMATN(3,3) - - DOUBLE PRECISION DPSI,DEPS,EPS0 - - - -* Nutation components and mean obliquity - CALL sla_NUTC(DATE,DPSI,DEPS,EPS0) - -* Rotation matrix - CALL sla_DEULER('XZX',EPS0,-DPSI,-(EPS0+DEPS),RMATN) - - END - SUBROUTINE sla_PREBN (BEP0, BEP1, RMATP) -*+ -* - - - - - - -* P R E B N -* - - - - - - -* -* Generate the matrix of precession between two epochs, -* using the old, pre-IAU1976, Bessel-Newcomb model, using -* Kinoshita's formulation (double precision) -* -* Given: -* BEP0 dp beginning Besselian epoch -* BEP1 dp ending Besselian epoch -* -* Returned: -* RMATP dp(3,3) precession matrix -* -* The matrix is in the sense V(BEP1) = RMATP * V(BEP0) -* -* Reference: -* Kinoshita, H. (1975) 'Formulas for precession', SAO Special -* Report No. 364, Smithsonian Institution Astrophysical -* Observatory, Cambridge, Massachusetts. -* -* Called: sla_DEULER -* -* P.T.Wallace Starlink 23 August 1996 -* -* Copyright (C) 1996 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION BEP0,BEP1,RMATP(3,3) - -* Arc seconds to radians - DOUBLE PRECISION AS2R - PARAMETER (AS2R=0.484813681109535994D-5) - - DOUBLE PRECISION BIGT,T,TAS2R,W,ZETA,Z,THETA - - - -* Interval between basic epoch B1850.0 and beginning epoch in TC - BIGT = (BEP0-1850D0)/100D0 - -* Interval over which precession required, in tropical centuries - T = (BEP1-BEP0)/100D0 - -* Euler angles - TAS2R = T*AS2R - W = 2303.5548D0+(1.39720D0+0.000059D0*BIGT)*BIGT - - ZETA = (W+(0.30242D0-0.000269D0*BIGT+0.017996D0*T)*T)*TAS2R - Z = (W+(1.09478D0+0.000387D0*BIGT+0.018324D0*T)*T)*TAS2R - THETA = (2005.1125D0+(-0.85294D0-0.000365D0*BIGT)*BIGT+ - : (-0.42647D0-0.000365D0*BIGT-0.041802D0*T)*T)*TAS2R - -* Rotation matrix - CALL sla_DEULER('ZYZ',-ZETA,THETA,-Z,RMATP) - - END - SUBROUTINE sla_PRECES (SYSTEM, EP0, EP1, RA, DC) -*+ -* - - - - - - - -* P R E C E S -* - - - - - - - -* -* Precession - either FK4 (Bessel-Newcomb, pre IAU 1976) or -* FK5 (Fricke, post IAU 1976) as required. -* -* Given: -* SYSTEM char precession to be applied: 'FK4' or 'FK5' -* EP0,EP1 dp starting and ending epoch -* RA,DC dp RA,Dec, mean equator & equinox of epoch EP0 -* -* Returned: -* RA,DC dp RA,Dec, mean equator & equinox of epoch EP1 -* -* Called: sla_DRANRM, sla_PREBN, sla_PREC, sla_DCS2C, -* sla_DMXV, sla_DCC2S -* -* Notes: -* -* 1) Lowercase characters in SYSTEM are acceptable. -* -* 2) The epochs are Besselian if SYSTEM='FK4' and Julian if 'FK5'. -* For example, to precess coordinates in the old system from -* equinox 1900.0 to 1950.0 the call would be: -* CALL sla_PRECES ('FK4', 1900D0, 1950D0, RA, DC) -* -* 3) This routine will NOT correctly convert between the old and -* the new systems - for example conversion from B1950 to J2000. -* For these purposes see sla_FK425, sla_FK524, sla_FK45Z and -* sla_FK54Z. -* -* 4) If an invalid SYSTEM is supplied, values of -99D0,-99D0 will -* be returned for both RA and DC. -* -* P.T.Wallace Starlink 20 April 1990 -* -* Copyright (C) 1995 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - CHARACTER SYSTEM*(*) - DOUBLE PRECISION EP0,EP1,RA,DC - - DOUBLE PRECISION PM(3,3),V1(3),V2(3) - CHARACTER SYSUC*3 - - DOUBLE PRECISION sla_DRANRM - - - - -* Convert to uppercase and validate SYSTEM - SYSUC=SYSTEM - IF (SYSUC(1:1).EQ.'f') SYSUC(1:1)='F' - IF (SYSUC(2:2).EQ.'k') SYSUC(2:2)='K' - IF (SYSUC.NE.'FK4'.AND.SYSUC.NE.'FK5') THEN - RA=-99D0 - DC=-99D0 - ELSE - -* Generate appropriate precession matrix - IF (SYSUC.EQ.'FK4') THEN - CALL sla_PREBN(EP0,EP1,PM) - ELSE - CALL sla_PREC(EP0,EP1,PM) - END IF - -* Convert RA,Dec to x,y,z - CALL sla_DCS2C(RA,DC,V1) - -* Precess - CALL sla_DMXV(PM,V1,V2) - -* Back to RA,Dec - CALL sla_DCC2S(V2,RA,DC) - RA=sla_DRANRM(RA) - - END IF - - END - SUBROUTINE sla_PREC (EP0, EP1, RMATP) -*+ -* - - - - - -* P R E C -* - - - - - -* -* Form the matrix of precession between two epochs (IAU 1976, FK5) -* (double precision) -* -* Given: -* EP0 dp beginning epoch -* EP1 dp ending epoch -* -* Returned: -* RMATP dp(3,3) precession matrix -* -* Notes: -* -* 1) The epochs are TDB (loosely ET) Julian epochs. -* -* 2) The matrix is in the sense V(EP1) = RMATP * V(EP0) -* -* 3) Though the matrix method itself is rigorous, the precession -* angles are expressed through canonical polynomials which are -* valid only for a limited time span. There are also known -* errors in the IAU precession rate. The absolute accuracy -* of the present formulation is better than 0.1 arcsec from -* 1960AD to 2040AD, better than 1 arcsec from 1640AD to 2360AD, -* and remains below 3 arcsec for the whole of the period -* 500BC to 3000AD. The errors exceed 10 arcsec outside the -* range 1200BC to 3900AD, exceed 100 arcsec outside 4200BC to -* 5600AD and exceed 1000 arcsec outside 6800BC to 8200AD. -* The SLALIB routine sla_PRECL implements a more elaborate -* model which is suitable for problems spanning several -* thousand years. -* -* References: -* Lieske,J.H., 1979. Astron.Astrophys.,73,282. -* equations (6) & (7), p283. -* Kaplan,G.H., 1981. USNO circular no. 163, pA2. -* -* Called: sla_DEULER -* -* P.T.Wallace Starlink 23 August 1996 -* -* Copyright (C) 1996 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION EP0,EP1,RMATP(3,3) - -* Arc seconds to radians - DOUBLE PRECISION AS2R - PARAMETER (AS2R=0.484813681109535994D-5) - - DOUBLE PRECISION T0,T,TAS2R,W,ZETA,Z,THETA - - - -* Interval between basic epoch J2000.0 and beginning epoch (JC) - T0 = (EP0-2000D0)/100D0 - -* Interval over which precession required (JC) - T = (EP1-EP0)/100D0 - -* Euler angles - TAS2R = T*AS2R - W = 2306.2181D0+(1.39656D0-0.000139D0*T0)*T0 - - ZETA = (W+((0.30188D0-0.000344D0*T0)+0.017998D0*T)*T)*TAS2R - Z = (W+((1.09468D0+0.000066D0*T0)+0.018203D0*T)*T)*TAS2R - THETA = ((2004.3109D0+(-0.85330D0-0.000217D0*T0)*T0) - : +((-0.42665D0-0.000217D0*T0)-0.041833D0*T)*T)*TAS2R - -* Rotation matrix - CALL sla_DEULER('ZYZ',-ZETA,THETA,-Z,RMATP) - - END - SUBROUTINE sla_PVOBS (P, H, STL, PV) -*+ -* - - - - - - -* P V O B S -* - - - - - - -* -* Position and velocity of an observing station (double precision) -* -* Given: -* P dp latitude (geodetic, radians) -* H dp height above reference spheroid (geodetic, metres) -* STL dp local apparent sidereal time (radians) -* -* Returned: -* PV dp(6) position/velocity 6-vector (AU, AU/s, true equator -* and equinox of date) -* -* Called: sla_GEOC -* -* IAU 1976 constants are used. -* -* P.T.Wallace Starlink 14 November 1994 -* -* Copyright (C) 1995 Rutherford Appleton Laboratory -* -* License: -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program (see SLA_CONDITIONS); if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -*- - - IMPLICIT NONE - - DOUBLE PRECISION P,H,STL,PV(6) - - DOUBLE PRECISION R,Z,S,C,V - -* Mean sidereal rate (at J2000) in radians per (UT1) second - DOUBLE PRECISION SR - PARAMETER (SR=7.292115855306589D-5) - - - -* Geodetic to geocentric conversion - CALL sla_GEOC(P,H,R,Z) - -* Functions of ST - S=SIN(STL) - C=COS(STL) - -* Speed - V=SR*R - -* Position - PV(1)=R*C - PV(2)=R*S - PV(3)=Z - -* Velocity - PV(4)=-V*S - PV(5)=V*C - PV(6)=0D0 - - END + SUBROUTINE sla_CLDJ (IY, IM, ID, DJM, J) +*+ +* - - - - - +* C L D J +* - - - - - +* +* Gregorian Calendar to Modified Julian Date +* +* Given: +* IY,IM,ID int year, month, day in Gregorian calendar +* +* Returned: +* DJM dp modified Julian Date (JD-2400000.5) for 0 hrs +* J int status: +* 0 = OK +* 1 = bad year (MJD not computed) +* 2 = bad month (MJD not computed) +* 3 = bad day (MJD computed) +* +* The year must be -4699 (i.e. 4700BC) or later. +* +* The algorithm is adapted from Hatcher 1984 (QJRAS 25, 53-55). +* +* Last revision: 27 July 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + INTEGER IY,IM,ID + DOUBLE PRECISION DJM + INTEGER J + +* Month lengths in days + INTEGER MTAB(12) + DATA MTAB / 31,28,31,30,31,30,31,31,30,31,30,31 / + + + +* Preset status. + J = 0 + +* Validate year. + IF ( IY .LT. -4699 ) THEN + J = 1 + ELSE + +* Validate month. + IF ( IM.GE.1 .AND. IM.LE.12 ) THEN + +* Allow for leap year. + IF ( MOD(IY,4) .EQ. 0 ) THEN + MTAB(2) = 29 + ELSE + MTAB(2) = 28 + END IF + IF ( MOD(IY,100).EQ.0 .AND. MOD(IY,400).NE.0 ) + : MTAB(2) = 28 + +* Validate day. + IF ( ID.LT.1 .OR. ID.GT.MTAB(IM) ) J=3 + +* Modified Julian Date. + DJM = DBLE ( ( 1461 * ( IY - (12-IM)/10 + 4712 ) ) / 4 + : + ( 306 * MOD ( IM+9, 12 ) + 5 ) / 10 + : - ( 3 * ( ( IY - (12-IM)/10 + 4900 ) / 100 ) ) / 4 + : + ID - 2399904 ) + +* Bad month. + ELSE + J=2 + END IF + + END IF + + END + DOUBLE PRECISION FUNCTION sla_DAT (UTC) +*+ +* - - - - +* D A T +* - - - - +* +* Increment to be applied to Coordinated Universal Time UTC to give +* International Atomic Time TAI (double precision) +* +* Given: +* UTC d UTC date as a modified JD (JD-2400000.5) +* +* Result: TAI-UTC in seconds +* +* Notes: +* +* 1 The UTC is specified to be a date rather than a time to indicate +* that care needs to be taken not to specify an instant which lies +* within a leap second. Though in most cases UTC can include the +* fractional part, correct behaviour on the day of a leap second +* can only be guaranteed up to the end of the second 23:59:59. +* +* 2 For epochs from 1961 January 1 onwards, the expressions from the +* file ftp://maia.usno.navy.mil/ser7/tai-utc.dat are used. +* +* 3 The 5ms time step at 1961 January 1 is taken from 2.58.1 (p87) of +* the 1992 Explanatory Supplement. +* +* 4 UTC began at 1960 January 1.0 (JD 2436934.5) and it is improper +* to call the routine with an earlier epoch. However, if this +* is attempted, the TAI-UTC expression for the year 1960 is used. +* +* +* :-----------------------------------------: +* : : +* : IMPORTANT : +* : : +* : This routine must be updated on each : +* : occasion that a leap second is : +* : announced : +* : : +* : Latest leap second: 2015 July 1 : +* : : +* :-----------------------------------------: +* +* Last revision: 5 July 2008 +* +* Copyright P.T.Wallace. All rights reserved. +*- + + IMPLICIT NONE + + DOUBLE PRECISION UTC + + DOUBLE PRECISION DT + + + + IF (.FALSE.) THEN + +* - - - - - - - - - - - - - - - - - - - - - - * +* Add new code here on each occasion that a * +* leap second is announced, and update the * +* preamble comments appropriately. * +* - - - - - - - - - - - - - - - - - - - - - - * + +* 2017 January 1 + ELSE IF (UTC.GE.57754D0) THEN + DT=37D0 + +* 2015 July 1 + ELSE IF (UTC.GE.57204D0) THEN + DT=36D0 + +* 2012 July 1 + ELSE IF (UTC.GE.56109D0) THEN + DT=35D0 + +* 2009 January 1 + ELSE IF (UTC.GE.54832D0) THEN + DT=34D0 + +* 2006 January 1 + ELSE IF (UTC.GE.53736D0) THEN + DT=33D0 + +* 1999 January 1 + ELSE IF (UTC.GE.51179D0) THEN + DT=32D0 + +* 1997 July 1 + ELSE IF (UTC.GE.50630D0) THEN + DT=31D0 + +* 1996 January 1 + ELSE IF (UTC.GE.50083D0) THEN + DT=30D0 + +* 1994 July 1 + ELSE IF (UTC.GE.49534D0) THEN + DT=29D0 + +* 1993 July 1 + ELSE IF (UTC.GE.49169D0) THEN + DT=28D0 + +* 1992 July 1 + ELSE IF (UTC.GE.48804D0) THEN + DT=27D0 + +* 1991 January 1 + ELSE IF (UTC.GE.48257D0) THEN + DT=26D0 + +* 1990 January 1 + ELSE IF (UTC.GE.47892D0) THEN + DT=25D0 + +* 1988 January 1 + ELSE IF (UTC.GE.47161D0) THEN + DT=24D0 + +* 1985 July 1 + ELSE IF (UTC.GE.46247D0) THEN + DT=23D0 + +* 1983 July 1 + ELSE IF (UTC.GE.45516D0) THEN + DT=22D0 + +* 1982 July 1 + ELSE IF (UTC.GE.45151D0) THEN + DT=21D0 + +* 1981 July 1 + ELSE IF (UTC.GE.44786D0) THEN + DT=20D0 + +* 1980 January 1 + ELSE IF (UTC.GE.44239D0) THEN + DT=19D0 + +* 1979 January 1 + ELSE IF (UTC.GE.43874D0) THEN + DT=18D0 + +* 1978 January 1 + ELSE IF (UTC.GE.43509D0) THEN + DT=17D0 + +* 1977 January 1 + ELSE IF (UTC.GE.43144D0) THEN + DT=16D0 + +* 1976 January 1 + ELSE IF (UTC.GE.42778D0) THEN + DT=15D0 + +* 1975 January 1 + ELSE IF (UTC.GE.42413D0) THEN + DT=14D0 + +* 1974 January 1 + ELSE IF (UTC.GE.42048D0) THEN + DT=13D0 + +* 1973 January 1 + ELSE IF (UTC.GE.41683D0) THEN + DT=12D0 + +* 1972 July 1 + ELSE IF (UTC.GE.41499D0) THEN + DT=11D0 + +* 1972 January 1 + ELSE IF (UTC.GE.41317D0) THEN + DT=10D0 + +* 1968 February 1 + ELSE IF (UTC.GE.39887D0) THEN + DT=4.2131700D0+(UTC-39126D0)*0.002592D0 + +* 1966 January 1 + ELSE IF (UTC.GE.39126D0) THEN + DT=4.3131700D0+(UTC-39126D0)*0.002592D0 + +* 1965 September 1 + ELSE IF (UTC.GE.39004D0) THEN + DT=3.8401300D0+(UTC-38761D0)*0.001296D0 + +* 1965 July 1 + ELSE IF (UTC.GE.38942D0) THEN + DT=3.7401300D0+(UTC-38761D0)*0.001296D0 + +* 1965 March 1 + ELSE IF (UTC.GE.38820D0) THEN + DT=3.6401300D0+(UTC-38761D0)*0.001296D0 + +* 1965 January 1 + ELSE IF (UTC.GE.38761D0) THEN + DT=3.5401300D0+(UTC-38761D0)*0.001296D0 + +* 1964 September 1 + ELSE IF (UTC.GE.38639D0) THEN + DT=3.4401300D0+(UTC-38761D0)*0.001296D0 + +* 1964 April 1 + ELSE IF (UTC.GE.38486D0) THEN + DT=3.3401300D0+(UTC-38761D0)*0.001296D0 + +* 1964 January 1 + ELSE IF (UTC.GE.38395D0) THEN + DT=3.2401300D0+(UTC-38761D0)*0.001296D0 + +* 1963 November 1 + ELSE IF (UTC.GE.38334D0) THEN + DT=1.9458580D0+(UTC-37665D0)*0.0011232D0 + +* 1962 January 1 + ELSE IF (UTC.GE.37665D0) THEN + DT=1.8458580D0+(UTC-37665D0)*0.0011232D0 + +* 1961 August 1 + ELSE IF (UTC.GE.37512D0) THEN + DT=1.3728180D0+(UTC-37300D0)*0.001296D0 + +* 1961 January 1 + ELSE IF (UTC.GE.37300D0) THEN + DT=1.4228180D0+(UTC-37300D0)*0.001296D0 + +* Before that + ELSE + DT=1.4178180D0+(UTC-37300D0)*0.001296D0 + + END IF + + sla_DAT=DT + + END + SUBROUTINE sla_DC62S (V, A, B, R, AD, BD, RD) +*+ +* - - - - - - +* D C 6 2 S +* - - - - - - +* +* Conversion of position & velocity in Cartesian coordinates +* to spherical coordinates (double precision) +* +* Given: +* V d(6) Cartesian position & velocity vector +* +* Returned: +* A d longitude (radians) +* B d latitude (radians) +* R d radial coordinate +* AD d longitude derivative (radians per unit time) +* BD d latitude derivative (radians per unit time) +* RD d radial derivative +* +* P.T.Wallace Starlink 28 April 1996 +* +* Copyright (C) 1996 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION V(6),A,B,R,AD,BD,RD + + DOUBLE PRECISION X,Y,Z,XD,YD,ZD,RXY2,RXY,R2,XYP + + + +* Components of position/velocity vector + X=V(1) + Y=V(2) + Z=V(3) + XD=V(4) + YD=V(5) + ZD=V(6) + +* Component of R in XY plane squared + RXY2=X*X+Y*Y + +* Modulus squared + R2=RXY2+Z*Z + +* Protection against null vector + IF (R2.EQ.0D0) THEN + X=XD + Y=YD + Z=ZD + RXY2=X*X+Y*Y + R2=RXY2+Z*Z + END IF + +* Position and velocity in spherical coordinates + RXY=SQRT(RXY2) + XYP=X*XD+Y*YD + IF (RXY2.NE.0D0) THEN + A=ATAN2(Y,X) + B=ATAN2(Z,RXY) + AD=(X*YD-Y*XD)/RXY2 + BD=(ZD*RXY2-Z*XYP)/(R2*RXY) + ELSE + A=0D0 + IF (Z.NE.0D0) THEN + B=ATAN2(Z,RXY) + ELSE + B=0D0 + END IF + AD=0D0 + BD=0D0 + END IF + R=SQRT(R2) + IF (R.NE.0D0) THEN + RD=(XYP+Z*ZD)/R + ELSE + RD=0D0 + END IF + + END + SUBROUTINE sla_DCC2S (V, A, B) +*+ +* - - - - - - +* D C C 2 S +* - - - - - - +* +* Cartesian to spherical coordinates (double precision) +* +* Given: +* V d(3) x,y,z vector +* +* Returned: +* A,B d spherical coordinates in radians +* +* The spherical coordinates are longitude (+ve anticlockwise looking +* from the +ve latitude pole) and latitude. The Cartesian coordinates +* are right handed, with the x axis at zero longitude and latitude, and +* the z axis at the +ve latitude pole. +* +* If V is null, zero A and B are returned. At either pole, zero A is +* returned. +* +* Last revision: 22 July 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION V(3),A,B + + DOUBLE PRECISION X,Y,Z,R + + + X = V(1) + Y = V(2) + Z = V(3) + R = SQRT(X*X+Y*Y) + + IF (R.EQ.0D0) THEN + A = 0D0 + ELSE + A = ATAN2(Y,X) + END IF + + IF (Z.EQ.0D0) THEN + B = 0D0 + ELSE + B = ATAN2(Z,R) + END IF + + END + SUBROUTINE sla_DCS2C (A, B, V) +*+ +* - - - - - - +* D C S 2 C +* - - - - - - +* +* Spherical coordinates to direction cosines (double precision) +* +* Given: +* A,B d spherical coordinates in radians +* (RA,Dec), (long,lat) etc. +* +* Returned: +* V d(3) x,y,z unit vector +* +* The spherical coordinates are longitude (+ve anticlockwise looking +* from the +ve latitude pole) and latitude. The Cartesian coordinates +* are right handed, with the x axis at zero longitude and latitude, and +* the z axis at the +ve latitude pole. +* +* Last revision: 26 December 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION A,B,V(3) + + DOUBLE PRECISION COSB + + + COSB = COS(B) + + V(1) = COS(A)*COSB + V(2) = SIN(A)*COSB + V(3) = SIN(B) + + END + SUBROUTINE sla_DE2H (HA, DEC, PHI, AZ, EL) +*+ +* - - - - - +* D E 2 H +* - - - - - +* +* Equatorial to horizon coordinates: HA,Dec to Az,El +* +* (double precision) +* +* Given: +* HA d hour angle +* DEC d declination +* PHI d observatory latitude +* +* Returned: +* AZ d azimuth +* EL d elevation +* +* Notes: +* +* 1) All the arguments are angles in radians. +* +* 2) Azimuth is returned in the range 0-2pi; north is zero, +* and east is +pi/2. Elevation is returned in the range +* +/-pi/2. +* +* 3) The latitude must be geodetic. In critical applications, +* corrections for polar motion should be applied. +* +* 4) In some applications it will be important to specify the +* correct type of hour angle and declination in order to +* produce the required type of azimuth and elevation. In +* particular, it may be important to distinguish between +* elevation as affected by refraction, which would +* require the "observed" HA,Dec, and the elevation +* in vacuo, which would require the "topocentric" HA,Dec. +* If the effects of diurnal aberration can be neglected, the +* "apparent" HA,Dec may be used instead of the topocentric +* HA,Dec. +* +* 5) No range checking of arguments is carried out. +* +* 6) In applications which involve many such calculations, rather +* than calling the present routine it will be more efficient to +* use inline code, having previously computed fixed terms such +* as sine and cosine of latitude, and (for tracking a star) +* sine and cosine of declination. +* +* P.T.Wallace Starlink 9 July 1994 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION HA,DEC,PHI,AZ,EL + + DOUBLE PRECISION D2PI + PARAMETER (D2PI=6.283185307179586476925286766559D0) + + DOUBLE PRECISION SH,CH,SD,CD,SP,CP,X,Y,Z,R,A + + +* Useful trig functions + SH=SIN(HA) + CH=COS(HA) + SD=SIN(DEC) + CD=COS(DEC) + SP=SIN(PHI) + CP=COS(PHI) + +* Az,El as x,y,z + X=-CH*CD*SP+SD*CP + Y=-SH*CD + Z=CH*CD*CP+SD*SP + +* To spherical + R=SQRT(X*X+Y*Y) + IF (R.EQ.0D0) THEN + A=0D0 + ELSE + A=ATAN2(Y,X) + END IF + IF (A.LT.0D0) A=A+D2PI + AZ=A + EL=ATAN2(Z,R) + + END + SUBROUTINE sla_DEULER (ORDER, PHI, THETA, PSI, RMAT) +*+ +* - - - - - - - +* D E U L E R +* - - - - - - - +* +* Form a rotation matrix from the Euler angles - three successive +* rotations about specified Cartesian axes (double precision) +* +* Given: +* ORDER c*(*) specifies about which axes the rotations occur +* PHI d 1st rotation (radians) +* THETA d 2nd rotation ( " ) +* PSI d 3rd rotation ( " ) +* +* Returned: +* RMAT d(3,3) rotation matrix +* +* A rotation is positive when the reference frame rotates +* anticlockwise as seen looking towards the origin from the +* positive region of the specified axis. +* +* The characters of ORDER define which axes the three successive +* rotations are about. A typical value is 'ZXZ', indicating that +* RMAT is to become the direction cosine matrix corresponding to +* rotations of the reference frame through PHI radians about the +* old Z-axis, followed by THETA radians about the resulting X-axis, +* then PSI radians about the resulting Z-axis. +* +* The axis names can be any of the following, in any order or +* combination: X, Y, Z, uppercase or lowercase, 1, 2, 3. Normal +* axis labelling/numbering conventions apply; the xyz (=123) +* triad is right-handed. Thus, the 'ZXZ' example given above +* could be written 'zxz' or '313' (or even 'ZxZ' or '3xZ'). ORDER +* is terminated by length or by the first unrecognized character. +* +* Fewer than three rotations are acceptable, in which case the later +* angle arguments are ignored. If all rotations are zero, the +* identity matrix is produced. +* +* P.T.Wallace Starlink 23 May 1997 +* +* Copyright (C) 1997 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + CHARACTER*(*) ORDER + DOUBLE PRECISION PHI,THETA,PSI,RMAT(3,3) + + INTEGER J,I,L,N,K + DOUBLE PRECISION RESULT(3,3),ROTN(3,3),ANGLE,S,C,W,WM(3,3) + CHARACTER AXIS + + + +* Initialize result matrix + DO J=1,3 + DO I=1,3 + IF (I.NE.J) THEN + RESULT(I,J) = 0D0 + ELSE + RESULT(I,J) = 1D0 + END IF + END DO + END DO + +* Establish length of axis string + L = LEN(ORDER) + +* Look at each character of axis string until finished + DO N=1,3 + IF (N.LE.L) THEN + +* Initialize rotation matrix for the current rotation + DO J=1,3 + DO I=1,3 + IF (I.NE.J) THEN + ROTN(I,J) = 0D0 + ELSE + ROTN(I,J) = 1D0 + END IF + END DO + END DO + +* Pick up the appropriate Euler angle and take sine & cosine + IF (N.EQ.1) THEN + ANGLE = PHI + ELSE IF (N.EQ.2) THEN + ANGLE = THETA + ELSE + ANGLE = PSI + END IF + S = SIN(ANGLE) + C = COS(ANGLE) + +* Identify the axis + AXIS = ORDER(N:N) + IF (AXIS.EQ.'X'.OR. + : AXIS.EQ.'x'.OR. + : AXIS.EQ.'1') THEN + +* Matrix for x-rotation + ROTN(2,2) = C + ROTN(2,3) = S + ROTN(3,2) = -S + ROTN(3,3) = C + + ELSE IF (AXIS.EQ.'Y'.OR. + : AXIS.EQ.'y'.OR. + : AXIS.EQ.'2') THEN + +* Matrix for y-rotation + ROTN(1,1) = C + ROTN(1,3) = -S + ROTN(3,1) = S + ROTN(3,3) = C + + ELSE IF (AXIS.EQ.'Z'.OR. + : AXIS.EQ.'z'.OR. + : AXIS.EQ.'3') THEN + +* Matrix for z-rotation + ROTN(1,1) = C + ROTN(1,2) = S + ROTN(2,1) = -S + ROTN(2,2) = C + + ELSE + +* Unrecognized character - fake end of string + L = 0 + + END IF + +* Apply the current rotation (matrix ROTN x matrix RESULT) + DO I=1,3 + DO J=1,3 + W = 0D0 + DO K=1,3 + W = W+ROTN(I,K)*RESULT(K,J) + END DO + WM(I,J) = W + END DO + END DO + DO J=1,3 + DO I=1,3 + RESULT(I,J) = WM(I,J) + END DO + END DO + + END IF + + END DO + +* Copy the result + DO J=1,3 + DO I=1,3 + RMAT(I,J) = RESULT(I,J) + END DO + END DO + + END + SUBROUTINE sla_DMOON (DATE, PV) +*+ +* - - - - - - +* D M O O N +* - - - - - - +* +* Approximate geocentric position and velocity of the Moon +* (double precision) +* +* Given: +* DATE D TDB (loosely ET) as a Modified Julian Date +* (JD-2400000.5) +* +* Returned: +* PV D(6) Moon x,y,z,xdot,ydot,zdot, mean equator and +* equinox of date (AU, AU/s) +* +* Notes: +* +* 1 This routine is a full implementation of the algorithm +* published by Meeus (see reference). +* +* 2 Meeus quotes accuracies of 10 arcsec in longitude, 3 arcsec in +* latitude and 0.2 arcsec in HP (equivalent to about 20 km in +* distance). Comparison with JPL DE200 over the interval +* 1960-2025 gives RMS errors of 3.7 arcsec and 83 mas/hour in +* longitude, 2.3 arcsec and 48 mas/hour in latitude, 11 km +* and 81 mm/s in distance. The maximum errors over the same +* interval are 18 arcsec and 0.50 arcsec/hour in longitude, +* 11 arcsec and 0.24 arcsec/hour in latitude, 40 km and 0.29 m/s +* in distance. +* +* 3 The original algorithm is expressed in terms of the obsolete +* timescale Ephemeris Time. Either TDB or TT can be used, but +* not UT without incurring significant errors (30 arcsec at +* the present time) due to the Moon's 0.5 arcsec/sec movement. +* +* 4 The algorithm is based on pre IAU 1976 standards. However, +* the result has been moved onto the new (FK5) equinox, an +* adjustment which is in any case much smaller than the +* intrinsic accuracy of the procedure. +* +* 5 Velocity is obtained by a complete analytical differentiation +* of the Meeus model. +* +* Reference: +* Meeus, l'Astronomie, June 1984, p348. +* +* P.T.Wallace Starlink 22 January 1998 +* +* Copyright (C) 1998 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE,PV(6) + +* Degrees, arcseconds and seconds of time to radians + DOUBLE PRECISION D2R,DAS2R,DS2R + PARAMETER (D2R=0.0174532925199432957692369D0, + : DAS2R=4.848136811095359935899141D-6, + : DS2R=7.272205216643039903848712D-5) + +* Seconds per Julian century (86400*36525) + DOUBLE PRECISION CJ + PARAMETER (CJ=3155760000D0) + +* Julian epoch of B1950 + DOUBLE PRECISION B1950 + PARAMETER (B1950=1949.9997904423D0) + +* Earth equatorial radius in AU ( = 6378.137 / 149597870 ) + DOUBLE PRECISION ERADAU + PARAMETER (ERADAU=4.2635212653763D-5) + + DOUBLE PRECISION T,THETA,SINOM,COSOM,DOMCOM,WA,DWA,WB,DWB,WOM, + : DWOM,SINWOM,COSWOM,V,DV,COEFF,EMN,EMPN,DN,FN,EN, + : DEN,DTHETA,FTHETA,EL,DEL,B,DB,BF,DBF,P,DP,SP,R, + : DR,X,Y,Z,XD,YD,ZD,SEL,CEL,SB,CB,RCB,RBD,W,EPJ, + : EQCOR,EPS,SINEPS,COSEPS,ES,EC + INTEGER N,I + +* +* Coefficients for fundamental arguments +* +* at J1900: T**0, T**1, T**2, T**3 +* at epoch: T**0, T**1 +* +* Units are degrees for position and Julian centuries for time +* + +* Moon's mean longitude + DOUBLE PRECISION ELP0,ELP1,ELP2,ELP3,ELP,DELP + PARAMETER (ELP0=270.434164D0, + : ELP1=481267.8831D0, + : ELP2=-0.001133D0, + : ELP3=0.0000019D0) + +* Sun's mean anomaly + DOUBLE PRECISION EM0,EM1,EM2,EM3,EM,DEM + PARAMETER (EM0=358.475833D0, + : EM1=35999.0498D0, + : EM2=-0.000150D0, + : EM3=-0.0000033D0) + +* Moon's mean anomaly + DOUBLE PRECISION EMP0,EMP1,EMP2,EMP3,EMP,DEMP + PARAMETER (EMP0=296.104608D0, + : EMP1=477198.8491D0, + : EMP2=0.009192D0, + : EMP3=0.0000144D0) + +* Moon's mean elongation + DOUBLE PRECISION D0,D1,D2,D3,D,DD + PARAMETER (D0=350.737486D0, + : D1=445267.1142D0, + : D2=-0.001436D0, + : D3=0.0000019D0) + +* Mean distance of the Moon from its ascending node + DOUBLE PRECISION F0,F1,F2,F3,F,DF + PARAMETER (F0=11.250889D0, + : F1=483202.0251D0, + : F2=-0.003211D0, + : F3=-0.0000003D0) + +* Longitude of the Moon's ascending node + DOUBLE PRECISION OM0,OM1,OM2,OM3,OM,DOM + PARAMETER (OM0=259.183275D0, + : OM1=-1934.1420D0, + : OM2=0.002078D0, + : OM3=0.0000022D0) + +* Coefficients for (dimensionless) E factor + DOUBLE PRECISION E1,E2,E,DE,ESQ,DESQ + PARAMETER (E1=-0.002495D0,E2=-0.00000752D0) + +* Coefficients for periodic variations etc + DOUBLE PRECISION PAC,PA0,PA1 + PARAMETER (PAC=0.000233D0,PA0=51.2D0,PA1=20.2D0) + DOUBLE PRECISION PBC + PARAMETER (PBC=-0.001778D0) + DOUBLE PRECISION PCC + PARAMETER (PCC=0.000817D0) + DOUBLE PRECISION PDC + PARAMETER (PDC=0.002011D0) + DOUBLE PRECISION PEC,PE0,PE1,PE2 + PARAMETER (PEC=0.003964D0, + : PE0=346.560D0,PE1=132.870D0,PE2=-0.0091731D0) + DOUBLE PRECISION PFC + PARAMETER (PFC=0.001964D0) + DOUBLE PRECISION PGC + PARAMETER (PGC=0.002541D0) + DOUBLE PRECISION PHC + PARAMETER (PHC=0.001964D0) + DOUBLE PRECISION PIC + PARAMETER (PIC=-0.024691D0) + DOUBLE PRECISION PJC,PJ0,PJ1 + PARAMETER (PJC=-0.004328D0,PJ0=275.05D0,PJ1=-2.30D0) + DOUBLE PRECISION CW1 + PARAMETER (CW1=0.0004664D0) + DOUBLE PRECISION CW2 + PARAMETER (CW2=0.0000754D0) + +* +* Coefficients for Moon position +* +* Tx(N) = coefficient of L, B or P term (deg) +* ITx(N,1-5) = coefficients of M, M', D, F, E**n in argument +* + INTEGER NL,NB,NP + PARAMETER (NL=50,NB=45,NP=31) + DOUBLE PRECISION TL(NL),TB(NB),TP(NP) + INTEGER ITL(5,NL),ITB(5,NB),ITP(5,NP) +* +* Longitude +* M M' D F n + DATA TL( 1)/ +6.288750D0 /, + : (ITL(I, 1),I=1,5)/ +0, +1, +0, +0, 0 / + DATA TL( 2)/ +1.274018D0 /, + : (ITL(I, 2),I=1,5)/ +0, -1, +2, +0, 0 / + DATA TL( 3)/ +0.658309D0 /, + : (ITL(I, 3),I=1,5)/ +0, +0, +2, +0, 0 / + DATA TL( 4)/ +0.213616D0 /, + : (ITL(I, 4),I=1,5)/ +0, +2, +0, +0, 0 / + DATA TL( 5)/ -0.185596D0 /, + : (ITL(I, 5),I=1,5)/ +1, +0, +0, +0, 1 / + DATA TL( 6)/ -0.114336D0 /, + : (ITL(I, 6),I=1,5)/ +0, +0, +0, +2, 0 / + DATA TL( 7)/ +0.058793D0 /, + : (ITL(I, 7),I=1,5)/ +0, -2, +2, +0, 0 / + DATA TL( 8)/ +0.057212D0 /, + : (ITL(I, 8),I=1,5)/ -1, -1, +2, +0, 1 / + DATA TL( 9)/ +0.053320D0 /, + : (ITL(I, 9),I=1,5)/ +0, +1, +2, +0, 0 / + DATA TL(10)/ +0.045874D0 /, + : (ITL(I,10),I=1,5)/ -1, +0, +2, +0, 1 / + DATA TL(11)/ +0.041024D0 /, + : (ITL(I,11),I=1,5)/ -1, +1, +0, +0, 1 / + DATA TL(12)/ -0.034718D0 /, + : (ITL(I,12),I=1,5)/ +0, +0, +1, +0, 0 / + DATA TL(13)/ -0.030465D0 /, + : (ITL(I,13),I=1,5)/ +1, +1, +0, +0, 1 / + DATA TL(14)/ +0.015326D0 /, + : (ITL(I,14),I=1,5)/ +0, +0, +2, -2, 0 / + DATA TL(15)/ -0.012528D0 /, + : (ITL(I,15),I=1,5)/ +0, +1, +0, +2, 0 / + DATA TL(16)/ -0.010980D0 /, + : (ITL(I,16),I=1,5)/ +0, -1, +0, +2, 0 / + DATA TL(17)/ +0.010674D0 /, + : (ITL(I,17),I=1,5)/ +0, -1, +4, +0, 0 / + DATA TL(18)/ +0.010034D0 /, + : (ITL(I,18),I=1,5)/ +0, +3, +0, +0, 0 / + DATA TL(19)/ +0.008548D0 /, + : (ITL(I,19),I=1,5)/ +0, -2, +4, +0, 0 / + DATA TL(20)/ -0.007910D0 /, + : (ITL(I,20),I=1,5)/ +1, -1, +2, +0, 1 / + DATA TL(21)/ -0.006783D0 /, + : (ITL(I,21),I=1,5)/ +1, +0, +2, +0, 1 / + DATA TL(22)/ +0.005162D0 /, + : (ITL(I,22),I=1,5)/ +0, +1, -1, +0, 0 / + DATA TL(23)/ +0.005000D0 /, + : (ITL(I,23),I=1,5)/ +1, +0, +1, +0, 1 / + DATA TL(24)/ +0.004049D0 /, + : (ITL(I,24),I=1,5)/ -1, +1, +2, +0, 1 / + DATA TL(25)/ +0.003996D0 /, + : (ITL(I,25),I=1,5)/ +0, +2, +2, +0, 0 / + DATA TL(26)/ +0.003862D0 /, + : (ITL(I,26),I=1,5)/ +0, +0, +4, +0, 0 / + DATA TL(27)/ +0.003665D0 /, + : (ITL(I,27),I=1,5)/ +0, -3, +2, +0, 0 / + DATA TL(28)/ +0.002695D0 /, + : (ITL(I,28),I=1,5)/ -1, +2, +0, +0, 1 / + DATA TL(29)/ +0.002602D0 /, + : (ITL(I,29),I=1,5)/ +0, +1, -2, -2, 0 / + DATA TL(30)/ +0.002396D0 /, + : (ITL(I,30),I=1,5)/ -1, -2, +2, +0, 1 / + DATA TL(31)/ -0.002349D0 /, + : (ITL(I,31),I=1,5)/ +0, +1, +1, +0, 0 / + DATA TL(32)/ +0.002249D0 /, + : (ITL(I,32),I=1,5)/ -2, +0, +2, +0, 2 / + DATA TL(33)/ -0.002125D0 /, + : (ITL(I,33),I=1,5)/ +1, +2, +0, +0, 1 / + DATA TL(34)/ -0.002079D0 /, + : (ITL(I,34),I=1,5)/ +2, +0, +0, +0, 2 / + DATA TL(35)/ +0.002059D0 /, + : (ITL(I,35),I=1,5)/ -2, -1, +2, +0, 2 / + DATA TL(36)/ -0.001773D0 /, + : (ITL(I,36),I=1,5)/ +0, +1, +2, -2, 0 / + DATA TL(37)/ -0.001595D0 /, + : (ITL(I,37),I=1,5)/ +0, +0, +2, +2, 0 / + DATA TL(38)/ +0.001220D0 /, + : (ITL(I,38),I=1,5)/ -1, -1, +4, +0, 1 / + DATA TL(39)/ -0.001110D0 /, + : (ITL(I,39),I=1,5)/ +0, +2, +0, +2, 0 / + DATA TL(40)/ +0.000892D0 /, + : (ITL(I,40),I=1,5)/ +0, +1, -3, +0, 0 / + DATA TL(41)/ -0.000811D0 /, + : (ITL(I,41),I=1,5)/ +1, +1, +2, +0, 1 / + DATA TL(42)/ +0.000761D0 /, + : (ITL(I,42),I=1,5)/ -1, -2, +4, +0, 1 / + DATA TL(43)/ +0.000717D0 /, + : (ITL(I,43),I=1,5)/ -2, +1, +0, +0, 2 / + DATA TL(44)/ +0.000704D0 /, + : (ITL(I,44),I=1,5)/ -2, +1, -2, +0, 2 / + DATA TL(45)/ +0.000693D0 /, + : (ITL(I,45),I=1,5)/ +1, -2, +2, +0, 1 / + DATA TL(46)/ +0.000598D0 /, + : (ITL(I,46),I=1,5)/ -1, +0, +2, -2, 1 / + DATA TL(47)/ +0.000550D0 /, + : (ITL(I,47),I=1,5)/ +0, +1, +4, +0, 0 / + DATA TL(48)/ +0.000538D0 /, + : (ITL(I,48),I=1,5)/ +0, +4, +0, +0, 0 / + DATA TL(49)/ +0.000521D0 /, + : (ITL(I,49),I=1,5)/ -1, +0, +4, +0, 1 / + DATA TL(50)/ +0.000486D0 /, + : (ITL(I,50),I=1,5)/ +0, +2, -1, +0, 0 / +* +* Latitude +* M M' D F n + DATA TB( 1)/ +5.128189D0 /, + : (ITB(I, 1),I=1,5)/ +0, +0, +0, +1, 0 / + DATA TB( 2)/ +0.280606D0 /, + : (ITB(I, 2),I=1,5)/ +0, +1, +0, +1, 0 / + DATA TB( 3)/ +0.277693D0 /, + : (ITB(I, 3),I=1,5)/ +0, +1, +0, -1, 0 / + DATA TB( 4)/ +0.173238D0 /, + : (ITB(I, 4),I=1,5)/ +0, +0, +2, -1, 0 / + DATA TB( 5)/ +0.055413D0 /, + : (ITB(I, 5),I=1,5)/ +0, -1, +2, +1, 0 / + DATA TB( 6)/ +0.046272D0 /, + : (ITB(I, 6),I=1,5)/ +0, -1, +2, -1, 0 / + DATA TB( 7)/ +0.032573D0 /, + : (ITB(I, 7),I=1,5)/ +0, +0, +2, +1, 0 / + DATA TB( 8)/ +0.017198D0 /, + : (ITB(I, 8),I=1,5)/ +0, +2, +0, +1, 0 / + DATA TB( 9)/ +0.009267D0 /, + : (ITB(I, 9),I=1,5)/ +0, +1, +2, -1, 0 / + DATA TB(10)/ +0.008823D0 /, + : (ITB(I,10),I=1,5)/ +0, +2, +0, -1, 0 / + DATA TB(11)/ +0.008247D0 /, + : (ITB(I,11),I=1,5)/ -1, +0, +2, -1, 1 / + DATA TB(12)/ +0.004323D0 /, + : (ITB(I,12),I=1,5)/ +0, -2, +2, -1, 0 / + DATA TB(13)/ +0.004200D0 /, + : (ITB(I,13),I=1,5)/ +0, +1, +2, +1, 0 / + DATA TB(14)/ +0.003372D0 /, + : (ITB(I,14),I=1,5)/ -1, +0, -2, +1, 1 / + DATA TB(15)/ +0.002472D0 /, + : (ITB(I,15),I=1,5)/ -1, -1, +2, +1, 1 / + DATA TB(16)/ +0.002222D0 /, + : (ITB(I,16),I=1,5)/ -1, +0, +2, +1, 1 / + DATA TB(17)/ +0.002072D0 /, + : (ITB(I,17),I=1,5)/ -1, -1, +2, -1, 1 / + DATA TB(18)/ +0.001877D0 /, + : (ITB(I,18),I=1,5)/ -1, +1, +0, +1, 1 / + DATA TB(19)/ +0.001828D0 /, + : (ITB(I,19),I=1,5)/ +0, -1, +4, -1, 0 / + DATA TB(20)/ -0.001803D0 /, + : (ITB(I,20),I=1,5)/ +1, +0, +0, +1, 1 / + DATA TB(21)/ -0.001750D0 /, + : (ITB(I,21),I=1,5)/ +0, +0, +0, +3, 0 / + DATA TB(22)/ +0.001570D0 /, + : (ITB(I,22),I=1,5)/ -1, +1, +0, -1, 1 / + DATA TB(23)/ -0.001487D0 /, + : (ITB(I,23),I=1,5)/ +0, +0, +1, +1, 0 / + DATA TB(24)/ -0.001481D0 /, + : (ITB(I,24),I=1,5)/ +1, +1, +0, +1, 1 / + DATA TB(25)/ +0.001417D0 /, + : (ITB(I,25),I=1,5)/ -1, -1, +0, +1, 1 / + DATA TB(26)/ +0.001350D0 /, + : (ITB(I,26),I=1,5)/ -1, +0, +0, +1, 1 / + DATA TB(27)/ +0.001330D0 /, + : (ITB(I,27),I=1,5)/ +0, +0, -1, +1, 0 / + DATA TB(28)/ +0.001106D0 /, + : (ITB(I,28),I=1,5)/ +0, +3, +0, +1, 0 / + DATA TB(29)/ +0.001020D0 /, + : (ITB(I,29),I=1,5)/ +0, +0, +4, -1, 0 / + DATA TB(30)/ +0.000833D0 /, + : (ITB(I,30),I=1,5)/ +0, -1, +4, +1, 0 / + DATA TB(31)/ +0.000781D0 /, + : (ITB(I,31),I=1,5)/ +0, +1, +0, -3, 0 / + DATA TB(32)/ +0.000670D0 /, + : (ITB(I,32),I=1,5)/ +0, -2, +4, +1, 0 / + DATA TB(33)/ +0.000606D0 /, + : (ITB(I,33),I=1,5)/ +0, +0, +2, -3, 0 / + DATA TB(34)/ +0.000597D0 /, + : (ITB(I,34),I=1,5)/ +0, +2, +2, -1, 0 / + DATA TB(35)/ +0.000492D0 /, + : (ITB(I,35),I=1,5)/ -1, +1, +2, -1, 1 / + DATA TB(36)/ +0.000450D0 /, + : (ITB(I,36),I=1,5)/ +0, +2, -2, -1, 0 / + DATA TB(37)/ +0.000439D0 /, + : (ITB(I,37),I=1,5)/ +0, +3, +0, -1, 0 / + DATA TB(38)/ +0.000423D0 /, + : (ITB(I,38),I=1,5)/ +0, +2, +2, +1, 0 / + DATA TB(39)/ +0.000422D0 /, + : (ITB(I,39),I=1,5)/ +0, -3, +2, -1, 0 / + DATA TB(40)/ -0.000367D0 /, + : (ITB(I,40),I=1,5)/ +1, -1, +2, +1, 1 / + DATA TB(41)/ -0.000353D0 /, + : (ITB(I,41),I=1,5)/ +1, +0, +2, +1, 1 / + DATA TB(42)/ +0.000331D0 /, + : (ITB(I,42),I=1,5)/ +0, +0, +4, +1, 0 / + DATA TB(43)/ +0.000317D0 /, + : (ITB(I,43),I=1,5)/ -1, +1, +2, +1, 1 / + DATA TB(44)/ +0.000306D0 /, + : (ITB(I,44),I=1,5)/ -2, +0, +2, -1, 2 / + DATA TB(45)/ -0.000283D0 /, + : (ITB(I,45),I=1,5)/ +0, +1, +0, +3, 0 / +* +* Parallax +* M M' D F n + DATA TP( 1)/ +0.950724D0 /, + : (ITP(I, 1),I=1,5)/ +0, +0, +0, +0, 0 / + DATA TP( 2)/ +0.051818D0 /, + : (ITP(I, 2),I=1,5)/ +0, +1, +0, +0, 0 / + DATA TP( 3)/ +0.009531D0 /, + : (ITP(I, 3),I=1,5)/ +0, -1, +2, +0, 0 / + DATA TP( 4)/ +0.007843D0 /, + : (ITP(I, 4),I=1,5)/ +0, +0, +2, +0, 0 / + DATA TP( 5)/ +0.002824D0 /, + : (ITP(I, 5),I=1,5)/ +0, +2, +0, +0, 0 / + DATA TP( 6)/ +0.000857D0 /, + : (ITP(I, 6),I=1,5)/ +0, +1, +2, +0, 0 / + DATA TP( 7)/ +0.000533D0 /, + : (ITP(I, 7),I=1,5)/ -1, +0, +2, +0, 1 / + DATA TP( 8)/ +0.000401D0 /, + : (ITP(I, 8),I=1,5)/ -1, -1, +2, +0, 1 / + DATA TP( 9)/ +0.000320D0 /, + : (ITP(I, 9),I=1,5)/ -1, +1, +0, +0, 1 / + DATA TP(10)/ -0.000271D0 /, + : (ITP(I,10),I=1,5)/ +0, +0, +1, +0, 0 / + DATA TP(11)/ -0.000264D0 /, + : (ITP(I,11),I=1,5)/ +1, +1, +0, +0, 1 / + DATA TP(12)/ -0.000198D0 /, + : (ITP(I,12),I=1,5)/ +0, -1, +0, +2, 0 / + DATA TP(13)/ +0.000173D0 /, + : (ITP(I,13),I=1,5)/ +0, +3, +0, +0, 0 / + DATA TP(14)/ +0.000167D0 /, + : (ITP(I,14),I=1,5)/ +0, -1, +4, +0, 0 / + DATA TP(15)/ -0.000111D0 /, + : (ITP(I,15),I=1,5)/ +1, +0, +0, +0, 1 / + DATA TP(16)/ +0.000103D0 /, + : (ITP(I,16),I=1,5)/ +0, -2, +4, +0, 0 / + DATA TP(17)/ -0.000084D0 /, + : (ITP(I,17),I=1,5)/ +0, +2, -2, +0, 0 / + DATA TP(18)/ -0.000083D0 /, + : (ITP(I,18),I=1,5)/ +1, +0, +2, +0, 1 / + DATA TP(19)/ +0.000079D0 /, + : (ITP(I,19),I=1,5)/ +0, +2, +2, +0, 0 / + DATA TP(20)/ +0.000072D0 /, + : (ITP(I,20),I=1,5)/ +0, +0, +4, +0, 0 / + DATA TP(21)/ +0.000064D0 /, + : (ITP(I,21),I=1,5)/ -1, +1, +2, +0, 1 / + DATA TP(22)/ -0.000063D0 /, + : (ITP(I,22),I=1,5)/ +1, -1, +2, +0, 1 / + DATA TP(23)/ +0.000041D0 /, + : (ITP(I,23),I=1,5)/ +1, +0, +1, +0, 1 / + DATA TP(24)/ +0.000035D0 /, + : (ITP(I,24),I=1,5)/ -1, +2, +0, +0, 1 / + DATA TP(25)/ -0.000033D0 /, + : (ITP(I,25),I=1,5)/ +0, +3, -2, +0, 0 / + DATA TP(26)/ -0.000030D0 /, + : (ITP(I,26),I=1,5)/ +0, +1, +1, +0, 0 / + DATA TP(27)/ -0.000029D0 /, + : (ITP(I,27),I=1,5)/ +0, +0, -2, +2, 0 / + DATA TP(28)/ -0.000029D0 /, + : (ITP(I,28),I=1,5)/ +1, +2, +0, +0, 1 / + DATA TP(29)/ +0.000026D0 /, + : (ITP(I,29),I=1,5)/ -2, +0, +2, +0, 2 / + DATA TP(30)/ -0.000023D0 /, + : (ITP(I,30),I=1,5)/ +0, +1, -2, +2, 0 / + DATA TP(31)/ +0.000019D0 /, + : (ITP(I,31),I=1,5)/ -1, -1, +4, +0, 1 / + + + +* Centuries since J1900 + T=(DATE-15019.5D0)/36525D0 + +* +* Fundamental arguments (radians) and derivatives (radians per +* Julian century) for the current epoch +* + +* Moon's mean longitude + ELP=D2R*MOD(ELP0+(ELP1+(ELP2+ELP3*T)*T)*T,360D0) + DELP=D2R*(ELP1+(2D0*ELP2+3D0*ELP3*T)*T) + +* Sun's mean anomaly + EM=D2R*MOD(EM0+(EM1+(EM2+EM3*T)*T)*T,360D0) + DEM=D2R*(EM1+(2D0*EM2+3D0*EM3*T)*T) + +* Moon's mean anomaly + EMP=D2R*MOD(EMP0+(EMP1+(EMP2+EMP3*T)*T)*T,360D0) + DEMP=D2R*(EMP1+(2D0*EMP2+3D0*EMP3*T)*T) + +* Moon's mean elongation + D=D2R*MOD(D0+(D1+(D2+D3*T)*T)*T,360D0) + DD=D2R*(D1+(2D0*D2+3D0*D3*T)*T) + +* Mean distance of the Moon from its ascending node + F=D2R*MOD(F0+(F1+(F2+F3*T)*T)*T,360D0) + DF=D2R*(F1+(2D0*F2+3D0*F3*T)*T) + +* Longitude of the Moon's ascending node + OM=D2R*MOD(OM0+(OM1+(OM2+OM3*T)*T)*T,360D0) + DOM=D2R*(OM1+(2D0*OM2+3D0*OM3*T)*T) + SINOM=SIN(OM) + COSOM=COS(OM) + DOMCOM=DOM*COSOM + +* Add the periodic variations + THETA=D2R*(PA0+PA1*T) + WA=SIN(THETA) + DWA=D2R*PA1*COS(THETA) + THETA=D2R*(PE0+(PE1+PE2*T)*T) + WB=PEC*SIN(THETA) + DWB=D2R*PEC*(PE1+2D0*PE2*T)*COS(THETA) + ELP=ELP+D2R*(PAC*WA+WB+PFC*SINOM) + DELP=DELP+D2R*(PAC*DWA+DWB+PFC*DOMCOM) + EM=EM+D2R*PBC*WA + DEM=DEM+D2R*PBC*DWA + EMP=EMP+D2R*(PCC*WA+WB+PGC*SINOM) + DEMP=DEMP+D2R*(PCC*DWA+DWB+PGC*DOMCOM) + D=D+D2R*(PDC*WA+WB+PHC*SINOM) + DD=DD+D2R*(PDC*DWA+DWB+PHC*DOMCOM) + WOM=OM+D2R*(PJ0+PJ1*T) + DWOM=DOM+D2R*PJ1 + SINWOM=SIN(WOM) + COSWOM=COS(WOM) + F=F+D2R*(WB+PIC*SINOM+PJC*SINWOM) + DF=DF+D2R*(DWB+PIC*DOMCOM+PJC*DWOM*COSWOM) + +* E-factor, and square + E=1D0+(E1+E2*T)*T + DE=E1+2D0*E2*T + ESQ=E*E + DESQ=2D0*E*DE + +* +* Series expansions +* + +* Longitude + V=0D0 + DV=0D0 + DO N=NL,1,-1 + COEFF=TL(N) + EMN=DBLE(ITL(1,N)) + EMPN=DBLE(ITL(2,N)) + DN=DBLE(ITL(3,N)) + FN=DBLE(ITL(4,N)) + I=ITL(5,N) + IF (I.EQ.0) THEN + EN=1D0 + DEN=0D0 + ELSE IF (I.EQ.1) THEN + EN=E + DEN=DE + ELSE + EN=ESQ + DEN=DESQ + END IF + THETA=EMN*EM+EMPN*EMP+DN*D+FN*F + DTHETA=EMN*DEM+EMPN*DEMP+DN*DD+FN*DF + FTHETA=SIN(THETA) + V=V+COEFF*FTHETA*EN + DV=DV+COEFF*(COS(THETA)*DTHETA*EN+FTHETA*DEN) + END DO + EL=ELP+D2R*V + DEL=(DELP+D2R*DV)/CJ + +* Latitude + V=0D0 + DV=0D0 + DO N=NB,1,-1 + COEFF=TB(N) + EMN=DBLE(ITB(1,N)) + EMPN=DBLE(ITB(2,N)) + DN=DBLE(ITB(3,N)) + FN=DBLE(ITB(4,N)) + I=ITB(5,N) + IF (I.EQ.0) THEN + EN=1D0 + DEN=0D0 + ELSE IF (I.EQ.1) THEN + EN=E + DEN=DE + ELSE + EN=ESQ + DEN=DESQ + END IF + THETA=EMN*EM+EMPN*EMP+DN*D+FN*F + DTHETA=EMN*DEM+EMPN*DEMP+DN*DD+FN*DF + FTHETA=SIN(THETA) + V=V+COEFF*FTHETA*EN + DV=DV+COEFF*(COS(THETA)*DTHETA*EN+FTHETA*DEN) + END DO + BF=1D0-CW1*COSOM-CW2*COSWOM + DBF=CW1*DOM*SINOM+CW2*DWOM*SINWOM + B=D2R*V*BF + DB=D2R*(DV*BF+V*DBF)/CJ + +* Parallax + V=0D0 + DV=0D0 + DO N=NP,1,-1 + COEFF=TP(N) + EMN=DBLE(ITP(1,N)) + EMPN=DBLE(ITP(2,N)) + DN=DBLE(ITP(3,N)) + FN=DBLE(ITP(4,N)) + I=ITP(5,N) + IF (I.EQ.0) THEN + EN=1D0 + DEN=0D0 + ELSE IF (I.EQ.1) THEN + EN=E + DEN=DE + ELSE + EN=ESQ + DEN=DESQ + END IF + THETA=EMN*EM+EMPN*EMP+DN*D+FN*F + DTHETA=EMN*DEM+EMPN*DEMP+DN*DD+FN*DF + FTHETA=COS(THETA) + V=V+COEFF*FTHETA*EN + DV=DV+COEFF*(-SIN(THETA)*DTHETA*EN+FTHETA*DEN) + END DO + P=D2R*V + DP=D2R*DV/CJ + +* +* Transformation into final form +* + +* Parallax to distance (AU, AU/sec) + SP=SIN(P) + R=ERADAU/SP + DR=-R*DP*COS(P)/SP + +* Longitude, latitude to x,y,z (AU) + SEL=SIN(EL) + CEL=COS(EL) + SB=SIN(B) + CB=COS(B) + RCB=R*CB + RBD=R*DB + W=RBD*SB-CB*DR + X=RCB*CEL + Y=RCB*SEL + Z=R*SB + XD=-Y*DEL-W*CEL + YD=X*DEL-W*SEL + ZD=RBD*CB+SB*DR + +* Julian centuries since J2000 + T=(DATE-51544.5D0)/36525D0 + +* Fricke equinox correction + EPJ=2000D0+T*100D0 + EQCOR=DS2R*(0.035D0+0.00085D0*(EPJ-B1950)) + +* Mean obliquity (IAU 1976) + EPS=DAS2R*(84381.448D0+(-46.8150D0+(-0.00059D0+0.001813D0*T)*T)*T) + +* To the equatorial system, mean of date, FK5 system + SINEPS=SIN(EPS) + COSEPS=COS(EPS) + ES=EQCOR*SINEPS + EC=EQCOR*COSEPS + PV(1)=X-EC*Y+ES*Z + PV(2)=EQCOR*X+Y*COSEPS-Z*SINEPS + PV(3)=Y*SINEPS+Z*COSEPS + PV(4)=XD-EC*YD+ES*ZD + PV(5)=EQCOR*XD+YD*COSEPS-ZD*SINEPS + PV(6)=YD*SINEPS+ZD*COSEPS + + END + SUBROUTINE sla_DMXV (DM, VA, VB) +*+ +* - - - - - +* D M X V +* - - - - - +* +* Performs the 3-D forward unitary transformation: +* +* vector VB = matrix DM * vector VA +* +* (double precision) +* +* Given: +* DM dp(3,3) matrix +* VA dp(3) vector +* +* Returned: +* VB dp(3) result vector +* +* To comply with the ANSI Fortran 77 standard, VA and VB must be +* different arrays. However, the routine is coded so as to work +* properly on many platforms even if this rule is violated. +* +* Last revision: 26 December 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DM(3,3),VA(3),VB(3) + + INTEGER I,J + DOUBLE PRECISION W,VW(3) + + +* Matrix DM * vector VA -> vector VW + DO J=1,3 + W=0D0 + DO I=1,3 + W=W+DM(J,I)*VA(I) + END DO + VW(J)=W + END DO + +* Vector VW -> vector VB + DO J=1,3 + VB(J)=VW(J) + END DO + + END + DOUBLE PRECISION FUNCTION sla_DRANGE (ANGLE) +*+ +* - - - - - - - +* D R A N G E +* - - - - - - - +* +* Normalize angle into range +/- pi (double precision) +* +* Given: +* ANGLE dp the angle in radians +* +* The result (double precision) is ANGLE expressed in the range +/- pi. +* +* P.T.Wallace Starlink 23 November 1995 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION ANGLE + + DOUBLE PRECISION DPI,D2PI + PARAMETER (DPI=3.141592653589793238462643D0) + PARAMETER (D2PI=6.283185307179586476925287D0) + + + sla_DRANGE=MOD(ANGLE,D2PI) + IF (ABS(sla_DRANGE).GE.DPI) + : sla_DRANGE=sla_DRANGE-SIGN(D2PI,ANGLE) + + END + DOUBLE PRECISION FUNCTION sla_DRANRM (ANGLE) +*+ +* - - - - - - - +* D R A N R M +* - - - - - - - +* +* Normalize angle into range 0-2 pi (double precision) +* +* Given: +* ANGLE dp the angle in radians +* +* The result is ANGLE expressed in the range 0-2 pi. +* +* Last revision: 22 July 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION ANGLE + + DOUBLE PRECISION D2PI + PARAMETER (D2PI=6.283185307179586476925286766559D0) + + + sla_DRANRM = MOD(ANGLE,D2PI) + IF (sla_DRANRM.LT.0D0) sla_DRANRM = sla_DRANRM+D2PI + + END + DOUBLE PRECISION FUNCTION sla_DTT (UTC) +*+ +* - - - - +* D T T +* - - - - +* +* Increment to be applied to Coordinated Universal Time UTC to give +* Terrestrial Time TT (formerly Ephemeris Time ET) +* +* (double precision) +* +* Given: +* UTC d UTC date as a modified JD (JD-2400000.5) +* +* Result: TT-UTC in seconds +* +* Notes: +* +* 1 The UTC is specified to be a date rather than a time to indicate +* that care needs to be taken not to specify an instant which lies +* within a leap second. Though in most cases UTC can include the +* fractional part, correct behaviour on the day of a leap second +* can only be guaranteed up to the end of the second 23:59:59. +* +* 2 Pre 1972 January 1 a fixed value of 10 + ET-TAI is returned. +* +* 3 See also the routine sla_DT, which roughly estimates ET-UT for +* historical epochs. +* +* Called: sla_DAT +* +* P.T.Wallace Starlink 6 December 1994 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION UTC + + DOUBLE PRECISION sla_DAT + + + sla_DTT=32.184D0+sla_DAT(UTC) + + END + SUBROUTINE sla_ECMAT (DATE, RMAT) +*+ +* - - - - - - +* E C M A T +* - - - - - - +* +* Form the equatorial to ecliptic rotation matrix - IAU 1980 theory +* (double precision) +* +* Given: +* DATE dp TDB (loosely ET) as Modified Julian Date +* (JD-2400000.5) +* Returned: +* RMAT dp(3,3) matrix +* +* Reference: +* Murray,C.A., Vectorial Astrometry, section 4.3. +* +* Note: +* The matrix is in the sense V(ecl) = RMAT * V(equ); the +* equator, equinox and ecliptic are mean of date. +* +* Called: sla_DEULER +* +* P.T.Wallace Starlink 23 August 1996 +* +* Copyright (C) 1996 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE,RMAT(3,3) + +* Arc seconds to radians + DOUBLE PRECISION AS2R + PARAMETER (AS2R=0.484813681109535994D-5) + + DOUBLE PRECISION T,EPS0 + + + +* Interval between basic epoch J2000.0 and current epoch (JC) + T = (DATE-51544.5D0)/36525D0 + +* Mean obliquity + EPS0 = AS2R* + : (84381.448D0+(-46.8150D0+(-0.00059D0+0.001813D0*T)*T)*T) + +* Matrix + CALL sla_DEULER('X',EPS0,0D0,0D0,RMAT) + + END + DOUBLE PRECISION FUNCTION sla_EPJ (DATE) +*+ +* - - - - +* E P J +* - - - - +* +* Conversion of Modified Julian Date to Julian Epoch (double precision) +* +* Given: +* DATE dp Modified Julian Date (JD - 2400000.5) +* +* The result is the Julian Epoch. +* +* Reference: +* Lieske,J.H., 1979. Astron.Astrophys.,73,282. +* +* P.T.Wallace Starlink February 1984 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE + + + sla_EPJ = 2000D0 + (DATE-51544.5D0)/365.25D0 + + END + SUBROUTINE sla_EQECL (DR, DD, DATE, DL, DB) +*+ +* - - - - - - +* E Q E C L +* - - - - - - +* +* Transformation from J2000.0 equatorial coordinates to +* ecliptic coordinates (double precision) +* +* Given: +* DR,DD dp J2000.0 mean RA,Dec (radians) +* DATE dp TDB (loosely ET) as Modified Julian Date +* (JD-2400000.5) +* Returned: +* DL,DB dp ecliptic longitude and latitude +* (mean of date, IAU 1980 theory, radians) +* +* Called: +* sla_DCS2C, sla_PREC, sla_EPJ, sla_DMXV, sla_ECMAT, sla_DCC2S, +* sla_DRANRM, sla_DRANGE +* +* P.T.Wallace Starlink March 1986 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DR,DD,DATE,DL,DB + + DOUBLE PRECISION sla_EPJ,sla_DRANRM,sla_DRANGE + + DOUBLE PRECISION RMAT(3,3),V1(3),V2(3) + + + +* Spherical to Cartesian + CALL sla_DCS2C(DR,DD,V1) + +* Mean J2000 to mean of date + CALL sla_PREC(2000D0,sla_EPJ(DATE),RMAT) + CALL sla_DMXV(RMAT,V1,V2) + +* Equatorial to ecliptic + CALL sla_ECMAT(DATE,RMAT) + CALL sla_DMXV(RMAT,V2,V1) + +* Cartesian to spherical + CALL sla_DCC2S(V1,DL,DB) + +* Express in conventional ranges + DL=sla_DRANRM(DL) + DB=sla_DRANGE(DB) + + END + DOUBLE PRECISION FUNCTION sla_EQEQX (DATE) +*+ +* - - - - - - +* E Q E Q X +* - - - - - - +* +* Equation of the equinoxes (IAU 1994, double precision) +* +* Given: +* DATE dp TDB (loosely ET) as Modified Julian Date +* (JD-2400000.5) +* +* The result is the equation of the equinoxes (double precision) +* in radians: +* +* Greenwich apparent ST = GMST + sla_EQEQX +* +* References: IAU Resolution C7, Recommendation 3 (1994) +* Capitaine, N. & Gontier, A.-M., Astron. Astrophys., +* 275, 645-650 (1993) +* +* Called: sla_NUTC +* +* Patrick Wallace Starlink 23 August 1996 +* +* Copyright (C) 1996 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE + +* Turns to arc seconds and arc seconds to radians + DOUBLE PRECISION T2AS,AS2R + PARAMETER (T2AS=1296000D0, + : AS2R=0.484813681109535994D-5) + + DOUBLE PRECISION T,OM,DPSI,DEPS,EPS0 + + + +* Interval between basic epoch J2000.0 and current epoch (JC) + T=(DATE-51544.5D0)/36525D0 + +* Longitude of the mean ascending node of the lunar orbit on the +* ecliptic, measured from the mean equinox of date + OM=AS2R*(450160.280D0+(-5D0*T2AS-482890.539D0 + : +(7.455D0+0.008D0*T)*T)*T) + +* Nutation + CALL sla_NUTC(DATE,DPSI,DEPS,EPS0) + +* Equation of the equinoxes + sla_EQEQX=DPSI*COS(EPS0)+AS2R*(0.00264D0*SIN(OM)+ + : 0.000063D0*SIN(OM+OM)) + + END + SUBROUTINE sla_GEOC (P, H, R, Z) +*+ +* - - - - - +* G E O C +* - - - - - +* +* Convert geodetic position to geocentric (double precision) +* +* Given: +* P dp latitude (geodetic, radians) +* H dp height above reference spheroid (geodetic, metres) +* +* Returned: +* R dp distance from Earth axis (AU) +* Z dp distance from plane of Earth equator (AU) +* +* Notes: +* +* 1 Geocentric latitude can be obtained by evaluating ATAN2(Z,R). +* +* 2 IAU 1976 constants are used. +* +* Reference: +* +* Green,R.M., Spherical Astronomy, CUP 1985, p98. +* +* Last revision: 22 July 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION P,H,R,Z + +* Earth equatorial radius (metres) + DOUBLE PRECISION A0 + PARAMETER (A0=6378140D0) + +* Reference spheroid flattening factor and useful function + DOUBLE PRECISION F,B + PARAMETER (F=1D0/298.257D0,B=(1D0-F)**2) + +* Astronomical unit in metres + DOUBLE PRECISION AU + PARAMETER (AU=1.49597870D11) + + DOUBLE PRECISION SP,CP,C,S + + + +* Geodetic to geocentric conversion + SP = SIN(P) + CP = COS(P) + C = 1D0/SQRT(CP*CP+B*SP*SP) + S = B*C + R = (A0*C+H)*CP/AU + Z = (A0*S+H)*SP/AU + + END + DOUBLE PRECISION FUNCTION sla_GMST (UT1) +*+ +* - - - - - +* G M S T +* - - - - - +* +* Conversion from universal time to sidereal time (double precision) +* +* Given: +* UT1 dp universal time (strictly UT1) expressed as +* modified Julian Date (JD-2400000.5) +* +* The result is the Greenwich mean sidereal time (double +* precision, radians). +* +* The IAU 1982 expression (see page S15 of 1984 Astronomical Almanac) +* is used, but rearranged to reduce rounding errors. This expression +* is always described as giving the GMST at 0 hours UT. In fact, it +* gives the difference between the GMST and the UT, which happens to +* equal the GMST (modulo 24 hours) at 0 hours UT each day. In this +* routine, the entire UT is used directly as the argument for the +* standard formula, and the fractional part of the UT is added +* separately. Note that the factor 1.0027379... does not appear in the +* IAU 1982 expression explicitly but in the form of the coefficient +* 8640184.812866, which is 86400x36525x0.0027379... +* +* See also the routine sla_GMSTA, which delivers better numerical +* precision by accepting the UT date and time as separate arguments. +* +* Called: sla_DRANRM +* +* P.T.Wallace Starlink 14 October 2001 +* +* Copyright (C) 2001 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION UT1 + + DOUBLE PRECISION sla_DRANRM + + DOUBLE PRECISION D2PI,S2R + PARAMETER (D2PI=6.283185307179586476925286766559D0, + : S2R=7.272205216643039903848711535369D-5) + + DOUBLE PRECISION TU + + + +* Julian centuries from fundamental epoch J2000 to this UT + TU=(UT1-51544.5D0)/36525D0 + +* GMST at this UT + sla_GMST=sla_DRANRM(MOD(UT1,1D0)*D2PI+ + : (24110.54841D0+ + : (8640184.812866D0+ + : (0.093104D0-6.2D-6*TU)*TU)*TU)*S2R) + + END + SUBROUTINE sla_NUTC (DATE, DPSI, DEPS, EPS0) +*+ +* - - - - - +* N U T C +* - - - - - +* +* Nutation: longitude & obliquity components and mean obliquity, +* using the Shirai & Fukushima (2001) theory. +* +* Given: +* DATE d TDB (loosely ET) as Modified Julian Date +* (JD-2400000.5) +* Returned: +* DPSI,DEPS d nutation in longitude,obliquity +* EPS0 d mean obliquity +* +* Notes: +* +* 1 The routine predicts forced nutation (but not free core nutation) +* plus corrections to the IAU 1976 precession model. +* +* 2 Earth attitude predictions made by combining the present nutation +* model with IAU 1976 precession are accurate to 1 mas (with respect +* to the ICRF) for a few decades around 2000. +* +* 3 The sla_NUTC80 routine is the equivalent of the present routine +* but using the IAU 1980 nutation theory. The older theory is less +* accurate, leading to errors as large as 350 mas over the interval +* 1900-2100, mainly because of the error in the IAU 1976 precession. +* +* References: +* +* Shirai, T. & Fukushima, T., Astron.J. 121, 3270-3283 (2001). +* +* Fukushima, T., Astron.Astrophys. 244, L11 (1991). +* +* Simon, J. L., Bretagnon, P., Chapront, J., Chapront-Touze, M., +* Francou, G. & Laskar, J., Astron.Astrophys. 282, 663 (1994). +* +* This revision: 24 November 2005 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE,DPSI,DEPS,EPS0 + +* Degrees to radians + DOUBLE PRECISION DD2R + PARAMETER (DD2R=1.745329251994329576923691D-2) + +* Arc seconds to radians + DOUBLE PRECISION DAS2R + PARAMETER (DAS2R=4.848136811095359935899141D-6) + +* Arc seconds in a full circle + DOUBLE PRECISION TURNAS + PARAMETER (TURNAS=1296000D0) + +* Reference epoch (J2000), MJD + DOUBLE PRECISION DJM0 + PARAMETER (DJM0=51544.5D0 ) + +* Days per Julian century + DOUBLE PRECISION DJC + PARAMETER (DJC=36525D0) + + INTEGER I,J + DOUBLE PRECISION T,EL,ELP,F,D,OM,VE,MA,JU,SA,THETA,C,S,DP,DE + +* Number of terms in the nutation model + INTEGER NTERMS + PARAMETER (NTERMS=194) + +* The SF2001 forced nutation model + INTEGER NA(9,NTERMS) + DOUBLE PRECISION PSI(4,NTERMS), EPS(4,NTERMS) + +* Coefficients of fundamental angles + DATA ( ( NA(I,J), I=1,9 ), J=1,10 ) / + : 0, 0, 0, 0, -1, 0, 0, 0, 0, + : 0, 0, 2, -2, 2, 0, 0, 0, 0, + : 0, 0, 2, 0, 2, 0, 0, 0, 0, + : 0, 0, 0, 0, -2, 0, 0, 0, 0, + : 0, 1, 0, 0, 0, 0, 0, 0, 0, + : 0, 1, 2, -2, 2, 0, 0, 0, 0, + : 1, 0, 0, 0, 0, 0, 0, 0, 0, + : 0, 0, 2, 0, 1, 0, 0, 0, 0, + : 1, 0, 2, 0, 2, 0, 0, 0, 0, + : 0, -1, 2, -2, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=11,20 ) / + : 0, 0, 2, -2, 1, 0, 0, 0, 0, + : -1, 0, 2, 0, 2, 0, 0, 0, 0, + : -1, 0, 0, 2, 0, 0, 0, 0, 0, + : 1, 0, 0, 0, 1, 0, 0, 0, 0, + : 1, 0, 0, 0, -1, 0, 0, 0, 0, + : -1, 0, 2, 2, 2, 0, 0, 0, 0, + : 1, 0, 2, 0, 1, 0, 0, 0, 0, + : -2, 0, 2, 0, 1, 0, 0, 0, 0, + : 0, 0, 0, 2, 0, 0, 0, 0, 0, + : 0, 0, 2, 2, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=21,30 ) / + : 2, 0, 0, -2, 0, 0, 0, 0, 0, + : 2, 0, 2, 0, 2, 0, 0, 0, 0, + : 1, 0, 2, -2, 2, 0, 0, 0, 0, + : -1, 0, 2, 0, 1, 0, 0, 0, 0, + : 2, 0, 0, 0, 0, 0, 0, 0, 0, + : 0, 0, 2, 0, 0, 0, 0, 0, 0, + : 0, 1, 0, 0, 1, 0, 0, 0, 0, + : -1, 0, 0, 2, 1, 0, 0, 0, 0, + : 0, 2, 2, -2, 2, 0, 0, 0, 0, + : 0, 0, 2, -2, 0, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=31,40 ) / + : -1, 0, 0, 2, -1, 0, 0, 0, 0, + : 0, 1, 0, 0, -1, 0, 0, 0, 0, + : 0, 2, 0, 0, 0, 0, 0, 0, 0, + : -1, 0, 2, 2, 1, 0, 0, 0, 0, + : 1, 0, 2, 2, 2, 0, 0, 0, 0, + : 0, 1, 2, 0, 2, 0, 0, 0, 0, + : -2, 0, 2, 0, 0, 0, 0, 0, 0, + : 0, 0, 2, 2, 1, 0, 0, 0, 0, + : 0, -1, 2, 0, 2, 0, 0, 0, 0, + : 0, 0, 0, 2, 1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=41,50 ) / + : 1, 0, 2, -2, 1, 0, 0, 0, 0, + : 2, 0, 0, -2, -1, 0, 0, 0, 0, + : 2, 0, 2, -2, 2, 0, 0, 0, 0, + : 2, 0, 2, 0, 1, 0, 0, 0, 0, + : 0, 0, 0, 2, -1, 0, 0, 0, 0, + : 0, -1, 2, -2, 1, 0, 0, 0, 0, + : -1, -1, 0, 2, 0, 0, 0, 0, 0, + : 2, 0, 0, -2, 1, 0, 0, 0, 0, + : 1, 0, 0, 2, 0, 0, 0, 0, 0, + : 0, 1, 2, -2, 1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=51,60 ) / + : 1, -1, 0, 0, 0, 0, 0, 0, 0, + : -2, 0, 2, 0, 2, 0, 0, 0, 0, + : 0, -1, 0, 2, 0, 0, 0, 0, 0, + : 3, 0, 2, 0, 2, 0, 0, 0, 0, + : 0, 0, 0, 1, 0, 0, 0, 0, 0, + : 1, -1, 2, 0, 2, 0, 0, 0, 0, + : 1, 0, 0, -1, 0, 0, 0, 0, 0, + : -1, -1, 2, 2, 2, 0, 0, 0, 0, + : -1, 0, 2, 0, 0, 0, 0, 0, 0, + : 2, 0, 0, 0, -1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=61,70 ) / + : 0, -1, 2, 2, 2, 0, 0, 0, 0, + : 1, 1, 2, 0, 2, 0, 0, 0, 0, + : 2, 0, 0, 0, 1, 0, 0, 0, 0, + : 1, 1, 0, 0, 0, 0, 0, 0, 0, + : 1, 0, -2, 2, -1, 0, 0, 0, 0, + : 1, 0, 2, 0, 0, 0, 0, 0, 0, + : -1, 1, 0, 1, 0, 0, 0, 0, 0, + : 1, 0, 0, 0, 2, 0, 0, 0, 0, + : -1, 0, 1, 0, 1, 0, 0, 0, 0, + : 0, 0, 2, 1, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=71,80 ) / + : -1, 1, 0, 1, 1, 0, 0, 0, 0, + : -1, 0, 2, 4, 2, 0, 0, 0, 0, + : 0, -2, 2, -2, 1, 0, 0, 0, 0, + : 1, 0, 2, 2, 1, 0, 0, 0, 0, + : 1, 0, 0, 0, -2, 0, 0, 0, 0, + : -2, 0, 2, 2, 2, 0, 0, 0, 0, + : 1, 1, 2, -2, 2, 0, 0, 0, 0, + : -2, 0, 2, 4, 2, 0, 0, 0, 0, + : -1, 0, 4, 0, 2, 0, 0, 0, 0, + : 2, 0, 2, -2, 1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=81,90 ) / + : 1, 0, 0, -1, -1, 0, 0, 0, 0, + : 2, 0, 2, 2, 2, 0, 0, 0, 0, + : 1, 0, 0, 2, 1, 0, 0, 0, 0, + : 3, 0, 0, 0, 0, 0, 0, 0, 0, + : 0, 0, 2, -2, -1, 0, 0, 0, 0, + : 3, 0, 2, -2, 2, 0, 0, 0, 0, + : 0, 0, 4, -2, 2, 0, 0, 0, 0, + : -1, 0, 0, 4, 0, 0, 0, 0, 0, + : 0, 1, 2, 0, 1, 0, 0, 0, 0, + : 0, 0, 2, -2, 3, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=91,100 ) / + : -2, 0, 0, 4, 0, 0, 0, 0, 0, + : -1, -1, 0, 2, 1, 0, 0, 0, 0, + : -2, 0, 2, 0, -1, 0, 0, 0, 0, + : 0, 0, 2, 0, -1, 0, 0, 0, 0, + : 0, -1, 2, 0, 1, 0, 0, 0, 0, + : 0, 1, 0, 0, 2, 0, 0, 0, 0, + : 0, 0, 2, -1, 2, 0, 0, 0, 0, + : 2, 1, 0, -2, 0, 0, 0, 0, 0, + : 0, 0, 2, 4, 2, 0, 0, 0, 0, + : -1, -1, 0, 2, -1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=101,110 ) / + : -1, 1, 0, 2, 0, 0, 0, 0, 0, + : 1, -1, 0, 0, 1, 0, 0, 0, 0, + : 0, -1, 2, -2, 0, 0, 0, 0, 0, + : 0, 1, 0, 0, -2, 0, 0, 0, 0, + : 1, -1, 2, 2, 2, 0, 0, 0, 0, + : 1, 0, 0, 2, -1, 0, 0, 0, 0, + : -1, 1, 2, 2, 2, 0, 0, 0, 0, + : 3, 0, 2, 0, 1, 0, 0, 0, 0, + : 0, 1, 2, 2, 2, 0, 0, 0, 0, + : 1, 0, 2, -2, 0, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=111,120 ) / + : -1, 0, -2, 4, -1, 0, 0, 0, 0, + : -1, -1, 2, 2, 1, 0, 0, 0, 0, + : 0, -1, 2, 2, 1, 0, 0, 0, 0, + : 2, -1, 2, 0, 2, 0, 0, 0, 0, + : 0, 0, 0, 2, 2, 0, 0, 0, 0, + : 1, -1, 2, 0, 1, 0, 0, 0, 0, + : -1, 1, 2, 0, 2, 0, 0, 0, 0, + : 0, 1, 0, 2, 0, 0, 0, 0, 0, + : 0, 1, 2, -2, 0, 0, 0, 0, 0, + : 0, 3, 2, -2, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=121,130 ) / + : 0, 0, 0, 1, 1, 0, 0, 0, 0, + : -1, 0, 2, 2, 0, 0, 0, 0, 0, + : 2, 1, 2, 0, 2, 0, 0, 0, 0, + : 1, 1, 0, 0, 1, 0, 0, 0, 0, + : 2, 0, 0, 2, 0, 0, 0, 0, 0, + : 1, 1, 2, 0, 1, 0, 0, 0, 0, + : -1, 0, 0, 2, 2, 0, 0, 0, 0, + : 1, 0, -2, 2, 0, 0, 0, 0, 0, + : 0, -1, 0, 2, -1, 0, 0, 0, 0, + : -1, 0, 1, 0, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=131,140 ) / + : 0, 1, 0, 1, 0, 0, 0, 0, 0, + : 1, 0, -2, 2, -2, 0, 0, 0, 0, + : 0, 0, 0, 1, -1, 0, 0, 0, 0, + : 1, -1, 0, 0, -1, 0, 0, 0, 0, + : 0, 0, 0, 4, 0, 0, 0, 0, 0, + : 1, -1, 0, 2, 0, 0, 0, 0, 0, + : 1, 0, 2, 1, 2, 0, 0, 0, 0, + : 1, 0, 2, -1, 2, 0, 0, 0, 0, + : -1, 0, 0, 2, -2, 0, 0, 0, 0, + : 0, 0, 2, 1, 1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=141,150 ) / + : -1, 0, 2, 0, -1, 0, 0, 0, 0, + : -1, 0, 2, 4, 1, 0, 0, 0, 0, + : 0, 0, 2, 2, 0, 0, 0, 0, 0, + : 1, 1, 2, -2, 1, 0, 0, 0, 0, + : 0, 0, 1, 0, 1, 0, 0, 0, 0, + : -1, 0, 2, -1, 1, 0, 0, 0, 0, + : -2, 0, 2, 2, 1, 0, 0, 0, 0, + : 2, -1, 0, 0, 0, 0, 0, 0, 0, + : 4, 0, 2, 0, 2, 0, 0, 0, 0, + : 2, 1, 2, -2, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=151,160 ) / + : 0, 1, 2, 1, 2, 0, 0, 0, 0, + : 1, 0, 4, -2, 2, 0, 0, 0, 0, + : 1, 1, 0, 0, -1, 0, 0, 0, 0, + : -2, 0, 2, 4, 1, 0, 0, 0, 0, + : 2, 0, 2, 0, 0, 0, 0, 0, 0, + : -1, 0, 1, 0, 0, 0, 0, 0, 0, + : 1, 0, 0, 1, 0, 0, 0, 0, 0, + : 0, 1, 0, 2, 1, 0, 0, 0, 0, + : -1, 0, 4, 0, 1, 0, 0, 0, 0, + : -1, 0, 0, 4, 1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=161,170 ) / + : 2, 0, 2, 2, 1, 0, 0, 0, 0, + : 2, 1, 0, 0, 0, 0, 0, 0, 0, + : 0, 0, 5, -5, 5, -3, 0, 0, 0, + : 0, 0, 0, 0, 0, 0, 0, 2, 0, + : 0, 0, 1, -1, 1, 0, 0, -1, 0, + : 0, 0, -1, 1, -1, 1, 0, 0, 0, + : 0, 0, -1, 1, 0, 0, 2, 0, 0, + : 0, 0, 3, -3, 3, 0, 0, -1, 0, + : 0, 0, -8, 8, -7, 5, 0, 0, 0, + : 0, 0, -1, 1, -1, 0, 2, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=171,180 ) / + : 0, 0, -2, 2, -2, 2, 0, 0, 0, + : 0, 0, -6, 6, -6, 4, 0, 0, 0, + : 0, 0, -2, 2, -2, 0, 8, -3, 0, + : 0, 0, 6, -6, 6, 0, -8, 3, 0, + : 0, 0, 4, -4, 4, -2, 0, 0, 0, + : 0, 0, -3, 3, -3, 2, 0, 0, 0, + : 0, 0, 4, -4, 3, 0, -8, 3, 0, + : 0, 0, -4, 4, -5, 0, 8, -3, 0, + : 0, 0, 0, 0, 0, 2, 0, 0, 0, + : 0, 0, -4, 4, -4, 3, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=181,190 ) / + : 0, 1, -1, 1, -1, 0, 0, 1, 0, + : 0, 0, 0, 0, 0, 0, 0, 1, 0, + : 0, 0, 1, -1, 1, 1, 0, 0, 0, + : 0, 0, 2, -2, 2, 0, -2, 0, 0, + : 0, -1, -7, 7, -7, 5, 0, 0, 0, + : -2, 0, 2, 0, 2, 0, 0, -2, 0, + : -2, 0, 2, 0, 1, 0, 0, -3, 0, + : 0, 0, 2, -2, 2, 0, 0, -2, 0, + : 0, 0, 1, -1, 1, 0, 0, 1, 0, + : 0, 0, 0, 0, 0, 0, 0, 0, 2 / + DATA ( ( NA(I,J), I=1,9 ), J=191,NTERMS ) / + : 0, 0, 0, 0, 0, 0, 0, 0, 1, + : 2, 0, -2, 0, -2, 0, 0, 3, 0, + : 0, 0, 1, -1, 1, 0, 0, -2, 0, + : 0, 0, -7, 7, -7, 5, 0, 0, 0 / + +* Nutation series: longitude + DATA ( ( PSI(I,J), I=1,4 ), J=1,10 ) / + : 3341.5D0, 17206241.8D0, 3.1D0, 17409.5D0, + : -1716.8D0, -1317185.3D0, 1.4D0, -156.8D0, + : 285.7D0, -227667.0D0, 0.3D0, -23.5D0, + : -68.6D0, -207448.0D0, 0.0D0, -21.4D0, + : 950.3D0, 147607.9D0, -2.3D0, -355.0D0, + : -66.7D0, -51689.1D0, 0.2D0, 122.6D0, + : -108.6D0, 71117.6D0, 0.0D0, 7.0D0, + : 35.6D0, -38740.2D0, 0.1D0, -36.2D0, + : 85.4D0, -30127.6D0, 0.0D0, -3.1D0, + : 9.0D0, 21583.0D0, 0.1D0, -50.3D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=11,20 ) / + : 22.1D0, 12822.8D0, 0.0D0, 13.3D0, + : 3.4D0, 12350.8D0, 0.0D0, 1.3D0, + : -21.1D0, 15699.4D0, 0.0D0, 1.6D0, + : 4.2D0, 6313.8D0, 0.0D0, 6.2D0, + : -22.8D0, 5796.9D0, 0.0D0, 6.1D0, + : 15.7D0, -5961.1D0, 0.0D0, -0.6D0, + : 13.1D0, -5159.1D0, 0.0D0, -4.6D0, + : 1.8D0, 4592.7D0, 0.0D0, 4.5D0, + : -17.5D0, 6336.0D0, 0.0D0, 0.7D0, + : 16.3D0, -3851.1D0, 0.0D0, -0.4D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=21,30 ) / + : -2.8D0, 4771.7D0, 0.0D0, 0.5D0, + : 13.8D0, -3099.3D0, 0.0D0, -0.3D0, + : 0.2D0, 2860.3D0, 0.0D0, 0.3D0, + : 1.4D0, 2045.3D0, 0.0D0, 2.0D0, + : -8.6D0, 2922.6D0, 0.0D0, 0.3D0, + : -7.7D0, 2587.9D0, 0.0D0, 0.2D0, + : 8.8D0, -1408.1D0, 0.0D0, 3.7D0, + : 1.4D0, 1517.5D0, 0.0D0, 1.5D0, + : -1.9D0, -1579.7D0, 0.0D0, 7.7D0, + : 1.3D0, -2178.6D0, 0.0D0, -0.2D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=31,40 ) / + : -4.8D0, 1286.8D0, 0.0D0, 1.3D0, + : 6.3D0, 1267.2D0, 0.0D0, -4.0D0, + : -1.0D0, 1669.3D0, 0.0D0, -8.3D0, + : 2.4D0, -1020.0D0, 0.0D0, -0.9D0, + : 4.5D0, -766.9D0, 0.0D0, 0.0D0, + : -1.1D0, 756.5D0, 0.0D0, -1.7D0, + : -1.4D0, -1097.3D0, 0.0D0, -0.5D0, + : 2.6D0, -663.0D0, 0.0D0, -0.6D0, + : 0.8D0, -714.1D0, 0.0D0, 1.6D0, + : 0.4D0, -629.9D0, 0.0D0, -0.6D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=41,50 ) / + : 0.3D0, 580.4D0, 0.0D0, 0.6D0, + : -1.6D0, 577.3D0, 0.0D0, 0.5D0, + : -0.9D0, 644.4D0, 0.0D0, 0.0D0, + : 2.2D0, -534.0D0, 0.0D0, -0.5D0, + : -2.5D0, 493.3D0, 0.0D0, 0.5D0, + : -0.1D0, -477.3D0, 0.0D0, -2.4D0, + : -0.9D0, 735.0D0, 0.0D0, -1.7D0, + : 0.7D0, 406.2D0, 0.0D0, 0.4D0, + : -2.8D0, 656.9D0, 0.0D0, 0.0D0, + : 0.6D0, 358.0D0, 0.0D0, 2.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=51,60 ) / + : -0.7D0, 472.5D0, 0.0D0, -1.1D0, + : -0.1D0, -300.5D0, 0.0D0, 0.0D0, + : -1.2D0, 435.1D0, 0.0D0, -1.0D0, + : 1.8D0, -289.4D0, 0.0D0, 0.0D0, + : 0.6D0, -422.6D0, 0.0D0, 0.0D0, + : 0.8D0, -287.6D0, 0.0D0, 0.6D0, + : -38.6D0, -392.3D0, 0.0D0, 0.0D0, + : 0.7D0, -281.8D0, 0.0D0, 0.6D0, + : 0.6D0, -405.7D0, 0.0D0, 0.0D0, + : -1.2D0, 229.0D0, 0.0D0, 0.2D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=61,70 ) / + : 1.1D0, -264.3D0, 0.0D0, 0.5D0, + : -0.7D0, 247.9D0, 0.0D0, -0.5D0, + : -0.2D0, 218.0D0, 0.0D0, 0.2D0, + : 0.6D0, -339.0D0, 0.0D0, 0.8D0, + : -0.7D0, 198.7D0, 0.0D0, 0.2D0, + : -1.5D0, 334.0D0, 0.0D0, 0.0D0, + : 0.1D0, 334.0D0, 0.0D0, 0.0D0, + : -0.1D0, -198.1D0, 0.0D0, 0.0D0, + : -106.6D0, 0.0D0, 0.0D0, 0.0D0, + : -0.5D0, 165.8D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=71,80 ) / + : 0.0D0, 134.8D0, 0.0D0, 0.0D0, + : 0.9D0, -151.6D0, 0.0D0, 0.0D0, + : 0.0D0, -129.7D0, 0.0D0, 0.0D0, + : 0.8D0, -132.8D0, 0.0D0, -0.1D0, + : 0.5D0, -140.7D0, 0.0D0, 0.0D0, + : -0.1D0, 138.4D0, 0.0D0, 0.0D0, + : 0.0D0, 129.0D0, 0.0D0, -0.3D0, + : 0.5D0, -121.2D0, 0.0D0, 0.0D0, + : -0.3D0, 114.5D0, 0.0D0, 0.0D0, + : -0.1D0, 101.8D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=81,90 ) / + : -3.6D0, -101.9D0, 0.0D0, 0.0D0, + : 0.8D0, -109.4D0, 0.0D0, 0.0D0, + : 0.2D0, -97.0D0, 0.0D0, 0.0D0, + : -0.7D0, 157.3D0, 0.0D0, 0.0D0, + : 0.2D0, -83.3D0, 0.0D0, 0.0D0, + : -0.3D0, 93.3D0, 0.0D0, 0.0D0, + : -0.1D0, 92.1D0, 0.0D0, 0.0D0, + : -0.5D0, 133.6D0, 0.0D0, 0.0D0, + : -0.1D0, 81.5D0, 0.0D0, 0.0D0, + : 0.0D0, 123.9D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=91,100 ) / + : -0.3D0, 128.1D0, 0.0D0, 0.0D0, + : 0.1D0, 74.1D0, 0.0D0, -0.3D0, + : -0.2D0, -70.3D0, 0.0D0, 0.0D0, + : -0.4D0, 66.6D0, 0.0D0, 0.0D0, + : 0.1D0, -66.7D0, 0.0D0, 0.0D0, + : -0.7D0, 69.3D0, 0.0D0, -0.3D0, + : 0.0D0, -70.4D0, 0.0D0, 0.0D0, + : -0.1D0, 101.5D0, 0.0D0, 0.0D0, + : 0.5D0, -69.1D0, 0.0D0, 0.0D0, + : -0.2D0, 58.5D0, 0.0D0, 0.2D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=101,110 ) / + : 0.1D0, -94.9D0, 0.0D0, 0.2D0, + : 0.0D0, 52.9D0, 0.0D0, -0.2D0, + : 0.1D0, 86.7D0, 0.0D0, -0.2D0, + : -0.1D0, -59.2D0, 0.0D0, 0.2D0, + : 0.3D0, -58.8D0, 0.0D0, 0.1D0, + : -0.3D0, 49.0D0, 0.0D0, 0.0D0, + : -0.2D0, 56.9D0, 0.0D0, -0.1D0, + : 0.3D0, -50.2D0, 0.0D0, 0.0D0, + : -0.2D0, 53.4D0, 0.0D0, -0.1D0, + : 0.1D0, -76.5D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=111,120 ) / + : -0.2D0, 45.3D0, 0.0D0, 0.0D0, + : 0.1D0, -46.8D0, 0.0D0, 0.0D0, + : 0.2D0, -44.6D0, 0.0D0, 0.0D0, + : 0.2D0, -48.7D0, 0.0D0, 0.0D0, + : 0.1D0, -46.8D0, 0.0D0, 0.0D0, + : 0.1D0, -42.0D0, 0.0D0, 0.0D0, + : 0.0D0, 46.4D0, 0.0D0, -0.1D0, + : 0.2D0, -67.3D0, 0.0D0, 0.1D0, + : 0.0D0, -65.8D0, 0.0D0, 0.2D0, + : -0.1D0, -43.9D0, 0.0D0, 0.3D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=121,130 ) / + : 0.0D0, -38.9D0, 0.0D0, 0.0D0, + : -0.3D0, 63.9D0, 0.0D0, 0.0D0, + : -0.2D0, 41.2D0, 0.0D0, 0.0D0, + : 0.0D0, -36.1D0, 0.0D0, 0.2D0, + : -0.3D0, 58.5D0, 0.0D0, 0.0D0, + : -0.1D0, 36.1D0, 0.0D0, 0.0D0, + : 0.0D0, -39.7D0, 0.0D0, 0.0D0, + : 0.1D0, -57.7D0, 0.0D0, 0.0D0, + : -0.2D0, 33.4D0, 0.0D0, 0.0D0, + : 36.4D0, 0.0D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=131,140 ) / + : -0.1D0, 55.7D0, 0.0D0, -0.1D0, + : 0.1D0, -35.4D0, 0.0D0, 0.0D0, + : 0.1D0, -31.0D0, 0.0D0, 0.0D0, + : -0.1D0, 30.1D0, 0.0D0, 0.0D0, + : -0.3D0, 49.2D0, 0.0D0, 0.0D0, + : -0.2D0, 49.1D0, 0.0D0, 0.0D0, + : -0.1D0, 33.6D0, 0.0D0, 0.0D0, + : 0.1D0, -33.5D0, 0.0D0, 0.0D0, + : 0.1D0, -31.0D0, 0.0D0, 0.0D0, + : -0.1D0, 28.0D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=141,150 ) / + : 0.1D0, -25.2D0, 0.0D0, 0.0D0, + : 0.1D0, -26.2D0, 0.0D0, 0.0D0, + : -0.2D0, 41.5D0, 0.0D0, 0.0D0, + : 0.0D0, 24.5D0, 0.0D0, 0.1D0, + : -16.2D0, 0.0D0, 0.0D0, 0.0D0, + : 0.0D0, -22.3D0, 0.0D0, 0.0D0, + : 0.0D0, 23.1D0, 0.0D0, 0.0D0, + : -0.1D0, 37.5D0, 0.0D0, 0.0D0, + : 0.2D0, -25.7D0, 0.0D0, 0.0D0, + : 0.0D0, 25.2D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=151,160 ) / + : 0.1D0, -24.5D0, 0.0D0, 0.0D0, + : -0.1D0, 24.3D0, 0.0D0, 0.0D0, + : 0.1D0, -20.7D0, 0.0D0, 0.0D0, + : 0.1D0, -20.8D0, 0.0D0, 0.0D0, + : -0.2D0, 33.4D0, 0.0D0, 0.0D0, + : 32.9D0, 0.0D0, 0.0D0, 0.0D0, + : 0.1D0, -32.6D0, 0.0D0, 0.0D0, + : 0.0D0, 19.9D0, 0.0D0, 0.0D0, + : -0.1D0, 19.6D0, 0.0D0, 0.0D0, + : 0.0D0, -18.7D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=161,170 ) / + : 0.1D0, -19.0D0, 0.0D0, 0.0D0, + : 0.1D0, -28.6D0, 0.0D0, 0.0D0, + : 4.0D0, 178.8D0,-11.8D0, 0.3D0, + : 39.8D0, -107.3D0, -5.6D0, -1.0D0, + : 9.9D0, 164.0D0, -4.1D0, 0.1D0, + : -4.8D0, -135.3D0, -3.4D0, -0.1D0, + : 50.5D0, 75.0D0, 1.4D0, -1.2D0, + : -1.1D0, -53.5D0, 1.3D0, 0.0D0, + : -45.0D0, -2.4D0, -0.4D0, 6.6D0, + : -11.5D0, -61.0D0, -0.9D0, 0.4D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=171,180 ) / + : 4.4D0, -68.4D0, -3.4D0, 0.0D0, + : 7.7D0, -47.1D0, -4.7D0, -1.0D0, + : -42.9D0, -12.6D0, -1.2D0, 4.2D0, + : -42.8D0, 12.7D0, -1.2D0, -4.2D0, + : -7.6D0, -44.1D0, 2.1D0, -0.5D0, + : -64.1D0, 1.7D0, 0.2D0, 4.5D0, + : 36.4D0, -10.4D0, 1.0D0, 3.5D0, + : 35.6D0, 10.2D0, 1.0D0, -3.5D0, + : -1.7D0, 39.5D0, 2.0D0, 0.0D0, + : 50.9D0, -8.2D0, -0.8D0, -5.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=181,190 ) / + : 0.0D0, 52.3D0, 1.2D0, 0.0D0, + : -42.9D0, -17.8D0, 0.4D0, 0.0D0, + : 2.6D0, 34.3D0, 0.8D0, 0.0D0, + : -0.8D0, -48.6D0, 2.4D0, -0.1D0, + : -4.9D0, 30.5D0, 3.7D0, 0.7D0, + : 0.0D0, -43.6D0, 2.1D0, 0.0D0, + : 0.0D0, -25.4D0, 1.2D0, 0.0D0, + : 2.0D0, 40.9D0, -2.0D0, 0.0D0, + : -2.1D0, 26.1D0, 0.6D0, 0.0D0, + : 22.6D0, -3.2D0, -0.5D0, -0.5D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=191,NTERMS ) / + : -7.6D0, 24.9D0, -0.4D0, -0.2D0, + : -6.2D0, 34.9D0, 1.7D0, 0.3D0, + : 2.0D0, 17.4D0, -0.4D0, 0.1D0, + : -3.9D0, 20.5D0, 2.4D0, 0.6D0 / + +* Nutation series: obliquity + DATA ( ( EPS(I,J), I=1,4 ), J=1,10 ) / + : 9205365.8D0, -1506.2D0, 885.7D0, -0.2D0, + : 573095.9D0, -570.2D0, -305.0D0, -0.3D0, + : 97845.5D0, 147.8D0, -48.8D0, -0.2D0, + : -89753.6D0, 28.0D0, 46.9D0, 0.0D0, + : 7406.7D0, -327.1D0, -18.2D0, 0.8D0, + : 22442.3D0, -22.3D0, -67.6D0, 0.0D0, + : -683.6D0, 46.8D0, 0.0D0, 0.0D0, + : 20070.7D0, 36.0D0, 1.6D0, 0.0D0, + : 12893.8D0, 39.5D0, -6.2D0, 0.0D0, + : -9593.2D0, 14.4D0, 30.2D0, -0.1D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=11,20 ) / + : -6899.5D0, 4.8D0, -0.6D0, 0.0D0, + : -5332.5D0, -0.1D0, 2.7D0, 0.0D0, + : -125.2D0, 10.5D0, 0.0D0, 0.0D0, + : -3323.4D0, -0.9D0, -0.3D0, 0.0D0, + : 3142.3D0, 8.9D0, 0.3D0, 0.0D0, + : 2552.5D0, 7.3D0, -1.2D0, 0.0D0, + : 2634.4D0, 8.8D0, 0.2D0, 0.0D0, + : -2424.4D0, 1.6D0, -0.4D0, 0.0D0, + : -123.3D0, 3.9D0, 0.0D0, 0.0D0, + : 1642.4D0, 7.3D0, -0.8D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=21,30 ) / + : 47.9D0, 3.2D0, 0.0D0, 0.0D0, + : 1321.2D0, 6.2D0, -0.6D0, 0.0D0, + : -1234.1D0, -0.3D0, 0.6D0, 0.0D0, + : -1076.5D0, -0.3D0, 0.0D0, 0.0D0, + : -61.6D0, 1.8D0, 0.0D0, 0.0D0, + : -55.4D0, 1.6D0, 0.0D0, 0.0D0, + : 856.9D0, -4.9D0, -2.1D0, 0.0D0, + : -800.7D0, -0.1D0, 0.0D0, 0.0D0, + : 685.1D0, -0.6D0, -3.8D0, 0.0D0, + : -16.9D0, -1.5D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=31,40 ) / + : 695.7D0, 1.8D0, 0.0D0, 0.0D0, + : 642.2D0, -2.6D0, -1.6D0, 0.0D0, + : 13.3D0, 1.1D0, -0.1D0, 0.0D0, + : 521.9D0, 1.6D0, 0.0D0, 0.0D0, + : 325.8D0, 2.0D0, -0.1D0, 0.0D0, + : -325.1D0, -0.5D0, 0.9D0, 0.0D0, + : 10.1D0, 0.3D0, 0.0D0, 0.0D0, + : 334.5D0, 1.6D0, 0.0D0, 0.0D0, + : 307.1D0, 0.4D0, -0.9D0, 0.0D0, + : 327.2D0, 0.5D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=41,50 ) / + : -304.6D0, -0.1D0, 0.0D0, 0.0D0, + : 304.0D0, 0.6D0, 0.0D0, 0.0D0, + : -276.8D0, -0.5D0, 0.1D0, 0.0D0, + : 268.9D0, 1.3D0, 0.0D0, 0.0D0, + : 271.8D0, 1.1D0, 0.0D0, 0.0D0, + : 271.5D0, -0.4D0, -0.8D0, 0.0D0, + : -5.2D0, 0.5D0, 0.0D0, 0.0D0, + : -220.5D0, 0.1D0, 0.0D0, 0.0D0, + : -20.1D0, 0.3D0, 0.0D0, 0.0D0, + : -191.0D0, 0.1D0, 0.5D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=51,60 ) / + : -4.1D0, 0.3D0, 0.0D0, 0.0D0, + : 130.6D0, -0.1D0, 0.0D0, 0.0D0, + : 3.0D0, 0.3D0, 0.0D0, 0.0D0, + : 122.9D0, 0.8D0, 0.0D0, 0.0D0, + : 3.7D0, -0.3D0, 0.0D0, 0.0D0, + : 123.1D0, 0.4D0, -0.3D0, 0.0D0, + : -52.7D0, 15.3D0, 0.0D0, 0.0D0, + : 120.7D0, 0.3D0, -0.3D0, 0.0D0, + : 4.0D0, -0.3D0, 0.0D0, 0.0D0, + : 126.5D0, 0.5D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=61,70 ) / + : 112.7D0, 0.5D0, -0.3D0, 0.0D0, + : -106.1D0, -0.3D0, 0.3D0, 0.0D0, + : -112.9D0, -0.2D0, 0.0D0, 0.0D0, + : 3.6D0, -0.2D0, 0.0D0, 0.0D0, + : 107.4D0, 0.3D0, 0.0D0, 0.0D0, + : -10.9D0, 0.2D0, 0.0D0, 0.0D0, + : -0.9D0, 0.0D0, 0.0D0, 0.0D0, + : 85.4D0, 0.0D0, 0.0D0, 0.0D0, + : 0.0D0, -88.8D0, 0.0D0, 0.0D0, + : -71.0D0, -0.2D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=71,80 ) / + : -70.3D0, 0.0D0, 0.0D0, 0.0D0, + : 64.5D0, 0.4D0, 0.0D0, 0.0D0, + : 69.8D0, 0.0D0, 0.0D0, 0.0D0, + : 66.1D0, 0.4D0, 0.0D0, 0.0D0, + : -61.0D0, -0.2D0, 0.0D0, 0.0D0, + : -59.5D0, -0.1D0, 0.0D0, 0.0D0, + : -55.6D0, 0.0D0, 0.2D0, 0.0D0, + : 51.7D0, 0.2D0, 0.0D0, 0.0D0, + : -49.0D0, -0.1D0, 0.0D0, 0.0D0, + : -52.7D0, -0.1D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=81,90 ) / + : -49.6D0, 1.4D0, 0.0D0, 0.0D0, + : 46.3D0, 0.4D0, 0.0D0, 0.0D0, + : 49.6D0, 0.1D0, 0.0D0, 0.0D0, + : -5.1D0, 0.1D0, 0.0D0, 0.0D0, + : -44.0D0, -0.1D0, 0.0D0, 0.0D0, + : -39.9D0, -0.1D0, 0.0D0, 0.0D0, + : -39.5D0, -0.1D0, 0.0D0, 0.0D0, + : -3.9D0, 0.1D0, 0.0D0, 0.0D0, + : -42.1D0, -0.1D0, 0.0D0, 0.0D0, + : -17.2D0, 0.1D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=91,100 ) / + : -2.3D0, 0.1D0, 0.0D0, 0.0D0, + : -39.2D0, 0.0D0, 0.0D0, 0.0D0, + : -38.4D0, 0.1D0, 0.0D0, 0.0D0, + : 36.8D0, 0.2D0, 0.0D0, 0.0D0, + : 34.6D0, 0.1D0, 0.0D0, 0.0D0, + : -32.7D0, 0.3D0, 0.0D0, 0.0D0, + : 30.4D0, 0.0D0, 0.0D0, 0.0D0, + : 0.4D0, 0.1D0, 0.0D0, 0.0D0, + : 29.3D0, 0.2D0, 0.0D0, 0.0D0, + : 31.6D0, 0.1D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=101,110 ) / + : 0.8D0, -0.1D0, 0.0D0, 0.0D0, + : -27.9D0, 0.0D0, 0.0D0, 0.0D0, + : 2.9D0, 0.0D0, 0.0D0, 0.0D0, + : -25.3D0, 0.0D0, 0.0D0, 0.0D0, + : 25.0D0, 0.1D0, 0.0D0, 0.0D0, + : 27.5D0, 0.1D0, 0.0D0, 0.0D0, + : -24.4D0, -0.1D0, 0.0D0, 0.0D0, + : 24.9D0, 0.2D0, 0.0D0, 0.0D0, + : -22.8D0, -0.1D0, 0.0D0, 0.0D0, + : 0.9D0, -0.1D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=111,120 ) / + : 24.4D0, 0.1D0, 0.0D0, 0.0D0, + : 23.9D0, 0.1D0, 0.0D0, 0.0D0, + : 22.5D0, 0.1D0, 0.0D0, 0.0D0, + : 20.8D0, 0.1D0, 0.0D0, 0.0D0, + : 20.1D0, 0.0D0, 0.0D0, 0.0D0, + : 21.5D0, 0.1D0, 0.0D0, 0.0D0, + : -20.0D0, 0.0D0, 0.0D0, 0.0D0, + : 1.4D0, 0.0D0, 0.0D0, 0.0D0, + : -0.2D0, -0.1D0, 0.0D0, 0.0D0, + : 19.0D0, 0.0D0, -0.1D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=121,130 ) / + : 20.5D0, 0.0D0, 0.0D0, 0.0D0, + : -2.0D0, 0.0D0, 0.0D0, 0.0D0, + : -17.6D0, -0.1D0, 0.0D0, 0.0D0, + : 19.0D0, 0.0D0, 0.0D0, 0.0D0, + : -2.4D0, 0.0D0, 0.0D0, 0.0D0, + : -18.4D0, -0.1D0, 0.0D0, 0.0D0, + : 17.1D0, 0.0D0, 0.0D0, 0.0D0, + : 0.4D0, 0.0D0, 0.0D0, 0.0D0, + : 18.4D0, 0.1D0, 0.0D0, 0.0D0, + : 0.0D0, 17.4D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=131,140 ) / + : -0.6D0, 0.0D0, 0.0D0, 0.0D0, + : -15.4D0, 0.0D0, 0.0D0, 0.0D0, + : -16.8D0, -0.1D0, 0.0D0, 0.0D0, + : 16.3D0, 0.0D0, 0.0D0, 0.0D0, + : -2.0D0, 0.0D0, 0.0D0, 0.0D0, + : -1.5D0, 0.0D0, 0.0D0, 0.0D0, + : -14.3D0, -0.1D0, 0.0D0, 0.0D0, + : 14.4D0, 0.0D0, 0.0D0, 0.0D0, + : -13.4D0, 0.0D0, 0.0D0, 0.0D0, + : -14.3D0, -0.1D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=141,150 ) / + : -13.7D0, 0.0D0, 0.0D0, 0.0D0, + : 13.1D0, 0.1D0, 0.0D0, 0.0D0, + : -1.7D0, 0.0D0, 0.0D0, 0.0D0, + : -12.8D0, 0.0D0, 0.0D0, 0.0D0, + : 0.0D0, -14.4D0, 0.0D0, 0.0D0, + : 12.4D0, 0.0D0, 0.0D0, 0.0D0, + : -12.0D0, 0.0D0, 0.0D0, 0.0D0, + : -0.8D0, 0.0D0, 0.0D0, 0.0D0, + : 10.9D0, 0.1D0, 0.0D0, 0.0D0, + : -10.8D0, 0.0D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=151,160 ) / + : 10.5D0, 0.0D0, 0.0D0, 0.0D0, + : -10.4D0, 0.0D0, 0.0D0, 0.0D0, + : -11.2D0, 0.0D0, 0.0D0, 0.0D0, + : 10.5D0, 0.1D0, 0.0D0, 0.0D0, + : -1.4D0, 0.0D0, 0.0D0, 0.0D0, + : 0.0D0, 0.1D0, 0.0D0, 0.0D0, + : 0.7D0, 0.0D0, 0.0D0, 0.0D0, + : -10.3D0, 0.0D0, 0.0D0, 0.0D0, + : -10.0D0, 0.0D0, 0.0D0, 0.0D0, + : 9.6D0, 0.0D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=161,170 ) / + : 9.4D0, 0.1D0, 0.0D0, 0.0D0, + : 0.6D0, 0.0D0, 0.0D0, 0.0D0, + : -87.7D0, 4.4D0, -0.4D0, -6.3D0, + : 46.3D0, 22.4D0, 0.5D0, -2.4D0, + : 15.6D0, -3.4D0, 0.1D0, 0.4D0, + : 5.2D0, 5.8D0, 0.2D0, -0.1D0, + : -30.1D0, 26.9D0, 0.7D0, 0.0D0, + : 23.2D0, -0.5D0, 0.0D0, 0.6D0, + : 1.0D0, 23.2D0, 3.4D0, 0.0D0, + : -12.2D0, -4.3D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=171,180 ) / + : -2.1D0, -3.7D0, -0.2D0, 0.1D0, + : -18.6D0, -3.8D0, -0.4D0, 1.8D0, + : 5.5D0, -18.7D0, -1.8D0, -0.5D0, + : -5.5D0, -18.7D0, 1.8D0, -0.5D0, + : 18.4D0, -3.6D0, 0.3D0, 0.9D0, + : -0.6D0, 1.3D0, 0.0D0, 0.0D0, + : -5.6D0, -19.5D0, 1.9D0, 0.0D0, + : 5.5D0, -19.1D0, -1.9D0, 0.0D0, + : -17.3D0, -0.8D0, 0.0D0, 0.9D0, + : -3.2D0, -8.3D0, -0.8D0, 0.3D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=181,190 ) / + : -0.1D0, 0.0D0, 0.0D0, 0.0D0, + : -5.4D0, 7.8D0, -0.3D0, 0.0D0, + : -14.8D0, 1.4D0, 0.0D0, 0.3D0, + : -3.8D0, 0.4D0, 0.0D0, -0.2D0, + : 12.6D0, 3.2D0, 0.5D0, -1.5D0, + : 0.1D0, 0.0D0, 0.0D0, 0.0D0, + : -13.6D0, 2.4D0, -0.1D0, 0.0D0, + : 0.9D0, 1.2D0, 0.0D0, 0.0D0, + : -11.9D0, -0.5D0, 0.0D0, 0.3D0, + : 0.4D0, 12.0D0, 0.3D0, -0.2D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=191,NTERMS ) / + : 8.3D0, 6.1D0, -0.1D0, 0.1D0, + : 0.0D0, 0.0D0, 0.0D0, 0.0D0, + : 0.4D0, -10.8D0, 0.3D0, 0.0D0, + : 9.6D0, 2.2D0, 0.3D0, -1.2D0 / + + + +* Interval between fundamental epoch J2000.0 and given epoch (JC). + T = (DATE-DJM0)/DJC + +* Mean anomaly of the Moon. + EL = 134.96340251D0*DD2R+ + : MOD(T*(1717915923.2178D0+ + : T*( 31.8792D0+ + : T*( 0.051635D0+ + : T*( - 0.00024470D0)))),TURNAS)*DAS2R + +* Mean anomaly of the Sun. + ELP = 357.52910918D0*DD2R+ + : MOD(T*( 129596581.0481D0+ + : T*( - 0.5532D0+ + : T*( 0.000136D0+ + : T*( - 0.00001149D0)))),TURNAS)*DAS2R + +* Mean argument of the latitude of the Moon. + F = 93.27209062D0*DD2R+ + : MOD(T*(1739527262.8478D0+ + : T*( - 12.7512D0+ + : T*( - 0.001037D0+ + : T*( 0.00000417D0)))),TURNAS)*DAS2R + +* Mean elongation of the Moon from the Sun. + D = 297.85019547D0*DD2R+ + : MOD(T*(1602961601.2090D0+ + : T*( - 6.3706D0+ + : T*( 0.006539D0+ + : T*( - 0.00003169D0)))),TURNAS)*DAS2R + +* Mean longitude of the ascending node of the Moon. + OM = 125.04455501D0*DD2R+ + : MOD(T*( - 6962890.5431D0+ + : T*( 7.4722D0+ + : T*( 0.007702D0+ + : T*( - 0.00005939D0)))),TURNAS)*DAS2R + +* Mean longitude of Venus. + VE = 181.97980085D0*DD2R+MOD(210664136.433548D0*T,TURNAS)*DAS2R + +* Mean longitude of Mars. + MA = 355.43299958D0*DD2R+MOD( 68905077.493988D0*T,TURNAS)*DAS2R + +* Mean longitude of Jupiter. + JU = 34.35151874D0*DD2R+MOD( 10925660.377991D0*T,TURNAS)*DAS2R + +* Mean longitude of Saturn. + SA = 50.07744430D0*DD2R+MOD( 4399609.855732D0*T,TURNAS)*DAS2R + +* Geodesic nutation (Fukushima 1991) in microarcsec. + DP = -153.1D0*SIN(ELP)-1.9D0*SIN(2D0*ELP) + DE = 0D0 + +* Shirai & Fukushima (2001) nutation series. + DO J=NTERMS,1,-1 + THETA = DBLE(NA(1,J))*EL+ + : DBLE(NA(2,J))*ELP+ + : DBLE(NA(3,J))*F+ + : DBLE(NA(4,J))*D+ + : DBLE(NA(5,J))*OM+ + : DBLE(NA(6,J))*VE+ + : DBLE(NA(7,J))*MA+ + : DBLE(NA(8,J))*JU+ + : DBLE(NA(9,J))*SA + C = COS(THETA) + S = SIN(THETA) + DP = DP+(PSI(1,J)+PSI(3,J)*T)*C+(PSI(2,J)+PSI(4,J)*T)*S + DE = DE+(EPS(1,J)+EPS(3,J)*T)*C+(EPS(2,J)+EPS(4,J)*T)*S + END DO + +* Change of units, and addition of the precession correction. + DPSI = (DP*1D-6-0.042888D0-0.29856D0*T)*DAS2R + DEPS = (DE*1D-6-0.005171D0-0.02408D0*T)*DAS2R + +* Mean obliquity of date (Simon et al. 1994). + EPS0 = (84381.412D0+ + : (-46.80927D0+ + : (-0.000152D0+ + : (0.0019989D0+ + : (-0.00000051D0+ + : (-0.000000025D0)*T)*T)*T)*T)*T)*DAS2R + + END + SUBROUTINE sla_NUT (DATE, RMATN) +*+ +* - - - - +* N U T +* - - - - +* +* Form the matrix of nutation for a given date - Shirai & Fukushima +* 2001 theory (double precision) +* +* Reference: +* Shirai, T. & Fukushima, T., Astron.J. 121, 3270-3283 (2001). +* +* Given: +* DATE d TDB (loosely ET) as Modified Julian Date +* (=JD-2400000.5) +* Returned: +* RMATN d(3,3) nutation matrix +* +* Notes: +* +* 1 The matrix is in the sense v(true) = rmatn * v(mean) . +* where v(true) is the star vector relative to the true equator and +* equinox of date and v(mean) is the star vector relative to the +* mean equator and equinox of date. +* +* 2 The matrix represents forced nutation (but not free core +* nutation) plus corrections to the IAU~1976 precession model. +* +* 3 Earth attitude predictions made by combining the present nutation +* matrix with IAU~1976 precession are accurate to 1~mas (with +* respect to the ICRS) for a few decades around 2000. +* +* 4 The distinction between the required TDB and TT is always +* negligible. Moreover, for all but the most critical applications +* UTC is adequate. +* +* Called: sla_NUTC, sla_DEULER +* +* Last revision: 1 December 2005 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE,RMATN(3,3) + + DOUBLE PRECISION DPSI,DEPS,EPS0 + + + +* Nutation components and mean obliquity + CALL sla_NUTC(DATE,DPSI,DEPS,EPS0) + +* Rotation matrix + CALL sla_DEULER('XZX',EPS0,-DPSI,-(EPS0+DEPS),RMATN) + + END + SUBROUTINE sla_PREBN (BEP0, BEP1, RMATP) +*+ +* - - - - - - +* P R E B N +* - - - - - - +* +* Generate the matrix of precession between two epochs, +* using the old, pre-IAU1976, Bessel-Newcomb model, using +* Kinoshita's formulation (double precision) +* +* Given: +* BEP0 dp beginning Besselian epoch +* BEP1 dp ending Besselian epoch +* +* Returned: +* RMATP dp(3,3) precession matrix +* +* The matrix is in the sense V(BEP1) = RMATP * V(BEP0) +* +* Reference: +* Kinoshita, H. (1975) 'Formulas for precession', SAO Special +* Report No. 364, Smithsonian Institution Astrophysical +* Observatory, Cambridge, Massachusetts. +* +* Called: sla_DEULER +* +* P.T.Wallace Starlink 23 August 1996 +* +* Copyright (C) 1996 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION BEP0,BEP1,RMATP(3,3) + +* Arc seconds to radians + DOUBLE PRECISION AS2R + PARAMETER (AS2R=0.484813681109535994D-5) + + DOUBLE PRECISION BIGT,T,TAS2R,W,ZETA,Z,THETA + + + +* Interval between basic epoch B1850.0 and beginning epoch in TC + BIGT = (BEP0-1850D0)/100D0 + +* Interval over which precession required, in tropical centuries + T = (BEP1-BEP0)/100D0 + +* Euler angles + TAS2R = T*AS2R + W = 2303.5548D0+(1.39720D0+0.000059D0*BIGT)*BIGT + + ZETA = (W+(0.30242D0-0.000269D0*BIGT+0.017996D0*T)*T)*TAS2R + Z = (W+(1.09478D0+0.000387D0*BIGT+0.018324D0*T)*T)*TAS2R + THETA = (2005.1125D0+(-0.85294D0-0.000365D0*BIGT)*BIGT+ + : (-0.42647D0-0.000365D0*BIGT-0.041802D0*T)*T)*TAS2R + +* Rotation matrix + CALL sla_DEULER('ZYZ',-ZETA,THETA,-Z,RMATP) + + END + SUBROUTINE sla_PRECES (SYSTEM, EP0, EP1, RA, DC) +*+ +* - - - - - - - +* P R E C E S +* - - - - - - - +* +* Precession - either FK4 (Bessel-Newcomb, pre IAU 1976) or +* FK5 (Fricke, post IAU 1976) as required. +* +* Given: +* SYSTEM char precession to be applied: 'FK4' or 'FK5' +* EP0,EP1 dp starting and ending epoch +* RA,DC dp RA,Dec, mean equator & equinox of epoch EP0 +* +* Returned: +* RA,DC dp RA,Dec, mean equator & equinox of epoch EP1 +* +* Called: sla_DRANRM, sla_PREBN, sla_PREC, sla_DCS2C, +* sla_DMXV, sla_DCC2S +* +* Notes: +* +* 1) Lowercase characters in SYSTEM are acceptable. +* +* 2) The epochs are Besselian if SYSTEM='FK4' and Julian if 'FK5'. +* For example, to precess coordinates in the old system from +* equinox 1900.0 to 1950.0 the call would be: +* CALL sla_PRECES ('FK4', 1900D0, 1950D0, RA, DC) +* +* 3) This routine will NOT correctly convert between the old and +* the new systems - for example conversion from B1950 to J2000. +* For these purposes see sla_FK425, sla_FK524, sla_FK45Z and +* sla_FK54Z. +* +* 4) If an invalid SYSTEM is supplied, values of -99D0,-99D0 will +* be returned for both RA and DC. +* +* P.T.Wallace Starlink 20 April 1990 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + CHARACTER SYSTEM*(*) + DOUBLE PRECISION EP0,EP1,RA,DC + + DOUBLE PRECISION PM(3,3),V1(3),V2(3) + CHARACTER SYSUC*3 + + DOUBLE PRECISION sla_DRANRM + + + + +* Convert to uppercase and validate SYSTEM + SYSUC=SYSTEM + IF (SYSUC(1:1).EQ.'f') SYSUC(1:1)='F' + IF (SYSUC(2:2).EQ.'k') SYSUC(2:2)='K' + IF (SYSUC.NE.'FK4'.AND.SYSUC.NE.'FK5') THEN + RA=-99D0 + DC=-99D0 + ELSE + +* Generate appropriate precession matrix + IF (SYSUC.EQ.'FK4') THEN + CALL sla_PREBN(EP0,EP1,PM) + ELSE + CALL sla_PREC(EP0,EP1,PM) + END IF + +* Convert RA,Dec to x,y,z + CALL sla_DCS2C(RA,DC,V1) + +* Precess + CALL sla_DMXV(PM,V1,V2) + +* Back to RA,Dec + CALL sla_DCC2S(V2,RA,DC) + RA=sla_DRANRM(RA) + + END IF + + END + SUBROUTINE sla_PREC (EP0, EP1, RMATP) +*+ +* - - - - - +* P R E C +* - - - - - +* +* Form the matrix of precession between two epochs (IAU 1976, FK5) +* (double precision) +* +* Given: +* EP0 dp beginning epoch +* EP1 dp ending epoch +* +* Returned: +* RMATP dp(3,3) precession matrix +* +* Notes: +* +* 1) The epochs are TDB (loosely ET) Julian epochs. +* +* 2) The matrix is in the sense V(EP1) = RMATP * V(EP0) +* +* 3) Though the matrix method itself is rigorous, the precession +* angles are expressed through canonical polynomials which are +* valid only for a limited time span. There are also known +* errors in the IAU precession rate. The absolute accuracy +* of the present formulation is better than 0.1 arcsec from +* 1960AD to 2040AD, better than 1 arcsec from 1640AD to 2360AD, +* and remains below 3 arcsec for the whole of the period +* 500BC to 3000AD. The errors exceed 10 arcsec outside the +* range 1200BC to 3900AD, exceed 100 arcsec outside 4200BC to +* 5600AD and exceed 1000 arcsec outside 6800BC to 8200AD. +* The SLALIB routine sla_PRECL implements a more elaborate +* model which is suitable for problems spanning several +* thousand years. +* +* References: +* Lieske,J.H., 1979. Astron.Astrophys.,73,282. +* equations (6) & (7), p283. +* Kaplan,G.H., 1981. USNO circular no. 163, pA2. +* +* Called: sla_DEULER +* +* P.T.Wallace Starlink 23 August 1996 +* +* Copyright (C) 1996 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION EP0,EP1,RMATP(3,3) + +* Arc seconds to radians + DOUBLE PRECISION AS2R + PARAMETER (AS2R=0.484813681109535994D-5) + + DOUBLE PRECISION T0,T,TAS2R,W,ZETA,Z,THETA + + + +* Interval between basic epoch J2000.0 and beginning epoch (JC) + T0 = (EP0-2000D0)/100D0 + +* Interval over which precession required (JC) + T = (EP1-EP0)/100D0 + +* Euler angles + TAS2R = T*AS2R + W = 2306.2181D0+(1.39656D0-0.000139D0*T0)*T0 + + ZETA = (W+((0.30188D0-0.000344D0*T0)+0.017998D0*T)*T)*TAS2R + Z = (W+((1.09468D0+0.000066D0*T0)+0.018203D0*T)*T)*TAS2R + THETA = ((2004.3109D0+(-0.85330D0-0.000217D0*T0)*T0) + : +((-0.42665D0-0.000217D0*T0)-0.041833D0*T)*T)*TAS2R + +* Rotation matrix + CALL sla_DEULER('ZYZ',-ZETA,THETA,-Z,RMATP) + + END + SUBROUTINE sla_PVOBS (P, H, STL, PV) +*+ +* - - - - - - +* P V O B S +* - - - - - - +* +* Position and velocity of an observing station (double precision) +* +* Given: +* P dp latitude (geodetic, radians) +* H dp height above reference spheroid (geodetic, metres) +* STL dp local apparent sidereal time (radians) +* +* Returned: +* PV dp(6) position/velocity 6-vector (AU, AU/s, true equator +* and equinox of date) +* +* Called: sla_GEOC +* +* IAU 1976 constants are used. +* +* P.T.Wallace Starlink 14 November 1994 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION P,H,STL,PV(6) + + DOUBLE PRECISION R,Z,S,C,V + +* Mean sidereal rate (at J2000) in radians per (UT1) second + DOUBLE PRECISION SR + PARAMETER (SR=7.292115855306589D-5) + + + +* Geodetic to geocentric conversion + CALL sla_GEOC(P,H,R,Z) + +* Functions of ST + S=SIN(STL) + C=COS(STL) + +* Speed + V=SR*R + +* Position + PV(1)=R*C + PV(2)=R*S + PV(3)=Z + +* Velocity + PV(4)=-V*S + PV(5)=V*C + PV(6)=0D0 + + END diff --git a/lib/sleep.h b/lib/sleep.h index c111cef0..df60bc92 100755 --- a/lib/sleep.h +++ b/lib/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 -# define sleep(t) _sleep((t) * 1000) -# else -# include -# 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 -# 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 +# define sleep(t) _sleep((t) * 1000) +# else +# include +# 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 +# ifndef _NEED_SLEEP_ONLY +# define msleep(t) usleep((t) * 1000) +# endif +#endif + +#endif /* _SLEEP_H */ diff --git a/lib/sleep_msec.f90 b/lib/sleep_msec.f90 index 21ab6182..1a8dbe4f 100755 --- a/lib/sleep_msec.f90 +++ b/lib/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/lib/slope.f90 b/lib/slope.f90 index c590ba6a..e8420979 100755 --- a/lib/slope.f90 +++ b/lib/slope.f90 @@ -1,40 +1,40 @@ -subroutine slope(y,npts,xpk) - -! Remove best-fit slope from data in y(i). When fitting the straight line, -! ignore the peak around xpk +/- 4 bins - - real y(npts) - - sumw=0. - sumx=0. - sumy=0. - sumx2=0. - sumxy=0. - sumy2=0. - do i=1,npts - if(abs(i-xpk).gt.4.0) then - sumw=sumw + 1.0 - x=i - sumx=sumx + x - sumy=sumy + y(i) - sumx2=sumx2 + x*x - sumxy=sumxy + x*y(i) - sumy2=sumy2 + y(i)**2 - endif - enddo - - delta=sumw*sumx2 - sumx**2 - a=(sumx2*sumy - sumx*sumxy) / delta - b=(sumw*sumxy - sumx*sumy) / delta - - sq=0. - do i=1,npts - y(i)=y(i)-(a + b*i) - if(abs(i-xpk).gt.4.0) sq=sq + y(i)**2 - enddo - rms=sqrt(sq/(sumw-4.0)) - y=y/rms - - return -end subroutine slope - +subroutine slope(y,npts,xpk) + +! Remove best-fit slope from data in y(i). When fitting the straight line, +! ignore the peak around xpk +/- 4 bins + + real y(npts) + + sumw=0. + sumx=0. + sumy=0. + sumx2=0. + sumxy=0. + sumy2=0. + do i=1,npts + if(abs(i-xpk).gt.4.0) then + sumw=sumw + 1.0 + x=i + sumx=sumx + x + sumy=sumy + y(i) + sumx2=sumx2 + x*x + sumxy=sumxy + x*y(i) + sumy2=sumy2 + y(i)**2 + endif + enddo + + delta=sumw*sumx2 - sumx**2 + a=(sumx2*sumy - sumx*sumxy) / delta + b=(sumw*sumxy - sumx*sumy) / delta + + sq=0. + do i=1,npts + y(i)=y(i)-(a + b*i) + if(abs(i-xpk).gt.4.0) sq=sq + y(i)**2 + enddo + rms=sqrt(sq/(sumw-4.0)) + y=y/rms + + return +end subroutine slope + diff --git a/lib/smo.f90 b/lib/smo.f90 index 87994310..c42de7c6 100755 --- a/lib/smo.f90 +++ b/lib/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/lib/smolorentz.f90 b/lib/smolorentz.f90 index 35c5c88e..70132f59 100755 --- a/lib/smolorentz.f90 +++ b/lib/smolorentz.f90 @@ -1,42 +1,42 @@ -!program smolorentz -subroutine smolorentz(s1,nz,w,s2) - -! parameter (nz=512) - real s1(nz),s2(nz) - real y(-50:50) -! character*8 arg - -! s1=0. -! s1(256)=1. - -! call getarg(1,arg) -! read(arg,*) w - - do i=-50,50 - x=i - z=x/(0.5*w) - y(i)=0. - if(abs(z).lt.3.0) then - d=1.0 + z*z - y(i)=(1.0/d - 0.1)*10.0/9.0 - endif - enddo - - jz=nint(1.5*w) - if(jz.gt.50) jz=50 - do i=1,nz - s=0. - sy=0. - do j=-jz,jz - k=i+j - if(k.ge.1 .and. k.le.nz) then - s=s + s1(k)*y(j) - sy=sy+y(j) - endif - enddo - s2(i)=s/sy -! write(52,3002) i-256,s1(i),s2(i) -!3002 format(i5,2f10.4) - enddo - -end subroutine smolorentz +!program smolorentz +subroutine smolorentz(s1,nz,w,s2) + +! parameter (nz=512) + real s1(nz),s2(nz) + real y(-50:50) +! character*8 arg + +! s1=0. +! s1(256)=1. + +! call getarg(1,arg) +! read(arg,*) w + + do i=-50,50 + x=i + z=x/(0.5*w) + y(i)=0. + if(abs(z).lt.3.0) then + d=1.0 + z*z + y(i)=(1.0/d - 0.1)*10.0/9.0 + endif + enddo + + jz=nint(1.5*w) + if(jz.gt.50) jz=50 + do i=1,nz + s=0. + sy=0. + do j=-jz,jz + k=i+j + if(k.ge.1 .and. k.le.nz) then + s=s + s1(k)*y(j) + sy=sy+y(j) + endif + enddo + s2(i)=s/sy +! write(52,3002) i-256,s1(i),s2(i) +!3002 format(i5,2f10.4) + enddo + +end subroutine smolorentz diff --git a/lib/softsym9f.f90 b/lib/softsym9f.f90 index d7f1ff30..bb505f0e 100755 --- a/lib/softsym9f.f90 +++ b/lib/softsym9f.f90 @@ -1,55 +1,55 @@ -subroutine softsym9f(ss2,ss3,i1SoftSymbols) - -! Compute soft symbols and S/N - - real ss2(0:8,85) - real ss3(0:7,69) - integer*1 i1SoftSymbolsScrambled(207) - integer*1 i1SoftSymbols(207) - - ss=0. - sig=0. - if(ss2(0,1).eq.-999.0) return !Silence compiler warning - do j=1,69 - smax=0. - do i=0,7 - smax=max(smax,ss3(i,j)) - ss=ss+ss3(i,j) - enddo - sig=sig+smax - ss=ss-smax - enddo - ave=ss/(69*7) !Baseline -! call pctile(ss2,9*85,35,xmed) !### better? ### - ss3=ss3/ave - sig=sig/69. !Signal - - m0=3 - k=0 - scale=10.0 - do j=1,69 - do m=m0-1,0,-1 !Get bit-wise soft symbols - if(m.eq.2) then - r1=max(ss3(4,j),ss3(5,j),ss3(6,j),ss3(7,j)) - r0=max(ss3(0,j),ss3(1,j),ss3(2,j),ss3(3,j)) - else if(m.eq.1) then - r1=max(ss3(2,j),ss3(3,j),ss3(4,j),ss3(5,j)) - r0=max(ss3(0,j),ss3(1,j),ss3(6,j),ss3(7,j)) - else - r1=max(ss3(1,j),ss3(2,j),ss3(4,j),ss3(7,j)) - r0=max(ss3(0,j),ss3(3,j),ss3(5,j),ss3(6,j)) - endif - - k=k+1 - i4=nint(scale*(r1-r0)) - if(i4.lt.-127) i4=-127 - if(i4.gt.127) i4=127 - i1SoftSymbolsScrambled(k)=i4 - enddo - enddo - - - call interleave9(i1SoftSymbolsScrambled,-1,i1SoftSymbols) - - return -end subroutine softsym9f +subroutine softsym9f(ss2,ss3,i1SoftSymbols) + +! Compute soft symbols and S/N + + real ss2(0:8,85) + real ss3(0:7,69) + integer*1 i1SoftSymbolsScrambled(207) + integer*1 i1SoftSymbols(207) + + ss=0. + sig=0. + if(ss2(0,1).eq.-999.0) return !Silence compiler warning + do j=1,69 + smax=0. + do i=0,7 + smax=max(smax,ss3(i,j)) + ss=ss+ss3(i,j) + enddo + sig=sig+smax + ss=ss-smax + enddo + ave=ss/(69*7) !Baseline +! call pctile(ss2,9*85,35,xmed) !### better? ### + ss3=ss3/ave + sig=sig/69. !Signal + + m0=3 + k=0 + scale=10.0 + do j=1,69 + do m=m0-1,0,-1 !Get bit-wise soft symbols + if(m.eq.2) then + r1=max(ss3(4,j),ss3(5,j),ss3(6,j),ss3(7,j)) + r0=max(ss3(0,j),ss3(1,j),ss3(2,j),ss3(3,j)) + else if(m.eq.1) then + r1=max(ss3(2,j),ss3(3,j),ss3(4,j),ss3(5,j)) + r0=max(ss3(0,j),ss3(1,j),ss3(6,j),ss3(7,j)) + else + r1=max(ss3(1,j),ss3(2,j),ss3(4,j),ss3(7,j)) + r0=max(ss3(0,j),ss3(3,j),ss3(5,j),ss3(6,j)) + endif + + k=k+1 + i4=nint(scale*(r1-r0)) + if(i4.lt.-127) i4=-127 + if(i4.gt.127) i4=127 + i1SoftSymbolsScrambled(k)=i4 + enddo + enddo + + + call interleave9(i1SoftSymbolsScrambled,-1,i1SoftSymbols) + + return +end subroutine softsym9f diff --git a/lib/softsym9w.f90 b/lib/softsym9w.f90 index 2c58dafd..c9b1d0a8 100755 --- a/lib/softsym9w.f90 +++ b/lib/softsym9w.f90 @@ -1,125 +1,125 @@ -subroutine softsym9w(id2,npts,xdt0,f0,width,nsubmode,xdt1,snrdb,i1softsymbols) - - parameter (NFFT=6912,NH=NFFT/2,NQ=NH/2) - real s(NQ) - real s2(0:8,85) - real s3(0:7,69) - real x(NFFT) - complex cx(0:NH) - integer*2 id2(60*12000) - integer*1 i1SoftSymbolsScrambled(207) - integer*1 i1softsymbols(207) - include 'jt9sync.f90' - equivalence (x,cx) - - if(npts.eq.-99) stop !Silence compiler warning - df=12000.0/NFFT - i0a=max(1.0,(xdt0-1.0)*12000.0) - i0b=(xdt0+1.0)*12000.0 - k1=max(1,nint((f0-0.5*width)/df)) - k2=min(NQ,nint((f0+0.5*width)/df)) - smax=0. - i0pk=1 - i1softsymbols=0 - - do i0=i0a,i0b,432 - s=0. - ssum=0. - do j=1,16 - ia=i0 + (ii(j)-1)*nfft - ib=ia+NFFT-1 - x=1.e-6*id2(ia:ib) - call four2a(x,nfft,1,-1,0) !r2c FFT - do k=1,NQ - s(k)=s(k) + real(cx(k))**2 + aimag(cx(k))**2 - enddo - enddo - ssum=ssum + sum(s(k1:k2)) - if(ssum.gt.smax) then - smax=ssum - i0pk=i0 - else - if(ssum.lt.0.7*smax) exit - endif - end do - xdt1=(i0pk-1)/12000.0 - - if(i0pk.le.0) go to 999 - - m=0 - do j=1,85 - ia=i0pk + (j-1)*nfft - ib=ia+NFFT-1 - x=1.e-6*id2(ia:ib) - call four2a(x,nfft,1,-1,0) !r2c FFT - do k=1,NQ - s(k)=real(cx(k))**2 + aimag(cx(k))**2 - enddo - - dtone=df*(2**nsubmode) - do i=0,8 - f=f0 + i*dtone - k1=max(1,nint((f-0.5*width)/df)) - k2=min(NQ,nint((f+0.5*width)/df)) - s2(i,j)=sum(s(k1:k2)) !Symbol spectra, including sync - enddo - - if(isync(j).eq.0) then - m=m+1 - s3(0:7,m)=s2(1:8,j) !Symbol spectra, data only - endif - -! write(19,3101) j,s2(0:8,j) -!3101 format(i2,9f8.2) - enddo - - ss=0. - sig=0. - do j=1,69 - smax=0. - do i=0,7 - smax=max(smax,s3(i,j)) - ss=ss+s3(i,j) - enddo - sig=sig+smax - ss=ss-smax - enddo - ave=ss/(69*7) !Baseline - call pctile(s2,9*85,35,xmed) - s3=s3/ave - sig=sig/69. !Signal - snrdb=db(sig/xmed) - 28.0 - - m0=3 - k=0 - do j=1,69 - smax=0. - do i=0,7 - if(s3(i,j).gt.smax) smax=s3(i,j) - enddo - - do m=m0-1,0,-1 !Get bit-wise soft symbols - if(m.eq.2) then - r1=max(s3(4,j),s3(5,j),s3(6,j),s3(7,j)) - r0=max(s3(0,j),s3(1,j),s3(2,j),s3(3,j)) - else if(m.eq.1) then - r1=max(s3(2,j),s3(3,j),s3(4,j),s3(5,j)) - r0=max(s3(0,j),s3(1,j),s3(6,j),s3(7,j)) - else - r1=max(s3(1,j),s3(2,j),s3(4,j),s3(7,j)) - r0=max(s3(0,j),s3(3,j),s3(5,j),s3(6,j)) - endif - - k=k+1 - i4=nint(10.0*(r1-r0)) - if(i4.lt.-127) i4=-127 - if(i4.gt.127) i4=127 - i1SoftSymbolsScrambled(k)=i4 - enddo - enddo - -! Remove interleaving - call interleave9(i1SoftSymbolsScrambled,-1,i1SoftSymbols) - -999 return -end subroutine softsym9w +subroutine softsym9w(id2,npts,xdt0,f0,width,nsubmode,xdt1,snrdb,i1softsymbols) + + parameter (NFFT=6912,NH=NFFT/2,NQ=NH/2) + real s(NQ) + real s2(0:8,85) + real s3(0:7,69) + real x(NFFT) + complex cx(0:NH) + integer*2 id2(60*12000) + integer*1 i1SoftSymbolsScrambled(207) + integer*1 i1softsymbols(207) + include 'jt9sync.f90' + equivalence (x,cx) + + if(npts.eq.-99) stop !Silence compiler warning + df=12000.0/NFFT + i0a=max(1.0,(xdt0-1.0)*12000.0) + i0b=(xdt0+1.0)*12000.0 + k1=max(1,nint((f0-0.5*width)/df)) + k2=min(NQ,nint((f0+0.5*width)/df)) + smax=0. + i0pk=1 + i1softsymbols=0 + + do i0=i0a,i0b,432 + s=0. + ssum=0. + do j=1,16 + ia=i0 + (ii(j)-1)*nfft + ib=ia+NFFT-1 + x=1.e-6*id2(ia:ib) + call four2a(x,nfft,1,-1,0) !r2c FFT + do k=1,NQ + s(k)=s(k) + real(cx(k))**2 + aimag(cx(k))**2 + enddo + enddo + ssum=ssum + sum(s(k1:k2)) + if(ssum.gt.smax) then + smax=ssum + i0pk=i0 + else + if(ssum.lt.0.7*smax) exit + endif + end do + xdt1=(i0pk-1)/12000.0 + + if(i0pk.le.0) go to 999 + + m=0 + do j=1,85 + ia=i0pk + (j-1)*nfft + ib=ia+NFFT-1 + x=1.e-6*id2(ia:ib) + call four2a(x,nfft,1,-1,0) !r2c FFT + do k=1,NQ + s(k)=real(cx(k))**2 + aimag(cx(k))**2 + enddo + + dtone=df*(2**nsubmode) + do i=0,8 + f=f0 + i*dtone + k1=max(1,nint((f-0.5*width)/df)) + k2=min(NQ,nint((f+0.5*width)/df)) + s2(i,j)=sum(s(k1:k2)) !Symbol spectra, including sync + enddo + + if(isync(j).eq.0) then + m=m+1 + s3(0:7,m)=s2(1:8,j) !Symbol spectra, data only + endif + +! write(19,3101) j,s2(0:8,j) +!3101 format(i2,9f8.2) + enddo + + ss=0. + sig=0. + do j=1,69 + smax=0. + do i=0,7 + smax=max(smax,s3(i,j)) + ss=ss+s3(i,j) + enddo + sig=sig+smax + ss=ss-smax + enddo + ave=ss/(69*7) !Baseline + call pctile(s2,9*85,35,xmed) + s3=s3/ave + sig=sig/69. !Signal + snrdb=db(sig/xmed) - 28.0 + + m0=3 + k=0 + do j=1,69 + smax=0. + do i=0,7 + if(s3(i,j).gt.smax) smax=s3(i,j) + enddo + + do m=m0-1,0,-1 !Get bit-wise soft symbols + if(m.eq.2) then + r1=max(s3(4,j),s3(5,j),s3(6,j),s3(7,j)) + r0=max(s3(0,j),s3(1,j),s3(2,j),s3(3,j)) + else if(m.eq.1) then + r1=max(s3(2,j),s3(3,j),s3(4,j),s3(5,j)) + r0=max(s3(0,j),s3(1,j),s3(6,j),s3(7,j)) + else + r1=max(s3(1,j),s3(2,j),s3(4,j),s3(7,j)) + r0=max(s3(0,j),s3(3,j),s3(5,j),s3(6,j)) + endif + + k=k+1 + i4=nint(10.0*(r1-r0)) + if(i4.lt.-127) i4=-127 + if(i4.gt.127) i4=127 + i1SoftSymbolsScrambled(k)=i4 + enddo + enddo + +! Remove interleaving + call interleave9(i1SoftSymbolsScrambled,-1,i1SoftSymbols) + +999 return +end subroutine softsym9w diff --git a/lib/sort.f90 b/lib/sort.f90 index 3a216210..0a90a6b3 100755 --- a/lib/sort.f90 +++ b/lib/sort.f90 @@ -1,96 +1,96 @@ -subroutine sort(n,arr) - - integer n,m,nstack - real arr(n) - parameter (m=7,nstack=50) - integer i,ir,j,jstack,k,l,istack(nstack) - real a,temp - - jstack=0 - l=1 - ir=n - n0=n - -1 if(ir-l.lt.m) then - do j=l+1,ir - a=arr(j) - do i=j-1,1,-1 - if(arr(i).le.a) goto 2 - arr(i+1)=arr(i) - enddo - i=0 -2 arr(i+1)=a - enddo - - if(jstack.eq.0) return - - ir=istack(jstack) - l=istack(jstack-1) - jstack=jstack-2 - - else - k=(l+ir)/2 - temp=arr(k) - arr(k)=arr(l+1) - arr(l+1)=temp - - if(arr(l+1).gt.arr(ir)) then - temp=arr(l+1) - arr(l+1)=arr(ir) - arr(ir)=temp - endif - - if(arr(l).gt.arr(ir)) then - temp=arr(l) - arr(l)=arr(ir) - arr(ir)=temp - endif - - if(arr(l+1).gt.arr(l)) then - temp=arr(l+1) - arr(l+1)=arr(l) - arr(l)=temp - endif - - i=l+1 - j=ir - a=arr(l) -3 i=i+1 - if(i.gt.n0) then - do jj=1,n0 - write(99,3001) jj,arr(jj),i,n,ir -3001 format(i10,e12.3,3i10) - enddo - close(99) - stop 'Bounds error in sort.f90' - endif - if(arr(i).lt.a) goto 3 - -4 j=j-1 - if(arr(j).gt.a) goto 4 - - if(j.lt.i) goto 5 - temp=arr(i) - arr(i)=arr(j) - arr(j)=temp - goto 3 - -5 arr(l)=arr(j) - arr(j)=a - jstack=jstack+2 - if(jstack.gt.nstack) stop 'nstack too small in sort' - - 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 sort +subroutine sort(n,arr) + + integer n,m,nstack + real arr(n) + parameter (m=7,nstack=50) + integer i,ir,j,jstack,k,l,istack(nstack) + real a,temp + + jstack=0 + l=1 + ir=n + n0=n + +1 if(ir-l.lt.m) then + do j=l+1,ir + a=arr(j) + do i=j-1,1,-1 + if(arr(i).le.a) goto 2 + arr(i+1)=arr(i) + enddo + i=0 +2 arr(i+1)=a + enddo + + if(jstack.eq.0) return + + ir=istack(jstack) + l=istack(jstack-1) + jstack=jstack-2 + + else + k=(l+ir)/2 + temp=arr(k) + arr(k)=arr(l+1) + arr(l+1)=temp + + if(arr(l+1).gt.arr(ir)) then + temp=arr(l+1) + arr(l+1)=arr(ir) + arr(ir)=temp + endif + + if(arr(l).gt.arr(ir)) then + temp=arr(l) + arr(l)=arr(ir) + arr(ir)=temp + endif + + if(arr(l+1).gt.arr(l)) then + temp=arr(l+1) + arr(l+1)=arr(l) + arr(l)=temp + endif + + i=l+1 + j=ir + a=arr(l) +3 i=i+1 + if(i.gt.n0) then + do jj=1,n0 + write(99,3001) jj,arr(jj),i,n,ir +3001 format(i10,e12.3,3i10) + enddo + close(99) + stop 'Bounds error in sort.f90' + endif + if(arr(i).lt.a) goto 3 + +4 j=j-1 + if(arr(j).gt.a) goto 4 + + if(j.lt.i) goto 5 + temp=arr(i) + arr(i)=arr(j) + arr(j)=temp + goto 3 + +5 arr(l)=arr(j) + arr(j)=a + jstack=jstack+2 + if(jstack.gt.nstack) stop 'nstack too small in sort' + + 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 sort diff --git a/lib/spec64.f90 b/lib/spec64.f90 index 1839b340..79322050 100755 --- a/lib/spec64.f90 +++ b/lib/spec64.f90 @@ -1,53 +1,53 @@ -subroutine spec64(c0,npts,nsps,mode_q65,jpk,s3,LL,NN) - - parameter (MAXFFT=20736) - complex c0(0:npts-1) !Complex spectrum of dd() - complex cs(0:MAXFFT-1) !Complex symbol spectrum - real s3(LL,NN) !Synchronized symbol spectra - real xbase0(LL),xbase(LL) -! integer ipk1(1) - integer isync(22) !Indices of 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/ - - nfft=nsps - j=0 - n=1 - do k=1,84 - if(k.eq.isync(n)) then - n=n+1 - cycle - endif - j=j+1 - ja=(k-1)*nsps + jpk - jb=ja+nsps-1 - if(ja.lt.0) ja=0 - if(jb.gt.npts-1) jb=npts-1 - nz=jb-ja - cs(0:nz)=c0(ja:jb) - if(nz.lt.nfft-1) cs(nz+1:)=0. - call four2a(cs,nsps,1,-1,1) !c2c FFT to frequency - do ii=1,LL - i=ii-65+mode_q65 !mode_q65 = 1 2 4 8 16 for Q65 A B C D E - if(i.lt.0) i=i+nsps - s3(ii,j)=real(cs(i))**2 + aimag(cs(i))**2 - enddo - enddo - - df=6000.0/nfft - do i=1,LL - call pctile(s3(i,1:NN),NN,45,xbase0(i)) !Get baseline for passband shape - enddo - - nh=25 - xbase(1:nh-1)=sum(xbase0(1:nh-1))/(nh-1.0) - xbase(LL-nh+1:LL)=sum(xbase0(LL-nh+1:LL))/(nh-1.0) - do i=nh,LL-nh - xbase(i)=sum(xbase0(i-nh+1:i+nh))/(2*nh+1) !Smoothed passband shape - enddo - - do i=1,LL - s3(i,1:NN)=s3(i,1:NN)/(xbase(i)+0.001) !Apply frequency equalization - enddo - - return -end subroutine spec64 +subroutine spec64(c0,npts,nsps,mode_q65,jpk,s3,LL,NN) + + parameter (MAXFFT=20736) + complex c0(0:npts-1) !Complex spectrum of dd() + complex cs(0:MAXFFT-1) !Complex symbol spectrum + real s3(LL,NN) !Synchronized symbol spectra + real xbase0(LL),xbase(LL) +! integer ipk1(1) + integer isync(22) !Indices of 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/ + + nfft=nsps + j=0 + n=1 + do k=1,84 + if(k.eq.isync(n)) then + n=n+1 + cycle + endif + j=j+1 + ja=(k-1)*nsps + jpk + jb=ja+nsps-1 + if(ja.lt.0) ja=0 + if(jb.gt.npts-1) jb=npts-1 + nz=jb-ja + cs(0:nz)=c0(ja:jb) + if(nz.lt.nfft-1) cs(nz+1:)=0. + call four2a(cs,nsps,1,-1,1) !c2c FFT to frequency + do ii=1,LL + i=ii-65+mode_q65 !mode_q65 = 1 2 4 8 16 for Q65 A B C D E + if(i.lt.0) i=i+nsps + s3(ii,j)=real(cs(i))**2 + aimag(cs(i))**2 + enddo + enddo + + df=6000.0/nfft + do i=1,LL + call pctile(s3(i,1:NN),NN,45,xbase0(i)) !Get baseline for passband shape + enddo + + nh=25 + xbase(1:nh-1)=sum(xbase0(1:nh-1))/(nh-1.0) + xbase(LL-nh+1:LL)=sum(xbase0(LL-nh+1:LL))/(nh-1.0) + do i=nh,LL-nh + xbase(i)=sum(xbase0(i-nh+1:i+nh))/(2*nh+1) !Smoothed passband shape + enddo + + do i=1,LL + s3(i,1:NN)=s3(i,1:NN)/(xbase(i)+0.001) !Apply frequency equalization + enddo + + return +end subroutine spec64 diff --git a/lib/spec9f.f90 b/lib/spec9f.f90 index 5f4c3ae6..96dac29c 100755 --- a/lib/spec9f.f90 +++ b/lib/spec9f.f90 @@ -1,30 +1,30 @@ -subroutine spec9f(id2,npts,nsps,s1,jz,nq) - -! Compute symbol spectra at quarter-symbol steps. - - integer*2 id2(0:npts) - real s1(nq,jz) - real x(960) - complex c(0:480) - equivalence (x,c) - - nfft=2*nsps !FFTs at twice the symbol length - nh=nfft/2 - do j=1,jz - ia=(j-1)*nsps/4 - ib=ia+nsps-1 - if(ib.gt.npts) exit - x(1:nh)=id2(ia:ib) - x(nh+1:)=0. - call four2a(x,nfft,1,-1,0) !r2c - k=mod(j-1,340)+1 - do i=1,NQ - s1(i,j)=1.e-10*(real(c(i))**2 + aimag(c(i))**2) - enddo - enddo - -!### Reference spectrum should be applied here (or possibly earlier?) ### -!### Normalize so that rms (or level?) is 1.0 ? ### - - return -end subroutine spec9f +subroutine spec9f(id2,npts,nsps,s1,jz,nq) + +! Compute symbol spectra at quarter-symbol steps. + + integer*2 id2(0:npts) + real s1(nq,jz) + real x(960) + complex c(0:480) + equivalence (x,c) + + nfft=2*nsps !FFTs at twice the symbol length + nh=nfft/2 + do j=1,jz + ia=(j-1)*nsps/4 + ib=ia+nsps-1 + if(ib.gt.npts) exit + x(1:nh)=id2(ia:ib) + x(nh+1:)=0. + call four2a(x,nfft,1,-1,0) !r2c + k=mod(j-1,340)+1 + do i=1,NQ + s1(i,j)=1.e-10*(real(c(i))**2 + aimag(c(i))**2) + enddo + enddo + +!### Reference spectrum should be applied here (or possibly earlier?) ### +!### Normalize so that rms (or level?) is 1.0 ? ### + + return +end subroutine spec9f diff --git a/lib/spec_qra65.f90 b/lib/spec_qra65.f90 index 5f69ca2c..15e8fd09 100755 --- a/lib/spec_qra65.f90 +++ b/lib/spec_qra65.f90 @@ -1,50 +1,50 @@ -subroutine spec_qra65(c0,nsps,s3,LL,NN) - -! Compute synchronized symbol spectra. - - complex c0(0:85*nsps-1) !Synchronized complex data at 6000 S/s - complex, allocatable :: cs(:) !Complex symbol spectrum - real s3(LL,NN) !Synchronized symbol spectra - real xbase0(LL),xbase(LL) !Work arrays - integer isync(22) !Indices of 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/ - - allocate(cs(0:nsps-1)) - fac=1.0/nsps - j=0 - n=1 - do k=1,84 - if(k.eq.isync(n)) then - n=n+1 - cycle - endif - j=j+1 - ja=(k-1)*nsps - jb=ja+nsps-1 - cs=fac*c0(ja:jb) - call four2a(cs,nsps,1,-1,1) !c2c FFT to frequency - do ii=1,LL - i=ii-65 - if(i.lt.0) i=i+nsps - s3(ii,j)=real(cs(i))**2 + aimag(cs(i))**2 - enddo - enddo - - df=6000.0/nsps - do i=1,LL - call pctile(s3(i,1:NN),NN,45,xbase0(i)) !Get baseline for passband shape - enddo - - nh=9 - xbase(1:nh-1)=sum(xbase0(1:nh-1))/(nh-1.0) - xbase(LL-nh+1:LL)=sum(xbase0(LL-nh+1:LL))/(nh-1.0) - do i=nh,LL-nh - xbase(i)=sum(xbase0(i-nh+1:i+nh))/(2*nh+1) !Smoothed passband shape - enddo - - do i=1,LL - s3(i,1:NN)=s3(i,1:NN)/(xbase(i)+0.001) !Apply frequency equalization - enddo - - return -end subroutine spec_qra65 +subroutine spec_qra65(c0,nsps,s3,LL,NN) + +! Compute synchronized symbol spectra. + + complex c0(0:85*nsps-1) !Synchronized complex data at 6000 S/s + complex, allocatable :: cs(:) !Complex symbol spectrum + real s3(LL,NN) !Synchronized symbol spectra + real xbase0(LL),xbase(LL) !Work arrays + integer isync(22) !Indices of 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/ + + allocate(cs(0:nsps-1)) + fac=1.0/nsps + j=0 + n=1 + do k=1,84 + if(k.eq.isync(n)) then + n=n+1 + cycle + endif + j=j+1 + ja=(k-1)*nsps + jb=ja+nsps-1 + cs=fac*c0(ja:jb) + call four2a(cs,nsps,1,-1,1) !c2c FFT to frequency + do ii=1,LL + i=ii-65 + if(i.lt.0) i=i+nsps + s3(ii,j)=real(cs(i))**2 + aimag(cs(i))**2 + enddo + enddo + + df=6000.0/nsps + do i=1,LL + call pctile(s3(i,1:NN),NN,45,xbase0(i)) !Get baseline for passband shape + enddo + + nh=9 + xbase(1:nh-1)=sum(xbase0(1:nh-1))/(nh-1.0) + xbase(LL-nh+1:LL)=sum(xbase0(LL-nh+1:LL))/(nh-1.0) + do i=nh,LL-nh + xbase(i)=sum(xbase0(i-nh+1:i+nh))/(2*nh+1) !Smoothed passband shape + enddo + + do i=1,LL + s3(i,1:NN)=s3(i,1:NN)/(xbase(i)+0.001) !Apply frequency equalization + enddo + + return +end subroutine spec_qra65 diff --git a/lib/stats.f90 b/lib/stats.f90 index ea7a7be4..a864f6a1 100755 --- a/lib/stats.f90 +++ b/lib/stats.f90 @@ -1,66 +1,66 @@ -program stats - - character*8 arg - character*40 infile - character decoded*22 - - nargs=iargc() - if(nargs.lt.1) then - print*,'Usage: stats file1 ...' - go to 999 - endif - - ttol=0.1 - nftol=1 - write(*,1000) -1000 format(' SNR Files Sync BM FT Hint Total False BadSync'/ & - 56('-')) - - do ifile=1,nargs - call getarg(ifile,infile) - open(10,file=infile,status='old') - i1=index(infile,".")+1 - i2=40 - if(index(infile,"_").gt.1) i2=index(infile,"_") - 1 - snrgen=0. - read(infile(i1:i2),*,err=1) snrgen -1 snrgen=-snrgen - nsynced=0 - nbm=0 - nftok=0 - nhint=0 - ngood=0 - nbad=0 - nbadsync=0 - - do iline=1,999999 - read(10,1010,end=100) nutc,sync,nsnr,dt,nfreq,ncandidates,nhard, & - ntotal,rtt,ntry,nft,nqual,decoded -1010 format(i4.4,f5.1,i4,f5.1,i5,i6,i3,i4,f6.3,i8,i2,i3,1x,a22) - - ndfreq=abs(nfreq-1500) - if(sync.ge.1.0 .and. abs(dt).le.ttol .and. ndfreq.le.nftol) then - nsynced=nsynced+1 - else - nbadsync=nbadsync+1 - endif - - if(decoded.eq.' ') cycle - if(nft.eq.2 .or. (ntotal.le.81 .and. rtt.le.0.87)) then !nag=0 - if(decoded(1:11).eq.'K1ABC W9XYZ') then - ngood=ngood+1 - if(nft.eq.1 .and. ncandidates.eq.0) nbm=nbm+1 - if(nft.eq.1) nftok=nftok+1 - if(nft.ge.2) nhint=nhint+1 - else - nbad=nbad+1 - endif - endif - enddo - -100 write(*,1100) snrgen,nutc,nsynced,nbm,nftok,nhint,ngood,nbad, & - nbadsync -1100 format(f5.1,8i6) - enddo - -999 end program stats +program stats + + character*8 arg + character*40 infile + character decoded*22 + + nargs=iargc() + if(nargs.lt.1) then + print*,'Usage: stats file1 ...' + go to 999 + endif + + ttol=0.1 + nftol=1 + write(*,1000) +1000 format(' SNR Files Sync BM FT Hint Total False BadSync'/ & + 56('-')) + + do ifile=1,nargs + call getarg(ifile,infile) + open(10,file=infile,status='old') + i1=index(infile,".")+1 + i2=40 + if(index(infile,"_").gt.1) i2=index(infile,"_") - 1 + snrgen=0. + read(infile(i1:i2),*,err=1) snrgen +1 snrgen=-snrgen + nsynced=0 + nbm=0 + nftok=0 + nhint=0 + ngood=0 + nbad=0 + nbadsync=0 + + do iline=1,999999 + read(10,1010,end=100) nutc,sync,nsnr,dt,nfreq,ncandidates,nhard, & + ntotal,rtt,ntry,nft,nqual,decoded +1010 format(i4.4,f5.1,i4,f5.1,i5,i6,i3,i4,f6.3,i8,i2,i3,1x,a22) + + ndfreq=abs(nfreq-1500) + if(sync.ge.1.0 .and. abs(dt).le.ttol .and. ndfreq.le.nftol) then + nsynced=nsynced+1 + else + nbadsync=nbadsync+1 + endif + + if(decoded.eq.' ') cycle + if(nft.eq.2 .or. (ntotal.le.81 .and. rtt.le.0.87)) then !nag=0 + if(decoded(1:11).eq.'K1ABC W9XYZ') then + ngood=ngood+1 + if(nft.eq.1 .and. ncandidates.eq.0) nbm=nbm+1 + if(nft.eq.1) nftok=nftok+1 + if(nft.ge.2) nhint=nhint+1 + else + nbad=nbad+1 + endif + endif + enddo + +100 write(*,1100) snrgen,nutc,nsynced,nbm,nftok,nhint,ngood,nbad, & + nbadsync +1100 format(f5.1,8i6) + enddo + +999 end program stats diff --git a/lib/sumsim.f90 b/lib/sumsim.f90 index 24cca29a..594b8b20 100755 --- a/lib/sumsim.f90 +++ b/lib/sumsim.f90 @@ -1,42 +1,42 @@ -program sumsim - -! Sum a number of *.wav files so that multiple signals are present - - use wavhdr - parameter (NMAX=60*12000) - type(hdr) h !Header for the .wav file - integer*2 iwave(NMAX) !i*2 data - real wave(NMAX) !r*4 data - character*80 fname - - nargs=iargc() - if(nargs.lt.1) then - print*,'Usage: sumsim file1 [file2, ...]' - go to 999 - endif - wave=0. - - do ifile=1,nargs - call getarg(ifile,fname) - open(10,file=trim(fname),status='old',access='stream') - read(10) h - npts=h%ndata/2 - nfsample=h%nsamrate - read(10) iwave(1:npts) - n=len(trim(fname)) - wave(1:npts)=wave(1:npts) + iwave(1:npts) - rms=sqrt(dot_product(wave(1:npts),wave(1:npts))/npts) - write(*,1000) ifile,npts,float(npts)/nfsample,rms,fname(n-14:n) -1000 format(i3,i8,f6.1,f10.3,2x,a15) - close(10) - enddo - -! fac=1.0/sqrt(float(nargs)) - fac=1.0/nargs - iwave(1:npts)=nint(fac*wave(1:npts)) - - open(12,file='000001_0000.wav',access='stream',status='unknown') - write(12) h,iwave(1:npts) - close(12) - -999 end program sumsim +program sumsim + +! Sum a number of *.wav files so that multiple signals are present + + use wavhdr + parameter (NMAX=60*12000) + type(hdr) h !Header for the .wav file + integer*2 iwave(NMAX) !i*2 data + real wave(NMAX) !r*4 data + character*80 fname + + nargs=iargc() + if(nargs.lt.1) then + print*,'Usage: sumsim file1 [file2, ...]' + go to 999 + endif + wave=0. + + do ifile=1,nargs + call getarg(ifile,fname) + open(10,file=trim(fname),status='old',access='stream') + read(10) h + npts=h%ndata/2 + nfsample=h%nsamrate + read(10) iwave(1:npts) + n=len(trim(fname)) + wave(1:npts)=wave(1:npts) + iwave(1:npts) + rms=sqrt(dot_product(wave(1:npts),wave(1:npts))/npts) + write(*,1000) ifile,npts,float(npts)/nfsample,rms,fname(n-14:n) +1000 format(i3,i8,f6.1,f10.3,2x,a15) + close(10) + enddo + +! fac=1.0/sqrt(float(nargs)) + fac=1.0/nargs + iwave(1:npts)=nint(fac*wave(1:npts)) + + open(12,file='000001_0000.wav',access='stream',status='unknown') + write(12) h,iwave(1:npts) + close(12) + +999 end program sumsim diff --git a/lib/superfox/foxgen2.f90 b/lib/superfox/foxgen2.f90 index a6831dc8..9be6ca86 100755 --- a/lib/superfox/foxgen2.f90 +++ b/lib/superfox/foxgen2.f90 @@ -1,75 +1,75 @@ -subroutine foxgen2(nslots,cmsg,line,foxcall) - -! Parse old-style Fox messages to extract the necessary pieces for a SuperFox -! transmission. - - use packjt77 - character*120 line - character*40 cmsg(5) !Old-style Fox messages are here - character*37 msg - character*26 sfmsg - character*13 mycall - character*11 foxcall - character*4 mygrid - character*6 hiscall_1,hiscall_2 - character*4 rpt1,rpt2 - character*13 w(19) - integer nw(19) - integer ntype !Message type: 0 Free Text - ! 1 CQ MyCall MyGrid - ! 2 Call_1 MyCall RR73 - ! 3 Call_1 MyCall rpt1 - ! 4 Call_1 RR73; Call_2 rpt2 - - if(nslots.lt.1 .or. nslots.gt.5) return - k=0 - do i=1,nslots - hiscall_1='' - hiscall_2='' - mycall='' - mygrid='' - rpt1='' - rpt2='' - msg=cmsg(i)(1:37) - call split77(msg,nwords,nw,w) - ntype=0 - if(msg(1:3).eq.'CQ ') then - ntype=1 - mycall=w(2)(1:12) - mygrid=w(3)(1:4) - else if(index(msg,';').gt.0) then - ntype=4 - hiscall_1=w(1)(1:6) - hiscall_2=w(3)(1:6) - rpt1='RR73' - rpt2=w(5)(1:4) - mycall=w(4)(2:nw(4)-1) - else if(index(msg,' RR73').gt.0) then - ntype=2 - hiscall_1=w(1)(1:6) - mycall=w(2)(1:12) - rpt1='RR73' - else if(nwords.eq.3 .and. nw(3).eq.3 .and. & - (w(3)(1:1).eq.'-' .or. w(3)(1:1).eq.'+')) then - ntype=3 - hiscall_1=w(1)(1:6) - mycall=w(2)(1:12) - rpt1=w(3)(1:4) - endif - - k=k+1 - if(ntype.le.3) call sfox_assemble(ntype,k,msg(1:26),mycall,mygrid,line) - if(ntype.eq.4) then - sfmsg=w(1)(1:nw(1))//' '//mycall(1:len(trim(mycall))+1)//'RR73' - call sfox_assemble(2,k,sfmsg,mycall,mygrid,line) - sfmsg=w(3)(1:nw(3))//' '//mycall(1:len(trim(mycall))+1)//w(5)(1:3) - k=k+1 - call sfox_assemble(3,k,sfmsg,mycall,mygrid,line) - endif - enddo - - call sfox_assemble(ntype,11,msg(1:26),mycall,mygrid,line) !k=11 to finish up - foxcall=mycall(1:11) - - return -end subroutine foxgen2 +subroutine foxgen2(nslots,cmsg,line,foxcall) + +! Parse old-style Fox messages to extract the necessary pieces for a SuperFox +! transmission. + + use packjt77 + character*120 line + character*40 cmsg(5) !Old-style Fox messages are here + character*37 msg + character*26 sfmsg + character*13 mycall + character*11 foxcall + character*4 mygrid + character*6 hiscall_1,hiscall_2 + character*4 rpt1,rpt2 + character*13 w(19) + integer nw(19) + integer ntype !Message type: 0 Free Text + ! 1 CQ MyCall MyGrid + ! 2 Call_1 MyCall RR73 + ! 3 Call_1 MyCall rpt1 + ! 4 Call_1 RR73; Call_2 rpt2 + + if(nslots.lt.1 .or. nslots.gt.5) return + k=0 + do i=1,nslots + hiscall_1='' + hiscall_2='' + mycall='' + mygrid='' + rpt1='' + rpt2='' + msg=cmsg(i)(1:37) + call split77(msg,nwords,nw,w) + ntype=0 + if(msg(1:3).eq.'CQ ') then + ntype=1 + mycall=w(2)(1:12) + mygrid=w(3)(1:4) + else if(index(msg,';').gt.0) then + ntype=4 + hiscall_1=w(1)(1:6) + hiscall_2=w(3)(1:6) + rpt1='RR73' + rpt2=w(5)(1:4) + mycall=w(4)(2:nw(4)-1) + else if(index(msg,' RR73').gt.0) then + ntype=2 + hiscall_1=w(1)(1:6) + mycall=w(2)(1:12) + rpt1='RR73' + else if(nwords.eq.3 .and. nw(3).eq.3 .and. & + (w(3)(1:1).eq.'-' .or. w(3)(1:1).eq.'+')) then + ntype=3 + hiscall_1=w(1)(1:6) + mycall=w(2)(1:12) + rpt1=w(3)(1:4) + endif + + k=k+1 + if(ntype.le.3) call sfox_assemble(ntype,k,msg(1:26),mycall,mygrid,line) + if(ntype.eq.4) then + sfmsg=w(1)(1:nw(1))//' '//mycall(1:len(trim(mycall))+1)//'RR73' + call sfox_assemble(2,k,sfmsg,mycall,mygrid,line) + sfmsg=w(3)(1:nw(3))//' '//mycall(1:len(trim(mycall))+1)//w(5)(1:3) + k=k+1 + call sfox_assemble(3,k,sfmsg,mycall,mygrid,line) + endif + enddo + + call sfox_assemble(ntype,11,msg(1:26),mycall,mygrid,line) !k=11 to finish up + foxcall=mycall(1:11) + + return +end subroutine foxgen2 diff --git a/lib/superfox/ft8_params.f90 b/lib/superfox/ft8_params.f90 index bd228bde..139ff964 100755 --- a/lib/superfox/ft8_params.f90 +++ b/lib/superfox/ft8_params.f90 @@ -1,12 +1,12 @@ -! LDPC (174,91) code -parameter (KK=91) !Information bits (77 + CRC14) -parameter (ND=58) !Data symbols -parameter (NS=21) !Sync symbols (3 @ Costas 7x7) -parameter (NN=NS+ND) !Total channel symbols (79) -parameter (NSPS=1920) !Samples per symbol at 12000 S/s -parameter (NZ=NSPS*NN) !Samples in full 15 s waveform (151,680) -parameter (NMAX=15*12000) !Samples in iwave (180,000) -parameter (NFFT1=2*NSPS, NH1=NFFT1/2) !Length of FFTs for symbol spectra -parameter (NSTEP=NSPS/4) !Rough time-sync step size -parameter (NHSYM=NMAX/NSTEP-3) !Number of symbol spectra (1/4-sym steps) -parameter (NDOWN=60) !Downsample factor +! LDPC (174,91) code +parameter (KK=91) !Information bits (77 + CRC14) +parameter (ND=58) !Data symbols +parameter (NS=21) !Sync symbols (3 @ Costas 7x7) +parameter (NN=NS+ND) !Total channel symbols (79) +parameter (NSPS=1920) !Samples per symbol at 12000 S/s +parameter (NZ=NSPS*NN) !Samples in full 15 s waveform (151,680) +parameter (NMAX=15*12000) !Samples in iwave (180,000) +parameter (NFFT1=2*NSPS, NH1=NFFT1/2) !Length of FFTs for symbol spectra +parameter (NSTEP=NSPS/4) !Rough time-sync step size +parameter (NHSYM=NMAX/NSTEP-3) !Number of symbol spectra (1/4-sym steps) +parameter (NDOWN=60) !Downsample factor diff --git a/lib/superfox/gtag.f90 b/lib/superfox/gtag.f90 index a21c5b40..9cf93ab3 100755 --- a/lib/superfox/gtag.f90 +++ b/lib/superfox/gtag.f90 @@ -1,3 +1,3 @@ - integer ntag - data ntag/z"1234567"/ - !----------------------------------------------------------------------- + integer ntag + data ntag/z"1234567"/ + !----------------------------------------------------------------------- diff --git a/lib/superfox/julian.f90 b/lib/superfox/julian.f90 index 8d8b7411..002167fc 100755 --- a/lib/superfox/julian.f90 +++ b/lib/superfox/julian.f90 @@ -1,39 +1,39 @@ -module julian - -contains - - integer*8 function itime8() - - implicit integer (a-z) -! 1 2 3 4 5 6 7 - integer it(8) !y m d nmin h m s - integer*8 secday - data secday/86400/ - - call date_and_time(values=it) - iyr=it(1) - imo=it(2) - iday=it(3) - days=JD(iyr,imo,iday) - 2440588 !Days since epoch Jan 1, 1970 - ih=it(5) - im=it(6)-it(4) !it(4) corrects for time zone - is=it(7) - nsec=3600*ih + 60*im + is - itime8=days*secday + nsec - - return - end function itime8 - - integer function JD(I,J,K) - -! Return Julian Date for I=year, J=month, K=day -! Reference: Fliegel and Van Flandern, Comm. ACM 11, 10, 1968 - - JD = K - 32075 + 1461*(I + 4800 + (J - 14)/12)/4 & - + 367*(J - 2 - (J - 14)/12*12)/12 - 3 & - *((I + 4900 + (J - 14)/12)/100)/4 - - return - end function JD - -end module julian +module julian + +contains + + integer*8 function itime8() + + implicit integer (a-z) +! 1 2 3 4 5 6 7 + integer it(8) !y m d nmin h m s + integer*8 secday + data secday/86400/ + + call date_and_time(values=it) + iyr=it(1) + imo=it(2) + iday=it(3) + days=JD(iyr,imo,iday) - 2440588 !Days since epoch Jan 1, 1970 + ih=it(5) + im=it(6)-it(4) !it(4) corrects for time zone + is=it(7) + nsec=3600*ih + 60*im + is + itime8=days*secday + nsec + + return + end function itime8 + + integer function JD(I,J,K) + +! Return Julian Date for I=year, J=month, K=day +! Reference: Fliegel and Van Flandern, Comm. ACM 11, 10, 1968 + + JD = K - 32075 + 1461*(I + 4800 + (J - 14)/12)/4 & + + 367*(J - 2 - (J - 14)/12*12)/12 - 3 & + *((I + 4900 + (J - 14)/12)/100)/4 + + return + end function JD + +end module julian diff --git a/lib/superfox/popen_module.f90 b/lib/superfox/popen_module.f90 index 3b937175..9aea9ff5 100755 --- a/lib/superfox/popen_module.f90 +++ b/lib/superfox/popen_module.f90 @@ -1,103 +1,103 @@ -!******************************************************************************* -!> -! A simple module for `popen`. - - module popen_module - - use,intrinsic :: iso_c_binding - - implicit none - - private - - ! interfaces to C functions - interface - - function popen(command, mode) bind(C,name='popen') - !! initiate pipe streams to or from a process - import :: c_char, c_ptr - implicit none - character(kind=c_char),dimension(*) :: command - character(kind=c_char),dimension(*) :: mode - type(c_ptr) :: popen - end function popen - - function fgets(s, siz, stream) bind(C,name='fgets') - !! get a string from a stream - import :: c_char, c_ptr, c_int - implicit none - type (c_ptr) :: fgets - character(kind=c_char),dimension(*) :: s - integer(kind=c_int),value :: siz - type(c_ptr),value :: stream - end function fgets - - function pclose(stream) bind(C,name='pclose') - !! close a pipe stream to or from a process - import :: c_ptr, c_int - implicit none - integer(c_int) :: pclose - type(c_ptr),value :: stream - end function pclose - - end interface - - public :: c2f_string, get_command_as_string - -contains - - !******************************************************************************* - !> - ! Convert a C string to a Fortran string. - - function c2f_string(c) result(f) - - character(len=*),intent(in) :: c !! C string - character(len=:),allocatable :: f !! Fortran string - - integer :: i - - i = index(c,c_null_char) - - if (i<=0) then - f = c - else if (i==1) then - f = '' - else if (i>1) then - f = c(1:i-1) - end if - - end function c2f_string - - !******************************************************************************* - !> - ! Return the result of the command as a string. - - function get_command_as_string(command) result(str) - - character(len=*),intent(in) :: command !! the command to run - character(len=:),allocatable :: str !! the result of that command - - integer,parameter :: buffer_length = 1000 !! read stream in chunks of this size - - type(c_ptr) :: h !! for `popen` - integer(c_int) :: istat !! `pclose` status - character(kind=c_char,len=buffer_length) :: line !! buffer to read from `fgets` - - str = '' - h = c_null_ptr - h = popen(command//c_null_char,'r'//c_null_char) - - if (c_associated(h)) then - do while (c_associated(fgets(line,buffer_length,h))) - str = str//c2f_string(line) - end do - istat = pclose(h) - end if - - end function get_command_as_string - -!******************************************************************************* - end module popen_module -!******************************************************************************* - +!******************************************************************************* +!> +! A simple module for `popen`. + + module popen_module + + use,intrinsic :: iso_c_binding + + implicit none + + private + + ! interfaces to C functions + interface + + function popen(command, mode) bind(C,name='popen') + !! initiate pipe streams to or from a process + import :: c_char, c_ptr + implicit none + character(kind=c_char),dimension(*) :: command + character(kind=c_char),dimension(*) :: mode + type(c_ptr) :: popen + end function popen + + function fgets(s, siz, stream) bind(C,name='fgets') + !! get a string from a stream + import :: c_char, c_ptr, c_int + implicit none + type (c_ptr) :: fgets + character(kind=c_char),dimension(*) :: s + integer(kind=c_int),value :: siz + type(c_ptr),value :: stream + end function fgets + + function pclose(stream) bind(C,name='pclose') + !! close a pipe stream to or from a process + import :: c_ptr, c_int + implicit none + integer(c_int) :: pclose + type(c_ptr),value :: stream + end function pclose + + end interface + + public :: c2f_string, get_command_as_string + +contains + + !******************************************************************************* + !> + ! Convert a C string to a Fortran string. + + function c2f_string(c) result(f) + + character(len=*),intent(in) :: c !! C string + character(len=:),allocatable :: f !! Fortran string + + integer :: i + + i = index(c,c_null_char) + + if (i<=0) then + f = c + else if (i==1) then + f = '' + else if (i>1) then + f = c(1:i-1) + end if + + end function c2f_string + + !******************************************************************************* + !> + ! Return the result of the command as a string. + + function get_command_as_string(command) result(str) + + character(len=*),intent(in) :: command !! the command to run + character(len=:),allocatable :: str !! the result of that command + + integer,parameter :: buffer_length = 1000 !! read stream in chunks of this size + + type(c_ptr) :: h !! for `popen` + integer(c_int) :: istat !! `pclose` status + character(kind=c_char,len=buffer_length) :: line !! buffer to read from `fgets` + + str = '' + h = c_null_ptr + h = popen(command//c_null_char,'r'//c_null_char) + + if (c_associated(h)) then + do while (c_associated(fgets(line,buffer_length,h))) + str = str//c2f_string(line) + end do + istat = pclose(h) + end if + + end function get_command_as_string + +!******************************************************************************* + end module popen_module +!******************************************************************************* + diff --git a/lib/superfox/qpc/dbgprintf.c b/lib/superfox/qpc/dbgprintf.c index f17d4e47..4a86e555 100755 --- a/lib/superfox/qpc/dbgprintf.c +++ b/lib/superfox/qpc/dbgprintf.c @@ -1,67 +1,67 @@ -// ------------------------------------------------------------------------------ -// dbgprintf.c -// Functions for printing debug information -// -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// -// This source 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 3 of the License, or -// (at your option) any later version. -// This file is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this source distribution. -// If not, see . -// ------------------------------------------------------------------------------ - -#include "dbgprintf.h" - -// print functions for debug purposes -void dbgprintf_vector_uchar(const char* name, const unsigned char* v, int vsize) -{ - int k; - - printf("%s=", name); - for (k = 0; k < vsize; k++) { - if ((k & 0x0F) == 0) - printf("\n"); - printf("%02X ", v[k]); - } - printf("\n"); -} - -void dbgprintf_vector_float(const char* name, const float* v, int vsize) -{ - int k; - - printf("%s=", name); - for (k = 0; k < vsize; k++) { - if ((k & 0x07) == 0) - printf("\n"); - printf("%10.3f ", v[k]); - } - printf("\n"); -} - -void dbgprintf_rows_float(const char* name, const float* v, int vsize, int nrows) -{ - int k; - int j; - - printf("%s=\n", name); - for (j = 0; j < nrows; j++) { - printf("r%d:", j); - for (k = 0; k < vsize; k++) { - if ((k & 0x07) == 0) - printf("\n"); - printf("%7.3f ", v[k]); - } - printf("\n"); - v += vsize; - } -} +// ------------------------------------------------------------------------------ +// dbgprintf.c +// Functions for printing debug information +// +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// +// This source 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 3 of the License, or +// (at your option) any later version. +// This file is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this source distribution. +// If not, see . +// ------------------------------------------------------------------------------ + +#include "dbgprintf.h" + +// print functions for debug purposes +void dbgprintf_vector_uchar(const char* name, const unsigned char* v, int vsize) +{ + int k; + + printf("%s=", name); + for (k = 0; k < vsize; k++) { + if ((k & 0x0F) == 0) + printf("\n"); + printf("%02X ", v[k]); + } + printf("\n"); +} + +void dbgprintf_vector_float(const char* name, const float* v, int vsize) +{ + int k; + + printf("%s=", name); + for (k = 0; k < vsize; k++) { + if ((k & 0x07) == 0) + printf("\n"); + printf("%10.3f ", v[k]); + } + printf("\n"); +} + +void dbgprintf_rows_float(const char* name, const float* v, int vsize, int nrows) +{ + int k; + int j; + + printf("%s=\n", name); + for (j = 0; j < nrows; j++) { + printf("r%d:", j); + for (k = 0; k < vsize; k++) { + if ((k & 0x07) == 0) + printf("\n"); + printf("%7.3f ", v[k]); + } + printf("\n"); + v += vsize; + } +} diff --git a/lib/superfox/qpc/dbgprintf.h b/lib/superfox/qpc/dbgprintf.h index 8133042b..dc906f09 100755 --- a/lib/superfox/qpc/dbgprintf.h +++ b/lib/superfox/qpc/dbgprintf.h @@ -1,64 +1,64 @@ -// ------------------------------------------------------------------------------ -// dbgprintf.h -// Functions for printing debug information -// -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// -// This source 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 3 of the License, or -// (at your option) any later version. -// This file is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this source distribution. -// If not, see . -// ------------------------------------------------------------------------------ - -#ifndef _dbgprintf_h_ -#define _dbgprintf_h_ - -// Define DBGPRINTF_ANYWAY -// in order to print debug information also -// when _DEBUG is not defined - -#define DBGPRINTF_ANYWAY - -#ifdef _DEBUG -#define DBG_PRINTF -#else -#ifdef DBGPRINTF_ANYWAY -#define DBG_PRINTF -#endif -#endif - -#include - -// print functions for debug purposes -#ifdef DBG_PRINTF - -#ifdef __cplusplus -extern "C" { -#endif - - void dbgprintf_vector_uchar(const char* name, const unsigned char* v, int vsize); - void dbgprintf_vector_float(const char* name, const float* v, int vsize); - void dbgprintf_rows_float(const char* name, const float* v, int vsize, int nrows); - -#ifdef __cplusplus -} -#endif - -#else - -#define dbgprintf_vector_uchar(a,b) -#define dbgprintf_vector_float(a,b) -#define dbgprintf_rows_float(a, b, c, d) - -#endif - -#endif // _dbgprintf_h_ +// ------------------------------------------------------------------------------ +// dbgprintf.h +// Functions for printing debug information +// +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// +// This source 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 3 of the License, or +// (at your option) any later version. +// This file is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this source distribution. +// If not, see . +// ------------------------------------------------------------------------------ + +#ifndef _dbgprintf_h_ +#define _dbgprintf_h_ + +// Define DBGPRINTF_ANYWAY +// in order to print debug information also +// when _DEBUG is not defined + +#define DBGPRINTF_ANYWAY + +#ifdef _DEBUG +#define DBG_PRINTF +#else +#ifdef DBGPRINTF_ANYWAY +#define DBG_PRINTF +#endif +#endif + +#include + +// print functions for debug purposes +#ifdef DBG_PRINTF + +#ifdef __cplusplus +extern "C" { +#endif + + void dbgprintf_vector_uchar(const char* name, const unsigned char* v, int vsize); + void dbgprintf_vector_float(const char* name, const float* v, int vsize); + void dbgprintf_rows_float(const char* name, const float* v, int vsize, int nrows); + +#ifdef __cplusplus +} +#endif + +#else + +#define dbgprintf_vector_uchar(a,b) +#define dbgprintf_vector_float(a,b) +#define dbgprintf_rows_float(a, b, c, d) + +#endif + +#endif // _dbgprintf_h_ diff --git a/lib/superfox/qpc/nhash2.c b/lib/superfox/qpc/nhash2.c index 40bae20e..78817c7d 100755 --- a/lib/superfox/qpc/nhash2.c +++ b/lib/superfox/qpc/nhash2.c @@ -1,383 +1,383 @@ -/* - - File name: nhash2.c - - *------------------------------------------------------------------------------ - * - * This file is part of the WSPR application, Weak Signal Propogation Reporter - * - * File Name: nhash.c - * Description: Functions to produce 32-bit hashes for hash table lookup - * - * Copyright (C) 2008-2014 Joseph Taylor, K1JT - * License: GNU GPL v3+ - * - * 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 3 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin - * Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Files: lookup3.c - * Copyright: Copyright (C) 2006 Bob Jenkins - * License: public-domain - * You may use this code any way you wish, private, educational, or commercial. - * It's free. - * - *------------------------------------------------------------------------------- -*/ - -/* -These are functions for producing 32-bit hashes for hash table lookup. -hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() -are externally useful functions. Routines to test the hash are included -if SELF_TEST is defined. You can use this free for any purpose. It's in -the public domain. It has no warranty. - -You probably want to use hashlittle(). hashlittle() and hashbig() -hash byte arrays. hashlittle() is is faster than hashbig() on -little-endian machines. Intel and AMD are little-endian machines. -On second thought, you probably want hashlittle2(), which is identical to -hashlittle() except it returns two 32-bit hashes for the price of one. -You could implement hashbig2() if you wanted but I haven't bothered here. - -If you want to find a hash of, say, exactly 7 integers, do - a = i1; b = i2; c = i3; - mix(a,b,c); - a += i4; b += i5; c += i6; - mix(a,b,c); - a += i7; - final(a,b,c); -then use c as the hash value. If you have a variable length array of -4-byte integers to hash, use hashword(). If you have a byte array (like -a character string), use hashlittle(). If you have several byte arrays, or -a mix of things, see the comments above hashlittle(). - -Why is this so big? I read 12 bytes at a time into 3 4-byte integers, -then mix those integers. This is fast (you can do a lot more thorough -mixing with 12*3 instructions on 3 integers than you can with 3 instructions -on 1 byte), but shoehorning those bytes into integers efficiently is messy. -*/ - -#define SELF_TEST 1 - -#include /* defines printf for tests */ -#include /* defines time_t for timings in the test */ -#include "nhash2.h" -//#include /* attempt to define endianness */ -//#ifdef linux -//# include /* attempt to define endianness */ -//#endif - -#define HASH_LITTLE_ENDIAN 1 - -#define hashsize(n) ((uint32_t)1<<(n)) -#define hashmask(n) (hashsize(n)-1) -#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) - -/* -------------------------------------------------------------------------------- -mix -- mix 3 32-bit values reversibly. - -This is reversible, so any information in (a,b,c) before mix() is -still in (a,b,c) after mix(). - -If four pairs of (a,b,c) inputs are run through mix(), or through -mix() in reverse, there are at least 32 bits of the output that -are sometimes the same for one pair and different for another pair. -This was tested for: -* pairs that differed by one bit, by two bits, in any combination - of top bits of (a,b,c), or in any combination of bottom bits of - (a,b,c). -* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed - the output delta to a Gray code (a^(a>>1)) so a string of 1's (as - is commonly produced by subtraction) look like a single 1-bit - difference. -* the base values were pseudorandom, all zero but one bit set, or - all zero plus a counter that starts at zero. - -Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that -satisfy this are - 4 6 8 16 19 4 - 9 15 3 18 27 15 - 14 9 3 7 17 3 -Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing -for "differ" defined as + with a one-bit base and a two-bit delta. I -used http://burtleburtle.net/bob/hash/avalanche.html to choose -the operations, constants, and arrangements of the variables. - -This does not achieve avalanche. There are input bits of (a,b,c) -that fail to affect some output bits of (a,b,c), especially of a. The -most thoroughly mixed value is c, but it doesn't really even achieve -avalanche in c. - -This allows some parallelism. Read-after-writes are good at doubling -the number of bits affected, so the goal of mixing pulls in the opposite -direction as the goal of parallelism. I did what I could. Rotates -seem to cost as much as shifts on every machine I could lay my hands -on, and rotates are much kinder to the top and bottom bits, so I used -rotates. -------------------------------------------------------------------------------- -*/ -#define mix(a,b,c) \ -{ \ - a -= c; a ^= rot(c, 4); c += b; \ - b -= a; b ^= rot(a, 6); a += c; \ - c -= b; c ^= rot(b, 8); b += a; \ - a -= c; a ^= rot(c,16); c += b; \ - b -= a; b ^= rot(a,19); a += c; \ - c -= b; c ^= rot(b, 4); b += a; \ -} - -/* -------------------------------------------------------------------------------- -final -- final mixing of 3 32-bit values (a,b,c) into c - -Pairs of (a,b,c) values differing in only a few bits will usually -produce values of c that look totally different. This was tested for -* pairs that differed by one bit, by two bits, in any combination - of top bits of (a,b,c), or in any combination of bottom bits of - (a,b,c). -* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed - the output delta to a Gray code (a^(a>>1)) so a string of 1's (as - is commonly produced by subtraction) look like a single 1-bit - difference. -* the base values were pseudorandom, all zero but one bit set, or - all zero plus a counter that starts at zero. - -These constants passed: - 14 11 25 16 4 14 24 - 12 14 25 16 4 14 24 -and these came close: - 4 8 15 26 3 22 24 - 10 8 15 26 3 22 24 - 11 8 15 26 3 22 24 -------------------------------------------------------------------------------- -*/ -#define final(a,b,c) \ -{ \ - c ^= b; c -= rot(b,14); \ - a ^= c; a -= rot(c,11); \ - b ^= a; b -= rot(a,25); \ - c ^= b; c -= rot(b,16); \ - a ^= c; a -= rot(c,4); \ - b ^= a; b -= rot(a,14); \ - c ^= b; c -= rot(b,24); \ -} - -/* -------------------------------------------------------------------------------- -hashlittle() -- hash a variable-length key into a 32-bit value - k : the key (the unaligned variable-length array of bytes) - length : the length of the key, counting by bytes - initval : can be any 4-byte value -Returns a 32-bit value. Every bit of the key affects every bit of -the return value. Two keys differing by one or two bits will have -totally different hash values. - -The best hash table sizes are powers of 2. There is no need to do -mod a prime (mod is sooo slow!). If you need less than 32 bits, -use a bitmask. For example, if you need only 10 bits, do - h = (h & hashmask(10)); -In which case, the hash table should have hashsize(10) elements. - -If you are hashing n strings (uint8_t **)k, do it like this: - for (i=0, h=0; i 12) - { - a += k[0]; - b += k[1]; - c += k[2]; - mix(a,b,c); - length -= 12; - k += 3; - } - - // printf("AAA %x %d %x %d\n",c,c,c&32767,c&32767); - - /*----------------------------- handle the last (probably partial) block */ - /* - * "k[2]&0xffffff" actually reads beyond the end of the string, but - * then masks off the part it's not allowed to read. Because the - * string is aligned, the masked-off tail is in the same word as the - * rest of the string. Every machine with memory protection I've seen - * does it on word boundaries, so is OK with this. But VALGRIND will - * still catch it and complain. The masking trick does make the hash - * noticably faster for short strings (like English words). - */ -#ifndef VALGRIND - - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; - case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; - case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=k[1]&0xffffff; a+=k[0]; break; - case 6 : b+=k[1]&0xffff; a+=k[0]; break; - case 5 : b+=k[1]&0xff; a+=k[0]; break; - case 4 : a+=k[0]; break; - case 3 : a+=k[0]&0xffffff; break; - case 2 : a+=k[0]&0xffff; break; - case 1 : a+=k[0]&0xff; break; - case 0 : return c; /* zero length strings require no mixing */ - } - -#else /* make valgrind happy */ - - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]; break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ - case 1 : a+=k8[0]; break; - case 0 : return c; - } - -#endif /* !valgrind */ - - } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { - const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ - const uint8_t *k8; - - /*--------------- all but last block: aligned reads and different mixing */ - while (length > 12) - { - a += k[0] + (((uint32_t)k[1])<<16); - b += k[2] + (((uint32_t)k[3])<<16); - c += k[4] + (((uint32_t)k[5])<<16); - mix(a,b,c); - length -= 12; - k += 6; - } - - /*----------------------------- handle the last (probably partial) block */ - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[4]+(((uint32_t)k[5])<<16); - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=k[4]; - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=k[2]; - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=k[0]; - break; - case 1 : a+=k8[0]; - break; - case 0 : return c; /* zero length requires no mixing */ - } - - } else { /* need to read the key one byte at a time */ - const uint8_t *k = (const uint8_t *)key; - - /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ - while (length > 12) - { - a += k[0]; - a += ((uint32_t)k[1])<<8; - a += ((uint32_t)k[2])<<16; - a += ((uint32_t)k[3])<<24; - b += k[4]; - b += ((uint32_t)k[5])<<8; - b += ((uint32_t)k[6])<<16; - b += ((uint32_t)k[7])<<24; - c += k[8]; - c += ((uint32_t)k[9])<<8; - c += ((uint32_t)k[10])<<16; - c += ((uint32_t)k[11])<<24; - mix(a,b,c); - length -= 12; - k += 12; - } - - /*-------------------------------- last block: affect all 32 bits of (c) */ - switch(length) /* all the case statements fall through */ - { - case 12: c+=((uint32_t)k[11])<<24; - /* fall through */ - case 11: c+=((uint32_t)k[10])<<16; - /* fall through */ - case 10: c+=((uint32_t)k[9])<<8; - /* fall through */ - case 9 : c+=k[8]; - /* fall through */ - case 8 : b+=((uint32_t)k[7])<<24; - /* fall through */ - case 7 : b+=((uint32_t)k[6])<<16; - /* fall through */ - case 6 : b+=((uint32_t)k[5])<<8; - /* fall through */ - case 5 : b+=k[4]; - /* fall through */ - case 4 : a+=((uint32_t)k[3])<<24; - /* fall through */ - case 3 : a+=((uint32_t)k[2])<<16; - /* fall through */ - case 2 : a+=((uint32_t)k[1])<<8; - /* fall through */ - case 1 : a+=k[0]; - break; - case 0 : return c; - } - } - - final(a,b,c); - return c; -} +/* + + File name: nhash2.c + + *------------------------------------------------------------------------------ + * + * This file is part of the WSPR application, Weak Signal Propogation Reporter + * + * File Name: nhash.c + * Description: Functions to produce 32-bit hashes for hash table lookup + * + * Copyright (C) 2008-2014 Joseph Taylor, K1JT + * License: GNU GPL v3+ + * + * 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 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Files: lookup3.c + * Copyright: Copyright (C) 2006 Bob Jenkins + * License: public-domain + * You may use this code any way you wish, private, educational, or commercial. + * It's free. + * + *------------------------------------------------------------------------------- +*/ + +/* +These are functions for producing 32-bit hashes for hash table lookup. +hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() +are externally useful functions. Routines to test the hash are included +if SELF_TEST is defined. You can use this free for any purpose. It's in +the public domain. It has no warranty. + +You probably want to use hashlittle(). hashlittle() and hashbig() +hash byte arrays. hashlittle() is is faster than hashbig() on +little-endian machines. Intel and AMD are little-endian machines. +On second thought, you probably want hashlittle2(), which is identical to +hashlittle() except it returns two 32-bit hashes for the price of one. +You could implement hashbig2() if you wanted but I haven't bothered here. + +If you want to find a hash of, say, exactly 7 integers, do + a = i1; b = i2; c = i3; + mix(a,b,c); + a += i4; b += i5; c += i6; + mix(a,b,c); + a += i7; + final(a,b,c); +then use c as the hash value. If you have a variable length array of +4-byte integers to hash, use hashword(). If you have a byte array (like +a character string), use hashlittle(). If you have several byte arrays, or +a mix of things, see the comments above hashlittle(). + +Why is this so big? I read 12 bytes at a time into 3 4-byte integers, +then mix those integers. This is fast (you can do a lot more thorough +mixing with 12*3 instructions on 3 integers than you can with 3 instructions +on 1 byte), but shoehorning those bytes into integers efficiently is messy. +*/ + +#define SELF_TEST 1 + +#include /* defines printf for tests */ +#include /* defines time_t for timings in the test */ +#include "nhash2.h" +//#include /* attempt to define endianness */ +//#ifdef linux +//# include /* attempt to define endianness */ +//#endif + +#define HASH_LITTLE_ENDIAN 1 + +#define hashsize(n) ((uint32_t)1<<(n)) +#define hashmask(n) (hashsize(n)-1) +#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) + +/* +------------------------------------------------------------------------------- +mix -- mix 3 32-bit values reversibly. + +This is reversible, so any information in (a,b,c) before mix() is +still in (a,b,c) after mix(). + +If four pairs of (a,b,c) inputs are run through mix(), or through +mix() in reverse, there are at least 32 bits of the output that +are sometimes the same for one pair and different for another pair. +This was tested for: +* pairs that differed by one bit, by two bits, in any combination + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). +* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. +* the base values were pseudorandom, all zero but one bit set, or + all zero plus a counter that starts at zero. + +Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that +satisfy this are + 4 6 8 16 19 4 + 9 15 3 18 27 15 + 14 9 3 7 17 3 +Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing +for "differ" defined as + with a one-bit base and a two-bit delta. I +used http://burtleburtle.net/bob/hash/avalanche.html to choose +the operations, constants, and arrangements of the variables. + +This does not achieve avalanche. There are input bits of (a,b,c) +that fail to affect some output bits of (a,b,c), especially of a. The +most thoroughly mixed value is c, but it doesn't really even achieve +avalanche in c. + +This allows some parallelism. Read-after-writes are good at doubling +the number of bits affected, so the goal of mixing pulls in the opposite +direction as the goal of parallelism. I did what I could. Rotates +seem to cost as much as shifts on every machine I could lay my hands +on, and rotates are much kinder to the top and bottom bits, so I used +rotates. +------------------------------------------------------------------------------- +*/ +#define mix(a,b,c) \ +{ \ + a -= c; a ^= rot(c, 4); c += b; \ + b -= a; b ^= rot(a, 6); a += c; \ + c -= b; c ^= rot(b, 8); b += a; \ + a -= c; a ^= rot(c,16); c += b; \ + b -= a; b ^= rot(a,19); a += c; \ + c -= b; c ^= rot(b, 4); b += a; \ +} + +/* +------------------------------------------------------------------------------- +final -- final mixing of 3 32-bit values (a,b,c) into c + +Pairs of (a,b,c) values differing in only a few bits will usually +produce values of c that look totally different. This was tested for +* pairs that differed by one bit, by two bits, in any combination + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). +* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. +* the base values were pseudorandom, all zero but one bit set, or + all zero plus a counter that starts at zero. + +These constants passed: + 14 11 25 16 4 14 24 + 12 14 25 16 4 14 24 +and these came close: + 4 8 15 26 3 22 24 + 10 8 15 26 3 22 24 + 11 8 15 26 3 22 24 +------------------------------------------------------------------------------- +*/ +#define final(a,b,c) \ +{ \ + c ^= b; c -= rot(b,14); \ + a ^= c; a -= rot(c,11); \ + b ^= a; b -= rot(a,25); \ + c ^= b; c -= rot(b,16); \ + a ^= c; a -= rot(c,4); \ + b ^= a; b -= rot(a,14); \ + c ^= b; c -= rot(b,24); \ +} + +/* +------------------------------------------------------------------------------- +hashlittle() -- hash a variable-length key into a 32-bit value + k : the key (the unaligned variable-length array of bytes) + length : the length of the key, counting by bytes + initval : can be any 4-byte value +Returns a 32-bit value. Every bit of the key affects every bit of +the return value. Two keys differing by one or two bits will have +totally different hash values. + +The best hash table sizes are powers of 2. There is no need to do +mod a prime (mod is sooo slow!). If you need less than 32 bits, +use a bitmask. For example, if you need only 10 bits, do + h = (h & hashmask(10)); +In which case, the hash table should have hashsize(10) elements. + +If you are hashing n strings (uint8_t **)k, do it like this: + for (i=0, h=0; i 12) + { + a += k[0]; + b += k[1]; + c += k[2]; + mix(a,b,c); + length -= 12; + k += 3; + } + + // printf("AAA %x %d %x %d\n",c,c,c&32767,c&32767); + + /*----------------------------- handle the last (probably partial) block */ + /* + * "k[2]&0xffffff" actually reads beyond the end of the string, but + * then masks off the part it's not allowed to read. Because the + * string is aligned, the masked-off tail is in the same word as the + * rest of the string. Every machine with memory protection I've seen + * does it on word boundaries, so is OK with this. But VALGRIND will + * still catch it and complain. The masking trick does make the hash + * noticably faster for short strings (like English words). + */ +#ifndef VALGRIND + + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; + case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; + case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=k[1]&0xffffff; a+=k[0]; break; + case 6 : b+=k[1]&0xffff; a+=k[0]; break; + case 5 : b+=k[1]&0xff; a+=k[0]; break; + case 4 : a+=k[0]; break; + case 3 : a+=k[0]&0xffffff; break; + case 2 : a+=k[0]&0xffff; break; + case 1 : a+=k[0]&0xff; break; + case 0 : return c; /* zero length strings require no mixing */ + } + +#else /* make valgrind happy */ + + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]; break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ + case 1 : a+=k8[0]; break; + case 0 : return c; + } + +#endif /* !valgrind */ + + } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { + const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ + const uint8_t *k8; + + /*--------------- all but last block: aligned reads and different mixing */ + while (length > 12) + { + a += k[0] + (((uint32_t)k[1])<<16); + b += k[2] + (((uint32_t)k[3])<<16); + c += k[4] + (((uint32_t)k[5])<<16); + mix(a,b,c); + length -= 12; + k += 6; + } + + /*----------------------------- handle the last (probably partial) block */ + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[4]+(((uint32_t)k[5])<<16); + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=k[4]; + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=k[2]; + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=k[0]; + break; + case 1 : a+=k8[0]; + break; + case 0 : return c; /* zero length requires no mixing */ + } + + } else { /* need to read the key one byte at a time */ + const uint8_t *k = (const uint8_t *)key; + + /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + a += ((uint32_t)k[1])<<8; + a += ((uint32_t)k[2])<<16; + a += ((uint32_t)k[3])<<24; + b += k[4]; + b += ((uint32_t)k[5])<<8; + b += ((uint32_t)k[6])<<16; + b += ((uint32_t)k[7])<<24; + c += k[8]; + c += ((uint32_t)k[9])<<8; + c += ((uint32_t)k[10])<<16; + c += ((uint32_t)k[11])<<24; + mix(a,b,c); + length -= 12; + k += 12; + } + + /*-------------------------------- last block: affect all 32 bits of (c) */ + switch(length) /* all the case statements fall through */ + { + case 12: c+=((uint32_t)k[11])<<24; + /* fall through */ + case 11: c+=((uint32_t)k[10])<<16; + /* fall through */ + case 10: c+=((uint32_t)k[9])<<8; + /* fall through */ + case 9 : c+=k[8]; + /* fall through */ + case 8 : b+=((uint32_t)k[7])<<24; + /* fall through */ + case 7 : b+=((uint32_t)k[6])<<16; + /* fall through */ + case 6 : b+=((uint32_t)k[5])<<8; + /* fall through */ + case 5 : b+=k[4]; + /* fall through */ + case 4 : a+=((uint32_t)k[3])<<24; + /* fall through */ + case 3 : a+=((uint32_t)k[2])<<16; + /* fall through */ + case 2 : a+=((uint32_t)k[1])<<8; + /* fall through */ + case 1 : a+=k[0]; + break; + case 0 : return c; + } + } + + final(a,b,c); + return c; +} diff --git a/lib/superfox/qpc/nhash2.h b/lib/superfox/qpc/nhash2.h index 830e18ac..1864a93f 100755 --- a/lib/superfox/qpc/nhash2.h +++ b/lib/superfox/qpc/nhash2.h @@ -1,22 +1,22 @@ -#ifndef NHASH_H_ -#define NHASH_H_ - -#ifdef Win32 -#include "win_stdint.h" /* defines uint32_t etc */ -#else -#include -#include /* defines uint32_t etc */ -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -uint32_t nhash( const void * key, uint64_t length, uint32_t initval); - //int nhash(const char *key, int length, int initval); - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef NHASH_H_ +#define NHASH_H_ + +#ifdef Win32 +#include "win_stdint.h" /* defines uint32_t etc */ +#else +#include +#include /* defines uint32_t etc */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t nhash( const void * key, uint64_t length, uint32_t initval); + //int nhash(const char *key, int length, int initval); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/superfox/qpc/np_qpc.c b/lib/superfox/qpc/np_qpc.c index 9398c43b..d44e544b 100755 --- a/lib/superfox/qpc/np_qpc.c +++ b/lib/superfox/qpc/np_qpc.c @@ -1,329 +1,329 @@ -// ------------------------------------------------------------------------------ -// np_qpc.h -// Q-Ary Polar Codes encoding/decoding functions -// -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// -// This source 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 3 of the License, or -// (at your option) any later version. -// This file is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this source distribution. -// If not, see . - -#include -#include -#include - -#include "dbgprintf.h" -#include "qpc_fwht.h" -#include "np_qpc.h" - -// static constant / functions - -static const float knorm = 1.0f / QPC_Q; - -static float* pdf_conv(float *dst, float* pdf1, float* pdf2) -{ - // convolution between two pdf - - float fwht_pdf1[QPC_Q]; - float fwht_pdf2[QPC_Q]; - int k; - - qpc_fwht(fwht_pdf1, pdf1); - qpc_fwht(fwht_pdf2, pdf2); - - for (k = 0; k < QPC_Q; k++) - fwht_pdf1[k] *= fwht_pdf2[k]; - - qpc_fwht(dst, fwht_pdf1); - - for (k = 0; k < QPC_Q; k++) - dst[k] *= knorm; - - return dst; -} -static void pdfarray_conv(float* dstarray, float* pdf1array, float* pdf2array, int numrows) -{ - int k; - - // convolutions between rows of pdfs - - for (k = 0; k < numrows; k++) { - pdf_conv(dstarray, pdf1array, pdf2array); - dstarray += QPC_Q; - pdf1array += QPC_Q; - pdf2array += QPC_Q; - } - -} - -static float _pdfuniform[QPC_Q]; -static const float* _pdf_uniform1(); -static const float* _pdf_uniform0(); -typedef const float*(*ptr_pdfuniform)(void); - -static ptr_pdfuniform _ptr_pdf_uniform = _pdf_uniform0; - -static const float* _pdf_uniform1() -{ - return _pdfuniform; -}; -static const float* _pdf_uniform0() -{ - // compute uniform pdf once for all - int k; - for (k = 0; k < QPC_Q; k++) - _pdfuniform[k] = knorm; - - // next call to _qpc_pdfuniform - // will be handled directly by _pqc_pdfuniform1 - _ptr_pdf_uniform = _pdf_uniform1; - - return _pdfuniform; -}; -static const float* pdf_uniform() -{ - return _ptr_pdf_uniform(); -} - -static float * pdf_mul(float *dst, float* pdf1, float* pdf2) -{ - int k; - float v; - float norm = 0; - for (k = 0; k < QPC_Q; k++) { - v = pdf1[k] * pdf2[k]; - dst[k] = v; - norm += v; - } - // if norm of the result is not positive - // return in dst a uniform distribution - if (norm <= 0) - memcpy(dst, pdf_uniform(), QPC_Q * sizeof(float)); - else { - norm = 1.0f / norm; - for (k = 0; k < QPC_Q; k++) - dst[k] = dst[k] * norm; - } - - - return dst; -} -static void pdfarray_mul(float* dstarray, float* pdf1array, float* pdf2array, int numrows) -{ - int k; - - // products between rows of pdfs - - for (k = 0; k < numrows; k++) { - pdf_mul(dstarray, pdf1array, pdf2array); - dstarray += QPC_Q; - pdf1array += QPC_Q; - pdf2array += QPC_Q; - } -} - -static float* pdf_convhard(float* dst, const float* pdf, unsigned char hd) -{ - // convolution between a pdf and a hard-decision feedback - - int k; - for (k=0;k pdfmax) { - pdfmax = pdf[k]; - imax = k; - } - - return imax; -} - -// local stack functions --------------------------------------- -static float _qpc_stack[QPC_N * QPC_Q * 2]; -static float* _qpc_stack_base = _qpc_stack; - -static float* _qpc_stack_push(int numfloats) -{ - float* addr = _qpc_stack_base; - _qpc_stack_base += numfloats; - return addr; -} -static void _qpc_stack_pop(int numfloats) -{ - _qpc_stack_base -= numfloats; -} - -// qpc encoder function (internal use) ---------------------------------------------------------- -unsigned char* _qpc_encode(unsigned char* y, unsigned char* x) -{ - // Non recursive polar encoder - // Same architecture of a fast fourier transform - // in which the fft butteflies are replaced by the polar transform - // butterflies - - int k, j, m; - int groups; - int bfypergroup; - int stepbfy; - int stepgroup; - int basegroup; - int basebfy; - - memcpy(y, x, QPC_N); - - for (k = 0; k < QPC_LOG2N; k++) { - groups = 1 << (QPC_LOG2N - 1 - k); - stepbfy = bfypergroup = 1 << k; - stepgroup = stepbfy << 1; - basegroup = 0; - for (j = 0; j < groups; j++) { - basebfy = basegroup; - for (m = 0; m < bfypergroup; m++) { - // polar transform - y[basebfy + stepbfy] = y[basebfy + stepbfy] ^ y[basebfy]; - basebfy = basebfy + 1; - } - basegroup = basegroup + stepgroup; - } - } - - return y; -} - -// qpc polar decoder (internal use )-------------------------------------------------- -void _qpc_decode(unsigned char* xdec, unsigned char* ydec, const float* py, const unsigned char* f, const unsigned char* fsize, const int numrows) -{ - - if (numrows == 1) { - if (fsize[0] == 0) { - // dbgprintf_vector_float("py", py, QPC_Q); - - // frozen symbol - xdec[0] = pdf_max(py); - ydec[0] = f[0]; - } - else { - // fsize = 1 => information symbol - xdec[0] = pdf_max(py); - ydec[0] = xdec[0]; - } - - } - else { - - int k; - int nextrows = numrows >> 1; - int size = nextrows << QPC_LOG2Q; - - // upper block variables - unsigned char* xdech = xdec + nextrows; - unsigned char* ydech = ydec + nextrows; - const unsigned char* fh = f + nextrows; - const unsigned char* fsizeh = fsize + nextrows; - - // Step 1. - // stack and init variables used in the recursion - - float* pyl = _qpc_stack_push(size); - memcpy(pyl, py, size * sizeof(float)); - - float* pyh = _qpc_stack_push(size); - memcpy(pyh, py + size, size * sizeof(float)); - - // Step 2. Recursion on upper block - // Forward pdf convolutions for the upper block - // (place in the lower part of py the convolution of lower and higher blocks) - -// float* pyh = py + size; -// pdfarray_conv(py, pyl, pyh, nextrows); // convolution overwriting the lower block of py which is not needed - - pdfarray_conv(pyh, pyl, pyh, nextrows); - _qpc_decode(xdech, ydech, pyh, fh, fsizeh, nextrows); - - // Step 3. compute pdfs in the lower block - pdfarray_convhard(pyh, py+size, ydech,nextrows); // dst ptr must be different form src ptr - pdfarray_mul(pyl, pyl, pyh, nextrows); - // we don't need pyh anymore - _qpc_stack_pop(size); - - // Step 4. Recursion on the lower block - _qpc_decode(xdec, ydec, pyl, f, fsize, nextrows); - // we don't need pyl anymore - _qpc_stack_pop(size); - - // Step 5. Update backward results - // xdec is already ok, we need just to update ydech - for (k = 0; k < nextrows; k++) - ydech[k] = ydech[k] ^ ydec[k]; - - } - - -} - -// Public encoding/decoding functions ------------------------------------------------ -void qpc_encode(unsigned char* y, const unsigned char* x) -{ - - // map information symbols - int kk, pos; - for (kk = 0; kk < QPC_K; kk++) { - pos = qpccode.xpos[kk]; - qpccode.f[pos] = x[kk]; - } - // do polar encoding - _qpc_encode(y, qpccode.f); -} -void qpc_decode(unsigned char* xdec, unsigned char* ydec, float* py) -{ - int k; - unsigned char x[QPC_N]; - - // set the first py row with know frozen (punctured) symbol - if (qpccode.np < qpccode.n) { - // assume that we punctured only the first output symbol - memset(py, 0, QPC_Q * sizeof(float)); - py[qpccode.f[0]] = 1.0f; - } - - // decode - _qpc_decode(x, ydec, py, qpccode.f, qpccode.fsize, QPC_N); - - // demap information symbols - for (k = 0; k < QPC_K; k++) - xdec[k] = x[qpccode.xpos[k]]; - -} +// ------------------------------------------------------------------------------ +// np_qpc.h +// Q-Ary Polar Codes encoding/decoding functions +// +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// +// This source 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 3 of the License, or +// (at your option) any later version. +// This file is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this source distribution. +// If not, see . + +#include +#include +#include + +#include "dbgprintf.h" +#include "qpc_fwht.h" +#include "np_qpc.h" + +// static constant / functions + +static const float knorm = 1.0f / QPC_Q; + +static float* pdf_conv(float *dst, float* pdf1, float* pdf2) +{ + // convolution between two pdf + + float fwht_pdf1[QPC_Q]; + float fwht_pdf2[QPC_Q]; + int k; + + qpc_fwht(fwht_pdf1, pdf1); + qpc_fwht(fwht_pdf2, pdf2); + + for (k = 0; k < QPC_Q; k++) + fwht_pdf1[k] *= fwht_pdf2[k]; + + qpc_fwht(dst, fwht_pdf1); + + for (k = 0; k < QPC_Q; k++) + dst[k] *= knorm; + + return dst; +} +static void pdfarray_conv(float* dstarray, float* pdf1array, float* pdf2array, int numrows) +{ + int k; + + // convolutions between rows of pdfs + + for (k = 0; k < numrows; k++) { + pdf_conv(dstarray, pdf1array, pdf2array); + dstarray += QPC_Q; + pdf1array += QPC_Q; + pdf2array += QPC_Q; + } + +} + +static float _pdfuniform[QPC_Q]; +static const float* _pdf_uniform1(); +static const float* _pdf_uniform0(); +typedef const float*(*ptr_pdfuniform)(void); + +static ptr_pdfuniform _ptr_pdf_uniform = _pdf_uniform0; + +static const float* _pdf_uniform1() +{ + return _pdfuniform; +}; +static const float* _pdf_uniform0() +{ + // compute uniform pdf once for all + int k; + for (k = 0; k < QPC_Q; k++) + _pdfuniform[k] = knorm; + + // next call to _qpc_pdfuniform + // will be handled directly by _pqc_pdfuniform1 + _ptr_pdf_uniform = _pdf_uniform1; + + return _pdfuniform; +}; +static const float* pdf_uniform() +{ + return _ptr_pdf_uniform(); +} + +static float * pdf_mul(float *dst, float* pdf1, float* pdf2) +{ + int k; + float v; + float norm = 0; + for (k = 0; k < QPC_Q; k++) { + v = pdf1[k] * pdf2[k]; + dst[k] = v; + norm += v; + } + // if norm of the result is not positive + // return in dst a uniform distribution + if (norm <= 0) + memcpy(dst, pdf_uniform(), QPC_Q * sizeof(float)); + else { + norm = 1.0f / norm; + for (k = 0; k < QPC_Q; k++) + dst[k] = dst[k] * norm; + } + + + return dst; +} +static void pdfarray_mul(float* dstarray, float* pdf1array, float* pdf2array, int numrows) +{ + int k; + + // products between rows of pdfs + + for (k = 0; k < numrows; k++) { + pdf_mul(dstarray, pdf1array, pdf2array); + dstarray += QPC_Q; + pdf1array += QPC_Q; + pdf2array += QPC_Q; + } +} + +static float* pdf_convhard(float* dst, const float* pdf, unsigned char hd) +{ + // convolution between a pdf and a hard-decision feedback + + int k; + for (k=0;k pdfmax) { + pdfmax = pdf[k]; + imax = k; + } + + return imax; +} + +// local stack functions --------------------------------------- +static float _qpc_stack[QPC_N * QPC_Q * 2]; +static float* _qpc_stack_base = _qpc_stack; + +static float* _qpc_stack_push(int numfloats) +{ + float* addr = _qpc_stack_base; + _qpc_stack_base += numfloats; + return addr; +} +static void _qpc_stack_pop(int numfloats) +{ + _qpc_stack_base -= numfloats; +} + +// qpc encoder function (internal use) ---------------------------------------------------------- +unsigned char* _qpc_encode(unsigned char* y, unsigned char* x) +{ + // Non recursive polar encoder + // Same architecture of a fast fourier transform + // in which the fft butteflies are replaced by the polar transform + // butterflies + + int k, j, m; + int groups; + int bfypergroup; + int stepbfy; + int stepgroup; + int basegroup; + int basebfy; + + memcpy(y, x, QPC_N); + + for (k = 0; k < QPC_LOG2N; k++) { + groups = 1 << (QPC_LOG2N - 1 - k); + stepbfy = bfypergroup = 1 << k; + stepgroup = stepbfy << 1; + basegroup = 0; + for (j = 0; j < groups; j++) { + basebfy = basegroup; + for (m = 0; m < bfypergroup; m++) { + // polar transform + y[basebfy + stepbfy] = y[basebfy + stepbfy] ^ y[basebfy]; + basebfy = basebfy + 1; + } + basegroup = basegroup + stepgroup; + } + } + + return y; +} + +// qpc polar decoder (internal use )-------------------------------------------------- +void _qpc_decode(unsigned char* xdec, unsigned char* ydec, const float* py, const unsigned char* f, const unsigned char* fsize, const int numrows) +{ + + if (numrows == 1) { + if (fsize[0] == 0) { + // dbgprintf_vector_float("py", py, QPC_Q); + + // frozen symbol + xdec[0] = pdf_max(py); + ydec[0] = f[0]; + } + else { + // fsize = 1 => information symbol + xdec[0] = pdf_max(py); + ydec[0] = xdec[0]; + } + + } + else { + + int k; + int nextrows = numrows >> 1; + int size = nextrows << QPC_LOG2Q; + + // upper block variables + unsigned char* xdech = xdec + nextrows; + unsigned char* ydech = ydec + nextrows; + const unsigned char* fh = f + nextrows; + const unsigned char* fsizeh = fsize + nextrows; + + // Step 1. + // stack and init variables used in the recursion + + float* pyl = _qpc_stack_push(size); + memcpy(pyl, py, size * sizeof(float)); + + float* pyh = _qpc_stack_push(size); + memcpy(pyh, py + size, size * sizeof(float)); + + // Step 2. Recursion on upper block + // Forward pdf convolutions for the upper block + // (place in the lower part of py the convolution of lower and higher blocks) + +// float* pyh = py + size; +// pdfarray_conv(py, pyl, pyh, nextrows); // convolution overwriting the lower block of py which is not needed + + pdfarray_conv(pyh, pyl, pyh, nextrows); + _qpc_decode(xdech, ydech, pyh, fh, fsizeh, nextrows); + + // Step 3. compute pdfs in the lower block + pdfarray_convhard(pyh, py+size, ydech,nextrows); // dst ptr must be different form src ptr + pdfarray_mul(pyl, pyl, pyh, nextrows); + // we don't need pyh anymore + _qpc_stack_pop(size); + + // Step 4. Recursion on the lower block + _qpc_decode(xdec, ydec, pyl, f, fsize, nextrows); + // we don't need pyl anymore + _qpc_stack_pop(size); + + // Step 5. Update backward results + // xdec is already ok, we need just to update ydech + for (k = 0; k < nextrows; k++) + ydech[k] = ydech[k] ^ ydec[k]; + + } + + +} + +// Public encoding/decoding functions ------------------------------------------------ +void qpc_encode(unsigned char* y, const unsigned char* x) +{ + + // map information symbols + int kk, pos; + for (kk = 0; kk < QPC_K; kk++) { + pos = qpccode.xpos[kk]; + qpccode.f[pos] = x[kk]; + } + // do polar encoding + _qpc_encode(y, qpccode.f); +} +void qpc_decode(unsigned char* xdec, unsigned char* ydec, float* py) +{ + int k; + unsigned char x[QPC_N]; + + // set the first py row with know frozen (punctured) symbol + if (qpccode.np < qpccode.n) { + // assume that we punctured only the first output symbol + memset(py, 0, QPC_Q * sizeof(float)); + py[qpccode.f[0]] = 1.0f; + } + + // decode + _qpc_decode(x, ydec, py, qpccode.f, qpccode.fsize, QPC_N); + + // demap information symbols + for (k = 0; k < QPC_K; k++) + xdec[k] = x[qpccode.xpos[k]]; + +} diff --git a/lib/superfox/qpc/np_qpc.h b/lib/superfox/qpc/np_qpc.h index a93bf1bc..0fa440e7 100755 --- a/lib/superfox/qpc/np_qpc.h +++ b/lib/superfox/qpc/np_qpc.h @@ -1,62 +1,62 @@ -// ------------------------------------------------------------------------------ -// np_qpc.h -// Q-Ary Polar Codes encoding/decoding functions -// -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// -// This source 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 3 of the License, or -// (at your option) any later version. -// This file is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this source distribution. -// If not, see . - - - -#ifndef _np_qpc_h_ -#define _np_qpc_h_ - -#define QPC_LOG2N 7 // log2(codeword length) (not punctured) -#define QPC_N (1< frozen) -} qpccode_ds; - -#ifdef __cplusplus -extern "C" -{ -#endif - - void qpc_encode(unsigned char* y, const unsigned char* x); - void qpc_decode(unsigned char* xdec, unsigned char* ydec, float* py); - - unsigned char* _qpc_encode(unsigned char* y, unsigned char* x); - void _qpc_decode(unsigned char* xdec, unsigned char* ydec, - const float* py, const unsigned char* f, const unsigned char* fsize, - const int numrows); - - extern qpccode_ds qpccode; - -#ifdef __cplusplus -} -#endif - -#endif // _np_qpc_h_ +// ------------------------------------------------------------------------------ +// np_qpc.h +// Q-Ary Polar Codes encoding/decoding functions +// +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// +// This source 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 3 of the License, or +// (at your option) any later version. +// This file is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this source distribution. +// If not, see . + + + +#ifndef _np_qpc_h_ +#define _np_qpc_h_ + +#define QPC_LOG2N 7 // log2(codeword length) (not punctured) +#define QPC_N (1< frozen) +} qpccode_ds; + +#ifdef __cplusplus +extern "C" +{ +#endif + + void qpc_encode(unsigned char* y, const unsigned char* x); + void qpc_decode(unsigned char* xdec, unsigned char* ydec, float* py); + + unsigned char* _qpc_encode(unsigned char* y, unsigned char* x); + void _qpc_decode(unsigned char* xdec, unsigned char* ydec, + const float* py, const unsigned char* f, const unsigned char* fsize, + const int numrows); + + extern qpccode_ds qpccode; + +#ifdef __cplusplus +} +#endif + +#endif // _np_qpc_h_ diff --git a/lib/superfox/qpc/np_rnd.c b/lib/superfox/qpc/np_rnd.c index 1d792c6b..df2afacc 100755 --- a/lib/superfox/qpc/np_rnd.c +++ b/lib/superfox/qpc/np_rnd.c @@ -1,135 +1,135 @@ -// ------------------------------------------------------------------------------ -// np_rnd.c -// Functions to generate random numbers with uniform/gaussian probability distributions -// -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// -// This source 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 3 of the License, or -// (at your option) any later version. -// This file is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this source distribution. -// If not, see . - -#include "np_rnd.h" - -#if _WIN32 // note the underscore: without it, it's not msdn official! - // Windows (x64 and x86) - #include // required only for GetTickCount(...) - #define K_RAND_MAX UINT_MAX -#elif _SVID_SOURCE || _XOPEN_SOURCE || __unix__ || (defined (__APPLE__) && defined(__MACH__)) /* POSIX or Unix or Apple */ - #include - #define rand_s(x) (*x)=(unsigned int)lrand48() // returns unsigned integers in the range 0..0x7FFFFFFF - #define K_RAND_MAX 0x7FFFFFFF // that's the max number - // generated by lrand48 -#else - #error "No good quality PRNG found" -#endif - - -void np_normrnd_real(float *dst, int nitems, float mean, float stdev) -{ - // for odd or even nitems - - unsigned int r; - float phi=0, u=0; - int set = 0; - float scalephi = (M_2PI / (1.0f + K_RAND_MAX)); - float scaleu = (1.0f / (1.0f + K_RAND_MAX)); - - - while (nitems--) - if (set==1) { - // generate a second normally distributed number - *dst++ = sinf(phi)*u*stdev+mean; - set = 0; - } - else { - // generate a uniform distributed phase phi in the range [0,2*PI) - rand_s((unsigned int*)&r); phi = scalephi * r; - - // generate a uniform distributed random number u in the range (0,1] - rand_s((unsigned int*)&r); u = scaleu * (1.0f + r); - - // generate normally distributed number - u = (float)sqrt(-2.0f * log(u)); - *dst++ = cosf(phi) * u * stdev + mean; - - set=1; - } -} - -void np_normrnd_cpx(float* dst, int nitems, float mean, float stdev) -{ - // as qpc_normrnd_real, but generates always nitems complex numbers (2*nitems reals) - - unsigned int r; - float phi = 0, u = 0; - // JHT int set = 0; - float scalephi = (M_2PI / (1.0f + K_RAND_MAX)); - float scaleu = (1.0f / (1.0f + K_RAND_MAX)); - - while (nitems--) { - // generate a uniform distributed phase phi in the range [0,2*PI) - rand_s((unsigned int*)&r); phi = scalephi * r; - - // generate a uniform distributed random number u in the range (0,1] - rand_s((unsigned int*)&r); u = scaleu * (1.0f + r); - - // generate normally distributed real and imaginary parts - u = (float)sqrt(-2.0f * log(u)); - *dst++ = cosf(phi) * u * stdev + mean; - *dst++ = sinf(phi) * u * stdev + mean; - } -} - -void np_unidrnd(unsigned int* dst, int nitems, unsigned int nsetsize) -{ - // generate uniform unsigned int random numbers in the range [0..nsetsize) - - unsigned int r; - float u; - float scaleu = (1.0f / (1.0f + K_RAND_MAX)); - - while (nitems--) { - rand_s((unsigned int*)&r); u = scaleu * nsetsize * r; - *dst++ = (unsigned int)floorf(u); - } - -} -void np_unidrnd_uc(unsigned char* dst, int nitems, unsigned char nsetsize) -{ - // generate uniform unsigned char random numbers in the range [0..nsetsize) - - unsigned int r; - float u; - float scaleu = (1.0f / (1.0f + K_RAND_MAX)); - - while (nitems--) { - rand_s((unsigned int*)&r); u = scaleu * nsetsize * r; - *dst++ = (unsigned char)floorf(u); - } - -} - -void np_unifrnd(float* dst, int nitems, float fmax) -{ - // generate uniform float random numbers in the range [0..fmax) - - unsigned int r; - float u; - float scaleu = (1.0f / (1.0f + K_RAND_MAX)); - - while (nitems--) { - rand_s((unsigned int*)&r); u = scaleu * fmax * r; - *dst++ = u; - } - -} +// ------------------------------------------------------------------------------ +// np_rnd.c +// Functions to generate random numbers with uniform/gaussian probability distributions +// +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// +// This source 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 3 of the License, or +// (at your option) any later version. +// This file is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this source distribution. +// If not, see . + +#include "np_rnd.h" + +#if _WIN32 // note the underscore: without it, it's not msdn official! + // Windows (x64 and x86) + #include // required only for GetTickCount(...) + #define K_RAND_MAX UINT_MAX +#elif _SVID_SOURCE || _XOPEN_SOURCE || __unix__ || (defined (__APPLE__) && defined(__MACH__)) /* POSIX or Unix or Apple */ + #include + #define rand_s(x) (*x)=(unsigned int)lrand48() // returns unsigned integers in the range 0..0x7FFFFFFF + #define K_RAND_MAX 0x7FFFFFFF // that's the max number + // generated by lrand48 +#else + #error "No good quality PRNG found" +#endif + + +void np_normrnd_real(float *dst, int nitems, float mean, float stdev) +{ + // for odd or even nitems + + unsigned int r; + float phi=0, u=0; + int set = 0; + float scalephi = (M_2PI / (1.0f + K_RAND_MAX)); + float scaleu = (1.0f / (1.0f + K_RAND_MAX)); + + + while (nitems--) + if (set==1) { + // generate a second normally distributed number + *dst++ = sinf(phi)*u*stdev+mean; + set = 0; + } + else { + // generate a uniform distributed phase phi in the range [0,2*PI) + rand_s((unsigned int*)&r); phi = scalephi * r; + + // generate a uniform distributed random number u in the range (0,1] + rand_s((unsigned int*)&r); u = scaleu * (1.0f + r); + + // generate normally distributed number + u = (float)sqrt(-2.0f * log(u)); + *dst++ = cosf(phi) * u * stdev + mean; + + set=1; + } +} + +void np_normrnd_cpx(float* dst, int nitems, float mean, float stdev) +{ + // as qpc_normrnd_real, but generates always nitems complex numbers (2*nitems reals) + + unsigned int r; + float phi = 0, u = 0; + // JHT int set = 0; + float scalephi = (M_2PI / (1.0f + K_RAND_MAX)); + float scaleu = (1.0f / (1.0f + K_RAND_MAX)); + + while (nitems--) { + // generate a uniform distributed phase phi in the range [0,2*PI) + rand_s((unsigned int*)&r); phi = scalephi * r; + + // generate a uniform distributed random number u in the range (0,1] + rand_s((unsigned int*)&r); u = scaleu * (1.0f + r); + + // generate normally distributed real and imaginary parts + u = (float)sqrt(-2.0f * log(u)); + *dst++ = cosf(phi) * u * stdev + mean; + *dst++ = sinf(phi) * u * stdev + mean; + } +} + +void np_unidrnd(unsigned int* dst, int nitems, unsigned int nsetsize) +{ + // generate uniform unsigned int random numbers in the range [0..nsetsize) + + unsigned int r; + float u; + float scaleu = (1.0f / (1.0f + K_RAND_MAX)); + + while (nitems--) { + rand_s((unsigned int*)&r); u = scaleu * nsetsize * r; + *dst++ = (unsigned int)floorf(u); + } + +} +void np_unidrnd_uc(unsigned char* dst, int nitems, unsigned char nsetsize) +{ + // generate uniform unsigned char random numbers in the range [0..nsetsize) + + unsigned int r; + float u; + float scaleu = (1.0f / (1.0f + K_RAND_MAX)); + + while (nitems--) { + rand_s((unsigned int*)&r); u = scaleu * nsetsize * r; + *dst++ = (unsigned char)floorf(u); + } + +} + +void np_unifrnd(float* dst, int nitems, float fmax) +{ + // generate uniform float random numbers in the range [0..fmax) + + unsigned int r; + float u; + float scaleu = (1.0f / (1.0f + K_RAND_MAX)); + + while (nitems--) { + rand_s((unsigned int*)&r); u = scaleu * fmax * r; + *dst++ = u; + } + +} diff --git a/lib/superfox/qpc/np_rnd.h b/lib/superfox/qpc/np_rnd.h index 6bc27b20..47a71a3c 100755 --- a/lib/superfox/qpc/np_rnd.h +++ b/lib/superfox/qpc/np_rnd.h @@ -1,59 +1,59 @@ -// ------------------------------------------------------------------------------ -// np_rnd.h -// Functions to generate random numbers with uniform/gaussian probability distributions -// -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// -// This source 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 3 of the License, or -// (at your option) any later version. -// This file is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this source distribution. -// If not, see . - -#ifndef _np_rnd_h_ -#define _np_rnd_h_ - -#define _CRT_RAND_S -#include - -#define _USE_MATH_DEFINES -#include -#define M_2PI (2.0f*(float)M_PI) - -#ifdef __cplusplus -extern "C" { -#endif - -// generate a random array of real numbers with a gaussian distribution of given mean and stdev -void np_normrnd_real(float *dst, int nitems, float mean, float stdev); - -// generate a random array of nitems complex numbers with a gaussian distribution of given mean and stdev -void np_normrnd_cpx(float* dst, int nitems, float mean, float stdev); - -// generate a random array of nitems unsigned int numbers with uniform distribution -// in the range [0 .. nsetsize) -void np_unidrnd(unsigned int* dst, int nitems, unsigned int nsetsize); - -// generate a random array of nitems unsigned chars numbers with uniform distribution -// in the range [0 .. nsetsize) -void np_unidrnd_uc(unsigned char* dst, int nitems, unsigned char nsetsize); - -// generate a random array of nitems float numbers with uniform distribution -// in the range [0 .. fmax) -void np_unifrnd(float* dst, int nitems, float fmax); - - -#ifdef __cplusplus -} -#endif - -#endif // _np_rnd_h_ - +// ------------------------------------------------------------------------------ +// np_rnd.h +// Functions to generate random numbers with uniform/gaussian probability distributions +// +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// +// This source 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 3 of the License, or +// (at your option) any later version. +// This file is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this source distribution. +// If not, see . + +#ifndef _np_rnd_h_ +#define _np_rnd_h_ + +#define _CRT_RAND_S +#include + +#define _USE_MATH_DEFINES +#include +#define M_2PI (2.0f*(float)M_PI) + +#ifdef __cplusplus +extern "C" { +#endif + +// generate a random array of real numbers with a gaussian distribution of given mean and stdev +void np_normrnd_real(float *dst, int nitems, float mean, float stdev); + +// generate a random array of nitems complex numbers with a gaussian distribution of given mean and stdev +void np_normrnd_cpx(float* dst, int nitems, float mean, float stdev); + +// generate a random array of nitems unsigned int numbers with uniform distribution +// in the range [0 .. nsetsize) +void np_unidrnd(unsigned int* dst, int nitems, unsigned int nsetsize); + +// generate a random array of nitems unsigned chars numbers with uniform distribution +// in the range [0 .. nsetsize) +void np_unidrnd_uc(unsigned char* dst, int nitems, unsigned char nsetsize); + +// generate a random array of nitems float numbers with uniform distribution +// in the range [0 .. fmax) +void np_unifrnd(float* dst, int nitems, float fmax); + + +#ifdef __cplusplus +} +#endif + +#endif // _np_rnd_h_ + diff --git a/lib/superfox/qpc/qpc_fwht.c b/lib/superfox/qpc/qpc_fwht.c index 92cb7c2b..77411211 100755 --- a/lib/superfox/qpc/qpc_fwht.c +++ b/lib/superfox/qpc/qpc_fwht.c @@ -1,233 +1,233 @@ -// ------------------------------------------------------------------------------ -// qpc_fwht.c -// Fast Walsh-Hadamard Transforms for q-ary polar codes -// -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// -// This source 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 3 of the License, or -// (at your option) any later version. -// This file is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this source distribution. -// If not, see . - -#include "qpc_fwht.h" - -static void _qpc_sumdiff8_16(float* y, float* t) -{ - y[0] = t[0] + t[16]; - y[16] = t[0] - t[16]; - - y[1] = t[1] + t[17]; - y[17] = t[1] - t[17]; - - y[2] = t[2] + t[18]; - y[18] = t[2] - t[18]; - - y[3] = t[3] + t[19]; - y[19] = t[3] - t[19]; - - y[4] = t[4] + t[20]; - y[20] = t[4] - t[20]; - - y[5] = t[5] + t[21]; - y[21] = t[5] - t[21]; - - y[6] = t[6] + t[22]; - y[22] = t[6] - t[22]; - - y[7] = t[7] + t[23]; - y[23] = t[7] - t[23]; - -} -static void _qpc_sumdiff8_32(float* y, float* t) -{ - y[0] = t[0] + t[32]; - y[32] = t[0] - t[32]; - - y[1] = t[1] + t[33]; - y[33] = t[1] - t[33]; - - y[2] = t[2] + t[34]; - y[34] = t[2] - t[34]; - - y[3] = t[3] + t[35]; - y[35] = t[3] - t[35]; - - y[4] = t[4] + t[36]; - y[36] = t[4] - t[36]; - - y[5] = t[5] + t[37]; - y[37] = t[5] - t[37]; - - y[6] = t[6] + t[38]; - y[38] = t[6] - t[38]; - - y[7] = t[7] + t[39]; - y[39] = t[7] - t[39]; - -} -static void _qpc_sumdiff8_64(float* y, float* t) -{ - y[0] = t[0] + t[64]; - y[64] = t[0] - t[64]; - - y[1] = t[1] + t[65]; - y[65] = t[1] - t[65]; - - y[2] = t[2] + t[66]; - y[66] = t[2] - t[66]; - - y[3] = t[3] + t[67]; - y[67] = t[3] - t[67]; - - y[4] = t[4] + t[68]; - y[68] = t[4] - t[68]; - - y[5] = t[5] + t[69]; - y[69] = t[5] - t[69]; - - y[6] = t[6] + t[70]; - y[70] = t[6] - t[70]; - - y[7] = t[7] + t[71]; - y[71] = t[7] - t[71]; - -} - -float* qpc_fwht8(float* y, float* x) -{ - float t[8]; - - // first stage - y[0] = x[0] + x[1]; - y[1] = x[0] - x[1]; - - y[2] = x[2] + x[3]; - y[3] = x[2] - x[3]; - - y[4] = x[4] + x[5]; - y[5] = x[4] - x[5]; - - y[6] = x[6] + x[7]; - y[7] = x[6] - x[7]; - - // second stage - t[0] = y[0] + y[2]; - t[2] = y[0] - y[2]; - - t[1] = y[1] + y[3]; - t[3] = y[1] - y[3]; - - t[4] = y[4] + y[6]; - t[6] = y[4] - y[6]; - - t[5] = y[5] + y[7]; - t[7] = y[5] - y[7]; - - // third stage - y[0] = t[0] + t[4]; - y[4] = t[0] - t[4]; - - y[1] = t[1] + t[5]; - y[5] = t[1] - t[5]; - - y[2] = t[2] + t[6]; - y[6] = t[2] - t[6]; - - y[3] = t[3] + t[7]; - y[7] = t[3] - t[7]; - - return y; -} -float* qpc_fwht16(float* y, float* x) -{ - float t[16]; - - qpc_fwht8(t, x); - qpc_fwht8(t + 8, x + 8); - - y[0] = t[0] + t[8]; - y[8] = t[0] - t[8]; - - y[1] = t[1] + t[9]; - y[9] = t[1] - t[9]; - - y[2] = t[2] + t[10]; - y[10] = t[2] - t[10]; - - y[3] = t[3] + t[11]; - y[11] = t[3] - t[11]; - - y[4] = t[4] + t[12]; - y[12] = t[4] - t[12]; - - y[5] = t[5] + t[13]; - y[13] = t[5] - t[13]; - - y[6] = t[6] + t[14]; - y[14] = t[6] - t[14]; - - y[7] = t[7] + t[15]; - y[15] = t[7] - t[15]; - - return y; - -} -float* qpc_fwht32(float* y, float* x) -{ - float t[32]; - - qpc_fwht16(t, x); - qpc_fwht16(t + 16, x + 16); - - _qpc_sumdiff8_16(y, t); - _qpc_sumdiff8_16(y + 8, t + 8); - - return y; -} -float* qpc_fwht64(float* y, float* x) -{ - float t[64]; - - qpc_fwht32(t, x); - qpc_fwht32(t + 32, x + 32); - - _qpc_sumdiff8_32(y, t); - _qpc_sumdiff8_32(y + 8, t + 8); - _qpc_sumdiff8_32(y + 16, t + 16); - _qpc_sumdiff8_32(y + 24, t + 24); - - return y; -} -float* qpc_fwht128(float* y, float* x) -{ - float t[128]; - - qpc_fwht64(t, x); - qpc_fwht64(t + 64, x + 64); - - _qpc_sumdiff8_64(y, t); - _qpc_sumdiff8_64(y + 8, t + 8); - _qpc_sumdiff8_64(y + 16, t + 16); - _qpc_sumdiff8_64(y + 24, t + 24); - _qpc_sumdiff8_64(y + 32, t + 32); - _qpc_sumdiff8_64(y + 40, t + 40); - _qpc_sumdiff8_64(y + 48, t + 48); - _qpc_sumdiff8_64(y + 56, t + 56); - - return y; -} - -// functions over pdfs used by the decoder ----------------------------------------------------------- - - - - +// ------------------------------------------------------------------------------ +// qpc_fwht.c +// Fast Walsh-Hadamard Transforms for q-ary polar codes +// +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// +// This source 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 3 of the License, or +// (at your option) any later version. +// This file is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this source distribution. +// If not, see . + +#include "qpc_fwht.h" + +static void _qpc_sumdiff8_16(float* y, float* t) +{ + y[0] = t[0] + t[16]; + y[16] = t[0] - t[16]; + + y[1] = t[1] + t[17]; + y[17] = t[1] - t[17]; + + y[2] = t[2] + t[18]; + y[18] = t[2] - t[18]; + + y[3] = t[3] + t[19]; + y[19] = t[3] - t[19]; + + y[4] = t[4] + t[20]; + y[20] = t[4] - t[20]; + + y[5] = t[5] + t[21]; + y[21] = t[5] - t[21]; + + y[6] = t[6] + t[22]; + y[22] = t[6] - t[22]; + + y[7] = t[7] + t[23]; + y[23] = t[7] - t[23]; + +} +static void _qpc_sumdiff8_32(float* y, float* t) +{ + y[0] = t[0] + t[32]; + y[32] = t[0] - t[32]; + + y[1] = t[1] + t[33]; + y[33] = t[1] - t[33]; + + y[2] = t[2] + t[34]; + y[34] = t[2] - t[34]; + + y[3] = t[3] + t[35]; + y[35] = t[3] - t[35]; + + y[4] = t[4] + t[36]; + y[36] = t[4] - t[36]; + + y[5] = t[5] + t[37]; + y[37] = t[5] - t[37]; + + y[6] = t[6] + t[38]; + y[38] = t[6] - t[38]; + + y[7] = t[7] + t[39]; + y[39] = t[7] - t[39]; + +} +static void _qpc_sumdiff8_64(float* y, float* t) +{ + y[0] = t[0] + t[64]; + y[64] = t[0] - t[64]; + + y[1] = t[1] + t[65]; + y[65] = t[1] - t[65]; + + y[2] = t[2] + t[66]; + y[66] = t[2] - t[66]; + + y[3] = t[3] + t[67]; + y[67] = t[3] - t[67]; + + y[4] = t[4] + t[68]; + y[68] = t[4] - t[68]; + + y[5] = t[5] + t[69]; + y[69] = t[5] - t[69]; + + y[6] = t[6] + t[70]; + y[70] = t[6] - t[70]; + + y[7] = t[7] + t[71]; + y[71] = t[7] - t[71]; + +} + +float* qpc_fwht8(float* y, float* x) +{ + float t[8]; + + // first stage + y[0] = x[0] + x[1]; + y[1] = x[0] - x[1]; + + y[2] = x[2] + x[3]; + y[3] = x[2] - x[3]; + + y[4] = x[4] + x[5]; + y[5] = x[4] - x[5]; + + y[6] = x[6] + x[7]; + y[7] = x[6] - x[7]; + + // second stage + t[0] = y[0] + y[2]; + t[2] = y[0] - y[2]; + + t[1] = y[1] + y[3]; + t[3] = y[1] - y[3]; + + t[4] = y[4] + y[6]; + t[6] = y[4] - y[6]; + + t[5] = y[5] + y[7]; + t[7] = y[5] - y[7]; + + // third stage + y[0] = t[0] + t[4]; + y[4] = t[0] - t[4]; + + y[1] = t[1] + t[5]; + y[5] = t[1] - t[5]; + + y[2] = t[2] + t[6]; + y[6] = t[2] - t[6]; + + y[3] = t[3] + t[7]; + y[7] = t[3] - t[7]; + + return y; +} +float* qpc_fwht16(float* y, float* x) +{ + float t[16]; + + qpc_fwht8(t, x); + qpc_fwht8(t + 8, x + 8); + + y[0] = t[0] + t[8]; + y[8] = t[0] - t[8]; + + y[1] = t[1] + t[9]; + y[9] = t[1] - t[9]; + + y[2] = t[2] + t[10]; + y[10] = t[2] - t[10]; + + y[3] = t[3] + t[11]; + y[11] = t[3] - t[11]; + + y[4] = t[4] + t[12]; + y[12] = t[4] - t[12]; + + y[5] = t[5] + t[13]; + y[13] = t[5] - t[13]; + + y[6] = t[6] + t[14]; + y[14] = t[6] - t[14]; + + y[7] = t[7] + t[15]; + y[15] = t[7] - t[15]; + + return y; + +} +float* qpc_fwht32(float* y, float* x) +{ + float t[32]; + + qpc_fwht16(t, x); + qpc_fwht16(t + 16, x + 16); + + _qpc_sumdiff8_16(y, t); + _qpc_sumdiff8_16(y + 8, t + 8); + + return y; +} +float* qpc_fwht64(float* y, float* x) +{ + float t[64]; + + qpc_fwht32(t, x); + qpc_fwht32(t + 32, x + 32); + + _qpc_sumdiff8_32(y, t); + _qpc_sumdiff8_32(y + 8, t + 8); + _qpc_sumdiff8_32(y + 16, t + 16); + _qpc_sumdiff8_32(y + 24, t + 24); + + return y; +} +float* qpc_fwht128(float* y, float* x) +{ + float t[128]; + + qpc_fwht64(t, x); + qpc_fwht64(t + 64, x + 64); + + _qpc_sumdiff8_64(y, t); + _qpc_sumdiff8_64(y + 8, t + 8); + _qpc_sumdiff8_64(y + 16, t + 16); + _qpc_sumdiff8_64(y + 24, t + 24); + _qpc_sumdiff8_64(y + 32, t + 32); + _qpc_sumdiff8_64(y + 40, t + 40); + _qpc_sumdiff8_64(y + 48, t + 48); + _qpc_sumdiff8_64(y + 56, t + 56); + + return y; +} + +// functions over pdfs used by the decoder ----------------------------------------------------------- + + + + diff --git a/lib/superfox/qpc/qpc_fwht.h b/lib/superfox/qpc/qpc_fwht.h index 733af7d4..30477a33 100755 --- a/lib/superfox/qpc/qpc_fwht.h +++ b/lib/superfox/qpc/qpc_fwht.h @@ -1,57 +1,57 @@ -// ------------------------------------------------------------------------------ -// qpc_fwht.h -// Fast Walsh-Hadamard Transforms for q-ary polar codes -// -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// -// This source 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 3 of the License, or -// (at your option) any later version. -// This file is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this source distribution. -// If not, see . - -#ifndef _qpc_fwht_h_ -#define _qpc_fwht_h_ - -#include "np_qpc.h" - -#if QPC_LOG2Q==7 -#define qpc_fwht(a,b) qpc_fwht128(a,b) -#endif -#if QPC_LOG2Q==6 -#define qpc_fwht(a,b) qpc_fwht64(a,b) -#endif -#if QPC_LOG2Q==5 -#define qpc_fwht(a,b) qpc_fwht32(a,b) -#endif -#if QPC_LOG2Q==4 -#define qpc_fwht(a,b) qpc_fwht16(a,b) -#endif -// Note that it makes no sense to use fast convolutions -// for transforms that are less than 16 symbols in size. -// For such cases direct convolutions are faster. -#if QPC_LOG2Q==3 -#define qpc_fwht(a,b) qpc_fwht8(a,b) -#endif - -#ifdef __cplusplus -extern "C" { -#endif - float* qpc_fwht8(float* y, float* x); - float* qpc_fwht16(float* y, float* x); - float* qpc_fwht32(float* y, float* x); - float* qpc_fwht64(float* y, float* x); - float* qpc_fwht128(float* y, float* x); -#ifdef __cplusplus -} -#endif - -#endif // _qpc_fwht_h_ +// ------------------------------------------------------------------------------ +// qpc_fwht.h +// Fast Walsh-Hadamard Transforms for q-ary polar codes +// +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// +// This source 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 3 of the License, or +// (at your option) any later version. +// This file is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this source distribution. +// If not, see . + +#ifndef _qpc_fwht_h_ +#define _qpc_fwht_h_ + +#include "np_qpc.h" + +#if QPC_LOG2Q==7 +#define qpc_fwht(a,b) qpc_fwht128(a,b) +#endif +#if QPC_LOG2Q==6 +#define qpc_fwht(a,b) qpc_fwht64(a,b) +#endif +#if QPC_LOG2Q==5 +#define qpc_fwht(a,b) qpc_fwht32(a,b) +#endif +#if QPC_LOG2Q==4 +#define qpc_fwht(a,b) qpc_fwht16(a,b) +#endif +// Note that it makes no sense to use fast convolutions +// for transforms that are less than 16 symbols in size. +// For such cases direct convolutions are faster. +#if QPC_LOG2Q==3 +#define qpc_fwht(a,b) qpc_fwht8(a,b) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + float* qpc_fwht8(float* y, float* x); + float* qpc_fwht16(float* y, float* x); + float* qpc_fwht32(float* y, float* x); + float* qpc_fwht64(float* y, float* x); + float* qpc_fwht128(float* y, float* x); +#ifdef __cplusplus +} +#endif + +#endif // _qpc_fwht_h_ diff --git a/lib/superfox/qpc/qpc_main.cpp b/lib/superfox/qpc/qpc_main.cpp index 4da5ed99..8e6c5955 100755 --- a/lib/superfox/qpc/qpc_main.cpp +++ b/lib/superfox/qpc/qpc_main.cpp @@ -1,198 +1,198 @@ - -// ------------------------------------------------------------------------------ -// qpc_main.cpp -// -// Test the WER performance of the QPC (127,50) Q=128 code -// -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ - -#include -#include -#include - -#include "dbgprintf.h" -#include "qpc_fwht.h" -#include "np_qpc.h" - -// for random numbers generation and NCFSK Rayleigh channel simulation -#include "np_rnd.h" -void qpc_channel(float* yout, unsigned char* y, float EsNo) -{ - // compute channel outputs amplitudes - - int k; - - // generate noise samples ----------------------------------------- - float sigman = 1.0f / sqrtf(2.0f); - np_normrnd_cpx(yout, QPC_N * QPC_Q, 0, sigman); - - // dbgprintf_rows_float("yout", yout, QPC_Q*2, QPC_N); - - // generate rayleigh distributed signal amplitudes ----------------- - float symamps[QPC_N * 2]; - np_normrnd_cpx(symamps, QPC_N, 0, sigman); - - // dbgprintf_vector_float("symamps", symamps, QPC_N*2); - - // normalize signal amps to unity ---------------------------------- - float pwr = 0.0f; - float* psymamps = symamps; - // compute sig power - for (k = 0; k < QPC_N; k++) { - pwr += psymamps[0] * psymamps[0] + psymamps[1] * psymamps[1]; - psymamps += 2; - } - pwr = pwr / QPC_N; - - // normalize to avg EsNo - float norm = sqrtf(EsNo/pwr); - psymamps = symamps; - for (k = 0; k < QPC_N; k++) { - psymamps[0] *= norm; - psymamps[1] *= norm; - psymamps += 2; - } - // dbgprintf_vector_float("symamps norm", symamps, QPC_N * 2); - - // add signal amplitudes to noise ----------------------------------- - float *pyout = yout; - psymamps= symamps; - for (k = 0; k < QPC_N; k++) { - pyout[y[k]<<1] += psymamps[0]; - pyout[(y[k]<<1)+1] += psymamps[1]; - pyout += (QPC_Q*2); - psymamps += 2; - } - - // dbgprintf_rows_float("s+n out", yout, QPC_Q * 2, QPC_N); - - return; -} -void qpc_likelihoods(float* py, float* yout, float EsNo, float No) -{ - // compute symbols likelihoods - // (rayleigh channel) - - int k, j; - - float norm = EsNo / (EsNo + 1) / No; - - // compute likelihoods from energies ---------------------------- - float* pybase; - float* ppyout = yout; - float normpwr; - float normpwrmax; - float pynorm; - - for (k = 0; k < QPC_N; k++) { - - // compute loglikelihoods and largest one from energies - pybase = py + k * QPC_Q; - normpwrmax = 0.0f; - for (j = 0; j < QPC_Q; j++) { - normpwr = norm * (ppyout[0] * ppyout[0] + ppyout[1] * ppyout[1]); - pybase[j] = normpwr; - if (normpwr > normpwrmax) - normpwrmax = normpwr; - ppyout += 2; - } - // subtract largest exponent - pynorm = 0.0f; - for (j = 0; j < QPC_Q; j++) { - pybase[j] = expf(pybase[j] - normpwrmax); - pynorm += pybase[j]; - } - // normalize to probabilities - pynorm = 1.0f / pynorm; - for (j = 0; j < QPC_Q; j++) - pybase[j] = pybase[j] * pynorm; - - } - - return; -} - -int main() -{ - int k; - - int NT = 20000; // number of transmissions to simultate - float EbNodB = 3.7f; // Eb/No to simulate - - - int kc = qpccode.k; - int np = qpccode.np; - float Rc = 1.0f * kc / np; - float Tm = 10.0f; // message duration - float Rb = 1.0f / Tm * (QPC_K - 2) * QPC_LOG2Q; // Bit rate assuming two symbols for CRC - - float EsNodB = EbNodB + 10.0f * log10f(Rc * QPC_LOG2Q); - - static unsigned char xin[QPC_K]; // input information symbols - static unsigned char xdec[QPC_K]; // decoded information symbols - static unsigned char y[QPC_N]; // encoded codeword - static unsigned char ydec[QPC_N]; // decoded codeword - - static float yout[QPC_N * QPC_Q * 2]; // channel complex amplitutes output - static float py[QPC_N * QPC_Q]; // channel output probabilities - - float EsNo = powf(10.0f, EsNodB / 10.0f); - float No = 1.0f; - - //JHT static float we; - static float wer; - - int kk; - - printf("QPC Word Error Rate Test\n"); - printf("Polar Code (%d,%d) Q=%d for the Rayleigh channel\n", qpccode.np, qpccode.k, qpccode.q); - printf("Eb/No = %.1f dB\n", EbNodB); - printf("Es/No = %.1f dB\n", EsNodB); - printf("Tmsg = %.1f s\n", Tm); - printf("Bit Rate = %.1f bit/s\n", Rb); - printf("SNR(2500) = %.1f dB\n\n", EbNodB + 10.0f * log10f(Rb/ 2500)); - - - for (k = 0; k < NT; k++) { - - np_unidrnd_uc(xin, QPC_K, QPC_Q); // generate random information symbols - - qpc_encode(y, xin); // encode - - // compute channel outputs and probabilities - - // Note that if the code is punctured (i.e. N=127) - // the first codeword symbol must not be transmitted over the channel - // Here, in order to avoid useless copies, - // the vector of likelihoods py continues to be a QPC_N*QPC_Q vector of floats. - // The first received symbol likelihoods should start always at offset QPC_Q. - // The first QPC_Q positions of py will be ignored (and set) by the decoder. - qpc_channel(yout, y, EsNo); - - // The decoder can't estimate the EsNo easily - // so we assume that in any case it is 5 dB - float EsNoDec = 3.16; - qpc_likelihoods(py, yout, EsNoDec, No); - - qpc_decode(xdec, ydec, py); // decode - - // count words in errors - for (kk = 0; kk < QPC_K; kk++) - if (xin[kk] ^ xdec[kk]) { - wer += 1; - break; - } - - // show the decoder performance every 200 codewords transmissions - if ((k % 200) == 0 && k>0) { - printf("k=%6d/%6d wer = %8.2E\n", k, NT, wer / k); - fflush(stdout); - } - - } - // show the final result - printf("k=%6d/%6d wer = %8.2E\n", k, NT, wer / k); - printf("\nAll done.\n"); - return 0; -} + +// ------------------------------------------------------------------------------ +// qpc_main.cpp +// +// Test the WER performance of the QPC (127,50) Q=128 code +// +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ + +#include +#include +#include + +#include "dbgprintf.h" +#include "qpc_fwht.h" +#include "np_qpc.h" + +// for random numbers generation and NCFSK Rayleigh channel simulation +#include "np_rnd.h" +void qpc_channel(float* yout, unsigned char* y, float EsNo) +{ + // compute channel outputs amplitudes + + int k; + + // generate noise samples ----------------------------------------- + float sigman = 1.0f / sqrtf(2.0f); + np_normrnd_cpx(yout, QPC_N * QPC_Q, 0, sigman); + + // dbgprintf_rows_float("yout", yout, QPC_Q*2, QPC_N); + + // generate rayleigh distributed signal amplitudes ----------------- + float symamps[QPC_N * 2]; + np_normrnd_cpx(symamps, QPC_N, 0, sigman); + + // dbgprintf_vector_float("symamps", symamps, QPC_N*2); + + // normalize signal amps to unity ---------------------------------- + float pwr = 0.0f; + float* psymamps = symamps; + // compute sig power + for (k = 0; k < QPC_N; k++) { + pwr += psymamps[0] * psymamps[0] + psymamps[1] * psymamps[1]; + psymamps += 2; + } + pwr = pwr / QPC_N; + + // normalize to avg EsNo + float norm = sqrtf(EsNo/pwr); + psymamps = symamps; + for (k = 0; k < QPC_N; k++) { + psymamps[0] *= norm; + psymamps[1] *= norm; + psymamps += 2; + } + // dbgprintf_vector_float("symamps norm", symamps, QPC_N * 2); + + // add signal amplitudes to noise ----------------------------------- + float *pyout = yout; + psymamps= symamps; + for (k = 0; k < QPC_N; k++) { + pyout[y[k]<<1] += psymamps[0]; + pyout[(y[k]<<1)+1] += psymamps[1]; + pyout += (QPC_Q*2); + psymamps += 2; + } + + // dbgprintf_rows_float("s+n out", yout, QPC_Q * 2, QPC_N); + + return; +} +void qpc_likelihoods(float* py, float* yout, float EsNo, float No) +{ + // compute symbols likelihoods + // (rayleigh channel) + + int k, j; + + float norm = EsNo / (EsNo + 1) / No; + + // compute likelihoods from energies ---------------------------- + float* pybase; + float* ppyout = yout; + float normpwr; + float normpwrmax; + float pynorm; + + for (k = 0; k < QPC_N; k++) { + + // compute loglikelihoods and largest one from energies + pybase = py + k * QPC_Q; + normpwrmax = 0.0f; + for (j = 0; j < QPC_Q; j++) { + normpwr = norm * (ppyout[0] * ppyout[0] + ppyout[1] * ppyout[1]); + pybase[j] = normpwr; + if (normpwr > normpwrmax) + normpwrmax = normpwr; + ppyout += 2; + } + // subtract largest exponent + pynorm = 0.0f; + for (j = 0; j < QPC_Q; j++) { + pybase[j] = expf(pybase[j] - normpwrmax); + pynorm += pybase[j]; + } + // normalize to probabilities + pynorm = 1.0f / pynorm; + for (j = 0; j < QPC_Q; j++) + pybase[j] = pybase[j] * pynorm; + + } + + return; +} + +int main() +{ + int k; + + int NT = 20000; // number of transmissions to simultate + float EbNodB = 3.7f; // Eb/No to simulate + + + int kc = qpccode.k; + int np = qpccode.np; + float Rc = 1.0f * kc / np; + float Tm = 10.0f; // message duration + float Rb = 1.0f / Tm * (QPC_K - 2) * QPC_LOG2Q; // Bit rate assuming two symbols for CRC + + float EsNodB = EbNodB + 10.0f * log10f(Rc * QPC_LOG2Q); + + static unsigned char xin[QPC_K]; // input information symbols + static unsigned char xdec[QPC_K]; // decoded information symbols + static unsigned char y[QPC_N]; // encoded codeword + static unsigned char ydec[QPC_N]; // decoded codeword + + static float yout[QPC_N * QPC_Q * 2]; // channel complex amplitutes output + static float py[QPC_N * QPC_Q]; // channel output probabilities + + float EsNo = powf(10.0f, EsNodB / 10.0f); + float No = 1.0f; + + //JHT static float we; + static float wer; + + int kk; + + printf("QPC Word Error Rate Test\n"); + printf("Polar Code (%d,%d) Q=%d for the Rayleigh channel\n", qpccode.np, qpccode.k, qpccode.q); + printf("Eb/No = %.1f dB\n", EbNodB); + printf("Es/No = %.1f dB\n", EsNodB); + printf("Tmsg = %.1f s\n", Tm); + printf("Bit Rate = %.1f bit/s\n", Rb); + printf("SNR(2500) = %.1f dB\n\n", EbNodB + 10.0f * log10f(Rb/ 2500)); + + + for (k = 0; k < NT; k++) { + + np_unidrnd_uc(xin, QPC_K, QPC_Q); // generate random information symbols + + qpc_encode(y, xin); // encode + + // compute channel outputs and probabilities + + // Note that if the code is punctured (i.e. N=127) + // the first codeword symbol must not be transmitted over the channel + // Here, in order to avoid useless copies, + // the vector of likelihoods py continues to be a QPC_N*QPC_Q vector of floats. + // The first received symbol likelihoods should start always at offset QPC_Q. + // The first QPC_Q positions of py will be ignored (and set) by the decoder. + qpc_channel(yout, y, EsNo); + + // The decoder can't estimate the EsNo easily + // so we assume that in any case it is 5 dB + float EsNoDec = 3.16; + qpc_likelihoods(py, yout, EsNoDec, No); + + qpc_decode(xdec, ydec, py); // decode + + // count words in errors + for (kk = 0; kk < QPC_K; kk++) + if (xin[kk] ^ xdec[kk]) { + wer += 1; + break; + } + + // show the decoder performance every 200 codewords transmissions + if ((k % 200) == 0 && k>0) { + printf("k=%6d/%6d wer = %8.2E\n", k, NT, wer / k); + fflush(stdout); + } + + } + // show the final result + printf("k=%6d/%6d wer = %8.2E\n", k, NT, wer / k); + printf("\nAll done.\n"); + return 0; +} diff --git a/lib/superfox/qpc/qpc_mod.f90 b/lib/superfox/qpc/qpc_mod.f90 index 069c77b1..931e5b3d 100755 --- a/lib/superfox/qpc/qpc_mod.f90 +++ b/lib/superfox/qpc/qpc_mod.f90 @@ -1,38 +1,38 @@ -module qpc_mod - interface - integer(c_int32_t) function nhash2 (xin, length, initval) bind(C, & - name="nhash2") - use iso_c_binding, only: c_signed_char, c_int64_t, c_int32_t - integer(c_int64_t), intent(in), value :: length - integer(c_signed_char), intent(in) :: xin(length) - integer(c_int32_t), intent(in), value :: initval - end function nhash2 - end interface - - interface - subroutine qpc_encode(y, xin) bind(C,name="qpc_encode") - use iso_c_binding, only: c_ptr, c_signed_char - integer(c_signed_char), intent(out) :: y(127) - integer(c_signed_char), intent(in) :: xin(50) - end subroutine qpc_encode - end interface - - interface - subroutine qpc_channel(yout, y, EsNo) bind(C,name="qpc_channel") - use iso_c_binding, only: c_float_complex, c_float, c_signed_char - complex(c_float_complex), intent(out) :: yout(128,128) - integer(c_signed_char), intent(out) :: y(127) - real(c_float), intent(in), value :: EsNo - end subroutine qpc_channel - end interface - - interface - subroutine qpc_decode(xdec, ydec, py) bind(C,name="qpc_decode") - use iso_c_binding, only: c_float, c_signed_char - real(c_float), intent(in) :: py(128,128) - integer(c_signed_char), intent(out) :: ydec(127) - integer(c_signed_char), intent(out) :: xdec(50) - end subroutine qpc_decode - end interface - -end module qpc_mod +module qpc_mod + interface + integer(c_int32_t) function nhash2 (xin, length, initval) bind(C, & + name="nhash2") + use iso_c_binding, only: c_signed_char, c_int64_t, c_int32_t + integer(c_int64_t), intent(in), value :: length + integer(c_signed_char), intent(in) :: xin(length) + integer(c_int32_t), intent(in), value :: initval + end function nhash2 + end interface + + interface + subroutine qpc_encode(y, xin) bind(C,name="qpc_encode") + use iso_c_binding, only: c_ptr, c_signed_char + integer(c_signed_char), intent(out) :: y(127) + integer(c_signed_char), intent(in) :: xin(50) + end subroutine qpc_encode + end interface + + interface + subroutine qpc_channel(yout, y, EsNo) bind(C,name="qpc_channel") + use iso_c_binding, only: c_float_complex, c_float, c_signed_char + complex(c_float_complex), intent(out) :: yout(128,128) + integer(c_signed_char), intent(out) :: y(127) + real(c_float), intent(in), value :: EsNo + end subroutine qpc_channel + end interface + + interface + subroutine qpc_decode(xdec, ydec, py) bind(C,name="qpc_decode") + use iso_c_binding, only: c_float, c_signed_char + real(c_float), intent(in) :: py(128,128) + integer(c_signed_char), intent(out) :: ydec(127) + integer(c_signed_char), intent(out) :: xdec(50) + end subroutine qpc_decode + end interface + +end module qpc_mod diff --git a/lib/superfox/qpc/qpc_n127k50q128.c b/lib/superfox/qpc/qpc_n127k50q128.c index c57bcd2b..3897cc83 100755 --- a/lib/superfox/qpc/qpc_n127k50q128.c +++ b/lib/superfox/qpc/qpc_n127k50q128.c @@ -1,60 +1,60 @@ -// ------------------------------------------------------------------------------ -// qpc_n127k50q128.c -// -// Defines the parameters of the q-ary polar code (127,50) Q=128 -// for WSJT-X -// ------------------------------------------------------------------------------ -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ -// -// WARNING: -// This source is NOT free software and it is licensed only for use with WSJT-X. -// No derived work is authorized to use this code without the written -// permission of his author (Nico Palermo / IV3NWV) who owns all the rights -// of this IP (intellectual property). -// -// This file is distributed ONLY for the purpose of documenting and making of -// public domain the encoding scheme used in WSJT-X so that the transmitted -// messages can be decoded by anybody. -// Anyway this does not imply that one could use the following tables in a -// derived work without an explicit and written authorization from his author. -// Any unauthorized use, as for any intellectual property, is simply -// illegal. -// ------------------------------------------------------------------------------- -#include "np_qpc.h" -qpccode_ds qpccode = { - 128, //n - 127, //np - 50, //k - 128, //q -{ - 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 16, 32, 17, 18, 64, 20, - 33, 34, 24, 7, 11, 36, 13, 19, 14, 65, 40, 21, 66, 22, 35, 68, - 25, 48, 37, 26, 72, 15, 38, 28, 41, 67, 23, 80, 42, 69, 49, 96, - 44, 27, 70, 50, 73, 39, 29, 52, 74, 30, 56, 81, 76, 43, 82, 84, - 97, 45, 71, 88, 98, 46, 100, 51, 104, 53, 75, 112, 54, 57, 99, 119, - 92, 77, 58, 117, 59, 83, 106, 31, 85, 108, 115, 116, 122, 125, 124, 91, - 61, 90, 89, 111, 78, 93, 94, 126, 86, 107, 110, 118, 121, 62, 120, 87, -105, 55, 114, 60, 127, 63, 103, 101, 123, 95, 102, 47, 109, 79, 113, 0 -}, -{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}, -{ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, - 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -} -}; +// ------------------------------------------------------------------------------ +// qpc_n127k50q128.c +// +// Defines the parameters of the q-ary polar code (127,50) Q=128 +// for WSJT-X +// ------------------------------------------------------------------------------ +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// +// WARNING: +// This source is NOT free software and it is licensed only for use with WSJT-X. +// No derived work is authorized to use this code without the written +// permission of his author (Nico Palermo / IV3NWV) who owns all the rights +// of this IP (intellectual property). +// +// This file is distributed ONLY for the purpose of documenting and making of +// public domain the encoding scheme used in WSJT-X so that the transmitted +// messages can be decoded by anybody. +// Anyway this does not imply that one could use the following tables in a +// derived work without an explicit and written authorization from his author. +// Any unauthorized use, as for any intellectual property, is simply +// illegal. +// ------------------------------------------------------------------------------- +#include "np_qpc.h" +qpccode_ds qpccode = { + 128, //n + 127, //np + 50, //k + 128, //q +{ + 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 16, 32, 17, 18, 64, 20, + 33, 34, 24, 7, 11, 36, 13, 19, 14, 65, 40, 21, 66, 22, 35, 68, + 25, 48, 37, 26, 72, 15, 38, 28, 41, 67, 23, 80, 42, 69, 49, 96, + 44, 27, 70, 50, 73, 39, 29, 52, 74, 30, 56, 81, 76, 43, 82, 84, + 97, 45, 71, 88, 98, 46, 100, 51, 104, 53, 75, 112, 54, 57, 99, 119, + 92, 77, 58, 117, 59, 83, 106, 31, 85, 108, 115, 116, 122, 125, 124, 91, + 61, 90, 89, 111, 78, 93, 94, 126, 86, 107, 110, 118, 121, 62, 120, 87, +105, 55, 114, 60, 127, 63, 103, 101, 123, 95, 102, 47, 109, 79, 113, 0 +}, +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}, +{ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +} +}; diff --git a/lib/superfox/qpc/qpc_subs.c b/lib/superfox/qpc/qpc_subs.c index cc6625e8..ec5f8e44 100755 --- a/lib/superfox/qpc/qpc_subs.c +++ b/lib/superfox/qpc/qpc_subs.c @@ -1,115 +1,115 @@ -// ------------------------------------------------------------------------------ -// qpc_test.cpp -// -// Test the WER performance of the QPC (127,50) Q=128 code -// -// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy -// ------------------------------------------------------------------------------ - -#include -#include -#include -#include - -#include "dbgprintf.h" -#include "qpc_fwht.h" -#include "np_qpc.h" - -#include "nhash2.h" - -// for random numbers generation and NCFSK Rayleigh channel simulation -#include "np_rnd.h" -void qpc_channel(float* yout, unsigned char* y, float EsNo) -{ - // compute channel outputs amplitudes - - int k; - - // generate noise samples ----------------------------------------- - float sigman = 1.0f / sqrtf(2.0f); - np_normrnd_cpx(yout, QPC_N * QPC_Q, 0, sigman); - - // dbgprintf_rows_float("yout", yout, QPC_Q*2, QPC_N); - - // generate rayleigh distributed signal amplitudes ----------------- - float symamps[QPC_N * 2]; - np_normrnd_cpx(symamps, QPC_N, 0, sigman); - - // dbgprintf_vector_float("symamps", symamps, QPC_N*2); - - // normalize signal amps to unity ---------------------------------- - float pwr = 0.0f; - float* psymamps = symamps; - // compute sig power - for (k = 0; k < QPC_N; k++) { - pwr += psymamps[0] * psymamps[0] + psymamps[1] * psymamps[1]; - psymamps += 2; - } - pwr = pwr / QPC_N; - - // normalize to avg EsNo - float norm = sqrtf(EsNo/pwr); - psymamps = symamps; - for (k = 0; k < QPC_N; k++) { - psymamps[0] *= norm; - psymamps[1] *= norm; - psymamps += 2; - } - // dbgprintf_vector_float("symamps norm", symamps, QPC_N * 2); - - // add signal amplitudes to noise ----------------------------------- - float *pyout = yout; - psymamps= symamps; - for (k = 0; k < QPC_N; k++) { - pyout[y[k]<<1] += psymamps[0]; - pyout[(y[k]<<1)+1] += psymamps[1]; - pyout += (QPC_Q*2); - psymamps += 2; - } - - // dbgprintf_rows_float("s+n out", yout, QPC_Q * 2, QPC_N); - - return; -} -void qpc_likelihoods(float* py, float* yout, float EsNo, float No) -{ - // compute symbols likelihoods - // (rayleigh channel) - - int k, j; - - float norm = EsNo / (EsNo + 1) / No; - - // compute likelihoods from energies ---------------------------- - float* pybase; - float* ppyout = yout; - float normpwr; - float normpwrmax; - float pynorm; - - for (k = 0; k < QPC_N; k++) { - - // compute loglikelihoods and largest one from energies - pybase = py + k * QPC_Q; - normpwrmax = 0.0f; - for (j = 0; j < QPC_Q; j++) { - normpwr = norm * (ppyout[0] * ppyout[0] + ppyout[1] * ppyout[1]); - pybase[j] = normpwr; - if (normpwr > normpwrmax) - normpwrmax = normpwr; - ppyout += 2; - } - // subtract largest exponent - pynorm = 0.0f; - for (j = 0; j < QPC_Q; j++) { - pybase[j] = expf(pybase[j] - normpwrmax); - pynorm += pybase[j]; - } - // normalize to probabilities - pynorm = 1.0f / pynorm; - for (j = 0; j < QPC_Q; j++) - pybase[j] = pybase[j] * pynorm; - } - - return; -} +// ------------------------------------------------------------------------------ +// qpc_test.cpp +// +// Test the WER performance of the QPC (127,50) Q=128 code +// +// (c) 2024 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ + +#include +#include +#include +#include + +#include "dbgprintf.h" +#include "qpc_fwht.h" +#include "np_qpc.h" + +#include "nhash2.h" + +// for random numbers generation and NCFSK Rayleigh channel simulation +#include "np_rnd.h" +void qpc_channel(float* yout, unsigned char* y, float EsNo) +{ + // compute channel outputs amplitudes + + int k; + + // generate noise samples ----------------------------------------- + float sigman = 1.0f / sqrtf(2.0f); + np_normrnd_cpx(yout, QPC_N * QPC_Q, 0, sigman); + + // dbgprintf_rows_float("yout", yout, QPC_Q*2, QPC_N); + + // generate rayleigh distributed signal amplitudes ----------------- + float symamps[QPC_N * 2]; + np_normrnd_cpx(symamps, QPC_N, 0, sigman); + + // dbgprintf_vector_float("symamps", symamps, QPC_N*2); + + // normalize signal amps to unity ---------------------------------- + float pwr = 0.0f; + float* psymamps = symamps; + // compute sig power + for (k = 0; k < QPC_N; k++) { + pwr += psymamps[0] * psymamps[0] + psymamps[1] * psymamps[1]; + psymamps += 2; + } + pwr = pwr / QPC_N; + + // normalize to avg EsNo + float norm = sqrtf(EsNo/pwr); + psymamps = symamps; + for (k = 0; k < QPC_N; k++) { + psymamps[0] *= norm; + psymamps[1] *= norm; + psymamps += 2; + } + // dbgprintf_vector_float("symamps norm", symamps, QPC_N * 2); + + // add signal amplitudes to noise ----------------------------------- + float *pyout = yout; + psymamps= symamps; + for (k = 0; k < QPC_N; k++) { + pyout[y[k]<<1] += psymamps[0]; + pyout[(y[k]<<1)+1] += psymamps[1]; + pyout += (QPC_Q*2); + psymamps += 2; + } + + // dbgprintf_rows_float("s+n out", yout, QPC_Q * 2, QPC_N); + + return; +} +void qpc_likelihoods(float* py, float* yout, float EsNo, float No) +{ + // compute symbols likelihoods + // (rayleigh channel) + + int k, j; + + float norm = EsNo / (EsNo + 1) / No; + + // compute likelihoods from energies ---------------------------- + float* pybase; + float* ppyout = yout; + float normpwr; + float normpwrmax; + float pynorm; + + for (k = 0; k < QPC_N; k++) { + + // compute loglikelihoods and largest one from energies + pybase = py + k * QPC_Q; + normpwrmax = 0.0f; + for (j = 0; j < QPC_Q; j++) { + normpwr = norm * (ppyout[0] * ppyout[0] + ppyout[1] * ppyout[1]); + pybase[j] = normpwr; + if (normpwr > normpwrmax) + normpwrmax = normpwr; + ppyout += 2; + } + // subtract largest exponent + pynorm = 0.0f; + for (j = 0; j < QPC_Q; j++) { + pybase[j] = expf(pybase[j] - normpwrmax); + pynorm += pybase[j]; + } + // normalize to probabilities + pynorm = 1.0f / pynorm; + for (j = 0; j < QPC_Q; j++) + pybase[j] = pybase[j] * pynorm; + } + + return; +} diff --git a/lib/superfox/qpc_decode2.f90 b/lib/superfox/qpc_decode2.f90 index a795ff6e..57152ab8 100755 --- a/lib/superfox/qpc_decode2.f90 +++ b/lib/superfox/qpc_decode2.f90 @@ -1,150 +1,150 @@ -subroutine qpc_decode2(c0,fsync,ftol,xdec,ndepth,dth,damp,crc_ok, & - snrsync,fbest,tbest,snr) - - use qpc_mod - - parameter(NMAX=15*12000,NFT=365,NZ=100) - complex c0(NMAX) !Signal as received - complex c(NMAX) !Signal as received - real py(0:127,0:127) !Probabilities for received synbol values - real py0(0:127,0:127) !Probabilities for strong signal - real pyd(0:127,0:127) !Dithered values for py - real s2(0:127,0:151) !Symbol spectra, including sync - real s3(0:127,0:127) !Synchronized symbol spectra - real No - integer crc_chk,crc_sent - integer*8 n47 - integer idf(NZ),idt(NZ) - integer nseed(33) - integer*1 xdec(0:49) !Decoded message - integer*1 ydec(0:127) !Decoded symbols - logical crc_ok - integer maxdither(8) - integer isync(24) !Symbol numbers for sync tones - data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80,83, & - 84,86,89/ - data n47/47/,maxdither/20,50,100,200,500,1000,2000,5000/ - data nseed/ & - 321278106, -658879006, 1239150429, -941466001, -698554454, & - 1136210962, 1633585627, 1261915021, -1134191465, -487888229, & - 2131958895, -1429290834, -1802468092, 1801346659, 1966248904, & - 402671397, -1961400750, -1567227835, 1895670987, -286583128, & - -595933665, -1699285543, 1518291336, 1338407128, 838354404, & - -2081343776, -1449416716, 1236537391, -133197638, 337355509, & - -460640480, 1592689606, 0/ - - data idf/0, 0, -1, 0, -1, 1, 0, -1, 1, -2, 0, -1, 1, -2, 2, & - 0, -1, 1, -2, 2, -3, 0, -1, 1, -2, 2, -3, 3, 0, -1, & - 1, -2, 2, -3, 3, -4, 0, -1, 1, -2, 2, -3, 3, -4, 4, & - 0, -1, 1, -2, 2, -3, 3, -4, 4, -5, -1, 1, -2, 2, -3, & - 3, -4, 4, -5, 1, -2, 2, -3, 3, -4, 4, -5, -2, 2, -3, & - 3, -4, 4, -5, 2, -3, 3, -4, 4, -5, -3, 3, -4, 4, -5, & - 3, -4, 4, -5, -4, 4, -5, 4, -5, -5/ - data idt/0 , -1, 0, 1, -1, 0, -2, 1, -1, 0, 2, -2, 1, -1, 0, & - -3, 2, -2, 1, -1, 0, 3, -3, 2, -2, 1, -1, 0, -4, 3, & - -3, 2, -2, 1, -1, 0, 4, -4, 3, -3, 2, -2, 1, -1, 0, & - -5, 4, -4, 3, -3, 2, -2, 1, -1, 0, -5, 4, -4, 3, -3, & - 2, -2, 1, -1, -5, 4, -4, 3, -3, 2, -2, 1, -5, 4, -4, & - 3, -3, 2, -2, -5, 4, -4, 3, -3, 2, -5, 4, -4, 3, -3, & - -5, 4, -4, 3, -5, 4, -4, -5, 4, -5/ - - - fsample=12000.0 - baud=12000.0/1024.0 - nstype=1 - n47=47 - mask21=2**21 - 1 - crc_ok=.false. - - call qpc_sync(c0,fsample,isync,fsync,ftol,f2,t2,snrsync) - f00=1500.0 + f2 - t00=t2 - fbest=f00 - tbest=t00 - maxd=1 - if(ndepth.gt.0) maxd=maxdither(ndepth) - maxft=NZ - if(snrsync.lt.4.0 .or. ndepth.le.0) maxft=1 - do idith=1,maxft - if(idith.ge.2) maxd=1 - deltaf=idf(idith)*0.5 - deltat=idt(idith)*8.0/1024.0 - f=f00+deltaf - t=t00+deltat - fshift=1500.0 - (f+baud) !Shift frequencies down by f + 1 bin - call twkfreq2(c0,c,NMAX,fsample,fshift) - a=1.0 - b=0.0 - do kk=1,4 - if(kk.eq.2) b=0.4 - if(kk.eq.3) b=0.5 - if(kk.eq.4) b=0.6 - call sfox_demod(c,1500.0,t,isync,s2,s3) !Compute s2 and s3 - - if(b.gt.0.0) then - do j=0,127 - call smo121a(s3(:,j),128,a,b) - enddo - endif - call pctile(s3,128*128,50,base3) - s3=s3/base3 - - EsNoDec=3.16 - No=1. - py0=s3 - call qpc_likelihoods2(py,s3,EsNoDec,No) !For weak signals - - call random_seed(put=nseed) - do kkk=1,maxd - if(kkk.eq.1) then - pyd=py0 - else - pyd=0. - if(kkk.gt.2) then - call random_number(pyd) - pyd=2.0*(pyd-0.5) - endif - where(py.gt.dth) pyd=0. !Don't perturb large likelihoods - pyd=py*(1.0 + damp*pyd) !Compute dithered likelihood - endif - do j=0,127 - ss=sum(pyd(:,j)) - if(ss.gt.0.0) then - pyd(:,j)=pyd(:,j)/ss - else - pyd(:,j)=0.0 - endif - enddo - - call qpc_decode(xdec,ydec,pyd) - xdec=xdec(49:0:-1) - crc_chk=iand(nhash2(xdec,n47,571),mask21) !Compute crc_chk - crc_sent=128*128*xdec(47) + 128*xdec(48) + xdec(49) - crc_ok=crc_chk.eq.crc_sent - - if(crc_ok) then - call qpc_snr(s3,ydec,snr) - if(snr.lt.-16.5) crc_ok=.false. -! write(61,3061) idith,kk,kkk,idf(idith),idt(idith),a,b -!3061 format(5i5,2f8.3) - return - endif - enddo !kk: dither of smoothing weights - enddo !kkk: dither of probabilities - enddo !idith: dither of frequency and time - return -end subroutine qpc_decode2 - -subroutine smo121a(x,nz,a,b) - - real x(nz) - fac=1.0/(a+2*b) - x0=x(1) - do i=2,nz-1 - x1=x(i) - x(i)=fac*(a*x(i) + b*(x0+x(i+1))) - x0=x1 - enddo - - return -end subroutine smo121a +subroutine qpc_decode2(c0,fsync,ftol,xdec,ndepth,dth,damp,crc_ok, & + snrsync,fbest,tbest,snr) + + use qpc_mod + + parameter(NMAX=15*12000,NFT=365,NZ=100) + complex c0(NMAX) !Signal as received + complex c(NMAX) !Signal as received + real py(0:127,0:127) !Probabilities for received synbol values + real py0(0:127,0:127) !Probabilities for strong signal + real pyd(0:127,0:127) !Dithered values for py + real s2(0:127,0:151) !Symbol spectra, including sync + real s3(0:127,0:127) !Synchronized symbol spectra + real No + integer crc_chk,crc_sent + integer*8 n47 + integer idf(NZ),idt(NZ) + integer nseed(33) + integer*1 xdec(0:49) !Decoded message + integer*1 ydec(0:127) !Decoded symbols + logical crc_ok + integer maxdither(8) + integer isync(24) !Symbol numbers for sync tones + data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80,83, & + 84,86,89/ + data n47/47/,maxdither/20,50,100,200,500,1000,2000,5000/ + data nseed/ & + 321278106, -658879006, 1239150429, -941466001, -698554454, & + 1136210962, 1633585627, 1261915021, -1134191465, -487888229, & + 2131958895, -1429290834, -1802468092, 1801346659, 1966248904, & + 402671397, -1961400750, -1567227835, 1895670987, -286583128, & + -595933665, -1699285543, 1518291336, 1338407128, 838354404, & + -2081343776, -1449416716, 1236537391, -133197638, 337355509, & + -460640480, 1592689606, 0/ + + data idf/0, 0, -1, 0, -1, 1, 0, -1, 1, -2, 0, -1, 1, -2, 2, & + 0, -1, 1, -2, 2, -3, 0, -1, 1, -2, 2, -3, 3, 0, -1, & + 1, -2, 2, -3, 3, -4, 0, -1, 1, -2, 2, -3, 3, -4, 4, & + 0, -1, 1, -2, 2, -3, 3, -4, 4, -5, -1, 1, -2, 2, -3, & + 3, -4, 4, -5, 1, -2, 2, -3, 3, -4, 4, -5, -2, 2, -3, & + 3, -4, 4, -5, 2, -3, 3, -4, 4, -5, -3, 3, -4, 4, -5, & + 3, -4, 4, -5, -4, 4, -5, 4, -5, -5/ + data idt/0 , -1, 0, 1, -1, 0, -2, 1, -1, 0, 2, -2, 1, -1, 0, & + -3, 2, -2, 1, -1, 0, 3, -3, 2, -2, 1, -1, 0, -4, 3, & + -3, 2, -2, 1, -1, 0, 4, -4, 3, -3, 2, -2, 1, -1, 0, & + -5, 4, -4, 3, -3, 2, -2, 1, -1, 0, -5, 4, -4, 3, -3, & + 2, -2, 1, -1, -5, 4, -4, 3, -3, 2, -2, 1, -5, 4, -4, & + 3, -3, 2, -2, -5, 4, -4, 3, -3, 2, -5, 4, -4, 3, -3, & + -5, 4, -4, 3, -5, 4, -4, -5, 4, -5/ + + + fsample=12000.0 + baud=12000.0/1024.0 + nstype=1 + n47=47 + mask21=2**21 - 1 + crc_ok=.false. + + call qpc_sync(c0,fsample,isync,fsync,ftol,f2,t2,snrsync) + f00=1500.0 + f2 + t00=t2 + fbest=f00 + tbest=t00 + maxd=1 + if(ndepth.gt.0) maxd=maxdither(ndepth) + maxft=NZ + if(snrsync.lt.4.0 .or. ndepth.le.0) maxft=1 + do idith=1,maxft + if(idith.ge.2) maxd=1 + deltaf=idf(idith)*0.5 + deltat=idt(idith)*8.0/1024.0 + f=f00+deltaf + t=t00+deltat + fshift=1500.0 - (f+baud) !Shift frequencies down by f + 1 bin + call twkfreq2(c0,c,NMAX,fsample,fshift) + a=1.0 + b=0.0 + do kk=1,4 + if(kk.eq.2) b=0.4 + if(kk.eq.3) b=0.5 + if(kk.eq.4) b=0.6 + call sfox_demod(c,1500.0,t,isync,s2,s3) !Compute s2 and s3 + + if(b.gt.0.0) then + do j=0,127 + call smo121a(s3(:,j),128,a,b) + enddo + endif + call pctile(s3,128*128,50,base3) + s3=s3/base3 + + EsNoDec=3.16 + No=1. + py0=s3 + call qpc_likelihoods2(py,s3,EsNoDec,No) !For weak signals + + call random_seed(put=nseed) + do kkk=1,maxd + if(kkk.eq.1) then + pyd=py0 + else + pyd=0. + if(kkk.gt.2) then + call random_number(pyd) + pyd=2.0*(pyd-0.5) + endif + where(py.gt.dth) pyd=0. !Don't perturb large likelihoods + pyd=py*(1.0 + damp*pyd) !Compute dithered likelihood + endif + do j=0,127 + ss=sum(pyd(:,j)) + if(ss.gt.0.0) then + pyd(:,j)=pyd(:,j)/ss + else + pyd(:,j)=0.0 + endif + enddo + + call qpc_decode(xdec,ydec,pyd) + xdec=xdec(49:0:-1) + crc_chk=iand(nhash2(xdec,n47,571),mask21) !Compute crc_chk + crc_sent=128*128*xdec(47) + 128*xdec(48) + xdec(49) + crc_ok=crc_chk.eq.crc_sent + + if(crc_ok) then + call qpc_snr(s3,ydec,snr) + if(snr.lt.-16.5) crc_ok=.false. +! write(61,3061) idith,kk,kkk,idf(idith),idt(idith),a,b +!3061 format(5i5,2f8.3) + return + endif + enddo !kk: dither of smoothing weights + enddo !kkk: dither of probabilities + enddo !idith: dither of frequency and time + return +end subroutine qpc_decode2 + +subroutine smo121a(x,nz,a,b) + + real x(nz) + fac=1.0/(a+2*b) + x0=x(1) + do i=2,nz-1 + x1=x(i) + x(i)=fac*(a*x(i) + b*(x0+x(i+1))) + x0=x1 + enddo + + return +end subroutine smo121a diff --git a/lib/superfox/qpc_likelihoods2.f90 b/lib/superfox/qpc_likelihoods2.f90 index e1393594..70a63181 100755 --- a/lib/superfox/qpc_likelihoods2.f90 +++ b/lib/superfox/qpc_likelihoods2.f90 @@ -1,28 +1,28 @@ -subroutine qpc_likelihoods2(py,s3,EsNo,No) - - integer QQ,QN - parameter(QQ=128,QN=128) - real py(0:QQ-1,0:QN-1) - real s3(0:QQ-1,0:QN-1) - real No,norm,normpwr,normpwrmax - - norm=(EsNo/(EsNo+1.0))/No - -! Compute likelihoods for symbol values, from the symbol power spectra - do k=0,QN-1 - normpwrmax=0. - do j=0,QQ-1 - normpwr=norm*s3(j,k) - py(j,k)=normpwr - normpwrmax=max(normpwr,normpwrmax) - enddo - pynorm=0. - do j=0,QQ-1 - py(j,k)=exp(py(j,k)-normpwrmax) - pynorm=pynorm + py(j,k) - enddo - py(0:QQ-1,k)=py(0:QQ-1,k)/pynorm !Normalize to probabilities - enddo - - return -end subroutine qpc_likelihoods2 +subroutine qpc_likelihoods2(py,s3,EsNo,No) + + integer QQ,QN + parameter(QQ=128,QN=128) + real py(0:QQ-1,0:QN-1) + real s3(0:QQ-1,0:QN-1) + real No,norm,normpwr,normpwrmax + + norm=(EsNo/(EsNo+1.0))/No + +! Compute likelihoods for symbol values, from the symbol power spectra + do k=0,QN-1 + normpwrmax=0. + do j=0,QQ-1 + normpwr=norm*s3(j,k) + py(j,k)=normpwr + normpwrmax=max(normpwr,normpwrmax) + enddo + pynorm=0. + do j=0,QQ-1 + py(j,k)=exp(py(j,k)-normpwrmax) + pynorm=pynorm + py(j,k) + enddo + py(0:QQ-1,k)=py(0:QQ-1,k)/pynorm !Normalize to probabilities + enddo + + return +end subroutine qpc_likelihoods2 diff --git a/lib/superfox/qpc_snr.f90 b/lib/superfox/qpc_snr.f90 index 457d2504..b2c807f0 100755 --- a/lib/superfox/qpc_snr.f90 +++ b/lib/superfox/qpc_snr.f90 @@ -1,17 +1,17 @@ -subroutine qpc_snr(s3,y,snr) - - use qpc_mod -! real s2(0:NQ-1,0:151) !Symbol spectra, including sync - real s3(0:127,0:127) !Synchronized symbol spectra - integer*1 y(0:127) !Encoded symbols -! integer isync(24) - - p=0. - do j=1,127 - i=y(j) - p=p + s3(i,j) - enddo - snr=db(p/127.0) - db(127.0) - 4.0 - - return -end subroutine qpc_snr +subroutine qpc_snr(s3,y,snr) + + use qpc_mod +! real s2(0:NQ-1,0:151) !Symbol spectra, including sync + real s3(0:127,0:127) !Synchronized symbol spectra + integer*1 y(0:127) !Encoded symbols +! integer isync(24) + + p=0. + do j=1,127 + i=y(j) + p=p + s3(i,j) + enddo + snr=db(p/127.0) - db(127.0) - 4.0 + + return +end subroutine qpc_snr diff --git a/lib/superfox/qpc_sync.f90 b/lib/superfox/qpc_sync.f90 index 9b1af13c..ea9afb5b 100755 --- a/lib/superfox/qpc_sync.f90 +++ b/lib/superfox/qpc_sync.f90 @@ -1,101 +1,113 @@ -subroutine qpc_sync(crcvd0,fsample,isync,fsync,ftol,f2,t2,snrsync) - - parameter(N9SEC=9*12000,NMAX=15*12000,NDOWN=16,NZ=N9SEC/NDOWN) - complex crcvd0(NMAX) !Signal as received - complex c0(0:N9SEC-1) !For long FFT - complex c1(0:NZ-1) - complex c1sum(0:NZ-1) - complex z - real s(N9SEC/4) - real p(-1125:1125) - integer ipk(1) - integer isync(24) - - baud=12000.0/1024.0 - df2=fsample/N9SEC - fac=1.0/N9SEC - c0=fac*crcvd0(1:N9SEC) - call four2a(c0,N9SEC,1,-1,1) !Forward c2c FFT - iz=N9SEC/4 - do i=1,iz - s(i)=real(c0(i))**2 + aimag(c0(i))**2 - enddo - - do i=1,4 !Smooth the spectrum a bit - call smo121(s,iz) - enddo - - ia=nint((fsync-ftol)/df2) - ib=nint((fsync+ftol)/df2) - ipk=maxloc(s(ia:ib)) - i0=ipk(1) + ia - 1 - f2=df2*i0-750.0 ! f2 is the offset from nominal 750 Hz. - ia=nint(i0-baud/df2) - ib=nint(i0+baud/df2) - s1=0.0 - s0=0.0 - do i=ia,ib - s0=s0+s(i) - s1=s1+(i-i0)*s(i) - enddo - delta=s1/s0 - i0=nint(i0+delta) - f2=i0*df2-750.0 - - c1=0. - ia=nint(i0-baud/df2) - ib=nint(i0+baud/df2) - do i=ia,ib - j=i-i0 - if(j.ge.0) c1(j)=c0(i) - if(j.lt.0) c1(j+NZ)=c0(i) - enddo - call four2a(c1,NZ,1,1,1) !Reverse c2c FFT: back to time domain - - c1sum(0)=c1(0) - do i=1,NZ-1 - c1sum(i)=c1sum(i-1) + c1(i) - enddo - - nspsd=1024/NDOWN - dt=NDOWN/12000.0 - lagmax=1.5/dt - i0=nint(0.5*fsample/NDOWN) !Nominal start time is 0.5 s - pmax=0. - lagpk=0 - do lag=-lagmax,lagmax - sp=0. - do j=1,24 - i1=i0 + (isync(j)-1)*nspsd + lag - i2=i1 + nspsd - if(i1.lt.0 .or. i1.gt.NZ-1) cycle - if(i2.lt.0 .or. i2.gt.NZ-1) cycle - z=c1sum(i2)-c1sum(i1) - sp=sp + real(z)**2 + aimag(z)**2 - enddo - if(sp.gt.pmax) then - pmax=sp - lagpk=lag - endif - p(lag)=sp - enddo - - t2=lagpk*dt - snrsync=0. - sp=0. - sq=0. - nsum=0 - tsym=1024/12000.0 - do lag=-lagmax,lagmax - t=(lag-lagpk)*dt - if(abs(t).lt.tsym) cycle - nsum=nsum+1 - sp=sp + p(lag) - sq=sq + p(lag)*p(lag) - enddo - ave=sp/nsum - rms=sqrt(sq/nsum-ave*ave) - snrsync=(pmax-ave)/rms - - return -end subroutine qpc_sync +subroutine qpc_sync(crcvd0,fsample,isync,fsync,ftol,f2,t2,snrsync) + + parameter(N9SEC=9*12000,NMAX=15*12000,NDOWN=16,NZ=N9SEC/NDOWN) + complex crcvd0(NMAX) !Signal as received + complex c0(0:N9SEC-1) !For long FFT + complex c1(0:NZ-1) + complex c1sum(0:NZ-1) + complex z + real s(N9SEC/4) + real p(-1125:1125) + integer ipk(1) + integer isync(24) + + baud=12000.0/1024.0 + df2=fsample/N9SEC + fac=1.0/N9SEC + c0=fac*crcvd0(1:N9SEC) + call four2a(c0,N9SEC,1,-1,1) !Forward c2c FFT + iz=N9SEC/4 + do i=1,iz + s(i)=real(c0(i))**2 + aimag(c0(i))**2 + enddo + + do i=1,4 !Smooth the spectrum a bit + call smo121(s,iz) + enddo + + ia=nint((fsync-ftol)/df2) + ib=nint((fsync+ftol)/df2) + + if (ia .lt. 1) ia=1; ! Avoid a potential bounds error + if (ib .ge. 27000) ib=27000; ! Avoid a potential bounds error + + ipk=maxloc(s(ia:ib)) + i0=ipk(1) + ia - 1 + f2=df2*i0-750.0 ! f2 is the offset from nominal 750 Hz. + ia=nint(i0-baud/df2) + ib=nint(i0+baud/df2) + + if (ia .lt. 1) ia=1; ! Avoid a potential bounds error + if (ib .ge. 27000) ib=27000; ! Avoid a potential bounds error + + s1=0.0 + s0=0.0 + do i=ia,ib + s0=s0+s(i) + s1=s1+(i-i0)*s(i) + enddo + delta=s1/s0 + i0=nint(i0+delta) + f2=i0*df2-750.0 + + c1=0. + ia=nint(i0-baud/df2) + ib=nint(i0+baud/df2) + + if (ia .lt. 0) ia=0; ! Avoid a potential bounds error + if (ib .ge. N9SEC-1) ib=N9SEC-1; ! Avoid a potential bounds error + + do i=ia,ib + j=i-i0 + if(j.ge.0) c1(j)=c0(i) + if(j.lt.0) c1(j+NZ)=c0(i) + enddo + call four2a(c1,NZ,1,1,1) !Reverse c2c FFT: back to time domain + + c1sum(0)=c1(0) + do i=1,NZ-1 + c1sum(i)=c1sum(i-1) + c1(i) + enddo + + nspsd=1024/NDOWN + dt=NDOWN/12000.0 + lagmax=1.5/dt + i0=nint(0.5*fsample/NDOWN) !Nominal start time is 0.5 s + pmax=0. + lagpk=0 + do lag=-lagmax,lagmax + sp=0. + do j=1,24 + i1=i0 + (isync(j)-1)*nspsd + lag + i2=i1 + nspsd + if(i1.lt.0 .or. i1.gt.NZ-1) cycle + if(i2.lt.0 .or. i2.gt.NZ-1) cycle + z=c1sum(i2)-c1sum(i1) + sp=sp + real(z)**2 + aimag(z)**2 + enddo + if(sp.gt.pmax) then + pmax=sp + lagpk=lag + endif + p(lag)=sp + enddo + + t2=lagpk*dt + snrsync=0. + sp=0. + sq=0. + nsum=0 + tsym=1024/12000.0 + do lag=-lagmax,lagmax + t=(lag-lagpk)*dt + if(abs(t).lt.tsym) cycle + nsum=nsum+1 + sp=sp + p(lag) + sq=sq + p(lag)*p(lag) + enddo + ave=sp/nsum + rms=sqrt(sq/nsum-ave*ave) + snrsync=(pmax-ave)/rms + + return +end subroutine qpc_sync diff --git a/lib/superfox/ran1.f90 b/lib/superfox/ran1.f90 index d0b35b74..b09b9bab 100755 --- a/lib/superfox/ran1.f90 +++ b/lib/superfox/ran1.f90 @@ -1,28 +1,28 @@ -FUNCTION ran1(idum) - INTEGER idum,IA,IM,IQ,IR,NTAB,NDIV - REAL ran1,AM,EPS,RNMX - PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836, & - NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS) - INTEGER j,k,iv(NTAB),iy - SAVE iv,iy - DATA iv /NTAB*0/, iy /0/ - if (idum.le.0.or.iy.eq.0) then - idum=max(-idum,1) - do j=NTAB+8,1,-1 - k=idum/IQ - idum=IA*(idum-k*IQ)-IR*k - if (idum.lt.0) idum=idum+IM - if (j.le.NTAB) iv(j)=idum - enddo - iy=iv(1) - endif - k=idum/IQ - idum=IA*(idum-k*IQ)-IR*k - if (idum.lt.0) idum=idum+IM - j=1+iy/NDIV - iy=iv(j) - iv(j)=idum - ran1=min(AM*iy,RNMX) - - return -END FUNCTION ran1 +FUNCTION ran1(idum) + INTEGER idum,IA,IM,IQ,IR,NTAB,NDIV + REAL ran1,AM,EPS,RNMX + PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836, & + NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS) + INTEGER j,k,iv(NTAB),iy + SAVE iv,iy + DATA iv /NTAB*0/, iy /0/ + if (idum.le.0.or.iy.eq.0) then + idum=max(-idum,1) + do j=NTAB+8,1,-1 + k=idum/IQ + idum=IA*(idum-k*IQ)-IR*k + if (idum.lt.0) idum=idum+IM + if (j.le.NTAB) iv(j)=idum + enddo + iy=iv(1) + endif + k=idum/IQ + idum=IA*(idum-k*IQ)-IR*k + if (idum.lt.0) idum=idum+IM + j=1+iy/NDIV + iy=iv(j) + iv(j)=idum + ran1=min(AM*iy,RNMX) + + return +END FUNCTION ran1 diff --git a/lib/superfox/sfox_ana.f90 b/lib/superfox/sfox_ana.f90 index 5983d31b..bc9ea6cf 100755 --- a/lib/superfox/sfox_ana.f90 +++ b/lib/superfox/sfox_ana.f90 @@ -1,17 +1,17 @@ -subroutine sfox_ana(dd,npts,c0,npts2) - - real dd(npts) !Raw data at 12000 Hz - complex c0(0:npts2-1) !Complex data at 12000 Hz - save - - nfft1=npts - nfft2=nfft1 - fac=2.0/(32767.0*nfft1) - c0(0:npts-1)=fac*dd(1:npts) - call four2a(c0,nfft1,1,-1,1) !Forward c2c FFT - c0(nfft2/2+1:nfft2-1)=0. !Remove negative frequencies - c0(0)=0.5*c0(0) !Scale the DC term to 1/2 - call four2a(c0,nfft2,1,1,1) !Inverse c2c FFT; c0 is analytic sig - - return -end subroutine sfox_ana +subroutine sfox_ana(dd,npts,c0,npts2) + + real dd(npts) !Raw data at 12000 Hz + complex c0(0:npts2-1) !Complex data at 12000 Hz + save + + nfft1=npts + nfft2=nfft1 + fac=2.0/(32767.0*nfft1) + c0(0:npts-1)=fac*dd(1:npts) + call four2a(c0,nfft1,1,-1,1) !Forward c2c FFT + c0(nfft2/2+1:nfft2-1)=0. !Remove negative frequencies + c0(0)=0.5*c0(0) !Scale the DC term to 1/2 + call four2a(c0,nfft2,1,1,1) !Inverse c2c FFT; c0 is analytic sig + + return +end subroutine sfox_ana diff --git a/lib/superfox/sfox_assemble.f90 b/lib/superfox/sfox_assemble.f90 index cf1810d7..1ea1834f 100755 --- a/lib/superfox/sfox_assemble.f90 +++ b/lib/superfox/sfox_assemble.f90 @@ -1,92 +1,92 @@ -subroutine sfox_assemble(ntype,k,msg,mycall0,mygrid0,line) - -! In subsequent calls, assemble all necessary information for a SuperFox -! transmission. - - character*120 line - character*26 msg - character*26 msg0,msg1,msg2(5),msg3(5) - character*4 rpt2(5) - character*6 hiscall(10) - character*13 mycall0,mycall - character*4 mygrid0,mygrid - integer ntype !Message type: 0 Free Text - ! 1 CQ MyCall MyGrid - ! 2 Call_1 MyCall RR73 - ! 3 Call_1 MyCall rpt - integer nmsg(0:3) !Number of messages of type ntype - data nmsg/0,0,0,0/,nbits/0/,ntx/0/,nb_mycall/0/ - save - - if(mycall0(1:1).ne.' ') mycall=mycall0 - if(mygrid0(1:1).ne.' ') mygrid=mygrid0 - if(ntype.ge.1) nb_mycall=28 !### Allow for nonstandard MyCall ### - if(sum(nmsg).eq.0) then - hiscall=' ' - rpt2=' ' - endif - - if(k.le.10) then - if(ntype.eq.0) then - if(nbits+nb_mycall.le.191) then !Enough room for a free text message? - nmsg(ntype)=nmsg(ntype)+1 - nbits=nbits+142 - msg0=msg - endif - else if(ntype.eq.1) then - if(nbits+nb_mycall.le.318) then !Enough room for a CQ ? - nmsg(ntype)=nmsg(ntype)+1 - nbits=nbits+15 - msg1=msg - endif - else if(ntype.eq.2) then - if(nbits+nb_mycall.le.305) then !Enough room for a RR73 message? - nmsg(ntype)=nmsg(ntype)+1 - nbits=nbits+28 - j=nmsg(ntype) - msg2(j)=msg - i1=index(msg,' ') - hiscall(j+5)=msg(1:i1-1) - endif - else if(ntype.eq.3) then - if(nbits+nb_mycall.le.300) then !Enough room for a message with report? - nmsg(ntype)=nmsg(ntype)+1 - nbits=nbits+33 - j=nmsg(ntype) - msg3(j)=msg - i1=index(msg,' ') - hiscall(j)=msg(1:i1-1) - i1=max(index(msg,'-'),index(msg,'+')) - rpt2(j)=msg(i1:i1+3) - endif - endif - return - endif - - if(k.ge.11) then -! All pieces are now available. Put them into a command line for external -! program sfox_tx. - ntx=ntx+1 !Transmission number - nbits=nbits+nb_mycall !Add bits for MyCall - - if(nmsg(1).ge.1) then - line=msg1 - else - line=trim(mycall) - do i=1,nmsg(3) - line=trim(line)//' '//trim(hiscall(i))//' '//rpt2(i) - enddo - do i=1,nmsg(2) - line=trim(line)//' '//trim(hiscall(i+5)) - enddo - endif - - nmsg=0 - nbits=0 - nb_mycall=0 - hiscall=' ' - rpt2=' ' - endif - - return -end subroutine sfox_assemble +subroutine sfox_assemble(ntype,k,msg,mycall0,mygrid0,line) + +! In subsequent calls, assemble all necessary information for a SuperFox +! transmission. + + character*120 line + character*26 msg + character*26 msg0,msg1,msg2(5),msg3(5) + character*4 rpt2(5) + character*6 hiscall(10) + character*13 mycall0,mycall + character*4 mygrid0,mygrid + integer ntype !Message type: 0 Free Text + ! 1 CQ MyCall MyGrid + ! 2 Call_1 MyCall RR73 + ! 3 Call_1 MyCall rpt + integer nmsg(0:3) !Number of messages of type ntype + data nmsg/0,0,0,0/,nbits/0/,ntx/0/,nb_mycall/0/ + save + + if(mycall0(1:1).ne.' ') mycall=mycall0 + if(mygrid0(1:1).ne.' ') mygrid=mygrid0 + if(ntype.ge.1) nb_mycall=28 !### Allow for nonstandard MyCall ### + if(sum(nmsg).eq.0) then + hiscall=' ' + rpt2=' ' + endif + + if(k.le.10) then + if(ntype.eq.0) then + if(nbits+nb_mycall.le.191) then !Enough room for a free text message? + nmsg(ntype)=nmsg(ntype)+1 + nbits=nbits+142 + msg0=msg + endif + else if(ntype.eq.1) then + if(nbits+nb_mycall.le.318) then !Enough room for a CQ ? + nmsg(ntype)=nmsg(ntype)+1 + nbits=nbits+15 + msg1=msg + endif + else if(ntype.eq.2) then + if(nbits+nb_mycall.le.305) then !Enough room for a RR73 message? + nmsg(ntype)=nmsg(ntype)+1 + nbits=nbits+28 + j=nmsg(ntype) + msg2(j)=msg + i1=index(msg,' ') + hiscall(j+5)=msg(1:i1-1) + endif + else if(ntype.eq.3) then + if(nbits+nb_mycall.le.300) then !Enough room for a message with report? + nmsg(ntype)=nmsg(ntype)+1 + nbits=nbits+33 + j=nmsg(ntype) + msg3(j)=msg + i1=index(msg,' ') + hiscall(j)=msg(1:i1-1) + i1=max(index(msg,'-'),index(msg,'+')) + rpt2(j)=msg(i1:i1+3) + endif + endif + return + endif + + if(k.ge.11) then +! All pieces are now available. Put them into a command line for external +! program sfox_tx. + ntx=ntx+1 !Transmission number + nbits=nbits+nb_mycall !Add bits for MyCall + + if(nmsg(1).ge.1) then + line=msg1 + else + line=trim(mycall) + do i=1,nmsg(3) + line=trim(line)//' '//trim(hiscall(i))//' '//rpt2(i) + enddo + do i=1,nmsg(2) + line=trim(line)//' '//trim(hiscall(i+5)) + enddo + endif + + nmsg=0 + nbits=0 + nb_mycall=0 + hiscall=' ' + rpt2=' ' + endif + + return +end subroutine sfox_assemble diff --git a/lib/superfox/sfox_demod.f90 b/lib/superfox/sfox_demod.f90 index 568d6786..cbb11df7 100755 --- a/lib/superfox/sfox_demod.f90 +++ b/lib/superfox/sfox_demod.f90 @@ -1,79 +1,79 @@ -subroutine sfox_demod(crcvd,f,t,isync,s2,s3) - - use sfox_mod - complex crcvd(NMAX) !Signal as received - complex c(0:NSPS-1) !Work array, one symbol long - real s2(0:NQ-1,0:151) !Symbol spectra, including sync - real s3(0:NQ-1,0:NN) !Synchronized symbol spectra - integer isync(24) - integer ipk(1) - integer hist1(0:NQ-1),hist2(0:NQ-1) - - j0=nint(12000.0*(t+0.5)) - df=12000.0/NSPS - i0=nint(f/df)-NQ/2 - k2=0 - s2(:,0)=0. !The punctured symbol - s3(:,0)=0. !The punctured symbol - - do n=1,NDS !Loop over all symbols - jb=n*NSPS + j0 - ja=jb-NSPS+1 - k2=k2+1 - if(ja.lt.1 .or. jb.gt.NMAX) cycle - c=crcvd(ja:jb) - call four2a(c,NSPS,1,-1,1) !Compute symbol spectrum - do i=0,NQ-1 - s2(i,k2)=real(c(i0+i))**2 + aimag(c(i0+i))**2 - enddo - enddo - - - call pctile(s2,NQ*151,50,base2) - s2=s2/base2 - - hist1=0 - hist2=0 - do j=0,151 - ipk=maxloc(s2(1:NQ-1,j)) !Find the spectral peak - i=ipk(1)-1 - hist1(i)=hist1(i)+1 - enddo - - hist1(0)=0 !Don't treat sync tone as a birdie - do i=0,123 - hist2(i)=sum(hist1(i:i+3)) - enddo - - ipk=maxloc(hist1) - i1=ipk(1)-1 - m1=maxval(hist1) - ipk=maxloc(hist2) - i2=ipk(1)-1 - m2=maxval(hist2) - if(m1.gt.12) then - do i=0,127 - if(hist1(i).gt.12) then - s2(i,:)=1.0 - endif - enddo - endif - - if(m2.gt.20) then - if(i2.ge.1) i2=i2-1 - if(i2.gt.120) i2=120 - s2(i2:i2+7,:)=1.0 - endif - - k3=0 - do n=1,NDS !Copy symbol spectra from s2 into s3 - if(any(isync(1:NS).eq.n)) cycle !Skip the sync symbols - k3=k3+1 - s3(:,k3)=s2(:,n) - enddo - - call pctile(s3,NQ*NN,50,base3) - s3=s3/base3 - - return -end subroutine sfox_demod +subroutine sfox_demod(crcvd,f,t,isync,s2,s3) + + use sfox_mod + complex crcvd(NMAX) !Signal as received + complex c(0:NSPS-1) !Work array, one symbol long + real s2(0:NQ-1,0:151) !Symbol spectra, including sync + real s3(0:NQ-1,0:NN) !Synchronized symbol spectra + integer isync(24) + integer ipk(1) + integer hist1(0:NQ-1),hist2(0:NQ-1) + + j0=nint(12000.0*(t+0.5)) + df=12000.0/NSPS + i0=nint(f/df)-NQ/2 + k2=0 + s2(:,0)=0. !The punctured symbol + s3(:,0)=0. !The punctured symbol + + do n=1,NDS !Loop over all symbols + jb=n*NSPS + j0 + ja=jb-NSPS+1 + k2=k2+1 + if(ja.lt.1 .or. jb.gt.NMAX) cycle + c=crcvd(ja:jb) + call four2a(c,NSPS,1,-1,1) !Compute symbol spectrum + do i=0,NQ-1 + s2(i,k2)=real(c(i0+i))**2 + aimag(c(i0+i))**2 + enddo + enddo + + + call pctile(s2,NQ*151,50,base2) + s2=s2/base2 + + hist1=0 + hist2=0 + do j=0,151 + ipk=maxloc(s2(1:NQ-1,j)) !Find the spectral peak + i=ipk(1)-1 + hist1(i)=hist1(i)+1 + enddo + + hist1(0)=0 !Don't treat sync tone as a birdie + do i=0,123 + hist2(i)=sum(hist1(i:i+3)) + enddo + + ipk=maxloc(hist1) + i1=ipk(1)-1 + m1=maxval(hist1) + ipk=maxloc(hist2) + i2=ipk(1)-1 + m2=maxval(hist2) + if(m1.gt.12) then + do i=0,127 + if(hist1(i).gt.12) then + s2(i,:)=1.0 + endif + enddo + endif + + if(m2.gt.20) then + if(i2.ge.1) i2=i2-1 + if(i2.gt.120) i2=120 + s2(i2:i2+7,:)=1.0 + endif + + k3=0 + do n=1,NDS !Copy symbol spectra from s2 into s3 + if(any(isync(1:NS).eq.n)) cycle !Skip the sync symbols + k3=k3+1 + s3(:,k3)=s2(:,n) + enddo + + call pctile(s3,NQ*NN,50,base3) + s3=s3/base3 + + return +end subroutine sfox_demod diff --git a/lib/superfox/sfox_gen_gfsk.f90 b/lib/superfox/sfox_gen_gfsk.f90 index d9087bf6..df01defe 100755 --- a/lib/superfox/sfox_gen_gfsk.f90 +++ b/lib/superfox/sfox_gen_gfsk.f90 @@ -1,86 +1,86 @@ -subroutine sfox_gen_gfsk(idat,f0,isync,itone,cdat) - - parameter (NSPS=1024) - parameter (NDS=151) - parameter (NN=127) !NN = number of code symbols - parameter (NS=24) !NS = number of sync symbols - parameter (NMAX=15*12000) - parameter (NPTS=(NDS+2)*NSPS) !# of samples in waveform at 12000 samples/sec - parameter (BT=8) !GFSK time-bandwidth product - - complex cdat(NMAX) - complex w, wstep - integer idat(NN) - integer isync(NS) - integer itone(NDS) - real*8 dt,twopi,phi,dphi_peak - real*8 dphi(0:NPTS-1) - real pulse(3*NSPS) - logical first/.true./ - - save first,twopi,dt,hmod,dphi_peak,pulse - - if(first) then - twopi=8.d0*atan(1.0) - fsample=12000.0 - dt=1.0/fsample - hmod=1.0 - dphi_peak=twopi*hmod/real(NSPS) - do i=1,3*NSPS - tt=(i-1.5*NSPS)/real(NSPS) - pulse(i)=gfsk_pulse(BT,tt) - enddo - first=.false. - endif - wave=0. - -! Create the itone sequence: data symbols and interspersed sync symbols - j=1 - k=0 - do i=1,NDS - if(j.le.NS .and. i.eq.isync(j)) then - if(j.lt.NS) j=j+1 !Index for next sync symbol - itone(i)=0 !Insert sync symbol at tone 0 - else - k=k+1 - itone(i)=idat(k) + 1 !Symbol value 0 is transmitted at tone 1, etc. - endif - enddo - -! Generate the SuperFox waveform. - - dphi=0.d0 - do j=1,NDS - ib=(j-1)*NSPS - ie=ib+3*NSPS-1 - dphi(ib:ie)=dphi(ib:ie)+dphi_peak*pulse(1:3*NSPS)*itone(j) - enddo - dphi(0:2*NSPS-1)=dphi(0:2*NSPS-1)+dphi_peak*itone(1)*pulse(NSPS+1:3*NSPS) - dphi(NDS*NSPS:(NDS+2)*NSPS-1)=dphi(NDS*NSPS:(NDS+2)*NSPS-1)+dphi_peak*itone(NDS)*pulse(1:2*NSPS) - - phi=0.d0 - dphi=dphi+twopi*f0*dt - k=0 - do j=1,NSPS*(NDS+2)-1 - k=k+1 - cdat(k)=cmplx(cos(phi),sin(phi)) - phi=phi+dphi(j) - enddo - -! Add raised cosine ramps at the beginning and end of the waveform. -! Since the modulator expects an integral number of symbols, dummy -! symbols are added to the beginning and end of the waveform to -! hold the ramps. All but nramp of the samples in each dummy -! symbol will be zero. - - nramp=NSPS/BT - cdat(1:NSPS-nramp)=cmplx(0.0,0.0) - cdat(NSPS-nramp+1:NSPS)=cdat(NSPS-nramp+1:NSPS) * & - (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - k1=(NDS+1)*NSPS+1 - cdat(k1:k1+nramp-1)=cdat(k1:k1+nramp-1) * & - (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - cdat(k1+nramp:NPTS)=0.0 - - return -end subroutine sfox_gen_gfsk +subroutine sfox_gen_gfsk(idat,f0,isync,itone,cdat) + + parameter (NSPS=1024) + parameter (NDS=151) + parameter (NN=127) !NN = number of code symbols + parameter (NS=24) !NS = number of sync symbols + parameter (NMAX=15*12000) + parameter (NPTS=(NDS+2)*NSPS) !# of samples in waveform at 12000 samples/sec + parameter (BT=8) !GFSK time-bandwidth product + + complex cdat(NMAX) + complex w, wstep + integer idat(NN) + integer isync(NS) + integer itone(NDS) + real*8 dt,twopi,phi,dphi_peak + real*8 dphi(0:NPTS-1) + real pulse(3*NSPS) + logical first/.true./ + + save first,twopi,dt,hmod,dphi_peak,pulse + + if(first) then + twopi=8.d0*atan(1.0) + fsample=12000.0 + dt=1.0/fsample + hmod=1.0 + dphi_peak=twopi*hmod/real(NSPS) + do i=1,3*NSPS + tt=(i-1.5*NSPS)/real(NSPS) + pulse(i)=gfsk_pulse(BT,tt) + enddo + first=.false. + endif + wave=0. + +! Create the itone sequence: data symbols and interspersed sync symbols + j=1 + k=0 + do i=1,NDS + if(j.le.NS .and. i.eq.isync(j)) then + if(j.lt.NS) j=j+1 !Index for next sync symbol + itone(i)=0 !Insert sync symbol at tone 0 + else + k=k+1 + itone(i)=idat(k) + 1 !Symbol value 0 is transmitted at tone 1, etc. + endif + enddo + +! Generate the SuperFox waveform. + + dphi=0.d0 + do j=1,NDS + ib=(j-1)*NSPS + ie=ib+3*NSPS-1 + dphi(ib:ie)=dphi(ib:ie)+dphi_peak*pulse(1:3*NSPS)*itone(j) + enddo + dphi(0:2*NSPS-1)=dphi(0:2*NSPS-1)+dphi_peak*itone(1)*pulse(NSPS+1:3*NSPS) + dphi(NDS*NSPS:(NDS+2)*NSPS-1)=dphi(NDS*NSPS:(NDS+2)*NSPS-1)+dphi_peak*itone(NDS)*pulse(1:2*NSPS) + + phi=0.d0 + dphi=dphi+twopi*f0*dt + k=0 + do j=1,NSPS*(NDS+2)-1 + k=k+1 + cdat(k)=cmplx(cos(phi),sin(phi)) + phi=phi+dphi(j) + enddo + +! Add raised cosine ramps at the beginning and end of the waveform. +! Since the modulator expects an integral number of symbols, dummy +! symbols are added to the beginning and end of the waveform to +! hold the ramps. All but nramp of the samples in each dummy +! symbol will be zero. + + nramp=NSPS/BT + cdat(1:NSPS-nramp)=cmplx(0.0,0.0) + cdat(NSPS-nramp+1:NSPS)=cdat(NSPS-nramp+1:NSPS) * & + (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + k1=(NDS+1)*NSPS+1 + cdat(k1:k1+nramp-1)=cdat(k1:k1+nramp-1) * & + (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + cdat(k1+nramp:NPTS)=0.0 + + return +end subroutine sfox_gen_gfsk diff --git a/lib/superfox/sfox_mod.f90 b/lib/superfox/sfox_mod.f90 index 6c4d8390..01fc06f2 100755 --- a/lib/superfox/sfox_mod.f90 +++ b/lib/superfox/sfox_mod.f90 @@ -1,73 +1,73 @@ -module sfox_mod - - parameter (NMAX=15*12000) !Samples in iwave (180,000) - integer MM,NQ,NN,KK,NS,NDS,NFZ,NSPS,NSYNC,NZ,NFFT1 - real baud,tsym,bw - -contains - subroutine sfox_init(mm0,nn0,kk0,itu,fspread,delay,fsample,ns0) - - character*2 itu - integer isps(54) - integer iloc(1) - data isps/ 896, 960, 972, 980,1000,1008,1024,1029,1050,1080, & - 1120,1125,1134,1152,1176,1200,1215,1225,1250,1260, & - 1280,1296,1323,1344,1350,1372,1400,1440,1458,1470, & - 1500,1512,1536,1568,1575,1600,1620,1680,1701,1715, & - 1728,1750,1764,1792,1800,1875,1890,1920,1944,1960, & - 2000,2016,2025,2048/ - - MM=mm0 !Bits per symbol - NQ=2**MM !Q, number of MFSK tones - NN=nn0 !Codeword length - KK=kk0 !Number of information symbols - NS=ns0 !Number of sync symbols - NDS=NN+NS !Total number of channel symbols - NFZ=3 !First zero - - jsps=nint(12.8*fsample/NDS) - iloc=minloc(abs(isps-jsps)) - NSPS=isps(iloc(1)) !Samples per symbol - NSYNC=NS*NSPS !Samples in sync waveform - NZ=NSPS*NDS !Samples in full Tx waveform - NFFT1=2*NSPS !Length of FFTs for symbol spectra - - baud=fsample/NSPS - tsym=1.0/baud - bw=NQ*baud - - fspread=0.0 - delay=0.0 - if(itu.eq.'LQ') then - fspread=0.5 - delay=0.5 - else if(itu.eq.'LM') then - fspread=1.5 - delay=2.0 - else if(itu.eq.'LD') then - fspread=10.0 - delay=6.0 - else if(itu.eq.'MQ') then - fspread=0.1 - delay=0.5 - else if(itu.eq.'MM') then - fspread=0.5 - delay=1.0 - else if(itu.eq.'MD') then - fspread=1.0 - delay=2.0 - else if(itu.eq.'HQ') then - fspread=0.5 - delay=1.0 - else if(itu.eq.'HM') then - fspread=10.0 - delay=3.0 - else if(itu.eq.'HD') then - fspread=30.0 - delay=7.0 - endif - - return - end subroutine sfox_init - -end module sfox_mod +module sfox_mod + + parameter (NMAX=15*12000) !Samples in iwave (180,000) + integer MM,NQ,NN,KK,NS,NDS,NFZ,NSPS,NSYNC,NZ,NFFT1 + real baud,tsym,bw + +contains + subroutine sfox_init(mm0,nn0,kk0,itu,fspread,delay,fsample,ns0) + + character*2 itu + integer isps(54) + integer iloc(1) + data isps/ 896, 960, 972, 980,1000,1008,1024,1029,1050,1080, & + 1120,1125,1134,1152,1176,1200,1215,1225,1250,1260, & + 1280,1296,1323,1344,1350,1372,1400,1440,1458,1470, & + 1500,1512,1536,1568,1575,1600,1620,1680,1701,1715, & + 1728,1750,1764,1792,1800,1875,1890,1920,1944,1960, & + 2000,2016,2025,2048/ + + MM=mm0 !Bits per symbol + NQ=2**MM !Q, number of MFSK tones + NN=nn0 !Codeword length + KK=kk0 !Number of information symbols + NS=ns0 !Number of sync symbols + NDS=NN+NS !Total number of channel symbols + NFZ=3 !First zero + + jsps=nint(12.8*fsample/NDS) + iloc=minloc(abs(isps-jsps)) + NSPS=isps(iloc(1)) !Samples per symbol + NSYNC=NS*NSPS !Samples in sync waveform + NZ=NSPS*NDS !Samples in full Tx waveform + NFFT1=2*NSPS !Length of FFTs for symbol spectra + + baud=fsample/NSPS + tsym=1.0/baud + bw=NQ*baud + + fspread=0.0 + delay=0.0 + if(itu.eq.'LQ') then + fspread=0.5 + delay=0.5 + else if(itu.eq.'LM') then + fspread=1.5 + delay=2.0 + else if(itu.eq.'LD') then + fspread=10.0 + delay=6.0 + else if(itu.eq.'MQ') then + fspread=0.1 + delay=0.5 + else if(itu.eq.'MM') then + fspread=0.5 + delay=1.0 + else if(itu.eq.'MD') then + fspread=1.0 + delay=2.0 + else if(itu.eq.'HQ') then + fspread=0.5 + delay=1.0 + else if(itu.eq.'HM') then + fspread=10.0 + delay=3.0 + else if(itu.eq.'HD') then + fspread=30.0 + delay=7.0 + endif + + return + end subroutine sfox_init + +end module sfox_mod diff --git a/lib/superfox/sfox_pack.f90 b/lib/superfox/sfox_pack.f90 index 56ccf89a..c5a6d94c 100755 --- a/lib/superfox/sfox_pack.f90 +++ b/lib/superfox/sfox_pack.f90 @@ -1,178 +1,178 @@ -subroutine sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) - - use qpc_mod - use packjt - use packjt77 - use julian - parameter (NQU1RKS=203514677) - integer*8 n47,n58,now - integer*1 xin(0:49) !Packed message as 7-bit symbols - logical*1 bMoreCQs,bSendMsg - logical text,allz - character*120 line !SuperFox message pieces - character*10 ckey - character*26 freeTextMsg - character*13 w(16) - character*11 c11 - character*329 msgbits !Packed message as bits - character*38 c - data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ - - i0=index(line,'/') - i3=0 !Default to i3=0, standard message - nh1=0 !Number of Hound calls with RR73 - nh2=0 !Number of Hound calls with report - -! Split the command line into words - w=' ' - i1=1 - do j=1,16 - do i=i1,min(i1+12,120) - if(line(i:i).eq.' ') exit - enddo - i2=i-1 - w(j)=line(i1:i2) - do i=i2+1,120 - if(line(i:i).ne.' ') exit - enddo - i1=i - if(i1.ge.120) exit - enddo - nwords=j - - do i=1,nwords - if(w(i)(1:1).eq.' ') then - nwords=i-1 - exit - endif - enddo - - do i=1,329 !Set all msgbits to '0' - msgbits(i:i)='0' - enddo - - now=itime8()/30 - now=30*now - read(ckey(5:10),*) notp - - write(msgbits(307:326),'(b20.20)') notp !Insert the digital signature - - if(w(1)(1:3).eq.'CQ ') then - i3=3 - c11=w(2)(1:11) - n58=0 - do i=1,11 - n58=n58*38 + index(c,c11(i:i)) - 1 - enddo - write(msgbits(1:58),'(b58.58)') n58 - call packgrid(w(3)(1:4),n15,text) - write(msgbits(59:73),'(b15.15)') n15 - write(msgbits(327:329),'(b3.3)') i3 !Message type i3=3 - go to 800 - endif - - call pack28(w(1),n28) !Fox call - write(msgbits(1:28),'(b28.28)') n28 - -! Default report is RR73 if we're also sending a free text message. - if(bSendMsg) msgbits(141:160)='11111111111111111111' - - j=29 - -! Process callsigns with RR73 - do i=2,nwords - if(w(i)(1:1).eq.'+' .or. w(i)(1:1).eq.'-') cycle !Skip report words - i1=min(i+1,nwords) - if(w(i1)(1:1) .eq.'+' .or. w(i1)(1:1).eq.'-') cycle !Skip if i+1 is report - call pack28(w(i),n28) - write(msgbits(j:j+27),1002) n28 !Insert this call for RR73 message -1002 format(b28.28) - j=j+28 - nh1=nh1+1 - if(nh1.ge.5) exit !At most 5 RR73 callsigns - enddo - -! Process callsigns with a report - j=169 - j2=281 - if(bSendMsg) then - i3=2 - j=29 + 28*nh1 - j2=141 + 5*nh1 - endif - - do i=2,nwords - i1=min(i+1,nwords) - if(w(i1)(1:1).eq.'+' .or. w(i1)(1:1).eq.'-') then - call pack28(w(i),n28) - write(msgbits(j:j+27),1002) n28 !Insert this call - read(w(i1),*) n !Valid reports are -18 to +12, plus RR73 - if(n.lt.-18) n=-18 !... Even numbers only ... - if(n.gt.12) n=12 - write(msgbits(j2:j2+4),1000) n+18 -1000 format(b5.5) - w(i1)="" - nh2=nh2+1 -! print*,'C',i3,i,j,n,w(i) - if( nh2.ge.4 .or. (nh1+nh2).ge.9 ) exit ! At most 4 callsigns w/reports - j=j+28 - j2=j2+5 - endif - enddo - -800 if(bSendMsg) then - i1=26 - do i=1,26 - if(freeTextMsg(i:i).ne.' ') i1=i - enddo - do i=i1+1,26 - freeTextMsg(i:i)='.' - enddo - if(i3.eq.3) then - call packtext77(freeTextMsg(1:13),msgbits(74:144)) - call packtext77(freeTextMsg(14:26),msgbits(145:215)) - elseif(i3.eq.2) then - call packtext77(freeTextMsg(1:13),msgbits(161:231)) - call packtext77(freeTextMsg(14:26),msgbits(232:302)) - endif - write(msgbits(327:329),'(b3.3)') i3 !Message type i3=2 - endif - if(bMoreCQs) msgbits(306:306)='1' - - read(msgbits(327:329),'(b3)') i3 - if(i3.eq.0) then - do i=1,9 - i0=i*28 + 1 - read(msgbits(i0:i0+27),'(b28)') n28 - if(n28.eq.0) write(msgbits(i0:i0+27),'(b28.28)') NQU1RKS - enddo - else if(i3.eq.3) then - allz=.true. - do i=0,6 - i0=i*32 + 74 - read(msgbits(i0:i0+31),'(b32)') n32 - if(n32.ne.0) allz=.false. - enddo - if(allz) then - do i=0,6 - i0=i*32 + 74 - write(msgbits(i0:i0+31),'(b32.32)') NQU1RKS - enddo - endif - endif - - read(msgbits,1004) xin(0:46) -1004 format(47b7) - - mask21=2**21 - 1 - n47=47 - ncrc21=iand(nhash2(xin,n47,571),mask21) !Compute 21-bit CRC - xin(47)=ncrc21/16384 !First 7 of 21 bits - xin(48)=iand(ncrc21/128,127) !Next 7 bits - xin(49)=iand(ncrc21,127) !Last 7 bits - - xin=xin(49:0:-1) !Reverse the symbol order -! NB: CRC is now in first three symbols, fox call in the last four. - - return -end subroutine sfox_pack +subroutine sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) + + use qpc_mod + use packjt + use packjt77 + use julian + parameter (NQU1RKS=203514677) + integer*8 n47,n58,now + integer*1 xin(0:49) !Packed message as 7-bit symbols + logical*1 bMoreCQs,bSendMsg + logical text,allz + character*120 line !SuperFox message pieces + character*10 ckey + character*26 freeTextMsg + character*13 w(16) + character*11 c11 + character*329 msgbits !Packed message as bits + character*38 c + data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ + + i0=index(line,'/') + i3=0 !Default to i3=0, standard message + nh1=0 !Number of Hound calls with RR73 + nh2=0 !Number of Hound calls with report + +! Split the command line into words + w=' ' + i1=1 + do j=1,16 + do i=i1,min(i1+12,120) + if(line(i:i).eq.' ') exit + enddo + i2=i-1 + w(j)=line(i1:i2) + do i=i2+1,120 + if(line(i:i).ne.' ') exit + enddo + i1=i + if(i1.ge.120) exit + enddo + nwords=j + + do i=1,nwords + if(w(i)(1:1).eq.' ') then + nwords=i-1 + exit + endif + enddo + + do i=1,329 !Set all msgbits to '0' + msgbits(i:i)='0' + enddo + + now=itime8()/30 + now=30*now + read(ckey(5:10),*) notp + + write(msgbits(307:326),'(b20.20)') notp !Insert the digital signature + + if(w(1)(1:3).eq.'CQ ') then + i3=3 + c11=w(2)(1:11) + n58=0 + do i=1,11 + n58=n58*38 + index(c,c11(i:i)) - 1 + enddo + write(msgbits(1:58),'(b58.58)') n58 + call packgrid(w(3)(1:4),n15,text) + write(msgbits(59:73),'(b15.15)') n15 + write(msgbits(327:329),'(b3.3)') i3 !Message type i3=3 + go to 800 + endif + + call pack28(w(1),n28) !Fox call + write(msgbits(1:28),'(b28.28)') n28 + +! Default report is RR73 if we're also sending a free text message. + if(bSendMsg) msgbits(141:160)='11111111111111111111' + + j=29 + +! Process callsigns with RR73 + do i=2,nwords + if(w(i)(1:1).eq.'+' .or. w(i)(1:1).eq.'-') cycle !Skip report words + i1=min(i+1,nwords) + if(w(i1)(1:1) .eq.'+' .or. w(i1)(1:1).eq.'-') cycle !Skip if i+1 is report + call pack28(w(i),n28) + write(msgbits(j:j+27),1002) n28 !Insert this call for RR73 message +1002 format(b28.28) + j=j+28 + nh1=nh1+1 + if(nh1.ge.5) exit !At most 5 RR73 callsigns + enddo + +! Process callsigns with a report + j=169 + j2=281 + if(bSendMsg) then + i3=2 + j=29 + 28*nh1 + j2=141 + 5*nh1 + endif + + do i=2,nwords + i1=min(i+1,nwords) + if(w(i1)(1:1).eq.'+' .or. w(i1)(1:1).eq.'-') then + call pack28(w(i),n28) + write(msgbits(j:j+27),1002) n28 !Insert this call + read(w(i1),*) n !Valid reports are -18 to +12, plus RR73 + if(n.lt.-18) n=-18 !... Even numbers only ... + if(n.gt.12) n=12 + write(msgbits(j2:j2+4),1000) n+18 +1000 format(b5.5) + w(i1)="" + nh2=nh2+1 +! print*,'C',i3,i,j,n,w(i) + if( nh2.ge.4 .or. (nh1+nh2).ge.9 ) exit ! At most 4 callsigns w/reports + j=j+28 + j2=j2+5 + endif + enddo + +800 if(bSendMsg) then + i1=26 + do i=1,26 + if(freeTextMsg(i:i).ne.' ') i1=i + enddo + do i=i1+1,26 + freeTextMsg(i:i)='.' + enddo + if(i3.eq.3) then + call packtext77(freeTextMsg(1:13),msgbits(74:144)) + call packtext77(freeTextMsg(14:26),msgbits(145:215)) + elseif(i3.eq.2) then + call packtext77(freeTextMsg(1:13),msgbits(161:231)) + call packtext77(freeTextMsg(14:26),msgbits(232:302)) + endif + write(msgbits(327:329),'(b3.3)') i3 !Message type i3=2 + endif + if(bMoreCQs) msgbits(306:306)='1' + + read(msgbits(327:329),'(b3)') i3 + if(i3.eq.0) then + do i=1,9 + i0=i*28 + 1 + read(msgbits(i0:i0+27),'(b28)') n28 + if(n28.eq.0) write(msgbits(i0:i0+27),'(b28.28)') NQU1RKS + enddo + else if(i3.eq.3) then + allz=.true. + do i=0,6 + i0=i*32 + 74 + read(msgbits(i0:i0+31),'(b32)') n32 + if(n32.ne.0) allz=.false. + enddo + if(allz) then + do i=0,6 + i0=i*32 + 74 + write(msgbits(i0:i0+31),'(b32.32)') NQU1RKS + enddo + endif + endif + + read(msgbits,1004) xin(0:46) +1004 format(47b7) + + mask21=2**21 - 1 + n47=47 + ncrc21=iand(nhash2(xin,n47,571),mask21) !Compute 21-bit CRC + xin(47)=ncrc21/16384 !First 7 of 21 bits + xin(48)=iand(ncrc21/128,127) !Next 7 bits + xin(49)=iand(ncrc21,127) !Last 7 bits + + xin=xin(49:0:-1) !Reverse the symbol order +! NB: CRC is now in first three symbols, fox call in the last four. + + return +end subroutine sfox_pack diff --git a/lib/superfox/sfox_prob.f90 b/lib/superfox/sfox_prob.f90 index 4a278035..c8e9f25c 100755 --- a/lib/superfox/sfox_prob.f90 +++ b/lib/superfox/sfox_prob.f90 @@ -1,55 +1,55 @@ -subroutine sfox_prob(s3,rxdat,rxprob,rxdat2,rxprob2) - -! Demodulate the 64-bin spectra for each of 63 symbols in a frame. - -! Parameters -! rxdat most reliable symbol value -! rxdat2 second most likely symbol value -! rxprob probability that rxdat was the transmitted value -! rxprob2 probability that rxdat2 was the transmitted value - - use sfox_mod - implicit real*8 (a-h,o-z) - real*4 s3(0:NQ-1,0:NN-1) - integer rxdat(0:NN-1),rxprob(0:NN-1),rxdat2(0:NN-1),rxprob2(0:NN-1) - - afac=1.1 -! scale=255.999 - scale=2047.999 - -! Compute average spectral value - ave=sum(s3)/(NQ*ND) - i1=1 !Silence warning - i2=1 - -! Compute probabilities for most reliable symbol values - do j=0,NN-1 !Loop over all symbols - s1=-1.e30 - psum=0. - do i=0,NQ-1 !Loop over frequency bins - x=min(afac*s3(i,j)/ave,50.d0) - psum=psum+s3(i,j) - if(s3(i,j).gt.s1) then - s1=s3(i,j) !Find max signal+noise power - i1=i !Find most reliable symbol value - endif - enddo - if(psum.eq.0.0) psum=1.e-6 !Guard against zero signal+noise - - s2=-1.e30 - do i=0,NQ-1 - if(i.ne.i1 .and. s3(i,j).gt.s2) then - s2=s3(i,j) !Second largest signal+noise power - i2=i !Bin number for second largest power - endif - enddo - p1=s1/psum !p1, p2 are symbol metrics for ftrsd - p2=s2/psum - rxdat(j)=i1 - rxdat2(j)=i2 - rxprob(j)=scale*p1 !Scaled probabilities, 0 - 255 - rxprob2(j)=scale*p2 - enddo - - return -end subroutine sfox_prob +subroutine sfox_prob(s3,rxdat,rxprob,rxdat2,rxprob2) + +! Demodulate the 64-bin spectra for each of 63 symbols in a frame. + +! Parameters +! rxdat most reliable symbol value +! rxdat2 second most likely symbol value +! rxprob probability that rxdat was the transmitted value +! rxprob2 probability that rxdat2 was the transmitted value + + use sfox_mod + implicit real*8 (a-h,o-z) + real*4 s3(0:NQ-1,0:NN-1) + integer rxdat(0:NN-1),rxprob(0:NN-1),rxdat2(0:NN-1),rxprob2(0:NN-1) + + afac=1.1 +! scale=255.999 + scale=2047.999 + +! Compute average spectral value + ave=sum(s3)/(NQ*ND) + i1=1 !Silence warning + i2=1 + +! Compute probabilities for most reliable symbol values + do j=0,NN-1 !Loop over all symbols + s1=-1.e30 + psum=0. + do i=0,NQ-1 !Loop over frequency bins + x=min(afac*s3(i,j)/ave,50.d0) + psum=psum+s3(i,j) + if(s3(i,j).gt.s1) then + s1=s3(i,j) !Find max signal+noise power + i1=i !Find most reliable symbol value + endif + enddo + if(psum.eq.0.0) psum=1.e-6 !Guard against zero signal+noise + + s2=-1.e30 + do i=0,NQ-1 + if(i.ne.i1 .and. s3(i,j).gt.s2) then + s2=s3(i,j) !Second largest signal+noise power + i2=i !Bin number for second largest power + endif + enddo + p1=s1/psum !p1, p2 are symbol metrics for ftrsd + p2=s2/psum + rxdat(j)=i1 + rxdat2(j)=i2 + rxprob(j)=scale*p1 !Scaled probabilities, 0 - 255 + rxprob2(j)=scale*p2 + enddo + + return +end subroutine sfox_prob diff --git a/lib/superfox/sfox_remove.f90 b/lib/superfox/sfox_remove.f90 new file mode 100755 index 00000000..d0a46c72 --- /dev/null +++ b/lib/superfox/sfox_remove.f90 @@ -0,0 +1,96 @@ +subroutine sfox_remove_tone(c0,fsync) + + parameter (NMAX=15*12000) + parameter (NFILT=8000) + complex c0(NMAX) + complex cwindow(15*12000) + complex cref(NMAX) + complex cfilt(NMAX) + real window(-NFILT/2:NFILT/2) +! real endcorrection(NFILT/2+1) + real s(NMAX/4) + integer ipk(1) + logical first + data first/.true./ + save cwindow,first,pi + + if(fsync.gt.1400.0) return !Avoid a potential bounds error + + if(first) then + pi=4.0*atan(1.0) + fac=1.0/float(NMAX) + sumw=0.0 + do j=-NFILT/2,NFILT/2 + window(j)=cos(pi*j/NFILT)**2 + sumw=sumw+window(j) + enddo + cwindow=0. + cwindow(1:NFILT+1)=window/sumw + cwindow=cshift(cwindow,NFILT/2+1) + call four2a(cwindow,NMAX,1,-1,1) + cwindow=cwindow*fac ! frequency domain smoothing filter + first=.false. + endif + + fsample=12000.0 + baud=fsample/1024.0 + df=fsample/NMAX + fac=1.0/NMAX + + do it=1,1 ! Remove 1 tone, if present + cfilt=fac*c0 + call four2a(cfilt,NMAX,1,-1,1) ! fourier transform of input data + iz=NMAX/4 + do i=1,iz + s(i)=real(cfilt(i))**2 + aimag(cfilt(i))**2 + enddo + + ia=nint((fsync-50.0)/df) + ib=nint((fsync+1500.0+50.0)/df) + ipk=maxloc(s(ia:ib)) + i0=ipk(1) + ia - 1 + + nbaud=nint(baud/df) + ia=i0-nbaud + ib=i0+nbaud + s0=0.0 + s1=0.0 + s2=0.0 + do i=ia,ib + s0=s0+s(i) + s1=s1+(i-i0)*s(i) + enddo + delta=s1/s0 + i0=nint(i0+delta) + f2=i0*df + + ia=i0-nbaud + ib=i0+nbaud + do i=ia,ib + s2=s2 + s(i)*(i-i0)**2 + enddo + sigma=sqrt(s2/s0)*df + +! write(*,*) 'frequency, spectral width ',f2,sigma + if(sigma .gt. 2.5) exit +! write(*,*) 'remove_tone - frequency: ',f2 + + dt=1.0/fsample + do i=1, NMAX + arg=2*pi*f2*i*dt + cref(i)=cmplx(cos(arg),sin(arg)) + enddo + cfilt=c0*conjg(cref) ! baseband to be filtered + call four2a(cfilt,NMAX,1,-1,1) + cfilt=cfilt*cwindow + call four2a(cfilt,NMAX,1,1,1) + + nframe=50*3456 + do i=1,nframe + cref(i)=cfilt(i)*cref(i) + c0(i)=c0(i)-cref(i) + enddo + enddo + + return +end subroutine sfox_remove_tone diff --git a/lib/superfox/sfox_remove_ft8.f90 b/lib/superfox/sfox_remove_ft8.f90 index fbfd75f0..fc990bca 100755 --- a/lib/superfox/sfox_remove_ft8.f90 +++ b/lib/superfox/sfox_remove_ft8.f90 @@ -1,213 +1,213 @@ -subroutine sfox_remove_ft8(dd,npts) - use packjt77 - include 'ft8_params.f90' - parameter (MAXCAND=100) - parameter (NP2=2812) - integer itone(NN) - integer iloc(1), ip(1) - integer icos7(0:6) - integer graymap(0:7) - integer*1 cw(174),apmask(174) - integer*1 message91(91) - integer*1 message77(77) - - character*77 c77 - character*37 msg37 - - real s8(0:7,NN) - real s2(0:7) - real ss(9) - real candidate(3,MAXCAND) - real sbase(NH1) - real dd(npts) - real bmeta(174),bmetd(174) - real llra(174),llrd(174) - complex cd0(0:3199) - complex csymb(32) - complex ctwk(32) - complex cs(0:7,NN) - data icos7/3,1,4,0,6,5,2/ - logical first,newdat - logical one(0:7,0:2) - logical unpk77_success - data first/.true./ - data graymap/0,1,3,2,5,6,4,7/ - save one,first,twopi - - if(first) then - one=.false. - do i=0,7 - do j=0,2 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - first=.false. - twopi=8.0*atan(1.0) - endif - - fs2=12000.0/NDOWN - dt2=1.0/fs2 - nfa=500 - nfb=2500 - syncmin=1.5 - nfqso=750 - call sync8(dd,npts,nfa,nfb,syncmin,nfqso,MAXCAND,candidate,ncand,sbase) - newdat=.true. - do icand=1,ncand - f1=candidate(1,icand) - xdt=candidate(2,icand) - xbase=10.0**(0.1*(sbase(nint(f1/3.125))-40.0)) - call ft8_downsample(dd,newdat,f1,cd0) - newdat=.false. - i0=nint((xdt+0.5)*fs2) - smax=0.0 - do idt=i0-10,i0+10 - call sync8d(cd0,idt,ctwk,0,sync) - if(sync.gt.smax) then - smax=sync - ibest=idt - endif - enddo - - smax=0.0 - delfbest=0.0 - do ifr=-5,5 !Search over +/- 2.5 Hz - delf=ifr*0.5 - dphi=twopi*delf*dt2 - phi=0.0 - do i=1,32 - ctwk(i)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - enddo - call sync8d(cd0,ibest,ctwk,1,sync) - if( sync .gt. smax ) then - smax=sync - delfbest=delf - endif - enddo - - f1=f1+delfbest !Improved estimate of DF - - call ft8_downsample(dd,newdat,f1,cd0) !Mix f1 to baseband and downsample - - smax=0.0 - do idt=-4,4 !Search over +/- one quarter symbol - call sync8d(cd0,ibest+idt,ctwk,0,sync) - ss(idt+5)=sync - enddo - smax=maxval(ss) - iloc=maxloc(ss) - ibest=iloc(1)-5+ibest - xdt=(ibest-1)*dt2 - sync=smax - - do k=1,NN - i1=ibest+(k-1)*32 - csymb=cmplx(0.0,0.0) - if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) - call four2a(csymb,32,1,-1,1) - cs(0:7,k)=csymb(1:8)/1e3 - s8(0:7,k)=abs(csymb(1:8)) - enddo - -! sync quality check - is1=0 - is2=0 - is3=0 - do k=1,7 - ip=maxloc(s8(:,k)) - if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 - ip=maxloc(s8(:,k+36)) - if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 - ip=maxloc(s8(:,k+72)) - if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 - enddo -! hard sync sum - max is 21 - nsync=is1+is2+is3 - if(nsync .le. 6) then ! bail out - nbadcrc=1 - cycle - endif - - nsym=1 - nt=2**(3*nsym) - do ihalf=1,2 - do k=1,29,nsym - if(ihalf.eq.1) ks=k+7 - if(ihalf.eq.2) ks=k+43 - amax=-1.0 - do i=0,nt-1 - i3=iand(i,7) - s2(i)=abs(cs(graymap(i3),ks)) - enddo - i32=1+(k-1)*3+(ihalf-1)*87 - ibmax=2 - do ib=0,ibmax - bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) - if(i32+ib .gt.174) cycle - bmeta(i32+ib)=bm - den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) - if(den.gt.0.0) then - cm=bm/den - else ! erase it - cm=0.0 - endif - bmetd(i32+ib)=cm - enddo - enddo - enddo - - call normalizebmet(bmeta,174) - call normalizebmet(bmetd,174) - - scalefac=2.83 - llra=scalefac*bmeta - llrd=scalefac*bmetd - - cw=0 - dmin=0 - norder=2 - maxosd=-1 - Keff=91 - apmask=0 - message91=0 - cw=0 - call decode174_91(llra,Keff,maxosd,norder,apmask,message91,cw, & - ntype,nharderrors,dmin) - - if(nharderrors.ge.0) then - message77=message91(1:77) - else - cycle - endif - - if(count(cw.eq.0).eq.174) cycle - - write(c77,'(77i1)') message77 - read(c77(72:74),'(b3)') n3 - read(c77(75:77),'(b3)') i3 - if(i3.gt.5 .or. (i3.eq.0.and.n3.gt.6)) cycle - if(i3.eq.0 .and. n3.eq.2) cycle - - call unpack77(c77,1,msg37,unpk77_success) -! write(77,*) 'FT8 interference: ',msg37 - if(.not.unpk77_success) cycle -! Message structure: S7 D29 S7 D29 S7 - itone(1:7)=icos7 - itone(36+1:36+7)=icos7 - itone(NN-6:NN)=icos7 - k=7 - do j=1,ND - i=3*j -2 - k=k+1 - if(j.eq.30) k=k+7 - indx=cw(i)*4 + cw(i+1)*2 + cw(i+2) - itone(k)=graymap(indx) - enddo - call subtractft8(dd,itone,f1,xdt,.true.) -! return - enddo - return -end subroutine sfox_remove_ft8 +subroutine sfox_remove_ft8(dd,npts) + use packjt77 + include 'ft8_params.f90' + parameter (MAXCAND=100) + parameter (NP2=2812) + integer itone(NN) + integer iloc(1), ip(1) + integer icos7(0:6) + integer graymap(0:7) + integer*1 cw(174),apmask(174) + integer*1 message91(91) + integer*1 message77(77) + + character*77 c77 + character*37 msg37 + + real s8(0:7,NN) + real s2(0:7) + real ss(9) + real candidate(3,MAXCAND) + real sbase(NH1) + real dd(npts) + real bmeta(174),bmetd(174) + real llra(174),llrd(174) + complex cd0(0:3199) + complex csymb(32) + complex ctwk(32) + complex cs(0:7,NN) + data icos7/3,1,4,0,6,5,2/ + logical first,newdat + logical one(0:7,0:2) + logical unpk77_success + data first/.true./ + data graymap/0,1,3,2,5,6,4,7/ + save one,first,twopi + + if(first) then + one=.false. + do i=0,7 + do j=0,2 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + first=.false. + twopi=8.0*atan(1.0) + endif + + fs2=12000.0/NDOWN + dt2=1.0/fs2 + nfa=500 + nfb=2500 + syncmin=1.5 + nfqso=750 + call sync8(dd,npts,nfa,nfb,syncmin,nfqso,MAXCAND,candidate,ncand,sbase) + newdat=.true. + do icand=1,ncand + f1=candidate(1,icand) + xdt=candidate(2,icand) + xbase=10.0**(0.1*(sbase(nint(f1/3.125))-40.0)) + call ft8_downsample(dd,newdat,f1,cd0) + newdat=.false. + i0=nint((xdt+0.5)*fs2) + smax=0.0 + do idt=i0-10,i0+10 + call sync8d(cd0,idt,ctwk,0,sync) + if(sync.gt.smax) then + smax=sync + ibest=idt + endif + enddo + + smax=0.0 + delfbest=0.0 + do ifr=-5,5 !Search over +/- 2.5 Hz + delf=ifr*0.5 + dphi=twopi*delf*dt2 + phi=0.0 + do i=1,32 + ctwk(i)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + enddo + call sync8d(cd0,ibest,ctwk,1,sync) + if( sync .gt. smax ) then + smax=sync + delfbest=delf + endif + enddo + + f1=f1+delfbest !Improved estimate of DF + + call ft8_downsample(dd,newdat,f1,cd0) !Mix f1 to baseband and downsample + + smax=0.0 + do idt=-4,4 !Search over +/- one quarter symbol + call sync8d(cd0,ibest+idt,ctwk,0,sync) + ss(idt+5)=sync + enddo + smax=maxval(ss) + iloc=maxloc(ss) + ibest=iloc(1)-5+ibest + xdt=(ibest-1)*dt2 + sync=smax + + do k=1,NN + i1=ibest+(k-1)*32 + csymb=cmplx(0.0,0.0) + if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) + call four2a(csymb,32,1,-1,1) + cs(0:7,k)=csymb(1:8)/1e3 + s8(0:7,k)=abs(csymb(1:8)) + enddo + +! sync quality check + is1=0 + is2=0 + is3=0 + do k=1,7 + ip=maxloc(s8(:,k)) + if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s8(:,k+36)) + if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s8(:,k+72)) + if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 + enddo +! hard sync sum - max is 21 + nsync=is1+is2+is3 + if(nsync .le. 6) then ! bail out + nbadcrc=1 + cycle + endif + + nsym=1 + nt=2**(3*nsym) + do ihalf=1,2 + do k=1,29,nsym + if(ihalf.eq.1) ks=k+7 + if(ihalf.eq.2) ks=k+43 + amax=-1.0 + do i=0,nt-1 + i3=iand(i,7) + s2(i)=abs(cs(graymap(i3),ks)) + enddo + i32=1+(k-1)*3+(ihalf-1)*87 + ibmax=2 + do ib=0,ibmax + bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) + if(i32+ib .gt.174) cycle + bmeta(i32+ib)=bm + den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) + if(den.gt.0.0) then + cm=bm/den + else ! erase it + cm=0.0 + endif + bmetd(i32+ib)=cm + enddo + enddo + enddo + + call normalizebmet(bmeta,174) + call normalizebmet(bmetd,174) + + scalefac=2.83 + llra=scalefac*bmeta + llrd=scalefac*bmetd + + cw=0 + dmin=0 + norder=2 + maxosd=-1 + Keff=91 + apmask=0 + message91=0 + cw=0 + call decode174_91(llra,Keff,maxosd,norder,apmask,message91,cw, & + ntype,nharderrors,dmin) + + if(nharderrors.ge.0) then + message77=message91(1:77) + else + cycle + endif + + if(count(cw.eq.0).eq.174) cycle + + write(c77,'(77i1)') message77 + read(c77(72:74),'(b3)') n3 + read(c77(75:77),'(b3)') i3 + if(i3.gt.5 .or. (i3.eq.0.and.n3.gt.6)) cycle + if(i3.eq.0 .and. n3.eq.2) cycle + + call unpack77(c77,1,msg37,unpk77_success) +! write(77,*) 'FT8 interference: ',msg37 + if(.not.unpk77_success) cycle +! Message structure: S7 D29 S7 D29 S7 + itone(1:7)=icos7 + itone(36+1:36+7)=icos7 + itone(NN-6:NN)=icos7 + k=7 + do j=1,ND + i=3*j -2 + k=k+1 + if(j.eq.30) k=k+7 + indx=cw(i)*4 + cw(i+1)*2 + cw(i+2) + itone(k)=graymap(indx) + enddo + call subtractft8(dd,itone,f1,xdt,.true.) +! return + enddo + return +end subroutine sfox_remove_ft8 diff --git a/lib/superfox/sfox_remove_tone.f90 b/lib/superfox/sfox_remove_tone.f90 index 20c5e76c..c8f9e033 100755 --- a/lib/superfox/sfox_remove_tone.f90 +++ b/lib/superfox/sfox_remove_tone.f90 @@ -1,95 +1,109 @@ -subroutine sfox_remove_tone(c0,fsync) - - parameter (NMAX=15*12000) - parameter (NFILT=8000) - complex c0(NMAX) - complex cwindow(15*12000) - complex cref(NMAX) - complex cfilt(NMAX) - real window(-NFILT/2:NFILT/2) -! real endcorrection(NFILT/2+1) - real s(NMAX/4) - integer ipk(1) - logical first - data first/.true./ - save cwindow,first,pi - - if(first) then - pi=4.0*atan(1.0) - fac=1.0/float(NMAX) - sumw=0.0 - do j=-NFILT/2,NFILT/2 - window(j)=cos(pi*j/NFILT)**2 - sumw=sumw+window(j) - enddo - cwindow=0. - cwindow(1:NFILT+1)=window/sumw - cwindow=cshift(cwindow,NFILT/2+1) - call four2a(cwindow,NMAX,1,-1,1) - cwindow=cwindow*fac ! frequency domain smoothing filter - first=.false. - endif - - fsample=12000.0 - baud=fsample/1024.0 - df=fsample/NMAX - fac=1.0/NMAX - - do it=1,1 ! Remove 1 tone, if present - cfilt=fac*c0 - call four2a(cfilt,NMAX,1,-1,1) ! fourier transform of input data - iz=NMAX/4 - do i=1,iz - s(i)=real(cfilt(i))**2 + aimag(cfilt(i))**2 - enddo - - ia=nint((fsync-50.0)/df) - ib=nint((fsync+1500.0+50.0)/df) - ipk=maxloc(s(ia:ib)) - i0=ipk(1) + ia - 1 - - nbaud=nint(baud/df) - ia=i0-nbaud - ib=i0+nbaud - s0=0.0 - s1=0.0 - s2=0.0 - do i=ia,ib - s0=s0+s(i) - s1=s1+(i-i0)*s(i) - enddo - delta=s1/s0 - i0=nint(i0+delta) - f2=i0*df - - ia=i0-nbaud - ib=i0+nbaud - do i=ia,ib - s2=s2 + s(i)*(i-i0)**2 - enddo - sigma=sqrt(s2/s0)*df - -! write(*,*) 'frequency, spectral width ',f2,sigma - if(sigma .gt. 2.5) exit -! write(*,*) 'remove_tone - frequency: ',f2 - - dt=1.0/fsample - do i=1, NMAX - arg=2*pi*f2*i*dt - cref(i)=cmplx(cos(arg),sin(arg)) - enddo - cfilt=c0*conjg(cref) ! baseband to be filtered - call four2a(cfilt,NMAX,1,-1,1) - cfilt=cfilt*cwindow - call four2a(cfilt,NMAX,1,1,1) - - nframe=50*3456 - do i=1,nframe - cref(i)=cfilt(i)*cref(i) - c0(i)=c0(i)-cref(i) - enddo - enddo - - return - -end subroutine sfox_remove_tone +subroutine sfox_remove_tone(c0,fsync) + + parameter (NMAX=15*12000) + parameter (NFILT=8000) + complex c0(NMAX) + complex cwindow(15*12000) + complex cref(NMAX) + complex cfilt(NMAX) + real window(-NFILT/2:NFILT/2) +! real endcorrection(NFILT/2+1) + real s(NMAX/4) + integer ipk(1) + logical first + data first/.true./ + save cwindow,first,pi + + if(fsync.gt.1400.0) return !Avoid a potential bounds error + + if(first) then + pi=4.0*atan(1.0) + fac=1.0/float(NMAX) + sumw=0.0 + do j=-NFILT/2,NFILT/2 + window(j)=cos(pi*j/NFILT)**2 + sumw=sumw+window(j) + enddo + cwindow=0. + cwindow(1:NFILT+1)=window/sumw + cwindow=cshift(cwindow,NFILT/2+1) + call four2a(cwindow,NMAX,1,-1,1) + cwindow=cwindow*fac ! frequency domain smoothing filter + first=.false. + endif + + fsample=12000.0 + baud=fsample/1024.0 + df=fsample/NMAX + fac=1.0/NMAX + + do it=1,1 ! Remove 1 tone, if present + cfilt=fac*c0 + call four2a(cfilt,NMAX,1,-1,1) ! fourier transform of input data + iz=NMAX/4 + do i=1,iz + s(i)=real(cfilt(i))**2 + aimag(cfilt(i))**2 + enddo + + ia=nint((fsync-50.0)/df) + ib=nint((fsync+1500.0+50.0)/df) + + if (ia .lt. 1) ia=1; ! Avoid a potential bounds error + if (ib .ge. 45000) ib=45000; ! Avoid a potential bounds error + + ipk=maxloc(s(ia:ib)) + i0=ipk(1) + ia - 1 + + nbaud=nint(baud/df) + ia=i0-nbaud + ib=i0+nbaud + + if (ia .lt. 1) ia=1; ! Avoid a potential bounds error + if (ib .ge. 45000) ib=45000; ! Avoid a potential bounds error + + s0=0.0 + s1=0.0 + s2=0.0 + do i=ia,ib + s0=s0+s(i) + s1=s1+(i-i0)*s(i) + enddo + delta=s1/s0 + i0=nint(i0+delta) + f2=i0*df + + ia=i0-nbaud + ib=i0+nbaud + + if (ia .lt. 1) ia=1; ! Avoid a potential bounds error + if (ib .ge. 45000) ib=45000; ! Avoid a potential bounds error + + do i=ia,ib + s2=s2 + s(i)*(i-i0)**2 + enddo + sigma=sqrt(s2/s0)*df + +! write(*,*) 'frequency, spectral width ',f2,sigma + if(sigma .gt. 2.5) exit +! write(*,*) 'remove_tone - frequency: ',f2 + + dt=1.0/fsample + do i=1, NMAX + arg=2*pi*f2*i*dt + cref(i)=cmplx(cos(arg),sin(arg)) + enddo + cfilt=c0*conjg(cref) ! baseband to be filtered + call four2a(cfilt,NMAX,1,-1,1) + cfilt=cfilt*cwindow + call four2a(cfilt,NMAX,1,1,1) + + nframe=50*3456 + do i=1,nframe + cref(i)=cfilt(i)*cref(i) + c0(i)=c0(i)-cref(i) + enddo + enddo + + return + +end subroutine sfox_remove_tone diff --git a/lib/superfox/sfox_unpack.f90 b/lib/superfox/sfox_unpack.f90 index 24209d0a..56168963 100755 --- a/lib/superfox/sfox_unpack.f90 +++ b/lib/superfox/sfox_unpack.f90 @@ -1,119 +1,119 @@ -subroutine sfox_unpack(nutc,x,nsnr,f0,dt0,foxcall,notp) - - use packjt77 - parameter (NQU1RKS=203514677) - integer*1 x(0:49) - integer*8 n58 - logical success - character*336 msgbits - character*22 msg(10) !### only msg(1) is used ??? ### - character*13 foxcall,c13 - character*10 ssignature - character*4 crpt(5),grid4 - character*26 freeTextMsg - character*38 c - logical use_otp - data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ - - ncq=0 - if (notp.eq.0) then - use_otp = .FALSE. - else - use_otp = .TRUE. - endif - write(msgbits,1000) x(0:46) -1000 format(47b7.7) - read(msgbits(327:329),'(b6)') i3 !Message type - read(msgbits(1:28),'(b28)') n28 !Standard Fox call - call unpack28(n28,foxcall,success) - - if(i3.eq.1) then !Compound Fox callsign -! read(msgbits(87:101),'(b15)') n15 -! call unpackgrid(n15,grid4) -! msg(1)='CQ '//trim(foxcall)//' '//grid4 -! write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(1)) -! go to 100 - else if(i3.eq.2) then !Up to 4 Hound calls and free text - call unpacktext77(msgbits(161:231),freeTextMsg(1:13)) - call unpacktext77(msgbits(232:302),freeTextMsg(14:26)) - do i=26,1,-1 - if(freeTextMsg(i:i).ne.'.') exit - freeTextMsg(i:i)=' ' - enddo - write(*,1100) nutc,nsnr,dt0,nint(f0),freeTextMsg -1100 format(i6.6,i4,f5.1,i5,1x,"~",2x,a) - else if(i3.eq.3) then !CQ FoxCall Grid - read(msgbits(1:58),'(b58)') n58 !FoxCall - do i=11,1,-1 - j=mod(n58,38)+1 - foxcall(i:i)=c(j:j) - n58=n58/38 - enddo - foxcall(12:13)=' ' - read(msgbits(59:73),'(b15)') n15 - call unpackgrid(n15,grid4) - msg(1)='CQ '//trim(foxcall)//' '//grid4 - write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(1)) - read(msgbits(74:105),'(b32)') n32 - if(n32.eq.NQU1RKS) go to 100 - call unpacktext77(msgbits(74:144),freeTextMsg(1:13)) - call unpacktext77(msgbits(145:215),freeTextMsg(14:26)) - do i=26,1,-1 - if(freeTextMsg(i:i).ne.'.') exit - freeTextMsg(i:i)=' ' - enddo - if(len(trim(freeTextMsg)).gt.0) write(*,1100) nutc,nsnr,dt0,& - nint(f0),freeTextMsg - go to 100 - endif - - j=281 - iz=4 !Max number of reports - if(i3.eq.2) j=141 - do i=1,iz !Extract the reports - read(msgbits(j:j+4),'(b5)') n - if(n.eq.31) then - crpt(i)='RR73' - else - write(crpt(i),1006) n-18 -1006 format(i3.2) - if(crpt(i)(1:1).eq.' ') crpt(i)(1:1)='+' - endif - j=j+5 - enddo - -! Unpack Hound callsigns and format user-level messages: - iz=9 !Max number of hound calls - if(i3.eq.2 .or. i3.eq.3) iz=4 - do i=1,iz - j=28*i + 1 - read(msgbits(j:j+27),'(b28)') n28 - call unpack28(n28,c13,success) - if(n28.eq.0 .or. n28.eq.NQU1RKS) cycle - msg(i)=trim(c13)//' '//trim(foxcall) - if(msg(i)(1:3).eq.'CQ ') then - ncq=ncq+1 - else - if(i3.eq.2) then - msg(i)=trim(msg(i))//' '//crpt(i) - else - if(i.le.5) msg(i)=trim(msg(i))//' RR73' - if(i.gt.5) msg(i)=trim(msg(i))//' '//crpt(i-5) - endif - endif - if(ncq.le.1 .or. msg(i)(1:3).ne.'CQ ') then - write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(i)) - endif - enddo - - if(msgbits(306:306).eq.'1' .and. ncq.lt.1) then - write(*,1100) nutc,nsnr,dt0,nint(f0),'CQ '//foxcall - endif - -100 read(msgbits(307:326),'(b20)') notp - if (use_otp) then - write(ssignature,'(I6.6)') notp - write(*,1100) nutc,nsnr,dt0,nint(f0),'$VERIFY$ '//trim(foxcall)//' '//trim(ssignature) - endif - return -end subroutine sfox_unpack +subroutine sfox_unpack(nutc,x,nsnr,f0,dt0,foxcall,notp) + + use packjt77 + parameter (NQU1RKS=203514677) + integer*1 x(0:49) + integer*8 n58 + logical success + character*336 msgbits + character*22 msg(10) !### only msg(1) is used ??? ### + character*13 foxcall,c13 + character*10 ssignature + character*4 crpt(5),grid4 + character*26 freeTextMsg + character*38 c + logical use_otp + data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ + + ncq=0 + if (notp.eq.0) then + use_otp = .FALSE. + else + use_otp = .TRUE. + endif + write(msgbits,1000) x(0:46) +1000 format(47b7.7) + read(msgbits(327:329),'(b6)') i3 !Message type + read(msgbits(1:28),'(b28)') n28 !Standard Fox call + call unpack28(n28,foxcall,success) + + if(i3.eq.1) then !Compound Fox callsign +! read(msgbits(87:101),'(b15)') n15 +! call unpackgrid(n15,grid4) +! msg(1)='CQ '//trim(foxcall)//' '//grid4 +! write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(1)) +! go to 100 + else if(i3.eq.2) then !Up to 4 Hound calls and free text + call unpacktext77(msgbits(161:231),freeTextMsg(1:13)) + call unpacktext77(msgbits(232:302),freeTextMsg(14:26)) + do i=26,1,-1 + if(freeTextMsg(i:i).ne.'.') exit + freeTextMsg(i:i)=' ' + enddo + write(*,1100) nutc,nsnr,dt0,nint(f0),freeTextMsg +1100 format(i6.6,i4,f5.1,i5,1x,"~",2x,a) + else if(i3.eq.3) then !CQ FoxCall Grid + read(msgbits(1:58),'(b58)') n58 !FoxCall + do i=11,1,-1 + j=mod(n58,38)+1 + foxcall(i:i)=c(j:j) + n58=n58/38 + enddo + foxcall(12:13)=' ' + read(msgbits(59:73),'(b15)') n15 + call unpackgrid(n15,grid4) + msg(1)='CQ '//trim(foxcall)//' '//grid4 + write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(1)) + read(msgbits(74:105),'(b32)') n32 + if(n32.eq.NQU1RKS) go to 100 + call unpacktext77(msgbits(74:144),freeTextMsg(1:13)) + call unpacktext77(msgbits(145:215),freeTextMsg(14:26)) + do i=26,1,-1 + if(freeTextMsg(i:i).ne.'.') exit + freeTextMsg(i:i)=' ' + enddo + if(len(trim(freeTextMsg)).gt.0) write(*,1100) nutc,nsnr,dt0,& + nint(f0),freeTextMsg + go to 100 + endif + + j=281 + iz=4 !Max number of reports + if(i3.eq.2) j=141 + do i=1,iz !Extract the reports + read(msgbits(j:j+4),'(b5)') n + if(n.eq.31) then + crpt(i)='RR73' + else + write(crpt(i),1006) n-18 +1006 format(i3.2) + if(crpt(i)(1:1).eq.' ') crpt(i)(1:1)='+' + endif + j=j+5 + enddo + +! Unpack Hound callsigns and format user-level messages: + iz=9 !Max number of hound calls + if(i3.eq.2 .or. i3.eq.3) iz=4 + do i=1,iz + j=28*i + 1 + read(msgbits(j:j+27),'(b28)') n28 + call unpack28(n28,c13,success) + if(n28.eq.0 .or. n28.eq.NQU1RKS) cycle + msg(i)=trim(c13)//' '//trim(foxcall) + if(msg(i)(1:3).eq.'CQ ') then + ncq=ncq+1 + else + if(i3.eq.2) then + msg(i)=trim(msg(i))//' '//crpt(i) + else + if(i.le.5) msg(i)=trim(msg(i))//' RR73' + if(i.gt.5) msg(i)=trim(msg(i))//' '//crpt(i-5) + endif + endif + if(ncq.le.1 .or. msg(i)(1:3).ne.'CQ ') then + write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(i)) + endif + enddo + + if(msgbits(306:306).eq.'1' .and. ncq.lt.1) then + write(*,1100) nutc,nsnr,dt0,nint(f0),'CQ '//foxcall + endif + +100 read(msgbits(307:326),'(b20)') notp + if (use_otp) then + write(ssignature,'(I6.6)') notp + write(*,1100) nutc,nsnr,dt0,nint(f0),'$VERIFY$ '//trim(foxcall)//' '//trim(ssignature) + endif + return +end subroutine sfox_unpack diff --git a/lib/superfox/sfox_wave.f90 b/lib/superfox/sfox_wave.f90 index 2e39a1c6..db69899c 100755 --- a/lib/superfox/sfox_wave.f90 +++ b/lib/superfox/sfox_wave.f90 @@ -1,40 +1,40 @@ -subroutine sfox_wave(fname) - -! Called by WSJT-X when it's time for SuperFox to transmit. Reads array -! itone(1:151) from disk file 'sfox_2.dat' in the writable data directory. - - parameter (NWAVE=(160+2)*134400*4) !Max WSJT-X waveform (FST4-1800 at 48kHz) - parameter (NN=151,NSPS=1024) - character*(*) fname - integer itone(151) - real*8 dt,twopi,f0,baud,phi,dphi - - common/foxcom/wave(NWAVE) - - wave=0. - open(25,file=trim(fname),status='unknown',err=999) - read(25,'(20i4)',err=999,end=999) itone - close(25) - if(itone(1).lt.0 .or. itone(1).gt.128) go to 999 - -! Generate the SuperFox waveform. - - dt=1.d0/48000.d0 - twopi=8.d0*atan(1.d0) - f0=750.0d0 - phi=0.d0 - baud=12000.d0/NSPS - k=0 - do j=1,NN - f=f0 + baud*mod(itone(j),128) - dphi=twopi*f*dt - do ii=1,4*NSPS - k=k+1 - phi=phi+dphi - xphi=phi - wave(k)=sin(xphi) - enddo - enddo - -999 return -end subroutine sfox_wave +subroutine sfox_wave(fname) + +! Called by WSJT-X when it's time for SuperFox to transmit. Reads array +! itone(1:151) from disk file 'sfox_2.dat' in the writable data directory. + + parameter (NWAVE=(160+2)*134400*4) !Max WSJT-X waveform (FST4-1800 at 48kHz) + parameter (NN=151,NSPS=1024) + character*(*) fname + integer itone(151) + real*8 dt,twopi,f0,baud,phi,dphi + + common/foxcom/wave(NWAVE) + + wave=0. + open(25,file=trim(fname),status='unknown',err=999) + read(25,'(20i4)',err=999,end=999) itone + close(25) + if(itone(1).lt.0 .or. itone(1).gt.128) go to 999 + +! Generate the SuperFox waveform. + + dt=1.d0/48000.d0 + twopi=8.d0*atan(1.d0) + f0=750.0d0 + phi=0.d0 + baud=12000.d0/NSPS + k=0 + do j=1,NN + f=f0 + baud*mod(itone(j),128) + dphi=twopi*f*dt + do ii=1,4*NSPS + k=k+1 + phi=phi+dphi + xphi=phi + wave(k)=sin(xphi) + enddo + enddo + +999 return +end subroutine sfox_wave diff --git a/lib/superfox/sfox_wave_gfsk.f90 b/lib/superfox/sfox_wave_gfsk.f90 index b2718723..b5b75b0a 100755 --- a/lib/superfox/sfox_wave_gfsk.f90 +++ b/lib/superfox/sfox_wave_gfsk.f90 @@ -1,77 +1,77 @@ -subroutine sfox_wave_gfsk() - -! Called by WSJT-X when it's time for SuperFox to transmit. Reads array -! itone(1:151) from disk file 'sfox_2.dat' in the writable data directory. -! Generates a GFSK waveform with short ramp-up and ramp-down symbols of -! duration NSPS/BT at the beginning and end of the waveform. - - parameter (NWAVE=(160+2)*134400*4) !Max WSJT-X waveform (FST4-1800 at 48kHz) - parameter (NSYM=151,NSPS=1024*4) - parameter (NPTS=(NSYM+2)*NSPS) - parameter (BT=8) - character*40 cmsg2 - integer itone(151) - real*8 dt,twopi,f0,phi,dphi_peak - real*8 dphi(0:NPTS-1) - real*8 pulse(3*NSPS) - logical first/.true./ - - common/foxcom/wave(NWAVE) - common/foxcom3/nslots2,cmsg2(5),itone3(151) - save first,twopi,dt,hmod,dphi_peak,pulse - - if(first) then - fsample=48000.0 - twopi=8.d0*atan(1.d0) - dt=1.d0/fsample - hmod=1.0 - dphi_peak=twopi*hmod/real(NSPS) - do i=1,3*NSPS - tt=(i-1.5*NSPS)/real(NSPS) - pulse(i)=gfsk_pulse(BT,tt) - enddo - first=.false. - endif - wave=0. - - itone=itone3 - if(itone(1).lt.0 .or. itone(1).gt.128) go to 999 - -! Generate the SuperFox waveform. - - dphi=0.d0 - do j=1,NSYM - ib=(j-1)*NSPS - ie=ib+3*NSPS-1 - dphi(ib:ie)=dphi(ib:ie)+dphi_peak*pulse(1:3*NSPS)*itone(j) - enddo - dphi(0:2*NSPS-1)=dphi(0:2*NSPS-1)+dphi_peak*itone(1)*pulse(NSPS+1:3*NSPS) - dphi(NSYM*NSPS:(NSYM+2)*NSPS-1)=dphi(NSYM*NSPS:(NSYM+2)*NSPS-1)+dphi_peak*itone(NSYM)*pulse(1:2*NSPS) - - phi=0.d0 - f0=750.0d0 - dphi=dphi+twopi*f0*dt - k=0 - do j=1,NSPS*(NSYM+2)-1 - k=k+1 - wave(k)=sin(phi) - phi=phi+dphi(j) - enddo - -! Add raised cosine ramps at the beginning and end of the waveform. -! Since the modulator expects an integral number of symbols, dummy -! symbols are added to the beginning and end of the waveform to -! hold the ramps. All but nramp of the samples in each dummy -! symbol will be zero. - - nramp=NSPS/BT - wave(1:NSPS-nramp)=0.0 - wave(NSPS-nramp+1:NSPS)=wave(NSPS-nramp+1:NSPS) * & - (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - k1=(NSYM+1)*NSPS+1 - wave(k1:k1+nramp-1)=wave(k1:k1+nramp-1) * & - (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - wave(k1+nramp:NPTS)=0.0 - -999 return -end subroutine sfox_wave_gfsk +subroutine sfox_wave_gfsk() + +! Called by WSJT-X when it's time for SuperFox to transmit. Reads array +! itone(1:151) from disk file 'sfox_2.dat' in the writable data directory. +! Generates a GFSK waveform with short ramp-up and ramp-down symbols of +! duration NSPS/BT at the beginning and end of the waveform. + + parameter (NWAVE=(160+2)*134400*4) !Max WSJT-X waveform (FST4-1800 at 48kHz) + parameter (NSYM=151,NSPS=1024*4) + parameter (NPTS=(NSYM+2)*NSPS) + parameter (BT=8) + character*40 cmsg2 + integer itone(151) + real*8 dt,twopi,f0,phi,dphi_peak + real*8 dphi(0:NPTS-1) + real*8 pulse(3*NSPS) + logical first/.true./ + + common/foxcom/wave(NWAVE) + common/foxcom3/nslots2,cmsg2(5),itone3(151) + save first,twopi,dt,hmod,dphi_peak,pulse + + if(first) then + fsample=48000.0 + twopi=8.d0*atan(1.d0) + dt=1.d0/fsample + hmod=1.0 + dphi_peak=twopi*hmod/real(NSPS) + do i=1,3*NSPS + tt=(i-1.5*NSPS)/real(NSPS) + pulse(i)=gfsk_pulse(BT,tt) + enddo + first=.false. + endif + wave=0. + + itone=itone3 + if(itone(1).lt.0 .or. itone(1).gt.128) go to 999 + +! Generate the SuperFox waveform. + + dphi=0.d0 + do j=1,NSYM + ib=(j-1)*NSPS + ie=ib+3*NSPS-1 + dphi(ib:ie)=dphi(ib:ie)+dphi_peak*pulse(1:3*NSPS)*itone(j) + enddo + dphi(0:2*NSPS-1)=dphi(0:2*NSPS-1)+dphi_peak*itone(1)*pulse(NSPS+1:3*NSPS) + dphi(NSYM*NSPS:(NSYM+2)*NSPS-1)=dphi(NSYM*NSPS:(NSYM+2)*NSPS-1)+dphi_peak*itone(NSYM)*pulse(1:2*NSPS) + + phi=0.d0 + f0=750.0d0 + dphi=dphi+twopi*f0*dt + k=0 + do j=1,NSPS*(NSYM+2)-1 + k=k+1 + wave(k)=sin(phi) + phi=phi+dphi(j) + enddo + +! Add raised cosine ramps at the beginning and end of the waveform. +! Since the modulator expects an integral number of symbols, dummy +! symbols are added to the beginning and end of the waveform to +! hold the ramps. All but nramp of the samples in each dummy +! symbol will be zero. + + nramp=NSPS/BT + wave(1:NSPS-nramp)=0.0 + wave(NSPS-nramp+1:NSPS)=wave(NSPS-nramp+1:NSPS) * & + (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + k1=(NSYM+1)*NSPS+1 + wave(k1:k1+nramp-1)=wave(k1:k1+nramp-1) * & + (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + wave(k1+nramp:NPTS)=0.0 + +999 return +end subroutine sfox_wave_gfsk diff --git a/lib/superfox/sfoxsim.f90 b/lib/superfox/sfoxsim.f90 index 8dac07a8..86f7019e 100755 --- a/lib/superfox/sfoxsim.f90 +++ b/lib/superfox/sfoxsim.f90 @@ -1,164 +1,164 @@ -program sfoxsim - -! - Generate complex-valued SuperFox waveform, cdat. -! - Pass cdat through Watterson channel simulator -! - Add noise to the imaginary part of cdat and write to wav file. - - use wavhdr - use qpc_mod - use sfox_mod - - type(hdr) h !Header for .wav file - logical*1 bMoreCQs !Include a CQ when space available? - logical*1 bSendMsg !Send a Free text message - integer*2 iwave(NMAX) !Generated i*2 waveform - integer isync(24) !Indices of sync symbols - integer itone(151) !Symbol values, data and sync - integer*1 xin(0:49) - integer*1 y(0:127) - real*4 xnoise(NMAX) !Random noise - real*4 dat(NMAX) !Generated real data - complex cdat(NMAX) !Generated complex waveform - complex crcvd(NMAX) !Signal as received - real, allocatable :: s3(:,:) !Symbol spectra: will be s3(NQ,NN) - integer, allocatable :: msg0(:) !Information symbols - integer, allocatable :: chansym(:) !Encoded data, 7-bit integers - character fname*17,arg*12,channel*2,foxcall*11 - character*10 ckey - character*26 text_msg - character*120 line !SuperFox message pieces - character*40 cmsg(5) - data ckey/'0000000000'/ - data cmsg/'W0AAA RR73; W5FFF -18', & - 'W1BBB RR73; W6GGG -15', & - 'W2CCC RR73; W7HHH -12', & - 'W3DDD RR73; W8III -09', & - 'W4EEE RR73; W9JJJ -06'/ - data text_msg/'0123456789ABCDEFGHIJKLMNOP'/ - data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80, & - 83,84,86,89/ - - nargs=iargc() - if(nargs.ne.10) then - print*,'Usage: sfoxsim f0 DT Chan FoxC H1 H2 CQ FT nfiles snr' - print*,'Example: sfoxsim 750 0.0 MM K1JT 5 1 0 0 10 -15' - print*,' f0=0 to dither f0 and DT' - print*,' Chan Channel type AW LQ LM LD MQ MM MD HQ HM HD' - print*,' FoxC Fox callsign' - print*,' key' - print*,' H1 number of Hound calls with RR73' - print*,' H2 number of Hound calls with reports' - print*,' CQ=1 to include a CQ message' - print*,' FT=1 to include a Free Text message' - go to 999 - endif - call getarg(1,arg) - read(arg,*) f0 - call getarg(2,arg) - read(arg,*) xdt - call getarg(3,channel) - call getarg(4,foxcall) - call getarg(5,arg) - read(arg,*) nh1 - call getarg(6,arg) - read(arg,*) nh2 - call getarg(7,arg) - read(arg,*) ncq - bMoreCQs=ncq.ne.0 - call getarg(8,arg) - read(arg,*) nft - bSendMsg=nft.ne.0 - call getarg(9,arg) - read(arg,*) nfiles - call getarg(10,arg) - read(arg,*) snr - - fspread=0.0 - delay=0.0 - fsample=12000.0 !Sample rate (Hz) - call sfox_init(7,127,50,channel,fspread,delay,fsample,24) - txt=(NN+NS)*NSPS/fsample - write(*,1000) f0,xdt,channel,snr -1000 format('sfoxsim: f0= ',f5.1,' dt= ',f4.2,' Channel: ',a2,' snr: ',f5.1,' dB') - -! Allocate storage for arrays that depend on code parameters. - allocate(s3(0:NQ-1,0:NN-1)) - allocate(msg0(1:KK)) - allocate(chansym(0:NN-1)) - - if(nft.ne.0) then - open(10,file='text_msg.txt',status='old',err=2) - read(10,*) text_msg - endif - -2 idum=-1 - rms=100. - baud=fsample/nsps !Keying rate, 11.719 baud for nsps=1024 - bandwidth_ratio=2500.0/fsample - do i=1,5 - cmsg(i)=cmsg(i)(1:19)//trim(foxcall)//cmsg(i)(24:28) - if(i.gt.nh1 .and. i.gt.nh2) then - cmsg(i)='' - elseif(i.gt.nh1) then - cmsg(i)=cmsg(i)(13:18)//trim(foxcall)//cmsg(i)(25:28) - elseif(i.gt.nh2) then - cmsg(i)=cmsg(i)(1:6)//trim(foxcall)//' RR73' - endif -! write(*,*) 'Debug ',cmsg(i) - enddo - - if((nh1+nh2).eq.0 .and. bMoreCQs) cmsg(1)='CQ '//trim(foxcall)//' FN20' - -! Generate a SuperFox message - nslots=5 - call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages - call sfox_pack(line,ckey,bMoreCQs,bSendMsg,text_msg,xin) - call qpc_encode(y,xin) - - y=cshift(y,1) - y(127)=0 - chansym=y(0:126) - - sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snr) - sigr=sqrt(2.)*sig - if(snr.gt.90.0) sig=1.0 - - do ifile=1,nfiles - xnoise=0. - if(snr.lt.90) then - do i=1,NMAX - xnoise(i)=gran() !Gaussian noise - enddo - endif - - f1=f0 - if(f0.eq.0.0) then - f1=750 + 20.0*(ran1(idum)-0.5) - xdt=ran1(idum)-0.5 - endif -! Generate cdat, the SuperFox waveform - call sfox_gen_gfsk(chansym,f1,isync,itone,cdat) - - crcvd=0. - crcvd(1:NMAX)=cshift(cdat(1:NMAX),-nint((0.5+xdt)*fsample)) - if(fspread.ne.0 .or. delay.ne.0) call watterson(crcvd,NMAX,NZ,fsample,& - delay,fspread) - - dat=aimag(sigr*crcvd(1:NMAX)) + xnoise !Add generated AWGN noise - fac=32767.0 - if(snr.ge.90.0) iwave(1:NMAX)=nint(fac*dat(1:NMAX)) - if(snr.lt.90.0) iwave(1:NMAX)=nint(rms*dat(1:NMAX)) - - h=default_header(12000,NMAX) - fname='000000_000001.wav' - nsec=(ifile-1)*30 - nhr=nsec/3600 - nmin=(nsec-nhr*3600)/60 - nsec=mod(nsec,60) - write(fname(8:13),'(3i2.2)') nhr,nmin,nsec - open(10,file=trim(fname),access='stream',status='unknown') - write(10) h,iwave(1:NMAX) !Save the .wav file - close(10) - enddo ! ifile - -999 end program sfoxsim +program sfoxsim + +! - Generate complex-valued SuperFox waveform, cdat. +! - Pass cdat through Watterson channel simulator +! - Add noise to the imaginary part of cdat and write to wav file. + + use wavhdr + use qpc_mod + use sfox_mod + + type(hdr) h !Header for .wav file + logical*1 bMoreCQs !Include a CQ when space available? + logical*1 bSendMsg !Send a Free text message + integer*2 iwave(NMAX) !Generated i*2 waveform + integer isync(24) !Indices of sync symbols + integer itone(151) !Symbol values, data and sync + integer*1 xin(0:49) + integer*1 y(0:127) + real*4 xnoise(NMAX) !Random noise + real*4 dat(NMAX) !Generated real data + complex cdat(NMAX) !Generated complex waveform + complex crcvd(NMAX) !Signal as received + real, allocatable :: s3(:,:) !Symbol spectra: will be s3(NQ,NN) + integer, allocatable :: msg0(:) !Information symbols + integer, allocatable :: chansym(:) !Encoded data, 7-bit integers + character fname*17,arg*12,channel*2,foxcall*11 + character*10 ckey + character*26 text_msg + character*120 line !SuperFox message pieces + character*40 cmsg(5) + data ckey/'0000000000'/ + data cmsg/'W0AAA RR73; W5FFF -18', & + 'W1BBB RR73; W6GGG -15', & + 'W2CCC RR73; W7HHH -12', & + 'W3DDD RR73; W8III -09', & + 'W4EEE RR73; W9JJJ -06'/ + data text_msg/'0123456789ABCDEFGHIJKLMNOP'/ + data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80, & + 83,84,86,89/ + + nargs=iargc() + if(nargs.ne.10) then + print*,'Usage: sfoxsim f0 DT Chan FoxC H1 H2 CQ FT nfiles snr' + print*,'Example: sfoxsim 750 0.0 MM K1JT 5 1 0 0 10 -15' + print*,' f0=0 to dither f0 and DT' + print*,' Chan Channel type AW LQ LM LD MQ MM MD HQ HM HD' + print*,' FoxC Fox callsign' + print*,' key' + print*,' H1 number of Hound calls with RR73' + print*,' H2 number of Hound calls with reports' + print*,' CQ=1 to include a CQ message' + print*,' FT=1 to include a Free Text message' + go to 999 + endif + call getarg(1,arg) + read(arg,*) f0 + call getarg(2,arg) + read(arg,*) xdt + call getarg(3,channel) + call getarg(4,foxcall) + call getarg(5,arg) + read(arg,*) nh1 + call getarg(6,arg) + read(arg,*) nh2 + call getarg(7,arg) + read(arg,*) ncq + bMoreCQs=ncq.ne.0 + call getarg(8,arg) + read(arg,*) nft + bSendMsg=nft.ne.0 + call getarg(9,arg) + read(arg,*) nfiles + call getarg(10,arg) + read(arg,*) snr + + fspread=0.0 + delay=0.0 + fsample=12000.0 !Sample rate (Hz) + call sfox_init(7,127,50,channel,fspread,delay,fsample,24) + txt=(NN+NS)*NSPS/fsample + write(*,1000) f0,xdt,channel,snr +1000 format('sfoxsim: f0= ',f5.1,' dt= ',f4.2,' Channel: ',a2,' snr: ',f5.1,' dB') + +! Allocate storage for arrays that depend on code parameters. + allocate(s3(0:NQ-1,0:NN-1)) + allocate(msg0(1:KK)) + allocate(chansym(0:NN-1)) + + if(nft.ne.0) then + open(10,file='text_msg.txt',status='old',err=2) + read(10,*) text_msg + endif + +2 idum=-1 + rms=100. + baud=fsample/nsps !Keying rate, 11.719 baud for nsps=1024 + bandwidth_ratio=2500.0/fsample + do i=1,5 + cmsg(i)=cmsg(i)(1:19)//trim(foxcall)//cmsg(i)(24:28) + if(i.gt.nh1 .and. i.gt.nh2) then + cmsg(i)='' + elseif(i.gt.nh1) then + cmsg(i)=cmsg(i)(13:18)//trim(foxcall)//cmsg(i)(25:28) + elseif(i.gt.nh2) then + cmsg(i)=cmsg(i)(1:6)//trim(foxcall)//' RR73' + endif +! write(*,*) 'Debug ',cmsg(i) + enddo + + if((nh1+nh2).eq.0 .and. bMoreCQs) cmsg(1)='CQ '//trim(foxcall)//' FN20' + +! Generate a SuperFox message + nslots=5 + call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages + call sfox_pack(line,ckey,bMoreCQs,bSendMsg,text_msg,xin) + call qpc_encode(y,xin) + + y=cshift(y,1) + y(127)=0 + chansym=y(0:126) + + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snr) + sigr=sqrt(2.)*sig + if(snr.gt.90.0) sig=1.0 + + do ifile=1,nfiles + xnoise=0. + if(snr.lt.90) then + do i=1,NMAX + xnoise(i)=gran() !Gaussian noise + enddo + endif + + f1=f0 + if(f0.eq.0.0) then + f1=750 + 20.0*(ran1(idum)-0.5) + xdt=ran1(idum)-0.5 + endif +! Generate cdat, the SuperFox waveform + call sfox_gen_gfsk(chansym,f1,isync,itone,cdat) + + crcvd=0. + crcvd(1:NMAX)=cshift(cdat(1:NMAX),-nint((0.5+xdt)*fsample)) + if(fspread.ne.0 .or. delay.ne.0) call watterson(crcvd,NMAX,NZ,fsample,& + delay,fspread) + + dat=aimag(sigr*crcvd(1:NMAX)) + xnoise !Add generated AWGN noise + fac=32767.0 + if(snr.ge.90.0) iwave(1:NMAX)=nint(fac*dat(1:NMAX)) + if(snr.lt.90.0) iwave(1:NMAX)=nint(rms*dat(1:NMAX)) + + h=default_header(12000,NMAX) + fname='000000_000001.wav' + nsec=(ifile-1)*30 + nhr=nsec/3600 + nmin=(nsec-nhr*3600)/60 + nsec=mod(nsec,60) + write(fname(8:13),'(3i2.2)') nhr,nmin,nsec + open(10,file=trim(fname),access='stream',status='unknown') + write(10) h,iwave(1:NMAX) !Save the .wav file + close(10) + enddo ! ifile + +999 end program sfoxsim diff --git a/lib/superfox/sfrx.f90 b/lib/superfox/sfrx.f90 index 51c71f93..86c9e793 100755 --- a/lib/superfox/sfrx.f90 +++ b/lib/superfox/sfrx.f90 @@ -1,59 +1,59 @@ -program sfrx - -! Command-line SuperFox decoder - - use sfox_mod - use julian - - integer*2 iwave(NMAX) - integer ihdr(11) - character*120 fname - include 'gtag.f90' - - narg=iargc() - - if(narg.lt.1) then - print*,'Usage: sfrx fsync ftol infile [...]' - print*,' sfrx 775 10 240811_102400.wav' - print*,'Reads one or more .wav files and calls SuperFox decoder on each.' - print '(" Git tag: ",z9)',ntag - go to 999 - endif - - call getarg(1,fname) - read(fname,*,err=1) fsync - call getarg(2,fname) - read(fname,*,err=1) ftol - - nfqso=nint(fsync) - ntol=nint(ftol) - -1 nf=0 - nd=0 - nv=0 - - do ifile=3,narg - call getarg(ifile,fname) - write(72,*) ifile,narg,fname - open(10,file=trim(fname),status='old',access='stream',err=4) - - go to 5 -4 print*,'Cannot open file ',trim(fname) - go to 999 -5 read(10) ihdr,iwave - close(10) - - nz=len(trim(fname)) - nyymmdd=ihdr(1) - nutc=ihdr(2) - if(fname(nz-3:nz).eq.'.wav') then - read(fname(nz-16:nz-11),*) nyymmdd - read(fname(nz-9:nz-4),*) nutc - endif - - call sfrx_sub(nyymmdd,nutc,nfqso,ntol,iwave) - - nf=nf+1 - enddo - -999 end program sfrx +program sfrx + +! Command-line SuperFox decoder + + use sfox_mod + use julian + + integer*2 iwave(NMAX) + integer ihdr(11) + character*120 fname + include 'gtag.f90' + + narg=iargc() + + if(narg.lt.1) then + print*,'Usage: sfrx fsync ftol infile [...]' + print*,' sfrx 775 10 240811_102400.wav' + print*,'Reads one or more .wav files and calls SuperFox decoder on each.' + print '(" Git tag: ",z9)',ntag + go to 999 + endif + + call getarg(1,fname) + read(fname,*,err=1) fsync + call getarg(2,fname) + read(fname,*,err=1) ftol + + nfqso=nint(fsync) + ntol=nint(ftol) + +1 nf=0 + nd=0 + nv=0 + + do ifile=3,narg + call getarg(ifile,fname) + write(72,*) ifile,narg,fname + open(10,file=trim(fname),status='old',access='stream',err=4) + + go to 5 +4 print*,'Cannot open file ',trim(fname) + go to 999 +5 read(10) ihdr,iwave + close(10) + + nz=len(trim(fname)) + nyymmdd=ihdr(1) + nutc=ihdr(2) + if(fname(nz-3:nz).eq.'.wav') then + read(fname(nz-16:nz-11),*) nyymmdd + read(fname(nz-9:nz-4),*) nutc + endif + + call sfrx_sub(nyymmdd,nutc,nfqso,ntol,iwave) + + nf=nf+1 + enddo + +999 end program sfrx diff --git a/lib/superfox/sfrx_sub.f90 b/lib/superfox/sfrx_sub.f90 index 1168610a..12a48e08 100755 --- a/lib/superfox/sfrx_sub.f90 +++ b/lib/superfox/sfrx_sub.f90 @@ -1,54 +1,54 @@ -subroutine sfrx_sub(nyymmdd,nutc,nfqso,ntol,iwave) - - use sfox_mod - use julian - - integer*2 iwave(NMAX) - integer*8 secday,ntime8 - integer*1 xdec(0:49) - character*13 foxcall - complex c0(NMAX) !Complex form of signal as received - real dd(NMAX) - logical crc_ok - data secday/86400/ - - fsync=nfqso - ftol=ntol - fsample=12000.0 - call sfox_init(7,127,50,'no',fspread,delay,fsample,24) - npts=15*12000 - - if(nyymmdd.eq.-1) then - ntime8=itime8()/30 - ntime8=30*ntime8 - else - iyr=2000+nyymmdd/10000 - imo=mod(nyymmdd/100,100) - iday=mod(nyymmdd,100) - ih=nutc/10000 - im=mod(nutc/100,100) - is=mod(nutc,100) - ntime8=secday*(JD(iyr,imo,iday)-2440588) + 3600*ih + 60*im + is - endif - - dd=iwave - call sfox_remove_ft8(dd,npts) - - call sfox_ana(dd,npts,c0,npts) - - call sfox_remove_tone(c0,fsync) ! Needs testing - - ndepth=3 - dth=0.5 - damp=1.0 - - call qpc_decode2(c0,fsync,ftol, xdec,ndepth,dth,damp,crc_ok, & - snrsync,fbest,tbest,snr) - if(crc_ok) then - nsnr=nint(snr) - nsignature = 1 - call sfox_unpack(nutc,xdec,nsnr,fbest-750.0,tbest,foxcall,nsignature) - endif - - return -end subroutine sfrx_sub +subroutine sfrx_sub(nyymmdd,nutc,nfqso,ntol,iwave) + + use sfox_mod + use julian + + integer*2 iwave(NMAX) + integer*8 secday,ntime8 + integer*1 xdec(0:49) + character*13 foxcall + complex c0(NMAX) !Complex form of signal as received + real dd(NMAX) + logical crc_ok + data secday/86400/ + + fsync=nfqso + ftol=ntol + fsample=12000.0 + call sfox_init(7,127,50,'no',fspread,delay,fsample,24) + npts=15*12000 + + if(nyymmdd.eq.-1) then + ntime8=itime8()/30 + ntime8=30*ntime8 + else + iyr=2000+nyymmdd/10000 + imo=mod(nyymmdd/100,100) + iday=mod(nyymmdd,100) + ih=nutc/10000 + im=mod(nutc/100,100) + is=mod(nutc,100) + ntime8=secday*(JD(iyr,imo,iday)-2440588) + 3600*ih + 60*im + is + endif + + dd=iwave + call sfox_remove_ft8(dd,npts) + + call sfox_ana(dd,npts,c0,npts) + + call sfox_remove_tone(c0,fsync) ! Needs testing + + ndepth=3 + dth=0.5 + damp=1.0 + + call qpc_decode2(c0,fsync,ftol, xdec,ndepth,dth,damp,crc_ok, & + snrsync,fbest,tbest,snr) + if(crc_ok) then + nsnr=nint(snr) + nsignature = 1 + call sfox_unpack(nutc,xdec,nsnr,fbest-750.0,tbest,foxcall,nsignature) + endif + + return +end subroutine sfrx_sub diff --git a/lib/superfox/sftx.f90 b/lib/superfox/sftx.f90 index d2ca7792..78b5ca15 100755 --- a/lib/superfox/sftx.f90 +++ b/lib/superfox/sftx.f90 @@ -1,107 +1,107 @@ -program sftx - -! This program is required in order to create a SuperFox transmission. - -! The present version goes through the following steps: -! 1. Read old-style Fox messages from file 'sfox_1.dat' in the WSJT-X -! writable data directory. -! 2. Parse up to NSlots=5 messages to extract MyCall, up to 9 Hound -! calls, and the report or RR73 to be sent to each Hound. -! 3. Assemble and encode a single SuperFox message to produce itone(1:151), -! the array of channel symbol values. -! 4. Write the contents of array itone to file 'sfox_2.dat'. - - use qpc_mod - use sfox_mod - character*120 fname !Corrected path for sfox_1.dat - character*120 line !List of SuperFox message pieces - character*40 cmsg(5) !Old-style Fox messages - character*26 freeTextMsg - character*2 arg - character*10 ckey -! character*9 foxkey - character*11 foxcall0,foxcall - logical*1 bMoreCQs,bSendMsg - logical crc_ok - real py(0:127,0:127) !Probabilities for received synbol values - integer*8 n47 - integer itone(151) !SuperFox channel-symbol values - integer*1 xin(0:49) !Packed message as 7-bit symbols - integer*1 xdec(0:49) !Decoded message - integer*1 y(0:127) !Encoded symbols as i*1 integers - integer*1 ydec(0:127) !Decoded codeword - integer*1 yy(0:10) - integer chansym0(127) !Transmitted symbols, data only - integer chansym(127) !Received symbols, data only - integer isync(24) !Symbol numbers for sync tones - data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80, & - 83,84,86,89/ - include 'gtag.f90' - - narg=iargc() - if(narg.ne.3) then - print '(" Git tag: ",z9)',ntag - go to 999 - endif - -! sftx - call getarg(1,fname) - do i=1,len(trim(fname)) - if(fname(i:i).eq.'\\') fname(i:i)='/' - enddo - call getarg(2,foxcall0) - call getarg(3,ckey) - -! if((foxkey(foxcall0).ne.ckey).and.(INDEX(ckey,'OTP:').eq.0)) then ! neither kind -! itone=-99 -! go to 100 -! endif - - fsample=12000.0 - call sfox_init(7,127,50,'no',fspread,delay,fsample,24) - open(25,file=trim(fname),status='unknown') - do i=1,5 - read(25,1000,end=10) cmsg(i) -1000 format(a40) - enddo - i=6 -10 close(25) - nslots=i-1 - freeTextMsg=' ' - bMoreCQs=cmsg(1)(40:40).eq.'1' - bSendMsg=cmsg(nslots)(39:39).eq.'1' - if(bSendMsg) then - freeTextMsg=cmsg(nslots)(1:26) - if(nslots.gt.2) nslots=2 - endif - - call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages - -! Pack message information and CRC into xin(0:49) - call sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) - call qpc_encode(y,xin) !Encode the message to 128 symbols - y=cshift(y,1) !Puncture the code by removing y(0) - y(127)=0 - chansym0=y(0:126) - -! Create the full itone sequence containing both data and sync symbols - j=1 - k=0 - do i=1,NDS - if(j.le.NS .and. i.eq.isync(j)) then - if(j.lt.NS) j=j+1 !Index for next sync symbol - itone(i)=0 !Insert sync symbol at tone 0 - else - k=k+1 - itone(i)=chansym0(k) + 1 !Symbol value 0 transmitted as tone 1, etc. - endif - enddo - -100 i1=max(index(fname,'sfox_1'),1) - fname(i1:i1+9)='sfox_2.dat' - open(25,file=trim(fname),status='unknown') - write(25,1100) itone -1100 format(20i4) - close(25) - -999 end program sftx +program sftx + +! This program is required in order to create a SuperFox transmission. + +! The present version goes through the following steps: +! 1. Read old-style Fox messages from file 'sfox_1.dat' in the WSJT-X +! writable data directory. +! 2. Parse up to NSlots=5 messages to extract MyCall, up to 9 Hound +! calls, and the report or RR73 to be sent to each Hound. +! 3. Assemble and encode a single SuperFox message to produce itone(1:151), +! the array of channel symbol values. +! 4. Write the contents of array itone to file 'sfox_2.dat'. + + use qpc_mod + use sfox_mod + character*120 fname !Corrected path for sfox_1.dat + character*120 line !List of SuperFox message pieces + character*40 cmsg(5) !Old-style Fox messages + character*26 freeTextMsg + character*2 arg + character*10 ckey +! character*9 foxkey + character*11 foxcall0,foxcall + logical*1 bMoreCQs,bSendMsg + logical crc_ok + real py(0:127,0:127) !Probabilities for received synbol values + integer*8 n47 + integer itone(151) !SuperFox channel-symbol values + integer*1 xin(0:49) !Packed message as 7-bit symbols + integer*1 xdec(0:49) !Decoded message + integer*1 y(0:127) !Encoded symbols as i*1 integers + integer*1 ydec(0:127) !Decoded codeword + integer*1 yy(0:10) + integer chansym0(127) !Transmitted symbols, data only + integer chansym(127) !Received symbols, data only + integer isync(24) !Symbol numbers for sync tones + data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80, & + 83,84,86,89/ + include 'gtag.f90' + + narg=iargc() + if(narg.ne.3) then + print '(" Git tag: ",z9)',ntag + go to 999 + endif + +! sftx + call getarg(1,fname) + do i=1,len(trim(fname)) + if(fname(i:i).eq.'\\') fname(i:i)='/' + enddo + call getarg(2,foxcall0) + call getarg(3,ckey) + +! if((foxkey(foxcall0).ne.ckey).and.(INDEX(ckey,'OTP:').eq.0)) then ! neither kind +! itone=-99 +! go to 100 +! endif + + fsample=12000.0 + call sfox_init(7,127,50,'no',fspread,delay,fsample,24) + open(25,file=trim(fname),status='unknown') + do i=1,5 + read(25,1000,end=10) cmsg(i) +1000 format(a40) + enddo + i=6 +10 close(25) + nslots=i-1 + freeTextMsg=' ' + bMoreCQs=cmsg(1)(40:40).eq.'1' + bSendMsg=cmsg(nslots)(39:39).eq.'1' + if(bSendMsg) then + freeTextMsg=cmsg(nslots)(1:26) + if(nslots.gt.2) nslots=2 + endif + + call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages + +! Pack message information and CRC into xin(0:49) + call sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) + call qpc_encode(y,xin) !Encode the message to 128 symbols + y=cshift(y,1) !Puncture the code by removing y(0) + y(127)=0 + chansym0=y(0:126) + +! Create the full itone sequence containing both data and sync symbols + j=1 + k=0 + do i=1,NDS + if(j.le.NS .and. i.eq.isync(j)) then + if(j.lt.NS) j=j+1 !Index for next sync symbol + itone(i)=0 !Insert sync symbol at tone 0 + else + k=k+1 + itone(i)=chansym0(k) + 1 !Symbol value 0 transmitted as tone 1, etc. + endif + enddo + +100 i1=max(index(fname,'sfox_1'),1) + fname(i1:i1+9)='sfox_2.dat' + open(25,file=trim(fname),status='unknown') + write(25,1100) itone +1100 format(20i4) + close(25) + +999 end program sftx diff --git a/lib/superfox/sftx_sub.f90 b/lib/superfox/sftx_sub.f90 index 138b4855..ed6c678c 100755 --- a/lib/superfox/sftx_sub.f90 +++ b/lib/superfox/sftx_sub.f90 @@ -1,65 +1,65 @@ -subroutine sftx_sub(ckey0) - -! This routine is required in order to create a SuperFox transmission. - -! The present version goes through the following steps: -! 1. Read old-style Fox messages from file 'sfox_1.dat' in the WSJT-X -! writable data directory. -! 2. Parse up to NSlots=5 messages to extract MyCall, up to 9 Hound -! calls, and the report or RR73 to be sent to each Hound. -! 3. Assemble and encode a single SuperFox message to produce itone(1:151), -! the array of channel symbol values. -! 4. Write the contents of array itone to file 'sfox_2.dat'. - - use qpc_mod - use sfox_mod - character*120 line !List of SuperFox message pieces - character*40 cmsg !Old-style Fox messages - character*26 freeTextMsg - character*(*) ckey0 - character*10 ckey - character*11 foxcall - logical*1 bMoreCQs,bSendMsg - integer*1 xin(0:49) !Packed message as 7-bit symbols - integer*1 y(0:127) !Encoded symbols as i*1 integers - integer chansym0(127) !Transmitted symbols, data only - integer isync(24) !Symbol numbers for sync tones - common/foxcom3/nslots,cmsg(5),itone(151) - data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80, & - 83,84,86,89/ - - ckey=ckey0 - - fsample=12000.0 - call sfox_init(7,127,50,'no',fspread,delay,fsample,24) - freeTextMsg=' ' - bMoreCQs=cmsg(1)(40:40).eq.'1' - bSendMsg=cmsg(nslots)(39:39).eq.'1' - if(bSendMsg) then - freeTextMsg=cmsg(nslots)(1:26) - if(nslots.gt.4) nslots=4 - endif - - call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages - -! Pack message information and CRC into xin(0:49) - call sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) - call qpc_encode(y,xin) !Encode the message to 128 symbols - y=cshift(y,1) !Puncture the code by removing y(0) - y(127)=0 - chansym0=y(0:126) - -! Create the full itone sequence containing both data and sync symbols - j=1 - k=0 - do i=1,NDS - if(j.le.NS .and. i.eq.isync(j)) then - if(j.lt.NS) j=j+1 !Index for next sync symbol - itone(i)=0 !Insert sync symbol at tone 0 - else - k=k+1 - itone(i)=chansym0(k) + 1 !Symbol value 0 transmitted as tone 1, etc. - endif - enddo - -end subroutine sftx_sub +subroutine sftx_sub(ckey0) + +! This routine is required in order to create a SuperFox transmission. + +! The present version goes through the following steps: +! 1. Read old-style Fox messages from file 'sfox_1.dat' in the WSJT-X +! writable data directory. +! 2. Parse up to NSlots=5 messages to extract MyCall, up to 9 Hound +! calls, and the report or RR73 to be sent to each Hound. +! 3. Assemble and encode a single SuperFox message to produce itone(1:151), +! the array of channel symbol values. +! 4. Write the contents of array itone to file 'sfox_2.dat'. + + use qpc_mod + use sfox_mod + character*120 line !List of SuperFox message pieces + character*40 cmsg !Old-style Fox messages + character*26 freeTextMsg + character*(*) ckey0 + character*10 ckey + character*11 foxcall + logical*1 bMoreCQs,bSendMsg + integer*1 xin(0:49) !Packed message as 7-bit symbols + integer*1 y(0:127) !Encoded symbols as i*1 integers + integer chansym0(127) !Transmitted symbols, data only + integer isync(24) !Symbol numbers for sync tones + common/foxcom3/nslots,cmsg(5),itone(151) + data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80, & + 83,84,86,89/ + + ckey=ckey0 + + fsample=12000.0 + call sfox_init(7,127,50,'no',fspread,delay,fsample,24) + freeTextMsg=' ' + bMoreCQs=cmsg(1)(40:40).eq.'1' + bSendMsg=cmsg(nslots)(39:39).eq.'1' + if(bSendMsg) then + freeTextMsg=cmsg(nslots)(1:26) + if(nslots.gt.4) nslots=4 + endif + + call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages + +! Pack message information and CRC into xin(0:49) + call sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) + call qpc_encode(y,xin) !Encode the message to 128 symbols + y=cshift(y,1) !Puncture the code by removing y(0) + y(127)=0 + chansym0=y(0:126) + +! Create the full itone sequence containing both data and sync symbols + j=1 + k=0 + do i=1,NDS + if(j.le.NS .and. i.eq.isync(j)) then + if(j.lt.NS) j=j+1 !Index for next sync symbol + itone(i)=0 !Insert sync symbol at tone 0 + else + k=k+1 + itone(i)=chansym0(k) + 1 !Symbol value 0 transmitted as tone 1, etc. + endif + enddo + +end subroutine sftx_sub diff --git a/lib/superfox/superfox_qpc_2.txt b/lib/superfox/superfox_qpc_2.txt index 98c0da79..f89bffe1 100755 --- a/lib/superfox/superfox_qpc_2.txt +++ b/lib/superfox/superfox_qpc_2.txt @@ -1,66 +1,66 @@ - Bit packing of SuperFox QPC Messages ------------------------------------------------------------------------------ -The IV3NWV Q-ary Polar Code has parameters (n,k) = (127,50). The last -three 7-bit information symbols convey a 21-bit CRC based on the first -47 symbols. Thus, each Super Fox transmission carries a payload of -47*7=329 bits. On a modern x86 processor the decoder executes in -deterministic time around 5 ms per decode, and always produces a -result. The CRC test rejects all but around 1 in two million false -decodes. - -Bit fields are labeled with tags as defined in the QEX article "The -FT4 and FT8 Communication Protocols" by Franke, Somerville, and Taylor -in QEX for July/August 2020, available on the WSJT web site here: -https://wsjt.sourceforge.io/FT4_FT8_QEX.pdf. As one example, the tag -'c28' denotes a standard callsign, which requires 28 bits. - -============================================================================= -i3 = 0: Standard message: FoxCall, up to 9 HoundCalls, up to 4 signal -reports, "MoreCQs" flag, a digital signature, and a 3-bit message type. ------------------------------------------------------------------------------ - F H1 H2 H3 H4 H5 H6 H7 H8 H9 R6 R7 R8 R9 U Q D M Type -c28 c28 c28 c28 c28 c28 c28 c28 c28 c28 r5 r5 r5 r5 u5 q1 d20 i3=0 Std Msg - 280 300 305 326 329 -============================================================================= -i3 = 1: If Fox uses a compound callsign we have space for only 8 Hound calls. -Otherwise like type i3=0. ------------------------------------------------------------------------------ - FC H1 H2 H2 H4 H5 H6 H7 H8 R5 R6 R7 R8 U Q D M -c58 c28 c28 c28 c28 c28 c28 c28 c28 r5 r5 r5 r5 u3 q1 d20 i3=1 - 58 282 302 305 326 329 -============================================================================= -i3 = 2: A free text message with up to 26 characters can be transmitted along -with messages to as many as 4 Hounds conveying either reports or RR73s. ------------------------------------------------------------------------------ - F H1 H2 H3 H4 R1 R2 R3 R4 T T U Q D M Type -c28 c28 c28 c28 c28 r5 r5 r5 r5 t71 t71 u3 q1 d20 i3=2 FT+4H - 140 160 302 305 326 329 -============================================================================= -i3 = 3: Message "CQ FoxCall Grid " ------------------------------------------------------------------------------ - FC G T T U Q D M Type -c58 g15 t71 t71 u90 q1 d20 i3=3 CQ FT - 58 73 144 215 305 326 329 -============================================================================= - -D Digital signature (20 bits) -F Fox call (28 bits) -FC Compound Fox call (58 bits) -G Grid locator (15 bits) -H Hound call (28 bits) -M Message type (3 bits) -Q MoreCQs flag -R Report, (5 bits: -18 to +12 dB, or RR73) -T Free text, up to 26 characters total -U Unused bits - -Unused callsign slots are set to the numerical value for "QU1RKS", and -ignored when received. Similarly for unused t71 slots. Unused report -slots are set to 0 (-20 dB). "CQ FoxCall" will be displayed along -with other messages if the "q1" bit is 1. - -The SuperFox decoder displays its results with a separate line for each Hound. -Thus, the old-style message "K1ABC RR73; W9XYZ -14" becomes - -K1ABC VP8PJ RR73 -W9XYZ VP8PJ -14 + Bit packing of SuperFox QPC Messages +----------------------------------------------------------------------------- +The IV3NWV Q-ary Polar Code has parameters (n,k) = (127,50). The last +three 7-bit information symbols convey a 21-bit CRC based on the first +47 symbols. Thus, each Super Fox transmission carries a payload of +47*7=329 bits. On a modern x86 processor the decoder executes in +deterministic time around 5 ms per decode, and always produces a +result. The CRC test rejects all but around 1 in two million false +decodes. + +Bit fields are labeled with tags as defined in the QEX article "The +FT4 and FT8 Communication Protocols" by Franke, Somerville, and Taylor +in QEX for July/August 2020, available on the WSJT web site here: +https://wsjt.sourceforge.io/FT4_FT8_QEX.pdf. As one example, the tag +'c28' denotes a standard callsign, which requires 28 bits. + +============================================================================= +i3 = 0: Standard message: FoxCall, up to 9 HoundCalls, up to 4 signal +reports, "MoreCQs" flag, a digital signature, and a 3-bit message type. +----------------------------------------------------------------------------- + F H1 H2 H3 H4 H5 H6 H7 H8 H9 R6 R7 R8 R9 U Q D M Type +c28 c28 c28 c28 c28 c28 c28 c28 c28 c28 r5 r5 r5 r5 u5 q1 d20 i3=0 Std Msg + 280 300 305 326 329 +============================================================================= +i3 = 1: If Fox uses a compound callsign we have space for only 8 Hound calls. +Otherwise like type i3=0. +----------------------------------------------------------------------------- + FC H1 H2 H2 H4 H5 H6 H7 H8 R5 R6 R7 R8 U Q D M +c58 c28 c28 c28 c28 c28 c28 c28 c28 r5 r5 r5 r5 u3 q1 d20 i3=1 + 58 282 302 305 326 329 +============================================================================= +i3 = 2: A free text message with up to 26 characters can be transmitted along +with messages to as many as 4 Hounds conveying either reports or RR73s. +----------------------------------------------------------------------------- + F H1 H2 H3 H4 R1 R2 R3 R4 T T U Q D M Type +c28 c28 c28 c28 c28 r5 r5 r5 r5 t71 t71 u3 q1 d20 i3=2 FT+4H + 140 160 302 305 326 329 +============================================================================= +i3 = 3: Message "CQ FoxCall Grid " +----------------------------------------------------------------------------- + FC G T T U Q D M Type +c58 g15 t71 t71 u90 q1 d20 i3=3 CQ FT + 58 73 144 215 305 326 329 +============================================================================= + +D Digital signature (20 bits) +F Fox call (28 bits) +FC Compound Fox call (58 bits) +G Grid locator (15 bits) +H Hound call (28 bits) +M Message type (3 bits) +Q MoreCQs flag +R Report, (5 bits: -18 to +12 dB, or RR73) +T Free text, up to 26 characters total +U Unused bits + +Unused callsign slots are set to the numerical value for "QU1RKS", and +ignored when received. Similarly for unused t71 slots. Unused report +slots are set to 0 (-20 dB). "CQ FoxCall" will be displayed along +with other messages if the "q1" bit is 1. + +The SuperFox decoder displays its results with a separate line for each Hound. +Thus, the old-style message "K1ABC RR73; W9XYZ -14" becomes + +K1ABC VP8PJ RR73 +W9XYZ VP8PJ -14 diff --git a/lib/superfox/twkfreq2.f90 b/lib/superfox/twkfreq2.f90 index 443088c6..3cb26f93 100755 --- a/lib/superfox/twkfreq2.f90 +++ b/lib/superfox/twkfreq2.f90 @@ -1,19 +1,19 @@ -subroutine twkfreq2(c3,c4,npts,fsample,fshift) - -! Adjust frequency of complex waveform - - complex c3(npts) - complex c4(npts) - complex w,wstep - data twopi/6.283185307/ - - w=1.0 - dphi=fshift*twopi/fsample - wstep=cmplx(cos(dphi),sin(dphi)) - do i=1,npts - w=w*wstep - c4(i)=w*c3(i) - enddo - - return -end subroutine twkfreq2 +subroutine twkfreq2(c3,c4,npts,fsample,fshift) + +! Adjust frequency of complex waveform + + complex c3(npts) + complex c4(npts) + complex w,wstep + data twopi/6.283185307/ + + w=1.0 + dphi=fshift*twopi/fsample + wstep=cmplx(cos(dphi),sin(dphi)) + do i=1,npts + w=w*wstep + c4(i)=w*c3(i) + enddo + + return +end subroutine twkfreq2 diff --git a/lib/symspec.f90 b/lib/symspec.f90 index 4f54d022..49adf105 100755 --- a/lib/symspec.f90 +++ b/lib/symspec.f90 @@ -1,126 +1,126 @@ -subroutine symspec(shared_data,k,TRperiod,nsps,ingain,bLowSidelobes, & - nminw,pxdb,s,df3,ihsym,npts8,pxdbmax,npct) - -! Input: -! k pointer to the most recent new data -! TRperiod T/R sequence length, seconds -! nsps samples per symbol, at 12000 Hz -! bLowSidelobes true to use windowed FFTs -! ndiskdat 0/1 to indicate if data from disk - -! Output: -! pxdb raw power (0-90 dB) -! s() current spectrum for waterfall display -! ihsym index number of this half-symbol (1-184) for 60 s modes - -! jt9com -! ss() JT9 symbol spectra at half-symbol steps -! savg() average spectra for waterfall display - - use, intrinsic :: iso_c_binding, only: c_int, c_short, c_float, c_char - include 'jt9com.f90' - - type(dec_data) :: shared_data - real*8 TRperiod - real*4 w3(MAXFFT3) - real*4 s(NSMAX) - real*4 ssum(NSMAX) - real*4 xc(0:MAXFFT3-1) - real*4 tmp(NSMAX) - complex cx(0:MAXFFT3/2) - integer nch(7) - logical*1 bLowSidelobes - - common/spectra/syellow(NSMAX),ref(0:3456),filter(0:3456) - data k0/99999999/,nfft3z/0/ - data nch/1,2,4,9,18,36,72/ - equivalence (xc,cx) - save - - if(TRperiod+npct.eq.-999.9) stop !Silence compiler warning - nfft3=16384 !df=12000.0/16384 = 0.732422 - jstep=nsps/2 !Step size = half-symbol in id2() - if(k.gt.NMAX) go to 900 - if(k.lt.2048) then !(2048 was nfft3) (Any need for this ???) - ihsym=0 - go to 900 !Wait for enough samples to start - endif - - if(nfft3.ne.nfft3z) then -! Compute new window - pi=4.0*atan(1.0) - w3=0 - call nuttal_window(w3,nfft3) - nfft3z=nfft3 - endif - - if(k.lt.k0) then !Start a new data block - k0=0 - ja=0 - ssum=0. - ihsym=0 - if(.not. shared_data%params%ndiskdat) shared_data%id2(k+1:)=0 !Needed to prevent "ghosts". Not sure why. - endif - gain=10.0**(0.1*ingain) - sq=0. - pxmax=0.; - - do i=k0+1,k - if(k0.eq.0 .and. i.le.10) cycle - x1=shared_data%id2(i) - if (abs(x1).gt.pxmax) pxmax = abs(x1); - sq=sq + x1*x1 - enddo - pxdb = 0. - if(sq.gt.0.0) pxdb=10*log10(sq/(k-k0)) - pxdbmax=0. - if(pxmax.gt.0) pxdbmax = 20*log10(pxmax) - - k0=k - ja=ja+jstep !Index of first sample - - fac0=0.1 - do i=0,nfft3-1 !Copy data into cx - j=ja+i-(nfft3-1) - xc(i)=0. - if(j.ge.1 .and.j.le.NMAX) xc(i)=fac0*shared_data%id2(j) - enddo - ihsym=ihsym+1 - - if(bLowSidelobes) xc(0:nfft3-1)=w3(1:nfft3)*xc(0:nfft3-1) !Apply window - call four2a(xc,nfft3,1,-1,0) !Real-to-complex FFT - - df3=12000.0/nfft3 !JT9: 0.732 Hz = 0.42 * tone spacing - iz=min(NSMAX,nint(5000.0/df3)) - fac=(1.0/nfft3)**2 - do i=1,iz - j=i-1 - if(j.lt.0) j=j+nfft3 - sx=fac*(real(cx(j))**2 + aimag(cx(j))**2) - if(ihsym.le.184) shared_data%ss(ihsym,i)=sx - ssum(i)=ssum(i) + sx - s(i)=1000.0*gain*sx - enddo - - shared_data%savg=ssum/ihsym - - if(mod(ihsym,10).eq.0) then - mode4=nch(nminw+1) - nsmo=min(10*mode4,150) - nsmo=4*nsmo - call flat1(shared_data%savg,iz,nsmo,syellow) - if(mode4.ge.2) call smo(syellow,iz,tmp,mode4) - if(mode4.ge.2) call smo(syellow,iz,tmp,mode4) - syellow(1:250)=0. - ia=500./df3 - ib=2700.0/df3 - smin=minval(syellow(ia:ib)) - smax=maxval(syellow(1:iz)) - syellow=(50.0/(smax-smin))*(syellow-smin) - where(syellow<0) syellow=0. - endif - -900 npts8=k/8 - - return -end subroutine symspec +subroutine symspec(shared_data,k,TRperiod,nsps,ingain,bLowSidelobes, & + nminw,pxdb,s,df3,ihsym,npts8,pxdbmax,npct) + +! Input: +! k pointer to the most recent new data +! TRperiod T/R sequence length, seconds +! nsps samples per symbol, at 12000 Hz +! bLowSidelobes true to use windowed FFTs +! ndiskdat 0/1 to indicate if data from disk + +! Output: +! pxdb raw power (0-90 dB) +! s() current spectrum for waterfall display +! ihsym index number of this half-symbol (1-184) for 60 s modes + +! jt9com +! ss() JT9 symbol spectra at half-symbol steps +! savg() average spectra for waterfall display + + use, intrinsic :: iso_c_binding, only: c_int, c_short, c_float, c_char + include 'jt9com.f90' + + type(dec_data) :: shared_data + real*8 TRperiod + real*4 w3(MAXFFT3) + real*4 s(NSMAX) + real*4 ssum(NSMAX) + real*4 xc(0:MAXFFT3-1) + real*4 tmp(NSMAX) + complex cx(0:MAXFFT3/2) + integer nch(7) + logical*1 bLowSidelobes + + common/spectra/syellow(NSMAX),ref(0:3456),filter(0:3456) + data k0/99999999/,nfft3z/0/ + data nch/1,2,4,9,18,36,72/ + equivalence (xc,cx) + save + + if(TRperiod+npct.eq.-999.9) stop !Silence compiler warning + nfft3=16384 !df=12000.0/16384 = 0.732422 + jstep=nsps/2 !Step size = half-symbol in id2() + if(k.gt.NMAX) go to 900 + if(k.lt.2048) then !(2048 was nfft3) (Any need for this ???) + ihsym=0 + go to 900 !Wait for enough samples to start + endif + + if(nfft3.ne.nfft3z) then +! Compute new window + pi=4.0*atan(1.0) + w3=0 + call nuttal_window(w3,nfft3) + nfft3z=nfft3 + endif + + if(k.lt.k0) then !Start a new data block + k0=0 + ja=0 + ssum=0. + ihsym=0 + if(.not. shared_data%params%ndiskdat) shared_data%id2(k+1:)=0 !Needed to prevent "ghosts". Not sure why. + endif + gain=10.0**(0.1*ingain) + sq=0. + pxmax=0.; + + do i=k0+1,k + if(k0.eq.0 .and. i.le.10) cycle + x1=shared_data%id2(i) + if (abs(x1).gt.pxmax) pxmax = abs(x1); + sq=sq + x1*x1 + enddo + pxdb = 0. + if(sq.gt.0.0) pxdb=10*log10(sq/(k-k0)) + pxdbmax=0. + if(pxmax.gt.0) pxdbmax = 20*log10(pxmax) + + k0=k + ja=ja+jstep !Index of first sample + + fac0=0.1 + do i=0,nfft3-1 !Copy data into cx + j=ja+i-(nfft3-1) + xc(i)=0. + if(j.ge.1 .and.j.le.NMAX) xc(i)=fac0*shared_data%id2(j) + enddo + ihsym=ihsym+1 + + if(bLowSidelobes) xc(0:nfft3-1)=w3(1:nfft3)*xc(0:nfft3-1) !Apply window + call four2a(xc,nfft3,1,-1,0) !Real-to-complex FFT + + df3=12000.0/nfft3 !JT9: 0.732 Hz = 0.42 * tone spacing + iz=min(NSMAX,nint(5000.0/df3)) + fac=(1.0/nfft3)**2 + do i=1,iz + j=i-1 + if(j.lt.0) j=j+nfft3 + sx=fac*(real(cx(j))**2 + aimag(cx(j))**2) + if(ihsym.le.184) shared_data%ss(ihsym,i)=sx + ssum(i)=ssum(i) + sx + s(i)=1000.0*gain*sx + enddo + + shared_data%savg=ssum/ihsym + + if(mod(ihsym,10).eq.0) then + mode4=nch(nminw+1) + nsmo=min(10*mode4,150) + nsmo=4*nsmo + call flat1(shared_data%savg,iz,nsmo,syellow) + if(mode4.ge.2) call smo(syellow,iz,tmp,mode4) + if(mode4.ge.2) call smo(syellow,iz,tmp,mode4) + syellow(1:250)=0. + ia=500./df3 + ib=2700.0/df3 + smin=minval(syellow(ia:ib)) + smax=maxval(syellow(1:iz)) + syellow=(50.0/(smax-smin))*(syellow-smin) + where(syellow<0) syellow=0. + endif + +900 npts8=k/8 + + return +end subroutine symspec diff --git a/lib/sync65.f90 b/lib/sync65.f90 index 5e3ba7d9..cfb3accb 100755 --- a/lib/sync65.f90 +++ b/lib/sync65.f90 @@ -1,94 +1,94 @@ -subroutine sync65(nfa,nfb,ntol,nqsym,ca,ncand,nrobust,bVHF) - - parameter (NSZ=3413,NFFT=8192,MAXCAND=300) - real ss(552,NSZ) - real ccfblue(-32:82) !CCF with pseudorandom sequence - real ccfred(NSZ) !Peak of ccfblue, as function of freq - logical bVHF - - type candidate - real freq - real dt - real sync - real flip - end type candidate - type(candidate) ca(MAXCAND) - - common/steve/thresh0 - common/sync/ss - - if(ntol.eq.-99) stop !Silence compiler warning - call setup65 - - df=12000.0/NFFT !df = 12000.0/8192 = 1.465 Hz - ia=max(2,nint(nfa/df)) - ib=min(NSZ-1,nint(nfb/df)) -! lag1=-11 -! lag2=59 -! lag1=-22 -! lag2=118 - lag1=-32 - lag2=82 !may need to be extended for EME - nsym=126 - ncand=0 - fdot=0. - ccfred=0. - ccfblue=0. - ccfmax=0. - ipk=0 - do i=ia,ib - call xcor(i,nqsym,nsym,lag1,lag2,ccfblue,ccf0,lagpk0,flip,fdot,nrobust) -! Remove best-fit slope from ccfblue and normalize so baseline rms=1.0 - if(.not.bVHF) call slope(ccfblue(lag1),lag2-lag1+1, & - lagpk0-lag1+1.0) - ccfred(i)=ccfblue(lagpk0) - if(ccfred(i).gt.ccfmax) then - ccfmax=ccfred(i) - ipk=i - endif - enddo - call pctile(ccfred(ia:ib),ib-ia+1,35,xmed) - ccfred(ia:ib)=ccfred(ia:ib)-xmed - ccfred(ia-1)=ccfred(ia) - ccfred(ib+1)=ccfred(ib) - - do i=ia,ib - freq=i*df - itry=0 - if(bVHF) then - if(i.ne.ipk .or. ccfmax.lt.thresh0) cycle - itry=1 - ncand=ncand+1 - else - if(ccfred(i).ge.thresh0 .and. ccfred(i).gt.ccfred(i-1) .and. & - ccfred(i).gt.ccfred(i+1)) then - itry=1 - ncand=ncand+1 - endif - endif - if(itry.ne.0) then - call xcor(i,nqsym,nsym,lag1,lag2,ccfblue,ccf0,lagpk,flip,fdot,nrobust) - if(.not.bVHF) call slope(ccfblue(lag1),lag2-lag1+1, & - lagpk-lag1+1.0) - xlag=lagpk - if(lagpk.gt.lag1 .and. lagpk.lt.lag2) then - call peakup(ccfblue(lagpk-1),ccfmax,ccfblue(lagpk+1),dx2) - xlag=lagpk+dx2 - endif - dtx=xlag*1024.0/11025.0 - ccfblue(lag1)=0. - ccfblue(lag2)=0. - ca(ncand)%freq=freq - ca(ncand)%dt=dtx - ca(ncand)%flip=flip - if(bVHF) then - ca(ncand)%sync=db(ccfred(i)) - 16.0 - else - ca(ncand)%sync=ccfred(i) - endif - endif - if(ncand.eq.MAXCAND) exit - enddo - - return -end subroutine sync65 +subroutine sync65(nfa,nfb,ntol,nqsym,ca,ncand,nrobust,bVHF) + + parameter (NSZ=3413,NFFT=8192,MAXCAND=300) + real ss(552,NSZ) + real ccfblue(-32:82) !CCF with pseudorandom sequence + real ccfred(NSZ) !Peak of ccfblue, as function of freq + logical bVHF + + type candidate + real freq + real dt + real sync + real flip + end type candidate + type(candidate) ca(MAXCAND) + + common/steve/thresh0 + common/sync/ss + + if(ntol.eq.-99) stop !Silence compiler warning + call setup65 + + df=12000.0/NFFT !df = 12000.0/8192 = 1.465 Hz + ia=max(2,nint(nfa/df)) + ib=min(NSZ-1,nint(nfb/df)) +! lag1=-11 +! lag2=59 +! lag1=-22 +! lag2=118 + lag1=-32 + lag2=82 !may need to be extended for EME + nsym=126 + ncand=0 + fdot=0. + ccfred=0. + ccfblue=0. + ccfmax=0. + ipk=0 + do i=ia,ib + call xcor(i,nqsym,nsym,lag1,lag2,ccfblue,ccf0,lagpk0,flip,fdot,nrobust) +! Remove best-fit slope from ccfblue and normalize so baseline rms=1.0 + if(.not.bVHF) call slope(ccfblue(lag1),lag2-lag1+1, & + lagpk0-lag1+1.0) + ccfred(i)=ccfblue(lagpk0) + if(ccfred(i).gt.ccfmax) then + ccfmax=ccfred(i) + ipk=i + endif + enddo + call pctile(ccfred(ia:ib),ib-ia+1,35,xmed) + ccfred(ia:ib)=ccfred(ia:ib)-xmed + ccfred(ia-1)=ccfred(ia) + ccfred(ib+1)=ccfred(ib) + + do i=ia,ib + freq=i*df + itry=0 + if(bVHF) then + if(i.ne.ipk .or. ccfmax.lt.thresh0) cycle + itry=1 + ncand=ncand+1 + else + if(ccfred(i).ge.thresh0 .and. ccfred(i).gt.ccfred(i-1) .and. & + ccfred(i).gt.ccfred(i+1)) then + itry=1 + ncand=ncand+1 + endif + endif + if(itry.ne.0) then + call xcor(i,nqsym,nsym,lag1,lag2,ccfblue,ccf0,lagpk,flip,fdot,nrobust) + if(.not.bVHF) call slope(ccfblue(lag1),lag2-lag1+1, & + lagpk-lag1+1.0) + xlag=lagpk + if(lagpk.gt.lag1 .and. lagpk.lt.lag2) then + call peakup(ccfblue(lagpk-1),ccfmax,ccfblue(lagpk+1),dx2) + xlag=lagpk+dx2 + endif + dtx=xlag*1024.0/11025.0 + ccfblue(lag1)=0. + ccfblue(lag2)=0. + ca(ncand)%freq=freq + ca(ncand)%dt=dtx + ca(ncand)%flip=flip + if(bVHF) then + ca(ncand)%sync=db(ccfred(i)) - 16.0 + else + ca(ncand)%sync=ccfred(i) + endif + endif + if(ncand.eq.MAXCAND) exit + enddo + + return +end subroutine sync65 diff --git a/lib/sync9f.f90 b/lib/sync9f.f90 index 8e4f0b0a..8aca06bb 100755 --- a/lib/sync9f.f90 +++ b/lib/sync9f.f90 @@ -1,55 +1,55 @@ -subroutine sync9f(s2,nq,nfa,nfb,ss2,ss3,lagpk,ipk,ccfbest) - -! Look for JT9 sync pattern in the folded symbol spectra, s2. -! Frequency search extends from nfa to nfb. Synchronized symbol -! spectra are put into ss2() and ss3(). - - integer ii4(16) - real s2(240,340) - real ss2(0:8,85) - real ss3(0:7,69) - include 'jt9sync.f90' - - ii4=4*ii-3 - ccf=0. - ccfbest=0. - nfft=4*nq - df=12000.0/nfft - ia=nfa/df - ib=nfb/df + 0.9999 - - do i=ia,ib - do lag=0,339 - t=0. - do n=1,16 - j=ii4(n)+lag - if(j.gt.340) j=j-340 - t=t + s2(i,j) - enddo - if(t.gt.ccfbest) then - lagpk=lag - ipk=i - ccfbest=t - endif - enddo - enddo - - do i=0,8 - j4=lagpk-4 - i2=2*i + ipk - if(i2.lt.1) i2=1 - m=0 - do j=1,85 - j4=j4+4 - if(j4.gt.340) j4=j4-340 - if(j4.lt.1) j4=j4+340 - ss2(i,j)=s2(i2,j4) - if(i.ge.1 .and. isync(j).eq.0) then - m=m+1 - ss3(i-1,m)=ss2(i,j) - endif - enddo - enddo - - return -end subroutine sync9f +subroutine sync9f(s2,nq,nfa,nfb,ss2,ss3,lagpk,ipk,ccfbest) + +! Look for JT9 sync pattern in the folded symbol spectra, s2. +! Frequency search extends from nfa to nfb. Synchronized symbol +! spectra are put into ss2() and ss3(). + + integer ii4(16) + real s2(240,340) + real ss2(0:8,85) + real ss3(0:7,69) + include 'jt9sync.f90' + + ii4=4*ii-3 + ccf=0. + ccfbest=0. + nfft=4*nq + df=12000.0/nfft + ia=nfa/df + ib=nfb/df + 0.9999 + + do i=ia,ib + do lag=0,339 + t=0. + do n=1,16 + j=ii4(n)+lag + if(j.gt.340) j=j-340 + t=t + s2(i,j) + enddo + if(t.gt.ccfbest) then + lagpk=lag + ipk=i + ccfbest=t + endif + enddo + enddo + + do i=0,8 + j4=lagpk-4 + i2=2*i + ipk + if(i2.lt.1) i2=1 + m=0 + do j=1,85 + j4=j4+4 + if(j4.gt.340) j4=j4-340 + if(j4.lt.1) j4=j4+340 + ss2(i,j)=s2(i2,j4) + if(i.ge.1 .and. isync(j).eq.0) then + m=m+1 + ss3(i-1,m)=ss2(i,j) + endif + enddo + enddo + + return +end subroutine sync9f diff --git a/lib/syncmsk.f90 b/lib/syncmsk.f90 index 4e1d2f96..0e26d46f 100755 --- a/lib/syncmsk.f90 +++ b/lib/syncmsk.f90 @@ -1,304 +1,304 @@ -subroutine syncmsk(cdat,npts,jpk,ipk,idf,rmax,snr,metric,decoded) - -! Attempt synchronization, and if successful decode using Viterbi algorithm. - - use iso_c_binding, only: c_loc,c_size_t - use packjt - use hashing - use timer_module, only: timer - - parameter (NSPM=1404,NSAVE=2000) - complex cdat(npts) !Analytic signal - complex cb(66) !Complex waveform for Barker-11 code - complex cd(0:11,0:3) - complex c(0:NSPM-1) !Complex data for one message length - complex c2(0:NSPM-1) - complex cb3(1:NSPM,3) - real r(12000) - real rdat(12000) - real ss1(12000) - real symbol(234) - real rdata(198) - real rd2(198) - real rsave(NSAVE) - real xp(29) - complex z,z0,z1,z2,z3,cfac - integer*1 e1(198) - integer*1, target :: d8(13) - integer*1 i1hash(4) - integer*1 i1 - integer*4 i4Msg6BitWords(12) !72-bit message as 6-bit words - integer mettab(0:255,0:1) !Metric table for BPSK modulation - integer ipksave(NSAVE) - integer jpksave(NSAVE) - integer indx(NSAVE) - integer b11(11) !Barker-11 code - character*22 decoded - character*72 c72 - logical first - equivalence (i1,i4) - equivalence (ihash,i1hash) - data xp/0.500000, 0.401241, 0.309897, 0.231832, 0.168095, & - 0.119704, 0.083523, 0.057387, 0.039215, 0.026890, & - 0.018084, 0.012184, 0.008196, 0.005475, 0.003808, & - 0.002481, 0.001710, 0.001052, 0.000789, 0.000469, & - 0.000329, 0.000225, 0.000187, 0.000086, 0.000063, & - 0.000017, 0.000091, 0.000032, 0.000045/ - data first/.true./ - data b11/1,1,1,0,0,0,1,0,0,1,0/ - save first,cb,cd,twopi,dt,f0,f1,mettab - - phi=0. - if(first) then -! Get the metric table - bias=0.0 - scale=20.0 - xln2=log(2.0) - mettab=0 - do i=128,156 - x0=log(max(0.001,2.0*xp(i-127)))/xln2 - x1=log(max(0.001,2.0*(1.0-xp(i-127))))/xln2 - mettab(i,0)=nint(scale*(x0-bias)) - mettab(i,1)=nint(scale*(x1-bias)) - mettab(256-i,0)=mettab(i,1) - mettab(256-i,1)=mettab(i,0) - enddo - do i=157,255 - mettab(i,0)=mettab(156,0) - mettab(i,1)=mettab(156,1) - mettab(256-i,0)=mettab(i,1) - mettab(256-i,1)=mettab(i,0) - enddo - j=0 - twopi=8.0*atan(1.0) - dt=1.0/12000.0 - f0=1000.0 - f1=2000.0 - dphi=0 - do i=1,11 - if(b11(i).eq.0) dphi=twopi*f0*dt - if(b11(i).eq.1) dphi=twopi*f1*dt - do n=1,6 - j=j+1 - phi=phi+dphi - cb(j)=cmplx(cos(phi),sin(phi)) - enddo - enddo - cb3=0. - cb3(1:66,1)=cb - cb3(283:348,1)=cb - cb3(769:834,1)=cb - - cb3(1:66,2)=cb - cb3(487:552,2)=cb - cb3(1123:1188,2)=cb - - cb3(1:66,3)=cb - cb3(637:702,3)=cb - cb3(919:984,3)=cb - - phi=0. - do n=0,3 - k=-1 - dphi=twopi*f0*dt - if(n.ge.2) dphi=twopi*f1*dt - do i=0,5 - k=k+1 - phi=phi+dphi - if(phi.gt.twopi) phi=phi-twopi - cd(k,n)=cmplx(cos(phi),sin(phi)) - enddo - - dphi=twopi*f0*dt - if(mod(n,2).eq.1) dphi=twopi*f1*dt - do i=6,11 - k=k+1 - phi=phi+dphi - if(phi.gt.twopi) phi=phi-twopi - cd(k,n)=cmplx(cos(phi),sin(phi)) - enddo - enddo - - first=.false. - endif - - nfft=NSPM - jz=npts-nfft - decoded=" " - ipk=0 - jpk=0 - metric=-9999 - r=0. - - call timer('sync1 ',0) - do j=1,jz !Find the Barker-11 sync vectors - z=0. - ss=0. - do i=1,66 - ss=ss + real(cdat(j+i-1))**2 + aimag(cdat(j+i-1))**2 - z=z + cdat(j+i-1)*conjg(cb(i)) !Signal matching Barker 11 - enddo - ss=sqrt(ss/66.0)*66.0 - r(j)=abs(z)/(0.908*ss) !Goodness-of-fit to Barker 11 - ss1(j)=ss - enddo - call timer('sync1 ',1) - - call timer('sync2 ',0) - jz=npts-nfft - rmax=0. -! n1=35, n2=69, n3=94 - k=0 - do j=1,jz !Find best full-message sync - if(ss1(j).lt.85.0) cycle - r1=r(j) + r(j+282) + r(j+768) ! 6*(12+n1) 6*(24+n1+n2) - r2=r(j) + r(j+486) + r(j+1122) ! 6*(12+n2) 6*(24+n2+n3) - r3=r(j) + r(j+636) + r(j+918) ! 6*(12+n3) 6*(24+n3+n1) - if(r1.gt.rmax) then - rmax=r1 - jpk=j - ipk=1 - endif - if(r2.gt.rmax) then - rmax=r2 - jpk=j - ipk=2 - endif - if(r3.gt.rmax) then - rmax=r3 - jpk=j - ipk=3 - endif - rrmax=max(r1,r2,r3) - if(rrmax.gt.1.9) then - k=min(k+1,NSAVE) - if(r1.eq.rrmax) ipksave(k)=1 - if(r2.eq.rrmax) ipksave(k)=2 - if(r3.eq.rrmax) ipksave(k)=3 - jpksave(k)=j - rsave(k)=rrmax - endif - enddo - call timer('sync2 ',1) - kmax=k - - call indexx(rsave,kmax,indx) - - call timer('sync3 ',0) - do kk=1,kmax - k=indx(kmax+1-kk) - ipk=ipksave(k) - jpk=jpksave(k) - rmax=rsave(k) - - c=conjg(cb3(1:NSPM,ipk))*cdat(jpk:jpk+nfft-1) - smax=0. - dfx=0. - idfbest=0 - do itry=1,25 - idf=itry/2 - if(mod(itry,2).eq.0) idf=-idf - idf=4*idf - twk=idf - call tweak1(c,NSPM,-twk,c2) - z=sum(c2) - if(abs(z).gt.smax) then - dfx=twk - smax=abs(z) - phi=atan2(aimag(z),real(z)) !Carrier phase offset - idfbest=idf - endif - enddo - idf=idfbest - call tweak1(cdat,npts,-dfx,cdat) - cfac=cmplx(cos(phi),-sin(phi)) - cdat=cfac*cdat - - sig=0. - ref=0. - rdat(1:npts)=cdat - iz=11 - do k=1,234 !Compute soft symbols - j=jpk+6*(k-1) - - z0=2.0*dot_product(cdat(j:j+iz),cd(0:iz,0)) - z1=2.0*dot_product(cdat(j:j+iz),cd(0:iz,1)) - z2=2.0*dot_product(cdat(j:j+iz),cd(0:iz,2)) - z3=2.0*dot_product(cdat(j:j+iz),cd(0:iz,3)) - -!### Maybe these should be weighted by yellow() ? - if(j+1404+iz.lt.npts) then - z0=z0 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,0)) - z1=z1 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,1)) - z2=z2 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,2)) - z3=z3 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,3)) - endif - - if(j-1404.ge.1) then - z0=z0 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,0)) - z1=z1 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,1)) - z2=z2 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,2)) - z3=z3 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,3)) - endif - - sym=max(abs(real(z2)),abs(real(z3))) - max(abs(real(z0)),abs(real(z1))) - - if(sym.lt.0.0) then - phi=atan2(aimag(z0),real(z0)) - sig=sig + real(z0)**2 - ref=ref + aimag(z0)**2 - else - phi=atan2(aimag(z1),real(z1)) - sig=sig + real(z1)**2 - ref=ref + aimag(z1)**2 - endif - n=k - if(ipk.eq.2) n=k+47 - if(ipk.eq.3) n=k+128 - if(n.gt.234) n=n-234 - ibit=0 - if(sym.ge.0) ibit=1 - symbol(n)=sym - enddo - snr=db(sig/ref-1.0) - - rdata(1:35)=symbol(12:46) - rdata(36:104)=symbol(59:127) - rdata(105:198)=symbol(140:233) - -! Re-order the symbols and make them i*1 - j=0 - do i=1,99 - i4=128+rdata(i) !### Should be nint() ??? ### - if(i4.gt.255) i4=255 - if(i4.lt.0) i4=0 - j=j+1 - e1(j)=i1 - rd2(j)=rdata(i) - i4=128+rdata(i+99) - if(i4.gt.255) i4=255 - if(i4.lt.0) i4=0 - j=j+1 - e1(j)=i1 - rd2(j)=rdata(i+99) - enddo - -! Decode the message - nb1=87 - call vit213(e1,nb1,mettab,d8,metric) - ihash=nhash(c_loc(d8),int(9,c_size_t),146) - ihash=2*iand(ihash,32767) - decoded=' ' - if(d8(10).eq.i1hash(2) .and. d8(11).eq.i1hash(1)) then - write(c72,1012) d8(1:9) -1012 format(9b8.8) - read(c72,1014) i4Msg6BitWords -1014 format(12b6.6) - call unpackmsg(i4Msg6BitWords,decoded) !Unpack to get msgsent - endif - if(decoded.ne.' ') exit - enddo - call timer('sync3 ',1) - - return -end subroutine syncmsk +subroutine syncmsk(cdat,npts,jpk,ipk,idf,rmax,snr,metric,decoded) + +! Attempt synchronization, and if successful decode using Viterbi algorithm. + + use iso_c_binding, only: c_loc,c_size_t + use packjt + use hashing + use timer_module, only: timer + + parameter (NSPM=1404,NSAVE=2000) + complex cdat(npts) !Analytic signal + complex cb(66) !Complex waveform for Barker-11 code + complex cd(0:11,0:3) + complex c(0:NSPM-1) !Complex data for one message length + complex c2(0:NSPM-1) + complex cb3(1:NSPM,3) + real r(12000) + real rdat(12000) + real ss1(12000) + real symbol(234) + real rdata(198) + real rd2(198) + real rsave(NSAVE) + real xp(29) + complex z,z0,z1,z2,z3,cfac + integer*1 e1(198) + integer*1, target :: d8(13) + integer*1 i1hash(4) + integer*1 i1 + integer*4 i4Msg6BitWords(12) !72-bit message as 6-bit words + integer mettab(0:255,0:1) !Metric table for BPSK modulation + integer ipksave(NSAVE) + integer jpksave(NSAVE) + integer indx(NSAVE) + integer b11(11) !Barker-11 code + character*22 decoded + character*72 c72 + logical first + equivalence (i1,i4) + equivalence (ihash,i1hash) + data xp/0.500000, 0.401241, 0.309897, 0.231832, 0.168095, & + 0.119704, 0.083523, 0.057387, 0.039215, 0.026890, & + 0.018084, 0.012184, 0.008196, 0.005475, 0.003808, & + 0.002481, 0.001710, 0.001052, 0.000789, 0.000469, & + 0.000329, 0.000225, 0.000187, 0.000086, 0.000063, & + 0.000017, 0.000091, 0.000032, 0.000045/ + data first/.true./ + data b11/1,1,1,0,0,0,1,0,0,1,0/ + save first,cb,cd,twopi,dt,f0,f1,mettab + + phi=0. + if(first) then +! Get the metric table + bias=0.0 + scale=20.0 + xln2=log(2.0) + mettab=0 + do i=128,156 + x0=log(max(0.001,2.0*xp(i-127)))/xln2 + x1=log(max(0.001,2.0*(1.0-xp(i-127))))/xln2 + mettab(i,0)=nint(scale*(x0-bias)) + mettab(i,1)=nint(scale*(x1-bias)) + mettab(256-i,0)=mettab(i,1) + mettab(256-i,1)=mettab(i,0) + enddo + do i=157,255 + mettab(i,0)=mettab(156,0) + mettab(i,1)=mettab(156,1) + mettab(256-i,0)=mettab(i,1) + mettab(256-i,1)=mettab(i,0) + enddo + j=0 + twopi=8.0*atan(1.0) + dt=1.0/12000.0 + f0=1000.0 + f1=2000.0 + dphi=0 + do i=1,11 + if(b11(i).eq.0) dphi=twopi*f0*dt + if(b11(i).eq.1) dphi=twopi*f1*dt + do n=1,6 + j=j+1 + phi=phi+dphi + cb(j)=cmplx(cos(phi),sin(phi)) + enddo + enddo + cb3=0. + cb3(1:66,1)=cb + cb3(283:348,1)=cb + cb3(769:834,1)=cb + + cb3(1:66,2)=cb + cb3(487:552,2)=cb + cb3(1123:1188,2)=cb + + cb3(1:66,3)=cb + cb3(637:702,3)=cb + cb3(919:984,3)=cb + + phi=0. + do n=0,3 + k=-1 + dphi=twopi*f0*dt + if(n.ge.2) dphi=twopi*f1*dt + do i=0,5 + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + cd(k,n)=cmplx(cos(phi),sin(phi)) + enddo + + dphi=twopi*f0*dt + if(mod(n,2).eq.1) dphi=twopi*f1*dt + do i=6,11 + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + cd(k,n)=cmplx(cos(phi),sin(phi)) + enddo + enddo + + first=.false. + endif + + nfft=NSPM + jz=npts-nfft + decoded=" " + ipk=0 + jpk=0 + metric=-9999 + r=0. + + call timer('sync1 ',0) + do j=1,jz !Find the Barker-11 sync vectors + z=0. + ss=0. + do i=1,66 + ss=ss + real(cdat(j+i-1))**2 + aimag(cdat(j+i-1))**2 + z=z + cdat(j+i-1)*conjg(cb(i)) !Signal matching Barker 11 + enddo + ss=sqrt(ss/66.0)*66.0 + r(j)=abs(z)/(0.908*ss) !Goodness-of-fit to Barker 11 + ss1(j)=ss + enddo + call timer('sync1 ',1) + + call timer('sync2 ',0) + jz=npts-nfft + rmax=0. +! n1=35, n2=69, n3=94 + k=0 + do j=1,jz !Find best full-message sync + if(ss1(j).lt.85.0) cycle + r1=r(j) + r(j+282) + r(j+768) ! 6*(12+n1) 6*(24+n1+n2) + r2=r(j) + r(j+486) + r(j+1122) ! 6*(12+n2) 6*(24+n2+n3) + r3=r(j) + r(j+636) + r(j+918) ! 6*(12+n3) 6*(24+n3+n1) + if(r1.gt.rmax) then + rmax=r1 + jpk=j + ipk=1 + endif + if(r2.gt.rmax) then + rmax=r2 + jpk=j + ipk=2 + endif + if(r3.gt.rmax) then + rmax=r3 + jpk=j + ipk=3 + endif + rrmax=max(r1,r2,r3) + if(rrmax.gt.1.9) then + k=min(k+1,NSAVE) + if(r1.eq.rrmax) ipksave(k)=1 + if(r2.eq.rrmax) ipksave(k)=2 + if(r3.eq.rrmax) ipksave(k)=3 + jpksave(k)=j + rsave(k)=rrmax + endif + enddo + call timer('sync2 ',1) + kmax=k + + call indexx(rsave,kmax,indx) + + call timer('sync3 ',0) + do kk=1,kmax + k=indx(kmax+1-kk) + ipk=ipksave(k) + jpk=jpksave(k) + rmax=rsave(k) + + c=conjg(cb3(1:NSPM,ipk))*cdat(jpk:jpk+nfft-1) + smax=0. + dfx=0. + idfbest=0 + do itry=1,25 + idf=itry/2 + if(mod(itry,2).eq.0) idf=-idf + idf=4*idf + twk=idf + call tweak1(c,NSPM,-twk,c2) + z=sum(c2) + if(abs(z).gt.smax) then + dfx=twk + smax=abs(z) + phi=atan2(aimag(z),real(z)) !Carrier phase offset + idfbest=idf + endif + enddo + idf=idfbest + call tweak1(cdat,npts,-dfx,cdat) + cfac=cmplx(cos(phi),-sin(phi)) + cdat=cfac*cdat + + sig=0. + ref=0. + rdat(1:npts)=cdat + iz=11 + do k=1,234 !Compute soft symbols + j=jpk+6*(k-1) + + z0=2.0*dot_product(cdat(j:j+iz),cd(0:iz,0)) + z1=2.0*dot_product(cdat(j:j+iz),cd(0:iz,1)) + z2=2.0*dot_product(cdat(j:j+iz),cd(0:iz,2)) + z3=2.0*dot_product(cdat(j:j+iz),cd(0:iz,3)) + +!### Maybe these should be weighted by yellow() ? + if(j+1404+iz.lt.npts) then + z0=z0 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,0)) + z1=z1 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,1)) + z2=z2 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,2)) + z3=z3 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,3)) + endif + + if(j-1404.ge.1) then + z0=z0 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,0)) + z1=z1 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,1)) + z2=z2 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,2)) + z3=z3 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,3)) + endif + + sym=max(abs(real(z2)),abs(real(z3))) - max(abs(real(z0)),abs(real(z1))) + + if(sym.lt.0.0) then + phi=atan2(aimag(z0),real(z0)) + sig=sig + real(z0)**2 + ref=ref + aimag(z0)**2 + else + phi=atan2(aimag(z1),real(z1)) + sig=sig + real(z1)**2 + ref=ref + aimag(z1)**2 + endif + n=k + if(ipk.eq.2) n=k+47 + if(ipk.eq.3) n=k+128 + if(n.gt.234) n=n-234 + ibit=0 + if(sym.ge.0) ibit=1 + symbol(n)=sym + enddo + snr=db(sig/ref-1.0) + + rdata(1:35)=symbol(12:46) + rdata(36:104)=symbol(59:127) + rdata(105:198)=symbol(140:233) + +! Re-order the symbols and make them i*1 + j=0 + do i=1,99 + i4=128+rdata(i) !### Should be nint() ??? ### + if(i4.gt.255) i4=255 + if(i4.lt.0) i4=0 + j=j+1 + e1(j)=i1 + rd2(j)=rdata(i) + i4=128+rdata(i+99) + if(i4.gt.255) i4=255 + if(i4.lt.0) i4=0 + j=j+1 + e1(j)=i1 + rd2(j)=rdata(i+99) + enddo + +! Decode the message + nb1=87 + call vit213(e1,nb1,mettab,d8,metric) + ihash=nhash(c_loc(d8),int(9,c_size_t),146) + ihash=2*iand(ihash,32767) + decoded=' ' + if(d8(10).eq.i1hash(2) .and. d8(11).eq.i1hash(1)) then + write(c72,1012) d8(1:9) +1012 format(9b8.8) + read(c72,1014) i4Msg6BitWords +1014 format(12b6.6) + call unpackmsg(i4Msg6BitWords,decoded) !Unpack to get msgsent + endif + if(decoded.ne.' ') exit + enddo + call timer('sync3 ',1) + + return +end subroutine syncmsk diff --git a/lib/tab.c b/lib/tab.c index d3b059ca..3cd419aa 100755 --- a/lib/tab.c +++ b/lib/tab.c @@ -1,36 +1,36 @@ -/* 8-bit parity lookup table, generated by partab.c */ -unsigned char Partab[] = { - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, -}; - +/* 8-bit parity lookup table, generated by partab.c */ +unsigned char Partab[] = { + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, +}; + diff --git a/lib/test_init_random_seed.f90 b/lib/test_init_random_seed.f90 index ddda394b..3b9dad1f 100755 --- a/lib/test_init_random_seed.f90 +++ b/lib/test_init_random_seed.f90 @@ -1,8 +1,8 @@ -program test_init_random_seed - real :: r(10,4) - call init_random_seed() - call random_number(r) - do i =1,10 - write (*, *) (r(i,j),j=1,4) - end do -end program test_init_random_seed +program test_init_random_seed + real :: r(10,4) + call init_random_seed() + call random_number(r) + do i =1,10 + write (*, *) (r(i,j),j=1,4) + end do +end program test_init_random_seed diff --git a/lib/test_q65.f90 b/lib/test_q65.f90 index 53fecc8f..598de976 100755 --- a/lib/test_q65.f90 +++ b/lib/test_q65.f90 @@ -1,191 +1,191 @@ -program test_q65 - - character*84 cmd1,cmd2,line - character*22 msg - character*8 arg - character*1 csubmode - integer naptype(0:5) - logical decok - - nargs=iargc() - if(nargs.ne.12) then - print*,'Usage: test_q65 "msg" A-D depth freq DT fDop f1 Stp TRp Q nfiles SNR' - print*,'Example: test_q65 "K1ABC W9XYZ EN37" A 3 1500 0.0 5.0 0.0 1 60 3 100 -20' - print*,'Use SNR = 0 to loop over all relevant SNRs' - print*,'Use MyCall=K1ABC, HisCall=W9XYZ, HisGrid="EN37" for AP decodes' - print*,'Option Q sets QSOprogress (0-5) for AP decoding.' - print*,'Add 16 to requested depth to enable message averaging.' - go to 999 - endif - call getarg(1,msg) - call getarg(2,csubmode) - call getarg(3,arg) - read(arg,*) ndepth - call getarg(4,arg) - read(arg,*) nf0 - call getarg(5,arg) - read(arg,*) dt - call getarg(6,arg) - read(arg,*) fDop - call getarg(7,arg) - read(arg,*) f1 - call getarg(8,arg) - read(arg,*) nstp - call getarg(9,arg) - read(arg,*) ntrperiod - call getarg(10,arg) - read(arg,*) nQSOprogress - call getarg(11,arg) - read(arg,*) nfiles - call getarg(12,arg) - read(arg,*) snr - - if(ntrperiod.eq.15) then - nsps=1800 - i50=-23 - else if(ntrperiod.eq.30) then - nsps=3600 - i50=-26 - else if(ntrperiod.eq.60) then - nsps=7200 - i50=-29 - else if(ntrperiod.eq.120) then - nsps=16000 - i50=-31 - else if(ntrperiod.eq.300) then - nsps=41472 - i50=-35 - else - stop 'Invalid TR period' - endif - - i50=i50 + 8.0*log(1.0+fDop)/log(240.0) - ia=i50 + 7 - ib=i50 - 10 - if(snr.ne.0.0) then - ia=99 - ib=99 - endif - - baud=12000.0/nsps - tsym=1.0/baud - -! 1 2 3 4 5 6 7 -! 1234567890123456789012345678901234567890123456789012345678901234567890123456' - cmd1='q65sim "K1ABC W9XYZ EN37 " A 1500 5.0 0.0 0.0 1 60 100 -10.0 > junk0' - cmd2='jt9 -3 -p 15 -L 300 -H 3000 -d 3 -b A -Q 3 -f 1500 -X 32 *.wav > junk' - - write(cmd1(10:33),'(a)') '"'//msg//'"' - cmd1(35:35)=csubmode - write(cmd1(37:40),'(i4)') nf0 - write(cmd1(41:45),'(f5.0)') fDop - write(cmd1(46:50),'(f5.2)') dt - write(cmd1(51:56),'(i6)') nint(f1) - write(cmd1(57:59),'(i3)') nstp - write(cmd1(60:63),'(i4)') ntrperiod - write(cmd1(64:68),'(i5)') nfiles - - write(cmd2(11:13),'(i3)') ntrperiod - write(cmd2(33:35),'(i3)') ndepth - write(cmd2(45:45),'(i1)') nQSOprogress - write(cmd2(50:53),'(i4)') nf0 - cmd2(40:40)=csubmode - - call system('rm -f *.wav') - - write(*,1008) ntrperiod,csubmode,ndepth,fDop,f1,nstp -1008 format('Mode:',i4,a1,' Depth:',i3,' fDop:',f6.1,' Drift:',f8.1, & - ' Steps:',i3) - write(*,1010) (j,j=0,5) - write(12,1010) (j,j=0,5) -1010 format(' SNR Sync Avg Dec Bad',6i4,' tdec avg rms'/64('-')) - - dterr=tsym/4.0 - nferr=max(1,nint(0.5*baud),nint(fdop/3.0)) - ndec1z=nfiles - - do nsnr=ia,ib,-1 - snr1=nsnr - if(ia.eq.99) snr1=snr - nsync=0 - ndec1=0 - nfalse=0 - naptype=0 - ndecn=0 - write(cmd1(72:76),'(f5.1)') snr1 - call system(cmd1) - call sec0(0,tdec) - call system(cmd2) - call sec0(1,tdec) - open(10,file='junk',status='unknown') - n=0 - snrsum=0. - snrsq=0. - nsum=0 - do iline=1,9999 - read(10,'(a71)',end=10) line - if(index(line,'' - go to 999 - endif - call getarg(1,infile) - i0=index(infile,'_') - read(infile(1:i0-1),*) fspread0 !Generated Doppler spread - read(infile(i0+1:i0+3),*) snrdb0 !Generated SNR - open(10,file=trim(infile),status='old',access='stream') - read(10) h - npts=h%ndata/2 - npings=npts/NMAX - nfsample=h%nsamrate - df=12000.0/NFFT - s=0. - fac=1.0/NMAX - - do iping=1,npings - read(10) id2(1:NMAX) - x(1:NMAX)=fac*id2(1:NMAX) - x(NMAX+1:)=0. - call four2a(x,NFFT,1,-1,0) - do i=1,8192 !Accumulate spectrum 0 - 3 kHz - s(i)=s(i) + real(c(i))**2 + aimag(c(i))**2 - enddo - enddo - - sa=s(2049:6144) - sb=s(2049:6144) - - call echo_snr(sa,sb,fspread0,blue,red,snrdb,db_err,fpeak,snr_detect) - - nqual=min(10,int(snr_detect-4.0)) - - write(*,1010) fspread0,snrdb0,snrdb,snrdb-snrdb0,db_err,fpeak, & - snr_detect,nqual - -1010 format(5f6.1,2f7.1,i4) - - do i=1,8192 - write(12,1100) i*df,s(i) -1100 format(f10.3,e15.6) - enddo - -999 end program test_snr +program test_snr + +! Test an algorithm for measuring SNR of EME echoes. + + use wavhdr + parameter (NMAX=27648) !27*1024 + parameter (NFFT=32768,NH=NFFT/2) + parameter (NZ=4096) + + type(hdr) h !Header for the .wav file + integer*2 id2(NMAX) !Buffer for Rx data + complex c(0:NH) + real x(NFFT) + real s(8192) + real sa(4096) + real sb(4096) + real red(4096) + real blue(4096) + character*80 infile + equivalence (x,c) + + nargs=iargc() + if(nargs.lt.1) then + print*,'Usage: test_snr ' + go to 999 + endif + call getarg(1,infile) + i0=index(infile,'_') + read(infile(1:i0-1),*) fspread0 !Generated Doppler spread + read(infile(i0+1:i0+3),*) snrdb0 !Generated SNR + open(10,file=trim(infile),status='old',access='stream') + read(10) h + npts=h%ndata/2 + npings=npts/NMAX + nfsample=h%nsamrate + df=12000.0/NFFT + s=0. + fac=1.0/NMAX + + do iping=1,npings + read(10) id2(1:NMAX) + x(1:NMAX)=fac*id2(1:NMAX) + x(NMAX+1:)=0. + call four2a(x,NFFT,1,-1,0) + do i=1,8192 !Accumulate spectrum 0 - 3 kHz + s(i)=s(i) + real(c(i))**2 + aimag(c(i))**2 + enddo + enddo + + sa=s(2049:6144) + sb=s(2049:6144) + + call echo_snr(sa,sb,fspread0,blue,red,snrdb,db_err,fpeak,snr_detect) + + nqual=min(10,int(snr_detect-4.0)) + + write(*,1010) fspread0,snrdb0,snrdb,snrdb-snrdb0,db_err,fpeak, & + snr_detect,nqual + +1010 format(5f6.1,2f7.1,i4) + + do i=1,8192 + write(12,1100) i*df,s(i) +1100 format(f10.3,e15.6) + enddo + +999 end program test_snr diff --git a/lib/testfast9.f90 b/lib/testfast9.f90 index eb08fb78..0315241f 100755 --- a/lib/testfast9.f90 +++ b/lib/testfast9.f90 @@ -1,42 +1,42 @@ -program testfast9 - - parameter (NMAX=30*12000) - integer*2 id2(NMAX) - integer narg(0:11) - character*80 line(100) - character submode*1,infile*80 - - nargs=iargc() - if(nargs.ne.2) then - print*,'Usage: testfast9 submode infile' - print*,'Example: testfast9 E 150806_123300.wav' - go to 999 - endif - call getarg(1,submode) - call getarg(2,infile) - - open(10,file=infile,access='stream',status='old') - read(10) id2(1:22) !Skip 44 header bytes - npts=NMAX - read(10,end=1) id2(1:npts) !Read the raw data - -1 i1=index(infile,'.wav') - read(infile(i1-6:i1-1),*) narg(0) - narg(1)=NMAX - n=ichar(submode) - narg(2)=n-ichar('A') - if(n.ge.97 .and. n.le.104) narg(2)=n-ichar('a') - narg(3)=1 - narg(4)=0 - narg(5)=0 - narg(6)=0 - narg(7)=29951 - narg(8)=1 - narg(9)=102 - narg(10)=700 - narg(11)=500 - - call fast9(id2,narg,line) - print*,line(1) - -999 end program testfast9 +program testfast9 + + parameter (NMAX=30*12000) + integer*2 id2(NMAX) + integer narg(0:11) + character*80 line(100) + character submode*1,infile*80 + + nargs=iargc() + if(nargs.ne.2) then + print*,'Usage: testfast9 submode infile' + print*,'Example: testfast9 E 150806_123300.wav' + go to 999 + endif + call getarg(1,submode) + call getarg(2,infile) + + open(10,file=infile,access='stream',status='old') + read(10) id2(1:22) !Skip 44 header bytes + npts=NMAX + read(10,end=1) id2(1:npts) !Read the raw data + +1 i1=index(infile,'.wav') + read(infile(i1-6:i1-1),*) narg(0) + narg(1)=NMAX + n=ichar(submode) + narg(2)=n-ichar('A') + if(n.ge.97 .and. n.le.104) narg(2)=n-ichar('a') + narg(3)=1 + narg(4)=0 + narg(5)=0 + narg(6)=0 + narg(7)=29951 + narg(8)=1 + narg(9)=102 + narg(10)=700 + narg(11)=500 + + call fast9(id2,narg,line) + print*,line(1) + +999 end program testfast9 diff --git a/lib/testmsg.f90 b/lib/testmsg.f90 index 5cfac595..eae851d6 100755 --- a/lib/testmsg.f90 +++ b/lib/testmsg.f90 @@ -1,145 +1,145 @@ - parameter (MAXTEST=75,NTEST=68) - character*22 testmsg(MAXTEST) - character*22 testmsgchk(MAXTEST) - ! Test msgs should include the extremes for the different types - ! See pfx.f90 - ! Type 1 P & A - ! Type 1 1A & E5 - data testmsg(1:NTEST)/ & - "CQ WB9XYZ EN34", & - "CQ DX WB9XYZ EN34", & - "QRZ WB9XYZ EN34", & - "KA1ABC WB9XYZ EN34", & - "KA1ABC WB9XYZ RO", & - "KA1ABC WB9XYZ -21", & - "KA1ABC WB9XYZ R-19", & - "KA1ABC WB9XYZ RRR", & - "KA1ABC WB9XYZ 73", & - "KA1ABC WB9XYZ", & - "CQ 010 WB9XYZ EN34", & - "CQ 999 WB9XYZ EN34", & - "CQ EU WB9XYZ EN34", & - "CQ WY WB9XYZ EN34", & - "1A/KA1ABC WB9XYZ", & - "E5/KA1ABC WB9XYZ", & - "KA1ABC 1A/WB9XYZ", & - "KA1ABC E5/WB9XYZ", & - "KA1ABC/P WB9XYZ", & - "KA1ABC/A WB9XYZ", & - "KA1ABC WB9XYZ/P", & - "KA1ABC WB9XYZ/A", & - "CQ KA1ABC/P", & - "CQ WB9XYZ/A", & - "QRZ KA1ABC/P", & - "QRZ WB9XYZ/A", & - "DE KA1ABC/P", & - "DE WB9XYZ/A", & - "CQ 1A/KA1ABC", & - "CQ E5/KA1ABC", & - "DE 1A/KA1ABC", & - "DE E5/KA1ABC", & - "QRZ 1A/KA1ABC", & - "QRZ E5/KA1ABC", & - "CQ WB9XYZ/1A", & - "CQ WB9XYZ/E5", & - "QRZ WB9XYZ/1A", & - "QRZ WB9XYZ/E5", & - "DE WB9XYZ/1A", & - "DE WB9XYZ/E5", & - "CQ A000/KA1ABC FM07", & - "CQ ZZZZ/KA1ABC FM07", & - "QRZ W4/KA1ABC FM07", & - "DE W4/KA1ABC FM07", & - "CQ W4/KA1ABC -22", & - "DE W4/KA1ABC -22", & - "QRZ W4/KA1ABC -22", & - "CQ W4/KA1ABC R-22", & - "DE W4/KA1ABC R-22", & - "QRZ W4/KA1ABC R-22", & - "DE W4/KA1ABC 73", & - "CQ KA1ABC FM07", & - "QRZ KA1ABC FM07", & - "DE KA1ABC/VE6 FM07", & - "CQ KA1ABC/VE6 -22", & - "DE KA1ABC/VE6 -22", & - "QRZ KA1ABC/VE6 -22", & - "CQ KA1ABC/VE6 R-22", & - "DE KA1ABC/VE6 R-22", & - "QRZ KA1ABC/VE6 R-22", & - "DE KA1ABC 73", & - "HELLO WORLD", & - "ZL4/KA1ABC 73", & - "KA1ABC XL/WB9XYZ", & - "KA1ABC WB9XYZ/W4", & - "DE KA1ABC/QRP 2W", & - "KA1ABC/1 WB9XYZ/1", & - "123456789ABCDEFGH"/ - data testmsgchk(1:NTEST)/ & - "CQ WB9XYZ EN34", & - "CQ DX WB9XYZ EN34", & - "QRZ WB9XYZ EN34", & - "KA1ABC WB9XYZ EN34", & - "KA1ABC WB9XYZ RO", & - "KA1ABC WB9XYZ -21", & - "KA1ABC WB9XYZ R-19", & - "KA1ABC WB9XYZ RRR", & - "KA1ABC WB9XYZ 73", & - "KA1ABC WB9XYZ", & - "CQ 000 WB9XYZ EN34", & - "CQ 999 WB9XYZ EN34", & - "CQ EU WB9XYZ EN34", & - "CQ WY WB9XYZ EN34", & - "1A/KA1ABC WB9XYZ", & - "E5/KA1ABC WB9XYZ", & - "KA1ABC 1A/WB9XYZ", & - "KA1ABC E5/WB9XYZ", & - "KA1ABC/P WB9XYZ", & - "KA1ABC/A WB9XYZ", & - "KA1ABC WB9XYZ/P", & - "KA1ABC WB9XYZ/A", & - "CQ KA1ABC/P", & - "CQ WB9XYZ/A", & - "QRZ KA1ABC/P", & - "QRZ WB9XYZ/A", & - "DE KA1ABC/P", & - "DE WB9XYZ/A", & - "CQ 1A/KA1ABC", & - "CQ E5/KA1ABC", & - "DE 1A/KA1ABC", & - "DE E5/KA1ABC", & - "QRZ 1A/KA1ABC", & - "QRZ E5/KA1ABC", & - "CQ WB9XYZ/1A", & - "CQ WB9XYZ/E5", & - "QRZ WB9XYZ/1A", & - "QRZ WB9XYZ/E5", & - "DE WB9XYZ/1A", & - "DE WB9XYZ/E5", & - "CQ A000/KA1ABC FM07", & - "CQ ZZZZ/KA1ABC FM07", & - "QRZ W4/KA1ABC FM07", & - "DE W4/KA1ABC FM07", & - "CQ W4/KA1ABC -22", & - "DE W4/KA1ABC -22", & - "QRZ W4/KA1ABC -22", & - "CQ W4/KA1ABC R-22", & - "DE W4/KA1ABC R-22", & - "QRZ W4/KA1ABC R-22", & - "DE W4/KA1ABC 73", & - "CQ KA1ABC FM07", & - "QRZ KA1ABC FM07", & - "DE KA1ABC/VE6 FM07", & - "CQ KA1ABC/VE6 -22", & - "DE KA1ABC/VE6 -22", & - "QRZ KA1ABC/VE6 -22", & - "CQ KA1ABC/VE6 R-22", & - "DE KA1ABC/VE6 R-22", & - "QRZ KA1ABC/VE6 R-22", & - "DE KA1ABC 73", & - "HELLO WORLD", & - "ZL4/KA1ABC 73", & - "KA1ABC XL/WB9", & - "KA1ABC WB9XYZ", & - "DE KA1ABC/QRP", & - "KA1ABC/1 WB9X", & - "123456789ABCD"/ + parameter (MAXTEST=75,NTEST=68) + character*22 testmsg(MAXTEST) + character*22 testmsgchk(MAXTEST) + ! Test msgs should include the extremes for the different types + ! See pfx.f90 + ! Type 1 P & A + ! Type 1 1A & E5 + data testmsg(1:NTEST)/ & + "CQ WB9XYZ EN34", & + "CQ DX WB9XYZ EN34", & + "QRZ WB9XYZ EN34", & + "KA1ABC WB9XYZ EN34", & + "KA1ABC WB9XYZ RO", & + "KA1ABC WB9XYZ -21", & + "KA1ABC WB9XYZ R-19", & + "KA1ABC WB9XYZ RRR", & + "KA1ABC WB9XYZ 73", & + "KA1ABC WB9XYZ", & + "CQ 010 WB9XYZ EN34", & + "CQ 999 WB9XYZ EN34", & + "CQ EU WB9XYZ EN34", & + "CQ WY WB9XYZ EN34", & + "1A/KA1ABC WB9XYZ", & + "E5/KA1ABC WB9XYZ", & + "KA1ABC 1A/WB9XYZ", & + "KA1ABC E5/WB9XYZ", & + "KA1ABC/P WB9XYZ", & + "KA1ABC/A WB9XYZ", & + "KA1ABC WB9XYZ/P", & + "KA1ABC WB9XYZ/A", & + "CQ KA1ABC/P", & + "CQ WB9XYZ/A", & + "QRZ KA1ABC/P", & + "QRZ WB9XYZ/A", & + "DE KA1ABC/P", & + "DE WB9XYZ/A", & + "CQ 1A/KA1ABC", & + "CQ E5/KA1ABC", & + "DE 1A/KA1ABC", & + "DE E5/KA1ABC", & + "QRZ 1A/KA1ABC", & + "QRZ E5/KA1ABC", & + "CQ WB9XYZ/1A", & + "CQ WB9XYZ/E5", & + "QRZ WB9XYZ/1A", & + "QRZ WB9XYZ/E5", & + "DE WB9XYZ/1A", & + "DE WB9XYZ/E5", & + "CQ A000/KA1ABC FM07", & + "CQ ZZZZ/KA1ABC FM07", & + "QRZ W4/KA1ABC FM07", & + "DE W4/KA1ABC FM07", & + "CQ W4/KA1ABC -22", & + "DE W4/KA1ABC -22", & + "QRZ W4/KA1ABC -22", & + "CQ W4/KA1ABC R-22", & + "DE W4/KA1ABC R-22", & + "QRZ W4/KA1ABC R-22", & + "DE W4/KA1ABC 73", & + "CQ KA1ABC FM07", & + "QRZ KA1ABC FM07", & + "DE KA1ABC/VE6 FM07", & + "CQ KA1ABC/VE6 -22", & + "DE KA1ABC/VE6 -22", & + "QRZ KA1ABC/VE6 -22", & + "CQ KA1ABC/VE6 R-22", & + "DE KA1ABC/VE6 R-22", & + "QRZ KA1ABC/VE6 R-22", & + "DE KA1ABC 73", & + "HELLO WORLD", & + "ZL4/KA1ABC 73", & + "KA1ABC XL/WB9XYZ", & + "KA1ABC WB9XYZ/W4", & + "DE KA1ABC/QRP 2W", & + "KA1ABC/1 WB9XYZ/1", & + "123456789ABCDEFGH"/ + data testmsgchk(1:NTEST)/ & + "CQ WB9XYZ EN34", & + "CQ DX WB9XYZ EN34", & + "QRZ WB9XYZ EN34", & + "KA1ABC WB9XYZ EN34", & + "KA1ABC WB9XYZ RO", & + "KA1ABC WB9XYZ -21", & + "KA1ABC WB9XYZ R-19", & + "KA1ABC WB9XYZ RRR", & + "KA1ABC WB9XYZ 73", & + "KA1ABC WB9XYZ", & + "CQ 000 WB9XYZ EN34", & + "CQ 999 WB9XYZ EN34", & + "CQ EU WB9XYZ EN34", & + "CQ WY WB9XYZ EN34", & + "1A/KA1ABC WB9XYZ", & + "E5/KA1ABC WB9XYZ", & + "KA1ABC 1A/WB9XYZ", & + "KA1ABC E5/WB9XYZ", & + "KA1ABC/P WB9XYZ", & + "KA1ABC/A WB9XYZ", & + "KA1ABC WB9XYZ/P", & + "KA1ABC WB9XYZ/A", & + "CQ KA1ABC/P", & + "CQ WB9XYZ/A", & + "QRZ KA1ABC/P", & + "QRZ WB9XYZ/A", & + "DE KA1ABC/P", & + "DE WB9XYZ/A", & + "CQ 1A/KA1ABC", & + "CQ E5/KA1ABC", & + "DE 1A/KA1ABC", & + "DE E5/KA1ABC", & + "QRZ 1A/KA1ABC", & + "QRZ E5/KA1ABC", & + "CQ WB9XYZ/1A", & + "CQ WB9XYZ/E5", & + "QRZ WB9XYZ/1A", & + "QRZ WB9XYZ/E5", & + "DE WB9XYZ/1A", & + "DE WB9XYZ/E5", & + "CQ A000/KA1ABC FM07", & + "CQ ZZZZ/KA1ABC FM07", & + "QRZ W4/KA1ABC FM07", & + "DE W4/KA1ABC FM07", & + "CQ W4/KA1ABC -22", & + "DE W4/KA1ABC -22", & + "QRZ W4/KA1ABC -22", & + "CQ W4/KA1ABC R-22", & + "DE W4/KA1ABC R-22", & + "QRZ W4/KA1ABC R-22", & + "DE W4/KA1ABC 73", & + "CQ KA1ABC FM07", & + "QRZ KA1ABC FM07", & + "DE KA1ABC/VE6 FM07", & + "CQ KA1ABC/VE6 -22", & + "DE KA1ABC/VE6 -22", & + "QRZ KA1ABC/VE6 -22", & + "CQ KA1ABC/VE6 R-22", & + "DE KA1ABC/VE6 R-22", & + "QRZ KA1ABC/VE6 R-22", & + "DE KA1ABC 73", & + "HELLO WORLD", & + "ZL4/KA1ABC 73", & + "KA1ABC XL/WB9", & + "KA1ABC WB9XYZ", & + "DE KA1ABC/QRP", & + "KA1ABC/1 WB9X", & + "123456789ABCD"/ diff --git a/lib/timefft.f90 b/lib/timefft.f90 index 96b81b2a..72ab41b2 100755 --- a/lib/timefft.f90 +++ b/lib/timefft.f90 @@ -1,141 +1,141 @@ -program timefft - -! Tests and times one-dimensional FFTs computed by FFTW3 - - use, intrinsic :: iso_c_binding - use FFTW3 - - complex(C_FLOAT_COMPLEX),pointer :: a(:),b(:),c(:) - real(C_FLOAT),pointer :: ar(:),br(:) - type(C_PTR) :: plan1,plan2 !Pointers to FFTW plans - type(C_PTR) :: pa,pb,pc - integer(C_INT) iret - integer*8 count0,count1,clkfreq - character problem*9 - logical linplace,lcomplex,lthreading - -! Get command-line parameters - call timefft_opts(npatience,maxthreads,linplace,lcomplex,nfft,problem,nflags) - lthreading=maxthreads.ge.1 - maxthreads=max(1,maxthreads) - - call sgran() ! see C rand generator (used in gran) - -! Allocate data arrays - pa=fftwf_alloc_complex(int(nfft,C_SIZE_T)) - call c_f_pointer(pa,a,[nfft]) - call c_f_pointer(pa,ar,[nfft]) - - pb=fftwf_alloc_complex(int(nfft,C_SIZE_T)) - call c_f_pointer(pb,b,[nfft]) - call c_f_pointer(pb,br,[nfft]) - - pc=fftwf_alloc_complex(int(nfft,C_SIZE_T)) - call c_f_pointer(pc,c,[nfft]) - -! Initialize FFTW threading - if(lthreading) iret=fftwf_init_threads() - -! Import FFTW wisdom, if available - iret=fftwf_import_wisdom_from_filename(C_CHAR_'wis.dat' // C_NULL_CHAR) - - do i=1,nfft !Generate random data - x=gran() - y=gran() - b(i)=cmplx(x,y) - enddo - iters=100 - - write(*,1000) -1000 format(/'Problem Threads Plan Time Gflops RMS iters'/ & - '--------------------------------------------------------') - -! Try nthreads = 1,maxthreads - do nthreads=1,maxthreads - a(1:nfft)=b(1:nfft) !Copy test data into a() - call system_clock(count0,clkfreq) -! Make the plans - if(lthreading) call fftwf_plan_with_nthreads(nthreads) - if(lcomplex) then - if(linplace) then - plan1=fftwf_plan_dft_1d(nfft,a,a,-1,nflags) - plan2=fftwf_plan_dft_1d(nfft,a,a,+1,nflags) - else - plan1=fftwf_plan_dft_1d(nfft,a,c,-1,nflags) - plan2=fftwf_plan_dft_1d(nfft,c,a,+1,nflags) - endif - else - if(linplace) then - plan1=fftwf_plan_dft_r2c_1d(nfft,ar,a,nflags) - plan2=fftwf_plan_dft_c2r_1d(nfft,a,ar,nflags) - else - plan1=fftwf_plan_dft_r2c_1d(nfft,ar,c,nflags) - plan2=fftwf_plan_dft_c2r_1d(nfft,c,ar,nflags) - endif - endif - call system_clock(count1,clkfreq) - tplan=0.5*float(count1-count0)/float(clkfreq) !Plan time for one transform - - total=0. - do iter=1,iters !Do many iterations - a=b !Copy test data into a() - call system_clock(count0,clkfreq) -! Compute the transforms - if(lcomplex) then - if(linplace) then - call fftwf_execute_dft(plan1,a,a) - call fftwf_execute_dft(plan2,a,a) - else - call fftwf_execute_dft(plan1,a,c) - call fftwf_execute_dft(plan2,c,a) - endif - else - if(linplace) then - call fftwf_execute_dft_r2c(plan1,ar,a) - call fftwf_execute_dft_c2r(plan2,a,ar) - else - call fftwf_execute_dft_r2c(plan1,ar,c) - call fftwf_execute_dft_c2r(plan2,c,ar) - endif - endif - call system_clock(count1,clkfreq) - total=total + float(count1-count0)/float(clkfreq) - if(total>=1.0 .and. iter>=10) go to 40 !Cut iterations short ? - enddo - iter=iters - -40 time=0.5*total/iter !Time for one FFT - gflops=5.0/(1.e9*time/(nfft*log(float(nfft))/log(2.0))) - a(1:nfft)=a(1:nfft)/nfft !Normalize the back-transformed data - -! Compute RMS difference between original data and back-transformed data. - sq=0. - if(lcomplex) then - do i=1,nfft - sq=sq + real(a(i)-b(i))**2 + aimag(a(i)-b(i))**2 - enddo - else - do i=1,nfft - sq=sq + (ar(i)-br(i))**2 - enddo - endif - rms=sqrt(sq/nfft) - -! Display results - write(*,1050) problem,nthreads,tplan,time,gflops,rms,iter -1050 format(a9,i4,f8.3,f10.6,f7.2,f11.7,i5) - enddo - -! Export accumulated FFTW wisdom - iret=fftwf_export_wisdom_to_filename(C_CHAR_'wis.dat' // C_NULL_CHAR) - -! Clean up - call fftwf_destroy_plan(plan1) - call fftwf_destroy_plan(plan2) - call fftwf_free(pa) - call fftwf_free(pb) - call fftwf_free(pc) - call fftwf_cleanup_threads() - call fftwf_cleanup() - -end program timefft +program timefft + +! Tests and times one-dimensional FFTs computed by FFTW3 + + use, intrinsic :: iso_c_binding + use FFTW3 + + complex(C_FLOAT_COMPLEX),pointer :: a(:),b(:),c(:) + real(C_FLOAT),pointer :: ar(:),br(:) + type(C_PTR) :: plan1,plan2 !Pointers to FFTW plans + type(C_PTR) :: pa,pb,pc + integer(C_INT) iret + integer*8 count0,count1,clkfreq + character problem*9 + logical linplace,lcomplex,lthreading + +! Get command-line parameters + call timefft_opts(npatience,maxthreads,linplace,lcomplex,nfft,problem,nflags) + lthreading=maxthreads.ge.1 + maxthreads=max(1,maxthreads) + + call sgran() ! see C rand generator (used in gran) + +! Allocate data arrays + pa=fftwf_alloc_complex(int(nfft,C_SIZE_T)) + call c_f_pointer(pa,a,[nfft]) + call c_f_pointer(pa,ar,[nfft]) + + pb=fftwf_alloc_complex(int(nfft,C_SIZE_T)) + call c_f_pointer(pb,b,[nfft]) + call c_f_pointer(pb,br,[nfft]) + + pc=fftwf_alloc_complex(int(nfft,C_SIZE_T)) + call c_f_pointer(pc,c,[nfft]) + +! Initialize FFTW threading + if(lthreading) iret=fftwf_init_threads() + +! Import FFTW wisdom, if available + iret=fftwf_import_wisdom_from_filename(C_CHAR_'wis.dat' // C_NULL_CHAR) + + do i=1,nfft !Generate random data + x=gran() + y=gran() + b(i)=cmplx(x,y) + enddo + iters=100 + + write(*,1000) +1000 format(/'Problem Threads Plan Time Gflops RMS iters'/ & + '--------------------------------------------------------') + +! Try nthreads = 1,maxthreads + do nthreads=1,maxthreads + a(1:nfft)=b(1:nfft) !Copy test data into a() + call system_clock(count0,clkfreq) +! Make the plans + if(lthreading) call fftwf_plan_with_nthreads(nthreads) + if(lcomplex) then + if(linplace) then + plan1=fftwf_plan_dft_1d(nfft,a,a,-1,nflags) + plan2=fftwf_plan_dft_1d(nfft,a,a,+1,nflags) + else + plan1=fftwf_plan_dft_1d(nfft,a,c,-1,nflags) + plan2=fftwf_plan_dft_1d(nfft,c,a,+1,nflags) + endif + else + if(linplace) then + plan1=fftwf_plan_dft_r2c_1d(nfft,ar,a,nflags) + plan2=fftwf_plan_dft_c2r_1d(nfft,a,ar,nflags) + else + plan1=fftwf_plan_dft_r2c_1d(nfft,ar,c,nflags) + plan2=fftwf_plan_dft_c2r_1d(nfft,c,ar,nflags) + endif + endif + call system_clock(count1,clkfreq) + tplan=0.5*float(count1-count0)/float(clkfreq) !Plan time for one transform + + total=0. + do iter=1,iters !Do many iterations + a=b !Copy test data into a() + call system_clock(count0,clkfreq) +! Compute the transforms + if(lcomplex) then + if(linplace) then + call fftwf_execute_dft(plan1,a,a) + call fftwf_execute_dft(plan2,a,a) + else + call fftwf_execute_dft(plan1,a,c) + call fftwf_execute_dft(plan2,c,a) + endif + else + if(linplace) then + call fftwf_execute_dft_r2c(plan1,ar,a) + call fftwf_execute_dft_c2r(plan2,a,ar) + else + call fftwf_execute_dft_r2c(plan1,ar,c) + call fftwf_execute_dft_c2r(plan2,c,ar) + endif + endif + call system_clock(count1,clkfreq) + total=total + float(count1-count0)/float(clkfreq) + if(total>=1.0 .and. iter>=10) go to 40 !Cut iterations short ? + enddo + iter=iters + +40 time=0.5*total/iter !Time for one FFT + gflops=5.0/(1.e9*time/(nfft*log(float(nfft))/log(2.0))) + a(1:nfft)=a(1:nfft)/nfft !Normalize the back-transformed data + +! Compute RMS difference between original data and back-transformed data. + sq=0. + if(lcomplex) then + do i=1,nfft + sq=sq + real(a(i)-b(i))**2 + aimag(a(i)-b(i))**2 + enddo + else + do i=1,nfft + sq=sq + (ar(i)-br(i))**2 + enddo + endif + rms=sqrt(sq/nfft) + +! Display results + write(*,1050) problem,nthreads,tplan,time,gflops,rms,iter +1050 format(a9,i4,f8.3,f10.6,f7.2,f11.7,i5) + enddo + +! Export accumulated FFTW wisdom + iret=fftwf_export_wisdom_to_filename(C_CHAR_'wis.dat' // C_NULL_CHAR) + +! Clean up + call fftwf_destroy_plan(plan1) + call fftwf_destroy_plan(plan2) + call fftwf_free(pa) + call fftwf_free(pb) + call fftwf_free(pc) + call fftwf_cleanup_threads() + call fftwf_cleanup() + +end program timefft diff --git a/lib/timefft_opts.f90 b/lib/timefft_opts.f90 index 3e0419d1..cd58132b 100755 --- a/lib/timefft_opts.f90 +++ b/lib/timefft_opts.f90 @@ -1,48 +1,48 @@ -subroutine timefft_opts(npatience,nthreads,linplace,lcomplex,nfft, & - problem,nflags) - - use FFTW3 - - logical linplace,lcomplex - character problem*9,arg*12 - - nargs=iargc() - if(nargs.lt.3) then - print*,'Usage: timefft npatience maxthreads [[o|i][r|c]]nfft' - print*,' npatience - 0 to 4' - print*,' maxthreads - suggest #CPUs or #CPUs-1' - print*,' o,i - out-of-place or in-place (default=in-place)' - print*,' r,c - real or complex (default=complex)' - print*,' ' - print*,'Examples:' - print*,' timefft 1 1 32768 (1 thread, in-place, complex)' - print*,' timefft 2 3 or32768 (more patient, 3 threads,' - print*,' out-of-place, real)' - stop - endif - - call getarg(1,arg) - read(arg,*) npatience - call getarg(2,arg) - read(arg,*) nthreads - call getarg(3,arg) - linplace=arg(1:1).ne.'o' .and. arg(2:2).ne.'o' - lcomplex=arg(1:1).ne.'r' .and. arg(2:2).ne.'r' - k=3 - if(ichar(arg(2:2)).ge.48 .and. ichar(arg(2:2)).le.57) k=2 - if(ichar(arg(1:1)).ge.48 .and. ichar(arg(1:1)).le.57) k=1 - read(arg(k:),*) nfft - - write(problem,'(i9)') nfft - problem='ic'//adjustl(problem) - if(.not.linplace) problem(1:1)='o' - if(.not.lcomplex) problem(2:2)='r' - - 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 - - return -end subroutine timefft_opts +subroutine timefft_opts(npatience,nthreads,linplace,lcomplex,nfft, & + problem,nflags) + + use FFTW3 + + logical linplace,lcomplex + character problem*9,arg*12 + + nargs=iargc() + if(nargs.lt.3) then + print*,'Usage: timefft npatience maxthreads [[o|i][r|c]]nfft' + print*,' npatience - 0 to 4' + print*,' maxthreads - suggest #CPUs or #CPUs-1' + print*,' o,i - out-of-place or in-place (default=in-place)' + print*,' r,c - real or complex (default=complex)' + print*,' ' + print*,'Examples:' + print*,' timefft 1 1 32768 (1 thread, in-place, complex)' + print*,' timefft 2 3 or32768 (more patient, 3 threads,' + print*,' out-of-place, real)' + stop + endif + + call getarg(1,arg) + read(arg,*) npatience + call getarg(2,arg) + read(arg,*) nthreads + call getarg(3,arg) + linplace=arg(1:1).ne.'o' .and. arg(2:2).ne.'o' + lcomplex=arg(1:1).ne.'r' .and. arg(2:2).ne.'r' + k=3 + if(ichar(arg(2:2)).ge.48 .and. ichar(arg(2:2)).le.57) k=2 + if(ichar(arg(1:1)).ge.48 .and. ichar(arg(1:1)).le.57) k=1 + read(arg(k:),*) nfft + + write(problem,'(i9)') nfft + problem='ic'//adjustl(problem) + if(.not.linplace) problem(1:1)='o' + if(.not.lcomplex) problem(2:2)='r' + + 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 + + return +end subroutine timefft_opts diff --git a/lib/timer_C_wrapper.f90 b/lib/timer_C_wrapper.f90 index 227abb51..866a8508 100755 --- a/lib/timer_C_wrapper.f90 +++ b/lib/timer_C_wrapper.f90 @@ -1,57 +1,57 @@ -module timer_c_wrapper - use :: iso_c_binding, only: c_ptr - use timer_module, only: timer, null_timer - implicit none - - ! - ! C interoperable callback setup - ! - abstract interface - subroutine c_timer_callback (context, dname, k) - use, intrinsic :: iso_c_binding, only: c_ptr, c_char - implicit none - type(c_ptr), value, intent(in) :: context - character(c_char), intent(in) :: dname(*) - integer, intent(in), value :: k - end subroutine c_timer_callback - end interface - - public :: init, fini - - private - - ! - ! the following are singleton items which assumes that any timer - ! implementation should only assume one global instance, probably a - ! struct or class object whose address is stored the context below - ! - type(c_ptr), private :: the_context - procedure(C_timer_callback), pointer, private :: the_callback - -contains - subroutine timer_callback_wrapper (dname, k) - use, intrinsic :: iso_c_binding, only: c_null_char - implicit none - character(len=8), intent(in) :: dname - integer, intent(in) :: k - call the_callback (the_context, trim (dname) // c_null_char, k) - end subroutine timer_callback_wrapper - - subroutine init (context, callback) - use, intrinsic :: iso_c_binding, only: c_ptr, c_funptr, c_f_procpointer - use iso_c_utilities, only: c_to_f_string - use timer_module, only: timer - implicit none - type(c_ptr), value, intent(in) :: context - type(c_funptr), value, intent(in) :: callback - the_context=context - call c_f_procpointer (callback, the_callback) - timer => timer_callback_wrapper - end subroutine init - - subroutine fini () - implicit none - timer => null_timer - end subroutine fini - -end module timer_c_wrapper +module timer_c_wrapper + use :: iso_c_binding, only: c_ptr + use timer_module, only: timer, null_timer + implicit none + + ! + ! C interoperable callback setup + ! + abstract interface + subroutine c_timer_callback (context, dname, k) + use, intrinsic :: iso_c_binding, only: c_ptr, c_char + implicit none + type(c_ptr), value, intent(in) :: context + character(c_char), intent(in) :: dname(*) + integer, intent(in), value :: k + end subroutine c_timer_callback + end interface + + public :: init, fini + + private + + ! + ! the following are singleton items which assumes that any timer + ! implementation should only assume one global instance, probably a + ! struct or class object whose address is stored the context below + ! + type(c_ptr), private :: the_context + procedure(C_timer_callback), pointer, private :: the_callback + +contains + subroutine timer_callback_wrapper (dname, k) + use, intrinsic :: iso_c_binding, only: c_null_char + implicit none + character(len=8), intent(in) :: dname + integer, intent(in) :: k + call the_callback (the_context, trim (dname) // c_null_char, k) + end subroutine timer_callback_wrapper + + subroutine init (context, callback) + use, intrinsic :: iso_c_binding, only: c_ptr, c_funptr, c_f_procpointer + use iso_c_utilities, only: c_to_f_string + use timer_module, only: timer + implicit none + type(c_ptr), value, intent(in) :: context + type(c_funptr), value, intent(in) :: callback + the_context=context + call c_f_procpointer (callback, the_callback) + timer => timer_callback_wrapper + end subroutine init + + subroutine fini () + implicit none + timer => null_timer + end subroutine fini + +end module timer_c_wrapper diff --git a/lib/timer_common.inc b/lib/timer_common.inc index 8da485dc..1e7f32a9 100755 --- a/lib/timer_common.inc +++ b/lib/timer_common.inc @@ -1,3 +1,3 @@ - integer :: level, onlevel(0:10) - common/timer_private/ level, onlevel - !$omp threadprivate(/timer_private/) + integer :: level, onlevel(0:10) + common/timer_private/ level, onlevel + !$omp threadprivate(/timer_private/) diff --git a/lib/timer_impl.f90 b/lib/timer_impl.f90 index 80a18547..221db9e0 100755 --- a/lib/timer_impl.f90 +++ b/lib/timer_impl.f90 @@ -1,266 +1,266 @@ -module timer_impl - !$ use omp_lib - use :: iso_c_binding, only: c_ptr - use timer_module, only: timer_callback - implicit none - - public :: init_timer, fini_timer - integer, public :: limtrace=0 -! integer, public :: limtrace=10000000 - - private - - integer, parameter :: MAXCALL=100 - integer :: lu=6 - real :: dut - integer :: i,nmax=0,ncall(MAXCALL),nlevel(MAXCALL),nparent(MAXCALL) - character(len=8) :: name(MAXCALL),space=' ' - logical :: on(MAXCALL) - real :: total,sum,sumf,ut(MAXCALL),ut0(MAXCALL) - !$ integer :: j,l,m,ntid(MAXCALL) - - ! - ! C interoperable callback setup - ! - public :: C_init_timer - abstract interface - subroutine C_timer_callback (context, dname, k) - use, intrinsic :: iso_c_binding, only: c_ptr - implicit none - type(c_ptr), intent(in) :: context - character(len=8), intent(in) :: dname - integer, intent(in) :: k - end subroutine C_timer_callback - end interface - type(c_ptr), private :: the_context - procedure(C_timer_callback), pointer, private :: the_C_callback - -contains - subroutine timer_callback_wrapper (dname, k) - implicit none - character(len=8), intent(in) :: dname - integer, intent(in) :: k - call the_C_callback (the_context, dname, k) - end subroutine timer_callback_wrapper - - subroutine C_init_timer (context, callback) bind(C) - use, intrinsic :: iso_c_binding, only: c_ptr, c_funptr, c_f_procpointer - use iso_c_utilities, only: c_to_f_string - use timer_module, only: timer - implicit none - type(c_ptr), intent(in) :: context - type(c_funptr), intent(in) :: callback - the_context=context - call c_f_procpointer (callback, the_C_callback) - timer => timer_callback_wrapper - end subroutine C_init_timer - - ! - ! default Fortran implementation which is thread safe using OpenMP - ! - subroutine default_timer (dname, k) - - ! Times procedure number n between a call with k=0 (tstart) and with - ! k=1 (tstop). Accumulates sums of these times in array ut (user time). - ! Also traces all calls (for debugging purposes) if limtrace.gt.0 - ! - ! If this is used with OpenMP than the /timer_private/ common - ! block must be copyed into each thread of a thread team by using - ! the copyin() clause on the !$omp parallel directive that creates - ! the team. - - implicit none - - character(len=8), intent(in) :: dname - integer, intent(in) :: k - - real :: ut1,eps=0.000001 - integer :: n,ndiv,ntrace=0 - !$ integer :: tid - character(len=8) :: tname - include 'timer_common.inc' - - !$omp critical(timer) - if(limtrace.lt.0) go to 999 - if(k.gt.1) go to 40 !Check for "all done" (k>1) - onlevel(0)=0 - - !$ tid=omp_get_thread_num() - do n=1,nmax !Check for existing name/parent[/thread] - if(name(n).eq.dname & - !$ .and.ntid(n).eq.tid & - ) then - if (on(n)) then - if (nparent(n).eq.onlevel(level-1)) goto 20 - else - if (nparent(n).eq.onlevel(level)) goto 20 - end if - end if - enddo - - nmax=nmax+1 !This is a new one - n=nmax - !$ ntid(n)=tid - ncall(n)=0 - on(n)=.false. - ut(n)=eps - name(n)=dname - -20 if(k.eq.0) then !Get start times (k=0) - if(on(n)) then - print*,'Error in timer: ',dname,' already on.' - end if - level=level+1 !Increment the level - on(n)=.true. - ! call system_clock(icount,irate) - ! ut0(n)=float(icount)/irate - ! call cpu_time(ut0(n)) - ut0(n)=secnds(0.0) - - ncall(n)=ncall(n)+1 - if(ncall(n).gt.1.and.nlevel(n).ne.level) then - !recursion is happening - ! - !TODO: somehow need to account for this deeper call at the - !shallowest instance in the call chain and this needs to be - !done without incrementing anything here other than counters - !and timers - ! - nlevel(n)=-1 - else - nlevel(n)=level - endif - nparent(n)=onlevel(level-1) - onlevel(level)=n - - else if(k.eq.1) then !Get stop times and accumulate sums. (k=1) - if(on(n)) then - on(n)=.false. - ! call system_clock(icount,irate) - ! ut1=float(icount)/irate - ! call cpu_time(ut1) - ut1=secnds(0.0) - - ut(n)=ut(n)+ut1-ut0(n) - endif - level=level-1 - endif - - ntrace=ntrace+1 - tname='TopLevel' - if(nparent(n).ge.1 .and. nparent(n).le.MAXCALL) tname=name(nparent(n)) - if(ntrace.lt.limtrace) write(lu,1020) ntrace,dname,k,level,nparent(n),tname -1020 format(i8,': ',a8,3i5,2x,a8) - flush(lu) - go to 998 - - ! Write out the timer statistics - -40 write(lu,1040) -1040 format(/' Name Time Frac dTime', & - ' dFrac Calls'/58('-')) - - !$ !walk backwards through the database rolling up thread data by call chain - !$ do i=nmax,1,-1 - !$ do j=1,i-1 - !$ l=j - !$ m=i - !$ do while (name(l).eq.name(m)) - !$ l=nparent(l) - !$ m=nparent(m) - !$ if (l.eq.0.or.m.eq.0) exit - !$ end do - !$ if (l.eq.0.and.m.eq.0) then - !$ !same call chain so roll up data - !$ ncall(j)=ncall(j)+ncall(i) - !$ ut(j)=ut(j)+ut(i) - !$ do n=1,nmax - !$ if (nparent(n).eq.i) nparent(n)=j - !$ end do - !$ name(i)=space - !$ exit - !$ end if - !$ end do - !$ end do - - if(k.gt.100) then - ndiv=k-100 - do i=1,nmax - ncall(i)=ncall(i)/ndiv - ut(i)=ut(i)/ndiv - enddo - endif - - total=ut(1) - sum=0. - sumf=0. - call print_root(1) - write(lu,1070) sum,sumf -1070 format(58('-')/32x,f10.3,f6.2) - nmax=0 - eps=0.000001 - ntrace=0 - level=0 - onlevel(0)=0 - -998 flush(lu) - -999 continue - - !$omp end critical(timer) - return - end subroutine default_timer - - recursive subroutine print_root(i) - implicit none - integer, intent(in) :: i - character(len=16) :: sname - real :: dutf, utf - integer :: j, kk - - if (i.le.nmax) then - if (name(i).ne.space) then - dut=ut(i) - do j=i,nmax - if (name(j).ne.space.and.nparent(j).eq.i) dut=dut-ut(j) - enddo - if(dut.lt.0.0) dut=0.0 - utf=ut(i)/total - dutf=dut/total - sum=sum+dut - sumf=sumf+dutf - kk=nlevel(i) - sname=space(1:kk)//name(i)//space(1:8-kk) - write(lu,2000) sname,ut(i),utf,dut,dutf,ncall(i) -2000 format(a16,2(f10.3,f6.2),i9) - do j=i,nmax - if(nparent(j).eq.i) call print_root(j) - enddo - end if - end if - return - end subroutine print_root - - subroutine init_timer (filename) - use, intrinsic :: iso_c_binding, only: c_char - use timer_module, only: timer - implicit none - character(len=*), optional, intent(in) :: filename - include 'timer_common.inc' - data level/0/, onlevel/11 * 0/ - if (present (filename)) then - open (newunit=lu, file=filename, status='unknown') - else - open (newunit=lu, file='timer.out', status='unknown') - end if - timer => default_timer - end subroutine init_timer - - subroutine fini_timer () - use timer_module, only: timer, null_timer - implicit none - timer => null_timer - close (lu) - end subroutine fini_timer - -end module timer_impl +module timer_impl + !$ use omp_lib + use :: iso_c_binding, only: c_ptr + use timer_module, only: timer_callback + implicit none + + public :: init_timer, fini_timer + integer, public :: limtrace=0 +! integer, public :: limtrace=10000000 + + private + + integer, parameter :: MAXCALL=100 + integer :: lu=6 + real :: dut + integer :: i,nmax=0,ncall(MAXCALL),nlevel(MAXCALL),nparent(MAXCALL) + character(len=8) :: name(MAXCALL),space=' ' + logical :: on(MAXCALL) + real :: total,sum,sumf,ut(MAXCALL),ut0(MAXCALL) + !$ integer :: j,l,m,ntid(MAXCALL) + + ! + ! C interoperable callback setup + ! + public :: C_init_timer + abstract interface + subroutine C_timer_callback (context, dname, k) + use, intrinsic :: iso_c_binding, only: c_ptr + implicit none + type(c_ptr), intent(in) :: context + character(len=8), intent(in) :: dname + integer, intent(in) :: k + end subroutine C_timer_callback + end interface + type(c_ptr), private :: the_context + procedure(C_timer_callback), pointer, private :: the_C_callback + +contains + subroutine timer_callback_wrapper (dname, k) + implicit none + character(len=8), intent(in) :: dname + integer, intent(in) :: k + call the_C_callback (the_context, dname, k) + end subroutine timer_callback_wrapper + + subroutine C_init_timer (context, callback) bind(C) + use, intrinsic :: iso_c_binding, only: c_ptr, c_funptr, c_f_procpointer + use iso_c_utilities, only: c_to_f_string + use timer_module, only: timer + implicit none + type(c_ptr), intent(in) :: context + type(c_funptr), intent(in) :: callback + the_context=context + call c_f_procpointer (callback, the_C_callback) + timer => timer_callback_wrapper + end subroutine C_init_timer + + ! + ! default Fortran implementation which is thread safe using OpenMP + ! + subroutine default_timer (dname, k) + + ! Times procedure number n between a call with k=0 (tstart) and with + ! k=1 (tstop). Accumulates sums of these times in array ut (user time). + ! Also traces all calls (for debugging purposes) if limtrace.gt.0 + ! + ! If this is used with OpenMP than the /timer_private/ common + ! block must be copyed into each thread of a thread team by using + ! the copyin() clause on the !$omp parallel directive that creates + ! the team. + + implicit none + + character(len=8), intent(in) :: dname + integer, intent(in) :: k + + real :: ut1,eps=0.000001 + integer :: n,ndiv,ntrace=0 + !$ integer :: tid + character(len=8) :: tname + include 'timer_common.inc' + + !$omp critical(timer) + if(limtrace.lt.0) go to 999 + if(k.gt.1) go to 40 !Check for "all done" (k>1) + onlevel(0)=0 + + !$ tid=omp_get_thread_num() + do n=1,nmax !Check for existing name/parent[/thread] + if(name(n).eq.dname & + !$ .and.ntid(n).eq.tid & + ) then + if (on(n)) then + if (nparent(n).eq.onlevel(level-1)) goto 20 + else + if (nparent(n).eq.onlevel(level)) goto 20 + end if + end if + enddo + + nmax=nmax+1 !This is a new one + n=nmax + !$ ntid(n)=tid + ncall(n)=0 + on(n)=.false. + ut(n)=eps + name(n)=dname + +20 if(k.eq.0) then !Get start times (k=0) + if(on(n)) then + print*,'Error in timer: ',dname,' already on.' + end if + level=level+1 !Increment the level + on(n)=.true. + ! call system_clock(icount,irate) + ! ut0(n)=float(icount)/irate + ! call cpu_time(ut0(n)) + ut0(n)=secnds(0.0) + + ncall(n)=ncall(n)+1 + if(ncall(n).gt.1.and.nlevel(n).ne.level) then + !recursion is happening + ! + !TODO: somehow need to account for this deeper call at the + !shallowest instance in the call chain and this needs to be + !done without incrementing anything here other than counters + !and timers + ! + nlevel(n)=-1 + else + nlevel(n)=level + endif + nparent(n)=onlevel(level-1) + onlevel(level)=n + + else if(k.eq.1) then !Get stop times and accumulate sums. (k=1) + if(on(n)) then + on(n)=.false. + ! call system_clock(icount,irate) + ! ut1=float(icount)/irate + ! call cpu_time(ut1) + ut1=secnds(0.0) + + ut(n)=ut(n)+ut1-ut0(n) + endif + level=level-1 + endif + + ntrace=ntrace+1 + tname='TopLevel' + if(nparent(n).ge.1 .and. nparent(n).le.MAXCALL) tname=name(nparent(n)) + if(ntrace.lt.limtrace) write(lu,1020) ntrace,dname,k,level,nparent(n),tname +1020 format(i8,': ',a8,3i5,2x,a8) + flush(lu) + go to 998 + + ! Write out the timer statistics + +40 write(lu,1040) +1040 format(/' Name Time Frac dTime', & + ' dFrac Calls'/58('-')) + + !$ !walk backwards through the database rolling up thread data by call chain + !$ do i=nmax,1,-1 + !$ do j=1,i-1 + !$ l=j + !$ m=i + !$ do while (name(l).eq.name(m)) + !$ l=nparent(l) + !$ m=nparent(m) + !$ if (l.eq.0.or.m.eq.0) exit + !$ end do + !$ if (l.eq.0.and.m.eq.0) then + !$ !same call chain so roll up data + !$ ncall(j)=ncall(j)+ncall(i) + !$ ut(j)=ut(j)+ut(i) + !$ do n=1,nmax + !$ if (nparent(n).eq.i) nparent(n)=j + !$ end do + !$ name(i)=space + !$ exit + !$ end if + !$ end do + !$ end do + + if(k.gt.100) then + ndiv=k-100 + do i=1,nmax + ncall(i)=ncall(i)/ndiv + ut(i)=ut(i)/ndiv + enddo + endif + + total=ut(1) + sum=0. + sumf=0. + call print_root(1) + write(lu,1070) sum,sumf +1070 format(58('-')/32x,f10.3,f6.2) + nmax=0 + eps=0.000001 + ntrace=0 + level=0 + onlevel(0)=0 + +998 flush(lu) + +999 continue + + !$omp end critical(timer) + return + end subroutine default_timer + + recursive subroutine print_root(i) + implicit none + integer, intent(in) :: i + character(len=16) :: sname + real :: dutf, utf + integer :: j, kk + + if (i.le.nmax) then + if (name(i).ne.space) then + dut=ut(i) + do j=i,nmax + if (name(j).ne.space.and.nparent(j).eq.i) dut=dut-ut(j) + enddo + if(dut.lt.0.0) dut=0.0 + utf=ut(i)/total + dutf=dut/total + sum=sum+dut + sumf=sumf+dutf + kk=nlevel(i) + sname=space(1:kk)//name(i)//space(1:8-kk) + write(lu,2000) sname,ut(i),utf,dut,dutf,ncall(i) +2000 format(a16,2(f10.3,f6.2),i9) + do j=i,nmax + if(nparent(j).eq.i) call print_root(j) + enddo + end if + end if + return + end subroutine print_root + + subroutine init_timer (filename) + use, intrinsic :: iso_c_binding, only: c_char + use timer_module, only: timer + implicit none + character(len=*), optional, intent(in) :: filename + include 'timer_common.inc' + data level/0/, onlevel/11 * 0/ + if (present (filename)) then + open (newunit=lu, file=filename, status='unknown') + else + open (newunit=lu, file='timer.out', status='unknown') + end if + timer => default_timer + end subroutine init_timer + + subroutine fini_timer () + use timer_module, only: timer, null_timer + implicit none + timer => null_timer + close (lu) + end subroutine fini_timer + +end module timer_impl diff --git a/lib/timer_module.f90 b/lib/timer_module.f90 index 40a97671..59675c16 100755 --- a/lib/timer_module.f90 +++ b/lib/timer_module.f90 @@ -1,24 +1,24 @@ -module timer_module - implicit none - - abstract interface - subroutine timer_callback (dname, k) - character(len=8), intent(in) :: dname - integer, intent(in) :: k - end subroutine timer_callback - end interface - - public :: null_timer - procedure(timer_callback), pointer :: timer => null_timer - -contains - ! - ! default Fortran implementation which does nothing - ! - subroutine null_timer (dname, k) - implicit none - character(len=8), intent(in) :: dname - integer, intent(in) :: k - if(dname.eq.'99999999' .and. k.eq.9999) stop !Silence compiler warnings - end subroutine null_timer -end module timer_module +module timer_module + implicit none + + abstract interface + subroutine timer_callback (dname, k) + character(len=8), intent(in) :: dname + integer, intent(in) :: k + end subroutine timer_callback + end interface + + public :: null_timer + procedure(timer_callback), pointer :: timer => null_timer + +contains + ! + ! default Fortran implementation which does nothing + ! + subroutine null_timer (dname, k) + implicit none + character(len=8), intent(in) :: dname + integer, intent(in) :: k + if(dname.eq.'99999999' .and. k.eq.9999) stop !Silence compiler warnings + end subroutine null_timer +end module timer_module diff --git a/lib/timf2.f90 b/lib/timf2.f90 index 582a9bce..bec391e2 100755 --- a/lib/timf2.f90 +++ b/lib/timf2.f90 @@ -1,142 +1,142 @@ -subroutine timf2(x0,k,nfft,nwindow,nb,peaklimit,x1, & - slimit,lstrong,px,nzap) - -! Sequential processing of time-domain I/Q data, using Linrad-like -! "first FFT" and "first backward FFT", treating frequencies with -! strong signals differently. Noise blanking is applied to weak -! signals only. - -! x0 - real input data -! nfft - length of FFTs -! nwindow - 0 for no window, 2 for sin^2 window -! x1 - real 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. 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) - real x0(0:nfft-1),x1(0:nfft-1) - real x(0:MAXFFT-1),xw(0:MAXFFT-1),xs(0:MAXFFT-1) - real xwov(0:MAXNH-1),xsov(0:MAXNH-1) - complex cx(0:MAXFFT-1),cxt(0:MAXFFT-1) - complex cxs(0:MAXFFT-1) !Strong signals - complex cxw(0:MAXFFT-1) !Weak signals - real*4 w(0:MAXFFT-1) - real*4 s(0:MAXNH) - logical*1 lstrong(0:MAXNH),lprev - integer ia(MAXSIGS),ib(MAXSIGS) - logical first - equivalence (x,cx),(xw,cxw),(xs,cxs) - data first/.true./ - data k0/99999999/ - save - - 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 - xsov=0. - xwov=0. - endif - k0=k - - x(0:nfft-1)=x0 - if(nwindow.eq.2) x(0:nfft-1)=w(0:nfft-1)*x(0:nfft-1) - call four2a(cx,nfft,1,-1,0) !First forward FFT, r2c - cxt(0:nh)=cx(0:nh) - -! Identify frequencies with strong signals. - do i=0,nh - p=real(cxt(i))**2 + aimag(cxt(i))**2 - s(i)=p - enddo - ave=sum(s(0:nh))/nh - lstrong(0:nh)=s(0:nh).gt.10.0*ave - - nsigs=0 - lprev=.false. - iwid=1 - ib=-99 - do i=0,nh - 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.nh) ib(nsigs)=nh - 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.nh .or. jb.lt.0 .or. jb.gt.nh) then - cycle - endif - if(jb.eq.-99) jb=ja + min(2*iwid,nh) - lstrong(ja:jb)=.true. - enddo - endif - -! Copy frequency-domain data into array cs (strong) or cw (weak). - do i=0,nh - if(lstrong(i)) then - cxs(i)=fac*cxt(i) - cxw(i)=0. - else - cxw(i)=fac*cxt(i) - cxs(i)=0. - endif - enddo - - call four2a(cxw,nfft,1,1,-1) !Transform weak and strong back - call four2a(cxs,nfft,1,1,-1) !to time domain, separately (c2r) - - if(nwindow.eq.2) then - xw(0:nh-1)=xw(0:nh-1)+xwov(0:nh-1) !Add previous segment's 2nd half - xwov(0:nh-1)=xw(nh:nfft-1) !Save 2nd half - xs(0:nh-1)=xs(0:nh-1)+xsov(0:nh-1) !Ditto for strong signals - xsov(0:nh-1)=xs(nh:nfft-1) - endif - -! Apply noise blanking to weak data - if(nb.ne.0) then - do i=0,kstep-1 - peak=abs(xw(i)) - if(peak.gt.peaklimit) then - xw(i)=0. - nzap=nzap+1 - endif - enddo - endif - -! Compute power levels from weak data only - do i=0,kstep-1 - px=px + xw(i)**2 - enddo - - x1(0:kstep-1)=xw(0:kstep-1) + xs(0:kstep-1) !Recombine weak + strong - - return -end subroutine timf2 +subroutine timf2(x0,k,nfft,nwindow,nb,peaklimit,x1, & + slimit,lstrong,px,nzap) + +! Sequential processing of time-domain I/Q data, using Linrad-like +! "first FFT" and "first backward FFT", treating frequencies with +! strong signals differently. Noise blanking is applied to weak +! signals only. + +! x0 - real input data +! nfft - length of FFTs +! nwindow - 0 for no window, 2 for sin^2 window +! x1 - real 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. 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) + real x0(0:nfft-1),x1(0:nfft-1) + real x(0:MAXFFT-1),xw(0:MAXFFT-1),xs(0:MAXFFT-1) + real xwov(0:MAXNH-1),xsov(0:MAXNH-1) + complex cx(0:MAXFFT-1),cxt(0:MAXFFT-1) + complex cxs(0:MAXFFT-1) !Strong signals + complex cxw(0:MAXFFT-1) !Weak signals + real*4 w(0:MAXFFT-1) + real*4 s(0:MAXNH) + logical*1 lstrong(0:MAXNH),lprev + integer ia(MAXSIGS),ib(MAXSIGS) + logical first + equivalence (x,cx),(xw,cxw),(xs,cxs) + data first/.true./ + data k0/99999999/ + save + + 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 + xsov=0. + xwov=0. + endif + k0=k + + x(0:nfft-1)=x0 + if(nwindow.eq.2) x(0:nfft-1)=w(0:nfft-1)*x(0:nfft-1) + call four2a(cx,nfft,1,-1,0) !First forward FFT, r2c + cxt(0:nh)=cx(0:nh) + +! Identify frequencies with strong signals. + do i=0,nh + p=real(cxt(i))**2 + aimag(cxt(i))**2 + s(i)=p + enddo + ave=sum(s(0:nh))/nh + lstrong(0:nh)=s(0:nh).gt.10.0*ave + + nsigs=0 + lprev=.false. + iwid=1 + ib=-99 + do i=0,nh + 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.nh) ib(nsigs)=nh + 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.nh .or. jb.lt.0 .or. jb.gt.nh) then + cycle + endif + if(jb.eq.-99) jb=ja + min(2*iwid,nh) + lstrong(ja:jb)=.true. + enddo + endif + +! Copy frequency-domain data into array cs (strong) or cw (weak). + do i=0,nh + if(lstrong(i)) then + cxs(i)=fac*cxt(i) + cxw(i)=0. + else + cxw(i)=fac*cxt(i) + cxs(i)=0. + endif + enddo + + call four2a(cxw,nfft,1,1,-1) !Transform weak and strong back + call four2a(cxs,nfft,1,1,-1) !to time domain, separately (c2r) + + if(nwindow.eq.2) then + xw(0:nh-1)=xw(0:nh-1)+xwov(0:nh-1) !Add previous segment's 2nd half + xwov(0:nh-1)=xw(nh:nfft-1) !Save 2nd half + xs(0:nh-1)=xs(0:nh-1)+xsov(0:nh-1) !Ditto for strong signals + xsov(0:nh-1)=xs(nh:nfft-1) + endif + +! Apply noise blanking to weak data + if(nb.ne.0) then + do i=0,kstep-1 + peak=abs(xw(i)) + if(peak.gt.peaklimit) then + xw(i)=0. + nzap=nzap+1 + endif + enddo + endif + +! Compute power levels from weak data only + do i=0,kstep-1 + px=px + xw(i)**2 + enddo + + x1(0:kstep-1)=xw(0:kstep-1) + xs(0:kstep-1) !Recombine weak + strong + + return +end subroutine timf2 diff --git a/lib/tstrig.c b/lib/tstrig.c index b8c66a19..2e77fea5 100755 --- a/lib/tstrig.c +++ b/lib/tstrig.c @@ -1,26 +1,26 @@ -#include "config.h" -#include -#include -#include -#include "tstrig.h" - -int set_conf(RIG *my_rig, char *conf_parms); - -int rig_control(rig_model_t my_model, int verbose); - -int main (int argc, char *argv[]) -{ - rig_model_t my_model = RIG_MODEL_DUMMY; - int verbose=0; - - my_model=214; - rig_control(my_model,verbose); - return 0; -} - -/* -gcc -c -Wall -I../include rig_control.c -gcc -c -Wall -I../include tstrig.c -gcc -o tstrig.exe -Wl,--enable-auto-import tstrig.o rig_control.o libhamlib.dll.a -strip tstrig.exe -*/ +#include "config.h" +#include +#include +#include +#include "tstrig.h" + +int set_conf(RIG *my_rig, char *conf_parms); + +int rig_control(rig_model_t my_model, int verbose); + +int main (int argc, char *argv[]) +{ + rig_model_t my_model = RIG_MODEL_DUMMY; + int verbose=0; + + my_model=214; + rig_control(my_model,verbose); + return 0; +} + +/* +gcc -c -Wall -I../include rig_control.c +gcc -c -Wall -I../include tstrig.c +gcc -o tstrig.exe -Wl,--enable-auto-import tstrig.o rig_control.o libhamlib.dll.a +strip tstrig.exe +*/ diff --git a/lib/tstrig.h b/lib/tstrig.h index d9ae974f..ce62d3d7 100755 --- a/lib/tstrig.h +++ b/lib/tstrig.h @@ -1,50 +1,50 @@ -/* - * rigctl_parse.h - (C) Stephane Fillod 2000-2010 - * - * This program test/control a radio using Hamlib. - * It takes commands in interactive mode as well as - * from command line options. - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef RIGCTL_PARSE_H -#define RIGCTL_PARSE_H - -#include -#include - -/* - * external prototype - */ - -int dumpcaps (RIG *, FILE *); -int dumpconf (RIG *, FILE *); - -/* - * Prototypes - */ -void usage_rig(FILE *); -void version(); -void list_models(); -int dump_chan(FILE *, RIG*, channel_t*); -int print_conf_list(const struct confparams *cfp, rig_ptr_t data); -int set_conf(RIG *my_rig, char *conf_parms); - -int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc); - -#endif /* RIGCTL_PARSE_H */ +/* + * rigctl_parse.h - (C) Stephane Fillod 2000-2010 + * + * This program test/control a radio using Hamlib. + * It takes commands in interactive mode as well as + * from command line options. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef RIGCTL_PARSE_H +#define RIGCTL_PARSE_H + +#include +#include + +/* + * external prototype + */ + +int dumpcaps (RIG *, FILE *); +int dumpconf (RIG *, FILE *); + +/* + * Prototypes + */ +void usage_rig(FILE *); +void version(); +void list_models(); +int dump_chan(FILE *, RIG*, channel_t*); +int print_conf_list(const struct confparams *cfp, rig_ptr_t data); +int set_conf(RIG *my_rig, char *conf_parms); + +int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc); + +#endif /* RIGCTL_PARSE_H */ diff --git a/lib/tweak1.f90 b/lib/tweak1.f90 index 8d72be8d..c62c4087 100755 --- a/lib/tweak1.f90 +++ b/lib/tweak1.f90 @@ -1,23 +1,23 @@ -subroutine tweak1(ca,jz,f0,cb) - -! Shift frequency of analytic signal ca, with output to cb - - complex ca(jz),cb(jz) - real*8 twopi - complex*16 w,wstep - complex w4 - data twopi/0.d0/ - save twopi - - if(twopi.eq.0.d0) twopi=8.d0*atan(1.d0) - w=1.d0 - dphi=twopi*f0/12000.d0 - wstep=cmplx(cos(dphi),sin(dphi)) - do i=1,jz - w=w*wstep - w4=w - cb(i)=w4*ca(i) - enddo - - return -end subroutine tweak1 +subroutine tweak1(ca,jz,f0,cb) + +! Shift frequency of analytic signal ca, with output to cb + + complex ca(jz),cb(jz) + real*8 twopi + complex*16 w,wstep + complex w4 + data twopi/0.d0/ + save twopi + + if(twopi.eq.0.d0) twopi=8.d0*atan(1.d0) + w=1.d0 + dphi=twopi*f0/12000.d0 + wstep=cmplx(cos(dphi),sin(dphi)) + do i=1,jz + w=w*wstep + w4=w + cb(i)=w4*ca(i) + enddo + + return +end subroutine tweak1 diff --git a/lib/types.f90 b/lib/types.f90 index 456938b4..0fb82320 100755 --- a/lib/types.f90 +++ b/lib/types.f90 @@ -1,18 +1,18 @@ -module types - use, intrinsic :: iso_fortran_env - implicit none - - ! use the Fortran 2008 intrinsic constants to define real kinds - integer, parameter :: sp = REAL32 - integer, parameter :: dp = REAL64 - integer, parameter :: qp = REAL128 - - type q3list - character*6 call - character*4 grid - integer nsec - integer nfreq - integer moonel - end type q3list - -end module types +module types + use, intrinsic :: iso_fortran_env + implicit none + + ! use the Fortran 2008 intrinsic constants to define real kinds + integer, parameter :: sp = REAL32 + integer, parameter :: dp = REAL64 + integer, parameter :: qp = REAL128 + + type q3list + character*6 call + character*4 grid + integer nsec + integer nfreq + integer moonel + end type q3list + +end module types diff --git a/lib/update_msk40_hasharray.f90 b/lib/update_msk40_hasharray.f90 index 04758fe3..64886b41 100755 --- a/lib/update_msk40_hasharray.f90 +++ b/lib/update_msk40_hasharray.f90 @@ -1,25 +1,25 @@ -subroutine update_msk40_hasharray(nhasharray) - - use packjt77 - character*37 hashmsg - integer nhasharray(MAXRECENT,MAXRECENT) - - nhasharray=-1 - do i=1,MAXRECENT - do j=i+1,MAXRECENT - if( recent_calls(i)(1:1) .ne. ' ' .and. recent_calls(j)(1:1) .ne. ' ' ) then - hashmsg=trim(recent_calls(i))//' '//trim(recent_calls(j)) - call fmtmsg(hashmsg,iz) - call hash(hashmsg,37,ihash) - ihash=iand(ihash,4095) - nhasharray(i,j)=ihash - hashmsg=trim(recent_calls(j))//' '//trim(recent_calls(i)) - call fmtmsg(hashmsg,iz) - call hash(hashmsg,37,ihash) - ihash=iand(ihash,4095) - nhasharray(j,i)=ihash - endif - enddo - enddo - -end subroutine update_msk40_hasharray +subroutine update_msk40_hasharray(nhasharray) + + use packjt77 + character*37 hashmsg + integer nhasharray(MAXRECENT,MAXRECENT) + + nhasharray=-1 + do i=1,MAXRECENT + do j=i+1,MAXRECENT + if( recent_calls(i)(1:1) .ne. ' ' .and. recent_calls(j)(1:1) .ne. ' ' ) then + hashmsg=trim(recent_calls(i))//' '//trim(recent_calls(j)) + call fmtmsg(hashmsg,iz) + call hash(hashmsg,37,ihash) + ihash=iand(ihash,4095) + nhasharray(i,j)=ihash + hashmsg=trim(recent_calls(j))//' '//trim(recent_calls(i)) + call fmtmsg(hashmsg,iz) + call hash(hashmsg,37,ihash) + ihash=iand(ihash,4095) + nhasharray(j,i)=ihash + endif + enddo + enddo + +end subroutine update_msk40_hasharray diff --git a/lib/update_recent_calls.f90 b/lib/update_recent_calls.f90 index 7772d4d4..e67ff385 100755 --- a/lib/update_recent_calls.f90 +++ b/lib/update_recent_calls.f90 @@ -1,19 +1,19 @@ -subroutine update_recent_calls(call,calls_hrd,nsize) -character*12 call,calls_hrd(nsize) - - new=1 - do ic=1,nsize - if( calls_hrd(ic).eq.call ) then - new=0 - endif - enddo - - if( new.eq.1 ) then - do ic=nsize-1,1,-1 - calls_hrd(ic+1)(1:12)=calls_hrd(ic)(1:12) - enddo - calls_hrd(1)(1:12)=call(1:12) - endif - - return - end subroutine update_recent_calls +subroutine update_recent_calls(call,calls_hrd,nsize) +character*12 call,calls_hrd(nsize) + + new=1 + do ic=1,nsize + if( calls_hrd(ic).eq.call ) then + new=0 + endif + enddo + + if( new.eq.1 ) then + do ic=nsize-1,1,-1 + calls_hrd(ic+1)(1:12)=calls_hrd(ic)(1:12) + enddo + calls_hrd(1)(1:12)=call(1:12) + endif + + return + end subroutine update_recent_calls diff --git a/lib/usleep.c b/lib/usleep.c index 4fc72381..6fbc98c6 100755 --- a/lib/usleep.c +++ b/lib/usleep.c @@ -1,8 +1,8 @@ -#include -#include "sleep.h" - -/* usleep(3) */ -void usleep_(unsigned long *microsec) -{ - usleep(*microsec); -} +#include +#include "sleep.h" + +/* usleep(3) */ +void usleep_(unsigned long *microsec) +{ + usleep(*microsec); +} diff --git a/lib/vit213.c b/lib/vit213.c index 8a9a83eb..93f803ab 100755 --- a/lib/vit213.c +++ b/lib/vit213.c @@ -1,221 +1,221 @@ -/* Viterbi decoder for arbitrary convolutional code - * viterbi27 and viterbi37 for the r=1/2 and r=1/3 K=7 codes are faster - * Copyright 1999 Phil Karn, KA9Q - * Modifications by Joe Taylor, K1JT - * May be used under the terms of the GNU Public License - */ - -#include - -/* Select code here */ - -#define V213 - -#ifdef V213 -#define K 13 /* Constraint length */ -#define N 2 /* Number of symbols per data bit */ -#define Polys Poly213 /* Select polynomials here */ -#endif - -/* Rate 1/2 codes */ -unsigned int Poly213[] = {012767,016461}; /* k = 13 */ - -#include - -#define LONGBITS 32 -#define LOGLONGBITS 5 - -#undef max -#define max(x,y) ((x) > (y) ? (x) : (y)) -#define D (1 << max(0,K-LOGLONGBITS-1)) -#define MAXNBITS 200 /* Maximum frame size (user bits) */ - -extern unsigned char Partab[]; /* Parity lookup table */ - -int Syms[1 << K]; - - -int parity(int x) -{ - x ^= (x >> 16); - x ^= (x >> 8); - return Partab[x & 0xff]; -} - -/* Convolutionally encode data into binary symbols */ -int enc213(unsigned char symbols[], unsigned char data[], - unsigned int nbytes, unsigned int startstate, - unsigned int endstate) -{ - unsigned int i,j,k; - int l,n=-1; - unsigned int encstate = startstate; - - for(k=0; k=0;l--){ - encstate = (encstate + encstate) + ((data[k] >> l) & 1); - for(j=0;j> i) & 1); - for(j=0;j> (N-j-1)) & 1][symbols[j]]; - } - } - symbols += N; - /* Run the add-compare-select operations */ - mask = 1; - for(i=0;i< 1 << (K-1);i+=2){ - int b1,b2; - - b1 = mets[Syms[i]]; - nmetric[i] = m0 = cmetric[i/2] + b1; - b2 = mets[Syms[i+1]]; - b1 -= b2; - m1 = cmetric[(i/2) + (1<<(K-2))] + b2; - - if(m1 > m0){ - nmetric[i] = m1; - *pp |= mask; - } - - m0 -= b1; - nmetric[i+1] = m0; - m1 += b1; - - if(m1 > m0){ - nmetric[i+1] = m1; - *pp |= mask << 1; - } - - mask <<= 2; - if(mask == 0){ - mask = 1; - pp++; - ipp++; - } - } - if(mask != 1){ - pp++; - ipp++; - } - if(++bitcnt == (int)nbits){ - *metric = nmetric[endstate]; - break; - } - memcpy(cmetric,nmetric,sizeof(cmetric)); - } - - /* Chain back from terminal state to produce decoded data */ - if(data == NULL) - return 0;/* Discard output */ - memset(data,0,(nbits+7)/8); /* round up in case nbits % 8 != 0 */ - - for(i=nbits-1;i >= 0;i--){ - // int a0,a1; - pp -= D; - ipp -= D; - m0=endstate >> LOGLONGBITS; - m1=1L << (endstate & (LONGBITS-1)); - if(pp[m0] & m1) { - // a0=nmetric[endstate]; - endstate |= (1 << (K-1)); - // a1=nmetric[endstate]; - data[i>>3] |= 0x80 >> (i&7); - // printf("B %d %d %d %d\n",*metric,i,a0,a1); - } - endstate >>= 1; - } - return 0; -} - -// Wrapper for calling "encode" from Fortran: -void enc213_( -unsigned char data[], // User data, 8 bits per byte -int *nbits, // Number of user bits -unsigned char symbols[], // Encoded one-bit symbols, 8 per byte -int *nsymbols, // Number of symbols -int *kk, // K -int *nn) // N -{ - int nbytes; - nbytes=(*nbits+7)/8; // Always encode multiple of 8 information bits - enc213(symbols,data,nbytes,0,0); // Do the encoding - *nsymbols=(*nbits+K-1)*N; // Return number of encoded symbols - *kk=K; - *nn=N; -} - -// Wrapper for calling "viterbi" from Fortran: -void vit213_( -unsigned char symbols[], /* Raw deinterleaved input symbols */ -unsigned int *Nbits, /* Number of decoded information bits */ -int mettab[2][256], /* Metric table, [sent sym][rx symbol] */ -unsigned char ddec[], /* Decoded output data */ -int *Metric /* Final path metric (bigger is better) */ -){ - int metric; - vit213(&metric,ddec,symbols,*Nbits,mettab,0,0); - *Metric=metric; -} - +/* Viterbi decoder for arbitrary convolutional code + * viterbi27 and viterbi37 for the r=1/2 and r=1/3 K=7 codes are faster + * Copyright 1999 Phil Karn, KA9Q + * Modifications by Joe Taylor, K1JT + * May be used under the terms of the GNU Public License + */ + +#include + +/* Select code here */ + +#define V213 + +#ifdef V213 +#define K 13 /* Constraint length */ +#define N 2 /* Number of symbols per data bit */ +#define Polys Poly213 /* Select polynomials here */ +#endif + +/* Rate 1/2 codes */ +unsigned int Poly213[] = {012767,016461}; /* k = 13 */ + +#include + +#define LONGBITS 32 +#define LOGLONGBITS 5 + +#undef max +#define max(x,y) ((x) > (y) ? (x) : (y)) +#define D (1 << max(0,K-LOGLONGBITS-1)) +#define MAXNBITS 200 /* Maximum frame size (user bits) */ + +extern unsigned char Partab[]; /* Parity lookup table */ + +int Syms[1 << K]; + + +int parity(int x) +{ + x ^= (x >> 16); + x ^= (x >> 8); + return Partab[x & 0xff]; +} + +/* Convolutionally encode data into binary symbols */ +int enc213(unsigned char symbols[], unsigned char data[], + unsigned int nbytes, unsigned int startstate, + unsigned int endstate) +{ + unsigned int i,j,k; + int l,n=-1; + unsigned int encstate = startstate; + + for(k=0; k=0;l--){ + encstate = (encstate + encstate) + ((data[k] >> l) & 1); + for(j=0;j> i) & 1); + for(j=0;j> (N-j-1)) & 1][symbols[j]]; + } + } + symbols += N; + /* Run the add-compare-select operations */ + mask = 1; + for(i=0;i< 1 << (K-1);i+=2){ + int b1,b2; + + b1 = mets[Syms[i]]; + nmetric[i] = m0 = cmetric[i/2] + b1; + b2 = mets[Syms[i+1]]; + b1 -= b2; + m1 = cmetric[(i/2) + (1<<(K-2))] + b2; + + if(m1 > m0){ + nmetric[i] = m1; + *pp |= mask; + } + + m0 -= b1; + nmetric[i+1] = m0; + m1 += b1; + + if(m1 > m0){ + nmetric[i+1] = m1; + *pp |= mask << 1; + } + + mask <<= 2; + if(mask == 0){ + mask = 1; + pp++; + ipp++; + } + } + if(mask != 1){ + pp++; + ipp++; + } + if(++bitcnt == (int)nbits){ + *metric = nmetric[endstate]; + break; + } + memcpy(cmetric,nmetric,sizeof(cmetric)); + } + + /* Chain back from terminal state to produce decoded data */ + if(data == NULL) + return 0;/* Discard output */ + memset(data,0,(nbits+7)/8); /* round up in case nbits % 8 != 0 */ + + for(i=nbits-1;i >= 0;i--){ + // int a0,a1; + pp -= D; + ipp -= D; + m0=endstate >> LOGLONGBITS; + m1=1L << (endstate & (LONGBITS-1)); + if(pp[m0] & m1) { + // a0=nmetric[endstate]; + endstate |= (1 << (K-1)); + // a1=nmetric[endstate]; + data[i>>3] |= 0x80 >> (i&7); + // printf("B %d %d %d %d\n",*metric,i,a0,a1); + } + endstate >>= 1; + } + return 0; +} + +// Wrapper for calling "encode" from Fortran: +void enc213_( +unsigned char data[], // User data, 8 bits per byte +int *nbits, // Number of user bits +unsigned char symbols[], // Encoded one-bit symbols, 8 per byte +int *nsymbols, // Number of symbols +int *kk, // K +int *nn) // N +{ + int nbytes; + nbytes=(*nbits+7)/8; // Always encode multiple of 8 information bits + enc213(symbols,data,nbytes,0,0); // Do the encoding + *nsymbols=(*nbits+K-1)*N; // Return number of encoded symbols + *kk=K; + *nn=N; +} + +// Wrapper for calling "viterbi" from Fortran: +void vit213_( +unsigned char symbols[], /* Raw deinterleaved input symbols */ +unsigned int *Nbits, /* Number of decoded information bits */ +int mettab[2][256], /* Metric table, [sent sym][rx symbol] */ +unsigned char ddec[], /* Decoded output data */ +int *Metric /* Final path metric (bigger is better) */ +){ + int metric; + vit213(&metric,ddec,symbols,*Nbits,mettab,0,0); + *Metric=metric; +} + diff --git a/lib/vit216.c b/lib/vit216.c index 7f90f853..fc0c5a76 100755 --- a/lib/vit216.c +++ b/lib/vit216.c @@ -1,219 +1,219 @@ -/* Viterbi decoder for arbitrary convolutional code - * viterbi27 and viterbi37 for the r=1/2 and r=1/3 K=7 codes are faster - * Copyright 1999 Phil Karn, KA9Q - * May be used under the terms of the GNU Public License - */ - -/* Select code here */ - -#define V216 - - -#ifdef V216 -#define K 16 /* Constraint length */ -#define N 2 /* Number of symbols per data bit */ -#define Polys Poly216 /* Select polynomials here */ -#endif - -/* Rate 1/2 codes */ -unsigned int Poly216[] = {0126723, 0152711}; /* k = 16 */ - -#include -#include - -#define LONGBITS 32 -#define LOGLONGBITS 5 - -#undef max -#define max(x,y) ((x) > (y) ? (x) : (y)) -#define D (1 << max(0,K-LOGLONGBITS-1)) -#define MAXNBITS 200 /* Maximum frame size (user bits) */ - -extern unsigned char Partab[]; /* Parity lookup table */ - -int Syms[1 << K]; -int VDInit = 0; - -int parity(int x) -{ - x ^= (x >> 16); - x ^= (x >> 8); - return Partab[x & 0xff]; -} - -// Wrapper for calling "encode" from Fortran: -//void __stdcall ENCODE( -void enc216_( -unsigned char data[], // User data, 8 bits per byte -int *nbits, // Number of user bits -unsigned char symbols[], // Encoded one-bit symbols, 8 per byte -int *nsymbols, // Number of symbols -int *kk, // K -int *nn) // N -{ - int nbytes; - nbytes=(*nbits+7)/8; // Always encode multiple of 8 information bits - enc216(symbols,data,nbytes,0,0); // Do the encoding - *nsymbols=(*nbits+K-1)*N; // Return number of encoded symbols - *kk=K; - *nn=N; -} - -/* Convolutionally encode data into binary symbols */ - enc216(unsigned char symbols[], unsigned char data[], - unsigned int nbytes, unsigned int startstate, - unsigned int endstate) -{ - int i,j,k,n=-1; - unsigned int encstate = startstate; - - for(k=0; k=0;i--){ - encstate = (encstate + encstate) + ((data[k] >> i) & 1); - for(j=0;j> i) & 1); - for(j=0;j> (N-j-1)) & 1][symbols[j]]; - } - } - symbols += N; - /* Run the add-compare-select operations */ - mask = 1; - for(i=0;i< 1 << (K-1);i+=2){ - int b1,b2; - - b1 = mets[Syms[i]]; - nmetric[i] = m0 = cmetric[i/2] + b1; - b2 = mets[Syms[i+1]]; - b1 -= b2; - m1 = cmetric[(i/2) + (1<<(K-2))] + b2; - - if(m1 > m0){ - nmetric[i] = m1; - *pp |= mask; - } - - m0 -= b1; - nmetric[i+1] = m0; - m1 += b1; - - if(m1 > m0){ - nmetric[i+1] = m1; - *pp |= mask << 1; - } - - mask <<= 2; - if(mask == 0){ - mask = 1; - pp++; - ipp++; - } - } - if(mask != 1){ - pp++; - ipp++; - } - if(++bitcnt == nbits){ - *metric = nmetric[endstate]; - break; - } - memcpy(cmetric,nmetric,sizeof(cmetric)); - } - - /* Chain back from terminal state to produce decoded data */ - if(data == NULL) - return 0;/* Discard output */ - memset(data,0,(nbits+7)/8); /* round up in case nbits % 8 != 0 */ - - for(i=nbits-1;i >= 0;i--){ - // int a0,a1; - pp -= D; - ipp -= D; - m0=endstate >> LOGLONGBITS; - m1=1L << (endstate & (LONGBITS-1)); - if(pp[m0] & m1) { - // a0=nmetric[endstate]; - endstate |= (1 << (K-1)); - // a1=nmetric[endstate]; - data[i>>3] |= 0x80 >> (i&7); - // printf("B %d %d %d %d\n",*metric,i,a0,a1); - } - endstate >>= 1; - } - return 0; -} +/* Viterbi decoder for arbitrary convolutional code + * viterbi27 and viterbi37 for the r=1/2 and r=1/3 K=7 codes are faster + * Copyright 1999 Phil Karn, KA9Q + * May be used under the terms of the GNU Public License + */ + +/* Select code here */ + +#define V216 + + +#ifdef V216 +#define K 16 /* Constraint length */ +#define N 2 /* Number of symbols per data bit */ +#define Polys Poly216 /* Select polynomials here */ +#endif + +/* Rate 1/2 codes */ +unsigned int Poly216[] = {0126723, 0152711}; /* k = 16 */ + +#include +#include + +#define LONGBITS 32 +#define LOGLONGBITS 5 + +#undef max +#define max(x,y) ((x) > (y) ? (x) : (y)) +#define D (1 << max(0,K-LOGLONGBITS-1)) +#define MAXNBITS 200 /* Maximum frame size (user bits) */ + +extern unsigned char Partab[]; /* Parity lookup table */ + +int Syms[1 << K]; +int VDInit = 0; + +int parity(int x) +{ + x ^= (x >> 16); + x ^= (x >> 8); + return Partab[x & 0xff]; +} + +// Wrapper for calling "encode" from Fortran: +//void __stdcall ENCODE( +void enc216_( +unsigned char data[], // User data, 8 bits per byte +int *nbits, // Number of user bits +unsigned char symbols[], // Encoded one-bit symbols, 8 per byte +int *nsymbols, // Number of symbols +int *kk, // K +int *nn) // N +{ + int nbytes; + nbytes=(*nbits+7)/8; // Always encode multiple of 8 information bits + enc216(symbols,data,nbytes,0,0); // Do the encoding + *nsymbols=(*nbits+K-1)*N; // Return number of encoded symbols + *kk=K; + *nn=N; +} + +/* Convolutionally encode data into binary symbols */ + enc216(unsigned char symbols[], unsigned char data[], + unsigned int nbytes, unsigned int startstate, + unsigned int endstate) +{ + int i,j,k,n=-1; + unsigned int encstate = startstate; + + for(k=0; k=0;i--){ + encstate = (encstate + encstate) + ((data[k] >> i) & 1); + for(j=0;j> i) & 1); + for(j=0;j> (N-j-1)) & 1][symbols[j]]; + } + } + symbols += N; + /* Run the add-compare-select operations */ + mask = 1; + for(i=0;i< 1 << (K-1);i+=2){ + int b1,b2; + + b1 = mets[Syms[i]]; + nmetric[i] = m0 = cmetric[i/2] + b1; + b2 = mets[Syms[i+1]]; + b1 -= b2; + m1 = cmetric[(i/2) + (1<<(K-2))] + b2; + + if(m1 > m0){ + nmetric[i] = m1; + *pp |= mask; + } + + m0 -= b1; + nmetric[i+1] = m0; + m1 += b1; + + if(m1 > m0){ + nmetric[i+1] = m1; + *pp |= mask << 1; + } + + mask <<= 2; + if(mask == 0){ + mask = 1; + pp++; + ipp++; + } + } + if(mask != 1){ + pp++; + ipp++; + } + if(++bitcnt == nbits){ + *metric = nmetric[endstate]; + break; + } + memcpy(cmetric,nmetric,sizeof(cmetric)); + } + + /* Chain back from terminal state to produce decoded data */ + if(data == NULL) + return 0;/* Discard output */ + memset(data,0,(nbits+7)/8); /* round up in case nbits % 8 != 0 */ + + for(i=nbits-1;i >= 0;i--){ + // int a0,a1; + pp -= D; + ipp -= D; + m0=endstate >> LOGLONGBITS; + m1=1L << (endstate & (LONGBITS-1)); + if(pp[m0] & m1) { + // a0=nmetric[endstate]; + endstate |= (1 << (K-1)); + // a1=nmetric[endstate]; + data[i>>3] |= 0x80 >> (i&7); + // printf("B %d %d %d %d\n",*metric,i,a0,a1); + } + endstate >>= 1; + } + return 0; +} diff --git a/lib/wav11.f90 b/lib/wav11.f90 index dbdab27c..1311d251 100755 --- a/lib/wav11.f90 +++ b/lib/wav11.f90 @@ -1,27 +1,27 @@ -subroutine wav11(d2,npts,dd) - -! Convert i*2 data sampled at 12000 Hz to r*4 sampled at 11025 Hz. - - parameter (NZ11=60*11025,NZ12=60*12000) - parameter (NFFT1=64*12000,NFFT2=64*11025) - integer*2 d2(NZ12) - real*4 dd(NZ11) - real x(NFFT1) - complex cx(0:NFFT1/2) - equivalence (x,cx) - save x,cx - - jz=min(NZ12,npts) - x(1:jz)=d2(1:jz) - x(jz+1:)=0.0 - call four2a(cx,nfft1,1,-1,0) !Forward FFT, r2c - df=12000.0/NFFT1 - ia=5000.0/df - cx(ia:)=0.0 - call four2a(cx,nfft2,1,1,-1) !Inverse FFT, c2r - npts=jz*11025.0/12000.0 - fac=1.e-6 - dd(1:npts)=fac*x(1:npts) - - return -end subroutine wav11 +subroutine wav11(d2,npts,dd) + +! Convert i*2 data sampled at 12000 Hz to r*4 sampled at 11025 Hz. + + parameter (NZ11=60*11025,NZ12=60*12000) + parameter (NFFT1=64*12000,NFFT2=64*11025) + integer*2 d2(NZ12) + real*4 dd(NZ11) + real x(NFFT1) + complex cx(0:NFFT1/2) + equivalence (x,cx) + save x,cx + + jz=min(NZ12,npts) + x(1:jz)=d2(1:jz) + x(jz+1:)=0.0 + call four2a(cx,nfft1,1,-1,0) !Forward FFT, r2c + df=12000.0/NFFT1 + ia=5000.0/df + cx(ia:)=0.0 + call four2a(cx,nfft2,1,1,-1) !Inverse FFT, c2r + npts=jz*11025.0/12000.0 + fac=1.e-6 + dd(1:npts)=fac*x(1:npts) + + return +end subroutine wav11 diff --git a/lib/wav12.f90 b/lib/wav12.f90 index 65ce501a..ff655436 100755 --- a/lib/wav12.f90 +++ b/lib/wav12.f90 @@ -1,49 +1,49 @@ -subroutine wav12(d2,d1,npts,nbitsam2) - -! Convert i*2 or i*1 data at 11025 Hz (from WSJT *.wav files) -! to i*2 data at 12000 Hz. - -! Input: i*2 d2(npts) or i*1 d1(npts) -! i*2 nbitsam2 = 8 or 16 (bits per sample) - -! Output: npts = (12000*npts)/11025 -! i*2 d2(npts) - - parameter (NZ11=60*11025,NZ12=60*12000) - parameter (NFFT1=64*11025,NFFT2=64*12000) - integer*1 d1(NZ11) - integer*1 d1a(NZ11) - integer*1 i1 - integer*2 i2 - integer*2 d2(NZ12) - real x(NFFT2) - complex cx(0:NFFT2/2) - integer*2 nbitsam2 - equivalence (x,cx),(i1,i2) - - jz=min(NZ11,npts) - if(nbitsam2.eq.8) then - jz=min(NZ11,npts) - d1a(1:jz)=d1(1:jz) !d1 and d2 may be same array in calling prog - do i=1,jz !Move data from d1a into d2 - i2=0 - i1=d1a(i) - d2(i)=10*(i2-128) - enddo - endif - - x(1:jz)=d2(1:jz) - x(jz+1:)=0.0 - call four2a(cx,nfft1,1,-1,0) !Forwarxd FFT, r2c - cx(nfft1/2:)=0.0 - call four2a(cx,nfft2,1,1,-1) !Inverse FFT, c2r - - npts=jz*12000.0/11025.0 - fac=1.e-6 -! if(nbitsam2.eq.16) fac=3.e-6 - x=fac*x - d2(1:npts)=nint(x(1:npts)) - if(npts.lt.NZ12) d2(npts+1:NZ12)=0 - - return -end subroutine wav12 +subroutine wav12(d2,d1,npts,nbitsam2) + +! Convert i*2 or i*1 data at 11025 Hz (from WSJT *.wav files) +! to i*2 data at 12000 Hz. + +! Input: i*2 d2(npts) or i*1 d1(npts) +! i*2 nbitsam2 = 8 or 16 (bits per sample) + +! Output: npts = (12000*npts)/11025 +! i*2 d2(npts) + + parameter (NZ11=60*11025,NZ12=60*12000) + parameter (NFFT1=64*11025,NFFT2=64*12000) + integer*1 d1(NZ11) + integer*1 d1a(NZ11) + integer*1 i1 + integer*2 i2 + integer*2 d2(NZ12) + real x(NFFT2) + complex cx(0:NFFT2/2) + integer*2 nbitsam2 + equivalence (x,cx),(i1,i2) + + jz=min(NZ11,npts) + if(nbitsam2.eq.8) then + jz=min(NZ11,npts) + d1a(1:jz)=d1(1:jz) !d1 and d2 may be same array in calling prog + do i=1,jz !Move data from d1a into d2 + i2=0 + i1=d1a(i) + d2(i)=10*(i2-128) + enddo + endif + + x(1:jz)=d2(1:jz) + x(jz+1:)=0.0 + call four2a(cx,nfft1,1,-1,0) !Forwarxd FFT, r2c + cx(nfft1/2:)=0.0 + call four2a(cx,nfft2,1,1,-1) !Inverse FFT, c2r + + npts=jz*12000.0/11025.0 + fac=1.e-6 +! if(nbitsam2.eq.16) fac=3.e-6 + x=fac*x + d2(1:npts)=nint(x(1:npts)) + if(npts.lt.NZ12) d2(npts+1:NZ12)=0 + + return +end subroutine wav12 diff --git a/lib/wavhdr.f90 b/lib/wavhdr.f90 index d39048f8..6568c1fa 100755 --- a/lib/wavhdr.f90 +++ b/lib/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/lib/wisdom.c b/lib/wisdom.c index d8c357f5..ef008a7d 100755 --- a/lib/wisdom.c +++ b/lib/wisdom.c @@ -1,13 +1,13 @@ -void export_wisdom_(char fname[], int len) -{ - int fftwf_export_wisdom_to_filename(const char *); - fname[len-1]=0; - fftwf_export_wisdom_to_filename(fname); -} - -void import_wisdom_(char fname[], int *success, int len) -{ - int fftwf_import_wisdom_from_filename(const char *); - fname[len-1]=0; - *success = fftwf_import_wisdom_from_filename(fname); -} +void export_wisdom_(char fname[], int len) +{ + int fftwf_export_wisdom_to_filename(const char *); + fname[len-1]=0; + fftwf_export_wisdom_to_filename(fname); +} + +void import_wisdom_(char fname[], int *success, int len) +{ + int fftwf_import_wisdom_from_filename(const char *); + fname[len-1]=0; + *success = fftwf_import_wisdom_from_filename(fname); +} diff --git a/lib/wqencode.f90 b/lib/wqencode.f90 index 74dc776c..59b24706 100755 --- a/lib/wqencode.f90 +++ b/lib/wqencode.f90 @@ -1,65 +1,65 @@ -subroutine wqencode(msg,ntype,data0) - -! Parse and encode a WSPR message. - - use packjt - parameter (MASK15=32767) - character*22 msg - character*12 call1,call2 - character grid4*4 - logical lbad1,lbad2 - integer*1 data0(11) - integer nu(0:9) - data nu/0,-1,1,0,-1,2,1,0,-1,1/ - -! Standard WSPR message (types 0 3 7 10 13 17 ... 60) - i1=index(msg,' ') - i2=index(msg,'/') - i3=index(msg,'<') - call1=msg(:i1-1) - if(i1.lt.3 .or. i1.gt.7 .or. i2.gt.0 .or. i3.gt.0) go to 10 - grid4=msg(i1+1:i1+4) - call packcall(call1,n1,lbad1) - call packgrid(grid4,ng,lbad2) - if(lbad1 .or. lbad2) go to 10 - ndbm=0 - read(msg(i1+5:),*) ndbm - if(ndbm.lt.0) ndbm=0 - if(ndbm.gt.60) ndbm=60 - ndbm=ndbm+nu(mod(ndbm,10)) - n2=128*ng + (ndbm+64) - call pack50(n1,n2,data0) - ntype=ndbm - go to 900 - -10 if(i2.ge.2 .and. i3.lt.1) then - call packpfx(call1,n1,ng,nadd) - ndbm=0 - read(msg(i1+1:),*) ndbm - if(ndbm.lt.0) ndbm=0 - if(ndbm.gt.60) ndbm=60 - ndbm=ndbm+nu(mod(ndbm,10)) - ntype=ndbm + 1 + nadd - n2=128*ng + ntype + 64 - call pack50(n1,n2,data0) - else if(i3.eq.1) then - i4=index(msg,'>') - call1=msg(2:i4-1) - call hash(call1,i4-2,ih) - i5=index(trim(msg(i1+1:)),' ') -! Convert grid to valid callsign format - first character moved to end - call2=msg(i1+2:i1+i5-1)//msg(i1+1:i1+1)//' ' - call packcall(call2,n1,lbad1) - ndbm=0 - read(msg(i1+i5+1:),*) ndbm - if(ndbm.lt.0) ndbm=0 - if(ndbm.gt.60) ndbm=60 - ndbm=ndbm+nu(mod(ndbm,10)) - ntype=-(ndbm+1) - n2=128*ih + ntype + 64 - call pack50(n1,n2,data0) - endif -900 continue - - return -end subroutine wqencode +subroutine wqencode(msg,ntype,data0) + +! Parse and encode a WSPR message. + + use packjt + parameter (MASK15=32767) + character*22 msg + character*12 call1,call2 + character grid4*4 + logical lbad1,lbad2 + integer*1 data0(11) + integer nu(0:9) + data nu/0,-1,1,0,-1,2,1,0,-1,1/ + +! Standard WSPR message (types 0 3 7 10 13 17 ... 60) + i1=index(msg,' ') + i2=index(msg,'/') + i3=index(msg,'<') + call1=msg(:i1-1) + if(i1.lt.3 .or. i1.gt.7 .or. i2.gt.0 .or. i3.gt.0) go to 10 + grid4=msg(i1+1:i1+4) + call packcall(call1,n1,lbad1) + call packgrid(grid4,ng,lbad2) + if(lbad1 .or. lbad2) go to 10 + ndbm=0 + read(msg(i1+5:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + n2=128*ng + (ndbm+64) + call pack50(n1,n2,data0) + ntype=ndbm + go to 900 + +10 if(i2.ge.2 .and. i3.lt.1) then + call packpfx(call1,n1,ng,nadd) + ndbm=0 + read(msg(i1+1:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + ntype=ndbm + 1 + nadd + n2=128*ng + ntype + 64 + call pack50(n1,n2,data0) + else if(i3.eq.1) then + i4=index(msg,'>') + call1=msg(2:i4-1) + call hash(call1,i4-2,ih) + i5=index(trim(msg(i1+1:)),' ') +! Convert grid to valid callsign format - first character moved to end + call2=msg(i1+2:i1+i5-1)//msg(i1+1:i1+1)//' ' + call packcall(call2,n1,lbad1) + ndbm=0 + read(msg(i1+i5+1:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + ntype=-(ndbm+1) + n2=128*ih + ntype + 64 + call pack50(n1,n2,data0) + endif +900 continue + + return +end subroutine wqencode diff --git a/lib/wrapkarn.c b/lib/wrapkarn.c index 1b1a6311..9e0a51ca 100755 --- a/lib/wrapkarn.c +++ b/lib/wrapkarn.c @@ -1,70 +1,70 @@ -#include -#include -#include -#include -#include -#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 +#include +#include +#include +#include +#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 '//grid6//' '//cdbm - else - message='<...> '//grid6//' '//cdbm - endif - endif - - return -end subroutine wqdecode - -subroutine wqencode(msg,ntype,data0) - -! Parse and encode a WSPR message. - - parameter (MASK15=32767) - character*22 msg - character*12 call1,call2 - character grid4*4,grid6*6 - logical lbad1,lbad2 - integer*1 data0(11) - integer nu(0:9) - data nu/0,-1,1,0,-1,2,1,0,-1,1/ - -! Standard WSPR message (types 0 3 7 10 13 17 ... 60) - i1=index(msg,' ') - i2=index(msg,'/') - i3=index(msg,'<') - call1=msg(:i1-1) - if(i1.lt.3 .or. i1.gt.7 .or. i2.gt.0 .or. i3.gt.0) go to 10 - grid4=msg(i1+1:i1+4) - call packcall(call1,n1,lbad1) - call packgrid(grid4,ng,lbad2) - if(lbad1 .or. lbad2) go to 10 - ndbm=0 - read(msg(i1+5:),*) ndbm - if(ndbm.lt.0) ndbm=0 - if(ndbm.gt.60) ndbm=60 - ndbm=ndbm+nu(mod(ndbm,10)) - n2=128*ng + (ndbm+64) - call pack50(n1,n2,data0) - ntype=ndbm - go to 900 - -10 if(i2.ge.2 .and. i3.lt.1) then - call packpfx(call1,n1,ng,nadd) - ndbm=0 - read(msg(i1+1:),*) ndbm - if(ndbm.lt.0) ndbm=0 - if(ndbm.gt.60) ndbm=60 - ndbm=ndbm+nu(mod(ndbm,10)) - ntype=ndbm + 1 + nadd - n2=128*ng + ntype + 64 - call pack50(n1,n2,data0) - else if(i3.eq.1) then - i4=index(msg,'>') - call1=msg(2:i4-1) - call hash(call1,i4-2,ih) - grid6=msg(i1+1:i1+6) - call2=grid6(2:6)//grid6(1:1)//' ' - call packcall(call2,n1,lbad1) - ndbm=0 - read(msg(i1+8:),*) ndbm - if(ndbm.lt.0) ndbm=0 - if(ndbm.gt.60) ndbm=60 - ndbm=ndbm+nu(mod(ndbm,10)) - ntype=-(ndbm+1) - n2=128*ih + ntype + 64 - call pack50(n1,n2,data0) - endif - go to 900 - -900 continue - return -end subroutine wqencode +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +! File Name: wspr_old_subs.f90 +! Description: Utility subroutines from WSPR 2.0 +! +! Copyright (C) 2001-2014 Joseph Taylor, K1JT +! License: GPL-3 +! +! 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 3 of the License, or (at your option) any later +! version. +! +! This program is distributed in the hope that it will be useful, but WITHOUT +! ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +! FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +! details. +! +! You should have received a copy of the GNU General Public License along with +! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +! Street, Fifth Floor, Boston, MA 02110-1301, USA. +! +!------------------------------------------------------------------------------- + +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 encode232(dat,nbytes,symbol,maxsym) + +! Convolutional encoder for a K=32, r=1/2 code. + + integer*1 dat(nbytes) !User data, packed 8 bits per byte + integer*1 symbol(maxsym) !Channel symbols, one bit per byte + integer*1 i1 + +! Layland-Lushbaugh polynomials for a K=32, r=1/2 convolutional code, +! and 8-bit parity lookup table. + + data npoly1/-221228207/,npoly2/-463389625/ + integer*1 partab(0:255) + data partab/ & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0/ + + nstate=0 + k=0 + do j=1,nbytes + do i=7,0,-1 + i1=dat(j) + i4=i1 + if (i4.lt.0) i4=i4+256 + nstate=ior(ishft(nstate,1),iand(ishft(i4,-i),1)) + n=iand(nstate,npoly1) + n=ieor(n,ishft(n,-16)) + k=k+1 + symbol(k)=partab(iand(ieor(n,ishft(n,-8)),255)) + n=iand(nstate,npoly2) + n=ieor(n,ishft(n,-16)) + k=k+1 + symbol(k)=partab(iand(ieor(n,ishft(n,-8)),255)) + enddo + enddo + + return +end subroutine encode232 + +subroutine fano232(symbol,nbits,mettab,ndelta,maxcycles,dat,ncycles,metric,ierr) + +! Sequential decoder for K=32, r=1/2 convolutional code using +! the Fano algorithm. Translated from C routine for same purpose +! written by Phil Karn, KA9Q. + + parameter (MAXBITS=103) + parameter (MAXDAT=13) !(MAXBITS+7)/8 + integer*1 symbol(0:2*MAXBITS-1) + integer*1 dat(MAXDAT) !Decoded user data, 8 bits per byte + integer mettab(0:255,0:1) !Metric table + +! These were the "node" structure in Karn's C code: + integer nstate(0:MAXBITS-1) !Encoder state of next node + integer gamma(0:MAXBITS-1) !Cumulative metric to this node + integer metrics(0:3,0:MAXBITS-1) !Metrics indexed by all possible Tx syms + integer tm(0:1,0:MAXBITS-1) !Sorted metrics for current hypotheses + integer ii(0:MAXBITS-1) !Current branch being tested + + logical noback + +! Layland-Lushbaugh polynomials for a K=32, r=1/2 convolutional code, +! and 8-bit parity lookup table. + + data npoly1/-221228207/,npoly2/-463389625/ + integer*1 partab(0:255) + data partab/ & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0/ + + ntail=nbits-31 + +! Compute all possible branch metrics for each symbol pair. +! This is the only place we actually look at the raw input symbols + i4a=0 + i4b=0 + do np=0,nbits-1 + j=2*np + i4a=symbol(j) + i4b=symbol(j+1) + if (i4a.lt.0) i4a=i4a+256 + if (i4b.lt.0) i4b=i4b+256 + metrics(0,np) = mettab(i4a,0) + mettab(i4b,0) + metrics(1,np) = mettab(i4a,0) + mettab(i4b,1) + metrics(2,np) = mettab(i4a,1) + mettab(i4b,0) + metrics(3,np) = mettab(i4a,1) + mettab(i4b,1) + enddo + + np=0 + nstate(np)=0 + +! Compute and sort branch metrics from the root node + n=iand(nstate(np),npoly1) + n=ieor(n,ishft(n,-16)) + lsym=partab(iand(ieor(n,ishft(n,-8)),255)) + n=iand(nstate(np),npoly2) + n=ieor(n,ishft(n,-16)) + lsym=lsym+lsym+partab(iand(ieor(n,ishft(n,-8)),255)) + m0=metrics(lsym,np) + m1=metrics(ieor(3,lsym),np) + if(m0.gt.m1) then + tm(0,np)=m0 !0-branch has better metric + tm(1,np)=m1 + else + tm(0,np)=m1 !1-branch is better + tm(1,np)=m0 + nstate(np)=nstate(np) + 1 !Set low bit + endif + +! Start with best branch + ii(np)=0 + gamma(np)=0 + nt=0 + +! Start the Fano decoder + do i=1,nbits*maxcycles +! Look forward + ngamma=gamma(np) + tm(ii(np),np) + if(ngamma.ge.nt) then + +! Node is acceptable. If first time visiting this node, tighten threshold: + if(gamma(np).lt.(nt+ndelta)) nt=nt + & + ndelta * ((ngamma-nt)/ndelta) + +! Move forward + gamma(np+1)=ngamma + nstate(np+1)=ishft(nstate(np),1) + np=np+1 + if(np.eq.nbits-1) go to 100 !We're done! + + n=iand(nstate(np),npoly1) + n=ieor(n,ishft(n,-16)) + lsym=partab(iand(ieor(n,ishft(n,-8)),255)) + n=iand(nstate(np),npoly2) + n=ieor(n,ishft(n,-16)) + lsym=lsym+lsym+partab(iand(ieor(n,ishft(n,-8)),255)) + + if(np.ge.ntail) then + tm(0,np)=metrics(lsym,np) !We're in the tail, all zeros + else + m0=metrics(lsym,np) + m1=metrics(ieor(3,lsym),np) + if(m0.gt.m1) then + tm(0,np)=m0 !0-branch has better metric + tm(1,np)=m1 + else + tm(0,np)=m1 !1-branch is better + tm(1,np)=m0 + nstate(np)=nstate(np) + 1 !Set low bit + endif + endif + + ii(np)=0 !Start with best branch + go to 99 + endif + +! Threshold violated, can't go forward +10 noback=.false. + if(np.eq.0) noback=.true. + if(np.gt.0) then + if(gamma(np-1).lt.nt) noback=.true. + endif + + if(noback) then +! Can't back up, either. Relax threshold and look forward again +! to a better branch. + nt=nt-ndelta + if(ii(np).ne.0) then + ii(np)=0 + nstate(np)=ieor(nstate(np),1) + endif + go to 99 + endif + +! Back up + np=np-1 + if(np.lt.ntail .and. ii(np).ne.1) then +! Search the next best branch + ii(np)=ii(np)+1 + nstate(np)=ieor(nstate(np),1) + go to 99 + endif + go to 10 +99 continue + enddo + i=nbits*maxcycles + +100 metric=gamma(np) !Final path metric + +! Copy decoded data to user's buffer + nbytes=(nbits+7)/8 + np=7 + do j=1,nbytes-1 + i4a=nstate(np) + dat(j)=i4a + np=np+8 + enddo + dat(nbytes)=0 + + ncycles=i+1 + ierr=0 + if(i.ge.maxcycles*nbits) ierr=-1 + + return +end subroutine fano232 + +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 hash(string,len,ihash) + + parameter (MASK15=32767) + character*(*) string + integer*1 ic(12) + + do i=1,len + ic(i)=ichar(string(i:i)) + enddo + i=nhash(ic,len,146) + ihash=iand(i,MASK15) + +! print*,'C',ihash,len,string + return +end subroutine hash + +subroutine inter_mept(id,ndir) + +! Interleave (ndir=1) or de-interleave (ndir=-1) the array id. + + integer*1 id(0:161),itmp(0:161) + integer j0(0:161) + logical first + data first/.true./ + save + + if(first) then +! Compute the interleave table using bit reversal. + k=-1 + do i=0,255 + n=0 + ii=i + do j=0,7 + n=n+n + if(iand(ii,1).ne.0) n=n+1 + ii=ii/2 + enddo + if(n.le.161) then + k=k+1 + j0(k)=n + endif + enddo + first=.false. + endif + + if(ndir.eq.1) then + do i=0,161 + itmp(j0(i))=id(i) + enddo + else + do i=0,161 + itmp(i)=id(j0(i)) + enddo + endif + + do i=0,161 + id(i)=itmp(i) + enddo + + return +end subroutine inter_mept + +function nchar(c) + +! Convert ASCII number, letter, or space to 0-36 for callsign packing. + + character c*1 + data 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(11),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 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,digit*10 + logical text + data digit/'0123456789'/ + + 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 + nfreq=100*(ichar(callsign(4:4))-48) + & + 10*(ichar(callsign(5:5))-48) + & + ichar(callsign(6:6))-48 + ncall=NBASE + 3 + nfreq + endif + return + else if(callsign(1:4).eq.'QRZ ') then + ncall=NBASE + 2 + 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(1: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 packgrid(grid,ng,text) + + parameter (NGBASE=180*180) + character*4 grid + logical text + + text=.false. + if(grid.eq.' ') go to 90 !Blank grid is OK + +! Test for numerical signal report, etc. + if(grid(1:1).eq.'-') then + n=10*(ichar(grid(2:2))-48) + ichar(grid(3:3)) - 48 + ng=NGBASE+1+n + go to 100 + else if(grid(1:2).eq.'R-') then + n=10*(ichar(grid(3:3))-48) + ichar(grid(4:4)) - 48 + if(n.eq.0) go to 90 + ng=NGBASE+31+n + go to 100 + else if(grid(1:2).eq.'RO') then + ng=NGBASE+62 + go to 100 + else if(grid(1:3).eq.'RRR') then + ng=NGBASE+63 + go to 100 + else if(grid(1:2).eq.'73') then + ng=NGBASE+64 + go to 100 + endif + + 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 100 + + call grid2deg(grid//'mm',dlong,dlat) + long=dlong + lat=dlat+ 90.0 + ng=((long+180)/2)*180 + lat + go to 100 + +90 ng=NGBASE + 1 + +100 return +end subroutine packgrid + +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 + +subroutine unpack50(dat,n1,n2) + + integer*1 dat(11) + + i=dat(1) + i4=iand(i,255) + n1=ishft(i4,20) + i=dat(2) + i4=iand(i,255) + n1=n1 + ishft(i4,12) + i=dat(3) + i4=iand(i,255) + n1=n1 + ishft(i4,4) + i=dat(4) + i4=iand(i,255) + n1=n1 + iand(ishft(i4,-4),15) + n2=ishft(iand(i4,15),18) + i=dat(5) + i4=iand(i,255) + n2=n2 + ishft(i4,10) + i=dat(6) + i4=iand(i,255) + n2=n2 + ishft(i4,2) + i=dat(7) + i4=iand(i,255) + n2=n2 + iand(ishft(i4,-6),3) + + return +end subroutine unpack50 + +subroutine unpackcall(ncall,word) + + character word*12,c*37 + + data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ '/ + + n=ncall + 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:) + +999 if(word(1:3).eq.'3D0') word='3DA0'//word(4:) + return +end subroutine unpackcall + +subroutine unpackgrid(ng,grid) + + parameter (NGBASE=180*180) + character grid*4,grid6*6,digit*10 + data digit/'0123456789'/ + + 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(1:4) !XXX explicitly truncate this -db + go to 100 + +10 n=ng-NGBASE-1 + if(n.ge.1 .and.n.le.30) then + grid(1:1)='-' + grid(2:2)=char(48+n/10) + grid(3:3)=char(48+mod(n,10)) + else if(n.ge.31 .and.n.le.60) then + n=n-30 + grid(1:2)='R-' + grid(3:3)=char(48+n/10) + grid(4:4)=char(48+mod(n,10)) + 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 + +100 return +end subroutine unpackgrid + +subroutine unpackpfx(ng,call1) + + character*12 call1 + character*3 pfx + + if(ng.lt.60000) then +! Add-on prefix of 1 to 3 characters + n=ng + do i=3,1,-1 + nc=mod(n,37) + if(nc.ge.0 .and. nc.le.9) then + pfx(i:i)=char(nc+48) + else if(nc.ge.10 .and. nc.le.35) then + pfx(i:i)=char(nc+55) + else + pfx(i:i)=' ' + endif + n=n/37 + enddo + call1=pfx//'/'//call1(1:8) + if(call1(1:1).eq.' ') call1=call1(2:) + if(call1(1:1).eq.' ') call1=call1(2:) + else +! Add-on suffix, one or teo characters + i1=index(call1,' ') + nc=ng-60000 + if(nc.ge.0 .and. nc.le.9) then + call1=call1(:i1-1)//'/'//char(nc+48) + else if(nc.ge.10 .and. nc.le.35) then + call1=call1(:i1-1)//'/'//char(nc+55) + else if(nc.ge.36 .and. nc.le.125) then + nc1=(nc-26)/10 + nc2=mod(nc-26,10) + call1=call1(:i1-1)//'/'//char(nc1+48)//char(nc2+48) + endif + endif + + return +end subroutine unpackpfx + +subroutine wqdecode(data0,message,ntype) + + parameter (N15=32768) + integer*1 data0(11) + character*22 message + character*12 callsign + character*3 cdbm + character grid4*4,grid6*6 + logical first + character*12 dcall(0:N15-1) + data first/.true./ + save first,dcall + +! May want to have a timeout (say, one hour?) on calls fetched +! from the hash table. + + if(first) then + dcall=' ' + first=.false. + endif + + message=' ' + call unpack50(data0,n1,n2) + call unpackcall(n1,callsign) + i1=index(callsign,' ') + call unpackgrid(n2/128,grid4) + ntype=iand(n2,127) -64 + +! Standard WSPR message (types 0 3 7 10 13 17 ... 60) + if(ntype.ge.0 .and. ntype.le.62) then + nu=mod(ntype,10) + if(nu.eq.0 .or. nu.eq.3 .or. nu.eq.7) then + write(cdbm,'(i3)') ntype + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + message=callsign(1:i1)//grid4//' '//cdbm + call hash(callsign,i1-1,ih) + dcall(ih)=callsign(:i1) + else + nadd=nu + if(nu.gt.3) nadd=nu-3 + if(nu.gt.7) nadd=nu-7 + ng=n2/128 + 32768*(nadd-1) + call unpackpfx(ng,callsign) + ndbm=ntype-nadd + write(cdbm,'(i3)') ndbm + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + i2=index(callsign,' ') + message=callsign(:i2)//cdbm + call hash(callsign,i2-1,ih) + dcall(ih)=callsign(:i2) + endif + else if(ntype.lt.0) then + ndbm=-(ntype+1) + grid6=callsign(6:6)//callsign(1:5) + ih=(n2-ntype-64)/128 + callsign=dcall(ih) + write(cdbm,'(i3)') ndbm + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + i2=index(callsign,' ') + if(dcall(ih)(1:1).ne.' ') then + message='<'//callsign(:i2-1)//'> '//grid6//' '//cdbm + else + message='<...> '//grid6//' '//cdbm + endif + endif + + return +end subroutine wqdecode + +subroutine wqencode(msg,ntype,data0) + +! Parse and encode a WSPR message. + + parameter (MASK15=32767) + character*22 msg + character*12 call1,call2 + character grid4*4,grid6*6 + logical lbad1,lbad2 + integer*1 data0(11) + integer nu(0:9) + data nu/0,-1,1,0,-1,2,1,0,-1,1/ + +! Standard WSPR message (types 0 3 7 10 13 17 ... 60) + i1=index(msg,' ') + i2=index(msg,'/') + i3=index(msg,'<') + call1=msg(:i1-1) + if(i1.lt.3 .or. i1.gt.7 .or. i2.gt.0 .or. i3.gt.0) go to 10 + grid4=msg(i1+1:i1+4) + call packcall(call1,n1,lbad1) + call packgrid(grid4,ng,lbad2) + if(lbad1 .or. lbad2) go to 10 + ndbm=0 + read(msg(i1+5:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + n2=128*ng + (ndbm+64) + call pack50(n1,n2,data0) + ntype=ndbm + go to 900 + +10 if(i2.ge.2 .and. i3.lt.1) then + call packpfx(call1,n1,ng,nadd) + ndbm=0 + read(msg(i1+1:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + ntype=ndbm + 1 + nadd + n2=128*ng + ntype + 64 + call pack50(n1,n2,data0) + else if(i3.eq.1) then + i4=index(msg,'>') + call1=msg(2:i4-1) + call hash(call1,i4-2,ih) + grid6=msg(i1+1:i1+6) + call2=grid6(2:6)//grid6(1:1)//' ' + call packcall(call2,n1,lbad1) + ndbm=0 + read(msg(i1+8:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + ntype=-(ndbm+1) + n2=128*ih + ntype + 64 + call pack50(n1,n2,data0) + endif + go to 900 + +900 continue + return +end subroutine wqencode diff --git a/lib/wsprcode/wsprcode.f90 b/lib/wsprcode/wsprcode.f90 index 937df980..88b55901 100755 --- a/lib/wsprcode/wsprcode.f90 +++ b/lib/wsprcode/wsprcode.f90 @@ -1,158 +1,158 @@ -!------------------------------------------------------------------------------- -! -! This file is part of the WSPR application, Weak Signal Propagation Reporter -! -! File Name: wsprcode.f90 -! Description: This program provides examples of the source encoding, -! convulsional error-control coding, bit and symbol ordering, -! and synchronizing information contained in WSPR messages. -! -! Copyright (C) 2001-2014 Joseph Taylor, K1JT -! License: GPL-3 -! -! 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 3 of the License, or (at your option) any later -! version. -! -! This program is distributed in the hope that it will be useful, but WITHOUT -! ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -! FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -! details. -! -! You should have received a copy of the GNU General Public License along with -! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin -! Street, Fifth Floor, Boston, MA 02110-1301, USA. -! -!------------------------------------------------------------------------------- - -program wsprcode - - parameter (NSYM=162) - parameter (MAXSYM=176) - character*22 msg,msg2 - integer*1 data0(13) - integer*1 data1(13) - integer*1 dat(206) - integer*1 softsym(206) - -! Define the sync vector: - integer*1 sync(NSYM) - data sync/ & - 1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, & - 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, & - 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, & - 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, & - 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, & - 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, & - 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, & - 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, & - 0,0/ - -! Metric table for decoding from soft symbols - integer mettab(0:255,0:1) - data mettab/ & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, & - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & - 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, & - 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, & - -1, -1, -1, -2, -2, -3, -4, -4, -5, -6, & - -7, -7, -8, -9, -10, -11, -12, -12, -13, -14, & - -15, -16, -17, -17, -18, -19, -20, -21, -22, -22, & - -23, -24, -25, -26, -26, -27, -28, -29, -30, -30, & - -31, -32, -33, -33, -34, -35, -36, -36, -37, -38, & - -38, -39, -40, -41, -41, -42, -43, -43, -44, -45, & - -45, -46, -47, -47, -48, -49, -49, -50, -51, -51, & - -52, -53, -53, -54, -54, -55, -56, -56, -57, -57, & - -58, -59, -59, -60, -60, -61, -62, -62, -62, -63, & - -64, -64, -65, -65, -66, -67, -67, -67, -68, -69, & - -69, -70, -70, -71, -72, -72, -72, -72, -73, -74, & - -75, -75, -75, -77, -76, -76, -78, -78, -80, -81, & - -80, -79, -83, -82, -81, -82, -82, -83, -84, -84, & - -84, -87, -86, -87, -88, -89, -89, -89, -88, -87, & - -86, -87, -84, -84, -84, -83, -82, -82, -81, -82, & - -83, -79, -80, -81, -80, -78, -78, -76, -76, -77, & - -75, -75, -75, -74, -73, -72, -72, -72, -72, -71, & - -70, -70, -69, -69, -68, -67, -67, -67, -66, -65, & - -65, -64, -64, -63, -62, -62, -62, -61, -60, -60, & - -59, -59, -58, -57, -57, -56, -56, -55, -54, -54, & - -53, -53, -52, -51, -51, -50, -49, -49, -48, -47, & - -47, -46, -45, -45, -44, -43, -43, -42, -41, -41, & - -40, -39, -38, -38, -37, -36, -36, -35, -34, -33, & - -33, -32, -31, -30, -30, -29, -28, -27, -26, -26, & - -25, -24, -23, -22, -22, -21, -20, -19, -18, -17, & - -17, -16, -15, -14, -13, -12, -12, -11, -10, -9, & - -8, -7, -7, -6, -5, -4, -4, -3, -2, -2, & - -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, & - 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, & - 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, & - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & - 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & - 5, 5/ - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: WSPRcode "message"' - go to 999 - endif - call getarg(1,msg) !Get message from command line - write(*,1000) msg -1000 format('Message: ',a22) - - nbits=50+31 !User bits=50, constraint length=32 - nbytes=(nbits+7)/8 - ndelta=50 - limit=20000 - - data0=0 - call wqencode(msg,ntype0,data0) !Source encoding - write(*,1002) data0(1:7),data0(1:6),data0(7)/64 -1002 format(/'Source-encoded message, 50 bits:'/'Hex: ',7z3.2/ & - 'Binary: ',6b9.8,b3.2) - - call encode232(data0,nbytes,dat,MAXSYM) !Convolutional encoding - call inter_mept(dat,1) !Interleaving - - write(*,1004) -1004 format(/'Data symbols:') - write(*,1006) (dat(i),i=1,NSYM) -1006 format(5x,30i2) - - write(*,1008) -1008 format(/'Sync symbols:') - write(*,1006) (sync(i),i=1,NSYM) - - write(*,1010) -1010 format(/'Channel symbols:') - write(*,1006) (2*dat(i)+sync(i),i=1,NSYM) - - call inter_mept(dat,-1) !Remove interleaving - softsym=-dat !Simulate soft symbols - -! Call the sequential (Fano algorithm) decoder - call fano232(softsym,nbits,mettab,ndelta,limit,data1,ncycles,metric,nerr) - call wqdecode(data1,msg2,ntype1) - - write(*,1020) msg2,ntype1 -1020 format(/'Decoded message: ',a22,' ntype:',i3) - -999 end program wsprcode - -include 'wspr_old_subs.f90' - +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +! File Name: wsprcode.f90 +! Description: This program provides examples of the source encoding, +! convulsional error-control coding, bit and symbol ordering, +! and synchronizing information contained in WSPR messages. +! +! Copyright (C) 2001-2014 Joseph Taylor, K1JT +! License: GPL-3 +! +! 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 3 of the License, or (at your option) any later +! version. +! +! This program is distributed in the hope that it will be useful, but WITHOUT +! ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +! FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +! details. +! +! You should have received a copy of the GNU General Public License along with +! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +! Street, Fifth Floor, Boston, MA 02110-1301, USA. +! +!------------------------------------------------------------------------------- + +program wsprcode + + parameter (NSYM=162) + parameter (MAXSYM=176) + character*22 msg,msg2 + integer*1 data0(13) + integer*1 data1(13) + integer*1 dat(206) + integer*1 softsym(206) + +! Define the sync vector: + integer*1 sync(NSYM) + data sync/ & + 1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, & + 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, & + 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, & + 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, & + 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, & + 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, & + 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, & + 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, & + 0,0/ + +! Metric table for decoding from soft symbols + integer mettab(0:255,0:1) + data mettab/ & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, & + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & + 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, & + 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, & + -1, -1, -1, -2, -2, -3, -4, -4, -5, -6, & + -7, -7, -8, -9, -10, -11, -12, -12, -13, -14, & + -15, -16, -17, -17, -18, -19, -20, -21, -22, -22, & + -23, -24, -25, -26, -26, -27, -28, -29, -30, -30, & + -31, -32, -33, -33, -34, -35, -36, -36, -37, -38, & + -38, -39, -40, -41, -41, -42, -43, -43, -44, -45, & + -45, -46, -47, -47, -48, -49, -49, -50, -51, -51, & + -52, -53, -53, -54, -54, -55, -56, -56, -57, -57, & + -58, -59, -59, -60, -60, -61, -62, -62, -62, -63, & + -64, -64, -65, -65, -66, -67, -67, -67, -68, -69, & + -69, -70, -70, -71, -72, -72, -72, -72, -73, -74, & + -75, -75, -75, -77, -76, -76, -78, -78, -80, -81, & + -80, -79, -83, -82, -81, -82, -82, -83, -84, -84, & + -84, -87, -86, -87, -88, -89, -89, -89, -88, -87, & + -86, -87, -84, -84, -84, -83, -82, -82, -81, -82, & + -83, -79, -80, -81, -80, -78, -78, -76, -76, -77, & + -75, -75, -75, -74, -73, -72, -72, -72, -72, -71, & + -70, -70, -69, -69, -68, -67, -67, -67, -66, -65, & + -65, -64, -64, -63, -62, -62, -62, -61, -60, -60, & + -59, -59, -58, -57, -57, -56, -56, -55, -54, -54, & + -53, -53, -52, -51, -51, -50, -49, -49, -48, -47, & + -47, -46, -45, -45, -44, -43, -43, -42, -41, -41, & + -40, -39, -38, -38, -37, -36, -36, -35, -34, -33, & + -33, -32, -31, -30, -30, -29, -28, -27, -26, -26, & + -25, -24, -23, -22, -22, -21, -20, -19, -18, -17, & + -17, -16, -15, -14, -13, -12, -12, -11, -10, -9, & + -8, -7, -7, -6, -5, -4, -4, -3, -2, -2, & + -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, & + 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, & + 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, & + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & + 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5/ + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: WSPRcode "message"' + go to 999 + endif + call getarg(1,msg) !Get message from command line + write(*,1000) msg +1000 format('Message: ',a22) + + nbits=50+31 !User bits=50, constraint length=32 + nbytes=(nbits+7)/8 + ndelta=50 + limit=20000 + + data0=0 + call wqencode(msg,ntype0,data0) !Source encoding + write(*,1002) data0(1:7),data0(1:6),data0(7)/64 +1002 format(/'Source-encoded message, 50 bits:'/'Hex: ',7z3.2/ & + 'Binary: ',6b9.8,b3.2) + + call encode232(data0,nbytes,dat,MAXSYM) !Convolutional encoding + call inter_mept(dat,1) !Interleaving + + write(*,1004) +1004 format(/'Data symbols:') + write(*,1006) (dat(i),i=1,NSYM) +1006 format(5x,30i2) + + write(*,1008) +1008 format(/'Sync symbols:') + write(*,1006) (sync(i),i=1,NSYM) + + write(*,1010) +1010 format(/'Channel symbols:') + write(*,1006) (2*dat(i)+sync(i),i=1,NSYM) + + call inter_mept(dat,-1) !Remove interleaving + softsym=-dat !Simulate soft symbols + +! Call the sequential (Fano algorithm) decoder + call fano232(softsym,nbits,mettab,ndelta,limit,data1,ncycles,metric,nerr) + call wqdecode(data1,msg2,ntype1) + + write(*,1020) msg2,ntype1 +1020 format(/'Decoded message: ',a22,' ntype:',i3) + +999 end program wsprcode + +include 'wspr_old_subs.f90' + diff --git a/lib/wsprd/Makefile b/lib/wsprd/Makefile index 109fe39a..c8e15723 100755 --- a/lib/wsprd/Makefile +++ b/lib/wsprd/Makefile @@ -1,39 +1,39 @@ -CC = gcc -FC = gfortran - -CFLAGS= -I/usr/include -Wall -Wno-missing-braces -Wno-unused-result -O3 -ffast-math -LDFLAGS = -L/usr/lib -FFLAGS = -O2 -Wall -Wno-conversion -LIBS = -lfftw3f -lm -lgfortran - -# Default rules -%.o: %.c $(DEPS) - ${CC} ${CFLAGS} -c $< -%.o: %.f - ${FC} ${FFLAGS} -c $< -%.o: %.F - ${FC} ${FFLAGS} -c $< -%.o: %.f90 - ${FC} ${FFLAGS} -c $< -%.o: %.F90 - ${FC} ${FFLAGS} -c $< - -all: wsprd wsprsim - -DEPS = wsprsim_utils.h wsprd_utils.h fano.h jelinek.h nhash.h - -indexx.o: ../indexx.f90 - ${FC} -o indexx.o ${FFLAGS} -c ../indexx.f90 - -OBJS1 = wsprd.o wsprsim_utils.o wsprd_utils.o tab.o fano.o jelinek.o nhash.o indexx.o osdwspr.o - -wsprd: $(OBJS1) - $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) - -OBJS2 = wsprsim.o wsprsim_utils.o wsprd_utils.o tab.o fano.o nhash.o - -wsprsim: $(OBJS2) - $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) - -clean: - $(RM) *.o wsprd wsprsim +CC = gcc +FC = gfortran + +CFLAGS= -I/usr/include -Wall -Wno-missing-braces -Wno-unused-result -O3 -ffast-math +LDFLAGS = -L/usr/lib +FFLAGS = -O2 -Wall -Wno-conversion +LIBS = -lfftw3f -lm -lgfortran + +# Default rules +%.o: %.c $(DEPS) + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: wsprd wsprsim + +DEPS = wsprsim_utils.h wsprd_utils.h fano.h jelinek.h nhash.h + +indexx.o: ../indexx.f90 + ${FC} -o indexx.o ${FFLAGS} -c ../indexx.f90 + +OBJS1 = wsprd.o wsprsim_utils.o wsprd_utils.o tab.o fano.o jelinek.o nhash.o indexx.o osdwspr.o + +wsprd: $(OBJS1) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +OBJS2 = wsprsim.o wsprsim_utils.o wsprd_utils.o tab.o fano.o nhash.o + +wsprsim: $(OBJS2) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +clean: + $(RM) *.o wsprd wsprsim diff --git a/lib/wsprd/Makefile.MinGW b/lib/wsprd/Makefile.MinGW index acad9002..d9fd6b83 100755 --- a/lib/wsprd/Makefile.MinGW +++ b/lib/wsprd/Makefile.MinGW @@ -1,30 +1,30 @@ -CC = gcc -#CC = clang -FC = gfortran - -FFLAGS = -O2 -Wall -Wno-conversion -CFLAGS= -Wall -Wno-missing-braces -O2 -#LDFLAGS = -L/JTSDK/fftw3f -LIBS = c:/JTSDK/fftw3f/libfftw3-3.dll -lm - -# Default rules -%.o: %.c $(DEPS) - ${CC} ${CFLAGS} -c $< -%.o: %.f - ${FC} ${FFLAGS} -c $< -%.o: %.F - ${FC} ${FFLAGS} -c $< -%.o: %.f90 - ${FC} ${FFLAGS} -c $< -%.o: %.F90 - ${FC} ${FFLAGS} -c $< - -all: wsprd - -DEPS = fano.h -OBJS1 = wsprd.o wsprd_utils.o fano.o tab.o nhash.o -wsprd: $(OBJS1) - $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) - -clean: - rm *.o wsprd +CC = gcc +#CC = clang +FC = gfortran + +FFLAGS = -O2 -Wall -Wno-conversion +CFLAGS= -Wall -Wno-missing-braces -O2 +#LDFLAGS = -L/JTSDK/fftw3f +LIBS = c:/JTSDK/fftw3f/libfftw3-3.dll -lm + +# Default rules +%.o: %.c $(DEPS) + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: wsprd + +DEPS = fano.h +OBJS1 = wsprd.o wsprd_utils.o fano.o tab.o nhash.o +wsprd: $(OBJS1) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +clean: + rm *.o wsprd diff --git a/lib/wsprd/Makefile.win32 b/lib/wsprd/Makefile.win32 index 705a7291..8d600d71 100755 --- a/lib/wsprd/Makefile.win32 +++ b/lib/wsprd/Makefile.win32 @@ -1,40 +1,40 @@ -CC = gcc -FC = gfortran - -FFLAGS = -O2 -Wall -Wno-conversion -CFLAGS= -I/JTSDK/fftw3f -Wall -Wno-missing-braces -O2 -#LDFLAGS = -L/JTSDK/fftw3f -Wl,--stack,4000000 -LDFLAGS = -L/JTSDK/fftw3f -LIBS = c:/JTSDK/fftw3f/libfftw3-3.dll -lm - -# Default rules -%.o: %.c $(DEPS) - ${CC} ${CFLAGS} -c $< -%.o: %.f - ${FC} ${FFLAGS} -c $< -%.o: %.F - ${FC} ${FFLAGS} -c $< -%.o: %.f90 - ${FC} ${FFLAGS} -c $< -%.o: %.F90 - ${FC} ${FFLAGS} -c $< - -all: wsprd.exe wsprsim.exe wsprd_exp.exe - -DEPS = wsprsim_utils.h wsprd_utils.h fano.h jelinek.h nhash.h - -OBJS1 = wsprd.o wsprsim_utils.o wsprd_utils.o tab.o fano.o jelinek.o nhash.o -wsprd.exe: $(OBJS1) - $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) - -OBJS2 = wsprsim.o wsprsim_utils.o wsprd_utils.o tab.o fano.o nhash.o -wsprsim.exe: $(OBJS2) - $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) - -OBJS3 = wsprd_exp.o wsprsim_utils.o wsprd_utils.o tab.o fano.o jelinek.o \ - nhash.o -wsprd_exp.exe: $(OBJS3) - $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) - -clean: - rm *.o wsprd.exe wsprsim.exe wsprd_exp.exe +CC = gcc +FC = gfortran + +FFLAGS = -O2 -Wall -Wno-conversion +CFLAGS= -I/JTSDK/fftw3f -Wall -Wno-missing-braces -O2 +#LDFLAGS = -L/JTSDK/fftw3f -Wl,--stack,4000000 +LDFLAGS = -L/JTSDK/fftw3f +LIBS = c:/JTSDK/fftw3f/libfftw3-3.dll -lm + +# Default rules +%.o: %.c $(DEPS) + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: wsprd.exe wsprsim.exe wsprd_exp.exe + +DEPS = wsprsim_utils.h wsprd_utils.h fano.h jelinek.h nhash.h + +OBJS1 = wsprd.o wsprsim_utils.o wsprd_utils.o tab.o fano.o jelinek.o nhash.o +wsprd.exe: $(OBJS1) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +OBJS2 = wsprsim.o wsprsim_utils.o wsprd_utils.o tab.o fano.o nhash.o +wsprsim.exe: $(OBJS2) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +OBJS3 = wsprd_exp.o wsprsim_utils.o wsprd_utils.o tab.o fano.o jelinek.o \ + nhash.o +wsprd_exp.exe: $(OBJS3) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +clean: + rm *.o wsprd.exe wsprsim.exe wsprd_exp.exe diff --git a/lib/wsprd/README b/lib/wsprd/README index d9605ac7..141c2fb2 100755 --- a/lib/wsprd/README +++ b/lib/wsprd/README @@ -1,70 +1,70 @@ -wsprd is a decoder for K1JT's Weak Signal Propagation Reporter (WSPR) mode. - -The program is written in C and is a command-line program that reads from a -.c2 file or .wav file and writes output to the console. It is used by WSJT-X -for wspr-mode decoding. - -USAGE: - wsprd [options...] infile - -OPTIONS: - -a path to writeable data files, default="." - -B disable block demodulation - use single-symbol noncoherent demod - -c write .c2 file at the end of the first pass - -C maximum number of decoder cycles per bit, default 10000 - -d deeper search. Slower, a few more decodes - -e x (x is transceiver dial frequency error in Hz) - -f x (x is transceiver dial frequency in MHz) - -H do not use (or update) the hash table - -J use the stack decoder instead of Fano decoder - -m decode wspr-15 .wav file - -o n (0<=n<=5), decoding depth for OSD, default is disabled - -q quick mode - doesn't dig deep for weak signals - -s single pass mode, no subtraction (same as original wsprd) - -v verbose mode (shows dupes) - -w wideband mode - decode signals within +/- 150 Hz of center - -z x (x is fano metric table bias, default is 0.45) - -infile can be either .wav or .c2 - -e.g. -./wsprd -wf 14.0956 140709_2258.wav - -Note that for .c2 files, the frequency within the file overrides the command -line value. - -FEATURES: -By default, wsprd reports signals that are within +/- 110 Hz of the -subband center frequency. The wideband option (-w) extends this to +/- 150 Hz. - -wsprd maintains a hashtable and will decode all three types of wspr -messages. An option (-H) is available to turn off use of the hashtable. - -Decoding is attempted using soft symbols derived using single-symbol -noncoherent detection. If decoding fails, then soft symbols derived using -block demodulation over 2- and 3-symbol blocks are used in subsequent -decoding attempts. For slower computers, block demodulation can be -disabled with the -B command line option. - -The symbols are decoded using Phil Karn's sequential decoder routine, -fano.c. The -J option replaces the Fano algorithm with the Jelinek -"stack-bucket" algorithm. If the -o command line option is enabled, then -an ordered-statistics decoder (OSD) is invoked if the Fano (or Jelinek) algorithm -fails. The OSD is a complete decoder, meaning that it always returns a codeword. -A returned codeword is considered valid only if the unpacked decode contains -a callsign that is already in the hashtable. - -NOTES: -This program attempts to maximize the number of successful decodes per transmit -interval by trying to decode virtually every peak in the averaged spectrum. -The program also implements two-pass decoding, whereby signals that are successfully -decoded are subtracted one-by-one during the first decoding pass. Then, the -decoder is run again. In many cases the subtraction process will uncover signals -that can then be successfully decoded on the second pass. - -There will be occasional duplicate decodes when two closely spaced -peaks come from the same signal. The program removes dupes based on callsign -and frequency. Two decodes that have the same callsign and estimated frequencies -that are within 1 Hz will be treated as decodes of the same signal. This -dupechecking is turned off with the -v flag. - +wsprd is a decoder for K1JT's Weak Signal Propagation Reporter (WSPR) mode. + +The program is written in C and is a command-line program that reads from a +.c2 file or .wav file and writes output to the console. It is used by WSJT-X +for wspr-mode decoding. + +USAGE: + wsprd [options...] infile + +OPTIONS: + -a path to writeable data files, default="." + -B disable block demodulation - use single-symbol noncoherent demod + -c write .c2 file at the end of the first pass + -C maximum number of decoder cycles per bit, default 10000 + -d deeper search. Slower, a few more decodes + -e x (x is transceiver dial frequency error in Hz) + -f x (x is transceiver dial frequency in MHz) + -H do not use (or update) the hash table + -J use the stack decoder instead of Fano decoder + -m decode wspr-15 .wav file + -o n (0<=n<=5), decoding depth for OSD, default is disabled + -q quick mode - doesn't dig deep for weak signals + -s single pass mode, no subtraction (same as original wsprd) + -v verbose mode (shows dupes) + -w wideband mode - decode signals within +/- 150 Hz of center + -z x (x is fano metric table bias, default is 0.45) + +infile can be either .wav or .c2 + +e.g. +./wsprd -wf 14.0956 140709_2258.wav + +Note that for .c2 files, the frequency within the file overrides the command +line value. + +FEATURES: +By default, wsprd reports signals that are within +/- 110 Hz of the +subband center frequency. The wideband option (-w) extends this to +/- 150 Hz. + +wsprd maintains a hashtable and will decode all three types of wspr +messages. An option (-H) is available to turn off use of the hashtable. + +Decoding is attempted using soft symbols derived using single-symbol +noncoherent detection. If decoding fails, then soft symbols derived using +block demodulation over 2- and 3-symbol blocks are used in subsequent +decoding attempts. For slower computers, block demodulation can be +disabled with the -B command line option. + +The symbols are decoded using Phil Karn's sequential decoder routine, +fano.c. The -J option replaces the Fano algorithm with the Jelinek +"stack-bucket" algorithm. If the -o command line option is enabled, then +an ordered-statistics decoder (OSD) is invoked if the Fano (or Jelinek) algorithm +fails. The OSD is a complete decoder, meaning that it always returns a codeword. +A returned codeword is considered valid only if the unpacked decode contains +a callsign that is already in the hashtable. + +NOTES: +This program attempts to maximize the number of successful decodes per transmit +interval by trying to decode virtually every peak in the averaged spectrum. +The program also implements two-pass decoding, whereby signals that are successfully +decoded are subtracted one-by-one during the first decoding pass. Then, the +decoder is run again. In many cases the subtraction process will uncover signals +that can then be successfully decoded on the second pass. + +There will be occasional duplicate decodes when two closely spaced +peaks come from the same signal. The program removes dupes based on callsign +and frequency. Two decodes that have the same callsign and estimated frequencies +that are within 1 Hz will be treated as decodes of the same signal. This +dupechecking is turned off with the -v flag. + diff --git a/lib/wsprd/fano.c b/lib/wsprd/fano.c index 799d5c0b..8fe1a649 100755 --- a/lib/wsprd/fano.c +++ b/lib/wsprd/fano.c @@ -1,239 +1,239 @@ -/* - This file is part of wsprd. - - File name: fano.c - - Description: Soft decision Fano sequential decoder for K=32 r=1/2 - convolutional code. - - Copyright 1994, Phil Karn, KA9Q - Minor modifications by Joe Taylor, K1JT -*/ - -#define LL 1 // Select Layland-Lushbaugh code -#include -#include -#include -#include "fano.h" - -struct node { - unsigned long encstate; // Encoder state of next node - long gamma; // Cumulative metric to this node - int metrics[4]; // Metrics indexed by all possible tx syms - int tm[2]; // Sorted metrics for current hypotheses - int i; // Current branch being tested -}; - -// Convolutional coding polynomials. All are rate 1/2, K=32 -#ifdef NASA_STANDARD -/* "NASA standard" code by Massey & Costello - * Nonsystematic, quick look-in, dmin=11, dfree=23 - * used on Pioneer 10-12, Helios A,B - */ -#define POLY1 0xbbef6bb7 -#define POLY2 0xbbef6bb5 -#endif - -#ifdef MJ -/* Massey-Johannesson code - * Nonsystematic, quick look-in, dmin=13, dfree>=23 - * Purported to be more computationally efficient than Massey-Costello - */ -#define POLY1 0xb840a20f -#define POLY2 0xb840a20d -#endif - -#ifdef LL -/* Layland-Lushbaugh code - * Nonsystematic, non-quick look-in, dmin=?, dfree=? - */ -#define POLY1 0xf2d05351 -#define POLY2 0xe4613c47 -#endif - -/* Convolutionally encode a packet. The input data bytes are read - * high bit first and the encoded packet is written into 'symbols', - * one symbol per byte. The first symbol is generated from POLY1, - * the second from POLY2. - * - * Storing only one symbol per byte uses more space, but it is faster - * and easier than trying to pack them more compactly. - */ -int encode( - unsigned char *symbols, // Output buffer, 2*nbytes*8 - unsigned char *data, // Input buffer, nbytes - unsigned int nbytes) // Number of bytes in data -{ - unsigned long encstate; - int sym; - int i; - - encstate = 0; - while(nbytes-- != 0) { - for(i=7;i>=0;i--) { - encstate = (encstate << 1) | ((*data >> i) & 1); - ENCODE(sym,encstate); - *symbols++ = sym >> 1; - *symbols++ = sym & 1; - } - data++; - } - return 0; -} - -/* Decode packet with the Fano algorithm. - * Return 0 on success, -1 on timeout - */ -int fano( - unsigned int *metric, // Final path metric (returned value) - unsigned int *cycles, // Cycle count (returned value) - unsigned int *maxnp, // Progress before timeout (returned value) - unsigned char *data, // Decoded output data - unsigned char *symbols, // Raw deinterleaved input symbols - unsigned int nbits, // Number of output bits - int mettab[2][256], // Metric table, [sent sym][rx symbol] - int delta, // Threshold adjust parameter - unsigned int maxcycles) // Decoding timeout in cycles per bit -{ - struct node *nodes; // First node - struct node *np; // Current node - struct node *lastnode; // Last node - struct node *tail; // First node of tail - int t; // Threshold - int m0,m1; - int ngamma; - unsigned int lsym; - unsigned int i; - - if((nodes = (struct node *)malloc((nbits+1)*sizeof(struct node))) == NULL) { - printf("malloc failed\n"); - return 0; - } - lastnode = &nodes[nbits-1]; - tail = &nodes[nbits-31]; - *maxnp = 0; - -/* Compute all possible branch metrics for each symbol pair - * This is the only place we actually look at the raw input symbols - */ - for(np=nodes;np <= lastnode;np++) { - np->metrics[0] = mettab[0][symbols[0]] + mettab[0][symbols[1]]; - np->metrics[1] = mettab[0][symbols[0]] + mettab[1][symbols[1]]; - np->metrics[2] = mettab[1][symbols[0]] + mettab[0][symbols[1]]; - np->metrics[3] = mettab[1][symbols[0]] + mettab[1][symbols[1]]; - symbols += 2; - } - np = nodes; - np->encstate = 0; - -// Compute and sort branch metrics from root node */ - ENCODE(lsym,np->encstate); // 0-branch (LSB is 0) - m0 = np->metrics[lsym]; - -/* Now do the 1-branch. To save another ENCODE call here and - * inside the loop, we assume that both polynomials are odd, - * providing complementary pairs of branch symbols. - - * This code should be modified if a systematic code were used. - */ - - m1 = np->metrics[3^lsym]; - if(m0 > m1) { - np->tm[0] = m0; // 0-branch has better metric - np->tm[1] = m1; - } else { - np->tm[0] = m1; // 1-branch is better - np->tm[1] = m0; - np->encstate++; // Set low bit - } - np->i = 0; // Start with best branch - maxcycles *= nbits; - np->gamma = t = 0; - - // Start the Fano decoder - for(i=1;i <= maxcycles;i++) { - if((int)(np-nodes) > (int)*maxnp) *maxnp=(int)(np-nodes); -#ifdef debug - printf("k=%ld, g=%ld, t=%d, m[%d]=%d, maxnp=%d, encstate=%lx\n", - np-nodes,np->gamma,t,np->i,np->tm[np->i],*maxnp,np->encstate); -#endif -// Look forward */ - ngamma = np->gamma + np->tm[np->i]; - if(ngamma >= t) { - if(np->gamma < t + delta) { // Node is acceptable - /* First time we've visited this node; - * Tighten threshold. - * - * This loop could be replaced with - * t += delta * ((ngamma - t)/delta); - * but the multiply and divide are slower. - */ - while(ngamma >= t + delta) t += delta; - } - np[1].gamma = ngamma; // Move forward - np[1].encstate = np->encstate << 1; - if( ++np == (lastnode+1) ) { - break; // Done! - } - - /* Compute and sort metrics, starting with the - * zero branch - */ - ENCODE(lsym,np->encstate); - if(np >= tail) { - /* The tail must be all zeroes, so don't - * bother computing the 1-branches here. - */ - np->tm[0] = np->metrics[lsym]; - } else { - m0 = np->metrics[lsym]; - m1 = np->metrics[3^lsym]; - if(m0 > m1) { - np->tm[0] = m0; // 0-branch is better - np->tm[1] = m1; - } else { - np->tm[0] = m1; // 1-branch is better - np->tm[1] = m0; - np->encstate++; // Set low bit - } - } - np->i = 0; // Start with best branch - continue; - } - // Threshold violated, can't go forward - for(;;) { // Look backward - if(np == nodes || np[-1].gamma < t) { - /* Can't back up either. - * Relax threshold and and look - * forward again to better branch. - */ - t -= delta; - if(np->i != 0) { - np->i = 0; - np->encstate ^= 1; - } - break; - } - // Back up - if(--np < tail && np->i != 1) { - np->i++; // Search next best branch - np->encstate ^= 1; - break; - } // else keep looking back - } - } - *metric = np->gamma; // Return the final path metric - - // Copy decoded data to user's buffer - nbits >>= 3; - np = &nodes[7]; - while(nbits-- != 0) { - *data++ = np->encstate; - np += 8; - } - *cycles = i+1; - - free(nodes); - if(i >= maxcycles) return -1; // Decoder timed out - return 0; // Successful completion -} +/* + This file is part of wsprd. + + File name: fano.c + + Description: Soft decision Fano sequential decoder for K=32 r=1/2 + convolutional code. + + Copyright 1994, Phil Karn, KA9Q + Minor modifications by Joe Taylor, K1JT +*/ + +#define LL 1 // Select Layland-Lushbaugh code +#include +#include +#include +#include "fano.h" + +struct node { + unsigned long encstate; // Encoder state of next node + long gamma; // Cumulative metric to this node + int metrics[4]; // Metrics indexed by all possible tx syms + int tm[2]; // Sorted metrics for current hypotheses + int i; // Current branch being tested +}; + +// Convolutional coding polynomials. All are rate 1/2, K=32 +#ifdef NASA_STANDARD +/* "NASA standard" code by Massey & Costello + * Nonsystematic, quick look-in, dmin=11, dfree=23 + * used on Pioneer 10-12, Helios A,B + */ +#define POLY1 0xbbef6bb7 +#define POLY2 0xbbef6bb5 +#endif + +#ifdef MJ +/* Massey-Johannesson code + * Nonsystematic, quick look-in, dmin=13, dfree>=23 + * Purported to be more computationally efficient than Massey-Costello + */ +#define POLY1 0xb840a20f +#define POLY2 0xb840a20d +#endif + +#ifdef LL +/* Layland-Lushbaugh code + * Nonsystematic, non-quick look-in, dmin=?, dfree=? + */ +#define POLY1 0xf2d05351 +#define POLY2 0xe4613c47 +#endif + +/* Convolutionally encode a packet. The input data bytes are read + * high bit first and the encoded packet is written into 'symbols', + * one symbol per byte. The first symbol is generated from POLY1, + * the second from POLY2. + * + * Storing only one symbol per byte uses more space, but it is faster + * and easier than trying to pack them more compactly. + */ +int encode( + unsigned char *symbols, // Output buffer, 2*nbytes*8 + unsigned char *data, // Input buffer, nbytes + unsigned int nbytes) // Number of bytes in data +{ + unsigned long encstate; + int sym; + int i; + + encstate = 0; + while(nbytes-- != 0) { + for(i=7;i>=0;i--) { + encstate = (encstate << 1) | ((*data >> i) & 1); + ENCODE(sym,encstate); + *symbols++ = sym >> 1; + *symbols++ = sym & 1; + } + data++; + } + return 0; +} + +/* Decode packet with the Fano algorithm. + * Return 0 on success, -1 on timeout + */ +int fano( + unsigned int *metric, // Final path metric (returned value) + unsigned int *cycles, // Cycle count (returned value) + unsigned int *maxnp, // Progress before timeout (returned value) + unsigned char *data, // Decoded output data + unsigned char *symbols, // Raw deinterleaved input symbols + unsigned int nbits, // Number of output bits + int mettab[2][256], // Metric table, [sent sym][rx symbol] + int delta, // Threshold adjust parameter + unsigned int maxcycles) // Decoding timeout in cycles per bit +{ + struct node *nodes; // First node + struct node *np; // Current node + struct node *lastnode; // Last node + struct node *tail; // First node of tail + int t; // Threshold + int m0,m1; + int ngamma; + unsigned int lsym; + unsigned int i; + + if((nodes = (struct node *)malloc((nbits+1)*sizeof(struct node))) == NULL) { + printf("malloc failed\n"); + return 0; + } + lastnode = &nodes[nbits-1]; + tail = &nodes[nbits-31]; + *maxnp = 0; + +/* Compute all possible branch metrics for each symbol pair + * This is the only place we actually look at the raw input symbols + */ + for(np=nodes;np <= lastnode;np++) { + np->metrics[0] = mettab[0][symbols[0]] + mettab[0][symbols[1]]; + np->metrics[1] = mettab[0][symbols[0]] + mettab[1][symbols[1]]; + np->metrics[2] = mettab[1][symbols[0]] + mettab[0][symbols[1]]; + np->metrics[3] = mettab[1][symbols[0]] + mettab[1][symbols[1]]; + symbols += 2; + } + np = nodes; + np->encstate = 0; + +// Compute and sort branch metrics from root node */ + ENCODE(lsym,np->encstate); // 0-branch (LSB is 0) + m0 = np->metrics[lsym]; + +/* Now do the 1-branch. To save another ENCODE call here and + * inside the loop, we assume that both polynomials are odd, + * providing complementary pairs of branch symbols. + + * This code should be modified if a systematic code were used. + */ + + m1 = np->metrics[3^lsym]; + if(m0 > m1) { + np->tm[0] = m0; // 0-branch has better metric + np->tm[1] = m1; + } else { + np->tm[0] = m1; // 1-branch is better + np->tm[1] = m0; + np->encstate++; // Set low bit + } + np->i = 0; // Start with best branch + maxcycles *= nbits; + np->gamma = t = 0; + + // Start the Fano decoder + for(i=1;i <= maxcycles;i++) { + if((int)(np-nodes) > (int)*maxnp) *maxnp=(int)(np-nodes); +#ifdef debug + printf("k=%ld, g=%ld, t=%d, m[%d]=%d, maxnp=%d, encstate=%lx\n", + np-nodes,np->gamma,t,np->i,np->tm[np->i],*maxnp,np->encstate); +#endif +// Look forward */ + ngamma = np->gamma + np->tm[np->i]; + if(ngamma >= t) { + if(np->gamma < t + delta) { // Node is acceptable + /* First time we've visited this node; + * Tighten threshold. + * + * This loop could be replaced with + * t += delta * ((ngamma - t)/delta); + * but the multiply and divide are slower. + */ + while(ngamma >= t + delta) t += delta; + } + np[1].gamma = ngamma; // Move forward + np[1].encstate = np->encstate << 1; + if( ++np == (lastnode+1) ) { + break; // Done! + } + + /* Compute and sort metrics, starting with the + * zero branch + */ + ENCODE(lsym,np->encstate); + if(np >= tail) { + /* The tail must be all zeroes, so don't + * bother computing the 1-branches here. + */ + np->tm[0] = np->metrics[lsym]; + } else { + m0 = np->metrics[lsym]; + m1 = np->metrics[3^lsym]; + if(m0 > m1) { + np->tm[0] = m0; // 0-branch is better + np->tm[1] = m1; + } else { + np->tm[0] = m1; // 1-branch is better + np->tm[1] = m0; + np->encstate++; // Set low bit + } + } + np->i = 0; // Start with best branch + continue; + } + // Threshold violated, can't go forward + for(;;) { // Look backward + if(np == nodes || np[-1].gamma < t) { + /* Can't back up either. + * Relax threshold and and look + * forward again to better branch. + */ + t -= delta; + if(np->i != 0) { + np->i = 0; + np->encstate ^= 1; + } + break; + } + // Back up + if(--np < tail && np->i != 1) { + np->i++; // Search next best branch + np->encstate ^= 1; + break; + } // else keep looking back + } + } + *metric = np->gamma; // Return the final path metric + + // Copy decoded data to user's buffer + nbits >>= 3; + np = &nodes[7]; + while(nbits-- != 0) { + *data++ = np->encstate; + np += 8; + } + *cycles = i+1; + + free(nodes); + if(i >= maxcycles) return -1; // Decoder timed out + return 0; // Successful completion +} diff --git a/lib/wsprd/fano.h b/lib/wsprd/fano.h index 4837cc6f..3290a094 100755 --- a/lib/wsprd/fano.h +++ b/lib/wsprd/fano.h @@ -1,39 +1,39 @@ -/* - This file is part of wsprd. - - File name: fano.h - - Description: Header file for sequential Fano decoder. - - Copyright 1994, Phil Karn, KA9Q - Minor modifications by Joe Taylor, K1JT -*/ - -#ifndef FANO_H -#define FANO_H - -int fano(unsigned int *metric, unsigned int *cycles, unsigned int *maxnp, - unsigned char *data,unsigned char *symbols, unsigned int nbits, - int mettab[2][256],int delta,unsigned int maxcycles); - -int encode(unsigned char *symbols,unsigned char *data,unsigned int nbytes); - -extern unsigned char Partab[]; - -/* Convolutional encoder macro. Takes the encoder state, generates - * a rate 1/2 symbol pair and stores it in 'sym'. The symbol generated from - * POLY1 goes into the 2-bit of sym, and the symbol generated from POLY2 - * goes into the 1-bit. - */ -#define ENCODE(sym,encstate){\ -unsigned long _tmp;\ -\ -_tmp = (encstate) & POLY1;\ -_tmp ^= _tmp >> 16;\ -(sym) = Partab[(_tmp ^ (_tmp >> 8)) & 0xff] << 1;\ -_tmp = (encstate) & POLY2;\ -_tmp ^= _tmp >> 16;\ -(sym) |= Partab[(_tmp ^ (_tmp >> 8)) & 0xff];\ -} - -#endif +/* + This file is part of wsprd. + + File name: fano.h + + Description: Header file for sequential Fano decoder. + + Copyright 1994, Phil Karn, KA9Q + Minor modifications by Joe Taylor, K1JT +*/ + +#ifndef FANO_H +#define FANO_H + +int fano(unsigned int *metric, unsigned int *cycles, unsigned int *maxnp, + unsigned char *data,unsigned char *symbols, unsigned int nbits, + int mettab[2][256],int delta,unsigned int maxcycles); + +int encode(unsigned char *symbols,unsigned char *data,unsigned int nbytes); + +extern unsigned char Partab[]; + +/* Convolutional encoder macro. Takes the encoder state, generates + * a rate 1/2 symbol pair and stores it in 'sym'. The symbol generated from + * POLY1 goes into the 2-bit of sym, and the symbol generated from POLY2 + * goes into the 1-bit. + */ +#define ENCODE(sym,encstate){\ +unsigned long _tmp;\ +\ +_tmp = (encstate) & POLY1;\ +_tmp ^= _tmp >> 16;\ +(sym) = Partab[(_tmp ^ (_tmp >> 8)) & 0xff] << 1;\ +_tmp = (encstate) & POLY2;\ +_tmp ^= _tmp >> 16;\ +(sym) |= Partab[(_tmp ^ (_tmp >> 8)) & 0xff];\ +} + +#endif diff --git a/lib/wsprd/fftw3.h b/lib/wsprd/fftw3.h index e4f32c86..58a2c73d 100755 --- a/lib/wsprd/fftw3.h +++ b/lib/wsprd/fftw3.h @@ -1,410 +1,410 @@ -/* - * Copyright (c) 2003, 2007-11 Matteo Frigo - * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology - * - * The following statement of license applies *only* to this header file, - * and *not* to the other files distributed with FFTW or derived therefrom: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/***************************** NOTE TO USERS ********************************* - * - * THIS IS A HEADER FILE, NOT A MANUAL - * - * If you want to know how to use FFTW, please read the manual, - * online at http://www.fftw.org/doc/ and also included with FFTW. - * For a quick start, see the manual's tutorial section. - * - * (Reading header files to learn how to use a library is a habit - * stemming from code lacking a proper manual. Arguably, it's a - * *bad* habit in most cases, because header files can contain - * interfaces that are not part of the public, stable API.) - * - ****************************************************************************/ - -#ifndef FFTW3_H -#define FFTW3_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/* If is included, use the C99 complex type. Otherwise - define a type bit-compatible with C99 complex */ -#if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) -# define FFTW_DEFINE_COMPLEX(R, C) typedef R _Complex C -#else -# define FFTW_DEFINE_COMPLEX(R, C) typedef R C[2] -#endif - -#define FFTW_CONCAT(prefix, name) prefix ## name -#define FFTW_MANGLE_DOUBLE(name) FFTW_CONCAT(fftw_, name) -#define FFTW_MANGLE_FLOAT(name) FFTW_CONCAT(fftwf_, name) -#define FFTW_MANGLE_LONG_DOUBLE(name) FFTW_CONCAT(fftwl_, name) -#define FFTW_MANGLE_QUAD(name) FFTW_CONCAT(fftwq_, name) - -/* IMPORTANT: for Windows compilers, you should add a line - #define FFTW_DLL - here and in kernel/ifftw.h if you are compiling/using FFTW as a - DLL, in order to do the proper importing/exporting, or - alternatively compile with -DFFTW_DLL or the equivalent - command-line flag. This is not necessary under MinGW/Cygwin, where - libtool does the imports/exports automatically. */ -#if defined(FFTW_DLL) && (defined(_WIN32) || defined(__WIN32__)) - /* annoying Windows syntax for shared-library declarations */ -# if defined(COMPILING_FFTW) /* defined in api.h when compiling FFTW */ -# define FFTW_EXTERN extern __declspec(dllexport) -# else /* user is calling FFTW; import symbol */ -# define FFTW_EXTERN extern __declspec(dllimport) -# endif -#else -# define FFTW_EXTERN extern -#endif - -enum fftw_r2r_kind_do_not_use_me { - FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2, - FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6, - FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10 -}; - -struct fftw_iodim_do_not_use_me { - int n; /* dimension size */ - int is; /* input stride */ - int os; /* output stride */ -}; - -#include /* for ptrdiff_t */ -struct fftw_iodim64_do_not_use_me { - ptrdiff_t n; /* dimension size */ - ptrdiff_t is; /* input stride */ - ptrdiff_t os; /* output stride */ -}; - -typedef void (*fftw_write_char_func_do_not_use_me)(char c, void *); -typedef int (*fftw_read_char_func_do_not_use_me)(void *); - -/* - huge second-order macro that defines prototypes for all API - functions. We expand this macro for each supported precision - - X: name-mangling macro - R: real data type - C: complex data type -*/ - -#define FFTW_DEFINE_API(X, R, C) \ - \ -FFTW_DEFINE_COMPLEX(R, C); \ - \ -typedef struct X(plan_s) *X(plan); \ - \ -typedef struct fftw_iodim_do_not_use_me X(iodim); \ -typedef struct fftw_iodim64_do_not_use_me X(iodim64); \ - \ -typedef enum fftw_r2r_kind_do_not_use_me X(r2r_kind); \ - \ -typedef fftw_write_char_func_do_not_use_me X(write_char_func); \ -typedef fftw_read_char_func_do_not_use_me X(read_char_func); \ - \ -FFTW_EXTERN void X(execute)(const X(plan) p); \ - \ -FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \ - C *in, C *out, int sign, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_dft_1d)(int n, C *in, C *out, int sign, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_2d)(int n0, int n1, \ - C *in, C *out, int sign, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_3d)(int n0, int n1, int n2, \ - C *in, C *out, int sign, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_many_dft)(int rank, const int *n, \ - int howmany, \ - C *in, const int *inembed, \ - int istride, int idist, \ - C *out, const int *onembed, \ - int ostride, int odist, \ - int sign, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru_dft)(int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - C *in, C *out, \ - int sign, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru_split_dft)(int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - R *ri, R *ii, R *ro, R *io, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru64_dft)(int rank, \ - const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - C *in, C *out, \ - int sign, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru64_split_dft)(int rank, \ - const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - R *ri, R *ii, R *ro, R *io, \ - unsigned flags); \ - \ -FFTW_EXTERN void X(execute_dft)(const X(plan) p, C *in, C *out); \ -FFTW_EXTERN void X(execute_split_dft)(const X(plan) p, R *ri, R *ii, \ - R *ro, R *io); \ - \ -FFTW_EXTERN X(plan) X(plan_many_dft_r2c)(int rank, const int *n, \ - int howmany, \ - R *in, const int *inembed, \ - int istride, int idist, \ - C *out, const int *onembed, \ - int ostride, int odist, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_dft_r2c)(int rank, const int *n, \ - R *in, C *out, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_dft_r2c_1d)(int n,R *in,C *out,unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_r2c_2d)(int n0, int n1, \ - R *in, C *out, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_r2c_3d)(int n0, int n1, \ - int n2, \ - R *in, C *out, unsigned flags); \ - \ - \ -FFTW_EXTERN X(plan) X(plan_many_dft_c2r)(int rank, const int *n, \ - int howmany, \ - C *in, const int *inembed, \ - int istride, int idist, \ - R *out, const int *onembed, \ - int ostride, int odist, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_dft_c2r)(int rank, const int *n, \ - C *in, R *out, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_dft_c2r_1d)(int n,C *in,R *out,unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_c2r_2d)(int n0, int n1, \ - C *in, R *out, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_c2r_3d)(int n0, int n1, \ - int n2, \ - C *in, R *out, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru_dft_r2c)(int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - R *in, C *out, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru_dft_c2r)(int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - C *in, R *out, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru_split_dft_r2c)( \ - int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - R *in, R *ro, R *io, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru_split_dft_c2r)( \ - int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - R *ri, R *ii, R *out, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru64_dft_r2c)(int rank, \ - const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - R *in, C *out, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru64_dft_c2r)(int rank, \ - const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - C *in, R *out, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru64_split_dft_r2c)( \ - int rank, const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - R *in, R *ro, R *io, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru64_split_dft_c2r)( \ - int rank, const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - R *ri, R *ii, R *out, \ - unsigned flags); \ - \ -FFTW_EXTERN void X(execute_dft_r2c)(const X(plan) p, R *in, C *out); \ -FFTW_EXTERN void X(execute_dft_c2r)(const X(plan) p, C *in, R *out); \ - \ -FFTW_EXTERN void X(execute_split_dft_r2c)(const X(plan) p, \ - R *in, R *ro, R *io); \ -FFTW_EXTERN void X(execute_split_dft_c2r)(const X(plan) p, \ - R *ri, R *ii, R *out); \ - \ -FFTW_EXTERN X(plan) X(plan_many_r2r)(int rank, const int *n, \ - int howmany, \ - R *in, const int *inembed, \ - int istride, int idist, \ - R *out, const int *onembed, \ - int ostride, int odist, \ - const X(r2r_kind) *kind, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_r2r)(int rank, const int *n, R *in, R *out, \ - const X(r2r_kind) *kind, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_r2r_1d)(int n, R *in, R *out, \ - X(r2r_kind) kind, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_r2r_2d)(int n0, int n1, R *in, R *out, \ - X(r2r_kind) kind0, X(r2r_kind) kind1, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_r2r_3d)(int n0, int n1, int n2, \ - R *in, R *out, X(r2r_kind) kind0, \ - X(r2r_kind) kind1, X(r2r_kind) kind2, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru_r2r)(int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - R *in, R *out, \ - const X(r2r_kind) *kind, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru64_r2r)(int rank, const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - R *in, R *out, \ - const X(r2r_kind) *kind, unsigned flags); \ - \ -FFTW_EXTERN void X(execute_r2r)(const X(plan) p, R *in, R *out); \ - \ -FFTW_EXTERN void X(destroy_plan)(X(plan) p); \ -FFTW_EXTERN void X(forget_wisdom)(void); \ -FFTW_EXTERN void X(cleanup)(void); \ - \ -FFTW_EXTERN void X(set_timelimit)(double t); \ - \ -FFTW_EXTERN void X(plan_with_nthreads)(int nthreads); \ -FFTW_EXTERN int X(init_threads)(void); \ -FFTW_EXTERN void X(cleanup_threads)(void); \ - \ -FFTW_EXTERN int X(export_wisdom_to_filename)(const char *filename); \ -FFTW_EXTERN void X(export_wisdom_to_file)(FILE *output_file); \ -FFTW_EXTERN char *X(export_wisdom_to_string)(void); \ -FFTW_EXTERN void X(export_wisdom)(X(write_char_func) write_char, \ - void *data); \ -FFTW_EXTERN int X(import_system_wisdom)(void); \ -FFTW_EXTERN int X(import_wisdom_from_filename)(const char *filename); \ -FFTW_EXTERN int X(import_wisdom_from_file)(FILE *input_file); \ -FFTW_EXTERN int X(import_wisdom_from_string)(const char *input_string); \ -FFTW_EXTERN int X(import_wisdom)(X(read_char_func) read_char, void *data); \ - \ -FFTW_EXTERN void X(fprint_plan)(const X(plan) p, FILE *output_file); \ -FFTW_EXTERN void X(print_plan)(const X(plan) p); \ - \ -FFTW_EXTERN void *X(malloc)(size_t n); \ -FFTW_EXTERN R *X(alloc_real)(size_t n); \ -FFTW_EXTERN C *X(alloc_complex)(size_t n); \ -FFTW_EXTERN void X(free)(void *p); \ - \ -FFTW_EXTERN void X(flops)(const X(plan) p, \ - double *add, double *mul, double *fmas); \ -FFTW_EXTERN double X(estimate_cost)(const X(plan) p); \ -FFTW_EXTERN double X(cost)(const X(plan) p); \ - \ -FFTW_EXTERN const char X(version)[]; \ -FFTW_EXTERN const char X(cc)[]; \ -FFTW_EXTERN const char X(codelet_optim)[]; - - -/* end of FFTW_DEFINE_API macro */ - -FFTW_DEFINE_API(FFTW_MANGLE_DOUBLE, double, fftw_complex) -FFTW_DEFINE_API(FFTW_MANGLE_FLOAT, float, fftwf_complex) -FFTW_DEFINE_API(FFTW_MANGLE_LONG_DOUBLE, long double, fftwl_complex) - -/* __float128 (quad precision) is a gcc extension on i386, x86_64, and ia64 - for gcc >= 4.6 (compiled in FFTW with --enable-quad-precision) */ -#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \ - && !(defined(__ICC) || defined(__INTEL_COMPILER)) \ - && (defined(__i386__) || defined(__x86_64__) || defined(__ia64__)) -# if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) -/* note: __float128 is a typedef, which is not supported with the _Complex - keyword in gcc, so instead we use this ugly __attribute__ version. - However, we can't simply pass the __attribute__ version to - FFTW_DEFINE_API because the __attribute__ confuses gcc in pointer - types. Hence redefining FFTW_DEFINE_COMPLEX. Ugh. */ -# undef FFTW_DEFINE_COMPLEX -# define FFTW_DEFINE_COMPLEX(R, C) typedef _Complex float __attribute__((mode(TC))) C -# endif -FFTW_DEFINE_API(FFTW_MANGLE_QUAD, __float128, fftwq_complex) -#endif - -#define FFTW_FORWARD (-1) -#define FFTW_BACKWARD (+1) - -#define FFTW_NO_TIMELIMIT (-1.0) - -/* documented flags */ -#define FFTW_MEASURE (0U) -#define FFTW_DESTROY_INPUT (1U << 0) -#define FFTW_UNALIGNED (1U << 1) -#define FFTW_CONSERVE_MEMORY (1U << 2) -#define FFTW_EXHAUSTIVE (1U << 3) /* NO_EXHAUSTIVE is default */ -#define FFTW_PRESERVE_INPUT (1U << 4) /* cancels FFTW_DESTROY_INPUT */ -#define FFTW_PATIENT (1U << 5) /* IMPATIENT is default */ -#define FFTW_ESTIMATE (1U << 6) -#define FFTW_WISDOM_ONLY (1U << 21) - -/* undocumented beyond-guru flags */ -#define FFTW_ESTIMATE_PATIENT (1U << 7) -#define FFTW_BELIEVE_PCOST (1U << 8) -#define FFTW_NO_DFT_R2HC (1U << 9) -#define FFTW_NO_NONTHREADED (1U << 10) -#define FFTW_NO_BUFFERING (1U << 11) -#define FFTW_NO_INDIRECT_OP (1U << 12) -#define FFTW_ALLOW_LARGE_GENERIC (1U << 13) /* NO_LARGE_GENERIC is default */ -#define FFTW_NO_RANK_SPLITS (1U << 14) -#define FFTW_NO_VRANK_SPLITS (1U << 15) -#define FFTW_NO_VRECURSE (1U << 16) -#define FFTW_NO_SIMD (1U << 17) -#define FFTW_NO_SLOW (1U << 18) -#define FFTW_NO_FIXED_RADIX_LARGE_N (1U << 19) -#define FFTW_ALLOW_PRUNING (1U << 20) - -#ifdef __cplusplus -} /* extern "C" */ -#endif /* __cplusplus */ - -#endif /* FFTW3_H */ +/* + * Copyright (c) 2003, 2007-11 Matteo Frigo + * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology + * + * The following statement of license applies *only* to this header file, + * and *not* to the other files distributed with FFTW or derived therefrom: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/***************************** NOTE TO USERS ********************************* + * + * THIS IS A HEADER FILE, NOT A MANUAL + * + * If you want to know how to use FFTW, please read the manual, + * online at http://www.fftw.org/doc/ and also included with FFTW. + * For a quick start, see the manual's tutorial section. + * + * (Reading header files to learn how to use a library is a habit + * stemming from code lacking a proper manual. Arguably, it's a + * *bad* habit in most cases, because header files can contain + * interfaces that are not part of the public, stable API.) + * + ****************************************************************************/ + +#ifndef FFTW3_H +#define FFTW3_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/* If is included, use the C99 complex type. Otherwise + define a type bit-compatible with C99 complex */ +#if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) +# define FFTW_DEFINE_COMPLEX(R, C) typedef R _Complex C +#else +# define FFTW_DEFINE_COMPLEX(R, C) typedef R C[2] +#endif + +#define FFTW_CONCAT(prefix, name) prefix ## name +#define FFTW_MANGLE_DOUBLE(name) FFTW_CONCAT(fftw_, name) +#define FFTW_MANGLE_FLOAT(name) FFTW_CONCAT(fftwf_, name) +#define FFTW_MANGLE_LONG_DOUBLE(name) FFTW_CONCAT(fftwl_, name) +#define FFTW_MANGLE_QUAD(name) FFTW_CONCAT(fftwq_, name) + +/* IMPORTANT: for Windows compilers, you should add a line + #define FFTW_DLL + here and in kernel/ifftw.h if you are compiling/using FFTW as a + DLL, in order to do the proper importing/exporting, or + alternatively compile with -DFFTW_DLL or the equivalent + command-line flag. This is not necessary under MinGW/Cygwin, where + libtool does the imports/exports automatically. */ +#if defined(FFTW_DLL) && (defined(_WIN32) || defined(__WIN32__)) + /* annoying Windows syntax for shared-library declarations */ +# if defined(COMPILING_FFTW) /* defined in api.h when compiling FFTW */ +# define FFTW_EXTERN extern __declspec(dllexport) +# else /* user is calling FFTW; import symbol */ +# define FFTW_EXTERN extern __declspec(dllimport) +# endif +#else +# define FFTW_EXTERN extern +#endif + +enum fftw_r2r_kind_do_not_use_me { + FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2, + FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6, + FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10 +}; + +struct fftw_iodim_do_not_use_me { + int n; /* dimension size */ + int is; /* input stride */ + int os; /* output stride */ +}; + +#include /* for ptrdiff_t */ +struct fftw_iodim64_do_not_use_me { + ptrdiff_t n; /* dimension size */ + ptrdiff_t is; /* input stride */ + ptrdiff_t os; /* output stride */ +}; + +typedef void (*fftw_write_char_func_do_not_use_me)(char c, void *); +typedef int (*fftw_read_char_func_do_not_use_me)(void *); + +/* + huge second-order macro that defines prototypes for all API + functions. We expand this macro for each supported precision + + X: name-mangling macro + R: real data type + C: complex data type +*/ + +#define FFTW_DEFINE_API(X, R, C) \ + \ +FFTW_DEFINE_COMPLEX(R, C); \ + \ +typedef struct X(plan_s) *X(plan); \ + \ +typedef struct fftw_iodim_do_not_use_me X(iodim); \ +typedef struct fftw_iodim64_do_not_use_me X(iodim64); \ + \ +typedef enum fftw_r2r_kind_do_not_use_me X(r2r_kind); \ + \ +typedef fftw_write_char_func_do_not_use_me X(write_char_func); \ +typedef fftw_read_char_func_do_not_use_me X(read_char_func); \ + \ +FFTW_EXTERN void X(execute)(const X(plan) p); \ + \ +FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \ + C *in, C *out, int sign, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_dft_1d)(int n, C *in, C *out, int sign, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_2d)(int n0, int n1, \ + C *in, C *out, int sign, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_3d)(int n0, int n1, int n2, \ + C *in, C *out, int sign, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_many_dft)(int rank, const int *n, \ + int howmany, \ + C *in, const int *inembed, \ + int istride, int idist, \ + C *out, const int *onembed, \ + int ostride, int odist, \ + int sign, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru_dft)(int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + C *in, C *out, \ + int sign, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru_split_dft)(int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + R *ri, R *ii, R *ro, R *io, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru64_dft)(int rank, \ + const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + C *in, C *out, \ + int sign, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru64_split_dft)(int rank, \ + const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + R *ri, R *ii, R *ro, R *io, \ + unsigned flags); \ + \ +FFTW_EXTERN void X(execute_dft)(const X(plan) p, C *in, C *out); \ +FFTW_EXTERN void X(execute_split_dft)(const X(plan) p, R *ri, R *ii, \ + R *ro, R *io); \ + \ +FFTW_EXTERN X(plan) X(plan_many_dft_r2c)(int rank, const int *n, \ + int howmany, \ + R *in, const int *inembed, \ + int istride, int idist, \ + C *out, const int *onembed, \ + int ostride, int odist, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_dft_r2c)(int rank, const int *n, \ + R *in, C *out, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_dft_r2c_1d)(int n,R *in,C *out,unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_r2c_2d)(int n0, int n1, \ + R *in, C *out, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_r2c_3d)(int n0, int n1, \ + int n2, \ + R *in, C *out, unsigned flags); \ + \ + \ +FFTW_EXTERN X(plan) X(plan_many_dft_c2r)(int rank, const int *n, \ + int howmany, \ + C *in, const int *inembed, \ + int istride, int idist, \ + R *out, const int *onembed, \ + int ostride, int odist, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_dft_c2r)(int rank, const int *n, \ + C *in, R *out, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_dft_c2r_1d)(int n,C *in,R *out,unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_c2r_2d)(int n0, int n1, \ + C *in, R *out, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_c2r_3d)(int n0, int n1, \ + int n2, \ + C *in, R *out, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru_dft_r2c)(int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + R *in, C *out, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru_dft_c2r)(int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + C *in, R *out, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru_split_dft_r2c)( \ + int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + R *in, R *ro, R *io, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru_split_dft_c2r)( \ + int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + R *ri, R *ii, R *out, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru64_dft_r2c)(int rank, \ + const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + R *in, C *out, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru64_dft_c2r)(int rank, \ + const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + C *in, R *out, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru64_split_dft_r2c)( \ + int rank, const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + R *in, R *ro, R *io, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru64_split_dft_c2r)( \ + int rank, const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + R *ri, R *ii, R *out, \ + unsigned flags); \ + \ +FFTW_EXTERN void X(execute_dft_r2c)(const X(plan) p, R *in, C *out); \ +FFTW_EXTERN void X(execute_dft_c2r)(const X(plan) p, C *in, R *out); \ + \ +FFTW_EXTERN void X(execute_split_dft_r2c)(const X(plan) p, \ + R *in, R *ro, R *io); \ +FFTW_EXTERN void X(execute_split_dft_c2r)(const X(plan) p, \ + R *ri, R *ii, R *out); \ + \ +FFTW_EXTERN X(plan) X(plan_many_r2r)(int rank, const int *n, \ + int howmany, \ + R *in, const int *inembed, \ + int istride, int idist, \ + R *out, const int *onembed, \ + int ostride, int odist, \ + const X(r2r_kind) *kind, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_r2r)(int rank, const int *n, R *in, R *out, \ + const X(r2r_kind) *kind, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_r2r_1d)(int n, R *in, R *out, \ + X(r2r_kind) kind, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_r2r_2d)(int n0, int n1, R *in, R *out, \ + X(r2r_kind) kind0, X(r2r_kind) kind1, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_r2r_3d)(int n0, int n1, int n2, \ + R *in, R *out, X(r2r_kind) kind0, \ + X(r2r_kind) kind1, X(r2r_kind) kind2, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru_r2r)(int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + R *in, R *out, \ + const X(r2r_kind) *kind, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru64_r2r)(int rank, const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + R *in, R *out, \ + const X(r2r_kind) *kind, unsigned flags); \ + \ +FFTW_EXTERN void X(execute_r2r)(const X(plan) p, R *in, R *out); \ + \ +FFTW_EXTERN void X(destroy_plan)(X(plan) p); \ +FFTW_EXTERN void X(forget_wisdom)(void); \ +FFTW_EXTERN void X(cleanup)(void); \ + \ +FFTW_EXTERN void X(set_timelimit)(double t); \ + \ +FFTW_EXTERN void X(plan_with_nthreads)(int nthreads); \ +FFTW_EXTERN int X(init_threads)(void); \ +FFTW_EXTERN void X(cleanup_threads)(void); \ + \ +FFTW_EXTERN int X(export_wisdom_to_filename)(const char *filename); \ +FFTW_EXTERN void X(export_wisdom_to_file)(FILE *output_file); \ +FFTW_EXTERN char *X(export_wisdom_to_string)(void); \ +FFTW_EXTERN void X(export_wisdom)(X(write_char_func) write_char, \ + void *data); \ +FFTW_EXTERN int X(import_system_wisdom)(void); \ +FFTW_EXTERN int X(import_wisdom_from_filename)(const char *filename); \ +FFTW_EXTERN int X(import_wisdom_from_file)(FILE *input_file); \ +FFTW_EXTERN int X(import_wisdom_from_string)(const char *input_string); \ +FFTW_EXTERN int X(import_wisdom)(X(read_char_func) read_char, void *data); \ + \ +FFTW_EXTERN void X(fprint_plan)(const X(plan) p, FILE *output_file); \ +FFTW_EXTERN void X(print_plan)(const X(plan) p); \ + \ +FFTW_EXTERN void *X(malloc)(size_t n); \ +FFTW_EXTERN R *X(alloc_real)(size_t n); \ +FFTW_EXTERN C *X(alloc_complex)(size_t n); \ +FFTW_EXTERN void X(free)(void *p); \ + \ +FFTW_EXTERN void X(flops)(const X(plan) p, \ + double *add, double *mul, double *fmas); \ +FFTW_EXTERN double X(estimate_cost)(const X(plan) p); \ +FFTW_EXTERN double X(cost)(const X(plan) p); \ + \ +FFTW_EXTERN const char X(version)[]; \ +FFTW_EXTERN const char X(cc)[]; \ +FFTW_EXTERN const char X(codelet_optim)[]; + + +/* end of FFTW_DEFINE_API macro */ + +FFTW_DEFINE_API(FFTW_MANGLE_DOUBLE, double, fftw_complex) +FFTW_DEFINE_API(FFTW_MANGLE_FLOAT, float, fftwf_complex) +FFTW_DEFINE_API(FFTW_MANGLE_LONG_DOUBLE, long double, fftwl_complex) + +/* __float128 (quad precision) is a gcc extension on i386, x86_64, and ia64 + for gcc >= 4.6 (compiled in FFTW with --enable-quad-precision) */ +#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \ + && !(defined(__ICC) || defined(__INTEL_COMPILER)) \ + && (defined(__i386__) || defined(__x86_64__) || defined(__ia64__)) +# if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) +/* note: __float128 is a typedef, which is not supported with the _Complex + keyword in gcc, so instead we use this ugly __attribute__ version. + However, we can't simply pass the __attribute__ version to + FFTW_DEFINE_API because the __attribute__ confuses gcc in pointer + types. Hence redefining FFTW_DEFINE_COMPLEX. Ugh. */ +# undef FFTW_DEFINE_COMPLEX +# define FFTW_DEFINE_COMPLEX(R, C) typedef _Complex float __attribute__((mode(TC))) C +# endif +FFTW_DEFINE_API(FFTW_MANGLE_QUAD, __float128, fftwq_complex) +#endif + +#define FFTW_FORWARD (-1) +#define FFTW_BACKWARD (+1) + +#define FFTW_NO_TIMELIMIT (-1.0) + +/* documented flags */ +#define FFTW_MEASURE (0U) +#define FFTW_DESTROY_INPUT (1U << 0) +#define FFTW_UNALIGNED (1U << 1) +#define FFTW_CONSERVE_MEMORY (1U << 2) +#define FFTW_EXHAUSTIVE (1U << 3) /* NO_EXHAUSTIVE is default */ +#define FFTW_PRESERVE_INPUT (1U << 4) /* cancels FFTW_DESTROY_INPUT */ +#define FFTW_PATIENT (1U << 5) /* IMPATIENT is default */ +#define FFTW_ESTIMATE (1U << 6) +#define FFTW_WISDOM_ONLY (1U << 21) + +/* undocumented beyond-guru flags */ +#define FFTW_ESTIMATE_PATIENT (1U << 7) +#define FFTW_BELIEVE_PCOST (1U << 8) +#define FFTW_NO_DFT_R2HC (1U << 9) +#define FFTW_NO_NONTHREADED (1U << 10) +#define FFTW_NO_BUFFERING (1U << 11) +#define FFTW_NO_INDIRECT_OP (1U << 12) +#define FFTW_ALLOW_LARGE_GENERIC (1U << 13) /* NO_LARGE_GENERIC is default */ +#define FFTW_NO_RANK_SPLITS (1U << 14) +#define FFTW_NO_VRANK_SPLITS (1U << 15) +#define FFTW_NO_VRECURSE (1U << 16) +#define FFTW_NO_SIMD (1U << 17) +#define FFTW_NO_SLOW (1U << 18) +#define FFTW_NO_FIXED_RADIX_LARGE_N (1U << 19) +#define FFTW_ALLOW_PRUNING (1U << 20) + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* FFTW3_H */ diff --git a/lib/wsprd/genmet.f90 b/lib/wsprd/genmet.f90 index c0d5ffc2..e5dcdaba 100755 --- a/lib/wsprd/genmet.f90 +++ b/lib/wsprd/genmet.f90 @@ -1,50 +1,50 @@ -program genmet - - character*12 arg - integer hist(-128:128) - lim(x)=min(127,max(-128,nint(scale*x))) - - nargs=iargc() - if(nargs.ne.4) then - print*,'Usage: genmet bw scale snr iters' - print*,'Example: genmet 1.46 20 -24 1000000' - go to 999 - endif - call getarg(1,arg) - read(arg,*) bw - call getarg(2,arg) - read(arg,*) scale - call getarg(3,arg) - read(arg,*) snr - call getarg(4,arg) - read(arg,*) iters - - hist=0 - s=sqrt(2500.0/bw) * 10.0**(0.05*snr) - fac=1.0/sqrt(2.0) - do iter=1,iters - x1=fac*gran() - y1=fac*gran() - x0=fac*gran() - y0=fac*gran() - r=(x1+s)**2 + y1*y1 - x0*x0 - y0*y0 - hist(lim(r))=hist(lim(r))+1 - enddo - - xln2=log(2.0) - do i=-128,127 - p1=hist(i)/dfloat(iters) - j=-i - if(j.gt.127) j=127 - p0=hist(j)/dfloat(iters) - xlhd0=log(max(0.001,2.0*p0/(p0+p1)))/xln2 - xlhd1=log(max(0.001,2.0*p1/(p0+p1)))/xln2 - write(13,1010) i/scale,hist(i)/dfloat(iters) -1010 format(f8.3,f12.9) - write(14,1012) i+128,xlhd0,xlhd1 -1012 format(i4,2f8.3) - enddo - -999 end program genmet - - +program genmet + + character*12 arg + integer hist(-128:128) + lim(x)=min(127,max(-128,nint(scale*x))) + + nargs=iargc() + if(nargs.ne.4) then + print*,'Usage: genmet bw scale snr iters' + print*,'Example: genmet 1.46 20 -24 1000000' + go to 999 + endif + call getarg(1,arg) + read(arg,*) bw + call getarg(2,arg) + read(arg,*) scale + call getarg(3,arg) + read(arg,*) snr + call getarg(4,arg) + read(arg,*) iters + + hist=0 + s=sqrt(2500.0/bw) * 10.0**(0.05*snr) + fac=1.0/sqrt(2.0) + do iter=1,iters + x1=fac*gran() + y1=fac*gran() + x0=fac*gran() + y0=fac*gran() + r=(x1+s)**2 + y1*y1 - x0*x0 - y0*y0 + hist(lim(r))=hist(lim(r))+1 + enddo + + xln2=log(2.0) + do i=-128,127 + p1=hist(i)/dfloat(iters) + j=-i + if(j.gt.127) j=127 + p0=hist(j)/dfloat(iters) + xlhd0=log(max(0.001,2.0*p0/(p0+p1)))/xln2 + xlhd1=log(max(0.001,2.0*p1/(p0+p1)))/xln2 + write(13,1010) i/scale,hist(i)/dfloat(iters) +1010 format(f8.3,f12.9) + write(14,1012) i+128,xlhd0,xlhd1 +1012 format(i4,2f8.3) + enddo + +999 end program genmet + + diff --git a/lib/wsprd/gran.c b/lib/wsprd/gran.c index ceeb6da7..24b98650 100755 --- a/lib/wsprd/gran.c +++ b/lib/wsprd/gran.c @@ -1,28 +1,28 @@ -#include -#include - -/* 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 +#include + +/* Generate gaussian random float with mean=0 and std_dev=1 */ +float gran_() +{ + float fac,rsq,v1,v2; + static float gset; + static int iset; + + if(iset){ + /* Already got one */ + iset = 0; + return gset; + } + /* Generate two evenly distributed numbers between -1 and +1 + * that are inside the unit circle + */ + do { + v1 = 2.0 * (float)rand() / RAND_MAX - 1; + v2 = 2.0 * (float)rand() / RAND_MAX - 1; + rsq = v1*v1 + v2*v2; + } while(rsq >= 1.0 || rsq == 0.0); + fac = sqrt(-2.0*log(rsq)/rsq); + gset = v1*fac; + iset++; + return v2*fac; +} diff --git a/lib/wsprd/jelinek.c b/lib/wsprd/jelinek.c index 551a9d46..8fe0d2f7 100755 --- a/lib/wsprd/jelinek.c +++ b/lib/wsprd/jelinek.c @@ -1,163 +1,163 @@ -/* - Soft-decision stack-based sequential decoder for K=32 r=1/2 - convolutional code. This code implements the "stack-bucket" algorithm - described in: - "Fast Sequential Decoding Algorithm Using a Stack", F. Jelinek - - The ENCODE macro from Phil Karn's (KA9Q) Fano decoder is used. - - Written by Steve Franke, K9AN for WSJT-X (July 2015) - */ - -#include "jelinek.h" - -#include -#include -#include -#include /* memset */ - -#include "fano.h" - -/* WSPR uses the Layland-Lushbaugh code - * Nonsystematic, non-quick look-in, dmin=?, dfree=? - */ -#define POLY1 0xf2d05351 -#define POLY2 0xe4613c47 - -//Decoder - returns 0 on success, -1 on timeout -int jelinek( - unsigned int *metric, /* Final path metric (returned value) */ - unsigned int *cycles, /* Cycle count (returned value) */ - unsigned char *data, /* Decoded output data */ - unsigned char *symbols, /* Raw deinterleaved input symbols */ - unsigned int nbits, /* Number of output bits */ - unsigned int stacksize, - struct snode *stack, - int mettab[2][256], /* Metric table, [sent sym][rx symbol] */ - unsigned int maxcycles)/* Decoding timeout in cycles per bit */ -{ - - // Compute branch metrics for each symbol pair - // The sequential decoding algorithm only uses the metrics, not the - // symbol values. - unsigned int i; - long int metrics[81][4]; - for(i=0; i>5)+200; //fast, but not particularly safe - totmet can be negative - if( bucket > high_bucket ) high_bucket=bucket; - if( bucket < low_bucket ) low_bucket=bucket; - - // place the 0 node on the stack, overwriting the parent (current) node - stack[ptr].encstate=encstate; - stack[ptr].gamma=totmet0; - stack[ptr].depth=depth; - stack[ptr].jpointer=buckets[bucket]; - buckets[bucket]=ptr; - - // if in the tail, only need to evaluate the "0" branch. - // Otherwise, enter this "if" and place the 1 node on the stack, - if( depth <= nbits_minus_ntail ) { - if( stackptr < stacksize_minus_1 ) { - stackptr++; - ptr=stackptr; - } else { // stack full - while( buckets[low_bucket] == 0 ) { //write latest to where the top of the lowest bucket points - low_bucket++; - } - ptr=buckets[low_bucket]; - buckets[low_bucket]=stack[ptr].jpointer; //make bucket point to next older entry - } - - bucket=(totmet1>>5)+200; //this may not be safe on all compilers - if( bucket > high_bucket ) high_bucket=bucket; - if( bucket < low_bucket ) low_bucket=bucket; - - stack[ptr].encstate=encstate+1; - stack[ptr].gamma=totmet1; - stack[ptr].depth=depth; - stack[ptr].jpointer=buckets[bucket]; - buckets[bucket]=ptr; - } - - // pick off the latest entry from the high bucket - while( buckets[high_bucket] == 0 ) { - high_bucket--; - } - ptr=buckets[high_bucket]; - buckets[high_bucket]=stack[ptr].jpointer; - depth=stack[ptr].depth; - gamma=stack[ptr].gamma; - encstate=stack[ptr].encstate; - - // we are done if the top entry on the stack is at depth nbits - if (depth == nbits) { - break; - } - } - - *cycles = i+1; - *metric = gamma; /* Return final path metric */ - - // printf("cycles %d stackptr=%d, depth=%d, gamma=%d, encstate=%lx\n", - // *cycles, stackptr, depth, *metric, encstate); - - for (i=0; i<7; i++) { - data[i]=(encstate>>(48-i*8))&(0x00000000000000ff); - } - for (i=7; i<11; i++) { - data[i]=0; - } - - if(*cycles/nbits >= maxcycles) //timed out - { - return -1; - } - return 0; //success -} +/* + Soft-decision stack-based sequential decoder for K=32 r=1/2 + convolutional code. This code implements the "stack-bucket" algorithm + described in: + "Fast Sequential Decoding Algorithm Using a Stack", F. Jelinek + + The ENCODE macro from Phil Karn's (KA9Q) Fano decoder is used. + + Written by Steve Franke, K9AN for WSJT-X (July 2015) + */ + +#include "jelinek.h" + +#include +#include +#include +#include /* memset */ + +#include "fano.h" + +/* WSPR uses the Layland-Lushbaugh code + * Nonsystematic, non-quick look-in, dmin=?, dfree=? + */ +#define POLY1 0xf2d05351 +#define POLY2 0xe4613c47 + +//Decoder - returns 0 on success, -1 on timeout +int jelinek( + unsigned int *metric, /* Final path metric (returned value) */ + unsigned int *cycles, /* Cycle count (returned value) */ + unsigned char *data, /* Decoded output data */ + unsigned char *symbols, /* Raw deinterleaved input symbols */ + unsigned int nbits, /* Number of output bits */ + unsigned int stacksize, + struct snode *stack, + int mettab[2][256], /* Metric table, [sent sym][rx symbol] */ + unsigned int maxcycles)/* Decoding timeout in cycles per bit */ +{ + + // Compute branch metrics for each symbol pair + // The sequential decoding algorithm only uses the metrics, not the + // symbol values. + unsigned int i; + long int metrics[81][4]; + for(i=0; i>5)+200; //fast, but not particularly safe - totmet can be negative + if( bucket > high_bucket ) high_bucket=bucket; + if( bucket < low_bucket ) low_bucket=bucket; + + // place the 0 node on the stack, overwriting the parent (current) node + stack[ptr].encstate=encstate; + stack[ptr].gamma=totmet0; + stack[ptr].depth=depth; + stack[ptr].jpointer=buckets[bucket]; + buckets[bucket]=ptr; + + // if in the tail, only need to evaluate the "0" branch. + // Otherwise, enter this "if" and place the 1 node on the stack, + if( depth <= nbits_minus_ntail ) { + if( stackptr < stacksize_minus_1 ) { + stackptr++; + ptr=stackptr; + } else { // stack full + while( buckets[low_bucket] == 0 ) { //write latest to where the top of the lowest bucket points + low_bucket++; + } + ptr=buckets[low_bucket]; + buckets[low_bucket]=stack[ptr].jpointer; //make bucket point to next older entry + } + + bucket=(totmet1>>5)+200; //this may not be safe on all compilers + if( bucket > high_bucket ) high_bucket=bucket; + if( bucket < low_bucket ) low_bucket=bucket; + + stack[ptr].encstate=encstate+1; + stack[ptr].gamma=totmet1; + stack[ptr].depth=depth; + stack[ptr].jpointer=buckets[bucket]; + buckets[bucket]=ptr; + } + + // pick off the latest entry from the high bucket + while( buckets[high_bucket] == 0 ) { + high_bucket--; + } + ptr=buckets[high_bucket]; + buckets[high_bucket]=stack[ptr].jpointer; + depth=stack[ptr].depth; + gamma=stack[ptr].gamma; + encstate=stack[ptr].encstate; + + // we are done if the top entry on the stack is at depth nbits + if (depth == nbits) { + break; + } + } + + *cycles = i+1; + *metric = gamma; /* Return final path metric */ + + // printf("cycles %d stackptr=%d, depth=%d, gamma=%d, encstate=%lx\n", + // *cycles, stackptr, depth, *metric, encstate); + + for (i=0; i<7; i++) { + data[i]=(encstate>>(48-i*8))&(0x00000000000000ff); + } + for (i=7; i<11; i++) { + data[i]=0; + } + + if(*cycles/nbits >= maxcycles) //timed out + { + return -1; + } + return 0; //success +} diff --git a/lib/wsprd/jelinek.h b/lib/wsprd/jelinek.h index 81de1218..82ce1deb 100755 --- a/lib/wsprd/jelinek.h +++ b/lib/wsprd/jelinek.h @@ -1,24 +1,24 @@ -#ifndef JELINEK_H -#define JELINEK_H - -#include - -struct snode { - uint64_t encstate; // Encoder state - int gamma; // Cumulative metric to this node - unsigned int depth; // depth of this node - unsigned int jpointer; -}; - -int jelinek(unsigned int *metric, - unsigned int *cycles, - unsigned char *data, - unsigned char *symbols, - unsigned int nbits, - unsigned int stacksize, - struct snode *stack, - int mettab[2][256], - unsigned int maxcycles); - -#endif - +#ifndef JELINEK_H +#define JELINEK_H + +#include + +struct snode { + uint64_t encstate; // Encoder state + int gamma; // Cumulative metric to this node + unsigned int depth; // depth of this node + unsigned int jpointer; +}; + +int jelinek(unsigned int *metric, + unsigned int *cycles, + unsigned char *data, + unsigned char *symbols, + unsigned int nbits, + unsigned int stacksize, + struct snode *stack, + int mettab[2][256], + unsigned int maxcycles); + +#endif + diff --git a/lib/wsprd/metric_tables.c b/lib/wsprd/metric_tables.c index f05c6b79..973651d7 100755 --- a/lib/wsprd/metric_tables.c +++ b/lib/wsprd/metric_tables.c @@ -1,138 +1,138 @@ -/******************************************************************************* -* 4 metric tables calculated via simulation for 2-FSK with Es/No=0,3,6,9 dB -* tables were calculated for constant rms noise level of 50. The symbol vector -* should be normalized to have rms amplitude equal to "symbol_scale". -********************************************************************************/ -//float symbol_scale[5]={42.6, 53.3, 72.7, 100.2, 125.4}; -float metric_tables[5][256]={ - {0.9782, 0.9695, 0.9689, 0.9669, 0.9666, 0.9653, 0.9638, 0.9618, 0.9599, 0.9601, - 0.9592, 0.9570, 0.9556, 0.9540, 0.9525, 0.9527, 0.9486, 0.9477, 0.9450, 0.9436, - 0.9424, 0.9400, 0.9381, 0.9360, 0.9340, 0.9316, 0.9301, 0.9272, 0.9254, 0.9224, - 0.9196, 0.9171, 0.9154, 0.9123, 0.9076, 0.9061, 0.9030, 0.9000, 0.8965, 0.8934, - 0.8903, 0.8874, 0.8834, 0.8792, 0.8760, 0.8726, 0.8685, 0.8639, 0.8599, 0.8550, - 0.8504, 0.8459, 0.8422, 0.8364, 0.8320, 0.8262, 0.8215, 0.8159, 0.8111, 0.8052, - 0.7996, 0.7932, 0.7878, 0.7812, 0.7745, 0.7685, 0.7616, 0.7550, 0.7479, 0.7405, - 0.7336, 0.7255, 0.7184, 0.7102, 0.7016, 0.6946, 0.6860, 0.6769, 0.6687, 0.6598, - 0.6503, 0.6416, 0.6325, 0.6219, 0.6122, 0.6016, 0.5920, 0.5818, 0.5711, 0.5606, - 0.5487, 0.5374, 0.5266, 0.5142, 0.5020, 0.4908, 0.4784, 0.4663, 0.4532, 0.4405, - 0.4271, 0.4144, 0.4006, 0.3865, 0.3731, 0.3594, 0.3455, 0.3304, 0.3158, 0.3009, - 0.2858, 0.2708, 0.2560, 0.2399, 0.2233, 0.2074, 0.1919, 0.1756, 0.1590, 0.1427, - 0.1251, 0.1074, 0.0905, 0.0722, 0.0550, 0.0381, 0.0183, 0.0000, -0.0185, -0.0391, - -0.0571, -0.0760, -0.0966, -0.1160, -0.1370, -0.1584, -0.1787, -0.1999, -0.2214, -0.2423, - -0.2643, -0.2879, -0.3114, -0.3336, -0.3568, -0.3806, -0.4050, -0.4293, -0.4552, -0.4798, - -0.5046, -0.5296, -0.5564, -0.5836, -0.6093, -0.6372, -0.6645, -0.6933, -0.7208, -0.7495, - -0.7763, -0.8065, -0.8378, -0.8660, -0.8964, -0.9293, -0.9592, -0.9907, -1.0214, -1.0509, - -1.0850, -1.1168, -1.1528, -1.1847, -1.2157, -1.2511, -1.2850, -1.3174, -1.3540, -1.3900, - -1.4201, -1.4580, -1.4956, -1.5292, -1.5683, -1.6030, -1.6411, -1.6789, -1.7147, -1.7539, - -1.7887, -1.8289, -1.8699, -1.9043, -1.9469, -1.9849, -2.0267, -2.0610, -2.1028, -2.1391, - -2.1855, -2.2215, -2.2712, -2.3033, -2.3440, -2.3870, -2.4342, -2.4738, -2.5209, -2.5646, - -2.6016, -2.6385, -2.6868, -2.7356, -2.7723, -2.8111, -2.8524, -2.9009, -2.9428, -2.9879, - -3.0103, -3.0832, -3.1340, -3.1628, -3.2049, -3.2557, -3.3101, -3.3453, -3.4025, -3.4317, - -3.4828, -3.5270, -3.5745, -3.6181, -3.6765, -3.7044, -3.7410, -3.8118, -3.8368, -3.9549, - -3.9488, -3.9941, -4.0428, -4.0892, -4.1648, -4.1965, -4.1892, -4.2565, -4.3356, -4.3948, - -4.4481, -4.4607, -4.5533, -4.5809, -4.5927, -5.1047}, - {0.9978, 0.9962, 0.9961, 0.9959, 0.9958, 0.9954, 0.9949, 0.9950, 0.9947, 0.9942, - 0.9940, 0.9939, 0.9933, 0.9931, 0.9928, 0.9924, 0.9921, 0.9916, 0.9911, 0.9909, - 0.9903, 0.9900, 0.9892, 0.9887, 0.9883, 0.9877, 0.9869, 0.9863, 0.9857, 0.9848, - 0.9842, 0.9835, 0.9825, 0.9817, 0.9808, 0.9799, 0.9791, 0.9777, 0.9767, 0.9757, - 0.9744, 0.9729, 0.9716, 0.9704, 0.9690, 0.9674, 0.9656, 0.9641, 0.9625, 0.9609, - 0.9587, 0.9567, 0.9548, 0.9524, 0.9501, 0.9478, 0.9453, 0.9426, 0.9398, 0.9371, - 0.9339, 0.9311, 0.9277, 0.9242, 0.9206, 0.9168, 0.9131, 0.9087, 0.9043, 0.8999, - 0.8953, 0.8907, 0.8857, 0.8803, 0.8747, 0.8690, 0.8632, 0.8572, 0.8507, 0.8439, - 0.8368, 0.8295, 0.8217, 0.8138, 0.8058, 0.7972, 0.7883, 0.7784, 0.7694, 0.7597, - 0.7489, 0.7378, 0.7269, 0.7152, 0.7030, 0.6911, 0.6782, 0.6643, 0.6506, 0.6371, - 0.6211, 0.6054, 0.5897, 0.5740, 0.5565, 0.5393, 0.5214, 0.5027, 0.4838, 0.4643, - 0.4436, 0.4225, 0.4004, 0.3787, 0.3562, 0.3324, 0.3089, 0.2839, 0.2584, 0.2321, - 0.2047, 0.1784, 0.1499, 0.1213, 0.0915, 0.0628, 0.0314, 0.0000, -0.0321, -0.0657, - -0.0977, -0.1324, -0.1673, -0.2036, -0.2387, -0.2768, -0.3150, -0.3538, -0.3936, -0.4327, - -0.4739, -0.5148, -0.5561, -0.6000, -0.6438, -0.6889, -0.7331, -0.7781, -0.8247, -0.8712, - -0.9177, -0.9677, -1.0142, -1.0631, -1.1143, -1.1686, -1.2169, -1.2680, -1.3223, -1.3752, - -1.4261, -1.4806, -1.5356, -1.5890, -1.6462, -1.7041, -1.7591, -1.8124, -1.8735, -1.9311, - -1.9891, -2.0459, -2.1048, -2.1653, -2.2248, -2.2855, -2.3466, -2.4079, -2.4668, -2.5263, - -2.5876, -2.6507, -2.7142, -2.7761, -2.8366, -2.8995, -2.9620, -3.0279, -3.0973, -3.1576, - -3.2238, -3.2890, -3.3554, -3.4215, -3.4805, -3.5518, -3.6133, -3.6812, -3.7473, -3.8140, - -3.8781, -3.9450, -4.0184, -4.0794, -4.1478, -4.2241, -4.2853, -4.3473, -4.4062, -4.4839, - -4.5539, -4.6202, -4.6794, -4.7478, -4.8309, -4.9048, -4.9669, -5.0294, -5.1194, -5.1732, - -5.2378, -5.3094, -5.3742, -5.4573, -5.5190, -5.5728, -5.6637, -5.7259, -5.7843, -5.8854, - -5.9553, -6.0054, -6.0656, -6.1707, -6.2241, -6.3139, -6.3393, -6.4356, -6.5153, -6.5758, - -6.6506, -6.7193, -6.7542, -6.8942, -6.9219, -6.9605, -7.1013, -7.1895, -7.1549, -7.2799, - -7.4119, -7.4608, -7.5256, -7.5879, -7.7598, -8.4120}, - {0.9999, 0.9998, 0.9998, 0.9998, 0.9998, 0.9998, 0.9997, 0.9997, 0.9997, 0.9997, - 0.9997, 0.9996, 0.9996, 0.9996, 0.9995, 0.9995, 0.9994, 0.9994, 0.9994, 0.9993, - 0.9993, 0.9992, 0.9991, 0.9991, 0.9990, 0.9989, 0.9988, 0.9988, 0.9988, 0.9986, - 0.9985, 0.9984, 0.9983, 0.9982, 0.9980, 0.9979, 0.9977, 0.9976, 0.9974, 0.9971, - 0.9969, 0.9968, 0.9965, 0.9962, 0.9960, 0.9957, 0.9953, 0.9950, 0.9947, 0.9941, - 0.9937, 0.9933, 0.9928, 0.9922, 0.9917, 0.9911, 0.9904, 0.9897, 0.9890, 0.9882, - 0.9874, 0.9863, 0.9855, 0.9843, 0.9832, 0.9819, 0.9806, 0.9792, 0.9777, 0.9760, - 0.9743, 0.9724, 0.9704, 0.9683, 0.9659, 0.9634, 0.9609, 0.9581, 0.9550, 0.9516, - 0.9481, 0.9446, 0.9406, 0.9363, 0.9317, 0.9270, 0.9218, 0.9160, 0.9103, 0.9038, - 0.8972, 0.8898, 0.8822, 0.8739, 0.8647, 0.8554, 0.8457, 0.8357, 0.8231, 0.8115, - 0.7984, 0.7854, 0.7704, 0.7556, 0.7391, 0.7210, 0.7038, 0.6840, 0.6633, 0.6408, - 0.6174, 0.5939, 0.5678, 0.5410, 0.5137, 0.4836, 0.4524, 0.4193, 0.3850, 0.3482, - 0.3132, 0.2733, 0.2315, 0.1891, 0.1435, 0.0980, 0.0493, 0.0000, -0.0510, -0.1052, - -0.1593, -0.2177, -0.2759, -0.3374, -0.4005, -0.4599, -0.5266, -0.5935, -0.6626, -0.7328, - -0.8051, -0.8757, -0.9498, -1.0271, -1.1019, -1.1816, -1.2642, -1.3459, -1.4295, -1.5077, - -1.5958, -1.6818, -1.7647, -1.8548, -1.9387, -2.0295, -2.1152, -2.2154, -2.3011, -2.3904, - -2.4820, -2.5786, -2.6730, -2.7652, -2.8616, -2.9546, -3.0526, -3.1445, -3.2445, -3.3416, - -3.4357, -3.5325, -3.6324, -3.7313, -3.8225, -3.9209, -4.0248, -4.1278, -4.2261, -4.3193, - -4.4220, -4.5262, -4.6214, -4.7242, -4.8234, -4.9245, -5.0298, -5.1250, -5.2232, -5.3267, - -5.4332, -5.5342, -5.6431, -5.7270, -5.8401, -5.9350, -6.0407, -6.1418, -6.2363, -6.3384, - -6.4536, -6.5429, -6.6582, -6.7433, -6.8438, -6.9478, -7.0789, -7.1894, -7.2714, -7.3815, - -7.4810, -7.5575, -7.6852, -7.8071, -7.8580, -7.9724, -8.1000, -8.2207, -8.2867, -8.4017, - -8.5287, -8.6347, -8.7082, -8.8319, -8.9448, -9.0355, -9.1885, -9.2095, -9.2863, -9.4186, - -9.5064, -9.6386, -9.7207, -9.8286, -9.9453, -10.0701, -10.1735, -10.3001, -10.2858, -10.5427, - -10.5982, -10.7361, -10.7042, -10.9212, -11.0097, -11.0469, -11.1155, -11.2812, -11.3472, -11.4988, - -11.5327, -11.6692, -11.9376, -11.8606, -12.1372, -13.2539}, - {1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, - 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, - 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, - 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, - 0.9999, 0.9998, 0.9998, 0.9998, 0.9998, 0.9997, 0.9997, 0.9997, 0.9997, 0.9996, - 0.9996, 0.9995, 0.9995, 0.9994, 0.9994, 0.9993, 0.9992, 0.9991, 0.9991, 0.9989, - 0.9988, 0.9986, 0.9985, 0.9983, 0.9981, 0.9980, 0.9977, 0.9974, 0.9971, 0.9968, - 0.9965, 0.9962, 0.9956, 0.9950, 0.9948, 0.9941, 0.9933, 0.9926, 0.9919, 0.9910, - 0.9899, 0.9889, 0.9877, 0.9863, 0.9845, 0.9829, 0.9811, 0.9791, 0.9769, 0.9741, - 0.9716, 0.9684, 0.9645, 0.9611, 0.9563, 0.9519, 0.9463, 0.9406, 0.9344, 0.9272, - 0.9197, 0.9107, 0.9016, 0.8903, 0.8791, 0.8653, 0.8523, 0.8357, 0.8179, 0.7988, - 0.7779, 0.7562, 0.7318, 0.7024, 0.6753, 0.6435, 0.6089, 0.5700, 0.5296, 0.4860, - 0.4366, 0.3855, 0.3301, 0.2735, 0.2114, 0.1443, 0.0682, 0.0000, -0.0715, -0.1604, - -0.2478, -0.3377, -0.4287, -0.5277, -0.6291, -0.7384, -0.8457, -0.9559, -1.0742, -1.1913, - -1.3110, -1.4238, -1.5594, -1.6854, -1.8093, -1.9414, -2.0763, -2.2160, -2.3611, -2.4876, - -2.6374, -2.7710, -2.9225, -3.0591, -3.2077, -3.3452, -3.4916, -3.6316, -3.7735, -3.9296, - -4.0682, -4.2334, -4.3607, -4.5270, -4.6807, -4.8108, -4.9753, -5.1212, -5.2631, -5.4042, - -5.5510, -5.7227, -5.8794, -6.0244, -6.1677, -6.3271, -6.4862, -6.6130, -6.7449, -6.9250, - -7.1232, -7.1736, -7.3628, -7.5596, -7.6906, -7.8129, -7.9817, -8.1440, -8.3016, -8.4797, - -8.5734, -8.7692, -8.9198, -9.0610, -9.1746, -9.3536, -9.5939, -9.6957, -9.8475, -9.9639, - -10.1730, -10.2427, -10.4573, -10.5413, -10.7303, -10.9339, -11.0215, -11.2047, -11.2894, -11.4572, - -11.6256, -11.7794, -11.8801, -12.1717, -12.2354, -12.3686, -12.6195, -12.6527, -12.8247, -12.9560, - -13.3265, -13.1667, -13.4274, -13.6064, -13.5515, -13.9501, -13.9926, -14.4049, -14.1653, -14.4348, - -14.7983, -14.7807, -15.2349, -15.3536, -15.3026, -15.2739, -15.7170, -16.2161, -15.9185, -15.9490, - -16.6258, -16.5568, -16.4318, -16.7999, -16.4101, -17.6393, -17.7643, -17.2644, -17.5973, -17.0403, - -17.7039, -18.0073, -18.1840, -18.3848, -18.6286, -20.7063}, - {1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, - 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, - 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, - 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, - 0.9999, 0.9998, 0.9998, 0.9998, 0.9998, 0.9997, 0.9997, 0.9997, 0.9997, 0.9996, - 0.9996, 0.9995, 0.9995, 0.9994, 0.9994, 0.9993, 0.9992, 0.9991, 0.9991, 0.9989, - 0.9988, 0.9986, 0.9985, 0.9983, 0.9981, 0.9980, 0.9977, 0.9974, 0.9971, 0.9968, - 0.9965, 0.9962, 0.9956, 0.9950, 0.9948, 0.9941, 0.9933, 0.9926, 0.9919, 0.9910, - 0.9899, 0.9889, 0.9877, 0.9863, 0.9845, 0.9829, 0.9811, 0.9791, 0.9769, 0.9741, - 0.9716, 0.9684, 0.9645, 0.9611, 0.9563, 0.9519, 0.9463, 0.9406, 0.9344, 0.9272, - 0.9197, 0.9107, 0.9016, 0.8903, 0.8791, 0.8653, 0.8523, 0.8357, 0.8179, 0.7988, - 0.7779, 0.7562, 0.7318, 0.7024, 0.6753, 0.6435, 0.6089, 0.5700, 0.5296, 0.4860, - 0.4366, 0.3855, 0.3301, 0.2735, 0.2114, 0.1443, 0.0682, 0.0000, -0.0715, -0.1604, - -0.2478, -0.3377, -0.4287, -0.5277, -0.6291, -0.7384, -0.8457, -0.9559, -1.0742, -1.1913, - -1.3110, -1.4238, -1.5594, -1.6854, -1.8093, -1.9414, -2.0763, -2.2160, -2.3611, -2.4876, - -2.6374, -2.7710, -2.9225, -3.0591, -3.2077, -3.3452, -3.4916, -3.6316, -3.7735, -3.9296, - -4.0682, -4.2334, -4.3607, -4.5270, -4.6807, -4.8108, -4.9753, -5.1212, -5.2631, -5.4042, - -5.5510, -5.7227, -5.8794, -6.0244, -6.1677, -6.3271, -6.4862, -6.6130, -6.7449, -6.9250, - -7.1232, -7.1736, -7.3628, -7.5596, -7.6906, -7.8129, -7.9817, -8.1440, -8.3016, -8.4797, - -8.5734, -8.7692, -8.9198, -9.0610, -9.1746, -9.3536, -9.5939, -9.6957, -9.8475, -9.9639, - -10.1730, -10.2427, -10.4573, -11.7794, -11.8801, -12.1717, -12.2354, -12.3686, -12.6195, -12.6527, - -12.8247, -12.9560, -13.3265, -13.1667, -13.4274, -13.6064, -13.5515, -13.9501, -13.9926, -14.4049, - -14.1653, -14.4348, -14.7983, -14.7807, -15.2349, -15.3536, -15.3026, -15.2739, -15.7170, -16.2161, - -15.9185, -15.9490, -16.6258, -16.5568, -16.4318, -16.7999, -16.4101, -17.6393, -17.7643, -17.2644, - -17.5973, -17.0403, -17.7039, -18.0073, -18.1840, -18.3848, -18.6286, -20.7063, 1.43370769e-019, - 2.64031087e-006, 6.6908396e+031, 1.77537994e+028, 2.79322819e+020, 1.94326e-019, - 0.00019371575, 2.80722121e-041}}; +/******************************************************************************* +* 4 metric tables calculated via simulation for 2-FSK with Es/No=0,3,6,9 dB +* tables were calculated for constant rms noise level of 50. The symbol vector +* should be normalized to have rms amplitude equal to "symbol_scale". +********************************************************************************/ +//float symbol_scale[5]={42.6, 53.3, 72.7, 100.2, 125.4}; +float metric_tables[5][256]={ + {0.9782, 0.9695, 0.9689, 0.9669, 0.9666, 0.9653, 0.9638, 0.9618, 0.9599, 0.9601, + 0.9592, 0.9570, 0.9556, 0.9540, 0.9525, 0.9527, 0.9486, 0.9477, 0.9450, 0.9436, + 0.9424, 0.9400, 0.9381, 0.9360, 0.9340, 0.9316, 0.9301, 0.9272, 0.9254, 0.9224, + 0.9196, 0.9171, 0.9154, 0.9123, 0.9076, 0.9061, 0.9030, 0.9000, 0.8965, 0.8934, + 0.8903, 0.8874, 0.8834, 0.8792, 0.8760, 0.8726, 0.8685, 0.8639, 0.8599, 0.8550, + 0.8504, 0.8459, 0.8422, 0.8364, 0.8320, 0.8262, 0.8215, 0.8159, 0.8111, 0.8052, + 0.7996, 0.7932, 0.7878, 0.7812, 0.7745, 0.7685, 0.7616, 0.7550, 0.7479, 0.7405, + 0.7336, 0.7255, 0.7184, 0.7102, 0.7016, 0.6946, 0.6860, 0.6769, 0.6687, 0.6598, + 0.6503, 0.6416, 0.6325, 0.6219, 0.6122, 0.6016, 0.5920, 0.5818, 0.5711, 0.5606, + 0.5487, 0.5374, 0.5266, 0.5142, 0.5020, 0.4908, 0.4784, 0.4663, 0.4532, 0.4405, + 0.4271, 0.4144, 0.4006, 0.3865, 0.3731, 0.3594, 0.3455, 0.3304, 0.3158, 0.3009, + 0.2858, 0.2708, 0.2560, 0.2399, 0.2233, 0.2074, 0.1919, 0.1756, 0.1590, 0.1427, + 0.1251, 0.1074, 0.0905, 0.0722, 0.0550, 0.0381, 0.0183, 0.0000, -0.0185, -0.0391, + -0.0571, -0.0760, -0.0966, -0.1160, -0.1370, -0.1584, -0.1787, -0.1999, -0.2214, -0.2423, + -0.2643, -0.2879, -0.3114, -0.3336, -0.3568, -0.3806, -0.4050, -0.4293, -0.4552, -0.4798, + -0.5046, -0.5296, -0.5564, -0.5836, -0.6093, -0.6372, -0.6645, -0.6933, -0.7208, -0.7495, + -0.7763, -0.8065, -0.8378, -0.8660, -0.8964, -0.9293, -0.9592, -0.9907, -1.0214, -1.0509, + -1.0850, -1.1168, -1.1528, -1.1847, -1.2157, -1.2511, -1.2850, -1.3174, -1.3540, -1.3900, + -1.4201, -1.4580, -1.4956, -1.5292, -1.5683, -1.6030, -1.6411, -1.6789, -1.7147, -1.7539, + -1.7887, -1.8289, -1.8699, -1.9043, -1.9469, -1.9849, -2.0267, -2.0610, -2.1028, -2.1391, + -2.1855, -2.2215, -2.2712, -2.3033, -2.3440, -2.3870, -2.4342, -2.4738, -2.5209, -2.5646, + -2.6016, -2.6385, -2.6868, -2.7356, -2.7723, -2.8111, -2.8524, -2.9009, -2.9428, -2.9879, + -3.0103, -3.0832, -3.1340, -3.1628, -3.2049, -3.2557, -3.3101, -3.3453, -3.4025, -3.4317, + -3.4828, -3.5270, -3.5745, -3.6181, -3.6765, -3.7044, -3.7410, -3.8118, -3.8368, -3.9549, + -3.9488, -3.9941, -4.0428, -4.0892, -4.1648, -4.1965, -4.1892, -4.2565, -4.3356, -4.3948, + -4.4481, -4.4607, -4.5533, -4.5809, -4.5927, -5.1047}, + {0.9978, 0.9962, 0.9961, 0.9959, 0.9958, 0.9954, 0.9949, 0.9950, 0.9947, 0.9942, + 0.9940, 0.9939, 0.9933, 0.9931, 0.9928, 0.9924, 0.9921, 0.9916, 0.9911, 0.9909, + 0.9903, 0.9900, 0.9892, 0.9887, 0.9883, 0.9877, 0.9869, 0.9863, 0.9857, 0.9848, + 0.9842, 0.9835, 0.9825, 0.9817, 0.9808, 0.9799, 0.9791, 0.9777, 0.9767, 0.9757, + 0.9744, 0.9729, 0.9716, 0.9704, 0.9690, 0.9674, 0.9656, 0.9641, 0.9625, 0.9609, + 0.9587, 0.9567, 0.9548, 0.9524, 0.9501, 0.9478, 0.9453, 0.9426, 0.9398, 0.9371, + 0.9339, 0.9311, 0.9277, 0.9242, 0.9206, 0.9168, 0.9131, 0.9087, 0.9043, 0.8999, + 0.8953, 0.8907, 0.8857, 0.8803, 0.8747, 0.8690, 0.8632, 0.8572, 0.8507, 0.8439, + 0.8368, 0.8295, 0.8217, 0.8138, 0.8058, 0.7972, 0.7883, 0.7784, 0.7694, 0.7597, + 0.7489, 0.7378, 0.7269, 0.7152, 0.7030, 0.6911, 0.6782, 0.6643, 0.6506, 0.6371, + 0.6211, 0.6054, 0.5897, 0.5740, 0.5565, 0.5393, 0.5214, 0.5027, 0.4838, 0.4643, + 0.4436, 0.4225, 0.4004, 0.3787, 0.3562, 0.3324, 0.3089, 0.2839, 0.2584, 0.2321, + 0.2047, 0.1784, 0.1499, 0.1213, 0.0915, 0.0628, 0.0314, 0.0000, -0.0321, -0.0657, + -0.0977, -0.1324, -0.1673, -0.2036, -0.2387, -0.2768, -0.3150, -0.3538, -0.3936, -0.4327, + -0.4739, -0.5148, -0.5561, -0.6000, -0.6438, -0.6889, -0.7331, -0.7781, -0.8247, -0.8712, + -0.9177, -0.9677, -1.0142, -1.0631, -1.1143, -1.1686, -1.2169, -1.2680, -1.3223, -1.3752, + -1.4261, -1.4806, -1.5356, -1.5890, -1.6462, -1.7041, -1.7591, -1.8124, -1.8735, -1.9311, + -1.9891, -2.0459, -2.1048, -2.1653, -2.2248, -2.2855, -2.3466, -2.4079, -2.4668, -2.5263, + -2.5876, -2.6507, -2.7142, -2.7761, -2.8366, -2.8995, -2.9620, -3.0279, -3.0973, -3.1576, + -3.2238, -3.2890, -3.3554, -3.4215, -3.4805, -3.5518, -3.6133, -3.6812, -3.7473, -3.8140, + -3.8781, -3.9450, -4.0184, -4.0794, -4.1478, -4.2241, -4.2853, -4.3473, -4.4062, -4.4839, + -4.5539, -4.6202, -4.6794, -4.7478, -4.8309, -4.9048, -4.9669, -5.0294, -5.1194, -5.1732, + -5.2378, -5.3094, -5.3742, -5.4573, -5.5190, -5.5728, -5.6637, -5.7259, -5.7843, -5.8854, + -5.9553, -6.0054, -6.0656, -6.1707, -6.2241, -6.3139, -6.3393, -6.4356, -6.5153, -6.5758, + -6.6506, -6.7193, -6.7542, -6.8942, -6.9219, -6.9605, -7.1013, -7.1895, -7.1549, -7.2799, + -7.4119, -7.4608, -7.5256, -7.5879, -7.7598, -8.4120}, + {0.9999, 0.9998, 0.9998, 0.9998, 0.9998, 0.9998, 0.9997, 0.9997, 0.9997, 0.9997, + 0.9997, 0.9996, 0.9996, 0.9996, 0.9995, 0.9995, 0.9994, 0.9994, 0.9994, 0.9993, + 0.9993, 0.9992, 0.9991, 0.9991, 0.9990, 0.9989, 0.9988, 0.9988, 0.9988, 0.9986, + 0.9985, 0.9984, 0.9983, 0.9982, 0.9980, 0.9979, 0.9977, 0.9976, 0.9974, 0.9971, + 0.9969, 0.9968, 0.9965, 0.9962, 0.9960, 0.9957, 0.9953, 0.9950, 0.9947, 0.9941, + 0.9937, 0.9933, 0.9928, 0.9922, 0.9917, 0.9911, 0.9904, 0.9897, 0.9890, 0.9882, + 0.9874, 0.9863, 0.9855, 0.9843, 0.9832, 0.9819, 0.9806, 0.9792, 0.9777, 0.9760, + 0.9743, 0.9724, 0.9704, 0.9683, 0.9659, 0.9634, 0.9609, 0.9581, 0.9550, 0.9516, + 0.9481, 0.9446, 0.9406, 0.9363, 0.9317, 0.9270, 0.9218, 0.9160, 0.9103, 0.9038, + 0.8972, 0.8898, 0.8822, 0.8739, 0.8647, 0.8554, 0.8457, 0.8357, 0.8231, 0.8115, + 0.7984, 0.7854, 0.7704, 0.7556, 0.7391, 0.7210, 0.7038, 0.6840, 0.6633, 0.6408, + 0.6174, 0.5939, 0.5678, 0.5410, 0.5137, 0.4836, 0.4524, 0.4193, 0.3850, 0.3482, + 0.3132, 0.2733, 0.2315, 0.1891, 0.1435, 0.0980, 0.0493, 0.0000, -0.0510, -0.1052, + -0.1593, -0.2177, -0.2759, -0.3374, -0.4005, -0.4599, -0.5266, -0.5935, -0.6626, -0.7328, + -0.8051, -0.8757, -0.9498, -1.0271, -1.1019, -1.1816, -1.2642, -1.3459, -1.4295, -1.5077, + -1.5958, -1.6818, -1.7647, -1.8548, -1.9387, -2.0295, -2.1152, -2.2154, -2.3011, -2.3904, + -2.4820, -2.5786, -2.6730, -2.7652, -2.8616, -2.9546, -3.0526, -3.1445, -3.2445, -3.3416, + -3.4357, -3.5325, -3.6324, -3.7313, -3.8225, -3.9209, -4.0248, -4.1278, -4.2261, -4.3193, + -4.4220, -4.5262, -4.6214, -4.7242, -4.8234, -4.9245, -5.0298, -5.1250, -5.2232, -5.3267, + -5.4332, -5.5342, -5.6431, -5.7270, -5.8401, -5.9350, -6.0407, -6.1418, -6.2363, -6.3384, + -6.4536, -6.5429, -6.6582, -6.7433, -6.8438, -6.9478, -7.0789, -7.1894, -7.2714, -7.3815, + -7.4810, -7.5575, -7.6852, -7.8071, -7.8580, -7.9724, -8.1000, -8.2207, -8.2867, -8.4017, + -8.5287, -8.6347, -8.7082, -8.8319, -8.9448, -9.0355, -9.1885, -9.2095, -9.2863, -9.4186, + -9.5064, -9.6386, -9.7207, -9.8286, -9.9453, -10.0701, -10.1735, -10.3001, -10.2858, -10.5427, + -10.5982, -10.7361, -10.7042, -10.9212, -11.0097, -11.0469, -11.1155, -11.2812, -11.3472, -11.4988, + -11.5327, -11.6692, -11.9376, -11.8606, -12.1372, -13.2539}, + {1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, + 0.9999, 0.9998, 0.9998, 0.9998, 0.9998, 0.9997, 0.9997, 0.9997, 0.9997, 0.9996, + 0.9996, 0.9995, 0.9995, 0.9994, 0.9994, 0.9993, 0.9992, 0.9991, 0.9991, 0.9989, + 0.9988, 0.9986, 0.9985, 0.9983, 0.9981, 0.9980, 0.9977, 0.9974, 0.9971, 0.9968, + 0.9965, 0.9962, 0.9956, 0.9950, 0.9948, 0.9941, 0.9933, 0.9926, 0.9919, 0.9910, + 0.9899, 0.9889, 0.9877, 0.9863, 0.9845, 0.9829, 0.9811, 0.9791, 0.9769, 0.9741, + 0.9716, 0.9684, 0.9645, 0.9611, 0.9563, 0.9519, 0.9463, 0.9406, 0.9344, 0.9272, + 0.9197, 0.9107, 0.9016, 0.8903, 0.8791, 0.8653, 0.8523, 0.8357, 0.8179, 0.7988, + 0.7779, 0.7562, 0.7318, 0.7024, 0.6753, 0.6435, 0.6089, 0.5700, 0.5296, 0.4860, + 0.4366, 0.3855, 0.3301, 0.2735, 0.2114, 0.1443, 0.0682, 0.0000, -0.0715, -0.1604, + -0.2478, -0.3377, -0.4287, -0.5277, -0.6291, -0.7384, -0.8457, -0.9559, -1.0742, -1.1913, + -1.3110, -1.4238, -1.5594, -1.6854, -1.8093, -1.9414, -2.0763, -2.2160, -2.3611, -2.4876, + -2.6374, -2.7710, -2.9225, -3.0591, -3.2077, -3.3452, -3.4916, -3.6316, -3.7735, -3.9296, + -4.0682, -4.2334, -4.3607, -4.5270, -4.6807, -4.8108, -4.9753, -5.1212, -5.2631, -5.4042, + -5.5510, -5.7227, -5.8794, -6.0244, -6.1677, -6.3271, -6.4862, -6.6130, -6.7449, -6.9250, + -7.1232, -7.1736, -7.3628, -7.5596, -7.6906, -7.8129, -7.9817, -8.1440, -8.3016, -8.4797, + -8.5734, -8.7692, -8.9198, -9.0610, -9.1746, -9.3536, -9.5939, -9.6957, -9.8475, -9.9639, + -10.1730, -10.2427, -10.4573, -10.5413, -10.7303, -10.9339, -11.0215, -11.2047, -11.2894, -11.4572, + -11.6256, -11.7794, -11.8801, -12.1717, -12.2354, -12.3686, -12.6195, -12.6527, -12.8247, -12.9560, + -13.3265, -13.1667, -13.4274, -13.6064, -13.5515, -13.9501, -13.9926, -14.4049, -14.1653, -14.4348, + -14.7983, -14.7807, -15.2349, -15.3536, -15.3026, -15.2739, -15.7170, -16.2161, -15.9185, -15.9490, + -16.6258, -16.5568, -16.4318, -16.7999, -16.4101, -17.6393, -17.7643, -17.2644, -17.5973, -17.0403, + -17.7039, -18.0073, -18.1840, -18.3848, -18.6286, -20.7063}, + {1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, + 0.9999, 0.9998, 0.9998, 0.9998, 0.9998, 0.9997, 0.9997, 0.9997, 0.9997, 0.9996, + 0.9996, 0.9995, 0.9995, 0.9994, 0.9994, 0.9993, 0.9992, 0.9991, 0.9991, 0.9989, + 0.9988, 0.9986, 0.9985, 0.9983, 0.9981, 0.9980, 0.9977, 0.9974, 0.9971, 0.9968, + 0.9965, 0.9962, 0.9956, 0.9950, 0.9948, 0.9941, 0.9933, 0.9926, 0.9919, 0.9910, + 0.9899, 0.9889, 0.9877, 0.9863, 0.9845, 0.9829, 0.9811, 0.9791, 0.9769, 0.9741, + 0.9716, 0.9684, 0.9645, 0.9611, 0.9563, 0.9519, 0.9463, 0.9406, 0.9344, 0.9272, + 0.9197, 0.9107, 0.9016, 0.8903, 0.8791, 0.8653, 0.8523, 0.8357, 0.8179, 0.7988, + 0.7779, 0.7562, 0.7318, 0.7024, 0.6753, 0.6435, 0.6089, 0.5700, 0.5296, 0.4860, + 0.4366, 0.3855, 0.3301, 0.2735, 0.2114, 0.1443, 0.0682, 0.0000, -0.0715, -0.1604, + -0.2478, -0.3377, -0.4287, -0.5277, -0.6291, -0.7384, -0.8457, -0.9559, -1.0742, -1.1913, + -1.3110, -1.4238, -1.5594, -1.6854, -1.8093, -1.9414, -2.0763, -2.2160, -2.3611, -2.4876, + -2.6374, -2.7710, -2.9225, -3.0591, -3.2077, -3.3452, -3.4916, -3.6316, -3.7735, -3.9296, + -4.0682, -4.2334, -4.3607, -4.5270, -4.6807, -4.8108, -4.9753, -5.1212, -5.2631, -5.4042, + -5.5510, -5.7227, -5.8794, -6.0244, -6.1677, -6.3271, -6.4862, -6.6130, -6.7449, -6.9250, + -7.1232, -7.1736, -7.3628, -7.5596, -7.6906, -7.8129, -7.9817, -8.1440, -8.3016, -8.4797, + -8.5734, -8.7692, -8.9198, -9.0610, -9.1746, -9.3536, -9.5939, -9.6957, -9.8475, -9.9639, + -10.1730, -10.2427, -10.4573, -11.7794, -11.8801, -12.1717, -12.2354, -12.3686, -12.6195, -12.6527, + -12.8247, -12.9560, -13.3265, -13.1667, -13.4274, -13.6064, -13.5515, -13.9501, -13.9926, -14.4049, + -14.1653, -14.4348, -14.7983, -14.7807, -15.2349, -15.3536, -15.3026, -15.2739, -15.7170, -16.2161, + -15.9185, -15.9490, -16.6258, -16.5568, -16.4318, -16.7999, -16.4101, -17.6393, -17.7643, -17.2644, + -17.5973, -17.0403, -17.7039, -18.0073, -18.1840, -18.3848, -18.6286, -20.7063, 1.43370769e-019, + 2.64031087e-006, 6.6908396e+031, 1.77537994e+028, 2.79322819e+020, 1.94326e-019, + 0.00019371575, 2.80722121e-041}}; diff --git a/lib/wsprd/mettab.c b/lib/wsprd/mettab.c index 21fde564..f188c0cc 100755 --- a/lib/wsprd/mettab.c +++ b/lib/wsprd/mettab.c @@ -1,76 +1,76 @@ -/* - This file is part of wsprd. - - File name: mettab.c - Description: Metric table for sequential Fano decoder. - - Copyright 2008-2015, Joseph Taylor, K1JT - License: GNU GPL v3 - - 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 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -int mettab[2][256]={ - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, - 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, - -1, -1, -1, -2, -2, -3, -4, -4, -5, -6, - -7, -7, -8, -9, -10, -11, -12, -12, -13, -14, - -15, -16, -17, -17, -18, -19, -20, -21, -22, -22, - -23, -24, -25, -26, -26, -27, -28, -29, -30, -30, - -31, -32, -33, -33, -34, -35, -36, -36, -37, -38, - -38, -39, -40, -41, -41, -42, -43, -43, -44, -45, - -45, -46, -47, -47, -48, -49, -49, -50, -51, -51, - -52, -53, -53, -54, -54, -55, -56, -56, -57, -57, - -58, -59, -59, -60, -60, -61, -62, -62, -62, -63, - -64, -64, -65, -65, -66, -67, -67, -67, -68, -69, - -69, -70, -70, -71, -72, -72, -72, -72, -73, -74, - -75, -75, -75, -77, -76, -76, -78, -78, -80, -81, - -80, -79, -83, -82, -81, -82, -82, -83, -84, -84, - -84, -87, -86, -87, -88,-105, -94,-105, -88, -87, - -86, -87, -84, -84, -84, -83, -82, -82, -81, -82, - -83, -79, -80, -81, -80, -78, -78, -76, -76, -77, - -75, -75, -75, -74, -73, -72, -72, -72, -72, -71, - -70, -70, -69, -69, -68, -67, -67, -67, -66, -65, - -65, -64, -64, -63, -62, -62, -62, -61, -60, -60, - -59, -59, -58, -57, -57, -56, -56, -55, -54, -54, - -53, -53, -52, -51, -51, -50, -49, -49, -48, -47, - -47, -46, -45, -45, -44, -43, -43, -42, -41, -41, - -40, -39, -38, -38, -37, -36, -36, -35, -34, -33, - -33, -32, -31, -30, -30, -29, -28, -27, -26, -26, - -25, -24, -23, -22, -22, -21, -20, -19, -18, -17, - -17, -16, -15, -14, -13, -12, -12, -11, -10, -9, - -8, -7, -7, -6, -5, -4, -4, -3, -2, -2, - -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, - 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5 }; +/* + This file is part of wsprd. + + File name: mettab.c + Description: Metric table for sequential Fano decoder. + + Copyright 2008-2015, Joseph Taylor, K1JT + License: GNU GPL v3 + + 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 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +int mettab[2][256]={ + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, + 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, + -1, -1, -1, -2, -2, -3, -4, -4, -5, -6, + -7, -7, -8, -9, -10, -11, -12, -12, -13, -14, + -15, -16, -17, -17, -18, -19, -20, -21, -22, -22, + -23, -24, -25, -26, -26, -27, -28, -29, -30, -30, + -31, -32, -33, -33, -34, -35, -36, -36, -37, -38, + -38, -39, -40, -41, -41, -42, -43, -43, -44, -45, + -45, -46, -47, -47, -48, -49, -49, -50, -51, -51, + -52, -53, -53, -54, -54, -55, -56, -56, -57, -57, + -58, -59, -59, -60, -60, -61, -62, -62, -62, -63, + -64, -64, -65, -65, -66, -67, -67, -67, -68, -69, + -69, -70, -70, -71, -72, -72, -72, -72, -73, -74, + -75, -75, -75, -77, -76, -76, -78, -78, -80, -81, + -80, -79, -83, -82, -81, -82, -82, -83, -84, -84, + -84, -87, -86, -87, -88,-105, -94,-105, -88, -87, + -86, -87, -84, -84, -84, -83, -82, -82, -81, -82, + -83, -79, -80, -81, -80, -78, -78, -76, -76, -77, + -75, -75, -75, -74, -73, -72, -72, -72, -72, -71, + -70, -70, -69, -69, -68, -67, -67, -67, -66, -65, + -65, -64, -64, -63, -62, -62, -62, -61, -60, -60, + -59, -59, -58, -57, -57, -56, -56, -55, -54, -54, + -53, -53, -52, -51, -51, -50, -49, -49, -48, -47, + -47, -46, -45, -45, -44, -43, -43, -42, -41, -41, + -40, -39, -38, -38, -37, -36, -36, -35, -34, -33, + -33, -32, -31, -30, -30, -29, -28, -27, -26, -26, + -25, -24, -23, -22, -22, -21, -20, -19, -18, -17, + -17, -16, -15, -14, -13, -12, -12, -11, -10, -9, + -8, -7, -7, -6, -5, -4, -4, -3, -2, -2, + -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5 }; diff --git a/lib/wsprd/nhash.c b/lib/wsprd/nhash.c index b7f935ec..5bf6ce04 100755 --- a/lib/wsprd/nhash.c +++ b/lib/wsprd/nhash.c @@ -1,383 +1,383 @@ -/* - This file is part of wsprd. - - File name: nhash.c - - *------------------------------------------------------------------------------ - * - * This file is part of the WSPR application, Weak Signal Propogation Reporter - * - * File Name: nhash.c - * Description: Functions to produce 32-bit hashes for hash table lookup - * - * Copyright (C) 2008-2014 Joseph Taylor, K1JT - * License: GNU GPL v3+ - * - * 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 3 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin - * Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Files: lookup3.c - * Copyright: Copyright (C) 2006 Bob Jenkins - * License: public-domain - * You may use this code any way you wish, private, educational, or commercial. - * It's free. - * - *------------------------------------------------------------------------------- -*/ - -/* -These are functions for producing 32-bit hashes for hash table lookup. -hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() -are externally useful functions. Routines to test the hash are included -if SELF_TEST is defined. You can use this free for any purpose. It's in -the public domain. It has no warranty. - -You probably want to use hashlittle(). hashlittle() and hashbig() -hash byte arrays. hashlittle() is is faster than hashbig() on -little-endian machines. Intel and AMD are little-endian machines. -On second thought, you probably want hashlittle2(), which is identical to -hashlittle() except it returns two 32-bit hashes for the price of one. -You could implement hashbig2() if you wanted but I haven't bothered here. - -If you want to find a hash of, say, exactly 7 integers, do - a = i1; b = i2; c = i3; - mix(a,b,c); - a += i4; b += i5; c += i6; - mix(a,b,c); - a += i7; - final(a,b,c); -then use c as the hash value. If you have a variable length array of -4-byte integers to hash, use hashword(). If you have a byte array (like -a character string), use hashlittle(). If you have several byte arrays, or -a mix of things, see the comments above hashlittle(). - -Why is this so big? I read 12 bytes at a time into 3 4-byte integers, -then mix those integers. This is fast (you can do a lot more thorough -mixing with 12*3 instructions on 3 integers than you can with 3 instructions -on 1 byte), but shoehorning those bytes into integers efficiently is messy. -*/ - -#define SELF_TEST 1 - -#include /* defines printf for tests */ -#include /* defines time_t for timings in the test */ -#include "nhash.h" -//#include /* attempt to define endianness */ -//#ifdef linux -//# include /* attempt to define endianness */ -//#endif - -#define HASH_LITTLE_ENDIAN 1 - -#define hashsize(n) ((uint32_t)1<<(n)) -#define hashmask(n) (hashsize(n)-1) -#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) - -/* -------------------------------------------------------------------------------- -mix -- mix 3 32-bit values reversibly. - -This is reversible, so any information in (a,b,c) before mix() is -still in (a,b,c) after mix(). - -If four pairs of (a,b,c) inputs are run through mix(), or through -mix() in reverse, there are at least 32 bits of the output that -are sometimes the same for one pair and different for another pair. -This was tested for: -* pairs that differed by one bit, by two bits, in any combination - of top bits of (a,b,c), or in any combination of bottom bits of - (a,b,c). -* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed - the output delta to a Gray code (a^(a>>1)) so a string of 1's (as - is commonly produced by subtraction) look like a single 1-bit - difference. -* the base values were pseudorandom, all zero but one bit set, or - all zero plus a counter that starts at zero. - -Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that -satisfy this are - 4 6 8 16 19 4 - 9 15 3 18 27 15 - 14 9 3 7 17 3 -Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing -for "differ" defined as + with a one-bit base and a two-bit delta. I -used http://burtleburtle.net/bob/hash/avalanche.html to choose -the operations, constants, and arrangements of the variables. - -This does not achieve avalanche. There are input bits of (a,b,c) -that fail to affect some output bits of (a,b,c), especially of a. The -most thoroughly mixed value is c, but it doesn't really even achieve -avalanche in c. - -This allows some parallelism. Read-after-writes are good at doubling -the number of bits affected, so the goal of mixing pulls in the opposite -direction as the goal of parallelism. I did what I could. Rotates -seem to cost as much as shifts on every machine I could lay my hands -on, and rotates are much kinder to the top and bottom bits, so I used -rotates. -------------------------------------------------------------------------------- -*/ -#define mix(a,b,c) \ -{ \ - a -= c; a ^= rot(c, 4); c += b; \ - b -= a; b ^= rot(a, 6); a += c; \ - c -= b; c ^= rot(b, 8); b += a; \ - a -= c; a ^= rot(c,16); c += b; \ - b -= a; b ^= rot(a,19); a += c; \ - c -= b; c ^= rot(b, 4); b += a; \ -} - -/* -------------------------------------------------------------------------------- -final -- final mixing of 3 32-bit values (a,b,c) into c - -Pairs of (a,b,c) values differing in only a few bits will usually -produce values of c that look totally different. This was tested for -* pairs that differed by one bit, by two bits, in any combination - of top bits of (a,b,c), or in any combination of bottom bits of - (a,b,c). -* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed - the output delta to a Gray code (a^(a>>1)) so a string of 1's (as - is commonly produced by subtraction) look like a single 1-bit - difference. -* the base values were pseudorandom, all zero but one bit set, or - all zero plus a counter that starts at zero. - -These constants passed: - 14 11 25 16 4 14 24 - 12 14 25 16 4 14 24 -and these came close: - 4 8 15 26 3 22 24 - 10 8 15 26 3 22 24 - 11 8 15 26 3 22 24 -------------------------------------------------------------------------------- -*/ -#define final(a,b,c) \ -{ \ - c ^= b; c -= rot(b,14); \ - a ^= c; a -= rot(c,11); \ - b ^= a; b -= rot(a,25); \ - c ^= b; c -= rot(b,16); \ - a ^= c; a -= rot(c,4); \ - b ^= a; b -= rot(a,14); \ - c ^= b; c -= rot(b,24); \ -} - -/* -------------------------------------------------------------------------------- -hashlittle() -- hash a variable-length key into a 32-bit value - k : the key (the unaligned variable-length array of bytes) - length : the length of the key, counting by bytes - initval : can be any 4-byte value -Returns a 32-bit value. Every bit of the key affects every bit of -the return value. Two keys differing by one or two bits will have -totally different hash values. - -The best hash table sizes are powers of 2. There is no need to do -mod a prime (mod is sooo slow!). If you need less than 32 bits, -use a bitmask. For example, if you need only 10 bits, do - h = (h & hashmask(10)); -In which case, the hash table should have hashsize(10) elements. - -If you are hashing n strings (uint8_t **)k, do it like this: - for (i=0, h=0; i 12) - { - a += k[0]; - b += k[1]; - c += k[2]; - mix(a,b,c); - length -= 12; - k += 3; - } - - /*----------------------------- handle the last (probably partial) block */ - /* - * "k[2]&0xffffff" actually reads beyond the end of the string, but - * then masks off the part it's not allowed to read. Because the - * string is aligned, the masked-off tail is in the same word as the - * rest of the string. Every machine with memory protection I've seen - * does it on word boundaries, so is OK with this. But VALGRIND will - * still catch it and complain. The masking trick does make the hash - * noticably faster for short strings (like English words). - */ -#ifndef VALGRIND - - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; - case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; - case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=k[1]&0xffffff; a+=k[0]; break; - case 6 : b+=k[1]&0xffff; a+=k[0]; break; - case 5 : b+=k[1]&0xff; a+=k[0]; break; - case 4 : a+=k[0]; break; - case 3 : a+=k[0]&0xffffff; break; - case 2 : a+=k[0]&0xffff; break; - case 1 : a+=k[0]&0xff; break; - case 0 : return c; /* zero length strings require no mixing */ - } - -#else /* make valgrind happy */ - - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]; break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ - case 1 : a+=k8[0]; break; - case 0 : return c; - } - -#endif /* !valgrind */ - - } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { - const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ - const uint8_t *k8; - - /*--------------- all but last block: aligned reads and different mixing */ - while (length > 12) - { - a += k[0] + (((uint32_t)k[1])<<16); - b += k[2] + (((uint32_t)k[3])<<16); - c += k[4] + (((uint32_t)k[5])<<16); - mix(a,b,c); - length -= 12; - k += 6; - } - - /*----------------------------- handle the last (probably partial) block */ - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[4]+(((uint32_t)k[5])<<16); - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=k[4]; - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=k[2]; - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=k[0]; - break; - case 1 : a+=k8[0]; - break; - case 0 : return c; /* zero length requires no mixing */ - } - - } else { /* need to read the key one byte at a time */ - const uint8_t *k = (const uint8_t *)key; - - /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ - while (length > 12) - { - a += k[0]; - a += ((uint32_t)k[1])<<8; - a += ((uint32_t)k[2])<<16; - a += ((uint32_t)k[3])<<24; - b += k[4]; - b += ((uint32_t)k[5])<<8; - b += ((uint32_t)k[6])<<16; - b += ((uint32_t)k[7])<<24; - c += k[8]; - c += ((uint32_t)k[9])<<8; - c += ((uint32_t)k[10])<<16; - c += ((uint32_t)k[11])<<24; - mix(a,b,c); - length -= 12; - k += 12; - } - - /*-------------------------------- last block: affect all 32 bits of (c) */ - switch(length) /* all the case statements fall through */ - { - case 12: c+=((uint32_t)k[11])<<24; - /* fall through */ - case 11: c+=((uint32_t)k[10])<<16; - /* fall through */ - case 10: c+=((uint32_t)k[9])<<8; - /* fall through */ - case 9 : c+=k[8]; - /* fall through */ - case 8 : b+=((uint32_t)k[7])<<24; - /* fall through */ - case 7 : b+=((uint32_t)k[6])<<16; - /* fall through */ - case 6 : b+=((uint32_t)k[5])<<8; - /* fall through */ - case 5 : b+=k[4]; - /* fall through */ - case 4 : a+=((uint32_t)k[3])<<24; - /* fall through */ - case 3 : a+=((uint32_t)k[2])<<16; - /* fall through */ - case 2 : a+=((uint32_t)k[1])<<8; - /* fall through */ - case 1 : a+=k[0]; - break; - case 0 : return c; - } - } - - final(a,b,c); - c=(32767&c); - - return c; -} +/* + This file is part of wsprd. + + File name: nhash.c + + *------------------------------------------------------------------------------ + * + * This file is part of the WSPR application, Weak Signal Propogation Reporter + * + * File Name: nhash.c + * Description: Functions to produce 32-bit hashes for hash table lookup + * + * Copyright (C) 2008-2014 Joseph Taylor, K1JT + * License: GNU GPL v3+ + * + * 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 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Files: lookup3.c + * Copyright: Copyright (C) 2006 Bob Jenkins + * License: public-domain + * You may use this code any way you wish, private, educational, or commercial. + * It's free. + * + *------------------------------------------------------------------------------- +*/ + +/* +These are functions for producing 32-bit hashes for hash table lookup. +hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() +are externally useful functions. Routines to test the hash are included +if SELF_TEST is defined. You can use this free for any purpose. It's in +the public domain. It has no warranty. + +You probably want to use hashlittle(). hashlittle() and hashbig() +hash byte arrays. hashlittle() is is faster than hashbig() on +little-endian machines. Intel and AMD are little-endian machines. +On second thought, you probably want hashlittle2(), which is identical to +hashlittle() except it returns two 32-bit hashes for the price of one. +You could implement hashbig2() if you wanted but I haven't bothered here. + +If you want to find a hash of, say, exactly 7 integers, do + a = i1; b = i2; c = i3; + mix(a,b,c); + a += i4; b += i5; c += i6; + mix(a,b,c); + a += i7; + final(a,b,c); +then use c as the hash value. If you have a variable length array of +4-byte integers to hash, use hashword(). If you have a byte array (like +a character string), use hashlittle(). If you have several byte arrays, or +a mix of things, see the comments above hashlittle(). + +Why is this so big? I read 12 bytes at a time into 3 4-byte integers, +then mix those integers. This is fast (you can do a lot more thorough +mixing with 12*3 instructions on 3 integers than you can with 3 instructions +on 1 byte), but shoehorning those bytes into integers efficiently is messy. +*/ + +#define SELF_TEST 1 + +#include /* defines printf for tests */ +#include /* defines time_t for timings in the test */ +#include "nhash.h" +//#include /* attempt to define endianness */ +//#ifdef linux +//# include /* attempt to define endianness */ +//#endif + +#define HASH_LITTLE_ENDIAN 1 + +#define hashsize(n) ((uint32_t)1<<(n)) +#define hashmask(n) (hashsize(n)-1) +#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) + +/* +------------------------------------------------------------------------------- +mix -- mix 3 32-bit values reversibly. + +This is reversible, so any information in (a,b,c) before mix() is +still in (a,b,c) after mix(). + +If four pairs of (a,b,c) inputs are run through mix(), or through +mix() in reverse, there are at least 32 bits of the output that +are sometimes the same for one pair and different for another pair. +This was tested for: +* pairs that differed by one bit, by two bits, in any combination + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). +* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. +* the base values were pseudorandom, all zero but one bit set, or + all zero plus a counter that starts at zero. + +Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that +satisfy this are + 4 6 8 16 19 4 + 9 15 3 18 27 15 + 14 9 3 7 17 3 +Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing +for "differ" defined as + with a one-bit base and a two-bit delta. I +used http://burtleburtle.net/bob/hash/avalanche.html to choose +the operations, constants, and arrangements of the variables. + +This does not achieve avalanche. There are input bits of (a,b,c) +that fail to affect some output bits of (a,b,c), especially of a. The +most thoroughly mixed value is c, but it doesn't really even achieve +avalanche in c. + +This allows some parallelism. Read-after-writes are good at doubling +the number of bits affected, so the goal of mixing pulls in the opposite +direction as the goal of parallelism. I did what I could. Rotates +seem to cost as much as shifts on every machine I could lay my hands +on, and rotates are much kinder to the top and bottom bits, so I used +rotates. +------------------------------------------------------------------------------- +*/ +#define mix(a,b,c) \ +{ \ + a -= c; a ^= rot(c, 4); c += b; \ + b -= a; b ^= rot(a, 6); a += c; \ + c -= b; c ^= rot(b, 8); b += a; \ + a -= c; a ^= rot(c,16); c += b; \ + b -= a; b ^= rot(a,19); a += c; \ + c -= b; c ^= rot(b, 4); b += a; \ +} + +/* +------------------------------------------------------------------------------- +final -- final mixing of 3 32-bit values (a,b,c) into c + +Pairs of (a,b,c) values differing in only a few bits will usually +produce values of c that look totally different. This was tested for +* pairs that differed by one bit, by two bits, in any combination + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). +* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. +* the base values were pseudorandom, all zero but one bit set, or + all zero plus a counter that starts at zero. + +These constants passed: + 14 11 25 16 4 14 24 + 12 14 25 16 4 14 24 +and these came close: + 4 8 15 26 3 22 24 + 10 8 15 26 3 22 24 + 11 8 15 26 3 22 24 +------------------------------------------------------------------------------- +*/ +#define final(a,b,c) \ +{ \ + c ^= b; c -= rot(b,14); \ + a ^= c; a -= rot(c,11); \ + b ^= a; b -= rot(a,25); \ + c ^= b; c -= rot(b,16); \ + a ^= c; a -= rot(c,4); \ + b ^= a; b -= rot(a,14); \ + c ^= b; c -= rot(b,24); \ +} + +/* +------------------------------------------------------------------------------- +hashlittle() -- hash a variable-length key into a 32-bit value + k : the key (the unaligned variable-length array of bytes) + length : the length of the key, counting by bytes + initval : can be any 4-byte value +Returns a 32-bit value. Every bit of the key affects every bit of +the return value. Two keys differing by one or two bits will have +totally different hash values. + +The best hash table sizes are powers of 2. There is no need to do +mod a prime (mod is sooo slow!). If you need less than 32 bits, +use a bitmask. For example, if you need only 10 bits, do + h = (h & hashmask(10)); +In which case, the hash table should have hashsize(10) elements. + +If you are hashing n strings (uint8_t **)k, do it like this: + for (i=0, h=0; i 12) + { + a += k[0]; + b += k[1]; + c += k[2]; + mix(a,b,c); + length -= 12; + k += 3; + } + + /*----------------------------- handle the last (probably partial) block */ + /* + * "k[2]&0xffffff" actually reads beyond the end of the string, but + * then masks off the part it's not allowed to read. Because the + * string is aligned, the masked-off tail is in the same word as the + * rest of the string. Every machine with memory protection I've seen + * does it on word boundaries, so is OK with this. But VALGRIND will + * still catch it and complain. The masking trick does make the hash + * noticably faster for short strings (like English words). + */ +#ifndef VALGRIND + + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; + case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; + case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=k[1]&0xffffff; a+=k[0]; break; + case 6 : b+=k[1]&0xffff; a+=k[0]; break; + case 5 : b+=k[1]&0xff; a+=k[0]; break; + case 4 : a+=k[0]; break; + case 3 : a+=k[0]&0xffffff; break; + case 2 : a+=k[0]&0xffff; break; + case 1 : a+=k[0]&0xff; break; + case 0 : return c; /* zero length strings require no mixing */ + } + +#else /* make valgrind happy */ + + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]; break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ + case 1 : a+=k8[0]; break; + case 0 : return c; + } + +#endif /* !valgrind */ + + } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { + const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ + const uint8_t *k8; + + /*--------------- all but last block: aligned reads and different mixing */ + while (length > 12) + { + a += k[0] + (((uint32_t)k[1])<<16); + b += k[2] + (((uint32_t)k[3])<<16); + c += k[4] + (((uint32_t)k[5])<<16); + mix(a,b,c); + length -= 12; + k += 6; + } + + /*----------------------------- handle the last (probably partial) block */ + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[4]+(((uint32_t)k[5])<<16); + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=k[4]; + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=k[2]; + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=k[0]; + break; + case 1 : a+=k8[0]; + break; + case 0 : return c; /* zero length requires no mixing */ + } + + } else { /* need to read the key one byte at a time */ + const uint8_t *k = (const uint8_t *)key; + + /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + a += ((uint32_t)k[1])<<8; + a += ((uint32_t)k[2])<<16; + a += ((uint32_t)k[3])<<24; + b += k[4]; + b += ((uint32_t)k[5])<<8; + b += ((uint32_t)k[6])<<16; + b += ((uint32_t)k[7])<<24; + c += k[8]; + c += ((uint32_t)k[9])<<8; + c += ((uint32_t)k[10])<<16; + c += ((uint32_t)k[11])<<24; + mix(a,b,c); + length -= 12; + k += 12; + } + + /*-------------------------------- last block: affect all 32 bits of (c) */ + switch(length) /* all the case statements fall through */ + { + case 12: c+=((uint32_t)k[11])<<24; + /* fall through */ + case 11: c+=((uint32_t)k[10])<<16; + /* fall through */ + case 10: c+=((uint32_t)k[9])<<8; + /* fall through */ + case 9 : c+=k[8]; + /* fall through */ + case 8 : b+=((uint32_t)k[7])<<24; + /* fall through */ + case 7 : b+=((uint32_t)k[6])<<16; + /* fall through */ + case 6 : b+=((uint32_t)k[5])<<8; + /* fall through */ + case 5 : b+=k[4]; + /* fall through */ + case 4 : a+=((uint32_t)k[3])<<24; + /* fall through */ + case 3 : a+=((uint32_t)k[2])<<16; + /* fall through */ + case 2 : a+=((uint32_t)k[1])<<8; + /* fall through */ + case 1 : a+=k[0]; + break; + case 0 : return c; + } + } + + final(a,b,c); + c=(32767&c); + + return c; +} diff --git a/lib/wsprd/nhash.h b/lib/wsprd/nhash.h index 9f9b6a67..a111916b 100755 --- a/lib/wsprd/nhash.h +++ b/lib/wsprd/nhash.h @@ -1,21 +1,21 @@ -#ifndef NHASH_H_ -#define NHASH_H_ - -#ifdef Win32 -#include "win_stdint.h" /* defines uint32_t etc */ -#else -#include -#include /* defines uint32_t etc */ -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -uint32_t nhash( const void * key, size_t length, uint32_t initval); - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef NHASH_H_ +#define NHASH_H_ + +#ifdef Win32 +#include "win_stdint.h" /* defines uint32_t etc */ +#else +#include +#include /* defines uint32_t etc */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t nhash( const void * key, size_t length, uint32_t initval); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wsprd/osdwspr.f90 b/lib/wsprd/osdwspr.f90 index 41965a58..2a2d712d 100755 --- a/lib/wsprd/osdwspr.f90 +++ b/lib/wsprd/osdwspr.f90 @@ -1,361 +1,361 @@ -subroutine osdwspr(ss,apmask,ndeep,cw,nhardmin,dmin) -! -use iso_c_binding -parameter (N=162, K=50, L=32) - -!integer*1 p1(L),p2(L),p3(L),p4(L) -integer*1 gg(64) - -real ss(N) -integer*1 apmask(N),apmaskr(N) -integer*1 gen(K,N) -integer*1 genmrb(K,N),g2(N,K) -integer*1 temp(K),m0(K),me(K),mi(K),misub(K),e2sub(N-K),e2(N-K),ui(N-K) -integer*1 r2pat(N-K) -integer indices(N),nxor(N) -integer*1 cw(N),ce(N),c0(N),hdec(N) -integer indx(N),ndeep,nhardmin -real rx(N),absrx(N),dmin -logical first,reset -data first/.true./ -data gg/1,1,0,1,0,1,0,0,1,0,0,0,1,1,0,0,1,0,1,0,0,1,0,1,1,1,0,1,1,0,0,0, & - 0,1,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,0,1,0,1,1,1,1,1,1/ - -save first,gen - -if( first ) then ! fill the generator matrix - gen=0 - gen(1,1:2*L)=gg(1:2*L) - do i=2,K - gen(i,:)=cshift(gen(i-1,:),-2) - enddo - first=.false. -endif - -rx=ss/127.0 -apmaskr=apmask - -! Hard decisions on the received word. -hdec=0 -where(rx .ge. 0) hdec=1 - -! Use magnitude of received symbols as a measure of reliability. -absrx=abs(rx) -call indexx(absrx,N,indx) - -! Re-order the columns of the generator matrix in order of decreasing reliability. -do i=1,N - genmrb(1:K,i)=gen(1:K,indx(N+1-i)) - indices(i)=indx(N+1-i) -enddo - -! Do gaussian elimination to create a generator matrix with the most reliable -! received bits in positions 1:K in order of decreasing reliability (more or less). -do id=1,K ! diagonal element indices - do icol=id,K+20 ! The 20 is ad hoc - beware - iflag=0 - if( genmrb(id,icol) .eq. 1 ) then - iflag=1 - if( icol .ne. id ) then ! reorder column - temp(1:K)=genmrb(1:K,id) - genmrb(1:K,id)=genmrb(1:K,icol) - genmrb(1:K,icol)=temp(1:K) - itmp=indices(id) - indices(id)=indices(icol) - indices(icol)=itmp - endif - do ii=1,K - if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then - genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) - endif - enddo - exit - endif - enddo -enddo - -g2=transpose(genmrb) - -! The hard decisions for the K MRB bits define the order 0 message, m0. -! Encode m0 using the modified generator matrix to find the "order 0" codeword. -! Flip various combinations of bits in m0 and re-encode to generate a list of -! codewords. Return the member of the list that has the smallest Euclidean -! distance to the received word. - -hdec=hdec(indices) ! hard decisions from received symbols -m0=hdec(1:K) ! zero'th order message -absrx=absrx(indices) -rx=rx(indices) -apmaskr=apmaskr(indices) - -call mrbencode(m0,c0,g2,N,K) - -nxor=ieor(c0,hdec) -nhardmin=sum(nxor) -dmin=sum(nxor*absrx) -cw=c0 -ntotal=0 -nrejected=0 - -if(ndeep.le.0) goto 998 ! norder=0 -if(ndeep.gt.5) ndeep=5 -if( ndeep.eq. 1) then - nord=1 - npre1=0 - npre2=0 - nt=66 - ntheta=16 -elseif(ndeep.eq.2) then - nord=1 - npre1=1 - npre2=0 - nt=66 - ntheta=22 - ntau = 16 -elseif(ndeep.eq.3) then - nord=1 - npre1=1 - npre2=1 - nt=66 - ntheta=22 - ntau=16 -elseif(ndeep.eq.4) then - nord=2 - npre1=1 - npre2=1 - nt=66 - ntheta=22 - ntau=16 -elseif(ndeep.eq.5) then - nord=3 - npre1=1 - npre2=1 - nt=66 - ntheta=22 - ntau=16 -endif - -do iorder=1,nord - misub(1:K-iorder)=0 - misub(K-iorder+1:K)=1 - iflag=K-iorder+1 - do while(iflag .ge.0) - if(iorder.eq.nord .and. npre1.eq.0) then - iend=iflag - else - iend=1 - endif - d1=0. - do n1=iflag,iend,-1 - mi=misub - mi(n1)=1 - if(any(iand(apmaskr(1:K),mi).eq.1)) cycle - ntotal=ntotal+1 - me=ieor(m0,mi) - if(n1.eq.iflag) then - call mrbencode(me,ce,g2,N,K) - e2sub=ieor(ce(K+1:N),hdec(K+1:N)) - e2=e2sub - nd1Kpt=sum(e2sub(1:nt))+1 - d1=sum(ieor(me(1:K),hdec(1:K))*absrx(1:K)) - else - e2=ieor(e2sub,g2(K+1:N,n1)) - nd1Kpt=sum(e2(1:nt))+2 - endif - if(nd1Kpt .le. ntheta) then - call mrbencode(me,ce,g2,N,K) - nxor=ieor(ce,hdec) - if(n1.eq.iflag) then - dd=d1+sum(e2sub*absrx(K+1:N)) - else - dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(K+1:N)) - endif - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - nd1Kptbest=nd1Kpt - endif - else - nrejected=nrejected+1 - endif - enddo -! Get the next test error pattern, iflag will go negative -! when the last pattern with weight iorder has been generated. - call nextpat(misub,k,iorder,iflag) - enddo -enddo - -if(npre2.eq.1) then - reset=.true. - ntotal=0 - do i1=K,1,-1 - do i2=i1-1,1,-1 - ntotal=ntotal+1 - mi(1:ntau)=ieor(g2(K+1:K+ntau,i1),g2(K+1:K+ntau,i2)) - call boxit(reset,mi(1:ntau),ntau,ntotal,i1,i2) - enddo - enddo - - ncount2=0 - ntotal2=0 - reset=.true. -! Now run through again and do the second pre-processing rule - misub(1:K-nord)=0 - misub(K-nord+1:K)=1 - iflag=K-nord+1 - do while(iflag .ge.0) - me=ieor(m0,misub) - call mrbencode(me,ce,g2,N,K) - e2sub=ieor(ce(K+1:N),hdec(K+1:N)) - do i2=0,ntau - ntotal2=ntotal2+1 - ui=0 - if(i2.gt.0) ui(i2)=1 - r2pat=ieor(e2sub,ui) -778 continue - call fetchit(reset,r2pat(1:ntau),ntau,in1,in2) - if(in1.gt.0.and.in2.gt.0) then - ncount2=ncount2+1 - mi=misub - mi(in1)=1 - mi(in2)=1 - if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:K),mi).eq.1)) cycle - me=ieor(m0,mi) - call mrbencode(me,ce,g2,N,K) - nxor=ieor(ce,hdec) - dd=sum(nxor*absrx) - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - endif - goto 778 - endif - enddo - call nextpat(misub,K,nord,iflag) - enddo -endif - -998 continue -! Re-order the codeword to as-received order. -cw(indices)=cw -hdec(indices)=hdec -return -end subroutine osdwspr - -subroutine mrbencode(me,codeword,g2,N,K) -integer*1 me(K),codeword(N),g2(N,K) -! fast encoding for low-weight test patterns - codeword=0 - do i=1,K - if( me(i) .eq. 1 ) then - codeword=ieor(codeword,g2(1:N,i)) - endif - enddo -return -end subroutine mrbencode - -subroutine nextpat(mi,k,iorder,iflag) - integer*1 mi(k),ms(k) -! generate the next test error pattern - ind=-1 - do i=1,k-1 - if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i - enddo - if( ind .lt. 0 ) then ! no more patterns of this order - iflag=ind - return - endif - ms=0 - ms(1:ind-1)=mi(1:ind-1) - ms(ind)=1 - ms(ind+1)=0 - if( ind+1 .lt. k ) then - nz=iorder-sum(ms) - ms(k-nz+1:k)=1 - endif - mi=ms - do i=1,k ! iflag will point to the lowest-index 1 in mi - if(mi(i).eq.1) then - iflag=i - exit - endif - enddo - return -end subroutine nextpat - -subroutine boxit(reset,e2,ntau,npindex,i1,i2) - integer*1 e2(1:ntau) - integer indexes(4000,2),fp(0:525000),np(4000) - logical reset - common/boxes/indexes,fp,np - - if(reset) then - patterns=-1 - fp=-1 - np=-1 - sc=-1 - indexes=-1 - reset=.false. - endif - - indexes(npindex,1)=i1 - indexes(npindex,2)=i2 - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - - ip=fp(ipat) ! see what's currently stored in fp(ipat) - if(ip.eq.-1) then - fp(ipat)=npindex - else - do while (np(ip).ne.-1) - ip=np(ip) - enddo - np(ip)=npindex - endif - return -end subroutine boxit - -subroutine fetchit(reset,e2,ntau,i1,i2) - integer indexes(4000,2),fp(0:525000),np(4000) - integer lastpat - integer*1 e2(ntau) - logical reset - common/boxes/indexes,fp,np - save lastpat,inext - - if(reset) then - lastpat=-1 - reset=.false. - endif - - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - index=fp(ipat) - - if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices - i1=indexes(index,1) - i2=indexes(index,2) - inext=np(index) - elseif(lastpat.eq.ipat .and. inext.gt.0) then - i1=indexes(inext,1) - i2=indexes(inext,2) - inext=np(inext) - else - i1=-1 - i2=-1 - inext=-1 - endif - lastpat=ipat - return -end subroutine fetchit - +subroutine osdwspr(ss,apmask,ndeep,cw,nhardmin,dmin) +! +use iso_c_binding +parameter (N=162, K=50, L=32) + +!integer*1 p1(L),p2(L),p3(L),p4(L) +integer*1 gg(64) + +real ss(N) +integer*1 apmask(N),apmaskr(N) +integer*1 gen(K,N) +integer*1 genmrb(K,N),g2(N,K) +integer*1 temp(K),m0(K),me(K),mi(K),misub(K),e2sub(N-K),e2(N-K),ui(N-K) +integer*1 r2pat(N-K) +integer indices(N),nxor(N) +integer*1 cw(N),ce(N),c0(N),hdec(N) +integer indx(N),ndeep,nhardmin +real rx(N),absrx(N),dmin +logical first,reset +data first/.true./ +data gg/1,1,0,1,0,1,0,0,1,0,0,0,1,1,0,0,1,0,1,0,0,1,0,1,1,1,0,1,1,0,0,0, & + 0,1,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,0,1,0,1,1,1,1,1,1/ + +save first,gen + +if( first ) then ! fill the generator matrix + gen=0 + gen(1,1:2*L)=gg(1:2*L) + do i=2,K + gen(i,:)=cshift(gen(i-1,:),-2) + enddo + first=.false. +endif + +rx=ss/127.0 +apmaskr=apmask + +! Hard decisions on the received word. +hdec=0 +where(rx .ge. 0) hdec=1 + +! Use magnitude of received symbols as a measure of reliability. +absrx=abs(rx) +call indexx(absrx,N,indx) + +! Re-order the columns of the generator matrix in order of decreasing reliability. +do i=1,N + genmrb(1:K,i)=gen(1:K,indx(N+1-i)) + indices(i)=indx(N+1-i) +enddo + +! Do gaussian elimination to create a generator matrix with the most reliable +! received bits in positions 1:K in order of decreasing reliability (more or less). +do id=1,K ! diagonal element indices + do icol=id,K+20 ! The 20 is ad hoc - beware + iflag=0 + if( genmrb(id,icol) .eq. 1 ) then + iflag=1 + if( icol .ne. id ) then ! reorder column + temp(1:K)=genmrb(1:K,id) + genmrb(1:K,id)=genmrb(1:K,icol) + genmrb(1:K,icol)=temp(1:K) + itmp=indices(id) + indices(id)=indices(icol) + indices(icol)=itmp + endif + do ii=1,K + if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then + genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) + endif + enddo + exit + endif + enddo +enddo + +g2=transpose(genmrb) + +! The hard decisions for the K MRB bits define the order 0 message, m0. +! Encode m0 using the modified generator matrix to find the "order 0" codeword. +! Flip various combinations of bits in m0 and re-encode to generate a list of +! codewords. Return the member of the list that has the smallest Euclidean +! distance to the received word. + +hdec=hdec(indices) ! hard decisions from received symbols +m0=hdec(1:K) ! zero'th order message +absrx=absrx(indices) +rx=rx(indices) +apmaskr=apmaskr(indices) + +call mrbencode(m0,c0,g2,N,K) + +nxor=ieor(c0,hdec) +nhardmin=sum(nxor) +dmin=sum(nxor*absrx) +cw=c0 +ntotal=0 +nrejected=0 + +if(ndeep.le.0) goto 998 ! norder=0 +if(ndeep.gt.5) ndeep=5 +if( ndeep.eq. 1) then + nord=1 + npre1=0 + npre2=0 + nt=66 + ntheta=16 +elseif(ndeep.eq.2) then + nord=1 + npre1=1 + npre2=0 + nt=66 + ntheta=22 + ntau = 16 +elseif(ndeep.eq.3) then + nord=1 + npre1=1 + npre2=1 + nt=66 + ntheta=22 + ntau=16 +elseif(ndeep.eq.4) then + nord=2 + npre1=1 + npre2=1 + nt=66 + ntheta=22 + ntau=16 +elseif(ndeep.eq.5) then + nord=3 + npre1=1 + npre2=1 + nt=66 + ntheta=22 + ntau=16 +endif + +do iorder=1,nord + misub(1:K-iorder)=0 + misub(K-iorder+1:K)=1 + iflag=K-iorder+1 + do while(iflag .ge.0) + if(iorder.eq.nord .and. npre1.eq.0) then + iend=iflag + else + iend=1 + endif + d1=0. + do n1=iflag,iend,-1 + mi=misub + mi(n1)=1 + if(any(iand(apmaskr(1:K),mi).eq.1)) cycle + ntotal=ntotal+1 + me=ieor(m0,mi) + if(n1.eq.iflag) then + call mrbencode(me,ce,g2,N,K) + e2sub=ieor(ce(K+1:N),hdec(K+1:N)) + e2=e2sub + nd1Kpt=sum(e2sub(1:nt))+1 + d1=sum(ieor(me(1:K),hdec(1:K))*absrx(1:K)) + else + e2=ieor(e2sub,g2(K+1:N,n1)) + nd1Kpt=sum(e2(1:nt))+2 + endif + if(nd1Kpt .le. ntheta) then + call mrbencode(me,ce,g2,N,K) + nxor=ieor(ce,hdec) + if(n1.eq.iflag) then + dd=d1+sum(e2sub*absrx(K+1:N)) + else + dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(K+1:N)) + endif + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + nd1Kptbest=nd1Kpt + endif + else + nrejected=nrejected+1 + endif + enddo +! Get the next test error pattern, iflag will go negative +! when the last pattern with weight iorder has been generated. + call nextpat(misub,k,iorder,iflag) + enddo +enddo + +if(npre2.eq.1) then + reset=.true. + ntotal=0 + do i1=K,1,-1 + do i2=i1-1,1,-1 + ntotal=ntotal+1 + mi(1:ntau)=ieor(g2(K+1:K+ntau,i1),g2(K+1:K+ntau,i2)) + call boxit(reset,mi(1:ntau),ntau,ntotal,i1,i2) + enddo + enddo + + ncount2=0 + ntotal2=0 + reset=.true. +! Now run through again and do the second pre-processing rule + misub(1:K-nord)=0 + misub(K-nord+1:K)=1 + iflag=K-nord+1 + do while(iflag .ge.0) + me=ieor(m0,misub) + call mrbencode(me,ce,g2,N,K) + e2sub=ieor(ce(K+1:N),hdec(K+1:N)) + do i2=0,ntau + ntotal2=ntotal2+1 + ui=0 + if(i2.gt.0) ui(i2)=1 + r2pat=ieor(e2sub,ui) +778 continue + call fetchit(reset,r2pat(1:ntau),ntau,in1,in2) + if(in1.gt.0.and.in2.gt.0) then + ncount2=ncount2+1 + mi=misub + mi(in1)=1 + mi(in2)=1 + if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:K),mi).eq.1)) cycle + me=ieor(m0,mi) + call mrbencode(me,ce,g2,N,K) + nxor=ieor(ce,hdec) + dd=sum(nxor*absrx) + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + endif + goto 778 + endif + enddo + call nextpat(misub,K,nord,iflag) + enddo +endif + +998 continue +! Re-order the codeword to as-received order. +cw(indices)=cw +hdec(indices)=hdec +return +end subroutine osdwspr + +subroutine mrbencode(me,codeword,g2,N,K) +integer*1 me(K),codeword(N),g2(N,K) +! fast encoding for low-weight test patterns + codeword=0 + do i=1,K + if( me(i) .eq. 1 ) then + codeword=ieor(codeword,g2(1:N,i)) + endif + enddo +return +end subroutine mrbencode + +subroutine nextpat(mi,k,iorder,iflag) + integer*1 mi(k),ms(k) +! generate the next test error pattern + ind=-1 + do i=1,k-1 + if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i + enddo + if( ind .lt. 0 ) then ! no more patterns of this order + iflag=ind + return + endif + ms=0 + ms(1:ind-1)=mi(1:ind-1) + ms(ind)=1 + ms(ind+1)=0 + if( ind+1 .lt. k ) then + nz=iorder-sum(ms) + ms(k-nz+1:k)=1 + endif + mi=ms + do i=1,k ! iflag will point to the lowest-index 1 in mi + if(mi(i).eq.1) then + iflag=i + exit + endif + enddo + return +end subroutine nextpat + +subroutine boxit(reset,e2,ntau,npindex,i1,i2) + integer*1 e2(1:ntau) + integer indexes(4000,2),fp(0:525000),np(4000) + logical reset + common/boxes/indexes,fp,np + + if(reset) then + patterns=-1 + fp=-1 + np=-1 + sc=-1 + indexes=-1 + reset=.false. + endif + + indexes(npindex,1)=i1 + indexes(npindex,2)=i2 + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + + ip=fp(ipat) ! see what's currently stored in fp(ipat) + if(ip.eq.-1) then + fp(ipat)=npindex + else + do while (np(ip).ne.-1) + ip=np(ip) + enddo + np(ip)=npindex + endif + return +end subroutine boxit + +subroutine fetchit(reset,e2,ntau,i1,i2) + integer indexes(4000,2),fp(0:525000),np(4000) + integer lastpat + integer*1 e2(ntau) + logical reset + common/boxes/indexes,fp,np + save lastpat,inext + + if(reset) then + lastpat=-1 + reset=.false. + endif + + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + index=fp(ipat) + + if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices + i1=indexes(index,1) + i2=indexes(index,2) + inext=np(index) + elseif(lastpat.eq.ipat .and. inext.gt.0) then + i1=indexes(inext,1) + i2=indexes(inext,2) + inext=np(inext) + else + i1=-1 + i2=-1 + inext=-1 + endif + lastpat=ipat + return +end subroutine fetchit + diff --git a/lib/wsprd/t2.f90 b/lib/wsprd/t2.f90 index 1f12af90..0f214db4 100755 --- a/lib/wsprd/t2.f90 +++ b/lib/wsprd/t2.f90 @@ -1,11 +1,11 @@ -program t2 - - df=375.0/65536.0 - do i=1,65536 - w=1.0/(1.0 + ((i-32768)/26214.0)**20) - f=(i-32768)*df - write(13,1010) f,w -1010 format(2f15.6) - enddo - -end program t2 +program t2 + + df=375.0/65536.0 + do i=1,65536 + w=1.0/(1.0 + ((i-32768)/26214.0)**20) + f=(i-32768)*df + write(13,1010) f,w +1010 format(2f15.6) + enddo + +end program t2 diff --git a/lib/wsprd/tab.c b/lib/wsprd/tab.c index 751f94e9..e330c757 100755 --- a/lib/wsprd/tab.c +++ b/lib/wsprd/tab.c @@ -1,41 +1,41 @@ -/* - This file is part of wsprd. - - File name: tab.c - Description: 8-bit parity lookup table. -*/ -unsigned char Partab[] = { - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, -}; - +/* + This file is part of wsprd. + + File name: tab.c + Description: 8-bit parity lookup table. +*/ +unsigned char Partab[] = { + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, +}; + diff --git a/lib/wsprd/unpk.c.obsolete b/lib/wsprd/unpk.c.obsolete index 29fbd4d5..fae2bcf8 100755 --- a/lib/wsprd/unpk.c.obsolete +++ b/lib/wsprd/unpk.c.obsolete @@ -1,124 +1,124 @@ -/* the routine unpk() is not in wsprd_utils.c */ -#include -#include -#include -#include -#include -#include -#include - -#include "wsprd_utils.h" - -unsigned int nhash_( const void *key, size_t length, uint32_t initval); - -void unpk_(signed char message[], int *nhashtab, char call_loc_pow[]) -{ - int i,n1,n2,n3,ndbm,ihash,nadd,noprint,nh; - char callsign[13],grid[5],grid6[7],cdbm[3]; - static char hashtab[32768][13]; - FILE *fhash; - - if(*nhashtab==1) { - char line[80], hcall[12]; - if( (fhash=fopen("hashtable.txt","r+")) ) { - while (fgets(line, sizeof(line), fhash) != NULL) { - sscanf(line,"%d %s",&nh,hcall); - strcpy(*hashtab+nh*13,hcall); - } - } else { - fhash=fopen("hashtable.txt","w+"); - } - fclose(fhash); - return; - } - - if(*nhashtab==2) { - fhash=fopen("hashtable.txt","w"); - for (i=0; i<32768; i++) { - if( strncmp(hashtab[i],"\0",1) != 0 ) { - fprintf(fhash,"%5d %s\n",i,*hashtab+i*13); - } - } - fclose(fhash); - return; - } - - unpack50(message,&n1,&n2); - unpackcall(n1,callsign); - unpackgrid(n2, grid); - int ntype = (n2&127) - 64; - callsign[12]=0; - grid[4]=0; - -/* - Based on the value of ntype, decide whether this is a Type 1, 2, or - 3 message. - - * Type 1: 6 digit call, grid, power - ntype is positive and is a member - of the set {0,3,7,10,13,17,20...60} - - * Type 2: extended callsign, power - ntype is positive but not - a member of the set of allowed powers - - * Type 3: hash, 6 digit grid, power - ntype is negative. -*/ - - if( (ntype >= 0) && (ntype <= 62) ) { - int nu=ntype%10; - if( nu == 0 || nu == 3 || nu == 7 ) { - ndbm=ntype; - memset(call_loc_pow,0,sizeof(char)*23); - sprintf(cdbm,"%2d",ndbm); - strncat(call_loc_pow,callsign,strlen(callsign)); - strncat(call_loc_pow," ",1); - strncat(call_loc_pow,grid,4); - strncat(call_loc_pow," ",1); - strncat(call_loc_pow,cdbm,2); - strncat(call_loc_pow,"\0",1); - ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); - strcpy(*hashtab+ihash*13,callsign); - } else { - nadd=nu; - if( nu > 3 ) nadd=nu-3; - if( nu > 7 ) nadd=nu-7; - n3=n2/128+32768*(nadd-1); - unpackpfx(n3,callsign); - ndbm=ntype-nadd; - memset(call_loc_pow,0,sizeof(char)*23); - sprintf(cdbm,"%2d",ndbm); - strncat(call_loc_pow,callsign,strlen(callsign)); - strncat(call_loc_pow," ",1); - strncat(call_loc_pow,cdbm,2); - strncat(call_loc_pow,"\0",1); - ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); - strcpy(*hashtab+ihash*13,callsign); - noprint=0; - } - } else if ( ntype < 0 ) { - ndbm=-(ntype+1); - memset(grid6,0,sizeof(char)*7); - strncat(grid6,callsign+5,1); - strncat(grid6,callsign,5); - ihash=(n2-ntype-64)/128; - if( strncmp(hashtab[ihash],"\0",1) != 0 ) { - sprintf(callsign,"<%s>",hashtab[ihash]); - } else { - sprintf(callsign,"%5s","<...>"); - } - - memset(call_loc_pow,0,sizeof(char)*23); - sprintf(cdbm,"%2d",ndbm); - strncat(call_loc_pow,callsign,strlen(callsign)); - strncat(call_loc_pow," ",1); - strncat(call_loc_pow,grid6,strlen(grid6)); - strncat(call_loc_pow," ",1); - strncat(call_loc_pow,cdbm,2); - strncat(call_loc_pow,"\0",1); - - noprint=0; - -// I don't know what to do with these... They show up as "A000AA" grids. - if( ntype == -64 ) noprint=1; - } - // printf("\nUnpacked in C: %s\n",call_loc_pow); -} +/* the routine unpk() is not in wsprd_utils.c */ +#include +#include +#include +#include +#include +#include +#include + +#include "wsprd_utils.h" + +unsigned int nhash_( const void *key, size_t length, uint32_t initval); + +void unpk_(signed char message[], int *nhashtab, char call_loc_pow[]) +{ + int i,n1,n2,n3,ndbm,ihash,nadd,noprint,nh; + char callsign[13],grid[5],grid6[7],cdbm[3]; + static char hashtab[32768][13]; + FILE *fhash; + + if(*nhashtab==1) { + char line[80], hcall[12]; + if( (fhash=fopen("hashtable.txt","r+")) ) { + while (fgets(line, sizeof(line), fhash) != NULL) { + sscanf(line,"%d %s",&nh,hcall); + strcpy(*hashtab+nh*13,hcall); + } + } else { + fhash=fopen("hashtable.txt","w+"); + } + fclose(fhash); + return; + } + + if(*nhashtab==2) { + fhash=fopen("hashtable.txt","w"); + for (i=0; i<32768; i++) { + if( strncmp(hashtab[i],"\0",1) != 0 ) { + fprintf(fhash,"%5d %s\n",i,*hashtab+i*13); + } + } + fclose(fhash); + return; + } + + unpack50(message,&n1,&n2); + unpackcall(n1,callsign); + unpackgrid(n2, grid); + int ntype = (n2&127) - 64; + callsign[12]=0; + grid[4]=0; + +/* + Based on the value of ntype, decide whether this is a Type 1, 2, or + 3 message. + + * Type 1: 6 digit call, grid, power - ntype is positive and is a member + of the set {0,3,7,10,13,17,20...60} + + * Type 2: extended callsign, power - ntype is positive but not + a member of the set of allowed powers + + * Type 3: hash, 6 digit grid, power - ntype is negative. +*/ + + if( (ntype >= 0) && (ntype <= 62) ) { + int nu=ntype%10; + if( nu == 0 || nu == 3 || nu == 7 ) { + ndbm=ntype; + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,grid,4); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); + strcpy(*hashtab+ihash*13,callsign); + } else { + nadd=nu; + if( nu > 3 ) nadd=nu-3; + if( nu > 7 ) nadd=nu-7; + n3=n2/128+32768*(nadd-1); + unpackpfx(n3,callsign); + ndbm=ntype-nadd; + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); + strcpy(*hashtab+ihash*13,callsign); + noprint=0; + } + } else if ( ntype < 0 ) { + ndbm=-(ntype+1); + memset(grid6,0,sizeof(char)*7); + strncat(grid6,callsign+5,1); + strncat(grid6,callsign,5); + ihash=(n2-ntype-64)/128; + if( strncmp(hashtab[ihash],"\0",1) != 0 ) { + sprintf(callsign,"<%s>",hashtab[ihash]); + } else { + sprintf(callsign,"%5s","<...>"); + } + + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,grid6,strlen(grid6)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + + noprint=0; + +// I don't know what to do with these... They show up as "A000AA" grids. + if( ntype == -64 ) noprint=1; + } + // printf("\nUnpacked in C: %s\n",call_loc_pow); +} diff --git a/lib/wsprd/wspr_params.f90 b/lib/wsprd/wspr_params.f90 index 54d78586..ebfc4cf7 100755 --- a/lib/wsprd/wspr_params.f90 +++ b/lib/wsprd/wspr_params.f90 @@ -1,20 +1,20 @@ -parameter (NN=162) -parameter (NSPS0=8192) !Samples per symbol at 12000 S/s -parameter (NDOWN=32) -parameter (NSPS=NSPS0/NDOWN) -parameter (NZ=NSPS*NN) !Samples in waveform at 12000 S/s -parameter (NZ0=NSPS0*NN) !Samples in waveform at 375 S/s -parameter (NMAX=120*12000) !Samples in waveform at 375 S/s - -! Define the sync vector: -integer*1 sync(162) -data sync/ & - 1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, & - 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, & - 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, & - 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, & - 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, & - 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, & - 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, & - 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, & - 0,0/ +parameter (NN=162) +parameter (NSPS0=8192) !Samples per symbol at 12000 S/s +parameter (NDOWN=32) +parameter (NSPS=NSPS0/NDOWN) +parameter (NZ=NSPS*NN) !Samples in waveform at 12000 S/s +parameter (NZ0=NSPS0*NN) !Samples in waveform at 375 S/s +parameter (NMAX=120*12000) !Samples in waveform at 375 S/s + +! Define the sync vector: +integer*1 sync(162) +data sync/ & + 1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, & + 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, & + 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, & + 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, & + 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, & + 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, & + 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, & + 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, & + 0,0/ diff --git a/lib/wsprd/wspr_wav.f90 b/lib/wsprd/wspr_wav.f90 index bad72b55..900ebda4 100755 --- a/lib/wsprd/wspr_wav.f90 +++ b/lib/wsprd/wspr_wav.f90 @@ -1,49 +1,49 @@ -subroutine wspr_wav(baud,xdt,h,f0,itone,snrdb,iwave) - -! Generate iwave() from itone(). - - include 'wspr_params.f90' - integer itone(NN) - integer*2 iwave(NMAX) - real*8 twopi,dt,dphi0,dphi1,dphi,phi - real dat(NMAX) - - twopi=8.d0*atan(1.d0) - dt=1.d0/12000.d0 - baud=375.0/256.0 - - dat=0. - if(snrdb.lt.90) then - do i=1,NMAX - dat(i)=gran() !Generate gaussian noise - enddo - bandwidth_ratio=2500.0/6000.0 - sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb) - else - sig=1.0 - endif - - phi=0.d0 - k=nint(xdt/dt) - do j=1,NN - dphi=twopi*(f0+h*(itone(j)-1.5)*baud)*dt - do i=1,NSPS0 - k=k+1 - phi=mod(phi+dphi,twopi) - if(k.gt.0 .and. k.le.NMAX) dat(k)=dat(k) + sig*sin(phi) - enddo - enddo - - rms=100.0 - if(snrdb.lt.90.0) then - dat=rms*dat; - if(maxval(abs(dat)).gt.32767.0) print*,"Warning - data will be clipped." - else - datpk=maxval(abs(dat)) - fac=32767.0/datpk - dat=fac*dat - endif - iwave=nint(dat) - - return -end subroutine wspr_wav +subroutine wspr_wav(baud,xdt,h,f0,itone,snrdb,iwave) + +! Generate iwave() from itone(). + + include 'wspr_params.f90' + integer itone(NN) + integer*2 iwave(NMAX) + real*8 twopi,dt,dphi0,dphi1,dphi,phi + real dat(NMAX) + + twopi=8.d0*atan(1.d0) + dt=1.d0/12000.d0 + baud=375.0/256.0 + + dat=0. + if(snrdb.lt.90) then + do i=1,NMAX + dat(i)=gran() !Generate gaussian noise + enddo + bandwidth_ratio=2500.0/6000.0 + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb) + else + sig=1.0 + endif + + phi=0.d0 + k=nint(xdt/dt) + do j=1,NN + dphi=twopi*(f0+h*(itone(j)-1.5)*baud)*dt + do i=1,NSPS0 + k=k+1 + phi=mod(phi+dphi,twopi) + if(k.gt.0 .and. k.le.NMAX) dat(k)=dat(k) + sig*sin(phi) + enddo + enddo + + rms=100.0 + if(snrdb.lt.90.0) then + dat=rms*dat; + if(maxval(abs(dat)).gt.32767.0) print*,"Warning - data will be clipped." + else + datpk=maxval(abs(dat)) + fac=32767.0/datpk + dat=fac*dat + endif + iwave=nint(dat) + + return +end subroutine wspr_wav diff --git a/lib/wsprd/wsprd.c b/lib/wsprd/wsprd.c index 484e4ecb..13f8d8b3 100755 --- a/lib/wsprd/wsprd.c +++ b/lib/wsprd/wsprd.c @@ -1,1581 +1,1582 @@ -/* - This file is part of program wsprd, a detector/demodulator/decoder - for the Weak Signal Propagation Reporter (WSPR) mode. - - File name: wsprd.c - - Copyright 2001-2018, Joe Taylor, K1JT - - Much of the present code is based on work by Steven Franke, K9AN, - which in turn was based on earlier work by K1JT. - - Copyright 2014-2018, Steven Franke, K9AN - - License: GNU GPL v3 - - 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 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fano.h" -#include "jelinek.h" -#include "nhash.h" -#include "wsprd_utils.h" -#include "wsprsim_utils.h" - -#define max(x,y) ((x) > (y) ? (x) : (y)) - -extern void osdwspr_ (float [], unsigned char [], int *, unsigned char [], int *, float *); - -// Possible PATIENCE options: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT, -// FFTW_MEASURE, FFTW_PATIENT, FFTW_EXHAUSTIVE -#define PATIENCE FFTW_ESTIMATE -fftwf_plan PLAN1,PLAN2,PLAN3; - -unsigned char pr3[162]= -{1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, - 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, - 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, - 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, - 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, - 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, - 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, - 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, - 0,0}; - -int printdata=0; - -//*************************************************************************** -unsigned long readc2file(char *ptr_to_infile, float *idat, float *qdat, - double *freq, int *wspr_type) -{ - float *buffer; - double dfreq; - int i,ntrmin; - char c2file[15]; - size_t nr; - FILE* fp; - - fp = fopen(ptr_to_infile,"rb"); - if (fp == NULL) { - fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile); - return 1; - } - nr=fread(c2file,sizeof(char),14,fp); - nr=fread(&ntrmin,sizeof(int),1,fp); - nr=fread(&dfreq,sizeof(double),1,fp); - *freq=dfreq; - - buffer=calloc(2*65536,sizeof(float)); - nr=fread(buffer,sizeof(float),2*45000,fp); - fclose(fp); - - *wspr_type=ntrmin; - - for(i=0; i<45000; i++) { - idat[i]=buffer[2*i]; - qdat[i]=-buffer[2*i+1]; - } - free(buffer); - - if( nr == 2*45000 ) { - return (unsigned long) nr/2; - } else { - return 1; - } -} - -//*************************************************************************** -unsigned long readwavfile(char *ptr_to_infile, int ntrmin, float *idat, float *qdat ) -{ - size_t i, j, npoints, nr; - int nfft1, nfft2, nh2, i0; - double df; - - nfft2=46080; //this is the number of downsampled points that will be returned - nh2=nfft2/2; - - if( ntrmin == 2 ) { - nfft1=nfft2*32; //need to downsample by a factor of 32 - df=12000.0/nfft1; - i0=1500.0/df+0.5; - npoints=114*12000; - } else if ( ntrmin == 15 ) { - nfft1=nfft2*8*32; - df=12000.0/nfft1; - i0=(1500.0+112.5)/df+0.5; - npoints=8*114*12000; - } else { - fprintf(stderr,"This should not happen\n"); - return 1; - } - - float *realin; - fftwf_complex *fftin, *fftout; - - FILE *fp; - short int *buf2; - - fp = fopen(ptr_to_infile,"rb"); - if (fp == NULL) { - fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile); - return 1; - } - - buf2 = calloc(npoints,sizeof(short int)); - nr=fread(buf2,2,22,fp); //Read and ignore header - nr=fread(buf2,2,npoints,fp); //Read raw data - fclose(fp); - if( nr == 0 ) { - free(buf2); - fprintf(stderr, "No data in file '%s'\n", ptr_to_infile); - return 1; - } - - realin=(float*) fftwf_malloc(sizeof(float)*nfft1); - fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*(nfft1/2+1)); - PLAN1 = fftwf_plan_dft_r2c_1d(nfft1, realin, fftout, PATIENCE); - - for (i=0; i(size_t)nh2 ) j=j-nfft2; - fftin[i][0]=fftout[j][0]; - fftin[i][1]=fftout[j][1]; - } - - fftwf_free(fftout); - fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*nfft2); - PLAN2 = fftwf_plan_dft_1d(nfft2, fftin, fftout, FFTW_BACKWARD, PATIENCE); - fftwf_execute(PLAN2); - - for (i=0; i<(size_t)nfft2; i++) { - idat[i]=fftout[i][0]/1000.0; - qdat[i]=fftout[i][1]/1000.0; - } - - fftwf_free(fftin); - fftwf_free(fftout); - return nfft2; -} - -//*************************************************************************** -void sync_and_demodulate(float *id, float *qd, long np, - unsigned char *symbols, float *f1, int ifmin, int ifmax, float fstep, - int *shift1, int lagmin, int lagmax, int lagstep, - float *drift1, int symfac, float *sync, int mode) -{ - /*********************************************************************** - * mode = 0: no frequency or drift search. find best time lag. * - * 1: no time lag or drift search. find best frequency. * - * 2: no frequency or time lag search. calculate soft-decision * - * symbols using passed frequency and shift. * - ************************************************************************/ - - static float fplast=-10000.0; - static float dt=1.0/375.0, df=375.0/256.0; - static float pi=3.14159265358979323846; - float twopidt, df15=df*1.5, df05=df*0.5; - - int i, j, k, lag; - float i0[162],q0[162],i1[162],q1[162],i2[162],q2[162],i3[162],q3[162]; - float p0,p1,p2,p3,cmet,totp,syncmax,fac; - float c0[256],s0[256],c1[256],s1[256],c2[256],s2[256],c3[256],s3[256]; - float dphi0, cdphi0, sdphi0, dphi1, cdphi1, sdphi1, dphi2, cdphi2, sdphi2, - dphi3, cdphi3, sdphi3; - float f0=0.0, fp, ss, fbest=0.0, fsum=0.0, f2sum=0.0, fsymb[162]; - int best_shift = 0, ifreq; - - syncmax=-1e30; - if( mode == 0 ) {ifmin=0; ifmax=0; fstep=0.0; f0=*f1;} - if( mode == 1 ) {lagmin=*shift1;lagmax=*shift1;f0=*f1;} - if( mode == 2 ) {lagmin=*shift1;lagmax=*shift1;ifmin=0;ifmax=0;f0=*f1;} - - twopidt=2*pi*dt; - for(ifreq=ifmin; ifreq<=ifmax; ifreq++) { - f0=*f1+ifreq*fstep; - for(lag=lagmin; lag<=lagmax; lag=lag+lagstep) { - ss=0.0; - totp=0.0; - for (i=0; i<162; i++) { - fp = f0 + (*drift1/2.0)*((float)i-81.0)/81.0; - if( i==0 || (fp != fplast) ) { // only calculate sin/cos if necessary - dphi0=twopidt*(fp-df15); - cdphi0=cos(dphi0); - sdphi0=sin(dphi0); - - dphi1=twopidt*(fp-df05); - cdphi1=cos(dphi1); - sdphi1=sin(dphi1); - - dphi2=twopidt*(fp+df05); - cdphi2=cos(dphi2); - sdphi2=sin(dphi2); - - dphi3=twopidt*(fp+df15); - cdphi3=cos(dphi3); - sdphi3=sin(dphi3); - - c0[0]=1; s0[0]=0; - c1[0]=1; s1[0]=0; - c2[0]=1; s2[0]=0; - c3[0]=1; s3[0]=0; - - for (j=1; j<256; j++) { - c0[j]=c0[j-1]*cdphi0 - s0[j-1]*sdphi0; - s0[j]=c0[j-1]*sdphi0 + s0[j-1]*cdphi0; - c1[j]=c1[j-1]*cdphi1 - s1[j-1]*sdphi1; - s1[j]=c1[j-1]*sdphi1 + s1[j-1]*cdphi1; - c2[j]=c2[j-1]*cdphi2 - s2[j-1]*sdphi2; - s2[j]=c2[j-1]*sdphi2 + s2[j-1]*cdphi2; - c3[j]=c3[j-1]*cdphi3 - s3[j-1]*sdphi3; - s3[j]=c3[j-1]*sdphi3 + s3[j-1]*cdphi3; - } - fplast = fp; - } - - i0[i]=0.0; q0[i]=0.0; - i1[i]=0.0; q1[i]=0.0; - i2[i]=0.0; q2[i]=0.0; - i3[i]=0.0; q3[i]=0.0; - - for (j=0; j<256; j++) { - k=lag+i*256+j; - if( (k>0) && (k syncmax ) { //Save best parameters - syncmax=ss; - best_shift=lag; - fbest=f0; - } - } // lag loop - } //freq loop - - if( mode <=1 ) { //Send best params back to caller - *sync=syncmax; - *shift1=best_shift; - *f1=fbest; - return; - } - - if( mode == 2 ) { - *sync=syncmax; - for (i=0; i<162; i++) { //Normalize the soft symbols - fsum=fsum+fsymb[i]/162.0; - f2sum=f2sum+fsymb[i]*fsymb[i]/162.0; - } - fac=sqrt(f2sum-fsum*fsum); - for (i=0; i<162; i++) { - fsymb[i]=symfac*fsymb[i]/fac; - if( fsymb[i] > 127) fsymb[i]=127.0; - if( fsymb[i] < -128 ) fsymb[i]=-128.0; - symbols[i]=fsymb[i] + 128; - } - return; - } - return; -} - -void noncoherent_sequence_detection(float *id, float *qd, long np, - unsigned char *symbols, float *f1, int *shift1, - float *drift1, int symfac, int *nblocksize, int *bitmetric) -{ - /************************************************************************ - * Noncoherent sequence detection for wspr. * - * Allowed block lengths are nblock=1,2,3,6, or 9 symbols. * - * Longer block lengths require longer channel coherence time. * - * The whole block is estimated at once. * - * nblock=1 corresponds to noncoherent detection of individual symbols * - * like the original wsprd symbol demodulator. * - ************************************************************************/ - static float fplast=-10000.0; - static float dt=1.0/375.0, df=375.0/256.0; - static float pi=3.14159265358979323846; - float twopidt, df15=df*1.5, df05=df*0.5; - - int i, j, k, lag, itone, ib, b, nblock, nseq, imask; - float xi[512],xq[512]; - float is[4][162],qs[4][162],cf[4][162],sf[4][162],cm,sm,cmp,smp; - float p[512],fac,xm1,xm0; - float c0[257],s0[257],c1[257],s1[257],c2[257],s2[257],c3[257],s3[257]; - float dphi0, cdphi0, sdphi0, dphi1, cdphi1, sdphi1, dphi2, cdphi2, sdphi2, - dphi3, cdphi3, sdphi3; - float f0, fp, fsum=0.0, f2sum=0.0, fsymb[162]; - - twopidt=2*pi*dt; - f0=*f1; - lag=*shift1; - nblock=*nblocksize; - nseq=1<0) && (k>(nblock-1-ib); - itone=pr3[i+ib]+2*b; - xi[j]=xi[j]+is[itone][i+ib]*cm + qs[itone][i+ib]*sm; - xq[j]=xq[j]+qs[itone][i+ib]*cm - is[itone][i+ib]*sm; - cmp=cf[itone][i+ib]*cm - sf[itone][i+ib]*sm; - smp=sf[itone][i+ib]*cm + cf[itone][i+ib]*sm; - cm=cmp; sm=smp; - } - p[j]=xi[j]*xi[j]+xq[j]*xq[j]; - p[j]=sqrt(p[j]); - } - for (ib=0; ib xm1) xm1=p[j]; - } - if((j & imask)==0) { - if(p[j]>xm0) xm0=p[j]; - } - } - fsymb[i+ib]=xm1-xm0; - if( bitbybit == 1 ) { - fsymb[i+ib]=fsymb[i+ib]/(xm1 > xm0 ? xm1 : xm0); - } - } - } - for (i=0; i<162; i++) { //Normalize the soft symbols - fsum=fsum+fsymb[i]/162.0; - f2sum=f2sum+fsymb[i]*fsymb[i]/162.0; - } - fac=sqrt(f2sum-fsum*fsum); - for (i=0; i<162; i++) { - fsymb[i]=symfac*fsymb[i]/fac; - if( fsymb[i] > 127) fsymb[i]=127.0; - if( fsymb[i] < -128 ) fsymb[i]=-128.0; - symbols[i]=fsymb[i] + 128; - } - return; -} - -/*************************************************************************** - symbol-by-symbol signal subtraction - ****************************************************************************/ -void subtract_signal(float *id, float *qd, long np, - float f0, int shift0, float drift0, unsigned char* channel_symbols) -{ - float dt=1.0/375.0, df=375.0/256.0; - int i, j, k; - float pi=4.*atan(1.0),twopidt, fp; - - float i0,q0; - float c0[256],s0[256]; - float dphi, cdphi, sdphi; - - twopidt=2*pi*dt; - - for (i=0; i<162; i++) { - fp = f0 + ((float)drift0/2.0)*((float)i-81.0)/81.0; - - dphi=twopidt*(fp+((float)channel_symbols[i]-1.5)*df); - cdphi=cos(dphi); - sdphi=sin(dphi); - - c0[0]=1; s0[0]=0; - - for (j=1; j<256; j++) { - c0[j]=c0[j-1]*cdphi - s0[j-1]*sdphi; - s0[j]=c0[j-1]*sdphi + s0[j-1]*cdphi; - } - - i0=0.0; q0=0.0; - - for (j=0; j<256; j++) { - k=shift0+i*256+j; - if( (k>0) & (k0) & (k0) && (k(nsig-1-nfilt/2) ) { - norm=partialsum[nfilt/2+nsig-1-i]; - } else { - norm=1.0; - } - k=shift0+i; - j=i+nfilt; - if( (k>0) && (k=2 ? 1:0; - } - deinterleave(cw); - nerrors=0; - for (i=0; i<162; i++) { - is = symbols[i] > 127 ? 1:0; - nerrors = nerrors + (is == cw[i] ? 0:1); - } - return nerrors; -} - -//*************************************************************************** -void usage(void) -{ - printf("Usage: wsprd [options...] infile\n"); - printf(" infile must have suffix .wav or .c2\n"); - printf("\n"); - printf("Options:\n"); - printf(" -a path to writeable data files, default=\".\"\n"); - printf(" -B disable block demodulation - use single-symbol noncoherent demod\n"); - printf(" -c write .c2 file at the end of the first pass\n"); - printf(" -C maximum number of decoder cycles per bit, default 10000\n"); - printf(" -d deeper search. Slower, a few more decodes\n"); - printf(" -e x (x is transceiver dial frequency error in Hz)\n"); - printf(" -f x (x is transceiver dial frequency in MHz)\n"); - printf(" -H do not use (or update) the hash table\n"); - printf(" -J use the stack decoder instead of Fano decoder\n"); - printf(" -m decode wspr-15 .wav file\n"); - printf(" -o n (0<=n<=5), decoding depth for OSD, default is disabled\n"); - printf(" -q quick mode - doesn't dig deep for weak signals\n"); - printf(" -s single pass mode, no subtraction (same as original wsprd)\n"); - printf(" -v verbose mode (shows dupes)\n"); - printf(" -w wideband mode - decode signals within +/- 150 Hz of center\n"); - printf(" -z x (x is fano metric table bias, default is 0.45)\n"); -} - -//*************************************************************************** -int main(int argc, char *argv[]) -{ - char cr[] = "(C) 2018, Steven Franke - K9AN"; - (void)cr; - extern char *optarg; - extern int optind; - int i,j,k; - unsigned char *symbols, *decdata, *channel_symbols, *apmask, *cw; - signed char message[]={-9,13,-35,123,57,-39,64,0,0,0,0}; - char *callsign, *grid, *call_loc_pow; - char *ptr_to_infile,*ptr_to_infile_suffix; - char *data_dir="."; - char wisdom_fname[200],all_fname[200],spots_fname[200]; - char timer_fname[200],hash_fname[200]; - char uttime[5],date[7]; - int c,delta,maxpts=65536,verbose=0,quickmode=0,more_candidates=0, stackdecoder=0; - int usehashtable=1,wspr_type=2, ipass, nblocksize; - int nhardmin,ihash; - int writec2=0,maxdrift; - int shift1, lagmin, lagmax, lagstep, ifmin, ifmax, not_decoded; - unsigned int nbits=81, stacksize=200000; - struct snode * stack=NULL; - unsigned int npoints, cycles, maxnp, metric; - float df=375.0/256.0/2; - float fsymbs[162]; - float dt=1.0/375.0, dt_print; - double dialfreq_cmdline=0.0, dialfreq, freq_print; - double dialfreq_error=0.0; - float fmin=-110, fmax=110; - float f1, fstep, sync1, drift1; - float dmin; - float psavg[512]; - float *idat, *qdat; - clock_t t0,t00; - float tfano=0.0,treadwav=0.0,tcandidates=0.0,tsync0=0.0; - float tsync1=0.0,tsync2=0.0,tosd=0.0,ttotal=0.0; - - struct cand { float freq; float snr; int shift; float drift; float sync; }; - struct cand candidates[200]; - - struct result { char date[7]; char time[5]; float sync; float snr; - float dt; double freq; char message[23]; float drift; - unsigned int cycles; int jitter; int blocksize; unsigned int metric; - int nhardmin; int ipass; int decodetype;}; - struct result decodes[50]; - - char *hashtab; - hashtab=calloc(32768*13,sizeof(char)); - char *loctab; - loctab=calloc(32768*5,sizeof(char)); - int nh; - symbols=calloc(nbits*2,sizeof(unsigned char)); - apmask=calloc(162,sizeof(unsigned char)); - cw=calloc(162,sizeof(unsigned char)); - decdata=calloc(11,sizeof(unsigned char)); - channel_symbols=calloc(nbits*2,sizeof(unsigned char)); - callsign=calloc(13,sizeof(char)); - grid=calloc(5,sizeof(char)); - call_loc_pow=calloc(23,sizeof(char)); - float allfreqs[100]; - char allcalls[100][13]; - for (i=0; i<100; i++) allfreqs[i]=0.0; - memset(allcalls,0,sizeof(char)*100*13); - - int uniques=0, noprint=0, ndecodes_pass=0; - - // Parameters used for performance-tuning: - unsigned int maxcycles=10000; //Decoder timeout limit - float minsync1=0.10; //First sync limit - float minsync2=0.12; //Second sync limit - int iifac=8; //Step size in final DT peakup - int symfac=50; //Soft-symbol normalizing factor - int subtraction=1; - int npasses=3; - int ndepth=-1; //Depth for OSD - - float minrms=52.0 * (symfac/64.0); //Final test for plausible decoding - delta=60; //Fano threshold step - float bias=0.45; //Fano metric bias (used for both Fano and stack algorithms) - - t00=clock(); - fftwf_complex *fftin, *fftout; -#include "./metric_tables.c" - - int mettab[2][256]; - - idat=calloc(maxpts,sizeof(float)); - qdat=calloc(maxpts,sizeof(float)); - - while ( (c = getopt(argc, argv, "a:BcC:de:f:HJmo:qstwvz:")) !=-1 ) { - switch (c) { - case 'a': - data_dir = optarg; - break; - case 'B': - npasses=2; - break; - case 'c': - writec2=1; - break; - case 'C': - maxcycles=(unsigned int) strtoul(optarg,NULL,10); - break; - case 'd': - more_candidates=1; - break; - case 'e': - dialfreq_error = strtod(optarg,NULL); // units of Hz - // dialfreq_error = dial reading - actual, correct frequency - break; - case 'f': - dialfreq_cmdline = strtod(optarg,NULL); // units of MHz - break; - case 'H': - usehashtable = 0; - break; - case 'J': //Stack (Jelinek) decoder, Fano decoder is the default - stackdecoder = 1; - break; - case 'm': //15-minute wspr mode - wspr_type = 15; - break; - case 'o': //use ordered-statistics-decoder - ndepth=(int) strtol(optarg,NULL,10); - break; - case 'q': //no shift jittering - quickmode = 1; - break; - case 's': //single pass mode - subtraction = 0; - npasses = 1; - break; - case 'v': - verbose = 1; - break; - case 'w': - fmin=-150.0; - fmax=150.0; - break; - case 'z': - bias=strtod(optarg,NULL); //fano metric bias (default is 0.45) - break; - case '?': - usage(); - return 1; - } - } - - if( access(data_dir, R_OK | W_OK)) { - fprintf(stderr, "Error: inaccessible data directory: '%s'\n", data_dir); - usage(); - return EXIT_FAILURE; - } - - if( optind+1 > argc) { - usage(); - return 1; - } else { - ptr_to_infile=argv[optind]; - } - - if( stackdecoder ) { - stack=calloc(stacksize,sizeof(struct snode)); - } - - // setup metric table - for(i=0; i<256; i++) { - mettab[0][i]=round( 10*(metric_tables[2][i]-bias) ); - mettab[1][i]=round( 10*(metric_tables[2][255-i]-bias) ); - } - - FILE *fp_fftwf_wisdom_file, *fall_wspr, *fwsprd, *fhash, *ftimer; - strcpy(wisdom_fname,"."); - strcpy(all_fname,"."); - strcpy(spots_fname,"."); - strcpy(timer_fname,"."); - strcpy(hash_fname,"."); - if(data_dir != NULL) { - strncpy(wisdom_fname,data_dir, sizeof wisdom_fname); - strncpy(all_fname,data_dir, sizeof all_fname); - strncpy(spots_fname,data_dir, sizeof spots_fname); - strncpy(timer_fname,data_dir, sizeof timer_fname); - strncpy(hash_fname,data_dir, sizeof hash_fname); - } - strncat(wisdom_fname,"/wspr_wisdom.dat",20); - strncat(all_fname,"/ALL_WSPR.TXT",20); - strncat(spots_fname,"/wspr_spots.txt",20); - strncat(timer_fname,"/wspr_timer.out",20); - strncat(hash_fname,"/hashtable.txt",20); - if ((fp_fftwf_wisdom_file = fopen(wisdom_fname, "r"))) { //Open FFTW wisdom - fftwf_import_wisdom_from_file(fp_fftwf_wisdom_file); - fclose(fp_fftwf_wisdom_file); - } - - fall_wspr=fopen(all_fname,"a"); - fwsprd=fopen(spots_fname,"w"); - // FILE *fdiag; - // fdiag=fopen("wsprd_diag","a"); - - if((ftimer=fopen(timer_fname,"r"))) { - //Accumulate timing data - int nr=fscanf(ftimer,"%f %f %f %f %f %f %f %f", - &treadwav,&tcandidates,&tsync0,&tsync1,&tsync2,&tfano,&tosd,&ttotal); - fclose(ftimer); - if(nr == 0) fprintf(stderr, "Empty timer file: '%s'\n", timer_fname); - } - ftimer=fopen(timer_fname,"w"); - - if( strstr(ptr_to_infile,".wav") ) { - ptr_to_infile_suffix=strstr(ptr_to_infile,".wav"); - - t0 = clock(); - npoints=readwavfile(ptr_to_infile, wspr_type, idat, qdat); - treadwav += (float)(clock()-t0)/CLOCKS_PER_SEC; - - if( npoints == 1 ) { - return 1; - } - dialfreq=dialfreq_cmdline - (dialfreq_error*1.0e-06); - } else if ( strstr(ptr_to_infile,".c2") !=0 ) { - ptr_to_infile_suffix=strstr(ptr_to_infile,".c2"); - npoints=readc2file(ptr_to_infile, idat, qdat, &dialfreq, &wspr_type); - if( npoints == 1 ) { - return 1; - } - dialfreq -= (dialfreq_error*1.0e-06); - } else { - printf("Error: Failed to open %s\n",ptr_to_infile); - printf("WSPR file must have suffix .wav or .c2\n"); - return 1; - } - - // Parse date and time from given filename - strncpy(date,ptr_to_infile_suffix-11,6); - strncpy(uttime,ptr_to_infile_suffix-4,4); - date[6]='\0'; - uttime[4]='\0'; - - // Do windowed ffts over 2 symbols, stepped by half symbols - int nffts=4*floor(npoints/512)-1; - fftin=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*512); - fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*512); - PLAN3 = fftwf_plan_dft_1d(512, fftin, fftout, FFTW_FORWARD, PATIENCE); - - float ps[512][nffts]; - float w[512]; - for(i=0; i<512; i++) { - w[i]=sin(0.006147931*i); - } - - if( usehashtable ) { - char line[80], hcall[13], hgrid[5]; - if( (fhash=fopen(hash_fname,"r+")) ) { - while (fgets(line, sizeof(line), fhash) != NULL) { - hgrid[0]='\0'; - sscanf(line,"%d %s %s",&nh,hcall,hgrid); - strcpy(hashtab+nh*13,hcall); - if(strlen(hgrid)>0) strcpy(loctab+nh*5,hgrid); - } - } else { - fhash=fopen(hash_fname,"w+"); - } - fclose(fhash); - } - - //*************** main loop starts here ***************** - for (ipass=0; ipass2) ipass=2; - if(ipass < 2) { - nblocksize=1; - maxdrift=4; - minsync2=0.12; - } - if(ipass == 2 ) { - nblocksize=4; // try 3 blocksizes plus bitbybit normalization - maxdrift=0; // no drift for smaller frequency estimator variance - minsync2=0.10; - } - ndecodes_pass=0; // still needed? - - for (i=0; i511 ) - k=k-512; - ps[j][i]=fftout[k][0]*fftout[k][0]+fftout[k][1]*fftout[k][1]; - } - } - - // Compute average spectrum - for (i=0; i<512; i++) psavg[i]=0.0; - for (i=0; ismspec[j-1]) && - (smspec[j]>smspec[j+1]) && - (npk<200); - if ( candidate ) { - candidates[npk].freq = (j-205)*df; - candidates[npk].snr = 10*log10(smspec[j])-snr_scaling_factor; - npk++; - } - } - if( more_candidates ) { - for(j=0; j<411; j=j+3) { - candidate = (smspec[j]>min_snr) && (npk<200); - if ( candidate ) { - candidates[npk].freq = (j-205)*df; - candidates[npk].snr = 10*log10(smspec[j])-snr_scaling_factor; - npk++; - } - } - } - - // Compute corrected fmin, fmax, accounting for dial frequency error - fmin += dialfreq_error; // dialfreq_error is in units of Hz - fmax += dialfreq_error; - - // Don't waste time on signals outside of the range [fmin,fmax]. - i=0; - for( j=0; j= fmin && candidates[j].freq <= fmax ) { - candidates[i]=candidates[j]; - i++; - } - } - npk=i; - - // bubble sort on snr - int pass; - struct cand tmp; - for (pass = 1; pass <= npk - 1; pass++) { - for (k = 0; k < npk - pass ; k++) { - if (candidates[k].snr < candidates[k+1].snr) { - tmp = candidates[k]; - candidates[k]=candidates[k+1]; - candidates[k+1] = tmp; - } - } - } - - t0=clock(); - - /* Make coarse estimates of shift (DT), freq, and drift - - * Look for time offsets up to +/- 8 symbols (about +/- 5.4 s) relative - to nominal start time, which is 2 seconds into the file - - * Calculates shift relative to the beginning of the file - - * Negative shifts mean that signal started before start of file - - * The program prints DT = shift-2 s - - * Shifts that cause sync vector to fall off of either end of the data - vector are accommodated by "partial decoding", such that missing - symbols produce a soft-decision symbol value of 128 - - * The frequency drift model is linear, deviation of +/- drift/2 over the - span of 162 symbols, with deviation equal to 0 at the center of the - signal vector. - */ - - int idrift,ifr,if0,ifd,k0; - int kindex; - float smax,ss,pow,p0,p1,p2,p3; - for(j=0; j= 0 && kindex < nffts ) { - p0=ps[ifd-3][kindex]; - p1=ps[ifd-1][kindex]; - p2=ps[ifd+1][kindex]; - p3=ps[ifd+3][kindex]; - - p0=sqrt(p0); - p1=sqrt(p1); - p2=sqrt(p2); - p3=sqrt(p3); - - ss=ss+(2*pr3[k]-1)*((p1+p3)-(p0+p2)); - pow=pow+p0+p1+p2+p3; - } - } - sync1=ss/pow; - if( sync1 > smax ) { //Save coarse parameters - smax=sync1; - candidates[j].shift=128*(k0+1); - candidates[j].drift=idrift; - candidates[j].freq=(ifr-256)*df; - candidates[j].sync=sync1; - } - } - } - } - } - tcandidates += (float)(clock()-t0)/CLOCKS_PER_SEC; - - /* - Refine the estimates of freq, shift using sync as a metric. - Sync is calculated such that it is a float taking values in the range - [0.0,1.0]. - - Function sync_and_demodulate has three modes of operation - mode is the last argument: - - 0 = no frequency or drift search. find best time lag. - 1 = no time lag or drift search. find best frequency. - 2 = no frequency or time lag search. Calculate soft-decision - symbols using passed frequency and shift. - - NB: best possibility for OpenMP may be here: several worker threads - could each work on one candidate at a time. - */ - for (j=0; jminsync1 continue - fstep=0.0; ifmin=0; ifmax=0; - lagmin=shift1-128; - lagmax=shift1+128; - lagstep=64; - t0 = clock(); - sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, - lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0); - tsync0 += (float)(clock()-t0)/CLOCKS_PER_SEC; - - fstep=0.25; ifmin=-2; ifmax=2; - t0 = clock(); - sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, - lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1); - - if(ipass < 2) { - // refine drift estimate - fstep=0.0; ifmin=0; ifmax=0; - float driftp,driftm,syncp,syncm; - driftp=drift1+0.5; - sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, - lagmin, lagmax, lagstep, &driftp, symfac, &syncp, 1); - - driftm=drift1-0.5; - sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, - lagmin, lagmax, lagstep, &driftm, symfac, &syncm, 1); - - if(syncp>sync1) { - drift1=driftp; - sync1=syncp; - } else if (syncm>sync1) { - drift1=driftm; - sync1=syncm; - } - } - tsync1 += (float)(clock()-t0)/CLOCKS_PER_SEC; - - // fine-grid lag and freq search - if( sync1 > minsync1 ) { - - lagmin=shift1-32; lagmax=shift1+32; lagstep=16; - t0 = clock(); - sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, - lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0); - tsync0 += (float)(clock()-t0)/CLOCKS_PER_SEC; - - // fine search over frequency - fstep=0.05; ifmin=-2; ifmax=2; - t0 = clock(); - sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, - lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1); - tsync1 += (float)(clock()-t0)/CLOCKS_PER_SEC; - - candidates[j].freq=f1; - candidates[j].shift=shift1; - candidates[j].drift=drift1; - candidates[j].sync=sync1; - } - } - - int nwat=0; - int idupe; - for ( j=0; j candidates[k].sync) candidates[k]=candidates[j]; - } else if ( candidates[j].sync > minsync2 ) { - candidates[nwat]=candidates[j]; - nwat++; - } - } - - int idt, ii, jittered_shift; - float y,sq,rms; - int ib, blocksize, bitmetric; - int n1,n2,n3,nadd,nu,ntype; - int osd_decode; - for (j=0; j minrms) { - deinterleave(symbols); - t0 = clock(); - - if ( stack ) { - not_decoded = jelinek(&metric, &cycles, decdata, symbols, nbits, - stacksize, stack, mettab,maxcycles); - } else { - not_decoded = fano(&metric,&cycles,&maxnp,decdata,symbols,nbits, - mettab,delta,maxcycles); - } - - tfano += (float)(clock()-t0)/CLOCKS_PER_SEC; - - if( (ndepth >= 0) && not_decoded ) { - for(i=0; i<162; i++) { - fsymbs[i]=symbols[i]-128.0; - } - t0 = clock(); - osdwspr_(fsymbs,apmask,&ndepth,cw,&nhardmin,&dmin); - tosd += (float)(clock()-t0)/CLOCKS_PER_SEC; - - for(i=0; i<162; i++) { - symbols[i]=255*cw[i]; - } - fano(&metric,&cycles,&maxnp,decdata,symbols,nbits, - mettab,delta,maxcycles); - for(i=0; i<11; i++) { - if( decdata[i]>127 ) { - message[i]=decdata[i]-256; - } else { - message[i]=decdata[i]; - } - } - unpack50(message,&n1,&n2); - if( !unpackcall(n1,callsign) ) break; - callsign[12]=0; - if( !unpackgrid(n2, grid) ) break; - grid[4]=0; - ntype = (n2&127) - 64; - int itype; - if( (ntype >= 0) && (ntype <= 62) ) { - nu = ntype%10; - itype=1; - if( !(nu == 0 || nu == 3 || nu == 7) ) { - nadd=nu; - if( nu > 3 ) nadd=nu-3; - if( nu > 7 ) nadd=nu-7; - n3=n2/128+32768*(nadd-1); - if( !unpackpfx(n3,callsign) ) { - break; - } - itype=2; - } - ihash=nhash(callsign,strlen(callsign),(uint32_t)146); - if(strncmp(hashtab+ihash*13,callsign,13)==0) { - if( (itype==1 && strncmp(loctab+ihash*5,grid,5)==0) || - (itype==2) ) { - not_decoded=0; - osd_decode =1; - } - } - } - } - - } - idt++; - if( quickmode ) break; - } - ib++; - } - - if( !not_decoded ) { - ndecodes_pass++; - - for(i=0; i<11; i++) { - - if( decdata[i]>127 ) { - message[i]=decdata[i]-256; - } else { - message[i]=decdata[i]; - } - - } - - // Unpack the decoded message, update the hashtable, apply - // sanity checks on grid and power, and return - // call_loc_pow string and also callsign (for de-duping). - noprint=unpk_(message,hashtab,loctab,call_loc_pow,callsign); - if( subtraction && !noprint ) { - if( get_wspr_channel_symbols(call_loc_pow, hashtab, loctab, channel_symbols) ) { - subtract_signal2(idat, qdat, npoints, f1, shift1, drift1, channel_symbols); - if(!osd_decode) nhardmin=count_hard_errors(symbols,channel_symbols); - } else { - break; - } - } - - // Remove dupes (same callsign and freq within 4 Hz) - int dupe=0; - for (i=0; i decodes[k+1].freq) { - temp = decodes[k]; - decodes[k]=decodes[k+1];; - decodes[k+1] = temp; - } - } - } - - for (i=0; i\n"); - - fftwf_free(fftin); - fftwf_free(fftout); - - if ((fp_fftwf_wisdom_file = fopen(wisdom_fname, "w"))) { - fftwf_export_wisdom_to_file(fp_fftwf_wisdom_file); - fclose(fp_fftwf_wisdom_file); - } - - ttotal += (float)(clock()-t00)/CLOCKS_PER_SEC; - - fprintf(ftimer,"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n\n", - treadwav,tcandidates,tsync0,tsync1,tsync2,tfano,tosd,ttotal); - - fprintf(ftimer,"Code segment Seconds Frac\n"); - fprintf(ftimer,"-----------------------------------\n"); - fprintf(ftimer,"readwavfile %7.2f %7.2f\n",treadwav,treadwav/ttotal); - fprintf(ftimer,"Coarse DT f0 f1 %7.2f %7.2f\n",tcandidates, - tcandidates/ttotal); - fprintf(ftimer,"sync_and_demod(0) %7.2f %7.2f\n",tsync0,tsync0/ttotal); - fprintf(ftimer,"sync_and_demod(1) %7.2f %7.2f\n",tsync1,tsync1/ttotal); - fprintf(ftimer,"sync_and_demod(2) %7.2f %7.2f\n",tsync2,tsync2/ttotal); - fprintf(ftimer,"Stack/Fano decoder %7.2f %7.2f\n",tfano,tfano/ttotal); - fprintf(ftimer,"OSD decoder %7.2f %7.2f\n",tosd,tosd/ttotal); - fprintf(ftimer,"-----------------------------------\n"); - fprintf(ftimer,"Total %7.2f %7.2f\n",ttotal,1.0); - - fclose(fall_wspr); - fclose(fwsprd); - // fclose(fdiag); - fclose(ftimer); - fftwf_destroy_plan(PLAN1); - fftwf_destroy_plan(PLAN2); - fftwf_destroy_plan(PLAN3); - - if( usehashtable ) { - fhash=fopen(hash_fname,"w"); - for (i=0; i<32768; i++) { - if( strncmp(hashtab+i*13,"\0",1) != 0 ) { - fprintf(fhash,"%5d %s %s\n",i,hashtab+i*13,loctab+i*5); - } - } - fclose(fhash); - } - - free(hashtab); - free(loctab); - free(symbols); - free(decdata); - free(channel_symbols); - free(callsign); - free(call_loc_pow); - free(idat); - free(qdat); - free(stack); - - return 0; -} +/* + This file is part of program wsprd, a detector/demodulator/decoder + for the Weak Signal Propagation Reporter (WSPR) mode. + + File name: wsprd.c + + Copyright 2001-2018, Joe Taylor, K1JT + + Much of the present code is based on work by Steven Franke, K9AN, + which in turn was based on earlier work by K1JT. + + Copyright 2014-2018, Steven Franke, K9AN + + License: GNU GPL v3 + + 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 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fano.h" +#include "jelinek.h" +#include "nhash.h" +#include "wsprd_utils.h" +#include "wsprsim_utils.h" + +#define max(x,y) ((x) > (y) ? (x) : (y)) + +extern void osdwspr_ (float [], unsigned char [], int *, unsigned char [], int *, float *); + +// Possible PATIENCE options: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT, +// FFTW_MEASURE, FFTW_PATIENT, FFTW_EXHAUSTIVE +#define PATIENCE FFTW_ESTIMATE +fftwf_plan PLAN1,PLAN2,PLAN3; + +unsigned char pr3[162]= +{1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, + 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, + 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, + 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, + 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, + 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, + 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, + 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, + 0,0}; + +int printdata=0; + +//*************************************************************************** +unsigned long readc2file(char *ptr_to_infile, float *idat, float *qdat, + double *freq, int *wspr_type) +{ + float *buffer; + double dfreq; + int i,ntrmin; + char c2file[15]; + size_t nr; + FILE* fp; + + fp = fopen(ptr_to_infile,"rb"); + if (fp == NULL) { + fprintf(stderr, "Cannot open data file '%s': %s\n", ptr_to_infile, strerror(errno)); + return 1; + } + nr=fread(c2file,sizeof(char),14,fp); + nr=fread(&ntrmin,sizeof(int),1,fp); + nr=fread(&dfreq,sizeof(double),1,fp); + *freq=dfreq; + + buffer=calloc(2*65536,sizeof(float)); + nr=fread(buffer,sizeof(float),2*45000,fp); + fclose(fp); + + *wspr_type=ntrmin; + + for(i=0; i<45000; i++) { + idat[i]=buffer[2*i]; + qdat[i]=-buffer[2*i+1]; + } + free(buffer); + + if( nr == 2*45000 ) { + return (unsigned long) nr/2; + } else { + return 1; + } +} + +//*************************************************************************** +unsigned long readwavfile(char *ptr_to_infile, int ntrmin, float *idat, float *qdat ) +{ + size_t i, j, npoints, nr; + int nfft1, nfft2, nh2, i0; + double df; + + nfft2=46080; //this is the number of downsampled points that will be returned + nh2=nfft2/2; + + if( ntrmin == 2 ) { + nfft1=nfft2*32; //need to downsample by a factor of 32 + df=12000.0/nfft1; + i0=1500.0/df+0.5; + npoints=114*12000; + } else if ( ntrmin == 15 ) { + nfft1=nfft2*8*32; + df=12000.0/nfft1; + i0=(1500.0+112.5)/df+0.5; + npoints=8*114*12000; + } else { + fprintf(stderr,"This should not happen\n"); + return 1; + } + + float *realin; + fftwf_complex *fftin, *fftout; + + FILE *fp; + short int *buf2; + + fp = fopen(ptr_to_infile,"rb"); + if (fp == NULL) { + fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile); + return 1; + } + + buf2 = calloc(npoints,sizeof(short int)); + nr=fread(buf2,2,22,fp); //Read and ignore header + nr=fread(buf2,2,npoints,fp); //Read raw data + fclose(fp); + if( nr == 0 ) { + free(buf2); + fprintf(stderr, "No data in file '%s'\n", ptr_to_infile); + return 1; + } + + realin=(float*) fftwf_malloc(sizeof(float)*nfft1); + fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*(nfft1/2+1)); + PLAN1 = fftwf_plan_dft_r2c_1d(nfft1, realin, fftout, PATIENCE); + + for (i=0; i(size_t)nh2 ) j=j-nfft2; + fftin[i][0]=fftout[j][0]; + fftin[i][1]=fftout[j][1]; + } + + fftwf_free(fftout); + fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*nfft2); + PLAN2 = fftwf_plan_dft_1d(nfft2, fftin, fftout, FFTW_BACKWARD, PATIENCE); + fftwf_execute(PLAN2); + + for (i=0; i<(size_t)nfft2; i++) { + idat[i]=fftout[i][0]/1000.0; + qdat[i]=fftout[i][1]/1000.0; + } + + fftwf_free(fftin); + fftwf_free(fftout); + return nfft2; +} + +//*************************************************************************** +void sync_and_demodulate(float *id, float *qd, long np, + unsigned char *symbols, float *f1, int ifmin, int ifmax, float fstep, + int *shift1, int lagmin, int lagmax, int lagstep, + float *drift1, int symfac, float *sync, int mode) +{ + /*********************************************************************** + * mode = 0: no frequency or drift search. find best time lag. * + * 1: no time lag or drift search. find best frequency. * + * 2: no frequency or time lag search. calculate soft-decision * + * symbols using passed frequency and shift. * + ************************************************************************/ + + static float fplast=-10000.0; + static float dt=1.0/375.0, df=375.0/256.0; + static float pi=3.14159265358979323846; + float twopidt, df15=df*1.5, df05=df*0.5; + + int i, j, k, lag; + float i0[162],q0[162],i1[162],q1[162],i2[162],q2[162],i3[162],q3[162]; + float p0,p1,p2,p3,cmet,totp,syncmax,fac; + float c0[256],s0[256],c1[256],s1[256],c2[256],s2[256],c3[256],s3[256]; + float dphi0, cdphi0, sdphi0, dphi1, cdphi1, sdphi1, dphi2, cdphi2, sdphi2, + dphi3, cdphi3, sdphi3; + float f0=0.0, fp, ss, fbest=0.0, fsum=0.0, f2sum=0.0, fsymb[162]; + int best_shift = 0, ifreq; + + syncmax=-1e30; + if( mode == 0 ) {ifmin=0; ifmax=0; fstep=0.0; f0=*f1;} + if( mode == 1 ) {lagmin=*shift1;lagmax=*shift1;f0=*f1;} + if( mode == 2 ) {lagmin=*shift1;lagmax=*shift1;ifmin=0;ifmax=0;f0=*f1;} + + twopidt=2*pi*dt; + for(ifreq=ifmin; ifreq<=ifmax; ifreq++) { + f0=*f1+ifreq*fstep; + for(lag=lagmin; lag<=lagmax; lag=lag+lagstep) { + ss=0.0; + totp=0.0; + for (i=0; i<162; i++) { + fp = f0 + (*drift1/2.0)*((float)i-81.0)/81.0; + if( i==0 || (fp != fplast) ) { // only calculate sin/cos if necessary + dphi0=twopidt*(fp-df15); + cdphi0=cos(dphi0); + sdphi0=sin(dphi0); + + dphi1=twopidt*(fp-df05); + cdphi1=cos(dphi1); + sdphi1=sin(dphi1); + + dphi2=twopidt*(fp+df05); + cdphi2=cos(dphi2); + sdphi2=sin(dphi2); + + dphi3=twopidt*(fp+df15); + cdphi3=cos(dphi3); + sdphi3=sin(dphi3); + + c0[0]=1; s0[0]=0; + c1[0]=1; s1[0]=0; + c2[0]=1; s2[0]=0; + c3[0]=1; s3[0]=0; + + for (j=1; j<256; j++) { + c0[j]=c0[j-1]*cdphi0 - s0[j-1]*sdphi0; + s0[j]=c0[j-1]*sdphi0 + s0[j-1]*cdphi0; + c1[j]=c1[j-1]*cdphi1 - s1[j-1]*sdphi1; + s1[j]=c1[j-1]*sdphi1 + s1[j-1]*cdphi1; + c2[j]=c2[j-1]*cdphi2 - s2[j-1]*sdphi2; + s2[j]=c2[j-1]*sdphi2 + s2[j-1]*cdphi2; + c3[j]=c3[j-1]*cdphi3 - s3[j-1]*sdphi3; + s3[j]=c3[j-1]*sdphi3 + s3[j-1]*cdphi3; + } + fplast = fp; + } + + i0[i]=0.0; q0[i]=0.0; + i1[i]=0.0; q1[i]=0.0; + i2[i]=0.0; q2[i]=0.0; + i3[i]=0.0; q3[i]=0.0; + + for (j=0; j<256; j++) { + k=lag+i*256+j; + if( (k>0) && (k syncmax ) { //Save best parameters + syncmax=ss; + best_shift=lag; + fbest=f0; + } + } // lag loop + } //freq loop + + if( mode <=1 ) { //Send best params back to caller + *sync=syncmax; + *shift1=best_shift; + *f1=fbest; + return; + } + + if( mode == 2 ) { + *sync=syncmax; + for (i=0; i<162; i++) { //Normalize the soft symbols + fsum=fsum+fsymb[i]/162.0; + f2sum=f2sum+fsymb[i]*fsymb[i]/162.0; + } + fac=sqrt(f2sum-fsum*fsum); + for (i=0; i<162; i++) { + fsymb[i]=symfac*fsymb[i]/fac; + if( fsymb[i] > 127) fsymb[i]=127.0; + if( fsymb[i] < -128 ) fsymb[i]=-128.0; + symbols[i]=fsymb[i] + 128; + } + return; + } + return; +} + +void noncoherent_sequence_detection(float *id, float *qd, long np, + unsigned char *symbols, float *f1, int *shift1, + float *drift1, int symfac, int *nblocksize, int *bitmetric) +{ + /************************************************************************ + * Noncoherent sequence detection for wspr. * + * Allowed block lengths are nblock=1,2,3,6, or 9 symbols. * + * Longer block lengths require longer channel coherence time. * + * The whole block is estimated at once. * + * nblock=1 corresponds to noncoherent detection of individual symbols * + * like the original wsprd symbol demodulator. * + ************************************************************************/ + static float fplast=-10000.0; + static float dt=1.0/375.0, df=375.0/256.0; + static float pi=3.14159265358979323846; + float twopidt, df15=df*1.5, df05=df*0.5; + + int i, j, k, lag, itone, ib, b, nblock, nseq, imask; + float xi[512],xq[512]; + float is[4][162],qs[4][162],cf[4][162],sf[4][162],cm,sm,cmp,smp; + float p[512],fac,xm1,xm0; + float c0[257],s0[257],c1[257],s1[257],c2[257],s2[257],c3[257],s3[257]; + float dphi0, cdphi0, sdphi0, dphi1, cdphi1, sdphi1, dphi2, cdphi2, sdphi2, + dphi3, cdphi3, sdphi3; + float f0, fp, fsum=0.0, f2sum=0.0, fsymb[162]; + + twopidt=2*pi*dt; + f0=*f1; + lag=*shift1; + nblock=*nblocksize; + nseq=1<0) && (k>(nblock-1-ib); + itone=pr3[i+ib]+2*b; + xi[j]=xi[j]+is[itone][i+ib]*cm + qs[itone][i+ib]*sm; + xq[j]=xq[j]+qs[itone][i+ib]*cm - is[itone][i+ib]*sm; + cmp=cf[itone][i+ib]*cm - sf[itone][i+ib]*sm; + smp=sf[itone][i+ib]*cm + cf[itone][i+ib]*sm; + cm=cmp; sm=smp; + } + p[j]=xi[j]*xi[j]+xq[j]*xq[j]; + p[j]=sqrt(p[j]); + } + for (ib=0; ib xm1) xm1=p[j]; + } + if((j & imask)==0) { + if(p[j]>xm0) xm0=p[j]; + } + } + fsymb[i+ib]=xm1-xm0; + if( bitbybit == 1 ) { + fsymb[i+ib]=fsymb[i+ib]/(xm1 > xm0 ? xm1 : xm0); + } + } + } + for (i=0; i<162; i++) { //Normalize the soft symbols + fsum=fsum+fsymb[i]/162.0; + f2sum=f2sum+fsymb[i]*fsymb[i]/162.0; + } + fac=sqrt(f2sum-fsum*fsum); + for (i=0; i<162; i++) { + fsymb[i]=symfac*fsymb[i]/fac; + if( fsymb[i] > 127) fsymb[i]=127.0; + if( fsymb[i] < -128 ) fsymb[i]=-128.0; + symbols[i]=fsymb[i] + 128; + } + return; +} + +/*************************************************************************** + symbol-by-symbol signal subtraction + ****************************************************************************/ +void subtract_signal(float *id, float *qd, long np, + float f0, int shift0, float drift0, unsigned char* channel_symbols) +{ + float dt=1.0/375.0, df=375.0/256.0; + int i, j, k; + float pi=4.*atan(1.0),twopidt, fp; + + float i0,q0; + float c0[256],s0[256]; + float dphi, cdphi, sdphi; + + twopidt=2*pi*dt; + + for (i=0; i<162; i++) { + fp = f0 + ((float)drift0/2.0)*((float)i-81.0)/81.0; + + dphi=twopidt*(fp+((float)channel_symbols[i]-1.5)*df); + cdphi=cos(dphi); + sdphi=sin(dphi); + + c0[0]=1; s0[0]=0; + + for (j=1; j<256; j++) { + c0[j]=c0[j-1]*cdphi - s0[j-1]*sdphi; + s0[j]=c0[j-1]*sdphi + s0[j-1]*cdphi; + } + + i0=0.0; q0=0.0; + + for (j=0; j<256; j++) { + k=shift0+i*256+j; + if( (k>0) & (k0) & (k0) && (k(nsig-1-nfilt/2) ) { + norm=partialsum[nfilt/2+nsig-1-i]; + } else { + norm=1.0; + } + k=shift0+i; + j=i+nfilt; + if( (k>0) && (k=2 ? 1:0; + } + deinterleave(cw); + nerrors=0; + for (i=0; i<162; i++) { + is = symbols[i] > 127 ? 1:0; + nerrors = nerrors + (is == cw[i] ? 0:1); + } + return nerrors; +} + +//*************************************************************************** +void usage(void) +{ + printf("Usage: wsprd [options...] infile\n"); + printf(" infile must have suffix .wav or .c2\n"); + printf("\n"); + printf("Options:\n"); + printf(" -a path to writeable data files, default=\".\"\n"); + printf(" -B disable block demodulation - use single-symbol noncoherent demod\n"); + printf(" -c write .c2 file at the end of the first pass\n"); + printf(" -C maximum number of decoder cycles per bit, default 10000\n"); + printf(" -d deeper search. Slower, a few more decodes\n"); + printf(" -e x (x is transceiver dial frequency error in Hz)\n"); + printf(" -f x (x is transceiver dial frequency in MHz)\n"); + printf(" -H do not use (or update) the hash table\n"); + printf(" -J use the stack decoder instead of Fano decoder\n"); + printf(" -m decode wspr-15 .wav file\n"); + printf(" -o n (0<=n<=5), decoding depth for OSD, default is disabled\n"); + printf(" -q quick mode - doesn't dig deep for weak signals\n"); + printf(" -s single pass mode, no subtraction (same as original wsprd)\n"); + printf(" -v verbose mode (shows dupes)\n"); + printf(" -w wideband mode - decode signals within +/- 150 Hz of center\n"); + printf(" -z x (x is fano metric table bias, default is 0.45)\n"); +} + +//*************************************************************************** +int main(int argc, char *argv[]) +{ + char cr[] = "(C) 2018, Steven Franke - K9AN"; + (void)cr; + extern char *optarg; + extern int optind; + int i,j,k; + unsigned char *symbols, *decdata, *channel_symbols, *apmask, *cw; + signed char message[]={-9,13,-35,123,57,-39,64,0,0,0,0}; + char *callsign, *grid, *call_loc_pow; + char *ptr_to_infile,*ptr_to_infile_suffix; + char *data_dir="."; + char wisdom_fname[200],all_fname[200],spots_fname[200]; + char timer_fname[200],hash_fname[200]; + char uttime[5],date[7]; + int c,delta,maxpts=65536,verbose=0,quickmode=0,more_candidates=0, stackdecoder=0; + int usehashtable=1,wspr_type=2, ipass, nblocksize; + int nhardmin,ihash; + int writec2=0,maxdrift; + int shift1, lagmin, lagmax, lagstep, ifmin, ifmax, not_decoded; + unsigned int nbits=81, stacksize=200000; + struct snode * stack=NULL; + unsigned int npoints, cycles, maxnp, metric; + float df=375.0/256.0/2; + float fsymbs[162]; + float dt=1.0/375.0, dt_print; + double dialfreq_cmdline=0.0, dialfreq, freq_print; + double dialfreq_error=0.0; + float fmin=-110, fmax=110; + float f1, fstep, sync1, drift1; + float dmin; + float psavg[512]; + float *idat, *qdat; + clock_t t0,t00; + float tfano=0.0,treadwav=0.0,tcandidates=0.0,tsync0=0.0; + float tsync1=0.0,tsync2=0.0,tosd=0.0,ttotal=0.0; + + struct cand { float freq; float snr; int shift; float drift; float sync; }; + struct cand candidates[200]; + + struct result { char date[7]; char time[5]; float sync; float snr; + float dt; double freq; char message[23]; float drift; + unsigned int cycles; int jitter; int blocksize; unsigned int metric; + int nhardmin; int ipass; int decodetype;}; + struct result decodes[50]; + + char *hashtab; + hashtab=calloc(32768*13,sizeof(char)); + char *loctab; + loctab=calloc(32768*5,sizeof(char)); + int nh; + symbols=calloc(nbits*2,sizeof(unsigned char)); + apmask=calloc(162,sizeof(unsigned char)); + cw=calloc(162,sizeof(unsigned char)); + decdata=calloc(11,sizeof(unsigned char)); + channel_symbols=calloc(nbits*2,sizeof(unsigned char)); + callsign=calloc(13,sizeof(char)); + grid=calloc(5,sizeof(char)); + call_loc_pow=calloc(23,sizeof(char)); + float allfreqs[100]; + char allcalls[100][13]; + for (i=0; i<100; i++) allfreqs[i]=0.0; + memset(allcalls,0,sizeof(char)*100*13); + + int uniques=0, noprint=0, ndecodes_pass=0; + + // Parameters used for performance-tuning: + unsigned int maxcycles=10000; //Decoder timeout limit + float minsync1=0.10; //First sync limit + float minsync2=0.12; //Second sync limit + int iifac=8; //Step size in final DT peakup + int symfac=50; //Soft-symbol normalizing factor + int subtraction=1; + int npasses=3; + int ndepth=-1; //Depth for OSD + + float minrms=52.0 * (symfac/64.0); //Final test for plausible decoding + delta=60; //Fano threshold step + float bias=0.45; //Fano metric bias (used for both Fano and stack algorithms) + + t00=clock(); + fftwf_complex *fftin, *fftout; +#include "./metric_tables.c" + + int mettab[2][256]; + + idat=calloc(maxpts,sizeof(float)); + qdat=calloc(maxpts,sizeof(float)); + + while ( (c = getopt(argc, argv, "a:BcC:de:f:HJmo:qstwvz:")) !=-1 ) { + switch (c) { + case 'a': + data_dir = optarg; + break; + case 'B': + npasses=2; + break; + case 'c': + writec2=1; + break; + case 'C': + maxcycles=(unsigned int) strtoul(optarg,NULL,10); + break; + case 'd': + more_candidates=1; + break; + case 'e': + dialfreq_error = strtod(optarg,NULL); // units of Hz + // dialfreq_error = dial reading - actual, correct frequency + break; + case 'f': + dialfreq_cmdline = strtod(optarg,NULL); // units of MHz + break; + case 'H': + usehashtable = 0; + break; + case 'J': //Stack (Jelinek) decoder, Fano decoder is the default + stackdecoder = 1; + break; + case 'm': //15-minute wspr mode + wspr_type = 15; + break; + case 'o': //use ordered-statistics-decoder + ndepth=(int) strtol(optarg,NULL,10); + break; + case 'q': //no shift jittering + quickmode = 1; + break; + case 's': //single pass mode + subtraction = 0; + npasses = 1; + break; + case 'v': + verbose = 1; + break; + case 'w': + fmin=-150.0; + fmax=150.0; + break; + case 'z': + bias=strtod(optarg,NULL); //fano metric bias (default is 0.45) + break; + case '?': + usage(); + return 1; + } + } + + if( access(data_dir, R_OK | W_OK)) { + fprintf(stderr, "Error: inaccessible data directory: '%s'\n", data_dir); + usage(); + return EXIT_FAILURE; + } + + if( optind+1 > argc) { + usage(); + return 1; + } else { + ptr_to_infile=argv[optind]; + } + + if( stackdecoder ) { + stack=calloc(stacksize,sizeof(struct snode)); + } + + // setup metric table + for(i=0; i<256; i++) { + mettab[0][i]=round( 10*(metric_tables[2][i]-bias) ); + mettab[1][i]=round( 10*(metric_tables[2][255-i]-bias) ); + } + + FILE *fp_fftwf_wisdom_file, *fall_wspr, *fwsprd, *fhash, *ftimer; + strcpy(wisdom_fname,"."); + strcpy(all_fname,"."); + strcpy(spots_fname,"."); + strcpy(timer_fname,"."); + strcpy(hash_fname,"."); + if(data_dir != NULL) { + strncpy(wisdom_fname,data_dir, sizeof wisdom_fname); + strncpy(all_fname,data_dir, sizeof all_fname); + strncpy(spots_fname,data_dir, sizeof spots_fname); + strncpy(timer_fname,data_dir, sizeof timer_fname); + strncpy(hash_fname,data_dir, sizeof hash_fname); + } + strncat(wisdom_fname,"/wspr_wisdom.dat",20); + strncat(all_fname,"/ALL_WSPR.TXT",20); + strncat(spots_fname,"/wspr_spots.txt",20); + strncat(timer_fname,"/wspr_timer.out",20); + strncat(hash_fname,"/hashtable.txt",20); + if ((fp_fftwf_wisdom_file = fopen(wisdom_fname, "r"))) { //Open FFTW wisdom + fftwf_import_wisdom_from_file(fp_fftwf_wisdom_file); + fclose(fp_fftwf_wisdom_file); + } + + fall_wspr=fopen(all_fname,"a"); + fwsprd=fopen(spots_fname,"w"); + // FILE *fdiag; + // fdiag=fopen("wsprd_diag","a"); + + if((ftimer=fopen(timer_fname,"r"))) { + //Accumulate timing data + int nr=fscanf(ftimer,"%f %f %f %f %f %f %f %f", + &treadwav,&tcandidates,&tsync0,&tsync1,&tsync2,&tfano,&tosd,&ttotal); + fclose(ftimer); + if(nr == 0) fprintf(stderr, "Empty timer file: '%s'\n", timer_fname); + } + ftimer=fopen(timer_fname,"w"); + + if( strstr(ptr_to_infile,".wav") ) { + ptr_to_infile_suffix=strstr(ptr_to_infile,".wav"); + + t0 = clock(); + npoints=readwavfile(ptr_to_infile, wspr_type, idat, qdat); + treadwav += (float)(clock()-t0)/CLOCKS_PER_SEC; + + if( npoints == 1 ) { + return 1; + } + dialfreq=dialfreq_cmdline - (dialfreq_error*1.0e-06); + } else if ( strstr(ptr_to_infile,".c2") !=0 ) { + ptr_to_infile_suffix=strstr(ptr_to_infile,".c2"); + npoints=readc2file(ptr_to_infile, idat, qdat, &dialfreq, &wspr_type); + if( npoints == 1 ) { + return 1; + } + dialfreq -= (dialfreq_error*1.0e-06); + } else { + printf("Error: Failed to open %s\n",ptr_to_infile); + printf("WSPR file must have suffix .wav or .c2\n"); + return 1; + } + + // Parse date and time from given filename + strncpy(date,ptr_to_infile_suffix-11,6); + strncpy(uttime,ptr_to_infile_suffix-4,4); + date[6]='\0'; + uttime[4]='\0'; + + // Do windowed ffts over 2 symbols, stepped by half symbols + int nffts=4*floor(npoints/512)-1; + fftin=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*512); + fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*512); + PLAN3 = fftwf_plan_dft_1d(512, fftin, fftout, FFTW_FORWARD, PATIENCE); + + float ps[512][nffts]; + float w[512]; + for(i=0; i<512; i++) { + w[i]=sin(0.006147931*i); + } + + if( usehashtable ) { + char line[80], hcall[13], hgrid[5]; + if( (fhash=fopen(hash_fname,"r+")) ) { + while (fgets(line, sizeof(line), fhash) != NULL) { + hgrid[0]='\0'; + sscanf(line,"%d %s %s",&nh,hcall,hgrid); + strcpy(hashtab+nh*13,hcall); + if(strlen(hgrid)>0) strcpy(loctab+nh*5,hgrid); + } + } else { + fhash=fopen(hash_fname,"w+"); + } + fclose(fhash); + } + + //*************** main loop starts here ***************** + for (ipass=0; ipass2) ipass=2; + if(ipass < 2) { + nblocksize=1; + maxdrift=4; + minsync2=0.12; + } + if(ipass == 2 ) { + nblocksize=4; // try 3 blocksizes plus bitbybit normalization + maxdrift=0; // no drift for smaller frequency estimator variance + minsync2=0.10; + } + ndecodes_pass=0; // still needed? + + for (i=0; i511 ) + k=k-512; + ps[j][i]=fftout[k][0]*fftout[k][0]+fftout[k][1]*fftout[k][1]; + } + } + + // Compute average spectrum + for (i=0; i<512; i++) psavg[i]=0.0; + for (i=0; ismspec[j-1]) && + (smspec[j]>smspec[j+1]) && + (npk<200); + if ( candidate ) { + candidates[npk].freq = (j-205)*df; + candidates[npk].snr = 10*log10(smspec[j])-snr_scaling_factor; + npk++; + } + } + if( more_candidates ) { + for(j=0; j<411; j=j+3) { + candidate = (smspec[j]>min_snr) && (npk<200); + if ( candidate ) { + candidates[npk].freq = (j-205)*df; + candidates[npk].snr = 10*log10(smspec[j])-snr_scaling_factor; + npk++; + } + } + } + + // Compute corrected fmin, fmax, accounting for dial frequency error + fmin += dialfreq_error; // dialfreq_error is in units of Hz + fmax += dialfreq_error; + + // Don't waste time on signals outside of the range [fmin,fmax]. + i=0; + for( j=0; j= fmin && candidates[j].freq <= fmax ) { + candidates[i]=candidates[j]; + i++; + } + } + npk=i; + + // bubble sort on snr + int pass; + struct cand tmp; + for (pass = 1; pass <= npk - 1; pass++) { + for (k = 0; k < npk - pass ; k++) { + if (candidates[k].snr < candidates[k+1].snr) { + tmp = candidates[k]; + candidates[k]=candidates[k+1]; + candidates[k+1] = tmp; + } + } + } + + t0=clock(); + + /* Make coarse estimates of shift (DT), freq, and drift + + * Look for time offsets up to +/- 8 symbols (about +/- 5.4 s) relative + to nominal start time, which is 2 seconds into the file + + * Calculates shift relative to the beginning of the file + + * Negative shifts mean that signal started before start of file + + * The program prints DT = shift-2 s + + * Shifts that cause sync vector to fall off of either end of the data + vector are accommodated by "partial decoding", such that missing + symbols produce a soft-decision symbol value of 128 + + * The frequency drift model is linear, deviation of +/- drift/2 over the + span of 162 symbols, with deviation equal to 0 at the center of the + signal vector. + */ + + int idrift,ifr,if0,ifd,k0; + int kindex; + float smax,ss,pow,p0,p1,p2,p3; + for(j=0; j= 0 && kindex < nffts ) { + p0=ps[ifd-3][kindex]; + p1=ps[ifd-1][kindex]; + p2=ps[ifd+1][kindex]; + p3=ps[ifd+3][kindex]; + + p0=sqrt(p0); + p1=sqrt(p1); + p2=sqrt(p2); + p3=sqrt(p3); + + ss=ss+(2*pr3[k]-1)*((p1+p3)-(p0+p2)); + pow=pow+p0+p1+p2+p3; + } + } + sync1=ss/pow; + if( sync1 > smax ) { //Save coarse parameters + smax=sync1; + candidates[j].shift=128*(k0+1); + candidates[j].drift=idrift; + candidates[j].freq=(ifr-256)*df; + candidates[j].sync=sync1; + } + } + } + } + } + tcandidates += (float)(clock()-t0)/CLOCKS_PER_SEC; + + /* + Refine the estimates of freq, shift using sync as a metric. + Sync is calculated such that it is a float taking values in the range + [0.0,1.0]. + + Function sync_and_demodulate has three modes of operation + mode is the last argument: + + 0 = no frequency or drift search. find best time lag. + 1 = no time lag or drift search. find best frequency. + 2 = no frequency or time lag search. Calculate soft-decision + symbols using passed frequency and shift. + + NB: best possibility for OpenMP may be here: several worker threads + could each work on one candidate at a time. + */ + for (j=0; jminsync1 continue + fstep=0.0; ifmin=0; ifmax=0; + lagmin=shift1-128; + lagmax=shift1+128; + lagstep=64; + t0 = clock(); + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0); + tsync0 += (float)(clock()-t0)/CLOCKS_PER_SEC; + + fstep=0.25; ifmin=-2; ifmax=2; + t0 = clock(); + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1); + + if(ipass < 2) { + // refine drift estimate + fstep=0.0; ifmin=0; ifmax=0; + float driftp,driftm,syncp,syncm; + driftp=drift1+0.5; + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &driftp, symfac, &syncp, 1); + + driftm=drift1-0.5; + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &driftm, symfac, &syncm, 1); + + if(syncp>sync1) { + drift1=driftp; + sync1=syncp; + } else if (syncm>sync1) { + drift1=driftm; + sync1=syncm; + } + } + tsync1 += (float)(clock()-t0)/CLOCKS_PER_SEC; + + // fine-grid lag and freq search + if( sync1 > minsync1 ) { + + lagmin=shift1-32; lagmax=shift1+32; lagstep=16; + t0 = clock(); + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0); + tsync0 += (float)(clock()-t0)/CLOCKS_PER_SEC; + + // fine search over frequency + fstep=0.05; ifmin=-2; ifmax=2; + t0 = clock(); + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1); + tsync1 += (float)(clock()-t0)/CLOCKS_PER_SEC; + + candidates[j].freq=f1; + candidates[j].shift=shift1; + candidates[j].drift=drift1; + candidates[j].sync=sync1; + } + } + + int nwat=0; + int idupe; + for ( j=0; j candidates[k].sync) candidates[k]=candidates[j]; + } else if ( candidates[j].sync > minsync2 ) { + candidates[nwat]=candidates[j]; + nwat++; + } + } + + int idt, ii, jittered_shift; + float y,sq,rms; + int ib, blocksize, bitmetric; + int n1,n2,n3,nadd,nu,ntype; + int osd_decode; + for (j=0; j minrms) { + deinterleave(symbols); + t0 = clock(); + + if ( stack ) { + not_decoded = jelinek(&metric, &cycles, decdata, symbols, nbits, + stacksize, stack, mettab,maxcycles); + } else { + not_decoded = fano(&metric,&cycles,&maxnp,decdata,symbols,nbits, + mettab,delta,maxcycles); + } + + tfano += (float)(clock()-t0)/CLOCKS_PER_SEC; + + if( (ndepth >= 0) && not_decoded ) { + for(i=0; i<162; i++) { + fsymbs[i]=symbols[i]-128.0; + } + t0 = clock(); + osdwspr_(fsymbs,apmask,&ndepth,cw,&nhardmin,&dmin); + tosd += (float)(clock()-t0)/CLOCKS_PER_SEC; + + for(i=0; i<162; i++) { + symbols[i]=255*cw[i]; + } + fano(&metric,&cycles,&maxnp,decdata,symbols,nbits, + mettab,delta,maxcycles); + for(i=0; i<11; i++) { + if( decdata[i]>127 ) { + message[i]=decdata[i]-256; + } else { + message[i]=decdata[i]; + } + } + unpack50(message,&n1,&n2); + if( !unpackcall(n1,callsign) ) break; + callsign[12]=0; + if( !unpackgrid(n2, grid) ) break; + grid[4]=0; + ntype = (n2&127) - 64; + int itype; + if( (ntype >= 0) && (ntype <= 62) ) { + nu = ntype%10; + itype=1; + if( !(nu == 0 || nu == 3 || nu == 7) ) { + nadd=nu; + if( nu > 3 ) nadd=nu-3; + if( nu > 7 ) nadd=nu-7; + n3=n2/128+32768*(nadd-1); + if( !unpackpfx(n3,callsign) ) { + break; + } + itype=2; + } + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); + if(strncmp(hashtab+ihash*13,callsign,13)==0) { + if( (itype==1 && strncmp(loctab+ihash*5,grid,5)==0) || + (itype==2) ) { + not_decoded=0; + osd_decode =1; + } + } + } + } + + } + idt++; + if( quickmode ) break; + } + ib++; + } + + if( !not_decoded ) { + ndecodes_pass++; + + for(i=0; i<11; i++) { + + if( decdata[i]>127 ) { + message[i]=decdata[i]-256; + } else { + message[i]=decdata[i]; + } + + } + + // Unpack the decoded message, update the hashtable, apply + // sanity checks on grid and power, and return + // call_loc_pow string and also callsign (for de-duping). + noprint=unpk_(message,hashtab,loctab,call_loc_pow,callsign); + if( subtraction && !noprint ) { + if( get_wspr_channel_symbols(call_loc_pow, hashtab, loctab, channel_symbols) ) { + subtract_signal2(idat, qdat, npoints, f1, shift1, drift1, channel_symbols); + if(!osd_decode) nhardmin=count_hard_errors(symbols,channel_symbols); + } else { + break; + } + } + + // Remove dupes (same callsign and freq within 4 Hz) + int dupe=0; + for (i=0; i decodes[k+1].freq) { + temp = decodes[k]; + decodes[k]=decodes[k+1];; + decodes[k+1] = temp; + } + } + } + + for (i=0; i\n"); + + fftwf_free(fftin); + fftwf_free(fftout); + + if ((fp_fftwf_wisdom_file = fopen(wisdom_fname, "w"))) { + fftwf_export_wisdom_to_file(fp_fftwf_wisdom_file); + fclose(fp_fftwf_wisdom_file); + } + + ttotal += (float)(clock()-t00)/CLOCKS_PER_SEC; + + fprintf(ftimer,"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n\n", + treadwav,tcandidates,tsync0,tsync1,tsync2,tfano,tosd,ttotal); + + fprintf(ftimer,"Code segment Seconds Frac\n"); + fprintf(ftimer,"-----------------------------------\n"); + fprintf(ftimer,"readwavfile %7.2f %7.2f\n",treadwav,treadwav/ttotal); + fprintf(ftimer,"Coarse DT f0 f1 %7.2f %7.2f\n",tcandidates, + tcandidates/ttotal); + fprintf(ftimer,"sync_and_demod(0) %7.2f %7.2f\n",tsync0,tsync0/ttotal); + fprintf(ftimer,"sync_and_demod(1) %7.2f %7.2f\n",tsync1,tsync1/ttotal); + fprintf(ftimer,"sync_and_demod(2) %7.2f %7.2f\n",tsync2,tsync2/ttotal); + fprintf(ftimer,"Stack/Fano decoder %7.2f %7.2f\n",tfano,tfano/ttotal); + fprintf(ftimer,"OSD decoder %7.2f %7.2f\n",tosd,tosd/ttotal); + fprintf(ftimer,"-----------------------------------\n"); + fprintf(ftimer,"Total %7.2f %7.2f\n",ttotal,1.0); + + fclose(fall_wspr); + fclose(fwsprd); + // fclose(fdiag); + fclose(ftimer); + fftwf_destroy_plan(PLAN1); + fftwf_destroy_plan(PLAN2); + fftwf_destroy_plan(PLAN3); + + if( usehashtable ) { + fhash=fopen(hash_fname,"w"); + for (i=0; i<32768; i++) { + if( strncmp(hashtab+i*13,"\0",1) != 0 ) { + fprintf(fhash,"%5d %s %s\n",i,hashtab+i*13,loctab+i*5); + } + } + fclose(fhash); + } + + free(hashtab); + free(loctab); + free(symbols); + free(decdata); + free(channel_symbols); + free(callsign); + free(call_loc_pow); + free(idat); + free(qdat); + free(stack); + + return 0; +} diff --git a/lib/wsprd/wsprd_stats.txt b/lib/wsprd/wsprd_stats.txt index 88fe6816..0d925aa6 100755 --- a/lib/wsprd/wsprd_stats.txt +++ b/lib/wsprd/wsprd_stats.txt @@ -1,24 +1,24 @@ - Linux Windows -Program Time Decodes Time Decodes -------------------------------------------------- -wsprd (Mar 2013) 2413 1451 2718 1451 - -k9an-wsprd 1800 2122 -k9an_wsprd -q 354 1939 - -wsprd 399 2190 356 2190 -wsprd -q 214 2034 192 2034 - -wsprd* 1240 2215 -wsprd# 1599 2220 - -------------------------------------------------- -* maxcycles=30000 -# maxcycles=20000, iifac=1 -------------------------------------------------- -Test data: 638 *.wav files (recorded by WSJT-X) -------------------------------------------------- -Linux machine: Core 2 Duo, E6750 CPU -Windows machine: 4-Core i5-2500 CPU -wsprd git commit: eecc274 -------------------------------------------------- + Linux Windows +Program Time Decodes Time Decodes +------------------------------------------------- +wsprd (Mar 2013) 2413 1451 2718 1451 + +k9an-wsprd 1800 2122 +k9an_wsprd -q 354 1939 + +wsprd 399 2190 356 2190 +wsprd -q 214 2034 192 2034 + +wsprd* 1240 2215 +wsprd# 1599 2220 + +------------------------------------------------- +* maxcycles=30000 +# maxcycles=20000, iifac=1 +------------------------------------------------- +Test data: 638 *.wav files (recorded by WSJT-X) +------------------------------------------------- +Linux machine: Core 2 Duo, E6750 CPU +Windows machine: 4-Core i5-2500 CPU +wsprd git commit: eecc274 +------------------------------------------------- diff --git a/lib/wsprd/wsprd_utils.c b/lib/wsprd/wsprd_utils.c index daf6a72d..64e809f8 100755 --- a/lib/wsprd/wsprd_utils.c +++ b/lib/wsprd/wsprd_utils.c @@ -1,340 +1,340 @@ -/* - This file is part of program wsprd, a detector/demodulator/decoder - for the Weak Signal Propagation Reporter (WSPR) mode. - - File name: wsprd_utils.c - - Copyright 2001-2015, Joe Taylor, K1JT - - Most of the code is based on work by Steven Franke, K9AN, which - in turn was based on earlier work by K1JT. - - Copyright 2014-2015, Steven Franke, K9AN - - License: GNU GPL v3 - - 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 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ -#include "wsprd_utils.h" - -#ifndef int32_t -#define int32_t int -#endif - -void unpack50( signed char *dat, int32_t *n1, int32_t *n2 ) -{ - int32_t i,i4; - - i=dat[0]; - i4=i&255; - *n1=i4<<20; - - i=dat[1]; - i4=i&255; - *n1=*n1+(i4<<12); - - i=dat[2]; - i4=i&255; - *n1=*n1+(i4<<4); - - i=dat[3]; - i4=i&255; - *n1=*n1+((i4>>4)&15); - *n2=(i4&15)<<18; - - i=dat[4]; - i4=i&255; - *n2=*n2+(i4<<10); - - i=dat[5]; - i4=i&255; - *n2=*n2+(i4<<2); - - i=dat[6]; - i4=i&255; - *n2=*n2+((i4>>6)&3); -} - -int unpackcall( int32_t ncall, char *call ) -{ - char c[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E', - 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', - 'U','V','W','X','Y','Z',' '}; - int32_t n; - int i; - char tmp[7]; - - n=ncall; - strcpy(call,"......"); - if (n < 262177560 ) { - i=n%27+10; - tmp[5]=c[i]; - n=n/27; - i=n%27+10; - tmp[4]=c[i]; - n=n/27; - i=n%27+10; - tmp[3]=c[i]; - n=n/27; - i=n%10; - tmp[2]=c[i]; - n=n/10; - i=n%36; - tmp[1]=c[i]; - n=n/36; - i=n; - tmp[0]=c[i]; - tmp[6]='\0'; - // remove leading whitespace - for(i=0; i<5; i++) { - if( tmp[i] != c[36] ) - break; - } - sprintf(call,"%-6s",&tmp[i]); - // remove trailing whitespace - for(i=0; i<6; i++) { - if( call[i] == c[36] ) { - call[i]='\0'; - } - } - } else { - return 0; - } - return 1; -} - -int unpackgrid( int32_t ngrid, char *grid) -{ - char c[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E', - 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', - 'U','V','W','X','Y','Z',' '}; - int dlat, dlong; - - ngrid=ngrid>>7; - if( ngrid < 32400 ) { - dlat=(ngrid%180)-90; - dlong=(ngrid/180)*2 - 180 + 2; - if( dlong < -180 ) - dlong=dlong+360; - if( dlong > 180 ) - dlong=dlong+360; - int nlong = 60.0*(180.0-dlong)/5.0; - int n1 = nlong/240; - int n2 = (nlong - 240*n1)/24; - grid[0] = c[10+n1]; - grid[2]= c[n2]; - - int nlat = 60.0*(dlat+90)/2.5; - n1 = nlat/240; - n2 = (nlat-240*n1)/24; - grid[1]=c[10+n1]; - grid[3]=c[n2]; - } else { - strcpy(grid,"XXXX"); - return 0; - } - return 1; -} - -int unpackpfx( int32_t nprefix, char *call) -{ - char nc, pfx[4]={'\0'}, tmpcall[7]; - int i; - int32_t n; - - strcpy(tmpcall,call); - if( nprefix < 60000 ) { - // add a prefix of 1 to 3 characters - n=nprefix; - for (i=2; i>=0; i--) { - nc=n%37; - if( (nc >= 0) & (nc <= 9) ) { - pfx[i]=nc+48; - } - else if( (nc >= 10) & (nc <= 35) ) { - pfx[i]=nc+55; - } - else { - pfx[i]=' '; - } - n=n/37; - } - - char * p = strrchr(pfx,' '); - strcpy(call, p ? p + 1 : pfx); - strncat(call,"/",1); - strncat(call,tmpcall,strlen(tmpcall)); - - } else { - // add a suffix of 1 or 2 characters - nc=nprefix-60000; - if( (nc >= 0) & (nc <= 9) ) { - pfx[0]=nc+48; - strcpy(call,tmpcall); - strncat(call,"/",1); - strncat(call,pfx,1); - } - else if( (nc >= 10) & (nc <= 35) ) { - pfx[0]=nc+55; - strcpy(call,tmpcall); - strncat(call,"/",1); - strncat(call,pfx,1); - } - else if( (nc >= 36) & (nc <= 125) ) { - pfx[0]=(nc-26)/10+48; - pfx[1]=(nc-26)%10+48; - strcpy(call,tmpcall); - strncat(call,"/",1); - strncat(call,pfx,2); - } - else { - return 0; - } - } - return 1; -} - -void deinterleave(unsigned char *sym) -{ - unsigned char tmp[162]; - unsigned char p, i, j; - - p=0; - i=0; - while (p<162) { - j=((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32; - if (j < 162 ) { - tmp[p]=sym[j]; - p=p+1; - } - i=i+1; - } - for (i=0; i<162; i++) { - sym[i]=tmp[i]; - } -} - -// used by qsort -int doublecomp(const void* elem1, const void* elem2) -{ - if(*(const double*)elem1 < *(const double*)elem2) - return -1; - return *(const double*)elem1 > *(const double*)elem2; -} - -int floatcomp(const void* elem1, const void* elem2) -{ - if(*(const float*)elem1 < *(const float*)elem2) - return -1; - return *(const float*)elem1 > *(const float*)elem2; -} - -int unpk_(signed char *message, char *hashtab, char *loctab, char *call_loc_pow, char *callsign) -{ - int n1,n2,n3,ndbm,ihash,nadd,noprint=0; - char grid[5],grid6[7],cdbm[4]; - - unpack50(message,&n1,&n2); - if( !unpackcall(n1,callsign) ) return 1; - if( !unpackgrid(n2, grid) ) return 1; - int ntype = (n2&127) - 64; - callsign[12]=0; - grid[4]=0; - - /* - Based on the value of ntype, decide whether this is a Type 1, 2, or - 3 message. - - * Type 1: 6 digit call, grid, power - ntype is positive and is a member - of the set {0,3,7,10,13,17,20...60} - - * Type 2: extended callsign, power - ntype is positive but not - a member of the set of allowed powers - - * Type 3: hash, 6 digit grid, power - ntype is negative. - */ - - if( (ntype >= 0) && (ntype <= 62) ) { - int nu=ntype%10; - if( nu == 0 || nu == 3 || nu == 7 ) { - ndbm=ntype; - memset(call_loc_pow,0,sizeof(char)*23); - sprintf(cdbm,"%2d",ndbm); - strncat(call_loc_pow,callsign,strlen(callsign)); - strncat(call_loc_pow," ",1); - strncat(call_loc_pow,grid,4); - strncat(call_loc_pow," ",1); - strncat(call_loc_pow,cdbm,2); - strncat(call_loc_pow,"\0",1); - ihash=nhash(callsign,strlen(callsign),(uint32_t)146); - strcpy(hashtab+ihash*13,callsign); - strcpy(loctab+ihash*5,grid); - } else { - nadd=nu; - if( nu > 3 ) nadd=nu-3; - if( nu > 7 ) nadd=nu-7; - n3=n2/128+32768*(nadd-1); - if( !unpackpfx(n3,callsign) ) return 1; - ndbm=ntype-nadd; - memset(call_loc_pow,0,sizeof(char)*23); - sprintf(cdbm,"%2d",ndbm); - strncat(call_loc_pow,callsign,strlen(callsign)); - strncat(call_loc_pow," ",1); - strncat(call_loc_pow,cdbm,2); - strncat(call_loc_pow,"\0",1); - int nu=ndbm%10; - if( nu == 0 || nu == 3 || nu == 7 || nu == 10 ) { //make sure power is OK - ihash=nhash(callsign,strlen(callsign),(uint32_t)146); - strcpy(hashtab+ihash*13,callsign); - } else noprint=1; - } - } else if ( ntype < 0 ) { - ndbm=-(ntype+1); - memset(grid6,0,sizeof(char)*7); -// size_t len=strlen(callsign); - size_t len=6; - strncat(grid6,callsign+len-1,1); - strncat(grid6,callsign,len-1); - int nu=ndbm%10; - if ((nu != 0 && nu != 3 && nu != 7 && nu != 10) || - !isalpha(grid6[0]) || !isalpha(grid6[1]) || - !isdigit(grid6[2]) || !isdigit(grid6[3])) { - // not testing 4'th and 5'th chars because of this case: JO33 40 - // grid is only 4 chars even though this is a hashed callsign... - // isalpha(grid6[4]) && isalpha(grid6[5]) ) ) { - noprint=1; - } - - ihash=(n2-ntype-64)/128; - if( strncmp(hashtab+ihash*13,"\0",1) != 0 ) { - sprintf(callsign,"<%s>",hashtab+ihash*13); - } else { - sprintf(callsign,"%5s","<...>"); - } - - memset(call_loc_pow,0,sizeof(char)*23); - sprintf(cdbm,"%2d",ndbm); - strncat(call_loc_pow,callsign,strlen(callsign)); - strncat(call_loc_pow," ",1); - strncat(call_loc_pow,grid6,strlen(grid6)); - strncat(call_loc_pow," ",1); - strncat(call_loc_pow,cdbm,2); - strncat(call_loc_pow,"\0",1); - - - // I don't know what to do with these... They show up as "A000AA" grids. - if( ntype == -64 ) noprint=1; - } - return noprint; -} +/* + This file is part of program wsprd, a detector/demodulator/decoder + for the Weak Signal Propagation Reporter (WSPR) mode. + + File name: wsprd_utils.c + + Copyright 2001-2015, Joe Taylor, K1JT + + Most of the code is based on work by Steven Franke, K9AN, which + in turn was based on earlier work by K1JT. + + Copyright 2014-2015, Steven Franke, K9AN + + License: GNU GPL v3 + + 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 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +#include "wsprd_utils.h" + +#ifndef int32_t +#define int32_t int +#endif + +void unpack50( signed char *dat, int32_t *n1, int32_t *n2 ) +{ + int32_t i,i4; + + i=dat[0]; + i4=i&255; + *n1=i4<<20; + + i=dat[1]; + i4=i&255; + *n1=*n1+(i4<<12); + + i=dat[2]; + i4=i&255; + *n1=*n1+(i4<<4); + + i=dat[3]; + i4=i&255; + *n1=*n1+((i4>>4)&15); + *n2=(i4&15)<<18; + + i=dat[4]; + i4=i&255; + *n2=*n2+(i4<<10); + + i=dat[5]; + i4=i&255; + *n2=*n2+(i4<<2); + + i=dat[6]; + i4=i&255; + *n2=*n2+((i4>>6)&3); +} + +int unpackcall( int32_t ncall, char *call ) +{ + char c[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E', + 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', + 'U','V','W','X','Y','Z',' '}; + int32_t n; + int i; + char tmp[7]; + + n=ncall; + strcpy(call,"......"); + if (n < 262177560 ) { + i=n%27+10; + tmp[5]=c[i]; + n=n/27; + i=n%27+10; + tmp[4]=c[i]; + n=n/27; + i=n%27+10; + tmp[3]=c[i]; + n=n/27; + i=n%10; + tmp[2]=c[i]; + n=n/10; + i=n%36; + tmp[1]=c[i]; + n=n/36; + i=n; + tmp[0]=c[i]; + tmp[6]='\0'; + // remove leading whitespace + for(i=0; i<5; i++) { + if( tmp[i] != c[36] ) + break; + } + sprintf(call,"%-6s",&tmp[i]); + // remove trailing whitespace + for(i=0; i<6; i++) { + if( call[i] == c[36] ) { + call[i]='\0'; + } + } + } else { + return 0; + } + return 1; +} + +int unpackgrid( int32_t ngrid, char *grid) +{ + char c[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E', + 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', + 'U','V','W','X','Y','Z',' '}; + int dlat, dlong; + + ngrid=ngrid>>7; + if( ngrid < 32400 ) { + dlat=(ngrid%180)-90; + dlong=(ngrid/180)*2 - 180 + 2; + if( dlong < -180 ) + dlong=dlong+360; + if( dlong > 180 ) + dlong=dlong+360; + int nlong = 60.0*(180.0-dlong)/5.0; + int n1 = nlong/240; + int n2 = (nlong - 240*n1)/24; + grid[0] = c[10+n1]; + grid[2]= c[n2]; + + int nlat = 60.0*(dlat+90)/2.5; + n1 = nlat/240; + n2 = (nlat-240*n1)/24; + grid[1]=c[10+n1]; + grid[3]=c[n2]; + } else { + strcpy(grid,"XXXX"); + return 0; + } + return 1; +} + +int unpackpfx( int32_t nprefix, char *call) +{ + char nc, pfx[4]={'\0'}, tmpcall[7]; + int i; + int32_t n; + + strcpy(tmpcall,call); + if( nprefix < 60000 ) { + // add a prefix of 1 to 3 characters + n=nprefix; + for (i=2; i>=0; i--) { + nc=n%37; + if( (nc >= 0) & (nc <= 9) ) { + pfx[i]=nc+48; + } + else if( (nc >= 10) & (nc <= 35) ) { + pfx[i]=nc+55; + } + else { + pfx[i]=' '; + } + n=n/37; + } + + char * p = strrchr(pfx,' '); + strcpy(call, p ? p + 1 : pfx); + strncat(call,"/",1); + strncat(call,tmpcall,strlen(tmpcall)); + + } else { + // add a suffix of 1 or 2 characters + nc=nprefix-60000; + if( (nc >= 0) & (nc <= 9) ) { + pfx[0]=nc+48; + strcpy(call,tmpcall); + strncat(call,"/",1); + strncat(call,pfx,1); + } + else if( (nc >= 10) & (nc <= 35) ) { + pfx[0]=nc+55; + strcpy(call,tmpcall); + strncat(call,"/",1); + strncat(call,pfx,1); + } + else if( (nc >= 36) & (nc <= 125) ) { + pfx[0]=(nc-26)/10+48; + pfx[1]=(nc-26)%10+48; + strcpy(call,tmpcall); + strncat(call,"/",1); + strncat(call,pfx,2); + } + else { + return 0; + } + } + return 1; +} + +void deinterleave(unsigned char *sym) +{ + unsigned char tmp[162]; + unsigned char p, i, j; + + p=0; + i=0; + while (p<162) { + j=((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32; + if (j < 162 ) { + tmp[p]=sym[j]; + p=p+1; + } + i=i+1; + } + for (i=0; i<162; i++) { + sym[i]=tmp[i]; + } +} + +// used by qsort +int doublecomp(const void* elem1, const void* elem2) +{ + if(*(const double*)elem1 < *(const double*)elem2) + return -1; + return *(const double*)elem1 > *(const double*)elem2; +} + +int floatcomp(const void* elem1, const void* elem2) +{ + if(*(const float*)elem1 < *(const float*)elem2) + return -1; + return *(const float*)elem1 > *(const float*)elem2; +} + +int unpk_(signed char *message, char *hashtab, char *loctab, char *call_loc_pow, char *callsign) +{ + int n1,n2,n3,ndbm,ihash,nadd,noprint=0; + char grid[5],grid6[7],cdbm[4]; + + unpack50(message,&n1,&n2); + if( !unpackcall(n1,callsign) ) return 1; + if( !unpackgrid(n2, grid) ) return 1; + int ntype = (n2&127) - 64; + callsign[12]=0; + grid[4]=0; + + /* + Based on the value of ntype, decide whether this is a Type 1, 2, or + 3 message. + + * Type 1: 6 digit call, grid, power - ntype is positive and is a member + of the set {0,3,7,10,13,17,20...60} + + * Type 2: extended callsign, power - ntype is positive but not + a member of the set of allowed powers + + * Type 3: hash, 6 digit grid, power - ntype is negative. + */ + + if( (ntype >= 0) && (ntype <= 62) ) { + int nu=ntype%10; + if( nu == 0 || nu == 3 || nu == 7 ) { + ndbm=ntype; + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,grid,4); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); + strcpy(hashtab+ihash*13,callsign); + strcpy(loctab+ihash*5,grid); + } else { + nadd=nu; + if( nu > 3 ) nadd=nu-3; + if( nu > 7 ) nadd=nu-7; + n3=n2/128+32768*(nadd-1); + if( !unpackpfx(n3,callsign) ) return 1; + ndbm=ntype-nadd; + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + int nu=ndbm%10; + if( nu == 0 || nu == 3 || nu == 7 || nu == 10 ) { //make sure power is OK + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); + strcpy(hashtab+ihash*13,callsign); + } else noprint=1; + } + } else if ( ntype < 0 ) { + ndbm=-(ntype+1); + memset(grid6,0,sizeof(char)*7); +// size_t len=strlen(callsign); + size_t len=6; + strncat(grid6,callsign+len-1,1); + strncat(grid6,callsign,len-1); + int nu=ndbm%10; + if ((nu != 0 && nu != 3 && nu != 7 && nu != 10) || + !isalpha(grid6[0]) || !isalpha(grid6[1]) || + !isdigit(grid6[2]) || !isdigit(grid6[3])) { + // not testing 4'th and 5'th chars because of this case: JO33 40 + // grid is only 4 chars even though this is a hashed callsign... + // isalpha(grid6[4]) && isalpha(grid6[5]) ) ) { + noprint=1; + } + + ihash=(n2-ntype-64)/128; + if( strncmp(hashtab+ihash*13,"\0",1) != 0 ) { + sprintf(callsign,"<%s>",hashtab+ihash*13); + } else { + sprintf(callsign,"%5s","<...>"); + } + + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,grid6,strlen(grid6)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + + + // I don't know what to do with these... They show up as "A000AA" grids. + if( ntype == -64 ) noprint=1; + } + return noprint; +} diff --git a/lib/wsprd/wsprd_utils.h b/lib/wsprd/wsprd_utils.h index 918c61f9..db6ba946 100755 --- a/lib/wsprd/wsprd_utils.h +++ b/lib/wsprd/wsprd_utils.h @@ -1,29 +1,29 @@ -#ifndef WSPRD_UTILS_H -#define WSPRD_UTILS_H - -#include -#include -#include -#include -#include -#include -#include -#include "nhash.h" - -void unpack50( signed char *dat, int32_t *n1, int32_t *n2 ); - -int unpackcall( int32_t ncall, char *call ); - -int unpackgrid( int32_t ngrid, char *grid); - -int unpackpfx( int32_t nprefix, char *call); - -void deinterleave(unsigned char *sym); - -// used by qsort -int doublecomp(const void* elem1, const void* elem2); -int floatcomp(const void* elem1, const void* elem2); - -int unpk_( signed char *message, char* hashtab, char* loctab, char *call_loc_pow, char *callsign); - -#endif +#ifndef WSPRD_UTILS_H +#define WSPRD_UTILS_H + +#include +#include +#include +#include +#include +#include +#include +#include "nhash.h" + +void unpack50( signed char *dat, int32_t *n1, int32_t *n2 ); + +int unpackcall( int32_t ncall, char *call ); + +int unpackgrid( int32_t ngrid, char *grid); + +int unpackpfx( int32_t nprefix, char *call); + +void deinterleave(unsigned char *sym); + +// used by qsort +int doublecomp(const void* elem1, const void* elem2); +int floatcomp(const void* elem1, const void* elem2); + +int unpk_( signed char *message, char* hashtab, char* loctab, char *call_loc_pow, char *callsign); + +#endif diff --git a/lib/wsprd/wsprsim.c b/lib/wsprd/wsprsim.c index 66fedfbf..f6633c1c 100755 --- a/lib/wsprd/wsprsim.c +++ b/lib/wsprd/wsprsim.c @@ -1,212 +1,212 @@ -/* - File name: wsprsim.c (first committed to wsjtx June 13, 2015) - */ -#include -#include -#include -#include - -#include "wsprsim_utils.h" -#include "wsprd_utils.h" -#include "fano.h" - -int printdata=0; - -void usage() { - printf("Usage: wsprsim [options] message\n"); - printf(" message format: \"K1ABC FN42 33\"\n"); - printf(" \"PJ4/K1ABC 33\"\n"); - printf(" \" FK52UD 33\"\n"); - printf("Options:\n"); - printf(" -c (print channel symbols)\n"); - printf(" -d (print packed data with zero tail - 11 bytes)\n"); - printf(" -f x (-100 Hz < f < 100 Hz)\n"); - printf(" -o filename (write a c2 file with this name)\n"); - printf(" -s x (x is snr of signal that is written to .c2 file)\n"); - printf("\n"); - printf(" e.g. ./wsprsim -cds -28 -o 150613_1920.c2 \"K1ABC FN42 33\"\n"); - printf(" then ./wsprd 150613_1920.c2\n"); -} - -int add_signal_vector(float f0, float t0, float amp, unsigned char* symbols - , double* isig, double* qsig) -{ - int i, j, ii, idelay; - double phi=0.0, twopidt, df, dt, dphi; - twopidt=8.0*atan(1.0)/375.0; - df=375.0/256.0; - dt=1/375.0; - idelay=t0/dt; - - for (i=0; i<162; i++) { - dphi=twopidt*(f0 + ( (double)symbols[i]-1.5)*df ); - for ( j=0; j<256; j++ ) { - ii=idelay+256*i+j; - isig[ii]=isig[ii]+amp*cos(phi); - qsig[ii]=qsig[ii]+amp*sin(phi); - phi=phi+dphi; - } - } - return 1; -} - -char* tobinary(int x) -{ - static char b[33]; - b[0] = '\0'; - - long unsigned int z; - for (z = 0x80000000; z > 0; z >>= 1) - { - strcat(b, ((x & z) == z) ? "1" : "0"); - } - - return b; -} - -double gaussrand() -{ - static double V1, V2, S; - static int phase = 0; - double X; - - if(phase == 0) { - do { - double U1 = (double)rand() / RAND_MAX; - double U2 = (double)rand() / RAND_MAX; - - V1 = 2 * U1 - 1; - V2 = 2 * U2 - 1; - S = V1 * V1 + V2 * V2; - } while(S >= 1 || S == 0); - - X = V1 * sqrt(-2 * log(S) / S); - } else - X = V2 * sqrt(-2 * log(S) / S); - - phase = 1 - phase; - - return X; -} - -unsigned long writec2file(char *c2filename, int trmin, double freq - , double *idat, double *qdat) -{ - int i; - float buffer[2*45000]; - memset(buffer,0,sizeof(float)*2*45000); - FILE *fp; - - fp = fopen(c2filename,"wb"); - if( fp == NULL ) { - fprintf(stderr, "Could not open c2 file '%s'\n", c2filename); - return 0; - } - unsigned long nwrite = fwrite(c2filename,sizeof(char),14,fp); - nwrite = fwrite(&trmin, sizeof(int), 1, fp); - nwrite = fwrite(&freq, sizeof(double), 1, fp); - - for(i=0; i<45000; i++) { - buffer[2*i]=idat[i]; - buffer[2*i+1]=-qdat[i]; - } - - nwrite = fwrite(buffer, sizeof(float), 2*45000, fp); - if( nwrite == 2*45000 ) { - return nwrite; - } else { - return 0; - } -} - - -//******************************************************************** -int main(int argc, char *argv[]) -{ - extern char *optarg; - extern int optind; - int i, c, printchannel=0, writec2=0; - float snr=50.0; - float f0=0.0, t0=1.0; - char *message, *c2filename, *hashtab, *loctab; - c2filename=malloc(sizeof(char)*15); - hashtab=malloc(sizeof(char)*32768*13); - loctab=malloc(sizeof(char)*32768*5); - memset(hashtab,0,sizeof(char)*32768*13); - memset(hashtab,0,sizeof(char)*32768*5); - - // message length is 22 characters - message=malloc(sizeof(char)*23); - - strcpy(c2filename,"000000_0001.c2"); - - srand(getpid()); - - while ( (c = getopt(argc, argv, "cdf:o:s:")) !=-1 ) { - switch (c) { - case 'c': - printchannel=1; - break; - case 'd': - printdata=1; - break; - case 'f': - f0 = atof(optarg); - break; - case 'o': - c2filename = optarg; - writec2=1; - break; - case 's': -// snr = (float)atoi(optarg); - snr = atof(optarg); - break; - } - } - - if( optind+1 > argc ) { - usage(); - return 0; - } else { - message=argv[optind]; - } - - unsigned char channel_symbols[162]; - get_wspr_channel_symbols(message, hashtab, loctab, channel_symbols); - - if( printchannel ) { - printf("Channel symbols:\n"); - for (i=0; i<162; i++) { - printf("%d ",channel_symbols[i]); - } - printf("\n"); - } - - // add noise, then signal - double isig[45000], qsig[45000]; - memset(isig,0,sizeof(double)*45000); - memset(qsig,0,sizeof(double)*45000); - - if( snr < 40 ) { - // snr in 375Hz is 8.2 dB higher than in 2500 Hz. - snr=snr+8.2; - snr=pow(10,snr/20.0)*pow(2,0.5); - - for (i = 0; i<45000; i++) { - isig[i]=isig[i]+gaussrand(); - qsig[i]=qsig[i]+gaussrand(); - } - } else { - snr=1.0; - } - - add_signal_vector(f0, t0, snr, channel_symbols, isig, qsig); - if( writec2) { - // write a .c2 file - double carrierfreq=10.1387; - int wsprtype=2; - printf("Writing %s\n",c2filename); - writec2file(c2filename, wsprtype, carrierfreq, isig, qsig); - } - return 1; -} +/* + File name: wsprsim.c (first committed to wsjtx June 13, 2015) + */ +#include +#include +#include +#include + +#include "wsprsim_utils.h" +#include "wsprd_utils.h" +#include "fano.h" + +int printdata=0; + +void usage() { + printf("Usage: wsprsim [options] message\n"); + printf(" message format: \"K1ABC FN42 33\"\n"); + printf(" \"PJ4/K1ABC 33\"\n"); + printf(" \" FK52UD 33\"\n"); + printf("Options:\n"); + printf(" -c (print channel symbols)\n"); + printf(" -d (print packed data with zero tail - 11 bytes)\n"); + printf(" -f x (-100 Hz < f < 100 Hz)\n"); + printf(" -o filename (write a c2 file with this name)\n"); + printf(" -s x (x is snr of signal that is written to .c2 file)\n"); + printf("\n"); + printf(" e.g. ./wsprsim -cds -28 -o 150613_1920.c2 \"K1ABC FN42 33\"\n"); + printf(" then ./wsprd 150613_1920.c2\n"); +} + +int add_signal_vector(float f0, float t0, float amp, unsigned char* symbols + , double* isig, double* qsig) +{ + int i, j, ii, idelay; + double phi=0.0, twopidt, df, dt, dphi; + twopidt=8.0*atan(1.0)/375.0; + df=375.0/256.0; + dt=1/375.0; + idelay=t0/dt; + + for (i=0; i<162; i++) { + dphi=twopidt*(f0 + ( (double)symbols[i]-1.5)*df ); + for ( j=0; j<256; j++ ) { + ii=idelay+256*i+j; + isig[ii]=isig[ii]+amp*cos(phi); + qsig[ii]=qsig[ii]+amp*sin(phi); + phi=phi+dphi; + } + } + return 1; +} + +char* tobinary(int x) +{ + static char b[33]; + b[0] = '\0'; + + long unsigned int z; + for (z = 0x80000000; z > 0; z >>= 1) + { + strcat(b, ((x & z) == z) ? "1" : "0"); + } + + return b; +} + +double gaussrand() +{ + static double V1, V2, S; + static int phase = 0; + double X; + + if(phase == 0) { + do { + double U1 = (double)rand() / RAND_MAX; + double U2 = (double)rand() / RAND_MAX; + + V1 = 2 * U1 - 1; + V2 = 2 * U2 - 1; + S = V1 * V1 + V2 * V2; + } while(S >= 1 || S == 0); + + X = V1 * sqrt(-2 * log(S) / S); + } else + X = V2 * sqrt(-2 * log(S) / S); + + phase = 1 - phase; + + return X; +} + +unsigned long writec2file(char *c2filename, int trmin, double freq + , double *idat, double *qdat) +{ + int i; + float buffer[2*45000]; + memset(buffer,0,sizeof(float)*2*45000); + FILE *fp; + + fp = fopen(c2filename,"wb"); + if( fp == NULL ) { + fprintf(stderr, "Could not open c2 file '%s'\n", c2filename); + return 0; + } + unsigned long nwrite = fwrite(c2filename,sizeof(char),14,fp); + nwrite = fwrite(&trmin, sizeof(int), 1, fp); + nwrite = fwrite(&freq, sizeof(double), 1, fp); + + for(i=0; i<45000; i++) { + buffer[2*i]=idat[i]; + buffer[2*i+1]=-qdat[i]; + } + + nwrite = fwrite(buffer, sizeof(float), 2*45000, fp); + if( nwrite == 2*45000 ) { + return nwrite; + } else { + return 0; + } +} + + +//******************************************************************** +int main(int argc, char *argv[]) +{ + extern char *optarg; + extern int optind; + int i, c, printchannel=0, writec2=0; + float snr=50.0; + float f0=0.0, t0=1.0; + char *message, *c2filename, *hashtab, *loctab; + c2filename=malloc(sizeof(char)*15); + hashtab=malloc(sizeof(char)*32768*13); + loctab=malloc(sizeof(char)*32768*5); + memset(hashtab,0,sizeof(char)*32768*13); + memset(hashtab,0,sizeof(char)*32768*5); + + // message length is 22 characters + message=malloc(sizeof(char)*23); + + strcpy(c2filename,"000000_0001.c2"); + + srand(getpid()); + + while ( (c = getopt(argc, argv, "cdf:o:s:")) !=-1 ) { + switch (c) { + case 'c': + printchannel=1; + break; + case 'd': + printdata=1; + break; + case 'f': + f0 = atof(optarg); + break; + case 'o': + c2filename = optarg; + writec2=1; + break; + case 's': +// snr = (float)atoi(optarg); + snr = atof(optarg); + break; + } + } + + if( optind+1 > argc ) { + usage(); + return 0; + } else { + message=argv[optind]; + } + + unsigned char channel_symbols[162]; + get_wspr_channel_symbols(message, hashtab, loctab, channel_symbols); + + if( printchannel ) { + printf("Channel symbols:\n"); + for (i=0; i<162; i++) { + printf("%d ",channel_symbols[i]); + } + printf("\n"); + } + + // add noise, then signal + double isig[45000], qsig[45000]; + memset(isig,0,sizeof(double)*45000); + memset(qsig,0,sizeof(double)*45000); + + if( snr < 40 ) { + // snr in 375Hz is 8.2 dB higher than in 2500 Hz. + snr=snr+8.2; + snr=pow(10,snr/20.0)*pow(2,0.5); + + for (i = 0; i<45000; i++) { + isig[i]=isig[i]+gaussrand(); + qsig[i]=qsig[i]+gaussrand(); + } + } else { + snr=1.0; + } + + add_signal_vector(f0, t0, snr, channel_symbols, isig, qsig); + if( writec2) { + // write a .c2 file + double carrierfreq=10.1387; + int wsprtype=2; + printf("Writing %s\n",c2filename); + writec2file(c2filename, wsprtype, carrierfreq, isig, qsig); + } + return 1; +} diff --git a/lib/wsprd/wsprsim_utils.c b/lib/wsprd/wsprsim_utils.c index 2cbffa59..0130a87e 100755 --- a/lib/wsprd/wsprsim_utils.c +++ b/lib/wsprd/wsprsim_utils.c @@ -1,312 +1,312 @@ -/* - Functions used by wsprsim - */ -#include "wsprsim_utils.h" -#include "wsprd_utils.h" -#include "nhash.h" -#include "fano.h" - -static char get_locator_character_code(char ch); -static char get_callsign_character_code(char ch); -static long unsigned int pack_grid4_power(char const *grid4, int power); -static long unsigned int pack_call(char const *callsign); -static void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd ); -static void interleave(unsigned char *sym); - -char get_locator_character_code(char ch) { - if( ch >=48 && ch <=57 ) { //0-9 - return ch-48; - } - if( ch == 32 ) { //space - return 36; - } - if( ch >= 65 && ch <= 82 ) { //A-Z - return ch-65; - } - return -1; -} - -char get_callsign_character_code(char ch) { - if( ch >=48 && ch <=57 ) { //0-9 - return ch-48; - } - if( ch == 32 ) { //space - return 36; - } - if( ch >= 65 && ch <= 90 ) { //A-Z - return ch-55; - } - return -1; -} - -long unsigned int pack_grid4_power(char const *grid4, int power) { - long unsigned int m; - - m=(179-10*grid4[0]-grid4[2])*180+10*grid4[1]+grid4[3]; - m=m*128+power+64; - return m; -} - -long unsigned int pack_call(char const *callsign) { - unsigned int i; - long unsigned int n; - char call6[6]; - memset(call6,' ',sizeof(call6)); - // callsign is 6 characters in length. Exactly. - size_t call_len = strlen(callsign); - if( call_len > 6 ) { - return 0; - } - if( isdigit(callsign[2]) ) { - for (i=0; i= 48 && nc <= 57 ) { - *m=nc-48; - } else if ( nc >= 65 && nc <= 90 ) { - *m=nc-65+10; - } else { - *m=38; - } - *m=60000-32768+*m; - } else if( callsign[i1+3]==0 ) { - //two char suffix - for (i=0; i= 48 && nc <= 57 ) { - nc=nc-48; - } else if ( nc >= 65 && nc <= 90 ) { - nc=nc-65+10; - } else { - nc=36; - } - *m=37*(*m)+nc; - } - *nadd=0; - if( *m > 32768 ) { - *m=*m-32768; - *nadd=1; - } - } - free (call6); -} - -void interleave(unsigned char *sym) -{ - unsigned char tmp[162]; - unsigned char p, i, j; - - p=0; - i=0; - while (p<162) { - j=((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32; - if (j < 162 ) { - tmp[j]=sym[p]; - p=p+1; - } - i=i+1; - } - for (i=0; i<162; i++) { - sym[i]=tmp[i]; - } -} - -int get_wspr_channel_symbols(char* rawmessage, char* hashtab, char* loctab, unsigned char* symbols) { - int m=0, ntype=0; - long unsigned int n=0; - int i, j, ihash; - unsigned char pr3[162]= - {1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, - 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, - 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, - 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, - 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, - 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, - 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, - 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, - 0,0}; - int nu[10]={0,-1,1,0,-1,2,1,0,-1,1}; - char *callsign, *grid, *powstr; - char grid4[5], message[23]; - - memset(message,0,sizeof(char)*23); - i=0; - while ( rawmessage[i] != 0 && i<23 ) { - message[i]=rawmessage[i]; - i++; - } - - size_t i1=strcspn(message," "); - size_t i2=strcspn(message,"/"); - size_t i3=strcspn(message,"<"); - size_t i4=strcspn(message,">"); - size_t mlen=strlen(message); - - // Use the presence and/or absence of "<" and "/" to decide what - // type of message. No sanity checks! Beware! - - if( i1 >= 3 && i1 < 7 && i2 == mlen && i3 == mlen ) { - // Type 1 message: K9AN EN50 33 - // xxnxxxx xxnn nn - callsign = strtok(message," "); - grid = strtok(NULL," "); - powstr = strtok(NULL," "); - int power = atoi(powstr); - n = pack_call(callsign); - - for (i=0; i<4; i++) { - grid4[i]=get_locator_character_code(*(grid+i)); - } - m = pack_grid4_power(grid4,power); - - } else if ( i3 == 0 && i4 < mlen ) { - // Type 3: EN50WC 33 - // FK52UD 37 - // send hash instead of callsign to make room for 6 char grid. - // if 4-digit locator is specified, 2 spaces are added to the end. - callsign=strtok(message,"<> "); - grid=strtok(NULL," "); - powstr=strtok(NULL," "); - int power = atoi(powstr); - if( power < 0 ) power=0; - if( power > 60 ) power=60; - power=power+nu[power%10]; - ntype=-(power+1); - ihash=nhash(callsign,strlen(callsign),(uint32_t)146); - m=128*ihash + ntype + 64; - - char grid6[7]; - memset(grid6,0,sizeof(char)*7); - j=strlen(grid); - for(i=0; istrlen(callsign) ) return 0; //guards against pathological case - powstr = strtok (NULL," "); - int power = atoi (powstr); - if( power < 0 ) power=0; - if( power > 60 ) power=60; - power=power+nu[power%10]; - int n1, ng, nadd; - pack_prefix(callsign, &n1, &ng, &nadd); - ntype=power + 1 + nadd; - m=128*ng+ntype+64; - n=n1; - } else { - return 0; - } - - // pack 50 bits + 31 (0) tail bits into 11 bytes - unsigned char it, data[11]; - memset(data,0,sizeof(char)*11); - it=0xFF & (n>>20); - data[0]=it; - it=0xFF & (n>>12); - data[1]=it; - it=0xFF & (n>>4); - data[2]=it; - it= ((n&(0x0F))<<4) + ((m>>18)&(0x0F)); - data[3]=it; - it=0xFF & (m>>10); - data[4]=it; - it=0xFF & (m>>2); - data[5]=it; - it=(m & 0x03)<<6 ; - data[6]=it; - data[7]=0; - data[8]=0; - data[9]=0; - data[10]=0; - - if( printdata ) { - printf("Data is :"); - for (i=0; i<11; i++) { - printf("%02X ",data[i]); - } - printf("\n"); - } - - // make sure that the 11-byte data vector is unpackable - // unpack it with the routine that the decoder will use and display - // the result. let the operator decide whether it worked. - - char *check_call_loc_pow, *check_callsign; - check_call_loc_pow=malloc(sizeof(char)*23); - check_callsign=malloc(sizeof(char)*13); - signed char check_data[11]; - memcpy(check_data,data,sizeof(char)*11); - - unpk_(check_data,hashtab,loctab,check_call_loc_pow,check_callsign); -// printf("Will decode as: %s\n",check_call_loc_pow); - - unsigned int nbytes=11; // The message with tail is packed into almost 11 bytes. - unsigned char channelbits[nbytes*8*2]; /* 162 rounded up */ - memset(channelbits,0,sizeof(char)*nbytes*8*2); - - encode(channelbits,data,nbytes); - - interleave(channelbits); - - for (i=0; i<162; i++) { - symbols[i]=2*channelbits[i]+pr3[i]; - } - free(check_call_loc_pow); - free(check_callsign); - return 1; -} +/* + Functions used by wsprsim + */ +#include "wsprsim_utils.h" +#include "wsprd_utils.h" +#include "nhash.h" +#include "fano.h" + +static char get_locator_character_code(char ch); +static char get_callsign_character_code(char ch); +static long unsigned int pack_grid4_power(char const *grid4, int power); +static long unsigned int pack_call(char const *callsign); +static void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd ); +static void interleave(unsigned char *sym); + +char get_locator_character_code(char ch) { + if( ch >=48 && ch <=57 ) { //0-9 + return ch-48; + } + if( ch == 32 ) { //space + return 36; + } + if( ch >= 65 && ch <= 82 ) { //A-Z + return ch-65; + } + return -1; +} + +char get_callsign_character_code(char ch) { + if( ch >=48 && ch <=57 ) { //0-9 + return ch-48; + } + if( ch == 32 ) { //space + return 36; + } + if( ch >= 65 && ch <= 90 ) { //A-Z + return ch-55; + } + return -1; +} + +long unsigned int pack_grid4_power(char const *grid4, int power) { + long unsigned int m; + + m=(179-10*grid4[0]-grid4[2])*180+10*grid4[1]+grid4[3]; + m=m*128+power+64; + return m; +} + +long unsigned int pack_call(char const *callsign) { + unsigned int i; + long unsigned int n; + char call6[6]; + memset(call6,' ',sizeof(call6)); + // callsign is 6 characters in length. Exactly. + size_t call_len = strlen(callsign); + if( call_len > 6 ) { + return 0; + } + if( isdigit(callsign[2]) ) { + for (i=0; i= 48 && nc <= 57 ) { + *m=nc-48; + } else if ( nc >= 65 && nc <= 90 ) { + *m=nc-65+10; + } else { + *m=38; + } + *m=60000-32768+*m; + } else if( callsign[i1+3]==0 ) { + //two char suffix + for (i=0; i= 48 && nc <= 57 ) { + nc=nc-48; + } else if ( nc >= 65 && nc <= 90 ) { + nc=nc-65+10; + } else { + nc=36; + } + *m=37*(*m)+nc; + } + *nadd=0; + if( *m > 32768 ) { + *m=*m-32768; + *nadd=1; + } + } + free (call6); +} + +void interleave(unsigned char *sym) +{ + unsigned char tmp[162]; + unsigned char p, i, j; + + p=0; + i=0; + while (p<162) { + j=((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32; + if (j < 162 ) { + tmp[j]=sym[p]; + p=p+1; + } + i=i+1; + } + for (i=0; i<162; i++) { + sym[i]=tmp[i]; + } +} + +int get_wspr_channel_symbols(char* rawmessage, char* hashtab, char* loctab, unsigned char* symbols) { + int m=0, ntype=0; + long unsigned int n=0; + int i, j, ihash; + unsigned char pr3[162]= + {1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, + 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, + 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, + 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, + 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, + 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, + 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, + 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, + 0,0}; + int nu[10]={0,-1,1,0,-1,2,1,0,-1,1}; + char *callsign, *grid, *powstr; + char grid4[5], message[23]; + + memset(message,0,sizeof(char)*23); + i=0; + while ( rawmessage[i] != 0 && i<23 ) { + message[i]=rawmessage[i]; + i++; + } + + size_t i1=strcspn(message," "); + size_t i2=strcspn(message,"/"); + size_t i3=strcspn(message,"<"); + size_t i4=strcspn(message,">"); + size_t mlen=strlen(message); + + // Use the presence and/or absence of "<" and "/" to decide what + // type of message. No sanity checks! Beware! + + if( i1 >= 3 && i1 < 7 && i2 == mlen && i3 == mlen ) { + // Type 1 message: K9AN EN50 33 + // xxnxxxx xxnn nn + callsign = strtok(message," "); + grid = strtok(NULL," "); + powstr = strtok(NULL," "); + int power = atoi(powstr); + n = pack_call(callsign); + + for (i=0; i<4; i++) { + grid4[i]=get_locator_character_code(*(grid+i)); + } + m = pack_grid4_power(grid4,power); + + } else if ( i3 == 0 && i4 < mlen ) { + // Type 3: EN50WC 33 + // FK52UD 37 + // send hash instead of callsign to make room for 6 char grid. + // if 4-digit locator is specified, 2 spaces are added to the end. + callsign=strtok(message,"<> "); + grid=strtok(NULL," "); + powstr=strtok(NULL," "); + int power = atoi(powstr); + if( power < 0 ) power=0; + if( power > 60 ) power=60; + power=power+nu[power%10]; + ntype=-(power+1); + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); + m=128*ihash + ntype + 64; + + char grid6[7]; + memset(grid6,0,sizeof(char)*7); + j=strlen(grid); + for(i=0; istrlen(callsign) ) return 0; //guards against pathological case + powstr = strtok (NULL," "); + int power = atoi (powstr); + if( power < 0 ) power=0; + if( power > 60 ) power=60; + power=power+nu[power%10]; + int n1, ng, nadd; + pack_prefix(callsign, &n1, &ng, &nadd); + ntype=power + 1 + nadd; + m=128*ng+ntype+64; + n=n1; + } else { + return 0; + } + + // pack 50 bits + 31 (0) tail bits into 11 bytes + unsigned char it, data[11]; + memset(data,0,sizeof(char)*11); + it=0xFF & (n>>20); + data[0]=it; + it=0xFF & (n>>12); + data[1]=it; + it=0xFF & (n>>4); + data[2]=it; + it= ((n&(0x0F))<<4) + ((m>>18)&(0x0F)); + data[3]=it; + it=0xFF & (m>>10); + data[4]=it; + it=0xFF & (m>>2); + data[5]=it; + it=(m & 0x03)<<6 ; + data[6]=it; + data[7]=0; + data[8]=0; + data[9]=0; + data[10]=0; + + if( printdata ) { + printf("Data is :"); + for (i=0; i<11; i++) { + printf("%02X ",data[i]); + } + printf("\n"); + } + + // make sure that the 11-byte data vector is unpackable + // unpack it with the routine that the decoder will use and display + // the result. let the operator decide whether it worked. + + char *check_call_loc_pow, *check_callsign; + check_call_loc_pow=malloc(sizeof(char)*23); + check_callsign=malloc(sizeof(char)*13); + signed char check_data[11]; + memcpy(check_data,data,sizeof(char)*11); + + unpk_(check_data,hashtab,loctab,check_call_loc_pow,check_callsign); +// printf("Will decode as: %s\n",check_call_loc_pow); + + unsigned int nbytes=11; // The message with tail is packed into almost 11 bytes. + unsigned char channelbits[nbytes*8*2]; /* 162 rounded up */ + memset(channelbits,0,sizeof(char)*nbytes*8*2); + + encode(channelbits,data,nbytes); + + interleave(channelbits); + + for (i=0; i<162; i++) { + symbols[i]=2*channelbits[i]+pr3[i]; + } + free(check_call_loc_pow); + free(check_callsign); + return 1; +} diff --git a/lib/wsprd/wsprsim_utils.h b/lib/wsprd/wsprsim_utils.h index 9843c56b..7f1f62e9 100755 --- a/lib/wsprd/wsprsim_utils.h +++ b/lib/wsprd/wsprsim_utils.h @@ -1,16 +1,16 @@ -#ifndef WSPRSIM_UTILS_H -#define WSPRSIM_UTILS_H - -#include -#include -#include -#include -#include -#include -#include - -extern int printdata; - -int get_wspr_channel_symbols(char* message, char* hashtab, char*loctab, unsigned char* symbols); - -#endif +#ifndef WSPRSIM_UTILS_H +#define WSPRSIM_UTILS_H + +#include +#include +#include +#include +#include +#include +#include + +extern int printdata; + +int get_wspr_channel_symbols(char* message, char* hashtab, char*loctab, unsigned char* symbols); + +#endif diff --git a/lib/wsprd/wsprsimf.f90 b/lib/wsprd/wsprsimf.f90 index 4c1d00a3..d6ee25d4 100755 --- a/lib/wsprd/wsprsimf.f90 +++ b/lib/wsprd/wsprsimf.f90 @@ -1,113 +1,113 @@ -!------------------------------------------------------------------------------- -! -! This file is part of the WSPR application, Weak Signal Propagation Reporter -! -!------------------------------------------------------------------------------- - -program wsprsim - - use wavhdr - include 'wspr_params.f90' - type(hdr) hwav - character arg*12,fname14*14,fname15*15 - character*22 msg,msgsent - complex c0(0:NMAX/NDOWN-1) - complex c(0:NMAX/NDOWN-1) - integer itone(NN) - integer*2 iwave(NMAX) - real*8 fMHz - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.8) then - print*,'Usage: wsprsim "message" f0 DT fsp del nwav nfiles snr' - print*,'Example: wsprsim "K1ABC FN42 30" 50 0.0 0.1 1.0 1 10 -33' - go to 999 - endif - call getarg(1,msg) !Message to be transmitted - call getarg(2,arg) - read(arg,*) f0 !Freq relative to WSPR-band center (Hz) - call getarg(3,arg) - read(arg,*) xdt !Time offset from nominal (s) - call getarg(4,arg) - read(arg,*) fspread !Watterson frequency spread (Hz) - call getarg(5,arg) - read(arg,*) delay !Watterson delay (ms) - call getarg(6,arg) - read(arg,*) nwav !1 for *.wav file, 0 for *.c2 file - call getarg(7,arg) - read(arg,*) nfiles !Number of files - call getarg(8,arg) - read(arg,*) snrdb !SNR_2500 - - twopi=8.0*atan(1.0) - fs=12000.0/NDOWN - dt=1.0/fs - tt=NSPS*dt - baud=12000.0/8192.0 - - txt=NZ*dt !Transmission length (s) - bandwidth_ratio=2500.0/(fs/2.0) - sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb) - if(snrdb.gt.90.0) sig=1.0 - txt=NN*NSPS0/12000.0 - - call genwspr(msg,msgsent,itone) !Encode the message, get itone - - write(*,1000) f0,xdt,txt,snrdb,fspread,delay,nfiles,msgsent -1000 format('f0:',f9.3,' DT:',f6.2,' txt:',f6.1,' SNR:',f6.1, & - ' fspread:',f6.1,' delay:',f6.1,' nfiles:',i3,2x,a22) -! write(*,*) "Channel symbols: " -! write(*,'(162i2)') itone - - h=1.0 - phi=0.0 - c0=0. - k=-1 + nint(xdt/dt) - do j=1,NN - dphi=-twopi*(f0+h*(itone(j)-1.5)*baud)*dt - do i=1,NSPS - k=k+1 - phi=mod(phi+dphi,twopi) - if(k.ge.0 .and. k.lt.NMAX/NDOWN) c0(k)=cmplx(cos(phi),sin(phi)) - enddo - enddo - call sgran() - do ifile=1,nfiles - c=c0 - if(nwav.eq.0) then - if( fspread .ne. 0.0 .or. delay .ne. 0.0 ) then - call watterson(c,NMAX/NDOWN,NN*NSPS,fs,delay,fspread) - endif - c=c*sig - if(snrdb.lt.90) then - do i=0,NMAX/NDOWN-1 !Add gaussian noise at specified SNR - xnoise=gran() - ynoise=gran() - c(i)=c(i) + cmplx(xnoise,ynoise) - enddo - endif - write(fname14,1100) ifile -1100 format('000000_',i4.4,'.c2') - open(10,file=fname14,status='unknown',access='stream') - fMHz=10.1387d0 - nmin=2 - write(10) fname14,nmin,fMHz,c !Save to *.c2 file - close(10) - write(*,1108) ifile,xdt,f0,snrdb,fname14 -1108 format(i4,f7.2,f8.2,f7.1,2x,a14) - else - freq=1500.0+f0 - call wspr_wav(baud,xdt,h,freq,itone,snrdb,iwave) - hwav=default_header(12000,NMAX) - write(fname15,1102) ifile -1102 format('000000_',i4.4,'.wav') - open(10,file=fname15,status='unknown',access='stream') - write(10) hwav,iwave !Save to *.wav file - close(10) - write(*,1110) ifile,xdt,f0,snrdb,fname15 -1110 format(i4,f7.2,f8.2,f7.1,2x,a15) - endif - enddo - -999 end program wsprsim +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +!------------------------------------------------------------------------------- + +program wsprsim + + use wavhdr + include 'wspr_params.f90' + type(hdr) hwav + character arg*12,fname14*14,fname15*15 + character*22 msg,msgsent + complex c0(0:NMAX/NDOWN-1) + complex c(0:NMAX/NDOWN-1) + integer itone(NN) + integer*2 iwave(NMAX) + real*8 fMHz + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.8) then + print*,'Usage: wsprsim "message" f0 DT fsp del nwav nfiles snr' + print*,'Example: wsprsim "K1ABC FN42 30" 50 0.0 0.1 1.0 1 10 -33' + go to 999 + endif + call getarg(1,msg) !Message to be transmitted + call getarg(2,arg) + read(arg,*) f0 !Freq relative to WSPR-band center (Hz) + call getarg(3,arg) + read(arg,*) xdt !Time offset from nominal (s) + call getarg(4,arg) + read(arg,*) fspread !Watterson frequency spread (Hz) + call getarg(5,arg) + read(arg,*) delay !Watterson delay (ms) + call getarg(6,arg) + read(arg,*) nwav !1 for *.wav file, 0 for *.c2 file + call getarg(7,arg) + read(arg,*) nfiles !Number of files + call getarg(8,arg) + read(arg,*) snrdb !SNR_2500 + + twopi=8.0*atan(1.0) + fs=12000.0/NDOWN + dt=1.0/fs + tt=NSPS*dt + baud=12000.0/8192.0 + + txt=NZ*dt !Transmission length (s) + bandwidth_ratio=2500.0/(fs/2.0) + sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + txt=NN*NSPS0/12000.0 + + call genwspr(msg,msgsent,itone) !Encode the message, get itone + + write(*,1000) f0,xdt,txt,snrdb,fspread,delay,nfiles,msgsent +1000 format('f0:',f9.3,' DT:',f6.2,' txt:',f6.1,' SNR:',f6.1, & + ' fspread:',f6.1,' delay:',f6.1,' nfiles:',i3,2x,a22) +! write(*,*) "Channel symbols: " +! write(*,'(162i2)') itone + + h=1.0 + phi=0.0 + c0=0. + k=-1 + nint(xdt/dt) + do j=1,NN + dphi=-twopi*(f0+h*(itone(j)-1.5)*baud)*dt + do i=1,NSPS + k=k+1 + phi=mod(phi+dphi,twopi) + if(k.ge.0 .and. k.lt.NMAX/NDOWN) c0(k)=cmplx(cos(phi),sin(phi)) + enddo + enddo + call sgran() + do ifile=1,nfiles + c=c0 + if(nwav.eq.0) then + if( fspread .ne. 0.0 .or. delay .ne. 0.0 ) then + call watterson(c,NMAX/NDOWN,NN*NSPS,fs,delay,fspread) + endif + c=c*sig + if(snrdb.lt.90) then + do i=0,NMAX/NDOWN-1 !Add gaussian noise at specified SNR + xnoise=gran() + ynoise=gran() + c(i)=c(i) + cmplx(xnoise,ynoise) + enddo + endif + write(fname14,1100) ifile +1100 format('000000_',i4.4,'.c2') + open(10,file=fname14,status='unknown',access='stream') + fMHz=10.1387d0 + nmin=2 + write(10) fname14,nmin,fMHz,c !Save to *.c2 file + close(10) + write(*,1108) ifile,xdt,f0,snrdb,fname14 +1108 format(i4,f7.2,f8.2,f7.1,2x,a14) + else + freq=1500.0+f0 + call wspr_wav(baud,xdt,h,freq,itone,snrdb,iwave) + hwav=default_header(12000,NMAX) + write(fname15,1102) ifile +1102 format('000000_',i4.4,'.wav') + open(10,file=fname15,status='unknown',access='stream') + write(10) hwav,iwave !Save to *.wav file + close(10) + write(*,1110) ifile,xdt,f0,snrdb,fname15 +1110 format(i4,f7.2,f8.2,f7.1,2x,a15) + endif + enddo + +999 end program wsprsim diff --git a/lib/xcall.txt b/lib/xcall.txt index b9f62409..8ace4345 100755 --- a/lib/xcall.txt +++ b/lib/xcall.txt @@ -1,268 +1,268 @@ -2E0DGP IO83 -5P6MJ JO54 -AA2UK FM29 -AA4HV EM55 -AA4QE EM78 -AA7UN DN32 -AB6BT CM88 -AB9QZ EN41 -AC4VM EM78 -AC9QI EN52 -AD0PL EM48 -AD9H EN61 -AF5NP EM10 -AF7M DM42 -AG4QX EL87 -AH0U CM97 -AK3Q EM79 -CC6IJM FO03 -CE4SFG FF45 -CF7GEM CN89 -CO2DC EL83 -CO2ER EL83 -CO2YQ EL83 -CO3LT EL93 -CT1FIU IN50 -CT7AEL IM69 -CU2DX HM77 -DL5UZ JN49 -DL6BEN JO44 -EA1AAE IN81 -EA5IGV IM99 -EA5ISK IM99 -EA5WO IM99 -EA5YI IM99 -EA7OM IM87 -EB3ENW JN11 -F6CAX JO00 -F6GCP JN18 -G4IUA IO91 -GI4FUE IO74 -HK2PMR FJ29 -HK4SAN FJ26 -HK6JCF FJ25 -I3FGX JN55 -IK2DJV JN45 -IK5BSC JN53 -IK8IJN JM78 -IN3BJS JN55 -IS0FWY JM49 -IU8CNE JN71 -IW4EJK JN54 -JA9AVA PM86 -JA9LJS PM86 -JR3IIR PM74 -K0AY FN20 -K1BMW CM99 -K1GG EM97 -K1HTV FM18 -K1VOI FN32 -K2AK DM41 -K2RMA EM90 -K2SST EM85 -K2TE EL98 -K3DBD FN20 -K3ZGA EL98 -K4DL EM63 -K4ELI EM74 -K4OP EM77 -K4SHQ EM64 -K5CIA EM12 -K5EJ EM45 -K5KLA EL49 -K5RCD EL09 -K5RWD EL09 -K5WP EM71 -K6JQ CM88 -K6MKF CM97 -K6RIM CM87 -K6SJT DM13 -K7CAH CN87 -K7NN DM42 -K7VNE DM43 -K9LRE EM57 -K9PY EN61 -KA1AQP FN42 -KA4RSZ EM73 -KA5JTM EL29 -KA6A EM13 -KA8TBW EN61 -KA9KQH EM59 -KB2M EL99 -KB5IKR EM70 -KC6AWX CM88 -KC9H EN62 -KC9UPE EN53 -KC9WIB EN61 -KC9WNZ EM48 -KD9E EM58 -KE0HQZ EN12 -KE0N EN34 -KE7HHW DN13 -KF4ZLO EM78 -KG5GCC EM50 -KG6TT CM88 -KG7GPM DN17 -KI7JFH CN85 -KI7MT DN46 -KK0M CM97 -KK6PTO DM14 -KM2J EL87 -KM4DDJ EM76 -KM4PJJ EM72 -KN1SIX EM90 -KN4CRD EM73 -KN9TVE EN52 -KO4PU EM67 -KP2L EM93 -KP4KD EL95 -KP4PR FK68 -KP4SX FK78 -KR6EN EM59 -KS0CW FM16 -KS4OT EM83 -KW4HT EM64 -LA5SJA KQ50 -LU6UBM FF84 -LU8AFR GF05 -LU8DQS GF05 -LU8EKC GF05 -LV7QFH EM95 -LZ1OI KN22 -M0LVL IO84 -M0OIC IO92 -M6RUG IO83 -MI0KOA IO74 -MM0LGS IO85 -N0BAK EN34 -N1SER EM90 -N2BJ EN61 -N2PPI FN30 -N3HI DM03 -N3MK FM27 -N4HYK EL87 -N4LAG EM85 -N4MKA EM84 -N5AYB EL17 -N5BCA EM12 -N5BSA EM12 -N5SLY EM13 -N6GP DM13 -N6OJ CM88 -N6PM DM13 -N6QQ DM03 -N6UK DM14 -N7IP DN26 -N7IY CN84 -N7NT DM43 -N7ZO CN85 -N8EHW EN81 -N8HMG EN91 -N8JAF EM89 -N9MUF EN51 -N9NTC EN53 -NA6L DM12 -NE6I DM12 -NN3V DM13 -NQ6F DM12 -NS2X EM76 -NU4T EM74 -NV8B EN63 -NX8Y EN80 -NY4I EL87 -ON3BZ JO20 -ON3EA JO21 -ON3LMA JO20 -ON7ZV JO20 -OT1V JO20 -OX6EYS LB60 -OZ1FHU JO55 -PA2GP JO33 -PD0LH JO22 -PD9BG JO21 -PE2K JO22 -PR7MB HI22 -PY2LK GG66 -PY2RJ GG66 -PY2XIZ GG66 -PY2YZB GG66 -PY4OY GG78 -PY7BC HI21 -RW0SR OO22 -SM6THE JO68 -SV2WT KN10 -TI4DJ EK70 -UT7QF KN77 -VA3DAZ EN82 -VA3LU EN58 -VE7AHT CN89 -VE9GJ FN77 -W0OGH DM52 -W0TW EN74 -W0YF EN11 -W1PFZ FN42 -W2HRO FN20 -W2PKY EL88 -W3BI FN20 -W3BS EM55 -W3KM FN20 -W3MR FM18 -W4EIS EM13 -W4GE FM02 -W4JSI EM64 -W4SFG EM74 -W4WYI EM83 -W5JPT EM11 -W5ZTX EL29 -W6AER CM87 -W6AUN DM79 -W6NWS FM05 -W6RYO DM08 -W7AUF CN85 -W7CT DN41 -W7DMC CN85 -W7SUR DM49 -W7VP CN87 -W8AKS EM97 -W8FHF EN90 -W8HC EM98 -W8MSC EN82 -W8OI EM88 -W8RES EM79 -W8WEJ EM99 -W8WKE EL16 -W9CTH EM69 -W9EO DM04 -W9WB EN51 -W9YSX EM79 -WA0LIF EN35 -WA1SXK EM95 -WA2HIP FN54 -WA4MIT EM63 -WA4VJK EM66 -WA6PHR CM94 -WA7DVD DN40 -WA9DU EM69 -WA9EIC EN60 -WA9JWL EN70 -WA9NNN EN61 -WB2JEP DM33 -WB2KSP FN31 -WB2REM EL97 -WB3FSR FN20 -WB5OZA EM30 -WB5TKI EL29 -WB5UDI EM20 -WB5XX EM33 -WB7UZO CN78 -WD4KAV CN87 -WD5IQR EM10 -WE5EE EL49 -WL7CG BP61 -WP4NSE FK68 -WS5W EM13 -WV5Y EL29 -WV8DOH EM99 -WV9L EM59 -WW7B DM33 -YV5BM FK60 +2E0DGP IO83 +5P6MJ JO54 +AA2UK FM29 +AA4HV EM55 +AA4QE EM78 +AA7UN DN32 +AB6BT CM88 +AB9QZ EN41 +AC4VM EM78 +AC9QI EN52 +AD0PL EM48 +AD9H EN61 +AF5NP EM10 +AF7M DM42 +AG4QX EL87 +AH0U CM97 +AK3Q EM79 +CC6IJM FO03 +CE4SFG FF45 +CF7GEM CN89 +CO2DC EL83 +CO2ER EL83 +CO2YQ EL83 +CO3LT EL93 +CT1FIU IN50 +CT7AEL IM69 +CU2DX HM77 +DL5UZ JN49 +DL6BEN JO44 +EA1AAE IN81 +EA5IGV IM99 +EA5ISK IM99 +EA5WO IM99 +EA5YI IM99 +EA7OM IM87 +EB3ENW JN11 +F6CAX JO00 +F6GCP JN18 +G4IUA IO91 +GI4FUE IO74 +HK2PMR FJ29 +HK4SAN FJ26 +HK6JCF FJ25 +I3FGX JN55 +IK2DJV JN45 +IK5BSC JN53 +IK8IJN JM78 +IN3BJS JN55 +IS0FWY JM49 +IU8CNE JN71 +IW4EJK JN54 +JA9AVA PM86 +JA9LJS PM86 +JR3IIR PM74 +K0AY FN20 +K1BMW CM99 +K1GG EM97 +K1HTV FM18 +K1VOI FN32 +K2AK DM41 +K2RMA EM90 +K2SST EM85 +K2TE EL98 +K3DBD FN20 +K3ZGA EL98 +K4DL EM63 +K4ELI EM74 +K4OP EM77 +K4SHQ EM64 +K5CIA EM12 +K5EJ EM45 +K5KLA EL49 +K5RCD EL09 +K5RWD EL09 +K5WP EM71 +K6JQ CM88 +K6MKF CM97 +K6RIM CM87 +K6SJT DM13 +K7CAH CN87 +K7NN DM42 +K7VNE DM43 +K9LRE EM57 +K9PY EN61 +KA1AQP FN42 +KA4RSZ EM73 +KA5JTM EL29 +KA6A EM13 +KA8TBW EN61 +KA9KQH EM59 +KB2M EL99 +KB5IKR EM70 +KC6AWX CM88 +KC9H EN62 +KC9UPE EN53 +KC9WIB EN61 +KC9WNZ EM48 +KD9E EM58 +KE0HQZ EN12 +KE0N EN34 +KE7HHW DN13 +KF4ZLO EM78 +KG5GCC EM50 +KG6TT CM88 +KG7GPM DN17 +KI7JFH CN85 +KI7MT DN46 +KK0M CM97 +KK6PTO DM14 +KM2J EL87 +KM4DDJ EM76 +KM4PJJ EM72 +KN1SIX EM90 +KN4CRD EM73 +KN9TVE EN52 +KO4PU EM67 +KP2L EM93 +KP4KD EL95 +KP4PR FK68 +KP4SX FK78 +KR6EN EM59 +KS0CW FM16 +KS4OT EM83 +KW4HT EM64 +LA5SJA KQ50 +LU6UBM FF84 +LU8AFR GF05 +LU8DQS GF05 +LU8EKC GF05 +LV7QFH EM95 +LZ1OI KN22 +M0LVL IO84 +M0OIC IO92 +M6RUG IO83 +MI0KOA IO74 +MM0LGS IO85 +N0BAK EN34 +N1SER EM90 +N2BJ EN61 +N2PPI FN30 +N3HI DM03 +N3MK FM27 +N4HYK EL87 +N4LAG EM85 +N4MKA EM84 +N5AYB EL17 +N5BCA EM12 +N5BSA EM12 +N5SLY EM13 +N6GP DM13 +N6OJ CM88 +N6PM DM13 +N6QQ DM03 +N6UK DM14 +N7IP DN26 +N7IY CN84 +N7NT DM43 +N7ZO CN85 +N8EHW EN81 +N8HMG EN91 +N8JAF EM89 +N9MUF EN51 +N9NTC EN53 +NA6L DM12 +NE6I DM12 +NN3V DM13 +NQ6F DM12 +NS2X EM76 +NU4T EM74 +NV8B EN63 +NX8Y EN80 +NY4I EL87 +ON3BZ JO20 +ON3EA JO21 +ON3LMA JO20 +ON7ZV JO20 +OT1V JO20 +OX6EYS LB60 +OZ1FHU JO55 +PA2GP JO33 +PD0LH JO22 +PD9BG JO21 +PE2K JO22 +PR7MB HI22 +PY2LK GG66 +PY2RJ GG66 +PY2XIZ GG66 +PY2YZB GG66 +PY4OY GG78 +PY7BC HI21 +RW0SR OO22 +SM6THE JO68 +SV2WT KN10 +TI4DJ EK70 +UT7QF KN77 +VA3DAZ EN82 +VA3LU EN58 +VE7AHT CN89 +VE9GJ FN77 +W0OGH DM52 +W0TW EN74 +W0YF EN11 +W1PFZ FN42 +W2HRO FN20 +W2PKY EL88 +W3BI FN20 +W3BS EM55 +W3KM FN20 +W3MR FM18 +W4EIS EM13 +W4GE FM02 +W4JSI EM64 +W4SFG EM74 +W4WYI EM83 +W5JPT EM11 +W5ZTX EL29 +W6AER CM87 +W6AUN DM79 +W6NWS FM05 +W6RYO DM08 +W7AUF CN85 +W7CT DN41 +W7DMC CN85 +W7SUR DM49 +W7VP CN87 +W8AKS EM97 +W8FHF EN90 +W8HC EM98 +W8MSC EN82 +W8OI EM88 +W8RES EM79 +W8WEJ EM99 +W8WKE EL16 +W9CTH EM69 +W9EO DM04 +W9WB EN51 +W9YSX EM79 +WA0LIF EN35 +WA1SXK EM95 +WA2HIP FN54 +WA4MIT EM63 +WA4VJK EM66 +WA6PHR CM94 +WA7DVD DN40 +WA9DU EM69 +WA9EIC EN60 +WA9JWL EN70 +WA9NNN EN61 +WB2JEP DM33 +WB2KSP FN31 +WB2REM EL97 +WB3FSR FN20 +WB5OZA EM30 +WB5TKI EL29 +WB5UDI EM20 +WB5XX EM33 +WB7UZO CN78 +WD4KAV CN87 +WD5IQR EM10 +WE5EE EL49 +WL7CG BP61 +WP4NSE FK68 +WS5W EM13 +WV5Y EL29 +WV8DOH EM99 +WV9L EM59 +WW7B DM33 +YV5BM FK60 diff --git a/lib/xcor.f90 b/lib/xcor.f90 index 537534df..83937736 100755 --- a/lib/xcor.f90 +++ b/lib/xcor.f90 @@ -1,76 +1,76 @@ -!subroutine xcor(ss,ipk,nsteps,nsym,lag1,lag2,ccf,ccf0,lagpk,flip,fdot,nrobust) -subroutine xcor(ipk,nsteps,nsym,lag1,lag2,ccf,ccf0,lagpk,flip,fdot,nrobust) - -! Computes ccf of a row of ss and the pseudo-random array pr. Returns -! peak of the CCF and the lag at which peak occurs. For JT65, the -! CCF peak may be either positive or negative, with negative implying -! the "OOO" message. - - use jt65_mod - parameter (NHMAX=3413) !Max length of power spectra - parameter (NSMAX=552) !Max number of quarter-symbol steps - real ss(NSMAX,NHMAX) !2d spectrum, stepped by half-symbols - real a(NSMAX) -! real ccf(-44:118) - real ccf(lag1:lag2) - data lagmin/0/ !Silence g77 warning -! save - common/sync/ss - - df=12000.0/8192. -! dtstep=0.5/df - dtstep=0.25/df - fac=dtstep/(60.0*df) - do j=1,nsteps - ii=nint((j-nsteps/2)*fdot*fac)+ipk - if( (ii.ge.1) .and. (ii.le.NHMAX) ) then - a(j)=ss(j,ii) - endif - enddo - - if(nrobust.eq.1) then -! use robust correlation estimator to mitigate AGC attack spikes at beginning -! this reduces the number of spurious candidates overall - call pctile(a,nsteps,50,xmed) - do j=1,nsteps - if( a(j).ge.xmed ) then - a(j)=1 - else - a(j)=-1 - endif - enddo - endif - - ccfmax=0. - ccfmin=0. - do lag=lag1,lag2 - x=0. - do i=1,nsym - j=4*i-3+lag - if(j.ge.1 .and. j.le.nsteps) x=x+a(j)*pr(i) - enddo - ccf(lag)=2*x !The 2 is for plotting scale - if(ccf(lag).gt.ccfmax) then - ccfmax=ccf(lag) - lagpk=lag - endif - - if(ccf(lag).lt.ccfmin) then - ccfmin=ccf(lag) - lagmin=lag - endif - enddo - - ccf0=ccfmax - flip=1.0 - if(-ccfmin.gt.ccfmax) then - do lag=lag1,lag2 - ccf(lag)=-ccf(lag) - enddo - lagpk=lagmin - ccf0=-ccfmin - flip=-1.0 - endif - - return -end subroutine xcor +!subroutine xcor(ss,ipk,nsteps,nsym,lag1,lag2,ccf,ccf0,lagpk,flip,fdot,nrobust) +subroutine xcor(ipk,nsteps,nsym,lag1,lag2,ccf,ccf0,lagpk,flip,fdot,nrobust) + +! Computes ccf of a row of ss and the pseudo-random array pr. Returns +! peak of the CCF and the lag at which peak occurs. For JT65, the +! CCF peak may be either positive or negative, with negative implying +! the "OOO" message. + + use jt65_mod + parameter (NHMAX=3413) !Max length of power spectra + parameter (NSMAX=552) !Max number of quarter-symbol steps + real ss(NSMAX,NHMAX) !2d spectrum, stepped by half-symbols + real a(NSMAX) +! real ccf(-44:118) + real ccf(lag1:lag2) + data lagmin/0/ !Silence g77 warning +! save + common/sync/ss + + df=12000.0/8192. +! dtstep=0.5/df + dtstep=0.25/df + fac=dtstep/(60.0*df) + do j=1,nsteps + ii=nint((j-nsteps/2)*fdot*fac)+ipk + if( (ii.ge.1) .and. (ii.le.NHMAX) ) then + a(j)=ss(j,ii) + endif + enddo + + if(nrobust.eq.1) then +! use robust correlation estimator to mitigate AGC attack spikes at beginning +! this reduces the number of spurious candidates overall + call pctile(a,nsteps,50,xmed) + do j=1,nsteps + if( a(j).ge.xmed ) then + a(j)=1 + else + a(j)=-1 + endif + enddo + endif + + ccfmax=0. + ccfmin=0. + do lag=lag1,lag2 + x=0. + do i=1,nsym + j=4*i-3+lag + if(j.ge.1 .and. j.le.nsteps) x=x+a(j)*pr(i) + enddo + ccf(lag)=2*x !The 2 is for plotting scale + if(ccf(lag).gt.ccfmax) then + ccfmax=ccf(lag) + lagpk=lag + endif + + if(ccf(lag).lt.ccfmin) then + ccfmin=ccf(lag) + lagmin=lag + endif + enddo + + ccf0=ccfmax + flip=1.0 + if(-ccfmin.gt.ccfmax) then + do lag=lag1,lag2 + ccf(lag)=-ccf(lag) + enddo + lagpk=lagmin + ccf0=-ccfmin + flip=-1.0 + endif + + return +end subroutine xcor diff --git a/lib/zplot9.f90 b/lib/zplot9.f90 index 96b6fe2a..6c56c9fc 100755 --- a/lib/zplot9.f90 +++ b/lib/zplot9.f90 @@ -1,31 +1,31 @@ -subroutine zplot9(s,freq,drift) - - real s(0:8,85) - character*1 line(85),mark(0:6) - data mark/' ',' ','.','-','+','X','$'/ - include 'jt9sync.f90' - - write(32,1000) freq,drift -1000 format('Freq:',f7.1,' Drift:',f5.1,' ',60('-')) - do j=8,0,-1 - do i=1,85 - n=(s(j,i)) - if(n.lt.0) n=0 - if(n.gt.6) n=6 - line(i)=mark(n) - enddo - write(32,1010) j,line -1010 format(i1,1x,85a1) - enddo - do i=1,85 - line(i)=' ' - if(isync(i).eq.1) line(i)='@' - enddo - write(32,1015) -1015 format(87('-')) - write(32,1020) line -1020 format(2x,85a1) - call flush(32) - - return -end subroutine zplot9 +subroutine zplot9(s,freq,drift) + + real s(0:8,85) + character*1 line(85),mark(0:6) + data mark/' ',' ','.','-','+','X','$'/ + include 'jt9sync.f90' + + write(32,1000) freq,drift +1000 format('Freq:',f7.1,' Drift:',f5.1,' ',60('-')) + do j=8,0,-1 + do i=1,85 + n=(s(j,i)) + if(n.lt.0) n=0 + if(n.gt.6) n=6 + line(i)=mark(n) + enddo + write(32,1010) j,line +1010 format(i1,1x,85a1) + enddo + do i=1,85 + line(i)=' ' + if(isync(i).eq.1) line(i)='@' + enddo + write(32,1015) +1015 format(87('-')) + write(32,1020) line +1020 format(2x,85a1) + call flush(32) + + return +end subroutine zplot9 diff --git a/lib/zplt.f90 b/lib/zplt.f90 index d91eefd1..a7f6e571 100755 --- a/lib/zplt.f90 +++ b/lib/zplt.f90 @@ -1,112 +1,112 @@ -subroutine zplt(z,iplt,sync,dtx,nfreq,flip,sync2,nplot,emedelay,dttol, & - nfqso,ntol) - - real z(458,65) - real zz(458,65) - integer ij(2) - character*4 lab - - call pctile(z,458*65,84,rms) - fac=0.05/rms - z=fac*z - dtq=0.114286 - df=11025.0/(2.0*2520.0) - - ia=nint((nfqso-ntol)/df) - 273 - if(ia.lt.1) ia=1 - ib=nint((nfqso+ntol)/df) - 273 - if(ib.gt.458) ib=458 - ja=(emedelay+0.8-dttol)/dtq - if(ja.lt.1) ja=1 - jb=(emedelay+0.8+dttol)/dtq - if(jb.gt.65) jb=65 - - zz=0. - zz(ia:ib,ja:jb)=z(ia:ib,ja:jb) - - zmin=minval(zz) - zmax=maxval(zz) - flip=1.0 - if(abs(zmin).gt.abs(zmax)) flip=-1.0 - - ij=maxloc(zz) - if(flip.lt.0.0) ij=minloc(zz) - i0=ij(1) - j0=ij(2) - nfreq=nint((i0+273)*df) - dtx=j0*dtq-0.8 -! write(69,3101) ia,ib,ja,jb,ij,dtx,nfreq -!3101 format(6i5,f8.2,i6) - - ia=max(1,i0-72) - ib=min(458,i0+72) - sync=16.33*flip*(z(i0,j0) - 0.5*(z(ia,j0)+z(ib,j0))) - sync2=20.0*flip*z(i0,j0) - - if(nplot.eq.0) go to 900 - - zmax=max(abs(zmin),abs(zmax),1.0) - zmin=-zmax - - do j=1,65 - write(61,1100) j*dtq-0.8,z(i0,j) -1100 format(2f10.3) - enddo - - do i=1,458 - write(62,1100) (i+273)*df,flip*z(i,j0) - enddo - - xx=1.5 - yy=7.5 - 3.0*iplt - width=6.0 - height=2.0 - IP=458 - JP=65 - imax=IP - jmax=JP - - if(iplt.eq.0) then - call imopen("testjt4.ps") - call imfont("Helvetica",16) - call impalette("BlueRed.pal") - endif - - call imr4mat_color(z,IP,JP,imax,jmax,zmin,zmax,xx,yy, & - width,height,1) - call imstring("Frequency (Hz)",xx+0.5*width,yy-0.5,2,0) - dy=0.1 - do i=1,9 - x=xx + 0.1*i*width - call imyline(x,yy,dy) - call imyline(x,yy+height,-dy) - enddo - do i=1,6 - nf=(i-1)*200 + 600 - write(lab,1020) nf -1020 format(i4) - x=xx + (i-1)*0.2*width - call imstring(lab,x,yy-0.25,2,0) - enddo - - dx=0.1 - do i=0,6 - y=yy + height*(0.8+i)/(65.0*0.114286) - call imxline(xx,y,dx) - call imxline(xx+width,y,-dx) - enddo - - do i=0,6,2 - y=yy + height*(0.8+i)/(65.0*0.114286) - write(lab,1020) i - call imstring(lab(4:4),xx-0.15,y-0.08,2,0) - enddo - - y=yy + height*(3.8)/(65.0*0.114286) - call imstring("DT", xx-0.5,y ,2,0) - call imstring("(s)",xx-0.5,y-0.25,2,0) - - if(iplt.eq.2) call imclose - -900 return -end subroutine zplt +subroutine zplt(z,iplt,sync,dtx,nfreq,flip,sync2,nplot,emedelay,dttol, & + nfqso,ntol) + + real z(458,65) + real zz(458,65) + integer ij(2) + character*4 lab + + call pctile(z,458*65,84,rms) + fac=0.05/rms + z=fac*z + dtq=0.114286 + df=11025.0/(2.0*2520.0) + + ia=nint((nfqso-ntol)/df) - 273 + if(ia.lt.1) ia=1 + ib=nint((nfqso+ntol)/df) - 273 + if(ib.gt.458) ib=458 + ja=(emedelay+0.8-dttol)/dtq + if(ja.lt.1) ja=1 + jb=(emedelay+0.8+dttol)/dtq + if(jb.gt.65) jb=65 + + zz=0. + zz(ia:ib,ja:jb)=z(ia:ib,ja:jb) + + zmin=minval(zz) + zmax=maxval(zz) + flip=1.0 + if(abs(zmin).gt.abs(zmax)) flip=-1.0 + + ij=maxloc(zz) + if(flip.lt.0.0) ij=minloc(zz) + i0=ij(1) + j0=ij(2) + nfreq=nint((i0+273)*df) + dtx=j0*dtq-0.8 +! write(69,3101) ia,ib,ja,jb,ij,dtx,nfreq +!3101 format(6i5,f8.2,i6) + + ia=max(1,i0-72) + ib=min(458,i0+72) + sync=16.33*flip*(z(i0,j0) - 0.5*(z(ia,j0)+z(ib,j0))) + sync2=20.0*flip*z(i0,j0) + + if(nplot.eq.0) go to 900 + + zmax=max(abs(zmin),abs(zmax),1.0) + zmin=-zmax + + do j=1,65 + write(61,1100) j*dtq-0.8,z(i0,j) +1100 format(2f10.3) + enddo + + do i=1,458 + write(62,1100) (i+273)*df,flip*z(i,j0) + enddo + + xx=1.5 + yy=7.5 - 3.0*iplt + width=6.0 + height=2.0 + IP=458 + JP=65 + imax=IP + jmax=JP + + if(iplt.eq.0) then + call imopen("testjt4.ps") + call imfont("Helvetica",16) + call impalette("BlueRed.pal") + endif + + call imr4mat_color(z,IP,JP,imax,jmax,zmin,zmax,xx,yy, & + width,height,1) + call imstring("Frequency (Hz)",xx+0.5*width,yy-0.5,2,0) + dy=0.1 + do i=1,9 + x=xx + 0.1*i*width + call imyline(x,yy,dy) + call imyline(x,yy+height,-dy) + enddo + do i=1,6 + nf=(i-1)*200 + 600 + write(lab,1020) nf +1020 format(i4) + x=xx + (i-1)*0.2*width + call imstring(lab,x,yy-0.25,2,0) + enddo + + dx=0.1 + do i=0,6 + y=yy + height*(0.8+i)/(65.0*0.114286) + call imxline(xx,y,dx) + call imxline(xx+width,y,-dx) + enddo + + do i=0,6,2 + y=yy + height*(0.8+i)/(65.0*0.114286) + write(lab,1020) i + call imstring(lab(4:4),xx-0.15,y-0.08,2,0) + enddo + + y=yy + height*(3.8)/(65.0*0.114286) + call imstring("DT", xx-0.5,y ,2,0) + call imstring("(s)",xx-0.5,y-0.25,2,0) + + if(iplt.eq.2) call imclose + +900 return +end subroutine zplt -- cgit v1.2.3