Index: NEMO/branches/2020/tickets_icb_1900/src/OCE/SBC/fldread.F90
===================================================================
--- NEMO/branches/2020/tickets_icb_1900/src/OCE/SBC/fldread.F90	(revision 13277)
+++ NEMO/branches/2020/tickets_icb_1900/src/OCE/SBC/fldread.F90	(revision 13899)
@@ -53,5 +53,5 @@
       LOGICAL              ::   ln_tint     ! time interpolation or not (T/F)
       LOGICAL              ::   ln_clim     ! climatology or not (T/F)
-      CHARACTER(len = 8)   ::   cltype      ! type of data file 'daily', 'monthly' or yearly'
+      CHARACTER(len = 8)   ::   clftyp      ! type of data file 'daily', 'monthly' or yearly'
       CHARACTER(len = 256) ::   wname       ! generic name of a NetCDF weights file to be used, blank if not
       CHARACTER(len = 34)  ::   vcomp       ! symbolic component name if a vector that needs rotation
@@ -69,11 +69,14 @@
       LOGICAL                         ::   ln_tint      ! time interpolation or not (T/F)
       LOGICAL                         ::   ln_clim      ! climatology or not (T/F)
-      CHARACTER(len = 8)              ::   cltype       ! type of data file 'daily', 'monthly' or yearly'
+      CHARACTER(len = 8)              ::   clftyp       ! type of data file 'daily', 'monthly' or yearly'
+      CHARACTER(len = 1)              ::   cltype       ! nature of grid-points: T, U, V...
+      REAL(wp)                        ::   zsgn         ! -1. the sign change across the north fold, =  1. otherwise
       INTEGER                         ::   num          ! iom id of the jpfld files to be read
-      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)
-      INTEGER , ALLOCATABLE, DIMENSION(:      ) ::   nrecsec   ! 
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:  ) ::   fnow   ! input fields interpolated to now time step
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   fdta   ! 2 consecutive record of input fields
+      INTEGER , DIMENSION(2,2)        ::   nrec         ! before/after record (1: index, 2: second since Jan. 1st 00h of yr nit000)
+      INTEGER                         ::   nbb          ! index of before values
+      INTEGER                         ::   naa          ! index of after  values
+      INTEGER , ALLOCATABLE, DIMENSION(:) ::   nrecsec   ! 
+      REAL(wp), POINTER, DIMENSION(:,:,:  ) ::   fnow   ! input fields interpolated to now time step
+      REAL(wp), POINTER, 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
@@ -157,4 +160,5 @@
       INTEGER  ::   jf           ! dummy indices
       INTEGER  ::   isecsbc      ! number of seconds between Jan. 1st 00h of nit000 year and the middle of sbc time step
+      INTEGER  ::   ibb, iaa     ! shorter name for sd(jf)%nbb and sd(jf)%naa
       LOGICAL  ::   ll_firstcall ! true if this is the first call to fld_read for this set of fields
       REAL(wp) ::   zt_offset    ! local time offset variable
@@ -204,4 +208,6 @@
             IF( TRIM(sd(jf)%clrootname) == 'NOT USED' )   CYCLE
             !
+            ibb = sd(jf)%nbb   ;   iaa = sd(jf)%naa
+            !
             IF( sd(jf)%ln_tint ) THEN              ! temporal interpolation
                IF(lwp .AND. kt - nit000 <= 100 ) THEN 
@@ -209,11 +215,11 @@
                      &    "', records b/a: ', i6.4, '/', i6.4, ' (days ', f9.4,'/', f9.4, ')')"
                   WRITE(numout, clfmt)  TRIM( sd(jf)%clvar ), kt, REAL(isecsbc,wp)/rday, nyear, nmonth, nday,   &            
-                     & sd(jf)%nrec_b(1), sd(jf)%nrec_a(1), REAL(sd(jf)%nrec_b(2),wp)/rday, REAL(sd(jf)%nrec_a(2),wp)/rday
-                  WRITE(numout, *) '      zt_offset is : ',zt_offset
+                     & sd(jf)%nrec(1,ibb), sd(jf)%nrec(1,iaa), REAL(sd(jf)%nrec(2,ibb),wp)/rday, REAL(sd(jf)%nrec(2,iaa),wp)/rday
+                  IF( zt_offset /= 0._wp )   WRITE(numout, *) '      zt_offset is : ', zt_offset
                ENDIF
                ! temporal interpolation weights
-               ztinta =  REAL( isecsbc - sd(jf)%nrec_b(2), wp ) / REAL( sd(jf)%nrec_a(2) - sd(jf)%nrec_b(2), wp )
+               ztinta =  REAL( isecsbc - sd(jf)%nrec(2,ibb), wp ) / REAL( sd(jf)%nrec(2,iaa) - sd(jf)%nrec(2,ibb), wp )
                ztintb =  1. - ztinta
-               sd(jf)%fnow(:,:,:) = ztintb * sd(jf)%fdta(:,:,:,1) + ztinta * sd(jf)%fdta(:,:,:,2)
+               sd(jf)%fnow(:,:,:) = ztintb * sd(jf)%fdta(:,:,:,ibb) + ztinta * sd(jf)%fdta(:,:,:,iaa)
             ELSE   ! nothing to do...
                IF(lwp .AND. kt - nit000 <= 100 ) THEN
@@ -221,5 +227,5 @@
                      &    "', record: ', i6.4, ' (days ', f9.4, ' <-> ', f9.4, ')')"
                   WRITE(numout, clfmt) TRIM(sd(jf)%clvar), kt, REAL(isecsbc,wp)/rday, nyear, nmonth, nday,    &
-                     &                 sd(jf)%nrec_a(1), REAL(sd(jf)%nrec_b(2),wp)/rday, REAL(sd(jf)%nrec_a(2),wp)/rday
+                     &                 sd(jf)%nrec(1,iaa), REAL(sd(jf)%nrec(2,ibb),wp)/rday, REAL(sd(jf)%nrec(2,iaa),wp)/rday
                ENDIF
             ENDIF
@@ -251,5 +257,5 @@
       !
       CALL fld_clopn( sdjf )
-      sdjf%nrec_a(:) = (/ 1, nflag /)  ! default definition to force flp_update to read the file.
+      sdjf%nrec(:,sdjf%naa) = (/ 1, nflag /)  ! default definition to force flp_update to read the file.
       !
    END SUBROUTINE fld_init
@@ -262,8 +268,8 @@
       !! ** Purpose : Compute
       !!              if sdjf%ln_tint = .TRUE.
-      !!                  nrec_a: record number and its time (nrec_b is obtained from nrec_a when swapping)
+      !!                  nrec(:,iaa): record number and its time (nrec(:,ibb) is obtained from nrec(:,iaa) when swapping)
       !!              if sdjf%ln_tint = .FALSE.
-      !!                  nrec_a(1): record number
-      !!                  nrec_b(2) and nrec_a(2): time of the beginning and end of the record
+      !!                  nrec(1,iaa): record number
+      !!                  nrec(2,ibb) and nrec(2,iaa): time of the beginning and end of the record
       !!----------------------------------------------------------------------
       INTEGER  ,           INTENT(in   ) ::   ksecsbc   ! 
@@ -271,11 +277,13 @@
       INTEGER  , OPTIONAL, INTENT(in   ) ::   Kmm    ! ocean time level index
       !
-      INTEGER  ::   ja     ! end of this record (in seconds)
-      !!----------------------------------------------------------------------
-      !
-      IF( ksecsbc > sdjf%nrec_a(2) ) THEN     ! --> we need to update after data
+      INTEGER  ::   ja           ! end of this record (in seconds)
+      INTEGER  ::   ibb, iaa     ! shorter name for sdjf%nbb and sdjf%naa
+      !!----------------------------------------------------------------------
+      ibb = sdjf%nbb   ;   iaa = sdjf%naa
+      !
+      IF( ksecsbc > sdjf%nrec(2,iaa) ) THEN     ! --> we need to update after data
         
