Index: LMDZ6/trunk/libf/phylmd/cospv2/cosp_config.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cospv2/cosp_config.F90	(revision 3702)
+++ LMDZ6/trunk/libf/phylmd/cospv2/cosp_config.F90	(revision 3723)
@@ -63,4 +63,6 @@
          N_HYDRO = 9               ! Number of hydrometeor classes used by quickbeam radar simulator.
 
+    ! Mode debug ou prod (AI 0302018)
+    logical :: ok_debug_cosp = .true.
     ! ####################################################################################  
     ! Joint histogram bin-boundaries
Index: LMDZ6/trunk/libf/phylmd/cospv2/cosp_utils.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cospv2/cosp_utils.F90	(revision 3702)
+++ LMDZ6/trunk/libf/phylmd/cospv2/cosp_utils.F90	(revision 3723)
@@ -56,4 +56,14 @@
     integer :: i,j,k
     real(wp) :: sigma,one_over_xip1,xi,rho0,rho,lambda_x,gamma_4_3_2,delta
+
+    real(wp) :: seuil
+
+    if (ok_debug_cosp) then
+       seuil=1.e-15
+    else
+       seuil=0.0
+    endif
+
+
     
     mxratio = 0.0
@@ -75,5 +85,6 @@
                         mxratio(i,j,k)=mxratio(i,j,k)/rho
                         ! Compute effective radius
-                        if ((reff(i,j,k) <= 0._wp).and.(flux(i,k) /= 0._wp)) then
+!                        if ((reff(i,j,k) <= 0._wp).and.(flux(i,k) /= 0._wp)) then
+                         if ((reff(i,j,k) <= 0._wp).and.(flux(i,k) > seuil)) then
                            lambda_x = (a_x*c_x*((rho0/rho)**g_x)*n_ax*gamma1/flux(i,k))**(1._wp/delta)
                            reff(i,j,k) = gamma_4_3_2/lambda_x
Index: LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_interface.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_interface.F90	(revision 3702)
+++ LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_interface.F90	(revision 3723)
@@ -74,13 +74,13 @@
 
 !!! Modules faisant partie du code source de COSPv2
-  use cosp_kinds,		  only: wp                         
-  use MOD_COSP_CONFIG,     		  only: N_HYDRO,RTTOV_MAX_CHANNELS, &
-      			   	 		niv_sorties, vgrid_z_in
-  use mod_quickbeam_optics,		  only: size_distribution,hydro_class_init, &
-                                 		quickbeam_optics_init
-  use quickbeam,           		  only: radar_cfg
-  use mod_cosp,            		  only: cosp_init,cosp_optical_inputs, &
-      						cosp_column_inputs,cosp_outputs, &
-						cosp_simulator
+  use cosp_kinds,  only: wp                         
+  use MOD_COSP_CONFIG,       only: N_HYDRO,RTTOV_MAX_CHANNELS, &
+                                    niv_sorties, vgrid_z_in
+  use mod_quickbeam_optics,  only: size_distribution,hydro_class_init, &
+                                   quickbeam_optics_init
+  use quickbeam,            only: radar_cfg
+  use mod_cosp,             only: cosp_init,cosp_optical_inputs, &
+                                  cosp_column_inputs,cosp_outputs, &
+                                  cosp_simulator
 
 
@@ -198,9 +198,9 @@
 
 ! Parametres qui sont lus a partir du fichier "cosp_input_nl.txt"
-   namelist/COSP_INPUT/overlap, isccp_topheight, isccp_topheight_direction,	  &
-              npoints_it, ncolumns, use_vgrid_in, csat_vgrid_in,		  &
-              cloudsat_radar_freq, surface_radar, use_mie_tables,		  &
-              cloudsat_use_gas_abs, cloudsat_do_ray, melt_lay, cloudsat_k2, 	  &
-              cloudsat_micro_scheme, lidar_ice_type, use_precipitation_fluxes, 	  &
+   namelist/COSP_INPUT/overlap, isccp_topheight, isccp_topheight_direction,  &
+              npoints_it, ncolumns, use_vgrid_in, csat_vgrid_in,  &
+              cloudsat_radar_freq, surface_radar, use_mie_tables,  &
+              cloudsat_use_gas_abs, cloudsat_do_ray, melt_lay, cloudsat_k2,  &
+              cloudsat_micro_scheme, lidar_ice_type, use_precipitation_fluxes,   &
               rttov_platform, rttov_satellite, rttov_Instrument, rttov_Nchannels, &
               rttov_Channels, rttov_Surfem, rttov_ZenAng, co2, ch4, n2o, co
@@ -215,6 +215,6 @@
 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
- print*,'Entree lmdz_cosp_interface' !phys_cosp2'
- if (debut_cosp) then
+print*,'Entree lmdz_cosp_interface' !phys_cosp2'
+if (debut_cosp) then
   NPoints=Nptslmdz
   Nlevels=Nlevlmdz
@@ -261,21 +261,4 @@
     print*,'ok read  cosp_input_nl'
 
-
-!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-!
-! 2) Initialisation de COSPv2
-!
-! Il y a 2 options possibles pour ecrire les sorties : XIOS ou sorties standard
-!
-! Si le modele a ete compile AVEC l'option xios, le programme passe par les
-! bouts de code delimites par "#ifdef CPP_XIOS" et "#else". Dans ce cas,
-! l'initialisation de COSP se fait au deuxieme appel de cette interface.
-!
-! Si le modele a ete compile SANS l'option xios, le programme passe par les
-! bouts de code delimites par "#else" et "#endif". Dans ce cas,
-! l'initialisation de COSP se fait au premier appel de cette interface.
-!
-!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
 ! Clefs Outputs initialisation
 #ifdef CPP_XIOS
@@ -286,8 +269,8 @@
 
   print*,' Cles des differents simulateurs cosp a itap :',itap
-print*,'cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
+  print*,'cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
 	cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov', &
         cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
-	cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov
+        cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov
 
     if (overlaplmdz.ne.overlap) then
@@ -309,17 +292,17 @@
     call quickbeam_optics_init()
 
- print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag
+  print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag
   call COSP_INIT(cfg%Lisccp, cfg%Lmodis, cfg%Lmisr, cfg%Lcloudsat, cfg%Lcalipso, &
-       		 cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov,          &
-       		 cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs,         &
-       		 cloudsat_do_ray, isccp_topheight, isccp_topheight_direction,    &
-		 surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in,      &
-       		 niv_sorties, Nlevels, cloudsat_micro_scheme)
-cosp_init_flag = 1
+        cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov,          &
+        cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs,         &
+        cloudsat_do_ray, isccp_topheight, isccp_topheight_direction,    &
+        surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in,      &
+        niv_sorties, Nlevels, cloudsat_micro_scheme)
+  cosp_init_flag = 1
  print*,' just after call COSP_INIT, cosp_init_flag =', cosp_init_flag
 endif
 #endif
 
