Index: LMDZ6/trunk/libf/phylmd/cosp/cosp_output_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/cosp_output_mod.F90	(revision 3246)
+++ LMDZ6/trunk/libf/phylmd/cosp/cosp_output_mod.F90	(revision 3247)
@@ -255,8 +255,9 @@
   real                      :: zjulian,zjulian_start
   real,dimension(Ncolumns)  :: column_ax
-  real,dimension(2,SR_BINS) :: sratio_bounds
-  real,dimension(SR_BINS)   ::  sratio_ax
   real,dimension(DBZE_BINS) ::  dbze_ax
   CHARACTER(LEN=20), DIMENSION(3)  :: chfreq = (/ '1day', '1d  ', '3h  ' /)            
+  real,parameter,dimension(SR_BINS) :: sratio_ax = (/0.005, &
+                                                  0.605,2.09,4.,6., & 
+                                          8.5,12.5,17.5,22.5,27.5,35.,45.,55.,70.,50040./)
 
 !!! Variables d'entree
@@ -283,16 +284,4 @@
     enddo
  
-
-    sratio_bounds(2,:)=stlidar%srbval(:) ! srbval contains the upper
-!                                         limits from lmd_ipsl_stats.f90
-    sratio_bounds(1,2:SR_BINS) = stlidar%srbval(1:SR_BINS-1)
-    sratio_bounds(1,1)         = 0.0
-    sratio_bounds(2,SR_BINS)   = 1.e5 ! This matches with Chepfer et al., JGR,
-!                                    ! 2009. However, it is not consistent 
-                                     ! with the upper limit in
-                                     ! lmd_ipsl_stats.f90, which is
-                                     ! LIDAR_UNDEF-1=998.999
-     sratio_ax(:) = (sratio_bounds(1,:)+sratio_bounds(2,:))/2.0 
-
     cosp_outfilenames(1) = 'histmthCOSP'
     cosp_outfilenames(2) = 'histdayCOSP'
Index: LMDZ6/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 3246)
+++ LMDZ6/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 3247)
@@ -118,81 +118,89 @@
  
 !   print*,'Appel histwrite2d_cosp'
-   CALL histwrite2d_cosp(o_cllcalipso,stlidar%cldlayer(:,1))
-   CALL histwrite2d_cosp(o_clhcalipso,stlidar%cldlayer(:,3))
-   CALL histwrite2d_cosp(o_clmcalipso,stlidar%cldlayer(:,2)) 
-   CALL histwrite2d_cosp(o_cltcalipso,stlidar%cldlayer(:,4))
-   CALL histwrite3d_cosp(o_clcalipso,stlidar%lidarcld,nvert)
-   CALL histwrite3d_cosp(o_clcalipsotmp,stlidar%lidarcldtmp(:,:,1),nverttemp)
-
-   CALL histwrite2d_cosp(o_cllcalipsoice,stlidar%cldlayerphase(:,1,1))
-   CALL histwrite2d_cosp(o_clhcalipsoice,stlidar%cldlayerphase(:,3,1))
-   CALL histwrite2d_cosp(o_clmcalipsoice,stlidar%cldlayerphase(:,2,1))
-   CALL histwrite2d_cosp(o_cltcalipsoice,stlidar%cldlayerphase(:,4,1))
-   CALL histwrite3d_cosp(o_clcalipsoice,stlidar%lidarcldphase(:,:,1),nvert)
-   CALL histwrite3d_cosp(o_clcalipsotmpice,stlidar%lidarcldtmp(:,:,2),nverttemp)
-
-   CALL histwrite2d_cosp(o_cllcalipsoliq,stlidar%cldlayerphase(:,1,2))
-   CALL histwrite2d_cosp(o_clhcalipsoliq,stlidar%cldlayerphase(:,3,2))
-   CALL histwrite2d_cosp(o_clmcalipsoliq,stlidar%cldlayerphase(:,2,2))
-   CALL histwrite2d_cosp(o_cltcalipsoliq,stlidar%cldlayerphase(:,4,2))
-   CALL histwrite3d_cosp(o_clcalipsoliq,stlidar%lidarcldphase(:,:,2),nvert)
-   CALL histwrite3d_cosp(o_clcalipsotmpliq,stlidar%lidarcldtmp(:,:,3),nverttemp)
-
-   CALL histwrite2d_cosp(o_cllcalipsoun,stlidar%cldlayerphase(:,1,3))
-   CALL histwrite2d_cosp(o_clhcalipsoun,stlidar%cldlayerphase(:,3,3))
-   CALL histwrite2d_cosp(o_clmcalipsoun,stlidar%cldlayerphase(:,2,3))
-   CALL histwrite2d_cosp(o_cltcalipsoun,stlidar%cldlayerphase(:,4,3))
-   CALL histwrite3d_cosp(o_clcalipsoun,stlidar%lidarcldphase(:,:,3),nvert)
-   CALL histwrite3d_cosp(o_clcalipsotmpun,stlidar%lidarcldtmp(:,:,4),nverttemp)
-
-   CALL histwrite2d_cosp(o_clopaquecalipso,stlidar%cldtype(:,1))               !OPAQ
-   CALL histwrite2d_cosp(o_clthincalipso,stlidar%cldtype(:,2))                 !OPAQ
-   CALL histwrite2d_cosp(o_clzopaquecalipso,stlidar%cldtype(:,3))              !OPAQ
-
-   CALL histwrite3d_cosp(o_clcalipsoopaque,stlidar%lidarcldtype(:,:,1),nvert)  !OPAQ
-   CALL histwrite3d_cosp(o_clcalipsothin,stlidar%lidarcldtype(:,:,2),nvert)    !OPAQ
-   CALL histwrite3d_cosp(o_clcalipsozopaque,stlidar%lidarcldtype(:,:,3),nvert) !OPAQ
-   CALL histwrite3d_cosp(o_clcalipsoopacity,stlidar%lidarcldtype(:,:,4),nvert) !OPAQ
-
-   CALL histwrite3d_cosp(o_proftemp,stlidar%proftemp,nvert)                    !TIBO
-
-#ifdef CPP_XIOS
-   CALL histwrite4d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr)
-   CALL histwrite4d_cosp(o_profSR,stlidar%profSR)                              !TIBO
+   if (cfg%Lcllcalipso) CALL histwrite2d_cosp(o_cllcalipso,stlidar%cldlayer(:,1))
+   if (cfg%Lclhcalipso) CALL histwrite2d_cosp(o_clhcalipso,stlidar%cldlayer(:,3))
+   if (cfg%Lclmcalipso) CALL histwrite2d_cosp(o_clmcalipso,stlidar%cldlayer(:,2)) 
+   if (cfg%Lcltcalipso) CALL histwrite2d_cosp(o_cltcalipso,stlidar%cldlayer(:,4))
+   if (cfg%Lclcalipso) CALL histwrite3d_cosp(o_clcalipso,stlidar%lidarcld,nvert)
+   if (cfg%Lclcalipsotmp) CALL histwrite3d_cosp(o_clcalipsotmp,stlidar%lidarcldtmp(:,:,1),nverttemp)
+
+   if (cfg%Lcllcalipsoice) CALL histwrite2d_cosp(o_cllcalipsoice,stlidar%cldlayerphase(:,1,1))
+   if (cfg%Lclhcalipsoice) CALL histwrite2d_cosp(o_clhcalipsoice,stlidar%cldlayerphase(:,3,1))
+   if (cfg%Lclmcalipsoice) CALL histwrite2d_cosp(o_clmcalipsoice,stlidar%cldlayerphase(:,2,1))
+   if (cfg%Lcltcalipsoice) CALL histwrite2d_cosp(o_cltcalipsoice,stlidar%cldlayerphase(:,4,1))
+   if (cfg%Lclcalipsoice) CALL histwrite3d_cosp(o_clcalipsoice,stlidar%lidarcldphase(:,:,1),nvert)
+   if (cfg%Lclcalipsotmpice) CALL histwrite3d_cosp(o_clcalipsotmpice,stlidar%lidarcldtmp(:,:,2),nverttemp)
+
+   if (cfg%Lcllcalipsoliq) CALL histwrite2d_cosp(o_cllcalipsoliq,stlidar%cldlayerphase(:,1,2))
+   if (cfg%Lclhcalipsoliq) CALL histwrite2d_cosp(o_clhcalipsoliq,stlidar%cldlayerphase(:,3,2))
+   if (cfg%Lclmcalipsoliq) CALL histwrite2d_cosp(o_clmcalipsoliq,stlidar%cldlayerphase(:,2,2))
+   if (cfg%Lcltcalipsoliq) CALL histwrite2d_cosp(o_cltcalipsoliq,stlidar%cldlayerphase(:,4,2))
+   if (cfg%Lclcalipsoliq) CALL histwrite3d_cosp(o_clcalipsoliq,stlidar%lidarcldphase(:,:,2),nvert)
+   if (cfg%Lclcalipsotmpliq) CALL histwrite3d_cosp(o_clcalipsotmpliq,stlidar%lidarcldtmp(:,:,3),nverttemp)
+
+   if (cfg%Lcllcalipsoun) CALL histwrite2d_cosp(o_cllcalipsoun,stlidar%cldlayerphase(:,1,3))
+   if (cfg%Lclhcalipsoun) CALL histwrite2d_cosp(o_clhcalipsoun,stlidar%cldlayerphase(:,3,3))
+   if (cfg%Lclmcalipsoun) CALL histwrite2d_cosp(o_clmcalipsoun,stlidar%cldlayerphase(:,2,3))
+   if (cfg%Lcltcalipsoun) CALL histwrite2d_cosp(o_cltcalipsoun,stlidar%cldlayerphase(:,4,3))
+   if (cfg%Lclcalipsoun) CALL histwrite3d_cosp(o_clcalipsoun,stlidar%lidarcldphase(:,:,3),nvert)
+   if (cfg%Lclcalipsotmpun) CALL histwrite3d_cosp(o_clcalipsotmpun,stlidar%lidarcldtmp(:,:,4),nverttemp)
+
+   if (cfg%Lclopaquecalipso) CALL histwrite2d_cosp(o_clopaquecalipso,stlidar%cldtype(:,1))               !OPAQ
+   if (cfg%Lclthincalipso) CALL histwrite2d_cosp(o_clthincalipso,stlidar%cldtype(:,2))                 !OPAQ
+   if (cfg%Lclzopaquecalipso) CALL histwrite2d_cosp(o_clzopaquecalipso,stlidar%cldtype(:,3))              !OPAQ
+
+   if (cfg%Lclcalipsoopaque) CALL histwrite3d_cosp(o_clcalipsoopaque,stlidar%lidarcldtype(:,:,1),nvert)  !OPAQ
+   if (cfg%Lclcalipsothin) CALL histwrite3d_cosp(o_clcalipsothin,stlidar%lidarcldtype(:,:,2),nvert)    !OPAQ
+   if (cfg%Lclcalipsozopaque) CALL histwrite3d_cosp(o_clcalipsozopaque,stlidar%lidarcldtype(:,:,3),nvert) !OPAQ
+   if (cfg%Lclcalipsoopacity) CALL histwrite3d_cosp(o_clcalipsoopacity,stlidar%lidarcldtype(:,:,4),nvert) !OPAQ
+
+   if (cfg%Lproftemp) CALL histwrite3d_cosp(o_proftemp,stlidar%proftemp,nvert)                    !TIBO
+
+#ifdef CPP_XIOS
+   if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr)
+   if (cfg%LprofSR) CALL histwrite4d_cosp(o_profSR,stlidar%profSR)                              !TIBO
 #else
-   do icl=1,SR_BINS
-      CALL histwrite3d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr(:,icl,:),nvert,icl)
-   enddo
-   do icl=1,Ncolumns                                                              !TIBO
-      CALL histwrite3d_cosp(o_profSR,stlidar%profSR(:,icl,:),nvert,icl)           !TIBO
-   enddo                                                                          !TIBO
-#endif
-   CALL histwrite3d_cosp(o_parasol_refl,stlidar%parasolrefl,nvertp)
-
-   do k=1,PARASOL_NREFL
-    do ip=1, Npoints
-     if (stlidar%cldlayer(ip,4).gt.0.01.and.stlidar%parasolrefl(ip,k).ne.missing_val) then
-       parasolcrefl(ip,k)=(stlidar%parasolrefl(ip,k)-0.03*(1.-stlidar%cldlayer(ip,4)))/ &
-                            stlidar%cldlayer(ip,4)
-        Ncref(ip,k) = 1.
-     else
-        parasolcrefl(ip,k)=missing_val
-        Ncref(ip,k) = 0.
-     endif
+   if (cfg%LcfadLidarsr532) then
+     do icl=1,SR_BINS
+        CALL histwrite3d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr(:,icl,:),nvert,icl)
+     enddo
+   endif
+   if (cfg%LprofSR) then
+     do icl=1,Ncolumns                                                              !TIBO
+        CALL histwrite3d_cosp(o_profSR,stlidar%profSR(:,icl,:),nvert,icl)           !TIBO
+     enddo                                                                          !TIBO
+   endif
+#endif
+   if (cfg%LparasolRefl) CALL histwrite3d_cosp(o_parasol_refl,stlidar%parasolrefl,nvertp)
+
+  if (cfg%LparasolRefl) then 
+    do k=1,PARASOL_NREFL
+     do ip=1, Npoints
+      if (stlidar%cldlayer(ip,4).gt.0.01.and.stlidar%parasolrefl(ip,k).ne.missing_val) then
+        parasolcrefl(ip,k)=(stlidar%parasolrefl(ip,k)-0.03*(1.-stlidar%cldlayer(ip,4)))/ &
+                             stlidar%cldlayer(ip,4)
+         Ncref(ip,k) = 1.
+      else
+         parasolcrefl(ip,k)=missing_val
+         Ncref(ip,k) = 0.
+      endif
+     enddo
     enddo
-   
-   enddo
-   CALL histwrite3d_cosp(o_Ncrefl,Ncref,nvertp)
-   CALL histwrite3d_cosp(o_parasol_crefl,parasolcrefl,nvertp)
-
-#ifdef CPP_XIOS
-   CALL histwrite4d_cosp(o_atb532,sglidar%beta_tot)
+    CALL histwrite3d_cosp(o_Ncrefl,Ncref,nvertp)
+    CALL histwrite3d_cosp(o_parasol_crefl,parasolcrefl,nvertp)
+  endif
+
+#ifdef CPP_XIOS
+   if (cfg%Latb532) CALL histwrite4d_cosp(o_atb532,sglidar%beta_tot)
 #else
-   do icl=1,Ncolumns 
-      CALL histwrite3d_cosp(o_atb532,sglidar%beta_tot(:,icl,:),nvertmcosp,icl)
-   enddo
-#endif
-
-   CALL histwrite3d_cosp(o_beta_mol532,sglidar%beta_mol,nvertmcosp) 
+   if (cfg%Latb532) then  
+     do icl=1,Ncolumns 
+        CALL histwrite3d_cosp(o_atb532,sglidar%beta_tot(:,icl,:),nvertmcosp,icl)
+     enddo
+   endif 
+#endif
+
+   if (cfg%LlidarBetaMol532) CALL histwrite3d_cosp(o_beta_mol532,sglidar%beta_mol,nvertmcosp) 
+
  endif !Lidar
 
@@ -202,15 +210,20 @@
    where(stradar%cfad_ze == R_UNDEF) stradar%cfad_ze = missing_val
 #ifdef CPP_XIOS
-   CALL histwrite4d_cosp(o_dbze94,sgradar%Ze_tot)
-   CALL histwrite4d_cosp(o_cfadDbze94,stradar%cfad_ze)
+   if (cfg%Ldbze94) CALL histwrite4d_cosp(o_dbze94,sgradar%Ze_tot)
+   if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,stradar%cfad_ze)
 #else
-   do icl=1,Ncolumns
-      CALL histwrite3d_cosp(o_dbze94,sgradar%Ze_tot(:,icl,:),nvertmcosp,icl)
-   enddo
-   do icl=1,DBZE_BINS
+   if (cfg%Ldbze94) then
+    do icl=1,Ncolumns
+       CALL histwrite3d_cosp(o_dbze94,sgradar%Ze_tot(:,icl,:),nvert,icl)
+    enddo
+   endif
+   if (cfg%LcfadDbze94) then
+    do icl=1,DBZE_BINS
     CALL histwrite3d_cosp(o_cfadDbze94,stradar%cfad_ze(:,icl,:),nvert,icl)
-   enddo
+    enddo
+   endif
 #endif
  endif
+! endif pour radar
 
 !!! Sorties combinees Cloudsat et Calipso
@@ -218,8 +231,8 @@
    where(stradar%lidar_only_freq_cloud == R_UNDEF) &
                            stradar%lidar_only_freq_cloud = missing_val
-   CALL histwrite3d_cosp(o_clcalipso2,stradar%lidar_only_freq_cloud,nvert)
+   if (cfg%Lclcalipso) CALL histwrite3d_cosp(o_clcalipso2,stradar%lidar_only_freq_cloud,nvert)
    where(stradar%radar_lidar_tcc == R_UNDEF) &
                            stradar%radar_lidar_tcc = missing_val
-   CALL histwrite2d_cosp(o_cltlidarradar,stradar%radar_lidar_tcc)
+   if (cfg%Lcltlidarradar) CALL histwrite2d_cosp(o_cltlidarradar,stradar%radar_lidar_tcc)
  endif
 
@@ -238,18 +251,21 @@
    CALL histwrite2d_cosp(o_sunlit,gbx%sunlit)
 #ifdef CPP_XIOS
-   CALL histwrite4d_cosp(o_clisccp2,isccp%fq_isccp)
+  if (cfg%Lclisccp) CALL histwrite4d_cosp(o_clisccp2,isccp%fq_isccp)
 #else
