Index: LMDZ5/trunk/libf/phylmd/Dust/phys_output_write_spl_mod.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/Dust/phys_output_write_spl_mod.F90	(revision 2753)
+++ LMDZ5/trunk/libf/phylmd/Dust/phys_output_write_spl_mod.F90	(revision 2754)
@@ -6,8 +6,7 @@
 !JE20150620<<
 !JE20150620>>
-
 !JE20150620<<
 
-    USE time_phylmdz_mod, only: day_step_phy, start_time, itau_phy
+  USE time_phylmdz_mod, ONLY: day_step_phy, start_time, itau_phy
 
   USE phytracr_spl_mod, ONLY : ok_chimeredust, id_prec, id_fine, id_coss, &
@@ -93,8 +92,8 @@
     ! defined and initialised in phys_output_mod.F90
 
-    USE dimphy, only: klon, klev, klevp1
+    USE dimphy, ONLY: klon, klev, klevp1
     USE ocean_slab_mod, ONLY: nslay
-    USE control_mod, only: day_step, iphysiq
-    USE phys_output_ctrlout_mod, only: o_phis, o_aire, is_ter, is_lic, is_oce, &
+    USE control_mod, ONLY: day_step, iphysiq
+    USE phys_output_ctrlout_mod, ONLY: o_phis, o_aire, is_ter, is_lic, is_oce, &
          is_ave, is_sic, o_contfracATM, o_contfracOR, &
          o_aireTER, o_flat, o_slp, o_tsol, &
@@ -288,5 +287,5 @@
 !JE20150620>>
 
-    USE phys_state_var_mod, only: pctsrf, paire_ter, rain_fall, snow_fall, &
+    USE phys_state_var_mod, ONLY: pctsrf, paire_ter, rain_fall, snow_fall, &
          qsol, z0m, z0h, fevap, agesno, &
          nday_rain, rain_con, snow_con, &
@@ -315,5 +314,5 @@
          vphiSTD, wTSTD, u2STD, v2STD, T2STD, missing_val_nf90
 
-    USE phys_local_var_mod, only: zxfluxlat, slp, zxtsol, zt2m, &
+    USE phys_local_var_mod, ONLY: zxfluxlat, slp, zxtsol, zt2m, &
          t2m_min_mon, t2m_max_mon, evap, &
          zu10m, zv10m, zq2m, zustar, zxqsurf, &
@@ -370,29 +369,27 @@
          d_q_ch4, pmfd, pmfu, ref_liq, ref_ice, rhwriteSTD
 
-    USE phys_output_var_mod, only: vars_defined, snow_o, zfra_o, bils_diss, &
+    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, &
          itau_con, nfiles, clef_files, nid_files, zvstr_gwd_rando
-    USE ocean_slab_mod, only: tslab, slab_bils, slab_bilg, tice, seaice
-    USE pbl_surface_mod, only: snow
-    USE indice_sol_mod, only: nbsrf
-    USE infotrac, only: nqtot, nqo, nbtr, type_trac
-    USE geometry_mod, only: cell_area
-    USE surface_data, only: type_ocean, version_ocean, ok_veget, ok_snow
-!    USE aero_mod, only: naero_spc
-    USE aero_mod, only: naero_tot, id_STRAT_phy
-    USE ioipsl, only: histend, histsync
-    USE iophy, only: set_itau_iophy, histwrite_phy
-    USE netcdf, only: nf90_fill_real
+    USE ocean_slab_mod, ONLY: tslab, slab_bils, slab_bilg, tice, seaice
+    USE pbl_surface_mod, ONLY: snow
+    USE indice_sol_mod, ONLY: nbsrf
+    USE infotrac, ONLY: nqtot, nqo, nbtr, type_trac
+    USE geometry_mod, ONLY: cell_area
+    USE surface_data, ONLY: type_ocean, version_ocean, ok_veget, ok_snow
+!    USE aero_mod, ONLY: naero_spc
+    USE aero_mod, ONLY: naero_tot, id_STRAT_phy
+    USE ioipsl, ONLY: histend, histsync
+    USE iophy, ONLY: set_itau_iophy, histwrite_phy
+    USE netcdf, ONLY: nf90_fill_real
 
 #ifdef CPP_XIOS
     ! ug Pour les sorties XIOS
     USE xios, ONLY: xios_update_calendar
-    USE wxios, only: wxios_closedef, missing_val
+    USE wxios, ONLY: wxios_closedef, missing_val
 #endif
-    USE phys_cal_mod, only : mth_len
-
+    USE phys_cal_mod, ONLY : mth_len
 
     IMPLICIT NONE
-
 
 !   INCLUDE "temps.h"
