Index: /branches/dev_001_GM/NEMO/OFF_SRC/IOM/in_out_manager.F90
===================================================================
--- /branches/dev_001_GM/NEMO/OFF_SRC/IOM/in_out_manager.F90	(revision 950)
+++ /branches/dev_001_GM/NEMO/OFF_SRC/IOM/in_out_manager.F90	(revision 951)
@@ -33,4 +33,6 @@
    INTEGER            ::   nleapy     = 0         !: Leap year calendar flag (0/1 or 30)
    INTEGER            ::   ninist     = 0         !: initial state output flag (0/1)
+   LOGICAL            ::   ln_dimgnnn = .FALSE.   !: type of dimgout. (F): 1 file for all proc
+                                                  !:                  (T): 1 file per proc
    !!----------------------------------------------------------------------
    !! was in restart but moved here because of the OFF line... better solution should be found...
@@ -72,8 +74,8 @@
    !!                          Run control  
    !!----------------------------------------------------------------------
-   
+
    INTEGER            ::   nstop = 0                !: error flag (=number of reason for a premature stop run)
    INTEGER            ::   nwarn = 0                !: warning flag (=number of warning found during the run)
-   CHARACTER(LEN=100) ::   ctmp1, ctmp2, ctmp3      !: temporary character
+   CHARACTER(len=200) ::   ctmp1, ctmp2, ctmp3      !: temporary character
    CHARACTER (len=64) ::   cform_err = "(/,' ===>>> : E R R O R',     /,'         ===========',/)"       !:
    CHARACTER (len=64) ::   cform_war = "(/,' ===>>> : W A R N I N G', /,'         ===============',/)"   !:
@@ -82,5 +84,5 @@
    !!----------------------------------------------------------------------
    !!  OPA 9.0 , LOCEAN-IPSL (2005) 
-   !! $Header$ 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/in_out_manager.F90,v 1.11 2007/03/02 16:37:06 opalod Exp $ 
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -168,5 +170,5 @@
         getunit = -1
      ENDIF
-     
+
    END FUNCTION getunit
 
Index: /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom.F90
===================================================================
--- /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom.F90	(revision 950)
+++ /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom.F90	(revision 951)
@@ -6,4 +6,5 @@
    !! History :  9.0  ! 05 12  (J. Belier) Original code
    !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
+   !!             "   ! 07 07  (D. Storkey) Changes to iom_gettime
    !!--------------------------------------------------------------------
    !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
@@ -19,4 +20,5 @@
    USE in_out_manager  ! I/O manager
    USE dom_oce         ! ocean space and time domain
+   USE lbclnk          ! lateal boundary condition / mpp exchanges
    USE iom_def         ! iom variables definitions
    USE iom_ioipsl      ! NetCDF format with IOIPSL library
@@ -28,4 +30,7 @@
    
    PUBLIC iom_open, iom_close, iom_varid, iom_get, iom_gettime, iom_rstput
+
+   PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
+   PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_get_123d
 
    INTERFACE iom_get
@@ -38,5 +43,5 @@
    !!----------------------------------------------------------------------
    !!  OPA 9.0 , LOCEAN-IPSL (2006)
-   !! $Header$
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom.F90,v 1.10 2007/06/29 14:10:50 opalod Exp $
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -44,5 +49,5 @@
 CONTAINS
 
-   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib )
+   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop )
       !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_open  ***
@@ -55,4 +60,5 @@
       INTEGER         , INTENT(in   ), OPTIONAL ::   kdom     ! Type of domain to be written (default = jpdom_local_noovlap)
       INTEGER         , INTENT(in   ), OPTIONAL ::   kiolib   ! library used to open the file (default = jpnf90) 
+      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
 
       CHARACTER(LEN=100)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
@@ -62,5 +68,6 @@
       CHARACTER(LEN=100)    ::   clinfo    ! info character
       LOGICAL               ::   llok      ! check the existence 
-      LOGICAL               ::   llwrt     ! 
+      LOGICAL               ::   llwrt     ! local definition of ldwrt
+      LOGICAL               ::   llstop    ! local definition of ldstop
       INTEGER               ::   iolib     ! library do we use to open the file
       INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits)
@@ -89,4 +96,8 @@
       ELSE                        ;   llwrt = .FALSE.
       ENDIF
+      ! do we call ctl_stop if we try to open a non-existing file in read mode?
+      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
+      ELSE                         ;   llstop = .TRUE.
+      ENDIF
       ! what library do we use to open the file?
       IF( PRESENT(kiolib) ) THEN   ;   iolib = kiolib
@@ -110,6 +121,6 @@
       iln = LEN_TRIM(clname)
       ils = LEN_TRIM(clsuffix)
-      IF( iln <= ils) clname = clname(1:iln)//TRIM(clsuffix)
-      IF( clname(iln-ils+1:iln) /= TRIM(clsuffix) )   clname = clname(1:iln)//TRIM(clsuffix)
+      IF( iln <= ils .OR. INDEX( TRIM(clname), TRIM(clsuffix), back = .TRUE. ) /= iln - ils + 1 )   &
+         &   clname = TRIM(clname)//TRIM(clsuffix)
       cltmpn = clname   ! store this name
       ! try to find if the file to be opened already exist
@@ -118,7 +129,9 @@
       IF( .NOT.llok ) THEN
          ! we try to add the cpu number to the name
-         WRITE(clcpu,*) narea-1
+         IF( iolib == jprstdimg ) THEN   ;   WRITE(clcpu,*) narea
+         ELSE                            ;   WRITE(clcpu,*) narea-1
+         ENDIF
          clcpu  = TRIM(ADJUSTL(clcpu))
-         iln = INDEX(clname,TRIM(clsuffix))
+         iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.)
          clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
          icnt = 0
@@ -132,38 +145,53 @@
          END DO
       ENDIF
-      ! check the domain definition
-      idom = jpdom_local_noovlap   ! default definition
-      IF( PRESENT(kdom) )   idom = kdom
-      ! create the domain informations
-      ! =============
-      SELECT CASE (idom)
-      CASE (jpdom_local_full)
-         idompar(:,1) = (/ jpi             , jpj              /)
-         idompar(:,2) = (/ nimpp           , njmpp            /)
-         idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1  /)
-         idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
-         idompar(:,5) = (/ jpi - nlei      , jpj - nlej       /)
-      CASE (jpdom_local_noextra)
-         idompar(:,1) = (/ nlci            , nlcj             /)
-         idompar(:,2) = (/ nimpp           , njmpp            /)
-         idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /)
-         idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
-         idompar(:,5) = (/ nlci - nlei     , nlcj - nlej      /)
-      CASE (jpdom_local_noovlap)
-         idompar(:,1) = (/ nlei - nldi + 1 , nlej - nldj + 1  /)
-         idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /)
-         idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /)
-         idompar(:,4) = (/ 0               , 0                /)
-         idompar(:,5) = (/ 0               , 0                /)
-      CASE DEFAULT
-         CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' )
-      END SELECT
+      IF( llwrt ) THEN
+         ! check the domain definition
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!         idom = jpdom_local_noovlap   ! default definition
+         IF( jpni*jpnj == jpnij ) THEN   ;   idom = jpdom_local_noovlap   ! default definition
+         ELSE                            ;   idom = jpdom_local_full      ! default definition
+         ENDIF
+         IF( PRESENT(kdom) )   idom = kdom
+         ! create the domain informations
+         ! =============
+         SELECT CASE (idom)
+         CASE (jpdom_local_full)
+            idompar(:,1) = (/ jpi             , jpj              /)
+            idompar(:,2) = (/ nimpp           , njmpp            /)
+            idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1  /)
+            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
+            idompar(:,5) = (/ jpi - nlei      , jpj - nlej       /)
+         CASE (jpdom_local_noextra)
+            idompar(:,1) = (/ nlci            , nlcj             /)
+            idompar(:,2) = (/ nimpp           , njmpp            /)
+            idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /)
+            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
+            idompar(:,5) = (/ nlci - nlei     , nlcj - nlej      /)
+         CASE (jpdom_local_noovlap)
+            idompar(:,1) = (/ nlei  - nldi + 1, nlej  - nldj + 1 /)
+            idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /)
+            idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /)
+            idompar(:,4) = (/ 0               , 0                /)
+            idompar(:,5) = (/ 0               , 0                /)
+         CASE DEFAULT
+            CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' )
+         END SELECT
+      ENDIF
       ! Open the NetCDF or RSTDIMG file
       ! =============
       ! do we have some free file identifier?
       IF( MINVAL(iom_file(:)%nfid) /= 0 )   &
-            &   CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' )
+         &   CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' )
+      ! if no file was found...
+      IF( .NOT. llok ) THEN
+         IF( .NOT. llwrt ) THEN   ! we are in read mode 
+            IF( llstop ) THEN   ;   CALL ctl_stop( TRIM(clinfo), 'File '//TRIM(cltmpn)//'* not found' )
+            ELSE                ;   istop = nstop + 1   ! make sure that istop /= nstop so we don't open the file
+            ENDIF
+         ELSE                     ! we are in write mode so we 
+            clname = cltmpn       ! get back the file name without the cpu number
+         ENDIF
+      ENDIF
       IF( istop == nstop ) THEN   ! no error within this routine
-         IF( .NOT. llok )   clname = cltmpn   ! get back the file name without the cpu number
          SELECT CASE (iolib)
          CASE (jpioipsl )   ;   CALL iom_ioipsl_open(  clname, kiomid, llwrt, llok, idompar )
@@ -212,5 +240,5 @@
                END SELECT
                iom_file(jf)%nfid       = 0   ! free the id 
-               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(kiomid)%name)//' ok'
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok'
             ELSEIF( PRESENT(kiomid) ) THEN
                WRITE(ctmp1,*) '--->',  kiomid
