Index: /branches/ORCHIDEE_2_2/ORCHIDEE/src_driver/forcing_tools.f90
===================================================================
--- /branches/ORCHIDEE_2_2/ORCHIDEE/src_driver/forcing_tools.f90	(revision 7257)
+++ /branches/ORCHIDEE_2_2/ORCHIDEE/src_driver/forcing_tools.f90	(revision 7258)
@@ -154,5 +154,5 @@
   REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:)      :: time_precip
   REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:,:)    :: timebnd_precip
-  REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:)      :: preciptime_slab             !! Variable needed to keep track of how much rainfall was already distributed
+  REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:,:)    :: preciptime_slab             !! Variable needed to keep track of how much rainfall was already distributed
   !
   REAL(r_std), SAVE, ALLOCATABLE, DIMENSION(:,:)    :: swdown_slab, lwdown_slab
@@ -925,8 +925,11 @@
     LOGICAL, SAVE :: first_call_spreadprec=.TRUE.
     REAL(r_std), SAVE :: time_to_spread=3600.0
+    LOGICAL, SAVE :: spreadprec_cont=.FALSE. 
+    !
     INTEGER(i_std) :: imin(1), i, tind(3)
     REAL(r_std) :: ft(3), dt, left, right
     INTEGER(i_std) :: offset, nb_spread
     LOGICAL, ALLOCATABLE, DIMENSION(:) :: mask
+    REAL(r_std), ALLOCATABLE, DIMENSION(:) :: tspread
     !
     !
@@ -934,4 +937,8 @@
        ALLOCATE(mask(slab_size_max))
        mask(:) = .FALSE.
+    ENDIF
+    IF ( .NOT. ALLOCATED(tspread) ) THEN 
+       ALLOCATE(tspread(nbpoint_proc)) 
+       tspread(:) = time_to_spread
     ENDIF
     !
@@ -953,5 +960,5 @@
        !
        IF ( nb_spread < 0 ) THEN
-          !Config Key   = SPRED_PREC_SEC
+          !Config Key   = SPREAD_PREC_SEC
           !Config Desc  = Spread the precipitation over an interval in seconds.
           !Config Def   = 3600
@@ -967,7 +974,30 @@
           !
           CALL getin_p('SPRED_PREC_SEC', time_to_spread)
+          IF ( time_to_spread == forcing_tstep_ave/2.0 ) THEN
+             ! If we still have the default value, check if the
+             ! keyword does not exist with the right spelling.
+             CALL getin_p('SPREAD_PREC_SEC', time_to_spread)
+          ENDIF
        ELSE
           time_to_spread = dt_sechiba_keep * nb_spread
        ENDIF
+       !
+       ! Add the option to introduce a continuous distribution of precipitation
+       !
+       !Config Key   = SPREAD_PREC_CONT
+       !Config Desc  = Take into account precipitation on the next forcing step for spreading it.
+       !Config Def   = FALSE
+       !Config Help  = This allows to extend the spreading of rainfall to the entire forcing
+       !Config         should it be raining on the following time step. This ensures that if it rains
+       !Config         in two consecutive forcing time step at least during the first period rainfall
+       !Config         will be continuous. This avoids the spiky nature of rainfall in periods of
+       !Config         prolonged rainfall.
+       !Config Units = -
+       !
+       ! This is the default should 'SPREAD_PREC_CONT' not be present in the run.def
+       !
+       spreadprec_cont = .FALSE.
+       !
+       CALL getin_p('SPREAD_PREC_CONT', spreadprec_cont)
        !
        ! Do some verifications on the information read from run.def
@@ -1006,56 +1036,71 @@
        ENDIF
        !
