Fortran Coder

查看: 7813|回复: 4
打印 上一主题 下一主题

[子程序] fortran程序报错讨论

[复制链接]

3

帖子

1

主题

0

精华

新人

F 币
23 元
贡献
9 点
跳转到指定楼层
楼主
发表于 2017-3-13 14:06:15 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
这是大程序中的一个小code,学长说在老版本的gfortran中编译不会报错,但现在编译会报错,报错信息为
Error: Variable 'n', used in aspecification expression, is referenced at (1) before the ENTRY statement in which it is a parameter


错误集中在后面的code中(完整code见附件,以下错误的地方我用 c    %%%%%%% 中间,有两处):
[Fortran] 纯文本查看 复制代码
subroutinernde(ua,n)
 c           random number generator proposed bymarsaglia and zaman
 c           in reportfsu-scri-87-50
 c           modified by f. james, 1988and 1989, to generate a vector
 c           of pseudorandom numbers ua oflength n.
 c           modified by k.k
 c    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 c     calling sequences for rnde:                                    ++
 c         call rnde(ua, n)         returns a vector ua of n          ++
 c                      32-bit randomfloating point numbers between  ++
 c                      zero and one.                                 ++
 c         call rnd3i(i1)          initializes the generator from one++
 c                      32-bit integeri1
 c   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       implicit none
       integer n
       real*8 ua(n), sina(102)
       logical first
       save  first
       integer ijkl, ijklin
       data first/.true./
 c
       if(first) then
          first=.false.
 c           default initialization. userhas called rnde without rnd3i.
          ijkl = 54217137




c     %%%%%%%%%%%%%%%%%%%%%%%
          call rnd3ix(ijkl)

c    %%%%%%%%%%%%%%%%%%%%%%%%%%%




      endif



c     %%%%%%%%%%%%%%%%%%%%%%%%%

      call rnd3x(ua, n)   

c     %%%%%%%%%%%%%%%%%%%%%%%%%%%




      return
 c         initializing routine for rnde,may be called before
 c         generating pseudorandom numberswith rnde. the input
 c         values should be in theranges:  0<=ijklin<=900 oooooo
 c     **************
       entry rnd3i(ijklin)
 c     *************
       first=.false.
       call rnd3ix(ijklin)
       return
 c     ************
       entry rnd3r(sina)
 c     ************
          first=.false.
          call rnd3rx(sina)
       end
       subroutine  rnd3ix(ijkl)
 c             the standard values inmarsaglia's paper, ijkl=54217137
           implicit none
           integer n
           real*8 ua(n), u(97), uni, s, t,zuni
           real*8 sina(102),sout(102)
           integer  jj, m
           integer ns, ijkl, i97, j97, ij,kl, i, j, k, l, ii, ivec
           real*8 twom24, c, cd, cm
           parameter (ns=24,twom24=2.**(-24))
           save c, cd, cm, i97, j97
 c
           ij = ijkl/30082
           kl = ijkl - 30082*ij
           i = mod(ij/177, 177) + 2
           j = mod(ij, 177) + 2
           k = mod(kl/169, 178) + 1
           l = mod(kl, 169)
            do   ii= 1, 97
               s = 0.
               t = .5
                do   jj= 1, ns
                   m = mod(mod(i*j,179)*k,179)
                   i = j
                   j = k
                   k = m
                   l = mod(53*l+1,169)
                   if(mod(l*m,64) .ge. 32)s = s+t
                   t = 0.5*t
                enddo
               u(ii) = s
            enddo
           c = 362436.*twom24
           cd = 7654321.*twom24
           cm = 16777213.*twom24
           i97 = 97
           j97 = 33
           return
 c     ****************
       entry rnd3x(ua, n)
 c     ****************
        do   ivec= 1, n
           uni = u(i97)-u(j97)
           if(uni .lt. 0.)uni=uni+1.
           u(i97) = uni
           i97 = i97-1
           if(i97 .eq. 0) i97=97
           j97 = j97-1
           if(j97 .eq. 0) j97=97
           c = c - cd
           if(c .lt. 0.) c=c+cm
           uni = uni-c
           if(uni .lt. 0.)uni=uni+1.
           ua(ivec) = uni
 c                 replace exact zeros byuniform distr. *2**-24
           if(uni .eq. 0.) then
               zuni = twom24*u(2)
 c               an exact zero here isvery unlikely, but let's be safe.
               if(zuni .eq. 0.) zuni=twom24*twom24
               ua(ivec) = zuni
           endif
        enddo
       return
 c     ****************** to get currentstatus
       entry rnd3s(sout)
 c     ***********
            do   i=1, 97
               sout(i)=u(i)
            enddo
           sout(98)=c
           sout(99)=cd
           sout(100)=cm
           sout(101)=i97
           sout(102)=j97
           return
 c     ****************  to restore the old status
       entry rnd3rx(sina)
            do   i=1, 97
                u(i)=sina(i)
            enddo
           c=sina(98)
           cd=sina(99)
           cm=sina(100)
           i97=sina(101)
           j97=sina(102)
       end



math-rnd.f

17.24 KB, 下载次数: 3

分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

3

帖子

1

主题

0

精华

新人

F 币
23 元
贡献
9 点
5#
 楼主| 发表于 2017-3-17 23:09:12 | 只看该作者
li913 发表于 2017-3-13 14:46
我这里并不报错。ivf2015+vs2010

对,在某些编译器没有报错,但是确实是有错误的...楼下给了回复,感谢你的帮助

3

帖子

1

主题

0

精华

新人

F 币
23 元
贡献
9 点
地板
 楼主| 发表于 2017-3-17 23:08:39 | 只看该作者
vvt 发表于 2017-3-13 17:32
336行
call rnd3ix(ijkl)
改为

谢谢,回复的有点晚!

954

帖子

0

主题

0

精华

大师

F 币
184 元
贡献
75 点

规矩勋章元老勋章新人勋章水王勋章热心勋章

QQ
板凳
发表于 2017-3-13 17:32:30 | 只看该作者
336行
call rnd3ix(ijkl)
改为
call rnd3ix(ijkl,n)

347行
call rnd3ix(ijklin)
改为
call rnd3ix(ijklin,n)

355行
subroutine  rnd3ix(ijkl)
改为
subroutine  rnd3ix(ijkl,n)

835

帖子

2

主题

0

精华

大宗师

F 币
3926 元
贡献
2334 点
沙发
发表于 2017-3-13 14:46:18 | 只看该作者
我这里并不报错。ivf2015+vs2010
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-12-24 02:49

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表