source: LMDZ6/trunk/libf/phylmd/Dust/phys_output_write_spl_mod.F90 @ 4250

Last change on this file since 4250 was 4160, checked in by asima, 3 years ago

In r4090 (FH) thermcell.h dissapears ; the flags required by subroutine thermcell_dq (iflag_wake, iflag_coupl, iflag_trig_bl, iflag_clos_bl) are now in the new file alpale.h

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