Index: trunk/NEMO/OPA_SRC/IOM/iom_rstdimg.F90
===================================================================
--- trunk/NEMO/OPA_SRC/IOM/iom_rstdimg.F90	(revision 588)
+++ trunk/NEMO/OPA_SRC/IOM/iom_rstdimg.F90	(revision 611)
@@ -68,4 +68,5 @@
       INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables
       INTEGER                                 ::   ipni, ipnj, ipnij, iarea   ! domain decomposition 
+      INTEGER                                 ::   iiglo, ijglo               ! domain global size 
       INTEGER                                 ::   jl                         ! loop variable
       CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables
@@ -118,13 +119,15 @@
       ! =============
       IF( ldok ) THEN      ! old file
-         READ( idrst, REC = 1   , IOSTAT = ios, ERR = 987 )   &
-              &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd
-         READ( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )   &
+         READ( idrst, REC = 1   , IOSTAT = ios, ERR = 987 )              &
+              &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
+              &   ipni, ipnj, ipnij, iarea, iiglo, ijglo
+         READ( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )                       &
             &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   &
-            &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d),   &
-            &   ipni, ipnj, ipnij, iarea 
+            &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d)
          clinfo = TRIM(clinfo)//' file '//TRIM(cdname)
-         IF( inx   /= kdompar(1,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in domain size in i direction' )
-         IF( iny   /= kdompar(2,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in domain size in j direction' )
+         IF( iiglo /= jpiglo       )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in global domain size in i direction' )
+         IF( ijglo /= jpjglo       )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in global domain size in j direction' )
+         IF( inx   /= kdompar(1,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in local domain size in i direction' )
+         IF( iny   /= kdompar(2,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in local domain size in j direction' )
          IF( inz   /= jpk          )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in domain size in k direction' )
          IF( ipni  /= jpni         )   CALL ctl_stop( TRIM(clinfo), 'Processor splitting changed along I' )
@@ -266,7 +269,7 @@
          IF( in3d == 0 ) THEN   ;   in3d = 1   ;   clna3d(1) = 'no3d'   ;   zval3d(1) = -1.   ;   ENDIF
          ! update the file header before closing it
-         WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 )   &
+         WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 )              &
             &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
-            &   jpni, jpnj, jpnij, narea, jpiglo, jpjglo,   &
+            &   jpni, jpnj, jpnij, narea, jpiglo, jpjglo,              &
             &   nlcit, nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
          IF( (ivnum * (jpvnl + wp)) > irecl8 ) THEN 
@@ -274,5 +277,5 @@
                  &   'Last record size is too big... You could reduce the value of jpvnl' )
          ELSE 
-            WRITE( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )    &
+            WRITE( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )                        &
                  &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   &
                  &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d)
@@ -309,5 +312,5 @@
 
 
-   SUBROUTINE iom_rstdimg_rp0d( kiomid, cdvar, pv_r0d )
+   SUBROUTINE iom_rstdimg_rp0d( kiomid, cdvar, kvid, pv_r0d )
       !!--------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_rstdimg_rstput  ***
@@ -317,4 +320,5 @@
       INTEGER                   , INTENT(in) ::   kiomid   ! Identifier of the file 
       CHARACTER(len=*)          , INTENT(in) ::   cdvar    ! time axis name
+      INTEGER                   , INTENT(in) ::   kvid     ! variable id
       REAL(wp)                  , INTENT(in) ::   pv_r0d   ! written 0d field
       !
@@ -324,5 +328,9 @@
       !  
       clinfo = '                    iom_rstdimg_rp0d ~~~  '
-      idvar = iom_file(kiomid)%nvars + 1
+      IF( kvid <= 0 ) THEN   !   new variable
+         idvar = iom_file(kiomid)%nvars + 1
+      ELSE                   !   the variable already exists in the file
+         idvar = kvid
+      ENDIF
       IF( idvar <= jpmax_vars ) THEN
          iom_file(kiomid)%nvars = idvar
@@ -422,5 +430,5 @@
 
 
-   SUBROUTINE iom_rstdimg_rp123d( kiomid, cdvar, pv_r1d, pv_r2d, pv_r3d )
+   SUBROUTINE iom_rstdimg_rp123d( kiomid, cdvar, kvid, pv_r1d, pv_r2d, pv_r3d )
       !!--------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_rstdimg_rstput  ***
@@ -430,4 +438,5 @@
       INTEGER                         , INTENT(in)           ::   kiomid   ! Identifier of the file 
       CHARACTER(len=*)                , INTENT(in)           ::   cdvar    ! time axis name
+      INTEGER                         , INTENT(in)           ::   kvid     ! variable id
       REAL(wp), DIMENSION(        jpk), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field
       REAL(wp), DIMENSION(jpi,jpj    ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field
@@ -450,5 +459,9 @@
       irec = iom_file(kiomid)%irec    ! get back the record number of the variable
       idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
-      idvar = iom_file(kiomid)%nvars + 1
+      IF( kvid <= 0 ) THEN   !   new variable
+         idvar = iom_file(kiomid)%nvars + 1
+      ELSE                   !   the variable already exists in the file
+         idvar = kvid
+      ENDIF
       IF( idvar > jpmax_vars )   CALL ctl_stop( TRIM(clinfo), 'increase the value of jpmax_vars' )
       IF( .NOT. PRESENT(pv_r1d) ) THEN