-       !
-       !
-       ! Do we need to take some rain from the previous time step ?
-       !
-       !! Time computation is not better than 1/1000 seconds
-       IF ( time_int(1) < timebnd_central(tind(2),1) .AND. preciptime_slab(tind(1)) < (time_to_spread-0.001) ) THEN
-          dt = ((timebnd_central(tind(2),1)-offset)-(time_int(1)-offset))*one_day
-          ft(1) = MIN(time_to_spread - preciptime_slab(tind(1)), dt)/tlen
-       ELSE
-          ft(1) = zero
-       ENDIF
-       !
-       ! Is there still some rain to spread from the current forcing time step ?
-       !
-       !! Time computation is not better than 1/1000 seconds
-       IF (preciptime_slab(tind(2)) < (time_to_spread-0.001) ) THEN
-          left = MAX(time_int(1), timebnd_central(tind(2),1))
-          right = MIN(time_int(2),timebnd_central(tind(2),2))
-          dt = ((right-offset)-(left-offset))*one_day
-          ft(2) = MIN(time_to_spread - preciptime_slab(tind(2)), dt)/tlen
-       ELSE
-          ft(2) = zero
-       ENDIF
-       !
-       ! Do we need to take some rain from the next time step ?
-       !
-       !! Time computation is not better than 1/1000 seconds
-       IF ( time_int(2) > timebnd_central(tind(2),2) .AND. preciptime_slab(tind(3)) < (time_to_spread-0.001) ) THEN
-          dt = ((time_int(2)-offset)-(timebnd_central(tind(2),2)-offset))*one_day
-          ft(3) = MIN(time_to_spread - preciptime_slab(tind(3)), dt)/tlen
-       ELSE
-          ft(3) = zero
-       ENDIF
-       !
-       ! Do the actual calculation
+       tspread(:) = time_to_spread
        !
        DO i=1, nbpoint_proc
+          !
+          IF ( spreadprec_cont ) THEN
+             !
+             ! If the next time step has also rainfall, then time_to_spread becomes the length of the forcing time step.
+             !
+             IF ( rainf_slab(i,tind(3)) > zero .OR. snowf_slab(i,tind(3)) > zero) THEN
+                tspread(i) = forcing_tstep_ave
+             ELSE
+                tspread(i) = time_to_spread
+             ENDIF
+          ELSE
+             ! Default behavious
+             tspread(i) = time_to_spread
+          ENDIF
+          !
+          ! Do we need to take some rain from the previous time step ?
+          !
+          !! Time computation is not better than 1/1000 seconds
+          IF ( time_int(1) < timebnd_central(tind(2),1) .AND. preciptime_slab(i,tind(1)) < (tspread(i)-0.001) ) THEN
+             dt = ((timebnd_central(tind(2),1)-offset)-(time_int(1)-offset))*one_day
+             ft(1) = MIN(tspread(i) - preciptime_slab(i,tind(1)), dt)/tlen
+          ELSE
+             ft(1) = zero
+          ENDIF
+          !
+          ! Is there still some rain to spread from the current forcing time step ?
+          !
+          !! Time computation is not better than 1/1000 seconds
+          IF (preciptime_slab(i,tind(2)) < (tspread(i)-0.001) ) THEN
+             left = MAX(time_int(1), timebnd_central(tind(2),1))
+             right = MIN(time_int(2),timebnd_central(tind(2),2))
+             dt = ((right-offset)-(left-offset))*one_day
+             ft(2) = MIN(tspread(i) - preciptime_slab(i,tind(2)), dt)/tlen
+          ELSE
+             ft(2) = zero
+          ENDIF
+          !
+          ! Do we need to take some rain from the next time step ?
+          !
+          !! Time computation is not better than 1/1000 seconds
+          IF ( time_int(2) > timebnd_central(tind(2),2) .AND. preciptime_slab(i,tind(3)) < (tspread(i)-0.001) ) THEN
+             dt = ((time_int(2)-offset)-(timebnd_central(tind(2),2)-offset))*one_day
+             ft(3) = MIN(tspread(i) - preciptime_slab(i,tind(3)), dt)/tlen
+          ELSE
+             ft(3) = zero
+          ENDIF
+          !
+          ! Do the actual calculation
+          !
           rainf(i) = (rainf_slab(i,tind(1)) * forcing_tstep_ave * ft(1) + &
-                  &  rainf_slab(i,tind(2)) * forcing_tstep_ave * ft(2) + &
-                  &  rainf_slab(i,tind(3)) * forcing_tstep_ave * ft(3))*tlen/time_to_spread
-  
+               &  rainf_slab(i,tind(2)) * forcing_tstep_ave * ft(2) + &
+               &  rainf_slab(i,tind(3)) * forcing_tstep_ave * ft(3))*tlen/tspread(i)
+
           snowf(i) = (snowf_slab(i,tind(1)) * forcing_tstep_ave * ft(1) + &
-                  &  snowf_slab(i,tind(2)) * forcing_tstep_ave * ft(2) + &
-                  &  snowf_slab(i,tind(3)) * forcing_tstep_ave * ft(3))*tlen/time_to_spread
+               &  snowf_slab(i,tind(2)) * forcing_tstep_ave * ft(2) + &
+               &  snowf_slab(i,tind(3)) * forcing_tstep_ave * ft(3))*tlen/tspread(i)
+          !
+          ! Update the time over which we have already spread the rainf
+          !
+          preciptime_slab(i,tind(1)) = preciptime_slab(i,tind(1)) + tlen * ft(1)
+          preciptime_slab(i,tind(2)) = preciptime_slab(i,tind(2)) + tlen * ft(2)
+          preciptime_slab(i,tind(3)) = preciptime_slab(i,tind(3)) + tlen * ft(3)
+          !
        ENDDO
