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

`` program picimplicit noneinteger c,ainteger b(5)external fmedianc=5b=(/9,2,7,1,6/)fmedian(a,b,c)endreal function fmedian(xmed,x,n)double precision suminteger i,n,xmeddimension x(n)sum=0.d0do 10 i=1,nsum=sum+(x(i)-xmed)/abs(x(i)-xmed)10 continuefmedian=sumreturnend``

What should I change in my pic code

When I try to compile Alexander`s code I got

`` print *, fmedian(a,b,c)1Warning: 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
``````

Top