C file: fortranmath.f

C subroutine myreverse (array in reversed order):

	SUBROUTINE myreverse(list,n,listout)
	integer n, temp
	real*8 list(0:n),listout(0:n)
Cf2py   intent(in) list
Cf2py   intent(out) listout
	temp = n
        do i = 0,n
	   listout(temp) = list(i)
	   temp = temp - 1
        end do
        end

C subroutine mysort_inc (sorts array in increasing order):

	SUBROUTINE mysort_inc(list,n)
	integer n
	real*8 list(0:n),temp
Cf2py   intent(in, out) list
	do i = 0,n-1	
	   do j = i+1,n
	      if(list(j).lt.list(i)) then
		      temp = list(i)
		      list(i) = list(j)
		      list(j) = temp
	      end if
	   end do
        end do
        end



C subroutine mysort_dec (sorts array in decreasing order):

	SUBROUTINE mysort_dec(list,n)
	integer n
	real*8 list(0:n),temp
Cf2py   intent(in, out) list
	do i = 0,n-1	
	   do j = i+1,n
	      if(list(j).gt.list(i)) then
		      temp = list(i)
		      list(i) = list(j)
		      list(j) = temp
	      end if
	   end do
        end do
        end


C subroutine mysum (return sum of elements in array):

	SUBROUTINE mysum(list,n,sum)
	integer n
	real*8 list(0:n), sum
	sum = 0.0
Cf2py   intent(in) list
Cf2py   intent(out) sum
	do i = 0, n
           sum = sum + list(i)
	end do 
	return
	end



C subroutine myaverage (return average of elements in array):

	SUBROUTINE myaverage(list,n,average)
	integer n
	real*8 list(0:n),sum,average
	sum = 0.0
Cf2py   intent(in) list
Cf2py   intent(out) average
	do i = 0, n
           sum = sum + list(i)
	end do 
	average = sum/(n+1)
	return
	end



C subroutine mymax (return largest element in array):

	SUBROUTINE mymax(list,n,max) 
	integer n
	real*8 list(0:n),max
Cf2py   intent(in) list
Cf2py   intent(out) max
	max = list(0)
	if(n.gt.1)then
		do i = 1, n 
			if(list(i).gt.max)then	
				max = list(i)
			end if
		end do 
	end if
	end 



C subroutine mymin (return smalles element in array):

	SUBROUTINE mymin(list,n,min) 
	integer n
	real*8 list(0:n),min
Cf2py   intent(in) list
Cf2py   intent(out) min
	min = list(0)
	if(n.gt.1)then
		do i = 1, n
			if(list(i).lt.min)then	
				min = list(i)
			end if
		end do 
	end if
	end 

