Index: /LMDZ6/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 3171)
+++ /LMDZ6/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 3172)
@@ -27,5 +27,5 @@
 #ifdef CPP_XIOS
     USE wxios, only: wxios_closedef
-    USE xios, only: xios_update_calendar
+    USE xios, only: xios_update_calendar, xios_field_is_active
 #endif
 
@@ -50,5 +50,4 @@
   real, dimension(Npoints,PARASOL_NREFL) :: parasolcrefl, Ncref
 
-
 #ifdef CPP_XIOS
   missing_val=missing_cosp
@@ -83,82 +82,84 @@
    endif
 
-#ifdef CPP_XIOS
- !$OMP MASTER
-IF (cosp_varsdefined) THEN
-   if (prt_level >= 10) then
-         WRITE(lunout,*)'Apell xios_update_calendar cosp_varsdefined iinitend ', &
-                         cosp_varsdefined,iinitend
-   endif 
-    CALL xios_update_calendar(itau_wcosp)
-ENDIF
-  !$OMP END MASTER
-  !$OMP BARRIER
-#endif
-
+!!#ifdef CPP_XIOS
+! !$OMP MASTER
+!IF (cosp_varsdefined) THEN
+!   if (prt_level >= 10) then
+!         WRITE(lunout,*)'Apell xios_update_calendar cosp_varsdefined iinitend ', &
+!                         cosp_varsdefined,iinitend
+!   endif 
+!    CALL xios_update_calendar(itau_wcosp)
+!ENDIF
+!  !$OMP END MASTER
+!  !$OMP BARRIER
+!!#endif
+
+!!!! Sorties Calipso
  if (cfg%Llidar_sim) then
 ! Pb des valeurs indefinies, on les met a 0
 ! A refaire proprement
