Index: trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 5412)
+++ trunk/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 5415)
@@ -98,5 +98,9 @@
       CHARACTER(len=10) :: clname
       INTEGER           ::   ji
-      !!----------------------------------------------------------------------
+      !
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_bnds
+      !!----------------------------------------------------------------------
+
+      ALLOCATE( z_bnds(jpk,2) )
 
       clname = cdname
@@ -123,4 +127,15 @@
          CALL set_grid( "W", glamt, gphit )
          CALL set_grid_znl( gphit )
+         !
+         IF( ln_cfmeta ) THEN   ! Add additional grid metadata
+            CALL iom_set_domain_attr("grid_T", area = e12t(nldi:nlei, nldj:nlej))
+            CALL iom_set_domain_attr("grid_U", area = e12u(nldi:nlei, nldj:nlej))
+            CALL iom_set_domain_attr("grid_V", area = e12v(nldi:nlei, nldj:nlej))
+            CALL iom_set_domain_attr("grid_W", area = e12t(nldi:nlei, nldj:nlej))
+            CALL set_grid_bounds( "T", glamf, gphif, glamt, gphit )
+            CALL set_grid_bounds( "U", glamv, gphiv, glamu, gphiu )
+            CALL set_grid_bounds( "V", glamu, gphiu, glamv, gphiv )
+            CALL set_grid_bounds( "W", glamf, gphif, glamt, gphit )
+         ENDIF
       ENDIF
 
@@ -135,11 +150,15 @@
           !
          CALL dom_grid_glo   ! Return to parent grid domain
-      ENDIF
-
-      IF ( ln_cfmeta ) THEN   ! add cell bounds
-         CALL set_grid_bounds( "T", cdname ) 
-         CALL set_grid_bounds( "U", cdname )
-         CALL set_grid_bounds( "V", cdname )
-         CALL set_grid_bounds( "W", cdname )
+         !
+         IF( ln_cfmeta ) THEN   ! Add additional grid metadata
+            CALL iom_set_domain_attr("grid_T", area = e1e2t_crs(nldi:nlei, nldj:nlej))
+            CALL iom_set_domain_attr("grid_U", area = e1u_crs(nldi:nlei, nldj:nlej) * e2u_crs(nldi:nlei, nldj:nlej))
+            CALL iom_set_domain_attr("grid_V", area = e1v_crs(nldi:nlei, nldj:nlej) * e2v_crs(nldi:nlei, nldj:nlej))
+            CALL iom_set_domain_attr("grid_W", area = e1e2t_crs(nldi:nlei, nldj:nlej))
+            CALL set_grid_bounds( "T", glamf_crs, gphif_crs, glamt_crs, gphit_crs )
+            CALL set_grid_bounds( "U", glamv_crs, gphiv_crs, glamu_crs, gphiu_crs )
+            CALL set_grid_bounds( "V", glamu_crs, gphiu_crs, glamv_crs, gphiv_crs )
+            CALL set_grid_bounds( "W", glamf_crs, gphif_crs, glamt_crs, gphit_crs )
+         ENDIF
       ENDIF
 
@@ -149,4 +168,17 @@
       CALL iom_set_axis_attr( "depthv", gdept_1d )
       CALL iom_set_axis_attr( "depthw", gdepw_1d )
+
+      ! Add vertical grid bounds
+      z_bnds(:      ,1) = gdepw_1d(:)
+      z_bnds(1:jpkm1,2) = gdepw_1d(2:jpk)
+      z_bnds(jpk:   ,2) = gdepw_1d(jpk) + e3t_1d(jpk)
+      CALL iom_set_axis_attr( "deptht", bounds=z_bnds )
+      CALL iom_set_axis_attr( "depthu", bounds=z_bnds )
+      CALL iom_set_axis_attr( "depthv", bounds=z_bnds )
+      z_bnds(:    ,2) = gdept_1d(:)
+      z_bnds(2:jpk,1) = gdept_1d(1:jpkm1)
+      z_bnds(1    ,1) = gdept_1d(1) - e3w_1d(1)
+      CALL iom_set_axis_attr( "depthw", bounds=z_bnds )
+
 # if defined key_floats
       CALL iom_set_axis_attr( "nfloat", (/ (REAL(ji,wp), ji=1,nfloat) /) )
