zsymsecloc.F90 20.1 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 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.
!--------------------------------------------------------------------------------

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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 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 225 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 259 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 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
MODULE m_zsymsecloc
  use m_juDFT
!*******************************************************
!  Solve the generalized secular equation. 
!  For film-systems exhibiting
!  z-reflexion symmetry, the basis is transformed to
!  even and odd functions and the even-even and odd-odd 
!  blocks are diagonalized separately.
!  If local orbitals are present in a film with z-reflection,
!  locrectify is used to construct linear combinations of
!  the local orbitals that are eigenfunctions of the z-
!  reflexion operation.
!  Frank Freimuth, January 2006
!*******************************************************
CONTAINS
  SUBROUTINE zsymsecloc(jsp,input,lapw,bkpt,atoms,&
       kveclo, sym,cell, dimension,matsize,&
       nsize, jij,matind,nred, a,b, z,eig,ne)

#include"cpp_double.h"

    USE m_locrectify
    USE m_geneigprobl
    USE m_types
    IMPLICIT NONE
    TYPE(t_dimension),INTENT(IN)   :: dimension
    TYPE(t_input),INTENT(IN)   :: input
    TYPE(t_jij),INTENT(IN)   :: jij
    TYPE(t_sym),INTENT(IN)   :: sym
    TYPE(t_cell),INTENT(IN)   :: cell
    TYPE(t_atoms),INTENT(IN)   :: atoms

    TYPE(t_lapw),INTENT(IN)   :: lapw
    real,intent(in)   ::bkpt(3)
    integer,intent(in)::kveclo(atoms%nlotot)

    !     ..
    !     .. Scalar Arguments ..
    INTEGER, INTENT (IN)    :: matsize,jsp 
    INTEGER, INTENT (INOUT) :: nsize
    INTEGER, INTENT (OUT)   :: ne
    INTEGER, INTENT (IN)    :: nred
    !     ..
    !     .. Array Arguments ..
    INTEGER, INTENT (IN)  :: matind(dimension%nbasfcn,2)
    REAL,    INTENT (OUT) :: eig(dimension%neigd)

#ifdef CPP_INVERSION
    REAL, ALLOCATABLE, INTENT (INOUT) :: a(:),b(:)
    REAL, ALLOCATABLE, INTENT (INOUT) :: z(:,:)
#else
    COMPLEX, ALLOCATABLE, INTENT (INOUT)::a(:),b(:)
    COMPLEX, ALLOCATABLE, INTENT (INOUT) :: z(:,:)
#endif


#ifdef CPP_INVERSION
    real locrec(atoms%nlotot,atoms%nlotot)
    real,allocatable::atemp(:,:)
    real,allocatable::btemp(:,:)
    real,allocatable::aa(:)
    real,allocatable::bb(:)
    real,allocatable::z1(:,:)
    real,allocatable::z2(:,:)
    real,allocatable::ztemp(:,:)
    real recsqrtwo,dobzero
#else
    complex locrec(atoms%nlotot,atoms%nlotot)
    complex,allocatable:: atemp(:,:)
    complex,allocatable:: btemp(:,:)
    complex,allocatable::aa(:)
    complex,allocatable::bb(:)
    complex,allocatable::z1(:,:)
    complex,allocatable::z2(:,:)
    complex,allocatable::ztemp(:,:)
    complex recsqrtwo,dobzero