-  do k = 1,Nlevout
-     do ip = 1,Npoints
-     if(stlidar%lidarcld(ip,k).eq.R_UNDEF)then
-      stlidar%lidarcld(ip,k)=missing_val
-     endif
-     if(stlidar%proftemp(ip,k).eq.R_UNDEF)then !TIBO
-      stlidar%proftemp(ip,k)=missing_val       !TIBO
-     endif                                     !TIBO
-     enddo
-
-     do ii= 1,SR_BINS
-      do ip = 1,Npoints
-       if(stlidar%cfad_sr(ip,ii,k).eq.R_UNDEF)then
-        stlidar%cfad_sr(ip,ii,k)=missing_val
-       endif
-      enddo
-     enddo
-
-     do ii= 1,Ncolumns                               !TIBO
-      do ip = 1,Npoints                              !TIBO
-!       if(stlidar%profSR(ip,ii,k).eq.R_UNDEF)then    !TIBO
-!        stlidar%profSR(ip,ii,k)=missing_val          !TIBO
-       if(stlidar%profSR(ip,k,ii).eq.R_UNDEF)then    !TIBO2
-        stlidar%profSR(ip,k,ii)=missing_val          !TIBO2
-       endif                                         !TIBO
-      enddo                                          !TIBO
-     enddo                                           !TIBO
-  enddo
-
-  do ip = 1,Npoints
-   do k = 1,Nlevlmdz
-     if(sglidar%beta_mol(ip,k).eq.R_UNDEF)then
-      sglidar%beta_mol(ip,k)=missing_val
-     endif
-
-     do ii= 1,Ncolumns
-       if(sglidar%beta_tot(ip,ii,k).eq.R_UNDEF)then
-        sglidar%beta_tot(ip,ii,k)=missing_val
-       endif
-     enddo
-
-    enddo    !k = 1,Nlevlmdz
-   enddo     !ip = 1,Npoints
-
-   do k = 1,LIDAR_NCAT
-    do ip = 1,Npoints
-     if(stlidar%cldlayer(ip,k).eq.R_UNDEF)then
-       stlidar%cldlayer(ip,k)=missing_val
-     endif
-    enddo
-   enddo
-
-   do k = 1,LIDAR_NTYPE                       !OPAQ
-    do ip = 1,Npoints                         !OPAQ
-     if(stlidar%cldtype(ip,k).eq.R_UNDEF)then !OPAQ
-       stlidar%cldtype(ip,k)=missing_val      !OPAQ
-     endif                                    !OPAQ
-    enddo                                     !OPAQ
-   enddo                                      !OPAQ
-
+!  do k = 1,Nlevout
+!     do ip = 1,Npoints
+!     if(stlidar%lidarcld(ip,k).eq.R_UNDEF)then
+!      stlidar%lidarcld(ip,k)=missing_val
+!     endif
+!     if(stlidar%proftemp(ip,k).eq.R_UNDEF)then !TIBO
+!      stlidar%proftemp(ip,k)=missing_val       !TIBO
+!     endif                                     !TIBO
+!     enddo
+
+!     do ii= 1,Ncolumns                               !TIBO
+!      do ip = 1,Npoints                              !TIBO
+!!       if(stlidar%profSR(ip,ii,k).eq.R_UNDEF)then    !TIBO
+!!        stlidar%profSR(ip,ii,k)=missing_val          !TIBO
+!       if(stlidar%profSR(ip,k,ii).eq.R_UNDEF)then    !TIBO2
+!        stlidar%profSR(ip,k,ii)=missing_val          !TIBO2
+!       endif                                         !TIBO
+!      enddo                                          !TIBO
+!     enddo                                           !TIBO
+!  enddo
+
+!  do ip = 1,Npoints
+!   do k = 1,Nlevlmdz
+!     if(sglidar%beta_mol(ip,k).eq.R_UNDEF)then
+!      sglidar%beta_mol(ip,k)=missing_val
+!     endif
+
+!     do ii= 1,Ncolumns
+!       if(sglidar%beta_tot(ip,ii,k).eq.R_UNDEF)then
+!        sglidar%beta_tot(ip,ii,k)=missing_val
+!       endif
+!     enddo
+
+!    enddo    !k = 1,Nlevlmdz
+!   enddo     !ip = 1,Npoints
+
+!   do k = 1,LIDAR_NCAT
+!    do ip = 1,Npoints
+!     if(stlidar%cldlayer(ip,k).eq.R_UNDEF)then
+!       stlidar%cldlayer(ip,k)=missing_val
+!     endif
+!    enddo
+!   enddo
+
+!   do k = 1,LIDAR_NTYPE                       !OPAQ
+!    do ip = 1,Npoints                         !OPAQ
+!     if(stlidar%cldtype(ip,k).eq.R_UNDEF)then !OPAQ
+!       stlidar%cldtype(ip,k)=missing_val      !OPAQ
+!     endif                                    !OPAQ
+!    enddo                                     !OPAQ
+!   enddo                                      !OPAQ
+ 
+!!! AI 02 2018 
+! Traitement missing_val
+   where(stlidar%lidarcld == R_UNDEF) stlidar%lidarcld = missing_val
+   where(stlidar%proftemp == R_UNDEF) stlidar%proftemp = missing_val   !TIBO  
+   where(stlidar%profSR == R_UNDEF) stlidar%profSR = missing_val       !TIBO2
+   where(sglidar%beta_mol == R_UNDEF) sglidar%beta_mol = missing_val  
+   where(sglidar%beta_tot == R_UNDEF) sglidar%beta_tot = missing_val 
+   where(stlidar%cldlayer == R_UNDEF) stlidar%cldlayer = missing_val
+   where(stlidar%cldtype == R_UNDEF) stlidar%cldtype = missing_val     !OPAQ
+   where(stlidar%cfad_sr == R_UNDEF) stlidar%cfad_sr = missing_val
 ! AI 11 / 2015
-
    where(stlidar%parasolrefl == R_UNDEF) stlidar%parasolrefl = missing_val
    where(stlidar%lidarcldtmp == R_UNDEF) stlidar%lidarcldtmp = missing_val
@@ -167,7 +168,6 @@
    where(stlidar%lidarcldtype == R_UNDEF) stlidar%lidarcldtype = missing_val   !OPAQ
    where(stlidar%lidarcldtmp == R_UNDEF) stlidar%lidarcldtmp = missing_val
-   
-
-   print*,'Appel histwrite2d_cosp'
+ 
+!   print*,'Appel histwrite2d_cosp'
    CALL histwrite2d_cosp(o_cllcalipso,stlidar%cldlayer(:,1))
    CALL histwrite2d_cosp(o_clhcalipso,stlidar%cldlayer(:,3))
@@ -249,6 +249,8 @@
  endif !Lidar
 
+!!! Sorties Cloudsat
  if (cfg%Lradar_sim) then
 
