Index: branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/hydrolc.f90
===================================================================
--- branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/hydrolc.f90	(revision 134)
+++ branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/hydrolc.f90	(revision 257)
@@ -3,7 +3,10 @@
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
-!! @Version : $Revision: 1.21 $, $Date: 2010/05/07 08:28:13 $
+!! @Version : $Revision: 45 $, $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
 !! 
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/hydrolc.f90,v 1.21 2010/05/07 08:28:13 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/hydrolc.f90 $
+!< $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 45 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
@@ -145,15 +148,16 @@
     !! We consider that any water on the ice is snow and we only peforme a water balance to have consistency.
     !! The water balance is limite to + or - 10^6 so that accumulation is not endless
+    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (inout) :: humrel        !! Relative humidity
+    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (inout) :: vegstress     !! Veg. moisture stress (only for vegetation growth)
+    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (inout) :: qsintveg      !! Water on vegetation due to interception
     ! output fields
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: run_off_tot   !! Complete runoff
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: drainage      !! Drainage
-    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: humrel        !! Relative humidity
-    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: vegstress     !! Veg. moisture stress (only for vegetation growth)
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)     :: run_off_tot   !! Complete runoff
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)     :: drainage      !! Drainage
+    REAL(r_std),DIMENSION (kjpindex,nbdl), INTENT (inout):: shumdiag      !! relative soil moisture
+
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: rsol          !! Resistence to bare soil evaporation
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: drysoil_frac  !! Fraction of visibly dry soil (between 0 and 1)
-    REAL(r_std),DIMENSION (kjpindex,nbdl), INTENT (out):: shumdiag      !! relative soil moisture
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: litterhumdiag !! litter humidity
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: tot_melt      !! Total melt    
-    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: qsintveg      !! Water on vegetation due to interception
 
     !
@@ -293,5 +297,4 @@
        CALL hydrolc_alma(kjpindex, index, .FALSE., qsintveg, snow, snow_nobio, soilwet)
     ENDIF
-
 
     !
@@ -313,5 +316,5 @@
           DO ji = 1, kjpindex
              IF ( vegtot(ji) .GT. zero ) THEN
-                histvar(ji)=histvar(ji)+veget(ji,jv)/vegtot(ji)*MAX((0.1-dss(ji,jv))*mx_eau_eau, 0.0)
+                histvar(ji)=histvar(ji)+veget(ji,jv)/vegtot(ji)*MAX((0.1-dss(ji,jv))*mx_eau_eau, zero)
              ENDIF
           ENDDO
@@ -322,11 +325,11 @@
        CALL histwrite(hist_id, 'mrso', kjit, histvar, kjpindex, index)
 
-       histvar(:)=run_off_tot(:)/86400.
+       histvar(:)=run_off_tot(:)/one_day
        CALL histwrite(hist_id, 'mrros', kjit, histvar, kjpindex, index)
 
-       histvar(:)=(run_off_tot(:)+drainage(:))/86400.
+       histvar(:)=(run_off_tot(:)+drainage(:))/one_day
        CALL histwrite(hist_id, 'mrro', kjit, histvar, kjpindex, index)
 
-       histvar(:)=(precip_rain(:)-SUM(precisol(:,:),dim=2))/86400.
+       histvar(:)=(precip_rain(:)-SUM(precisol(:,:),dim=2))/one_day
        CALL histwrite(hist_id, 'prveg', kjit, histvar, kjpindex, index)
 
@@ -369,5 +372,5 @@
              DO ji = 1, kjpindex
                 IF ( vegtot(ji) .GT. zero ) THEN
-                   histvar(ji)=histvar(ji)+veget(ji,jv)/vegtot(ji)*MAX((0.1-dss(ji,jv))*mx_eau_eau, 0.0)
+                   histvar(ji)=histvar(ji)+veget(ji,jv)/vegtot(ji)*MAX((0.1-dss(ji,jv))*mx_eau_eau, zero)
                 ENDIF
              ENDDO
@@ -375,5 +378,5 @@
           CALL histwrite(hist2_id, 'mrsos', kjit, histvar, kjpindex, index)
 
-          histvar(:)=(run_off_tot(:)+drainage(:))/86400.
+          histvar(:)=(run_off_tot(:)+drainage(:))/one_day
           CALL histwrite(hist2_id, 'mrro', kjit, histvar, kjpindex, index)
 
@@ -772,5 +775,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (snow, val_exp, 'HYDROL_SNOW', 0.0_r_std)
+        CALL setvar_p (snow, val_exp, 'HYDROL_SNOW', zero)
         !
         !Config Key  = HYDROL_SNOWAGE
@@ -781,5 +784,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (snow_age, val_exp, 'HYDROL_SNOWAGE', 0.0_r_std)
+        CALL setvar_p (snow_age, val_exp, 'HYDROL_SNOWAGE', zero)
         !
         !Config Key  = HYDROL_SNOW_NOBIO