-         ! find where is the new after record... (it is not necessary sdjf%nrec_a(1)+1 )
-         ja = sdjf%nrec_a(1)
+         ! find where is the new after record... (it is not necessary sdjf%nrec(1,iaa)+1 )
+         ja = sdjf%nrec(1,iaa)
          DO WHILE ( ksecsbc >= sdjf%nrecsec(ja) .AND. ja < sdjf%nreclast )   ! Warning: make sure ja <= sdjf%nreclast in this test
             ja = ja + 1
@@ -284,8 +292,8 @@
 
          ! if ln_tint and if the new after is not ja+1, we need also to update after data before the swap
-         ! so, after the swap, sdjf%nrec_b(2) will still be the closest value located just before ksecsbc
-         IF( sdjf%ln_tint .AND. ( ja > sdjf%nrec_a(1) + 1 .OR. sdjf%nrec_a(2) == nflag ) ) THEN
-            sdjf%nrec_a(:) = (/ ja-1, sdjf%nrecsec(ja-1) /)   ! update nrec_a with before information
-            CALL fld_get( sdjf, Kmm )                         ! read after data that will be used as before data
+         ! so, after the swap, sdjf%nrec(2,ibb) will still be the closest value located just before ksecsbc
+         IF( sdjf%ln_tint .AND. ( ja > sdjf%nrec(1,iaa) + 1 .OR. sdjf%nrec(2,iaa) == nflag ) ) THEN
+            sdjf%nrec(:,iaa) = (/ ja-1, sdjf%nrecsec(ja-1) /)   ! update nrec(:,iaa) with before information
+            CALL fld_get( sdjf, Kmm )                           ! read after data that will be used as before data
          ENDIF
             
@@ -310,7 +318,7 @@
             ! if ln_tint and if after is not the first record, we must (potentially again) update after data before the swap
             IF( sdjf%ln_tint .AND. ja > 1 ) THEN
-               IF( sdjf%nrecsec(0) /= nflag ) THEN                  ! no trick used: after file is not the current file
-                  sdjf%nrec_a(:) = (/ ja-1, sdjf%nrecsec(ja-1) /)   ! update nrec_a with before information
-                  CALL fld_get( sdjf, Kmm )                         ! read after data that will be used as before data
+               IF( sdjf%nrecsec(0) /= nflag ) THEN                    ! no trick used: after file is not the current file
+                  sdjf%nrec(:,iaa) = (/ ja-1, sdjf%nrecsec(ja-1) /)   ! update nrec(:,iaa) with before information
+                  CALL fld_get( sdjf, Kmm )                           ! read after data that will be used as before data
                ENDIF
             ENDIF
@@ -318,16 +326,14 @@
          ENDIF
 
-         IF( sdjf%ln_tint ) THEN 
-            ! Swap data
-            sdjf%nrec_b(:)     = sdjf%nrec_a(:)                     ! swap before record informations
-            sdjf%rotn(1)       = sdjf%rotn(2)                       ! swap before rotate informations
-            sdjf%fdta(:,:,:,1) = sdjf%fdta(:,:,:,2)                 ! swap before record field
-         ELSE
-            sdjf%nrec_b(:) = (/ ja-1, sdjf%nrecsec(ja-1) /)         ! only for print 
+         IF( sdjf%ln_tint ) THEN                                ! Swap data
+            sdjf%nbb = sdjf%naa                                 !    swap indices
+            sdjf%naa = 3 - sdjf%naa                             !    = 2(1) if naa == 1(2)
+         ELSE                                                   ! No swap
+            sdjf%nrec(:,ibb) = (/ ja-1, sdjf%nrecsec(ja-1) /)   !    only for print 
          ENDIF
             
          ! read new after data
-         sdjf%nrec_a(:) = (/ ja, sdjf%nrecsec(ja) /)                ! update nrec_a as it is used by fld_get
-         CALL fld_get( sdjf, Kmm )                                  ! read after data (with nrec_a informations)
+         sdjf%nrec(:,sdjf%naa) = (/ ja, sdjf%nrecsec(ja) /)     ! update nrec(:,naa) as it is used by fld_get
+         CALL fld_get( sdjf, Kmm )                              ! read after data (with nrec(:,naa) informations)
         
       ENDIF
@@ -346,70 +352,43 @@
       !
       INTEGER ::   ipk      ! number of vertical levels of sdjf%fdta ( 2D: ipk=1 ; 3D: ipk=jpk )
+      INTEGER ::   iaa      ! shorter name for sdjf%naa
       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
-      !!---------------------------------------------------------------------
-      !
-      ipk = SIZE( sdjf%fnow, 3 )
-      !
-      IF( ASSOCIATED(sdjf%imap) ) THEN
-         IF( sdjf%ln_tint ) THEN   ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1),   &
-            &                                        sdjf%imap, sdjf%igrd, sdjf%ibdy, sdjf%ltotvel, sdjf%lzint, Kmm )
-         ELSE                      ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1),   &
-            &                                        sdjf%imap, sdjf%igrd, sdjf%ibdy, sdjf%ltotvel, sdjf%lzint, Kmm )
-         ENDIF
-      ELSE IF( LEN(TRIM(sdjf%wgtname)) > 0 ) THEN
+      REAL(wp), DIMENSION(:,:,:), POINTER ::   dta_alias   ! short cut
+      !!---------------------------------------------------------------------
+      iaa = sdjf%naa
+      !
+      IF( sdjf%ln_tint ) THEN   ;   dta_alias => sdjf%fdta(:,:,:,iaa)
+      ELSE                      ;   dta_alias => sdjf%fnow(:,:,:    )
+      ENDIF
+      ipk = SIZE( dta_alias, 3 )
+      !
+      IF( ASSOCIATED(sdjf%imap) ) THEN              ! BDY case 
+         CALL fld_map( sdjf%num, sdjf%clvar, dta_alias(:,:,:), sdjf%nrec(1,iaa),   &
+            &          sdjf%imap, sdjf%igrd, sdjf%ibdy, sdjf%ltotvel, sdjf%lzint, Kmm )
+      ELSE IF( LEN(TRIM(sdjf%wgtname)) > 0 ) THEN   ! On-the-fly interpolation
          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 )
-         ENDIF
-      ELSE
-         IF( SIZE(sdjf%fnow, 1) == jpi ) THEN   ;   ipdom = jpdom_data
-         ELSE                                   ;   ipdom = jpdom_unknown
-         ENDIF
+         CALL fld_interp( sdjf%num, sdjf%clvar, iw, ipk, dta_alias(:,:,:), sdjf%nrec(1,iaa), sdjf%lsmname )
+         CALL lbc_lnk( 'fldread', dta_alias(:,:,:), sdjf%cltype, sdjf%zsgn, kfillmode = jpfillcopy )
+      ELSE                                          ! default case
          ! 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 )
