io_hybrid.F90 6.18 KB
Newer Older
Daniel Wortmann's avatar
Daniel Wortmann committed
1 2 3 4 5 6
module m_io_hybrid
  use m_io_matrix
  use m_judft
  use m_types
  implicit none
  !private
Daniel Wortmann's avatar
Daniel Wortmann committed
7
  integer,save :: id_olap,id_z,id_v_x,id_coulomb,id_coulomb_spm
Daniel Wortmann's avatar
Daniel Wortmann committed
8 9 10
  !public:: open_hybrid_io,read_cmt,write_cmt
contains

11
  SUBROUTINE open_hybrid_io1(DIMENSION,l_real)
Daniel Wortmann's avatar
Daniel Wortmann committed
12 13 14
    implicit none
    TYPE(t_dimension),INTENT(IN):: dimension
    LOGICAL,INTENT(IN)          :: l_real
15
    LOGICAL :: opened=.false.
Daniel Wortmann's avatar
Daniel Wortmann committed
16 17

    
18 19 20 21

    if (opened) return
    opened=.true.

Daniel Wortmann's avatar
Daniel Wortmann committed
22 23 24 25 26 27
    print *,"Open olap.mat"
    id_olap=OPEN_MATRIX(l_real,dimension%nbasfcn,1,"olap.mat")
    print *,"Open z.mat"
    id_z=OPEN_MATRIX(l_real,dimension%nbasfcn,1,"z.mat")
    print *,"Open v_x.mat"
    id_v_x=OPEN_MATRIX(l_real,dimension%nbasfcn,1,"v_x.mat")
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  END SUBROUTINE open_hybrid_io1
  SUBROUTINE open_hybrid_io2(hybrid,DIMENSION,atoms,l_real)
    IMPLICIT NONE
    TYPE(t_hybrid),INTENT(IN)   :: hybrid
    TYPE(t_dimension),INTENT(IN):: dimension
    TYPE(t_atoms),INTENT(IN)    :: atoms
    LOGICAL,INTENT(IN)          :: l_real
    INTEGER:: irecl_coulomb
    LOGICAL :: opened=.FALSE.

    

    if (opened) return
    opened=.true.
    OPEN(unit=777,file='cmt',form='unformatted',access='direct',&
         &     recl=dimension%neigd*hybrid%maxlmindx*atoms%nat*16)
  
Daniel Wortmann's avatar
Daniel Wortmann committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#ifdef CPP_NOSPMVEC
    irecl_coulomb = hybrid%maxbasm1 * (hybrid%maxbasm1+1) * 8 / 2
    if (.not.l_real) irecl_coulomb =irecl_coulomb *2
    OPEN(unit=778,file='coulomb',form='unformatted',access='direct', recl=irecl_coulomb)
    id_coulomb=778
#else
    ! if the sparse matrix technique is used, several entries of the
    ! matrix vanish so that the size of each entry is smaller
    irecl_coulomb = ( atoms%ntype*(hybrid%maxlcutm1+1)*(hybrid%maxindxm1-1)**2&
         +   atoms%nat *(hybrid%maxlcutm1+2)*(2*hybrid%maxlcutm1+1)*(hybrid%maxindxm1-1)&
         +   (hybrid%maxindxm1-1)*atoms%nat**2&
         +   ((hybrid%maxlcutm1+1)**2*atoms%nat+hybrid%maxgptm)&
         *((hybrid%maxlcutm1+1)**2*atoms%nat+hybrid%maxgptm+1)/2 )*8
    if (.not.l_real) irecl_coulomb =irecl_coulomb *2
    OPEN(unit=778,file='coulomb1',form='unformatted',access='direct', recl=irecl_coulomb)
    id_coulomb_spm=778
#endif
62
  END SUBROUTINE open_hybrid_io2
Daniel Wortmann's avatar
Daniel Wortmann committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  
  subroutine write_cmt(cmt,nk)
    implicit none
    complex,INTENT(IN):: cmt(:,:,:)
    integer,INTENT(IN):: nk

    write(777,rec=nk) cmt
  end subroutine write_cmt

  subroutine read_cmt(cmt,nk)
    implicit none
    complex,INTENT(OUT):: cmt(:,:,:)
    integer,INTENT(IN):: nk

    read(777,rec=nk) cmt
  end subroutine read_cmt

Daniel Wortmann's avatar
Daniel Wortmann committed
80 81 82
  subroutine write_coulomb(nk,l_real,coulomb)
    implicit none
    complex,intent(in) :: coulomb(:)
83 84
    integer,intent(in) :: nk
    logical,intent(in) :: l_real
Daniel Wortmann's avatar
Daniel Wortmann committed
85 86 87 88 89 90 91 92 93 94

    if (l_real) THEN
       write(id_coulomb,rec=nk) real(coulomb)
    else
       write(id_coulomb,rec=nk) coulomb
    end if
  end subroutine write_coulomb

   subroutine write_coulomb_spm_r(nk,coulomb_mt1,coulomb_mt2,coulomb_mt3,coulomb_mtir)
    implicit none
Daniel Wortmann's avatar
Daniel Wortmann committed
95 96 97
    real,intent(in)    :: coulomb_mt1(:,:,:,:)
    real,intent(in) :: coulomb_mt2(:,:,:,:), coulomb_mt3(:,:,:)
    real,intent(in) :: coulomb_mtir(:)
Daniel Wortmann's avatar
Daniel Wortmann committed
98 99
    integer,intent(in) :: nk
    
Daniel Wortmann's avatar
Daniel Wortmann committed
100
    print *, "write coulomb",nk,size(coulomb_mt1),size(coulomb_mt2),size(coulomb_mt3),size(coulomb_mtir)