-   do icl=1,7
-   CALL histwrite3d_cosp(o_clisccp2,isccp%fq_isccp(:,icl,:),nvertisccp,icl) 
-   enddo
-#endif
-   CALL histwrite3d_cosp(o_boxtauisccp,isccp%boxtau,nvertcol)
-   CALL histwrite3d_cosp(o_boxptopisccp,isccp%boxptop,nvertcol) 
-   CALL histwrite2d_cosp(o_tclisccp,isccp%totalcldarea) 
-   CALL histwrite2d_cosp(o_ctpisccp,isccp%meanptop) 
-   CALL histwrite2d_cosp(o_tauisccp,isccp%meantaucld) 
-   CALL histwrite2d_cosp(o_albisccp,isccp%meanalbedocld) 
-   CALL histwrite2d_cosp(o_meantbisccp,isccp%meantb) 
-   CALL histwrite2d_cosp(o_meantbclrisccp,isccp%meantbclr)
+   if (cfg%Lclisccp) then
+     do icl=1,7
+       CALL histwrite3d_cosp(o_clisccp2,isccp%fq_isccp(:,icl,:),nvertisccp,icl) 
+     enddo
+   endif
+#endif
+
+   if (cfg%Lboxtauisccp) CALL histwrite3d_cosp(o_boxtauisccp,isccp%boxtau,nvertcol)
+   if (cfg%Lboxptopisccp) CALL histwrite3d_cosp(o_boxptopisccp,isccp%boxptop,nvertcol) 
+   if (cfg%Lcltisccp) CALL histwrite2d_cosp(o_tclisccp,isccp%totalcldarea) 
+   if (cfg%Lpctisccp) CALL histwrite2d_cosp(o_ctpisccp,isccp%meanptop) 
+   if (cfg%Ltauisccp) CALL histwrite2d_cosp(o_tauisccp,isccp%meantaucld) 
+   if (cfg%Lalbisccp) CALL histwrite2d_cosp(o_albisccp,isccp%meanalbedocld) 
+   if (cfg%Lmeantbisccp) CALL histwrite2d_cosp(o_meantbisccp,isccp%meantb) 
+   if (cfg%Lmeantbclrisccp) CALL histwrite2d_cosp(o_meantbclrisccp,isccp%meantbclr)
  endif ! Isccp
 
@@ -259,11 +275,14 @@
 
 #ifdef CPP_XIOS
-   CALL histwrite4d_cosp(o_clMISR,misr%fq_MISR)
+   if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,misr%fq_MISR)
 #else
-   do icl=1,7 
+   if (cfg%LclMISR) then
+    do icl=1,7 
       CALL histwrite3d_cosp(o_clMISR,misr%fq_MISR(:,icl,:),nvertmisr,icl)
-   enddo
+    enddo
+   endif
 #endif
  endif
+! endif pour Misr
 
 !!! Modis simulator
@@ -298,30 +317,30 @@
         modis%Ice_Water_Path_Mean = missing_val
 
-    where(modis%Optical_Thickness_Total_LogMean == R_UNDEF) &
+  where(modis%Optical_Thickness_Total_LogMean == R_UNDEF) &
           modis%Optical_Thickness_Total_LogMean = missing_val
            
-    where(modis%Optical_Thickness_Water_LogMean == R_UNDEF) &
+  where(modis%Optical_Thickness_Water_LogMean == R_UNDEF) &
           modis%Optical_Thickness_Water_LogMean = missing_val
 
-    where(modis%Optical_Thickness_Ice_LogMean == R_UNDEF) &
+  where(modis%Optical_Thickness_Ice_LogMean == R_UNDEF) &
           modis%Optical_Thickness_Ice_LogMean = missing_val
     
-   CALL histwrite2d_cosp(o_cllmodis,modis%Cloud_Fraction_Low_Mean)
-   CALL histwrite2d_cosp(o_clhmodis,modis%Cloud_Fraction_High_Mean)
-   CALL histwrite2d_cosp(o_clmmodis,modis%Cloud_Fraction_Mid_Mean)
-   CALL histwrite2d_cosp(o_cltmodis,modis%Cloud_Fraction_Total_Mean)
-   CALL histwrite2d_cosp(o_clwmodis,modis%Cloud_Fraction_Water_Mean)
-   CALL histwrite2d_cosp(o_climodis,modis%Cloud_Fraction_Ice_Mean)
-   CALL histwrite2d_cosp(o_tautmodis,modis%Optical_Thickness_Total_Mean)
-   CALL histwrite2d_cosp(o_tauwmodis,modis%Optical_Thickness_Water_Mean)
-   CALL histwrite2d_cosp(o_tauimodis,modis%Optical_Thickness_Ice_Mean)
-   CALL histwrite2d_cosp(o_tautlogmodis,modis%Optical_Thickness_Total_LogMean)  
-   CALL histwrite2d_cosp(o_tauwlogmodis,modis%Optical_Thickness_Water_LogMean)
-   CALL histwrite2d_cosp(o_tauilogmodis,modis%Optical_Thickness_Ice_LogMean)
-   CALL histwrite2d_cosp(o_reffclwmodis,modis%Cloud_Particle_Size_Water_Mean)
-   CALL histwrite2d_cosp(o_reffclimodis,modis%Cloud_Particle_Size_Ice_Mean)
-   CALL histwrite2d_cosp(o_pctmodis,modis%Cloud_Top_Pressure_Total_Mean)
-   CALL histwrite2d_cosp(o_lwpmodis,modis%Liquid_Water_Path_Mean)
-   CALL histwrite2d_cosp(o_iwpmodis,modis%Ice_Water_Path_Mean)
+  if (cfg%Lcllmodis) CALL histwrite2d_cosp(o_cllmodis,modis%Cloud_Fraction_Low_Mean)
+  if (cfg%Lclhmodis) CALL histwrite2d_cosp(o_clhmodis,modis%Cloud_Fraction_High_Mean)
+  if (cfg%Lclmmodis) CALL histwrite2d_cosp(o_clmmodis,modis%Cloud_Fraction_Mid_Mean)
+  if (cfg%Lcltmodis) CALL histwrite2d_cosp(o_cltmodis,modis%Cloud_Fraction_Total_Mean)
+  if (cfg%Lclwmodis) CALL histwrite2d_cosp(o_clwmodis,modis%Cloud_Fraction_Water_Mean)
+  if (cfg%Lclimodis) CALL histwrite2d_cosp(o_climodis,modis%Cloud_Fraction_Ice_Mean)
+  if (cfg%Ltautmodis)  CALL histwrite2d_cosp(o_tautmodis,modis%Optical_Thickness_Total_Mean)
+  if (cfg%Ltauwmodis) CALL histwrite2d_cosp(o_tauwmodis,modis%Optical_Thickness_Water_Mean)
+  if (cfg%Ltauimodis) CALL histwrite2d_cosp(o_tauimodis,modis%Optical_Thickness_Ice_Mean)
+  if (cfg%Ltautlogmodis) CALL histwrite2d_cosp(o_tautlogmodis,modis%Optical_Thickness_Total_LogMean)  
+  if (cfg%Ltauwlogmodis) CALL histwrite2d_cosp(o_tauwlogmodis,modis%Optical_Thickness_Water_LogMean)
+  if (cfg%Ltauilogmodis) CALL histwrite2d_cosp(o_tauilogmodis,modis%Optical_Thickness_Ice_LogMean)
+  if (cfg%Lreffclwmodis) CALL histwrite2d_cosp(o_reffclwmodis,modis%Cloud_Particle_Size_Water_Mean)
+  if (cfg%Lreffclimodis) CALL histwrite2d_cosp(o_reffclimodis,modis%Cloud_Particle_Size_Ice_Mean)
+  if (cfg%Lpctmodis) CALL histwrite2d_cosp(o_pctmodis,modis%Cloud_Top_Pressure_Total_Mean)
+  if (cfg%Llwpmodis) CALL histwrite2d_cosp(o_lwpmodis,modis%Liquid_Water_Path_Mean)
+  if (cfg%Liwpmodis) CALL histwrite2d_cosp(o_iwpmodis,modis%Ice_Water_Path_Mean)
 
     where(modis%Optical_Thickness_vs_Cloud_Top_Pressure == R_UNDEF) &
@@ -329,10 +348,12 @@
 
 #ifdef CPP_XIOS
-   CALL histwrite4d_cosp(o_clmodis,modis%Optical_Thickness_vs_Cloud_Top_Pressure)
+   if (cfg%Lclmodis) CALL histwrite4d_cosp(o_clmodis,modis%Optical_Thickness_vs_Cloud_Top_Pressure)
 #else
+  if (cfg%Lclmodis) then
    do icl=1,7
    CALL histwrite3d_cosp(o_clmodis, &
      modis%Optical_Thickness_vs_Cloud_Top_Pressure(:,icl,:),nvertisccp,icl)           
    enddo
+  endif 
 #endif
 
@@ -344,15 +365,21 @@
 
 #ifdef CPP_XIOS
-    CALL histwrite4d_cosp(o_crimodis,modis%Optical_Thickness_vs_ReffIce)
-    CALL histwrite4d_cosp(o_crlmodis,modis%Optical_Thickness_vs_ReffLiq)
+  if (cfg%Lcrimodis) CALL histwrite4d_cosp(o_crimodis,modis%Optical_Thickness_vs_ReffIce)
+  if (cfg%Lcrlmodis) CALL histwrite4d_cosp(o_crlmodis,modis%Optical_Thickness_vs_ReffLiq)
 #else
+  if (cfg%Lcrimodis) then
     do icl=1,7
-   CALL histwrite3d_cosp(o_crimodis, &
-     modis%Optical_Thickness_vs_ReffIce(:,icl,:),nvertReffIce,icl)
-   CALL histwrite3d_cosp(o_crlmodis, &
-     modis%Optical_Thickness_vs_ReffLiq(:,icl,:),nvertReffLiq,icl)
+     CALL histwrite3d_cosp(o_crimodis, &
+          modis%Optical_Thickness_vs_ReffIce(:,icl,:),nvertReffIce,icl)
     enddo
-#endif
- endif
+  endif
+  if (cfg%Lcrlmodis) then
+    do icl=1,7 
+     CALL histwrite3d_cosp(o_crlmodis, &
+          modis%Optical_Thickness_vs_ReffLiq(:,icl,:),nvertReffLiq,icl)
+    enddo
+  endif 
+#endif
+ endif !modis
 
  IF(.NOT.cosp_varsdefined) THEN
@@ -798,8 +825,8 @@
 
 #ifdef CPP_XIOS
-    IF (ok_all_xml) THEN
+!    IF (ok_all_xml) THEN
      CALL xios_send_field(var%name, Field4d(:,:,1:nlev,1:nlev2))
      IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
-    ENDIF
+!    ENDIF
 #endif
 