-   print*,'Fin lecture Namelists, debut_cosp =',debut_cosp
+  print*,'Fin lecture Namelists, debut_cosp =',debut_cosp
 
   endif ! debut_cosp
@@ -327,5 +310,5 @@
 
 !!! Ici on modifie les cles logiques pour les outputs selon les champs actives dans les .xml
-  if ((itap.gt.1).and.(first_write))then
+  if ((itap.ge.1).and.(first_write))then
 #ifdef CPP_XIOS
     call read_xiosfieldactive(cfg)
@@ -344,12 +327,12 @@
     call quickbeam_optics_init()
 
- print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag
+  print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag
   call COSP_INIT(cfg%Lisccp, cfg%Lmodis, cfg%Lmisr, cfg%Lcloudsat, cfg%Lcalipso, &
-       		 cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov,          &
-       		 cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs,         &
-       		 cloudsat_do_ray, isccp_topheight, isccp_topheight_direction,    &
-		 surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in,      &
-       		 niv_sorties, Nlevels, cloudsat_micro_scheme)
-cosp_init_flag = 1
+        cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov,          &
+        cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs,         &
+        cloudsat_do_ray, isccp_topheight, isccp_topheight_direction,    &
+        surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in,      &
+        niv_sorties, Nlevels, cloudsat_micro_scheme)
+  cosp_init_flag = 1
  print*,' just after call COSP_INIT, cosp_init_flag =', cosp_init_flag
 endif ! cosp_init_flag
@@ -573,5 +556,5 @@
        print *, 'Calling write output'
         call lmdz_cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, freq_COSP, &
-			            missing_val, cfg, niv_sorties, cospOUT)
+                                    missing_val, cfg, niv_sorties, cospOUT)
 
 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Index: LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_output_write_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_output_write_mod.F90	(revision 3702)
+++ LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_output_write_mod.F90	(revision 3723)
@@ -30,5 +30,5 @@
 
   SUBROUTINE lmdz_cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, freq_COSP, missing_cosp, &
-  				    cfg, Nlvgrid, cospOUT)
+                                    cfg, Nlvgrid, cospOUT)
 
 
@@ -41,8 +41,6 @@
   use mod_cosp,   only: cosp_outputs
 
-#ifdef CPP_XIOS
     USE wxios, only: wxios_closedef
     USE xios, only: xios_update_calendar, xios_field_is_active
-#endif
   IMPLICIT NONE  
 !!! Variables d'entree
@@ -62,13 +60,9 @@
 ! Variables locals intermidiaires pour inverser les axes des champs 4D
 ! Compatibilite avec sorties CMIP
-  real, dimension(Npoints,Nlevout,SR_BINS) :: tmp_fi4da_cfadL, tmp_fi4da_cfadLgr, tmp_fi4da_cfadLatlid
-  real, dimension(Npoints,Nlevout,CLOUDSAT_DBZE_BINS) :: tmp_fi4da_cfadR
+  real, dimension(Npoints,Nlvgrid,SR_BINS) :: tmp_fi4da_cfadL, tmp_fi4da_cfadLgr, tmp_fi4da_cfadLatlid
+  real, dimension(Npoints,Nlvgrid,CLOUDSAT_DBZE_BINS) :: tmp_fi4da_cfadR
   real, dimension(Npoints,numMISRHgtBins,7) :: tmp_fi4da_misr
 
-#ifdef CPP_XIOS
   missing_val=missing_cosp
-#else
-  missing_val=0.
-#endif
 
   Nlevout = Nlvgrid
@@ -90,137 +84,196 @@
     ok_sync = .TRUE.
     
-!DO iinit=1, iinitend
-! AI sept 2014 cette boucle supprimee
-! On n'ecrit pas quand itap=1 (cosp)
-
-!   if (prt_level >= 10) then
-!         WRITE(lunout,*)'DO iinit=1, iinitend ',iinitend
-!   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%Lcalipso) then
-!!! AI 02 2018 
-! Traitement missing_val
-!!!   where(stlidar%lidarcld == R_UNDEF) stlidar%lidarcld = missing_val
-!!!   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
-!!!   where(stlidar%cldlayerphase == R_UNDEF) stlidar%cldlayerphase = missing_val
-!!!   where(stlidar%lidarcldphase == R_UNDEF) stlidar%lidarcldphase = missing_val
-!   where(stlidar%lidarcldtype == R_UNDEF) stlidar%lidarcldtype = missing_val   !OPAQ
-!!!   where(stlidar%lidarcldtmp == R_UNDEF) stlidar%lidarcldtmp = missing_val
-
-!!! missing values pour toutes les valeurs R_UNDEF des variables de CALIPSO
-!   where(cospOUT%calipso_betaperp_tot == R_UNDEF) cospOUT%calipso_betaperp_tot = missing_val
-   where(cospOUT%calipso_beta_tot == R_UNDEF) cospOUT%calipso_beta_tot = missing_val
-   where(cospOUT%calipso_tau_tot == R_UNDEF) cospOUT%calipso_tau_tot = missing_val
-   where(cospOUT%calipso_lidarcldphase == R_UNDEF) cospOUT%calipso_lidarcldphase = missing_val
-   where(cospOUT%calipso_lidarcldtype == R_UNDEF) cospOUT%calipso_lidarcldtype = missing_val
-   where(cospOUT%calipso_cldlayerphase == R_UNDEF) cospOUT%calipso_cldlayerphase = missing_val
-   where(cospOUT%calipso_lidarcldtmp == R_UNDEF)    cospOUT%calipso_lidarcldtmp = missing_val
-   where(cospOUT%calipso_cfad_sr == R_UNDEF) 	    cospOUT%calipso_cfad_sr = missing_val
-   where(cospOUT%calipso_lidarcld == R_UNDEF) 	    cospOUT%calipso_lidarcld = missing_val
-   where(cospOUT%calipso_cldlayer == R_UNDEF)	    cospOUT%calipso_cldlayer = missing_val
-   where(cospOUT%calipso_cldtype == R_UNDEF)	    cospOUT%calipso_cldtype = missing_val
-   where(cospOUT%calipso_cldtypetemp == R_UNDEF)    cospOUT%calipso_cldtypetemp = missing_val
-   where(cospOUT%calipso_cldtypemeanz == R_UNDEF)   cospOUT%calipso_cldtypemeanz = missing_val
-   where(cospOUT%calipso_cldtypemeanzse == R_UNDEF) cospOUT%calipso_cldtypemeanzse = missing_val
-   where(cospOUT%calipso_beta_mol == R_UNDEF) 	    cospOUT%calipso_beta_mol = missing_val
-   where(cospOUT%calipso_temp_tot == R_UNDEF) 	    cospOUT%calipso_temp_tot = missing_val
-   where(cospOUT%calipso_cldthinemis == R_UNDEF)    cospOUT%calipso_cldthinemis = missing_val
-   where(cospOUT%calipso_srbval == R_UNDEF) 	    cospOUT%calipso_srbval = missing_val
-
 
 !   print*,'Appel histwrite2d_cosp'
