1!
2! Copyright (C) 1996-2016	The SIESTA group
3!  This file is distributed under the terms of the
4!  GNU General Public License: see COPYING in the top directory
5!  or http://www.gnu.org/copyleft/gpl.txt.
6! See Docs/Contributors.txt for a list of contributors.
7!
8      subroutine read_xc_info()
9C
10C     Reads the exchange-correlation functional information
11C     and calls setXC to store it
12C
13      use precision, only : dp
14      use SiestaXC,  only : setXC
15      use fdf
16      use parallel,  only : Node
17      use sys,       only : die
18
19      implicit none
20
21C     LOCAL variables
22
23      integer, parameter      :: MaxFunc = 10
24      integer                 :: nXCfunc
25      character(len=20)       :: XCauth(MaxFunc)
26      character(len=20)       :: XCfunc(MaxFunc)
27      real(dp)                :: XCweightX(MaxFunc)
28      real(dp)                :: XCweightC(MaxFunc)
29
30        integer            :: n
31        integer            :: ni
32        integer            :: nn
33        integer            :: nr
34
35        type(block_fdf)            :: bfdf
36        type(parsed_line), pointer :: pline
37
38C Read XC functionals
39        if (fdf_block('xc.hybrid',bfdf)) then
40          if (.not. fdf_bline(bfdf,pline)) then
41            call die('setXC: ERROR no data in XC.hybrid block')
42          endif
43          ni = fdf_bnintegers(pline)
44
45          if (ni .eq. 0) then
46            call die('setXC: Number of functionals missing in ' //
47     .               'XC.hybrid')
48          endif
49          nXCfunc = abs(fdf_bintegers(pline,1))
50          if (nXCfunc .gt. MaxFunc) then
51            call die('setXC: Too many functionals in XC.hybrid')
52          endif
53          do n= 1, nXCfunc
54            if (.not. fdf_bline(bfdf,pline)) then
55              call die('setXC: Number of XC functionals does not match')
56            endif
57            nn = fdf_bnnames(pline)
58            nr = fdf_bnreals(pline)
59
60            if (nn .gt. 0) then
61              XCfunc(n) = fdf_bnames(pline,1)
62            else
63              XCfunc(n) = 'LDA'
64            endif
65            if (nn .gt. 1) then
66              XCauth(n) = fdf_bnames(pline,2)
67            else
68              XCauth(n) = 'PZ'
69            endif
70            if (nr .gt. 1) then
71              XCweightX(n) = fdf_breals(pline,1)
72              XCweightC(n) = fdf_breals(pline,2)
73            elseif (nr .eq. 1) then
74              XCweightX(n) = fdf_breals(pline,1)
75              XCweightC(n) = fdf_breals(pline,1)
76            else
77              XCweightX(n) = 1.0_dp
78              XCweightC(n) = 1.0_dp
79            endif
80          enddo
81          call fdf_bclose(bfdf)
82        else
83          nXCfunc = 1
84          XCfunc(1) = fdf_string('xc.functional','LDA')
85          XCauth(1) = fdf_string('xc.authors','PZ')
86          XCweightX(1) = 1.0_dp
87          XCweightC(1) = 1.0_dp
88        endif
89
90C Output data for hybrid functionals
91        if ((nXCfunc .gt. 1) .and. (Node .eq. 0)) then
92          write(6,'(/,''xc:'')')
93          write(6,'(''xc:  Hybrid exchange-correlation functional:'')
94     .      ')
95          write(6,'(''xc:'')')
96          write(6,'(''xc: Number     Functional     Authors  '',
97     .      ''   Weight(Ex)   Weight(Ec)'')')
98          do n = 1,nXCfunc
99          write(6,'(''xc: '',i4,3x,a20,2x,a20,3x,f5.3,8x,f5.3)')
100     .        n,XCfunc(n),XCauth(n),XCweightX(n),XCweightC(n)
101          enddo
102          write(6,'(''xc:'')')
103        endif
104
105C     Store information in module
106
107      call setXC (n=nXCfunc, func=XCfunc, auth=XCauth,
108     $            wx=XCweightX, wc=XCweightC)
109
110      end subroutine read_xc_info
111
112