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