source: LMDZ5/trunk/libf/phylmd/Dust/phys_output_write_spl_mod.F90 @ 2753

Last change on this file since 2753 was 2747, checked in by oboucher, 8 years ago

Changing declaration of nslay to follow changset 2656 from emillour

File size: 70.7 KB
Line 
1!
2! $Id: phys_output_write_mod.F90 2298 2015-06-14 19:13:32Z fairhead $
3!
4MODULE phys_output_write_spl_mod
5
6!JE20150620<<
7!JE20150620>>
8
9!JE20150620<<
10
11    USE time_phylmdz_mod, only: day_step_phy, start_time, itau_phy
12
13  USE phytracr_spl_mod, ONLY : ok_chimeredust, id_prec, id_fine, id_coss, &
14       id_codu, id_scdu , &
15       d_tr_cl, d_tr_th, d_tr_cv, d_tr_lessi_impa, &
16       d_tr_lessi_nucl, d_tr_insc, d_tr_bcscav, d_tr_evapls, d_tr_ls,  &
17       d_tr_trsp, d_tr_sscav, d_tr_sat, d_tr_uscav ,&
18       diff_aod550_tot,&
19       diag_aod670_tot, diag_aod865_tot, &
20       diff_aod550_tr2, diag_aod670_tr2, diag_aod865_tr2, &
21       diag_aod550_ss, diag_aod670_ss, diag_aod865_ss, &
22       diag_aod550_dust, diag_aod670_dust, diag_aod865_dust , &
23       diag_aod550_dustsco, diag_aod670_dustsco, diag_aod865_dustsco, &
24!       aod550_aqua, aod670_aqua, aod865_aqua, &
25!       aod550_terra, aod670_terra, aod865_terra, &
26       aod550_aqua,aod550_tr2_aqua,aod550_ss_aqua,aod550_dust_aqua,aod550_dustsco_aqua,&
27       aod670_aqua,aod670_tr2_aqua,aod670_ss_aqua,aod670_dust_aqua,aod670_dustsco_aqua,&
28       aod865_aqua,aod865_tr2_aqua,aod865_ss_aqua,aod865_dust_aqua,aod865_dustsco_aqua,&
29       aod550_terra,aod550_tr2_terra,aod550_ss_terra,aod550_dust_terra,aod550_dustsco_terra,&
30       aod670_terra,aod670_tr2_terra,aod670_ss_terra,aod670_dust_terra,aod670_dustsco_terra,&
31       aod865_terra,aod865_tr2_terra,aod865_ss_terra,aod865_dust_terra,aod865_dustsco_terra,&
32       trm01,trm02,trm03,trm04,trm05, &
33       sconc01,sconc02,sconc03,sconc04,sconc05, &
34       flux01,flux02,flux03,flux04,flux05,&
35       ds01,ds02,ds03,ds04,ds05, &
36       dh01,dh02,dh03,dh04,dh05, &
37       dtrconv01,dtrconv02,dtrconv03,dtrconv04,dtrconv05, &
38       dtherm01,dtherm02,dtherm03,dtherm04,dtherm05, &
39       dhkecv01,dhkecv02,dhkecv03,dhkecv04,dhkecv05, &
40       d_tr_ds01,d_tr_ds02,d_tr_ds03,d_tr_ds04,d_tr_ds05, &
41       dhkelsc01,dhkelsc02,dhkelsc03,dhkelsc04,dhkelsc05, &
42       d_tr_cv01,d_tr_cv02,d_tr_cv03,d_tr_cv04,d_tr_cv05, &
43       d_tr_trsp01,d_tr_trsp02,d_tr_trsp03,d_tr_trsp04,d_tr_trsp05, &
44       d_tr_sscav01,d_tr_sscav02,d_tr_sscav03,d_tr_sscav04,d_tr_sscav05, &
45       d_tr_sat01,d_tr_sat02,d_tr_sat03,d_tr_sat04,d_tr_sat05, &
46       d_tr_uscav01,d_tr_uscav02,d_tr_uscav03,d_tr_uscav04,d_tr_uscav05, &
47       d_tr_insc01,d_tr_insc02,d_tr_insc03,d_tr_insc04,d_tr_insc05, &
48       d_tr_bcscav01,d_tr_bcscav02,d_tr_bcscav03,d_tr_bcscav04,d_tr_bcscav05, &
49       d_tr_evapls01,d_tr_evapls02,d_tr_evapls03,d_tr_evapls04,d_tr_evapls05, &
50       d_tr_ls01,d_tr_ls02,d_tr_ls03,d_tr_ls04,d_tr_ls05, &
51       d_tr_dyn01,d_tr_dyn02,d_tr_dyn03,d_tr_dyn04,d_tr_dyn05, &
52       d_tr_cl01,d_tr_cl02,d_tr_cl03,d_tr_cl04,d_tr_cl05, &
53       d_tr_th01,d_tr_th02,d_tr_th03,d_tr_th04,d_tr_th05, &
54       sed_ss,sed_dust,sed_dustsco,his_g2pgas,his_g2paer, &
55       sed_ss3D,sed_dust3D,sed_dustsco3D, &
56       fluxbb, &
57       fluxff,fluxbcbb,fluxbcff,fluxbcnff, &
58       fluxbcba,fluxbc,fluxombb,fluxomff,fluxomnff, &
59       fluxomba,fluxomnat,fluxom,fluxh2sff,fluxh2snff, &
60       fluxso2ff,fluxso2nff,fluxso2bb,fluxso2vol,fluxso2ba, &
61       fluxso2,fluxso4ff,fluxso4nff,fluxso4ba,fluxso4bb, &
62       fluxso4,fluxdms,fluxh2sbio,fluxdustec,&
63       fluxddfine,  &
64       fluxddcoa,fluxddsco,fluxdd, &
65       fluxssfine,fluxsscoa, &
66       fluxss,flux_sparam_ind,flux_sparam_bb,flux_sparam_ff, &
67       flux_sparam_ddfine,flux_sparam_ddcoa, &
68       flux_sparam_ddsco,flux_sparam_ssfine, &
69       flux_sparam_sscoa,u10m_ss,v10m_ss
70
71  USE dustemission_mod, ONLY : m1dflux, m2dflux, m3dflux
72
73!  USE phytrac_mod, ONLY : d_tr_cl, d_tr_th, d_tr_cv, d_tr_lessi_impa, &
74!       d_tr_lessi_nucl, d_tr_insc, d_tr_bcscav, d_tr_evapls, d_tr_ls,  &
75!       d_tr_trsp, d_tr_sscav, d_tr_sat, d_tr_uscav
76
77!JE20150620>>
78
79  ! Author: Abderrahmane IDELKADI (original include file)
80  ! Author: Laurent FAIRHEAD (transformation to module/subroutine)
81  ! Author: Ulysse GERARD (effective implementation)
82
83CONTAINS
84
85  ! ug Routine pour définir (los du premier passageà) ET sortir les variables
86  SUBROUTINE phys_output_write_spl(itap, pdtphys, paprs, pphis, &
87       pplay, lmax_th, aerosol_couple,         &
88       ok_ade, ok_aie, ivap, new_aod, ok_sync, &
89       ptconv, read_climoz, clevSTD, ptconvth, &
90       d_t, qx, d_qx, d_tr_dyn, zmasse, flag_aerosol, flag_aerosol_strat, ok_cdnc)
91
92    ! This subroutine does the actual writing of diagnostics that were
93    ! defined and initialised in phys_output_mod.F90
94
95    USE dimphy, only: klon, klev, klevp1
96    USE ocean_slab_mod, ONLY: nslay
97    USE control_mod, only: day_step, iphysiq
98    USE phys_output_ctrlout_mod, only: o_phis, o_aire, is_ter, is_lic, is_oce, &
99         is_ave, is_sic, o_contfracATM, o_contfracOR, &
100         o_aireTER, o_flat, o_slp, o_tsol, &
101         o_t2m, o_t2m_min, o_t2m_max, &
102         o_t2m_min_mon, o_t2m_max_mon, &
103         o_q2m, o_ustar, o_u10m, o_v10m, &
104         o_wind10m, o_wind10max, o_gusts, o_sicf, &
105         o_psol, o_mass, o_qsurf, o_qsol, &
106         o_precip, o_ndayrain, o_plul, o_pluc, &
107         o_snow, o_msnow, o_fsnow, o_evap, &
108         o_tops, o_tops0, o_topl, o_topl0, &
109         o_SWupTOA, o_SWupTOAclr, o_SWdnTOA, &
110         o_SWdnTOAclr, o_nettop, o_SWup200, &
111         o_SWup200clr, o_SWdn200, o_SWdn200clr, &
112         o_LWup200, o_LWup200clr, o_LWdn200, &
113         o_LWdn200clr, o_sols, o_sols0, &
114         o_soll, o_radsol, o_soll0, o_SWupSFC, &
115         o_SWupSFCclr, o_SWdnSFC, o_SWdnSFCclr, &
116         o_LWupSFC, o_LWdnSFC, o_LWupSFCclr, &
117         o_LWdnSFCclr, o_bils, o_bils_diss, &
118         o_bils_ec,o_bils_ech, o_bils_tke, o_bils_kinetic, &
119         o_bils_latent, o_bils_enthalp, o_sens, &
120         o_fder, o_ffonte, o_fqcalving, o_fqfonte, &
121         o_taux, o_tauy, o_snowsrf, o_qsnow, &
122         o_snowhgt, o_toice, o_sissnow, o_runoff, &
123         o_albslw3, o_pourc_srf, o_fract_srf, &
124         o_taux_srf, o_tauy_srf, o_tsol_srf, &
125         o_evappot_srf, o_ustar_srf, o_u10m_srf, &
126         o_v10m_srf, o_t2m_srf, o_evap_srf, &
127         o_sens_srf, o_lat_srf, o_flw_srf, &
128         o_fsw_srf, o_wbils_srf, o_wbilo_srf, &
129         o_tke_srf, o_tke_max_srf,o_dltpbltke_srf, o_wstar, &
130         o_cdrm, o_cdrh, o_cldl, o_cldm, o_cldh, &
131         o_cldt, o_JrNt, o_cldljn, o_cldmjn, &
132         o_cldhjn, o_cldtjn, o_cldq, o_lwp, o_iwp, &
133         o_ue, o_ve, o_uq, o_vq, o_cape, o_pbase, &
134         o_ptop, o_fbase, o_plcl, o_plfc, &
135         o_wbeff, o_cape_max, o_upwd, o_Ma, &
136         o_dnwd, o_dnwd0, o_ftime_con, o_mc, &
137         o_prw, o_s_pblh, o_s_pblt, o_s_lcl, &
138         o_s_therm, o_uSTDlevs, o_vSTDlevs, &
139         o_wSTDlevs, o_zSTDlevs, o_qSTDlevs, &
140         o_tSTDlevs, epsfra, o_t_oce_sic, &
141         o_ale_bl, o_alp_bl, o_ale_wk, o_alp_wk, &
142         o_ale, o_alp, o_cin, o_WAPE, o_wake_h, &
143         o_wake_s, o_wake_deltat, o_wake_deltaq, &
144         o_wake_omg, o_dtwak, o_dqwak, o_Vprecip, &
145         o_ftd, o_fqd, o_wdtrainA, o_wdtrainM, &
146         o_n2, o_s2, o_proba_notrig, &
147         o_random_notrig, o_ale_bl_stat, &
148         o_ale_bl_trig, o_alp_bl_det, &
149         o_alp_bl_fluct_m, o_alp_bl_fluct_tke, &
150         o_alp_bl_conv, o_alp_bl_stat, &
151         o_slab_qflux, o_tslab, o_slab_bils, &
152         o_slab_bilg, o_slab_sic, o_slab_tice, &
153         o_weakinv, o_dthmin, o_cldtau, &
154         o_cldemi, o_pr_con_l, o_pr_con_i, &
155         o_pr_lsc_l, o_pr_lsc_i, o_re, o_fl, &
156         o_rh2m, o_rh2m_min, o_rh2m_max, &
157         o_qsat2m, o_tpot, o_tpote, o_SWnetOR, &
158         o_SWdownOR, o_LWdownOR, o_snowl, &
159         o_solldown, o_dtsvdfo, o_dtsvdft, &
160         o_dtsvdfg, o_dtsvdfi, o_z0m, o_z0h, o_od550aer, &
161         o_od865aer, o_absvisaer, o_od550lt1aer, &
162         o_sconcso4, o_sconcno3, o_sconcoa, o_sconcbc, &
163         o_sconcss, o_sconcdust, o_concso4, o_concno3, &
164         o_concoa, o_concbc, o_concss, o_concdust, &
165         o_loadso4, o_loadoa, o_loadbc, o_loadss, &
166         o_loaddust, o_tausumaero, o_tausumaero_lw, &
167         o_topswad, o_topswad0, o_solswad, o_solswad0, &
168         o_toplwad, o_toplwad0, o_sollwad, o_sollwad0, &
169         o_swtoaas_nat, o_swsrfas_nat, &
170         o_swtoacs_nat, o_swtoaas_ant, &
171         o_swsrfas_ant, o_swtoacs_ant, &
172         o_swsrfcs_ant, o_swtoacf_nat, &
173         o_swsrfcf_nat, o_swtoacf_ant, &
174         o_swsrfcs_nat, o_swsrfcf_ant, &
175         o_swtoacf_zero, o_swsrfcf_zero, &
176         o_topswai, o_solswai, o_scdnc, &
177         o_cldncl, o_reffclws, o_reffclwc, &
178         o_cldnvi, o_lcc, o_lcc3d, o_lcc3dcon, &
179         o_lcc3dstra, o_reffclwtop, o_ec550aer, &
180         o_lwcon, o_iwcon, o_temp, o_theta, &
181         o_ovapinit, o_ovap, o_oliq, o_geop, &
182         o_vitu, o_vitv, o_vitw, o_pres, o_paprs, &
183         o_zfull, o_zhalf, o_rneb, o_rnebjn, o_rnebcon, &
184         o_rnebls, o_rhum, o_ozone, o_ozone_light, &
185         o_dtphy, o_dqphy, o_albe_srf, o_z0m_srf, o_z0h_srf, &
186         o_ages_srf, o_snow_srf, o_alb1, o_alb2, o_tke, &
187         o_tke_max, o_kz, o_kz_max, o_clwcon, &
188         o_dtdyn, o_dqdyn, o_dudyn, o_dvdyn, &
189         o_dtcon, o_tntc, o_ducon, o_dvcon, &
190         o_dqcon, o_tnhusc, o_tnhusc, o_dtlsc, &
191         o_dtlschr, o_dqlsc, o_beta_prec, &
192         o_dtlscth, o_dtlscst, o_dqlscth, &
193         o_dqlscst, o_plulth, o_plulst, &
194         o_ptconvth, o_lmaxth, o_dtvdf, &
195         o_dtdis, o_dqvdf, o_dteva, o_dqeva, &
196         o_ptconv, o_ratqs, o_dtthe, &
197         o_duthe, o_dvthe, o_ftime_th, &
198         o_f_th, o_e_th, o_w_th, o_q_th, &
199         o_a_th, o_d_th, o_f0_th, o_zmax_th, &
200         o_dqthe, o_dtajs, o_dqajs, o_dtswr, &
201         o_dtsw0, o_dtlwr, o_dtlw0, o_dtec, &
202         o_duvdf, o_dvvdf, o_duoro, o_dvoro, &
203         o_dtoro, o_dulif, o_dvlif, o_dtlif, &
204 !       o_duhin, o_dvhin, o_dthin, &
205         o_dqch4, o_rsu, &
206         o_rsd, o_rlu, o_rld, o_rsucs, o_rsdcs, &
207         o_rlucs, o_rldcs, o_tnt, o_tntr, &
208         o_tntscpbl, o_tnhus, o_tnhusscpbl, &
209         o_evu, o_h2o, o_mcd, o_dmc, o_ref_liq, &
210         o_ref_ice, o_rsut4co2, o_rlut4co2, &
211         o_rsutcs4co2, o_rlutcs4co2, o_rsu4co2, &
212         o_rlu4co2, o_rsucs4co2, o_rlucs4co2, &
213         o_rsd4co2, o_rld4co2, o_rsdcs4co2, &
214         o_rldcs4co2, o_tnondef, o_ta, o_zg, &
215         o_hus, o_hur, o_ua, o_va, o_wap, &
216         o_psbg, o_tro3, o_tro3_daylight, &
217         o_uxv, o_vxq, o_vxT, o_wxq, o_vxphi, &
218         o_wxT, o_uxu, o_vxv, o_TxT, o_trac, &
219         o_dtr_vdf, o_dtr_the, o_dtr_con, &
220         o_dtr_lessi_impa, o_dtr_lessi_nucl, &
221         o_dtr_insc, o_dtr_bcscav, o_dtr_evapls, &
222!        o_dtr_ls, o_dtr_dyn, o_dtr_cl, o_dtr_trsp, o_dtr_sscav, &
223         o_dtr_ls, o_dtr_trsp, o_dtr_sscav, &
224         o_dtr_sat, o_dtr_uscav, o_trac_cum, o_du_gwd_rando, o_dv_gwd_rando, &
225!JE20150620<<
226!         o_vstr_gwd_rando
227         o_vstr_gwd_rando, &
228         o_m1dflux,o_m2dflux,o_m3dflux, &
229         o_taue550, &
230         o_taue670,o_taue865, &
231         o_taue550_tr2, o_taue670_tr2, o_taue865_tr2, &
232         o_taue550_ss,o_taue670_ss, o_taue865_ss, &
233         o_taue550_dust, o_taue670_dust, o_taue865_dust, &
234         o_taue550_dustsco, o_taue670_dustsco, o_taue865_dustsco, &
235         o_taue550_aqua, o_taue670_aqua, o_taue865_aqua, &
236         o_taue550_terra, o_taue670_terra, o_taue865_terra, &
237         o_taue550_fine_aqua     ,         o_taue670_fine_aqua     ,  &
238         o_taue865_fine_aqua     ,         o_taue550_coss_aqua      ,  &
239         o_taue670_coss_aqua      ,         o_taue865_coss_aqua      ,  &
240         o_taue550_codu_aqua    ,         o_taue670_codu_aqua    ,  &
241         o_taue865_codu_aqua    ,         o_taue670_scdu_aqua ,  &
242         o_taue550_scdu_aqua ,         o_taue865_scdu_aqua ,  &
243         o_taue550_fine_terra     ,         o_taue670_fine_terra     ,&
244         o_taue865_fine_terra     ,         o_taue550_coss_terra      ,&
245         o_taue670_coss_terra      ,         o_taue865_coss_terra      ,&
246         o_taue550_codu_terra    ,         o_taue670_codu_terra    ,&
247         o_taue865_codu_terra    ,         o_taue670_scdu_terra ,&
248         o_taue550_scdu_terra ,         o_taue865_scdu_terra ,&
249         o_trm01,o_trm02,o_trm03,o_trm04,o_trm05,&
250         o_sconc01,o_sconc02,o_sconc03,o_sconc04,o_sconc05, &
251         o_flux01,o_flux02,o_flux03,o_flux04,o_flux05, &
252         o_ds01,o_ds02,o_ds03,o_ds04,o_ds05, &
253         o_dh01,o_dh02,o_dh03,o_dh04,o_dh05, &
254         o_dtrconv01,o_dtrconv02,o_dtrconv03,o_dtrconv04,o_dtrconv05, &
255         o_dtherm01,o_dtherm02,o_dtherm03,o_dtherm04,o_dtherm05, &
256         o_dhkecv01,o_dhkecv02,o_dhkecv03,o_dhkecv04,o_dhkecv05, &
257         o_d_tr_ds01,o_d_tr_ds02,o_d_tr_ds03,o_d_tr_ds04,o_d_tr_ds05, &
258         o_dhkelsc01,o_dhkelsc02,o_dhkelsc03,o_dhkelsc04,o_dhkelsc05, &
259         o_d_tr_sat01,o_d_tr_cv01,o_d_tr_cv02,o_d_tr_cv03,o_d_tr_cv04,o_d_tr_cv05,&
260         o_d_tr_trsp01,o_d_tr_trsp02,o_d_tr_trsp03,o_d_tr_trsp04,o_d_tr_trsp05,&
261         o_d_tr_sscav01,o_d_tr_sscav02,o_d_tr_sscav03,o_d_tr_sscav04,o_d_tr_sscav05,&
262         o_d_tr_sat02,o_d_tr_sat03,o_d_tr_sat04,o_d_tr_sat05,  &
263         o_d_tr_uscav01,o_d_tr_uscav02,o_d_tr_uscav03,o_d_tr_uscav04,o_d_tr_uscav05,&
264         o_d_tr_insc01,o_d_tr_insc02,o_d_tr_insc03,o_d_tr_insc04,o_d_tr_insc05,&
265         o_d_tr_bcscav01,o_d_tr_bcscav02,o_d_tr_bcscav03,o_d_tr_bcscav04,o_d_tr_bcscav05,&
266         o_d_tr_evapls01,o_d_tr_evapls02,o_d_tr_evapls03,o_d_tr_evapls04,o_d_tr_evapls05,&
267         o_d_tr_ls01,o_d_tr_ls02,o_d_tr_ls03,o_d_tr_ls04,o_d_tr_ls05,&
268         o_d_tr_dyn01,o_d_tr_dyn02,o_d_tr_dyn03,o_d_tr_dyn04,o_d_tr_dyn05,&
269         o_d_tr_cl01,o_d_tr_cl02,o_d_tr_cl03,o_d_tr_cl04,o_d_tr_cl05,&
270         o_d_tr_th01,o_d_tr_th02,o_d_tr_th03,o_d_tr_th04,o_d_tr_th05,&
271         o_sed_ss,o_sed_dust,o_sed_dustsco,o_g2p_gas,o_g2p_aer, &
272         o_sed_ss3D,o_sed_dust3D,o_sed_dustsco3D, &
273         o_fluxbb, &
274         o_fluxff    ,o_fluxbcbb  ,o_fluxbcff  ,o_fluxbcnff , &
275         o_fluxbcba  ,o_fluxbc    ,o_fluxombb  ,o_fluxomff  , &
276         o_fluxomnff ,o_fluxomba  ,o_fluxomnat ,o_fluxom    , &
277         o_fluxh2sff ,o_fluxh2snff,o_fluxso2ff ,o_fluxso2nff, &
278         o_fluxso2bb ,o_fluxso2vol,o_fluxso2ba ,o_fluxso2   , &
279         o_fluxso4ff ,o_fluxso4nff,o_fluxso4bb ,o_fluxso4ba , &
280         o_fluxso4   ,o_fluxdms   ,o_fluxh2sbio,o_fluxdustec, &
281         o_fluxddfine,o_fluxddcoa ,o_fluxddsco ,o_fluxdd    ,&
282         o_fluxssfine,o_fluxsscoa, o_fluxss, &
283         o_flux_sparam_ind,o_flux_sparam_bb, &
284         o_flux_sparam_ff ,o_flux_sparam_ddfine  ,o_flux_sparam_ddcoa, &
285         o_flux_sparam_ddsco,o_flux_sparam_ssfine,o_flux_sparam_sscoa, &
286         o_u10m_ss,o_v10m_ss
287
288!JE20150620>>
289
290    USE phys_state_var_mod, only: pctsrf, paire_ter, rain_fall, snow_fall, &
291         qsol, z0m, z0h, fevap, agesno, &
292         nday_rain, rain_con, snow_con, &
293         topsw, toplw, toplw0, swup, swdn, &
294         topsw0, swup0, swdn0, SWup200, SWup200clr, &
295         SWdn200, SWdn200clr, LWup200, LWup200clr, &
296         LWdn200, LWdn200clr, solsw, solsw0, sollw, &
297         radsol, sollw0, sollwdown, sollw, gustiness, &
298         sollwdownclr, lwdn0, ftsol, ustar, u10m, &
299         v10m, pbl_tke, wake_delta_pbl_TKE, &
300         wstar, cape, ema_pcb, ema_pct, &
301         ema_cbmf, Ma, fm_therm, ale_bl, alp_bl, ale, &
302         alp, cin, wake_pe, wake_s, wake_deltat, &
303         wake_deltaq, ftd, fqd, ale_bl_trig, albsol1, &
304         rnebcon, wo, falb1, albsol2, coefh, clwcon0, &
305         ratqs, entr_therm, zqasc, detr_therm, f0, &
306         lwup, lwdn, lwup0, coefm, &
307         swupp, lwupp, swup0p, lwup0p, swdnp, lwdnp, &
308         swdn0p, lwdn0p, tnondef, O3sumSTD, uvsumSTD, &
309         vqsumSTD, vTsumSTD, O3daysumSTD, wqsumSTD, &
310         vphisumSTD, wTsumSTD, u2sumSTD, v2sumSTD, &
311         T2sumSTD, nlevSTD, &
312!        du_gwd_rando, dv_gwd_rando, &
313         ulevSTD, vlevSTD, wlevSTD, philevSTD, qlevSTD, tlevSTD, &
314         rhlevSTD, O3STD, O3daySTD, uvSTD, vqSTD, vTSTD, wqSTD, &
315         vphiSTD, wTSTD, u2STD, v2STD, T2STD, missing_val_nf90
316
317    USE phys_local_var_mod, only: zxfluxlat, slp, zxtsol, zt2m, &
318         t2m_min_mon, t2m_max_mon, evap, &
319         zu10m, zv10m, zq2m, zustar, zxqsurf, &
320         rain_lsc, snow_lsc, bils, sens, fder, &
321         zxffonte, zxfqcalving, zxfqfonte, fluxu, &
322         fluxv, zxsnow, qsnow, snowhgt, to_ice, &
323         sissnow, runoff, albsol3_lic, evap_pot, &
324         t2m, fluxt, fluxlat, fsollw, fsolsw, &
325         wfbils, wfbilo, cdragm, cdragh, cldl, cldm, &
326         cldh, cldt, JrNt, cldljn, cldmjn, cldhjn, &
327         cldtjn, cldq, flwp, fiwp, ue, ve, uq, vq, &
328         plcl, plfc, wbeff, upwd, dnwd, dnwd0, prw, &
329         s_pblh, s_pblt, s_lcl, s_therm, uwriteSTD, &
330         vwriteSTD, wwriteSTD, phiwriteSTD, qwriteSTD, &
331         twriteSTD, ale_wake, alp_wake, wake_h, &
332         wake_omg, d_t_wake, d_q_wake, Vprecip, &
333         wdtrainA, wdtrainM, n2, s2, proba_notrig, &
334         random_notrig, ale_bl_stat, &
335         alp_bl_det, alp_bl_fluct_m, alp_bl_conv, &
336         alp_bl_stat, alp_bl_fluct_tke, slab_wfbils, &
337         weak_inversion, dthmin, cldtau, cldemi, &
338         pmflxr, pmflxs, prfl, psfl, re, fl, rh2m, &
339         qsat2m, tpote, tpot, d_ts, od550aer, &
340         od865aer, absvisaer, od550lt1aer, sconcso4, sconcno3, &
341         sconcoa, sconcbc, sconcss, sconcdust, concso4, concno3, &
342         concoa, concbc, concss, concdust, loadso4, &
343         loadoa, loadbc, loadss, loaddust, tausum_aero, &
344         topswad_aero, topswad0_aero, solswad_aero, &
345         solswad0_aero, topsw_aero, solsw_aero, &
346         topsw0_aero, solsw0_aero, topswcf_aero, &
347         solswcf_aero, topswai_aero, solswai_aero, &
348         toplwad_aero, toplwad0_aero, sollwad_aero, &
349         sollwad0_aero, toplwai_aero, sollwai_aero, &
350         scdnc, cldncl, reffclws, reffclwc, cldnvi, &
351         lcc, lcc3d, lcc3dcon, lcc3dstra, reffclwtop, &
352         ec550aer, flwc, fiwc, t_seri, theta, q_seri, &
353!jyg<
354!!         ql_seri, zphi, u_seri, v_seri, omega, cldfra, &
355         ql_seri, tr_seri, &
356         zphi, u_seri, v_seri, omega, cldfra, &
357!>jyg
358         rneb, rnebjn, zx_rh, d_t_dyn, d_q_dyn, &
359         d_u_dyn, d_v_dyn, d_t_con, d_t_ajsb, d_t_ajs, &
360         d_u_ajs, d_v_ajs, &
361         d_u_con, d_v_con, d_q_con, d_q_ajs, d_t_lsc, &
362         d_t_lwr,d_t_lw0,d_t_swr,d_t_sw0, &
363         d_t_eva, d_q_lsc, beta_prec, d_t_lscth, &
364         d_t_lscst, d_q_lscth, d_q_lscst, plul_th, &
365         plul_st, d_t_vdf, d_t_diss, d_q_vdf, d_q_eva, &
366         zw2, fraca, zmax_th, d_q_ajsb, d_t_ec, d_u_vdf, &
367         d_v_vdf, d_u_oro, d_v_oro, d_t_oro, d_u_lif, &
368         d_v_lif, d_t_lif, &
369!        d_u_hin, d_v_hin, d_t_hin, &
370         d_q_ch4, pmfd, pmfu, ref_liq, ref_ice, rhwriteSTD
371
372    USE phys_output_var_mod, only: vars_defined, snow_o, zfra_o, bils_diss, &
373         bils_ec,bils_ech, bils_tke, bils_kinetic, bils_latent, bils_enthalp, &
374         itau_con, nfiles, clef_files, nid_files, zvstr_gwd_rando
375    USE ocean_slab_mod, only: tslab, slab_bils, slab_bilg, tice, seaice
376    USE pbl_surface_mod, only: snow
377    USE indice_sol_mod, only: nbsrf
378    USE infotrac, only: nqtot, nqo, nbtr, type_trac
379    USE geometry_mod, only: cell_area
380    USE surface_data, only: type_ocean, version_ocean, ok_veget, ok_snow
381!    USE aero_mod, only: naero_spc
382    USE aero_mod, only: naero_tot, id_STRAT_phy
383    USE ioipsl, only: histend, histsync
384    USE iophy, only: set_itau_iophy, histwrite_phy
385    USE netcdf, only: nf90_fill_real
386
387#ifdef CPP_XIOS
388    ! ug Pour les sorties XIOS
389    USE xios, ONLY: xios_update_calendar
390    USE wxios, only: wxios_closedef, missing_val
391#endif
392    USE phys_cal_mod, only : mth_len
393
394
395    IMPLICIT NONE
396
397
398!   INCLUDE "temps.h"
399    INCLUDE "clesphys.h"
400    INCLUDE "thermcell.h"
401    INCLUDE "compbl.h"
402    INCLUDE "YOMCST.h"
403    INCLUDE "dimensions.h"
404    include "iniprint.h"
405
406    ! Input
407    INTEGER :: itap, ivap, read_climoz
408    INTEGER, DIMENSION(klon) :: lmax_th
409    LOGICAL :: aerosol_couple, ok_sync
410    LOGICAL :: ok_ade, ok_aie, new_aod
411    LOGICAL, DIMENSION(klon, klev) :: ptconv, ptconvth
412    REAL :: pdtphys
413    CHARACTER (LEN=4), DIMENSION(nlevSTD) :: clevSTD
414    REAL, DIMENSION(klon,nlevSTD) :: zx_tmp_fi3d_STD
415    REAL, DIMENSION(klon) :: pphis
416    REAL, DIMENSION(klon, klev) :: pplay, d_t
417    REAL, DIMENSION(klon, klev+1) :: paprs
418    REAL, DIMENSION(klon,klev,nqtot) :: qx, d_qx
419    REAL,DIMENSION(klon,klev,nbtr),INTENT(IN)    :: d_tr_dyn
420    REAL, DIMENSION(klon, llm) :: zmasse
421    INTEGER :: flag_aerosol_strat
422    INTEGER :: flag_aerosol
423    LOGICAL :: ok_cdnc
424    REAL, DIMENSION(3) :: freq_moyNMC
425
426    ! Local
427    INTEGER, PARAMETER :: jjmp1=jjm+1-1/jjm
428    INTEGER :: itau_w
429    INTEGER :: i, iinit, iinitend=1, iff, iq, nsrf, k, ll, naero
430    REAL, DIMENSION (klon) :: zx_tmp_fi2d
431    REAL, DIMENSION (klon,klev) :: zx_tmp_fi3d, zpt_conv
432    REAL, DIMENSION (klon,klev+1) :: zx_tmp_fi3d1
433    CHARACTER (LEN=4)              :: bb2
434    INTEGER, DIMENSION(iim*jjmp1)  :: ndex2d
435    INTEGER, DIMENSION(iim*jjmp1*klev) :: ndex3d
436    REAL, PARAMETER :: dobson_u = 2.1415e-05 ! Dobson unit, in kg m-2
437!   REAL, PARAMETER :: missing_val=nf90_fill_real
438#ifndef CPP_XIOS
439    REAL :: missing_val
440#endif
441    REAL, PARAMETER :: un_jour=86400.
442
443    ! On calcul le nouveau tau:
444    itau_w = itau_phy + itap
445    ! On le donne à iophy pour que les histwrite y aient accès:
446    CALL set_itau_iophy(itau_w)
447
448    IF(.NOT.vars_defined) THEN
449       iinitend = 2
450    ELSE
451       iinitend = 1
452    ENDIF
453
454    ! ug la boucle qui suit ne sert qu'une fois, pour l'initialisation, sinon il n'y a toujours qu'un seul passage:
455    DO iinit=1, iinitend
456#ifdef CPP_XIOS
457       !$OMP MASTER
458       IF (vars_defined) THEN
459          if (prt_level >= 10) then
460             write(lunout,*)"phys_output_write: call xios_update_calendar, itau_w=",itau_w
461          endif
462!          CALL xios_update_calendar(itau_w)
463          CALL xios_update_calendar(itap)
464       END IF
465       !$OMP END MASTER
466       !$OMP BARRIER
467#endif
468       ! On procède à l'écriture ou à la définition des nombreuses variables:
469!!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
470       CALL histwrite_phy(o_phis, pphis)
471       CALL histwrite_phy(o_aire, cell_area)
472
473       IF (vars_defined) THEN
474          DO i=1, klon
475             zx_tmp_fi2d(i)=pctsrf(i,is_ter)+pctsrf(i,is_lic)
476          ENDDO
477       ENDIF
478
479       CALL histwrite_phy(o_contfracATM, zx_tmp_fi2d)
480       CALL histwrite_phy(o_contfracOR, pctsrf(:,is_ter))
481       CALL histwrite_phy(o_aireTER, paire_ter)
482
483!!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
484! JE20141223 <<
485#include "spla_output_write.h"
486! JE20141223 >>
487
488       CALL histwrite_phy(o_flat, zxfluxlat)
489       CALL histwrite_phy(o_slp, slp)
490       CALL histwrite_phy(o_tsol, zxtsol)
491       CALL histwrite_phy(o_t2m, zt2m)
492       CALL histwrite_phy(o_t2m_min, zt2m)
493       CALL histwrite_phy(o_t2m_max, zt2m)
494       CALL histwrite_phy(o_t2m_max_mon, t2m_max_mon)
495       CALL histwrite_phy(o_t2m_min_mon, t2m_min_mon)
496
497       IF (vars_defined) THEN
498          DO i=1, klon
499             zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
500          ENDDO
501       ENDIF
502       CALL histwrite_phy(o_wind10m, zx_tmp_fi2d)
503
504       IF (vars_defined) THEN
505          DO i=1, klon
506             zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
507          ENDDO
508       ENDIF
509       CALL histwrite_phy(o_wind10max, zx_tmp_fi2d)
510
511       CALL histwrite_phy(o_gusts, gustiness)
512
513       IF (vars_defined) THEN
514          DO i = 1, klon
515             zx_tmp_fi2d(i) = pctsrf(i,is_sic)
516          ENDDO
517       ENDIF
518       CALL histwrite_phy(o_sicf, zx_tmp_fi2d)
519       CALL histwrite_phy(o_q2m, zq2m)
520       CALL histwrite_phy(o_ustar, zustar)
521       CALL histwrite_phy(o_u10m, zu10m)
522       CALL histwrite_phy(o_v10m, zv10m)
523
524       IF (vars_defined) THEN
525          DO i = 1, klon
526             zx_tmp_fi2d(i) = paprs(i,1)
527          ENDDO
528       ENDIF
529       CALL histwrite_phy(o_psol, zx_tmp_fi2d)
530       CALL histwrite_phy(o_mass, zmasse)
531       CALL histwrite_phy(o_qsurf, zxqsurf)
532
533       IF (.NOT. ok_veget) THEN
534          CALL histwrite_phy(o_qsol, qsol)
535       ENDIF
536
537       IF (vars_defined) THEN
538          DO i = 1, klon
539             zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
540          ENDDO
541       ENDIF
542
543       CALL histwrite_phy(o_precip, zx_tmp_fi2d)
544       CALL histwrite_phy(o_ndayrain, nday_rain)
545
546       IF (vars_defined) THEN
547          DO i = 1, klon
548             zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
549          ENDDO
550       ENDIF
551       CALL histwrite_phy(o_plul, zx_tmp_fi2d)
552
553       IF (vars_defined) THEN
554          DO i = 1, klon
555             zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
556          ENDDO
557       ENDIF
558       CALL histwrite_phy(o_pluc, zx_tmp_fi2d)
559       CALL histwrite_phy(o_snow, snow_fall)
560       CALL histwrite_phy(o_msnow, zxsnow)
561       CALL histwrite_phy(o_fsnow, zfra_o)
562       CALL histwrite_phy(o_evap, evap)
563       CALL histwrite_phy(o_tops, topsw)
564       CALL histwrite_phy(o_tops0, topsw0)
565       CALL histwrite_phy(o_topl, toplw)
566       CALL histwrite_phy(o_topl0, toplw0)
567
568       IF (vars_defined) THEN
569          zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
570       ENDIF
571       CALL histwrite_phy(o_SWupTOA, zx_tmp_fi2d)
572
573       IF (vars_defined) THEN
574          zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
575       ENDIF
576       CALL histwrite_phy(o_SWupTOAclr, zx_tmp_fi2d)
577
578       IF (vars_defined) THEN
579          zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
580       ENDIF
581       CALL histwrite_phy(o_SWdnTOA, zx_tmp_fi2d)
582
583       IF (vars_defined) THEN
584          zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
585       ENDIF
586       CALL histwrite_phy(o_SWdnTOAclr, zx_tmp_fi2d)
587
588       IF (vars_defined) THEN
589          zx_tmp_fi2d(:) = topsw(:)-toplw(:)
590       ENDIF
591       CALL histwrite_phy(o_nettop, zx_tmp_fi2d)
592       CALL histwrite_phy(o_SWup200, SWup200)
593       CALL histwrite_phy(o_SWup200clr, SWup200clr)
594       CALL histwrite_phy(o_SWdn200, SWdn200)
595       CALL histwrite_phy(o_SWdn200clr, SWdn200clr)
596       CALL histwrite_phy(o_LWup200, LWup200)
597       CALL histwrite_phy(o_LWup200clr, LWup200clr)
598       CALL histwrite_phy(o_LWdn200, LWdn200)
599       CALL histwrite_phy(o_LWdn200clr, LWdn200clr)
600       CALL histwrite_phy(o_sols, solsw)
601       CALL histwrite_phy(o_sols0, solsw0)
602       CALL histwrite_phy(o_soll, sollw)
603       CALL histwrite_phy(o_radsol, radsol)
604       CALL histwrite_phy(o_soll0, sollw0)
605
606       IF (vars_defined) THEN
607          zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
608       ENDIF
609       CALL histwrite_phy(o_SWupSFC, zx_tmp_fi2d)
610
611       IF (vars_defined) THEN
612          zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 1 )
613       ENDIF
614       CALL histwrite_phy(o_SWupSFCclr, zx_tmp_fi2d)
615
616       IF (vars_defined) THEN
617          zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
618       ENDIF
619       CALL histwrite_phy(o_SWdnSFC, zx_tmp_fi2d)
620
621       IF (vars_defined) THEN
622          zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 1 )
623       ENDIF
624       CALL histwrite_phy(o_SWdnSFCclr, zx_tmp_fi2d)
625
626       IF (vars_defined) THEN
627          zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
628       ENDIF
629       CALL histwrite_phy(o_LWupSFC, zx_tmp_fi2d)
630       CALL histwrite_phy(o_LWdnSFC, sollwdown)
631
632       IF (vars_defined) THEN
633          sollwdownclr(1:klon) = -1.*lwdn0(1:klon,1)
634          zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
635       ENDIF
636       CALL histwrite_phy(o_LWupSFCclr, zx_tmp_fi2d)
637       CALL histwrite_phy(o_LWdnSFCclr, sollwdownclr)
638       CALL histwrite_phy(o_bils, bils)
639       CALL histwrite_phy(o_bils_diss, bils_diss)
640       CALL histwrite_phy(o_bils_ec, bils_ec)
641       IF (iflag_ener_conserv>=1) THEN
642         CALL histwrite_phy(o_bils_ech, bils_ech)
643       ENDIF
644       CALL histwrite_phy(o_bils_tke, bils_tke)
645       CALL histwrite_phy(o_bils_kinetic, bils_kinetic)
646       CALL histwrite_phy(o_bils_latent, bils_latent)
647       CALL histwrite_phy(o_bils_enthalp, bils_enthalp)
648
649       IF (vars_defined) THEN
650          zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
651       ENDIF
652       CALL histwrite_phy(o_sens, zx_tmp_fi2d)
653       CALL histwrite_phy(o_fder, fder)
654       CALL histwrite_phy(o_ffonte, zxffonte)
655       CALL histwrite_phy(o_fqcalving, zxfqcalving)
656       CALL histwrite_phy(o_fqfonte, zxfqfonte)
657       IF (vars_defined) THEN
658          zx_tmp_fi2d=0.
659          DO nsrf=1,nbsrf
660             zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxu(:,1,nsrf)
661          ENDDO
662       ENDIF
663       CALL histwrite_phy(o_taux, zx_tmp_fi2d)
664
665       IF (vars_defined) THEN
666          zx_tmp_fi2d=0.
667          DO nsrf=1,nbsrf
668             zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxv(:,1,nsrf)
669          ENDDO
670       ENDIF
671       CALL histwrite_phy(o_tauy, zx_tmp_fi2d)
672
673       IF (ok_snow) THEN
674          CALL histwrite_phy(o_snowsrf, snow_o)
675          CALL histwrite_phy(o_qsnow, qsnow)
676          CALL histwrite_phy(o_snowhgt,snowhgt)
677          CALL histwrite_phy(o_toice,to_ice)
678          CALL histwrite_phy(o_sissnow,sissnow)
679          CALL histwrite_phy(o_runoff,runoff)
680          CALL histwrite_phy(o_albslw3,albsol3_lic)
681       ENDIF
682
683       DO nsrf = 1, nbsrf
684          IF (vars_defined)             zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
685          CALL histwrite_phy(o_pourc_srf(nsrf), zx_tmp_fi2d)
686          IF (vars_defined)           zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
687          CALL histwrite_phy(o_fract_srf(nsrf), zx_tmp_fi2d)
688          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
689          CALL histwrite_phy(o_taux_srf(nsrf), zx_tmp_fi2d)
690          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
691          CALL histwrite_phy(o_tauy_srf(nsrf), zx_tmp_fi2d)
692          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
693          CALL histwrite_phy(o_tsol_srf(nsrf), zx_tmp_fi2d)
694          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = evap_pot( 1 : klon, nsrf)
695          CALL histwrite_phy(o_evappot_srf(nsrf), zx_tmp_fi2d)
696          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = ustar(1 : klon, nsrf)
697          CALL histwrite_phy(o_ustar_srf(nsrf), zx_tmp_fi2d)
698          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = u10m(1 : klon, nsrf)
699          CALL histwrite_phy(o_u10m_srf(nsrf), zx_tmp_fi2d)
700          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = v10m(1 : klon, nsrf)
701          CALL histwrite_phy(o_v10m_srf(nsrf), zx_tmp_fi2d)
702          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = t2m(1 : klon, nsrf)
703          CALL histwrite_phy(o_t2m_srf(nsrf), zx_tmp_fi2d)
704          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = fevap(1 : klon, nsrf)
705          CALL histwrite_phy(o_evap_srf(nsrf), zx_tmp_fi2d)
706          IF (vars_defined)        zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
707          CALL histwrite_phy(o_sens_srf(nsrf), zx_tmp_fi2d)
708          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
709          CALL histwrite_phy(o_lat_srf(nsrf), zx_tmp_fi2d)
710          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
711          CALL histwrite_phy(o_flw_srf(nsrf), zx_tmp_fi2d)
712          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
713          CALL histwrite_phy(o_fsw_srf(nsrf), zx_tmp_fi2d)
714          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
715          CALL histwrite_phy(o_wbils_srf(nsrf), zx_tmp_fi2d)
716          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfbilo( 1 : klon, nsrf)
717          CALL histwrite_phy(o_wbilo_srf(nsrf), zx_tmp_fi2d)
718
719          IF (iflag_pbl > 1) THEN
720             CALL histwrite_phy(o_tke_srf(nsrf),  pbl_tke(:,1:klev,nsrf))
721             CALL histwrite_phy(o_tke_max_srf(nsrf),  pbl_tke(:,1:klev,nsrf))
722          ENDIF
723!jyg<
724          IF (iflag_pbl > 1 .AND. iflag_wake>=1  .AND. iflag_pbl_split >=1) THEN
725             CALL histwrite_phy(o_dltpbltke_srf(nsrf), wake_delta_pbl_TKE(:,1:klev,nsrf))
726          ENDIF
727!>jyg
728
729       ENDDO
730       DO nsrf=1,nbsrf+1
731          CALL histwrite_phy(o_wstar(nsrf), wstar(1 : klon, nsrf))
732       ENDDO
733
734       CALL histwrite_phy(o_cdrm, cdragm)
735       CALL histwrite_phy(o_cdrh, cdragh)
736       CALL histwrite_phy(o_cldl, cldl)
737       CALL histwrite_phy(o_cldm, cldm)
738       CALL histwrite_phy(o_cldh, cldh)
739       CALL histwrite_phy(o_cldt, cldt)
740       CALL histwrite_phy(o_JrNt, JrNt)
741       CALL histwrite_phy(o_cldljn, cldl*JrNt)
742       CALL histwrite_phy(o_cldmjn, cldm*JrNt)
743       CALL histwrite_phy(o_cldhjn, cldh*JrNt)
744       CALL histwrite_phy(o_cldtjn, cldt*JrNt)
745       CALL histwrite_phy(o_cldq, cldq)
746       IF (vars_defined)       zx_tmp_fi2d(1:klon) = flwp(1:klon)
747       CALL histwrite_phy(o_lwp, zx_tmp_fi2d)
748       IF (vars_defined)       zx_tmp_fi2d(1:klon) = fiwp(1:klon)
749       CALL histwrite_phy(o_iwp, zx_tmp_fi2d)
750       CALL histwrite_phy(o_ue, ue)
751       CALL histwrite_phy(o_ve, ve)
752       CALL histwrite_phy(o_uq, uq)
753       CALL histwrite_phy(o_vq, vq)
754       IF(iflag_con.GE.3) THEN ! sb
755          CALL histwrite_phy(o_cape, cape)
756          CALL histwrite_phy(o_pbase, ema_pcb)
757          CALL histwrite_phy(o_ptop, ema_pct)
758          CALL histwrite_phy(o_fbase, ema_cbmf)
759          if (iflag_con /= 30) then
760             CALL histwrite_phy(o_plcl, plcl)
761             CALL histwrite_phy(o_plfc, plfc)
762             CALL histwrite_phy(o_wbeff, wbeff)
763          end if
764
765          CALL histwrite_phy(o_cape_max, cape)
766
767          CALL histwrite_phy(o_upwd, upwd)
768          CALL histwrite_phy(o_Ma, Ma)
769          CALL histwrite_phy(o_dnwd, dnwd)
770          CALL histwrite_phy(o_dnwd0, dnwd0)
771          IF (vars_defined)         zx_tmp_fi2d=float(itau_con)/float(itap)
772          CALL histwrite_phy(o_ftime_con, zx_tmp_fi2d)
773          IF (vars_defined) THEN
774             IF(iflag_thermals>=1)THEN
775                zx_tmp_fi3d=dnwd+dnwd0+upwd+fm_therm(:,1:klev)
776             ELSE
777                zx_tmp_fi3d=dnwd+dnwd0+upwd
778             ENDIF
779          ENDIF
780          CALL histwrite_phy(o_mc, zx_tmp_fi3d)
781       ENDIF !iflag_con .GE. 3
782       CALL histwrite_phy(o_prw, prw)
783       CALL histwrite_phy(o_s_pblh, s_pblh)
784       CALL histwrite_phy(o_s_pblt, s_pblt)
785       CALL histwrite_phy(o_s_lcl, s_lcl)
786       CALL histwrite_phy(o_s_therm, s_therm)
787       !IM : Les champs suivants (s_capCL, s_oliqCL, s_cteiCL, s_trmb1, s_trmb2, s_trmb3) ne sont pas definis dans HBTM.F
788       !       IF (o_s_capCL%flag(iff)<=lev_files(iff)) THEN
789       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
790       !    $o_s_capCL%name,itau_w,s_capCL)
791       !       ENDIF
792       !       IF (o_s_oliqCL%flag(iff)<=lev_files(iff)) THEN
793       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
794       !    $o_s_oliqCL%name,itau_w,s_oliqCL)
795       !       ENDIF
796       !       IF (o_s_cteiCL%flag(iff)<=lev_files(iff)) THEN
797       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
798       !    $o_s_cteiCL%name,itau_w,s_cteiCL)
799       !       ENDIF
800       !       IF (o_s_trmb1%flag(iff)<=lev_files(iff)) THEN
801       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
802       !    $o_s_trmb1%name,itau_w,s_trmb1)
803       !       ENDIF
804       !       IF (o_s_trmb2%flag(iff)<=lev_files(iff)) THEN
805       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
806       !    $o_s_trmb2%name,itau_w,s_trmb2)
807       !       ENDIF
808       !       IF (o_s_trmb3%flag(iff)<=lev_files(iff)) THEN
809       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
810       !    $o_s_trmb3%name,itau_w,s_trmb3)
811       !       ENDIF
812
813#ifdef CPP_IOIPSL
814#ifndef CPP_XIOS
815  IF (.NOT.ok_all_xml) THEN
816       ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
817       ! Champs interpolles sur des niveaux de pression
818       missing_val=missing_val_nf90
819       DO iff=1, nfiles
820          ll=0
821          DO k=1, nlevSTD
822             bb2=clevSTD(k)
823             IF(bb2.EQ."850".OR.bb2.EQ."700".OR. &
824                  bb2.EQ."500".OR.bb2.EQ."200".OR. &
825                  bb2.EQ."100".OR. &
826                  bb2.EQ."50".OR.bb2.EQ."10") THEN
827
828                ! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
829                ll=ll+1
830                CALL histwrite_phy(o_uSTDlevs(ll),uwriteSTD(:,k,iff), iff)
831                CALL histwrite_phy(o_vSTDlevs(ll),vwriteSTD(:,k,iff), iff)
832                CALL histwrite_phy(o_wSTDlevs(ll),wwriteSTD(:,k,iff), iff)
833                CALL histwrite_phy(o_zSTDlevs(ll),phiwriteSTD(:,k,iff), iff)
834                CALL histwrite_phy(o_qSTDlevs(ll),qwriteSTD(:,k,iff), iff)
835                CALL histwrite_phy(o_tSTDlevs(ll),twriteSTD(:,k,iff), iff)
836
837             ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
838          ENDDO
839       ENDDO
840  ENDIF
841#endif
842#endif
843#ifdef CPP_XIOS
844  IF(ok_all_xml) THEN
845!XIOS  CALL xios_get_field_attr("u850",default_value=missing_val)
846!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
847          ll=0
848          DO k=1, nlevSTD
849             bb2=clevSTD(k)
850             IF(bb2.EQ."850".OR.bb2.EQ."700".OR. &
851                bb2.EQ."500".OR.bb2.EQ."200".OR. &
852                bb2.EQ."100".OR. &
853                bb2.EQ."50".OR.bb2.EQ."10") THEN
854                ll=ll+1
855                CALL histwrite_phy(o_uSTDlevs(ll),ulevSTD(:,k))
856                CALL histwrite_phy(o_vSTDlevs(ll),vlevSTD(:,k))
857                CALL histwrite_phy(o_wSTDlevs(ll),wlevSTD(:,k))
858                CALL histwrite_phy(o_zSTDlevs(ll),philevSTD(:,k))
859                CALL histwrite_phy(o_qSTDlevs(ll),qlevSTD(:,k))
860                CALL histwrite_phy(o_tSTDlevs(ll),tlevSTD(:,k))
861             ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
862          ENDDO
863  ENDIF
864#endif
865       IF (vars_defined) THEN
866          DO i=1, klon
867             IF (pctsrf(i,is_oce).GT.epsfra.OR. &
868                  pctsrf(i,is_sic).GT.epsfra) THEN
869                zx_tmp_fi2d(i) = (ftsol(i, is_oce) * pctsrf(i,is_oce)+ &
870                     ftsol(i, is_sic) * pctsrf(i,is_sic))/ &
871                     (pctsrf(i,is_oce)+pctsrf(i,is_sic))
872             ELSE
873                zx_tmp_fi2d(i) = 273.15
874             ENDIF
875          ENDDO
876       ENDIF
877       CALL histwrite_phy(o_t_oce_sic, zx_tmp_fi2d)
878
879       ! Couplage convection-couche limite
880       IF (iflag_con.GE.3) THEN
881          IF (iflag_coupl>=1) THEN
882             CALL histwrite_phy(o_ale_bl, ale_bl)
883             CALL histwrite_phy(o_alp_bl, alp_bl)
884          ENDIF !iflag_coupl>=1
885       ENDIF !(iflag_con.GE.3)
886       ! Wakes
887       IF (iflag_con.EQ.3) THEN
888          IF (iflag_wake>=1) THEN
889             CALL histwrite_phy(o_ale_wk, ale_wake)
890             CALL histwrite_phy(o_alp_wk, alp_wake)
891             CALL histwrite_phy(o_ale, ale)
892             CALL histwrite_phy(o_alp, alp)
893             CALL histwrite_phy(o_cin, cin)
894             CALL histwrite_phy(o_WAPE, wake_pe)
895             CALL histwrite_phy(o_wake_h, wake_h)
896             CALL histwrite_phy(o_wake_s, wake_s)
897             CALL histwrite_phy(o_wake_deltat, wake_deltat)
898             CALL histwrite_phy(o_wake_deltaq, wake_deltaq)
899             CALL histwrite_phy(o_wake_omg, wake_omg)
900             IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_wake(1:klon,1:klev) &
901                  /pdtphys
902             CALL histwrite_phy(o_dtwak, zx_tmp_fi3d)
903             IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_wake(1:klon,1:klev)/pdtphys
904             CALL histwrite_phy(o_dqwak, zx_tmp_fi3d)
905          ENDIF ! iflag_wake>=1
906          CALL histwrite_phy(o_ftd, ftd)
907          CALL histwrite_phy(o_fqd, fqd)
908       ENDIF !(iflag_con.EQ.3)
909       IF (iflag_con.EQ.3.OR.iflag_con.EQ.30) THEN
910          ! sortie RomP convection descente insaturee iflag_con=30
911          ! etendue a iflag_con=3 (jyg)
912          CALL histwrite_phy(o_Vprecip, Vprecip)
913          CALL histwrite_phy(o_wdtrainA, wdtrainA)
914          CALL histwrite_phy(o_wdtrainM, wdtrainM)
915       ENDIF !(iflag_con.EQ.3.or.iflag_con.EQ.30)
916!!! nrlmd le 10/04/2012
917       IF (iflag_trig_bl>=1) THEN
918          CALL histwrite_phy(o_n2, n2)
919          CALL histwrite_phy(o_s2, s2)
920          CALL histwrite_phy(o_proba_notrig, proba_notrig)
921          CALL histwrite_phy(o_random_notrig, random_notrig)
922          CALL histwrite_phy(o_ale_bl_stat, ale_bl_stat)
923          CALL histwrite_phy(o_ale_bl_trig, ale_bl_trig)
924       ENDIF  !(iflag_trig_bl>=1)
925       IF (iflag_clos_bl>=1) THEN
926          CALL histwrite_phy(o_alp_bl_det, alp_bl_det)
927          CALL histwrite_phy(o_alp_bl_fluct_m, alp_bl_fluct_m)
928          CALL histwrite_phy(o_alp_bl_fluct_tke,  &
929               alp_bl_fluct_tke)
930          CALL histwrite_phy(o_alp_bl_conv, alp_bl_conv)
931          CALL histwrite_phy(o_alp_bl_stat, alp_bl_stat)
932       ENDIF  !(iflag_clos_bl>=1)
933!!! fin nrlmd le 10/04/2012
934       ! Output of slab ocean variables
935       IF (type_ocean=='slab ') THEN
936          CALL histwrite_phy(o_slab_qflux, slab_wfbils)
937          CALL histwrite_phy(o_slab_bils, slab_bils)
938          IF (nslay.EQ.1) THEN
939              zx_tmp_fi2d(:)=tslab(:,1)
940              CALL histwrite_phy(o_tslab, zx_tmp_fi2d)
941          ELSE
942              CALL histwrite_phy(o_tslab, tslab)
943          END IF
944          IF (version_ocean=='sicINT') THEN
945              CALL histwrite_phy(o_slab_bilg, slab_bilg)
946              CALL histwrite_phy(o_slab_tice, tice)
947              CALL histwrite_phy(o_slab_sic, seaice)
948          END IF
949       ENDIF !type_ocean == force/slab
950       CALL histwrite_phy(o_weakinv, weak_inversion)
951       CALL histwrite_phy(o_dthmin, dthmin)
952       CALL histwrite_phy(o_cldtau, cldtau)
953       CALL histwrite_phy(o_cldemi, cldemi)
954       CALL histwrite_phy(o_pr_con_l, pmflxr(:,1:klev))
955       CALL histwrite_phy(o_pr_con_i, pmflxs(:,1:klev))
956       CALL histwrite_phy(o_pr_lsc_l, prfl(:,1:klev))
957       CALL histwrite_phy(o_pr_lsc_i, psfl(:,1:klev))
958       CALL histwrite_phy(o_re, re)
959       CALL histwrite_phy(o_fl, fl)
960       IF (vars_defined) THEN
961          DO i=1, klon
962             zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
963          ENDDO
964       ENDIF
965       CALL histwrite_phy(o_rh2m, zx_tmp_fi2d)
966
967       IF (vars_defined) THEN
968          DO i=1, klon
969             zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
970          ENDDO
971       ENDIF
972       CALL histwrite_phy(o_rh2m_min, zx_tmp_fi2d)
973
974       IF (vars_defined) THEN
975          DO i=1, klon
976             zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
977          ENDDO
978       ENDIF
979       CALL histwrite_phy(o_rh2m_max, zx_tmp_fi2d)
980
981       CALL histwrite_phy(o_qsat2m, qsat2m)
982       CALL histwrite_phy(o_tpot, tpot)
983       CALL histwrite_phy(o_tpote, tpote)
984       IF (vars_defined) zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, is_ter)
985       CALL histwrite_phy(o_SWnetOR,  zx_tmp_fi2d)
986       IF (vars_defined) zx_tmp_fi2d(1:klon) = solsw(1:klon)/(1.-albsol1(1:klon))
987       CALL histwrite_phy(o_SWdownOR,  zx_tmp_fi2d)
988       CALL histwrite_phy(o_LWdownOR, sollwdown)
989       CALL histwrite_phy(o_snowl, snow_lsc)
990       CALL histwrite_phy(o_solldown, sollwdown)
991       CALL histwrite_phy(o_dtsvdfo, d_ts(:,is_oce))
992       CALL histwrite_phy(o_dtsvdft, d_ts(:,is_ter))
993       CALL histwrite_phy(o_dtsvdfg,  d_ts(:,is_lic))
994       CALL histwrite_phy(o_dtsvdfi, d_ts(:,is_sic))
995       CALL histwrite_phy(o_z0m, z0m(:,nbsrf+1))
996       CALL histwrite_phy(o_z0h, z0h(:,nbsrf+1))
997       ! OD550 per species
998!--OLIVIER
999!This is warranted by treating INCA aerosols as offline aerosols
1000!       IF (new_aod .and. (.not. aerosol_couple)) THEN
1001       IF (new_aod) THEN
1002          IF (flag_aerosol.GT.0) THEN
1003             CALL histwrite_phy(o_od550aer, od550aer)
1004             CALL histwrite_phy(o_od865aer, od865aer)
1005             CALL histwrite_phy(o_absvisaer, absvisaer)
1006             CALL histwrite_phy(o_od550lt1aer, od550lt1aer)
1007             CALL histwrite_phy(o_sconcso4, sconcso4)
1008             CALL histwrite_phy(o_sconcno3, sconcno3)
1009             CALL histwrite_phy(o_sconcoa, sconcoa)
1010             CALL histwrite_phy(o_sconcbc, sconcbc)
1011             CALL histwrite_phy(o_sconcss, sconcss)
1012             CALL histwrite_phy(o_sconcdust, sconcdust)
1013             CALL histwrite_phy(o_concso4, concso4)
1014             CALL histwrite_phy(o_concno3, concno3)
1015             CALL histwrite_phy(o_concoa, concoa)
1016             CALL histwrite_phy(o_concbc, concbc)
1017             CALL histwrite_phy(o_concss, concss)
1018             CALL histwrite_phy(o_concdust, concdust)
1019             CALL histwrite_phy(o_loadso4, loadso4)
1020             CALL histwrite_phy(o_loadoa, loadoa)
1021             CALL histwrite_phy(o_loadbc, loadbc)
1022             CALL histwrite_phy(o_loadss, loadss)
1023             CALL histwrite_phy(o_loaddust, loaddust)
1024             !--STRAT AER
1025          ENDIF
1026          IF (flag_aerosol.GT.0.OR.flag_aerosol_strat>=1) THEN
1027!             DO naero = 1, naero_spc
1028!--correction mini bug OB
1029             DO naero = 1, naero_tot
1030                CALL histwrite_phy(o_tausumaero(naero), &
1031                     tausum_aero(:,2,naero) )
1032             END DO
1033          ENDIF
1034          IF (flag_aerosol_strat>=1) THEN
1035             CALL histwrite_phy(o_tausumaero_lw, &
1036                  tausum_aero(:,6,id_STRAT_phy) )
1037          ENDIF
1038       ENDIF
1039       IF (ok_ade) THEN
1040          CALL histwrite_phy(o_topswad, topswad_aero)
1041          CALL histwrite_phy(o_topswad0, topswad0_aero)
1042          CALL histwrite_phy(o_solswad, solswad_aero)
1043          CALL histwrite_phy(o_solswad0, solswad0_aero)
1044          CALL histwrite_phy(o_toplwad, toplwad_aero)
1045          CALL histwrite_phy(o_toplwad0, toplwad0_aero)
1046          CALL histwrite_phy(o_sollwad, sollwad_aero)
1047          CALL histwrite_phy(o_sollwad0, sollwad0_aero)
1048          !====MS forcing diagnostics
1049          if (new_aod) then
1050             CALL histwrite_phy(o_swtoaas_nat, topsw_aero(:,1))
1051             CALL histwrite_phy(o_swsrfas_nat, solsw_aero(:,1))
1052             CALL histwrite_phy(o_swtoacs_nat, topsw0_aero(:,1))
1053             CALL histwrite_phy(o_swsrfcs_nat, solsw0_aero(:,1))
1054             !ant
1055             CALL histwrite_phy(o_swtoaas_ant, topsw_aero(:,2))
1056             CALL histwrite_phy(o_swsrfas_ant, solsw_aero(:,2))
1057             CALL histwrite_phy(o_swtoacs_ant, topsw0_aero(:,2))
1058             CALL histwrite_phy(o_swsrfcs_ant, solsw0_aero(:,2))
1059             !cf
1060             if (.not. aerosol_couple) then
1061                CALL histwrite_phy(o_swtoacf_nat, topswcf_aero(:,1))
1062                CALL histwrite_phy(o_swsrfcf_nat, solswcf_aero(:,1))
1063                CALL histwrite_phy(o_swtoacf_ant, topswcf_aero(:,2))
1064                CALL histwrite_phy(o_swsrfcf_ant, solswcf_aero(:,2))
1065                CALL histwrite_phy(o_swtoacf_zero,topswcf_aero(:,3))
1066                CALL histwrite_phy(o_swsrfcf_zero,solswcf_aero(:,3))
1067             endif
1068          endif ! new_aod
1069          !====MS forcing diagnostics
1070       ENDIF
1071       IF (ok_aie) THEN
1072          CALL histwrite_phy(o_topswai, topswai_aero)
1073          CALL histwrite_phy(o_solswai, solswai_aero)
1074       ENDIF
1075       IF (flag_aerosol.GT.0.AND.ok_cdnc) THEN
1076          CALL histwrite_phy(o_scdnc, scdnc)
1077          CALL histwrite_phy(o_cldncl, cldncl)
1078          CALL histwrite_phy(o_reffclws, reffclws)
1079          CALL histwrite_phy(o_reffclwc, reffclwc)
1080          CALL histwrite_phy(o_cldnvi, cldnvi)
1081          CALL histwrite_phy(o_lcc, lcc)
1082          CALL histwrite_phy(o_lcc3d, lcc3d)
1083          CALL histwrite_phy(o_lcc3dcon, lcc3dcon)
1084          CALL histwrite_phy(o_lcc3dstra, lcc3dstra)
1085          CALL histwrite_phy(o_reffclwtop, reffclwtop)
1086       ENDIF
1087       ! Champs 3D:
1088       IF (ok_ade .OR. ok_aie) then
1089          CALL histwrite_phy(o_ec550aer, ec550aer)
1090       ENDIF
1091       CALL histwrite_phy(o_lwcon, flwc)
1092       CALL histwrite_phy(o_iwcon, fiwc)
1093       CALL histwrite_phy(o_temp, t_seri)
1094       CALL histwrite_phy(o_theta, theta)
1095       CALL histwrite_phy(o_ovapinit, qx(:,:,ivap))
1096       CALL histwrite_phy(o_ovap, q_seri)
1097       CALL histwrite_phy(o_oliq, ql_seri)
1098       CALL histwrite_phy(o_geop, zphi)
1099       CALL histwrite_phy(o_vitu, u_seri)
1100       CALL histwrite_phy(o_vitv, v_seri)
1101       CALL histwrite_phy(o_vitw, omega)
1102       CALL histwrite_phy(o_pres, pplay)
1103       CALL histwrite_phy(o_paprs, paprs(:,1:klev))
1104       IF (vars_defined) THEN
1105          DO i=1, klon
1106             zx_tmp_fi3d1(i,1)= pphis(i)/RG
1107             !020611   zx_tmp_fi3d(i,1)= pphis(i)/RG
1108          ENDDO
1109          DO k=1, klev
1110             !020611        DO k=1, klev-1
1111             DO i=1, klon
1112                !020611         zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - (t_seri(i,k) *RD *
1113                zx_tmp_fi3d1(i,k+1)= zx_tmp_fi3d1(i,k) - (t_seri(i,k) *RD *  &
1114                     (paprs(i,k+1) - paprs(i,k))) / ( pplay(i,k) * RG )
1115             ENDDO
1116          ENDDO
1117       ENDIF
1118       CALL histwrite_phy(o_zfull,zx_tmp_fi3d1(:,2:klevp1))
1119       !020611    $o_zfull%name,itau_w,zx_tmp_fi3d)
1120
1121       IF (vars_defined)  THEN
1122          DO i=1, klon
1123             zx_tmp_fi3d(i,1)= pphis(i)/RG - ( &
1124                  (t_seri(i,1)+zxtsol(i))/2. *RD * &
1125                  (pplay(i,1) - paprs(i,1)))/( (paprs(i,1)+pplay(i,1))/2.* RG)
1126          ENDDO
1127          DO k=1, klev-1
1128             DO i=1, klon
1129                zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - ( &
1130                     (t_seri(i,k)+t_seri(i,k+1))/2. *RD *  &
1131                     (pplay(i,k+1) - pplay(i,k))) / ( paprs(i,k) * RG )
1132             ENDDO
1133          ENDDO
1134       ENDIF
1135       CALL histwrite_phy(o_zhalf, zx_tmp_fi3d)
1136       CALL histwrite_phy(o_rneb, cldfra)
1137       CALL histwrite_phy(o_rnebcon, rnebcon)
1138       CALL histwrite_phy(o_rnebls, rneb)
1139       IF (vars_defined)  THEN
1140          DO k=1, klev
1141             DO i=1, klon
1142                zx_tmp_fi3d(i,k)=cldfra(i,k)*JrNt(i)
1143             ENDDO
1144          ENDDO
1145       ENDIF
1146       CALL histwrite_phy(o_rnebjn, zx_tmp_fi3d)
1147       CALL histwrite_phy(o_rhum, zx_rh)
1148       CALL histwrite_phy(o_ozone, &
1149            wo(:, :, 1) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
1150
1151       IF (read_climoz == 2) THEN
1152          CALL histwrite_phy(o_ozone_light, &
1153               wo(:, :, 2) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
1154       ENDIF
1155
1156       CALL histwrite_phy(o_dtphy, d_t)
1157       CALL histwrite_phy(o_dqphy,  d_qx(:,:,ivap))
1158       DO nsrf=1, nbsrf
1159          IF (vars_defined) zx_tmp_fi2d(1 : klon) = falb1( 1 : klon, nsrf)
1160          CALL histwrite_phy(o_albe_srf(nsrf), zx_tmp_fi2d)
1161          IF (vars_defined) zx_tmp_fi2d(1 : klon) = z0m( 1 : klon, nsrf)
1162          CALL histwrite_phy(o_z0m_srf(nsrf), zx_tmp_fi2d)
1163          IF (vars_defined) zx_tmp_fi2d(1 : klon) = z0h( 1 : klon, nsrf)
1164          CALL histwrite_phy(o_z0h_srf(nsrf), zx_tmp_fi2d)
1165          IF (vars_defined) zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
1166          CALL histwrite_phy(o_ages_srf(nsrf), zx_tmp_fi2d)
1167          IF (vars_defined) zx_tmp_fi2d(1 : klon) = snow( 1 : klon, nsrf)
1168          CALL histwrite_phy(o_snow_srf(nsrf), zx_tmp_fi2d)
1169       ENDDO !nsrf=1, nbsrf
1170       CALL histwrite_phy(o_alb1, albsol1)
1171       CALL histwrite_phy(o_alb2, albsol2)
1172       !FH Sorties pour la couche limite
1173       if (iflag_pbl>1) then
1174          zx_tmp_fi3d=0.
1175          IF (vars_defined) THEN
1176             do nsrf=1,nbsrf
1177                do k=1,klev
1178                   zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k) &
1179                        +pctsrf(:,nsrf)*pbl_tke(:,k,nsrf)
1180                enddo
1181             enddo
1182          ENDIF
1183          CALL histwrite_phy(o_tke, zx_tmp_fi3d)
1184
1185          CALL histwrite_phy(o_tke_max, zx_tmp_fi3d)
1186       ENDIF
1187
1188       CALL histwrite_phy(o_kz, coefh(:,:,is_ave))
1189
1190       CALL histwrite_phy(o_kz_max, coefh(:,:,is_ave))
1191
1192       CALL histwrite_phy(o_clwcon, clwcon0)
1193       CALL histwrite_phy(o_dtdyn, d_t_dyn)
1194       CALL histwrite_phy(o_dqdyn, d_q_dyn)
1195       CALL histwrite_phy(o_dudyn, d_u_dyn)
1196       CALL histwrite_phy(o_dvdyn, d_v_dyn)
1197
1198       IF (vars_defined) THEN
1199          zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys
1200       ENDIF
1201       CALL histwrite_phy(o_dtcon, zx_tmp_fi3d)
1202       if(iflag_thermals.eq.0)then
1203          IF (vars_defined) THEN
1204             zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys + &
1205                  d_t_ajsb(1:klon,1:klev)/pdtphys
1206          ENDIF
1207          CALL histwrite_phy(o_tntc, zx_tmp_fi3d)
1208       else if(iflag_thermals.ge.1.and.iflag_wake.EQ.1)then
1209          IF (vars_defined) THEN
1210             zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys + &
1211                  d_t_ajs(1:klon,1:klev)/pdtphys + &
1212                  d_t_wake(1:klon,1:klev)/pdtphys
1213          ENDIF
1214          CALL histwrite_phy(o_tntc, zx_tmp_fi3d)
1215       endif
1216       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_con(1:klon,1:klev)/pdtphys
1217       CALL histwrite_phy(o_ducon, zx_tmp_fi3d)
1218       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_con(1:klon,1:klev)/pdtphys
1219       CALL histwrite_phy(o_dvcon, zx_tmp_fi3d)
1220       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
1221       CALL histwrite_phy(o_dqcon, zx_tmp_fi3d)
1222
1223       IF(iflag_thermals.EQ.0) THEN
1224          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
1225          CALL histwrite_phy(o_tnhusc, zx_tmp_fi3d)
1226       ELSE IF(iflag_thermals.GE.1.AND.iflag_wake.EQ.1) THEN
1227          IF (vars_defined) THEN
1228             zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys + &
1229                  d_q_ajs(1:klon,1:klev)/pdtphys + &
1230                  d_q_wake(1:klon,1:klev)/pdtphys
1231          ENDIF
1232          CALL histwrite_phy(o_tnhusc, zx_tmp_fi3d)
1233       ENDIF
1234
1235       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lsc(1:klon,1:klev)/pdtphys
1236       CALL histwrite_phy(o_dtlsc, zx_tmp_fi3d)
1237       IF (vars_defined) zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+ &
1238            d_t_eva(1:klon,1:klev))/pdtphys
1239       CALL histwrite_phy(o_dtlschr, zx_tmp_fi3d)
1240       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
1241       CALL histwrite_phy(o_dqlsc, zx_tmp_fi3d)
1242       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=beta_prec(1:klon,1:klev)
1243       CALL histwrite_phy(o_beta_prec, zx_tmp_fi3d)
1244!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1245       ! Sorties specifiques a la separation thermiques/non thermiques
1246       if (iflag_thermals>=1) then
1247          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lscth(1:klon,1:klev)/pdtphys
1248          CALL histwrite_phy(o_dtlscth, zx_tmp_fi3d)
1249          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lscst(1:klon,1:klev)/pdtphys
1250          CALL histwrite_phy(o_dtlscst, zx_tmp_fi3d)
1251          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
1252          CALL histwrite_phy(o_dqlscth, zx_tmp_fi3d)
1253          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
1254          CALL histwrite_phy(o_dqlscst, zx_tmp_fi3d)
1255          CALL histwrite_phy(o_plulth, plul_th)
1256          CALL histwrite_phy(o_plulst, plul_st)
1257          IF (vars_defined) THEN
1258             do k=1,klev
1259                do i=1,klon
1260                   if (ptconvth(i,k)) then
1261                      zx_tmp_fi3d(i,k)=1.
1262                   else
1263                      zx_tmp_fi3d(i,k)=0.
1264                   endif
1265                enddo
1266             enddo
1267          ENDIF
1268          CALL histwrite_phy(o_ptconvth, zx_tmp_fi3d)
1269          IF (vars_defined) THEN
1270             do i=1,klon
1271                zx_tmp_fi2d(1:klon)=lmax_th(:)
1272             enddo
1273          ENDIF
1274          CALL histwrite_phy(o_lmaxth, zx_tmp_fi2d)
1275       endif ! iflag_thermals>=1
1276!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1277       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
1278       CALL histwrite_phy(o_dtvdf, zx_tmp_fi3d)
1279       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_diss(1:klon,1:klev)/pdtphys
1280       CALL histwrite_phy(o_dtdis, zx_tmp_fi3d)
1281       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
1282       CALL histwrite_phy(o_dqvdf, zx_tmp_fi3d)
1283       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
1284       CALL histwrite_phy(o_dteva, zx_tmp_fi3d)
1285       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
1286       CALL histwrite_phy(o_dqeva, zx_tmp_fi3d)
1287       zpt_conv = 0.
1288       WHERE (ptconv) zpt_conv = 1.
1289       CALL histwrite_phy(o_ptconv, zpt_conv)
1290       CALL histwrite_phy(o_ratqs, ratqs)
1291       IF (vars_defined) THEN
1292          zx_tmp_fi3d(1:klon,1:klev)=d_t_ajs(1:klon,1:klev)/pdtphys - &
1293               d_t_ajsb(1:klon,1:klev)/pdtphys
1294       ENDIF
1295       CALL histwrite_phy(o_dtthe, zx_tmp_fi3d)
1296       IF (vars_defined) THEN
1297          zx_tmp_fi3d(1:klon,1:klev)=d_u_ajs(1:klon,1:klev)/pdtphys
1298       ENDIF
1299       CALL histwrite_phy(o_duthe, zx_tmp_fi3d)
1300       IF (vars_defined) THEN
1301          zx_tmp_fi3d(1:klon,1:klev)=d_v_ajs(1:klon,1:klev)/pdtphys
1302       ENDIF
1303       CALL histwrite_phy(o_dvthe, zx_tmp_fi3d)
1304
1305       IF (iflag_thermals>=1) THEN
1306          ! Pour l instant 0 a y reflichir pour les thermiques
1307          zx_tmp_fi2d=0.
1308          CALL histwrite_phy(o_ftime_th, zx_tmp_fi2d)
1309          CALL histwrite_phy(o_f_th, fm_therm)
1310          CALL histwrite_phy(o_e_th, entr_therm)
1311          CALL histwrite_phy(o_w_th, zw2)
1312          CALL histwrite_phy(o_q_th, zqasc)
1313          CALL histwrite_phy(o_a_th, fraca)
1314          CALL histwrite_phy(o_d_th, detr_therm)
1315          CALL histwrite_phy(o_f0_th, f0)
1316          CALL histwrite_phy(o_zmax_th, zmax_th)
1317          IF (vars_defined) THEN
1318             zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys - &
1319                  d_q_ajsb(1:klon,1:klev)/pdtphys
1320          ENDIF
1321          CALL histwrite_phy(o_dqthe, zx_tmp_fi3d)
1322       ENDIF !iflag_thermals
1323       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_ajsb(1:klon,1:klev)/pdtphys
1324       CALL histwrite_phy(o_dtajs, zx_tmp_fi3d)
1325       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
1326       CALL histwrite_phy(o_dqajs, zx_tmp_fi3d)
1327       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_swr(1:klon,1:klev)/pdtphys
1328       CALL histwrite_phy(o_dtswr, zx_tmp_fi3d)
1329       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_sw0(1:klon,1:klev)/pdtphys
1330       CALL histwrite_phy(o_dtsw0, zx_tmp_fi3d)
1331       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lwr(1:klon,1:klev)/pdtphys
1332       CALL histwrite_phy(o_dtlwr, zx_tmp_fi3d)
1333       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lw0(1:klon,1:klev)/pdtphys
1334       CALL histwrite_phy(o_dtlw0, zx_tmp_fi3d)
1335       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)/pdtphys
1336       CALL histwrite_phy(o_dtec, zx_tmp_fi3d)
1337       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
1338       CALL histwrite_phy(o_duvdf, zx_tmp_fi3d)
1339       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
1340       CALL histwrite_phy(o_dvvdf, zx_tmp_fi3d)
1341       IF (ok_orodr) THEN
1342          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
1343          CALL histwrite_phy(o_duoro, zx_tmp_fi3d)
1344          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
1345          CALL histwrite_phy(o_dvoro, zx_tmp_fi3d)
1346          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_oro(1:klon,1:klev)/pdtphys
1347          CALL histwrite_phy(o_dtoro, zx_tmp_fi3d)
1348       ENDIF
1349       IF (ok_orolf) THEN
1350          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
1351          CALL histwrite_phy(o_dulif, zx_tmp_fi3d)
1352
1353          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
1354          CALL histwrite_phy(o_dvlif, zx_tmp_fi3d)
1355
1356          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lif(1:klon,1:klev)/pdtphys
1357          CALL histwrite_phy(o_dtlif, zx_tmp_fi3d)
1358       ENDIF
1359
1360!      IF (ok_hines) THEN
1361!         IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_hin(1:klon,1:klev)/pdtphys
1362!         CALL histwrite_phy(o_duhin, zx_tmp_fi3d)
1363!         IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_hin(1:klon,1:klev)/pdtphys
1364!         CALL histwrite_phy(o_dvhin, zx_tmp_fi3d)
1365!         IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_hin(1:klon,1:klev)/pdtphys
1366!         CALL histwrite_phy(o_dthin, zx_tmp_fi3d)
1367!      ENDIF
1368
1369!      IF (ok_gwd_rando) then
1370!         CALL histwrite_phy(o_du_gwd_rando, du_gwd_rando / pdtphys)
1371!         CALL histwrite_phy(o_dv_gwd_rando, dv_gwd_rando / pdtphys)
1372!         CALL histwrite_phy(o_vstr_gwd_rando, zvstr_gwd_rando)
1373!      end IF
1374
1375       IF (ok_qch4) then
1376          CALL histwrite_phy(o_dqch4, d_q_ch4 / pdtphys)
1377       ENDIF
1378
1379       CALL histwrite_phy(o_rsu, swup)
1380       CALL histwrite_phy(o_rsd, swdn)
1381       CALL histwrite_phy(o_rlu, lwup)
1382       CALL histwrite_phy(o_rld, lwdn)
1383       CALL histwrite_phy(o_rsucs, swup0)
1384       CALL histwrite_phy(o_rsdcs, swdn0)
1385       CALL histwrite_phy(o_rlucs, lwup0)
1386       CALL histwrite_phy(o_rldcs, lwdn0)
1387       IF(vars_defined) THEN
1388          zx_tmp_fi3d(1:klon,1:klev)=d_t(1:klon,1:klev)+ &
1389               d_t_dyn(1:klon,1:klev)
1390       ENDIF
1391       CALL histwrite_phy(o_tnt, zx_tmp_fi3d)
1392       IF(vars_defined) THEN
1393          zx_tmp_fi3d(1:klon,1:klev)=d_t_swr(1:klon,1:klev)/pdtphys + &
1394               d_t_lwr(1:klon,1:klev)/pdtphys
1395       ENDIF
1396       CALL histwrite_phy(o_tntr, zx_tmp_fi3d)
1397       IF(vars_defined) THEN
1398          zx_tmp_fi3d(1:klon,1:klev)= (d_t_lsc(1:klon,1:klev)+ &
1399               d_t_eva(1:klon,1:klev)+ &
1400               d_t_vdf(1:klon,1:klev))/pdtphys
1401       ENDIF
1402       CALL histwrite_phy(o_tntscpbl, zx_tmp_fi3d)
1403       IF(vars_defined) THEN
1404          zx_tmp_fi3d(1:klon,1:klev)=d_qx(1:klon,1:klev,ivap)+ &
1405               d_q_dyn(1:klon,1:klev)
1406       ENDIF
1407       CALL histwrite_phy(o_tnhus, zx_tmp_fi3d)
1408       IF(vars_defined) THEN
1409          zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys+ &
1410               d_q_eva(1:klon,1:klev)/pdtphys
1411       ENDIF
1412       CALL histwrite_phy(o_tnhusscpbl, zx_tmp_fi3d)
1413       CALL histwrite_phy(o_evu, coefm(:,:,is_ave))
1414       IF(vars_defined) THEN
1415          zx_tmp_fi3d(1:klon,1:klev)=q_seri(1:klon,1:klev)+ &
1416               ql_seri(1:klon,1:klev)
1417       ENDIF
1418       CALL histwrite_phy(o_h2o, zx_tmp_fi3d)
1419       if (iflag_con >= 3) then
1420          IF(vars_defined) THEN
1421             zx_tmp_fi3d(1:klon,1:klev)=-1 * (dnwd(1:klon,1:klev)+ &
1422                  dnwd0(1:klon,1:klev))
1423          ENDIF
1424          CALL histwrite_phy(o_mcd, zx_tmp_fi3d)
1425          IF(vars_defined) THEN
1426             zx_tmp_fi3d(1:klon,1:klev)=upwd(1:klon,1:klev) + &
1427                  dnwd(1:klon,1:klev)+ dnwd0(1:klon,1:klev)
1428          ENDIF
1429          CALL histwrite_phy(o_dmc, zx_tmp_fi3d)
1430       else if (iflag_con == 2) then
1431          CALL histwrite_phy(o_mcd,  pmfd)
1432          CALL histwrite_phy(o_dmc,  pmfu + pmfd)
1433       end if
1434       CALL histwrite_phy(o_ref_liq, ref_liq)
1435       CALL histwrite_phy(o_ref_ice, ref_ice)
1436       if (RCO2_per.NE.RCO2_act.OR.RCH4_per.NE.RCH4_act.OR. &
1437            RN2O_per.NE.RN2O_act.OR.RCFC11_per.NE.RCFC11_act.OR. &
1438            RCFC12_per.NE.RCFC12_act) THEN
1439          IF(vars_defined) zx_tmp_fi2d(1 : klon) = swupp ( 1 : klon, klevp1 )
1440          CALL histwrite_phy(o_rsut4co2, zx_tmp_fi2d)
1441          IF(vars_defined) zx_tmp_fi2d(1 : klon) = lwupp ( 1 : klon, klevp1 )
1442          CALL histwrite_phy(o_rlut4co2, zx_tmp_fi2d)
1443          IF(vars_defined) zx_tmp_fi2d(1 : klon) = swup0p ( 1 : klon, klevp1 )
1444          CALL histwrite_phy(o_rsutcs4co2, zx_tmp_fi2d)
1445          IF(vars_defined) zx_tmp_fi2d(1 : klon) = lwup0p ( 1 : klon, klevp1 )
1446          CALL histwrite_phy(o_rlutcs4co2, zx_tmp_fi2d)
1447          CALL histwrite_phy(o_rsu4co2, swupp)
1448          CALL histwrite_phy(o_rlu4co2, lwupp)
1449          CALL histwrite_phy(o_rsucs4co2, swup0p)
1450          CALL histwrite_phy(o_rlucs4co2, lwup0p)
1451          CALL histwrite_phy(o_rsd4co2, swdnp)
1452          CALL histwrite_phy(o_rld4co2, lwdnp)
1453          CALL histwrite_phy(o_rsdcs4co2, swdn0p)
1454          CALL histwrite_phy(o_rldcs4co2, lwdn0p)
1455       ENDIF
1456!!!!!!!!!!!! Sorties niveaux de pression NMC !!!!!!!!!!!!!!!!!!!!
1457#ifdef CPP_IOIPSL
1458#ifndef CPP_XIOS
1459  IF (.NOT.ok_all_xml) THEN
1460       ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
1461       ! Champs interpolles sur des niveaux de pression
1462       missing_val=missing_val_nf90
1463       DO iff=7, nfiles
1464
1465          CALL histwrite_phy(o_tnondef,tnondef(:,:,iff-6),iff)
1466          CALL histwrite_phy(o_ta,twriteSTD(:,:,iff-6),iff)
1467          CALL histwrite_phy(o_zg,phiwriteSTD(:,:,iff-6),iff)
1468          CALL histwrite_phy(o_hus,qwriteSTD(:,:,iff-6),iff)
1469          CALL histwrite_phy(o_hur,rhwriteSTD(:,:,iff-6),iff)
1470          CALL histwrite_phy(o_ua,uwriteSTD(:,:,iff-6),iff)
1471          CALL histwrite_phy(o_va,vwriteSTD(:,:,iff-6),iff)
1472          CALL histwrite_phy(o_wap,wwriteSTD(:,:,iff-6),iff)
1473          IF(vars_defined) THEN
1474             DO k=1, nlevSTD
1475                DO i=1, klon
1476                   IF(tnondef(i,k,iff-6).NE.missing_val) THEN
1477                      IF(freq_outNMC(iff-6).LT.0) THEN
1478                         freq_moyNMC(iff-6)=(mth_len*un_jour)/freq_calNMC(iff-6)
1479                      ELSE
1480                         freq_moyNMC(iff-6)=freq_outNMC(iff-6)/freq_calNMC(iff-6)
1481                      ENDIF
1482                      zx_tmp_fi3d_STD(i,k) = (100.*tnondef(i,k,iff-6))/freq_moyNMC(iff-6)
1483                   ELSE
1484                      zx_tmp_fi3d_STD(i,k) = missing_val
1485                   ENDIF
1486                ENDDO
1487             ENDDO
1488          ENDIF
1489          CALL histwrite_phy(o_psbg,zx_tmp_fi3d_STD,iff)
1490          IF(vars_defined) THEN
1491             DO k=1, nlevSTD
1492                DO i=1, klon
1493                   IF(O3sumSTD(i,k,iff-6).NE.missing_val) THEN
1494                      zx_tmp_fi3d_STD(i,k) = O3sumSTD(i,k,iff-6) * 1.e+9
1495                   ELSE
1496                      zx_tmp_fi3d_STD(i,k) = missing_val
1497                   ENDIF
1498                ENDDO
1499             ENDDO !k=1, nlevSTD
1500          ENDIF
1501          CALL histwrite_phy(o_tro3,zx_tmp_fi3d_STD,iff)
1502          if (read_climoz == 2) THEN
1503             IF(vars_defined) THEN
1504                DO k=1, nlevSTD
1505                   DO i=1, klon
1506                      IF(O3daysumSTD(i,k,iff-6).NE.missing_val) THEN
1507                         zx_tmp_fi3d_STD(i,k) = O3daysumSTD(i,k,iff-6) * 1.e+9
1508                      ELSE
1509                         zx_tmp_fi3d_STD(i,k) = missing_val
1510                      ENDIF
1511                   ENDDO
1512                ENDDO !k=1, nlevSTD
1513             ENDIF
1514             CALL histwrite_phy(o_tro3_daylight,zx_tmp_fi3d_STD,iff)
1515          endif
1516          CALL histwrite_phy(o_uxv,uvsumSTD(:,:,iff-6),iff)
1517          CALL histwrite_phy(o_vxq,vqsumSTD(:,:,iff-6),iff)
1518          CALL histwrite_phy(o_vxT,vTsumSTD(:,:,iff-6),iff)
1519          CALL histwrite_phy(o_wxq,wqsumSTD(:,:,iff-6),iff)
1520          CALL histwrite_phy(o_vxphi,vphisumSTD(:,:,iff-6),iff)
1521          CALL histwrite_phy(o_wxT,wTsumSTD(:,:,iff-6),iff)
1522          CALL histwrite_phy(o_uxu,u2sumSTD(:,:,iff-6),iff)
1523          CALL histwrite_phy(o_vxv,v2sumSTD(:,:,iff-6),iff)
1524          CALL histwrite_phy(o_TxT,T2sumSTD(:,:,iff-6),iff)
1525       ENDDO !nfiles
1526  ENDIF
1527#endif
1528#endif
1529#ifdef CPP_XIOS
1530  IF(ok_all_xml) THEN
1531!      DO iff=7, nfiles
1532
1533!         CALL histwrite_phy(o_tnondef,tnondef(:,:,3))
1534          CALL histwrite_phy(o_ta,tlevSTD(:,:))
1535          CALL histwrite_phy(o_zg,philevSTD(:,:))
1536          CALL histwrite_phy(o_hus,qlevSTD(:,:))
1537          CALL histwrite_phy(o_hur,rhlevSTD(:,:))
1538          CALL histwrite_phy(o_ua,ulevSTD(:,:))
1539          CALL histwrite_phy(o_va,vlevSTD(:,:))
1540          CALL histwrite_phy(o_wap,wlevSTD(:,:))
1541!         IF(vars_defined) THEN
1542!            DO k=1, nlevSTD
1543!               DO i=1, klon
1544!                  IF(tnondef(i,k,3).NE.missing_val) THEN
1545!                     IF(freq_outNMC(iff-6).LT.0) THEN
1546!                        freq_moyNMC(iff-6)=(mth_len*un_jour)/freq_calNMC(iff-6)
1547!                     ELSE
1548!                        freq_moyNMC(iff-6)=freq_outNMC(iff-6)/freq_calNMC(iff-6)
1549!                     ENDIF
1550!                     zx_tmp_fi3d_STD(i,k) = (100.*tnondef(i,k,3))/freq_moyNMC(iff-6)
1551!                  ELSE
1552!                     zx_tmp_fi3d_STD(i,k) = missing_val
1553!                  ENDIF
1554!               ENDDO
1555!            ENDDO
1556!         ENDIF
1557!         CALL histwrite_phy(o_psbg,zx_tmp_fi3d_STD)
1558          IF(vars_defined) THEN
1559             DO k=1, nlevSTD
1560                DO i=1, klon
1561                   IF(O3STD(i,k).NE.missing_val) THEN
1562                      zx_tmp_fi3d_STD(i,k) = O3STD(i,k) * 1.e+9
1563                   ELSE
1564                      zx_tmp_fi3d_STD(i,k) = missing_val
1565                   ENDIF
1566                ENDDO
1567             ENDDO !k=1, nlevSTD
1568          ENDIF
1569          CALL histwrite_phy(o_tro3,zx_tmp_fi3d_STD)
1570          if (read_climoz == 2) THEN
1571             IF(vars_defined) THEN
1572                DO k=1, nlevSTD
1573                   DO i=1, klon
1574                      IF(O3daySTD(i,k).NE.missing_val) THEN
1575                         zx_tmp_fi3d_STD(i,k) = O3daySTD(i,k) * 1.e+9
1576                      ELSE
1577                         zx_tmp_fi3d_STD(i,k) = missing_val
1578                      ENDIF
1579                   ENDDO
1580                ENDDO !k=1, nlevSTD
1581             ENDIF
1582             CALL histwrite_phy(o_tro3_daylight,zx_tmp_fi3d_STD)
1583          endif
1584          CALL histwrite_phy(o_uxv,uvSTD(:,:))
1585          CALL histwrite_phy(o_vxq,vqSTD(:,:))
1586          CALL histwrite_phy(o_vxT,vTSTD(:,:))
1587          CALL histwrite_phy(o_wxq,wqSTD(:,:))
1588          CALL histwrite_phy(o_vxphi,vphiSTD(:,:))
1589          CALL histwrite_phy(o_wxT,wTSTD(:,:))
1590          CALL histwrite_phy(o_uxu,u2STD(:,:))
1591          CALL histwrite_phy(o_vxv,v2STD(:,:))
1592          CALL histwrite_phy(o_TxT,T2STD(:,:))
1593!      ENDDO !nfiles
1594  ENDIF
1595#endif
1596!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1597        IF (nqtot.GE.nqo+1) THEN
1598            DO iq=nqo+1,nqtot
1599              IF (type_trac == 'lmdz' .OR. type_trac == 'repr') THEN
1600
1601!jyg<
1602!!             CALL histwrite_phy(o_trac(iq-nqo), qx(:,:,iq))
1603             CALL histwrite_phy(o_trac(iq-nqo), tr_seri(:,:,iq-nqo))
1604!>jyg
1605             CALL histwrite_phy(o_dtr_vdf(iq-nqo),d_tr_cl(:,:,iq-nqo))
1606             CALL histwrite_phy(o_dtr_the(iq-nqo),d_tr_th(:,:,iq-nqo))
1607             CALL histwrite_phy(o_dtr_con(iq-nqo),d_tr_cv(:,:,iq-nqo))
1608             CALL histwrite_phy(o_dtr_lessi_impa(iq-nqo),d_tr_lessi_impa(:,:,iq-nqo))
1609             CALL histwrite_phy(o_dtr_lessi_nucl(iq-nqo),d_tr_lessi_nucl(:,:,iq-nqo))
1610             CALL histwrite_phy(o_dtr_insc(iq-nqo),d_tr_insc(:,:,iq-nqo))
1611             CALL histwrite_phy(o_dtr_bcscav(iq-nqo),d_tr_bcscav(:,:,iq-nqo))
1612             CALL histwrite_phy(o_dtr_evapls(iq-nqo),d_tr_evapls(:,:,iq-nqo))
1613             CALL histwrite_phy(o_dtr_ls(iq-nqo),d_tr_ls(:,:,iq-nqo))
1614!            CALL histwrite_phy(o_dtr_dyn(iq-nqo),d_tr_dyn(:,:,iq-nqo))
1615         !!  CALL histwrite_phy(o_dtr_cl(iq-nqo),d_tr_cl(:,:,iq-nqo))
1616             CALL histwrite_phy(o_dtr_trsp(iq-nqo),d_tr_trsp(:,:,iq-nqo))
1617             CALL histwrite_phy(o_dtr_sscav(iq-nqo),d_tr_sscav(:,:,iq-nqo))
1618             CALL histwrite_phy(o_dtr_sat(iq-nqo),d_tr_sat(:,:,iq-nqo))
1619             CALL histwrite_phy(o_dtr_uscav(iq-nqo),d_tr_uscav(:,:,iq-nqo))
1620             zx_tmp_fi2d=0.
1621             IF(vars_defined) THEN
1622                DO k=1,klev
1623!jyg<
1624!!                   zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*qx(:,k,iq)
1625                   zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*tr_seri(:,k,iq-nqo)
1626!>jyg
1627                ENDDO
1628             ENDIF
1629             CALL histwrite_phy(o_trac_cum(iq-nqo), zx_tmp_fi2d)
1630             endif
1631          ENDDO
1632       ENDIF
1633
1634       IF(.NOT.vars_defined) THEN
1635          !$OMP MASTER
1636#ifndef CPP_IOIPSL_NO_OUTPUT
1637          DO iff=1,nfiles
1638             IF (clef_files(iff)) THEN
1639                CALL histend(nid_files(iff))
1640                ndex2d = 0
1641                ndex3d = 0
1642
1643             ENDIF ! clef_files
1644          ENDDO !  iff
1645#endif
1646#ifdef CPP_XIOS
1647          !On finalise l'initialisation:
1648          CALL wxios_closedef()
1649#endif
1650
1651          !$OMP END MASTER
1652          !$OMP BARRIER
1653          vars_defined = .TRUE.
1654
1655       END IF
1656
1657    END DO
1658
1659    IF(vars_defined) THEN
1660       ! On synchronise les fichiers pour IOIPSL
1661#ifndef CPP_IOIPSL_NO_OUTPUT
1662       !$OMP MASTER
1663       DO iff=1,nfiles
1664          IF (ok_sync .AND. clef_files(iff)) THEN
1665             CALL histsync(nid_files(iff))
1666          ENDIF
1667       END DO
1668       !$OMP END MASTER
1669#endif
1670    ENDIF
1671
1672  END SUBROUTINE phys_output_write_spl
1673
1674END MODULE phys_output_write_spl_mod
Note: See TracBrowser for help on using the repository browser.