summaryrefslogtreecommitdiff
path: root/map65/libm65/run_m65.f90
blob: 140420162621c014ad84591d3c38a7426ab042a3 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
module run_m65_mod
   use iso_c_binding
   implicit none
contains

subroutine run_m65(pol, sample_rate_96000) bind(C, name='run_m65_')
  use iso_c_binding
  use timer_module, only: timer
  use timer_impl, only: init_timer, fini_timer
  use debug_log
  use m65a_mod
  use npar_ptrs_mod, only: snapshot_release, t_start, nhsym, mycall, hiscall, hisgrid, neme, &
                            initialize_decode_parameters, claim_decode_request, get_stop_m65, &
                            active_request_id, active_request_expired
  use stdout_channel_mod, only: write_stdout
  use decodes_mod, only: nhsym1,nhsym2
  use deep65_mod, only: build_call3_candidates
  use sleep_msec_mod
  use sec_midn_mod, only: sec_midn

  implicit none

  integer(c_int), intent(in) :: pol, sample_rate_96000

  ! Local variables
  integer :: sample_rate
  character(len=128) :: line
  integer :: t_rate
  integer :: t_now

  nhsym1=280
  nhsym2=302

  dbg_enabled = .false.   ! flip to .true. to enable dbg() logging to w3sz_debug.log

  if (sample_rate_96000 /=0) then
     sample_rate = 96000
  else
     sample_rate = 95238   ! 96000 / 1.008, legacy WSJT slow-96k correction
  endif
  call write_stdout('STARTING RUN_M65'//new_line('a'))

  ! and one of the others, e.g.
  write (line, '(A, I0)') ' ********** IN RUN_M65 sample_rate is: ', sample_rate
  call write_stdout(trim(line)//new_line('a'))

!  if (.not. associated(savg)) then
  !   print *, 'ERROR:RUN_M65 savg is not associated!'
!  else
  !   print *, 'RUN_M65 savg is associated. Shape =', shape(savg), " loc:", loc(savg)
!  end if

!  if (.not. associated(dd)) then
  !   print *, 'ERROR: RUN_M65 dd is not associated!'
!  else
  !   print *, 'RUN_M65 dd is associated. Shape =', shape(dd), " loc:", loc(dd)
!  end if

!  if (.not. associated(ss)) then
  !   print *, 'ERROR: RUN_M65 ss is not associated!'
!  else
  !   print *, 'RUN_M65 ss is associated. Shape =', shape(ss), " loc:", loc(ss)
!  end if

!  print *, ' ********** IN RUN_M65 sample_rate_96000 is: ', sample_rate
!  flush (6)
!  print *, ' ********** IN RUN_M65 pol is: ', pol
!  flush (6)

  !print *, 'IN RUN_M65, initial stop_m65 =', stop_m65
  !flush(6)

  call init_timer()
  call initialize_decode_parameters()

  ! Encode the CALL3.TXT candidates before the first decode's time budget starts.
  ! deep65 rebuilds them when calls, grids, the EME filter, or CALL3.TXT change.
  call dbg('run_m65: eager build_call3_candidates() STARTING at t=' // rtoa(sec_midn()))
  call build_call3_candidates(mycall, hiscall, hisgrid, neme)
  call dbg('run_m65: eager build_call3_candidates() DONE at t=' // rtoa(sec_midn()))

  do while (get_stop_m65() == 0)
     if (claim_decode_request()) then
        if (active_request_expired) then
           write(line, '(A,1X,I0)') '<DecodeSkipped>', active_request_id
           call write_stdout(trim(line)//new_line('a'))
        else
           call system_clock(t_start, t_rate)
           call m65a()
           call system_clock(t_now)
           call snapshot_release()
           call dbg('run_m65: request completed, elapsed=' // rtoa(real(t_now - t_start)/real(t_rate)))
        endif
     endif
     call sleep_msec(50)
  end do

  call fini_timer()
  close(21)

end subroutine run_m65
end module run_m65_mod