24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 4083  |  回复: 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

至尊木虫 (职业作家)

【答案】应助回帖

★ ★
微尘、梦想(金币+2): 2011-05-10 19:03:47
引用回帖:
Originally posted by Gina88 at 2011-05-10 00:52:37:
谢谢您!您给我的程序所用内存比我的应该节省很多,运行实现了我想要的功能。真的非常感谢!

从得到您写的程序我一直在看,大部分能看懂。
除了下面读写
augmentation occupancies   1  33
  0.5246464E ...

部分的程序之外,这部分能看出来是反复读取和写入,可是怎么判断循环结束还是看不懂。另外
160 160 160没有看见读,怎么就能写入了呢。
这个程序真是奇妙啊。
也就高手能写出这样的程序。
要是我自己,打死我也想不出还有这个写法。
真的非常感谢snoopyzhao 了:)

在进入下面这个循环之前,如果是 spin ==2,那么所有的文件都没有关闭,如果是 spin /=2,那么除文件 1 以外都关闭了。

   do
      read(fileunit,'(a)',iostat=ios) line
      if (ios < 0) exit
      if (index (line, trim(subline)) /= 0) exit !这一行是判断是不是 160 160 160 那行的。如果是跳出读 augmentation occupancies 部分的循环。
      if (n == 1) then
         write(68,'(a)') trim(line)
      endif
   end do
   if (spin /=2) exit ! 如果 spin /=2,程序到这里已经结束了,因为 iostat 显示已经读到文件的最后了……
   if (n == 1) then
       write(68,'(a)') trim(line) !这就是写 160 160 160 那一行的
       allocate(densitydn(FFTx*FFTy*FFTz,filenum))
   end if

后面应该是这个部分一样,但那只是关系 spin ==2 的事了……
50楼2011-05-10 06:50:40
已阅   回复此楼   关注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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 311(085601)求调剂 +4 liziyeyeye 2026-03-28 4/200 2026-03-28 18:50 by 535743368
[考研] 一志愿华理,数一英一285求A区调剂 +8 AZMK 2026-03-25 12/600 2026-03-28 18:15 by AZMK
[考研] 生物学学硕,一志愿湖南大学,初试成绩338 +5 YYYYYNNNNN 2026-03-26 6/300 2026-03-28 17:50 by 狂炫麦当当
[考研] 321求调剂 +6 材料cailiao 2026-03-21 6/300 2026-03-28 13:14 by 唐沐儿
[考研] 291求调剂 +15 hhhhxn.. 2026-03-23 21/1050 2026-03-28 11:26 by self2008
[考研] 材料求调剂一志愿哈工大324 +7 闫旭东 2026-03-28 9/450 2026-03-28 08:51 by Xu de nuo
[考研] 一志愿211院校 344分 东北农业大学生物学学硕,求调剂 +5 丶风雪夜归人丶 2026-03-26 8/400 2026-03-27 19:22 by 丶风雪夜归人丶
[考研] 283求调剂(080500) +4 A child 2026-03-27 4/200 2026-03-27 15:34 by XPU李庆
[考研] 279 分 求调剂 +4 睡个好觉_16 2026-03-24 4/200 2026-03-27 15:05 by 醉在风里
[考研] 材料学硕,求调剂 6+5 糖葫芦888ll 2026-03-22 10/500 2026-03-27 08:18 by hypershenger
[考研] 284求调剂 +11 junqihahaha 2026-03-26 12/600 2026-03-27 04:37 by wxiongid
[考研] 325求调剂 +5 李嘉图·S·路 2026-03-23 5/250 2026-03-27 00:42 by wxiongid
[考研] 333求调剂 +6 wfh030413@ 2026-03-23 6/300 2026-03-26 22:45 by 学员8dgXkO
[考研] 0703化学求调剂 +3 丹青奶盖 2026-03-26 5/250 2026-03-26 20:11 by macy2011
[考研] 309求调剂 +4 gajsj 2026-03-25 5/250 2026-03-26 00:27 by Dyhoer
[考研] 303求调剂 +6 蓝山月 2026-03-25 6/300 2026-03-25 22:47 by 418490947
[考研] 347求调剂 +4 L when 2026-03-25 4/200 2026-03-25 13:37 by cocolv
[考研] 一志愿南航材料专317分求调剂 +5 炸呀炸呀炸薯条 2026-03-23 5/250 2026-03-24 16:52 by 星空星月
[考研] 一志愿吉大化学322求调剂 +4 17501029541 2026-03-23 6/300 2026-03-24 10:21 by 戴围脖的小蚊子
[考研] 335求调剂 +4 yuyu宇 2026-03-23 5/250 2026-03-23 23:49 by Txy@872106
信息提示
请填处理意见