Index: /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcblk_core.F90
===================================================================
--- /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 2186)
+++ /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 2187)
@@ -26,4 +26,5 @@
    USE fldread         ! read input fields
    USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE sbcdcy          ! surface forcing: diurnal cycle
    USE iom             ! I/O manager library
    USE in_out_manager  ! I/O manager
@@ -147,4 +148,13 @@
          READ  ( numnam, namsbc_core )
          !
+         ! do we plan to use ln_dm2dc with non-daily forcing?
+         IF( ln_dm2dc .AND. sn_qsr%nfreqh /= 24 )   &
+            &   CALL ctl_stop( 'sbc_blk_core: ln_dm2dc can be activated only with daily short-wave forcing' ) 
+         IF( ln_dm2dc .AND. sn_qsr%ln_tint ) THEN
+            CALL ctl_warn( 'sbc_blk_core: ln_dm2dc is taking care of the temporal interpolation of daily qsr',   &
+                 &         '              ==> We force time interpolation = .false. for qsr' )
+            sn_qsr%ln_tint = .false.
+         ENDIF
+         !
          ! store namelist information in an array
          slf_i(jp_wndi) = sn_wndi   ;   slf_i(jp_wndj) = sn_wndj
@@ -169,9 +179,11 @@
          !
          ! fill sf with slf_i and control print
-         CALL fld_fill( sf, slf_i, cn_dir, 'sbc_blk_core', 'flux formulattion for ocean surface boundary condition', 'namsbc_core' )
+         CALL fld_fill( sf, slf_i, cn_dir, 'sbc_blk_core', 'flux formulation for ocean surface boundary condition', 'namsbc_core' )
          !
       ENDIF
 
       CALL fld_read( kt, nn_fsbc, sf )                   ! input fields provided at the current time-step
+
+      IF( ln_dm2dc )   CALL sbc_dcy( kt , sf(jp_qsr)%fnow )   ! modify sf(jp_qsr)%fnow for diurnal cycle
 
 #if defined key_lim3