-   if (cfg%Lcllcalipso) CALL histwrite2d_cosp(o_cllcalipso,cospOUT%calipso_cldlayer(:,1))
-   if (cfg%Lclhcalipso) CALL histwrite2d_cosp(o_clhcalipso,cospOUT%calipso_cldlayer(:,3))
-   if (cfg%Lclmcalipso) CALL histwrite2d_cosp(o_clmcalipso,cospOUT%calipso_cldlayer(:,2)) 
-   if (cfg%Lcltcalipso) CALL histwrite2d_cosp(o_cltcalipso,cospOUT%calipso_cldlayer(:,4))
-   if (cfg%Lclcalipso) CALL histwrite3d_cosp(o_clcalipso,cospOUT%calipso_lidarcld,nvert)
-   if (cfg%Lclcalipsotmp) CALL histwrite3d_cosp(o_clcalipsotmp,cospOUT%calipso_lidarcldtmp(:,:,1),nverttemp)
-
-   if (cfg%Lcllcalipsoice) CALL histwrite2d_cosp(o_cllcalipsoice,cospOUT%calipso_cldlayerphase(:,1,1))
-   if (cfg%Lclhcalipsoice) CALL histwrite2d_cosp(o_clhcalipsoice,cospOUT%calipso_cldlayerphase(:,3,1))
-   if (cfg%Lclmcalipsoice) CALL histwrite2d_cosp(o_clmcalipsoice,cospOUT%calipso_cldlayerphase(:,2,1))
-   if (cfg%Lcltcalipsoice) CALL histwrite2d_cosp(o_cltcalipsoice,cospOUT%calipso_cldlayerphase(:,4,1))
-   if (cfg%Lclcalipsoice) CALL histwrite3d_cosp(o_clcalipsoice,cospOUT%calipso_lidarcldphase(:,:,1),nvert)
-   if (cfg%Lclcalipsotmpice) CALL histwrite3d_cosp(o_clcalipsotmpice,cospOUT%calipso_lidarcldtmp(:,:,2),nverttemp)
-
-   if (cfg%Lcllcalipsoliq) CALL histwrite2d_cosp(o_cllcalipsoliq,cospOUT%calipso_cldlayerphase(:,1,2))
-   if (cfg%Lclhcalipsoliq) CALL histwrite2d_cosp(o_clhcalipsoliq,cospOUT%calipso_cldlayerphase(:,3,2))
-   if (cfg%Lclmcalipsoliq) CALL histwrite2d_cosp(o_clmcalipsoliq,cospOUT%calipso_cldlayerphase(:,2,2))
-   if (cfg%Lcltcalipsoliq) CALL histwrite2d_cosp(o_cltcalipsoliq,cospOUT%calipso_cldlayerphase(:,4,2))
-   if (cfg%Lclcalipsoliq) CALL histwrite3d_cosp(o_clcalipsoliq,cospOUT%calipso_lidarcldphase(:,:,2),nvert)
-   if (cfg%Lclcalipsotmpliq) CALL histwrite3d_cosp(o_clcalipsotmpliq,cospOUT%calipso_lidarcldtmp(:,:,3),nverttemp)
-
-   if (cfg%Lcllcalipsoun) CALL histwrite2d_cosp(o_cllcalipsoun,cospOUT%calipso_cldlayerphase(:,1,3))
-   if (cfg%Lclhcalipsoun) CALL histwrite2d_cosp(o_clhcalipsoun,cospOUT%calipso_cldlayerphase(:,3,3))
-   if (cfg%Lclmcalipsoun) CALL histwrite2d_cosp(o_clmcalipsoun,cospOUT%calipso_cldlayerphase(:,2,3))
-   if (cfg%Lcltcalipsoun) CALL histwrite2d_cosp(o_cltcalipsoun,cospOUT%calipso_cldlayerphase(:,4,3))
-   if (cfg%Lclcalipsoun) CALL histwrite3d_cosp(o_clcalipsoun,cospOUT%calipso_lidarcldphase(:,:,3),nvert)
-   if (cfg%Lclcalipsotmpun) CALL histwrite3d_cosp(o_clcalipsotmpun,cospOUT%calipso_lidarcldtmp(:,:,4),nverttemp)
-
-   if (cfg%Lclopaquecalipso) CALL histwrite2d_cosp(o_clopaquecalipso,cospOUT%calipso_cldtype(:,1))
-   if (cfg%Lclthincalipso) CALL histwrite2d_cosp(o_clthincalipso,cospOUT%calipso_cldtype(:,2))   
-   if (cfg%Lclzopaquecalipso) CALL histwrite2d_cosp(o_clzopaquecalipso,cospOUT%calipso_cldtype(:,3))
-   if (cfg%Lclcalipsoopaque) CALL histwrite3d_cosp(o_clcalipsoopaque,cospOUT%calipso_lidarcldtype(:,:,1),nvert)
-   if (cfg%Lclcalipsothin) CALL histwrite3d_cosp(o_clcalipsothin,cospOUT%calipso_lidarcldtype(:,:,2),nvert)  
-   if (cfg%Lclcalipsozopaque) CALL histwrite3d_cosp(o_clcalipsozopaque,cospOUT%calipso_lidarcldtype(:,:,3),nvert)
-   if (cfg%Lclcalipsoopacity) CALL histwrite3d_cosp(o_clcalipsoopacity,cospOUT%calipso_lidarcldtype(:,:,4),nvert)
-
-   if (cfg%Lclopaquetemp) CALL histwrite2d_cosp(o_clopaquetemp,cospOUT%calipso_cldtypetemp(:,1))
-   if (cfg%Lclthintemp) CALL histwrite2d_cosp(o_clthintemp,cospOUT%calipso_cldtypetemp(:,2))
-   if (cfg%Lclzopaquetemp) CALL histwrite2d_cosp(o_clzopaquetemp,cospOUT%calipso_cldtypetemp(:,3))
-   if (cfg%Lclopaquemeanz) CALL histwrite2d_cosp(o_clopaquemeanz,cospOUT%calipso_cldtypemeanz(:,1))
-   if (cfg%Lclthinmeanz) CALL histwrite2d_cosp(o_clthinmeanz,cospOUT%calipso_cldtypemeanz(:,2))
-   if (cfg%Lclthinemis) CALL histwrite2d_cosp(o_clthinemis,cospOUT%calipso_cldthinemis)
-   if (cfg%Lclopaquemeanzse) CALL histwrite2d_cosp(o_clopaquemeanzse,cospOUT%calipso_cldtypemeanzse(:,1))
-   if (cfg%Lclthinmeanzse) CALL histwrite2d_cosp(o_clthinmeanzse,cospOUT%calipso_cldtypemeanzse(:,2))
-   if (cfg%Lclzopaquecalipsose) CALL histwrite2d_cosp(o_clzopaquecalipsose,cospOUT%calipso_cldtypemeanzse(:,3))
-
-
-#ifdef CPP_XIOS
-   do icl=1,SR_BINS
-      tmp_fi4da_cfadL(:,:,icl)=cospOUT%calipso_cfad_sr(:,icl,:)
-   enddo
+   if (cfg%Lcllcalipso) then 
+      where(cospOUT%calipso_cldlayer(:,1) == R_UNDEF) cospOUT%calipso_cldlayer(:,1) = missing_val
+      CALL histwrite2d_cosp(o_cllcalipso,cospOUT%calipso_cldlayer(:,1))
+   endif
+   if (cfg%Lclhcalipso) then 
+      where(cospOUT%calipso_cldlayer(:,3) == R_UNDEF) cospOUT%calipso_cldlayer(:,3) = missing_val
+      CALL histwrite2d_cosp(o_clhcalipso,cospOUT%calipso_cldlayer(:,3))
+   endif
+   if (cfg%Lclmcalipso) then
+      where(cospOUT%calipso_cldlayer(:,2) == R_UNDEF) cospOUT%calipso_cldlayer(:,2) = missing_val
+      CALL histwrite2d_cosp(o_clmcalipso,cospOUT%calipso_cldlayer(:,2)) 
+   endif
+   if (cfg%Lcltcalipso) then
+      where(cospOUT%calipso_cldlayer(:,4) == R_UNDEF) cospOUT%calipso_cldlayer(:,4) = missing_val
+      CALL histwrite2d_cosp(o_cltcalipso,cospOUT%calipso_cldlayer(:,4))
+   endif
+   if (cfg%Lclcalipso) then 
+      where(cospOUT%calipso_lidarcld == R_UNDEF)    cospOUT%calipso_lidarcld = missing_val
+      CALL histwrite3d_cosp(o_clcalipso,cospOUT%calipso_lidarcld,nvert)
+   endif
+   if (cfg%Lclcalipsotmp) then
+      where(cospOUT%calipso_lidarcldtmp(:,:,1) == R_UNDEF) cospOUT%calipso_lidarcldtmp(:,:,1) = missing_val
+      CALL histwrite3d_cosp(o_clcalipsotmp,cospOUT%calipso_lidarcldtmp(:,:,1),nverttemp)
+   endif
+
+   if (cfg%Lcllcalipsoice) then
+      where(cospOUT%calipso_cldlayerphase(:,1,1) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,1,1) = missing_val
+      CALL histwrite2d_cosp(o_cllcalipsoice,cospOUT%calipso_cldlayerphase(:,1,1))
+   endif
+   if (cfg%Lclhcalipsoice) then
+      where(cospOUT%calipso_cldlayerphase(:,3,1) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,3,1) = missing_val 
+      CALL histwrite2d_cosp(o_clhcalipsoice,cospOUT%calipso_cldlayerphase(:,3,1))
+   endif
+   if (cfg%Lclmcalipsoice) then
+      where(cospOUT%calipso_cldlayerphase(:,2,1) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,2,1) = missing_val
+      CALL histwrite2d_cosp(o_clmcalipsoice,cospOUT%calipso_cldlayerphase(:,2,1))
+   endif
+   if (cfg%Lcltcalipsoice) then
+      where(cospOUT%calipso_cldlayerphase(:,4,1) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,4,1) = missing_val
+      CALL histwrite2d_cosp(o_cltcalipsoice,cospOUT%calipso_cldlayerphase(:,4,1))
+   endif
+   if (cfg%Lclcalipsoice) then 
+      where(cospOUT%calipso_lidarcldphase(:,:,1) == R_UNDEF) cospOUT%calipso_lidarcldphase(:,:,1) = missing_val
+      CALL histwrite3d_cosp(o_clcalipsoice,cospOUT%calipso_lidarcldphase(:,:,1),nvert)
+   endif
+   if (cfg%Lclcalipsotmpice) then
+      where(cospOUT%calipso_lidarcldtmp(:,:,2) == R_UNDEF) cospOUT%calipso_lidarcldtmp(:,:,2) = missing_val
+      CALL histwrite3d_cosp(o_clcalipsotmpice,cospOUT%calipso_lidarcldtmp(:,:,2),nverttemp)
+   endif
+
+   if (cfg%Lcllcalipsoliq) then
+      where(cospOUT%calipso_cldlayerphase(:,1,2) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,1,2) = missing_val
+      CALL histwrite2d_cosp(o_cllcalipsoliq,cospOUT%calipso_cldlayerphase(:,1,2))
+   endif
+   if (cfg%Lclhcalipsoliq) then 
+      where(cospOUT%calipso_cldlayerphase(:,3,2) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,3,2) = missing_val
+      CALL histwrite2d_cosp(o_clhcalipsoliq,cospOUT%calipso_cldlayerphase(:,3,2))
+   endif
+   if (cfg%Lclmcalipsoliq) then 
+      where(cospOUT%calipso_cldlayerphase(:,2,2) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,2,2) = missing_val
+      CALL histwrite2d_cosp(o_clmcalipsoliq,cospOUT%calipso_cldlayerphase(:,2,2))
+   endif
+   if (cfg%Lcltcalipsoliq) then
+      where(cospOUT%calipso_cldlayerphase(:,4,2) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,4,2) = missing_val
+      CALL histwrite2d_cosp(o_cltcalipsoliq,cospOUT%calipso_cldlayerphase(:,4,2))
+   endif
+   if (cfg%Lclcalipsoliq) then
+      where(cospOUT%calipso_lidarcldphase(:,:,2) == R_UNDEF) cospOUT%calipso_lidarcldphase(:,:,2) = missing_val
+      CALL histwrite3d_cosp(o_clcalipsoliq,cospOUT%calipso_lidarcldphase(:,:,2),nvert)
+   endif
+   if (cfg%Lclcalipsotmpliq) then
+      where(cospOUT%calipso_lidarcldtmp(:,:,3) == R_UNDEF) cospOUT%calipso_lidarcldtmp(:,:,3) = missing_val
+      CALL histwrite3d_cosp(o_clcalipsotmpliq,cospOUT%calipso_lidarcldtmp(:,:,3),nverttemp)
+   endif
+   if (cfg%Lcllcalipsoun) then
+      where(cospOUT%calipso_cldlayerphase(:,1,3) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,1,3) = missing_val
+      CALL histwrite2d_cosp(o_cllcalipsoun,cospOUT%calipso_cldlayerphase(:,1,3))
+   endif 
+   if (cfg%Lclhcalipsoun) then
+      where(cospOUT%calipso_cldlayerphase(:,3,3) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,3,3) = missing_val
+      CALL histwrite2d_cosp(o_clhcalipsoun,cospOUT%calipso_cldlayerphase(:,3,3))
+   endif
+   if (cfg%Lclmcalipsoun) then 
+      where(cospOUT%calipso_cldlayerphase(:,2,3) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,2,3) = missing_val
+      CALL histwrite2d_cosp(o_clmcalipsoun,cospOUT%calipso_cldlayerphase(:,2,3))
+   endif
+   if (cfg%Lcltcalipsoun) then
+      where(cospOUT%calipso_cldlayerphase(:,4,3) == R_UNDEF) cospOUT%calipso_cldlayerphase(:,4,3) = missing_val
+      CALL histwrite2d_cosp(o_cltcalipsoun,cospOUT%calipso_cldlayerphase(:,4,3))
+   endif
+   if (cfg%Lclcalipsoun) then 
+      where(cospOUT%calipso_lidarcldphase(:,:,3) == R_UNDEF) cospOUT%calipso_lidarcldphase(:,:,3) = missing_val
+      CALL histwrite3d_cosp(o_clcalipsoun,cospOUT%calipso_lidarcldphase(:,:,3),nvert)
+   endif
+   if (cfg%Lclcalipsotmpun) then
+      where(cospOUT%calipso_lidarcldtmp(:,:,4) == R_UNDEF) cospOUT%calipso_lidarcldtmp(:,:,4) = missing_val
+      CALL histwrite3d_cosp(o_clcalipsotmpun,cospOUT%calipso_lidarcldtmp(:,:,4),nverttemp)
+   endif
+
+   if (cfg%Lclopaquecalipso) then 
+      where(cospOUT%calipso_cldtype(:,1) == R_UNDEF) cospOUT%calipso_cldtype(:,1) = missing_val
+      CALL histwrite2d_cosp(o_clopaquecalipso,cospOUT%calipso_cldtype(:,1))
+   endif
+   if (cfg%Lclthincalipso) then
+      where(cospOUT%calipso_cldtype(:,2) == R_UNDEF) cospOUT%calipso_cldtype(:,2) = missing_val
+      CALL histwrite2d_cosp(o_clthincalipso,cospOUT%calipso_cldtype(:,2))   
+   endif
+   if (cfg%Lclzopaquecalipso) then
+      where(cospOUT%calipso_cldtype(:,3) == R_UNDEF) cospOUT%calipso_cldtype(:,3) = missing_val      
+      CALL histwrite2d_cosp(o_clzopaquecalipso,cospOUT%calipso_cldtype(:,3))
+   endif
+   if (cfg%Lclcalipsoopaque) then
+      where(cospOUT%calipso_lidarcldtype(:,:,1) == R_UNDEF) cospOUT%calipso_lidarcldtype(:,:,1) = missing_val      
+      CALL histwrite3d_cosp(o_clcalipsoopaque,cospOUT%calipso_lidarcldtype(:,:,1),nvert)
+   endif
+   if (cfg%Lclcalipsothin) then
+      where(cospOUT%calipso_lidarcldtype(:,:,2) == R_UNDEF) cospOUT%calipso_lidarcldtype(:,:,2) = missing_val
+      CALL histwrite3d_cosp(o_clcalipsothin,cospOUT%calipso_lidarcldtype(:,:,2),nvert)  
+   endif
+   if (cfg%Lclcalipsozopaque) then
+      where(cospOUT%calipso_lidarcldtype(:,:,3) == R_UNDEF) cospOUT%calipso_lidarcldtype(:,:,3) = missing_val
+      CALL histwrite3d_cosp(o_clcalipsozopaque,cospOUT%calipso_lidarcldtype(:,:,3),nvert)
+   endif
+   if (cfg%Lclcalipsoopacity) then
+      where(cospOUT%calipso_lidarcldtype(:,:,4) == R_UNDEF) cospOUT%calipso_lidarcldtype(:,:,4) = missing_val
+      CALL histwrite3d_cosp(o_clcalipsoopacity,cospOUT%calipso_lidarcldtype(:,:,4),nvert)
+   endif
+
+   if (cfg%Lclopaquetemp) then 
+      where(cospOUT%calipso_cldtypetemp(:,1) == R_UNDEF) cospOUT%calipso_cldtypetemp(:,1) = missing_val
+      CALL histwrite2d_cosp(o_clopaquetemp,cospOUT%calipso_cldtypetemp(:,1))
+   endif
+   if (cfg%Lclthintemp) then 
+      where(cospOUT%calipso_cldtypetemp(:,2) == R_UNDEF) cospOUT%calipso_cldtypetemp(:,2) = missing_val
+      CALL histwrite2d_cosp(o_clthintemp,cospOUT%calipso_cldtypetemp(:,2))
+   endif 
+   if (cfg%Lclzopaquetemp) then
+      where(cospOUT%calipso_cldtypetemp(:,3) == R_UNDEF) cospOUT%calipso_cldtypetemp(:,3) = missing_val
+      CALL histwrite2d_cosp(o_clzopaquetemp,cospOUT%calipso_cldtypetemp(:,3))
+   endif
+   if (cfg%Lclopaquemeanz) then
+      where(cospOUT%calipso_cldtypemeanz(:,1) == R_UNDEF) cospOUT%calipso_cldtypemeanz(:,1) = missing_val
+      CALL histwrite2d_cosp(o_clopaquemeanz,cospOUT%calipso_cldtypemeanz(:,1))
+   endif
+   if (cfg%Lclthinmeanz) then
+      where(cospOUT%calipso_cldtypemeanz(:,2) == R_UNDEF) cospOUT%calipso_cldtypemeanz(:,2) = missing_val
+      CALL histwrite2d_cosp(o_clthinmeanz,cospOUT%calipso_cldtypemeanz(:,2))
+   endif
+   if (cfg%Lclthinemis) then 
+      where(cospOUT%calipso_cldthinemis == R_UNDEF) cospOUT%calipso_cldthinemis = missing_val
+      CALL histwrite2d_cosp(o_clthinemis,cospOUT%calipso_cldthinemis)
+   endif
+   if (cfg%Lclopaquemeanzse) then
+      where(cospOUT%calipso_cldtypemeanzse(:,1) == R_UNDEF) cospOUT%calipso_cldtypemeanzse(:,1) = missing_val
+      CALL histwrite2d_cosp(o_clopaquemeanzse,cospOUT%calipso_cldtypemeanzse(:,1))
+   endif
+   if (cfg%Lclthinmeanzse) then
+      where(cospOUT%calipso_cldtypemeanzse(:,2) == R_UNDEF) cospOUT%calipso_cldtypemeanzse(:,2) = missing_val
+      CALL histwrite2d_cosp(o_clthinmeanzse,cospOUT%calipso_cldtypemeanzse(:,2))
+   endif
+   if (cfg%Lclzopaquecalipsose) then 
+      where(cospOUT%calipso_cldtypemeanzse(:,3) == R_UNDEF) cospOUT%calipso_cldtypemeanzse(:,3) = missing_val
+      CALL histwrite2d_cosp(o_clzopaquecalipsose,cospOUT%calipso_cldtypemeanzse(:,3))
+   endif
+
+
+   if (cfg%LcfadLidarsr532) then 
+     where(cospOUT%calipso_cfad_sr == R_UNDEF) cospOUT%calipso_cfad_sr = missing_val
+    
+     do icl=1,SR_BINS
+      do k=1,Nlvgrid
+       do ip=1,Npoints
+        tmp_fi4da_cfadL(ip,k,icl)=cospOUT%calipso_cfad_sr(ip,icl,k)
+       enddo
+      enddo
+     enddo
 !   if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr)