@@ -223,5 +251,5 @@
 
 
-   FUNCTION iom_varid ( kiomid, cdvar, kdimsz )  
+   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, ldstop )  
       !!-----------------------------------------------------------------------
       !!                  ***  FUNCTION  iom_varid  ***
@@ -232,13 +260,19 @@
       CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
       INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
+      LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
       !
       INTEGER                        ::   iom_varid, iiv, i_nvd
       LOGICAL                        ::   ll_fnd
       CHARACTER(LEN=100)             ::   clinfo                   ! info character
+      LOGICAL                        ::   llstop                   ! local definition of ldstop
       !!-----------------------------------------------------------------------
-      clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
       iom_varid = 0                         ! default definition
-      !
-      IF( kiomid > 0 ) THEN
+      ! do we call ctl_stop if we look for non-existing variable?
+      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
+      ELSE                         ;   llstop = .TRUE.
+      ENDIF
+      !
+      IF( kiomid > 0 ) THEN
+         clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
          IF( iom_file(kiomid)%nfid == 0 ) THEN 
             CALL ctl_stop( trim(clinfo), 'the file is not open' )
@@ -257,6 +291,6 @@
                   SELECT CASE (iom_file(kiomid)%iolib)
                   CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
-                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid(   kiomid, cdvar, iiv, kdimsz )
-                  CASE (jprstdimg)   ;   iom_varid = 0   ! all variables are listed in iom_file
+                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz )
+                  CASE (jprstdimg)   ;   iom_varid = -1   ! all variables are listed in iom_file
                   CASE DEFAULT   
                      CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
@@ -266,4 +300,5 @@
                         &                         'increase the parameter jpmax_vars')
                ENDIF
+               IF( llstop .AND. iom_varid == -1 )   CALL ctl_stop( TRIM(clinfo)//' not found' ) 
             ELSE
                iom_varid = iiv
@@ -294,14 +329,16 @@
       INTEGER               :: idvar   ! variable id
       !
-      idvar = iom_varid( kiomid, cdvar )
-      IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
-         SELECT CASE (iom_file(kiomid)%iolib)
-         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
-         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
-         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
-         CASE DEFAULT    
-            CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-         END SELECT
-      END IF
+      IF( kiomid > 0 ) THEN
+         idvar = iom_varid( kiomid, cdvar )
+         IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
+            CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
+            CASE DEFAULT    
+               CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
    END SUBROUTINE iom_g0d
 
@@ -315,6 +352,8 @@
       INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
       !
-      IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
-            &                                        ktime=ktime, kstart=kstart, kcount=kcount )
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
+      ENDIF
    END SUBROUTINE iom_g1d
 
@@ -328,6 +367,8 @@
       INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis
       !
-      IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
-            &                                        ktime=ktime, kstart=kstart, kcount=kcount )
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
+      ENDIF
    END SUBROUTINE iom_g2d
 
@@ -341,12 +382,14 @@
       INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis
       !
-      IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
-            &                                        ktime=ktime, kstart=kstart, kcount=kcount )
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
+      ENDIF
    END SUBROUTINE iom_g3d
    !!----------------------------------------------------------------------
 
    SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   &
-         &                   pv_r1d, pv_r2d, pv_r3d,   &
-         &                   ktime , kstart, kcount  )
+         &                  pv_r1d, pv_r2d, pv_r3d,   &
+         &                  ktime , kstart, kcount  )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_get_123d  ***
@@ -373,22 +416,27 @@
       INTEGER                        ::   itime       ! record number
       INTEGER                        ::   istop       ! temporary value of nstop
+      INTEGER                        ::   ix1, ix2, iy1, iy2   ! subdomain indexes
+      INTEGER                        ::   ji, jj      ! loop counters
+      INTEGER                        ::   irankpv       ! 
+      INTEGER                        ::   ind1, ind2  ! substring index
       INTEGER, DIMENSION(jpmax_dims) ::   istart      ! starting point to read for each axis
       INTEGER, DIMENSION(jpmax_dims) ::   icnt        ! number of value to read along each axis 
       INTEGER, DIMENSION(jpmax_dims) ::   idimsz      ! size of the dimensions of the variable
+      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable
       REAL(wp)                       ::   zscf, zofs  ! sacle_factor and add_offset
       INTEGER                        ::   itmp        ! temporary integer
       CHARACTER(LEN=100)             ::   clinfo      ! info character
+      CHARACTER(LEN=100)             ::   clname      ! file name
+      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      ! 
       !---------------------------------------------------------------------
       !
-      clinfo = '          iom_get_123d, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
+      clname = iom_file(kiomid)%name   !   esier to read
+      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
       ! local definition of the domain ?
       idom = kdom
       ! check kcount and kstart optionals parameters...
-      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) )   &
-            CALL ctl_stop( trim(clinfo), 'kcount present needs kstart present' )
-      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) )   &
-            CALL ctl_stop( trim(clinfo), 'kstart present needs kcount present' )
-      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   )   &
-            CALL ctl_stop( trim(clinfo), 'kstart present needs kdom = jpdom_unknown' )
+      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
+      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
+      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
 
       ! Search for the variable in the data base (eventually actualize data)
@@ -402,142 +450,86 @@
          idmspc = inbdim                                   ! number of spatial dimensions in the file
          IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
-         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo),   &
-               &                    'the file has more than 3 spatial dimensions this case is not coded...' ) 
-         IF( idom == jpdom_local ) THEN        ! Identify the domain in case of jpdom_local definition
-            IF( idimsz(1) == jpi .AND. idimsz(2) == jpj ) THEN 
-               idom = jpdom_local_full
-            ELSEIF( idimsz(1) == nlci .AND. idimsz(2) == nlcj ) THEN 
-               idom = jpdom_local_noextra
-            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN 
-               idom = jpdom_local_noovlap
-            ELSE 
-               CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
-            ENDIF
-         ENDIF
+         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
+         !
+         ! update idom definition...
+         ! Identify the domain in case of jpdom_auto(glo/dta) definition
+         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN            
+            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
+            ELSE                               ;   idom = jpdom_data
+            ENDIF
+            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
+            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
+            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
+         ENDIF
+         ! Identify the domain in case of jpdom_local definition
+         IF( idom == jpdom_local ) THEN
+            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
+            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
+            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
+            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
+            ENDIF
+         ENDIF
+         !
+         ! check the consistency between input array and data rank in the file
+         !
+         ! initializations
+         itime = 1
+         IF( PRESENT(ktime) ) itime = ktime
+
+         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
+         WRITE(clrankpv, fmt='(i1)') irankpv
+         WRITE(cldmspc , fmt='(i1)') idmspc
+         !
+         IF(     idmspc <  irankpv ) THEN 
+            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
+               &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
+         ELSEIF( idmspc == irankpv ) THEN
+            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
+               &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
+         ELSEIF( idmspc >  irankpv ) THEN
+               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
+                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
+                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
+                        &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
+                  idmspc = idmspc - 1
+               ELSE
+                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
+                     &                         'we do not accept data with more than '//cldmspc//' spatial dimension',   &
+                     &                         'Use ncwa -a to suppress the unnecessary dimensions' )
+               ENDIF
+         ENDIF
+
          !
          ! definition of istart and icnt
          !
-         ! initializations
+         icnt  (:) = 1
          istart(:) = 1
-         icnt  (:) = 1
-         itime = 1
-         IF( PRESENT(ktime) ) itime = ktime
-         !
-         IF( PRESENT(pv_r1d) ) THEN
-            IF( idmspc == 1 ) THEN 
-               ! data is 1d array (+ maybe a temporal dimension)
-               IF( PRESENT(kstart) ) THEN
-                  istart(1:2) = (/ kstart(1), itime /)
-                  icnt(1) = kcount(1)
-               ELSE
-                  IF( kdom == jpdom_unknown ) THEN
-                     istart(2) = itime
-                     icnt(1) = idimsz(1)
-                  ELSE 
-                     CALL ctl_stop( trim(clinfo), 'case not coded...You must use jpdom_unknown' )
+         istart(idmspc+1) = itime
+
+         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
+         ELSE
+            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
+            ELSE 
+               IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
+                  IF(     idom == jpdom_data    ) THEN ; istart(1:2) = (/ mig(1), mjg(1) /)  ! icnt(1:2) done bellow
+                  ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done bellow
                   ENDIF