-         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  )
-         !
-         SELECT CASE( ipk )
-         CASE(1)
-            IF( lk_c1d .AND. lmoor ) THEN
-               IF( sdjf%ln_tint ) THEN
-                  CALL iom_get( sdjf%num, sdjf%clvar, sdjf%fdta(2,2,1,2), sdjf%nrec_a(1) )
-                  CALL lbc_lnk( 'fldread', sdjf%fdta(:,:,1,2),'Z',1.0_wp )
-               ELSE
-                  CALL iom_get( sdjf%num, sdjf%clvar, sdjf%fnow(2,2,1  ), sdjf%nrec_a(1) )
-                  CALL lbc_lnk( 'fldread', sdjf%fnow(:,:,1  ),'Z',1.0_wp )
-               ENDIF
-            ELSE
-               IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,1,2), sdjf%nrec_a(1) )
-               ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,1  ), sdjf%nrec_a(1) )
-               ENDIF
-            ENDIF
-         CASE DEFAULT
-            IF(lk_c1d .AND. lmoor ) THEN
-               IF( sdjf%ln_tint ) THEN
-                  CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, sdjf%fdta(2,2,:,2), sdjf%nrec_a(1) )
-                  CALL lbc_lnk( 'fldread', sdjf%fdta(:,:,:,2),'Z',1.0_wp )
-               ELSE
-                  CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, sdjf%fnow(2,2,:  ), sdjf%nrec_a(1) )
-                  CALL lbc_lnk( 'fldread', sdjf%fnow(:,:,:  ),'Z',1.0_wp )
-               ENDIF
-            ELSE
-               IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1) )
-               ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1) )
-               ENDIF
-            ENDIF
-         END SELECT
-      ENDIF
-      !
-      sdjf%rotn(2) = .false.   ! vector not yet rotated
+         IF( iom_file( sdjf%num )%luld( idvar ) )   idmspc = idmspc - 1   ! id of the last spatial dimension
+         lmoor  = (  idmspc == 0 .OR. PRODUCT( iom_file( sdjf%num )%dimsz( 1:MAX(idmspc,1) ,idvar ) ) == ipk  )    
+         !
+         IF( lk_c1d .AND. lmoor ) THEN
+            CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, dta_alias(2,2,:), sdjf%nrec(1,iaa) )   ! jpdom_unknown -> no lbc_lnk
+            CALL lbc_lnk( 'fldread', dta_alias(:,:,:), 'T', 1., kfillmode = jpfillcopy )
+         ELSE
+            CALL iom_get( sdjf%num,  jpdom_global, sdjf%clvar, dta_alias(:,:,:), sdjf%nrec(1,iaa),   &
+               &          sdjf%cltype, sdjf%zsgn, kfill = jpfillcopy )
+         ENDIF
+      ENDIF
+      !
+      sdjf%rotn(iaa) = .false.   ! vector not yet rotated
       !
    END SUBROUTINE fld_get
@@ -447,10 +426,10 @@
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   zdta_read_z  ! work space local data requiring vertical interpolation
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   zdta_read_dz ! work space local data requiring vertical interpolation
-      CHARACTER(LEN=1),DIMENSION(3)             ::   clgrid
+      CHARACTER(LEN=1),DIMENSION(3)             ::   cltype
       LOGICAL                                   ::   lluld        ! is the variable using the unlimited dimension
       LOGICAL                                   ::   llzint       ! local value of ldzint
       !!---------------------------------------------------------------------
       !
-      clgrid = (/'t','u','v'/)
+      cltype = (/'t','u','v'/)
       !
       ipi = SIZE( pdta, 1 )
@@ -487,12 +466,12 @@
          IF( ipkb /= ipk .OR. llzint ) THEN   ! boundary data not on model vertical grid : vertical interpolation
             !
