From 74ed8511c880c19b67584610cd66091963091b8f Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Fri, 18 Mar 2022 15:51:55 +0100
Subject: [PATCH] Philippe 18/03/2022: bugfix: correct xseglen by removing
 xtstep of first model

(cherry picked from commit 6dbfd11a0ec7c7608e84586cb228b0f704458235)
---
 src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90 | 8 ++++----
 src/MNH/ground_paramn.f90                   | 6 +++---
 src/MNH/ini_aircraft_balloon.f90            | 4 ++--
 src/MNH/ini_lesn.f90                        | 4 ++--
 src/MNH/ini_posprofilern.f90                | 4 ++--
 src/MNH/ini_surfstationn.f90                | 8 ++------
 6 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90 b/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
index 50412e8c0..b436b0d18 100644
--- a/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
+++ b/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 1994-2021 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 1994-2022 CNRS, Meteo-France and Universite Paul Sabatier
 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
 !MNH_LIC for details. version 1.
@@ -252,7 +252,7 @@ USE MODD_CONF,          ONLY: CPROGRAM, l2d, lpack
 USE MODD_CONF_n,        ONLY: CSTORAGE_TYPE
 USE MODD_DIM_n,         ONLY: NIMAX_ll, NJMAX_ll, NKMAX
 use modd_dyn,           only: xseglen
-use modd_dyn_n,         only: xtstep
+use modd_dyn_n,         only: dyn_model
 use modd_field,         only: NMNHDIM_NI, NMNHDIM_NJ, NMNHDIM_NI_U, NMNHDIM_NJ_U, NMNHDIM_NI_V, NMNHDIM_NJ_V,   &
                               NMNHDIM_LEVEL, NMNHDIM_LEVEL_W, NMNHDIM_TIME,                                     &
                               NMNHDIM_ONE,  NMNHDIM_NSWB, NMNHDIM_NLWB, NMNHDIM_COMPLEX,                        &
@@ -421,13 +421,13 @@ if ( tpfile%ctype == 'MNHDIACHRONIC' ) then
 
   !Dimension for the number of profiler times
   if ( numbprofiler > 0 ) then
-    iprof = Int ( ( xseglen - xtstep ) / tprofiler%step ) + 1
+    iprof = Nint ( ( xseglen - dyn_model(1)%xtstep ) / tprofiler%step ) + 1
     call IO_Add_dim_nc4( tpfile, NMNHDIM_PROFILER_TIME, 'time_profiler', iprof )
   end if
 
   !Dimension for the number of station times
   if ( numbstat > 0 ) then
-    istation = Int ( ( xseglen - xtstep ) / tstation%step ) + 1
+    istation = Nint ( ( xseglen - dyn_model(1)%xtstep ) / tstation%step ) + 1
     call IO_Add_dim_nc4( tpfile, NMNHDIM_STATION_TIME, 'time_station', istation )
   end if
 
diff --git a/src/MNH/ground_paramn.f90 b/src/MNH/ground_paramn.f90
index f440efcb7..68e38a1c3 100644
--- a/src/MNH/ground_paramn.f90
+++ b/src/MNH/ground_paramn.f90
@@ -123,7 +123,7 @@ USE MODI_GET_HALO
 USE MODI_MNH_OASIS_RECV
 USE MODI_MNH_OASIS_SEND
 USE MODD_SFX_OASIS, ONLY : LOASIS
-USE MODD_DYN, ONLY : XSEGLEN
+USE MODD_DYN,        ONLY: DYN_MODEL, XSEGLEN
 #endif
 !
 USE MODD_LUNIT_n, ONLY: TLUOUT
@@ -575,7 +575,7 @@ CALL DATETIME_DISTANCE(TDTSEG,TDTCUR,ZTIMEC)
 #ifdef CPLOASIS
 IF (LOASIS) THEN
   IF ( MOD(ZTIMEC,1.0) .LE. 1E-2 .OR. (1.0 - MOD(ZTIMEC,1.0)) .LE. 1E-2 ) THEN
-    IF ( NINT(ZTIMEC-(XSEGLEN-XTSTEP)) .LT. 0 ) THEN
+    IF ( NINT(ZTIMEC-(XSEGLEN-DYN_MODEL(1)%XTSTEP)) .LT. 0 ) THEN
       WRITE(ILUOUT,*) '----------------------------'
       WRITE(ILUOUT,*) ' Reception des champs avec OASIS'
       WRITE(ILUOUT,*) 'NINT(ZTIMEC)=', NINT(ZTIMEC)