Index: /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcdcy.F90
===================================================================
--- /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcdcy.F90	(revision 2187)
+++ /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcdcy.F90	(revision 2187)
@@ -0,0 +1,226 @@
+MODULE sbcdcy
+   !!======================================================================
+   !!                    ***  MODULE  sbcdcy  ***
+   !! Ocean forcing:  compute the diurnal cycle
+   !!======================================================================
+   !! History : 8.2  !  2005-02  (D. Bernie)  Original code
+   !!           9.0  !  2006-02  (S. Masson, G. Madec)  adaptation to OPA9
+   !!           3.1  !  2009-07  (J.M. Molines)  adaptation to nemo3.1
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!  sbc_dcy : compute solar flux at kt from daily mean, taking 
+   !!            diurnal cycle into account
+   !!----------------------------------------------------------------------
+   USE oce              ! ocean dynamics and tracers
+   USE phycst           ! ocean physics
+   USE dom_oce          ! ocean space and time domain
+   USE in_out_manager   ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+   INTEGER                      ::   idayqsr                                            ! day when parameters were computed
+   REAL(wp), DIMENSION(jpi,jpj) ::   zaaa, zbbb, zccc, zab, ztmd, zdawn, zdusk, zscal   ! parameters to compute the diurnal cycle
+   REAL(wp), DIMENSION(jpi,jpj) ::   qsr_daily                                          ! to hold daily mean QSR
+  
+   PUBLIC sbc_dcy       ! routine called by sbc
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , LOCEAN-IPSL (2010) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+      SUBROUTINE sbc_dcy( kt, pqsr )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_dcy  ***
+      !!
+      !! ** Purpose : introduce a diurnal cycle of qsr from daily values
+      !!
+      !! ** Method  : see Appendix A of 
+      !!              Bernie, DJ, Guilyardi, E, Madec, G, Slingo, JM and Woolnough, SJ
+      !!              Impact of resolving the diurnal cycle in an ocean--atmosphere GCM. Part 1: a diurnally forced OGCM
+      !!              Climate Dynamics 29:6, 575-590 (2007)
+      !!
+      !! ** Action  : redistribute daily QSR on each time step following the diurnal cycle
+      !!----------------------------------------------------------------------
+      INTEGER,                      INTENT( in    ) ::   kt     ! ocean time-step index
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   pqsr   ! QSR flux with diurnal cycle
+      !!
+      INTEGER  ::   ji, jj                                      ! dummy loop indices
+      REAL(wp) ::   fintegral, pt1, pt2, paaa, pbbb, pccc       ! 
+      REAL(wp) ::   ztwopi, zinvtwopi, zconvrad 
+      REAL(wp) ::   zlo, zup, zlousd, zupusd
+      REAL(wp) ::   zdsws, zdecrad, ztx
+      REAL(wp) ::   ztmp, ztmp1, ztmp2, ztest
+      !!---------------------------------------------------------------------
+
+      !----------------------------------------------------------------------
+      ! statement functions
+
+      fintegral(pt1, pt2, paaa, pbbb, pccc) =                           &
+         &   paaa * pt2 + zinvtwopi * pbbb * SIN(pccc + ztwopi * pt2)   &
+         & - paaa * pt1 - zinvtwopi * pbbb * SIN(pccc + ztwopi * pt1)
+      !----------------------------------------------------------------------
+
+      ! Initialization
+      ! --------------
+      ztwopi    = 2. * rpi
+      zinvtwopi = 1. / ztwopi
+      zconvrad  = ztwopi / 360.
+
+      ! When are we during the day (from 0 to 1)
+      zlo = MOD( rdt / rday * REAL( kt-nit000, wp ), 1.)
+      zup = zlo + rdt / rday
+
+      !                                          
+      IF (kt == nit000) THEN                    
+         !
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'sbc_dcy : introduce diurnal cycle from daily mean qsr'
+            WRITE(numout,*) '~~~~~~~'
+            WRITE(numout,*)
+         ENDIF
+         idayqsr = 0
+         ! Compute C needed to compute the time integral of the diurnal cycle
+         zccc(:,:) = zconvrad * glamt(:,:) - rpi
+         ! time of midday
+         ztmd(:,:) = 0.5 - glamt(:,:) / 360.
+         ztmd(:,:) = MOD((ztmd(:,:) + 1.), 1.)
+      ENDIF
+
+      ! If this is a new day, we have to update the dawn, dusk and scaling function  
+      !----------------------
+    
+      !     2.1 dawn and dusk  
+
+      ! nday is the number of days since the beginning of the current month 
+      IF( idayqsr /= nday ) THEN 
+         ! save the day of the year and the daily mean of qsr
+         idayqsr = nday 
+         ! number of days since the previous winter solstice (supposed to be always 21 December)         
+         zdsws = 11 + nday_year
+         ! declination of the earths orbit
+         zdecrad = (-23.5 * zconvrad) * COS( zdsws * ztwopi / REAL(nyear_len(1),wp) )
+         ! save the daily QSR for nest hours of the day
+         qsr_daily(:,:) = pqsr(:,:)
+         ! Compute A and B needed to compute the time integral of the diurnal cycle
+        
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ztmp = zconvrad * gphit(ji,jj)
+               zaaa(ji,jj) = SIN(ztmp) * SIN(zdecrad)
+               zbbb(ji,jj) = COS(ztmp) * COS(zdecrad)
+            END DO  
+         END DO  
+
+         ! Compute the time of dawn and dusk
+
+         ! zab to test if the day time is equal to 0, less than 24h of full day        
+         zab(:,:) = -zaaa(:,:) / zbbb(:,:)
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( ABS(zab(ji,jj)) < 1 ) THEN
+         ! day duration is less than 24h
+         ! When is it night?
+                  ztx = zinvtwopi * (ACOS(zab(ji,jj)) - zccc(ji,jj))
+                  ztest = -zbbb(ji,jj) * SIN( zccc(ji,jj) + ztwopi * ztx )
+         ! is it dawn or dusk?
+                  IF ( ztest > 0 ) THEN
+                     zdawn(ji,jj) = ztx
+                     zdusk(ji,jj) = ztmd(ji,jj) + ( ztmd(ji,jj) - zdawn(ji,jj) )
+                  ELSE
+                     zdusk(ji,jj) = ztx
+                     zdawn(ji,jj) = ztmd(ji,jj) - ( zdusk(ji,jj) - ztmd(ji,jj) )
+                  ENDIF
+               ELSE
+                  zdawn(ji,jj) = ztmd(ji,jj) + 0.5
+                  zdusk(ji,jj) = zdawn(ji,jj)
+               ENDIF
+             END DO  
+         END DO  
+         zdawn(:,:) = MOD((zdawn(:,:) + 1.), 1.)
+         zdusk(:,:) = MOD((zdusk(:,:) + 1.), 1.)
+
+
+         !     2.2 Compute the scalling function:
+         !         S* = the inverse of the time integral of the diurnal cycle from dawm to dusk
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( ABS(zab(ji,jj)) < 1 ) THEN
+         ! day duration is less than 24h
+                  IF ( zdawn(ji,jj) < zdusk(ji,jj) ) THEN
+         ! day time in one part
+                     zscal(ji,jj) = fintegral(zdawn(ji,jj), zdusk(ji,jj), zaaa(ji,jj), zbbb(ji,jj), zccc(ji,jj)) 
+                     zscal(ji,jj) = 1. / zscal(ji,jj)
+                  ELSE
+         ! day time in two parts
+                     zscal(ji,jj) = fintegral(0., zdusk(ji,jj), zaaa(ji,jj), zbbb(ji,jj), zccc(ji,jj))   &
+                        &         + fintegral(zdawn(ji,jj), 1., zaaa(ji,jj), zbbb(ji,jj), zccc(ji,jj)) 
+                     zscal(ji,jj) = 1. / zscal(ji,jj)
+                  ENDIF
+               ELSE
+                  IF ( zaaa(ji,jj) > zbbb(ji,jj) ) THEN
+         ! 24h day
+                     zscal(ji,jj) = fintegral(0., 1., zaaa(ji,jj), zbbb(ji,jj), zccc(ji,jj)) 
+                     zscal(ji,jj) = 1. / zscal(ji,jj)
+                  ELSE
+         ! No day
+                     zscal(ji,jj) = 0.
+                  ENDIF
+               ENDIF
+            END DO  
+         END DO  
+         !
+         ztmp = rday / rdt
+         zscal(:,:) = zscal(:,:) * ztmp
+
+      ENDIF 
+
+         !     3. compute qsr with the diurnal cycle
+         !     -----------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF ( ABS(zab(ji,jj)) < 1 ) THEN
+         ! day duration is less than 24h
+                  IF ( zdawn(ji,jj) < zdusk(ji,jj) ) THEN
+         ! day time in one part
+                     zlousd = MAX(zlo, zdawn(ji,jj))
+                     zlousd = MIN(zlousd, zup)
+                     zupusd = MIN(zup, zdusk(ji,jj))
+                     zupusd = MAX(zupusd, zlo)
+                     ztmp = fintegral(zlousd, zupusd, zaaa(ji,jj), zbbb(ji,jj), zccc(ji,jj)) 
+                     pqsr(ji,jj) = qsr_daily(ji,jj) * ztmp * zscal(ji,jj)
+                  ELSE
+         ! day time in two parts
+                     zlousd = MIN(zlo, zdusk(ji,jj))
+                     zupusd = MIN(zup, zdusk(ji,jj))
+                     ztmp1 = fintegral(zlousd, zupusd, zaaa(ji,jj), zbbb(ji,jj), zccc(ji,jj)) 
+                     zlousd = MAX(zlo, zdawn(ji,jj))
+                     zupusd = MAX(zup, zdawn(ji,jj))
+                     ztmp2 = fintegral(zlousd, zupusd, zaaa(ji,jj), zbbb(ji,jj), zccc(ji,jj)) 
+                     ztmp = ztmp1 + ztmp2
+                     pqsr(ji,jj) = qsr_daily(ji,jj) * ztmp * zscal(ji,jj)
+                  ENDIF
+            ELSE
+                  IF ( zaaa(ji,jj) > zbbb(ji,jj) ) THEN
+         ! 24h day
+                     ztmp = fintegral(zlo, zup, zaaa(ji,jj), zbbb(ji,jj), zccc(ji,jj)) 
+                     pqsr(ji,jj) = qsr_daily(ji,jj) * ztmp * zscal(ji,jj)
+                  ELSE
+         ! No day
+                     pqsr(ji,jj) = 0.
+                  ENDIF
+            ENDIF
+         END DO  
+      END DO  
+
+   END SUBROUTINE sbc_dcy
+
+   !!======================================================================
+END MODULE sbcdcy
Index: /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcflx.F90
===================================================================
--- /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcflx.F90	(revision 2186)
+++ /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcflx.F90	(revision 2187)
@@ -29,4 +29,5 @@
    USE sbc_oce         ! Surface boundary condition: ocean fields
    USE phycst          ! physical constants
