Index: LMDZ5/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 2760)
+++ LMDZ5/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 2794)
@@ -17,5 +17,5 @@
    CONTAINS
 
-  SUBROUTINE cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, freq_COSP, &
+  SUBROUTINE cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, freq_COSP, missing_val, &
                                cfg, gbx, vgrid, sglidar, sgradar, stlidar, stradar, &
                                isccp, misr, modis)
@@ -32,5 +32,5 @@
 !!! Variables d'entree
   integer               :: itap, Nlevlmdz, Ncolumns, Npoints
-  real                  :: freq_COSP, dtime
+  real                  :: freq_COSP, dtime, missing_val
   type(cosp_config)     :: cfg     ! Control outputs
   type(cosp_gridbox)    :: gbx     ! Gridbox information. Input for COSP
@@ -95,5 +95,5 @@
      do ip = 1,Npoints
      if(stlidar%lidarcld(ip,k).eq.R_UNDEF)then
-      stlidar%lidarcld(ip,k)=Cosp_fill_value
+      stlidar%lidarcld(ip,k)=missing_val
      endif
      enddo
@@ -102,5 +102,5 @@
       do ip = 1,Npoints
        if(stlidar%cfad_sr(ip,ii,k).eq.R_UNDEF)then
-        stlidar%cfad_sr(ip,ii,k)=Cosp_fill_value
+        stlidar%cfad_sr(ip,ii,k)=missing_val
        endif
       enddo
@@ -111,10 +111,10 @@
    do k = 1,Nlevlmdz
      if(sglidar%beta_mol(ip,k).eq.R_UNDEF)then
-      sglidar%beta_mol(ip,k)=Cosp_fill_value
+      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)=Cosp_fill_value
+        sglidar%beta_tot(ip,ii,k)=missing_val
        endif
      enddo
@@ -126,5 +126,5 @@
     do ip = 1,Npoints
      if(stlidar%cldlayer(ip,k).eq.R_UNDEF)then
-      stlidar%cldlayer(ip,k)=Cosp_fill_value
+       stlidar%cldlayer(ip,k)=missing_val
      endif
     enddo
@@ -133,9 +133,9 @@
 ! AI 11 / 2015
 
-   where(stlidar%parasolrefl == R_UNDEF) stlidar%parasolrefl = 0.0
-   where(stlidar%lidarcldtmp == R_UNDEF) stlidar%lidarcldtmp = 0.0
-   where(stlidar%cldlayerphase == R_UNDEF) stlidar%cldlayerphase = 0.0
-   where(stlidar%lidarcldphase == R_UNDEF) stlidar%lidarcldphase = 0.0
-   where(stlidar%lidarcldtmp == R_UNDEF) stlidar%lidarcldtmp = 0.0
+   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%lidarcldtmp == R_UNDEF) stlidar%lidarcldtmp = missing_val
    
 
@@ -207,8 +207,8 @@
  if (cfg%Llidar_sim .and. cfg%Lradar_sim) then
    where(stradar%lidar_only_freq_cloud == R_UNDEF) &
-                           stradar%lidar_only_freq_cloud = 0.0
+                           stradar%lidar_only_freq_cloud = missing_val
    CALL histwrite3d_cosp(o_clcalipso2,stradar%lidar_only_freq_cloud,nvert)
    where(stradar%radar_lidar_tcc == R_UNDEF) &
-                           stradar%radar_lidar_tcc = 0.0 
+                           stradar%radar_lidar_tcc = missing_val
    CALL histwrite2d_cosp(o_cltlidarradar,stradar%radar_lidar_tcc)
  endif
@@ -219,20 +219,20 @@
    do ip = 1,Npoints
     if(isccp%totalcldarea(ip).eq.R_UNDEF)then
-      isccp%totalcldarea(ip)=Cosp_fill_value
+      isccp%totalcldarea(ip)=missing_val
     endif
     if(isccp%meanptop(ip).eq.R_UNDEF)then
-      isccp%meanptop(ip)=Cosp_fill_value
+      isccp%meanptop(ip)=missing_val
     endif
     if(isccp%meantaucld(ip).eq.R_UNDEF)then
-      isccp%meantaucld(ip)=Cosp_fill_value
+      isccp%meantaucld(ip)=missing_val
     endif
     if(isccp%meanalbedocld(ip).eq.R_UNDEF)then
-      isccp%meanalbedocld(ip)=Cosp_fill_value
+     isccp%meanalbedocld(ip)=missing_val
     endif
     if(isccp%meantb(ip).eq.R_UNDEF)then
-      isccp%meantb(ip)=Cosp_fill_value
+     isccp%meantb(ip)=missing_val
     endif
     if(isccp%meantbclr(ip).eq.R_UNDEF)then
-      isccp%meantbclr(ip)=Cosp_fill_value
+       isccp%meantbclr(ip)=missing_val
     endif
 
@@ -240,5 +240,5 @@
      do ii=1,7
      if(isccp%fq_isccp(ip,ii,k).eq.R_UNDEF)then
-      isccp%fq_isccp(ip,ii,k)=Cosp_fill_value
+      isccp%fq_isccp(ip,ii,k)=missing_val
      endif
      enddo
@@ -247,5 +247,5 @@
     do ii=1,Ncolumns
      if(isccp%boxtau(ip,ii).eq.R_UNDEF)then
-       isccp%boxtau(ip,ii)=Cosp_fill_value
+       isccp%boxtau(ip,ii)=missing_val
      endif
     enddo
@@ -253,5 +253,5 @@
     do ii=1,Ncolumns
      if(isccp%boxptop(ip,ii).eq.R_UNDEF)then
-       isccp%boxptop(ip,ii)=Cosp_fill_value
+      isccp%boxptop(ip,ii)=missing_val
      endif
     enddo
@@ -278,5 +278,5 @@
        do k=1,MISR_N_CTH
         if(misr%fq_MISR(ip,ii,k).eq.R_UNDEF)then
-              misr%fq_MISR(ip,ii,k)=Cosp_fill_value
+            misr%fq_MISR(ip,ii,k)=missing_val
         endif
        enddo
@@ -294,47 +294,57 @@
   do ip=1,Npoints
     if(modis%Cloud_Fraction_Low_Mean(ip).eq.R_UNDEF)then
-       modis%Cloud_Fraction_Low_Mean(ip)=Cosp_fill_value
+      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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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)=Cosp_fill_value
+       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
+
+    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)
@@ -360,5 +370,5 @@
        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)=0.
+          modis%Optical_Thickness_vs_Cloud_Top_Pressure(ip,ii,k)=missing_val
         endif
        enddo
@@ -372,8 +382,8 @@
 
     where(modis%Optical_Thickness_vs_ReffIce == R_UNDEF) &
-          modis%Optical_Thickness_vs_ReffIce = Cosp_fill_value
+          modis%Optical_Thickness_vs_ReffIce = missing_val
 
     where(modis%Optical_Thickness_vs_ReffLiq == R_UNDEF) &
-          modis%Optical_Thickness_vs_ReffLiq = Cosp_fill_value
+          modis%Optical_Thickness_vs_ReffLiq = missing_val
 
     do icl=1,7
