24小时热门版块排行榜    

Znn3bq.jpeg
查看: 2599  |  回复: 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的回帖

li_clifff

银虫 (正式写手)

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

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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 310求调剂 +13 666真好 2026-04-11 14/700 2026-04-12 16:48 by 1005715100
[考研] 291求调剂 +11 关忆北. 2026-04-09 12/600 2026-04-12 10:32 by 逆水乘风
[考研] 305求调剂 +6 77Qi 2026-04-07 6/300 2026-04-12 02:30 by 秋豆菜芽
[考研] 药学专硕调剂 +8 ? 一路生?花? 2026-04-10 10/500 2026-04-11 21:21 by zhouxiaoyu
[考研] 还有化工二轮调剂的学校吗 5+14 化工人999 2026-04-09 48/2400 2026-04-11 10:27 by 89436494
[考研] 080100力学316求调剂 +8 L_Hairui 2026-04-07 8/400 2026-04-11 10:00 by zhq0425
[考研] 265求调剂 +12 风说她早忘了 2026-04-10 13/650 2026-04-10 18:56 by chemisry
[考研] 344求调剂 +7 丶风雪夜归人丶 2026-04-09 7/350 2026-04-10 12:05 by pengliang8036
[考研] 求调剂 +11 翩翩一书生 2026-04-09 13/650 2026-04-10 10:27 by liuhuiying09
[考研] 考研二轮调剂 +8 故人?? 2026-04-09 8/400 2026-04-10 09:44 by 青梅duoduo
[考研] 0703化学求调剂 +21 不知名的小卅 2026-04-08 21/1050 2026-04-09 18:55 by l_paradox
[考研] 086000生物与医药调剂 +7 awwwwwooooo 2026-04-09 7/350 2026-04-09 13:31 by 北极159263
[考研] 生物学学硕,初试351分,求调剂 +4 …~、王…~ 2026-04-08 5/250 2026-04-08 21:49 by limeifeng
[考研] 0703化学调剂 348分 +14 唉我超真没招了 2026-04-06 15/750 2026-04-08 19:16 by 我减肥1
[考研] 一志愿华东理工085601材料工程303分求调剂 +15 a1708 2026-04-06 15/750 2026-04-08 16:23 by luoyongfeng
[考研] 材料工程专业日语生求调剂 +9 111623 2026-04-07 9/450 2026-04-07 23:31 by 一只好果子?
[考研] 085100建筑学 寻求跨专业调剂 一志愿南大294分 校级省级国家级奖项若干 踏实肯干 +3 1021075758 2026-04-06 4/200 2026-04-07 09:23 by 蓝云思雨
[考研] 081200-11408-367学硕求调剂 +4 1_2_3111 2026-04-06 4/200 2026-04-07 08:13 by jp9609
[考研] 求助 +3 卡卡东88 2026-04-06 4/200 2026-04-06 15:28 by going home
[考研] 362求调剂一志愿中国石油大学 +4 我要考大 2026-04-06 6/300 2026-04-06 14:11 by 无际的草原
信息提示
请填处理意见