#endif
    logical l_verbose
    logical kindlocrec(atoms%nlotot)
    real,allocatable::etemp1(:),etemp2(:)
    integer iind,jind,ii,info,iu,pos1,pos2,pos3,i2,j2
    integer ne1,ne2,i1,j1,i,j
    logical,allocatable:: evensort(:)
    integer evenlocs,oddlocs
    integer evenlocindex(atoms%nlotot)
    integer oddlocindex(atoms%nlotot)


    !      print*,"in zsymsecloc"
    deallocate(z)

    !******************************************
    ! l_zref=.false. => simply call eigensolver
    !******************************************
    if(.not.sym%l_zref)then
       call geneigprobl(dimension%nbasfcn, nsize,dimension%neigd,jij%l_j,a,b, z,eig,ne)

       allocate(a(dimension%nbasfcn*(dimension%nbasfcn+1)/2))
       allocate(b(dimension%nbasfcn*(dimension%nbasfcn+1)/2))
       return
       !******************************************
       ! l_zref=.true. => blockdiagonalize
       ! hamiltonian and overlap-matrix by
       ! transforming to even/odd basisfunctions
       !******************************************
    else
       inquire(file='verbose',exist=l_verbose)
       if(.not.l_verbose)inquire(file='veryverbose',exist=l_verbose)
       iu=dimension%neigd/2
#ifdef CPP_INVERSION
       recsqrtwo=1.0/sqrt(2.0)
       dobzero=0.0
#else
       recsqrtwo=cmplx(1.0/sqrt(2.0),0.0)
       dobzero=cmplx(0.0,0.0)
#endif


       if(atoms%nlotot.gt.0)then
          !*********************************************
          ! Find even/odd linear combinations of locs
          !*********************************************
          if(l_verbose)then
             print*,"find lincos of locs that are eigenfunctions of zreflection"
             print*,"apws=",lapw%nv(jsp)
             print*,"atoms%nlotot=",atoms%nlotot
             print*,"basis-size=",nsize
          endif
          IF(nsize/=(lapw%nv(jsp)+atoms%nlotot)) &
               CALL juDFT_error("nsize /= lapw%nv + atoms%nlotot" ,calledby ="zsymsecloc")
          call locrectify(jsp,input,lapw,bkpt,atoms, kveclo, sym,cell,&
                    locrec,kindlocrec,evenlocs,oddlocs, evenlocindex,oddlocindex)


          !*********************************************
          ! Perform basis-transformation of Hamiltonian
          ! and Overlap matrix. The new basis is the basis
          ! of even / odd (with respect to z-reflection)
          ! local orbitals.
          !*********************************************
          allocate(atemp(lapw%nv(jsp),atoms%nlotot))
          allocate(btemp(atoms%nlotot,lapw%nv(jsp)))
          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             atemp(1:lapw%nv(jsp),iind)=a(pos1+1:pos1+lapw%nv(jsp))
          enddo
#ifdef CPP_INVERSION
          call CPP_BLAS_sgemm('T','T',atoms%nlotot,lapw%nv(jsp),atoms%nlotot,real(1.0),&
                   locrec,atoms%nlotot,atemp,lapw%nv(jsp),real(0.0),btemp,atoms%nlotot)
#else
          call CPP_BLAS_cgemm('C','T',atoms%nlotot,lapw%nv(jsp),atoms%nlotot,cmplx(1.0,0.0),&
                   locrec,atoms%nlotot,atemp,lapw%nv(jsp),cmplx(0.0,0.0),btemp,atoms%nlotot)
#endif
          atemp(:,:) = transpose(btemp)
          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             a(pos1+1:pos1+lapw%nv(jsp))=atemp(1:lapw%nv(jsp),iind)
          enddo

          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             atemp(1:lapw%nv(jsp),iind)=b(pos1+1:pos1+lapw%nv(jsp))
          enddo
#ifdef CPP_INVERSION
          call CPP_BLAS_sgemm('T','T',atoms%nlotot,lapw%nv(jsp),atoms%nlotot,real(1.0),&
                   locrec,atoms%nlotot,atemp,lapw%nv(jsp),real(0.0),btemp,atoms%nlotot)
#else
          call CPP_BLAS_cgemm('C','T',atoms%nlotot,lapw%nv(jsp),atoms%nlotot,cmplx(1.0,0.0),&
                   locrec,atoms%nlotot,atemp,lapw%nv(jsp),cmplx(0.0,0.0),btemp,atoms%nlotot)
