Index: trunk/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90
===================================================================
--- trunk/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 5836)
+++ trunk/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 6140)
@@ -4,9 +4,7 @@
    !! Ocean forcing:  read input field for surface boundary condition
    !!=====================================================================
-   !! History :  2.0  !  06-2006  (S. Masson, G. Madec) Original code
-   !!                 !  05-2008  (S. Alderson) Modified for Interpolation in memory
-   !!                 !                         from input grid to model grid
-   !!                 !  10-2013  (D. Delrosso, P. Oddo) implement suppression of 
-   !!                 !                         land point prior to interpolation
+   !! History :  2.0  !  06-2006  (S. Masson, G. Madec)  Original code
+   !!                 !  05-2008  (S. Alderson)  Modified for Interpolation in memory from input grid to model grid
+   !!                 !  10-2013  (D. Delrosso, P. Oddo)  suppression of land point prior to interpolation
    !!----------------------------------------------------------------------
 
@@ -15,15 +13,16 @@
    !!                   surface boundary condition
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! ???
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE geo2ocean       ! for vector rotation on to model grid
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE lbclnk          ! ocean lateral boundary conditions (C1D case)
-   USE ioipsl, ONLY :   ymds2ju, ju2ymds   ! for calendar
-   USE sbc_oce
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constant
+   USE sbc_oce        ! surface boundary conditions : fields
+   USE geo2ocean      ! for vector rotation on to model grid
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE ioipsl  , ONLY : ymds2ju, ju2ymds   ! for calendar
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! work arrays
+   USE lbclnk         ! ocean lateral boundary conditions (C1D case)
    
    IMPLICIT NONE
@@ -60,6 +59,6 @@
       INTEGER , DIMENSION(2)          ::   nrec_b       ! before record (1: index, 2: second since Jan. 1st 00h of nit000 year)
       INTEGER , DIMENSION(2)          ::   nrec_a       ! after  record (1: index, 2: second since Jan. 1st 00h of nit000 year)
-      REAL(wp) , ALLOCATABLE, DIMENSION(:,:,:  ) ::   fnow       ! input fields interpolated to now time step
-      REAL(wp) , ALLOCATABLE, DIMENSION(:,:,:,:) ::   fdta       ! 2 consecutive record of input fields
+      REAL(wp) , ALLOCATABLE, DIMENSION(:,:,:  ) ::   fnow   ! input fields interpolated to now time step
+      REAL(wp) , ALLOCATABLE, DIMENSION(:,:,:,:) ::   fdta   ! 2 consecutive record of input fields
       CHARACTER(len = 256)            ::   wgtname      ! current name of the NetCDF weight file acting as a key
       !                                                 ! into the WGTLIST structure
@@ -133,22 +132,21 @@
       INTEGER  , INTENT(in   ), OPTIONAL     ::   kit       ! subcycle timestep for timesplitting option
       INTEGER  , INTENT(in   ), OPTIONAL     ::   kt_offset ! provide fields at time other than "now"
-                                                            !   kt_offset = -1 => fields at "before" time level
-                                                            !   kt_offset = +1 => fields at "after"  time level
-                                                            !   etc.
-      !!
-      INTEGER  ::   itmp       ! temporary variable
-      INTEGER  ::   imf        ! size of the structure sd
-      INTEGER  ::   jf         ! dummy indices
-      INTEGER  ::   isecend    ! number of second since Jan. 1st 00h of nit000 year at nitend
-      INTEGER  ::   isecsbc    ! number of seconds between Jan. 1st 00h of nit000 year and the middle of sbc time step
-      INTEGER  ::   it_offset  ! local time offset variable
-      LOGICAL  ::   llnxtyr    ! open next year  file?
-      LOGICAL  ::   llnxtmth   ! open next month file?
-      LOGICAL  ::   llstop     ! stop is the file does not exist
+      !                                                     !   kt_offset = -1 => fields at "before" time level
+      !                                                     !   kt_offset = +1 => fields at "after"  time level
+      !                                                     !   etc.
+      INTEGER  ::   itmp         ! local variable
+      INTEGER  ::   imf          ! size of the structure sd
+      INTEGER  ::   jf           ! dummy indices
+      INTEGER  ::   isecend      ! number of second since Jan. 1st 00h of nit000 year at nitend
+      INTEGER  ::   isecsbc      ! number of seconds between Jan. 1st 00h of nit000 year and the middle of sbc time step
+      INTEGER  ::   it_offset    ! local time offset variable
+      LOGICAL  ::   llnxtyr      ! open next year  file?
+      LOGICAL  ::   llnxtmth     ! open next month file?
+      LOGICAL  ::   llstop       ! stop is the file does not exist
       LOGICAL  ::   ll_firstcall ! true if this is the first call to fld_read for this set of fields
-      REAL(wp) ::   ztinta     ! ratio applied to after  records when doing time interpolation
-      REAL(wp) ::   ztintb     ! ratio applied to before records when doing time interpolation
-      CHARACTER(LEN=1000) ::   clfmt   ! write format
-      TYPE(MAP_POINTER) ::   imap   ! global-to-local mapping indices
+      REAL(wp) ::   ztinta       ! ratio applied to after  records when doing time interpolation
+      REAL(wp) ::   ztintb       ! ratio applied to before records when doing time interpolation
+      CHARACTER(LEN=1000) ::   clfmt  ! write format
+      TYPE(MAP_POINTER)   ::   imap   ! global-to-local mapping indices
       !!---------------------------------------------------------------------
       ll_firstcall = kt == nit000