-       !
-       ! Update the time over which we have already spread the rainf
-       !
-       preciptime_slab(tind(1)) = preciptime_slab(tind(1)) + tlen * ft(1)
-       preciptime_slab(tind(2)) = preciptime_slab(tind(2)) + tlen * ft(2)
-       preciptime_slab(tind(3)) = preciptime_slab(tind(3)) + tlen * ft(3)
-       !
     ELSE
        WRITE(numout,*) "Time interval toward which we will interpolate : ", time_int
@@ -1295,4 +1340,5 @@
     REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: u_full, v_full
     REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: ps_full, ztq_full, zuv_full
+    REAL(r_std), ALLOCATABLE, DIMENSION(:)      :: preciptime_tmp
     !
     ! 1.0 Verify that for the slabs the memory is allocated for the variable
@@ -1315,5 +1361,6 @@
     IF ( .NOT. ALLOCATED(time_precip) ) ALLOCATE(time_precip(slab_size))
     IF ( .NOT. ALLOCATED(timebnd_precip) ) ALLOCATE(timebnd_precip(slab_size,2))
-    IF ( .NOT. ALLOCATED(preciptime_slab) ) ALLOCATE(preciptime_slab(slab_size))
+    IF ( .NOT. ALLOCATED(preciptime_slab) ) ALLOCATE(preciptime_slab(nbpoint_proc,slab_size)) 
+    IF ( .NOT. ALLOCATED(preciptime_tmp) ) ALLOCATE(preciptime_tmp(slab_size))
     !
     IF ( .NOT. ALLOCATED(swdown_slab) ) ALLOCATE(swdown_slab(nbpoint_proc,slab_size))
@@ -1364,5 +1411,5 @@
             &                     tair_full, tairmax_full, tairmin_full, time_tair, timebnd_tair, &
             &                     qair_full, time_qair, timebnd_qair, &
-            &                     rainf_full, snowf_full, time_precip, timebnd_precip, preciptime_slab, &
+            &                     rainf_full, snowf_full, time_precip, timebnd_precip, preciptime_tmp, &
             &                     swdown_full, time_swdown, timebnd_swdown, &
             &                     lwdown_full, time_lwdown, timebnd_lwdown, &
@@ -1401,5 +1448,5 @@
     CALL bcast(time_precip)
     CALL bcast(timebnd_precip)
-    CALL bcast(preciptime_slab)
+    CALL bcast(preciptime_tmp)
     CALL bcast(time_swdown)
     CALL bcast(timebnd_swdown)
@@ -1448,4 +1495,10 @@
        zuv_slab(:,:) = zuv_full(:,:)
     ENDIF