Index: LMDZ6/trunk/libf/phylmd/cosp/cosp_read_otputkeys.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/cosp_read_otputkeys.F90	(revision 3247)
+++ LMDZ6/trunk/libf/phylmd/cosp/cosp_read_otputkeys.F90	(revision 3247)
@@ -0,0 +1,1258 @@
+!!!=============================================================================
+!!! AI mars 2018
+!!  Module permettant de controler les cles de sorties cosp
+!!  pour LMDZ
+!! 1. on initialise les cles au 1er passage a cosp itap de la physique = 1
+!! 2. on garde la routine de lecture du fichier namelist cosp_out...txt pour le
+!!    cas non XIOS (ioipsl)
+!! 3. on rajoutte une subroutine qui interoge XIOS si les champs sont demandes
+!!    dans les xml alors on les active et on active les simulateurs
+!!    correspondant 
+!!!=============================================================================
+
+module cosp_read_otputkeys
+
+  USE MOD_COSP_CONSTANTS
+  USE MOD_COSP_TYPES
+  USE mod_phys_lmdz_para
+
+CONTAINS
+!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+!--------------- SUBROUTINE READ_COSP_OUTPUT_NL -------------------------
+!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ SUBROUTINE cosp_outputkeys_init(cfg)
+  implicit none
+  type(cosp_config),intent(out) :: cfg 
+  character(len=32) :: out_list(N_OUT_LIST)
+  integer :: i
+
+                
+   do i=1,N_OUT_LIST
+      cfg%out_list(i)=''
+   enddo
+
+   cfg%Llidar_sim=.false.
+   cfg%Lradar_sim=.false.
+   cfg%Lisccp_sim=.false.
+   cfg%Lmodis_sim=.false.
+   cfg%Lmisr_sim=.false.
+   cfg%Lrttov_sim=.false.
+   cfg%Lstats=.false.
+   cfg%Lwrite_output=.false.
+   cfg%Ltoffset=.false.
+   cfg%Lfracout=.false.
+
+  cfg%Lcllcalipso=.FALSE.
+  cfg%Lclmcalipso=.FALSE.
+  cfg%Lclhcalipso=.FALSE.
+  cfg%Lcltcalipso=.FALSE.
+  cfg%Lcllcalipsoice=.FALSE.
+  cfg%Lclmcalipsoice=.FALSE.
+  cfg%Lclhcalipsoice=.FALSE.
+  cfg%Lcltcalipsoice=.FALSE.
+  cfg%Lcllcalipsoliq=.FALSE.
+  cfg%Lclmcalipsoliq=.FALSE.
+  cfg%Lclhcalipsoliq=.FALSE.
+  cfg%Lcltcalipsoliq=.FALSE.
+  cfg%Lcllcalipsoun=.FALSE.
+  cfg%Lclmcalipsoun=.FALSE.
+  cfg%Lclhcalipsoun=.FALSE.
+  cfg%Lcltcalipsoun=.FALSE.
+  cfg%Lclcalipso=.FALSE.
+  cfg%Lclcalipsoice=.FALSE.
+  cfg%Lclcalipsoliq=.FALSE.
+  cfg%Lclcalipsoun=.FALSE.
+  cfg%Lclcalipsotmp=.FALSE.
+  cfg%Lclcalipsotmpice=.FALSE.
+  cfg%Lclcalipsotmpliq=.FALSE.
+  cfg%Lclcalipsotmpun=.FALSE.
+  cfg%LparasolRefl=.FALSE.
+  cfg%LcfadLidarsr532=.FALSE.
+  cfg%Latb532=.FALSE.
+  cfg%LlidarBetaMol532=.FALSE.
+  cfg%Lclopaquecalipso=.FALSE.
+  cfg%Lclthincalipso=.FALSE.
+  cfg%Lclzopaquecalipso=.FALSE.
+  cfg%Lclcalipsoopaque=.FALSE.
+  cfg%Lclcalipsothin=.FALSE.
+  cfg%Lclcalipsozopaque=.FALSE.
+  cfg%Lclcalipsoopacity=.FALSE.
+  cfg%Lproftemp=.FALSE.
+  cfg%LprofSR=.FALSE.
+
+  cfg%LcfadDbze94=.FALSE.
+  cfg%Ldbze94=.FALSE.
+  cfg%Lcltlidarradar=.FALSE.
+  cfg%Lclcalipso2=.FALSE.
+
+  cfg%Lclisccp=.FALSE.
+  cfg%Lboxtauisccp=.FALSE.
+  cfg%Lboxptopisccp=.FALSE.
+  cfg%Lcltisccp=.FALSE.
+  cfg%Lpctisccp=.FALSE.
+  cfg%Ltauisccp=.FALSE.
+  cfg%Lalbisccp=.FALSE.
+  cfg%Lmeantbisccp=.FALSE.
+  cfg%Lmeantbclrisccp=.FALSE.
+
+  cfg%LclMISR=.FALSE.
+
+  cfg%Lcllmodis=.FALSE.
+  cfg%Lclmmodis=.FALSE.
+  cfg%Lclhmodis=.FALSE.
+  cfg%Lcltmodis=.FALSE.
+  cfg%Lclwmodis=.FALSE.
+  cfg%Lclimodis=.FALSE.
+  cfg%Ltautmodis=.FALSE.
+  cfg%Ltauwmodis=.FALSE.
+  cfg%Ltauimodis=.FALSE.
+  cfg%Ltautlogmodis=.FALSE.
+  cfg%Ltauilogmodis=.FALSE.
+  cfg%Ltauwlogmodis=.FALSE.
+  cfg%Lreffclwmodis=.FALSE.
+  cfg%Lreffclimodis=.FALSE.
+  cfg%Lpctmodis=.FALSE.
+  cfg%Llwpmodis=.FALSE.
+  cfg%Liwpmodis=.FALSE.
+  cfg%Lclmodis=.FALSE.
+  cfg%Lcrimodis=.FALSE.
+  cfg%Lcrlmodis=.FALSE.
+
+  cfg%Ltbrttov=.FALSE.
+
+ end subroutine cosp_outputkeys_init
+
+ SUBROUTINE cosp_outputkeys_test(cfg)
+  implicit none
+  type(cosp_config),intent(out) :: cfg
+  character(len=32) :: out_list(N_OUT_LIST)
+  integer :: i
+
+
+   do i=1,N_OUT_LIST
+      cfg%out_list(i)=''
+   enddo
+
+   cfg%Llidar_sim=.true.
+   cfg%Lradar_sim=.false.
+   cfg%Lisccp_sim=.false.
+   cfg%Lmodis_sim=.false.
+   cfg%Lmisr_sim=.false.
+   cfg%Lrttov_sim=.false.
+   cfg%Lstats=.false.
+   cfg%Lwrite_output=.false.
+   cfg%Ltoffset=.false.
+   cfg%Lfracout=.false.
+
+  cfg%Lcllcalipso=.TRUE.
+  cfg%Lclmcalipso=.TRUE.
+  cfg%Lclhcalipso=.TRUE.
+  cfg%Lcltcalipso=.TRUE.
+  cfg%Lcllcalipsoice=.FALSE.
+  cfg%Lclmcalipsoice=.FALSE.
+  cfg%Lclhcalipsoice=.FALSE.
+  cfg%Lcltcalipsoice=.FALSE.
+  cfg%Lcllcalipsoliq=.FALSE.
+  cfg%Lclmcalipsoliq=.FALSE.
+  cfg%Lclhcalipsoliq=.FALSE.
+  cfg%Lcltcalipsoliq=.FALSE.
+  cfg%Lcllcalipsoun=.FALSE.
+  cfg%Lclmcalipsoun=.FALSE.
+  cfg%Lclhcalipsoun=.FALSE.
+  cfg%Lcltcalipsoun=.FALSE.
+  cfg%Lclcalipso=.FALSE.
+  cfg%Lclcalipsoice=.FALSE.
+  cfg%Lclcalipsoliq=.FALSE.
+  cfg%Lclcalipsoun=.FALSE.
+  cfg%Lclcalipsotmp=.FALSE.
+  cfg%Lclcalipsotmpice=.FALSE.
+  cfg%Lclcalipsotmpliq=.FALSE.
+  cfg%Lclcalipsotmpun=.FALSE.
+  cfg%LparasolRefl=.FALSE.
+  cfg%LcfadLidarsr532=.FALSE.
+  cfg%Latb532=.FALSE.
+  cfg%LlidarBetaMol532=.FALSE.
+  cfg%Lclopaquecalipso=.FALSE.
+  cfg%Lclthincalipso=.FALSE.
+  cfg%Lclzopaquecalipso=.FALSE.
+  cfg%Lclcalipsoopaque=.FALSE.
+  cfg%Lclcalipsothin=.FALSE.
+  cfg%Lclcalipsozopaque=.FALSE.
+  cfg%Lclcalipsoopacity=.FALSE.
+  cfg%Lproftemp=.FALSE.
+  cfg%LprofSR=.FALSE.
+
+  cfg%LcfadDbze94=.FALSE.
+  cfg%Ldbze94=.FALSE.
+  cfg%Lcltlidarradar=.FALSE.
+  cfg%Lclcalipso2=.FALSE.
+
+  cfg%Lclisccp=.FALSE.
+  cfg%Lboxtauisccp=.FALSE.
+  cfg%Lboxptopisccp=.FALSE.
+  cfg%Lcltisccp=.FALSE.
+  cfg%Lpctisccp=.FALSE.
+  cfg%Ltauisccp=.FALSE.
+  cfg%Lalbisccp=.FALSE.
+  cfg%Lmeantbisccp=.FALSE.
+  cfg%Lmeantbclrisccp=.FALSE.
+
+  cfg%LclMISR=.FALSE.
+
+  cfg%Lcllmodis=.FALSE.
+  cfg%Lclmmodis=.FALSE.
+  cfg%Lclhmodis=.FALSE.
+  cfg%Lcltmodis=.FALSE.
+  cfg%Lclwmodis=.FALSE.
+  cfg%Lclimodis=.FALSE.
+  cfg%Ltautmodis=.FALSE.
+  cfg%Ltauwmodis=.FALSE.
+  cfg%Ltauimodis=.FALSE.
+  cfg%Ltautlogmodis=.FALSE.
+  cfg%Ltauilogmodis=.FALSE.
+  cfg%Ltauwlogmodis=.FALSE.
+  cfg%Lreffclwmodis=.FALSE.
+  cfg%Lreffclimodis=.FALSE.
+  cfg%Lpctmodis=.FALSE.
+  cfg%Llwpmodis=.FALSE.
+  cfg%Liwpmodis=.FALSE.
+  cfg%Lclmodis=.FALSE.
+  cfg%Lcrimodis=.FALSE.
+  cfg%Lcrlmodis=.FALSE.
+
+  cfg%Ltbrttov=.FALSE.
+
+ end subroutine cosp_outputkeys_test
+
+ SUBROUTINE READ_COSP_OUTPUT_NL(itap,cosp_nl,cfg)
+
+#ifdef CPP_XIOS
+    USE xios, ONLY: xios_field_is_active
+#endif
+  implicit none
+  character(len=*),intent(in) :: cosp_nl
+  type(cosp_config),intent(out) :: cfg
+  ! Local variables
+  integer :: i, itap
+
+ logical, save :: Lradar_sim,Llidar_sim,Lisccp_sim,Lmodis_sim,Lmisr_sim,Lrttov_sim, Lstats, &
+             Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,LcfadDbze94, &
+             LcfadLidarsr532,Lclcalipso2,Lclcalipso,Lclhcalipso,Lclisccp,Lcllcalipso, &
+             Lclmcalipso,Lcltcalipso,Lcltlidarradar,Lpctisccp,Ldbze94,Ltauisccp,Lcltisccp, &
+             Lclcalipsoliq,Lclcalipsoice,Lclcalipsoun, &
+             Lclcalipsotmp,Lclcalipsotmpliq,Lclcalipsotmpice,Lclcalipsotmpun, &
+             Lcltcalipsoliq,Lcltcalipsoice,Lcltcalipsoun, &
+             Lclhcalipsoliq,Lclhcalipsoice,Lclhcalipsoun, &
+             Lclmcalipsoliq,Lclmcalipsoice,Lclmcalipsoun, &
+             Lcllcalipsoliq,Lcllcalipsoice,Lcllcalipsoun, &
+             Ltoffset,LparasolRefl,LclMISR,Lmeantbisccp,Lmeantbclrisccp, &
+             Lfracout,LlidarBetaMol532,Ltbrttov, &
+             Lcltmodis,Lclwmodis,Lclimodis,Lclhmodis,Lclmmodis,Lcllmodis,Ltautmodis,Ltauwmodis,Ltauimodis,Ltautlogmodis, &
+             Ltauwlogmodis,Ltauilogmodis,Lreffclwmodis,Lreffclimodis,Lpctmodis,Llwpmodis, &
+             Liwpmodis,Lclmodis,Lcrimodis,Lcrlmodis,Lclopaquecalipso,Lclthincalipso,      &           !OPAQ (2)
+             Lclzopaquecalipso,Lclcalipsoopaque,Lclcalipsothin,Lclcalipsozopaque,Lclcalipsoopacity, & !OPAQ (5)
+             LprofSR,Lproftemp                                                                        !TIBO (2)
+
+  namelist/COSP_OUTPUT/Lradar_sim,Llidar_sim,Lisccp_sim,Lmodis_sim,Lmisr_sim,Lrttov_sim, &
+             Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,LcfadDbze94, &
+             LcfadLidarsr532,Lclcalipso2,Lclcalipso,Lclhcalipso,Lclisccp, &
+             Lcllcalipso,Lclmcalipso,Lcltcalipso,Lcltlidarradar,Lpctisccp,Ldbze94,Ltauisccp, &
+             Lclcalipsoliq,Lclcalipsoice,Lclcalipsoun, &
+             Lclcalipsotmp,Lclcalipsotmpliq,Lclcalipsotmpice,Lclcalipsotmpun, &
+             Lcltcalipsoliq,Lcltcalipsoice,Lcltcalipsoun, &
+             Lclhcalipsoliq,Lclhcalipsoice,Lclhcalipsoun, &
+             Lclmcalipsoliq,Lclmcalipsoice,Lclmcalipsoun, &
+             Lcllcalipsoliq,Lcllcalipsoice,Lcllcalipsoun, &
+             Lcltisccp,Ltoffset,LparasolRefl,LclMISR,Lmeantbisccp,Lmeantbclrisccp, &
+             Lfracout,LlidarBetaMol532,Ltbrttov, &
+             Lcltmodis,Lclwmodis,Lclimodis,Lclhmodis,Lclmmodis,Lcllmodis,Ltautmodis,Ltauwmodis,Ltauimodis,Ltautlogmodis, &
+             Ltauwlogmodis,Ltauilogmodis,Lreffclwmodis,Lreffclimodis,Lpctmodis,Llwpmodis, &
+             Liwpmodis,Lclmodis,Lcrimodis,Lcrlmodis,Lclopaquecalipso,Lclthincalipso,      &           !OPAQ (2)
+             Lclzopaquecalipso,Lclcalipsoopaque,Lclcalipsothin,Lclcalipsozopaque,Lclcalipsoopacity, & !OPAQ (5)
+             LprofSR,Lproftemp                                                                        !TIBO (2)
+   
+  do i=1,N_OUT_LIST
+    cfg%out_list(i)=''
+  enddo
+  
+! Lecture du fichier namelist
+  IF (is_master) THEN
+    open(10,file=cosp_nl,status='old')
+    read(10,nml=cosp_output)
+    close(10)
+  ENDIF
+  
+  CALL bcast(Lradar_sim)
+  CALL bcast(Llidar_sim)
+  CALL bcast(Lisccp_sim)
+  CALL bcast(Lmodis_sim)
+  CALL bcast(Lmisr_sim)
+  CALL bcast(Lrttov_sim)
+
+  CALL bcast(Lstats)
+
+  CALL bcast(Lalbisccp)
+  CALL bcast(Latb532)
+  CALL bcast(Lboxptopisccp)
+  CALL bcast(Lboxtauisccp)
+  CALL bcast(LcfadDbze94)
+  CALL bcast(LcfadLidarsr532)
+  CALL bcast(Lclcalipso2)
+  CALL bcast(Lclcalipso)
+  CALL bcast(Lclhcalipso)
+  CALL bcast(Lclcalipsoliq)
+  CALL bcast(Lclcalipsoice)
+  CALL bcast(Lclcalipsoun)
+  CALL bcast(Lclcalipsotmp)
+  CALL bcast(Lclcalipsotmpliq)
+  CALL bcast(Lclcalipsotmpice)
+  CALL bcast(Lclcalipsotmpun)
+  CALL bcast(Lcltcalipsoliq)
+  CALL bcast(Lcltcalipsoice)
+  CALL bcast(Lcltcalipsoun)
+  CALL bcast(Lclhcalipsoliq)
+  CALL bcast(Lclhcalipsoice)
+  CALL bcast(Lclhcalipsoun)
+  CALL bcast(Lclmcalipsoliq)
+  CALL bcast(Lclmcalipsoice)
+  CALL bcast(Lclmcalipsoun)
+  CALL bcast(Lcllcalipsoliq)
+  CALL bcast(Lcllcalipsoice) 
+  CALL bcast(Lcllcalipsoun)
+  CALL bcast(Lclisccp)
+  CALL bcast(Lcllcalipso)
+  CALL bcast(Lclmcalipso)
+  CALL bcast(Lcltcalipso)
+  CALL bcast(Lcltlidarradar)
+  CALL bcast(Lpctisccp)
+  CALL bcast(Ldbze94)
+  CALL bcast(Ltauisccp)
+  CALL bcast(Lcltisccp)
+  CALL bcast(LparasolRefl)
+  CALL bcast(LclMISR)
+  CALL bcast(Lmeantbisccp)
+  CALL bcast(Lmeantbclrisccp)
+  CALL bcast(Lfracout)
+  CALL bcast(LlidarBetaMol532)
+  CALL bcast(Lcltmodis)
+  CALL bcast(Lclwmodis)
+  CALL bcast(Lclimodis) 
+  CALL bcast(Lclhmodis)
+  CALL bcast(Lclmmodis)
+  CALL bcast(Lcllmodis)
+  CALL bcast(Ltautmodis)
+  CALL bcast(Ltauwmodis)
+  CALL bcast(Ltauimodis)
+  CALL bcast(Ltautlogmodis)
+  CALL bcast(Ltauwlogmodis)
+  CALL bcast(Ltauilogmodis)
+  CALL bcast(Lreffclwmodis)
+  CALL bcast(Lreffclimodis)
+  CALL bcast(Lpctmodis)
+  CALL bcast(Llwpmodis)
+  CALL bcast(Liwpmodis)
+  CALL bcast(Lclmodis)
+  CALL bcast(Ltbrttov)
+  CALL bcast(Lcrimodis)
+  CALL bcast(Lcrlmodis)
+  CALL bcast(Lclopaquecalipso)  !OPAQ
+  CALL bcast(Lclthincalipso)    !OPAQ
+  CALL bcast(Lclzopaquecalipso) !OPAQ
+  CALL bcast(Lclcalipsoopaque)  !OPAQ
+  CALL bcast(Lclcalipsothin)    !OPAQ
+  CALL bcast(Lclcalipsozopaque) !OPAQ
+  CALL bcast(Lclcalipsoopacity) !OPAQ
+  CALL bcast(LprofSR)           !TIBO
+  CALL bcast(Lproftemp)         !TIBO
+
+!$OMP BARRIER
+
+!  print*,' Cles sorties cosp :'
+!  print*,' Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lrttov_sim', &
+!           Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lrttov_sim
+
+
+  ! Deal with dependencies
+  if (.not.Lradar_sim) then
+    LcfadDbze94   = .false.
+    Lclcalipso2    = .false.
+    Lcltlidarradar = .false. ! Needs radar & lidar
+    Ldbze94        = .false.
+    Lclcalipso2    = .false. ! Needs radar & lidar
+  endif
+
+  if (.not.Llidar_sim) then
+    Latb532          = .false.
+    LcfadLidarsr532  = .false.
+    Lclcalipso2      = .false.
+    Lclcalipso       = .false.
+    Lclhcalipso      = .false.
+    Lcllcalipso      = .false.
+    Lclmcalipso      = .false.
+    Lcltcalipso      = .false.
+    Lcltlidarradar   = .false. ! Needs radar & lidar
+    LparasolRefl     = .false.
+    LlidarBetaMol532 = .false.
+!! AI
+    Lclcalipsoliq       = .false.
+    Lclcalipsoice       = .false.
+    Lclcalipsoun        = .false.
+    Lclcalipsotmp       = .false.
+    Lclcalipsotmpun     = .false.
+    Lclcalipsotmpliq    = .false.
+    Lclcalipsotmpice    = .false.
+    Lclhcalipsoliq      = .false.
+    Lcllcalipsoliq      = .false.
+    Lclmcalipsoliq      = .false.
+    Lcltcalipsoliq      = .false.
+    Lclhcalipsoice      = .false.
+    Lcllcalipsoice      = .false.
+    Lclmcalipsoice      = .false.
+    Lcltcalipsoice      = .false.
+    Lclhcalipsoun       = .false.
+    Lcllcalipsoun       = .false.
+    Lclmcalipsoun       = .false.
+    Lcltcalipsoun       = .false.
+    Lclopaquecalipso    = .false. !OPAQ
+    Lclthincalipso      = .false. !OPAQ
+    Lclzopaquecalipso   = .false. !OPAQ
+    Lclcalipsoopaque    = .false. !OPAQ
+    Lclcalipsothin      = .false. !OPAQ
+    Lclcalipsozopaque   = .false. !OPAQ
+    Lclcalipsoopacity   = .false. !OPAQ
+    LprofSR             = .false. !TIBO
+    Lproftemp           = .false. !TIBO
+  endif
+
+  if (.not.Lisccp_sim) then
+    Lalbisccp       = .false.
+    Lboxptopisccp   = .false.
+    Lboxtauisccp    = .false.
+    Lclisccp        = .false.
+    Lpctisccp       = .false.
+    Ltauisccp       = .false.
+    Lcltisccp       = .false.
+    Lmeantbisccp    = .false.
+    Lmeantbclrisccp = .false.
+  endif
+
+  if (.not.Lmisr_sim) then
+    LclMISR = .false.
+  endif
+  if (.not.Lrttov_sim) then
+    Ltbrttov = .false.
+  endif
+  if ((.not.Lradar_sim).and.(.not.Llidar_sim).and. &
+      (.not.Lisccp_sim).and.(.not.Lmisr_sim)) then
+    Lfracout = .false.
+    Lstats = .false.
+  endif
+ if (.not.Lmodis_sim) then
+    Lcltmodis=.false.
+    Lclwmodis=.false.
+    Lclimodis=.false.
+    Lclhmodis=.false.
+    Lclmmodis=.false.
+    Lcllmodis=.false.
+    Ltautmodis=.false.
+    Ltauwmodis=.false.
+    Ltauimodis=.false.
+    Ltautlogmodis=.false.
+    Ltauwlogmodis=.false.
+    Ltauilogmodis=.false.
+    Lreffclwmodis=.false.
+    Lreffclimodis=.false.
+    Lpctmodis=.false.
+    Llwpmodis=.false.
+    Liwpmodis=.false.
+    Lclmodis=.false.
+    Lcrimodis=.false.
+    Lcrlmodis=.false.
+  endif
+  if (Lmodis_sim) Lisccp_sim = .true.
+
+  ! Diagnostics that use Radar and Lidar
+  if (((Lclcalipso2).or.(Lcltlidarradar)).and.((Lradar_sim).or.(Llidar_sim))) then
+    Lclcalipso2    = .true.
+    Lcltlidarradar = .true.
+    Llidar_sim     = .true.
+    Lradar_sim     = .true.
+  endif
+
+  if ((Lradar_sim).or.(Llidar_sim).or.(Lisccp_sim)) Lstats = .true.
+
+  ! Copy instrument flags to cfg structure
+  cfg%Lradar_sim = Lradar_sim
+  cfg%Llidar_sim = Llidar_sim
+  cfg%Lisccp_sim = Lisccp_sim
+  cfg%Lmodis_sim = Lmodis_sim
+  cfg%Lmisr_sim  = Lmisr_sim
+  cfg%Lrttov_sim = Lrttov_sim
+
+  cfg%Lstats = Lstats
+
+  ! Flag to control output to file
+  cfg%Lwrite_output = .false.
+  if (cfg%Lstats.or.cfg%Lmisr_sim.or.cfg%Lrttov_sim) then
+    cfg%Lwrite_output = .true.
+  endif
+
+  ! Output diagnostics
+  i = 1
+  if (Lalbisccp)        cfg%out_list(i) = 'albisccp'
+  i = i+1
+  if (Latb532)          cfg%out_list(i) = 'atb532'
+  i = i+1
+  if (Lboxptopisccp)    cfg%out_list(i) = 'boxptopisccp'
+  i = i+1
+  if (Lboxtauisccp)     cfg%out_list(i) = 'boxtauisccp'
+  i = i+1
+  if (LcfadDbze94)      cfg%out_list(i) = 'cfadDbze94'
+  i = i+1
+  if (LcfadLidarsr532)  cfg%out_list(i) = 'cfadLidarsr532'
+  i = i+1
+  if (Lclcalipso2)      cfg%out_list(i) = 'clcalipso2'
+  i = i+1
+  if (Lclcalipso)       cfg%out_list(i) = 'clcalipso'
+  i = i+1
+  if (Lclhcalipso)      cfg%out_list(i) = 'clhcalipso'
+  i = i+1
+  if (Lclisccp)         cfg%out_list(i) = 'clisccp'
+  i = i+1
+  if (Lcllcalipso)      cfg%out_list(i) = 'cllcalipso'
+  i = i+1
+  if (Lclmcalipso)      cfg%out_list(i) = 'clmcalipso'
+  i = i+1
+  if (Lcltcalipso)      cfg%out_list(i) = 'cltcalipso'
+  i = i+1
+
+  if (Lcllcalipsoice)      cfg%out_list(i) = 'cllcalipsoice'
+  i = i+1
+  if (Lclmcalipsoice)      cfg%out_list(i) = 'clmcalipsoice'
+  i = i+1
+  if (Lclhcalipsoice)      cfg%out_list(i) = 'clhcalipsoice'
+  i = i+1
+  if (Lcltcalipsoice)      cfg%out_list(i) = 'cltcalipsoice'
+  i = i+1
+  if (Lcllcalipsoliq)      cfg%out_list(i) = 'cllcalipsoliq'
+  i = i+1
+  if (Lclmcalipsoliq)      cfg%out_list(i) = 'clmcalipsoliq'
+  i = i+1
+  if (Lclhcalipsoliq)      cfg%out_list(i) = 'clhcalipsoliq'
+  i = i+1
+  if (Lcltcalipsoliq)      cfg%out_list(i) = 'cltcalipsoliq'
+  i = i+1
+  if (Lcllcalipsoun)      cfg%out_list(i) = 'cllcalipsoun'
+  i = i+1
+  if (Lclmcalipsoun)      cfg%out_list(i) = 'clmcalipsoun'
+  i = i+1
+  if (Lclhcalipsoun)      cfg%out_list(i) = 'clhcalipsoun'
+  i = i+1
+  if (Lcltcalipsoun)      cfg%out_list(i) = 'cltcalipsoun'
+  i = i+1
+
+  if (Lclcalipsoice)       cfg%out_list(i) = 'clcalipsoice'
+  i = i+1
+  if (Lclcalipsoliq)       cfg%out_list(i) = 'clcalipsoliq'
+  i = i+1
+  if (Lclcalipsoun)       cfg%out_list(i) = 'clcalipsoun'
+  i = i+1
+
+  if (Lclcalipsotmp)       cfg%out_list(i) = 'clcalipsotmp'
+  i = i+1
+  if (Lclcalipsotmpice)       cfg%out_list(i) = 'clcalipsotmpice'
+  i = i+1
+  if (Lclcalipsotmpliq)       cfg%out_list(i) = 'clcalipsotmpliq'
+  i = i+1
+  if (Lclcalipsotmpun)       cfg%out_list(i) = 'clcalipsotmpun'
+  i = i+1
+  if (Lcltlidarradar)   cfg%out_list(i) = 'cltlidarradar'
+  i = i+1
+  if (Lpctisccp)        cfg%out_list(i) = 'pctisccp'
+  i = i+1
+  if (Ldbze94)          cfg%out_list(i) = 'dbze94'
+  i = i+1
+  if (Ltauisccp)        cfg%out_list(i) = 'tauisccp'
+  i = i+1
+  if (Lcltisccp)        cfg%out_list(i) = 'cltisccp'
+  i = i+1
+  if (Ltoffset)         cfg%out_list(i) = 'toffset'
+  i = i+1
+  if (LparasolRefl)     cfg%out_list(i) = 'parasolRefl'
+  i = i+1
+  if (LclMISR)          cfg%out_list(i) = 'clMISR'
+  i = i+1
+  if (Lmeantbisccp)     cfg%out_list(i) = 'meantbisccp'
+  i = i+1
+  if (Lmeantbclrisccp)  cfg%out_list(i) = 'meantbclrisccp'
+  i = i+1
+  if (Lfracout)         cfg%out_list(i) = 'fracout'
+  i = i+1
+  if (LlidarBetaMol532) cfg%out_list(i) = 'lidarBetaMol532'
+  i = i+1
+  if (Ltbrttov)         cfg%out_list(i) = 'tbrttov'
+  i = i+1
+  if (Lcltmodis)        cfg%out_list(i) = 'cltmodis'
+  i = i+1
+  if (Lclwmodis)        cfg%out_list(i) = 'clwmodis'
+  i = i+1
+  if (Lclimodis)        cfg%out_list(i) = 'climodis'
+  i = i+1
+  if (Lclhmodis)        cfg%out_list(i) = 'clhmodis'
+  i = i+1
+  if (Lclmmodis)        cfg%out_list(i) = 'clmmodis'
+  i = i+1
+  if (Lcllmodis)        cfg%out_list(i) = 'cllmodis'
+  i = i+1
+  if (Ltautmodis)       cfg%out_list(i) = 'tautmodis'
+  i = i+1
+  if (Ltauwmodis)       cfg%out_list(i) = 'tauwmodis'
+  i = i+1
+  if (Ltauimodis)       cfg%out_list(i) = 'tauimodis'
+  i = i+1
+  if (Ltautlogmodis)    cfg%out_list(i) = 'tautlogmodis'
+  i = i+1
+  if (Ltauwlogmodis)    cfg%out_list(i) = 'tauwlogmodis'
+  i = i+1
+  if (Ltauilogmodis)    cfg%out_list(i) = 'tauilogmodis'
+  i = i+1
+  if (Lreffclwmodis)    cfg%out_list(i) = 'reffclwmodis'
+  i = i+1
+  if (Lreffclimodis)    cfg%out_list(i) = 'reffclimodis'
+  i = i+1
+  if (Lpctmodis)        cfg%out_list(i) = 'pctmodis'
+  i = i+1
+  if (Llwpmodis)        cfg%out_list(i) = 'lwpmodis'
+  i = i+1
+  if (Liwpmodis)        cfg%out_list(i) = 'iwpmodis'
+  i = i+1
+  if (Lclmodis)         cfg%out_list(i) = 'clmodis'
+  i = i+1
+  if (Lcrimodis)         cfg%out_list(i) = 'crimodis'
+  i = i+1
+  if (Lcrlmodis)         cfg%out_list(i) = 'crlmodis'
+
+  i = i+1                                                            !OPAQ
+  if (Lclopaquecalipso)         cfg%out_list(i) = 'clopaquecalipso'  !OPAQ
+  i = i+1                                                            !OPAQ
+  if (Lclthincalipso)           cfg%out_list(i) = 'clthincalipso'    !OPAQ
+  i = i+1                                                            !OPAQ
+  if (Lclzopaquecalipso)        cfg%out_list(i) = 'clzopaquecalipso' !OPAQ
+  i = i+1                                                            !OPAQ
+  if (Lclcalipsoopaque)         cfg%out_list(i) = 'clcalipsoopaque'  !OPAQ
+  i = i+1                                                            !OPAQ
+  if (Lclcalipsothin)           cfg%out_list(i) = 'clcalipsothin'    !OPAQ
+  i = i+1                                                            !OPAQ
+  if (Lclcalipsozopaque)        cfg%out_list(i) = 'clcalipsozopaque' !OPAQ
+  i = i+1                                                            !OPAQ
+  if (Lclcalipsoopacity)        cfg%out_list(i) = 'clcalipsoopacity' !OPAQ
+  i = i+1                                                            !TIBO
+  if (LprofSR)                  cfg%out_list(i) = 'profSR'           !TIBO
+  i = i+1                                                            !TIBO
+  if (Lproftemp)                cfg%out_list(i) = 'proftemp'         !TIBO
+    
+  if (i /= N_OUT_LIST) then
+     print *, 'COSP_IO: wrong number of output diagnostics'
+     print *, i,N_OUT_LIST
+     stop
+  endif
+
+  ! Copy diagnostic flags to cfg structure
+  ! ISCCP simulator  
+  cfg%Lalbisccp = Lalbisccp
+  cfg%Latb532 = Latb532
+  cfg%Lboxptopisccp = Lboxptopisccp
+  cfg%Lboxtauisccp = Lboxtauisccp
+  cfg%Lmeantbisccp = Lmeantbisccp
+  cfg%Lmeantbclrisccp = Lmeantbclrisccp
+  cfg%Lclisccp = Lclisccp
+  cfg%Lpctisccp = Lpctisccp
+  cfg%Ltauisccp = Ltauisccp
+  cfg%Lcltisccp = Lcltisccp
+  ! CloudSat simulator  
+  cfg%Ldbze94 = Ldbze94
+  cfg%LcfadDbze94 = LcfadDbze94
+  ! CALIPSO/PARASOL simulator  
+  cfg%LcfadLidarsr532 = LcfadLidarsr532
+  cfg%Lclcalipso2 = Lclcalipso2
+  cfg%Lclcalipso = Lclcalipso
+  cfg%Lclhcalipso = Lclhcalipso
+  cfg%Lcllcalipso = Lcllcalipso
+  cfg%Lclmcalipso = Lclmcalipso
+  cfg%Lcltcalipso = Lcltcalipso
+  cfg%Lclhcalipsoice = Lclhcalipsoice
+  cfg%Lcllcalipsoice = Lcllcalipsoice
+  cfg%Lclmcalipsoice = Lclmcalipsoice
+  cfg%Lcltcalipsoice = Lcltcalipsoice
+  cfg%Lclhcalipsoliq = Lclhcalipsoliq
+  cfg%Lcllcalipsoliq = Lcllcalipsoliq
+  cfg%Lclmcalipsoliq = Lclmcalipsoliq
+  cfg%Lcltcalipsoliq = Lcltcalipsoliq
+  cfg%Lclhcalipsoun = Lclhcalipsoun
+  cfg%Lcllcalipsoun = Lcllcalipsoun
+  cfg%Lclmcalipsoun = Lclmcalipsoun
+  cfg%Lcltcalipsoun = Lcltcalipsoun
+  cfg%Lclcalipsoice = Lclcalipsoice
+  cfg%Lclcalipsoliq = Lclcalipsoliq
+  cfg%Lclcalipsoun = Lclcalipsoun
+  cfg%Lclcalipsotmp = Lclcalipsotmp
+  cfg%Lclcalipsotmpice = Lclcalipsotmpice
+  cfg%Lclcalipsotmpliq = Lclcalipsotmpliq
+  cfg%Lclcalipsotmpun = Lclcalipsotmpun
+  cfg%Lcltlidarradar = Lcltlidarradar
+  cfg%LparasolRefl = LparasolRefl
+  cfg%Lclopaquecalipso  = Lclopaquecalipso  !OPAQ
+  cfg%Lclthincalipso    = Lclthincalipso    !OPAQ
+  cfg%Lclzopaquecalipso = Lclzopaquecalipso !OPAQ
+  cfg%Lclcalipsoopaque  = Lclcalipsoopaque  !OPAQ
+  cfg%Lclcalipsothin    = Lclcalipsothin    !OPAQ
+  cfg%Lclcalipsozopaque = Lclcalipsozopaque !OPAQ
+  cfg%Lclcalipsoopacity = Lclcalipsoopacity !OPAQ
+  cfg%LprofSR           = LprofSR           !TIBO
+  cfg%Lproftemp         = Lproftemp         !TIBO
+  ! MISR simulator  
+  cfg%LclMISR = LclMISR
+  ! Other
+  cfg%Ltoffset = Ltoffset
+  cfg%Lfracout = Lfracout
+  cfg%LlidarBetaMol532 = LlidarBetaMol532
+  ! RTTOV
+  cfg%Ltbrttov = Ltbrttov
+  ! MODIS simulator  
+  cfg%Lcltmodis=Lcltmodis
+  cfg%Lclwmodis=Lclwmodis
+  cfg%Lclimodis=Lclimodis
+  cfg%Lclhmodis=Lclhmodis
+  cfg%Lclmmodis=Lclmmodis
+  cfg%Lcllmodis=Lcllmodis
+  cfg%Ltautmodis=Ltautmodis
+  cfg%Ltauwmodis=Ltauwmodis
+  cfg%Ltauimodis=Ltauimodis
+  cfg%Ltautlogmodis=Ltautlogmodis
+  cfg%Ltauwlogmodis=Ltauwlogmodis
+  cfg%Ltauilogmodis=Ltauilogmodis
+  cfg%Lreffclwmodis=Lreffclwmodis
+  cfg%Lreffclimodis=Lreffclimodis
+  cfg%Lpctmodis=Lpctmodis
+  cfg%Llwpmodis=Llwpmodis
+  cfg%Liwpmodis=Liwpmodis
+  cfg%Lclmodis=Lclmodis
+  cfg%Lcrimodis=Lcrimodis
+  cfg%Lcrlmodis=Lcrlmodis
+  
+ END SUBROUTINE READ_COSP_OUTPUT_NL
+
+ SUBROUTINE read_xiosfieldactive(cfg)
+
+    USE MOD_COSP_CONSTANTS
+    USE MOD_COSP_TYPES
+#ifdef CPP_XIOS
+    USE xios, ONLY: xios_field_is_active
+#endif
+  implicit none
+  type(cosp_config),intent(out) :: cfg
+  integer :: i
+
+#ifdef CPP_XIOS
+
+ logical, save :: Lradar_sim,Llidar_sim,Lisccp_sim,Lmodis_sim,Lmisr_sim,Lrttov_sim, Lstats, &
+             Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,LcfadDbze94, &
+             LcfadLidarsr532,Lclcalipso2,Lclcalipso,Lclhcalipso,Lclisccp,Lcllcalipso, &
+             Lclmcalipso,Lcltcalipso,Lcltlidarradar,Lpctisccp,Ldbze94,Ltauisccp,Lcltisccp, & 
+             Lclcalipsoliq,Lclcalipsoice,Lclcalipsoun, &
+             Lclcalipsotmp,Lclcalipsotmpliq,Lclcalipsotmpice,Lclcalipsotmpun, &
+             Lcltcalipsoliq,Lcltcalipsoice,Lcltcalipsoun, &
+             Lclhcalipsoliq,Lclhcalipsoice,Lclhcalipsoun, &
+             Lclmcalipsoliq,Lclmcalipsoice,Lclmcalipsoun, &
+             Lcllcalipsoliq,Lcllcalipsoice,Lcllcalipsoun, &
+             Ltoffset,LparasolRefl,LclMISR,Lmeantbisccp,Lmeantbclrisccp, &
+             Lfracout,LlidarBetaMol532,Ltbrttov, &
+             Lcltmodis,Lclwmodis,Lclimodis,Lclhmodis,Lclmmodis,Lcllmodis, &
+             Ltautmodis,Ltauwmodis,Ltauimodis,Ltautlogmodis, &
+             Ltauwlogmodis,Ltauilogmodis,Lreffclwmodis,Lreffclimodis,Lpctmodis,Llwpmodis, & 
+             Liwpmodis,Lclmodis,Lcrimodis,Lcrlmodis,Lclopaquecalipso,Lclthincalipso, &
+             Lclzopaquecalipso,Lclcalipsoopaque,Lclcalipsothin,Lclcalipsozopaque,Lclcalipsoopacity, &
+             LprofSR,Lproftemp
+        
+!!$OMP THREADPRIVATE(Lradar_sim,Llidar_sim,Lisccp_sim,Lmodis_sim,Lmisr_sim,Lrttov_sim)
+!!$OMP THREADPRIVATE(Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,LcfadDbze94)
+!!$OMP THREADPRIVATE(LcfadLidarsr532,Lclcalipso2,Lclcalipso,Lclhcalipso,Lclisccp,Lcllcalipso)
+!!$OMP THREADPRIVATE(Lclmcalipso,Lcltcalipso,Lcltlidarradar,Lpctisccp,Ldbze94,Ltauisccp,Lcltisccp)
+!!$OMP THREADPRIVATE(Lclcalipsoliq,Lclcalipsoice,Lclcalipsoun)
+!!$OMP THREADPRIVATE(Lclcalipsotmp,Lclcalipsotmpliq,Lclcalipsotmpice,Lclcalipsotmpun)
+!!$OMP THREADPRIVATE(Lcltcalipsoliq,Lcltcalipsoice,Lcltcalipsoun)
+!!$OMP THREADPRIVATE(Lclhcalipsoliq,Lclhcalipsoice,Lclhcalipsoun)
+!!$OMP THREADPRIVATE(Lclmcalipsoliq,Lclmcalipsoice,Lclmcalipsoun)
+!!$OMP THREADPRIVATE(Lcllcalipsoliq,Lcllcalipsoice,Lcllcalipsoun)
+!!$OMP THREADPRIVATE(Ltoffset,LparasolRefl,LclMISR,Lmeantbisccp,Lmeantbclrisccp)
+!!$OMP THREADPRIVATE(Lfracout,LlidarBetaMol532,Ltbrttov)
+!!$OMP THREADPRIVATE(Lcltmodis,Lclwmodis,Lclimodis,Lclhmodis,Lclmmodis,Lcllmodis)
+!!$OMP THREADPRIVATE(Ltautmodis,Ltauwmodis,Ltauimodis,Ltautlogmodis)
+!!$OMP THREADPRIVATE(Ltauwlogmodis,Ltauilogmodis,Lreffclwmodis,Lreffclimodis,Lpctmodis,Llwpmodis)
+!!$OMP THREADPRIVATE(Liwpmodis,Lclmodis,Lcrimodis,Lcrlmodis,Lclopaquecalipso,Lclthincalipso)
+!!$OMP THREADPRIVATE(Lclzopaquecalipso,Lclcalipsoopaque,Lclcalipsothin,Lclcalipsozopaque,Lclcalipsoopacity)
+!!$OMP THREADPRIVATE(LprofSR,Lproftemp) 
+
+  character(len=32) :: out_list(N_OUT_LIST)
+
+  do i=1,N_OUT_LIST
+    cfg%out_list(i)=''
+  enddo
+
+    LcfadDbze94   = .false.
+    Lclcalipso2    = .false.
+    Lcltlidarradar = .false. ! Needs radar & lidar
+    Ldbze94        = .false.
+    Lclcalipso2    = .false. ! Needs radar & lidar
+
+    Latb532          = .false.
+    LcfadLidarsr532  = .false.
+    Lclcalipso       = .false.
+    Lclhcalipso      = .false.
+    Lcllcalipso      = .false.
+    Lclmcalipso      = .false.
+    Lcltcalipso      = .false.
+    LparasolRefl     = .false.
+    LlidarBetaMol532 = .false.
+    Lclcalipsoliq       = .false.
+    Lclcalipsoice       = .false.
+    Lclcalipsoun        = .false.
+    Lclcalipsotmp       = .false.
+    Lclcalipsotmpun     = .false.
+    Lclcalipsotmpliq    = .false.
+    Lclcalipsotmpice    = .false.
+    Lclhcalipsoliq      = .false.
+    Lcllcalipsoliq      = .false.
+    Lclmcalipsoliq      = .false.
+    Lcltcalipsoliq      = .false.
+    Lclhcalipsoice      = .false.
+    Lcllcalipsoice      = .false.
+    Lclmcalipsoice      = .false.
+    Lcltcalipsoice      = .false.
+    Lclhcalipsoun       = .false.
+    Lcllcalipsoun       = .false.
+    Lclmcalipsoun       = .false.
+    Lcltcalipsoun       = .false.
+    Lclopaquecalipso    = .false. !OPAQ
+    Lclthincalipso      = .false. !OPAQ
+    Lclzopaquecalipso   = .false. !OPAQ
+    Lclcalipsoopaque    = .false. !OPAQ
+    Lclcalipsothin      = .false. !OPAQ
+    Lclcalipsozopaque   = .false. !OPAQ
+    Lclcalipsoopacity   = .false. !OPAQ
+    LprofSR             = .false. !TIBO
+    Lproftemp           = .false. !TIBO
+
+    Lalbisccp       = .false.
+    Lboxptopisccp   = .false.
+    Lboxtauisccp    = .false.
+    Lclisccp        = .false.
+    Lpctisccp       = .false.
+    Ltauisccp       = .false.
+    Lcltisccp       = .false.
+    Lmeantbisccp    = .false.
+    Lmeantbclrisccp = .false.
+
+    LclMISR = .false.
+
+    Ltbrttov = .false.
+
+    Lcltmodis=.false.
+    Lclwmodis=.false.
+    Lclimodis=.false.
+    Lclhmodis=.false.
+    Lclmmodis=.false.
+    Lcllmodis=.false.
+    Ltautmodis=.false.
+    Ltauwmodis=.false.
+    Ltauimodis=.false.
+    Ltautlogmodis=.false.
+    Ltauwlogmodis=.false.
+    Ltauilogmodis=.false.
+    Lreffclwmodis=.false.
+    Lreffclimodis=.false.
+    Lpctmodis=.false.
+    Llwpmodis=.false.
+    Liwpmodis=.false.
+    Lclmodis=.false.
+    Lcrimodis=.false.
+    Lcrlmodis=.false.
+
+    Lradar_sim=.false.
+    Llidar_sim=.false.
+    Lisccp_sim=.false.
+    Lmodis_sim=.false.
+    Lmisr_sim=.false.
+    Lrttov_sim=.false.
+
+    Lstats=.false.
+!    Ltoffset=.false.
+!    Lfracout=.false.
+!    Lwrite_output=.false.
+
+  IF (is_master) THEN
+! VEREFIER LES CHAMPS DEMANDES DANS .XML
+! 2. Si champs active dans .xml alors mettre la cles de sortie en true
+ IF (xios_field_is_active("cllcalipso")) Lcllcalipso=.TRUE.
+ IF (xios_field_is_active("clmcalipso")) Lclmcalipso=.TRUE.
+ IF (xios_field_is_active("clhcalipso")) Lclhcalipso=.TRUE.
+ IF (xios_field_is_active("cltcalipso")) Lcltcalipso=.TRUE.
+ IF (xios_field_is_active("cllcalipsoice")) Lcllcalipsoice=.TRUE.
+ IF (xios_field_is_active("clmcalipsoice")) Lclmcalipsoice=.TRUE.
+ IF (xios_field_is_active("clhcalipsoice")) Lclhcalipsoice=.TRUE.
+ IF (xios_field_is_active("cltcalipsoice")) Lcltcalipsoice=.TRUE.
+ IF (xios_field_is_active("cllcalipsoliq")) Lcllcalipsoliq=.TRUE.
+ IF (xios_field_is_active("clmcalipsoliq")) Lclmcalipsoliq=.TRUE.
+ IF (xios_field_is_active("clhcalipsoliq")) Lclhcalipsoliq=.TRUE.
+ IF (xios_field_is_active("cltcalipsoliq")) Lcltcalipsoliq=.TRUE.
+ IF (xios_field_is_active("cllcalipsoun")) Lcllcalipsoun=.TRUE.
+ IF (xios_field_is_active("clmcalipsoun")) Lclmcalipsoun=.TRUE.
+ IF (xios_field_is_active("clhcalipsoun")) Lclhcalipsoun=.TRUE.
+ IF (xios_field_is_active("cltcalipsoun")) Lcltcalipsoun=.TRUE.
+ IF (xios_field_is_active("clcalipso")) Lclcalipso=.TRUE.
+ IF (xios_field_is_active("clcalipsoice")) Lclcalipsoice=.TRUE.
+ IF (xios_field_is_active("clcalipsoliq")) Lclcalipsoliq=.TRUE.
+ IF (xios_field_is_active("clcalipsoun")) Lclcalipsoun=.TRUE.
+ IF (xios_field_is_active("clcalipsotmp")) Lclcalipsotmp=.TRUE.
+ IF (xios_field_is_active("clcalipsotmpice")) Lclcalipsotmpice=.TRUE.
+ IF (xios_field_is_active("clcalipsotmpliq")) Lclcalipsotmpliq=.TRUE.
+ IF (xios_field_is_active("clcalipsotmpun")) Lclcalipsotmpun=.TRUE.
+ IF (xios_field_is_active("parasol_refl")) LparasolRefl=.TRUE.
+! IF (xios_field_is_active("parasol_crefl")) cfg%LparasolRefl=.TRUE.
+! IF (xios_field_is_active("Ncrefl")) cfg%LparasolRefl=.TRUE.
+ IF (xios_field_is_active("cfad_lidarsr532")) LcfadLidarsr532=.TRUE.
+ IF (xios_field_is_active("atb532")) Latb532=.TRUE.
+ IF (xios_field_is_active("beta_mol532")) LlidarBetaMol532=.TRUE.
+ IF (xios_field_is_active("clopaquecalipso")) Lclopaquecalipso=.TRUE.
+ IF (xios_field_is_active("clthincalipso")) Lclthincalipso=.TRUE.
+ IF (xios_field_is_active("clzopaquecalipso")) Lclzopaquecalipso=.TRUE.
+ IF (xios_field_is_active("clcalipsoopaque")) Lclcalipsoopaque=.TRUE.
+ IF (xios_field_is_active("clcalipsothin")) Lclcalipsothin=.TRUE.
+ IF (xios_field_is_active("clcalipsozopaque")) Lclcalipsozopaque=.TRUE.
+ IF (xios_field_is_active("clcalipsoopacity")) Lclcalipsoopacity=.TRUE.
+ IF (xios_field_is_active("proftemp")) Lproftemp=.TRUE.
+ IF (xios_field_is_active("profSR")) LprofSR=.TRUE.
+!!!! 38 champ Calipso
+
+ IF (xios_field_is_active("cfadDbze94")) LcfadDbze94=.TRUE.
+ IF (xios_field_is_active("dbze94")) Ldbze94=.TRUE.
+!!! 2 champs CLOUDSAT
+
+ IF (xios_field_is_active("cltlidarradar")) Lcltlidarradar=.TRUE.
+ IF (xios_field_is_active("clcalipso2")) Lclcalipso2=.TRUE.
+!!! 2 champs CLOUDSAT et CALIPSO
+
+ IF (xios_field_is_active("clisccp2")) Lclisccp=.TRUE.
+ IF (xios_field_is_active("boxtauisccp")) Lboxtauisccp=.TRUE.
+ IF (xios_field_is_active("boxptopisccp")) Lboxptopisccp=.TRUE.
+ IF (xios_field_is_active("tclisccp")) Lcltisccp=.TRUE.
+ IF (xios_field_is_active("ctpisccp")) Lpctisccp=.TRUE.
+ IF (xios_field_is_active("tauisccp")) Ltauisccp=.TRUE.
+ IF (xios_field_is_active("albisccp")) Lalbisccp=.TRUE.
+ IF (xios_field_is_active("meantbisccp")) Lmeantbisccp=.TRUE.
+ IF (xios_field_is_active("meantbclrisccp")) Lmeantbclrisccp=.TRUE.
+!!! 9 champs ISCCP
+
+ IF (xios_field_is_active("clMISR")) LclMISR=.TRUE.
+!!! 1 champs MISR
+
+ IF (xios_field_is_active("cllmodis")) Lcllmodis=.TRUE.
+ IF (xios_field_is_active("clmmodis")) Lclmmodis=.TRUE.
+ IF (xios_field_is_active("clhmodis")) Lclhmodis=.TRUE.
+ IF (xios_field_is_active("cltmodis")) Lcltmodis=.TRUE.
+ IF (xios_field_is_active("clwmodis")) Lclwmodis=.TRUE.
+ IF (xios_field_is_active("climodis")) Lclimodis=.TRUE.
+ IF (xios_field_is_active("tautmodis")) Ltautmodis=.TRUE.
+ IF (xios_field_is_active("tauwmodis")) Ltauwmodis=.TRUE.
+ IF (xios_field_is_active("tauimodis")) Ltauimodis=.TRUE.
+ IF (xios_field_is_active("tautlogmodis")) Ltautlogmodis=.TRUE.
+ IF (xios_field_is_active("tauilogmodis")) Ltauilogmodis=.TRUE.
+ IF (xios_field_is_active("tauwlogmodis")) Ltauwlogmodis=.TRUE.
+ IF (xios_field_is_active("reffclwmodis")) Lreffclwmodis=.TRUE.
+ IF (xios_field_is_active("reffclimodis")) Lreffclimodis=.TRUE.
+ IF (xios_field_is_active("pctmodis")) Lpctmodis=.TRUE.
+ IF (xios_field_is_active("lwpmodis")) Llwpmodis=.TRUE.
+ IF (xios_field_is_active("iwpmodis")) Liwpmodis=.TRUE.
+ IF (xios_field_is_active("clmodis")) Lclmodis=.TRUE.
+ IF (xios_field_is_active("crimodis")) Lcrimodis=.TRUE.
+ IF (xios_field_is_active("crlmodis")) Lcrlmodis=.TRUE.
+!!! 20 champs MODIS
+! IF (xios_field_is_active("tbrttov")) cfg%Ltbrttov=.TRUE.
+
+! 2.  si champs demande alors activer le simulateur correspondant
+   IF (xios_field_is_active("cllcalipso").OR. &
+       xios_field_is_active("clmcalipso").OR. &
+       xios_field_is_active("clhcalipso").OR. &
+       xios_field_is_active("cltcalipso").OR. &
+       xios_field_is_active("cllcalipsoice").OR. &
+       xios_field_is_active("clmcalipsoice").OR. &
+       xios_field_is_active("clhcalipsoice").OR. &
+       xios_field_is_active("cltcalipsoice").OR. &
+       xios_field_is_active("cllcalipsoliq").OR. &
+       xios_field_is_active("clmcalipsoliq").OR. &
+       xios_field_is_active("clhcalipsoliq").OR. &
+       xios_field_is_active("cltcalipsoliq").OR. &
+       xios_field_is_active("cllcalipsoun").OR. &
+       xios_field_is_active("clmcalipsoun").OR. &
+       xios_field_is_active("clhcalipsoun").OR. &
+       xios_field_is_active("cltcalipsoun").OR. &
+       xios_field_is_active("clcalipso").OR. &
+       xios_field_is_active("clcalipsoice").OR. &
+       xios_field_is_active("clcalipsoliq").OR. &
+       xios_field_is_active("clcalipsoun").OR. &
+       xios_field_is_active("clcalipsotmp").OR. &
+       xios_field_is_active("clcalipsotmpice").OR. &
+       xios_field_is_active("clcalipsotmpliq").OR. &
+       xios_field_is_active("clcalipsotmpun").OR. &
+       xios_field_is_active("parasol_refl").OR. &
+       xios_field_is_active("cfad_lidarsr532").OR. &
+       xios_field_is_active("atb532").OR. &
+       xios_field_is_active("beta_mol532").OR. &
+       xios_field_is_active("clopaquecalipso").OR. &
+       xios_field_is_active("clthincalipso").OR. &
+       xios_field_is_active("clzopaquecalipso").OR. &
+       xios_field_is_active("clcalipsoopaque").OR. &
+       xios_field_is_active("clcalipsothin").OR. &
+       xios_field_is_active("clcalipsozopaque").OR. &
+       xios_field_is_active("clcalipsoopacity").OR. &
+       xios_field_is_active("proftemp").OR. &
+       xios_field_is_active("profSR")) Llidar_sim=.TRUE.
+
+    IF (xios_field_is_active("cfadDbze94").OR. &
+      xios_field_is_active("dbze94")) & Lradar_sim=.TRUE.
+
+    IF (xios_field_is_active("cltlidarradar").OR. &
+      xios_field_is_active("clcalipso2")) THEN
+               Lradar_sim=.TRUE.
+               Llidar_sim=.TRUE.
+    ENDIF
+
+    IF (xios_field_is_active("clisccp2").OR. &
+       xios_field_is_active("boxtauisccp").OR. &
+       xios_field_is_active("boxptopisccp").OR. &
+       xios_field_is_active("tclisccp").OR. &
+       xios_field_is_active("ctpisccp").OR. &
+       xios_field_is_active("tauisccp").OR. &
+       xios_field_is_active("albisccp").OR. &
+       xios_field_is_active("meantbisccp").OR. &
+       xios_field_is_active("meantbclrisccp")) Lisccp_sim=.TRUE.
+
+    IF (xios_field_is_active("clMISR")) Lmisr_sim=.TRUE.
+
+    IF (xios_field_is_active("cllmodis").OR. &
+       xios_field_is_active("clmmodis").OR. &
+       xios_field_is_active("clhmodis").OR. &
+       xios_field_is_active("cltmodis").OR. &
+       xios_field_is_active("clwmodis").OR. &
+       xios_field_is_active("climodis").OR. &
+       xios_field_is_active("tautmodis").OR. &
+       xios_field_is_active("tauwmodis").OR. &
+       xios_field_is_active("tauimodis").OR. &
+       xios_field_is_active("tautlogmodis").OR. &
+       xios_field_is_active("tauilogmodis").OR. &
+       xios_field_is_active("tauwlogmodis").OR. &
+       xios_field_is_active("reffclwmodis").OR. &
+       xios_field_is_active("reffclimodis").OR. &
+       xios_field_is_active("pctmodis").OR. &
+       xios_field_is_active("lwpmodis").OR. &
+       xios_field_is_active("iwpmodis").OR. &
+       xios_field_is_active("clmodis").OR. &
+       xios_field_is_active("crimodis").OR. &
+       xios_field_is_active("crlmodis")) Lmodis_sim=.TRUE.
+
+  ENDIF !   (is_master) 
+
+  CALL bcast(Lradar_sim)
+  CALL bcast(Llidar_sim)
+  CALL bcast(Lisccp_sim)
+  CALL bcast(Lmodis_sim)
+  CALL bcast(Lmisr_sim)
+  CALL bcast(Lrttov_sim)
+
+  CALL bcast(Lstats)
+
+  CALL bcast(Lalbisccp)
+  CALL bcast(Latb532)
+  CALL bcast(Lboxptopisccp)
+  CALL bcast(Lboxtauisccp)
+  CALL bcast(LcfadDbze94)
+  CALL bcast(LcfadLidarsr532)
+  CALL bcast(Lclcalipso2)
+  CALL bcast(Lclcalipso)
+  CALL bcast(Lclhcalipso)
+  CALL bcast(Lclcalipsoliq)
+  CALL bcast(Lclcalipsoice)
+  CALL bcast(Lclcalipsoun)
+  CALL bcast(Lclcalipsotmp)
+  CALL bcast(Lclcalipsotmpliq)
+  CALL bcast(Lclcalipsotmpice)
+  CALL bcast(Lclcalipsotmpun)
+  CALL bcast(Lcltcalipsoliq)
+  CALL bcast(Lcltcalipsoice)
+  CALL bcast(Lcltcalipsoun)
+  CALL bcast(Lclhcalipsoliq)
+  CALL bcast(Lclhcalipsoice)
+  CALL bcast(Lclhcalipsoun)
+  CALL bcast(Lclmcalipsoliq)
+  CALL bcast(Lclmcalipsoice)
+  CALL bcast(Lclmcalipsoun)
+  CALL bcast(Lcllcalipsoliq)
+  CALL bcast(Lcllcalipsoice)
+  CALL bcast(Lcllcalipsoun)
+  CALL bcast(Lclisccp)
+  CALL bcast(Lcllcalipso)
+  CALL bcast(Lclmcalipso)
+  CALL bcast(Lcltcalipso)
+  CALL bcast(Lcltlidarradar)
+  CALL bcast(Lpctisccp)
+  CALL bcast(Ldbze94)
+  CALL bcast(Ltauisccp)
+  CALL bcast(Lcltisccp)
+  CALL bcast(LparasolRefl)
+  CALL bcast(LclMISR)
+  CALL bcast(Lmeantbisccp)
+  CALL bcast(Lmeantbclrisccp)
+  CALL bcast(Lfracout)
+  CALL bcast(LlidarBetaMol532)
+  CALL bcast(Lcltmodis)
+  CALL bcast(Lclwmodis)
+  CALL bcast(Lclimodis)
+  CALL bcast(Lclhmodis)
+  CALL bcast(Lclmmodis)
+  CALL bcast(Lcllmodis)
+  CALL bcast(Ltautmodis)
+  CALL bcast(Ltauwmodis)
+  CALL bcast(Ltauimodis)
+  CALL bcast(Ltautlogmodis)
+  CALL bcast(Ltauwlogmodis)
+  CALL bcast(Ltauilogmodis)
+  CALL bcast(Lreffclwmodis)
+  CALL bcast(Lreffclimodis)
+  CALL bcast(Lpctmodis)
+  CALL bcast(Llwpmodis)
+  CALL bcast(Liwpmodis)
+  CALL bcast(Lclmodis)
+  CALL bcast(Ltbrttov)
+  CALL bcast(Lcrimodis)
+  CALL bcast(Lcrlmodis)
+  CALL bcast(Lclopaquecalipso)  !OPAQ
+  CALL bcast(Lclthincalipso)    !OPAQ
+  CALL bcast(Lclzopaquecalipso) !OPAQ
+  CALL bcast(Lclcalipsoopaque)  !OPAQ
+  CALL bcast(Lclcalipsothin)    !OPAQ
+  CALL bcast(Lclcalipsozopaque) !OPAQ
+  CALL bcast(Lclcalipsoopacity) !OPAQ
+  CALL bcast(LprofSR)           !TIBO
+  CALL bcast(Lproftemp)         !TIBO
+
+!$OMP BARRIER
+
+    if ((Lradar_sim).or.(Llidar_sim).or.(Lisccp_sim)) Lstats = .true.
+!    IF (xios_field_is_active("tbrttov")) cfg%Lrttov_sim=.TRUE.
+
+  ! Copy diagnostic flags to cfg structure
+  ! ISCCP simulator  
+  cfg%Lalbisccp = Lalbisccp
+  cfg%Latb532 = Latb532
+  cfg%Lboxptopisccp = Lboxptopisccp
+  cfg%Lboxtauisccp = Lboxtauisccp
+  cfg%Lmeantbisccp = Lmeantbisccp
+  cfg%Lmeantbclrisccp = Lmeantbclrisccp
+  cfg%Lclisccp = Lclisccp
+  cfg%Lpctisccp = Lpctisccp
+  cfg%Ltauisccp = Ltauisccp
+  cfg%Lcltisccp = Lcltisccp
+
+! CloudSat simulator  
+  cfg%Ldbze94 = Ldbze94
+  cfg%LcfadDbze94 = LcfadDbze94
+
+! Cloudsat et Calipso
+  cfg%Lclcalipso2 = Lclcalipso2
+  cfg%Lcltlidarradar = Lcltlidarradar
+
+! CALIPSO/PARASOL simulator  
+  cfg%LcfadLidarsr532 = LcfadLidarsr532
+  cfg%Lclcalipso = Lclcalipso
+  cfg%Lclhcalipso = Lclhcalipso
+  cfg%Lcllcalipso = Lcllcalipso
+  cfg%Lclmcalipso = Lclmcalipso
+  cfg%Lcltcalipso = Lcltcalipso
+  cfg%Lclhcalipsoice = Lclhcalipsoice
+  cfg%Lcllcalipsoice = Lcllcalipsoice
+  cfg%Lclmcalipsoice = Lclmcalipsoice
+  cfg%Lcltcalipsoice = Lcltcalipsoice
+  cfg%Lclhcalipsoliq = Lclhcalipsoliq
+  cfg%Lcllcalipsoliq = Lcllcalipsoliq
+  cfg%Lclmcalipsoliq = Lclmcalipsoliq
+  cfg%Lcltcalipsoliq = Lcltcalipsoliq
+  cfg%Lclhcalipsoun = Lclhcalipsoun
+  cfg%Lcllcalipsoun = Lcllcalipsoun
+  cfg%Lclmcalipsoun = Lclmcalipsoun
+  cfg%Lcltcalipsoun = Lcltcalipsoun
+  cfg%Lclcalipsoice = Lclcalipsoice
+  cfg%Lclcalipsoliq = Lclcalipsoliq
+  cfg%Lclcalipsoun = Lclcalipsoun
+  cfg%Lclcalipsotmp = Lclcalipsotmp
+  cfg%Lclcalipsotmpice = Lclcalipsotmpice
+  cfg%Lclcalipsotmpliq = Lclcalipsotmpliq
+  cfg%Lclcalipsotmpun = Lclcalipsotmpun
+  cfg%LparasolRefl = LparasolRefl
+  cfg%Lclopaquecalipso  = Lclopaquecalipso  !OPAQ
+  cfg%Lclthincalipso    = Lclthincalipso    !OPAQ
+  cfg%Lclzopaquecalipso = Lclzopaquecalipso !OPAQ
+  cfg%Lclcalipsoopaque  = Lclcalipsoopaque  !OPAQ
+  cfg%Lclcalipsothin    = Lclcalipsothin    !OPAQ
+  cfg%Lclcalipsozopaque = Lclcalipsozopaque !OPAQ
+  cfg%Lclcalipsoopacity = Lclcalipsoopacity !OPAQ
+  cfg%LprofSR           = LprofSR           !TIBO
+  cfg%Lproftemp         = Lproftemp         !TIBO
+  cfg%LlidarBetaMol532 = LlidarBetaMol532
+
+! MISR simulator  
+  cfg%LclMISR = LclMISR
+
+! RTTOV
+  cfg%Ltbrttov = Ltbrttov
+
+! MODIS simulator  
+  cfg%Lcltmodis=Lcltmodis
+  cfg%Lclwmodis=Lclwmodis
+  cfg%Lclimodis=Lclimodis
+  cfg%Lclhmodis=Lclhmodis
+  cfg%Lclmmodis=Lclmmodis
+  cfg%Lcllmodis=Lcllmodis
+  cfg%Ltautmodis=Ltautmodis
+  cfg%Ltauwmodis=Ltauwmodis
+  cfg%Ltauimodis=Ltauimodis
+  cfg%Ltautlogmodis=Ltautlogmodis
+  cfg%Ltauwlogmodis=Ltauwlogmodis
+  cfg%Ltauilogmodis=Ltauilogmodis
+  cfg%Lreffclwmodis=Lreffclwmodis
+  cfg%Lreffclimodis=Lreffclimodis
+  cfg%Lpctmodis=Lpctmodis
+  cfg%Llwpmodis=Llwpmodis
+  cfg%Liwpmodis=Liwpmodis
+  cfg%Lclmodis=Lclmodis
+  cfg%Lcrimodis=Lcrimodis
+  cfg%Lcrlmodis=Lcrlmodis
+
+! Others
+!  cfg%Lwrite_output=Lwrite_output
+!  cfg%Ltoffset=Ltoffset
+!  cfg%Lfracout=Lfracout
+  cfg%Lstats = Lstats
+
+! Copy instrument flags to cfg structure
+  cfg%Lradar_sim = Lradar_sim
+  cfg%Llidar_sim = Llidar_sim
+  cfg%Lisccp_sim = Lisccp_sim
+  cfg%Lmodis_sim = Lmodis_sim
+  cfg%Lmisr_sim  = Lmisr_sim
+  cfg%Lrttov_sim = Lrttov_sim
+
+#endif
+
+  END SUBROUTINE read_xiosfieldactive
+
+END MODULE cosp_read_otputkeys
Index: LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90	(revision 3246)
+++ LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90	(revision 3247)
@@ -87,4 +87,5 @@
     USE xios, ONLY: xios_field_is_active
 #endif