+   where(stradar%cfad_ze == R_UNDEF) stradar%cfad_ze = missing_val
 #ifdef CPP_XIOS
    CALL histwrite4d_cosp(o_dbze94,sgradar%Ze_tot)
@@ -264,4 +266,5 @@
  endif
 
+!!! Sorties combinees Cloudsat et Calipso
  if (cfg%Llidar_sim .and. cfg%Lradar_sim) then
    where(stradar%lidar_only_freq_cloud == R_UNDEF) &
@@ -273,47 +276,56 @@
  endif
 
+!!! Sorties Isccp
  if (cfg%Lisccp_sim) then
-
 ! Traitement des valeurs indefinies
-   do ip = 1,Npoints
-    if(isccp%totalcldarea(ip).eq.R_UNDEF)then
-      isccp%totalcldarea(ip)=missing_val
-    endif
-    if(isccp%meanptop(ip).eq.R_UNDEF)then
-      isccp%meanptop(ip)=missing_val
-    endif
-    if(isccp%meantaucld(ip).eq.R_UNDEF)then
-      isccp%meantaucld(ip)=missing_val
-    endif
-    if(isccp%meanalbedocld(ip).eq.R_UNDEF)then
-     isccp%meanalbedocld(ip)=missing_val
-    endif
-    if(isccp%meantb(ip).eq.R_UNDEF)then
-     isccp%meantb(ip)=missing_val
-    endif
-    if(isccp%meantbclr(ip).eq.R_UNDEF)then
-       isccp%meantbclr(ip)=missing_val
-    endif
-
-    do k=1,7
-     do ii=1,7
-     if(isccp%fq_isccp(ip,ii,k).eq.R_UNDEF)then
-      isccp%fq_isccp(ip,ii,k)=missing_val
-     endif
-     enddo
-    enddo
-
-    do ii=1,Ncolumns
-     if(isccp%boxtau(ip,ii).eq.R_UNDEF)then
-       isccp%boxtau(ip,ii)=missing_val
-     endif
-    enddo
-
-    do ii=1,Ncolumns
-     if(isccp%boxptop(ip,ii).eq.R_UNDEF)then
-      isccp%boxptop(ip,ii)=missing_val
-     endif
-    enddo
-   enddo
+!   do ip = 1,Npoints
+!    if(isccp%totalcldarea(ip).eq.R_UNDEF)then
+!      isccp%totalcldarea(ip)=missing_val
+!    endif
+!    if(isccp%meanptop(ip).eq.R_UNDEF)then
+!      isccp%meanptop(ip)=missing_val
+!    endif
+!    if(isccp%meantaucld(ip).eq.R_UNDEF)then
+!      isccp%meantaucld(ip)=missing_val
+!    endif
+!    if(isccp%meanalbedocld(ip).eq.R_UNDEF)then
+!     isccp%meanalbedocld(ip)=missing_val
+!    endif
+!    if(isccp%meantb(ip).eq.R_UNDEF)then
+!     isccp%meantb(ip)=missing_val
+!    endif
+!    if(isccp%meantbclr(ip).eq.R_UNDEF)then
+!       isccp%meantbclr(ip)=missing_val
+!    endif
+
+!    do k=1,7
+!     do ii=1,7
+!     if(isccp%fq_isccp(ip,ii,k).eq.R_UNDEF)then
+!      isccp%fq_isccp(ip,ii,k)=missing_val
+!     endif
+!     enddo
+!    enddo
+
+!    do ii=1,Ncolumns
+!     if(isccp%boxtau(ip,ii).eq.R_UNDEF)then
+!       isccp%boxtau(ip,ii)=missing_val
+!     endif
+!    enddo
+
+!    do ii=1,Ncolumns
+!     if(isccp%boxptop(ip,ii).eq.R_UNDEF)then
+!      isccp%boxptop(ip,ii)=missing_val
+!     endif
+!    enddo
+!   enddo
+  where(isccp%totalcldarea == R_UNDEF) isccp%totalcldarea = missing_val
+  where(isccp%meanptop == R_UNDEF) isccp%meanptop = missing_val
+  where(isccp%meantaucld == R_UNDEF) isccp%meantaucld = missing_val
+  where(isccp%meanalbedocld == R_UNDEF) isccp%meanalbedocld = missing_val
+  where(isccp%meantb == R_UNDEF) isccp%meantb = missing_val
+  where(isccp%meantbclr == R_UNDEF) isccp%meantbclr = missing_val
+  where(isccp%fq_isccp == R_UNDEF) isccp%fq_isccp = missing_val
+  where(isccp%boxtau == R_UNDEF) isccp%boxtau = missing_val
+  where(isccp%boxptop == R_UNDEF) isccp%boxptop = missing_val 
 
    CALL histwrite2d_cosp(o_sunlit,gbx%sunlit)
