corespec_eval.f90 286 KB
Newer Older
1 2 3 4 5 6 7 8
!--------------------------------------------------------------------------------
! Copyright (c) 2017 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

MODULE m_corespec_eval

9
  USE m_types_setup
10 11 12
  USE m_types_usdus       
  USE m_types_cdnval, ONLY: t_eigVecCoeffs        
  USE m_constants        
13
  USE m_corespec
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

  IMPLICIT NONE

  CONTAINS

!===============================================================================
!
!  S U B R O U T I N E   C O R E S P E C _ G A U N T
!
!-------------------------------------------------------------------------------
!
  SUBROUTINE corespec_gaunt()

!    use factorials
    
    use m_clebsch

    implicit none

!    real :: threejsymbol

    logical :: cmsum,clevn,ctiq1,ctiq2,ctiq3
    real :: twol1p1,twola1p1,twolip1

    smeno = "corespec_gaunt"

    write(*,'(/,a)') trim(smeno)//ssep

!    call init_factorials(6*(lmaxd+1)+1)

    ln = min(0,minval(csv%lc)-1)
    lx = max(csi%lx,maxval(csv%lc)+1)

    lan = 0
    lax = csi%lx+maxval(csv%lc)+1

    lin = minval(csv%lc)-1
    lix = maxval(csv%lc)+1

!!$    print*,"ln,lx,lan,lax,lin,lix"
!!$    print*,ln,lx,lan,lax,lin,lix

    if(.not.allocated(csv%gaunt)) &
         &allocate(csv%gaunt(ln:lx,-lx:lx,lan:lax,-lax:lax,lin:lix,-lix:lix))
58
    csv%gaunt = 0.0
59 60 61

! m<=l condition fulfilled by looping m within l value interval {-l,...,+l}

62
    csv%gaunt = 0.0
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    do l1 = ln,lx
      do m1 = -l1,l1
        do la1 = lan,lax
          do mu1 = -la1,la1
            do li = lin,lix
              do mi = -li,li
                cmsum = (m1+mu1-mi).eq.0  ! sum of m q-nos. = 0
                clevn = mod((l1+la1+li),2).eq.0  ! sum of l q-nos. is even
                ctiq1 = (la1+li-l1).ge.0  ! triangle inequality 1
                ctiq2 = (l1+li-la1).ge.0  ! triangle inequality 2
                ctiq3 = (l1+la1-li).ge.0  ! triangle inequality 3
                twol1p1 = dble(2*l1+1)
                twola1p1 = dble(2*la1+1)
                twolip1 = dble(2*li+1)
                if(cmsum.and.clevn.and.ctiq1.and.ctiq2.and.ctiq3) then
                  csv%gaunt(l1,m1,la1,mu1,li,mi) = &
!                       &threejsymbol((l1),(la1),0,0,(li),0)*&
!                       &threejsymbol((l1),(la1),(m1),(mu1),(li),-(mi)))&
                       &clebsch(real(l1),real(la1),0.0,0.0,real(li),0.0)*&
                       &clebsch(real(l1),real(la1),real(m1),real(mu1),real(li),real(mi))*&
83
                       &sqrt(twol1p1*twola1p1/(4.0*pi_const*twolip1))*&
84
                       &(-1)**(mi)
85
                  if(csv%gaunt(l1,m1,la1,mu1,li,mi).ne.0.0) &
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
                       &write(53,'(6i5,f12.6)') l1,m1,la1,mu1,li,-mi,csv%gaunt(l1,m1,la1,mu1,li,mi)
!!$                  if(abs(csv%gaunt(l1,m1,la1,mu1,li,mi)).lt.1.d-6) &
!!$                       &write(*,'(6i5,f24.20)') l1,m1,la1,mu1,li,-mi,csv%gaunt(l1,m1,la1,mu1,li,mi)
                endif
              enddo
            enddo
          enddo
        enddo
      enddo
    enddo

    if(csi%verb.eq.1) write(*,*) ""

  end subroutine corespec_gaunt
!
!===============================================================================
!===============================================================================
!
!  S U B R O U T I N E   C O R E S P E C _ R M E
!
!-------------------------------------------------------------------------------
!
  subroutine corespec_rme(atoms,input,itype,nstd,&
                          jspins,jspin,efermi,&
                          msh,vr,f,g)

    USE m_constants, ONLY : c_light
    USE m_setcor
    USE m_differ
    USE m_intgr, ONLY : intgr3
    USE m_dr2fdr
    USE m_sphbes
    USE m_intgr, ONLY : intgr3

    implicit none

    TYPE(t_atoms),INTENT(IN)   :: atoms
    TYPE(t_input),INTENT(IN)   :: input

    integer, intent(in) :: itype  ! call in ntype loop with itype = n
    integer, intent(in) :: nstd
    integer, intent(in) :: jspins,jspin
    real, intent(in) :: efermi
    integer, intent(in) :: msh
    real, intent    (in) :: vr(atoms%jmtd,atoms%ntype,jspins)
    real, intent (in) :: f(atoms%jmtd,2,0:atoms%lmaxd,jspin:jspin)
    real, intent (in) :: g(atoms%jmtd,2,0:atoms%lmaxd,jspin:jspin)

    integer :: nr,lx,lax,lin,lix,nqv,nen,nex

    integer :: ir,id,iljc,ic,il,ila,iqv,ie,ierr
    integer :: nst,kappa(nstd),nprnc(nstd)
    real :: nc,nlc,njc
    real :: c,bmu,t2,weight,e,d,rn,res,qr
    real :: vrd(msh),occ(nstd,jspins),a(msh),b(msh)
    real :: resd

    real, allocatable :: fpd(:)
    real, allocatable :: fp(:),fc(:),fsb(:)
    real :: sum1,sum2,sum3,sum1d,sum2d

    smeno = "corespec_rme"

149
    if(itype.ne.csi%atomType) return
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

    write(*,'(/,a)') trim(smeno)//ssep

    c = c_light(1.0)

    nr = atoms%jri(itype)

    allocate(fp(nr),fpd(nr),fc(nr))

  ! CORE functions
  ! csv%fc(ir,:,:,:) : ir = 1:nr
  ! csv%fc(:,id,:,:) : id = 1 { r*fc(r) } or 2 { r*[dfc(r)/dr] }
  ! csv%fc(:,:,iljc,:) : iljc = 1:csv%nljc
  ! csv%fc(:,:,:,ic) : ic = 1 { large component } or 2 { small component }
    if(.not.allocated(csv%fc)) allocate(csv%fc(nr,2,csv%nljc,2))
165
    csv%fc = 0.0
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

  ! core setup
    bmu = 0.0

    CALL setcor(itype,jspins,atoms,input,bmu,nst,kappa,nprnc,occ)

  ! extend core potential
    vrd(1:nr) = vr(1:nr,itype,jspin)
    t2 = vrd(nr)/(nr-msh)
    do ir = nr+1,msh
      vrd(ir) = vrd(nr)+t2*(ir-nr)
    enddo

  ! calculate core radial functions
    nc = real(csv%nc)
    do iljc = 1,csv%nljc
      njc = real(edgej(csi%edgeidx(iljc)))/2.0
      nlc = real(edgel(csi%edgeidx(iljc)))
      weight = 2*njc+1.0
      csv%eedge(iljc) = -2*(atoms%zatom(itype)/(nc+nlc))**2
      d = exp(atoms%dx(itype))
      rn = atoms%rmsh(1,itype)*(d**(msh-1))

      CALL differ(nc,nlc,njc,c,atoms%zatom(itype),atoms%dx(itype),&
                  atoms%rmsh(1,itype),rn,d,msh,vrd,&
                  e,&
                  a,b,ierr)

      csv%eedge(iljc)=dble(e)
      csv%fc(:,1,iljc,1) = a(1:nr)  ! large component
      csv%fc(:,1,iljc,2) = b(1:nr)  ! small component
      do ic = 1,2
        fp(:) = real(csv%fc(:,1,iljc,ic)*atoms%rmsh(1:nr,itype))
        CALL dr2fdr(fp,atoms%rmsh(1,itype),nr,fc)
        csv%fc(:,2,iljc,ic)=dble(fc(:)/atoms%rmsh(1:nr,itype))

        if(ic.eq.1) then
        do ir=1,nr
        write(90,'(2i5,16e12.4)') iljc,ir,atoms%rmsh(ir,itype),csv%fc(ir,1,iljc,ic),csv%fc(ir,2,iljc,ic)
        enddo
        write(90,*) ''
        write(90,*) ''
        endif

      enddo
      
      fp = csv%fc(:,1,iljc,1)**2
      CALL intgr3(fp,atoms%rmsh(1,itype),atoms%dx(itype),nr,sum1)
      fp = csv%fc(:,1,iljc,2)**2
      CALL intgr3(fp,atoms%rmsh(1,itype),atoms%dx(itype),nr,sum2)
      write(*,'(a,i5,3f8.4)') "ui",0,sum1,sum2,sum1+sum2

      fp = csv%fc(:,2,iljc,1)**2
      CALL intgr3(fp,atoms%rmsh(1,itype),atoms%dx(itype),nr,sum1)
      fp = csv%fc(:,2,iljc,2)**2
      CALL intgr3(fp,atoms%rmsh(1,itype),atoms%dx(itype),nr,sum2)
      write(*,'(a,i5,3f8.4)') "ui",0,sum1,sum2,sum1+sum2

      write(60,*) ""