@@ -790,5 +793,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (snow_nobio, val_exp, 'HYDROL_SNOW_NOBIO', 0.0_r_std)
+        CALL setvar_p (snow_nobio, val_exp, 'HYDROL_SNOW_NOBIO', zero)
         !
         !Config Key  = HYDROL_SNOW_NOBIO_AGE
@@ -799,5 +802,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (snow_nobio_age, val_exp, 'HYDROL_SNOW_NOBIO_AGE', 0.0_r_std)
+        CALL setvar_p (snow_nobio_age, val_exp, 'HYDROL_SNOW_NOBIO_AGE', zero)
         !
         !Config Key  = HYDROL_HUMR
@@ -808,6 +811,6 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (humrel, val_exp,'HYDROL_HUMR', 1.0_r_std)
-        CALL setvar_p (vegstress, val_exp,'HYDROL_HUMR', 1.0_r_std)
+        CALL setvar_p (humrel, val_exp,'HYDROL_HUMR', un)
+        CALL setvar_p (vegstress, val_exp,'HYDROL_HUMR', un)
         !
         !Config Key  = HYDROL_BQSB
@@ -827,5 +830,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (gqsb, val_exp, 'HYDROL_GQSB', 0.0_r_std)
+        CALL setvar_p (gqsb, val_exp, 'HYDROL_GQSB', zero)
         !
         !Config Key  = HYDROL_DSG
@@ -836,5 +839,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (dsg, val_exp, 'HYDROL_DSG', 0.0_r_std)
+        CALL setvar_p (dsg, val_exp, 'HYDROL_DSG', zero)
 
         ! set inital value for dsp if needed
@@ -872,5 +875,5 @@
         !Config        the model is started without a restart file. 
         !
-        CALL setvar_p (qsintveg, val_exp, 'HYDROL_QSV', 0.0_r_std)
+        CALL setvar_p (qsintveg, val_exp, 'HYDROL_QSV', zero)
         !
         tmpdss = dsg - gqsb / mx_eau_eau
@@ -889,5 +892,5 @@
                     IF (.NOT. (dsg(ji,1).EQ. zero .OR. gqsb(ji,1).EQ.zero)) THEN
                        ! Ajouts Nathalie - Fred - le 28 Mars 2006
-                       a_subgrd(ji)=MIN(MAX(dsg(ji,1)-dss(ji,1),0.)/dsg_min,1.)
+                       a_subgrd(ji)=MIN(MAX(dsg(ji,1)-dss(ji,1),zero)/dsg_min,un)
                        !
                     ENDIF
@@ -906,5 +909,5 @@
                  IF (.NOT. (dsg(ji,1).EQ. zero .OR. gqsb(ji,1).EQ.zero)) THEN
                     ! Ajouts Nathalie - Fred - le 28 Mars 2006
-                    a_subgrd(ji)=MIN(MAX(dsg(ji,1)-dss(ji,1),0.)/dsg_min,1.)
+                    a_subgrd(ji)=MIN(MAX(dsg(ji,1)-dss(ji,1),zero)/dsg_min,un)
                     !
                  ENDIF
@@ -915,5 +918,5 @@
            ! Correction Nathalie - le 28 Mars 2006 - re-ecriture drysoil_frac/hdry - Fred Hourdin
            ! revu 22 novembre 2007
-           hdry(:) = a_subgrd(:)*dss(:,1) + (1.-a_subgrd(:))*dsp(:,1)
+           hdry(:) = a_subgrd(:)*dss(:,1) + (un-a_subgrd(:))*dsp(:,1)
         ENDIF
         !
@@ -1090,5 +1093,5 @@
 
     ! The fraction of soil which is visibly dry (dry when dss = 0.1 m)
-    drysoil_frac(:) = MIN(MAX(dss(:,1),0.)*10._r_std, un)
+    drysoil_frac(:) = MIN(MAX(dss(:,1),zero)*10._r_std, un)
     !
     ! Compute the resistance to bare soil evaporation
@@ -1102,6 +1105,6 @@
           ! du fond. En gros, rsol=hdry*rsol_cste pour hdry < 1m70
           !rsol(ji) = dss(ji,1) * rsol_cste
-          !rsol(ji) =  ( drysoil_frac(ji) + 1./(10.*(dpu_cste - drysoil_frac(ji))+1.e-10)**2 ) * rsol_cste
-          rsol(ji) =  ( hdry(ji) + 1./(10.*(dpu_cste - hdry(ji))+1.e-10)**2 ) * rsol_cste
+          !rsol(ji) =  ( drysoil_frac(ji) + un/(10.*(dpu_cste - drysoil_frac(ji))+1.e-10)**2 ) * rsol_cste
+          rsol(ji) =  ( hdry(ji) + un/(10.*(dpu_cste - hdry(ji))+1.e-10)**2 ) * rsol_cste
        ENDIF
     ENDDO