-   if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfadLidarsr532,tmp_fi4da_cfadL)   !!! "_" enleve
-#else
-   if (cfg%LcfadLidarsr532) then
-     do icl=1,SR_BINS
-        CALL histwrite3d_cosp(o_cfadLidarsr532,cospOUT%calipso_cfad_sr(:,icl,:),nvert,icl)   !!! "_" enleve
-     enddo
-   endif
-#endif
-
-#ifdef CPP_XIOS
-   if (cfg%Latb532) CALL histwrite4d_cosp(o_atb532,cospOUT%calipso_beta_tot)
-#else
+    CALL histwrite4d_cosp(o_cfadLidarsr532,tmp_fi4da_cfadL)   !!! "_" enleve
+   endif
+
    if (cfg%Latb532) then  
-     do icl=1,Ncolumns 
-        CALL histwrite3d_cosp(o_atb532,cospOUT%calipso_beta_tot(:,icl,:),nvertmcosp,icl)
-     enddo
-   endif 
-#endif
-
-   if (cfg%LlidarBetaMol532) CALL histwrite3d_cosp(o_lidarBetaMol532,cospOUT%calipso_beta_mol,nvertmcosp) 
+     where(cospOUT%calipso_beta_tot == R_UNDEF) cospOUT%calipso_beta_tot = missing_val
+     CALL histwrite4d_cosp(o_atb532,cospOUT%calipso_beta_tot)
+   endif
+   if (cfg%LlidarBetaMol532) then 
+     where(cospOUT%calipso_tau_tot == R_UNDEF) cospOUT%calipso_tau_tot = missing_val
+     CALL histwrite3d_cosp(o_lidarBetaMol532,cospOUT%calipso_beta_mol,nvertmcosp) 
+   endif
 
  endif !Calipso