@@ -335,15 +347,16 @@
  endif ! Isccp
 
-! MISR simulator
+!!! MISR simulator
  if (cfg%Lmisr_sim) then
-   do ip=1,Npoints
-     do ii=1,7
-       do k=1,MISR_N_CTH
-        if(misr%fq_MISR(ip,ii,k).eq.R_UNDEF)then
-            misr%fq_MISR(ip,ii,k)=missing_val
-        endif
-       enddo
-     enddo
-   enddo
+!   do ip=1,Npoints
+!     do ii=1,7
+!       do k=1,MISR_N_CTH
+!        if(misr%fq_MISR(ip,ii,k).eq.R_UNDEF)then
+!            misr%fq_MISR(ip,ii,k)=missing_val
+!        endif
+!       enddo
+!     enddo
+!   enddo
+   where(misr%fq_MISR == R_UNDEF) misr%fq_MISR = missing_val
 
 #ifdef CPP_XIOS
@@ -356,57 +369,83 @@
  endif
 
-! Modis simulator
+!!! Modis simulator
  if (cfg%Lmodis_sim) then
-
-  do ip=1,Npoints
-    if(modis%Cloud_Fraction_Low_Mean(ip).eq.R_UNDEF)then
-      modis%Cloud_Fraction_Low_Mean(ip)=missing_val
-    endif
-    if(modis%Cloud_Fraction_High_Mean(ip).eq.R_UNDEF)then
-       modis%Cloud_Fraction_High_Mean(ip)=missing_val 
-    endif
-    if(modis%Cloud_Fraction_Mid_Mean(ip).eq.R_UNDEF)then
-       modis%Cloud_Fraction_Mid_Mean(ip)=missing_val
-    endif
-    if(modis%Cloud_Fraction_Total_Mean(ip).eq.R_UNDEF)then
-       modis%Cloud_Fraction_Total_Mean(ip)=missing_val
-    endif
-    if(modis%Cloud_Fraction_Water_Mean(ip).eq.R_UNDEF)then
-       modis%Cloud_Fraction_Water_Mean(ip)=missing_val
-    endif
-    if(modis%Cloud_Fraction_Ice_Mean(ip).eq.R_UNDEF)then
-       modis%Cloud_Fraction_Ice_Mean(ip)=missing_val
-    endif
-    if(modis%Optical_Thickness_Total_Mean(ip).eq.R_UNDEF)then
-       modis%Optical_Thickness_Total_Mean(ip)=missing_val
-    endif
-    if(modis%Optical_Thickness_Water_Mean(ip).eq.R_UNDEF)then
-       modis%Optical_Thickness_Water_Mean(ip)=missing_val
-    endif
-    if(modis%Optical_Thickness_Ice_Mean(ip).eq.R_UNDEF)then
-       modis%Optical_Thickness_Ice_Mean(ip)=missing_val
-    endif
-    if(modis%Cloud_Particle_Size_Water_Mean(ip).eq.R_UNDEF)then
-       modis%Cloud_Particle_Size_Water_Mean(ip)=missing_val
-    endif
-    if(modis%Cloud_Particle_Size_Ice_Mean(ip).eq.R_UNDEF)then
-       modis%Cloud_Particle_Size_Ice_Mean(ip)=missing_val
-    endif
-    if(modis%Cloud_Top_Pressure_Total_Mean(ip).eq.R_UNDEF)then
-       modis%Cloud_Top_Pressure_Total_Mean(ip)=missing_val
-    endif
-    if(modis%Liquid_Water_Path_Mean(ip).eq.R_UNDEF)then
-       modis%Liquid_Water_Path_Mean(ip)=missing_val
-    endif
-    if(modis%Ice_Water_Path_Mean(ip).eq.R_UNDEF)then
-       modis%Ice_Water_Path_Mean(ip)=missing_val
-    endif
-
-  enddo
+  where(modis%Cloud_Fraction_Low_Mean == R_UNDEF) &
+        modis%Cloud_Fraction_Low_Mean = missing_val
+  where(modis%Cloud_Fraction_High_Mean == R_UNDEF) &
+        modis%Cloud_Fraction_High_Mean = missing_val
+  where(modis%Cloud_Fraction_Mid_Mean == R_UNDEF) &
+        modis%Cloud_Fraction_Mid_Mean = missing_val
+  where(modis%Cloud_Fraction_Total_Mean == R_UNDEF) &
+        modis%Cloud_Fraction_Total_Mean = missing_val
+  where(modis%Cloud_Fraction_Water_Mean == R_UNDEF) &
+        modis%Cloud_Fraction_Water_Mean = missing_val
+  where(modis%Cloud_Fraction_Ice_Mean == R_UNDEF) &
+        modis%Cloud_Fraction_Ice_Mean = missing_val
+  where(modis%Optical_Thickness_Total_Mean == R_UNDEF) &
+        modis%Optical_Thickness_Total_Mean = missing_val
+  where(modis%Optical_Thickness_Water_Mean == R_UNDEF) &
+        modis%Optical_Thickness_Water_Mean = missing_val
+  where(modis%Optical_Thickness_Ice_Mean == R_UNDEF) &
+        modis%Optical_Thickness_Ice_Mean = missing_val
+  where(modis%Cloud_Particle_Size_Water_Mean == R_UNDEF) &
+        modis%Cloud_Particle_Size_Water_Mean = missing_val
+  where(modis%Cloud_Particle_Size_Ice_Mean == R_UNDEF) &
+        modis%Cloud_Particle_Size_Ice_Mean = missing_val
+  where(modis%Cloud_Top_Pressure_Total_Mean == R_UNDEF) &
+        modis%Cloud_Top_Pressure_Total_Mean = missing_val
+  where(modis%Liquid_Water_Path_Mean == R_UNDEF) &
+        modis%Liquid_Water_Path_Mean = missing_val 
+  where(modis%Ice_Water_Path_Mean == R_UNDEF) &
+        modis%Ice_Water_Path_Mean = missing_val
+
+!  de ip=1,Npoints
+!    if(modis%Cloud_Fraction_Low_Mean(ip).eq.R_UNDEF)then
+!      modis%Cloud_Fraction_Low_Mean(ip)=missing_val
+!    endif
+!    if(modis%Cloud_Fraction_High_Mean(ip).eq.R_UNDEF)then
+!       modis%Cloud_Fraction_High_Mean(ip)=missing_val 
+!    endif
+!    if(modis%Cloud_Fraction_Mid_Mean(ip).eq.R_UNDEF)then
+!       modis%Cloud_Fraction_Mid_Mean(ip)=missing_val
+!    endif
+!    if(modis%Cloud_Fraction_Total_Mean(ip).eq.R_UNDEF)then
+!       modis%Cloud_Fraction_Total_Mean(ip)=missing_val
+!    endif
+!    if(modis%Cloud_Fraction_Water_Mean(ip).eq.R_UNDEF)then
+!       modis%Cloud_Fraction_Water_Mean(ip)=missing_val
+!    endif
+!    if(modis%Cloud_Fraction_Ice_Mean(ip).eq.R_UNDEF)then
+!       modis%Cloud_Fraction_Ice_Mean(ip)=missing_val
+!    endif
+!    if(modis%Optical_Thickness_Total_Mean(ip).eq.R_UNDEF)then
+!       modis%Optical_Thickness_Total_Mean(ip)=missing_val
+!    endif
+!    if(modis%Optical_Thickness_Water_Mean(ip).eq.R_UNDEF)then
+!       modis%Optical_Thickness_Water_Mean(ip)=missing_val
+!    endif
+!    if(modis%Optical_Thickness_Ice_Mean(ip).eq.R_UNDEF)then
+!       modis%Optical_Thickness_Ice_Mean(ip)=missing_val
+!    endif
+!    if(modis%Cloud_Particle_Size_Water_Mean(ip).eq.R_UNDEF)then
+!       modis%Cloud_Particle_Size_Water_Mean(ip)=missing_val
+!    endif
+!    if(modis%Cloud_Particle_Size_Ice_Mean(ip).eq.R_UNDEF)then
+!       modis%Cloud_Particle_Size_Ice_Mean(ip)=missing_val
+!    endif
+!    if(modis%Cloud_Top_Pressure_Total_Mean(ip).eq.R_UNDEF)then
+!       modis%Cloud_Top_Pressure_Total_Mean(ip)=missing_val
+!    endif
+!    if(modis%Liquid_Water_Path_Mean(ip).eq.R_UNDEF)then
+!       modis%Liquid_Water_Path_Mean(ip)=missing_val
+!    endif
+!    if(modis%Ice_Water_Path_Mean(ip).eq.R_UNDEF)then
+!       modis%Ice_Water_Path_Mean(ip)=missing_val
+!    endif
+!  enddo
 
     where(modis%Optical_Thickness_Total_LogMean == R_UNDEF) &
           modis%Optical_Thickness_Total_LogMean = missing_val
            
