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

Last change on this file since 2668 was 2630, checked in by fhourdin, 8 years ago

Importation du modèle d'aérosols de Boucher, Escribano et al.

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