Index: /LMDZ4/branches/LMDZ4_AR5/libf/cosp/cosp_lidar.F90
===================================================================
--- /LMDZ4/branches/LMDZ4_AR5/libf/cosp/cosp_lidar.F90	(revision 1527)
+++ /LMDZ4/branches/LMDZ4_AR5/libf/cosp/cosp_lidar.F90	(revision 1528)
@@ -69,4 +69,5 @@
       mr_cl(:,:) = sghydro%mr_hydro(:,i,:,I_CVCLIQ)
       mr_ci(:,:) = sghydro%mr_hydro(:,i,:,I_CVCICE)
+      frac_out(:,:) = sgx%frac_out(:,i,:)    
       call lidar_simulator(sgx%Npoints, sgx%Nlevels, 4 &
                  , PARASOL_NREFL, LIDAR_UNDEF  &
@@ -74,5 +75,5 @@
                  , mr_ll, mr_li, mr_cl, mr_ci &
                  , gbx%Reff(:,:,I_LSCLIQ), gbx%Reff(:,:,I_LSCICE), gbx%Reff(:,:,I_CVCLIQ), gbx%Reff(:,:,I_CVCICE) &
-                 , sgx%frac_out, gbx%lidar_ice_type, y%beta_mol, beta_tot, tau_tot  &
+                 , frac_out, gbx%lidar_ice_type, y%beta_mol, beta_tot, tau_tot  &
                  , refle ) ! reflectance
       
Index: /LMDZ4/branches/LMDZ4_AR5/libf/cosp/ini_histdayCOSP.h
===================================================================
--- /LMDZ4/branches/LMDZ4_AR5/libf/cosp/ini_histdayCOSP.h	(revision 1527)
+++ /LMDZ4/branches/LMDZ4_AR5/libf/cosp/ini_histdayCOSP.h	(revision 1528)
@@ -18,9 +18,11 @@
 
 ! Definition de l'axe vertical
+       if (use_vgrid) then
         CALL histvert(nid_day_cosp,"height","height","m",Nlevout,vgrid%z,nvert)
-        print*,'Ok height Nlevout, height =',Nlevout,vgrid%z
+       else
+        CALL histvert(nid_day_cosp,"presnivs","Vertical levels","mb",Nlevout,presnivs,nvert)
+       endif
+
         CALL histvert(nid_day_cosp,"height_mlev","height_mlev","m",Nlevlmdz,vgrid%mz,nvertm)
-        print*,'Ok height_mlev Nlevout, height_mlev =',Nlevout,vgrid%mz
-!        CALL histvert(nid_day_cosp,"presnivs","Vertical levels","mb",Nlevout,presnivs,nvert)
 
         CALL histvert(nid_day_cosp,"sza","solar_zenith_angle","degrees",PARASOL_NREFL,PARASOL_SZA,nvertp)
@@ -28,5 +30,5 @@
         CALL histvert(nid_day_cosp,"pressure2","pressure","mb",7,ISCCP_PC,nvertisccp)
 
-        CALL histvert(nid_day_cosp,"column","column","count",Ncolumns,column_ax,nvertcol)
+        CALL histvert(nid_day_cosp,"column","column","count",Ncolumns,column_ax(1:Ncolumns),nvertcol)
 
 ! Sorties LIDAR
Index: /LMDZ4/branches/LMDZ4_AR5/libf/cosp/ini_histhfCOSP.h
===================================================================
--- /LMDZ4/branches/LMDZ4_AR5/libf/cosp/ini_histhfCOSP.h	(revision 1527)
+++ /LMDZ4/branches/LMDZ4_AR5/libf/cosp/ini_histhfCOSP.h	(revision 1528)
@@ -18,9 +18,11 @@
 
 ! Definition de l'axe vertical
+       if (use_vgrid) then
         CALL histvert(nid_hf_cosp,"height","height","m",Nlevout,vgrid%z,nvert)
-        print*,'Ok height Nlevout, height =',Nlevout,vgrid%z
+       else
+        CALL histvert(nid_hf_cosp,"presnivs","Vertical levels","mb",Nlevout,presnivs,nvert)
+       endif
+
         CALL histvert(nid_hf_cosp,"height_mlev","height_mlev","m",Nlevlmdz,vgrid%mz,nvertm)
-        print*,'Ok height_mlev Nlevout height_mlev =',Nlevout,vgrid%mz
-!        CALL histvert(nid_hf_cosp,"presnivs","Vertical levels","mb",Nlevout,presnivs,nvert)
 
         CALL histvert(nid_hf_cosp,"sza","solar_zenith_angle","degrees",PARASOL_NREFL,PARASOL_SZA,nvertp)