@@ -245,26 +298,14 @@
    if (cfg%LlidarBetaMol532gr) CALL histwrite3d_cosp(o_lidarBetaMol532gr,cospOUT%grLidar532_beta_mol,nvertmcosp) 
 
-#ifdef CPP_XIOS
    do icl=1,SR_BINS
-      tmp_fi4da_cfadLgr(:,:,icl)=cospOUT%grLidar532_cfad_sr(:,icl,:)
+      do k=1,Nlvgrid
+       do ip=1,Npoints
+         tmp_fi4da_cfadLgr(ip,k,icl)=cospOUT%grLidar532_cfad_sr(ip,icl,k)
+       enddo
+      enddo
    enddo
    if (cfg%LcfadLidarsr532gr) CALL histwrite4d_cosp(o_cfadLidarsr532gr,tmp_fi4da_cfadLgr)
-#else
-   if (cfg%LcfadLidarsr532gr) then
-     do icl=1,SR_BINS
-        CALL histwrite3d_cosp(o_cfadLidarsr532gr,cospOUT%grLidar532_cfad_sr(:,icl,:),nvert,icl)
-     enddo
-   endif
-#endif
-
-#ifdef CPP_XIOS
+
    if (cfg%Latb532gr) CALL histwrite4d_cosp(o_atb532gr,cospOUT%grLidar532_beta_tot)
