From 0609abac507d2b6924c6d32db9420c61ed958b46 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Wed, 15 Mar 2023 13:20:50 +0100
Subject: [PATCH] Philippe 15/03/2023: reapply lost commit on budget after
 merge (commit 9f26b7a5)

---
 src/MNH/budget.f90 | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/MNH/budget.f90 b/src/MNH/budget.f90
index 96091c176..d453e9aab 100644
--- a/src/MNH/budget.f90
+++ b/src/MNH/budget.f90
@@ -7,6 +7,7 @@
 !  P. Wautelet 28/01/2020: new subroutines: Budget_store_init, Budget_store_end and Budget_source_id_find in new module mode_budget
 !  P. Wautelet 17/08/2020: treat LES budgets correctly
 !  P. Wautelet 05/03/2021: measure cpu_time for budgets
+!  J.Escobar   06/10/2021: for bit reproductiblity use MPPDB_CHECK if LCHECK=T
 !-----------------------------------------------------------------
 
 !#################
@@ -16,12 +17,12 @@ module mode_budget
 use modd_budget,     only: cbutype, nbutime, tbudgetdata, xtime_bu, xtime_bu_process
 use modd_les_budget, only: xtime_les_bu, xtime_les_bu_process
 
+use mode_msg
+
 use modi_cart_compress, only: Cart_compress
 use modi_mask_compress, only: Mask_compress
 use modi_second_mnh,    only: Second_mnh
 
-use mode_msg
-
 implicit none
 
 private
@@ -36,15 +37,23 @@ contains
 
 !
 subroutine Budget_store_init( tpbudget, hsource, pvars )
-  use modd_les, only: lles_call
+  use modd_conf, only: lcheck
+  use modd_les,  only: lles_call
+
+  use mode_mppdb
 
   type(tbudgetdata),      intent(inout) :: tpbudget ! Budget datastructure
   character(len=*),       intent(in)    :: hsource  ! Name of the source term
   real, dimension(:,:,:), intent(in)    :: pvars    ! Current value to be stored
 
+  character(len=:), allocatable :: hbudget
   integer :: iid ! Reference number of the current source term
 
-  call Print_msg( NVERB_DEBUG, 'BUD', 'Budget_store_init', trim( tpbudget%cname )//':'//trim( hsource ) )
+  hbudget = trim( tpbudget%cname )//':'//trim( hsource )
+
+  call Print_msg( NVERB_DEBUG, 'BUD', 'Budget_store_init', hbudget )
+
+  if ( lcheck ) call Mppdb_check3d( pvars, 'BUD_INI::' // hbudget, precision )
 
   if ( lles_call ) then
     call Second_mnh( ztime1 )
@@ -112,19 +121,27 @@ subroutine Budget_store_init( tpbudget, hsource, pvars )
 
 
 subroutine Budget_store_end( tpbudget, hsource, pvars )
+  use modd_conf, only: lcheck
   use modd_les, only: lles_call
 
+  use mode_mppdb
+
   use modi_les_budget, only: Les_budget
 
   type(tbudgetdata),      intent(inout) :: tpbudget ! Budget datastructure
   character(len=*),       intent(in) :: hsource     ! Name of the source term
   real, dimension(:,:,:), intent(in) :: pvars       ! Current value to be stored
 
+  character(len=:), allocatable :: hbudget
   integer :: iid    ! Reference number of the current source term
   integer :: igroup ! Number of the group where to store the source term
   real, dimension(:,:,:), allocatable :: zvars_add
 
-  call Print_msg( NVERB_DEBUG, 'BUD', 'Budget_store_end', trim( tpbudget%cname )//':'//trim( hsource ) )
+  hbudget = trim( tpbudget%cname )//':'//trim( hsource )
+
+  call Print_msg( NVERB_DEBUG, 'BUD', 'Budget_store_end', hbudget )
+
+  if ( lcheck ) call Mppdb_check3d( pvars, 'BUD_INI::' // hbudget, precision )
 
   if ( lles_call ) then
     if ( hsource /= tpbudget%clessource ) &
-- 
GitLab