-               ENDIF
-            ELSE
-               CALL ctl_stop( trim(clinfo), 'to keep iom lisibility, when reading a 1D array,', &
-                     &         'we do not accept data with more than 1 spatial dimension',     &
-                     &         'Use ncwa -a to suppress the unnecessary dimensions')
-            ENDIF
-         ELSEIF( PRESENT(pv_r2d) ) THEN
-            SELECT CASE (idmspc)
-            CASE (1)
-               CALL ctl_stop( trim(clinfo), 'the file has only 1 spatial dimension',  &
-                     &         'it is impossible to read a 2d array from this file...')
-            CASE (2)
-               ! data is 2d array (+ maybe a temporal dimension)
-               IF( PRESENT(kstart) ) THEN
-                  istart(1:3) = (/ kstart(1:2), itime /)
-                  icnt(1:2) = kcount(1:2)
-               ELSE
-                  IF( kdom == jpdom_unknown ) THEN
-                     istart(3) = itime
-                     icnt(1:2) = idimsz(1:2)
-                  ELSE 
-                     IF( idom == jpdom_data ) THEN
-                        istart(1:3) = (/ mig(1), mjg(1), itime /)
-                     ELSEIF( idom == jpdom_global ) THEN
-                        istart(1:3) = (/ nimpp, njmpp, itime /)
-                     ENDIF
-                     ! we do not read the overlap -> we start to read at nldi, nldj
-                     IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
-                     ! we do not read the overlap and the extra-halos  
-                     ! -> from nldi to nlei and from nldj to nlej 
-                     icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
+                  ! we do not read the overlap                     -> we start to read at nldi, nldj
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
+                  IF( jpni*jpnj == jpnij .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
+                  ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej 
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
+                  IF( jpni*jpnj == jpnij ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
+                  ELSE                            ;   icnt(1:2) = (/ nlci           , nlcj            /)
                   ENDIF
-               ENDIF
-            CASE DEFAULT
-               IF( itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
-                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...',                &
-                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
-                        &         'we accept this case even if there is a possible mix-up between z and time dimension' )           
-                  IF( PRESENT(kstart) ) THEN
-                     istart(1:2) = kstart(1:2)
-                     icnt(1:2) = kcount(1:2)
-                  ELSE
-                     IF( kdom == jpdom_unknown ) THEN
-                        icnt(1:2) = idimsz(1:2)
-                     ELSE 
-                        IF( idom == jpdom_data ) THEN
-                           istart(1:2) = (/ mig(1), mjg(1) /)
-                        ELSEIF( idom == jpdom_global ) THEN
-                           istart(1:2) = (/ nimpp, njmpp /)
-                        ENDIF
-                        ! we do not read the overlap -> we start to read at nldi, nldj
-                        IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
-                        ! we do not read the overlap and the extra-halos  
-                        ! -> from nldi to nlei and from nldj to nlej 
-                        icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
-                     ENDIF
-                  ENDIF
-               ELSE
-                  CALL ctl_stop( trim(clinfo), 'to keep iom lisibility, when reading a 2D array,',           &
-                        &                       'we do not accept data with more than 2 spatial dimension',   &
-                        &                       'Use ncwa -a to suppress the unnecessary dimensions' )
-               ENDIF
-            END SELECT
-         ELSEIF( PRESENT(pv_r3d) ) THEN
-            SELECT CASE (idmspc)
-            CASE( 1 )
-               CALL ctl_stop( trim(clinfo), 'the file has only 1 spatial dimension',            &
-                     &                       'it is impossible to read a 3d array from this file...' )
-            CASE( 2 )
-               CALL ctl_stop( trim(clinfo), 'the file has only 2 spatial dimension',            &
-                     &                       'it is impossible to read a 3d array from this file...' )
-            CASE( 3 )
-               ! data is 3d array (+ maybe a temporal dimension)
-               IF( PRESENT(kstart) ) THEN
-                  istart(1:4) = (/ kstart(1:3), itime /)
-                  icnt(1:3) = kcount(1:3)
-               ELSE
-                  IF( kdom == jpdom_unknown ) THEN
-                     istart(4) = itime
-                     icnt(1:3) = idimsz(1:3)
-                  ELSE 
-                     IF( idom == jpdom_data ) THEN
-                        istart(1:4) = (/ mig(1), mjg(1), 1, itime /)
-                     ELSEIF( idom == jpdom_global ) THEN
-                        istart(1:4) = (/ nimpp, njmpp, 1, itime /)
-                     ENDIF
-                     ! we do not read the overlap -> we start to read at nldi, nldj
-                     IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
-                     ! we do not read the overlap and the extra-halos
-                     ! -> from nldi to nlei and from nldj to nlej 
-                     icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
-                     IF( idom == jpdom_data ) THEN 
-                        icnt(3) = jpkdta
-                     ELSE
-                        icnt(3) = jpk
+                  IF( PRESENT(pv_r3d) ) THEN
+                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
+                     ELSE                            ; icnt(3) = jpk
                      ENDIF
                   ENDIF
                ENDIF
-            CASE DEFAULT
-               CALL ctl_stop( trim(clinfo), 'to keep iom lisibility, when reading a 3D array,',   &
-                     &         'we do not accept data with more than 3 spatial dimension',         &
-                     &         'Use ncwa -a to suppress the unnecessary dimensions' )           
-            END SELECT
+            ENDIF
          ENDIF
 
@@ -546,7 +538,7 @@
          DO jl = 1, jpmax_dims
             itmp = istart(jl)+icnt(jl)-1
-            IF( (itmp) > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
-               WRITE(ctmp1,*) '(istart(',jl,') + icnt(',jl,') - 1) = ', itmp
-               WRITE(ctmp2,*) ' is larger than idimsz(',jl,'): ', idimsz(jl)
+            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
+               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
+               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
                CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
             ENDIF
@@ -555,62 +547,97 @@
          ! check that icnt matches the input array
          !-     
-         IF( PRESENT(pv_r1d) ) THEN
-            itmp = size(pv_r1d)
-            WRITE(ctmp1,*) 'size(pv_r1d): ', itmp, ' /= icnt(1): ', icnt(1)
-            IF( itmp /= icnt(1) )   CALL ctl_stop( trim(clinfo), ctmp1 )
-         ELSEIF( PRESENT(pv_r2d) ) THEN
-            DO jl = 1, 2
-               IF( idom == jpdom_unknown ) THEN
-                  itmp = size(pv_r2d, jl)
-                  WRITE(ctmp1,*) 'size(pv_r2d, ',jl,'): ',itmp,' /= icnt(',jl,'): ',icnt(jl)
-               ELSE 
-                  itmp = size(pv_r2d(nldi:nlei,nldj:nlej), jl)
-                  WRITE(ctmp1,*) 'size(pv_r2d(nldi:nlei,nldj:nlej), ',jl,'): ',itmp,' /= icnt(',jl,'): ',icnt(jl)
+         IF( idom == jpdom_unknown ) THEN
+            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
+            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
+            IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
+            ctmp1 = 'd'
+         ELSE
+            IF( irankpv == 2 ) THEN
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
+               IF( jpni*jpnj == jpnij ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
+               ELSE                          ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
                ENDIF
-               IF( itmp /= icnt(jl) )   CALL ctl_stop( trim(clinfo), ctmp1 )
-            END DO
-         ELSEIF( PRESENT(pv_r3d) ) THEN
-            DO jl = 1, 3
-               IF( idom == jpdom_unknown ) THEN
-                  itmp = size(pv_r3d, jl)
-                  WRITE(ctmp1,*) 'size(pv_r3d, ',jl,'): ',itmp,' /= icnt(',jl,'):', icnt(jl)
-               ELSE 
-                  itmp = size(pv_r3d(nldi:nlei,nldj:nlej,:), jl)
-                  WRITE(ctmp1,*) 'size(pv_r3d(nldi:nlei,nldj:nlej), ',jl,'): ',itmp,' /= icnt(',jl,'): ',icnt(jl)
+            ENDIF
+            IF( irankpv == 3 ) THEN 
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
+               IF( jpni*jpnj == jpnij ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
+               ELSE                          ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
                ENDIF
-               IF( itmp /= icnt(jl) )   CALL ctl_stop( trim(clinfo), ctmp1 )
-            END DO
-         ENDIF
+            ENDIF
+         ENDIF
+         
+         DO jl = 1, irankpv
+            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
+            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
+         END DO
+
       ENDIF
 
       ! read the data
       !-     
-      IF( istop == nstop) THEN ! no additional errors until this point...
+      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
          !
+         ! find the right index of the array to be read
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
+!         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+!         ENDIF
+         IF( jpni*jpnj == jpnij ) THEN
+            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
+            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+            ENDIF
+         ELSE
+            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
+            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+            ENDIF
+         ENDIF
+      
          SELECT CASE (iom_file(kiomid)%iolib)
-         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idom, idvar, inbdim, istart, icnt, pv_r1d, pv_r2d, pv_r3d )
-         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idom, idvar, inbdim, istart, icnt, pv_r1d, pv_r2d, pv_r3d )
-         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar,         istart, icnt, pv_r1d, pv_r2d, pv_r3d )
+         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
+            &                                         pv_r1d, pv_r2d, pv_r3d )
+         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
+            &                                         pv_r1d, pv_r2d, pv_r3d )
+         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2,   &
+            &                                         pv_r1d, pv_r2d, pv_r3d )
          CASE DEFAULT    
             CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
          END SELECT
-         IF( istop == nstop .AND. lwp )   &
-               WRITE(numout,*) '           read '//trim(cdvar)//' in '//trim(iom_file(kiomid)%name)//' ok'
-         !--- Apply scale_factor and offset
-         zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
-         zofs = iom_file(kiomid)%ofs(idvar)      ! offset
-         IF( PRESENT(pv_r1d) ) THEN
-            IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
-            IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
-         ELSEIF( PRESENT(pv_r2d) ) THEN
-!CDIR COLLAPSE
-            IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
-!CDIR COLLAPSE
-            IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
-         ELSEIF( PRESENT(pv_r3d) ) THEN
-!CDIR COLLAPSE
-            IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
-!CDIR COLLAPSE
-            IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
+
+         IF( istop == nstop ) THEN   ! no additional errors until this point...
+            IF(lwp) WRITE(numout,*) '           read '//TRIM(cdvar)//' in '//TRIM(iom_file(kiomid)%name)//' ok'
+            
+            !--- overlap areas and extra hallows (mpp)
+            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
+               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
+            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
+               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
+               IF( icnt(3) == jpk ) THEN
+                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
+               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
+                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
+                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
+               ENDIF
+            ENDIF
+            
+            !--- Apply scale_factor and offset
+            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
+            zofs = iom_file(kiomid)%ofs(idvar)      ! offset
+            IF(     PRESENT(pv_r1d) ) THEN
+               IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
+               IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
+            ELSEIF( PRESENT(pv_r2d) ) THEN
+               !CDIR COLLAPSE
+               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
+               !CDIR COLLAPSE
+               IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
+            ELSEIF( PRESENT(pv_r3d) ) THEN
+               !CDIR COLLAPSE
+               IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
+               !CDIR COLLAPSE
+               IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
+            ENDIF
+            !
          ENDIF
          !
