Index: LMDZ6/branches/LMDZ-COSP/libf/phylmd/cospv2/lmdz_cosp_output_write_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ-COSP/libf/phylmd/cospv2/lmdz_cosp_output_write_mod.F90	(revision 3728)
+++ LMDZ6/branches/LMDZ-COSP/libf/phylmd/cospv2/lmdz_cosp_output_write_mod.F90	(revision 3730)
@@ -273,5 +273,5 @@
    endif
    if (cfg%LlidarBetaMol532) then 
-     where(cospOUT%calipso_tau_tot == R_UNDEF) cospOUT%calipso_tau_tot = missing_val
+     where(cospOUT%calipso_beta_mol == R_UNDEF) cospOUT%calipso_beta_mol = missing_val
      CALL histwrite3d_cosp(o_lidarBetaMol532,cospOUT%calipso_beta_mol,nvertmcosp) 
    endif
@@ -282,21 +282,35 @@
 !!!! Sorties Ground Lidar
  if (cfg%LgrLidar532) then
-
-   where(cospOUT%grLidar532_beta_tot == R_UNDEF) cospOUT%grLidar532_beta_tot = missing_val
-   where(cospOUT%grLidar532_cfad_sr == R_UNDEF) cospOUT%grLidar532_cfad_sr = missing_val
-   where(cospOUT%grLidar532_lidarcld == R_UNDEF) cospOUT%grLidar532_lidarcld = missing_val
-   where(cospOUT%grLidar532_cldlayer == R_UNDEF) cospOUT%grLidar532_cldlayer = missing_val
-   where(cospOUT%grLidar532_beta_mol == R_UNDEF) cospOUT%grLidar532_beta_mol = missing_val
-   where(cospOUT%grLidar532_srbval == R_UNDEF) cospOUT%grLidar532_srbval = missing_val
-
-   if (cfg%LcllgrLidar532) CALL histwrite2d_cosp(o_cllgrLidar532,cospOUT%grLidar532_cldlayer(:,1))
-   if (cfg%LclmgrLidar532) CALL histwrite2d_cosp(o_clmgrLidar532,cospOUT%grLidar532_cldlayer(:,2))
-   if (cfg%LclhgrLidar532) CALL histwrite2d_cosp(o_clhgrLidar532,cospOUT%grLidar532_cldlayer(:,3))
-   if (cfg%LcltgrLidar532) CALL histwrite2d_cosp(o_cltgrLidar532,cospOUT%grLidar532_cldlayer(:,4))
-
-   if (cfg%LclgrLidar532) CALL histwrite3d_cosp(o_clgrLidar532,cospOUT%grLidar532_lidarcld,nvert)
-   if (cfg%LlidarBetaMol532gr) CALL histwrite3d_cosp(o_lidarBetaMol532gr,cospOUT%grLidar532_beta_mol,nvertmcosp) 
-
-   do icl=1,SR_BINS
+! AI juin 2020 Voir a quoi correspond ce champs
+!   where(cospOUT%grLidar532_srbval == R_UNDEF) cospOUT%grLidar532_srbval = missing_val
+
+   if (cfg%LcllgrLidar532) then
+      where(cospOUT%grLidar532_cldlayer(:,1) == R_UNDEF) cospOUT%grLidar532_cldlayer(:,1) = missing_val
+      CALL histwrite2d_cosp(o_cllgrLidar532,cospOUT%grLidar532_cldlayer(:,1))
+   endif
+   if (cfg%LclmgrLidar532) then
+      where(cospOUT%grLidar532_cldlayer(:,2) == R_UNDEF) cospOUT%grLidar532_cldlayer(:,2) = missing_val
+      CALL histwrite2d_cosp(o_clmgrLidar532,cospOUT%grLidar532_cldlayer(:,2))
+   endif
+   if (cfg%LclhgrLidar532) then
+      where(cospOUT%grLidar532_cldlayer(:,3) == R_UNDEF) cospOUT%grLidar532_cldlayer(:,3) = missing_val
+      CALL histwrite2d_cosp(o_clhgrLidar532,cospOUT%grLidar532_cldlayer(:,3))
+   endif
+   if (cfg%LcltgrLidar532) then
+      where(cospOUT%grLidar532_cldlayer(:,4) == R_UNDEF) cospOUT%grLidar532_cldlayer(:,4) = missing_val
+      CALL histwrite2d_cosp(o_cltgrLidar532,cospOUT%grLidar532_cldlayer(:,4))
+   endif
+
+   if (cfg%LclgrLidar532) then
+       where(cospOUT%grLidar532_lidarcld == R_UNDEF) cospOUT%grLidar532_lidarcld = missing_val
+      CALL histwrite3d_cosp(o_clgrLidar532,cospOUT%grLidar532_lidarcld,nvert)
+   endif
+   if (cfg%LlidarBetaMol532gr) then
+      where(cospOUT%grLidar532_beta_mol == R_UNDEF) cospOUT%grLidar532_beta_mol = missing_val
+      CALL histwrite3d_cosp(o_lidarBetaMol532gr,cospOUT%grLidar532_beta_mol,nvertmcosp) 
+   endif
+   if (cfg%LcfadLidarsr532gr) then
+     where(cospOUT%grLidar532_cfad_sr == R_UNDEF) cospOUT%grLidar532_cfad_sr = missing_val
+     do icl=1,SR_BINS
       do k=1,Nlvgrid
        do ip=1,Npoints