-#else
-   if (cfg%Latb532gr) then  
-     do icl=1,Ncolumns 
-        CALL histwrite3d_cosp(o_atb532gr,cospOUT%grLidar532_beta_tot(:,icl,:),nvertmcosp,icl)
-     enddo
-   endif 
-#endif
 
 endif ! Ground Lidar 532 nm
@@ -289,26 +330,14 @@
    if (cfg%LlidarBetaMol355) CALL histwrite3d_cosp(o_lidarBetaMol355,cospOUT%atlid_beta_mol,nvertmcosp) 
 
-#ifdef CPP_XIOS
    do icl=1,SR_BINS
-      tmp_fi4da_cfadLatlid(:,:,icl)=cospOUT%atlid_cfad_sr(:,icl,:)
+      do k=1,Nlvgrid
+       do ip=1,Npoints
+          tmp_fi4da_cfadLatlid(ip,k,icl)=cospOUT%atlid_cfad_sr(ip,icl,k)
+       enddo
+      enddo
    enddo
    if (cfg%LcfadLidarsr355) CALL histwrite4d_cosp(o_cfadlidarsr355,tmp_fi4da_cfadLatlid)
-#else
-   if (cfg%LcfadLidarsr355) then
-     do icl=1,SR_BINS
-        CALL histwrite3d_cosp(o_cfadlidarsr355,cospOUT%atlid_cfad_sr(:,icl,:),nvert,icl)
-     enddo
-   endif
-#endif
-
-#ifdef CPP_XIOS
+
    if (cfg%Latb355) CALL histwrite4d_cosp(o_atb355,cospOUT%atlid_beta_tot)