+  use cosp_read_otputkeys
 
   IMPLICIT NONE
@@ -142,6 +143,4 @@
 !$OMP THREADPRIVATE(first_write)
 
-  logical, save :: ok_readxiosactive_cosp=.false.
-!$OMP THREADPRIVATE(ok_readxiosactive_cosp)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Input variables from LMDZ-GCM
   integer                         :: overlaplmdz   !  overlap type: 1=max, 2=rand, 3=max/rand ! cosp input (output lmdz)
@@ -159,4 +158,7 @@
   double precision,dimension(2)               :: d_time_bnds
   
+  real,dimension(2,SR_BINS) :: sratio_bounds
+  real,dimension(SR_BINS)   ::  sratio_ax
+
    namelist/COSP_INPUT/overlap,isccp_topheight,isccp_topheight_direction, &
               npoints_it,ncolumns,use_vgrid,nlr,csat_vgrid, &
@@ -168,5 +170,4 @@
 
 !---------------- End of declaration of variables --------------
-   
 
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -181,6 +182,11 @@
   CALL read_cosp_input
 
-! Clefs Outputs 
-  call read_cosp_output_nl(itap,cosp_output_nl,cfg)
+! Clefs Outputs initialisation
+  call cosp_outputkeys_init(cfg)
+!!!   call cosp_outputkeys_test(cfg)
+  print*,' Cles des differents simulateurs cosp a itap :',itap
+  print*,'Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lmodis_sim,Lrttov_sim,Lstats', &
+          cfg%Lradar_sim,cfg%Llidar_sim,cfg%Lisccp_sim,cfg%Lmisr_sim,cfg%Lmodis_sim, &
+          cfg%Lrttov_sim,cfg%Lstats
 
     if (overlaplmdz.ne.overlap) then