@@ -304,9 +318,12 @@
        enddo
       enddo
-   enddo
-   if (cfg%LcfadLidarsr532gr) CALL histwrite4d_cosp(o_cfadLidarsr532gr,tmp_fi4da_cfadLgr)
-
-   if (cfg%Latb532gr) CALL histwrite4d_cosp(o_atb532gr,cospOUT%grLidar532_beta_tot)
-
+     enddo
+     CALL histwrite4d_cosp(o_cfadLidarsr532gr,tmp_fi4da_cfadLgr)
+   endif
+
+   if (cfg%Latb532gr) then
+      where(cospOUT%grLidar532_beta_tot == R_UNDEF) cospOUT%grLidar532_beta_tot = missing_val
+      CALL histwrite4d_cosp(o_atb532gr,cospOUT%grLidar532_beta_tot)
+   endif
 endif ! Ground Lidar 532 nm
 
@@ -314,21 +331,34 @@
 !!!! Sorties Atlid
  if (cfg%Latlid) then
-
-   where(cospOUT%atlid_beta_tot == R_UNDEF) cospOUT%atlid_beta_tot = missing_val
-   where(cospOUT%atlid_cfad_sr == R_UNDEF) cospOUT%atlid_cfad_sr = missing_val
-   where(cospOUT%atlid_lidarcld == R_UNDEF) cospOUT%atlid_lidarcld = missing_val
-   where(cospOUT%atlid_cldlayer == R_UNDEF) cospOUT%atlid_cldlayer = missing_val
-   where(cospOUT%atlid_beta_mol == R_UNDEF) cospOUT%atlid_beta_mol = missing_val
-   where(cospOUT%atlid_srbval == R_UNDEF) cospOUT%atlid_srbval = missing_val
-
-   if (cfg%Lcllatlid) CALL histwrite2d_cosp(o_cllatlid,cospOUT%atlid_cldlayer(:,1))
-   if (cfg%Lclmatlid) CALL histwrite2d_cosp(o_clmatlid,cospOUT%atlid_cldlayer(:,2))
-   if (cfg%Lclhatlid) CALL histwrite2d_cosp(o_clhatlid,cospOUT%atlid_cldlayer(:,3))
-   if (cfg%Lcltatlid) CALL histwrite2d_cosp(o_cltatlid,cospOUT%atlid_cldlayer(:,4))
-
-   if (cfg%Lclatlid) CALL histwrite3d_cosp(o_clatlid,cospOUT%atlid_lidarcld,nvert)
-   if (cfg%LlidarBetaMol355) CALL histwrite3d_cosp(o_lidarBetaMol355,cospOUT%atlid_beta_mol,nvertmcosp) 
-
-   do icl=1,SR_BINS
+! AI juin 2020 Voir a quoi correspond ce champs
+!   where(cospOUT%atlid_srbval == R_UNDEF) cospOUT%atlid_srbval = missing_val
+
+   if (cfg%Lcllatlid) then 
+      where(cospOUT%atlid_cldlayer(:,1) == R_UNDEF) cospOUT%atlid_cldlayer(:,1) = missing_val
+      CALL histwrite2d_cosp(o_cllatlid,cospOUT%atlid_cldlayer(:,1))
+   endif
+   if (cfg%Lclmatlid) then
+      where(cospOUT%atlid_cldlayer(:,2) == R_UNDEF) cospOUT%atlid_cldlayer(:,2) = missing_val
+      CALL histwrite2d_cosp(o_clmatlid,cospOUT%atlid_cldlayer(:,2))
+   endif
+   if (cfg%Lclhatlid) then
+      where(cospOUT%atlid_cldlayer(:,3) == R_UNDEF) cospOUT%atlid_cldlayer(:,3) = missing_val
+      CALL histwrite2d_cosp(o_clhatlid,cospOUT%atlid_cldlayer(:,3))
+   endif
+   if (cfg%Lcltatlid) then
+      where(cospOUT%atlid_cldlayer(:,4) == R_UNDEF) cospOUT%atlid_cldlayer(:,4) = missing_val
+      CALL histwrite2d_cosp(o_cltatlid,cospOUT%atlid_cldlayer(:,4))
+   endif
+   if (cfg%Lclatlid) then
+      where(cospOUT%atlid_lidarcld == R_UNDEF) cospOUT%atlid_lidarcld = missing_val
+      CALL histwrite3d_cosp(o_clatlid,cospOUT%atlid_lidarcld,nvert)
+   endif
+   if (cfg%LlidarBetaMol355) then
+      where(cospOUT%atlid_beta_mol == R_UNDEF) cospOUT%atlid_beta_mol = missing_val
+      CALL histwrite3d_cosp(o_lidarBetaMol355,cospOUT%atlid_beta_mol,nvertmcosp) 
+   endif
+   if (cfg%LcfadLidarsr355) then
+     where(cospOUT%atlid_cfad_sr == R_UNDEF) cospOUT%atlid_cfad_sr = missing_val
+     do icl=1,SR_BINS
       do k=1,Nlvgrid
        do ip=1,Npoints