@@ -28,5 +30,5 @@
         CALL histvert(nid_hf_cosp,"pressure2","pressure","mb",7,ISCCP_PC,nvertisccp)
 
-        CALL histvert(nid_hf_cosp,"column","column","count",Ncolumns,column_ax,nvertcol)
+        CALL histvert(nid_hf_cosp,"column","column","count",Ncolumns,column_ax(1:Ncolumns),nvertcol)
 
 ! Sorties LIDAR
Index: /LMDZ4/branches/LMDZ4_AR5/libf/cosp/ini_histmthCOSP.h
===================================================================
--- /LMDZ4/branches/LMDZ4_AR5/libf/cosp/ini_histmthCOSP.h	(revision 1527)
+++ /LMDZ4/branches/LMDZ4_AR5/libf/cosp/ini_histmthCOSP.h	(revision 1528)
@@ -14,11 +14,14 @@
         idayref = day_ref
         CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-
         CALL histbeg_phy("histmthCOSP",itau_phy,zjulian,dtime,nhori,nid_mth_cosp) 
 
 ! Definition de l'axe vertical
+        print*,'height_mlev=',vgrid%mz
+       if (use_vgrid) then 
         CALL histvert(nid_mth_cosp,"height","height","m",Nlevout,vgrid%z,nvert)
+       else
+        CALL histvert(nid_mth_cosp,"presnivs","Vertical levels","Pa",Nlevout,presnivs,nvert,"down")
+       endif
         CALL histvert(nid_mth_cosp,"height_mlev","height_mlev","m",Nlevlmdz,vgrid%mz,nvertm)
-!        CALL histvert(nid_mth_cosp,"presnivs","Vertical levels","mb",Nlevout,presnivs,nvert)
 
         CALL histvert(nid_mth_cosp,"sza","solar_zenith_angle","degrees",PARASOL_NREFL,PARASOL_SZA,nvertp)
@@ -26,5 +29,5 @@
         CALL histvert(nid_mth_cosp,"pressure2","pressure","mb",7,ISCCP_PC,nvertisccp)
 
-        CALL histvert(nid_mth_cosp,"column","column","count",Ncolumns,column_ax,nvertcol)
+        CALL histvert(nid_mth_cosp,"column","column","count",Ncolumns,column_ax(1:Ncolumns),nvertcol)
 
 ! Sorties LIDAR
@@ -59,4 +62,12 @@
                      iim,jj_nb,nhori, Nlevout,1,Nlevout,nvert, 32, &
                      "ave(X)", zout,zstomth)
+!         CALL histdef(nid_mth_cosp, "zlev_m", &
+!                     "Height at Midel model levels", "m", &
+!                     iim,jj_nb,nhori, Nlevlmdz,1,Nlevlmdz,nvertm, 32, &
+!                     "ave(X)", zout,zstomth)
+!         CALL histdef(nid_mth_cosp, "zlev_b", &
+!                     "Height at bottom model levels", "m", &
+!                     iim,jj_nb,nhori, Nlevlmdz,1,Nlevlmdz,nvertm, 32, &
+!                     "ave(X)", zout,zstomth)
          endif
            if (cfg%Lcfad_lidarsr532) then
Index: /LMDZ4/branches/LMDZ4_AR5/libf/cosp/lidar_simulator.F90
===================================================================
--- /LMDZ4/branches/LMDZ4_AR5/libf/cosp/lidar_simulator.F90	(revision 1527)
+++ /LMDZ4/branches/LMDZ4_AR5/libf/cosp/lidar_simulator.F90	(revision 1528)
@@ -179,4 +179,7 @@
       REAL tautot_S_liq(npoints),tautot_S_ice(npoints)     ! for liq and ice clouds
 
+! Abderrahmane 8-2-2011
+      Logical iflag_testlidar
+      PARAMETER (iflag_testlidar=.false.)
 
 !------------------------------------------------------------
@@ -384,4 +387,19 @@
       END DO
 
+     if (iflag_testlidar) then
+!+JLD test 
+!     do k=1,nlev
+!      print*,'Min val de frac_out=',k,minval(frac_out(:,k))
+!      print*,'Max val de frac_out=',k,maxval(frac_out(:,k))
+!     enddo
+       where ( frac_out(:,:).ge.0.5)
+! Correction AI 9 5 11          pnorm(:,:) = pmol(:,:)*10.
+       pnorm(:,:) = pmol(:,:)*50.
+        elsewhere
+          pnorm(:,:) = pmol(:,:)
+        endwhere
+!-JLD test 
+     endif
+
 !-------- End computation Lidar --------------------------
 