@@ -189,20 +195,20 @@
    print*,'Fin lecture Namelists, debut_cosp =',debut_cosp
 
-  print*,' Cles des differents simulateurs cosp 1er appel Cosp :'
-  print*,'Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lmodis_sim,Lrttov_sim', &
-          cfg%Lradar_sim,cfg%Llidar_sim,cfg%Lisccp_sim,cfg%Lmisr_sim,cfg%Lmodis_sim,cfg%Lrttov_sim
-
   endif ! debut_cosp
 
-!!! Ici on modifie les cles logiques selon les champs actives dans les .xml
+!!! Ici on modifie les cles logiques pour les outputs selon les champs actives dans les .xml
+  if ((itap.gt.1).and.(first_write))then
 #ifdef CPP_XIOS
- if (ok_readxiosactive_cosp) then
-  if ((itap.gt.1).and.(first_write))then
-     call read_cosp_output_nl(itap,cosp_output_nl,cfg)
-     first_write=.false.
+    call read_xiosfieldactive(cfg)
+#else
+    call read_cosp_output_nl(itap,cosp_output_nl,cfg)
+#endif
+    first_write=.false.
+
+    print*,' Cles des differents simulateurs cosp a itap :',itap
+    print*,'Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lmodis_sim,Lrttov_sim,Lstats', &
+          cfg%Lradar_sim,cfg%Llidar_sim,cfg%Lisccp_sim,cfg%Lmisr_sim,cfg%Lmodis_sim, &
+          cfg%Lrttov_sim,cfg%Lstats
   endif
