summaryrefslogtreecommitdiff
path: root/tests/unit/jt65/test_jt65_xcor_silence.f90
blob: 27fbadfb228c64711a6f6f7890dc0e62bb78c991 (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
program test_jt65_xcor_silence

  use jt65_mod, only: jt65_work, ensure_jt65_workspace
  implicit none

  integer, parameter :: lag1 = -32, lag2 = 82, nhmax = 3413, nsmax = 552
  real :: ccf(lag1:lag2), ccf0, flip
  integer :: lagpk


  call setup65
  call ensure_jt65_workspace()
  allocate(jt65_work%spectra(nsmax,nhmax))
  jt65_work%spectra = 0.0
  lagpk = huge(0)

  call xcor(1,nsmax,126,lag1,lag2,ccf,ccf0,lagpk,flip,0.0,0)

  call require(lagpk == lag1, 'silence returns the first valid lag')
  call require(all(ccf == 0.0), 'silence produces zero correlation')
  call require(ccf0 == 0.0, 'silence produces a zero peak')
  call require(flip == 1.0, 'silence keeps normal polarity')

contains

  subroutine require(condition, description)
    logical, intent(in) :: condition
    character(len=*), intent(in) :: description

    if (.not. condition) then
       print '(a)', 'FAIL: '//description
       error stop 1
    end if
  end subroutine require

end program test_jt65_xcor_silence