@@ -620,5 +647,5 @@
 
 
-   SUBROUTINE iom_gettime( kiomid, cdvar, ptime )
+   SUBROUTINE iom_gettime( kiomid, ptime, cdvar, kntime, cdunits, cdcalendar )
       !!--------------------------------------------------------------------
       !!                   ***  SUBROUTINE iom_gettime  ***
@@ -626,39 +653,56 @@
       !! ** Purpose : read the time axis cdvar in the file 
       !!--------------------------------------------------------------------
-      INTEGER               , INTENT(in   ) ::   kiomid   ! file Identifier
-      CHARACTER(len=*)      , INTENT(in   ) ::   cdvar    ! time axis name
-      REAL(wp), DIMENSION(:), INTENT(  out) ::   ptime    ! the time axis
-      !
+      INTEGER                    , INTENT(in   ) ::   kiomid     ! file Identifier
+      REAL(wp), DIMENSION(:)     , INTENT(  out) ::   ptime      ! the time axis
+      CHARACTER(len=*), OPTIONAL , INTENT(in   ) ::   cdvar      ! time axis name
+      INTEGER         , OPTIONAL , INTENT(  out) ::   kntime     ! number of times in file
+      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdunits    ! units attribute of time coordinate
+      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdcalendar ! calendar attribute of 
+      !
+      INTEGER, DIMENSION(1) :: kdimsz
       INTEGER            ::   idvar    ! id of the variable
+      CHARACTER(LEN=32)  ::   tname    ! local name of time coordinate
       CHARACTER(LEN=100) ::   clinfo   ! info character
       !---------------------------------------------------------------------
       !
-      clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
-      idvar = iom_varid( kiomid, cdvar )
-      !
-      ptime(:) = 0. ! default definition
-      IF( idvar > 0 ) THEN
-         IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
-            IF( iom_file(kiomid)%luld(idvar) ) THEN
-               IF( iom_file(kiomid)%dimsz(1,idvar) == size(ptime) ) THEN
-                  SELECT CASE (iom_file(kiomid)%iolib)
-                  CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime )
-                  CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime )
-                  CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
-                  CASE DEFAULT    
-                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-                  END SELECT
+      IF ( PRESENT(cdvar) ) THEN
+         tname = cdvar
+      ELSE
+         tname = iom_file(kiomid)%uldname
+      ENDIF
+      IF( kiomid > 0 ) THEN
+         clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(tname)
+         IF ( PRESENT(kntime) ) THEN
+            idvar  = iom_varid( kiomid, tname, kdimsz = kdimsz )
+            kntime = kdimsz(1)
+         ELSE
+            idvar = iom_varid( kiomid, tname )
+         ENDIF
+         !
+         ptime(:) = 0. ! default definition
+         IF( idvar > 0 ) THEN
+            IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
+               IF( iom_file(kiomid)%luld(idvar) ) THEN
+                  IF( iom_file(kiomid)%dimsz(1,idvar) == size(ptime) ) THEN
+                     SELECT CASE (iom_file(kiomid)%iolib)
+                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime, cdunits, cdcalendar )
+                     CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime, cdunits, cdcalendar )
+                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
+                     CASE DEFAULT    
+                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+                     END SELECT
+                  ELSE
+                     WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
+                     CALL ctl_stop( trim(clinfo), trim(ctmp1) )
+                  ENDIF
                ELSE
-                  WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
-                  CALL ctl_stop( trim(clinfo), trim(ctmp1) )
+                  CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
                ENDIF
             ELSE
-               CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
+               CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
             ENDIF
          ELSE
-            CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
-         ENDIF
-      ELSE
-         CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
+            CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
+         ENDIF
       ENDIF
       !
@@ -677,14 +721,16 @@
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
       INTEGER :: ivid   ! variable id
-      IF( iom_file(kiomid)%nfid > 0 ) THEN
-         ivid = iom_varid(kiomid, cdvar)
-         SELECT CASE (iom_file(kiomid)%iolib)
-         CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
-         CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
-         CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, pvar )
-         CASE DEFAULT     
-            CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-         END SELECT
-      END IF
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
    END SUBROUTINE iom_rp0d
 
@@ -697,14 +743,16 @@
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
       INTEGER :: ivid   ! variable id
-      IF( iom_file(kiomid)%nfid > 0 ) THEN
-         ivid = iom_varid(kiomid, cdvar)
-         SELECT CASE (iom_file(kiomid)%iolib)
-         CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
-         CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
-         CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, pv_r1d = pvar )
-         CASE DEFAULT     
-            CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-         END SELECT
-      END IF
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
    END SUBROUTINE iom_rp1d
 
@@ -717,14 +765,16 @@
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
       INTEGER :: ivid   ! variable id
-      IF( iom_file(kiomid)%nfid > 0 ) THEN
-         ivid = iom_varid(kiomid, cdvar)
-         SELECT CASE (iom_file(kiomid)%iolib)
-         CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
-         CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
-         CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, pv_r2d = pvar ) 
-         CASE DEFAULT     
-            CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-         END SELECT
-      END IF
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
    END SUBROUTINE iom_rp2d
 
@@ -737,14 +787,16 @@
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
       INTEGER :: ivid   ! variable id
-      IF( iom_file(kiomid)%nfid > 0 ) THEN
-         ivid = iom_varid(kiomid, cdvar)
-         SELECT CASE (iom_file(kiomid)%iolib)
-         CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
-         CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
-         CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, pv_r3d = pvar )
-         CASE DEFAULT     
-            CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
-         END SELECT
-      END IF
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
    END SUBROUTINE iom_rp3d
    !!----------------------------------------------------------------------
Index: /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_def.F90
===================================================================
--- /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_def.F90	(revision 950)
+++ /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_def.F90	(revision 951)
@@ -5,8 +5,9 @@
    !!====================================================================
    !! History :  9.0  ! 06 09  (S. Masson) Original code
+   !!             "   ! 07 07  (D. Storkey) Add uldname
    !!--------------------------------------------------------------------
    !!---------------------------------------------------------------------------------
    !! OPA 9.0 , LOCEAN-IPSL (2006) 
-   !! $Header$ 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_def.F90,v 1.7 2007/06/05 10:33:38 opalod Exp $ 
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!---------------------------------------------------------------------------------
@@ -24,4 +25,6 @@
    INTEGER, PARAMETER, PUBLIC ::   jpdom_local_noovlap = 6   !: (nldi:nlei  ,nldj:nlej  )
    INTEGER, PARAMETER, PUBLIC ::   jpdom_unknown       = 7   !: No dimension checking
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_autoglo       = 8   !: 
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_autodta       = 9   !: 
 
    INTEGER, PARAMETER, PUBLIC ::   jpioipsl    = 100      !: Use ioipsl (fliocom only) library
@@ -41,10 +44,11 @@
 
    INTEGER, PARAMETER, PUBLIC ::   jpmax_files  = 20   !: maximum number of simultaneously opened file
-   INTEGER, PARAMETER, PUBLIC ::   jpmax_vars   = 60   !: maximum number of variables in one file
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_vars   = 360  !: maximum number of variables in one file
    INTEGER, PARAMETER, PUBLIC ::   jpmax_dims   =  4   !: maximum number of dimensions for one variable
    INTEGER, PARAMETER, PUBLIC ::   jpmax_digits =  5   !: maximum number of digits for the cpu number in the file name
 
+!$AGRIF_DO_NOT_TREAT
    INTEGER, PUBLIC            ::   iom_init = 0        !: used to initialize iom_file(:)%nfid to 0
-!$AGRIF_DO_NOT_TREAT
+
    TYPE, PUBLIC ::   file_descriptor
       CHARACTER(LEN=240)                        ::   name     !: name of the file
@@ -54,5 +58,6 @@
       INTEGER                                   ::   iduld    !: id of the unlimited dimension
       INTEGER                                   ::   irec     !: writing record position  
-      CHARACTER(LEN=16), DIMENSION(jpmax_vars)  ::   cn_var   !: names of the variables
+      CHARACTER(LEN=32)                         ::   uldname  !: name of the unlimited dimension
+      CHARACTER(LEN=32), DIMENSION(jpmax_vars)  ::   cn_var   !: names of the variables
       INTEGER, DIMENSION(jpmax_vars)            ::   nvid     !: id of the variables
       INTEGER, DIMENSION(jpmax_vars)            ::   ndims    !: number of dimensions of the variables
Index: /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_ioipsl.F90
===================================================================
--- /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_ioipsl.F90	(revision 950)
+++ /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_ioipsl.F90	(revision 951)
@@ -6,4 +6,5 @@
    !! History :  9.0  ! 05 12  (J. Belier) Original code
    !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
+   !!             "   ! 07 07  (D. Storkey) Changes to iom_ioipsl_gettime
    !!--------------------------------------------------------------------
    !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
