24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 4085  |  回复: 59
本帖产生 3 个 程序强帖 ,点击这里进行查看
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

Gina88

木虫 (正式写手)

[求助] 写了一个fortran90的小程序,编译通不过,请大侠帮忙

program cell-POSCAR

!announcement begin***********************************
implicit none
real(8)::cellcon(3,3)       !lattice constance
real(8),allocatable::atomcoor(:,  !direct coordinate of atoms
integer,allocatable::type(
integer i,j,k,m,n           !m:atom number,n:type number
character(len=1) nonsense    !to contain something that will not be used
character(len=2) position   !to read %
character(len=2) element1,element2  
!End announcement************************************

!Begin reading data from "cell"****************************
open(unit=18,file="cell",status="old"
read(18,*)nonsense
do i=1,3  
  read(18,*)cellcon(i,1),cellcon(i,2),cellcon(i,3)
end do
read(18,*)position
read(18,*)nonsense
read(18,*)nonsense
n=0;m=0
read(18,*)element2
do while(position/=element2)
  n=n+1
  element1=element2
  do while(element1==element2)
    m=m+1
    read(18,*)element2
  end do
end do
close(18)

allocate(type(n))
allocate(atomcoor(m,3))

open(unit=28,file="cell",status="old"
read(28,*)nonsense
read(28,*)nonsense
read(28,*)nonsense
read(28,*)nonsense
read(28,*)nonsense
read(28,*)nonsense
read(28,*)nonsense
read(28,*)element2,atomcoor(1,1),atomcoor(1,2),atomcoor(1,3)
i=1;k=1
element1=element2
if (m==1) then
  type(1)=1
else if
  do j=2,m
    read(28,*)element2,atomcoor(j,1),atomcoor(j,2),atomcoor(j,3)
    if(element1==element2) then
      k=k+1
      if(m==j) type(i)=k
    else if
      type(i)=k
      i=i+1
      element1=element2
      k=1
      if(m==j) type(i)=k
    end if   
  end do
end if
close(28)
!End reading data from "cell"****************************

!Begin writing to "POSCAR"******************************
open(unit=38,file="POSCAR",status="replace"
write(38,10)System
write(38,100)cellcon(1,1)
do i=1,3
  write(38,200)(cellcon(i,j)/cellcon(1,1),j=1,3)
end do
write(38,60)(type(i),i=1,n)
write(38,20)Selective,dynamic
write(38,30)Direct
do i=1,m
  write(38,300)(atomcoor(i,j),j=1,3)
end do
10 FORMAT(1X,A6)
20 FORMAT(1X,A9,1X,A7)
30 FORMAT(1X,A6)
60 FORMAT(1X,n(I3,2X))
100 FORMAT(1X,F18.16)
200 FORMAT(1X,3(F18.16,3X))
300 FORMAT(1X,F18.16,2X,F18.16,2X,F18.16,2X,'T',2X,'T',2X,'T')
close(38)
!End writing to "POSCAR"********************************

end
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

【答案】应助回帖

引用回帖:
Originally posted by Gina88 at 2011-05-09 09:51:06:
en,相减的数据不包含augmentation occupancies的那部分,
相减的是384 160 24以下,augmentation occupancies以上的那部分数据。
即CHGCAR1=CHGCAR1-CHGCAR2。

谢谢大侠了!

数据就是EIGENVAL,还有C ...

给一个实现,但与你最初的想法可能不一样,由于你只进行部分差减,因为除此以外部分的数据,全部以字符串形式读入与输出,只定义为数不多几个数组,而且把数组的维数也降下来,你看一下吧……
CODE:
program diff_CHGCAR

!announcement begin********************
implicit none
real(8),allocatable::densityup(:,:)
real(8),allocatable::densitydn(:,:)
integer,allocatable::atomnum(:)
integer i,k,n,ios,fileunit
integer filenum,atomsum,typenum,line_len
integer FFTx,FFTy,FFTz
character(len=80)::line
character(len=80)::filename
character(len=80)::subline
!End announcement**********************

!Begin reading data from "EIGENVAL"******
real(8)::atomnum1,atomnum2,notkown3
integer spin                    
open(unit=18,file="EIGENVAL")
read(18,*)atomnum1,atomnum2,notkown3,spin
close(18)
!End reading data from "EIGENVAL"********

write(*,*)"number of files:(2 or 3?)"
read(*,*)filenum

open(unit=68,file="CHGCAR",status="replace")

do n=1,filenum
   write(filename,'(a,i0)') 'CHGCAR',n
   fileunit = 28 + n-1
   open(unit=fileunit,file=filename,status='old')
   read(fileunit,'(a)')line
   if (n==1) write(68,'(a)') trim(line)
   read(fileunit,'(a)')line
   if (n==1) write(68,'(a)') trim(line)
   do i=1,3
      read(fileunit,'(a)')line
      if (n==1) write(68,'(a)') trim(line)
   end do
   read(fileunit,'(a)')line
   if (n==1) then
      write(68,'(a)') trim(line)
      line=adjustl(line)
      line_len=len_trim(line)
      typenum=1
      do i=1,line_len
         if(line(i:i)==' ' .and. line(i:i+1)/=' ') typenum=typenum+1
      end do
      allocate(atomnum(typenum))
   end if
   read(fileunit,'(a)') line
   if (n==1) then
      write(68,'(a)') trim(line)
      read(line,*) (atomnum(i),i=1,typenum)
      atomsum=sum(atomnum)
   end if
   read(fileunit,'(a)') line
   if(n==1) write(68,'(a)') trim(line)
   do i=1,atomsum
      read(fileunit,'(a)') line
      if(n==1) write(68,'(a)') trim(line)
   end do
   read(fileunit,'(a)') line
   if(n==1) write(68,'(a)')
   read(fileunit,'(a)') line
   if(n==1) write(68,'(a)') trim(line)
   subline = adjustl(line)
   read(line,*) FFTx,FFTy,FFTz
   if (n==1)  allocate(densityup(FFTx*FFTy*FFTz,filenum))
   read(fileunit,*)(densityup(i,n),i=1,FFTx*FFTy*FFTz)
   if (n/=1) then
      do k=2,FFTx*FFTy*FFTz
         densityup(k,1) = densityup(k,1)-densityup(k,n)
      end do
   end if
if (spin /=2 .and. n/=1) close(fileunit)
end do

write(68,'(5e16.9)')(densityup(k,1),k=1,FFTx*FFTy*FFTz)

do n=1,filenum
   fileunit = 28 + n-1
   do
      read(fileunit,'(a)',iostat=ios) line
      if (ios < 0) exit
      if (index (line, trim(subline)) /= 0) exit
      if (n == 1) then
         write(68,'(a)') trim(line)
      endif
   end do
   if (spin /=2) exit
   if (n == 1) then
       write(68,'(a)') trim(line)
       allocate(densitydn(FFTx*FFTy*FFTz,filenum))
   end if
   read(fileunit, *) (densityup(i,n),i=1,FFTx*FFTy*FFTz)
   if (n/=1) then
      do k=2,FFTx*FFTy*FFTz
         densityup(k,1) = densityup(k,1)-densityup(k,n)
      end do
   end if
   if(n/=1) close(fileunit)
end do

if (spin == 2) then
   write(68,'(5e16.9)')(densitydn(k,1),k=1,FFTx*FFTy*FFTz)
   do
      read(28,'(a)',iostat=ios) line
      if (ios < 0) exit
      write(68,'(a)') trim(line)
   end do
end if

close(28)
close(68)
stop
end

44楼2011-05-09 16:41:46
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 60 个回答

Gina88

木虫 (正式写手)

这个是cell的内容
%BLOCK LATTICE_CART
      12.782529349912258      -0.000000000000028       0.000000000000001
      -0.000000000000000      13.529995000000000       0.000000000000001
       0.000000000000000       0.000000000000000      10.000000000000000
%ENDBLOCK LATTICE_CART

%BLOCK POSITIONS_FRAC
  H   0.0555000007152556   0.1666999995708470   0.5000000000000000
  H   0.2221666673819220   0.0666999995708464   0.5000000000000000
  H   0.1110555562708110   0.0666999995708466   0.5000000000000000
  H   0.1110555562708110   0.0666999995708466   0.5000000000000000
  C   0.2777222229374780   0.1666999995708470   0.5000000000000000
  C   0.3888333340485890   0.1666999995708470   0.5000000000000000
  C   0.5555000007152560   0.0666999995708465   0.5000000000000000
  S   0.4443888896041450   0.0666999995708466   0.5000000000000000
  S   0.6110555562708110   0.1666999995708470   0.5000000000000000
  si   0.6110555562708110   0.1666999995708470   0.5000000000000000
%ENDBLOCK POSITIONS_FRAC
2楼2011-05-04 17:52:59
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

Gina88

木虫 (正式写手)

那个笑脸:)是
冒号+右括号

那个红脸”)是
右括号
3楼2011-05-04 17:56:30
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

Gina88

木虫 (正式写手)

program cell-POSCAR

!announcement begin***********************************
implicit none
real(8)::cellcon(3,3)       !lattice constance
real(8),allocatable::atomcoor(:,  !direct coordinate of atoms
integer,allocatable::type(
integer i,j,k,m,n           !m:atom number,n:type number
character(len=1) nonsense    !to contain something that will not be used
character(len=2) position   !to read %
character(len=2) element1,element2  
!End announcement************************************

!Begin reading data from "cell"****************************
open(unit=18,file="cell",status="old"
read(18,*)nonsense
do i=1,3  
  read(18,*)cellcon(i,1),cellcon(i,2),cellcon(i,3)
end do
read(18,*)position
read(18,*)nonsense
read(18,*)nonsense
n=0;m=0
read(18,*)element2
do while(position/=element2)
  n=n+1
  element1=element2
  do while(element1==element2)
    m=m+1
    read(18,*)element2
  end do
end do
close(18)

allocate(type(n))
allocate(atomcoor(m,3))

open(unit=28,file="cell",status="old"
read(28,*)nonsense
read(28,*)nonsense
read(28,*)nonsense
read(28,*)nonsense
read(28,*)nonsense
read(28,*)nonsense
read(28,*)nonsense
read(28,*)element2,atomcoor(1,1),atomcoor(1,2),atomcoor(1,3)
i=1;k=1
element1=element2
if (m==1) then
  type(1)=1
else if
  do j=2,m
    read(28,*)element2,atomcoor(j,1),atomcoor(j,2),atomcoor(j,3)
    if(element1==element2) then
      k=k+1
      if(m==j) type(i)=k
    else if
      type(i)=k
      i=i+1
      element1=element2
      k=1
      if(m==j) type(i)=k
    end if   
  end do
end if
close(28)
!End reading data from "cell"****************************

!Begin writing to "POSCAR"******************************
open(unit=38,file="POSCAR",status="replace"
write(38,10)System
write(38,100)cellcon(1,1)
do i=1,3
  write(38,200)(cellcon(i,j)/cellcon(1,1),j=1,3)
end do
write(38,60)(type(i),i=1,n)
write(38,20)Selective,dynamic
write(38,30)Direct
do i=1,m
  write(38,300)(atomcoor(i,j),j=1,3)
end do
10 FORMAT(1X,A6)
20 FORMAT(1X,A9,1X,A7)
30 FORMAT(1X,A6)
60 FORMAT(1X,n(I3,2X))
100 FORMAT(1X,F18.16)
200 FORMAT(1X,3(F18.16,3X))
300 FORMAT(1X,F18.16,2X,F18.16,2X,F18.16,2X,'T',2X,'T',2X,'T')
close(38)
!End writing to "POSCAR"********************************

end
4楼2011-05-04 17:58:28
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 085701求调剂初试286分 +4 secret0328 2026-03-28 4/200 2026-03-28 21:09 by 15366876211
[考研] 315求调剂 +4 akie... 2026-03-28 5/250 2026-03-28 21:05 by zhq0425
[考研] 一志愿北京化工大学材料与化工(085600)296求调剂 +11 稻妻小编 2026-03-26 11/550 2026-03-28 21:04 by 唐沐儿
[考研] 调剂310 +6 温柔的晚安 2026-03-25 7/350 2026-03-28 16:04 by qq2000
[考研] 312,生物学求调剂 +3 小译同学abc 2026-03-28 3/150 2026-03-28 15:32 by 落睿可思
[考研] 086502化学工程342求调剂 +6 阿姨复古不过 2026-03-27 6/300 2026-03-28 07:06 by wangy0907
[考研] 315分求调剂 +7 26考研上岸版26 2026-03-26 7/350 2026-03-28 04:05 by fmesaito
[考研] 0703化学求调剂,各位老师看看我!!! +5 祁祺祺 2026-03-25 5/250 2026-03-27 21:44 by 东方猪猪
[考研] 279 分 求调剂 +4 睡个好觉_16 2026-03-24 4/200 2026-03-27 15:05 by 醉在风里
[考研] 调剂 +3 李嘉图·S·路 2026-03-27 3/150 2026-03-27 11:19 by wangjy2002
[考研] 327求调剂 +7 prayer13 2026-03-23 7/350 2026-03-26 20:48 by 不吃魚的貓
[考研] 中国科学院深圳先进技术研究院-光纤传感课题组招生-中国科学院大学、深圳理工大学联培 +5 YangTyu1 2026-03-26 5/250 2026-03-26 18:27 by 猫咪猫咪呀
[考研] B区考研调剂 +4 yqdszhdap- 2026-03-22 5/250 2026-03-25 08:51 by baoball
[考研] 289材料与化工(085600)B区求调剂 +4 这么名字咋样 2026-03-22 5/250 2026-03-25 08:20 by mx.yue
[考研] 上海电力大学材料防护与新材料重点实验室招收调剂研究生(材料、化学、电化学,环境) +4 我爱学电池 2026-03-23 4/200 2026-03-25 00:59 by 1027_324
[考研] 求调剂 +6 研研,接电话 2026-03-24 7/350 2026-03-24 17:01 by barlinike
[考研] 求调剂一志愿武汉理工大学材料工程(085601) +5 WW.' 2026-03-23 7/350 2026-03-24 14:50 by sprinining
[考研] 环境学硕288求调剂 +8 皮皮皮123456 2026-03-22 8/400 2026-03-23 23:47 by 热情沙漠
[考研] 284求调剂 +3 yanzhixue111 2026-03-23 6/300 2026-03-23 22:58 by pswait
[考研] 求老师收我 +3 zzh16938784 2026-03-23 3/150 2026-03-23 12:56 by ztnimte
信息提示
请填处理意见