@@ -168,4 +200,7 @@
       
       CALL xios_update_calendar(0)
+
+      DEALLOCATE( z_bnds )
+
 #endif
       
@@ -1069,9 +1104,6 @@
       CHARACTER(LEN=*), INTENT(in) ::   cdname
       REAL(wp)        , INTENT(in) ::   pfield0d
-      REAL(wp)        , DIMENSION(jpi,jpj) ::   zz     ! masson
 #if defined key_iomput
-      zz(:,:)=pfield0d
-      CALL xios_send_field(cdname, zz)
-      !CALL xios_send_field(cdname, (/pfield0d/)) 
+      CALL xios_send_field(cdname, (/pfield0d/)) 
 #else
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
@@ -1114,5 +1146,5 @@
    SUBROUTINE iom_set_domain_attr( cdid, ni_glo, nj_glo, ibegin, jbegin, ni, nj, zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj,   &
       &                                    data_dim, data_ibegin, data_ni, data_jbegin, data_nj, lonvalue, latvalue, mask,     &
-      &                                    nvertex, bounds_lon, bounds_lat )
+      &                                    nvertex, bounds_lon, bounds_lat, area )
       CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
       INTEGER                  , OPTIONAL, INTENT(in) ::   ni_glo, nj_glo, ibegin, jbegin, ni, nj
@@ -1120,5 +1152,5 @@
       INTEGER                  , OPTIONAL, INTENT(in) ::   zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj, nvertex
       REAL(wp), DIMENSION(:)   , OPTIONAL, INTENT(in) ::   lonvalue, latvalue
-      REAL(wp), DIMENSION(:,:) , OPTIONAL, INTENT(in) ::   bounds_lon, bounds_lat
+      REAL(wp), DIMENSION(:,:) , OPTIONAL, INTENT(in) ::   bounds_lon, bounds_lat, area
       LOGICAL,  DIMENSION(:,:) , OPTIONAL, INTENT(in) ::   mask
 
@@ -1127,5 +1159,6 @@
             &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
             &    zoom_ibegin=zoom_ibegin, zoom_jbegin=zoom_jbegin, zoom_ni=zoom_ni, zoom_nj=zoom_nj,                       &
-            &    lonvalue=lonvalue, latvalue=latvalue, mask=mask, nvertex=nvertex, bounds_lon=bounds_lon, bounds_lat=bounds_lat )
+            &    lonvalue=lonvalue, latvalue=latvalue, mask=mask, nvertex=nvertex, bounds_lon=bounds_lon,                  &
+            &    bounds_lat=bounds_lat, area=area )
       ENDIF
 
@@ -1134,5 +1167,6 @@
             &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
             &    zoom_ibegin=zoom_ibegin, zoom_jbegin=zoom_jbegin, zoom_ni=zoom_ni, zoom_nj=zoom_nj,                       &
-            &    lonvalue=lonvalue, latvalue=latvalue, mask=mask, nvertex=nvertex, bounds_lon=bounds_lon, bounds_lat=bounds_lat )
+            &    lonvalue=lonvalue, latvalue=latvalue, mask=mask, nvertex=nvertex, bounds_lon=bounds_lon,                  &
+            &    bounds_lat=bounds_lat, area=area )
       ENDIF
       CALL xios_solve_inheritance()
@@ -1141,9 +1175,14 @@
 
 
-   SUBROUTINE iom_set_axis_attr( cdid, paxis )
+   SUBROUTINE iom_set_axis_attr( cdid, paxis, bounds )
       CHARACTER(LEN=*)      , INTENT(in) ::   cdid
