Index: branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_ioipsl.F90
===================================================================
--- branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_ioipsl.F90	(revision 740)
+++ 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
