Index: LMDZ5/trunk/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 2670)
+++ LMDZ5/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 2690)
@@ -182,4 +182,12 @@
          o_alt_tropo
 
+#ifdef CPP_StratAer
+    USE phys_output_ctrlout_mod, only:  & 
+         o_sulf_convert, o_sulf_nucl, o_sulf_cond_evap, o_ocs_convert, &
+         o_sfluxaer, o_R2SO4, o_OCS_lifetime, o_SO2_lifetime, &
+         o_OCS_backgr_tend, o_SO2_backgr_tend, o_sulf_dep_dry, o_sulf_dep_wet, &
+         o_surf_PM25_sulf, o_ext_strat_550, o_tau_strat_550, &
+         o_p_tropopause, o_vsed_aer, o_tau_strat_1020, o_ext_strat_1020, o_f_r_wet
+#endif
 
     USE phys_state_var_mod, only: pctsrf, paire_ter, rain_fall, snow_fall, &
@@ -273,4 +281,13 @@
          ep, epmax_diag ! epmax_cape
 
+#ifdef CPP_StratAer 
+    USE phys_local_var_mod, only:  &
+         sulf_convert, sulf_nucl, sulf_cond_evap, ocs_convert, &
+         sfluxaer, R2SO4, OCS_lifetime, SO2_lifetime, &
+         OCS_backgr_tend, SO2_backgr_tend, sulf_dep_dry, sulf_dep_wet, &
+         surf_PM25_sulf, tau_strat_550, p_tropopause, tausum_strat, &
+         vsed_aer, tau_strat_1020, f_r_wet
+#endif
+
     USE phys_output_var_mod, only: vars_defined, snow_o, zfra_o, bils_diss, &
          bils_ec,bils_ech, bils_tke, bils_kinetic, bils_latent, bils_enthalp, &
@@ -292,6 +309,4 @@
          alt_tropo
 
-  
-
     USE ocean_slab_mod, only: nslay, tslab, slab_bils, slab_bilg, tice, &
         seaice, slab_ekman,slab_hdiff, dt_ekman, dt_hdiff
@@ -370,5 +385,5 @@
     CALL set_itau_iophy(itau_w)
 
-    IF(.NOT.vars_defined) THEN
+    IF (.NOT.vars_defined) THEN
        iinitend = 2
     ELSE
@@ -381,10 +396,10 @@
        !$OMP MASTER
        IF (vars_defined) THEN
-          if (prt_level >= 10) then
+          IF (prt_level >= 10) then
              write(lunout,*)"phys_output_write: call xios_update_calendar, itau_w=",itau_w
-          endif
+          ENDIF
 !          CALL xios_update_calendar(itau_w)
           CALL xios_update_calendar(itap)
-       END IF
+       ENDIF
        !$OMP END MASTER
        !$OMP BARRIER
@@ -395,10 +410,10 @@
 
        zx_tmp_fi2d = cell_area
-       if (is_north_pole_phy) then
+       IF (is_north_pole_phy) then
          zx_tmp_fi2d(1) = cell_area(1)/nbp_lon
-       endif
-       if (is_south_pole_phy) then
+       ENDIF
+       IF (is_south_pole_phy) then
          zx_tmp_fi2d(klon) = cell_area(klon)/nbp_lon
-       endif
+       ENDIf
        CALL histwrite_phy(o_aire, zx_tmp_fi2d)
 
@@ -779,14 +794,14 @@
        CALL histwrite_phy(o_uq, uq)
        CALL histwrite_phy(o_vq, vq)
-       IF(iflag_con.GE.3) THEN ! sb
+       IF (iflag_con.GE.3) THEN ! sb
           CALL histwrite_phy(o_cape, cape)
           CALL histwrite_phy(o_pbase, ema_pcb)
           CALL histwrite_phy(o_ptop, ema_pct)
           CALL histwrite_phy(o_fbase, ema_cbmf)
-          if (iflag_con /= 30) then
+          IF (iflag_con /= 30) THEN
              CALL histwrite_phy(o_plcl, plcl)
              CALL histwrite_phy(o_plfc, plfc)
              CALL histwrite_phy(o_wbeff, wbeff)
