!
! $Id: gr_fi_dyn_p.F 1279 2009-12-10 09:02:56Z fairhead $
!
      SUBROUTINE gr_fi_dyn_p(nfield,ngrid,im,jm,pfi,pdyn)
#ifdef CPP_EARTH
! Interface with parallel physics,
! for now this routine only works with Earth physics
      USE mod_interface_dyn_phys
      USE dimphy
      use parallel
      IMPLICIT NONE
c=======================================================================
c   passage d'un champ de la grille scalaire a la grille physique
c=======================================================================

c-----------------------------------------------------------------------
c   declarations:
c   -------------

      INTEGER im,jm,ngrid,nfield
      REAL pdyn(im,jm,nfield)
      REAL pfi(ngrid,nfield)

      INTEGER i,j,ifield,ig

c-----------------------------------------------------------------------
c   calcul:
c   -------
c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
      DO ifield=1,nfield

        do ig=1,klon
          i=index_i(ig)
          j=index_j(ig)
          pdyn(i,j,ifield)=pfi(ig,ifield)
          if (i==1) pdyn(im,j,ifield)=pdyn(i,j,ifield)
	enddo

c   traitement des poles
      if (pole_nord) then
        do i=1,im
	  pdyn(i,1,ifield)=pdyn(1,1,ifield)
	enddo
      endif
       
      if (pole_sud) then
        do i=1,im
	  pdyn(i,jm,ifield)=pdyn(1,jm,ifield)
	enddo
      endif
      
      ENDDO
c$OMP END DO NOWAIT
#else
      write(lunout,*) "gr_fi_dyn_p : This routine should not be called",
     &   "without parallelized physics"
      stop
#endif
! of #ifdef CPP_EARTH
      RETURN
      END
