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/IOM/iom.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/IOM/iom.F90

    r13226 r13899  
    2121   !!---------------------------------------------------------------------- 
    2222   USE dom_oce         ! ocean space and time domain 
     23   USE domutl          !  
    2324   USE c1d             ! 1D vertical configuration 
    2425   USE flo_oce         ! floats module declarations 
     
    3435   USE ice      , ONLY :   jpl 
    3536#endif 
    36    USE domngb          ! ocean space and time domain 
    3737   USE phycst          ! physical constants 
    3838   USE dianam          ! build name of file 
     
    101101CONTAINS 
    102102 
    103    SUBROUTINE iom_init( cdname, fname, ld_tmppatch, ld_closedef )  
     103   SUBROUTINE iom_init( cdname, fname, ld_closedef )  
    104104      !!---------------------------------------------------------------------- 
    105105      !!                     ***  ROUTINE   *** 
     
    110110      CHARACTER(len=*),           INTENT(in)  :: cdname 
    111111      CHARACTER(len=*), OPTIONAL, INTENT(in)  :: fname 
    112       LOGICAL         , OPTIONAL, INTENT(in)  :: ld_tmppatch 
    113112      LOGICAL         , OPTIONAL, INTENT(in)  :: ld_closedef 
    114113#if defined key_iomput 
     
    123122      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zt_bnds, zw_bnds 
    124123      REAL(wp), DIMENSION(2,jpkam1)         :: za_bnds   ! ABL vertical boundaries 
    125       LOGICAL ::   ll_tmppatch = .TRUE.    !: seb: patch before we remove periodicity 
    126       INTEGER ::   nldi_save, nlei_save    !:      and close boundaries in output files 
    127       INTEGER ::   nldj_save, nlej_save    !: 
    128124      LOGICAL ::   ll_closedef = .TRUE. 
    129       !!---------------------------------------------------------------------- 
    130       ! 
    131       ! seb: patch before we remove periodicity and close boundaries in output files 
    132       IF( PRESENT(ld_tmppatch) ) THEN   ;   ll_tmppatch = ld_tmppatch 
    133       ELSE                              ;   ll_tmppatch = .TRUE. 
    134       ENDIF 
    135       IF ( ll_tmppatch ) THEN 
    136          nldi_save = nldi   ;   nlei_save = nlei 
    137          nldj_save = nldj   ;   nlej_save = nlej 
    138          IF( nimpp           ==      1 ) nldi = 1 
    139          IF( nimpp + jpi - 1 == jpiglo ) nlei = jpi 
    140          IF( njmpp           ==      1 ) nldj = 1 
    141          IF( njmpp + jpj - 1 == jpjglo ) nlej = jpj 
    142       ENDIF 
     125      LOGICAL ::   ll_exist 
     126      !!---------------------------------------------------------------------- 
     127      ! 
    143128      IF ( PRESENT(ld_closedef) ) ll_closedef = ld_closedef 
    144129      ! 
     
    157142 
    158143      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL 
    159       CASE ( 1)   ; CALL xios_define_calendar( TYPE = "Gregorian", time_origin = xios_date(irefyear,irefmonth,irefday,00,00,00), & 
    160           &                                    start_date = xios_date(nyear,nmonth,nday,0,0,0) ) 
    161       CASE ( 0)   ; CALL xios_define_calendar( TYPE = "NoLeap"   , time_origin = xios_date(irefyear,irefmonth,irefday,00,00,00), & 
    162           &                                    start_date = xios_date(nyear,nmonth,nday,0,0,0) ) 
    163       CASE (30)   ; CALL xios_define_calendar( TYPE = "D360"     , time_origin = xios_date(irefyear,irefmonth,irefday,00,00,00), & 
    164           &                                    start_date = xios_date(nyear,nmonth,nday,0,0,0) ) 
     144      CASE ( 1)   ;   CALL xios_define_calendar( TYPE = "Gregorian", time_origin = xios_date(irefyear,irefmonth,irefday,0,0,0),  & 
     145          &                                                          start_date  = xios_date(   nyear,   nmonth,   nday,0,0,0) ) 
     146      CASE ( 0)   ;   CALL xios_define_calendar( TYPE = "NoLeap"   , time_origin = xios_date(irefyear,irefmonth,irefday,0,0,0),  & 
     147          &                                                          start_date  = xios_date(   nyear,   nmonth,   nday,0,0,0) ) 
     148      CASE (30)   ;   CALL xios_define_calendar( TYPE = "D360"     , time_origin = xios_date(irefyear,irefmonth,irefday,0,0,0),  & 
     149          &                                                          start_date  = xios_date(   nyear,   nmonth,   nday,0,0,0) ) 
    165150      END SELECT 
    166151 
     
    176161         ! 
    177162         IF( ln_cfmeta ) THEN   ! Add additional grid metadata 
    178             CALL iom_set_domain_attr("grid_T", area = real( e1e2t(nldi:nlei, nldj:nlej), dp)) 
    179             CALL iom_set_domain_attr("grid_U", area = real( e1e2u(nldi:nlei, nldj:nlej), dp)) 
    180             CALL iom_set_domain_attr("grid_V", area = real( e1e2v(nldi:nlei, nldj:nlej), dp)) 
    181             CALL iom_set_domain_attr("grid_W", area = real( e1e2t(nldi:nlei, nldj:nlej), dp)) 
     163            CALL iom_set_domain_attr("grid_T", area = real( e1e2t(Nis0:Nie0, Njs0:Nje0), dp)) 
     164            CALL iom_set_domain_attr("grid_U", area = real( e1e2u(Nis0:Nie0, Njs0:Nje0), dp)) 
     165            CALL iom_set_domain_attr("grid_V", area = real( e1e2v(Nis0:Nie0, Njs0:Nje0), dp)) 
     166            CALL iom_set_domain_attr("grid_W", area = real( e1e2t(Nis0:Nie0, Njs0:Nje0), dp)) 
    182167            CALL set_grid_bounds( "T", glamf, gphif, glamt, gphit ) 
    183168            CALL set_grid_bounds( "U", glamv, gphiv, glamu, gphiu ) 
     
    199184         ! 
    200185         IF( ln_cfmeta .AND. .NOT. llrst_context) THEN   ! Add additional grid metadata 
    201             CALL iom_set_domain_attr("grid_T", area = real(e1e2t_crs(nldi:nlei, nldj:nlej), dp)) 
    202             CALL iom_set_domain_attr("grid_U", area = real(e1u_crs(nldi:nlei, nldj:nlej) * e2u_crs(nldi:nlei, nldj:nlej), dp) ) 
    203             CALL iom_set_domain_attr("grid_V", area = real(e1v_crs(nldi:nlei, nldj:nlej) * e2v_crs(nldi:nlei, nldj:nlej), dp) ) 
    204             CALL iom_set_domain_attr("grid_W", area = real(e1e2t_crs(nldi:nlei, nldj:nlej), dp ) ) 
     186            CALL iom_set_domain_attr("grid_T", area = real(e1e2t_crs(Nis0:Nie0, Njs0:Nje0), dp)) 
     187            CALL iom_set_domain_attr("grid_U", area = real(e1u_crs(Nis0:Nie0, Njs0:Nje0) * e2u_crs(Nis0:Nie0, Njs0:Nje0), dp)) 
     188            CALL iom_set_domain_attr("grid_V", area = real(e1v_crs(Nis0:Nie0, Njs0:Nje0) * e2v_crs(Nis0:Nie0, Njs0:Nje0), dp)) 
     189            CALL iom_set_domain_attr("grid_W", area = real(e1e2t_crs(Nis0:Nie0, Njs0:Nje0), dp)) 
    205190            CALL set_grid_bounds( "T", glamf_crs, gphif_crs, glamt_crs, gphit_crs ) 
    206191            CALL set_grid_bounds( "U", glamv_crs, gphiv_crs, glamu_crs, gphiu_crs ) 
     
    246231          CALL iom_set_axis_attr( "ghw_abl", bounds=za_bnds ) 
    247232 
    248           CALL iom_set_axis_attr( "nfloat", (/ (REAL(ji,wp), ji=1,jpnfl) /) ) 
     233          CALL iom_set_axis_attr(  "nfloat", (/ (REAL(ji,wp), ji=1,jpnfl) /) ) 
    249234# if defined key_si3 
    250235          CALL iom_set_axis_attr( "ncatice", (/ (REAL(ji,wp), ji=1,jpl) /) ) 
     
    259244          CALL iom_set_axis_attr( "iax_26C", (/ REAL(26,wp) /) )   ! strange syntaxe and idea... 
    260245          CALL iom_set_axis_attr( "iax_28C", (/ REAL(28,wp) /) )   ! strange syntaxe and idea... 
    261           CALL iom_set_axis_attr( "basin"  , (/ (REAL(ji,wp), ji=1,5) /) ) 
     246          ! for diaprt, we need to define an axis which size can be 1 (default) or 5 (if the file subbasins.nc exists) 
     247          INQUIRE( FILE = 'subbasins.nc', EXIST = ll_exist ) 
     248          nbasin = 1 + 4 * COUNT( (/ll_exist/) ) 
     249          CALL iom_set_axis_attr( "basin"  , (/ (REAL(ji,wp), ji=1,nbasin) /) ) 
    262250      ENDIF 
    263251      ! 
     
    288276      DEALLOCATE( zt_bnds, zw_bnds ) 
    289277      ! 
    290       IF ( ll_tmppatch ) THEN 
    291          nldi = nldi_save   ;   nlei = nlei_save 
    292          nldj = nldj_save   ;   nlej = nlej_save 
    293       ENDIF 
    294278#endif 
    295279      ! 
     
    370354           rst_file = TRIM(clpath)//TRIM(cn_ocerst_in) 
    371355        ELSE 
    372            rst_file = TRIM(clpath)//'1_'//TRIM(cn_ocerst_in) 
     356           rst_file = TRIM(clpath)//TRIM(Agrif_CFixed())//'_'//TRIM(cn_ocerst_in) 
    373357        ENDIF 
    374358!set name of the restart file and enable available fields 
     
    671655 
    672656 
    673    SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, ldstop, ldiof, kdlev, cdcomp ) 
     657   SUBROUTINE iom_open( cdname, kiomid, ldwrt, ldstop, ldiof, kdlev, cdcomp ) 
    674658      !!--------------------------------------------------------------------- 
    675659      !!                   ***  SUBROUTINE  iom_open  *** 
     
    680664      INTEGER         , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file 
    681665      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldwrt    ! open in write modeb          (default = .FALSE.) 
    682       INTEGER         , INTENT(in   ), OPTIONAL ::   kdom     ! Type of domain to be written (default = jpdom_local_noovlap) 
    683666      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.) 
    684667      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldiof    ! Interp On the Fly, needed for AGRIF (default = .FALSE.) 
     
    693676      LOGICAL               ::   llok      ! check the existence  
    694677      LOGICAL               ::   llwrt     ! local definition of ldwrt 
    695       LOGICAL               ::   llnoov    ! local definition to read overlap 
    696678      LOGICAL               ::   llstop    ! local definition of ldstop 
    697679      LOGICAL               ::   lliof     ! local definition of ldiof 
    698680      INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits) 
    699681      INTEGER               ::   iln, ils  ! lengths of character 
    700       INTEGER               ::   idom      ! type of domain 
    701682      INTEGER               ::   istop     !  
    702       INTEGER, DIMENSION(2,5) ::   idompar ! domain parameters:  
    703683      ! local number of points for x,y dimensions 
    704684      ! position of first local point for x,y dimensions 
     
    732712      ELSE                        ;   lliof = .FALSE. 
    733713      ENDIF 
    734       ! do we read the overlap  
    735       ! ugly patch SM+JMM+RB to overwrite global definition in some cases 
    736       llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
    737714      ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix) 
    738715      ! ============= 
     
    773750      ELSE 
    774751         lxios_sini = .TRUE. 
    775       ENDIF 
    776       IF( llwrt ) THEN 
    777          ! check the domain definition 
    778 ! JMM + SM: ugly patch before getting the new version of lib_mpp) 
    779 !         idom = jpdom_local_noovlap   ! default definition 
    780          IF( llnoov ) THEN   ;   idom = jpdom_local_noovlap   ! default definition 
    781          ELSE                ;   idom = jpdom_local_full      ! default definition 
    782          ENDIF 
    783          IF( PRESENT(kdom) )   idom = kdom 
    784          ! create the domain informations 
    785          ! ============= 
    786          SELECT CASE (idom) 
    787          CASE (jpdom_local_full) 
    788             idompar(:,1) = (/ jpi             , jpj              /) 
    789             idompar(:,2) = (/ nimpp           , njmpp            /) 
    790             idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1  /) 
    791             idompar(:,4) = (/ nldi - 1        , nldj - 1         /) 
    792             idompar(:,5) = (/ jpi - nlei      , jpj - nlej       /) 
    793          CASE (jpdom_local_noextra) 
    794             idompar(:,1) = (/ nlci            , nlcj             /) 
    795             idompar(:,2) = (/ nimpp           , njmpp            /) 
    796             idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /) 
    797             idompar(:,4) = (/ nldi - 1        , nldj - 1         /) 
    798             idompar(:,5) = (/ nlci - nlei     , nlcj - nlej      /) 
    799          CASE (jpdom_local_noovlap) 
    800             idompar(:,1) = (/ nlei  - nldi + 1, nlej  - nldj + 1 /) 
    801             idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /) 
    802             idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /) 
    803             idompar(:,4) = (/ 0               , 0                /) 
    804             idompar(:,5) = (/ 0               , 0                /) 
    805          CASE DEFAULT 
    806             CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' ) 
    807          END SELECT 
    808752      ENDIF 
    809753      ! Open the NetCDF file 
     
    830774      ENDIF 
    831775      IF( istop == nstop ) THEN   ! no error within this routine 
    832          CALL iom_nf90_open( clname, kiomid, llwrt, llok, idompar, kdlev = kdlev, cdcomp = cdcomp ) 
     776         CALL iom_nf90_open( clname, kiomid, llwrt, llok, kdlev = kdlev, cdcomp = cdcomp ) 
    833777      ENDIF 
    834778      ! 
     
    10911035   END SUBROUTINE iom_g1d_dp 
    10921036 
    1093    SUBROUTINE iom_g2d_sp( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr, ldxios) 
    1094       INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file 
    1095       INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read 
    1096       CHARACTER(len=*), INTENT(in   )                           ::   cdvar     ! Name of the variable 
    1097       REAL(sp)        , INTENT(  out), DIMENSION(:,:)           ::   pvar      ! read field 
    1098       REAL(dp)        , ALLOCATABLE  , DIMENSION(:,:)           ::   ztmp_pvar ! tmp var to read field 
    1099       INTEGER         , INTENT(in   )                , OPTIONAL ::   ktime     ! record number 
    1100       INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kstart    ! start axis position of the reading  
    1101       INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis 
    1102       LOGICAL         , INTENT(in   )                , OPTIONAL ::   lrowattr  ! logical flag telling iom_get to 
    1103                                                                                ! look for and use a file attribute 
    1104                                                                                ! called open_ocean_jstart to set the start 
    1105                                                                                ! value for the 2nd dimension (netcdf only) 
    1106       LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios      ! read data using XIOS 
     1037   SUBROUTINE iom_g2d_sp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios) 
     1038      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file 
     1039      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read 
     1040      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable 
     1041      REAL(sp)        , INTENT(  out), DIMENSION(:,:)         ::   pvar      ! read field 
     1042      REAL(dp)        , ALLOCATABLE  , DIMENSION(:,:)         ::   ztmp_pvar ! tmp var to read field 
     1043      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number 
     1044      CHARACTER(len=1), INTENT(in   )              , OPTIONAL ::   cd_type   ! nature of grid-points (T, U, V, F, W) 
     1045      REAL(dp)        , INTENT(in   )              , OPTIONAL ::   psgn      ! -1.(1.): (not) change sign across the north fold 
     1046      INTEGER         , INTENT(in   )              , OPTIONAL ::   kfill     ! value of kfillmode in lbc_lbk 
     1047      INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kstart    ! start axis position of the reading  
     1048      INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kcount    ! number of points in each axis 
     1049      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS 
    11071050      ! 
    11081051      IF( kiomid > 0 ) THEN 
    11091052         IF( iom_file(kiomid)%nfid > 0 ) THEN 
    11101053            ALLOCATE(ztmp_pvar(size(pvar,1), size(pvar,2))) 
    1111             CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=ztmp_pvar,   & 
    1112               &                                                     ktime=ktime, kstart=kstart, kcount=kcount, & 
    1113               &                                                     lrowattr=lrowattr,  ldxios=ldxios) 
     1054            CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r2d = ztmp_pvar  , ktime = ktime,   & 
     1055             &                                                      cd_type = cd_type, psgn   = psgn  , kfill = kfill,   & 
     1056             &                                                      kstart  = kstart , kcount = kcount, ldxios=ldxios  ) 
     1057            pvar = ztmp_pvar 
     1058            DEALLOCATE(ztmp_pvar) 
     1059         ENDIF 
     1060      ENDIF 
     1061   END SUBROUTINE iom_g2d_sp 
     1062 
     1063   SUBROUTINE iom_g2d_dp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios) 
     1064      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file 
     1065      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read 
     1066      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable 
     1067      REAL(dp)        , INTENT(  out), DIMENSION(:,:)         ::   pvar      ! read field 
     1068      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number 
     1069      CHARACTER(len=1), INTENT(in   )              , OPTIONAL ::   cd_type   ! nature of grid-points (T, U, V, F, W) 
     1070      REAL(dp)        , INTENT(in   )              , OPTIONAL ::   psgn      ! -1.(1.): (not) change sign across the north fold 
     1071      INTEGER         , INTENT(in   )              , OPTIONAL ::   kfill     ! value of kfillmode in lbc_lbk 
     1072      INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kstart    ! start axis position of the reading  
     1073      INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kcount    ! number of points in each axis 
     1074      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS 
     1075      ! 
     1076      IF( kiomid > 0 ) THEN 
     1077         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r2d = pvar  , ktime = ktime,   & 
     1078            &                                                       cd_type = cd_type, psgn   = psgn  , kfill = kfill,   & 
     1079            &                                                       kstart  = kstart , kcount = kcount, ldxios=ldxios  ) 
     1080      ENDIF 
     1081   END SUBROUTINE iom_g2d_dp 
     1082 
     1083   SUBROUTINE iom_g3d_sp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios ) 
     1084      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file 
     1085      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read 
     1086      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable 
     1087      REAL(sp)        , INTENT(  out), DIMENSION(:,:,:)       ::   pvar      ! read field 
     1088      REAL(dp)        , ALLOCATABLE  , DIMENSION(:,:,:)       ::   ztmp_pvar ! tmp var to read field 
     1089      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number 
     1090      CHARACTER(len=1), INTENT(in   )              , OPTIONAL ::   cd_type   ! nature of grid-points (T, U, V, F, W) 
     1091      REAL(dp)        , INTENT(in   )              , OPTIONAL ::   psgn      ! -1.(1.) : (not) change sign across the north fold 
     1092      INTEGER         , INTENT(in   )              , OPTIONAL ::   kfill     ! value of kfillmode in lbc_lbk 
     1093      INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kstart    ! start axis position of the reading  
     1094      INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kcount    ! number of points in each axis 
     1095      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS 
     1096      ! 
     1097      IF( kiomid > 0 ) THEN 
     1098         IF( iom_file(kiomid)%nfid > 0 ) THEN 
     1099            ALLOCATE(ztmp_pvar(size(pvar,1), size(pvar,2), size(pvar,3))) 
     1100            CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r3d = ztmp_pvar  , ktime = ktime,   & 
     1101            &                                                       cd_type = cd_type, psgn   = psgn  , kfill = kfill,   & 
     1102            &                                                       kstart  = kstart , kcount = kcount, ldxios=ldxios  ) 
    11141103            pvar = ztmp_pvar 
    11151104            DEALLOCATE(ztmp_pvar) 
    11161105         END IF 
    11171106      ENDIF 
    1118    END SUBROUTINE iom_g2d_sp 
    1119  
    1120  
    1121    SUBROUTINE iom_g2d_dp( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr, ldxios) 
    1122       INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file 
    1123       INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read 
    1124       CHARACTER(len=*), INTENT(in   )                           ::   cdvar     ! Name of the variable 
    1125       REAL(dp)        , INTENT(  out), DIMENSION(:,:)           ::   pvar      ! read field 
    1126       INTEGER         , INTENT(in   )                , OPTIONAL ::   ktime     ! record number 
    1127       INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kstart    ! start axis position of the reading  
    1128       INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis 
    1129       LOGICAL         , INTENT(in   )                , OPTIONAL ::   lrowattr  ! logical flag telling iom_get to 
    1130                                                                                ! look for and use a file attribute 
    1131                                                                                ! called open_ocean_jstart to set the start 
    1132                                                                                ! value for the 2nd dimension (netcdf only) 
    1133       LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios      ! read data using XIOS 
    1134       ! 
    1135       IF( kiomid > 0 ) THEN 
    1136          IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   & 
    1137               &                                                     ktime=ktime, kstart=kstart, kcount=kcount, & 
    1138               &                                                     lrowattr=lrowattr,  ldxios=ldxios) 
    1139       ENDIF 
    1140    END SUBROUTINE iom_g2d_dp 
    1141  
    1142    SUBROUTINE iom_g3d_sp( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr, ldxios ) 
    1143       INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file 
    1144       INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read 
    1145       CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable 
    1146       REAL(sp)        , INTENT(  out), DIMENSION(:,:,:)           ::   pvar      ! read field 
    1147       REAL(dp)        , ALLOCATABLE  , DIMENSION(:,:,:)           ::   ztmp_pvar ! tmp var to read field 
    1148       INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number 
    1149       INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kstart    ! start axis position of the reading  
    1150       INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis 
    1151       LOGICAL         , INTENT(in   )                  , OPTIONAL ::   lrowattr  ! logical flag telling iom_get to 
    1152                                                                                  ! look for and use a file attribute 
    1153                                                                                  ! called open_ocean_jstart to set the start 
    1154                                                                                  ! value for the 2nd dimension (netcdf only) 
    1155       LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios        ! read data using XIOS 
     1107   END SUBROUTINE iom_g3d_sp 
     1108 
     1109   SUBROUTINE iom_g3d_dp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios ) 
     1110      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file 
     1111      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read 
     1112      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable 
     1113      REAL(dp)        , INTENT(  out), DIMENSION(:,:,:)       ::   pvar      ! read field 
     1114      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number 
     1115      CHARACTER(len=1), INTENT(in   )              , OPTIONAL ::   cd_type   ! nature of grid-points (T, U, V, F, W) 
     1116      REAL(dp)        , INTENT(in   )              , OPTIONAL ::   psgn      ! -1.(1.) : (not) change sign across the north fold 
     1117      INTEGER         , INTENT(in   )              , OPTIONAL ::   kfill     ! value of kfillmode in lbc_lbk 
     1118      INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kstart    ! start axis position of the reading  
     1119      INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kcount    ! number of points in each axis 
     1120      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS 
    11561121      ! 
    11571122      IF( kiomid > 0 ) THEN 
    11581123         IF( iom_file(kiomid)%nfid > 0 ) THEN 
    1159             ALLOCATE(ztmp_pvar(size(pvar,1), size(pvar,2), size(pvar,3))) 
    1160             CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=ztmp_pvar,   & 
    1161               &                                                     ktime=ktime, kstart=kstart, kcount=kcount, & 
    1162               &                                                     lrowattr=lrowattr, ldxios=ldxios ) 
    1163             pvar = ztmp_pvar 
    1164             DEALLOCATE(ztmp_pvar) 
     1124            CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r3d = pvar  , ktime = ktime,   & 
     1125            &                                                       cd_type = cd_type, psgn   = psgn  , kfill = kfill,   & 
     1126            &                                                       kstart  = kstart , kcount = kcount, ldxios=ldxios  ) 
    11651127         END IF 
    11661128      ENDIF 
    1167    END SUBROUTINE iom_g3d_sp 
    1168  
    1169    SUBROUTINE iom_g3d_dp( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr, ldxios ) 
    1170       INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file 
    1171       INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read 
    1172       CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable 
    1173       REAL(dp)        , INTENT(  out), DIMENSION(:,:,:)           ::   pvar      ! read field 
    1174       INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number 
    1175       INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kstart    ! start axis position of the reading  
    1176       INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis 
    1177       LOGICAL         , INTENT(in   )                  , OPTIONAL ::   lrowattr  ! logical flag telling iom_get to 
    1178                                                                                  ! look for and use a file attribute 
    1179                                                                                  ! called open_ocean_jstart to set the start 
    1180                                                                                  ! value for the 2nd dimension (netcdf only) 
    1181       LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios        ! read data using XIOS 
    1182       ! 
    1183       IF( kiomid > 0 ) THEN 
    1184          IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   & 
    1185               &                                                     ktime=ktime, kstart=kstart, kcount=kcount, & 
    1186               &                                                     lrowattr=lrowattr, ldxios=ldxios ) 
    1187       ENDIF 
    11881129   END SUBROUTINE iom_g3d_dp 
    11891130 
    1190  
    1191  
    11921131   !!---------------------------------------------------------------------- 
    11931132 
    1194    SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   & 
    1195          &                  pv_r1d, pv_r2d, pv_r3d,   & 
    1196          &                  ktime , kstart, kcount,   & 
    1197          &                  lrowattr, ldxios        ) 
     1133   SUBROUTINE iom_get_123d( kiomid , kdom, cdvar, pv_r1d, pv_r2d, pv_r3d, ktime ,   & 
     1134         &                  cd_type, psgn, kfill, kstart, kcount, ldxios ) 
    11981135      !!----------------------------------------------------------------------- 
    11991136      !!                  ***  ROUTINE  iom_get_123d  *** 
     
    12031140      !! ** Method : read ONE record at each CALL 
    12041141      !!----------------------------------------------------------------------- 
    1205       INTEGER                    , INTENT(in   )           ::   kiomid     ! Identifier of the file 
    1206       INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read 
    1207       CHARACTER(len=*)           , INTENT(in   )           ::   cdvar      ! Name of the variable 
    1208       REAL(dp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case) 
    1209       REAL(dp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case) 
    1210       REAL(dp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case) 
    1211       INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime      ! record number 
    1212       INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart     ! start position of the reading in each axis  
    1213       INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount     ! number of points to be read in each axis 
    1214       LOGICAL                    , INTENT(in   ), OPTIONAL ::   lrowattr   ! logical flag telling iom_get to 
    1215                                                                            ! look for and use a file attribute 
    1216                                                                            ! called open_ocean_jstart to set the start 
    1217                                                                            ! value for the 2nd dimension (netcdf only) 
    1218       LOGICAL                    , INTENT(in   ), OPTIONAL ::   ldxios     ! use XIOS to read restart 
    1219       ! 
    1220       LOGICAL                        ::   llxios       ! local definition for XIOS read 
    1221       LOGICAL                        ::   llnoov      ! local definition to read overlap 
    1222       LOGICAL                        ::   luse_jattr  ! local definition to read open_ocean_jstart file attribute 
    1223       INTEGER                        ::   jstartrow   ! start point for 2nd dimension optionally set by file attribute 
     1142      INTEGER                    , INTENT(in   )           ::   kiomid    ! Identifier of the file 
     1143      INTEGER                    , INTENT(in   )           ::   kdom      ! Type of domain to be read 
     1144      CHARACTER(len=*)           , INTENT(in   )           ::   cdvar     ! Name of the variable 
     1145      REAL(dp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d    ! read field (1D case) 
     1146      REAL(dp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d    ! read field (2D case) 
     1147      REAL(dp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d    ! read field (3D case) 
     1148      INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime     ! record number 
     1149      CHARACTER(len=1)           , INTENT(in   ), OPTIONAL ::   cd_type   ! nature of grid-points (T, U, V, F, W) 
     1150      REAL(dp)                   , INTENT(in   ), OPTIONAL ::   psgn      ! -1.(1.) : (not) change sign across the north fold 
     1151      INTEGER                    , INTENT(in   ), OPTIONAL ::   kfill     ! value of kfillmode in lbc_lbk 
     1152      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart    ! start position of the reading in each axis  
     1153      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount    ! number of points to be read in each axis 
     1154      LOGICAL                    , INTENT(in   ), OPTIONAL ::   ldxios    ! use XIOS to read restart 
     1155      ! 
     1156      LOGICAL                        ::   llok        ! true if ok! 
     1157      LOGICAL                        ::   llxios      ! local definition for XIOS read 
    12241158      INTEGER                        ::   jl          ! loop on number of dimension  
    12251159      INTEGER                        ::   idom        ! type of domain 
     
    12381172      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable 
    12391173      REAL(dp)                       ::   zscf, zofs  ! sacle_factor and add_offset 
     1174      REAL(wp)                       ::   zsgn        ! local value of psgn 
    12401175      INTEGER                        ::   itmp        ! temporary integer 
    12411176      CHARACTER(LEN=256)             ::   clinfo      ! info character 
    12421177      CHARACTER(LEN=256)             ::   clname      ! file name 
    12431178      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      !  
    1244       LOGICAL                        ::   ll_depth_spec ! T => if kstart, kcount present then *only* use values for 3rd spatial dimension. 
     1179      CHARACTER(LEN=1)               ::   cl_type     ! local value of cd_type 
     1180      LOGICAL                        ::   ll_only3rd  ! T => if kstart, kcount present then *only* use values for 3rd spatial dimension. 
    12451181      INTEGER                        ::   inlev       ! number of levels for 3D data 
    12461182      REAL(dp)                       ::   gma, gmi 
     
    12511187      ! 
    12521188      llxios = .FALSE. 
    1253       if(PRESENT(ldxios)) llxios = ldxios 
    1254       idvar = iom_varid( kiomid, cdvar )  
     1189      IF( PRESENT(ldxios) )  llxios = ldxios 
     1190      ! 
    12551191      idom = kdom 
     1192      istop = nstop 
    12561193      ! 
    12571194      IF(.NOT.llxios) THEN 
    12581195         clname = iom_file(kiomid)%name   !   esier to read 
    12591196         clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar) 
    1260          ! local definition of the domain ? 
    1261          ! do we read the overlap  
    1262          ! ugly patch SM+JMM+RB to overwrite global definition in some cases 
    1263          llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif  
    12641197         ! check kcount and kstart optionals parameters... 
    1265          IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present') 
    1266          IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present') 
    1267          IF( PRESENT(kstart) .AND. idom /= jpdom_unknown .AND.  idom /= jpdom_autoglo_xy  ) & 
    1268      &          CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown or kdom = jpdom_autoglo_xy') 
    1269  
    1270          luse_jattr = .false. 
    1271          IF( PRESENT(lrowattr) ) THEN 
    1272             IF( lrowattr .AND. idom /= jpdom_data   ) CALL ctl_stop(trim(clinfo), 'lrowattr present and true needs kdom = jpdom_data') 
    1273             IF( lrowattr .AND. idom == jpdom_data   ) luse_jattr = .true. 
    1274          ENDIF 
    1275  
     1198         IF( PRESENT(kcount) .AND. .NOT. PRESENT(kstart) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present') 
     1199         IF( PRESENT(kstart) .AND. .NOT. PRESENT(kcount) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present') 
     1200         IF( PRESENT(kstart) .AND. idom /= jpdom_unknown .AND. idom /= jpdom_auto_xy ) & 
     1201            &          CALL ctl_stop(TRIM(clinfo), 'kstart present needs idom = jpdom_unknown or idom = jpdom_auto_xy') 
     1202         IF( idom == jpdom_auto_xy .AND. .NOT. PRESENT(kstart) ) & 
     1203            &          CALL ctl_stop(TRIM(clinfo), 'idom = jpdom_auto_xy requires kstart to be present') 
     1204         ! 
    12761205         ! Search for the variable in the data base (eventually actualize data) 
    1277          istop = nstop 
    12781206         ! 
     1207         idvar = iom_varid( kiomid, cdvar )  
    12791208         IF( idvar > 0 ) THEN 
    1280             ! to write iom_file(kiomid)%dimsz in a shorter way ! 
    1281             idimsz(:) = iom_file(kiomid)%dimsz(:, idvar)  
     1209            ! 
     1210            idimsz(:) = iom_file(kiomid)%dimsz(:, idvar)      ! to write iom_file(kiomid)%dimsz in a shorter way 
    12821211            inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file 
    12831212            idmspc = inbdim                                   ! number of spatial dimensions in the file 
     
    12851214            IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...')  
    12861215            ! 
    1287             ! update idom definition... 
    1288             ! Identify the domain in case of jpdom_auto(glo/dta) definition 
    1289             IF( idom == jpdom_autoglo_xy ) THEN 
    1290                ll_depth_spec = .TRUE. 
    1291                idom = jpdom_autoglo 
    1292             ELSE 
    1293                ll_depth_spec = .FALSE. 
    1294             ENDIF 
    1295             IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN             
    1296                IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global  
    1297                ELSE                               ;   idom = jpdom_data 
    1298                ENDIF 
     1216            ! Identify the domain in case of jpdom_auto definition 
     1217            IF( idom == jpdom_auto .OR. idom == jpdom_auto_xy ) THEN             
     1218               idom = jpdom_global   ! default 
     1219               ! else: if the file name finishes with _xxxx.nc with xxxx any number 
    12991220               ind1 = INDEX( clname, '_', back = .TRUE. ) + 1 
    13001221               ind2 = INDEX( clname, '.', back = .TRUE. ) - 1 
    13011222               IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF 
    1302             ENDIF 
    1303             ! Identify the domain in case of jpdom_local definition 
    1304             IF( idom == jpdom_local ) THEN 
    1305                IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full 
    1306                ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra 
    1307                ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap 
    1308                ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' ) 
    1309                ENDIF 
    13101223            ENDIF 
    13111224            ! 
     
    13201233            WRITE(cldmspc , fmt='(i1)') idmspc 
    13211234            ! 
    1322             !!GS: we consider 2D data as 3D data with vertical dim size = 1 
    1323             !IF(     idmspc <  irankpv ) THEN  
    1324             !   CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   & 
    1325             !      &                         'it is impossible to read a '//clrankpv//'D array from this file...' ) 
    1326             !ELSEIF( idmspc == irankpv ) THEN 
    1327             IF( idmspc == irankpv ) THEN 
     1235            IF(     idmspc <  irankpv ) THEN                     ! it seems we want to read more than we can... 
     1236               IF(     irankpv == 3 .AND. idmspc == 2 ) THEN     !   3D input array from 2D spatial data in the file: 
     1237                  llok = inlev == 1                              !     -> 3rd dimension must be equal to 1 
     1238               ELSEIF( irankpv == 3 .AND. idmspc == 1 ) THEN     !   3D input array from 1D spatial data in the file: 
     1239                  llok = inlev == 1 .AND. SIZE(pv_r3d, 2) == 1   !     -> 2nd and 3rd dimensions must be equal to 1 
     1240               ELSEIF( irankpv == 2 .AND. idmspc == 2 ) THEN     !   2D input array from 1D spatial data in the file: 
     1241                  llok = SIZE(pv_r2d, 2) == 1                    !     -> 2nd dimension must be equal to 1 
     1242               ELSE 
     1243                  llok = .FALSE. 
     1244               ENDIF 
     1245               IF( .NOT. llok )   CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   & 
     1246                  &                                            '=> cannot read a true '//clrankpv//'D array from this file...' ) 
     1247            ELSEIF( idmspc == irankpv ) THEN 
    13281248               IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   & 
    13291249                  &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' ) 
    1330             ELSEIF( idmspc >  irankpv ) THEN 
     1250            ELSEIF( idmspc >  irankpv ) THEN                     ! it seems we want to read less than we should... 
    13311251                  IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN 
    1332                      CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   & 
     1252                     CALL ctl_warn( trim(clinfo), '2D array input but 3 spatial dimensions in the file...'              ,   & 
    13331253                           &         'As the size of the z dimension is 1 and as we try to read the first record, ',   & 
    13341254                           &         'we accept this case, even if there is a possible mix-up between z and time dimension' )    
     
    13441264            ! definition of istart and icnt 
    13451265            ! 
    1346             icnt  (:) = 1 
    1347             istart(:) = 1 
    1348             istart(idmspc+1) = itime 
    1349     
    1350             IF( PRESENT(kstart) .AND. .NOT. ll_depth_spec ) THEN  
    1351                istart(1:idmspc) = kstart(1:idmspc)  
    1352                icnt  (1:idmspc) = kcount(1:idmspc) 
    1353             ELSE 
    1354                IF(idom == jpdom_unknown ) THEN 
    1355                   icnt(1:idmspc) = idimsz(1:idmspc) 
    1356                ELSE  
    1357                   IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array 
    1358                      IF(     idom == jpdom_data    ) THEN 
    1359                         jstartrow = 1 
    1360                         IF( luse_jattr ) THEN 
    1361                            CALL iom_getatt(kiomid, 'open_ocean_jstart', jstartrow ) ! -999 is returned if the attribute is not found 
    1362                            jstartrow = MAX(1,jstartrow) 
    1363                         ENDIF 
    1364                         istart(1:2) = (/ mig(1), mjg(1) + jstartrow - 1 /)  ! icnt(1:2) done below 
    1365                      ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done below 
    1366                      ENDIF 
    1367                      ! we do not read the overlap                     -> we start to read at nldi, nldj 
    1368 ! JMM + SM: ugly patch before getting the new version of lib_mpp) 
    1369 !                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /) 
    1370                      IF( llnoov .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /) 
    1371                   ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej  
    1372 ! JMM + SM: ugly patch before getting the new version of lib_mpp) 
    1373 !                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /) 
    1374                      IF( llnoov ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /) 
    1375                      ELSE                ;   icnt(1:2) = (/ nlci           , nlcj            /) 
    1376                      ENDIF 
    1377                      IF( PRESENT(pv_r3d) ) THEN 
    1378                         IF( idom == jpdom_data ) THEN                        ;                               icnt(3) = inlev 
    1379                         ELSEIF( ll_depth_spec .AND. PRESENT(kstart) ) THEN   ;   istart(3) = kstart(3)   ;   icnt(3) = kcount(3) 
    1380                         ELSE                                                 ;                               icnt(3) = inlev 
    1381                         ENDIF 
    1382                      ENDIF 
     1266            icnt  (:) = 1              ! default definition (simple way to deal with special cases listed above)  
     1267            istart(:) = 1              ! default definition (simple way to deal with special cases listed above)  
     1268            istart(idmspc+1) = itime   ! temporal dimenstion 
     1269            ! 
     1270            IF( idom == jpdom_unknown ) THEN 
     1271               IF( PRESENT(kstart) .AND. idom /= jpdom_auto_xy ) THEN  
     1272                  istart(1:idmspc) = kstart(1:idmspc)  
     1273                  icnt  (1:idmspc) = kcount(1:idmspc) 
     1274               ELSE 
     1275                  icnt  (1:idmspc) = idimsz(1:idmspc) 
     1276               ENDIF 
     1277            ELSE   !   not a 1D array as pv_r1d requires jpdom_unknown 
     1278               ! we do not read the overlap and the extra-halos -> from Nis0 to Nie0 and from Njs0 to Nje0  
     1279               IF( idom == jpdom_global )   istart(1:2) = (/ mig0(Nis0), mjg0(Njs0) /) 
     1280               icnt(1:2) = (/ Ni_0, Nj_0 /) 
     1281               IF( PRESENT(pv_r3d) ) THEN 
     1282                  IF( idom == jpdom_auto_xy ) THEN 
     1283                     istart(3) = kstart(3) 
     1284                     icnt  (3) = kcount(3) 
     1285                  ELSE 
     1286                     icnt  (3) = inlev 
    13831287                  ENDIF 
    13841288               ENDIF 
    13851289            ENDIF 
    1386  
     1290            ! 
    13871291            ! check that istart and icnt can be used with this file 
    13881292            !- 
     
    13951299               ENDIF 
    13961300            END DO 
    1397  
     1301            ! 
    13981302            ! check that icnt matches the input array 
    13991303            !-      
     
    14051309            ELSE 
    14061310               IF( irankpv == 2 ) THEN 
    1407 ! JMM + SM: ugly patch before getting the new version of lib_mpp) 
    1408 !               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)' 
    1409                   IF( llnoov ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)' 
    1410                   ELSE              ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)' 
    1411                   ENDIF 
     1311                  ishape(1:2) = SHAPE(pv_r2d(Nis0:Nie0,Njs0:Nje0  ))   ;   ctmp1 = 'd(Nis0:Nie0,Njs0:Nje0)' 
    14121312               ENDIF 
    14131313               IF( irankpv == 3 ) THEN  
    1414 ! JMM + SM: ugly patch before getting the new version of lib_mpp) 
    1415 !               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)' 
    1416                   IF( llnoov ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)' 
    1417                   ELSE              ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)' 
    1418                   ENDIF 
     1314                  ishape(1:3) = SHAPE(pv_r3d(Nis0:Nie0,Njs0:Nje0,:))   ;   ctmp1 = 'd(Nis0:Nie0,Njs0:Nje0,:)' 
    14191315               ENDIF 
    1420             ENDIF 
    1421           
     1316            ENDIF          
    14221317            DO jl = 1, irankpv 
    14231318               WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl) 
     
    14311326         IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point... 
    14321327            ! 
    1433          ! find the right index of the array to be read 
    1434 ! JMM + SM: ugly patch before getting the new version of lib_mpp) 
    1435 !         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej 
    1436 !         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2) 
    1437 !         ENDIF 
    1438             IF( llnoov ) THEN 
    1439                IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej 
    1440                ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2) 
    1441                ENDIF 
    1442             ELSE 
    1443                IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj 
    1444                ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2) 
    1445                ENDIF 
     1328            ! find the right index of the array to be read 
     1329            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = Nis0   ;   ix2 = Nie0      ;   iy1 = Njs0   ;   iy2 = Nje0 
     1330            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2) 
    14461331            ENDIF 
    14471332       
     
    14501335            IF( istop == nstop ) THEN   ! no additional errors until this point... 
    14511336               IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i6,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name) 
    1452               
     1337 
     1338               cl_type = 'T' 
     1339               IF( PRESENT(cd_type) )   cl_type = cd_type 
     1340               zsgn = 1._wp 
     1341               IF( PRESENT(psgn   ) )   zsgn    = psgn 
    14531342               !--- overlap areas and extra hallows (mpp) 
    1454                IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN 
    1455                   CALL lbc_lnk( 'iom', pv_r2d,'Z', -999.0_wp, kfillmode = jpfillnothing ) 
    1456                ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN 
    1457                   ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension 
    1458                   IF( icnt(3) == inlev ) THEN 
    1459                      CALL lbc_lnk( 'iom', pv_r3d,'Z', -999.0_wp, kfillmode = jpfillnothing ) 
    1460                   ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...) 
    1461                      DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO 
    1462                      DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO 
    1463                   ENDIF 
     1343               IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown .AND. cl_type /= 'Z' ) THEN 
     1344                  CALL lbc_lnk( 'iom', pv_r2d, cl_type, zsgn, kfillmode = kfill ) 
     1345               ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown .AND. cl_type /= 'Z' ) THEN 
     1346                  CALL lbc_lnk( 'iom', pv_r3d, cl_type, zsgn, kfillmode = kfill ) 
    14641347               ENDIF 
    14651348               ! 
     
    14781361         CALL iom_swap( TRIM(crxios_context) )  
    14791362         IF( PRESENT(pv_r3d) ) THEN 
    1480             pv_r3d(:, :, :) = 0. 
    1481             if(lwp) write(numout,*) 'XIOS RST READ (3D): ',trim(cdvar) 
     1363            IF(lwp) WRITE(numout,*) 'XIOS RST READ (3D): ',TRIM(cdvar) 
    14821364            CALL xios_recv_field( trim(cdvar), pv_r3d) 
    1483             IF(idom /= jpdom_unknown ) then 
    1484                 CALL lbc_lnk( 'iom', pv_r3d,'Z', -999.0_wp, kfillmode = jpfillnothing) 
    1485             ENDIF 
     1365            IF(idom /= jpdom_unknown )   CALL lbc_lnk( 'iom', pv_r3d,'Z', -999., kfillmode = jpfillnothing) 
    14861366         ELSEIF( PRESENT(pv_r2d) ) THEN 
    1487             pv_r2d(:, :) = 0. 
    1488             if(lwp) write(numout,*) 'XIOS RST READ (2D): ', trim(cdvar) 
     1367            IF(lwp) WRITE(numout,*) 'XIOS RST READ (2D): ', TRIM(cdvar) 
    14891368            CALL xios_recv_field( trim(cdvar), pv_r2d) 
    1490             IF(idom /= jpdom_unknown ) THEN 
    1491                 CALL lbc_lnk('iom', pv_r2d,'Z',-999.0_wp, kfillmode = jpfillnothing) 
    1492             ENDIF 
     1369            IF(idom /= jpdom_unknown )   CALL lbc_lnk('iom', pv_r2d,'Z',-999., kfillmode = jpfillnothing) 
    14931370         ELSEIF( PRESENT(pv_r1d) ) THEN 
    1494             pv_r1d(:) = 0. 
    1495             if(lwp) write(numout,*) 'XIOS RST READ (1D): ', trim(cdvar) 
     1371            IF(lwp) WRITE(numout,*) 'XIOS RST READ (1D): ', TRIM(cdvar) 
    14961372            CALL xios_recv_field( trim(cdvar), pv_r1d) 
    14971373         ENDIF 
     
    20361912      CHARACTER(LEN=*)            , INTENT(in) ::   cdname 
    20371913      REAL(sp),     DIMENSION(:,:), INTENT(in) ::   pfield2d 
    2038 #if defined key_iomput 
    2039       CALL xios_send_field(cdname, pfield2d) 
     1914      IF( iom_use(cdname) ) THEN 
     1915#if defined key_iomput 
     1916         CALL xios_send_field( cdname, pfield2d ) 
    20401917#else 
    2041       IF( .FALSE. )   WRITE(numout,*) cdname, pfield2d   ! useless test to avoid compilation warnings 
    2042 #endif 
     1918         WRITE(numout,*) pfield2d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings 
     1919#endif 
     1920      ENDIF 
    20431921   END SUBROUTINE iom_p2d_sp 
    20441922 
     
    20461924      CHARACTER(LEN=*)            , INTENT(in) ::   cdname 
    20471925      REAL(dp),     DIMENSION(:,:), INTENT(in) ::   pfield2d 
    2048 #if defined key_iomput 
    2049       CALL xios_send_field(cdname, pfield2d) 
     1926      IF( iom_use(cdname) ) THEN 
     1927#if defined key_iomput 
     1928         CALL xios_send_field( cdname, pfield2d ) 
    20501929#else 
    2051       IF( .FALSE. )   WRITE(numout,*) cdname, pfield2d   ! useless test to avoid compilation warnings 
    2052 #endif 
     1930         WRITE(numout,*) pfield2d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings 
     1931#endif 
     1932      ENDIF 
    20531933   END SUBROUTINE iom_p2d_dp 
    20541934 
     
    20561936      CHARACTER(LEN=*)                , INTENT(in) ::   cdname 
    20571937      REAL(sp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d 
    2058 #if defined key_iomput 
    2059       CALL xios_send_field( cdname, pfield3d ) 
     1938      IF( iom_use(cdname) ) THEN 
     1939#if defined key_iomput 
     1940         CALL xios_send_field( cdname, pfield3d ) 
    20601941#else 
    2061       IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings 
    2062 #endif 
     1942         WRITE(numout,*) pfield3d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings 
     1943#endif 
     1944      ENDIF 
    20631945   END SUBROUTINE iom_p3d_sp 
    20641946 
     
    20661948      CHARACTER(LEN=*)                , INTENT(in) ::   cdname 
    20671949      REAL(dp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d 
    2068 #if defined key_iomput 
    2069       CALL xios_send_field( cdname, pfield3d ) 
     1950      IF( iom_use(cdname) ) THEN 
     1951#if defined key_iomput 
     1952         CALL xios_send_field( cdname, pfield3d ) 
    20701953#else 
    2071       IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings 
    2072 #endif 
     1954         WRITE(numout,*) pfield3d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings 
     1955#endif 
     1956      ENDIF 
    20731957   END SUBROUTINE iom_p3d_dp 
    20741958 
     
    20761960      CHARACTER(LEN=*)                , INTENT(in) ::   cdname 
    20771961      REAL(sp),       DIMENSION(:,:,:,:), INTENT(in) ::   pfield4d 
    2078 #if defined key_iomput 
    2079       CALL xios_send_field(cdname, pfield4d) 
     1962      IF( iom_use(cdname) ) THEN 
     1963#if defined key_iomput 
     1964         CALL xios_send_field (cdname, pfield4d ) 
    20801965#else 
    2081       IF( .FALSE. )   WRITE(numout,*) cdname, pfield4d   ! useless test to avoid compilation warnings 
    2082 #endif 
     1966         WRITE(numout,*) pfield4d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings 
     1967#endif 
     1968      ENDIF 
    20831969   END SUBROUTINE iom_p4d_sp 
    20841970 
     
    20861972      CHARACTER(LEN=*)                , INTENT(in) ::   cdname 
    20871973      REAL(dp),       DIMENSION(:,:,:,:), INTENT(in) ::   pfield4d 
    2088 #if defined key_iomput 
    2089       CALL xios_send_field(cdname, pfield4d) 
     1974      IF( iom_use(cdname) ) THEN 
     1975#if defined key_iomput 
     1976         CALL xios_send_field (cdname, pfield4d ) 
    20901977#else 
    2091       IF( .FALSE. )   WRITE(numout,*) cdname, pfield4d   ! useless test to avoid compilation warnings 
    2092 #endif 
     1978         WRITE(numout,*) pfield4d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings 
     1979#endif 
     1980      ENDIF 
    20931981   END SUBROUTINE iom_p4d_dp 
    20941982 
     
    22872175      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat 
    22882176      ! 
    2289       INTEGER  :: ni, nj 
    22902177      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmask 
    22912178      LOGICAL, INTENT(IN) :: ldxios, ldrxios 
    22922179      !!---------------------------------------------------------------------- 
    22932180      ! 
    2294       ni = nlei-nldi+1 
    2295       nj = nlej-nldj+1 
    2296       ! 
    2297       CALL iom_set_domain_attr("grid_"//cdgrd, ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj) 
    2298       CALL iom_set_domain_attr("grid_"//cdgrd, data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj) 
     2181      CALL iom_set_domain_attr("grid_"//cdgrd, ni_glo=Ni0glo,nj_glo=Nj0glo,ibegin=mig0(Nis0)-1,jbegin=mjg0(Njs0)-1,ni=Ni_0,nj=Nj_0) 
     2182      CALL iom_set_domain_attr("grid_"//cdgrd, data_dim=2, data_ibegin = -nn_hls, data_ni = jpi, data_jbegin = -nn_hls, data_nj = jpj) 
    22992183!don't define lon and lat for restart reading context.  
    23002184      IF ( .NOT.ldrxios ) & 
    2301          CALL iom_set_domain_attr("grid_"//cdgrd, lonvalue = real(RESHAPE(plon(nldi:nlei, nldj:nlej),(/ ni*nj /)), dp),   & 
    2302          &                                     latvalue = real(RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /)),dp )  
     2185         CALL iom_set_domain_attr("grid_"//cdgrd, lonvalue = real(RESHAPE(plon(Nis0:Nie0, Njs0:Nje0),(/ Ni_0*Nj_0 /)),dp),   & 
     2186         &                                        latvalue = real(RESHAPE(plat(Nis0:Nie0, Njs0:Nje0),(/ Ni_0*Nj_0 /)),dp ) 
    23032187      ! 
    23042188      IF ( ln_mskland .AND. (.NOT.ldxios) ) THEN 
     
    23062190         SELECT CASE ( cdgrd ) 
    23072191         CASE('T')   ;   zmask(:,:,:)       = tmask(:,:,:) 
    2308          CASE('U')   ;   zmask(2:jpim1,:,:) = tmask(2:jpim1,:,:) + tmask(3:jpi,:,:)   ;   CALL lbc_lnk( 'iom', zmask, 'U', 1.0_wp ) 
    2309          CASE('V')   ;   zmask(:,2:jpjm1,:) = tmask(:,2:jpjm1,:) + tmask(:,3:jpj,:)   ;   CALL lbc_lnk( 'iom', zmask, 'V', 1.0_wp ) 
     2192         CASE('U')   ;   zmask(2:jpim1,:,:) = tmask(2:jpim1,:,:) + tmask(3:jpi,:,:) 
     2193         CASE('V')   ;   zmask(:,2:jpjm1,:) = tmask(:,2:jpjm1,:) + tmask(:,3:jpj,:) 
    23102194         CASE('W')   ;   zmask(:,:,2:jpk  ) = tmask(:,:,1:jpkm1) + tmask(:,:,2:jpk)   ;   zmask(:,:,1) = tmask(:,:,1) 
    23112195         END SELECT 
    23122196         ! 
    2313          CALL iom_set_domain_attr( "grid_"//cdgrd       , mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,1),(/ni*nj    /)) /= 0. ) 
    2314          CALL iom_set_grid_attr  ( "grid_"//cdgrd//"_3D", mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,:),(/ni,nj,jpk/)) /= 0. ) 
     2197         CALL iom_set_domain_attr( "grid_"//cdgrd       , mask = RESHAPE(zmask(Nis0:Nie0,Njs0:Nje0,1),(/Ni_0*Nj_0    /)) /= 0. ) 
     2198         CALL iom_set_grid_attr  ( "grid_"//cdgrd//"_3D", mask = RESHAPE(zmask(Nis0:Nie0,Njs0:Nje0,:),(/Ni_0,Nj_0,jpk/)) /= 0. ) 
    23152199      ENDIF 
    23162200      ! 
    23172201   END SUBROUTINE set_grid 
    2318  
    23192202 
    23202203   SUBROUTINE set_grid_bounds( cdgrd, plon_cnr, plat_cnr, plon_pnt, plat_pnt ) 
     
    23292212      REAL(wp), DIMENSION(jpi,jpj), OPTIONAL, INTENT(in) :: plon_pnt, plat_pnt  ! Lat/lon coord. of the point of cell (i,j) 
    23302213      ! 
    2331       INTEGER :: ji, jj, jn, ni, nj 
     2214      INTEGER :: ji, jj, jn 
    23322215      INTEGER :: icnr, jcnr                             ! Offset such that the vertex coordinate (i+icnr,j+jcnr) 
    2333       !                                                 ! represents the bottom-left corner of cell (i,j) 
     2216      !                                                 ! represents the 
     2217      !                                                 bottom-left corner of 
     2218      !                                                 cell (i,j) 
    23342219      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: z_bnds      ! Lat/lon coordinates of the vertices of cell (i,j) 
    23352220      REAL(wp), ALLOCATABLE, DIMENSION(:,:)     :: z_fld       ! Working array to determine where to rotate cells 
     
    23462231      END SELECT 
    23472232      ! 
    2348       ni = nlei-nldi+1   ! Dimensions of subdomain interior 
    2349       nj = nlej-nldj+1 
    2350       ! 
    23512233      z_fld(:,:) = 1._wp 
    23522234      CALL lbc_lnk( 'iom', z_fld, cdgrd, -1.0_wp )    ! Working array for location of northfold 
    23532235      ! 
    23542236      ! Cell vertices that can be defined 
    2355       DO jj = 2, jpjm1 
    2356          DO ji = 2, jpim1 
    2357             z_bnds(1,ji,jj,1) = plat_cnr(ji+icnr,  jj+jcnr  ) ! Bottom-left 
    2358             z_bnds(2,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr  ) ! Bottom-right 
    2359             z_bnds(3,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right 
    2360             z_bnds(4,ji,jj,1) = plat_cnr(ji+icnr,  jj+jcnr+1) ! Top-left 
    2361             z_bnds(1,ji,jj,2) = plon_cnr(ji+icnr,  jj+jcnr  ) ! Bottom-left 
    2362             z_bnds(2,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr  ) ! Bottom-right 
    2363             z_bnds(3,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right 
    2364             z_bnds(4,ji,jj,2) = plon_cnr(ji+icnr,  jj+jcnr+1) ! Top-left 
    2365          END DO 
    2366       END DO 
    2367       ! 
    2368       ! Cell vertices on boundries 
    2369       DO jn = 1, 4 
    2370          CALL lbc_lnk( 'iom', z_bnds(jn,:,:,1), cdgrd, 1.0_wp, pfillval=999._wp ) 
    2371          CALL lbc_lnk( 'iom', z_bnds(jn,:,:,2), cdgrd, 1.0_wp, pfillval=999._wp ) 
    2372       END DO 
    2373       ! 
    2374       ! Zero-size cells at closed boundaries if cell points provided, 
    2375       ! otherwise they are closed cells with unrealistic bounds 
    2376       IF( PRESENT(plon_pnt) .AND. PRESENT(plat_pnt) ) THEN 
    2377          IF( (nbondi == -1 .OR. nbondi == 2) .AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6) ) THEN 
    2378             DO jn = 1, 4        ! (West or jpni = 1), closed E-W 
    2379                z_bnds(jn,1,:,1) = plat_pnt(1,:)  ;  z_bnds(jn,1,:,2) = plon_pnt(1,:) 
    2380             END DO 
     2237      DO_2D( 0, 0, 0, 0 ) 
     2238         z_bnds(1,ji,jj,1) = plat_cnr(ji+icnr,  jj+jcnr  ) ! Bottom-left 
     2239         z_bnds(2,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr  ) ! Bottom-right 
     2240         z_bnds(3,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right 
     2241         z_bnds(4,ji,jj,1) = plat_cnr(ji+icnr,  jj+jcnr+1) ! Top-left 
     2242         z_bnds(1,ji,jj,2) = plon_cnr(ji+icnr,  jj+jcnr  ) ! Bottom-left 
     2243         z_bnds(2,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr  ) ! Bottom-right 
     2244         z_bnds(3,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right 
     2245         z_bnds(4,ji,jj,2) = plon_cnr(ji+icnr,  jj+jcnr+1) ! Top-left 
     2246      END_2D 
     2247      ! 
     2248      DO_2D( 0, 0, 0, 0 ) 
     2249         IF( z_fld(ji,jj) == -1. ) THEN 
     2250            z_rot(1,:) = z_bnds(3,ji,jj,:) ; z_rot(2,:) = z_bnds(4,ji,jj,:) 
     2251            z_rot(3,:) = z_bnds(1,ji,jj,:) ; z_rot(4,:) = z_bnds(2,ji,jj,:) 
     2252            z_bnds(:,ji,jj,:) = z_rot(:,:) 
    23812253         ENDIF 
    2382          IF( (nbondi == 1 .OR. nbondi == 2) .AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6) ) THEN 
    2383             DO jn = 1, 4        ! (East or jpni = 1), closed E-W 
    2384                z_bnds(jn,nlci,:,1) = plat_pnt(nlci,:)  ;  z_bnds(jn,nlci,:,2) = plon_pnt(nlci,:) 
    2385             END DO 
    2386          ENDIF 
    2387          IF( nbondj == -1 .OR. (nbondj == 2 .AND. jperio /= 2) ) THEN 
    2388             DO jn = 1, 4        ! South or (jpnj = 1, not symmetric) 
    2389                z_bnds(jn,:,1,1) = plat_pnt(:,1)  ;  z_bnds(jn,:,1,2) = plon_pnt(:,1) 
    2390             END DO 
    2391          ENDIF 
    2392          IF( (nbondj == 1 .OR. nbondj == 2) .AND. jperio  < 3 ) THEN 
    2393             DO jn = 1, 4        ! (North or jpnj = 1), no north fold 
    2394                z_bnds(jn,:,nlcj,1) = plat_pnt(:,nlcj)  ;  z_bnds(jn,:,nlcj,2) = plon_pnt(:,nlcj) 
    2395             END DO 
    2396          ENDIF 
    2397       ENDIF 
    2398       ! 
    2399       IF( (nbondj == 1 .OR. nbondj == 2) .AND. jperio >= 3 ) THEN    ! Rotate cells at the north fold 
    2400          DO jj = 1, jpj 
    2401             DO ji = 1, jpi 
    2402                IF( z_fld(ji,jj) == -1. ) THEN 
    2403                   z_rot(1,:) = z_bnds(3,ji,jj,:) ; z_rot(2,:) = z_bnds(4,ji,jj,:) 
    2404                   z_rot(3,:) = z_bnds(1,ji,jj,:) ; z_rot(4,:) = z_bnds(2,ji,jj,:) 
    2405                   z_bnds(:,ji,jj,:) = z_rot(:,:) 
    2406                ENDIF 
    2407             END DO 
    2408          END DO 
    2409       ELSE IF( nbondj == 2 .AND. jperio == 2 ) THEN                  ! Invert cells at the symmetric equator 
    2410          DO ji = 1, jpi 
    2411             z_rot(1:2,:) = z_bnds(3:4,ji,1,:) 
    2412             z_rot(3:4,:) = z_bnds(1:2,ji,1,:) 
    2413             z_bnds(:,ji,1,:) = z_rot(:,:) 
    2414          END DO 
    2415       ENDIF 
    2416       ! 
    2417       CALL iom_set_domain_attr("grid_"//cdgrd, bounds_lat =real( RESHAPE(z_bnds(:,nldi:nlei,nldj:nlej,1),(/ 4,ni*nj /)), dp),           & 
    2418           &                                    bounds_lon =real( RESHAPE(z_bnds(:,nldi:nlei,nldj:nlej,2),(/ 4,ni*nj /)), dp), nvertex=4 ) 
    2419       ! 
    2420       DEALLOCATE( z_bnds, z_fld, z_rot )  
     2254      END_2D 
     2255      ! 
     2256      CALL iom_set_domain_attr("grid_"//cdgrd, bounds_lat = real(RESHAPE(z_bnds(:,Nis0:Nie0,Njs0:Nje0,1),(/ 4,Ni_0*Nj_0 /)), dp),           & 
     2257          &                                    bounds_lon = real(RESHAPE(z_bnds(:,Nis0:Nie0,Njs0:Nje0,2),(/ 4,Ni_0*Nj_0 /)), dp), nvertex=4 ) 
     2258      ! 
     2259      DEALLOCATE( z_bnds, z_fld, z_rot ) 
    24212260      ! 
    24222261   END SUBROUTINE set_grid_bounds 
    24232262 
    2424  
    24252263   SUBROUTINE set_grid_znl( plat ) 
    24262264      !!---------------------------------------------------------------------- 
     
    24322270      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat 
    24332271      ! 
    2434       INTEGER  :: ni, nj, ix, iy 
     2272      INTEGER  :: ix, iy 
    24352273      REAL(wp), DIMENSION(:), ALLOCATABLE  ::   zlon 
    24362274      !!---------------------------------------------------------------------- 
    24372275      ! 
    2438       ni=nlei-nldi+1       ! define zonal mean domain (jpj*jpk) 
    2439       nj=nlej-nldj+1 
    2440       ALLOCATE( zlon(ni*nj) )       ;       zlon(:) = 0._wp 
     2276      ALLOCATE( zlon(Ni_0*Nj_0) )       ;       zlon(:) = 0._wp 
    24412277      ! 
    24422278!      CALL dom_ngb( -168.53_wp, 65.03_wp, ix, iy, 'T' ) !  i-line that passes through Bering Strait: Reference latitude (used in plots) 
    24432279      CALL dom_ngb( 180.0_wp, 90.0_wp, ix, iy, 'T' ) !  i-line that passes near the North Pole : Reference latitude (used in plots) 
    2444       CALL iom_set_domain_attr("gznl", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj) 
    2445       CALL iom_set_domain_attr("gznl", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj) 
     2280      CALL iom_set_domain_attr("gznl", ni_glo=Ni0glo, nj_glo=Nj0glo, ibegin=mig0(Nis0)-1, jbegin=mjg0(Njs0)-1, ni=Ni_0, nj=Nj_0) 
     2281      CALL iom_set_domain_attr("gznl", data_dim=2, data_ibegin = -nn_hls, data_ni = jpi, data_jbegin = -nn_hls, data_nj = jpj) 
    24462282      CALL iom_set_domain_attr("gznl", lonvalue = real(zlon, dp),   & 
    2447          &                             latvalue = real(RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /)),dp))   
    2448       CALL iom_set_zoom_domain_attr("ptr", ibegin=ix-1, jbegin=0, ni=1, nj=jpjglo) 
     2283         &                             latvalue = real(RESHAPE(plat(Nis0:Nie0, Njs0:Nje0),(/ Ni_0*Nj_0 /)),dp))   
     2284      CALL iom_set_zoom_domain_attr("ptr", ibegin=ix-1, jbegin=0, ni=1, nj=Nj0glo) 
    24492285      ! 
    24502286      CALL iom_update_file_name('ptr') 
     
    25232359         ! Equatorial section (attributs: jbegin, ni, name_suffix) 
    25242360         CALL dom_ngb( 0.0_wp, 0.0_wp, ix, iy, cl1 ) 
    2525          CALL iom_set_zoom_domain_attr('Eq'//cl1, ibegin=0, jbegin=iy-1, ni=jpiglo, nj=1 ) 
     2361         CALL iom_set_zoom_domain_attr('Eq'//cl1, ibegin=0, jbegin=iy-1, ni=Ni0glo, nj=1 ) 
    25262362         CALL iom_get_file_attr   ('Eq'//cl1, name_suffix = clsuff             ) 
    25272363         CALL iom_set_file_attr   ('Eq'//cl1, name_suffix = TRIM(clsuff)//'_Eq') 
Note: See TracChangeset for help on using the changeset viewer.