@@ -166,5 +164,5 @@
          isecsbc = nsec_year + nsec1jan000 + (kit+it_offset)*NINT( rdt/REAL(nn_baro,wp) )
       ELSE                      ! middle of sbc time step
-         isecsbc = nsec_year + nsec1jan000 + NINT(0.5 * REAL(kn_fsbc - 1,wp) * rdttra(1)) + it_offset * NINT(rdttra(1))
+         isecsbc = nsec_year + nsec1jan000 + NINT(0.5 * REAL(kn_fsbc - 1,wp) * rdt) + it_offset * NINT(rdt)
       ENDIF
       imf = SIZE( sd )
@@ -193,5 +191,5 @@
                CALL fld_rec( kn_fsbc, sd(jf), kt_offset = it_offset, kit = kit )    ! update after record informations
 
-               ! if kn_fsbc*rdttra is larger than nfreqh (which is kind of odd),
+               ! if kn_fsbc*rdt is larger than nfreqh (which is kind of odd),
                ! it is possible that the before value is no more the good one... we have to re-read it
                ! if before is not the last record of the file currently opened and after is the first record to be read
@@ -214,5 +212,5 @@
                IF( sd(jf)%ln_tint ) THEN
                   
-                  ! if kn_fsbc*rdttra is larger than nfreqh (which is kind of odd),
+                  ! if kn_fsbc*rdt is larger than nfreqh (which is kind of odd),
                   ! it is possible that the before value is no more the good one... we have to re-read it
                   ! if before record is not just just before the after record...
@@ -245,5 +243,5 @@
                         ! year/month/week/day file to be not present. If the run continue further than the current
                         ! year/month/week/day, next year/month/week/day file must exist
-                        isecend = nsec_year + nsec1jan000 + (nitend - kt) * NINT(rdttra(1))   ! second at the end of the run 
+                        isecend = nsec_year + nsec1jan000 + (nitend - kt) * NINT(rdt)   ! second at the end of the run
                         llstop = isecend > sd(jf)%nrec_a(2)                                   ! read more than 1 record of next year
                         ! we suppose that the date of next file is next day (should be ok even for weekly files...)
@@ -299,7 +297,5 @@
          END DO                                    ! --- end loop over field --- !
          !
-         !                                         ! ====================================== !
-      ENDIF                                        ! update field at each kn_fsbc time-step !
-      !                                            ! ====================================== !
+      ENDIF
       !
    END SUBROUTINE fld_read
@@ -333,12 +329,12 @@
       llprevday  = .FALSE.
       isec_week  = 0
-            
+      !
       ! define record informations
       CALL fld_rec( kn_fsbc, sdjf, ldbefore = .TRUE. )  ! return before values in sdjf%nrec_a (as we will swap it later)
-
+      !
       ! Note that shifting time to be centrered in the middle of sbc time step impacts only nsec_* variables of the calendar 
-
+      !
       IF( sdjf%ln_tint ) THEN ! we need to read the previous record and we will put it in the current record structure
-
+         !
          IF( sdjf%nrec_a(1) == 0  ) THEN   ! we redefine record sdjf%nrec_a(1) with the last record of previous year file
             IF    ( sdjf%nfreqh == -12 ) THEN   ! yearly mean
@@ -391,5 +387,5 @@
          !
          CALL fld_clopn( sdjf, iyear, imonth, iday, .NOT. llprev )
-
+         !
          ! if previous year/month/day file does not exist, we switch to the current year/month/day
          IF( llprev .AND. sdjf%num <= 0 ) THEN
@@ -401,5 +397,5 @@
             CALL fld_clopn( sdjf )
          ENDIF
-         
+         !
          IF( llprev ) THEN   ! check if the record sdjf%nrec_a(1) exists in the file
             idvar = iom_varid( sdjf%num, sdjf%clvar )                                        ! id of the variable sdjf%clvar
@@ -408,11 +404,10 @@
             sdjf%nrec_a(1) = MIN( sdjf%nrec_a(1), inrec )   ! make sure we select an existing record
          ENDIF
-
-         ! read before data in after arrays(as we will swap it later)
-         CALL fld_get( sdjf, map )
-
+         !
+         CALL fld_get( sdjf, map )         ! read before data in after arrays(as we will swap it later)
+         !
          clfmt = "('fld_init : time-interpolation for ', a, ' read previous record = ', i6, ' at time = ', f7.2, ' days')"
          IF(lwp) WRITE(numout, clfmt) TRIM(sdjf%clvar), sdjf%nrec_a(1), REAL(sdjf%nrec_a(2),wp)/rday
-
+         !
       ENDIF
       !
@@ -435,8 +430,8 @@
       LOGICAL  , INTENT(in   ), OPTIONAL ::   ldbefore  ! sent back before record values (default = .FALSE.)
       INTEGER  , INTENT(in   ), OPTIONAL ::   kit       ! index of barotropic subcycle
