From c4e9d2115d6e946ea8742ff37634f44ca4660a63 Mon Sep 17 00:00:00 2001
From: Jean-Pierre CHABOUREAU <jean-pierre.chaboureau@aero.obs-mip.fr>
Date: Thu, 9 Feb 2023 16:55:36 +0100
Subject: [PATCH] Jean-Pierre 09/02/2023: writing of COSZEN for solar
 instruments

---
 src/MNH/call_rttov13.f90 | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/MNH/call_rttov13.f90 b/src/MNH/call_rttov13.f90
index 2dd5c691a..08cf7ba85 100644
--- a/src/MNH/call_rttov13.f90
+++ b/src/MNH/call_rttov13.f90
@@ -205,6 +205,7 @@ REAL :: ZZH, zdeg_to_rad, zrad_to_deg, zbeta, zalpha
 REAL :: XFILLVALUE =  9.9692099683868690e+36 
 
 ! Other arrays for zenithal solar angle 
+LOGICAL                             :: LCOSZENOUT
 REAL, DIMENSION(:,:),   ALLOCATABLE :: ZCOSZEN, ZSINZEN, ZAZIMSOL
 
 ! -----------------------------------------------------------------------------
@@ -310,6 +311,7 @@ opts % config % verbose       = .FALSE.  ! Enable printing of warnings
 opts_scatt % config % verbose = .FALSE. ! Disable printing of warnings
 opts_scatt % lusercfrac = .FALSE.
 
+LCOSZENOUT=.TRUE.
 ALLOCATE(ZCOSZEN(IIU,IJU))
 ALLOCATE(ZSINZEN(IIU,IJU))
 ALLOCATE(ZAZIMSOL(IIU,IJU))
@@ -778,8 +780,25 @@ DO JSAT=1,IJSAT ! loop over sensors
       NTYPE      = TYPEREAL,                       &
       NDIMS      = 2,                              &
       LTIMEDEP   = .TRUE.                          )
-!     ZOUT(:,:,JCH) = ZOUT(:,:,JCH) *ZCOSZEN(:,:)
       CALL IO_Field_write(TPFILE,TZFIELD,ZOUT(:,:,JCH))
+      IF (opts%rt_ir%addsolar .AND. LCOSZENOUT) THEN
+        YMNHNAME   = 'COSZEN'
+        YUNITS     = '-'
+        YCOMMENT   = 'Cosine of solar zenith angle'
+        TZFIELD = TFIELDMETADATA(                    &
+        CMNHNAME   = TRIM( YMNHNAME ),               &
+        CSTDNAME   = '',                             &
+        CLONGNAME  = 'MesoNH: ' // TRIM( YMNHNAME ), &
+        CUNITS     = TRIM( YUNITS ),                 &
+        CDIR       = 'XY',                           &
+        CCOMMENT   = TRIM( YCOMMENT ),               &
+        NGRID      = 1,                              &
+        NTYPE      = TYPEREAL,                       &
+        NDIMS      = 2,                              &
+        LTIMEDEP   = .TRUE.                          )
+        CALL IO_Field_write(TPFILE,TZFIELD,ZCOSZEN)
+        LCOSZENOUT=.FALSE.
+      END IF
     ELSE
       YMNHNAME   = TRIM(YBEG)//'_'//TRIM(YEND)//'refl'
       YUNITS     = 'dBZ'
-- 
GitLab