From 848e7d853ec1b734b16c15e11982fcbc12bdfb5c Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Wed, 10 Feb 2021 13:55:37 +0100
Subject: [PATCH] Philippe 10/02/2021: budgets: add missing sources for
 NSV_C2R2BEG+3 budget if LSUPSAT=T

(cherry picked from commit f4b64eda22eafce75d8b1624698307516fd2652f)
---
 src/MNH/ini_budget.f90          | 28 ++++++++++++++++++++++++++++
 src/MNH/khko_notadjust.f90      |  5 ++++-
 src/MNH/sources_neg_correct.f90 | 13 +++++++------
 3 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/src/MNH/ini_budget.f90 b/src/MNH/ini_budget.f90
index a20c0d687..9d357c6a9 100644
--- a/src/MNH/ini_budget.f90
+++ b/src/MNH/ini_budget.f90
@@ -171,6 +171,7 @@ END MODULE MODI_INI_BUDGET
 !  P. Wautelet 01/02/2021: bugfix: add missing CEDS source terms for SV budgets
 !  P. Wautelet 02/02/2021: budgets: add missing source terms for SV budgets in LIMA
 !  P. Wautelet 03/02/2021: budgets: add new source if LIMA splitting: CORR2
+!  P. Wautelet 10/02/2021: budgets: add missing sources for NSV_C2R2BEG+3 budget
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -3199,6 +3200,33 @@ USE MODD_PARAM_LIMA, ONLY : NMOD_CCN, NMOD_IFN, NMOD_IMM
       ILAST_PROC_NBR = ILAST_PROC_NBR + 1
       YWORK2(12+JSV,ILAST_PROC_NBR)= 'NECON_'
       IPROACTV(12+JSV,ILAST_PROC_NBR) = NNECONSV
+    CASE (4)
+      ILAST_PROC_NBR = ILAST_PROC_NBR + 1
+      YWORK2(12+JSV,ILAST_PROC_NBR)= 'NETUR_'
+      IF ( HTURB /= 'NONE' ) IPROACTV(12+JSV,ILAST_PROC_NBR) = NNETURSV
+      ILAST_PROC_NBR = ILAST_PROC_NBR + 1
+      YWORK2(12+JSV,ILAST_PROC_NBR)= 'MAFL_'
+      IF ( HSCONV == 'EDKF' ) IPROACTV(12+JSV,ILAST_PROC_NBR) = NMAFLSV
+      IF ( LVISC ) THEN
+        ILAST_PROC_NBR = ILAST_PROC_NBR + 1
+        YWORK2(12+JSV,ILAST_PROC_NBR)= 'VISC_'
+        IPROACTV(12+JSV,ILAST_PROC_NBR) = NVISCSV
+      END IF
+      ILAST_PROC_NBR = ILAST_PROC_NBR + 1
+      YWORK2(12+JSV,ILAST_PROC_NBR)= 'ADV_'
+      IPROACTV(12+JSV,ILAST_PROC_NBR) = NADVSV
+      ILAST_PROC_NBR = ILAST_PROC_NBR + 1
+      YWORK2(12+JSV,ILAST_PROC_NBR)= 'NEADV_'
+      IPROACTV(12+JSV,ILAST_PROC_NBR) = NNEADVSV
+      ILAST_PROC_NBR = ILAST_PROC_NBR + 1
+      YWORK2(12+JSV,ILAST_PROC_NBR)= 'NEGA_'
+      IPROACTV(12+JSV,ILAST_PROC_NBR) = NNEGASV
+      ILAST_PROC_NBR = ILAST_PROC_NBR + 1
+      YWORK2(12+JSV,ILAST_PROC_NBR)= 'CEVA_'
+      IPROACTV(12+JSV,ILAST_PROC_NBR) = 1
+      ILAST_PROC_NBR = ILAST_PROC_NBR + 1
+      YWORK2(12+JSV,ILAST_PROC_NBR)= 'NECON_'
+      IPROACTV(12+JSV,ILAST_PROC_NBR) = NNECONSV
     END SELECT
     !
 ELSEIF (JSV >= NSV_LIMA_BEG .AND. JSV <= NSV_LIMA_END) THEN  
diff --git a/src/MNH/khko_notadjust.f90 b/src/MNH/khko_notadjust.f90
index a1cf0d41e..04474e10b 100644
--- a/src/MNH/khko_notadjust.f90
+++ b/src/MNH/khko_notadjust.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 1994-2018 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 2013-2021 CNRS, Meteo-France and Universite Paul Sabatier
 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt  
 !MNH_LIC for details. version 1.
