From 05cc29a90c245f26176908b218ad5f9e4edfd0e3 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Thu, 5 Apr 2018 11:35:35 +0200
Subject: [PATCH] Philippe 05/04/2018: IO: add NMODEL field to TFILEDATA type
 needed to manage correctly domain number when writing dimension variables

---
 src/LIB/SURCOUCHE/src/modd_io.f90               | 2 ++
 src/LIB/SURCOUCHE/src/mode_io_manage_struct.f90 | 8 ++++++--
 src/MNH/open_nestpgd_files.f90                  | 4 ++--
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/LIB/SURCOUCHE/src/modd_io.f90 b/src/LIB/SURCOUCHE/src/modd_io.f90
index a3bfbd886..b7b9966ad 100644
--- a/src/LIB/SURCOUCHE/src/modd_io.f90
+++ b/src/LIB/SURCOUCHE/src/modd_io.f90
@@ -85,6 +85,8 @@ TYPE TFILEDATA
                                                !the 2 sub-files are abcd.Z001 and abcd.Z002
   TYPE(TFILE_ELT),DIMENSION(:),ALLOCATABLE :: TFILES_IOZ !Corresponding Z-splitted files
   !
+  INTEGER           :: NMODEL = 0          !Model number corresponding to the file (field not always set)
+  !
   ! Fields for LFI files
   INTEGER(KIND=LFI_INT) :: NLFININAR = 0  !Number of articles of the LFI file (only accurate if file opened in read mode)
   INTEGER(KIND=LFI_INT) :: NLFINPRAR = 0  !Number of predicted articles of the LFI file (non crucial)
diff --git a/src/LIB/SURCOUCHE/src/mode_io_manage_struct.f90 b/src/LIB/SURCOUCHE/src/mode_io_manage_struct.f90
index 1d3991a46..c6ecbd17e 100644
--- a/src/LIB/SURCOUCHE/src/mode_io_manage_struct.f90
+++ b/src/LIB/SURCOUCHE/src/mode_io_manage_struct.f90
@@ -573,8 +573,9 @@ END SUBROUTINE POPULATE_STRUCT
 !
 END SUBROUTINE IO_PREPARE_BAKOUT_STRUCT
 !
-SUBROUTINE IO_FILE_ADD2LIST(TPFILE,HNAME,HTYPE,HMODE, &
-                            HFORM,HACCESS,HFORMAT,KLFINPRAR,KLFITYPE,KLFIVERB,KRECL,TPDADFILE,TPDATAFILE,OOLD)
+SUBROUTINE IO_FILE_ADD2LIST(TPFILE,HNAME,HTYPE,HMODE,                                &
+                            HFORM,HACCESS,HFORMAT,KLFINPRAR,KLFITYPE,KLFIVERB,KRECL, &
+                            KMODEL,TPDADFILE,TPDATAFILE,OOLD)
 !
 USE MODD_BAKOUT,         ONLY: LOUT_COMPRESS,LOUT_REDUCE_FLOAT_PRECISION,NOUT_COMPRESS_LEVEL
 USE MODD_CONF,           ONLY: CPROGRAM
@@ -592,6 +593,7 @@ INTEGER(KIND=LFI_INT),  OPTIONAL,INTENT(IN)    :: KLFINPRAR !Number of predicted
 INTEGER,                OPTIONAL,INTENT(IN)    :: KLFITYPE  !Type of the file (used to generate list of files to transfers)
 INTEGER,                OPTIONAL,INTENT(IN)    :: KLFIVERB  !LFI verbosity level
 INTEGER,                OPTIONAL,INTENT(IN)    :: KRECL     !Record length
+INTEGER,                OPTIONAL,INTENT(IN)    :: KMODEL    !Model number
 TYPE(TFILEDATA),POINTER,OPTIONAL,INTENT(IN)    :: TPDADFILE !Corresponding dad file
 TYPE(TFILEDATA),POINTER,OPTIONAL,INTENT(IN)    :: TPDATAFILE!Corresponding data file (used only for DES files)
 LOGICAL,                OPTIONAL,INTENT(IN)    :: OOLD      !FALSE if new file (should not be found)
@@ -836,6 +838,8 @@ SELECT CASE(TPFILE%CTYPE)
     END IF
 END SELECT
 !
+IF(PRESENT(KMODEL)) TPFILE%NMODEL = KMODEL
+!
 TPFILE%LOPENED = .FALSE.
 TPFILE%NOPEN   = 0
 TPFILE%NCLOSE  = 0
diff --git a/src/MNH/open_nestpgd_files.f90 b/src/MNH/open_nestpgd_files.f90
index e8d5a26a9..743e498a2 100644
--- a/src/MNH/open_nestpgd_files.f90
+++ b/src/MNH/open_nestpgd_files.f90
@@ -310,11 +310,11 @@ DO JPGD=1,NMODEL
   IF (NDAD(JPGD)>=1) THEN
     TZDADFILE => TPFILENESTPGD(NDAD(JPGD))%TZFILE
     CALL IO_FILE_ADD2LIST(TPFILENESTPGD(JPGD)%TZFILE,TRIM(YPGD(JPGD))//'.nest'//ADJUSTL(YNEST),'PREPNESTPGD', &
-                          'WRITE',KLFITYPE=1,KLFIVERB=NVERB,TPDADFILE=TZDADFILE)
+                          'WRITE',KLFITYPE=1,KLFIVERB=NVERB,KMODEL=JPGD,TPDADFILE=TZDADFILE)
   ELSE
     NULLIFY(TZDADFILE)
     CALL IO_FILE_ADD2LIST(TPFILENESTPGD(JPGD)%TZFILE,TRIM(YPGD(JPGD))//'.nest'//ADJUSTL(YNEST),'PREPNESTPGD', &
-                          'WRITE',KLFITYPE=1,KLFIVERB=NVERB)
+                          'WRITE',KLFITYPE=1,KLFIVERB=NVERB,KMODEL=JPGD)
   END IF
 END DO
 !
-- 
GitLab