source: trunk/LMDZ.PLUTO/libf/phypluto/physiq_mod.F90 @ 3197

Last change on this file since 3197 was 3197, checked in by afalco, 10 months ago

Pluto PCM:
Fixed some flags for aerosols
AF

  • Property svn:executable set to *
File size: 77.8 KB
Line 
1      module physiq_mod
2
3      implicit none
4
5      contains
6
7      subroutine physiq(ngrid,nlayer,nq,   &
8                  firstcall,lastcall,      &
9                  pday,ptime,ptimestep,    &
10                  pplev,pplay,pphi,        &
11                  pu,pv,pt,pq,             &
12                  flxw,                    &
13                  pdu,pdv,pdt,pdq,pdpsrf)
14
15!!
16      use write_field_phy, only: Writefield_phy
17!!
18      use ioipsl_getin_p_mod, only: getin_p
19      use radinc_h, only : L_NSPECTI,L_NSPECTV,naerkind, corrkdir, banddir
20      use generic_cloud_common_h, only : epsi_generic, Psat_generic
21      use gases_h, only: gnom, gfrac
22      use radcommon_h, only: sigma, glat, grav, BWNV, WNOI, DWNI, DWNV, WNOV
23      use suaer_corrk_mod, only: suaer_corrk
24      use radii_mod, only: su_aer_radii,haze_reffrad_fix
25      use aerosol_mod, only: iaero_haze, i_haze, haze_prof
26      use surfdat_h, only: phisfi, zmea, zstd, zsig, zgam, zthe, &
27                           dryness
28      use comdiurn_h, only: coslat, sinlat, coslon, sinlon
29      use comsaison_h, only: mu0, fract, dist_star, declin, right_ascen
30      use comsoil_h, only: nsoilmx, layer, mlayer, inertiedat
31      use geometry_mod, only: latitude, longitude, cell_area
32      USE comgeomfi_h, only: totarea, totarea_planet
33      USE tracer_h, only: noms, mmol, radius, rho_q, qext, &
34                          igcm_n2,&
35                          alpha_lift, alpha_devil, qextrhor, &
36                          nesp, is_chim, is_condensable,constants_epsi_generic
37      use time_phylmdz_mod, only: ecritphy, iphysiq, nday
38      use phyetat0_mod, only: phyetat0
39      use wstats_mod, only: callstats, wstats, mkstats
40      use phyredem, only: physdem0, physdem1
41      use planetwide_mod, only: planetwide_minval,planetwide_maxval,planetwide_sumval
42      use mod_phys_lmdz_para, only : is_master
43      use planete_mod, only: apoastr, periastr, year_day, peri_day, &
44                            obliquit, nres, z0
45      use comcstfi_mod, only: pi, g, rcp, r, rad, mugaz, cpp
46      use time_phylmdz_mod, only: daysec
47      use callkeys_mod, only: albedo_spectral_mode, calladj, calldifv, &
48                              callrad, callsoil, nosurf, &
49                              aerohaze, corrk, diagdtau,&
50                              diurnal, enertest, fat1au, &
51                              icetstep, intheat, iradia, kastprof, &
52                              lwrite, mass_redistrib, meanOLR, &
53                              n2cond,nearn2cond, noseason_day, &
54                              season, sedimentation,generic_condensation, &
55                              aerohaze, haze_proffix, &
56                              specOLR, &
57                              startphy_file, testradtimes, &
58                              tracer, UseTurbDiff, &
59                              global1d, szangle
60      use generic_tracer_index_mod, only: generic_tracer_index
61      use check_fields_mod, only: check_physics_fields
62      use conc_mod, only: rnew, cpnew, ini_conc_mod
63      use phys_state_var_mod
64      use callcorrk_mod, only: callcorrk
65      use vdifc_mod, only: vdifc
66      use turbdiff_mod, only: turbdiff
67      use turb_mod, only : q2,sensibFlux,turb_resolved
68      use mass_redistribution_mod, only: mass_redistribution
69      use condensation_generic_mod, only: condensation_generic
70      use datafile_mod, only: datadir
71#ifndef MESOSCALE
72      use vertical_layers_mod, only: presnivs, pseudoalt
73      use mod_phys_lmdz_omp_data, ONLY: is_omp_master
74#else
75      use comm_wrf, only : comm_HR_SW, comm_HR_LW,  &
76         comm_CLOUDFRAC,comm_TOTCLOUDFRAC, comm_RH, &
77         comm_HR_DYN,     &
78         comm_DQICE,comm_DQVAP,comm_ALBEQ,          &
79         comm_FLUXTOP_DN,comm_FLUXABS_SW,           &
80         comm_FLUXTOP_LW,comm_FLUXSURF_SW,          &
81         comm_FLUXSURF_LW,comm_FLXGRD,              &
82         comm_DTRAIN,comm_DTLSC,                    &
83         comm_LATENT_HF
84
85#endif
86
87#ifdef CPP_XIOS
88      use xios_output_mod, only: initialize_xios_output, &
89                                 update_xios_timestep, &
90                                 send_xios_field
91      use wxios, only: wxios_context_init, xios_context_finalize
92#endif
93
94      implicit none
95
96
97!==================================================================
98!
99!     Purpose
100!     -------
101!     Central subroutine for all the physics parameterisations in the
102!     universal model. Originally adapted from the Mars LMDZ model.
103!
104!     The model can be run without or with tracer transport
105!     depending on the value of "tracer" in file "callphys.def".
106!
107!
108!   It includes:
109!
110!      I. Initialization :
111!         I.1 Firstcall initializations.
112!         I.2 Initialization for every call to physiq.
113!
114!      II. Compute radiative transfer tendencies (longwave and shortwave) :
115!         II.a Option 1 : Call correlated-k radiative transfer scheme.
116!         II.b Option 2 : Call Newtonian cooling scheme.
117!         II.c Option 3 : Atmosphere has no radiative effect.
118!
119!      III. Vertical diffusion (turbulent mixing) :
120!
121!      IV. Convection :
122!         IV.a Thermal plume model
123!         IV.b Dry convective adjusment
124!
125!      V. Condensation and sublimation of gases (currently just N2).
126!
127!      VI. Tracers
128!         VI.1. Water and water ice.
129!         VI.2  Photochemistry
130!         VI.3. Aerosols and particles.
131!         VI.4. Updates (pressure variations, surface budget).
132!         VI.5. Slab Ocean.
133!         VI.6. Surface Tracer Update.
134!
135!      VII. Surface and sub-surface soil temperature.
136!
137!      VIII. Perform diagnostics and write output files.
138!
139!
140!   arguments
141!   ---------
142!
143!   INPUT
144!   -----
145!
146!    ngrid                 Size of the horizontal grid.
147!    nlayer                Number of vertical layers.
148!    nq                    Number of advected fields.
149!
150!    firstcall             True at the first call.
151!    lastcall              True at the last call.
152!
153!    pday                  Number of days counted from the North. Spring equinoxe.
154!    ptime                 Universal time (0<ptime<1): ptime=0.5 at 12:00 UT.
155!    ptimestep             timestep (s).
156!
157!    pplay(ngrid,nlayer)   Pressure at the middle of the layers (Pa).
158!    pplev(ngrid,nlayer+1) Intermediate pressure levels (Pa).
159!    pphi(ngrid,nlayer)    Geopotential at the middle of the layers (m2.s-2).
160!
161!    pu(ngrid,nlayer)      u, zonal component of the wind (ms-1).
162!    pv(ngrid,nlayer)      v, meridional component of the wind (ms-1).
163!
164!    pt(ngrid,nlayer)      Temperature (K).
165!
166!    pq(ngrid,nlayer,nq)   Advected fields.
167!
168!    pudyn(ngrid,nlayer)    \
169!    pvdyn(ngrid,nlayer)     \ Dynamical temporal derivative for the
170!    ptdyn(ngrid,nlayer)     / corresponding variables.
171!    pqdyn(ngrid,nlayer,nq) /
172!    flxw(ngrid,nlayer)      vertical mass flux (kg/s) at layer lower boundary
173!
174!   OUTPUT
175!   ------
176!
177!    pdu(ngrid,nlayer)        \
178!    pdv(ngrid,nlayer)         \  Temporal derivative of the corresponding
179!    pdt(ngrid,nlayer)         /  variables due to physical processes.
180!    pdq(ngrid,nlayer)        /
181!    pdpsrf(ngrid)             /
182!
183!
184!     Authors
185!     -------
186!           Frederic Hourdin        15/10/93
187!           Francois Forget        1994
188!           Christophe Hourdin        02/1997
189!           Subroutine completely rewritten by F. Forget (01/2000)
190!           Water ice clouds: Franck Montmessin (update 06/2003)
191!           Radiatively active tracers: J.-B. Madeleine (10/2008-06/2009)
192!           New correlated-k radiative scheme: R. Wordsworth (2009)
193!           Many specifically Martian subroutines removed: R. Wordsworth (2009)
194!           Improved water cycle: R. Wordsworth / B. Charnay (2010)
195!           To F90: R. Wordsworth (2010)
196!           New turbulent diffusion scheme: J. Leconte (2012)
197!           Loops converted to F90 matrix format: J. Leconte (2012)
198!           No more ngrid/nq, F90 commons and adaptation to parallel: A. Spiga (2012)
199!           Purge of the code : M. Turbet (2015)
200!           Photochemical core developped by F. Lefevre: B. Charnay (2017)
201!           Purge for Pluto model : A. Falco (2024)
202!==================================================================
203
204
205!    0.  Declarations :
206!    ------------------
207
208include "netcdf.inc"
209
210! Arguments :
211! -----------
212
213!   INPUTS:
214!   -------
215
216      integer,intent(in) :: ngrid             ! Number of atmospheric columns.
217      integer,intent(in) :: nlayer            ! Number of atmospheric layers.
218      integer,intent(in) :: nq                ! Number of tracers.
219
220      logical,intent(in) :: firstcall ! Signals first call to physics.
221      logical,intent(in) :: lastcall  ! Signals last call to physics.
222
223      real,intent(in) :: pday                  ! Number of elapsed sols since reference Ls=0.
224      real,intent(in) :: ptime                 ! "Universal time", given as fraction of sol (e.g.: 0.5 for noon).
225      real,intent(in) :: ptimestep             ! Physics timestep (s).
226      real,intent(in) :: pplev(ngrid,nlayer+1) ! Inter-layer pressure (Pa).
227      real,intent(in) :: pplay(ngrid,nlayer)   ! Mid-layer pressure (Pa).
228      real,intent(in) :: pphi(ngrid,nlayer)    ! Geopotential at mid-layer (m2s-2).
229      real,intent(in) :: pu(ngrid,nlayer)      ! Zonal wind component (m/s).
230      real,intent(in) :: pv(ngrid,nlayer)      ! Meridional wind component (m/s).
231      real,intent(in) :: pt(ngrid,nlayer)      ! Temperature (K).
232      real,intent(in) :: pq(ngrid,nlayer,nq)   ! Tracers (kg/kg_of_air).
233      real,intent(in) :: flxw(ngrid,nlayer)    ! Vertical mass flux (ks/s) at lower boundary of layer
234
235!   OUTPUTS:
236!   --------
237
238!     Physical tendencies :
239
240      real,intent(out) :: pdu(ngrid,nlayer)    ! Zonal wind tendencies (m/s/s).
241      real,intent(out) :: pdv(ngrid,nlayer)    ! Meridional wind tendencies (m/s/s).
242      real,intent(out) :: pdt(ngrid,nlayer)    ! Temperature tendencies (K/s).
243      real,intent(out) :: pdq(ngrid,nlayer,nq) ! Tracer tendencies (kg/kg_of_air/s).
244      real,intent(out) :: pdpsrf(ngrid)        ! Surface pressure tendency (Pa/s).
245
246! Local saved variables:
247! ----------------------
248      integer,save :: day_ini                                      ! Initial date of the run (sol since Ls=0).
249      integer,save :: icount                                       ! Counter of calls to physiq during the run.
250!$OMP THREADPRIVATE(day_ini,icount)
251
252! Local variables :
253! -----------------
254
255!     Aerosol (dust or ice) extinction optical depth  at reference wavelength
256!     for the "naerkind" optically active aerosols:
257
258      real,save,allocatable :: aerosol(:,:,:) ! Aerosols
259!$OMP THREADPRIVATE(aerosol)
260      real zh(ngrid,nlayer)               ! Potential temperature (K).
261      real pw(ngrid,nlayer)               ! Vertical velocity (m/s). (NOTE : >0 WHEN DOWNWARDS !!)
262      real omega(ngrid,nlayer)            ! omega velocity (Pa/s, >0 when downward)
263
264      integer l,ig,ierr,iq,nw,isoil,iesp, igcm_generic_vap, igcm_generic_ice
265      logical call_ice_vap_generic ! to call only one time the ice/vap pair of a tracer
266
267      real zls                       ! Solar longitude (radians).
268      real zlss                      ! Sub solar point longitude (radians).
269      real zday                      ! Date (time since Ls=0, calculated in sols).
270      real zzlay(ngrid,nlayer)       ! Altitude at the middle of the atmospheric layers.
271      real zzlev(ngrid,nlayer+1)     ! Altitude at the atmospheric layer boundaries.
272
273! VARIABLES for the thermal plume model (AF24: deleted)
274
275! TENDENCIES due to various processes :
276
277      ! For Surface Temperature : (K/s)
278      real zdtsurf(ngrid)     ! Cumulated tendencies.
279      real zdtsurfmr(ngrid)   ! Mass_redistribution routine.
280      real zdtsurfc(ngrid)    ! Condense_n2 routine.
281      real zdtsdif(ngrid)     ! Turbdiff/vdifc routines.
282      ! real zdtsurf_hyd(ngrid) ! Hydrol routine.
283
284      ! For Atmospheric Temperatures : (K/s)
285      real dtlscale(ngrid,nlayer)                             ! Largescale routine.
286      real dt_generic_condensation(ngrid,nlayer)              ! condensation_generic routine.
287      real zdtc(ngrid,nlayer)                                 ! Condense_n2 routine.
288      real zdtdif(ngrid,nlayer)                               ! Turbdiff/vdifc routines.
289      real zdtmr(ngrid,nlayer)                                ! Mass_redistribution routine.
290      real zdtsw1(ngrid,nlayer), zdtlw1(ngrid,nlayer)         ! Callcorrk routine.
291      real zdtchim(ngrid,nlayer)                              ! Calchim routine.
292
293      ! For Surface Tracers : (kg/m2/s)
294      real dqsurf(ngrid,nq)                 ! Cumulated tendencies.
295      real zdqsurfc(ngrid)                  ! Condense_n2 routine.
296      REAL zdqsc(ngrid,nq)                  ! Condense_n2 routine.
297      real zdqsdif(ngrid,nq)                ! Turbdiff/vdifc routines.
298      real zdqssed(ngrid,nq)                ! Callsedim routine.
299      real zdqsurfmr(ngrid,nq)              ! Mass_redistribution routine.
300
301      ! For Tracers : (kg/kg_of_air/s)
302      real zdqc(ngrid,nlayer,nq)      ! Condense_n2 routine.
303      real zdqadj(ngrid,nlayer,nq)    ! Convadj routine.
304      real zdqdif(ngrid,nlayer,nq)    ! Turbdiff/vdifc routines.
305      real zdqevap(ngrid,nlayer)      ! Turbdiff routine.
306      real zdqsed(ngrid,nlayer,nq)    ! Callsedim routine.
307      real zdqmr(ngrid,nlayer,nq)     ! Mass_redistribution routine.
308      real dqvaplscale_generic(ngrid,nlayer,nq) ! condensation_generic routine.
309      real dqcldlscale_generic(ngrid,nlayer,nq) ! condensation_generic routine.
310      REAL,allocatable,save :: zdqchim(:,:,:) ! Calchim_asis routine
311      REAL,allocatable,save :: zdqschim(:,:)  ! Calchim_asis routine
312!$OMP THREADPRIVATE(zdqchim,zdqschim)
313
314
315      !! PLUTO variables
316      REAL zdqch4cloud(ngrid,nlayer,nq)
317      REAL zdqsch4cloud(ngrid,nq)
318      REAL zdtch4cloud(ngrid,nlayer)
319      REAL zdqcocloud(ngrid,nlayer,nq)
320      REAL zdqscocloud(ngrid,nq)
321      REAL zdtcocloud(ngrid,nlayer)
322      REAL rice_ch4(ngrid,nlayer)    ! Methane ice geometric mean radius (m)
323      REAL rice_co(ngrid,nlayer)     ! CO ice geometric mean radius (m)
324
325      REAL zdqsch4fast(ngrid)    ! used only for fast model nogcm
326      REAL zdqch4fast(ngrid)    ! used only for fast model nogcm
327      REAL zdqscofast(ngrid)    ! used only for fast model nogcm
328      REAL zdqcofast(ngrid)    ! used only for fast model nogcm
329      REAL zdqflow(ngrid,nq)
330
331      REAL zdteuv(ngrid,nlayer)    ! (K/s)
332      REAL zdtconduc(ngrid,nlayer) ! (K/s)
333      REAL zdumolvis(ngrid,nlayer)
334      REAL zdvmolvis(ngrid,nlayer)
335      real zdqmoldiff(ngrid,nlayer,nq)
336
337      ! Haze relatated tendancies
338      REAL zdqhaze(ngrid,nlayer,nq)
339      REAL zdqprodhaze(ngrid,nq)
340      REAL zdqsprodhaze(ngrid)
341      REAL zdqhaze_col(ngrid)
342      REAL zdqphot_prec(ngrid,nlayer)
343      REAL zdqphot_ch4(ngrid,nlayer)
344      REAL zdqconv_prec(ngrid,nlayer)
345      REAL zdq_source(ngrid,nlayer,nq)
346      ! Fast Haze relatated tendancies
347      REAL fluxbot(ngrid)
348      REAL gradflux(ngrid)
349      REAL fluxlym_sol_bot(ngrid)      ! Solar flux Lyman alpha ph.m-2.s-1 reaching the surface
350      REAL fluxlym_ipm_bot(ngrid)      ! IPM (Interplanetary) flux Lyman alpha ph.m-2.s-1 reaching the surface
351      REAL flym_sol(ngrid)      ! Incident Solar flux Lyman alpha ph.m-2.s-1
352      REAL flym_ipm(ngrid)      ! Incident IPM (Interplanetary) flux Lyman alpha ph.m-2.s-1
353
354
355
356      REAL array_zero1(ngrid)
357      REAL array_zero2(ngrid,nlayer)
358
359      ! For Winds : (m/s/s)
360      real zdvadj(ngrid,nlayer), zduadj(ngrid,nlayer)       ! Convadj routine.
361      real zdumr(ngrid,nlayer), zdvmr(ngrid,nlayer)         ! Mass_redistribution routine.
362      real zdvdif(ngrid,nlayer), zdudif(ngrid,nlayer)       ! Turbdiff/vdifc routines.
363      real zdhdif(ngrid,nlayer)                             ! Turbdiff/vdifc routines.
364      real zdhadj(ngrid,nlayer)                             ! Convadj routine.
365      REAL zdvc(ngrid,nlayer),zduc(ngrid,nlayer)            ! condense_n2 routine.
366
367      ! For Pressure and Mass :
368      real zdmassmr(ngrid,nlayer) ! Atmospheric Mass tendency for mass_redistribution (kg_of_air/m2/s).
369      real zdmassmr_col(ngrid)    ! Atmospheric Column Mass tendency for mass_redistribution (kg_of_air/m2/s).
370      real zdpsrfmr(ngrid)        ! Pressure tendency for mass_redistribution routine (Pa/s).
371
372
373
374! Local variables for LOCAL CALCULATIONS:
375! ---------------------------------------
376      real zflubid(ngrid)
377      real zplanck(ngrid),zpopsk(ngrid,nlayer)
378      real ztim1,ztim2,ztim3, z1,z2
379      real ztime_fin
380      real zdh(ngrid,nlayer)
381      real gmplanet
382      real taux(ngrid),tauy(ngrid)
383
384
385! local variables for DIAGNOSTICS : (diagfi & stat)
386! -------------------------------------------------
387      real ps(ngrid)                                     ! Surface Pressure.
388      real zt(ngrid,nlayer)                              ! Atmospheric Temperature.
389      real zu(ngrid,nlayer),zv(ngrid,nlayer)             ! Zonal and Meridional Winds.
390      real zq(ngrid,nlayer,nq)                           ! Atmospheric Tracers.
391      real zdtadj(ngrid,nlayer)                          ! Convadj Diagnostic.
392      real zdtdyn(ngrid,nlayer)                          ! Dynamical Heating (K/s).
393      real zdudyn(ngrid,nlayer)                          ! Dynamical Zonal Wind tendency (m.s-2).
394
395      real reff(ngrid,nlayer)                       ! Effective dust radius (used if doubleq=T).
396      real vmr(ngrid,nlayer)                        ! volume mixing ratio
397      real time_phys
398
399      real ISR,ASR,OLR,GND,DYN,GSR,Ts1,Ts2,Ts3,TsS ! for Diagnostic.
400
401      real qcol(ngrid,nq) ! Tracer Column Mass (kg/m2).
402
403      !     Pluto adding variables
404      real vmr_ch4(ngrid)  ! vmr ch4
405      real vmr_co(ngrid)  ! vmr co
406      real rho(ngrid,nlayer) ! density
407      real zrho_ch4(ngrid,nlayer) ! density methane kg.m-3
408      real zrho_co(ngrid,nlayer) ! density CO kg.m-3
409      real zrho_haze(ngrid,nlayer) ! density haze kg.m-3
410      real zdqrho_photprec(ngrid,nlayer) !photolysis rate kg.m-3.s-1
411      real zq1temp_ch4(ngrid) !
412      real qsat_ch4(ngrid) !
413      real qsat_ch4_l1(ngrid) !
414!      CHARACTER(LEN=20) :: txt ! to temporarly store text for eddy tracers
415      real profmmr(ngrid,nlayer) ! fixed profile of haze if haze_proffix
416      real sensiblehf1(ngrid) ! sensible heat flux
417      real sensiblehf2(ngrid) ! sensible heat flux
418
419!     included by RW for H2O Manabe scheme
420      real rneb_man(ngrid,nlayer) ! H2O cloud fraction (moistadj).
421      real rneb_lsc(ngrid,nlayer) ! H2O cloud fraction (large scale).
422
423
424!     to test energy conservation (RW+JL)
425      real mass(ngrid,nlayer),massarea(ngrid,nlayer)
426      real dEtot, dEtots, AtmToSurf_TurbFlux
427      real,save :: dEtotSW, dEtotsSW, dEtotLW, dEtotsLW
428!$OMP THREADPRIVATE(dEtotSW, dEtotsSW, dEtotLW, dEtotsLW)
429
430!JL12 conservation test for mean flow kinetic energy has been disabled temporarily
431
432      real dtmoist_max,dtmoist_min
433      real dItot, dItot_tmp, dVtot, dVtot_tmp
434
435
436      real dWtot, dWtot_tmp, dWtots, dWtots_tmp
437
438      real psat_tmp ! AF24: to remove?
439
440      real qsat_generic(ngrid,nlayer,nq) ! generic condensable tracers (GCS) specific concentration at saturation (kg/kg_of_air).
441      real RH_generic(ngrid,nlayer,nq)   ! generic condensable tracers (GCS) Relative humidity.
442      real rneb_generic(ngrid,nlayer,nq) ! GCS cloud fraction (generic condensation).
443      real psat_tmp_generic
444      real, save :: metallicity ! metallicity of planet --- is not used here, but necessary to call function Psat_generic
445!$OMP THREADPRIVATE(metallicity)
446
447      real reffrad_generic_zeros_for_wrf(ngrid,nlayer) !  !!! this is temporary, it is only a list of zeros, it will be replaced when a generic aerosol will be implemented
448
449      ! For Clear Sky Case. (AF24: deleted)
450
451      real nconsMAX, vdifcncons(ngrid), cadjncons(ngrid) ! Vdfic water conservation test. By RW
452
453      real muvar(ngrid,nlayer+1) ! For Runaway Greenhouse 1D study. By RW
454
455      real,save,allocatable :: reffcol(:,:)
456!$OMP THREADPRIVATE(reffcol)
457
458!  Non-oro GW tendencies
459      REAL d_u_hin(ngrid,nlayer), d_v_hin(ngrid,nlayer)
460      REAL d_t_hin(ngrid,nlayer)
461!  Diagnostics 2D of gw_nonoro
462      REAL zustrhi(ngrid), zvstrhi(ngrid)
463
464
465      real :: tsurf2(ngrid)
466!!      real :: flux_o(ngrid),flux_g(ngrid)
467      real :: flux_g(ngrid)
468      real :: flux_sens_lat(ngrid)
469      real :: qsurfint(ngrid,nq)
470#ifdef MESOSCALE
471      REAL :: lsf_dt(nlayer)
472      REAL :: lsf_dq(nlayer)
473#endif
474
475      ! flags to trigger extra sanity checks
476      logical, save ::  check_physics_inputs=.false.
477      logical, save ::  check_physics_outputs=.false.
478!$OPM THREADPRIVATE(check_physics_inputs,check_physics_outputs)
479
480      ! Misc
481      character*2 :: str2
482      character(len=10) :: tmp1
483      character(len=10) :: tmp2
484!==================================================================================================
485
486! -----------------
487! I. INITIALISATION
488! -----------------
489
490! --------------------------------
491! I.1   First Call Initialisation.
492! --------------------------------
493      if (firstcall) then
494         call getin_p("check_physics_inputs", check_physics_inputs)
495         call getin_p("check_physics_outputs", check_physics_outputs)
496
497         ! Allocate saved arrays (except for 1D model, where this has already
498         ! been done)
499#ifndef MESOSCALE
500         if (ngrid>1) call phys_state_var_init(nq)
501#endif
502
503!        Variables set to 0
504!        ~~~~~~~~~~~~~~~~~~
505         dtrad(:,:) = 0.0
506         fluxrad(:) = 0.0
507         tau_col(:) = 0.0
508         zdtsw(:,:) = 0.0
509         zdtlw(:,:) = 0.0
510
511!        Initialize tracer names, indexes and properties.
512!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
513         IF (.NOT.ALLOCATED(noms)) ALLOCATE(noms(nq)) ! (because noms is an argument of physdem1 whether or not tracer is on)
514         if (tracer) then
515            call initracer(ngrid,nq)
516            ! if(photochem) then !AF24: removed
517         endif
518!        Initialize aerosol indexes.
519!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~
520         ! call iniaerosol
521         ! allocate related local arrays
522         ! (need be allocated instead of automatic because of "naerkind")
523         allocate(aerosol(ngrid,nlayer,naerkind))
524         allocate(reffcol(ngrid,naerkind))
525
526#ifdef CPP_XIOS
527         ! Initialize XIOS context
528         write(*,*) "physiq: call wxios_context_init"
529         CALL wxios_context_init
530#endif
531
532!        Read 'startfi.nc' file.
533!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
534#ifndef MESOSCALE
535         call phyetat0(startphy_file,                                 &
536                       ngrid,nlayer,"startfi.nc",0,0,nsoilmx,nq,      &
537                       day_ini,time_phys,tsurf,tsoil,emis,q2,qsurf)
538
539#else
540
541         day_ini = pday
542#endif
543
544#ifndef MESOSCALE
545         if (.not.startphy_file) then
546           ! additionnal "academic" initialization of physics
547           if (is_master) write(*,*) "Physiq: initializing tsurf(:) to pt(:,1) !!"
548           tsurf(:)=pt(:,1)
549           if (is_master) write(*,*) "Physiq: initializing tsoil(:) to pt(:,1) !!"
550           do isoil=1,nsoilmx
551             tsoil(1:ngrid,isoil)=tsurf(1:ngrid)
552           enddo
553           if (is_master) write(*,*) "Physiq: initializing day_ini to pdat !"
554           day_ini=pday
555         endif
556#endif
557         if (pday.ne.day_ini) then
558             write(*,*) "ERROR in physiq.F90:"
559             write(*,*) "bad synchronization between physics and dynamics"
560             write(*,*) "dynamics day: ",pday
561             write(*,*) "physics day:  ",day_ini
562             stop
563         endif
564
565         write (*,*) 'In physiq day_ini =', day_ini
566
567!        Initialize albedo calculation.
568!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
569         albedo(:,:)=0.0
570         albedo_bareground(:)=0.0
571         albedo_snow_SPECTV(:)=0.0
572         albedo_n2_ice_SPECTV(:)=0.0
573         call surfini(ngrid,nq,qsurf,albedo,albedo_bareground,albedo_snow_SPECTV,albedo_n2_ice_SPECTV)
574
575!        Initialize orbital calculation.
576!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
577         call iniorbit(apoastr,periastr,year_day,peri_day,obliquit)
578
579
580!        Initialize soil.
581!        ~~~~~~~~~~~~~~~~
582         if (callsoil) then
583            call soil(ngrid,nsoilmx,firstcall,lastcall,inertiedat, &
584                      ptimestep,tsurf,tsoil,capcal,fluxgrd)
585         else ! else of 'callsoil'.
586            print*,'WARNING! Thermal conduction in the soil turned off'
587            capcal(:)=1.e6
588            fluxgrd(:)=intheat
589            print*,'Flux from ground = ',intheat,' W m^-2'
590         endif ! end of 'callsoil'.
591
592         icount=1
593
594!        Initialize surface history variable.
595!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
596         qsurf_hist(:,:)=qsurf(:,:)
597
598!!         call WriteField_phy("post_qsurf_hist_qsurf",qsurf(1:ngrid,igcm_h2o_vap),1)
599
600!        Initialize variable for dynamical heating and zonal wind tendency diagnostic
601!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
602         ztprevious(:,:)=pt(:,:)
603         zuprevious(:,:)=pu(:,:)
604
605!        Set temperature just above condensation temperature (for Early Mars)
606!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
607         if(nearn2cond) then
608            write(*,*)' WARNING! Starting at Tcond+1K'
609            do l=1, nlayer
610               do ig=1,ngrid
611                  pdt(ig,l)= ((-3167.8)/(log(.01*pplay(ig,l))-23.23)+4     &
612                      -pt(ig,l)) / ptimestep
613               enddo
614            enddo
615         endif
616
617         if(meanOLR)then
618            call system('rm -f rad_bal.out') ! to record global radiative balance.
619            call system('rm -f tem_bal.out') ! to record global mean/max/min temperatures.
620            call system('rm -f h2o_bal.out') ! to record global hydrological balance.
621         endif
622
623
624         !! Initialize variables for water cycle ! AF24: removed
625
626!        Set metallicity for GCS
627!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
628         metallicity=0.0 ! default value --- is not used here but necessary to call function Psat_generic
629         call getin_p("metallicity",metallicity) ! --- is not used here but necessary to call function Psat_generic
630
631!        Set some parameters for the thermal plume model !AF24: removed
632!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
633
634#ifndef MESOSCALE
635         if (ngrid.ne.1) then ! Note : no need to create a restart file in 1d.
636            call physdem0("restartfi.nc",longitude,latitude,nsoilmx,ngrid,nlayer,nq, &
637                         ptimestep,pday+nday,time_phys,cell_area,          &
638                         albedo_bareground,inertiedat,zmea,zstd,zsig,zgam,zthe)
639         endif
640
641!!         call WriteField_phy("post_physdem_qsurf",qsurf(1:ngrid,igcm_h2o_vap),1)
642#endif
643         if (corrk) then
644            ! We initialise the spectral grid here instead of
645            ! at firstcall of callcorrk so we can output XspecIR, XspecVI
646            ! when using Dynamico
647            print*, "physiq_mod: Correlated-k data base folder:",trim(datadir)
648            call getin_p("corrkdir",corrkdir)
649            print*,"corrkdir = ", corrkdir
650            write (tmp1, '(i4)') L_NSPECTI
651            write (tmp2, '(i4)') L_NSPECTV
652            banddir=trim(trim(adjustl(tmp1))//'x'//trim(adjustl(tmp2)))
653            banddir=trim(trim(adjustl(corrkdir))//'/'//trim(adjustl(banddir)))
654            call setspi !Basic infrared properties.
655            call setspv ! Basic visible properties.
656            call sugas_corrk       ! Set up gaseous absorption properties.
657            if (aerohaze) then
658               call suaer_corrk       ! Set up aerosol optical properties.
659            endif
660         endif
661
662!!         call WriteField_phy("post_corrk_firstcall_qsurf",qsurf(1:ngrid,igcm_h2o_vap),1)
663         ! XIOS outputs
664#ifdef CPP_XIOS
665
666         write(*,*) "physiq: call initialize_xios_output"
667         call initialize_xios_output(pday,ptime,ptimestep,daysec, &
668                                     year_day,presnivs,pseudoalt,WNOI,WNOV)
669#endif
670
671!!         call WriteField_phy("post_xios_qsurf",qsurf(1:ngrid,igcm_h2o_vap),1)
672
673         write(*,*) "physiq: end of firstcall"
674      endif ! end of 'firstcall'
675
676!!      call WriteField_phy("post_firstcall_qsurf",qsurf(1:ngrid,igcm_h2o_vap),1)
677!!      call writediagfi(ngrid,"firstcall_post_qsurf"," "," ",2,qsurf(1:ngrid,igcm_h2o_vap))
678
679      if (check_physics_inputs) then
680         !check the validity of input fields coming from the dynamics
681         call check_physics_fields("begin physiq:", pt, pu, pv, pplev, pq)
682      endif
683
684!      call writediagfi(ngrid,"pre_physical_rnat"," "," ",2,rnat)
685!      call writediagfi(ngrid,"pre_physical_capcal"," "," ",2,capcal)
686
687! ------------------------------------------------------
688! I.2   Initializations done at every physical timestep:
689! ------------------------------------------------------
690
691#ifdef CPP_XIOS
692      ! update XIOS time/calendar
693      call update_xios_timestep
694#endif
695
696      ! Initialize various variables
697      ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
698
699      if ( .not.nearn2cond ) then
700         pdt(1:ngrid,1:nlayer) = 0.0
701      endif
702      zdtsurf(1:ngrid)      = 0.0
703      pdq(1:ngrid,1:nlayer,1:nq) = 0.0
704      dqsurf(1:ngrid,1:nq)= 0.0
705      pdu(1:ngrid,1:nlayer) = 0.0
706      pdv(1:ngrid,1:nlayer) = 0.0
707      pdpsrf(1:ngrid)       = 0.0
708      zflubid(1:ngrid)      = 0.0
709      flux_sens_lat(1:ngrid) = 0.0
710      taux(1:ngrid) = 0.0
711      tauy(1:ngrid) = 0.0
712
713      zday=pday+ptime ! Compute time, in sols (and fraction thereof).
714
715      ! Compute Stellar Longitude (Ls), and orbital parameters.
716      ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
717      if (season) then
718         call stellarlong(zday,zls)
719      else
720         call stellarlong(noseason_day,zls)
721      end if
722
723      call orbite(zls,dist_star,declin,right_ascen)
724
725      if (diurnal) then
726              zlss=-2.*pi*(zday-.5)
727      else if(diurnal .eqv. .false.) then
728              zlss=9999.
729      endif
730
731
732      glat(:) = g !AF24: removed oblateness
733
734      ! Compute geopotential between layers.
735      ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
736      zzlay(1:ngrid,1:nlayer)=pphi(1:ngrid,1:nlayer)
737      do l=1,nlayer
738         zzlay(1:ngrid,l)= zzlay(1:ngrid,l)/glat(1:ngrid)
739      enddo
740
741      zzlev(1:ngrid,1)=0.
742
743      do l=2,nlayer
744         do ig=1,ngrid
745            z1=(pplay(ig,l-1)+pplev(ig,l))/(pplay(ig,l-1)-pplev(ig,l))
746            z2=(pplev(ig,l)+pplay(ig,l))/(pplev(ig,l)-pplay(ig,l))
747            zzlev(ig,l)=(z1*zzlay(ig,l-1)+z2*zzlay(ig,l))/(z1+z2)
748         enddo
749      enddo
750
751      !Altitude of top interface (nlayer+1), using the thicknesss of the level below the top one. LT22
752
753      zzlev(1:ngrid,nlayer+1) = 2*zzlev(1:ngrid,nlayer)-zzlev(1:ngrid,nlayer-1)
754
755      ! Compute potential temperature
756      ! Note : Potential temperature calculation may not be the same in physiq and dynamic...
757      ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
758      do l=1,nlayer
759         do ig=1,ngrid
760            zpopsk(ig,l)=(pplay(ig,l)/pplev(ig,1))**rcp
761            zh(ig,l)=pt(ig,l)/zpopsk(ig,l)
762            mass(ig,l)  = (pplev(ig,l) - pplev(ig,l+1))/glat(ig)
763            massarea(ig,l)=mass(ig,l)*cell_area(ig)
764         enddo
765      enddo
766
767     ! Compute vertical velocity (m/s) from vertical mass flux
768     ! w = F / (rho*area) and rho = P/(r*T)
769     ! But first linearly interpolate mass flux to mid-layers
770      do l=1,nlayer-1
771         pw(1:ngrid,l)=0.5*(flxw(1:ngrid,l)+flxw(1:ngrid,l+1))
772      enddo
773      pw(1:ngrid,nlayer)=0.5*flxw(1:ngrid,nlayer) ! since flxw(nlayer+1)=0
774      do l=1,nlayer
775         pw(1:ngrid,l)=(pw(1:ngrid,l)*r*pt(1:ngrid,l)) /  &
776                       (pplay(1:ngrid,l)*cell_area(1:ngrid))
777      enddo
778      ! omega in Pa/s
779      do l=1,nlayer-1
780         omega(1:ngrid,l)=0.5*(flxw(1:ngrid,l)+flxw(1:ngrid,l+1))
781      enddo
782      omega(1:ngrid,nlayer)=0.5*flxw(1:ngrid,nlayer) ! since flxw(nlayer+1)=0
783      do l=1,nlayer
784         omega(1:ngrid,l)=g*omega(1:ngrid,l)/cell_area(1:ngrid)
785      enddo
786
787!---------------------------------
788! II. Compute radiative tendencies
789!---------------------------------
790
791      ! Compute local stellar zenith angles
792      ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
793      if (diurnal) then
794         ztim1=SIN(declin)
795         ztim2=COS(declin)*COS(2.*pi*(zday-.5))
796         ztim3=-COS(declin)*SIN(2.*pi*(zday-.5))
797
798         call stelang(ngrid,sinlon,coslon,sinlat,coslat,    &
799                        ztim1,ztim2,ztim3,mu0,fract)
800      else if(diurnal .eqv. .false.) then
801
802         call mucorr(ngrid,declin,latitude,mu0,fract,10000.,rad)
803         ! WARNING: this function appears not to work in 1D
804
805         if ((ngrid.eq.1).and.(global1d)) then ! Fixed zenith angle 'szangle' in 1D simulations w/ globally-averaged sunlight.
806            mu0 = cos(pi*szangle/180.0)
807         endif
808
809      endif
810
811      if (callrad) then
812         if( mod(icount-1,iradia).eq.0.or.lastcall) then
813
814            ! Eclipse incoming sunlight !AF24: removed
815
816!!            call writediagfi(ngrid,"corrk_pre_dqsurf"," "," ",2,dqsurf(1:ngrid,igcm_h2o_vap))
817!!            call writediagfi(ngrid,"corrk_pre_qsurf"," "," ",2,qsurf(1:ngrid,igcm_h2o_vap))
818
819
820            if (corrk) then
821
822! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
823! II.a Call correlated-k radiative transfer scheme
824! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
825               if(kastprof)then
826                  print*,'kastprof should not = true here'
827                  call abort
828               endif
829               ! if(water) then !AF24: removed
830
831               if(generic_condensation) then
832                  do iq=1,nq
833
834                     call generic_tracer_index(nq,iq,igcm_generic_vap,igcm_generic_ice,call_ice_vap_generic)
835
836                     if (call_ice_vap_generic) then ! to call only one time the ice/vap pair of a tracer
837
838                        epsi_generic=constants_epsi_generic(iq)
839
840                        muvar(1:ngrid,1:nlayer)=mugaz/(1.e0+(1.e0/epsi_generic-1.e0)*pq(1:ngrid,1:nlayer,igcm_generic_vap))
841                        muvar(1:ngrid,nlayer+1)=mugaz/(1.e0+(1.e0/epsi_generic-1.e0)*pq(1:ngrid,nlayer,igcm_generic_vap))
842
843                     endif
844                  end do ! do iq=1,nq loop on tracers
845               ! take into account generic condensable specie (GCS) effect on mean molecular weight
846
847               else
848                  muvar(1:ngrid,1:nlayer+1)=mugaz
849               endif
850
851               ! if(ok_slab_ocean) then !AF24: removed
852
853               ! standard callcorrk
854               ! clearsky=.false.
855               call callcorrk(ngrid,nlayer,pq,nq,qsurf,                           &
856                              albedo,albedo_equivalent,emis,mu0,pplev,pplay,pt,   &
857                              tsurf,fract,dist_star,aerosol,muvar,                &
858                              zdtlw,zdtsw,fluxsurf_lw,fluxsurf_sw,                &
859                              fluxsurfabs_sw,fluxtop_lw,                          &
860                              fluxabs_sw,fluxtop_dn,OLR_nu,OSR_nu,GSR_nu,         &
861                              int_dtaui,int_dtauv,                                &
862                              tau_col,cloudfrac,totcloudfrac,                     &
863                              .false.,firstcall,lastcall)
864
865                !GG (feb2021): Option to "artificially" decrease the raditive time scale in
866                !the deep atmosphere  press > 0.1 bar. Suggested by MT.
867                !! COEFF_RAD to be "tuned" to facilitate convergence of tendency
868
869                !coeff_rad=0.   ! 0 values, it doesn't accelerate the convergence
870                !coeff_rad=0.5
871                !coeff_rad=1.
872                !do l=1, nlayer
873                !  do ig=1,ngrid
874                !    if(pplay(ig,l).ge.1.d4) then
875                !      zdtsw(ig,l)=zdtsw(ig,l)*(pplay(ig,l)/1.d4)**coeff_rad
876                !      zdtlw(ig,l)=zdtlw(ig,l)*(pplay(ig,l)/1.d4)**coeff_rad
877                !    endif
878                !  enddo
879                !enddo
880
881                ! AF24: removed CLFvarying Option
882
883               ! if(ok_slab_ocean) then
884               !    tsurf(:)=tsurf2(:)
885               ! endif
886
887
888               ! Radiative flux from the sky absorbed by the surface (W.m-2).
889               GSR=0.0
890               fluxrad_sky(1:ngrid)=emis(1:ngrid)*fluxsurf_lw(1:ngrid)+fluxsurfabs_sw(1:ngrid)
891
892                            !if(noradsurf)then ! no lower surface; SW flux just disappears
893                            !   GSR = SUM(fluxsurf_sw(1:ngrid)*cell_area(1:ngrid))/totarea
894                            !   fluxrad_sky(1:ngrid)=emis(1:ngrid)*fluxsurf_lw(1:ngrid)
895                            !   print*,'SW lost in deep atmosphere = ',GSR,' W m^-2'
896                            !endif
897
898               ! Net atmospheric radiative heating rate (K.s-1)
899               dtrad(1:ngrid,1:nlayer)=zdtsw(1:ngrid,1:nlayer)+zdtlw(1:ngrid,1:nlayer)
900
901               ! Late initialization of the Ice Spectral Albedo. We needed the visible bands to do that !
902               if (firstcall .and. albedo_spectral_mode) then
903                  call spectral_albedo_calc(albedo_snow_SPECTV)
904               endif
905
906! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
907! II.b Call Newtonian cooling scheme !AF24: removed
908! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
909            else
910! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
911! II.c Atmosphere has no radiative effect
912! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
913               fluxtop_dn(1:ngrid)  = fract(1:ngrid)*mu0(1:ngrid)*Fat1AU/dist_star**2
914               if(ngrid.eq.1)then ! / by 4 globally in 1D case...
915                  fluxtop_dn(1)  = fract(1)*Fat1AU/dist_star**2/2.0
916               endif
917               fluxsurf_sw(1:ngrid) = fluxtop_dn(1:ngrid)
918               print*,'------------WARNING---WARNING------------' ! by MT2015.
919               print*,'You are in corrk=false mode, '
920               print*,'and the surface albedo is taken equal to the first visible spectral value'
921
922               fluxsurfabs_sw(1:ngrid) = fluxtop_dn(1:ngrid)*(1.-albedo(1:ngrid,1))
923               fluxrad_sky(1:ngrid)    = fluxsurfabs_sw(1:ngrid)
924               fluxtop_lw(1:ngrid)  = emis(1:ngrid)*sigma*tsurf(1:ngrid)**4
925
926               dtrad(1:ngrid,1:nlayer)=0.0 ! no atmospheric radiative heating
927
928            endif ! end of corrk
929
930         endif ! of if(mod(icount-1,iradia).eq.0)
931
932
933         ! Transformation of the radiative tendencies
934         ! ------------------------------------------
935         zplanck(1:ngrid)=tsurf(1:ngrid)*tsurf(1:ngrid)
936         zplanck(1:ngrid)=emis(1:ngrid)*sigma*zplanck(1:ngrid)*zplanck(1:ngrid)
937         fluxrad(1:ngrid)=fluxrad_sky(1:ngrid)-zplanck(1:ngrid)
938         pdt(1:ngrid,1:nlayer)=pdt(1:ngrid,1:nlayer)+dtrad(1:ngrid,1:nlayer)
939
940         ! Test of energy conservation
941         !----------------------------
942         if(enertest)then
943            call planetwide_sumval(cpp*massarea(:,:)*zdtsw(:,:)/totarea_planet,dEtotSW)
944            call planetwide_sumval(cpp*massarea(:,:)*zdtlw(:,:)/totarea_planet,dEtotLW)
945            !call planetwide_sumval(fluxsurf_sw(:)*(1.-albedo_equivalent(:))*cell_area(:)/totarea_planet,dEtotsSW) !JL13 carefull, albedo can have changed since the last time we called corrk
946            call planetwide_sumval(fluxsurfabs_sw(:)*cell_area(:)/totarea_planet,dEtotsSW) !JL13 carefull, albedo can have changed since the last time we called corrk
947            call planetwide_sumval((fluxsurf_lw(:)*emis(:)-zplanck(:))*cell_area(:)/totarea_planet,dEtotsLW)
948            dEzRadsw(:,:)=cpp*mass(:,:)*zdtsw(:,:)
949            dEzRadlw(:,:)=cpp*mass(:,:)*zdtlw(:,:)
950            if (is_master) then
951               print*,'---------------------------------------------------------------'
952               print*,'In corrk SW atmospheric heating       =',dEtotSW,' W m-2'
953               print*,'In corrk LW atmospheric heating       =',dEtotLW,' W m-2'
954               print*,'atmospheric net rad heating (SW+LW)   =',dEtotLW+dEtotSW,' W m-2'
955               print*,'In corrk SW surface heating           =',dEtotsSW,' W m-2'
956               print*,'In corrk LW surface heating           =',dEtotsLW,' W m-2'
957               print*,'surface net rad heating (SW+LW)       =',dEtotsLW+dEtotsSW,' W m-2'
958            endif
959         endif ! end of 'enertest'
960
961      endif ! of if (callrad)
962
963!!      call writediagfi(ngrid,"vdifc_pre_dqsurf"," "," ",2,dqsurf(1:ngrid,igcm_h2o_vap))
964!!      call writediagfi(ngrid,"vdifc_pre_qsurf"," "," ",2,qsurf(1:ngrid,igcm_h2o_vap))
965
966
967!  --------------------------------------------
968!  III. Vertical diffusion (turbulent mixing) :
969!  --------------------------------------------
970
971      if (calldifv) then
972
973         zflubid(1:ngrid)=fluxrad(1:ngrid)+fluxgrd(1:ngrid)
974
975         ! JL12 the following if test is temporarily there to allow us to compare the old vdifc with turbdiff.
976         if (UseTurbDiff) then
977
978            call turbdiff(ngrid,nlayer,nq,                  &
979                          ptimestep,capcal,                      &
980                          pplay,pplev,zzlay,zzlev,z0,            &
981                          pu,pv,pt,zpopsk,pq,tsurf,emis,qsurf,   &
982                          pdt,pdq,zflubid,                       &
983                          zdudif,zdvdif,zdtdif,zdtsdif,          &
984                          sensibFlux,q2,zdqdif,zdqevap,zdqsdif,  &
985                          taux,tauy)
986
987         else
988
989            zdh(1:ngrid,1:nlayer)=pdt(1:ngrid,1:nlayer)/zpopsk(1:ngrid,1:nlayer)
990
991            call vdifc(ngrid,nlayer,nq,zpopsk,           &
992                       ptimestep,capcal,lwrite,               &
993                       pplay,pplev,zzlay,zzlev,z0,            &
994                       pu,pv,zh,pq,tsurf,emis,qsurf,          &
995                       zdh,pdq,zflubid,                       &
996                       zdudif,zdvdif,zdhdif,zdtsdif,          &
997                       sensibFlux,q2,zdqdif,zdqsdif)
998
999            zdtdif(1:ngrid,1:nlayer)=zdhdif(1:ngrid,1:nlayer)*zpopsk(1:ngrid,1:nlayer) ! for diagnostic only
1000            zdqevap(1:ngrid,1:nlayer)=0.
1001
1002         end if !end of 'UseTurbDiff'
1003
1004         zdtsurf(1:ngrid)=zdtsurf(1:ngrid)+zdtsdif(1:ngrid)
1005
1006         !!! this is always done, except for turbulence-resolving simulations
1007         if (.not. turb_resolved) then
1008           pdv(1:ngrid,1:nlayer)=pdv(1:ngrid,1:nlayer)+zdvdif(1:ngrid,1:nlayer)
1009           pdu(1:ngrid,1:nlayer)=pdu(1:ngrid,1:nlayer)+zdudif(1:ngrid,1:nlayer)
1010           pdt(1:ngrid,1:nlayer)=pdt(1:ngrid,1:nlayer)+zdtdif(1:ngrid,1:nlayer)
1011         endif
1012
1013         ! if(ok_slab_ocean)then !AF24: removed
1014         !    flux_sens_lat(1:ngrid)=(zdtsdif(1:ngrid)*capcal(1:ngrid)-fluxrad(1:ngrid))
1015         ! endif
1016
1017!!         call writediagfi(ngrid,"vdifc_post_zdqsdif"," "," ",2,zdqsdif(1:ngrid,igcm_h2o_vap))
1018
1019         if (tracer) then
1020           pdq(1:ngrid,1:nlayer,1:nq)=pdq(1:ngrid,1:nlayer,1:nq)+ zdqdif(1:ngrid,1:nlayer,1:nq)
1021           dqsurf(1:ngrid,1:nq)=dqsurf(1:ngrid,1:nq) + zdqsdif(1:ngrid,1:nq)
1022         end if ! of if (tracer)
1023
1024!!         call writediagfi(ngrid,"vdifc_post_dqsurf"," "," ",2,dqsurf(1:ngrid,igcm_h2o_vap))
1025!!         call writediagfi(ngrid,"vdifc_post_qsurf"," "," ",2,qsurf(1:ngrid,igcm_h2o_vap))
1026
1027         ! test energy conservation
1028         !-------------------------
1029         if(enertest)then
1030
1031            dEzdiff(:,:)=cpp*mass(:,:)*zdtdif(:,:)
1032            do ig = 1, ngrid
1033               dEdiff(ig)=SUM(dEzdiff (ig,:))+ sensibFlux(ig)! subtract flux to the ground
1034               dEzdiff(ig,1)= dEzdiff(ig,1)+ sensibFlux(ig)! subtract flux to the ground
1035            enddo
1036
1037            call planetwide_sumval(dEdiff(:)*cell_area(:)/totarea_planet,dEtot)
1038            dEdiffs(:)=capcal(:)*zdtsdif(:)-zflubid(:)-sensibFlux(:)
1039            call planetwide_sumval(dEdiffs(:)*cell_area(:)/totarea_planet,dEtots)
1040            call planetwide_sumval(sensibFlux(:)*cell_area(:)/totarea_planet,AtmToSurf_TurbFlux)
1041
1042            if (is_master) then
1043
1044               if (UseTurbDiff) then
1045                         print*,'In TurbDiff sensible flux (atm=>surf) =',AtmToSurf_TurbFlux,' W m-2'
1046                         print*,'In TurbDiff non-cons atm nrj change   =',dEtot,' W m-2'
1047                  print*,'In TurbDiff (correc rad+latent heat) surf nrj change =',dEtots,' W m-2'
1048               else
1049                         print*,'In vdifc sensible flux (atm=>surf)    =',AtmToSurf_TurbFlux,' W m-2'
1050                         print*,'In vdifc non-cons atm nrj change      =',dEtot,' W m-2'
1051                         print*,'In vdifc (correc rad+latent heat) surf nrj change =',dEtots,' W m-2'
1052               end if
1053            endif ! end of 'is_master'
1054
1055         ! JL12 : note that the black body radiative flux emitted by the surface has been updated by the implicit scheme but not given back elsewhere.
1056         endif ! end of 'enertest'
1057
1058
1059         ! ! Test water conservation. !AF24: removed
1060
1061      else ! calldifv
1062
1063         ! if(.not.newtonian)then
1064            zdtsurf(1:ngrid) = zdtsurf(1:ngrid) + (fluxrad(1:ngrid) + fluxgrd(1:ngrid))/capcal(1:ngrid)
1065
1066      endif ! end of 'calldifv'
1067
1068
1069!-------------------
1070!   IV. Convection :
1071!-------------------
1072
1073! ~~~~~~~~~~~~~~~~~~~~~~~~~~
1074! IV.a Thermal plume model : AF24: removed
1075! ~~~~~~~~~~~~~~~~~~~~~~~~~~
1076
1077! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1078! IV.b Dry convective adjustment :
1079! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1080
1081      if(calladj) then
1082
1083         zdh(1:ngrid,1:nlayer) = pdt(1:ngrid,1:nlayer)/zpopsk(1:ngrid,1:nlayer)
1084         zduadj(1:ngrid,1:nlayer)=0.0
1085         zdvadj(1:ngrid,1:nlayer)=0.0
1086         zdhadj(1:ngrid,1:nlayer)=0.0
1087
1088
1089         call convadj(ngrid,nlayer,nq,ptimestep,            &
1090                      pplay,pplev,zpopsk,                   &
1091                      pu,pv,zh,pq,                          &
1092                      pdu,pdv,zdh,pdq,                      &
1093                      zduadj,zdvadj,zdhadj,                 &
1094                      zdqadj)
1095
1096         pdu(1:ngrid,1:nlayer) = pdu(1:ngrid,1:nlayer) + zduadj(1:ngrid,1:nlayer)
1097         pdv(1:ngrid,1:nlayer) = pdv(1:ngrid,1:nlayer) + zdvadj(1:ngrid,1:nlayer)
1098         pdt(1:ngrid,1:nlayer)    = pdt(1:ngrid,1:nlayer) + zdhadj(1:ngrid,1:nlayer)*zpopsk(1:ngrid,1:nlayer)
1099         zdtadj(1:ngrid,1:nlayer) = zdhadj(1:ngrid,1:nlayer)*zpopsk(1:ngrid,1:nlayer) ! for diagnostic only
1100
1101         if(tracer) then
1102            pdq(1:ngrid,1:nlayer,1:nq) = pdq(1:ngrid,1:nlayer,1:nq) + zdqadj(1:ngrid,1:nlayer,1:nq)
1103         end if
1104
1105         ! Test energy conservation
1106         if(enertest)then
1107            call planetwide_sumval(cpp*massarea(:,:)*zdtadj(:,:)/totarea_planet,dEtot)
1108            if (is_master) print*,'In convadj atmospheric energy change  =',dEtot,' W m-2'
1109         endif
1110
1111         ! ! Test water conservation !AF24: removed
1112
1113      endif ! end of 'calladj'
1114!----------------------------------------------
1115!   Non orographic Gravity Waves: AF24: removed
1116!---------------------------------------------
1117
1118!-----------------------------------------------
1119!   V. Nitrogen condensation-sublimation :
1120!-----------------------------------------------
1121
1122      if (n2cond) then
1123
1124         if (.not.tracer) then
1125            print*,'We need a N2 ice tracer to condense N2'
1126            call abort
1127         endif
1128
1129         call condense_n2(ngrid,nlayer,nq,ptimestep,                    &
1130                           capcal,pplay,pplev,tsurf,pt,                 &
1131                           pphi,pdt,pdu,pdv,zdtsurf,pu,pv,pq,pdq,       &
1132                           qsurf(1,igcm_n2),albedo,emis,                &
1133                           zdtc,zdtsurfc,pdpsrf,zduc,zdvc,              &
1134                           zdqc,zdqsc(1,igcm_n2))
1135
1136         pdt(1:ngrid,1:nlayer) = pdt(1:ngrid,1:nlayer)+zdtc(1:ngrid,1:nlayer)
1137         zdtsurf(1:ngrid)      = zdtsurf(1:ngrid) + zdtsurfc(1:ngrid)
1138
1139         pdq(1:ngrid,1:nlayer,1:nq)   = pdq(1:ngrid,1:nlayer,1:nq)+ zdqc(1:ngrid,1:nlayer,1:nq)
1140         ! dqsurf(1:ngrid,igcm_n2_ice) = dqsurf(1:ngrid,igcm_n2_ice) + zdqsurfc(1:ngrid)
1141
1142!!         call writediagfi(ngrid,"condense_n2_post_dqsurf"," "," ",2,dqsurf(1:ngrid,igcm_h2o_vap))
1143!!         call writediagfi(ngrid,"condense_n2_post_qsurf"," "," ",2,qsurf(1:ngrid,igcm_h2o_vap))
1144
1145         ! test energy conservation
1146         if(enertest)then
1147            call planetwide_sumval(cpp*massarea(:,:)*zdtc(:,:)/totarea_planet,dEtot)
1148            call planetwide_sumval(capcal(:)*zdtsurfc(:)*cell_area(:)/totarea_planet,dEtots)
1149            if (is_master) then
1150               print*,'In n2cloud atmospheric energy change   =',dEtot,' W m-2'
1151               print*,'In n2cloud surface energy change       =',dEtots,' W m-2'
1152            endif
1153         endif
1154
1155      endif  ! end of 'n2cond'
1156
1157
1158!---------------------------------------------
1159!   VI. Specific parameterizations for tracers
1160!---------------------------------------------
1161
1162      if (tracer) then
1163
1164  ! ---------------------
1165  !   VI.1. Water and ice !AF24: removed
1166  ! ---------------------
1167  ! -------------------------
1168  !   VI.2. Photochemistry !AF24: removed
1169  ! -------------------------
1170  ! -------------------------
1171  !   VI.3. Aerosol particles
1172  ! -------------------------
1173
1174         !Generic Condensation
1175         if (generic_condensation) then
1176            call condensation_generic(ngrid,nlayer,nq,ptimestep,pplev,pplay,   &
1177                                          pt,pq,pdt,pdq,dt_generic_condensation, &
1178                                          dqvaplscale_generic,dqcldlscale_generic,rneb_generic)
1179            pdt(1:ngrid,1:nlayer) = pdt(1:ngrid,1:nlayer)+dt_generic_condensation(1:ngrid,1:nlayer)
1180            pdq(1:ngrid,1:nlayer,1:nq) = pdq(1:ngrid,1:nlayer,1:nq)+dqvaplscale_generic(1:ngrid,1:nlayer,1:nq)
1181            pdq(1:ngrid,1:nlayer,1:nq) = pdq(1:ngrid,1:nlayer,1:nq)+dqcldlscale_generic(1:ngrid,1:nlayer,1:nq)
1182
1183            if(enertest)then
1184               do ig=1,ngrid
1185                  genericconddE(ig) = cpp*SUM(mass(:,:)*dt_generic_condensation(:,:))
1186               enddo
1187
1188               call planetwide_sumval(cpp*massarea(:,:)*dt_generic_condensation(:,:)/totarea_planet,dEtot)
1189
1190               if (is_master) print*,'In generic condensation atmospheric energy change =',dEtot,' W m-2'
1191            end if
1192
1193            ! if (.not. water) then
1194               ! Compute GCS (Generic Condensable Specie) cloud fraction. For now we can not have both water cloud fraction and GCS cloud fraction
1195               ! Water is the priority
1196               ! If you have set water and generic_condensation, then cloudfrac will be water cloudfrac
1197               !
1198               ! If you have set generic_condensation (and not water) and you have set several GCS
1199               ! then cloudfrac will be only the cloudfrac of the last generic tracer
1200               ! (Because it is rewritten every tracer in the loop)
1201               !
1202               ! Maybe one should create a cloudfrac_generic(ngrid,nlayer,nq) with 3 dimensions, the last one for tracers
1203
1204               ! Let's loop on tracers
1205               cloudfrac(:,:)=0.0
1206               do iq=1,nq
1207                  call generic_tracer_index(nq,iq,igcm_generic_vap,igcm_generic_ice,call_ice_vap_generic)
1208                  if (call_ice_vap_generic) then ! to call only one time the ice/vap pair of a tracer
1209                     do l = 1, nlayer
1210                        do ig=1,ngrid
1211                           cloudfrac(ig,l)=rneb_generic(ig,l,iq)
1212                        enddo
1213                     enddo
1214                  endif
1215            end do ! do iq=1,nq loop on tracers
1216            ! endif ! .not. water
1217
1218         endif !generic_condensation
1219
1220         !Generic Rain !AF24: removed
1221
1222         ! Sedimentation.
1223         if (sedimentation) then
1224
1225            zdqsed(1:ngrid,1:nlayer,1:nq) = 0.0
1226            zdqssed(1:ngrid,1:nq)  = 0.0
1227
1228            ! if(watertest)then !AF24: removed
1229
1230            call callsedim(ngrid,nlayer,ptimestep,           &
1231                          pplev,zzlev,pt,pdt,pq,pdq,        &
1232                          zdqsed,zdqssed,nq)
1233
1234            ! if(watertest)then !AF24: removed
1235
1236            ! Whether it falls as rain or snow depends only on the surface temperature
1237            pdq(1:ngrid,1:nlayer,1:nq) = pdq(1:ngrid,1:nlayer,1:nq) + zdqsed(1:ngrid,1:nlayer,1:nq)
1238            dqsurf(1:ngrid,1:nq) = dqsurf(1:ngrid,1:nq) + zdqssed(1:ngrid,1:nq)
1239
1240!!            call writediagfi(ngrid,"callsedim_post_dqsurf"," "," ",2,dqsurf(1:ngrid,igcm_h2o_vap))
1241
1242            ! ! Test water conservation !AF24: removed
1243
1244         end if ! end of 'sedimentation'
1245
1246!!         call writediagfi(ngrid,"mass_redist_pre_dqsurf"," "," ",2,dqsurf(1:ngrid,igcm_h2o_vap))
1247!!         call writediagfi(ngrid,"mass_redist_pre_qsurf"," "," ",2,qsurf(1:ngrid,igcm_h2o_vap))
1248
1249  ! ---------------
1250  !   VI.4. Updates
1251  ! ---------------
1252
1253         ! Updating Atmospheric Mass and Tracers budgets.
1254         if(mass_redistrib) then
1255
1256            zdmassmr(1:ngrid,1:nlayer) = mass(1:ngrid,1:nlayer) * 0
1257            !    (   zdqevap(1:ngrid,1:nlayer)                          &
1258            !    !   + zdqrain(1:ngrid,1:nlayer,igcm_h2o_vap)             &
1259            !    !   + dqmoist(1:ngrid,1:nlayer,igcm_h2o_vap)             &
1260            !      + dqvaplscale(1:ngrid,1:nlayer) )
1261
1262            do ig = 1, ngrid
1263               zdmassmr_col(ig)=SUM(zdmassmr(ig,1:nlayer))
1264            enddo
1265
1266            ! call writediagfi(ngrid,"mass_evap","mass gain"," ",3,zdmassmr)
1267            ! call writediagfi(ngrid,"mass_evap_col","mass gain col"," ",2,zdmassmr_col)
1268            call writediagfi(ngrid,"mass","mass","kg/m2",3,mass)
1269
1270            call mass_redistribution(ngrid,nlayer,nq,ptimestep,                     &
1271                                     capcal,pplay,pplev,pt,tsurf,pq,qsurf,     &
1272                                     pu,pv,pdt,zdtsurf,pdq,pdu,pdv,zdmassmr,        &
1273                                     zdtmr,zdtsurfmr,zdpsrfmr,zdumr,zdvmr,zdqmr,zdqsurfmr)
1274
1275            pdq(1:ngrid,1:nlayer,1:nq) = pdq(1:ngrid,1:nlayer,1:nq) + zdqmr(1:ngrid,1:nlayer,1:nq)
1276            dqsurf(1:ngrid,1:nq)       = dqsurf(1:ngrid,1:nq) + zdqsurfmr(1:ngrid,1:nq)
1277            pdt(1:ngrid,1:nlayer)      = pdt(1:ngrid,1:nlayer) + zdtmr(1:ngrid,1:nlayer)
1278            pdu(1:ngrid,1:nlayer)      = pdu(1:ngrid,1:nlayer) + zdumr(1:ngrid,1:nlayer)
1279            pdv(1:ngrid,1:nlayer)      = pdv(1:ngrid,1:nlayer) + zdvmr(1:ngrid,1:nlayer)
1280            pdpsrf(1:ngrid)            = pdpsrf(1:ngrid) + zdpsrfmr(1:ngrid)
1281            zdtsurf(1:ngrid)           = zdtsurf(1:ngrid) + zdtsurfmr(1:ngrid)
1282
1283         endif
1284
1285!         call writediagfi(ngrid,"mass_redistribution_post_dqsurf"," "," ",2,dqsurf(1:ngrid,igcm_h2o_vap))
1286
1287!!         call writediagfi(ngrid,"slab_pre_dqsurf"," "," ",2,dqsurf(1:ngrid,igcm_h2o_vap))
1288!!         call writediagfi(ngrid,"slab_pre_qsurf"," "," ",2,qsurf(1:ngrid,igcm_h2o_vap))
1289
1290
1291! ------------------
1292!   VI.5. Slab Ocean !AF24: removed
1293! ------------------
1294
1295  ! -----------------------------
1296  !   VI.6. Surface Tracer Update
1297  ! -----------------------------
1298
1299         ! AF24: deleted hydrology
1300
1301         qsurf(1:ngrid,1:nq) = qsurf(1:ngrid,1:nq) + ptimestep*dqsurf(1:ngrid,1:nq)
1302
1303         ! Add qsurf to qsurf_hist, which is what we save in diagfi.nc. At the same time, we set the water
1304         ! content of ocean gridpoints back to zero, in order to avoid rounding errors in vdifc, rain.
1305         qsurf_hist(:,:) = qsurf(:,:)
1306
1307         ! if(ice_update)then
1308         !    ice_min(1:ngrid)=min(ice_min(1:ngrid),qsurf(1:ngrid,igcm_h2o_ice))
1309         ! endif
1310
1311      endif! end of if 'tracer'
1312
1313
1314!------------------------------------------------
1315!   VII. Surface and sub-surface soil temperature
1316!------------------------------------------------
1317
1318
1319      ! ! Increment surface temperature
1320      ! if(ok_slab_ocean)then  !AF24: removed
1321
1322      tsurf(1:ngrid)=tsurf(1:ngrid)+ptimestep*zdtsurf(1:ngrid)
1323
1324      ! Compute soil temperatures and subsurface heat flux.
1325      if (callsoil) then
1326         call soil(ngrid,nsoilmx,.false.,lastcall,inertiedat,   &
1327                   ptimestep,tsurf,tsoil,capcal,fluxgrd)
1328      endif
1329
1330
1331!       if (ok_slab_ocean) then !AF24: removed
1332
1333      ! Test energy conservation
1334      if(enertest)then
1335         call planetwide_sumval(cell_area(:)*capcal(:)*zdtsurf(:)/totarea_planet,dEtots)
1336         if (is_master) print*,'Surface energy change                 =',dEtots,' W m-2'
1337      endif
1338
1339
1340!---------------------------------------------------
1341!   VIII. Perform diagnostics and write output files
1342!---------------------------------------------------
1343
1344      ! Note : For output only: the actual model integration is performed in the dynamics.
1345
1346
1347      ! Temperature, zonal and meridional winds.
1348      zt(1:ngrid,1:nlayer) = pt(1:ngrid,1:nlayer) + pdt(1:ngrid,1:nlayer)*ptimestep
1349      zu(1:ngrid,1:nlayer) = pu(1:ngrid,1:nlayer) + pdu(1:ngrid,1:nlayer)*ptimestep
1350      zv(1:ngrid,1:nlayer) = pv(1:ngrid,1:nlayer) + pdv(1:ngrid,1:nlayer)*ptimestep
1351
1352      !! Recast thermal plume vertical velocity array for outputs
1353      !! AF24: removed
1354
1355      ! Diagnostic.
1356      zdtdyn(1:ngrid,1:nlayer)     = (pt(1:ngrid,1:nlayer)-ztprevious(1:ngrid,1:nlayer)) / ptimestep
1357      ztprevious(1:ngrid,1:nlayer) = zt(1:ngrid,1:nlayer)
1358
1359      zdudyn(1:ngrid,1:nlayer)     = (pu(1:ngrid,1:nlayer)-zuprevious(1:ngrid,1:nlayer)) / ptimestep
1360      zuprevious(1:ngrid,1:nlayer) = zu(1:ngrid,1:nlayer)
1361
1362      if(firstcall)then
1363         zdtdyn(1:ngrid,1:nlayer)=0.0
1364         zdudyn(1:ngrid,1:nlayer)=0.0
1365      endif
1366
1367      ! Dynamical heating diagnostic.
1368      do ig=1,ngrid
1369         fluxdyn(ig)= SUM(zdtdyn(ig,:) *mass(ig,:))*cpp
1370      enddo
1371
1372      ! Tracers.
1373      zq(1:ngrid,1:nlayer,1:nq) = pq(1:ngrid,1:nlayer,1:nq) + pdq(1:ngrid,1:nlayer,1:nq)*ptimestep
1374
1375      ! Surface pressure.
1376      ps(1:ngrid) = pplev(1:ngrid,1) + pdpsrf(1:ngrid)*ptimestep
1377
1378
1379
1380      ! Surface and soil temperature information
1381      call planetwide_sumval(cell_area(:)*tsurf(:)/totarea_planet,Ts1)
1382      call planetwide_minval(tsurf(:),Ts2)
1383      call planetwide_maxval(tsurf(:),Ts3)
1384      if(callsoil)then
1385         TsS = SUM(cell_area(:)*tsoil(:,nsoilmx))/totarea        ! mean temperature at bottom soil layer
1386         if (is_master) then
1387            print*,'          ave[Tsurf]             min[Tsurf]             max[Tsurf]             ave[Tdeep]'
1388            print*,Ts1,Ts2,Ts3,TsS
1389         end if
1390      else
1391         if (is_master) then
1392            print*,'          ave[Tsurf]             min[Tsurf]             max[Tsurf]'
1393            print*,Ts1,Ts2,Ts3
1394         endif
1395      end if
1396
1397
1398      ! Check the energy balance of the simulation during the run
1399      if(corrk)then
1400
1401         call planetwide_sumval(cell_area(:)*fluxtop_dn(:)/totarea_planet,ISR)
1402         call planetwide_sumval(cell_area(:)*fluxabs_sw(:)/totarea_planet,ASR)
1403         call planetwide_sumval(cell_area(:)*fluxtop_lw(:)/totarea_planet,OLR)
1404         call planetwide_sumval(cell_area(:)*fluxgrd(:)/totarea_planet,GND)
1405         call planetwide_sumval(cell_area(:)*fluxdyn(:)/totarea_planet,DYN)
1406         do ig=1,ngrid
1407            if(fluxtop_dn(ig).lt.0.0)then
1408               print*,'fluxtop_dn has gone crazy'
1409               print*,'fluxtop_dn=',fluxtop_dn(ig)
1410               print*,'tau_col=',tau_col(ig)
1411               print*,'aerosol=',aerosol(ig,:,:)
1412               print*,'temp=   ',pt(ig,:)
1413               print*,'pplay=  ',pplay(ig,:)
1414               call abort
1415            endif
1416         end do
1417
1418         if(ngrid.eq.1)then
1419            DYN=0.0
1420         endif
1421
1422         if (is_master) then
1423            print*,'  ISR            ASR            OLR            GND            DYN [W m^-2]'
1424            print*, ISR,ASR,OLR,GND,DYN
1425         endif
1426
1427         if(enertest .and. is_master)then
1428            print*,'SW flux/heating difference SW++ - ASR = ',dEtotSW+dEtotsSW-ASR,' W m-2'
1429            print*,'LW flux/heating difference LW++ - OLR = ',dEtotLW+dEtotsLW+OLR,' W m-2'
1430            print*,'LW energy balance LW++ + ASR = ',dEtotLW+dEtotsLW+ASR,' W m-2'
1431         endif
1432
1433         if(meanOLR .and. is_master)then
1434            if((ngrid.gt.1) .or. (mod(icount-1,ecritphy).eq.0))then
1435               ! to record global radiative balance
1436               open(92,file="rad_bal.out",form='formatted',position='append')
1437               write(92,*) zday,ISR,ASR,OLR
1438               close(92)
1439               open(93,file="tem_bal.out",form='formatted',position='append')
1440               if(callsoil)then
1441                         write(93,*) zday,Ts1,Ts2,Ts3,TsS
1442               else
1443                  write(93,*) zday,Ts1,Ts2,Ts3
1444               endif
1445               close(93)
1446            endif
1447         endif
1448
1449      endif ! end of 'corrk'
1450
1451
1452      ! Diagnostic to test radiative-convective timescales in code.
1453      if(testradtimes)then
1454         open(38,file="tau_phys.out",form='formatted',position='append')
1455         ig=1
1456         do l=1,nlayer
1457            write(38,*) -1./pdt(ig,l),pt(ig,l),pplay(ig,l)
1458         enddo
1459         close(38)
1460         print*,'As testradtimes enabled,'
1461         print*,'exiting physics on first call'
1462         call abort
1463      endif
1464
1465
1466      ! Compute column amounts (kg m-2) if tracers are enabled.
1467      if(tracer)then
1468         qcol(1:ngrid,1:nq)=0.0
1469         do iq=1,nq
1470            do ig=1,ngrid
1471               qcol(ig,iq) = SUM( zq(ig,1:nlayer,iq) * mass(ig,1:nlayer))
1472            enddo
1473         enddo
1474
1475         if (aerohaze) then
1476            ! Generalised for arbitrary aerosols now. By LK
1477         reffcol(1:ngrid,1:naerkind)=0.0
1478            ! call n2_reffrad(ngrid,nlayer,nq,zq,reffrad(1,1,iaero_haze))
1479         if (haze_proffix.and.i_haze.gt.0.) then
1480               call haze_prof(ngrid,nlayer,zzlay,pplay,pt, &
1481                                        reffrad,profmmr)
1482               zdqhaze(:,:,i_haze)=(profmmr(:,:)-pq(:,:,igcm_n2)) & ! AF: TODO: replace by igcm_haze?
1483                                                        /ptimestep
1484              else
1485               !! AF: TODO import from pluto.old?
1486               ! call hazecloud(ngrid,nlayer,nq,ptimestep,&
1487               !    pplay,pplev,pq,pdq,dist_sol,mu0,zfluxuv,zdqhaze,&
1488               !    zdqphot_prec,zdqphot_ch4,zdqconv_prec,declin)
1489              endif
1490
1491         DO iq=1, nq ! should be updated
1492            DO l=1,nlayer
1493              DO ig=1,ngrid
1494                   pdq(ig,l,iq)=pdq(ig,l,iq)+ zdqhaze(ig,l,iq)
1495              ENDDO
1496            ENDDO
1497         ENDDO
1498         endif ! end of aerohaze
1499      endif ! end of 'tracer'
1500
1501
1502      ! ! Test for water conservation. !AF24: removed
1503
1504      ! Calculate RH_generic (Generic Relative Humidity) for diagnostic.
1505      if(generic_condensation)then
1506         RH_generic(:,:,:)=0.0
1507         do iq=1,nq
1508
1509            call generic_tracer_index(nq,iq,igcm_generic_vap,igcm_generic_ice,call_ice_vap_generic)
1510
1511            if (call_ice_vap_generic) then ! to call only one time the ice/vap pair of a tracer
1512
1513               do l = 1, nlayer
1514                  do ig=1,ngrid
1515                     call Psat_generic(zt(ig,l),pplay(ig,l),metallicity,psat_tmp_generic,qsat_generic(ig,l,iq))
1516                     RH_generic(ig,l,iq) = zq(ig,l,igcm_generic_vap) / qsat_generic(ig,l,iq)
1517                  enddo
1518               enddo
1519
1520            end if
1521
1522         end do ! iq=1,nq
1523
1524      endif ! end of 'generic_condensation'
1525
1526
1527      if (is_master) print*,'--> Ls =',zls*180./pi
1528
1529
1530!----------------------------------------------------------------------
1531!        Writing NetCDF file  "RESTARTFI" at the end of the run
1532!----------------------------------------------------------------------
1533
1534!        Note: 'restartfi' is stored just before dynamics are stored
1535!              in 'restart'. Between now and the writting of 'restart',
1536!              there will have been the itau=itau+1 instruction and
1537!              a reset of 'time' (lastacll = .true. when itau+1= itaufin)
1538!              thus we store for time=time+dtvr
1539
1540
1541
1542      if(lastcall) then
1543         ztime_fin = ptime + ptimestep/(float(iphysiq)*daysec)
1544
1545         !! Update surface ice distribution to iterate to steady state if requested
1546         !! AF24: removed
1547
1548         ! endif
1549#ifndef MESOSCALE
1550
1551         if (ngrid.ne.1) then
1552            write(*,*)'PHYSIQ: for physdem ztime_fin =',ztime_fin
1553
1554            call physdem1("restartfi.nc",nsoilmx,ngrid,nlayer,nq, &
1555                          ptimestep,ztime_fin,                    &
1556                          tsurf,tsoil,emis,q2,qsurf_hist)
1557         endif
1558#endif
1559         ! if(ok_slab_ocean) then
1560         !    call ocean_slab_final!(tslab, seaice)
1561         ! end if
1562
1563    endif ! end of 'lastcall'
1564
1565
1566! -----------------------------------------------------------------
1567! WSTATS: Saving statistics
1568! -----------------------------------------------------------------
1569! ("stats" stores and accumulates key variables in file "stats.nc"
1570!  which can later be used to make the statistic files of the run:
1571!  if flag "callstats" from callphys.def is .true.)
1572
1573
1574         call wstats(ngrid,"ps","Surface pressure","Pa",2,ps)
1575         call wstats(ngrid,"tsurf","Surface temperature","K",2,tsurf)
1576         call wstats(ngrid,"fluxsurf_lw",                               &
1577                     "Thermal IR radiative flux to surface","W.m-2",2,  &
1578                     fluxsurf_lw)
1579         call wstats(ngrid,"fluxtop_lw",                                &
1580                     "Thermal IR radiative flux to space","W.m-2",2,    &
1581                     fluxtop_lw)
1582
1583!            call wstats(ngrid,"fluxsurf_sw",                               &
1584!                        "Solar radiative flux to surface","W.m-2",2,       &
1585!                         fluxsurf_sw_tot)
1586!            call wstats(ngrid,"fluxtop_sw",                                &
1587!                        "Solar radiative flux to space","W.m-2",2,         &
1588!                        fluxtop_sw_tot)
1589
1590
1591         call wstats(ngrid,"ISR","incoming stellar rad.","W m-2",2,fluxtop_dn)
1592         call wstats(ngrid,"ASR","absorbed stellar rad.","W m-2",2,fluxabs_sw)
1593         call wstats(ngrid,"OLR","outgoing longwave rad.","W m-2",2,fluxtop_lw)
1594         !call wstats(ngrid,"ALB","Surface albedo"," ",2,albedo_equivalent)
1595         !call wstats(ngrid,"ALB_1st","First Band Surface albedo"," ",2,albedo(:,1))
1596         call wstats(ngrid,"p","Pressure","Pa",3,pplay)
1597         call wstats(ngrid,"temp","Atmospheric temperature","K",3,zt)
1598         call wstats(ngrid,"u","Zonal (East-West) wind","m.s-1",3,zu)
1599         call wstats(ngrid,"v","Meridional (North-South) wind","m.s-1",3,zv)
1600         call wstats(ngrid,"w","Vertical (down-up) wind","m.s-1",3,pw)
1601         call wstats(ngrid,"q2","Boundary layer eddy kinetic energy","m2.s-2",3,q2)
1602
1603         if (tracer) then
1604            do iq=1,nq
1605               call wstats(ngrid,noms(iq),noms(iq),'kg/kg',3,zq(1,1,iq))
1606               call wstats(ngrid,trim(noms(iq))//'_surf',trim(noms(iq))//'_surf',  &
1607                           'kg m^-2',2,qsurf(1,iq) )
1608               call wstats(ngrid,trim(noms(iq))//'_col',trim(noms(iq))//'_col',    &
1609                          'kg m^-2',2,qcol(1,iq) )
1610
1611!              call wstats(ngrid,trim(noms(iq))//'_reff',                          &
1612!                          trim(noms(iq))//'_reff',                                   &
1613!                          'm',3,reffrad(1,1,iq))
1614
1615            end do
1616
1617         endif ! end of 'tracer'
1618
1619         !AF24: deleted slab ocean and water
1620
1621         if(lastcall.and.callstats) then
1622            write (*,*) "Writing stats..."
1623            call mkstats(ierr)
1624         endif
1625
1626
1627#ifndef MESOSCALE
1628
1629!-----------------------------------------------------------------------------------------------------
1630!           OUTPUT in netcdf file "DIAGFI.NC", containing any variable for diagnostic
1631!
1632!             Note 1 : output with  period "ecritphy", set in "run.def"
1633!
1634!             Note 2 : writediagfi can also be called from any other subroutine for any variable,
1635!                      but its preferable to keep all the calls in one place ...
1636!-----------------------------------------------------------------------------------------------------
1637
1638      call writediagfi(ngrid,"Ls","solar longitude","deg",0,zls*180./pi)
1639      call writediagfi(ngrid,"Lss","sub solar longitude","deg",0,zlss*180./pi)
1640      call writediagfi(ngrid,"RA","right ascension","deg",0,right_ascen*180./pi)
1641      call writediagfi(ngrid,"Declin","solar declination","deg",0,declin*180./pi)
1642      call writediagfi(ngrid,"tsurf","Surface temperature","K",2,tsurf)
1643      call writediagfi(ngrid,"ps","Surface pressure","Pa",2,ps)
1644      call writediagfi(ngrid,"temp","temperature","K",3,zt)
1645      call writediagfi(ngrid,"teta","potential temperature","K",3,zh)
1646      call writediagfi(ngrid,"u","Zonal wind","m.s-1",3,zu)
1647      call writediagfi(ngrid,"v","Meridional wind","m.s-1",3,zv)
1648      call writediagfi(ngrid,"w","Vertical wind","m.s-1",3,pw)
1649      call writediagfi(ngrid,"p","Pressure","Pa",3,pplay)
1650
1651!     Subsurface temperatures
1652!        call writediagsoil(ngrid,"tsurf","Surface temperature","K",2,tsurf)
1653!        call writediagsoil(ngrid,"temp","temperature","K",3,tsoil)
1654
1655!       ! Oceanic layers !AF24: removed
1656
1657      ! ! Thermal plume model  !AF24: removed
1658
1659!        GW non-oro outputs  !AF24: removed
1660
1661      ! Total energy balance diagnostics
1662      if(callrad)then
1663
1664         !call writediagfi(ngrid,"ALB","Surface albedo"," ",2,albedo_equivalent)
1665         !call writediagfi(ngrid,"ALB_1st","First Band Surface albedo"," ",2,albedo(:,1))
1666         call writediagfi(ngrid,"ISR","incoming stellar rad.","W m-2",2,fluxtop_dn)
1667         call writediagfi(ngrid,"ASR","absorbed stellar rad.","W m-2",2,fluxabs_sw)
1668         call writediagfi(ngrid,"OLR","outgoing longwave rad.","W m-2",2,fluxtop_lw)
1669         call writediagfi(ngrid,"shad","rings"," ", 2, fract)
1670
1671!           call writediagfi(ngrid,"ASRcs","absorbed stellar rad (cs).","W m-2",2,fluxabs_sw1)
1672!           call writediagfi(ngrid,"OLRcs","outgoing longwave rad (cs).","W m-2",2,fluxtop_lw1)
1673!           call writediagfi(ngrid,"fluxsurfsw","sw surface flux.","W m-2",2,fluxsurf_sw)
1674!           call writediagfi(ngrid,"fluxsurflw","lw back radiation.","W m-2",2,fluxsurf_lw)
1675!           call writediagfi(ngrid,"fluxsurfswcs","sw surface flux (cs).","W m-2",2,fluxsurf_sw1)
1676!           call writediagfi(ngrid,"fluxsurflwcs","lw back radiation (cs).","W m-2",2,fluxsurf_lw1)
1677
1678         ! if(ok_slab_ocean) then
1679         !    call writediagfi(ngrid,"GND","heat flux from ground","W m-2",2,fluxgrdocean)
1680         ! else
1681         call writediagfi(ngrid,"GND","heat flux from ground","W m-2",2,fluxgrd)
1682         ! endif
1683
1684         call writediagfi(ngrid,"DYN","dynamical heat input","W m-2",2,fluxdyn)
1685
1686      endif ! end of 'callrad'
1687
1688      if(enertest) then
1689
1690         if (calldifv) then
1691
1692            call writediagfi(ngrid,"q2","turbulent kinetic energy","J.kg^-1",3,q2)
1693            call writediagfi(ngrid,"sensibFlux","sensible heat flux","w.m^-2",2,sensibFlux)
1694
1695!             call writediagfi(ngrid,"dEzdiff","turbulent diffusion heating (-sensible flux)","w.m^-2",3,dEzdiff)
1696!             call writediagfi(ngrid,"dEdiff","integrated turbulent diffusion heating (-sensible flux)","w.m^-2",2,dEdiff)
1697!             call writediagfi(ngrid,"dEdiffs","In TurbDiff (correc rad+latent heat) surf nrj change","w.m^-2",2,dEdiffs)
1698
1699         endif
1700
1701         if (corrk) then
1702            call writediagfi(ngrid,"dEzradsw","radiative heating","w.m^-2",3,dEzradsw)
1703            call writediagfi(ngrid,"dEzradlw","radiative heating","w.m^-2",3,dEzradlw)
1704         endif
1705
1706!          if(watercond) then  !AF24: removed
1707
1708         if (generic_condensation) then
1709
1710            call writediagfi(ngrid,"genericconddE","heat from generic condensation","W m-2",2,genericconddE)
1711            call writediagfi(ngrid,"dt_generic_condensation","heating from generic condensation","K s-1",3,dt_generic_condensation)
1712
1713         endif
1714
1715      endif ! end of 'enertest'
1716
1717        ! Diagnostics of optical thickness
1718        ! Warning this is exp(-tau), I let you postproc with -log to have tau itself - JVO 19
1719        if (diagdtau) then
1720          do nw=1,L_NSPECTV
1721            write(str2,'(i2.2)') nw
1722            call writediagfi(ngrid,'dtauv'//str2,'Layer optical thickness attenuation in VI band '//str2,'',1,int_dtauv(:,nlayer:1:-1,nw))
1723          enddo
1724          do nw=1,L_NSPECTI
1725            write(str2,'(i2.2)') nw
1726            call writediagfi(ngrid,'dtaui'//str2,'Layer optical thickness attenuation in IR band '//str2,'',1,int_dtaui(:,nlayer:1:-1,nw))
1727          enddo
1728        endif
1729
1730
1731        ! Temporary inclusions for heating diagnostics.
1732        call writediagfi(ngrid,"zdtsw","SW heating","T s-1",3,zdtsw)
1733        call writediagfi(ngrid,"zdtlw","LW heating","T s-1",3,zdtlw)
1734        call writediagfi(ngrid,"dtrad","radiative heating","K s-1",3,dtrad)
1735        call writediagfi(ngrid,"zdtdyn","Dyn. heating","T s-1",3,zdtdyn)
1736
1737        ! For Debugging.
1738        !call writediagfi(ngrid,'rnat','Terrain type',' ',2,real(rnat))
1739        !call writediagfi(ngrid,'pphi','Geopotential',' ',3,pphi)
1740
1741
1742      ! Output aerosols.!AF: TODO: write haze aerosols
1743      ! if (igcm_n2_ice.ne.0.and.iaero_haze.ne.0) &
1744      !    call writediagfi(ngrid,'N2ice_reff','N2ice_reff','m',3,reffrad(1,1,iaero_haze))
1745      ! if (igcm_n2_ice.ne.0.and.iaero_haze.ne.0) &
1746      !    call writediagfi(ngrid,'N2ice_reffcol','N2ice_reffcol','um kg m^-2',2,reffcol(1,iaero_haze))
1747      ! if (igcm_h2o_ice.ne.0.and.iaero_h2o.ne.0) &  !AF24: removed
1748
1749      ! Output tracers.
1750      if (tracer) then
1751
1752         do iq=1,nq
1753            call writediagfi(ngrid,noms(iq),noms(iq),'kg/kg',3,zq(1,1,iq))
1754            call writediagfi(ngrid,trim(noms(iq))//'_surf',trim(noms(iq))//'_surf',  &
1755                             'kg m^-2',2,qsurf_hist(1,iq) )
1756            call writediagfi(ngrid,trim(noms(iq))//'_col',trim(noms(iq))//'_col',    &
1757                            'kg m^-2',2,qcol(1,iq) )
1758!          call writediagfi(ngrid,trim(noms(iq))//'_surf',trim(noms(iq))//'_surf',  &
1759!                          'kg m^-2',2,qsurf(1,iq) )
1760
1761            ! if(watercond.or.CLFvarying)then  !AF24: removed
1762
1763            if(generic_condensation)then
1764               call writediagfi(ngrid,"rneb_generic","GCS cloud fraction (generic condensation)"," ",3,rneb_generic)
1765               call writediagfi(ngrid,"CLF","GCS cloud fraction"," ",3,cloudfrac)
1766               call writediagfi(ngrid,"RH_generic","GCS relative humidity"," ",3,RH_generic)
1767            endif
1768
1769            ! if(generic_rain)then  !AF24: removed
1770            ! if((hydrology).and.(.not.ok_slab_ocean))then  !AF24: removed
1771
1772            call writediagfi(ngrid,"tau_col","Total aerosol optical depth","[]",2,tau_col)
1773
1774         enddo ! end of 'nq' loop
1775
1776       endif ! end of 'tracer'
1777
1778
1779      ! Output spectrum.
1780      if(specOLR.and.corrk)then
1781         call writediagspecIR(ngrid,"OLR3D","OLR(lon,lat,band)","W/m^2/cm^-1",3,OLR_nu)
1782         call writediagspecVI(ngrid,"OSR3D","OSR(lon,lat,band)","W/m^2/cm^-1",3,OSR_nu)
1783         call writediagspecVI(ngrid,"GSR3D","GSR(lon,lat,band)","W/m^2/cm^-1",3,GSR_nu)
1784      endif
1785
1786#else
1787   comm_HR_SW(1:ngrid,1:nlayer) = zdtsw(1:ngrid,1:nlayer)
1788   comm_HR_LW(1:ngrid,1:nlayer) = zdtlw(1:ngrid,1:nlayer)
1789   comm_ALBEQ(1:ngrid)=albedo_equivalent(1:ngrid)
1790   if (.not.calldifv) comm_LATENT_HF(:)=0.0
1791   ! if ((tracer).and.(water)) then  !AF24: removed
1792
1793   if ((tracer).and.(generic_condensation)) then
1794   ! .and.(.not. water)
1795
1796      ! If you have set generic_condensation (and not water) and you have set several GCS
1797      ! then the outputs given to WRF will be only the ones for the last generic tracer
1798      ! (Because it is rewritten every tracer in the loop)
1799      ! WRF can take only one moist tracer
1800
1801      do iq=1,nq
1802         call generic_tracer_index(nq,iq,igcm_generic_vap,igcm_generic_ice,call_ice_vap_generic)
1803
1804         if (call_ice_vap_generic) then ! to call only one time the ice/vap pair of a tracer
1805
1806            reffrad_generic_zeros_for_wrf(:,:) = 1.
1807
1808            comm_CLOUDFRAC(1:ngrid,1:nlayer) = cloudfrac(1:ngrid,1:nlayer)
1809            comm_TOTCLOUDFRAC(1:ngrid) = totcloudfrac(1:ngrid) !??????
1810            comm_SURFRAIN(1:ngrid) = zdqsrain_generic(1:ngrid,iq)
1811            comm_DQVAP(1:ngrid,1:nlayer) = pdq(1:ngrid,1:nlayer,igcm_generic_vap)
1812            comm_DQICE(1:ngrid,1:nlayer)=pdq(1:ngrid,1:nlayer,igcm_generic_ice)
1813            ! comm_H2OICE_REFF(1:ngrid,1:nlayer) = reffrad_generic_zeros_for_wrf(1:ngrid,1:nlayer) ! for now zeros !
1814            !comm_H2OICE_REFF(1:ngrid,1:nlayer) = 0*zdtrain_generic(1:ngrid,1:nlayer) ! for now zeros !
1815            comm_REEVAP(1:ngrid) = reevap_precip_generic(1:ngrid,iq)
1816            comm_DTRAIN(1:ngrid,1:nlayer) = zdtrain_generic(1:ngrid,1:nlayer)
1817            comm_DTLSC(1:ngrid,1:nlayer) = dt_generic_condensation(1:ngrid,1:nlayer)
1818            comm_RH(1:ngrid,1:nlayer) = RH_generic(1:ngrid,1:nlayer,iq)
1819
1820         endif
1821      end do ! do iq=1,nq loop on tracers
1822
1823   else
1824      comm_CLOUDFRAC(1:ngrid,1:nlayer)=0.
1825      comm_TOTCLOUDFRAC(1:ngrid)=0.
1826      comm_SURFRAIN(1:ngrid)=0.
1827      comm_DQVAP(1:ngrid,1:nlayer)=0.
1828      comm_DQICE(1:ngrid,1:nlayer)=0.
1829      ! comm_H2OICE_REFF(1:ngrid,1:nlayer)=0.
1830      comm_REEVAP(1:ngrid)=0.
1831      comm_DTRAIN(1:ngrid,1:nlayer)=0.
1832      comm_DTLSC(1:ngrid,1:nlayer)=0.
1833      comm_RH(1:ngrid,1:nlayer)=0.
1834
1835   endif ! if water, if generic_condensation, else
1836
1837   comm_FLUXTOP_DN(1:ngrid)=fluxtop_dn(1:ngrid)
1838   comm_FLUXABS_SW(1:ngrid)=fluxabs_sw(1:ngrid)
1839   comm_FLUXTOP_LW(1:ngrid)=fluxtop_lw(1:ngrid)
1840   comm_FLUXSURF_SW(1:ngrid)=fluxsurf_sw(1:ngrid)
1841   comm_FLUXSURF_LW(1:ngrid)=fluxsurf_lw(1:ngrid)
1842   comm_FLXGRD(1:ngrid)=fluxgrd(1:ngrid)
1843   sensibFlux(1:ngrid) = zflubid(1:ngrid) - capcal(1:ngrid)*zdtsdif(1:ngrid) !!! ????
1844   comm_HR_DYN(1:ngrid,1:nlayer) = zdtdyn(1:ngrid,1:nlayer)
1845
1846!      if (turb_resolved) then
1847!        open(17,file='lsf.txt',form='formatted',status='old')
1848!        rewind(17)
1849!        DO l=1,nlayer
1850!          read(17,*) lsf_dt(l),lsf_dq(l)
1851!        ENDDO
1852!        close(17)
1853!        do ig=1,ngrid
1854!          if ((tracer).and.(water)) then
1855!           pdq(ig,:,igcm_h2o_vap) = pdq(ig,:,igcm_h2o_vap) + lsf_dq(:)
1856!          endif
1857!          pdt(ig,:) = pdt(ig,:) + lsf_dt(:)
1858!          comm_HR_DYN(ig,:) = lsf_dt(:)
1859!        enddo
1860!      endif
1861#endif
1862
1863! XIOS outputs
1864#ifdef CPP_XIOS
1865      ! Send fields to XIOS: (NB these fields must also be defined as
1866      ! <field id="..." /> in context_lmdz_physics.xml to be correctly used)
1867      CALL send_xios_field("ls",zls)
1868
1869      CALL send_xios_field("ps",ps)
1870      CALL send_xios_field("area",cell_area)
1871      CALL send_xios_field("p",pplay)
1872      CALL send_xios_field("temperature",zt)
1873      CALL send_xios_field("u",zu)
1874      CALL send_xios_field("v",zv)
1875      CALL send_xios_field("omega",omega)
1876
1877!       IF (calltherm) THEN  !AF24: removed
1878      ! IF (water) THEN  !AF24: removed
1879
1880      CALL send_xios_field("ISR",fluxtop_dn)
1881      CALL send_xios_field("OLR",fluxtop_lw)
1882      CALL send_xios_field("ASR",fluxabs_sw)
1883
1884      if (specOLR .and. corrk) then
1885         call send_xios_field("OLR3D",OLR_nu)
1886         call send_xios_field("IR_Bandwidth",DWNI)
1887         call send_xios_field("VI_Bandwidth",DWNV)
1888         call send_xios_field("OSR3D",OSR_nu)
1889         call send_xios_field("GSR3D",GSR_nu)
1890      endif
1891
1892      if (lastcall.and.is_omp_master) then
1893        write(*,*) "physiq: call xios_context_finalize"
1894        call xios_context_finalize
1895      endif
1896#endif
1897
1898      if (check_physics_outputs) then
1899         ! Check the validity of updated fields at the end of the physics step
1900         call check_physics_fields("end of physiq:", zt, zu, zv, pplev, zq)
1901      endif
1902
1903      icount=icount+1
1904
1905      end subroutine physiq
1906
1907   end module physiq_mod
Note: See TracBrowser for help on using the repository browser.