summaryrefslogtreecommitdiff
path: root/lib/jt65_host_support.f90
blob: 6abd3b74d5be27f7d6aa7d9887f5142ef2231430 (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
module jt65_host_support
  use jt65_decode, only: jt65_decoder,jt65_average_entry
  use prog_args, only: data_dir
  implicit none
  private
  public :: load_jt65_calls,write_jt65_averages

contains

  subroutine load_jt65_calls(calls,grids)
    character(len=12), allocatable, intent(out) :: calls(:)
    character(len=4), allocatable, intent(out) :: grids(:)
    character(len=12), allocatable :: call_buffer(:)
    character(len=4), allocatable :: grid_buffer(:)
    character(len=180) :: line
    integer :: unit,ios,count,first,second

    allocate(call_buffer(10000),grid_buffer(10000))
    count=0
    open(newunit=unit,file=trim(data_dir)//'/CALL3.TXT',status='old',action='read',iostat=ios)
    if(ios==0) then
       do while(count<size(call_buffer))
          read(unit,'(a)',iostat=ios) line
          if(ios/=0) exit
          if(line(:4)=='ZZZZ'.or.line(:2)=='//') cycle
          first=index(line,',')
          if(first<4) cycle
          second=index(line(first+1:),',')
          if(second<5) cycle
          count=count+1
          call_buffer(count)=line(:first-1)
          grid_buffer(count)=line(first+1:first+4)
       enddo
       close(unit)
    endif
    calls=call_buffer(:count)
    grids=grid_buffer(:count)
  end subroutine load_jt65_calls

  subroutine write_jt65_averages(decoder,unit)
    class(jt65_decoder), intent(inout) :: decoder
    integer, intent(in) :: unit
    type(jt65_average_entry) :: entries(64)
    integer :: count,i
    character :: used,polarity

    call decoder%get_averages(entries,count)
    rewind(unit)
    do i=1,count
       used='.'
       if(entries(i)%used) used='$'
       polarity=' '
       if(entries(i)%polarity<0) polarity='#'
       if(entries(i)%polarity>0) polarity='*'
       write(unit,'(a1,i5.4,f6.1,f6.2,i6,1x,a1)') used,entries(i)%utc, &
            entries(i)%sync,entries(i)%dt,entries(i)%frequency,polarity
    enddo
    endfile(unit)
    flush(unit)
  end subroutine write_jt65_averages
end module jt65_host_support