Index: LMDZ4/branches/LMDZ4_AR5/libf/cosp/phys_cosp.F90
===================================================================
--- LMDZ4/branches/LMDZ4_AR5/libf/cosp/phys_cosp.F90	(revision 1401)
+++ 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.
