From 158a611193fc1b9c3044d0e381da9c4da3c52561 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Fri, 12 Apr 2024 09:15:41 +0200
Subject: [PATCH] Philippe 12/04/2024: Fill_tfieldmetadata: populate ndimlist
 if CDIR=XX, YY or ZZ

---
 src/LIB/SURCOUCHE/src/modd_field.f90 | 30 +++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/LIB/SURCOUCHE/src/modd_field.f90 b/src/LIB/SURCOUCHE/src/modd_field.f90
index 7f44477b9..8d75b37d6 100644
--- a/src/LIB/SURCOUCHE/src/modd_field.f90
+++ b/src/LIB/SURCOUCHE/src/modd_field.f90
@@ -315,6 +315,7 @@ type(tfieldmetadata) function Fill_tfieldmetadata( cmnhname, cstdname, clongname
   logical,               optional, intent(in) :: ltimedep
 
   character(len=:), allocatable :: ymnhname
+  logical                       :: gdimlistfilled
 
   ! cmnhname
   if ( Present( cmnhname ) ) then
@@ -418,29 +419,44 @@ type(tfieldmetadata) function Fill_tfieldmetadata( cmnhname, cstdname, clongname
     tpfield%ndimlist(tpfield%ndims+1:) = NMNHDIM_UNUSED
   else
     !If ndimlist is not provided, it is possible to fill it if some information is available
+    gdimlistfilled = .false.
     if ( Present( cdir ) ) then
       if ( cdir == 'XY' ) then
         ! Check also on NGRIDUNKNOWN (this happens if the optional ngrid argument is not provided)
         if ( tpfield%ndims == 2 .and. tpfield%ngrid /= NGRIDUNKNOWN ) then
           tpfield%ndimlist(1:2) = NMNHDIM_ARAKAWA(tpfield%ngrid,1:2)
+          gdimlistfilled = .true.
         else if ( tpfield%ndims == 3 .and. tpfield%ngrid /= NGRIDUNKNOWN ) then
           tpfield%ndimlist(1:3) = NMNHDIM_ARAKAWA(tpfield%ngrid,1:3)
+          gdimlistfilled = .true.
         else if ( tpfield%ndims == 4 .and. tpfield%ngrid /= NGRIDUNKNOWN ) then
           tpfield%ndimlist(1:3) = NMNHDIM_ARAKAWA(tpfield%ngrid,1:3)
           tpfield%ndimlist(4) = NMNHDIM_NOTLISTED
-        else
-          call Print_msg( NVERB_DEBUG, 'GEN', 'Fill_tfielddata', 'ndimlist not filled for variable ' // Trim( ymnhname ) )
+          gdimlistfilled = .true.
+        end if
+      else if ( cdir == 'XX' ) then
+        if ( tpfield%ndims == 1 .and. tpfield%ngrid /= NGRIDUNKNOWN ) then
+          tpfield%ndimlist(1) = NMNHDIM_ARAKAWA(tpfield%ngrid,1)
+          gdimlistfilled = .true.
+        end if
+      else if ( cdir == 'YY' ) then
+        if ( tpfield%ndims == 1 .and. tpfield%ngrid /= NGRIDUNKNOWN ) then
+          tpfield%ndimlist(1) = NMNHDIM_ARAKAWA(tpfield%ngrid,2)
+          gdimlistfilled = .true.
+        end if
+      else if ( cdir == 'ZZ' ) then
+        if ( tpfield%ndims == 1 .and. tpfield%ngrid /= NGRIDUNKNOWN ) then
+          tpfield%ndimlist(1) = NMNHDIM_ARAKAWA(tpfield%ngrid,3)
+          gdimlistfilled = .true.
         end if
-      else
-        call Print_msg( NVERB_DEBUG, 'GEN', 'Fill_tfielddata', 'ndimlist not filled for variable ' // Trim( ymnhname ) )
       end if
-    else
-      call Print_msg( NVERB_DEBUG, 'GEN', 'Fill_tfielddata', 'ndimlist not filled for variable ' // Trim( ymnhname ) )
     end if
+    if (.not. gdimlistfilled ) &
+      call Print_msg( NVERB_DEBUG, 'GEN', 'Fill_tfielddata', 'ndimlist not filled for variable ' // Trim( ymnhname ) )
   end if
   if ( Present( ltimedep ) ) then
     if ( ltimedep ) then
-      if ( tpfield%ndims == NMNHMAXDIMS )                                                                        &
+      if ( tpfield%ndims == NMNHMAXDIMS )                                                                &
         call Print_msg( NVERB_ERROR, 'GEN', 'Fill_tfielddata',                                           &
                         'ltimedep=T not possible if ndims=NMNHMAXDIMS for variable ' // Trim( ymnhname ) )
       !Set this dimension only if ndimlist already filled up or tpfield%ndims = 0
-- 
GitLab