+   USE sbcdcy          ! diurnal cycle on qsr
    USE fldread         ! read input fields
    USE iom             ! IOM library
@@ -115,4 +116,8 @@
          READ   ( numnam, namsbc_flx ) 
 
+         ! do we plan to use ln_dm2dc with non-daily forcing?
+         IF( ln_dm2dc .AND. sn_qsr%nfreqh /= 24 )   &
+            &   CALL ctl_stop( 'sbc_blk_core: ln_dm2dc can be activated only with daily short-wave forcing' ) 
+
          ! store namelist information in an array
          slf_i(jp_utau) = sn_utau   ;   slf_i(jp_vtau) = sn_vtau
@@ -138,4 +143,5 @@
       CALL fld_read( kt, nn_fsbc, sf )           ! Read input fields and provides the
       !                                          ! input fields at the current time-step
+      IF( ln_dm2dc )   CALL sbc_dcy( kt , sf(jp_qsr)%fnow )   ! modify sf(jp_qsr)%fnow for diurnal cycle
 
       IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN
Index: /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 2186)
+++ /branches/dev_r2174_DCY/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 2187)
@@ -137,4 +137,10 @@
       IF( nn_ice == 2 .AND. .NOT.( ln_blk_clio .OR. ln_blk_core .OR. lk_cpl ) )   &
          &   CALL ctl_stop( 'sea-ice model requires a bulk formulation or coupled configuration' )
