From a9abdd82ff79e0e4f107ee7ff663cc87fd83654d Mon Sep 17 00:00:00 2001
From: Juan Escobar <escj@aero.obs-mip.fr>
Date: Tue, 22 Aug 2017 09:52:25 +0200
Subject: [PATCH] J.P. Chaboureau & Juan 21/08/2017:surf_solar_slopes.f90,
 correction for tiny solar zenithal angle in R*4

---
 src/MNH/surf_solar_slopes.f90 | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/MNH/surf_solar_slopes.f90 b/src/MNH/surf_solar_slopes.f90
index 4c8bb61f1..9dd3fbe40 100644
--- a/src/MNH/surf_solar_slopes.f90
+++ b/src/MNH/surf_solar_slopes.f90
@@ -75,13 +75,14 @@ END MODULE MODI_SURF_SOLAR_SLOPES
 !!      Original    15/01/02
 !!      V. Masson   01/03/03 add multiple wavelengths
 !!      V. Masson   04/01/11 standard definition of azimuthal angle
+!!      J.P. Chaboureau & Juan 21/08/2017 correction for tiny solar zenithal angle in R*4
 !!
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
 !              ------------
 !
-USE MODD_CST, ONLY : XPI
+USE MODD_CST, ONLY : XPI, XMNH_TINY
 !
 IMPLICIT NONE
 !
@@ -173,14 +174,14 @@ DO JT=1,4
 !* slope angles
 !
       ZSLOPANG = ATAN(SQRT(ZDZSDX**2+ZDZSDY**2))
-      ZSLOPAZI = - 0.5*XPI - ATAN2( ZDZSDY, ZDZSDX + SIGN(1.E-30,ZDZSDX) )
+      ZSLOPAZI = - 0.5*XPI - ATAN2( ZDZSDY, ZDZSDX + SIGN(XMNH_TINY,ZDZSDX) )
 !
 !* modification of radiation received by 1 square meter of surface 
 ! (of the triangle) because of its orientation relative to the sun
 !
       PDIRSWDT(JI,JJ,JT,:) = MAX( 0.0 , PDIRSRFSWD(JI,JJ,:) * ( &
          COS(ZSLOPANG)                                          &
-       + SIN(ZSLOPANG) * PSINZEN(JI,JJ) / PCOSZEN(JI,JJ)        &
+       + SIN(ZSLOPANG) * PSINZEN(JI,JJ) / MAX(PCOSZEN(JI,JJ), XMNH_TINY) &
          *  COS(PAZIMSOL(JI,JJ)-ZSLOPAZI)                     ) &
                                 )
 !
-- 
GitLab