New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 13899 for NEMO/branches/2020/tickets_icb_1900/src/OCE/SBC/fldread.F90 – NEMO

Ignore:
Timestamp:
2020-11-27T17:26:33+01:00 (4 years ago)
Author:
mathiot
Message:

ticket #1900: update branch to trunk and add ICB test case

Location:
NEMO/branches/2020/tickets_icb_1900
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2020/tickets_icb_1900

    • Property svn:externals
      •  

        old new  
        22^/utils/build/makenemo@HEAD   makenemo 
        33^/utils/build/mk@HEAD         mk 
        4 ^/utils/tools/@HEAD           tools 
         4^/utils/tools@HEAD            tools 
        55^/vendors/AGRIF/dev_r12970_AGRIF_CMEMS      ext/AGRIF 
        66^/vendors/FCM@HEAD            ext/FCM 
         
        88 
        99# SETTE 
        10 ^/utils/CI/sette@12931        sette 
         10^/utils/CI/sette@13559        sette 
  • NEMO/branches/2020/tickets_icb_1900/src/OCE/SBC/fldread.F90

    r13237 r13899  
    5353      LOGICAL              ::   ln_tint     ! time interpolation or not (T/F) 
    5454      LOGICAL              ::   ln_clim     ! climatology or not (T/F) 
    55       CHARACTER(len = 8)   ::   cltype      ! type of data file 'daily', 'monthly' or yearly' 
     55      CHARACTER(len = 8)   ::   clftyp      ! type of data file 'daily', 'monthly' or yearly' 
    5656      CHARACTER(len = 256) ::   wname       ! generic name of a NetCDF weights file to be used, blank if not 
    5757      CHARACTER(len = 34)  ::   vcomp       ! symbolic component name if a vector that needs rotation 
     
    6969      LOGICAL                         ::   ln_tint      ! time interpolation or not (T/F) 
    7070      LOGICAL                         ::   ln_clim      ! climatology or not (T/F) 
    71       CHARACTER(len = 8)              ::   cltype       ! type of data file 'daily', 'monthly' or yearly' 
     71      CHARACTER(len = 8)              ::   clftyp       ! type of data file 'daily', 'monthly' or yearly' 
     72      CHARACTER(len = 1)              ::   cltype       ! nature of grid-points: T, U, V... 
     73      REAL(wp)                        ::   zsgn         ! -1. the sign change across the north fold, =  1. otherwise 
    7274      INTEGER                         ::   num          ! iom id of the jpfld files to be read 
    73       INTEGER , DIMENSION(2)          ::   nrec_b       ! before record (1: index, 2: second since Jan. 1st 00h of nit000 year) 
    74       INTEGER , DIMENSION(2)          ::   nrec_a       ! after  record (1: index, 2: second since Jan. 1st 00h of nit000 year) 
    75       INTEGER , ALLOCATABLE, DIMENSION(:      ) ::   nrecsec   !  
    76       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:  ) ::   fnow   ! input fields interpolated to now time step 
    77       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   fdta   ! 2 consecutive record of input fields 
     75      INTEGER , DIMENSION(2,2)        ::   nrec         ! before/after record (1: index, 2: second since Jan. 1st 00h of yr nit000) 
     76      INTEGER                         ::   nbb          ! index of before values 
     77      INTEGER                         ::   naa          ! index of after  values 
     78      INTEGER , ALLOCATABLE, DIMENSION(:) ::   nrecsec   !  
     79      REAL(wp), POINTER, DIMENSION(:,:,:  ) ::   fnow   ! input fields interpolated to now time step 
     80      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   fdta   ! 2 consecutive record of input fields 
    7881      CHARACTER(len = 256)            ::   wgtname      ! current name of the NetCDF weight file acting as a key 
    7982      !                                                 ! into the WGTLIST structure 
     
    157160      INTEGER  ::   jf           ! dummy indices 
    158161      INTEGER  ::   isecsbc      ! number of seconds between Jan. 1st 00h of nit000 year and the middle of sbc time step 
     162      INTEGER  ::   ibb, iaa     ! shorter name for sd(jf)%nbb and sd(jf)%naa 
    159163      LOGICAL  ::   ll_firstcall ! true if this is the first call to fld_read for this set of fields 
    160164      REAL(wp) ::   zt_offset    ! local time offset variable 
     
    204208            IF( TRIM(sd(jf)%clrootname) == 'NOT USED' )   CYCLE 
    205209            ! 
     210            ibb = sd(jf)%nbb   ;   iaa = sd(jf)%naa 
     211            ! 
    206212            IF( sd(jf)%ln_tint ) THEN              ! temporal interpolation 
    207213               IF(lwp .AND. kt - nit000 <= 100 ) THEN  
     
    209215                     &    "', records b/a: ', i6.4, '/', i6.4, ' (days ', f9.4,'/', f9.4, ')')" 
    210216                  WRITE(numout, clfmt)  TRIM( sd(jf)%clvar ), kt, REAL(isecsbc,wp)/rday, nyear, nmonth, nday,   &             
    211                      & 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 
    212                   WRITE(numout, *) '      zt_offset is : ',zt_offset 
     217                     & 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 
     218                  IF( zt_offset /= 0._wp )   WRITE(numout, *) '      zt_offset is : ', zt_offset 
    213219               ENDIF 
    214220               ! temporal interpolation weights 
    215                ztinta =  REAL( isecsbc - sd(jf)%nrec_b(2), wp ) / REAL( sd(jf)%nrec_a(2) - sd(jf)%nrec_b(2), wp ) 
     221               ztinta =  REAL( isecsbc - sd(jf)%nrec(2,ibb), wp ) / REAL( sd(jf)%nrec(2,iaa) - sd(jf)%nrec(2,ibb), wp ) 
    216222               ztintb =  1. - ztinta 
    217                sd(jf)%fnow(:,:,:) = ztintb * sd(jf)%fdta(:,:,:,1) + ztinta * sd(jf)%fdta(:,:,:,2) 
     223               sd(jf)%fnow(:,:,:) = ztintb * sd(jf)%fdta(:,:,:,ibb) + ztinta * sd(jf)%fdta(:,:,:,iaa) 
    218224            ELSE   ! nothing to do... 
    219225               IF(lwp .AND. kt - nit000 <= 100 ) THEN 
     
    221227                     &    "', record: ', i6.4, ' (days ', f9.4, ' <-> ', f9.4, ')')" 
    222228                  WRITE(numout, clfmt) TRIM(sd(jf)%clvar), kt, REAL(isecsbc,wp)/rday, nyear, nmonth, nday,    & 
    223                      &                 sd(jf)%nrec_a(1), REAL(sd(jf)%nrec_b(2),wp)/rday, REAL(sd(jf)%nrec_a(2),wp)/rday 
     229                     &                 sd(jf)%nrec(1,iaa), REAL(sd(jf)%nrec(2,ibb),wp)/rday, REAL(sd(jf)%nrec(2,iaa),wp)/rday 
    224230               ENDIF 
    225231            ENDIF 
     
    251257      ! 
    252258      CALL fld_clopn( sdjf ) 
    253       sdjf%nrec_a(:) = (/ 1, nflag /)  ! default definition to force flp_update to read the file. 
     259      sdjf%nrec(:,sdjf%naa) = (/ 1, nflag /)  ! default definition to force flp_update to read the file. 
    254260      ! 
    255261   END SUBROUTINE fld_init 
     
    262268      !! ** Purpose : Compute 
    263269      !!              if sdjf%ln_tint = .TRUE. 
    264       !!                  nrec_a: record number and its time (nrec_b is obtained from nrec_a when swapping) 
     270      !!                  nrec(:,iaa): record number and its time (nrec(:,ibb) is obtained from nrec(:,iaa) when swapping) 
    265271      !!              if sdjf%ln_tint = .FALSE. 
    266       !!                  nrec_a(1): record number 
    267       !!                  nrec_b(2) and nrec_a(2): time of the beginning and end of the record 
     272      !!                  nrec(1,iaa): record number 
     273      !!                  nrec(2,ibb) and nrec(2,iaa): time of the beginning and end of the record 
    268274      !!---------------------------------------------------------------------- 
    269275      INTEGER  ,           INTENT(in   ) ::   ksecsbc   !  
     
    271277      INTEGER  , OPTIONAL, INTENT(in   ) ::   Kmm    ! ocean time level index 
    272278      ! 
    273       INTEGER  ::   ja     ! end of this record (in seconds) 
    274       !!---------------------------------------------------------------------- 
    275       ! 
    276       IF( ksecsbc > sdjf%nrec_a(2) ) THEN     ! --> we need to update after data 
     279      INTEGER  ::   ja           ! end of this record (in seconds) 
     280      INTEGER  ::   ibb, iaa     ! shorter name for sdjf%nbb and sdjf%naa 
     281      !!---------------------------------------------------------------------- 
     282      ibb = sdjf%nbb   ;   iaa = sdjf%naa 
     283      ! 
     284      IF( ksecsbc > sdjf%nrec(2,iaa) ) THEN     ! --> we need to update after data 
    277285         
    278          ! find where is the new after record... (it is not necessary sdjf%nrec_a(1)+1 ) 
    279          ja = sdjf%nrec_a(1) 
     286         ! find where is the new after record... (it is not necessary sdjf%nrec(1,iaa)+1 ) 
     287         ja = sdjf%nrec(1,iaa) 
    280288         DO WHILE ( ksecsbc >= sdjf%nrecsec(ja) .AND. ja < sdjf%nreclast )   ! Warning: make sure ja <= sdjf%nreclast in this test 
    281289            ja = ja + 1 
     
    284292 
    285293         ! if ln_tint and if the new after is not ja+1, we need also to update after data before the swap 
    286          ! so, after the swap, sdjf%nrec_b(2) will still be the closest value located just before ksecsbc 
    287          IF( sdjf%ln_tint .AND. ( ja > sdjf%nrec_a(1) + 1 .OR. sdjf%nrec_a(2) == nflag ) ) THEN 
    288             sdjf%nrec_a(:) = (/ ja-1, sdjf%nrecsec(ja-1) /)   ! update nrec_a with before information 
    289             CALL fld_get( sdjf, Kmm )                         ! read after data that will be used as before data 
     294         ! so, after the swap, sdjf%nrec(2,ibb) will still be the closest value located just before ksecsbc 
     295         IF( sdjf%ln_tint .AND. ( ja > sdjf%nrec(1,iaa) + 1 .OR. sdjf%nrec(2,iaa) == nflag ) ) THEN 
     296            sdjf%nrec(:,iaa) = (/ ja-1, sdjf%nrecsec(ja-1) /)   ! update nrec(:,iaa) with before information 
     297            CALL fld_get( sdjf, Kmm )                           ! read after data that will be used as before data 
    290298         ENDIF 
    291299             
     
    310318            ! if ln_tint and if after is not the first record, we must (potentially again) update after data before the swap 
    311319            IF( sdjf%ln_tint .AND. ja > 1 ) THEN 
    312                IF( sdjf%nrecsec(0) /= nflag ) THEN                  ! no trick used: after file is not the current file 
    313                   sdjf%nrec_a(:) = (/ ja-1, sdjf%nrecsec(ja-1) /)   ! update nrec_a with before information 
    314                   CALL fld_get( sdjf, Kmm )                         ! read after data that will be used as before data 
     320               IF( sdjf%nrecsec(0) /= nflag ) THEN                    ! no trick used: after file is not the current file 
     321                  sdjf%nrec(:,iaa) = (/ ja-1, sdjf%nrecsec(ja-1) /)   ! update nrec(:,iaa) with before information 
     322                  CALL fld_get( sdjf, Kmm )                           ! read after data that will be used as before data 
    315323               ENDIF 
    316324            ENDIF 
     
    318326         ENDIF 
    319327 
    320          IF( sdjf%ln_tint ) THEN  
    321             ! Swap data 
    322             sdjf%nrec_b(:)     = sdjf%nrec_a(:)                     ! swap before record informations 
    323             sdjf%rotn(1)       = sdjf%rotn(2)                       ! swap before rotate informations 
    324             sdjf%fdta(:,:,:,1) = sdjf%fdta(:,:,:,2)                 ! swap before record field 
    325          ELSE 
    326             sdjf%nrec_b(:) = (/ ja-1, sdjf%nrecsec(ja-1) /)         ! only for print  
     328         IF( sdjf%ln_tint ) THEN                                ! Swap data 
     329            sdjf%nbb = sdjf%naa                                 !    swap indices 
     330            sdjf%naa = 3 - sdjf%naa                             !    = 2(1) if naa == 1(2) 
     331         ELSE                                                   ! No swap 
     332            sdjf%nrec(:,ibb) = (/ ja-1, sdjf%nrecsec(ja-1) /)   !    only for print  
    327333         ENDIF 
    328334             
    329335         ! read new after data 
    330          sdjf%nrec_a(:) = (/ ja, sdjf%nrecsec(ja) /)                ! update nrec_a as it is used by fld_get 
    331          CALL fld_get( sdjf, Kmm )                                  ! read after data (with nrec_a informations) 
     336         sdjf%nrec(:,sdjf%naa) = (/ ja, sdjf%nrecsec(ja) /)     ! update nrec(:,naa) as it is used by fld_get 
     337         CALL fld_get( sdjf, Kmm )                              ! read after data (with nrec(:,naa) informations) 
    332338         
    333339      ENDIF 
     
    346352      ! 
    347353      INTEGER ::   ipk      ! number of vertical levels of sdjf%fdta ( 2D: ipk=1 ; 3D: ipk=jpk ) 
     354      INTEGER ::   iaa      ! shorter name for sdjf%naa 
    348355      INTEGER ::   iw       ! index into wgts array 
    349       INTEGER ::   ipdom    ! index of the domain 
    350356      INTEGER ::   idvar    ! variable ID 
    351357      INTEGER ::   idmspc   ! number of spatial dimensions 
    352358      LOGICAL ::   lmoor    ! C1D case: point data 
    353       !!--------------------------------------------------------------------- 
    354       ! 
    355       ipk = SIZE( sdjf%fnow, 3 ) 
    356       ! 
    357       IF( ASSOCIATED(sdjf%imap) ) THEN 
    358          IF( sdjf%ln_tint ) THEN   ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1),   & 
    359             &                                        sdjf%imap, sdjf%igrd, sdjf%ibdy, sdjf%ltotvel, sdjf%lzint, Kmm ) 
    360          ELSE                      ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1),   & 
    361             &                                        sdjf%imap, sdjf%igrd, sdjf%ibdy, sdjf%ltotvel, sdjf%lzint, Kmm ) 
    362          ENDIF 
    363       ELSE IF( LEN(TRIM(sdjf%wgtname)) > 0 ) THEN 
     359      REAL(wp), DIMENSION(:,:,:), POINTER ::   dta_alias   ! short cut 
     360      !!--------------------------------------------------------------------- 
     361      iaa = sdjf%naa 
     362      ! 
     363      IF( sdjf%ln_tint ) THEN   ;   dta_alias => sdjf%fdta(:,:,:,iaa) 
     364      ELSE                      ;   dta_alias => sdjf%fnow(:,:,:    ) 
     365      ENDIF 
     366      ipk = SIZE( dta_alias, 3 ) 
     367      ! 
     368      IF( ASSOCIATED(sdjf%imap) ) THEN              ! BDY case  
     369         CALL fld_map( sdjf%num, sdjf%clvar, dta_alias(:,:,:), sdjf%nrec(1,iaa),   & 
     370            &          sdjf%imap, sdjf%igrd, sdjf%ibdy, sdjf%ltotvel, sdjf%lzint, Kmm ) 
     371      ELSE IF( LEN(TRIM(sdjf%wgtname)) > 0 ) THEN   ! On-the-fly interpolation 
    364372         CALL wgt_list( sdjf, iw ) 
    365          IF( sdjf%ln_tint ) THEN   ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw, ipk, sdjf%fdta(:,:,:,2),          &  
    366             &                                                                          sdjf%nrec_a(1), sdjf%lsmname ) 
    367          ELSE                      ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw, ipk, sdjf%fnow(:,:,:  ),          & 
    368             &                                                                          sdjf%nrec_a(1), sdjf%lsmname ) 
    369          ENDIF 
    370       ELSE 
    371          IF( SIZE(sdjf%fnow, 1) == jpi ) THEN   ;   ipdom = jpdom_data 
    372          ELSE                                   ;   ipdom = jpdom_unknown 
    373          ENDIF 
     373         CALL fld_interp( sdjf%num, sdjf%clvar, iw, ipk, dta_alias(:,:,:), sdjf%nrec(1,iaa), sdjf%lsmname ) 
     374         CALL lbc_lnk( 'fldread', dta_alias(:,:,:), sdjf%cltype, sdjf%zsgn, kfillmode = jpfillcopy ) 
     375      ELSE                                          ! default case 
    374376         ! C1D case: If product of spatial dimensions == ipk, then x,y are of 
    375377         ! size 1 (point/mooring data): this must be read onto the central grid point 
    376378         idvar  = iom_varid( sdjf%num, sdjf%clvar ) 
    377379         idmspc = iom_file ( sdjf%num )%ndims( idvar ) 
    378          IF( iom_file( sdjf%num )%luld( idvar ) )   idmspc = idmspc - 1 
    379          lmoor  = (  idmspc == 0 .OR. PRODUCT( iom_file( sdjf%num )%dimsz( 1:MAX(idmspc,1) ,idvar ) ) == ipk  ) 
    380          ! 
    381          SELECT CASE( ipk ) 
    382          CASE(1) 
    383             IF( lk_c1d .AND. lmoor ) THEN 
    384                IF( sdjf%ln_tint ) THEN 
    385                   CALL iom_get( sdjf%num, sdjf%clvar, sdjf%fdta(2,2,1,2), sdjf%nrec_a(1) ) 
    386                   CALL lbc_lnk( 'fldread', sdjf%fdta(:,:,1,2),'Z',1.0_wp ) 
    387                ELSE 
    388                   CALL iom_get( sdjf%num, sdjf%clvar, sdjf%fnow(2,2,1  ), sdjf%nrec_a(1) ) 
    389                   CALL lbc_lnk( 'fldread', sdjf%fnow(:,:,1  ),'Z',1.0_wp ) 
    390                ENDIF 
    391             ELSE 
    392                IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,1,2), sdjf%nrec_a(1) ) 
    393                ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,1  ), sdjf%nrec_a(1) ) 
    394                ENDIF 
    395             ENDIF 
    396          CASE DEFAULT 
    397             IF(lk_c1d .AND. lmoor ) THEN 
    398                IF( sdjf%ln_tint ) THEN 
    399                   CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, sdjf%fdta(2,2,:,2), sdjf%nrec_a(1) ) 
    400                   CALL lbc_lnk( 'fldread', sdjf%fdta(:,:,:,2),'Z',1.0_wp ) 
    401                ELSE 
    402                   CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, sdjf%fnow(2,2,:  ), sdjf%nrec_a(1) ) 
    403                   CALL lbc_lnk( 'fldread', sdjf%fnow(:,:,:  ),'Z',1.0_wp ) 
    404                ENDIF 
    405             ELSE 
    406                IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1) ) 
    407                ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1) ) 
    408                ENDIF 
    409             ENDIF 
    410          END SELECT 
    411       ENDIF 
    412       ! 
    413       sdjf%rotn(2) = .false.   ! vector not yet rotated 
     380         IF( iom_file( sdjf%num )%luld( idvar ) )   idmspc = idmspc - 1   ! id of the last spatial dimension 
     381         lmoor  = (  idmspc == 0 .OR. PRODUCT( iom_file( sdjf%num )%dimsz( 1:MAX(idmspc,1) ,idvar ) ) == ipk  )     
     382         ! 
     383         IF( lk_c1d .AND. lmoor ) THEN 
     384            CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, dta_alias(2,2,:), sdjf%nrec(1,iaa) )   ! jpdom_unknown -> no lbc_lnk 
     385            CALL lbc_lnk( 'fldread', dta_alias(:,:,:), 'T', 1., kfillmode = jpfillcopy ) 
     386         ELSE 
     387            CALL iom_get( sdjf%num,  jpdom_global, sdjf%clvar, dta_alias(:,:,:), sdjf%nrec(1,iaa),   & 
     388               &          sdjf%cltype, sdjf%zsgn, kfill = jpfillcopy ) 
     389         ENDIF 
     390      ENDIF 
     391      ! 
     392      sdjf%rotn(iaa) = .false.   ! vector not yet rotated 
    414393      ! 
    415394   END SUBROUTINE fld_get 
     
    447426      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   zdta_read_z  ! work space local data requiring vertical interpolation 
    448427      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   zdta_read_dz ! work space local data requiring vertical interpolation 
    449       CHARACTER(LEN=1),DIMENSION(3)             ::   clgrid 
     428      CHARACTER(LEN=1),DIMENSION(3)             ::   cltype 
    450429      LOGICAL                                   ::   lluld        ! is the variable using the unlimited dimension 
    451430      LOGICAL                                   ::   llzint       ! local value of ldzint 
    452431      !!--------------------------------------------------------------------- 
    453432      ! 
    454       clgrid = (/'t','u','v'/) 
     433      cltype = (/'t','u','v'/) 
    455434      ! 
    456435      ipi = SIZE( pdta, 1 ) 
     
    487466         IF( ipkb /= ipk .OR. llzint ) THEN   ! boundary data not on model vertical grid : vertical interpolation 
    488467            ! 
    489             IF( ipk == jpk .AND. iom_varid(knum,'gdep'//clgrid(kgrd)) /= -1 .AND. iom_varid(knum,'e3'//clgrid(kgrd)) /= -1 ) THEN 
     468            IF( ipk == jpk .AND. iom_varid(knum,'gdep'//cltype(kgrd)) /= -1 .AND. iom_varid(knum,'e3'//cltype(kgrd)) /= -1 ) THEN 
    490469                
    491470               ALLOCATE( zdta_read(ipi,ipj,ipkb), zdta_read_z(ipi,ipj,ipkb), zdta_read_dz(ipi,ipj,ipkb) ) 
    492471                 
    493472               CALL fld_map_core( zz_read, kmap, zdta_read ) 
    494                CALL iom_get ( knum, jpdom_unknown, 'gdep'//clgrid(kgrd), zz_read )   ! read only once? Potential temporal evolution? 
     473               CALL iom_get ( knum, jpdom_unknown, 'gdep'//cltype(kgrd), zz_read )   ! read only once? Potential temporal evolution? 
    495474               CALL fld_map_core( zz_read, kmap, zdta_read_z ) 
    496                CALL iom_get ( knum, jpdom_unknown,   'e3'//clgrid(kgrd), zz_read )   ! read only once? Potential temporal evolution? 
     475               CALL iom_get ( knum, jpdom_unknown,   'e3'//cltype(kgrd), zz_read )   ! read only once? Potential temporal evolution? 
    497476               CALL fld_map_core( zz_read, kmap, zdta_read_dz ) 
    498477                
     
    504483               IF( ipk /= jpk ) CALL ctl_stop( 'fld_map : this should be an impossible case...' ) 
    505484               WRITE(ctmp1,*) 'fld_map : vertical interpolation for bdy variable '//TRIM(cdvar)//' requires '  
    506                IF( iom_varid(knum, 'gdep'//clgrid(kgrd)) == -1 ) CALL ctl_stop( ctmp1//'gdep'//clgrid(kgrd)//' variable' ) 
    507                IF( iom_varid(knum,   'e3'//clgrid(kgrd)) == -1 ) CALL ctl_stop( ctmp1//  'e3'//clgrid(kgrd)//' variable' ) 
     485               IF( iom_varid(knum, 'gdep'//cltype(kgrd)) == -1 ) CALL ctl_stop( ctmp1//'gdep'//cltype(kgrd)//' variable' ) 
     486               IF( iom_varid(knum,   'e3'//cltype(kgrd)) == -1 ) CALL ctl_stop( ctmp1//  'e3'//cltype(kgrd)//' variable' ) 
    508487 
    509488            ENDIF 
     
    728707      CHARACTER (LEN=100)          ::   clcomp       ! dummy weight name 
    729708      REAL(wp), DIMENSION(jpi,jpj) ::   utmp, vtmp   ! temporary arrays for vector rotation 
     709      REAL(wp), DIMENSION(:,:,:), POINTER ::   dta_u, dta_v    ! short cut 
    730710      !!--------------------------------------------------------------------- 
    731711      ! 
     
    747727                  END DO 
    748728                  IF( iv > 0 ) THEN   ! fields ju and iv are two components which need to be rotated together 
     729                     IF( sd(ju)%ln_tint ) THEN   ;   dta_u => sd(ju)%fdta(:,:,:,jn)   ;   dta_v => sd(iv)%fdta(:,:,:,jn)  
     730                     ELSE                        ;   dta_u => sd(ju)%fnow(:,:,:   )   ;   dta_v => sd(iv)%fnow(:,:,:   ) 
     731                     ENDIF 
    749732                     DO jk = 1, SIZE( sd(ju)%fnow, 3 ) 
    750                         IF( sd(ju)%ln_tint )THEN 
    751                            CALL rot_rep( sd(ju)%fdta(:,:,jk,jn), sd(iv)%fdta(:,:,jk,jn), 'T', 'en->i', utmp(:,:) ) 
    752                            CALL rot_rep( sd(ju)%fdta(:,:,jk,jn), sd(iv)%fdta(:,:,jk,jn), 'T', 'en->j', vtmp(:,:) ) 
    753                            sd(ju)%fdta(:,:,jk,jn) = utmp(:,:)   ;   sd(iv)%fdta(:,:,jk,jn) = vtmp(:,:) 
    754                         ELSE  
    755                            CALL rot_rep( sd(ju)%fnow(:,:,jk   ), sd(iv)%fnow(:,:,jk   ), 'T', 'en->i', utmp(:,:) ) 
    756                            CALL rot_rep( sd(ju)%fnow(:,:,jk   ), sd(iv)%fnow(:,:,jk   ), 'T', 'en->j', vtmp(:,:) ) 
    757                            sd(ju)%fnow(:,:,jk   ) = utmp(:,:)   ;   sd(iv)%fnow(:,:,jk   ) = vtmp(:,:) 
    758                         ENDIF 
     733                        CALL rot_rep( dta_u(:,:,jk), dta_v(:,:,jk), 'T', 'en->i', utmp(:,:) ) 
     734                        CALL rot_rep( dta_u(:,:,jk), dta_v(:,:,jk), 'T', 'en->j', vtmp(:,:) ) 
     735                        dta_u(:,:,jk) = utmp(:,:)   ;   dta_v(:,:,jk) = vtmp(:,:) 
    759736                     END DO 
    760737                     sd(ju)%rotn(jn) = .TRUE.               ! vector was rotated  
     
    802779 
    803780      ! current file parameters 
    804       IF( sdjf%cltype(1:4) == 'week' ) THEN          ! find the day of the beginning of the current week 
    805          isecwk = ksec_week( sdjf%cltype(6:8) )     ! seconds between the beginning of the week and half of current time step 
    806          llprevmt = isecwk > nsec_month               ! longer time since beginning of the current week than the current month 
     781      IF( sdjf%clftyp(1:4) == 'week' ) THEN         ! find the day of the beginning of the current week 
     782         isecwk = ksec_week( sdjf%clftyp(6:8) )     ! seconds between the beginning of the week and half of current time step 
     783         llprevmt = isecwk > nsec_month             ! longer time since beginning of the current week than the current month 
    807784         llprevyr = llprevmt .AND. nmonth == 1 
    808785         iyr = nyear  - COUNT((/llprevyr/)) 
    809786         imt = nmonth - COUNT((/llprevmt/)) + 12 * COUNT((/llprevyr/)) 
    810787         idy = nday + nmonth_len(nmonth-1) * COUNT((/llprevmt/)) - isecwk / idaysec 
    811          isecwk = nsec_year - isecwk              ! seconds between 00h jan 1st of current year and current week beginning 
     788         isecwk = nsec_year - isecwk                ! seconds between 00h jan 1st of current year and current week beginning 
    812789      ELSE 
    813790         iyr = nyear 
     
    819796      ! previous file parameters 
    820797      IF( llprev ) THEN 
    821          IF( sdjf%cltype(1:4) == 'week'    ) THEN     ! find the day of the beginning of previous week 
    822             isecwk = isecwk + 7 * idaysec         ! seconds between the beginning of previous week and half of the time step 
    823             llprevmt = isecwk > nsec_month            ! longer time since beginning of the previous week than the current month 
     798         IF( sdjf%clftyp(1:4) == 'week'    ) THEN   ! find the day of the beginning of previous week 
     799            isecwk = isecwk + 7 * idaysec           ! seconds between the beginning of previous week and half of the time step 
     800            llprevmt = isecwk > nsec_month          ! longer time since beginning of the previous week than the current month 
    824801            llprevyr = llprevmt .AND. nmonth == 1 
    825802            iyr = nyear  - COUNT((/llprevyr/)) 
    826803            imt = nmonth - COUNT((/llprevmt/)) + 12 * COUNT((/llprevyr/)) 
    827804            idy = nday + nmonth_len(nmonth-1) * COUNT((/llprevmt/)) - isecwk / idaysec 
    828             isecwk = nsec_year - isecwk           ! seconds between 00h jan 1st of current year and previous week beginning 
     805            isecwk = nsec_year - isecwk             ! seconds between 00h jan 1st of current year and previous week beginning 
    829806         ELSE 
    830             idy = nday   - COUNT((/ sdjf%cltype == 'daily'                 /)) 
    831             imt = nmonth - COUNT((/ sdjf%cltype == 'monthly' .OR. idy == 0 /)) 
    832             iyr = nyear  - COUNT((/ sdjf%cltype == 'yearly'  .OR. imt == 0 /)) 
     807            idy = nday   - COUNT((/ sdjf%clftyp == 'daily'                 /)) 
     808            imt = nmonth - COUNT((/ sdjf%clftyp == 'monthly' .OR. idy == 0 /)) 
     809            iyr = nyear  - COUNT((/ sdjf%clftyp == 'yearly'  .OR. imt == 0 /)) 
    833810            IF( idy == 0 ) idy = nmonth_len(imt) 
    834811            IF( imt == 0 ) imt = 12 
     
    839816      ! next file parameters 
    840817      IF( llnext ) THEN 
    841          IF( sdjf%cltype(1:4) == 'week'    ) THEN     ! find the day of the beginning of next week 
    842             isecwk = 7 * idaysec - isecwk         ! seconds between half of the time step and the beginning of next week 
     818         IF( sdjf%clftyp(1:4) == 'week'    ) THEN   ! find the day of the beginning of next week 
     819            isecwk = 7 * idaysec - isecwk           ! seconds between half of the time step and the beginning of next week 
    843820            llnextmt = isecwk > ( nmonth_len(nmonth)*idaysec - nsec_month )   ! larger than the seconds to the end of the month 
    844821            llnextyr = llnextmt .AND. nmonth == 12 
     
    846823            imt = nmonth + COUNT((/llnextmt/)) - 12 * COUNT((/llnextyr/)) 
    847824            idy = nday - nmonth_len(nmonth) * COUNT((/llnextmt/)) + isecwk / idaysec + 1 
    848             isecwk = nsec_year + isecwk           ! seconds between 00h jan 1st of current year and next week beginning 
     825            isecwk = nsec_year + isecwk             ! seconds between 00h jan 1st of current year and next week beginning 
    849826         ELSE 
    850             idy = nday   + COUNT((/ sdjf%cltype == 'daily'                                 /)) 
    851             imt = nmonth + COUNT((/ sdjf%cltype == 'monthly' .OR. idy > nmonth_len(nmonth) /)) 
    852             iyr = nyear  + COUNT((/ sdjf%cltype == 'yearly'  .OR. imt == 13                /)) 
     827            idy = nday   + COUNT((/ sdjf%clftyp == 'daily'                                 /)) 
     828            imt = nmonth + COUNT((/ sdjf%clftyp == 'monthly' .OR. idy > nmonth_len(nmonth) /)) 
     829            iyr = nyear  + COUNT((/ sdjf%clftyp == 'yearly'  .OR. imt == 13                /)) 
    853830            IF( idy > nmonth_len(nmonth) )   idy = 1 
    854831            IF( imt == 13                )   imt = 1 
     
    867844      IF    ( NINT(sdjf%freqh) == -12 ) THEN            ;   ireclast = 1    ! yearly mean: consider only 1 record 
    868845      ELSEIF( NINT(sdjf%freqh) ==  -1 ) THEN                                ! monthly mean: 
    869          IF(     sdjf%cltype      == 'monthly' ) THEN   ;   ireclast = 1    !  consider that the file has  1 record 
     846         IF(     sdjf%clftyp      == 'monthly' ) THEN   ;   ireclast = 1    !  consider that the file has  1 record 
    870847         ELSE                                           ;   ireclast = 12   !  consider that the file has 12 record 
    871848         ENDIF 
    872849      ELSE                                                                  ! higher frequency mean (in hours) 
    873          IF(     sdjf%cltype      == 'monthly' ) THEN   ;   ireclast = NINT( 24. * REAL(nmonth_len(indexmt), wp) / sdjf%freqh ) 
    874          ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ;   ireclast = NINT( 24. * 7.                            / sdjf%freqh ) 
    875          ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ;   ireclast = NINT( 24.                                 / sdjf%freqh ) 
     850         IF(     sdjf%clftyp      == 'monthly' ) THEN   ;   ireclast = NINT( 24. * REAL(nmonth_len(indexmt), wp) / sdjf%freqh ) 
     851         ELSEIF( sdjf%clftyp(1:4) == 'week'    ) THEN   ;   ireclast = NINT( 24. * 7.                            / sdjf%freqh ) 
     852         ELSEIF( sdjf%clftyp      == 'daily'   ) THEN   ;   ireclast = NINT( 24.                                 / sdjf%freqh ) 
    876853         ELSE                                           ;   ireclast = NINT( 24. * REAL( nyear_len(indexyr), wp) / sdjf%freqh ) 
    877854         ENDIF 
     
    891868         sdjf%nrecsec(1) = sdjf%nrecsec(0) + nyear_len( indexyr ) * idaysec 
    892869      ELSEIF( NINT(sdjf%freqh) ==  -1 ) THEN                                     ! monthly mean: 
    893          IF(     sdjf%cltype      == 'monthly' ) THEN                            !    monthly file 
     870         IF(     sdjf%clftyp      == 'monthly' ) THEN                            !    monthly file 
    894871            sdjf%nrecsec(0   ) = nsec1jan000 + nmonth_beg(indexmt  ) 
    895872            sdjf%nrecsec(1   ) = nsec1jan000 + nmonth_beg(indexmt+1) 
     
    899876         ENDIF 
    900877      ELSE                                                                       ! higher frequency mean (in hours) 
    901          IF(     sdjf%cltype      == 'monthly' ) THEN   ;   istart = nsec1jan000 + nmonth_beg(indexmt) 
    902          ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ;   istart = nsec1jan000 + isecwk 
    903          ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ;   istart = nsec1jan000 + nmonth_beg(indexmt) + ( idy - 1 ) * idaysec 
     878         IF(     sdjf%clftyp      == 'monthly' ) THEN   ;   istart = nsec1jan000 + nmonth_beg(indexmt) 
     879         ELSEIF( sdjf%clftyp(1:4) == 'week'    ) THEN   ;   istart = nsec1jan000 + isecwk 
     880         ELSEIF( sdjf%clftyp      == 'daily'   ) THEN   ;   istart = nsec1jan000 + nmonth_beg(indexmt) + ( idy - 1 ) * idaysec 
    904881         ELSEIF( indexyr          == 0         ) THEN   ;   istart = nsec1jan000 - nyear_len( 0 ) * idaysec 
    905882         ELSEIF( indexyr          == 2         ) THEN   ;   istart = nsec1jan000 + nyear_len( 1 ) * idaysec 
     
    942919      IF( sdjf%num <= 0 .OR. .NOT. sdjf%ln_clim  ) THEN 
    943920         IF( sdjf%num > 0 )   CALL iom_close( sdjf%num )   ! close file if already open 
    944          CALL iom_open( sdjf%clname, sdjf%num, ldstop = llstop, ldiof = LEN(TRIM(sdjf%wgtname)) > 0 ) 
     921         CALL iom_open( sdjf%clname, sdjf%num, ldstop = llstop, ldiof = LEN_TRIM(sdjf%wgtname) > 0 ) 
    945922      ENDIF 
    946923      ! 
     
    964941         ENDIF 
    965942         ! 
    966          CALL iom_open( sdjf%clname, sdjf%num, ldiof = LEN(TRIM(sdjf%wgtname)) > 0 )    
     943         CALL iom_open( sdjf%clname, sdjf%num, ldiof = LEN_TRIM(sdjf%wgtname) > 0 )    
    967944         ! 
    968945      ENDIF 
     
    997974         sdf(jf)%ln_tint    = sdf_n(jf)%ln_tint 
    998975         sdf(jf)%ln_clim    = sdf_n(jf)%ln_clim 
    999          sdf(jf)%cltype     = sdf_n(jf)%cltype 
     976         sdf(jf)%clftyp     = sdf_n(jf)%clftyp 
     977         sdf(jf)%cltype     = 'T'   ! by default don't do any call to lbc_lnk in iom_get 
     978         sdf(jf)%zsgn       = 1.    ! by default don't do change signe across the north fold 
    1000979         sdf(jf)%num        = -1 
     980         sdf(jf)%nbb        = 1  ! start with before data in 1 
     981         sdf(jf)%naa        = 2  ! start with after  data in 2 
    1001982         sdf(jf)%wgtname    = " " 
    1002983         IF( LEN( TRIM(sdf_n(jf)%wname) ) > 0 )   sdf(jf)%wgtname = TRIM( cdir )//sdf_n(jf)%wname 
     
    1005986         sdf(jf)%vcomp      = sdf_n(jf)%vcomp 
    1006987         sdf(jf)%rotn(:)    = .TRUE.   ! pretend to be rotated -> won't try to rotate data before the first call to fld_get 
    1007          IF( sdf(jf)%cltype(1:4) == 'week' .AND. nn_leapy == 0  )   & 
     988         IF( sdf(jf)%clftyp(1:4) == 'week' .AND. nn_leapy == 0  )   & 
    1008989            &   CALL ctl_stop('fld_clopn: weekly file ('//TRIM(sdf(jf)%clrootname)//') needs nn_leapy = 1') 
    1009          IF( sdf(jf)%cltype(1:4) == 'week' .AND. sdf(jf)%ln_clim )   & 
     990         IF( sdf(jf)%clftyp(1:4) == 'week' .AND. sdf(jf)%ln_clim )   & 
    1010991            &   CALL ctl_stop('fld_clopn: weekly file ('//TRIM(sdf(jf)%clrootname)//') needs ln_clim = .FALSE.') 
    1011992         sdf(jf)%nreclast   = -1 ! Set to non zero default value to avoid errors, is updated to meaningful value during fld_clopn 
     
    10331014            WRITE(numout,*) '         weights: '        , TRIM( sdf(jf)%wgtname    ),   & 
    10341015               &                  '   pairing: '        , TRIM( sdf(jf)%vcomp      ),   & 
    1035                &                  '   data type: '      ,       sdf(jf)%cltype      ,   & 
     1016               &                  '   data type: '      ,       sdf(jf)%clftyp      ,   & 
    10361017               &                  '   land/sea mask:'   , TRIM( sdf(jf)%lsmname    ) 
    10371018            call flush(numout) 
     
    10511032      !!---------------------------------------------------------------------- 
    10521033      TYPE( FLD ), INTENT(in   ) ::   sd        ! field with name of weights file 
    1053       INTEGER    , INTENT(inout) ::   kwgt      ! index of weights 
     1034      INTEGER    , INTENT(  out) ::   kwgt      ! index of weights 
    10541035      ! 
    10551036      INTEGER ::   kw, nestid   ! local integer 
    1056       LOGICAL ::   found        ! local logical 
    10571037      !!---------------------------------------------------------------------- 
    10581038      ! 
    10591039      !! search down linked list  
    10601040      !! weights filename is either present or we hit the end of the list 
    1061       found = .FALSE. 
    10621041      ! 
    10631042      !! because agrif nest part of filenames are now added in iom_open 
     
    10691048#endif 
    10701049      DO kw = 1, nxt_wgt-1 
    1071          IF( TRIM(ref_wgts(kw)%wgtname) == TRIM(sd%wgtname) .AND. & 
    1072              ref_wgts(kw)%nestid == nestid) THEN 
     1050         IF( ref_wgts(kw)%wgtname == sd%wgtname .AND. & 
     1051             ref_wgts(kw)%nestid  == nestid) THEN 
    10731052            kwgt = kw 
    1074             found = .TRUE. 
    1075             EXIT 
     1053            RETURN 
    10761054         ENDIF 
    10771055      END DO 
    1078       IF( .NOT.found ) THEN 
    1079          kwgt = nxt_wgt 
    1080          CALL fld_weight( sd ) 
    1081       ENDIF 
     1056      kwgt = nxt_wgt 
     1057      CALL fld_weight( sd ) 
    10821058      ! 
    10831059   END SUBROUTINE wgt_list 
     
    11221098      TYPE( FLD ), INTENT(in) ::   sd   ! field with name of weights file 
    11231099      !! 
    1124       INTEGER ::   jn         ! dummy loop indices 
     1100      INTEGER ::   ji,jj,jn   ! dummy loop indices 
    11251101      INTEGER ::   inum       ! local logical unit 
    11261102      INTEGER ::   id         ! local variable id 
     
    11281104      INTEGER ::   zwrap      ! local integer 
    11291105      LOGICAL ::   cyclical   !  
    1130       CHARACTER (len=5) ::   aname   ! 
    1131       INTEGER , DIMENSION(:), ALLOCATABLE ::   ddims 
    1132       INTEGER,  DIMENSION(jpi,jpj) ::   data_src 
     1106      CHARACTER (len=5) ::   clname   ! 
     1107      INTEGER , DIMENSION(4) ::   ddims 
     1108      INTEGER                ::   isrc 
    11331109      REAL(wp), DIMENSION(jpi,jpj) ::   data_tmp 
    11341110      !!---------------------------------------------------------------------- 
     
    11431119      !! current weights file 
    11441120 
    1145       !! open input data file (non-model grid) 
    1146       CALL iom_open( sd%clname, inum, ldiof =  LEN(TRIM(sd%wgtname)) > 0 ) 
    1147  
    1148       !! get dimensions: we consider 2D data as 3D data with vertical dim size = 1 
    1149       IF( SIZE(sd%fnow, 3) > 0 ) THEN 
    1150          ALLOCATE( ddims(4) ) 
    1151       ELSE 
    1152          ALLOCATE( ddims(3) ) 
    1153       ENDIF 
    1154       id = iom_varid( inum, sd%clvar, ddims ) 
    1155  
    1156       !! close it 
    1157       CALL iom_close( inum ) 
     1121      !! get data grid dimensions 
     1122      id = iom_varid( sd%num, sd%clvar, ddims ) 
    11581123 
    11591124      !! now open the weights file 
    1160  
    11611125      CALL iom_open ( sd%wgtname, inum )   ! interpolation weights 
    11621126      IF( inum > 0 ) THEN 
     
    11941158         !! two possible cases: bilinear (4 weights) or bicubic (16 weights) 
    11951159         id = iom_varid(inum, 'src05', ldstop=.FALSE.) 
    1196          IF( id <= 0) THEN 
    1197             ref_wgts(nxt_wgt)%numwgt = 4 
    1198          ELSE 
    1199             ref_wgts(nxt_wgt)%numwgt = 16 
    1200          ENDIF 
    1201  
    1202          ALLOCATE( ref_wgts(nxt_wgt)%data_jpi(jpi,jpj,4) ) 
    1203          ALLOCATE( ref_wgts(nxt_wgt)%data_jpj(jpi,jpj,4) ) 
    1204          ALLOCATE( ref_wgts(nxt_wgt)%data_wgt(jpi,jpj,ref_wgts(nxt_wgt)%numwgt) ) 
     1160         IF( id <= 0 ) THEN   ;   ref_wgts(nxt_wgt)%numwgt = 4 
     1161         ELSE                 ;   ref_wgts(nxt_wgt)%numwgt = 16 
     1162         ENDIF 
     1163 
     1164         ALLOCATE( ref_wgts(nxt_wgt)%data_jpi(Nis0:Nie0,Njs0:Nje0,4) ) 
     1165         ALLOCATE( ref_wgts(nxt_wgt)%data_jpj(Nis0:Nie0,Njs0:Nje0,4) ) 
     1166         ALLOCATE( ref_wgts(nxt_wgt)%data_wgt(Nis0:Nie0,Njs0:Nje0,ref_wgts(nxt_wgt)%numwgt) ) 
    12051167 
    12061168         DO jn = 1,4 
    1207             aname = ' ' 
    1208             WRITE(aname,'(a3,i2.2)') 'src',jn 
    1209             data_tmp(:,:) = 0 
    1210             CALL iom_get ( inum, jpdom_data, aname, data_tmp(:,:) ) 
    1211             data_src(:,:) = INT(data_tmp(:,:)) 
    1212             ref_wgts(nxt_wgt)%data_jpj(:,:,jn) = 1 + (data_src(:,:)-1) / ref_wgts(nxt_wgt)%ddims(1) 
    1213             ref_wgts(nxt_wgt)%data_jpi(:,:,jn) = data_src(:,:) - ref_wgts(nxt_wgt)%ddims(1)*(ref_wgts(nxt_wgt)%data_jpj(:,:,jn)-1) 
     1169            WRITE(clname,'(a3,i2.2)') 'src',jn 
     1170            CALL iom_get ( inum, jpdom_global, clname, data_tmp(:,:), cd_type = 'Z' )   !  no call to lbc_lnk 
     1171            DO_2D( 0, 0, 0, 0 ) 
     1172               isrc = NINT(data_tmp(ji,jj)) - 1 
     1173               ref_wgts(nxt_wgt)%data_jpi(ji,jj,jn) = 1 + MOD(isrc,  ref_wgts(nxt_wgt)%ddims(1)) 
     1174               ref_wgts(nxt_wgt)%data_jpj(ji,jj,jn) = 1 +     isrc / ref_wgts(nxt_wgt)%ddims(1) 
     1175            END_2D 
    12141176         END DO 
    12151177 
    12161178         DO jn = 1, ref_wgts(nxt_wgt)%numwgt 
    1217             aname = ' ' 
    1218             WRITE(aname,'(a3,i2.2)') 'wgt',jn 
    1219             ref_wgts(nxt_wgt)%data_wgt(:,:,jn) = 0.0 
    1220             CALL iom_get ( inum, jpdom_data, aname, ref_wgts(nxt_wgt)%data_wgt(:,:,jn) ) 
     1179            WRITE(clname,'(a3,i2.2)') 'wgt',jn 
     1180            CALL iom_get ( inum, jpdom_global, clname, data_tmp(:,:), cd_type = 'Z' )   !  no call to lbc_lnk 
     1181            DO_2D( 0, 0, 0, 0 ) 
     1182               ref_wgts(nxt_wgt)%data_wgt(ji,jj,jn) = data_tmp(ji,jj) 
     1183            END_2D 
    12211184         END DO 
    12221185         CALL iom_close (inum) 
    12231186  
    12241187         ! find min and max indices in grid 
    1225          ref_wgts(nxt_wgt)%botleft(1) = MINVAL(ref_wgts(nxt_wgt)%data_jpi(:,:,:)) 
    1226          ref_wgts(nxt_wgt)%botleft(2) = MINVAL(ref_wgts(nxt_wgt)%data_jpj(:,:,:)) 
     1188         ref_wgts(nxt_wgt)%botleft( 1) = MINVAL(ref_wgts(nxt_wgt)%data_jpi(:,:,:)) 
     1189         ref_wgts(nxt_wgt)%botleft( 2) = MINVAL(ref_wgts(nxt_wgt)%data_jpj(:,:,:)) 
    12271190         ref_wgts(nxt_wgt)%topright(1) = MAXVAL(ref_wgts(nxt_wgt)%data_jpi(:,:,:)) 
    12281191         ref_wgts(nxt_wgt)%topright(2) = MAXVAL(ref_wgts(nxt_wgt)%data_jpj(:,:,:)) 
     
    12481211         CALL ctl_stop( '    fld_weight : unable to read the file ' ) 
    12491212      ENDIF 
    1250  
    1251       DEALLOCATE (ddims ) 
    12521213      ! 
    12531214   END SUBROUTINE fld_weight 
     
    12821243      SELECT CASE( SIZE(zfieldo(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),3) ) 
    12831244      CASE(1) 
    1284          CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,1), 1, rec1_lsm, recn_lsm) 
     1245         CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,1),   & 
     1246            &          1, kstart = rec1_lsm, kcount = recn_lsm) 
    12851247      CASE DEFAULT 
    1286          CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:), 1, rec1_lsm, recn_lsm) 
     1248         CALL iom_get( inum, jpdom_unknown, 'LSM', zslmec1(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),   & 
     1249            &          1, kstart = rec1_lsm, kcount = recn_lsm) 
    12871250      END SELECT 
    12881251      CALL iom_close( inum ) 
     
    13571320 
    13581321 
    1359    SUBROUTINE fld_interp( num, clvar, kw, kk, dta,  & 
    1360                           &         nrec, lsmfile)       
     1322   SUBROUTINE fld_interp( num, clvar, kw, kk, dta, nrec, lsmfile)       
    13611323      !!--------------------------------------------------------------------- 
    13621324      !!                    ***  ROUTINE fld_interp  *** 
     
    13761338      INTEGER, DIMENSION(3) ::   rec1_lsm, recn_lsm   ! temporary arrays for start and length in case of seaoverland 
    13771339      INTEGER ::   ii_lsm1,ii_lsm2,ij_lsm1,ij_lsm2    ! temporary indices 
    1378       INTEGER ::   jk, jn, jm, jir, jjr               ! loop counters 
     1340      INTEGER ::   ji, jj, jk, jn, jir, jjr           ! loop counters 
     1341      INTEGER ::   ipk 
    13791342      INTEGER ::   ni, nj                             ! lengths 
    13801343      INTEGER ::   jpimin,jpiwid                      ! temporary indices 
     
    13871350      REAL(wp),DIMENSION(:,:,:), ALLOCATABLE ::   ztmp_fly_dta                 ! local array of values on input grid      
    13881351      !!---------------------------------------------------------------------- 
     1352      ipk = SIZE(dta, 3) 
    13891353      ! 
    13901354      !! for weighted interpolation we have weights at four corners of a box surrounding  
     
    14161380 
    14171381 
    1418       IF( LEN( TRIM(lsmfile) ) > 0 ) THEN 
     1382      IF( LEN_TRIM(lsmfile) > 0 ) THEN 
    14191383      !! indeces for ztmp_fly_dta 
    14201384      ! -------------------------- 
     
    14461410         CASE(1) 
    14471411              CALL iom_get( num, jpdom_unknown, clvar, ztmp_fly_dta(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,1),   & 
    1448                  &                                                                nrec, rec1_lsm, recn_lsm) 
     1412                 &          nrec, kstart = rec1_lsm, kcount = recn_lsm) 
    14491413         CASE DEFAULT 
    14501414              CALL iom_get( num, jpdom_unknown, clvar, ztmp_fly_dta(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),   & 
    1451                  &                                                                nrec, rec1_lsm, recn_lsm) 
     1415                 &          nrec, kstart = rec1_lsm, kcount = recn_lsm) 
    14521416         END SELECT 
    14531417         CALL apply_seaoverland(lsmfile,ztmp_fly_dta(jpi1_lsm:jpi2_lsm,jpj1_lsm:jpj2_lsm,:),                  & 
     
    14691433          
    14701434         ref_wgts(kw)%fly_dta(:,:,:) = 0.0 
    1471          CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%fly_dta(jpi1:jpi2,jpj1:jpj2,:), nrec, rec1, recn) 
     1435         CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%fly_dta(jpi1:jpi2,jpj1:jpj2,:), nrec, kstart = rec1, kcount = recn) 
    14721436      ENDIF 
    14731437       
     
    14751439      !! first four weights common to both bilinear and bicubic 
    14761440      !! data_jpi, data_jpj have already been shifted to (1,1) corresponding to botleft 
    1477       !! note that we have to offset by 1 into fly_dta array because of halo 
    1478       dta(:,:,:) = 0.0 
    1479       DO jk = 1,4 
    1480         DO jn = 1, jpj 
    1481           DO jm = 1,jpi 
    1482             ni = ref_wgts(kw)%data_jpi(jm,jn,jk) 
    1483             nj = ref_wgts(kw)%data_jpj(jm,jn,jk) 
    1484             dta(jm,jn,:) = dta(jm,jn,:) + ref_wgts(kw)%data_wgt(jm,jn,jk) * ref_wgts(kw)%fly_dta(ni+1,nj+1,:) 
    1485           END DO 
    1486         END DO 
     1441      !! note that we have to offset by 1 into fly_dta array because of halo added to fly_dta (rec1 definition) 
     1442      dta(:,:,:) = 0._wp 
     1443      DO jn = 1,4 
     1444         DO_3D( 0, 0, 0, 0, 1,ipk ) 
     1445            ni = ref_wgts(kw)%data_jpi(ji,jj,jn) + 1 
     1446            nj = ref_wgts(kw)%data_jpj(ji,jj,jn) + 1 
     1447            dta(ji,jj,jk) = dta(ji,jj,jk) + ref_wgts(kw)%data_wgt(ji,jj,jn) * ref_wgts(kw)%fly_dta(ni,nj,jk) 
     1448         END_3D 
    14871449      END DO 
    14881450 
    14891451      IF(ref_wgts(kw)%numwgt .EQ. 16) THEN 
    14901452 
    1491         !! fix up halo points that we couldnt read from file 
    1492         IF( jpi1 == 2 ) THEN 
    1493            ref_wgts(kw)%fly_dta(jpi1-1,:,:) = ref_wgts(kw)%fly_dta(jpi1,:,:) 
    1494         ENDIF 
    1495         IF( jpi2 + jpimin - 1 == ref_wgts(kw)%ddims(1)+1 ) THEN 
    1496            ref_wgts(kw)%fly_dta(jpi2+1,:,:) = ref_wgts(kw)%fly_dta(jpi2,:,:) 
    1497         ENDIF 
    1498         IF( jpj1 == 2 ) THEN 
    1499            ref_wgts(kw)%fly_dta(:,jpj1-1,:) = ref_wgts(kw)%fly_dta(:,jpj1,:) 
    1500         ENDIF 
    1501         IF( jpj2 + jpjmin - 1 == ref_wgts(kw)%ddims(2)+1 .AND. jpj2 .lt. jpjwid+2 ) THEN 
    1502            ref_wgts(kw)%fly_dta(:,jpj2+1,:) = 2.0*ref_wgts(kw)%fly_dta(:,jpj2,:) - ref_wgts(kw)%fly_dta(:,jpj2-1,:) 
    1503         ENDIF 
    1504  
    1505         !! if data grid is cyclic we can do better on east-west edges 
    1506         !! but have to allow for whether first and last columns are coincident 
    1507         IF( ref_wgts(kw)%cyclic ) THEN 
    1508            rec1(2) = MAX( jpjmin-1, 1 ) 
    1509            recn(1) = 1 
    1510            recn(2) = MIN( jpjwid+2, ref_wgts(kw)%ddims(2)-rec1(2)+1 ) 
    1511            jpj1 = 2 + rec1(2) - jpjmin 
    1512            jpj2 = jpj1 + recn(2) - 1 
    1513            IF( jpi1 == 2 ) THEN 
    1514               rec1(1) = ref_wgts(kw)%ddims(1) - ref_wgts(kw)%overlap 
    1515               CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%col(:,jpj1:jpj2,:), nrec, rec1, recn) 
    1516               ref_wgts(kw)%fly_dta(jpi1-1,jpj1:jpj2,:) = ref_wgts(kw)%col(1,jpj1:jpj2,:) 
    1517            ENDIF 
    1518            IF( jpi2 + jpimin - 1 == ref_wgts(kw)%ddims(1)+1 ) THEN 
    1519               rec1(1) = 1 + ref_wgts(kw)%overlap 
    1520               CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%col(:,jpj1:jpj2,:), nrec, rec1, recn) 
    1521               ref_wgts(kw)%fly_dta(jpi2+1,jpj1:jpj2,:) = ref_wgts(kw)%col(1,jpj1:jpj2,:) 
    1522            ENDIF 
    1523         ENDIF 
    1524  
    1525         ! gradient in the i direction 
    1526         DO jk = 1,4 
    1527           DO jn = 1, jpj 
    1528             DO jm = 1,jpi 
    1529               ni = ref_wgts(kw)%data_jpi(jm,jn,jk) 
    1530               nj = ref_wgts(kw)%data_jpj(jm,jn,jk) 
    1531               dta(jm,jn,:) = dta(jm,jn,:) + ref_wgts(kw)%data_wgt(jm,jn,jk+4) * 0.5 *         & 
    1532                                (ref_wgts(kw)%fly_dta(ni+2,nj+1,:) - ref_wgts(kw)%fly_dta(ni,nj+1,:)) 
    1533             END DO 
    1534           END DO 
    1535         END DO 
    1536  
    1537         ! gradient in the j direction 
    1538         DO jk = 1,4 
    1539           DO jn = 1, jpj 
    1540             DO jm = 1,jpi 
    1541               ni = ref_wgts(kw)%data_jpi(jm,jn,jk) 
    1542               nj = ref_wgts(kw)%data_jpj(jm,jn,jk) 
    1543               dta(jm,jn,:) = dta(jm,jn,:) + ref_wgts(kw)%data_wgt(jm,jn,jk+8) * 0.5 *         & 
    1544                                (ref_wgts(kw)%fly_dta(ni+1,nj+2,:) - ref_wgts(kw)%fly_dta(ni+1,nj,:)) 
    1545             END DO 
    1546           END DO 
    1547         END DO 
    1548  
    1549          ! gradient in the ij direction 
    1550          DO jk = 1,4 
    1551             DO jn = 1, jpj 
    1552                DO jm = 1,jpi 
    1553                   ni = ref_wgts(kw)%data_jpi(jm,jn,jk) 
    1554                   nj = ref_wgts(kw)%data_jpj(jm,jn,jk) 
    1555                   dta(jm,jn,:) = dta(jm,jn,:) + ref_wgts(kw)%data_wgt(jm,jn,jk+12) * 0.25 * ( & 
    1556                                (ref_wgts(kw)%fly_dta(ni+2,nj+2,:) - ref_wgts(kw)%fly_dta(ni  ,nj+2,:)) -   & 
    1557                                (ref_wgts(kw)%fly_dta(ni+2,nj  ,:) - ref_wgts(kw)%fly_dta(ni  ,nj  ,:))) 
    1558                END DO 
    1559             END DO 
     1453         !! fix up halo points that we couldnt read from file 
     1454         IF( jpi1 == 2 ) THEN 
     1455            ref_wgts(kw)%fly_dta(jpi1-1,:,:) = ref_wgts(kw)%fly_dta(jpi1,:,:) 
     1456         ENDIF 
     1457         IF( jpi2 + jpimin - 1 == ref_wgts(kw)%ddims(1)+1 ) THEN 
     1458            ref_wgts(kw)%fly_dta(jpi2+1,:,:) = ref_wgts(kw)%fly_dta(jpi2,:,:) 
     1459         ENDIF 
     1460         IF( jpj1 == 2 ) THEN 
     1461            ref_wgts(kw)%fly_dta(:,jpj1-1,:) = ref_wgts(kw)%fly_dta(:,jpj1,:) 
     1462         ENDIF 
     1463         IF( jpj2 + jpjmin - 1 == ref_wgts(kw)%ddims(2)+1 .AND. jpj2 .LT. jpjwid+2 ) THEN 
     1464            ref_wgts(kw)%fly_dta(:,jpj2+1,:) = 2.0*ref_wgts(kw)%fly_dta(:,jpj2,:) - ref_wgts(kw)%fly_dta(:,jpj2-1,:) 
     1465         ENDIF 
     1466          
     1467         !! if data grid is cyclic we can do better on east-west edges 
     1468         !! but have to allow for whether first and last columns are coincident 
     1469         IF( ref_wgts(kw)%cyclic ) THEN 
     1470            rec1(2) = MAX( jpjmin-1, 1 ) 
     1471            recn(1) = 1 
     1472            recn(2) = MIN( jpjwid+2, ref_wgts(kw)%ddims(2)-rec1(2)+1 ) 
     1473            jpj1 = 2 + rec1(2) - jpjmin 
     1474            jpj2 = jpj1 + recn(2) - 1 
     1475            IF( jpi1 == 2 ) THEN 
     1476               rec1(1) = ref_wgts(kw)%ddims(1) - ref_wgts(kw)%overlap 
     1477               CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%col(:,jpj1:jpj2,:), nrec, kstart = rec1, kcount = recn) 
     1478               ref_wgts(kw)%fly_dta(jpi1-1,jpj1:jpj2,:) = ref_wgts(kw)%col(1,jpj1:jpj2,:) 
     1479            ENDIF 
     1480            IF( jpi2 + jpimin - 1 == ref_wgts(kw)%ddims(1)+1 ) THEN 
     1481               rec1(1) = 1 + ref_wgts(kw)%overlap 
     1482               CALL iom_get( num, jpdom_unknown, clvar, ref_wgts(kw)%col(:,jpj1:jpj2,:), nrec, kstart = rec1, kcount = recn) 
     1483               ref_wgts(kw)%fly_dta(jpi2+1,jpj1:jpj2,:) = ref_wgts(kw)%col(1,jpj1:jpj2,:) 
     1484            ENDIF 
     1485         ENDIF 
     1486         ! 
     1487!!$         DO jn = 1,4 
     1488!!$            DO_3D( 0, 0, 0, 0, 1,ipk ) 
     1489!!$               ni = ref_wgts(kw)%data_jpi(ji,jj,jn) + 1 
     1490!!$               nj = ref_wgts(kw)%data_jpj(ji,jj,jn) + 1 
     1491!!$               dta(ji,jj,jk) = dta(ji,jj,jk)   & 
     1492!!$                  ! gradient in the i direction 
     1493!!$                  &            + ref_wgts(kw)%data_wgt(ji,jj,jn+4) * 0.5_wp *                                    & 
     1494!!$                  &                (ref_wgts(kw)%fly_dta(ni+1,nj  ,jk) - ref_wgts(kw)%fly_dta(ni-1,nj  ,jk))     & 
     1495!!$                  ! gradient in the j direction 
     1496!!$                  &            + ref_wgts(kw)%data_wgt(ji,jj,jn+8) * 0.5_wp *                                    & 
     1497!!$                  &                (ref_wgts(kw)%fly_dta(ni  ,nj+1,jk) - ref_wgts(kw)%fly_dta(ni  ,nj-1,jk))     & 
     1498!!$                  ! gradient in the ij direction 
     1499!!$                  &            + ref_wgts(kw)%data_wgt(ji,jj,jn+12) * 0.25_wp *                                  & 
     1500!!$                  &               ((ref_wgts(kw)%fly_dta(ni+1,nj+1,jk) - ref_wgts(kw)%fly_dta(ni-1,nj+1,jk)) -   & 
     1501!!$                  &                (ref_wgts(kw)%fly_dta(ni+1,nj-1,jk) - ref_wgts(kw)%fly_dta(ni-1,nj-1,jk))) 
     1502!!$            END_3D 
     1503!!$         END DO 
     1504         ! 
     1505         DO jn = 1,4 
     1506            DO_3D( 0, 0, 0, 0, 1,ipk ) 
     1507               ni = ref_wgts(kw)%data_jpi(ji,jj,jn) 
     1508               nj = ref_wgts(kw)%data_jpj(ji,jj,jn) 
     1509               ! gradient in the i direction 
     1510               dta(ji,jj,jk) = dta(ji,jj,jk) + ref_wgts(kw)%data_wgt(ji,jj,jn+4) * 0.5_wp *         & 
     1511                  &                (ref_wgts(kw)%fly_dta(ni+2,nj+1,jk) - ref_wgts(kw)%fly_dta(ni  ,nj+1,jk)) 
     1512            END_3D 
     1513         END DO 
     1514         DO jn = 1,4 
     1515            DO_3D( 0, 0, 0, 0, 1,ipk ) 
     1516               ni = ref_wgts(kw)%data_jpi(ji,jj,jn) 
     1517               nj = ref_wgts(kw)%data_jpj(ji,jj,jn) 
     1518               ! gradient in the j direction 
     1519               dta(ji,jj,jk) = dta(ji,jj,jk) + ref_wgts(kw)%data_wgt(ji,jj,jn+8) * 0.5_wp *         & 
     1520                  &                (ref_wgts(kw)%fly_dta(ni+1,nj+2,jk) - ref_wgts(kw)%fly_dta(ni+1,nj  ,jk)) 
     1521            END_3D 
     1522         END DO 
     1523         DO jn = 1,4 
     1524            DO_3D( 0, 0, 0, 0, 1,ipk ) 
     1525               ni = ref_wgts(kw)%data_jpi(ji,jj,jn) 
     1526               nj = ref_wgts(kw)%data_jpj(ji,jj,jn) 
     1527               ! gradient in the ij direction 
     1528               dta(ji,jj,jk) = dta(ji,jj,jk) + ref_wgts(kw)%data_wgt(ji,jj,jn+12) * 0.25_wp * (     & 
     1529                  &                (ref_wgts(kw)%fly_dta(ni+2,nj+2,jk) - ref_wgts(kw)%fly_dta(ni  ,nj+2,jk)) -   & 
     1530                  &                (ref_wgts(kw)%fly_dta(ni+2,nj  ,jk) - ref_wgts(kw)%fly_dta(ni  ,nj  ,jk))) 
     1531            END_3D 
    15601532         END DO 
    15611533         ! 
     
    15841556      IF( .NOT. sdjf%ln_clim ) THEN    
    15851557                                         WRITE(clname, '(a,"_y",i4.4)' ) TRIM( sdjf%clrootname ), kyear    ! add year 
    1586          IF( sdjf%cltype /= 'yearly' )   WRITE(clname, '(a, "m",i2.2)' ) TRIM( clname          ), kmonth   ! add month 
     1558         IF( sdjf%clftyp /= 'yearly' )   WRITE(clname, '(a, "m",i2.2)' ) TRIM( clname          ), kmonth   ! add month 
    15871559      ELSE 
    15881560         ! build the new filename if climatological data 
    1589          IF( sdjf%cltype /= 'yearly' )   WRITE(clname, '(a,"_m",i2.2)' ) TRIM( sdjf%clrootname ), kmonth   ! add month 
    1590       ENDIF 
    1591       IF(    sdjf%cltype == 'daily' .OR. sdjf%cltype(1:4) == 'week' ) & 
     1561         IF( sdjf%clftyp /= 'yearly' )   WRITE(clname, '(a,"_m",i2.2)' ) TRIM( sdjf%clrootname ), kmonth   ! add month 
     1562      ENDIF 
     1563      IF(    sdjf%clftyp == 'daily' .OR. sdjf%clftyp(1:4) == 'week' ) & 
    15921564         &                               WRITE(clname, '(a,"d" ,i2.2)' ) TRIM( clname          ), kday     ! add day 
    15931565 
     
    16131585         IF( cl_week(ijul) == TRIM(cdday) ) EXIT 
    16141586      END DO 
    1615       IF( ijul .GT. 7 )   CALL ctl_stop( 'ksec_week: wrong day for sdjf%cltype(6:8): '//TRIM(cdday) ) 
     1587      IF( ijul .GT. 7 )   CALL ctl_stop( 'ksec_week: wrong day for sdjf%clftyp(6:8): '//TRIM(cdday) ) 
    16161588      ! 
    16171589      ishift = ijul * NINT(rday) 
Note: See TracChangeset for help on using the changeset viewer.