-                                                        ! used only if sdjf%ln_tint = .TRUE.
+      !                                                 ! used only if sdjf%ln_tint = .TRUE.
       INTEGER  , INTENT(in   ), OPTIONAL ::   kt_offset ! Offset of required time level compared to "now"
-                                                        !   time level in units of time steps.
-      !!
+      !                                                 !   time level in units of time steps.
+      !
       LOGICAL  ::   llbefore    ! local definition of ldbefore
       INTEGER  ::   iendrec     ! end of this record (in seconds)
@@ -459,5 +454,5 @@
       IF( PRESENT(kt_offset) )   it_offset = kt_offset
       IF( PRESENT(kit) ) THEN   ;   it_offset = ( kit + it_offset ) * NINT( rdt/REAL(nn_baro,wp) )
-      ELSE                      ;   it_offset =         it_offset   * NINT(       rdttra(1)      )
+      ELSE                      ;   it_offset =         it_offset   * NINT(       rdt            )
       ENDIF
       !
@@ -536,6 +531,6 @@
          ELSE                                           ;   ztmp = REAL(nsec_year ,wp)  ! since 00h on Jan 1 of the current year
          ENDIF
-         ztmp = ztmp + 0.5 * REAL(kn_fsbc - 1, wp) * rdttra(1) + REAL( it_offset, wp )  ! centrered in the middle of sbc time step
-         ztmp = ztmp + 0.01 * rdttra(1)                                                 ! avoid truncation error 
+         ztmp = ztmp + 0.5 * REAL(kn_fsbc - 1, wp) * rdt + REAL( it_offset, wp )        ! centrered in the middle of sbc time step
+         ztmp = ztmp + 0.01 * rdt                                                       ! avoid truncation error 
          IF( sdjf%ln_tint ) THEN                ! time interpolation, shift by 1/2 record
             !
@@ -592,13 +587,13 @@
       !! ** Purpose :   read the data
       !!----------------------------------------------------------------------
-      TYPE(FLD), INTENT(inout) ::   sdjf   ! input field related variables
-      TYPE(MAP_POINTER),INTENT(in) ::   map   ! global-to-local mapping indices
-      !!
-      INTEGER                  ::   ipk    ! number of vertical levels of sdjf%fdta ( 2D: ipk=1 ; 3D: ipk=jpk )
-      INTEGER                  ::   iw     ! index into wgts array
-      INTEGER                  ::   ipdom  ! index of the domain
-      INTEGER                  ::   idvar  ! variable ID
-      INTEGER                  ::   idmspc ! number of spatial dimensions
-      LOGICAL                  ::   lmoor  ! C1D case: point data
+      TYPE(FLD)        , INTENT(inout) ::   sdjf   ! input field related variables
+      TYPE(MAP_POINTER), INTENT(in   ) ::   map    ! global-to-local mapping indices
+      !
+      INTEGER ::   ipk      ! number of vertical levels of sdjf%fdta ( 2D: ipk=1 ; 3D: ipk=jpk )
+      INTEGER ::   iw       ! index into wgts array
+      INTEGER ::   ipdom    ! index of the domain
+      INTEGER ::   idvar    ! variable ID
+      INTEGER ::   idmspc   ! number of spatial dimensions
+      LOGICAL ::   lmoor    ! C1D case: point data
       !!---------------------------------------------------------------------
       !
@@ -611,19 +606,19 @@
       ELSE IF( LEN(TRIM(sdjf%wgtname)) > 0 ) THEN
          CALL wgt_list( sdjf, iw )
-         IF( sdjf%ln_tint ) THEN   ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw , ipk  , sdjf%fdta(:,:,:,2), & 
-              & sdjf%nrec_a(1), sdjf%lsmname )
-         ELSE                      ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw , ipk  , sdjf%fnow(:,:,:  ), &
-              & sdjf%nrec_a(1), sdjf%lsmname )
+         IF( sdjf%ln_tint ) THEN   ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw, ipk, sdjf%fdta(:,:,:,2),          & 
+            &                                                                          sdjf%nrec_a(1), sdjf%lsmname )
+         ELSE                      ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw, ipk, sdjf%fnow(:,:,:  ),          &
+            &                                                                          sdjf%nrec_a(1), sdjf%lsmname )
          ENDIF
       ELSE
-         IF( SIZE(sdjf%fnow, 1) == jpi ) THEN  ;  ipdom = jpdom_data
-         ELSE                                  ;  ipdom = jpdom_unknown
+         IF( SIZE(sdjf%fnow, 1) == jpi ) THEN   ;   ipdom = jpdom_data
+         ELSE                                   ;   ipdom = jpdom_unknown
          ENDIF
          ! C1D case: If product of spatial dimensions == ipk, then x,y are of
          ! size 1 (point/mooring data): this must be read onto the central grid point
          idvar  = iom_varid( sdjf%num, sdjf%clvar )
-         idmspc = iom_file( sdjf%num )%ndims( idvar )
+         idmspc = iom_file ( sdjf%num )%ndims( idvar )
          IF( iom_file( sdjf%num )%luld( idvar ) )   idmspc = idmspc - 1