@@ -1124,5 +1127,5 @@
 !!$            ( mean_dsg(ji) .GT. min_sechiba ) .AND. &
 !!$            ( mean_dsg(ji) .LT. 5.E-4 ) ) THEN
-!!$        litterhumdiag(ji) = 0.0
+!!$        litterhumdiag(ji) = zero
 !!$      ENDIF
 !!$    ENDDO
@@ -1273,5 +1276,5 @@
          IF (snow(ji).GT.sneige) THEN 
             !
-            snowmelt(ji) = (1. - frac_nobio(ji,iice))*(temp_sol_new(ji) - tp_00) * soilcap(ji) / chalfu0 
+            snowmelt(ji) = (un - frac_nobio(ji,iice))*(temp_sol_new(ji) - tp_00) * soilcap(ji) / chalfu0 
             !
             ! 1.3.1.1 enough snow for melting or not
@@ -1409,5 +1412,5 @@
                     &  (un - snow_nobio_age(ji,iice)/max_snow_age) * dtradia/one_day ) * &
                     &  EXP(-precip_snow(ji) / snow_trans) - snow_nobio_age(ji,iice)
-        IF (d_age(ji) .GT. 0. ) THEN
+        IF (d_age(ji) .GT. zero ) THEN
           xx(ji) = MAX( tp_00 - temp_sol_new(ji), zero )
           xx(ji) = ( xx(ji) / 7._r_std ) ** 4._r_std
@@ -1456,5 +1459,4 @@
     REAL(r_std), DIMENSION (kjpindex,nvm)          :: zqsintvegnew
     LOGICAL, SAVE                                  :: firstcall=.TRUE.
-!    REAL(r_std), SAVE, DIMENSION(nvm)              :: throughfall_by_pft
 
     IF ( firstcall ) THEN
@@ -1578,5 +1580,5 @@
         ENDIF
     !
-        IF (resdist(ji,jv) .GT. 0.) THEN
+        IF (resdist(ji,jv) .GT. zero) THEN
          qsintveg2(ji,jv) = qsintveg(ji,jv)/resdist(ji,jv)
         ELSE
@@ -1586,5 +1588,5 @@
     ENDDO
     !
-    vegchtot(:) = 0.
+    vegchtot(:) = zero
     DO jv = 1, nvm
       DO ji = 1, kjpindex
@@ -1595,5 +1597,5 @@
     DO jv = 1, nvm
       DO ji = 1, kjpindex
-        IF ( vegchtot(ji) .GT. 0. ) THEN
+        IF ( vegchtot(ji) .GT. zero ) THEN
           gdq(ji,jv) = ABS(vmr(ji,jv)) * gqsb(ji,jv)
           bdq(ji,jv) = ABS(vmr(ji,jv)) * bqsb(ji,jv)
@@ -1613,5 +1615,5 @@
     DO jv = 1, nvm
       DO ji = 1, kjpindex
-        IF ( ( vegchtot(ji) .GT. 0. ) .AND. ( vmr(ji,jv) .LT. 0. ) ) THEN
+        IF ( ( vegchtot(ji) .GT. zero ) .AND. ( vmr(ji,jv) .LT. zero ) ) THEN
           gtr(ji) = gtr(ji) + gdq(ji,jv)
           btr(ji) = btr(ji) + bdq(ji,jv)
@@ -1625,8 +1627,8 @@
     DO jv = 1, nvm
       DO ji = 1, kjpindex
-        IF ( vegchtot(ji) .GT. 0. .AND. ABS(vtr(ji)) .GT. EPS1) THEN
+        IF ( vegchtot(ji) .GT. zero .AND. ABS(vtr(ji)) .GT. EPS1) THEN
             fra(ji) = vmr(ji,jv) / vtr(ji)
-             IF ( vmr(ji,jv) .GT. 0.)  THEN
-              IF (veget(ji,jv) .GT. 0.) THEN
+             IF ( vmr(ji,jv) .GT. zero)  THEN
+              IF (veget(ji,jv) .GT. zero) THEN
                gqsb(ji,jv) = (resdist(ji,jv)*gqsb(ji,jv) + fra(ji)*gtr(ji))/veget(ji,jv)
                bqsb(ji,jv) = (resdist(ji,jv)*bqsb(ji,jv) + fra(ji)*btr(ji))/veget(ji,jv)
@@ -2003,6 +2005,6 @@
     IF (long_print) WRITE(numout,*)  'hydrolc_soil 3.0 : Vertical diffusion'
 
-    mean_bqsb(:) = 0.
-    mean_gqsb(:) = 0.
+    mean_bqsb(:) = zero
+    mean_gqsb(:) = zero
     DO jv = 1, nvm
       DO ji = 1, kjpindex
