Index: LMDZ4/branches/LMDZ4-dev/libf/phylmd/clesphys.h
===================================================================
--- LMDZ4/branches/LMDZ4-dev/libf/phylmd/clesphys.h	(revision 1255)
+++ LMDZ4/branches/LMDZ4-dev/libf/phylmd/clesphys.h	(revision 1258)
@@ -54,4 +54,5 @@
        REAL ecrit_LES
        REAL freq_ISCCP, ecrit_ISCCP
+       REAL freq_COSP
        INTEGER :: ip_ebil_phy, iflag_rrtm
        LOGICAL :: ok_strato
@@ -71,5 +72,5 @@
      &     , ecrit_ins, ecrit_hf, ecrit_hf2mth, ecrit_day               &
      &     , ecrit_mth, ecrit_tra, ecrit_reg                            &
-     &     , freq_ISCCP, ecrit_ISCCP, ip_ebil_phy                       &
+     &     , freq_ISCCP, ecrit_ISCCP, freq_COSP, ip_ebil_phy            &
      &     , ok_lic_melt, cvl_corr, aer_type                            &
      &     , qsol0, iflag_rrtm, ok_strato,ok_hines,ecrit_LES            &
Index: LMDZ4/branches/LMDZ4-dev/libf/phylmd/conf_phys.F90
===================================================================
--- LMDZ4/branches/LMDZ4-dev/libf/phylmd/conf_phys.F90	(revision 1255)
+++ LMDZ4/branches/LMDZ4-dev/libf/phylmd/conf_phys.F90	(revision 1258)
@@ -79,4 +79,5 @@
   REAL,SAVE           :: bl95_b0_omp, bl95_b1_omp
   REAL,SAVE           :: freq_ISCCP_omp, ecrit_ISCCP_omp
+  REAL,SAVE           :: freq_COSP_omp
   real,SAVE           :: fact_cldcon_omp, facttemps_omp,ratqsbas_omp
   real,SAVE           :: ratqshaut_omp
@@ -324,4 +325,14 @@
   ecrit_ISCCP_omp = 1.
   call getin('ecrit_ISCCP', ecrit_ISCCP_omp)
+
+!Config Key  = freq_COSP
+!Config Desc = Frequence d'appel du simulateur COSP en secondes;
+!              par defaut 10800, i.e. 3 heures
+!Config Def  = 10800.
+!Config Help = Used in ini_histdayCOSP.h
+!
+  freq_COSP_omp = 10800.
+  call getin('freq_COSP', freq_COSP_omp)
+
 !
 !Config Key  = ip_ebil_phy
@@ -1372,4 +1383,5 @@
     freq_ISCCP = freq_ISCCP_omp
     ecrit_ISCCP = ecrit_ISCCP_omp
+    freq_COSP = freq_COSP_omp
     ok_ade = ok_ade_omp
     ok_aie = ok_aie_omp
@@ -1468,4 +1480,5 @@
   write(numout,*)' Frequence appel simulateur ISCCP, freq_ISCCP =', freq_ISCCP
   write(numout,*)' Frequence appel simulateur ISCCP, ecrit_ISCCP =', ecrit_ISCCP
+  write(numout,*)' Frequence appel simulateur COSP, freq_COSP =', freq_COSP
   write(numout,*)' Sortie bilan d''energie, ip_ebil_phy =', ip_ebil_phy
   write(numout,*)' Excentricite = ',R_ecc
Index: LMDZ4/branches/LMDZ4-dev/libf/phylmd/newmicro.F
===================================================================
--- LMDZ4/branches/LMDZ4-dev/libf/phylmd/newmicro.F	(revision 1255)
+++ LMDZ4/branches/LMDZ4-dev/libf/phylmd/newmicro.F	(revision 1258)
@@ -8,5 +8,6 @@
      e                  mass_solu_aero, mass_solu_aero_pi, 
      e                  bl95_b0, bl95_b1,
-     s                  cldtaupi, re, fl)
+     s                  cldtaupi, re, fl, reliq, reice)
+
       USE dimphy
       IMPLICIT none
@@ -119,4 +120,7 @@
       REAL rad_chaud_tab(klon, klev), zflwp_var, zfiwp_var
 
+! Abderrahmane oct 2009
+      Real reliq(klon, klev), reice(klon, klev)
+
 c
 c Calculer l'epaisseur optique et l'emmissivite des nuages
@@ -164,5 +168,5 @@
                                 !
                   cdnc_pi(i,k) = 10.**(bl95_b0+bl95_b1*
-     &             log(MAX(mass_solu_aero_pi(i,k),1.e-4))/log(10.))*1.e6 !-m-3
+     &               log(MAX(mass_solu_aero_pi(i,k),1.e-4))/log(10.))*1.e6 !-m-3
                   cdnc_pi(i,k)=MIN(1000.e6,MAX(20.e6,cdnc_pi(i,k)))
                ENDDO
