1 2 3 4 5 6 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
| program main
implicit none integer,parameter::N=20 character(len=90)::str,vector(3) character(len=30)::fdf,filename,suffix,prefile character(len=2),allocatable::ElemSymb(:) character(len=90),allocatable::frac(:) integer::fileid,i,j,aux,total,SpeciNo(N),k,m,point,debug integer,allocatable::ElemZ(:) integer,external:: GetElemZ character,external::num2char
debug=0
read(5,err=20,end=20,fmt='(a)') str 20 continue filename=trim(adjustl(str))//'.cell' fileid=10 open(unit=fileid,file=filename)
if(debug==1) print*,'Input string: '//trim(str)
i=0 do while(.true.) read(unit=fileid,fmt='(a)')str i=i+1 if(str(1:24)=="%ENDBLOCK POSITIONS_FRAC")then close(fileid) goto 30 end if end do
30 continue total=i aux=total-8 allocate(frac(aux)) allocate(ElemSymb(aux)) allocate(ElemZ(aux)) open(unit=fileid,file=filename) do i=1,total-1 read(unit=fileid,fmt='(a)')str if(i>1 .and. i<5) then vector(i-1)=str elseif(i>=8)then frac(i-7)=str end if end do close(unit=fileid) i=index(filename,'.cell') prefile=filename(1:(i-1)) fdf=trim(prefile)//".fdf" do i=1,aux str=frac(i) ElemSymb(i)=str(2:3) ElemZ(i)=GetElemZ(ElemSymb(i)) frac(i)=str(4:66) end do
if(debug==1)then print*,"total N.O.of Atom",aux print*,'ElemSymb',ElemSymb print*,'ElemZ',ElemZ print*,'frac',frac end if
m=1 k=0 do i=1,aux if(i==aux)then k=k+1 SpeciNo(m)=k else j=i+1 if(ElemZ(i)==ElemZ(j))then k=k+1 else SpeciNo(m)=k+1 k=0 m=m+1 endif endif enddo
if(debug==1)then print*,'N.O. of species: '//num2char(m) print*,'SpeciNo:',speciNo endif
call writetofdf(frac,SpeciNo,m,ElemZ,ElemSymb,aux,prefile,fdf,vector)
end
subroutine writetofdf(frac,SpeciNo,m,ElemZ,ElemSymb,aux,filename,fdf,vector) implicit none integer aux character(len=90) frac(aux),vector(3) character(len=2) ElemSymb(aux) integer SpeciNo(m),ElemZ(aux),m,i,count,j character(len=30) fdf,filename character(len=90)str integer,external::GetElemZ character(len=10),external ::num2char open(unit=10,file=fdf) write(10,'(a)')'SystemName '//filename write(10,'(a)')'SystemLabel '//filename write(10,'(a)')'NumberOfSpecies'//' '//num2char(m) write(10,'(a)')'NumberOfAtoms'//' '//num2char(aux) write(10,'(a)')'%block ChemicalSpeciesLabel' count=0 if(aux==1)then write(10,'(30a)')trim(num2char(1)//' '//num2char(GetElemZ(ElemSymb(1)))//' '//ElemSymb(1)) print*,ElemSymb(1) else do i=1,m count=count+SpeciNo(i) str=num2char(i)//' '//num2char(GetElemz(ElemSymb(count)))//' '//ElemSymb(count) write(10,'(a)')trim(str) print*,ElemSymb(count) enddo end if write(10,'(a)')'%endblock ChemicalSpeciesLabel' write(10,'(a)')'LatticeConstant 1.0 Ang' write(10,'(a)')'%block LatticeVectors' do i=1,3 write(10,'(a)')vector(i) end do write(10,'(a)')'%endblock LatticeVectors' write(10,'(a)')"" write(10,'(a)')'AtomicCoordinatesFormat Fractional' write(10,'(a)')'%block AtomicCoordinatesAndAtomicSpecies' count=1 if(aux==1)then write(10,'(a)')trim( frac(1))//" "//num2char(1) else do i=1,m
do j=count,SpeciNo(i)+count-1 write(10,'(a)')trim( frac(j))//" "//num2char(i) end do count=count+SpeciNo(i) end do end if write(10,'(a)')'%endblock AtomicCoordinatesAndAtomicSpecies' write(10,'(a)')'%include para.fdf'
close(10) end subroutine
subroutine copyfile(file1,file2) implicit none character(len=90) line character(len=30)file1,file2 open(11,file=trim(file1),status='old') do while(.true.) read(11,err=40,end=40,fmt='(a)')line write(10,'(a)')line end do 40 continue return end subroutine
character(len=*) function num2char(num) implicit none integer num character(len=10) str write(str,'(i4)')num num2char=trim(adjustl(str)) return end function
integer function GetElemZ(str) implicit none integer i character(len=2) str
if(str=="H" .or. str=="H " .or. str== " H" )then i=1 elseif(str=="He")then i=2 elseif(str=="Li")then i=3 elseif(str=="Be")then i=4 elseif(str=="B" .or. str=="B " .or. str== " B" )then i=5 elseif(str=="C" .or. str=="C " .or. str== " C" )then i=6 elseif(str=="N" .or. str=="N " .or. str== " N" )then i=7 elseif(str=="O" .or. str=="O " .or. str== " O" )then i=8 elseif(str=="F" .or. str=="F " .or. str== " F" )then i=9 elseif(str=="Na")then i=11 elseif(str=="Mg")then i=12 elseif(str=="Al")then i=13 elseif(str=="Si" )then i=14 elseif(str=="P" .or. str=="P " .or. str== " P" )then i=15 elseif(str=="S" .or. str=="S " .or. str== " S" )then i=16 elseif(str=="Cl")then i=17 elseif(str=="K" .or. str=="K " .or. str== " K" )then i=19 elseif(str=="Ca")then i=20 elseif(str=="Sc")then i=21 elseif(str=="Ti")then i=22 elseif(str=="V" .or. str=="V " .or. str== " V" )then i=23 elseif(str=="Cr" )then i=24 elseif(str=="Mn")then i=25 elseif(str=="Fe")then i=26 elseif(str=="Co")then i=27 elseif(str=="Ni")then i=28 elseif(str=="Cu")then i=29 elseif(str=="Zn")then i=30 elseif(str=="Ga")then i=31 elseif(str=="Ge")then i=32 elseif(str=="As")then i=33 elseif(str=="Se")then i=34 elseif(str=="Br")then i=35 elseif(str=="Rb")then i=37 elseif(str=="Sr")then i=38 elseif(str=="Y" .or. str=="Y " .or. str== " Y" )then i=39 elseif(str=="Zr")then i=40 elseif(str=="Nb")then i=41 elseif(str=="Mo")then i=42 elseif(str=="Tc")then i=43 elseif(str=="Ru")then i=44 elseif(str=="Rh")then i=45 elseif(str=="Pd")then i=46 elseif(str=="Ag")then i=47 elseif(str=="Cd")then i=48 elseif(str=="In")then i=49 elseif(str=="Sn")then i=50 elseif(str=="Sb")then i=51 elseif(str=="Te")then i=52 elseif(str=="I" .or. str==' I' .or. str=='I ')then i=53 elseif(str=="Cs")then i=55 elseif(str=="Ba")then i=56 elseif(str=="Bi")then i=83 else i=0 stop "element not found !" endif GetElemZ=i if(GetElemZ==0) stop return end function
|