-         lmoor  = (idmspc == 0 .OR. PRODUCT( iom_file( sdjf%num )%dimsz( 1:MAX(idmspc,1) ,idvar ) ) == ipk)
+         lmoor  = (  idmspc == 0 .OR. PRODUCT( iom_file( sdjf%num )%dimsz( 1:MAX(idmspc,1) ,idvar ) ) == ipk  )
          !
          SELECT CASE( ipk )
@@ -660,6 +655,7 @@
       !
       sdjf%rotn(2) = .false.   ! vector not yet rotated
-
+      !
    END SUBROUTINE fld_get
+
 
    SUBROUTINE fld_map( num, clvar, dta, nrec, map )
@@ -688,9 +684,9 @@
       REAL(wp), POINTER, DIMENSION(:,:,:)     ::   dta_read  ! work space for global data
       !!---------------------------------------------------------------------
-            
+      !
       ipi = SIZE( dta, 1 )
       ipj = 1
       ipk = SIZE( dta, 3 )
-
+      !
       idvar   = iom_varid( num, clvar )
       ilendta = iom_file(num)%dimsz(1,idvar)
@@ -698,14 +694,14 @@
 #if defined key_bdy
       ipj = iom_file(num)%dimsz(2,idvar)
-      IF ( map%ll_unstruc) THEN ! unstructured open boundary data file
+      IF( map%ll_unstruc) THEN   ! unstructured open boundary data file
          dta_read => dta_global
-      ELSE                      ! structured open boundary data file
+      ELSE                       ! structured open boundary data file
          dta_read => dta_global2
       ENDIF
 #endif
 
-      IF(lwp) WRITE(numout,*) 'Dim size for ',TRIM(clvar),' is ', ilendta
+      IF(lwp) WRITE(numout,*) 'Dim size for ',        TRIM(clvar),' is ', ilendta
       IF(lwp) WRITE(numout,*) 'Number of levels for ',TRIM(clvar),' is ', ipk
-
+      !
       SELECT CASE( ipk )
       CASE(1)        ;   CALL iom_get ( num, jpdom_unknown, clvar, dta_read(1:ilendta,1:ipj,1    ), nrec )
@@ -713,5 +709,5 @@
       END SELECT
       !
-      IF ( map%ll_unstruc ) THEN ! unstructured open boundary data file
+      IF( map%ll_unstruc ) THEN  ! unstructured open boundary data file
          DO ib = 1, ipi
             DO ik = 1, ipk
@@ -728,5 +724,5 @@
          END DO
       ENDIF
-
+      !
    END SUBROUTINE fld_map
 
@@ -738,17 +734,17 @@
       !! ** Purpose :   Vector fields may need to be rotated onto the local grid direction
       !!----------------------------------------------------------------------
-      INTEGER  , INTENT(in   )               ::   kt        ! ocean time step
-      TYPE(FLD), INTENT(inout), DIMENSION(:) ::   sd        ! input field related variables
-      !!
-      INTEGER                           ::   ju,jv,jk,jn  ! loop indices
-      INTEGER                           ::   imf          ! size of the structure sd
-      INTEGER                           ::   ill          ! character length
-      INTEGER                           ::   iv           ! indice of V component
+      INTEGER                , INTENT(in   ) ::   kt   ! ocean time step
+      TYPE(FLD), DIMENSION(:), INTENT(inout) ::   sd   ! input field related variables
+      !
+      INTEGER ::   ju, jv, jk, jn  ! loop indices
+      INTEGER ::   imf             ! size of the structure sd
+      INTEGER ::   ill             ! character length
+      INTEGER ::   iv              ! indice of V component
+      CHARACTER (LEN=100)               ::   clcomp       ! dummy weight name
       REAL(wp), POINTER, DIMENSION(:,:) ::   utmp, vtmp   ! temporary arrays for vector rotation