- 
     where(modis%Optical_Thickness_Water_LogMean == R_UNDEF) &
           modis%Optical_Thickness_Water_LogMean = missing_val
@@ -433,13 +472,15 @@
    CALL histwrite2d_cosp(o_iwpmodis,modis%Ice_Water_Path_Mean)
 
-   do ip=1,Npoints
-     do ii=1,7
-       do k=1,7
-       if(modis%Optical_Thickness_vs_Cloud_Top_Pressure(ip,ii,k).eq.R_UNDEF)then
-          modis%Optical_Thickness_vs_Cloud_Top_Pressure(ip,ii,k)=missing_val
-        endif
-       enddo
-     enddo
-    enddo 
+!   do ip=1,Npoints
+!     do ii=1,7
+!       do k=1,7
+!       if(modis%Optical_Thickness_vs_Cloud_Top_Pressure(ip,ii,k).eq.R_UNDEF)then
+!          modis%Optical_Thickness_vs_Cloud_Top_Pressure(ip,ii,k)=missing_val
+!        endif
+!       enddo
+!     enddo
+!    enddo 
+    where(modis%Optical_Thickness_vs_Cloud_Top_Pressure == R_UNDEF) &
+          modis%Optical_Thickness_vs_Cloud_Top_Pressure = missing_val
 
 #ifdef CPP_XIOS