@@ -19,5 +20,4 @@
    USE in_out_manager  ! I/O manager
    USE dom_oce         ! ocean space and time domain
-   USE lbclnk          ! lateal boundary condition / mpp exchanges
    USE iom_def         ! iom variables definitions
    USE ioipsl          ! IOIPSL library
@@ -36,5 +36,5 @@
    !!----------------------------------------------------------------------
    !!  OPA 9.0 , LOCEAN-IPSL (2006)
-   !! $Header$
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_ioipsl.F90,v 1.8 2007/06/29 14:10:50 opalod Exp $
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -48,9 +48,9 @@
       !! ** Purpose :  open an input file with IOIPSL (only fliocom module)
       !!---------------------------------------------------------------------
-      CHARACTER(len=*)       , INTENT(inout) ::   cdname    ! File name
-      INTEGER                , INTENT(  out) ::   kiomid    ! ioipsl identifier of the opened file
-      LOGICAL                , INTENT(in   ) ::   ldwrt     ! read or write the file?
-      LOGICAL                , INTENT(in   ) ::   ldok      ! check the existence 
-      INTEGER, DIMENSION(2,5), INTENT(in   ) ::   kdompar   ! domain parameters: 
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname    ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid    ! ioipsl identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt     ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok      ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar   ! domain parameters: 
 
       CHARACTER(LEN=100) ::   clinfo     ! info character
@@ -59,4 +59,5 @@
       INTEGER            ::   ifliodom   ! model domain identifier (see flio_dom_set)
       INTEGER            ::   ioipslid   ! ioipsl identifier of the opened file
+      INTEGER            ::   jl         ! loop variable
       !---------------------------------------------------------------------
 
@@ -92,5 +93,5 @@
             ENDIF
          ELSE              ! the file should be open for read mode so it must exist...
-            CALL ctl_stop( TRIM(clinfo), 'File '//cdname(1:iln-1)//'* not found' )
+            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
          ENDIF
       ENDIF
@@ -98,5 +99,9 @@
       ! =============
       IF( istop == nstop ) THEN   ! no error within this routine
-         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+         kiomid = 0
+         DO jl = jpmax_files, 1, -1
+            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
+         ENDDO
          iom_file(kiomid)%name   = TRIM(cdname)
          iom_file(kiomid)%nfid   = ioipslid
@@ -161,8 +166,9 @@
                   &           len_dims = iom_file(kiomid)%dimsz(1:i_nvd,kiv), &   ! dimensions size
                   &           id_dims  = idimid(1:i_nvd) )                        ! dimensions ids
-            DO ji = 1, i_nvd   ! find the unlimited dimension
+            iom_file(kiomid)%luld(kiv) = .FALSE.   ! default value
+            DO ji = 1, i_nvd                       ! find the unlimited dimension
                IF( idimid(ji) == iom_file(kiomid)%iduld ) iom_file(kiomid)%luld(kiv) = .TRUE.
             END DO
-            !---------- Deal with scale_factor and offset
+            !---------- Deal with scale_factor and add_offset
             CALL flioinqa( ioipslid, cdvar, 'scale_factor', ll_fnd )
             IF( ll_fnd) THEN
@@ -171,7 +177,7 @@
                iom_file(kiomid)%scf(kiv) = 1.
             END IF
-            CALL flioinqa( ioipslid, cdvar, 'offset', ll_fnd )
+            CALL flioinqa( ioipslid, cdvar, 'add_offset', ll_fnd )
             IF( ll_fnd ) THEN
-               CALL fliogeta( ioipslid, cdvar, 'offset', iom_file(kiomid)%ofs(kiv) )
+               CALL fliogeta( ioipslid, cdvar, 'add_offset', iom_file(kiomid)%ofs(kiv) )
             ELSE
                iom_file(kiomid)%ofs(kiv) = 0.
@@ -190,7 +196,6 @@
                   &                       'increase the parameter jpmax_vars')
          ENDIF
-!!$                  ELSE  
-!!$                     CALL ctl_warn( trim(clinfo), 'Variable '//trim(cdvar)// &
-!!$                        &                         ' is not found in the file '//trim(iom_file(kiomid)%name) )
+      ELSE  
+         iom_ioipsl_varid = -1   !   variable not found, return error code: -1
       ENDIF
       !
@@ -213,6 +218,6 @@
 
 
-   SUBROUTINE iom_ioipsl_g123d( kiomid, kdom, kvid, knbdim, kstart, kcount,    &
-         &                          pv_r1d, pv_r2d, pv_r3d)
+   SUBROUTINE iom_ioipsl_g123d( kiomid, kvid, knbdim, kstart, kcount, kx1, kx2, ky1, ky2,   &
+         &                      pv_r1d, pv_r2d, pv_r3d)
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_ioipsl_g123d  ***
@@ -223,9 +228,9 @@
       !!-----------------------------------------------------------------------
       INTEGER                    , INTENT(in   )           ::   kiomid     ! iom identifier of the file
-      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
       INTEGER                    , INTENT(in   )           ::   kvid       ! Name of the variable
       INTEGER                    , INTENT(in   )           ::   knbdim     ! number of dimensions of the variable
       INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kstart     ! start position of the reading in each axis 
       INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kcount     ! number of points to be read in each axis
+      INTEGER ,                    INTENT(in   )           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
       REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
       REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
@@ -235,32 +240,13 @@
       CHARACTER(LEN=100)    ::   clvn       ! variable name
       !---------------------------------------------------------------------
-      clvn = TRIM(iom_file(kiomid)%cn_var(kvid))
-      ioipslid = iom_file(kiomid)%nfid
+      clvn = TRIM(iom_file(kiomid)%cn_var(kvid))   ! get back variable name 
+      ioipslid = iom_file(kiomid)%nfid             ! get back IPIPSL file id
       !
       IF( PRESENT(pv_r1d) ) THEN
-         CALL fliogetv( ioipslid, clvn, pv_r1d(:), start=kstart(1:knbdim), count=kcount(1:knbdim) )
+         CALL fliogetv( ioipslid, clvn, pv_r1d(:                ), start = kstart(1:knbdim), count = kcount(1:knbdim) )
       ELSEIF( PRESENT(pv_r2d) ) THEN
-         IF( kdom /= jpdom_unknown ) THEN
-            CALL fliogetv( ioipslid, clvn, pv_r2d(nldi:nlei,nldj:nlej), start=kstart(1:knbdim), count=kcount(1:knbdim) )
-            !--- Fill the overlap areas and extra hallows (mpp)
-            CALL lbc_lnk (pv_r2d,'Z',-999.,'no0')
-         ELSE
-            CALL fliogetv( ioipslid, clvn, pv_r2d(:,:), start=kstart(1:knbdim), count=kcount(1:knbdim) )
-         ENDIF
+         CALL fliogetv( ioipslid, clvn, pv_r2d(kx1:kx2,ky1:ky2  ), start = kstart(1:knbdim), count = kcount(1:knbdim) )
       ELSEIF( PRESENT(pv_r3d) ) THEN
-         IF( kdom /= jpdom_unknown ) THEN
-            CALL fliogetv( ioipslid, clvn, pv_r3d(nldi:nlei,nldj:nlej,:), start=kstart(1:knbdim),   &
-                  &                                                         count=kcount  (1:knbdim) )
-            !--- Fill the overlap areas and extra hallows (mpp)
-            ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
-            IF( kcount(3) == jpk ) THEN
-               CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
-            ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
-               pv_r3d(nlei+1:jpi,      :   ,:) = 1.            
-               pv_r3d(      :   ,nlej+1:jpj,:) = 1.            
-            ENDIF
-         ELSE
-            CALL fliogetv( ioipslid, clvn, pv_r3d(:,:,:), start=kstart(1:knbdim), count=kcount(1:knbdim) )
-         ENDIF
+         CALL fliogetv( ioipslid, clvn, pv_r3d(kx1:kx2,ky1:ky2,:), start = kstart(1:knbdim), count = kcount(1:knbdim) )
       ENDIF
       !
@@ -269,5 +255,5 @@
 
 
-   SUBROUTINE iom_ioipsl_gettime( kiomid, kvid, ptime )
+   SUBROUTINE iom_ioipsl_gettime( kiomid, kvid, ptime, cdunits, cdcalendar )
       !!--------------------------------------------------------------------
       !!                   ***  SUBROUTINE iom_gettime  ***
@@ -275,11 +261,19 @@
       !! ** Purpose : read the time axis kvid in the file with IOIPSL (only fliocom module)
       !!--------------------------------------------------------------------
-      INTEGER               , INTENT(in   ) ::   kiomid   ! file Identifier
-      INTEGER               , INTENT(in   ) ::   kvid     ! variable id
-      REAL(wp), DIMENSION(:), INTENT(  out) ::   ptime    ! the time axis
+      INTEGER                   , INTENT(in   ) ::   kiomid     ! file Identifier
+      INTEGER                   , INTENT(in   ) ::   kvid       ! variable id
+      REAL(wp), DIMENSION(:)    , INTENT(  out) ::   ptime      ! the time axis
+      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdunits    ! units attribute
+      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdcalendar ! calendar attribute
       !---------------------------------------------------------------------
       !
       CALL fliogetv( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), ptime(:),   &
             &         start=(/ 1 /), count=(/ iom_file(kiomid)%dimsz(1, kvid) /) )
+      IF ( PRESENT(cdunits) ) THEN 
+         CALL fliogeta( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), "units", cdunits )
+      ENDIF
+      IF ( PRESENT(cdcalendar) ) THEN 
+         CALL fliogeta( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), "calendar", cdcalendar )
+      ENDIF
       !
    END SUBROUTINE iom_ioipsl_gettime