-      CHARACTER (LEN=100)               ::   clcomp       ! dummy weight name
-      !!---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj, utmp, vtmp )
-
+      !!---------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi,jpj,   utmp, vtmp )
+      !
       !! (sga: following code should be modified so that pairs arent searched for each time
       !
@@ -786,5 +782,5 @@
        END DO
       !
-      CALL wrk_dealloc( jpi,jpj, utmp, vtmp )
+      CALL wrk_dealloc( jpi,jpj,   utmp, vtmp )
       !
    END SUBROUTINE fld_rot
@@ -802,5 +798,5 @@
       INTEGER, OPTIONAL, INTENT(in   ) ::   kday     ! day value
       LOGICAL, OPTIONAL, INTENT(in   ) ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
-      !!
+      !
       LOGICAL :: llprevyr              ! are we reading previous year  file?
       LOGICAL :: llprevmth             ! are we reading previous month file?
@@ -853,9 +849,9 @@
       !
       IF( TRIM(clname) /= TRIM(sdjf%clname) .OR. sdjf%num == 0 ) THEN   ! new file to be open 
-
+         !
          sdjf%clname = TRIM(clname)
          IF( sdjf%num /= 0 )   CALL iom_close( sdjf%num )   ! close file if already open
          CALL iom_open( sdjf%clname, sdjf%num, ldstop = ldstop, ldiof =  LEN(TRIM(sdjf%wgtname)) > 0 )
-
+         !
          ! find the last record to be read -> update sdjf%nreclast
          indexyr = iyear - nyear + 1
@@ -866,5 +862,5 @@
          CASE ( 2 )   ;   imonth_len = 31   ! next     year -> imonth = 1
          END SELECT
-         
+         !
          ! last record to be read in the current file
          IF    ( sdjf%nfreqh == -12 ) THEN                 ;   sdjf%nreclast = 1    !  yearly mean
@@ -880,5 +876,5 @@
             ENDIF
          ENDIF
-         
+         !
       ENDIF
       !
@@ -901,5 +897,5 @@
       INTEGER  ::   jf       ! dummy indices
       !!---------------------------------------------------------------------
-
+      !
       DO jf = 1, SIZE(sdf)
          sdf(jf)%clrootname = TRIM( cdir )//TRIM( sdf_n(jf)%clname )
@@ -923,5 +919,5 @@
          sdf(jf)%nreclast = -1 ! Set to non zero default value to avoid errors, is updated to meaningful value during fld_clopn
       END DO
-
+      !
       IF(lwp) THEN      ! control print
          WRITE(numout,*)
@@ -943,5 +939,5 @@
          END DO
       ENDIF
-      
+      !
    END SUBROUTINE fld_fill
 
@@ -958,5 +954,5 @@
       TYPE( FLD ), INTENT(in   ) ::   sd        ! field with name of weights file
       INTEGER    , INTENT(inout) ::   kwgt      ! index of weights
-      !!
+      !
       INTEGER ::   kw, nestid   ! local integer
       LOGICAL ::   found        ! local logical
@@ -966,5 +962,5 @@
       !! weights filename is either present or we hit the end of the list
       found = .FALSE.
-
+      !
       !! because agrif nest part of filenames are now added in iom_open
       !! to distinguish between weights files on the different grids, need to track
@@ -1028,18 +1024,18 @@
       TYPE( FLD ), INTENT(in) ::   sd   ! field with name of weights file
       !!
-      INTEGER                           ::   jn            ! dummy loop indices
-      INTEGER                           ::   inum          ! temporary logical unit
-      INTEGER                           ::   id            ! temporary variable id
-      INTEGER                           ::   ipk           ! temporary vertical dimension
-      CHARACTER (len=5)                 ::   aname
+      INTEGER ::   jn         ! dummy loop indices
+      INTEGER ::   inum       ! local logical unit
+      INTEGER ::   id         ! local variable id
+      INTEGER ::   ipk        ! local vertical dimension
+      INTEGER ::   zwrap      ! local integer
+      LOGICAL ::   cyclical   ! 
+      CHARACTER (len=5) ::   aname   !
       INTEGER , DIMENSION(:), ALLOCATABLE ::   ddims
       INTEGER , POINTER, DIMENSION(:,:) ::   data_src
       REAL(wp), POINTER, DIMENSION(:,:) ::   data_tmp
-      LOGICAL                           ::   cyclical
-      INTEGER                           ::   zwrap      ! local integer
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi,jpj, data_src )   ! integer
-      CALL wrk_alloc( jpi,jpj, data_tmp )
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi,jpj,   data_src )   ! integer
+      CALL wrk_alloc( jpi,jpj,   data_tmp )
       !
       IF( nxt_wgt > tot_wgts ) THEN
@@ -1151,7 +1147,7 @@
          ALLOCATE( ref_wgts(nxt_wgt)%fly_dta(ref_wgts(nxt_wgt)%jpiwgt+3, ref_wgts(nxt_wgt)%jpjwgt+3 ,ipk) )
          IF( ref_wgts(nxt_wgt)%cyclic ) ALLOCATE( ref_wgts(nxt_wgt)%col(1,ref_wgts(nxt_wgt)%jpjwgt+3,ipk) )
-
+         !
          nxt_wgt = nxt_wgt + 1
-
+         !
       ELSE 
          CALL ctl_stop( '    fld_weight : unable to read the file ' )
@@ -1166,6 +1162,6 @@
 
 
-   SUBROUTINE apply_seaoverland(clmaskfile,zfieldo,jpi1_lsm,jpi2_lsm,jpj1_lsm, &
-                          &      jpj2_lsm,itmpi,itmpj,itmpz,rec1_lsm,recn_lsm)
+   SUBROUTINE apply_seaoverland( clmaskfile, zfieldo, jpi1_lsm, jpi2_lsm, jpj1_lsm,   &
+                          &      jpj2_lsm, itmpi, itmpj, itmpz, rec1_lsm, recn_lsm )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE apply_seaoverland  ***
@@ -1176,67 +1172,61 @@
       !!      D. Delrosso INGV          
       !!---------------------------------------------------------------------- 
