Index: branches/ORCHIDEE_2_2/ORCHIDEE/src_global/interregxy.f90
===================================================================
--- branches/ORCHIDEE_2_2/ORCHIDEE/src_global/interregxy.f90	(revision 7595)
+++ branches/ORCHIDEE_2_2/ORCHIDEE/src_global/interregxy.f90	(revision 7597)
@@ -31,5 +31,5 @@
     REAL(r_std), INTENT(in)      :: lat_rel(iml, jml)    ! Latitudes for the souce grid
     INTEGER(i_std), INTENT(in)   :: mask(iml, jml)       ! Mask which retains only the significative points
-                                                         ! of the source grid.
+    ! of the source grid.
     CHARACTER(LEN=*), INTENT(in) :: callsign             ! Allows to specify which variable is beeing treated
     INTEGER(i_std), INTENT(in)   :: incmax               ! Maximum point of the source grid we can store.
@@ -81,74 +81,77 @@
        DO js=1,jml
           !
-          ! 1.0 Get the center of the box and their corresponding grid point 
-          !
-          lons(1) = lon_rel(is,js)
-          lats(1) = lat_rel(is,js)
-          !
-          ! Assume all grids go from West to Est
-          dle=(lon_rel(MIN(is+1,iml),js)-lon_rel(is,js))/2.0
-          dlw=(lon_rel(is,js)-lon_rel(MAX(is-1,1),js))/2.0
-          ! 
-          IF ( lat_rel(1,1) < lat_rel(iml,jml)) THEN
-             ! Grid in SN direction
-             dls=(lat_rel(is,js)-lat_rel(is,MAX(js-1,1)))/2.0
-             dln=(lat_rel(is,MIN(js+1,jml))-lat_rel(is,js))/2.0
-          ELSE
-             dls=(lat_rel(is,js)-lat_rel(is,MIN(js+1,jml)))/2.0
-             dln=(lat_rel(is,MAX(js-1,1))-lat_rel(is,js))/2.0
-          ENDIF
-          ! Treat the border cases
-          IF ( dlw < dle/2. ) dlw = dle
-          IF ( dle < dlw/2. ) dle = dlw
-          !
-          IF ( dls < dln/2. ) dls = dln
-          IF ( dln < dls/2. ) dln = dls
-          !
-          DO i=0,sbd
-             ! Put the points in the order : SW, SE, NE, NW
-             lons(2+i) = lons(1) - dlw + i*((dlw+dle)/FLOAT(sbd+1))
-             lats(2+i) = lats(1) - dls
-             !
-             lons(2+(sbd+1)+i) = lons(1) + dle
-             lats(2+(sbd+1)+i) = lats(1) - dls + i*((dls+dln)/FLOAT(sbd+1))
-             !
-             lons(2+2*(sbd+1)+i) = lons(1) + dle - i*((dlw+dle)/FLOAT(sbd+1))
-             lats(2+2*(sbd+1)+i) = lats(1) + dln
-             !
-             lons(2+3*(sbd+1)+i) = lons(1) - dlw
-             lats(2+3*(sbd+1)+i) = lats(1) + dln - i*((dls+dln)/FLOAT(sbd+1))
-          ENDDO
-          !
-          ! Test that the polygone overlaps with the Bounding box. We might have projections
-          ! which are not valid outside of the RCM domain.
-          !
-          IF ( ((MINVAL(lons) > BBlon(1) .AND. MINVAL(lons) < BBlon(2)) .OR.   &
-             &  (MAXVAL(lons) > BBlon(1) .AND. MAXVAL(lons) < BBlon(2))) .AND. & 
-             & ((MINVAL(lats) > BBlat(1) .AND. MINVAL(lats) < BBlat(2)) .OR.   &
-             &  (MAXVAL(lats) > BBlat(1) .AND. MAXVAL(lats) < BBlat(2)))) THEN
-             !
-             !
-             CALL Grid_Toij (lons, lats, ri, rj)
-             !
-             !
-             ! Find the points of the WRF grid boxes we need to scan to place this box (is, js) 
-             ! of the source grid.
-             !
-             ilow = MAX(FLOOR(MINVAL(ri)),1)
-             iup  = MIN(CEILING(MAXVAL(ri)), iim_g)
-             jlow = MAX(FLOOR(MINVAL(rj)),1)
-             jup  = MIN(CEILING(MAXVAL(rj)), jjm_g)
-             !
-             !
-             IF ( ilow < iup .OR. jlow < jup ) THEN
-                !
-                ! Find the grid boxes in WRF and compute the overlap area.
-                !
-                CALL interregxy_findpoints(iim_g, jjm_g, lon_rel(is,js), lon_rel(is,js), is, js, ri, rj, incmax, &
-                     &    checkprint, nbov, sourcei, sourcej, overlap)
-                
-             ENDIF
-             !
-             !
+          IF ( mask(is,js) == 1 ) THEN
+             !
+             ! 1.0 Get the center of the box and their corresponding grid point 
+             !
+             lons(1) = lon_rel(is,js)
+             lats(1) = lat_rel(is,js)
+             !
+             ! Assume all grids go from West to Est
+             dle=(lon_rel(MIN(is+1,iml),js)-lon_rel(is,js))/2.0
+             dlw=(lon_rel(is,js)-lon_rel(MAX(is-1,1),js))/2.0
+             ! 
+             IF ( lat_rel(1,1) < lat_rel(iml,jml)) THEN
+                ! Grid in SN direction
+                dls=(lat_rel(is,js)-lat_rel(is,MAX(js-1,1)))/2.0
+                dln=(lat_rel(is,MIN(js+1,jml))-lat_rel(is,js))/2.0
+             ELSE
+                dls=(lat_rel(is,js)-lat_rel(is,MIN(js+1,jml)))/2.0
+                dln=(lat_rel(is,MAX(js-1,1))-lat_rel(is,js))/2.0
+             ENDIF
+             ! Treat the border cases
+             IF ( dlw < dle/2. ) dlw = dle
+             IF ( dle < dlw/2. ) dle = dlw
+             !
+             IF ( dls < dln/2. ) dls = dln
+             IF ( dln < dls/2. ) dln = dls
+             !
+             DO i=0,sbd
+                ! Put the points in the order : SW, SE, NE, NW
+                lons(2+i) = lons(1) - dlw + i*((dlw+dle)/FLOAT(sbd+1))
+                lats(2+i) = lats(1) - dls
+                !
+                lons(2+(sbd+1)+i) = lons(1) + dle
+                lats(2+(sbd+1)+i) = lats(1) - dls + i*((dls+dln)/FLOAT(sbd+1))
+                !
+                lons(2+2*(sbd+1)+i) = lons(1) + dle - i*((dlw+dle)/FLOAT(sbd+1))
+                lats(2+2*(sbd+1)+i) = lats(1) + dln
+                !
+                lons(2+3*(sbd+1)+i) = lons(1) - dlw
+                lats(2+3*(sbd+1)+i) = lats(1) + dln - i*((dls+dln)/FLOAT(sbd+1))
+             ENDDO
+             !
+             ! Test that the polygone overlaps with the Bounding box. We might have projections
+             ! which are not valid outside of the RCM domain.
+             !
+             IF ( ((MINVAL(lons) > BBlon(1) .AND. MINVAL(lons) < BBlon(2)) .OR.   &
+                  &  (MAXVAL(lons) > BBlon(1) .AND. MAXVAL(lons) < BBlon(2))) .AND. & 
+                  & ((MINVAL(lats) > BBlat(1) .AND. MINVAL(lats) < BBlat(2)) .OR.   &
+                  &  (MAXVAL(lats) > BBlat(1) .AND. MAXVAL(lats) < BBlat(2)))) THEN
+                !
+                !
+                CALL Grid_Toij (lons, lats, ri, rj)
+                !
+                !
+                ! Find the points of the WRF grid boxes we need to scan to place this box (is, js) 
+                ! of the source grid.
+                !
+                ilow = MAX(FLOOR(MINVAL(ri)),1)
+                iup  = MIN(CEILING(MAXVAL(ri)), iim_g)
+                jlow = MAX(FLOOR(MINVAL(rj)),1)
+                jup  = MIN(CEILING(MAXVAL(rj)), jjm_g)
+                !
+                !
+                IF ( ilow < iup .OR. jlow < jup ) THEN
+                   !
+                   ! Find the grid boxes in WRF and compute the overlap area.
+                   !
+                   CALL interregxy_findpoints(iim_g, jjm_g, lon_rel(is,js), lon_rel(is,js), is, js, ri, rj, incmax, &
+                        &    checkprint, nbov, sourcei, sourcej, overlap)
+
+                ENDIF
+                !
+                !
+             ENDIF
           ENDIF
        ENDDO