-#else
-   if (cfg%Latb355) then  
-     do icl=1,Ncolumns 
-        CALL histwrite3d_cosp(o_atb355,cospOUT%atlid_beta_tot(:,icl,:),nvertmcosp,icl)
-     enddo
-   endif 
-#endif
 
 endif ! Atlid
@@ -322,11 +351,5 @@
      CALL histwrite3d_cosp(o_parasolGrid_refl,cospOUT%parasolGrid_refl,nvertp)
 
-#ifdef CPP_XIOS
      CALL histwrite4d_cosp(o_parasolPix_refl,cospOUT%parasolPix_refl)
-#else 
-     do icl=1,Ncolumns 
-        CALL histwrite3d_cosp(o_parasolPix_refl,cospOUT%parasolPix_refl(:,icl,:),nvertp,icl)
-     enddo
-#endif
 
     endif ! LparasolRefl
@@ -371,23 +394,14 @@
    if (cfg%Lradarpia) CALL histwrite2d_cosp(o_radarpia,cospOUT%cloudsat_pia)
 
-#ifdef CPP_XIOS
    do icl=1,CLOUDSAT_DBZE_BINS
-     tmp_fi4da_cfadR(:,:,icl)=cospOUT%cloudsat_cfad_ze(:,icl,:)
+      do k=1,Nlvgrid
+       do ip=1,Npoints
+         tmp_fi4da_cfadR(ip,k,icl)=cospOUT%cloudsat_cfad_ze(ip,icl,k)
+       enddo
+      enddo
    enddo
    if (cfg%Ldbze94) CALL histwrite4d_cosp(o_dbze94,cospOUT%cloudsat_Ze_tot)
 !   if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,stradar%cfad_ze)
    if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,tmp_fi4da_cfadR)
-#else
-   if (cfg%Ldbze94) then
-    do icl=1,Ncolumns
-       CALL histwrite3d_cosp(o_dbze94,cospOUT%cloudsat_Ze_tot(:,icl,:),nvert,icl)
-    enddo
-   endif
-   if (cfg%LcfadDbze94) then
-    do icl=1,CLOUDSAT_DBZE_BINS
-    CALL histwrite3d_cosp(o_cfadDbze94,cospOUT%cloudsat_cfad_ze(:,icl,:),nvert,icl)
-    enddo
-   endif
-#endif
  endif
 ! endif pour CloudSat
@@ -425,13 +439,5 @@
 
 !   CALL histwrite2d_cosp(o_sunlit,gbx%sunlit)
-#ifdef CPP_XIOS
   if (cfg%Lclisccp) CALL histwrite4d_cosp(o_clisccp,cospOUT%isccp_fq)
-#else
-   if (cfg%Lclisccp) then
-     do icl=1,7
-       CALL histwrite3d_cosp(o_clisccp,cospOUT%isccp_fq(:,icl,:),nvertisccp,icl) 
-     enddo
-   endif
-#endif
 
    if (cfg%Lboxtauisccp) CALL histwrite3d_cosp(o_boxtauisccp,cospOUT%isccp_boxtau,nvertcol)
@@ -456,16 +462,14 @@
    where(cospOUT%misr_cldarea == R_UNDEF) cospOUT%misr_cldarea = missing_val
 
-#ifdef CPP_XIOS
    do icl=1,numMISRHgtBins
-      tmp_fi4da_misr(:,icl,:)=cospOUT%misr_fq(:,:,icl)
+      do k=1,Nlvgrid
+       do ip=1,Npoints    
+      tmp_fi4da_misr(ip,icl,k)=cospOUT%misr_fq(ip,k,icl)
+       enddo
+      enddo
    enddo
 !   if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,misr%fq_MISR)
 !   if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,tmp_fi4da_misr)
    CALL histwrite4d_cosp(o_misr_fq,tmp_fi4da_misr)
-#else
-    do icl=1,7 
-      CALL histwrite3d_cosp(o_misr_fq,cospOUT%misr_fq(:,icl,:),nvertmisr,icl)
-    enddo
-#endif
 
    CALL histwrite2d_cosp(o_misr_meanztop,cospOUT%misr_meanztop) 
@@ -540,36 +544,8 @@
           cospOUT%modis_Optical_thickness_vs_ReffLIQ = missing_val
 
-#ifdef CPP_XIOS
     CALL histwrite4d_cosp(o_modis_ot_vs_ctp,cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure)
     CALL histwrite4d_cosp(o_modis_ot_vs_reffice,cospOUT%modis_Optical_Thickness_vs_ReffICE)
     CALL histwrite4d_cosp(o_modis_ot_vs_reffliq,cospOUT%modis_Optical_thickness_vs_ReffLIQ)
-#else
-   do icl=1,7
-   CALL histwrite3d_cosp(o_modis_ot_vs_ctp, &
-     cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(:,icl,:),nvertisccp,icl)
-   CALL histwrite3d_cosp(o_modis_ot_vs_reffice, &
-     cospOUT%modis_Optical_Thickness_vs_ReffICE(:,icl,:),nvertReffIce,icl)
-   CALL histwrite3d_cosp(o_modis_ot_vs_reffliq, &
-     cospOUT%modis_Optical_thickness_vs_ReffLIQ(:,icl,:),nvertReffLiq,icl)
-   enddo
-#endif
-
-!#ifdef CPP_XIOS
-!  if (cfg%Lclmodis) CALL histwrite4d_cosp(o_crimodis,modis%Optical_Thickness_vs_ReffIce)
-!  if (cfg%Lclmodis) CALL histwrite4d_cosp(o_crlmodis,modis%Optical_Thickness_vs_ReffLiq)
-!#else
-!  if (cfg%Lclmodis) then
-!    do icl=1,7
-!     CALL histwrite3d_cosp(o_crimodis, &
-!          modis%Optical_Thickness_vs_ReffIce(:,icl,:),nvertReffIce,icl)
-!    enddo
-!  endif
-!  if (cfg%Lclmodis) then
-!    do icl=1,7 
-!     CALL histwrite3d_cosp(o_crlmodis, &
-!          modis%Optical_Thickness_vs_ReffLiq(:,icl,:),nvertReffLiq,icl)
-!    enddo
-!  endif 
-!#endif
+
   endif ! Lclmodis
 
