Index: /LMDZ6/trunk/libf/phylmd/physiq_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 3775)
+++ /LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 3776)
@@ -16,31 +16,109 @@
        d_u, d_v, d_t, d_qx, d_ps)
 
+! For clarity, the "USE" section is now arranged in alphabetical order,
+! with a separate section for CPP keys
+! PLEASE try to follow this rule 
+
+    USE ACAMA_GWD_rando_m, only: ACAMA_GWD_rando
+    USE aero_mod
+    USE add_phys_tend_mod, only : add_pbl_tend, add_phys_tend, diag_phys_tend, prt_enerbil, &
+  &      fl_ebil, fl_cor_ebil
     USE assert_m, only: assert
+    USE change_srf_frac_mod
+    USE conf_phys_m, only: conf_phys
+    USE carbon_cycle_mod, ONLY : infocfields_init, RCO2_glo, carbon_cycle_rad
+    USE CFMIP_point_locations   ! IM stations CFMIP
+    USE cmp_seri_mod
+    USE dimphy
+    USE etat0_limit_unstruct_mod
+    USE FLOTT_GWD_rando_m, only: FLOTT_GWD_rando
+    USE fonte_neige_mod, ONLY  : fonte_neige_get_vars
+    USE geometry_mod, ONLY: cell_area, latitude_deg, longitude_deg
     USE ioipsl, only: histbeg, histvert, histdef, histend, histsync, &
          histwrite, ju2ymds, ymds2ju, getin
-    USE geometry_mod, ONLY: cell_area, latitude_deg, longitude_deg
+    USE ioipsl_getin_p_mod, ONLY : getin_p
+    USE indice_sol_mod
+    USE infotrac_phy, ONLY: nqtot, nbtr, nqo, type_trac
+    USE iophy
+    USE limit_read_mod, ONLY : init_limit_read
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev, klon_glo, grid1dTo2d_glo, grid_type, unstructured
+    USE mod_phys_lmdz_mpi_data, only: is_mpi_root
+    USE mod_phys_lmdz_para
+    USE netcdf95, only: nf95_close
+    USE netcdf, only: nf90_fill_real     ! IM for NMC files
+    USE open_climoz_m, only: open_climoz ! ozone climatology from a file
+    USE ozonecm_m, only: ozonecm ! ozone of J.-F. Royer
+    USE pbl_surface_mod, ONLY : pbl_surface
+    USE phyaqua_mod, only: zenang_an
+    USE phystokenc_mod, ONLY: offline, phystokenc
     USE phys_cal_mod, only: year_len, mth_len, days_elapsed, jh_1jan, &
          year_cur, mth_cur,jD_cur, jH_cur, jD_ref, day_cur, hour
+!!  USE phys_local_var_mod, ONLY : a long list of variables
+!!              ==> see below, after "CPP Keys" section
+    USE phys_state_var_mod ! Variables sauvegardees de la physique
+    USE phys_output_mod
+    USE phys_output_ctrlout_mod
+    USE print_control_mod, ONLY: mydebug=>debug , lunout, prt_level
+    USE readaerosol_mod, ONLY : init_aero_fromfile
+    USE readaerosolstrato_m, ONLY : init_readaerosolstrato
+    USE radlwsw_m, only: radlwsw
+    USE regr_horiz_time_climoz_m, ONLY: regr_horiz_time_climoz
+    USE regr_pr_time_av_m, only: regr_pr_time_av
+    USE surface_data,     ONLY : type_ocean, ok_veget, ok_snow
+    USE time_phylmdz_mod, only: annee_ref, current_time, day_ini, day_ref, &
+          day_step_phy, itau_phy, pdtphys, raz_date, start_time, update_time
+    USE tracinca_mod, ONLY: config_inca
+    USE tropopause_m,     ONLY: dyn_tropopause
+    USE vampir
+    USE VERTICAL_LAYERS_MOD, ONLY: aps,bps, ap, bp
     USE write_field_phy
-    USE dimphy
-    USE infotrac_phy, ONLY: nqtot, nbtr, nqo, type_trac
-    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev, klon_glo, grid1dTo2d_glo, grid_type, unstructured
-    USE mod_phys_lmdz_para
-    USE iophy
-    USE print_control_mod, ONLY: mydebug=>debug , lunout, prt_level
-    USE phystokenc_mod, ONLY: offline, phystokenc
-    USE time_phylmdz_mod, only: raz_date, day_step_phy, update_time,current_time
-    USE vampir
-    USE pbl_surface_mod, ONLY : pbl_surface
-    USE change_srf_frac_mod
-    USE surface_data,     ONLY : type_ocean, ok_veget, ok_snow
-    USE tropopause_m,     ONLY: dyn_tropopause
+
+    !USE cmp_seri_mod
+!    USE add_phys_tend_mod, only : add_pbl_tend, add_phys_tend, diag_phys_tend, prt_enerbil, &
+!  &      fl_ebil, fl_cor_ebil
+
+!!!!!!!!!!!!!!!!!! "USE" section for CPP keys !!!!!!!!!!!!!!!!!!!!!!!!
+!
+!
 #ifdef CPP_Dust