#endif
          atemp(:,:) = transpose(btemp)
          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             b(pos1+1:pos1+lapw%nv(jsp))=atemp(1:lapw%nv(jsp),iind)
          enddo
          deallocate(atemp)
          deallocate(btemp)

          allocate(atemp(atoms%nlotot,atoms%nlotot))
          allocate(btemp(atoms%nlotot,atoms%nlotot))
          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             do jind=1,iind-1
                atemp(iind,jind)=a(pos1+lapw%nv(jsp)+jind)
#ifdef CPP_INVERSION
                atemp(jind,iind)=a(pos1+lapw%nv(jsp)+jind)
#else
                atemp(jind,iind)=conjg(a(pos1+lapw%nv(jsp)+jind))
#endif
             enddo
             atemp(iind,iind)=a(pos1+lapw%nv(jsp)+iind)
          enddo
#ifdef CPP_INVERSION
          call CPP_BLAS_sgemm('T','N',atoms%nlotot,atoms%nlotot,atoms%nlotot,real(1.0),&
                    locrec,atoms%nlotot,atemp,atoms%nlotot,real(0.0),btemp,atoms%nlotot)
          call CPP_BLAS_sgemm('N','N',atoms%nlotot,atoms%nlotot,atoms%nlotot,real(1.0),&
                    btemp,atoms%nlotot,locrec,atoms%nlotot,real(0.0),atemp,atoms%nlotot)
#else
          call CPP_BLAS_cgemm('C','N',atoms%nlotot,atoms%nlotot,atoms%nlotot,cmplx(1.0,0.0),&
                    locrec,atoms%nlotot,atemp,atoms%nlotot,cmplx(0.0,0.0),btemp,atoms%nlotot)
          call CPP_BLAS_cgemm('N','N',atoms%nlotot,atoms%nlotot,atoms%nlotot,cmplx(1.0,0.0),&
                    btemp,atoms%nlotot,locrec,atoms%nlotot,cmplx(0.0,0.0),atemp,atoms%nlotot)
#endif
          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             do jind=1,iind
                a(pos1+lapw%nv(jsp)+jind)=atemp(iind,jind)
             enddo
          enddo

          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             do jind=1,iind-1
                atemp(iind,jind)=b(pos1+lapw%nv(jsp)+jind)
#ifdef CPP_INVERSION
                atemp(jind,iind)=b(pos1+lapw%nv(jsp)+jind)
#else
                atemp(jind,iind)=conjg(b(pos1+lapw%nv(jsp)+jind))
#endif
             enddo
             atemp(iind,iind)=b(pos1+lapw%nv(jsp)+iind)
          enddo
#ifdef CPP_INVERSION
          call CPP_BLAS_sgemm('T','N',atoms%nlotot,atoms%nlotot,atoms%nlotot,real(1.0),&
                    locrec,atoms%nlotot,atemp,atoms%nlotot,real(0.0),btemp,atoms%nlotot)
          call CPP_BLAS_sgemm('N','N',atoms%nlotot,atoms%nlotot,atoms%nlotot,real(1.0),&
                    btemp,atoms%nlotot,locrec,atoms%nlotot,real(0.0),atemp,atoms%nlotot)
#else
          call CPP_BLAS_cgemm('C','N',atoms%nlotot,atoms%nlotot,atoms%nlotot,cmplx(1.0,0.0),&
                    locrec,atoms%nlotot,atemp,atoms%nlotot,cmplx(0.0,0.0),btemp,atoms%nlotot)
          call CPP_BLAS_cgemm('N','N',atoms%nlotot,atoms%nlotot,atoms%nlotot,cmplx(1.0,0.0),&
                    btemp,atoms%nlotot,locrec,atoms%nlotot,cmplx(0.0,0.0),atemp,atoms%nlotot)
