崩溃了...不太会使用sum和random函数,所以总是报错
subroutine read_obstacles(obst)implicit none
include "head.inc"
EXTERNAL sum
complex h(51,51),h1(51,51),F(51,51),F1(51,51),
&obst(51,51)
integer k,l,P,Q
integer x,y
do 11 k= 1, 51
do 10 l = 1, 51
F(P,Q)=0.675*0.675*(exp(-2.3*((k/50)*(k/50)+(l/10)*
& (l/10))**0.5))*((-1)**(2*k*P/50+2*l*Q/50))
if (k==(1,51).and.l==(1,51))then
F1(P,Q)=sum(F,1,)
end if
10 continue
11 continue
do 20 P=1,51
do 21 Q=1, 51
h(k,l)=1/10000*F1(P,Q)*(-1)**((k*P+l*Q)/26)
if (P==(1,51).and.Q==(1,51))then
h1(k,l)=sum(h,1,)
end if
21 continue
20 continue
do 22 k= 1, 51
do 23 l = 1, 51
call RANDOM_SEED()
call RANDOM_NUMBER()
obst(lx,ly)=h1(k,l)*random_number(lx,ly)
if (lx==(1,51).and.ly==(1,51))then
obst(x,y)=sum(obst,1,)
end if
23 continue
22 continue
end
错误 1 error #6404: This name does not have a type, and must have an explicit type. E:\sia\2018.8月\coding\chap2\chap2\main.for 178
警告 2 warning #7532: The number of arguments is incompatible with intrinsic procedure, assume 'external'. E:\sia\2018.8月\coding\chap2\chap2\main.for 197
错误 3 error #6404: This name does not have a type, and must have an explicit type. E:\sia\2018.8月\coding\chap2\chap2\main.for 200
错误 4 error #5508: Declaration of routine 'READ_PARAMETERS' conflicts with a previous declaration E:\sia\2018.8月\coding\chap2\chap2\main.for 124
啊真是被这个程序心态搞崩了 EXTERNAL sum
这句去掉
call RANDOM_SEED()
这句放到主程序的第一个执行语句的前面,之后不再调用。
random_number这样用
call random_number(lx)
call random_number(ly)
详解 http://random.w.fcode.cn
至于sum怎么用,我不明白你的意图
sum(h,1,)
你是不是想这样写?
y = sum(h(:,1:21))
fcode 发表于 2018-8-28 07:38
EXTERNAL sum
这句去掉
sum就是想把从1到51的所有情况的值相加....我也搞乱了...查了好多地方也没搞明白这个sum到底应该怎么用。是只能用在数组中吗? 对,只能用于数组。
如果第一个参数是二维数组,你可以指定在第几维上进行累加。
如果在第一维,那么结果就是第二维大小那么大的一维数组。
如果在第二维,那么结果就是第一维大小那么大的一维数组。
如果不指定,那么就是全部累加,结果是一个单变量。
complex h(51,51) , s(21) , s2(51) , s3
s = sum( h(:,1:21) , 1 )
s2= sum( h(:,1:21) , 2 )
s3= sum( h(:,1:21) )
fcode 发表于 2018-8-28 11:02
对,只能用于数组。
如果第一个参数是二维数组,你可以指定在第几维上进行累加。
如果在第一维,那么结果就 ...
系统提示说random_number的数据类型参数是无效的...可是我已经call过了诶... 给出代码,错误提示 fcode 发表于 2018-8-28 14:57
给出代码,错误提示
现在已经没错误了,就是调试又断点,可能是逻辑上的错误。谢谢您前辈!这几天给了我很多指导!麻烦您了!嘻嘻:-loveliness:
页:
[1]