Fortran Coder

查看: 8262|回复: 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] 纯文本查看 复制代码
001subroutinernde(ua,n)
002 c           random number generator proposed bymarsaglia and zaman
003 c           in reportfsu-scri-87-50
004 c           modified by f. james, 1988and 1989, to generate a vector
005 c           of pseudorandom numbers ua oflength n.
006 c           modified by k.k
007 c    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
008 c     calling sequences for rnde:                                    ++
009 c         call rnde(ua, n)         returns a vector ua of n          ++
010 c                      32-bit randomfloating point numbers between  ++
011 c                      zero and one.                                 ++
012 c         call rnd3i(i1)          initializes the generator from one++
013 c                      32-bit integeri1
014 c   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
015       implicit none
016       integer n
017       real*8 ua(n), sina(102)
018       logical first
019       save  first
020       integer ijkl, ijklin
021       data first/.true./
022 c
023       if(first) then
024          first=.false.
025 c           default initialization. userhas called rnde without rnd3i.
026          ijkl = 54217137
027 
028 
029 
030 
031c     %%%%%%%%%%%%%%%%%%%%%%%
032          call rnd3ix(ijkl)
033 
034c    %%%%%%%%%%%%%%%%%%%%%%%%%%%
035 
036 
037 
038 
039      endif
040 
041 
042 
043c     %%%%%%%%%%%%%%%%%%%%%%%%%
044 
045      call rnd3x(ua, n)  
046 
047c     %%%%%%%%%%%%%%%%%%%%%%%%%%%
048 
049 
050 
051 
052      return
053 c         initializing routine for rnde,may be called before
054 c         generating pseudorandom numberswith rnde. the input
055 c         values should be in theranges:  0<=ijklin<=900 oooooo
056 c     **************
057       entry rnd3i(ijklin)
058 c     *************
059       first=.false.
060       call rnd3ix(ijklin)
061       return
062 c     ************
063       entry rnd3r(sina)
064 c     ************
065          first=.false.
066          call rnd3rx(sina)
067       end
068       subroutine  rnd3ix(ijkl)
069 c             the standard values inmarsaglia's paper, ijkl=54217137
070           implicit none
071           integer n
072           real*8 ua(n), u(97), uni, s, t,zuni
073           real*8 sina(102),sout(102)
074           integer  jj, m
075           integer ns, ijkl, i97, j97, ij,kl, i, j, k, l, ii, ivec
076           real*8 twom24, c, cd, cm
077           parameter (ns=24,twom24=2.**(-24))
078           save c, cd, cm, i97, j97
079 c
080           ij = ijkl/30082
081           kl = ijkl - 30082*ij
082           i = mod(ij/177, 177) + 2
083           j = mod(ij, 177) + 2
084           k = mod(kl/169, 178) + 1
085           l = mod(kl, 169)
086            do   ii= 1, 97
087               s = 0.
088               t = .5
089                do   jj= 1, ns
090                   m = mod(mod(i*j,179)*k,179)
091                   i = j
092                   j = k
093                   k = m
094                   l = mod(53*l+1,169)
095                   if(mod(l*m,64) .ge. 32)s = s+t
096                   t = 0.5*t
097                enddo
098               u(ii) = s
099            enddo
100           c = 362436.*twom24
101           cd = 7654321.*twom24
102           cm = 16777213.*twom24
103           i97 = 97
104           j97 = 33
105           return
106 c     ****************
107       entry rnd3x(ua, n)
108 c     ****************
109        do   ivec= 1, n
110           uni = u(i97)-u(j97)
111           if(uni .lt. 0.)uni=uni+1.
112           u(i97) = uni
113           i97 = i97-1
114           if(i97 .eq. 0) i97=97
115           j97 = j97-1
116           if(j97 .eq. 0) j97=97
117           c = c - cd
118           if(c .lt. 0.) c=c+cm
119           uni = uni-c
120           if(uni .lt. 0.)uni=uni+1.
121           ua(ivec) = uni
122 c                 replace exact zeros byuniform distr. *2**-24
123           if(uni .eq. 0.) then
124               zuni = twom24*u(2)
125 c               an exact zero here isvery unlikely, but let's be safe.
126               if(zuni .eq. 0.) zuni=twom24*twom24
127               ua(ivec) = zuni
128           endif
129        enddo
130       return
131 c     ****************** to get currentstatus
132       entry rnd3s(sout)
133 c     ***********
134            do   i=1, 97
135               sout(i)=u(i)
136            enddo
137           sout(98)=c
138           sout(99)=cd
139           sout(100)=cm
140           sout(101)=i97
141           sout(102)=j97
142           return
143 c     ****************  to restore the old status
144       entry rnd3rx(sina)
145            do   i=1, 97
146                u(i)=sina(i)
147            enddo
148           c=sina(98)
149           cd=sina(99)
150           cm=sina(100)
151           i97=sina(101)
152           j97=sina(102)
153       end



math-rnd.f

17.24 KB, 下载次数: 3

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

838

帖子

2

主题

0

精华

大宗师

F 币
3937 元
贡献
2339 点
沙发
发表于 2017-3-13 14:46:18 | 只看该作者
我这里并不报错。ivf2015+vs2010

955

帖子

0

主题

0

精华

大师

F 币
188 元
贡献
77 点

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

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)

3

帖子

1

主题

0

精华

新人

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

谢谢,回复的有点晚!

3

帖子

1

主题

0

精华

新人

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

对,在某些编译器没有报错,但是确实是有错误的...楼下给了回复,感谢你的帮助
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2025-5-1 02:05

Powered by Discuz! X3.4

© 2013-2025 Comsenz Inc.

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