@@ -459,6 +500,4 @@
 
 #ifdef CPP_XIOS
-!    print*,'dimension de crimodis=',size(modis%Optical_Thickness_vs_ReffIce,2),&
-!                                    size(modis%Optical_Thickness_vs_ReffIce,3)
     CALL histwrite4d_cosp(o_crimodis,modis%Optical_Thickness_vs_ReffIce)
     CALL histwrite4d_cosp(o_crlmodis,modis%Optical_Thickness_vs_ReffLiq)
Index: /LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90	(revision 3171)
+++ /LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90	(revision 3172)
@@ -84,4 +84,7 @@
   use cosp_output_write_mod
 !  use MOD_COSP_Modis_Simulator, only : cosp_modis 
+#ifdef CPP_XIOS
+    USE xios, ONLY: xios_field_is_active
+#endif
 
   IMPLICIT NONE
@@ -136,4 +139,7 @@
 !$OMP THREADPRIVATE(debut_cosp)
 
+  logical, save :: first_write=.true.
+!$OMP THREADPRIVATE(first_write)
+
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Input variables from LMDZ-GCM
   integer                         :: overlaplmdz   !  overlap type: 1=max, 2=rand, 3=max/rand ! cosp input (output lmdz)
@@ -171,5 +177,5 @@
 
 ! Clefs Outputs 
-  call read_cosp_output_nl(cosp_output_nl,cfg)
+  call read_cosp_output_nl(itap,cosp_output_nl,cfg)
 
     if (overlaplmdz.ne.overlap) then
@@ -178,9 +184,23 @@
    print*,'Fin lecture Namelists, debut_cosp =',debut_cosp
 
-  print*,' Cles des differents simulateurs 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
+#ifdef CPP_XIOS
+  if ((itap.gt.1).and.(first_write))then
+!    call read_xiosfieldactive(cfg)
+     call read_cosp_output_nl(itap,cosp_output_nl,cfg)
+!       print*,' Dans cosp_write itap first_writ LcfadLidarsr532 =', &
+!                     itap, first_write, cfg%LcfadLidarsr532
+     first_write=.false.
+  endif
+!  print*,' Dans cosp_write itap LcfadLidarsr532 =', &
+!                     itap, cfg%LcfadLidarsr532
+#endif
+
 
   time_bnds(1) = dtime-dtime/2.
