Index: branches/2012/dev_MERCATOR_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbcdcy.F90
===================================================================
--- branches/2012/dev_MERCATOR_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbcdcy.F90	(revision 3582)
+++ branches/2012/dev_MERCATOR_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbcdcy.F90	(revision 3586)
@@ -49,5 +49,5 @@
 
 
-   FUNCTION sbc_dcy( pqsrin ) RESULT( zqsrout )
+   FUNCTION sbc_dcy( pqsrin, l_mask ) RESULT( zqsrout )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE sbc_dcy  ***
@@ -63,11 +63,14 @@
       !!              Part 1: a diurnally forced OGCM. Climate Dynamics 29:6, 575-590.
       !!----------------------------------------------------------------------
+      LOGICAL, OPTIONAL, INTENT(in) :: l_mask ! use the routine for night mask computation
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pqsrin    ! input daily QSR flux 
       !!
       INTEGER  ::   ji, jj                                       ! dummy loop indices
+      INTEGER, DIMENSION(jpi,jpj) :: imask_night ! night mask
       REAL(wp) ::   ztwopi, zinvtwopi, zconvrad 
       REAL(wp) ::   zlo, zup, zlousd, zupusd
       REAL(wp) ::   zdsws, zdecrad, ztx, zsin, zcos
       REAL(wp) ::   ztmp, ztmp1, ztmp2, ztest
+      REAL(wp) ::   ztmpm, ztmpm1, ztmpm2
       REAL(wp), DIMENSION(jpi,jpj) ::   zqsrout                  ! output QSR flux with diurnal cycle
       !---------------------------statement functions------------------------
@@ -90,5 +93,5 @@
       zup = zlo + ( REAL(nn_fsbc, wp)     * rdttra(1) ) / rday
       !                                          
-      IF( nday_qsr == -1 ) THEN       ! first time step only               
+      IF( nday_qsr == -1 ) THEN       ! first time step only  
          IF(lwp) THEN
             WRITE(numout,*)
@@ -120,5 +123,5 @@
          zdecrad = (-23.5 * zconvrad) * COS( zdsws * ztwopi / REAL(nyear_len(1),wp) )
          ! Compute A and B needed to compute the time integral of the diurnal cycle
-        
+
          zsin = SIN( zdecrad )   ;   zcos = COS( zdecrad )
          DO jj = 1, jpj
@@ -129,5 +132,4 @@
             END DO  
          END DO  
-
          ! Compute the time of dawn and dusk
 
@@ -156,5 +158,4 @@
          rdawn(:,:) = MOD( (rdawn(:,:) + 1._wp), 1._wp )
          rdusk(:,:) = MOD( (rdusk(:,:) + 1._wp), 1._wp )
-
          !     2.2 Compute the scalling function:
          !         S* = the inverse of the time integral of the diurnal cycle from dawm to dusk
@@ -185,10 +186,11 @@
          !
       ENDIF 
-
          !     3. update qsr with the diurnal cycle
          !     ------------------------------------
 
+      imask_night(:,:) = 0
       DO jj = 1, jpj
          DO ji = 1, jpi
+            ztmpm = 0.0
             IF( ABS(rab(ji,jj)) < 1 ) THEN         ! day duration is less than 24h
                !
@@ -200,4 +202,6 @@
                   ztmp = fintegral(zlousd, zupusd, raa(ji,jj), rbb(ji,jj), rcc(ji,jj)) 
                   zqsrout(ji,jj) = pqsrin(ji,jj) * ztmp * rscal(ji,jj)
+                  ztmpm = zupusd - zlousd
+                  IF ( ztmpm .EQ. 0 ) imask_night(ji,jj) = 1
                   !
                ELSE                                         ! day time in two parts
@@ -205,9 +209,13 @@
                   zupusd = MIN(zup, rdusk(ji,jj))
                   ztmp1 = fintegral(zlousd, zupusd, raa(ji,jj), rbb(ji,jj), rcc(ji,jj)) 
+                  ztmpm1=zupusd-zlousd
                   zlousd = MAX(zlo, rdawn(ji,jj))
                   zupusd = MAX(zup, rdawn(ji,jj))
                   ztmp2 = fintegral(zlousd, zupusd, raa(ji,jj), rbb(ji,jj), rcc(ji,jj)) 
+                  ztmpm2 =zupusd-zlousd
                   ztmp = ztmp1 + ztmp2
+                  ztmpm = ztmpm1 + ztmpm2
                   zqsrout(ji,jj) = pqsrin(ji,jj) * ztmp * rscal(ji,jj)
+                  IF (ztmpm .EQ. 0.) imask_night(ji,jj) = 1
                ENDIF
             ELSE                                   ! 24h light or 24h night
@@ -216,11 +224,17 @@
                   ztmp = fintegral(zlo, zup, raa(ji,jj), rbb(ji,jj), rcc(ji,jj)) 
                   zqsrout(ji,jj) = pqsrin(ji,jj) * ztmp * rscal(ji,jj)
+                  imask_night(ji,jj) = 0
                   !
                ELSE                                         ! No day
                   zqsrout(ji,jj) = 0.e0
+                  imask_night(ji,jj) = 1
                ENDIF
             ENDIF
          END DO  
       END DO  
+      !
+      IF ( PRESENT(l_mask) .AND. l_mask ) THEN
+         zqsrout(:,:) = float(imask_night(:,:))
+      ENDIF
       !
       IF( nn_timing == 1 )  CALL timing_stop('sbc_dcy')
