Index: NEMO/branches/2020/r12377_ticket2386/tests/VORTEX/MY_SRC/usrdef_hgr.F90
===================================================================
--- NEMO/branches/2020/r12377_ticket2386/tests/VORTEX/MY_SRC/usrdef_hgr.F90	(revision 12451)
+++ NEMO/branches/2020/r12377_ticket2386/tests/VORTEX/MY_SRC/usrdef_hgr.F90	(revision 13540)
@@ -26,4 +26,6 @@
    PUBLIC   usr_def_hgr   ! called by domhgr.F90
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
@@ -61,7 +63,7 @@
       REAL(wp), DIMENSION(:,:), INTENT(out) ::   pe1e2u, pe1e2v               ! u- & v-surfaces (if reduction in strait)   [m2]
       !
-      INTEGER  ::   ji, jj   ! dummy loop indices
+      INTEGER  ::   ji, jj     ! dummy loop indices
       REAL(wp) ::   zphi0, zlam0, zbeta, zf0
-      REAL(wp) ::   zti, zui, ztj, zvj   ! local scalars
+      REAL(wp) ::   zti, ztj   ! local scalars
       !!-------------------------------------------------------------------------------
       !
@@ -75,33 +77,39 @@
       ! Position coordinates (in kilometers)
       !                          ==========
-      zlam0 = -(jpiglo-1)/2 * 1.e-3 * rn_dx
-      zphi0 = -(jpjglo-1)/2 * 1.e-3 * rn_dy 
-
+#if defined key_agrif 
+      IF( Agrif_Root() ) THEN
+#endif
+         ! Compatibility WITH old version: 
+         ! jperio = 0 =>  Ni0glo = jpigo_old_version
+         !            =>  jpiglo-1 replaced by Ni0glo-1
+         zlam0 = -REAL( (Ni0glo-1)/2, wp) * 1.e-3 * rn_dx
+         zphi0 = -REAL( (Nj0glo-1)/2, wp) * 1.e-3 * rn_dy 
 #if defined key_agrif
-      ! ! let lower left longitude and latitude from parent
-      IF (.NOT.Agrif_root()) THEN
-          zlam0 = (0.5_wp-(Agrif_parent(jpiglo)-1)/2)*1.e-3*Agrif_irhox()*rn_dx &
-             &+(Agrif_Ix()+nbghostcells-1)*Agrif_irhox()*rn_dx*1.e-3-(0.5_wp+nbghostcells)*rn_dx*1.e-3
-          zphi0 = (0.5_wp-(Agrif_parent(jpjglo)-1)/2)*1.e-3*Agrif_irhoy()*rn_dy &
-             &+(Agrif_Iy()+nbghostcells-1)*Agrif_irhoy()*rn_dy*1.e-3-(0.5_wp+nbghostcells)*rn_dy*1.e-3
+      ELSE
+         ! ! let lower left longitude and latitude from parent
+         ! Compatibility WITH old version: 
+         ! jperio = 0 =>  Ni0glo = jpigo_old_version
+         !            =>  Agrif_parent(jpiglo)-1 replaced by  Agrif_parent(Ni0glo)-1
+         zlam0 = ( 0.5_wp - REAL( ( Agrif_parent(Ni0glo)-1 ) / 2, wp) ) * 1.e-3 * Agrif_irhox() * rn_dx  &
+            &  + ( Agrif_Ix() + nbghostcells - 1 ) * Agrif_irhox() * rn_dx * 1.e-3 - ( 0.5_wp + nbghostcells ) * rn_dx * 1.e-3
+         zphi0 = ( 0.5_wp - REAL( ( Agrif_parent(Nj0glo)-1 ) / 2, wp) ) * 1.e-3 * Agrif_irhoy() * rn_dy  &
+            &  + ( Agrif_Iy() + nbghostcells - 1 ) * Agrif_irhoy() * rn_dy * 1.e-3 - ( 0.5_wp + nbghostcells ) * rn_dy * 1.e-3
       ENDIF 
 #endif
          
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zti = FLOAT( ji - 1 + nimpp - 1 )          ;  ztj = FLOAT( jj - 1 + njmpp - 1 )
-            zui = FLOAT( ji - 1 + nimpp - 1 ) + 0.5_wp ;  zvj = FLOAT( jj - 1 + njmpp - 1 ) + 0.5_wp
-
-            plamt(ji,jj) = zlam0 + rn_dx * 1.e-3 * zti
-            plamu(ji,jj) = zlam0 + rn_dx * 1.e-3 * zui
-            plamv(ji,jj) = plamt(ji,jj) 
-            plamf(ji,jj) = plamu(ji,jj) 
-   
-            pphit(ji,jj) = zphi0 + rn_dy * 1.e-3 * ztj
-            pphiv(ji,jj) = zphi0 + rn_dy * 1.e-3 * zvj
-            pphiu(ji,jj) = pphit(ji,jj) 
-            pphif(ji,jj) = pphiv(ji,jj) 
-         END DO
-      END DO
+      DO_2D( 1, 1, 1, 1 )
+         zti = REAL( mig0_oldcmp(ji) - 1, wp )   ! start at i=0 in the global grid without halos
+         ztj = REAL( mjg0_oldcmp(jj) - 1, wp )   ! start at j=0 in the global grid without halos
+         
+         plamt(ji,jj) = zlam0 + rn_dx * 1.e-3 *   zti
+         plamu(ji,jj) = zlam0 + rn_dx * 1.e-3 * ( zti + 0.5_wp )
+         plamv(ji,jj) = plamt(ji,jj) 
+         plamf(ji,jj) = plamu(ji,jj) 
+         
+         pphit(ji,jj) = zphi0 + rn_dy * 1.e-3 *   ztj
+         pphiv(ji,jj) = zphi0 + rn_dy * 1.e-3 * ( ztj + 0.5_wp )
+         pphiu(ji,jj) = pphit(ji,jj) 
+         pphif(ji,jj) = pphiv(ji,jj) 
+      END_2D
       !     
       ! Horizontal scale factors (in meters)