@@ -336,9 +366,12 @@
        enddo
       enddo
-   enddo
-   if (cfg%LcfadLidarsr355) CALL histwrite4d_cosp(o_cfadlidarsr355,tmp_fi4da_cfadLatlid)
-
-   if (cfg%Latb355) CALL histwrite4d_cosp(o_atb355,cospOUT%atlid_beta_tot)
-
+     enddo
+     CALL histwrite4d_cosp(o_cfadlidarsr355,tmp_fi4da_cfadLatlid)
+   endif
+
+   if (cfg%Latb355) then
+      where(cospOUT%atlid_beta_tot == R_UNDEF) cospOUT%atlid_beta_tot = missing_val 
+      CALL histwrite4d_cosp(o_atb355,cospOUT%atlid_beta_tot)
+   endif
 endif ! Atlid
 
@@ -346,13 +379,10 @@
  if (cfg%Lparasol) then
    if (cfg%LparasolRefl) then
-! Ces 2 diagnostics sont controles par la clef logique "LparasolRefl"
-
-!!!   if (cfg%LparasolRefl) CALL histwrite3d_cosp(o_parasolrefl,cospOUT%parasolrefl,nvertp)
+     where(cospOUT%parasolGrid_refl == R_UNDEF) cospOUT%parasolGrid_refl = missing_val
+     where(cospOUT%parasolPix_refl == R_UNDEF) cospOUT%parasolPix_refl = missing_val
      CALL histwrite3d_cosp(o_parasolGrid_refl,cospOUT%parasolGrid_refl,nvertp)
-
      CALL histwrite4d_cosp(o_parasolPix_refl,cospOUT%parasolPix_refl)
-
-    endif ! LparasolRefl
-   endif ! Parasol
+   endif ! LparasolRefl
+ endif ! Parasol
 
 !  if (cfg%LparasolRefl) then 
@@ -376,23 +406,55 @@
 !!! Sorties CloudSat
  if (cfg%Lcloudsat) then
