if (.not. out_ex) then
print *, "OUTCAR: file not exist."
stop
end if
if (.not. con_ex) then
print *, "CONTCAR: file not exist."
stop
end if
! Read the species in OUTCAR
open(unit=11,file='OUTCAR',status='OLD')
atomkind=0
do while(.not.eof)
read(11,*,end=10) line
if(index(line,'VRHFIN').ne.0) then
atomkind=atomkind+1
upper=index(line,':')-1
lower=index(line,'=')+1
lable(atomkind)=line(lower:upper)
end if
end do
close(11)
10 continue
! Read POSCAR to process lattice information and amount of each kind
! Process the label list
do i=1,atomkind
do j=1,iatom(i)
latom(j,i)=lable(i)
end do
end do
do i=1,3
temp(i)=0.0
do j=1,3
temp(i)=temp(i)+rv(j,i)**2
end do
temp(i)=sqrt(temp(i))
end do
a=temp(1)
b=temp(2)
c=temp(3)
do i=1,3
temp(3+i)=0.0
end do
do j=1,3
temp(4)=temp(4)+rv(j,2)*rv(j,3)
temp(5)=temp(5)+rv(j,1)*rv(j,3)
temp(6)=temp(6)+rv(j,1)*rv(j,2)
end do
temp(4)=temp(4)/(temp(2)*temp(3))
temp(5)=temp(5)/(temp(1)*temp(3))
temp(6)=temp(6)/(temp(1)*temp(2))
open (21,file=opsition)
write(21,300) system
write(21,300) "lattice lengths: "
write(21,300) "a=", a
write(21,300) "b=", b
write(21,300) "c=", c
write(21,300) "lattice angles: "
write(21,300) "alpha=", alpha
write(21,300) "beta=", beta
write(21,300) "gamma=", gamma
close(21)
! Read OUTCAR to process the coordinates
open(unit=11,file='OUTCAR',status='OLD')
open (21,file=opsition)
do while(.not.eof)
read(11,*,end=30) line
if (index(line,'POSITION').ne.0) then
read(11,*,end=30) line
do i=1,atomkind
do j=1,iatom(i)
read(11,*,end=30) dx(j,i), dy(j,i), dz(j,i)
write(21,300) latom(j,i), dx(j,i), dy(j,i), dz(j,i)
end do
end do
if (.not. out_ex) then
print *, "OUTCAR: file not exist."
stop
end if
if (.not. con_ex) then
print *, "CONTCAR: file not exist."
stop
end if
! Read the species in OUTCAR
open(unit=11,file='OUTCAR',status='OLD')
atomkind=0
do while(.not.eof)
read(11,*,end=10) line
if(index(line,'VRHFIN').ne.0) then
atomkind=atomkind+1
upper=index(line,':')-1
lower=index(line,'=')+1
lable(atomkind)=line(lower:upper)
end if
end do
close(11)
10 continue
! Read POSCAR to process lattice information and amount of each kind
! Process the label list
do i=1,atomkind
do j=1,iatom(i)
latom(j,i)=lable(i)
end do
end do
do i=1,3
temp(i)=0.0
do j=1,3
temp(i)=temp(i)+rv(j,i)**2
end do
temp(i)=sqrt(temp(i))
end do
a=temp(1)
b=temp(2)
c=temp(3)
do i=1,3
temp(3+i)=0.0
end do
do j=1,3
temp(4)=temp(4)+rv(j,2)*rv(j,3)
temp(5)=temp(5)+rv(j,1)*rv(j,3)
temp(6)=temp(6)+rv(j,1)*rv(j,2)
end do
temp(4)=temp(4)/(temp(2)*temp(3))
temp(5)=temp(5)/(temp(1)*temp(3))
temp(6)=temp(6)/(temp(1)*temp(2))
open (21,file=opsition)
write(21,300) system
write(21,300) "lattice lengths: "
write(21,300) "a=", a
write(21,300) "b=", b
write(21,300) "c=", c
write(21,300) "lattice angles: "
write(21,300) "alpha=", alpha
write(21,300) "beta=", beta
write(21,300) "gamma=", gamma
close(21)
! Read OUTCAR to process the coordinates
open(unit=11,file='OUTCAR',status='OLD')
open (21,file=opsition)
do while(.not.eof)
read(11,*,end=30) line
if (index(line,'POSITION').ne.0) then
read(11,*,end=30) line
do i=1,atomkind
do j=1,iatom(i)
read(11,*,end=30) dx(j,i), dy(j,i), dz(j,i)
write(21,300) latom(j,i), dx(j,i), dy(j,i), dz(j,i)
end do
end do