@@ -579,13 +555,6 @@
  IF(.NOT.cosp_varsdefined) THEN
 !$OMP MASTER
-#ifndef CPP_IOIPSL_NO_OUTPUT
-            DO iff=1,3
-                IF (cosp_outfilekeys(iff)) THEN
-                  CALL histend(cosp_nidfiles(iff))
-                ENDIF ! cosp_outfilekeys
-            ENDDO !  iff
-#endif
 ! Fermeture dans phys_output_write
-!#ifdef CPP_XIOS
+!#ifdef 1
             !On finalise l'initialisation:
             !CALL wxios_closedef()
@@ -599,13 +568,4 @@
     IF(cosp_varsdefined) THEN
 ! On synchronise les fichiers pour IOIPSL
-#ifndef CPP_IOIPSL_NO_OUTPUT 
-!$OMP MASTER
-     DO iff=1,3
-         IF (ok_sync .AND. cosp_outfilekeys(iff)) THEN
-             CALL histsync(cosp_nidfiles(iff))
-         ENDIF
-     END DO
-!$OMP END MASTER
-#endif
     ENDIF  !cosp_varsdefined
 
@@ -628,7 +588,5 @@
     USE mod_grid_phy_lmdz, ONLY: nbp_lon
     USE print_control_mod, ONLY: lunout,prt_level
-#ifdef CPP_XIOS
   USE wxios
-#endif
 
     IMPLICIT NONE
@@ -662,5 +620,4 @@
     ENDIF
 
-#ifdef CPP_XIOS
      IF (.not. ok_all_xml) then
        IF ( var%cles(iff) ) THEN
@@ -672,13 +629,5 @@
        ENDIF
      ENDIF
-#endif
-
-#ifndef CPP_IOIPSL_NO_OUTPUT 
-       IF ( var%cles(iff) ) THEN
-          CALL histdef (cosp_nidfiles(iff), var%name, var%description, var%unit, &
-               nbp_lon,jj_nb,nhoricosp(iff), 1,1,1, -99, 32, &
-               typeecrit, zstophym,zoutm_cosp(iff))
-       ENDIF
-#endif
+
 
   END SUBROUTINE histdef2d_cosp
@@ -693,7 +642,5 @@
     USE print_control_mod, ONLY: lunout,prt_level
 
-#ifdef CPP_XIOS
   USE wxios
-#endif
 
 
@@ -769,5 +716,4 @@
     ENDIF
 
-#ifdef CPP_XIOS
       IF (.not. ok_all_xml) then
         IF ( var%cles(iff) ) THEN
@@ -779,14 +725,5 @@
         ENDIF
       ENDIF
-#endif
-
-#ifndef CPP_IOIPSL_NO_OUTPUT
-       IF ( var%cles(iff) ) THEN
-          CALL histdef (cosp_nidfiles(iff), nom, var%description, var%unit, &
-               nbp_lon, jj_nb, nhoricosp(iff), klevs, 1, &
-               klevs, nvertsave, 32, typeecrit, &
-               zstophym, zoutm_cosp(iff))
-       ENDIF
-#endif
+
 
   END SUBROUTINE histdef3d_cosp
@@ -801,7 +738,5 @@
   USE print_control_mod, ONLY: lunout,prt_level
 
-#ifdef CPP_XIOS
   USE xios, only: xios_send_field
-#endif
 
   IMPLICIT NONE
@@ -826,4 +761,5 @@
   IF(.NOT.cosp_varsdefined) THEN
 !$OMP MASTER
+      print*,'var, cosp_varsdefined dans cosp_varsdefined ',var%name, cosp_varsdefined
       !Si phase de dÃ©finition.... on dÃ©finit
       CALL conf_cospoutputs(var%name,var%cles)
@@ -848,9 +784,5 @@
            IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
                 ALLOCATE(index2d(nbp_lon*jj_nb))
-#ifndef CPP_IOIPSL_NO_OUTPUT
-        CALL histwrite(cosp_nidfiles(iff),var%name,itau_iocosp,Field2d,nbp_lon*jj_nb,index2d) 
-#endif
                 deallocate(index2d)
-#ifdef CPP_XIOS
               IF (.not. ok_all_xml) then
                  if (firstx) then
@@ -862,9 +794,7 @@
                  endif
               ENDIF
-#endif
            ENDIF
       ENDDO 
 
-#ifdef CPP_XIOS
       IF (ok_all_xml) THEN
         if (prt_level >= 1) then
@@ -873,5 +803,4 @@
        CALL xios_send_field(var%name, Field2d)
       ENDIF
-#endif
 
 !$OMP END MASTER   
@@ -891,7 +820,5 @@
   USE print_control_mod, ONLY: lunout,prt_level
 
-#ifdef CPP_XIOS
   USE xios, only: xios_send_field
-#endif
 
 
@@ -952,9 +879,5 @@
         IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
            ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
-#ifndef CPP_IOIPSL_NO_OUTPUT
-    CALL histwrite(cosp_nidfiles(iff),nom,itau_iocosp,Field3d,nbp_lon*jj_nb*nlev,index3d) 
-#endif
-
-#ifdef CPP_XIOS
+
           IF (.not. ok_all_xml) then
            IF (firstx) THEN
@@ -964,14 +887,11 @@
            ENDIF
           ENDIF
-#endif
          deallocate(index3d)
         ENDIF
       ENDDO
-#ifdef CPP_XIOS
     IF (ok_all_xml) THEN
      CALL xios_send_field(nom, Field3d(:,:,1:nlev))
      IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
     ENDIF
-#endif
 
 !$OMP END MASTER   
@@ -991,7 +911,5 @@
   USE print_control_mod, ONLY: lunout,prt_level
 
-#ifdef CPP_XIOS
   USE xios, only: xios_send_field
-#endif
 
 
@@ -1023,10 +941,8 @@
     CALL grid1Dto2D_mpi(buffer_omp,field4d)
 
-#ifdef CPP_XIOS
 !    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
 
 !$OMP END MASTER   