-
-   where(cospOUT%cloudsat_Ze_tot == R_UNDEF) cospOUT%cloudsat_Ze_tot = missing_val
-   where(cospOUT%cloudsat_cfad_ze == R_UNDEF) cospOUT%cloudsat_cfad_ze = missing_val
-   where(cospOUT%cloudsat_precip_cover == R_UNDEF) cospOUT%cloudsat_precip_cover = missing_val
-   where(cospOUT%cloudsat_pia == R_UNDEF) cospOUT%cloudsat_pia = missing_val
-
-   if (cfg%Lptradarflag0) CALL histwrite2d_cosp(o_ptradarflag0,cospOUT%cloudsat_precip_cover(:,1))
-   if (cfg%Lptradarflag1) CALL histwrite2d_cosp(o_ptradarflag1,cospOUT%cloudsat_precip_cover(:,2))
-   if (cfg%Lptradarflag2) CALL histwrite2d_cosp(o_ptradarflag2,cospOUT%cloudsat_precip_cover(:,3))
-   if (cfg%Lptradarflag3) CALL histwrite2d_cosp(o_ptradarflag3,cospOUT%cloudsat_precip_cover(:,4))
-   if (cfg%Lptradarflag4) CALL histwrite2d_cosp(o_ptradarflag4,cospOUT%cloudsat_precip_cover(:,5))
-   if (cfg%Lptradarflag5) CALL histwrite2d_cosp(o_ptradarflag5,cospOUT%cloudsat_precip_cover(:,6))
-   if (cfg%Lptradarflag6) CALL histwrite2d_cosp(o_ptradarflag6,cospOUT%cloudsat_precip_cover(:,7))
-   if (cfg%Lptradarflag7) CALL histwrite2d_cosp(o_ptradarflag7,cospOUT%cloudsat_precip_cover(:,8))
-   if (cfg%Lptradarflag8) CALL histwrite2d_cosp(o_ptradarflag8,cospOUT%cloudsat_precip_cover(:,9))
-   if (cfg%Lptradarflag9) CALL histwrite2d_cosp(o_ptradarflag9,cospOUT%cloudsat_precip_cover(:,10))
-   if (cfg%Lradarpia) CALL histwrite2d_cosp(o_radarpia,cospOUT%cloudsat_pia)
-
-   do icl=1,CLOUDSAT_DBZE_BINS
+! AI juin 2020 voir a quoi correspond ce champs
+!   where(cospOUT%cloudsat_pia == R_UNDEF) cospOUT%cloudsat_pia = missing_val
+
+   if (cfg%Lptradarflag0) then
+     where(cospOUT%cloudsat_precip_cover(:,1) == R_UNDEF) cospOUT%cloudsat_precip_cover(:,1) = missing_val
+     CALL histwrite2d_cosp(o_ptradarflag0,cospOUT%cloudsat_precip_cover(:,1))
+   endif
+   if (cfg%Lptradarflag1) then
+     where(cospOUT%cloudsat_precip_cover(:,2) == R_UNDEF) cospOUT%cloudsat_precip_cover(:,2) = missing_val
+     CALL histwrite2d_cosp(o_ptradarflag1,cospOUT%cloudsat_precip_cover(:,2))
+   endif
+   if (cfg%Lptradarflag2) then
+      where(cospOUT%cloudsat_precip_cover(:,3) == R_UNDEF) cospOUT%cloudsat_precip_cover(:,3) = missing_val
+      CALL histwrite2d_cosp(o_ptradarflag2,cospOUT%cloudsat_precip_cover(:,3))
+   endif
+   if (cfg%Lptradarflag3) then
+      where(cospOUT%cloudsat_precip_cover(:,4) == R_UNDEF) cospOUT%cloudsat_precip_cover(:,4) = missing_val
+      CALL histwrite2d_cosp(o_ptradarflag3,cospOUT%cloudsat_precip_cover(:,4))
+   endif
+   if (cfg%Lptradarflag4) then
+      where(cospOUT%cloudsat_precip_cover(:,5) == R_UNDEF) cospOUT%cloudsat_precip_cover(:,5) = missing_val
+      CALL histwrite2d_cosp(o_ptradarflag3,cospOUT%cloudsat_precip_cover(:,5))
+   endif
+   if (cfg%Lptradarflag5) then
+      where(cospOUT%cloudsat_precip_cover(:,6) == R_UNDEF) cospOUT%cloudsat_precip_cover(:,6) = missing_val
+      CALL histwrite2d_cosp(o_ptradarflag3,cospOUT%cloudsat_precip_cover(:,6))
+   endif
+   if (cfg%Lptradarflag6) then
+      where(cospOUT%cloudsat_precip_cover(:,7) == R_UNDEF) cospOUT%cloudsat_precip_cover(:,7) = missing_val
+      CALL histwrite2d_cosp(o_ptradarflag3,cospOUT%cloudsat_precip_cover(:,7))
+   endif
+   if (cfg%Lptradarflag7) then
+      where(cospOUT%cloudsat_precip_cover(:,8) == R_UNDEF) cospOUT%cloudsat_precip_cover(:,8) = missing_val
+      CALL histwrite2d_cosp(o_ptradarflag3,cospOUT%cloudsat_precip_cover(:,8))
+   endif
+   if (cfg%Lptradarflag8) then
+      where(cospOUT%cloudsat_precip_cover(:,9) == R_UNDEF) cospOUT%cloudsat_precip_cover(:,9) = missing_val
+      CALL histwrite2d_cosp(o_ptradarflag3,cospOUT%cloudsat_precip_cover(:,9))
+   endif
+   if (cfg%Lptradarflag9) then
+      where(cospOUT%cloudsat_precip_cover(:,10) == R_UNDEF) cospOUT%cloudsat_precip_cover(:,10) = missing_val
+      CALL histwrite2d_cosp(o_ptradarflag3,cospOUT%cloudsat_precip_cover(:,10))
+   endif
+
+   if (cfg%Ldbze94) then
+     where(cospOUT%cloudsat_Ze_tot == R_UNDEF) cospOUT%cloudsat_Ze_tot = missing_val 
+     CALL histwrite4d_cosp(o_dbze94,cospOUT%cloudsat_Ze_tot)
+   endif
+   if (cfg%LcfadDbze94)  then
+     where(cospOUT%cloudsat_cfad_ze == R_UNDEF) cospOUT%cloudsat_cfad_ze = missing_val  
+     do icl=1,CLOUDSAT_DBZE_BINS
       do k=1,Nlvgrid
        do ip=1,Npoints
