From f32b566161985b7e5566703c677fb3e9d5b9e18e Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Tue, 23 Mar 2021 14:56:00 +0100
Subject: [PATCH] Philippe 23/03/2021: budgets: add ALL, LIST_AVAIL and
 LIST_ALL special strings for budget source terms

---
 src/MNH/ini_budget.f90 | 58 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/src/MNH/ini_budget.f90 b/src/MNH/ini_budget.f90
index b4d17c2fd..9d8f37fe3 100644
--- a/src/MNH/ini_budget.f90
+++ b/src/MNH/ini_budget.f90
@@ -4419,12 +4419,68 @@ subroutine Sourcelist_scan( tpbudget, hbulist )
 
   character(len=:), allocatable :: yline
   character(len=:), allocatable :: ysrc
+  character(len=:), dimension(:), allocatable :: ymsg
   integer                       :: idx
   integer                       :: igroup
   integer                       :: igroup_idx
   integer                       :: ipos
+  integer                       :: istart
   integer                       :: ji
 
+  istart = 1
+
+  ! Case 'LIST_AVAIL': list all the available source terms
+  if ( Size( hbulist ) > 0 ) then
+    if ( Trim( hbulist(1) ) == 'LIST_AVAIL' ) then
+      Allocate( character(len=65) :: ymsg(tpbudget%nsources + 1) )
+      ymsg(1) = '---------------------------------------------------------------------'
+      ymsg(2) = 'Available source terms for budget ' // Trim( tpbudget%cname )
+      Write( ymsg(3), '( A32, " ", A32 )' ) 'Name', 'Long name'
+      idx = 3
+      do ji = 1, tpbudget%nsources
+        if ( All( tpbudget%tsources(ji)%cmnhname /= [ 'INIF' , 'ENDF', 'AVEF' ] ) ) then
+          idx = idx + 1
+          Write( ymsg(idx), '( A32, " ", A32 )' ) tpbudget%tsources(ji)%cmnhname, tpbudget%tsources(ji)%clongname
+        end if
+      end do
+      ymsg(tpbudget%nsources + 1 ) = '---------------------------------------------------------------------'
+      call Print_msg_multi( NVERB_WARNING, 'BUD', 'Sourcelist_scan', ymsg )
+      !To not read the 1st line again
+      istart = 2
+    end if
+  end if
+
+  ! Case 'LIST_ALL': list all the source terms
+  if ( Size( hbulist ) > 0 ) then
+    if ( Trim( hbulist(1) ) == 'LIST_ALL' ) then
+      Allocate( character(len=65) :: ymsg(tpbudget%nsourcesmax + 1) )
+      ymsg(1) = '---------------------------------------------------------------------'
+      ymsg(2) = 'Source terms for budget ' // Trim( tpbudget%cname )
+      Write( ymsg(3), '( A32, " ", A32 )' ) 'Name', 'Long name'
+      idx = 3
+      do ji = 1, tpbudget%nsourcesmax
+        if ( All( tpbudget%tsources(ji)%cmnhname /= [ 'INIF' , 'ENDF', 'AVEF' ] ) ) then
+          idx = idx + 1
+          Write( ymsg(idx), '( A32, " ", A32 )' ) tpbudget%tsources(ji)%cmnhname, tpbudget%tsources(ji)%clongname
+        end if
+      end do
+      ymsg(tpbudget%nsourcesmax + 1 ) = '---------------------------------------------------------------------'
+      call Print_msg_multi( NVERB_WARNING, 'BUD', 'Sourcelist_scan', ymsg )
+      !To not read the 1st line again
+      istart = 2
+    end if
+  end if
+
+  ! Case 'ALL': enable all available source terms
+  if ( Size( hbulist ) > 0 ) then
+    if ( Trim( hbulist(1) ) == 'ALL' ) then
+      do ji = 1, tpbudget%nsources
+        tpbudget%tsources(ji)%ngroup = 1
+      end do
+      return
+    end if
+  end if
+
   !Always enable INIF, ENDF and AVEF terms
   ipos = Source_find( tpbudget, 'INIF' )
   if ( ipos < 1 ) call Print_msg( NVERB_FATAL, 'BUD', 'Sourcelist_scan', 'source term ' // Trim( tpbudget%cname ) &
@@ -4444,7 +4500,7 @@ subroutine Sourcelist_scan( tpbudget, hbulist )
   !igroup_idx start at 2 because 1 is reserved for individually stored source terms
   igroup_idx = 2
 
-  do ji = 1, Size( hbulist )
+  do ji = istart, Size( hbulist )
     if ( Len_trim( hbulist(ji) ) > 0 ) then
       ! Scan the line and separate the different sources (separated by + signs)
       yline = Trim(hbulist(ji))
-- 
GitLab