From c5c08f354c756451725ac05fc98c6ba87e77a080 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Mon, 11 Jan 2021 12:01:02 +0100
Subject: [PATCH] Philippe 11/01/2021: budgets: ignore xbuwri for cartesian
 boxes (write at every xbulen interval)

---
 src/MNH/ini_budget.f90  | 37 +++++++++++++++++++++++--------------
 src/MNH/modd_budget.f90 |  6 +++---
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/src/MNH/ini_budget.f90 b/src/MNH/ini_budget.f90
index 0a1adcb42..4974859c9 100644
--- a/src/MNH/ini_budget.f90
+++ b/src/MNH/ini_budget.f90
@@ -1,10 +1,11 @@
-!MNH_LIC Copyright 1995-2020 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 1995-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.
 !-----------------------------------------------------------------
 ! Modifications:
 !  P. Wautelet 17/08/2020: add Budget_preallocate subroutine
+!  P. Wautelet 11/01/2021: ignore xbuwri for cartesian boxes (write at every xbulen interval)
 !-----------------------------------------------------------------
 module mode_ini_budget
 
@@ -332,25 +333,33 @@ if ( cbutype == 'CART' .or. cbutype == 'MASK' ) then
   if ( Abs( Nint( xbulen / xtstep ) * xtstep - xbulen ) > ( ITOL * xtstep ) ) &
     call Print_msg( NVERB_WARNING, 'BUD', 'Ini_budget', 'xbulen is not a multiple of xtstep' )
 
-  !Check if xbuwri is a multiple of xtstep (within tolerance)
-  if ( Abs( Nint( xbuwri / xtstep ) * xtstep - xbuwri ) > ( ITOL * xtstep ) ) &
-    call Print_msg( NVERB_WARNING, 'BUD', 'Ini_budget', 'xbuwri is not a multiple of xtstep' )
+  if ( cbutype == 'CART' ) then
+    !Check if xseglen is a multiple of xbulen (within tolerance)
+    if ( Abs( Nint( xseglen / xbulen ) * xbulen - xseglen ) > ( ITOL * xseglen ) ) &
+      call Print_msg( NVERB_WARNING, 'BUD', 'Ini_budget', 'xseglen is not a multiple of xbuwri' )
+
+    !Write cartesian budgets every xbulen time period (do not take xbuwri into account)
+    nbuwrnb = 1
+    xbuwri = xbulen
+
+    nbusubwrite = nbuwrnb                            !Number of budget time average periods for each write
+    nbutotwrite = nbuwrnb * Nint( xseglen / xbuwri ) !Total number of budget time average periods
+  else if ( cbutype == 'MASK' ) then
+    !Check if xbuwri is a multiple of xtstep (within tolerance)
+    if ( Abs( Nint( xbuwri / xtstep ) * xtstep - xbuwri ) > ( ITOL * xtstep ) ) &
+      call Print_msg( NVERB_WARNING, 'BUD', 'Ini_budget', 'xbuwri is not a multiple of xtstep' )
 
-  !Check if xbuwri is a multiple of xbulen (within tolerance)
-  if ( Abs( Nint( xbuwri / xbulen ) * xbulen - xbuwri ) > ( ITOL * xbulen ) ) &
-    call Print_msg( NVERB_WARNING, 'BUD', 'Ini_budget', 'xbuwri is not a multiple of xbulen' )
+    !Check if xbuwri is a multiple of xbulen (within tolerance)
+    if ( Abs( Nint( xbuwri / xbulen ) * xbulen - xbuwri ) > ( ITOL * xbulen ) ) &
+      call Print_msg( NVERB_WARNING, 'BUD', 'Ini_budget', 'xbuwri is not a multiple of xbulen' )
 
-  !Check if xseglen is a multiple of xbuwri (within tolerance)
-  if ( Abs( Nint( xseglen / xbuwri ) * xbuwri - xseglen ) > ( ITOL * xseglen ) ) &
-    call Print_msg( NVERB_WARNING, 'BUD', 'Ini_budget', 'xseglen is not a multiple of xbuwri' )
+    !Check if xseglen is a multiple of xbuwri (within tolerance)
+    if ( Abs( Nint( xseglen / xbuwri ) * xbuwri - xseglen ) > ( ITOL * xseglen ) ) &
+      call Print_msg( NVERB_WARNING, 'BUD', 'Ini_budget', 'xseglen is not a multiple of xbuwri' )
 
     NBUWRNB = NINT (XBUWRI / XBULEN)  ! only after NBUWRNB budget periods, we write the
                                       ! result on the FM_FILE
 
-  if ( cbutype == 'CART' ) then
-    nbusubwrite = 1                        !Number of budget time average periods for each write
-    nbutotwrite = Nint( xseglen / xbuwri ) !Total number of budget time average periods
-  else if ( cbutype == 'MASK' ) then
     nbusubwrite = nbuwrnb                            !Number of budget time average periods for each write
     nbutotwrite = nbuwrnb * Nint( xseglen / xbuwri ) !Total number of budget time average periods
   end if
diff --git a/src/MNH/modd_budget.f90 b/src/MNH/modd_budget.f90
index aa5fbd9c1..d4f0da663 100644
--- a/src/MNH/modd_budget.f90
+++ b/src/MNH/modd_budget.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 1995-2020 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 1995-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.
@@ -148,8 +148,8 @@ REAL, SAVE    :: XBULEN                    ! length in seconds of the budget
 !
 INTEGER, SAVE :: NBUSTEP                   ! number of model timesteps required 
                                            ! for the budget time average
-REAL, SAVE    :: XBUWRI                    ! period in seconds of
-                                           ! budget writing on FM-files
+REAL, SAVE    :: XBUWRI                    ! period in seconds between
+                                           ! budget writing for budget masks
 INTEGER, SAVE :: NBUWRNB                   ! number of budget periods when storage
                                            ! arrays are written on FM-files
 INTEGER, SAVE :: NBUTSHIFT                 ! temporal shift for budgets writing
-- 
GitLab