-      REAL(wp), DIMENSION(:), INTENT(in) ::   paxis
-      IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, size=size(paxis),value=paxis )
-      IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, size=size(paxis),value=paxis )
+      REAL(wp), DIMENSION(:)  , OPTIONAL, INTENT(in) ::   paxis
+      REAL(wp), DIMENSION(:,:), OPTIONAL, INTENT(in) ::   bounds
+      IF ( PRESENT(paxis) ) THEN
+         IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, size=SIZE(paxis), value=paxis )
+         IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, size=SIZE(paxis), value=paxis )
+      ENDIF
+      IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, bounds=bounds )
+      IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, bounds=bounds )
       CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_axis_attr
@@ -1261,5 +1300,5 @@
 
 
-   SUBROUTINE set_grid_bounds( cdgrd, cdname )
+   SUBROUTINE set_grid_bounds( cdgrd, plon_cnr, plat_cnr, plon_pnt, plat_pnt )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE set_grid_bounds  ***
@@ -1269,9 +1308,9 @@
       !!----------------------------------------------------------------------
       CHARACTER(LEN=1) , INTENT(in) :: cdgrd
-      CHARACTER(LEN=*) , INTENT(in) :: cdname
+      !
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in)           :: plon_cnr, plat_cnr  ! Lat/lon coordinates of a contiguous vertex of cell (i,j)
+      REAL(wp), DIMENSION(jpi,jpj), OPTIONAL, INTENT(in) :: plon_pnt, plat_pnt  ! Lat/lon coordinates of the point of cell (i,j)
       !
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:)   :: z_bnds      ! Lat/lon coordinates of the vertices of cell (i,j)
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)     :: z_cnr       ! Lat/lon coordinates of a contiguous vertex of cell (i,j)
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)     :: z_pnt       ! Lat/lon coordinates of the point of cell (i,j)
       REAL(wp), ALLOCATABLE, DIMENSION(:,:)       :: z_fld       ! Working array to determine where to rotate cells
       REAL(wp), ALLOCATABLE, DIMENSION(:,:)       :: z_rot       ! Lat/lon working array for rotation of cells
@@ -1281,35 +1320,14 @@
       INTEGER :: ji, jj, jn, ni, nj
 
-      ALLOCATE( z_bnds(4,jpi,jpj,2), z_cnr(jpi,jpj,2), z_pnt(jpi,jpj,2), z_fld(jpi,jpj), z_rot(4,2)  )
-
-      ! Grid information
+      ALLOCATE( z_bnds(4,jpi,jpj,2), z_fld(jpi,jpj), z_rot(4,2)  )
+
+      ! Offset of coordinate representing bottom-left corner
       SELECT CASE ( TRIM(cdgrd) )
          CASE ('T', 'W')
             icnr = -1 ; jcnr = -1