@@ -400,8 +462,7 @@
        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)
+     enddo
+     CALL histwrite4d_cosp(o_cfadDbze94,tmp_fi4da_cfadR)
+  endif
  endif
 ! endif pour CloudSat
@@ -410,17 +471,25 @@
 !!! Sorties combinees Cloudsat et Calipso
  if (cfg%Lcalipso .and. cfg%Lcloudsat) then
-   where(cospOUT%lidar_only_freq_cloud == R_UNDEF) &
+
+   if (cfg%Lclcalipso2) then
+     where(cospOUT%lidar_only_freq_cloud == R_UNDEF) &
                            cospOUT%lidar_only_freq_cloud = missing_val
-   where(cospOUT%cloudsat_tcc == R_UNDEF) &
+     CALL histwrite3d_cosp(o_clcalipso2,cospOUT%lidar_only_freq_cloud,nvert)
+   endif
+   if (cfg%Lcloudsat_tcc) then
+     where(cospOUT%cloudsat_tcc == R_UNDEF) &
                            cospOUT%cloudsat_tcc = missing_val
-   where(cospOUT%cloudsat_tcc2 == R_UNDEF) &
+     CALL histwrite2d_cosp(o_cloudsat_tcc,cospOUT%cloudsat_tcc)
+   endif
+   if (cfg%Lcloudsat_tcc2) then
+     where(cospOUT%cloudsat_tcc2 == R_UNDEF) &
                            cospOUT%cloudsat_tcc2 = missing_val
-   where(cospOUT%radar_lidar_tcc == R_UNDEF) &
-                           cospOUT%radar_lidar_tcc = missing_val
-
-   if (cfg%Lclcalipso2) CALL histwrite3d_cosp(o_clcalipso2,cospOUT%lidar_only_freq_cloud,nvert)
-   if (cfg%Lcloudsat_tcc) CALL histwrite2d_cosp(o_cloudsat_tcc,cospOUT%cloudsat_tcc)
-   if (cfg%Lcloudsat_tcc2) CALL histwrite2d_cosp(o_cloudsat_tcc2,cospOUT%cloudsat_tcc2)
-   if (cfg%Lcltlidarradar) CALL histwrite2d_cosp(o_cltlidarradar,cospOUT%radar_lidar_tcc)
+     CALL histwrite2d_cosp(o_cloudsat_tcc2,cospOUT%cloudsat_tcc2)
+   endif
+   if (cfg%Lcltlidarradar) then
+     where(cospOUT%radar_lidar_tcc == R_UNDEF) &
+                           cospOUT%radar_lidar_tcc = missing_val     
+     CALL histwrite2d_cosp(o_cltlidarradar,cospOUT%radar_lidar_tcc)
+   endif
  endif
 