-          end if
+          ENDIF
 
           CALL histwrite_phy(o_cape_max, cape)
@@ -799,5 +814,5 @@
           CALL histwrite_phy(o_ftime_con, zx_tmp_fi2d)
           IF (vars_defined) THEN
-             IF(iflag_thermals>=1)THEN
+             IF (iflag_thermals>=1)THEN
                 zx_tmp_fi3d=dnwd+dnwd0+upwd+fm_therm(:,1:klev)
              ELSE
@@ -850,5 +865,5 @@
           DO k=1, nlevSTD
              bb2=clevSTD(k) 
-             IF(bb2.EQ."850".OR.bb2.EQ."700".OR. &
+             IF (bb2.EQ."850".OR.bb2.EQ."700".OR. &
                   bb2.EQ."500".OR.bb2.EQ."200".OR. &
                   bb2.EQ."100".OR. &
@@ -871,5 +886,5 @@
 #endif
 #ifdef CPP_XIOS
-  IF(ok_all_xml) THEN
+  IF (ok_all_xml) THEN
 !XIOS  CALL xios_get_field_attr("u850",default_value=missing_val)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -877,5 +892,5 @@
           DO k=1, nlevSTD
              bb2=clevSTD(k) 
-             IF(bb2.EQ."850".OR.bb2.EQ."700".OR. &
+             IF (bb2.EQ."850".OR.bb2.EQ."700".OR. &
                 bb2.EQ."500".OR.bb2.EQ."200".OR. &
                 bb2.EQ."100".OR. &
@@ -994,10 +1009,10 @@
           ELSE
               CALL histwrite_phy(o_tslab, tslab(:,1:nslay))
-          END IF
+          ENDIF
           IF (version_ocean=='sicINT') THEN
               CALL histwrite_phy(o_slab_bilg, slab_bilg)
               CALL histwrite_phy(o_slab_tice, tice)
               CALL histwrite_phy(o_slab_sic, seaice)
-          END IF
+          ENDIF
           IF (slab_hdiff) THEN
             IF (nslay.EQ.1) THEN
@@ -1006,6 +1021,6 @@
             ELSE
                 CALL histwrite_phy(o_slab_hdiff, dt_hdiff(:,1:nslay))
-            END IF
-          END IF
+            ENDIF
+          ENDIF
           IF (slab_ekman.GT.0) THEN
             IF (nslay.EQ.1) THEN
@@ -1014,6 +1029,6 @@
             ELSE
                 CALL histwrite_phy(o_slab_ekman, dt_ekman(:,1:nslay))
-            END IF
-          END IF
+            ENDIF
+          ENDIF
        ENDIF !type_ocean == force/slab
        CALL histwrite_phy(o_weakinv, weak_inversion)
@@ -1094,16 +1109,36 @@
           ENDIF
           IF (flag_aerosol.GT.0.OR.flag_aerosol_strat.GT.0) THEN
-!             DO naero = 1, naero_spc
-!--correction mini bug OB
              DO naero = 1, naero_tot
-                CALL histwrite_phy(o_tausumaero(naero), &
-                     tausum_aero(:,2,naero) )
+                CALL histwrite_phy(o_tausumaero(naero),tausum_aero(:,2,naero))
              END DO
           ENDIF
           IF (flag_aerosol_strat.GT.0) THEN
-             CALL histwrite_phy(o_tausumaero_lw, &
-                  tausum_aero(:,6,id_STRAT_phy) )
-          ENDIF
-       ENDIF
+             CALL histwrite_phy(o_tausumaero_lw,tausum_aero(:,6,id_STRAT_phy))
+          ENDIF
+       ENDIF
+#ifdef CPP_StratAer
+       IF (type_trac=='coag') THEN
+          CALL histwrite_phy(o_sulf_convert, sulf_convert)
+          CALL histwrite_phy(o_sulf_nucl, sulf_nucl)
+          CALL histwrite_phy(o_sulf_cond_evap, sulf_cond_evap)
+          CALL histwrite_phy(o_ocs_convert, ocs_convert)
+          CALL histwrite_phy(o_R2SO4, R2SO4)
+          CALL histwrite_phy(o_OCS_lifetime, OCS_lifetime)
+          CALL histwrite_phy(o_SO2_lifetime, SO2_lifetime)
+          CALL histwrite_phy(o_OCS_backgr_tend, OCS_backgr_tend)
+          CALL histwrite_phy(o_SO2_backgr_tend, SO2_backgr_tend)
+          CALL histwrite_phy(o_sulf_dep_dry, sulf_dep_dry)
+          CALL histwrite_phy(o_sulf_dep_wet, sulf_dep_wet)
+          CALL histwrite_phy(o_surf_PM25_sulf, surf_PM25_sulf)
+          CALL histwrite_phy(o_p_tropopause, p_tropopause)
+          CALL histwrite_phy(o_sfluxaer, sfluxaer)
+          CALL histwrite_phy(o_vsed_aer, vsed_aer)
+          CALL histwrite_phy(o_f_r_wet, f_r_wet)
+          CALL histwrite_phy(o_ext_strat_550, tau_strat_550)
+          CALL histwrite_phy(o_ext_strat_1020, tau_strat_1020)
+          CALL histwrite_phy(o_tau_strat_550, tausum_strat(:,1))
+          CALL histwrite_phy(o_tau_strat_1020, tausum_strat(:,2))
+       ENDIF
+#endif
        IF (ok_ade) THEN
           CALL histwrite_phy(o_topswad, topswad_aero*swradcorr)
@@ -1116,5 +1151,5 @@
           CALL histwrite_phy(o_sollwad0, sollwad0_aero)
           !====MS forcing diagnostics
-          if (new_aod) then
+          IF (new_aod) THEN
              zx_tmp_fi2d(:)=topsw_aero(:,1)*swradcorr(:)
              CALL histwrite_phy(o_swtoaas_nat,zx_tmp_fi2d)
@@ -1135,5 +1170,5 @@
              CALL histwrite_phy(o_swsrfcs_ant,zx_tmp_fi2d)
              !cf
-             if (.not. aerosol_couple) then
+             IF (.not. aerosol_couple) THEN
                 zx_tmp_fi2d(:)=topswcf_aero(:,1)*swradcorr(:)
                 CALL histwrite_phy(o_swtoacf_nat,zx_tmp_fi2d)
@@ -1148,6 +1183,6 @@
                 zx_tmp_fi2d(:)=solswcf_aero(:,3)*swradcorr(:)
                 CALL histwrite_phy(o_swsrfcf_zero,zx_tmp_fi2d)
-             endif
-          endif ! new_aod
+             ENDIF
+          ENDIF ! new_aod
           !====MS forcing diagnostics
        ENDIF
@@ -1261,13 +1296,13 @@
        CALL histwrite_phy(o_alb2, albsol2)
        !FH Sorties pour la couche limite
-       if (iflag_pbl>1) then
+       IF (iflag_pbl>1) THEN
           zx_tmp_fi3d=0.
           IF (vars_defined) THEN
-             do nsrf=1,nbsrf
-                do k=1,klev
+             DO nsrf=1,nbsrf
+                DO k=1,klev
                    zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k) &
                         +pctsrf(:,nsrf)*pbl_tke(:,k,nsrf)
-                enddo
-             enddo
+                ENDDO
+             ENDDO
           ENDIF
           CALL histwrite_phy(o_tke, zx_tmp_fi3d)
@@ -1325,8 +1360,8 @@
        CALL histwrite_phy(o_dqcon2d, zx_tmp_fi2d)
 
-       IF(iflag_thermals.EQ.0) THEN
+       IF (iflag_thermals.EQ.0) THEN
           IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_tnhusc, zx_tmp_fi3d)
-       ELSE IF(iflag_thermals.GE.1.AND.iflag_wake.EQ.1) THEN
+       ELSE IF (iflag_thermals.GE.1.AND.iflag_wake.EQ.1) THEN
           IF (vars_defined) THEN
              zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys + &
@@ -1350,14 +1385,14 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        ! Sorties specifiques a la separation thermiques/non thermiques
-       if (iflag_thermals>=1) then
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lscth(1:klon,1:klev)/pdtphys
+       IF (iflag_thermals>=1) THEN
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lscth(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dtlscth, zx_tmp_fi3d)
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lscst(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lscst(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dtlscst, zx_tmp_fi3d)
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dqlscth, zx_tmp_fi3d)
           CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
           CALL histwrite_phy(o_dqlscth2d, zx_tmp_fi2d)
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dqlscst, zx_tmp_fi3d)
           CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
@@ -1366,13 +1401,13 @@
           CALL histwrite_phy(o_plulst, plul_st)
           IF (vars_defined) THEN
-             do k=1,klev
-                do i=1,klon
-                   if (ptconvth(i,k)) then
+             DO k=1,klev
+                DO i=1,klon
+                   IF (ptconvth(i,k)) THEN
                       zx_tmp_fi3d(i,k)=1.
-                   else
+                   ELSE
                       zx_tmp_fi3d(i,k)=0.
-                   endif
-                enddo
-             enddo
+                   ENDIF
+                ENDDO
+             ENDDO
           ENDIF
           CALL histwrite_phy(o_ptconvth, zx_tmp_fi3d)
@@ -1383,9 +1418,9 @@
           ENDIF
           CALL histwrite_phy(o_lmaxth, zx_tmp_fi2d)
-       endif ! iflag_thermals>=1
+       ENDIF ! iflag_thermals>=1
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dtvdf, zx_tmp_fi3d)
-       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_diss(1:klon,1:klev)/pdtphys
+       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_diss(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dtdis, zx_tmp_fi3d)
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
@@ -1437,40 +1472,40 @@
           CALL histwrite_phy(o_dqthe2d, zx_tmp_fi2d)
        ENDIF !iflag_thermals