-    USE phytracr_spl_mod, ONLY: phytracr_spl
+    USE phytracr_spl_mod, ONLY: phytracr_spl, phytracr_spl_out_init
+    USE phys_output_write_spl_mod
+#else
+    USE phytrac_mod, ONLY : phytrac_init, phytrac
+    USE phys_output_write_mod
 #endif
+
+
+#ifdef REPROBUS
+    USE CHEM_REP, ONLY : Init_chem_rep_xjour, &
+         d_q_rep,d_ql_rep,d_qi_rep,ptrop,ttrop, &
+         ztrop, gravit,itroprep, Z1,Z2,fac,B
+#endif
+
+
+#ifdef CPP_RRTM
+    USE YOERAD, ONLY : NRADLP
+    USE YOESW, ONLY : RSUN
+#endif
+
+
 #ifdef CPP_StratAer
     USE strataer_mod, ONLY: strataer_init
 #endif
-    USE phys_local_var_mod, ONLY: phys_local_var_init, phys_local_var_end, &
+
+
+#ifdef CPP_XIOS
+    USE xios, ONLY: xios_update_calendar, xios_context_finalize, &
+            xios_get_field_attr, xios_field_is_active
+    USE wxios, ONLY: missing_val, missing_val_omp
+#endif
+#ifndef CPP_XIOS
+    USE paramLMDZ_phy_mod
+#endif
+!
+!
+!!!!!!!!!!!!!!!!!!  END "USE" for CPP keys !!!!!!!!!!!!!!!!!!!!!!
+
+USE phys_local_var_mod, ONLY: phys_local_var_init, phys_local_var_end, &
        ! [Variables internes non sauvegardees de la physique]
        ! Variables locales pour effectuer les appels en serie
@@ -216,69 +294,5 @@
        zxsnow,snowhgt,qsnow,to_ice,sissnow,runoff,albsol3_lic
        !
-    USE phys_state_var_mod ! Variables sauvegardees de la physique
-#ifdef CPP_Dust
-    USE phys_output_write_spl_mod
-#else
-    USE phys_output_var_mod ! Variables pour les ecritures des sorties
-#endif
-
-    USE phys_output_write_mod
-    USE fonte_neige_mod, ONLY  : fonte_neige_get_vars
-    USE phys_output_mod
-    USE phys_output_ctrlout_mod
-    USE open_climoz_m, only: open_climoz ! ozone climatology from a file
-    USE regr_pr_time_av_m, only: regr_pr_time_av
-    USE netcdf95, only: nf95_close
-    !IM for NMC files
-    USE netcdf, only: nf90_fill_real
-    USE mod_phys_lmdz_mpi_data, only: is_mpi_root
-    USE aero_mod
-    USE ozonecm_m, only: ozonecm ! ozone of J.-F. Royer
-    USE conf_phys_m, only: conf_phys
-    USE radlwsw_m, only: radlwsw
-    USE phyaqua_mod, only: zenang_an
-    USE time_phylmdz_mod, only: day_step_phy, annee_ref, day_ref, itau_phy, &
-         start_time, pdtphys, day_ini
-    USE tracinca_mod, ONLY: config_inca
-#ifdef CPP_XIOS
-    USE wxios, ONLY: missing_val, missing_val_omp
-    USE xios, ONLY: xios_get_field_attr, xios_field_is_active
-#endif
-#ifdef REPROBUS
-    USE CHEM_REP, ONLY : Init_chem_rep_xjour, &
-         d_q_rep,d_ql_rep,d_qi_rep,ptrop,ttrop, &
-         ztrop, gravit,itroprep, Z1,Z2,fac,B
-#endif
-    USE indice_sol_mod
-    USE phytrac_mod, ONLY : phytrac_init, phytrac
-    USE carbon_cycle_mod, ONLY : infocfields_init, RCO2_glo, carbon_cycle_rad
-
-#ifdef CPP_RRTM
-    USE YOERAD, ONLY : NRADLP
-    USE YOESW, ONLY : RSUN
-#endif
-    USE ioipsl_getin_p_mod, ONLY : getin_p
-
-#ifndef CPP_XIOS
-    USE paramLMDZ_phy_mod
-#endif
-
-    USE cmp_seri_mod
-    USE add_phys_tend_mod, only : add_pbl_tend, add_phys_tend, diag_phys_tend, prt_enerbil, &
-  &      fl_ebil, fl_cor_ebil
-
-    !IM stations CFMIP
-    USE CFMIP_point_locations
-    USE FLOTT_GWD_rando_m, only: FLOTT_GWD_rando
-    USE ACAMA_GWD_rando_m, only: ACAMA_GWD_rando
-    USE VERTICAL_LAYERS_MOD, ONLY: aps,bps, ap, bp
-    USE etat0_limit_unstruct_mod
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_update_calendar, xios_context_finalize
-#endif
-    USE limit_read_mod, ONLY : init_limit_read
-    USE regr_horiz_time_climoz_m, ONLY: regr_horiz_time_climoz
-    USE readaerosol_mod, ONLY : init_aero_fromfile
-    USE readaerosolstrato_m, ONLY : init_readaerosolstrato
+
 
     IMPLICIT NONE