@@ -92,6 +92,8 @@ END MODULE MODI_KHKO_NOTADJUST
 !!   M.Mazoyer : 04/16 : New dummy arguments
 !!   M.Mazoyer : 10/2016 New KHKO output fields
 !!  Philippe Wautelet: 05/2016-04/2018: new data structures and calls for I/O
+!  P. Wautelet 28/05/2019: move COUNTJV function to tools.f90
+!  P. Wautelet 10/02/2021: add CEVA source for NSV_C2R2BEG+3 budget
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -416,6 +418,7 @@ IF (LBUDGET_TH) CALL BUDGET (PTHS(:,:,:) * PRHODJ(:,:,:),4,'COND_BU_RTH')
 IF (LBUDGET_SV) THEN
   CALL BUDGET (PCNUCS(:,:,:) * PRHODJ(:,:,:),13+(NSV_C2R2BEG-1),'CEVA_BU_RSV') ! RCN
   CALL BUDGET (PCCS(:,:,:) * PRHODJ(:,:,:),14+(NSV_C2R2BEG-1),'CEVA_BU_RSV') ! RCC
+  CALL BUDGET (PSAT(:,:,:) * PRHODJ(:,:,:),12+(NSV_C2R2BEG+3),'CEVA_BU_RSV')
 END IF
 !
  CONTAINS
diff --git a/src/MNH/sources_neg_correct.f90 b/src/MNH/sources_neg_correct.f90
index 8a6578c62..667a264cc 100644
--- a/src/MNH/sources_neg_correct.f90
+++ b/src/MNH/sources_neg_correct.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 2020-2020 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 2020-2021 CNRS, Meteo-France and Universite Paul Sabatier
 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
 !MNH_LIC for details. version 1.
@@ -7,6 +7,7 @@
 ! Modifications:
 !  P. Wautelet 30/06/2020: remove non-local corrections in resolved_cloud for NEGA => new local corrections here
 !  J. Escobar  21/07/2020: bug <-> array of size(:,:,:,0) => return if krr=0
+!  P. Wautelet 10/02/2021: budgets: add missing sources for NSV_C2R2BEG+3 budget
 !-----------------------------------------------------------------
 module mode_sources_neg_correct
 
@@ -23,7 +24,7 @@ subroutine Sources_neg_correct( hcloud, hbudname, krr, ptstep, ppabst, ptht, prt
 use modd_budget,     only: lbudget_th, lbudget_rv, lbudget_rc, lbudget_rr, lbudget_ri, &
                            lbudget_rs, lbudget_rg, lbudget_rh, lbudget_sv
 use modd_cst,        only: xci, xcl, xcpd, xcpv, xlstt, xlvtt, xp00, xrd, xtt
-use modd_nsv,        only: nsv_c2r2beg, nsv_lima_beg, nsv_lima_end, nsv_lima_nc, nsv_lima_nr, nsv_lima_ni
+use modd_nsv,        only: nsv_c2r2beg, nsv_c2r2end, nsv_lima_beg, nsv_lima_end, nsv_lima_nc, nsv_lima_nr, nsv_lima_ni
 use modd_param_lima, only: lcold_lima => lcold, lrain_lima => lrain, lwarm_lima => lwarm, &
                            xctmin_lima => xctmin, xrtmin_lima => xrtmin
 
@@ -249,8 +250,8 @@ if ( hbudname /= 'NECON' .and. hbudname /= 'NEGA' ) then
   END IF
 
   if ( lbudget_sv .and. (hcloud == 'C2R2' .or. hcloud == 'KHKO' ) ) then
-    do ji = 1, 3
-      call Budget( prsvs(:, :, :, nsv_c2r2beg - 1 + ji), 12 + nsv_c2r2beg - 1 + ji, Trim( hbudname )//'_BU_RSV' )
+    do ji = nsv_c2r2beg, nsv_c2r2end
+      call Budget( prsvs(:, :, :, ji), 12 + ji, Trim( hbudname )//'_BU_RSV' )
     end do
   end if
   if ( lbudget_sv .and. hcloud == 'LIMA' ) then
@@ -275,8 +276,8 @@ else !NECON + NEGA
   end if
 
   if ( lbudget_sv .and. (hcloud == 'C2R2' .or. hcloud == 'KHKO' )) then
-    do ji = 1, 3
-      call Budget( prsvs(:, :, :, nsv_c2r2beg - 1 + ji) * prhodj(:, :, :), 12 + nsv_c2r2beg - 1 + ji, Trim( hbudname )//'_BU_RSV' )
+    do ji = nsv_c2r2beg, nsv_c2r2end
+      call Budget( prsvs(:, :, :, ji) * prhodj(:, :, :), 12 + ji, Trim( hbudname )//'_BU_RSV' )
     end do
   end if
   if ( lbudget_sv .and. hcloud == 'LIMA' ) then
-- 
GitLab