@@ -330,13 +324,11 @@
                &                  long_name="Time axis", units='seconds since 0001-01-01 00:00:00' )
          ! update informations structure related the dimension variable we just added...
-         iom_file(kiomid)%nvars         = 4
-         iom_file(kiomid)%luld(1:4)     = (/ .FALSE., .FALSE., .FALSE., .TRUE. /)
-         iom_file(kiomid)%cn_var(1:3)   = (/ 'nav_lon', 'nav_lat', 'nav_lev' /)
-         iom_file(kiomid)%cn_var(4)     = 'time_counter'
-         iom_file(kiomid)%ndims(1:4)    = (/ 2, 2, 1, 1 /)  
-         CALL flioinqf( ioipslid, ln_dim = idimsz )
-         iom_file(kiomid)%dimsz(1:2, 1) = idimsz(1:2)
-         iom_file(kiomid)%dimsz(1:2, 2) = idimsz(1:2)
-         iom_file(kiomid)%dimsz(1, 3:4) = (/idimsz(3), 1/)
+         iom_file(kiomid)%nvars       = 4
+         iom_file(kiomid)%luld(1:4)   = (/ .FALSE., .FALSE., .FALSE., .TRUE. /)
+         iom_file(kiomid)%cn_var(1:3) = (/ 'nav_lon', 'nav_lat', 'nav_lev' /)
+         iom_file(kiomid)%cn_var(4)   = 'time_counter'
+         iom_file(kiomid)%ndims(1:4)  = (/ 2, 2, 1, 1 /)
+         ! trick: defined to 0 to say that dimension variables are defined but not yet written
+         iom_file(kiomid)%dimsz(1, 1) = 0   
          IF(lwp) WRITE(numout,*) TRIM(clinfo)//' define dimension variables done'
       ENDIF
@@ -403,4 +395,5 @@
             ! write dimension variables if it is not already done
             ! =============
+            ! trick: is defined to 0 => dimension variable are defined but not yet written
             IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN
                CALL flioputv( ioipslid, 'nav_lon'     , glamt(ix1:ix2, iy1:iy2) )
@@ -408,5 +401,10 @@
                CALL flioputv( ioipslid, 'nav_lev'     , gdept_0 )
                ! +++ WRONG VALUE: to be improved but not really useful...
-               CALL flioputv( ioipslid, 'time_counter', kt )   
+               CALL flioputv( ioipslid, 'time_counter', kt )
+               ! update the values of the variables dimensions size
+               CALL flioinqf( ioipslid, ln_dim = idimsz )
+               iom_file(kiomid)%dimsz(1:2, 1) = idimsz(1:2)
+               iom_file(kiomid)%dimsz(1:2, 2) = idimsz(1:2)
+               iom_file(kiomid)%dimsz(1, 3:4) = (/idimsz(3), 1/)
                IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done'
             ENDIF
Index: /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_nf90.F90
===================================================================
--- /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_nf90.F90	(revision 950)
+++ /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_nf90.F90	(revision 951)
@@ -6,4 +6,5 @@
    !! History :  9.0  ! 05 12  (J. Belier) Original code
    !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
+   !!             "   ! 07 07  (D. Storkey) Changes to iom_nf90_gettime
    !!--------------------------------------------------------------------
    !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
@@ -36,5 +37,5 @@
    !!----------------------------------------------------------------------
    !!  OPA 9.0 , LOCEAN-IPSL (2006)
-   !! $Header$
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_nf90.F90,v 1.8 2007/06/29 14:10:50 opalod Exp $
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -48,9 +49,9 @@
       !! ** Purpose : open an input file with NF90
       !!---------------------------------------------------------------------
-      CHARACTER(len=*)       , INTENT(inout) ::   cdname    ! File name
-      INTEGER                , INTENT(  out) ::   kiomid    ! nf90 identifier of the opened file
-      LOGICAL                , INTENT(in   ) ::   ldwrt     ! read or write the file?
-      LOGICAL                , INTENT(in   ) ::   ldok      ! check the existence 
-      INTEGER, DIMENSION(2,5), INTENT(in   ) ::   kdompar   ! domain parameters: 
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname    ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid    ! nf90 identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt     ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok      ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar   ! domain parameters: 
 
       CHARACTER(LEN=100) ::   clinfo   ! info character
@@ -60,4 +61,5 @@
       INTEGER            ::   if90id   ! nf90 identifier of the opened file
       INTEGER            ::   idmy     ! dummy variable
+      INTEGER            ::   jl       ! loop variable
       !---------------------------------------------------------------------
 
@@ -103,5 +105,5 @@
             CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_type'           , 'BOX'              ), clinfo)
          ELSE              ! the file should be open for read mode so it must exist...
-            CALL ctl_stop( TRIM(clinfo), 'File '//cdname(1:iln-1)//'* not found' )
+            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
          ENDIF
       ENDIF
@@ -109,5 +111,9 @@
       ! =============
       IF( istop == nstop ) THEN   ! no error within this routine
-         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+         kiomid = 0
+         DO jl = jpmax_files, 1, -1
+            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
+         ENDDO
          iom_file(kiomid)%name   = TRIM(cdname)
          iom_file(kiomid)%nfid   = if90id
@@ -116,4 +122,8 @@
          iom_file(kiomid)%irec   = -1   ! useless for NetCDF files, used to know if the file is in define mode 
          CALL iom_nf90_check(NF90_Inquire(if90id, unlimitedDimId = iom_file(kiomid)%iduld), clinfo)
+         IF ( iom_file(kiomid)%iduld .GE. 0 ) THEN
+           CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, iom_file(kiomid)%iduld,   &
+        &                                               name = iom_file(kiomid)%uldname), clinfo)
+         ENDIF
          IF(lwp) WRITE(numout,*) '                   ---> '//TRIM(cdname)//' OK'
       ELSE
@@ -174,9 +184,10 @@
          iom_file(kiomid)%ndims(kiv)  = i_nvd
          CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, dimids = idimid(1:i_nvd)), clinfo)   ! dimensions ids
-         DO ji = 1, i_nvd   ! dimensions size
+         iom_file(kiomid)%luld(kiv) = .FALSE.   ! default value
+         DO ji = 1, i_nvd                       ! dimensions size
             CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, idimid(ji), len = iom_file(kiomid)%dimsz(ji,kiv)), clinfo)   
             IF( idimid(ji) == iom_file(kiomid)%iduld ) iom_file(kiomid)%luld(kiv) = .TRUE.   ! unlimited dimension? 
          END DO
-         !---------- Deal with scale_factor and offset
+         !---------- Deal with scale_factor and add_offset
          llok = NF90_Inquire_attribute(if90id, ivarid, 'scale_factor') == nf90_noerr
          IF( llok) THEN
@@ -185,7 +196,7 @@
             iom_file(kiomid)%scf(kiv) = 1.
          END IF
-         llok = NF90_Inquire_attribute(if90id, ivarid, 'offset') == nf90_noerr
+         llok = NF90_Inquire_attribute(if90id, ivarid, 'add_offset') == nf90_noerr
          IF( llok ) THEN
-            CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, 'offset', iom_file(kiomid)%ofs(kiv)), clinfo)
+            CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, 'add_offset', iom_file(kiomid)%ofs(kiv)), clinfo)
          ELSE
             iom_file(kiomid)%ofs(kiv) = 0.
@@ -200,7 +211,6 @@
             ENDIF
          ENDIF
-!!$                  ELSE  
-!!$                     CALL ctl_warn( trim(clinfo), 'Variable '//trim(cdvar)// &
-!!$                        &                         ' is not found in the file '//trim(iom_file(kiomid)%name) )
+      ELSE  
+         iom_nf90_varid = -1   !   variable not found, return error code: -1
       ENDIF
       !
@@ -226,6 +236,6 @@
 
 
-   SUBROUTINE iom_nf90_g123d( kiomid, kdom, kvid, knbdim, kstart, kcount,    &
-         &                          pv_r1d, pv_r2d, pv_r3d)
+   SUBROUTINE iom_nf90_g123d( kiomid, kvid, knbdim, kstart, kcount, kx1, kx2, ky1, ky2,   &
+         &                    pv_r1d, pv_r2d, pv_r3d )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_nf90_g123d  ***
@@ -236,47 +246,30 @@
       !!-----------------------------------------------------------------------
       INTEGER                    , INTENT(in   )           ::   kiomid    ! iom identifier of the file
-      INTEGER                    , INTENT(in   )           ::   kdom      ! Type of domain to be read
       INTEGER                    , INTENT(in   )           ::   kvid      ! Name of the variable
       INTEGER                    , INTENT(in   )           ::   knbdim    ! number of dimensions of the variable
       INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kstart    ! start position of the reading in each axis 
       INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kcount    ! number of points to be read in each axis
+      INTEGER ,                    INTENT(in   )           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
       REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d    ! read field (1D case)
       REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d    ! read field (2D case)
       REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d    ! read field (3D case)
       !
-      CHARACTER(LEN=100) ::   clinfo   ! info character
-      INTEGER            ::   if90id   ! nf90 identifier of the opened file
-      INTEGER            ::   ivid     ! nf90 variable id
+      CHARACTER(LEN=100) ::   clinfo               ! info character
+      INTEGER            ::   if90id               ! nf90 identifier of the opened file
+      INTEGER            ::   ivid                 ! nf90 variable id
       !---------------------------------------------------------------------
       clinfo = 'iom_nf90_g123d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
       if90id = iom_file(kiomid)%nfid         ! get back NetCDF file id
       ivid   = iom_file(kiomid)%nvid(kvid)   ! get back NetCDF var id
-      IF( PRESENT(pv_r1d) ) THEN
-         CALL iom_nf90_check(NF90_GET_VAR(if90id, ivid, pv_r1d(:), start=kstart(1:knbdim), count=kcount(1:knbdim)), clinfo )
+      !
+      IF(     PRESENT(pv_r1d) ) THEN
+         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r1d(:                ), start = kstart(1:knbdim),   &
+            &                                                                       count = kcount(1:knbdim)), clinfo )
       ELSEIF( PRESENT(pv_r2d) ) THEN