@@ -2030,5 +2032,5 @@
         DO ji = 1, kjpindex
            IF (lbad_ij(ji)) THEN
-              IF ( veget(ji,jv) .GT. 0. ) THEN
+              IF ( veget(ji,jv) .GT. zero ) THEN
                  !
                  bqsb(ji,jv) = mean_bqsb(ji)
@@ -2056,5 +2058,5 @@
 !        !
 !        DO ji = 1, kjpindex
-!          IF ( veget(ji,jv) .GT. 0. ) THEN
+!          IF ( veget(ji,jv) .GT. zero ) THEN
 !            !
 !            bqsb(ji,jv) = mean_bqsb(ji)
@@ -2082,6 +2084,6 @@
       ENDDO
       !
-      mean_bqsb(:) = 0.
-      mean_gqsb(:) = 0.
+      mean_bqsb(:) = zero
+      mean_gqsb(:) = zero
       DO jv = 1, nvm
         DO ji = 1, kjpindex
@@ -2180,6 +2182,6 @@
                zhumrel_up(ji) = EXP( - humcste(jv) * dss(ji,jv))
                ! Ajouts Nathalie - Fred - le 28 Mars 2006
-               a_subgrd(ji,jv)=MIN(MAX(dsg(ji,jv)-dss(ji,jv),0.)/dsg_min,1.)
-               humrel(ji,jv)=a_subgrd(ji,jv)*zhumrel_up(ji)+(1.-a_subgrd(ji,jv))*zhumrel_lo(ji)
+               a_subgrd(ji,jv)=MIN(MAX(dsg(ji,jv)-dss(ji,jv),zero)/dsg_min,un)
+               humrel(ji,jv)=a_subgrd(ji,jv)*zhumrel_up(ji)+(un-a_subgrd(ji,jv))*zhumrel_lo(ji)
                !
                vegstress(ji,jv) = zhumrel_lo(ji) + zhumrel_up(ji) - EXP( - humcste(jv) * dsg(ji,jv) ) 
@@ -2221,9 +2223,9 @@
 
     ! The fraction of visibly dry soil (dry when dss(:,1) = 0.1 m)
-    drysoil_frac(:) = MIN(MAX(dss(:,1),0.)*10._r_std, un)
+    drysoil_frac(:) = MIN(MAX(dss(:,1),zero)*10._r_std, un)
 
     ! Correction Nathalie - le 28 Mars 2006 - re-ecriture drysoil_frac/hdry - Fred Hourdin
     ! revu 22 novembre 2007
-    hdry(:) = a_subgrd(:,1)*dss(:,1) + (1.-a_subgrd(:,1))*dsp(:,1)
+    hdry(:) = a_subgrd(:,1)*dss(:,1) + (un-a_subgrd(:,1))*dsp(:,1)
     !
     ! Compute the resistance to bare soil evaporation.
@@ -2237,5 +2239,5 @@
           ! du fond. En gros, rsol=hdry*rsol_cste pour hdry < 1m70
           !rsol(ji) = dss(ji,1) * rsol_cste
-          rsol(ji) =  ( hdry(ji) + 1./(10.*(dpu_cste - hdry(ji))+1.e-10)**2 ) * rsol_cste
+          rsol(ji) =  ( hdry(ji) + un/(10.*(dpu_cste - hdry(ji))+1.e-10)**2 ) * rsol_cste
        ENDIF
     ENDDO
@@ -2389,5 +2391,5 @@
        IF ( ABS(delta_water(ji)-tot_flux(ji)) .GT. allowed_err ) THEN
           WRITE(numout,*) 'HYDROL does not conserve water. The erroneous point is : ', ji
-          WRITE(numout,*) 'The error in mm/d is :', (delta_water(ji)-tot_flux(ji))/dtradia, &
+          WRITE(numout,*) 'The error in mm/d is :', (delta_water(ji)-tot_flux(ji))/dtradia*one_day, &
                & ' and in mm/dt : ', delta_water(ji)-tot_flux(ji)
           WRITE(numout,*) 'delta_water : ', delta_water(ji), ' tot_flux : ', tot_flux(ji)
@@ -2520,5 +2522,5 @@
       !Config  Key  = HYDROL_TAU_HDIFF
       !Config  Desc = time scale (s) for horizontal diffusion of water
-      !Config  Def  = 86400.
+      !Config  Def  = one_day
       !Config  If   = HYDROL_OK_HDIFF
       !Config  Help = Defines how fast diffusion occurs horizontally between
@@ -2526,5 +2528,5 @@
       !Config         diffusion.
 
-      tau_hdiff = 86400.
+      tau_hdiff = one_day
       CALL getin_p('HYDROL_TAU_HDIFF',tau_hdiff)
 