- endif
-#endif
-
 
   time_bnds(1) = dtime-dtime/2.
@@ -212,7 +218,4 @@
   d_dtime=dtime
 
-
-!  print*,'Debut phys_cosp itap,dtime,freq_cosp,ecrit_mth,ecrit_day,ecrit_hf ', &
-!          itap,dtime,freq_cosp,ecrit_mth,ecrit_day,ecrit_hf
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ! Allocate memory for gridbox type
@@ -221,11 +224,4 @@
 !        print *, 'Allocating memory for gridbox type...'
 
-!! AI
-!        call construct_cosp_gridbox(dble(itap),radar_freq,surface_radar,use_mie_tables,use_gas_abs,do_ray,melt_lay,k2, &
-!                                    Npoints,Nlevels,Ncolumns,N_HYDRO,Nprmts_max_hydro,Naero,Nprmts_max_aero,Npoints_it, &
-!                                    lidar_ice_type,isccp_topheight,isccp_topheight_direction,overlap,emsfc_lw, &
-!                                    use_precipitation_fluxes,use_reff, &
-!                                    Platform,Satellite,Instrument,Nchannels,ZenAng, &
-!                                    channels(1:Nchannels),surfem(1:Nchannels),co2,ch4,n2o,co,gbx)
 ! Surafce emissivity
         emsfc_lw = 1.
@@ -347,8 +343,8 @@
 
 !+++++++++++++ Open output files and define output files axis !+++++++++++++
-     if (debut_cosp) then
+    if (debut_cosp) then
 
       !$OMP MASTER
-        print *, ' Open outpts files and define axis'
+!        print *, ' Open outpts files and define axis'
         call cosp_output_open(Nlevlmdz, Ncolumns, presnivs, dtime, freq_cosp, &
                               ok_mensuelCOSP, ok_journeCOSP, ok_hfCOSP, ok_all_xml, &
@@ -357,5 +353,6 @@
       !$OMP BARRIER
         debut_cosp=.false.
-      endif ! debut_cosp
+!      endif ! debut_cosp
+    else
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
         ! Call simulator
@@ -370,5 +367,4 @@
 !#endif
 !!
-
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
@@ -379,9 +375,9 @@
                                cfg, gbx, vgrid, sglidar, sgradar, stlidar, stradar, & 
                                isccp, misr, modis)
-
+    endif !debut_cosp
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
         ! Deallocate memory in derived types
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-!        print *, 'Deallocating memory...'
+        print *, 'Deallocating memory...'
         call free_cosp_gridbox(gbx)
         call free_cosp_subgrid(sgx)