-      INTEGER                                   :: inum,jni,jnj,jnz,jc                  ! temporary indices
-      INTEGER,                   INTENT(in)     :: itmpi,itmpj,itmpz                    ! lengths
-      INTEGER,                   INTENT(in)     :: jpi1_lsm,jpi2_lsm,jpj1_lsm,jpj2_lsm  ! temporary indices
-      INTEGER, DIMENSION(3),     INTENT(in)     :: rec1_lsm,recn_lsm                    ! temporary arrays for start and length
-      REAL(wp),DIMENSION (:,:,:),INTENT(inout)  :: zfieldo                              ! input/output array for seaoverland application
-      REAL(wp),DIMENSION (:,:,:),ALLOCATABLE    :: zslmec1                              ! temporary array for land point detection
-      REAL(wp),DIMENSION (:,:),  ALLOCATABLE    :: zfieldn                              ! array of forcing field with undeff for land points
-      REAL(wp),DIMENSION (:,:),  ALLOCATABLE    :: zfield                               ! array of forcing field
-      CHARACTER (len=100),       INTENT(in)     :: clmaskfile                           ! land/sea mask file name
-      !!---------------------------------------------------------------------
-      ALLOCATE ( zslmec1(itmpi,itmpj,itmpz) )
-      ALLOCATE ( zfieldn(itmpi,itmpj) )
-      ALLOCATE ( zfield(itmpi,itmpj) )
-
+      INTEGER,                   INTENT(in   ) :: itmpi,itmpj,itmpz                    ! lengths
+      INTEGER,                   INTENT(in   ) :: jpi1_lsm,jpi2_lsm,jpj1_lsm,jpj2_lsm  ! temporary indices
+      INTEGER, DIMENSION(3),     INTENT(in   ) :: rec1_lsm,recn_lsm                    ! temporary arrays for start and length
+      REAL(wp),DIMENSION (:,:,:),INTENT(inout) :: zfieldo                              ! input/output array for seaoverland application
+      CHARACTER (len=100),       INTENT(in   ) :: clmaskfile                           ! land/sea mask file name
+      !
+      INTEGER :: inum,jni,jnj,jnz,jc   ! local indices
+      REAL(wp),DIMENSION (:,:,:),ALLOCATABLE :: zslmec1             ! local array for land point detection
+      REAL(wp),DIMENSION (:,:),  ALLOCATABLE :: zfieldn   ! array of forcing field with undeff for land points
+      REAL(wp),DIMENSION (:,:),  ALLOCATABLE :: zfield    ! array of forcing field
+      !!---------------------------------------------------------------------
+      !
+      ALLOCATE ( zslmec1(itmpi,itmpj,itmpz), zfieldn(itmpi,itmpj), zfield(itmpi,itmpj) )
+      !
       ! Retrieve the land sea mask data
       CALL iom_open( clmaskfile, inum )
       SELECT CASE( SIZE(zfieldo(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),3) )
       CASE(1)
-           CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,1), 1, rec1_lsm, recn_lsm)
+         CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,1), 1, rec1_lsm, recn_lsm)
       CASE DEFAULT
-           CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:), 1, rec1_lsm, recn_lsm)
+         CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:), 1, rec1_lsm, recn_lsm)
       END SELECT
       CALL iom_close( inum )
-
-      DO jnz=1,rec1_lsm(3)                            !! Loop over k dimension
-
-         DO jni=1,itmpi                               !! copy the original field into a tmp array
-            DO jnj=1,itmpj                            !! substituting undeff over land points
-            zfieldn(jni,jnj) = zfieldo(jni,jnj,jnz)
-               IF ( zslmec1(jni,jnj,jnz) == 1. ) THEN
-                  zfieldn(jni,jnj) = undeff_lsm
-               ENDIF
+      !
+      DO jnz=1,rec1_lsm(3)             !! Loop over k dimension
+         !
+         DO jni = 1, itmpi                               !! copy the original field into a tmp array
+            DO jnj = 1, itmpj                            !! substituting undeff over land points
+               zfieldn(jni,jnj) = zfieldo(jni,jnj,jnz)
+               IF( zslmec1(jni,jnj,jnz) == 1. )   zfieldn(jni,jnj) = undeff_lsm
             END DO
          END DO
-  
-      CALL seaoverland(zfieldn,itmpi,itmpj,zfield)
-      DO jc=1,nn_lsm
-         CALL seaoverland(zfield,itmpi,itmpj,zfield)
-      END DO
-
-      !   Check for Undeff and substitute original values
-      IF(ANY(zfield==undeff_lsm)) THEN
-         DO jni=1,itmpi
-            DO jnj=1,itmpj
-               IF (zfield(jni,jnj)==undeff_lsm) THEN
-                  zfield(jni,jnj) = zfieldo(jni,jnj,jnz)
-               ENDIF
-            ENDDO
-         ENDDO
-      ENDIF
-
-      zfieldo(:,:,jnz)=zfield(:,:)
-
-      END DO                          !! End Loop over k dimension
-
-      DEALLOCATE ( zslmec1 )
-      DEALLOCATE ( zfieldn )
-      DEALLOCATE ( zfield )
-
+         !
+         CALL seaoverland( zfieldn, itmpi, itmpj, zfield )
+         DO jc = 1, nn_lsm
+            CALL seaoverland( zfield, itmpi, itmpj, zfield )
+         END DO
+         !
+         !   Check for Undeff and substitute original values
+         IF( ANY(zfield==undeff_lsm) ) THEN
+            DO jni = 1, itmpi
+               DO jnj = 1, itmpj
+                  IF( zfield(jni,jnj)==undeff_lsm )   zfield(jni,jnj) = zfieldo(jni,jnj,jnz)
+               END DO
+            END DO
+         ENDIF
+         !
+         zfieldo(:,:,jnz) = zfield(:,:)
+         !
+      END DO                           !! End Loop over k dimension
+      !
+      DEALLOCATE ( zslmec1, zfieldn, zfield )
+      !
    END SUBROUTINE apply_seaoverland 
 
 
