Index: /trunk/tools/diag_tools.py
===================================================================
--- /trunk/tools/diag_tools.py	(revision 2208)
+++ /trunk/tools/diag_tools.py	(revision 2209)
@@ -41,4 +41,6 @@
 # Forcompute_psl_ptarget: Function to compute the sea-level pressure following 
 #   target_pressure value found in `p_interp.F'
+# Forcompute_range_faces: Function to compute faces [uphill, valley, downhill] of sections of a 
+#   mountain rage, along a given face
 # Forcompute_zmla_gen: Function to compute the boundary layer height following a 
 #   generic method with Fortran
@@ -1384,8 +1386,8 @@
     varvdims = dimvns[:]
 
-    if len(var.shape) == 2:
-        faces = np.zeros((var.shape[0],var.shape[1]), dtype=np.float)
-        dx = var.shape[1]
-        dy = var.shape[0]
+    if len(hgt.shape) == 2:
+        faces = np.zeros(hgt.shape, dtype=np.float)
+        dx = hgt.shape[1]
+        dy = hgt.shape[0]
 
         facest=fdin.module_fordiagnostics.compute_range_faces(lon=lon[:].transpose(),\
Index: /trunk/tools/diagnostics.py
===================================================================
--- /trunk/tools/diagnostics.py	(revision 2208)
+++ /trunk/tools/diagnostics.py	(revision 2209)
@@ -27,4 +27,6 @@
 # compute_OMEGAw: Function to transform OMEGA [Pas-1] to velocities [ms-1]
 # compute_prw: Function to compute water vapour path (prw)
+# compute_range_faces: Function to compute faces [uphill, valley, downhill] of sections of a mountain
+#   range, along a given face
 # compute_rh: Function to compute relative humidity following 'Tetens' equation (T,P) ...'
 # compute_td: Function to compute the dew point temperature
@@ -88,5 +90,5 @@
     #######
 availdiags = ['ACRAINTOT', 'accum', 'clt', 'cllmh', 'convini', 'deaccum', 'fog_K84', \
-  'fog_RUC', 'LMDZrh', 'mslp', 'OMEGAw', 'RAINTOT',                                  \
+  'fog_RUC', 'LMDZrh', 'mslp', 'OMEGAw', 'RAINTOT', 'range_faces',                   \
   'rvors', 'td', 'timemax', 'timeoverthres', 'turbulence', 'uavaFROMwswd',           \
   'WRFcape_afwa', 'WRFclivi', 'WRFclwvi', 'WRF_denszint', 'WRFgeop',                 \
@@ -99,5 +101,6 @@
 
 # Variables not to check
-NONcheckingvars = ['accum', 'cllmh', 'deaccum', 'TSrhs', 'TStd', 'TSwds', 'TSwss',   \
+NONcheckingvars = ['accum', 'cllmh', 'deaccum', 'face:WE', 'face:SN', 'TSrhs',       \
+  'TStd', 'TSwds', 'TSwss',                                                          \
   'WRFbils',                                                                         \
   'WRFclivi', 'WRFclwvi', 'WRFdens', 'WRFgeop',                                      \
@@ -676,5 +679,5 @@
         ncvar.insert_variable(ncobj, 'hurs', diagout, diagoutd, diagoutvd, newnc)
 
-# range_faces: LON, LAT, HGT, 'face,[WE],[SN]'
+# range_faces: LON, LAT, HGT, 'face:['WE'/'SN']'
     elif diagn == 'range_faces':
             
@@ -682,10 +685,18 @@
         var1 = ncobj.variables[depvars[1]][:]
         var2 = ncobj.variables[depvars[2]][:]
-        var3 = depvars[3].split(',')[1]
+        var3 = depvars[3].split(':')[1]
+
+        lon, lat = gen.lonlat2D(var0, var1)
+        if len(var2.shape) == 3:
+            print warnmsg
+            print '  ' + diagn + ": shapping to 2D variable '" + depvars[2] + "' !!"
+            hgt = var2[0,:,:]
+        else:
+            hgt = var2[:]
 
         dnamesvar = list(ncobj.variables[depvars[0]].dimensions)
         dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames)
 
-        diagout, diagoutd, diagoutvd = diag.Forcompute_range_faces(var0, var1, var2, \
+        diagout, diagoutd, diagoutvd = diag.Forcompute_range_faces(lon, lat, hgt,    \
           var3, dnamesvar, dvnamesvar)
 
Index: /trunk/tools/module_ForDiagnostics.f90
===================================================================
--- /trunk/tools/module_ForDiagnostics.f90	(revision 2208)
+++ /trunk/tools/module_ForDiagnostics.f90	(revision 2209)
@@ -27,6 +27,7 @@
 ! compute_fog_RUC: Computation of fog and visibility following RUC method Smirnova, (2000)
 ! compute_fog_FRAML50: fog and visibility following Gultepe and Milbrandt, (2010)
+! compute_massvertint1D: Subroutine to vertically integrate a 1D variable in eta vertical coordinates
 ! compute_psl_ecmwf: Compute sea level pressure using ECMWF method following Mats Hamrud and Philippe Courtier [Pa]
-! compute_massvertint1D: Subroutine to vertically integrate a 1D variable in eta vertical coordinates
+! compute_range_faces: Subroutine to compute faces [uphill, valleys, downhill] of a mountain range along a given face
 ! compute_vertint1D: Subroutine to vertically integrate a 1D variable in any vertical coordinates
 ! compute_zint4D: Subroutine to vertically integrate a 4D variable in any vertical coordinates
Index: /trunk/tools/module_ForDiagnosticsVars.f90
===================================================================
--- /trunk/tools/module_ForDiagnosticsVars.f90	(revision 2208)
+++ /trunk/tools/module_ForDiagnosticsVars.f90	(revision 2209)
@@ -35,4 +35,5 @@
 ! var_potevap_orPM: potential evapotranspiration following Penman-Monteith formulation implemented in ORCHIDEE
 ! var_psl_ecmwf: sea level pressure using ECMWF method following Mats Hamrud and Philippe Courtier [Pa]
+! var_range_faces: compute faces [uphill, valleys, downhill] of a monuntain range along a face
 ! var_rh: Subroutine to compute relative humidity following 'Tetens' equation (T,P) ...'
 ! var_zmla_generic: Subroutine to compute pbl-height following a generic method
@@ -1579,5 +1580,5 @@
 
   SUBROUTINE var_range_faces(d, lon, lat, hgt, faces)
-! Subroutine to compute faces of a monuntain range along a face
+! Subroutine to compute faces [uphill, valleys, downhill] of a monuntain range along a face
 
     IMPLICIT NONE
@@ -1619,6 +1620,8 @@
       IF (dhgt(i) > 0.) THEN
         faces(i) = 1
-      ELSE 
+      ELSE IF (dhgt(i) < 0.) THEN
         faces(i) = -1
+      ELSE
+        faces(i) = 0
       END IF
       ! peaks
@@ -1634,19 +1637,24 @@
 
     ! tendency of the slope
-    ddhgt(1) = 1 
+    ddhgt(1) = 1
     Nfaces = 1
     Ndhgt(Nfaces) = 1
     DO i=2, d-1
       IF (faces(i) /= faces(i-1)) THEN
-        ddhgt(i) = ddhgt(i-1) + 1
         Nfaces = Nfaces + 1
         Ndhgt(Nfaces) = 1
+        ddhgt(i) = ddhgt(i-1) + 1
       ELSE
         Ndhgt(Nfaces) = Ndhgt(Nfaces) + 1
+        ddhgt(i) = ddhgt(i-1)
       END IF
     END DO
 
-    PRINT *, 'ddhgt:', ddhgt
     PRINT *, Nfaces, ' length faces:', Ndhgt(1:Nfaces)
+
+    PRINT *, '# lon[0] lat[1] heights[2] slope[3] faces[4] ddhgt[5]'
+    DO i=1, d
+      PRINT *, lon(i), lat(i), hgt(i), dhgt(i), faces(i), ddhgt(i)
+    END DO
 
     RETURN
Index: /trunk/tools/variables_values.dat
===================================================================
--- /trunk/tools/variables_values.dat	(revision 2208)
+++ /trunk/tools/variables_values.dat	(revision 2209)
@@ -389,4 +389,6 @@
 r, r, rain_mixing_ratio, 0., 0.03, rain|mixing|ratio, KgKg-1, BuPu, $qr$, qr
 QRAIN, r, rain_mixing_ratio, 0., 0.03, rain|mixing|ratio, KgKg-1, BuPu, $qr$, qr
+rangefaces, rangefaces, range_faces, -1, 1, mountain|rage|faces|(-1:|downhill;|0:|valley|;1:|uphill), 1, seismic, $range^{faces}$,range_faces
+range_faces, rangefaces, range_faces, -1, 1, mountain|rage|faces|(-1:|downhill;|0:|valley|;1:|uphill), 1, seismic, $range^{faces}$,range_faces
 reinf_slope, rslope, slope, 0., 1., slope, -, rainbow, $slope$, slope
 r_field, r_field, r_field, 0., 96., r_field, 1, BuPu, $r^{field}$, rfield
