Index: LMDZ5/branches/testing/libf/phylmd/cosp/phys_cosp.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/cosp/phys_cosp.F90	(revision 2408)
+++ LMDZ5/branches/testing/libf/phylmd/cosp/phys_cosp.F90	(revision 2435)
@@ -2,5 +2,6 @@
 
 ! ISCCP, Radar (QuickBeam), Lidar et Parasol (ACTSIM), MISR, RTTOVS
-!Idelkadi Abderrahmane Aout-Septembre 2009
+!Idelkadi Abderrahmane Aout-Septembre 2009 First Version
+!Idelkadi Abderrahmane Nov 2015 version v1.4.0
 
   subroutine phys_cosp( itap,dtime,freq_cosp, &
@@ -67,6 +68,10 @@
 ! meantbisccp,                          !Mean all-sky 10.5 micron brightness temperature as calculated by the ISCCP Simulator
 ! meantbclrisccp                        !Mean clear-sky 10.5 micron brightness temperature as calculated by the ISCCP Simulator
+
+!!! AI rajouter les nouvelles sorties
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
+!! AI rajouter
+  #include "cosp_defs.h" 
   USE MOD_COSP_CONSTANTS
   USE MOD_COSP_TYPES
@@ -78,5 +83,6 @@
   use cosp_output_mod
   use cosp_output_write_mod
- 
+!  use MOD_COSP_Modis_Simulator, only : cosp_modis 
+
   IMPLICIT NONE
 
@@ -100,5 +106,11 @@
   type(cosp_sglidar) :: sglidar ! Output from lidar simulator
   type(cosp_isccp)   :: isccp   ! Output from ISCCP simulator
+!! AI rajout modis
+  type(cosp_modis)   :: modis   ! Output from MODIS simulator
+!!
   type(cosp_misr)    :: misr    ! Output from MISR simulator
+!! AI rajout rttovs
+!  type(cosp_rttov)   :: rttov   ! Output from RTTOV
+!!
   type(cosp_vgrid)   :: vgrid   ! Information on vertical grid of stats
   type(cosp_radarstats) :: stradar ! Summary statistics from radar simulator
@@ -106,5 +118,5 @@
 
   integer :: t0,t1,count_rate,count_max
-  integer :: Nlon,Nlat,geomode
+  integer :: Nlon,Nlat
   real,save :: radar_freq,k2,ZenAng,co2,ch4,n2o,co,emsfc_lw
 !$OMP THREADPRIVATE(emsfc_lw)
@@ -134,6 +146,6 @@
   integer                         :: itap,k,ip
   real                            :: dtime,freq_cosp
+  real,dimension(2)               :: time_bnds
   
-!
    namelist/COSP_INPUT/overlap,isccp_topheight,isccp_topheight_direction, &
               npoints_it,ncolumns,use_vgrid,nlr,csat_vgrid, &
@@ -167,8 +179,11 @@
 
   print*,' Cles des differents simulateurs cosp :'
-  print*,' Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lrttov_sim', &
-          cfg%Lradar_sim,cfg%Llidar_sim,cfg%Lisccp_sim,cfg%Lmisr_sim,cfg%Lrttov_sim
+  print*,'Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lmodis_sim,Lrttov_sim', &
+          cfg%Lradar_sim,cfg%Llidar_sim,cfg%Lisccp_sim,cfg%Lmisr_sim,cfg%Lmodis_sim,cfg%Lrttov_sim
 
   endif ! debut_cosp
+
+  time_bnds(1) = dtime-dtime/2.
+  time_bnds(2) = dtime+dtime/2.
 
 !  print*,'Debut phys_cosp itap,dtime,freq_cosp,ecrit_mth,ecrit_day,ecrit_hf ', &
@@ -178,6 +193,16 @@
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
         print *, 'Allocating memory for gridbox type...'
-
-        call construct_cosp_gridbox(dble(itap),radar_freq,surface_radar,use_mie_tables,use_gas_abs,do_ray,melt_lay,k2, &
+!! AI
+!        call construct_cosp_gridbox(dble(itap),radar_freq,surface_radar,use_mie_tables,use_gas_abs,do_ray,melt_lay,k2, &
+!                                    Npoints,Nlevels,Ncolumns,N_HYDRO,Nprmts_max_hydro,Naero,Nprmts_max_aero,Npoints_it, &
+!                                    lidar_ice_type,isccp_topheight,isccp_topheight_direction,overlap,emsfc_lw, &
+!                                    use_precipitation_fluxes,use_reff, &
+!                                    Platform,Satellite,Instrument,Nchannels,ZenAng, &
+!                                    channels(1:Nchannels),surfem(1:Nchannels),co2,ch4,n2o,co,gbx)
+! Surafce emissivity
+        emsfc_lw = 1.
+
+        call construct_cosp_gridbox(dtime,time_bnds,radar_freq,surface_radar,use_mie_tables,use_gas_abs, &
+                                    do_ray,melt_lay,k2, &
                                     Npoints,Nlevels,Ncolumns,N_HYDRO,Nprmts_max_hydro,Naero,Nprmts_max_aero,Npoints_it, &
                                     lidar_ice_type,isccp_topheight,isccp_topheight_direction,overlap,emsfc_lw, &
@@ -230,11 +255,12 @@
 
 ! sunlit calcule a partir de la fraction d ensoleillement par jour
-      do ip = 1, Npoints
-        if (sunlit(ip).le.0.) then
-           gbx%sunlit(ip)=0.
-        else
-           gbx%sunlit(ip)=1.
-        endif
-      enddo
+!      do ip = 1, Npoints
+!        if (sunlit(ip).le.0.) then
+!           gbx%sunlit(ip)=0.
+!        else
+!           gbx%sunlit(ip)=1.
+!        endif
+!      enddo
+       gbx%sunlit=sunlit
 
 ! A voir l equivalent LMDZ
@@ -260,4 +286,5 @@
      gbx%Reff(:,:,I_LSCLIQ) = ref_liq*1e-6
      gbx%Reff(:,:,I_LSCICE) = ref_ice*1e-6
+!! AI A revoir
      gbx%Reff(:,:,I_CVCLIQ) = ref_liq*1e-6
      gbx%Reff(:,:,I_CVCICE) = ref_ice*1e-6
@@ -269,7 +296,4 @@
         gbx%dem_c    = 0.
 
-! Surafce emissivity
-       emsfc_lw = 1.
-               
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
         ! Define new vertical grid
@@ -288,5 +312,9 @@
         call construct_cosp_lidarstats(cfg,Npoints,Ncolumns,vgrid%Nlvgrid,N_HYDRO,PARASOL_NREFL,stlidar)
         call construct_cosp_isccp(cfg,Npoints,Ncolumns,Nlevels,isccp)
+!! AI rajout
+        call construct_cosp_modis(cfg,Npoints,modis)
+!!
         call construct_cosp_misr(cfg,Npoints,misr)
+!        call construct_cosp_rttov(cfg,Npoints,Nchannels,rttov)
 
 !+++++++++++++ Open output files and define output files axis !+++++++++++++
@@ -306,11 +334,21 @@
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
         print *, 'Calling simulator...'
-        call cosp(overlap,Ncolumns,cfg,vgrid,gbx,sgx,sgradar,sglidar,isccp,misr,stradar,stlidar)
+!! AI 
+!        call cosp(overlap,Ncolumns,cfg,vgrid,gbx,sgx,sgradar,sglidar,isccp,misr,stradar,stlidar)
+!#ifdef RTTOV
+!        call cosp(overlap,Ncolumns,cfg,vgrid,gbx,sgx,sgradar,sglidar,isccp,misr,modis,rttov,stradar,stlidar)
+!#else
+        call cosp(overlap,Ncolumns,cfg,vgrid,gbx,sgx,sgradar,sglidar,isccp,misr,modis,stradar,stlidar)
+!#endif
+!!
+
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 !!!!!!!!!!!!!!!!!! Ecreture des sorties Cosp !!!!!!!!!!!!!!r!!!!!!:!!!!!
+
        print *, 'Calling write output'
         call cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, freq_COSP, &
-                               cfg, gbx, vgrid, sglidar, stlidar, isccp)
+                               cfg, gbx, vgrid, sglidar, sgradar, stlidar, stradar, & 
+                               isccp, misr, modis)
 
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -326,4 +364,8 @@
         call free_cosp_isccp(isccp)
         call free_cosp_misr(misr)
+!! AI
+        call free_cosp_modis(modis)
+!        call free_cosp_rttov(rttov)
+!!
         call free_cosp_vgrid(vgrid)  
   
