当前位置: 动力学知识库 > 问答 > 编程问答 >

fortran - Error: ‘fmedian’ at (1) is not a variable

问题描述:

I want to see how this function works.I have tried to write small f77 code

 program pic

implicit none

integer c,a

integer b(5)

external fmedian

c=5

b=(/9,2,7,1,6/)

fmedian(a,b,c)

end

real function fmedian(xmed,x,n)

double precision sum

integer i,n,xmed

dimension x(n)

sum=0.d0

do 10 i=1,n

sum=sum+(x(i)-xmed)/abs(x(i)-xmed)

10 continue

fmedian=sum

return

end

What should I change in my pic code

When I try to compile Alexander`s code I got

 print *, fmedian(a,b,c)

1

Warning: Type mismatch in argument ‘x’ at (1); passed INTEGER(4) to REAL(4)

网友答案:

fmedian is a function, i.e. it returns something. However, you do not assign the return value anywhere.

You could, e.g., print the result of fmedian to the screen:

      print *, fmedian(a,b,c)

Additionally, you need to declare the return value of fmedian

      real fmedian

Your program would then look like:

      program pic

      implicit none
      integer c,a
      integer b(5)
      real fmedian
      external fmedian
      c=5
      b=(/9,2,7,1,6/)  
      print *, fmedian(a,b,c)

      end


      real function fmedian(xmed,x,n)
      double precision sum
      integer i,n,xmed
      dimension x(n)
      sum=0.d0
      do 10 i=1,n
        sum=sum+(x(i)-xmed)/abs(x(i)-xmed)
  10    continue
      fmedian=sum
      return
      end
分享给朋友:
您可能感兴趣的文章:
随机阅读: