aboutsummaryrefslogtreecommitdiff
path: root/src/matdet.F90
blob: 3ac922671b82b4e6ecbac2e720bce13b5990a6fd (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
! $Header$

#include "cctk.h"

module matdet
  use lapack
  implicit none
  private
  
  public calc_symdet4
  
contains
  
  subroutine calc_symdet4 (g4, dtg4, lerr)
    CCTK_REAL,           intent(in)  :: g4(4,4)
    CCTK_REAL,           intent(out) :: dtg4
    logical,   optional, intent(out) :: lerr
    CCTK_REAL :: tmp(4,4)
    integer   :: ipiv(4)
    integer   :: info
    integer   :: nperms
    integer   :: i
    character :: msg*100
    
    tmp = g4
    call sytrf (4, 4, tmp, 4, ipiv, info)
    
    if (info < 0) then
       write (msg, '("Error in call to SYTRF, info=",i4)') info
       call CCTK_WARN (1, msg)
    end if
    
    if (present(lerr)) lerr = info /= 0
    
    if (info > 0) then
       dtg4 = 0
       return
    end if
    
    nperms = 0
    do i=1,4
       if (mod(ipiv(i),2) /= mod(i,2)) nperms = nperms+1
    end do
    if (mod(nperms,2) /=0) call CCTK_WARN (0, "internal error")
    nperms = nperms / 2
    
    dtg4 = 1
    if (mod(nperms,2)/=0) dtg4 = -1
    do i=1,4
       dtg4 = dtg4 * tmp(i,i)
    end do
  end subroutine calc_symdet4
  
end module matdet