-         IF( kdom /= jpdom_unknown ) THEN
-            CALL iom_nf90_check(NF90_GET_VAR(if90id, ivid, pv_r2d(nldi:nlei,nldj:nlej),   &
-                  &                           start=kstart(1:knbdim), count=kcount(1:knbdim)), clinfo)
-            !--- Fill the overlap areas and extra hallows (mpp)
-            CALL lbc_lnk (pv_r2d,'Z',-999.,'no0')
-         ELSE
-            CALL iom_nf90_check(NF90_GET_VAR(if90id, ivid, pv_r2d(:,:), start=kstart(1:knbdim), count=kcount(1:knbdim)), clinfo)
-         ENDIF
+         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r2d(kx1:kx2,ky1:ky2  ), start = kstart(1:knbdim),   &
+            &                                                                       count = kcount(1:knbdim)), clinfo )
       ELSEIF( PRESENT(pv_r3d) ) THEN
-         IF( kdom /= jpdom_unknown ) THEN
-            CALL iom_nf90_check(NF90_GET_VAR(if90id, ivid, pv_r3d(nldi:nlei,nldj:nlej,:),   &
-                  &                           start=kstart(1:knbdim), count=kcount  (1:knbdim)), clinfo)
-            !--- Fill the overlap areas and extra hallows (mpp)
-            ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
-            IF( kcount(3) == jpk ) THEN
-               CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
-            ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
-               pv_r3d(nlei+1:jpi,      :   ,:) = 1.            
-               pv_r3d(      :   ,nlej+1:jpj,:) = 1.            
-            ENDIF
-         ELSE
-            CALL iom_nf90_check(NF90_GET_VAR(if90id, ivid, pv_r3d(:,:,:),   &
-                  &                           start=kstart(1:knbdim), count=kcount  (1:knbdim)), clinfo)
-         ENDIF
+         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r3d(kx1:kx2,ky1:ky2,:), start = kstart(1:knbdim),   &
+            &                                                                       count = kcount(1:knbdim)), clinfo )
       ENDIF
       !
@@ -284,5 +277,5 @@
 
 
-   SUBROUTINE iom_nf90_gettime( kiomid, kvid, ptime )
+   SUBROUTINE iom_nf90_gettime( kiomid, kvid, ptime, cdunits, cdcalendar )
       !!--------------------------------------------------------------------
       !!                   ***  SUBROUTINE iom_gettime  ***
@@ -290,7 +283,9 @@
       !! ** Purpose : read the time axis kvid in the file with NF90
       !!--------------------------------------------------------------------
-      INTEGER               , INTENT(in   ) ::   kiomid   ! file Identifier
-      INTEGER               , INTENT(in   ) ::   kvid     ! variable id
-      REAL(wp), DIMENSION(:), INTENT(  out) ::   ptime    ! the time axis
+      INTEGER                   , INTENT(in   ) ::   kiomid     ! file Identifier
+      INTEGER                   , INTENT(in   ) ::   kvid       ! variable id
+      REAL(wp), DIMENSION(:)    , INTENT(  out) ::   ptime      ! the time axis
+      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdunits    ! units attribute
+      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdcalendar ! calendar attribute
       !
       CHARACTER(LEN=100) ::   clinfo     ! info character
@@ -299,4 +294,12 @@
       CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), ptime(:),   &
             &                           start=(/ 1 /), count=(/ iom_file(kiomid)%dimsz(1, kvid) /)), clinfo)
+      IF ( PRESENT(cdunits) ) THEN 
+         CALL iom_nf90_check(NF90_GET_ATT(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), "units", &
+            &                           values=cdunits), clinfo)
+      ENDIF
+      IF ( PRESENT(cdcalendar) ) THEN 
+         CALL iom_nf90_check(NF90_GET_ATT(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), "calendar", &
+            &                           values=cdcalendar), clinfo)
+      ENDIF
       !
    END SUBROUTINE iom_nf90_gettime
@@ -355,9 +358,6 @@
          iom_file(kiomid)%cn_var(1:4) = cltmp
          iom_file(kiomid)%ndims(1:4)  = (/ 2, 2, 1, 1 /)  
-         CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 1, len = iom_file(kiomid)%dimsz(1,1) ), clinfo)
-         CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 2, len = iom_file(kiomid)%dimsz(2,1) ), clinfo)
-         iom_file(kiomid)%dimsz(1:2, 2) = iom_file(kiomid)%dimsz(1:2, 1)
-         CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 3, len = iom_file(kiomid)%dimsz(1,3) ), clinfo)
-         iom_file(kiomid)%dimsz(1  , 4) = 1   ! unlimited dimension
+         ! trick: defined to 0 to say that dimension variables are defined but not yet written
+         iom_file(kiomid)%dimsz(1, 1)  = 0   
          IF(lwp) WRITE(numout,*) TRIM(clinfo)//' define dimension variables done'
       ENDIF
@@ -433,4 +433,5 @@
             ! write dimension variables if it is not already done
             ! =============
+            ! trick: is defined to 0 => dimension variable are defined but not yet written
             IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN
                CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lon'     , idmy ), clinfo)
@@ -443,4 +444,10 @@
                CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'time_counter', idmy ), clinfo)
                CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, kt                      ), clinfo)   
+               ! update the values of the variables dimensions size
+               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 1, len = iom_file(kiomid)%dimsz(1,1) ), clinfo)
+               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 2, len = iom_file(kiomid)%dimsz(2,1) ), clinfo)
+               iom_file(kiomid)%dimsz(1:2, 2) = iom_file(kiomid)%dimsz(1:2, 1)
+               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 3, len = iom_file(kiomid)%dimsz(1,3) ), clinfo)
+               iom_file(kiomid)%dimsz(1  , 4) = 1   ! unlimited dimension
                IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done'
             ENDIF
Index: /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_rstdimg.F90
===================================================================
--- /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_rstdimg.F90	(revision 950)
+++ /branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_rstdimg.F90	(revision 951)
@@ -31,7 +31,10 @@
       MODULE PROCEDURE iom_rstdimg_rp0d, iom_rstdimg_rp123d
    END INTERFACE
+
+   INTEGER, PARAMETER ::   jpvnl          = 32   ! variable name length
+      
    !!----------------------------------------------------------------------
    !!  OPA 9.0 , LOCEAN-IPSL (2006)
-   !! $Header$
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_rstdimg.F90,v 1.9 2007/06/29 14:10:50 opalod Exp $
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -45,9 +48,9 @@
       !! ** Purpose :  open an input file read only (return 0 if not found)
       !!---------------------------------------------------------------------
-      CHARACTER(len=*)       , INTENT(inout) ::   cdname   ! File name
-      INTEGER                , INTENT(  out) ::   kiomid   ! iom identifier of the opened file
-      LOGICAL                , INTENT(in   ) ::   ldwrt    ! read or write the file?
-      LOGICAL                , INTENT(in   ) ::   ldok     ! check the existence 
-      INTEGER, DIMENSION(2,5), INTENT(in   ) ::   kdompar  ! domain parameters: 
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname   ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt    ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok     ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar  ! domain parameters: 
 
       CHARACTER(LEN=100)                      ::   clinfo                     ! info character
@@ -59,4 +62,5 @@
       INTEGER                                 ::   irecl8                     ! record length
       INTEGER                                 ::   ios                        ! IO status
+      INTEGER                                 ::   irhd                       ! record of the header infos
       INTEGER                                 ::   ivnum                      ! number of variables
       INTEGER                                 ::   ishft                      ! counter shift
@@ -64,9 +68,10 @@
       INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables
       INTEGER                                 ::   ipni, ipnj, ipnij, iarea   ! domain decomposition 
-      CHARACTER(LEN=8), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables
+      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
       REAL(wp),         DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record
       !                                                                               ! position for 1/2/3D variables
       !---------------------------------------------------------------------
-
       clinfo = '                    iom_rstdimg_open ~~~  '
       istop = nstop      ! store the actual value of nstop
@@ -99,7 +104,7 @@
          iln = INDEX( cdname, '.dimg' )
          IF( ldwrt ) THEN  ! the file should be open in readwrite mode so we create it...
-            irecl8= kdompar(1,1) * kdompar(2,1) * wp
+            irecl8= MAX( kdompar(1,1) * kdompar(2,1) * wp, ( 8*jpnij + 15 ) * 4 )
             IF( jpnij > 1 ) THEN
-               WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea-1, '.dimg'
+               WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea, '.dimg'
                cdname = TRIM(cltmp)
             ENDIF
@@ -108,5 +113,5 @@
                &       , RECL = irecl8, STATUS = 'new', ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
          ELSE              ! the file should be open for read mode so it must exist...
