From 78e5e5516f611414dcf482ad550e199aab2f8797 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Fri, 28 Aug 2020 11:51:43 +0200
Subject: [PATCH] Philippe 28/08/2020: budgets: LES_NORM_4D: improve treatment
 of units (problems when too many space characters at the end)

---
 src/MNH/mode_les_diachro.f90 | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/MNH/mode_les_diachro.f90 b/src/MNH/mode_les_diachro.f90
index fb99217eb..536ab8fc2 100644
--- a/src/MNH/mode_les_diachro.f90
+++ b/src/MNH/mode_les_diachro.f90
@@ -170,6 +170,7 @@ integer :: ipower_kg_1st
 integer :: ji
 integer, dimension ( NNORMS ) :: ipowers
 character( len = 8 ) :: yun, yname, ypower
+character( len = : ), allocatable :: yunit
 character( len = 8 ), dimension( NMAXUNITS ) :: yunits
 logical :: gsv
 !------------------------------------------------------------------------------
@@ -187,20 +188,22 @@ inunits = 0
 ikg = 0
 idx = 1
 
+yunit = trim( hunit )
+
 !Separate units
 do
-  ispace = scan( hunit(idx: ), ' ' )
+  ispace = scan( yunit(idx: ), ' ' )
   if ( ispace == 0 ) then
     inunits = inunits + 1
     if (inunits > NMAXUNITS ) call Print_msg( NVERB_FATAL, 'GEN', 'LES_NORM_4D', 'inunits > NMAXUNITS' )
-    yunits(inunits ) = hunit(idx:)
+    yunits(inunits ) = yunit(idx:)
     exit
-  else if ( ispace == len(hunit(idx: )) ) then
+  else if ( ispace == len(yunit(idx: )) ) then
     exit
   else
     inunits = inunits + 1
     if (inunits > NMAXUNITS ) call Print_msg( NVERB_FATAL, 'GEN', 'LES_NORM_4D', 'inunits > NMAXUNITS' )
-    yunits(inunits ) =  hunit( idx : idx+ispace-1 )
+    yunits(inunits ) =  yunit( idx : idx+ispace-1 )
     idx = idx + ispace
   end if
 end do
-- 
GitLab