24小时热门版块排行榜    

查看: 3502  |  回复: 11
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

贺仪

铁杆木虫 (著名写手)

[求助] fortran编译 read出错 完毕

错误提示
POSITION.F(31): error #6358: Constants and expressions are invalid in read-only I/O lists.   [MSP]
      read(15,*) (msp(i),i=1,10)
前面msp有定义
character msp(10)
  read(15,*) (msp(i),i=1,10)
语法有问题吗?

一下是全部程序
      program getpos
ccccccccc  12 is SPPARKS OUTPUT  cccccccc
ccccccccc 15 is the molecure  ccccccccc
ccccccccc  13 is OUTPUT   ccccccccccc
      integer mnum nsp
      real coord(2000,3)
      real species(10,3)
      integer nsp(10)
      real x y z
      character tile cellp cella cellb cellz msp(10)  
      open(12,file='POSCAR',status='old')
      open(15,file='POSCAR',status='old')
      open(13,file='CONTCAR',status='new')
ccccccccccccccccccc sys param a b c cccccccccccccc
      read(12,*) tile
      write(13,*) tile
      read(12,*) cellp
      write(13,*) cellp
      read(12,*) cella ;
      write(13,*) cella
      read(12,*) cellb ;
      write(13,*) cellb
      read(12,*) cellc ;
      write(13,*) cellc
      read(15,*);
      read(15,*);
      read(15,*);
      read(15,*);
      read(15,*);
cccccccccccccccccccc atom char ccccccccccccccccccccccc
      read(15,*) (msp(i),i=1,10)
      write(13,*) (msp(i),i=1,10)
      read(12,*);
cccccccccccccccccccc atom num  cccccccccccccccccccccccc
      read(12,*) mnum
      read(15,*) (nsp(i),i=1,10)
      DO i=1, 10
         N_anum=mnum*nsp(i)
         write(13,N_anum)
      END DO
      read(12,*)
      read(15,*)
      write(13,*) 'R'
cccccccccccccccc  read molecue coord cccccccccccc
      DO i=1, mnum
         read(12,*) (coord(i,j),j=1,13)
      ENDDO
      close(12)
cc
      DO j=1, 10                !!! species cyc !!!!!!
            DO i=1, nsp(j)          !!! the j atom cyc !!!!!!
                  read(15,*) x y z  !!!!!!!!!!!!!!!!!!!!!!!! molecure coord !!!!!!!!!!!!!
                      DO k=1, mnum
                                nx=x+coord(k,1)
                                ny=y+coord(k,2)
                                nz=z+coord(k,3)
                                write(13,*) nx ,ny ,nz
                      ENDDO
            ENDDO
      ENDDO
          close(15)
          close(13)
      END

[ Last edited by 贺仪 on 2011-8-23 at 14:53 ]
回复此楼
嘟啦啦嘟啦啦嘟
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

贺仪

铁杆木虫 (著名写手)

余泽成: 刚才发错了,呵呵,金币送你了,常来程序语言版! 2011-08-24 16:22:03
引用回帖:
5楼: Originally posted by snoopyzhao at 2011-08-23 15:00:35:
不知道你这个是啥意思?

你给出的代码中太多不规范的东西,呵呵,反正我用 gfortran 会提示很多错误……

是的 错误很多 这是最开始的 现在调好了,程序如下:
      program getpos
ccccccccc  12 is SPPARKS OUTPUT  cccccccc
ccccccccc 15 is the molecure  ccccccccc
ccccccccc  13 is OUTPUT   ccccccccccc
      integer mnum Nanum
      real::coord(2000,3)
      integer::nsp(4)
      real x y z
      character tile cellp
      character::msp(4)
      real::cella(3)
      real::cellb(3)
      real::cellc(3)  
      open(12,file='POSCARS',status='old')
      open(15,file='POSCARV',status='old')
      open(13,file='CONTCAR',status='new')
