source: LMDZ5/trunk/libf/phylmd/phys_output_write_mod.F90 @ 1907

Last change on this file since 1907 was 1907, checked in by lguez, 10 years ago

Added a copyright property to every file of the distribution, except
for the fcm files (which have their own copyright). Use svn propget on
a file to see the copyright. For instance:

$ svn propget copyright libf/phylmd/physiq.F90
Name of program: LMDZ
Creation date: 1984
Version: LMDZ5
License: CeCILL version 2
Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
See the license file in the root directory

Also added the files defining the CeCILL version 2 license, in French
and English, at the top of the LMDZ tree.

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
File size: 54.4 KB
Line 
1!
2! $Header$
3!
4MODULE phys_output_write_mod
5
6  USE phytrac_mod, ONLY : d_tr_cl, d_tr_th, d_tr_cv, d_tr_lessi_impa, &
7       d_tr_lessi_nucl, d_tr_insc, d_tr_bcscav, d_tr_evapls, d_tr_ls,  &
8       d_tr_trsp, d_tr_sscav, d_tr_sat, d_tr_uscav
9
10  ! Author: Abderrahmane IDELKADI (original include file)
11  ! Author: Laurent FAIRHEAD (transformation to module/subroutine)
12  ! Author: Ulysse GERARD (effective implementation)
13
14CONTAINS
15
16  ! ug Routine pour définir (los du premier passageà) ET sortir les variables
17  SUBROUTINE phys_output_write(itap, pdtphys, paprs, pphis, &
18       pplay, lmax_th, aerosol_couple,         &
19       ok_ade, ok_aie, ivap, new_aod, ok_sync, &
20       ptconv, read_climoz, clevSTD, freq_moyNMC, ptconvth, &
21       d_t, qx, d_qx, zmasse, flag_aerosol_strat)
22
23    ! This subroutine does the actual writing of diagnostics that were
24    ! defined and initialised in phys_output_mod.F90
25
26    USE dimphy, only: klon, klev, klevp1
27    USE control_mod, only: day_step, iphysiq
28    USE phys_output_ctrlout_mod, only: o_phis, o_aire, is_ter, is_lic, is_oce, &
29         is_ave, is_sic, o_contfracATM, o_contfracOR, &
30         o_aireTER, o_flat, o_slp, o_tsol, &
31         o_t2m, o_t2m_min, o_t2m_max, &
32         o_q2m, o_ustar, o_u10m, o_v10m, &
33         o_wind10m, o_wind10max, o_sicf, &
34         o_psol, o_mass, o_qsurf, o_qsol, &
35         o_precip, o_ndayrain, o_plul, o_pluc, &
36         o_snow, o_msnow, o_fsnow, o_evap, &
37         o_tops, o_tops0, o_topl, o_topl0, &
38         o_SWupTOA, o_SWupTOAclr, o_SWdnTOA, &
39         o_SWdnTOAclr, o_nettop, o_SWup200, &
40         o_SWup200clr, o_SWdn200, o_SWdn200clr, &
41         o_LWup200, o_LWup200clr, o_LWdn200, &
42         o_LWdn200clr, o_sols, o_sols0, &
43         o_soll, o_radsol, o_soll0, o_SWupSFC, &
44         o_SWupSFCclr, o_SWdnSFC, o_SWdnSFCclr, &
45         o_LWupSFC, o_LWdnSFC, o_LWupSFCclr, &
46         o_LWdnSFCclr, o_bils, o_bils_diss, &
47         o_bils_ec, o_bils_tke, o_bils_kinetic, &
48         o_bils_latent, o_bils_enthalp, o_sens, &
49         o_fder, o_ffonte, o_fqcalving, o_fqfonte, &
50         o_taux, o_tauy, o_snowsrf, o_qsnow, &
51         o_snowhgt, o_toice, o_sissnow, o_runoff, &
52         o_albslw3, o_pourc_srf, o_fract_srf, &
53         o_taux_srf, o_tauy_srf, o_tsol_srf, &
54         o_evappot_srf, o_ustar_srf, o_u10m_srf, &
55         o_v10m_srf, o_t2m_srf, o_evap_srf, &
56         o_sens_srf, o_lat_srf, o_flw_srf, &
57         o_fsw_srf, o_wbils_srf, o_wbilo_srf, &
58         o_tke_srf, o_tke_max_srf, o_wstar, &
59         o_cdrm, o_cdrh, o_cldl, o_cldm, o_cldh, &
60         o_cldt, o_cldq, o_lwp, o_iwp, o_ue, &
61         o_ve, o_uq, o_vq, o_cape, o_pbase, &
62         o_ptop, o_fbase, o_plcl, o_plfc, &
63         o_wbeff, o_cape_max, o_upwd, o_Ma, &
64         o_dnwd, o_dnwd0, o_ftime_con, o_mc, &
65         o_prw, o_s_pblh, o_s_pblt, o_s_lcl, &
66         o_s_therm, o_uSTDlevs, o_vSTDlevs, &
67         o_wSTDlevs, o_zSTDlevs, o_qSTDlevs, &
68         o_tSTDlevs, epsfra, o_t_oce_sic, &
69         o_ale_bl, o_alp_bl, o_ale_wk, o_alp_wk, &
70         o_ale, o_alp, o_cin, o_WAPE, o_wake_h, &
71         o_wake_s, o_wake_deltat, o_wake_deltaq, &
72         o_wake_omg, o_dtwak, o_dqwak, o_Vprecip, &
73         o_ftd, o_fqd, o_wdtrainA, o_wdtrainM, &
74         o_n2, o_s2, o_proba_notrig, &
75         o_random_notrig, o_ale_bl_stat, &
76         o_ale_bl_trig, o_alp_bl_det, &
77         o_alp_bl_fluct_m, o_alp_bl_fluct_tke, &
78         o_alp_bl_conv, o_alp_bl_stat, o_slab_bils, &
79         o_weakinv, o_dthmin, o_cldtau, &
80         o_cldemi, o_pr_con_l, o_pr_con_i, &
81         o_pr_lsc_l, o_pr_lsc_i, o_re, o_fl, &
82         o_rh2m, o_rh2m_min, o_rh2m_max, &
83         o_qsat2m, o_tpot, o_tpote, o_SWnetOR, &
84         o_SWdownOR, o_LWdownOR, o_snowl, &
85         o_solldown, o_dtsvdfo, o_dtsvdft, &
86         o_dtsvdfg, o_dtsvdfi, o_rugs, o_od550aer, &
87         o_od865aer, o_absvisaer, o_od550lt1aer, &
88         o_sconcso4, o_sconcoa, o_sconcbc, &
89         o_sconcss, o_sconcdust, o_concso4, &
90         o_concoa, o_concbc, o_concss, o_concdust, &
91         o_loadso4, o_loadoa, o_loadbc, o_loadss, &
92         o_loaddust, o_tausumaero, o_topswad, &
93         o_topswad0, o_solswad, o_solswad0, &
94         o_swtoaas_nat, o_swsrfas_nat, &
95         o_swtoacs_nat, o_swtoaas_ant, &
96         o_swsrfas_ant, o_swtoacs_ant, &
97         o_swsrfcs_ant, o_swtoacf_nat, &
98         o_swsrfcf_nat, o_swtoacf_ant, &
99         o_swsrfcs_nat, o_swsrfcf_ant, &
100         o_swtoacf_zero, o_swsrfcf_zero, &
101         o_topswai, o_solswai, o_scdnc, &
102         o_cldncl, o_reffclws, o_reffclwc, &
103         o_cldnvi, o_lcc, o_lcc3d, o_lcc3dcon, &
104         o_lcc3dstra, o_reffclwtop, o_ec550aer, &
105         o_lwcon, o_iwcon, o_temp, o_theta, &
106         o_ovapinit, o_ovap, o_oliq, o_geop, &
107         o_vitu, o_vitv, o_vitw, o_pres, o_paprs, &
108         o_zfull, o_zhalf, o_rneb, o_rnebcon, &
109         o_rnebls, o_rhum, o_ozone, o_ozone_light, &
110         o_dtphy, o_dqphy, o_albe_srf, o_rugs_srf, &
111         o_ages_srf, o_alb1, o_alb2, o_tke, &
112         o_tke_max, o_kz, o_kz_max, o_clwcon, &
113         o_dtdyn, o_dqdyn, o_dudyn, o_dvdyn, &
114         o_dtcon, o_tntc, o_ducon, o_dvcon, &
115         o_dqcon, o_tnhusc, o_tnhusc, o_dtlsc, &
116         o_dtlschr, o_dqlsc, o_beta_prec, &
117         o_dtlscth, o_dtlscst, o_dqlscth, &
118         o_dqlscst, o_plulth, o_plulst, &
119         o_ptconvth, o_lmaxth, o_dtvdf, &
120         o_dtdis, o_dqvdf, o_dteva, o_dqeva, &
121         o_ptconv, o_ratqs, o_dtthe, &
122         o_duthe, o_dvthe, o_ftime_th, &
123         o_f_th, o_e_th, o_w_th, o_q_th, &
124         o_a_th, o_d_th, o_f0_th, o_zmax_th, &
125         o_dqthe, o_dtajs, o_dqajs, o_dtswr, &
126         o_dtsw0, o_dtlwr, o_dtlw0, o_dtec, &
127         o_duvdf, o_dvvdf, o_duoro, o_dvoro, &
128         o_dtoro, o_dulif, o_dvlif, o_dtlif, &
129         o_duhin, o_dvhin, o_dthin, o_rsu, &
130         o_rsd, o_rlu, o_rld, o_rsucs, o_rsdcs, &
131         o_rlucs, o_rldcs, o_tnt, o_tntr, &
132         o_tntscpbl, o_tnhus, o_tnhusscpbl, &
133         o_evu, o_h2o, o_mcd, o_dmc, o_ref_liq, &
134         o_ref_ice, o_rsut4co2, o_rlut4co2, &
135         o_rsutcs4co2, o_rlutcs4co2, o_rsu4co2, &
136         o_rlu4co2, o_rsucs4co2, o_rlucs4co2, &
137         o_rsd4co2, o_rld4co2, o_rsdcs4co2, &
138         o_rldcs4co2, o_tnondef, o_ta, o_zg, &
139         o_hus, o_hur, o_ua, o_va, o_wap, &
140         o_psbg, o_tro3, o_tro3_daylight, &
141         o_uxv, o_vxq, o_vxT, o_wxq, o_vxphi, &
142         o_wxT, o_uxu, o_vxv, o_TxT, o_trac, &
143         o_dtr_vdf, o_dtr_the, o_dtr_con, &
144         o_dtr_lessi_impa, o_dtr_lessi_nucl, &
145         o_dtr_insc, o_dtr_bcscav, o_dtr_evapls, &
146         o_dtr_ls, o_dtr_trsp, o_dtr_sscav, &
147         o_dtr_sat, o_dtr_uscav, o_trac_cum
148
149    USE phys_state_var_mod, only: pctsrf, paire_ter, rain_fall, snow_fall, &
150         nday_rain, rain_con, snow_con, &
151         topsw, toplw, toplw0, swup, swdn, &
152         topsw0, swup0, swdn0, SWup200, SWup200clr, &
153         SWdn200, SWdn200clr, LWup200, LWup200clr, &
154         LWdn200, LWdn200clr, solsw, solsw0, sollw, &
155         radsol, sollw0, sollwdown, sollw, &
156         sollwdownclr, lwdn0, ftsol, ustar, u10m, &
157         v10m, pbl_tke, wstar, cape, ema_pcb, ema_pct, &
158         ema_cbmf, Ma, fm_therm, ale_bl, alp_bl, ale, &
159         alp, cin, wake_pe, wake_s, wake_deltat, &
160         wake_deltaq, ftd, fqd, ale_bl_trig, albsol1, &
161         rnebcon, wo, falb1, albsol2, coefh, clwcon0, &
162         ratqs, entr_therm, zqasc, detr_therm, f0, heat, &
163         heat0, cool, cool0, lwup, lwdn, lwup0, coefm, &
164         swupp, lwupp, swup0p, lwup0p, swdnp, lwdnp, &
165         swdn0p, lwdn0p, tnondef, O3sumSTD, uvsumSTD, &
166         vqsumSTD, vTsumSTD, O3daysumSTD, wqsumSTD, &
167         vphisumSTD, wTsumSTD, u2sumSTD, v2sumSTD, &
168         T2sumSTD, nlevSTD
169
170    USE phys_local_var_mod, only: zxfluxlat, slp, zxtsol, zt2m, &
171         zu10m, zv10m, zq2m, zustar, zxqsurf, qsol, &
172         rain_lsc, snow_lsc, evap, bils, sens, fder, &
173         zxffonte, zxfqcalving, zxfqfonte, fluxu, &
174         fluxv, zxsnow, qsnow, snowhgt, to_ice, &
175         sissnow, runoff, albsol3_lic, evap_pot, &
176         t2m, fevap, fluxt, fluxlat, fsollw, fsolsw, &
177         wfbils, wfbilo, cdragm, cdragh, cldl, cldm, &
178         cldh, cldt, cldq, flwp, fiwp, ue, ve, uq, vq, &
179         plcl, plfc, wbeff, upwd, dnwd, dnwd0, prw, &
180         s_pblh, s_pblt, s_lcl, s_therm, uwriteSTD, &
181         vwriteSTD, wwriteSTD, phiwriteSTD, qwriteSTD, &
182         twriteSTD, ale_wake, alp_wake, wake_h, &
183         wake_omg, d_t_wake, d_q_wake, Vprecip, &
184         wdtrainA, wdtrainM, n2, s2, proba_notrig, &
185         random_notrig, ale_bl_stat, &
186         alp_bl_det, alp_bl_fluct_m, alp_bl_conv, &
187         alp_bl_stat, alp_bl_fluct_tke, slab_wfbils, &
188         weak_inversion, dthmin, cldtau, cldemi, &
189         pmflxr, pmflxs, prfl, psfl, re, fl, rh2m, &
190         qsat2m, tpote, tpot, d_ts, zxrugs, od550aer, &
191         od865aer, absvisaer, od550lt1aer, sconcso4, &
192         sconcoa, sconcbc, sconcss, sconcdust, concso4, &
193         concoa, concbc, concss, concdust, loadso4, &
194         loadoa, loadbc, loadss, loaddust, tausum_aero, &
195         topswad_aero, topswad0_aero, solswad_aero, &
196         solswad0_aero, topsw_aero, solsw_aero, &
197         topsw0_aero, solsw0_aero, topswcf_aero, &
198         solswcf_aero, topswai_aero, solswai_aero, &
199         scdnc, cldncl, reffclws, reffclwc, cldnvi, &
200         lcc, lcc3d, lcc3dcon, lcc3dstra, reffclwtop, &
201         ec550aer, flwc, fiwc, t_seri, theta, q_seri, &
202         ql_seri, zphi, u_seri, v_seri, omega, cldfra, &
203         rneb, zx_rh, frugs, agesno, d_t_dyn, d_q_dyn, &
204         d_u_dyn, d_v_dyn, d_t_con, d_t_ajsb, d_t_ajs, &
205         d_u_ajsb, d_u_ajs, d_v_ajsb, d_v_ajs, &
206         d_u_con, d_v_con, d_q_con, d_q_ajs, d_t_lsc, &
207         d_t_eva, d_q_lsc, beta_prec, d_t_lscth, &
208         d_t_lscst, d_q_lscth, d_q_lscst, plul_th, &
209         plul_st, d_t_vdf, d_t_diss, d_q_vdf, d_q_eva, &
210         zw2, fraca, zmax_th, d_q_ajsb, d_t_ec, d_u_vdf, &
211         d_v_vdf, d_u_oro, d_v_oro, d_t_oro, d_u_lif, &
212         d_v_lif, d_t_lif, d_u_hin, d_v_hin, d_t_hin, &
213         pmfd, pmfu, ref_liq, ref_ice, rhwriteSTD
214
215    USE phys_output_var_mod, only: vars_defined, snow_o, zfra_o, bils_diss, &
216         bils_ec, bils_tke, bils_kinetic, bils_latent, &
217         bils_enthalp, itau_con, nfiles, clef_files, &
218         nid_files
219    USE indice_sol_mod, only: nbsrf
220    USE infotrac, only: nqtot
221    USE comgeomphy, only: airephy
222    USE surface_data, only: type_ocean, ok_veget, ok_snow
223    USE aero_mod, only: naero_spc
224    USE ioipsl, only: histend, histsync
225    USE iophy, only: set_itau_iophy, histwrite_phy
226    USE netcdf, only: nf90_fill_real
227
228#ifdef CPP_XIOS
229    ! ug Pour les sorties XIOS
230    USE wxios, only: wxios_update_calendar, wxios_closedef
231#endif
232
233    IMPLICIT NONE
234
235    INCLUDE "temps.h"
236    INCLUDE "clesphys.h"
237    INCLUDE "thermcell.h"
238    INCLUDE "compbl.h"
239    INCLUDE "YOMCST.h"
240    INCLUDE "dimensions.h"
241    include "iniprint.h"
242
243    ! Input
244    INTEGER :: itap, ivap, read_climoz
245    INTEGER, DIMENSION(klon) :: lmax_th
246    LOGICAL :: aerosol_couple, ok_sync
247    LOGICAL :: ok_ade, ok_aie, new_aod
248    LOGICAL, DIMENSION(klon, klev) :: ptconv, ptconvth
249    REAL :: pdtphys
250    CHARACTER (LEN=4), DIMENSION(nlevSTD) :: clevSTD
251    REAL, DIMENSION(klon) :: pphis
252    REAL, DIMENSION(klon, klev) :: pplay, d_t
253    REAL, DIMENSION(klon, klev+1) :: paprs
254    REAL, DIMENSION(klon,klev,nqtot) :: qx, d_qx
255    REAL, DIMENSION(klon, llm) :: zmasse
256    LOGICAL :: flag_aerosol_strat
257    REAL, DIMENSION(3) :: freq_moyNMC
258
259    ! Local
260    INTEGER, PARAMETER :: jjmp1=jjm+1-1/jjm
261    INTEGER :: itau_w
262    INTEGER :: i, iinit, iinitend=1, iff, iq, nsrf, k, ll, naero
263    REAL, DIMENSION (klon) :: zx_tmp_fi2d
264    REAL, DIMENSION (klon,klev) :: zx_tmp_fi3d, zpt_conv
265    REAL, DIMENSION (klon,klev+1) :: zx_tmp_fi3d1
266    CHARACTER (LEN=4)              :: bb2
267    INTEGER, DIMENSION(iim*jjmp1)  :: ndex2d
268    INTEGER, DIMENSION(iim*jjmp1*klev) :: ndex3d
269    REAL, PARAMETER :: dobson_u = 2.1415e-05 ! Dobson unit, in kg m-2
270    REAL, PARAMETER :: missing_val=nf90_fill_real
271
272    ! On calcul le nouveau tau:
273    itau_w = itau_phy + itap + start_time * day_step / iphysiq
274    ! On le donne à iophy pour que les histwrite y aient accès:
275    CALL set_itau_iophy(itau_w)
276
277    IF(.NOT.vars_defined) THEN
278       iinitend = 2
279    ELSE
280       iinitend = 1
281    ENDIF
282
283    ! ug la boucle qui suit ne sert qu'une fois, pour l'initialisation, sinon il n'y a toujours qu'un seul passage:
284    DO iinit=1, iinitend
285#ifdef CPP_XIOS
286       !$OMP MASTER
287       IF (vars_defined) THEN
288          if (prt_level >= 10) then
289             write(lunout,*)"phys_output_write: call wxios_update_calendar, itau_w=",itau_w
290          endif
291          CALL wxios_update_calendar(itau_w)
292       END IF
293       !$OMP END MASTER
294       !$OMP BARRIER
295#endif
296       ! On procède à l'écriture ou à la définition des nombreuses variables:
297!!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
298       CALL histwrite_phy(o_phis, pphis)
299       CALL histwrite_phy(o_aire, airephy)
300
301       IF (vars_defined) THEN
302          DO i=1, klon
303             zx_tmp_fi2d(i)=pctsrf(i,is_ter)+pctsrf(i,is_lic)
304          ENDDO
305       ENDIF
306
307       CALL histwrite_phy(o_contfracATM, zx_tmp_fi2d)
308       CALL histwrite_phy(o_contfracOR, pctsrf(:,is_ter))
309       CALL histwrite_phy(o_aireTER, paire_ter)
310!!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
311       CALL histwrite_phy(o_flat, zxfluxlat)
312       CALL histwrite_phy(o_slp, slp)
313       CALL histwrite_phy(o_tsol, zxtsol)
314       CALL histwrite_phy(o_t2m, zt2m)
315       CALL histwrite_phy(o_t2m_min, zt2m)
316       CALL histwrite_phy(o_t2m_max, zt2m)
317
318       IF (vars_defined) THEN
319          DO i=1, klon
320             zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
321          ENDDO
322       ENDIF
323       CALL histwrite_phy(o_wind10m, zx_tmp_fi2d)
324
325       IF (vars_defined) THEN
326          DO i=1, klon
327             zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
328          ENDDO
329       ENDIF
330       CALL histwrite_phy(o_wind10max, zx_tmp_fi2d)
331
332       IF (vars_defined) THEN
333          DO i = 1, klon
334             zx_tmp_fi2d(i) = pctsrf(i,is_sic)
335          ENDDO
336       ENDIF
337       CALL histwrite_phy(o_sicf, zx_tmp_fi2d)
338       CALL histwrite_phy(o_q2m, zq2m)
339       CALL histwrite_phy(o_ustar, zustar)
340       CALL histwrite_phy(o_u10m, zu10m)
341       CALL histwrite_phy(o_v10m, zv10m)
342
343       IF (vars_defined) THEN
344          DO i = 1, klon
345             zx_tmp_fi2d(i) = paprs(i,1)
346          ENDDO
347       ENDIF
348       CALL histwrite_phy(o_psol, zx_tmp_fi2d)
349       CALL histwrite_phy(o_mass, zmasse)
350       CALL histwrite_phy(o_qsurf, zxqsurf)
351
352       IF (.NOT. ok_veget) THEN
353          CALL histwrite_phy(o_qsol, qsol)
354       ENDIF
355
356       IF (vars_defined) THEN
357          DO i = 1, klon
358             zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
359          ENDDO
360       ENDIF
361
362       CALL histwrite_phy(o_precip, zx_tmp_fi2d)
363       CALL histwrite_phy(o_ndayrain, nday_rain)
364
365       IF (vars_defined) THEN
366          DO i = 1, klon
367             zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
368          ENDDO
369       ENDIF
370       CALL histwrite_phy(o_plul, zx_tmp_fi2d)
371
372       IF (vars_defined) THEN
373          DO i = 1, klon
374             zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
375          ENDDO
376       ENDIF
377       CALL histwrite_phy(o_pluc, zx_tmp_fi2d)
378       CALL histwrite_phy(o_snow, snow_fall)
379       CALL histwrite_phy(o_msnow, snow_o)
380       CALL histwrite_phy(o_fsnow, zfra_o)
381       CALL histwrite_phy(o_evap, evap)
382       CALL histwrite_phy(o_tops, topsw)
383       CALL histwrite_phy(o_tops0, topsw0)
384       CALL histwrite_phy(o_topl, toplw)
385       CALL histwrite_phy(o_topl0, toplw0)
386
387       IF (vars_defined) THEN
388          zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
389       ENDIF
390       CALL histwrite_phy(o_SWupTOA, zx_tmp_fi2d)
391
392       IF (vars_defined) THEN
393          zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
394       ENDIF
395       CALL histwrite_phy(o_SWupTOAclr, zx_tmp_fi2d)
396
397       IF (vars_defined) THEN
398          zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
399       ENDIF
400       CALL histwrite_phy(o_SWdnTOA, zx_tmp_fi2d)
401
402       IF (vars_defined) THEN
403          zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
404       ENDIF
405       CALL histwrite_phy(o_SWdnTOAclr, zx_tmp_fi2d)
406
407       IF (vars_defined) THEN
408          zx_tmp_fi2d(:) = topsw(:)-toplw(:)
409       ENDIF
410       CALL histwrite_phy(o_nettop, zx_tmp_fi2d)
411       CALL histwrite_phy(o_SWup200, SWup200)
412       CALL histwrite_phy(o_SWup200clr, SWup200clr)
413       CALL histwrite_phy(o_SWdn200, SWdn200)
414       CALL histwrite_phy(o_SWdn200clr, SWdn200clr)
415       CALL histwrite_phy(o_LWup200, LWup200)
416       CALL histwrite_phy(o_LWup200clr, LWup200clr)
417       CALL histwrite_phy(o_LWdn200, LWdn200)
418       CALL histwrite_phy(o_LWdn200clr, LWdn200clr)
419       CALL histwrite_phy(o_sols, solsw)
420       CALL histwrite_phy(o_sols0, solsw0)
421       CALL histwrite_phy(o_soll, sollw)
422       CALL histwrite_phy(o_radsol, radsol)
423       CALL histwrite_phy(o_soll0, sollw0)
424
425       IF (vars_defined) THEN
426          zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
427       ENDIF
428       CALL histwrite_phy(o_SWupSFC, zx_tmp_fi2d)
429
430       IF (vars_defined) THEN
431          zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 1 )
432       ENDIF
433       CALL histwrite_phy(o_SWupSFCclr, zx_tmp_fi2d)
434
435       IF (vars_defined) THEN
436          zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
437       ENDIF
438       CALL histwrite_phy(o_SWdnSFC, zx_tmp_fi2d)
439
440       IF (vars_defined) THEN
441          zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 1 )
442       ENDIF
443       CALL histwrite_phy(o_SWdnSFCclr, zx_tmp_fi2d)
444
445       IF (vars_defined) THEN
446          zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
447       ENDIF
448       CALL histwrite_phy(o_LWupSFC, zx_tmp_fi2d)
449       CALL histwrite_phy(o_LWdnSFC, sollwdown)
450
451       IF (vars_defined) THEN
452          sollwdownclr(1:klon) = -1.*lwdn0(1:klon,1)
453          zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
454       ENDIF
455       CALL histwrite_phy(o_LWupSFCclr, zx_tmp_fi2d)
456       CALL histwrite_phy(o_LWdnSFCclr, sollwdownclr)
457       CALL histwrite_phy(o_bils, bils)
458       CALL histwrite_phy(o_bils_diss, bils_diss)
459       CALL histwrite_phy(o_bils_ec, bils_ec)
460       CALL histwrite_phy(o_bils_tke, bils_tke)
461       CALL histwrite_phy(o_bils_kinetic, bils_kinetic)
462       CALL histwrite_phy(o_bils_latent, bils_latent)
463       CALL histwrite_phy(o_bils_enthalp, bils_enthalp)
464
465       IF (vars_defined) THEN
466          zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
467       ENDIF
468       CALL histwrite_phy(o_sens, zx_tmp_fi2d)
469       CALL histwrite_phy(o_fder, fder)
470       CALL histwrite_phy(o_ffonte, zxffonte)
471       CALL histwrite_phy(o_fqcalving, zxfqcalving)
472       CALL histwrite_phy(o_fqfonte, zxfqfonte)
473       IF (vars_defined) THEN
474          zx_tmp_fi2d=0.
475          DO nsrf=1,nbsrf
476             zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxu(:,1,nsrf)
477          ENDDO
478       ENDIF
479       CALL histwrite_phy(o_taux, zx_tmp_fi2d)
480
481       IF (vars_defined) THEN
482          zx_tmp_fi2d=0.
483          DO nsrf=1,nbsrf
484             zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxv(:,1,nsrf)
485          ENDDO
486       ENDIF
487       CALL histwrite_phy(o_tauy, zx_tmp_fi2d)
488
489       IF (ok_snow) THEN
490          CALL histwrite_phy(o_snowsrf, zxsnow)
491          CALL histwrite_phy(o_qsnow, qsnow)
492          CALL histwrite_phy(o_snowhgt,snowhgt)
493          CALL histwrite_phy(o_toice,to_ice)
494          CALL histwrite_phy(o_sissnow,sissnow)
495          CALL histwrite_phy(o_runoff,runoff)
496          CALL histwrite_phy(o_albslw3,albsol3_lic)
497       ENDIF
498
499       DO nsrf = 1, nbsrf
500          IF (vars_defined)             zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
501          CALL histwrite_phy(o_pourc_srf(nsrf), zx_tmp_fi2d)
502          IF (vars_defined)           zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
503          CALL histwrite_phy(o_fract_srf(nsrf), zx_tmp_fi2d)
504          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
505          CALL histwrite_phy(o_taux_srf(nsrf), zx_tmp_fi2d)
506          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
507          CALL histwrite_phy(o_tauy_srf(nsrf), zx_tmp_fi2d)
508          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
509          CALL histwrite_phy(o_tsol_srf(nsrf), zx_tmp_fi2d)
510          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = evap_pot( 1 : klon, nsrf)
511          CALL histwrite_phy(o_evappot_srf(nsrf), zx_tmp_fi2d)
512          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = ustar(1 : klon, nsrf)
513          CALL histwrite_phy(o_ustar_srf(nsrf), zx_tmp_fi2d)
514          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = u10m(1 : klon, nsrf)
515          CALL histwrite_phy(o_u10m_srf(nsrf), zx_tmp_fi2d)
516          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = v10m(1 : klon, nsrf)
517          CALL histwrite_phy(o_v10m_srf(nsrf), zx_tmp_fi2d)
518          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = t2m(1 : klon, nsrf)
519          CALL histwrite_phy(o_t2m_srf(nsrf), zx_tmp_fi2d)
520          IF (vars_defined)       zx_tmp_fi2d(1 : klon) = fevap(1 : klon, nsrf)
521          CALL histwrite_phy(o_evap_srf(nsrf), zx_tmp_fi2d)
522          IF (vars_defined)        zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
523          CALL histwrite_phy(o_sens_srf(nsrf), zx_tmp_fi2d)
524          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
525          CALL histwrite_phy(o_lat_srf(nsrf), zx_tmp_fi2d)
526          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
527          CALL histwrite_phy(o_flw_srf(nsrf), zx_tmp_fi2d)
528          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
529          CALL histwrite_phy(o_fsw_srf(nsrf), zx_tmp_fi2d)
530          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
531          CALL histwrite_phy(o_wbils_srf(nsrf), zx_tmp_fi2d)
532          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfbilo( 1 : klon, nsrf)
533          CALL histwrite_phy(o_wbilo_srf(nsrf), zx_tmp_fi2d)
534
535          IF (iflag_pbl > 1) THEN
536             CALL histwrite_phy(o_tke_srf(nsrf),  pbl_tke(:,1:klev,nsrf))
537             CALL histwrite_phy(o_tke_max_srf(nsrf),  pbl_tke(:,1:klev,nsrf))
538          ENDIF
539
540       ENDDO
541       DO nsrf=1,nbsrf+1
542          CALL histwrite_phy(o_wstar(nsrf), wstar(1 : klon, nsrf))
543       ENDDO
544
545       CALL histwrite_phy(o_cdrm, cdragm)
546       CALL histwrite_phy(o_cdrh, cdragh)
547       CALL histwrite_phy(o_cldl, cldl)
548       CALL histwrite_phy(o_cldm, cldm)
549       CALL histwrite_phy(o_cldh, cldh)
550       CALL histwrite_phy(o_cldt, cldt)
551       CALL histwrite_phy(o_cldq, cldq)
552       IF (vars_defined)       zx_tmp_fi2d(1:klon) = flwp(1:klon)
553       CALL histwrite_phy(o_lwp, zx_tmp_fi2d)
554       IF (vars_defined)       zx_tmp_fi2d(1:klon) = fiwp(1:klon)
555       CALL histwrite_phy(o_iwp, zx_tmp_fi2d)
556       CALL histwrite_phy(o_ue, ue)
557       CALL histwrite_phy(o_ve, ve)
558       CALL histwrite_phy(o_uq, uq)
559       CALL histwrite_phy(o_vq, vq)
560       IF(iflag_con.GE.3) THEN ! sb
561          CALL histwrite_phy(o_cape, cape)
562          CALL histwrite_phy(o_pbase, ema_pcb)
563          CALL histwrite_phy(o_ptop, ema_pct)
564          CALL histwrite_phy(o_fbase, ema_cbmf)
565          if (iflag_con /= 30) then
566             CALL histwrite_phy(o_plcl, plcl)
567             CALL histwrite_phy(o_plfc, plfc)
568             CALL histwrite_phy(o_wbeff, wbeff)
569          end if
570
571          CALL histwrite_phy(o_cape_max, cape)
572
573          CALL histwrite_phy(o_upwd, upwd)
574          CALL histwrite_phy(o_Ma, Ma)
575          CALL histwrite_phy(o_dnwd, dnwd)
576          CALL histwrite_phy(o_dnwd0, dnwd0)
577          IF (vars_defined)         zx_tmp_fi2d=float(itau_con)/float(itap)
578          CALL histwrite_phy(o_ftime_con, zx_tmp_fi2d)
579          IF (vars_defined) THEN
580             IF(iflag_thermals>=1)THEN
581                zx_tmp_fi3d=dnwd+dnwd0+upwd+fm_therm(:,1:klev)
582             ELSE
583                zx_tmp_fi3d=dnwd+dnwd0+upwd
584             ENDIF
585          ENDIF
586          CALL histwrite_phy(o_mc, zx_tmp_fi3d)
587       ENDIF !iflag_con .GE. 3
588       CALL histwrite_phy(o_prw, prw)
589       CALL histwrite_phy(o_s_pblh, s_pblh)
590       CALL histwrite_phy(o_s_pblt, s_pblt)
591       CALL histwrite_phy(o_s_lcl, s_lcl)
592       CALL histwrite_phy(o_s_therm, s_therm)
593       !IM : Les champs suivants (s_capCL, s_oliqCL, s_cteiCL, s_trmb1, s_trmb2, s_trmb3) ne sont pas definis dans HBTM.F
594       !       IF (o_s_capCL%flag(iff)<=lev_files(iff)) THEN
595       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
596       !    $o_s_capCL%name,itau_w,s_capCL)
597       !       ENDIF
598       !       IF (o_s_oliqCL%flag(iff)<=lev_files(iff)) THEN
599       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
600       !    $o_s_oliqCL%name,itau_w,s_oliqCL)
601       !       ENDIF
602       !       IF (o_s_cteiCL%flag(iff)<=lev_files(iff)) THEN
603       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
604       !    $o_s_cteiCL%name,itau_w,s_cteiCL)
605       !       ENDIF
606       !       IF (o_s_trmb1%flag(iff)<=lev_files(iff)) THEN
607       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
608       !    $o_s_trmb1%name,itau_w,s_trmb1)
609       !       ENDIF
610       !       IF (o_s_trmb2%flag(iff)<=lev_files(iff)) THEN
611       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
612       !    $o_s_trmb2%name,itau_w,s_trmb2)
613       !       ENDIF
614       !       IF (o_s_trmb3%flag(iff)<=lev_files(iff)) THEN
615       !     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
616       !    $o_s_trmb3%name,itau_w,s_trmb3)
617       !       ENDIF
618
619       ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
620       ! Champs interpolles sur des niveaux de pression
621       DO iff=1, nfiles
622          ll=0
623          DO k=1, nlevSTD
624             bb2=clevSTD(k)
625             IF(bb2.EQ."850".OR.bb2.EQ."700".OR. &
626                  bb2.EQ."500".OR.bb2.EQ."200".OR. &
627                  bb2.EQ."100".OR. &
628                  bb2.EQ."50".OR.bb2.EQ."10") THEN
629
630                ! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
631                ll=ll+1
632                CALL histwrite_phy(o_uSTDlevs(ll),uwriteSTD(:,k,iff), iff)
633                CALL histwrite_phy(o_vSTDlevs(ll),vwriteSTD(:,k,iff), iff)
634                CALL histwrite_phy(o_wSTDlevs(ll),wwriteSTD(:,k,iff), iff)
635                CALL histwrite_phy(o_zSTDlevs(ll),phiwriteSTD(:,k,iff), iff)
636                CALL histwrite_phy(o_qSTDlevs(ll),qwriteSTD(:,k,iff), iff)
637                CALL histwrite_phy(o_tSTDlevs(ll),twriteSTD(:,k,iff), iff)
638
639             ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
640          ENDDO
641       ENDDO
642
643       IF (vars_defined) THEN
644          DO i=1, klon
645             IF (pctsrf(i,is_oce).GT.epsfra.OR. &
646                  pctsrf(i,is_sic).GT.epsfra) THEN
647                zx_tmp_fi2d(i) = (ftsol(i, is_oce) * pctsrf(i,is_oce)+ &
648                     ftsol(i, is_sic) * pctsrf(i,is_sic))/ &
649                     (pctsrf(i,is_oce)+pctsrf(i,is_sic))
650             ELSE
651                zx_tmp_fi2d(i) = 273.15
652             ENDIF
653          ENDDO
654       ENDIF
655       CALL histwrite_phy(o_t_oce_sic, zx_tmp_fi2d)
656
657       ! Couplage convection-couche limite
658       IF (iflag_con.GE.3) THEN
659          IF (iflag_coupl>=1) THEN
660             CALL histwrite_phy(o_ale_bl, ale_bl)
661             CALL histwrite_phy(o_alp_bl, alp_bl)
662          ENDIF !iflag_coupl>=1
663       ENDIF !(iflag_con.GE.3)
664       ! Wakes
665       IF (iflag_con.EQ.3) THEN
666          IF (iflag_wake>=1) THEN
667             CALL histwrite_phy(o_ale_wk, ale_wake)
668             CALL histwrite_phy(o_alp_wk, alp_wake)
669             CALL histwrite_phy(o_ale, ale)
670             CALL histwrite_phy(o_alp, alp)
671             CALL histwrite_phy(o_cin, cin)
672             CALL histwrite_phy(o_WAPE, wake_pe)
673             CALL histwrite_phy(o_wake_h, wake_h)
674             CALL histwrite_phy(o_wake_s, wake_s)
675             CALL histwrite_phy(o_wake_deltat, wake_deltat)
676             CALL histwrite_phy(o_wake_deltaq, wake_deltaq)
677             CALL histwrite_phy(o_wake_omg, wake_omg)
678             IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_wake(1:klon,1:klev) &
679                  /pdtphys
680             CALL histwrite_phy(o_dtwak, zx_tmp_fi3d)
681             IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_wake(1:klon,1:klev)/pdtphys
682             CALL histwrite_phy(o_dqwak, zx_tmp_fi3d)
683          ENDIF ! iflag_wake>=1
684          CALL histwrite_phy(o_Vprecip, Vprecip)
685          CALL histwrite_phy(o_ftd, ftd)
686          CALL histwrite_phy(o_fqd, fqd)
687       ELSEIF (iflag_con.EQ.30) THEN
688          ! sortie RomP convection descente insaturee iflag_con=30
689          CALL histwrite_phy(o_Vprecip, Vprecip)
690          CALL histwrite_phy(o_wdtrainA, wdtrainA)
691          CALL histwrite_phy(o_wdtrainM, wdtrainM)
692       ENDIF !(iflag_con.EQ.3.or.iflag_con.EQ.30)
693!!! nrlmd le 10/04/2012
694       IF (iflag_trig_bl>=1) THEN
695          CALL histwrite_phy(o_n2, n2)
696          CALL histwrite_phy(o_s2, s2)
697          CALL histwrite_phy(o_proba_notrig, proba_notrig)
698          CALL histwrite_phy(o_random_notrig, random_notrig)
699          CALL histwrite_phy(o_ale_bl_stat, ale_bl_stat)
700          CALL histwrite_phy(o_ale_bl_trig, ale_bl_trig)
701       ENDIF  !(iflag_trig_bl>=1)
702       IF (iflag_clos_bl>=1) THEN
703          CALL histwrite_phy(o_alp_bl_det, alp_bl_det)
704          CALL histwrite_phy(o_alp_bl_fluct_m, alp_bl_fluct_m)
705          CALL histwrite_phy(o_alp_bl_fluct_tke,  &
706               alp_bl_fluct_tke)
707          CALL histwrite_phy(o_alp_bl_conv, alp_bl_conv)
708          CALL histwrite_phy(o_alp_bl_stat, alp_bl_stat)
709       ENDIF  !(iflag_clos_bl>=1)
710!!! fin nrlmd le 10/04/2012
711       IF (type_ocean=='slab ') THEN
712          CALL histwrite_phy(o_slab_bils, slab_wfbils)
713       ENDIF !type_ocean == force/slab
714       CALL histwrite_phy(o_weakinv, weak_inversion)
715       CALL histwrite_phy(o_dthmin, dthmin)
716       CALL histwrite_phy(o_cldtau, cldtau)
717       CALL histwrite_phy(o_cldemi, cldemi)
718       CALL histwrite_phy(o_pr_con_l, pmflxr(:,1:klev))
719       CALL histwrite_phy(o_pr_con_i, pmflxs(:,1:klev))
720       CALL histwrite_phy(o_pr_lsc_l, prfl(:,1:klev))
721       CALL histwrite_phy(o_pr_lsc_i, psfl(:,1:klev))
722       CALL histwrite_phy(o_re, re)
723       CALL histwrite_phy(o_fl, fl)
724       IF (vars_defined) THEN
725          DO i=1, klon
726             zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
727          ENDDO
728       ENDIF
729       CALL histwrite_phy(o_rh2m, zx_tmp_fi2d)
730
731       IF (vars_defined) THEN
732          DO i=1, klon
733             zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
734          ENDDO
735       ENDIF
736       CALL histwrite_phy(o_rh2m_min, zx_tmp_fi2d)
737
738       IF (vars_defined) THEN
739          DO i=1, klon
740             zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
741          ENDDO
742       ENDIF
743       CALL histwrite_phy(o_rh2m_max, zx_tmp_fi2d)
744
745       CALL histwrite_phy(o_qsat2m, qsat2m)
746       CALL histwrite_phy(o_tpot, tpot)
747       CALL histwrite_phy(o_tpote, tpote)
748       IF (vars_defined) zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, is_ter)
749       CALL histwrite_phy(o_SWnetOR,  zx_tmp_fi2d)
750       IF (vars_defined) zx_tmp_fi2d(1:klon) = solsw(1:klon)/(1.-albsol1(1:klon))
751       CALL histwrite_phy(o_SWdownOR,  zx_tmp_fi2d)
752       CALL histwrite_phy(o_LWdownOR, sollwdown)
753       CALL histwrite_phy(o_snowl, snow_lsc)
754       CALL histwrite_phy(o_solldown, sollwdown)
755       CALL histwrite_phy(o_dtsvdfo, d_ts(:,is_oce))
756       CALL histwrite_phy(o_dtsvdft, d_ts(:,is_ter))
757       CALL histwrite_phy(o_dtsvdfg,  d_ts(:,is_lic))
758       CALL histwrite_phy(o_dtsvdfi, d_ts(:,is_sic))
759       CALL histwrite_phy(o_rugs, zxrugs)
760       ! OD550 per species
761       IF (new_aod .and. (.not. aerosol_couple)) THEN
762          IF (ok_ade.OR.ok_aie) THEN
763             CALL histwrite_phy(o_od550aer, od550aer)
764             CALL histwrite_phy(o_od865aer, od865aer)
765             CALL histwrite_phy(o_absvisaer, absvisaer)
766             CALL histwrite_phy(o_od550lt1aer, od550lt1aer)
767             CALL histwrite_phy(o_sconcso4, sconcso4)
768             CALL histwrite_phy(o_sconcoa, sconcoa)
769             CALL histwrite_phy(o_sconcbc, sconcbc)
770             CALL histwrite_phy(o_sconcss, sconcss)
771             CALL histwrite_phy(o_sconcdust, sconcdust)
772             CALL histwrite_phy(o_concso4, concso4)
773             CALL histwrite_phy(o_concoa, concoa)
774             CALL histwrite_phy(o_concbc, concbc)
775             CALL histwrite_phy(o_concss, concss)
776             CALL histwrite_phy(o_concdust, concdust)
777             CALL histwrite_phy(o_loadso4, loadso4)
778             CALL histwrite_phy(o_loadoa, loadoa)
779             CALL histwrite_phy(o_loadbc, loadbc)
780             CALL histwrite_phy(o_loadss, loadss)
781             CALL histwrite_phy(o_loaddust, loaddust)
782             !--STRAT AER
783          ENDIF
784          IF (ok_ade.OR.ok_aie.OR.flag_aerosol_strat) THEN
785             DO naero = 1, naero_spc
786                CALL histwrite_phy(o_tausumaero(naero), &
787                     tausum_aero(:,2,naero) )
788             END DO
789          ENDIF
790       ENDIF
791       IF (ok_ade) THEN
792          CALL histwrite_phy(o_topswad, topswad_aero)
793          CALL histwrite_phy(o_topswad0, topswad0_aero)
794          CALL histwrite_phy(o_solswad, solswad_aero)
795          CALL histwrite_phy(o_solswad0, solswad0_aero)
796          !====MS forcing diagnostics
797          if (new_aod) then
798             CALL histwrite_phy(o_swtoaas_nat, topsw_aero(:,1))
799             CALL histwrite_phy(o_swsrfas_nat, solsw_aero(:,1))
800             CALL histwrite_phy(o_swtoacs_nat, topsw0_aero(:,1))
801             CALL histwrite_phy(o_swsrfcs_nat, solsw0_aero(:,1))
802             !ant
803             CALL histwrite_phy(o_swtoaas_ant, topsw_aero(:,2))
804             CALL histwrite_phy(o_swsrfas_ant, solsw_aero(:,2))
805             CALL histwrite_phy(o_swtoacs_ant, topsw0_aero(:,2))
806             CALL histwrite_phy(o_swsrfcs_ant, solsw0_aero(:,2))
807             !cf
808             if (.not. aerosol_couple) then
809                CALL histwrite_phy(o_swtoacf_nat, topswcf_aero(:,1))
810                CALL histwrite_phy(o_swsrfcf_nat, solswcf_aero(:,1))
811                CALL histwrite_phy(o_swtoacf_ant, topswcf_aero(:,2))
812                CALL histwrite_phy(o_swsrfcf_ant, solswcf_aero(:,2))
813                CALL histwrite_phy(o_swtoacf_zero,topswcf_aero(:,3))
814                CALL histwrite_phy(o_swsrfcf_zero,solswcf_aero(:,3))
815             endif
816          endif ! new_aod
817          !====MS forcing diagnostics
818       ENDIF
819       IF (ok_aie) THEN
820          CALL histwrite_phy(o_topswai, topswai_aero)
821          CALL histwrite_phy(o_solswai, solswai_aero)
822          CALL histwrite_phy(o_scdnc, scdnc)
823          CALL histwrite_phy(o_cldncl, cldncl)
824          CALL histwrite_phy(o_reffclws, reffclws)
825          CALL histwrite_phy(o_reffclwc, reffclwc)
826          CALL histwrite_phy(o_cldnvi, cldnvi)
827          CALL histwrite_phy(o_lcc, lcc)
828          CALL histwrite_phy(o_lcc3d, lcc3d)
829          CALL histwrite_phy(o_lcc3dcon, lcc3dcon)
830          CALL histwrite_phy(o_lcc3dstra, lcc3dstra)
831          CALL histwrite_phy(o_reffclwtop, reffclwtop)
832       ENDIF
833       ! Champs 3D:
834       IF (ok_ade .OR. ok_aie) then
835          CALL histwrite_phy(o_ec550aer, ec550aer)
836       ENDIF
837       CALL histwrite_phy(o_lwcon, flwc)
838       CALL histwrite_phy(o_iwcon, fiwc)
839       CALL histwrite_phy(o_temp, t_seri)
840       CALL histwrite_phy(o_theta, theta)
841       CALL histwrite_phy(o_ovapinit, qx(:,:,ivap))
842       CALL histwrite_phy(o_ovap, q_seri)
843       CALL histwrite_phy(o_oliq, ql_seri)
844       CALL histwrite_phy(o_geop, zphi)
845       CALL histwrite_phy(o_vitu, u_seri)
846       CALL histwrite_phy(o_vitv, v_seri)
847       CALL histwrite_phy(o_vitw, omega)
848       CALL histwrite_phy(o_pres, pplay)
849       CALL histwrite_phy(o_paprs, paprs(:,1:klev))
850       IF (vars_defined) THEN
851          DO i=1, klon
852             zx_tmp_fi3d1(i,1)= pphis(i)/RG
853             !020611   zx_tmp_fi3d(i,1)= pphis(i)/RG
854          ENDDO
855          DO k=1, klev
856             !020611        DO k=1, klev-1
857             DO i=1, klon
858                !020611         zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - (t_seri(i,k) *RD *
859                zx_tmp_fi3d1(i,k+1)= zx_tmp_fi3d1(i,k) - (t_seri(i,k) *RD *  &
860                     (paprs(i,k+1) - paprs(i,k))) / ( pplay(i,k) * RG )
861             ENDDO
862          ENDDO
863       ENDIF
864       CALL histwrite_phy(o_zfull,zx_tmp_fi3d1(:,2:klevp1))
865       !020611    $o_zfull%name,itau_w,zx_tmp_fi3d)
866
867       IF (vars_defined)  THEN
868          DO i=1, klon
869             zx_tmp_fi3d(i,1)= pphis(i)/RG - ( &
870                  (t_seri(i,1)+zxtsol(i))/2. *RD * &
871                  (pplay(i,1) - paprs(i,1)))/( (paprs(i,1)+pplay(i,1))/2.* RG)
872          ENDDO
873          DO k=1, klev-1
874             DO i=1, klon
875                zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - ( &
876                     (t_seri(i,k)+t_seri(i,k+1))/2. *RD *  &
877                     (pplay(i,k+1) - pplay(i,k))) / ( paprs(i,k) * RG )
878             ENDDO
879          ENDDO
880       ENDIF
881       CALL histwrite_phy(o_zhalf, zx_tmp_fi3d)
882       CALL histwrite_phy(o_rneb, cldfra)
883       CALL histwrite_phy(o_rnebcon, rnebcon)
884       CALL histwrite_phy(o_rnebls, rneb)
885       CALL histwrite_phy(o_rhum, zx_rh)
886       CALL histwrite_phy(o_ozone, &
887            wo(:, :, 1) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
888
889       IF (read_climoz == 2) THEN
890          CALL histwrite_phy(o_ozone_light, &
891               wo(:, :, 2) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
892       ENDIF
893
894       CALL histwrite_phy(o_dtphy, d_t)
895       CALL histwrite_phy(o_dqphy,  d_qx(:,:,ivap))
896       DO nsrf=1, nbsrf
897          IF (vars_defined) zx_tmp_fi2d(1 : klon) = falb1( 1 : klon, nsrf)
898          CALL histwrite_phy(o_albe_srf(nsrf), zx_tmp_fi2d)
899          IF (vars_defined) zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
900          CALL histwrite_phy(o_rugs_srf(nsrf), zx_tmp_fi2d)
901          IF (vars_defined) zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
902          CALL histwrite_phy(o_ages_srf(nsrf), zx_tmp_fi2d)
903       ENDDO !nsrf=1, nbsrf
904       CALL histwrite_phy(o_alb1, albsol1)
905       CALL histwrite_phy(o_alb2, albsol2)
906       !FH Sorties pour la couche limite
907       if (iflag_pbl>1) then
908          zx_tmp_fi3d=0.
909          IF (vars_defined) THEN
910             do nsrf=1,nbsrf
911                do k=1,klev
912                   zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k) &
913                        +pctsrf(:,nsrf)*pbl_tke(:,k,nsrf)
914                enddo
915             enddo
916          ENDIF
917          CALL histwrite_phy(o_tke, zx_tmp_fi3d)
918
919          CALL histwrite_phy(o_tke_max, zx_tmp_fi3d)
920       ENDIF
921
922       CALL histwrite_phy(o_kz, coefh(:,:,is_ave))
923
924       CALL histwrite_phy(o_kz_max, coefh(:,:,is_ave))
925
926       CALL histwrite_phy(o_clwcon, clwcon0)
927       CALL histwrite_phy(o_dtdyn, d_t_dyn)
928       CALL histwrite_phy(o_dqdyn, d_q_dyn)
929       CALL histwrite_phy(o_dudyn, d_u_dyn)
930       CALL histwrite_phy(o_dvdyn, d_v_dyn)
931
932       IF (vars_defined) THEN
933          zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys
934       ENDIF
935       CALL histwrite_phy(o_dtcon, zx_tmp_fi3d)
936       if(iflag_thermals.eq.1)then
937          IF (vars_defined) THEN
938             zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys + &
939                  d_t_ajsb(1:klon,1:klev)/pdtphys
940          ENDIF
941          CALL histwrite_phy(o_tntc, zx_tmp_fi3d)
942       else if(iflag_thermals.gt.1.and.iflag_wake.EQ.1)then
943          IF (vars_defined) THEN
944             zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys + &
945                  d_t_ajs(1:klon,1:klev)/pdtphys + &
946                  d_t_wake(1:klon,1:klev)/pdtphys
947          ENDIF
948          CALL histwrite_phy(o_tntc, zx_tmp_fi3d)
949       endif
950       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_con(1:klon,1:klev)/pdtphys
951       CALL histwrite_phy(o_ducon, zx_tmp_fi3d)
952       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_con(1:klon,1:klev)/pdtphys
953       CALL histwrite_phy(o_dvcon, zx_tmp_fi3d)
954       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
955       CALL histwrite_phy(o_dqcon, zx_tmp_fi3d)
956
957       IF(iflag_thermals.EQ.1) THEN
958          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
959          CALL histwrite_phy(o_tnhusc, zx_tmp_fi3d)
960       ELSE IF(iflag_thermals.GT.1.AND.iflag_wake.EQ.1) THEN
961          IF (vars_defined) THEN
962             zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys + &
963                  d_q_ajs(1:klon,1:klev)/pdtphys + &
964                  d_q_wake(1:klon,1:klev)/pdtphys
965          ENDIF
966          CALL histwrite_phy(o_tnhusc, zx_tmp_fi3d)
967       ENDIF
968
969       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lsc(1:klon,1:klev)/pdtphys
970       CALL histwrite_phy(o_dtlsc, zx_tmp_fi3d)
971       IF (vars_defined) zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+ &
972            d_t_eva(1:klon,1:klev))/pdtphys
973       CALL histwrite_phy(o_dtlschr, zx_tmp_fi3d)
974       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
975       CALL histwrite_phy(o_dqlsc, zx_tmp_fi3d)
976       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=beta_prec(1:klon,1:klev)
977       CALL histwrite_phy(o_beta_prec, zx_tmp_fi3d)
978!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
979       ! Sorties specifiques a la separation thermiques/non thermiques
980       if (iflag_thermals>=1) then
981          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lscth(1:klon,1:klev)/pdtphys
982          CALL histwrite_phy(o_dtlscth, zx_tmp_fi3d)
983          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lscst(1:klon,1:klev)/pdtphys
984          CALL histwrite_phy(o_dtlscst, zx_tmp_fi3d)
985          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
986          CALL histwrite_phy(o_dqlscth, zx_tmp_fi3d)
987          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
988          CALL histwrite_phy(o_dqlscst, zx_tmp_fi3d)
989          CALL histwrite_phy(o_plulth, plul_th)
990          CALL histwrite_phy(o_plulst, plul_st)
991          IF (vars_defined) THEN
992             do k=1,klev
993                do i=1,klon
994                   if (ptconvth(i,k)) then
995                      zx_tmp_fi3d(i,k)=1.
996                   else
997                      zx_tmp_fi3d(i,k)=0.
998                   endif
999                enddo
1000             enddo
1001          ENDIF
1002          CALL histwrite_phy(o_ptconvth, zx_tmp_fi3d)
1003          IF (vars_defined) THEN
1004             do i=1,klon
1005                zx_tmp_fi2d(1:klon)=lmax_th(:)
1006             enddo
1007          ENDIF
1008          CALL histwrite_phy(o_lmaxth, zx_tmp_fi2d)
1009       endif ! iflag_thermals>=1
1010!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1011       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
1012       CALL histwrite_phy(o_dtvdf, zx_tmp_fi3d)
1013       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_diss(1:klon,1:klev)/pdtphys
1014       CALL histwrite_phy(o_dtdis, zx_tmp_fi3d)
1015       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
1016       CALL histwrite_phy(o_dqvdf, zx_tmp_fi3d)
1017       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
1018       CALL histwrite_phy(o_dteva, zx_tmp_fi3d)
1019       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
1020       CALL histwrite_phy(o_dqeva, zx_tmp_fi3d)
1021       zpt_conv = 0.
1022       WHERE (ptconv) zpt_conv = 1.
1023       CALL histwrite_phy(o_ptconv, zpt_conv)
1024       CALL histwrite_phy(o_ratqs, ratqs)
1025       IF (vars_defined) THEN
1026          zx_tmp_fi3d(1:klon,1:klev)=d_t_ajs(1:klon,1:klev)/pdtphys - &
1027               d_t_ajsb(1:klon,1:klev)/pdtphys
1028       ENDIF
1029       CALL histwrite_phy(o_dtthe, zx_tmp_fi3d)
1030       IF (vars_defined) THEN
1031          zx_tmp_fi3d(1:klon,1:klev)=d_u_ajs(1:klon,1:klev)/pdtphys - &
1032               d_u_ajsb(1:klon,1:klev)/pdtphys
1033       ENDIF
1034       CALL histwrite_phy(o_duthe, zx_tmp_fi3d)
1035       IF (vars_defined) THEN
1036          zx_tmp_fi3d(1:klon,1:klev)=d_v_ajs(1:klon,1:klev)/pdtphys - &
1037               d_v_ajsb(1:klon,1:klev)/pdtphys
1038       ENDIF
1039       CALL histwrite_phy(o_dvthe, zx_tmp_fi3d)
1040
1041       IF (iflag_thermals>=1) THEN
1042          ! Pour l instant 0 a y reflichir pour les thermiques
1043          zx_tmp_fi2d=0.
1044          CALL histwrite_phy(o_ftime_th, zx_tmp_fi2d)
1045          CALL histwrite_phy(o_f_th, fm_therm)
1046          CALL histwrite_phy(o_e_th, entr_therm)
1047          CALL histwrite_phy(o_w_th, zw2)
1048          CALL histwrite_phy(o_q_th, zqasc)
1049          CALL histwrite_phy(o_a_th, fraca)
1050          CALL histwrite_phy(o_d_th, detr_therm)
1051          CALL histwrite_phy(o_f0_th, f0)
1052          CALL histwrite_phy(o_zmax_th, zmax_th)
1053          IF (vars_defined) THEN
1054             zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys - &
1055                  d_q_ajsb(1:klon,1:klev)/pdtphys
1056          ENDIF
1057          CALL histwrite_phy(o_dqthe, zx_tmp_fi3d)
1058       ENDIF !iflag_thermals
1059       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_ajsb(1:klon,1:klev)/pdtphys
1060       CALL histwrite_phy(o_dtajs, zx_tmp_fi3d)
1061       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
1062       CALL histwrite_phy(o_dqajs, zx_tmp_fi3d)
1063       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY
1064       CALL histwrite_phy(o_dtswr, zx_tmp_fi3d)
1065       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
1066       CALL histwrite_phy(o_dtsw0, zx_tmp_fi3d)
1067       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
1068       CALL histwrite_phy(o_dtlwr, zx_tmp_fi3d)
1069       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
1070       CALL histwrite_phy(o_dtlw0, zx_tmp_fi3d)
1071       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)/pdtphys
1072       CALL histwrite_phy(o_dtec, zx_tmp_fi3d)
1073       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
1074       CALL histwrite_phy(o_duvdf, zx_tmp_fi3d)
1075       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
1076       CALL histwrite_phy(o_dvvdf, zx_tmp_fi3d)
1077       IF (ok_orodr) THEN
1078          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
1079          CALL histwrite_phy(o_duoro, zx_tmp_fi3d)
1080          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
1081          CALL histwrite_phy(o_dvoro, zx_tmp_fi3d)
1082          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_oro(1:klon,1:klev)/pdtphys
1083          CALL histwrite_phy(o_dtoro, zx_tmp_fi3d)
1084       ENDIF
1085       IF (ok_orolf) THEN
1086          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
1087          CALL histwrite_phy(o_dulif, zx_tmp_fi3d)
1088
1089          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
1090          CALL histwrite_phy(o_dvlif, zx_tmp_fi3d)
1091
1092          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lif(1:klon,1:klev)/pdtphys
1093          CALL histwrite_phy(o_dtlif, zx_tmp_fi3d)
1094       ENDIF
1095
1096       IF (ok_hines) THEN
1097          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_hin(1:klon,1:klev)/pdtphys
1098          CALL histwrite_phy(o_duhin, zx_tmp_fi3d)
1099          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_hin(1:klon,1:klev)/pdtphys
1100          CALL histwrite_phy(o_dvhin, zx_tmp_fi3d)
1101          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_hin(1:klon,1:klev)/pdtphys
1102          CALL histwrite_phy(o_dthin, zx_tmp_fi3d)
1103       ENDIF
1104       CALL histwrite_phy(o_rsu, swup)
1105       CALL histwrite_phy(o_rsd, swdn)
1106       CALL histwrite_phy(o_rlu, lwup)
1107       CALL histwrite_phy(o_rld, lwdn)
1108       CALL histwrite_phy(o_rsucs, swup0)
1109       CALL histwrite_phy(o_rsdcs, swdn0)
1110       CALL histwrite_phy(o_rlucs, lwup0)
1111       CALL histwrite_phy(o_rldcs, lwdn0)
1112       IF(vars_defined) THEN
1113          zx_tmp_fi3d(1:klon,1:klev)=d_t(1:klon,1:klev)+ &
1114               d_t_dyn(1:klon,1:klev)
1115       ENDIF
1116       CALL histwrite_phy(o_tnt, zx_tmp_fi3d)
1117       IF(vars_defined) THEN
1118          zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY - &
1119               cool(1:klon,1:klev)/RDAY
1120       ENDIF
1121       CALL histwrite_phy(o_tntr, zx_tmp_fi3d)
1122       IF(vars_defined) THEN
1123          zx_tmp_fi3d(1:klon,1:klev)= (d_t_lsc(1:klon,1:klev)+ &
1124               d_t_eva(1:klon,1:klev)+ &
1125               d_t_vdf(1:klon,1:klev))/pdtphys
1126       ENDIF
1127       CALL histwrite_phy(o_tntscpbl, zx_tmp_fi3d)
1128       IF(vars_defined) THEN
1129          zx_tmp_fi3d(1:klon,1:klev)=d_qx(1:klon,1:klev,ivap)+ &
1130               d_q_dyn(1:klon,1:klev)
1131       ENDIF
1132       CALL histwrite_phy(o_tnhus, zx_tmp_fi3d)
1133       IF(vars_defined) THEN
1134          zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys+ &
1135               d_q_eva(1:klon,1:klev)/pdtphys
1136       ENDIF
1137       CALL histwrite_phy(o_tnhusscpbl, zx_tmp_fi3d)
1138       CALL histwrite_phy(o_evu, coefm(:,:,is_ave))
1139       IF(vars_defined) THEN
1140          zx_tmp_fi3d(1:klon,1:klev)=q_seri(1:klon,1:klev)+ &
1141               ql_seri(1:klon,1:klev)
1142       ENDIF
1143       CALL histwrite_phy(o_h2o, zx_tmp_fi3d)
1144       if (iflag_con >= 3) then
1145          IF(vars_defined) THEN
1146             zx_tmp_fi3d(1:klon,1:klev)=-1 * (dnwd(1:klon,1:klev)+ &
1147                  dnwd0(1:klon,1:klev))
1148          ENDIF
1149          CALL histwrite_phy(o_mcd, zx_tmp_fi3d)
1150          IF(vars_defined) THEN
1151             zx_tmp_fi3d(1:klon,1:klev)=upwd(1:klon,1:klev) + &
1152                  dnwd(1:klon,1:klev)+ dnwd0(1:klon,1:klev)
1153          ENDIF
1154          CALL histwrite_phy(o_dmc, zx_tmp_fi3d)
1155       else if (iflag_con == 2) then
1156          CALL histwrite_phy(o_mcd,  pmfd)
1157          CALL histwrite_phy(o_dmc,  pmfu + pmfd)
1158       end if
1159       CALL histwrite_phy(o_ref_liq, ref_liq)
1160       CALL histwrite_phy(o_ref_ice, ref_ice)
1161       if (RCO2_per.NE.RCO2_act.OR.RCH4_per.NE.RCH4_act.OR. &
1162            RN2O_per.NE.RN2O_act.OR.RCFC11_per.NE.RCFC11_act.OR. &
1163            RCFC12_per.NE.RCFC12_act) THEN
1164          IF(vars_defined) zx_tmp_fi2d(1 : klon) = swupp ( 1 : klon, klevp1 )
1165          CALL histwrite_phy(o_rsut4co2, zx_tmp_fi2d)
1166          IF(vars_defined) zx_tmp_fi2d(1 : klon) = lwupp ( 1 : klon, klevp1 )
1167          CALL histwrite_phy(o_rlut4co2, zx_tmp_fi2d)
1168          IF(vars_defined) zx_tmp_fi2d(1 : klon) = swup0p ( 1 : klon, klevp1 )
1169          CALL histwrite_phy(o_rsutcs4co2, zx_tmp_fi2d)
1170          IF(vars_defined) zx_tmp_fi2d(1 : klon) = lwup0p ( 1 : klon, klevp1 )
1171          CALL histwrite_phy(o_rlutcs4co2, zx_tmp_fi2d)
1172          CALL histwrite_phy(o_rsu4co2, swupp)
1173          CALL histwrite_phy(o_rlu4co2, lwupp)
1174          CALL histwrite_phy(o_rsucs4co2, swup0p)
1175          CALL histwrite_phy(o_rlucs4co2, lwup0p)
1176          CALL histwrite_phy(o_rsd4co2, swdnp)
1177          CALL histwrite_phy(o_rld4co2, lwdnp)
1178          CALL histwrite_phy(o_rsdcs4co2, swdn0p)
1179          CALL histwrite_phy(o_rldcs4co2, lwdn0p)
1180       ENDIF
1181!!!!!!!!!!!! Sorties niveaux de pression NMC !!!!!!!!!!!!!!!!!!!!
1182       DO iff=7, nfiles
1183
1184          CALL histwrite_phy(o_tnondef,tnondef(:,:,iff-6),iff)
1185          CALL histwrite_phy(o_ta,twriteSTD(:,:,iff-6),iff)
1186          CALL histwrite_phy(o_zg,phiwriteSTD(:,:,iff-6),iff)
1187          CALL histwrite_phy(o_hus,qwriteSTD(:,:,iff-6),iff)
1188          CALL histwrite_phy(o_hur,rhwriteSTD(:,:,iff-6),iff)
1189          CALL histwrite_phy(o_ua,uwriteSTD(:,:,iff-6),iff)
1190          CALL histwrite_phy(o_va,vwriteSTD(:,:,iff-6),iff)
1191          CALL histwrite_phy(o_wap,wwriteSTD(:,:,iff-6),iff)
1192          IF(vars_defined) THEN
1193             DO k=1, nlevSTD
1194                DO i=1, klon
1195                   IF(tnondef(i,k,iff-6).NE.missing_val) THEN
1196                      zx_tmp_fi3d(i,k) = (100.*tnondef(i,k,iff-6))/freq_moyNMC(iff-6)
1197                   ELSE
1198                      zx_tmp_fi3d(i,k) = missing_val
1199                   ENDIF
1200                ENDDO
1201             ENDDO
1202          ENDIF
1203          CALL histwrite_phy(o_psbg,zx_tmp_fi3d,iff)
1204          IF(vars_defined) THEN
1205             DO k=1, nlevSTD
1206                DO i=1, klon
1207                   IF(O3sumSTD(i,k,iff-6).NE.missing_val) THEN
1208                      zx_tmp_fi3d(i,k) = O3sumSTD(i,k,iff-6) * 1.e+9
1209                   ELSE
1210                      zx_tmp_fi3d(i,k) = missing_val
1211                   ENDIF
1212                ENDDO
1213             ENDDO !k=1, nlevSTD
1214          ENDIF
1215          CALL histwrite_phy(o_tro3,zx_tmp_fi3d,iff)
1216          if (read_climoz == 2) THEN
1217             IF(vars_defined) THEN
1218                DO k=1, nlevSTD
1219                   DO i=1, klon
1220                      IF(O3daysumSTD(i,k,iff-6).NE.missing_val) THEN
1221                         zx_tmp_fi3d(i,k) = O3daysumSTD(i,k,iff-6) * 1.e+9
1222                      ELSE
1223                         zx_tmp_fi3d(i,k) = missing_val
1224                      ENDIF
1225                   ENDDO
1226                ENDDO !k=1, nlevSTD
1227             ENDIF
1228             CALL histwrite_phy(o_tro3_daylight,zx_tmp_fi3d,iff)
1229          endif
1230          CALL histwrite_phy(o_uxv,uvsumSTD(:,:,iff-6),iff)
1231          CALL histwrite_phy(o_vxq,vqsumSTD(:,:,iff-6),iff)
1232          CALL histwrite_phy(o_vxT,vTsumSTD(:,:,iff-6),iff)
1233          CALL histwrite_phy(o_wxq,wqsumSTD(:,:,iff-6),iff)
1234          CALL histwrite_phy(o_vxphi,vphisumSTD(:,:,iff-6),iff)
1235          CALL histwrite_phy(o_wxT,wTsumSTD(:,:,iff-6),iff)
1236          CALL histwrite_phy(o_uxu,u2sumSTD(:,:,iff-6),iff)
1237          CALL histwrite_phy(o_vxv,v2sumSTD(:,:,iff-6),iff)
1238          CALL histwrite_phy(o_TxT,T2sumSTD(:,:,iff-6),iff)
1239       ENDDO !nfiles
1240!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1241       IF (nqtot.GE.3) THEN
1242          DO iq=3,nqtot
1243             CALL histwrite_phy(o_trac(iq-2), qx(:,:,iq))
1244             CALL histwrite_phy(o_dtr_vdf(iq-2),d_tr_cl(:,:,iq-2))
1245             CALL histwrite_phy(o_dtr_the(iq-2),d_tr_th(:,:,iq-2))
1246             CALL histwrite_phy(o_dtr_con(iq-2),d_tr_cv(:,:,iq-2))
1247             CALL histwrite_phy(o_dtr_lessi_impa(iq-2),d_tr_lessi_impa(:,:,iq-2))
1248             CALL histwrite_phy(o_dtr_lessi_nucl(iq-2),d_tr_lessi_nucl(:,:,iq-2))
1249             CALL histwrite_phy(o_dtr_insc(iq-2),d_tr_insc(:,:,iq-2))
1250             CALL histwrite_phy(o_dtr_bcscav(iq-2),d_tr_bcscav(:,:,iq-2))
1251             CALL histwrite_phy(o_dtr_evapls(iq-2),d_tr_evapls(:,:,iq-2))
1252             CALL histwrite_phy(o_dtr_ls(iq-2),d_tr_ls(:,:,iq-2))
1253             CALL histwrite_phy(o_dtr_trsp(iq-2),d_tr_trsp(:,:,iq-2))
1254             CALL histwrite_phy(o_dtr_sscav(iq-2),d_tr_sscav(:,:,iq-2))
1255             CALL histwrite_phy(o_dtr_sat(iq-2),d_tr_sat(:,:,iq-2))
1256             CALL histwrite_phy(o_dtr_uscav(iq-2),d_tr_uscav(:,:,iq-2))
1257             zx_tmp_fi2d=0.
1258             IF(vars_defined) THEN
1259                DO k=1,klev
1260                   zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*qx(:,k,iq)
1261                ENDDO
1262             ENDIF
1263             CALL histwrite_phy(o_trac_cum(iq-2), zx_tmp_fi2d)
1264          ENDDO
1265       ENDIF
1266
1267       IF(.NOT.vars_defined) THEN
1268          !$OMP MASTER
1269#ifndef CPP_NO_IOIPSL
1270          DO iff=1,nfiles
1271             IF (clef_files(iff)) THEN
1272                CALL histend(nid_files(iff))
1273                ndex2d = 0
1274                ndex3d = 0
1275
1276             ENDIF ! clef_files
1277          ENDDO !  iff
1278#endif
1279#ifdef CPP_XIOS
1280          !On finalise l'initialisation:
1281          CALL wxios_closedef()
1282#endif
1283
1284          !$OMP END MASTER
1285          !$OMP BARRIER
1286          vars_defined = .TRUE.
1287
1288       END IF
1289
1290    END DO
1291
1292    IF(vars_defined) THEN
1293       ! On synchronise les fichiers pour IOIPSL
1294#ifndef CPP_NO_IOIPSL
1295       !$OMP MASTER
1296       DO iff=1,nfiles
1297          IF (ok_sync .AND. clef_files(iff)) THEN
1298             CALL histsync(nid_files(iff))
1299          ENDIF
1300       END DO
1301       !$OMP END MASTER
1302#endif
1303    ENDIF
1304
1305  END SUBROUTINE phys_output_write
1306
1307END MODULE phys_output_write_mod
Note: See TracBrowser for help on using the repository browser.