From 57c4ac34b6d465cc8dc8dfe6eca371abd897b71c Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Thu, 8 Oct 2020 14:52:15 +0200
Subject: [PATCH] Philippe 08/10/2020: IO: add clessource in tbudgetdata type

---
 src/MNH/budget.f90      | 8 ++++++++
 src/MNH/modd_budget.f90 | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/src/MNH/budget.f90 b/src/MNH/budget.f90
index ef8c99224..e98d8652d 100644
--- a/src/MNH/budget.f90
+++ b/src/MNH/budget.f90
@@ -48,6 +48,8 @@ subroutine Budget_store_init( tpbudget, hsource, pvars )
       allocate( tpbudget%xtmplesstore( Size( pvars, 1 ), Size( pvars, 2 ), Size ( pvars, 3 )  ) )
     end if
     tpbudget%xtmplesstore(:, :, :) = pvars(:, :, :)
+
+    tpbudget%clessource = hsource
   end if
 
   ! Nothing else to do if budgets are not enabled
@@ -106,6 +108,12 @@ subroutine Budget_store_end( tpbudget, hsource, pvars )
   call Print_msg( NVERB_DEBUG, 'BUD', 'Budget_store_end', trim( tpbudget%cname )//':'//trim( hsource ) )
 
   if ( lles_call ) then
+    if ( hsource /= tpbudget%clessource ) &
+      call Print_msg( NVERB_FATAL, 'BUD', 'Budget_store_end', 'hsource not the same as in Budget_store_init (' &
+                      // Trim( hsource ) // ' / ' // Trim( tpbudget%clessource ) // ')' )
+
+    tpbudget%clessource = 'reset'
+
     if ( allocated( tpbudget%xtmplesstore ) ) then
       ! Do the call to Les_budget with oadd=.true.
       ! This is necessary when the call to Budget_store_init was done with pvars not strictly
diff --git a/src/MNH/modd_budget.f90 b/src/MNH/modd_budget.f90
index abb8a950c..99154b8e0 100644
--- a/src/MNH/modd_budget.f90
+++ b/src/MNH/modd_budget.f90
@@ -55,6 +55,7 @@
 !  P. Wautelet 23/04/2020: add nid in tbudgetdata datatype
 !  P. Wautelet 30/06/2020: add NNETURSV, NNEADVSV and NNECONSV variables
 !  P. Wautelet 17/08/2020: add xtmplesstore in tbudgetdata datatype
+!  P. Wautelet 08/10/2020: add clessource in tbudgetdata datatype
 !-------------------------------------------------------------------------------
 !
 !*       0.   DECLARATIONS
@@ -88,6 +89,7 @@ integer :: nbudgets ! Number of budget categories
 type tbudgetdata
   character(len=NBUNAMELGTMAX)  :: cname    = ''
   character(len=NCOMMENTLGTMAX) :: ccomment = ''
+  character(len=100)            :: clessource = '' ! Last source stored
   integer :: nid         = -1 !Identifier number (based on parameters NBUDGET_*)
   integer :: ngroups     = 0 !Number of groups of source terms to store
   integer :: nsources    = 0 !Number of source terms
-- 
GitLab