source: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_write_mod.F90 @ 4648

Last change on this file since 4648 was 4647, checked in by idelkadi, 12 months ago

Implementation in the LMDZ code of the double call of the ECRAD radiative transfer code to estimate the 3D radiative effect of clouds.

  • This double call of Ecrad is controlled by the ok_3Deffect logic key.
  • If this key is enabled, 2 files of parameter configuration "namelists" for ECRAD are required at runtime: namelist_ecrad and namelist_ecrad_s2.
  • If this key is deactivated, the configuration and initialization part (reading namelist and netcdf files) is performed only once during simulation (1st call to ECRAD). Otherwise, configuration and initialization are performed each time Ecrad is called.
  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:keywords set to Id
File size: 111.8 KB
Line 
1!
2! $Id: phys_output_write_mod.F90 4647 2023-08-07 11:42:51Z idelkadi $
3!
4MODULE phys_output_write_mod
5
6  USE phytrac_mod, ONLY : d_tr_cl, d_tr_th, d_tr_cv, d_tr_lessi_impa, &
7       d_tr_lessi_nucl, d_tr_insc, d_tr_bcscav, d_tr_evapls, d_tr_ls,  &
8       d_tr_trsp, d_tr_sscav, d_tr_sat, d_tr_uscav, flux_tr_dry
9
10  ! Author: Abderrahmane IDELKADI (original include file)
11  ! Author: Laurent FAIRHEAD (transformation to module/subroutine)
12  ! Author: Ulysse GERARD (effective implementation)
13
14CONTAINS
15
16  ! ug Routine pour définir (lors du premier passage) ET sortir les variables
17  SUBROUTINE phys_output_write(itap, pdtphys, paprs, pphis, &
18       pplay, lmax_th, aerosol_couple,         &
19       ok_ade, ok_aie, ok_volcan, ivap, iliq, isol, ok_sync, &
20       ptconv, read_climoz, clevSTD, ptconvth, &
21       d_u, d_t, qx, d_qx, zmasse, flag_aerosol, flag_aerosol_strat, ok_cdnc)
22
23    ! This subroutine does the actual writing of diagnostics that were
24    ! defined and initialised in phys_output_mod.F90
25
26    USE dimphy, ONLY: klon, klev, klevp1
27    USE infotrac_phy, ONLY: nbtr, nqtot, nqo, type_trac, tracers, niso, ntiso
28    USE strings_mod,  ONLY: maxlen
29    USE mod_phys_lmdz_para, ONLY: is_north_pole_phy,is_south_pole_phy
30    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
31    USE time_phylmdz_mod, ONLY: day_step_phy, start_time, itau_phy
32    USE vertical_layers_mod, ONLY : ap, bp, aps, bps
33    USE phys_output_ctrlout_mod, ONLY: o_phis, o_aire, is_ter, is_lic, is_oce, &
34         o_longitude, o_latitude, &
35         o_Ahyb, o_Bhyb,o_Ahyb_bounds, o_Bhyb_bounds, &
36         o_Ahyb_mid, o_Bhyb_mid,o_Ahyb_mid_bounds, o_Bhyb_mid_bounds, &
37         is_ave, is_sic, o_contfracATM, o_contfracOR, &
38         o_aireTER, o_flat, o_slp, o_ptstar, o_pt0, o_tsol, &
39         o_t2m, o_t2m_min, o_t2m_max, &
40         o_t2m_min_mon, o_t2m_max_mon, &
41         o_nt2mout, o_nt2moutfg, &
42         o_nq2mout, o_nq2moutfg, &
43         o_nu2mout, o_nu2moutfg, &
44         o_q2m, o_ustar, o_u10m, o_v10m, &
45         o_wind10m, o_wind10max, o_wind100m, o_gusts, o_sicf, &
46         o_loadfactor_wind_onshore, o_loadfactor_wind_offshore, &
47         o_psol, o_mass, o_qsurf, o_qsol, &
48         o_precip, o_rain_fall, o_rain_con, o_ndayrain, o_plul, o_pluc, o_plun, &
49         o_snow, o_msnow, o_fsnow, o_evap, o_ep,o_epmax_diag, & ! epmax_cape
50         o_tops, o_tops0, o_topl, o_topl0, &
51         o_SWupTOA, o_SWupTOAclr, o_SWupTOAcleanclr, o_SWdnTOA, o_fdiffSWdnSFC, &
52         o_SWdnTOAclr, o_nettop, o_SWup200, &
53         o_SWup200clr, o_SWdn200, o_SWdn200clr, &
54         o_LWup200, o_LWup200clr, o_LWdn200, &
55         o_LWdn200clr, o_sols, o_sols0, &
56         o_soll, o_radsol, o_soll0, o_SWupSFC, &
57         o_SWupSFCclr, o_SWupSFCcleanclr, o_SWdnSFC, o_SWdnSFCclr, o_SWdnSFCcleanclr, &
58         o_LWupSFC, o_LWdnSFC, o_LWupSFCclr, &
59         o_LWdnSFCclr, o_LWupTOAcleanclr, o_LWdnSFCcleanclr, o_bils, o_bils_diss, &
60         o_bils_ec,o_bils_ech, o_bils_tke, o_bils_kinetic, &
61         o_bils_latent, o_bils_enthalp, o_sens, &
62         o_fder, o_ffonte, o_fqcalving, o_fqfonte, o_mrroli, o_runofflic, &
63         o_taux, o_tauy, o_snowsrf, o_qsnow, &
64         o_snowhgt, o_toice, o_sissnow, o_runoff, &
65         o_albslw3, o_pourc_srf, o_fract_srf, &
66         o_taux_srf, o_tauy_srf, o_tsol_srf, &
67         o_evappot_srf, o_ustar_srf, o_u10m_srf, &
68         o_v10m_srf, o_t2m_srf, o_evap_srf, &
69         o_sens_srf, o_lat_srf, o_flw_srf, &
70         o_fsw_srf, o_wbils_srf, o_wbilo_srf, &
71         o_wevap_srf, o_wrain_srf, o_wsnow_srf, &
72         o_tke_srf, o_tke_max_srf,o_dltpbltke_srf, o_wstar, &
73         o_l_mixmin,o_l_mix, &
74         o_cdrm, o_cdrh, o_cldl, o_cldm, o_cldh, &
75         o_cldt, o_JrNt, o_cldljn, o_cldmjn, &
76         o_cldhjn, o_cldtjn, o_cldq, o_lwp, o_iwp, &
77         o_ue, o_ve, o_uq, o_vq, o_cape, o_pbase, &
78         o_uwat, o_vwat, &
79         o_ptop, o_fbase, o_plcl, o_plfc, &
80         o_wbeff, o_convoccur, o_cape_max, o_upwd, o_ep,o_epmax_diag, &
81         o_Mipsh, o_Ma, &
82         o_dnwd, o_dnwd0, o_ftime_deepcv, o_ftime_con, o_mc, &
83         o_prw, o_prlw, o_prsw, o_s_pblh, o_s_pblt, o_s_lcl, &
84         o_s_therm, o_uSTDlevs, o_vSTDlevs, &
85         o_wSTDlevs, o_zSTDlevs, o_qSTDlevs, &
86         o_tSTDlevs, epsfra, o_t_oce_sic, &
87         o_ale_bl, o_alp_bl, o_ale_wk, o_alp_wk, &
88         o_dtvdf_x    , o_dtvdf_w    , o_dqvdf_x    , o_dqvdf_w    , &
89         o_sens_x     , o_sens_w     , o_flat_x     , o_flat_w     , &
90         o_delta_tsurf, o_delta_tsurf_srf, &
91         o_cdragh_x   , o_cdragh_w   , o_cdragm_x   , o_cdragm_w   , &
92         o_kh         , o_kh_x       , o_kh_w       , &
93         o_ale, o_alp, o_cin, o_WAPE, o_wake_h, o_cv_gen, o_wake_dens, &
94         o_wake_s, o_wake_deltat, o_wake_deltaq, &
95         o_wake_omg, o_dtwak, o_dqwak, o_dqwak2d, o_Vprecip, &
96         o_qtaa, o_Clwaa, &
97         o_ftd, o_fqd, o_wdtrainA, o_wdtrainS, o_wdtrainM, &
98         o_n2, o_s2, o_proba_notrig, &
99         o_random_notrig, o_ale_bl_stat, &
100         o_ale_bl_trig, o_alp_bl_det, &
101         o_alp_bl_fluct_m, o_alp_bl_fluct_tke, &
102         o_alp_bl_conv, o_alp_bl_stat, &
103         o_slab_qflux, o_tslab, o_slab_bils, &
104         o_slab_bilg, o_slab_sic, o_slab_tice, &
105         o_slab_hdiff, o_slab_ekman, o_slab_gm,  &
106         o_weakinv, o_dthmin, o_cldtau, &
107         o_cldemi, o_pr_con_l, o_pr_con_i, &
108         o_pr_lsc_l, o_pr_lsc_i, o_re, o_fl, &
109         o_rh2m, &
110         o_qsat2m, o_tpot, o_tpote, o_SWnetOR, &
111         o_LWdownOR, o_snowl, &
112         o_solldown, o_dtsvdfo, o_dtsvdft, &
113         o_dtsvdfg, o_dtsvdfi, o_z0m, o_z0h,  o_od443aer, o_od550aer, &
114         o_dryod550aer, o_od865aer, o_abs550aer, o_od550lt1aer, &
115         o_sconcso4, o_sconcno3, o_sconcoa, o_sconcbc, &
116         o_sconcss, o_sconcdust, o_concso4, o_concno3, &
117         o_concoa, o_concbc, o_concss, o_concdust, &
118         o_loadso4, o_loadoa, o_loadbc, o_loadss, &
119         o_loaddust, o_loadno3, o_tausumaero, &
120         o_drytausumaero, o_tausumaero_lw, &
121         o_topswad, o_topswad0, o_solswad, o_solswad0, &
122         o_toplwad, o_toplwad0, o_sollwad, o_sollwad0, &
123         o_swtoaas_nat, o_swsrfas_nat, &
124         o_swtoacs_nat, o_swtoaas_ant, &
125         o_swsrfas_ant, o_swtoacs_ant, &
126         o_swsrfcs_ant, o_swtoacf_nat, &
127         o_swsrfcf_nat, o_swtoacf_ant, &
128         o_swsrfcs_nat, o_swsrfcf_ant, &
129         o_swtoacf_zero, o_swsrfcf_zero, &
130         o_topswai, o_solswai, o_toplwai, o_sollwai, o_scdnc, &
131         o_cldncl, o_reffclws, o_reffclwc, o_solbnd, o_stratomask,&
132         o_cldnvi, o_lcc, o_lcc3d, o_lcc3dcon, &
133         o_lcc3dstra, o_icc3dcon, o_icc3dstra, &
134         o_cldicemxrat, o_cldwatmxrat, o_reffclwtop, o_ec550aer, &
135         o_lwcon, o_iwcon, o_temp, o_theta, &
136         o_ovapinit, o_ovap, o_oliq, o_ocond, o_geop, &
137         o_vitu, o_vitv, o_vitw, o_pres, o_paprs, &
138         o_zfull, o_zhalf, o_rneb, o_rnebjn, o_rnebcon, &
139         o_rnebls, o_rneblsvol, o_rhum, o_rhl, o_rhi, o_ozone, o_ozone_light, &
140         o_duphy, o_dtphy, o_dqphy, o_dqphy2d, o_dqlphy, o_dqlphy2d, &
141         o_dqsphy, o_dqsphy2d, o_albe_srf, o_z0m_srf, o_z0h_srf, &
142         o_ages_srf, o_snow_srf, o_alb1, o_alb2, o_tke, o_tke_dissip, &
143         o_tke_max, o_kz, o_kz_max, o_clwcon, &
144         o_dtdyn, o_dqdyn, o_dqdyn2d, o_dqldyn, o_dqldyn2d, &
145         o_dqsdyn, o_dqsdyn2d, o_dudyn, o_dvdyn, &
146         o_dtcon, o_tntc, o_ducon, o_dvcon, &
147         o_dqcon, o_dqcon2d, o_tnhusc, o_tnhusc, o_dtlsc, &
148         o_dtlschr, o_dqlsc, o_dqlsc2d, o_beta_prec, &
149         o_dtlscth, o_dtlscst, o_dqlscth, o_dqlscth2d, &
150         o_dqlscst, o_dqlscst2d, o_plulth, o_plulst, &
151         o_ptconvth, o_lmaxth, o_dtvdf, &
152         o_dtdis, o_dqvdf, o_dqvdf2d, o_dteva, o_dqeva, o_dqeva2d, &
153         o_ptconv, o_ratqs, o_dtthe, &
154         o_duthe, o_dvthe, o_ftime_th, &
155         o_f_th, o_e_th, o_w_th, o_q_th, &
156         o_a_th, o_cloudth_sth, o_cloudth_senv, &
157         o_cloudth_sigmath, o_cloudth_sigmaenv, &
158         o_d_th, o_f0_th, o_zmax_th, &
159         o_dqthe, o_dqthe2d, o_dtajs, o_dqajs, o_dqajs2d, o_dtswr, &
160         o_dtsw0, o_dtlwr, o_dtlw0, o_dtec, &
161         o_duvdf, o_dvvdf, o_duoro, o_dvoro, &
162         o_dtoro, o_dulif, o_dvlif, o_dtlif, &
163         o_du_gwd_hines, o_dv_gwd_hines, o_dthin, o_dqch4, o_rsu, &
164         o_du_gwd_front, o_dv_gwd_front, &
165         o_east_gwstress, o_west_gwstress, &
166         o_rsd, o_rlu, o_rld, o_rsucs, o_rsdcs, o_rsucsaf, o_rsdcsaf, &
167         o_rlucs, o_rldcs, o_tnt, o_tntr, &
168         o_tntscpbl, o_tnhus, o_tnhusscpbl, &
169         o_evu, o_h2o, o_mcd, o_dmc, o_ref_liq, &
170         o_ref_ice, o_rsut4co2, o_rlut4co2, &
171         o_rsutcs4co2, o_rlutcs4co2, o_rsu4co2, &
172         o_rlu4co2, o_rsucs4co2, o_rlucs4co2, &
173         o_rsd4co2, o_rld4co2, o_rsdcs4co2, &
174         o_rldcs4co2, o_tnondef, o_ta, o_zg, &
175         o_hus, o_hur, o_ua, o_va, o_wap, &
176         o_psbg, o_tro3, o_tro3_daylight, &
177         o_uxv, o_vxq, o_vxT, o_wxq, o_vxphi, &
178         o_wxT, o_uxu, o_vxv, o_TxT, o_trac, &
179         o_dtr_vdf, o_dtr_the, o_dtr_con, &
180         o_dtr_lessi_impa, o_dtr_lessi_nucl, &
181         o_dtr_insc, o_dtr_bcscav, o_dtr_evapls, &
182         o_dtr_ls, o_dtr_trsp, o_dtr_sscav, o_dtr_dry, &
183         o_dtr_sat, o_dtr_uscav, o_trac_cum, o_du_gwd_rando, o_dv_gwd_rando, &
184         o_ustr_gwd_hines,o_vstr_gwd_hines,o_ustr_gwd_rando,o_vstr_gwd_rando, &
185         o_ustr_gwd_front,o_vstr_gwd_front, &
186         o_sens_prec_liq_oce, o_sens_prec_liq_sic, &
187         o_sens_prec_sol_oce, o_sens_prec_sol_sic, &
188         o_lat_prec_liq_oce, o_lat_prec_liq_sic, &
189         o_lat_prec_sol_oce, o_lat_prec_sol_sic, &
190         o_sza, &
191! Marine
192         o_map_prop_hc, o_map_prop_hist, o_map_emis_hc, o_map_iwp_hc, &
193         o_map_deltaz_hc, o_map_pcld_hc, o_map_tcld_hc, &
194         o_map_emis_hist, o_map_iwp_hist, o_map_deltaz_hist, &
195         o_map_rad_hist, &
196         o_map_emis_Cb, o_map_pcld_Cb, o_map_tcld_Cb, &
197         o_map_emis_ThCi, o_map_pcld_ThCi, o_map_tcld_ThCi, &
198         o_map_emis_Anv, o_map_pcld_Anv, o_map_tcld_Anv, &
199         o_map_ntot, o_map_hc,o_map_hist,o_map_Cb,o_map_ThCi,o_map_Anv, &
200#ifdef ISO
201! Isotopes
202         o_xtprecip,o_xtplul,o_xtpluc,o_xtovap,o_xtoliq,o_xtcond, &
203         o_xtevap,o_dxtdyn,o_dxtldyn,o_dxtcon,o_dxtlsc,o_dxteva, &
204         o_dxtajs,o_dxtvdf,o_dxtthe, o_dxtch4, &
205         o_dxtprod_nucl,o_dxtcosmo,o_dxtdecroiss, &
206#endif
207! Tropopause
208         o_alt_tropo, &
209         o_p_tropopause, o_z_tropopause, o_t_tropopause,  &
210         o_col_O3_strato, o_col_O3_tropo,                 &
211!--aviation & supersaturation
212         o_oclr, o_ocld, o_oss, o_ovc, o_rnebss, o_rnebclr, o_rnebseri, o_gammass, &
213         o_N1_ss, o_N2_ss, o_qsatl, o_qsats, &
214         o_drnebsub, o_drnebcon, o_drnebtur, o_drnebavi, o_flight_m, o_flight_h2o, &
215         o_Tcontr, o_qcontr, o_qcontr2, o_fcontrN, o_fcontrP, &
216!--interactive CO2
217         o_flx_co2_ocean, o_flx_co2_ocean_cor, &
218         o_flx_co2_land, o_flx_co2_land_cor, &
219         o_flx_co2_ff, o_flx_co2_bb, &
220         o_delta_sst, o_delta_sal, o_ds_ns, o_dt_ns, o_dter, o_dser, o_tkt, &
221         o_tks, o_taur, o_sss
222
223#ifdef CPP_StratAer
224    USE phys_output_ctrlout_mod, ONLY:  &
225         o_budg_3D_nucl, o_budg_3D_cond_evap, o_budg_3D_ocs_to_so2, o_budg_3D_so2_to_h2so4, &
226         o_budg_sed_part, o_R2SO4, o_OCS_lifetime, o_SO2_lifetime, &
227         o_budg_3D_backgr_ocs, o_budg_3D_backgr_so2, &
228         o_budg_dep_dry_ocs, o_budg_dep_wet_ocs, &
229         o_budg_dep_dry_so2, o_budg_dep_wet_so2, &
230         o_budg_dep_dry_h2so4, o_budg_dep_wet_h2so4, &
231         o_budg_dep_dry_part, o_budg_dep_wet_part, &
232         o_budg_emi_ocs, o_budg_emi_so2, o_budg_emi_h2so4, o_budg_emi_part, &
233         o_budg_ocs_to_so2, o_budg_so2_to_h2so4, o_budg_h2so4_to_part, &
234         o_surf_PM25_sulf, o_ext_strat_550, o_tau_strat_550, &
235         o_vsed_aer, o_tau_strat_1020, o_ext_strat_1020, o_f_r_wet
236#endif
237
238#ifdef CPP_ECRAD
239    USE phys_output_ctrlout_mod, ONLY:  &
240         o_soll0_s2,o_soll_s2,o_sols0_s2,o_sols_s2, &
241         o_topl0_s2,o_topl_s2,o_tops0_s2,o_tops_s2
242#endif
243
244    USE ice_sursat_mod, ONLY: flight_m, flight_h2o
245   
246    USE phys_output_ctrlout_mod, ONLY: o_heat_volc, o_cool_volc !NL
247    USE phys_state_var_mod, ONLY: heat_volc, cool_volc !NL
248
249    USE phys_state_var_mod, ONLY: pctsrf, rain_fall, snow_fall, &
250         qsol, z0m, z0h, fevap, agesno, &
251         nday_rain, rain_con, snow_con, &
252         topsw, toplw, toplw0, swup, swdn, solswfdiff, &
253         topsw0, swupc0, swdnc0, swup0, swdn0, SWup200, SWup200clr, &
254         SWdn200, SWdn200clr, LWup200, LWup200clr, &
255         LWdn200, LWdn200clr, solsw, solsw0, sollw, &
256         radsol, swradcorr, sollw0, sollwdown, sollw, gustiness, &
257         sollwdownclr, lwdnc0, lwdn0, ftsol, ustar, u10m, &
258         v10m, pbl_tke, wake_delta_pbl_TKE, &
259         delta_tsurf, &
260         wstar, cape, ema_pcb, ema_pct, &
261         ema_cbmf, Mipsh, Ma, fm_therm, ale_bl, alp_bl, ale, &
262         alp, cin, wake_pe, wake_dens, cv_gen, wake_s, wake_deltat, &
263         wake_deltaq, ftd, fqd, ale_bl_trig, albsol1, &
264         ale_wake, ale_bl_stat, &
265         rnebcon, wo, falb1, albsol2, coefh, clwcon0, &
266         ratqs, entr_therm, zqasc, detr_therm, f0, &
267         lwup, lwdn, lwupc0, lwup0, coefm, &
268         swupp, lwupp, swupc0p, swup0p, lwupc0p, lwup0p, swdnp, lwdnp, &
269         swdnc0p, swdn0p, lwdnc0p, lwdn0p, tnondef, O3sumSTD, uvsumSTD, &
270         vqsumSTD, vTsumSTD, O3daysumSTD, wqsumSTD, &
271         vphisumSTD, wTsumSTD, u2sumSTD, v2sumSTD, &
272         T2sumSTD, nlevSTD, du_gwd_rando, du_gwd_front, &
273         ulevSTD, vlevSTD, wlevSTD, philevSTD, qlevSTD, tlevSTD, &
274         rhlevSTD, O3STD, O3daySTD, uvSTD, vqSTD, vTSTD, wqSTD, vphiSTD, &
275         wTSTD, u2STD, v2STD, T2STD, missing_val_nf90, delta_sal, ds_ns, &
276#ifdef ISO
277        xtrain_con, xtsnow_con, xtrain_fall, xtsnow_fall, &
278#endif
279         dt_ns, delta_sst, dter, dser
280
281! AI 08 2023 pour ECRAD 3Deffect
282#ifdef CPP_ECRAD
283    USE phys_state_var_mod, ONLY: &
284        sollw0_s2,sollw_s2,solsw0_s2,solsw_s2, &
285        toplw0_s2,toplw_s2,topsw0_s2,topsw_s2
286#endif
287
288    USE phys_local_var_mod, ONLY: zxfluxlat, slp, ptstar, pt0, zxtsol, zt2m, &
289         zn2mout, t2m_min_mon, t2m_max_mon, evap, &
290         l_mixmin,l_mix, tke_dissip, &
291         zu10m, zv10m, zq2m, zustar, zxqsurf, &
292         rain_lsc, rain_num, snow_lsc, bils, sens, fder, &
293         zxffonte, zxfqcalving, zxfqfonte, zxrunofflic, fluxu, &
294         fluxv, zxsnow, qsnow, snowhgt, to_ice, &
295         sissnow, runoff, albsol3_lic, evap_pot, &
296         t2m, fluxt, fluxlat, fsollw, fsolsw, &
297         wfbils, wfbilo, wfevap, wfrain, wfsnow, &
298         cdragm, cdragh, cldl, cldm, &
299         cldh, cldt, JrNt,   & ! only output names: cldljn,cldmjn,cldhjn,cldtjn
300         cldq, flwp, fiwp, ue, ve, uq, vq, &
301         uwat, vwat, &
302         rneb_seri, d_rneb_dyn, &
303         plcl, plfc, wbeff, convoccur, upwd, dnwd, dnwd0, prw, prlw, prsw, &
304         s_pblh, s_pblt, s_lcl, s_therm, uwriteSTD, &
305         vwriteSTD, wwriteSTD, phiwriteSTD, qwriteSTD, &
306         twriteSTD, alp_wake, &
307!!         dtvdf_x    ,dtvdf_w    ,dqvdf_x    ,dqvdf_w    , &
308         d_t_vdf_x    ,d_t_vdf_w    ,d_q_vdf_x    ,d_q_vdf_w    , &
309         sens_x     ,sens_w     ,zxfluxlat_x,zxfluxlat_w, &
310         cdragh_x   ,cdragh_w   ,cdragm_x   ,cdragm_w   , &
311         kh         ,kh_x       ,kh_w       , &
312         wake_h, &
313         wake_omg, d_t_wake, d_q_wake, Vprecip, qtaa, Clw, &
314         wdtrainA, wdtrainS, wdtrainM, n2, s2, proba_notrig, &
315         random_notrig, &
316         qclr, qcld, qss, qvc, rnebclr, rnebss, gamma_ss, &
317         N1_ss, N2_ss, zqsatl, zqsats, &
318         Tcontr, qcontr, qcontr2, fcontrN, fcontrP, &
319         drneb_sub, drneb_con, drneb_tur, drneb_avi, &
320         alp_bl_det, alp_bl_fluct_m, alp_bl_conv, &
321         alp_bl_stat, alp_bl_fluct_tke, slab_wfbils, &
322         weak_inversion, dthmin, cldtau, cldemi, &
323         pmflxr, pmflxs, prfl, psfl, re, fl, rh2m, &
324         qsat2m, tpote, tpot, d_ts, od443aer, od550aer, dryod550aer, &
325         od865aer, abs550aer, od550lt1aer, sconcso4, sconcno3, &
326         sconcoa, sconcbc, sconcss, sconcdust, concso4, concno3, &
327         concoa, concbc, concss, concdust, loadso4, &
328         loadoa, loadbc, loadss, loaddust, loadno3, tausum_aero, drytausum_aero, &
329         topswad_aero, topswad0_aero, solswad_aero, &
330         solswad0_aero, topsw_aero, solsw_aero, &
331         topsw0_aero, solsw0_aero, topswcf_aero, &
332         solswcf_aero, topswai_aero, solswai_aero, &
333         toplwad_aero, toplwad0_aero, sollwad_aero, &
334         sollwad0_aero, toplwai_aero, sollwai_aero, &
335         scdnc, cldncl, reffclws, reffclwc, cldnvi, stratomask,&
336         lcc, lcc3d, lcc3dcon, lcc3dstra, &
337         icc3dcon, icc3dstra, zfice, reffclwtop, &
338         ec550aer, flwc, fiwc, t_seri, theta, q_seri, &
339         ql_seri, qs_seri, tr_seri, &
340         zphi, u_seri, v_seri, omega, cldfra, &
341         rneb, rnebjn, rneblsvol, zx_rh, zx_rhl, zx_rhi, d_t_dyn,  &
342         d_q_dyn,  d_ql_dyn, d_qs_dyn, &
343         d_q_dyn2d,  d_ql_dyn2d, d_qs_dyn2d, &
344         d_u_dyn, d_v_dyn, d_t_con, d_t_ajsb, d_t_ajs, &
345         d_u_ajs, d_v_ajs, &
346         d_u_con, d_v_con, d_q_con, d_q_ajs, d_t_lsc, &
347         d_t_lwr,d_t_lw0,d_t_swr,d_t_sw0, &
348         d_t_eva, d_q_lsc, beta_prec, d_t_lscth, &
349         d_t_lscst, d_q_lscth, d_q_lscst, plul_th, &
350         plul_st, d_t_vdf, d_t_diss, d_q_vdf, d_q_eva, &
351         zw2, fraca, zmax_th, d_q_ajsb, d_t_ec, d_u_vdf, &
352         d_v_vdf, d_u_oro, d_v_oro, d_t_oro, d_u_lif, &
353         d_v_lif, d_t_lif, du_gwd_hines, dv_gwd_hines, d_t_hin, &
354         dv_gwd_rando, dv_gwd_front, &
355         east_gwstress, west_gwstress, &
356         d_q_ch4, pmfd, pmfu, ref_liq, ref_ice, rhwriteSTD, &
357#ifdef ISO
358        xtrain_lsc, xtsnow_lsc, xt_seri, xtl_seri,xts_seri,xtevap, &
359        d_xt_dyn,d_xtl_dyn,d_xt_con,d_xt_vdf,d_xt_ajsb, &
360        d_xt_lsc,d_xt_eva,d_xt_ch4, &
361        d_xt_ajs, d_xt_ajsb, &
362        d_xt_prod_nucl,d_xt_cosmo,d_xt_decroiss, &
363#endif
364         ep, epmax_diag, &  ! epmax_cape
365         p_tropopause, t_tropopause, z_tropopause
366
367#ifdef CPP_StratAer
368    USE phys_local_var_mod, ONLY:  &
369         budg_3D_nucl, budg_3D_cond_evap, budg_3D_ocs_to_so2, budg_3D_so2_to_h2so4, &
370         budg_sed_part, R2SO4, OCS_lifetime, SO2_lifetime, &
371         budg_3D_backgr_ocs, budg_3D_backgr_so2, &
372         budg_dep_dry_ocs, budg_dep_wet_ocs, &
373         budg_dep_dry_so2, budg_dep_wet_so2, &
374         budg_dep_dry_h2so4, budg_dep_wet_h2so4, &
375         budg_dep_dry_part, budg_dep_wet_part, &
376         budg_emi_ocs, budg_emi_so2, budg_emi_h2so4, budg_emi_part, &
377         budg_ocs_to_so2, budg_so2_to_h2so4, budg_h2so4_to_part, &
378         surf_PM25_sulf, tau_strat_550, tausum_strat, &
379         vsed_aer, tau_strat_1020, f_r_wet
380#endif
381
382    USE carbon_cycle_mod, ONLY: fco2_ff, fco2_bb, fco2_land, fco2_ocean
383    USE carbon_cycle_mod, ONLY: fco2_ocean_cor, fco2_land_cor
384
385    USE phys_output_var_mod, ONLY: vars_defined, snow_o, zfra_o, bils_diss, &
386         bils_ec,bils_ech, bils_tke, bils_kinetic, bils_latent, bils_enthalp, &
387         itau_con, nfiles, clef_files, nid_files, dryaod_diag, &
388         zustr_gwd_hines, zvstr_gwd_hines,zustr_gwd_rando, zvstr_gwd_rando, &
389         zustr_gwd_front, zvstr_gwd_front, sza_o,    &
390         sens_prec_liq_o, sens_prec_sol_o, lat_prec_liq_o, lat_prec_sol_o, &
391         cloudth_sth,cloudth_senv,cloudth_sigmath,cloudth_sigmaenv, &
392! Marine
393         map_prop_hc, map_prop_hist, &
394         map_emis_hc,map_iwp_hc,map_deltaz_hc,&
395         map_pcld_hc,map_tcld_hc,&
396         map_emis_hist,map_iwp_hist,map_deltaz_hist,&
397         map_rad_hist,&
398         map_ntot,map_hc,map_hist,&
399         map_Cb,map_ThCi,map_Anv,&
400         map_emis_Cb,map_pcld_Cb,map_tcld_Cb,&
401         map_emis_ThCi,map_pcld_ThCi,map_tcld_ThCi,&
402         map_emis_Anv,map_pcld_Anv,map_tcld_Anv, &
403         alt_tropo, &
404!Ionela
405         ok_4xCO2atm, tkt, tks, taur, sss
406
407    USE ocean_slab_mod, ONLY: nslay, tslab, slab_bilg, tice, seaice, &
408        slab_ekman,slab_hdiff,slab_gm,dt_ekman, dt_hdiff, dt_gm, dt_qflux
409    USE pbl_surface_mod, ONLY: snow
410    USE indice_sol_mod, ONLY: nbsrf
411#ifdef ISO
412    USE isotopes_mod, ONLY: iso_HTO
413#endif
414    USE geometry_mod, ONLY: cell_area, latitude_deg, longitude_deg
415    USE surface_data, ONLY: type_ocean, version_ocean, ok_veget, landice_opt
416    USE aero_mod, ONLY: naero_tot, id_STRAT_phy
417    USE ioipsl, ONLY: histend, histsync
418    USE iophy, ONLY: set_itau_iophy, histwrite_phy
419    USE netcdf, ONLY: nf90_fill_real
420    USE print_control_mod, ONLY: prt_level,lunout
421
422
423#ifdef CPP_XIOS
424    ! ug Pour les sorties XIOS
425    USE xios
426    USE wxios, ONLY: wxios_closedef, missing_val, wxios_set_context
427#endif
428    USE phys_cal_mod, ONLY : mth_len
429
430#ifdef CPP_RRTM
431    USE YOESW, ONLY : RSUN
432#endif
433    USE tracinca_mod, ONLY: config_inca
434    use config_ocean_skin_m, only: activate_ocean_skin
435
436    USE vertical_layers_mod, ONLY: presnivs
437
438    IMPLICIT NONE
439
440    INCLUDE "clesphys.h"
441    INCLUDE "alpale.h"
442    INCLUDE "compbl.h"
443    INCLUDE "YOMCST.h"
444
445    ! Input
446    INTEGER :: itap, ivap, iliq, isol, read_climoz
447    INTEGER, DIMENSION(klon) :: lmax_th
448    LOGICAL :: aerosol_couple, ok_sync
449    LOGICAL :: ok_ade, ok_aie, ok_volcan
450    LOGICAL, DIMENSION(klon, klev) :: ptconv, ptconvth
451    REAL :: pdtphys
452    CHARACTER (LEN=4), DIMENSION(nlevSTD) :: clevSTD
453    REAL, DIMENSION(klon,nlevSTD) :: zx_tmp_fi3d_STD
454    REAL, DIMENSION(klon) :: pphis
455    REAL, DIMENSION(klon, klev) :: pplay, d_u, d_t
456    REAL, DIMENSION(klon, klev+1) :: paprs
457    REAL, DIMENSION(klon,klev,nqtot) :: qx, d_qx
458    REAL, DIMENSION(klon, klev) :: zmasse
459    INTEGER :: flag_aerosol_strat
460    INTEGER :: flag_aerosol
461    LOGICAL :: ok_cdnc
462    REAL, DIMENSION(3) :: freq_moyNMC
463
464    ! Local
465    INTEGER :: itau_w
466    INTEGER :: i, iinit, iinitend=1, iff, iq, nsrf, k, ll, naero
467    REAL, DIMENSION (klon) :: zx_tmp_fi2d, zpt_conv2d, wind100m
468    REAL, DIMENSION (klon,klev) :: zx_tmp_fi3d, zpt_conv
469    REAL, DIMENSION (klon,klev+1) :: zx_tmp_fi3d1
470    REAL, DIMENSION (klon,NSW) :: zx_tmp_fi3dsp
471    CHARACTER (LEN=4)              :: bb2
472    INTEGER, DIMENSION(nbp_lon*nbp_lat)  :: ndex2d
473    INTEGER, DIMENSION(nbp_lon*nbp_lat*klev) :: ndex3d
474    REAL, PARAMETER :: dobson_u = 2.1415e-05 ! Dobson unit, in kg m-2
475!   REAL, PARAMETER :: missing_val=nf90_fill_real
476    REAL, DIMENSION(klev+1,2) :: Ahyb_bounds, Bhyb_bounds
477    REAL, DIMENSION(klev,2) :: Ahyb_mid_bounds, Bhyb_mid_bounds
478    INTEGER :: ilev
479    INTEGER, SAVE :: kmax_100m
480!$OMP THREADPRIVATE(kmax_100m)
481    REAL :: x
482#ifndef CPP_XIOS
483    REAL :: missing_val
484#endif
485    REAL, PARAMETER :: un_jour=86400.
486    INTEGER :: ISW, itr, ixt, it
487    CHARACTER*1 ch1
488    CHARACTER(LEN=maxlen) :: varname, dn
489
490#ifdef CPP_XIOS
491    TYPE(xios_fieldgroup) :: group_handle
492    TYPE(xios_field) :: child
493#endif
494#ifdef CPP_StratAer
495    LOGICAL, PARAMETER :: debug_strataer=.FALSE.
496    CHARACTER(LEN=maxlen) :: unt
497#endif
498    REAL,DIMENSION(klon,klev) :: z, dz
499    REAL,DIMENSION(klon)      :: zrho, zt
500
501    ! On calcul le nouveau tau:
502    itau_w = itau_phy + itap
503    ! On le donne à iophy pour que les histwrite y aient accès:
504    CALL set_itau_iophy(itau_w)
505
506 !   IF (.NOT.vars_defined) THEN
507       iinitend = 1
508 !   ELSE
509 !      iinitend = 1
510 !   ENDIF
511
512#ifdef CPP_XIOS
513    CALL wxios_set_context
514#endif
515
516#ifndef CPP_XIOS
517    missing_val=missing_val_nf90
518#endif
519
520    IF (.NOT.vars_defined) THEN
521      kmax_100m=1
522      DO k=1, klev-1
523        IF (presnivs(k).GT.0.97*101325.) kmax_100m = k !--finding out max level for 100 m with a good margin
524      ENDDO
525    ENDIF
526
527    Ahyb_bounds(1,1) = 0.
528    Ahyb_bounds(1,2) = aps(1)
529    Bhyb_bounds(1,1) = 1.
530    Bhyb_bounds(1,2) = bps(1)   
531    DO ilev=2,klev
532      Ahyb_bounds(ilev,1) = aps(ilev-1)
533      Ahyb_bounds(ilev,2) = aps(ilev)
534      Bhyb_bounds(ilev,1) = bps(ilev-1)
535      Bhyb_bounds(ilev,2) = bps(ilev)
536    ENDDO
537     Ahyb_bounds(klev+1,1) = aps(klev)
538     Ahyb_bounds(klev+1,2) = 0.
539     Bhyb_bounds(klev+1,1) = bps(klev)
540     Bhyb_bounds(klev+1,2) = 0.
541
542    DO ilev=1, klev
543      Ahyb_mid_bounds(ilev,1) = ap(ilev)
544      Ahyb_mid_bounds(ilev,2) = ap(ilev+1)
545      Bhyb_mid_bounds(ilev,1) = bp(ilev)
546      Bhyb_mid_bounds(ilev,2) = bp(ilev+1)
547    END DO
548
549#ifdef CPP_XIOS
550#ifdef CPP_StratAer
551!$OMP MASTER
552   IF (.NOT.vars_defined) THEN
553          !On ajoute les variables 3D traceurs par l interface fortran
554          CALL xios_get_handle("fields_strataer_trac_3D", group_handle)
555          ! On boucle sur les traceurs pour les ajouter au groupe puis fixer les attributs
556          DO iq = 1, nqtot
557            IF(.NOT.(tracers(iq)%isAdvected .AND. tracers(iq)%isInPhysics)) CYCLE
558            dn = 'd'//TRIM(tracers(iq)%name)//'_'
559            WRITE (lunout,*) 'XIOS var=', nqo, iq, nqtot, tracers(iq)%name
560
561            unt = "kg kg-1"
562            varname=trim(tracers(iq)%name)
563            CALL xios_add_child(group_handle, child, varname)
564            CALL xios_set_attr(child, name=varname, unit=unt)
565
566            unt = "kg kg-1 s-1"
567            varname=TRIM(dn)//'vdf'
568            CALL xios_add_child(group_handle, child, varname)
569            CALL xios_set_attr(child, name=varname, unit=unt)
570            varname=TRIM(dn)//'the'
571            CALL xios_add_child(group_handle, child, varname)
572            CALL xios_set_attr(child, name=varname, unit=unt)
573            varname=TRIM(dn)//'con'
574            CALL xios_add_child(group_handle, child, varname)
575            CALL xios_set_attr(child, name=varname, unit=unt)
576            varname=TRIM(dn)//'lessi_impa'
577            CALL xios_add_child(group_handle, child, varname)
578            CALL xios_set_attr(child, name=varname, unit=unt)
579            varname=TRIM(dn)//'lessi_nucl'
580            CALL xios_add_child(group_handle, child, varname)
581            CALL xios_set_attr(child, name=varname, unit=unt)
582            varname=TRIM(dn)//'insc'
583            CALL xios_add_child(group_handle, child, varname)
584            CALL xios_set_attr(child, name=varname, unit=unt)
585            varname=TRIM(dn)//'bcscav'
586            CALL xios_add_child(group_handle, child, varname)
587            CALL xios_set_attr(child, name=varname, unit=unt)
588            varname=TRIM(dn)//'evapls'
589            CALL xios_add_child(group_handle, child, varname)
590            CALL xios_set_attr(child, name=varname, unit=unt)
591            varname=TRIM(dn)//'ls'
592            CALL xios_add_child(group_handle, child, varname)
593            CALL xios_set_attr(child, name=varname, unit=unt)
594            varname=TRIM(dn)//'trsp'
595            CALL xios_add_child(group_handle, child, varname)
596            CALL xios_set_attr(child, name=varname, unit=unt)
597            varname=TRIM(dn)//'sscav'
598            CALL xios_add_child(group_handle, child, varname)
599            CALL xios_set_attr(child, name=varname, unit=unt)
600            varname=TRIM(dn)//'sat'
601            CALL xios_add_child(group_handle, child, varname)
602            CALL xios_set_attr(child, name=varname, unit=unt)
603            varname=TRIM(dn)//'uscav'
604            CALL xios_add_child(group_handle, child, varname)
605            CALL xios_set_attr(child, name=varname, unit=unt)
606          END DO
607          !On ajoute les variables 2D traceurs par l interface fortran
608          CALL xios_get_handle("fields_strataer_trac_2D", group_handle)
609          ! On boucle sur les traceurs pour les ajouter au groupe puis fixer les attributs
610          DO iq = 1, nqtot
611            IF(.NOT.(tracers(iq)%isAdvected .AND. tracers(iq)%isInPhysics)) CYCLE
612
613            unt = "kg m-2"
614            varname='cum'//trim(tracers(iq)%name)
615            WRITE (lunout,*) 'XIOS var=', iq, nqtot, varname
616            CALL xios_add_child(group_handle, child, varname)
617            CALL xios_set_attr(child, name=varname, unit=unt)
618
619            unt = "kg m-2 s-1"
620            varname='cumd'//trim(tracers(iq)%name)//'_dry'
621            CALL xios_add_child(group_handle, child, varname)
622            CALL xios_set_attr(child, name=varname, unit=unt)
623          ENDDO
624    ENDIF
625!$OMP END MASTER
626#endif
627#endif
628
629    ! ug la boucle qui suit ne sert qu'une fois, pour l'initialisation, sinon il n'y a toujours qu'un seul passage:
630    DO iinit=1, iinitend
631!      print *,'IFF iinit=', iinit, iinitend
632#ifdef CPP_XIOS
633       !$OMP MASTER
634       IF (vars_defined) THEN
635          IF (prt_level >= 10) then
636             write(lunout,*)"phys_output_write: call xios_update_calendar, itau_w=",itau_w
637          ENDIF
638!          CALL xios_update_calendar(itau_w)
639          CALL xios_update_calendar(itap)
640       ENDIF
641       !$OMP END MASTER
642       !$OMP BARRIER
643#endif
644       ! On procède à l'écriture ou à la définition des nombreuses variables:
645!!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
646       CALL histwrite_phy(o_phis, pphis)
647
648       zx_tmp_fi2d = cell_area
649       IF (is_north_pole_phy) then
650         zx_tmp_fi2d(1) = cell_area(1)/nbp_lon
651       ENDIF
652       IF (is_south_pole_phy) then
653         zx_tmp_fi2d(klon) = cell_area(klon)/nbp_lon
654       ENDIf
655       CALL histwrite_phy(o_aire, zx_tmp_fi2d)
656
657       IF (vars_defined) THEN
658          DO i=1, klon
659             zx_tmp_fi2d(i)=pctsrf(i,is_ter)+pctsrf(i,is_lic)
660          ENDDO
661       ENDIF
662
663       CALL histwrite_phy(o_contfracATM, zx_tmp_fi2d)
664       CALL histwrite_phy(o_contfracOR, pctsrf(:,is_ter))
665!
666#ifdef CPP_XIOS
667       CALL histwrite_phy("R_ecc",R_ecc)
668       CALL histwrite_phy("R_peri",R_peri)
669       CALL histwrite_phy("R_incl",R_incl)
670       CALL histwrite_phy("solaire",solaire)
671       CALL histwrite_phy(o_Ahyb, ap)
672       CALL histwrite_phy(o_Bhyb, bp)
673       CALL histwrite_phy(o_Ahyb_bounds, Ahyb_bounds)
674       CALL histwrite_phy(o_Bhyb_bounds, Bhyb_bounds)
675       CALL histwrite_phy(o_Ahyb_mid, aps)
676       CALL histwrite_phy(o_Bhyb_mid, bps)
677       CALL histwrite_phy(o_Ahyb_mid_bounds, Ahyb_mid_bounds)
678       CALL histwrite_phy(o_Bhyb_mid_bounds, Bhyb_mid_bounds)
679       CALL histwrite_phy(o_longitude, longitude_deg)
680       CALL histwrite_phy(o_latitude, latitude_deg)
681!
682#ifdef CPP_RRTM
683      IF (iflag_rrtm.EQ.1) THEN
684        DO ISW=1, NSW
685          WRITE(ch1,'(i1)') ISW
686!         zx_tmp_0d=RSUN(ISW)
687!         CALL histwrite_phy("rsun"//ch1,zx_tmp_0d)
688          CALL histwrite_phy("rsun"//ch1,RSUN(ISW))
689        ENDDO
690      ENDIF
691#endif
692!
693       CALL histwrite_phy("co2_ppm",co2_ppm)
694       CALL histwrite_phy("CH4_ppb",CH4_ppb)
695       CALL histwrite_phy("N2O_ppb",N2O_ppb)
696       CALL histwrite_phy("CFC11_ppt",CFC11_ppt)
697       CALL histwrite_phy("CFC12_ppt",CFC12_ppt)
698!
699#endif
700
701!!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
702! Simulateur AIRS
703     IF (ok_airs) then
704      CALL histwrite_phy(o_alt_tropo,alt_tropo)
705 
706      CALL histwrite_phy(o_map_prop_hc,map_prop_hc)
707      CALL histwrite_phy(o_map_prop_hist,map_prop_hist)
708
709      CALL histwrite_phy(o_map_emis_hc,map_emis_hc)
710      CALL histwrite_phy(o_map_iwp_hc,map_iwp_hc)
711      CALL histwrite_phy(o_map_deltaz_hc,map_deltaz_hc)
712      CALL histwrite_phy(o_map_pcld_hc,map_pcld_hc)
713      CALL histwrite_phy(o_map_tcld_hc,map_tcld_hc)
714
715      CALL histwrite_phy(o_map_emis_hist,map_emis_hist)
716      CALL histwrite_phy(o_map_iwp_hist,map_iwp_hist)
717      CALL histwrite_phy(o_map_deltaz_hist,map_deltaz_hist)
718
719      CALL histwrite_phy(o_map_ntot,map_ntot)
720      CALL histwrite_phy(o_map_hc,map_hc)
721      CALL histwrite_phy(o_map_hist,map_hist)
722
723      CALL histwrite_phy(o_map_Cb,map_Cb)
724      CALL histwrite_phy(o_map_ThCi,map_ThCi)
725      CALL histwrite_phy(o_map_Anv,map_Anv)
726
727      CALL histwrite_phy(o_map_emis_Cb,map_emis_Cb)
728      CALL histwrite_phy(o_map_pcld_Cb,map_pcld_Cb)
729      CALL histwrite_phy(o_map_tcld_Cb,map_tcld_Cb)
730
731      CALL histwrite_phy(o_map_emis_ThCi,map_emis_ThCi)
732      CALL histwrite_phy(o_map_pcld_ThCi,map_pcld_ThCi)
733      CALL histwrite_phy(o_map_tcld_ThCi,map_tcld_ThCi)
734
735      CALL histwrite_phy(o_map_emis_Anv,map_emis_Anv)
736      CALL histwrite_phy(o_map_pcld_Anv,map_pcld_Anv)
737      CALL histwrite_phy(o_map_tcld_Anv,map_tcld_Anv)
738     ENDIF
739
740       CALL histwrite_phy(o_sza, sza_o)
741       CALL histwrite_phy(o_flat, zxfluxlat)
742       CALL histwrite_phy(o_ptstar, ptstar)
743       CALL histwrite_phy(o_pt0, pt0)
744       CALL histwrite_phy(o_slp, slp)
745       CALL histwrite_phy(o_tsol, zxtsol)
746       CALL histwrite_phy(o_t2m, zt2m)
747       CALL histwrite_phy(o_t2m_min, zt2m)
748       CALL histwrite_phy(o_t2m_max, zt2m)
749       CALL histwrite_phy(o_t2m_max_mon, t2m_max_mon)
750       CALL histwrite_phy(o_t2m_min_mon, t2m_min_mon)
751
752       IF (vars_defined) THEN
753          DO i=1, klon
754             zx_tmp_fi2d(i)=real(zn2mout(i,1))
755          ENDDO
756       ENDIF
757       CALL histwrite_phy(o_nt2mout, zx_tmp_fi2d)
758
759       IF (vars_defined) THEN
760          DO i=1, klon
761             zx_tmp_fi2d(i)=real(zn2mout(i,2))
762          ENDDO
763       ENDIF
764       CALL histwrite_phy(o_nt2moutfg, zx_tmp_fi2d)
765
766       IF (vars_defined) THEN
767          DO i=1, klon
768             zx_tmp_fi2d(i)=real(zn2mout(i,3))
769          ENDDO
770       ENDIF
771       CALL histwrite_phy(o_nq2mout, zx_tmp_fi2d)
772
773       IF (vars_defined) THEN
774          DO i=1, klon
775             zx_tmp_fi2d(i)=real(zn2mout(i,4))
776          ENDDO
777       ENDIF
778       CALL histwrite_phy(o_nq2moutfg, zx_tmp_fi2d)
779
780       IF (vars_defined) THEN
781          DO i=1, klon
782             zx_tmp_fi2d(i)=real(zn2mout(i,5))
783          ENDDO
784       ENDIF
785       CALL histwrite_phy(o_nu2mout, zx_tmp_fi2d)
786
787       IF (vars_defined) THEN
788          DO i=1, klon
789             zx_tmp_fi2d(i)=real(zn2mout(i,6))
790          ENDDO
791       ENDIF
792       CALL histwrite_phy(o_nu2moutfg, zx_tmp_fi2d)
793
794       IF (vars_defined) THEN
795          DO i=1, klon
796             zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
797          ENDDO
798       ENDIF
799       CALL histwrite_phy(o_wind10m, zx_tmp_fi2d)
800
801       IF (vars_defined) THEN
802          DO i=1, klon
803             zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
804          ENDDO
805       ENDIF
806       CALL histwrite_phy(o_wind10max, zx_tmp_fi2d)
807
808       CALL histwrite_phy(o_gusts, gustiness)
809
810       IF (vars_defined) THEN
811          DO k = 1, kmax_100m                                      !--we could stop much lower
812            zrho(:) = pplay(:,k)/t_seri(:,k)/RD                    ! air density in kg/m3
813            dz(:,k) = (paprs(:,k)-paprs(:,k+1))/zrho(:)/RG         ! layer thickness in m
814            IF (k==1) THEN
815              z(:,1) = (paprs(:,1)-pplay(:,1))/zrho(:)/RG          ! altitude middle of first layer in m
816              zt(:)  = dz(:,1)                                     ! altitude top of first layer in m
817            ELSE
818              z(:,k) = zt(:) + (paprs(:,k)-pplay(:,k))/zrho(:)/RG  ! altitude middle of layer k in m
819              zt(:)  = zt(:) + dz(:,k)                             ! altitude top of layer k in m
820            ENDIF
821          ENDDO
822          wind100m(:)=missing_val
823          DO k=1, kmax_100m-1                                      !--we could stop much lower
824            DO i=1,klon
825              IF (z(i,k).LT.100..AND.z(i,k+1).GE.100.) THEN
826                wind100m(i)=SQRT( (u_seri(i,k)+(100.-z(i,k))/(z(i,k+1)-z(i,k))*(u_seri(i,k+1)-u_seri(i,k)))**2.0 + &
827                                  (v_seri(i,k)+(100.-z(i,k))/(z(i,k+1)-z(i,k))*(v_seri(i,k+1)-v_seri(i,k)))**2.0 )
828              ENDIF
829            ENDDO
830          ENDDO
831       ENDIF
832       CALL histwrite_phy(o_wind100m, wind100m)
833
834       IF (vars_defined) THEN
835         !--polynomial fit for 14,Vestas,1074,V136/3450 kW windmill - Olivier
836         DO i=1,klon
837           IF (pctsrf(i,is_ter).GT.0.05 .AND. wind100m(i).NE.missing_val) THEN
838             x=wind100m(i)
839             IF (x.LE.3.0 .OR. x.GE.22.5) THEN
840               zx_tmp_fi2d(i)=0.0
841             ELSE IF (x.GE.10.0) THEN
842               zx_tmp_fi2d(i)=1.0
843             ELSE
844               zx_tmp_fi2d(i)= 10.73 + x*(-14.69 + x*(8.339 + x*(-2.59 + x*(0.4893 + x*(-0.05898 + x*(0.004627 + &
845                               x*(-0.0002352 + x*(7.478e-06 + x*(-1.351e-07 + x*(1.059e-09))))))))))
846               zx_tmp_fi2d(i)=MIN(MAX(zx_tmp_fi2d(i),0.0),1.0)
847             ENDIF
848           ELSE
849             zx_tmp_fi2d(i)=missing_val
850           ENDIF
851         ENDDO
852       ENDIF
853       CALL histwrite_phy(o_loadfactor_wind_onshore, zx_tmp_fi2d)
854
855       IF (vars_defined) THEN
856         !--polynomial fit for 14,Vestas,867,V164/8000 kW - Olivier
857         DO i=1,klon
858           IF (pctsrf(i,is_oce).GT.0.05 .AND. wind100m(i).NE.missing_val) THEN
859             x=wind100m(i)
860             IF (x.LE.3.0 .OR. x.GE.25.5) THEN
861               zx_tmp_fi2d(i)=0.0
862             ELSE IF (x.GE.12.5) THEN
863               zx_tmp_fi2d(i)=1.0
864             ELSE
865               zx_tmp_fi2d(i)= 20.59 + x*(-22.39 + x*(10.25 + x*(-2.601 + x*(0.4065 + x*(-0.04099 + x*(0.002716 + &
866                               x*(-0.0001175 + x*(3.195e-06 + x*(-4.959e-08 + x*(3.352e-10))))))))))
867               zx_tmp_fi2d(i)=MIN(MAX(zx_tmp_fi2d(i),0.0),1.0)
868             ENDIF
869           ELSE
870             zx_tmp_fi2d(i)=missing_val
871           ENDIF
872         ENDDO
873       ENDIF
874       CALL histwrite_phy(o_loadfactor_wind_offshore, zx_tmp_fi2d)
875
876       IF (vars_defined) THEN
877          DO i = 1, klon
878             zx_tmp_fi2d(i) = pctsrf(i,is_sic)
879          ENDDO
880       ENDIF
881       CALL histwrite_phy(o_sicf, zx_tmp_fi2d)
882       CALL histwrite_phy(o_q2m, zq2m)
883       IF (vars_defined) zx_tmp_fi2d = zustar
884       CALL histwrite_phy(o_ustar, zx_tmp_fi2d)
885       CALL histwrite_phy(o_u10m, zu10m)
886       CALL histwrite_phy(o_v10m, zv10m)
887
888       IF (vars_defined) THEN
889          DO i = 1, klon
890             zx_tmp_fi2d(i) = paprs(i,1)
891          ENDDO
892       ENDIF
893       CALL histwrite_phy(o_psol, zx_tmp_fi2d)
894       CALL histwrite_phy(o_mass, zmasse)
895       CALL histwrite_phy(o_qsurf, zxqsurf)
896
897       IF (.NOT. ok_veget) THEN
898          CALL histwrite_phy(o_qsol, qsol)
899       ENDIF
900
901       IF (vars_defined) THEN
902          DO i = 1, klon
903             zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
904          ENDDO
905       ENDIF
906
907       CALL histwrite_phy(o_precip, zx_tmp_fi2d)
908       CALL histwrite_phy(o_rain_fall, rain_fall)
909       CALL histwrite_phy(o_ndayrain, nday_rain)
910
911       ! epmax_cape:
912!       CALL histwrite_phy(o_epmax_diag, epmax_diag)
913       CALL histwrite_phy(o_ep, ep)
914
915       IF (vars_defined) THEN
916          DO i = 1, klon
917             zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
918          ENDDO
919       ENDIF
920       CALL histwrite_phy(o_plul, zx_tmp_fi2d)
921       CALL histwrite_phy(o_plun, rain_num)
922
923       IF (vars_defined) THEN
924          DO i = 1, klon
925             zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
926          ENDDO
927       ENDIF
928       CALL histwrite_phy(o_pluc, zx_tmp_fi2d)
929       CALL histwrite_phy(o_rain_con, rain_con)
930       CALL histwrite_phy(o_snow, snow_fall)
931       CALL histwrite_phy(o_msnow, zxsnow)
932       CALL histwrite_phy(o_fsnow, zfra_o)
933       CALL histwrite_phy(o_evap, evap)
934
935       IF (vars_defined) THEN
936         zx_tmp_fi2d = topsw*swradcorr
937       ENDIF
938       CALL histwrite_phy(o_tops, zx_tmp_fi2d)
939
940       IF (vars_defined) THEN
941         zx_tmp_fi2d = topsw0*swradcorr
942       ENDIF
943       CALL histwrite_phy(o_tops0, zx_tmp_fi2d)
944
945       CALL histwrite_phy(o_topl, toplw)
946       CALL histwrite_phy(o_topl0, toplw0)
947
948       IF (vars_defined) THEN
949          zx_tmp_fi2d(:) = swup(:,klevp1)*swradcorr(:)
950       ENDIF
951       CALL histwrite_phy(o_SWupTOA, zx_tmp_fi2d)
952
953       IF (vars_defined) THEN
954          zx_tmp_fi2d(:) = swup0(:,klevp1)*swradcorr(:)
955       ENDIF
956       CALL histwrite_phy(o_SWupTOAclr, zx_tmp_fi2d)
957
958       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN
959          IF (vars_defined) THEN
960             zx_tmp_fi2d(:) = swupc0(:,klevp1)*swradcorr(:)
961          ENDIF
962          CALL histwrite_phy(o_SWupTOAcleanclr, zx_tmp_fi2d)
963       ENDIF
964
965       IF (vars_defined) THEN
966          zx_tmp_fi2d(:) = swdn(:,klevp1)*swradcorr(:)
967       ENDIF
968       CALL histwrite_phy(o_SWdnTOA, zx_tmp_fi2d)
969
970       IF (vars_defined) THEN
971          zx_tmp_fi2d(:) = swdn0(:,klevp1)*swradcorr(:)
972       ENDIF
973       CALL histwrite_phy(o_SWdnTOAclr, zx_tmp_fi2d)
974
975       IF (vars_defined) THEN
976          zx_tmp_fi2d(:) = topsw(:)*swradcorr(:)-toplw(:)
977       ENDIF
978       CALL histwrite_phy(o_nettop, zx_tmp_fi2d)
979       
980       IF (vars_defined) THEN
981          zx_tmp_fi2d = SWup200*swradcorr
982       ENDIF
983       CALL histwrite_phy(o_SWup200, zx_tmp_fi2d)
984       
985       IF (vars_defined) THEN
986          zx_tmp_fi2d = SWup200clr*swradcorr
987       ENDIF
988       CALL histwrite_phy(o_SWup200clr, zx_tmp_fi2d)
989       
990       IF (vars_defined) THEN
991          zx_tmp_fi2d = SWdn200*swradcorr
992       ENDIF
993       CALL histwrite_phy(o_SWdn200, zx_tmp_fi2d)
994       
995       
996       IF (vars_defined) THEN
997          zx_tmp_fi2d = SWdn200clr*swradcorr
998       ENDIF
999       CALL histwrite_phy(o_SWdn200clr, zx_tmp_fi2d)
1000       
1001       CALL histwrite_phy(o_LWup200, LWup200)
1002       CALL histwrite_phy(o_LWup200clr, LWup200clr)
1003       CALL histwrite_phy(o_LWdn200, LWdn200)
1004       CALL histwrite_phy(o_LWdn200clr, LWdn200clr)
1005       
1006       IF (vars_defined) THEN
1007          zx_tmp_fi2d = solsw*swradcorr
1008       ENDIF
1009       CALL histwrite_phy(o_sols, zx_tmp_fi2d)
1010       
1011       
1012       IF (vars_defined) THEN
1013          zx_tmp_fi2d = solsw0*swradcorr
1014       ENDIF
1015       CALL histwrite_phy(o_sols0, zx_tmp_fi2d)
1016       CALL histwrite_phy(o_soll, sollw)
1017       CALL histwrite_phy(o_soll0, sollw0)
1018       CALL histwrite_phy(o_radsol, radsol)
1019
1020       IF (vars_defined) THEN
1021          zx_tmp_fi2d(:) = swup(:,1)*swradcorr(:)
1022       ENDIF
1023       CALL histwrite_phy(o_SWupSFC, zx_tmp_fi2d)
1024
1025       IF (vars_defined) THEN
1026          zx_tmp_fi2d(:) = swup0(:,1)*swradcorr(:)
1027       ENDIF
1028       CALL histwrite_phy(o_SWupSFCclr, zx_tmp_fi2d)
1029
1030       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN
1031          IF (vars_defined) THEN
1032             zx_tmp_fi2d(:) = swupc0(:,1)*swradcorr(:)
1033          ENDIF
1034          CALL histwrite_phy(o_SWupSFCcleanclr, zx_tmp_fi2d)
1035       ENDIF
1036
1037       IF (vars_defined) THEN
1038          zx_tmp_fi2d(:) = swdn(:,1)*swradcorr(:)
1039       ENDIF
1040       CALL histwrite_phy(o_SWdnSFC, zx_tmp_fi2d)
1041
1042       IF (vars_defined) THEN
1043          zx_tmp_fi2d(:) = swdn0(:,1)*swradcorr(:)
1044       ENDIF
1045       CALL histwrite_phy(o_SWdnSFCclr, zx_tmp_fi2d)
1046
1047       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN
1048          IF (vars_defined) THEN
1049             zx_tmp_fi2d(:) = swdnc0(:,1)*swradcorr(:)
1050          ENDIF
1051          CALL histwrite_phy(o_SWdnSFCcleanclr, zx_tmp_fi2d)
1052       ENDIF
1053
1054       CALL histwrite_phy(o_fdiffSWdnSFC, solswfdiff)
1055
1056       IF (vars_defined) THEN
1057          zx_tmp_fi2d(:)=sollwdown(:)-sollw(:)
1058       ENDIF
1059       CALL histwrite_phy(o_LWupSFC, zx_tmp_fi2d)
1060       CALL histwrite_phy(o_LWdnSFC, sollwdown)
1061
1062       IF (vars_defined) THEN
1063          sollwdownclr(1:klon) = -1.*lwdn0(1:klon,1)
1064          zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
1065       ENDIF
1066       CALL histwrite_phy(o_LWupSFCclr, zx_tmp_fi2d)
1067       CALL histwrite_phy(o_LWdnSFCclr, sollwdownclr)
1068
1069       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN
1070          IF (vars_defined) THEN
1071             zx_tmp_fi2d(:) = lwupc0(:,klevp1)
1072          ENDIF
1073          CALL histwrite_phy(o_LWupTOAcleanclr, zx_tmp_fi2d)
1074       ENDIF
1075
1076       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN
1077          IF (vars_defined) THEN
1078             zx_tmp_fi2d(:) = -1.*lwdnc0(:,1)
1079          ENDIF
1080          CALL histwrite_phy(o_LWdnSFCcleanclr, zx_tmp_fi2d)
1081       ENDIF
1082
1083!AI 08 2023 Ecrad 3Deffect
1084#ifdef CPP_ECRAD
1085     if (ok_3Deffect) then
1086        IF (vars_defined) THEN
1087          zx_tmp_fi2d = solsw_s2*swradcorr
1088       ENDIF
1089       CALL histwrite_phy(o_sols_s2, zx_tmp_fi2d)
1090       IF (vars_defined) THEN
1091          zx_tmp_fi2d = solsw0_s2*swradcorr
1092       ENDIF
1093       CALL histwrite_phy(o_sols0_s2, zx_tmp_fi2d)
1094       CALL histwrite_phy(o_soll_s2, sollw_s2)
1095       CALL histwrite_phy(o_soll0_s2, sollw0_s2)
1096       IF (vars_defined) THEN
1097         zx_tmp_fi2d = topsw_s2*swradcorr
1098       ENDIF
1099       CALL histwrite_phy(o_tops_s2, zx_tmp_fi2d)
1100
1101       IF (vars_defined) THEN
1102         zx_tmp_fi2d = topsw0_s2*swradcorr
1103       ENDIF
1104       CALL histwrite_phy(o_tops0_s2, zx_tmp_fi2d)
1105
1106       CALL histwrite_phy(o_topl_s2, toplw_s2)
1107       CALL histwrite_phy(o_topl0_s2, toplw0_s2)
1108     endif
1109#endif       
1110
1111       CALL histwrite_phy(o_bils, bils)
1112       CALL histwrite_phy(o_bils_diss, bils_diss)
1113       CALL histwrite_phy(o_bils_ec, bils_ec)
1114       CALL histwrite_phy(o_bils_ech, bils_ech)
1115       CALL histwrite_phy(o_bils_tke, bils_tke)
1116       CALL histwrite_phy(o_bils_kinetic, bils_kinetic)
1117       CALL histwrite_phy(o_bils_latent, bils_latent)
1118       CALL histwrite_phy(o_bils_enthalp, bils_enthalp)
1119
1120       IF (vars_defined) THEN
1121          zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
1122       ENDIF
1123       CALL histwrite_phy(o_sens, zx_tmp_fi2d)
1124       CALL histwrite_phy(o_fder, fder)
1125       CALL histwrite_phy(o_ffonte, zxffonte)
1126       CALL histwrite_phy(o_fqcalving, zxfqcalving)
1127       CALL histwrite_phy(o_fqfonte, zxfqfonte)
1128       IF (vars_defined) THEN
1129          zx_tmp_fi2d(1:klon)=(zxfqfonte(1:klon)+rain_fall(1:klon))*pctsrf(1:klon,is_lic)
1130       ENDIF
1131       CALL histwrite_phy(o_mrroli, zx_tmp_fi2d)
1132       CALL histwrite_phy(o_runofflic, zxrunofflic)
1133       IF (vars_defined) THEN
1134          zx_tmp_fi2d=0.
1135          DO nsrf=1,nbsrf
1136             zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxu(:,1,nsrf)
1137          ENDDO
1138       ENDIF
1139       CALL histwrite_phy(o_taux, zx_tmp_fi2d)
1140
1141       IF (vars_defined) THEN
1142          zx_tmp_fi2d=0.
1143          DO nsrf=1,nbsrf
1144             zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxv(:,1,nsrf)
1145          ENDDO
1146       ENDIF
1147       CALL histwrite_phy(o_tauy, zx_tmp_fi2d)
1148
1149       ! Etienne: test sorties pour compil sur JZ
1150!       IF (landice_opt .GE. 1) THEN
1151!          CALL histwrite_phy(o_snowsrf, snow_o)
1152!          CALL histwrite_phy(o_qsnow, qsnow)
1153!          CALL histwrite_phy(o_snowhgt,snowhgt)
1154!          CALL histwrite_phy(o_toice,to_ice)
1155!          CALL histwrite_phy(o_sissnow,sissnow)
1156!          CALL histwrite_phy(o_runoff,runoff)
1157!          CALL histwrite_phy(o_albslw3,albsol3_lic)
1158!       ENDIF
1159
1160       DO nsrf = 1, nbsrf
1161
1162          IF (vars_defined)             zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
1163          CALL histwrite_phy(o_pourc_srf(nsrf), zx_tmp_fi2d)
1164          IF (vars_defined)           zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
1165          CALL histwrite_phy(o_fract_srf(nsrf), zx_tmp_fi2d)
1166          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
1167          CALL histwrite_phy(o_taux_srf(nsrf), zx_tmp_fi2d)
1168          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
1169          CALL histwrite_phy(o_tauy_srf(nsrf), zx_tmp_fi2d)
1170          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
1171          CALL histwrite_phy(o_tsol_srf(nsrf), zx_tmp_fi2d)
1172          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = evap_pot( 1 : klon, nsrf)
1173          CALL histwrite_phy(o_evappot_srf(nsrf), zx_tmp_fi2d)
1174          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = ustar(1 : klon, nsrf)
1175          CALL histwrite_phy(o_ustar_srf(nsrf), zx_tmp_fi2d)
1176          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = u10m(1 : klon, nsrf)
1177          CALL histwrite_phy(o_u10m_srf(nsrf), zx_tmp_fi2d)
1178          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = v10m(1 : klon, nsrf)
1179          CALL histwrite_phy(o_v10m_srf(nsrf), zx_tmp_fi2d)
1180          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = t2m(1 : klon, nsrf)
1181          CALL histwrite_phy(o_t2m_srf(nsrf), zx_tmp_fi2d)
1182          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = fevap(1 : klon, nsrf)
1183          CALL histwrite_phy(o_evap_srf(nsrf), zx_tmp_fi2d)
1184          IF (vars_defined)        zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
1185          CALL histwrite_phy(o_sens_srf(nsrf), zx_tmp_fi2d)
1186          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
1187          CALL histwrite_phy(o_lat_srf(nsrf), zx_tmp_fi2d)
1188          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
1189          CALL histwrite_phy(o_flw_srf(nsrf), zx_tmp_fi2d)
1190          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
1191          CALL histwrite_phy(o_fsw_srf(nsrf), zx_tmp_fi2d)
1192          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
1193          CALL histwrite_phy(o_wbils_srf(nsrf), zx_tmp_fi2d)
1194          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfbilo( 1 : klon, nsrf)
1195          CALL histwrite_phy(o_wbilo_srf(nsrf), zx_tmp_fi2d)
1196          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfevap( 1 : klon, nsrf)
1197          CALL histwrite_phy(o_wevap_srf(nsrf), zx_tmp_fi2d)
1198          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfrain( 1 : klon, nsrf)
1199          CALL histwrite_phy(o_wrain_srf(nsrf), zx_tmp_fi2d)
1200          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfsnow( 1 : klon, nsrf)
1201          CALL histwrite_phy(o_wsnow_srf(nsrf), zx_tmp_fi2d)
1202
1203          IF (iflag_pbl > 1) THEN
1204             CALL histwrite_phy(o_tke_srf(nsrf),  pbl_tke(:,1:klev,nsrf))
1205             !CALL histwrite_phy(o_l_mix(nsrf),  l_mix(:,1:klev,nsrf))
1206             CALL histwrite_phy(o_l_mixmin(nsrf),  l_mixmin(:,1:klev,nsrf))
1207             CALL histwrite_phy(o_tke_max_srf(nsrf),  pbl_tke(:,1:klev,nsrf))
1208
1209                         
1210          ENDIF
1211!jyg<
1212          IF (iflag_pbl > 1 .AND. iflag_wake>=1  .AND. iflag_pbl_split >=1) THEN
1213             CALL histwrite_phy(o_dltpbltke_srf(nsrf), wake_delta_pbl_TKE(:,1:klev,nsrf))
1214          ENDIF
1215!>jyg
1216!          IF (iflag_pbl > 1 .AND. ifl_pbltree  >=1 ) THEN
1217!       CALL histwrite_phy(o_treedrg_srf(nsrf), treedrg(:,1:klev,nsrf))
1218!            ENDIF
1219
1220       ENDDO
1221       
1222               
1223        IF (iflag_pbl > 1) THEN
1224          zx_tmp_fi3d=0.
1225          IF (vars_defined) THEN
1226             DO nsrf=1,nbsrf
1227                DO k=1,klev
1228                   zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k) &
1229                        +pctsrf(:,nsrf)*tke_dissip(:,k,nsrf)
1230                ENDDO
1231             ENDDO
1232          ENDIF
1233         
1234          CALL histwrite_phy(o_tke_dissip, zx_tmp_fi3d)   
1235       ENDIF
1236
1237       IF (vars_defined) zx_tmp_fi2d(1 : klon) = sens_prec_liq_o(1 : klon, 1)
1238       CALL histwrite_phy(o_sens_prec_liq_oce, zx_tmp_fi2d)       
1239       IF (vars_defined) zx_tmp_fi2d(1 : klon) = sens_prec_liq_o(1 : klon, 2)
1240       CALL histwrite_phy(o_sens_prec_liq_sic, zx_tmp_fi2d)       
1241       IF (vars_defined) zx_tmp_fi2d(1 : klon) = sens_prec_sol_o(1 : klon, 1)
1242       CALL histwrite_phy(o_sens_prec_sol_oce, zx_tmp_fi2d)       
1243       IF (vars_defined) zx_tmp_fi2d(1 : klon) = sens_prec_sol_o(1 : klon, 2)
1244       CALL histwrite_phy(o_sens_prec_sol_sic, zx_tmp_fi2d)       
1245
1246       IF (vars_defined) zx_tmp_fi2d(1 : klon) = lat_prec_liq_o(1 : klon, 1)
1247       CALL histwrite_phy(o_lat_prec_liq_oce, zx_tmp_fi2d)       
1248       IF (vars_defined) zx_tmp_fi2d(1 : klon) = lat_prec_liq_o(1 : klon, 2)
1249       CALL histwrite_phy(o_lat_prec_liq_sic, zx_tmp_fi2d)       
1250       IF (vars_defined) zx_tmp_fi2d(1 : klon) = lat_prec_sol_o(1 : klon, 1)
1251       CALL histwrite_phy(o_lat_prec_sol_oce, zx_tmp_fi2d)       
1252       IF (vars_defined) zx_tmp_fi2d(1 : klon) = lat_prec_sol_o(1 : klon, 2)
1253       CALL histwrite_phy(o_lat_prec_sol_sic, zx_tmp_fi2d)       
1254
1255       DO nsrf=1,nbsrf+1
1256          CALL histwrite_phy(o_wstar(nsrf), wstar(1 : klon, nsrf))
1257       ENDDO
1258
1259       CALL histwrite_phy(o_cdrm, cdragm)
1260       CALL histwrite_phy(o_cdrh, cdragh)
1261       CALL histwrite_phy(o_cldl, cldl)
1262       CALL histwrite_phy(o_cldm, cldm)
1263       CALL histwrite_phy(o_cldh, cldh)
1264       CALL histwrite_phy(o_cldt, cldt)
1265       CALL histwrite_phy(o_JrNt, JrNt)
1266       
1267       IF (vars_defined)  zx_tmp_fi2d=cldl*JrNt     
1268       CALL histwrite_phy(o_cldljn, zx_tmp_fi2d)
1269       
1270       IF (vars_defined)  zx_tmp_fi2d=cldm*JrNt     
1271       CALL histwrite_phy(o_cldmjn, zx_tmp_fi2d)
1272       
1273       IF (vars_defined)  zx_tmp_fi2d=cldh*JrNt
1274       CALL histwrite_phy(o_cldhjn, zx_tmp_fi2d)
1275       
1276       IF (vars_defined)  zx_tmp_fi2d=cldt*JrNt
1277       CALL histwrite_phy(o_cldtjn, zx_tmp_fi2d)
1278       
1279       CALL histwrite_phy(o_cldq, cldq)
1280       IF (vars_defined)       zx_tmp_fi2d(1:klon) = flwp(1:klon)
1281       CALL histwrite_phy(o_lwp, zx_tmp_fi2d)
1282       IF (vars_defined)       zx_tmp_fi2d(1:klon) = fiwp(1:klon)
1283       CALL histwrite_phy(o_iwp, zx_tmp_fi2d)
1284       CALL histwrite_phy(o_ue, ue)
1285       CALL histwrite_phy(o_ve, ve)
1286       CALL histwrite_phy(o_uq, uq)
1287       CALL histwrite_phy(o_vq, vq)
1288       CALL histwrite_phy(o_uwat, uwat)
1289       CALL histwrite_phy(o_vwat, vwat)
1290       IF (iflag_con.GE.3) THEN ! sb
1291          CALL histwrite_phy(o_cape, cape)
1292          CALL histwrite_phy(o_pbase, ema_pcb)
1293          CALL histwrite_phy(o_ptop, ema_pct)
1294          CALL histwrite_phy(o_fbase, ema_cbmf)
1295          IF (iflag_con /= 30) THEN
1296             CALL histwrite_phy(o_plcl, plcl)
1297             CALL histwrite_phy(o_plfc, plfc)
1298             CALL histwrite_phy(o_wbeff, wbeff)
1299             CALL histwrite_phy(o_convoccur, convoccur)
1300          ENDIF
1301
1302          CALL histwrite_phy(o_cape_max, cape)
1303
1304          CALL histwrite_phy(o_upwd, upwd)
1305          CALL histwrite_phy(o_Ma, Ma)
1306          CALL histwrite_phy(o_dnwd, dnwd)
1307          CALL histwrite_phy(o_dnwd0, dnwd0)
1308          !! The part relative to the frequency of occurence of convection
1309          !! is now grouped with the part relative to thermals and shallow
1310          !! convection (output of the 3 fields: ftime_deepcv, ftime_th and
1311          !!  ftime_con).
1312          IF (vars_defined) THEN
1313             IF (iflag_thermals>=1)THEN
1314                zx_tmp_fi3d=dnwd+dnwd0+upwd+fm_therm(:,1:klev)
1315             ELSE
1316                zx_tmp_fi3d=dnwd+dnwd0+upwd
1317             ENDIF
1318          ENDIF
1319          CALL histwrite_phy(o_mc, zx_tmp_fi3d)
1320       ENDIF !iflag_con .GE. 3
1321       CALL histwrite_phy(o_prw, prw)
1322       CALL histwrite_phy(o_prlw, prlw)
1323       CALL histwrite_phy(o_prsw, prsw)
1324       CALL histwrite_phy(o_s_pblh, s_pblh)
1325       CALL histwrite_phy(o_s_pblt, s_pblt)
1326       CALL histwrite_phy(o_s_lcl, s_lcl)
1327       CALL histwrite_phy(o_s_therm, s_therm)
1328       !IM : Les champs suivants (s_capCL, s_oliqCL, s_cteiCL, s_trmb1, s_trmb2, s_trmb3) ne sont pas definis dans HBTM.F
1329       !       IF (o_s_capCL%flag(iff)<=lev_files(iff)) THEN
1330       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1331       !    $o_s_capCL%name,itau_w,s_capCL)
1332       !       ENDIF
1333       !       IF (o_s_oliqCL%flag(iff)<=lev_files(iff)) THEN
1334       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1335       !    $o_s_oliqCL%name,itau_w,s_oliqCL)
1336       !       ENDIF
1337       !       IF (o_s_cteiCL%flag(iff)<=lev_files(iff)) THEN
1338       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1339       !    $o_s_cteiCL%name,itau_w,s_cteiCL)
1340       !       ENDIF
1341       !       IF (o_s_trmb1%flag(iff)<=lev_files(iff)) THEN
1342       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1343       !    $o_s_trmb1%name,itau_w,s_trmb1)
1344       !       ENDIF
1345       !       IF (o_s_trmb2%flag(iff)<=lev_files(iff)) THEN
1346       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1347       !    $o_s_trmb2%name,itau_w,s_trmb2)
1348       !       ENDIF
1349       !       IF (o_s_trmb3%flag(iff)<=lev_files(iff)) THEN
1350       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1351       !    $o_s_trmb3%name,itau_w,s_trmb3)
1352       !       ENDIF
1353
1354#ifdef CPP_IOIPSL
1355#ifndef CPP_XIOS
1356  IF (.NOT.ok_all_xml) THEN
1357       ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
1358       ! Champs interpolles sur des niveaux de pression
1359       DO iff=1, nfiles
1360          ll=0
1361          DO k=1, nlevSTD
1362             bb2=clevSTD(k)
1363             IF (bb2.EQ."850".OR.bb2.EQ."700".OR. &
1364                  bb2.EQ."500".OR.bb2.EQ."200".OR. &
1365                  bb2.EQ."100".OR. &
1366                  bb2.EQ."50".OR.bb2.EQ."10") THEN
1367
1368                ! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1369                ll=ll+1
1370                CALL histwrite_phy(o_uSTDlevs(ll),uwriteSTD(:,k,iff), iff)
1371                CALL histwrite_phy(o_vSTDlevs(ll),vwriteSTD(:,k,iff), iff)
1372                CALL histwrite_phy(o_wSTDlevs(ll),wwriteSTD(:,k,iff), iff)
1373                CALL histwrite_phy(o_zSTDlevs(ll),phiwriteSTD(:,k,iff), iff)
1374                CALL histwrite_phy(o_qSTDlevs(ll),qwriteSTD(:,k,iff), iff)
1375                CALL histwrite_phy(o_tSTDlevs(ll),twriteSTD(:,k,iff), iff)
1376
1377             ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
1378          ENDDO
1379       ENDDO
1380  ENDIF
1381#endif
1382#endif
1383#ifdef CPP_XIOS
1384  IF (ok_all_xml) THEN
1385!XIOS  CALL xios_get_field_attr("u850",default_value=missing_val)
1386!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1387          ll=0
1388          DO k=1, nlevSTD
1389             bb2=clevSTD(k)
1390             IF (bb2.EQ."850".OR.bb2.EQ."700".OR. &
1391                bb2.EQ."500".OR.bb2.EQ."200".OR. &
1392                bb2.EQ."100".OR. &
1393                bb2.EQ."50".OR.bb2.EQ."10") THEN
1394                ll=ll+1
1395                CALL histwrite_phy(o_uSTDlevs(ll),ulevSTD(:,k))
1396                CALL histwrite_phy(o_vSTDlevs(ll),vlevSTD(:,k))
1397                CALL histwrite_phy(o_wSTDlevs(ll),wlevSTD(:,k))
1398                CALL histwrite_phy(o_zSTDlevs(ll),philevSTD(:,k))
1399                CALL histwrite_phy(o_qSTDlevs(ll),qlevSTD(:,k))
1400                CALL histwrite_phy(o_tSTDlevs(ll),tlevSTD(:,k))
1401             ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
1402          ENDDO
1403  ENDIF
1404#endif
1405       IF (vars_defined) THEN
1406          DO i=1, klon
1407             IF (pctsrf(i,is_oce).GT.epsfra.OR. &
1408                  pctsrf(i,is_sic).GT.epsfra) THEN
1409                zx_tmp_fi2d(i) = (ftsol(i, is_oce) * pctsrf(i,is_oce)+ &
1410                     ftsol(i, is_sic) * pctsrf(i,is_sic))/ &
1411                     (pctsrf(i,is_oce)+pctsrf(i,is_sic))
1412             ELSE
1413                zx_tmp_fi2d(i) = 273.15
1414             ENDIF
1415          ENDDO
1416       ENDIF
1417       CALL histwrite_phy(o_t_oce_sic, zx_tmp_fi2d)
1418
1419       ! Couplage convection-couche limite
1420       IF (iflag_con.GE.3) THEN
1421          IF (iflag_coupl>=1) THEN
1422             CALL histwrite_phy(o_ale_bl, ale_bl)
1423             CALL histwrite_phy(o_alp_bl, alp_bl)
1424          ENDIF !iflag_coupl>=1
1425       ENDIF !(iflag_con.GE.3)
1426       ! Wakes
1427       IF (iflag_con.EQ.3) THEN
1428          CALL histwrite_phy(o_Mipsh, Mipsh)
1429          IF (iflag_wake>=1) THEN
1430             CALL histwrite_phy(o_ale_wk, ale_wake)
1431             CALL histwrite_phy(o_alp_wk, alp_wake)
1432             IF (iflag_pbl_split>=1) THEN
1433!!               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=dtvdf_x(1:klon,1:klev)/pdtphys
1434!!               CALL histwrite_phy(o_dtvdf_x    ,zx_tmp_fi3d)
1435!!               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=dtvdf_w(1:klon,1:klev)/pdtphys
1436!!               CALL histwrite_phy(o_dtvdf_w    ,zx_tmp_fi3d)
1437!!               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=dqvdf_x(1:klon,1:klev)/pdtphys
1438!!               CALL histwrite_phy(o_dqvdf_x    ,zx_tmp_fi3d)
1439!!               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=dqvdf_w(1:klon,1:klev)/pdtphys
1440!
1441               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf_x(1:klon,1:klev)/pdtphys
1442               CALL histwrite_phy(o_dtvdf_x    ,zx_tmp_fi3d)
1443               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf_w(1:klon,1:klev)/pdtphys
1444               CALL histwrite_phy(o_dtvdf_w    ,zx_tmp_fi3d)
1445               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf_x(1:klon,1:klev)/pdtphys
1446               CALL histwrite_phy(o_dqvdf_x    ,zx_tmp_fi3d)
1447               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf_w(1:klon,1:klev)/pdtphys
1448!
1449               CALL histwrite_phy(o_dqvdf_w    ,zx_tmp_fi3d)
1450       IF (vars_defined)  zx_tmp_fi2d(1:klon)=-1*sens_x(1:klon)
1451               CALL histwrite_phy(o_sens_x     ,zx_tmp_fi2d)
1452       IF (vars_defined)  zx_tmp_fi2d(1:klon)=-1*sens_w(1:klon)
1453               CALL histwrite_phy(o_sens_w     ,zx_tmp_fi2d)
1454               CALL histwrite_phy(o_flat_x     ,zxfluxlat_x)
1455               CALL histwrite_phy(o_flat_w     ,zxfluxlat_w)
1456          zx_tmp_fi2d=0.
1457          IF (vars_defined) THEN
1458             DO nsrf=1,nbsrf
1459                   zx_tmp_fi2d(:)=zx_tmp_fi2d(:) &
1460                        +pctsrf(:,nsrf)*delta_tsurf(:,nsrf)
1461             ENDDO
1462          ENDIF
1463               CALL histwrite_phy(o_delta_tsurf,zx_tmp_fi2d)
1464               CALL histwrite_phy(o_cdragh_x   ,cdragh_x   )
1465               CALL histwrite_phy(o_cdragh_w   ,cdragh_w   )
1466               CALL histwrite_phy(o_cdragm_x   ,cdragm_x   )
1467               CALL histwrite_phy(o_cdragm_w   ,cdragm_w   )
1468               CALL histwrite_phy(o_kh         ,kh         )
1469               CALL histwrite_phy(o_kh_x       ,kh_x       )
1470               CALL histwrite_phy(o_kh_w       ,kh_w       )
1471             ENDIF   ! (iflag_pbl_split>=1)
1472             CALL histwrite_phy(o_ale, ale)
1473             CALL histwrite_phy(o_alp, alp)
1474             CALL histwrite_phy(o_cin, cin)
1475             CALL histwrite_phy(o_WAPE, wake_pe)
1476             CALL histwrite_phy(o_cv_gen, cv_gen)
1477             CALL histwrite_phy(o_wake_h, wake_h)
1478             CALL histwrite_phy(o_wake_dens, wake_dens)
1479             CALL histwrite_phy(o_wake_s, wake_s)
1480             CALL histwrite_phy(o_wake_deltat, wake_deltat)
1481             CALL histwrite_phy(o_wake_deltaq, wake_deltaq)
1482             CALL histwrite_phy(o_wake_omg, wake_omg)
1483             IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_wake(1:klon,1:klev) &
1484                  /pdtphys
1485             CALL histwrite_phy(o_dtwak, zx_tmp_fi3d)
1486             IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_wake(1:klon,1:klev)/pdtphys
1487             CALL histwrite_phy(o_dqwak, zx_tmp_fi3d)
1488             IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
1489             CALL histwrite_phy(o_dqwak2d, zx_tmp_fi2d)
1490          ENDIF ! iflag_wake>=1
1491          CALL histwrite_phy(o_ftd, ftd)
1492          CALL histwrite_phy(o_fqd, fqd)
1493       ENDIF !(iflag_con.EQ.3)
1494       IF (iflag_con.EQ.3.OR.iflag_con.EQ.30) THEN
1495          ! sortie RomP convection descente insaturee iflag_con=30
1496          ! etendue a iflag_con=3 (jyg)
1497          CALL histwrite_phy(o_Vprecip, Vprecip)
1498          CALL histwrite_phy(o_qtaa, qtaa)
1499          CALL histwrite_phy(o_clwaa, clw)
1500          CALL histwrite_phy(o_wdtrainA, wdtrainA)
1501          CALL histwrite_phy(o_wdtrainS, wdtrainS)
1502          CALL histwrite_phy(o_wdtrainM, wdtrainM)
1503       ENDIF !(iflag_con.EQ.3.or.iflag_con.EQ.30)
1504!!! nrlmd le 10/04/2012
1505       IF (iflag_trig_bl>=1) THEN
1506          CALL histwrite_phy(o_n2, n2)
1507          CALL histwrite_phy(o_s2, s2)
1508          CALL histwrite_phy(o_proba_notrig, proba_notrig)
1509          CALL histwrite_phy(o_random_notrig, random_notrig)
1510          CALL histwrite_phy(o_ale_bl_stat, ale_bl_stat)
1511          CALL histwrite_phy(o_ale_bl_trig, ale_bl_trig)
1512       ENDIF  !(iflag_trig_bl>=1)
1513       IF (iflag_clos_bl>=1) THEN
1514          CALL histwrite_phy(o_alp_bl_det, alp_bl_det)
1515          CALL histwrite_phy(o_alp_bl_fluct_m, alp_bl_fluct_m)
1516          CALL histwrite_phy(o_alp_bl_fluct_tke,  &
1517               alp_bl_fluct_tke)
1518          CALL histwrite_phy(o_alp_bl_conv, alp_bl_conv)
1519          CALL histwrite_phy(o_alp_bl_stat, alp_bl_stat)
1520       ENDIF  !(iflag_clos_bl>=1)
1521!!! fin nrlmd le 10/04/2012
1522       ! Output of slab ocean variables
1523       IF (type_ocean=='slab ') THEN
1524          CALL histwrite_phy(o_slab_bils, slab_wfbils)
1525          IF (nslay.EQ.1) THEN
1526              IF (vars_defined) zx_tmp_fi2d(:)=tslab(:,1)
1527              CALL histwrite_phy(o_tslab, zx_tmp_fi2d)
1528              IF (vars_defined) zx_tmp_fi2d(:)=dt_qflux(:,1)
1529              CALL histwrite_phy(o_slab_qflux, zx_tmp_fi2d)
1530          ELSE
1531              CALL histwrite_phy(o_tslab, tslab(:,1:nslay))
1532              CALL histwrite_phy(o_slab_qflux, dt_qflux(:,1:nslay))
1533          ENDIF
1534          IF (version_ocean=='sicINT') THEN
1535              CALL histwrite_phy(o_slab_bilg, slab_bilg)
1536              CALL histwrite_phy(o_slab_tice, tice)
1537              CALL histwrite_phy(o_slab_sic, seaice)
1538          ENDIF
1539          IF (slab_gm) THEN
1540             CALL histwrite_phy(o_slab_gm, dt_gm(:,1:nslay))
1541          ENDIF
1542          IF (slab_hdiff) THEN
1543            IF (nslay.EQ.1) THEN
1544                IF (vars_defined) zx_tmp_fi2d(:)=dt_hdiff(:,1)
1545                CALL histwrite_phy(o_slab_hdiff, zx_tmp_fi2d)
1546            ELSE
1547                CALL histwrite_phy(o_slab_hdiff, dt_hdiff(:,1:nslay))
1548            ENDIF
1549          ENDIF
1550          IF (slab_ekman.GT.0) THEN
1551            IF (nslay.EQ.1) THEN
1552                IF (vars_defined) zx_tmp_fi2d(:)=dt_ekman(:,1)
1553                CALL histwrite_phy(o_slab_ekman, zx_tmp_fi2d)
1554            ELSE
1555                CALL histwrite_phy(o_slab_ekman, dt_ekman(:,1:nslay))
1556            ENDIF
1557          ENDIF
1558       ENDIF !type_ocean == force/slab
1559       CALL histwrite_phy(o_weakinv, weak_inversion)
1560       CALL histwrite_phy(o_dthmin, dthmin)
1561       CALL histwrite_phy(o_cldtau, cldtau)
1562       CALL histwrite_phy(o_cldemi, cldemi)
1563       CALL histwrite_phy(o_pr_con_l, pmflxr(:,1:klev))
1564       CALL histwrite_phy(o_pr_con_i, pmflxs(:,1:klev))
1565       CALL histwrite_phy(o_pr_lsc_l, prfl(:,1:klev))
1566       CALL histwrite_phy(o_pr_lsc_i, psfl(:,1:klev))
1567       CALL histwrite_phy(o_re, re)
1568       CALL histwrite_phy(o_fl, fl)
1569       IF (vars_defined) THEN
1570          DO i=1, klon
1571             IF (zt2m(i).LE.273.15) then
1572                zx_tmp_fi2d(i)=MAX(0.,rh2m(i)*100.)
1573             ELSE
1574                zx_tmp_fi2d(i)=MAX(0.,MIN(100.,rh2m(i)*100.))
1575             ENDIF
1576          ENDDO
1577       ENDIF
1578       CALL histwrite_phy(o_rh2m, zx_tmp_fi2d)
1579
1580!       IF (vars_defined) THEN
1581!          DO i=1, klon
1582!             zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
1583!          ENDDO
1584!       ENDIF
1585!       CALL histwrite_phy(o_rh2m_min, zx_tmp_fi2d)
1586
1587!       IF (vars_defined) THEN
1588!          DO i=1, klon
1589!             zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
1590!          ENDDO
1591!       ENDIF
1592!       CALL histwrite_phy(o_rh2m_max, zx_tmp_fi2d)
1593
1594       CALL histwrite_phy(o_qsat2m, qsat2m)
1595       CALL histwrite_phy(o_tpot, tpot)
1596       CALL histwrite_phy(o_tpote, tpote)
1597       IF (vars_defined) zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, is_ter)
1598       CALL histwrite_phy(o_SWnetOR,  zx_tmp_fi2d)
1599       CALL histwrite_phy(o_LWdownOR, sollwdown)
1600       CALL histwrite_phy(o_snowl, snow_lsc)
1601       CALL histwrite_phy(o_solldown, sollwdown)
1602       CALL histwrite_phy(o_dtsvdfo, d_ts(:,is_oce))
1603       CALL histwrite_phy(o_dtsvdft, d_ts(:,is_ter))
1604       CALL histwrite_phy(o_dtsvdfg,  d_ts(:,is_lic))
1605       CALL histwrite_phy(o_dtsvdfi, d_ts(:,is_sic))
1606       CALL histwrite_phy(o_z0m, z0m(:,nbsrf+1))
1607       CALL histwrite_phy(o_z0h, z0h(:,nbsrf+1))
1608
1609       ! od550 per species
1610!--OLIVIER
1611!This is warranted by treating INCA aerosols as offline aerosols
1612#ifndef CPP_ECRAD
1613       IF (flag_aerosol.GT.0) THEN
1614          IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN
1615
1616             CALL histwrite_phy(o_od443aer, od443aer)
1617             CALL histwrite_phy(o_od550aer, od550aer)
1618             CALL histwrite_phy(o_od865aer, od865aer)
1619             CALL histwrite_phy(o_abs550aer, abs550aer)
1620             CALL histwrite_phy(o_od550lt1aer, od550lt1aer)
1621             CALL histwrite_phy(o_sconcso4, sconcso4)
1622             CALL histwrite_phy(o_sconcno3, sconcno3)
1623             CALL histwrite_phy(o_sconcoa, sconcoa)
1624             CALL histwrite_phy(o_sconcbc, sconcbc)
1625             CALL histwrite_phy(o_sconcss, sconcss)
1626             CALL histwrite_phy(o_sconcdust, sconcdust)
1627             CALL histwrite_phy(o_concso4, concso4)
1628             CALL histwrite_phy(o_concno3, concno3)
1629             CALL histwrite_phy(o_concoa, concoa)
1630             CALL histwrite_phy(o_concbc, concbc)
1631             CALL histwrite_phy(o_concss, concss)
1632             CALL histwrite_phy(o_concdust, concdust)
1633             CALL histwrite_phy(o_loadso4, loadso4)
1634             CALL histwrite_phy(o_loadoa, loadoa)
1635             CALL histwrite_phy(o_loadbc, loadbc)
1636             CALL histwrite_phy(o_loadss, loadss)
1637             CALL histwrite_phy(o_loaddust, loaddust)
1638             CALL histwrite_phy(o_loadno3, loadno3)
1639             CALL histwrite_phy(o_dryod550aer, dryod550aer)
1640             DO naero = 1, naero_tot-1
1641                CALL histwrite_phy(o_drytausumaero(naero),drytausum_aero(:,naero))
1642             END DO
1643          ENDIF
1644       ENDIF
1645       !--STRAT AER
1646       IF (flag_aerosol.GT.0.OR.flag_aerosol_strat.GT.0) THEN
1647          DO naero = 1, naero_tot
1648             CALL histwrite_phy(o_tausumaero(naero),tausum_aero(:,2,naero))
1649          END DO
1650       ENDIF
1651       IF (flag_aerosol_strat.GT.0) THEN
1652          CALL histwrite_phy(o_tausumaero_lw,tausum_aero(:,6,id_STRAT_phy))
1653       ENDIF
1654
1655       CALL histwrite_phy(o_p_tropopause, p_tropopause)
1656       CALL histwrite_phy(o_t_tropopause, t_tropopause)
1657       CALL histwrite_phy(o_z_tropopause, z_tropopause)
1658
1659! ThL -- In the following, we assume read_climoz == 1
1660       IF (vars_defined) THEN
1661         zx_tmp_fi2d = 0.0    ! Computation for strato, added ThL
1662         DO k=1, klev
1663            zx_tmp_fi2d(:) = zx_tmp_fi2d(:) + wo(:,k,1) * stratomask(:,k) * 1.e3
1664         END DO
1665       ENDIF
1666       CALL histwrite_phy(o_col_O3_strato, zx_tmp_fi2d) ! Added ThL
1667
1668       IF (vars_defined) THEN
1669         zx_tmp_fi2d = 0.0    ! Computation for tropo, added ThL
1670         DO k=1, klev
1671            zx_tmp_fi2d(:) = zx_tmp_fi2d(:) + wo(:,k,1) * (1.0-stratomask(:,k)) * 1.e3
1672         END DO
1673       ENDIF
1674       CALL histwrite_phy(o_col_O3_tropo, zx_tmp_fi2d)   ! Added ThL
1675! end add ThL
1676
1677#ifdef CPP_StratAer
1678       IF (type_trac=='coag') THEN
1679          CALL histwrite_phy(o_R2SO4, R2SO4)
1680          CALL histwrite_phy(o_OCS_lifetime, OCS_lifetime)
1681          CALL histwrite_phy(o_SO2_lifetime, SO2_lifetime)
1682          CALL histwrite_phy(o_budg_3D_backgr_ocs,   budg_3D_backgr_ocs)
1683          CALL histwrite_phy(o_budg_3D_backgr_so2,   budg_3D_backgr_so2)
1684          CALL histwrite_phy(o_budg_3D_ocs_to_so2,   budg_3D_ocs_to_so2)
1685          CALL histwrite_phy(o_budg_3D_so2_to_h2so4, budg_3D_so2_to_h2so4)
1686          CALL histwrite_phy(o_budg_3D_nucl,         budg_3D_nucl)
1687          CALL histwrite_phy(o_budg_3D_cond_evap,    budg_3D_cond_evap)
1688          CALL histwrite_phy(o_budg_dep_dry_ocs,     budg_dep_dry_ocs)
1689          CALL histwrite_phy(o_budg_dep_wet_ocs,     budg_dep_wet_ocs)
1690          CALL histwrite_phy(o_budg_dep_dry_so2,     budg_dep_dry_so2)
1691          CALL histwrite_phy(o_budg_dep_wet_so2,     budg_dep_wet_so2)
1692          CALL histwrite_phy(o_budg_dep_dry_h2so4,   budg_dep_dry_h2so4)
1693          CALL histwrite_phy(o_budg_dep_wet_h2so4,   budg_dep_wet_h2so4)
1694          CALL histwrite_phy(o_budg_dep_dry_part,    budg_dep_dry_part)
1695          CALL histwrite_phy(o_budg_dep_wet_part,    budg_dep_wet_part)
1696          CALL histwrite_phy(o_budg_emi_ocs,         budg_emi_ocs)
1697          CALL histwrite_phy(o_budg_emi_so2,         budg_emi_so2)
1698          CALL histwrite_phy(o_budg_emi_h2so4,       budg_emi_h2so4)
1699          CALL histwrite_phy(o_budg_emi_part,        budg_emi_part)
1700          CALL histwrite_phy(o_budg_ocs_to_so2,      budg_ocs_to_so2)
1701          CALL histwrite_phy(o_budg_so2_to_h2so4,    budg_so2_to_h2so4)
1702          CALL histwrite_phy(o_budg_h2so4_to_part,   budg_h2so4_to_part)
1703          CALL histwrite_phy(o_budg_sed_part,        budg_sed_part)
1704          CALL histwrite_phy(o_surf_PM25_sulf, surf_PM25_sulf)
1705          CALL histwrite_phy(o_vsed_aer, vsed_aer)
1706          CALL histwrite_phy(o_f_r_wet, f_r_wet)
1707          CALL histwrite_phy(o_ext_strat_550, tau_strat_550)
1708          CALL histwrite_phy(o_ext_strat_1020, tau_strat_1020)
1709          CALL histwrite_phy(o_tau_strat_550, tausum_strat(:,1))
1710          CALL histwrite_phy(o_tau_strat_1020, tausum_strat(:,2))
1711       ENDIF
1712#endif
1713       !NL
1714       IF (ok_volcan .AND. ok_ade) THEN
1715          DO k=1, klev
1716             IF (vars_defined) zx_tmp_fi3d(:,k)=heat_volc(:,k)*swradcorr(:)
1717          ENDDO
1718          CALL histwrite_phy(o_heat_volc, zx_tmp_fi3d)
1719          DO k=1, klev
1720             IF (vars_defined) zx_tmp_fi3d(:,k)=cool_volc(:,k)
1721          ENDDO
1722          CALL histwrite_phy(o_cool_volc, zx_tmp_fi3d)
1723       ENDIF
1724       IF (ok_ade) THEN
1725          IF (vars_defined) zx_tmp_fi2d(:)=topswad_aero*swradcorr
1726          CALL histwrite_phy(o_topswad, zx_tmp_fi2d)
1727         
1728          IF (vars_defined) zx_tmp_fi2d(:)=topswad0_aero*swradcorr
1729          CALL histwrite_phy(o_topswad0, zx_tmp_fi2d)
1730                   
1731          IF (vars_defined) zx_tmp_fi2d(:)=solswad_aero*swradcorr
1732          CALL histwrite_phy(o_solswad, zx_tmp_fi2d)
1733                   
1734          IF (vars_defined) zx_tmp_fi2d(:)=solswad0_aero*swradcorr
1735          CALL histwrite_phy(o_solswad0, zx_tmp_fi2d)
1736         
1737          IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN
1738
1739             CALL histwrite_phy(o_toplwad, toplwad_aero)
1740             CALL histwrite_phy(o_toplwad0, toplwad0_aero)
1741             CALL histwrite_phy(o_sollwad, sollwad_aero)
1742             CALL histwrite_phy(o_sollwad0, sollwad0_aero)
1743          ENDIF
1744          !====MS forcing diagnostics
1745          !ym warning : topsw_aero, solsw_aero, topsw0_aero, solsw0_aero are not defined by model
1746          !ym => init to 0 in radlwsw_m.F90 ztopsw_aero, zsolsw_aero, ztopsw0_aero, zsolsw0_aero
1747
1748          IF (vars_defined) zx_tmp_fi2d(:)=topsw_aero(:,1)*swradcorr(:)
1749          CALL histwrite_phy(o_swtoaas_nat,zx_tmp_fi2d)
1750          IF (vars_defined) zx_tmp_fi2d(:)=solsw_aero(:,1)*swradcorr(:)
1751          CALL histwrite_phy(o_swsrfas_nat,zx_tmp_fi2d)
1752          IF (vars_defined) zx_tmp_fi2d(:)=topsw0_aero(:,1)*swradcorr(:)
1753          CALL histwrite_phy(o_swtoacs_nat,zx_tmp_fi2d)
1754          IF (vars_defined) zx_tmp_fi2d(:)=solsw0_aero(:,1)*swradcorr(:)
1755          CALL histwrite_phy(o_swsrfcs_nat,zx_tmp_fi2d)
1756          !ant
1757          IF (vars_defined) zx_tmp_fi2d(:)=topsw_aero(:,2)*swradcorr(:)
1758          CALL histwrite_phy(o_swtoaas_ant,zx_tmp_fi2d)
1759          IF (vars_defined) zx_tmp_fi2d(:)=solsw_aero(:,2)*swradcorr(:)
1760          CALL histwrite_phy(o_swsrfas_ant,zx_tmp_fi2d)
1761          IF (vars_defined) zx_tmp_fi2d(:)=topsw0_aero(:,2)*swradcorr(:)
1762          CALL histwrite_phy(o_swtoacs_ant,zx_tmp_fi2d)
1763          IF (vars_defined) zx_tmp_fi2d(:)=solsw0_aero(:,2)*swradcorr(:)
1764          CALL histwrite_phy(o_swsrfcs_ant,zx_tmp_fi2d)
1765          !cf
1766          IF (.not. aerosol_couple) THEN
1767             IF (vars_defined) zx_tmp_fi2d(:)=topswcf_aero(:,1)*swradcorr(:)
1768             CALL histwrite_phy(o_swtoacf_nat,zx_tmp_fi2d)
1769             IF (vars_defined) zx_tmp_fi2d(:)=solswcf_aero(:,1)*swradcorr(:)
1770             CALL histwrite_phy(o_swsrfcf_nat,zx_tmp_fi2d)
1771             IF (vars_defined) zx_tmp_fi2d(:)=topswcf_aero(:,2)*swradcorr(:)
1772             CALL histwrite_phy(o_swtoacf_ant,zx_tmp_fi2d)
1773             IF (vars_defined) zx_tmp_fi2d(:)=solswcf_aero(:,2)*swradcorr(:)
1774             CALL histwrite_phy(o_swsrfcf_ant,zx_tmp_fi2d)
1775             IF (vars_defined) zx_tmp_fi2d(:)=topswcf_aero(:,3)*swradcorr(:)
1776             CALL histwrite_phy(o_swtoacf_zero,zx_tmp_fi2d)
1777             IF (vars_defined) zx_tmp_fi2d(:)=solswcf_aero(:,3)*swradcorr(:)
1778             CALL histwrite_phy(o_swsrfcf_zero,zx_tmp_fi2d)
1779          ENDIF
1780          !====MS forcing diagnostics
1781       ENDIF
1782       IF (ok_aie) THEN
1783          IF (vars_defined) zx_tmp_fi2d(:)= topswai_aero*swradcorr
1784          CALL histwrite_phy(o_topswai, zx_tmp_fi2d)
1785         
1786          IF (vars_defined) zx_tmp_fi2d(:)=toplwai_aero*swradcorr
1787          CALL histwrite_phy(o_toplwai, zx_tmp_fi2d)
1788         
1789          IF (vars_defined) zx_tmp_fi2d(:)=solswai_aero*swradcorr
1790          CALL histwrite_phy(o_solswai, zx_tmp_fi2d)
1791         
1792          IF (vars_defined) zx_tmp_fi2d(:)=sollwai_aero*swradcorr
1793          CALL histwrite_phy(o_sollwai, zx_tmp_fi2d)
1794       ENDIF
1795       IF (flag_aerosol.GT.0.AND.ok_cdnc) THEN
1796          CALL histwrite_phy(o_scdnc, scdnc)
1797          CALL histwrite_phy(o_cldncl, cldncl)
1798          CALL histwrite_phy(o_reffclws, reffclws)
1799          CALL histwrite_phy(o_reffclwc, reffclwc)
1800          CALL histwrite_phy(o_cldnvi, cldnvi)
1801          CALL histwrite_phy(o_lcc, lcc)
1802          CALL histwrite_phy(o_lcc3d, lcc3d)
1803          CALL histwrite_phy(o_lcc3dcon, lcc3dcon)
1804          CALL histwrite_phy(o_lcc3dstra, lcc3dstra)
1805          CALL histwrite_phy(o_icc3dcon, icc3dcon)
1806          CALL histwrite_phy(o_icc3dstra, icc3dstra)
1807          CALL histwrite_phy(o_cldicemxrat, zfice)
1808          IF (vars_defined) zx_tmp_fi3d(:,:)=1-zfice(:,:)
1809          CALL histwrite_phy(o_cldwatmxrat, zx_tmp_fi3d)
1810          CALL histwrite_phy(o_reffclwtop, reffclwtop)
1811       ENDIF
1812       ! Champs 3D:
1813       IF (ok_ade .OR. ok_aie) then
1814          IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN
1815             CALL histwrite_phy(o_ec550aer, ec550aer)
1816          ENDIF
1817       ENDIF
1818
1819       CALL histwrite_phy(o_lwcon, flwc)
1820       CALL histwrite_phy(o_iwcon, fiwc)
1821       CALL histwrite_phy(o_temp, t_seri)
1822       CALL histwrite_phy(o_theta, theta)
1823       CALL histwrite_phy(o_ovapinit, qx(:,:,ivap))
1824       CALL histwrite_phy(o_ovap, q_seri)
1825       CALL histwrite_phy(o_oliq, ql_seri)
1826
1827       IF (vars_defined) zx_tmp_fi3d = ql_seri+qs_seri
1828       CALL histwrite_phy(o_ocond, zx_tmp_fi3d)
1829
1830       CALL histwrite_phy(o_geop, zphi)
1831       CALL histwrite_phy(o_vitu, u_seri)
1832       CALL histwrite_phy(o_vitv, v_seri)
1833       CALL histwrite_phy(o_vitw, omega)
1834       CALL histwrite_phy(o_pres, pplay)
1835       CALL histwrite_phy(o_paprs, paprs(:,1:klev))
1836       
1837       IF (vars_defined) zx_tmp_fi3d = zphi/RG
1838       CALL histwrite_phy(o_zfull,zx_tmp_fi3d)
1839
1840#ifdef CPP_XIOS
1841!solbnd begin
1842#ifdef CPP_RRTM
1843      IF (iflag_rrtm.EQ.1) THEN
1844       IF (vars_defined) THEN
1845        DO ISW=1, NSW
1846          zx_tmp_fi3dsp(:,ISW) = swdn(:,klevp1)*swradcorr(:)*RSUN(ISW)
1847        ENDDO
1848        CALL histwrite_phy(o_solbnd, zx_tmp_fi3dsp)
1849       ENDIF
1850      ENDIF
1851#endif
1852!solbnd end
1853#endif
1854#endif
1855
1856       IF (flag_aerosol_strat.EQ.2) THEN
1857         CALL histwrite_phy(o_stratomask, stratomask)
1858       ENDIF
1859     
1860       IF (vars_defined)  THEN
1861        zx_tmp_fi3d(:,1)= pphis(:)/RG
1862        DO k = 2, klev
1863         DO i = 1, klon
1864            zx_tmp_fi3d(i,k) = zphi(i,k-1)/RG + &
1865                          (zphi(i,k)-zphi(i,k-1))/RG * &
1866                          (paprs(i,k)-pplay(i,k-1))/(pplay(i,k)-pplay(i,k-1))
1867         ENDDO
1868        ENDDO
1869       ENDIF
1870       CALL histwrite_phy(o_zhalf, zx_tmp_fi3d)
1871       CALL histwrite_phy(o_rneb, cldfra)
1872       CALL histwrite_phy(o_rnebcon, rnebcon)
1873       CALL histwrite_phy(o_rnebls, rneb)
1874       CALL histwrite_phy(o_rneblsvol, rneblsvol)
1875       IF (vars_defined)  THEN
1876          DO k=1, klev
1877             DO i=1, klon
1878                zx_tmp_fi3d(i,k)=cldfra(i,k)*JrNt(i)
1879             ENDDO
1880          ENDDO
1881       ENDIF
1882       CALL histwrite_phy(o_rnebjn, zx_tmp_fi3d)
1883       CALL histwrite_phy(o_rhum, zx_rh)
1884       IF (iflag_ice_thermo .GT. 0) THEN
1885          IF (vars_defined) zx_tmp_fi3d = zx_rhl * 100.
1886          CALL histwrite_phy(o_rhl, zx_tmp_fi3d)
1887          IF (vars_defined) zx_tmp_fi3d = zx_rhi * 100.
1888          CALL histwrite_phy(o_rhi, zx_tmp_fi3d)
1889       ENDIF
1890
1891!--aviation & supersaturation
1892       IF (ok_ice_sursat) THEN
1893         CALL histwrite_phy(o_oclr, qclr)
1894         CALL histwrite_phy(o_ocld, qcld)
1895         CALL histwrite_phy(o_oss, qss)
1896         CALL histwrite_phy(o_ovc, qvc)
1897         CALL histwrite_phy(o_rnebclr, rnebclr)
1898         CALL histwrite_phy(o_rnebss, rnebss)
1899         CALL histwrite_phy(o_rnebseri, rneb_seri)
1900         CALL histwrite_phy(o_gammass, gamma_ss)
1901         CALL histwrite_phy(o_N1_ss, N1_ss)
1902         CALL histwrite_phy(o_N2_ss, N2_ss)
1903         CALL histwrite_phy(o_drnebsub, drneb_sub)
1904         CALL histwrite_phy(o_drnebcon, drneb_con)
1905         CALL histwrite_phy(o_drnebtur, drneb_tur)
1906         CALL histwrite_phy(o_drnebavi, drneb_avi)
1907         CALL histwrite_phy(o_qsatl, zqsatl)
1908         CALL histwrite_phy(o_qsats, zqsats)
1909         CALL histwrite_phy(o_Tcontr, Tcontr)
1910         CALL histwrite_phy(o_qcontr, qcontr)
1911         CALL histwrite_phy(o_qcontr2, qcontr2)
1912         CALL histwrite_phy(o_fcontrN, fcontrN)
1913         CALL histwrite_phy(o_fcontrP, fcontrP)
1914       ENDIF
1915       IF (ok_plane_contrail) THEN
1916         CALL histwrite_phy(o_flight_m, flight_m)
1917       ENDIF
1918       IF (ok_plane_h2o) THEN
1919         CALL histwrite_phy(o_flight_h2o, flight_h2o)
1920       ENDIF
1921       
1922       IF (vars_defined) zx_tmp_fi3d = wo(:, :, 1) * dobson_u * 1e3 / zmasse / rmo3 * rmd
1923       CALL histwrite_phy(o_ozone, zx_tmp_fi3d)
1924
1925       IF (read_climoz == 2) THEN
1926         IF (vars_defined) zx_tmp_fi3d = wo(:, :, 2) * dobson_u * 1e3 / zmasse / rmo3 * rmd
1927         CALL histwrite_phy(o_ozone_light, zx_tmp_fi3d)
1928       ENDIF
1929
1930       CALL histwrite_phy(o_duphy, d_u)
1931
1932       CALL histwrite_phy(o_dtphy, d_t)
1933
1934       CALL histwrite_phy(o_dqphy,  d_qx(:,:,ivap))
1935       IF (vars_defined) CALL water_int(klon,klev,d_qx(:,:,ivap),zmasse,zx_tmp_fi2d)
1936       CALL histwrite_phy(o_dqphy2d,  zx_tmp_fi2d)
1937
1938       CALL histwrite_phy(o_dqlphy,  d_qx(:,:,iliq))
1939       IF (vars_defined) CALL water_int(klon,klev,d_qx(:,:,iliq),zmasse,zx_tmp_fi2d)
1940       CALL histwrite_phy(o_dqlphy2d,  zx_tmp_fi2d)
1941
1942       IF (nqo.EQ.3) THEN
1943       CALL histwrite_phy(o_dqsphy,  d_qx(:,:,isol))
1944       IF (vars_defined) CALL water_int(klon,klev,d_qx(:,:,isol),zmasse,zx_tmp_fi2d)
1945       CALL histwrite_phy(o_dqsphy2d,  zx_tmp_fi2d)
1946       ELSE
1947       zx_tmp_fi3d=0.0
1948       CALL histwrite_phy(o_dqsphy,  zx_tmp_fi3d)
1949       zx_tmp_fi2d=0.0
1950       CALL histwrite_phy(o_dqsphy2d,  zx_tmp_fi2d)
1951       ENDIF
1952
1953       DO nsrf=1, nbsrf
1954          IF (vars_defined) zx_tmp_fi2d(1 : klon) = falb1( 1 : klon, nsrf)
1955          CALL histwrite_phy(o_albe_srf(nsrf), zx_tmp_fi2d)
1956          IF (vars_defined) zx_tmp_fi2d(1 : klon) = z0m( 1 : klon, nsrf)
1957          CALL histwrite_phy(o_z0m_srf(nsrf), zx_tmp_fi2d)
1958          IF (vars_defined) zx_tmp_fi2d(1 : klon) = z0h( 1 : klon, nsrf)
1959          CALL histwrite_phy(o_z0h_srf(nsrf), zx_tmp_fi2d)
1960          IF (vars_defined) zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
1961          CALL histwrite_phy(o_ages_srf(nsrf), zx_tmp_fi2d)
1962          IF (vars_defined) zx_tmp_fi2d(1 : klon) = snow( 1 : klon, nsrf)
1963          CALL histwrite_phy(o_snow_srf(nsrf), zx_tmp_fi2d)
1964       ENDDO !nsrf=1, nbsrf
1965       CALL histwrite_phy(o_alb1, albsol1)
1966       CALL histwrite_phy(o_alb2, albsol2)
1967       !FH Sorties pour la couche limite
1968       IF (iflag_pbl>1) THEN
1969          zx_tmp_fi3d=0.
1970          IF (vars_defined) THEN
1971             DO nsrf=1,nbsrf
1972                DO k=1,klev
1973                   zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k) &
1974                        +pctsrf(:,nsrf)*pbl_tke(:,k,nsrf)
1975                ENDDO
1976             ENDDO
1977          ENDIF
1978          CALL histwrite_phy(o_tke, zx_tmp_fi3d)
1979          CALL histwrite_phy(o_tke_max, zx_tmp_fi3d) 
1980
1981       ENDIF
1982
1983       CALL histwrite_phy(o_kz, coefh(:,:,is_ave))
1984
1985       CALL histwrite_phy(o_kz_max, coefh(:,:,is_ave))
1986
1987       CALL histwrite_phy(o_clwcon, clwcon0)
1988       CALL histwrite_phy(o_dtdyn, d_t_dyn)
1989
1990       CALL histwrite_phy(o_dqdyn, d_q_dyn)
1991
1992       CALL histwrite_phy(o_dqdyn2d,d_q_dyn2d)
1993
1994       CALL histwrite_phy(o_dqldyn, d_ql_dyn)
1995
1996       CALL histwrite_phy(o_dqldyn2d, d_ql_dyn2d)
1997
1998       CALL histwrite_phy(o_dqsdyn, d_qs_dyn)
1999
2000       CALL histwrite_phy(o_dqsdyn2d, d_qs_dyn2d)
2001
2002       CALL histwrite_phy(o_dudyn, d_u_dyn)
2003       CALL histwrite_phy(o_dvdyn, d_v_dyn)
2004
2005       IF (vars_defined) THEN
2006          zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys
2007       ENDIF
2008       CALL histwrite_phy(o_dtcon, zx_tmp_fi3d)
2009       IF (iflag_thermals.EQ.0) THEN
2010          IF (vars_defined) THEN
2011             zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys + &
2012                  d_t_ajsb(1:klon,1:klev)/pdtphys
2013          ENDIF
2014          CALL histwrite_phy(o_tntc, zx_tmp_fi3d)
2015       ELSE IF(iflag_thermals.GE.1.AND.iflag_wake.EQ.1) THEN
2016          IF (vars_defined) THEN
2017             zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys + &
2018                  d_t_ajs(1:klon,1:klev)/pdtphys + &
2019                  d_t_wake(1:klon,1:klev)/pdtphys
2020          ENDIF
2021          CALL histwrite_phy(o_tntc, zx_tmp_fi3d)
2022       ENDIF
2023       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_con(1:klon,1:klev)/pdtphys
2024       CALL histwrite_phy(o_ducon, zx_tmp_fi3d)
2025       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_con(1:klon,1:klev)/pdtphys
2026       CALL histwrite_phy(o_dvcon, zx_tmp_fi3d)
2027       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
2028       CALL histwrite_phy(o_dqcon, zx_tmp_fi3d)
2029       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
2030       CALL histwrite_phy(o_dqcon2d, zx_tmp_fi2d)
2031
2032       IF (iflag_thermals.EQ.0) THEN
2033          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
2034          CALL histwrite_phy(o_tnhusc, zx_tmp_fi3d)
2035       ELSE IF (iflag_thermals.GE.1.AND.iflag_wake.EQ.1) THEN
2036          IF (vars_defined) THEN
2037             zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys + &
2038                  d_q_ajs(1:klon,1:klev)/pdtphys + &
2039                  d_q_wake(1:klon,1:klev)/pdtphys
2040          ENDIF
2041          CALL histwrite_phy(o_tnhusc, zx_tmp_fi3d)
2042       ENDIF
2043
2044       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lsc(1:klon,1:klev)/pdtphys
2045       CALL histwrite_phy(o_dtlsc, zx_tmp_fi3d)
2046       IF (vars_defined) zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+ &
2047            d_t_eva(1:klon,1:klev))/pdtphys
2048       CALL histwrite_phy(o_dtlschr, zx_tmp_fi3d)
2049       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
2050       CALL histwrite_phy(o_dqlsc, zx_tmp_fi3d)
2051       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
2052       CALL histwrite_phy(o_dqlsc2d, zx_tmp_fi2d)
2053       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=beta_prec(1:klon,1:klev)
2054       CALL histwrite_phy(o_beta_prec, zx_tmp_fi3d)
2055!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2056       ! Sorties specifiques a la separation thermiques/non thermiques
2057       IF (iflag_thermals>=1) THEN
2058          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lscth(1:klon,1:klev)/pdtphys
2059          CALL histwrite_phy(o_dtlscth, zx_tmp_fi3d)
2060          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lscst(1:klon,1:klev)/pdtphys
2061          CALL histwrite_phy(o_dtlscst, zx_tmp_fi3d)
2062          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
2063          CALL histwrite_phy(o_dqlscth, zx_tmp_fi3d)
2064          IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
2065          CALL histwrite_phy(o_dqlscth2d, zx_tmp_fi2d)
2066          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
2067          CALL histwrite_phy(o_dqlscst, zx_tmp_fi3d)
2068          IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
2069          CALL histwrite_phy(o_dqlscst2d, zx_tmp_fi2d)
2070          CALL histwrite_phy(o_plulth, plul_th)
2071          CALL histwrite_phy(o_plulst, plul_st)
2072          IF (vars_defined) THEN
2073             DO i=1,klon
2074                zx_tmp_fi2d(1:klon)=lmax_th(:)
2075             ENDDO
2076          ENDIF
2077          CALL histwrite_phy(o_lmaxth, zx_tmp_fi2d)
2078          IF (vars_defined) THEN
2079             DO k=1,klev
2080                DO i=1,klon
2081                   IF (ptconvth(i,k)) THEN
2082                      zx_tmp_fi3d(i,k)=1.
2083                   ELSE
2084                      zx_tmp_fi3d(i,k)=0.
2085                   ENDIF
2086                ENDDO
2087             ENDDO
2088          ENDIF
2089          CALL histwrite_phy(o_ptconvth, zx_tmp_fi3d)
2090       ENDIF ! iflag_thermals>=1
2091!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2092       zpt_conv = 0.
2093       WHERE (ptconv) zpt_conv = 1.
2094       CALL histwrite_phy(o_ptconv, zpt_conv)
2095!!       IF (vars_defined)         zx_tmp_fi2d=float(itau_con)/float(itap)
2096!!       CALL histwrite_phy(o_ftime_con, zx_tmp_fi2d)
2097       IF (vars_defined) THEN
2098          zpt_conv2d(:) = 0.
2099          DO k=1,klev
2100            WHERE (ptconv(:,k)) zpt_conv2d(:) = 1.
2101          ENDDO
2102       ENDIF
2103       CALL histwrite_phy(o_ftime_deepcv, zpt_conv2d)
2104       IF (vars_defined) THEN
2105          zx_tmp_fi2d(:) = 0.
2106          DO k=1,klev
2107            WHERE (ptconvth(:,k)) zx_tmp_fi2d(:) = 1.
2108          ENDDO
2109       ENDIF
2110       CALL histwrite_phy(o_ftime_th, zx_tmp_fi2d)
2111       IF (vars_defined) THEN
2112           zx_tmp_fi2d(:) = max(zx_tmp_fi2d(:),zpt_conv2d(:))
2113       ENDIF
2114       CALL histwrite_phy(o_ftime_con, zx_tmp_fi2d)
2115!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2116       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
2117       CALL histwrite_phy(o_dtvdf, zx_tmp_fi3d)
2118       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_diss(1:klon,1:klev)/pdtphys
2119       CALL histwrite_phy(o_dtdis, zx_tmp_fi3d)
2120       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
2121       CALL histwrite_phy(o_dqvdf, zx_tmp_fi3d)
2122       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
2123       CALL histwrite_phy(o_dqvdf2d, zx_tmp_fi2d)
2124       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
2125       CALL histwrite_phy(o_dteva, zx_tmp_fi3d)
2126       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
2127       CALL histwrite_phy(o_dqeva, zx_tmp_fi3d)
2128       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
2129       CALL histwrite_phy(o_dqeva2d, zx_tmp_fi2d)
2130       CALL histwrite_phy(o_ratqs, ratqs)
2131       IF (vars_defined) THEN
2132          zx_tmp_fi3d(1:klon,1:klev)=d_t_ajs(1:klon,1:klev)/pdtphys - &
2133               d_t_ajsb(1:klon,1:klev)/pdtphys
2134       ENDIF
2135       CALL histwrite_phy(o_dtthe, zx_tmp_fi3d)
2136       IF (vars_defined) THEN
2137          zx_tmp_fi3d(1:klon,1:klev)=d_u_ajs(1:klon,1:klev)/pdtphys
2138       ENDIF
2139       CALL histwrite_phy(o_duthe, zx_tmp_fi3d)
2140       IF (vars_defined) THEN
2141          zx_tmp_fi3d(1:klon,1:klev)=d_v_ajs(1:klon,1:klev)/pdtphys
2142       ENDIF
2143       CALL histwrite_phy(o_dvthe, zx_tmp_fi3d)
2144
2145       IF (iflag_thermals>=1) THEN
2146          ! Pour l instant 0 a y reflichir pour les thermiques
2147          ! regroupe avec ftime_deepcv et ftime_con
2148          !!zx_tmp_fi2d=0.
2149          !!CALL histwrite_phy(o_ftime_th, zx_tmp_fi2d)
2150          CALL histwrite_phy(o_f_th, fm_therm)
2151          CALL histwrite_phy(o_e_th, entr_therm)
2152          CALL histwrite_phy(o_w_th, zw2)
2153          CALL histwrite_phy(o_q_th, zqasc)
2154          CALL histwrite_phy(o_a_th, fraca)
2155          CALL histwrite_phy(o_cloudth_sth, cloudth_sth)
2156          CALL histwrite_phy(o_cloudth_senv, cloudth_senv)
2157          CALL histwrite_phy(o_cloudth_sigmath, cloudth_sigmath)
2158          CALL histwrite_phy(o_cloudth_sigmaenv, cloudth_sigmaenv)
2159          CALL histwrite_phy(o_d_th, detr_therm)
2160          CALL histwrite_phy(o_f0_th, f0)
2161          CALL histwrite_phy(o_zmax_th, zmax_th)
2162          IF (vars_defined) THEN
2163             zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys - &
2164                  d_q_ajsb(1:klon,1:klev)/pdtphys
2165          ENDIF
2166          CALL histwrite_phy(o_dqthe, zx_tmp_fi3d)
2167          IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
2168          CALL histwrite_phy(o_dqthe2d, zx_tmp_fi2d)
2169       ENDIF !iflag_thermals
2170       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_ajsb(1:klon,1:klev)/pdtphys
2171       CALL histwrite_phy(o_dtajs, zx_tmp_fi3d)
2172       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
2173       CALL histwrite_phy(o_dqajs, zx_tmp_fi3d)
2174       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
2175       CALL histwrite_phy(o_dqajs2d, zx_tmp_fi2d)
2176       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_swr(1:klon,1:klev)/pdtphys
2177       CALL histwrite_phy(o_dtswr, zx_tmp_fi3d)
2178       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_sw0(1:klon,1:klev)/pdtphys
2179       CALL histwrite_phy(o_dtsw0, zx_tmp_fi3d)
2180       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lwr(1:klon,1:klev)/pdtphys
2181       CALL histwrite_phy(o_dtlwr, zx_tmp_fi3d)
2182       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lw0(1:klon,1:klev)/pdtphys
2183       CALL histwrite_phy(o_dtlw0, zx_tmp_fi3d)
2184       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)/pdtphys
2185       CALL histwrite_phy(o_dtec, zx_tmp_fi3d)
2186       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
2187       CALL histwrite_phy(o_duvdf, zx_tmp_fi3d)
2188       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
2189       CALL histwrite_phy(o_dvvdf, zx_tmp_fi3d)
2190       IF (ok_orodr) THEN
2191          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
2192          CALL histwrite_phy(o_duoro, zx_tmp_fi3d)
2193          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
2194          CALL histwrite_phy(o_dvoro, zx_tmp_fi3d)
2195          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_oro(1:klon,1:klev)/pdtphys
2196          CALL histwrite_phy(o_dtoro, zx_tmp_fi3d)
2197       ENDIF
2198       IF (ok_orolf) THEN
2199          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
2200          CALL histwrite_phy(o_dulif, zx_tmp_fi3d)
2201
2202          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
2203          CALL histwrite_phy(o_dvlif, zx_tmp_fi3d)
2204
2205          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lif(1:klon,1:klev)/pdtphys
2206          CALL histwrite_phy(o_dtlif, zx_tmp_fi3d)
2207       ENDIF
2208
2209       IF (ok_hines) THEN
2210          IF (vars_defined) zx_tmp_fi3d=du_gwd_hines/pdtphys
2211          CALL histwrite_phy(o_du_gwd_hines, zx_tmp_fi3d)
2212
2213          IF (vars_defined) zx_tmp_fi3d= dv_gwd_hines/pdtphys         
2214          CALL histwrite_phy(o_dv_gwd_hines, zx_tmp_fi3d)
2215         
2216          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_hin(1:klon,1:klev)/pdtphys
2217          CALL histwrite_phy(o_dthin, zx_tmp_fi3d)
2218          CALL histwrite_phy(o_ustr_gwd_hines, zustr_gwd_hines)
2219          CALL histwrite_phy(o_vstr_gwd_hines, zvstr_gwd_hines)
2220       ENDIF
2221
2222       IF (.not. ok_hines .and. ok_gwd_rando) THEN
2223          IF (vars_defined)  zx_tmp_fi3d=du_gwd_front / pdtphys
2224          CALL histwrite_phy(o_du_gwd_front, zx_tmp_fi3d)
2225         
2226          IF (vars_defined)  zx_tmp_fi3d=dv_gwd_front / pdtphys
2227          CALL histwrite_phy(o_dv_gwd_front, zx_tmp_fi3d)
2228         
2229          CALL histwrite_phy(o_ustr_gwd_front, zustr_gwd_front)
2230          CALL histwrite_phy(o_vstr_gwd_front, zvstr_gwd_front)
2231       ENDIF
2232
2233       IF (ok_gwd_rando) THEN
2234          IF (vars_defined)  zx_tmp_fi3d=du_gwd_rando / pdtphys
2235          CALL histwrite_phy(o_du_gwd_rando, zx_tmp_fi3d)
2236         
2237          IF (vars_defined)  zx_tmp_fi3d=dv_gwd_rando / pdtphys
2238          CALL histwrite_phy(o_dv_gwd_rando, zx_tmp_fi3d)
2239          CALL histwrite_phy(o_ustr_gwd_rando, zustr_gwd_rando)
2240          CALL histwrite_phy(o_vstr_gwd_rando, zvstr_gwd_rando)
2241          CALL histwrite_phy(o_east_gwstress, east_gwstress )
2242          CALL histwrite_phy(o_west_gwstress, west_gwstress )
2243       ENDIF
2244
2245       IF (ok_qch4) THEN
2246          IF (vars_defined) zx_tmp_fi3d=d_q_ch4 / pdtphys
2247          CALL histwrite_phy(o_dqch4, zx_tmp_fi3d)
2248       ENDIF
2249       
2250       IF (vars_defined) THEN
2251         DO k=1, klevp1
2252           zx_tmp_fi3d1(:,k)=swup(:,k)*swradcorr(:)
2253         ENDDO
2254       ENDIF
2255       
2256       CALL histwrite_phy(o_rsu, zx_tmp_fi3d1)
2257
2258
2259       IF (vars_defined) THEN
2260         DO k=1, klevp1
2261           zx_tmp_fi3d1(:,k)=swdn(:,k)*swradcorr(:)
2262         ENDDO
2263       ENDIF
2264       
2265       CALL histwrite_phy(o_rsd, zx_tmp_fi3d1)
2266
2267       IF (vars_defined) THEN
2268         DO k=1, klevp1
2269           zx_tmp_fi3d1(:,k)=swup0(:,k)*swradcorr(:)
2270         ENDDO
2271       ENDIF
2272       
2273       CALL histwrite_phy(o_rsucs, zx_tmp_fi3d1)
2274
2275       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN
2276          IF (vars_defined) THEN
2277             DO k=1, klevp1
2278                zx_tmp_fi3d1(:,k)=swupc0(:,k)*swradcorr(:)
2279             ENDDO
2280          ENDIF
2281          CALL histwrite_phy(o_rsucsaf, zx_tmp_fi3d1)
2282       ENDIF
2283
2284       IF (vars_defined) THEN
2285         DO k=1, klevp1
2286           zx_tmp_fi3d1(:,k)=swdn0(:,k)*swradcorr(:)
2287         ENDDO
2288       ENDIF
2289       CALL histwrite_phy(o_rsdcs, zx_tmp_fi3d1)
2290
2291       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN
2292          IF (vars_defined) THEN
2293             DO k=1, klevp1
2294                zx_tmp_fi3d1(:,k)=swdnc0(:,k)*swradcorr(:)
2295             ENDDO
2296          ENDIF
2297          CALL histwrite_phy(o_rsdcsaf, zx_tmp_fi3d1)
2298       ENDIF
2299
2300       CALL histwrite_phy(o_rlu, lwup)
2301       CALL histwrite_phy(o_rld, lwdn)
2302       CALL histwrite_phy(o_rlucs, lwup0)
2303       CALL histwrite_phy(o_rldcs, lwdn0)
2304
2305       IF (vars_defined) THEN
2306          zx_tmp_fi3d(1:klon,1:klev)=d_t(1:klon,1:klev)+ &
2307               d_t_dyn(1:klon,1:klev)
2308       ENDIF
2309       CALL histwrite_phy(o_tnt, zx_tmp_fi3d)
2310
2311       IF (vars_defined) THEN
2312          zx_tmp_fi3d(1:klon,1:klev)=d_t_swr(1:klon,1:klev)/pdtphys + &
2313               d_t_lwr(1:klon,1:klev)/pdtphys
2314       ENDIF
2315       CALL histwrite_phy(o_tntr, zx_tmp_fi3d)
2316       IF (vars_defined) THEN
2317          zx_tmp_fi3d(1:klon,1:klev)= (d_t_lsc(1:klon,1:klev)+ &
2318               d_t_eva(1:klon,1:klev)+ &
2319               d_t_vdf(1:klon,1:klev))/pdtphys
2320       ENDIF
2321       CALL histwrite_phy(o_tntscpbl, zx_tmp_fi3d)
2322       IF (vars_defined) THEN
2323          zx_tmp_fi3d(1:klon,1:klev)=d_qx(1:klon,1:klev,ivap)+ &
2324               d_q_dyn(1:klon,1:klev)
2325       ENDIF
2326       CALL histwrite_phy(o_tnhus, zx_tmp_fi3d)
2327       IF (vars_defined) THEN
2328          zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys+ &
2329               d_q_eva(1:klon,1:klev)/pdtphys
2330       ENDIF
2331       CALL histwrite_phy(o_tnhusscpbl, zx_tmp_fi3d)
2332       CALL histwrite_phy(o_evu, coefm(:,:,is_ave))
2333       IF (vars_defined) THEN
2334          zx_tmp_fi3d(1:klon,1:klev)=q_seri(1:klon,1:klev)+ &
2335               ql_seri(1:klon,1:klev)
2336       ENDIF
2337       CALL histwrite_phy(o_h2o, zx_tmp_fi3d)
2338       IF (iflag_con >= 3) THEN
2339          IF (vars_defined) THEN
2340             zx_tmp_fi3d(1:klon,1:klev)=-1 * (dnwd(1:klon,1:klev)+ &
2341                  dnwd0(1:klon,1:klev))
2342          ENDIF
2343          CALL histwrite_phy(o_mcd, zx_tmp_fi3d)
2344          IF (vars_defined) THEN
2345             zx_tmp_fi3d(1:klon,1:klev)=upwd(1:klon,1:klev) + &
2346                  dnwd(1:klon,1:klev)+ dnwd0(1:klon,1:klev)
2347          ENDIF
2348          CALL histwrite_phy(o_dmc, zx_tmp_fi3d)
2349       ELSE IF (iflag_con == 2) THEN
2350          CALL histwrite_phy(o_mcd,  pmfd)
2351          IF (vars_defined) zx_tmp_fi3d = pmfu + pmfd
2352          CALL histwrite_phy(o_dmc,  zx_tmp_fi3d)
2353       ENDIF
2354       CALL histwrite_phy(o_ref_liq, ref_liq)
2355       CALL histwrite_phy(o_ref_ice, ref_ice)
2356!
2357       IF (ok_4xCO2atm) THEN
2358          IF (vars_defined) zx_tmp_fi2d(:) = swupp(:,klevp1)*swradcorr(:)
2359          CALL histwrite_phy(o_rsut4co2, zx_tmp_fi2d)
2360          IF (vars_defined) zx_tmp_fi2d(:) = lwupp(:,klevp1)
2361          CALL histwrite_phy(o_rlut4co2, zx_tmp_fi2d)
2362          IF (vars_defined) zx_tmp_fi2d(:) = swup0p(:,klevp1)*swradcorr(:)
2363          CALL histwrite_phy(o_rsutcs4co2, zx_tmp_fi2d)
2364          IF (vars_defined) zx_tmp_fi2d(:) = lwup0p(:,klevp1)
2365          CALL histwrite_phy(o_rlutcs4co2, zx_tmp_fi2d)
2366          IF (vars_defined) THEN
2367            DO k=1, klevp1
2368              zx_tmp_fi3d1(:,k)=swupp(:,k)*swradcorr(:)
2369            ENDDO
2370          ENDIF
2371          CALL histwrite_phy(o_rsu4co2, zx_tmp_fi3d1)
2372          IF (vars_defined) THEN
2373            DO k=1, klevp1
2374              zx_tmp_fi3d1(:,k)=swup0p(:,k)*swradcorr(:)
2375            ENDDO
2376          ENDIF
2377          CALL histwrite_phy(o_rsucs4co2, zx_tmp_fi3d1)
2378          IF (vars_defined) THEN
2379            DO k=1, klevp1
2380              zx_tmp_fi3d1(:,k)=swdnp(:,k)*swradcorr(:)
2381            ENDDO
2382          ENDIF
2383          CALL histwrite_phy(o_rsd4co2, zx_tmp_fi3d1)
2384          IF (vars_defined) THEN
2385            DO k=1, klevp1
2386              zx_tmp_fi3d1(:,k)=swdn0p(:,k)*swradcorr(:)
2387            ENDDO
2388          ENDIF
2389          CALL histwrite_phy(o_rsdcs4co2, zx_tmp_fi3d1)
2390          CALL histwrite_phy(o_rlu4co2, lwupp)
2391          CALL histwrite_phy(o_rlucs4co2, lwup0p)
2392          CALL histwrite_phy(o_rld4co2, lwdnp)
2393          CALL histwrite_phy(o_rldcs4co2, lwdn0p)
2394       ENDIF !ok_4xCO2atm
2395!!!!!!!!!!!! Sorties niveaux de pression NMC !!!!!!!!!!!!!!!!!!!!
2396#ifdef CPP_IOIPSL
2397#ifndef CPP_XIOS
2398  IF (.NOT.ok_all_xml) THEN
2399       ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
2400       ! Champs interpolles sur des niveaux de pression
2401       DO iff=7, nfiles-1 !--OB: here we deal with files 7,8,9
2402
2403          CALL histwrite_phy(o_tnondef,tnondef(:,:,iff-6),iff)
2404          CALL histwrite_phy(o_ta,twriteSTD(:,:,iff-6),iff)
2405          CALL histwrite_phy(o_zg,phiwriteSTD(:,:,iff-6),iff)
2406          CALL histwrite_phy(o_hus,qwriteSTD(:,:,iff-6),iff)
2407          CALL histwrite_phy(o_hur,rhwriteSTD(:,:,iff-6),iff)
2408          CALL histwrite_phy(o_ua,uwriteSTD(:,:,iff-6),iff)
2409          CALL histwrite_phy(o_va,vwriteSTD(:,:,iff-6),iff)
2410          CALL histwrite_phy(o_wap,wwriteSTD(:,:,iff-6),iff)
2411          IF (vars_defined) THEN
2412             DO k=1, nlevSTD
2413                DO i=1, klon
2414                   IF (tnondef(i,k,iff-6).NE.missing_val) THEN
2415                      IF (freq_outNMC(iff-6).LT.0) THEN
2416                         freq_moyNMC(iff-6)=(mth_len*un_jour)/freq_calNMC(iff-6)
2417                      ELSE
2418                         freq_moyNMC(iff-6)=freq_outNMC(iff-6)/freq_calNMC(iff-6)
2419                      ENDIF
2420                      zx_tmp_fi3d_STD(i,k) = (100.*tnondef(i,k,iff-6))/freq_moyNMC(iff-6)
2421                   ELSE
2422                      zx_tmp_fi3d_STD(i,k) = missing_val
2423                   ENDIF
2424                ENDDO
2425             ENDDO
2426          ENDIF
2427          CALL histwrite_phy(o_psbg,zx_tmp_fi3d_STD,iff)
2428          IF (vars_defined) THEN
2429             DO k=1, nlevSTD
2430                DO i=1, klon
2431                   IF (O3sumSTD(i,k,iff-6).NE.missing_val) THEN
2432                      zx_tmp_fi3d_STD(i,k) = O3sumSTD(i,k,iff-6) * 1.e+9
2433                   ELSE
2434                      zx_tmp_fi3d_STD(i,k) = missing_val
2435                   ENDIF
2436                ENDDO
2437             ENDDO !k=1, nlevSTD
2438          ENDIF
2439          CALL histwrite_phy(o_tro3,zx_tmp_fi3d_STD,iff)
2440          IF (read_climoz == 2) THEN
2441             IF (vars_defined) THEN
2442                DO k=1, nlevSTD
2443                   DO i=1, klon
2444                      IF (O3daysumSTD(i,k,iff-6).NE.missing_val) THEN
2445                         zx_tmp_fi3d_STD(i,k) = O3daysumSTD(i,k,iff-6) * 1.e+9
2446                      ELSE
2447                         zx_tmp_fi3d_STD(i,k) = missing_val
2448                      ENDIF
2449                   ENDDO
2450                ENDDO !k=1, nlevSTD
2451             ENDIF
2452             CALL histwrite_phy(o_tro3_daylight,zx_tmp_fi3d_STD,iff)
2453          endif
2454          CALL histwrite_phy(o_uxv,uvsumSTD(:,:,iff-6),iff)
2455          CALL histwrite_phy(o_vxq,vqsumSTD(:,:,iff-6),iff)
2456          CALL histwrite_phy(o_vxT,vTsumSTD(:,:,iff-6),iff)
2457          CALL histwrite_phy(o_wxq,wqsumSTD(:,:,iff-6),iff)
2458          CALL histwrite_phy(o_vxphi,vphisumSTD(:,:,iff-6),iff)
2459          CALL histwrite_phy(o_wxT,wTsumSTD(:,:,iff-6),iff)
2460          CALL histwrite_phy(o_uxu,u2sumSTD(:,:,iff-6),iff)
2461          CALL histwrite_phy(o_vxv,v2sumSTD(:,:,iff-6),iff)
2462          CALL histwrite_phy(o_TxT,T2sumSTD(:,:,iff-6),iff)
2463       ENDDO !nfiles
2464  ENDIF
2465#endif
2466#endif
2467#ifdef CPP_XIOS
2468  IF (ok_all_xml) THEN
2469!      DO iff=7, nfiles
2470
2471!         CALL histwrite_phy(o_tnondef,tnondef(:,:,3))
2472          CALL histwrite_phy(o_ta,tlevSTD(:,:))
2473          CALL histwrite_phy(o_zg,philevSTD(:,:))
2474          CALL histwrite_phy(o_hus,qlevSTD(:,:))
2475          CALL histwrite_phy(o_hur,rhlevSTD(:,:))
2476          CALL histwrite_phy(o_ua,ulevSTD(:,:))
2477          CALL histwrite_phy(o_va,vlevSTD(:,:))
2478          CALL histwrite_phy(o_wap,wlevSTD(:,:))
2479!         IF (vars_defined) THEN
2480!            DO k=1, nlevSTD
2481!               DO i=1, klon
2482!                  IF (tnondef(i,k,3).NE.missing_val) THEN
2483!                     IF (freq_outNMC(iff-6).LT.0) THEN
2484!                        freq_moyNMC(iff-6)=(mth_len*un_jour)/freq_calNMC(iff-6)
2485!                     ELSE
2486!                        freq_moyNMC(iff-6)=freq_outNMC(iff-6)/freq_calNMC(iff-6)
2487!                     ENDIF
2488!                     zx_tmp_fi3d_STD(i,k) = (100.*tnondef(i,k,3))/freq_moyNMC(iff-6)
2489!                  ELSE
2490!                     zx_tmp_fi3d_STD(i,k) = missing_val
2491!                  ENDIF
2492!               ENDDO
2493!            ENDDO
2494!         ENDIF
2495!         CALL histwrite_phy(o_psbg,zx_tmp_fi3d_STD)
2496          IF (vars_defined) THEN
2497             DO k=1, nlevSTD
2498                DO i=1, klon
2499                   IF (O3STD(i,k).NE.missing_val) THEN
2500                      zx_tmp_fi3d_STD(i,k) = O3STD(i,k) * 1.e+9
2501                   ELSE
2502                      zx_tmp_fi3d_STD(i,k) = missing_val
2503                   ENDIF
2504                ENDDO
2505             ENDDO !k=1, nlevSTD
2506          ENDIF
2507          CALL histwrite_phy(o_tro3,zx_tmp_fi3d_STD)
2508          IF (read_climoz == 2) THEN
2509             IF (vars_defined) THEN
2510                DO k=1, nlevSTD
2511                   DO i=1, klon
2512                      IF (O3daySTD(i,k).NE.missing_val) THEN
2513                         zx_tmp_fi3d_STD(i,k) = O3daySTD(i,k) * 1.e+9
2514                      ELSE
2515                         zx_tmp_fi3d_STD(i,k) = missing_val
2516                      ENDIF
2517                   ENDDO
2518                ENDDO !k=1, nlevSTD
2519             ENDIF
2520             CALL histwrite_phy(o_tro3_daylight,zx_tmp_fi3d_STD)
2521          ENDIF
2522          CALL histwrite_phy(o_uxv,uvSTD(:,:))
2523          CALL histwrite_phy(o_vxq,vqSTD(:,:))
2524          CALL histwrite_phy(o_vxT,vTSTD(:,:))
2525          CALL histwrite_phy(o_wxq,wqSTD(:,:))
2526          CALL histwrite_phy(o_vxphi,vphiSTD(:,:))
2527          CALL histwrite_phy(o_wxT,wTSTD(:,:))
2528          CALL histwrite_phy(o_uxu,u2STD(:,:))
2529          CALL histwrite_phy(o_vxv,v2STD(:,:))
2530          CALL histwrite_phy(o_TxT,T2STD(:,:))
2531!      ENDDO !nfiles
2532  ENDIF
2533#endif
2534!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2535       IF (iflag_phytrac == 1 ) then
2536!
2537         IF (type_trac == 'co2i') THEN
2538           itr = 0
2539           DO iq = 1, nqtot
2540             IF(.NOT.tracers(iq)%isInPhysics) CYCLE
2541             itr = itr + 1
2542!            write(*,*) 'phys_output_write_mod 2370: itr=',itr
2543             !--3D fields
2544             CALL histwrite_phy(o_trac(itr), tr_seri(:,:,itr))
2545             CALL histwrite_phy(o_dtr_vdf(itr),d_tr_cl(:,:,itr))
2546             CALL histwrite_phy(o_dtr_the(itr),d_tr_th(:,:,itr))
2547             CALL histwrite_phy(o_dtr_con(itr),d_tr_cv(:,:,itr))
2548             !--2D fields
2549             !--CO2 burden
2550             zx_tmp_fi2d=0.
2551             IF (vars_defined) THEN
2552                DO k=1,klev
2553                   zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*tr_seri(:,k,itr)
2554                ENDDO
2555             ENDIF
2556             CALL histwrite_phy(o_trac_cum(itr), zx_tmp_fi2d)
2557           ENDDO !--iq
2558           !--CO2 net fluxes
2559           CALL histwrite_phy(o_flx_co2_land,  fco2_land)
2560           CALL histwrite_phy(o_flx_co2_ocean, fco2_ocean)
2561           CALL histwrite_phy(o_flx_co2_ocean_cor, fco2_ocean_cor)
2562           CALL histwrite_phy(o_flx_co2_land_cor, fco2_land_cor)
2563           CALL histwrite_phy(o_flx_co2_ff,    fco2_ff)
2564           CALL histwrite_phy(o_flx_co2_bb,    fco2_bb)
2565
2566         ELSE IF (type_trac == 'inco') THEN
2567           itr = 0
2568           DO iq = 1, nqtot
2569             IF(.NOT.tracers(iq)%isInPhysics) CYCLE
2570             itr = itr+1
2571             IF(tracers(iq)%component /= 'co2i') CYCLE
2572             !--3D fields
2573             CALL histwrite_phy(o_trac   (itr),tr_seri(:,:,itr))
2574             CALL histwrite_phy(o_dtr_vdf(itr),d_tr_cl(:,:,itr))
2575             CALL histwrite_phy(o_dtr_the(itr),d_tr_th(:,:,itr))
2576             CALL histwrite_phy(o_dtr_con(itr),d_tr_cv(:,:,itr))
2577             !--2D fields
2578             !--CO2 burden
2579             zx_tmp_fi2d=0.
2580             IF (vars_defined) THEN
2581                DO k=1,klev
2582                   zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*tr_seri(:,k,itr)
2583                ENDDO
2584             ENDIF
2585             CALL histwrite_phy(o_trac_cum(itr), zx_tmp_fi2d)
2586           ENDDO !--iq
2587           !--CO2 net fluxes
2588           CALL histwrite_phy(o_flx_co2_land,  fco2_land)
2589           CALL histwrite_phy(o_flx_co2_ocean, fco2_ocean)
2590           CALL histwrite_phy(o_flx_co2_ocean_cor, fco2_ocean_cor)
2591           CALL histwrite_phy(o_flx_co2_land_cor, fco2_land_cor)
2592           CALL histwrite_phy(o_flx_co2_ff,    fco2_ff)
2593           CALL histwrite_phy(o_flx_co2_bb,    fco2_bb)
2594
2595         ELSE IF (ANY(type_trac==['lmdz','coag'])) THEN
2596           itr = 0
2597           DO iq = 1, nqtot
2598             IF(.NOT.tracers(iq)%isInPhysics) CYCLE
2599             itr = itr + 1
2600!            write(*,*) 'phys_output_write_mod 2337: itr=',itr
2601             !--3D fields
2602             CALL histwrite_phy(o_trac(itr), tr_seri(:,:,itr))
2603             CALL histwrite_phy(o_dtr_vdf(itr),d_tr_cl(:,:,itr))
2604             CALL histwrite_phy(o_dtr_the(itr),d_tr_th(:,:,itr))
2605             CALL histwrite_phy(o_dtr_con(itr),d_tr_cv(:,:,itr))
2606             CALL histwrite_phy(o_dtr_lessi_impa(itr),d_tr_lessi_impa(:,:,itr))
2607             CALL histwrite_phy(o_dtr_lessi_nucl(itr),d_tr_lessi_nucl(:,:,itr))
2608             CALL histwrite_phy(o_dtr_insc(itr),d_tr_insc(:,:,itr))
2609             CALL histwrite_phy(o_dtr_bcscav(itr),d_tr_bcscav(:,:,itr))
2610             CALL histwrite_phy(o_dtr_evapls(itr),d_tr_evapls(:,:,itr))
2611             CALL histwrite_phy(o_dtr_ls(itr),d_tr_ls(:,:,itr))
2612             CALL histwrite_phy(o_dtr_trsp(itr),d_tr_trsp(:,:,itr))
2613             CALL histwrite_phy(o_dtr_sscav(itr),d_tr_sscav(:,:,itr))
2614             CALL histwrite_phy(o_dtr_sat(itr),d_tr_sat(:,:,itr))
2615             CALL histwrite_phy(o_dtr_uscav(itr),d_tr_uscav(:,:,itr))
2616            !--2D fields
2617             CALL histwrite_phy(o_dtr_dry(itr), flux_tr_dry(:,itr))
2618             zx_tmp_fi2d=0.
2619             IF (vars_defined) THEN
2620                DO k=1,klev
2621                   zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*tr_seri(:,k,itr)
2622                ENDDO
2623             ENDIF
2624             CALL histwrite_phy(o_trac_cum(itr), zx_tmp_fi2d)
2625           ENDDO !--iq
2626         ENDIF   !--type_trac
2627       ENDIF   !(iflag_phytrac==1)
2628
2629       if (activate_ocean_skin >= 1) then
2630          CALL histwrite_phy(o_delta_sst, delta_sst)
2631          CALL histwrite_phy(o_delta_sal, delta_sal)
2632          CALL histwrite_phy(o_ds_ns, ds_ns)
2633          CALL histwrite_phy(o_dt_ns, dt_ns)
2634          CALL histwrite_phy(o_dter, dter)
2635          CALL histwrite_phy(o_dser, dser)
2636          CALL histwrite_phy(o_tkt, tkt)
2637          CALL histwrite_phy(o_tks, tks)
2638          CALL histwrite_phy(o_taur, taur)
2639          CALL histwrite_phy(o_sss, sss)
2640       end if
2641
2642#ifdef ISO
2643    do ixt=1,ntiso
2644!        write(*,*) 'ixt'
2645        IF (vars_defined) zx_tmp_fi2d(:) = xtrain_fall(ixt,:) + xtsnow_fall(ixt,:)
2646        CALL histwrite_phy(o_xtprecip(ixt), zx_tmp_fi2d)
2647
2648        IF (vars_defined) zx_tmp_fi2d(:) = xtrain_lsc(ixt,:) + xtsnow_lsc(ixt,:)
2649        CALL histwrite_phy(o_xtplul(ixt), zx_tmp_fi2d)
2650
2651        IF (vars_defined) zx_tmp_fi2d(:) = xtrain_con(ixt,:) + xtsnow_con(ixt,:)
2652        CALL histwrite_phy(o_xtpluc(ixt), zx_tmp_fi2d)
2653        CALL histwrite_phy(o_xtevap(ixt),   xtevap(ixt,:))
2654        CALL histwrite_phy(o_xtovap(ixt),  xt_seri(ixt,:,:))
2655        CALL histwrite_phy(o_xtoliq(ixt), xtl_seri(ixt,:,:))
2656
2657        IF (vars_defined) zx_tmp_fi3d(:,:)=xtl_seri(ixt,:,:)+xts_seri(ixt,:,:)
2658        CALL histwrite_phy(o_xtcond(ixt), zx_tmp_fi3d)
2659        CALL histwrite_phy(o_dxtdyn(ixt),   d_xt_dyn(ixt,:,:))
2660        CALL histwrite_phy(o_dxtldyn(ixt), d_xtl_dyn(ixt,:,:))
2661
2662        IF (vars_defined) zx_tmp_fi3d(:,:)=d_xt_con(ixt,:,:)/pdtphys
2663        CALL histwrite_phy(o_dxtcon(ixt), zx_tmp_fi3d)
2664
2665        IF (vars_defined) zx_tmp_fi3d(:,:)=d_xt_lsc(ixt,:,:)/pdtphys
2666        CALL histwrite_phy(o_dxtlsc(ixt), zx_tmp_fi3d)
2667
2668        IF (vars_defined) zx_tmp_fi3d(:,:)=d_xt_eva(ixt,:,:)/pdtphys
2669        CALL histwrite_phy(o_dxteva(ixt), zx_tmp_fi3d)
2670
2671        IF (vars_defined) zx_tmp_fi3d(:,:)=d_xt_vdf(ixt,:,:)/pdtphys
2672        CALL histwrite_phy(o_dxtvdf(ixt), zx_tmp_fi3d)
2673
2674        IF (vars_defined) zx_tmp_fi3d(:,:)=d_xt_ajsb(ixt,:,:)/pdtphys
2675        CALL histwrite_phy(o_dxtajs(ixt), zx_tmp_fi3d)
2676
2677        IF (vars_defined) zx_tmp_fi3d(:,:)=(d_xt_ajs(ixt,:,:)-d_xt_ajsb(ixt,:,:))/pdtphys
2678        CALL histwrite_phy(o_dxtthe(ixt), zx_tmp_fi3d)
2679
2680        IF (ok_qch4) THEN
2681          IF (vars_defined) zx_tmp_fi3d(:,:)=d_xt_ch4(ixt,:,:)/pdtphys
2682          CALL histwrite_phy(o_dxtch4(ixt), zx_tmp_fi3d)
2683        END IF
2684
2685        IF (ixt == iso_HTO) THEN
2686          IF (vars_defined) zx_tmp_fi3d(:,:)=d_xt_prod_nucl(ixt,:,:)/pdtphys
2687          CALL histwrite_phy(o_dxtprod_nucl(ixt), zx_tmp_fi3d)
2688
2689          IF (vars_defined) zx_tmp_fi3d(:,:)=d_xt_cosmo(ixt,:,:)/pdtphys
2690          CALL histwrite_phy(o_dxtcosmo(ixt), zx_tmp_fi3d)
2691
2692          IF (vars_defined) zx_tmp_fi3d(:,:)=d_xt_decroiss(ixt,:,:)/pdtphys
2693          CALL histwrite_phy(o_dxtdecroiss(ixt), zx_tmp_fi3d)
2694        END IF
2695
2696    !write(*,*) 'phys_output_write_mod 2531'
2697    enddo
2698#endif
2699
2700       IF (.NOT.vars_defined) THEN
2701          !$OMP MASTER
2702#ifndef CPP_IOIPSL_NO_OUTPUT
2703          DO iff=1,nfiles
2704             IF (clef_files(iff)) THEN
2705                CALL histend(nid_files(iff))
2706                ndex2d = 0
2707                ndex3d = 0
2708             ENDIF ! clef_files
2709          ENDDO !  iff
2710#endif
2711#ifdef CPP_XIOS
2712          !On finalise l'initialisation:
2713          CALL wxios_closedef()
2714#endif
2715          !$OMP END MASTER
2716          !$OMP BARRIER
2717          vars_defined = .TRUE.
2718
2719       ENDIF !--.NOT.vars_defined
2720
2721    ENDDO
2722
2723    IF (vars_defined) THEN
2724       ! On synchronise les fichiers pour IOIPSL
2725#ifndef CPP_IOIPSL_NO_OUTPUT
2726       !$OMP MASTER
2727       DO iff=1,nfiles
2728          IF (ok_sync .AND. clef_files(iff)) THEN
2729             CALL histsync(nid_files(iff))
2730          ENDIF
2731       END DO
2732       !$OMP END MASTER
2733#endif
2734    ENDIF
2735
2736  END SUBROUTINE phys_output_write
2737
2738END MODULE phys_output_write_mod
Note: See TracBrowser for help on using the repository browser.