-            IF( TRIM(cdname) == TRIM(cxios_context)//"_crs" ) THEN
-               z_cnr(:,:,1) = gphif_crs ; z_cnr(:,:,2) = glamf_crs
-               z_pnt(:,:,1) = gphit_crs ; z_pnt(:,:,2) = glamt_crs
-            ELSE
-               z_cnr(:,:,1) = gphif ; z_cnr(:,:,2) = glamf
-               z_pnt(:,:,1) = gphit ; z_pnt(:,:,2) = glamt
-            ENDIF
          CASE ('U')
             icnr =  0 ; jcnr = -1
-            IF( TRIM(cdname) == TRIM(cxios_context)//"_crs" ) THEN
-               z_cnr(:,:,1) = gphiv_crs ; z_cnr(:,:,2) = glamv_crs
-               z_pnt(:,:,1) = gphiu_crs ; z_pnt(:,:,2) = glamu_crs
-            ELSE
-               z_cnr(:,:,1) = gphiv ; z_cnr(:,:,2) = glamv
-               z_pnt(:,:,1) = gphiu ; z_pnt(:,:,2) = glamu
-            ENDIF
          CASE ('V')
             icnr = -1 ; jcnr =  0
-            IF( TRIM(cdname) == TRIM(cxios_context)//"_crs" ) THEN
-               z_cnr(:,:,1) = gphiu_crs ; z_cnr(:,:,2) = glamu_crs
-               z_pnt(:,:,1) = gphiv_crs ; z_pnt(:,:,2) = glamv_crs
-            ELSE
-               z_cnr(:,:,1) = gphiu ; z_cnr(:,:,2) = glamu
-               z_pnt(:,:,1) = gphiv ; z_pnt(:,:,2) = glamv
-            ENDIF
       END SELECT
 
@@ -1322,8 +1340,12 @@
       DO jj = 2, jpjm1
          DO ji = 2, jpim1
-            z_bnds(1,ji,jj,:) = z_cnr(ji+icnr,  jj+jcnr  ,:) ! Bottom-left
-            z_bnds(2,ji,jj,:) = z_cnr(ji+icnr+1,jj+jcnr  ,:) ! Bottom-right
-            z_bnds(3,ji,jj,:) = z_cnr(ji+icnr+1,jj+jcnr+1,:) ! Top-right
-            z_bnds(4,ji,jj,:) = z_cnr(ji+icnr,  jj+jcnr+1,:) ! Top-left
+            z_bnds(1,ji,jj,1) = plat_cnr(ji+icnr,  jj+jcnr  ) ! Bottom-left
+            z_bnds(2,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr  ) ! Bottom-right
+            z_bnds(3,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right
+            z_bnds(4,ji,jj,1) = plat_cnr(ji+icnr,  jj+jcnr+1) ! Top-left
+            z_bnds(1,ji,jj,2) = plon_cnr(ji+icnr,  jj+jcnr  ) ! Bottom-left
+            z_bnds(2,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr  ) ! Bottom-right
+            z_bnds(3,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right
+            z_bnds(4,ji,jj,2) = plon_cnr(ji+icnr,  jj+jcnr+1) ! Top-left
          END DO
       END DO
@@ -1335,21 +1357,28 @@
       END DO
 
-      ! Zero-size cells at closed boundaries
-      IF( (nbondi == -1 .OR. nbondi == 2) .AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6) ) THEN
-         DO jn = 1, 4  ;  z_bnds(jn,1,:,:) = z_pnt(1,:,:)        ;  END DO      ! (West or jpni = 1), closed E-W
-      ENDIF
-      IF( (nbondi == 1 .OR. nbondi == 2) .AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6) ) THEN
-         DO jn = 1, 4  ;  z_bnds(jn,nlci,:,:) = z_pnt(nlci,:,:)  ;  END DO      ! (East or jpni = 1), closed E-W
-      ENDIF
-      IF( nbondj == -1 .OR. (nbondj == 2 .AND. jperio /= 2) ) THEN
-         DO jn = 1, 4  ;  z_bnds(jn,:,1,:) = z_pnt(:,1,:)        ;  END DO      ! South or (jpnj = 1, not symmetric)
-      ENDIF
-      IF( (nbondj == 1 .OR. nbondj == 2) .AND. jperio  < 3 ) THEN
-         DO jn = 1, 4  ;  z_bnds(jn,:,nlcj,:) = z_pnt(:,nlcj,:)  ;  END DO      ! (North or jpnj = 1), no north fold
-      ENDIF
-
-! =====================================================================================================
-!             Do we need to set zero-size cells at Mediterranean / Persian Gulf region?
-! =====================================================================================================
+      ! Zero-size cells at closed boundaries if cell points provided,
+      ! otherwise they are closed cells with unrealistic bounds
+      IF( PRESENT(plon_pnt) .AND. PRESENT(plat_pnt) ) THEN
+         IF( (nbondi == -1 .OR. nbondi == 2) .AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6) ) THEN
+            DO jn = 1, 4        ! (West or jpni = 1), closed E-W
+               z_bnds(jn,1,:,1) = plat_pnt(1,:)  ;  z_bnds(jn,1,:,2) = plon_pnt(1,:)
+            END DO
+         ENDIF
+         IF( (nbondi == 1 .OR. nbondi == 2) .AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6) ) THEN
+            DO jn = 1, 4        ! (East or jpni = 1), closed E-W
+               z_bnds(jn,nlci,:,1) = plat_pnt(nlci,:)  ;  z_bnds(jn,nlci,:,2) = plon_pnt(nlci,:)
+            END DO
+         ENDIF
+         IF( nbondj == -1 .OR. (nbondj == 2 .AND. jperio /= 2) ) THEN
+            DO jn = 1, 4        ! South or (jpnj = 1, not symmetric)
+               z_bnds(jn,:,1,1) = plat_pnt(:,1)  ;  z_bnds(jn,:,1,2) = plon_pnt(:,1)
+            END DO
+         ENDIF
+         IF( (nbondj == 1 .OR. nbondj == 2) .AND. jperio  < 3 ) THEN
+            DO jn = 1, 4        ! (North or jpnj = 1), no north fold
+               z_bnds(jn,:,nlcj,1) = plat_pnt(:,nlcj)  ;  z_bnds(jn,:,nlcj,2) = plon_pnt(:,nlcj)
+            END DO
+         ENDIF
+      ENDIF
 
       ! Rotate cells at the north fold
@@ -1377,5 +1406,5 @@
                                                bounds_lon = RESHAPE(z_bnds(:,nldi:nlei,nldj:nlej,2),(/ 4,ni*nj /)), nvertex=4 )
 
