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的回帖

Gina88

木虫 (正式写手)

引用回帖:
Originally posted by snoopyzhao at 2011-05-05 20:20:57:
双精度的话,能够精确表示的也就是小数点后 15 位吧,呵呵……

所以,不是小数点后数越多越好……

还想问您两个问题:
第一是:
如果一行有几个整数,但是整数的个数我预先不知道,这种情况下可不可以定义一个大的一维数组去读这行整数值?
第二是:
如下面的数据:第一行以下一共有33个实数,我可不可以用一个一维(33个元素)的数组去读它?(这33个数换行了)
augmentation occupancies  26  33
-0.3020203E-02 -0.3630216E-02  0.1322052E-22 -0.2276385E-24 -0.3631489E-03
-0.2377830E-24  0.8411942E-25 -0.6534484E-04  0.3774742E-02  0.1211868E-23
  0.8196879E-24  0.4815977E-06  0.4575581E-24  0.0000000E+00  0.1202539E-03
-0.7358878E-01 -0.3733756E-25 -0.7586368E-24  0.2978979E-01 -0.2504865E-24
  0.5120104E-01 -0.5159168E-02 -0.3582313E-24 -0.1759637E-24  0.2707249E-02
  0.1711978E-24  0.4539353E-02  0.2080057E-03 -0.2071017E-25  0.2595011E-25
  0.8042437E-04 -0.1039480E-25  0.1027306E-03
23楼2011-05-07 11:10:21
已阅   回复此楼   关注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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 求调剂 +7 争取九点睡 2026-03-28 8/400 2026-03-28 21:07 by 争取九点睡
[考研] 一志愿北京理工大学本科211材料工程294求调剂 +4 mikasa的围巾 2026-03-28 4/200 2026-03-28 20:44 by lbsjt
[考研] 085600,专业课化工原理,321分求调剂 +3 大馋小子 2026-03-28 3/150 2026-03-28 20:10 by wxiongid
[考研] 085600,材料与化工321分求调剂 +9 大馋小子 2026-03-28 9/450 2026-03-28 14:56 by 神马都不懂
[考研] 调剂求院校招收 +4 鹤鲸鸽 2026-03-28 4/200 2026-03-28 13:38 by 唐沐儿
[考研] 266分,求材料冶金能源化工等调剂 +7 哇呼哼呼哼 2026-03-27 9/450 2026-03-28 12:22 by zllcz
[考研] 调剂 +3 好好读书。 2026-03-28 3/150 2026-03-28 12:04 by 王保杰33
[考研] 339求调剂,想调回江苏 +6 烤麦芽 2026-03-27 8/400 2026-03-28 10:40 by 烤麦芽
[材料工程] 一志愿C9材料与化工专业总分300求调剂 +8 曼111 2026-03-24 9/450 2026-03-28 07:58 by YYYYX1234
[考研] 求调剂 +8 张zz111 2026-03-27 9/450 2026-03-28 03:41 by fmesaito
[考研] 一志愿上海理工能源动力(085800)310分求调剂 +3 zhangmingc 2026-03-27 4/200 2026-03-27 19:01 by 给你你注意休息
[考研] 一志愿华东理工大学081700,初试分数271 +6 kotoko_ik 2026-03-23 7/350 2026-03-27 12:29 by 惠州彭于晏
[考研] 一志愿211,335分,0856,求调剂院校和导师 +4 倾____萧 2026-03-27 5/250 2026-03-27 11:52 by zhshch
[考研] 中国科学院深圳先进技术研究院-光纤传感课题组招生-中国科学院大学、深圳理工大学联培 +5 YangTyu1 2026-03-26 5/250 2026-03-26 18:27 by 猫咪猫咪呀
[考研] 一志愿天津大学339材料与化工求调剂 +3 江往卖鱼 2026-03-26 3/150 2026-03-26 09:42 by 王小欠i
[考研] 考研一志愿苏州大学初始315(英一)求调剂 +3 sbdksD 2026-03-24 4/200 2026-03-25 18:16 by xcjcqu
[考研] 各位老师您好:本人初试372分 +5 jj涌77 2026-03-25 6/300 2026-03-25 14:15 by mapenggao
[考研] 上海电力大学材料防护与新材料重点实验室招收调剂研究生(材料、化学、电化学,环境) +4 我爱学电池 2026-03-23 4/200 2026-03-25 00:59 by 1027_324
[有机交流] 有机合成求助 20+3 FENGSHUJEI 2026-03-23 5/250 2026-03-24 19:31 by 88817753
[考研] 335求调剂 +4 yuyu宇 2026-03-23 5/250 2026-03-23 23:49 by Txy@872106
信息提示
请填处理意见