1127
1131
call TanhSinh_Exact(c%c_io%N,ce,cw,a,b, p=tmp)
1137
! Read the file information
1138
call contour_file(c,mu,Eta)
1133
1141
write(*,*) 'Method for contour ',trim(c%c_io%name), &
1134
1142
' could not be deciphered: ', c%c_io%method
1135
1143
call die('Could not determine the line-integral')
1138
! I know this is "bad" practice, however, zero is a well-defined quantity.
1139
set_c = sum(abs(c%c(:))) == 0._dp
1141
1146
! get the index in the ID array (same index in w-array)
1142
1147
call ID2idx(c,mu%ID,idx)
1149
if ( method(c%c_io) == CC_USER ) then
1152
c%w(idx,i) = c%w(idx,i) * nf((real(c%c(i), dp) - mu%mu) / mu%kT)
1157
! I know this is "bad" practice, however, zero is a well-defined quantity.
1158
set_c = sum(abs(c%c(:))) == 0._dp
1146
1162
c%c(i) = dcmplx(ce(i),Eta)
1148
1164
if ( abs(c%c(i) - dcmplx(ce(i),Eta)) > 1.e-10_dp ) then
1149
call die('contour_line: Error on contour match')
1165
call die('contour_line: Error on contour match')
1153
!ztmp = (c%c(i) - mu%mu) / mu%kT
1154
c%w(idx,i) = cw(i) * nf((ce(i) - mu%mu) / mu%kT)
1169
c%w(idx,i) = cw(i) * nf((ce(i) - mu%mu) / mu%kT)
1158
1175
deallocate(ce,cw)
1160
1177
end subroutine contour_line
1439
1458
end subroutine contour_continued_fraction
1460
! This routine will read the contour points from a file
1461
subroutine contour_file(c,mu,Eta)
1462
use m_io, only: io_assign, io_close
1463
use fdf, only: fdf_convfac
1465
type(ts_cw), intent(inout) :: c
1466
type(ts_mu), intent(in) :: mu
1467
! The lifting into the complex plane
1468
real(dp), intent(in) :: Eta
1470
integer :: iu, iostat, ne, idx
1472
complex(dp) :: E , W
1473
real(dp) :: rE, iE, rW, iW, conv
1474
character(len=512) :: file, line
1475
character(len=16) :: unit
1477
! The contour type contains the file name in:
1478
! c%c_io%cN (weirdly enough)
1480
call ID2idx(c,mu%ID,idx)
1484
! Open the contour file
1485
inquire(file=trim(file), exist=exist)
1486
if ( .not. exist ) then
1487
call die('The file: '//trim(file)//' could not be found to read contour points!')
1491
open(iu, file=trim(file), form='formatted', status='old')
1494
! The default unit is eV.
1495
! On every line an optional unit-specificer may be used to specify the
1496
! subsequent lines units (until another unit is specified)
1497
conv = fdf_convfac('eV', 'Ry')
1499
! Now we have the line
1500
read(iu, '(a)', iostat=iostat) line
1501
if ( iostat /= 0 ) exit
1502
if ( len_trim(line) == 0 ) cycle
1503
line = trim(adjustl(line))
1504
if ( line(1:1) == '#' ) cycle
1506
! We have a line with energy and weight
1508
! There are three optional ways of reading this
1509
! 1. ReE ImE, ReW ImW [unit]
1510
read(line, *, iostat=iostat) rE, iE, rW, iW, unit
1511
if ( iostat == 0 ) then
1512
conv = fdf_convfac(unit, 'Ry')
1514
read(line, *, iostat=iostat) rE, iE, rW, iW
1516
if ( iostat == 0 ) then
1517
c%c(ne) = dcmplx(rE,iE) * conv
1518
c%w(idx,ne) = dcmplx(rW,iW) * conv
1522
! 2. ReE ImE, ReW [unit]
1524
read(line, *, iostat=iostat) rE, iE, rW, unit
1525
if ( iostat == 0 ) then
1526
conv = fdf_convfac(unit, 'Ry')
1528
read(line, *, iostat=iostat) rE, iE, rW
1530
if ( iostat == 0 ) then
1531
c%c(ne) = dcmplx(rE,iE) * conv
1532
c%w(idx,ne) = dcmplx(rW,iW) * conv
1536
! 3. ReE , ReW [unit]
1539
read(line, *, iostat=iostat) rE, rW, unit
1540
if ( iostat == 0 ) then
1541
conv = fdf_convfac(unit, 'Ry')
1543
read(line, *, iostat=iostat) rE, rW
1545
if ( iostat == 0 ) then
1546
c%c(ne) = dcmplx(rE * conv,iE)
1547
c%w(idx,ne) = dcmplx(rW,iW) * conv
1551
call die('Contour file: '//trim(file)//' is not formatted correctly. &
1552
&Please read the documentation!')
1558
if ( c%c_io%N /= ne ) then
1559
call die('Error in reading the contour points from file: '//trim(file))
1562
end subroutine contour_file
1441
1564
function Eq_E(id,step) result(c)
1442
1565
integer, intent(in) :: id
1443
1566
integer, intent(in), optional :: step