Index: LMDZ6/trunk/libf/phylmd/cosp/read_cosp_output_nl.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/read_cosp_output_nl.F90	(revision 3246)
+++ 	(revision )
@@ -1,716 +1,0 @@
-!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-!--------------- SUBROUTINE READ_COSP_OUTPUT_NL -------------------------
-!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- SUBROUTINE READ_COSP_OUTPUT_NL(itap,cosp_nl,cfg)
-  USE MOD_COSP_CONSTANTS
-  USE MOD_COSP_TYPES
-  USE mod_phys_lmdz_para
-
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_field_is_active
-#endif
-  implicit none
-  character(len=*),intent(in) :: cosp_nl
-  type(cosp_config),intent(out) :: cfg
-  ! Local variables
-  integer :: i, itap
-
-!! AI 
-!  logical, save ::   Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lrttov_sim, &
-!             Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,Lcfad_dbze94, &
-!             Lcfad_lidarsr532,Lclcalipso2,Lclcalipso,Lclhcalipso,Lclisccp2,Lcllcalipso, &
-!             Lclmcalipso,Lcltcalipso,Lcltlidarradar,Lctpisccp,Ldbze94,Ltauisccp,Ltclisccp, &
-!             Llongitude,Llatitude,Lparasol_refl,LclMISR,Lmeantbisccp,Lmeantbclrisccp, &
-!             Lfrac_out,Lbeta_mol532,Ltbrttov
-
-!  namelist/COSP_OUTPUT/Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lrttov_sim, &
-!             Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,Lcfad_dbze94, &
-!             Lcfad_lidarsr532,Lclcalipso2,Lclcalipso,Lclhcalipso,Lclisccp2, &
-!             Lcllcalipso,Lclmcalipso,Lcltcalipso,Lcltlidarradar,Lctpisccp,Ldbze94,Ltauisccp, &
-!             Ltclisccp,Llongitude,Llatitude,Lparasol_refl,LclMISR,Lmeantbisccp,Lmeantbclrisccp, &
-!             Lfrac_out,Lbeta_mol532,Ltbrttov
-!!
-
- logical, save :: Lradar_sim,Llidar_sim,Lisccp_sim,Lmodis_sim,Lmisr_sim,Lrttov_sim, &
-             Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,LcfadDbze94, &
-             LcfadLidarsr532,Lclcalipso2,Lclcalipso,Lclhcalipso,Lclisccp,Lcllcalipso, &
-             Lclmcalipso,Lcltcalipso,Lcltlidarradar,Lpctisccp,Ldbze94,Ltauisccp,Lcltisccp, &
-             Lclcalipsoliq,Lclcalipsoice,Lclcalipsoun, &
-             Lclcalipsotmp,Lclcalipsotmpliq,Lclcalipsotmpice,Lclcalipsotmpun, &
-             Lcltcalipsoliq,Lcltcalipsoice,Lcltcalipsoun, &
-             Lclhcalipsoliq,Lclhcalipsoice,Lclhcalipsoun, &
-             Lclmcalipsoliq,Lclmcalipsoice,Lclmcalipsoun, &
-             Lcllcalipsoliq,Lcllcalipsoice,Lcllcalipsoun, &
-             Ltoffset,LparasolRefl,LclMISR,Lmeantbisccp,Lmeantbclrisccp, &
-             Lfracout,LlidarBetaMol532,Ltbrttov, &
-             Lcltmodis,Lclwmodis,Lclimodis,Lclhmodis,Lclmmodis,Lcllmodis,Ltautmodis,Ltauwmodis,Ltauimodis,Ltautlogmodis, &
-             Ltauwlogmodis,Ltauilogmodis,Lreffclwmodis,Lreffclimodis,Lpctmodis,Llwpmodis, &
-             Liwpmodis,Lclmodis,Lcrimodis,Lcrlmodis,Lclopaquecalipso,Lclthincalipso,      &           !OPAQ (2)
-             Lclzopaquecalipso,Lclcalipsoopaque,Lclcalipsothin,Lclcalipsozopaque,Lclcalipsoopacity, & !OPAQ (5)
-             LprofSR,Lproftemp                                                                        !TIBO (2)
-
-  namelist/COSP_OUTPUT/Lradar_sim,Llidar_sim,Lisccp_sim,Lmodis_sim,Lmisr_sim,Lrttov_sim, &
-             Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,LcfadDbze94, &
-             LcfadLidarsr532,Lclcalipso2,Lclcalipso,Lclhcalipso,Lclisccp, &
-             Lcllcalipso,Lclmcalipso,Lcltcalipso,Lcltlidarradar,Lpctisccp,Ldbze94,Ltauisccp, &
-             Lclcalipsoliq,Lclcalipsoice,Lclcalipsoun, &
-             Lclcalipsotmp,Lclcalipsotmpliq,Lclcalipsotmpice,Lclcalipsotmpun, &
-             Lcltcalipsoliq,Lcltcalipsoice,Lcltcalipsoun, &
-             Lclhcalipsoliq,Lclhcalipsoice,Lclhcalipsoun, &
-             Lclmcalipsoliq,Lclmcalipsoice,Lclmcalipsoun, &
-             Lcllcalipsoliq,Lcllcalipsoice,Lcllcalipsoun, &
-             Lcltisccp,Ltoffset,LparasolRefl,LclMISR,Lmeantbisccp,Lmeantbclrisccp, &
-             Lfracout,LlidarBetaMol532,Ltbrttov, &
-             Lcltmodis,Lclwmodis,Lclimodis,Lclhmodis,Lclmmodis,Lcllmodis,Ltautmodis,Ltauwmodis,Ltauimodis,Ltautlogmodis, &
-             Ltauwlogmodis,Ltauilogmodis,Lreffclwmodis,Lreffclimodis,Lpctmodis,Llwpmodis, &
-             Liwpmodis,Lclmodis,Lcrimodis,Lcrlmodis,Lclopaquecalipso,Lclthincalipso,      &           !OPAQ (2)
-             Lclzopaquecalipso,Lclcalipsoopaque,Lclcalipsothin,Lclcalipsozopaque,Lclcalipsoopacity, & !OPAQ (5)
-             LprofSR,Lproftemp                                                                        !TIBO (2)
-   
-  do i=1,N_OUT_LIST
-    cfg%out_list(i)=''
-  enddo
-  
-! Lecture du fichier namelist
-  IF (is_master) THEN
-    open(10,file=cosp_nl,status='old')
-    read(10,nml=cosp_output)
-    close(10)
-  ENDIF
-  
-  CALL bcast(Lradar_sim)
-  CALL bcast(Llidar_sim)
-  CALL bcast(Lisccp_sim)
-  CALL bcast(Lmodis_sim)
-  CALL bcast(Lmisr_sim)
-  CALL bcast(Lrttov_sim)
-
-  CALL bcast(Lalbisccp)
-  CALL bcast(Latb532)
-  CALL bcast(Lboxptopisccp)
-  CALL bcast(Lboxtauisccp)
-  CALL bcast(LcfadDbze94)
-  CALL bcast(LcfadLidarsr532)
-  CALL bcast(Lclcalipso2)
-  CALL bcast(Lclcalipso)
-  CALL bcast(Lclhcalipso)
-  CALL bcast(Lclcalipsoliq)
-  CALL bcast(Lclcalipsoice)
-  CALL bcast(Lclcalipsoun)
-  CALL bcast(Lclcalipsotmp)
-  CALL bcast(Lclcalipsotmpliq)
-  CALL bcast(Lclcalipsotmpice)
-  CALL bcast(Lclcalipsotmpun)
-  CALL bcast(Lcltcalipsoliq)
-  CALL bcast(Lcltcalipsoice)
-  CALL bcast(Lcltcalipsoun)
-  CALL bcast(Lclhcalipsoliq)
-  CALL bcast(Lclhcalipsoice)
-  CALL bcast(Lclhcalipsoun)
-  CALL bcast(Lclmcalipsoliq)
-  CALL bcast(Lclmcalipsoice)
-  CALL bcast(Lclmcalipsoun)
-  CALL bcast(Lcllcalipsoliq)
-  CALL bcast(Lcllcalipsoice) 
-  CALL bcast(Lcllcalipsoun)
-  CALL bcast(Lclisccp)
-  CALL bcast(Lcllcalipso)
-  CALL bcast(Lclmcalipso)
-  CALL bcast(Lcltcalipso)
-  CALL bcast(Lcltlidarradar)
-  CALL bcast(Lpctisccp)
-  CALL bcast(Ldbze94)
-  CALL bcast(Ltauisccp)
-  CALL bcast(Lcltisccp)
-  CALL bcast(LparasolRefl)
-  CALL bcast(LclMISR)
-  CALL bcast(Lmeantbisccp)
-  CALL bcast(Lmeantbclrisccp)
-  CALL bcast(Lfracout)
-  CALL bcast(LlidarBetaMol532)
-  CALL bcast(Lcltmodis)
-  CALL bcast(Lclwmodis)
-  CALL bcast(Lclimodis) 
-  CALL bcast(Lclhmodis)
-  CALL bcast(Lclmmodis)
-  CALL bcast(Lcllmodis)
-  CALL bcast(Ltautmodis)
-  CALL bcast(Ltauwmodis)
-  CALL bcast(Ltauimodis)
-  CALL bcast(Ltautlogmodis)
-  CALL bcast(Ltauwlogmodis)
-  CALL bcast(Ltauilogmodis)
-  CALL bcast(Lreffclwmodis)
-  CALL bcast(Lreffclimodis)
-  CALL bcast(Lpctmodis)
-  CALL bcast(Llwpmodis)
-  CALL bcast(Liwpmodis)
-  CALL bcast(Lclmodis)
-  CALL bcast(Ltbrttov)
-  CALL bcast(Lcrimodis)
-  CALL bcast(Lcrlmodis)
-  CALL bcast(Lclopaquecalipso)  !OPAQ
-  CALL bcast(Lclthincalipso)    !OPAQ
-  CALL bcast(Lclzopaquecalipso) !OPAQ
-  CALL bcast(Lclcalipsoopaque)  !OPAQ
-  CALL bcast(Lclcalipsothin)    !OPAQ
-  CALL bcast(Lclcalipsozopaque) !OPAQ
-  CALL bcast(Lclcalipsoopacity) !OPAQ
-  CALL bcast(LprofSR)           !TIBO
-  CALL bcast(Lproftemp)         !TIBO
-
-!$OMP BARRIER
-
-!  print*,' Cles sorties cosp :'
-!  print*,' Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lrttov_sim', &
-!           Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lrttov_sim
-
-
-  ! Deal with dependencies
-  if (.not.Lradar_sim) then
-    LcfadDbze94   = .false.
-    Lclcalipso2    = .false.
-    Lcltlidarradar = .false. ! Needs radar & lidar
-    Ldbze94        = .false.
-    Lclcalipso2    = .false. ! Needs radar & lidar
-  endif
-
-  if (.not.Llidar_sim) then
-    Latb532          = .false.
-    LcfadLidarsr532  = .false.
-    Lclcalipso2      = .false.
-    Lclcalipso       = .false.
-    Lclhcalipso      = .false.
-    Lcllcalipso      = .false.
-    Lclmcalipso      = .false.
-    Lcltcalipso      = .false.
-    Lcltlidarradar   = .false. ! Needs radar & lidar
-    LparasolRefl     = .false.
-    LlidarBetaMol532 = .false.
-!! AI
-    Lclcalipsoliq       = .false.
-    Lclcalipsoice       = .false.
-    Lclcalipsoun        = .false.
-    Lclcalipsotmp       = .false.
-    Lclcalipsotmpun     = .false.
-    Lclcalipsotmpliq    = .false.
-    Lclcalipsotmpice    = .false.
-    Lclhcalipsoliq      = .false.
-    Lcllcalipsoliq      = .false.
-    Lclmcalipsoliq      = .false.
-    Lcltcalipsoliq      = .false.
-    Lclhcalipsoice      = .false.
-    Lcllcalipsoice      = .false.
-    Lclmcalipsoice      = .false.
-    Lcltcalipsoice      = .false.
-    Lclhcalipsoun       = .false.
-    Lcllcalipsoun       = .false.
-    Lclmcalipsoun       = .false.
-    Lcltcalipsoun       = .false.
-    Lclopaquecalipso    = .false. !OPAQ
-    Lclthincalipso      = .false. !OPAQ
-    Lclzopaquecalipso   = .false. !OPAQ
-    Lclcalipsoopaque    = .false. !OPAQ
-    Lclcalipsothin      = .false. !OPAQ
-    Lclcalipsozopaque   = .false. !OPAQ
-    Lclcalipsoopacity   = .false. !OPAQ
-    LprofSR             = .false. !TIBO
-    Lproftemp           = .false. !TIBO
-  endif
-
-  if (.not.Lisccp_sim) then
-    Lalbisccp       = .false.
-    Lboxptopisccp   = .false.
-    Lboxtauisccp    = .false.
-    Lclisccp        = .false.
-    Lpctisccp       = .false.
-    Ltauisccp       = .false.
-    Lcltisccp       = .false.
-    Lmeantbisccp    = .false.
-    Lmeantbclrisccp = .false.
-  endif
-
-  if (.not.Lmisr_sim) then
-    LclMISR = .false.
-  endif
-  if (.not.Lrttov_sim) then
-    Ltbrttov = .false.
-  endif
-  if ((.not.Lradar_sim).and.(.not.Llidar_sim).and. &
-      (.not.Lisccp_sim).and.(.not.Lmisr_sim)) then
-    Lfracout = .false.
-  endif
- if (.not.Lmodis_sim) then
-    Lcltmodis=.false.
-    Lclwmodis=.false.
-    Lclimodis=.false.
-    Lclhmodis=.false.
-    Lclmmodis=.false.
-    Lcllmodis=.false.
-    Ltautmodis=.false.
-    Ltauwmodis=.false.
-    Ltauimodis=.false.
-    Ltautlogmodis=.false.
-    Ltauwlogmodis=.false.
-    Ltauilogmodis=.false.
-    Lreffclwmodis=.false.
-    Lreffclimodis=.false.
-    Lpctmodis=.false.
-    Llwpmodis=.false.
-    Liwpmodis=.false.
-    Lclmodis=.false.
-    Lcrimodis=.false.
-    Lcrlmodis=.false.
-  endif
-  if (Lmodis_sim) Lisccp_sim = .true.
-
-  ! Diagnostics that use Radar and Lidar
-  if (((Lclcalipso2).or.(Lcltlidarradar)).and.((Lradar_sim).or.(Llidar_sim))) then
-    Lclcalipso2    = .true.
-    Lcltlidarradar = .true.
-    Llidar_sim     = .true.
-    Lradar_sim     = .true.
-  endif
-
-  cfg%Lstats = .false.
-  if ((Lradar_sim).or.(Llidar_sim).or.(Lisccp_sim)) cfg%Lstats = .true.
-
-  ! Copy instrument flags to cfg structure
-  cfg%Lradar_sim = Lradar_sim
-  cfg%Llidar_sim = Llidar_sim
-  cfg%Lisccp_sim = Lisccp_sim
-  cfg%Lmodis_sim = Lmodis_sim
-  cfg%Lmisr_sim  = Lmisr_sim
-  cfg%Lrttov_sim = Lrttov_sim
-
-  ! Flag to control output to file
-  cfg%Lwrite_output = .false.
-  if (cfg%Lstats.or.cfg%Lmisr_sim.or.cfg%Lrttov_sim) then
-    cfg%Lwrite_output = .true.
-  endif
-
-  ! Output diagnostics
-  i = 1
-  if (Lalbisccp)        cfg%out_list(i) = 'albisccp'
-  i = i+1
-  if (Latb532)          cfg%out_list(i) = 'atb532'
-  i = i+1
-  if (Lboxptopisccp)    cfg%out_list(i) = 'boxptopisccp'
-  i = i+1
-  if (Lboxtauisccp)     cfg%out_list(i) = 'boxtauisccp'
-  i = i+1
-  if (LcfadDbze94)      cfg%out_list(i) = 'cfadDbze94'
-  i = i+1
-  if (LcfadLidarsr532)  cfg%out_list(i) = 'cfadLidarsr532'
-  i = i+1
-  if (Lclcalipso2)      cfg%out_list(i) = 'clcalipso2'
-  i = i+1
-  if (Lclcalipso)       cfg%out_list(i) = 'clcalipso'
-  i = i+1
-  if (Lclhcalipso)      cfg%out_list(i) = 'clhcalipso'
-  i = i+1
-  if (Lclisccp)         cfg%out_list(i) = 'clisccp'
-  i = i+1
-  if (Lcllcalipso)      cfg%out_list(i) = 'cllcalipso'
-  i = i+1
-  if (Lclmcalipso)      cfg%out_list(i) = 'clmcalipso'
-  i = i+1
-  if (Lcltcalipso)      cfg%out_list(i) = 'cltcalipso'
-  i = i+1
-
-  if (Lcllcalipsoice)      cfg%out_list(i) = 'cllcalipsoice'
-  i = i+1
-  if (Lclmcalipsoice)      cfg%out_list(i) = 'clmcalipsoice'
-  i = i+1
-  if (Lclhcalipsoice)      cfg%out_list(i) = 'clhcalipsoice'
-  i = i+1
-  if (Lcltcalipsoice)      cfg%out_list(i) = 'cltcalipsoice'
-  i = i+1
-  if (Lcllcalipsoliq)      cfg%out_list(i) = 'cllcalipsoliq'
-  i = i+1
-  if (Lclmcalipsoliq)      cfg%out_list(i) = 'clmcalipsoliq'
-  i = i+1
-  if (Lclhcalipsoliq)      cfg%out_list(i) = 'clhcalipsoliq'
-  i = i+1
-  if (Lcltcalipsoliq)      cfg%out_list(i) = 'cltcalipsoliq'
-  i = i+1
-  if (Lcllcalipsoun)      cfg%out_list(i) = 'cllcalipsoun'
-  i = i+1
-  if (Lclmcalipsoun)      cfg%out_list(i) = 'clmcalipsoun'
-  i = i+1
-  if (Lclhcalipsoun)      cfg%out_list(i) = 'clhcalipsoun'
-  i = i+1
-  if (Lcltcalipsoun)      cfg%out_list(i) = 'cltcalipsoun'
-  i = i+1
-
-  if (Lclcalipsoice)       cfg%out_list(i) = 'clcalipsoice'
-  i = i+1
-  if (Lclcalipsoliq)       cfg%out_list(i) = 'clcalipsoliq'
-  i = i+1
-  if (Lclcalipsoun)       cfg%out_list(i) = 'clcalipsoun'
-  i = i+1
-
-  if (Lclcalipsotmp)       cfg%out_list(i) = 'clcalipsotmp'
-  i = i+1
-  if (Lclcalipsotmpice)       cfg%out_list(i) = 'clcalipsotmpice'
-  i = i+1
-  if (Lclcalipsotmpliq)       cfg%out_list(i) = 'clcalipsotmpliq'
-  i = i+1
-  if (Lclcalipsotmpun)       cfg%out_list(i) = 'clcalipsotmpun'
-  i = i+1
-  if (Lcltlidarradar)   cfg%out_list(i) = 'cltlidarradar'
-  i = i+1
-  if (Lpctisccp)        cfg%out_list(i) = 'pctisccp'
-  i = i+1
-  if (Ldbze94)          cfg%out_list(i) = 'dbze94'
-  i = i+1
-  if (Ltauisccp)        cfg%out_list(i) = 'tauisccp'
-  i = i+1
-  if (Lcltisccp)        cfg%out_list(i) = 'cltisccp'
-  i = i+1
-  if (Ltoffset)         cfg%out_list(i) = 'toffset'
-  i = i+1
-  if (LparasolRefl)     cfg%out_list(i) = 'parasolRefl'
-  i = i+1
-  if (LclMISR)          cfg%out_list(i) = 'clMISR'
-  i = i+1
-  if (Lmeantbisccp)     cfg%out_list(i) = 'meantbisccp'
-  i = i+1
-  if (Lmeantbclrisccp)  cfg%out_list(i) = 'meantbclrisccp'
-  i = i+1
-  if (Lfracout)         cfg%out_list(i) = 'fracout'
-  i = i+1
-  if (LlidarBetaMol532) cfg%out_list(i) = 'lidarBetaMol532'
-  i = i+1
-  if (Ltbrttov)         cfg%out_list(i) = 'tbrttov'
-  i = i+1
-  if (Lcltmodis)        cfg%out_list(i) = 'cltmodis'
-  i = i+1
-  if (Lclwmodis)        cfg%out_list(i) = 'clwmodis'
-  i = i+1
-  if (Lclimodis)        cfg%out_list(i) = 'climodis'
-  i = i+1
-  if (Lclhmodis)        cfg%out_list(i) = 'clhmodis'
-  i = i+1
-  if (Lclmmodis)        cfg%out_list(i) = 'clmmodis'
-  i = i+1
-  if (Lcllmodis)        cfg%out_list(i) = 'cllmodis'
-  i = i+1
-  if (Ltautmodis)       cfg%out_list(i) = 'tautmodis'
-  i = i+1
-  if (Ltauwmodis)       cfg%out_list(i) = 'tauwmodis'
-  i = i+1
-  if (Ltauimodis)       cfg%out_list(i) = 'tauimodis'
-  i = i+1
-  if (Ltautlogmodis)    cfg%out_list(i) = 'tautlogmodis'
-  i = i+1
-  if (Ltauwlogmodis)    cfg%out_list(i) = 'tauwlogmodis'
-  i = i+1
-  if (Ltauilogmodis)    cfg%out_list(i) = 'tauilogmodis'
-  i = i+1
-  if (Lreffclwmodis)    cfg%out_list(i) = 'reffclwmodis'
-  i = i+1
-  if (Lreffclimodis)    cfg%out_list(i) = 'reffclimodis'
-  i = i+1
-  if (Lpctmodis)        cfg%out_list(i) = 'pctmodis'
-  i = i+1
-  if (Llwpmodis)        cfg%out_list(i) = 'lwpmodis'
-  i = i+1
-  if (Liwpmodis)        cfg%out_list(i) = 'iwpmodis'
-  i = i+1
-  if (Lclmodis)         cfg%out_list(i) = 'clmodis'
-  i = i+1
-  if (Lcrimodis)         cfg%out_list(i) = 'crimodis'
-  i = i+1
-  if (Lcrlmodis)         cfg%out_list(i) = 'crlmodis'
-
-  i = i+1                                                            !OPAQ
-  if (Lclopaquecalipso)         cfg%out_list(i) = 'clopaquecalipso'  !OPAQ
-  i = i+1                                                            !OPAQ
-  if (Lclthincalipso)           cfg%out_list(i) = 'clthincalipso'    !OPAQ
-  i = i+1                                                            !OPAQ
-  if (Lclzopaquecalipso)        cfg%out_list(i) = 'clzopaquecalipso' !OPAQ
-  i = i+1                                                            !OPAQ
-  if (Lclcalipsoopaque)         cfg%out_list(i) = 'clcalipsoopaque'  !OPAQ
-  i = i+1                                                            !OPAQ
-  if (Lclcalipsothin)           cfg%out_list(i) = 'clcalipsothin'    !OPAQ
-  i = i+1                                                            !OPAQ
-  if (Lclcalipsozopaque)        cfg%out_list(i) = 'clcalipsozopaque' !OPAQ
-  i = i+1                                                            !OPAQ
-  if (Lclcalipsoopacity)        cfg%out_list(i) = 'clcalipsoopacity' !OPAQ
-  i = i+1                                                            !TIBO
-  if (LprofSR)                  cfg%out_list(i) = 'profSR'           !TIBO
-  i = i+1                                                            !TIBO
-  if (Lproftemp)                cfg%out_list(i) = 'proftemp'         !TIBO
-    
-  if (i /= N_OUT_LIST) then
-     print *, 'COSP_IO: wrong number of output diagnostics'
-     print *, i,N_OUT_LIST
-     stop
-  endif
-
-  ! Copy diagnostic flags to cfg structure
-  ! ISCCP simulator  
-  cfg%Lalbisccp = Lalbisccp
-  cfg%Latb532 = Latb532
-  cfg%Lboxptopisccp = Lboxptopisccp
-  cfg%Lboxtauisccp = Lboxtauisccp
-  cfg%Lmeantbisccp = Lmeantbisccp
-  cfg%Lmeantbclrisccp = Lmeantbclrisccp
-  cfg%Lclisccp = Lclisccp
-  cfg%Lpctisccp = Lpctisccp
-  cfg%Ltauisccp = Ltauisccp
-  cfg%Lcltisccp = Lcltisccp
-  ! CloudSat simulator  
-  cfg%Ldbze94 = Ldbze94
-  cfg%LcfadDbze94 = LcfadDbze94
-  ! CALIPSO/PARASOL simulator  
-  cfg%LcfadLidarsr532 = LcfadLidarsr532
-  cfg%Lclcalipso2 = Lclcalipso2
-  cfg%Lclcalipso = Lclcalipso
-  cfg%Lclhcalipso = Lclhcalipso
-  cfg%Lcllcalipso = Lcllcalipso
-  cfg%Lclmcalipso = Lclmcalipso
-  cfg%Lcltcalipso = Lcltcalipso
-  cfg%Lclhcalipsoice = Lclhcalipsoice
-  cfg%Lcllcalipsoice = Lcllcalipsoice
-  cfg%Lclmcalipsoice = Lclmcalipsoice
-  cfg%Lcltcalipsoice = Lcltcalipsoice
-  cfg%Lclhcalipsoliq = Lclhcalipsoliq
-  cfg%Lcllcalipsoliq = Lcllcalipsoliq
-  cfg%Lclmcalipsoliq = Lclmcalipsoliq
-  cfg%Lcltcalipsoliq = Lcltcalipsoliq
-  cfg%Lclhcalipsoun = Lclhcalipsoun
-  cfg%Lcllcalipsoun = Lcllcalipsoun
-  cfg%Lclmcalipsoun = Lclmcalipsoun
-  cfg%Lcltcalipsoun = Lcltcalipsoun
-  cfg%Lclcalipsoice = Lclcalipsoice
-  cfg%Lclcalipsoliq = Lclcalipsoliq
-  cfg%Lclcalipsoun = Lclcalipsoun
-  cfg%Lclcalipsotmp = Lclcalipsotmp
-  cfg%Lclcalipsotmpice = Lclcalipsotmpice
-  cfg%Lclcalipsotmpliq = Lclcalipsotmpliq
-  cfg%Lclcalipsotmpun = Lclcalipsotmpun
-  cfg%Lcltlidarradar = Lcltlidarradar
-  cfg%LparasolRefl = LparasolRefl
-  cfg%Lclopaquecalipso  = Lclopaquecalipso  !OPAQ
-  cfg%Lclthincalipso    = Lclthincalipso    !OPAQ
-  cfg%Lclzopaquecalipso = Lclzopaquecalipso !OPAQ
-  cfg%Lclcalipsoopaque  = Lclcalipsoopaque  !OPAQ
-  cfg%Lclcalipsothin    = Lclcalipsothin    !OPAQ
-  cfg%Lclcalipsozopaque = Lclcalipsozopaque !OPAQ
-  cfg%Lclcalipsoopacity = Lclcalipsoopacity !OPAQ
-  cfg%LprofSR           = LprofSR           !TIBO
-  cfg%Lproftemp         = Lproftemp         !TIBO
-  ! MISR simulator  
-  cfg%LclMISR = LclMISR
-  ! Other
-  cfg%Ltoffset = Ltoffset
-  cfg%Lfracout = Lfracout
-  cfg%LlidarBetaMol532 = LlidarBetaMol532
-  ! RTTOV
-  cfg%Ltbrttov = Ltbrttov
-  ! MODIS simulator  
-  cfg%Lcltmodis=Lcltmodis
-  cfg%Lclwmodis=Lclwmodis
-  cfg%Lclimodis=Lclimodis
-  cfg%Lclhmodis=Lclhmodis
-  cfg%Lclmmodis=Lclmmodis
-  cfg%Lcllmodis=Lcllmodis
-  cfg%Ltautmodis=Ltautmodis
-  cfg%Ltauwmodis=Ltauwmodis
-  cfg%Ltauimodis=Ltauimodis
-  cfg%Ltautlogmodis=Ltautlogmodis
-  cfg%Ltauwlogmodis=Ltauwlogmodis
-  cfg%Ltauilogmodis=Ltauilogmodis
-  cfg%Lreffclwmodis=Lreffclwmodis
-  cfg%Lreffclimodis=Lreffclimodis
-  cfg%Lpctmodis=Lpctmodis
-  cfg%Llwpmodis=Llwpmodis
-  cfg%Liwpmodis=Liwpmodis
-  cfg%Lclmodis=Lclmodis
-  cfg%Lcrimodis=Lcrimodis
-  cfg%Lcrlmodis=Lcrlmodis
-  
-#ifdef CPP_XIOS
- if (itap.gt.1) then
-
-! VEREFIER LES CHAMPS DEMANDES DANS .XML
-! 2. Si champs active dans .xml alors mettre la cles de sortie en true
- IF (xios_field_is_active("cllcalipso")) cfg%Lcllcalipso=.TRUE.
- IF (xios_field_is_active("clmcalipso")) cfg%Lclmcalipso=.TRUE.
- IF (xios_field_is_active("clhcalipso")) cfg%Lclhcalipso=.TRUE.
- IF (xios_field_is_active("cltcalipso")) cfg%Lcltcalipso=.TRUE.
-! IF (xios_field_is_active("pcllcalipso")) cfg%Lcllcalipso=.TRUE.
-! IF (xios_field_is_active("pclmcalipso")) cfg%Lclmcalipso=.TRUE.
-! IF (xios_field_is_active("pclhcalipso")) cfg%Lclhcalipso=.TRUE.
-! IF (xios_field_is_active("pcltcalipso")) cfg%Lcltcalipso=.TRUE.
- IF (xios_field_is_active("cllcalipsoice")) cfg%Lcllcalipsoice=.TRUE.
- IF (xios_field_is_active("clmcalipsoice")) cfg%Lclmcalipsoice=.TRUE.
- IF (xios_field_is_active("clhcalipsoice")) cfg%Lclhcalipsoice=.TRUE.
- IF (xios_field_is_active("cltcalipsoice")) cfg%Lcltcalipsoice=.TRUE.
- IF (xios_field_is_active("cllcalipsoliq")) cfg%Lcllcalipsoliq=.TRUE.
- IF (xios_field_is_active("clmcalipsoliq")) cfg%Lclmcalipsoliq=.TRUE.
- IF (xios_field_is_active("clhcalipsoliq")) cfg%Lclhcalipsoliq=.TRUE.
- IF (xios_field_is_active("cltcalipsoliq")) cfg%Lcltcalipsoliq=.TRUE.
- IF (xios_field_is_active("cllcalipsoun")) cfg%Lcllcalipsoun=.TRUE.
- IF (xios_field_is_active("clmcalipsoun")) cfg%Lclmcalipsoun=.TRUE.
- IF (xios_field_is_active("clhcalipsoun")) cfg%Lclhcalipsoun=.TRUE.
- IF (xios_field_is_active("cltcalipsoun")) cfg%Lcltcalipsoun=.TRUE.
- IF (xios_field_is_active("clcalipso")) cfg%Lclcalipso=.TRUE.
-! IF (xios_field_is_active("pclcalipso")) cfg%Lclcalipso=.TRUE.
- IF (xios_field_is_active("clcalipsoice")) cfg%Lclcalipsoice=.TRUE.
- IF (xios_field_is_active("clcalipsoliq")) cfg%Lclcalipsoliq=.TRUE.
- IF (xios_field_is_active("clcalipsoun")) cfg%Lclcalipsoun=.TRUE.
- IF (xios_field_is_active("clcalipsotmp")) cfg%Lclcalipsotmp=.TRUE.
- IF (xios_field_is_active("clcalipsotmpice")) cfg%Lclcalipsotmpice=.TRUE.
- IF (xios_field_is_active("clcalipsotmpliq")) cfg%Lclcalipsotmpliq=.TRUE.
- IF (xios_field_is_active("clcalipsotmpun")) cfg%Lclcalipsotmpun=.TRUE.
- IF (xios_field_is_active("parasol_refl")) cfg%LparasolRefl=.TRUE.
- IF (xios_field_is_active("parasol_crefl")) cfg%LparasolRefl=.TRUE.
- IF (xios_field_is_active("Ncrefl")) cfg%LparasolRefl=.TRUE.
- IF (xios_field_is_active("cfad_lidarsr532")) cfg%LcfadLidarsr532=.TRUE.
- IF (xios_field_is_active("atb532")) cfg%Latb532=.TRUE.
- IF (xios_field_is_active("beta_mol532")) cfg%LlidarBetaMol532=.TRUE.
- IF (xios_field_is_active("clopaquecalipso")) cfg%Lclopaquecalipso=.TRUE.
- IF (xios_field_is_active("clthincalipso")) cfg%Lclthincalipso=.TRUE.
- IF (xios_field_is_active("clzopaquecalipso")) cfg%Lclzopaquecalipso=.TRUE.
- IF (xios_field_is_active("clcalipsoopaque")) cfg%Lclcalipsoopaque=.TRUE.
- IF (xios_field_is_active("clcalipsothin")) cfg%Lclcalipsothin=.TRUE.
- IF (xios_field_is_active("clcalipsozopaque")) cfg%Lclcalipsozopaque=.TRUE.
- IF (xios_field_is_active("clcalipsoopacity")) cfg%Lclcalipsoopacity=.TRUE.
- IF (xios_field_is_active("proftemp")) cfg%Lproftemp=.TRUE.
- IF (xios_field_is_active("profSR")) cfg%LprofSR=.TRUE.
-
- IF (xios_field_is_active("cfadDbze94")) cfg%LcfadDbze94=.TRUE.
- IF (xios_field_is_active("dbze94")) cfg%Ldbze94=.TRUE.
- IF (xios_field_is_active("cltlidarradar")) cfg%Lcltlidarradar=.TRUE.
- IF (xios_field_is_active("clcalipso2")) cfg%Lclcalipso2=.TRUE.
-
-   IF (xios_field_is_active("clisccp2")) cfg%Lclisccp=.TRUE.
- IF (xios_field_is_active("boxtauisccp")) cfg%Lboxtauisccp=.TRUE.
- IF (xios_field_is_active("boxptopisccp")) cfg%Lboxptopisccp=.TRUE.
- IF (xios_field_is_active("tclisccp")) cfg%Lcltisccp=.TRUE.
- IF (xios_field_is_active("ctpisccp")) cfg%Lpctisccp=.TRUE.
- IF (xios_field_is_active("tauisccp")) cfg%Ltauisccp=.TRUE.
- IF (xios_field_is_active("albisccp")) cfg%Lalbisccp=.TRUE.
- IF (xios_field_is_active("meantbisccp")) cfg%Lmeantbisccp=.TRUE.
- IF (xios_field_is_active("meantbclrisccp")) cfg%Lmeantbclrisccp=.TRUE.
-
-   IF (xios_field_is_active("clMISR")) cfg%LclMISR=.TRUE.
-
-IF (xios_field_is_active("cllmodis")) cfg%Lcllmodis=.TRUE.
- IF (xios_field_is_active("clmmodis")) cfg%Lclmmodis=.TRUE.
- IF (xios_field_is_active("clhmodis")) cfg%Lclhmodis=.TRUE.
- IF (xios_field_is_active("cltmodis")) cfg%Lcltmodis=.TRUE.
- IF (xios_field_is_active("clwmodis")) cfg%Lclwmodis=.TRUE.
- IF (xios_field_is_active("climodis")) cfg%Lclimodis=.TRUE.
- IF (xios_field_is_active("tautmodis")) cfg%Ltautmodis=.TRUE.
- IF (xios_field_is_active("tauwmodis")) cfg%Ltauwmodis=.TRUE.
- IF (xios_field_is_active("tauimodis")) cfg%Ltauimodis=.TRUE.
- IF (xios_field_is_active("tautlogmodis")) cfg%Ltautlogmodis=.TRUE.
- IF (xios_field_is_active("tauilogmodis")) cfg%Ltauilogmodis=.TRUE.
- IF (xios_field_is_active("tauwlogmodis")) cfg%Ltauwlogmodis=.TRUE.
- IF (xios_field_is_active("reffclwmodis")) cfg%Lreffclwmodis=.TRUE.
- IF (xios_field_is_active("reffclimodis")) cfg%Lreffclimodis=.TRUE.
- IF (xios_field_is_active("pctmodis")) cfg%Lpctmodis=.TRUE.
- IF (xios_field_is_active("lwpmodis")) cfg%Llwpmodis=.TRUE.
- IF (xios_field_is_active("iwpmodis")) cfg%Liwpmodis=.TRUE.
- IF (xios_field_is_active("clmodis")) cfg%Lclmodis=.TRUE.
- IF (xios_field_is_active("crimodis")) cfg%Lcrimodis=.TRUE.
- IF (xios_field_is_active("crlmodis")) cfg%Lcrlmodis=.TRUE.
-
-! 2.  si champs demande alors activer le simulateur correspondant
-   IF (xios_field_is_active("cllcalipso").OR. &
-       xios_field_is_active("clmcalipso").OR. &
-       xios_field_is_active("clhcalipso").OR. &
-       xios_field_is_active("cltcalipso").OR. &
-!       xios_field_is_active("pcllcalipso").OR. &
-!       xios_field_is_active("pclmcalipso").OR. &
-!       xios_field_is_active("pclhcalipso").OR. &
-!       xios_field_is_active("pcltcalipso").OR. &
-       xios_field_is_active("cllcalipsoice").OR. &
-       xios_field_is_active("clmcalipsoice").OR. &
-       xios_field_is_active("clhcalipsoice").OR. &
-       xios_field_is_active("cltcalipsoice").OR. &
-       xios_field_is_active("cllcalipsoliq").OR. &
-       xios_field_is_active("clmcalipsoliq").OR. &
-       xios_field_is_active("clhcalipsoliq").OR. &
-       xios_field_is_active("cltcalipsoliq").OR. &
-       xios_field_is_active("cllcalipsoun").OR. &
-       xios_field_is_active("clmcalipsoun").OR. &
-       xios_field_is_active("clhcalipsoun").OR. &
-       xios_field_is_active("cltcalipsoun").OR. &
-       xios_field_is_active("clcalipso").OR. &
-!       xios_field_is_active("pclcalipso").OR. &
-       xios_field_is_active("clcalipsoice").OR. &
-       xios_field_is_active("clcalipsoliq").OR. &
-       xios_field_is_active("clcalipsoun").OR. &
-       xios_field_is_active("clcalipsotmp").OR. &
-       xios_field_is_active("clcalipsotmpice").OR. &
-       xios_field_is_active("clcalipsotmpliq").OR. &
-       xios_field_is_active("clcalipsotmpun").OR. &
-       xios_field_is_active("parasol_refl").OR. &
-       xios_field_is_active("parasol_crefl").OR. &
-       xios_field_is_active("Ncrefl").OR. &
-       xios_field_is_active("cfad_lidarsr532").OR. &
-       xios_field_is_active("atb532").OR. &
-       xios_field_is_active("beta_mol532").OR. &
-       xios_field_is_active("clopaquecalipso").OR. &
-       xios_field_is_active("clthincalipso").OR. &
-       xios_field_is_active("clzopaquecalipso").OR. &
-       xios_field_is_active("clcalipsoopaque").OR. &
-       xios_field_is_active("clcalipsothin").OR. &
-       xios_field_is_active("clcalipsozopaque").OR. &
-       xios_field_is_active("clcalipsoopacity").OR. &
-       xios_field_is_active("proftemp").OR. &
-       xios_field_is_active("profSR")) cfg%Llidar_sim=.TRUE.
-
-    IF (xios_field_is_active("cfadDbze94").OR. &
-      xios_field_is_active("dbze94")) &
-               cfg%Lradar_sim=.TRUE.
-
-    IF (xios_field_is_active("cltlidarradar").OR. &
-      xios_field_is_active("clcalipso2")) THEN
-               cfg%Lradar_sim=.TRUE.
-               cfg%Llidar_sim=.TRUE.
-    ENDIF
-
-    IF (xios_field_is_active("clisccp2").OR. &
-       xios_field_is_active("boxtauisccp").OR. &
-       xios_field_is_active("boxptopisccp").OR. &
-       xios_field_is_active("tclisccp").OR. &
-       xios_field_is_active("ctpisccp").OR. &
-       xios_field_is_active("tauisccp").OR. &
-       xios_field_is_active("albisccp").OR. &
-       xios_field_is_active("meantbisccp").OR. &
-       xios_field_is_active("meantbclrisccp")) cfg%Lisccp_sim=.TRUE.
-
-    IF (xios_field_is_active("clMISR")) cfg%Lmisr_sim=.TRUE.
-
-    IF (xios_field_is_active("cllmodis").OR. &
-       xios_field_is_active("clmmodis").OR. &
-       xios_field_is_active("clhmodis").OR. &
-       xios_field_is_active("cltmodis").OR. &
-       xios_field_is_active("clwmodis").OR. &
-       xios_field_is_active("climodis").OR. &
-       xios_field_is_active("tautmodis").OR. &
-       xios_field_is_active("tauwmodis").OR. &
-       xios_field_is_active("tauimodis").OR. &
-       xios_field_is_active("tautlogmodis").OR. &
-       xios_field_is_active("tauilogmodis").OR. &
-       xios_field_is_active("tauwlogmodis").OR. &
-       xios_field_is_active("reffclwmodis").OR. &
-       xios_field_is_active("reffclimodis").OR. &
-       xios_field_is_active("pctmodis").OR. &
-       xios_field_is_active("lwpmodis").OR. &
-       xios_field_is_active("iwpmodis").OR. &
-       xios_field_is_active("clmodis").OR. &
-       xios_field_is_active("crimodis").OR. &
-       xios_field_is_active("crlmodis")) cfg%Lmodis_sim=.TRUE.
-
- endif
-#endif
-
- END SUBROUTINE READ_COSP_OUTPUT_NL
-
