From 3cc7d5e584100565db7abc3404a26dec886cfeba Mon Sep 17 00:00:00 2001
From: Quentin Rodier <quentin.rodier@meteo.fr>
Date: Thu, 30 Sep 2021 18:08:49 +0200
Subject: [PATCH] Quentin 30/09/2021: bugfix RESTART reproductibility. The
 surfex online diagnostics (but included pseudo-pronostic variables such as
 TSRAD) are written at a time step of +1 in advance with respect to the
 atmospheric variables which lead to wrong computation of fluxes (such as
 radiative) at the initial step of a RESTART

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

diff --git a/src/MNH/modeln.f90 b/src/MNH/modeln.f90
index ea53387a5..82bccf250 100644
--- a/src/MNH/modeln.f90
+++ b/src/MNH/modeln.f90
@@ -972,6 +972,10 @@ IF ( nfile_backup_current < NBAK_NUMB ) THEN
       TFILE_SURFEX => TZBAKFILE
       CALL GOTO_SURFEX(IMI)
       CALL WRITE_SURF_ATM_n(YSURF_CUR,'MESONH','ALL',.FALSE.)
+      IF ( nfile_backup_current -1 > 0) THEN
+        CALL DIAG_SURF_ATM_n(YSURF_CUR,'MESONH')
+        CALL WRITE_DIAG_SURF_ATM_n(YSURF_CUR,'MESONH','ALL')
+      END IF
       NULLIFY(TFILE_SURFEX)
     END IF
     !
@@ -1426,17 +1430,6 @@ IF (CDCONV/='NONE') THEN
   END IF
 END IF
 !
-IF ( nfile_backup_current > 0 .AND. nfile_backup_current <= NBAK_NUMB ) THEN
-  IF ( KTCOUNT == TBACKUPN(nfile_backup_current)%NSTEP ) THEN
-    IF (CSURF=='EXTE') THEN
-      CALL GOTO_SURFEX(IMI)
-      CALL DIAG_SURF_ATM_n(YSURF_CUR,'MESONH')
-      TFILE_SURFEX => TZBAKFILE
-      CALL WRITE_DIAG_SURF_ATM_n(YSURF_CUR,'MESONH','ALL')
-      NULLIFY(TFILE_SURFEX)
-    END IF
-  END IF
-END IF
 !
 CALL SECOND_MNH2(ZTIME2)
 !
-- 
GitLab