@@ -1347,4 +1361,10 @@
        iflag_phytrac = 1 ! by default we do want to call phytrac
        CALL getin_p('iflag_phytrac',iflag_phytrac)
+#ifdef CPP_Dust
+       IF (iflag_phytrac.EQ.0) THEN 
+         WRITE(lunout,*) 'In order to run with SPLA, iflag_phytrac will be forced to 1'
+         iflag_phytrac = 1
+       ENDIF
+#endif	
        nvm_lmdz = 13
        CALL getin_p('NVM',nvm_lmdz)
@@ -1681,9 +1701,21 @@
 
        CALL iniradia(klon,klev,paprs(1,1:klev+1))
-       ! Initialisation des champs dans phytrac qui sont utilisés par phys_output_write
+
+       ! Initialisation des champs dans phytrac* qui sont utilisés par phys_output_write*
+#ifdef CPP_Dust
+       ! Quand on utilise SPLA, on force iflag_phytrac=1
+       CALL phytracr_spl_out_init()
+       CALL phys_output_write_spl(itap, pdtphys, paprs, pphis,                  &
+                                pplay, lmax_th, aerosol_couple,                 &
+                                ok_ade, ok_aie, ivap, ok_sync,                  &
+                                ptconv, read_climoz, clevSTD,                   &
+                                ptconvth, d_t, qx, d_qx, d_tr_dyn, zmasse,      &
+                                flag_aerosol, flag_aerosol_strat, ok_cdnc)
+#else
+       ! phys_output_write écrit des variables traceurs seulement si iflag_phytrac == 1 
+       ! donc seulement dans ce cas on doit appeler phytrac_init()
        IF (iflag_phytrac == 1 ) THEN
           CALL phytrac_init()
-        ENDIF
-
+       ENDIF
        CALL phys_output_write(itap, pdtphys, paprs, pphis,                    &
                               pplay, lmax_th, aerosol_couple,                 &
@@ -1692,4 +1724,6 @@
                               ptconvth, d_u, d_t, qx, d_qx, zmasse,           &
                               flag_aerosol, flag_aerosol_strat, ok_cdnc)
+#endif
+
 
 #ifdef CPP_XIOS
@@ -4775,8 +4809,7 @@
     ENDIF
 
-    IF (iflag_phytrac == 1 ) THEN
-
 #ifdef CPP_Dust
-      CALL       phytracr_spl ( debut,lafin , jD_cur,jH_cur,iflag_con,       &  ! I
+    !  Avec SPLA, iflag_phytrac est forcé =1 
+    CALL       phytracr_spl ( debut,lafin , jD_cur,jH_cur,iflag_con,       &  ! I
                       pdtphys,ftsol,                                   &  ! I
                       t,q_seri,paprs,pplay,RHcl,                  &  ! I
@@ -4794,6 +4827,6 @@
 
 #else
-
-    CALL phytrac ( &
+    IF (iflag_phytrac == 1 ) THEN
+      CALL phytrac ( &
          itap,     days_elapsed+1,    jH_cur,   debut, &
          lafin,    phys_tstep,     u, v,     t, &
@@ -4832,7 +4865,8 @@
 
 #endif
+    ENDIF    ! (iflag_phytrac=1)
 
 #endif
-    ENDIF    ! (iflag_phytrac=1)
+    !ENDIF    ! (iflag_phytrac=1)
 
     IF (offline) THEN
@@ -5134,5 +5168,5 @@
   CALL phys_output_write_spl(itap, pdtphys, paprs, pphis,  &
        pplay, lmax_th, aerosol_couple,                 &
-       ok_ade, ok_aie, ivap, ok_sync,         &
+       ok_ade, ok_aie, ivap, ok_sync,                  &
        ptconv, read_climoz, clevSTD,                   &
        ptconvth, d_t, qx, d_qx, d_tr_dyn, zmasse,      &
@@ -5153,5 +5187,5 @@
 #endif
 
-! On remet des variables a .false. apres un premier appel
+! Pour XIOS : On remet des variables a .false. apres un premier appel
     IF (debut) THEN
 #ifdef CPP_XIOS
