Index: LMDZ6/trunk/libf/phylmd/conf_phys_m.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/conf_phys_m.F90	(revision 3790)
+++ LMDZ6/trunk/libf/phylmd/conf_phys_m.F90	(revision 3792)
@@ -86,5 +86,9 @@
     CHARACTER (len = 10),SAVE  :: type_veget_omp
     CHARACTER (len = 8), SAVE  :: aer_type_omp
-    LOGICAL, SAVE       :: ok_snow_omp
+    INTEGER, SAVE       :: landice_opt_omp
+    INTEGER, SAVE       :: n_dtis_omp
+    INTEGER, SAVE       :: iflag_tsurf_inlandsis_omp
+    INTEGER, SAVE       :: iflag_albzenith_omp    
+    LOGICAL, SAVE       :: SnoMod_omp,BloMod_omp,ok_outfor_omp
     LOGICAL, SAVE       :: ok_newmicro_omp
     LOGICAL, SAVE       :: ok_all_xml_omp
@@ -318,12 +322,60 @@
     !
 
-    ! Martin
-    !Config Key  = ok_snow
-    !Config Desc = Flag to activate snow model SISVAT
-    !Config Def  = .FALSE.
-    ok_snow_omp = .FALSE.
-    CALL getin('ok_snow', ok_snow_omp)
-    ! Martin
-
+    ! INLANDSIS
+    !==================================================================
+    ! Martin et Etienne
+    !Config Key  = landice_opt
+    !Config Desc = which landice snow model (BULK, SISVAT or INLANDSIS)
+    !Config Def  = 0
+    landice_opt_omp = 0
+    CALL getin('landice_opt', landice_opt_omp)
+    ! Martin et Etienne
+
+    !Etienne
+    !Config Key  = iflag_tsurf_inlandsis
+    !Config Desc = which method to calculate tsurf in INLANDSIS
+    !Config Def  = 0
+    iflag_tsurf_inlandsis_omp = 0
+    CALL getin('iflag_tsurf_inlandsis', iflag_tsurf_inlandsis_omp)
+
+    !Etienne
+    !Config Key  = iflag_albzenith
+    !Config Desc = method to account for albedo sensitivity to solar zenith angle
+    !Config Def  = 0
+    iflag_albzenith_omp = 0
+    CALL getin('iflag_albzenith', iflag_albzenith_omp)
+
+    !Etienne
+    !Config Key  = n_dtis
+    !Config Desc = number of subtimesteps for INLANDSIS
+    !Config Def  = 1
+    n_dtis_omp = 1
+    CALL getin('n_dtis', n_dtis_omp)
+
+    !Etienne
+    !Config Key  = SnoMod
+    !Config Desc = activation of snow modules in inlandsis
+    !Config Def  = 1
+    SnoMod_omp = .TRUE.
+    CALL getin('SnoMod', SnoMod_omp)
+
+    !Etienne
+    !Config Key  = BloMod
+    !Config Desc = activation of blowing snow in inlandsis
+    !Config Def  = 1
+    BloMod_omp = .FALSE.
+    CALL getin('BloMod', BloMod_omp)
+
+    !Etienne
+    !Config Key  = ok_outfor
+    !Config Desc = activation of output ascii file in inlandsis
+    !Config Def  = 1
+   ok_outfor_omp = .FALSE.
+    CALL getin('ok_outfor', ok_outfor_omp)
+
+
+
+    !==================================================================
+    
     !Config Key  = OK_journe
     !Config Desc = Pour des sorties journalieres 
@@ -2291,8 +2343,14 @@
        ok_veget=.FALSE.
     ENDIF
-    ! Martin
-    ok_snow = ok_snow_omp
-    ! Martin
-
+    ! SISVAT and INLANDSIS
+    !=================================================
+    landice_opt = landice_opt_omp
+    iflag_tsurf_inlandsis = iflag_tsurf_inlandsis_omp
+    iflag_albzenith = iflag_albzenith_omp
+    n_dtis=n_dtis_omp
+    SnoMod=SnoMod_omp
+    BloMod=BloMod_omp
+    ok_outfor=ok_outfor_omp
+    !=================================================
     ok_all_xml = ok_all_xml_omp
     ok_lwoff = ok_lwoff_omp
@@ -2554,5 +2612,5 @@
     WRITE(lunout,*) ' Version ocean = ', version_ocean
     WRITE(lunout,*) ' Config veget = ', ok_veget,type_veget
-    WRITE(lunout,*) ' Snow model SISVAT : ok_snow = ', ok_snow
+    WRITE(lunout,*) ' Snow model landice : landice_opt = ', landice_opt
     WRITE(lunout,*) ' Config xml pour XIOS : ok_all_xml = ', ok_all_xml
     WRITE(lunout,*) ' Sortie journaliere = ', ok_journe
@@ -2753,4 +2811,11 @@
     WRITE(lunout,*) ' carbon_cycle_rad = ', carbon_cycle_rad
     WRITE(lunout,*) ' level_coupling_esm = ', level_coupling_esm
+    WRITE(lunout,*) ' iflag_tsurf_inlandsis = ', iflag_tsurf_inlandsis
+    WRITE(lunout,*) ' iflag_albzenith = ', iflag_albzenith
+    WRITE(lunout,*) ' n_dtis = ', n_dtis
+    WRITE(lunout,*) ' SnoMod = ', SnoMod
+    WRITE(lunout,*) ' BloMod = ', BloMod
+    WRITE(lunout,*) ' ok_outfor = ', ok_outfor
+
 
     !$OMP END MASTER
Index: LMDZ6/trunk/libf/phylmd/dimsoil.h
===================================================================
--- LMDZ6/trunk/libf/phylmd/dimsoil.h	(revision 3790)
+++ LMDZ6/trunk/libf/phylmd/dimsoil.h	(revision 3792)
@@ -4,2 +4,17 @@
       INTEGER nsoilmx
       PARAMETER (nsoilmx=11)
+
+! For Inlandsis, Etienne Vignon:
+
+      INTEGER nsnowmx
+      PARAMETER (nsnowmx=35)
+      
+      INTEGER nsismx
+      PARAMETER (nsismx=46) 
+
+! nsismx should be equal to nsoilmx+nsnowmx 
+
+
+
+
+
Index: LMDZ6/trunk/libf/phylmd/inlandsis/VAR0SV.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/VAR0SV.F90	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/VAR0SV.F90	(revision 3792)
@@ -0,0 +1,33 @@
+MODULE VAR0SV
+
+USE VAR_SV, only : nsol, nsno 
+USE VARdSV, only : nsot
+
+IMPLICIT NONE
+                                                  
+      INTEGER    :: islpSV(-nsol:0)                                           
+      INTEGER    :: isnpSV(      nsno)                                        
+      INTEGER    :: islmSV(-nsol:0)    
+                                      
+      INTEGER,PARAMETER :: nkhy=50                                            
+      REAL       :: Implic,Explic                                             
+      REAL       :: dzmiSV(-nsol:0)          ! dz_(i-1/2)                     
+      REAL       :: dzi_SV(-nsol:0)          ! dz_(i-1)/(dz_(i)+dz_(i-1))     
+      REAL       :: dziiSV(-nsol:0)          ! dz_(i)  /(dz_(i)+dz_(i-1))     
+      REAL       :: dtz_SV(-nsol:0)          ! dt / dz             
+      REAL       :: dtz_SV2(-nsol:0)          ! dt / dz             
+      REAL       :: dz78SV(-nsol:0)          ! 7/8 (dz)                       
+      REAL       :: dz34SV(-nsol:0)          ! 3/4 (dz)                       
+      REAL       :: dz_8SV(-nsol:0)          ! 1/8 (dz)                       
+      REAL       :: dzAvSV(-nsol:0)          ! 1/8dz_(-1)+3/4dz+1/8dz_(+1)    
+      REAL       :: OcndSV                   ! Swab Ocean / Soil Ratio        
+      REAL       :: rocsSV( 0:nsot)          ! Soil Contribution to (ro c)_s  
+      REAL       :: etamSV( 0:nsot)          ! Soil Minimum Humidity          
+      REAL       :: s1__SV( 0:nsot)          ! ... X eta**( b+2), DR97(3.36)  
+      REAL       :: s2__SV( 0:nsot)          ! ... X eta**(2b+3), DR97(3.35)  
+      REAL       :: aKdtSV( 0:nsot, 0:nkhy)  ! Khyd=a*eta+b: a * dt           
+      REAL       :: bKdtSV( 0:nsot, 0:nkhy)  ! Khyd=a*eta+b: b * dt     
+      REAL       :: aKdtSV2( 0:nsot, 0:nkhy)  ! Khyd=a*eta+b: a * dt           
+      REAL       :: bKdtSV2( 0:nsot, 0:nkhy)  ! Khyd=a*eta+b: b * dt                 
+
+END MODULE VAR0SV
Index: LMDZ6/trunk/libf/phylmd/inlandsis/VAR_SV.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/VAR_SV.F90	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/VAR_SV.F90	(revision 3792)
@@ -0,0 +1,26 @@
+MODULE VAR_SV
+
+
+IMPLICIT NONE
+
+INCLUDE "dimsoil.h"
+
+! +
+! +   LMDZ_SV dims
+! +   ===================
+! +
+!      INTEGER,PARAMETER :: nsol=nsoilmx-1
+!      INTEGER,PARAMETER :: nsno=nsnowmx
+     
+      INTEGER, PARAMETER    :: nsol=nsoilmx-1
+      INTEGER, PARAMETER    :: nsot=nsoilmx+1
+      INTEGER, PARAMETER    :: nsno=nsnowmx
+      INTEGER, PARAMETER    :: nb_wri=1
+      INTEGER,SAVE      :: klonv
+!$OMP THREADPRIVATE(klonv)
+      INTEGER,SAVE      :: knonv
+!$OMP THREADPRIVATE(knonv)
+
+
+
+END MODULE VAR_SV
Index: LMDZ6/trunk/libf/phylmd/inlandsis/VARdSV.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/VARdSV.F90	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/VARdSV.F90	(revision 3792)
@@ -0,0 +1,101 @@
+MODULE VARdSV
+
+USE VAR_SV
+
+IMPLICIT NONE
+
+
+! +--SISVAT Global Variables
+! +  =======================
+
+      LOGICAL           ::   INI_SV=.false.          ! Initialisation Switch     
+      REAL,PARAMETER    ::   eps_21=1.e-21           ! Arbitrary  very small value
+
+
+! +--Snow
+! +  ----
+
+      INTEGER,PARAMETER,DIMENSION(5) ::   istdSV(1:5)=(/1,2,3,4,5/)  ! Snow History
+
+      REAL,PARAMETER    ::   Cn_dSV= 2105.           ! Snow Heat Capacity          [J/kg/K]
+      REAL,PARAMETER    ::   SMndSV= 1.00            ! Minimum Thickness of new Layers
+      REAL,PARAMETER    ::   G1_dSV= 99.             ! Conversion 0/99-->0/1 
+      REAL,PARAMETER    ::   DDcdSV= 1.,DFcdSV= 4.,DScdSV= 3.   
+                                                     ! Snow Grains Optical Diameter [1e-4m]
+      REAL,PARAMETER    ::   ADSdSV= 4.              ! Snow Grains Actual  Diameter [1e-4m]
+      REAL,PARAMETER    ::   So1dSV= 0.580,So2dSV= 0.320,So3dSV= 0.100
+                                                     ! Total Solar Irradiance Fractions [-]
+                                                     ! Tuning ETH camp 0.3--0.8mim Interval
+                                                     ! Tuning ETH camp 0.8--1.5mim Interval
+                                                     ! Tuning ETH camp 1.5--2.8mim Interval
+                                                     ! So1dSV=0.606,So2dSV=0.301,So3dSV=0.093
+      REAL,PARAMETER    ::   aI1dSV= 0.40,aI2dSV= 0.45,aI3dSV= 0.65
+                                                     ! Bare Ice Albedo                  [-]
+                                                     ! Minimum/Maximum/ICE lense albedo at 
+                                                     ! 800 kg/m3 and minimum pure snow albedo
+      REAL,PARAMETER    ::   ws0dSV= 0.07            ! Irreducible Water Saturation in Snow
+      REAL,PARAMETER    ::   roCdSV= 800.            ! Pore Hole Close OFF Density  [kg/m3]
+      REAL,PARAMETER    ::   roBdSV= 450.            ! Max blowing snow Density [kg/m3]
+      REAL,PARAMETER    ::   roSdSV= 450.            ! Max pure    snow Density [kg/m3]
+      REAL,PARAMETER    ::   ru_dSV= 200.            ! Surficial Water Scale Factor [kg/m2]
+
+!C +--Ice
+!C +  ---
+
+      REAL,PARAMETER    ::   CdidSV= 2.1
+
+
+
+!C +--Soil
+!C +  ----
+
+      REAL,PARAMETER    ::   rcwdSV = 4.180e+6    ! Density * Water Specific Heat
+      REAL              ::   dz_dSV(-nsol:0)      ! Vertical  Discretization MARSV:
+                                                  !/0.72,0.20,0.060,0.019,0.001/ 
+                                                  ! Layer's Thickness
+      REAL              ::   zz_dSV               ! Soil      Thickness
+
+      REAL,PARAMETER    ::   etadSV(0:nsot) = (/ 1.000,0.395,0.410,     &
+     &     0.435,0.485,0.451,0.420,0.477,0.476,0.426,0.492,0.482,0.001 /)      
+                                                  ! Water Content at Saturation  [m3/m3]
+
+      REAL,PARAMETER    ::   psidSV(0:nsot) = (/ 1.000,0.121,0.090,     &
+     &     0.218,0.786,0.478,0.299,0.356,0.630,0.153,0.490,0.405,0.001 /)
+                                                  ! Water Succion at Saturation      [m]
+
+      REAL,PARAMETER    ::   Ks_dSV(0:nsot) = (/ 0.e00, 176.0e-6,       &
+     &          156.3e-6,  34.1e-6,   7.2e-6,   7.0e-6,   6.3e-6,       &
+     &            1.7e-6,   2.5e-6,   2.2e-6,   1.0e-6,   1.3e-6,0.0e0 /)
+                                                  ! Hydraulic Conductivity
+                                                  !               at Saturation    [m/s]
+      REAL,PARAMETER    ::   bCHdSV(0:nsot) = (/ 1.00, 4.05, 4.38,      &
+     &      4.90, 5.30, 5.39, 7.12, 7.75, 8.52,10.40,10.40,11.40, 0.02 /)
+                                                  ! Clapp-Hornberger Coefficient b   [-]
+
+ !     etadSV,   psidSV,   Ks_dSV    bCHdSV  
+ !     /1.000,    1.000,   0.0e00,     1.00,      !  0 WATER
+ !      0.395,    0.121, 176.0e-6,     4.05,      !  1 SAND
+ !      0.410,    0.090, 156.3e-6,     4.38,      !  2 LOAMY      SAND
+ !      0.435,    0.218,  34.1e-6,     4.90,      !  3 SANDY      LOAM
+ !      0.485,    0.786,   7.2e-6,     5.30,      !  4 SILT       LOAM
+ !      0.451,    0.478,   7.0e-6,     5.39,      !  5            LOAM
+ !      0.420,    0.299,   6.3e-6,     7.12,      !  6 SANDY CLAY LOAM
+ !      0.477,    0.356,   1.7e-6,     7.75,      !  7 SILTY CLAY LOAM 
+ !      0.476,    0.630,   2.5e-6,     8.52,      !  8       CLAY LOAM
+ !      0.426,    0.153,   2.2e-6,    10.40,      !  9 SANDY CLAY
+ !      0.492,    0.490,   1.0e-6,    10.40,      ! 10 SILTY CLAY
+ !      0.482,    0.405,   1.3e-6,    11.40,      ! 11       CLAY
+ !      0.001,    0.001,   0.0e00,     0.02/      ! 12       ICE 
+
+
+!C +--Water Bodies
+!C +  ------------
+
+      REAL,PARAMETER    ::   vK_dSV = 1000.       ! Diffusivity in Water          [m2/s]
+      REAL,PARAMETER    ::   TSIdSV = 0.50        ! Sea-Ice Fraction: SST Scale      [K]
+
+      INTEGER ::  iso1  !rajout hjp for ini - check if ivg,iso is possible
+
+!
+
+END MODULE VARdSV
Index: LMDZ6/trunk/libf/phylmd/inlandsis/VARphy.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/VARphy.F90	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/VARphy.F90	(revision 3792)
@@ -0,0 +1,98 @@
+MODULE VARphy
+
+
+IMPLICIT NONE
+
+
+
+! Etienne, 08112020: merging YOMCST_SISVAT,  PHY_SV and VARphy
+! but redundancies remain
+!
+!  ATTENTION!!!!: ce fichier include est compatible format fixe/format libre
+!                 veillez à n'utiliser que des ! pour les commentaires
+!                 et à bien positionner les & des lignes de continuation
+!                 (les placer en colonne 6 et en colonne 73)
+!
+!
+! A1.0 Fundamental constants
+!----------------------------
+! Constants
+                                                                              
+      CHARACTER(LEN=1), PARAMETER :: labnum(0:9) =                            &
+              (/'0','1','2','3','4','5','6','7','8','9'/)             
+!C +...                labnum: Alphanumeric Character      
+     
+                                                                               
+      INTEGER, PARAMETER ::  iun=1                                             
+      REAL, PARAMETER    ::  zer0 = 0.0e+0, half = 0.5e+0, un_1 = 1.0e+0,     &
+     &                       eps6 = 1.0e-6, R_1000=1.e3       
+      REAL, PARAMETER    ::  zero = 0.0e+0, demi = 0.5e+0, unun = 1.0e+0,     &
+     &                       epsi = 1.0e-6, eps9 = 1.0e-9         
+      REAL               ::  ea_MAX,ea_MIN                                                                               
+      REAL, PARAMETER    ::  pi = 3.141592653589793238462643e0
+     
+! A1.2 Geoide
+!-------------
+      REAL, PARAMETER    ::  Grav_F = 9.81e0, Grav_I = 1./Grav_F                       
+!C +                   Grav_F:  Gravitational  Force         =  9.81    m/s2           
+!C +                   Grav_I: 1 / Grav_F                    = 1 /9.81    s2/m    
+
+                                                                               
+      REAL, PARAMETER    ::  gravit = 9.81e0,      gravi2 = gravit**2 ,       &
+     &                       grvinv = 1./gravit                       
+!C +                   gravit: Earth Gravity Acceleration    = 9.81    m/s2    
+!C +                   gravi2: idem (squared)                                  
+!C +                   grvinv: idem (inverse)                 
+! A1.3 Radiation
+!----------------
+      REAL,PARAMETER :: StefBo=5.67e-8  
+!C +                   StefBo: Stefan-Boltzman Constant       =    5.67d-8 W/m2/K4
+
+! A1.4 Thermodynamic 
+!-----------------------------
+     
+      REAL, PARAMETER    ::  cp=1004.708845
+                                                       
+      REAL, PARAMETER    ::  RVapor=461.e0, Lv_H2O=2.5008e+6,&
+     &                       Ls_H2O=2.8345e+6, r_LvCp=2490.04,r_LcCp=332.27,  &
+     &                       r_LsCp=2822.31            
+!C +                   cp    : dry air specific heat at constant p (1004 J/kg/K) 
+
+      REAL, PARAMETER    ::  LhfH2O=3.34e+5, LhvH2O=2.5008e+6,&
+     &                       LhsH2O=2.8345e+6     
+      REAL, PARAMETER    ::  rhoWat=1000.00e0    
+!C +                   rhoWat: Water Specific Mass            = 1000.00d+0 kg/m3 
+
+      REAL, PARAMETER    ::  rhoIce=920.e0, BSnoRo=3.30e+2, frsno=300.0                             
+!C +...                rhoIce:  Density      of Pure Ice      =  920.00d+0 kg/m3
+!C +                   BSnoRo : Blowed Snow Density           =  255.00d+0 kg/m3 
+                                                                                
+      REAL, PARAMETER    ::  Tf_Sno=273.16e+0 
+!C +...                Tf_Sno: Snow  Melting  Point           =  273.16    K     
+
+
+      REAL, PARAMETER    ::  ro_Wat=1000.00e0, C__Wat=4186.00e0
+!C +                   ro_Wat: Density       of Water         = 1000.00d+0 kg/m3 
+!C +                   C__Wat: Heat Capacity of Water         = 4186.00d+0 J/kg/K
+                                                                                
+      REAL, PARAMETER    ::  ro_Ice=920.e0, cdice=2.10e0                                 
+!C +...                ro_Ice:  Density      of Pure Ice       =  920.00d+0 kg/m3
+!C +                   cdice :  Conductivity of Pure Ice       =    2.51d+0 W/m/K
+                                                                                
+      REAL, PARAMETER    ::  TfSnow=273.15e+0,csnow=2105.00e+0,r0sno=3.00e+1, &
+     &                       blsno=3.30e+2,   Lf_H2O=3.337e+5                          
+!C +...                TfSnow:        Snow melting Temperature=  273.15d+0 K     
+!C +                    csnow:Heat Capacity of Snow             2105      J/kg/K 
+!C +                         (Loth et al. 1993, JGR 98 D6, 2.2.2 2e para p.10453)
+!C +                   r0sno : Fresh  Snow Density                50.00d+0 kg/m3 
+!C +                   blsno : Blowed Snow Density               330.00d+0 kg/m3 
+!C +                   Lf_H2O: Latent Heat of Fusion of Snow  =    3.34d+5 J/kg  
+
+! A1.6 Turbulent and molecular diffusion
+!----------------------------------------
+      REAL, PARAMETER    ::  A_MolV = 1.35e-5, vonKrm = 0.40e0
+!C +...                A_MolV: Air Viscosity                 = 1.35d-5 m2/s   
+!C +                   vonKrm: von Karman constant           = 0.4            
+                                                                          
+
+END MODULE VARphy
Index: LMDZ6/trunk/libf/phylmd/inlandsis/VARtSV.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/VARtSV.F90	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/VARtSV.F90	(revision 3792)
@@ -0,0 +1,64 @@
+MODULE VARtSV
+
+USE VAR_SV, only : nsol, nsno, klonv
+
+IMPLICIT NONE
+! +
+      INTEGER, PARAMETER      ::   ntaver = 4
+! +
+      REAL,ALLOCATABLE,SAVE                ::   toicSV(:)    ! Snow to ice balance    
+!$OMP THREADPRIVATE(toicSV)
+
+      REAL,ALLOCATABLE,SAVE                ::   dz1_SV(:,:) ! "inverse" layer thicknes
+!$OMP THREADPRIVATE(dz1_SV)
+      REAL,ALLOCATABLE,SAVE                ::   dz2_SV(:,:) ! layer thickness
+!$OMP THREADPRIVATE(dz2_SV)
+
+
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE  ::   Tsf_SV  ! surface temperature !hj12032010
+!$OMP THREADPRIVATE(Tsf_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE  ::   TsfnSV  ! new surface temperature 
+!$OMP THREADPRIVATE(TsfnSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE  ::   AcoHSV, BcoHSV ! coefficients for Enthalpy
+!$OMP THREADPRIVATE(AcoHSV, BcoHSV)                             ! evolution,from atmosphere
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE  ::   AcoQSV, BcoQSV ! coefficients for Humidity
+!$OMP THREADPRIVATE( AcoQSV, BcoQSV)                            ! evolution,from atmosphere
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE  ::   ps__SV  ! surface pressure 
+!$OMP THREADPRIVATE(ps__SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE  ::   p1l_SV  ! 1st layer pressure 
+!$OMP THREADPRIVATE(p1l_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE  ::   cdH_SV  ! drag coeff Energy (?)
+!$OMP THREADPRIVATE(cdH_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE  ::   cdM_SV  ! drag coeff momentum (?)
+!$OMP THREADPRIVATE(cdM_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE  ::   rsolSV  ! Radiation balance surface
+!$OMP THREADPRIVATE(rsolSV)
+      REAL,SAVE                            ::   lambSV  ! coefficient soil layers
+!$OMP THREADPRIVATE(lambSV)
+
+ 
+CONTAINS
+
+  SUBROUTINE INIT_VARtSV
+  IMPLICIT NONE
+  
+      ALLOCATE(toicSV(klonv))
+
+      ALLOCATE(dz1_SV(klonv,-nsol:nsno))     ! "inverse" layer thicknes
+      ALLOCATE(dz2_SV(klonv,-nsol:nsno))     ! layer thickness
+      ALLOCATE(Tsf_SV(klonv))                ! surface temperature !hj12032010
+      ALLOCATE(TsfnSV(klonv))                ! new surface temperature 
+      ALLOCATE(AcoHSV(klonv), BcoHSV(klonv)) ! coefficients for Enthalpy
+                                             ! evolution,from atmosphere
+      ALLOCATE(AcoQSV(klonv), BcoQSV(klonv)) ! coefficients for Humidity
+                                             ! evolution,from atmosphere                                                                                   
+      ALLOCATE(ps__SV(klonv))                ! surface pressure 
+      ALLOCATE(p1l_SV(klonv))                ! 1st layer pressure 
+      ALLOCATE(cdH_SV(klonv))                ! drag coeff Energy (?)
+      ALLOCATE(cdM_SV(klonv))                ! drag coeff momentum (?)
+      ALLOCATE(rsolSV(klonv))                ! Radiation balance surface
+
+  END SUBROUTINE INIT_VARtSV
+
+END MODULE VARtSV
+
Index: LMDZ6/trunk/libf/phylmd/inlandsis/VARxSV.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/VARxSV.F90	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/VARxSV.F90	(revision 3792)
@@ -0,0 +1,356 @@
+MODULE VARxSV                      
+
+USE VAR_SV, only : klonv, nsol, nsno, nb_wri
+                                                          
+IMPLICIT NONE                                                                                
+! +--SISVAT INPUT        Variables                                              
+! +  -----------------------------                                              
+  
+      INTEGER, DIMENSION(:),ALLOCATABLE,SAVE ::   LSmask  ! Land-Sea   Mask                 
+!$OMP THREADPRIVATE(LSmask)
+      INTEGER, DIMENSION(:),ALLOCATABLE,SAVE ::   isotSV  ! Soil       Type                 
+!$OMP THREADPRIVATE(isotSV)
+      INTEGER, DIMENSION(:),ALLOCATABLE,SAVE ::   iWaFSV  ! Soil       Drainage:(1,0)=(y,n) 
+!$OMP THREADPRIVATE(iWaFSV)                                                                              
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   coszSV  ! Cosine of Sun zenithal Angle    
+!$OMP THREADPRIVATE(coszSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   sol_SV  ! Downward  Solar    Radiation    
+!$OMP THREADPRIVATE(sol_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   IRd_SV  ! Downward  Longwave Radiation    
+!$OMP THREADPRIVATE(IRd_SV)
+                                                                                
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   drr_SV  ! Rain  Intensity       [kg/m2/s] 
+!$OMP THREADPRIVATE(drr_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   dsn_SV  ! Snow  Intensity       [kg/m2/s] 
+!$OMP THREADPRIVATE(dsn_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   dsnbSV  ! Idem, fraction, from Drift  [-] 
+!$OMP THREADPRIVATE(dsnbSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   esnbSV  ! Idem, fraction, from Drift  [-]
+!$OMP THREADPRIVATE(esnbSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   dbs_SV  ! Drift Amount            [kg/m2] 
+!$OMP THREADPRIVATE(dbs_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   dbs_Er  ! BS Erosion              [kg/m2]
+!$OMP THREADPRIVATE(dbs_Er)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   dbs_Ac  !  BS Accumulation         [kg/m2]
+!$OMP THREADPRIVATE(dbs_Ac)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   BrosSV  ! Buffer Snow Layer Density
+!$OMP THREADPRIVATE(BrosSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   BG1sSV  ! Buffer Snow Layer Dendr/Sphe[-]
+!$OMP THREADPRIVATE(BG1sSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   BG2sSV  ! Buffer Snow Layer Spher/Size[-][0.0001m]
+!$OMP THREADPRIVATE(BG2sSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   dz0_SV  ! dz0(Sastrugi dh)            [m] 
+!$OMP THREADPRIVATE(dz0_SV)
+                                                                               
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   cld_SV  ! Cloudiness (seen from SBL)      
+!$OMP THREADPRIVATE(cld_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   za__SV  ! SBL Height                      
+!$OMP THREADPRIVATE(za__SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   VV__SV  !(SBL Top)  Wind Velocity         
+!$OMP THREADPRIVATE(VV__SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   VVs_SV  !(Sastr,V)  Relevance
+!$OMP THREADPRIVATE(VVs_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   RRs_SV  !(Sastr,V)  Counter
+!$OMP THREADPRIVATE(RRs_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   DDs_SV  !(Sastr,V)  Angle
+!$OMP THREADPRIVATE(DDs_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   TaT_SV  ! SBL Top   Temperature           
+!$OMP THREADPRIVATE(TaT_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   ExnrSV  ! Exner     Potential             
+!$OMP THREADPRIVATE(ExnrSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   dSdTSV  ! Sensible Heat Flux T Derivat.   
+!$OMP THREADPRIVATE(dSdTSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   dLdTSV  ! Latent   Heat Flux T Derivat.   
+!$OMP THREADPRIVATE(dLdTSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   rhT_SV  ! SBL Top   Air  Density          
+!$OMP THREADPRIVATE(rhT_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   QaT_SV  ! SBL Top   Specific Humidity     
+!$OMP THREADPRIVATE(QaT_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   dQa_SV  ! SBL Flux  Limitation of Qa      
+!$OMP THREADPRIVATE(dQa_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   qsnoSV  ! SBL Mean  Snow       Content    
+!$OMP THREADPRIVATE(qsnoSV)                                                                   
+                                                                               
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   alb0SV  ! Soil    Albedo                  
+!$OMP THREADPRIVATE(alb0SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   slopSV  ! Snow/Ice/Soil-Water Surf. Slope 
+!$OMP THREADPRIVATE(slopSV)
+
+                                                              
+      REAL,SAVE                      ::   zSBLSV  ! SBL Height (Initial Value)      
+!$OMP THREADPRIVATE(zSBLSV)
+      REAL,SAVE                      ::   dt__SV  ! Time Step                       
+!$OMP THREADPRIVATE(dt__SV)
+      CHARACTER (len=18),SAVE        ::   daHost  ! Date Host Model                 
+!$OMP THREADPRIVATE(daHost)
+                                                                               
+                                                                               
+! +--SISVAT INPUT/OUTPUT Variables                                             
+! +  -----------------------------                                             
+                                                                               
+      INTEGER, DIMENSION(:),ALLOCATABLE,SAVE ::   isnoSV  ! Nb of Ice/Snow Layers           
+!$OMP THREADPRIVATE(isnoSV)
+      INTEGER, DIMENSION(:),ALLOCATABLE,SAVE ::   ispiSV  ! Uppermost superimposed ice      
+!$OMP THREADPRIVATE(ispiSV)
+      INTEGER, DIMENSION(:),ALLOCATABLE,SAVE ::   iiceSV  ! Nb of Ice      Layers           
+!$OMP THREADPRIVATE(iiceSV)
+      INTEGER ,ALLOCATABLE,SAVE              ::   istoSV(:,:)  ! Snow Layer     History          
+!$OMP THREADPRIVATE(istoSV)                                                                              
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   alb_SV  ! Surface Albedo           
+!$OMP THREADPRIVATE(alb_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   emi_SV  ! Surface Emissivity       
+!$OMP THREADPRIVATE(emi_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   IRs_SV  ! Soil           IR Flux          
+!$OMP THREADPRIVATE(IRs_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   LMO_SV  ! Monin-Obukhov  Scale            
+!$OMP THREADPRIVATE(LMO_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   us__SV  ! Friction       Velocity         
+!$OMP THREADPRIVATE(us__SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   uts_SV  ! Temperature Turbulent Scale     
+!$OMP THREADPRIVATE(uts_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   cutsSV  ! Temperature Turbulent Scale C.  
+!$OMP THREADPRIVATE(cutsSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   uqs_SV  ! Spec.Humid. Turbulent Scale     
+!$OMP THREADPRIVATE(uqs_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   uss_SV  ! Blow.Snow   Turbulent Scale     
+!$OMP THREADPRIVATE(uss_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   usthSV  ! Blowing Snow Erosion Thresh.    
+!$OMP THREADPRIVATE(usthSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   rCDmSV  ! Square  Root Contribut. Drag_m  
+!$OMP THREADPRIVATE(rCDmSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   rCDhSV  ! Square  Root Contribut. Drag_h  
+!$OMP THREADPRIVATE(rCDhSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0m_SV  ! Momentum     Roughness Length   
+!$OMP THREADPRIVATE(Z0m_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0mmSV  !  z0(Momentum,    Time Mean) [m] 
+!$OMP THREADPRIVATE(Z0mmSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0mnSV  !  z0(Momentum,    instanta.) [m] 
+!$OMP THREADPRIVATE(Z0mnSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0roSV  ! Subgrid Topo Roughness Length   
+!$OMP THREADPRIVATE(Z0roSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0SaSV  !  z0(Sastrugi  h)            [m] 
+!$OMP THREADPRIVATE(Z0SaSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0e_SV  !  z0(Snow eroded)            [m] 
+!$OMP THREADPRIVATE(Z0e_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0emSV  !  z0(Snow eroded, Time Mean) [m] 
+!$OMP THREADPRIVATE(Z0emSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0enSV  !  z0(Snow eroded, instanta.) [m] 
+!$OMP THREADPRIVATE(Z0enSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0h_SV  ! Heat         Roughness Length   
+!$OMP THREADPRIVATE(Z0h_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0hmSV  !  z0(Heat,        Time Mean) [m] 
+!$OMP THREADPRIVATE(Z0hmSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   Z0hnSV  !  z0(Heat,        instanta.) [m] 
+!$OMP THREADPRIVATE(Z0hnSV)
+                                                                         
+
+                                                                        
+      REAL ,ALLOCATABLE,SAVE   ::   TsisSV(:,:)  ! Snow/Ice/Soil-Water Temperature 
+!$OMP THREADPRIVATE(TsisSV)
+      REAL ,ALLOCATABLE,SAVE   ::   ro__SV(:,:)  ! Snow/Ice/Soil-Water VolumicMass 
+!$OMP THREADPRIVATE(ro__SV)
+      REAL,ALLOCATABLE,SAVE    ::   eta_SV(:,:)  ! Snow/Ice/Soil     Water Content 
+!$OMP THREADPRIVATE(eta_SV)
+      REAL,ALLOCATABLE,SAVE    ::   G1snSV(:,:)  ! Snow Dendricity/Sphericity      
+!$OMP THREADPRIVATE(G1snSV)
+      REAL,ALLOCATABLE,SAVE    ::   G2snSV(:,:)  ! Snow Sphericity/Size            
+!$OMP THREADPRIVATE(G2snSV)
+      REAL,ALLOCATABLE,SAVE    ::   dzsnSV(:,:)  ! Snow Layer  Thickness           
+!$OMP THREADPRIVATE(dzsnSV)
+      REAL,ALLOCATABLE,SAVE    ::   agsnSV(:,:)  ! Snow Age                        
+!$OMP THREADPRIVATE(agsnSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   BufsSV  ! Snow Buffer Layer               
+!$OMP THREADPRIVATE(BufsSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   rusnSV  ! Surficial   Water               
+!$OMP THREADPRIVATE(rusnSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   SWf_SV  ! Normalized  Decay               
+!$OMP THREADPRIVATE(SWf_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   SWS_SV  ! Surficial Water Status          
+!$OMP THREADPRIVATE(SWS_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   HFraSV  ! Frazil      Thickness           
+!$OMP THREADPRIVATE(HFraSV)
+                                                                            
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   zWE_SV  ! Current   Snow Thickness [mmWE] 
+!$OMP THREADPRIVATE(zWE_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   zWEcSV  ! Compacted Snow Thickness [mmWE] 
+!$OMP THREADPRIVATE(zWEcSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   wem_SV  ! Only Melting             [mmWE] 
+!$OMP THREADPRIVATE(wem_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   wer_SV  ! Refreezing               [mmWE] 
+!$OMP THREADPRIVATE(wer_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   wes_SV  ! Sublimation              [mmWE] 
+!$OMP THREADPRIVATE(wes_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   zn4_SV  ! snowheight change         [mm]
+!$OMP THREADPRIVATE(zn4_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   zn5_SV  ! snowheight change         [mm]
+!$OMP THREADPRIVATE(zn5_SV)                                                                            
+                                                                              
+! +--SISVAT OUTPUT       Variables                                            
+! +  -----------------------------                                            
+                                                                               
+      INTEGER,DIMENSION(nb_wri),SAVE ::   no__SV  ! OUTPUT file Unit Number         
+!$OMP THREADPRIVATE(no__SV)
+      INTEGER,DIMENSION(nb_wri),SAVE ::   i___SV  ! OUTPUT point   i Coordinate    
+!$OMP THREADPRIVATE(i___SV)
+      INTEGER,DIMENSION(nb_wri),SAVE ::   j___SV  ! OUTPUT point   j Coordinate     
+!$OMP THREADPRIVATE(j___SV)
+      INTEGER,DIMENSION(nb_wri),SAVE ::   n___SV  ! OUTPUT point   n Coordinate     
+!$OMP THREADPRIVATE(n___SV)
+      INTEGER,DIMENSION(nb_wri),SAVE ::   lwriSV  ! OUTPUT point vec Index          
+!$OMP THREADPRIVATE(lwriSV)
+!                                                                              
+      INTEGER, DIMENSION(:),ALLOCATABLE,SAVE ::   ii__SV  ! WORK   point   i Coordinate     
+!$OMP THREADPRIVATE(ii__SV)
+      INTEGER, DIMENSION(:),ALLOCATABLE,SAVE ::   jj__SV  ! WORK   point   j Coordinate     
+!$OMP THREADPRIVATE(jj__SV)
+      INTEGER, DIMENSION(:),ALLOCATABLE,SAVE ::   nn__SV  ! WORK   point   n Coordinate     
+!$OMP THREADPRIVATE(nn__SV)
+                                                                               
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   IRu_SV  ! UPward    IR Flux (effective)   
+!$OMP THREADPRIVATE(IRu_SV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   hSalSV  ! Saltating Layer Height          
+!$OMP THREADPRIVATE(hSalSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   qSalSV  ! Saltating Snow  Concentration   
+!$OMP THREADPRIVATE(qSalSV)
+      REAL, DIMENSION(:),ALLOCATABLE,SAVE    ::   RnofSV  ! RunOFF    Intensity             
+!$OMP THREADPRIVATE(RnofSV)
+      REAL, DIMENSION(:,:),ALLOCATABLE,SAVE    ::   RuofSV  ! RunOFF    Intensity             
+!$OMP THREADPRIVATE(RuofSV)
+
+
+
+                  
+CONTAINS
+
+
+
+  SUBROUTINE INIT_VARxSV
+  IMPLICIT NONE
+
+      INTEGER                                :: ikl
+
+      ALLOCATE(LSmask(klonv))  ! Land-Sea   Mask                 
+      ALLOCATE(isotSV(klonv))  ! Soil       Type                 
+      ALLOCATE(iWaFSV(klonv))  ! Soil       Drainage:(1,0)=(y,n)                                                                               
+      ALLOCATE(coszSV(klonv))  ! Cosine of Sun zenithal Angle    
+      ALLOCATE(sol_SV(klonv))  ! Downward  Solar    Radiation    
+      ALLOCATE(IRd_SV(klonv))  ! Downward  Longwave Radiation    
+                                                                                
+      ALLOCATE(drr_SV(klonv))  ! Rain  Intensity       [kg/m2/s] 
+      ALLOCATE(dsn_SV(klonv))  ! Snow  Intensity       [kg/m2/s] 
+      ALLOCATE(dsnbSV(klonv))  ! Idem, from Drift        [kg/m2] 
+      ALLOCATE(esnbSV(klonv))  ! Idem, from Drift        [kg/m2] 
+      ALLOCATE(dbs_SV(klonv))  ! Drift Amount            [kg/m2] 
+      ALLOCATE(dbs_er(klonv))  ! Drift erosion           [kg/m2] 
+      ALLOCATE(dbs_ac(klonv))  ! Drift accumulation      [kg/m2] 
+      ALLOCATE(BrosSV(klonv))
+      ALLOCATE(BG1sSV(klonv))          
+      ALLOCATE(BG2sSV(klonv))
+      ALLOCATE(dz0_SV(klonv))  ! dz0(Sastrugi dh)            [m] 
+                                                                               
+      ALLOCATE(cld_SV(klonv))  ! Cloudiness (seen from SBL)      
+      ALLOCATE(za__SV(klonv))  ! SBL Height                      
+      ALLOCATE(VV__SV(klonv))  !(SBL Top)  Wind Velocity         
+      ALLOCATE(VVs_SV(klonv))
+      ALLOCATE(RRs_SV(klonv))
+      ALLOCATE(DDs_SV(klonv))
+      ALLOCATE(TaT_SV(klonv))  ! SBL Top   Temperature           
+      ALLOCATE(ExnrSV(klonv))  ! Exner     Potential             
+      ALLOCATE(dSdTSV(klonv))  ! Sensible Heat Flux T Derivat.   
+      ALLOCATE(dLdTSV(klonv))  ! Latent   Heat Flux T Derivat.   
+      ALLOCATE(rhT_SV(klonv))  ! SBL Top   Air  Density          
+      ALLOCATE(QaT_SV(klonv))  ! SBL Top   Specific Humidity     
+      ALLOCATE(dQa_SV(klonv))  ! SBL Flux  Limitation of Qa      
+      ALLOCATE(qsnoSV(klonv))  ! SBL Mean  Snow       Content    
+                                                                               
+      ALLOCATE(alb0SV(klonv))  ! Soil    Albedo                  
+      ALLOCATE(slopSV(klonv))  ! Snow/Ice/Soil-Water Surf. Slope 
+
+                                                                               
+                                                                               
+! +--SISVAT INPUT/OUTPUT Variables                                             
+! +  -----------------------------                                             
+                                                                               
+      ALLOCATE(isnoSV(klonv))  ! Nb of Ice/Snow Layers           
+      ALLOCATE(ispiSV(klonv))  ! Uppermost superimposed ice      
+      ALLOCATE(iiceSV(klonv))  ! Nb of Ice      Layers           
+      ALLOCATE(istoSV(klonv,0:nsno))  ! Snow Layer     History          
+                                                                               
+      ALLOCATE(alb_SV(klonv))  ! Surface-Canopy Albedo           
+      ALLOCATE(emi_SV(klonv))  ! Surface-Canopy Emissivity       
+      ALLOCATE(IRs_SV(klonv))  ! Soil           IR Flux          
+      ALLOCATE(LMO_SV(klonv))  ! Monin-Obukhov  Scale            
+      ALLOCATE(us__SV(klonv))  ! Friction       Velocity         
+      ALLOCATE(uts_SV(klonv))  ! Temperature Turbulent Scale     
+      ALLOCATE(cutsSV(klonv))  ! Temperature Turbulent Scale C.  
+      ALLOCATE(uqs_SV(klonv))  ! Spec.Humid. Turbulent Scale     
+      ALLOCATE(uss_SV(klonv))  ! Blow.Snow   Turbulent Scale     
+      ALLOCATE(usthSV(klonv))  ! Blowing Snow Erosion Thresh.    
+      ALLOCATE(rCDmSV(klonv))  ! Square  Root Contribut. Drag_m  
+      ALLOCATE(rCDhSV(klonv))  ! Square  Root Contribut. Drag_h  
+      ALLOCATE(Z0m_SV(klonv))  ! Momentum     Roughness Length   
+      ALLOCATE(Z0mmSV(klonv))  !  z0(Momentum,    Time Mean) [m] 
+      ALLOCATE(Z0mnSV(klonv))  !  z0(Momentum,    instanta.) [m] 
+      ALLOCATE(Z0roSV(klonv))  ! Subgrid Topo Roughness Length   
+      ALLOCATE(Z0SaSV(klonv))  !  z0(Sastrugi  h)            [m] 
+      ALLOCATE(Z0e_SV(klonv))  !  z0(Snow eroded)            [m] 
+      ALLOCATE(Z0emSV(klonv))  !  z0(Snow eroded, Time Mean) [m] 
+      ALLOCATE(Z0enSV(klonv))  !  z0(Snow eroded, instanta.) [m] 
+      ALLOCATE(Z0h_SV(klonv))  !  Heat         Roughness Length   
+      ALLOCATE(Z0hmSV(klonv))  !  z0(Heat,        Time Mean) [m] 
+      ALLOCATE(Z0hnSV(klonv))  !  z0(Heat,        instanta.) [m] 
+                                                                          
+                                                                        
+      ALLOCATE(TsisSV(klonv,-nsol:nsno))  ! Snow/Ice/Soil-Water Temperature 
+      ALLOCATE(ro__SV(klonv,-nsol:nsno))  ! Snow/Ice/Soil-Water VolumicMass 
+      ALLOCATE(eta_SV(klonv,-nsol:nsno))  ! Snow/Ice/Soil     Water Content 
+      ALLOCATE(G1snSV(klonv,    0:nsno))  ! Snow Dendricity/Sphericity      
+      ALLOCATE(G2snSV(klonv,    0:nsno))  ! Snow Sphericity/Size            
+      ALLOCATE(dzsnSV(klonv,    0:nsno))  ! Snow Layer  Thickness           
+      ALLOCATE(agsnSV(klonv,    0:nsno))  ! Snow Age                        
+      ALLOCATE(BufsSV(klonv))  ! Snow Buffer Layer               
+      ALLOCATE(rusnSV(klonv))  ! Surficial   Water               
+      ALLOCATE(SWf_SV(klonv))  ! Normalized  Decay               
+      ALLOCATE(SWS_SV(klonv))  ! Surficial Water Status          
+      ALLOCATE(HFraSV(klonv))  ! Frazil      Thickness           
+                                                                            
+      ALLOCATE(zWE_SV(klonv))  ! Current   Snow Thickness [mmWE] 
+      ALLOCATE(zWEcSV(klonv))  ! Compacted Snow Thickness [mmWE] 
+      ALLOCATE(wem_SV(klonv)) ! Only Melting             [mmWE] 
+      ALLOCATE(wer_SV(klonv)) ! Refreezing               [mmWE] 
+      ALLOCATE(wes_SV(klonv))  ! Sublimation              [mmWE] 
+      ALLOCATE(zn4_SV(klonv))  ! snow height change       [mm] 
+      ALLOCATE(zn5_SV(klonv))  ! snow height change       [mm]                                                                             
+                                                                              
+! +--SISVAT OUTPUT       Variables                                            
+! +  -----------------------------                                            
+                                                                               
+!                                                                              
+      ALLOCATE(ii__SV(klonv))  ! WORK   point   i Coordinate     
+      ALLOCATE(jj__SV(klonv))  ! WORK   point   j Coordinate     
+      ALLOCATE(nn__SV(klonv))  ! WORK   point   n Coordinate     
+                                                                               
+      ALLOCATE(IRu_SV(klonv))  ! UPward    IR Flux (effective)   
+      ALLOCATE(hSalSV(klonv))  ! Saltating Layer Height          
+      ALLOCATE(qSalSV(klonv))  ! Saltating Snow  Concentration   
+      ALLOCATE(RnofSV(klonv))  ! RunOFF    Intensity      
+      ALLOCATE(RuofSV(klonv,4))  ! RunOFF    Intensity      
+
+
+      DO ikl=1,klonv        
+        LSmask(ikl)   = 0
+        isotSV(ikl)   = 0                
+        iWaFSV(ikl)   = 0 
+        isnoSV(ikl)   = 0  
+        ispiSV(ikl)   = 0
+        iiceSV(ikl)   = 0          
+        istoSV(ikl,:) = 0
+        ii__SV(ikl)   = 0
+        jj__SV(ikl)   = 0
+        nn__SV(ikl)   = 0 
+      END DO
+  END SUBROUTINE INIT_VARxSV
+
+
+                                               
+END MODULE VARxSV
Index: LMDZ6/trunk/libf/phylmd/inlandsis/VARySV.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/VARySV.F90	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/VARySV.F90	(revision 3792)
@@ -0,0 +1,120 @@
+MODULE VARySV
+
+USE VAR_SV, only : klonv, nsol, nsno
+
+
+IMPLICIT NONE
+
+! +
+      INTEGER, DIMENSION(:),SAVE,ALLOCATABLE ::   NLaysv  ! New   Snow     Layer   Switch   
+!$OMP THREADPRIVATE(NLaysv)
+      INTEGER, DIMENSION(:),SAVE,ALLOCATABLE ::   i_thin  ! Index of the thinest Layer      
+!$OMP THREADPRIVATE(i_thin)
+      INTEGER, DIMENSION(:),SAVE,ALLOCATABLE ::   LIndsv  ! Contiguous Layer relative Index
+!$OMP THREADPRIVATE(LIndsv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   albisv  ! Integrated Surface Albedo
+!$OMP THREADPRIVATE(albisv)
+      !hj prelim                                            
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   alb1sv  ! Surface Albedo VIS      
+!$OMP THREADPRIVATE(alb1sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   alb2sv  ! Surface Albedo NIR      
+!$OMP THREADPRIVATE(alb2sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   alb3sv  ! Surface Albedo FIR      
+!$OMP THREADPRIVATE(alb3sv)
+
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   albssv  ! Soil               Albedo [-]   
+!$OMP THREADPRIVATE(albssv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   SoSosv  !? Surface Absorbed Solar Radiat.  
+!$OMP THREADPRIVATE(SoSosv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   Eso_sv  !? Emissivity of       Soil+Snow   
+!$OMP THREADPRIVATE(Eso_sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   HSv_sv  ! Sensible Heat Flux  [W/m2]      
+!$OMP THREADPRIVATE(HSv_sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   HLv_sv  ! Latent   Heat Flux  [W/m2]      
+!$OMP THREADPRIVATE(HLv_sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   HSs_sv  !? Sensible Heat Flux (t)          
+!$OMP THREADPRIVATE(HSs_sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   HLs_sv  !? Latent   Heat Flux (t)          
+!$OMP THREADPRIVATE(HLs_sv) 
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   sqrCm0  ! in Neutral Drag Coef.Moment.    
+!$OMP THREADPRIVATE(sqrCm0)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   sqrCh0  ! in Neutral Drag Coef.Heat       
+!$OMP THREADPRIVATE(sqrCh0)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   Lx_H2O  ! Latent Heat of Vaporiz./Sublim. 
+!$OMP THREADPRIVATE(Lx_H2O)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   ram_sv  ! Aerodyn.Resistance (Moment.)    
+!$OMP THREADPRIVATE(ram_sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   rah_sv  ! Aerodyn.Resistance (Heat)       
+!$OMP THREADPRIVATE(rah_sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   Fh__sv  ! Stability Function              
+!$OMP THREADPRIVATE(Fh__sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   dFh_sv  ! Stability Function (Deriv.)     
+!$OMP THREADPRIVATE(dFh_sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   Evp_sv  !x Evaporation        [kg/m2]      
+!$OMP THREADPRIVATE(Evp_sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   EvT_sv  !x Evapotranspiration [kg/m2]      
+!$OMP THREADPRIVATE(EvT_sv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   LSdzsv  ! Land/Sea Vert. Discretiz. Fact. 
+!$OMP THREADPRIVATE(LSdzsv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   Tsrfsv  ! Surface    Temperature          
+!$OMP THREADPRIVATE(Tsrfsv)
+      REAL,SAVE,ALLOCATABLE  ::   sEX_sv(:,:)  ! Verticaly Integr.Extinct.Coef.  
+!$OMP THREADPRIVATE(sEX_sv)
+      REAL,SAVE,ALLOCATABLE  ::   zzsnsv(:,:)    ! Snow  Pack Thickness      [m]   
+!$OMP THREADPRIVATE(zzsnsv)
+      REAL,SAVE,ALLOCATABLE  ::   psi_sv(:,:)    ! Soil   Water        Potential   
+!$OMP THREADPRIVATE(psi_sv)
+      REAL,SAVE,ALLOCATABLE  ::   Khydsv(:,:)    ! Soil   Hydraulic    Conductiv.  
+!$OMP THREADPRIVATE(Khydsv)
+      REAL, DIMENSION(:),SAVE,ALLOCATABLE    ::   EExcsv  ! Energy in Excess, current       
+!$OMP THREADPRIVATE(EExcsv)
+
+CONTAINS
+  SUBROUTINE INIT_VARySV
+  IMPLICIT NONE
+      INTEGER                ::   ikl
+
+      ALLOCATE(NLaysv(klonv))  ! New   Snow     Layer   Switch   
+      ALLOCATE(i_thin(klonv))  ! Index of the thinest Layer      
+      ALLOCATE(LIndsv(klonv))  ! Contiguous Layer relative Index
+      ALLOCATE(albisv(klonv))  ! Integrated Surface Albedo
+      !hj prelim                                            
+      ALLOCATE(alb1sv(klonv))  ! Surface Albedo VIS      
+      ALLOCATE(alb2sv(klonv))  ! Surface Albedo NIR      
+      ALLOCATE(alb3sv(klonv))  ! Surface Albedo FIR       
+
+      !
+      ALLOCATE(albssv(klonv))  ! Soil               Albedo [-]   
+      ALLOCATE(SoSosv(klonv))  !? Surface Absorbed Solar Radiat.  
+      ALLOCATE(Eso_sv(klonv))  !? Emissivity of       Soil+Snow   
+      ALLOCATE(HSv_sv(klonv))  ! Sensible Heat Flux  [W/m2]      
+      ALLOCATE(HLv_sv(klonv))  ! Latent   Heat Flux  [W/m2]      
+      ALLOCATE(HSs_sv(klonv))  !? Sensible Heat Flux (t)          
+      ALLOCATE(HLs_sv(klonv))  !? Latent   Heat Flux (t)     
+      ALLOCATE(sqrCm0(klonv))  ! in Neutral Drag Coef.Moment.    
+      ALLOCATE(sqrCh0(klonv))  ! in Neutral Drag Coef.Heat       
+      ALLOCATE(Lx_H2O(klonv))  ! Latent Heat of Vaporiz./Sublim. 
+      ALLOCATE(ram_sv(klonv))  ! Aerodyn.Resistance (Moment.)    
+      ALLOCATE(rah_sv(klonv))  ! Aerodyn.Resistance (Heat)       
+      ALLOCATE(Fh__sv(klonv))  ! Stability Function              
+      ALLOCATE(dFh_sv(klonv))  ! Stability Function (Deriv.)     
+      ALLOCATE(Evp_sv(klonv))  !x Evaporation        [kg/m2]      
+      ALLOCATE(EvT_sv(klonv))  !x Evapotranspiration [kg/m2]      
+      ALLOCATE(LSdzsv(klonv))  ! Land/Sea Vert. Discretiz. Fact. 
+      ALLOCATE(Tsrfsv(klonv))  ! Surface    Temperature          
+      ALLOCATE(sEX_sv(klonv,-nsol:nsno+1))  ! Verticaly Integr.Extinct.Coef.  
+      ALLOCATE(zzsnsv(klonv,    0:nsno))    ! Snow  Pack Thickness      [m]   
+      ALLOCATE(psi_sv(klonv,-nsol:0   ))    ! Soil   Water        Potential   
+      ALLOCATE(Khydsv(klonv,-nsol:0   ))    ! Soil   Hydraulic    Conductiv.  
+      ALLOCATE(EExcsv(klonv))  ! Energy in Excess, current         
+
+      DO ikl=1,klonv
+        NLaysv(ikl)   = 0
+        i_thin(ikl)   = 0
+        LIndsv(ikl)   = 0
+      END DO
+
+  END SUBROUTINE INIT_VARySV
+
+END MODULE VARySV
+
Index: LMDZ6/trunk/libf/phylmd/inlandsis/inlandsis.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/inlandsis.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/inlandsis.F	(revision 3792)
@@ -0,0 +1,1239 @@
+      subroutine INLANDSIS(SnoMod,BloMod,jjtime)
+
+      USE dimphy
+
+!--------------------------------------------------------------------------+
+!     INLANDSIS module                                                     |
+!     Simplified SISVAT module, containing ice and snow processes for      |
+!     ice-covered surfaces                                                 |
+!     version MARv3, november 2020                                         |
+!     SubRoutine INLANDSIS contains the fortran 77 code of the             |
+!                Soil/Ice Snow Vegetation Atmosphere Transfer Scheme       |
+!                                                                          |
+!--------------------------------------------------------------------------+
+!     PARAMETERS:  klonv: Total Number of columns =                        |
+!     ^^^^^^^^^^        = Total Number of continental     grid boxes       |
+!                       X       Number of Mosaic Cell per grid box         |
+!                                                                          |
+!     INPUT:   daHost   : Date Host Model                                  |
+!     ^^^^^                                                                |
+!                                                                          |
+!     INPUT:   LSmask   : 1:          Land       MASK                      |
+!     ^^^^^               0:          Sea        MASK                      |
+!              isotSV   = 0,...,12:   Soil       Type                      |
+!                         0:          Water,          Liquid (Sea, Lake)   |
+!                        12:          Water, Solid           (Ice)         |
+!                                                                          |
+!     INPUT:   coszSV   : Cosine of the Sun Zenithal Distance          [-] |
+!     ^^^^^    sol_SV   : Surface Downward  Solar      Radiation    [W/m2] |
+!              IRd_SV   : Surface Downward  Longwave   Radiation    [W/m2] |
+!              drr_SV   : Rain  Intensity                        [kg/m2/s] |
+!              dsn_SV   : Snow  Intensity                      [mm w.e./s] |
+!              dsnbSV   : Snow  Intensity,  Drift Fraction             [-] |
+!              dbs_SV   : Drift Amount                           [mm w.e.] |
+!              za__SV   : Surface Boundary Layer (SBL) Height          [m] |
+!              VV__SV   :(SBL Top)   Wind Velocity                   [m/s] |
+!              TaT_SV   : SBL Top    Temperature                       [K] |
+!              rhT_SV   : SBL Top    Air  Density                  [kg/m3] |
+!              QaT_SV   : SBL Top    Specific  Humidity            [kg/kg] |
+!              qsnoSV   : SBL Mean   Snow      Content             [kg/kg] |
+!              alb0SV   : Soil Basic Albedo                            [-] |
+!              slopSV   : Surface    Slope                             [-] |
+!              dt__SV   : Time  Step                                   [s] |
+!                                                                          |
+!     INPUT /  isnoSV   = total Nb of Ice/Snow Layers                      |
+!     OUTPUT:  ispiSV   = 0,...,nsno: Uppermost Superimposed Ice Layer     |
+!     ^^^^^^   iiceSV   = total Nb of Ice      Layers                      |
+!              istoSV   = 0,...,5 :   Snow     History (see istdSV data)   |
+!                                                                          |
+!     INPUT /  alb_SV   : Surface        Albedo                        [-] |
+!     OUTPUT:  emi_SV   : Surface        Emissivity                    [-] |
+!     ^^^^^^   IRs_SV   : Soil           IR Flux  (negative)        [W/m2] |
+!              LMO_SV   : Monin-Obukhov               Scale            [m] |
+!              us__SV   : Friction          Velocity                 [m/s] |
+!              uts_SV   : Temperature       Turbulent Scale          [m/s] |
+!              uqs_SV   : Specific Humidity Velocity                 [m/s] |
+!              uss_SV   : Blowing Snow      Turbulent Scale          [m/s] |
+!              usthSV   : Blowing Snow      Erosion   Threshold      [m/s] |
+!              Z0m_SV   : Momentum     Roughness Length                [m] |
+!              Z0mmSV   : Momentum     Roughness Length (time mean)    [m] |
+!              Z0mnSV   : Momentum     Roughness Length (instantaneous)[m] |
+!              Z0SaSV   : Sastrugi     Roughness Length                [m] |
+!              Z0e_SV   : Erosion Snow Roughness Length                [m] |
+!              Z0emSV   : Erosion Snow Roughness Length (time mean)    [m] |
+!              Z0enSV   : Erosion Snow Roughness Length (instantaneous)[m] |
+!              Z0roSV   : Subgrid Topo Roughness Length                [m] |
+!              Z0h_SV   : Heat         Roughness Length                [m] |
+!              TsisSV   : Soil/Ice Temperatures (layers -nsol,-nsol+1,..,0)|
+!                       & Snow     Temperatures (layers  1,2,...,nsno) [K] |
+!              ro__SV   : Soil/Snow Volumic Mass                   [kg/m3] |
+!              eta_SV   : Soil/Snow Water   Content                [m3/m3] |
+!              G1snSV   : snow dendricity/sphericity                       |
+!              G2snSV   : snow sphericity/grain size                       |
+!              dzsnSV   : Snow Layer        Thickness                  [m] |
+!              agsnSV   : Snow       Age                             [day] |
+!              BufsSV   : Snow Buffer Layer              [kg/m2] .OR. [mm] |
+!              BrosSV   : Snow Buffer Layer Density      [kg/m3]           |
+!              BG1sSV   : Snow Buffer Layer Dendricity / Sphericity    [-] |
+!              BG2sSV   : Snow Buffer Layer Sphericity / Size [-] [0.1 mm] |
+!              rusnSV   : Surficial   Water              [kg/m2] .OR. [mm] |
+!                                                                          |
+!     OUTPUT:  no__SV   : OUTPUT file Unit Number                      [-] |
+!     ^^^^^^   i___SV   : OUTPUT point   i Coordinate                  [-] |
+!              j___SV   : OUTPUT point   j Coordinate                  [-] |
+!              n___SV   : OUTPUT point   n Coordinate                  [-] |
+!              lwriSV   : OUTPUT point vec Index                       [-] |
+!                                                                          |
+!     OUTPUT:  IRu_SV   : Upward     IR Flux (+, upw., effective)      [K] |
+!     ^^^^^^   hSalSV   : Saltating Layer Height                       [m] |
+!              qSalSV   : Saltating Snow  Concentration            [kg/kg] |
+!              RnofSV   : RunOFF Intensity                       [kg/m2/s] |
+!                                                                          |
+!     Internal Variables:                                                  |
+!     ^^^^^^^^^^^^^^^^^^                                                   |
+!              NLaysv   = New            Snow Layer Switch             [-] |
+!              albisv   : Snow/Ice/Water/Soil Integrated Albedo        [-] |
+!              SoSosv   : Absorbed Solar Radiation by Surfac.(Normaliz)[-] |
+!              TBr_sv   : Brightness Temperature                       [K] |
+!              IRupsv   : Upward     IR Flux (-, upw.)              [W/m2] |
+!              ram_sv   : Aerodynamic Resistance for Momentum        [s/m] |
+!              rah_sv   : Aerodynamic Resistance for Heat            [s/m] |
+!              Evp_sv   : Evaporation                              [kg/m2] |
+!              EvT_sv   : Evapotranspiration                       [kg/m2] |
+!              HSs_sv   : Surface    Sensible Heat Flux + => absorb.[W/m2] |
+!              HLs_sv   : Surface    Latent   Heat Flux + => absorb.[W/m2] |
+!              Lx_H2O   : Latent Heat of Vaporization/Sublimation   [J/kg] |
+!              Tsrfsv   : Surface    Temperature                       [K] |
+!              sEX_sv   : Verticaly Integrated Extinction Coefficient  [-] |
+!              LSdzsv   : Vertical   Discretization Factor             [-] |
+!                       =    1. Soil                                       |
+!                       = 1000. Ocean                                      |
+!              z_snsv   : Snow Pack  Thickness                         [m] |
+!              zzsnsv   : Snow Pack  Thickness                         [m] |
+!              albssv   : Soil       Albedo                            [-] |
+!              Eso_sv   : Soil+Snow       Emissivity                   [-] |
+!              Khydsv   : Soil   Hydraulic    Conductivity           [m/s] |
+!                                                                          |
+!              ETSo_0   : Snow/Soil Energy Power, before Forcing    [W/m2] |
+!              ETSo_1   : Snow/Soil Energy Power, after  Forcing    [W/m2] |
+!              ETSo_d   : Snow/Soil Energy Power         Forcing    [W/m2] |
+!              EqSn_0   : Snow      Energy, before Phase Change     [J/m2] |
+!              EqSn_1   : Snow      Energy, after  Phase Change     [J/m2] |
+!              EqSn_d   : Snow      Energy,       net    Forcing    [J/m2] |
+!              Enrsvd   : SVAT      Energy Power         Forcing    [W/m2] |
+!              Enrbal   : SVAT      Energy Balance                  [W/m2] |
+!              Wats_0   : Soil Water,  before Forcing                 [mm] |
+!              Wats_1   : Soil Water,  after  Forcing                 [mm] |
+!              Wats_d   : Soil Water          Forcing                 [mm] |
+!              SIWm_0   : Snow        initial Mass               [mm w.e.] |
+!              SIWm_1   : Snow        final   Mass               [mm w.e.] |
+!              SIWa_i   : Snow Atmos. initial Forcing            [mm w.e.] |
+!              SIWa_f   : Snow Atmos. final   Forcing(noConsumed)[mm w.e.] |
+!              SIWe_i   : SnowErosion initial Forcing            [mm w.e.] |
+!              SIWe_f   : SnowErosion final   Forcing(noConsumed)[mm w.e.] |
+!              SIsubl   : Snow sublimed/deposed  Mass            [mm w.e.] |
+!              SImelt   : Snow Melted            Mass            [mm w.e.] |
+!              SIrnof   : Surficial Water + Run OFF Change       [mm w.e.] |
+!              SIvAcr   : Sea-Ice    vertical Acretion           [mm w.e.] |
+!              Watsvd   : SVAT Water          Forcing                 [mm] |
+!              Watbal   : SVAT Water  Balance                       [W/m2] |
+!                                                                          |
+!              vk2      : Square of Von Karman Constant                [-] |
+!              sqrCm0   : Factor of   Neutral Drag Coeffic.Momentum  [s/m] |
+!              sqrCh0   : Factor of   Neutral Drag Coeffic.Heat      [s/m] |
+!              EmiSol   : Soil          Emissivity                     [-] |
+!              EmiSno   : Snow          Emissivity                     [-] |
+!              EmiWat   : Water         Emissivity                     [-] |
+!              Z0mLnd   :          Land Roughness Length               [m] |
+!              sqrrZ0   : u*t/u*                                           |
+!              f_eff    : Marticorena & B. 1995 JGR (20)                   |
+!              A_Fact   : Fundamental * Roughness                          |
+!              Z0mBSn   :         BSnow Roughness Length               [m] |
+!              Z0mBS0   : Mimimum BSnow Roughness Length (blown* )     [m] |
+!              Z0m_Sn   :          Snow Roughness Length (surface)     [m] |
+!              Z0m_S0   : Mimimum  Snow Roughness Length               [m] |
+!              Z0m_S1   : Maximum  Snow Roughness Length               [m] |
+!              Z0_GIM   : Minimum GIMEX Roughness Length               [m] |
+!              Z0_ICE   : Sea Ice ISW   Roughness Length               [m] |
+!                                                                          |
+!                                                                          |
+!--------------------------------------------------------------------------+
+     
+
+
+! Global Variables
+! ================
+
+
+      USE VARphy
+      USE VAR_SV
+      USE VARdSV
+      USE VAR0SV
+      USE VARxSV
+      USE VARySV
+      USE VARtSV
+      USE surface_data, only: iflag_tsurf_inlandsis
+
+
+      IMPLICIT NONE
+
+      logical   SnoMod
+      logical   BloMod
+      integer   jjtime
+
+
+! Internal Variables
+! ==================
+
+! Non Local
+! ---------
+
+      real      TBr_sv(klonv)                 ! Brightness Temperature
+      real      IRdwsv(klonv)                 ! DOWNward   IR Flux
+      real      IRupsv(klonv)                 ! UPward     IR Flux
+      real      d_Bufs,Bufs_N                 ! Buffer Snow Layer Increment
+      real      Buf_ro,Bros_N                 ! Buffer Snow Layer Density
+      real      BufPro                        ! Buffer Snow Layer Density
+      real      Buf_G1,BG1__N                 ! Buffer Snow Layer Dendr/Sphe[-]
+      real      Buf_G2,BG2__N                 ! Buffer Snow Layer Spher/Size[-]
+      real      Bdzssv(klonv)                 ! Buffer Snow Layer Thickness
+      real      z_snsv(klonv)                 ! Snow-Ice, current Thickness
+
+
+
+! Local
+! -----
+
+      integer   iwr
+      integer   ikl   ,isn   ,isl   ,ist      !
+      integer   ist__s,ist__w                 ! Soil/Water Body Identifier
+      integer   growth                        ! Seasonal               Mask
+      integer   LISmsk                        ! Land+Ice / Open    Sea Mask
+      integer   LSnMsk                        ! Snow-Ice / No Snow-Ice Mask
+      integer   IceMsk,IcIndx(klonv)          !      Ice / No      Ice Mask
+      integer   SnoMsk                        ! Snow     / No Snow     Mask
+
+      real      roSMin,roSMax,roSn_1,roSn_2,roSn_3   ! Fallen Snow Density (PAHAUT)
+      real      Dendr1,Dendr2,Dendr3          ! Fallen Snow Dendric.(GIRAUD)
+      real      Spher1,Spher2,Spher3,Spher4   ! Fallen Snow Spheric.(GIRAUD)
+      real      Polair                        ! Polar  Snow Switch
+      real      PorSno,Por_BS,Salt_f,PorRef   !
+c #sw real      PorVol,rWater                 !
+c #sw real      rusNEW,rdzNEW,etaNEW          !
+      real      ro_new                        !
+      real      TaPole                        ! Maximum     Polar Temperature
+      real      T__Min                        ! Minimum realistic Temperature
+      real      EmiSol                        ! Emissivity of       Soil
+      real      EmiSno                        ! Emissivity of            Snow
+      real      EmiWat                        ! Emissivity of a Water Area
+      real      vk2                           ! Square of Von Karman Constant
+      real      u2star                        !(u*)**2
+      real      Z0mLnd                        !          Land Roughness Length
+c #ZN real      sqrrZ0                        ! u*t/u*
+      real      f_eff                         ! Marticorena & B. 1995 JGR (20)
+      real      A_Fact                        ! Fundamental * Roughness
+      real      Z0m_nu                        ! Smooth R Snow Roughness Length
+      real      Z0mBSn                        !         BSnow Roughness Length
+      real      Z0mBS0                        ! Mimimum BSnow Roughness Length
+      real      Z0m_S0                        ! Mimimum  Snow Roughness Length
+      real      Z0m_S1                        ! Maximum  Snow Roughness Length
+c #SZ real      Z0Sa_N                        ! Regime   Snow Roughness Length
+c #SZ real      Z0SaSi                        ! 1.IF Rgm Snow Roughness Length 
+c #GL real      Z0_GIM                        ! Mimimum GIMEX Roughness Length
+      real      Z0_ICE                        ! Ice ISW   Roughness Length
+      real      Z0m_Sn,Z0m_90                 ! Snow  Surface Roughness Length
+      real      SnoWat                        ! Snow Layer    Switch
+c #RN real      rstar,alors                   !
+c #RN real      rstar0,rstar1,rstar2          !
+      real      SameOK                        ! 1. => Same Type of Grains
+      real      G1same                        ! Averaged G1,  same Grains
+      real      G2same                        ! Averaged G2,  same Grains
+      real      typ__1                        ! 1. => Lay1 Type: Dendritic
+      real      zroNEW                        ! dz X ro, if fresh Snow
+      real      G1_NEW                        ! G1,      if fresh Snow
+      real      G2_NEW                        ! G2,      if fresh Snow
+      real      zroOLD                        ! dz X ro, if old   Snow
+      real      G1_OLD                        ! G1,      if old   Snow
+      real      G2_OLD                        ! G2,      if old   Snow
+      real      SizNEW                        ! Size,    if fresh Snow
+      real      SphNEW                        ! Spheric.,if fresh Snow
+      real      SizOLD                        ! Size,    if old   Snow
+      real      SphOLD                        ! Spheric.,if old   Snow
+      real      Siz_av                        ! Averaged    Grain Size
+      real      Sph_av                        ! Averaged    Grain Spher.
+      real      Den_av                        ! Averaged    Grain Dendr.
+      real      DendOK                        ! 1. => Average is  Dendr.
+      real      G1diff                        ! Averaged G1, diff. Grains
+      real      G2diff                        ! Averaged G2, diff. Grains
+      real      G1                            ! Averaged G1
+      real      G2                            ! Averaged G2
+      real      param                         ! Polynomial   fit z0=f(T)
+      real      Z0_obs                        ! Fit Z0_obs=f(T) (m)
+      real      tamin                         ! min T of linear fit (K)
+      real      tamax                         ! max T of linear fit (K)
+      real      coefa,coefb,coefc,coefd       ! Coefs for z0=f(T)
+      real      ta1,ta2,ta3                   ! Air temperature thresholds
+      real      z01,z02,z03                   ! z0 thresholds
+      real      tt_c,vv_c                     ! Critical param.
+      real      tt_tmp,vv_tmp,vv_virt         ! Temporary variables
+      logical   density_kotlyakov             ! .true. if Kotlyakov 1961
+      real      e_prad,e1pRad,A_Rad0,absg_V,absgnI,exdRad ! variables for SoSosv calculations
+      real      zm1, zm2, coefslope                    ! variables for surface temperature extrapolation
+
+
+
+! Internal DATA
+! =============
+
+      data      T__Min / 200.00/              ! Minimum realistic Temperature
+      data      TaPole / 263.15/              ! Maximum Polar     Temperature
+      data      roSMin /  30.  /              ! Minimum Snow  Density
+      data      roSMax / 400.  /              ! Max Fresh Snow Density
+      data      tt_c   / -2.0  /              ! Critical Temp. (degC)
+      data      vv_c   / 14.3  /              ! Critical Wind speed (m/s)
+      data      roSn_1 / 109.  /              ! Fall.Sno.Density, Indep. Param.
+      data      roSn_2 /   6.  /              ! Fall.Sno.Density, Temper.Param.
+      data      roSn_3 /  26.  /              ! Fall.Sno.Density, Wind   Param.
+      data      Dendr1 /  17.12/              ! Fall.Sno.Dendric.,Wind 1/Param.
+      data      Dendr2 / 128.  /              ! Fall.Sno.Dendric.,Wind 2/Param.
+      data      Dendr3 / -20.  /              ! Fall.Sno.Dendric.,Indep. Param.
+      data      Spher1 /   7.87/              ! Fall.Sno.Spheric.,Wind 1/Param.
+      data      Spher2 /  38.  /              ! Fall.Sno.Spheric.,Wind 2/Param.
+      data      Spher3 /  50.  /              ! Fall.Sno.Spheric.,Wind 3/Param.
+      data      Spher4 /  90.  /              ! Fall.Sno.Spheric.,Indep. Param.
+      data      EmiSol /   0.99999999/        ! 0.94Emissivity of Soil
+      data      EmiWat /   0.99999999/        ! Emissivity of a Water Area
+      data      EmiSno /   0.99999999/        ! Emissivity of Snow
+      
+!     DATA      Emissivities                  ! Pielke, 1984, pp. 383,409
+
+      data      Z0mBS0 /   0.5e-6/            ! MINimum Snow Roughness Length 
+                                              ! for Momentum if Blowing Snow
+                                              ! Gallee et al. 2001 BLM 99 (19)
+      data      Z0m_S0/    0.00005/           ! MINimum Snow Roughness Length
+                                              ! MegaDunes    included
+      data      Z0m_S1/    0.030  /           ! MAXimum Snow Roughness Length
+                                              !        (Sastrugis)
+c #GL data      Z0_GIM/    0.0013/            ! Ice Min Z0 = 0.0013 m (Broeke)
+!                                             ! Old Ice Z0 = 0.0500 m (Bruce)
+!                                             !              0.0500 m (Smeets)
+!                                             !              0.1200 m (Broeke)
+      data      Z0_ICE/    0.0010/            ! Sea-Ice Z0 = 0.0010 m (Andreas)
+!                                             !    (Ice Station Weddel -- ISW)
+      vk2    =  vonKrm  *  vonKrm             ! Square of Von Karman Constant
+
+
+! BEGIN.main.
+! ===========================
+
+
+
+
+! "Soil" Humidity of Water Bodies
+! ===============================
+
+      DO ikl=1,knonv
+
+          ist    =      isotSV(ikl)                       ! Soil Type
+          ist__s =  min(ist, 1)                           ! 1 => Soil
+          ist__w =  1 - ist__s                            ! 1 => Water Body
+        DO isl=-nsol,0
+          eta_SV(ikl,isl) = eta_SV(ikl,isl) * ist__s      ! Soil 
+     .                    + etadSV(ist)     * ist__w      ! Water Body
+        END DO
+
+
+! Vertical Discretization Factor
+! ==============================
+
+          LSdzsv(ikl)     =                   ist__s      ! Soil
+     .                    + OcndSV          * ist__w      ! Water Body
+      END DO
+
+
+! Blowing Particles Threshold Friction velocity
+! =============================================
+
+c #AE       usthSV(ikl) =                     1.0e+2
+!          END DO
+!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+
+
+
+
+! Contribution of Snow to the Surface Snow Pack
+! =============================================
+
+      IF (SnoMod)                                                 THEN
+
+
+ 
+C +--Blowing Snow
+C +  ------------
+ 
+        IF (BloMod) then
+         if (klonv.eq.1) then
+          if(isnoSV(1).ge.2                   .and.
+     .       TsisSV(1,max(1,isnoSV(1)))<273.  .and.
+     .       ro__SV(1,max(1,isnoSV(1)))<500.  .and.
+     .       eta_SV(1,max(1,isnoSV(1)))<epsi) then
+C +                       **********
+                     call SISVAT_BSn
+          endif
+         else
+                     call SISVAT_BSn
+C +                       **********
+         endif
+        ENDIF
+ 
+
+
+C +--Buffer Layer
+C +  ------------
+ 
+          DO ikl=1,knonv
+c  BufsSV(ikl) [mm w.e.] i.e, i.e., [kg/m2]
+            d_Bufs      =  max(dsn_SV(ikl) *dt__SV,0.)  !
+            dsn_SV(ikl) =      0.                       !
+            Bufs_N      =      BufsSV(ikl) +d_Bufs      !
+ 
+ 
+C +--Snow Density
+C +  ^^^^^^^^^^^^
+            Polair      =      zero
+c #NP       Polair      =  max(zero,                    !
+c #NP.                         sign(unun,TaPole         !
+c #NP.                                  -TaT_SV(ikl)))  !
+            Polair      =  max(zero,                    !
+     .                         sign(unun,TaPole         !
+     .                                  -TaT_SV(ikl)))  !
+            Buf_ro      =  max( rosMin,                 ! Fallen Snow Density
+     .      roSn_1+roSn_2*     (TaT_SV(ikl)-TfSnow)     ! [kg/m3]
+     .            +roSn_3*sqrt( VV__SV(ikl)))           ! Pahaut    (CEN), Etienne: use wind speed at first model level instead of 10m wind
+c #NP       BufPro      =  max( rosMin,                 ! Fallen Snow Density
+c #NP.         104. *sqrt( max( VV10SV(ikl)-6.0,0.0)))  ! Kotlyakov (1961)
+ 
+            density_kotlyakov = .true.
+c #AC       density_kotlyakov = .false.  !C.Agosta snow densisty as if BS is on b
+c #BS       density_kotlyakov = .false.  !C.Amory BS 2018
+C + ...     Fallen Snow Density, Adapted for Antarctica
+            if (density_kotlyakov) then
+                tt_tmp = TaT_SV(ikl)-TfSnow
+                !vv_tmp = VV10SV(ikl)
+                vv_tmp=VV__SV(ikl) ! Etienne: use wind speed at first model level instead of 10m wind
+C + ...         [ A compromise between
+C + ...           Kotlyakov (1961) and Lenaerts (2012, JGR, Part1) ]
+                if (tt_tmp.ge.-10) then
+                  BufPro   =  max( rosMin,
+     .            104. *sqrt( max( vv_tmp-6.0,0.0))) ! Kotlyakov (1961)
+                else
+                  vv_virt = (tt_c*vv_tmp+vv_c*(tt_tmp+10))
+     .                     /(tt_c+tt_tmp+10)
+                  BufPro  = 104. *sqrt( max( vv_virt-6.0,0.0))
+                endif
+            else
+C + ...         [ density derived from observations of the first 50cm of
+C + ...           snow - cf. Rajashree Datta - and multiplied by 0.8 ]
+C + ...           C. Agosta, 2016-09
+cc #SD           BufPro = 149.2 + 6.84*VV10SV(ikl) + 0.48*Tsrfsv(ikl)
+cc #SD           BufPro = 125 + 14*VV10SV(ikl) + 0.6*Tsrfsv(ikl) !MAJ CK and CAm
+!                BufPro = 200 + 21 * VV10SV(ikl)!CK 29/07/19
+                 BufPro = 200 + 21 * VV__SV(ikl)!Etienne: use wind speed at first model level instead of 10m wind
+            endif
+ 
+            Bros_N      = (1. - Polair) *   Buf_ro      ! Temperate Snow
+     .                        + Polair  *   BufPro      ! Polar     Snow
+ 
+            Bros_N = max( 20.,max(rosMin,  Bros_N))
+            Bros_N = min(400.,min(rosMax-1,Bros_N)) ! for dz_min in SISVAT_zSn
+ 
+ 
+!    Density of deposited blown snow
+!    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ 
+c #BS       Bros_N      = frsno
+c #BS       ro_new      = ro__SV(ikl,max(1,isnoSV(ikl)))
+c #BS       ro_new      = max(Bros_N,min(roBdSV,ro_new))
+c #BS       Fac         = 1-((ro__SV(ikl,max(1,isnoSV(ikl)))
+c #BS.                     -roBdSV)/(500.-roBdSV))
+c #BS       Fac         = max(0.,min(1.,Fac))
+c #BS       dsnbSV(ikl) = Fac*dsnbSV(ikl)
+c #BS       Bros_N      = Bros_N     * (1.0-dsnbSV(ikl))
+c #BS.                  + ro_new     *      dsnbSV(ikl)
+
+
+ 
+!    Time averaged Density of deposited blown Snow
+!    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+           
+            BrosSV(ikl) =(Bros_N     *      d_Bufs      !
+     .                   +BrosSV(ikl)*      BufsSV(ikl))!
+     .                   /         max(epsi,Bufs_N)     !
+ 
+ 
+C +-- S.Falling Snow Properties (computed as in SISVAT_zAg)
+C +     ^^^^^^^^^^^^^^^^^^^^^^^
+            Buf_G1      =  max(-G1_dSV,                 ! Temperate Snow
+     .               min(Dendr1*VV__SV(ikl)-Dendr2,     !     Dendricity
+     .                   Dendr3                   ))    !
+            Buf_G2      =  min( Spher4,                 ! Temperate Snow
+     .               max(Spher1*VV__SV(ikl)+Spher2,     !     Sphericity
+     .                   Spher3                   ))    !
+            Buf_G1      = (1. - Polair) *   Buf_G1      ! Temperate Snow
+     .                        + Polair  *   G1_dSV      ! Polar     Snow
+            Buf_G2      = (1. - Polair) *   Buf_G2      ! Temperate Snow
+     .                        + Polair  *   ADSdSV      ! Polar     Snow
+                G1      =                   Buf_G1      ! NO  Blown Snow
+                G2      =                   Buf_G2      ! NO  Blown Snow
+
+ 
+!     S.1. Meme  Type  de Neige  / same Grain Type
+!          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+c #BS       SameOK  =  max(zero,
+c #BS.                     sign(unun,    Buf_G1             *G1_dSV
+c #BS.                                 - eps_21                    ))
+c #BS       G1same  = ((1.0-dsnbSV(ikl))*Buf_G1+dsnbSV(ikl) *G1_dSV)
+c #BS       G2same  = ((1.0-dsnbSV(ikl))*Buf_G2+dsnbSV(ikl) *ADSdSV)
+!           Blowing Snow Properties:                         G1_dSV, ADSdSV
+ 
+!     S.2. Types differents / differents Types
+!          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+c #BS       typ__1  =  max(zero,sign(unun,epsi-Buf_G1))   ! =1.=> Dendritic
+c #BS       zroNEW  =     typ__1  *(1.0-dsnbSV(ikl))      ! fract.Dendr.Lay.
+c #BS.              + (1.-typ__1) *     dsnbSV(ikl)       !
+c #BS       G1_NEW  =     typ__1  *Buf_G1                 ! G1 of Dendr.Lay.
+c #BS.              + (1.-typ__1) *G1_dSV                 !
+c #BS       G2_NEW  =     typ__1  *Buf_G2                 ! G2 of Dendr.Lay.
+c #BS.              + (1.-typ__1) *ADSdSV                 !
+c #BS       zroOLD  = (1.-typ__1) *(1.0-dsnbSV(ikl))      ! fract.Spher.Lay.
+c #BS.              +     typ__1  *     dsnbSV(ikl)       !
+c #BS       G1_OLD  = (1.-typ__1) *Buf_G1                 ! G1 of Spher.Lay.
+c #BS.              +     typ__1  *G1_dSV                 !
+c #BS       G2_OLD  = (1.-typ__1) *Buf_G2                 ! G2 of Spher.Lay.
+c #BS.              +     typ__1  *ADSdSV                 !
+c #BS       SizNEW  =    -G1_NEW  *DDcdSV/G1_dSV          ! Size  Dendr.Lay.
+c #BS.               +(1.+G1_NEW         /G1_dSV)         !
+c #BS.                  *(G2_NEW  *DScdSV/G1_dSV          !
+c #BS.               +(1.-G2_NEW         /G1_dSV)*DFcdSV) !
+c #BS       SphNEW  =     G2_NEW         /G1_dSV          ! Spher.Dendr.Lay.
+c #BS       SizOLD  =     G2_OLD                          ! Size  Spher.Lay.
+c #BS       SphOLD  =     G1_OLD         /G1_dSV          ! Spher.Spher.Lay.
+c #BS       Siz_av =     (zroNEW*SizNEW+zroOLD*SizOLD)    ! Averaged Size
+c #BS       Sph_av = min( zroNEW*SphNEW+zroOLD*SphOLD     !
+c #BS.                   ,  unun)                         ! Averaged Sphericity
+c #BS       Den_av = min((Siz_av -(    Sph_av *DScdSV     !
+c #BS.                            +(1.-Sph_av)*DFcdSV))   !
+c #BS.                 / (DDcdSV -(    Sph_av *DScdSV     !
+c #BS.                            +(1.-Sph_av)*DFcdSV))   !
+c #BS.                   ,  unun)                         !
+c #BS       DendOK  = max(zero,                           !
+c #BS.                    sign(unun,     Sph_av *DScdSV   ! Small   Grains
+c #BS.                              +(1.-Sph_av)*DFcdSV   ! Faceted Grains
+c #BS.                              -    Siz_av        )) !
+C +...      REMARQUE: le  type moyen (dendritique ou non) depend
+C +         ^^^^^^^^  de la  comparaison avec le diametre optique
+C +                   d'une neige recente de   dendricite nulle
+C +...      REMARK:   the mean type  (dendritic   or not) depends
+C +         ^^^^^^    on the comparaison with the optical diameter
+C +                   of a recent snow    having zero dendricity
+ 
+c #BS       G1diff  =(   -DendOK *Den_av
+c #BS.               +(1.-DendOK)*Sph_av) *G1_dSV
+c #BS       G2diff  =     DendOK *Sph_av  *G1_dSV
+c #BS.               +(1.-DendOK)*Siz_av
+c #BS       G1      =     SameOK *G1same
+c #BS.               +(1.-SameOK)*G1diff
+c #BS       G2      =     SameOK *G2same
+c #BS.               +(1.-SameOK)*G2diff
+ 
+
+ 
+!     S.1. Meme  Type  de Neige  / same Grain Type
+!          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+            SameOK  =  max(zero,
+     .                     sign(unun,    Buf_G1 *BG1sSV(ikl)
+     .                                 - eps_21                    ))
+            G1same  = (d_Bufs*Buf_G1+BufsSV(ikl)*BG1sSV(ikl))
+     .                     /max(epsi,Bufs_N)
+            G2same  = (d_Bufs*Buf_G2+BufsSV(ikl)*BG2sSV(ikl))
+     .                     /max(epsi,Bufs_N)
+ 
+!     S.2. Types differents / differents Types
+!          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+            typ__1  =  max(zero,sign(unun,epsi-Buf_G1))   ! =1.=> Dendritic
+            zroNEW  =(    typ__1  *d_Bufs                 ! fract.Dendr.Lay.
+     .              + (1.-typ__1) *BufsSV(ikl))           !
+     .                   /max(epsi,Bufs_N)                !
+            G1_NEW  =     typ__1  *Buf_G1                 ! G1 of Dendr.Lay.
+     .              + (1.-typ__1) *BG1sSV(ikl)            !
+            G2_NEW  =     typ__1  *Buf_G2                 ! G2 of Dendr.Lay.
+     .              + (1.-typ__1) *BG2sSV(ikl)            !
+            zroOLD  =((1.-typ__1) *d_Bufs                 ! fract.Spher.Lay.
+     .              +     typ__1  *BufsSV(ikl))           !
+     .                   /max(epsi,Bufs_N)                !
+            G1_OLD  = (1.-typ__1) *Buf_G1                 ! G1 of Spher.Lay.
+     .              +     typ__1  *BG1sSV(ikl)            !
+            G2_OLD  = (1.-typ__1) *Buf_G2                 ! G2 of Spher.Lay.
+     .              +     typ__1  *BG2sSV(ikl)            !
+            SizNEW  =    -G1_NEW  *DDcdSV/G1_dSV          ! Size  Dendr.Lay.
+     .               +(1.+G1_NEW         /G1_dSV)         !
+     .                  *(G2_NEW  *DScdSV/G1_dSV          !
+     .               +(1.-G2_NEW         /G1_dSV)*DFcdSV) !
+            SphNEW  =     G2_NEW         /G1_dSV          ! Spher.Dendr.Lay.
+            SizOLD  =     G2_OLD                          ! Size  Spher.Lay.
+            SphOLD  =     G1_OLD         /G1_dSV          ! Spher.Spher.Lay.
+            Siz_av  =   ( zroNEW  *SizNEW+zroOLD*SizOLD)  ! Averaged Size
+            Sph_av = min( zroNEW  *SphNEW+zroOLD*SphOLD   !
+     .                  ,   unun                       )  ! Averaged Sphericity
+            Den_av = min((Siz_av  - (    Sph_av *DScdSV   !
+     .                              +(1.-Sph_av)*DFcdSV)) !
+     .                 / (DDcdSV  - (    Sph_av *DScdSV   !
+     .                              +(1.-Sph_av)*DFcdSV)) !
+     .                  ,   unun                         )!
+            DendOK  = max(zero,                           !
+     .                    sign(unun,     Sph_av *DScdSV   ! Small   Grains
+     .                              +(1.-Sph_av)*DFcdSV   ! Faceted Grains
+     .                              -    Siz_av        )) !
+C +...      REMARQUE: le  type moyen (dendritique ou non) depend
+C +         ^^^^^^^^  de la  comparaison avec le diametre optique
+C +                   d'une neige recente de   dendricite nulle
+C +...      REMARK:   the mean type  (dendritic   or not) depends
+C +         ^^^^^^    on the comparaison with the optical diameter
+C +                   of a recent snow    having zero dendricity
+ 
+            G1diff  =(   -DendOK *Den_av
+     .               +(1.-DendOK)*Sph_av) *G1_dSV
+            G2diff  =     DendOK *Sph_av  *G1_dSV
+     .               +(1.-DendOK)*Siz_av
+            G1      =     SameOK *G1same
+     .               +(1.-SameOK)*G1diff
+            G2      =     SameOK *G2same
+     .               +(1.-SameOK)*G2diff
+ 
+            BG1sSV(ikl) =                       G1      !
+     .                  *       Bufs_N/max(epsi,Bufs_N) !
+            BG2sSV(ikl) =                       G2      !
+     .                  *       Bufs_N/max(epsi,Bufs_N) !
+ 
+
+C +--Update of Buffer Layer Content & Decision about creating a new snow layer
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+            BufsSV(ikl) =       Bufs_N                  !     [mm w.e.]
+            NLaysv(ikl) = min(unun,                     !
+     .                    max(zero,                     ! Allows to create
+     .                        sign(unun,BufsSV(ikl)     ! a new snow Layer
+     .                                 -SMndSV     ))   ! if Buffer > SMndSV
+     .                   *max(zero,                     ! Except if * Erosion
+     .                        sign(unun,0.50            ! dominates
+     .                                 -dsnbSV(ikl)))   !
+     .                   +max(zero,                     ! Allows to create
+     .                        sign(unun,BufsSV(ikl)     ! a new snow Layer
+     .                                 -SMndSV*3.00)))  ! is Buffer > SMndSV*3
+            Bdzssv(ikl) = 1.e-3*BufsSV(ikl)*ro_Wat      ! [mm w.e.] -> [m w.e.]
+     .                            /max(epsi,BrosSV(ikl))!& [m w.e.] -> [m]
+ 
+
+ 
+          END DO
+ 
+
+
+! Snow Pack Discretization
+! ========================
+
+!            **********
+        call SISVAT_zSn
+!            **********
+
+!            **********
+! #ve   call SISVAT_wEq('_zSn  ',0)
+!            **********
+
+
+
+! Add a new Snow Layer
+! ====================
+
+          DO ikl=1,knonv
+
+            isnoSV(ikl)     = isnoSV(ikl)         +NLaysv(ikl)
+            isn             = isnoSV(ikl)
+            dzsnSV(ikl,isn) = dzsnSV(ikl,isn) * (1-NLaysv(ikl))
+     .                      + Bdzssv(ikl)     *    NLaysv(ikl) 
+            TsisSV(ikl,isn) = TsisSV(ikl,isn) * (1-NLaysv(ikl))
+     .                  + min(TaT_SV(ikl),Tf_Sno) *NLaysv(ikl) 
+
+            ro__SV(ikl,isn) = ro__SV(ikl,isn) * (1-NLaysv(ikl))
+     .                      + Brossv(ikl)     *    NLaysv(ikl) 
+            eta_SV(ikl,isn) = eta_SV(ikl,isn) * (1-NLaysv(ikl))   ! + 0. 
+            agsnSV(ikl,isn) = agsnSV(ikl,isn) * (1-NLaysv(ikl))   ! + 0. 
+            G1snSV(ikl,isn) = G1snSV(ikl,isn) * (1-NLaysv(ikl))
+     .                      + BG1ssv(ikl)     *    NLaysv(ikl)
+            G2snSV(ikl,isn) = G2snSV(ikl,isn) * (1-NLaysv(ikl))
+     .                      + BG2ssv(ikl)     *    NLaysv(ikl)
+            istoSV(ikl,isn) = istoSV(ikl,isn) * (1-NLaysv(ikl))
+     .   + max(zer0,sign(un_1,TaT_SV(ikl)
+     .                       -Tf_Sno-eps_21)) *    istdSV(2)
+     .                                        *    NLaysv(ikl)
+            BufsSV(ikl)     = BufsSV(ikl)     * (1-NLaysv(ikl))
+            NLaysv(ikl)     = 0
+
+
+          END DO
+
+
+! Snow Pack Thickness
+! -------------------
+
+        DO ikl=1,knonv
+            z_snsv(ikl)     = 0.0
+        END DO
+        DO   isn=1,nsno
+          DO ikl=1,knonv
+            z_snsv(ikl)     = z_snsv(ikl) + dzsnSV(ikl,isn)
+            zzsnsv(ikl,isn) = z_snsv(ikl)
+          END DO
+        END DO
+
+
+
+      END IF
+
+
+
+! Soil Albedo: Soil Humidity Correction
+! ==========================================
+
+!         REFERENCE: McCumber and Pielke (1981), Pielke (1984)
+!         ^^^^^^^^^
+          DO ikl=1,knonv
+            albssv(ikl) = 
+     .      alb0SV(ikl) *(1.0-min(half,eta_SV(       ikl,0)
+     .                                /etadSV(isotSV(ikl))))
+!         REMARK:    Albedo of Water Surfaces (isotSV=0): 
+!         ^^^^^^     alb0SV := 2  X  effective value, while 
+!                    eta_SV :=          etadSV
+          END DO
+
+
+! Snow Pack Optical Properties
+! ============================
+
+      IF (SnoMod)                                                 THEN
+
+!            ******
+        call SnOptP(jjtime)
+!            ******
+
+      ELSE
+        DO ikl=1,knonv
+          sEX_sv(ikl,1) = 1.0
+          sEX_sv(ikl,0) = 0.0
+          albisv(ikl)   = albssv(ikl)
+        END DO
+      END IF
+
+
+
+! Soil optical properties
+! =============================
+!Etienne: as in inlandis we do not call vgopt, we need to define
+!the albedo  alb_SV and to calculate the
+!absorbed Solar Radiation by Surfac (Normaliz)[-] SoSosv
+
+ 
+      DO ikl=1,klonv
+
+            e_pRad = 2.5   *  coszSV(ikl)       ! exponential argument,
+                                                ! V/nIR radiation partitioning,
+                                                ! DR97, 2, eqn (2.53) & (2.54)
+            e1pRad = 1.-exp(-e_pRad)            ! exponential, V/nIR Rad. Part.
+            exdRad= 1.
+ 
+! Visible Part of the Solar Radiation Spectrum (V,   0.4--0.7mi.m) 
+            A_Rad0 =      0.25 + 0.697 * e1pRad ! Absorbed    Vis. Radiation
+            absg_V = (1.-albisv(ikl))*(A_Rad0*exdRad)  !
+ 
+! Near-IR Part of the Solar Radiation Spectrum (nIR, 0.7--2.8mi.m)
+ 
+            A_Rad0 =      0.80 + 0.185 * e1pRad ! Absorbed    nIR. Radiation
+            absgnI = (1.-albisv(ikl))*(A_Rad0*exdRad)  !
+
+            SoSosv(ikl) = (absg_V+absgnI)*0.5d0
+
+            alb_SV(ikl) = albisv(ikl)
+
+      END DO
+ 
+!            **********
+! #ve   call SISVAT_wEq('SnOptP',0)
+!            **********
+
+
+! Surface Emissivity (Etienne: simplified calculation for landice)
+! =============================================================
+!
+       DO ikl=1,knonv
+            LSnMsk     =     min( 1,isnoSV(ikl))
+            Eso_sv(ikl)=  EmiSol*(1-LSnMsk)+EmiSno*LSnMsk  ! Sol+Sno Emissivity
+            emi_SV(ikl)= EmiSol*(1-LSnMsk) + EmiSno*LSnMsk
+        END DO
+
+
+
+
+!  Upward IR (INPUT, from previous time step)
+! ===================================================================
+
+        DO ikl=1,knonv
+! #e1     Enrsvd(ikl) =    - IRs_SV(ikl)
+           IRupsv(ikl) =      IRs_SV(ikl) 
+        END DO
+
+
+! Turbulence
+! ==========
+
+! Latent Heat of Vaporization/Sublimation
+! ---------------------------------------
+
+        DO ikl=1,knonv
+          SnoWat      =                     min(isnoSV(ikl),0)
+          Lx_H2O(ikl) =
+     .    (1.-SnoWat) * LhvH2O 
+     .  +     SnoWat  *(LhsH2O * (1.-eta_SV(ikl,isnoSV(ikl)))
+     .                 +LhvH2O *     eta_SV(ikl,isnoSV(ikl)) )
+        END DO
+
+
+
+
+! Aerodynamic Resistance
+! ^^^^^^^^^^^^^^^^^^^^^^
+
+
+       DO ikl=1,knonv
+          ram_sv(ikl) = 1./(cdM_SV(ikl)*max(VV__SV(ikl),eps6))
+          rah_sv(ikl) = 1./(cdH_SV(ikl)*max(VV__SV(ikl),eps6))
+        END DO
+
+
+
+! Soil   Energy Balance
+! =====================
+
+
+      if (iflag_tsurf_inlandsis .eq. 0) then
+
+       call SISVAT_TSo
+
+      else
+
+       call SISVAT_TS2
+
+      end if
+
+
+!            **********
+! #ve   call SISVAT_wEq('_TSo  ',0)
+!            **********
+
+
+
+! Soil Water     Potential
+! ------------------------
+
+      DO   isl=-nsol,0
+        DO ikl=1,knonv
+          ist             =     isotSV(ikl)        ! Soil Type
+          psi_sv(ikl,isl) =     psidSV(ist)        ! DR97, Eqn.(3.34)
+     .  *(etadSV(ist) /max(eps6,eta_SV(ikl,isl)))  !
+     .  **bCHdSV(ist)                              !
+
+
+! Soil Hydraulic Conductivity
+! ---------------------------
+
+          Khydsv(ikl,isl) =    s2__SV(ist)         ! DR97, Eqn.(3.35)
+     .  *(eta_SV(ikl,isl)**(2.*bCHdSV(ist)+3.))    !  
+        END DO
+      END DO
+
+
+! Melting / Refreezing in the Snow Pack
+! =====================================
+
+      IF (SnoMod)                                                 THEN
+
+!            **********
+        call SISVAT_qSn
+!            **********
+
+!            **********
+! #ve   call SISVAT_wEq('_qSn  ',0)
+!            **********
+
+
+! Snow Pack Thickness
+! -------------------
+
+          DO ikl=1,knonv
+            z_snsv(ikl)     = 0.0
+          END DO
+        DO   isn=1,nsno
+          DO ikl=1,knonv
+            z_snsv(ikl)     = z_snsv(ikl) + dzsnSV(ikl,isn)
+            zzsnsv(ikl,isn) = z_snsv(ikl)
+          END DO
+        END DO
+
+
+! Energy in Excess is added to the first Soil Layer
+! -------------------------------------------------
+        DO ikl=1,knonv
+            z_snsv(ikl)   = max(zer0,
+     .                          sign(un_1,eps6-z_snsv(ikl)))
+            TsisSV(ikl,0) = TsisSV(ikl,0)    + EExcsv(ikl)
+     .                                       /(rocsSV(isotSV(ikl))
+     .                                        +rcwdSV*eta_SV(ikl,0))
+            EExcsv(ikl)   = 0.
+        END DO
+
+
+      END IF
+
+
+! Soil   Water  Balance
+! =====================
+
+!            **********
+        call SISVAT_qSo
+! #m0.                 (Wats_0,Wats_1,Wats_d)
+!            **********
+
+
+! Surface Fluxes
+! =====================
+
+        DO ikl=1,knonv
+         IRdwsv(ikl)=IRd_SV(ikl)*Eso_sv(ikl) ! Downward IR
+!         IRdwsv(ikl)=tau_sv(ikl) *IRd_SV(ikl)*Eso_sv(ikl) ! Downward IR
+!    .          +(1.0-tau_sv(ikl))*IRd_SV(ikl)*Evg_sv(ikl) !  ! Etienne, remove vegetation component
+          IRupsv(ikl) =      IRupsv(ikl)                   ! Upward   IR
+          IRu_SV(ikl) =     -IRupsv(ikl)                   ! Upward   IR
+     .                      +IRd_SV(ikl)                   ! (effective)
+     .                      -IRdwsv(ikl)                   ! (positive)
+
+          TBr_sv(ikl) =sqrt(sqrt(IRu_SV(ikl)/StefBo))      ! Brightness
+!                                                          ! Temperature
+          uts_SV(ikl) =     (HSv_sv(ikl) +HSs_sv(ikl))     ! u*T*
+     .                     /(rhT_SV(ikl) *cp)          !
+          uqs_SV(ikl) =     (HLv_sv(ikl) +HLs_sv(ikl))     ! u*q*
+     .                     /(rhT_SV(ikl) *LhvH2O)          !
+          LMO_SV(ikl) = TaT_SV(ikl)*(us__SV(ikl)**3)
+     .                     /gravit/uts_SV(ikl)/vonKrm      ! MO length
+     
+
+! Surface Temperature
+! ^^^^^^^^^^^^^^^^^^^^
+!           Tsrfsv(ikl) =TsisSV(ikl,isnoSV(ikl))
+
+! Etienne: extrapolation from the two uppermost levels:
+
+         if (isnoSV(ikl) >=2) then
+           zm1=-dzsnSV(ikl,isnoSV(ikl))/2.
+           zm2=-(dzsnSV(ikl,isnoSV(ikl)) + dzsnSV(ikl,isnoSV(ikl)-1)/2.)
+         else if (isnoSV(ikl) .EQ. 1) then
+           zm1=-dzsnSV(ikl,isnoSV(ikl))/2.
+           zm2=-(dzsnSV(ikl,isnoSV(ikl))+dz_dSV(0)/2.)
+         else
+           zm1=-dz_dSV(0)/2.
+           zm2=-(dz_dSV(0)+dz_dSV(-1)/2.)
+
+         end if
+
+           coefslope=(TsisSV(ikl,isnoSV(ikl))-TsisSV(ikl,isnoSV(ikl)-1)) 
+     .               /(zm1-zm2)
+           Tsrfsv(ikl)=TsisSV(ikl,isnoSV(ikl))+coefslope*(0. - zm1)
+
+
+        END DO
+
+
+! Snow Pack Properties (sphericity, dendricity, size)
+! ===================================================
+
+      IF (SnoMod)                                                 THEN
+
+!            **********
+        call SISVAT_GSn
+!            **********
+
+!            **********
+! #ve   call SISVAT_wEq('_GSn  ',0)
+!            **********
+
+
+
+      END IF
+
+
+! Roughness Length for next time step
+!====================================
+
+! Note that in INLANDSIS, we treat only ice covered surfaces so calculation
+! of z0 is much simpler (no subgrid fraction of ocean or land)
+! old calculations are commented below
+
+
+C +--Roughness Length for Momentum
+C +  -----------------------------
+ 
+C +--Land+Sea-Ice / Ice-free Sea Mask
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+        DO ikl=1,klonv
+          IcIndx(ikl) = 0
+        ENDDO
+        DO isn=1,nsno
+        DO ikl=1,klonv
+          IcIndx(ikl) = max(IcIndx(ikl),
+     .                      isn*max(0,
+     .                              sign(1,
+     .                                   int(ro__SV(ikl,isn)-900.))))
+        ENDDO
+        ENDDO
+ 
+        DO ikl=1,klonv
+          LISmsk    =     1. ! in inlandsis, land only
+          IceMsk    =     max(0,sign(1   ,IcIndx(ikl)-1)  )
+          SnoMsk    = max(min(isnoSV(ikl)-iiceSV(ikl),1),0)
+
+ 
+
+          Z0mLnd      =max( Z0_ICE    ,    5.e-5  )  ! Min set := Z0 on *
+
+C +--Z0 Smooth Regime over Snow (Andreas 1995, CRREL Report 95-16, p. 8)
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+          Z0m_nu =       5.e-5 ! z0s~(10-d)*exp(-vonkar/sqrt(1.1e-03))
+ 
+C +--Z0 Saltat.Regime over Snow (Gallee  et al., 2001, BLM 99 (19) p.11)
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+          u2star =       us__SV(ikl) *us__SV(ikl)
+          Z0mBSn =       u2star      *0.536e-3   -  61.8e-6
+          Z0mBSn =   max(Z0mBS0      ,Z0mBSn)
+ 
+C +--Z0 Smooth + Saltat. Regime
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+          Z0enSV(ikl) =  Z0m_nu
+     .                +  Z0mBSn
+ 
+C +--Rough   Snow Surface Roughness Length (Typical Value)
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+c #tz     Z0m_Sn =    0.250e-3 ! Andreas 1995, CRREL Report 95-16, fig.1&p.2
+                               ! z0r~(10-d)*exp(-vonkar/sqrt(1.5e-03))-5.e-5
+          Z0m_Sn =    2.000e-3 ! Calibration    of MAR
+c #TZ     Z0m_Sn =    1.000e-3 ! Exemple Tuning in RACMO
+c #TZ     Z0m_Sn =    0.500e-3 ! Exemple Tuning in MAR
+ 
+C +--Rough   Snow Surface Roughness Length (Variable Sastrugi Height)
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+          A_Fact      =  1.0000        ! Andreas et al., 2004, p.4
+                                       ! ams.confex.com/ams/pdfpapers/68601.pdf
+ 
+! Parameterization of z0 dependance on Temperature (C. Amory, 2017)
+! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+! Z0=f(T) deduced from observations, Adelie Land, dec2012-dec2013
+          coefa = 0.1658 !0.1862 !Ant
+          coefb = -50.3869 !-55.7718 !Ant
+          ta1 = 253.15 !255. Ant
+          ta2 = 273.15
+          ta3 = 273.15+3
+          z01 = exp(coefa*ta1 + coefb) !~0.2 ! ~0.25 mm
+          z02 = exp(coefa*ta2 + coefb) !~6  !~7 mm
+          z03 = z01
+          coefc = log(z03/z02)/(ta3-ta2)
+          coefd = log(z03)-coefc*ta3
+          if (TaT_SV(ikl) .lt. ta1) then
+            Z0_obs = z01
+          else if (TaT_SV(ikl).ge.ta1 .and. TaT_SV(ikl).lt.ta2) then
+            Z0_obs = exp(coefa*TaT_SV(ikl) + coefb)
+          else if (TaT_SV(ikl).ge.ta2 .and. TaT_SV(ikl).lt.ta3) then
+            ! if st > 0, melting induce smooth surface
+            Z0_obs = exp(coefc*TaT_SV(ikl) + coefd)
+          else
+            Z0_obs = z03
+          endif
+ 
+
+! pour le moment, on choisit une valeur fixe
+          Z0_obs = 1.000e-3
+ 
+cCA       Snow roughness lenght deduced from observations
+cCA       (parametrization if no Blowing Snow)
+cCA       ----------------------------------- C. Agosta 09-2016 -----
+cCA       Substract Z0enSV(ikl) because re-added later in Z0mnSV(ikl)
+          Z0m_Sn = Z0_obs - Z0enSV(ikl)
+cCA       -----------------------------------------------------------
+ 
+          param = Z0_obs/1. ! param(s) | 1.(m/s)=TUNING
+ 
+c #SZ     Z0Sa_N =                   (us__SV(ikl) -0.2)*param   ! 0.0001=TUNING
+c #SZ.           * max(zero,sign(unun,TfSnow-eps9
+c #SZ.                               -TsisSV(ikl , isnoSV(ikl))))
+!!#SZ     Z0SaSi = max(zero,sign(unun,Z0Sa_N                  ))! 1 if erosion
+c #SZ     Z0SaSi = max(zero,sign(unun,zero  -eps9 -uss_SV(ikl)))!
+c #SZ     Z0Sa_N = max(zero,          Z0Sa_N)
+c #SZ     Z0SaSV(ikl) =
+c #SZ.             max(Z0SaSV(ikl)   ,Z0SaSV(ikl)
+c #SZ.               + Z0SaSi*(Z0Sa_N-Z0SaSV(ikl))*exp(-dt__SV/43200.))
+c #SZ.               -            min(dz0_SV(ikl) ,     Z0SaSV(ikl))
+ 
+c #SZ     A_Fact      =               Z0SaSV(ikl) *  5.0/0.15   ! A=5 if h~10cm
+C +...    CAUTION: The influence of the sastrugi direction is not yet included
+ 
+c #SZ     Z0m_Sn =                    Z0SaSV(ikl)               !
+c #SZ.                              - Z0m_nu                    !
+ 
+C +--Z0 Saltat.Regime over Snow (Shao & Lin, 1999, BLM 91 (46)  p.222)
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+c #ZN     sqrrZ0 =       usthSV(ikl)/max( us__SV(ikl),0.001)
+c #ZN     sqrrZ0 =                   min( sqrrZ0     ,0.999)
+c #ZN     Z0mBSn =       0.55 *0.55 *exp(-sqrrZ0     *sqrrZ0)
+c #ZN.                  *us__SV(ikl)*     us__SV(ikl)*grvinv*0.5
+ 
+C +--Z0 Smooth + Saltat. Regime (Shao & Lin, 1999, BLM 91 (46)  p.222)
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+c #ZN     Z0enSV(ikl) = (Z0m_nu     **    sqrrZ0 )
+c #ZN.                * (Z0mBSn     **(1.-sqrrZ0))
+c #ZN     Z0enSV(ikl) =  max(Z0enSV(ikl), Z0m_nu)
+ 
+C +--Z0 Smooth Regime over Snow (Andreas etAl., 2004
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^  ams.confex.com/ams/pdfpapers/68601.pdf)
+c #ZA     Z0m_nu = 0.135*akmol  / max(us__SV(ikl) , epsi)
+ 
+C +--Z0 Saltat.Regime over Snow (Andreas etAl., 2004
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^  ams.confex.com/ams/pdfpapers/68601.pdf)
+c #ZA     Z0mBSn = 0.035*u2star      *grvinv
+ 
+C +--Z0 Smooth + Saltat. Regime (Andreas etAl., 2004
+!    (      used by Erosion)     ams.confex.com/ams/pdfpapers/68601.pdf)
+!    ^^^^^^^^^^^^^^^^^^^^^^^^^^
+c #ZA     Z0enSV(ikl) =  Z0m_nu
+c #ZA.                +  Z0mBSn
+ 
+C +--Z0 Rough  Regime over Snow (Andreas etAl., 2004
+C +  (.NOT. used by Erosion)     ams.confex.com/ams/pdfpapers/68601.pdf)
+!    ^^^^^^^^^^^^^^^^^^^^^^^^^^
+!!#ZA     u2star =      (us__SV(ikl) -0.1800)     / 0.1
+!!#ZA     Z0m_Sn =A_Fact*Z0mBSn *exp(-u2star*u2star)
+c #ZA     Z0m_90 =(10.-0.025*VVs_SV(ikl)/5.)
+c #ZA.            *exp(-0.4/sqrt(.00275+.00001*max(0.,VVs_SV(ikl)-5.)))
+c #ZA     Z0m_Sn =           DDs_SV(ikl)* Z0m_90 / 45.
+c #ZA.         - DDs_SV(ikl)*DDs_SV(ikl)* Z0m_90 /(90.*90.)
+ 
+C +--Z0  (Erosion)    over Snow (instantaneous or time average)
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+          Z0e_SV(ikl) =  Z0enSV(ikl)
+          Z0e_SV(ikl) =  Z0emSV(ikl)
+ 
+C +--Momentum  Roughness Length
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^                              ! Contribution of
+          Z0mnSV(ikl) =  Z0mLnd                              ! land Form
+     .                + (Z0m_Sn                              ! Sastrugi   Form
+     .                +  Z0enSV(ikl))   *SnoMsk              ! Snow    Erosion
+ 
+
+C +--GIS  Roughness Length
+C +  ^^^^^^^^^^^^^^^^^^^^^
+c #GL     Z0mnSV(ikl) =
+c #GL.      (1-LSmask(ikl)) *     Z0mnSV(ikl)
+c #GL.    +    LSmask(ikl)  * max(Z0mnSV(ikl),max(Z0_GIM,
+c #GL.                                            Z0_GIM+
+c #GL.      (0.0032-Z0_GIM)*(ro__SV(ikl,isnoSV(ikl))-600.)   !
+c #GL.                     /(920.00                 -600.))) !
+ 
+C +--Mom. Roughness Length, Instantaneous OR Box Moving Average in Time
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+          Z0m_SV(ikl) =  Z0mnSV(ikl)                         ! Z0mnSV  instant.
+!          Z0m_SV(ikl) =  Z0mmSV(ikl)                         ! Z0mnSV  Average
+ 
+C +--Corrected Threshold Friction Velocity before Erosion    ! Marticorena and
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    ! Bergametti 1995
+! not used anymore since Marticorena and Bergametti disabled !CK 18/07/2018
+cc #BS     Z0e_SV(ikl) =   min(Z0m_SV(ikl),Z0e_SV(ikl))       !
+cc #MB     f_eff=    log(0.35*(0.1        /Z0e_SV(ikl))**0.8) ! JGR 100
+cc #MB     f_eff=1.-(log(      Z0m_SV(ikl)/Z0e_SV(ikl)      ))! (20) p. 16420
+cc #MB.            /(max(      f_eff      ,epsi             ))! p.16426 2nd ?
+cc #MB     f_eff=    max(      f_eff      ,epsi              )! CONTROL
+cc #MB     f_eff=1.0   -(1.0 - f_eff)     /5.00               ! TUNING
+cc #MB     f_eff=    min(      f_eff      ,1.00              )!
+cc #MB    usthSV(ikl) =       usthSV(ikl)/f_eff              !
+ 
+ 
+ 
+C +--Roughness Length for Scalars
+C +  ----------------------------
+ 
+          Z0hnSV(ikl) =     Z0mnSV(ikl)/  7.4
+c #SH     Z0hnSV(ikl) =     Z0mnSV(ikl)/100.0
+C +                         Z0h = Z0m  /100.0   over the Sahel
+C +                                            (Taylor & Clark, QJRMS 127,p864)
+ 
+c #RN     rstar       =     Z0mnSV(ikl) * us__SV(ikl) / akmol
+c #RN     rstar       = max(epsi,min(rstar,thous))
+c #RN     alors       =          log(rstar)
+c #RN     rstar0      = 1.250e0 * max(zero,sign(unun,0.135e0 - rstar))
+c #RN.                +(1.      - max(zero,sign(unun,0.135e0 - rstar)))
+c #RN.                *(0.149e0 * max(zero,sign(unun,2.500e0 - rstar))
+c #RN.                + 0.317e0
+c #RN.                *(1.      - max(zero,sign(unun,2.500e0 - rstar))))
+c #RN     rstar1      = 0.      * max(zero,sign(unun,0.135e0 - rstar))
+c #RN.                +(1.      - max(zero,sign(unun,0.135e0 - rstar)))
+c #RN.                *(-0.55e0 * max(zero,sign(unun,2.500e0 - rstar))
+c #RN.                - 0.565
+c #RN.                *(1.      - max(zero,sign(unun,2.500e0 - rstar))))
+c #RN     rstar2      = 0.      * max(zero,sign(unun,0.135e0 - rstar))
+c #RN.                +(1.      - max(zero,sign(unun,0.135e0 - rstar)))
+c #RN.                *(0.      * max(zero,sign(unun,2.500e0 - rstar))
+c #RN.                - 0.183
+c #RN.                *(unun    - max(zero,sign(unun,2.500e0 - rstar))))
+ 
+cXF    #RN does not work over bare ice
+cXF    MAR is then too warm and not enough melt
+ 
+c #RN     if(ro__SV(ikl,isnoSV(ikl))>50
+c #RN.  .and.ro__SV(ikl,isnoSV(ikl))<roSdSV)then
+ 
+c #RN     Z0hnSV(ikl) = max(zero
+c #RN.                , sign(unun,zzsnsv(ikl,isnoSV(ikl))-epsi))
+c #RN.                * exp(rstar0+rstar1*alors+rstar2*alors*alors)
+c #RN.                * 0.001e0 + Z0hnSV(ikl) * ( 1. - max(zero
+c #RN.                , sign(unun,zzsnsv(ikl,isnoSV(ikl))-epsi)))
+ 
+c #RN     endif
+  
+          Z0h_SV(ikl) =     Z0hnSV(ikl)
+!          Z0h_SV(ikl) =     Z0hmSV(ikl)
+ 
+
+c #MT     Z0m_SV(ikl) = max(2.0e-6     ,Z0m_SV(ikl)) ! Min Z0_m (Garrat Scheme)
+!          Z0m_SV(ikl) = min(Z0m_SV(ikl),za__SV(ikl)*0.3333)
+     
+
+       END DO
+ 
+
+       return
+       end
+
+
+
+
+
+
+
+
+
+
+ 
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_bsn.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_bsn.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_bsn.F	(revision 3792)
@@ -0,0 +1,114 @@
+ 
+ 
+      subroutine SISVAT_BSn
+ 
+C +------------------------------------------------------------------------+
+C | MAR          SISVAT_BSn                               04-apr-2020  MAR |
+C |   SubRoutine SISVAT_BSn treats Snow Erosion                            |
+C |   (not deposition anymore since 2-jun 2018)                            |
+C |                                                                        |
+C |   SISVAT_bsn computes the snow erosion mass according to both the      |
+C |   theoretical maximum erosion amount computed in SISVATesbl and the    |
+C |   availability of snow (currently in the uppermost snow layer only)    |
+C |                                                                        |
+C |   Preprocessing  Option: SISVAT IO (not always a standard preprocess.) |
+C |   ^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^                                     |
+C |   FILE                 |      CONTENT                                  |
+C |   ~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+C | # stdout               | #sb: OUTPUT of Snow Erosion                   |
+C |                        |      unit  6, SubRoutine  SISVAT_BSn **ONLY** |
+C +------------------------------------------------------------------------+
+ 
+ 
+ 
+ 
+C +--General Variables
+C +  =================
+
+      use VARphy
+      use VAR_SV
+      use VARdSV
+      use VARxSV
+      use VARySV
+ 
+ 
+       IMPLICIT NONE
+
+C +--Local Variables
+C +  ===============
+ 
+ 
+      integer  ikl   ,isn
+      real     h_mmWE                        ! Eroded Snow Layer Min Thickness
+      real     dbsaux(knonv)                 ! Drift Amount   (Dummy Variable)
+      real     dzweqo,dzweqn,bsno_x          ! Conversion variables for erosion
+      real     dz_new,rho_new
+      real     snofOK                        ! Threshd Snow Fall
+      real     Fac                           ! Correction factor for erosion
+      real     densif                        ! Densification rate if erosion
+ 
+C +--DATA
+C +  ====
+ 
+      data     h_mmWE  / 0.01e00  /          ! Eroded Snow Layer Min Thickness
+ 
+C +--EROSION
+C +  =======
+ 
+      !DO isn = nsno,2,-1
+      DO ikl = 1,knonv
+ 
+        isn         = isnoSV(ikl)
+        dzweqo      = dzsnSV(ikl,isn) *ro__SV(ikl,isn)      ! [kg/m2, mm w.e.]
+ 
+        bsno_x      = min(0.,dbs_SV(ikl))
+c       Fac         = min(1.,max(1-(ro__SV(ikl,isn)/700.),0.)**2)
+c       Fac         = min(1.,max(1-(qsnoSV(ikl)*1000/30.),0.))
+c       bsno_x      = bsno_x*Fac
+ 
+        dzweqn      = dzweqo + bsno_x
+        dzweqn      = max(dzweqn,h_mmWE)
+        dzweqn      = min(dzweqn,dzweqo)
+cXF
+        dbs_SV(ikl) = dbs_SV(ikl)    +(dzweqo -dzweqn)
+        dbs_Er(ikl) = dbs_Er(ikl)    +(dzweqo -dzweqn)
+        dzsnSV(ikl,isn) =              dzweqn
+     .                       /max(epsi,ro__SV(ikl,isn))
+ 
+        ! Densification of the uppermost snow layer if erosion:
+        if((dzweqo-dzweqn)>0                    .and.
+     .     dzsnSV(ikl,isn)>0                    .and.
+     .     ro__SV(ikl,max(1,isnoSV(ikl)))<roBdSV) then
+ 
+        !characteristic time scale for drifting snow compaction set to 24h
+        !linear densification rate [kg/m3/s] over 24h
+        densif         = (450. - frsno) / (3600*24)
+ 
+        !Attenuation of compaction rate from 450 to 500 kg/m3
+        Fac         = 1-((ro__SV(ikl,max(1,isnoSV(ikl)))
+     .                        -roBdSV)/(500.-roBdSV))
+        Fac         = max(0.,min(1.,Fac))
+ 
+        if (ro__SV(ikl,max(1,isnoSV(ikl)))>roBdSV) then
+          densif=densif*Fac
+        endif
+ 
+        rho_new        = min(roBdSV,ro__SV(ikl,isn)+densif*dt__SV)
+        dz_new         = dzsnSV(ikl,isn)*ro__SV(ikl,isn)/rho_new
+        ro__SV(ikl,isn)=rho_new
+        dzsnSV(ikl,isn)=dz_new
+        endif
+ 
+        if(dzsnSV(ikl,isn)>0 .and.dzsnSV(ikl,isn)<0.0001)then
+        dbs_SV(ikl) = dbs_SV(ikl)+ dzsnSV(ikl,isn)*ro__SV(ikl,isn)
+        dbs_Er(ikl) = dbs_Er(ikl)+ dzsnSV(ikl,isn)*ro__SV(ikl,isn)
+        dzsnSV(ikl,isn) = 0
+        ro__SV(ikl,isn) = 0
+        isnoSV(ikl)     = max(0,isnoSV(ikl) - 1)
+        endif
+ 
+      END DO
+      !END DO
+ 
+      return
+      END
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_gsn.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_gsn.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_gsn.F	(revision 3792)
@@ -0,0 +1,925 @@
+  
+      subroutine SISVAT_GSn
+ 
+C +------------------------------------------------------------------------+
+C | MAR          SISVAT_GSn                                20-09-2003  MAR |
+C |   SubRoutine SISVAT_GSn simulates SNOW Metamorphism                    |
+C +------------------------------------------------------------------------+
+C |                                                                        |
+C |   PARAMETERS:  knonv: Total Number of columns =                        |
+C |   ^^^^^^^^^^        = Total Number of continental     grid boxes       |
+C |                     X       Number of Mosaic Cell per grid box         |
+C |                                                                        |
+C |   INPUT /  isnoSV   = total Nb of Ice/Snow Layers                      |
+C |   OUTPUT:  iiceSV   = total Nb of Ice      Layers                      |
+C |   ^^^^^^   istoSV   = 0,...,5 :   Snow     History (see istdSV data)   |
+C |                                                                        |
+C |   INPUT:   TsisSV   : Soil/Ice Temperatures (layers -nsol,-nsol+1,..,0)|
+C |   ^^^^^             & Snow     Temperatures (layers  1,2,...,nsno) [K] |
+C |            ro__SV   : Soil/Snow Volumic Mass                   [kg/m3] |
+C |            eta_SV   : Soil/Snow Water   Content                [m3/m3] |
+C |            slopSV   : Surface Slope                                [-] |
+C |            dzsnSV   : Snow Layer        Thickness                  [m] |
+C |            dt__SV2   : Time  Step                                   [s] |
+C |                                                                        |
+C |   INPUT /  G1snSV   : Dendricity (<0) or Sphericity (>0) of Snow Layer |
+C |   OUTPUT:  G2snSV   : Sphericity (>0) or Size            of Snow Layer |
+C |   ^^^^^^                                                               |
+C |                                                                        |
+C |   Formalisme adopte pour la Representation des Grains:                 |
+C |   Formalism         for the Representation of  Grains:                 |
+C |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                 |
+C |                                                                        |
+C |             1       - -1                 Neige Fraiche                 |
+C |            / \      |                    -------------                 |
+C |           /   \     |  Dendricite        decrite  par Dendricite       |
+C |          /     \    |  Dendricity                  et Sphericite       |
+C |         /       \   |                                                  |
+C |        2---------3  -  0                 described by Dendricity       |
+C |                                                   and Sphericity       |
+C |        |---------|                                                     |
+C |        0         1                                                     |
+C |        Sphericite                                                      |
+C |        Sphericity                                                      |
+C |                                                                        |
+C |        4---------5  -                                                  |
+C |        |         |  |                                                  |
+C |        |         |  |  Diametre (1/10eme de mm) (ou Taille)            |
+C |        |         |  |  Diameter (1/10th  of mm) (or Size  )            |
+C |        |         |  |                                                  |
+C |        |         |  |                    Neige non dendritique         |
+C |        6---------7  -                    ---------------------         |
+C |                                          decrite  par Sphericite       |
+C |                                                    et     Taille       |
+C |                                          described by Sphericity       |
+C |                                                   and       Size       |
+C |                                                                        |
+C |   Les Variables du Modele:                                             |
+C |   Model         Variables:                                             |
+C |   ^^^^^^^^^^^^^^^^^^^^^^^^                                             |
+C |     Cas Dendritique               Cas non Dendritique                  |
+C |                                                                        |
+C |     G1snSV        : Dendricite    G1snSV        : Sphericite           |
+C |     G2snSV        : Sphericite    G2snSV        : Taille (1/10e mm)    |
+C |                                                   Size                 |
+C |                                                                        |
+C |   Cas Dendritique/ Dendritic Case                                      |
+C |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                      |
+C |   Dendricite(Dendricity) G1snSV                                        |
+C |            varie     de -G1_dSV (-99 par defaut / etoile)          a 0 |
+C |            division par -G1_dSV pour obtenir des valeurs entre 1  et 0 |
+C |            varies  from -G1_dSV (default -99    / fresh snow)     to 0 |
+C |            division  by -G1_dSV to obtain values       between 1 and 0 |
+C |                                                                        |
+C |   Sphericite(Sphericity) G2snSV                                        |
+C |            varie     de  0         (cas completement anguleux)         |
+C |                       a  G1_dSV (99 par defaut, cas spherique)         |
+C |            division par  G1_dSV pour obtenir des valeurs entre 0  et 1 |
+C |            varies  from  0      (full faceted)               to G1_dSV |
+C |                                                                        |
+C |   Cas non Dendritique / non Dendritic Case                             |
+C |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                             |
+C |   Sphericite(Sphericity) G1snSV                                        |
+C |            varie     de  0         (cas completement anguleux)         |
+C |                       a  G1_dSV (99 par defaut, cas spherique)         |
+C |            division par  G1_dSV pour obtenir des valeurs entre 0  et 1 |
+C |            varies  from  0      (full faceted)               to G1_dSV |
+C |                                                                        |
+C |   Taille    (Size)       G2snSV                                        |
+C |            superieure a  ADSdSV (.4 mm) et ne fait que croitre         |
+C |            greater than  ADSdSV (.4 mm) always increases               |
+C |                                                                        |
+C |   Exemples: Points caracteristiques des Figures ci-dessus              |
+C |   ^^^^^^^^^                                                            |
+C |                                                                        |
+C |               G1snSV    G2snSV     dendricite  sphericite  taille      |
+C |                                    dendricity  sphericity  size        |
+C |   ------------------------------------------------------------------   |
+C |                                                            [1/10 mm]   |
+C |     1        -G1_dSV    sph3SN          1           0.5                |
+C |     2           0         0             0           0                  |
+C |     3           0       G1_dSV          0           1                  |
+C |     4           0       ADSdSV                      0       4.         |
+C |     5         G1_dSV    ADSdSV-vsphe1               1       3.         |
+C |     6           0         --                        0       --         |
+C |     7         G1_dSV      --                        1       --         |
+C |                                                                        |
+C |   par defaut: G1_dSV=99.                                               |
+C |                         sph3SN=50.                                     |
+C |                         ADSdSV= 4.                                     |
+C |                                vsphe1=1.                               |
+C |                                                                        |
+C |   Methode:                                                             |
+C |   ^^^^^^^^                                                             |
+C |   1. Evolution Types de Grains selon Lois de Brun et al. (1992):       |
+C |      Grain metamorphism according to         Brun et al. (1992):       |
+C |      Plusieurs Cas sont a distiguer  /  the different Cases are:       |
+C |       1.1 Metamorphose Neige humide  /  wet Snow                       |
+C |       1.2 Metamorphose Neige seche   /  dry Snow                       |
+C |         1.2.1 Gradient faible        /  low      Temperature Gradient  |
+C |         1.2.2 Gradient moyen         /  moderate Temperature Gradient  |
+C |         1.2.3 Gradient fort          /  high     Temperature Gradient  |
+C |      Dans chaque Cas on separe Neige Dendritique et non Dendritique    |
+C |                           le Passage Dendritique -> non Dendritique    |
+C |                           se fait lorsque  G1snSV devient > 0          |
+C |      the Case of Dentritic or non Dendritic Snow is treated separately |
+C |      the Limit   Dentritic -> non Dendritic is reached when G1snSV > 0 |
+C |                                                                        |
+C |   2. Tassement: Loi de Viscosite adaptee selon le Type de Grains       |
+C |      Snow Settling:    Viscosity depends on the   Grain Type           |
+C |                                                                        |
+C |   3. Update Variables historiques (cas non dendritique seulement)      |
+C |      nhSNow defaut                                                     |
+C |                0    Cas normal                                         |
+C |      istdSV(1) 1    Grains anguleux / faceted cristal                  |
+C |      istdSV(2) 2    Grains ayant ete en presence d eau liquide         |
+C |                     mais n'ayant pas eu de caractere anguleux    /     |
+C |                     liquid water and no faceted cristals before        |
+C |      istdSV(3) 3    Grains ayant ete en presence d eau liquide         |
+C |                     ayant eu auparavant un caractere anguleux    /     |
+C |                     liquid water and    faceted cristals before        |
+C |                                                                        |
+C |   REFER. : Brun et al.      1989, J. Glaciol 35 pp. 333--342           |
+C |   ^^^^^^^^ Brun et al.      1992, J. Glaciol 38 pp.  13-- 22           |
+C |            (CROCUS Model, adapted to MAR at CEN by H.Gallee)           |
+C |                                                                        |
+C |   REFER. : Marbouty, D.     1980, J. Glaciol 26 pp. xxx--xxx           |
+C |   ^^^^^^^^ (CROCUS Model, adapted to MAR at CEN by H.Gallee)           |
+C |            (for angular shapes)                                        |
+C |                                                                        |
+C |   Preprocessing  Option: SISVAT IO (not always a standard preprocess.) |
+C |   ^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^                                     |
+C |   FILE                 |      CONTENT                                  |
+C |   ~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+C | # SISVAT_GSn.vp        | #vp: OUTPUT/Verification: Snow   Properties   |
+C |                        |      unit 47, SubRoutines SISVAT_zSn, _GSn    |
+C | # stdout               | #wp: OUTPUT/Verification: Snow   Properties   |
+C |                        |      unit  6, SubRoutine  SISVAT_GSn          |
+C |                                                                        |
+C +------------------------------------------------------------------------+
+ 
+ 
+ 
+ 
+C +--Global Variables
+C +  ================
+
+      use VARphy
+      use VAR_SV
+      use VARdSV
+      use VAR0SV
+      use VARxSV
+      use VARtSV
+
+  
+      IMPLICIT NONE
+  
+     
+ 
+C +--INPUT/OUTPUT
+C +  ------------
+ 
+ 
+C +--OUTPUT
+C +  ------
+ 
+      integer   dt__SV2
+ 
+ 
+C +--Local  Variables
+C +  ================
+ 
+      logical   vector                        !
+      integer   ikl                           !
+      integer   isn   ,isnp                   !
+      integer   istoOK                        !
+      real      G1_bak,G2_bak                 ! Old Values of G1, G2
+      real      ro_dry(knonv,      nsno)      ! Dry Density            [g/cm3]
+      real      etaSno(knonv,      nsno)      ! Liquid Water Content   [g/cm2]
+      real      SnMass(knonv)                 ! Snow   Mass            [kg/m2]
+      real      dTsndz                        ! Temperature Gradient
+      real      sWater                        !        Water Content       [%]
+      real      exp1Wa                        !
+      real      dDENDR                        ! Dendricity Increment
+      real      DENDRn                        ! Normalized Dendricity
+      real      SPHERn                        ! Normalized Sphericity
+      real      Wet_OK                        ! Wet Metamorphism Switch
+      real      OK__DE                        !
+      real      OK__wd                        ! New G*, from wet Dendritic
+      real      G1__wd                        ! New G1, from wet Dendritic
+      real      G2__wd                        ! New G2, from wet Dendritic
+      real      OKlowT                        !
+      real      facVap                        !
+      real      OK_ldd                        !
+      real      G1_ldd                        !
+      real      G2_ldd                        !
+      real      DiamGx                        !
+      real      DiamOK                        !
+      real      No_Big                        !
+      real      dSPHER                        !
+      real      SPHER0                        !
+      real      SPHbig                        !
+      real      G1_lds                        !
+      real      OK_mdT                        !
+      real      OKmidT                        !
+      real      OKhigT                        !
+      real      OK_mdd                        !
+      real      G1_mdd                        !
+      real      G2_mdd                        !
+      real      G1_mds                        !
+      real      OK_hdd                        !
+      real      G1_hdd                        !
+      real      G2_hdd                        !
+      real      OK_hds                        !
+      real      G1_hds                        !
+      real      T1__OK,T2__OK                 !
+      real      T3_xOK,T3__OK,T3_nOK          !
+      real      ro1_OK,ro2_OK                 !
+      real      dT1_OK,dT2_OK,dT3xOK,dT3_OK   !
+      real      dT4xOK,dT4_OK,dT4nOK,AngSno   !
+      real      G2_hds,SphrOK,HISupd          !
+      real      H1a_OK,H1b_OK,H1__OK          !
+      real      H23aOK,H23bOK,H23_OK          !
+      real      H2__OK,H3__OK                 !
+      real      H45_OK,H4__OK,H5__OK          !
+      real      ViscSn,OK_Liq,OK_Ang,OKxLiq   !
+      real      dSnMas,dzsnew,rosnew,rosmax,smb_old,smb_new
+      real      zn_old,zn_new
+ 
+      real      epsi5                         ! Alpha ev67 single precision	
+      real      vdiam1                        ! Small Grains Min.Diam.[.0001m]
+      real      vdiam2                        ! Spher.Variat.Max Diam.    [mm]
+      real      vdiam3                        ! Min.Diam.|Limit Spher.    [mm]
+      real      vdiam4                        ! Min.Diam.|Viscosity Change
+      real      vsphe1                        ! Max Sphericity
+      real      vsphe2                        ! Low T Metamorphism  Coeff.
+      real      vsphe3                        ! Max.Sphericity (history=1)
+      real      vsphe4                        ! Min.Sphericity=>history=1
+      real      vtang1,vtang2,vtang3,vtang4   ! Temperature Contribution
+      real      vtang5,vtang6,vtang7,vtang8   !
+      real      vtang9,vtanga,vtangb,vtangc   !
+      real      vrang1,vrang2                 ! Density     Contribution
+      real      vgang1,vgang2,vgang3,vgang4   ! Grad(T)     Contribution
+      real      vgang5,vgang6,vgang7,vgang8   !
+      real      vgang9,vganga,vgangb,vgangc   !
+      real      vgran6                        ! Max.Sphericity for Settling
+      real      vtelv1                        ! Threshold | history = 2, 3
+      real       vvap1                        ! Vapor Pressure Coefficient
+      real       vvap2                        ! Vapor Pressure Exponent
+      real      vgrat1                        ! Boundary weak/mid   grad(T)
+      real      vgrat2                        ! Boundary mid/strong grad(T)
+      real         vfi                        ! PHI,         strong grad(T)
+      real      vvisc1,vvisc2,vvisc3,vvisc4   ! Viscosity Coefficients
+      real      vvisc5,vvisc6,vvisc7          ! id., wet Snow
+      real      rovisc                        ! Wet Snow Density  Influence
+      real        vdz3                        ! Maximum Layer Densification
+      real      OK__ws                        ! New G2
+      real      G1__ws                        ! New G1, from wet Spheric
+      real      G2__ws                        ! New G2, from wet Spheric
+      real      husi_0,husi_1,husi_2,husi_3   ! Constants for New G2
+      real      vtail1,vtail2                 ! Constants for New G2
+      real      frac_j                        ! Time Step            [Day]
+ 
+      real       vdent1                       ! Wet Snow Metamorphism
+      integer   nvdent1                       ! (Coefficients for
+      integer   nvdent2                       !           Dendricity)
+ 
+C +--Snow Properties: IO
+C +  ~~~~~~~~~~~~~~~~~~~
+! #vp real      G_curr(18),Gcases(18)
+! #vp common   /GSnLOC/    Gcases
+! #wp real                 D__MAX
+! #wp common   /GSnMAX/    D__MAX
+ 
+ 
+C +--DATA
+C +  ====
+ 
+      data       vector/.true./               ! Vectorization  Switch
+      data       vdent1/ 0.5e8/               ! Wet Snow Metamorphism
+cXF                      tuned for Greenland (2.e8=old value)
+      data      nvdent1/ 3   /                ! (Coefficients for
+      data      nvdent2/16   /                !           Dendricity)
+ 
+      data       husi_0 /20.      /           !   10  * 2
+      data       husi_1 / 0.23873 /           ! (3/4) /pi
+      data       husi_2 / 4.18880 /           ! (4/3) *pi
+      data       husi_3 / 0.33333 /           !  1/3
+      data       vtail1 / 1.28e-08/           !  Wet Metamorphism
+      data       vtail2 / 4.22e-10/           ! (NON Dendritic / Spheric)
+ 
+      data       epsi5  / 1.0e-5  /           !
+ 
+      data       vdiam1 / 4.0     /           ! Small Grains Min.Diameter
+ 
+      data       vdiam2 / 0.5     /           ! Spher.Variat.Max Diam.[mm]
+      data       vdiam3 / 3.0     /           ! Min.Diam.|Limit Spher.[mm]
+      data       vdiam4 / 2.0     /           ! Min.Diam.|Viscosity Change
+ 
+      data       vsphe1 / 1.0     /           ! Max Sphericity
+      data       vsphe2 / 1.0e9   /           ! Low T Metamorphism  Coeff.
+      data       vsphe3 / 0.5     /           ! Max.Sphericity (history=1)
+      data       vsphe4 / 0.1     /           ! Min.Sphericity=>history=1
+ 
+      data       vgran6 / 51.     /           ! Max.Sphericity for Settling
+      data       vtelv1 / 5.e-1   /           ! Threshold | history = 2, 3
+ 
+      data        vvap1 /-6.e3    /           ! Vapor Pressure Coefficient
+      data        vvap2 / 0.4     /           ! Vapor Pressure Exponent
+ 
+      data       vgrat1 /0.05     /           ! Boundary weak/mid   grad(T)
+      data       vgrat2 /0.15     /           ! Boundary mid/strong grad(T)
+      data          vfi /0.09     /           ! PHI,         strong grad(T)
+ 
+      data       vvisc1 / 0.70    /           ! Viscosity Coefficients
+      data       vvisc2 / 1.11e5  /           !
+      data       vvisc3 /23.00    /           !
+      data       vvisc4 / 0.10    /           !
+      data       vvisc5 / 1.00    /           ! id., wet Snow
+      data       vvisc6 / 2.00    /           !
+      data       vvisc7 /10.00    /           !
+      data       rovisc / 0.25    /           ! Wet Snow Density  Influence
+      data         vdz3 / 0.30    /           ! Maximum Layer Densification
+ 
+ 
+C +--DATA (Coefficient Fonction fort Gradient Marbouty)
+C +  --------------------------------------------------
+ 
+      data       vtang1 /40.0/                ! Temperature Contribution
+      data       vtang2 / 6.0/                !
+      data       vtang3 /22.0/                !
+      data       vtang4 / 0.7/                !
+      data       vtang5 / 0.3/                !
+      data       vtang6 / 6.0/                !
+      data       vtang7 / 1.0/                !
+      data       vtang8 / 0.8/                !
+      data       vtang9 /16.0/                !
+      data       vtanga / 0.2/                !
+      data       vtangb / 0.2/                !
+      data       vtangc /18.0/                !
+ 
+      data       vrang1 / 0.40/               ! Density     Contribution
+      data       vrang2 / 0.15/               !
+ 
+      data       vgang1 / 0.70/               ! Grad(T)     Contribution
+      data       vgang2 / 0.25/               !
+      data       vgang3 / 0.40/               !
+      data       vgang4 / 0.50/               !
+      data       vgang5 / 0.10/               !
+      data       vgang6 / 0.15/               !
+      data       vgang7 / 0.10/               !
+      data       vgang8 / 0.55/               !
+      data       vgang9 / 0.65/               !
+      data       vganga / 0.20/               !
+      data       vgangb / 0.85/               !
+      data       vgangc / 0.15/               !
+ 
+! #wp data       D__MAX / 4.00/               !
+ 
+ 
+C +-- 1. Metamorphoses dans les Strates
+C +      Metamorphism
+C +      ==============================
+ 
+      dt__SV2= dt__SV
+      frac_j = dt__SV2 / 86400.                        ! Time Step [Day]
+ 
+      zn4_SV = 0
+ 
+ 
+C +-- 1.1 Initialisation: teneur en eau liquide et gradient de temperature
+C +   ------------------  liquid water content and temperature gradient
+ 
+       DO ikl=1,knonv
+        DO   isn=1,isnoSV(ikl)
+ 
+          ro_dry(ikl,isn) = 1.e-3 *ro__SV(ikl,isn)    ! Dry Density
+     .                    *(1.    -eta_SV(ikl,isn))   !         [g/cm3]
+          etaSno(ikl,isn) = 1.e-1 *dzsnSV(ikl,isn)    ! Liquid Water
+     .                    *        ro__SV(ikl,isn)    ! Content [g/cm2]
+     .                    *        eta_SV(ikl,isn)    !
+        END DO
+      END DO
+ 
+c!$OMP PARALLEL DO default(firstprivate)
+c!$OMP.shared (/xSISVAT_I/,/xSISVAT_R/,/SoR0SV/,/SoI0SV/,/Sn_dSV/)
+       DO ikl=1,knonv
+        DO   isn=1,isnoSV(ikl)
+          isnp   = min(isn+1,isnoSV(ikl))
+ 
+          dTsndz = abs( (TsisSV(ikl,isnp)-TsisSV(ikl,isn-1)) *2.e-2
+     .            /max(((dzsnSV(ikl,isnp)+dzsnSV(ikl,isn)  )
+     .                 *(           isnp -           isn)
+     .                 +(dzsnSV(ikl,isn )+dzsnSV(ikl,isn-1))),epsi))
+C +...    Factor 1.d-2 for Conversion K/m --> K/cm
+ 
+ 
+C +-- 1.2 Metamorphose humide
+C +       Wet Snow Metamorphism
+C +       ---------------------
+ 
+          Wet_OK = max(zero,sign(unun,eta_SV(ikl,isn)-epsi))
+ 
+ 
+C +--     Vitesse de diminution de la dendricite
+C +       Rate of the dendricity decrease
+C +       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+          sWater=1.d-1*ro__SV(ikl,isn)*eta_SV(ikl,isn)
+     .       /max(epsi,ro_dry(ikl,isn))
+C +...    sWater:Water Content [%]
+C +              1.d-1= 1.d2(1->%) * 1.d-3(ro__SV*eta_SV:kg/m3->g/cm3)
+ 
+          exp1Wa=   sWater**nvdent1
+          dDENDR=max(exp1Wa/nvdent2,vdent1*exp(vvap1/TfSnow))
+ 
+C +-- 1.2.1 Cas dendritique/dendritic Case
+C +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+          OK__wd=max(zero,                            !
+     .               sign(unun,-G1snSV(ikl,isn)       !
+     .                         -epsi           ))     !
+ 
+          DENDRn=-G1snSV(ikl,isn)/G1_dSV  ! Normalized Dendricity (+)
+          SPHERn= G2snSV(ikl,isn)/G1_dSV  ! Normalized Sphericity
+          DENDRn= DENDRn -dDENDR *frac_j  ! New        Dendricity (+)
+          SPHERn= SPHERn +dDENDR *frac_j  ! New        Sphericity
+ 
+          OK__DE=max(zero,                            ! IF 1.,
+     .               sign(unun, DENDRn                ! NO change
+     .                         -epsi           ))     ! Dendr. -> Spheric
+ 
+          G1__wd=OK__DE *    (      -DENDRn*G1_dSV)   ! Dendritic
+     .      +(1.-OK__DE)* min(G1_dSV,SPHERn*G1_dSV)   ! Dendr. -> Spheric
+          G2__wd=OK__DE * min(G1_dSV,SPHERn*G1_dSV)   ! Spheric
+     .      +(1.-OK__DE)*(ADSdSV-min(SPHERn,vsphe1))  ! Spher. -> Size
+ 
+C +-- 1.2.2 Cas non dendritique non completement spherique
+C +         Evolution de la Sphericite seulement.
+C +         Non dendritic and not completely spheric Case
+C +         Evolution of    Sphericity only (not size)
+C +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+          OK__ws=max(zero,                            !
+     .               sign(unun, G1_dSV                !
+     .                         -epsi5                 !
+     .                         -G1snSV(ikl,isn)))     !
+ 
+          SPHERn= G1snSV(ikl,isn)/G1_dSV
+          SPHERn= SPHERn +dDENDR *frac_j
+          G1__ws=         min(G1_dSV,SPHERn*G1_dSV)
+ 
+C +-- 1.2.3 Cas non dendritique et spherique / non dendritic and spheric
+C +         Evolution de la Taille seulement / Evolution of Size only
+C +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+          G2__ws =  husi_0
+     .           *( husi_1
+     .            *(husi_2 *( G2snSV(ikl,isn)/husi_0)**3
+     .                      +(vtail1 +vtail2 *exp1Wa    )*dt__SV2))
+     .           ** husi_3
+ 
+ 
+C +-- 1.3 Metamorposes seches / Dry Metamorphism
+C +       --------------------------------------
+ 
+ 
+C +-- 1.3.1 Calcul Metamorphose faible/low Gradient (0.00-0.05 deg/cm)
+C +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+          OKlowT=max(zero,                            !
+     .               sign(unun, vgrat1                !
+     .                         -dTsndz         ))     !
+ 
+          facVap=exp(vvap1/TsisSV(ikl,isn))
+ 
+C +-- 1.3.1.1 Cas dendritique / dendritic Case
+ 
+          OK_ldd=max(zero,                            !
+     .               sign(unun,-G1snSV(ikl,isn)       !
+     .                         -epsi           ))     !
+ 
+          DENDRn=-G1snSV(ikl,isn)     /G1_dSV
+          SPHERn= G2snSV(ikl,isn)     /G1_dSV
+          DENDRn= DENDRn-vdent1*facVap*frac_j
+          SPHERn= SPHERn+vsphe2*facVap*frac_j
+ 
+          OK__DE=max(zero,                            ! IF 1.,
+     .               sign(unun, DENDRn                ! NO change
+     .                         -epsi           ))     ! Dendr. -> Spheric
+ 
+          G1_ldd= OK__DE *    (      -DENDRn*G1_dSV)  ! Dendritic
+     .       +(1.-OK__DE)* min(G1_dSV,SPHERn*G1_dSV)  ! Dendr. -> Spheric
+          G2_ldd= OK__DE * min(G1_dSV,SPHERn*G1_dSV)  ! Spheric
+     .       +(1.-OK__DE)*(ADSdSV-min(SPHERn,vsphe1)) ! Spher. -> Size
+ 
+C +-- 1.3.1.2 Cas non dendritique / non dendritic Case
+ 
+          SPHERn=G1snSV(ikl,isn)/G1_dSV
+          DiamGx=G2snSV(ikl,isn)*0.1
+ 
+          istoOK=min( abs(istoSV(ikl,isn)-
+     .                    istdSV(1)      ),1)         ! zero if istoSV = 1
+          DiamOK=max(zero,  sign(unun,vdiam2-DiamGx))
+          No_Big=    istoOK+DiamOK
+          No_Big=min(No_Big,unun)
+ 
+          dSPHER=           vsphe2*facVap*frac_j      !
+          SPHER0=    SPHERn+dSPHER                    ! small grains
+          SPHbig=    SPHERn+dSPHER                    ! big   grains
+     .        *exp(min(zero,vdiam3-G2snSV(ikl,isn)))  ! (history = 2 or 3)
+          SPHbig=       min(vsphe3,SPHbig)            ! limited sphericity
+          SPHERn= No_Big *  SPHER0
+     .      + (1.-No_Big)*  SPHbig
+ 
+          G1_lds=       min(G1_dSV,SPHERn*G1_dSV)
+ 
+C +-- 1.3.2 Calcul Metamorphose Gradient Moyen/Moderate (0.05-0.15)
+C +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+          OK_mdT=max(zero,                            !
+     .               sign(unun, vgrat2                !
+     .                         -dTsndz))              !
+          OKmidT=               OK_mdT  *(1.-OKlowT)  !
+          OKhigT=          (1. -OK_mdT) *(1.-OKlowT)  !
+ 
+          facVap=vdent1*exp(vvap1/TsisSV(ikl,isn))
+     .                 *   (1.e2 *dTsndz)**vvap2
+ 
+C +-- 1.3.2.1 cas dendritique / dendritic case.
+ 
+          OK_mdd=max(zero,                            !
+     .               sign(unun,-G1snSV(ikl,isn)       !
+     .                         -epsi           ))     !
+ 
+          DENDRn=-G1snSV(ikl,isn)/G1_dSV
+          SPHERn= G2snSV(ikl,isn)/G1_dSV
+          DENDRn= DENDRn - facVap*frac_j
+          SPHERn= SPHERn - facVap*frac_j
+ 
+          OK__DE=max(zero,                            ! IF 1.,
+     .               sign(unun, DENDRn                ! NO change
+     .                         -epsi           ))     ! Dendr. -> Spheric
+ 
+          G1_mdd= OK__DE *    (      -DENDRn*G1_dSV)  ! Dendritic
+     .       +(1.-OK__DE)* max(zero  ,SPHERn*G1_dSV)  ! Dendr. -> Spheric
+          G2_mdd= OK__DE * max(zero  ,SPHERn*G1_dSV)  ! Spheric
+     .       +(1.-OK__DE)*(ADSdSV-max(SPHERn,zero  )) ! Spher. -> Size
+ 
+C +-- 1.3.2.2 Cas non dendritique / non dendritic Case
+ 
+          SPHERn=G1snSV(ikl,isn)/G1_dSV
+          SPHERn=         SPHERn-facVap*frac_j
+          G1_mds=max(zero,SPHERn*G1_dSV)
+ 
+C +-- 1.3.3 Calcul Metamorphose fort / high Gradient
+C +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+          facVap=vdent1*exp(vvap1/TsisSV(ikl,isn))
+     .                 *   (1.e2 *dTsndz)**vvap2
+ 
+C +-- 1.3.3.1 Cas dendritique / dendritic Case
+ 
+          OK_hdd=max(zero,                            !
+     .               sign(unun,-G1snSV(ikl,isn)       !
+     .                         -epsi           ))     !
+ 
+          DENDRn=-G1snSV(ikl,isn)/G1_dSV              !
+          SPHERn= G2snSV(ikl,isn)/G1_dSV              !
+          DENDRn= DENDRn - facVap*frac_j              !
+          SPHERn= SPHERn - facVap*frac_j              ! Non dendritic
+C +                                                   ! and angular
+          OK__DE=max(zero,                            ! IF 1.,
+     .               sign(unun, DENDRn                ! NO change
+     .                         -epsi  ))              ! Dendr. -> Spheric
+ 
+          G1_hdd= OK__DE *    (      -DENDRn*G1_dSV)  ! Dendritic
+     .       +(1.-OK__DE)* max(zero  ,SPHERn*G1_dSV)  ! Dendr. -> Spheric
+          G2_hdd= OK__DE * max(zero  ,SPHERn*G1_dSV)  ! Spheric
+     .       +(1.-OK__DE)*(ADSdSV-max(SPHERn,zero  )) ! Spher. -> Size
+ 
+C +-- 1.3.3.2 Cas non dendritique non completement anguleux.
+C +           non dendritic and spericity gt. 0
+ 
+          OK_hds=max(zero,                            !
+     .               sign(unun, G1snSV(ikl,isn)       !
+     .                         -epsi           ))     !
+ 
+          SPHERn= G1snSV(ikl,isn)/G1_dSV
+          SPHERn= SPHERn - facVap*frac_j
+          G1_hds= max(zero,SPHERn*G1_dSV)
+ 
+C +-- 1.3.3.3 Cas non dendritique et anguleux
+C +           dendritic and spericity = 0.
+ 
+          T1__OK = max(zero,sign(unun,TsisSV(ikl,isn)-TfSnow+vtang1))
+          T2__OK = max(zero,sign(unun,TsisSV(ikl,isn)-TfSnow+vtang2))
+          T3_xOK = max(zero,sign(unun,TsisSV(ikl,isn)-TfSnow+vtang3))
+          T3__OK =                    T3_xOK  * (1. - T2__OK)
+          T3_nOK =              (1. - T3_xOK) * (1. - T2__OK)
+          ro1_OK = max(zero,sign(unun,vrang1-ro_dry(ikl,isn)))
+          ro2_OK = max(zero,sign(unun,ro_dry(ikl,isn)-vrang2))
+          dT1_OK = max(zero,sign(unun,vgang1-dTsndz         ))
+          dT2_OK = max(zero,sign(unun,vgang2-dTsndz         ))
+          dT3xOK = max(zero,sign(unun,vgang3-dTsndz         ))
+          dT3_OK =                    dT3xOK  * (1. - dT2_OK)
+          dT4xOK = max(zero,sign(unun,vgang4-dTsndz         ))
+          dT4_OK =                    dT4xOK  * (1. - dT3_OK)
+     .                                        * (1. - dT2_OK)
+          dT4nOK =              (1. - dT4xOK) * (1. - dT3_OK)
+     .                                        * (1. - dT2_OK)
+ 
+C +-- Influence de la Temperature /Temperature Influence
+C +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+          AngSno =
+     .      T1__OK                                                       ! 11
+     .    *(T2__OK*(vtang4+vtang5*(TfSnow       -TsisSV(ikl,isn))        ! 12
+     .                    /vtang6)                                       !
+     .     +T3__OK*(vtang7-vtang8*(TfSnow-vtang2-TsisSV(ikl,isn))        ! 13
+     .                    /vtang9)                                       !
+     .     +T3_nOK*(vtanga-vtangb*(TfSnow-vtang3-TsisSV(ikl,isn))        ! 14
+     .                    /vtangc))                                      !
+ 
+C +-- Influence de la Masse Volumique /Density Influence
+C +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+     .    * ro1_OK
+     .        *(   ro2_OK*(1. - (ro_dry(ikl,isn)-vrang2)                 !
+     .                                  /(vrang1-vrang2))                !
+     .         +1.-ro2_OK                                )               !
+ 
+C +-- Influence du Gradient de Temperature /Temperature Gradient Influence
+C +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+     .        *(   dT1_OK*(dT2_OK*vgang5*(dTsndz-vgang6)                 ! 15
+     .                                  /(vgang2-vgang6)                 !
+     .                    +dT3_OK*vgang7                                 ! 16
+     .                    +dT4_OK*vgang9                                 ! 17
+     .                    +dT4nOK*vgangb                )                ! 18
+     .         +1.-dT1_OK                                )               !
+     .    + ro1_OK
+     .        *    dT1_OK*(dT3_OK*vgang8*(dTsndz-vgang2)
+     .                                  /(vgang3-vgang2)
+     .                    +dT4_OK*vganga*(dTsndz-vgang3)
+     .                                  /(vgang4-vgang3)
+     .                    +dT4nOK*vgangc*(dTsndz-vgang4)
+     .                                  /(vgang1-vgang4))
+ 
+          G2_hds = G2snSV(ikl,isn) + 1.d2 *AngSno*vfi     *frac_j
+ 
+ 
+C +--New Properties
+C +  --------------
+ 
+          G1_bak          = G1snSV(ikl,isn)
+          G2_bak          = G2snSV(ikl,isn)
+ 
+          G1snSV(ikl,isn) = Wet_OK * (    OK__wd             *G1__wd    !  1
+     .                               +(1.-OK__wd)*    OK__ws *G1__ws    !  2
+     .                               +(1.-OK__wd)*(1.-OK__ws)*G1_bak)   !  3
+     .               +(1. - Wet_OK)                                     !
+     .                *(    OKlowT  *(    OK_ldd             *G1_ldd    !  4
+     .                               +(1.-OK_ldd)            *G1_lds)   !  5
+     .                    + OKmidT  *(    OK_mdd             *G1_mdd    !  6
+     .                               +(1.-OK_mdd)            *G1_mds)   !  7
+     .                    + OKhigT  *(    OK_hdd             *G1_hdd    !  8
+     .                               +(1.-OK_hdd)*    OK_hds *G1_hds    !  9
+     .                               +(1.-OK_hdd)*(1.-OK_hds)*G1_bak))  ! 10
+ 
+cXF
+      if(G1snSV(ikl,isn)<0.1)
+     .    G2_hds = G2snSV(ikl,isn) + 1.d1 *AngSno*vfi     *frac_j
+cXF
+ 
+ 
+          G2snSV(ikl,isn) = Wet_OK * (    OK__wd             *G2__wd    !  1
+     .                               +(1.-OK__wd)*    OK__ws *G2_bak    !  2
+     .                               +(1.-OK__wd)*(1.-OK__ws)*G2__ws)   !  3
+     .               +(1. - Wet_OK)                                     !
+     .                *(    OKlowT  *(    OK_ldd             *G2_ldd    !  4
+     .                               +(1.-OK_ldd)            *G2_bak)   !  5
+     .                    + OKmidT  *(    OK_mdd             *G2_mdd    !  6
+     .                               +(1.-OK_mdd)            *G2_bak)   !  7
+     .                    + OKhigT  *(    OK_hdd             *G2_hdd    !  8
+     .                               +(1.-OK_hdd)*    OK_hds *G2_bak    !  9
+     .                               +(1.-OK_hdd)*(1.-OK_hds)*G2_hds))  ! 10
+ 
+C +--Snow Properties: IO Set Up
+C +  ~~~~~~~~~~~~~~~~~~~~~~~~~~
+! #vp     G_curr( 1) =     Wet_OK             *    OK__wd
+! #vp     G_curr( 2) =     Wet_OK             *(1.-OK__wd)*    OK__ws
+! #vp     G_curr( 3) =     Wet_OK             *(1.-OK__wd)*(1.-OK__ws)
+! #vp     G_curr( 4) = (1.-Wet_OK)*    OKlowT *    OK_ldd
+! #vp     G_curr( 5) = (1.-Wet_OK)*    OKlowT *(1.-OK_ldd)
+! #vp     G_curr( 6) = (1.-Wet_OK)*    OKmidT *    OK_mdd
+! #vp     G_curr( 7) = (1.-Wet_OK)*    OKmidT *(1.-OK_mdd)
+! #vp     G_curr( 8) = (1.-Wet_OK)*    OKhigT *    OK_hdd
+! #vp     G_curr( 9) = (1.-Wet_OK)*    OKhigT *(1.-OK_hdd)*    OK_hds
+! #vp     G_curr(10) = (1.-Wet_OK)*    OKhigT *(1.-OK_hdd)*(1.-OK_hds)
+! #vp     G_curr(11) =     T1__OK                         * G_curr(10)
+! #vp     G_curr(12) =     T2__OK                         * G_curr(10)
+! #vp     G_curr(13) =     T3__OK                         * G_curr(10)
+! #vp     G_curr(14) =     T3_nOK                         * G_curr(10)
+! #vp     G_curr(15) =     ro1_OK*     dT1_OK *    dT2_OK * G_curr(10)
+! #vp     G_curr(16) =     ro1_OK*     dT1_OK *    dT3_OK * G_curr(10)
+! #vp     G_curr(17) =     ro1_OK*     dT1_OK *    dT4_OK * G_curr(10)
+! #vp     G_curr(18) =     ro1_OK*     dT1_OK *    dT4nOK * G_curr(10)
+ 
+! #vp     Gcases( 1) = max(Gcases( 1),G_curr( 1))
+! #vp     Gcases( 2) = max(Gcases( 2),G_curr( 2))
+! #vp     Gcases( 3) = max(Gcases( 3),G_curr( 3))
+! #vp     Gcases( 4) = max(Gcases( 4),G_curr( 4))
+! #vp     Gcases( 5) = max(Gcases( 5),G_curr( 5))
+! #vp     Gcases( 6) = max(Gcases( 6),G_curr( 6))
+! #vp     Gcases( 7) = max(Gcases( 7),G_curr( 7))
+! #vp     Gcases( 8) = max(Gcases( 8),G_curr( 8))
+! #vp     Gcases( 9) = max(Gcases( 9),G_curr( 9))
+! #vp     Gcases(10) = max(Gcases(10),G_curr(10))
+! #vp     Gcases(11) = max(Gcases(11),G_curr(11))
+! #vp     Gcases(12) = max(Gcases(12),G_curr(12))
+! #vp     Gcases(13) = max(Gcases(13),G_curr(13))
+! #vp     Gcases(14) = max(Gcases(14),G_curr(14))
+! #vp     Gcases(15) = max(Gcases(15),G_curr(15))
+! #vp     Gcases(16) = max(Gcases(16),G_curr(16))
+! #vp     Gcases(17) = max(Gcases(17),G_curr(17))
+! #vp     Gcases(18) = max(Gcases(18),G_curr(18))
+ 
+C +--Snow Properties: IO
+C +  ~~~~~~~~~~~~~~~~~~~
+! #vp     IF          (isn    .le.     isnoSV(ikl))
+! #vp.    write(47,471)isn            ,isnoSV(ikl)                    ,
+! #vp.                 TsisSV(ikl,isn),ro__SV(ikl,isn),eta_SV(ikl,isn),
+! #vp.                 G1_bak         ,G2_bak         ,istoSV(ikl,isn),
+! #vp.                 dTsndz,
+! #vp.                (       k ,k=1,18),
+! #vp.                (G_curr(k),k=1,18),
+! #vp.                (Gcases(k),k=1,18),
+! #vp.                 Wet_OK,OK__wd,G1__wd,G2__wd,
+! #vp.                     1.-OK__wd,OK__ws,G1__ws,1.-OK__ws,G2__ws,
+! #vp.              1.-Wet_OK,OKlowT,OK_ldd,G1_ldd,          G2_ldd,
+! #vp.                            1.-OK_ldd,G1_lds,
+! #vp.                        OKmidT,OK_mdd,G1_mdd,          G1_mdd,
+! #vp.                            1.-OK_mdd,G1_mds,
+! #vp.                        OKhigT,OK_hdd,G1_hdd,          G2_hdd,
+! #vp.                            1.-OK_hdd,OK_hds,          G1_hds,
+! #vp.                                             1.-OK_hds,G2_hds,
+! #vp.                 G1snSV(ikl,isn),
+! #vp.                 G2snSV(ikl,isn)
+
+        END DO
+      END DO
+c!$OMP END PARALLEL DO
+ 
+C +-- 2. Mise a Jour Variables Historiques (Cas non dendritique)
+C +      Update of the historical Variables
+C +      =======================================================
+ 
+      IF (vector)                                                   THEN
+cXF
+         DO  ikl=1,knonv
+          DO isn=1,isnoSV(ikl)
+          SphrOK = max(zero,sign(unun,       G1snSV(ikl,isn)))
+          H1a_OK = max(zero,sign(unun,vsphe4-G1snSV(ikl,isn)))
+          H1b_OK =     1   - min(1   ,       istoSV(ikl,isn))
+          H1__OK =                    H1a_OK*H1b_OK
+          H23aOK = max(zero,sign(unun,vsphe4-G1_dSV
+     .                                      +G1snSV(ikl,isn)))
+          H23bOK = max(zero,sign(unun,etaSno(ikl,isn)
+     .                      /max(epsi,dzsnSV(ikl,isn))
+     .                                      -vtelv1         ))
+          H23_OK =                    H23aOK*H23bOK
+          H2__OK =     1   - min(1   ,       istoSV(ikl,isn))
+          H3__OK =     1   - min(1   ,   abs(istoSV(ikl,isn)-istdSV(1)))
+          H45_OK = max(zero,sign(unun,TfSnow-TsisSV(ikl,isn)+epsi))
+          H4__OK =     1   - min(1   ,   abs(istoSV(ikl,isn)-istdSV(2)))
+          H5__OK =     1   - min(1   ,   abs(istoSV(ikl,isn)-istdSV(3)))
+ 
+          HISupd          =
+     .    SphrOK*(H1__OK                             *istdSV(1)
+     .       +(1.-H1__OK)*    H23_OK         *(H2__OK*istdSV(2)
+     .                                        +H3__OK*istdSV(3))
+     .       +(1.-H1__OK)*(1.-H23_OK) *H45_OK*(H4__OK*istdSV(4)
+     .                                        +H5__OK*istdSV(5)))
+          istoSV(ikl,isn) =   HISupd  +
+     .           (1.-min(unun,HISupd))               *istoSV(ikl,isn)
+        END DO
+        END DO
+      ELSE
+ 
+ 
+C +-- 2. Mise a Jour Variables Historiques (Cas non dendritique)
+C +      Update of the historical Variables
+C +      =======================================================
+ 
+        DO ikl=1,knonv
+        DO isn=iiceSV(ikl),isnoSV(ikl)
+          IF  (G1snSV(ikl,isn).ge.0.)                               THEN
+            IF(G1snSV(ikl,isn).lt.vsphe4.and.istoSV(ikl,isn).eq.0)  THEN
+                   istoSV(ikl,isn)=istdSV(1)
+            ELSEIF(G1_dSV-G1snSV(ikl,isn)         .lt.vsphe4.and.
+     .             etaSno(ikl,isn)/dzsnSV(ikl,isn).gt.vtelv1)       THEN
+              IF  (istoSV(ikl,isn).eq.0)
+     .             istoSV(ikl,isn)=   istdSV(2)
+              IF  (istoSV(ikl,isn).eq.istdSV(1))
+     .             istoSV(ikl,isn)=   istdSV(3)
+            ELSEIF(TsisSV(ikl,isn).lt.TfSnow)                       THEN
+              IF  (istoSV(ikl,isn).eq.istdSV(2))
+     .             istoSV(ikl,isn)=   istdSV(4)
+              IF  (istoSV(ikl,isn).eq.istdSV(3))
+     .             istoSV(ikl,isn)=   istdSV(5)
+            END IF
+          END IF
+        END DO
+        END DO
+      END IF
+ 
+ 
+C +-- 3. Tassement mecanique /mechanical Settlement
+C +      ==========================================
+ 
+        DO ikl=1,knonv
+          SnMass(ikl) = 0.
+        END DO
+cXF
+      DO ikl=1,knonv
+ 
+        smb_old = 0.
+         zn_old = 0
+        DO isn  = 1, isnoSV(ikl)
+        smb_old = smb_old + dzsnSV(ikl,isn) *ro__SV(ikl,isn)
+         zn_old = zn_old  + dzsnSV(ikl,isn)
+        ENDDO
+ 
+        DO   isn=isnoSV(ikl),1,-1
+          dSnMas     = 100.*dzsnSV(ikl,isn)*ro_dry(ikl,isn)
+          SnMass(ikl)=      SnMass(ikl)+0.5*dSnMas
+          ViscSn     =      vvisc1         *vvisc2
+     .               *exp(vvisc3           *ro_dry(ikl,isn)
+     .                   +vvisc4*abs(TfSnow-TsisSV(ikl,isn)))
+     .                                     *ro_dry(ikl,isn)/rovisc
+ 
+C +-- Changement de Viscosite si Teneur en Eau liquide
+C +   Change of the Viscosity if liquid Water Content
+C +   ------------------------------------------------
+ 
+          OK_Liq     =    max(zero,sign(unun,etaSno(ikl,isn)-epsi))
+          OK_Ang     =    max(zero,sign(unun,vgran6-G1snSV(ikl,isn)))
+     .                *(1-min(1   , abs(istoSV(ikl,isn)-istdSV(1))))
+! #wp     IF (G1snSV(ikl,isn).gt.0..AND.G1snSV(ikl,isn).lt.vsphe4
+! #wp.                             .AND.istoSV(ikl,isn).eq.     0)
+! #wp.    THEN
+! #wp       write(6,*) ikl,isn,' G1,G2,hist,OK_Ang  ',
+! #wp.          G1snSV(ikl,isn), G2snSV(ikl,isn),istoSV(ikl,isn),OK_Ang
+! #wp       stop "Grains anguleux mal d?finis"
+! #wp     END IF
+          OKxLiq     =    max(zero,sign(unun,vtelv1-etaSno(ikl,isn)
+     .                                    /max(epsi,dzsnSV(ikl,isn))))
+     .               *    max(0   ,sign(1   ,istoSV(ikl,isn)
+     .                                      -istdSV(1)      ))
+          ViscSn     =
+     .    ViscSn*(    OK_Liq/(vvisc5+vvisc6*etaSno(ikl,isn)
+     .                            /max(epsi,dzsnSV(ikl,isn)))
+     .           +(1.-OK_Liq)                               )
+     .          *(    OK_Ang*exp(min(ADSdSV,G2snSV(ikl,isn)-vdiam4))
+     .           +(1.-OK_Ang)                                       )
+     .          *(    OKxLiq*        vvisc7
+     .           +(1.-OKxLiq)              )
+ 
+ 
+C +-- Calcul nouvelle Epaisseur / new Thickness
+C +   -----------------------------------------
+ 
+          dzsnew         =
+     .    dzsnSV(ikl,isn)
+     .     *max(vdz3,
+     .         (unun-dt__SV2*max(SnMass(ikl)*cos(slopSV(ikl)),unun)
+     .                     /max(ViscSn                      ,epsi)))
+          rosnew         = ro__SV(ikl,isn) *dzsnSV(ikl,isn)
+     .                            /max(1e-10,dzsnew)
+          rosmax         = 1.   /( (1. -eta_SV(ikl,isn)) /ro_Ice
+     .                           +      eta_SV(ikl,isn)  /ro_Wat)
+          rosnew         = min(rosnew ,rosmax)
+          dzsnew         = dzsnSV(ikl,isn) *ro__SV(ikl,isn)
+     .                            /max(1e-10,rosnew)
+          ro__SV(ikl,isn)= rosnew
+          dzsnSV(ikl,isn)= dzsnew
+          ro_dry(ikl,isn)= ro__SV(ikl,isn)*(1.-eta_SV(ikl,isn))*1.e-3
+C +...    ro_dry: Dry Density (g/cm3)
+C +
+          SnMass(ikl)    = SnMass(ikl)+dSnMas*0.5
+        END DO
+ 
+        smb_new = 0.
+        DO isn  = 1, isnoSV(ikl)
+        smb_new = smb_new + dzsnSV(ikl,isn) *ro__SV(ikl,isn)
+        ENDDO
+ 
+        isn=1
+        if (dzsnSV(ikl,isn)>0.and.ro__SV(ikl,isn)>0) then
+        dzsnSV(ikl,isn) = dzsnSV(ikl,isn) +0.9999*(smb_old-smb_new)
+     .                  / ro__SV(ikl,isn)
+        endif
+ 
+         zn_new = 0
+        DO isn  = 1, isnoSV(ikl)
+         zn_new = zn_new  + dzsnSV(ikl,isn)
+        ENDDO
+        zn4_SV(ikl) = zn4_SV(ikl) + (zn_new - zn_old)
+ 
+      END DO
+ 
+
+ 
+      return
+      end
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_qsn.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_qsn.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_qsn.F	(revision 3792)
@@ -0,0 +1,722 @@
+ 
+ 
+      subroutine SISVAT_qSn
+     .                     (
+! #e1.                      EqSn_0,EqSn_1,EqSn_d
+! #m1.                     ,SIsubl,SImelt,SIrnof
+     .                     )
+ 
+C +------------------------------------------------------------------------+
+C | MAR          SISVAT_qSn                           Fri 29-Jul-2011  MAR |
+C |   SubRoutine SISVAT_qSn updates  the Snow Water Content                |
+C +------------------------------------------------------------------------+
+C |                                                                        |
+C |   PARAMETERS:  knonv: Total Number of columns =                        |
+C |   ^^^^^^^^^^        = Total Number of continental     grid boxes       |
+C |                     X       Number of Mosaic Cell per grid box         |
+C |                                                                        |
+C |   INPUT:   isnoSV   = total Nb of Ice/Snow Layers                      |
+C |   ^^^^^                                                                |
+C |                                                                        |
+C |   INPUT:   TaT_SV   : SBL Top    Temperature                       [K] |
+C |   ^^^^^    dt__SV   : Time Step                                    [s] |
+C |                                                                        |
+C |   INPUT /  drr_SV   : Rain Intensity                         [kg/m2/s] |
+C |   OUTPUT:  dzsnSV   : Snow Layer Thickness                         [m] |
+C |   ^^^^^^   eta_SV   : Snow Water Content                       [m3/m3] |
+C |            ro__SV   : Snow/Soil  Volumic Mass                  [kg/m3] |
+C |            TsisSV   : Soil/Ice Temperatures (layers -nsol,-nsol+1,..,0)|
+C |                     & Snow     Temperatures (layers  1,2,...,nsno) [K] |
+C |                                                                        |
+C |   OUTPUT:  SWS_SV   : Surficial Water Status                           |
+C |   ^^^^^^                                                               |
+C |            EExcsv   : Snow Energy in Excess, initial Forcing    [J/m2] |
+C |            EqSn_d   : Snow Energy in Excess, remaining          [J/m2] |
+C |            EqSn_0   : Snow Energy, before Phase Change          [J/m2] |
+C |            EqSn_1   : Snow Energy, after  Phase Change          [J/m2] |
+C |            SIsubl   : Snow sublimed/deposed Mass             [mm w.e.] |
+C |            SImelt   : Snow Melted           Mass             [mm w.e.] |
+C |            SIrnof   : Surficial Water + Run OFF Change       [mm w.e.] |
+C |                                                                        |
+C |   Internal Variables:                                                  |
+C |   ^^^^^^^^^^^^^^^^^^                                                   |
+C |                                                                        |
+C | # OPTIONS: #E0: IO for Verification: Energy       Budget               |
+C | # ^^^^^^^                                                              |
+C | #          #su: IO for Verification: Slush        Diagnostic           |
+C |                                                                        |
+C |                                                                        |
+C +------------------------------------------------------------------------+
+ 
+ 
+ 
+ 
+C +--Global Variables
+C +  ================
+
+      use VARphy
+      use VAR_SV
+      use VARdSV
+      use VAR0SV
+      use VARxSV
+      use VARySV
+
+      IMPLICIT NONE
+
+ 
+! Energy          Budget
+! ~~~~~~~~~~~~~~~~~~~~~~
+! #e1 real     EqSn_d(knonv)                 ! Energy in Excess, initial
+! #e1 real     EqSn_0(knonv)                 ! Snow Energy, befor Phase Change
+! #vm real     EqSn01(knonv)                 ! Snow Energy, after Phase Change
+! #vm real     EqSn02(knonv)                 ! Snow Energy, after Phase Change
+                                             !              .AND. Last Melting
+! #e1 real     EqSn_1(knonv)                 ! Snow Energy, after Phase Change
+                                             !              .AND. Mass Redistr.
+! Snow/Ice (Mass) Budget
+! ~~~~~~~~~~~~~~~~~~~~~~
+! #m1 real     SIsubl(knonv)                 ! Snow Deposed Mass
+! #m1 real     SImelt(knonv)                 ! Snow Melted  Mass
+! #m1 real     SIrnof(knonv)                 ! Local Surficial Water + Run OFF
+ 
+ 
+C +--Internal Variables
+C +  ==================
+ 
+      integer  ikl   ,isn                    !
+      integer  nh                            ! Non erodible Snow: up.lay.Index
+      integer  LayrOK                        ! 1 (0)  if In(Above) Snow Pack
+      integer  k_face                        ! 1 (0)  if Crystal(no) faceted
+      integer  LastOK                        ! 1 ==>  1! Snow Layer
+      integer  NOLayr                        ! 1     Layer  Update
+      integer  noSnow(knonv)                 ! Nb of Layers Updater
+      integer  kSlush                        ! Slush Switch
+      real     dTSnow                        ! Temperature                  [C]
+      real     EExdum(knonv)                 ! Energy in Excess when no Snow
+      real     OKmelt                        ! 1 (0)  if        (no) Melting
+      real     EnMelt                        ! Energy in excess, for Melting
+      real     SnHLat                        ! Energy consumed   in  Melting
+      real     AdEnrg,B_Enrg                 ! Additional Energy from  Vapor
+      real     dzVap0,dzVap1                 ! Vaporized Thickness          [m]
+      real     dzMelt(knonv)                 ! Melted    Thickness          [m]
+      real     rosDry                        ! Snow volumic Mass if no Water in
+      real     PorVol                        ! Pore volume
+      real     PClose                        ! Pore Hole Close OFF Switch
+      real     SGDiam                        !      Snow Grain Diameter
+      real     SGDmax                        ! Max. Snow Grain Diameter
+      real     rWater                        ! Retained Water           [kg/m2]
+      real     drrNEW                        ! New available Water      [kg/m2]
+      real     rdzNEW                        ! Snow          Mass       [kg/m2]
+      real     rdzsno                        ! Snow          Mass       [kg/m2]
+      real     EnFrez                        ! Energy Release    in  Freezing
+      real     WaFrez                        ! Water  consumed   in  Melting
+      real     RapdOK                        ! 1. ==> Snow melts rapidly
+      real     ThinOK                        ! 1. ==> Snow Layer is thin
+      real     dzepsi                        ! Minim. Snow Layer Thickness (!)
+      real     dz_Min                        ! Minim. Snow Layer Thickness
+      real     z_Melt                        ! Last (thin) Layer Melting
+      real     rusnew                        ! Surficial Water Thickness   [mm]
+      real     zWater                        ! Max Slush Water Thickness   [mm]
+      real     zSlush                        !     Slush Water Thickness   [mm]
+      real     ro_new                        ! New Snow/ice  Density    [kg/m3]
+      real     zc,zt                         ! Non erod.Snow Thickness[mm w.e.]
+      real     rusnSV0(knonv)
+      real     Tsave
+ 
+C +--OUTPUT of SISVAT Trace Statistics (see assignation in PHY_SISVAT)
+C +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      integer             isnnew,isinew,isnUpD,isnitr
+ 
+! OUTPUT in SISVAT at specified i,j,k,n (see assignation in PHY_SISVAT)
+! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+! #wx integer             iSV_v1,jSV_v1,nSV_v1,kSV_v1,lSV_v1
+! #wx common/SISVAT_EV/   iSV_v1,jSV_v1,nSV_v1,kSV_v1,lSV_v1
+ 
+C +--Energy and Mass Budget
+C +  ~~~~~~~~~~~~~~~~~~~~~~
+! #vm real     WqSn_0(knonv)                 ! Snow Water+Forcing  Initial
+! #vm real     WqSn_1(knonv)                 ! Snow Water+Forcing, Final
+! #vm logical         emopen                 ! IO   Switch
+! #vm common/Se_qSn_L/emopen                 !
+! #vm integer         no_err                 !
+! #vm common/Se_qSn_I/no_err                 !
+! #vm real     hourer,timeer                 !
+! #vm common/Se_qSn_R/timeer                 !
+ 
+C +--Slush Diagnostic: IO
+C +  ~~~~~~~~~~~~~~~~~~~~
+! #vu logical         su_opn                 ! IO   Switch
+! #vu common/SI_qSn_L/su_opn                 !
+ 
+ 
+C +--DATA
+C +  ====
+ 
+      data      dzepsi/0.0001/                ! Minim. Snow Layer Thickness (!)
+c #?? data      dz_Min/0.005/                 ! Minim. Snow Layer Thickness
+c ... Warning: Too high for Col de Porte: precludes 1st snow (layer) apparition
+      data      dz_Min/2.5e-3/                ! Minim. Snow Layer Thickness
+      data      SGDmax/0.003/                 ! Maxim. Snow Grain Diameter  [m]
+                                              ! (Rowe et al. 1995, JGR p.16268)
+ 
+C +--Energy Budget (IN)
+C +  ==================
+ 
+! #e1   DO ikl=1,knonv
+! #e1     EqSn_0(ikl) = 0.
+! #e1   END DO
+! #e1 DO   isn=nsno,1,-1
+! #e1   DO ikl=1,knonv
+! #e1     EqSn_0(ikl) = EqSn_0(ikl) + ro__SV(ikl,isn) *dzsnSV(ikl,isn)
+! #e1.                *(Cn_dSV      *(TsisSV(ikl,isn) -TfSnow         )
+! #e1.                 -Lf_H2O      *(1.              -eta_SV(ikl,isn)))
+! #e1   END DO
+! #e1 END DO
+ 
+ 
+C +--Water  Budget (IN)
+C +  ==================
+ 
+! #vm   DO ikl=1,knonv
+! #vm     WqSn_0(ikl) = drr_SV(ikl) * dt__SV
+! #vm.                 +rusnSV(ikl)
+! #vm   END DO
+! #vm DO   isn=nsno,1,-1
+! #vm   DO ikl=1,knonv
+! #vm     WqSn_0(ikl) = WqSn_0(ikl) + ro__SV(ikl,isn) *dzsnSV(ikl,isn)
+! #vm   END DO
+! #vm END DO
+ 
+ 
+C +--Snow Melt Budget
+C +  ================
+ 
+! #m1   DO ikl=1,knonv
+! #m1     SImelt(ikl) = 0.
+! #m1     SIrnof(ikl) = rusnSV(ikl) + RnofSV(ikl) * dt__SV
+! #m1   END DO
+ 
+ 
+C +--Initialization
+C +  ==============
+ 
+      DO ikl=1,knonv
+        noSnow(ikl)   = 0                   ! Nb of Layers Updater
+        ispiSV(ikl)   = 0                   ! Pore Hole Close OFF Index
+                                            ! (assumed to be the Top of
+                                            !  the surimposed Ice Layer)
+        zn5_SV(ikl)   = 0.
+        rusnSV0(ikl)  = 0.
+
+      END DO
+ 
+ 
+C +--Melting/Freezing Energy
+C +  =======================
+ 
+C +...REMARK: Snow liquid Water Temperature assumed = TfSnow
+C +   ^^^^^^
+        DO ikl=1,knonv
+          EExdum(ikl) = drr_SV(ikl)     * C__Wat *(TaT_SV(ikl)-TfSnow)
+     .                                  * dt__SV
+          EExcsv(ikl) = EExdum(ikl)     *    min(1,isnoSV(ikl)) ! Snow exists
+          EExdum(ikl) = EExdum(ikl)     -          EExcsv(ikl)  !
+! #e1     EqSn_d(ikl) = EExcsv(ikl)                             !
+        END DO
+ 
+ 
+C +--Surficial Water Status
+C +  ----------------------
+ 
+        DO ikl=1,knonv
+          SWS_SV(ikl) = max(zero,sign(unun,TfSnow
+     .                                    -TsisSV(ikl,isnoSV(ikl))))
+        END DO
+ 
+      DO ikl=1,knonv
+       DO isn=min(nsno,isnoSV(ikl)+1),1,-1
+! EV          DO isn=nsno,1,-1
+C +--Energy, store Previous Content
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+          dTSnow      = TsisSV(ikl,isn) -          TfSnow
+          EExcsv(ikl) = EExcsv(ikl)
+     .                + ro__SV(ikl,isn) * Cn_dSV * dTSnow
+     .                                           * dzsnSV(ikl,isn)
+
+          Tsave       = TsisSV(ikl,isn)
+
+          TsisSV(ikl,isn) =                        TfSnow
+ 
+C +--Water,  store Previous Content
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+          drr_SV(ikl) = drr_SV(ikl)
+     .                + ro__SV(ikl,isn)          * eta_SV(ikl,isn)
+     .                                           * dzsnSV(ikl,isn)
+     .                / dt__SV
+          ro__SV(ikl,isn) =
+     .                  ro__SV(ikl,isn) *(1.     - eta_SV(ikl,isn))
+          eta_SV(ikl,isn) =  0.
+ 
+ 
+C +--Melting  if EExcsv > 0
+C +  ======================
+ 
+          EnMelt      =    max(zero,          EExcsv(ikl) )
+ 
+C +--Energy Consumption
+C +  ^^^^^^^^^^^^^^^^^^
+          SnHLat      = ro__SV(ikl,isn) * Lf_H2O
+          dzMelt(ikl) = EnMelt      / max(SnHLat,    epsi )
+          noSnow(ikl) = noSnow(ikl)
+     .      + max(zero  ,sign(unun,dzMelt(ikl)                !
+     .                            -dzsnSV(ikl ,isn)))         ! 1 if full Melt
+     .       *min(1     , max(0 ,1+isnoSV(ikl)-isn))          ! 1 in the  Pack
+          dzMelt(ikl) =
+     .              min(dzsnSV(ikl, isn),dzMelt(ikl))
+          dzsnSV(ikl,isn) =
+     .                  dzsnSV(ikl,isn) -dzMelt(ikl)
+          zn5_SV(ikl) = zn5_SV(ikl)     +dzMelt(ikl)
+          EExcsv(ikl) = EExcsv(ikl)     -dzMelt(ikl)*SnHLat
+          wem_SV(ikl) = wem_SV(ikl)     -dzMelt(ikl)*ro__SV(ikl,isn)
+ 
+C +--Water  Production
+C +  ^^^^^^^^^^^^^^^^^
+          drr_SV(ikl) = drr_SV(ikl)
+     .                + ro__SV(ikl,isn) * dzMelt(ikl)/dt__SV
+! #m1     SImelt(ikl) = SImelt(ikl)
+! #m1.                + ro__SV(ikl,isn) * dzMelt(ikl)
+          OKmelt      =max(zero,sign(unun,drr_SV(ikl)-epsi))
+ 
+C +--Snow History
+C +  ^^^^^^^^^^^^
+          k_face          =       min(    istoSV(ikl,isn),istdSV(1)) ! = 1  if
+     .                           *max(0,2-istoSV(ikl,isn)          ) ! faceted
+          istoSV(ikl,isn) =                                          !
+     .        (1.-OKmelt) *               istoSV(ikl,isn)            !
+     .      +     OKmelt  *((1-k_face) *  istdSV(2)                  !
+     .                     +   k_face  *  istdSV(3)      )           !
+ 
+ 
+C +--Freezing if EExcsv < 0
+C +  ======================
+ 
+          rdzsno      =          ro__SV(ikl,isn) * dzsnSV(ikl ,isn)
+          LayrOK      = min(   1, max(0          , isnoSV(ikl)-isn+1))
+          EnFrez      = min(zero,                  EExcsv(ikl))
+          WaFrez      =   -(     EnFrez          * LayrOK / Lf_H2O)
+          drrNEW      = max(zero,drr_SV(ikl)     - WaFrez / dt__SV)
+          WaFrez      =    (     drr_SV(ikl)     - drrNEW)* dt__SV
+          drr_SV(ikl) =          drrNEW
+          EExcsv(ikl) =          EExcsv(ikl)     + WaFrez * Lf_H2O
+          EnFrez      = min(zero,EExcsv(ikl))    * LayrOK
+          rdzNEW      = WaFrez + rdzsno
+          ro__SV(ikl,isn) =      rdzNEW /max(epsi, dzsnSV(ikl,isn))
+
+! EV: condition on Enfrez
+!          if (EnFrez .eq. 0.) then
+          
+          TsisSV(ikl,isn) = Tsave
+!          else
+          TsisSV(ikl,isn) =      TfSnow
+     .                + EnFrez /(Cn_dSV *max(epsi, rdzNEW)        )
+!          end if
+          EExcsv(ikl) =          EExcsv(ikl)     - EnFrez
+          wer_SV(ikl) = WaFrez
+     .                + wer_SV(ikl)
+ 
+ 
+
+C +--Snow Water Content
+C +  ==================
+ 
+C +--Percolation Velocity
+C +  ^^^^^^^^^^^^^^^^^^^^
+c #PW     SGDiam    = 1.6d-4
+c #PW.              + 1.1d-13 *(ro__SV(ikl,isn)*ro__SV(ikl,isn)
+c #PW.                         *ro__SV(ikl,isn)*ro__SV(ikl,isn))
+ 
+C +--Pore   Volume [-]
+C +  ^^^^^^^^^^^^^^^^^
+          rosDry      =(1.     - eta_SV(ikl,isn))* ro__SV(ikl,isn) !
+          PorVol      = 1.     - rosDry          / ro_Ice          !
+          PorVol      =      max(PorVol          , zero  )         !
+ 
+C +--Water  Retention
+C +  ^^^^^^^^^^^^^^^^
+          rWater      = ws0dSV * PorVol * ro_Wat * dzsnSV(ikl,isn)
+          drrNEW      = max(zero,drr_SV(ikl)     - rWater /dt__SV)
+          rWater      =    (     drr_SV(ikl)     - drrNEW)*dt__SV
+          drr_SV(ikl)     =      drrNEW
+          rdzNEW          =      rWater
+     .                         + rosDry          * dzsnSV(ikl,isn)
+          eta_SV(ikl,isn) =      rWater / max(epsi,rdzNEW)
+          ro__SV(ikl,isn) =      rdzNEW / max(epsi,dzsnSV(ikl,isn))
+ 
+C +--Pore Hole Close OFF
+C +  ^^^^^^^^^^^^^^^^^^^
+          PClose = max(zero,
+     .                 sign(unun,ro__SV(ikl,isn)
+     .                          -roCdSV         ))
+          ispiSV(ikl) =          ispiSV(ikl)      *(1.-PClose)
+     .                +      max(ispiSV(ikl),isn)    * Pclose
+          PClose = max(0   ,                         ! Water under SuPer.Ice
+     .                 min (1   ,ispiSV(ikl)         ! contributes to
+     .                          -isn            ))   ! Surficial   Water
+ 
+cXF
+          if(ro__SV(ikl,isn) >= roCdSV.and.ro__SV(ikl,1)<900)
+     .    PClose = min(0.50,PClose *
+     .    (1.-(ro_ice-ro__SV(ikl,isn))/(ro_ice-roCdSV)))
+ 
+          PClose = max(0.,min(1.,PClose))
+ 
+          if(isn==1) then
+               PClose = 1
+           ispiSV(ikl)= max(ispiSV(ikl),1)
+          endif
+ 
+          if(drr_SV(ikl)    >0  .and.TsisSV(ikl,isn)>273.14) then
+           if((ro__SV(ikl,isn)>900.and.ro__SV(ikl,isn)<920).or.
+     .         ro__SV(ikl,isn)>950) then
+             dzsnSV(ikl,isn) = dzsnSV(ikl,isn)*ro__SV(ikl,isn)/ro_ice
+             ro__SV(ikl,isn) = ro_ice
+             PClose          = 1
+           endif
+          endif
+ 
+c         if (isn>1.and.isn<nsno     .and.
+c    .      ro__SV(ikl,isn-1)>900    .and.
+c    .      ro__SV(ikl,isn)  >roCdSV .and.
+c    .      ro__SV(ikl,isn)  <900    .and.
+c    .      TsisSV(ikl,isn)  >273.14 .and.
+c    .      TsisSV(ikl,isn+1)<273.15 .and.
+c    .      drr_SV(ikl)      >0)     then
+c          TsisSV(ikl,isn)=273.14
+c          PClose = 1
+c         endif
+ 
+cXF
+          rusnSV(ikl) =          rusnSV(ikl)
+     .                +          drr_SV(ikl) *dt__SV * PClose
+          rusnSV0(ikl)=         rusnSV0(ikl)
+     .                +          drr_SV(ikl) *dt__SV * PClose
+          drr_SV(ikl) =          drr_SV(ikl)      *(1.-PClose)
+ 
+        END DO
+
+      END DO
+ 
+ 
+C +--Remove Zero-Thickness Layers
+C +  ============================
+ 
+ 1000 CONTINUE
+           isnitr =          0
+      DO   ikl=1,knonv
+           isnUpD =          0
+           isinew =          0
+cXF
+
+
+        DO isn=1,min(nsno-1,isnoSV(ikl))
+           isnnew =(unun-max(zero  ,sign(unun,dzsnSV(ikl,isn)-dzepsi)))
+     .             *     max(0     , min(1   ,isnoSV(ikl) +1 -isn ))
+           isnUpD =      max(isnUpD,          isnnew)
+           isnitr =      max(isnitr,          isnnew)
+           isinew =      isn*isnUpD *max(0, 1-isinew)      ! LowerMost  0-Layer
+     .                                       +isinew       ! Index
+           dzsnSV(ikl,isn) =                  dzsnSV(ikl,isn+isnnew)
+           ro__SV(ikl,isn) =                  ro__SV(ikl,isn+isnnew)
+           TsisSV(ikl,isn) =                  TsisSV(ikl,isn+isnnew)
+           eta_SV(ikl,isn) =                  eta_SV(ikl,isn+isnnew)
+           G1snSV(ikl,isn) =                  G1snSV(ikl,isn+isnnew)
+           G2snSV(ikl,isn) =                  G2snSV(ikl,isn+isnnew)
+           dzsnSV(ikl,isn+isnnew) =(1-isnnew)*dzsnSV(ikl,isn+isnnew)
+           ro__SV(ikl,isn+isnnew) =(1-isnnew)*ro__SV(ikl,isn+isnnew)
+           eta_SV(ikl,isn+isnnew) =(1-isnnew)*eta_SV(ikl,isn+isnnew)
+           G1snSV(ikl,isn+isnnew) =(1-isnnew)*G1snSV(ikl,isn+isnnew)
+           G2snSV(ikl,isn+isnnew) =(1-isnnew)*G2snSV(ikl,isn+isnnew)
+
+        END DO
+           isnoSV(ikl)   =   isnoSV(ikl)-isnUpD            ! Nb of Snow   Layer
+           ispiSV(ikl)   =   ispiSV(ikl)                   ! Nb of SuperI Layer
+     .    -isnUpD *max(0,min(ispiSV(ikl)-isinew,1))        ! Update  if I=0
+ 
+      END DO
+
+      IF  (isnitr.GT.0)                                       GO TO 1000
+ 
+ 
+C +--New upper Limit of the non erodible Snow (istoSV .GT. 1)
+C +  ========================================
+ 
+      DO   ikl=1,knonv
+           nh =     0
+cXF
+        DO isn=  isnoSV(ikl),1,-1
+           nh =    nh + isn* min(istoSV(ikl,isn)-1,1)*max(0,1-nh)
+        ENDDO
+           zc =     0.
+           zt =     0.
+cXF
+        DO isn=1,isnoSV(ikl)
+           zc =    zc +          dzsnSV(ikl,isn) *ro__SV(ikl,isn)
+     .                     * max(0,min(1,nh+1-isn))
+           zt =    zt +          dzsnSV(ikl,isn) *ro__SV(ikl,isn)
+        END DO
+           zWE_SV(ikl) =                 zt
+           zWEcSV(ikl) = min(zWEcSV(ikl),zt)
+           zWEcSV(ikl) = max(zWEcSV(ikl),zc)
+      END DO
+ 
+ 
+C +--Energy Budget (OUT)
+C +  ===================
+ 
+! #vm   DO ikl=1,knonv
+! #vm     EqSn01(ikl) =-EqSn_0(ikl)
+! #vm.                 -EExcsv(ikl)
+! #vm   END DO
+! #vm DO   isn=nsno,1,-1
+! #vm   DO ikl=1,knonv
+! #vm     EqSn01(ikl) = EqSn01(ikl) + ro__SV(ikl,isn) *dzsnSV(ikl,isn)
+! #vm.                *(Cn_dSV      *(TsisSV(ikl,isn) -TfSnow         )
+! #vm.                 -Lf_H2O      *(1.              -eta_SV(ikl,isn)))
+! #vm   END DO
+! #vm END DO
+ 
+ 
+C +--"Negative Heat" from supercooled rain
+C +   ------------------------------------
+ 
+      DO ikl=1,knonv
+          EExcsv(ikl) = EExcsv(ikl) + EExdum(ikl)
+ 
+ 
+C +--Surficial Water Run OFF
+C +  -----------------------
+ 
+          rusnew      = rusnSV(ikl) * SWf_SV(ikl)
+ 
+          if(isnoSV(ikl)<=1) rusnew = 0.
+          !if(ivgtSV(ikl)>=1) rusnew = 0.
+ 
+c #EU                        rusnew = 0.
+c #AC                        rusnew = 0.
+          RnofSV(ikl) = RnofSV(ikl)
+     .                +(rusnSV(ikl) - rusnew     ) / dt__SV
+          RuofSV(ikl,1) = RuofSV(ikl,1)
+     .                +(rusnSV(ikl) - rusnew     ) / dt__SV
+          RuofSV(ikl,4) = RuofSV(ikl,4)
+     .                +(rusnSV0(ikl)             ) / dt__SV
+          rusnSV(ikl) = rusnew
+      END DO
+ 
+ 
+C +--Percolation down the Continental Ice Pack
+C +  -----------------------------------------
+ 
+        DO ikl=1,knonv
+          drr_SV(ikl) = drr_SV(ikl) + rusnSV(ikl)
+     .                     * (1-min(1,ispiSV(ikl)))/ dt__SV
+          rusnSV(ikl) = rusnSV(ikl)
+     .                     *    min(1,ispiSV(ikl))
+        END DO
+ 
+cXF removal of too thin snowlayers if TT> 275.15 + bug if TT>> 273.15
+        DO ikl=1,knonv
+         zt=0.
+         DO isn=1,isnoSV(ikl)
+          zt=zt+dzsnSV(ikl,isn)
+         ENDDO
+         
+         if(zt<0.005+(TaT_SV(ikl)-TfSnow)/1000..and.
+     .      isnoSV(ikl)             >0         .and.
+     .      TaT_SV(ikl)             >=TfSnow   .and.
+     .      istoSV(ikl,isnoSV(ikl)) >1       ) then
+          DO isn=1,isnoSV(ikl)
+           drr_SV(ikl)    = drr_SV(ikl)
+     .                    + dzsnSV(ikl,isn)*ro__SV(ikl,isn) /dt__SV
+           dzsnSV(ikl,isn)= 0.
+
+          ENDDO
+          isnoSV(ikl)     = 0
+         endif
+        ENDDO
+ 
+C +--Slush Formation (CAUTION: ADD RunOff Possibility before Activation)
+C +  ---------------  ^^^^^^^  ^^^
+ 
+ 
+c #SU DO  ikl=1,knonv
+c #SU  DO isn=1,isnoSV(ikl)
+c #SU     kSlush = min(1,max(0,isn+1-ispiSV(ikl)))        ! Slush Switch
+ 
+C +--Available Additional Pore   Volume [-]
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+c #SU     PorVol = 1. - ro__SV(ikl,isn)                    ! [--]
+c #SU.           *(1. - eta_SV(ikl,isn))/ ro_Ice           !
+c #SU.           -      eta_SV(ikl,isn)                    !
+c #SU.                 *ro__SV(ikl,isn) / ro_Wat           !
+c #SU     PorVol =  max(PorVol          , zero  )          !
+c #SU     zWater =      dzsnSV(ikl,isn) * PorVol * 1000.   ! [mm] OR [kg/m2]
+c #SU.           * (1. -SWS_SV(ikl)                        ! 0 <=> freezing
+c #SU.                *(1 -min(1,iabs(isn-isnoSV(ikl)))))  ! 1 <=> isn=isnoSV
+c #SU     zSlush =  min(rusnSV(ikl)     , zWater)          ! [mm] OR [kg/m2]
+c #SU     ro_new      =(dzsnSV(ikl,isn) * ro__SV(ikl,isn)  !
+c #SU.                 +zSlush                           ) !
+c #SU.            / max(dzsnSV(ikl,isn) , epsi           ) !
+c #SU     if(ro_new<ro_Ice+20) then ! MAX 940kg/m3         !
+c #SU      rusnSV(ikl)  = rusnSV(ikl)          - zSlush    ! [mm] OR [kg/m2]
+c #SU      RuofSV(ikl,4)= max(0.,RuofSV(ikl,4) - zSlush/dt__SV)
+c #SU      eta_SV(ikl,isn) =(ro_new - ro__SV(ikl,isn)      !
+c #SU.                     *(1.     - eta_SV(ikl,isn)))    !
+c #SU.                / max (ro_new , epsi            )    !
+c #SU      ro__SV(ikl,isn) =      ro_new                   !
+c #SU     endif
+c #SU   END DO
+c #SU END DO
+ 
+ 
+C +--Impact of the Sublimation/Deposition on the Surface Mass Balance
+C +  ================================================================
+ 
+      DO ikl=1,knonv
+         isn                     = isnoSV(ikl)
+          dzVap0                  =                   dt__SV
+     .  * HLs_sv(ikl)         * min(isn             , 1   )
+     .  /(Lx_H2O(ikl)         * max(ro__SV(ikl,isn) , epsi))
+          NOLayr=min(zero,sign(unun,dzsnSV(ikl,isn) + dzVap0))
+          dzVap1=min(zero,          dzsnSV(ikl,isn) + dzVap0)
+ 
+ 
+C +--Additional Energy
+C +  -----------------
+ 
+c #VH     AdEnrg = dzVap0 * ro__SV(ikl,isnoSV(ikl))           ! Water   Vapor
+c #VH.            *C__Wat *(TsisSV(ikl,isnoSV(ikl)) -TfSnow)  ! Sensible Heat
+ 
+c #aH     B_Enrg =(Cn_dSV      *(TsisSV(ikl,isn) -TfSnow         )
+c #aH.            -Lf_H2O      *(1.              -eta_SV(ikl,isn)))
+c #aH.           /(1.          + dzVap0 /max(epsi,dzsnSV(ikl,isn)))
+c #aH     eta_SV(ikl,isn) =
+c #aH.           max(zero,unun +(B_Enrg
+c #aH.                         -(TsisSV(ikl,isn) -TfSnow)*Cn_dSV)
+c #aH.                          /Lf_H2O                          )
+c #aH     TsisSV(ikl,isn) =    ( B_Enrg
+c #aH.                         +(1.              -eta_SV(ikl,isn))
+c #aH.                          *Lf_H2O                          )
+c #aH.                         / Cn_dSV
+c #aH.                         + TfSnow
+ 
+! #e1     STOP "PLEASE add Energy (#aH) from deposition/sublimation"
+ 
+ 
+C +--Update of the upper Snow layer Thickness
+C +  ----------------------------------------
+ 
+          dzsnSV(ikl,isn) =
+     .           max(zero,  dzsnSV(ikl,isnoSV(ikl)) + dzVap0)
+          isnoSV(ikl)     = isnoSV(ikl)             + NOLayr
+          isn             = isnoSV(ikl)
+          dzsnSV(ikl,isn) = dzsnSV(ikl,isn) + dzVap1
+          wes_SV(ikl)     = ro__SV(ikl,isn) * dzVap0
+
+      END DO
+ 
+ 
+C +--Energy Budget (OUT)
+C +  ===================
+ 
+! #vm   DO ikl=1,knonv
+! #vm     EqSn02(ikl) =-EqSn_0(ikl)
+! #vm.                 -EExcsv(ikl)
+! #vm   END DO
+! #vm DO   isn=nsno,1,-1
+! #vm   DO ikl=1,knonv
+! #vm     EqSn02(ikl) = EqSn01(ikl) + ro__SV(ikl,isn) *dzsnSV(ikl,isn)
+! #vm.                *(Cn_dSV      *(TsisSV(ikl,isn) -TfSnow         )
+! #vm.                 -Lf_H2O      *(1.              -eta_SV(ikl,isn)))
+! #vm   END DO
+! #vm END DO
+ 
+ 
+C +--Snow/I Budget
+C +  -------------
+ 
+! #m1   DO ikl=1,knonv
+! #m1     SIsubl(ikl) = dt__SV*HLs_sv(ikl)*min(isnoSV(ikl),1)
+! #m1.                        /Lx_H2O(ikl)
+! #m1     SIrnof(ikl) = rusnSV(ikl) + RnofSV(ikl) * dt__SV
+! #m1.                - SIrnof(ikl)
+! #m1   END DO
+ 
+ 
+C +--Anticipated Disappearance of a rapidly Melting too thin Last Snow Layer
+C +  =======================================================================
+ 
+      DO ikl=1,knonv
+        LastOK = min(1   , max(0   ,iiceSV(ikl)-isnoSV(ikl)+2)
+     .                    *min(1   ,isnoSV(ikl)-iiceSV(ikl))
+     .                    +min(1   ,isnoSV(ikl))              )
+        RapdOK = max(zero,sign(unun,dzMelt(ikl)-epsi         ))
+        ThinOK = max(zero,sign(unun,dz_Min     -dzsnSV(ikl,1)))
+        z_Melt = LastOK     *RapdOK*ThinOK
+        noSnow(ikl)   = noSnow(ikl)   + z_Melt
+        z_Melt        =                 z_Melt *dzsnSV(ikl,1)
+        dzsnSV(ikl,1) = dzsnSV(ikl,1) - z_Melt
+        EExcsv(ikl)   = EExcsv(ikl)   - z_Melt *ro__SV(ikl,1)
+     .                                *(1.     -eta_SV(ikl,1))*Lf_H2O
+ 
+C +--Water  Production
+C +  ^^^^^^^^^^^^^^^^^
+        drr_SV(ikl)   = drr_SV(ikl)
+     .                + ro__SV(ikl,1) * z_Melt /dt__SV
+      END DO
+ 
+ 
+C +--Update Nb of Layers
+C +  ===================
+ 
+      DO ikl=1,knonv
+        isnoSV(ikl)   = isnoSV(ikl)
+     .     * min(1,iabs(isnoSV(ikl)-noSnow(ikl)))
+      END DO
+ 
+ 
+! Energy Budget (OUT)
+! ===================
+ 
+! #e1   DO ikl=1,knonv
+! #e1     EqSn_1(ikl) = 0.
+! #e1   END DO
+! #e1 DO   isn=nsno,1,-1
+! #e1   DO ikl=1,knonv
+! #e1     EqSn_1(ikl) = EqSn_1(ikl) + ro__SV(ikl,isn) *dzsnSV(ikl,isn)
+! #e1.                *(Cn_dSV      *(TsisSV(ikl,isn) -TfSnow         )
+! #e1.                 -Lf_H2O      *(1.              -eta_SV(ikl,isn)))
+! #e1   END DO
+! #e1 END DO
+ 
+ 
+C +--Water  Budget (OUT)
+C +  ===================
+ 
+! #vm   DO ikl=1,knonv
+! #vm     WqSn_0(ikl) = WqSn_0(ikl)
+! #vm.                + HLs_sv(ikl)    * dt__SV
+! #vm.             *min(isnoSV(ikl),1) / Lx_H2O(ikl)
+! #vm     WqSn_1(ikl) = drr_SV(ikl)    * dt__SV
+! #vm.                + rusnSV(ikl)
+! #vm.                + RnofSV(ikl)    * dt__SV
+! #vm   END DO
+! #vm DO   isn=nsno,1,-1
+! #vm   DO ikl=1,knonv
+! #vm     WqSn_1(ikl) = WqSn_1(ikl)
+! #vm.                + ro__SV(ikl,isn)* dzsnSV(ikl,isn)
+! #vm   END DO
+! #vm END DO
+ 
+ 
+      return
+      end
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_qso.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_qso.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_qso.F	(revision 3792)
@@ -0,0 +1,710 @@
+ 
+ 
+      subroutine SISVAT_qSo
+! #m0.                     (Wats_0,Wats_1,Wats_d)
+ 
+C +------------------------------------------------------------------------+
+C | MAR          SISVAT_qSo                                 6-04-2001  MAR |
+C |   SubRoutine SISVAT_qSo computes the Soil      Water  Balance          |
+C +------------------------------------------------------------------------+
+C |                                                                        |
+C |   PARAMETERS:  knonv: Total Number of columns =                        |
+C |   ^^^^^^^^^^        = Total Number of continental     grid boxes       |
+C |                     X       Number of Mosaic Cell per grid box         |
+C |                                                                        |
+C |   INPUT:   isnoSV   = total Nb of Ice/Snow Layers                      |
+C |   ^^^^^    isotSV   = 0,...,11:   Soil       Type                      |
+C |                       0:          Water, Solid or Liquid               |
+C |                                                                        |
+C |   INPUT:   rhT_SV   : SBL Top    Air  Density                  [kg/m3] |
+C |   ^^^^^    drr_SV   : Rain   Intensity                       [kg/m2/s] |
+C |            LSdzsv   : Vertical   Discretization Factor             [-] |
+C |                     =    1. Soil                                       |
+C |                     = 1000. Ocean                                      |
+C |            dt__SV   : Time   Step                                  [s] |
+C |                                                                        |
+C |            Lx_H2O   : Latent Heat of Vaporization/Sublimation   [J/kg] |
+C |            HLs_sv   : Latent Heat  Flux                         [W/m2] |
+C |                                                                        |
+C |   INPUT /  eta_SV   : Water      Content                       [m3/m3] |
+C |   OUTPUT:  Khydsv   : Soil   Hydraulic    Conductivity           [m/s] |
+C |   ^^^^^^                                                               |
+C |                                                                        |
+C |   OUTPUT:  RnofSV   : RunOFF Intensity                       [kg/m2/s] |
+C |   ^^^^^^   Wats_0   : Soil Water,  before Forcing                 [mm] |
+C |            Wats_1   : Soil Water,  after  Forcing                 [mm] |
+C |            Wats_d   : Soil Water          Forcing                 [mm] |
+C |                                                                        |
+C |   Internal Variables:                                                  |
+C |   ^^^^^^^^^^^^^^^^^^                                                   |
+C |            z_Bump   : (Partly)Bumpy Layers Height                  [m] |
+C |            z0Bump   :         Bumpy Layers Height                  [m] |
+C |            dzBump   :  Lowest Bumpy Layer:                         [m] |
+C |            etBump   :         Bumps Layer Averaged Humidity    [m3/m3] |
+C |            etaMid   : Layer Interface's Humidity               [m3/m3] |
+C |            eta__f   : Layer             Humidity  (Water Front)[m3/m3] |
+C |            Dhyd_f   : Soil  Hydraulic Diffusivity (Water Front) [m2/s] |
+C |            Dhydif   : Soil  Hydraulic Diffusivity               [m2/s] |
+C |            WgFlow   : Water         gravitational     Flux   [kg/m2/s] |
+C |            Wg_MAX   : Water MAXIMUM gravitational     Flux   [kg/m2/s] |
+C |            SatRat   : Water         Saturation        Flux   [kg/m2/s] |
+C |            WExces   : Water         Saturation Excess Flux   [kg/m2/s] |
+C |            Dhydtz   : Dhydif * dt / dz                             [m] |
+C |            FreeDr   : Free Drainage Fraction                       [-] |
+C |            Elem_A   : A Diagonal Coefficient                           |
+C |            Elem_C   : C Diagonal Coefficient                           |
+C |            Diag_A   : A Diagonal                                       |
+C |            Diag_B   : B Diagonal                                       |
+C |            Diag_C   : C Diagonal                                       |
+C |            Term_D   :   Independant Term                               |
+C |            Aux__P   : P Auxiliary Variable                             |
+C |            Aux__Q   : Q Auxiliary Variable                             |
+C |                                                                        |
+C |   TUNING PARAMETER:                                                    |
+C |   ^^^^^^^^^^^^^^^^                                                     |
+C |            z0soil   : Soil Surface averaged Bumps Height           [m] |
+C |                                                                        |
+C |   METHOD: NO   Skin Surface Humidity                                   |
+C |   ^^^^^^  Semi-Implicit Crank Nicholson Scheme                         |
+C |           (Partial) free Drainage, Water Bodies excepted (Lakes, Sea)  |
+C |                                                                        |
+
+C |                                                                        |
+C | # OPTIONS: #GF: Saturation Front                                       |
+C | # ^^^^^^^  #GH: Saturation Front allows Horton Runoff                  |
+C | #          #GA: Soil Humidity Geometric Average                        |
+C | #          #BP: Parameterization of Terrain Bumps                      |
+C |                                                                        |
+C |                                                                        |
+C +------------------------------------------------------------------------+
+ 
+ 
+ 
+ 
+C +--Global Variables
+C +  ================
+ 
+      use VARphy
+      use VAR_SV
+      use VARdSV
+      use VAR0SV
+      use VARxSV
+      use VARySV
+
+     
+      IMPLICIT NONE
+
+ 
+C +--OUTPUT
+C +  ------
+ 
+! Water (Mass) Budget
+! ~~~~~~~~~~~~~~~~~~~
+! #m0 real      Wats_0(knonv)                 ! Soil Water,  before forcing
+! #m0 real      Wats_1(knonv)                 ! Soil Water,  after  forcing
+! #m0 real      Wats_d(knonv)                 ! Soil Water          forcing
+ 
+ 
+C +--Internal Variables
+C +  ==================
+ 
+      integer   isl   ,jsl   ,ist   ,ikl      !
+      integer   ikm   ,ikp   ,ik0   ,ik1      !
+      integer   ist__s,ist__w                 ! Soil/Water Body Identifier
+c #BP real      z0soil                        ! Soil Surface Bumps Height  [m]
+c #BP real      z_Bump                        !(Partly)Bumpy Layers Height [m]
+c #BP real      z0Bump                        !        Bumpy Layers Height [m]
+c #BP real      dzBump                        ! Lowest Bumpy Layer:
+ 
+c #BP real      etBump(knonv)                 ! Bumps Layer Averaged Humidity
+      real      etaMid                        ! Layer Interface's Humidity
+      real      Dhydif                        ! Hydraulic Diffusivity   [m2/s]
+      real      eta__f                        ! Water Front Soil Water Content
+      real      Khyd_f                        ! Water Front Hydraulic Conduct.
+      real      Khydav                        ! Hydraulic Conductivity   [m/s]
+      real      WgFlow                        ! Water gravitat. Flux [kg/m2/s]
+      real      Wg_MAX                        ! Water MAX.grav. Flux [kg/m2/s]
+      real      SatRat                        ! Saturation      Flux [kg/m2/s]
+      real      WExces                        ! Saturat. Excess Flux [kg/m2/s]
+      real      SoRnOF(knonv)                 ! Soil     Run    OFF
+      real      Dhydtz(knonv,-nsol:0)         ! Dhydif * dt / dz           [m]
+      real      Elem_A,Elem_B,Elem_C          !   Diagonal Coefficients
+      real      Diag_A(knonv,-nsol:0)         ! A Diagonal
+      real      Diag_B(knonv,-nsol:0)         ! B Diagonal
+      real      Diag_C(knonv,-nsol:0)         ! C Diagonal
+      real      Term_D(knonv,-nsol:0)         !   Independant Term
+      real      Aux__P(knonv,-nsol:0)         ! P Auxiliary Variable
+      real      Aux__Q(knonv,-nsol:0)         ! Q Auxiliary Variable
+      real      etaaux(knonv,-nsol:-nsol+1)   ! Soil Water Content     [m3/m3]
+      real      FreeDr                        ! Free Drainage Fraction (actual)
+      real      FreeD0                        ! Free Drainage Fraction (1=Full)
+      real      aKdtSV3( 0:nsot, 0:nkhy)      ! Khyd=a*eta+b: a * dt
+      real      bKdtSV3( 0:nsot, 0:nkhy)      ! Khyd=a*eta+b: b * dt
+ 
+! Water (Mass) Budget
+! ~~~~~~~~~~~~~~~~~~~
+c #mw logical         mwopen                  ! IO   Switch
+c #mw common/Sm_qSo_L/mwopen                  !
+c #mw real     hourwr,timewr                  !
+c #mw common/Sm_qSo_R/timewr                  !
+c #mw real            Evapor(knonv)           !
+ 
+ 
+C +--Internal DATA
+C +  =============
+ 
+c #BP data      z0soil/0.020/                 ! Soil Surface Bumps Height  [m]
+      data      FreeD0/1.000/                 ! Free Drainage Fraction (1=Full)
+ 
+      aKdtSV3=aKdtSV2*dt__SV
+      bKdtSV3=bKdtSV2*dt__SV
+ 
+! Water  Budget (IN)
+! ==================
+ 
+! #m0   DO ikl=1,knonv
+! #m0     Wats_0(ikl) = 0.                    ! OLD RunOFF Contrib.
+! #m0     Wats_d(ikl) = drr_SV(ikl)           ! Water Surface Forc.
+! #m0   END DO
+ 
+! #m0      isl= -nsol
+! #m0   DO ikl=1,knonv
+! #m0     Wats_0(ikl) = Wats_0(ikl)
+! #m0.      + ro_Wat *( eta_SV(ikl,isl)   *dz78SV(isl)
+! #m0.                + eta_SV(ikl,isl+1) *dz_8SV(isl) ) * LSdzsv(ikl)
+! #m0   END DO
+ 
+! #m0 DO   isl= -nsol+1,-1
+! #m0   DO ikl=1,knonv
+! #m0     Wats_0(ikl) = Wats_0(ikl)
+! #m0.      + ro_Wat *( eta_SV(ikl,isl)   *dz34SV(isl)
+! #m0.                +(eta_SV(ikl,isl-1)
+! #m0.                 +eta_SV(ikl,isl+1))*dz_8SV(isl) ) * LSdzsv(ikl)
+! #m0   END DO
+! #m0 END DO
+ 
+! #m0      isl=  0
+! #m0   DO ikl=1,knonv
+! #m0     Wats_0(ikl) = Wats_0(ikl)
+! #m0.      + ro_Wat *( eta_SV(ikl,isl)   *dz78SV(isl)
+! #m0.                + eta_SV(ikl,isl-1) *dz_8SV(isl) ) * LSdzsv(ikl)
+! #m0   END DO
+ 
+ 
+C +--Gravitational Flow
+C +  ==================
+ 
+C +...    METHOD: Surface Water Flux saturates successively the soil layers
+C +       ^^^^^^  from up to below, but is limited by infiltration capacity.
+C +               Hydraulic Conductivity again contributes after this step,
+C +               not redundantly because of a constant (saturated) profile.
+ 
+C +--Flux  Limitor
+C +  ^^^^^^^^^^^^^
+           isl=0
+        DO ikl=1,knonv
+          ist    = isotSV(ikl)                     ! Soil Type
+          ist__s = min(ist, 1)                     ! 1 => Soil
+          ist__w = 1 - ist__s                      ! 1 => Water Body
+          Dhydif = s1__SV(ist)
+     .               *max(epsi,eta_SV(ikl,isl))    ! Hydraulic Diffusivity
+     .                      **(bCHdSV(ist)+2.)     ! DR97, Eqn.(3.36)
+          Dhydif = ist__s    * Dhydif              !
+     .           + ist__w    * vK_dSV              ! Water Bodies
+C +
+          Khydav = ist__s    * Ks_dSV(ist)         ! DR97  Assumption
+     .           + ist__w    * vK_dSV              ! Water Bodies
+C +
+          Wg_MAX = ro_Wat     *Dhydif              ! MAXimum  Infiltration
+     .           *(etadSV(ist)-eta_SV(ikl,isl))    !          Rate
+     .           /(dzAvSV(isl)*LSdzsv(ikl)    )    !
+     .          +  ro_Wat     *Khydav              !
+ 
+C +--Surface Horton RunOFF
+C +  ^^^^^^^^^^^^^^^^^^^^^
+          SoRnOF(ikl) =
+     .                max(zero,drr_SV(ikl)-Wg_MAX)
+        RuofSV(ikl,1) = RuofSV(ikl,1) +    SoRnOF(ikl)
+          drr_SV(ikl) =        drr_SV(ikl)-SoRnOF(ikl)
+        RuofSV(ikl,2) = RuofSV(ikl,2) +max(0.,drr_SV(ikl))
+        END DO
+ 
+c #GF DO   isl=0,-nsol,-1
+c #GF   DO ikl=1,knonv
+c #GF     ist    = isotSV(ikl)                     ! Soil Type
+c #GF     ist__s = min(ist, 1)                     ! 1 => Soil
+c #GF     ist__w = 1 - ist__s                      ! 1 => Water Body
+ 
+C +--Water Diffusion
+C +  ^^^^^^^^^^^^^^^
+c #GF     Dhydif = s1__SV(ist)
+c #GF.               *max(epsi,eta_SV(ikl,isl))    ! Hydraulic Diffusivity
+c #GF.                      **(bCHdSV(ist)+2.)     ! DR97, Eqn.(3.36)
+c #GF     Dhydif = ist__s    * Dhydif              !
+c #GF.           + ist__w    * vK_dSV              ! Water Bodies
+ 
+C +--Water Conduction (without Horton Runoff)
+C +  ^^^^^^^^^^^^^^^^
+c #GF     Khyd_f =             Ks_dSV(ist)
+C +...    Uses saturated K ==> Horton Runoff ~0    !
+ 
+C +--Water Conduction (with    Horton Runoff)
+C +  ^^^^^^^^^^^^^^^^
+c #GH     ik0    = nkhy       *eta_SV(ikl,isl)
+c #GH.                        /etadSV(ist)
+c #GH     eta__f         =            1.
+c #GH.   -aKdtSV3(ist,ik0)/(2. *dzAvSV(isl)
+c #GH.                        *LSdzsv(ikl))
+c #GH     eta__f         = max(eps_21,eta__f)
+c #GH     eta__f         = min(etadSV(ist),
+c #GH.                         eta_SV(ikl,isl) +
+c #GH.   (aKdtSV3(ist,ik0)     *eta_SV(ikl,isl)
+c #GH.   +bKdtSV3(ist,ik0))   /(dzAvSV(isl)
+c #GH.                        *LSdzsv(ikl))
+c #GH.                       / eta__f          )
+c #GH     eta__f         = .5*(eta_SV(ikl,isl)
+c #GH.                        +eta__f)
+ 
+c #gh     eta__f         =     eta_SV(ikl,isl)
+ 
+c #GH     ik0    = nkhy       *eta__f
+c #GH.                        /etadSV(ist)
+c #GH     Khyd_f =
+c #GH.   (aKdtSV3(ist,ik0)     *eta__f
+c #GH.   +bKdtSV3(ist,ik0))    /dt__SV
+ 
+c #GF     Khydav = ist__s    * Khyd_f              ! DR97  Assumption
+c #GF.           + ist__w    * vK_dSV              ! Water Bodies
+ 
+C +--Gravitational Flow
+C +  ^^^^^^^^^^^^^^^^^^
+c #GF     Wg_MAX =                                 ! MAXimum  Infiltration
+c #GF.             ro_Wat     *Dhydif              !          Rate
+c #GF.           *(etadSV(ist)-eta_SV(ikl,isl))    !
+c #GF.           /(dzAvSV(isl)*LSdzsv(ikl)    )    !
+c #GF.          +  ro_Wat     *Khydav              !
+c #GF   END DO
+c #GF END DO
+c #GF   DO ikl=1,knonv
+c #GF     SoRnOF(ikl)     =    SoRnOF(ikl)         ! RunOFF Intensity
+c #GF.                    +    drr_SV(ikl)         ! [kg/m2/s]
+C +!!!    Inclure la possibilite de creer une mare sur un bedrock impermeable
+c #GF     drr_SV(ikl) = 0.
+c #GF   END DO
+ 
+ 
+C +--Temperature Correction due to a changed Soil Energy Content
+C +  ===========================================================
+ 
+C +!!!    Mettre en oeuvre le couplage humidit?-?nergie
+ 
+ 
+C +--Full Resolution of the Richard's Equation
+C +  =========================================
+ 
+C +...    METHOD: Water content evolution results from water fluxes
+C +       ^^^^^^  at the layer boundaries
+C +               Conductivity is approximated by a piecewise linear profile.
+C +               Semi-Implicit Crank-Nicholson scheme is used.
+C +              (Bruen, 1997, Sensitivity of hydrological processes
+C +                            at the land-atmosphere interface.
+C +                            Proc. Royal Irish Academy,  IGBP symposium
+C +                            on global change and the Irish Environment.
+C +                            Publ.: Maynooth)
+ 
+C +                      - - - - - - - -   isl+1/2   - -  ^
+C +                                                       |
+C +   eta_SV(isl)        ---------------   isl     -----  +--dz_dSV(isl)  ^
+C +                                                       |               |
+C +   Dhydtz(isl) etaMid - - - - - - - -   isl-1/2   - -  v  dzmiSV(isl)--+
+C +                                                                       |
+C +   eta_SV(isl-1)      ---------------   isl-1   -----                  v
+ 
+C +--Transfert       Coefficients
+C +  ----------------------------
+ 
+      DO   isl=-nsol+1,0
+        DO ikl=1,knonv
+          ist    =      isotSV(ikl)                       ! Soil Type
+          ist__s =      min(ist, 1)                       ! 1 => Soil
+          ist__w =      1 - ist__s                        ! 1 => Water Body
+          etaMid =     (dz_dSV(isl)  *eta_SV(ikl,isl-1)   ! eta at layers
+     .                 +dz_dSV(isl-1)*eta_SV(ikl,isl)  )  !     interface
+     .           /(2.0* dzmiSV(isl))                      ! LSdzsv implicit !
+c #GA     etaMid = sqrt(dz_dSV(isl)  *eta_SV(ikl,isl-1)   ! Idem, geometric
+c #GA.                 *dz_dSV(isl-1)*eta_SV(ikl,isl)  )  !       average
+c #GA.           /(2.0* dzmiSV(isl))                      ! (Vauclin&al.1979)
+          Dhydif          =    s1__SV(ist)                ! Hydraul.Diffusi.
+     .  *(etaMid         **(   bCHdSV(ist)+2.))           ! DR97, Eqn.(3.36)
+          Dhydtz(ikl,isl) =    Dhydif*dt__SV              !
+     .                              /(dzmiSV(isl)         !
+     .                               *LSdzsv(ikl))        !
+          Dhydtz(ikl,isl) =    Dhydtz(ikl,isl) * ist__s   ! Soil
+     .        +0.5*dzmiSV(isl)*LSdzsv(ikl)     * ist__w   ! Water bodies
+ 
+        END DO
+      END DO
+           isl=-nsol
+        DO ikl=1,knonv
+          Dhydtz(ikl,isl) =    0.0                        !
+        END DO
+ 
+ 
+C +--Tridiagonal Elimination: Set Up
+C +  -------------------------------
+ 
+C +--Soil/Snow Interior
+C +  ^^^^^^^^^^^^^^^^^^
+ 
+      DO   isl=0,-nsol,-1
+        DO ikl=1,knonv
+         ist             = isotSV(ikl)
+         eta_SV(ikl,isl) = max(epsi,           eta_SV(ikl,isl))
+        END DO
+      END DO
+ 
+      DO   isl=-nsol,-nsol+1
+        DO ikl=1,knonv
+          etaaux(ikl,isl) =  eta_SV(ikl,isl)
+        END DO
+      END DO
+ 
+      DO   isl=-nsol+1,-1
+        DO ikl=1,knonv
+          ist      =         isotSV(ikl)
+          ikm      = nkhy *  eta_SV(ikl,isl-1) / etadSV(ist)
+          ik0      = nkhy *  eta_SV(ikl,isl)   / etadSV(ist)
+          ikp      = nkhy *  eta_SV(ikl,isl+1) / etadSV(ist)
+ 
+          if(ikm<0.or.ik0<0.or.ikp<0)then
+           print *,"CRASH1 in sisvat_qso.f on pixel (i,j,n)",
+     .     ii__SV(ikl),jj__SV(ikl),nn__SV(ikl)
+           print *,"decrease your time step or increase ntphys "//
+     .             "and ntdiff in time_steps.f"
+           stop
+          endif
+ 
+ 
+          Elem_A   =         Dhydtz(ikl,isl)
+     .                    -  aKdtSV3(ist,ikm)* dziiSV(isl)  *LSdzsv(ikl)
+          Elem_B   =      - (Dhydtz(ikl,isl)
+     .                      +Dhydtz(ikl,isl+1)
+     .                      -aKdtSV3(ist,ik0)*(dziiSV(isl+1)
+     .                                       -dzi_SV(isl) )*LSdzsv(ikl))
+          Elem_C   =         Dhydtz(ikl,isl+1)
+     .                    +  aKdtSV3(ist,ikp)* dzi_SV(isl+1)*LSdzsv(ikl)
+          Diag_A(ikl,isl) =  dz_8SV(isl)        *LSdzsv(ikl)
+     .                      -Implic            * Elem_A
+          Diag_B(ikl,isl) =  dz34SV(isl)        *LSdzsv(ikl)
+     .                      -Implic            * Elem_B
+          Diag_C(ikl,isl) =  dz_8SV(isl)        *LSdzsv(ikl)
+     .                      -Implic            * Elem_C
+ 
+          Term_D(ikl,isl) = (dz_8SV(isl) *LSdzsv(ikl)
+     .                      +Explic      *Elem_A     )*eta_SV(ikl,isl-1)
+     .                    + (dz34SV(isl) *LSdzsv(ikl)
+     .                      +Explic      *Elem_B     )*eta_SV(ikl,isl)
+     .                    + (dz_8SV(isl) *LSdzsv(ikl)
+     .                      +Explic      *Elem_C     )*eta_SV(ikl,isl+1)
+     .                    + (bKdtSV3(ist,ikp)* dzi_SV(isl+1)
+     .                      +bKdtSV3(ist,ik0)*(dziiSV(isl+1)
+     .                                       -dzi_SV(isl)  )
+     .                      -bKdtSV3(ist,ikm)* dziiSV(isl)   )
+     .                                      * LSdzsv(ikl)
+        END DO
+      END DO
+ 
+           isl=-nsol
+        DO ikl=1,knonv
+          ist      =         isotSV(ikl)
+c #       FreeDr   =         FreeD0            *  min(ist,1)
+          FreeDr   =         iWaFSV(ikl)       *  min(ist,1)
+          ik0      = nkhy *  eta_SV(ikl,isl  ) / etadSV(ist)
+          ikp      = nkhy *  eta_SV(ikl,isl+1) / etadSV(ist)
+ 
+          if(ik0<0.or.ikp<0)then
+           print *,"CRASH2 in sisvat_qso.f on pixel (i,j,n)",
+     .     ii__SV(ikl),jj__SV(ikl),nn__SV(ikl)
+           print *,"decrease your time step or increase ntphys "//
+     .             "and ntdiff in time_steps.f"
+           stop
+          endif
+ 
+          Elem_A   =         0.
+          Elem_B   =      - (Dhydtz(ikl,isl+1)
+     .                      -aKdtSV3(ist,ik0)*(dziiSV(isl+1)*LSdzsv(ikl)
+     .                                       -FreeDr                  ))
+          Elem_C   =         Dhydtz(ikl,isl+1)
+     .                    +  aKdtSV3(ist,ikp)* dzi_SV(isl+1)*LSdzsv(ikl)
+          Diag_A(ikl,isl) =  0.
+          Diag_B(ikl,isl) =  dz78SV(isl) *LSdzsv(ikl)
+     .                      -Implic      *Elem_B
+          Diag_C(ikl,isl) =  dz_8SV(isl) *LSdzsv(ikl)
+     .                      -Implic      *Elem_C
+ 
+          Term_D(ikl,isl) = (dz78SV(isl) *LSdzsv(ikl)
+     .                      +Explic      *Elem_B     )*eta_SV(ikl,isl)
+     .                    + (dz_8SV(isl) *LSdzsv(ikl)
+     .                      +Explic      *Elem_C     )*eta_SV(ikl,isl+1)
+     .                    + (bKdtSV3(ist,ikp)* dzi_SV(isl+1)*LSdzsv(ikl)
+     .                      +bKdtSV3(ist,ik0)*(dziiSV(isl+1)*LSdzsv(ikl)
+     .                                       -FreeDr                  ))
+        END DO
+ 
+           isl=0
+        DO ikl=1,knonv
+          ist      =         isotSV(ikl)
+          ikm      = nkhy *  eta_SV(ikl,isl-1) / etadSV(ist)
+          ik0      = nkhy *  eta_SV(ikl,isl)   / etadSV(ist)
+          Elem_A   =         Dhydtz(ikl,isl)
+     .                    -  aKdtSV3(ist,ikm)* dziiSV(isl)*LSdzsv(ikl)
+          Elem_B   =      - (Dhydtz(ikl,isl)
+     .                      +aKdtSV3(ist,ik0)* dzi_SV(isl)*LSdzsv(ikl))
+          Elem_C   =         0.
+          Diag_A(ikl,isl) =  dz_8SV(isl) *LSdzsv(ikl)
+     .                    -  Implic      *Elem_A
+          Diag_B(ikl,isl) =  dz78SV(isl) *LSdzsv(ikl)
+     .                    -  Implic      *Elem_B
+          Diag_C(ikl,isl) =  0.
+C +
+          Term_D(ikl,isl) = (dz_8SV(isl) *LSdzsv(ikl)
+     .                      +Explic      *Elem_A     )*eta_SV(ikl,isl-1)
+     .                    + (dz78SV(isl) *LSdzsv(ikl)
+     .                      +Explic      *Elem_B     )*eta_SV(ikl,isl)
+     .                    - (bKdtSV3(ist,ik0)* dzi_SV(isl)
+     .                      +bKdtSV3(ist,ikm)* dziiSV(isl))*LSdzsv(ikl)
+     .            + dt__SV *(HLs_sv(ikl)    *     (1-min(1,isnoSV(ikl)))
+     .                     / (ro_Wat *dz_dSV(0) * Lx_H2O(ikl))
+cXF bug 17/05/2017
+     .                      +drr_SV(ikl))/ro_Wat
+        END DO
+ 
+        DO ikl=1,knonv
+         drr_SV(ikl)=0. ! drr is included in the 1st soil layer
+        ENDDO
+ 
+C +
+C +
+C +--Tridiagonal Elimination
+C +  =======================
+C +
+C +--Forward  Sweep
+C +  ^^^^^^^^^^^^^^
+        DO ikl=  1,knonv
+          Aux__P(ikl,-nsol) = Diag_B(ikl,-nsol)
+          Aux__Q(ikl,-nsol) =-Diag_C(ikl,-nsol)/Aux__P(ikl,-nsol)
+        END DO
+C +
+      DO   isl=-nsol+1,0
+        DO ikl=      1,knonv
+          Aux__P(ikl,isl)   = Diag_A(ikl,isl)  *Aux__Q(ikl,isl-1)
+     .                       +Diag_B(ikl,isl)
+          Aux__Q(ikl,isl)   =-Diag_C(ikl,isl)  /Aux__P(ikl,isl)
+        END DO
+      END DO
+C +
+        DO ikl=      1,knonv
+          eta_SV(ikl,-nsol) = Term_D(ikl,-nsol)/Aux__P(ikl,-nsol)
+        END DO
+C +
+      DO   isl=-nsol+1,0
+        DO ikl=      1,knonv
+          eta_SV(ikl,isl)   =(Term_D(ikl,isl)
+     .                       -Diag_A(ikl,isl)  *eta_SV(ikl,isl-1))
+     .                                         /Aux__P(ikl,isl)
+        END DO
+      END DO
+ 
+C +--Backward Sweep
+C +  ^^^^^^^^^^^^^^
+      DO   isl=-1,-nsol,-1
+        DO ikl= 1,knonv
+          eta_SV(ikl,isl)   = Aux__Q(ikl,isl)  *eta_SV(ikl,isl+1)
+     .                                         +eta_SV(ikl,isl)
+        END DO
+      END DO
+ 
+ 
+C +--Horton RunOFF Intensity
+C +  =======================
+ 
+      DO   isl=0,-nsol,-1
+        DO ikl=1,knonv
+          ist    =   isotSV(ikl)                   ! Soil Type
+          SatRat =  (eta_SV(ikl,isl)-etadSV(ist))  ! OverSaturation Rate
+     .              *ro_Wat         *dzAvSV(isl)   !
+     .                              *LSdzsv(ikl)   !
+     .                              /dt__SV        !
+          SoRnOF(ikl)     =          SoRnOF(ikl)   !
+     .                    + max(zero,SatRat)       !
+          RuofSV(ikl,3)   = RuofSV(ikl,3) +
+     .                    + max(zero,SatRat)
+          eta_SV(ikl,isl) = max(epsi               !
+c #ED.                         +etamSV(isotSV(ikl))!
+     .                         ,eta_SV(ikl,isl))   !
+          eta_SV(ikl,isl) = min(eta_SV(ikl,isl)    !
+     .                         ,etadSV(ist)    )   !
+        END DO
+      END DO
+ 
+C +--IO, for Verification
+C +  ~~~~~~~~~~~~~~~~~~~~
+c #WR     write(6,6010)
+ 6010     format(/,1x)
+      DO   isl= 0,-nsol,-1
+        DO ikl= 1,knonv
+          ist      =          isotSV(ikl)
+          ikp      = nkhy  *  eta_SV(ikl,isl)  /etadSV(ist)
+          Khydsv(ikl,isl)   =(aKdtSV3(ist,ikp)  *eta_SV(ikl,isl)
+     .                       +bKdtSV3(ist,ikp)) *2.0/dt__SV
+c #WR     write(6,6011) ikl,isl,eta_SV(ikl,isl)*1.e3,
+c #WR.                  ikp,    aKdtSV3(ist,ikp),bKdtSV3(ist,ikp),
+c #WR.                          Khydsv(ikl,isl)
+ 6011     format(2i3,f8.1,i3,3e12.3)
+        END DO
+      END DO
+ 
+ 
+C +--Additional RunOFF Intensity
+C +  ===========================
+ 
+        DO ikl=1,knonv
+          ist      =          isotSV(ikl)
+          ik0      = nkhy  *  etaaux(ikl,-nsol  ) /etadSV(ist)
+c #       FreeDr   =          FreeD0            *  min(ist,1)
+          FreeDr   =          iWaFSV(ikl)       *  min(ist,1)
+          SoRnOF(ikl) =  SoRnOF(ikl)
+     .                + (aKdtSV3(ist,ik0)*(etaaux(ikl,-nsol)*Explic
+     .                                   +eta_SV(ikl,-nsol)*Implic)
+     .                 + bKdtSV3(ist,ik0)                           )
+     .                 * FreeDr          *ro_Wat           /dt__SV
+        RuofSV(ikl,3) = RuofSV(ikl,3)
+     .                + (aKdtSV3(ist,ik0)*(etaaux(ikl,-nsol)*Explic
+     .                                   +eta_SV(ikl,-nsol)*Implic)
+     .                 + bKdtSV3(ist,ik0)                           )
+     .                 * FreeDr          *ro_Wat           /dt__SV
+ 
+C +--Full Run OFF: Update
+C +  ~~~~~~~~~~~~~~~~~~~~
+          RnofSV(ikl)   = RnofSV(ikl)   + SoRnOF(ikl)
+          RuofSV(ikl,4) = RuofSV(ikl,4) + SoRnOF(ikl)
+        END DO
+ 
+ 
+C +--Temperature Correction due to a changed Soil Energy Content
+C +  ===========================================================
+ 
+C +!!!    Mettre en oeuvre le couplage humidit?-?nergie
+ 
+ 
+C +--Bumps/Asperites Treatment
+C +  =========================
+ 
+C +--Average over Bump Depth (z0soil)
+C +  --------------------------------
+ 
+c #BP       z_Bump      = 0.
+c #BP     DO ikl=1,knonv
+c #BP       etBump(ikl) = 0.
+c #BP     END DO
+C +
+c #BP DO     isl=0,-nsol,-1
+c #BP       z0Bump      = z_Bump
+c #BP       z_Bump      = z_Bump      +  dzAvSV(isl)
+c #BP   IF (z_Bump.lt.z0soil)                                       THEN
+c #BP     DO ikl=1,knonv
+c #BP       etBump(ikl) = etBump(ikl) +  dzAvSV(isl)   *eta_SV(ikl,isl)
+c #BP     END DO
+c #BP   END IF
+c #BP   IF (z_Bump.gt.z0soil.AND.z0Bump.lt.z0soil)                  THEN
+c #BP     DO ikl=1,knonv
+c #BP       etBump(ikl) = etBump(ikl) + (z0soil-z0Bump)*eta_SV(ikl,isl)
+c #BP       etBump(ikl) = etBump(ikl) /  z0soil
+c #BP     END DO
+c #BP   END IF
+c #BP END DO
+ 
+ 
+C +--Correction
+C +  ----------
+ 
+c #BP       z_Bump      = 0.
+c #BP DO     isl=0,-nsol,-1
+c #BP       z0Bump =  z_Bump
+c #BP       z_Bump =  z_Bump +dzAvSV(isl)
+c #BP   IF (z_Bump.lt.z0soil)                                       THEN
+c #BP     DO ikl=1,knonv
+c #BP       eta_SV(ikl,isl) = etBump(ikl)
+c #BP     END DO
+c #BP   END IF
+c #BP   IF (z_Bump.gt.z0soil.AND.z0Bump.lt.z0soil)                  THEN
+c #BP       dzBump          =    z_Bump -  z0soil
+c #BP     DO ikl=1,knonv
+c #BP       eta_SV(ikl,isl) =(etBump(ikl)    *(dzAvSV(isl)-dzBump)
+c #BP.                      + eta_SV(ikl,isl)*             dzBump)
+c #BP.                      /                  dzAvSV(isl)
+c #BP     END DO
+c #BP   END IF
+c #BP END DO
+ 
+ 
+C +--Positive Definite
+C +  =================
+ 
+c #BP DO   isl= 0,-nsol,-1
+c #BP   DO ikl= 1,knonv
+c #BP     eta_SV(ikl,isl)   =          max(epsi,eta_SV(ikl,isl))
+c #BP   END DO
+c #BP END DO
+ 
+ 
+C +--Water  Budget (OUT)
+C +  ===================
+ 
+! #m0   DO ikl=1,knonv
+! #m0     Wats_d(ikl) = Wats_d(ikl)                    !
+! #m0.                + drr_SV(ikl)     *zero          ! Precipitation is
+C +                                      \______________ already included
+! #m0.                + HLs_sv(ikl)
+! #m0.          *(1-min(isnoSV(ikl),1)) /Lx_H2O(ikl)   ! Evaporation
+! #m0.                - SoRnOF(ikl)                    ! Soil RunOFF Contrib.
+! #m0     Wats_1(ikl) = 0.                             !
+c #mw     Evapor(ikl) = HLs_sv(ikl)     *dt__SV        !
+c #mw.          *(1-min(isnoSV(ikl),1)) /Lx_H2O(ikl)   !
+! #m0   END DO
+ 
+! #m0 DO   isl= -nsol,0
+! #m0   DO ikl=1,knonv
+! #m0     Wats_d(ikl) = Wats_d(ikl)                    !
+! #m0   END DO
+! #m0 END DO
+! #m0   DO ikl=1,knonv
+! #m0     Wats_d(ikl) = Wats_d(ikl)     *dt__SV        !
+! #m0   END DO
+ 
+! #m0      isl= -nsol
+! #m0   DO ikl=1,knonv
+! #m0     Wats_1(ikl) = Wats_1(ikl)
+! #m0.      + ro_Wat *( eta_SV(ikl,isl)   *dz78SV(isl)
+! #m0.                + eta_SV(ikl,isl+1) *dz_8SV(isl) ) *LSdzsv(ikl)
+! #m0   END DO
+ 
+! #m0 DO   isl= -nsol+1,-1
+! #m0   DO ikl=1,knonv
+! #m0     Wats_1(ikl) = Wats_1(ikl)
+! #m0.      + ro_Wat *( eta_SV(ikl,isl)   *dz34SV(isl)
+! #m0.                +(eta_SV(ikl,isl-1)
+! #m0.                 +eta_SV(ikl,isl+1))*dz_8SV(isl) ) *LSdzsv(ikl)
+! #m0   END DO
+! #m0 END DO
+ 
+! #m0      isl=  0
+! #m0   DO ikl=1,knonv
+! #m0     Wats_1(ikl) = Wats_1(ikl)
+! #m0.      + ro_Wat *( eta_SV(ikl,isl)   *dz78SV(isl)
+! #m0.                + eta_SV(ikl,isl-1) *dz_8SV(isl) ) *LSdzsv(ikl)
+! #m0   END DO
+ 
+ 
+      return
+      end
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_sop.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_sop.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_sop.F	(revision 3792)
@@ -0,0 +1,521 @@
+ 
+ 
+      subroutine SnOptP(jjtime)
+ 
+C +------------------------------------------------------------------------+
+C | MAR/SISVAT   SnOptP                                    12-08-2019  MAR |
+C |   SubRoutine SnOptP computes the Snow Pack optical Properties          |
+C +------------------------------------------------------------------------+
+C |                                                                        |
+C |   PARAMETERS:  knonv: Total Number of columns =                        |
+C |   ^^^^^^^^^^        = Total Number of continental     Grid Boxes       |
+C |                     X       Number of Mosaic Cell per Grid Box         |
+C |                                                                        |
+C |   INPUT:   isnoSV   = total Nb of Ice/Snow Layers                      |
+C |   ^^^^^    ispiSV   = 0,...,nsno: Uppermost Superimposed Ice Layer     |
+C |                                                                        |
+C |                                                                        |
+C |   INPUT:   G1snSV   : Dendricity (<0) or Sphericity (>0) of Snow Layer |
+C |   ^^^^^    G2snSV   : Sphericity (>0) or Size            of Snow Layer |
+C |            agsnSV   : Snow       Age                             [day] |
+C |            ro__SV   : Snow/Soil  Volumic Mass                  [kg/m3] |
+C |            eta_SV   : Water      Content                       [m3/m3] |
+C |            rusnSV   : Surficial  Water   Thickness   [kg/m2] .OR. [mm] |
+C |            SWS_SV   : Surficial  Water   Status                        |
+C |            dzsnSV   : Snow       Layer   Thickness                 [m] |
+C |                                                                        |
+C |            albssv   : Soil       Albedo                            [-] |
+C |            zzsnsv   : Snow       Pack    Thickness                 [m] |
+C |                                                                        |
+C |   OUTPUT:  albisv   : Snow/Ice/Water/Soil Integrated Albedo        [-] |
+C |   ^^^^^^   sEX_sv   : Verticaly Integrated Extinction Coefficient      |
+C |                                                                        |
+C |   Internal Variables:                                                  |
+C |   ^^^^^^^^^^^^^^^^^^                                                   |
+C |            SnOpSV   : Snow Grain optical Size                      [m] |
+C |            EX1_sv   : Integrated Snow Extinction (0.3--0.8micr.m)      |
+C |            EX2_sv   : Integrated Snow Extinction (0.8--1.5micr.m)      |
+C |            EX3_sv   : Integrated Snow Extinction (1.5--2.8micr.m)      |
+C |                                                                        |
+C |   METHODE:    Calcul de la taille optique des grains ? partir de       |
+C |   ^^^^^^^    -leur type decrit par les deux variables descriptives     |
+C |                    continues sur la plage -99/+99 passees en appel.    |
+C |              -la taille optique (1/10mm) des etoiles,                  |
+C |                                          des grains fins et            |
+C |                                          des jeunes faces planes       |
+C |                                                                        |
+C |   METHOD:     Computation of the optical diameter of the grains        |
+C |   ^^^^^^      described with the CROCUS formalism G1snSV / G2snSV      |
+C |                                                                        |
+C |   REFERENCE: Brun et al.      1989, J. Glaciol 35 pp. 333--342         |
+C |   ^^^^^^^^^  Brun et al.      1992, J. Glaciol 38 pp.  13-- 22         |
+C |              Eric Martin Sept.1996                                     |
+C |                                                                        |
+C |                                                                        |
+C +------------------------------------------------------------------------+
+ 
+ 
+ 
+ 
+C +--Global Variables
+C +  ================
+ 
+
+      use VARphy
+      use VAR_SV
+      use VARdSV
+      use VARxSV
+      use VARySV
+      use VARtSV
+      USE surface_data, only: iflag_albzenith
+
+      IMPLICIT NONE
+
+ 
+C + -- INPUT
+      integer jjtime
+
+C +--Internal Variables
+C +  ==================
+ 
+      real      coalb1(knonv)                      ! weighted Coalbedo, Vis.
+      real      coalb2(knonv)                      ! weighted Coalbedo, nIR 1
+      real      coalb3(knonv)                      ! weighted Coalbedo, nIR 2
+      real      coalbm                             ! weighted Coalbedo, mean
+      real      sExt_1(knonv)                      ! Extinction Coeff., Vis.
+      real      sExt_2(knonv)                      ! Extinction Coeff., nIR 1
+      real      sExt_3(knonv)                      ! Extinction Coeff., nIR 2
+      real      SnOpSV(knonv,      nsno)           ! Snow Grain optical Size
+c #AG real      agesno
+ 
+      integer   isn   ,ikl   ,isn1  
+      real      sbeta1,sbeta2,sbeta3,sbeta4,sbeta5
+      real      AgeMax,AlbMin,HSnoSV,HIceSV,doptmx,SignG1,Sph_OK
+      real      dalbed,dalbeS,dalbeW
+      real      bsegal,czemax,csegal
+      real      RoFrez,DiffRo,SignRo,SnowOK,OpSqrt
+      real      albSn1,albIc1,a_SnI1,a_SII1
+      real      albSn2,albIc2,a_SnI2,a_SII2
+      real      albSn3,albIc3,a_SnI3,a_SII3
+      real      albSno,albIce,albSnI,albSII,albWIc,albmax
+      real      doptic,Snow_H,SIce_H,SnownH,SIcenH
+      real      exarg1,exarg2,exarg3,sign_0,sExt_0
+      real      albedo_old,albCor
+      real      ro_ave,dz_ave,minalb
+      real      thetazs,thetazs0,aap,bbp,ccp,alb0      ! parameters for zenoth angle effect at Dome C
+
+
+ 
+C +--Local   DATA
+C +  ============
+ 
+C +--For the computation of the solar irradiance extinction in snow
+C +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      data      sbeta1/0.0192/,sbeta2/0.4000/,sbeta3/0.1098/
+      data      sbeta4/1.0000/
+      data      sbeta5/2.00e1/
+ 
+C +--Snow Age Maximum (Taiga, e.g. Col de Porte)
+C +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      data      AgeMax  /60.0/
+C +...          AgeMax:  Snow Age Maximum                              [day]
+ 
+      data      AlbMin  /0.94/
+C +...          AlbMin:  Albedo   Minimum / visible (0.3--0.8 micrometers)
+ 
+      data      HSnoSV  /0.01/
+C +...          HSnoSV:  Snow     Thickness through witch
+C +                      Albedo is interpolated to Ice  Albedo
+      data      HIceSV  /0.10/
+C +...          HIceSV:  Snow/Ice Thickness through witch
+C +                      Albedo is interpolated to Soil Albedo
+      data      doptmx  /2.3e-3/
+C +...          doptmx:  Maximum  optical Diameter    (pi * R**2)        [m]
+C +
+      data      czeMAX  /0.173648178/  ! 80.deg (Segal et al., 1991 JAS)
+
+      data      bsegal  /4.00       /  !
+      data      albmax  /0.99       /  ! Albedo max
+
+C +-- For the computation of solar zenoth angle effect from Dome C data
+C +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      data      aap/0.00016/,bbp/-0.017/,ccp/1.2/
+
+ 
+ 
+C +--Snow Grain optical Size
+C +  =======================
+ 
+        DO ikl=1,knonv
+         DO   isn=1,max(1,isnoSV(ikl))
+ 
+          G2snSV(ikl,isn) =  max(epsi,G2snSV(ikl,isn))
+C +...    Avoid non physical Values
+ 
+          SignG1          = sign(unun,G1snSV(ikl,isn))
+          Sph_OK          =  max(zero,SignG1)
+ 
+          SnOpSV(ikl,isn) =   1.e-4 *
+C +...    SI:           (from 1/10 mm to m)
+ 
+ 
+C +--Contribution of Non Dendritic Snow
+C +  ----------------------------------
+ 
+     .    (    Sph_OK *(      G2snSV(ikl,isn)*G1snSV(ikl,isn)/G1_dSV
+     .              +max(demi*G2snSV(ikl,isn),DFcdSV)
+     .                 *(unun-G1snSV(ikl,isn)                /G1_dSV))
+ 
+ 
+C +--Contribution of     Dendritic Snow
+C +  ----------------------------------
+ 
+     .    +(1.-Sph_OK)*(     -G1snSV(ikl,isn)*DDcdSV         /G1_dSV
+     .                 +(unun+G1snSV(ikl,isn)                /G1_dSV)
+     .                  *    (G2snSV(ikl,isn)*DScdSV         /G1_dSV
+     .                 +(unun-G2snSV(ikl,isn)                /G1_dSV)
+     .                                       *DFcdSV                 )))
+          SnOpSV(ikl,isn) =  max(zero,SnOpSV(ikl,isn))
+        END DO
+      END DO
+ 
+ 
+C +--Snow/Ice Albedo
+C +  ===============
+
+ 
+ 
+C +--Uppermost effective Snow Layer
+C +  ------------------------------
+ 
+        DO ikl=1,knonv
+ 
+           isn   =  max(iun,isnoSV(ikl))
+ 
+          SignRo = sign(unun, rocdSV - ro__SV(ikl,isn))
+          SnowOK =  max(zero,SignRo) ! Ice Density Threshold
+ 
+          OpSqrt = sqrt(SnOpSV(ikl,isn))
+ 
+cCA    +--Correction of snow albedo for Antarctica/Greenland
+cCA       --------------------------------------------------
+          albCor = 1.
+c #GL     albCor = 1.01
+c #AC     albCor = 1.01
+ 
+          albSn1 =  0.96-1.580*OpSqrt
+          albSn1 =  max(albSn1,AlbMin)
+ 
+          albSn1 =  max(albSn1,zero)
+          albSn1 =  min(albSn1*albCor,unun)
+ 
+          albSn2 =  0.95-15.40*OpSqrt
+          albSn2 =  max(albSn2,zero)
+          albSn2 =  min(albSn2*albCor,unun)
+ 
+          doptic =  min(SnOpSV(ikl,isn),doptmx)
+          albSn3 =  346.3*doptic -32.31*OpSqrt +0.88
+          albSn3 =  max(albSn3,zero)
+          albSn3 =  min(albSn3*albCor,unun)
+ 
+          !snow albedo corection if wetsnow
+c #GL     albSn1 =  albSn1*max(0.9,(1.-1.5*eta_SV(ikl,isn)))
+c #GL     albSn2 =  albSn2*max(0.9,(1.-1.5*eta_SV(ikl,isn)))
+c #GL     albSn3 =  albSn3*max(0.9,(1.-1.5*eta_SV(ikl,isn)))
+ 
+          albSno =  So1dSV*albSn1
+     .           +  So2dSV*albSn2
+     .           +  So3dSV*albSn3
+ 
+cXF
+          minalb =  (aI2dSV + (aI3dSV -aI2dSV)
+     .           *  (ro__SV(ikl,isn)-ro_Ice)/(roSdSV-ro_Ice))
+          minalb =  min(aI3dSV,max(aI2dSV,minalb)) ! pure/firn albedo
+ 
+          SnowOK =  SnowOK*max(zero,sign(unun,     albSno-minalb))
+          albSn1 =  SnowOK*albSn1+(1.0-SnowOK)*max(albSno,minalb)
+          albSn2 =  SnowOK*albSn2+(1.0-SnowOK)*max(albSno,minalb)
+          albSn3 =  SnowOK*albSn3+(1.0-SnowOK)*max(albSno,minalb)
+ 
+c +           ro < roSdSV |          min al > aI3dSV
+c +  roSdSV < ro < rocdSV | aI2dSV < min al < aI3dSV (fct of density)
+ 
+ 
+C +--Snow/Ice Pack Thickness
+C +  -----------------------
+ 
+          isn    =    max(min(isnoSV(ikl) ,ispiSV(ikl)),0)
+          Snow_H =  zzsnsv(ikl,isnoSV(ikl))-zzsnsv(ikl,isn)
+          SIce_H =  zzsnsv(ikl,isnoSV(ikl))
+          SnownH =  Snow_H  /  HSnoSV
+          SnownH =  min(unun,  SnownH)
+          SIcenH =  SIce_H  / (HIceSV)
+          SIcenH =  min(unun,  SIcenH)
+ 
+C +       The value of SnownH is set to 1 in case of ice lenses above
+C +       1m of dry snow (ro<600kg/m3) for using CROCUS albedo
+ 
+c         ro_ave =  0.
+c         dz_ave =  0.
+c         SnowOK =  1.
+c      do isn    =  isnoSV(ikl),1,-1
+c         ro_ave =  ro_ave + ro__SV(ikl,isn) * dzsnSV(ikl,isn) * SnowOK
+c         dz_ave =  dz_ave +                   dzsnSV(ikl,isn) * SnowOK
+c         SnowOK =  max(zero,sign(unun,1.-dz_ave))
+c      enddo
+ 
+c         ro_ave =  ro_ave / max(dz_ave,epsi)
+c         SnowOK =  max(zero,sign(unun,600.-ro_ave))
+c         SnownH =  SnowOK + SnownH * (1. - SnowOK)
+ 
+C +--Integrated Snow/Ice Albedo: Case of Water on Bare Ice
+C +  -----------------------------------------------------
+ 
+          isn    =  max(min(isnoSV(ikl) ,ispiSV(ikl)),0)
+ 
+          albWIc =  aI1dSV-(aI1dSV-aI2dSV)
+     .           *  exp(-(rusnSV(ikl)                      !
+     .           *  (1. -SWS_SV(ikl)                       ! 0 <=> freezing
+     .           *  (1  -min(1,iabs(isn-isnoSV(ikl)))))    ! 1 <=> isn=isnoSV
+     .           /   ru_dSV)**0.50)                        !
+c         albWIc = max(aI1dSV,min(aI2dSV,albWIc+slopSV(ikl)*
+c    .             min(5.,max(1.,dx/10000.))))
+ 
+          SignRo = sign(unun,ro_Ice-5.-ro__SV(ikl,isn))    ! RoSN<920kg/m3
+          SnowOK =  max(zero,SignRo)
+ 
+          albWIc = (1. - SnowOK) * albWIc + SnowOK
+     .           * (aI2dSV + (aI3dSV -aI2dSV)
+     .           * (ro__SV(ikl,isn)-ro_Ice)/(roSdSV-ro_Ice))
+ 
+c +  rocdSV < ro < ro_ice | aI2dSV< al <aI3dSV (fct of density)
+c +           ro > ro_ice | aI1dSV< al <aI2dSV (fct of superficial water content
+ 
+ 
+C +--Integrated Snow/Ice      Albedo
+C +  -------------------------------
+ 
+          a_SII1      =     albWIc      +(albSn1-albWIc)     *SnownH
+          a_SII1      = min(a_SII1       ,albSn1)
+ 
+          a_SII2      =     albWIc      +(albSn2-albWIc)     *SnownH
+          a_SII2      = min(a_SII2       ,albSn2)
+ 
+          a_SII3      =     albWIc      +(albSn3-albWIc)     *SnownH
+          a_SII3      = min(a_SII3       ,albSn3)
+ 
+cc #AG     agesno =      min(agsnSV(ikl,isn)          ,AgeMax)
+cc #AG     a_SII1      =     a_SII1      -0.175*agesno/AgeMax
+C +...                                   Impurities: Col de Porte Parameter.
+ 
+ 
+!    Zenith Angle Correction (Segal et al.,         1991, JAS 48, p.1025)
+!    ----------------------- (Wiscombe & Warren, dec1980, JAS   , p.2723)
+!                            (Warren,               1982,  RG   , p.  81)
+!                            (Vignon, PhD Thesis, pp 150, conditions at Dome C)
+!                            -------------------------------------------------
+ 
+         
+          dalbed = 0.0
+
+          if (iflag_albzenith .GE. 0) then
+          csegal = max(czemax                   ,coszSV(ikl))
+c #cz     dalbeS =   ((bsegal+unun)/(unun+2.0*bsegal*csegal)
+c #cz.                -       unun                          )*0.32
+c #cz.              /  bsegal
+c #cz     dalbeS = max(dalbeS,zero)
+c #cz     dalbed =     dalbeS      *       min(1,isnoSV(ikl))
+ 
+          dalbeW =(0.64 - csegal  )*0.0625  ! Warren 1982, RevGeo, fig.12b
+                                            ! 0.0625 = 5% * 1/0.8,   p.81
+                                            ! 0.64   = cos(50)
+          dalbed =     dalbeW      *       min(1,isnoSV(ikl))
+
+
+! Vignon PhD thesis, Dome C conditions
+
+            if (iflag_albzenith .EQ. 1) then
+            thetazs0=-bbp/(2.0*aap)
+            alb0=(bbp**2)/4./aap-(bbp**2)/2./aap+ccp
+            thetazs=max(acos(coszSV(ikl))/pi*180.0,thetazs0) ! in degrees
+
+
+            dalbeW = aap*(thetazs**2)+bbp*thetazs+ccp-alb0       
+            dalbed =     dalbeW      *       min(1,isnoSV(ikl))
+            end if
+
+
+            end if
+ 
+C +--Elsewhere    Integrated Snow/Ice Albedo
+C +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+c #cp     ELSE
+            albSII =     So1dSV*a_SII1
+     .                 + So2dSV*a_SII2
+     .                 + So3dSV*a_SII3
+c #cp     END IF
+ 
+ 
+C +--Integrated Snow/Ice/Soil Albedo
+C +  -------------------------------
+ 
+            alb1sv(ikl) =     albssv(ikl) +(a_SII1-albssv(ikl))*SIcenH
+            alb1sv(ikl) = min(alb1sv(ikl)  ,a_SII1)
+ 
+            alb2sv(ikl) =     albssv(ikl) +(a_SII2-albssv(ikl))*SIcenH
+            alb2sv(ikl) = min(alb2sv(ikl)  ,a_SII2)
+ 
+            alb3sv(ikl) =     albssv(ikl) +(a_SII3-albssv(ikl))*SIcenH
+            alb3sv(ikl) = min(alb3sv(ikl)  ,a_SII3)
+ 
+            albisv(ikl) =     albssv(ikl) +(albSII-albssv(ikl))*SIcenH
+            albisv(ikl) = min(albisv(ikl)  ,albSII)
+ 
+ 
+C +--Integrated Snow/Ice/Soil Albedo: Clouds Correction! Greuell & all., 1994
+C +  --------------------------------------------------! Glob.&t Planet.Change
+                                                       ! (9):91-114
+            alb1sv(ikl) = alb1sv(ikl) + 0.05 *(cld_SV(ikl)-0.5)*SIcenH
+     .                  + dalbed      *    (1.-cld_SV(ikl))
+            alb2sv(ikl) = alb2sv(ikl) + 0.05 *(cld_SV(ikl)-0.5)*SIcenH
+     .                  + dalbed      *    (1.-cld_SV(ikl))
+            alb3sv(ikl) = alb3sv(ikl) + 0.05 *(cld_SV(ikl)-0.5)*SIcenH
+     .                  + dalbed      *    (1.-cld_SV(ikl))
+            albisv(ikl) = albisv(ikl) + 0.05 *(cld_SV(ikl)-0.5)*SIcenH
+     .                  + dalbed      *    (1.-cld_SV(ikl))
+ 
+C +--Integrated Snow/Ice/Soil Albedo: Minimum snow albedo = aI1dSV
+C +  -------------------------------------------------------------
+ 
+            albedo_old  = albisv(ikl)
+            albisv(ikl) = max(albisv(ikl),aI1dSV   * SIcenH
+     .                  + albssv(ikl) *(1.0        - SIcenH))
+            alb1sv(ikl) = alb1sv(ikl) - 1.0/3.0             ! 33 %
+     .                  * (albedo_old-albisv(ikl)) / So1dSV
+            alb2sv(ikl) = alb2sv(ikl) - 1.0/3.0             ! 33 %
+     .                  * (albedo_old-albisv(ikl)) / So2dSV
+            alb3sv(ikl) = alb3sv(ikl) - 1.0/3.0             ! 33 %
+     .                  * (albedo_old-albisv(ikl)) / So3dSV
+ 
+ 
+C +--Integrated Snow/Ice/Soil Albedo: Maximum albedo = 95%
+C +  -----------------------------------------------------
+ 
+            albedo_old  = albisv(ikl)
+            albisv(ikl) = min(albisv(ikl),0.95)
+            alb1sv(ikl) = alb1sv(ikl) - 1.0/3.0             ! 33 %
+     .                  * (albedo_old-albisv(ikl)) / So1dSV
+            alb2sv(ikl) = alb2sv(ikl) - 1.0/3.0             ! 33 %
+     .                  * (albedo_old-albisv(ikl)) / So2dSV
+            alb3sv(ikl) = alb3sv(ikl) - 1.0/3.0             ! 33 %
+     .                  * (albedo_old-albisv(ikl)) / So3dSV
+
+
+	!Sea Ice/snow permanent-interractive prescription from Nemo 
+	!AO_CK 20/02/2020
+
+        ! No check if coupling update since MAR and NEMO albedo are too different
+	! and since MAR albedo is computed on properties that are not in NEMO
+        ! prescription for each time step with NEMO values 
+	
+c #AO      if (LSmask(ikl) .eq. 0 .and. coupling_ao .eq. .true.) then 
+c #AO       if (AOmask(ikl) .eq. 0) then  
+c #AO       albisv(ikl) =  (1.-AOmask(ikl))* albAOsisv(ikl)
+c #AO.                    +(AOmask(ikl)*albisv(ikl))
+c #AO       alb1sv(ikl) =   (1.-AOmask(ikl))* albAOsisv(ikl)
+c #AO.                    +(AOmask(ikl)*alb1sv(ikl))
+c #AO       alb2sv(ikl) =   (1.-AOmask(ikl))* albAOsisv(ikl)
+c #AO.                    +(AOmask(ikl)*alb2sv(ikl))
+c #AO       alb3sv(ikl) =   (1.-AOmask(ikl))* albAOsisv(ikl)
+c #AO.                    +(AOmask(ikl)*alb3sv(ikl))
+c #AO       endif
+c #AO      endif
+
+ 
+            alb1sv(ikl) = min(max(zero,alb1sv(ikl)),albmax)
+            alb2sv(ikl) = min(max(zero,alb2sv(ikl)),albmax)
+            alb3sv(ikl) = min(max(zero,alb3sv(ikl)),albmax)
+ 
+        END DO
+ 
+ 
+C +--Extinction Coefficient: Exponential Factor
+C +  ==========================================
+ 
+        DO ikl=1,knonv
+          sExt_1(ikl)        = 1.
+          sExt_2(ikl)        = 1.
+          sExt_3(ikl)        = 1.
+          sEX_sv(ikl,nsno+1) = 1.
+ 
+          coalb1(ikl) = (1.          -alb1sv(ikl))*So1dSV
+          coalb2(ikl) = (1.          -alb2sv(ikl))*So2dSV
+          coalb3(ikl) = (1.          -alb3sv(ikl))*So3dSV
+          coalbm      =  coalb1(ikl) +coalb2(ikl) +coalb3(ikl)
+          coalb1(ikl) =  coalb1(ikl)              /coalbm
+          coalb2(ikl) =  coalb2(ikl)              /coalbm
+          coalb3(ikl) =  coalb3(ikl)              /coalbm
+        END DO
+ 
+cXF
+ 
+        DO   isn=nsno,1,-1
+          DO ikl=1,knonv
+            sEX_sv(ikl,isn) = 1.0
+           !sEX_sv(ikl,isn) = 0.95 ! if MAR is too warm in summer
+          END DO
+        END DO
+ 
+        DO ikl=1,knonv
+         DO isn=max(1,isnoSV(ikl)),1,-1
+ 
+          SignRo = sign(unun, rocdSV - ro__SV(ikl,isn))
+          SnowOK =  max(zero,SignRo) ! Ice Density Threshold
+ 
+          RoFrez =  1.e-3      * ro__SV(ikl,isn) * (1.0-eta_SV(ikl,isn))
+ 
+          OpSqrt = sqrt(max(epsi,SnOpSV(ikl,isn)))
+          exarg1 =      SnowOK  *1.e2 *max(sbeta1*RoFrez/OpSqrt,sbeta2)
+     .            +(1.0-SnowOK)           *sbeta5
+          exarg2 =      SnowOK  *1.e2 *max(sbeta3*RoFrez/OpSqrt,sbeta4)
+     .            +(1.0-SnowOK)           *sbeta5
+          exarg3 =      SnowOK  *1.e2     *sbeta5
+     .            +(1.0-SnowOK)           *sbeta5
+ 
+ 
+C +--Integrated Extinction of Solar Irradiance (Normalized Value)
+C +  ============================================================
+ 
+          sExt_1(ikl) = sExt_1(ikl)
+     .                          * exp(min(0.0,-exarg1 *dzsnSV(ikl,isn)))
+          sign_0      =              sign(unun,eps9   -sExt_1(ikl))
+          sExt_0      =               max(zero,sign_0)*sExt_1(ikl)
+          sExt_1(ikl) = sExt_1(ikl)                   -sExt_0
+ 
+          sExt_2(ikl) = sExt_2(ikl)
+     .                          * exp(min(0.0,-exarg2 *dzsnSV(ikl,isn)))
+          sign_0      =              sign(unun,eps9   -sExt_2(ikl))
+          sExt_0      =               max(zero,sign_0)*sExt_2(ikl)
+          sExt_2(ikl) = sExt_2(ikl)                   -sExt_0
+ 
+          sExt_3(ikl) = sExt_3(ikl)
+     .                          * exp(min(0.0,-exarg3 *dzsnSV(ikl,isn)))
+          sign_0      =              sign(unun,eps9   -sExt_3(ikl))
+          sExt_0      =               max(zero,sign_0)*sExt_3(ikl)
+          sExt_3(ikl) = sExt_3(ikl)                   -sExt_0
+ 
+          sEX_sv(ikl,isn) = coalb1(ikl) * sExt_1(ikl)
+     .                    + coalb2(ikl) * sExt_2(ikl)
+     .                    + coalb3(ikl) * sExt_3(ikl)
+        END DO
+      END DO
+ 
+      DO   isn=0,-nsol,-1
+        DO ikl=1,knonv
+          sEX_sv(ikl,isn) = 0.0
+        END DO
+      END DO
+ 
+ 
+      return
+      end
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_ts2.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_ts2.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_ts2.F	(revision 3792)
@@ -0,0 +1,477 @@
+      subroutine SISVAT_TS2                                                     
+c #ES.                     (ETSo_0,ETSo_1,ETSo_d)                               
+                                                                                
+C +------------------------------------------------------------------------+    
+C | MAR          SISVAT_TS2                            Mon 16-08-2009  MAR |    
+C |   SubRoutine SISVAT_TS2 computes the Soil/Snow temperature and fluxes  |
+C |   using the same method as in LMDZ for consistency.                    |
+C |   The corresponding LMDZ routines are soil (soil.F90) and calcul_fluxs |
+C |   (calcul_fluxs_mod.F90).                                              |   
+C +------------------------------------------------------------------------+    
+C |                                                                        |    
+C |                                                                        |    
+C |   PARAMETERS:  klonv: Total Number of columns =                        |    
+C |   ^^^^^^^^^^        = Total Number of grid boxes of surface type       |    
+C |                       (land ice for now)                               |    
+C |                                                                        |    
+C |   INPUT:   isnoSV   = total Nb of Ice/Snow Layers                      |    
+C |   ^^^^^    sol_SV   : Downward Solar Radiation                  [W/m2] |    
+C |            IRd_SV   : Surface Downward  Longwave   Radiation    [W/m2] |       
+C |            VV__SV   : SBL Top    Wind Speed                      [m/s] |    
+C |            TaT_SV   : SBL Top    Temperature                       [K] |     
+C |            QaT_SV   : SBL Top    Specific  Humidity            [kg/kg] |      
+C |            dzsnSV   : Snow Layer Thickness                         [m] |        
+C |            dt__SV   : Time Step                                    [s] |    
+C |                                                                        |    
+C |            SoSosv   : Absorbed Solar Radiation by Surfac.(Normaliz)[-] |    
+C |            Eso_sv   : Soil+Snow       Emissivity                   [-] |    
+C |   ?        rah_sv   : Aerodynamic Resistance for Heat            [s/m] |    
+C |                                                                        | 
+C |            dz1_SV    : "inverse" layer thickness (centered)      [1/m] |
+C |            dz2_SV    : layer thickness (layer above (?))           [m] |
+C |            AcoHSV    : coefficient for Enthalpy evolution, from atm.   |
+C |            AcoHSV    : coefficient for Enthalpy evolution, from atm.   |
+C |            AcoQSV    : coefficient for Humidity evolution, from atm.   | 
+C |            BcoQSV    : coefficient for Humidity evolution, from atm.   |
+C |            ps__SV    : surface pressure                           [Pa] |
+C |            p1l_SV    : 1st atmospheric layer pressure             [Pa] |     
+C |            cdH_SV    : drag coeff Energy (?)                           |
+C |            rsolSV    : Radiation balance surface                [W/m2] |
+C |            lambSV    : Coefficient for soil layer geometry         [-] |
+C |                                                                        |    
+C |   INPUT /  TsisSV   : Soil/Ice Temperatures (layers -nsol,-nsol+1,..,0)|    
+C |   OUTPUT:           & Snow     Temperatures (layers  1,2,...,nsno) [K] |    
+C |   ^^^^^^   rsolSV   : Radiation balance surface                 [W/m2] |     
+C |                                                                        |    
+C |   OUTPUT:  IRs_SV   : Soil      IR Radiation                    [W/m2] |    
+C |   ^^^^^^   HSs_sv   : Sensible  Heat Flux                       [W/m2] |    
+C |            HLs_sv   : Latent    Heat Flux                       [W/m2] |  
+C |            TsfnSV   : new surface temperature                      [K] |
+C |            Evp_sv   : Evaporation                              [kg/m2] |
+C |            dSdTSV   : Sensible Heat Flux temp. derivative     [W/m2/K] |
+C |            dLdTSV   : Latent Heat Flux temp. derivative       [W/m2/K] |
+C |                                                                        | 
+C |   ?        ETSo_0   : Snow/Soil Energy Power, before Forcing    [W/m2] |    
+C |   ?        ETSo_1   : Snow/Soil Energy Power, after  Forcing    [W/m2] |    
+C |   ?        ETSo_d   : Snow/Soil Energy Power         Forcing    [W/m2] |    
+C |                                                                        | 
+C |________________________________________________________________________|
+
+      USE VAR_SV
+      USE VARdSV
+ 
+      USE VARySV                      
+      USE VARtSV                      
+      USE VARxSV 
+      USE VARphy
+      USE indice_sol_mod
+
+
+      IMPLICIT NONE                                                                    
+                                                                                
+                                                                                
+C +--Global Variables                                                           
+C +  ================                                                          
+
+      INCLUDE "YOMCST.h"
+      INCLUDE "YOETHF.h"
+      INCLUDE "FCTTRE.h"
+!      INCLUDE "indicesol.h"
+      INCLUDE "comsoil.h"
+!      include  "LMDZphy.inc"   
+                                                                        
+C +--OUTPUT for Stand Alone NetCDF File                                         
+C +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                         
+c #NC      real*8        SOsoKL(klonv)             ! Absorbed Solar Radiation        
+c #NC      real*8        IRsoKL(klonv)             ! Absorbed IR    Radiation        
+c #NC      real*8        HSsoKL(klonv)             ! Absorbed Sensible Heat Flux     
+c #NC      real*8        HLsoKL(klonv)             ! Absorbed Latent   Heat Flux     
+c #NC      real*8        HLs_KL(klonv)             ! Evaporation                     
+c #NC      real*8        HLv_KL(klonv)             ! Transpiration                   
+c #NC      common/DumpNC/SOsoKL,IRsoKL                                               
+c #NC     .             ,HSsoKL,HLsoKL                                               
+c #NC     .             ,HLs_KL,HLv_KL          
+
+C +--Internal Variables                                                         
+C +  ==================    
+
+      integer ig,jk,isl
+      real mu     
+      real Tsrf(klonv)               ! surface temperature as extrapolated from soil
+      real mug(klonv)                 !hj coef top layers 
+      real ztherm_i(klonv),zdz2(klonv,-nsol:nsno),z1s
+      real pfluxgrd(klonv), pcapcal(klonv), cal(klonv)
+      real beta(klonv), dif_grnd(klonv)
+      real C_coef(klonv,-nsol:nsno),D_coef(klonv,-nsol:nsno)
+
+      REAL, DIMENSION(klonv)   :: zx_mh, zx_nh, zx_oh
+      REAL, DIMENSION(klonv)   :: zx_mq, zx_nq, zx_oq
+      REAL, DIMENSION(klonv)   :: zx_pkh, zx_dq_s_dt, zx_qsat, zx_coef
+      REAL, DIMENSION(klonv)   :: zx_sl, zx_k1
+      REAL, DIMENSION(klonv)   :: d_ts
+      REAL                     :: zdelta, zcvm5, zx_qs, zcor, zx_dq_s_dh
+      REAL                     :: qsat_new, q1_new
+C      REAL, PARAMETER          :: t_grnd = 271.35, t_coup = 273.15
+C      REAL, PARAMETER          :: max_eau_sol = 150.0
+      REAL, DIMENSION(klonv)   :: IRs__D, dIRsdT
+
+
+      REAL t_grnd                      ! not used
+      parameter(t_grnd = 271.35)       !
+      REAL t_coup                      ! distinguish evap/sublimation
+      parameter(t_coup = 273.15)       !
+      REAL max_eau_sol
+      parameter(max_eau_sol = 150.0)
+
+
+!        write(*,*)'T check'
+!     
+!        DO  ig = 1,knonv  
+!            DO  jk = 1,isnoSV(ig) !nsno       
+!              IF (TsisSV(ig,jk) <= 1.) THEN          !hj check
+!                TsisSV(ig,jk) = TsisSV(ig,isnoSV(ig))
+!              ENDIF  
+!
+!              IF (TsisSV(ig,jk) <= 1.) THEN          !hj check
+!                TsisSV(ig,jk) = 273.15
+!              ENDIF   
+!            END DO
+!        END DO     
+
+C!=======================================================================
+C! I. First part: corresponds to soil.F90 in LMDZ
+C!=======================================================================
+
+      DO ig = 1,knonv      
+        DO jk =1,isnoSV(ig)
+          dz2_SV(ig,jk)=dzsnSV(ig,jk)
+C! use arithmetic center between layers to derive dz1 for snow layers for simplicity: 
+          dz1_SV(ig,jk)=2./(dzsnSV(ig,jk)+dzsnSV(ig,jk-1)) 
+        ENDDO
+      ENDDO
+
+      DO ig = 1,knonv
+        ztherm_i(ig)   = inertie_lic
+        IF (isnoSV(ig) > 0) ztherm_i(ig)   = inertie_sno
+      ENDDO
+
+C!-----------------------------------------------------------------------
+C! 1)
+C! Calculation of Cgrf and Dgrd coefficients using soil temperature from 
+C! previous time step.
+C!
+C! These variables are recalculated on the local compressed grid instead 
+C! of saved in restart file.
+C!-----------------------------------------------------------------------
+      DO ig=1,knonv
+        DO jk=-nsol,nsno
+          zdz2(ig,jk)=dz2_SV(ig,jk)/dt__SV                                !ptimestep
+        ENDDO
+      ENDDO
+ 
+      DO ig=1,knonv
+        z1s = zdz2(ig,-nsol)+dz1_SV(ig,-nsol+1)
+        C_coef(ig,-nsol+1)=zdz2(ig,-nsol)*TsisSV(ig,-nsol)/z1s
+        D_coef(ig,-nsol+1)=dz1_SV(ig,-nsol+1)/z1s
+      ENDDO
+
+      DO ig=1,knonv
+        DO jk=-nsol+1,isnoSV(ig)-1,1
+          z1s = 1./(zdz2(ig,jk)+dz1_SV(ig,jk+1)+dz1_SV(ig,jk)           &
+     &          *(1.-D_coef(ig,jk)))
+          C_coef(ig,jk+1)=                                              &
+     &          (TsisSV(ig,jk)*zdz2(ig,jk)                              &
+     &          +dz1_SV(ig,jk)*C_coef(ig,jk)) * z1s
+          D_coef(ig,jk+1)=dz1_SV(ig,jk+1)*z1s
+        ENDDO
+      ENDDO
+
+C!-----------------------------------------------------------------------
+C! 2)
+C! Computation of the soil temperatures using the Cgrd and Dgrd
+C! coefficient computed above
+C!
+C!-----------------------------------------------------------------------
+C! Extrapolate surface Temperature                   !hj check
+      mu=1./((2.**1.5-1.)/(2.**(0.5)-1.)-1.)
+
+!     IF (knonv>0) THEN 
+!      DO ig=1,8 
+!        write(*,*)ig,'sisvat: Tsis ',TsisSV(ig,isnoSV(ig))
+!        write(*,*)'max-1            ',TsisSV(ig,isnoSV(ig)-1)
+!        write(*,*)'max-2            ',TsisSV(ig,isnoSV(ig)-2)
+!        write(*,*)'0                ',TsisSV(ig,0)
+!!        write(*,*)min(max(isnoSV(ig),0),1),max(1-isnoSV(ig),0)
+!      ENDDO
+!     END IF
+
+      DO ig=1,knonv    
+        IF (isnoSV(ig).GT.0) THEN
+          IF (isnoSV(ig).GT.1) THEN
+           mug(ig)=1./(1.+dzsnSV(ig,isnoSV(ig)-1)/dzsnSV(ig,isnoSV(ig))) !mu
+          ELSE
+           mug(ig) = 1./(1.+dzsnSV(ig,isnoSV(ig)-1)/dz_dSV(0)) !mu
+          ENDIF
+        ELSE
+          mug(ig) = lambSV
+        ENDIF
+
+        IF (mug(ig)  .LE. 0.05) THEN
+         write(*,*)'Attention mu low', mug(ig)
+        ENDIF
+        IF (mug(ig)  .GE. 0.98) THEN
+         write(*,*)'Attention mu high', mug(ig)
+        ENDIF
+
+        Tsrf(ig)=(1.5*TsisSV(ig,isnoSV(ig))-0.5*TsisSV(ig,isnoSV(ig)-1))&
+     &           *min(max(isnoSV(ig),0),1)+                             &
+     &           ((mug(ig)+1)*TsisSV(ig,0)-mug(ig)*TsisSV(ig,-1))       &
+     &           *max(1-isnoSV(ig),0)  
+      ENDDO
+
+  
+
+C! Surface temperature
+      DO ig=1,knonv
+      TsisSV(ig,isnoSV(ig))=(mug(ig)*C_coef(ig,isnoSV(ig))+Tsf_SV(ig))/ &
+     &        (mug(ig)*(1.-D_coef(ig,isnoSV(ig)))+1.)
+      ENDDO
+  
+C! Other temperatures
+      DO ig=1,knonv
+        DO jk=isnoSV(ig),-nsol+1,-1
+          TsisSV(ig,jk-1)=C_coef(ig,jk)+D_coef(ig,jk)                   &
+     &          *TsisSV(ig,jk)
+        ENDDO
+      ENDDO
+C      write(*,*)ig,'Tsis',TsisSV(ig,0)
+
+C      IF (indice == is_sic) THEN
+C        DO ig = 1,knonv
+C          TsisSV(ig,-nsol) = RTT - 1.8
+C        END DO
+C      ENDIF
+
+CC      !hj new 11 03 2010
+        DO ig=1,knonv                                                          
+          isl         = isnoSV(ig)                                             
+C          dIRsdT(ig) = Eso_sv(ig)* SteBo   * 4.                        & ! - d(IR)/d(T)   
+C     &                             * Tsf_SV(ig)                         & !T TsisSV(ig,isl)           !                
+C     &                             * Tsf_SV(ig)                         & !TsisSV(ig,isl)           !                
+C     &                             * Tsf_SV(ig) !TsisSV(ig,isl)           !                
+C          IRs__D(ig) = dIRsdT(ig)* Tsf_SV(ig) * 0.75 !TsisSV(ig,isl) * 0.75    !: 
+          dIRsdT(ig) = Eso_sv(ig)* StefBo   * 4.                        & ! - d(IR)/d(T)   
+     &                             * TsisSV(ig,isl)                     & !
+     &                             * TsisSV(ig,isl)                     & !
+     &                             * TsisSV(ig,isl)                     & !
+          IRs__D(ig) = dIRsdT(ig)* TsisSV(ig,isl) * 0.75                  !: 
+         END DO
+       !hj
+C!-----------------------------------------------------------------------
+C! 3)
+C! Calculate the Cgrd and Dgrd coefficient corresponding to actual soil 
+C! temperature
+C!-----------------------------------------------------------------------
+      DO ig=1,knonv
+        z1s = zdz2(ig,-nsol)+dz1_SV(ig,-nsol+1)
+        C_coef(ig,-nsol+1) = zdz2(ig,-nsol)*TsisSV(ig,-nsol)/z1s
+        D_coef(ig,-nsol+1) = dz1_SV(ig,-nsol+1)/z1s
+      ENDDO
+
+      DO ig=1,knonv  
+        DO jk=-nsol+1,isnoSV(ig)-1,1
+          z1s = 1./(zdz2(ig,jk)+dz1_SV(ig,jk+1)+dz1_SV(ig,jk)           &
+     &          *(1.-D_coef(ig,jk)))
+          C_coef(ig,jk+1) = (TsisSV(ig,jk)*zdz2(ig,jk)+                 &
+     &          dz1_SV(ig,jk)*C_coef(ig,jk)) * z1s
+          D_coef(ig,jk+1) = dz1_SV(ig,jk+1)*z1s
+        ENDDO
+      ENDDO
+
+C!-----------------------------------------------------------------------
+C! 4)
+C! Computation of the surface diffusive flux from ground and
+C! calorific capacity of the ground
+C!-----------------------------------------------------------------------
+      DO ig=1,knonv
+C! (pfluxgrd)
+        pfluxgrd(ig) = ztherm_i(ig)*dz1_SV(ig,isnoSV(ig))*              &
+     &      (C_coef(ig,isnoSV(ig))+(D_coef(ig,isnoSV(ig))-1.)           &
+     &      *TsisSV(ig,isnoSV(ig)))
+C! (pcapcal)
+        pcapcal(ig)  = ztherm_i(ig)*                                    &
+     &      (dz2_SV(ig,isnoSV(ig))+dt__SV*(1.-D_coef(ig,isnoSV(ig)))    &
+     &      *dz1_SV(ig,isnoSV(ig)))
+        z1s = mug(ig)*(1.-D_coef(ig,isnoSV(ig)))+1.
+        pcapcal(ig)  = pcapcal(ig)/z1s
+        pfluxgrd(ig) = ( pfluxgrd(ig)                                   &
+     &       + pcapcal(ig) * (TsisSV(ig,isnoSV(ig)) * z1s               &
+     &       - mug(ig)* C_coef(ig,isnoSV(ig))                           &
+     &       - Tsf_SV(ig))       /dt__SV )
+      ENDDO
+        
+      
+      cal(1:knonv) = RCPD / pcapcal(1:knonv)
+      rsolSV(1:knonv)  = rsolSV(1:knonv) + pfluxgrd(1:knonv)
+C!=======================================================================
+C! II. Second part: corresponds to calcul_fluxs_mod.F90 in LMDZ
+C!=======================================================================
+
+      Evp_sv = 0.
+c #NC HSsoKL=0.
+c #NC HLsoKL=0.
+      dSdTSV = 0.
+      dLdTSV = 0.
+	
+      beta(:) = 1.0
+      dif_grnd(:) = 0.0
+
+C! zx_qs = qsat en kg/kg
+C!**********************************************************************x***************
+
+      DO ig = 1,knonv
+        IF (ps__SV(ig).LT.1.) THEN
+!          write(*,*)'ig',ig,'ps',ps__SV(ig)
+          ps__SV(ig)=max(ps__SV(ig),1.e-8)
+        ENDIF
+        IF (p1l_SV(ig).LT.1.) THEN
+!          write(*,*)'ig',ig,'p1l',p1l_SV(ig)
+          p1l_SV(ig)=max(p1l_SV(ig),1.e-8)
+        ENDIF
+        IF (TaT_SV(ig).LT.180.) THEN
+!          write(*,*)'ig',ig,'TaT',TaT_SV(ig)
+          TaT_SV(ig)=max(TaT_SV(ig),180.)
+        ENDIF
+        IF (QaT_SV(ig).LT.1.e-8) THEN
+!          write(*,*)'ig',ig,'QaT',QaT_SV(ig)
+          QaT_SV(ig)=max(QaT_SV(ig),1.e-8)
+        ENDIF
+        IF (Tsf_SV(ig).LT.100.) THEN
+!          write(*,*)'ig',ig,'Tsf',Tsf_SV(ig)
+          Tsf_SV(ig)=max(Tsf_SV(ig),180.)
+        ENDIF
+        IF (Tsf_SV(ig).GT.500.) THEN
+!          write(*,*)'ig',ig,'Tsf',Tsf_SV(ig)
+          Tsf_SV(ig)=min(Tsf_SV(ig),400.)
+        ENDIF
+!         IF (Tsrf(ig).LT.1.) THEN
+!!          write(*,*)'ig',ig,'Tsrf',Tsrf(ig)  
+!           Tsrf(ig)=max(Tsrf(ig),TaT_SV(ig)-20.)
+!         ENDIF
+         IF (cdH_SV(ig).LT.1.e-10) THEN
+!           IF (ig.le.3)   write(*,*)'ig',ig,'cdH',cdH_SV(ig)
+           cdH_SV(ig)=.5
+         ENDIF
+      ENDDO  
+
+
+      DO ig = 1,knonv
+        zx_pkh(ig) = 1. ! (ps__SV(ig)/ps__SV(ig))**RKAPPA
+        IF (thermcep) THEN
+          zdelta=MAX(0.,SIGN(1.,rtt-Tsf_SV(ig)))
+          zcvm5 = R5LES*LhvH2O*(1.-zdelta) + R5IES*LhsH2O*zdelta
+          zcvm5 = zcvm5 / RCPD / (1.0+RVTMP2*QaT_SV(ig))
+          zx_qs= r2es * FOEEW(Tsf_SV(ig),zdelta)/ps__SV(ig)
+          zx_qs=MIN(0.5,zx_qs)
+          !write(*,*)'zcor',retv*zx_qs
+          zcor=1./(1.-retv*zx_qs)
+          zx_qs=zx_qs*zcor
+          zx_dq_s_dh = FOEDE(Tsf_SV(ig),zdelta,zcvm5,zx_qs,zcor)        &
+     &          /LhvH2O / zx_pkh(ig)
+        ELSE
+          IF (Tsf_SV(ig).LT.t_coup) THEN
+             zx_qs = qsats(Tsf_SV(ig)) / ps__SV(ig)
+             zx_dq_s_dh = dqsats(Tsf_SV(ig),zx_qs)/LhvH2O               &
+     &             / zx_pkh(ig)
+          ELSE
+             zx_qs = qsatl(Tsf_SV(ig)) / ps__SV(ig)
+             zx_dq_s_dh = dqsatl(Tsf_SV(ig),zx_qs)/LhvH2O               &
+     &             / zx_pkh(ig)
+          ENDIF
+        ENDIF
+        zx_dq_s_dt(ig) = RCPD * zx_pkh(ig) * zx_dq_s_dh
+        zx_qsat(ig) = zx_qs
+C        zx_coef(ig) = cdH_SV(ig) *                                     &
+C     &       (1.0+SQRT(u1lay(ig)**2+v1lay(ig)**2)) *                   &
+C     &       p1l_SV(ig)/(RD*t1lay(ig))
+        zx_coef(ig) = cdH_SV(ig) *                                      &
+     &       (1.0+VV__SV(ig)) *                                         &
+     &       p1l_SV(ig)/(RD*TaT_SV(ig))
+       
+      ENDDO
+
+
+C! === Calcul de la temperature de surface ===
+C! zx_sl = chaleur latente d'evaporation ou de sublimation
+C!****************************************************************************************
+
+      DO ig = 1,knonv
+        zx_sl(ig) = LhvH2O
+        IF (Tsf_SV(ig) .LT. RTT) zx_sl(ig) = LhsH2O
+        zx_k1(ig) = zx_coef(ig)
+      ENDDO
+    
+
+      DO ig = 1,knonv
+C! Q
+        zx_oq(ig) = 1. - (beta(ig) * zx_k1(ig) * BcoQSV(ig) * dt__SV)
+        zx_mq(ig) = beta(ig) * zx_k1(ig) *                              &
+     &       (AcoQSV(ig) - zx_qsat(ig) +                                &
+     &       zx_dq_s_dt(ig) * Tsf_SV(ig))                               &
+     &       / zx_oq(ig)
+        zx_nq(ig) = beta(ig) * zx_k1(ig) * (-1. * zx_dq_s_dt(ig))       &
+     &       / zx_oq(ig)
+       
+C! H
+        zx_oh(ig) = 1. - (zx_k1(ig) * BcoHSV(ig) * dt__SV)
+        zx_mh(ig) = zx_k1(ig) * AcoHSV(ig) / zx_oh(ig)
+        zx_nh(ig) = - (zx_k1(ig) * RCPD * zx_pkh(ig))/ zx_oh(ig)
+     
+C! surface temperature
+        TsfnSV(ig) = (Tsf_SV(ig) + cal(ig)/RCPD * zx_pkh(ig) * dt__SV * &
+     &       (rsolSV(ig) + zx_mh(ig) + zx_sl(ig) * zx_mq(ig))           & 
+     &       + dif_grnd(ig) * t_grnd * dt__SV)/                         &
+     &       ( 1. - dt__SV * cal(ig)/(RCPD * zx_pkh(ig)) *              &
+     &       (zx_nh(ig) + zx_sl(ig) * zx_nq(ig))                        &  
+     &       + dt__SV * dif_grnd(ig))
+
+!hj rajoute 22 11 2010 tuning...
+        TsfnSV(ig) = min(RTT+0.02,TsfnSV(ig))
+       
+        d_ts(ig) = TsfnSV(ig) - Tsf_SV(ig)
+
+
+C!== flux_q est le flux de vapeur d'eau: kg/(m**2 s)  positive vers bas
+C!== flux_t est le flux de cpt (energie sensible): j/(m**2 s)
+        Evp_sv(ig) = - zx_mq(ig) - zx_nq(ig) * TsfnSV(ig) 
+        HLs_sv(ig) = - Evp_sv(ig) * zx_sl(ig)
+        HSs_sv(ig) = zx_mh(ig) + zx_nh(ig) * TsfnSV(ig)
+       
+C! Derives des flux dF/dTs (W m-2 K-1):
+        dSdTSV(ig) = zx_nh(ig)
+        dLdTSV(ig) = zx_sl(ig) * zx_nq(ig)
+
+
+!hj  new 11 03 2010                                      
+        isl         = isnoSV(ig)
+!        TsisSV(ig,isl) = TsfnSV(ig)                                         
+        IRs_SV(ig) = IRs__D(ig)                                         &!     
+     &                - dIRsdT(ig) * TsfnSV(ig) !TsisSV(ig,isl)?      !  
+
+! hj
+c #NC   SOsoKL(ig) = sol_SV(ig) * SoSosv(ig)              ! Absorbed Sol.    
+c #NC   IRsoKL(ig) =               IRs_SV(ig)                           & !Up Surf. IR
+c #NC&        +     tau_sv(ig)      *IRd_SV(ig)*Eso_sv(ig)              & !Down Atm IR
+c #NC&        -(1.0-tau_sv(ig)) *0.5*IRv_sv(ig)            ! Down Veg IR  
+c #NC   HLsoKL(ig) = HLs_sv(ig) 
+c #NC   HSsoKL(ig) = HSs_sv(ig) 
+c #NC   HLs_KL(ig) = Evp_sv(ig)
+
+C! Nouvelle valeure de l'humidite au dessus du sol
+        qsat_new=zx_qsat(ig) + zx_dq_s_dt(ig) * d_ts(ig)
+        q1_new = AcoQSV(ig) - BcoQSV(ig)* Evp_sv(ig)*dt__SV
+        QaT_SV(ig)=q1_new*(1.-beta(ig)) + beta(ig)*qsat_new 
+
+      ENDDO
+
+      end ! subroutine SISVAT_TS2  
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_tso.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_tso.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_tso.F	(revision 3792)
@@ -0,0 +1,618 @@
+ 
+ 
+ 
+ 
+      subroutine SISVAT_TSo
+! #e1.                     (ETSo_0,ETSo_1,ETSo_d)
+ 
+C +------------------------------------------------------------------------+
+C | MAR          SISVAT_TSo                                06-10-2020  MAR |
+C |   SubRoutine SISVAT_TSo computes the Soil/Snow Energy Balance          |
+C +------------------------------------------------------------------------+
+C |                                                                        |
+C |   PARAMETERS:  knonv: Total Number of columns =                        |
+C |   ^^^^^^^^^^        = Total Number of continental     grid boxes       |
+C |                     X       Number of Mosaic Cell per grid box         |
+C |                                                                        |
+C |   INPUT:   isotSV   = 0,...,11:   Soil       Type                      |
+C |   ^^^^^               0:          Water, Solid or Liquid               |
+C |            isnoSV   = total Nb of Ice/Snow Layers                      |
+C |            dQa_SV   = Limitation of  Water Vapor  Turbulent Flux       |
+C |                                                                        |
+C |   INPUT:   sol_SV   : Downward Solar Radiation                  [W/m2] |
+C |   ^^^^^    IRd_SV   : Surface Downward  Longwave   Radiation    [W/m2] |
+C |            za__SV   : SBL Top    Height                            [m] |
+C |            VV__SV   : SBL Top    Wind Speed                      [m/s] |
+C |            TaT_SV   : SBL Top    Temperature                       [K] |
+C |            rhT_SV   : SBL Top    Air  Density                  [kg/m3] |
+C |            QaT_SV   : SBL Top    Specific  Humidity            [kg/kg] |
+C |            LSdzsv   : Vertical   Discretization Factor             [-] |
+C |                     =    1. Soil                                       |
+C |                     = 1000. Ocean                                      |
+C |            dzsnSV   : Snow Layer Thickness                         [m] |
+C |            ro__SV   : Snow/Soil  Volumic Mass                  [kg/m3] |
+C |            eta_SV   : Soil Water Content                       [m3/m3] |
+C |            dt__SV   : Time Step                                    [s] |
+C |                                                                        |
+C |            SoSosv   : Absorbed Solar Radiation by Surfac.(Normaliz)[-] |
+C |            Eso_sv   : Soil+Snow       Emissivity                   [-] |
+C |            rah_sv   : Aerodynamic Resistance for Heat            [s/m] |
+C |            Lx_H2O   : Latent Heat of Vaporization/Sublimation   [J/kg] |
+C |            sEX_sv   : Verticaly Integrated Extinction Coefficient  [-] |
+C |                                                                        |
+C |   INPUT /  TsisSV   : Soil/Ice Temperatures (layers -nsol,-nsol+1,..,0)|
+C |   OUTPUT:           & Snow     Temperatures (layers  1,2,...,nsno) [K] |
+C |   ^^^^^^                                                               |
+C |                                                                        |
+C |   OUTPUT:  IRs_SV   : Soil      IR Radiation                    [W/m2] |
+C |   ^^^^^^   HSs_sv   : Sensible  Heat Flux                       [W/m2] |
+C |            HLs_sv   : Latent    Heat Flux                       [W/m2] |
+C |            ETSo_0   : Snow/Soil Energy Power, before Forcing    [W/m2] |
+C |            ETSo_1   : Snow/Soil Energy Power, after  Forcing    [W/m2] |
+C |            ETSo_d   : Snow/Soil Energy Power         Forcing    [W/m2] |
+C |                                                                        |
+C |   Internal Variables:                                                  |
+C |   ^^^^^^^^^^^^^^^^^^                                                   |
+C |                                                                        |
+C |   METHOD: NO   Skin Surface Temperature                                |
+C |   ^^^^^^  Semi-Implicit Crank Nicholson Scheme                         |
+C |                                                                        |
+C | # OPTIONS: #E0: Energy Budget Verification                             |
+C | # ^^^^^^^  #kd: KDsvat Option:NO Flux  Limitor     on HL               |
+C | #          #KD: KDsvat Option:Explicit Formulation of HL               |
+C | #          #NC: OUTPUT for Stand Alone NetCDF File                     |
+C |                                                                        |
+C +------------------------------------------------------------------------+
+ 
+ 
+ 
+ 
+C +--Global Variables
+C +  ================
+ 
+      use VARphy
+      use VAR_SV
+      use VARdSV
+      use VARxSV
+      use VARySV
+      use VARtSV
+      use VAR0SV
+      
+
+      IMPLICIT NONE
+
+ 
+C +--OUTPUT
+C +  ------
+ 
+! #e1 real      ETSo_0(knonv)                 ! Soil/Snow Power, before Forcing
+! #e1 real      ETSo_1(knonv)                 ! Soil/Snow Power, after  Forcing
+! #e1 real      ETSo_d(knonv)                 ! Soil/Snow Power, Forcing
+ 
+ 
+C +--Internal Variables
+C +  ==================
+ 
+      integer   ikl   ,isl   ,jsl   ,ist      !
+      integer   ist__s,ist__w                 ! Soil/Water  Body Identifier
+      integer   islsgn                        ! Soil/Snow Surfac.Identifier
+      real      eps__3                        ! Arbitrary    Low Number
+      real      etaMid,psiMid                 ! Layer Interface's Humidity
+      real      mu_eta                        !     Soil thermal Conductivity
+      real      mu_exp                        ! arg Soil thermal Conductivity
+      real      mu_min                        ! Min Soil thermal Conductivity
+      real      mu_max                        ! Max Soil thermal Conductivity
+      real      mu_sno(knonv),mu_aux          !     Snow thermal Conductivity
+      real      mu__dz(knonv,-nsol:nsno+1)    ! mu_(eta,sno)   / dz
+      real      dtC_sv(knonv,-nsol:nsno)      ! dt      / C
+      real      IRs__D(knonv)                 ! UpwardIR Previous Iter.Contr.
+      real      dIRsdT(knonv)                 ! UpwardIR           T Derivat.
+      real      f_HSHL(knonv)                 ! Factor common to HS and HL
+      real      dRidTs(knonv)                 ! d(Rib)/d(Ts)
+      real      HS___D(knonv)                 ! Sensible Heat Flux Atm.Contr.
+      real      f___HL(knonv)                 !
+      real      HL___D(knonv)                 ! Latent   Heat Flux Atm.Contr.
+      REAL      TSurf0(knonv),dTSurf          ! Previous Surface Temperature
+      real      qsatsg(knonv) !,den_qs,arg_qs ! Soil   Saturat. Spec. Humidity
+      real      dqs_dT(knonv)                 ! d(qsatsg)/dTv
+      real      Psi(   knonv)                 ! 1st Soil Layer Water Potential
+      real      RHuSol(knonv)                 ! Soil Surface Relative Humidity
+      real      etaSol                        ! Soil Surface          Humidity
+      real      d__eta                        ! Soil Surface Humidity Increm.
+      real      Elem_A,Elem_C                 !   Diagonal Coefficients
+      real      Diag_A(knonv,-nsol:nsno)      ! A Diagonal
+      real      Diag_B(knonv,-nsol:nsno)      ! B Diagonal
+      real      Diag_C(knonv,-nsol:nsno)      ! C Diagonal
+      real      Term_D(knonv,-nsol:nsno)      !   Independant Term
+      real      Aux__P(knonv,-nsol:nsno)      ! P Auxiliary Variable
+      real      Aux__Q(knonv,-nsol:nsno)      ! Q Auxiliary Variable
+      real      Ts_Min,Ts_Max                 ! Temperature Limits
+! #e1 real      Exist0                        ! Existing Layer Switch
+      real      psat_wat, psat_ice, sp        ! computation of qsat
+
+      integer   nt_srf,it_srf,itEuBk          ! HL: Surface Scheme
+      parameter(nt_srf=10)                    !
+      real      agpsrf,xgpsrf,dt_srf,dt_ver   !
+      real      etaBAK(knonv)                 !
+      real      etaNEW(knonv)                 !
+      real      etEuBk(knonv)                 !
+      real      fac_dt(knonv),faceta(knonv)   !
+      real      PsiArg(knonv),SHuSol(knonv)   !
+ 
+
+ 
+C +--Internal DATA
+C +  =============
+ 
+      data      eps__3 /   1.e-3   /          ! Arbitrary    Low Number
+      data      mu_exp /  -0.4343  /          ! Soil Thermal Conductivity
+      data      mu_min /   0.172   /          ! Min Soil Thermal Conductivity
+      data      mu_max /   2.000   /          ! Max Soil Thermal Conductivity
+      data      Ts_Min / 175.      /          ! Temperature            Minimum
+      data      Ts_Max / 300.      /          ! Temperature Acceptable Maximum
+C +                                           ! including   Snow Melt  Energy
+ 
+ 
+
+C +--Heat Conduction Coefficient (zero in the Layers over the highest one)
+C +  ===========================
+C +                             ---------------- isl    eta_SV, rho C (isl)
+C +
+C +--Soil                       ++++++++++++++++        etaMid,    mu (isl)
+C +  ----
+C +                             ---------------- isl-1  eta_SV, rho C (isl-1)
+           isl=-nsol
+        DO ikl=1,knonv
+
+          mu__dz(ikl,isl) = 0.
+ 
+          dtC_sv(ikl,isl) = dtz_SV2(isl)  * dt__SV        ! dt / (dz X rho C)
+     .                   /((rocsSV(isotSV(ikl))           ! [s / (m.J/m3/K)]
+     .                     +rcwdSV*eta_SV(ikl,isl))       !
+     .                     *LSdzsv(ikl)            )      !
+        END DO
+      DO   isl=-nsol+1,0
+        DO ikl=1,knonv
+          ist    =      isotSV(ikl)                       ! Soil Type
+          ist__s =  min(ist, 1)                           ! 1 => Soil
+          ist__w =  1 - ist__s                            ! 1 => Water Body
+ 
+          etaMid = 0.5*(dz_dSV(isl-1)*eta_SV(ikl,isl-1)   ! eta at layers
+     .                 +dz_dSV(isl)  *eta_SV(ikl,isl)  )  !     interface
+     .                 /dzmiSV(isl)                       ! LSdzsv implicit !
+          etaMid =  max(etaMid,epsi)
+          psiMid =      psidSV(ist)
+     .                *(etadSV(ist)/etaMid)**bCHdSV(ist)
+          mu_eta =      3.82      *(psiMid)**mu_exp       ! Soil Thermal
+          mu_eta =  min(max(mu_eta, mu_min), mu_max)      ! Conductivity
+C +                                                       ! DR97 eq.3.31
+          mu_eta =  ist__s *mu_eta +ist__w * vK_dSV       ! Water Bodies
+C +                                                       ! Correction
+          mu__dz(ikl,isl) = mu_eta/(dzmiSV(isl)           !
+     .                             *LSdzsv(ikl))          !
+ 
+          dtC_sv(ikl,isl) = dtz_SV2(isl)* dt__SV          ! dt / (dz X rho C)
+     .                   /((rocsSV(isotSV(ikl))           !
+     .                     +rcwdSV*eta_SV(ikl,isl))       !
+     .                     *LSdzsv(ikl)            )      !
+        END DO
+      END DO
+ 
+ 
+C +--Soil/Snow Interface
+C +  -------------------
+ 
+C +--Soil Contribution
+C +  ^^^^^^^^^^^^^^^^^
+           isl=1
+        DO ikl=1,knonv
+          ist    =      isotSV(ikl)                       ! Soil Type
+          ist__s =  min(ist, 1)                           ! 1 => Soil
+          ist__w =  1 - ist__s                            ! 1 => Water Body
+          psiMid =      psidSV(ist)                       ! Snow => Saturation
+          mu_eta =      3.82      *(psiMid)**mu_exp       ! Soil Thermal
+          mu_eta =  min(max(mu_eta, mu_min), mu_max)      ! Conductivity
+C +                                                       ! DR97 eq.3.31
+          mu_eta =  ist__s *mu_eta +ist__w * vK_dSV       ! Water Bodies
+ 
+C +--Snow Contribution
+C +  ^^^^^^^^^^^^^^^^^
+          mu_sno(ikl) =  CdidSV                           !
+     .                 *(ro__SV(ikl,isl) /ro_Wat) ** 1.88 !
+          mu_sno(ikl) =          max(epsi,mu_sno(ikl))    !
+C +...    mu_sno :  Snow Heat Conductivity Coefficient [Wm/K]
+C +                 (Yen 1981, CRREL Rep., 81-10)
+ 
+C +--Combined Heat Conductivity
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+          mu__dz(ikl,isl) = 2./(dzsnSV(ikl,isl  )         ! Combined Heat
+     .                         /mu_sno(ikl)               ! Conductivity
+     .                         +LSdzsv(ikl)               !
+     .                         *dz_dSV(    isl-1)/mu_eta) ! Coefficient
+ 
+C +--Inverted Heat Capacity
+C +  ^^^^^^^^^^^^^^^^^^^^^^
+          dtC_sv(ikl,isl) = dt__SV/max(epsi,              ! dt / (dz X rho C)
+     .    dzsnSV(ikl,isl) * ro__SV(ikl,isl) *Cn_dSV)      !
+        END DO
+ 
+ 
+C +--Snow
+C +  ----
+ 
+      DO ikl=1,knonv
+      DO   isl=1,min(nsno,isnoSV(ikl)+1)
+          ro__SV(ikl,isl) =                               !
+     .                   ro__SV(ikl ,isl)                 !
+     .       * max(0,min(isnoSV(ikl)-isl+1,1))            !
+
+        END DO
+      END DO
+ 
+      DO ikl=1,knonv
+      DO   isl=1,min(nsno,isnoSV(ikl)+1)
+ 
+C +--Combined Heat Conductivity
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+          mu_aux      =  CdidSV                           !
+     .                 *(ro__SV(ikl,isl) /ro_Wat) ** 1.88 !
+          mu__dz(ikl,isl) =                               !
+     .      2.                        *mu_aux*mu_sno(ikl) ! Combined Heat
+     .     /max(epsi,dzsnSV(ikl,isl  )*mu_sno(ikl)        ! Conductivity
+     .              +dzsnSV(ikl,isl-1)*mu_aux     )       ! For upper Layer
+          mu_sno(ikl)     =            mu_aux             !
+ 
+C +--Inverted Heat Capacity
+C +  ^^^^^^^^^^^^^^^^^^^^^^
+          dtC_sv(ikl,isl) = dt__SV/max(eps__3,            ! dt / (dz X rho C)
+     .    dzsnSV(ikl,isl) * ro__SV(ikl,isl) *Cn_dSV)      !
+        END DO
+      END DO
+ 
+ 
+C +--Uppermost Effective Layer: NO conduction
+C +  ----------------------------------------
+ 
+        DO ikl=1,knonv
+          mu__dz(ikl,isnoSV(ikl)+1) = 0.0
+        END DO
+ 
+ 
+C +--Energy Budget (IN)
+C +  ==================
+ 
+! #e1   DO ikl=1,knonv
+! #e1     ETSo_0(ikl) = 0.
+! #e1   END DO
+! #e1 DO   isl= -nsol,nsno
+! #e1   DO ikl=1,knonv
+! #e1     Exist0      = isl -           isnoSV(ikl)
+! #e1     Exist0      = 1.  - max(zero,min(unun,Exist0))
+! #e1     ETSo_0(ikl) = ETSo_0(ikl)
+! #e1.                +(TsisSV(ikl,isl)-TfSnow)*Exist0
+! #e1.                                 /dtC_sv(ikl,isl)
+! #e1   END DO
+! #e1 END DO
+ 
+ 
+C +--Tridiagonal Elimination: Set Up
+C +  ===============================
+ 
+C +--Soil/Snow Interior
+C +  ^^^^^^^^^^^^^^^^^^
+      DO ikl=1,knonv
+      DO   isl=-nsol+1,min(nsno-1,isnoSV(ikl)+1)
+
+          Elem_A          =  dtC_sv(ikl,isl)         *mu__dz(ikl,isl)
+          Elem_C          =  dtC_sv(ikl,isl)         *mu__dz(ikl,isl+1)
+          Diag_A(ikl,isl) = -Elem_A  *Implic
+          Diag_C(ikl,isl) = -Elem_C  *Implic
+          Diag_B(ikl,isl) =  1.0d+0  -Diag_A(ikl,isl)-Diag_C(ikl,isl)
+          Term_D(ikl,isl) =  Explic *(Elem_A         *TsisSV(ikl,isl-1)
+     .                               +Elem_C         *TsisSV(ikl,isl+1))
+     .             +(1.0d+0 -Explic *(Elem_A+Elem_C))*TsisSV(ikl,isl)
+     .  + dtC_sv(ikl,isl)           * sol_SV(ikl)    *SoSosv(ikl)
+     .                                               *(sEX_sv(ikl,isl+1)
+     .                                               -sEX_sv(ikl,isl  ))
+        END DO
+      END DO
+ 
+C +--Soil  lowest Layer
+C +  ^^^^^^^^^^^^^^^^^^
+           isl= -nsol
+        DO ikl=1,knonv
+          Elem_A          =  0.
+          Elem_C          =  dtC_sv(ikl,isl)         *mu__dz(ikl,isl+1)
+          Diag_A(ikl,isl) =  0.
+          Diag_C(ikl,isl) = -Elem_C  *Implic
+          Diag_B(ikl,isl) =  1.0d+0  -Diag_A(ikl,isl)-Diag_C(ikl,isl)
+          Term_D(ikl,isl) =  Explic * Elem_C         *TsisSV(ikl,isl+1)
+     .             +(1.0d+0 -Explic * Elem_C)        *TsisSV(ikl,isl)
+     .  + dtC_sv(ikl,isl)           * sol_SV(ikl)    *SoSosv(ikl)
+     .                                              *(sEX_sv(ikl,isl+1)
+     .                                               -sEX_sv(ikl,isl  ))
+        END DO
+ 
+C +--Snow highest Layer (dummy!)
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+        isl=  min(isnoSV(1)+1,nsno)
+        DO ikl=1,knonv
+          Elem_A          =  dtC_sv(ikl,isl)  *mu__dz(ikl,isl)
+          Elem_C          =  0.
+          Diag_A(ikl,isl) = -Elem_A  *Implic
+          Diag_C(ikl,isl) =  0.
+          Diag_B(ikl,isl) =  1.0d+0  -Diag_A(ikl,isl)
+          Term_D(ikl,isl) =  Explic * Elem_A  *TsisSV(ikl,isl-1)
+     .             +(1.0d+0 -Explic * Elem_A) *TsisSV(ikl,isl)
+     .  + dtC_sv(ikl,isl) * (sol_SV(ikl)      *SoSosv(ikl)
+     .                                       *(sEX_sv(ikl,isl+1)
+     .                                        -sEX_sv(ikl,isl  )))
+        END DO
+ 
+C +--Surface: UPwardIR Heat Flux
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+        DO ikl=1,knonv
+          isl         = isnoSV(ikl)
+          dIRsdT(ikl) = Eso_sv(ikl)* StefBo          * 4.      ! - d(IR)/d(T)
+     .                             * TsisSV(ikl,isl)           !
+     .                             * TsisSV(ikl,isl)           !
+     .                             * TsisSV(ikl,isl)           !
+          IRs__D(ikl) = dIRsdT(ikl)* TsisSV(ikl,isl) * 0.75    !
+ 
+C +--Surface: Richardson Number:   T Derivative
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+c #RC     dRidTs(ikl) =-gravit      *    za__SV(ikl)
+c #RC.                /(TaT_SV(ikl) *    VV__SV(ikl)
+c #RC.                              *    VV__SV(ikl))
+ 
+C +--Surface: Turbulent Heat Flux: Factors
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+          f_HSHL(ikl) = rhT_SV(ikl)  /    rah_sv(ikl)           ! to  HS, HL
+          f___HL(ikl) = f_HSHL(ikl) *    Lx_H2O(ikl)
+ 
+C +--Surface: Sensible  Heat Flux: T Derivative
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+          dSdTSV(ikl) = f_HSHL(ikl) *    Cp                    !#- d(HS)/d(T)
+c #RC.         *(1.0  -(TsisSV(ikl,isl) -TaT_SV(ikl))          !#Richardson
+c #RC.         * dRidTs(ikl)*dFh_sv(ikl)/rah_sv(ikl))          ! Nb. Correct.
+          HS___D(ikl) = dSdTSV(ikl) *    TaT_SV(ikl)           !
+ 
+C +--Surface: Latent    Heat Flux: Saturation Specific Humidity
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+c         den_qs      =         TsisSV(ikl,isl)- 35.8          !
+c         arg_qs      = 17.27 *(TsisSV(ikl,isl)-273.16)        !
+c    .                                   / den_qs              !
+c         qsatsg(ikl) = .0038 *        exp(arg_qs)             !
+
+!          sp = (pst_SV(ikl) + ptopSV) * 10.
+
+          sp=ps__SV(ikl)
+          psat_ice = 6.1070 * exp(6150. *(1./273.16 -
+     .                                              1./TsisSV(ikl,isl)))
+
+          psat_wat = 6.1078 * exp (5.138*log(273.16   /TsisSV(ikl,isl)))
+     .             * exp (6827.*(1.         /273.16-1./TsisSV(ikl,isl)))
+
+          if(TsisSV(ikl,isl)<=273.16) then
+            qsatsg(ikl) = 0.622 * psat_ice / (sp - 0.378 * psat_ice)
+          else
+            qsatsg(ikl) = 0.622 * psat_wat / (sp - 0.378 * psat_wat)
+          endif
+
+c         dqs_dT(ikl) = qsatsg(ikl)* 4099.2   /(den_qs *den_qs)!
+          fac_dt(ikl) = f_HSHL(ikl)/(ro_Wat   * dz_dSV(0))     !
+        END DO
+ 
+C +--Surface: Latent    Heat Flux: Surface    Relative Humidity
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+              xgpsrf       =   1.05                            !
+              agpsrf       = dt__SV*(   1.0-xgpsrf        )    !
+     .                             /(   1.0-xgpsrf**nt_srf)    !
+              dt_srf       = agpsrf                            !
+              dt_ver       = 0.                                !
+            DO ikl=1,knonv
+              isl          =          isnoSV(ikl)              !
+              etaBAK(ikl)  = max(epsi,eta_SV(ikl ,isl))        !
+              etaNEW(ikl)  =          etaBAK(ikl)              !
+              etEuBk(ikl)  =          etaNEW(ikl)              !
+            END DO                                             !
+        DO it_srf=1,nt_srf                                     !
+              dt_ver       = dt_ver     +dt_srf                !
+            DO ikl=1,knonv                                     !
+              faceta(ikl)  = fac_dt(ikl)*dt_srf                !
+c #VX         faceta(ikl)  = faceta(ikl)                       !
+c #VX.                  /(1.+faceta(ikl)*dQa_SV(ikl))          !    Limitation
+                                                               ! by Atm.Conten
+c #??.        *max(0,sign(1.,qsatsg(ikl)-QaT_SV(ikl))))        ! NO Limitation
+                                                               ! of Downw.Flux
+            END DO                                             !
+          DO itEuBk=1,2                                        !
+            DO ikl=1,knonv
+              ist    = max(0,isotSV(ikl)-100*isnoSV(ikl))      ! 0 if    H2O
+                                                               !
+              Psi(ikl) =                                       !
+     .                psidSV(ist)                              ! DR97, Eqn 3.34
+     .              *(etadSV(ist)                              !
+     .           /max(etEuBk(ikl),epsi))                       !
+     .              **bCHdSV(ist)                              !
+              PsiArg(ikl) = 7.2E-5*Psi(ikl)                    !
+              RHuSol(ikl) =   exp(-min(0.,PsiArg(ikl)))    !
+              SHuSol(ikl) =     qsatsg(ikl)  *RHuSol(ikl)      ! DR97, Eqn 3.15
+              etEuBk(ikl) =                                    !
+     .       (etaNEW(ikl) + faceta(ikl)*(QaT_SV(ikl)           !
+     .                                  -SHuSol(ikl)           !
+     .                    *(1.          -bCHdSV(ist)           !
+     .                                  *PsiArg(ikl))       )) !
+     .      /(1.          + faceta(ikl)* SHuSol(ikl)           !
+     .                                  *bCHdSV(ist)           !
+     .                                  *PsiArg(ikl)           !
+     .                                  /etaNEW(ikl))          !
+              etEuBk(ikl) = etEuBk(ikl)          !
+c    .                                 /(Ro_Wat*dz_dSV(0))     !
+     .                    * dt_srf     /(Ro_Wat*dz_dSV(0))     !
+cXF 15/05/2017 BUG
+            END DO                                             !
+          END DO                                               !
+            DO ikl=1,knonv                                     !
+              etaNEW(ikl) =  max(etEuBk(ikl),epsi)             !
+            END DO                                             !
+              dt_srf      =      dt_srf         * xgpsrf       !
+        END DO                                                 !
+ 
+C +--Surface: Latent    Heat Flux: Soil/Water Surface Contributions
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+        DO ikl=1,knonv                                         !
+          isl        =  isnoSV(ikl)                            !
+          ist   = max(0,isotSV(ikl)-100*isnoSV(ikl))           ! 0 if    H2O
+          ist__s= min(1,ist)                                   ! 1 if no H2O
+          ist__w=     1-ist__s                                 ! 1 if    H2O
+          d__eta     =  eta_SV(ikl,isl)-etaNEW(ikl)            !
+          ! latent heat flux computation
+          HL___D(ikl)=( ist__s *ro_Wat *dz_dSV(0)              ! Soil Contrib.
+     .                *(etaNEW(ikl)    -etaBAK(ikl)) / dt__SV  !
+     .                 +ist__w         *f_HSHL(ikl)            ! H2O  Contrib.
+     .                *(QaT_SV(ikl)    - qsatsg(ikl))        ) !
+     .                * Lx_H2O(ikl)                            ! common factor
+ 
+c #DL     RHuSol(ikl) =(QaT_SV(ikl)                            !
+c #DL.                 -HL___D(ikl)    / f___HL(ikl))          !
+c #DL.                / qsatsg(ikl)                            !
+ 
+C +--Surface: Latent    Heat Flux: T Derivative
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+          dLdTSV(ikl) = 0.
+c #DL     dLdTSV(ikl) = f___HL(ikl) * RHuSol(ikl) *dqs_dT(ikl) ! - d(HL)/d(T)
+c #DL     HL___D(ikl) = HL___D(ikl)                            !
+c #DL.                 +dLdTSV(ikl) * TsisSV(ikl,isl)          !
+        END DO                                                 !
+ 
+C +--Surface: Tridiagonal Matrix Set Up
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+        DO ikl=1,knonv
+          isl             =  isnoSV(ikl)
+          TSurf0(ikl)     =  TsisSV(ikl,isl)
+
+          Elem_A          =  dtC_sv(ikl,isl)*mu__dz(ikl,isl)
+          Elem_C          =  0.
+          Diag_A(ikl,isl) = -Elem_A *Implic
+          Diag_C(ikl,isl) =  0.
+          Diag_B(ikl,isl) =  1.0d+0 -Diag_A(ikl,isl)
+          Diag_B(ikl,isl) =  Diag_B(ikl,isl)
+     .  + dtC_sv(ikl,isl) * (dIRsdT(ikl)                       ! Upw. Sol IR
+     .                      +dSdTSV(ikl)                       ! HS/Surf.Contr.
+     .                      +dLdTSV(ikl))                      ! HL/Surf.Contr.
+
+          Term_D(ikl,isl) =  Explic *Elem_A *TsisSV(ikl,isl-1)
+     .             +(1.0d+0 -Explic *Elem_A)*TsisSV(ikl,isl)
+
+
+
+          Term_D(ikl,isl) =  Term_D(ikl,isl)
+     .  + dtC_sv(ikl,isl) * (sol_SV(ikl)    *SoSosv(ikl)       ! Absorbed
+     .                                     *(sEX_sv(ikl,isl+1) ! Solar
+     .                                      -sEX_sv(ikl,isl  ))!
+     .                              +   IRd_SV(ikl)*Eso_sv(ikl) ! Down Atm IR
+     .                                +IRs__D(ikl)             ! Upw. Sol IR
+     .                                +HS___D(ikl)             ! HS/Atmo.Contr.
+     .                                +HL___D(ikl)            )! HL/Atmo.Contr.
+     
+        END DO
+ 
+ 
+C +--Tridiagonal Elimination
+C +  =======================
+ 
+C +--Forward  Sweep
+C +  ^^^^^^^^^^^^^^
+        DO ikl=  1,knonv
+          Aux__P(ikl,-nsol) = Diag_B(ikl,-nsol)
+          Aux__Q(ikl,-nsol) =-Diag_C(ikl,-nsol)/Aux__P(ikl,-nsol)
+        END DO
+ 
+        DO ikl=      1,knonv
+
+        DO   isl=-nsol+1,min(nsno,isnoSV(ikl)+1)
+          Aux__P(ikl,isl)   = Diag_A(ikl,isl)  *Aux__Q(ikl,isl-1)
+     .                       +Diag_B(ikl,isl)
+          Aux__Q(ikl,isl)   =-Diag_C(ikl,isl)  /Aux__P(ikl,isl)
+        END DO
+        END DO
+ 
+        DO ikl=      1,knonv
+          TsisSV(ikl,-nsol) = Term_D(ikl,-nsol)/Aux__P(ikl,-nsol)
+        END DO
+ 
+        DO ikl=      1,knonv
+        DO   isl=-nsol+1,min(nsno,isnoSV(ikl)+1)
+          TsisSV(ikl,isl)   =(Term_D(ikl,isl)
+     .                       -Diag_A(ikl,isl)  *TsisSV(ikl,isl-1))
+     .                                         /Aux__P(ikl,isl)
+
+  
+        END DO
+        END DO
+ 
+C +--Backward Sweep
+C +  ^^^^^^^^^^^^^^
+        DO ikl=     1,knonv
+        DO   isl=min(nsno-1,isnoSV(ikl)+1),-nsol,-1
+           
+
+          TsisSV(ikl,isl)   = Aux__Q(ikl,isl)  *TsisSV(ikl,isl+1)
+     .                                         +TsisSV(ikl,isl)
+          if(isl==0.and.isnoSV(ikl)==0) then
+ 
+           TsisSV(ikl,isl)  = min(TaT_SV(ikl)+30,TsisSV(ikl,isl))
+           TsisSV(ikl,isl)  = max(TaT_SV(ikl)-30,TsisSV(ikl,isl))
+
+
+c #EU      TsisSV(ikl,isl)  = max(TaT_SV(ikl)-15.,TsisSV(ikl,isl))
+
+          !XF 18/11/2018 to avoid ST reaching 70�C!!
+          !It is an error compensation but does not work over tundra
+ 
+          endif
+
+   
+
+        END DO
+       
+      END DO
+ 
+C +--Temperature Limits (avoids problems in case of no Snow Layers)
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+        DO ikl=     1,knonv
+           isl              = isnoSV(ikl)
+          dTSurf            = TsisSV(ikl,isl) -     TSurf0(ikl)
+          TsisSV(ikl,isl)   = TSurf0(ikl) + sign(1.,dTSurf) ! 180.0 dgC/hr
+     .              * min(abs(dTSurf),5.e-2*dt__SV)         ! =0.05 dgC/s
+
+
+
+        END DO
+
+        DO ikl=     1,knonv
+        DO   isl=min(nsno,isnoSV(ikl)+1),1      ,-1
+          TsisSV(ikl,isl)   = max(Ts_Min,       TsisSV(ikl,isl))
+          TsisSV(ikl,isl)   = min(Ts_Max,       TsisSV(ikl,isl))
+        END DO
+
+        END DO
+ 
+C +--Update Surface    Fluxes
+C +  ========================
+ 
+        DO ikl=      1,knonv
+          isl         = isnoSV(ikl)
+          IRs_SV(ikl) = IRs__D(ikl)                          !
+     .                - dIRsdT(ikl) * TsisSV(ikl,isl)        !
+          HSs_sv(ikl) = HS___D(ikl)                          ! Sensible Heat
+     .                - dSdTSV(ikl) * TsisSV(ikl,isl)        ! Downward > 0
+          HLs_sv(ikl) = HL___D(ikl)                          ! Latent   Heat
+     .                - dLdTSV(ikl) * TsisSV(ikl,isl)        ! Downward > 0
+        END DO
+
+ 
+ 
+      return
+      end
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_weq.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_weq.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_weq.F	(revision 3792)
@@ -0,0 +1,104 @@
+ 
+ 
+      subroutine SISVAT_wEq( labWEq ,istart)
+ 
+C +------------------------------------------------------------------------+
+C | MAR          SISVAT_wEq                                22-09-2001  MAR |
+C |   SubRoutine SISVAT_wEq computes the Snow/Ice  Water  Equivalent       |
+C |                                                                        |
+C |                                                                        |
+C |   Preprocessing  Option: SISVAT IO (not always a standard preprocess.) |
+C |   ^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^                                     |
+C |   FILE                 |      CONTENT                                  |
+C |   ~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+C | # SISVAT_wEq.ve        | #ve: OUTPUT/Verification: Snow/Ice Water Eqv. |
+C |                        |      unit 45, SubRoutine  SISVAT_wEq **ONLY** |
+C +------------------------------------------------------------------------+
+ 
+ 
+ 
+ 
+C +--Global Variables
+C +  ================
+
+      use VARphy
+      use VAR_SV
+      use VARxSV
+ 
+      IMPLICIT NONE
+
+ 
+ 
+      character*6         labWEq
+      integer             istart
+ 
+      logical             logWEq
+      common/SISVAT_wEq_L/logWEq
+ 
+ 
+C +--Local  Variables
+C +  ================
+ 
+      integer  ikl   ,isn
+      real     SnoWEQ,IceWEQ
+ 
+ 
+C +--Switch Initialization
+C +  =====================
+ 
+      IF (.NOT.logWEq)                                              THEN
+               logWEq = .true.
+               open(unit=45,status='unknown',file='SISVAT_wEq.ve')
+               rewind    45
+      END IF
+ 
+ 
+C +--Snow Water Equivalent
+C +  =====================
+ 
+           ikl   = 1
+      IF          (isnoSV(ikl).gt.iiceSV(ikl))                      THEN
+ 
+          SnoWEQ = 0.
+        DO isn   = iiceSV(ikl)+1 ,isnoSV(ikl)
+          SnoWEQ = SnoWEQ       + ro__SV(ikl,isn) * dzsnSV(ikl,isn)
+        END DO
+ 
+      END IF
+ 
+ 
+C +--Ice  Water Equivalent
+C +  =====================
+ 
+      IF        (iiceSV(1).gt.0)                                    THEN
+ 
+          IceWEQ = 0.
+        DO isn   =             1 ,iiceSV(ikl)
+          IceWEQ = IceWEQ       + ro__SV(ikl,isn) * dzsnSV(ikl,isn)
+        END DO
+ 
+      END IF
+ 
+ 
+C +--OUTPUT
+C +  ======
+ 
+ !      IF (istart.eq.1)                                              THEN
+ !        write(45,45)dahost,i___SV(lwriSV(1)),j___SV(lwriSV(1)),
+ !     .              n___SV(lwriSV(1))
+ ! 45     format(a18,10('-'),'Pt.',3i4,60('-'))
+ !      END IF
+ 
+ !      write(45,450) labWEq,IceWEQ,iiceSV(ikl),SnoWEQ
+ !     .                    ,IceWEQ+SnoWEQ,isnoSV(ikl)
+ !     .                                  ,drr_SV(ikl)*dt__SV
+ !     .                                  ,dsn_SV(ikl)*dt__SV
+ !     .                                  ,BufsSV(ikl)
+ ! 450  format(a6,3x,'  I+S =',f11.4,'(',i2,') +',f11.4,' =',
+ !     .                       f11.4,'(',i2,')',
+ !     .             '  drr =', f7.4,
+ !     .             '  dsn =', f7.4,
+ !     .             '  Buf =', f7.4)
+ 
+      return
+      end
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_zag.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_zag.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_zag.F	(revision 3792)
@@ -0,0 +1,238 @@
+ 
+ 
+      subroutine SISVAT_zAg
+     .                     (isagra,isagrb,WEagra
+     .                     ,dzagra,dzagrb,T_agra,T_agrb
+     .                     ,roagra,roagrb,etagra,etagrb
+     .                     ,G1agra,G1agrb,G2agra,G2agrb
+     .                     ,agagra,agagrb,Agreg1
+     .                     )
+ 
+C +------------------------------------------------------------------------+
+C | MAR SURFACE                                       Sat 30-Apr-2004  MAR |
+C |   SubRoutine SISVAT_zAg aggregates two contiguous snow layers          |
+C |                                                                        |
+C +------------------------------------------------------------------------+
+C |                                                                        |
+C |   PARAMETERS:  knonv: Total Number of columns =                        |
+C |   ^^^^^^^^^^        = Total Number of continental     grid boxes       |
+C |                     X       Number of Mosaic Cell per grid box         |
+C |                                                                        |
+C |   INPUT:   isagrb   : 2nd     Layer History                            |
+C |   ^^^^^                                                                |
+C |                                                                        |
+C |   INPUT:   dzagrb   : 2nd     Layer Thickness                          |
+C |   ^^^^^    T_agrb   : 2nd     Layer Temperature                        |
+C |            roagrb   : 2nd     Layer Density                            |
+C |            etagrb   : 2nd     Layer Water Content                      |
+C |            G1agrb   : 2nd     Layer Dendricity/Spher.                  |
+C |            G2agrb   : 2nd     Layer Sphericity/Size                    |
+C |            agagrb   : 2nd     Age                                      |
+C |            Agreg1   : 1. when Agregation constrained                   |
+C |                                                                        |
+C |   INPUT /  isagra   : 1st     Layer History                            |
+C |   OUTPUT:                                                              |
+C |   ^^^^^^                                                               |
+C |                                                                        |
+C |   INPUT /  dzagra   : 1st     Layer Thickness                          |
+C |   OUTPUT:  T_agra   : 1st     Layer Temperature                        |
+C |   ^^^^^^   roagra   : 1st     Layer Density                            |
+C |            etagra   : 1st     Layer Water Content                      |
+C |            G1agra   : 1st     Layer Dendricity/Spher.                  |
+C |            G2agra   : 1st     Layer Sphericity/Size                    |
+C |            agagra   : 1st     Age                                      |
+C |                                                                        |
+C +------------------------------------------------------------------------+
+ 
+ 
+ 
+ 
+C +--Global Variables
+C +  ================
+ 
+      use VARphy
+      use VAR_SV
+      use VARdSV
+      use VAR0SV
+      use VARxSV
+
+      IMPLICIT NONE
+
+ 
+C +--INPUT
+C +  -----
+ 
+      integer   isagrb(knonv)                 ! 2nd Layer History
+      real      dzagrb(knonv)                 ! 2nd Layer Thickness
+      real      T_agrb(knonv)                 ! 2nd Layer Temperature
+      real      roagrb(knonv)                 ! 2nd Layer Density
+      real      etagrb(knonv)                 ! 2nd Layer Water Content
+      real      G1agrb(knonv)                 ! 2nd Layer Dendricity/Spher.
+      real      G2agrb(knonv)                 ! 2nd Layer Sphericity/Size
+      real      agagrb(knonv)                 ! 2nd Layer Age
+ 
+ 
+C +--INPUT/OUTPUT
+C +  ------------
+ 
+      integer   isagra(knonv)                 ! 1st Layer History
+      real      WEagra(knonv)                 ! 1st Layer Height    [mm w.e.]
+      real      Agreg1(knonv)                 ! 1. ===>   Agregates
+      real      dzagra(knonv)                 ! 1st Layer Thickness
+      real      T_agra(knonv)                 ! 1st Layer Temperature
+      real      roagra(knonv)                 ! 1st Layer Density
+      real      etagra(knonv)                 ! 1st Layer Water Content
+      real      G1agra(knonv)                 ! 1st Layer Dendricity/Spher.
+      real      G2agra(knonv)                 ! 1st Layer Sphericity/Size
+      real      agagra(knonv)                 ! 1st Layer Age
+ 
+ 
+C +--Internal Variables
+C +  ==================
+ 
+      integer   ikl
+      integer   nh                            ! Averaged    Snow History
+      integer   nh__OK                        ! 1=>Conserve Snow History
+      real      rh                            !
+      real      dz                            ! Thickness
+      real      dzro_1                        ! Thickness X Density, Lay.1
+      real      dzro_2                        ! Thickness X Density, Lay.2
+      real      dzro                          ! Thickness X Density, Aver.
+      real      ro                            ! Averaged    Density
+      real      wn                            ! Averaged    Water Content
+      real      tn                            ! Averaged    Temperature
+      real      ag                            ! Averaged    Snow Age
+      real      SameOK                        ! 1. => Same Type of Grains
+      real      G1same                        ! Averaged G1,  same Grains
+      real      G2same                        ! Averaged G2,  same Grains
+      real      typ__1                        ! 1. => Lay1 Type: Dendritic
+      real      zroNEW                        ! dz X ro, if fresh Snow
+      real      G1_NEW                        ! G1,      if fresh Snow
+      real      G2_NEW                        ! G2,      if fresh Snow
+      real      zroOLD                        ! dz X ro, if old   Snow
+      real      G1_OLD                        ! G1,      if old   Snow
+      real      G2_OLD                        ! G2,      if old   Snow
+      real      SizNEW                        ! Size,    if fresh Snow
+      real      SphNEW                        ! Spheric.,if fresh Snow
+      real      SizOLD                        ! Size,    if old   Snow
+      real      SphOLD                        ! Spheric.,if old   Snow
+      real      Siz_av                        ! Averaged    Grain Size
+      real      Sph_av                        ! Averaged    Grain Spher.
+      real      Den_av                        ! Averaged    Grain Dendr.
+      real      DendOK                        ! 1. => Average is  Dendr.
+      real      G1diff                        ! Averaged G1, diff. Grains
+      real      G2diff                        ! Averaged G2, diff. Grains
+      real      G1                            ! Averaged G1
+      real      G2                            ! Averaged G2
+ 
+
+ 
+C +--Mean   Properties
+C +  =================
+ 
+C +-- 1 Densite, Contenu en Eau, Temperature /
+C +     Density, Water Content,  Temperature
+C +     ------------------------------------
+ 
+      DO ikl = 1,knonv
+          dz      =  dzagra(ikl) + dzagrb(ikl)
+          dzro_1  =  roagra(ikl) * dzagra(ikl)
+          dzro_2  =  roagrb(ikl) * dzagrb(ikl)
+          dzro    =  dzro_1      + dzro_2
+          ro      =  dzro
+     .     /max(epsi,dz)
+          wn      = (dzro_1*etagra(ikl) + dzro_2*etagrb(ikl))
+     .     /max(epsi,dzro)
+          tn      = (dzro_1*T_agra(ikl) + dzro_2*T_agrb(ikl))
+     .     /max(epsi,dzro)
+          ag      = (dzro_1*agagra(ikl) + dzro_2*agagrb(ikl))
+     .     /max(epsi,dzro)
+ 
+          rh      =  max(zero,sign(unun,zWEcSV(ikl)
+     .                                         -0.5*WEagra(ikl)))
+          nh__OK  =  rh
+          nh      =                 max(isagra(ikl),isagrb(ikl))
+c #HB.            *  nh__OK
+c #HB.          + (1-nh__OK)*       min(isagra(ikl),isagrb(ikl))
+ 
+ 
+ 
+C +-- 2 Nouveaux Types de Grains /  new Grain Types
+C +     -------------------------------------------
+ 
+C +-- 2.1. Meme  Type  de Neige  / same Grain Type
+C +        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+          SameOK  =  max(zero,
+     .                   sign(unun, G1agra(ikl) *G1agrb(ikl)  - eps_21))
+          G1same  = (dzro_1*G1agra(ikl) + dzro_2*G1agrb(ikl))
+     .     /max(epsi,dzro)
+          G2same  = (dzro_1*G2agra(ikl) + dzro_2*G2agrb(ikl))
+     .     /max(epsi,dzro)
+ 
+C +-- 2.2. Types differents / differents Types
+C +        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+          typ__1  =  max(zero,sign(unun,epsi-G1agra(ikl))) ! =1.=> Dendritic
+          zroNEW  =     typ__1  *dzro_1                    ! ro of Dendr.Lay.
+     .            + (1.-typ__1) *dzro_2                    !
+          G1_NEW  =     typ__1  *G1agra(ikl)               ! G1 of Dendr.Lay.
+     .            + (1.-typ__1) *G1agrb(ikl)               !
+          G2_NEW  =     typ__1  *G2agra(ikl)               ! G2 of Dendr.Lay.
+     .            + (1.-typ__1) *G2agrb(ikl)               !
+          zroOLD  = (1.-typ__1) *dzro_1                    ! ro of Spher.Lay.
+     .            +     typ__1  *dzro_2                    !
+          G1_OLD  = (1.-typ__1) *G1agra(ikl)               ! G1 of Spher.Lay.
+     .            +     typ__1  *G1agrb(ikl)               !
+          G2_OLD  = (1.-typ__1) *G2agra(ikl)               ! G2 of Spher.Lay.
+     .            +     typ__1  *G2agrb(ikl)               !
+          SizNEW  =    -G1_NEW  *DDcdSV/G1_dSV             ! Size  Dendr.Lay.
+     .             +(1.+G1_NEW         /G1_dSV)            !
+     .                *(G2_NEW  *DScdSV/G1_dSV             !
+     .             +(1.-G2_NEW         /G1_dSV)*DFcdSV)    !
+          SphNEW  =     G2_NEW         /G1_dSV             ! Spher.Dendr.Lay.
+          SizOLD  =     G2_OLD                             ! Size  Spher.Lay.
+          SphOLD  =     G1_OLD         /G1_dSV             ! Spher.Spher.Lay.
+          Siz_av  = (zroNEW*SizNEW+zroOLD*SizOLD)      ! Averaged Size
+     .     /max(epsi,dzro)                             !
+          Sph_av  = (zroNEW*SphNEW+zroOLD*SphOLD)      ! Averaged Sphericity
+     .     /max(epsi,dzro)                             !
+          Den_av  = (Siz_av -(    Sph_av *DScdSV       !
+     .                       +(1.-Sph_av)*DFcdSV))     !
+     .            / (DDcdSV -(    Sph_av *DScdSV       !
+     .                       +(1.-Sph_av)*DFcdSV))     !
+          DendOK  = max(zero,                          !
+     .                  sign(unun,     Sph_av *DScdSV  ! Small   Grains Contr.
+     .                            +(1.-Sph_av)*DFcdSV  ! Faceted Grains Contr.
+     .                            -    Siz_av        ))!
+C +...    REMARQUE: le  type moyen (dendritique ou non) depend
+C +       ^^^^^^^^  de la  comparaison avec le diametre optique
+C +                 d'une neige recente de   dendricite nulle
+C +...    REMARK:   the mean type  (dendritic   or not) depends
+C +       ^^^^^^    on the comparaison with the optical diameter
+C +                 of a recent snow    having zero dendricity
+ 
+          G1diff  =(   -DendOK *Den_av
+     .             +(1.-DendOK)*Sph_av) *G1_dSV
+          G2diff  =     DendOK *Sph_av  *G1_dSV
+     .             +(1.-DendOK)*Siz_av
+          G1      =     SameOK *G1same
+     .             +(1.-SameOK)*G1diff
+          G2      =     SameOK *G2same
+     .             +(1.-SameOK)*G2diff
+ 
+ 
+C +--Assignation to new Properties
+C +  =============================
+ 
+          isagra(ikl)   = Agreg1(ikl) *nh +(1.-Agreg1(ikl)) *isagra(ikl)
+          dzagra(ikl)   = Agreg1(ikl) *dz +(1.-Agreg1(ikl)) *dzagra(ikl)
+          T_agra(ikl)   = Agreg1(ikl) *tn +(1.-Agreg1(ikl)) *T_agra(ikl)
+          roagra(ikl)   = Agreg1(ikl) *ro +(1.-Agreg1(ikl)) *roagra(ikl)
+          etagra(ikl)   = Agreg1(ikl) *wn +(1.-Agreg1(ikl)) *etagra(ikl)
+          G1agra(ikl)   = Agreg1(ikl) *G1 +(1.-Agreg1(ikl)) *G1agra(ikl)
+          G2agra(ikl)   = Agreg1(ikl) *G2 +(1.-Agreg1(ikl)) *G2agra(ikl)
+          agagra(ikl)   = Agreg1(ikl) *ag +(1.-Agreg1(ikl)) *agagra(ikl)
+ 
+      END DO
+ 
+      return
+      end
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_zcr.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_zcr.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_zcr.F	(revision 3792)
@@ -0,0 +1,175 @@
+ 
+ 
+      subroutine SISVAT_zCr
+C +
+C +------------------------------------------------------------------------+
+C | MAR          SISVAT_zCr                                12-12-2002  MAR |
+C |   SubRoutine SISVAT_zCr determines criteria for Layers Agregation      |
+C |                                                                        |
+C +------------------------------------------------------------------------+
+C |                                                                        |
+C |   PARAMETERS:  klonv: Total Number of columns =                        |
+C |   ^^^^^^^^^^        = Total Number of continental     grid boxes       |
+C |                     X       Number of Mosaic Cell per grid box         |
+C |                                                                        |
+C |   INPUT /  isnoSV   = total Nb of Ice/Snow Layers                      |
+C |   OUTPUT:  iiceSV   = total Nb of Ice      Layers                      |
+C |   ^^^^^^   ispiSV   = 0,...,nsno: Uppermost Superimposed Ice Layer     |
+C |            istoSV   = 0,...,5 :   Snow     History (see istdSV data)   |
+C |                                                                        |
+C |   INPUT /  ro__SV   : Soil/Snow Volumic Mass                   [kg/m3] |
+C |   OUTPUT:           & Snow     Temperatures (layers  1,2,...,nsno) [K] |
+C |   ^^^^^^   G1snSV   : Dendricity (<0) or Sphericity (>0) of Snow Layer |
+C |            G2snSV   : Sphericity (>0) or Size            of Snow Layer |
+C |            agsnSV   : Snow       Age                             [day] |
+C |                                                                        |
+C |   OUTPUT:  LIndsv   : Relative Index of a contiguous Layer to agregate |
+C |   ^^^^^^                                                               |
+C +------------------------------------------------------------------------+
+C +
+C +
+C +
+C +
+C +--Global Variables
+C +  ================
+C  
+      use VARphy
+      use VAR_SV
+      use VARdSV
+      use VAR0SV
+      use VARxSV
+      use VARySV
+      use VARtSV
+     
+      IMPLICIT NONE
+
+C +
+C +
+C +--Internal Variables
+C +  ==================
+C +
+      integer   ikl   ,isn   ,is0   ,is1
+      integer   isno_1                        ! Switch:  ! Snow Layer over Ice
+      real      Dtyp_0,Dtyp_1                 ! Snow Grains Difference Measure
+      real      DenSph                        ! 1. when contiguous spheric
+C +                                           !     and dendritic  Grains
+      real      DendOK                        ! 1. when dendritic  Grains
+      real      dTypMx                        ! Grain Type Differ.
+      real      dTypSp                        ! Sphericity Weight
+      real      dTypRo                        ! Density    Weight
+      real      dTypDi                        ! Grain Diam.Weight
+      real      dTypHi                        ! History    Weight
+ 
+ 
+C +--DATA
+C +  ====
+ 
+      data      dTypMx / 200.0  /             ! Grain Type Weight
+      data      dTypSp /   0.5  /             ! Sphericity Weight
+      data      dTypRo /   0.5  /             ! Density    Weight
+      data      dTypDi /  10.0  /             ! Grain Diam.Weight
+      data      dTypHi / 100.0  /             ! History    Weight
+ 
+ 
+C +--Agregation Criteria
+C +  ===================
+C +
+      DO  ikl=1,knonv
+          i_thin(ikl) = min(i_thin(ikl),isnoSV(ikl))
+          isn         = max(1          ,i_thin(ikl))
+C +
+C +
+C +--Comparison with the downward Layer
+C +  ----------------------------------
+C +
+
+          is0    = max(1,        i_thin(ikl)-1 )        ! Downward Layer Index
+          DenSph = max(zero,                            ! isn/is1
+     .                 sign(unun,                       ! Dendricity/Sphericity
+     .                      epsi-G1snSV(ikl,isn)        !            Switch
+     .                          *G1snSV(ikl,is0)))      !
+          DendOK = max(zero,                            ! Dendricity Switch
+     .                 sign(unun,                       !
+     .                      epsi-G1snSV(ikl,isn)))      !
+C +          
+          Dtyp_0 =
+     .         DenSph *      dTypMx
+     .    +(1.-DenSph)
+     .    *    DendOK *((abs(G1snSV(ikl,isn)            ! Dendricity
+     .                      -G1snSV(ikl,is0))           !     Contribution
+     .                  +abs(G2snSV(ikl,isn)            ! Sphericity
+     .                      -G2snSV(ikl,is0))) *dTypSp  !     Contribution
+     .                  +abs(ro__SV(ikl,isn)            ! Density
+     .                      -ro__SV(ikl,is0))  *dTypRo) !     Contribution
+     .    +(1.-DenSph)                                  !
+     .    *(1.-DendOK)*((abs(G1snSV(ikl,isn)            ! Sphericity
+     .                      -G1snSV(ikl,is0))           !     Contribution
+     .                  +abs(G2snSV(ikl,isn)            ! Size
+     .                      -G2snSV(ikl,is0))) *dTypDi  !     Contribution
+     .                  +abs(ro__SV(ikl,isn)            ! Density
+     .                      -ro__SV(ikl,is0))  *dTypRo) !     Contribution
+          Dtyp_0 =                                      !
+     .                   min(dTypMx,                    !
+     .                       Dtyp_0                     !
+     .                  +abs(istoSV(ikl,isn)            ! History
+     .                      -istoSV(ikl,is0))  *dTypHi) !     Contribution
+     .        +             (1 -abs(isn-is0))  * 1.e+6  !"Same Layer"Score
+     .        +  max(0,1-abs(iiceSV(ikl)                !"Ice /Snow
+     .                                 -is0))  * 1.e+6  ! Interface" Score
+C +
+C +
+C +--Comparison with the   upward Layer
+C +  ----------------------------------
+C +
+          is1    = min(          i_thin(ikl)+1,         ! Upward   Layer Index
+     .                 max(1,    isnoSV(ikl)  ))        !
+          DenSph = max(zero,                            ! isn/is1
+     .                 sign(unun,                       ! Dendricity/Sphericity
+     .                      epsi-G1snSV(ikl,isn)        !            Switch
+     .                          *G1snSV(ikl,is1)))      !
+          DendOK = max(zero,                            ! Dendricity Switch
+     .                 sign(unun,                       !
+     .                      epsi-G1snSV(ikl,isn)))      !
+C +
+          Dtyp_1 =
+     .         DenSph *      dTypMx
+     .    +(1.-DenSph)
+     .    *    DendOK *((abs(G1snSV(ikl,isn)            ! Dendricity
+     .                      -G1snSV(ikl,is1))           !     Contribution
+     .                  +abs(G2snSV(ikl,isn)            ! Sphericity
+     .                      -G2snSV(ikl,is1))) *dTypSp  !     Contribution
+     .                  +abs(ro__SV(ikl,isn)            ! Density
+     .                      -ro__SV(ikl,is1))  *dTypRo) !     Contribution
+     .    +(1.-DenSph)                                  !
+     .    *(1.-DendOK)*((abs(G1snSV(ikl,isn)            ! Sphericity
+     .                      -G1snSV(ikl,is1))           !     Contribution
+     .                  +abs(G2snSV(ikl,isn)            ! Size
+     .                      -G2snSV(ikl,is1))) *dTypDi  !     Contribution
+     .                  +abs(ro__SV(ikl,isn)            ! Density
+     .                      -ro__SV(ikl,is1))  *dTypRo) !     Contribution
+          Dtyp_1 =                                      !
+     .                   min(dTypMx,                    !
+     .                       Dtyp_1                     !
+     .                  +abs(istoSV(ikl,isn)            ! History
+     .                      -istoSV(ikl,is1))  *dTypHi) !     Contribution
+     .        +             (1 -abs(isn-is1))  * 1.e+6  !"Same Layer"Score
+     .        +  max(0,1-abs(iiceSV(ikl)                !"Ice /Snow
+     .                                 -isn))  * 1.e+6  ! Interface" Score
+C +
+C +
+C +--Index of the Layer to agregate
+C +  ==============================
+C +
+          LIndsv(ikl) = sign(unun,Dtyp_0
+     .                           -Dtyp_1)
+          isno_1      = (1 -min (abs(isnoSV(ikl)        ! Switch = 1
+     .                              -iiceSV(ikl)-1),1)) !   if isno = iice +1
+     .                * (1 -min (abs(isnoSV(ikl)        ! Switch = 1
+     .                              -i_thin(ikl)  ),1)) !   if isno = i_ithin
+          LIndsv(ikl) = (1 -isno_1) *LIndsv(ikl)        ! Contiguous Layer is
+     .                     -isno_1                      ! downward for top L.
+          i_thin(ikl) =  max(1,   i_thin(ikl)   )
+      END DO
+C +
+      return
+      end
Index: LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_zsn.F
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_zsn.F	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/sisvat_zsn.F	(revision 3792)
@@ -0,0 +1,720 @@
+ 
+ 
+      subroutine SISVAT_zSn
+ 
+C +------------------------------------------------------------------------+
+C | MAR          SISVAT_zSn                                12-07-2019  MAR |
+C |   SubRoutine SISVAT_zSn manages the Snow Pack vertical Discretization  |
+C |                                                                        |
+C +------------------------------------------------------------------------+
+C |                                                                        |
+C |   PARAMETERS:  knonv: Total Number of columns =                        |
+C |   ^^^^^^^^^^        = Total Number of continental     grid boxes       |
+C |                     X       Number of Mosaic Cell per grid box         |
+C |                                                                        |
+C |   INPUT /  NLaysv   = New             Snow Layer  Switch               |
+C |   OUTPUT:  isnoSV   = total Nb of Ice/Snow Layers                      |
+C |   ^^^^^^   ispiSV   = 0,...,nsno: Uppermost Superimposed Ice Layer     |
+C |            iiceSV   = total Nb of Ice      Layers                      |
+C |            istoSV   = 0,...,5 :   Snow     History (see istdSV data)   |
+C |                                                                        |
+C |   INPUT /  TsisSV   : Soil/Ice Temperatures (layers -nsol,-nsol+1,..,0)|
+C |   OUTPUT:           & Snow     Temperatures (layers  1,2,...,nsno) [K] |
+C |   ^^^^^^   ro__SV   : Soil/Snow Volumic Mass                   [kg/m3] |
+C |            eta_SV   : Soil/Snow Water   Content                [m3/m3] |
+C |            dzsnSV   : Snow Layer        Thickness                  [m] |
+C |            G1snSV   : Dendricity (<0) or Sphericity (>0) of Snow Layer |
+C |            G2snSV   : Sphericity (>0) or Size            of Snow Layer |
+C |            agsnSV   : Snow       Age                             [day] |
+C |                                                                        |
+C |   METHOD:  1) Agregate the thinest Snow Layer                          |
+C |   ^^^^^^      if a new Snow Layer has been precipitated   (NLaysv = 1) |
+C |            2) Divide   a too thick Snow Layer except                   |
+C |               if the maximum Number of Layer is reached                |
+C |               in this case forces                          NLay_s = 1  |
+C |            3) Agregate the thinest Snow Layer                          |
+C |               in order to divide a too thick Snow Layer                |
+C |               at next Time Step when                       NLay_s = 1  |
+C |                                                                        |
+C +------------------------------------------------------------------------+
+ 
+ 
+ 
+ 
+C +--Global Variables
+C +  ================
+ 
+
+      use VARphy
+      use VAR_SV
+      use VARdSV
+      use VAR0SV
+      use VARxSV
+      use VARySV
+
+      IMPLICIT NONE
+
+ 
+C +--Internal Variables
+C +  ==================
+ 
+      integer   ikl   ,isn   ,i               !
+ 
+
+            
+
+ 
+ 
+      integer   NLay_s(knonv)                 ! Split Snow Layer         Switch
+      integer   isagr1(knonv)                 ! 1st     Layer History
+      integer   isagr2(knonv)                 ! 2nd     Layer History
+      integer   LstLay                        ! 0 ====> isnoSV = 1
+      integer   isno_n                        ! Snow Normal.Profile
+      integer   iice_n                        ! Ice  Normal.Profile
+      integer   iiceOK                        ! Ice         Switch
+      integer   icemix                        ! 0 ====> Agregated Snow+Ice=Snow
+C +                                           ! 1                          Ice
+      integer   isn1  (knonv)                 ! 1st layer to stagger
+      real      staggr                        !              stagger  Switch
+ 
+      real      WEagre(knonv)                 ! Snow Water Equivalent Thickness
+      real      dzthin(knonv)                 ! Thickness of the thinest layer
+      real      OKthin                        ! Swich ON  a  new thinest layer
+      real      dz_dif                        ! difference from ideal discret.
+      real      thickL                        ! Thick Layer          Indicator
+      real      OK_ICE                        ! Swich ON   uppermost Ice Layer
+ 
+      real      Agrege(knonv)                 ! 1. when Agregation constrained
+      real      dzepsi                        ! Min Single Snw Layer Thickness
+      real      dzxmin                        ! Min Acceptable Layer Thickness
+      real      dz_min                        ! Min            Layer Thickness
+      real      dz_max                        ! Max            Layer Thickness
+      real      dzagr1(knonv)                 ! 1st     Layer Thickness
+      real      dzagr2(knonv)                 ! 2nd     Layer Thickness
+      real      T_agr1(knonv)                 ! 1st     Layer Temperature
+      real      T_agr2(knonv)                 ! 2nd     Layer Temperature
+      real      roagr1(knonv)                 ! 1st     Layer Density
+      real      roagr2(knonv)                 ! 2nd     Layer Density
+      real      etagr1(knonv)                 ! 1st     Layer Water Content
+      real      etagr2(knonv)                 ! 2nd     Layer Water Content
+      real      G1agr1(knonv)                 ! 1st     Layer Dendricity/Spher.
+      real      G1agr2(knonv)                 ! 2nd     Layer Dendricity/Spher.
+      real      G2agr1(knonv)                 ! 1st     Layer Sphericity/Size
+      real      G2agr2(knonv)                 ! 2nd     Layer Sphericity/Size
+      real      agagr1(knonv)                 ! 1st     Layer Age
+      real      agagr2(knonv)                 ! 2nd     Layer Age
+
+ 
+C +--DATA
+C +  ====
+ 
+      data      icemix /   0    /             ! 0 ====> Agregated Snow+Ice=Snow
+      data      dzepsi /   0.0020/            ! Min single Layer Thickness
+      data      dzxmin /   0.0025/            ! Min accept.Layer Thickness
+c #EU data      dz_min /   0.0050/            ! Min Local  Layer Thickness < SMn
+      data      dz_min /   0.0040/            ! Min Local  Layer Thickness < SMn
+      data      dz_max /   0.0300/            ! Min Gener. Layer Thickness
+C +   CAUTION:  dz_max > dz_min*2 is required ! Otherwise re-agregation is
+C +                                           ! activated  after splitting
+ 
+
+ 
+
+ 
+C +--Constrains Agregation         of too thin  Layers
+C +  =================================================
+ 
+C +--Search the thinest  non-zero Layer
+C +  ----------------------------------
+ 
+        DO ikl=1,knonv
+          if(isnoSV(ikl)<=2)             dz_min=max(0.0050,dz_min)
+ 
+                                          dzepsi=0.0015
+          if(ro__SV(ikl,isnoSV(ikl))>920) dzepsi=0.0020
+ 
+          dzthin(ikl) = 0.                              ! Arbitrary unrealistic
+        END DO                                          !       Layer Thickness
+cXF
+      DO ikl=1,knonv
+      DO   isn=1,isnoSV(ikl)-3 ! no agregation of 3 first snowlayers
+                               ! XF 04/07/2019
+ 
+          isno_n    =             isnoSV(ikl)-isn+1     ! Snow Normal.Profile
+          iice_n    =             iiceSV(ikl)-isn       ! Ice  Normal.Profile
+          iiceOK    = min(1,max(0,iice_n         +1))   ! Ice         Switch
+! #vz     dz_ref(isn) =                                 !
+! #vz.          dz_min *((1-iiceOK)*isno_n*isno_n       ! Theoretical Profile
+! #vz.                 +    iiceOK *    2**iice_n)      !
+! #vz.               /max(1,isnoSV(ikl))                !
+          dz_dif      = max(zero,                       ! Actual      Profile
+     .          dz_min                                  !
+     .                 *((1-iiceOK)*isno_n*isno_n       ! Theoretical Profile
+     .                 +    iiceOK *2.   **iice_n)      !
+     .        - dzsnSV(ikl, isn)                    )   ! Actual      Profile
+! #vz     dzwdif(isn) =     dz_dif                      !
+          OKthin      = max(zero,                       !
+     .                      sign(unun,                  !
+     .                           dz_dif-dzthin(ikl)))   ! 1.=> New thinest Lay.
+     .                * max(0,                          ! 1 => .le. isnoSV
+     .                  min(1,                          ! 1 => isn is in the
+     .                      isnoSV(ikl)-isn +1 ))       !          Snow Pack
+     .                * min(unun,                                !
+!
+!                       1st additional Condition to accept OKthin
+     .                  max(zero,                                ! combination
+     .                      sign(unun,G1snSV(ikl,      isn  )    ! G1 with same
+     .                               *G1snSV(ikl,max(1,isn-1)))) !  sign => OK
+!
+!                       2nd additional Condition to accept OKthin
+     .                + max(zero,                                ! G1>0
+     .                      sign(unun,G1snSV(ikl,      isn   ))) !  =>OK
+!
+!                       3rd additional Condition to accept OKthin
+     .                + max(zero,                                ! dz too small
+     .                      sign(unun,dzxmin                     !  =>OK
+     .                               -dzsnSV(ikl,      isn   ))))!
+ 
+          i_thin(ikl) =    (1. - OKthin)  * i_thin(ikl) ! Update   thinest Lay.
+     .                         + OKthin   * isn         !                Index
+          dzthin(ikl) =    (1. - OKthin)  * dzthin(ikl) !
+     .                         + OKthin   * dz_dif      !
+        END DO
+      END DO
+ 
+
+ 
+      DO ikl=1,knonv
+      DO   isn=1,isnoSV(ikl)
+          OKthin =      max(zero,                       !
+     .                      sign(unun,                  !
+     .                           dz_min                 !
+     .                          -dzsnSV(ikl,isn)))      !
+     .                * max(zero,                       ! ON if dz > 0
+     .                      sign(unun,                  !
+     .                           dzsnSV(ikl,isn)-epsi)) !
+     .           *min(1,max(0,                          ! Multiple Snow    Lay.
+     .                      min (1,                     ! Switch = 1
+     .                           isnoSV(ikl)            !   if isno > iice + 1
+     .                          -iiceSV(ikl)-1))        !
+C +                                                     !
+     .             +int(max(zero,                       !
+     .                      sign(unun,                  !
+     .                           dzepsi                 ! Minimum accepted for
+     .                          -dzsnSV(ikl,isn))))     ! 1 Snow Layer over Ice
+     .             *int(max(zero,                       ! ON if dz > 0
+     .                      sign(unun,                  !
+     .                           dzsnSV(ikl,isn)-epsi)))!
+     .                 *(1 -min (abs(isnoSV(ikl)        ! Switch = 1
+     .                              -iiceSV(ikl)-1),1)) !   if isno = iice + 1
+C +                                                     !
+     .                 +max(0,                          ! Ice
+     .                      min (1,                     ! Switch
+     .                           iiceSV(ikl)+1-isn)))   !
+     .             *min(unun,                                    !
+     .                  max(zero,                                ! combination
+     .                      sign(unun,G1snSV(ikl,      isn  )    ! G1>0 + G1<0
+     .                               *G1snSV(ikl,max(1,isn-1)))) ! NO
+     .                + max(zero,                                !
+     .                      sign(unun,G1snSV(ikl,      isn   ))) !
+     .                + max(zero,                                !
+     .                      sign(unun,dzxmin                     !
+     .                               -dzsnSV(ikl,      isn   ))))!
+          i_thin(ikl) =    (1. - OKthin)  * i_thin(ikl) ! Update   thinest Lay.
+     .                         + OKthin   * isn         !                Index
+        END DO
+      END DO
+ 
+
+
+ 
+C +   ***************
+      call SISVAT_zCr
+C +   ***************
+ 
+ 
+C +--Assign the 2 Layers to agregate
+C +  -------------------------------
+ 
+        DO ikl=1,knonv
+          isn         =    i_thin(ikl)
+          if(LIndsv(ikl)>0) isn=min(nsno-1,isn) ! cXF
+          isagr1(ikl) =    istoSV(ikl,isn)
+          isagr2(ikl) =    istoSV(ikl,isn+LIndsv(ikl))
+          dzagr1(ikl) =    dzsnSV(ikl,isn)
+          dzagr2(ikl) =    dzsnSV(ikl,isn+LIndsv(ikl))
+          T_agr1(ikl) =    TsisSV(ikl,isn)
+          T_agr2(ikl) =    TsisSV(ikl,isn+LIndsv(ikl))
+          roagr1(ikl) =    ro__SV(ikl,isn)
+          roagr2(ikl) =    ro__SV(ikl,isn+LIndsv(ikl))
+          etagr1(ikl) =    eta_SV(ikl,isn)
+          etagr2(ikl) =    eta_SV(ikl,isn+LIndsv(ikl))
+          G1agr1(ikl) =    G1snSV(ikl,isn)
+          G1agr2(ikl) =    G1snSV(ikl,isn+LIndsv(ikl))
+          G2agr1(ikl) =    G2snSV(ikl,isn)
+          G2agr2(ikl) =    G2snSV(ikl,isn+LIndsv(ikl))
+          agagr1(ikl) =    agsnSV(ikl,isn)
+          agagr2(ikl) =    agsnSV(ikl,isn+LIndsv(ikl))
+          LstLay      = min(1,max(  0,isnoSV(ikl) -1))  ! 0  if single Layer
+          isnoSV(ikl) =               isnoSV(ikl)       ! decrement   isnoSV
+     .     -(1-LstLay)* max(zero,                       ! if downmost  Layer
+     .                      sign(unun,eps_21            ! <  1.e-21 m
+     .                               -dzsnSV(ikl,1)))   !
+          isnoSV(ikl) = max(   0,     isnoSV(ikl)   )   !
+          Agrege(ikl) = max(zero,                       !
+     .                      sign(unun,dz_min            ! No Agregation
+     .                               -dzagr1(ikl)  ))   ! if too thick Layer
+     .                               *LstLay            ! if  a single Layer
+     .                * min( max(0   ,isnoSV(ikl)+1     ! if Agregation
+     .                               -i_thin(ikl)       !    with    a Layer
+     .                               -LIndsv(ikl)  ),1) !    above the Pack
+ 
+          WEagre(ikl) = 0.
+        END DO
+ 
+ 
+        DO ikl=1,knonv
+        DO   isn=1,isnoSV(ikl)
+          WEagre(ikl) = WEagre(ikl) + ro__SV(ikl,isn)*dzsnSV(ikl,isn)
+     .                                *min(1,max(0,i_thin(ikl)+1-isn))
+        ENDDO
+        ENDDO
+ 
+ 
+C +--Agregates
+C +  ---------
+ 
+C +     ***************
+        call SISVAT_zAg
+     .                 (isagr1,isagr2,WEagre
+     .                 ,dzagr1,dzagr2,T_agr1,T_agr2
+     .                 ,roagr1,roagr2,etagr1,etagr2
+     .                 ,G1agr1,G1agr2,G2agr1,G2agr2
+     .                 ,agagr1,agagr2,Agrege
+     .                 )
+C +     ***************
+ 
+ 
+C +--Rearranges the Layers
+C +  ---------------------
+ 
+C +--New (agregated) Snow layer
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+        DO ikl=1,knonv
+          isn     =             i_thin(ikl)
+          isn     = min(isn,isn+LIndsv(ikl))
+          isnoSV(ikl) =  max(0.,isnoSV(ikl) -Agrege(ikl))
+          iiceSV(ikl) =         iiceSV(ikl)
+     .            -max(0,sign(1,iiceSV(ikl) -isn +icemix))
+     .                                      *Agrege(ikl)
+     .            *max(0,sign(1,iiceSV(ikl) -1          ))
+          istoSV(ikl,isn) = (1.-Agrege(ikl))*istoSV(ikl,isn)
+     .                      +   Agrege(ikl) *isagr1(ikl)
+          dzsnSV(ikl,isn) = (1.-Agrege(ikl))*dzsnSV(ikl,isn)
+     .                      +   Agrege(ikl) *dzagr1(ikl)
+          TsisSV(ikl,isn) = (1.-Agrege(ikl))*TsisSV(ikl,isn)
+     .                      +   Agrege(ikl) *T_agr1(ikl)
+          ro__SV(ikl,isn) = (1.-Agrege(ikl))*ro__SV(ikl,isn)
+     .                      +   Agrege(ikl) *roagr1(ikl)
+          eta_SV(ikl,isn) = (1.-Agrege(ikl))*eta_SV(ikl,isn)
+     .                      +   Agrege(ikl) *etagr1(ikl)
+          G1snSV(ikl,isn) = (1.-Agrege(ikl))*G1snSV(ikl,isn)
+     .                      +   Agrege(ikl) *G1agr1(ikl)
+          G2snSV(ikl,isn) = (1.-Agrege(ikl))*G2snSV(ikl,isn)
+     .                      +   Agrege(ikl) *G2agr1(ikl)
+          agsnSV(ikl,isn) = (1.-Agrege(ikl))*agsnSV(ikl,isn)
+     .                      +   Agrege(ikl) *agagr1(ikl)
+        END DO
+ 
+C +--Above
+C +  ^^^^^
+        DO ikl=1,knonv
+          isn1(ikl)=max(i_thin(ikl),i_thin(ikl)+LIndsv(ikl))
+        END DO
+        DO i=  1,nsno-1
+        DO ikl=1,knonv
+            staggr        =  min(1,max(0,i +1 -isn1(ikl)   ))
+            istoSV(ikl,i) = (1.-staggr     )*istoSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*istoSV(ikl,i  )
+     .                      +   Agrege(ikl) *istoSV(ikl,i+1))
+            dzsnSV(ikl,i) = (1.-staggr     )*dzsnSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*dzsnSV(ikl,i  )
+     .                      +   Agrege(ikl) *dzsnSV(ikl,i+1))
+            TsisSV(ikl,i) = (1.-staggr     )*TsisSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*TsisSV(ikl,i  )
+     .                      +   Agrege(ikl) *TsisSV(ikl,i+1))
+            ro__SV(ikl,i) = (1.-staggr     )*ro__SV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*ro__SV(ikl,i  )
+     .                      +   Agrege(ikl) *ro__SV(ikl,i+1))
+            eta_SV(ikl,i) = (1.-staggr     )*eta_SV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*eta_SV(ikl,i  )
+     .                      +   Agrege(ikl) *eta_SV(ikl,i+1))
+            G1snSV(ikl,i) = (1.-staggr     )*G1snSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*G1snSV(ikl,i  )
+     .                      +   Agrege(ikl) *G1snSV(ikl,i+1))
+            G2snSV(ikl,i) = (1.-staggr     )*G2snSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*G2snSV(ikl,i  )
+     .                      +   Agrege(ikl) *G2snSV(ikl,i+1))
+            agsnSV(ikl,i) = (1.-staggr     )*agsnSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*agsnSV(ikl,i  )
+     .                      +   Agrege(ikl) *agsnSV(ikl,i+1))
+        END DO
+        END DO
+ 
+        DO ikl=1,knonv
+          isn             = min(isnoSV(ikl) +1,nsno)
+          istoSV(ikl,isn) = (1.-Agrege(ikl))*istoSV(ikl,isn)
+          dzsnSV(ikl,isn) = (1.-Agrege(ikl))*dzsnSV(ikl,isn)
+          TsisSV(ikl,isn) = (1.-Agrege(ikl))*TsisSV(ikl,isn)
+          ro__SV(ikl,isn) = (1.-Agrege(ikl))*ro__SV(ikl,isn)
+          eta_SV(ikl,isn) = (1.-Agrege(ikl))*eta_SV(ikl,isn)
+          G1snSV(ikl,isn) = (1.-Agrege(ikl))*G1snSV(ikl,isn)
+          G2snSV(ikl,isn) = (1.-Agrege(ikl))*G2snSV(ikl,isn)
+          agsnSV(ikl,isn) = (1.-Agrege(ikl))*agsnSV(ikl,isn)
+        END DO
+ 
+
+ 
+ 
+C +--Constrains Splitting          of too thick Layers
+C +  =================================================
+ 
+ 
+C +--Search the thickest non-zero Layer
+C +  ----------------------------------
+ 
+        DO ikl=1,knonv
+          dzthin(ikl) =   0.                            ! Arbitrary unrealistic
+        END DO
+      DO ikl=1,knonv
+        DO   isn=1,isnoSV(ikl)
+          isno_n    =             isnoSV(ikl)-isn+1     ! Snow Normal.Profile
+          iice_n    =             iiceSV(ikl)-isn       ! Ice  Normal.Profile
+          iiceOK    = min(1,max(0,iice_n         +1))   ! Ice         Switch
+          dz_dif    =(      dzsnSV(ikl,isn)             ! Actual      Profile
+     .        - dz_max *((1-iiceOK)*isno_n*isno_n       ! Theoretical Profile
+     .                 +    iiceOK *2.   **iice_n)  )   !
+     .                 /max(dzsnSV(ikl,isn),epsi)       !
+          OKthin      = max(zero,                       !
+     .                      sign(unun,                  !
+     .                           dz_dif-dzthin(ikl)))   ! 1.=>New thickest Lay.
+     .                * max(0,                          ! 1 =>.le. isnoSV
+     .                  min(1,                          !
+     .                      isnoSV(ikl)-isn +1 ))       !
+          i_thin(ikl) =    (1. - OKthin)  * i_thin(ikl) !  Update thickest Lay.
+     .                         + OKthin   * isn         !                Index
+          dzthin(ikl) =    (1. - OKthin)  * dzthin(ikl) !
+     .                         + OKthin   * dz_dif      !
+        END DO
+ 
+        isn=max(1,isnoSV(ikl)-3)
+        if(dzsnSV(ikl,isn)>0.30) then   ! surface layer > 30cm
+         i_thin(ikl) = isn              ! XF 04/07/2019
+         dzthin(ikl) = dzsnSV(ikl,isn)
+        endif
+ 
+        isn=max(1,isnoSV(ikl)-2)
+        if(dzsnSV(ikl,isn)>0.10) then   ! surface layer > 10cm
+         i_thin(ikl) = isn              ! XF 04/07/2019
+         dzthin(ikl) = dzsnSV(ikl,isn)
+        endif
+ 
+        isn=max(1,isnoSV(ikl)-1)
+        if(dzsnSV(ikl,isn)>0.05) then   ! surface layer > 5cm
+         i_thin(ikl) = isn              ! XF 04/07/2019
+         dzthin(ikl) = dzsnSV(ikl,isn)
+        endif
+ 
+        isn=max(1,isnoSV(ikl))
+        if(dzsnSV(ikl,isn)>0.02) then   ! surface layer > 2cm
+         i_thin(ikl) = isn              ! XF 04/07/2019
+         dzthin(ikl) = dzsnSV(ikl,isn)
+        endif
+ 
+      END DO
+ 
+      DO   ikl=1,knonv
+          ThickL      = max(zero,                       ! 1. => a too   thick
+     .                      sign(unun,dzthin(ikl)       !         Layer exists
+     .                               -epsi       ))     !
+     .        * max(0,1-max(0   ,     isnoSV(ikl)       ! No spliting allowed
+     .                               -nsno+1     ))     ! if isno > nsno - 1
+          Agrege(ikl) =               ThickL            ! 1. => effective split
+     .        * max(0,1-max(0   ,     NLaysv(ikl)       !
+     .                               +isnoSV(ikl)       !
+     .                               -nsno+1     ))     !
+          NLay_s(ikl) =               ThickL            ! Agregation
+     .        * max(0,1-max(0   ,     NLaysv(ikl)       ! to allow  Splitting
+     .                               +isnoSV(ikl)       !   at next Time Step
+     .                               -nsno       ))     !
+     .                               -Agrege(ikl)       !
+          NLay_s(ikl) = max(0   ,     NLay_s(ikl))      ! Agregation effective
+      END DO
+ 
+
+C +--Rearranges the Layers
+C +  ---------------------
+ 
+      DO isn=nsno,2,-1
+      DO ikl=1,knonv
+        IF (Agrege(ikl).gt.0..AND.i_thin(ikl).lt.isnoSV(ikl))       THEN
+          staggr          =  min(1,max(0,isn-i_thin(ikl)    -1))
+     .                    *  min(1,max(0,    isnoSV(ikl)-isn+2))
+          istoSV(ikl,isn) =        staggr  * istoSV(ikl ,isn-1)
+     .                    + (1. -  staggr) * istoSV(ikl ,isn  )
+          dzsnSV(ikl,isn) =        staggr  * dzsnSV(ikl ,isn-1)
+     .                    + (1. -  staggr) * dzsnSV(ikl ,isn  )
+          TsisSV(ikl,isn) =        staggr  * TsisSV(ikl ,isn-1)
+     .                    + (1. -  staggr) * TsisSV(ikl ,isn  )
+          ro__SV(ikl,isn) =        staggr  * ro__SV(ikl ,isn-1)
+     .                    + (1. -  staggr) * ro__SV(ikl ,isn  )
+          eta_SV(ikl,isn) =        staggr  * eta_SV(ikl ,isn-1)
+     .                    + (1. -  staggr) * eta_SV(ikl ,isn  )
+          G1snSV(ikl,isn) =        staggr  * G1snSV(ikl ,isn-1)
+     .                    + (1. -  staggr) * G1snSV(ikl ,isn  )
+          G2snSV(ikl,isn) =        staggr  * G2snSV(ikl ,isn-1)
+     .                    + (1. -  staggr) * G2snSV(ikl ,isn  )
+          agsnSV(ikl,isn) =        staggr  * agsnSV(ikl ,isn-1)
+     .                    + (1. -  staggr) * agsnSV(ikl ,isn  )
+        END IF
+      END DO
+      END DO
+ 
+      DO  ikl=1,knonv
+          isn             =     i_thin(ikl)
+          dzsnSV(ikl,isn) = 0.5*Agrege(ikl) *dzsnSV(ikl,isn)
+     .                    + (1.-Agrege(ikl))*dzsnSV(ikl,isn)
+ 
+          isn             = min(i_thin(ikl) +1,nsno)
+          istoSV(ikl,isn) =     Agrege(ikl) *istoSV(ikl,isn-1)
+     .                    + (1.-Agrege(ikl))*istoSV(ikl,isn)
+          dzsnSV(ikl,isn) =     Agrege(ikl) *dzsnSV(ikl,isn-1)
+     .                    + (1.-Agrege(ikl))*dzsnSV(ikl,isn)
+          TsisSV(ikl,isn) =     Agrege(ikl) *TsisSV(ikl,isn-1)
+     .                    + (1.-Agrege(ikl))*TsisSV(ikl,isn)
+          ro__SV(ikl,isn) =     Agrege(ikl) *ro__SV(ikl,isn-1)
+     .                    + (1.-Agrege(ikl))*ro__SV(ikl,isn)
+          eta_SV(ikl,isn) =     Agrege(ikl) *eta_SV(ikl,isn-1)
+     .                    + (1.-Agrege(ikl))*eta_SV(ikl,isn)
+          G1snSV(ikl,isn) =     Agrege(ikl) *G1snSV(ikl,isn-1)
+     .                    + (1.-Agrege(ikl))*G1snSV(ikl,isn)
+          G2snSV(ikl,isn) =     Agrege(ikl) *G2snSV(ikl,isn-1)
+     .                    + (1.-Agrege(ikl))*G2snSV(ikl,isn)
+          agsnSV(ikl,isn) =     Agrege(ikl) *agsnSV(ikl,isn-1)
+     .                    + (1.-Agrege(ikl))*agsnSV(ikl,isn)
+          isnoSV(ikl)     = min(Agrege(ikl) +isnoSV(ikl),real(nsno))
+          iiceSV(ikl)     =                  iiceSV(ikl)
+     .                    +     Agrege(ikl) *max(0,sign(1,iiceSV(ikl)
+     .                                                   -isn +icemix))
+     .                                      *max(0,sign(1,iiceSV(ikl)
+     .                                                   -1          ))
+      END DO
+ 
+ 
+C +--Constrains Agregation in case of too much  Layers
+C +  =================================================
+ 
+C +--Search the thinest   non-zero Layer
+C +  -----------------------------------
+
+
+ 
+        DO ikl=1,knonv
+          dzthin(ikl) =   0.                            ! Arbitrary unrealistic
+        END DO                                          !       Layer Thickness
+      DO ikl=1,knonv
+        DO isn=1,isnoSV(ikl)-3 ! no agregation of 3 first snowlayers
+                               ! XF 04/07/2019
+ 
+          isno_n    =             isnoSV(ikl)-isn+1     ! Snow Normal.Profile
+          iice_n    =             iiceSV(ikl)-isn       ! Ice  Normal.Profile
+          iiceOK    = min(1,max(0,iice_n         +1))   ! Ice         Switch
+! #vz     dz_ref(isn) =                                 !
+! #vz.          dz_min *((1-iiceOK)*isno_n*isno_n       ! Theoretical Profile
+! #vz.                 +    iiceOK *    2**iice_n)      !
+! #vz.               /max(1,isnoSV(ikl))                !
+          dz_dif      =     dz_min                      ! Actual      Profile
+     .                    - dzsnSV(ikl    ,isn)         !
+     .        /max(epsi,((1-iiceOK)*isno_n*isno_n       ! Theoretical Profile
+     .                 +    iiceOK *2.   **iice_n))     !
+! #vz     dzwdif(isn) =     dz_dif                      !
+          OKthin      = max(zero,                       !
+     .                      sign(unun,                  !
+     .                           dz_dif  - dzthin(ikl)))! 1.=> New thinest Lay.
+     .                * max(0,                          ! 1 => .le. isnoSV
+     .                  min(1,                          !
+     .                      isnoSV(ikl)-isn +1 ))       !
+          i_thin(ikl) =    (1. - OKthin) * i_thin(ikl)  ! Update   thinest Lay.
+     .                         + OKthin  * isn          !                Index
+          dzthin(ikl) =    (1. - OKthin) * dzthin(ikl)  !
+     .                         + OKthin  * dz_dif       !
+
+
+        END DO
+      END DO
+ 
+ 
+
+
+
+C +--Index of the contiguous Layer to agregate
+C +  -----------------------------------------
+ 
+C +   ***************
+      call SISVAT_zCr
+C +   ***************
+ 
+ 
+C +--Assign the 2 Layers to agregate
+C +  -------------------------------
+ 
+        DO ikl=1,knonv
+          isn         =    i_thin(ikl)
+          if(LIndsv(ikl)>0) isn=min(isn, nsno-1) !cXF
+          isagr1(ikl) =    istoSV(ikl,isn)
+          isagr2(ikl) =    istoSV(ikl,isn+LIndsv(ikl))
+          dzagr1(ikl) =    dzsnSV(ikl,isn)
+          dzagr2(ikl) =    dzsnSV(ikl,isn+LIndsv(ikl))
+          T_agr1(ikl) =    TsisSV(ikl,isn)
+          T_agr2(ikl) =    TsisSV(ikl,isn+LIndsv(ikl))
+          roagr1(ikl) =    ro__SV(ikl,isn)
+          roagr2(ikl) =    ro__SV(ikl,isn+LIndsv(ikl))
+          etagr1(ikl) =    eta_SV(ikl,isn)
+          etagr2(ikl) =    eta_SV(ikl,isn+LIndsv(ikl))
+          G1agr1(ikl) =    G1snSV(ikl,isn)
+          G1agr2(ikl) =    G1snSV(ikl,isn+LIndsv(ikl))
+          G2agr1(ikl) =    G2snSV(ikl,isn)
+          G2agr2(ikl) =    G2snSV(ikl,isn+LIndsv(ikl))
+          agagr1(ikl) =    agsnSV(ikl,isn)
+          agagr2(ikl) =    agsnSV(ikl,isn+LIndsv(ikl))
+          LstLay      = min(1,max(  0,    isnoSV(ikl)-1   ))
+          Agrege(ikl) = min(1,
+     .                  max(0,
+     .                      NLaysv(ikl)   +isnoSV(ikl)-nsno
+     .                     +NLay_s(ikl)                    )
+     .                                    *LstLay           )
+ 
+C + minimum uppermost layer thickness to guarantee a correct reproduction of the snow
+C + atmosphere coupling
+        if(dzsnSV(ikl,max(1,isnoSV(ikl)-0))>0.02 .or.   ! surface layers> 2-5-10
+     .     dzsnSV(ikl,max(1,isnoSV(ikl)-1))>0.05 .or.   ! XF 04/07/2019
+     .     dzsnSV(ikl,max(1,isnoSV(ikl)-2))>0.10 .or.
+     .     dzsnSV(ikl,max(1,isnoSV(ikl)-3))>0.30 )then
+          Agrege(ikl) = min(1,
+     .                  max(0,
+     .                      NLaysv(ikl)   +isnoSV(ikl)+1-nsno ! nsno-1 layers ma
+     .                     +NLay_s(ikl)                    )
+     .                                    *LstLay           )
+        endif
+ 
+          isnoSV(ikl) =                    isnoSV(ikl)
+     .     -(1-LstLay)*max(zero,
+     .                     sign(unun,      eps_21
+     .                                    -dzsnSV(ikl,1)   ))
+          isnoSV(ikl) =max(   0,           isnoSV(ikl)      )
+ 
+          WEagre(ikl) = 0.
+        END DO
+ 
+        DO isn=1,nsno
+        DO ikl=1,knonv
+          WEagre(ikl) = WEagre(ikl) + ro__SV(ikl,isn)*dzsnSV(ikl,isn)
+     .                                *min(1,max(0,i_thin(ikl)+1-isn))
+        ENDDO
+        ENDDO
+
+C +--Agregates
+C +  ---------
+ 
+C +     ***************
+        call SISVAT_zAg
+     .                 (isagr1,isagr2,WEagre
+     .                 ,dzagr1,dzagr2,T_agr1,T_agr2
+     .                 ,roagr1,roagr2,etagr1,etagr2
+     .                 ,G1agr1,G1agr2,G2agr1,G2agr2
+     .                 ,agagr1,agagr2,Agrege
+     .                 )
+C +     ***************
+ 
+ 
+C +--Rearranges the Layers
+C +  ---------------------
+ 
+C +--New (agregated) Snow layer
+C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^
+        DO ikl=1,knonv
+          isn     =             i_thin(ikl)
+          isn     = min(isn,isn+LIndsv(ikl))
+          isnoSV(ikl) =  max(0.,isnoSV(ikl) -Agrege(ikl))
+          iiceSV(ikl) =         iiceSV(ikl)
+     .            -max(0,sign(1,iiceSV(ikl) -isn +icemix))
+     .                                      *Agrege(ikl)
+     .            *max(0,sign(1,iiceSV(ikl) -1          ))
+          istoSV(ikl,isn) = (1.-Agrege(ikl))*istoSV(ikl,isn)
+     .                      +   Agrege(ikl) *isagr1(ikl)
+          dzsnSV(ikl,isn) = (1.-Agrege(ikl))*dzsnSV(ikl,isn)
+     .                      +   Agrege(ikl) *dzagr1(ikl)
+          TsisSV(ikl,isn) = (1.-Agrege(ikl))*TsisSV(ikl,isn)
+     .                      +   Agrege(ikl) *T_agr1(ikl)
+          ro__SV(ikl,isn) = (1.-Agrege(ikl))*ro__SV(ikl,isn)
+     .                      +   Agrege(ikl) *roagr1(ikl)
+          eta_SV(ikl,isn) = (1.-Agrege(ikl))*eta_SV(ikl,isn)
+     .                      +   Agrege(ikl) *etagr1(ikl)
+          G1snSV(ikl,isn) = (1.-Agrege(ikl))*G1snSV(ikl,isn)
+     .                      +   Agrege(ikl) *G1agr1(ikl)
+          G2snSV(ikl,isn) = (1.-Agrege(ikl))*G2snSV(ikl,isn)
+     .                      +   Agrege(ikl) *G2agr1(ikl)
+          agsnSV(ikl,isn) = (1.-Agrege(ikl))*agsnSV(ikl,isn)
+     .                      +   Agrege(ikl) *agagr1(ikl)
+        END DO
+ 
+C +--Above
+C +  ^^^^^
+        DO ikl=1,knonv
+          isn1(ikl)=max(i_thin(ikl),i_thin(ikl)+LIndsv(ikl))
+        END DO
+        DO i=  1,nsno-1
+        DO ikl=1,knonv
+            staggr        =  min(1,max(0,i +1 -isn1(ikl)   ))
+            istoSV(ikl,i) = (1.-staggr     )*istoSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*istoSV(ikl,i  )
+     .                      +   Agrege(ikl) *istoSV(ikl,i+1))
+            dzsnSV(ikl,i) = (1.-staggr     )*dzsnSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*dzsnSV(ikl,i  )
+     .                      +   Agrege(ikl) *dzsnSV(ikl,i+1))
+            TsisSV(ikl,i) = (1.-staggr     )*TsisSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*TsisSV(ikl,i  )
+     .                      +   Agrege(ikl) *TsisSV(ikl,i+1))
+            ro__SV(ikl,i) = (1.-staggr     )*ro__SV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*ro__SV(ikl,i  )
+     .                      +   Agrege(ikl) *ro__SV(ikl,i+1))
+            eta_SV(ikl,i) = (1.-staggr     )*eta_SV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*eta_SV(ikl,i  )
+     .                      +   Agrege(ikl) *eta_SV(ikl,i+1))
+            G1snSV(ikl,i) = (1.-staggr     )*G1snSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*G1snSV(ikl,i  )
+     .                      +   Agrege(ikl) *G1snSV(ikl,i+1))
+            G2snSV(ikl,i) = (1.-staggr     )*G2snSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*G2snSV(ikl,i  )
+     .                      +   Agrege(ikl) *G2snSV(ikl,i+1))
+            agsnSV(ikl,i) = (1.-staggr     )*agsnSV(ikl,i  )
+     .            + staggr*((1.-Agrege(ikl))*agsnSV(ikl,i  )
+     .                      +   Agrege(ikl) *agsnSV(ikl,i+1))
+        END DO
+        END DO
+ 
+        DO ikl=1,knonv
+          isn             = min(isnoSV(ikl) +1,nsno)
+          istoSV(ikl,isn) = (1.-Agrege(ikl))*istoSV(ikl,isn)
+          dzsnSV(ikl,isn) = (1.-Agrege(ikl))*dzsnSV(ikl,isn)
+          TsisSV(ikl,isn) = (1.-Agrege(ikl))*TsisSV(ikl,isn)
+          ro__SV(ikl,isn) = (1.-Agrege(ikl))*ro__SV(ikl,isn)
+          eta_SV(ikl,isn) = (1.-Agrege(ikl))*eta_SV(ikl,isn)
+          G1snSV(ikl,isn) = (1.-Agrege(ikl))*G1snSV(ikl,isn)
+          G2snSV(ikl,isn) = (1.-Agrege(ikl))*G2snSV(ikl,isn)
+          agsnSV(ikl,isn) = (1.-Agrege(ikl))*agsnSV(ikl,isn)
+        END DO
+
+ 
+      return
+      end
Index: LMDZ6/trunk/libf/phylmd/inlandsis/surf_inlandsis_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/inlandsis/surf_inlandsis_mod.F90	(revision 3792)
+++ LMDZ6/trunk/libf/phylmd/inlandsis/surf_inlandsis_mod.F90	(revision 3792)
@@ -0,0 +1,1454 @@
+MODULE surf_inlandsis_mod
+
+  IMPLICIT NONE
+
+ 
+  CONTAINS
+
+                                       
+
+  SUBROUTINE surf_inlandsis(knon,rlon,rlat, ikl2i, itime, dtime, debut, lafin, &
+             rmu0, swdown, lwdown, albedo_old, pexner, ps, p1lay, &
+             precip_rain, precip_snow, precip_snow_adv, snow_adv, &
+             zsl_height, wind_velo, ustar, temp_air, dens_air, spechum, tsurf, &
+             rugos, snow_cont_air, alb_soil, slope, cloudf, &
+             radsol, qsol, tsoil, snow, zfra, snowhgt, qsnow, to_ice, sissnow, agesno, & 
+             AcoefH, AcoefQ, BcoefH, BcoefQ, cdragm, cdragh, &
+             runoff_lic, evap, fluxsens, fluxlat, dflux_s, dflux_l, &      
+             tsurf_new, alb1, alb2, alb3, &
+             emis_new, z0m, z0h, qsurf)       
+                                                                             
+! +------------------------------------------------------------------------+   
+! |                                                                        |   
+! |   SubRoutine surf_inlandsis: Interfacing Lmdz AND Sisvat's Ice and Snow|
+! |                              (INLANDSIS)                               |
+! |   SISVAT (Soil/Ice Snow Vegetation Atmosphere Transfer Scheme)         |   
+! |   surface scheme of the Modele Atmospherique Regional (MAR)            |
+! |   Author: Heinz Juergen Punge, LSCE                June 2009           |
+! |     based on the MAR-SISVAT interface by Hubert Gallee                 |
+! |           Update Etienne Vignon, LMD, Novembre 2020                    |
+! |                                                                        |   
+! +------------------------------------------------------------------------+   
+! |   
+! |   In the current setup, SISVAT is used only to model the land ice      |
+! |   part of the surface; hence it is called with the compressed variables| 
+! |   from pbl_surface, and only by the surf_landice routine.              |
+! |                                                                        |   
+! |   In this interface it is assumed that the partitioning of the soil,   |
+! |   and hence the number of grid points is constant during a simulation, |
+! |   hence eg. snow properties remain stored in the global SISVAT         |
+! |   variables between the calls and don't need to be handed over as      |
+! |   arguments. When the partitioning is supposed to change, make sure to |
+! |   update the variables.                                                | 
+! |                                                                        |  
+! |   INPUT                                                                |  
+! |             SnoMod: Snow Pack is set up when .T.                       |  
+! |             reaLBC: Update Bound.Condit.when .T.                       |   
+! |                                                                        |  
+! |   INPUT    (via MODULES VARxSV, VARySV, VARtSV)                        |  
+! |   ^^^^^     xxxxSV: SISVAT/LMDZ interfacing variables                  |   
+! |                                                                        |  
+! |   Preprocessing  Option: SISVAT PHYSICS                                |   
+! |   ^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^                                |   
+! | #                       #HY                                            |   
+! | #                       #SN: Snow         Model                        |   
+! | #                       #BS: Blowing Snow Parameterization             |   
+! +------------------------------------------------------------------------+ 
+        
+    USE dimphy                                            
+    USE VAR_SV 
+    USE VARdSV 
+    USE VARxSV 
+    USE VARySV
+    USE VARtSV
+    USE VARphy
+    USE surface_data, only: iflag_tsurf_inlandsis,SnoMod,BloMod,ok_outfor                                       
+
+    IMPLICIT NONE    
+                                                                
+! +--INTERFACE Variables                                                     
+! +  =================== 
+                                            
+!    include  "dimsoil.h"                                     
+                                                                    
+
+! +--Global Variables                                                          
+! +  ================  
+! Input Variables for SISVAT
+    INTEGER,               INTENT(IN)      :: knon
+    INTEGER,               INTENT(IN)      :: itime   
+    REAL,                  INTENT(IN)      :: dtime 
+    LOGICAL,               INTENT(IN)      :: debut     ! true if first step
+    LOGICAL,               INTENT(IN)      :: lafin     ! true if last step
+
+    INTEGER, DIMENSION(klon), INTENT(IN)   :: ikl2i     ! Index Decompression
+    REAL, DIMENSION(klon), INTENT(IN)      :: rlon, rlat
+    REAL, DIMENSION(klon), INTENT(IN)      :: rmu0      ! cos sol. zenith angle
+    REAL, DIMENSION(klon), INTENT(IN)      :: swdown    !
+    REAL, DIMENSION(klon), INTENT(IN)      :: lwdown    ! 
+    REAL, DIMENSION(klon), INTENT(IN)      :: albedo_old    
+    REAL, DIMENSION(klon), INTENT(IN)      :: pexner    ! Exner potential
+    REAL, DIMENSION(klon), INTENT(IN)      :: precip_rain, precip_snow
+    REAL, DIMENSION(klon), INTENT(IN)      :: precip_snow_adv, snow_adv 
+                                                        !Snow Drift
+    REAL, DIMENSION(klon), INTENT(IN)      :: zsl_height, wind_velo
+    REAL, DIMENSION(klon), INTENT(IN)      :: temp_air, spechum, ps,p1lay
+    REAL, DIMENSION(klon), INTENT(IN)      :: dens_air, tsurf            
+    REAL, DIMENSION(klon), INTENT(IN)      :: rugos,snow_cont_air
+    REAL, DIMENSION(klon), INTENT(IN)      :: alb_soil, slope 
+    REAL, DIMENSION(klon), INTENT(IN)      :: cloudf   
+    REAL, DIMENSION(klon), INTENT(IN)      :: AcoefH, AcoefQ
+    REAL, DIMENSION(klon), INTENT(IN)      :: BcoefH, BcoefQ
+    REAL, DIMENSION(klon), INTENT(IN)      :: cdragm, cdragh
+    REAL, DIMENSION(klon), INTENT(IN)      :: ustar   ! friction velocity
+
+! Variables exchanged between LMDZ and SISVAT
+    REAL, DIMENSION(klon), INTENT(IN)      :: radsol    ! Surface absorbed rad.
+    REAL, DIMENSION(klon), INTENT(INOUT)   :: snow      ! Tot snow mass [kg/m2]
+    REAL, DIMENSION(klon), INTENT(INOUT)   :: zfra      ! snwo surface fraction [0-1]
+    REAL, DIMENSION(klon,nsoilmx), INTENT(OUT) :: tsoil ! Soil Temperature 
+    REAL, DIMENSION(klon), INTENT(OUT)       :: qsol      ! Soil Water Content  
+    REAL, DIMENSION(klon), INTENT(INOUT)     :: z0m    ! Momentum Roughn Lgt
+    REAL, DIMENSION(klon), INTENT(INOUT)     :: z0h    ! Momentum Roughn Lgt 
+
+
+! Output Variables for LMDZ
+    REAL, DIMENSION(klon), INTENT(OUT)     :: alb1      ! Albedo SW 
+    REAL, DIMENSION(klon), INTENT(OUT)     :: alb2,alb3 ! Albedo NIR and LW
+    REAL, DIMENSION(klon), INTENT(OUT)     :: emis_new  ! Surface Emissivity
+    REAL, DIMENSION(klon), INTENT(OUT)     :: runoff_lic ! Runoff            
+    REAL, DIMENSION(klon), INTENT(OUT)     :: dflux_s   ! d/dT sens. ht flux  
+    REAL, DIMENSION(klon), INTENT(OUT)     :: dflux_l   ! d/dT latent ht flux 
+    REAL, DIMENSION(klon), INTENT(OUT)     :: fluxsens  ! Sensible ht flux    
+    REAL, DIMENSION(klon), INTENT(OUT)     :: fluxlat   ! Latent heat flux
+    REAL, DIMENSION(klon), INTENT(OUT)     :: evap      ! Evaporation
+    REAL, DIMENSION(klon), INTENT(OUT)     :: agesno    ! Snow age (top layer)
+    REAL, DIMENSION(klon), INTENT(OUT)     :: tsurf_new ! Surface Temperature 
+    REAL, DIMENSION(klon), INTENT(OUT)     :: qsurf     ! Surface Humidity 
+
+! Specific INLANDIS outputs
+
+    REAL, DIMENSION(klon), INTENT(OUT)     :: qsnow     ! Total H2O snow[kg/m2]
+    REAL, DIMENSION(klon), INTENT(OUT)     :: snowhgt   ! Snow height (m)
+    REAL, DIMENSION(klon), INTENT(OUT)     :: to_ice    ! Snow passed to ice 
+    REAL, DIMENSION(klon), INTENT(OUT)     :: sissnow   ! Snow in model (kg/m2)
+
+                                                                          
+
+                                                                    
+! +--Internal  Variables                                                       
+! +  ===================                                          
+
+    CHARACTER(len=20)               :: fn_outfor ! Name for output file
+    INTEGER                         :: i, ig, ikl, isl, isn, nt
+    INTEGER                         :: gp_outfor, un_outfor
+    REAL, PARAMETER                 :: f1=0.5
+    REAL, PARAMETER                 :: sn_upp=5000.,sn_low=500.
+    REAL, PARAMETER                 :: sn_add=400.,sn_div=2.
+                                             ! snow mass upper,lower limit, 
+                                             ! added mass/division lowest layer
+    REAL, PARAMETER                 :: c1_zuo=12.960e+4, c2_zuo=2.160e+6
+    REAL, PARAMETER                 :: c3_zuo=1.400e+2,  czemin=1.e-3  
+                                             ! Parameters for drainage
+! c1_zuo/ 2.796e+4/,c2_zuo/2.160e+6/,c3_zuo/1.400e+2/ !     Tuning
+! +...        Run Off Parameters                                              
+! +           86400*1.5 day     ...*25 days (Modif. ETH Camp: 86400*0.3day)    
+! +           (Zuo and Oerlemans 1996, J.Glacio. 42, 305--317)             
+
+    REAL, DIMENSION(klon)           :: eps0SL          ! surface Emissivity 
+    REAL                            :: zsigma, Ua_min, Us_min
+    REAL                            :: lambda          ! Par. soil discret.
+    REAL, DIMENSION(nsoilmx), SAVE  :: dz1,dz2         ! Soil layer thicknesses
+!$OMP THREADPRIVATE(dz1,dz2)
+    LOGICAL, SAVE                   :: firstcall
+!$OMP THREADPRIVATE(firstcall)                
+
+               
+                                        
+! +--Internal Variables
+! +  ==================
+
+    INTEGER                         ::  iso
+    LOGICAL                         ::  file_exists
+    CHARACTER(len=20)               ::  fichnom
+!========================================================================
+
+      PRINT*, 'je rentre dans inlandsis'
+
+      zsigma=1000.
+      dt__SV=dtime
+      
+    
+
+!     write(*,*)'Start of simulation? ',debut        !hj
+
+      IF (debut) THEN 
+        firstcall=.TRUE. 
+        INI_SV=.false.
+
+      ELSE
+        firstcall=.false.
+        INI_SV=.true.
+      END IF
+
+
+
+
+       IF (ok_outfor) THEN
+        un_outfor=51                 ! unit number for point output file
+        gp_outfor= 1        ! grid point number for point output
+        fn_outfor='outfor_SV.dat'
+       END IF
+
+! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+
+
+! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+! + INITIALISATION: BEGIN +++ 
+! + -------------------------
+! +
+! + Compute soil discretization (as for LMDZ)
+! + -----------------------------------------  
+      IF (firstcall) THEN
+
+! +--Array size
+     klonv=klon
+     knonv=knon
+
+
+        write(*,*)'klon',klon,'klonv',klonv,'knon',knon,'nsol',nsol,'nsno',nsno
+
+
+        CALL INIT_VARtSV
+        CALL INIT_VARxSV
+        CALL INIT_VARySV
+
+        eps0SL(:)=0.
+        
+        
+! +--Soil layer thickness                                                   
+! +  -----------------------  
+!        write(*,'(/a)') 'Start SISVAT init: soil discretization ', nsoilmx
+        CALL get_soil_levels(dz1,dz2,lambda)
+
+        
+        lambSV=lambda
+        dz1_SV(1:knon,1:) = 0.     
+        dz2_SV(1:knon,1:) = 0.
+                      
+        DO isl =   -nsol,0   
+          dz_dSV(isl) = 0.5e-3*dz2(1-isl)           ! Soil layer thickness 
+          DO ikl=1,knon
+            dz1_SV(ikl,isl) = dz1(1-isl)    !1.e-3* 
+            dz2_SV(ikl,isl) = dz2(1-isl)    !1.e-3*
+          END DO
+
+        END DO
+
+
+
+
+        DO ikl=1,knon     
+
+
+! Initialise variables
+          
+          ispiSV(ikl)             = 0 
+          iiceSV(ikl)             = 0  
+          rusnSV(ikl)             = 0.   
+          toicSV(ikl)             = 0.     
+          isnoSV(ikl)             = 0.       ! # snow layers                            
+          istoSV(ikl,:)           = 0. 
+          eta_SV(ikl,:)           = 0.     
+          TsisSV(ikl,:)           = 0.
+          ro__SV(ikl,:)           = 0.        
+          G1snSV(ikl,:)           = 0.  
+          G2snSV(ikl,:)           = 0. 
+          agsnSV(ikl,:)           = 0. 
+          dzsnSV(ikl,:)           = 0. 
+          zzsnsv(ikl,:)           = 0.                                           
+          BufsSV(ikl)             = 0.    
+          qsnoSV(ikl)             = 0.     ! BL snow content  
+          zWEcSV(ikl)             = 0.
+          dbs_SV(ikl)             = 0.
+          dsnbSV(ikl)             = 0.
+          esnbSV(ikl)             = 0.
+          BrosSV(ikl)             = 0.
+          BG1sSV(ikl)             = 0.          
+          BG2sSV(ikl)             = 0.
+          SWS_SV(ikl)             = 0.
+          RnofSV(ikl)             = 0.     ! RunOFF Intensity 
+          RRs_SV(ikl)             = 0.
+          DDs_SV(ikl)             = 0.
+          VVs_SV(ikl)             = 0.
+          cld_SV(ikl)             = 0.      
+          uts_SV(ikl)             = 0.     ! u*T*  arbitrary  
+          uqs_SV(ikl)             = 0.     ! u*q*    " 
+          uss_SV(ikl)             = 0.     ! u*s*    "
+          LMO_SV(ikl)             = 0.
+
+
+! Set variables 
+
+          LSmask(ikl) = 1                          ! Land/Sea   Mask    
+          isotSV(ikl) = 12                         ! Soil       Type  -> 12= ice  
+          iWaFSV(ikl) = 1                          ! Soil Drainage                                     
+          eps0SL(ikl )= 1.
+          alb0SV(ikl) = alb_soil(ikl)                 ! Soil Albedo        
+          Z0m_SV(ikl) = z0m(ikl)                      ! Moment.Roughn.L.
+          Z0h_SV(ikl) = z0h(ikl)                      ! heat Roughn.L.
+
+! + Soil Upward IR Flux, Water Fluxes, roughness length  
+          IRs_SV(ikl) =                               &
+              -eps0SL(ikl)* StefBo*(temp_air(ikl)**4)   ! Upward IR Flux    
+          Tsf_SV(ikl) = min(temp_air(ikl),TfSnow)       
+          
+! + Soil
+        DO isl =   -nsol,0    
+          TsisSV(ikl,isl) = min(tsoil(ikl,1+nsol),TfSnow-0.2)   !temp_air(ikl)  !tsoil(ikl,1-isl)   Soil Temperature
+          !TsisSV(ikl,isl) = min(temp_air(ikl),TfSnow-0.2)
+          eta_SV(ikl,isl) = epsi                        !etasoil(ikl,1-isl) Soil Water[m3/m3]
+          ro__SV(ikl,isl) = rhoIce                         !rosoil(ikl,1-isl)  volumic mass
+        END DO      
+
+
+
+!! Initialise with snow
+          !  G1snSV(ikl,0)          = 0.                   !      [-]     
+          !  G2snSV(ikl,0)          = 1.6                  ! [-] [0.0001 m] 
+          !  dzsnSV(ikl,0)          = dz_dSV(0)            !           [m] 
+
+
+          ! if (snow(ikl) .GT. 0.) then
+          !   isnoSV(ikl)             = 1       ! snow layers                            
+          !   istoSV(ikl,1:nsno)      = 0     ! 0,...,5 :   Snow     History (see istdSV data)
+          !   eta_SV(ikl,1:nsno)      = epsi     
+          !   TsisSV(ikl,1:nsno)      = tsoil(ikl,1)         
+          !   ro__SV(ikl,1:nsno)      = 350.0       
+          !   G1snSV(ikl,1:nsno)      = 0.   !      [-]  
+          !   G2snSV(ikl,1:nsno)      = 1.6   !     [-] [0.0001 m] 
+          !   agsnSV(ikl,1:nsno)      = 50.   !          [day] 
+          !   dzsnSV(ikl,1)           = snow(ikl)/max(ro__SV(ikl,1),epsi) ![m] 
+! ! ecrete si trop de neige:
+!              IF (snow(ikl) .ge. sn_upp) THEN  !thinnen snow layer below
+!               dzsnSV(ikl,1)      = dzsnSV(ikl,1)/sn_div
+!               toicSV(ikl) = toicSV(ikl)+dzsnSV(ikl,1)*ro__SV(ikl,1)/sn_div
+!              END IF
+!            zzsnsv(ikl,1)      =  dzsnSV(ikl,1)                    ! Total snow pack thickness
+!          endif
+
+
+! Initialise la neige avec un profil de densité prochde des conditions de Dôme C (~10m de neige avec 19 niveaux) (Etienne):
+          isnoSV(ikl)                    = 19
+          istoSV(ikl,1:isnoSV(ikl))      = 100
+          ro__SV(ikl,1:isnoSV(ikl))      = 350.      
+          eta_SV(ikl,1:isnoSV(ikl))      = epsi
+          TsisSV(ikl,1:isnoSV(ikl))      = min(tsoil(ikl,1),TfSnow-0.2)
+          G1snSV(ikl,1:isnoSV(ikl))      = 0
+          G2snSV(ikl,1:isnoSV(ikl))      = 1.6 
+          agsnSV(ikl,1:isnoSV(ikl))      = 50.    
+          dzsnSV(ikl,19)                  = 0.015
+          dzsnSV(ikl,18)                  =0.015
+          dzsnSV(ikl,17)                  =0.020
+          dzsnSV(ikl,16)                  =0.030
+          dzsnSV(ikl,15)                  =0.040
+          dzsnSV(ikl,14)                  =0.060
+          dzsnSV(ikl,13)                  =0.080
+          dzsnSV(ikl,12)                  =0.110
+          dzsnSV(ikl,11)                  =0.150
+          dzsnSV(ikl,10)                  =0.200
+          dzsnSV(ikl,9)                   =0.300
+          dzsnSV(ikl,8)                   =0.420
+          dzsnSV(ikl,7)                   =0.780
+          dzsnSV(ikl,6)                   =1.020
+          dzsnSV(ikl,5)                   =0.980
+          dzsnSV(ikl,4)                   =1.020
+          dzsnSV(ikl,3)                   =3.970
+          dzsnSV(ikl,2)                   =1.020
+          dzsnSV(ikl,1)                   =0.100
+
+
+        END DO                                            
+
+! +--Surface Fall Line Slope                                                   
+! +  -----------------------  
+        IF (SnoMod)  THEN                
+          DO ikl=1,knon  
+            slopSV(ikl) = slope(ikl)
+            SWf_SV(ikl) =             &   ! Normalized Decay of the  
+              exp(-dt__SV             &   ! Surficial Water Content  
+              /(c1_zuo                &   !(Zuo and Oerlemans 1996,  
+            +c2_zuo*exp(-c3_zuo*abs(slopSV(ikl)))))  ! J.Glacio. 42, 305--317)
+          END DO                                     
+        END IF                            
+
+! + SISVAT_ini (as for use with MAR, but not computing soil layers)
+! + -------------------------------------------------------------
+!        write(*,'(/a)') 'Start SISVAT initialization: SISVAT_ini' 
+        CALL SISVAT_ini(knon)
+
+
+! +--Read restart file
+! +  =================================================   
+        
+        INQUIRE(FILE="startsis.nc", EXIST=file_exists)
+        IF (file_exists) THEN
+        CALL sisvatetat0("startsis.nc",ikl2i)
+        END IF
+        
+        
+        
+! +--Output ascii file
+! +  =================================================   
+               
+        
+        
+        ! open output file 
+        IF (ok_outfor) THEN
+          open(unit=un_outfor,status='replace',file=fn_outfor)         
+          ikl=gp_outfor     ! index sur la grille land ice
+          write(un_outfor,*) fn_outfor, ikl, dt__SV   
+          write(un_outfor,*) 'nsnow - albedo - z0m - z0h , dz [m,35], temp [K,46], rho [kg/m3,46], eta [kg/kg,46] &
+           & G1 [-,35], G2 [-,35], agesnow [d,35], history [-,35]'
+
+        END IF
+ 
+      END IF  ! firstcall                        
+! +                                
+! +  +++  INITIALISATION:  END  +++                               
+! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+
+! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+! + READ FORCINGS  
+! + ------------------------ 
+
+! + Update Forcings for SISVAT given by the LMDZ model.
+! +
+      DO ikl=1,knon
+
+! +--Atmospheric Forcing                                    (INPUT)            
+! +  ^^^^^^^^^^^^^^^^^^^                                     ^^^^^ 
+        zSBLSV      = 1000.                         ! [m]                
+        za__SV(ikl) = zsl_height(ikl)               ! surface layer height (fisr model level) [m]
+        Ua_min      = epsi                          !
+        Ua_min      = 0.2 * sqrt(za__SV(ikl)   )    !                    
+        VV__SV(ikl) = max(Ua_min, wind_velo(ikl))   ! Wind velocity       [m/s]
+        TaT_SV(ikl) = temp_air(ikl)                 ! BL top Temperature    [K]
+        ExnrSV(ikl) = pexner(ikl)                   ! Exner potential          
+        rhT_SV(ikl) = dens_air(ikl)                 ! Air density           
+        QaT_SV(ikl) = spechum(ikl)                  ! Specific humidity 
+        ps__SV(ikl) = ps(ikl)                       ! surface pressure     [Pa]
+        p1l_SV(ikl) = p1lay(ikl)                    ! lowest atm. layer press[Pa]
+
+! +--Surface properties
+! +  ^^^^^^^^^^^^^^^^^^
+
+        Z0m_SV(ikl) = z0m(ikl)                      ! Moment.Roughn.L.
+        Z0h_SV(ikl) = z0h(ikl)                      ! Moment.Roughn.L.
+
+! +--Energy Fluxes                                          (INPUT)           
+! +  ^^^^^^^^^^^^^                                           ^^^^^             
+        coszSV(ikl) = max(czemin,rmu0(ikl))         ! cos(zenith.Dist.)  
+        sol_SV(ikl) = swdown(ikl)                   ! downward Solar  
+        IRd_SV(ikl) = lwdown(ikl)                   ! downward IR    
+        rsolSV(ikl) = radsol(ikl)                   ! surface absorbed rad.   
+
+! +--Water  Fluxes                                          (INPUT)           
+! +  ^^^^^^^^^^^^^                                           ^^^^^             
+        drr_SV(ikl) = precip_rain(ikl)              ! Rain fall rate  [kg/m2/s]
+        dsn_SV(ikl) = precip_snow(ikl)              ! Snow fall rate  [kg/m2/s]
+!c #BS  dbsnow      = -SLussl(i,j,n)                ! Erosion    
+!c #BS.               *dtPhys     *rhT_SV(ikl) /ro_Wat                    
+!c #BS  dsnbSV(ikl) = snow_adv(ikl)  ! min(max(zero,dbsnow)              
+!c #BS.                    /    max(epsi,d_snow),unun)                    
+!c #BS  dbs_SV(ikl) = snow_cont_air(ikl)
+!c #BS                  blowSN(i,j,n)               !          [kg/m2]  
+                                                                              
+! +--Soil/BL                                      (INPUT)            
+! +  ^^^^^^^                                       ^^^^^            
+        alb0SV(ikl) = alb_soil(ikl)                 ! Soil background Albedo 
+        AcoHSV(ikl) = AcoefH(ikl)  
+        BcoHSV(ikl) = BcoefH(ikl)                     
+        AcoQSV(ikl) = AcoefQ(ikl)  
+        BcoQSV(ikl) = BcoefQ(ikl)             
+        cdH_SV(ikl) = cdragh(ikl)     
+        cdM_SV(ikl) = cdragm(ikl)     
+        Us_min      = 0.01
+        us__SV(ikl) = max(Us_min, ustar(ikl)) 
+        ram_sv(ikl) = 1./(cdragm(ikl)*max(VV__SV(ikl),eps6))
+        rah_sv(ikl) = 1./(cdragh(ikl)*max(VV__SV(ikl),eps6))   
+
+! +--Energy Fluxes                                          (INPUT/OUTPUT)    
+! +  ^^^^^^^^^^^^^                                           ^^^^^^^^^^^^    
+        IF (.not.firstcall) THEN  
+        Tsf_SV(ikl) = tsurf(ikl)                     !hj 12 03 2010
+        cld_SV(ikl) = cloudf(ikl)                    ! Cloudiness         
+        END IF
+ 
+
+      END DO
+
+!                            
+! +  +++  READ FORCINGS:  END  +++    
+! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+
+! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+! +--SISVAT EXECUTION                                                          
+! +  ----------------                                                          
+
+      call  INLANDSIS(SnoMod,BloMod,1) 
+
+! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+! + RETURN RESULTS  
+! + -------------- 
+! + Return (compressed) SISVAT variables to LMDZ             
+! + 
+      DO  ikl=1,knon                  ! use only 1:knon (actual ice sheet..) 
+        runoff_lic(ikl)    = RnofSV(ikl)*dtime   ! RunOFF: intensity* time step
+        dflux_s(ikl)       = dSdTSV(ikl)         ! Sens.H.Flux T-Der. 
+        dflux_l(ikl)       = dLdTSV(ikl)         ! Latn.H.Flux T-Der. 
+        fluxsens(ikl)      = HSs_sv(ikl)         ! HS                 
+        fluxlat(ikl)       = HLs_sv(ikl)         ! HL                 
+        evap(ikl)          = HLs_sv(ikl)/LHvH2O  ! Evaporation  
+        snow(ikl)          = 0.
+        snowhgt(ikl)       = 0.
+        qsnow(ikl)         = 0.
+        qsol(ikl)          = 0. 
+! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+! +
+! +   Check snow thickness,  substract if too thick   (commended by etienne: add if too thin) 
+
+        sissnow(ikl)       = 0.  !()
+      DO  isn = 1,isnoSV(ikl)                                               
+        sissnow(ikl)       = sissnow(ikl)+dzsnSV(ikl,isn)* ro__SV(ikl,isn)   
+      END DO
+
+       IF (sissnow(ikl) .LE. sn_low) THEN  !add snow 
+       IF (isnoSV(ikl).GE.1) THEN
+         dzsnSV(ikl,1)      = dzsnSV(ikl,1) + sn_add/max(ro__SV(ikl,1),epsi)  
+         toicSV(ikl)        = toicSV(ikl)   - sn_add
+!       ELSE
+!         write(*,*) 'Attention, bare ice... point ',ikl
+!         isnoSV(ikl)        = 1
+!         istoSV(ikl,1)      = 0
+!         ro__SV(ikl,1)      = 350.      
+!         dzsnSV(ikl,1)      = sn_add/max(ro__SV(ikl,1),epsi)  ! 1.
+!         eta_SV(ikl,1)      = epsi
+!         TsisSV(ikl,1)      = min(TsisSV(ikl,0),TfSnow-0.2)   
+!         G1snSV(ikl,1)      = 0.
+!         G2snSV(ikl,1)      = 0.3 
+!         agsnSV(ikl,1)      = 10.    
+!         toicSV(ikl)        = toicSV(ikl)   - sn_add
+       END IF
+       END IF
+
+      IF (sissnow(ikl) .ge. sn_upp) THEN  !thinnen snow layer below
+        dzsnSV(ikl,1)      = dzsnSV(ikl,1)/sn_div
+        toicSV(ikl) = toicSV(ikl)+dzsnSV(ikl,1)*ro__SV(ikl,1)/sn_div
+      END IF
+
+        sissnow(ikl)       = 0.  !()
+
+        DO  isn = 1,isnoSV(ikl)                                               
+        sissnow(ikl) = sissnow(ikl)+dzsnSV(ikl,isn)* ro__SV(ikl,isn)           
+        snowhgt(ikl) = snowhgt(ikl)+dzsnSV(ikl,isn)              
+        qsnow(ikl)   = qsnow(ikl)+1e03*eta_SV(ikl,isn)*dzsnSV(ikl,isn)   
+        END DO
+
+        ! Etienne: pourquoi ajouter toicSV ici? Pour bilan d'eau?
+        snow(ikl)    = sissnow(ikl)+toicSV(ikl)
+        to_ice(ikl)  = toicSV(ikl)
+
+
+      DO  isl =   -nsol,0    
+        tsoil(ikl,1-isl)   = TsisSV(ikl,isl)       ! Soil Temperature  
+        qsol(ikl)          = qsol(ikl)                      &    
+                            +eta_SV(ikl,isl) * dz_dSV(isl)  
+      END DO                                               
+        agesno(ikl)        = agsnSV(ikl,isnoSV(ikl))        !          [day] 
+
+        alb1(ikl)          = alb1sv(ikl)             ! Albedo VIS  
+        alb2(ikl)          = ((So1dSV-f1)*alb1sv(ikl)                   &
+     &                       +So2dSV*alb2sv(ikl)+So3dSV*alb3sv(ikl))/f1    
+                                                     ! Albedo NIR 
+        alb3(ikl)          = alb3sv(ikl)             ! Albedo FIR  
+
+        tsurf_new(ikl)     =Tsrfsv(ikl)
+
+        zfra(ikl)          = max(min(isnoSV(ikl)-iiceSV(ikl),1),0)
+        qsurf(ikl)         = QaT_SV(ikl) 
+        emis_new(ikl)      = eps0SL(ikl)  
+        z0m(ikl)           = Z0m_SV(ikl) 
+        z0h(ikl)           = Z0h_SV(ikl) 
+
+      END DO  ! ikl
+      
+
+
+
+
+
+! write variables in output file
+
+      IF (ok_outfor) THEN
+        ikl=gp_outfor
+
+!        write(un_outfor,*) 'nsnow [-,1], dz [m,35], temp [K,46], rho [kg/m3,46], eta [kg/kg,46]'
+!        write(un_outfor,*) 'G1 [-,35], G2 [-,35], agesnow [d,35], history [-,35]'
+        write(un_outfor,*) '+++++++++++++++++++++++++++++++++++++++++++++++'
+        write(un_outfor,*) isnoSV(ikl), alb_SV(ikl), Z0m_SV(ikl), Z0h_SV(ikl)
+        write(un_outfor,*) dzsnSV(ikl,:)
+        write(un_outfor,*) TsisSV(ikl,:)
+        write(un_outfor,*) ro__SV(ikl,:)
+        write(un_outfor,*) eta_SV(ikl,:)
+        write(un_outfor,*) G1snSV(ikl,:)
+        write(un_outfor,*) G2snSV(ikl,:)
+        write(un_outfor,*) agsnSV(ikl,:)
+        write(un_outfor,*) istoSV(ikl,:)
+       
+      ENDIF
+
+
+
+
+! +  -----------------------------                              
+! +  END --- RETURN RESULTS    
+! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      IF (lafin) THEN
+        fichnom = "restartsis.nc"
+        CALL sisvatredem("restartsis.nc",ikl2i,rlon,rlat)     
+        
+        IF (ok_outfor) THEN
+          close(unit=un_outfor)                    
+        END IF 
+      END IF                                                          
+
+
+  END SUBROUTINE surf_inlandsis
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+!=======================================================================
+
+  SUBROUTINE get_soil_levels(dz1, dz2, lambda)
+! ======================================================================
+! Routine to compute the vertical discretization of the soil in analogy
+! to LMDZ. In LMDZ it is done in soil.F, which is not used in the case 
+! of SISVAT, therefore it's needed here.
+!
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    USE mod_phys_lmdz_para
+    USE VAR_SV 
+
+
+!    INCLUDE "dimsoil.h"
+
+    REAL, DIMENSION(nsoilmx), INTENT(OUT) :: dz2, dz1
+    REAL, INTENT(OUT)                     :: lambda
+
+
+!-----------------------------------------------------------------------
+!   Depthts:
+!   --------
+    REAL fz,rk,fz1,rk1,rk2
+    REAL min_period, dalph_soil
+    INTEGER ierr,jk
+
+    fz(rk)=fz1*(dalph_soil**rk-1.)/(dalph_soil-1.)
+
+!    write(*,*)'Start soil level computation' 
+!-----------------------------------------------------------------------
+! Calculation of some constants
+! NB! These constants do not depend on the sub-surfaces
+!-----------------------------------------------------------------------
+!-----------------------------------------------------------------------
+!   ground levels 
+!   grnd=z/l where l is the skin depth of the diurnal cycle:
+!-----------------------------------------------------------------------
+
+     min_period=1800. ! en secondes
+     dalph_soil=2.    ! rapport entre les epaisseurs de 2 couches succ.
+! !$OMP MASTER
+!     IF (is_mpi_root) THEN
+!        OPEN(99,file='soil.def',status='old',form='formatted',iostat=ierr)
+!        IF (ierr == 0) THEN ! Read file only if it exists
+!           READ(99,*) min_period
+!           READ(99,*) dalph_soil
+!           PRINT*,'Discretization for the soil model'
+!           PRINT*,'First level e-folding depth',min_period, &
+!                '   dalph',dalph_soil
+!           CLOSE(99)
+!        END IF
+!     ENDIF
+! !$OMP END MASTER
+!     CALL bcast(min_period)
+!     CALL bcast(dalph_soil)
+
+!   la premiere couche represente un dixieme de cycle diurne
+     fz1=SQRT(min_period/3.14)
+     
+     DO jk=1,nsoilmx
+        rk1=jk
+        rk2=jk-1
+        dz2(jk)=fz(rk1)-fz(rk2) 
+     ENDDO
+     DO jk=1,nsoilmx-1
+        rk1=jk+.5
+        rk2=jk-.5
+        dz1(jk)=1./(fz(rk1)-fz(rk2))
+     ENDDO
+     lambda=fz(.5)*dz1(1)
+     PRINT*,'full layers, intermediate layers (seconds)'
+     DO jk=1,nsoilmx
+        rk=jk
+        rk1=jk+.5
+        rk2=jk-.5
+        PRINT *,'fz=', &
+             fz(rk1)*fz(rk2)*3.14,fz(rk)*fz(rk)*3.14
+     ENDDO
+
+  END SUBROUTINE get_soil_levels
+  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+!===========================================================================
+
+  SUBROUTINE SISVAT_ini(knon)                                                     
+                                                                               
+!C +------------------------------------------------------------------------+  
+!C | MAR          SISVAT_ini                             Jd 11-10-2007  MAR | 
+!C |   SubRoutine SISVAT_ini generates non time dependant SISVAT parameters |  
+!C +------------------------------------------------------------------------+  
+!C |   PARAMETERS:  klonv: Total Number of columns =                        |  
+!C |   ^^^^^^^^^^        = Total Number of continental     grid boxes       |  
+!C |                     X       Number of Mosaic Cell per grid box         |  
+!C |                                                                        |  
+!C |   INPUT:   dt__SV   : Time  Step                                   [s] | 
+!C |   ^^^^^    dz_dSV   : Layer Thickness                              [m] |  
+!C |                                                                        |  
+!C |   OUTPUT:             [-] |  
+!C |   ^^^^^^   rocsSV   : Soil Contrib. to (ro c)_s exclud.Water  [J/kg/K] |  
+!C |            etamSV   : Soil Minimum Humidity                    [m3/m3] |  
+!C |                      (based on a prescribed Soil Relative Humidity)    |  
+!C |            s1__SV   : Factor of eta**( b+2) in Hydraul.Diffusiv.       |  
+!C |            s2__SV   : Factor of eta**( b+2) in Hydraul.Conduct.        |  
+!C |            aKdtSV   : KHyd: Piecewise Linear Profile:  a * dt    [m]   |  
+!C |            bKdtSV   : KHyd: Piecewise Linear Profile:  b * dt    [m/s] |  
+!C |            dzsnSV(0): Soil first Layer Thickness                   [m] |  
+!C |            dzmiSV   : Distance between two contiguous levels       [m] |  
+!C |            dz78SV   : 7/8 (Layer Thickness)                        [m] | 
+!C |            dz34SV   : 3/4 (Layer Thickness)                        [m] | 
+!C |            dz_8SV   : 1/8 (Layer Thickness)                        [m] | 
+!C |            dzAvSV   : 1/8  dz_(i-1) + 3/4 dz_(i) + 1/8 dz_(i+1)    [m] | 
+!C |            dtz_SV   : dt/dz                                      [s/m] | 
+!C |            OcndSV   : Swab Ocean / Soil Ratio                      [-] |
+!C |            Implic   : Implicit Parameter  (0.5:  Crank-Nicholson)      |  
+!C |            Explic   : Explicit Parameter = 1.0 - Implic                |  
+!C |                                                                        | 
+!C | # OPTIONS: #ER: Richards Equation is not smoothed                      |
+!C | # ^^^^^^^  #kd: De Ridder   Discretization                             |
+!C | #          #SH: Hapex-Sahel Values                                     !  
+!C |                                                                        | 
+!C +------------------------------------------------------------------------+  
+!                                                                              
+!                                                                             
+                                                                              
+!C +--Global Variables                                                         
+!C +  ================         
+
+      USE dimphy
+      USE VARphy                                           
+      USE VAR_SV                                                     
+      USE VARdSV                                                         
+      USE VAR0SV                                                           
+      USE VARxSV
+      USE VARtSV
+      USE VARxSV
+      USE VARySV
+      IMPLICIT NONE                                                           
+                                                                              
+                                                                              
+                                                                              
+!C +--Arguments                                                     
+!C +  ==================                                                      
+       INTEGER,INTENT(IN) ::  knon                                       
+
+!C +--Internal Variables                                                     
+!C +  ==================                                                      
+                                                                               
+      INTEGER ::  ivt   ,ist   ,ikl   ,isl   ,isn   ,ikh               
+      INTEGER ::  misl_2,nisl_2                                              
+      REAL    ::  d__eta,eta__1,eta__2,Khyd_1,Khyd_2                           
+      REAL,PARAMETER  ::  RHsMin=  0.001        ! Min.Soil Relative Humidity   
+      REAL    ::  PsiMax                        ! Max.Soil Water    Potential 
+      REAL    ::  a_Khyd,b_Khyd                 ! Piecewis.https://www.lequipe.fr/Water Conductivity 
+
+
+!c #WR REAL    ::  Khyd_x,Khyd_y                                               
+                                                                              
+                                                                              
+                                                                 
+!C +--Non Time Dependant SISVAT parameters                                    
+!C +  ====================================                                
+                                                                              
+!C +--Soil Discretization                                                     
+!C +  -------------------                                                     
+                                                                              
+!C +--Numerical Scheme Parameters                                             
+!C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^                                             
+        Implic = 0.75                           ! 0.5  <==> Crank-Nicholson  
+        Explic = 1.00 - Implic                  !                            
+                                                                             
+!C +--Soil/Snow Layers Indices                                                
+!C +  ^^^^^^^^^^^^^^^^^^^^^^^^                                                
+      DO  isl=-nsol,0                                                          
+        islpSV(isl) =           isl+1                                         
+        islpSV(isl) = min(      islpSV(isl),0)                                
+        islmSV(isl) =           isl-1                                         
+        islmSV(isl) = max(-nsol,islmSV(isl))                                 
+      END DO                                                                  
+                                                                               
+      DO  isn=1,nsno                                                           
+        isnpSV(isn) =           isn+1                                          
+        isnpSV(isn) = min(      isnpSV(isn),nsno)                            
+      END DO                                                                 
+                                                                              
+!C +--Soil      Layers Thicknesses                                             
+!C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
+! Not used here as LMDZ method is applied, see SUBROUTINE get_soil_levels!    
+!c #kd IF (nsol.gt.4)                                              THEN        
+!c #kd   DO isl=-5,-nsol,-1                                                    
+!c #kd     dz_dSV(isl)=   1.                                                  
+!c #kd   END DO                                                                
+!c #kd END IF                                                                 
+!                                                                             
+!      IF (nsol.ne.4)                                              THEN        
+!        DO isl= 0,-nsol,-1                                                   
+!          misl_2 =     -mod(isl,2)                                          
+!          nisl_2 =         -isl/2                                            
+!          dz_dSV(isl)=(((1-misl_2) * 0.001                                   
+!     .                  +  misl_2  * 0.003) * 10**(nisl_2)) * 4.             
+!C +...    dz_dSV(0)  =         Hapex-Sahel Calibration:       4 mm            
+!                                                                             
+!c +SH     dz_dSV(isl)=(((1-misl_2) * 0.001                                   
+!c +SH.                  +  misl_2  * 0.003) * 10**(nisl_2)) * 1.              
+!                                                                             
+!c #05     dz_dSV(isl)=(((1-misl_2) * 0.001                                    
+!c #05.                  +  misl_2  * 0.008) * 10**(nisl_2)) * 0.5             
+!        END DO                                                                
+!          dz_dSV(0)  =               0.001                                    
+!          dz_dSV(-1) = dz_dSV(-1)  - dz_dSV(0)              + 0.004         
+!      END IF           
+
+                                                                               
+        zz_dSV      = 0.                                                      
+      DO  isl=-nsol,0                                                        
+        dzmiSV(isl) = 0.500*(dz_dSV(isl)        +dz_dSV(islmSV(isl)))        
+        dziiSV(isl) = 0.500* dz_dSV(isl)        /dzmiSV(isl)                  
+        dzi_SV(isl) = 0.500* dz_dSV(islmSV(isl))/dzmiSV(isl)                   
+        dtz_SV(isl) =        dt__SV             /dz_dSV(isl)  
+        dtz_SV2(isl) =        1.            /dz_dSV(isl)                          
+        dz78SV(isl) = 0.875* dz_dSV(isl)                                      
+        dz34SV(isl) = 0.750* dz_dSV(isl)                                      
+        dz_8SV(isl) = 0.125* dz_dSV(isl)                                       
+        dzAvSV(isl) = 0.125* dz_dSV(islmSV(isl))                        &
+     &              + 0.750* dz_dSV(isl)                                &
+     &              + 0.125* dz_dSV(islpSV(isl))                                                              
+        zz_dSV      = zz_dSV+dz_dSV(isl)                                      
+      END DO                                                                  
+      DO ikl=1,knon !v                                                          
+        dzsnSV(ikl,0) =      dz_dSV(0)                                        
+      END DO                                                                  
+                                                                              
+!C +--Conversion to a 50 m Swab Ocean Discretization                           
+!C +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                           
+        OcndSV = 0.                                                           
+      DO isl=-nsol,0                                                          
+        OcndSV = OcndSV +dz_dSV(isl)                                           
+      END DO                                                                   
+        OcndSV = 50.    /OcndSV                                                
+                                                                                                            
+                                                                                                                                                                                                                                
+!C +--Secondary Soil       Parameters                                          
+!C +  -------------------------------                                         
+                                                                               
+      DO  ist=0,nsot                                                           
+         rocsSV(ist)=(1.0-etadSV(ist))*1.2E+6   ! Soil Contrib. to (ro c)_s    
+         s1__SV(ist)=     bCHdSV(ist)          & ! Factor of (eta)**(b+2)     
+     &  *psidSV(ist)     *Ks_dSV(ist)          & !    in DR97, Eqn.(3.36)     
+     & /(etadSV(ist)**(   bCHdSV(ist)+3.))     !                              
+         s2__SV(ist)=     Ks_dSV(ist)          & ! Factor of (eta)**(2b+3)     
+     & /(etadSV(ist)**(2.*bCHdSV(ist)+3.))     !    in DR97, Eqn.(3.35)       
+                                                                             
+!C +--Soil Minimum Humidity (from a prescribed minimum relative Humidity)     
+!C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    
+         Psimax = -(log(RHsMin))/7.2E-5        ! DR97, Eqn 3.15 Inversion   
+         etamSV(ist) =  etadSV(ist)                                      &
+     &         *(PsiMax/psidSV(ist))**(-min(10.,1./bCHdSV(ist)))             
+      END DO                                                                  
+         etamSV(12)  =  0.                                                   
+                                                                             
+!C +--Piecewise Hydraulic Conductivity Profiles                               
+!C +  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                               
+      DO   ist=0,nsot                                                          
+ 
+                                                                             
+          d__eta          =  etadSV(ist)/nkhy                                 
+          eta__1          =  0.                                              
+          eta__2          =  d__eta                                           
+        DO ikh=0,nkhy                                                         
+          Khyd_1          =  s2__SV(ist)             & ! DR97, Eqn.(3.35)      
+     &  *(eta__1      **(2. *bCHdSV(ist)+3.))        !                       
+          Khyd_2          =  s2__SV(ist)             &!                       
+     &  *(eta__2      **(2. *bCHdSV(ist)+3.))        !                       
+                                                                             
+          a_Khyd          = (Khyd_2-Khyd_1)/d__eta   !                       
+          b_Khyd          =  Khyd_1-a_Khyd *eta__1   !                       
+!c #WR     Khyd_x          =  a_Khyd*eta__1 +b_Khyd   !                       
+!c #WR     Khyd_y          =  a_Khyd*eta__2 +b_Khyd   !                       
+          aKdtSV(ist,ikh) =  a_Khyd       * dt__SV   !                       
+          bKdtSV(ist,ikh) =  b_Khyd       * dt__SV   !                         
+               
+          eta__1          = eta__1  + d__eta                              
+          eta__2          = eta__2  + d__eta                              
+        END DO                                                             
+      END DO                                                               
+
+                                                                           
+      return                                                               
+
+  END SUBROUTINE SISVAT_ini
+
+
+
+
+
+
+
+!***************************************************************************
+
+    SUBROUTINE sisvatetat0 (fichnom,ikl2i)
+
+    USE dimphy
+    USE mod_grid_phy_lmdz
+    USE mod_phys_lmdz_para
+
+    USE iostart
+    USE VAR_SV
+    USE VARdSV
+    USE VARxSV          
+    USE VARtSV
+    USE indice_sol_mod
+
+      IMPLICIT none
+!======================================================================
+! Auteur(s) HJ PUNGE (LSCE) date: 07/2009
+! Objet: Lecture du fichier de conditions initiales pour SISVAT
+!======================================================================
+    include "netcdf.inc"
+!    include "indicesol.h"
+
+!    include "dimsoil.h"
+    include "clesphys.h"
+    include "thermcell.h"
+    include "compbl.h"
+
+!======================================================================
+    CHARACTER(LEN=*) :: fichnom
+
+
+    INTEGER, DIMENSION(klon), INTENT(IN) :: ikl2i
+    REAL, DIMENSION(klon) :: rlon
+    REAL, DIMENSION(klon) :: rlat
+
+! les variables globales ecrites dans le fichier restart
+    REAL, DIMENSION(klon) :: isno
+    REAL, DIMENSION(klon) :: ispi
+    REAL, DIMENSION(klon) :: iice
+    REAL, DIMENSION(klon) :: rusn 
+    REAL, DIMENSION(klon, nsno) :: isto
+
+    REAL, DIMENSION(klon, nsismx) :: Tsis
+    REAL, DIMENSION(klon, nsismx) :: eta
+    REAL, DIMENSION(klon, nsismx) :: ro 
+
+    REAL, DIMENSION(klon, nsno) :: dzsn      
+    REAL, DIMENSION(klon, nsno) :: G1sn
+    REAL, DIMENSION(klon, nsno) :: G2sn
+    REAL, DIMENSION(klon, nsno) :: agsn
+
+    REAL, DIMENSION(klon) :: toic
+
+
+    INTEGER  :: isl, ikl, i, isn , errT, erreta, errro, errdz, snopts
+    CHARACTER (len=2) :: str2
+    LOGICAL :: found
+  
+    errT=0
+    errro=0
+    erreta=0
+    errdz=0
+    snopts=0
+! Ouvrir le fichier contenant l'etat initial:
+
+      CALL open_startphy(fichnom)
+
+! Lecture des latitudes, longitudes (coordonnees):
+
+      CALL get_field("latitude",rlat,found)
+      CALL get_field("longitude",rlon,found)
+
+      CALL get_field("n_snows", isno,found)
+      IF (.NOT. found) THEN
+        PRINT*, 'phyetat0: Le champ <n_snows> est absent'
+        PRINT *, 'fichier startsisvat non compatible avec sisvatetat0'
+      ENDIF
+
+      CALL get_field("n_ice_top",ispi,found)
+      CALL get_field("n_ice",iice,found)
+      CALL get_field("surf_water",rusn,found)
+!      IF (.NOT. found) THEN
+!        PRINT*, 'phyetat0: Le champ <surf_water> est absent'
+!        rusn(:)=0.  
+!      ENDIF
+
+
+      CALL get_field("to_ice",toic,found)
+      IF (.NOT. found) THEN
+        PRINT*, 'phyetat0: Le champ <to_ice> est absent'
+        toic(:)=0.  
+      ENDIF
+
+
+
+      DO isn = 1,nsno
+        IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL get_field("AGESNOW"//str2, &
+                          agsn(:,isn),found)
+        ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+        ENDIF
+      ENDDO
+      DO isn = 1,nsno
+        IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL get_field("DZSNOW"//str2, &
+                          dzsn(:,isn),found)
+        ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+        ENDIF
+      ENDDO
+      DO isn = 1,nsno
+        IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL get_field("G2SNOW"//str2, &
+                          G2sn(:,isn),found)
+        ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+        ENDIF
+      ENDDO
+      DO isn = 1,nsno
+        IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL get_field("G1SNOW"//str2, &
+                          G1sn(:,isn),found)
+        ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+        ENDIF
+      ENDDO
+      DO isn = 1,nsismx
+        IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL get_field("ETA"//str2, &
+                          eta(:,isn),found)
+        ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+        ENDIF
+      ENDDO
+      DO isn = 1,nsismx
+        IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL get_field("RO"//str2, &
+                          ro(:,isn),found)
+        ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+        ENDIF
+      ENDDO
+      DO isn = 1,nsismx
+        IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL get_field("TSS"//str2, &
+                          Tsis(:,isn),found)
+        ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+        ENDIF
+      ENDDO
+      DO isn = 1,nsno
+        IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL get_field("HISTORY"//str2, &
+                          isto(:,isn),found)
+        ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+        ENDIF
+      ENDDO
+      write(*,*)'Read ',fichnom,' finished!!'
+
+!*********************************************************************************
+! Compress restart file variables for SISVAT
+
+
+      DO  ikl = 1,klon                                                   
+          i   = ikl2i(ikl)   
+          IF (i > 0) THEN
+              isnoSV(ikl)     = INT(isno(i))          ! Nb Snow/Ice Lay.   
+              ispiSV(ikl)     = INT(ispi(i))          ! Nb Supr.Ice Lay.  
+              iiceSV(ikl)     = INT(iice(i))          ! Nb      Ice Lay.   
+                                                                              
+
+            DO isl =   -nsol,0    
+              ro__SV(ikl,isl) = ro(i,nsno+1-isl)       !                    
+              eta_SV(ikl,isl) = eta(i,nsno+1-isl)         ! Soil Humidity      
+!hjp 15/10/2010
+              IF (eta_SV(ikl,isl) <= 1.e-6) THEN          !hj check
+                eta_SV(ikl,isl) = 1.e-6
+              ENDIF
+              TsisSV(ikl,isl) = Tsis(i,nsno+1-isl)        ! Soil Temperature  
+              IF (TsisSV(ikl,isl) <= 1.) THEN             !hj check
+!                errT=errT+1
+                TsisSV(ikl,isl) = 273.15-0.2              ! Etienne: negative temperature since soil is ice
+              ENDIF
+
+            END DO        
+            write(*,*)'Copy histo', ikl
+    
+   
+            DO  isn = 1,isnoSV(ikl) !nsno      
+              snopts=snopts+1 
+              IF (isto(i,isn) > 10.) THEN          !hj check
+                write(*,*)'Irregular isto',ikl,i,isn,isto(i,isn)
+                isto(i,isn) = 1.
+              ENDIF
+
+              istoSV(ikl,isn) = INT(isto(i,isn))     ! Snow     History 
+              ro__SV(ikl,isn) = ro(i,isn)            !        [kg/m3]     
+              eta_SV(ikl,isn) = eta(i,isn)           !        [m3/m3]  
+              TsisSV(ikl,isn) = Tsis(i,isn)          !            [K]  
+
+             IF (TsisSV(ikl,isn) <= 1.) THEN          !hj check
+              errT=errT+1
+              TsisSV(ikl,isn) = TsisSV(ikl,0)
+             ENDIF  
+             IF (TsisSV(ikl,isn) <= 1.) THEN          !hj check
+              TsisSV(ikl,isn) = 263.15
+             ENDIF
+             IF (eta_SV(ikl,isn) < 1.e-9) THEN          !hj check
+              eta_SV(ikl,isn) = 1.e-6  
+              erreta=erreta+1
+             ENDIF  
+             IF (ro__SV(ikl,isn) <= 10.) THEN          !hj check
+              ro__SV(ikl,isn) = 11.
+              errro=errro+1
+             ENDIF 
+              write(*,*)ikl,i,isn,Tsis(i,isn),G1sn(i,isn)
+              G1snSV(ikl,isn) = G1sn(i,isn)          ! [-]        [-]     
+              G2snSV(ikl,isn) = G2sn(i,isn)          ! [-] [0.0001 m] 
+              dzsnSV(ikl,isn) = dzsn(i,isn)          !            [m]         
+              agsnSV(ikl,isn) = agsn(i,isn)          !          [day]     
+            END DO  
+              rusnSV(ikl)     = rusn(i)              ! Surficial Water    
+              toicSV(ikl)     = toic(i)              ! bilan snow to ice   
+          END IF                       
+        END DO    
+
+    END SUBROUTINE sisvatetat0
+
+
+
+
+!======================================================================
+    SUBROUTINE sisvatredem (fichnom,ikl2i,rlon,rlat)
+    
+     
+    
+!======================================================================
+! Auteur(s) HJ PUNGE (LSCE) date: 07/2009
+! Objet: Ecriture de l'etat de redemarrage pour SISVAT
+!======================================================================
+    USE mod_grid_phy_lmdz
+    USE mod_phys_lmdz_para
+    USE iostart
+    USE VAR_SV
+    USE VARxSV          
+    USE VARySV !hj tmp 12 03 2010
+    USE VARtSV
+    USE indice_sol_mod
+    USE dimphy
+
+
+    IMPLICIT none
+
+    include "netcdf.inc"
+!    include "indicesol.h" 
+!    include "dimsoil.h"
+    include "clesphys.h" 
+    include "thermcell.h"
+    include "compbl.h"
+
+!======================================================================
+
+    CHARACTER(LEN=*) :: fichnom
+    INTEGER, DIMENSION(klon), INTENT(IN) :: ikl2i
+    REAL, DIMENSION(klon), INTENT(IN) :: rlon
+    REAL, DIMENSION(klon), INTENT(IN) :: rlat
+
+! les variables globales ecrites dans le fichier restart
+    REAL, DIMENSION(klon) :: isno
+    REAL, DIMENSION(klon) :: ispi
+    REAL, DIMENSION(klon) :: iice
+    REAL, DIMENSION(klon, nsnowmx) :: isto
+
+    REAL, DIMENSION(klon, nsismx) :: Tsis
+    REAL, DIMENSION(klon, nsismx) :: eta
+    REAL, DIMENSION(klon, nsnowmx) :: dzsn
+    REAL, DIMENSION(klon, nsismx) :: ro        
+    REAL, DIMENSION(klon, nsnowmx) :: G1sn
+    REAL, DIMENSION(klon, nsnowmx) :: G2sn
+    REAL, DIMENSION(klon, nsnowmx) :: agsn
+    REAL, DIMENSION(klon) :: IRs
+    REAL, DIMENSION(klon) :: LMO
+    REAL, DIMENSION(klon) :: rusn 
+    REAL, DIMENSION(klon) :: toic
+    REAL, DIMENSION(klon) :: Bufs
+    REAL, DIMENSION(klon) :: alb1,alb2,alb3
+
+    INTEGER isl, ikl, i, isn, ierr
+    CHARACTER (len=2) :: str2
+    INTEGER           :: pass
+
+      isno(:)       = 0       
+      ispi(:)       = 0 
+      iice(:)       = 0                                
+      IRs(:)        = 0.
+      LMO(:)        = 0.                             
+      eta(:,:)      = 0.     
+      Tsis(:,:)     = 0.         
+      isto(:,:)     = 0 
+      ro(:,:)       = 0.        
+      G1sn(:,:)     = 0.    
+      G2sn(:,:)     = 0. 
+      dzsn(:,:)     = 0.        
+      agsn(:,:)     = 0. 
+      rusn(:)       = 0.   
+      toic(:)       = 0.   
+      Bufs(:)       = 0.   
+      alb1(:)       = 0.
+      alb2(:)       = 0.
+      alb3(:)       = 0.
+
+!***************************************************************************
+! Uncompress SISVAT output variables for storage
+           
+
+      print*, 'je rentre dans restart inlandsis'     
+      DO  ikl = 1,klon  
+           i   = ikl2i(ikl)
+      IF (i > 0) THEN
+        isno(i)       = 1.*isnoSV(ikl)               ! Nb Snow/Ice Lay.   
+        ispi(i)       = 1.*ispiSV(ikl)               ! Nb Supr.Ice Lay.   
+        iice(i)       = 1.*iiceSV(ikl)               ! Nb      Ice Lay.       
+   
+!        IRs(i)        = IRs_SV(ikl)
+!        LMO(i)        = LMO_SV(ikl)                             
+
+
+        DO isl =   -nsol,0                           !                    
+          eta(i,nsno+1-isl)  = eta_SV(ikl,isl)            ! Soil Humidity      
+          Tsis(i,nsno+1-isl) = TsisSV(ikl,isl)            ! Soil Temperature   
+          ro(i,nsno+1-isl)   = ro__SV(ikl,isl)            !        [kg/m3]    
+        END DO        
+ 
+  
+        DO  isn = 1,nsno              
+          isto(i,isn)   = 1.*istoSV(ikl,isn)         ! Snow     History 
+          ro(i,isn)     = ro__SV(ikl,isn)            !        [kg/m3]     
+          eta(i,isn)    = eta_SV(ikl,isn)            !        [m3/m3]  
+          Tsis(i,isn)   = TsisSV(ikl,isn)            !            [K]    
+          G1sn(i,isn)   = G1snSV(ikl,isn)            ! [-]        [-]     
+          G2sn(i,isn)   = G2snSV(ikl,isn)            ! [-] [0.0001 m] 
+          dzsn(i,isn)   = dzsnSV(ikl,isn)            !            [m]         
+          agsn(i,isn)   = agsnSV(ikl,isn)            !          [day]     
+        END DO  
+        rusn(i)       = rusnSV(ikl)                  ! Surficial Water  
+        toic(i)       = toicSV(ikl)                  ! to ice 
+        alb1(i)       = alb1sv(ikl) 
+        alb2(i)       = alb2sv(ikl)
+        alb3(i)       = alb3sv(ikl)
+!        Bufs(i)       = BufsSV(ikl)      
+      END IF                     
+      END DO                                                
+
+
+      print*, 'je call open_restart'     
+
+      CALL open_restartphy(fichnom)
+
+      print*, 'je sors open_restart'     
+
+
+      DO pass = 1, 2
+        CALL put_field(pass,"longitude", &
+                    "Longitudes de la grille physique",rlon)     
+        CALL put_field(pass,"latitude","Latitudes de la grille physique",rlat)
+  
+        CALL put_field(pass,"n_snows", "number of snow/ice layers",isno)
+        CALL put_field(pass,"n_ice_top", "number of top ice layers",ispi)
+        CALL put_field(pass,"n_ice", "number of ice layers",iice)
+        CALL put_field(pass,"IR_soil", "Soil IR flux",IRs)
+        CALL put_field(pass,"LMO", "Monin-Obukhov Scale",LMO)
+        CALL put_field(pass,"surf_water", "Surficial water",rusn)
+        CALL put_field(pass,"snow_buffer", "Snow buffer layer",Bufs)
+        CALL put_field(pass,"alb_1", "albedo sw",alb1)
+        CALL put_field(pass,"alb_2", "albedo nIR",alb2)
+        CALL put_field(pass,"alb_3", "albedo fIR",alb3)
+        CALL put_field(pass,"to_ice", "Snow passed to ice",toic)
+
+
+
+        DO isn = 1,nsno
+          IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL put_field(pass,"AGESNOW"//str2, &
+                         "Age de la neige layer No."//str2, &
+                         agsn(:,isn))
+          ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+          ENDIF
+        ENDDO
+        DO isn = 1,nsno
+          IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL put_field(pass,"DZSNOW"//str2, &
+                         "Snow/ice thickness layer No."//str2, &
+                         dzsn(:,isn))
+          ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+          ENDIF
+        ENDDO
+        DO isn = 1,nsno
+          IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL put_field(pass,"G2SNOW"//str2, &
+                         "Snow Property 2, layer No."//str2, &
+                         G2sn(:,isn))
+          ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+          ENDIF
+        ENDDO
+        DO isn = 1,nsno
+          IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL put_field(pass,"G1SNOW"//str2, &
+                         "Snow Property 1, layer No."//str2, &
+                         G1sn(:,isn))
+          ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+          ENDIF
+        ENDDO
+        DO isn = 1,nsismx
+          IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL put_field(pass,"ETA"//str2, &
+                         "Soil/snow water content layer No."//str2, &
+                         eta(:,isn))
+          ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+          ENDIF
+        ENDDO
+        DO isn = 1,nsismx   !nsno
+          IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL put_field(pass,"RO"//str2, &
+                           "Snow density layer No."//str2, &
+                           ro(:,isn))
+          ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+          ENDIF
+        ENDDO
+        DO isn = 1,nsismx
+          IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL put_field(pass,"TSS"//str2, &
+                           "Soil/snow temperature layer No."//str2, &
+                           Tsis(:,isn))
+          ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+          ENDIF
+        ENDDO
+        DO isn = 1,nsno
+          IF (isn.LE.99) THEN
+            WRITE(str2,'(i2.2)') isn
+            CALL put_field(pass,"HISTORY"//str2, &
+                           "Snow history layer No."//str2, &
+                           isto(:,isn))
+          ELSE
+            PRINT*, "Trop de couches"
+            CALL abort
+          ENDIF
+        ENDDO
+
+      CALL enddef_restartphy
+      ENDDO
+      CALL close_restartphy
+
+
+  END SUBROUTINE sisvatredem
+
+END MODULE surf_inlandsis_mod
Index: LMDZ6/trunk/libf/phylmd/phys_output_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phys_output_mod.F90	(revision 3790)
+++ LMDZ6/trunk/libf/phylmd/phys_output_mod.F90	(revision 3792)
@@ -40,5 +40,5 @@
     USE mod_phys_lmdz_para
     !Martin
-    USE surface_data, ONLY : ok_snow
+    USE surface_data, ONLY : landice_opt
     USE phys_output_ctrlout_mod
     USE mod_grid_phy_lmdz, only: klon_glo,nbp_lon,nbp_lat
Index: LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 3790)
+++ LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 3792)
@@ -361,5 +361,5 @@
     USE infotrac_phy, ONLY: nqtot, nqo, type_trac, tname, niadv
     USE geometry_mod, ONLY: cell_area, latitude_deg, longitude_deg
-    USE surface_data, ONLY: type_ocean, version_ocean, ok_veget, ok_snow
+    USE surface_data, ONLY: type_ocean, version_ocean, ok_veget, landice_opt
     USE aero_mod, ONLY: naero_tot, id_STRAT_phy
     USE ioipsl, ONLY: histend, histsync
@@ -1001,5 +1001,5 @@
        CALL histwrite_phy(o_tauy, zx_tmp_fi2d)
 
-       IF (ok_snow) THEN
+       IF (landice_opt .GE. 1) THEN
           CALL histwrite_phy(o_snowsrf, snow_o)
           CALL histwrite_phy(o_qsnow, qsnow)
Index: LMDZ6/trunk/libf/phylmd/physiq_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 3790)
+++ LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 3792)
@@ -65,5 +65,5 @@
     USE regr_horiz_time_climoz_m, ONLY: regr_horiz_time_climoz
     USE regr_pr_time_av_m, only: regr_pr_time_av
-    USE surface_data,     ONLY : type_ocean, ok_veget, ok_snow
+    USE surface_data,     ONLY : type_ocean, ok_veget, landice_opt
     USE time_phylmdz_mod, only: annee_ref, current_time, day_ini, day_ref, &
           day_step_phy, itau_phy, pdtphys, raz_date, start_time, update_time
Index: LMDZ6/trunk/libf/phylmd/surf_landice_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/surf_landice_mod.F90	(revision 3790)
+++ LMDZ6/trunk/libf/phylmd/surf_landice_mod.F90	(revision 3792)
@@ -25,5 +25,5 @@
 
     USE dimphy
-    USE surface_data,     ONLY : type_ocean, calice, calsno, ok_snow
+    USE surface_data,     ONLY : type_ocean, calice, calsno, landice_opt, n_dtis
     USE fonte_neige_mod,  ONLY : fonte_neige, run_off_lic
     USE cpl_mod,          ONLY : cpl_send_landice_fields
@@ -36,4 +36,9 @@
     USE surf_sisvat_mod,  ONLY : surf_sisvat
 #endif
+
+#ifdef CPP_INLANDSIS
+    USE surf_inlandsis_mod,  ONLY : surf_inlandsis
+#endif
+
     USE indice_sol_mod
 
@@ -86,6 +91,6 @@
 !    REAL, DIMENSION(klon), INTENT(OUT)            :: alb1  ! new albedo in visible SW interval
 !    REAL, DIMENSION(klon), INTENT(OUT)            :: alb2  ! new albedo in near IR interval
-    REAL, DIMENSION(6), INTENT(IN)              ::SFRWL
-    REAL, DIMENSION(klon,nsw), INTENT(OUT)        ::alb_dir,alb_dif
+    REAL, DIMENSION(6), INTENT(IN)                :: SFRWL
+    REAL, DIMENSION(klon,nsw), INTENT(OUT)        :: alb_dir,alb_dif
 !albedo SB <<<
     REAL, DIMENSION(klon), INTENT(OUT)            :: evap, fluxsens, fluxlat
@@ -108,16 +113,18 @@
     REAL, DIMENSION(klon)    :: zfra, alb_neig
     REAL, DIMENSION(klon)    :: radsol
-    REAL, DIMENSION(klon)    :: u0, v0, u1_lay, v1_lay
-    INTEGER                  :: i,j
+    REAL, DIMENSION(klon)    :: u0, v0, u1_lay, v1_lay, ustar
+    INTEGER                  :: i,j,nt
 
     REAL, DIMENSION(klon)    :: emis_new                  !Emissivity
     REAL, DIMENSION(klon)    :: swdown,lwdown
     REAL, DIMENSION(klon)    :: precip_snow_adv, snow_adv !Snow Drift precip./advection
-    REAL, DIMENSION(klon)    :: bl_height, wind_velo      !height boundary layer, wind spd
+    REAL, DIMENSION(klon)    :: zsl_height, wind_velo      !surface layer height, wind spd
     REAL, DIMENSION(klon)    :: dens_air,  snow_cont_air  !air density; snow content air
     REAL, DIMENSION(klon)    :: alb_soil                  !albedo of underlying ice
     REAL, DIMENSION(klon)    :: pexner                    !Exner potential
     REAL                     :: pref
-    REAL, DIMENSION(klon,nsoilmx) :: tsoil0 !modfi
+    REAL, DIMENSION(klon,nsoilmx) :: tsoil0               !modif
+    REAL                          :: dtis                ! subtimestep
+    LOGICAL                       :: debut_is, lafin_is  ! debut and lafin for inlandsis
 
     CHARACTER (len = 20)                      :: modname = 'surf_landice'
@@ -139,7 +146,8 @@
   LOGICAL, SAVE :: firstcall = .TRUE.
   !$OMP THREADPRIVATE(firstcall)
-!FC
-
-
+
+
+!FC firtscall initializations
+!******************************************************************************************
   IF (firstcall) THEN
   alb_vis_sno_lic=0.77
@@ -149,7 +157,11 @@
   CALL getin_p('alb_nir_sno_lic',alb_nir_sno_lic)
            PRINT*, 'alb_nir_sno_lic',alb_nir_sno_lic
+  
+!  z0m=1.e-3
+!  z0h = z0m
   firstcall=.false.
   ENDIF
-!
+!******************************************************************************************
+
 ! Initialize output variables
     alb3(:) = 999999.
@@ -166,9 +178,16 @@
 
 !****************************************************************************************
-!   ok_snow = TRUE  : prepare and call SISVAT snow model
-!   ok_snow = FALSE : soil_model, calcul_flux, fonte_neige, ... 
-!
-!****************************************************************************************
-    IF (ok_snow) THEN
+!  landice_opt = 0 : soil_model, calcul_flux, fonte_neige, ...  
+!  landice_opt = 1  : prepare and call SISVAT snow model
+!  landice_opt = 2  : prepare and call INLANDSIS snow model
+!****************************************************************************************
+
+
+    IF (landice_opt .EQ. 1) THEN
+    
+!****************************************************************************************
+! CALL to SISVAT interface
+!****************************************************************************************
+
 #ifdef CPP_SISVAT
        ! Prepare for calling SISVAT
@@ -192,11 +211,8 @@
           pexner(i)        = (p1lay(i)/pref)**(RD/RCPD)
           dens_air(i)      = p1lay(i)/RD/temp_air(i)  ! dry air density
-          bl_height(i)     = pphi1(i)/RG              
+          zsl_height(i)     = pphi1(i)/RG              
        END DO
 
-!****************************************************************************************
-! CALL to SISVAT interface
-!
-!****************************************************************************************
+
        ! config: compute everything with SV but temperatures afterwards with soil/calculfluxs
        DO i = 1, knon
@@ -209,5 +225,5 @@
             rmu0, swdown, lwdown, pexner, ps, p1lay, &
             precip_rain, precip_snow, precip_snow_adv, snow_adv, &
-            bl_height, wind_velo, temp_air, dens_air, spechum, tsurf, &
+            zsl_height, wind_velo, temp_air, dens_air, spechum, tsurf, &
             rugoro, snow_cont_air, alb_soil, slope, cloudf, &
             radsol, qsol, tsoil0, snow, snowhgt, qsnow, to_ice,sissnow, agesno, &
@@ -232,8 +248,87 @@
             flux_u1, flux_v1)
 #else
-       abort_message='Pb de coherence: ok_snow = .true. mais CPP_SISVAT = .false.'
+       abort_message='Pb de coherence: landice_opt = 1 mais CPP_SISVAT = .false.'
        CALL abort_physic(modname,abort_message,1)
 #endif
-    ELSE ! ok_snow=FALSE
+
+!****************************************************************************************
+! CALL to INLANDSIS interface
+!****************************************************************************************
+
+    ELSE IF (landice_opt .EQ. 2) THEN
+#ifdef CPP_INLANDSIS
+
+        debut_is=debut
+        lafin_is=.false.
+        ! Suppose zero surface speed
+        u0(:)            = 0.0
+        v0(:)            = 0.0
+
+
+        CALL calcul_flux_wind(knon, dtime, &
+         u0, v0, u1, v1, gustiness, cdragm, &
+         AcoefU, AcoefV, BcoefU, BcoefV, &
+         p1lay, temp_air, &
+         flux_u1, flux_v1)
+
+       
+       ! Set constants and compute some input for SISVAT
+       ! = 1000 hPa
+       ! and calculate incoming flux for SW and LW interval: swdown, lwdown
+       swdown(:)        = 0.0
+       lwdown(:)        = 0.0
+       snow_adv(:)      = 0.  ! no snow blown in for now
+       snow_cont_air(:) = 0.       
+       alb_soil(:)      = 0.4 ! before albedo(:) but here it is the ice albedo that we have to set
+       ustar(:)         = 0.
+       pref             = 100000.       
+       DO i = 1, knon
+          swdown(i)        = swnet(i)/(1-albedo(i))
+          lwdown(i)        = lwdownm(i)
+          wind_velo(i)     = u1(i)**2 + v1(i)**2
+          wind_velo(i)     = wind_velo(i)**0.5
+          pexner(i)        = (p1lay(i)/pref)**(RD/RCPD)
+          dens_air(i)      = p1lay(i)/RD/temp_air(i)  ! dry air density
+          zsl_height(i)    = pphi1(i)/RG      
+          tsoil0(i,:)      = tsoil(i,:)  
+          ustar(i)= (cdragm(i)*(wind_velo(i)**2))**0.5   
+       END DO
+       
+
+       ! Subtimestepping
+       
+        dtis=dtime/n_dtis
+
+        DO nt=1,n_dtis
+
+          IF (lafin .and. nt.eq.n_dtis) THEN
+            lafin_is=.true.
+          END IF
+
+        !PRINT*,'RENTRE DANS INLANDSIS','itime',itime,'dtime',dtime,'dtis',dtis
+        CALL surf_inlandsis(knon, rlon, rlat, knindex, itime, dtis, debut_is, lafin_is, &
+            rmu0, swdown, lwdown, albedo, pexner, ps, p1lay, &
+            precip_rain, precip_snow, precip_snow_adv, snow_adv, &
+            zsl_height, wind_velo, ustar, temp_air, dens_air, spechum, tsurf, &
+            rugoro, snow_cont_air, alb_soil, slope, cloudf, &
+            radsol, qsol, tsoil0, snow, zfra, snowhgt, qsnow, to_ice,sissnow, agesno, &
+            AcoefH, AcoefQ, BcoefH, BcoefQ, cdragm, cdragh, &
+            run_off_lic, evap, fluxsens, fluxlat, dflux_s, dflux_l, &        
+            tsurf_new, alb1, alb2, alb3, &
+            emis_new, z0m, z0h, qsurf)      
+
+         debut_is=.false.
+
+        END DO
+
+
+#else
+       abort_message='Pb de coherence: landice_opt = 2 mais CPP_INLANDSIS = .false.'
+       CALL abort_physic(modname,abort_message,1)
+#endif
+
+
+
+    ELSE 
 
 !****************************************************************************************
@@ -261,6 +356,6 @@
 !
 !****************************************************************************************
- !   beta(:) = 1.0
- !   dif_grnd(:) = 0.0
+!    beta(:) = 1.0
+!    dif_grnd(:) = 0.0
 
 ! Suppose zero surface speed
@@ -287,5 +382,5 @@
 !    
 !****************************************************************************************
-    CALL fonte_neige( knon, is_lic, knindex, dtime, &
+    CALL fonte_neige(knon, is_lic, knindex, dtime, &
          tsurf, precip_rain, precip_snow, &
          snow, qsol, tsurf_new, evap)
@@ -323,5 +418,10 @@
     z0m = SQRT(z0m**2+rugoro**2)
 
-    END IF ! ok_snow
+
+
+
+    
+
+    END IF ! landice_opt
 
 
@@ -340,12 +440,13 @@
   
 !****************************************************************************************
-       snow_o=0.
-       zfra_o = 0.
-       DO j = 1, knon
-           i = knindex(j)
-           snow_o(i) = snow(j) 
-           zfra_o(i) = zfra(j)
-       ENDDO
-
+! Etienne: comment these lines because of duplication just below
+!       snow_o=0.
+!       zfra_o = 0.
+!       DO j = 1, knon
+!           i = knindex(j)
+!           snow_o(i) = snow(j) 
+!           zfra_o(i) = zfra(j)
+!       ENDDO
+!
 !****************************************************************************************
        snow_o=0.
Index: LMDZ6/trunk/libf/phylmd/surface_data.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/surface_data.F90	(revision 3790)
+++ LMDZ6/trunk/libf/phylmd/surface_data.F90	(revision 3792)
@@ -15,7 +15,4 @@
   !$OMP THREADPRIVATE(type_veget)
 
-  LOGICAL, SAVE          :: ok_snow       ! true for coupling to snow model SISVAT
-  !$OMP THREADPRIVATE(ok_snow)
-
   CHARACTER(len=6), SAVE :: type_ocean    ! force/slab/couple
   !$OMP THREADPRIVATE(type_ocean)
@@ -30,3 +27,22 @@
   !$OMP THREADPRIVATE(t_coupl)
 
+  ! FOR INLANDSIS:
+  !===============
+
+   INTEGER, SAVE          :: landice_opt       ! 1 for coupling with SISVAT, 2 for coupling with INLANDSIS
+  !$OMP THREADPRIVATE(landice_opt)
+
+   INTEGER, SAVE          :: iflag_tsurf_inlandsis ! 0 SISVAT method, 1 LMDZ method
+  !$OMP THREADPRIVATE(iflag_tsurf_inlandsis)
+
+   INTEGER, SAVE          :: iflag_albzenith ! dependency of albedo to zenith angle
+  !$OMP THREADPRIVATE(iflag_albzenith)  
+
+   INTEGER, SAVE          :: n_dtis           ! number of subtimesteps for INLANDSIS
+  !$OMP THREADPRIVATE(n_dtis)
+
+  ! with or without snow module/ blowing snow, ascii outfile
+   LOGICAL, SAVE           :: SnoMod,BloMod,ok_outfor 
+  !$OMP THREADPRIVATE(SnoMod,BloMod,ok_outfor)    
+
 END MODULE surface_data