#endif
          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             do jind=1,iind
                b(pos1+lapw%nv(jsp)+jind)=atemp(iind,jind)
             enddo
          enddo

          deallocate(atemp)
          deallocate(btemp)

       else
          evenlocs=0
          oddlocs=0
       endif ! atoms%nlotot.gt.0

       !*********************************************
       ! Test matind.
       !*********************************************
       ii=0
       jind=0
       pos1=0
       do iind=1,nred
          IF(matind(iind,1)<matind(iind,2))  CALL juDFT_error("mat1mat2" ,calledby ="zsymsecloc")
          IF(matind(iind,1)<pos1) CALL juDFT_error("matpos1",calledby ="zsymsecloc")
          pos1=matind(iind,1)
          if(matind(iind,1).ne.matind(iind,2))then
             ii=ii+1
          else
             jind=jind+1
          endif
       enddo
       IF(2*ii+jind/=lapw%nv(jsp)) CALL juDFT_error("matind",calledby="zsymsecloc")

       !*****************************************************************
       !Transform into representation with even-even- and odd-odd-blocks.
       !First step: Transform the lapw-lapw-part.
       !*****************************************************************
       allocate(    aa(  ((nred+evenlocs)*(nred+evenlocs+1))/2   )  )
       allocate(    bb(  ((nred+evenlocs)*(nred+evenlocs+1))/2   )  )
       i2=0
       j2=0
       DO i=1,nred
          DO j=1,i
             i1=(matind(i,1)-1)*matind(i,1)/2+matind(j,1)
             j1=(matind(i,1)-1)*matind(i,1)/2+matind(j,2)
             i2=i2+1
             aa(i2)=a(i1)+a(j1)
             bb(i2)=b(i1)+b(j1)
             IF ((matind(i,1).NE.matind(i,2)).AND. (matind(j,1).NE.matind(j,2))) THEN
                j2=j2+1
                a(j2)=a(i1)-a(j1)
                b(j2)=b(i1)-b(j1)
             ENDIF
          ENDDO
       ENDDO

       if(atoms%nlotot.gt.0)then
          !******************************************************
          !the lapw-lo- and lo-lo-parts for the even-even-block.
          !******************************************************
          allocate(atemp(lapw%nv(jsp),atoms%nlotot))
          allocate(btemp(nred,evenlocs))
          !hamiltonian
          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             atemp(1:lapw%nv(jsp),iind)=a(pos1+1:pos1+lapw%nv(jsp))
          enddo
          do jind=1,evenlocs
             do iind=1,nred
                btemp(iind,jind)=(atemp(matind(iind,1),evenlocindex(jind))&
                     +atemp(matind(iind,2),evenlocindex(jind)))*recsqrtwo
             enddo
          enddo
          do iind=1,evenlocs
             pos1=((nred+iind)*(nred+iind-1))/2
             aa(pos1+1:pos1+nred)=btemp(1:nred,iind)
          enddo
          !metric
          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             atemp(1:lapw%nv(jsp),iind)=b(pos1+1:pos1+lapw%nv(jsp))
          enddo
          do jind=1,evenlocs
             do iind=1,nred
                btemp(iind,jind)=(atemp(matind(iind,1),evenlocindex(jind))&
                     +atemp(matind(iind,2),evenlocindex(jind)))*recsqrtwo
             enddo
          enddo
          do iind=1,evenlocs
             pos1=((nred+iind)*(nred+iind-1))/2
             bb(pos1+1:pos1+nred)=btemp(1:nred,iind)
          enddo
          deallocate(btemp)
          deallocate(atemp)
          !hamiltonian
          do iind=1,evenlocs
             do jind=1,iind
                pos1=((lapw%nv(jsp)+evenlocindex(iind))*(lapw%nv(jsp)+evenlocindex(iind)-1))/2
                pos2=((nred+iind)*(nred+iind-1))/2
                aa(pos2+nred+jind)=a(pos1+lapw%nv(jsp)+evenlocindex(jind))
             enddo
          enddo
          !metric
          do iind=1,evenlocs
             do jind=1,iind
                pos1=((lapw%nv(jsp)+evenlocindex(iind))*(lapw%nv(jsp)+evenlocindex(iind)-1))/2
                pos2=((nred+iind)*(nred+iind-1))/2
                bb(pos2+nred+jind)=b(pos1+lapw%nv(jsp)+evenlocindex(jind))
             enddo
          enddo


          !******************************************************
          !the lapw-lo- and lo-lo-parts for the odd-odd-block
          !******************************************************
          allocate(atemp(lapw%nv(jsp),atoms%nlotot))
          allocate(btemp(lapw%nv(jsp)-nred,oddlocs))
          !hamiltonian
          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             atemp(1:lapw%nv(jsp),iind)=a(pos1+1:pos1+lapw%nv(jsp))
          enddo
          do jind=1,oddlocs
             ii=0
             do iind=1,nred
                if(matind(iind,1).ne.matind(iind,2))then
                   ii=ii+1
                   btemp(ii,jind)=(atemp(matind(iind,1),oddlocindex(jind))&
                        -atemp(matind(iind,2),oddlocindex(jind)))*recsqrtwo
                endif
             enddo
          enddo
          do iind=1,oddlocs
             pos1=((lapw%nv(jsp)-nred+iind)*(lapw%nv(jsp)-nred+iind-1))/2
             a(pos1+1:pos1+lapw%nv(jsp)-nred)=btemp(1:lapw%nv(jsp)-nred,iind)
          enddo
          !metric
          do iind=1,atoms%nlotot
             pos1=((lapw%nv(jsp)+iind)*(lapw%nv(jsp)+iind-1))/2
             atemp(1:lapw%nv(jsp),iind)=b(pos1+1:pos1+lapw%nv(jsp))
          enddo
          do jind=1,oddlocs
             ii=0
             do iind=1,nred
                if(matind(iind,1).ne.matind(iind,2))then
                   ii=ii+1
                   btemp(ii,jind)=(atemp(matind(iind,1),oddlocindex(jind))&
                        -atemp(matind(iind,2),oddlocindex(jind)))*recsqrtwo
                endif
             enddo
          enddo
          do iind=1,oddlocs
             pos1=((lapw%nv(jsp)-nred+iind)*(lapw%nv(jsp)-nred+iind-1))/2
             b(pos1+1:pos1+lapw%nv(jsp)-nred)=btemp(1:lapw%nv(jsp)-nred,iind)
          enddo
          deallocate(btemp)
          deallocate(atemp)
          !hamiltonian
          do iind=1,oddlocs
             do jind=1,iind
                pos1=((lapw%nv(jsp)+oddlocindex(iind))*(lapw%nv(jsp)+oddlocindex(iind)-1))/2
                pos2=((lapw%nv(jsp)-nred+iind)*(lapw%nv(jsp)-nred+iind-1))/2
                a(pos2+lapw%nv(jsp)-nred+jind)=a(pos1+lapw%nv(jsp)+oddlocindex(jind))
             enddo
          enddo
          !metric
          do iind=1,oddlocs
             do jind=1,iind
                pos1=((lapw%nv(jsp)+oddlocindex(iind))*(lapw%nv(jsp)+oddlocindex(iind)-1))/2
                pos2=((lapw%nv(jsp)-nred+iind)*(lapw%nv(jsp)-nred+iind-1))/2
                b(pos2+lapw%nv(jsp)-nred+jind)=b(pos1+lapw%nv(jsp)+oddlocindex(jind))
             enddo
          enddo



       endif !atoms%nlotot.gt.0

       !******************************************************
       !Solve the eigenvalue problem for the odd-odd block
       !******************************************************

       allocate(etemp2(iu+1))
       call geneigprobl(lapw%nv(jsp)-nred+oddlocs, lapw%nv(jsp)-nred+oddlocs,iu,jij%l_j,a,b, z2,etemp2,ne2)

       if(l_verbose)then   
          print*,"odd block diagonalized"
       endif

       !***********************************************************
       !Solve the eigenvalue problem for the even-even block
       !***********************************************************
       allocate(etemp1(iu+1))
       call geneigprobl(nred+evenlocs, nred+evenlocs,iu,jij%l_j,aa,bb, z1,etemp1,ne1)
       if(l_verbose)then
          print*,"even block diagonalized"
       endif


       ne=ne1+ne2
       !********************************************************************
       !  Recover eigenvectors of original eigenvalue problem.
       !  Sort eigenvalues and eigenvectors according to increasing eigenvalue.
       !  etemp1 holds eigenvalues of even block.
       !  etemp2 holds eigenvalues of odd block.
       !  z1 holds eigenvectors of even block.
       !  z2 holds eigenvectors of odd block.
       !********************************************************************
       allocate(z(dimension%nbasfcn,dimension%neigd))
       allocate(evensort(ne))
       etemp1(ne1+1)=99.9e9
       etemp2(ne2+1)=99.9e9
       jind=1
       iind=1
       !evensort(ii)=.true.  => eigenvalue ii belongs to even spectrum
       !evensort(ii)=.false. => eigenvalue ii belongs to odd spectrum
       do ii=1,ne
          if(etemp1(iind).lt.etemp2(jind)) then
             evensort(ii)=.true.
             iind=iind+1
          else
             evensort(ii)=.false.
             jind=jind+1
          endif
       enddo
       iind=1 !position in the even-arrays
       jind=1 !position in the oneD%odd-arrays
       do ii=1,ne
          if(evensort(ii))then
             eig(ii)=etemp1(iind)
             z(1:lapw%nv(jsp)+atoms%nlotot,ii)=dobzero
             !Recover the eigenvectors of the original problem for the even block
             do i=1,nred
                z(matind(i,1),ii)=z1(i,iind)*recsqrtwo
                z(matind(i,2),ii)=z(matind(i,2),ii)+z1(i,iind)*recsqrtwo
             enddo !i
             if(atoms%nlotot.gt.0) z(lapw%nv(jsp)+1:lapw%nv(jsp)+atoms%nlotot,ii)=dobzero
             do pos1=1,evenlocs
                do i=1,atoms%nlotot