+    !
+    !
+    !
+    DO is=1,nbpoint_proc
+       preciptime_slab(is,:) = preciptime_tmp(:)
+    ENDDO
     !
     ! Clean-up to free the memory on the root processor.
@@ -3861,17 +3914,17 @@
         ! First extral the information from the date string
         !
-        READ(ymd(1:INDEX(ymd,'-')-1),'(I4)') year0
+        READ(ymd(1:INDEX(ymd,'-')-1),'(I)') year0
         ymd=TRIM(ymd(INDEX(ymd,'-')+1:LEN_TRIM(ymd)))
-        READ(ymd(1:INDEX(ymd,'-')-1),'(I2)') month0
+        READ(ymd(1:INDEX(ymd,'-')-1),'(I)') month0
         ymd=TRIM(ymd(INDEX(ymd,'-')+1:LEN_TRIM(ymd)))
-        READ(ymd,'(I2)') day0
+        READ(ymd,'(I)') day0
         !
         ! Now extract from the time string
         !
-        READ(hms(1:INDEX(hms,':')-1),'(I2)') hours0
+        READ(hms(1:INDEX(hms,':')-1),'(I)') hours0
         hms=TRIM(hms(INDEX(hms,':')+1:LEN_TRIM(hms)))
-        READ(hms(1:INDEX(hms,':')-1),'(I2)') minutes0
+        READ(hms(1:INDEX(hms,':')-1),'(I)') minutes0
         hms=TRIM(hms(INDEX(hms,':')+1:LEN_TRIM(hms)))
-        READ(hms,'(I2)') seci
+        READ(hms,'(I)') seci
         !
         sec0 = hours0*3600. + minutes0*60. + seci
Index: /branches/ORCHIDEE_2_2/ORCHIDEE/src_global/interpol_help.f90
===================================================================
--- /branches/ORCHIDEE_2_2/ORCHIDEE/src_global/interpol_help.f90	(revision 7257)
+++ /branches/ORCHIDEE_2_2/ORCHIDEE/src_global/interpol_help.f90	(revision 7258)
@@ -73,5 +73,5 @@
     REAL(r_std), ALLOCATABLE, DIMENSION(:,:) :: loup_rel, lolow_rel, laup_rel, lalow_rel
     INTEGER(i_std), ALLOCATABLE, DIMENSION(:,:) :: searchind
-    REAL(r_std) :: lon_up, lon_low, lat_up, lat_low
+    REAL(r_std) :: lon_up, lon_low, lat_up, lat_low, lat_resol, lon_resol
     REAL(r_std) :: coslat, ax, ay, sgn, lonrel, lolowrel, louprel
     INTEGER(i_std) :: fopt, fopt_max, ip, jp, ib, i, itmp, iprog, nbind
@@ -132,8 +132,7 @@
     ENDIF
     !
-    sgn = lat_rel(1,1)/ABS(lat_rel(1,1))
-    lat_ful(2:iml+1,1) = sgn*180 - lat_rel(1:iml,1)
-    sgn = lat_rel(1,jml)/ABS(lat_rel(1,jml))
-    lat_ful(2:iml+1,jml+2) = sgn*180 - lat_rel(1:iml,jml)
+    lat_resol = lat_rel(1,2) - lat_rel(1,1)
+    lat_ful(2:iml+1,1) = lat_rel(1,1) - lat_resol
+    lat_ful(2:iml+1,jml+2) = lat_rel(1,jml) + lat_resol
     lat_ful(1,1) = lat_ful(iml+1,1)
     lat_ful(iml+2,1) = lat_ful(2,1)
@@ -143,6 +142,9 @@
     ! Add the longitude lines to the top and bottom
     !
+    lon_resol = lon_ful(3,2) - lon_ful(2,2)
     lon_ful(:,1) = lon_ful(:,2) 
     lon_ful(:,jml+2) = lon_ful(:,jml+1) 
+    lon_ful(1,:) = lon_ful(2,1) - lon_resol
+    lon_ful(iml+2,:) = lon_ful(iml+1,1) + lon_resol
     !
     !  Get the upper and lower limits of each grid box