-   SUBROUTINE seaoverland(zfieldn,ileni,ilenj,zfield)
+   SUBROUTINE seaoverland( zfieldn, ileni, ilenj, zfield )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE seaoverland  ***
@@ -1245,29 +1235,31 @@
       !!      D. Delrosso INGV
       !!---------------------------------------------------------------------- 
-      INTEGER,INTENT(in)                       :: ileni,ilenj              ! lengths 
-      REAL,DIMENSION (ileni,ilenj),INTENT(in)  :: zfieldn                  ! array of forcing field with undeff for land points
-      REAL,DIMENSION (ileni,ilenj),INTENT(out) :: zfield                   ! array of forcing field
-      REAL,DIMENSION (ileni,ilenj)             :: zmat1,zmat2,zmat3,zmat4  ! temporary arrays for seaoverland application
-      REAL,DIMENSION (ileni,ilenj)             :: zmat5,zmat6,zmat7,zmat8  ! temporary arrays for seaoverland application
-      REAL,DIMENSION (ileni,ilenj)             :: zlsm2d                   ! temporary arrays for seaoverland application
-      REAL,DIMENSION (ileni,ilenj,8)           :: zlsm3d                   ! temporary arrays for seaoverland application
-      LOGICAL,DIMENSION (ileni,ilenj,8)        :: ll_msknan3d              ! logical mask for undeff detection
-      LOGICAL,DIMENSION (ileni,ilenj)          :: ll_msknan2d              ! logical mask for undeff detection
+      INTEGER                      , INTENT(in   ) :: ileni,ilenj   ! lengths 
+      REAL, DIMENSION (ileni,ilenj), INTENT(in   ) :: zfieldn       ! array of forcing field with undeff for land points
+      REAL, DIMENSION (ileni,ilenj), INTENT(  out) :: zfield        ! array of forcing field
+      !
+      REAL   , DIMENSION (ileni,ilenj)   :: zmat1, zmat2, zmat3, zmat4  ! local arrays 
+      REAL   , DIMENSION (ileni,ilenj)   :: zmat5, zmat6, zmat7, zmat8  !   -     - 
+      REAL   , DIMENSION (ileni,ilenj)   :: zlsm2d                      !   -     - 
+      REAL   , DIMENSION (ileni,ilenj,8) :: zlsm3d                      !   -     -
+      LOGICAL, DIMENSION (ileni,ilenj,8) :: ll_msknan3d                 ! logical mask for undeff detection
+      LOGICAL, DIMENSION (ileni,ilenj)   :: ll_msknan2d                 ! logical mask for undeff detection
       !!---------------------------------------------------------------------- 
-      zmat8 = eoshift(zfieldn   ,  SHIFT=-1, BOUNDARY = (/zfieldn(:,1)/)    ,DIM=2)
-      zmat1 = eoshift(zmat8     ,  SHIFT=-1, BOUNDARY = (/zmat8(1,:)/)      ,DIM=1)
-      zmat2 = eoshift(zfieldn   ,  SHIFT=-1, BOUNDARY = (/zfieldn(1,:)/)    ,DIM=1)
-      zmat4 = eoshift(zfieldn   ,  SHIFT= 1, BOUNDARY = (/zfieldn(:,ilenj)/),DIM=2)
-      zmat3 = eoshift(zmat4     ,  SHIFT=-1, BOUNDARY = (/zmat4(1,:)/)      ,DIM=1)
-      zmat5 = eoshift(zmat4     ,  SHIFT= 1, BOUNDARY = (/zmat4(ileni,:)/)  ,DIM=1)
-      zmat6 = eoshift(zfieldn   ,  SHIFT= 1, BOUNDARY = (/zfieldn(ileni,:)/),DIM=1)
-      zmat7 = eoshift(zmat8     ,  SHIFT= 1, BOUNDARY = (/zmat8(ileni,:)/)  ,DIM=1)
-
+      zmat8 = eoshift( zfieldn , SHIFT=-1 , BOUNDARY = (/zfieldn(:,1)/)     , DIM=2 )
+      zmat1 = eoshift( zmat8   , SHIFT=-1 , BOUNDARY = (/zmat8(1,:)/)       , DIM=1 )
+      zmat2 = eoshift( zfieldn , SHIFT=-1 , BOUNDARY = (/zfieldn(1,:)/)     , DIM=1 )
+      zmat4 = eoshift( zfieldn , SHIFT= 1 , BOUNDARY = (/zfieldn(:,ilenj)/) , DIM=2 )
+      zmat3 = eoshift( zmat4   , SHIFT=-1 , BOUNDARY = (/zmat4(1,:)/)       , DIM=1 )
+      zmat5 = eoshift( zmat4   , SHIFT= 1 , BOUNDARY = (/zmat4(ileni,:)/)   , DIM=1 )
+      zmat6 = eoshift( zfieldn , SHIFT= 1 , BOUNDARY = (/zfieldn(ileni,:)/) , DIM=1 )
+      zmat7 = eoshift( zmat8   , SHIFT= 1 , BOUNDARY = (/zmat8(ileni,:)/)   , DIM=1 )
+      !
       zlsm3d  = RESHAPE( (/ zmat1, zmat2, zmat3, zmat4, zmat5, zmat6, zmat7, zmat8 /), (/ ileni, ilenj, 8 /))