@@ -178,5 +182,5 @@
      &                 *((pqlwp(i,k)*pplay(i,k)/(RD * T(i,k)))  
      &                 /(4./3*RPI*1000.*cdnc(i,k)) )**(1./3.)
-                  rad_chaud_tab(i,k) = MAX(rad_chaud_tab(i,k) *1.e6, 5.) 
+                  rad_chaud_tab(i,k) = MAX(rad_chaud_tab(i,k) * 1e6, 5.) 
                ENDDO            
             ENDDO
@@ -220,4 +224,6 @@
                   re(i,k) = rad_chaud_tab(i,k)*fl(i,k)
                   
+                  rel = 0.
+                  rei = 0.
                   pclc(i,k) = 0.0
                   pcltau(i,k) = 0.0
@@ -251,4 +257,5 @@
                      cldtaupi(i,k) = 3.0/2.0 * zflwp_var / radius
      &                    + zfiwp_var * (3.448e-03  + 2.431/rei)
+
                   ENDIF         ! ok_aie
                                 ! For output diagnostics
@@ -279,7 +286,7 @@
 c     for ice clouds, Ebert & Curry (1992)] 
                   
-                  if (zflwp_var.eq.0.) rel = 1. 
-                  if (zfiwp_var.eq.0. .or. rei.le.0.) rei = 1. 
-                  pcltau(i,k) = 3.0/2.0 * ( zflwp_var/rel )
+                 if (zflwp_var.eq.0.) rel = 1. 
+                 if (zfiwp_var.eq.0. .or. rei.le.0.) rei = 1. 
+                 pcltau(i,k) = 3.0/2.0 * ( zflwp_var/rel )
      &                 + zfiwp_var * (3.448e-03  + 2.431/rei)
 c     -- cloud infrared emissivity:
@@ -295,5 +302,12 @@
 
                ENDIF
-               
+              reliq(i,k)=rel
+              reice(i,k)=rei 
+              if (i.eq.1) then
+              print*,'Dans newmicro rel, rei :',rel, rei
+              print*,'Dans newmicro reliq, reice :',
+     $             reliq(i,k),reice(i,k)
+              endif
+
             ENDDO
          ENDDO
Index: LMDZ4/branches/LMDZ4-dev/libf/phylmd/phys_output_mod.F90
===================================================================
--- LMDZ4/branches/LMDZ4-dev/libf/phylmd/phys_output_mod.F90	(revision 1255)
+++ LMDZ4/branches/LMDZ4-dev/libf/phylmd/phys_output_mod.F90	(revision 1258)
@@ -984,9 +984,8 @@
  CALL histdef3d(iff,o_cldemi%flag,o_cldemi%name, "Cloud optical emissivity", "1")
 !IM: bug ?? dimensionnement variables (klon,klev+1) pmflxr, pmflxs, prfl, psfl
-! CALL histdef3d(iff,o_pr_con_l%flag,o_pmflxr%name, "Convective precipitation lic", " ")
-! CALL histdef3d(iff,o_pr_con_i%flag,o_pmflxs%name, "Convective precipitation ice", " ")
-! CALL histdef3d(iff,o_pr_lsc_l%flag,o_prfl%name, "Large scale precipitation lic", " ")
-! CALL histdef3d(iff,o_pr_lsc_i%flag,o_psfl%name, "Large scale precipitation ice", " ")
-
+ CALL histdef3d(iff,o_pr_con_l%flag,o_pr_con_l%name, "Convective precipitation lic", " ")
+ CALL histdef3d(iff,o_pr_con_i%flag,o_pr_con_i%name, "Convective precipitation ice", " ")
+ CALL histdef3d(iff,o_pr_lsc_l%flag,o_pr_lsc_l%name, "Large scale precipitation lic", " ")
+ CALL histdef3d(iff,o_pr_lsc_i%flag,o_pr_lsc_i%name, "Large scale precipitation ice", " ")
 !FH Sorties pour la couche limite
      if (iflag_pbl>1) then
Index: LMDZ4/branches/LMDZ4-dev/libf/phylmd/phys_output_write.h
===================================================================
--- LMDZ4/branches/LMDZ4-dev/libf/phylmd/phys_output_write.h	(revision 1255)
+++ LMDZ4/branches/LMDZ4-dev/libf/phylmd/phys_output_write.h	(revision 1258)
@@ -743,19 +743,24 @@
        ENDIF
 
