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