-       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_ajsb(1:klon,1:klev)/pdtphys
+       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_ajsb(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dtajs, zx_tmp_fi3d)
-       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
+       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqajs, zx_tmp_fi3d)
        CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqajs2d, zx_tmp_fi2d)
-       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_swr(1:klon,1:klev)/pdtphys
+       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_swr(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dtswr, zx_tmp_fi3d)
-       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_sw0(1:klon,1:klev)/pdtphys
+       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_sw0(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dtsw0, zx_tmp_fi3d)
-       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lwr(1:klon,1:klev)/pdtphys
+       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lwr(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dtlwr, zx_tmp_fi3d)
-       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lw0(1:klon,1:klev)/pdtphys
+       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lw0(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dtlw0, zx_tmp_fi3d)
-       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)/pdtphys
+       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dtec, zx_tmp_fi3d)
-       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
+       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_duvdf, zx_tmp_fi3d)
-       IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
+       IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dvvdf, zx_tmp_fi3d)
        IF (ok_orodr) THEN
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_duoro, zx_tmp_fi3d)
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dvoro, zx_tmp_fi3d)
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_oro(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_oro(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dtoro, zx_tmp_fi3d)
        ENDIF
        IF (ok_orolf) THEN
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dulif, zx_tmp_fi3d)
 
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dvlif, zx_tmp_fi3d)
 
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lif(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_lif(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dtlif, zx_tmp_fi3d)
        ENDIF
@@ -1479,11 +1514,11 @@
           CALL histwrite_phy(o_du_gwd_hines, du_gwd_hines/pdtphys)
           CALL histwrite_phy(o_dv_gwd_hines, dv_gwd_hines/pdtphys)
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_hin(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_hin(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dthin, zx_tmp_fi3d)
           CALL histwrite_phy(o_ustr_gwd_hines, zustr_gwd_hines)
           CALL histwrite_phy(o_vstr_gwd_hines, zvstr_gwd_hines)
-       end IF
-
-       if (.not. ok_hines .and. ok_gwd_rando) then
+       ENDIF
+
+       IF (.not. ok_hines .and. ok_gwd_rando) THEN
           CALL histwrite_phy(o_du_gwd_front, du_gwd_front / pdtphys)
           CALL histwrite_phy(o_dv_gwd_front, dv_gwd_front / pdtphys)
@@ -1492,5 +1527,5 @@
        ENDIF
 
-       IF (ok_gwd_rando) then
+       IF (ok_gwd_rando) THEN
           CALL histwrite_phy(o_du_gwd_rando, du_gwd_rando / pdtphys)
           CALL histwrite_phy(o_dv_gwd_rando, dv_gwd_rando / pdtphys)
@@ -1499,7 +1534,7 @@
           CALL histwrite_phy(o_east_gwstress, east_gwstress )
           CALL histwrite_phy(o_west_gwstress, west_gwstress )
-       end IF
-
-       IF (ok_qch4) then
+       ENDIF
+
+       IF (ok_qch4) THEN
           CALL histwrite_phy(o_dqch4, d_q_ch4 / pdtphys)
        ENDIF
@@ -1527,5 +1562,5 @@
        CALL histwrite_phy(o_rldcs, lwdn0)
 
-       IF(vars_defined) THEN
+       IF (vars_defined) THEN
           zx_tmp_fi3d(1:klon,1:klev)=d_t(1:klon,1:klev)+ &
                d_t_dyn(1:klon,1:klev)
@@ -1533,10 +1568,10 @@
        CALL histwrite_phy(o_tnt, zx_tmp_fi3d)
 
-       IF(vars_defined) THEN
+       IF (vars_defined) THEN
           zx_tmp_fi3d(1:klon,1:klev)=d_t_swr(1:klon,1:klev)/pdtphys + &
                d_t_lwr(1:klon,1:klev)/pdtphys
        ENDIF
        CALL histwrite_phy(o_tntr, zx_tmp_fi3d)
-       IF(vars_defined) THEN
+       IF (vars_defined) THEN
           zx_tmp_fi3d(1:klon,1:klev)= (d_t_lsc(1:klon,1:klev)+ &
                d_t_eva(1:klon,1:klev)+ &
@@ -1544,10 +1579,10 @@
        ENDIF
        CALL histwrite_phy(o_tntscpbl, zx_tmp_fi3d)
-       IF(vars_defined) THEN
+       IF (vars_defined) THEN
           zx_tmp_fi3d(1:klon,1:klev)=d_qx(1:klon,1:klev,ivap)+ &
                d_q_dyn(1:klon,1:klev)
        ENDIF
        CALL histwrite_phy(o_tnhus, zx_tmp_fi3d)
-       IF(vars_defined) THEN
+       IF (vars_defined) THEN
           zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys+ &
                d_q_eva(1:klon,1:klev)/pdtphys
@@ -1555,36 +1590,36 @@
        CALL histwrite_phy(o_tnhusscpbl, zx_tmp_fi3d)
        CALL histwrite_phy(o_evu, coefm(:,:,is_ave))
-       IF(vars_defined) THEN
+       IF (vars_defined) THEN
           zx_tmp_fi3d(1:klon,1:klev)=q_seri(1:klon,1:klev)+ &
                ql_seri(1:klon,1:klev) 
        ENDIF
        CALL histwrite_phy(o_h2o, zx_tmp_fi3d)
-       if (iflag_con >= 3) then
-          IF(vars_defined) THEN
+       IF (iflag_con >= 3) THEN
+          IF (vars_defined) THEN
              zx_tmp_fi3d(1:klon,1:klev)=-1 * (dnwd(1:klon,1:klev)+ &
                   dnwd0(1:klon,1:klev)) 
           ENDIF
           CALL histwrite_phy(o_mcd, zx_tmp_fi3d)
-          IF(vars_defined) THEN
+          IF (vars_defined) THEN
              zx_tmp_fi3d(1:klon,1:klev)=upwd(1:klon,1:klev) + &
                   dnwd(1:klon,1:klev)+ dnwd0(1:klon,1:klev) 
           ENDIF
           CALL histwrite_phy(o_dmc, zx_tmp_fi3d)
-       else if (iflag_con == 2) then
+       ELSE IF (iflag_con == 2) THEN
           CALL histwrite_phy(o_mcd,  pmfd)
           CALL histwrite_phy(o_dmc,  pmfu + pmfd)
-       end if
+       ENDIF
        CALL histwrite_phy(o_ref_liq, ref_liq)
        CALL histwrite_phy(o_ref_ice, ref_ice)
-       if (RCO2_per.NE.RCO2_act.OR.RCH4_per.NE.RCH4_act.OR. &
+       IF (RCO2_per.NE.RCO2_act.OR.RCH4_per.NE.RCH4_act.OR. &
             RN2O_per.NE.RN2O_act.OR.RCFC11_per.NE.RCFC11_act.OR. &
             RCFC12_per.NE.RCFC12_act) THEN
-          IF(vars_defined) zx_tmp_fi2d(:) = swupp(:,klevp1)*swradcorr(:)
+          IF (vars_defined) zx_tmp_fi2d(:) = swupp(:,klevp1)*swradcorr(:)
           CALL histwrite_phy(o_rsut4co2, zx_tmp_fi2d)
-          IF(vars_defined) zx_tmp_fi2d(:) = lwupp(:,klevp1)
+          IF (vars_defined) zx_tmp_fi2d(:) = lwupp(:,klevp1)
           CALL histwrite_phy(o_rlut4co2, zx_tmp_fi2d)
-          IF(vars_defined) zx_tmp_fi2d(:) = swup0p(:,klevp1)*swradcorr(:)
+          IF (vars_defined) zx_tmp_fi2d(:) = swup0p(:,klevp1)*swradcorr(:)
           CALL histwrite_phy(o_rsutcs4co2, zx_tmp_fi2d)
-          IF(vars_defined) zx_tmp_fi2d(:) = lwup0p(:,klevp1)
+          IF (vars_defined) zx_tmp_fi2d(:) = lwup0p(:,klevp1)
           CALL histwrite_phy(o_rlutcs4co2, zx_tmp_fi2d)
           DO k=1, klevp1
@@ -1626,9 +1661,9 @@
           CALL histwrite_phy(o_va,vwriteSTD(:,:,iff-6),iff)
           CALL histwrite_phy(o_wap,wwriteSTD(:,:,iff-6),iff)
-          IF(vars_defined) THEN
+          IF (vars_defined) THEN
              DO k=1, nlevSTD
                 DO i=1, klon
-                   IF(tnondef(i,k,iff-6).NE.missing_val) THEN
-                      IF(freq_outNMC(iff-6).LT.0) THEN
+                   IF (tnondef(i,k,iff-6).NE.missing_val) THEN
+                      IF (freq_outNMC(iff-6).LT.0) THEN
                          freq_moyNMC(iff-6)=(mth_len*un_jour)/freq_calNMC(iff-6)
                       ELSE
@@ -1643,8 +1678,8 @@
           ENDIF
           CALL histwrite_phy(o_psbg,zx_tmp_fi3d_STD,iff)
-          IF(vars_defined) THEN
+          IF (vars_defined) THEN
              DO k=1, nlevSTD
                 DO i=1, klon
-                   IF(O3sumSTD(i,k,iff-6).NE.missing_val) THEN
+                   IF (O3sumSTD(i,k,iff-6).NE.missing_val) THEN
                       zx_tmp_fi3d_STD(i,k) = O3sumSTD(i,k,iff-6) * 1.e+9
                    ELSE
@@ -1655,9 +1690,9 @@
           ENDIF
           CALL histwrite_phy(o_tro3,zx_tmp_fi3d_STD,iff)
-          if (read_climoz == 2) THEN
-             IF(vars_defined) THEN
+          IF (read_climoz == 2) THEN
+             IF (vars_defined) THEN
                 DO k=1, nlevSTD
                    DO i=1, klon
-                      IF(O3daysumSTD(i,k,iff-6).NE.missing_val) THEN
+                      IF (O3daysumSTD(i,k,iff-6).NE.missing_val) THEN
                          zx_tmp_fi3d_STD(i,k) = O3daysumSTD(i,k,iff-6) * 1.e+9
                       ELSE
@@ -1683,5 +1718,5 @@
 #endif
 #ifdef CPP_XIOS
-  IF(ok_all_xml) THEN 
+  IF (ok_all_xml) THEN 
 !      DO iff=7, nfiles
 
@@ -1694,9 +1729,9 @@
           CALL histwrite_phy(o_va,vlevSTD(:,:))
           CALL histwrite_phy(o_wap,wlevSTD(:,:))
-!         IF(vars_defined) THEN
+!         IF (vars_defined) THEN
 !            DO k=1, nlevSTD
 !               DO i=1, klon
-!                  IF(tnondef(i,k,3).NE.missing_val) THEN
-!                     IF(freq_outNMC(iff-6).LT.0) THEN
+!                  IF (tnondef(i,k,3).NE.missing_val) THEN
+!                     IF (freq_outNMC(iff-6).LT.0) THEN
 !                        freq_moyNMC(iff-6)=(mth_len*un_jour)/freq_calNMC(iff-6)
 !                     ELSE
@@ -1711,8 +1746,8 @@
 !         ENDIF
 !         CALL histwrite_phy(o_psbg,zx_tmp_fi3d_STD)
-          IF(vars_defined) THEN
+          IF (vars_defined) THEN
              DO k=1, nlevSTD
                 DO i=1, klon
-                   IF(O3STD(i,k).NE.missing_val) THEN
+                   IF (O3STD(i,k).NE.missing_val) THEN
                       zx_tmp_fi3d_STD(i,k) = O3STD(i,k) * 1.e+9
                    ELSE
@@ -1723,9 +1758,9 @@
           ENDIF
           CALL histwrite_phy(o_tro3,zx_tmp_fi3d_STD)
-          if (read_climoz == 2) THEN
-             IF(vars_defined) THEN
+          IF (read_climoz == 2) THEN
+             IF (vars_defined) THEN
                 DO k=1, nlevSTD
                    DO i=1, klon
-                      IF(O3daySTD(i,k).NE.missing_val) THEN
+                      IF (O3daySTD(i,k).NE.missing_val) THEN
                          zx_tmp_fi3d_STD(i,k) = O3daySTD(i,k) * 1.e+9
                       ELSE
@@ -1736,5 +1771,5 @@
              ENDIF
              CALL histwrite_phy(o_tro3_daylight,zx_tmp_fi3d_STD)
-          endif
+          ENDIF
           CALL histwrite_phy(o_uxv,uvSTD(:,:))
           CALL histwrite_phy(o_vxq,vqSTD(:,:))
@@ -1751,11 +1786,7 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
         IF (nqtot.GE.nqo+1) THEN
-            DO iq=nqo+1,nqtot
-              IF (type_trac == 'lmdz' .OR. type_trac == 'repr') THEN
-
-!jyg<
-!!             CALL histwrite_phy(o_trac(iq-nqo), qx(:,:,iq))
+          DO iq=nqo+1,nqtot
+            IF (type_trac == 'lmdz' .OR. type_trac == 'repr' .OR. type_trac == 'coag') THEN
              CALL histwrite_phy(o_trac(iq-nqo), tr_seri(:,:,iq-nqo))
-!>jyg
              CALL histwrite_phy(o_dtr_vdf(iq-nqo),d_tr_cl(:,:,iq-nqo))
              CALL histwrite_phy(o_dtr_the(iq-nqo),d_tr_th(:,:,iq-nqo))
@@ -1772,18 +1803,15 @@
              CALL histwrite_phy(o_dtr_uscav(iq-nqo),d_tr_uscav(:,:,iq-nqo))
              zx_tmp_fi2d=0.
-             IF(vars_defined) THEN
+             IF (vars_defined) THEN
                 DO k=1,klev
-!jyg<
-!!                   zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*qx(:,k,iq)
                    zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*tr_seri(:,k,iq-nqo)
-!>jyg
                 ENDDO
              ENDIF
              CALL histwrite_phy(o_trac_cum(iq-nqo), zx_tmp_fi2d)
-             endif
-          ENDDO
-       ENDIF
-
-       IF(.NOT.vars_defined) THEN
+            ENDIF
+          ENDDO
+       ENDIF
+
+       IF (.NOT.vars_defined) THEN
           !$OMP MASTER
 #ifndef CPP_IOIPSL_NO_OUTPUT 
@@ -1801,14 +1829,12 @@
           CALL wxios_closedef()
 #endif
-
           !$OMP END MASTER
           !$OMP BARRIER
           vars_defined = .TRUE.
-
-       END IF
-
-    END DO
-
-    IF(vars_defined) THEN
+       ENDIF
+
+    ENDDO
+
+    IF (vars_defined) THEN
        ! On synchronise les fichiers pour IOIPSL
 #ifndef CPP_IOIPSL_NO_OUTPUT 
@@ -1823,5 +1849,4 @@
     ENDIF
 
-
   END SUBROUTINE phys_output_write
 
