I am trying to write a program in Fortran (using Plato) to calculate the median of an array without sorting them. However, I receive this error and it seems that the program doesn't enter the function at all. Can anyone please let me know what is wrong about my program? My program is this:
!=================program median========================
program MedianVal
real,dimension(:),allocatable::arr
real::median
integer::n
print*,'please enter the number of the arrays'
read*,i
allocate(arr(i))
print*,'please enter your array:'
read*,arr
!med=median(n,arr)
!print*,'The median is:'
!print*,median(n,arr)
write(6,*)'The median is:',median(n,arr)
end program
!=================Function Median=======================
real function median(n,arr)
real,dimension(:),allocatable::arr
integer::n
!allocate(arr(i))
print*,'entered function'
n=size(arr,1)
print*,n
median=0
if(mod(n,2)==0)then
median=(arr((n-1)/2)+arr(n/2))/2
else
median=arr(n/2)
end if
end function median
Here is the error log :
Attempt to call a routine with an incorrect or missing INTERFACE related to argument number two, which needs to be declared as assumed-shape in both the caller and callee at address 1c008629
Within file Exercise2.exe in MEDIAN at address fc in MEDIANVAL in line 14, at address 371