-            CALL ctl_stop( TRIM(clinfo), 'File '//cdname(1:iln-1)//'* not found' )
+            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
          ENDIF
       ENDIF
@@ -114,12 +119,17 @@
       ! =============
       IF( ldok ) THEN      ! old file
-         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz, in0d, in1d, in2d, in3d
-         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz, in0d, in1d, in2d, in3d,   &
+         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( ldwrt ) THEN
+            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' )
+         ENDIF
          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' )
@@ -131,5 +141,9 @@
       ! =============
       IF( istop == nstop ) THEN   ! no error within this routine
-         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+         kiomid = 0
+         DO jl = jpmax_files, 1, -1
+            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
+         ENDDO
          iom_file(kiomid)%name    = TRIM(cdname)
          iom_file(kiomid)%nfid    = idrst
@@ -209,10 +223,11 @@
       INTEGER                                 ::   irecl8                     ! record length
       INTEGER                                 ::   ios                        ! IO status
+      INTEGER                                 ::   irhd                       ! record of the header infos
       INTEGER                                 ::   ivnum                      ! number of variables
       INTEGER                                 ::   idrst                      ! file logical unit
       INTEGER                                 ::   inx, iny, inz              ! x,y,z dimension of the variable
       INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables
-      CHARACTER(LEN=8), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables
-      REAL(wp),         DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record
+      CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d    ! name of 0/1/2/3D variables
+      REAL(wp),          DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d    ! value of 0d variables or record
       !                                                                               ! position for 1/2/3D variables
       !---------------------------------------------------------------------
@@ -226,4 +241,5 @@
       IF( ios == 0 ) THEN
          READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz   ! get back domain size
+         irhd = iom_file(kiomid)%irec
          ivnum = iom_file(kiomid)%nvars
          in0d = 0   ;   in1d = 0   ;   in2d = 0   ;   in3d = 0
@@ -249,5 +265,5 @@
             END SELECT
          END DO
-         ! force to have at least 1 valriable in each list (not necessary (?), but safer)
+         ! force to have at least 1 variable in each list (not necessary (?), but safer...)
          IF( in0d == 0 ) THEN   ;   in0d = 1   ;   clna0d(1) = 'no0d'   ;   zval0d(1) = -1.   ;   ENDIF
          IF( in1d == 0 ) THEN   ;   in1d = 1   ;   clna1d(1) = 'no1d'   ;   zval1d(1) = -1.   ;   ENDIF
@@ -255,8 +271,16 @@
          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 ) irecl8, inx, iny, inz, in0d, in1d, in2d, in3d,   &
-            &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   &
-            &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d),   &
-            &   jpni, jpnj, jpnij, narea, jpiglo, jpjglo, nlcit, nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+         WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 )              &
+            &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
+            &   jpni, jpnj, jpnij, narea, jpiglo, jpjglo,              &
+            &   nlcit, nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+         IF( (ivnum * (jpvnl + wp)) > irecl8 ) THEN 
+            CALL ctl_stop( TRIM(clinfo),   &
+                 &   'Last record size is too big... You could reduce the value of jpvnl' )
+         ELSE 
+            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)
+         ENDIF
       ELSE
          ios = 0   ! we cannot write in the file
@@ -290,5 +314,5 @@
 
 
-   SUBROUTINE iom_rstdimg_rp0d( kiomid, cdvar, pv_r0d )
+   SUBROUTINE iom_rstdimg_rp0d( kiomid, cdvar, kvid, pv_r0d )
       !!--------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_rstdimg_rstput  ***
@@ -298,4 +322,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
       !
@@ -305,5 +330,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
@@ -320,6 +349,6 @@
 
 
-   SUBROUTINE iom_rstdimg_g123d( kiomid, kdom  , kvid  , kstart, kcount,    &
-         &                          pv_r1d, pv_r2d, pv_r3d )
+   SUBROUTINE iom_rstdimg_g123d( kiomid, kdom  , kvid, kx1, kx2, ky1, ky2,   &
+         &                       pv_r1d, pv_r2d, pv_r3d )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_rstdimg_g123d  ***
@@ -332,6 +361,5 @@
       INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
       INTEGER                    , INTENT(in   )           ::   kvid       ! variable id
-      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kstart     ! start position of the reading in each axis 
-      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kcount     ! number of points to be read in each axis
+      INTEGER ,                    INTENT(inout)           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
       REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
       REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
@@ -342,60 +370,31 @@
       INTEGER            ::   jk                   ! loop counter
       INTEGER            ::   idrst                ! logical unit of the restart file
-      INTEGER            ::   istop                ! temporary storage of nstop
-      INTEGER            ::   ix1, ix2, iy1, iy2   ! subdomain indexes
       !---------------------------------------------------------------------
       clinfo = '                    iom_rstdimg_g123d ~~~  '
       !
-      istop = nstop                   ! store the actual value of nstop
-      idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
-      IF( kdom == jpdom_data .OR. kdom == jpdom_global )   &
-            &   CALL ctl_stop( TRIM(clinfo), TRIM(iom_file(kiomid)%cn_var(kvid))//': case not coded for rstdimg files' )
-      !
-      IF( istop == nstop .AND. kvid > 0 ) THEN
-         IF( .NOT. PRESENT(pv_r1d) ) THEN
-            SELECT CASE (kdom)   ! find the right index of the array to be read
-            CASE (jpdom_local_full)      ;   ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
-            CASE (jpdom_local_noextra)   ;   ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj
-            CASE (jpdom_local_noovlap)   ;   ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
-            CASE DEFAULT                 ;   CALL ctl_stop( clinfo, 'we should not be there...' )
-            END SELECT
-         ENDIF
+      IF( kdom == jpdom_data .OR. kdom == jpdom_global ) THEN
+         CALL ctl_stop( TRIM(clinfo), TRIM(iom_file(kiomid)%cn_var(kvid))//': case not coded for rstdimg files' )
+      ELSE
+      !
+         idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
+         ! modify the subdomain indexes because we cannot directly extract the appropriate subdomaine
+         IF(     kdom == jpdom_local_full    ) THEN   ;   kx1 = 1   ;   kx2 = jpi    ;   ky1 = 1
+         ELSEIF( kdom == jpdom_local_noextra ) THEN   ;   kx1 = 1   ;   kx2 = nlci   ;   ky1 = 1
+         ENDIF
+         !
          IF(     PRESENT(pv_r1d) ) THEN   ! read 1D variables
-            READ( idrst, REC = iom_file(kiomid)%nvid(kvid), IOSTAT = ios, ERR = 987 )   pv_r1d(:)
+            READ(    idrst, REC = iom_file(kiomid)%nvid(kvid)         , IOSTAT = ios, ERR = 987 )   pv_r1d(:)
          ELSEIF( PRESENT(pv_r2d) ) THEN   ! read 2D variables
-            READ( idrst, REC = iom_file(kiomid)%nvid(kvid), IOSTAT = ios, ERR = 987 )   pv_r2d(ix1:ix2, iy1:iy2 )
-            SELECT CASE (kdom)
-            CASE (jpdom_local_noextra)   !--- Fill extra hallows (mpp)       
-               pv_r2d(nlci+1:jpi,      :   ) = 1.    
-               pv_r2d(      :   ,nlcj+1:jpj) = 1.            
-            CASE (jpdom_local_noovlap)   !--- Fill the overlap areas and extra hallows (mpp)
-               CALL lbc_lnk (pv_r2d,'Z',-999.,'no0')
-            CASE DEFAULT
-            END SELECT
+            READ(    idrst, REC = iom_file(kiomid)%nvid(kvid)         , IOSTAT = ios, ERR = 987 )   pv_r2d(kx1:kx2, ky1:ky2    )
          ELSEIF( PRESENT(pv_r3d) ) THEN   ! read 3D variables
             DO jk = 1, iom_file(kiomid)%dimsz(3,kvid)   ! do loop on each level
-               READ( idrst, REC = iom_file(kiomid)%nvid(kvid) + jk - 1, IOSTAT = ios, ERR = 987 )   &
-                     &      pv_r3d( ix1:ix2, iy1:iy2, jk )
-            END DO
-            SELECT CASE (kdom)
-            CASE (jpdom_local_noextra)   !--- Fill extra hallows (mpp)       
-               pv_r3d(nlci+1:jpi,      :   ,:) = 1.    
-               pv_r3d(      :   ,nlcj+1:jpj,:) = 1.            
-            CASE (jpdom_local_noovlap)   !--- Fill the overlap areas and extra hallows (mpp)
-               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
-               IF( kcount(3) == jpk ) THEN
-                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
-               ELSE
-                  pv_r3d(nlei+1:jpi,      :   ,:) = 1.            
-                  pv_r3d(      :   ,nlej+1:jpj,:) = 1.            
-               ENDIF
-            CASE DEFAULT
-            END SELECT
-         ENDIF
-      ENDIF
-987   CONTINUE
-      IF( ios /= 0 ) THEN
-         WRITE(ctmp1,*) '           iostat = ', ios
-         CALL ctl_stop( TRIM(clinfo), '   IO error with file '//TRIM(iom_file(kiomid)%name), ctmp1 )
+               READ( idrst, REC = iom_file(kiomid)%nvid(kvid) + jk - 1, IOSTAT = ios, ERR = 987 )   pv_r3d(kx1:kx2, ky1:ky2, jk)
+            END DO
+         ENDIF
+987      CONTINUE
+         IF( ios /= 0 ) THEN
+            WRITE(ctmp1,*) '           iostat = ', ios
+            CALL ctl_stop( TRIM(clinfo), '   IO error with file '//TRIM(iom_file(kiomid)%name), ctmp1 )
+         ENDIF
       ENDIF
       !
@@ -403,5 +402,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  ***
@@ -411,4 +410,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
@@ -431,5 +431,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
