!copyright (C) 2001  MSC-RPN COMM  %%%RPNPHY%%%
*** S/P VEGI
*
#include "phy_macros_f.h"

      SUBROUTINE VEGI ( RG, T, TS, HU, PS, W2, RGL, 1,2
     1                  LAI, RSMIN, GAMMA, WWILT, WFC, RS,
     1                  N )
*
#include "impnone.cdk"
*
      INTEGER N
      REAL RG(N), T(N), HU(N), PS(N), W2(N), TS(N)
      REAL RGL(N), LAI(N), RSMIN(N), GAMMA(N), WWILT(N)
      REAL WFC(N), RS(N)
*
*Author
*          S. Belair (January 1997)
*Revisions
* 001      B. Bilodeau (January 2001)
*          Automatic arrays
*
*Object
*
*          Calculates the surface stomatal resistance Rs
*
*
*Arguments
*
*          - Input -
* RG       solar radiation
* T        low-level temperature of air
* TS       surface temperature
* HU       low-level specific humidity of air
* PS       surface pressure
* W2       soil volumetric water content
* RGL      constant for the calculation of the stomatal resistance
* LAI      Leaf area index
* RSMIN    minimum stomatal resistance
* GAMMA    other constant for RS
* WWILT    volumetric water content at the wilting point
* WFC      volumetric water content at the field capacity
*
*          - Output -
* RS       Surface or stomatal resistance
*
*
#include "consphy.cdk"
*
      INTEGER I
*
*
*
************************************************************************
*     AUTOMATIC ARRAYS
************************************************************************
*
      AUTOMATIC (  F    , REAL , (N))
      AUTOMATIC (  F1   , REAL , (N))
      AUTOMATIC (  F2   , REAL , (N))
      AUTOMATIC (  F3   , REAL , (N))
      AUTOMATIC (  F4   , REAL , (N))
      AUTOMATIC (  QSAT , REAL , (N))
*
************************************************************************
*
#include "dintern.cdk"
#include "fintern.cdk"
*
*
*
*
*
*
*
*
**       1.     THE 'ZF1' FACTOR
*               ---------------
*                      This factor measures the influence
*                      of the photosynthetically active radiation
*
*
      DO I=1,N
        F(I)  = 0.55*2.*RG(I) / (RGL(I)+1.E-6) /
     1          ( LAI(I)+1.E-6 )
        F1(I) = ( F(I) + RSMIN(I)/5000. ) / ( 1. + F(I) )
      END DO
*
*
*
*
**       2.     THE 'ZF2' FACTOR
*               ----------------
*                      This factor takes into account the effect
*                      of the water stress on the surface
*                      resistance
*
*                      NOTE that W2 (liquid portion of soil water) is
*                      used here instead of W2+WF.  Thus, when soil water
*                      freezes (W2 --> 0), ZF2 becomes small and the
*                      surface increases increases (no transpiration when
*                      soils are frozen).  
*
      DO I=1,N
*
*
*            For humid soils, this factor does not
*            increase the stomatal resistance
*
        IF (W2(I).GE.WFC(I)) F2(I) = 1.0
*
*
*            The stomatal resistance should be large
*            when the soil is very dry
*
        IF (W2(I).LT.WFC(I).AND.W2(I).LE.WWILT(I))
     1        F2(I) = 1.E-5
*
*
*            For intermediate soils:
*
        IF (W2(I).LT.WFC(I).AND.W2(I).GT.WWILT(I))
     1      F2(I) = ( W2(I)-WWILT(I) ) /
     1              ( WFC(I)-WWILT(I) + 1.E-6 )
*
      END DO
*
*
*
**       3.     THE 'ZF3' FACTOR
*               ----------------
*                           This factor represents the effect of
*                           vapor pressure deficit of the atmosphere.
*                           For very humid air, the stomatal resistance
*                           is small, whereas it increases as the
*                           air becomes drier.
*
*
      DO I=1,N
*
       QSAT(I) = FOQST( TS(I), PS(I) )
*
       F3(I) = MAX( 1. - GAMMA(I)*( QSAT(I)
     1        - HU(I) )*1000. , 1.E-3 )
*
      END DO
*
*
*
**       4.     THE 'ZF4' FACTOR
*               ----------------
*                  This factor introduces an air temperature
*                  dependance on the surface stomatal resistance
*
      DO I=1,N
        F4(I) = MAX( 1.0 - 0.0016*(298.15-T(I))**2, 1.E-3 )
      END DO
*
*
**       5.     THE SURFACE STOMATAL RESISTANCE
*               -------------------------------
*
      DO I=1,N
        RS(I) = RSMIN(I) / ( LAI(I)+1.E-6 )
     1        / F1(I) / F2(I) / F3(I) / F4(I)
*
        RS(I) = MIN( RS(I),5000.  )
        RS(I) = MAX( RS(I), 1.E-4 )
      END DO
*
*
*
*
      RETURN
      END