@@ -446,5 +443,5 @@
     CALL set_itau_iophy(itau_w)
 
-    IF(.NOT.vars_defined) THEN
+    IF (.NOT.vars_defined) THEN
        iinitend = 2
     ELSE
@@ -457,10 +454,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
@@ -752,14 +749,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)
@@ -772,5 +769,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
@@ -821,5 +818,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. &
@@ -841,6 +838,7 @@
 #endif
 #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)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -848,5 +846,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. &
@@ -941,10 +939,10 @@
           ELSE
               CALL histwrite_phy(o_tslab, tslab)
-          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
        ENDIF !type_ocean == force/slab
        CALL histwrite_phy(o_weakinv, weak_inversion)
@@ -1030,5 +1028,5 @@
                 CALL histwrite_phy(o_tausumaero(naero), &
                      tausum_aero(:,2,naero) )
-             END DO
+             ENDDO
           ENDIF
           IF (flag_aerosol_strat>=1) THEN
@@ -1047,5 +1045,5 @@
           CALL histwrite_phy(o_sollwad0, sollwad0_aero)
           !====MS forcing diagnostics
-          if (new_aod) then
+          IF (new_aod) THEN
              CALL histwrite_phy(o_swtoaas_nat, topsw_aero(:,1))
              CALL histwrite_phy(o_swsrfas_nat, solsw_aero(:,1))
@@ -1058,5 +1056,5 @@
              CALL histwrite_phy(o_swsrfcs_ant, solsw0_aero(:,2))
              !cf
-             if (.not. aerosol_couple) then
+             IF (.not. aerosol_couple) THEN
                 CALL histwrite_phy(o_swtoacf_nat, topswcf_aero(:,1))
                 CALL histwrite_phy(o_swsrfcf_nat, solswcf_aero(:,1))
@@ -1065,6 +1063,6 @@
                 CALL histwrite_phy(o_swtoacf_zero,topswcf_aero(:,3))
                 CALL histwrite_phy(o_swsrfcf_zero,solswcf_aero(:,3))
-             endif
-          endif ! new_aod
+             ENDIF
+          ENDIF ! new_aod
           !====MS forcing diagnostics
        ENDIF
@@ -1086,5 +1084,5 @@
        ENDIF
        ! Champs 3D:
-       IF (ok_ade .OR. ok_aie) then
+       IF (ok_ade .OR. ok_aie) THEN
           CALL histwrite_phy(o_ec550aer, ec550aer)
        ENDIF
@@ -1171,9 +1169,9 @@
        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)
@@ -1200,5 +1198,5 @@
        ENDIF
        CALL histwrite_phy(o_dtcon, zx_tmp_fi3d)
-       if(iflag_thermals.eq.0)then
+       IF (iflag_thermals.eq.0)THEN
           IF (vars_defined) THEN
              zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys + &
@@ -1206,5 +1204,5 @@
           ENDIF
           CALL histwrite_phy(o_tntc, zx_tmp_fi3d)
-       else if(iflag_thermals.ge.1.and.iflag_wake.EQ.1)then
+       ELSEIF (iflag_thermals.ge.1.and.iflag_wake.EQ.1)THEN
           IF (vars_defined) THEN
              zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys + &
@@ -1213,5 +1211,5 @@
           ENDIF
           CALL histwrite_phy(o_tntc, zx_tmp_fi3d)
-       endif
+       ENDIF
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_con(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_ducon, zx_tmp_fi3d)
@@ -1221,8 +1219,8 @@
        CALL histwrite_phy(o_dqcon, zx_tmp_fi3d)
 
-       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
+       ELSEIF (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 + &
@@ -1244,23 +1242,23 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        ! 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)
-          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 histwrite_phy(o_plulth, plul_th)
           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
+                   ENDIF
                 enddo
              enddo
@@ -1268,14 +1266,14 @@
           CALL histwrite_phy(o_ptconvth, zx_tmp_fi3d)
           IF (vars_defined) THEN
-             do i=1,klon
+             DO i=1,klon
                 zx_tmp_fi2d(1:klon)=lmax_th(:)
              enddo
           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
@@ -1321,57 +1319,57 @@
           CALL histwrite_phy(o_dqthe, zx_tmp_fi3d)
        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)
-       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
 
 !      IF (ok_hines) THEN
-!         IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_hin(1:klon,1:klev)/pdtphys
+!         IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_hin(1:klon,1:klev)/pdtphys
 !         CALL histwrite_phy(o_duhin, zx_tmp_fi3d)
-!         IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_hin(1:klon,1:klev)/pdtphys
+!         IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_hin(1:klon,1:klev)/pdtphys
 !         CALL histwrite_phy(o_dvhin, zx_tmp_fi3d)