Daniel Wortmann's avatar
Daniel Wortmann committed
101 102 103 104 105
    write(id_coulomb_spm,rec=nk) coulomb_mt1,coulomb_mt2,coulomb_mt3,coulomb_mtir
  end subroutine write_coulomb_spm_r

   subroutine write_coulomb_spm_c(nk,coulomb_mt1,coulomb_mt2,coulomb_mt3,coulomb_mtir)
    implicit none
Daniel Wortmann's avatar
Daniel Wortmann committed
106 107 108
    real,intent(in)    :: coulomb_mt1(:,:,:,:)
    complex,intent(in) :: coulomb_mt2(:,:,:,:), coulomb_mt3(:,:,:)
    complex,intent(in) :: coulomb_mtir(:)
Daniel Wortmann's avatar
Daniel Wortmann committed
109 110 111 112 113 114 115
    integer,intent(in) :: nk
    
    write(id_coulomb_spm,rec=nk) coulomb_mt1,coulomb_mt2,coulomb_mt3,coulomb_mtir
  end subroutine write_coulomb_spm_c

     subroutine read_coulomb_spm_r(nk,coulomb_mt1,coulomb_mt2,coulomb_mt3,coulomb_mtir)
    implicit none
Daniel Wortmann's avatar
Daniel Wortmann committed
116 117 118
    real,intent(out)    :: coulomb_mt1(:,:,:,:)
    real,intent(out) :: coulomb_mt2(:,:,:,:), coulomb_mt3(:,:,:)
    real,intent(out) :: coulomb_mtir(:)
Daniel Wortmann's avatar
Daniel Wortmann committed
119 120
    integer,intent(in) :: nk
    
Daniel Wortmann's avatar
Daniel Wortmann committed
121
    print *, "read coulomb",nk,size(coulomb_mt1),size(coulomb_mt2),size(coulomb_mt3),size(coulomb_mtir)
Daniel Wortmann's avatar
Daniel Wortmann committed
122 123 124 125 126
    read(id_coulomb_spm,rec=nk) coulomb_mt1,coulomb_mt2,coulomb_mt3,coulomb_mtir
  end subroutine read_coulomb_spm_r

   subroutine read_coulomb_spm_c(nk,coulomb_mt1,coulomb_mt2,coulomb_mt3,coulomb_mtir)
    implicit none
Daniel Wortmann's avatar
Daniel Wortmann committed
127 128 129
    real,intent(out)    :: coulomb_mt1(:,:,:,:)
    complex,intent(out) :: coulomb_mt2(:,:,:,:), coulomb_mt3(:,:,:)
    complex,intent(out) :: coulomb_mtir(:)
Daniel Wortmann's avatar
Daniel Wortmann committed
130 131 132 133 134 135 136
    integer,intent(in) :: nk
    read(id_coulomb_spm,rec=nk) coulomb_mt1,coulomb_mt2,coulomb_mt3,coulomb_mtir
  end subroutine read_coulomb_spm_c

  subroutine read_coulomb_r(nk,coulomb)
    implicit none
    real   ,intent(out) :: coulomb(:)
137
    integer,intent(in) :: nk
Daniel Wortmann's avatar
Daniel Wortmann committed
138 139 140 141 142 143 144

    read(id_coulomb,rec=nk) coulomb
  end subroutine read_coulomb_r
  
  subroutine read_coulomb_c(nk,coulomb)
    implicit none
    complex,intent(out) :: coulomb(:)
145
    integer,intent(in) :: nk
Daniel Wortmann's avatar
Daniel Wortmann committed
146 147 148
    
    read(id_coulomb,rec=nk) coulomb
  end subroutine read_coulomb_c
Daniel Wortmann's avatar
Daniel Wortmann committed
149

Daniel Wortmann's avatar
Daniel Wortmann committed
150 151

  
Daniel Wortmann's avatar
Daniel Wortmann committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
  subroutine read_olap(mat,rec)
    implicit none
    TYPE(t_mat),INTENT(INOUT):: mat
    INTEGER,INTENT(IN)           :: rec
    
    CALL read_matrix(mat,rec,id_olap)
  END subroutine read_olap

    subroutine write_olap(mat,rec)
    implicit none
    TYPE(t_mat),INTENT(IN)   :: mat
    INTEGER,INTENT(IN)           :: rec
    
    CALL write_matrix(mat,rec,id_olap)
  END subroutine write_olap

  subroutine read_z(mat,rec)
    implicit none
    TYPE(t_mat),INTENT(INOUT):: mat
    INTEGER,INTENT(IN)           :: rec
Daniel Wortmann's avatar
Daniel Wortmann committed
172
    print *,"read z:",rec
Daniel Wortmann's avatar
Daniel Wortmann committed
173 174 175 176 177 178 179 180
    
    CALL read_matrix(mat,rec,id_z)
  END subroutine read_z

    subroutine write_z(mat,rec)
    implicit none
    TYPE(t_mat),INTENT(IN)   :: mat
    INTEGER,INTENT(IN)           :: rec
Daniel Wortmann's avatar
Daniel Wortmann committed
181 182
     print *,"write z:",rec
   CALL write_matrix(mat,rec,id_z)
Daniel Wortmann's avatar
Daniel Wortmann committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  END subroutine write_z

  subroutine read_v_x(mat,rec)
    implicit none
    TYPE(t_mat),INTENT(INOUT):: mat
    INTEGER,INTENT(IN)           :: rec
    
    CALL read_matrix(mat,rec,id_v_x)
  END subroutine read_v_x

  subroutine write_v_x(mat,rec)
    implicit none
    TYPE(t_mat),INTENT(IN)   :: mat
    INTEGER,INTENT(IN)           :: rec
    
    CALL write_matrix(mat,rec,id_v_x)
  END subroutine write_v_x

  
 

end module m_io_hybrid