-      ll_msknan3d = .not.(zlsm3d==undeff_lsm)
-      ll_msknan2d = .not.(zfieldn==undeff_lsm)  ! FALSE where is Undeff (land)
-      zlsm2d = (SUM ( zlsm3d, 3 , ll_msknan3d ) )/(MAX(1,(COUNT( ll_msknan3d , 3 ))   ))
-      WHERE ((COUNT( ll_msknan3d , 3 )) == 0.0_wp)  zlsm2d = undeff_lsm
-      zfield = MERGE (zfieldn,zlsm2d,ll_msknan2d)
+      ll_msknan3d = .NOT.( zlsm3d  == undeff_lsm )
+      ll_msknan2d = .NOT.( zfieldn == undeff_lsm )  ! FALSE where is Undeff (land)
+      zlsm2d = SUM( zlsm3d, 3 , ll_msknan3d ) / MAX( 1 , COUNT( ll_msknan3d , 3 ) )
+      WHERE( COUNT( ll_msknan3d , 3 ) == 0._wp )   zlsm2d = undeff_lsm
+      zfield = MERGE( zfieldn, zlsm2d, ll_msknan2d )
+      !
    END SUBROUTINE seaoverland
 
@@ -1288,19 +1280,18 @@
       INTEGER                   , INTENT(in   ) ::   nrec    ! record number to read (ie time slice)
       CHARACTER(LEN=*)          , INTENT(in   ) ::   lsmfile ! land sea mask file name
-      !! 
-      REAL(wp),DIMENSION(:,:,:),ALLOCATABLE     ::   ztmp_fly_dta,zfieldo                  ! temporary array of values on input grid
-      INTEGER, DIMENSION(3)                     ::   rec1,recn                             ! temporary arrays for start and length
-      INTEGER, DIMENSION(3)                     ::   rec1_lsm,recn_lsm                     ! temporary arrays for start and length in case of seaoverland
-      INTEGER                                   ::   ii_lsm1,ii_lsm2,ij_lsm1,ij_lsm2       ! temporary indices
-      INTEGER                                   ::   jk, jn, jm, jir, jjr                  ! loop counters
-      INTEGER                                   ::   ni, nj                                ! lengths
-      INTEGER                                   ::   jpimin,jpiwid                         ! temporary indices
-      INTEGER                                   ::   jpimin_lsm,jpiwid_lsm                 ! temporary indices
-      INTEGER                                   ::   jpjmin,jpjwid                         ! temporary indices
-      INTEGER                                   ::   jpjmin_lsm,jpjwid_lsm                 ! temporary indices
-      INTEGER                                   ::   jpi1,jpi2,jpj1,jpj2                   ! temporary indices
-      INTEGER                                   ::   jpi1_lsm,jpi2_lsm,jpj1_lsm,jpj2_lsm   ! temporary indices
-      INTEGER                                   ::   itmpi,itmpj,itmpz                     ! lengths
-      
+      !
+      INTEGER, DIMENSION(3) ::   rec1, recn           ! temporary arrays for start and length
+      INTEGER, DIMENSION(3) ::   rec1_lsm, recn_lsm   ! temporary arrays for start and length in case of seaoverland
+      INTEGER ::   ii_lsm1,ii_lsm2,ij_lsm1,ij_lsm2    ! temporary indices
+      INTEGER ::   jk, jn, jm, jir, jjr               ! loop counters
+      INTEGER ::   ni, nj                             ! lengths
+      INTEGER ::   jpimin,jpiwid                      ! temporary indices
+      INTEGER ::   jpimin_lsm,jpiwid_lsm              ! temporary indices
+      INTEGER ::   jpjmin,jpjwid                      ! temporary indices
+      INTEGER ::   jpjmin_lsm,jpjwid_lsm              ! temporary indices
+      INTEGER ::   jpi1,jpi2,jpj1,jpj2                ! temporary indices
+      INTEGER ::   jpi1_lsm,jpi2_lsm,jpj1_lsm,jpj2_lsm   ! temporary indices
+      INTEGER ::   itmpi,itmpj,itmpz                     ! lengths
+      REAL(wp),DIMENSION(:,:,:), ALLOCATABLE ::   ztmp_fly_dta                 ! local array of values on input grid     
       !!----------------------------------------------------------------------
       !
@@ -1355,6 +1346,6 @@
 
 
-         itmpi=SIZE(ztmp_fly_dta(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),1)
-         itmpj=SIZE(ztmp_fly_dta(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),2)
+         itmpi=jpi2_lsm-jpi1_lsm+1
+         itmpj=jpj2_lsm-jpj1_lsm+1
          itmpz=kk
          ALLOCATE(ztmp_fly_dta(itmpi,itmpj,itmpz))