-!         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)
 !      ENDIF
 
-!      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)
+!      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)
 !         CALL histwrite_phy(o_vstr_gwd_rando, zvstr_gwd_rando)
-!      end IF
-
-       IF (ok_qch4) then
+!      ENDIF
+
+       IF (ok_qch4) THEN
           CALL histwrite_phy(o_dqch4, d_q_ch4 / pdtphys)
        ENDIF
@@ -1385,15 +1383,15 @@
        CALL histwrite_phy(o_rlucs, lwup0)
        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)
        ENDIF
        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)+ &
@@ -1401,10 +1399,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
@@ -1412,36 +1410,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
+       ELSEIF (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(1 : klon) = swupp ( 1 : klon, klevp1 )
+          IF (vars_defined) zx_tmp_fi2d(1 : klon) = swupp ( 1 : klon, klevp1 )
           CALL histwrite_phy(o_rsut4co2, zx_tmp_fi2d)
-          IF(vars_defined) zx_tmp_fi2d(1 : klon) = lwupp ( 1 : klon, klevp1 )
+          IF (vars_defined) zx_tmp_fi2d(1 : klon) = lwupp ( 1 : klon, klevp1 )
           CALL histwrite_phy(o_rlut4co2, zx_tmp_fi2d)
-          IF(vars_defined) zx_tmp_fi2d(1 : klon) = swup0p ( 1 : klon, klevp1 )
+          IF (vars_defined) zx_tmp_fi2d(1 : klon) = swup0p ( 1 : klon, klevp1 )
           CALL histwrite_phy(o_rsutcs4co2, zx_tmp_fi2d)
-          IF(vars_defined) zx_tmp_fi2d(1 : klon) = lwup0p ( 1 : klon, klevp1 )
+          IF (vars_defined) zx_tmp_fi2d(1 : klon) = lwup0p ( 1 : klon, klevp1 )
           CALL histwrite_phy(o_rlutcs4co2, zx_tmp_fi2d)
           CALL histwrite_phy(o_rsu4co2, swupp)
@@ -1461,5 +1459,5 @@
        ! Champs interpolles sur des niveaux de pression
        missing_val=missing_val_nf90
-       DO iff=7, nfiles
+       DO iff=7, nfiles-1 !--here we deal with files 7,8 and 9
 
           CALL histwrite_phy(o_tnondef,tnondef(:,:,iff-6),iff)
@@ -1471,9 +1469,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
@@ -1488,8 +1486,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
@@ -1500,9 +1498,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
@@ -1513,5 +1511,5 @@
              ENDIF
              CALL histwrite_phy(o_tro3_daylight,zx_tmp_fi3d_STD,iff)
-          endif
+          ENDIF
           CALL histwrite_phy(o_uxv,uvsumSTD(:,:,iff-6),iff)
           CALL histwrite_phy(o_vxq,vqsumSTD(:,:,iff-6),iff)
@@ -1528,5 +1526,5 @@
 #endif
 #ifdef CPP_XIOS
-  IF(ok_all_xml) THEN 
+  IF (ok_all_xml) THEN 
 !      DO iff=7, nfiles
 
@@ -1539,9 +1537,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
@@ -1556,8 +1554,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
@@ -1568,9 +1566,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
@@ -1581,5 +1579,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(:,:))
@@ -1599,8 +1597,5 @@
               IF (type_trac == 'lmdz' .OR. type_trac == 'repr') THEN
 
-!jyg<
-!!             CALL histwrite_phy(o_trac(iq-nqo), qx(:,:,iq))
              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))
@@ -1613,5 +1608,5 @@
              CALL histwrite_phy(o_dtr_ls(iq-nqo),d_tr_ls(:,:,iq-nqo))
 !            CALL histwrite_phy(o_dtr_dyn(iq-nqo),d_tr_dyn(:,:,iq-nqo))
-         !!  CALL histwrite_phy(o_dtr_cl(iq-nqo),d_tr_cl(:,:,iq-nqo))
+!            CALL histwrite_phy(o_dtr_cl(iq-nqo),d_tr_cl(:,:,iq-nqo))
              CALL histwrite_phy(o_dtr_trsp(iq-nqo),d_tr_trsp(:,:,iq-nqo))
              CALL histwrite_phy(o_dtr_sscav(iq-nqo),d_tr_sscav(:,:,iq-nqo))
@@ -1619,18 +1614,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 
@@ -1653,9 +1645,9 @@
           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 
@@ -1665,5 +1657,5 @@
              CALL histsync(nid_files(iff))
           ENDIF
-       END DO
+       ENDDO
        !$OMP END MASTER
 #endif
