	module polynomes

contains
! fonction polynomiale p(x,y)
! coefficient de X^n Y^m == coef(n+1,m+1)

	real(kind(0d0)) function val_pol (coef, X, Y)

	implicit none

	integer m,n,i,j
	real(kind(0d0)) coef(:,:),x,y,p

	n=size(coef,1) ; m=size(coef,2)
! n+1 puissance max en x
! m+1 puissance max en y
	
	do j=m,1,-1
	  p=coef(n,j)
	  do i=n-1,1,-1
	   p=p*x+ coef(i,j)
	  enddo
	  if (j == m) then
            val_pol=p
	  else
           val_pol=val_pol*y+p
	  endif
	enddo

	end function

	real(kind(0d0)) function dx_pol (coef, X, Y)

	implicit none

	integer m,n,i,j
	real(kind(0d0)) coef(:,:),x,y,p,dp

	n=size(coef,1) ; m=size(coef,2)
! n+1 puissance max en x
! m+1 puissance max en y
	
	do j=m,1,-1
	  p=coef(n,j)
	  dp=0d0
	  do i=n-1,1,-1
	   dp=dp*x+p
	   p=p*x+ coef(i,j)
	  enddo
	  if (j == m) then
            dx_pol=dp
	  else
           dx_pol=dx_pol*y+dp
	  endif
	enddo

	end function

	real(kind(0d0)) function dy_pol (coef, X, Y)

	implicit none

	integer m,n,i,j
	real(kind(0d0)) coef(:,:),x,y,p,pol

	n=size(coef,1) ; m=size(coef,2)
! n+1 puissance max en x
! m+1 puissance max en y
	
	do j=m,1,-1
	  p=coef(n,j)
	  do i=n-1,1,-1
	   p=p*x+ coef(i,j)
	  enddo
	  if (j == m) then
            dy_pol=0d0
	    pol=p
	  else
           dy_pol=dy_pol*y+pol
           pol=pol*y+p
	  endif
	enddo

	end function

	subroutine deriv_pol(coef,coefx,coefy)

	real(kind(0d0)) coef(:,:)
	real(kind(0d0)), pointer :: coefx(:,:), coefy(:,:)
	integer i,j,nx,ny

	nx=size(coef,1); ny=size(coef,2)
	allocate(coefx(nx-1,ny),coefy(nx,ny-1))

	do j=1,ny
	 do i=1,nx-1
	  coefx(i,j)=i*coef(i+1,j)
	 enddo
	enddo
	
	do j=1,ny-1
	 do i=1,nx
  	  coefy(i,j)=j*coef(i,j+1)
	 enddo
	enddo
	
	end subroutine

	real(kind(0d0)) function jacob(coefx,coefy,x,y)

	real(kind(0d0)) coefx(:,:),coefy(:,:),x,y,p_xx,p_yy,p_xy

	p_xx=dx_pol(coefx,x,y)
	p_yy=dy_pol(coefy,x,y)
	p_xy=dx_pol(coefy,x,y)

	jacob=p_xx*p_yy-(p_xy)**2
	end function

	end module
