24小时热门版块排行榜    

查看: 1958  |  回复: 9
本帖产生 1 个 程序强帖 ,点击这里进行查看

li_clifff

银虫 (正式写手)

[求助] 请教一个fortran小程序编译出错的问题,谢谢

如下程序编译不成功,不知道问题出在哪里,mesh.dat文件格式是第一行是numnp, numel的数值,第二行到最后是mesh的各个四边形的具体坐标。错误信息是:Error: A specification expression object must be a dummy argument, a COMMON block object, or an object accessible through host or use association   [NUMNP]  integer*4 numnp, numel   
还有G:\Program Files\Microsoft Visual Studio\MyProjects\mesh\pmesh.for(22) : Error: An automatic object is invalid in a main program.   [X] dimension x(2,numnp),ia(numnp),请多多指教,谢谢                        


  PROGRAM pmesh
c
c-----------------------------------------------------------------
c     purpose : to eliminate the string from existed mesh data
c               warning : the mesh has to be made out of quadrangles only
c     in :c
c     out :
c             x     : array containing node coordinates
c             ia    : nodes reference number
c             ien   : list of element nodes
c             mat   : material ref. numbers for all elements
c             in    : element sides ref. number
cc-----------------------------------------------------------------------
c
      implicit real*8 (a-h,o-z)
      real xreal,yreal
      integer*4 numnp, numel                           
      dimension x(2,numnp),ia(numnp)
      dimension ien(4,numel),mat(numel),in(4,numel)
   
      open(57,file='pmesh1.dat')
      open(58,file='pmesh2.dat')
      
         call sizemesh(numnp, numel)
         open(21,file='mesh.dat')
          read(21,*)
          do 300 i=1,numnp                   
          read(21,2100)idum,xreal,yreal,ia(i)
              x(1,i) = xreal
              x(2,i) = yreal
          write(57,*)idum,xreal,yreal,ia(i)
300    continue
          do 500 n=1,numel
          read(21,2300)ndum,(ien(i,n),i=1,4),(in(i,n),i=1,4)
          write(58,*)ndum,(ien(i,n),i=1,4),(in(i,n),i=1,4)
500    continue
          close(21)

2100  format(i5,2x,e15.5,2x,e12.5,2x,i2)
2300  format(5(i5,2x),4(i2,2x))
          end
c**************************************************************


     subroutine sizemesh(numnp,numel)

        integer numnp, numel

      open(21,file='mesh.dat')
      read(21,*) numnp,numel
     close(21)
     return
     end
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

【答案】应助回帖

★ ★
余泽成(金币+2): 谢谢参与应助! 2011-08-24 16:26:52
ben_ladeng: 专家考核存档 2011-09-28 11:39:50
你主程中的 numnp 和 numel 必须赋值,否则必须使用动态数组,那么你的 x, ia, ien, mat, in 等数组就需要用 allocatable 之类的关键词重新声明,然后在调用子程序 sizemesh 之后,用 allocated 来分配内存。
2楼2011-08-24 11:13:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★
li_clifff(金币+20): 确实是这样,动态数组,学习了,谢谢 2011-08-24 11:36:10
余泽成(金币+3): 辛苦了! 2011-08-24 16:27:14
dubo(金币+5, 程序强帖+1): 多谢应猪 2011-08-27 16:42:39
ben_ladeng: 专家考核存档 2011-09-28 11:40:00
上面错了一点儿,不是用 allocated,而是用 allocate 来分配内存。下面是修改后的程序:
CODE:
      PROGRAM pmesh
c
c-----------------------------------------------------------------
c     purpose : to eliminate the string from existed mesh data
c               warning : the mesh has to be made out of quadrangles only
c     in :c
c     out :
c             x     : array containing node coordinates
c             ia    : nodes reference number
c             ien   : list of element nodes
c             mat   : material ref. numbers for all elements
c             in    : element sides ref. number
cc-----------------------------------------------------------------------
c
      implicit real*8 (a-h,o-z)
      real xreal,yreal
      integer*4 numnp, numel                           
      real, allocatable :: x(:,:)
      integer*4, allocatable :: ien(:,:), ia(:), mat(:), in(:,:)
!     dimension x(2,numnp),ia(numnp)
!     dimension ien(4,numel),mat(numel),in(4,numel)
   
      open(57,file='pmesh1.dat')
      open(58,file='pmesh2.dat')
      
         call sizemesh(numnp, numel)
         allocate(x(2,numnp),ia(numnp),ien(4,numel),mat(numel),
     +             in(4,numel))
         open(21,file='mesh.dat')
          read(21,*)
          do 300 i=1,numnp                  
          read(21,2100)idum,xreal,yreal,ia(i)
              x(1,i) = xreal
              x(2,i) = yreal
          write(57,*)idum,xreal,yreal,ia(i)
300    continue
          do 500 n=1,numel
          read(21,2300)ndum,(ien(i,n),i=1,4),(in(i,n),i=1,4)
          write(58,*)ndum,(ien(i,n),i=1,4),(in(i,n),i=1,4)
500    continue
          close(21)

2100  format(i5,2x,e15.5,2x,e12.5,2x,i2)
2300  format(5(i5,2x),4(i2,2x))
          end
c**************************************************************


      subroutine sizemesh(numnp,numel)

        integer numnp, numel

      open(21,file='mesh.dat')
      read(21,*) numnp,numel
      close(21)
      return
      end

3楼2011-08-24 11:26:59
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

li_clifff

银虫 (正式写手)


dubo(金币+1): 欢迎讨论 2011-08-27 16:41:30
但是我真看到有的f77程序主程序不用allocatable,直接调用子程序生成的numnp, numel就可以,就是按我那样开始写的,不知道自己按那样的方式怎么行不通了
4楼2011-08-24 12:53:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

