13531cc112b667a48b57e58bda7383e62af6b98e
[MNH-git_open_source-lfs.git] / src / MNH / modeln.f90
1 !MNH_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
3 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt  
4 !MNH_LIC for details. version 1.
5 !-----------------------------------------------------------------
6 !--------------- special set of characters for RCS information
7 !-----------------------------------------------------------------
8 ! $Source: /home/cvsroot/MNH-VX-Y-Z/src/MNH/modeln.f90,v $ $Revision: 1.3.2.5.2.5.2.9.2.12.2.7.2.4 $
9 !-----------------------------------------------------------------
10 !     ###################
11       MODULE MODI_MODEL_n
12 !     ###################
13 !
14 INTERFACE
15 !
16        SUBROUTINE MODEL_n(KTCOUNT,OEXIT)
17 !
18 INTEGER, INTENT(IN)   :: KTCOUNT  ! temporal loop index of model KMODEL
19 LOGICAL, INTENT(INOUT):: OEXIT    ! switch for the end of the temporal loop
20 !
21 END SUBROUTINE MODEL_n
22 !
23 END INTERFACE
24 !
25 END MODULE MODI_MODEL_n
26
27 !     ################################### 
28       SUBROUTINE MODEL_n(KTCOUNT, OEXIT) 
29 !     ###################################
30 !
31 !!****  *MODEL_n * -monitor of the model version _n 
32 !!
33 !!    PURPOSE
34 !!    -------
35 !       The purpose of this routine is to build up a typical model version
36 !     by sequentially calling the specialized routines.
37 !
38 !!**  METHOD
39 !!    ------
40 !!      Some preliminary initializations are performed in the first section.
41 !!    Then, specialized routines are called to update the guess of the future
42 !!    instant XRxxS of the variable xx by adding the effects of all the
43 !!    different sources of evolution.
44 !!
45 !!              (guess of xx at t+dt) * Rhod_ref * Jacobian
46 !!      XRxxS = -------------------------------------------
47 !!                           2 dt
48 !!
49 !!      At this level, the informations are transferred with a USE association
50 !!    from the INIT step, where the modules have been previously filled. The
51 !!    transfer to the subroutines computing each source term is performed by
52 !!    argument in order to avoid repeated compilations of these subroutines.
53 !!      This monitor model_n, must therefore be duplicated for each model,
54 !!    model1 corresponds in this case to the outermost model, model2 is used
55 !!    for the first level of gridnesting,....  
56 !!      The effect of all parameterizations is computed in PHYS_PARAM_n, which
57 !!    is itself a monitor. This is due to a possible large number of
58 !!    parameterizations, which can be activated and therefore, will require a
59 !!    very large list of arguments. To circumvent this problem, we transfer by
60 !!    a USE association, the necessary informations in this monitor, which will
61 !!    dispatch the pertinent information to every parametrization.
62 !!      Some elaborated diagnostics, LES tools, budget storages are also called
63 !!    at this level because they require informations about the fields at every
64 !!    timestep.
65 !!
66 !!
67 !!    EXTERNAL
68 !!    --------
69 !!      Subroutine FMLOOK: to recover the logical unit number linked to a FMfile
70 !!      Subroutine FMOPEN: to open a FMfile
71 !!      Subroutine WRITE_DESFM: to write the descriptive part of a FMfile
72 !!      Subroutine WRITE_LFIFM: to write the binary part of a FMfile
73 !!      Subroutine SET_MASK   : to compute all the masks selected for budget
74 !!                         computations
75 !!      Subroutine BOUNDARIES   : set the fields at the marginal points in every
76 !!                         directions according the selected boundary conditions
77 !!      Subroutine INITIAL_GUESS: initializes the guess of the future instant
78 !!      Subroutine LES_FLX_SPECTRA: computes the resolved fluxes and the
79 !!                     spectra of some quantities when running in LES mode.
80 !!      Subroutine ADVECTION: computes the advection terms.
81 !!      Subroutine DYN_SOURCES: computes the curvature, Coriolis, gravity terms.
82 !!      Subroutine NUM_DIFF: applies the fourth order numerical diffusion.
83 !!      Subroutine RELAXATION: performs the relaxation to Larger Scale fields
84 !!                             in the upper levels and outermost vertical planes
85 !!      Subroutine PHYS_PARAM_n : computes the parameterized physical terms
86 !!      Subroutine RAD_BOUND: prepares the velocity normal components for the bc.
87 !!      Subroutine RESOLVED_CLOUD : computes the sources terms for water in any
88 !!                                  form
89 !!      Subroutine PRESSURE : computes the pressure gradient term and the
90 !!                            absolute pressure
91 !!      Subroutine EXCHANGE : updates the halo of each subdomains
92 !!      Subroutine ENDSTEP : advances in time the  fields.
93 !!      Subroutines UVW_LS_COUPLING and SCALAR_LS_COUPLING:
94 !!                                 compute the large scale fields, used to
95 !!                                 couple Model_n with outer informations.
96 !!      Subroutine ENDSTEP_BUDGET: writes the budget informations.
97 !!      Subroutine FMCLOS        : closes a FM file
98 !!      Subroutine ADD_FORECAST_TO_DATE : transform the current time in GMT
99 !!      Subroutine FORCING : computes forcing terms
100 !!      Subroutine ADD3DFIELD_ll : add a field to 3D-list
101 !!
102 !!    IMPLICIT ARGUMENTS
103 !!    ------------------
104 !!          MODD_DYN
105 !!          MODD_CONF
106 !!          MODD_NESTING
107 !!          MODD_BUDGET
108 !!          MODD_PARAMETERS
109 !!          MODD_CONF_n
110 !!          MODD_CURVCOR_n
111 !!          MODD_DYN_n
112 !!          MODD_DIM_n
113 !!          MODD_ADV_n
114 !!          MODD_FIELD_n
115 !!          MODD_LSFIELD_n
116 !!          MODD_GRID_n
117 !!          MODD_METRICS_n
118 !!          MODD_LBC_n
119 !!          MODD_PARAM_n
120 !!          MODD_REF_n
121 !!          MODD_LUNIT_n
122 !!          MODD_OUT_n
123 !!          MODD_TIME_n
124 !!          MODD_TURB_n
125 !!          MODD_CLOUDPAR_n
126 !!          MODD_TIME
127 !!
128 !!    REFERENCE
129 !!    ---------
130 !!
131 !!    AUTHOR
132 !!    ------
133 !!      J.-P. Pinty                  * LA *
134 !!
135 !!    MODIFICATIONS
136 !!    -------------
137 !!      Original    15/09/94
138 !!      Modification 20/10/94  (J.Stein) for the outputs and abs_layers routines
139 !!      Modification 10/11/94  (J.Stein) change ABS_LAYER_FIELDS call
140 !!      Modification 16/11/94  (J.Stein) add call to the renormalization
141 !!      Modification 17/11/94  (J.-P. Lafore and J.-P. Pinty) call NUM_DIFF
142 !!      Modification 08/12/94  (J.Stein) cleaning + remove (RENORM + ABS_LAYER..
143 !!                             ..) + add RELAXATION + LS fiels in the arguments
144 !!      Modification 19/12/94  (J.Stein) switch for the num diff
145 !!      Modification 22/12/94  (J.Stein) update tdtcur + change dyn_source call
146 !!      Modification 05/01/95  (J.Stein) add the parameterization monitor
147 !!      Modification 09/01/95  (J.Stein) add the 1D switch
148 !!      Modification 10/01/95  (J.Stein) displace the TDTCUR computation
149 !!      Modification 03/01/95  (J.-P. Lafore) Absolute pressure diagnosis
150 !!      Modification Jan 19, 1995 (J. Cuxart) Shunt the DYN_SOURCES in 1D cases.
151 !!      Modification Jan 24, 1995 (J. Stein)  Interchange Boundaries and
152 !!                           Initial_guess to correct a bug in 2D configuration
153 !!      Modification Feb 02, 1995 (I.Mallet) update BOUNDARIES and RAD_BOUND
154 !!                                           calls
155 !!      Modification Mar 10, 1995 (I.Mallet) add call to SET_COUPLING
156 !!                   March,21, 1995 (J. Stein) remove R from the historical var.
157 !!                   March,26, 1995 (J. Stein) add the EPS variable
158 !!                   April 18, 1995 (J. Cuxart) add the LES call
159 !!                   Sept 20,1995 (Lafore) coupling for the dry mass Md
160 !!                   Nov   2,1995 (Stein) displace the temporal counter increase
161 !!                   Jan   2,1996 (Stein) rm the test on the temporal counter
162 !!      Modification Feb   5,1996 (J. Vila) implementation new advection
163 !!                                          schemes for scalars
164 !!      Modification Feb  20,1996 (J.Stein) doctor norm
165 !!                   Dec95 - Jul96 (Georgelin, Pinty, Mari, Suhre) FORCING
166 !!                   June 17,1996 (Vincent, Lafore, Jabouille)
167 !!                                        statistics of computing time
168 !!                   Aug 8, 1996 (K. Suhre) add chemistry
169 !!                   October 12, 1996 (J. Stein) save the PSRC value
170 !!                   Sept 05,1996 (V.Masson) print of loop index for debugging
171 !!                                           purposes
172 !!                   July 22,1996 (Lafore) improve write of computing time statistics
173 !!                   July 29,1996 (Lafore) nesting introduction
174 !!                   Aug.  1,1996 (Lafore) synchronization between models
175 !!                   Sept. 4,1996 (Lafore) modification of call to routine SET_COUPLING
176 !!                                         now splitted in 2 routines
177 !!                                         (UVW_LS_COUPLING and SCALAR_LS_COUPLING)
178 !!                   Sept  5,1996 (V.Masson) print of loop index for debugging
179 !!                                           purposes
180 !!                   Sept 25,1996 (V.Masson) test for coupling performed here
181 !!                   Oct. 29,1996 (Lafore)   one-way nesting implementation
182 !!                   Oct. 12,1996 (J. Stein) save the PSRC value
183 !!                   Dec. 12,1996 (Lafore)   change call to RAD_BOUND
184 !!                   Dec. 21,1996 (Lafore)   two-way nesting implementation
185 !!                   Mar. 12,1997 (Lafore)   introduction of "surfacic" LS fields
186 !!                   Nov 18, 1996 (J.-P. Pinty) FORCING revisited (translation)
187 !!                   Dec 04, 1996 (J.-P. Pinty) include mixed-phase clouds
188 !!                   Dec 20, 1996 (J.-P. Pinty) update the budgets
189 !!                   Dec 23, 1996 (J.-P. Pinty) add the diachronic file control
190 !!                   Jan 11, 1997 (J.-P. Pinty) add the deep convection control
191 !!                   Dec  20,1996 (V.Masson) call boundaries before the writing
192 !!                   Fev 25, 1997 (P.Jabouille) modify the LES tools
193 !!                   April 3,1997 (Lafore)      merging of the nesting
194 !!                                              developments on MASTER3
195 !!                   Jul.  8,1997 (Lafore)  print control for nesting (NVERB>=7)
196 !!                   Jul. 28,1997 (Masson)  supress LSTEADY_DMASS
197 !!                   Aug. 19,1997 (Lafore)  full Clark's formulation introduction
198 !!                   Sept 26,1997 (Lafore)  LS source calculation at restart
199 !!                                          (temporarily test to have LS at instant t)
200 !!                   Jan. 28,1998 (Bechtold) add SST forcing
201 !!                   fev. 10,1998 (Lafore)  RHODJ computation and storage for budget
202 !!                   Jul. 10,1998 (Stein )  sequentiel loop for nesting
203 !!                   Apr. 07,1999 (Stein )  cleaning of the nesting subroutines
204 !!                   oct. 20,1998 (Jabouille) //
205 !!                   oct. 20,2000 (J.-P. Pinty) add the C2R2 scheme
206 !!                   fev. 01,2001 (D.Gazen) add module MODD_NSV for NSV variables
207 !!                   mar,  4,2002 (V.Ducrocq) call to temporal series
208 !!                   mar, 8, 2001 (V. Masson) advection of perturbation of theta in neutral cases.
209 !!                   Nov, 6, 2002 (V. Masson) time counters for budgets & LES
210 !!                   mars 20,2001 (Pinty)   add ICE4 and C3R5 options
211 !!                   jan. 2004    (Masson)  surface externalization
212 !!                   sept 2004 (M. Tomasini) Cloud mixing length modification
213 !!                   june 2005 (P. Tulet)  add aerosols / dusts
214 !!                   Jul. 2005 (N. Asencio)  two_way and phys_param calls: 
215 !!                             Add the surface parameters : precipitating 
216 !!                             hydrometeors, Short and Long Wave , MASKkids array 
217 !!                   Fev. 2006 (M. Leriche) add aqueous phase chemistry
218 !!                   april 2006 (T.Maric) Add halo related to 4th order advection scheme
219 !!                   May 2006 Remove KEPS
220 !!                   Oct 2008 (C.Lac) FIT for variables advected with PPM
221 !!                   July 2009 : Displacement of surface diagnostics call to be
222 !!                               coherent with  surface diagnostics obtained with DIAG
223 !!                   10/11/2009 (P. Aumond) Add mean moments
224 !!                   Nov, 12, 2009 (C. Barthe) add cloud electrification and lightning flashes
225 !!                   July 2010 (M. Leriche) add ice phase chemical species
226 !!                   April 2011 (C.Lac) : Remove instant M 
227 !!                   April 2011 (C.Lac, V.Masson) : Time splitting for advection
228 !!      J.Escobar 21/03/2013: for HALOK comment all NHALO=1 test
229 !!       P. Tulet      Nov 2014 accumulated moles of aqueous species that fall at the surface   
230 !!                   Dec 2014 (C.Lac) : For reproducibility START/RESTA
231 !!      J.Escobar 20/04/2015: missing UPDATE_HALO before UPDATE_HALO2
232 !!              July, 2015 (O.Nuissier/F.Duffourg) Add microphysics diagnostic for
233 !!                                      aircraft, ballon and profiler
234 !!       C.Lac    11/09/2015: correction of the budget due to FIT temporal scheme
235 !!      J.Escobar : 15/09/2015 : WENO5 & JPHEXT <> 1
236 !!                   Sep 2015 (S. Bielli) : Remove YDADFILE from argument call 
237 !!                              of write_phys_param
238 !!      J.Escobar : 19/04/2016 : Pb IOZ/NETCDF , missing OPARALLELIO=.FALSE. for PGD files
239 !!      M.Mazoyer : 04/2016      DTHRAD used for radiative cooling when LACTIT
240 !!      M.Leriche : 03/2016 Move computation of accumulated chem. in rain to ch_monitor
241 !!                  09/2016 Add filter on negative values on AERDEP SV before relaxation
242 !!-------------------------------------------------------------------------------
243 !
244 !*       0.     DECLARATIONS
245 !               ------------
246 !
247 USE MODE_ll
248 USE MODE_IO_ll
249 USE MODE_ELEC_ll
250 !
251 USE MODE_FM
252 !
253 USE MODD_TIME
254 USE MODD_DYN
255 USE MODD_DYNZD
256 USE MODD_CONF
257 USE MODD_NESTING
258 USE MODD_FMOUT
259 USE MODD_BUDGET
260 USE MODD_PARAMETERS
261 USE MODD_PARAM_ICE,        ONLY : LWARM,LSEDIC,LCONVHG
262 USE MODD_FRC
263 USE MODD_AIRCRAFT_BALLOON
264 USE MODD_STATION_n
265 USE MODD_PROFILER_n
266 USE MODD_PARAM_C2R2,      ONLY : LSEDC, LRAIN, LACTIT
267 USE MODD_PARAM_C1R3,      ONLY : LSEDI, LHHONI
268 USE MODD_LES
269 USE MODD_LES_BUDGET
270 USE MODD_LUNIT
271 USE MODD_GRID, ONLY: XLONORI,XLATORI
272 USE MODD_SERIES, ONLY: LSERIES
273 USE MODD_TURB_CLOUD, ONLY: NMODEL_CLOUD,CTURBLEN_CLOUD,XCEI
274 !
275 USE MODD_SUB_MODEL_n
276 USE MODD_GET_n
277 USE MODD_CONF_n
278 USE MODD_CURVCOR_n
279 USE MODD_DIM_n
280 USE MODD_DYN_n
281 USE MODD_DYNZD_n
282 USE MODD_ADV_n
283 USE MODD_FIELD_n
284 USE MODD_PAST_FIELD_n
285 USE MODD_MEAN_FIELD_n
286 USE MODD_MEAN_FIELD
287 USE MODD_LSFIELD_n
288 USE MODD_GRID_n
289 USE MODD_METRICS_n
290 USE MODD_LBC_n
291 USE MODD_PARAM_n
292 USE MODD_REF_n
293 USE MODD_FRC_n
294 USE MODD_LUNIT_n
295 USE MODD_OUT_n
296 USE MODD_TIME_n 
297 USE MODD_TURB_n
298 USE MODD_CLOUDPAR_n
299 USE MODD_PRECIP_n
300 USE MODD_BIKHARDT_n
301 USE MODD_DEEP_CONVECTION_n
302 USE MODD_NSV
303 USE MODD_RADIATIONS_n, ONLY : XTSRAD,XSCAFLASWD,XDIRFLASWD,XDIRSRFSWD, XAER, XDTHRAD
304 USE MODD_SERIES_n, ONLY: NFREQSERIES
305 USE MODD_CH_AERO_n,    ONLY: XSOLORG, XMI
306 USE MODD_CH_MNHC_n,    ONLY: LUSECHEM,LCH_CONV_LINOX,LUSECHAQ,LUSECHIC, &
307                              LCH_INIT_FIELD
308 USE MODD_CST, ONLY: XMD
309 USE MODD_NUDGING_n
310 USE MODD_PARAM_MFSHALL_n
311 USE MODD_ELEC_DESCR
312 !
313 USE MODD_CLOUD_MF_n      
314 USE MODI_INITIAL_GUESS
315 USE MODI_MEAN_FIELD
316 USE MODI_BOUNDARIES
317 USE MODI_ADVECTION_METSV
318 USE MODI_ADVECTION_UVW     
319 USE MODI_ADVECTION_UVW_CEN 
320 USE MODI_GRAVITY_IMPL         
321 USE MODI_DYN_SOURCES
322 USE MODI_RELAXATION
323 USE MODI_NUM_DIFF
324 USE MODI_PHYS_PARAM_n
325 USE MODI_RAD_BOUND
326 USE MODI_PRESSUREZ
327 USE MODI_ENDSTEP
328 USE MODI_EXCHANGE
329 USE MODI_RESOLVED_CLOUD
330 USE MODI_RESOLVED_ELEC_n
331 USE MODI_RELAX2FW_ION 
332 USE MODI_LS_COUPLING
333 USE MODI_WRITE_DESFM_n
334 USE MODI_WRITE_LFIFM_n
335 USE MODI_MNHWRITE_ZS_DUMMY_n
336 USE MODI_ENDSTEP_BUDGET
337 USE MODI_BUDGET_FLAGS
338 USE MODI_ADD_FORECAST_TO_DATE
339 USE MODI_FORCING
340 USE MODI_ADV_FORCING_n
341 USE MODI_REL_FORCING_n
342 USE MODI_NUDGING
343 USE MODI_TEMPORAL_DIST
344 USE MODI_WRITE_LFIFMN_FORDIACHRO_n
345 USE MODI_MENU_DIACHRO
346 USE MODI_MASK_COMPRESS
347 USE MODI_CART_COMPRESS
348 USE MODI_SHUMAN
349 USE MODI_ONE_WAY_n
350 USE MODI_TWO_WAY
351 USE MODI_SPAWN_LS_n
352 USE MODI_LES_INI_TIMESTEP_n
353 USE MODI_WRITE_LES_n
354 USE MODI_AIRCRAFT_BALLOON
355 USE MODI_WRITE_AIRCRAFT_BALLOON
356 USE MODI_UPDATE_NSV
357 USE MODI_PROFILER_n
358 USE MODI_STATION_n
359 USE MODI_WRITE_SERIES_n
360 USE MODI_WRITE_PROFILER_n
361 USE MODI_WRITE_STATION_n
362 USE MODI_MNHGET_SURF_PARAM_n
363 USE MODI_INI_DIAG_IN_RUN
364 USE MODI_END_DIAG_IN_RUN
365 USE MODI_TURB_CLOUD_INDEX
366 USE MODI_INI_LG
367 USE MODI_INI_MEAN_FIELD
368 !
369 USE MODE_MODELN_HANDLER
370 !
371 USE MODD_2D_FRC
372 USE MODD_TIMEZ
373 USE MODE_MNH_TIMING
374 !
375 USE MODI_SETLB_LG
376 USE MODI_GOTO_SURFEX
377 USE MODI_WRITE_SURF_ATM_N
378 USE MODI_SET_MASK
379 USE MODI_DIAG_SURF_ATM_N
380 USE MODI_WRITE_DIAG_SURF_ATM_N
381 USE MODI_SERIES_N
382 USE MODI_LES_N
383 !
384 #ifdef MNH_NCWRIT
385 USE MODN_NCOUT
386 USE MODE_UTIL
387 #endif
388 USE MODI_GET_HALO
389 USE MODE_MPPDB
390 !
391 IMPLICIT NONE
392 !
393 !*       0.1   declarations of arguments
394 !
395 !
396 !
397 INTEGER, INTENT(IN)   :: KTCOUNT
398 LOGICAL, INTENT(INOUT):: OEXIT
399 !
400 !*       0.2   declarations of local variables
401 !
402 INTEGER :: ILUOUT      ! Logical unit number for the output listing
403 INTEGER :: IIU,IJU,IKU ! array size in first, second and third dimensions
404 INTEGER :: IIB,IIE,IJB,IJE,IKB,IKE ! index values for the physical subdomain
405 INTEGER :: JSV,JRR     ! Loop index for scalar and moist variables
406 CHARACTER (LEN=28) :: YFMFILE   ! name of the OUTPUT FM-file
407 CHARACTER (LEN=28) :: YDADFILE  ! name of the corresponding DAD model OUTPUT FM-file
408 CHARACTER (LEN=4)  :: YNUMBER   ! character string for the OUTPUT FM-file number
409 CHARACTER (LEN=4)  :: YDADNUMBER! character string for the DAD model OUTPUT FM-file number
410 CHARACTER (LEN=32) :: YDESFM    ! name of the desfm part of this FM-file
411 INTEGER  :: INBVAR              ! number of HALO2_lls to allocate
412 INTEGER  :: IRESP               ! return code in FM routines
413 INTEGER  :: IINFO_ll            ! return code of parallel routine
414 INTEGER :: INPRAR               ! number of articles predicted  in
415                                 !  the LFIFM file
416 INTEGER :: ININAR               ! number of articles  present in
417                                 !  the LFIFM file
418 INTEGER :: ITYPE                ! type of file (cpio or not)
419 INTEGER :: JOUT                 ! loop index on the output instant list
420 INTEGER :: IOUTDAD              ! numero of the OUTPUT FM-file of DAD model
421 INTEGER :: JOUTDAD              ! loop index on the output instant list for DAD model
422 LOGICAL :: GSTEADY_DMASS        ! conditional call to mass computation
423 !
424                                 ! for computing time analysis
425 REAL*8,DIMENSION(2)         :: ZTIME,ZTIME1,ZTIME2,ZEND,ZTOT,ZALL,ZTOT_PT
426 !
427 REAL*8,DIMENSION(2)         :: ZTIME_STEP,ZTIME_STEP_PTS
428 CHARACTER                 :: YMI
429 INTEGER                   :: IPOINTS
430 CHARACTER(len=12)         :: YTCOUNT,YPOINTS
431
432 REAL         :: ZSTAT_CSTORE,ZSTAT_CBOUND,ZSTAT_CGUESS,ZSTAT_CADV,ZSTAT_CSOURCES
433 REAL         :: ZSTAT_CDIFF,ZSTAT_CRELAX,ZSTAT_CPARAM
434 REAL         :: ZSTAT_CSPECTRA,ZSTAT_CRAD_BOUND,ZSTAT_CPRESS
435 REAL         :: ZSTAT_CCLOUD,ZSTAT_CSTEP_SWA,ZSTAT_CSTEP_MISC
436 REAL         :: ZSTAT_CCOUPL,ZSTAT_CSTEP_BUD,ZSTAT_CSTEP_CDRAG
437 REAL         :: ZSTAT_CSTEP_CTRACER,ZSTAT_CSTEP_CELEC
438 REAL         :: SCONV_CTURB,ZSTAT_C1WAY,ZSTAT_C2WAY,ZSTAT_CMAFL
439 REAL         :: ZSTAT_CRAD,ZSTAT_CDCONV,ZSTAT_CGROUND,ZSTAT_CHALO
440 REAL         :: ZSTAT_CFORCING,ZSTAT_CNUDGING,ZSTAT_CCHEM
441 !
442 REAL         :: ZPERCALL,ZPRICE
443 REAL         :: ZPERCSTORE,ZPERCBOUND,ZPERCGUESS,ZPERCADV,ZPERCSOURCES,ZPERCDRAG
444 REAL         :: ZPERCDIFF,ZPERCRELAX,ZPERCPARAM
445 REAL         :: ZPERCSPECTRA,ZPERCRAD_BOUND,ZPERCPRESS
446 REAL         :: ZPERCCLOUD,ZPERCSTEP_SWA,ZPERCSTEP_MISC
447 REAL         :: ZPERCELEC
448 REAL         :: ZPERCCOUPL,ZPERCSTEP_BUD
449 REAL         :: ZPERCTURB,ZPERC1WAY,ZPERC2WAY
450 REAL         :: ZPERCRAD,ZPERCSHADOWS,ZPERCKAFR,ZPERCGROUND,ZPERCHALO,ZPERCMAFL,ZPERTRACER
451 REAL         :: ZPERCFORCING,ZPERCNUDGING,ZPERCCHEM
452 REAL         :: ZTSTEP_UVW   ! Double timestep except for cold start (single)
453 REAL         :: ZTSTEP_MET,ZTSTEP_SV ! Effective time step for advection
454 !
455 INTEGER :: ISYNCHRO          ! model synchronic index relative to its father
456                              ! = 1  for the first time step in phase with DAD
457                              ! = 0  for the last  time step (out of phase)
458 INTEGER      :: IMI ! Current model index
459 REAL, DIMENSION(:,:),ALLOCATABLE          :: ZSEA
460 REAL, DIMENSION(:,:),ALLOCATABLE          :: ZTOWN
461 ! Dummy pointers needed to correct an ifort Bug
462 REAL, DIMENSION(:), POINTER :: DPTR_XZHAT
463 REAL, DIMENSION(:), POINTER :: DPTR_XBMX1,DPTR_XBMX2,DPTR_XBMX3,DPTR_XBMX4
464 REAL, DIMENSION(:), POINTER :: DPTR_XBMY1,DPTR_XBMY2,DPTR_XBMY3,DPTR_XBMY4
465 REAL, DIMENSION(:), POINTER :: DPTR_XBFX1,DPTR_XBFX2,DPTR_XBFX3,DPTR_XBFX4
466 REAL, DIMENSION(:), POINTER :: DPTR_XBFY1,DPTR_XBFY2,DPTR_XBFY3,DPTR_XBFY4
467 CHARACTER(LEN=4), DIMENSION(:), POINTER :: DPTR_CLBCX,DPTR_CLBCY
468 INTEGER, DIMENSION(:,:,:), POINTER :: DPTR_NKLIN_LBXU,DPTR_NKLIN_LBYU,DPTR_NKLIN_LBXV,DPTR_NKLIN_LBYV
469 INTEGER, DIMENSION(:,:,:), POINTER :: DPTR_NKLIN_LBXW,DPTR_NKLIN_LBYW,DPTR_NKLIN_LBXM,DPTR_NKLIN_LBYM
470 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XCOEFLIN_LBXU,DPTR_XCOEFLIN_LBYU
471 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XCOEFLIN_LBXV,DPTR_XCOEFLIN_LBYV
472 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XCOEFLIN_LBXW,DPTR_XCOEFLIN_LBYW
473 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XCOEFLIN_LBXM,DPTR_XCOEFLIN_LBYM
474 REAL, DIMENSION(:,:,:),   POINTER :: DPTR_XLBXUM,DPTR_XLBYUM,DPTR_XLBXVM,DPTR_XLBYVM
475 REAL, DIMENSION(:,:,:),   POINTER :: DPTR_XLBXWM,DPTR_XLBYWM,DPTR_XLBXTHM,DPTR_XLBYTHM
476 REAL, DIMENSION(:,:,:),   POINTER :: DPTR_XLBXTKEM,DPTR_XLBYTKEM
477 REAL, DIMENSION(:,:,:,:),   POINTER :: DPTR_XLBXSVM,DPTR_XLBYSVM                
478 REAL, DIMENSION(:,:,:,:), POINTER :: DPTR_XLBXRM,DPTR_XLBYRM
479 REAL, DIMENSION(:,:,:),   POINTER ::  DPTR_XZZ
480 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XLSUM,DPTR_XLSVM,DPTR_XLSWM,DPTR_XLSTHM,DPTR_XLSRVM
481 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XLSUS,DPTR_XLSVS,DPTR_XLSWS,DPTR_XLSTHS,DPTR_XLSRVS
482 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XLBXUS,DPTR_XLBYUS,DPTR_XLBXVS,DPTR_XLBYVS
483 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XLBXWS,DPTR_XLBYWS,DPTR_XLBXTHS,DPTR_XLBYTHS
484 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XLBXTKES,DPTR_XLBYTKES
485 REAL, DIMENSION(:,:,:,:), POINTER :: DPTR_XLBXRS,DPTR_XLBYRS,DPTR_XLBXSVS,DPTR_XLBYSVS
486 !
487 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XRHODJ,DPTR_XUM,DPTR_XVM,DPTR_XWM,DPTR_XTHM
488 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XTKEM,DPTR_XRUS,DPTR_XRVS,DPTR_XRWS,DPTR_XRTHS
489 REAL, DIMENSION(:,:,:), POINTER :: DPTR_XRTKES,DPTR_XDIRFLASWD,DPTR_XSCAFLASWD,DPTR_XDIRSRFSWD
490 REAL, DIMENSION(:,:,:,:), POINTER :: DPTR_XRM,DPTR_XSVM,DPTR_XRRS,DPTR_XRSVS
491 REAL, DIMENSION(:,:), POINTER :: DPTR_XINPRC,DPTR_XINPRR,DPTR_XINPRS,DPTR_XINPRG
492 REAL, DIMENSION(:,:), POINTER :: DPTR_XINPRH,DPTR_XPRCONV,DPTR_XPRSCONV
493 LOGICAL, DIMENSION(:,:),POINTER :: DPTR_GMASKkids
494 !
495 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3))           :: ZSPEEDC
496 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3))           :: ZSPEEDR
497 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3))           :: ZSPEEDS
498 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3))           :: ZSPEEDG
499 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3))           :: ZSPEEDH
500 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3))           :: ZINPRC3D
501 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3))           :: ZINPRS3D
502 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3))           :: ZINPRG3D
503 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3))           :: ZINPRH3D
504 !
505 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3)) :: ZRUS,ZRVS,ZRWS
506 !
507 ! for various testing
508 INTEGER :: IK
509 REAL, DIMENSION(SIZE(XTHT,1),SIZE(XTHT,2),SIZE(XTHT,3)) :: ZTMP
510 !
511 TYPE(LIST_ll), POINTER :: TZFIELDC_ll   ! list of fields to exchange
512 TYPE(HALO2LIST_ll), POINTER :: TZHALO2C_ll   ! list of fields to exchange
513 !
514 !-------------------------------------------------------------------------------
515 !
516 !*        1    PRELIMINARY
517 !              ------------
518 ITYPE = 1
519 IMI = GET_CURRENT_MODEL_INDEX()
520 !
521 !*       1.0   update NSV_* variables for current model
522 !              ----------------------------------------
523 !
524 CALL UPDATE_NSV(IMI)
525 !
526 !*       1.1   RECOVER THE LOGICAL UNIT NUMBER FOR THE OUTPUT PRINTS
527 !
528 CALL FMLOOK_ll(CLUOUT,CLUOUT,ILUOUT,IRESP)
529 !
530 !*       1.2   SET ARRAY SIZE
531 !
532 CALL GET_DIM_EXT_ll('B',IIU,IJU)
533 IKU=NKMAX+2*JPVEXT
534 CALL GET_INDICE_ll (IIB,IJB,IIE,IJE)
535 IKB=1+JPVEXT
536 IKE=IKU-JPVEXT
537 !
538 IF (IMI==1) THEN
539   GSTEADY_DMASS=LSTEADYLS
540 ELSE
541   GSTEADY_DMASS=.FALSE.
542 END IF
543 !
544 !*       1.3   OPEN THE DIACHRONIC FILE
545 !
546 IF (KTCOUNT == 1) THEN
547 !
548   NULLIFY(TZFIELDS_ll,TZLSFIELD_ll,TZFIELDT_ll)
549   NULLIFY(TZHALO2T_ll)
550   NULLIFY(TZLSHALO2_ll)
551   NULLIFY(TZFIELDSC_ll)
552 !
553   ALLOCATE(ZWT_ACT_NUC(SIZE(XWT,1),SIZE(XWT,2),SIZE(XWT,3)))
554   ALLOCATE(GMASKkids(SIZE(XWT,1),SIZE(XWT,2)))
555 !
556 ! initialization of the FM file output number
557   IOUT=0
558 !
559   INPRAR = 50
560   CALL FMOPEN_ll(CFMDIAC,'WRITE',CLUOUT,INPRAR,ITYPE,NVERB,ININAR,IRESP)
561   YDESFM=ADJUSTL(ADJUSTR(CFMDIAC)//'.des')
562   CALL WRITE_DESFM_n(IMI,YDESFM,CLUOUT)
563 #ifdef MNH_NCWRIT
564   NC_WRITE = LNETCDF
565   NC_FILE=''
566   CALL WRITE_LFIFMN_FORDIACHRO_n(CFMDIAC)
567   IF ( LNETCDF ) THEN
568      DEF_NC=.FALSE.
569      CALL WRITE_LFIFMN_FORDIACHRO_n(CFMDIAC)
570      DEF_NC=.TRUE.
571   END IF
572   NC_WRITE = .FALSE.
573 #else
574   CALL WRITE_LFIFMN_FORDIACHRO_n(CFMDIAC)
575 #endif
576 !
577 !*       1.4   Initialization of the list of fields for the halo updates
578 !
579 !                 a) Sources terms
580 !
581   CALL ADD3DFIELD_ll(TZFIELDS_ll, XRUS)
582   CALL ADD3DFIELD_ll(TZFIELDS_ll, XRVS)
583   CALL ADD3DFIELD_ll(TZFIELDS_ll, XRWS)
584   CALL ADD3DFIELD_ll(TZFIELDS_ll, XRTHS)
585   CALL ADD3DFIELD_ll(TZFIELDS_ll, XRUS_PRES)
586   CALL ADD3DFIELD_ll(TZFIELDS_ll, XRVS_PRES)
587   CALL ADD3DFIELD_ll(TZFIELDS_ll, XRWS_PRES)
588   CALL ADD3DFIELD_ll(TZFIELDS_ll, XRTHS_CLD)
589   IF (SIZE(XRTKES,1) /= 0) CALL ADD3DFIELD_ll(TZFIELDS_ll, XRTKES)
590   DO JRR=1,NRR
591     CALL ADD3DFIELD_ll(TZFIELDS_ll, XRRS(:,:,:,JRR))
592     CALL ADD3DFIELD_ll(TZFIELDS_ll, XRRS_CLD(:,:,:,JRR))
593   ENDDO
594   DO JSV=1,NSV
595     CALL ADD3DFIELD_ll(TZFIELDS_ll, XRSVS(:,:,:,JSV))
596     CALL ADD3DFIELD_ll(TZFIELDS_ll, XRSVS_CLD(:,:,:,JSV))
597   ENDDO
598   IF (SIZE(XSRCT,1) /= 0) CALL ADD3DFIELD_ll(TZFIELDS_ll, XSRCT)
599   !
600   IF ((LNUMDIFU .OR. LNUMDIFTH .OR. LNUMDIFSV) ) THEN
601   !
602   !                 b) LS fields
603   !
604     CALL ADD3DFIELD_ll(TZLSFIELD_ll, XLSUM)
605     CALL ADD3DFIELD_ll(TZLSFIELD_ll, XLSVM)
606     CALL ADD3DFIELD_ll(TZLSFIELD_ll, XLSWM)
607     CALL ADD3DFIELD_ll(TZLSFIELD_ll, XLSTHM)
608     IF (NRR >= 1) THEN
609       CALL ADD3DFIELD_ll(TZLSFIELD_ll, XLSRVM)
610     ENDIF
611   !
612   !                 c) Fields at t
613   !
614     CALL ADD3DFIELD_ll(TZFIELDT_ll, XUT)
615     CALL ADD3DFIELD_ll(TZFIELDT_ll, XVT)
616     CALL ADD3DFIELD_ll(TZFIELDT_ll, XWT)
617     CALL ADD3DFIELD_ll(TZFIELDT_ll, XTHT)
618     IF (SIZE(XRTKES,1) /= 0) CALL ADD3DFIELD_ll(TZFIELDT_ll, XTKET)
619     DO JRR=1,NRR
620       CALL ADD3DFIELD_ll(TZFIELDT_ll, XRT(:,:,:,JRR))
621     ENDDO
622     DO JSV=1,NSV
623       CALL ADD3DFIELD_ll(TZFIELDT_ll, XSVT(:,:,:,JSV))
624     ENDDO
625   !
626   !*       1.5   Initialize the list of fields for the halo updates (2nd layer)
627   !
628     INBVAR = 4+NRR+NSV
629     IF (SIZE(XRTKES,1) /= 0) INBVAR=INBVAR+1
630     CALL INIT_HALO2_ll(TZHALO2T_ll,INBVAR,IIU,IJU,IKU)
631     CALL INIT_HALO2_ll(TZLSHALO2_ll,4+MIN(1,NRR),IIU,IJU,IKU)
632   !
633   !*       1.6   Initialise the 2nd layer of the halo of the LS fields
634   !
635     IF ( LSTEADYLS ) THEN
636        CALL UPDATE_HALO_ll(TZLSFIELD_ll, IINFO_ll)
637        CALL UPDATE_HALO2_ll(TZLSFIELD_ll, TZLSHALO2_ll, IINFO_ll)
638     END IF
639   END IF
640   !
641 !
642   !
643   XT_START = 0.0
644   ! 
645   XT_STORE     = 0.0
646   XT_BOUND     = 0.0
647   XT_GUESS     = 0.0
648   XT_FORCING   = 0.0
649   XT_NUDGING   = 0.0
650   XT_ADV       = 0.0
651   XT_ADVUVW    = 0.0
652   XT_GRAV      = 0.0
653   XT_SOURCES   = 0.0
654   !
655   XT_DIFF      = 0.0
656   XT_RELAX     = 0.0
657   XT_PARAM     = 0.0
658   XT_SPECTRA   = 0.0
659   XT_HALO      = 0.0
660   XT_RAD_BOUND = 0.0
661   XT_PRESS     = 0.0
662   !
663   XT_CLOUD     = 0.0
664   XT_STEP_SWA  = 0.0
665   XT_STEP_MISC = 0.0
666   XT_COUPL     = 0.0
667   XT_1WAY      = 0.0
668   XT_STEP_BUD  = 0.0
669   !
670   XT_RAD       = 0.0
671   XT_DCONV     = 0.0
672   XT_GROUND    = 0.0
673   XT_TURB      = 0.0
674   XT_MAFL      = 0.0
675   XT_DRAG      = 0.0
676   XT_TRACER    = 0.0
677   XT_SHADOWS   = 0.0
678   XT_ELEC      = 0.0
679   XT_CHEM      = 0.0
680   XT_2WAY      = 0.0
681   !
682 END IF
683 !
684 !*       1.7   Allocation of arrays for observation diagnostics
685 !
686 CALL INI_DIAG_IN_RUN(IIU,IJU,IKU,LFLYER,LSTATION,LPROFILER)
687 !
688 !
689 CALL SECOND_MNH2(ZEND)
690 !
691 !-------------------------------------------------------------------------------
692 !
693 !*       2.    ONE-WAY NESTING AND LARGE SCALE FIELD REFRESH
694 !              ---------------------------------------------
695 !
696 !
697 CALL SECOND_MNH2(ZTIME1)
698 !
699 ISYNCHRO = MODULO (KTCOUNT, NDTRATIO(IMI) )      ! test of synchronisation
700 !
701
702
703 IF (IMI/=1 .AND. NDAD(IMI)/=IMI .AND. (ISYNCHRO==1 .OR. NDTRATIO(IMI) == 1) ) THEN     
704 !                                                                        
705   ! Use dummy pointers to correct an ifort BUG
706   DPTR_XBMX1=>XBMX1
707   DPTR_XBMX2=>XBMX2
708   DPTR_XBMX3=>XBMX3
709   DPTR_XBMX4=>XBMX4
710   DPTR_XBMY1=>XBMY1
711   DPTR_XBMY2=>XBMY2
712   DPTR_XBMY3=>XBMY3
713   DPTR_XBMY4=>XBMY4
714   DPTR_XBFX1=>XBFX1
715   DPTR_XBFX2=>XBFX2
716   DPTR_XBFX3=>XBFX3
717   DPTR_XBFX4=>XBFX4
718   DPTR_XBFY1=>XBFY1
719   DPTR_XBFY2=>XBFY2
720   DPTR_XBFY3=>XBFY3
721   DPTR_XBFY4=>XBFY4
722   DPTR_CLBCX=>CLBCX
723   DPTR_CLBCY=>CLBCY
724   !
725   DPTR_XZZ=>XZZ
726   DPTR_XZHAT=>XZHAT
727   DPTR_XCOEFLIN_LBXM=>XCOEFLIN_LBXM
728   DPTR_XLSTHM=>XLSTHM
729   DPTR_XLSRVM=>XLSRVM
730   DPTR_XLSUM=>XLSUM
731   DPTR_XLSVM=>XLSVM
732   DPTR_XLSWM=>XLSWM
733   DPTR_XLSTHS=>XLSTHS
734   DPTR_XLSRVS=>XLSRVS
735   DPTR_XLSUS=>XLSUS
736   DPTR_XLSVS=>XLSVS
737   DPTR_XLSWS=>XLSWS
738   !
739   IF ( LSTEADYLS                     ) THEN
740     NCPL_CUR=0
741   ELSE
742     IF (NCPL_CUR/=1) THEN
743       IF ( KTCOUNT+1 == NCPL_TIMES(NCPL_CUR-1,IMI)  ) THEN
744         !
745         !  LS sources are interpolated from the LS field 
746         ! values of model DAD(IMI)
747         CALL SPAWN_LS_n(NDAD(IMI),XTSTEP,IMI,                        &
748              DPTR_XBMX1,DPTR_XBMX2,DPTR_XBMX3,DPTR_XBMX4,DPTR_XBMY1,DPTR_XBMY2,DPTR_XBMY3,DPTR_XBMY4,        &
749              DPTR_XBFX1,DPTR_XBFX2,DPTR_XBFX3,DPTR_XBFX4,DPTR_XBFY1,DPTR_XBFY2,DPTR_XBFY3,DPTR_XBFY4,        &
750              NDXRATIO_ALL(IMI),NDYRATIO_ALL(IMI),                    &
751              DPTR_CLBCX,DPTR_CLBCY,DPTR_XZZ,DPTR_XZHAT,LSLEVE,XLEN1,XLEN2,DPTR_XCOEFLIN_LBXM, &
752              DPTR_XLSTHM,DPTR_XLSRVM,DPTR_XLSUM,DPTR_XLSVM,DPTR_XLSWM,                        &
753              DPTR_XLSTHS,DPTR_XLSRVS,DPTR_XLSUS,DPTR_XLSVS,DPTR_XLSWS                         )
754       END IF
755     END IF
756     !
757   END IF
758   !
759   DPTR_NKLIN_LBXU=>NKLIN_LBXU
760   DPTR_XCOEFLIN_LBXU=>XCOEFLIN_LBXU
761   DPTR_NKLIN_LBYU=>NKLIN_LBYU
762   DPTR_XCOEFLIN_LBYU=>XCOEFLIN_LBYU
763   DPTR_NKLIN_LBXV=>NKLIN_LBXV
764   DPTR_XCOEFLIN_LBXV=>XCOEFLIN_LBXV
765   DPTR_NKLIN_LBYV=>NKLIN_LBYV
766   DPTR_XCOEFLIN_LBYV=>XCOEFLIN_LBYV
767   DPTR_NKLIN_LBXW=>NKLIN_LBXW
768   DPTR_XCOEFLIN_LBXW=>XCOEFLIN_LBXW
769   DPTR_NKLIN_LBYW=>NKLIN_LBYW
770   DPTR_XCOEFLIN_LBYW=>XCOEFLIN_LBYW
771   !
772   DPTR_NKLIN_LBXM=>NKLIN_LBXM
773   DPTR_XCOEFLIN_LBXM=>XCOEFLIN_LBXM
774   DPTR_NKLIN_LBYM=>NKLIN_LBYM
775   DPTR_XCOEFLIN_LBYM=>XCOEFLIN_LBYM
776   !
777   DPTR_XLBXUM=>XLBXUM
778   DPTR_XLBYUM=>XLBYUM
779   DPTR_XLBXVM=>XLBXVM
780   DPTR_XLBYVM=>XLBYVM
781   DPTR_XLBXWM=>XLBXWM
782   DPTR_XLBYWM=>XLBYWM
783   DPTR_XLBXTHM=>XLBXTHM
784   DPTR_XLBYTHM=>XLBYTHM
785   DPTR_XLBXTKEM=>XLBXTKEM
786   DPTR_XLBYTKEM=>XLBYTKEM
787   DPTR_XLBXRM=>XLBXRM
788   DPTR_XLBYRM=>XLBYRM
789   DPTR_XLBXSVM=>XLBXSVM
790   DPTR_XLBYSVM=>XLBYSVM
791   !  
792   DPTR_XLBXUS=>XLBXUS
793   DPTR_XLBYUS=>XLBYUS
794   DPTR_XLBXVS=>XLBXVS
795   DPTR_XLBYVS=>XLBYVS
796   DPTR_XLBXWS=>XLBXWS
797   DPTR_XLBYWS=>XLBYWS
798   DPTR_XLBXTHS=>XLBXTHS
799   DPTR_XLBYTHS=>XLBYTHS
800   DPTR_XLBXTKES=>XLBXTKES
801   DPTR_XLBYTKES=>XLBYTKES
802   DPTR_XLBXRS=>XLBXRS
803   DPTR_XLBYRS=>XLBYRS
804   DPTR_XLBXSVS=>XLBXSVS
805   DPTR_XLBYSVS=>XLBYSVS
806   !
807   CALL ONE_WAY_n(NDAD(IMI),CLUOUT,XTSTEP,IMI,KTCOUNT,                   &
808        DPTR_XBMX1,DPTR_XBMX2,DPTR_XBMX3,DPTR_XBMX4,DPTR_XBMY1,DPTR_XBMY2,DPTR_XBMY3,DPTR_XBMY4,        &
809        DPTR_XBFX1,DPTR_XBFX2,DPTR_XBFX3,DPTR_XBFX4,DPTR_XBFY1,DPTR_XBFY2,DPTR_XBFY3,DPTR_XBFY4,        &
810        NDXRATIO_ALL(IMI),NDYRATIO_ALL(IMI),NDTRATIO(IMI),         &
811        DPTR_CLBCX,DPTR_CLBCY,NRIMX,NRIMY,                                &
812        DPTR_NKLIN_LBXU,DPTR_XCOEFLIN_LBXU,DPTR_NKLIN_LBYU,DPTR_XCOEFLIN_LBYU,      &
813        DPTR_NKLIN_LBXV,DPTR_XCOEFLIN_LBXV,DPTR_NKLIN_LBYV,DPTR_XCOEFLIN_LBYV,      &
814        DPTR_NKLIN_LBXW,DPTR_XCOEFLIN_LBXW,DPTR_NKLIN_LBYW,DPTR_XCOEFLIN_LBYW,      &
815        DPTR_NKLIN_LBXM,DPTR_XCOEFLIN_LBXM,DPTR_NKLIN_LBYM,DPTR_XCOEFLIN_LBYM,      &
816        GSTEADY_DMASS,CCLOUD,LUSECHAQ,LUSECHIC,                           &
817        DPTR_XLBXUM,DPTR_XLBYUM,DPTR_XLBXVM,DPTR_XLBYVM,DPTR_XLBXWM,DPTR_XLBYWM,              &
818        DPTR_XLBXTHM,DPTR_XLBYTHM,                                        &
819        DPTR_XLBXTKEM,DPTR_XLBYTKEM,                                      &
820        DPTR_XLBXRM,DPTR_XLBYRM,DPTR_XLBXSVM,DPTR_XLBYSVM,                          &
821        XDRYMASST,XDRYMASSS,                                    &
822        DPTR_XLBXUS,DPTR_XLBYUS,DPTR_XLBXVS,DPTR_XLBYVS,DPTR_XLBXWS,DPTR_XLBYWS,              &
823        DPTR_XLBXTHS,DPTR_XLBYTHS,                                        &
824        DPTR_XLBXTKES,DPTR_XLBYTKES,                                      &
825        DPTR_XLBXRS,DPTR_XLBYRS,DPTR_XLBXSVS,DPTR_XLBYSVS                           )
826   !
827 END IF
828 !
829 CALL SECOND_MNH2(ZTIME2)                                                  
830 XT_1WAY = XT_1WAY + ZTIME2 - ZTIME1                                
831 !
832 !-------------------------------------------------------------------------------
833 !
834 !*       3.    LATERAL BOUNDARY CONDITIONS EXCEPT FOR NORMAL VELOCITY
835 !              ------------------------------------------------------
836 !
837 ZTIME1=ZTIME2
838 !
839 !*       3.1   Set the lagragian variables values at the LB
840 !
841 IF( LLG .AND. IMI==1 ) CALL SETLB_LG
842 !
843 IF (CCONF == "START" .OR. (CCONF == "RESTA" .AND. KTCOUNT /= 1 )) THEN
844 CALL MPPDB_CHECK3DM("before BOUNDARIES:XUT, XVT, XWT, XTHT, XTKET",PRECISION,&
845                    &  XUT, XVT, XWT, XTHT, XTKET)
846 CALL BOUNDARIES (                                                   &
847             XTSTEP,CLBCX,CLBCY,NRR,NSV,KTCOUNT,                     &
848             XLBXUM,XLBXVM,XLBXWM,XLBXTHM,XLBXTKEM,XLBXRM,XLBXSVM,   &
849             XLBYUM,XLBYVM,XLBYWM,XLBYTHM,XLBYTKEM,XLBYRM,XLBYSVM,   &
850             XLBXUS,XLBXVS,XLBXWS,XLBXTHS,XLBXTKES,XLBXRS,XLBXSVS,   &
851             XLBYUS,XLBYVS,XLBYWS,XLBYTHS,XLBYTKES,XLBYRS,XLBYSVS,   &
852             XRHODJ,                                                 &
853             XUT, XVT, XWT, XTHT, XTKET, XRT, XSVT, XSRCT            )
854 CALL MPPDB_CHECK3DM("after  BOUNDARIES:XUT, XVT, XWT, XTHT, XTKET",PRECISION,&
855                    &  XUT, XVT, XWT, XTHT, XTKET)
856 END IF
857 !
858 CALL SECOND_MNH2(ZTIME2)
859 !
860 XT_BOUND = XT_BOUND + ZTIME2 - ZTIME1
861 !
862 !-------------------------------------------------------------------------------
863 !* initializes surface number
864 IF (CSURF=='EXTE') CALL GOTO_SURFEX(IMI,.TRUE.)
865 !-------------------------------------------------------------------------------
866 !
867 !*       4.    STORAGE IN A SYNCHRONOUS FILE
868 !              -----------------------------
869 !
870 ZTIME1 = ZTIME2
871 !
872 YFMFILE='                            '
873 DO JOUT = 1,NOUT_NUMB
874   IF (KTCOUNT == NOUT_TIMES(JOUT)) THEN
875     IOUT=IOUT+1
876     GCLOSE_OUT=.TRUE.
877     INPRAR = 22 +2*(4+NRR+NSV)
878     WRITE (YNUMBER,FMT="('.',I3.3)") IOUT
879     YFMFILE=ADJUSTL(ADJUSTR(COUTFILE)//YNUMBER)
880 !
881 !        search for the corresponding Output of the DAD model
882 !
883     IF (NDAD(IMI) == IMI .OR.  IMI == 1) THEN
884       YDADFILE=YFMFILE
885     ELSE
886       IOUTDAD=0
887       DO JOUTDAD =1,JPOUTMAX
888         IF ( XFMOUT(NDAD(IMI),JOUTDAD) /= XUNDEF .AND.                 &
889              XFMOUT(NDAD(IMI),JOUTDAD) <= (XFMOUT(IMI,JOUT)+1.E-10) )   &
890                      IOUTDAD=IOUTDAD+1
891       END DO
892       IF(IOUTDAD>0) THEN
893         WRITE (YDADNUMBER,FMT="('.',I3.3)") IOUTDAD
894         YDADFILE=ADJUSTL(ADJUSTR(CDAD_NAME(IMI))//YDADNUMBER)
895       ELSE
896         WRITE (YDADFILE,FMT="('NO_DAD_FILE')")
897       END IF
898     END IF
899 !
900     CALL FMOPEN_ll(YFMFILE,'WRITE',CLUOUT,INPRAR,ITYPE,NVERB,ININAR,IRESP)
901     YDESFM=ADJUSTL(ADJUSTR(YFMFILE)//'.des')
902 !  
903     CALL WRITE_DESFM_n(IMI,YDESFM,CLUOUT)
904 #ifdef MNH_NCWRIT
905     NC_WRITE = LNETCDF
906     NC_FILE = ''
907     CALL WRITE_LFIFM_n(YFMFILE,YDADFILE)
908     COUTFMFILE = YFMFILE
909     CALL MNHWRITE_ZS_DUMMY_n(CPROGRAM)
910     IF ( LNETCDF ) THEN
911       DEF_NC=.FALSE.
912       CALL WRITE_LFIFM_n(YFMFILE,YDADFILE)
913       COUTFMFILE = YFMFILE
914       CALL MNHWRITE_ZS_DUMMY_n(CPROGRAM)
915       DEF_NC=.TRUE.
916     END IF
917     NC_WRITE = .FALSE.
918 #else
919     CALL WRITE_LFIFM_n(YFMFILE,YDADFILE)
920     COUTFMFILE = YFMFILE
921     CALL MNHWRITE_ZS_DUMMY_n(CPROGRAM)
922 #endif
923     IF (CSURF=='EXTE') THEN
924       CALL GOTO_SURFEX(IMI,.TRUE.)
925 #ifdef MNH_NCWRIT
926       NC_WRITE = LNETCDF
927       NC_FILE = 'sf1'
928       CALL WRITE_SURF_ATM_n('MESONH','ALL',.FALSE.)
929       IF ( LNETCDF ) THEN
930         DEF_NC=.FALSE.
931         CALL WRITE_SURF_ATM_n('MESONH','ALL',.FALSE.)
932         DEF_NC=.TRUE.
933       END IF
934 #else
935       CALL WRITE_SURF_ATM_n('MESONH','ALL',.FALSE.)
936 #endif
937     END IF
938     !
939     ! Reinitialize Lagragian variables at every model output
940     IF (LLG .AND. LINIT_LG .AND. CINIT_LG=='FMOUT') THEN
941       CALL INI_LG(XXHAT,XYHAT,XZZ,XSVT,XLBXSVM,XLBYSVM)
942       IF (NVERB>=5) THEN
943         WRITE(UNIT=ILUOUT,FMT=*) '************************************'
944         WRITE(UNIT=ILUOUT,FMT=*) '*** Lagrangian variables refreshed after ',TRIM(YFMFILE),' output'
945         WRITE(UNIT=ILUOUT,FMT=*) '************************************'
946       END IF
947     END IF
948     ! Reinitialise mean variables
949     IF (LMEAN_FIELD) THEN
950        CALL INI_MEAN_FIELD
951     END IF
952 !
953   END IF
954 !
955 END DO
956 !
957 CALL SECOND_MNH2(ZTIME2)
958 !
959 XT_STORE = XT_STORE + ZTIME2 - ZTIME1
960 !
961 !-------------------------------------------------------------------------------
962 !
963 !*       5.    INITIALIZATION OF THE BUDGET VARIABLES
964 !              --------------------------------------
965 !
966 IF (NBUMOD==IMI) THEN
967   LBU_ENABLE = CBUTYPE /='NONE'.AND. CBUTYPE /='SKIP' 
968 ELSE
969   LBU_ENABLE = .FALSE.
970 END IF
971 !
972 IF (NBUMOD==IMI .AND. CBUTYPE=='MASK' ) THEN
973   CALL SET_MASK
974   IF (LBU_RU)   XBURHODJU(:,NBUTIME,:) = XBURHODJU(:,NBUTIME,:)    &
975                             + MASK_COMPRESS(MXM(XRHODJ))
976   IF (LBU_RV)   XBURHODJV(:,NBUTIME,:) = XBURHODJV(:,NBUTIME,:)    &
977                             + MASK_COMPRESS(MYM(XRHODJ))
978   IF (LBU_RW)   XBURHODJW(:,NBUTIME,:) = XBURHODJW(:,NBUTIME,:)    &
979                             + MASK_COMPRESS(MZM(1,IKU,1,XRHODJ))
980   IF (ALLOCATED(XBURHODJ))                                         &
981                 XBURHODJ (:,NBUTIME,:) = XBURHODJ (:,NBUTIME,:)    &
982                               + MASK_COMPRESS(XRHODJ)
983 END IF
984 !
985 IF (NBUMOD==IMI .AND. CBUTYPE=='CART' ) THEN
986   IF (LBU_RU)   XBURHODJU(:,:,:) = XBURHODJU(:,:,:)    &
987                 + CART_COMPRESS(MXM(XRHODJ))
988   IF (LBU_RV)   XBURHODJV(:,:,:) = XBURHODJV(:,:,:)    &
989                 + CART_COMPRESS(MYM(XRHODJ))
990   IF (LBU_RW)   XBURHODJW(:,:,:) = XBURHODJW(:,:,:)    &
991                 + CART_COMPRESS(MZM(1,IKU,1,XRHODJ))
992   IF (ALLOCATED(XBURHODJ))                             &
993                 XBURHODJ (:,:,:) = XBURHODJ (:,:,:)    &
994                 + CART_COMPRESS(XRHODJ)
995 END IF
996 !
997 CALL BUDGET_FLAGS(LUSERV, LUSERC, LUSERR,         &
998                   LUSERI, LUSERS, LUSERG, LUSERH  )
999 !
1000 XTIME_BU   = 0.0
1001 !
1002 !-------------------------------------------------------------------------------
1003 !
1004 !*       6.    INITIALIZATION OF THE FIELD TENDENCIES
1005 !              --------------------------------------
1006 !
1007 ZTIME1 = ZTIME2
1008 XTIME_BU_PROCESS = 0.
1009 !
1010 CALL INITIAL_GUESS ( NRR, NSV, KTCOUNT, XRHODJ,IMI, XTSTEP,                 &
1011                      XRUS, XRVS, XRWS, XRTHS, XRRS, XRTKES, XRSVS,          &
1012                      XUT, XVT, XWT, XTHT, XRT, XTKET, XSVT )
1013 !
1014 CALL SECOND_MNH2(ZTIME2)
1015 !
1016 XT_GUESS = XT_GUESS + ZTIME2 - ZTIME1 - XTIME_BU_PROCESS
1017 !
1018 !-------------------------------------------------------------------------------
1019 !
1020 !*       7.    INITIALIZATION OF THE LES FOR CURRENT TIME-STEP
1021 !              -----------------------------------------------
1022 !
1023 XTIME_LES_BU   = 0.0
1024 XTIME_LES      = 0.0
1025 IF (LLES) CALL LES_INI_TIMESTEP_n(KTCOUNT)
1026 !
1027 !-------------------------------------------------------------------------------
1028 !
1029 !*       8.    TWO-WAY INTERACTIVE GRID-NESTING
1030 !              --------------------------------
1031 !
1032 !
1033 CALL SECOND_MNH2(ZTIME1)
1034 XTIME_BU_PROCESS = 0.
1035 XTIME_LES_BU_PROCESS = 0.
1036 !
1037 GMASKkids(:,:)=.FALSE.
1038 !
1039 IF (NMODEL>1) THEN
1040   ! correct an ifort bug
1041   DPTR_XRHODJ=>XRHODJ
1042   DPTR_XUM=>XUT
1043   DPTR_XVM=>XVT
1044   DPTR_XWM=>XWT
1045   DPTR_XTHM=>XTHT
1046   DPTR_XRM=>XRT
1047   DPTR_XTKEM=>XTKET
1048   DPTR_XSVM=>XSVT
1049   DPTR_XRUS=>XRUS
1050   DPTR_XRVS=>XRVS
1051   DPTR_XRWS=>XRWS
1052   DPTR_XRTHS=>XRTHS
1053   DPTR_XRRS=>XRRS
1054   DPTR_XRTKES=>XRTKES
1055   DPTR_XRSVS=>XRSVS
1056   DPTR_XINPRC=>XINPRC
1057   DPTR_XINPRR=>XINPRR
1058   DPTR_XINPRS=>XINPRS
1059   DPTR_XINPRG=>XINPRG
1060   DPTR_XINPRH=>XINPRH
1061   DPTR_XPRCONV=>XPRCONV
1062   DPTR_XPRSCONV=>XPRSCONV
1063   DPTR_XDIRFLASWD=>XDIRFLASWD
1064   DPTR_XSCAFLASWD=>XSCAFLASWD
1065   DPTR_XDIRSRFSWD=>XDIRSRFSWD
1066   DPTR_GMASKkids=>GMASKkids
1067   !
1068   CALL TWO_WAY(     CLUOUT,NRR,NSV,KTCOUNT,DPTR_XRHODJ,IMI,XTSTEP,        &        
1069        DPTR_XUM ,DPTR_XVM ,DPTR_XWM , DPTR_XTHM, DPTR_XRM, DPTR_XTKEM, DPTR_XSVM,              &        
1070        DPTR_XRUS,DPTR_XRVS,DPTR_XRWS,DPTR_XRTHS,DPTR_XRRS,DPTR_XRTKES,DPTR_XRSVS,              &
1071        DPTR_XINPRC,DPTR_XINPRR,DPTR_XINPRS,DPTR_XINPRG,DPTR_XINPRH,DPTR_XPRCONV,DPTR_XPRSCONV, &
1072        DPTR_XDIRFLASWD,DPTR_XSCAFLASWD,DPTR_XDIRSRFSWD,DPTR_GMASKkids           )
1073 END IF
1074 !
1075 CALL SECOND_MNH2(ZTIME2)
1076 XT_2WAY = XT_2WAY + ZTIME2 - ZTIME1 - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1077 !
1078 !-------------------------------------------------------------------------------
1079 !-------------------------------------------------------------------------------
1080 !
1081 !*       10.    FORCING
1082 !               -------
1083 !
1084 !
1085 ZTIME1 = ZTIME2
1086 XTIME_BU_PROCESS = 0.
1087 XTIME_LES_BU_PROCESS = 0.
1088 !
1089 IF ( LFORCING ) THEN
1090   CALL FORCING(XTSTEP,LUSERV,XRHODJ,XCORIOZ,XZHAT,XZZ,TDTCUR,&
1091                XUFRC_PAST, XVFRC_PAST,                &
1092                XUT,XVT,XWT,XTHT,XTKET,XRT,XSVT,       &
1093                XRUS,XRVS,XRWS,XRTHS,XRTKES,XRRS,XRSVS,IMI)
1094 END IF
1095 !
1096 IF ( L2D_ADV_FRC ) THEN 
1097   CALL ADV_FORCING_n(XRHODJ,TDTCUR,XTHT,XRT,XZZ,XRTHS,XRRS)
1098 END IF
1099 IF ( L2D_REL_FRC ) THEN 
1100   CALL REL_FORCING_n(XRHODJ,TDTCUR,XTHT,XRT,XZZ,XRTHS,XRRS)
1101 END IF
1102 !
1103 CALL SECOND_MNH2(ZTIME2)
1104 !
1105 XT_FORCING = XT_FORCING + ZTIME2 - ZTIME1 &
1106              - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1107 !
1108 !-------------------------------------------------------------------------------
1109 !
1110 !*       11.    NUDGING
1111 !               -------
1112 !
1113 !
1114 ZTIME1 = ZTIME2
1115 XTIME_BU_PROCESS = 0.
1116 XTIME_LES_BU_PROCESS = 0.
1117 !
1118 IF ( LNUDGING ) THEN
1119   CALL NUDGING(LUSERV,XRHODJ,XTNUDGING,         &
1120                XUT,XVT,XWT,XTHT,XRT,            &
1121                XLSUM,XLSVM,XLSWM,XLSTHM,XLSRVM, &
1122                XRUS,XRVS,XRWS,XRTHS,XRRS)
1123
1124 END IF
1125 !
1126 CALL SECOND_MNH2(ZTIME2)
1127 !
1128 XT_NUDGING = XT_NUDGING + ZTIME2 - ZTIME1 &
1129              - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1130 !
1131 !-------------------------------------------------------------------------------
1132 !
1133 !*       12.    DYNAMICAL SOURCES
1134 !               -----------------
1135 !
1136 ZTIME1 = ZTIME2
1137 XTIME_BU_PROCESS = 0.
1138 XTIME_LES_BU_PROCESS = 0.
1139 !
1140 IF( LTRANS ) THEN
1141   XUT(:,:,:) = XUT(:,:,:) + XUTRANS
1142   XVT(:,:,:) = XVT(:,:,:) + XVTRANS
1143 END IF
1144 !
1145 CALL DYN_SOURCES( NRR,NRRL, NRRI,                              &
1146                   XUT, XVT, XWT, XTHT, XRT,                    &
1147                   XCORIOX, XCORIOY, XCORIOZ, XCURVX, XCURVY,   &
1148                   XRHODJ, XZZ, XTHVREF, XEXNREF,               &
1149                   XRUS, XRVS, XRWS, XRTHS                      )
1150 !
1151 IF( LTRANS ) THEN
1152   XUT(:,:,:) = XUT(:,:,:) - XUTRANS
1153   XVT(:,:,:) = XVT(:,:,:) - XVTRANS
1154 END IF
1155 !
1156 CALL SECOND_MNH2(ZTIME2)
1157 !
1158 XT_SOURCES = XT_SOURCES + ZTIME2 - ZTIME1 &
1159              - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1160 !
1161 !-------------------------------------------------------------------------------
1162 !
1163 !*       13.    NUMERICAL DIFFUSION
1164 !               -------------------
1165 !
1166 ZTIME1 = ZTIME2
1167 XTIME_BU_PROCESS = 0.
1168 XTIME_LES_BU_PROCESS = 0.
1169 !
1170 IF ( LNUMDIFU .OR. LNUMDIFTH .OR. LNUMDIFSV ) THEN
1171 !
1172   CALL UPDATE_HALO_ll(TZFIELDT_ll, IINFO_ll)
1173   CALL UPDATE_HALO2_ll(TZFIELDT_ll, TZHALO2T_ll, IINFO_ll)
1174   IF ( .NOT. LSTEADYLS ) THEN
1175      CALL UPDATE_HALO_ll(TZLSFIELD_ll, IINFO_ll)
1176      CALL UPDATE_HALO2_ll(TZLSFIELD_ll, TZLSHALO2_ll, IINFO_ll)
1177   END IF
1178   CALL NUM_DIFF ( CLBCX, CLBCY, NRR, NSV,                               &
1179                   XDK2U, XDK4U, XDK2TH, XDK4TH, XDK2SV, XDK4SV, IMI,    &
1180                   XUT, XVT, XWT, XTHT, XTKET, XRT, XSVT,                &
1181                   XLSUM,XLSVM,XLSWM,XLSTHM,XLSRVM,XRHODJ,               &
1182                   XRUS, XRVS, XRWS, XRTHS, XRTKES, XRRS, XRSVS,         &
1183                   LZDIFFU,LNUMDIFU, LNUMDIFTH, LNUMDIFSV,               &
1184                   TZHALO2T_ll, TZLSHALO2_ll,XZDIFFU_HALO2      )
1185 END IF
1186 !
1187 DO JSV = NSV_CHEMBEG,NSV_CHEMEND
1188   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1189 END DO
1190 DO JSV = NSV_CHICBEG,NSV_CHICEND
1191   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1192 END DO
1193 DO JSV = NSV_AERBEG,NSV_AEREND
1194   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1195 END DO
1196 DO JSV = NSV_LNOXBEG,NSV_LNOXEND
1197   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1198 END DO
1199 DO JSV = NSV_DSTBEG,NSV_DSTEND
1200   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1201 END DO
1202 DO JSV = NSV_SLTBEG,NSV_SLTEND
1203   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1204 END DO
1205 DO JSV = NSV_PPBEG,NSV_PPEND
1206   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1207 END DO
1208 #ifdef MNH_FOREFIRE
1209 DO JSV = NSV_FFBEG,NSV_FFEND
1210   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1211 END DO
1212 #endif
1213 DO JSV = NSV_CSBEG,NSV_CSEND
1214   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1215 END DO
1216 DO JSV = NSV_DSTDEPBEG,NSV_DSTDEPEND
1217   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1218 END DO
1219 DO JSV = NSV_SLTDEPBEG,NSV_SLTDEPEND
1220   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1221 END DO
1222 DO JSV = NSV_AERDEPBEG,NSV_AERDEPEND
1223   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
1224 END DO
1225
1226 IF (CELEC .NE. 'NONE') THEN
1227   XRSVS(:,:,:,NSV_ELECBEG) = MAX(XRSVS(:,:,:,NSV_ELECBEG),0.)
1228   XRSVS(:,:,:,NSV_ELECEND) = MAX(XRSVS(:,:,:,NSV_ELECEND),0.)
1229 END IF
1230 !
1231 CALL SECOND_MNH2(ZTIME2)
1232 !
1233 XT_DIFF = XT_DIFF + ZTIME2 - ZTIME1 &
1234           - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1235 !
1236 !-------------------------------------------------------------------------------
1237 !
1238 !*       14.    UPPER AND LATERAL RELAXATION
1239 !               ----------------------------
1240 !
1241 ZTIME1 = ZTIME2
1242 XTIME_BU_PROCESS = 0.
1243 XTIME_LES_BU_PROCESS = 0.
1244 !
1245 IF(LVE_RELAX .OR. LVE_RELAX_GRD .OR. LHORELAX_UVWTH .OR. LHORELAX_RV .OR.&
1246    LHORELAX_RC .OR. LHORELAX_RR .OR. LHORELAX_RI .OR. LHORELAX_RS .OR.   &
1247    LHORELAX_RG .OR. LHORELAX_RH .OR. LHORELAX_TKE .OR.                   &
1248    ANY(LHORELAX_SV)) THEN
1249   CALL RELAXATION (LVE_RELAX,LVE_RELAX_GRD,LHORELAX_UVWTH,LHORELAX_RV,LHORELAX_RC,   &
1250                    LHORELAX_RR,LHORELAX_RI,LHORELAX_RS,LHORELAX_RG,    &
1251                    LHORELAX_RH,LHORELAX_TKE,LHORELAX_SV,               &
1252                    LHORELAX_SVC2R2,LHORELAX_SVC1R3,                    &
1253                    LHORELAX_SVELEC,LHORELAX_SVLG,                      &
1254                    LHORELAX_SVCHEM,LHORELAX_SVCHIC,LHORELAX_SVAER,     &
1255                    LHORELAX_SVDST,LHORELAX_SVSLT,LHORELAX_SVPP,        &
1256                    LHORELAX_SVCS,                                      &
1257 #ifdef MNH_FOREFIRE
1258                    LHORELAX_SVFF,                                      &
1259 #endif
1260                    KTCOUNT,NRR,NSV,XTSTEP,XRHODJ,                      &
1261                    XUT, XVT, XWT, XTHT, XRT, XSVT, XTKET,              &
1262                    XLSUM, XLSVM, XLSWM, XLSTHM,                        &
1263                    XLBXUM, XLBXVM, XLBXWM, XLBXTHM,                    &
1264                    XLBXRM, XLBXSVM, XLBXTKEM,                          &
1265                    XLBYUM, XLBYVM, XLBYWM, XLBYTHM,                    &
1266                    XLBYRM, XLBYSVM, XLBYTKEM,                          &
1267                    NALBOT, XALK, XALKW,                                &
1268                    NALBAS, XALKBAS, XALKWBAS,                          &
1269                    LMASK_RELAX,XKURELAX, XKVRELAX, XKWRELAX,           &
1270                    NRIMX,NRIMY,                                        &
1271                    XRUS, XRVS, XRWS, XRTHS, XRRS, XRSVS, XRTKES        )
1272 END IF
1273
1274 IF (CELEC.NE.'NONE' .AND. LRELAX2FW_ION) THEN
1275    CALL RELAX2FW_ION (KTCOUNT, IMI, XTSTEP, XRHODJ, XSVT, NALBOT,      &
1276                       XALK, LMASK_RELAX, XKWRELAX, XRSVS )   
1277 END IF                      
1278 !
1279 CALL SECOND_MNH2(ZTIME2)
1280 !
1281 XT_RELAX = XT_RELAX + ZTIME2 - ZTIME1 &
1282            - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1283 !
1284 !-------------------------------------------------------------------------------
1285 !
1286 !*       15.    PARAMETRIZATIONS' MONITOR
1287 !               -------------------------
1288 !
1289 ZTIME1 = ZTIME2
1290 !
1291 #ifdef MNH_NCWRIT
1292 IF ( LNETCDF .AND. GCLOSE_OUT ) THEN
1293   DEF_NC = .TRUE.
1294   NC_WRITE=LNETCDF
1295   NC_FILE='phy'
1296   LLFIFM = .FALSE.
1297   CALL WRITE_PHYS_PARAM(YFMFILE)
1298   DEF_NC=.FALSE.
1299   LLFIFM = .TRUE.
1300 END IF
1301 CALL PHYS_PARAM_n(KTCOUNT,YFMFILE, GCLOSE_OUT,                        &
1302                   XT_RAD,XT_SHADOWS,XT_DCONV,XT_GROUND,XT_MAFL,       &
1303                   XT_DRAG,XT_TURB,XT_TRACER,                          &
1304                   XT_CHEM,ZTIME,GMASKkids)
1305 DEF_NC=.TRUE.
1306 #else
1307 CALL PHYS_PARAM_n(KTCOUNT,YFMFILE, GCLOSE_OUT,                        &
1308                   XT_RAD,XT_SHADOWS,XT_DCONV,XT_GROUND,XT_MAFL,       &
1309                   XT_DRAG,XT_TURB,XT_TRACER,                          &
1310                   XT_CHEM,ZTIME,GMASKkids)
1311 #endif                  
1312 !
1313 IF (CDCONV/='NONE') THEN
1314   XPACCONV = XPACCONV + XPRCONV * XTSTEP
1315   IF (LCH_CONV_LINOX) THEN
1316     XIC_TOTAL_NUMBER = XIC_TOTAL_NUMBER + XIC_RATE * XTSTEP
1317     XCG_TOTAL_NUMBER = XCG_TOTAL_NUMBER + XCG_RATE * XTSTEP
1318   END IF
1319 END IF
1320 !
1321 DO JOUT = 1,NOUT_NUMB
1322   IF (KTCOUNT == NOUT_TIMES(JOUT)) THEN
1323     IF (CSURF=='EXTE') THEN
1324       CALL GOTO_SURFEX(IMI,.TRUE.)
1325       CALL DIAG_SURF_ATM_n('MESONH')
1326 #ifdef MNH_NCWRIT
1327       NC_WRITE=LNETCDF
1328       NC_FILE='sf2'
1329       CALL WRITE_DIAG_SURF_ATM_n('MESONH','ALL')
1330       IF ( LNETCDF ) THEN
1331         DEF_NC=.FALSE.
1332         CALL WRITE_DIAG_SURF_ATM_n('MESONH','ALL')
1333         DEF_NC=.TRUE.
1334         NC_WRITE = .FALSE.
1335       END IF
1336 #else
1337       CALL WRITE_DIAG_SURF_ATM_n('MESONH','ALL')
1338 #endif
1339     END IF
1340   END IF
1341 END DO
1342 !
1343 CALL SECOND_MNH2(ZTIME2)
1344 !
1345 XT_PARAM = XT_PARAM + ZTIME2 - ZTIME1 - XTIME_LES - ZTIME
1346 !
1347 !-------------------------------------------------------------------------------
1348 !
1349 !*       16.    TEMPORAL SERIES
1350 !               ---------------
1351 !
1352 ZTIME1 = ZTIME2
1353 !
1354 IF (LSERIES) THEN
1355   IF ( MOD (KTCOUNT-1,NFREQSERIES) == 0 ) CALL SERIES_n
1356 END IF
1357 !
1358 CALL SECOND_MNH2(ZTIME2)
1359 !
1360 XT_STEP_MISC = XT_STEP_MISC + ZTIME2 - ZTIME1
1361 !
1362 !-------------------------------------------------------------------------------
1363 !
1364 !*       17.    LARGE SCALE FIELD REFRESH
1365 !               -------------------------
1366 !
1367 ZTIME1 = ZTIME2
1368 !
1369 IF (.NOT. LSTEADYLS) THEN
1370   IF (  IMI==1                             .AND.      &
1371     NCPL_CUR < NCPL_NBR                              ) THEN
1372     IF (KTCOUNT+1 == NCPL_TIMES(NCPL_CUR,1)          ) THEN
1373                                   ! The next current time reachs a
1374       NCPL_CUR=NCPL_CUR+1         ! coupling one, LS sources are refreshed
1375       !
1376       CALL LS_COUPLING(CLUOUT,XTSTEP,GSTEADY_DMASS,CCONF,                   &
1377              CGETTKET,                                                      &
1378              CGETRVT,CGETRCT,CGETRRT,CGETRIT,                               &
1379              CGETRST,CGETRGT,CGETRHT,CGETSVT,LCH_INIT_FIELD, NSV,           &
1380              NIMAX_ll,NJMAX_ll,                                             &
1381              NSIZELBX_ll,NSIZELBXU_ll,NSIZELBY_ll,NSIZELBYV_ll,             &
1382              NSIZELBXTKE_ll,NSIZELBYTKE_ll,                                 &
1383              NSIZELBXR_ll,NSIZELBYR_ll,NSIZELBXSV_ll,NSIZELBYSV_ll,         &
1384              XLSUM,XLSVM,XLSWM,XLSTHM,XLSRVM,XDRYMASST,                     &
1385              XLBXUM,XLBXVM,XLBXWM,XLBXTHM,XLBXTKEM,XLBXRM,XLBXSVM,          &
1386              XLBYUM,XLBYVM,XLBYWM,XLBYTHM,XLBYTKEM,XLBYRM,XLBYSVM,          &
1387              XLSUS,XLSVS,XLSWS,XLSTHS,XLSRVS,XDRYMASSS,                     &
1388              XLBXUS,XLBXVS,XLBXWS,XLBXTHS,XLBXTKES,XLBXRS,XLBXSVS,          &
1389              XLBYUS,XLBYVS,XLBYWS,XLBYTHS,XLBYTKES,XLBYRS,XLBYSVS           )
1390       !
1391       DO JSV=NSV_CHEMBEG,NSV_CHEMEND
1392         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
1393         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
1394       ENDDO
1395       !
1396       DO JSV=NSV_LNOXBEG,NSV_LNOXEND
1397         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
1398         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
1399       ENDDO
1400       !
1401       DO JSV=NSV_AERBEG,NSV_AEREND
1402         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
1403         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
1404       ENDDO
1405       !
1406       DO JSV=NSV_DSTBEG,NSV_DSTEND
1407         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
1408         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
1409       ENDDO
1410       !
1411       DO JSV=NSV_DSTDEPBEG,NSV_DSTDEPEND
1412         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
1413         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
1414       ENDDO
1415       !
1416       DO JSV=NSV_SLTBEG,NSV_SLTEND
1417         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
1418         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
1419       ENDDO
1420       !
1421       DO JSV=NSV_SLTDEPBEG,NSV_SLTDEPEND
1422         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
1423         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
1424       ENDDO
1425       !
1426       DO JSV=NSV_PPBEG,NSV_PPEND
1427         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
1428         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
1429       ENDDO
1430       !
1431 #ifdef MNH_FOREFIRE
1432       DO JSV=NSV_FFBEG,NSV_FFEND
1433         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
1434         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
1435       ENDDO
1436       !
1437 #endif
1438       DO JSV=NSV_CSBEG,NSV_CSEND
1439         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
1440         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
1441       ENDDO
1442      END IF
1443   END IF
1444 END IF
1445 !
1446 CALL SECOND_MNH2(ZTIME2)
1447 !
1448 XT_COUPL = XT_COUPL + ZTIME2 - ZTIME1
1449 !
1450 !-------------------------------------------------------------------------------
1451 !
1452 !
1453 !*       9.    ADVECTION
1454 !              ---------
1455 !
1456 ZTIME1 = ZTIME2
1457 XTIME_BU_PROCESS = 0.
1458 XTIME_LES_BU_PROCESS = 0.
1459 !
1460 !
1461 !
1462 CALL MPPDB_CHECK3DM("before ADVEC_METSV:XU/V/W/TH/TKE/T,XRHODJ",PRECISION,&
1463                    &  XUT, XVT, XWT, XTHT, XTKET,XRHODJ)
1464  CALL ADVECTION_METSV ( CLUOUT, YFMFILE, GCLOSE_OUT,CUVW_ADV_SCHEME, &
1465                  CMET_ADV_SCHEME, CSV_ADV_SCHEME, CCLOUD, NSPLIT,    &
1466                  LSPLIT_CFL, XSPLIT_CFL, LCFL_WRIT,                  &
1467                  CLBCX, CLBCY, NRR, NSV, TDTCUR, XTSTEP,             &
1468                  XUT, XVT, XWT, XTHT, XRT, XTKET, XSVT, XPABST,      &
1469                  XTHVREF, XRHODJ, XDXX, XDYY, XDZZ, XDZX, XDZY,      &
1470                  XRTHS, XRRS, XRTKES, XRSVS,                         &
1471                  XRTHS_CLD, XRRS_CLD, XRSVS_CLD, XRTKEMS             )
1472 CALL MPPDB_CHECK3DM("after  ADVEC_METSV:XU/V/W/TH/TKE/T,XRHODJ ",PRECISION,&
1473                    &  XUT, XVT, XWT, XTHT, XTKET,XRHODJ)
1474 !
1475 CALL SECOND_MNH2(ZTIME2)
1476 !
1477 XT_ADV = XT_ADV + ZTIME2 - ZTIME1 - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1478 !
1479 ZTIME1 = ZTIME2
1480 XTIME_BU_PROCESS = 0.
1481 XTIME_LES_BU_PROCESS = 0.
1482 !
1483 ZRWS = XRWS
1484 !
1485 CALL GRAVITY_IMPL ( CLBCX, CLBCY, NRR, NRRL, NRRI,XTSTEP,            &
1486                  XTHT, XRT, XTHVREF, XRHODJ, XRWS, XRTHS, XRRS,      &
1487                  XRTHS_CLD, XRRS_CLD                                 )   
1488 !
1489 ! At the initial instant the difference with the ref state creates a 
1490 ! vertical velocity production that must not be advected as it is 
1491 ! compensated by the pressure gradient
1492 !
1493 IF (KTCOUNT == 1 .AND. CCONF=='START') XRWS_PRES = - (XRWS - ZRWS) 
1494 !
1495 CALL SECOND_MNH2(ZTIME2)
1496 !
1497 XT_GRAV = XT_GRAV + ZTIME2 - ZTIME1 - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1498
1499 ZTIME1 = ZTIME2
1500 XTIME_BU_PROCESS = 0.
1501 XTIME_LES_BU_PROCESS = 0.
1502 !
1503 !MPPDB_CHECK_LB=.TRUE.
1504 CALL MPPDB_CHECK3DM("before ADVEC_UVW:XU/V/W/TH/TKE/T,XRHODJ,XRU/V/Ws",PRECISION,&
1505                    &  XUT, XVT, XWT, XTHT, XTKET,XRHODJ,XRUS,XRVS,XRWS)
1506 IF (CUVW_ADV_SCHEME(1:3)=='CEN') THEN
1507   IF (CUVW_ADV_SCHEME=='CEN4TH') THEN
1508     NULLIFY(TZFIELDC_ll)
1509     NULLIFY(TZHALO2C_ll)
1510       CALL ADD3DFIELD_ll(TZFIELDC_ll, XUT)
1511       CALL ADD3DFIELD_ll(TZFIELDC_ll, XVT)
1512       CALL ADD3DFIELD_ll(TZFIELDC_ll, XWT)
1513       CALL INIT_HALO2_ll(TZHALO2C_ll,3,IIU,IJU,IKU)
1514       CALL UPDATE_HALO_ll(TZFIELDC_ll,IINFO_ll)
1515       CALL UPDATE_HALO2_ll(TZFIELDC_ll, TZHALO2C_ll, IINFO_ll)
1516   END IF
1517  CALL ADVECTION_UVW_CEN(CUVW_ADV_SCHEME,                &
1518                            CLBCX, CLBCY,                           &
1519                            XTSTEP, KTCOUNT,                        &
1520                            XUM, XVM, XWM, XDUM, XDVM, XDWM,        &
1521                            XUT, XVT, XWT,                          &
1522                            XRHODJ, XDXX, XDYY, XDZZ, XDZX, XDZY,   &
1523                            XRUS,XRVS, XRWS,                        &
1524                            TZHALO2C_ll                             )
1525   IF (CUVW_ADV_SCHEME=='CEN4TH') THEN
1526     CALL CLEANLIST_ll(TZFIELDC_ll)
1527     NULLIFY(TZFIELDC_ll)
1528     CALL  DEL_HALO2_ll(TZHALO2C_ll)
1529     NULLIFY(TZHALO2C_ll)
1530   END IF
1531 ELSE
1532
1533   CALL ADVECTION_UVW(CUVW_ADV_SCHEME, CTEMP_SCHEME,                  &
1534                  NWENO_ORDER, NSPLIT,                                &
1535                  CLBCX, CLBCY, XTSTEP,                               &
1536                  XUT, XVT, XWT,                                      &
1537                  XRHODJ, XDXX, XDYY, XDZZ, XDZX, XDZY,               &
1538                  XRUS, XRVS, XRWS,                                   &
1539                  XRUS_PRES, XRVS_PRES, XRWS_PRES                     )
1540 END IF
1541 !
1542 CALL MPPDB_CHECK3DM("after  ADVEC_UVW:XU/V/W/TH/TKE/T,XRHODJ,XRU/V/Ws",PRECISION,&
1543                    &  XUT, XVT, XWT, XTHT, XTKET,XRHODJ,XRUS,XRVS,XRWS)
1544 !MPPDB_CHECK_LB=.FALSE.
1545 !
1546 CALL SECOND_MNH2(ZTIME2)
1547 !
1548 XT_ADVUVW = XT_ADVUVW + ZTIME2 - ZTIME1 - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1549 !
1550 !-------------------------------------------------------------------------------
1551 !
1552 IF (NMODEL_CLOUD==IMI .AND. CTURBLEN_CLOUD/='NONE') THEN
1553   CALL TURB_CLOUD_INDEX(XTSTEP,YFMFILE,CLUOUT,                    &
1554                         LTURB_DIAG,GCLOSE_OUT,NRRI,               &
1555                         XRRS,XRT,XRHODJ,XDXX,XDYY,XDZZ,XDZX,XDZY, &
1556                         XCEI )
1557 END IF
1558 !
1559 !-------------------------------------------------------------------------------
1560 !
1561 !*       18.    LATERAL BOUNDARY CONDITION FOR THE NORMAL VELOCITY
1562 !               --------------------------------------------------
1563 !
1564 ZTIME1 = ZTIME2
1565 !
1566 CALL MPPDB_CHECK3DM("before RAD_BOUND :XRU/V/WS",PRECISION,XRUS,XRVS,XRWS)
1567 ZRUS=XRUS
1568 ZRVS=XRVS
1569 ZRWS=XRWS
1570 !
1571   CALL RAD_BOUND (CLBCX,CLBCY,CTURB,XCARPKMAX,           &
1572                 XTSTEP,                                  &
1573                 XDXHAT, XDYHAT, XZHAT,                   &
1574                 XUT, XVT,                                &
1575                 XLBXUM, XLBYVM, XLBXUS, XLBYVS,          &
1576                 XCPHASE, XCPHASE_PBL, XRHODJ,            &
1577                 XTKET,XRUS, XRVS, XRWS                   )
1578 ZRUS=XRUS-ZRUS
1579 ZRVS=XRVS-ZRVS
1580 ZRWS=XRWS-ZRWS
1581 !
1582 CALL SECOND_MNH2(ZTIME2)
1583 !
1584 XT_RAD_BOUND = XT_RAD_BOUND + ZTIME2 - ZTIME1
1585 !
1586 !-------------------------------------------------------------------------------
1587 !
1588 !*       19.    PRESSURE COMPUTATION
1589 !               --------------------
1590 !
1591 ZTIME1 = ZTIME2
1592 XTIME_BU_PROCESS = 0.
1593 XTIME_LES_BU_PROCESS = 0.
1594 !
1595 !
1596 IF(.NOT. L1D) THEN
1597 !
1598 CALL MPPDB_CHECK3DM("before pressurez:XRU/V/WS",PRECISION,XRUS,XRVS,XRWS)
1599   XRUS_PRES = XRUS
1600   XRVS_PRES = XRVS
1601   XRWS_PRES = XRWS
1602 !
1603   CALL PRESSUREZ( CLUOUT,                                                &
1604                   CLBCX,CLBCY,CPRESOPT,NITR,LITRADJ,KTCOUNT, XRELAX,IMI, &
1605                   XRHODJ,XDXX,XDYY,XDZZ,XDZX,XDZY,XDXHATM,XDYHATM,XRHOM, &
1606                   XAF,XBFY,XCF,XTRIGSX,XTRIGSY,NIFAXX,NIFAXY,            &
1607                   NRR,NRRL,NRRI,XDRYMASST,XREFMASS,XMASS_O_PHI0,         &
1608                   XTHT,XRT,XRHODREF,XTHVREF,XRVREF,XEXNREF, XLINMASS,    &
1609                   XRUS, XRVS, XRWS, XPABST,                              &
1610                   XBFB,&
1611                   XBF_SXP2_YP1_Z) !JUAN Z_SPLITING
1612 !
1613   XRUS_PRES = XRUS - XRUS_PRES + ZRUS
1614   XRVS_PRES = XRVS - XRVS_PRES + ZRVS
1615   XRWS_PRES = XRWS - XRWS_PRES + ZRWS
1616 !
1617 END IF
1618 !
1619 CALL SECOND_MNH2(ZTIME2)
1620 !
1621 XT_PRESS = XT_PRESS + ZTIME2 - ZTIME1 &
1622            - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1623 !
1624 !-------------------------------------------------------------------------------
1625 !
1626 !*       20.    WATER MICROPHYSICS
1627 !               ------------------
1628 !
1629 ZTIME1 = ZTIME2
1630 XTIME_BU_PROCESS = 0.
1631 XTIME_LES_BU_PROCESS = 0.
1632 !
1633 IF (CCLOUD /= 'NONE' .AND. CELEC == 'NONE') THEN
1634 !
1635   IF (CCLOUD == 'C2R2' .OR. CCLOUD == 'KHKO' .OR. CCLOUD == 'C3R5' ) THEN
1636     IF ( LFORCING ) THEN
1637       ZWT_ACT_NUC(:,:,:) = XWT(:,:,:) + XWTFRC(:,:,:)
1638     ELSE
1639       ZWT_ACT_NUC(:,:,:) = XWT(:,:,:)
1640     END IF
1641     IF (CTURB /= 'NONE' ) THEN
1642       ZWT_ACT_NUC(:,:,:) = ZWT_ACT_NUC(:,:,:) + (2./3. * XTKET(:,:,:))**0.5
1643     ENDIF
1644   ELSE
1645     ZWT_ACT_NUC(:,:,:) = 0.
1646   END IF
1647 !
1648   XRTHS_CLD  = XRTHS
1649   XRRS_CLD   = XRRS
1650   XRSVS_CLD  = XRSVS
1651   IF (CSURF=='EXTE') THEN
1652     ALLOCATE (ZSEA(SIZE(XRHODJ,1),SIZE(XRHODJ,2)))
1653     ALLOCATE (ZTOWN(SIZE(XRHODJ,1),SIZE(XRHODJ,2)))
1654     ZSEA(:,:) = 0.
1655     ZTOWN(:,:)= 0.
1656     CALL MNHGET_SURF_PARAM_n (PSEA=ZSEA(:,:),PTOWN=ZTOWN(:,:))
1657 #ifdef MNH_NCWRIT
1658     NC_FILE='phy'
1659     DEF_NC=.FALSE.
1660     CALL RESOLVED_CLOUD ( CCLOUD, CACTCCN, CSCONV, CMF_CLOUD, NRR, NSPLITR,    &
1661                           NSPLITG, IMI, KTCOUNT,                               &
1662                           CLBCX,CLBCY,YFMFILE, CLUOUT, CRAD, CTURBDIM,         &
1663                           GCLOSE_OUT, LSUBG_COND,LSIGMAS,CSUBG_AUCV,XTSTEP,    &
1664                           XZZ, XRHODJ, XRHODREF, XEXNREF,                      &
1665                           XPABST, XTHT,XRT,XSIGS,VSIGQSAT,XMFCONV,XTHM,XRCM,   &
1666                           XPABSM, ZWT_ACT_NUC,XDTHRAD, XRTHS, XRRS,            &
1667                           XSVT, XRSVS,                                         &
1668                           XSRCT, XCLDFR,XCIT,                                  &
1669                           LSEDIC,LACTIT, LSEDC, LSEDI, LRAIN, LWARM, LHHONI,   &
1670                           LCONVHG, XCF_MF,XRC_MF, XRI_MF,                      &
1671                           XINPRC,ZINPRC3D,XINPRR, XINPRR3D, XEVAP3D,           &
1672                           XINPRS,ZINPRS3D, XINPRG,ZINPRG3D,                    &
1673                           XINPRH,ZINPRH3D, XSOLORG , XMI,                      &
1674                           ZSPEEDC, ZSPEEDR, ZSPEEDS, ZSPEEDG, ZSPEEDH,         &
1675                           ZSEA, ZTOWN    )
1676     DEF_NC=.TRUE.
1677 #else    
1678     CALL RESOLVED_CLOUD ( CCLOUD, CACTCCN, CSCONV, CMF_CLOUD, NRR, NSPLITR,    &
1679                           NSPLITG, IMI, KTCOUNT,                               &
1680                           CLBCX,CLBCY,YFMFILE, CLUOUT, CRAD, CTURBDIM,         &
1681                           GCLOSE_OUT, LSUBG_COND,LSIGMAS,CSUBG_AUCV,XTSTEP,    &
1682                           XZZ, XRHODJ, XRHODREF, XEXNREF,                      &
1683                           XPABST, XTHT,XRT,XSIGS,VSIGQSAT,XMFCONV,XTHM,XRCM,   &
1684                           XPABSM, ZWT_ACT_NUC,XDTHRAD, XRTHS, XRRS,            &
1685                           XSVT, XRSVS,                                         &
1686                           XSRCT, XCLDFR,XCIT,                                  &
1687                           LSEDIC,LACTIT, LSEDC, LSEDI, LRAIN, LWARM, LHHONI,   &
1688                           LCONVHG, XCF_MF,XRC_MF, XRI_MF,                      &
1689                           XINPRC,ZINPRC3D,XINPRR, XINPRR3D, XEVAP3D,           &
1690                           XINPRS,ZINPRS3D, XINPRG,ZINPRG3D, XINPRH,ZINPRH3D,   &
1691                           XSOLORG , XMI,                                       &
1692                           ZSPEEDC, ZSPEEDR, ZSPEEDS, ZSPEEDG, ZSPEEDH,         &
1693                           ZSEA, ZTOWN    )
1694 #endif
1695     DEALLOCATE(ZTOWN)
1696   ELSE
1697 #ifdef MNH_NCWRIT
1698     NC_FILE='phy'
1699     DEF_NC=.FALSE.
1700     CALL RESOLVED_CLOUD ( CCLOUD, CACTCCN, CSCONV, CMF_CLOUD, NRR, NSPLITR,    &
1701                           NSPLITG, IMI, KTCOUNT,                               &
1702                           CLBCX,CLBCY,YFMFILE, CLUOUT, CRAD, CTURBDIM,         &
1703                           GCLOSE_OUT, LSUBG_COND,LSIGMAS,CSUBG_AUCV,           &
1704                           XTSTEP,XZZ, XRHODJ, XRHODREF, XEXNREF,               &
1705                           XPABST, XTHT,XRT,XSIGS,VSIGQSAT,XMFCONV,XTHM,XRCM,   &
1706                           XPABSM, ZWT_ACT_NUC,XDTHRAD, XRTHS, XRRS,            &
1707                           XSVT, XRSVS,                                         &
1708                           XSRCT, XCLDFR,XCIT,                                  &
1709                           LSEDIC, LACTIT, LSEDC, LSEDI, LRAIN, LWARM, LHHONI,  &
1710                           LCONVHG, XCF_MF,XRC_MF, XRI_MF,                      &
1711                           XINPRC,ZINPRC3D,XINPRR, XINPRR3D, XEVAP3D,             &
1712                           XINPRS,ZINPRS3D, XINPRG,ZINPRG3D, XINPRH,ZINPRH3D,   &
1713                           XSOLORG, XMI,ZSPEEDC, ZSPEEDR, ZSPEEDS, ZSPEEDG, ZSPEEDH)
1714     DEF_NC=.TRUE.
1715 #else
1716     CALL RESOLVED_CLOUD ( CCLOUD, CACTCCN, CSCONV, CMF_CLOUD, NRR, NSPLITR,    &
1717                           NSPLITG, IMI, KTCOUNT,                               &
1718                           CLBCX,CLBCY,YFMFILE, CLUOUT, CRAD, CTURBDIM,         &
1719                           GCLOSE_OUT, LSUBG_COND,LSIGMAS,CSUBG_AUCV,           &
1720                           XTSTEP,XZZ, XRHODJ, XRHODREF, XEXNREF,               &
1721                           XPABST, XTHT,XRT,XSIGS,VSIGQSAT,XMFCONV,XTHM,XRCM,   &
1722                           XPABSM, ZWT_ACT_NUC,XDTHRAD, XRTHS, XRRS,            &
1723                           XSVT, XRSVS,                                         &
1724                           XSRCT, XCLDFR,XCIT,                                  &
1725                           LSEDIC, LACTIT, LSEDC, LSEDI, LRAIN, LWARM, LHHONI,  &
1726                           LCONVHG, XCF_MF,XRC_MF, XRI_MF,                      &
1727                           XINPRC,ZINPRC3D,XINPRR, XINPRR3D, XEVAP3D,             &
1728                           XINPRS,ZINPRS3D, XINPRG,ZINPRG3D, XINPRH,ZINPRH3D,   &
1729                           XSOLORG, XMI,                             &
1730                           ZSPEEDC, ZSPEEDR, ZSPEEDS, ZSPEEDG, ZSPEEDH          )
1731 #endif
1732   END IF
1733   XRTHS_CLD  = XRTHS - XRTHS_CLD
1734   XRRS_CLD   = XRRS  - XRRS_CLD
1735   XRSVS_CLD  = XRSVS - XRSVS_CLD
1736 !
1737   IF (CCLOUD /= 'REVE' ) THEN
1738     XACPRR = XACPRR + XINPRR * XTSTEP
1739     IF ((CCLOUD(1:3) == 'ICE' .AND. LSEDIC ) .OR.                       &
1740         ((CCLOUD == 'C2R2' .OR. CCLOUD == 'C3R5' .OR. CCLOUD == 'KHKO') &
1741                               .AND. LSEDC  )      )   THEN                  
1742       XACPRC = XACPRC + XINPRC * XTSTEP
1743     END IF
1744     IF (CCLOUD(1:3) == 'ICE' .OR. CCLOUD == 'C3R5') THEN
1745       XACPRS = XACPRS + XINPRS * XTSTEP
1746       XACPRG = XACPRG + XINPRG * XTSTEP
1747       IF (CCLOUD == 'ICE4') XACPRH = XACPRH + XINPRH * XTSTEP          
1748     END IF
1749   END IF
1750 !
1751 ! It is necessary that SV_C2R2 and SV_C1R3 are contiguous in the preceeding CALL
1752 !
1753 END IF
1754 !
1755 CALL SECOND_MNH2(ZTIME2)
1756 !
1757 XT_CLOUD = XT_CLOUD + ZTIME2 - ZTIME1 &
1758            - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1759 !
1760 !-------------------------------------------------------------------------------
1761 !
1762 !*       21.    CLOUD ELECTRIFICATION AND LIGHTNING FLASHES
1763 !               -------------------------------------------
1764 !
1765 ZTIME1 = ZTIME2
1766 XTIME_BU_PROCESS = 0.
1767 XTIME_LES_BU_PROCESS = 0.
1768 !
1769 IF (CELEC /= 'NONE' .AND. (CCLOUD(1:3) == 'ICE')) THEN
1770   ZWT_ACT_NUC(:,:,:) = 0.
1771 !
1772   XRTHS_CLD = XRTHS
1773   XRRS_CLD  = XRRS
1774   XRSVS_CLD = XRSVS
1775   IF (CSURF=='EXTE') THEN
1776     ALLOCATE (ZSEA(SIZE(XRHODJ,1),SIZE(XRHODJ,2)))
1777     ALLOCATE (ZTOWN(SIZE(XRHODJ,1),SIZE(XRHODJ,2)))
1778     ZSEA(:,:) = 0.
1779     ZTOWN(:,:)= 0.
1780     CALL MNHGET_SURF_PARAM_n (PSEA=ZSEA(:,:),PTOWN=ZTOWN(:,:))
1781     CALL RESOLVED_ELEC_n (CCLOUD, CSCONV, CMF_CLOUD,                     &
1782                           NRR, NSPLITR, IMI, KTCOUNT, OEXIT,             &
1783                           CLBCX, CLBCY, CRAD, CTURBDIM,                  &
1784                           LSUBG_COND, LSIGMAS,VSIGQSAT,CSUBG_AUCV,       &
1785                           XTSTEP, XZZ, XRHODJ, XRHODREF, XEXNREF,        &
1786                           XPABST, XTHT, XRTHS, XWT,  XRT, XRRS,          &
1787                           XSVT, XRSVS, XCIT,                             &
1788                           XSIGS, XSRCT, XCLDFR, XMFCONV, XCF_MF, XRC_MF, &
1789                           XRI_MF, LSEDIC, LWARM,                         &
1790                           XINPRC, XINPRR, XINPRR3D, XEVAP3D,             &
1791                           XINPRS, XINPRG, XINPRH,                        &
1792                           ZSEA, ZTOWN                                    )
1793     DEALLOCATE(ZTOWN)
1794   ELSE
1795     CALL RESOLVED_ELEC_n (CCLOUD, CSCONV, CMF_CLOUD,                     &
1796                           NRR, NSPLITR, IMI, KTCOUNT, OEXIT,             &
1797                           CLBCX, CLBCY, CRAD, CTURBDIM,                  &
1798                           LSUBG_COND, LSIGMAS,VSIGQSAT, CSUBG_AUCV,      &
1799                           XTSTEP, XZZ, XRHODJ, XRHODREF, XEXNREF,        &
1800                           XPABST, XTHT, XRTHS, XWT,                      &
1801                           XRT, XRRS, XSVT, XRSVS, XCIT,                  &
1802                           XSIGS, XSRCT, XCLDFR, XMFCONV, XCF_MF, XRC_MF, &
1803                           XRI_MF, LSEDIC, LWARM,                         &
1804                           XINPRC, XINPRR, XINPRR3D, XEVAP3D,             &
1805                           XINPRS, XINPRG, XINPRH                         )
1806   END IF
1807   XRTHS_CLD = XRTHS - XRTHS_CLD
1808   XRRS_CLD  = XRRS  - XRRS_CLD
1809   XRSVS_CLD = XRSVS - XRSVS_CLD
1810 !
1811   XACPRR = XACPRR + XINPRR * XTSTEP
1812   IF ((CCLOUD(1:3) == 'ICE' .AND. LSEDIC)) & 
1813        XACPRC = XACPRC + XINPRC * XTSTEP
1814   IF (CCLOUD(1:3) == 'ICE') THEN
1815     XACPRS = XACPRS + XINPRS * XTSTEP
1816     XACPRG = XACPRG + XINPRG * XTSTEP
1817     IF (CCLOUD == 'ICE4') XACPRH = XACPRH + XINPRH * XTSTEP          
1818   END IF
1819 END IF
1820 !
1821 CALL SECOND_MNH2(ZTIME2)
1822 !
1823 XT_ELEC = XT_ELEC + ZTIME2 - ZTIME1 &
1824            - XTIME_LES_BU_PROCESS - XTIME_BU_PROCESS
1825 !
1826 !-------------------------------------------------------------------------------
1827 !
1828 !*       21.    L.E.S. COMPUTATIONS
1829 !               -------------------
1830 !
1831 ZTIME1 = ZTIME2
1832 !
1833 CALL LES_n
1834 !
1835 CALL SECOND_MNH2(ZTIME2)
1836 !
1837 XT_SPECTRA = XT_SPECTRA + ZTIME2 - ZTIME1 + XTIME_LES_BU + XTIME_LES
1838 !
1839 !-------------------------------------------------------------------------------
1840 !
1841 !*       21. bis    MEAN_UM
1842 !               --------------------
1843 !
1844 IF (LMEAN_FIELD) THEN
1845    CALL MEAN_FIELD(XUT, XVT, XWT, XTHT, XTKET, XPABST)
1846 END IF
1847 !
1848 !-------------------------------------------------------------------------------
1849 !
1850 !*       22.    UPDATE HALO OF EACH SUBDOMAINS FOR TIME T+DT
1851 !               --------------------------------------------
1852 !
1853 ZTIME1 = ZTIME2
1854 !
1855 CALL EXCHANGE (XTSTEP,NRR,NSV,XRHODJ,TZFIELDS_ll,     &
1856                XRUS, XRVS,XRWS,XRTHS,XRRS,XRTKES,XRSVS)
1857 !
1858 CALL SECOND_MNH2(ZTIME2)
1859 !
1860 XT_HALO = XT_HALO + ZTIME2 - ZTIME1
1861 !
1862 !-------------------------------------------------------------------------------
1863 !
1864 !*       23.    TEMPORAL SWAPPING
1865 !               -----------------
1866 !
1867 ZTIME1 = ZTIME2
1868 XTIME_BU_PROCESS = 0.
1869 !
1870 CALL ENDSTEP  ( XTSTEP,NRR,NSV,KTCOUNT,IMI,               &
1871                 CUVW_ADV_SCHEME,XRHODJ,                   &
1872                 XRUS,XRVS,XRWS,XDRYMASSS,                 &
1873                 XRTHS,XRRS,XRTKES,XRSVS,                  &
1874                 XLSUS,XLSVS,XLSWS,                        &
1875                 XLSTHS,XLSRVS,                            &
1876                 XLBXUS,XLBXVS,XLBXWS,                     &
1877                 XLBXTHS,XLBXRS,XLBXTKES,XLBXSVS,          &
1878                 XLBYUS,XLBYVS,XLBYWS,                     &
1879                 XLBYTHS,XLBYRS,XLBYTKES,XLBYSVS,          &
1880                 XUM,XVM,XWM,                              &
1881                 XUT,XVT,XWT,XPABST,XDRYMASST,             &
1882                 XTHT, XRT, XTHM, XRCM, XPABSM,XTKET, XSVT,&
1883                 XLSUM,XLSVM,XLSWM,                        &
1884                 XLSTHM,XLSRVM,                            &
1885                 XLBXUM,XLBXVM,XLBXWM,                     &
1886                 XLBXTHM,XLBXRM,XLBXTKEM,XLBXSVM,          &
1887                 XLBYUM,XLBYVM,XLBYWM,                     &
1888                 XLBYTHM,XLBYRM,XLBYTKEM,XLBYSVM           )
1889 !
1890 CALL SECOND_MNH2(ZTIME2)
1891 !
1892 XT_STEP_SWA = XT_STEP_SWA + ZTIME2 - ZTIME1 - XTIME_BU_PROCESS
1893 !
1894 !-------------------------------------------------------------------------------
1895 !
1896 !*       24.1    BALLOON and AIRCRAFT
1897 !               --------------------
1898 !
1899 ZTIME1 = ZTIME2
1900 !
1901 IF (LFLYER)                                                                   &
1902   CALL AIRCRAFT_BALLOON(CLUOUT, XTSTEP,                                       &
1903                       TDTEXP, TDTMOD, TDTSEG, TDTCUR,                         &
1904                       XXHAT, XYHAT, XZZ, XMAP, XLONORI, XLATORI,              &
1905                       XUT, XVT, XWT, XPABST, XTHT, XRT, XSVT, XTKET, XTSRAD,  &
1906                       XRHODREF,XCIT,ZSPEEDC, ZSPEEDR, ZSPEEDS, ZSPEEDG,       &
1907                       ZSPEEDH,PSEA=ZSEA(:,:))
1908
1909
1910 !-------------------------------------------------------------------------------
1911 !
1912 !*       24.2    STATION (observation diagnostic)
1913 !               --------------------------------
1914 !
1915 IF (LSTATION)                                                            &
1916   CALL STATION_n(CLUOUT, XTSTEP,                                         &
1917                  TDTEXP, TDTMOD, TDTSEG, TDTCUR,                         &
1918                  XXHAT, XYHAT, XZZ,                                      &
1919                  XUT, XVT, XWT, XTHT, XRT, XSVT, XTKET, XTSRAD, XPABST   )
1920 !
1921 !---------------------------------------------------------
1922 !
1923 !*       24.3    PROFILER (observation diagnostic)
1924 !               ---------------------------------
1925 !
1926 IF (LPROFILER)                                                           &
1927   CALL PROFILER_n(CLUOUT, XTSTEP,                                        &
1928                   TDTEXP, TDTMOD, TDTSEG, TDTCUR,                        &
1929                   XXHAT, XYHAT, XZZ,XRHODREF,                            &
1930                   XUT, XVT, XWT, XTHT, XRT, XSVT, XTKET, XTSRAD, XPABST, &
1931                   XAER, XCLDFR, XCIT ,                                   &
1932                   ZSPEEDC, ZSPEEDR, ZSPEEDS, ZSPEEDG, ZSPEEDH,           &
1933                   ZINPRC3D,XINPRR3D,ZINPRS3D,ZINPRG3D,ZINPRH3D           )
1934 !
1935 !
1936 CALL SECOND_MNH2(ZTIME2)
1937 !
1938 XT_STEP_MISC = XT_STEP_MISC + ZTIME2 - ZTIME1
1939 !
1940 !-------------------------------------------------------------------------------
1941 !
1942 !*       24.4   deallocation of observation diagnostics
1943 !               ---------------------------------------
1944 !
1945 CALL END_DIAG_IN_RUN
1946 !
1947 !-------------------------------------------------------------------------------
1948 !
1949 !
1950 !*       25.    STORAGE OF BUDGET FIELDS
1951 !               ------------------------
1952 !
1953 ZTIME1 = ZTIME2
1954 !
1955 IF (NBUMOD==IMI .AND. CBUTYPE/='NONE') THEN
1956   CALL ENDSTEP_BUDGET(CFMDIAC,CLUOUT,KTCOUNT,TDTCUR,TDTMOD,XTSTEP,NSV)
1957 END IF
1958 !
1959 CALL SECOND_MNH2(ZTIME2)
1960 !
1961 XT_STEP_BUD = XT_STEP_BUD + ZTIME2 - ZTIME1 + XTIME_BU
1962 !
1963 !-------------------------------------------------------------------------------
1964 !
1965 !*       26.    FM FILE CLOSURE
1966 !               ---------------
1967 !
1968 IF (GCLOSE_OUT) THEN
1969   GCLOSE_OUT=.FALSE.
1970   CALL FMCLOS_ll(YFMFILE,'KEEP',CLUOUT,IRESP)
1971 END IF
1972 !
1973 !-------------------------------------------------------------------------------
1974 !
1975 !*       27.    CURRENT TIME REFRESH
1976 !               --------------------
1977 !
1978 TDTCUR%TIME=TDTCUR%TIME + XTSTEP
1979 CALL ADD_FORECAST_TO_DATE(TDTCUR%TDATE%YEAR, &
1980                           TDTCUR%TDATE%MONTH,&
1981                           TDTCUR%TDATE%DAY,  &
1982                           TDTCUR%TIME        )
1983 !
1984 !-------------------------------------------------------------------------------
1985 !
1986 !*       28.    CPU ANALYSIS
1987 !               ------------
1988 !
1989 CALL SECOND_MNH2(ZTIME2)
1990 XT_START=XT_START+ZTIME2-ZEND
1991 !
1992 !
1993 IF ( KTCOUNT == NSTOP .AND. IMI==1) THEN
1994   OEXIT=.TRUE.
1995 END IF
1996 !
1997 IF (OEXIT) THEN
1998 !
1999 #ifdef MNH_NCWRIT
2000   NC_WRITE = LNETCDF
2001   NC_FILE = 'ser'
2002   IF (LSERIES) CALL WRITE_SERIES_n(CFMDIAC,CLUOUT )
2003   CALL WRITE_AIRCRAFT_BALLOON(CFMDIAC)
2004   CALL WRITE_STATION_n(CFMDIAC)
2005   CALL WRITE_PROFILER_n(CFMDIAC)
2006   CALL WRITE_LES_n(' ')
2007   CALL WRITE_LES_n('A')
2008   CALL WRITE_LES_n('E')
2009   CALL WRITE_LES_n('H')
2010   IF ( LNETCDF ) THEN
2011     DEF_NC=.FALSE.
2012     IF (LSERIES) CALL WRITE_SERIES_n(CFMDIAC,CLUOUT )
2013     CALL WRITE_AIRCRAFT_BALLOON(CFMDIAC)
2014     CALL WRITE_STATION_n(CFMDIAC)
2015     CALL WRITE_PROFILER_n(CFMDIAC)
2016     CALL WRITE_LES_n(' ')
2017     CALL WRITE_LES_n('A')
2018     CALL WRITE_LES_n('E')
2019     CALL WRITE_LES_n('H')
2020     DEF_NC=.TRUE.
2021   END IF
2022   NC_WRITE = .FALSE.
2023 #else
2024   IF (LSERIES) CALL WRITE_SERIES_n(CFMDIAC,CLUOUT )
2025   CALL WRITE_AIRCRAFT_BALLOON(CFMDIAC)
2026   CALL WRITE_STATION_n(CFMDIAC)
2027   CALL WRITE_PROFILER_n(CFMDIAC)
2028   CALL WRITE_LES_n(' ')
2029   CALL WRITE_LES_n('A')
2030   CALL WRITE_LES_n('E')
2031   CALL WRITE_LES_n('H')
2032 #endif  
2033   CALL MENU_DIACHRO(CFMDIAC,CLUOUT,'END')
2034   CALL FMCLOS_ll(CFMDIAC,'KEEP',CLUOUT,IRESP)
2035   !
2036   CALL FMCLOS_ll(CINIFILE,'KEEP',CLUOUT,IRESP)
2037   IF (CSURF=="EXTE") CALL FMCLOS_ll(CINIFILEPGD,'KEEP',CLUOUT,IRESP,OPARALLELIO=.FALSE.)
2038 !
2039 !*       28.1   print statistics!
2040 !
2041   ! Set File Timing OUTPUT
2042   !
2043   CALL SET_ILUOUT_TIMING(ILUOUT)
2044   !
2045   ! Compute global time
2046   !
2047   CALL TIME_STAT_ll(XT_START,ZTOT)
2048   !
2049   CALL TIME_HEADER_ll(IMI)
2050   !
2051   CALL TIME_STAT_ll(XT_1WAY,ZTOT,       ' ONE WAY','=')
2052   CALL TIME_STAT_ll(XT_BOUND,ZTOT,      ' BOUNDARIES','=')
2053   CALL TIME_STAT_ll(XT_STORE,ZTOT,      ' STORE-FIELDS','=')
2054     CALL TIME_STAT_ll(TIMEZ%T_WRIT3D_SEND,ZTOT,    '   W3D_SEND ','-')
2055     CALL TIME_STAT_ll(TIMEZ%T_WRIT3D_RECV,ZTOT,    '   W3D_RECV ','-')
2056     CALL TIME_STAT_ll(TIMEZ%T_WRIT3D_WRIT,ZTOT,    '   W3D_WRIT ','-')
2057     CALL TIME_STAT_ll(TIMEZ%T_WRIT3D_WAIT,ZTOT,    '   W3D_WAIT ','-')
2058     CALL TIME_STAT_ll(TIMEZ%T_WRIT3D_ALL ,ZTOT,    '   W3D_ALL ','-')
2059     CALL TIME_STAT_ll(TIMEZ%T_WRIT2D_GATH,ZTOT,    '   W2D_GATH ','-')
2060     CALL TIME_STAT_ll(TIMEZ%T_WRIT2D_WRIT,ZTOT,    '   W2D_WRIT ','-')
2061     CALL TIME_STAT_ll(TIMEZ%T_WRIT2D_ALL ,ZTOT,    '   W2D_ALL ','-')
2062   CALL TIME_STAT_ll(XT_GUESS,ZTOT,      ' INITIAL_GUESS','=')
2063   CALL TIME_STAT_ll(XT_2WAY,ZTOT,       ' TWO WAY','=')
2064   CALL TIME_STAT_ll(XT_ADV,ZTOT,        ' ADVECTION MET','=')
2065   CALL TIME_STAT_ll(XT_ADVUVW,ZTOT,     ' ADVECTION UVW','=')
2066   CALL TIME_STAT_ll(XT_GRAV,ZTOT,       ' GRAVITY','=')
2067   CALL TIME_STAT_ll(XT_FORCING,ZTOT,    ' FORCING','=')
2068   CALL TIME_STAT_ll(XT_NUDGING,ZTOT,    ' NUDGING','=')
2069   CALL TIME_STAT_ll(XT_SOURCES,ZTOT,    ' DYN_SOURCES','=')
2070   CALL TIME_STAT_ll(XT_DIFF,ZTOT,       ' NUM_DIFF','=')
2071   CALL TIME_STAT_ll(XT_RELAX,ZTOT,      ' RELAXATION','=')
2072   !
2073   CALL  TIMING_LEGEND() 
2074   !
2075   CALL TIME_STAT_ll(XT_PARAM,ZTOT,      ' PHYS_PARAM','=')
2076     CALL TIME_STAT_ll(XT_RAD,ZTOT,      '   RAD       = '//CRAD  ,'-')
2077     CALL TIME_STAT_ll(XT_SHADOWS,ZTOT,  '   SHADOWS'             ,'-')
2078     CALL TIME_STAT_ll(XT_DCONV,ZTOT,    '   DEEP CONV = '//CDCONV,'-')
2079     CALL TIME_STAT_ll(XT_GROUND,ZTOT,   '   GROUND'              ,'-')
2080     CALL TIME_STAT_ll(XT_TURB,ZTOT,     '   TURB      = '//CTURB ,'-')
2081     CALL TIME_STAT_ll(XT_MAFL,ZTOT,     '   MAFL      = '//CSCONV,'-')
2082     CALL TIME_STAT_ll(XT_CHEM,ZTOT,     '   CHIMIE'              ,'-')
2083   CALL  TIMING_LEGEND()
2084   CALL TIME_STAT_ll(XT_COUPL,ZTOT,      ' SET_COUPLING','=')
2085   CALL TIME_STAT_ll(XT_RAD_BOUND,ZTOT,  ' RAD_BOUND','=')
2086   !
2087   CALL  TIMING_LEGEND()
2088   ! 
2089   CALL TIME_STAT_ll(XT_PRESS,ZTOT,      ' PRESSURE ','=','F')
2090   !JUAN Z_SPLITTING
2091     CALL TIME_STAT_ll(TIMEZ%T_MAP_B_SX_YP2_ZP1,ZTOT,          '   REMAP       B=>FFTXZ'  ,'-','F')
2092     CALL TIME_STAT_ll(TIMEZ%T_MAP_SX_YP2_ZP1_SXP2_Y_ZP1,ZTOT, '   REMAP   FFTXZ=>FFTYZ'  ,'-','F')
2093     CALL TIME_STAT_ll(TIMEZ%T_MAP_SXP2_Y_ZP1_B,ZTOT,          '   REMAP   FTTYZ=>B'      ,'-','F')
2094     CALL TIME_STAT_ll(TIMEZ%T_MAP_SXP2_Y_ZP1_SXP2_YP1_Z,ZTOT, '   REMAP   FFTYZ=>SUBZ'   ,'-','F')
2095     CALL TIME_STAT_ll(TIMEZ%T_MAP_B_SXP2_Y_ZP1,ZTOT,          '   REMAP       B=>FFTYZ-1','-','F')
2096     CALL TIME_STAT_ll(TIMEZ%T_MAP_SXP2_YP1_Z_SXP2_Y_ZP1,ZTOT, '   REMAP    SUBZ=>FFTYZ-1','-','F')
2097     CALL TIME_STAT_ll(TIMEZ%T_MAP_SXP2_Y_ZP1_SX_YP2_ZP1,ZTOT, '   REMAP FFTYZ-1=>FFTXZ-1','-','F')
2098     CALL TIME_STAT_ll(TIMEZ%T_MAP_SX_YP2_ZP1_B,ZTOT,          '   REMAP FFTXZ-1=>B     ' ,'-','F')
2099   ! JUAN P1/P2
2100   CALL TIME_STAT_ll(XT_CLOUD,ZTOT,      ' RESOLVED_CLOUD','=')
2101   CALL TIME_STAT_ll(XT_HALO,ZTOT,       ' EXCHANGE_HALO','=')
2102   CALL TIME_STAT_ll(XT_STEP_SWA,ZTOT,   ' ENDSTEP','=')
2103   CALL TIME_STAT_ll(XT_STEP_BUD,ZTOT,   ' BUDGETS','=')
2104   CALL TIME_STAT_ll(XT_SPECTRA,ZTOT,    ' LES','=')
2105   CALL TIME_STAT_ll(XT_STEP_MISC,ZTOT,  ' MISCELLANEOUS','=')
2106   !
2107   ! sum of call subroutine
2108   !
2109   ZALL   = XT_1WAY + XT_BOUND   + XT_STORE   + XT_GUESS    +  XT_2WAY   + &
2110            XT_ADV  + XT_FORCING + XT_NUDGING + XT_SOURCES  +  XT_DIFF   + &
2111            XT_ADVUVW  + XT_GRAV +                                         &
2112            XT_RELAX+ XT_PARAM   + XT_COUPL   + XT_RAD_BOUND+XT_PRESS    + &
2113            XT_CLOUD+  XT_HALO   + XT_SPECTRA + XT_STEP_SWA +XT_STEP_MISC+ &
2114            XT_STEP_BUD
2115   CALL TIME_STAT_ll(ZALL,ZTOT,          ' SUM(CALL)','=')
2116   CALL  TIMING_SEPARATOR('=')
2117   !
2118   ! Gobale Stat
2119   !
2120   WRITE(ILUOUT,FMT=*)
2121   WRITE(ILUOUT,FMT=*)
2122   CALL  TIMING_LEGEND() 
2123   !
2124   ! MODELN all included
2125   !
2126   CALL  TIMING_SEPARATOR('+')
2127   CALL  TIMING_SEPARATOR('+')  
2128   WRITE(YMI,FMT="(I0)") IMI
2129   CALL TIME_STAT_ll(XT_START,ZTOT,      ' MODEL'//YMI,'+')
2130   CALL  TIMING_SEPARATOR('+')
2131   CALL  TIMING_SEPARATOR('+')
2132   CALL  TIMING_SEPARATOR('+')
2133   !
2134   ! Timing/ Steps
2135   !
2136   ZTIME_STEP     =  XT_START / FLOAT(KTCOUNT)
2137   WRITE(YTCOUNT,FMT="(I0)") KTCOUNT
2138   CALL TIME_STAT_ll(ZTIME_STEP,ZTOT,     ' SECOND/STEP='//YTCOUNT,'=')
2139   !
2140   ! Timing/Step/Points
2141   !
2142   IPOINTS = NIMAX_ll*NJMAX_ll*NKMAX
2143   WRITE(YPOINTS,FMT="(I0)") IPOINTS
2144   ZTIME_STEP_PTS =  ZTIME_STEP / FLOAT(IPOINTS) * 1e6
2145   CALL TIME_STAT_ll(ZTIME_STEP_PTS,ZTOT_PT)
2146   CALL TIME_STAT_ll(ZTIME_STEP_PTS,ZTOT_PT,  ' MICROSEC/STP/PT='//YPOINTS,'-')
2147   !
2148   CALL  TIMING_SEPARATOR('=')
2149   !
2150   !
2151   !
2152   CALL CLOSE_ll(CLUOUT,IOSTAT=IRESP)
2153   IF (IMI==NMODEL) CALL CLOSE_ll(CLUOUT0,IOSTAT=IRESP)
2154 END IF
2155 !
2156 END SUBROUTINE MODEL_n