-      DEALLOCATE( z_bnds, z_cnr, z_pnt, z_fld, z_rot ) 
+      DEALLOCATE( z_bnds, z_fld, z_rot ) 
 
    END SUBROUTINE set_grid_bounds
@@ -1416,10 +1445,22 @@
       !!
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(1) ::   zz = 1.
+      REAL(wp), DIMENSION(1)   ::   zz = 0.
+      REAL(wp), DIMENSION(4,1) ::   z_lat, z_lon
       !!----------------------------------------------------------------------
       CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea, jbegin=1, ni=1, nj=1)
-      CALL iom_set_domain_attr('scalarpoint', data_dim=2, data_ibegin = 1, data_ni = 1, data_jbegin = 1, data_nj = 1)
+      CALL iom_set_domain_attr('scalarpoint', data_dim=2, data_ibegin = 0, data_ni = 1, data_jbegin = 0, data_nj = 1)
+      
+      z_lon(1,:) = MINVAL(glamt) ; z_lon(2,:) = MAXVAL(glamt) ; z_lon(3,:) = MAXVAL(glamt) ; z_lon(4,:) = MINVAL(glamt)
+      z_lat(1,:) = MINVAL(gphit) ; z_lat(2,:) = MINVAL(gphit) ; z_lat(3,:) = MAXVAL(gphit) ; z_lat(4,:) = MAXVAL(gphit)
+
+      IF( lk_mpp ) THEN
+         CALL mpp_min( z_lon(1,1) ) ; CALL mpp_min( z_lon(4,1) ) ; CALL mpp_max( z_lon(2,1) ) ; CALL mpp_max( z_lon(3,1) )
+         CALL mpp_min( z_lat(1,1) ) ; CALL mpp_min( z_lat(2,1) ) ; CALL mpp_max( z_lat(3,1) ) ; CALL mpp_max( z_lat(4,1) )
+      ENDIF
+
+      CALL iom_set_domain_attr('globalscalar', lonvalue=zz, latvalue=zz, bounds_lon=z_lon, bounds_lat=z_lat, nvertex=4)
+
       zz=REAL(narea,wp)
-      CALL iom_set_domain_attr('scalarpoint', lonvalue=zz, latvalue=zz)
+      CALL iom_set_domain_attr('1point', lonvalue=zz, latvalue=zz)
 
    END SUBROUTINE set_scalar