★ ★
余泽成(金币+1): 谢谢参与应助! 2011-08-24 16:27:27
dubo(金币+1): 欢迎讨论 2011-08-27 16:41:43
ben_ladeng: 专家考核存档 2011-09-28 11:40:16
引用回帖:
4楼: Originally posted by li_clifff at 2011-08-24 12:53:08:
但是我真看到有的f77程序主程序不用allocatable,直接调用子程序生成的numnp, numel就可以,就是按我那样开始写的,不知道自己按那样的方式怎么行不通了

在主程序中不行,在子程序中有可能可行,但不是你这种写法……

也就是说,如果声明变量时,numnp, numel 有值就行,否则不行……
5楼2011-08-24 14:53:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

li_clifff

银虫 (正式写手)

引用回帖:
2楼: Originally posted by snoopyzhao at 2011-08-24 11:13:08:
你主程中的 numnp 和 numel 必须赋值,否则必须使用动态数组,那么你的 x, ia, ien, mat, in 等数组就需要用 allocatable 之类的关键词重新声明,然后在调用子程序 sizemesh 之后,用 allocated 来分配内存。

如果在引用call meshsize之前对numnp赋值,或者打开一个文件,读取参数,对numnp赋值,那么是不是就没有问题了呢
6楼2011-09-28 11:02:42
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

问题是,如果 numnp 没有值,主程序中相关的变量就不能成功声明,所以还是不行……
7楼2011-09-28 11:23:24
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

li_clifff

银虫 (正式写手)

引用回帖:
7楼: Originally posted by snoopyzhao at 2011-09-28 11:23:24:
问题是,如果 numnp 没有值,主程序中相关的变量就不能成功声明,所以还是不行……

恩,明白,那只有include 一个参数文件,如 Include 'Parameters.inc',
把numnp这样的参数 赋值在里面应该可以吧?
8楼2011-09-28 11:40:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

li_clifff

银虫 (正式写手)

我发现早期f77程序,对数组没有动态赋值,都是先定义一个大的数组比如
x(nnpmax),nnpmax在parameter.inc文件里,而实际上子程序里的大小nnp是变化的,但只要不超过nnpmax就行,这样的方式也不错。
9楼2011-09-28 11:46:33
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

引用回帖:
8楼: Originally posted by li_clifff at 2011-09-28 11:40:48:
恩,明白,那只有include 一个参数文件,如 Include 'Parameters.inc',
把numnp这样的参数 赋值在里面应该可以吧?

是这样的,呵呵……
10楼2011-09-28 12:34:22
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 li_clifff 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 博后基金刷到的BUG,图片来的更直观 +9 carolloo 2024-06-17 10/500 2024-06-17 20:44 by sunyuwei1994
[考博] 这个博士要读吗 +9 Sea Breeze 2024-06-16 17/850 2024-06-17 19:50 by zeolitess
[基金申请] 有人中过人文社科类的博后特助吗? +3 outsider1986 2024-06-16 4/200 2024-06-17 19:35 by outsider1986
[论文投稿] 审稿问题:为什么荧光激发波长和紫外吸收波长差的大? 10+5 sdawege 2024-06-14 10/500 2024-06-17 18:54 by HH-探针
[考博] 2025考博 +7 自强不息a?a 2024-06-15 11/550 2024-06-17 18:13 by 小木雄子
[基金申请] 博后面上今天有bug可以看到是否资助? +22 lyfbangong 2024-06-12 33/1650 2024-06-17 16:17 by carolloo
[有机交流] 苯酚和炔醇反应,mitsunobu反应 5+3 TONGMEIMEI 2024-06-12 9/450 2024-06-17 15:00 by dschong
[文学芳草园] 累并快乐着 +14 MYHLD521 2024-06-14 14/700 2024-06-17 14:51 by shl2112501
[教师之家] 请问事业编制和年薪制冲突吗? +10 ZHONGWU_U 2024-06-14 10/500 2024-06-17 14:44 by 周周520
[催化] 镍负载氧化铝的保存问题 8+3 lwn0130 2024-06-15 4/200 2024-06-17 10:48 by adaihao
[硕博家园] 博士毕业高校和就业的相关问题 +6 SCITOPPP 2024-06-14 10/500 2024-06-17 10:08 by SCITOPPP
[论文投稿] 投稿被一个审稿人恶意评审了怎么样? +5 1chen 2024-06-14 7/350 2024-06-15 23:15 by xy66xy
[基金申请] 关于博后基金的bug问题 +6 lxr1991 2024-06-14 9/450 2024-06-15 21:17 by since—2010
[考博] 上海交大招收材料化学方向科研助理/“申请考核”博士(已招满) +3 灵梦and紫 2024-06-12 4/200 2024-06-15 20:58 by 1822836277
[食品] 食品博士导师 +6 小李醒yy 2024-06-11 9/450 2024-06-14 23:37 by 小李醒yy
[基金申请] 工材E10口函评结束了吗 10+3 我1的飞翔 2024-06-13 5/250 2024-06-14 06:35 by nono2009
[硕博家园] 机械研究生如何拿到年薪40+w +13 阿巴阿巴哦哦 2024-06-11 15/750 2024-06-13 15:40 by 113745685
[考博] 博导选择 +3 bing85977 2024-06-12 3/150 2024-06-13 15:34 by 我是邱尧
[硕博家园] 考博应该从哪里开始准备 +6 亮姐2019 2024-06-11 8/400 2024-06-13 12:53 by 帕秋莉GO
[论文投稿] 摩擦磨损论文投稿 +3 jmysan 2024-06-12 3/150 2024-06-13 08:36 by 莱茵润色
信息提示
请填处理意见