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