Index: /LMDZ4/branches/LMDZ4_AR5/libf/cosp/phys_cosp.F90
===================================================================
--- /LMDZ4/branches/LMDZ4_AR5/libf/cosp/phys_cosp.F90	(revision 1527)
+++ /LMDZ4/branches/LMDZ4_AR5/libf/cosp/phys_cosp.F90	(revision 1528)
@@ -1,6 +1,6 @@
 ! Simulateur COSP : Cfmip Observation Simulator Package
+
 ! ISCCP, Radar (QuickBeam), Lidar et Parasol (ACTSIM), MISR, RTTOVS
 !Idelkadi Abderrahmane Aout-Septembre 2009
-
 
   subroutine phys_cosp( itap,dtime,freq_cosp, &
@@ -8,5 +8,5 @@
                         ecrit_mth,ecrit_day,ecrit_hf, &
                         Nptslmdz,Nlevlmdz,lon,lat, presnivs,overlaplmdz, &
-                        ref_liq,ref_ice,fracTerLic,u_wind,v_wind,phi,ph,p,skt,t, &
+                        ref_liq,ref_ice,fracTerLic,u_wind,v_wind,phis,phi,ph,p,skt,t, &
                         sh,rh,tca,cca,mr_lsliq,mr_lsice,fl_lsrainI,fl_lssnowI, &
                         fl_ccrainI,fl_ccsnowI,mr_ozone,dtau_s,dem_s)
@@ -25,4 +25,5 @@
 ! u_wind,v_wind,                        !Vents a 10m ???
 ! phi,                                  !Geopotentiel
+! phis,                                  !Geopotentiel sol
 ! ph,                                   !pression pour chaque inter-couche
 ! p,                                    !Pression aux milieux des couches
@@ -85,5 +86,6 @@
   integer, save :: isccp_topheight,isccp_topheight_direction,overlap
   integer,save  :: Ncolumns     ! Number of subcolumns in SCOPS
-  integer,parameter :: Ncollmdz=20
+!  integer,parameter :: Ncollmdz=20
+  integer,parameter :: Ncolmax=100
   integer, save :: Npoints      ! Number of gridpoints
 !$OMP THREADPRIVATE(Npoints)
@@ -126,7 +128,8 @@
 !$OMP THREADPRIVATE(debut_cosp)
   integer :: itau_wcosp
-  character(len=10),dimension(Ncollmdz),parameter :: chcol=(/'c01','c02','c03','c04','c05','c06','c07','c08','c09','c10', &
-                                                   'c11','c12','c13','c14','c15','c16','c17','c18','c19','c20'/)
-  real,dimension(Ncollmdz) :: column_ax
+  character(len=2) :: str2
+  real,dimension(Ncolmax) :: column_ax
+  character(len=10),save,dimension(Ncolmax) :: chcol
+
   integer, save :: Nlevout
 !$OMP THREADPRIVATE(Nlevout)
@@ -137,10 +140,9 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Input variables from LMDZ-GCM
   integer                         :: overlaplmdz   !  overlap type: 1=max, 2=rand, 3=max/rand ! cosp input (output lmdz)
-!  real,dimension(Npoints,Nlevels) :: height,phi,p,ph,T,sh,rh,tca,cca,mr_lsliq,mr_lsice,mr_ccliq,mr_ccice, &
   real,dimension(Nptslmdz,Nlevlmdz) :: height,phi,p,ph,T,sh,rh,tca,cca,mr_lsliq,mr_lsice,mr_ccliq,mr_ccice, & 
                                      fl_lsrain,fl_lssnow,fl_ccrain,fl_ccsnow,fl_lsgrpl, &
-                                     zlev,mr_ozone,radliq,radice,dtau_s,dem_s,ref_liq,ref_ice
+                                     zlev,zlev_half,mr_ozone,radliq,radice,dtau_s,dem_s,ref_liq,ref_ice
   real,dimension(Nptslmdz,Nlevlmdz) ::  fl_lsrainI,fl_lssnowI,fl_ccrainI,fl_ccsnowI
-  real,dimension(Nptslmdz)        :: lon,lat,skt,fracTerLic,u_wind,v_wind
+  real,dimension(Nptslmdz)        :: lon,lat,skt,fracTerLic,u_wind,v_wind,phis
   real,dimension(Nlevlmdz)        :: presnivs
   integer                         :: itap,k,ip
@@ -165,19 +167,18 @@
  if (debut_cosp) then
   NPoints=Nptslmdz
+  Nlevels=Nlevlmdz
+  
 ! Lecture du namelist input 
   CALL read_cosp_input
 
+  do ii=1,Ncolumns
+    write(str2,'(i2.2)')ii
+    chcol(ii)="c"//str2
+    column_ax(ii) = real(ii)
+  enddo
+
 ! Clefs Outputs 
   call read_cosp_output_nl(cosp_output_nl,cfg)
 