225
      csv%occ(iljc) = dble(occ((csv%nc-1)**2+csi%edgeidx(iljc),jspin))
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
      write(*,"(a,2(a,i2),a,f3.1,2(a,i2),a,f16.8,a)") trim(smeno)//ssep,&
           &"core state: iljc = ",iljc,&
           &", nc = ",nint(nc),&
           &", njc = ",njc,&
           &", nlc = ",nint(nlc),&
           &", occ. csv%occ = ",nint(csv%occ(iljc)),&
           &", energy csv%eedge(iljc) = ",csv%eedge(iljc)," Ha found"
      if(efermi-csv%eedge(iljc).lt.ecoredeep) then
        write(*,csmsgsfs)  trim(smeno),&
             &"core state energy found not very deep: ",&
             &"efermi-csv%eedge(iljc) = ",&
             &(efermi-csv%eedge(iljc))*hartree_to_ev_const,"eV ; are you sure ? "//csmsgwar
      endif
    enddo

    CALL corespec_eloss_qv(efermi)  ! set-up csv%eloss and csv%qv arrays

    lx = csi%lx  ! lmax for l index
    lax = lx+maxval(csv%lc)+1  ! lmax for la index
    lin = minval(csv%lc)  ! minimum lc q-no.
    lix = maxval(csv%lc)  ! maximum lc q-no.
    nqv = csv%nqv
    nen = csv%nen
    nex = csv%nex

    allocate(fsb(0:lax))

  ! VALENCE functions
  ! csv%fv(ir,:,:,:) : ir = 1:nr
  ! csv%fv(:,il,:,:) : il = 0:csi%lx
  ! csv%fv(:,:,id,:) : id = 1 { a.u } or 2 { b.u' }
  ! csv%fv(:,:,:,ic) : ic = 1 { large component } or 2 { small component }
    if(.not.allocated(csv%fv)) allocate(csv%fv(nr,0:lx,2,2))
259
    csv%fv = 0.0
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291

    do ic = 1,2
      do il = 0,lx
        csv%fv(:,il,1,ic) = f(1:nr,ic,il,jspin)
        csv%fv(:,il,2,ic) = g(1:nr,ic,il,jspin)

        if(ic.eq.1) then
        do ir=1,nr
        write(70,'(3i5,16e12.4)') ic,il,ir,atoms%rmsh(ir,itype),csv%fv(ir,il,1,ic),csv%fv(ir,il,2,ic)
        enddo
        write(70,*) ''
        write(70,*) ''
        endif

       fp(:) = csv%fv(:,il,1,ic)**2
        CALL intgr3(fp,atoms%rmsh(1,itype),atoms%dx(itype),nr,sum1)
        fp(:) = csv%fv(:,il,2,ic)**2
        CALL intgr3(fp,atoms%rmsh(1,itype),atoms%dx(itype),nr,sum2)
        fp(:) = csv%fv(:,il,1,ic)*csv%fv(:,il,2,ic)
        CALL intgr3(fp,atoms%rmsh(1,itype),atoms%dx(itype),nr,sum3)
        write(*,'(a,i5,3f8.4)') "u ",il,sum1,sum2,sum3

      enddo
    enddo

  ! BESSEL functions
  ! csv%fb(ir,:,:,:,:) : ir = 1:nr
  ! csv%fb(:,il,:,:,:) : il = 0:lax
  ! csv%fb(:,,:,iljc,:,:) : iljc = 1:csv%nljc
  ! csv%fb(:,:,:,iqv,:) : iqv = 1:nqv
  ! csv%fb(:,:,:,:,ie) : ie = nen:nex
    if(.not.allocated(csv%fb)) allocate(csv%fb(nr,0:lax,csv%nljc,nqv,nen:nex))
292
    csv%fb = 0.0
293 294 295 296 297

    do ie = nen,nex
      do iqv = 1,nqv
        do iljc = 1,csv%nljc
          do ir = 1,nr
298
            fsb=0.0
299 300 301 302 303 304 305 306 307 308
            qr = real(csv%qv(0,iljc,iqv,ie)*atoms%rmsh(ir,itype))
            CALL sphbes(lax,qr,fsb)
            csv%fb(ir,:,iljc,iqv,ie) = dble(fsb)
!            write(70,'(4i5,16e12.4)') ie,iqv,iljc,ir,atoms%rmsh(ir,itype),fsb
          enddo
!          write(70,*) ''
        enddo
      enddo
    enddo

309 310 311 312 313 314 315 316
    if(.NOT.ALLOCATED(csv%rmeA)) THEN
       ALLOCATE(csv%rmeA(2,0:lx,0:lax,csv%nljc,2,nqv,nen:nex))
       ALLOCATE(csv%rmeB(2,0:lx,0:lax,csv%nljc,2,nqv,nen:nex))
       ALLOCATE(csv%rmeC(2,0:lx,0:lax,csv%nljc,2,nqv,nen:nex))
    END IF
    csv%rmeA = 0.0
    csv%rmeB = 0.0
    csv%rmeC = 0.0
317 318 319 320 321 322 323 324 325 326 327 328

    do ie = nen,nex
      do iqv = 1,nqv
        do ic = 1,2
          do iljc = 1,csv%nljc
            do ila = 0,lax
              do il = 0,lx
                do id = 1,2
                  fp(:)=csv%fc(1:nr,1,iljc,ic)*&
                       &csv%fv(1:nr,il,id,ic)*&
                       &csv%fb(1:nr,ila,iljc,iqv,ie)
                  CALL intgr3(fp,atoms%rmsh(1,itype),atoms%dx(itype),nr,res)
329
                  csv%rmeA(id,il,ila,iljc,ic,iqv,ie)=dble(res)
330 331
                  fp(:)=fp(:)/atoms%rmsh(1:nr,itype)
                  CALL intgr3(fp,atoms%rmsh(1,itype),atoms%dx(itype),nr,res)
332
                  csv%rmeC(id,il,ila,iljc,ic,iqv,ie)=dble(res)
333 334 335 336
                  fp(:)=csv%fc(1:nr,2,iljc,ic)*&
                       &csv%fv(1:nr,il,id,ic)*&
                       &csv%fb(1:nr,ila,iljc,iqv,ie)!/atoms%rmsh(1:nr,itype)
                  CALL intgr3(fp,atoms%rmsh(1,itype),atoms%dx(itype),nr,res)
337
                  csv%rmeB(id,il,ila,iljc,ic,iqv,ie)=dble(res)
338
                  write(41,'(7(a,i5),3f12.6)') 'ie=',ie,' iqv=',iqv,' ic=',ic,&
339 340 341 342
                        ' iljc=',iljc,' id=',id,' ila=',ila,' il=',il,&
                        csv%rmeA(id,il,ila,iljc,ic,iqv,ie),&
                        csv%rmeB(id,il,ila,iljc,ic,iqv,ie),&
                        csv%rmeC(id,il,ila,iljc,ic,iqv,ie)
343 344 345 346 347 348 349 350
                enddo  ! id
              enddo  ! il
            enddo  ! ila
          enddo  ! iljc
        enddo  ! ic
      enddo  ! iqv
    enddo  ! ie

351
    print*,size(3*csv%rmeA)
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
 
    deallocate(fsb,fc,fpd,fp)

    if(csi%verb.eq.1) write(*,*) ""

  end subroutine corespec_rme
!
!===============================================================================
!===============================================================================
!
!  S U B R O U T I N E   C O R E S P E C _ D O S
!
!-------------------------------------------------------------------------------
!
  subroutine corespec_dos(atoms,usdus,ispin,lmd,nkpt,ikpt,&
367
                          neigd,noccbd,efermi,sig_dos,eig,we,eigVecCoeffs)
368 369 370

    IMPLICIT NONE

371 372 373
    TYPE (t_atoms), INTENT(IN)      :: atoms
    TYPE (t_usdus), INTENT(IN)      :: usdus
    TYPE(t_eigVecCoeffs),INTENT(IN) :: eigVecCoeffs
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393

!     .. Scalar Arguments ..
    integer, intent(in) :: ispin,lmd,nkpt,ikpt
    integer, intent(in) :: neigd,noccbd
    real, intent(in) :: efermi,sig_dos
!     .. Array Arguments ..
    real, intent (in) :: eig(neigd),we(noccbd)

! local variables
    integer :: lx,lmx,nen,nex
    integer :: iatom,iband,l1,m1,l2,m2,lm1,lm2,ie!,ljc,iqv
    real :: sigma,eigos(noccbd)
    real :: sum11,sum22

    smeno = "corespec_dos"

    lx = csi%lx
    lmx = lx*(lx+2)
    nen = csv%nen
    nex = csv%nex
394
    iatom = atoms%neq(csi%atomType)
395
    sigma = sqrt(2.0)*sig_dos*hartree_to_ev_const
396 397 398 399 400 401 402 403 404 405 406
    sigma = sig_dos*hartree_to_ev_const
    eigos(1:noccbd) = (eig(1:noccbd)-efermi)*hartree_to_ev_const/dble(sigma)

    if(ikpt.eq.1) then
      write(*,'(/,a)') trim(smeno)//ssep
      if(.not.allocated(csv%dose)) allocate(csv%dose(2,2,0:lmx,0:lmx,0:nex))
      if(.not.allocated(csv%dosb)) allocate(csv%dosb(2,2,0:lmx,0:lmx,noccbd))
      if(.not.allocated(csv%eos)) then
        allocate(csv%eos(0:nex))
        csv%eos(:) = csv%egrid(:)/dble(sigma)
      endif
407
      csv%dose = 0.0
408
    endif
409
    csv%dosb = 0.0
410 411 412 413 414

    do iband = 1,noccbd
      do l1 = 0,lx
        do m1 = -l1,l1
          lm1 = l1*(l1+1)+m1
415 416 417 418 419 420 421 422 423 424
          do l2 = 0,lx!!$
            do m2 = -l2,l2!!$
              lm2 = l2*(l2+1)+m2!!$
!!!! for dose:
!!!! order of xcof, xcof' : aa', ab', ba', bb'
!!!! is meant by            11 , 12 , 21 , 22
!!!! or, put another way, first index is unprimed (i.e. the outer loop furter down), second index is primed (i.e. the inner loop further down)

!!!! Check what we(1) is and does, if necessary, add a we(1) contribution to all acofs and bcofs
          csv%dosb(1,1,lm2,lm1,iband) = dble(eigVecCoeffs%acof(iband,lm2,iatom,ispin)*&
425
               &conjg(eigVecCoeffs%acof(iband,lm1,iatom,ispin)))!*we(1)
426
          csv%dosb(1,2,lm2,lm1,iband) = dble(eigVecCoeffs%acof(iband,lm2,iatom,ispin)*&
427
               &conjg(eigVecCoeffs%bcof(iband,lm1,iatom,ispin)))
428
          csv%dosb(2,1,lm2,lm1,iband) = dble(eigVecCoeffs%bcof(iband,lm2,iatom,ispin)*&
429
               &conjg(eigVecCoeffs%acof(iband,lm1,iatom,ispin)))
430
          csv%dosb(2,2,lm2,lm1,iband) = dble(eigVecCoeffs%bcof(iband,lm2,iatom,ispin)*&
431
               &conjg(eigVecCoeffs%bcof(iband,lm1,iatom,ispin)))!*we(1)*usdus%ddn(l1,csi%atomType,ispin)
432
!!!!! this has to be checked: is >> ddn << factor necessary !!!!!
433 434 435
!!!!! Check if we(iband) should be multiplied with everything
        enddo!!$
        enddo!!$
436 437
        enddo
      enddo
438 439
      if(eigos(iband)+3.0*sigma.ge.csv%eos(0).and.&
           &eigos(iband)-3.0*sigma.le.csv%eos(nex)) then
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
        do ie = 0,nex
          csv%dose(:,:,:,:,ie) = csv%dose(:,:,:,:,ie)+&
               &csv%dosb(:,:,:,:,iband)*exp(-(eigos(iband)-csv%eos(ie))**2)
        enddo
      endif
    enddo

    if(ikpt.eq.nkpt) then
      csv%dose = csv%dose/(sqrt(pi_const)*sigma)
      do ie=0,nex
        write(36,*) csv%egrid(ie),sum(csv%dose(1,1,:,:,ie)+csv%dose(2,2,:,:,ie))
      enddo
      write(36,*) ""
      write(*,'(10i8)') atoms%llod,noccbd,atoms%nlod,atoms%nat,neigd,atoms%ntype,atoms%lmaxd
      write(*,'(10i8)') lmd,atoms%ntype

      if(csi%verb.eq.1) write(*,*) ""
    endif

  end subroutine corespec_dos
!
!===============================================================================
!===============================================================================
!
!  S U B R O U T I N E   C O R E S P E C _ D D S C S
!
!-------------------------------------------------------------------------------
!
  subroutine corespec_ddscs(jspin,jspins)

    use m_ylm

472

473 474 475 476 477 478 479 480 481 482 483 484
    implicit none

    integer, intent(in) :: jspin,jspins

    integer :: lx,lmx,lan,lax,nqv,nen,nex,nor

    integer :: ic,ie,iqv,ior,it,iljc,imi,id1,id2,ip1,ip2
    integer :: l1,l2,m1,m2,lm1,lm2
    integer :: la1,la2,mu1,mu2
    integer :: li,mi
    integer :: lamu,lamu1,lamu2

485 486 487
    real :: gamma,beta,rho,qepref
    real, allocatable :: orvec(:,:)
!    real, allocatable :: orw(:)
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
    real :: ga(0:2,2)
    real :: prd(0:2,0:2)
    complex :: td(2),orfac,ila1la2
    complex, allocatable :: tdy(:,:),orpref(:),ylm(:,:)

    smeno = "corespec_ddscs"

    write(*,'(/,a)') trim(smeno)//ssep

    lx = csi%lx
    lmx = lx*(lx+2)
    lan = 0
    lax = csi%lx+maxval(csv%lc)+1
    nqv = csv%nqv
    nen = csv%nen
    nex = csv%nex

    nor = 1
506 507 508 509
!    nor = 26
    if(.not.allocated(orvec)) allocate(orvec(1:nor,3))
!    if(.not.allocated(orw)) allocate(orw(0:nor))
!    call lebedev(nor,orvec,orw)
510
    orvec(1,:) = (/1.0,0.0,0.0/)
511 512

    if(.not.allocated(csv%ddscs)) then
513
      allocate(csv%ddscs(2,0:nor,1:csv%nljc,0:nqv,0:nex))
514
      csv%ddscs = cmplx(0.0,0.0)
515 516 517 518
    endif
    if(.not.allocated(tdy)) allocate(tdy(0:nor,2))
    if(.not.allocated(orpref)) then
      allocate(orpref(0:nor))
519
      orpref(0) = 1.0
520
      if(nor.gt.0) then
521
        orpref(1:nor) = (4.0*pi_const)**2
522 523
        if(.not.allocated(ylm)) allocate(ylm(0:lax*(lax+2),nor))
        do ior = 1,nor
524
          CALL ylm4(lax,orvec(ior,:),ylm(:,ior))
525 526 527 528 529 530 531 532 533 534 535 536
          do la1 = lan,lax ; do mu1 = -la1,la1
            lamu = la1*(la1+1)+mu1
            write(98,'(3i5,2f12.8)') la1,mu1,lamu,ylm(lamu,ior)
          enddo; enddo
        enddo
      endif
    endif

    ic = 1
    gamma = csv%gamma
    beta = csv%beta

537
    rho = alpha*beta*sqrt(4.0*pi_const/3.0)
538
    print*,gamma,beta,rho
539
!    rho = 0.0
540 541 542 543 544

    do ie = nen,nex  ! energy
      do iqv = 1,nqv  ! q-vector
        do iljc = 1,csv%nljc  ! core levels
          li = edgel(csi%edgeidx(iljc))
545
          qepref = 4.0*gamma**2*csv%qv1(iljc,iqv,ie)/csv%qv0/&
546 547
               &(csv%qv(0,iljc,iqv,ie)**2-(csv%eloss(iljc,ie)*alpha)**2)**2
!!$          write(*,'(2i5,3f20.4)') ie,iljc,csv%qv(0,iljc,iqv,ie),csv%eloss(iljc,ie)*alpha,qepref
548
          tdy = cmplx(0.0,0.0)
549

550
          do imi = 1,(edgej(csi%edgeidx(iljc))+1)/2!min(nint(csv%occ(iljc)*jspins/2),2*li+1)
551
            mi = sign(jspin)*(edgej(csi%edgeidx(iljc))-4*(imi-1)-1)/2
552
!!            print*,jspin,ie,iljc,li,mi
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
            write(39,*) jspin,ie,iljc,li,mi

            do l1 = 0,lx ; do m1 = -l1,l1
              lm1 = l1*(l1+1)+m1
              do la1 = lan,lax ; do mu1 = -la1,la1
                lamu1 = la1*(la1+1)+mu1

                ga(0,1) = csv%gaunt(l1,-m1,la1,mu1,li,mi)
                ga(1,1) = csv%gaunt(li+1,-mi,li,mi,1,0)*&
                     &csv%gaunt(l1,-m1,la1,mu1,li+1,mi)+&
                     &csv%gaunt(li-1,-mi,li,mi,1,0)*&
                     &csv%gaunt(l1,-m1,la1,mu1,li-1,mi)
                ga(2,1) = csv%gaunt(li+1,-mi,li,mi+1,1,-1)*&
                     &csv%gaunt(l1,-m1,la1,mu1,li+1,mi)+&
                     &csv%gaunt(li-1,-mi,li,mi+1,1,-1)*&
                     &csv%gaunt(l1,-m1,la1,mu1,li-1,mi)*&
                     &sqrt(dble(2*(li-mi)*(li+mi+1)))+mi*ga(1,1)

                do l2 = 0,lx ; do m2 = -l2,l2
                  lm2 = l2*(l2+1)+m2
                  do la2 = lan,lax ; do mu2 = -la2,la2
                    lamu2 = la2*(la2+1)+mu2
                    
576
 !                   if(l1.eq.l2.and.m1.eq.m2) then
577 578 579 580 581 582 583 584 585 586 587 588

                    ga(0,2) = csv%gaunt(l2,-m2,la2,mu2,li,mi)
                    ga(1,2) = csv%gaunt(li+1,-mi,li,mi,1,0)*&
                             &csv%gaunt(l2,-m2,la2,mu2,li+1,mi)+&
                             &csv%gaunt(li-1,-mi,li,mi,1,0)*&
                             &csv%gaunt(l2,-m2,la2,mu2,li-1,mi)
                    ga(2,2) = csv%gaunt(li+1,-mi,li,mi+1,1,-1)*&
                             &csv%gaunt(l2,-m2,la2,mu2,li+1,mi)+&
                             &csv%gaunt(li-1,-mi,li,mi+1,1,-1)*&
                             &csv%gaunt(l2,-m2,la2,mu2,li-1,mi)*&
                             &sqrt(dble(2*(li-mi)*(li+mi+1)))+mi*ga(1,2)

589
                    prd = 0.0
590

591 592
                    do id1 = 1,2 ; 
                      do id2 = 1,2
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
                        prd(0,0) = prd(0,0)+ &
                           csv%rmeA(id1,l1,la1,iljc,ic,iqv,ie)*csv%rmeA(id2,l2,la2,iljc,ic,iqv,ie)*csv%dose(id1,id2,lm1,lm2,ie)
                        prd(0,1) = prd(0,1)+ &
                           csv%rmeA(id1,l1,la1,iljc,ic,iqv,ie)*csv%rmeB(id2,l2,la2,iljc,ic,iqv,ie)*csv%dose(id1,id2,lm1,lm2,ie)
                        prd(0,2) = prd(0,2)+ &
                           csv%rmeA(id1,l1,la1,iljc,ic,iqv,ie)*csv%rmeC(id2,l2,la2,iljc,ic,iqv,ie)*csv%dose(id1,id2,lm1,lm2,ie)
                        prd(1,0) = prd(1,0)+ &
                           csv%rmeB(id1,l1,la1,iljc,ic,iqv,ie)*csv%rmeA(id2,l2,la2,iljc,ic,iqv,ie)*csv%dose(id1,id2,lm1,lm2,ie)
                        prd(1,1) = prd(1,1)+ &
                           csv%rmeB(id1,l1,la1,iljc,ic,iqv,ie)*csv%rmeB(id2,l2,la2,iljc,ic,iqv,ie)*csv%dose(id1,id2,lm1,lm2,ie)
                        prd(1,2) = prd(1,2)+ &
                           csv%rmeB(id1,l1,la1,iljc,ic,iqv,ie)*csv%rmeC(id2,l2,la2,iljc,ic,iqv,ie)*csv%dose(id1,id2,lm1,lm2,ie)
                        prd(2,0) = prd(2,0)+ &
                           csv%rmeC(id1,l1,la1,iljc,ic,iqv,ie)*csv%rmeA(id2,l2,la2,iljc,ic,iqv,ie)*csv%dose(id1,id2,lm1,lm2,ie)
                        prd(2,1) = prd(2,1)+ &
                           csv%rmeC(id1,l1,la1,iljc,ic,iqv,ie)*csv%rmeB(id2,l2,la2,iljc,ic,iqv,ie)*csv%dose(id1,id2,lm1,lm2,ie)
                        prd(2,2) = prd(2,2)+ &
                           csv%rmeC(id1,l1,la1,iljc,ic,iqv,ie)*csv%rmeC(id2,l2,la2,iljc,ic,iqv,ie)*csv%dose(id1,id2,lm1,lm2,ie)
611 612
                      enddo 
                    enddo
613 614 615 616 617 618 619

                    td(1) = prd(0,0)*ga(0,1)*ga(0,2)
                    td(2) = cone*rho**2*(&
                           &prd(1,1)*ga(1,1)*ga(1,2)&
                          &+prd(2,2)*ga(2,1)*ga(2,2)&
                          &-prd(1,2)*ga(1,1)*ga(2,2)&
                          &-prd(2,1)*ga(2,1)*ga(1,2))&
620
                          &+cimu*rho*(-1)**(li+1)*(&
621 622 623
                          &-prd(0,1)*ga(0,1)*ga(1,2)&
                          &+prd(0,2)*ga(0,1)*ga(2,2)&
                          &+prd(1,0)*ga(1,1)*ga(0,2)&
624 625
                          &-prd(2,0)*ga(2,1)*ga(0,2))&
                          &+td(1)
626 627 628
                    
                    ila1la2 = cimu**(la1-la2)
                    
629
                    if(abs(real(td(1))).gt.0.0.or.abs(real(td(2))).gt.0.0.or.abs(aimag(td(2))).gt.0.0) then
630 631 632 633 634 635 636 637 638 639 640 641 642 643
                    write(39,'(2f4.0,i2,6i4,a,6i4,a,6f7.3,a,4f10.6)') ila1la2,la1-la2,l1,-m1,la1,mu1,li,mi,'  ',l2,-m2,la2,mu2,li,mi,'  ',ga(0,1),ga(0,2),ga(1,1),ga(1,2),ga(2,1),ga(2,2),'  ',1000000*td
                    endif

                    do ior = 0,nor  ! orientation
                      if(ior.eq.0) then
                        orfac = cone
                      else
                        orfac = ylm(lamu1,ior)*conjg(ylm(lamu2,ior))
                      endif
                      
                      tdy(ior,1:2) = tdy(ior,1:2)+td(1:2)*orfac*ila1la2

                    enddo  ! ior

644
 !                 endif
645 646 647 648 649 650 651 652 653 654 655 656 657

                  enddo; enddo
                enddo; enddo

              enddo; enddo
            enddo; enddo

          enddo  ! mi

          do it = 1,2
            do ior = 0,nor
              csv%ddscs(it,ior,iljc,iqv,ie) = csv%ddscs(it,ior,iljc,iqv,ie)+&
                   &qepref*orpref(ior)*tdy(ior,it)
658 659 660
!!        calculate the integral over all q-vectors, save the result in iqv=0
          csv%ddscs(it,ior,iljc,0,ie) = csv%ddscs(it,ior,iljc,0,ie)+&
                   &csv%ddscs(it,ior,iljc,iqv,ie)*csv%qv(4,iljc,iqv,ie)
661 662 663 664 665 666 667 668 669 670 671
            enddo
          enddo

        enddo  ! iljc
      enddo  ! iqv
    enddo  ! ie

    if(jspin.eq.1) then
      do ior = 0,nor
      do iljc = 1,csv%nljc
        do ie = nen,nex
672 673
!!        write(37,'(2i5,f8.3,4es16.4)') ior,iljc,csv%eloss(iljc,ie)*hartree_to_ev_const,csv%ddscs(1,ior,iljc,1,ie),csv%ddscs(2,ior,iljc,1,ie)
          write(37,'(2i5,f16.3,4es16.4)') ior,iljc,csv%eloss(iljc,ie)*hartree_to_ev_const,csv%ddscs(1,ior,iljc,0,ie),csv%ddscs(2,ior,iljc,0,ie)
674 675 676 677 678 679 680 681 682 683
        enddo
        write(37,*) ""
      enddo
      write(37,*) ""
      enddo
    endif
    if(jspin.eq.2) then
      do ior = 0,nor
      do iljc = 1,csv%nljc
        do ie = nen,nex
684 685
!!        write(38,'(2i5,f8.3,4es16.4)') ior,iljc,csv%eloss(iljc,ie)*hartree_to_ev_const,csv%ddscs(1,ior,iljc,1,ie),csv%ddscs(2,ior,iljc,1,ie)
          write(38,'(2i5,f16.3,4es16.4)') ior,iljc,csv%eloss(iljc,ie)*hartree_to_ev_const,csv%ddscs(1,ior,iljc,0,ie),csv%ddscs(2,ior,iljc,0,ie)
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
        enddo
        write(38,*) ""
      enddo
      write(38,*) ""
      enddo
    endif

    if(csi%verb.eq.1) write(*,*) ""

  end subroutine corespec_ddscs
!
!===============================================================================
!===============================================================================
!
!  S U B R O U T I N E   C O R E S P E C _ E L O S S _ Q V
!
!-------------------------------------------------------------------------------
!
  subroutine corespec_eloss_qv(efermi)

    implicit none

    real, intent(in) :: efermi

710 711
    integer :: ie,iljc,iqv,iphi,ir
    real :: eout,relfac,pi,ri,r,dr,p,alpha,beta,geofac,gf1,gf2,normfac
712
    pi = 3.141592653589793238462643
713
    smeno = "corespec_eloss_qv"
714
    normfac = 1!4*csv%nqr**2!/(pi*(r**2))
715
    write(*,'(/,a)') trim(smeno)//ssep
716 717 718 719
!    csv%nqphi = 12
!    csv%nqr = 20
    csv%nqv = 1+csv%nqphi*csv%nqr
!    write(*,'(2i6,3f16.7)')csv%nqr,csv%nqphi,csv%alpha_ex,csv%beta_ex,csv%I0
720 721 722 723 724 725 726 727 728 729 730 731 732
    if(.not.allocated(csv%eloss)) &
         &allocate(csv%eloss(csv%nljc,csv%nen:csv%nex))
    if(.not.allocated(csv%qv1)) &
         &allocate(csv%qv1(csv%nljc,csv%nqv,csv%nen:csv%nex))
    do ie = csv%nen,csv%nex
      do iljc = 1,csv%nljc
        csv%eloss(iljc,ie) = csv%egrid(ie)/hartree_to_ev_const+dble(efermi)-csv%eedge(iljc)
!!$        print*,iljc,ie,csv%egrid(ie),csv%eloss(iljc,ie)
      enddo
    enddo

    csv%qv0 = e2q(csi%ek0/hartree_to_ev_const)
    relfac = (mec2)**2/(csi%ek0+mec2)**2
733
    alpha=csv%qv0*csv%alpha_ex
734 735 736
!!$    print*,csi%ek0,csv%qv0

    if(.not.allocated(csv%qv)) &
737 738 739
         &allocate(csv%qv(0:4,csv%nljc,csv%nqv,csv%nen:csv%nex))
!!  qv(0) = |qv(1:3)|
!!  qv(4) = weight of qv(1:3)
740
    csv%qv=0.0
741
    if(csv%nqv.gt.1)then    
742
    do ie = csv%nen,csv%nex
743
      do iljc = 1,csv%nljc
744
          eout = csi%ek0/hartree_to_ev_const-csv%eloss(iljc,ie)
745
        do iqv = 1,csv%nqv
746
          csv%qv1(iljc,iqv,ie) = e2q(eout)
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
!!   set up circular 2D mesh with qz==(csv%qv1(iljc,iqv,ie)-csv%qv0)*relfac
!!   and (qx,qy) = r*(sin(phi),cos(phi))
!!   R = alpha + beta
!!   r_0 = 0
!!   r_i = i/N_r*R , i>0
!!   phi_i = i/N_phi*2pi
!!   Areas of each volume element, this corresponds to the weights of the point in the integral
!!   A_1 = pi/4 * (r_0+r_1)²
!!   A_i = pi/(N_phi*4)*(r_{i+1}²-r_{i-1}²+2*r_i*(r_{i+1}-r_{i-1})) (1<i<=N_r)
!!   A_{N_r+1} = pi/(N_phi)*(r_{N_r}² - 1/4*(r_{N_r}+r_{N_r-1})²)
!!   A_ges = pi *(alpha + beta)²
!!   Numbering of the nodes (the i-index above are independent of each other, now we make a 2-D grid with 1-D indexing by counting upwards around the clock):
!!   j=1 => center node (r=0, phi=0)
!!   j=2 ... N_phi+1 => nodes of r=r_1, phi=phi_{i=mod_{N_phi}(j-1)}
!!   j...  => nodes of r=r_{1+frac{j-2-mod_{n_r}(j-2)}{n_r}} and phi = phi_{i=mod_{N_phi}(j-1)}

          beta=csv%beta_ex*csv%qv1(iljc,iqv,ie)
!!  r is the radius of the q-disc which sits at z=q_min and contains all the allowed q-vectors 
          r=alpha + beta !small angle approximation: sin(a) ~ a
          dr = r/csv%nqr
          iphi = modulo(iqv-1,csv%nqphi)
          ir = 1+(iqv-2-modulo(iqv-2,csv%nqr))/csv%nqr
          ri = (ir-0.5)*dr
!          normfac=normfac/(pi*(r**2))
!!        write the weight of qv, i.e. the area it represents
          csv%qv(4,iljc,iqv,ie) = 1.
!          write(*,'(6f16.10)')dr,csv%nqr,csv%nqphi,ir,r
!!        write weights and values of q_x and q_y for the q-vectors:
          if(ir.eq.0) then
          csv%qv(1,iljc,iqv,ie) = 0 ! here is the angular dependency
          csv%qv(2,iljc,iqv,ie) = 0 ! here is the angular dependency
             csv%qv(4,iljc,iqv,ie) = pi*0.0625*dr**2
          elseif(ir.eq.1) then
          csv%qv(1,iljc,iqv,ie) = ri*SIN(iphi/csv%nqphi*2*pi) ! here is the angular dependency
          csv%qv(2,iljc,iqv,ie) = ri*COS(iphi/csv%nqphi*2*pi) ! here is the angular dependency
             csv%qv(4,iljc,iqv,ie) = pi*0.9735*dr**2!!!!pi/csv%nqphi*(r**2-0.25*(2.*r-dr)**2) (old, less sensible mesh described above)
          else
          csv%qv(1,iljc,iqv,ie) = ri*SIN(iphi/csv%nqphi*2*pi) ! here is the angular dependency
          csv%qv(2,iljc,iqv,ie) = ri*COS(iphi/csv%nqphi*2*pi) ! here is the angular dependency
             csv%qv(4,iljc,iqv,ie) = pi/csv%nqphi*(2*ir-1)*dr**2
          endif
!!        write z coordinates:
          csv%qv(3,iljc,iqv,ie) = (csv%qv0-csv%qv1(iljc,iqv,ie))*relfac ! here is no angular dependency
!!        write the length of qv
791 792
          csv%qv(0,iljc,iqv,ie) = sqrt(&
               &dot_product(csv%qv(1:3,iljc,iqv,ie),csv%qv(1:3,iljc,iqv,ie)))
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
!          write(*,'(f16.6)')csv%qv(4,iljc,iqv,ie)

!!        calculate the g_alpha_beta function and multiply with the weight to obtain the overall weight of the specific q-vector
!!        Step 1: calculate all the relevant point of the overlapping circles
          p=0.5*(ri**2+(alpha)**2-(beta)**2)/(ri)
!          write(*,'(f16.10)')p
           geofac=0.
!          gf1=csv%I0/(csv%alpha_ex**2)*min(alpha,beta)**2
!          gf2=csv%I0/(csv%alpha_ex**2)*(0.5*pi*(alpha**2 + beta**2)-p*sqrt(alpha**2-p**2)-(ri-p)*sqrt(beta**2-(ri-p)**2)&
!                    &-beta**2*asin((ri-p)/beta)-alpha**2*asin(p/alpha))
          if(ri.LE.abs(alpha-beta)) then
              geofac=csv%I0/(csv%alpha_ex**2)*min(alpha,beta)**2
!             geofac=csv%I0/(csv%alpha_ex**2)*min(alpha,beta)**2
!             write(*,'(f16.6)')geofac
          elseif(ri.GE.(alpha+beta)) then
             geofac=0.
             write(*,csmsgsis)'geofac is 0'
          else
              geofac=csv%I0/(csv%alpha_ex**2)*(0.5*pi*(alpha**2 + beta**2)-p*sqrt(alpha**2-p**2)-(ri-p)*sqrt(beta**2-(ri-p)**2)&
                    &-beta**2*asin((ri-p)/beta)-alpha**2*asin(p/alpha))
!             geofac=csv%I0/(csv%alpha_ex**2)*(0.5*pi*(alpha**2 + beta**2)-p*sqrt(alpha**2-p**2)-(ri-p)*sqrt(beta**2-(ri-p)**2)&
!                    &-beta**2*asin((ri-p)/beta)-alpha**2*asin(p/alpha))
!             write(*,csmsgsis)'geofac is not 0'
!             write(*,'(3f16.6)')alpha**2-p**2,beta**2-(ri-p)**2, geofac
           endif
!          write(*,'(f16.10)')geofac
          csv%qv(4,iljc,iqv,ie) = csv%qv(4,iljc,iqv,ie)*geofac *normfac/(pi*(r**2))
!          csv%qv(4,iljc,iqv,ie) = 1.
!          write(*,'(f16.6)')csv%qv(4,iljc,iqv,ie)
822
!!$          write(*,'(3i5,2f16.2,6f16.6)') ie,iqv,iljc,csi%ek0,eout*hartree_to_ev_const,csv%qv1(iljc,iqv,ie),csv%eloss(iljc,ie),csv%qv(:,iljc,iqv,ie)
823
          write(*,'(5f16.5)')alpha,beta,ri,abs(alpha-beta),alpha+beta!,csv%nqr,csv%qv(4,iljc,iqv,ie)
824 825 826
        enddo
      enddo
    enddo
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
    else !number of q-vectors == 1:
    do ie = csv%nen,csv%nex
      do iljc = 1,csv%nljc
          eout = csi%ek0/hartree_to_ev_const-csv%eloss(iljc,ie)
        do iqv = 1,csv%nqv
          csv%qv1(iljc,iqv,ie) = e2q(eout)
          beta=csv%beta_ex*csv%qv1(iljc,iqv,ie)
          r=alpha + beta !small angle approximation: sin(a) ~ a
!!        only q||z vectors are calcualted:
!!        write x, y, and z coordinates:
          csv%qv(1,iljc,iqv,ie) = 0 ! here is no angular dependency
          csv%qv(2,iljc,iqv,ie) = 0 ! here is no angular dependency
 
          csv%qv(3,iljc,iqv,ie) = (csv%qv0-csv%qv1(iljc,iqv,ie))*relfac ! here is no angular dependency
!!        write the length of qv
          csv%qv(0,iljc,iqv,ie) = sqrt(&
               &dot_product(csv%qv(1:3,iljc,iqv,ie),csv%qv(1:3,iljc,iqv,ie)))
!!        write the weight of qv, i.e. the area it represents, normalized by the
!total area, i.e. 1.
          csv%qv(4,iljc,iqv,ie) = 1.!(pi*(r**2))!!*0.25
          dr = r
          write(*,'(7f16.5)')alpha,beta,r*500,pi,r**2,pi*dr*dr!,csv%nqr,csv%qv(4,iljc,iqv,ie)
!!        calculate the g_alpha_beta function and multiply with the weight to obtain the overall weight of the specific q-vector
!!        Step 1: calculate all the relevant point of the overlapping circles
           geofac=0.
              geofac=csv%I0/(csv%alpha_ex**2)*min(alpha,beta)**2
          csv%qv(4,iljc,iqv,ie) = csv%qv(4,iljc,iqv,ie)*geofac
!          csv%qv(4,iljc,iqv,ie) = 1.
!          write(*,'(f16.6)')csv%qv(4,iljc,iqv,ie)
!          write(*,'(3i5,2f16.2,6f16.6)') ie,iqv,iljc,csi%ek0,eout*hartree_to_ev_const,csv%qv1(iljc,iqv,ie),csv%eloss(iljc,ie),csv%qv(:,iljc,iqv,ie)
        enddo
      enddo
    enddo
    
    endif
862 863 864

    if(csi%verb.eq.1) write(*,*) ""

865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
!    implicit none

!    real, intent(in) :: efermi

!    integer :: ie,iljc,iqv
!    real :: eout,relfac

!    smeno = "corespec_eloss_qv"

!    write(*,'(/,a)') trim(smeno)//ssep

!    csv%nqv = 1

!    if(.not.allocated(csv%eloss)) &
!         &allocate(csv%eloss(csv%nljc,csv%nen:csv%nex))
!    if(.not.allocated(csv%qv1)) &
!         &allocate(csv%qv1(csv%nljc,csv%nqv,csv%nen:csv%nex))
!    do ie = csv%nen,csv%nex
!      do iljc = 1,csv%nljc
!        csv%eloss(iljc,ie) = csv%egrid(ie)/hartree_to_ev_const+dble(efermi)-csv%eedge(iljc)
!!$        print*,iljc,ie,csv%egrid(ie),csv%eloss(iljc,ie)
!      enddo
!    enddo

!    csv%qv0 = e2q(csi%ek0/hartree_to_ev_const)
!    relfac = (mec2)**2/(csi%ek0+mec2)**2
!!$    print*,csi%ek0,csv%qv0

!    if(.not.allocated(csv%qv)) &
!         &allocate(csv%qv(0:3,csv%nljc,csv%nqv,csv%nen:csv%nex))
895
!    csv%qv=0.0
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910
!    do ie = csv%nen,csv%nex
!      do iqv = 1,csv%nqv
!        do iljc = 1,csv%nljc
!          eout = csi%ek0/hartree_to_ev_const-csv%eloss(iljc,ie)
!          csv%qv1(iljc,iqv,ie) = e2q(eout)
!          csv%qv(3,iljc,iqv,ie) = (csv%qv1(iljc,iqv,ie)-csv%qv0)*relfac
!          csv%qv(0,iljc,iqv,ie) = sqrt(&
!               &dot_product(csv%qv(1:3,iljc,iqv,ie),csv%qv(1:3,iljc,iqv,ie)))
!!$          write(*,'(3i5,2f16.2,6f16.6)') ie,iqv,iljc,csi%ek0,eout*hartree_to_ev_const,csv%qv1(iljc,iqv,ie),csv%eloss(iljc,ie),csv%qv(:,iljc,iqv,ie)
!        enddo
!      enddo
!    enddo

!    if(csi%verb.eq.1) write(*,*) ""

911 912 913 914 915 916 917 918 919 920 921 922 923
  end subroutine corespec_eloss_qv
!
!===============================================================================
!===============================================================================
!  F U N C T I O N   E 2 Q
!-------------------------------------------------------------------------------
!
  real function e2q(e)

    use m_corespec, only : mec2,alpha
    implicit none
    real, intent(in) :: e

924
    e2q=sqrt(e**2+2.0*e*mec2/hartree_to_ev_const)*alpha
925 926 927 928 929 930

  end function e2q
!
!===============================================================================


931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062

!
!===============================================================================
!===============================================================================
!
!  S U B R O U T I N E   L E B E D E V
!
!-------------------------------------------------------------------------------
!

  subroutine lebedev(nleb,r2leb,wleb)
    implicit none
    integer, intent(in) :: nleb
    double precision, intent(out) :: r2leb(nleb,3),wleb(nleb)

    integer :: ileb,ctrln
    double precision :: vec(0)

    if(nleb.eq. 0006) call LD0006(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0014) call LD0014(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0026) call LD0026(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0038) call LD0038(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0050) call LD0050(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0074) call LD0074(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0086) call LD0086(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0110) call LD0110(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0146) call LD0146(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0170) call LD0170(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0194) call LD0194(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0230) call LD0230(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0266) call LD0266(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0302) call LD0302(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0350) call LD0350(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0434) call LD0434(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0590) call LD0590(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0770) call LD0770(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 0974) call LD0974(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 1202) call LD1202(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 1454) call LD1454(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 1730) call LD1730(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 2030) call LD2030(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 2354) call LD2354(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 2702) call LD2702(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 3074) call LD3074(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 3470) call LD3470(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 3890) call LD3890(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 4334) call LD4334(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 4802) call LD4802(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 5294) call LD5294(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)
    if(nleb.eq. 5810) call LD5810(r2leb(1,1),r2leb(1,2),r2leb(1,3),wleb,ctrln)

    write(*,'(i8)') nleb
    do ileb = 1,nleb
       write(*,'(4f12.6)') r2leb(ileb,1:3),wleb(ileb)
    enddo

  end subroutine lebedev
!
!===============================================================================


       subroutine gen_oh(code, num, x, y, z, w, a, b, v)
       implicit logical(a-z)
       double precision x(*),y(*),z(*),w(*)
       double precision a,b,v
       integer code
       integer num
       double precision c
!    
!       This subroutine is part of a set of subroutines that generate
!       Lebedev grids [1-6] for integration on a sphere. The original 
!       C-code [1] was kindly provided by Dr. Dmitri N. Laikov and 
!       translated into fortran by Dr. Christoph van Wuellen.
!       This subroutine was translated from C to fortran77 by hand.
!    
!       Users of this code are asked to include reference [1] in their
!       publications, and in the user- and programmers-manuals 
!       describing their codes.
!    
!       This code was distributed through CCL (http://www.ccl.net/).
!    
!       [1] V.I. Lebedev, and D.N. Laikov
!           "A quadrature formula for the sphere of the 131st
!            algebraic order of accuracy"
!           Doklady Mathematics, Vol. 59, No. 3, 1999, pp. 477-481.
!    
!       [2] V.I. Lebedev
!           "A quadrature formula for the sphere of 59th algebraic
!            order of accuracy"
!           Russian Acad. Sci. Dokl. Math., Vol. 50, 1995, pp. 283-286. 
!    
!       [3] V.I. Lebedev, and A.L. Skorokhodov
!           "Quadrature formulas of orders 41, 47, and 53 for the sphere"
!           Russian Acad. Sci. Dokl. Math., Vol. 45, 1992, pp. 587-592. 
!    
!       [4] V.I. Lebedev
!           "Spherical quadrature formulas exact to orders 25-29"
!           Siberian Mathematical Journal, Vol. 18, 1977, pp. 99-107. 
!    
!       [5] V.I. Lebedev
!           "Quadratures on a sphere"
!           Computational Mathematics and Mathematical Physics, Vol. 16,
!           1976, pp. 10-24. 
!    
!       [6] V.I. Lebedev
!           "Values of the nodes and weights of ninth to seventeenth 
!            order Gauss-Markov quadrature formulae invariant under the
!            octahedron group with inversion"
!           Computational Mathematics and Mathematical Physics, Vol. 15,
!           1975, pp. 44-51.
!    
!    
!      Given a point on a sphere (specified by a and b), generate all
!      the equivalent points under Oh symmetry, making grid points with
!      weight v.
!      The variable num is increased by the number of different points
!      generated.
!    
!      Depending on code, there are 6...48 different but equivalent
!      points.
!    
!      code=1:   (0,0,1) etc                                (  6 points)
!      code=2:   (0,a,a) etc, a=1/sqrt(2)                   ( 12 points)
!      code=3:   (a,a,a) etc, a=1/sqrt(3)                   (  8 points)
!      code=4:   (a,a,b) etc, b=sqrt(1-2 a^2)               ( 24 points)
!      code=5:   (a,b,0) etc, b=sqrt(1-a^2), a input        ( 24 points)
!      code=6:   (a,b,c) etc, c=sqrt(1-a^2-b^2), a/b input  ( 48 points)
!    
       goto (1,2,3,4,5,6) code
       write (6,*) 'Gen_Oh: Invalid Code'
       stop 
    1  continue
1063
       a=1.0
1064
       x(1) =  a
1065 1066
       y(1) =  0.0
       z(1) =  0.0
1067 1068
       w(1) =  v
       x(2) = -a
1069 1070
       y(2) =  0.0
       z(2) =  0.0
1071
       w(2) =  v
1072
       x(3) =  0.0
1073
       y(3) =  a
1074
       z(3) =  0.0
1075
       w(3) =  v
1076
       x(4) =  0.0
1077
       y(4) = -a
1078
       z(4) =  0.0
1079
       w(4) =  v
1080 1081
       x(5) =  0.0
       y(5) =  0.0
1082 1083
       z(5) =  a
       w(5) =  v
1084 1085
       x(6) =  0.0
       y(6) =  0.0
1086 1087 1088 1089 1090 1091
       z(6) = -a
       w(6) =  v
       num=num+6
       return
!    
    2  continue
1092 1093
       a=sqrt(0.5)
       x( 1) =  0.0
1094 1095 1096
       y( 1) =  a
       z( 1) =  a
       w( 1) =  v
1097
       x( 2) =  0.0
1098 1099 1100
       y( 2) = -a
       z( 2) =  a
       w( 2) =  v
1101
       x( 3) =  0.0
1102 1103 1104
       y( 3) =  a
       z( 3) = -a
       w( 3) =  v
1105
       x( 4) =  0.0
1106 1107 1108 1109
       y( 4) = -a
       z( 4) = -a
       w( 4) =  v
       x( 5) =  a
1110
       y( 5) =  0.0
1111 1112 1113
       z( 5) =  a
       w( 5) =  v
       x( 6) = -a
1114
       y( 6) =  0.0
1115 1116 1117
       z( 6) =  a
       w( 6) =  v
       x( 7) =  a
1118
       y( 7) =  0.0
1119 1120 1121
       z( 7) = -a
       w( 7) =  v
       x( 8) = -a
1122
       y( 8) =  0.0
1123 1124 1125 1126
       z( 8) = -a
       w( 8) =  v
       x( 9) =  a
       y( 9) =  a
1127
       z( 9) =  0.0
1128 1129 1130
       w( 9) =  v
       x(10) = -a
       y(10) =  a
1131
       z(10) =  0.0
1132 1133 1134
       w(10) =  v
       x(11) =  a
       y(11) = -a
1135
       z(11) =  0.0
1136 1137 1138
       w(11) =  v
       x(12) = -a
       y(12) = -a
1139
       z(12) =  0.0
1140 1141 1142 1143 1144
       w(12) =  v
       num=num+12
       return
!    
    3  continue
1145
       a = sqrt(1.0/3.0)
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
       x(1) =  a
       y(1) =  a
       z(1) =  a
       w(1) =  v
       x(2) = -a
       y(2) =  a
       z(2) =  a
       w(2) =  v
       x(3) =  a
       y(3) = -a
       z(3) =  a
       w(3) =  v
       x(4) = -a
       y(4) = -a
       z(4) =  a
       w(4) =  v
       x(5) =  a
       y(5) =  a
       z(5) = -a
       w(5) =  v
       x(6) = -a
       y(6) =  a
       z(6) = -a
       w(6) =  v
       x(7) =  a
       y(7) = -a
       z(7) = -a
       w(7) =  v
       x(8) = -a
       y(8) = -a
       z(8) = -a
       w(8) =  v
       num=num+8
       return
!    
    4  continue
1182
       b = sqrt(1.0 - 2.0*a*a)
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
       x( 1) =  a
       y( 1) =  a
       z( 1) =  b
       w( 1) =  v
       x( 2) = -a
       y( 2) =  a
       z( 2) =  b
       w( 2) =  v
       x( 3) =  a
       y( 3) = -a
       z( 3) =  b
       w( 3) =  v
       x( 4) = -a
       y( 4) = -a
       z( 4) =  b
       w( 4) =  v
       x( 5) =  a
       y( 5) =  a
       z( 5) = -b
       w( 5) =  v
       x( 6) = -a
       y( 6) =  a
       z( 6) = -b
       w( 6) =  v
       x( 7) =  a
       y( 7) = -a
       z( 7) = -b
       w( 7) =  v
       x( 8) = -a
       y( 8) = -a
       z( 8) = -b
       w( 8) =  v
       x( 9) =  a
       y( 9) =  b
       z( 9) =  a
       w( 9) =  v
       x(10) = -a
       y(10) =  b
       z(10) =  a
       w(10) =  v
       x(11) =  a
       y(11) = -b
       z(11) =  a
       w(11) =  v
       x(12) = -a
       y(12) = -b
       z(12) =  a
       w(12) =  v
       x(13) =  a
       y(13) =  b
       z(13) = -a
       w(13) =  v
       x(14) = -a
       y(14) =  b
       z(14) = -a
       w(14) =  v
       x(15) =  a
       y(15) = -b
       z(15) = -a
       w(15) =  v
       x(16) = -a
       y(16) = -b
       z(16) = -a
       w(16) =  v
       x(17) =  b
       y(17) =  a
       z(17) =  a
       w(17) =  v
       x(18) = -b
       y(18) =  a
       z(18) =  a
       w(18) =  v
       x(19) =  b
       y(19) = -a
       z(19) =  a
       w(19) =  v
       x(20) = -b
       y(20) = -a
       z(20) =  a
       w(20) =  v
       x(21) =  b
       y(21) =  a
       z(21) = -a
       w(21) =  v
       x(22) = -b
       y(22) =  a
       z(22) = -a
       w(22) =  v
       x(23) =  b
       y(23) = -a
       z(23) = -a
       w(23) =  v
       x(24) = -b
       y(24) = -a
       z(24) = -a
       w(24) =  v
       num=num+24
       return
!    
    5  continue
1283
       b=sqrt(1.0-a*a)
1284 1285
       x( 1) =  a
       y( 1) =  b
1286
       z( 1) =  0.0
1287 1288 1289
       w( 1) =  v
       x( 2) = -a
       y( 2) =  b
1290
       z( 2) =  0.0
1291 1292 1293
       w( 2) =  v
       x( 3) =  a
       y( 3) = -b
1294
       z( 3) =  0.0
1295 1296 1297
       w( 3) =  v
       x( 4) = -a
       y( 4) = -b
1298
       z( 4) =  0.0
1299 1300 1301
       w( 4) =  v
       x( 5) =  b
       y( 5) =  a
1302
       z( 5) =  0.0
1303 1304 1305
       w( 5) =  v
       x( 6) = -b
       y( 6) =  a
1306
       z( 6) =  0.0
1307 1308 1309
       w( 6) =  v
       x( 7) =  b
       y( 7) = -a
1310
       z( 7) =  0.0
1311 1312 1313
       w( 7) =  v
       x( 8) = -b
       y( 8) = -a
1314
       z( 8) =  0.0
1315 1316
       w( 8) =  v
       x( 9) =  a
1317
       y( 9) =  0.0
1318 1319 1320
       z( 9) =  b
       w( 9) =  v
       x(10) = -a
1321
       y(10) =  0.0
1322 1323 1324
       z(10) =  b
       w(10) =  v
       x(11) =  a
1325
       y(11) =  0.0
1326 1327 1328
       z(11) = -b
       w(11) =  v
       x(12) = -a
1329
       y(12) =  0.0
1330 1331 1332
       z(12) = -b
       w(12) =  v
       x(13) =  b
1333
       y(13) =  0.0
1334 1335 1336
       z(13) =  a
       w(13) =  v
       x(14) = -b
1337
       y(14) =  0.0
1338 1339 1340
       z(14) =  a
       w(14) =  v
       x(15) =  b
1341
       y(15) =  0.0
1342 1343 1344
       z(15) = -a
       w(15) =  v
       x(16) = -b
1345
       y(16) =  0.0
1346 1347
       z(16) = -a
       w(16) =  v
1348
       x(17) =  0.0
1349 1350 1351
       y(17) =  a
       z(17) =  b
       w(17) =  v
1352
       x(18) =  0.0
1353 1354 1355
       y(18) = -a
       z(18) =  b
       w(18) =  v
1356
       x(19) =  0.0
1357 1358 1359
       y(19) =  a
       z(19) = -b
       w(19) =  v
1360
       x(20) =  0.0
1361 1362 1363
       y(20) = -a
       z(20) = -b
       w(20) =  v
1364
       x(21) =  0.0
1365 1366 1367
       y(21) =  b
       z(21) =  a
       w(21) =  v
1368
       x(22) =  0.0
1369 1370 1371
       y(22) = -b
       z(22) =  a
       w(22) =  v
1372
       x(23) =  0.0
1373 1374 1375
       y(23) =  b
       z(23) = -a
       w(23) =  v
1376
       x(24) =  0.0
1377 1378 1379 1380 1381 1382 1383
       y(24) = -b
       z(24) = -a
       w(24) =  v
       num=num+24
       return
!    
    6  continue
1384
       c=sqrt(1.0 - a*a - b*b)
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634
       x( 1) =  a
       y( 1) =  b
       z( 1) =  c
       w( 1) =  v
       x( 2) = -a
       y( 2) =  b
       z( 2) =  c
       w( 2) =  v
       x( 3) =  a
       y( 3) = -b
       z( 3) =  c
       w( 3) =  v
       x( 4) = -a
       y( 4) = -b
       z( 4) =  c
       w( 4) =  v
       x( 5) =  a
       y( 5) =  b
       z( 5) = -c
       w( 5) =  v
       x( 6) = -a
       y( 6) =  b
       z( 6) = -c
       w( 6) =  v
       x( 7) =  a
       y( 7) = -b
       z( 7) = -c
       w( 7) =  v
       x( 8) = -a
       y( 8) = -b
       z( 8) = -c
       w( 8) =  v
       x( 9) =  a
       y( 9) =  c
       z( 9) =  b
       w( 9) =  v
       x(10) = -a
       y(10) =  c
       z(10) =  b
       w(10) =  v
       x(11) =  a
       y(11) = -c
       z(11) =  b
       w(11) =  v
       x(12) = -a
       y(12) = -c
       z(12) =  b
       w(12) =  v
       x(13) =  a
       y(13) =  c
       z(13) = -b
       w(13) =  v
       x(14) = -a
       y(14) =  c
       z(14) = -b
       w(14) =  v
       x(15) =  a
       y(15) = -c
       z(15) = -b
       w(15) =  v
       x(16) = -a
       y(16) = -c
       z(16) = -b
       w(16) =  v
       x(17) =  b
       y(17) =  a
       z(17) =  c
       w(17) =  v
       x(18) = -b
       y(18) =  a
       z(18) =  c
       w(18) =  v
       x(19) =  b
       y(19) = -a
       z(19) =  c
       w(19) =  v
       x(20) = -b
       y(20) = -a
       z(20) =  c
       w(20) =  v
       x(21) =  b
       y(21) =  a
       z(21) = -c
       w(21) =  v
       x(22) = -b
       y(22) =  a
       z(22) = -c
       w(22) =  v
       x(23) =  b
       y(23) = -a
       z(23) = -c
       w(23) =  v
       x(24) = -b
       y(24) = -a
       z(24) = -c
       w(24) =  v
       x(25) =  b
       y(25) =  c
       z(25) =  a
       w(25) =  v
       x(26) = -b
       y(26) =  c
       z(26) =  a
       w(26) =  v
       x(27) =  b
       y(27) = -c
       z(27) =  a
       w(27) =  v
       x(28) = -b
       y(28) = -c
       z(28) =  a
       w(28) =  v
       x(29) =  b
       y(29) =  c
       z(29) = -a
       w(29) =  v
       x(30) = -b
       y(30) =  c
       z(30) = -a
       w(30) =  v
       x(31) =  b
       y(31) = -c
       z(31) = -a
       w(31) =  v
       x(32) = -b
       y(32) = -c
       z(32) = -a
       w(32) =  v
       x(33) =  c
       y(33) =  a
       z(33) =  b
       w(33) =  v
       x(34) = -c
       y(34) =  a
       z(34) =  b
       w(34) =  v
       x(35) =  c
       y(35) = -a
       z(35) =  b
       w(35) =  v
       x(36) = -c
       y(36) = -a
       z(36) =  b
       w(36) =  v
       x(37) =  c
       y(37) =  a
       z(37) = -b
       w(37) =  v
       x(38) = -c
       y(38) =  a
       z(38) = -b
       w(38) =  v
       x(39) =  c
       y(39) = -a
       z(39) = -b
       w(39) =  v
       x(40) = -c
       y(40) = -a
       z(40) = -b
       w(40) =  v
       x(41) =  c
       y(41) =  b
       z(41) =  a
       w(41) =  v
       x(42) = -c
       y(42) =  b
       z(42) =  a
       w(42) =  v
       x(43) =  c
       y(43) = -b
       z(43) =  a
       w(43) =  v
       x(44) = -c
       y(44) = -b
       z(44) =  a
       w(44) =  v
       x(45) =  c
       y(45) =  b
       z(45) = -a
       w(45) =  v
       x(46) = -c
       y(46) =  b
       z(46) = -a
       w(46) =  v
       x(47) =  c
       y(47) = -b
       z(47) = -a
       w(47) =  v
       x(48) = -c
       y(48) = -b
       z(48) = -a
       w(48) =  v
       num=num+48
       return
       end
       SUBROUTINE LD0006(X,Y,Z,W,N)
       DOUBLE PRECISION X(   6)
       DOUBLE PRECISION Y(   6)
       DOUBLE PRECISION Z(   6)
       DOUBLE PRECISION W(   6)
       INTEGER N
       DOUBLE PRECISION A,B,V
!  
!      LEBEDEV    6-POINT ANGULAR GRID
!  
!    
!       This subroutine is part of a set of subroutines that generate
!       Lebedev grids [1-6] for integration on a sphere. The original 
!       C-code [1] was kindly provided by Dr. Dmitri N. Laikov and 
!       translated into fortran by Dr. Christoph van Wuellen.
!       This subroutine was translated using a C to fortran77 conversion
!       tool written by Dr. Christoph van Wuellen.
!    
!       Users of this code are asked to include reference [1] in their
!       publications, and in the user- and programmers-manuals 
!       describing their codes.
!    
!       This code was distributed through CCL (http://www.ccl.net/).
!    
!       [1] V.I. Lebedev, and D.N. Laikov
!           "A quadrature formula for the sphere of the 131st
!            algebraic order of accuracy"
!           Doklady Mathematics, Vol. 59, No. 3, 1999, pp. 477-481.
!    
!       [2] V.I. Lebedev
!           "A quadrature formula for the sphere of 59th algebraic
!            order of accuracy"
!           Russian Acad. Sci. Dokl. Math., Vol. 50, 1995, pp. 283-286. 
!    
!       [3] V.I. Lebedev, and A.L. Skorokhodov
!           "Quadrature formulas of orders 41, 47, and 53 for the sphere"
!           Russian Acad. Sci. Dokl. Math., Vol. 45, 1992, pp. 587-592. 
!    
!       [4] V.I. Lebedev
!           "Spherical quadrature formulas exact to orders 25-29"
!           Siberian Mathematical Journal, Vol. 18, 1977, pp. 99-107. 
!    
!       [5] V.I. Lebedev
!           "Quadratures on a sphere"
!           Computational Mathematics and Mathematical Physics, Vol. 16,
!           1976, pp. 10-24. 
!    
!       [6] V.I. Lebedev
!           "Values of the nodes and weights of ninth to seventeenth 
!            order Gauss-Markov quadrature formulae invariant under the
!            octahedron group with inversion"
!           Computational Mathematics and Mathematical Physics, Vol. 15,
!           1975, pp. 44-51.
!    
       N=1
1635
       V=0.1666666666666667
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649