#ifdef CPP_INVERSION
                   z(lapw%nv(jsp)+i,ii)=z(lapw%nv(jsp)+i,ii)+ z1(nred+pos1,iind)*locrec(i,evenlocindex(pos1))
#else
                   z(lapw%nv(jsp)+i,ii)=z(lapw%nv(jsp)+i,ii)+ z1(nred+pos1,iind)*conjg(locrec(i,evenlocindex(pos1)))
#endif
                enddo
             enddo
             iind=iind+1
          else
             !Recover the eigenvectors of the original problem for the odd block
             eig(ii)=etemp2(jind)
             j1=0
             do i=1,nred
                if(matind(i,1).ne.matind(i,2))then
                   j1=j1+1
                   z(matind(i,1),ii)=z2(j1,jind)*recsqrtwo
                   z(matind(i,2),ii)=-z2(j1,jind)*recsqrtwo
                else
                   z(matind(i,1),ii)=dobzero
                endif
             enddo !i
             if(atoms%nlotot.gt.0) z(lapw%nv(jsp)+1:lapw%nv(jsp)+atoms%nlotot,ii)=dobzero
             do pos1=1,oddlocs
                do i=1,atoms%nlotot
#ifdef CPP_INVERSION
                   z(lapw%nv(jsp)+i,ii)=z(lapw%nv(jsp)+i,ii)+ z2(lapw%nv(jsp)-nred+pos1,jind)*locrec(i,oddlocindex(pos1))
#else
                   z(lapw%nv(jsp)+i,ii)=z(lapw%nv(jsp)+i,ii)+ z2(lapw%nv(jsp)-nred+pos1,jind)*conjg(locrec(i,oddlocindex(pos1)))
#endif
                enddo
             enddo
             jind=jind+1
          endif !evensort
       enddo !ii

       allocate(a(dimension%nbasfcn*(dimension%nbasfcn+1)/2))
       allocate(b(dimension%nbasfcn*(dimension%nbasfcn+1)/2))
    endif !sym%l_zref

    deallocate ( z1,z2,etemp1,etemp2,evensort )

  END SUBROUTINE zsymsecloc
      END MODULE