ccccccccccccccccccc sys param a b c cccccccccccccc
      read(12,*) tile
      write(13,"(2XA10)" tile
      read(12,*) cellp
      write(13,*) cellp
      read(12,*) (cella(i),i=1,3)
      write(13,"(3(2XF10.7))" (cella(i),i=1,3)
      read(12,*) (cellb(i),i=1,3)
      write(13,"(3(2XF10.7))" (cellb(i),i=1,3)
      read(12,*) (cellc(i),i=1,3)
      write(13,"(3(2XF10.7))" (cellc(i),i=1,3)
      read(15,*)
      read(15,*)
      read(15,*)
      read(15,*)
      read(15,*)
cccccccccccccccccccc atom char ccccccccccccccccccccccc
      read(15,*) (msp(i),i=1,4)
      write(13,"(4(2XA2))" (msp(i),i=1,4)
      read(12,*)
cccccccccccccccccccc atom num  cccccccccccccccccccccccc
      read(12,*) mnum
      read(15,*) (nsp(i),i=1,4)
      DO i=1, 4
               Nanum=mnum*nsp(i)
         write(13,10) Nanum
      END DO
      read(12,*)
      read(15,*)
      write(13,"(/,A1)" 'D'
      DO i=1, mnum
         read(12,*) (coord(i,j),j=1,3)
      END DO
      close(12)
cc
      DO j=1, 4                !!! species cyc !!!!!!
            DO i=1, nsp(j)          !!! the j species atom cyc !!!!!!
                  read(15,*) x, y, z  !!!!!!!!!!!!!!!!!!!!!!!! molecure coord !!!!!!!!!!!!!
                      DO k=1, mnum
                          write(13,100) x+coord(k,1), y+coord(k,2), z+coord(k,3)
                      END DO
            END DO
      END DO
      close(15)
      close(13)
10    FORMAT(2XI5.0,\)
100   FORMAT(3(2XF10.6))
      END
嘟啦啦嘟啦啦嘟
6楼2011-08-23 15:06:55
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 12 个回答

snoopyzhao

至尊木虫 (职业作家)

【答案】应助回帖

★ ★
贺仪(金币+5): 多谢指教! 2011-08-23 14:53:23
余泽成(金币+2): 谢谢参与应助! 2011-08-24 16:20:44
引用回帖:
1楼: Originally posted by 贺仪 at 2011-08-23 09:57:29:
错误提示
POSITION.F(31): error #6358: Constants and expressions are invalid in read-only I/O lists.   [MSP]
      read(15,*) (msp(i),i=1,10)
前面msp有定义
character msp(10)
  read(15,*) (msp(i ...

character 类型数据不能用 read(15, *) 这种方式来读取吧。 * 只适合于数值,而且读出来的格式只能是浮点数……

如果你的 msp 是用来存单个字符(10个?),那么你可以用下面的代码试试(没有测试,不保证正确……)
CODE:
read(15, '(a1)') (msp(i), i=1,10)

2楼2011-08-23 14:31:59
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

【答案】应助回帖

★ ★
贺仪(金币+5): 多谢指教! 2011-08-23 14:53:34
余泽成(金币+2): 辛苦了! 2011-08-24 16:20:55
看来我前面的说法没有切入要点,你的问题在于
      real x y z
      character tile cellp cella cellb cellz msp(10)  
上面两行各个变量之间应该用逗号来分隔……

当然,字符的确不能用 read(15,*) 这种方式来读……
3楼2011-08-23 14:47:28
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

贺仪

铁杆木虫 (著名写手)


余泽成(金币+1): 谢谢参与应助! 2011-08-24 16:21:05
不是读取的原因
在定义的时候用“::”后就可以了
嘟啦啦嘟啦啦嘟
4楼2011-08-23 14:55:38
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考博] 博士自荐 +4 kkluvs 2026-02-28 4/200 2026-03-01 10:19 by 馥安馥安
[考研] 317一志愿华南理工电气工程求调剂 +5 Soliloquy_Q 2026-02-28 9/450 2026-03-01 10:15 by Soliloquy_Q
[考研] 材料化工调剂 +3 今夏不夏 2026-03-01 3/150 2026-03-01 10:13 by 杨杨杨紫
[考研] 0856化工专硕求调剂 +4 董boxing 2026-03-01 4/200 2026-03-01 10:11 by 杨杨杨紫
[硕博家园] 2025届双非化工硕士毕业,申博 +3 更多的是 2026-02-27 4/200 2026-03-01 10:04 by ztg729
[考研] 272求调剂 +4 材紫有化 2026-02-28 4/200 2026-03-01 09:20 by L135790
[考研] 291分工科求调剂 +5 science饿饿 2026-03-01 5/250 2026-03-01 09:19 by L135790
[论文投稿] 求助coordination chemistry reviews 的写作模板 10+3 ljplijiapeng 2026-02-27 4/200 2026-03-01 09:07 by babero
[考研] 材料调剂 +4 爱擦汗的可乐冰 2026-02-28 4/200 2026-03-01 00:38 by 猫猫球alter
[基金申请] 面上模板改不了页边距吧? +5 ieewxg 2026-02-25 6/300 2026-03-01 00:10 by addressing
[考研] 307求调剂 +4 73372112 2026-02-28 6/300 2026-03-01 00:04 by ll247
[考研] 化工专硕348,一志愿985求调剂 +4 弗格个 2026-02-28 6/300 2026-02-28 22:00 by wang_dand
[考研] 292求调剂 +3 yhk_819 2026-02-28 3/150 2026-02-28 21:57 by gaoxiaoniuma
[考研] 295求调剂 +5 19171856320 2026-02-28 5/250 2026-02-28 21:39 by gaoxiaoniuma
[考博] 26申博 +4 想申博! 2026-02-26 4/200 2026-02-28 21:37 by limorning
[考研] 求调剂 +4 repeatt?t 2026-02-28 4/200 2026-02-28 21:16 by gaoxiaoniuma
[考研] 276求调剂 +3 路lyh123 2026-02-28 4/200 2026-02-28 19:45 by 路lyh123
[考研] 0856调剂 +3 刘梦微 2026-02-28 3/150 2026-02-28 13:22 by houyaoxu
[考研] 寻找调剂 +3 LYidhsjabdj 2026-02-28 3/150 2026-02-28 12:59 by miniwendy
[硕博家园] 【博士招生】太原理工大学2026化工博士 +4 N1ce_try 2026-02-24 8/400 2026-02-26 08:40 by N1ce_try
信息提示
请填处理意见