-    if ( (Ncollmdz.ne.Ncolumns).or. (Nlevlmdz.ne.Nlevels) ) then
-       print*,'Nb points Horiz, Vert, Sub-col passes par physiq.F = ', &
-               Nptslmdz, Nlevlmdz, Ncollmdz
-       print*,'Nb points Horiz, Vert, Sub-col lus dans namelist = ', &
-               Npoints, Nlevels, Ncolumns
-       print*,'Nb points Horiz, Vert, Sub-col passes par physiq.F est different de celui lu par namelist '
-       call abort
-    endif
-    
     if (overlaplmdz.ne.overlap) then
        print*,'Attention overlaplmdz different de overlap lu dans namelist '
@@ -221,15 +222,14 @@
         gbx%p = p !
         gbx%ph = ph
-        gbx%zlev_half = phi/9.81
-
-       do k = 1, Nlevels-1
-       do ip = 1, Npoints
-        zlev(ip,k) = phi(ip,k)/9.81 + (phi(ip,k+1)-phi(ip,k))/9.81 * (ph(ip,k)-ph(ip,k+1))/p(ip,k)
-       enddo
-       enddo
-       do ip = 1, Npoints
-        zlev(ip,Nlevels) = zlev(ip,Nlevels-1)+ 2.*(phi(ip,Nlevels)/9.81-zlev(ip,Nlevels-1))
-       END DO
-        gbx%zlev = zlev
+        gbx%zlev = phi/9.81
+
+        zlev_half(:,1) = phis(:)/9.81
+        do k = 2, Nlevels
+          do ip = 1, Npoints
+           zlev_half(ip,k) = phi(ip,k)/9.81 + &
+               (phi(ip,k)-phi(ip,k-1))/9.81 * (ph(ip,k)-p(ip,k)) / (p(ip,k)-p(ip,k-1))
+          enddo
+        enddo
+        gbx%zlev_half = zlev_half
 
         gbx%T = T
@@ -275,33 +275,8 @@
         gbx%snow_cv = fl_ccsnow  !flux_convective_cloud_snow
 
-!Attention Teste
-!       do k = 1, Nlevels
-!        do ip = 1, Npoints
-!!     liquid particles :
-!         radliq(ip,k) = 12.0e-06
-!         if (k.le.3) radliq(ip,k) = 11.0e-06
-
-!    ice particles :
-!        if ( (t(ip,k)-273.15).gt.-81.4 ) then
-!          radice(ip,k) = (0.71*(t(ip,k)-273.15)+61.29)*1e-6
-!        else
-!          radice(ip,k) = 3.5*1e-6
-!        endif
-!       END DO
-!      END DO
-
-!      gbx%Reff(:,:,I_LSCLIQ) = radliq
-!      gbx%Reff(:,:,I_LSCICE) = radice
-!      gbx%Reff(:,:,I_CVCLIQ) = radliq
-!      gbx%Reff(:,:,I_CVCICE) = radice
-!      print*,'radliq(1,:)=',radliq(1,:)
-!      print*,'radice(1,:)=',radice(1,:)
-
      gbx%Reff(:,:,I_LSCLIQ) = ref_liq*1e-6
      gbx%Reff(:,:,I_LSCICE) = ref_ice*1e-6
      gbx%Reff(:,:,I_CVCLIQ) = ref_liq*1e-6
      gbx%Reff(:,:,I_CVCICE) = ref_ice*1e-6
-!     print*,'ref_liq(1,:)=',ref_liq(1,:)*1e-6
-!     print*,'ref_liq(1,:)=',ref_ice(1,:)*1e-6
 
         ! ISCCP simulator
@@ -338,7 +313,4 @@
      include "ini_histhfCOSP.h"
  endif
-
-!   print*,'Fin Initialisation des sorties COSP, debut_cosp =',debut_cosp 
-!   print*,'R_UNDEF=',R_UNDEF
 
    debut_cosp=.false.
Index: /LMDZ4/branches/LMDZ4_AR5/libf/phylmd/physiq.F
===================================================================
--- /LMDZ4/branches/LMDZ4_AR5/libf/phylmd/physiq.F	(revision 1527)
+++ /LMDZ4/branches/LMDZ4_AR5/libf/phylmd/physiq.F	(revision 1528)
@@ -3246,5 +3246,5 @@
      $                   ref_liq,ref_ice,
      $                   pctsrf(:,is_ter)+pctsrf(:,is_lic),
-     $                   zu10m,zv10m,
+     $                   zu10m,zv10m,pphis,
      $                   zphi,paprs(:,1:klev),pplay,zxtsol,t_seri,
      $                   qx(:,:,ivap),zx_rh,cldfra,rnebcon,flwc,fiwc,