-!      IF (o_pr_con_l%flag(iff)<=lev_files(iff)) THEN
-!      CALL histwrite_phy(nid_files(iff),o_pmflxr%name,itau_w,pmflxr)
-!      ENDIF
-
-!      IF (o_pr_con_i%flag(iff)<=lev_files(iff)) THEN
-!      CALL histwrite_phy(nid_files(iff),o_pmflxs%name,itau_w,pmflxs)
-!      ENDIF
-
-!      IF (o_pr_lsc_l%flag(iff)<=lev_files(iff)) THEN
-!      CALL histwrite_phy(nid_files(iff),o_prfl%name,itau_w,prfl)
-!      ENDIF
-
-!      IF (o_pr_lsc_i%flag(iff)<=lev_files(iff)) THEN
-!      CALL histwrite_phy(nid_files(iff),o_psfl%name,itau_w,psfl)
-!      ENDIF
+      IF (o_pr_con_l%flag(iff)<=lev_files(iff)) THEN
+      CALL histwrite_phy(nid_files(iff),
+     s         o_pr_con_l%name,itau_w,pmflxr(:,1:klev))
+      ENDIF
+
+      IF (o_pr_con_i%flag(iff)<=lev_files(iff)) THEN
+      CALL histwrite_phy(nid_files(iff),
+     s         o_pr_con_i%name,itau_w,pmflxs(:,1:klev))
+      ENDIF
+
+      IF (o_pr_lsc_l%flag(iff)<=lev_files(iff)) THEN
+      CALL histwrite_phy(nid_files(iff),
+     s        o_pr_lsc_l%name,itau_w,prfl(:,1:klev))
+      ENDIF
+
+      IF (o_pr_lsc_i%flag(iff)<=lev_files(iff)) THEN
+      CALL histwrite_phy(nid_files(iff),
+     s        o_pr_lsc_i%name,itau_w,psfl(:,1:klev))
+      ENDIF
+
 
       IF (o_rh2m%flag(iff)<=lev_files(iff)) THEN
Index: LMDZ4/branches/LMDZ4-dev/libf/phylmd/physiq.F
===================================================================
--- LMDZ4/branches/LMDZ4-dev/libf/phylmd/physiq.F	(revision 1255)
+++ LMDZ4/branches/LMDZ4-dev/libf/phylmd/physiq.F	(revision 1258)
@@ -888,4 +888,5 @@
       logical ok_newmicro
       save ok_newmicro
+      real ref_liq(klon,klev), ref_ice(klon,klev)
 c$OMP THREADPRIVATE(ok_newmicro)
       save fact_cldcon,facttemps
@@ -1115,4 +1116,8 @@
 cIM 100106 END : pouvoir sortir les ctes de la physique
 c
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+c Declarations pour Simulateur COSP
+c============================================================
+      real :: mr_ozone(klon,klev)
 c======================================================================
 ! Ecriture eventuelle d'un profil verticale en entree de la physique.
@@ -2875,5 +2880,5 @@
      e            mass_solu_aero, mass_solu_aero_pi,
      e            bl95_b0, bl95_b1,
-     s            cldtaupi, re, fl)
+     s            cldtaupi, re, fl, ref_liq, ref_ice)
       else
       CALL nuage (paprs, pplay,
@@ -3168,4 +3173,40 @@
 c
 c
+!====================================================================
+! Interface Simulateur COSP (Calipso, ISCCP, MISR, ..)
+!====================================================================
+! Abderrahmane 24.08.09
+
+!      IF (ok_cosp) THEN
+! adeclarer 
+#ifdef CPP_COSP
+       IF (MOD(itap,NINT(freq_cosp/dtime)).EQ.0) THEN
+
+       print*,'freq_cosp',freq_cosp
+          mr_ozone=wo * dobson_u * 1e3 / zmasse
+!       print*,'Dans physiq.F avant appel cosp ref_liq,ref_ice=',
+!     s        ref_liq,ref_ice
+          call phys_cosp(itap,dtime,freq_cosp,
+     $                 ecrit_mth,ecrit_day,ecrit_hf,overlap,
+     $                   klon,klev,rlon,rlat,presnivs,
+     $                   ref_liq,ref_ice,
+     $                   pctsrf(:,is_ter)+pctsrf(:,is_lic),
+     $                   zu10m,zv10m,
+     $                   zphi,paprs(:,1:klev),pplay,zxtsol,t_seri,
+     $                   qx(:,:,ivap),zx_rh,cldfra,rnebcon,flwc,fiwc,
+     $                   prfl(:,1:klev),psfl(:,1:klev),
+     $                   pmflxr(:,1:klev),pmflxs(:,1:klev),
+     $                   mr_ozone,cldtau, cldemi)
+!     L          calipso2D,calipso3D,cfadlidar,parasolrefl,atb,betamol,
+!     L          cfaddbze,clcalipso2,dbze,cltlidarradar,
+!     M          clMISR,
+!     R          clisccp2,boxtauisccp,boxptopisccp,tclisccp,ctpisccp,
+!     I          tauisccp,albisccp,meantbisccp,meantbclrisccp)
+
+        ENDIF
+
+!      ENDIF
+#endif
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 cAA
 cAA Installation de l'interface online-offline pour traceurs