@@ -605,7 +605,7 @@ CALL COUPLING_SURF_ATM_n(YSURF_CUR,'MESONH', 'E',ZTIMEC,
 #ifdef CPLOASIS
 IF (LOASIS) THEN
   IF ( MOD(ZTIMEC,1.0) .LE. 1E-2 .OR. (1.0 - MOD(ZTIMEC,1.0)) .LE. 1E-2 ) THEN
-    IF (NINT(ZTIMEC-(XSEGLEN-XTSTEP)) .LT. 0) THEN
+    IF (NINT(ZTIMEC-(XSEGLEN-DYN_MODEL(1)%XTSTEP)) .LT. 0) THEN
       WRITE(ILUOUT,*) '----------------------------'
       WRITE(ILUOUT,*) ' Envoi des champs avec OASIS'
       WRITE(ILUOUT,*) 'NINT(ZTIMEC)=', NINT(ZTIMEC)
diff --git a/src/MNH/ini_aircraft_balloon.f90 b/src/MNH/ini_aircraft_balloon.f90
index 0b22d3403..cdb990bb7 100644
--- a/src/MNH/ini_aircraft_balloon.f90
+++ b/src/MNH/ini_aircraft_balloon.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 2000-2020 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 2000-2022 CNRS, Meteo-France and Universite Paul Sabatier
 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
 !MNH_LIC for details. version 1.
@@ -360,7 +360,7 @@ IF (IMI /= TPFLYER%NMODEL .AND. .NOT. (IMI==1 .AND. TPFLYER%NMODEL==0) ) RETURN
 IF ( CPROGRAM == 'DIAG  ' ) THEN
   ISTORE = INT ( NTIME_AIRCRAFT_BALLOON / TPFLYER%STEP ) + 1
 ELSE
-  ISTORE = INT ( (PSEGLEN-XTSTEP) / TPFLYER%STEP ) + 1
+  ISTORE = NINT ( ( PSEGLEN - DYN_MODEL(1)%XTSTEP ) / TPFLYER%STEP ) + 1
 ENDIF
 !
 IF (TPFLYER%NMODEL == 0) ISTORE=0
diff --git a/src/MNH/ini_lesn.f90 b/src/MNH/ini_lesn.f90
index 45d7b9f9a..05a30c423 100644
--- a/src/MNH/ini_lesn.f90
+++ b/src/MNH/ini_lesn.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 2000-2021 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 2000-2022 CNRS, Meteo-France and Universite Paul Sabatier
 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
 !MNH_LIC for details. version 1.
@@ -321,7 +321,7 @@ XLES_TEMP_SAMPLING = XTSTEP * NLES_DTCOUNT
 !            ----------------------------------------
 !
 !
-NLES_TIMES = ( INT( (XSEGLEN-XTSTEP+1.E-6) / XTSTEP ) ) / NLES_DTCOUNT
+NLES_TIMES = ( NINT( ( XSEGLEN - DYN_MODEL(1)%XTSTEP ) / XTSTEP ) ) / NLES_DTCOUNT
 !
 !*      3.5  current LES time counter
 !            ------------------------
diff --git a/src/MNH/ini_posprofilern.f90 b/src/MNH/ini_posprofilern.f90
index 08b25fba1..00279c8a8 100644
--- a/src/MNH/ini_posprofilern.f90
+++ b/src/MNH/ini_posprofilern.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 1994-2021 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 1994-2022 CNRS, Meteo-France and Universite Paul Sabatier
 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
 !MNH_LIC for details. version 1.
@@ -156,7 +156,7 @@ SUBROUTINE ALLOCATE_PROFILER_n(TPROFILER)
 !
 TYPE(PROFILER), INTENT(INOUT) :: TPROFILER
 !
-ISTORE = INT ( (PSEGLEN-XTSTEP) / TPROFILER%STEP ) + 1
+ISTORE = NINT( ( PSEGLEN - DYN_MODEL(1)%XTSTEP ) / TPROFILER%STEP ) + 1
 !
 allocate( tprofiler%tpdates( istore ) )
 ALLOCATE(TPROFILER%ERROR (NUMBPROFILER))
diff --git a/src/MNH/ini_surfstationn.f90 b/src/MNH/ini_surfstationn.f90
index f53ee35d1..5b79bb289 100644
--- a/src/MNH/ini_surfstationn.f90
+++ b/src/MNH/ini_surfstationn.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 1994-2021 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 1994-2022 CNRS, Meteo-France and Universite Paul Sabatier
 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
 !MNH_LIC for details. version 1.
@@ -171,11 +171,7 @@ if ( tstation%step < xtstep ) then
   tstation%step = xtstep
 end if
 
-IF (KMI==1) THEN
- ISTORE = NINT ( (PSEGLEN-XTSTEP) / TSTATION%STEP ) + 1
-ELSE 
- ISTORE = NINT ( (PSEGLEN-XTSTEP * NDTRATIO(KMI)) / TSTATION%STEP ) + 1
-END IF
+ISTORE = NINT ( ( PSEGLEN - DYN_MODEL(1)%XTSTEP ) / TSTATION%STEP ) + 1
 
 allocate( tstation%tpdates( istore ) )
 ALLOCATE(TSTATION%ERROR (NUMBSTAT))
-- 
GitLab