@@ -421,3 +441,187 @@
   END SUBROUTINE read_cosp_input 
 
+  SUBROUTINE read_xiosfieldactive(cfg)
+
+    USE MOD_COSP_TYPES
+#ifdef CPP_XIOS
+    USE xios, ONLY: xios_field_is_active
+#endif
+  type(cosp_config),intent(out) :: cfg
+
+! 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.
+  END SUBROUTINE read_xiosfieldactive 
+
+
 end subroutine phys_cosp
Index: /LMDZ6/trunk/libf/phylmd/cosp/read_cosp_output_nl.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/cosp/read_cosp_output_nl.F90	(revision 3171)
+++ /LMDZ6/trunk/libf/phylmd/cosp/read_cosp_output_nl.F90	(revision 3172)
@@ -2,5 +2,5 @@
 !--------------- SUBROUTINE READ_COSP_OUTPUT_NL -------------------------
 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- SUBROUTINE READ_COSP_OUTPUT_NL(cosp_nl,cfg)
+ SUBROUTINE READ_COSP_OUTPUT_NL(itap,cosp_nl,cfg)
   USE MOD_COSP_CONSTANTS
   USE MOD_COSP_TYPES
@@ -8,5 +8,5 @@
 
 #ifdef CPP_XIOS
-    USE xios, ONLY: xios_get_field_attr, xios_field_is_active
+    USE xios, ONLY: xios_field_is_active
 #endif
 
@@ -14,5 +14,5 @@
   type(cosp_config),intent(out) :: cfg
   ! Local variables
-  integer :: i
+  integer :: i, itap
 
 !! AI 
@@ -79,187 +79,4 @@
   ENDIF
   
-! VEREFIER LES CHAMPS DEMANDES DANS .XML
-! 2. Si champs active dans .xml alors mettre la cles de sortie en true
-#ifdef CPP_XIOS
-   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("pcllcalipso")) Lcllcalipso=.TRUE.
-             IF (xios_field_is_active("pclmcalipso")) Lclmcalipso=.TRUE.
-             IF (xios_field_is_active("pclhcalipso")) Lclhcalipso=.TRUE.
-             IF (xios_field_is_active("pcltcalipso")) 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("pclcalipso")) 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")) Lparasol_refl=.TRUE.
-             IF (xios_field_is_active("parasol_crefl")) Lparasol_refl=.TRUE.
-             IF (xios_field_is_active("Ncrefl")) Lparasol_refl=.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")) Lbeta_mol532=.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.
-
-   IF (xios_field_is_active("cfadDbze94")) LcfadDbze94=.TRUE.
-             IF (xios_field_is_active("dbze94")) Ldbze94=.TRUE.
-             IF (xios_field_is_active("cltlidarradar")) Lcltlidarradar=.TRUE.
-             IF (xios_field_is_active("clcalipso2")) Lclcalipso2=.TRUE.
-
-   IF (xios_field_is_active("clisccp2")) Lclisccp2=.TRUE.
-             IF (xios_field_is_active("boxtauisccp")) Lboxtauisccp=.TRUE.
-             IF (xios_field_is_active("boxptopisccp")) Lboxptopisccp=.TRUE.
-             IF (xios_field_is_active("tclisccp")) Ltclisccp=.TRUE.
-             IF (xios_field_is_active("ctpisccp")) Lctpisccp=.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.
-
-   IF (xios_field_is_active("clMISR")) LclMISR=.TRUE.
-
-             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("jpdftaureicemodis")) Lcrimodis=.TRUE.
-             IF (xios_field_is_active("crimodis")) Lcrimodis=.TRUE.
-!             IF (xios_field_is_active("jpdftaureliqmodis")) Lcrlmodis=.TRUE.
-             IF (xios_field_is_active("crlmodis")) 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")) &
-                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 
-
-
   CALL bcast(Lradar_sim)
   CALL bcast(Llidar_sim)
@@ -348,4 +165,5 @@
 !  print*,' Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lrttov_sim', &
 !           Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lrttov_sim
+
 
   ! Deal with dependencies
@@ -714,4 +532,183 @@
   cfg%Lcrimodis=Lcrimodis
   cfg%Lcrlmodis=Lcrlmodis
+  
+    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
+
 
  END SUBROUTINE READ_COSP_OUTPUT_NL