+      
+      IF( ln_dm2dc .AND. .NOT.( ln_flx .OR. ln_blk_core ) )   &
+         &   CALL ctl_stop( 'diurnal cycle into qsr field from daily values requires a flux or core-bulk formulation' )
+      
+      IF( ln_dm2dc .AND. ( ( NINT(rday) / ( nn_fsbc * NINT(rdt) ) )  < 8 ) )   &
+         &   CALL ctl_warn( 'diurnal cycle for qsr: the sampling of the diurnal cycle is too small...' )
       
       ! Choice of the Surface Boudary Condition (set nsbc)
@@ -216,6 +222,4 @@
       ! Misc. Options
       ! -------------
-
-!!gm  IF( ln_dm2dc       )   CALL sbc_dcy( kt )                 ! Daily mean qsr distributed over the Diurnal Cycle
       
       SELECT CASE( nn_ice )                                     ! Update heat and freshwater fluxes over sea-ice areas
@@ -239,7 +243,7 @@
          CALL iom_put( "emp"    , emp       )                   ! upward water flux
          CALL iom_put( "emps"   , emps      )                   ! c/d water flux
-         CALL iom_put( "qns+qsr", qns + qsr )                   ! total heat flux   (caution if ln_dm2dc=true, to be 
-         CALL iom_put( "qns"    , qns       )                   ! solar heat flux    moved after the call to iom_setkt)
-         CALL iom_put( "qsr"    ,       qsr )                   ! solar heat flux    moved after the call to iom_setkt)
+         CALL iom_put( "qns+qsr", qns + qsr )                   ! total heat flux
+         CALL iom_put( "qns"    , qns       )                   ! solar heat flux
+         CALL iom_put( "qsr"    ,       qsr )                   ! solar heat flux
          IF(  nn_ice > 0 )   CALL iom_put( "ice_cover", fr_i )  ! ice fraction 
       ENDIF