-            IF( ipk == jpk .AND. iom_varid(knum,'gdep'//clgrid(kgrd)) /= -1 .AND. iom_varid(knum,'e3'//clgrid(kgrd)) /= -1 ) THEN
+            IF( ipk == jpk .AND. iom_varid(knum,'gdep'//cltype(kgrd)) /= -1 .AND. iom_varid(knum,'e3'//cltype(kgrd)) /= -1 ) THEN
                
                ALLOCATE( zdta_read(ipi,ipj,ipkb), zdta_read_z(ipi,ipj,ipkb), zdta_read_dz(ipi,ipj,ipkb) )
                 
                CALL fld_map_core( zz_read, kmap, zdta_read )
-               CALL iom_get ( knum, jpdom_unknown, 'gdep'//clgrid(kgrd), zz_read )   ! read only once? Potential temporal evolution?
+               CALL iom_get ( knum, jpdom_unknown, 'gdep'//cltype(kgrd), zz_read )   ! read only once? Potential temporal evolution?
                CALL fld_map_core( zz_read, kmap, zdta_read_z )
-               CALL iom_get ( knum, jpdom_unknown,   'e3'//clgrid(kgrd), zz_read )   ! read only once? Potential temporal evolution?
+               CALL iom_get ( knum, jpdom_unknown,   'e3'//cltype(kgrd), zz_read )   ! read only once? Potential temporal evolution?
                CALL fld_map_core( zz_read, kmap, zdta_read_dz )
                
@@ -504,6 +483,6 @@
                IF( ipk /= jpk ) CALL ctl_stop( 'fld_map : this should be an impossible case...' )
                WRITE(ctmp1,*) 'fld_map : vertical interpolation for bdy variable '//TRIM(cdvar)//' requires ' 
-               IF( iom_varid(knum, 'gdep'//clgrid(kgrd)) == -1 ) CALL ctl_stop( ctmp1//'gdep'//clgrid(kgrd)//' variable' )
-               IF( iom_varid(knum,   'e3'//clgrid(kgrd)) == -1 ) CALL ctl_stop( ctmp1//  'e3'//clgrid(kgrd)//' variable' )
+               IF( iom_varid(knum, 'gdep'//cltype(kgrd)) == -1 ) CALL ctl_stop( ctmp1//'gdep'//cltype(kgrd)//' variable' )
+               IF( iom_varid(knum,   'e3'//cltype(kgrd)) == -1 ) CALL ctl_stop( ctmp1//  'e3'//cltype(kgrd)//' variable' )
 
             ENDIF
@@ -728,4 +707,5 @@
       CHARACTER (LEN=100)          ::   clcomp       ! dummy weight name
       REAL(wp), DIMENSION(jpi,jpj) ::   utmp, vtmp   ! temporary arrays for vector rotation
+      REAL(wp), DIMENSION(:,:,:), POINTER ::   dta_u, dta_v    ! short cut
       !!---------------------------------------------------------------------
       !
@@ -747,14 +727,11 @@
                   END DO
                   IF( iv > 0 ) THEN   ! fields ju and iv are two components which need to be rotated together
+                     IF( sd(ju)%ln_tint ) THEN   ;   dta_u => sd(ju)%fdta(:,:,:,jn)   ;   dta_v => sd(iv)%fdta(:,:,:,jn) 
+                     ELSE                        ;   dta_u => sd(ju)%fnow(:,:,:   )   ;   dta_v => sd(iv)%fnow(:,:,:   )
+                     ENDIF
                      DO jk = 1, SIZE( sd(ju)%fnow, 3 )
-                        IF( sd(ju)%ln_tint )THEN
-                           CALL rot_rep( sd(ju)%fdta(:,:,jk,jn), sd(iv)%fdta(:,:,jk,jn), 'T', 'en->i', utmp(:,:) )
-                           CALL rot_rep( sd(ju)%fdta(:,:,jk,jn), sd(iv)%fdta(:,:,jk,jn), 'T', 'en->j', vtmp(:,:) )
-                           sd(ju)%fdta(:,:,jk,jn) = utmp(:,:)   ;   sd(iv)%fdta(:,:,jk,jn) = vtmp(:,:)
-                        ELSE 
-                           CALL rot_rep( sd(ju)%fnow(:,:,jk   ), sd(iv)%fnow(:,:,jk   ), 'T', 'en->i', utmp(:,:) )
-                           CALL rot_rep( sd(ju)%fnow(:,:,jk   ), sd(iv)%fnow(:,:,jk   ), 'T', 'en->j', vtmp(:,:) )
-                           sd(ju)%fnow(:,:,jk   ) = utmp(:,:)   ;   sd(iv)%fnow(:,:,jk   ) = vtmp(:,:)
-                        ENDIF
+                        CALL rot_rep( dta_u(:,:,jk), dta_v(:,:,jk), 'T', 'en->i', utmp(:,:) )
+                        CALL rot_rep( dta_u(:,:,jk), dta_v(:,:,jk), 'T', 'en->j', vtmp(:,:) )
+                        dta_u(:,:,jk) = utmp(:,:)   ;   dta_v(:,:,jk) = vtmp(:,:)
                      END DO
                      sd(ju)%rotn(jn) = .TRUE.               ! vector was rotated 
@@ -802,12 +779,12 @@
 
       ! current file parameters
-      IF( sdjf%cltype(1:4) == 'week' ) THEN          ! find the day of the beginning of the current week
-         isecwk = ksec_week( sdjf%cltype(6:8) )     ! seconds between the beginning of the week and half of current time step
-         llprevmt = isecwk > nsec_month               ! longer time since beginning of the current week than the current month
+      IF( sdjf%clftyp(1:4) == 'week' ) THEN         ! find the day of the beginning of the current week
+         isecwk = ksec_week( sdjf%clftyp(6:8) )     ! seconds between the beginning of the week and half of current time step
+         llprevmt = isecwk > nsec_month             ! longer time since beginning of the current week than the current month
          llprevyr = llprevmt .AND. nmonth == 1
          iyr = nyear  - COUNT((/llprevyr/))
          imt = nmonth - COUNT((/llprevmt/)) + 12 * COUNT((/llprevyr/))
          idy = nday + nmonth_len(nmonth-1) * COUNT((/llprevmt/)) - isecwk / idaysec
-         isecwk = nsec_year - isecwk              ! seconds between 00h jan 1st of current year and current week beginning
+         isecwk = nsec_year - isecwk                ! seconds between 00h jan 1st of current year and current week beginning
       ELSE
          iyr = nyear
@@ -819,16 +796,16 @@
       ! previous file parameters
       IF( llprev ) THEN
-         IF( sdjf%cltype(1:4) == 'week'    ) THEN     ! find the day of the beginning of previous week
-            isecwk = isecwk + 7 * idaysec         ! seconds between the beginning of previous week and half of the time step
-            llprevmt = isecwk > nsec_month            ! longer time since beginning of the previous week than the current month
+         IF( sdjf%clftyp(1:4) == 'week'    ) THEN   ! find the day of the beginning of previous week
+            isecwk = isecwk + 7 * idaysec           ! seconds between the beginning of previous week and half of the time step
+            llprevmt = isecwk > nsec_month          ! longer time since beginning of the previous week than the current month
             llprevyr = llprevmt .AND. nmonth == 1
             iyr = nyear  - COUNT((/llprevyr/))
             imt = nmonth - COUNT((/llprevmt/)) + 12 * COUNT((/llprevyr/))
             idy = nday + nmonth_len(nmonth-1) * COUNT((/llprevmt/)) - isecwk / idaysec
-            isecwk = nsec_year - isecwk           ! seconds between 00h jan 1st of current year and previous week beginning
+            isecwk = nsec_year - isecwk             ! seconds between 00h jan 1st of current year and previous week beginning
          ELSE
-            idy = nday   - COUNT((/ sdjf%cltype == 'daily'                 /))
-            imt = nmonth - COUNT((/ sdjf%cltype == 'monthly' .OR. idy == 0 /))
-            iyr = nyear  - COUNT((/ sdjf%cltype == 'yearly'  .OR. imt == 0 /))
+            idy = nday   - COUNT((/ sdjf%clftyp == 'daily'                 /))
+            imt = nmonth - COUNT((/ sdjf%clftyp == 'monthly' .OR. idy == 0 /))
+            iyr = nyear  - COUNT((/ sdjf%clftyp == 'yearly'  .OR. imt == 0 /))
             IF( idy == 0 ) idy = nmonth_len(imt)
             IF( imt == 0 ) imt = 12
@@ -839,6 +816,6 @@
       ! next file parameters
       IF( llnext ) THEN
-         IF( sdjf%cltype(1:4) == 'week'    ) THEN     ! find the day of the beginning of next week
-            isecwk = 7 * idaysec - isecwk         ! seconds between half of the time step and the beginning of next week
+         IF( sdjf%clftyp(1:4) == 'week'    ) THEN   ! find the day of the beginning of next week
+            isecwk = 7 * idaysec - isecwk           ! seconds between half of the time step and the beginning of next week
             llnextmt = isecwk > ( nmonth_len(nmonth)*idaysec - nsec_month )   ! larger than the seconds to the end of the month
             llnextyr = llnextmt .AND. nmonth == 12
@@ -846,9 +823,9 @@
             imt = nmonth + COUNT((/llnextmt/)) - 12 * COUNT((/llnextyr/))
             idy = nday - nmonth_len(nmonth) * COUNT((/llnextmt/)) + isecwk / idaysec + 1
-            isecwk = nsec_year + isecwk           ! seconds between 00h jan 1st of current year and next week beginning
+            isecwk = nsec_year + isecwk             ! seconds between 00h jan 1st of current year and next week beginning
          ELSE
-            idy = nday   + COUNT((/ sdjf%cltype == 'daily'                                 /))
-            imt = nmonth + COUNT((/ sdjf%cltype == 'monthly' .OR. idy > nmonth_len(nmonth) /))
-            iyr = nyear  + COUNT((/ sdjf%cltype == 'yearly'  .OR. imt == 13                /))
+            idy = nday   + COUNT((/ sdjf%clftyp == 'daily'                                 /))
+            imt = nmonth + COUNT((/ sdjf%clftyp == 'monthly' .OR. idy > nmonth_len(nmonth) /))
+            iyr = nyear  + COUNT((/ sdjf%clftyp == 'yearly'  .OR. imt == 13                /))
             IF( idy > nmonth_len(nmonth) )   idy = 1
             IF( imt == 13                )   imt = 1
@@ -867,11 +844,11 @@
       IF    ( NINT(sdjf%freqh) == -12 ) THEN            ;   ireclast = 1    ! yearly mean: consider only 1 record
       ELSEIF( NINT(sdjf%freqh) ==  -1 ) THEN                                ! monthly mean:
-         IF(     sdjf%cltype      == 'monthly' ) THEN   ;   ireclast = 1    !  consider that the file has  1 record
+         IF(     sdjf%clftyp      == 'monthly' ) THEN   ;   ireclast = 1    !  consider that the file has  1 record
          ELSE                                           ;   ireclast = 12   !  consider that the file has 12 record
          ENDIF
       ELSE                                                                  ! higher frequency mean (in hours)
-         IF(     sdjf%cltype      == 'monthly' ) THEN   ;   ireclast = NINT( 24. * REAL(nmonth_len(indexmt), wp) / sdjf%freqh )
-         ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ;   ireclast = NINT( 24. * 7.                            / sdjf%freqh )
-         ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ;   ireclast = NINT( 24.                                 / sdjf%freqh )
+         IF(     sdjf%clftyp      == 'monthly' ) THEN   ;   ireclast = NINT( 24. * REAL(nmonth_len(indexmt), wp) / sdjf%freqh )
+         ELSEIF( sdjf%clftyp(1:4) == 'week'    ) THEN   ;   ireclast = NINT( 24. * 7.                            / sdjf%freqh )
+         ELSEIF( sdjf%clftyp      == 'daily'   ) THEN   ;   ireclast = NINT( 24.                                 / sdjf%freqh )
          ELSE                                           ;   ireclast = NINT( 24. * REAL( nyear_len(indexyr), wp) / sdjf%freqh )
          ENDIF
@@ -891,5 +868,5 @@
          sdjf%nrecsec(1) = sdjf%nrecsec(0) + nyear_len( indexyr ) * idaysec
       ELSEIF( NINT(sdjf%freqh) ==  -1 ) THEN                                     ! monthly mean:
-         IF(     sdjf%cltype      == 'monthly' ) THEN                            !    monthly file
+         IF(     sdjf%clftyp      == 'monthly' ) THEN                            !    monthly file
             sdjf%nrecsec(0   ) = nsec1jan000 + nmonth_beg(indexmt  )
             sdjf%nrecsec(1   ) = nsec1jan000 + nmonth_beg(indexmt+1)
@@ -899,7 +876,7 @@
          ENDIF
       ELSE                                                                       ! higher frequency mean (in hours)
-         IF(     sdjf%cltype      == 'monthly' ) THEN   ;   istart = nsec1jan000 + nmonth_beg(indexmt)
-         ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ;   istart = nsec1jan000 + isecwk
-         ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ;   istart = nsec1jan000 + nmonth_beg(indexmt) + ( idy - 1 ) * idaysec
+         IF(     sdjf%clftyp      == 'monthly' ) THEN   ;   istart = nsec1jan000 + nmonth_beg(indexmt)
+         ELSEIF( sdjf%clftyp(1:4) == 'week'    ) THEN   ;   istart = nsec1jan000 + isecwk
+         ELSEIF( sdjf%clftyp      == 'daily'   ) THEN   ;   istart = nsec1jan000 + nmonth_beg(indexmt) + ( idy - 1 ) * idaysec
          ELSEIF( indexyr          == 0         ) THEN   ;   istart = nsec1jan000 - nyear_len( 0 ) * idaysec
          ELSEIF( indexyr          == 2         ) THEN   ;   istart = nsec1jan000 + nyear_len( 1 ) * idaysec
@@ -942,5 +919,5 @@
       IF( sdjf%num <= 0 .OR. .NOT. sdjf%ln_clim  ) THEN
          IF( sdjf%num > 0 )   CALL iom_close( sdjf%num )   ! close file if already open
-         CALL iom_open( sdjf%clname, sdjf%num, ldstop = llstop, ldiof = LEN(TRIM(sdjf%wgtname)) > 0 )
+         CALL iom_open( sdjf%clname, sdjf%num, ldstop = llstop, ldiof = LEN_TRIM(sdjf%wgtname) > 0 )
       ENDIF
       !
@@ -964,5 +941,5 @@
          ENDIF
          !
-         CALL iom_open( sdjf%clname, sdjf%num, ldiof = LEN(TRIM(sdjf%wgtname)) > 0 )   
+         CALL iom_open( sdjf%clname, sdjf%num, ldiof = LEN_TRIM(sdjf%wgtname) > 0 )   
          !
       ENDIF
@@ -997,6 +974,10 @@
          sdf(jf)%ln_tint    = sdf_n(jf)%ln_tint
          sdf(jf)%ln_clim    = sdf_n(jf)%ln_clim
-         sdf(jf)%cltype     = sdf_n(jf)%cltype
+         sdf(jf)%clftyp     = sdf_n(jf)%clftyp
+         sdf(jf)%cltype     = 'T'   ! by default don't do any call to lbc_lnk in iom_get
+         sdf(jf)%zsgn       = 1.    ! by default don't do change signe across the north fold
          sdf(jf)%num        = -1
+         sdf(jf)%nbb        = 1  ! start with before data in 1
+         sdf(jf)%naa        = 2  ! start with after  data in 2
          sdf(jf)%wgtname    = " "
          IF( LEN( TRIM(sdf_n(jf)%wname) ) > 0 )   sdf(jf)%wgtname = TRIM( cdir )//sdf_n(jf)%wname
@@ -1005,7 +986,7 @@
          sdf(jf)%vcomp      = sdf_n(jf)%vcomp
          sdf(jf)%rotn(:)    = .TRUE.   ! pretend to be rotated -> won't try to rotate data before the first call to fld_get
-         IF( sdf(jf)%cltype(1:4) == 'week' .AND. nn_leapy == 0  )   &
+         IF( sdf(jf)%clftyp(1:4) == 'week' .AND. nn_leapy == 0  )   &
             &   CALL ctl_stop('fld_clopn: weekly file ('//TRIM(sdf(jf)%clrootname)//') needs nn_leapy = 1')
-         IF( sdf(jf)%cltype(1:4) == 'week' .AND. sdf(jf)%ln_clim )   &
+         IF( sdf(jf)%clftyp(1:4) == 'week' .AND. sdf(jf)%ln_clim )   &
             &   CALL ctl_stop('fld_clopn: weekly file ('//TRIM(sdf(jf)%clrootname)//') needs ln_clim = .FALSE.')
          sdf(jf)%nreclast   = -1 ! Set to non zero default value to avoid errors, is updated to meaningful value during fld_clopn
@@ -1033,5 +1014,5 @@
             WRITE(numout,*) '         weights: '        , TRIM( sdf(jf)%wgtname    ),   &
                &                  '   pairing: '        , TRIM( sdf(jf)%vcomp      ),   &
-               &                  '   data type: '      ,       sdf(jf)%cltype      ,   &
+               &                  '   data type: '      ,       sdf(jf)%clftyp      ,   &
                &                  '   land/sea mask:'   , TRIM( sdf(jf)%lsmname    )
             call flush(numout)
@@ -1051,13 +1032,11 @@
       !!----------------------------------------------------------------------
       TYPE( FLD ), INTENT(in   ) ::   sd        ! field with name of weights file
-      INTEGER    , INTENT(inout) ::   kwgt      ! index of weights
+      INTEGER    , INTENT(  out) ::   kwgt      ! index of weights
       !
       INTEGER ::   kw, nestid   ! local integer
-      LOGICAL ::   found        ! local logical
       !!----------------------------------------------------------------------
       !
       !! search down linked list 
       !! 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
@@ -1069,15 +1048,12 @@
 #endif
       DO kw = 1, nxt_wgt-1
-         IF( TRIM(ref_wgts(kw)%wgtname) == TRIM(sd%wgtname) .AND. &
-             ref_wgts(kw)%nestid == nestid) THEN
+         IF( ref_wgts(kw)%wgtname == sd%wgtname .AND. &
+             ref_wgts(kw)%nestid  == nestid) THEN
             kwgt = kw
-            found = .TRUE.
-            EXIT
+            RETURN
          ENDIF
       END DO
-      IF( .NOT.found ) THEN
-         kwgt = nxt_wgt
-         CALL fld_weight( sd )
-      ENDIF
+      kwgt = nxt_wgt
+      CALL fld_weight( sd )
       !
    END SUBROUTINE wgt_list
@@ -1122,5 +1098,5 @@
       TYPE( FLD ), INTENT(in) ::   sd   ! field with name of weights file
       !!
-      INTEGER ::   jn         ! dummy loop indices
+      INTEGER ::   ji,jj,jn   ! dummy loop indices
       INTEGER ::   inum       ! local logical unit
       INTEGER ::   id         ! local variable id
@@ -1128,7 +1104,7 @@
       INTEGER ::   zwrap      ! local integer
       LOGICAL ::   cyclical   ! 
-      CHARACTER (len=5) ::   aname   !
-      INTEGER , DIMENSION(:), ALLOCATABLE ::   ddims
-      INTEGER,  DIMENSION(jpi,jpj) ::   data_src
+      CHARACTER (len=5) ::   clname   !
+      INTEGER , DIMENSION(4) ::   ddims
+      INTEGER                ::   isrc
       REAL(wp), DIMENSION(jpi,jpj) ::   data_tmp
       !!----------------------------------------------------------------------
@@ -1143,20 +1119,8 @@
       !! current weights file
 
-      !! open input data file (non-model grid)
-      CALL iom_open( sd%clname, inum, ldiof =  LEN(TRIM(sd%wgtname)) > 0 )
-
-      !! get dimensions: we consider 2D data as 3D data with vertical dim size = 1
-      IF( SIZE(sd%fnow, 3) > 0 ) THEN
-         ALLOCATE( ddims(4) )
-      ELSE
-         ALLOCATE( ddims(3) )
-      ENDIF
-      id = iom_varid( inum, sd%clvar, ddims )
-
-      !! close it
-      CALL iom_close( inum )
+      !! get data grid dimensions
+      id = iom_varid( sd%num, sd%clvar, ddims )
 
       !! now open the weights file
-
       CALL iom_open ( sd%wgtname, inum )   ! interpolation weights
       IF( inum > 0 ) THEN
@@ -1194,35 +1158,34 @@
          !! two possible cases: bilinear (4 weights) or bicubic (16 weights)
          id = iom_varid(inum, 'src05', ldstop=.FALSE.)
-         IF( id <= 0) THEN
-            ref_wgts(nxt_wgt)%numwgt = 4
-         ELSE
-            ref_wgts(nxt_wgt)%numwgt = 16
-         ENDIF
-
-         ALLOCATE( ref_wgts(nxt_wgt)%data_jpi(jpi,jpj,4) )
-         ALLOCATE( ref_wgts(nxt_wgt)%data_jpj(jpi,jpj,4) )
-         ALLOCATE( ref_wgts(nxt_wgt)%data_wgt(jpi,jpj,ref_wgts(nxt_wgt)%numwgt) )
+         IF( id <= 0 ) THEN   ;   ref_wgts(nxt_wgt)%numwgt = 4
+         ELSE                 ;   ref_wgts(nxt_wgt)%numwgt = 16
+         ENDIF
+
+         ALLOCATE( ref_wgts(nxt_wgt)%data_jpi(Nis0:Nie0,Njs0:Nje0,4) )
+         ALLOCATE( ref_wgts(nxt_wgt)%data_jpj(Nis0:Nie0,Njs0:Nje0,4) )
+         ALLOCATE( ref_wgts(nxt_wgt)%data_wgt(Nis0:Nie0,Njs0:Nje0,ref_wgts(nxt_wgt)%numwgt) )
 
          DO jn = 1,4
-            aname = ' '
-            WRITE(aname,'(a3,i2.2)') 'src',jn
-            data_tmp(:,:) = 0
-            CALL iom_get ( inum, jpdom_data, aname, data_tmp(:,:) )
-            data_src(:,:) = INT(data_tmp(:,:))
-            ref_wgts(nxt_wgt)%data_jpj(:,:,jn) = 1 + (data_src(:,:)-1) / ref_wgts(nxt_wgt)%ddims(1)
-            ref_wgts(nxt_wgt)%data_jpi(:,:,jn) = data_src(:,:) - ref_wgts(nxt_wgt)%ddims(1)*(ref_wgts(nxt_wgt)%data_jpj(:,:,jn)-1)
+            WRITE(clname,'(a3,i2.2)') 'src',jn
+            CALL iom_get ( inum, jpdom_global, clname, data_tmp(:,:), cd_type = 'Z' )   !  no call to lbc_lnk
+            DO_2D( 0, 0, 0, 0 )
+               isrc = NINT(data_tmp(ji,jj)) - 1
+               ref_wgts(nxt_wgt)%data_jpi(ji,jj,jn) = 1 + MOD(isrc,  ref_wgts(nxt_wgt)%ddims(1))
+               ref_wgts(nxt_wgt)%data_jpj(ji,jj,jn) = 1 +     isrc / ref_wgts(nxt_wgt)%ddims(1)
+            END_2D
          END DO
 
          DO jn = 1, ref_wgts(nxt_wgt)%numwgt
-            aname = ' '
-            WRITE(aname,'(a3,i2.2)') 'wgt',jn
-            ref_wgts(nxt_wgt)%data_wgt(:,:,jn) = 0.0
-            CALL iom_get ( inum, jpdom_data, aname, ref_wgts(nxt_wgt)%data_wgt(:,:,jn) )
+            WRITE(clname,'(a3,i2.2)') 'wgt',jn
+            CALL iom_get ( inum, jpdom_global, clname, data_tmp(:,:), cd_type = 'Z' )   !  no call to lbc_lnk
+            DO_2D( 0, 0, 0, 0 )
+               ref_wgts(nxt_wgt)%data_wgt(ji,jj,jn) = data_tmp(ji,jj)
+            END_2D
          END DO
          CALL iom_close (inum)
  
          ! find min and max indices in grid
-         ref_wgts(nxt_wgt)%botleft(1) = MINVAL(ref_wgts(nxt_wgt)%data_jpi(:,:,:))
-         ref_wgts(nxt_wgt)%botleft(2) = MINVAL(ref_wgts(nxt_wgt)%data_jpj(:,:,:))
+         ref_wgts(nxt_wgt)%botleft( 1) = MINVAL(ref_wgts(nxt_wgt)%data_jpi(:,:,:))
+         ref_wgts(nxt_wgt)%botleft( 2) = MINVAL(ref_wgts(nxt_wgt)%data_jpj(:,:,:))
          ref_wgts(nxt_wgt)%topright(1) = MAXVAL(ref_wgts(nxt_wgt)%data_jpi(:,:,:))
          ref_wgts(nxt_wgt)%topright(2) = MAXVAL(ref_wgts(nxt_wgt)%data_jpj(:,:,:))
@@ -1248,6 +1211,4 @@
          CALL ctl_stop( '    fld_weight : unable to read the file ' )
       ENDIF
-
-      DEALLOCATE (ddims )
       !
    END SUBROUTINE fld_weight
@@ -1282,7 +1243,9 @@
       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, kstart = rec1_lsm, kcount = 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, kstart = rec1_lsm, kcount = recn_lsm)
       END SELECT
       CALL iom_close( inum )
@@ -1357,6 +1320,5 @@
 
 
-   SUBROUTINE fld_interp( num, clvar, kw, kk, dta,  &
-                          &         nrec, lsmfile)      
+   SUBROUTINE fld_interp( num, clvar, kw, kk, dta, nrec, lsmfile)      
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_interp  ***
@@ -1376,5 +1338,6 @@
       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 ::   ji, jj, jk, jn, jir, jjr           ! loop counters
+      INTEGER ::   ipk
       INTEGER ::   ni, nj                             ! lengths
       INTEGER ::   jpimin,jpiwid                      ! temporary indices
@@ -1387,4 +1350,5 @@
       REAL(wp),DIMENSION(:,:,:), ALLOCATABLE ::   ztmp_fly_dta                 ! local array of values on input grid     
       !!----------------------------------------------------------------------
+      ipk = SIZE(dta, 3)
       !
       !! for weighted interpolation we have weights at four corners of a box surrounding 
@@ -1416,5 +1380,5 @@
 
 
-      IF( LEN( TRIM(lsmfile) ) > 0 ) THEN
+      IF( LEN_TRIM(lsmfile) > 0 ) THEN
       !! indeces for ztmp_fly_dta
       ! --------------------------
@@ -1446,8 +1410,8 @@
          CASE(1)
               CALL iom_get( num, jpdom_unknown, clvar, ztmp_fly_dta(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,1),   &
-                 &                                                                nrec, rec1_lsm, recn_lsm)
+                 &          nrec, kstart = rec1_lsm, kcount = recn_lsm)
          CASE DEFAULT
               CALL iom_get( num, jpdom_unknown, clvar, ztmp_fly_dta(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),   &
-                 &                                                                nrec, rec1_lsm, recn_lsm)
+                 &          nrec, kstart = rec1_lsm, kcount = recn_lsm)
          END SELECT
          CALL apply_seaoverland(lsmfile,ztmp_fly_dta(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),                  &
@@ -1469,5 +1433,5 @@
          
          ref_wgts(kw)%fly_dta(:,:,:) = 0.0
-         CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%fly_dta(jpi1:jpi2,jpj1:jpj2,:), nrec, rec1, recn)
+         CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%fly_dta(jpi1:jpi2,jpj1:jpj2,:), nrec, kstart = rec1, kcount = recn)
       ENDIF
       
@@ -1475,87 +1439,95 @@
       !! first four weights common to both bilinear and bicubic
       !! data_jpi, data_jpj have already been shifted to (1,1) corresponding to botleft
-      !! note that we have to offset by 1 into fly_dta array because of halo
-      dta(:,:,:) = 0.0
-      DO jk = 1,4
-        DO jn = 1, jpj
-          DO jm = 1,jpi
-            ni = ref_wgts(kw)%data_jpi(jm,jn,jk)
-            nj = ref_wgts(kw)%data_jpj(jm,jn,jk)
-            dta(jm,jn,:) = dta(jm,jn,:) + ref_wgts(kw)%data_wgt(jm,jn,jk) * ref_wgts(kw)%fly_dta(ni+1,nj+1,:)
-          END DO
-        END DO
+      !! note that we have to offset by 1 into fly_dta array because of halo added to fly_dta (rec1 definition)
+      dta(:,:,:) = 0._wp
+      DO jn = 1,4
+         DO_3D( 0, 0, 0, 0, 1,ipk )
+            ni = ref_wgts(kw)%data_jpi(ji,jj,jn) + 1
+            nj = ref_wgts(kw)%data_jpj(ji,jj,jn) + 1
+            dta(ji,jj,jk) = dta(ji,jj,jk) + ref_wgts(kw)%data_wgt(ji,jj,jn) * ref_wgts(kw)%fly_dta(ni,nj,jk)
+         END_3D
       END DO
 
       IF(ref_wgts(kw)%numwgt .EQ. 16) THEN
 
-        !! fix up halo points that we couldnt read from file
-        IF( jpi1 == 2 ) THEN
-           ref_wgts(kw)%fly_dta(jpi1-1,:,:) = ref_wgts(kw)%fly_dta(jpi1,:,:)
-        ENDIF
-        IF( jpi2 + jpimin - 1 == ref_wgts(kw)%ddims(1)+1 ) THEN
-           ref_wgts(kw)%fly_dta(jpi2+1,:,:) = ref_wgts(kw)%fly_dta(jpi2,:,:)
-        ENDIF
-        IF( jpj1 == 2 ) THEN
-           ref_wgts(kw)%fly_dta(:,jpj1-1,:) = ref_wgts(kw)%fly_dta(:,jpj1,:)
-        ENDIF
-        IF( jpj2 + jpjmin - 1 == ref_wgts(kw)%ddims(2)+1 .AND. jpj2 .lt. jpjwid+2 ) THEN
-           ref_wgts(kw)%fly_dta(:,jpj2+1,:) = 2.0*ref_wgts(kw)%fly_dta(:,jpj2,:) - ref_wgts(kw)%fly_dta(:,jpj2-1,:)
-        ENDIF
-
-        !! if data grid is cyclic we can do better on east-west edges
-        !! but have to allow for whether first and last columns are coincident
-        IF( ref_wgts(kw)%cyclic ) THEN
-           rec1(2) = MAX( jpjmin-1, 1 )
-           recn(1) = 1
-           recn(2) = MIN( jpjwid+2, ref_wgts(kw)%ddims(2)-rec1(2)+1 )
-           jpj1 = 2 + rec1(2) - jpjmin
-           jpj2 = jpj1 + recn(2) - 1
-           IF( jpi1 == 2 ) THEN
-              rec1(1) = ref_wgts(kw)%ddims(1) - ref_wgts(kw)%overlap
-              CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%col(:,jpj1:jpj2,:), nrec, rec1, recn)
-              ref_wgts(kw)%fly_dta(jpi1-1,jpj1:jpj2,:) = ref_wgts(kw)%col(1,jpj1:jpj2,:)
-           ENDIF
-           IF( jpi2 + jpimin - 1 == ref_wgts(kw)%ddims(1)+1 ) THEN
-              rec1(1) = 1 + ref_wgts(kw)%overlap
-              CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%col(:,jpj1:jpj2,:), nrec, rec1, recn)
-              ref_wgts(kw)%fly_dta(jpi2+1,jpj1:jpj2,:) = ref_wgts(kw)%col(1,jpj1:jpj2,:)
-           ENDIF
-        ENDIF
-
-        ! gradient in the i direction
-        DO jk = 1,4
-          DO jn = 1, jpj
-            DO jm = 1,jpi
-              ni = ref_wgts(kw)%data_jpi(jm,jn,jk)
-              nj = ref_wgts(kw)%data_jpj(jm,jn,jk)
-              dta(jm,jn,:) = dta(jm,jn,:) + ref_wgts(kw)%data_wgt(jm,jn,jk+4) * 0.5 *         &
-                               (ref_wgts(kw)%fly_dta(ni+2,nj+1,:) - ref_wgts(kw)%fly_dta(ni,nj+1,:))
-            END DO
-          END DO
-        END DO
-
-        ! gradient in the j direction
-        DO jk = 1,4
-          DO jn = 1, jpj
-            DO jm = 1,jpi
-              ni = ref_wgts(kw)%data_jpi(jm,jn,jk)
-              nj = ref_wgts(kw)%data_jpj(jm,jn,jk)
-              dta(jm,jn,:) = dta(jm,jn,:) + ref_wgts(kw)%data_wgt(jm,jn,jk+8) * 0.5 *         &
-                               (ref_wgts(kw)%fly_dta(ni+1,nj+2,:) - ref_wgts(kw)%fly_dta(ni+1,nj,:))
-            END DO
-          END DO
-        END DO
-
-         ! gradient in the ij direction
-         DO jk = 1,4
-            DO jn = 1, jpj
-               DO jm = 1,jpi
-                  ni = ref_wgts(kw)%data_jpi(jm,jn,jk)
-                  nj = ref_wgts(kw)%data_jpj(jm,jn,jk)
-                  dta(jm,jn,:) = dta(jm,jn,:) + ref_wgts(kw)%data_wgt(jm,jn,jk+12) * 0.25 * ( &
-                               (ref_wgts(kw)%fly_dta(ni+2,nj+2,:) - ref_wgts(kw)%fly_dta(ni  ,nj+2,:)) -   &
-                               (ref_wgts(kw)%fly_dta(ni+2,nj  ,:) - ref_wgts(kw)%fly_dta(ni  ,nj  ,:)))
-               END DO
-            END DO
+         !! fix up halo points that we couldnt read from file
+         IF( jpi1 == 2 ) THEN
+            ref_wgts(kw)%fly_dta(jpi1-1,:,:) = ref_wgts(kw)%fly_dta(jpi1,:,:)
+         ENDIF
+         IF( jpi2 + jpimin - 1 == ref_wgts(kw)%ddims(1)+1 ) THEN
+            ref_wgts(kw)%fly_dta(jpi2+1,:,:) = ref_wgts(kw)%fly_dta(jpi2,:,:)
+         ENDIF
+         IF( jpj1 == 2 ) THEN
+            ref_wgts(kw)%fly_dta(:,jpj1-1,:) = ref_wgts(kw)%fly_dta(:,jpj1,:)
+         ENDIF
+         IF( jpj2 + jpjmin - 1 == ref_wgts(kw)%ddims(2)+1 .AND. jpj2 .LT. jpjwid+2 ) THEN
+            ref_wgts(kw)%fly_dta(:,jpj2+1,:) = 2.0*ref_wgts(kw)%fly_dta(:,jpj2,:) - ref_wgts(kw)%fly_dta(:,jpj2-1,:)
+         ENDIF
+         
+         !! if data grid is cyclic we can do better on east-west edges
+         !! but have to allow for whether first and last columns are coincident
+         IF( ref_wgts(kw)%cyclic ) THEN
+            rec1(2) = MAX( jpjmin-1, 1 )
+            recn(1) = 1
+            recn(2) = MIN( jpjwid+2, ref_wgts(kw)%ddims(2)-rec1(2)+1 )
+            jpj1 = 2 + rec1(2) - jpjmin
+            jpj2 = jpj1 + recn(2) - 1
+            IF( jpi1 == 2 ) THEN
+               rec1(1) = ref_wgts(kw)%ddims(1) - ref_wgts(kw)%overlap
+               CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%col(:,jpj1:jpj2,:), nrec, kstart = rec1, kcount = recn)
+               ref_wgts(kw)%fly_dta(jpi1-1,jpj1:jpj2,:) = ref_wgts(kw)%col(1,jpj1:jpj2,:)
+            ENDIF
+            IF( jpi2 + jpimin - 1 == ref_wgts(kw)%ddims(1)+1 ) THEN
+               rec1(1) = 1 + ref_wgts(kw)%overlap
+               CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%col(:,jpj1:jpj2,:), nrec, kstart = rec1, kcount = recn)
+               ref_wgts(kw)%fly_dta(jpi2+1,jpj1:jpj2,:) = ref_wgts(kw)%col(1,jpj1:jpj2,:)
+            ENDIF
+         ENDIF
+         !
+!!$         DO jn = 1,4
+!!$            DO_3D( 0, 0, 0, 0, 1,ipk )
+!!$               ni = ref_wgts(kw)%data_jpi(ji,jj,jn) + 1
+!!$               nj = ref_wgts(kw)%data_jpj(ji,jj,jn) + 1
+!!$               dta(ji,jj,jk) = dta(ji,jj,jk)   &
+!!$                  ! gradient in the i direction
+!!$                  &            + ref_wgts(kw)%data_wgt(ji,jj,jn+4) * 0.5_wp *                                    &
+!!$                  &                (ref_wgts(kw)%fly_dta(ni+1,nj  ,jk) - ref_wgts(kw)%fly_dta(ni-1,nj  ,jk))     &
+!!$                  ! gradient in the j direction
+!!$                  &            + ref_wgts(kw)%data_wgt(ji,jj,jn+8) * 0.5_wp *                                    &
+!!$                  &                (ref_wgts(kw)%fly_dta(ni  ,nj+1,jk) - ref_wgts(kw)%fly_dta(ni  ,nj-1,jk))     &
+!!$                  ! gradient in the ij direction
+!!$                  &            + ref_wgts(kw)%data_wgt(ji,jj,jn+12) * 0.25_wp *                                  &
+!!$                  &               ((ref_wgts(kw)%fly_dta(ni+1,nj+1,jk) - ref_wgts(kw)%fly_dta(ni-1,nj+1,jk)) -   &
+!!$                  &                (ref_wgts(kw)%fly_dta(ni+1,nj-1,jk) - ref_wgts(kw)%fly_dta(ni-1,nj-1,jk)))
+!!$            END_3D
+!!$         END DO
+         !
+         DO jn = 1,4
+            DO_3D( 0, 0, 0, 0, 1,ipk )
+               ni = ref_wgts(kw)%data_jpi(ji,jj,jn)
+               nj = ref_wgts(kw)%data_jpj(ji,jj,jn)
+               ! gradient in the i direction
+               dta(ji,jj,jk) = dta(ji,jj,jk) + ref_wgts(kw)%data_wgt(ji,jj,jn+4) * 0.5_wp *         &
+                  &                (ref_wgts(kw)%fly_dta(ni+2,nj+1,jk) - ref_wgts(kw)%fly_dta(ni  ,nj+1,jk))
+            END_3D
+         END DO
+         DO jn = 1,4
+            DO_3D( 0, 0, 0, 0, 1,ipk )
+               ni = ref_wgts(kw)%data_jpi(ji,jj,jn)
+               nj = ref_wgts(kw)%data_jpj(ji,jj,jn)
+               ! gradient in the j direction
+               dta(ji,jj,jk) = dta(ji,jj,jk) + ref_wgts(kw)%data_wgt(ji,jj,jn+8) * 0.5_wp *         &
+                  &                (ref_wgts(kw)%fly_dta(ni+1,nj+2,jk) - ref_wgts(kw)%fly_dta(ni+1,nj  ,jk))
+            END_3D
+         END DO
+         DO jn = 1,4
+            DO_3D( 0, 0, 0, 0, 1,ipk )
+               ni = ref_wgts(kw)%data_jpi(ji,jj,jn)
+               nj = ref_wgts(kw)%data_jpj(ji,jj,jn)
+               ! gradient in the ij direction
+               dta(ji,jj,jk) = dta(ji,jj,jk) + ref_wgts(kw)%data_wgt(ji,jj,jn+12) * 0.25_wp * (     &
+                  &                (ref_wgts(kw)%fly_dta(ni+2,nj+2,jk) - ref_wgts(kw)%fly_dta(ni  ,nj+2,jk)) -   &
+                  &                (ref_wgts(kw)%fly_dta(ni+2,nj  ,jk) - ref_wgts(kw)%fly_dta(ni  ,nj  ,jk)))
+            END_3D
          END DO
          !
@@ -1584,10 +1556,10 @@
       IF( .NOT. sdjf%ln_clim ) THEN   
                                          WRITE(clname, '(a,"_y",i4.4)' ) TRIM( sdjf%clrootname ), kyear    ! add year
-         IF( sdjf%cltype /= 'yearly' )   WRITE(clname, '(a, "m",i2.2)' ) TRIM( clname          ), kmonth   ! add month
+         IF( sdjf%clftyp /= 'yearly' )   WRITE(clname, '(a, "m",i2.2)' ) TRIM( clname          ), kmonth   ! add month
       ELSE
          ! build the new filename if climatological data
-         IF( sdjf%cltype /= 'yearly' )   WRITE(clname, '(a,"_m",i2.2)' ) TRIM( sdjf%clrootname ), kmonth   ! add month
-      ENDIF
-      IF(    sdjf%cltype == 'daily' .OR. sdjf%cltype(1:4) == 'week' ) &
+         IF( sdjf%clftyp /= 'yearly' )   WRITE(clname, '(a,"_m",i2.2)' ) TRIM( sdjf%clrootname ), kmonth   ! add month
+      ENDIF
+      IF(    sdjf%clftyp == 'daily' .OR. sdjf%clftyp(1:4) == 'week' ) &
          &                               WRITE(clname, '(a,"d" ,i2.2)' ) TRIM( clname          ), kday     ! add day
 
@@ -1613,5 +1585,5 @@
          IF( cl_week(ijul) == TRIM(cdday) ) EXIT
       END DO
-      IF( ijul .GT. 7 )   CALL ctl_stop( 'ksec_week: wrong day for sdjf%cltype(6:8): '//TRIM(cdday) )
+      IF( ijul .GT. 7 )   CALL ctl_stop( 'ksec_week: wrong day for sdjf%clftyp(6:8): '//TRIM(cdday) )
       !
       ishift = ijul * NINT(rday)
