Index: LMDZ5/trunk/libf/cosp/cosp_output_mod.F90
===================================================================
--- LMDZ5/trunk/libf/cosp/cosp_output_mod.F90	(revision 1926)
+++ LMDZ5/trunk/libf/cosp/cosp_output_mod.F90	(revision 1926)
@@ -0,0 +1,222 @@
+! A.Idelkadi sept 2013 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Module pour declarer et initialiser les parametres de controle des fichiers de sorties et des champs a sortir
+!! La routine cosp_output_open (appelee 1 seule fois dans phy_cosp.F90) permet :
+!! de creer les fichiers avec leurs grilles horizontales et verticales
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  MODULE cosp_output_mod
+
+  USE MOD_COSP_CONSTANTS
+  USE MOD_COSP_TYPES
+
+! cosp_output_mod
+      INTEGER, PRIVATE             :: i
+!!!!!!! Controle des fichier de sorties Cosp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+      LOGICAL, DIMENSION(3), SAVE  :: cosp_outfilekeys
+      INTEGER, DIMENSION(3), SAVE  :: cosp_nidfiles
+!$OMP THREADPRIVATE(cosp_outfilekeys, cosp_nidfiles)
+      INTEGER, DIMENSION(3), SAVE  :: nhoricosp, nvert, nvertmcosp, nvertcol, nvertisccp, nvertp
+      REAL, DIMENSION(3), SAVE                :: zoutm_cosp
+!$OMP THREADPRIVATE(nhori, nvert, nvertmcosp, nvertcol, nvertisccp, nvertp, zoutm_cosp)
+      REAL, SAVE                   :: zdtimemoy_cosp
+!$OMP THREADPRIVATE(zdtimemoy_cosp) 
+      CHARACTER(LEN=20), DIMENSION(3), SAVE  :: cosp_outfiletypes
+      CHARACTER(LEN=20), DIMENSION(3), SAVE  :: cosp_outfilenames
+      REAL, DIMENSION(3), SAVE               :: cosp_ecritfiles 
+!$OMP THREADPRIVATE(cosp_outfiletypes, cosp_outfilenames, cosp_ecritfiles)
+
+!!!!  Controle des variables a sortir dans les fichiers !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  TYPE ctrl_outcosp
+     LOGICAL,DIMENSION(3)                 :: cles             !!! Sortir ou non le champs
+     CHARACTER(len=20)                    :: name       
+     CHARACTER(len=150)                   :: description      !!! Nom
+     CHARACTER(len=20)                    :: unit             !!! Unite 
+     CHARACTER(len=20),DIMENSION(3)  :: cosp_typeecrit        !!! Operation (ave, inst, ...)
+  END TYPE ctrl_outcosp
+! CALIPSO vars
+  TYPE(ctrl_outcosp), SAVE :: o_cllcalipso = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+         "cllcalipso", "Lidar Low-level Cloud Fraction", "1", (/ ('', i=1, 3) /))                                   
+  TYPE(ctrl_outcosp), SAVE :: o_clmcalipso = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+         "clmcalipso", "Lidar Mid-level Cloud Fraction", "1", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_clhcalipso = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+         "clhcalipso", "Lidar Hight-level Cloud Fraction", "1", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_cltcalipso = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+         "cltcalipso", "Lidar Total Cloud Fraction", "1", (/ ('', i=1, 3) /)) 
+  TYPE(ctrl_outcosp), SAVE :: o_clcalipso = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+         "clcalipso", "Lidar Cloud Fraction (532 nm)", "1", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_cfad_lidarsr532 = ctrl_outcosp((/ .FALSE., .FALSE., .FALSE. /), &
+         "cfad_lidarsr532", "Lidar Scattering Ratio CFAD (532 nm)", "1", (/ ('', i=1, 3) /))   
+  TYPE(ctrl_outcosp), SAVE :: o_parasol_refl = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+         "parasol_refl", "PARASOL-like mono-directional reflectance","1", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_parasol_crefl = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &              
+         "parasol_crefl", "PARASOL-like mono-directional reflectance (integral)","1", (/ ('', i=1, 3) /))                  
+  TYPE(ctrl_outcosp), SAVE :: o_atb532 = ctrl_outcosp((/ .FALSE., .FALSE., .FALSE. /), &
+         "atb532", "Lidar Attenuated Total Backscatter (532 nm)","1", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_beta_mol532 = ctrl_outcosp((/ .FALSE., .FALSE., .FALSE. /), &
+         "beta_mol532", "Lidar Molecular Backscatter (532 nm)","m-1 sr-1", (/ ('', i=1, 3) /))
+! ISCCP vars
+  TYPE(ctrl_outcosp), SAVE :: o_sunlit = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+         "sunlit", "1 for day points, 0 for nightime","1",(/ ('', i=1, 3) /))                   
+  TYPE(ctrl_outcosp), SAVE :: o_clisccp2 = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+         "clisccp2", "Cloud Fraction as Calculated by the ISCCP Simulator","1", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_boxtauisccp = ctrl_outcosp((/ .FALSE., .FALSE., .FALSE. /), &
+         "boxtauisccp", "Optical Depth in Each Column as Calculated by the ISCCP Simulator","1", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_boxptopisccp = ctrl_outcosp((/ .FALSE., .FALSE., .FALSE. /), &
+         "boxptopisccp", "Cloud Top Pressure in Each Column as Calculated by the ISCCP Simulator","Pa", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_tclisccp = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+          "tclisccp", "Total Cloud Fraction as Calculated by the ISCCP Simulator", "1", (/ ('', i=1, 3) /)) 
+  TYPE(ctrl_outcosp), SAVE :: o_ctpisccp = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+          "ctpisccp", "Mean Cloud Top Pressure as Calculated by the ISCCP Simulator", "Pa", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_tauisccp = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+          "tauisccp", "Optical Depth as Calculated by the ISCCP Simulator", "1", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_albisccp = ctrl_outcosp((/ .TRUE., .TRUE., .TRUE. /), &
+          "albisccp", "Mean Cloud Albedo as Calculated by the ISCCP Simulator", "1", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_meantbisccp = ctrl_outcosp((/ .FALSE., .FALSE., .FALSE. /), &
+          "meantbisccp", " Mean all-sky 10.5 micron brightness temperature as calculated &
+           by the ISCCP Simulator","K", (/ ('', i=1, 3) /))
+  TYPE(ctrl_outcosp), SAVE :: o_meantbclrisccp = ctrl_outcosp((/ .FALSE., .FALSE., .FALSE. /), &
+          "meantbclrisccp", "Mean clear-sky 10.5 micron brightness temperature as calculated &
+           by the ISCCP Simulator","K", (/ ('', i=1, 3) /))
+
+!   LOGICAL, SAVE :: cosp_varsdefined = .FALSE. ! ug PAS THREADPRIVATE ET C'EST NORMAL
+  LOGICAL, SAVE        :: cosp_varsdefined
+  INTEGER, save        :: Nlevout,Ncolout
+!$OMP THREADPRIVATE(Nlevout) 
+
+CONTAINS
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!!!!!!!!! Ouverture des fichier et definition des  axes!!!!!!!!
+  !! histbeg, histvert
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
+
+  SUBROUTINE cosp_output_open(Nlevlmdz, Ncolumns, presnivs, dtime, freq_cosp, &
+                              ok_mensuelCOSP, ok_journeCOSP, ok_hfCOSP, &
+                              ecrit_mth, ecrit_day, ecrit_hf, use_vgrid, vgrid)
+
+
+  USE iophy
+  USE ioipsl
+  USE phys_cal_mod
+
+#ifdef CPP_XIOS
+    ! ug Pour les sorties XIOS
+    USE wxios
+#endif
+
+  IMPLICIT NONE
+
+!!! Variables d'entree
+  integer                  :: Nlevlmdz, Ncolumns      ! Number of levels
+  real,dimension(Nlevlmdz) :: presnivs
+  real                     :: dtime, freq_cosp, ecrit_day, ecrit_hf, ecrit_mth 
+  logical                  :: ok_mensuelCOSP, ok_journeCOSP, ok_hfCOSP, use_vgrid                    
+  type(cosp_vgrid)   :: vgrid   ! Information on vertical grid of stats
+
+!!! Variables locales
+  integer                  :: idayref, iff, ii
+  real                     :: zjulian
+  real,dimension(Ncolumns) :: column_ax
+
+!!! Variables d'entree
+  include "temps.h"
+  INCLUDE 'iniprint.h'
+
+#ifdef CPP_XIOS
+    ! ug Variables utilisées pour récupérer le calendrier pour xios
+    INTEGER :: x_an, x_mois, x_jour
+    REAL :: x_heure
+#endif
+
+    WRITE(lunout,*) 'Debut cosp_output_mod.F90'
+    ! Initialisations (Valeurs par defaut)
+    Nlevout = vgrid%Nlvgrid
+    Ncolout = Ncolumns
+
+    do ii=1,Ncolumns
+      column_ax(ii) = real(ii)
+    enddo
+
+
+    cosp_outfilenames(1) = 'histmthCOSP'
+    cosp_outfilenames(2) = 'histdayCOSP'
+    cosp_outfilenames(3) = 'histhfCOSP'
+
+    cosp_outfiletypes(1) = 'ave(X)'
+    cosp_outfiletypes(2) = 'ave(X)'
+    cosp_outfiletypes(3) = 'ave(X)'
+
+    cosp_outfilekeys(1) = ok_mensuelCOSP
+    cosp_outfilekeys(2) = ok_journeCOSP
+    cosp_outfilekeys(3) = ok_hfCOSP
+
+    cosp_ecritfiles(1) = mth_len*86400.
+    cosp_ecritfiles(2) = 1.*86400.
+    cosp_ecritfiles(3) = 0.125*86400.
+
+! Lecture des parametres dans output.def ou config.def
+
+    CALL getin('cosp_outfilenames',cosp_outfilenames)
+    CALL getin('cosp_outfilekeys',cosp_outfilekeys)
+    CALL getin('cosp_outfiletimesteps',cosp_ecritfiles)
+    CALL getin('cosp_outfiletypes',cosp_outfiletypes)
+
+    WRITE(lunout,*)'cosp_outfilenames=',cosp_outfilenames
+    WRITE(lunout,*)'cosp_outfilekeys=',cosp_outfilekeys
+    WRITE(lunout,*)'cosp_outfiletimesteps=',cosp_ecritfiles
+    WRITE(lunout,*)'cosp_outfiletypes=',cosp_outfiletypes
+ 
+#ifdef CPP_XIOS
+    ! ug Réglage du calendrier xios
+    !Temps julian => an, mois, jour, heure
+    CALL ymds2ju(annee_ref, 1, day_ref, 0.0, zjulian)
+    CALL ju2ymds(zjulian, x_an, x_mois, x_jour, x_heure)
+    CALL wxios_set_cal(dtime, calend, x_an, x_mois, x_jour, x_heure)
+#endif
+   
+    zdtimemoy_cosp = freq_COSP         ! Frequence ou l on moyenne
+
+    DO iff=1,3
+       zoutm_cosp(iff) = cosp_ecritfiles(iff) ! Frequence ou l on ecrit en seconde
+
+       IF (cosp_outfilekeys(iff)) THEN
+           idayref = day_ref
+           CALL ymds2ju(annee_ref, 1, idayref, 0., zjulian) 
+           CALL histbeg_phy(cosp_outfilenames(iff),itau_phy,zjulian,&
+             dtime,nhoricosp(iff),cosp_nidfiles(iff))
+
+! Definition de l'axe vertical
+       if (use_vgrid) then
+! Axe vertical Cosp 40 niveaux (en m)
+      CALL histvert(cosp_nidfiles(iff),"height","height","m",Nlevout,vgrid%z,nvert(iff))
+       else
+! Axe vertical modele LMDZ presnivs
+      CALL histvert(cosp_nidfiles(iff),"presnivs","Vertical levels","Pa",Nlevout,presnivs,nvert(iff),"down")
+       endif
+! Axe vertical niveaux modele (en m)
+      CALL histvert(cosp_nidfiles(iff),"height_mlev","height_mlev","m",Nlevlmdz,vgrid%mz,nvertmcosp(iff))
+
+      CALL histvert(cosp_nidfiles(iff),"sza","solar_zenith_angle","degrees",PARASOL_NREFL,PARASOL_SZA,nvertp(iff))
+
+      CALL histvert(cosp_nidfiles(iff),"pressure2","pressure","mb",7,ISCCP_PC,nvertisccp(iff),"down")
+
+      CALL histvert(cosp_nidfiles(iff),"column","column","count",Ncolumns,column_ax(1:Ncolumns),nvertcol(iff))
+
+#ifdef CPP_XIOS
+    ! ug déclaration des axes verticaux de chaque fichier:
+    if (use_vgrid) then
+      CALL wxios_add_vaxis("height", cosp_nidfiles(iff), Nlevout, vgrid%z)
+    else
+      CALL wxios_add_vaxis("presnivs", cosp_nidfiles(iff), Nlevout, presnivs)
+    endif
+    CALL wxios_add_vaxis("height_mlev", cosp_nidfiles(iff), Nlevlmdz, vgrid%mz)
+    CALL wxios_add_vaxis("sza", cosp_nidfiles(iff), PARASOL_NREFL, PARASOL_SZA)
+    CALL wxios_add_vaxis("pressure2", cosp_nidfiles(iff), 7, ISCCP_PC)
+    CALL wxios_add_vaxis("column", cosp_nidfiles(iff), Ncolumns, column_ax)
+#endif
+
+      ENDIF
+  ENDDO
+
+    end SUBROUTINE cosp_output_open
+
+ END MODULE cosp_output_mod
Index: LMDZ5/trunk/libf/cosp/cosp_output_write_mod.F90
===================================================================
--- LMDZ5/trunk/libf/cosp/cosp_output_write_mod.F90	(revision 1926)
+++ LMDZ5/trunk/libf/cosp/cosp_output_write_mod.F90	(revision 1926)
@@ -0,0 +1,533 @@
+!!!! Abderrahmane Idelkadi aout 2013 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Module pour definir (au 1er appel) et ecrire les variables dans les fichiers de sortie cosp
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   MODULE cosp_output_write_mod
+  
+   USE cosp_output_mod
+  
+   INTEGER, SAVE  :: itau_iocosp
+!$OMP THREADPRIVATE(itau_iocosp)
+
+!  INTERFACE histwrite_cosp
+!    MODULE PROCEDURE histwrite2d_cosp,histwrite3d_cosp
+!  END INTERFACE
+
+   CONTAINS
+
+  SUBROUTINE cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, freq_COSP, cfg, gbx, sglidar, stlidar, isccp)
+
+    USE ioipsl
+    USE control_mod
+
+#ifdef CPP_XIOS
+    ! ug Pour les sorties XIOS
+        USE wxios
+    USE xios
+#endif
+
+!!! Variables d'entree
+  integer               :: itap, Nlevlmdz, Ncolumns, Npoints
+  real                  :: freq_COSP, dtime
+  type(cosp_config)     :: cfg     ! Control outputs
+  type(cosp_gridbox)    :: gbx     ! Gridbox information. Input for COSP
+  type(cosp_sglidar)    :: sglidar ! Output from lidar simulator
+  type(cosp_isccp)      :: isccp   ! Output from ISCCP simulator
+  type(cosp_lidarstats) :: stlidar ! Summary statistics from lidar simulator
+
+!!! Variables locales
+  integer               :: icl, iinitend=1
+  logical               :: ok_sync
+  integer               :: itau_wcosp
+  real, dimension(Npoints,PARASOL_NREFL) :: parasolcrefl, Ncref
+
+  include "temps.h"
+
+  IF (MOD(itap,NINT(freq_COSP/dtime)).EQ.0) THEN
+       
+! A refaire
+       itau_wcosp = itau_phy + itap + start_time * day_step / iphysiq
+
+! On le donne a  cosp_output_write_mod pour que les histwrite y aient acces:
+       CALL set_itau_iocosp(itau_wcosp)
+
+    ok_sync = .TRUE.
+    
+    IF(.NOT.cosp_varsdefined) THEN
+        iinitend = 2
+    ELSE
+        iinitend = 1
+    ENDIF
+
+! ug la boucle qui suit ne sert qu'une fois, pour l'initialisation, sinon il n'y a toujours qu'un seul passage:
+DO iinit=1, iinitend
+#ifdef CPP_XIOS
+IF (cosp_varsdefined) THEN
+     CALL wxios_update_calendar(itau_iocosp)
+END IF
+#endif
+
+ if (cfg%Llidar_sim) then
+
+! Pb des valeurs indefinies, on les met a 0
+! A refaire proprement
+  do k = 1,Nlevout
+     do ip = 1,Npoints
+     if(stlidar%lidarcld(ip,k).eq.R_UNDEF)then
+      stlidar%lidarcld(ip,k)=0.
+     endif
+     enddo
+
+     do ii= 1,SR_BINS
+      do ip = 1,Npoints
+       if(stlidar%cfad_sr(ip,ii,k).eq.R_UNDEF)then
+        stlidar%cfad_sr(ip,ii,k)=0.
+       endif
+      enddo
+     enddo
+   enddo
+
+  do ip = 1,Npoints
+   do k = 1,Nlevlmdz
+     if(sglidar%beta_mol(ip,k).eq.R_UNDEF)then
+      sglidar%beta_mol(ip,k)=0.
+     endif
+
+     do ii= 1,Ncolumns
+       if(sglidar%beta_tot(ip,ii,k).eq.R_UNDEF)then
+        sglidar%beta_tot(ip,ii,k)=0.
+       endif
+     enddo
+
+    enddo    !k = 1,Nlevlmdz
+   enddo     !ip = 1,Npoints
+
+   do k = 1,LIDAR_NCAT
+    do ip = 1,Npoints
+     if(stlidar%cldlayer(ip,k).eq.R_UNDEF)then
+      stlidar%cldlayer(ip,k)=0.
+     endif
+    enddo
+   enddo
+
+   CALL histwrite2d_cosp(o_cllcalipso,stlidar%cldlayer(:,1))
+   CALL histwrite2d_cosp(o_clhcalipso,stlidar%cldlayer(:,3))
+   CALL histwrite2d_cosp(o_clmcalipso,stlidar%cldlayer(:,2)) 
+   CALL histwrite2d_cosp(o_cltcalipso,stlidar%cldlayer(:,4))
+   CALL histwrite3d_cosp(o_clcalipso,stlidar%lidarcld,nvert)
+
+   do icl=1,SR_BINS
+      CALL histwrite3d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr(:,icl,:),nvert,icl)
+   enddo
+
+   CALL histwrite3d_cosp(o_parasol_refl,stlidar%parasolrefl,nvertp)
+
+   do k=1,PARASOL_NREFL
+    do ip=1, Npoints
+     if (stlidar%cldlayer(ip,4).gt.0.01) then
+       parasolcrefl(ip,k)=(stlidar%parasolrefl(ip,k)-0.03*(1.-stlidar%cldlayer(ip,4)))/ &
+                            stlidar%cldlayer(ip,4)
+        Ncref(ip,k) = 1.
+     else
+        parasolcrefl(ip,k)=0.
+        Ncref(ip,k) = 0.
+     endif
+    enddo
+   enddo
+   CALL histwrite3d_cosp(o_parasol_crefl,parasolcrefl,nvertp)
+
+   do icl=1,Ncolumns 
+      CALL histwrite3d_cosp(o_atb532,sglidar%beta_tot(:,icl,:),nvertmcosp,icl)
+   enddo
+   CALL histwrite3d_cosp(o_beta_mol532,sglidar%beta_mol,nvertmcosp) 
+ endif !Lidar
+
+ if (cfg%Lisccp_sim) then
+
+! Traitement des valeurs indefinies
+   do ip = 1,Npoints
+    if(isccp%totalcldarea(ip).eq.-1.E+30)then
+      isccp%totalcldarea(ip)=0.
+    endif
+    if(isccp%meanptop(ip).eq.-1.E+30)then
+      isccp%meanptop(ip)=0.
+    endif
+    if(isccp%meantaucld(ip).eq.-1.E+30)then
+      isccp%meantaucld(ip)=0.
+    endif
+    if(isccp%meanalbedocld(ip).eq.-1.E+30)then
+      isccp%meanalbedocld(ip)=0.
+    endif
+    if(isccp%meantb(ip).eq.-1.E+30)then
+      isccp%meantb(ip)=0.
+    endif
+    if(isccp%meantbclr(ip).eq.-1.E+30)then
+      isccp%meantbclr(ip)=0.
+    endif
+
+    do k=1,7
+     do ii=1,7
+     if(isccp%fq_isccp(ip,ii,k).eq.-1.E+30)then
+      isccp%fq_isccp(ip,ii,k)=0.
+     endif
+     enddo
+    enddo
+
+    do ii=1,Ncolumns
+     if(isccp%boxtau(ip,ii).eq.-1.E+30)then
+       isccp%boxtau(ip,ii)=0.
+     endif
+    enddo
+
+    do ii=1,Ncolumns
+     if(isccp%boxptop(ip,ii).eq.-1.E+30)then
+       isccp%boxptop(ip,ii)=0.
+     endif
+    enddo
+   enddo
+
+   CALL histwrite2d_cosp(o_sunlit,gbx%sunlit)
+   do icl=1,7
+   CALL histwrite3d_cosp(o_clisccp2,isccp%fq_isccp(:,icl,:),nvertisccp,icl) 
+   enddo
+   CALL histwrite3d_cosp(o_boxtauisccp,isccp%boxtau,nvertcol)
+   CALL histwrite3d_cosp(o_boxptopisccp,isccp%boxptop,nvertcol) 
+   CALL histwrite2d_cosp(o_tclisccp,isccp%totalcldarea) 
+   CALL histwrite2d_cosp(o_ctpisccp,isccp%meanptop) 
+   CALL histwrite2d_cosp(o_tauisccp,isccp%meantaucld) 
+   CALL histwrite2d_cosp(o_albisccp,isccp%meanalbedocld) 
+   CALL histwrite2d_cosp(o_meantbisccp,isccp%meantb) 
+   CALL histwrite2d_cosp(o_meantbclrisccp,isccp%meantbclr)
+ endif ! Isccp
+
+ IF(.NOT.cosp_varsdefined) THEN
+!$OMP MASTER
+            DO iff=1,3
+                IF (cosp_outfilekeys(iff)) THEN
+                  CALL histend(cosp_nidfiles(iff))
+                ENDIF ! cosp_outfilekeys
+            ENDDO !  iff
+#ifdef CPP_XIOS
+            !On finalise l'initialisation:
+            CALL wxios_closedef()
+#endif
+!$OMP END MASTER
+!$OMP BARRIER
+            cosp_varsdefined = .TRUE.
+ END IF
+END DO  !! iinit
+
+!    IF(cosp_varsdefined) THEN
+! On synchronise les fichiers pour IOIPSL
+!$OMP MASTER
+   DO iff=1,3
+         IF (ok_sync .AND. cosp_outfilekeys(iff)) THEN
+             CALL histsync(cosp_nidfiles(iff))
+         ENDIF
+   END DO
+!$OMP END MASTER
+
+   ENDIF ! if freq_COSP
+
+    END SUBROUTINE cosp_output_write
+
+! ug Routine pour definir itau_iocosp depuis cosp_output_write_mod:
+  SUBROUTINE set_itau_iocosp(ito)
+      IMPLICIT NONE
+      INTEGER, INTENT(IN) :: ito
+      itau_iocosp = ito
+  END SUBROUTINE
+
+  SUBROUTINE histdef2d_cosp (iff,var)
+
+    USE ioipsl
+    USE dimphy
+    use iophy
+    USE mod_phys_lmdz_para
+
+    IMPLICIT NONE
+
+    INCLUDE "dimensions.h"
+    INCLUDE "temps.h"
+
+    INTEGER                          :: iff
+    TYPE(ctrl_outcosp)               :: var
+
+    REAL zstophym
+    CHARACTER(LEN=20) :: typeecrit
+
+    ! ug On rÃ©cupÃ¨re le type Ã©crit de la structure:
+    !       Assez moche, Ã|  refaire si meilleure mÃ©thode...
+    IF (INDEX(var%cosp_typeecrit(iff), "once") > 0) THEN
+       typeecrit = 'once'
+    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_min") > 0) THEN
+       typeecrit = 't_min(X)'
+    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_max") > 0) THEN
+       typeecrit = 't_max(X)'
+    ELSE IF(INDEX(var%cosp_typeecrit(iff), "inst") > 0) THEN
+       typeecrit = 'inst(X)'
+    ELSE
+       typeecrit = cosp_outfiletypes(iff)
+    ENDIF
+
+    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
+       zstophym=zoutm_cosp(iff)
+    ELSE
+       zstophym=zdtimemoy_cosp
+    ENDIF
+
+#ifdef CPP_XIOS
+        CALL wxios_add_field_to_file(var%name, 2, cosp_nidfiles(iff),
+cosp_outfilenames(iff), &
+        var%description, var%unit, var%cles(iff), typeecrit)
+#endif
+       IF ( var%cles(iff) ) THEN
+          CALL histdef (cosp_nidfiles(iff), var%name, var%description, var%unit, &
+               iim,jj_nb,nhoricosp(iff), 1,1,1, -99, 32, &
+               typeecrit, zstophym,zoutm_cosp(iff))
+       ENDIF
+
+  END SUBROUTINE histdef2d_cosp
+
+ SUBROUTINE histdef3d_cosp (iff,var,nvertsave,ncols)
+    USE ioipsl
+    USE dimphy
+    use iophy
+    USE mod_phys_lmdz_para
+
+    IMPLICIT NONE
+
+    INCLUDE "dimensions.h"
+    INCLUDE "temps.h"
+
+    INTEGER                        :: iff, klevs
+    INTEGER, INTENT(IN), OPTIONAL  :: ncols ! ug RUSTINE POUR LES variables 4D
+    INTEGER, INTENT(IN)           :: nvertsave
+    TYPE(ctrl_outcosp)             :: var
+
+    REAL zstophym
+    CHARACTER(LEN=20) :: typeecrit, nomi
+    CHARACTER(LEN=20) :: nom
+    character(len=2) :: str2
+
+! Axe vertical
+      IF (nvertsave.eq.nvertp(iff)) THEN
+          klevs=PARASOL_NREFL
+      ELSE IF (nvertsave.eq.nvertisccp(iff)) THEN
+          klevs=7
+      ELSE IF (nvertsave.eq.nvertcol(iff)) THEN
+          klevs=Ncolout
+      ELSE
+          klevs=Nlevout
+      ENDIF
+      
+         
+! ug RUSTINE POUR LES Champs 4D
+      IF (PRESENT(ncols)) THEN
+               write(str2,'(i2.2)')ncols
+               nomi=var%name
+               nom="c"//str2//"_"//nomi
+      ELSE
+               nom=var%name
+      END IF
+
+    ! ug On rÃ©cupÃ¨re le type Ã©crit de la structure:
+    !       Assez moche, Ã|  refaire si meilleure mÃ©thode...
+    IF (INDEX(var%cosp_typeecrit(iff), "once") > 0) THEN
+       typeecrit = 'once'
+    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_min") > 0) THEN
+       typeecrit = 't_min(X)'
+    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_max") > 0) THEN
+       typeecrit = 't_max(X)'
+    ELSE IF(INDEX(var%cosp_typeecrit(iff), "inst") > 0) THEN
+       typeecrit = 'inst(X)'
+    ELSE
+       typeecrit = cosp_outfiletypes(iff)
+    ENDIF
+
+    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
+       zstophym=zoutm_cosp(iff)
+    ELSE
+       zstophym=zdtimemoy_cosp
+    ENDIF
+
+#ifdef CPP_XIOS
+        CALL wxios_add_field_to_file(nom, 3, cosp_nidfiles(iff),
+cosp_outfilenames(iff), &
+        var%description, var%unit, var%flag(iff), typeecrit)
+#endif
+       IF ( var%cles(iff) ) THEN
+          CALL histdef (cosp_nidfiles(iff), nom, var%description, var%unit, &
+               iim, jj_nb, nhoricosp(iff), klevs, 1, &
+               klevs, nvertsave, 32, typeecrit, &
+               zstophym, zoutm_cosp(iff))
+       ENDIF
+  END SUBROUTINE histdef3d_cosp
+
+ SUBROUTINE histwrite2d_cosp(var,field)
+  USE dimphy
+  USE mod_phys_lmdz_para
+  USE ioipsl
+  use iophy
+
+#ifdef CPP_XIOS
+  USE wxios
+#endif
+
+  IMPLICIT NONE
+  INCLUDE 'dimensions.h'
+  INCLUDE 'iniprint.h'
+
+    TYPE(ctrl_outcosp), INTENT(IN) :: var
+    REAL, DIMENSION(:), INTENT(IN) :: field
+
+    INTEGER :: iff
+
+    REAL,DIMENSION(klon_mpi) :: buffer_omp
+    INTEGER, allocatable, DIMENSION(:) :: index2d
+    REAL :: Field2d(iim,jj_nb)
+    CHARACTER(LEN=20) ::  nomi, nom
+    character(len=2) :: str2
+
+    IF (prt_level >= 9) WRITE(lunout,*)'Begin histrwrite2d ',var%name
+
+  ! On regarde si on est dans la phase de dÃ©finition ou d'Ã©criture:
+  IF(.NOT.cosp_varsdefined) THEN
+!$OMP MASTER
+      !Si phase de dÃ©finition.... on dÃ©finit
+      CALL conf_cospoutputs(var%name,var%cles)
+      DO iff=1, 3
+         IF (cosp_outfilekeys(iff)) THEN
+            CALL histdef2d_cosp(iff, var)
+         ENDIF
+      ENDDO
+!$OMP END MASTER
+  ELSE
+    !Et sinon on.... Ã©crit
+    IF (SIZE(field)/=klon) &
+  CALL abort_gcm('iophy::histwrite2d_cosp','Field first DIMENSION not equal to klon',1) 
+
+    CALL Gather_omp(field,buffer_omp)
+!$OMP MASTER
+    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
+
+! La boucle sur les fichiers:
+      DO iff=1, 3
+           IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
+                ALLOCATE(index2d(iim*jj_nb))
+        CALL histwrite(cosp_nidfiles(iff),var%name,itau_iocosp,Field2d,iim*jj_nb,index2d) 
+#ifdef CPP_XIOS
+                IF (iff == 1) THEN
+                   CALL wxios_write_2D(var%name, Field2d)
+                ENDIF
+#endif
+
+                deallocate(index2d)
+           ENDIF !levfiles
+      ENDDO
+!$OMP END MASTER   
+  ENDIF ! vars_defined
+  IF (prt_level >= 9) WRITE(lunout,*)'End histrwrite2d_cosp ',nom
+  END SUBROUTINE histwrite2d_cosp
+
+! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
+! AI sept 2013
+  SUBROUTINE histwrite3d_cosp(var, field, nverts, ncols)
+  USE dimphy
+  USE mod_phys_lmdz_para
+  USE ioipsl
+  use iophy
+
+#ifdef CPP_XIOS
+! USE WXIOS
+#endif
+
+
+  IMPLICIT NONE
+  INCLUDE 'dimensions.h'
+  INCLUDE 'iniprint.h'
+
+    TYPE(ctrl_outcosp), INTENT(IN)    :: var
+    REAL, DIMENSION(:,:), INTENT(IN)  :: field ! --> field(klon,:)
+    INTEGER, INTENT(IN), OPTIONAL     :: ncols ! ug RUSTINE POUR LES Champs 4D.....
+    INTEGER, DIMENSION(3), INTENT(IN) :: nverts
+
+    INTEGER :: iff, k
+
+    REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
+    REAL :: Field3d(iim,jj_nb,SIZE(field,2))
+    INTEGER :: ip, n, nlev
+    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
+    CHARACTER(LEN=20) ::  nomi, nom
+    character(len=2) :: str2
+
+  IF (prt_level >= 9) write(lunout,*)'Begin histrwrite3d ',var%name
+
+! ug RUSTINE POUR LES STD LEVS.....
+      IF (PRESENT(ncols)) THEN
+              write(str2,'(i2.2)')ncols
+              nomi=var%name
+              nom="c"//str2//"_"//nomi
+      ELSE
+               nom=var%name
+      END IF
+  ! On regarde si on est dans la phase de dÃ©finition ou d'Ã©criture:
+  IF(.NOT.cosp_varsdefined) THEN
+      !Si phase de dÃ©finition.... on dÃ©finit
+!$OMP MASTER
+      CALL conf_cospoutputs(var%name,var%cles)
+      DO iff=1, 3
+        IF (cosp_outfilekeys(iff)) THEN
+          CALL histdef3d_cosp(iff, var, nverts(iff), ncols)
+        ENDIF
+      ENDDO
+!$OMP END MASTER
+  ELSE
+    !Et sinon on.... Ã©crit
+    IF (SIZE(field,1)/=klon) &
+   CALL abort_gcm('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)                                  
+    nlev=SIZE(field,2)
+
+
+    CALL Gather_omp(field,buffer_omp)
+!$OMP MASTER
+    CALL grid1Dto2D_mpi(buffer_omp,field3d)
+
+
+! BOUCLE SUR LES FICHIERS
+     DO iff=1, 3
+        IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
+           ALLOCATE(index3d(iim*jj_nb*nlev))
+    CALL histwrite(cosp_nidfiles(iff),nom,itau_iocosp,Field3d,iim*jj_nb*nlev,index3d) 
+
+#ifdef CPP_XIOS
+           IF (iff == 1) THEN
+               CALL wxios_write_3D(nom, Field3d(:,:,1:klev))
+           ENDIF
+#endif
+         deallocate(index3d)
+        ENDIF
+      ENDDO
+!$OMP END MASTER   
+  ENDIF ! vars_defined
+  IF (prt_level >= 9) write(lunout,*)'End histrwrite3d_cosp ',nom
+  END SUBROUTINE histwrite3d_cosp
+
+  SUBROUTINE conf_cospoutputs(nam_var,cles_var)
+!!! Lecture des noms et cles de sortie des variables dans config.def
+    !   en utilisant les routines getin de IOIPSL  
+    use ioipsl
+
+    IMPLICIT NONE
+    include 'iniprint.h'
+
+   CHARACTER(LEN=20)               :: nam_var, nnam_var
+   LOGICAL, DIMENSION(3)           :: cles_var
+
+! Lecture dans config.def ou output.def de cles_var et name_var
+    CALL getin('cles_'//nam_var,cles_var)
+    CALL getin('name_'//nam_var,nam_var)
+    IF(prt_level>10) WRITE(lunout,*)'nam_var cles_var ',nam_var,cles_var(:)
+
+  END SUBROUTINE conf_cospoutputs
+
+ END MODULE cosp_output_write_mod
Index: LMDZ5/trunk/libf/cosp/ini_histdayCOSP.h
===================================================================
--- LMDZ5/trunk/libf/cosp/ini_histdayCOSP.h	(revision 1925)
+++ 	(revision )
@@ -1,197 +1,0 @@
-! Abderrahmane Idelkadi Septebmre 2009
-! Sorties journalieres de COSP 
-! Pour l'instant sorties Lidar et ISCCP
-!
-! sorties par jour
-!
-!$OMP MASTER
-        zstoday = ecrit_day
-        zout = freq_COSP
-!
-!       PRINT*, 'La frequence de sortie hf3d est de ', ecrit_hf
-!
-
-        idayref = day_ref
-        CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-
-        CALL histbeg_phy("histdayCOSP",itau_phy,zjulian,dtime,nhori,nid_day_cosp) 
-
-! Definition de l'axe vertical
-       if (use_vgrid) then
-        CALL histvert(nid_day_cosp,"height","height","m",Nlevout,vgrid%z,nvert)
-       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,nvertmcosp)
-
-        CALL histvert(nid_day_cosp,"sza","solar_zenith_angle","degrees",PARASOL_NREFL,PARASOL_SZA,nvertp)
-
-        CALL histvert(nid_day_cosp,"pressure2","pressure","mb",7,ISCCP_PC,nvertisccp)
-
-        CALL histvert(nid_day_cosp,"column","column","count",Ncolumns,column_ax(1:Ncolumns),nvertcol)
-
-! Sorties LIDAR
-       if (cfg%Llidar_sim) then
-         if (cfg%Lcllcalipso) then
-         CALL histdef(nid_day_cosp, "cllcalipso", &
-                     "Lidar Low-level Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstoday)
-         endif
-         if (cfg%Lclhcalipso) then
-         CALL histdef(nid_day_cosp, "clhcalipso", &
-                     "Lidar High-level Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstoday)
-         endif
-         if (cfg%Lclmcalipso) then
-         CALL histdef(nid_day_cosp, "clmcalipso", &
-                     "Lidar Mid-level Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstoday)
-         endif
-         if (cfg%Lcltcalipso) then
-         CALL histdef(nid_day_cosp, "cltcalipso", &
-                     "Lidar Total Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstoday)
-         endif
-         if (cfg%Lclcalipso) then
-         CALL histdef(nid_day_cosp, "clcalipso", &
-                     "Lidar Cloud Fraction (532 nm)", "1", &
-                     iim,jj_nb,nhori, Nlevout,1,Nlevout,nvert, 32, &
-                     "ave(X)", zout,zstoday)
-         endif
-           if (cfg%Lcfad_lidarsr532) then
-              do ii=1,SR_BINS
-               CALL histdef(nid_day_cosp, "cfad_lidarsr532_"//chcol(ii), &
-                           "Lidar Scattering Ratio CFAD (532 nm)","1", &
-                           iim,jj_nb,nhori, Nlevout,1,Nlevout,nvert, 32, &
-                           "ave(X)", zout,zstoday)   
-              enddo
-           endif
-           if (cfg%Lparasol_refl) then
-            CALL histdef(nid_day_cosp, "parasol_refl", &
-                        "PARASOL-like mono-directional reflectance","1", &
-                        iim,jj_nb,nhori, PARASOL_NREFL,1, PARASOL_NREFL, nvertp,32, &
-                        "ave(X)", zout,zstoday)   
-           endif
-           if (cfg%Latb532) then
-            do ii=1,Ncolumns
-             CALL histdef(nid_day_cosp, "atb532_"//chcol(ii), &
-                         "Lidar Attenuated Total Backscatter (532 nm)","1", &
-                         iim,jj_nb,nhori, Nlevlmdz,1,Nlevlmdz,nvertmcosp, 32, &
-                         "ave(X)", zout,zstoday)
-            enddo
-           endif
-           if (cfg%Lbeta_mol532) then
-            CALL histdef(nid_day_cosp, "beta_mol532", &
-                        "Lidar Molecular Backscatter (532 nm)","m-1 sr-1", &
-                        iim,jj_nb,nhori, Nlevlmdz,1,Nlevlmdz,nvertmcosp, 32, &
-                         "ave(X)", zout,zstoday)
-           endif
-        endif ! Lidar
-
-! Sorties RADAR
-!Attention A FAIRE
-!        if (cfg%Lradar_sim) then
-!         print*,'Ecriture sorties Radar'
-!          if (cfg%Lcfad_dbze94) then
-!              print*,'Ecriture de cfad_dbze94.nc '
-!              A revoir l axe vertical Nlvgrid
-!               do ii=1,DBZE_BINS
-!                   dbze_ax(ii) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*(ii - 0.5)
-!               enddo
-!               call write_netcdf4d('cfad_dbze94.nc',use_vgrid,nlon,nlat,Nlevout,DBZE_BINS, &
-!                                   x,y,out_levs,dbze_ax,i,ndays,time,stradar%cfad_ze)
-!          endif
-!          if (cfg%Lclcalipso2) then
-!               call write_netcdf3d('clcalipso2.nc',use_vgrid,'clcalipso2', &
-!                              nlon,nlat,Nlevout,x,y,out_levs,i,ndays,time,stradar%lidar_only_freq_cloud)
-!          endif
-!          if (cfg%Ldbze94) then
-!             do ii=1,Ncolumns
-!                xcol(ii)=float(i)
-!             enddo
-!             call write_netcdf4d('dbze94.nc',use_vgrid,nlon,nlat,Nlevout,Ncolumns, &
-!                                 x,y,out_levs,xcol,i,ndays,time,sgradar%Ze_tot)
-!          endif
-!          if (cfg%Lcltlidarradar) then
-!             call write_netcdf2d('cltlidarradar.nc','cltlidarradar', &
-!                                 nlon,nlat,x,y,i,ndays,time,stradar%radar_lidar_tcc)
-!          endif
-!        endif  ! Radar
-
-! Sorties MISR
-!Attention A FAIRE
-!        if (cfg%Lmisr_sim) then
-!         print*,'Ecriture sorties Misr'
-!            call write_netcdf4d('clMISR.nc',use_vgrid,nlon,nlat,MISR_N_CTH,7, &
-!                                x,y,MISR_CTH,ISCCP_TAU,i,ndays,time,misr%fq_MISR)
-!        endif
-
-! Sorties ISCCP
-        if (cfg%Lisccp_sim) then
-         if (cfg%Lclisccp2) then
-            do ii=1,7
-             CALL histdef(nid_day_cosp, "clisccp2_"//chcol(ii), &
-                         "Cloud Fraction as Calculated by the ISCCP Simulator","1", &
-                         iim,jj_nb,nhori,7,1,7,nvertisccp, 32, &
-                         "ave(X)", zout,zstoday)
-            enddo
-          endif
-          if (cfg%Lboxtauisccp) then
-            CALL histdef(nid_day_cosp, "boxtauisccp", &
-                         "Optical Depth in Each Column as Calculated by the ISCCP Simulator","1", &
-                         iim,jj_nb,nhori,Ncolumns,1,Ncolumns,nvertcol, 32, &
-                         "ave(X)", zout,zstoday)
-          endif
-          if (cfg%Lboxptopisccp) then
-            CALL histdef(nid_day_cosp, "boxptopisccp", &
-                         "Cloud Top Pressure in Each Column as Calculated by the ISCCP Simulator","Pa", &
-                         iim,jj_nb,nhori,Ncolumns,1,Ncolumns,nvertcol, 32, &
-                         "ave(X)", zout,zstoday)
-          endif
-          if (cfg%Ltclisccp) then
-           CALL histdef(nid_day_cosp, "tclisccp", &
-                     "Total Cloud Fraction as Calculated by the ISCCP Simulator", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstoday)
-          endif
-          if (cfg%Lctpisccp) then
-            CALL histdef(nid_day_cosp, "ctpisccp", &
-                     "Mean Cloud Top Pressure as Calculated by the ISCCP Simulator", "Pa", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstoday)
-          endif
-          if (cfg%Ltauisccp) then
-           CALL histdef(nid_day_cosp, "tauisccp", &
-                     "Optical Depth as Calculated by the ISCCP Simulator", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstoday)
-          endif
-          if (cfg%Lalbisccp) then
-           CALL histdef(nid_day_cosp, "albisccp", &
-                     "Mean Cloud Albedo as Calculated by the ISCCP Simulator", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstoday) 
-          endif
-          if (cfg%Lmeantbisccp) then
-            CALL histdef(nid_day_cosp, "meantbisccp", &
-             " Mean all-sky 10.5 micron brightness temperature as calculated by the ISCCP Simulator","K", &
-             iim, jj_nb,nhori,1,1,1,-99,32, &
-             "ave(X)", zout,zstoday)
-          endif
-          if (cfg%Lmeantbclrisccp) then
-           CALL histdef(nid_day_cosp, "meantbclrisccp", &
-            "Mean clear-sky 10.5 micron brightness temperature as calculated by the ISCCP Simulator","K", &
-             iim, jj_nb,nhori,1,1,1,-99,32, &
-             "ave(X)", zout,zstoday) 
-          endif
-        endif ! Isccp
-
-
-        CALL histend(nid_day_cosp)
-!$OMP END MASTER
-!$OMP BARRIER
Index: LMDZ5/trunk/libf/cosp/ini_histhfCOSP.h
===================================================================
--- LMDZ5/trunk/libf/cosp/ini_histhfCOSP.h	(revision 1925)
+++ 	(revision )
@@ -1,197 +1,0 @@
-! Abderrahmane Idelkadi Septebmre 2009
-! Sorties journalieres de COSP 
-! Pour l'instant sorties Lidar et ISCCP
-!
-! sorties par jour
-!
-!$OMP MASTER
-        zstohf = ecrit_hf
-        zout = freq_COSP
-!
-!       PRINT*, 'La frequence de sortie hf3d est de ', ecrit_hf
-!
-
-        idayref = day_ref
-        CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-
-        CALL histbeg_phy("histhfCOSP",itau_phy,zjulian,dtime,nhori,nid_hf_cosp) 
-
-! Definition de l'axe vertical
-       if (use_vgrid) then
-        CALL histvert(nid_hf_cosp,"height","height","m",Nlevout,vgrid%z,nvert)
-       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,nvertmcosp)
-
-        CALL histvert(nid_hf_cosp,"sza","solar_zenith_angle","degrees",PARASOL_NREFL,PARASOL_SZA,nvertp)
-
-        CALL histvert(nid_hf_cosp,"pressure2","pressure","mb",7,ISCCP_PC,nvertisccp)
-
-        CALL histvert(nid_hf_cosp,"column","column","count",Ncolumns,column_ax(1:Ncolumns),nvertcol)
-
-! Sorties LIDAR
-       if (cfg%Llidar_sim) then
-         if (cfg%Lcllcalipso) then
-         CALL histdef(nid_hf_cosp, "cllcalipso", &
-                     "Lidar Low-level Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstohf)
-         endif
-         if (cfg%Lclhcalipso) then
-         CALL histdef(nid_hf_cosp, "clhcalipso", &
-                     "Lidar High-level Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstohf)
-         endif
-         if (cfg%Lclmcalipso) then
-         CALL histdef(nid_hf_cosp, "clmcalipso", &
-                     "Lidar Mid-level Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstohf)
-         endif
-         if (cfg%Lcltcalipso) then
-         CALL histdef(nid_hf_cosp, "cltcalipso", &
-                     "Lidar Total Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstohf)
-         endif
-         if (cfg%Lclcalipso) then
-         CALL histdef(nid_hf_cosp, "clcalipso", &
-                     "Lidar Cloud Fraction (532 nm)", "1", &
-                     iim,jj_nb,nhori, Nlevout,1,Nlevout,nvert, 32, &
-                     "ave(X)", zout,zstohf)
-         endif
-           if (cfg%Lcfad_lidarsr532) then
-              do ii=1,SR_BINS
-               CALL histdef(nid_hf_cosp, "cfad_lidarsr532_"//chcol(ii), &
-                           "Lidar Scattering Ratio CFAD (532 nm)","1", &
-                           iim,jj_nb,nhori, Nlevout,1,Nlevout,nvert, 32, &
-                           "ave(X)", zout,zstohf)   
-              enddo
-           endif
-           if (cfg%Lparasol_refl) then
-            CALL histdef(nid_hf_cosp, "parasol_refl", &
-                        "PARASOL-like mono-directional reflectance","1", &
-                        iim,jj_nb,nhori, PARASOL_NREFL,1, PARASOL_NREFL, nvertp,32, &
-                        "ave(X)", zout,zstohf)   
-           endif
-           if (cfg%Latb532) then
-            do ii=1,Ncolumns
-             CALL histdef(nid_hf_cosp, "atb532_"//chcol(ii), &
-                         "Lidar Attenuated Total Backscatter (532 nm)","1", &
-                         iim,jj_nb,nhori, Nlevlmdz,1,Nlevlmdz,nvertmcosp, 32, &
-                         "ave(X)", zout,zstohf)
-            enddo
-           endif
-           if (cfg%Lbeta_mol532) then
-            CALL histdef(nid_hf_cosp, "beta_mol532", &
-                        "Lidar Molecular Backscatter (532 nm)","m-1 sr-1", &
-                        iim,jj_nb,nhori, Nlevlmdz,1,Nlevlmdz,nvertmcosp, 32, &
-                         "ave(X)", zout,zstohf)
-           endif
-        endif ! Lidar
-
-! Sorties RADAR
-!Attention A FAIRE
-!        if (cfg%Lradar_sim) then
-!         print*,'Ecriture sorties Radar'
-!          if (cfg%Lcfad_dbze94) then
-!              print*,'Ecriture de cfad_dbze94.nc '
-!              A revoir l axe vertical Nlvgrid
-!               do ii=1,DBZE_BINS
-!                   dbze_ax(ii) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*(ii - 0.5)
-!               enddo
-!               call write_netcdf4d('cfad_dbze94.nc',use_vgrid,nlon,nlat,Nlevout,DBZE_BINS, &
-!                                   x,y,out_levs,dbze_ax,i,ndays,time,stradar%cfad_ze)
-!          endif
-!          if (cfg%Lclcalipso2) then
-!               call write_netcdf3d('clcalipso2.nc',use_vgrid,'clcalipso2', &
-!                              nlon,nlat,Nlevout,x,y,out_levs,i,ndays,time,stradar%lidar_only_freq_cloud)
-!          endif
-!          if (cfg%Ldbze94) then
-!             do ii=1,Ncolumns
-!                xcol(ii)=float(i)
-!             enddo
-!             call write_netcdf4d('dbze94.nc',use_vgrid,nlon,nlat,Nlevout,Ncolumns, &
-!                                 x,y,out_levs,xcol,i,ndays,time,sgradar%Ze_tot)
-!          endif
-!          if (cfg%Lcltlidarradar) then
-!             call write_netcdf2d('cltlidarradar.nc','cltlidarradar', &
-!                                 nlon,nlat,x,y,i,ndays,time,stradar%radar_lidar_tcc)
-!          endif
-!        endif  ! Radar
-
-! Sorties MISR
-!Attention A FAIRE
-!        if (cfg%Lmisr_sim) then
-!         print*,'Ecriture sorties Misr'
-!            call write_netcdf4d('clMISR.nc',use_vgrid,nlon,nlat,MISR_N_CTH,7, &
-!                                x,y,MISR_CTH,ISCCP_TAU,i,ndays,time,misr%fq_MISR)
-!        endif
-
-! Sorties ISCCP
-        if (cfg%Lisccp_sim) then
-         if (cfg%Lclisccp2) then
-            do ii=1,7
-             CALL histdef(nid_hf_cosp, "clisccp2_"//chcol(ii), &
-                         "Cloud Fraction as Calculated by the ISCCP Simulator","1", &
-                         iim,jj_nb,nhori,7,1,7,nvertisccp, 32, &
-                         "ave(X)", zout,zstohf)
-            enddo
-          endif
-          if (cfg%Lboxtauisccp) then
-            CALL histdef(nid_hf_cosp, "boxtauisccp", &
-                         "Optical Depth in Each Column as Calculated by the ISCCP Simulator","1", &
-                         iim,jj_nb,nhori,Ncolumns,1,Ncolumns,nvertcol, 32, &
-                         "ave(X)", zout,zstohf)
-          endif
-          if (cfg%Lboxptopisccp) then
-            CALL histdef(nid_hf_cosp, "boxptopisccp", &
-                         "Cloud Top Pressure in Each Column as Calculated by the ISCCP Simulator","Pa", &
-                         iim,jj_nb,nhori,Ncolumns,1,Ncolumns,nvertcol, 32, &
-                         "ave(X)", zout,zstohf)
-          endif
-          if (cfg%Ltclisccp) then
-           CALL histdef(nid_hf_cosp, "tclisccp", &
-                     "Total Cloud Fraction as Calculated by the ISCCP Simulator", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstohf)
-          endif
-          if (cfg%Lctpisccp) then
-            CALL histdef(nid_hf_cosp, "ctpisccp", &
-                     "Mean Cloud Top Pressure as Calculated by the ISCCP Simulator", "Pa", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstohf)
-          endif
-          if (cfg%Ltauisccp) then
-           CALL histdef(nid_hf_cosp, "tauisccp", &
-                     "Optical Depth as Calculated by the ISCCP Simulator", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstohf)
-          endif
-          if (cfg%Lalbisccp) then
-           CALL histdef(nid_hf_cosp, "albisccp", &
-                     "Mean Cloud Albedo as Calculated by the ISCCP Simulator", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstohf) 
-          endif
-          if (cfg%Lmeantbisccp) then
-            CALL histdef(nid_hf_cosp, "meantbisccp", &
-             " Mean all-sky 10.5 micron brightness temperature as calculated by the ISCCP Simulator","K", &
-             iim, jj_nb,nhori,1,1,1,-99,32, &
-             "ave(X)", zout,zstohf)
-          endif
-          if (cfg%Lmeantbclrisccp) then
-           CALL histdef(nid_hf_cosp, "meantbclrisccp", &
-            "Mean clear-sky 10.5 micron brightness temperature as calculated by the ISCCP Simulator","K", &
-             iim, jj_nb,nhori,1,1,1,-99,32, &
-             "ave(X)", zout,zstohf) 
-          endif
-        endif ! Isccp
-
-
-        CALL histend(nid_hf_cosp)
-!$OMP END MASTER
-!$OMP BARRIER
Index: LMDZ5/trunk/libf/cosp/ini_histmthCOSP.h
===================================================================
--- LMDZ5/trunk/libf/cosp/ini_histmthCOSP.h	(revision 1925)
+++ 	(revision )
@@ -1,204 +1,0 @@
-! Abderrahmane Idelkadi Septebmre 2009
-! Sorties journalieres de COSP 
-! Pour l'instant sorties Lidar et ISCCP
-!
-! sorties par jour
-!
-!$OMP MASTER
-        zstomth = ecrit_mth
-        zout = freq_COSP
-!
-!       PRINT*, 'La frequence de sortie hf3d est de ', ecrit_hf
-!
-
-        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,nvertmcosp)
-
-        CALL histvert(nid_mth_cosp,"sza","solar_zenith_angle","degrees",PARASOL_NREFL,PARASOL_SZA,nvertp)
-
-        CALL histvert(nid_mth_cosp,"pressure2","pressure","mb",7,ISCCP_PC,nvertisccp)
-
-        CALL histvert(nid_mth_cosp,"column","column","count",Ncolumns,column_ax(1:Ncolumns),nvertcol)
-
-! Sorties LIDAR
-       if (cfg%Llidar_sim) then
-         if (cfg%Lcllcalipso) then
-         CALL histdef(nid_mth_cosp, "cllcalipso", &
-                     "Lidar Low-level Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstomth)
-         endif
-         if (cfg%Lclhcalipso) then
-         CALL histdef(nid_mth_cosp, "clhcalipso", &
-                     "Lidar High-level Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstomth)
-         endif
-         if (cfg%Lclmcalipso) then
-         CALL histdef(nid_mth_cosp, "clmcalipso", &
-                     "Lidar Mid-level Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstomth)
-         endif
-         if (cfg%Lcltcalipso) then
-         CALL histdef(nid_mth_cosp, "cltcalipso", &
-                     "Lidar Total Cloud Fraction", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstomth)
-         endif
-         if (cfg%Lclcalipso) then
-         CALL histdef(nid_mth_cosp, "clcalipso", &
-                     "Lidar Cloud Fraction (532 nm)", "1", &
-                     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,nvertmcosp, 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,nvertmcosp, 32, &
-!                     "ave(X)", zout,zstomth)
-         endif
-           if (cfg%Lcfad_lidarsr532) then
-              do ii=1,SR_BINS
-               CALL histdef(nid_mth_cosp, "cfad_lidarsr532_"//chcol(ii), &
-                           "Lidar Scattering Ratio CFAD (532 nm)","1", &
-                           iim,jj_nb,nhori, Nlevout,1,Nlevout,nvert, 32, &
-                           "ave(X)", zout,zstomth)   
-              enddo
-           endif
-           if (cfg%Lparasol_refl) then
-            CALL histdef(nid_mth_cosp, "parasol_refl", &
-                        "PARASOL-like mono-directional reflectance","1", &
-                        iim,jj_nb,nhori, PARASOL_NREFL,1, PARASOL_NREFL, nvertp,32, &
-                        "ave(X)", zout,zstomth)   
-           endif
-           if (cfg%Latb532) then
-            do ii=1,Ncolumns
-             CALL histdef(nid_mth_cosp, "atb532_"//chcol(ii), &
-                         "Lidar Attenuated Total Backscatter (532 nm)","1", &
-                         iim,jj_nb,nhori, Nlevlmdz,1,Nlevlmdz,nvertmcosp, 32, &
-                         "ave(X)", zout,zstomth)
-            enddo
-           endif
-           if (cfg%Lbeta_mol532) then
-            CALL histdef(nid_mth_cosp, "beta_mol532", &
-                        "Lidar Molecular Backscatter (532 nm)","m-1 sr-1", &
-                        iim,jj_nb,nhori, Nlevlmdz,1,Nlevlmdz,nvertmcosp, 32, &
-                         "ave(X)", zout,zstomth)
-           endif
-        endif ! Lidar
-
-! Sorties RADAR
-!Attention A FAIRE
-!        if (cfg%Lradar_sim) then
-!         print*,'Ecriture sorties Radar'
-!          if (cfg%tttttttttttt) then
-!              print*,'Ecriture de cfad_dbze94.nc '
-!              A revoir l axe vertical Nlvgrid
-!               do ii=1,DBZE_BINS
-!                   dbze_ax(ii) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*(ii - 0.5)
-!               enddo
-!               call write_netcdf4d('cfad_dbze94.nc',use_vgrid,nlon,nlat,Nlevout,DBZE_BINS, &
-!                                   x,y,out_levs,dbze_ax,i,ndays,time,stradar%cfad_ze)
-!          endif
-!          if (cfg%Lclcalipso2) then
-!               call write_netcdf3d('clcalipso2.nc',use_vgrid,'clcalipso2', &
-!                              nlon,nlat,Nlevout,x,y,out_levs,i,ndays,time,stradar%lidar_only_freq_cloud)
-!          endif
-!          if (cfg%Ldbze94) then
-!             do ii=1,Ncolumns
-!                xcol(ii)=float(i)
-!             enddo
-!             call write_netcdf4d('dbze94.nc',use_vgrid,nlon,nlat,Nlevout,Ncolumns, &
-!                                 x,y,out_levs,xcol,i,ndays,time,sgradar%Ze_tot)
-!          endif
-!          if (cfg%Lcltlidarradar) then
-!             call write_netcdf2d('cltlidarradar.nc','cltlidarradar', &
-!                                 nlon,nlat,x,y,i,ndays,time,stradar%radar_lidar_tcc)
-!          endif
-!        endif  ! Radar
-
-! Sorties MISR
-!Attention A FAIRE
-!        if (cfg%Lmisr_sim) then
-!         print*,'Ecriture sorties Misr'
-!            call write_netcdf4d('clMISR.nc',use_vgrid,nlon,nlat,MISR_N_CTH,7, &
-!                                x,y,MISR_CTH,ISCCP_TAU,i,ndays,time,misr%fq_MISR)
-!        endif
-
-! Sorties ISCCP
-        if (cfg%Lisccp_sim) then
-         if (cfg%Lclisccp2) then
-            do ii=1,7
-             CALL histdef(nid_mth_cosp, "clisccp2_"//chcol(ii), &
-                         "Cloud Fraction as Calculated by the ISCCP Simulator","1", &
-                         iim,jj_nb,nhori,7,1,7,nvertisccp, 32, &
-                         "ave(X)", zout,zstomth)
-            enddo
-          endif
-          if (cfg%Lboxtauisccp) then
-            CALL histdef(nid_mth_cosp, "boxtauisccp", &
-                         "Optical Depth in Each Column as Calculated by the ISCCP Simulator","1", &
-                         iim,jj_nb,nhori,Ncolumns,1,Ncolumns,nvertcol, 32, &
-                         "ave(X)", zout,zstomth)
-          endif
-          if (cfg%Lboxptopisccp) then
-            CALL histdef(nid_mth_cosp, "boxptopisccp", &
-                         "Cloud Top Pressure in Each Column as Calculated by the ISCCP Simulator","Pa", &
-                         iim,jj_nb,nhori,Ncolumns,1,Ncolumns,nvertcol, 32, &
-                         "ave(X)", zout,zstomth)
-          endif
-          if (cfg%Ltclisccp) then
-           CALL histdef(nid_mth_cosp, "tclisccp", &
-                     "Total Cloud Fraction as Calculated by the ISCCP Simulator", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstomth)
-          endif
-          if (cfg%Lctpisccp) then
-            CALL histdef(nid_mth_cosp, "ctpisccp", &
-                     "Mean Cloud Top Pressure as Calculated by the ISCCP Simulator", "Pa", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstomth)
-          endif
-          if (cfg%Ltauisccp) then
-           CALL histdef(nid_mth_cosp, "tauisccp", &
-                     "Optical Depth as Calculated by the ISCCP Simulator", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstomth)
-          endif
-          if (cfg%Lalbisccp) then
-           CALL histdef(nid_mth_cosp, "albisccp", &
-                     "Mean Cloud Albedo as Calculated by the ISCCP Simulator", "1", &
-                     iim, jj_nb,nhori,1,1,1,-99,32, &
-                     "ave(X)", zout,zstomth) 
-          endif
-          if (cfg%Lmeantbisccp) then
-            CALL histdef(nid_mth_cosp, "meantbisccp", &
-             " Mean all-sky 10.5 micron brightness temperature as calculated by the ISCCP Simulator","K", &
-             iim, jj_nb,nhori,1,1,1,-99,32, &
-             "ave(X)", zout,zstomth)
-          endif
-          if (cfg%Lmeantbclrisccp) then
-           CALL histdef(nid_mth_cosp, "meantbclrisccp", &
-            "Mean clear-sky 10.5 micron brightness temperature as calculated by the ISCCP Simulator","K", &
-             iim, jj_nb,nhori,1,1,1,-99,32, &
-             "ave(X)", zout,zstomth) 
-          endif
-        endif ! Isccp
-
-
-        CALL histend(nid_mth_cosp)
-!$OMP END MASTER
-!$OMP BARRIER
Index: LMDZ5/trunk/libf/cosp/write_histdayCOSP.h
===================================================================
--- LMDZ5/trunk/libf/cosp/write_histdayCOSP.h	(revision 1925)
+++ 	(revision )
@@ -1,139 +1,0 @@
-! Ecriture des fichiers de sorties COSP
-! Sorties journalierres
-! Abderrahmane Idelkadi Septembre 2009
-
-      IF (MOD(itap,NINT(freq_COSP/dtime)).EQ.0) THEN
-
-       itau_wcosp = itau_phy + itap
-
-! Sorties LIDAR
-       if (cfg%Llidar_sim) then
-         if (cfg%Lcllcalipso) then
-          CALL histwrite_phy(nid_day_cosp,lCOSP,"cllcalipso", &
-     itau_wcosp,stlidar%cldlayer(:,1))
-         endif
-         if (cfg%Lclhcalipso) then
-          CALL histwrite_phy(nid_day_cosp,lCOSP,"clhcalipso", &
-     itau_wcosp,stlidar%cldlayer(:,3))
-         endif
-         if (cfg%Lclmcalipso) then
-          CALL histwrite_phy(nid_day_cosp,lCOSP,"clmcalipso", &
-     itau_wcosp,stlidar%cldlayer(:,2))
-         endif
-         if (cfg%Lcltcalipso) then
-          CALL histwrite_phy(nid_day_cosp,lCOSP,"cltcalipso", &
-     itau_wcosp,stlidar%cldlayer(:,4)) 
-         endif
-         if (cfg%Lclcalipso) then
-          CALL histwrite_phy(nid_day_cosp,lCOSP,"clcalipso", &
-     itau_wcosp,stlidar%lidarcld)
-         endif
-         if (cfg%Lcfad_lidarsr532) then
-           do ii=1,SR_BINS
-            CALL histwrite_phy(nid_day_cosp,lCOSP, &
-     "cfad_lidarsr532_"//chcol(ii),itau_wcosp,stlidar%cfad_sr(:,ii,:))
-           enddo
-         endif
-         if (cfg%Lparasol_refl) then
-           CALL histwrite_phy(nid_day_cosp,lCOSP,"parasol_refl", &
-     itau_wcosp,stlidar%parasolrefl)
-         endif
-         if (cfg%Latb532) then
-           do ii=1,Ncolumns
-            CALL histwrite_phy(nid_day_cosp,lCOSP,"atb532_"//chcol(ii), &
-     itau_wcosp,sglidar%beta_tot(:,ii,:))
-           enddo
-         endif
-         if (cfg%Lbeta_mol532) then
-           CALL histwrite_phy(nid_day_cosp,lCOSP,"beta_mol532", &
-     itau_wcosp,sglidar%beta_mol)
-         endif
-        endif ! Lidar
-
-! Sorties RADAR
-!Attention A FAIRE
-!        if (cfg%Lradar_sim) then
-!         print*,'Ecriture sorties Radar'
-!          if (cfg%Lcfad_dbze94) then
-!              print*,'Ecriture de cfad_dbze94.nc '
-!              A revoir l axe vertical Nlvgrid
-!               do ii=1,DBZE_BINS
-!                   dbze_ax(ii) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*(ii - 0.5)
-!               enddo
-!               call write_netcdf4d('cfad_dbze94.nc',use_vgrid,nlon,nlat,Nlevout,DBZE_BINS, &
-!                                   x,y,out_levs,dbze_ax,i,ndays,time,stradar%cfad_ze)
-!          endif
-!          if (cfg%Lclcalipso2) then
-!               call write_netcdf3d('clcalipso2.nc',use_vgrid,'clcalipso2', &
-!                              nlon,nlat,Nlevout,x,y,out_levs,i,ndays,time,stradar%lidar_only_freq_cloud)
-!          endif
-!          if (cfg%Ldbze94) then
-!             do ii=1,Ncolumns
-!                xcol(ii)=float(i)
-!             enddo
-!             call write_netcdf4d('dbze94.nc',use_vgrid,nlon,nlat,Nlevout,Ncolumns, &
-!                                 x,y,out_levs,xcol,i,ndays,time,sgradar%Ze_tot)
-!          endif
-!          if (cfg%Lcltlidarradar) then
-!             call write_netcdf2d('cltlidarradar.nc','cltlidarradar', &
-!                                 nlon,nlat,x,y,i,ndays,time,stradar%radar_lidar_tcc)
-!          endif
-!        endif  ! Radar
-
-! Sorties MISR
-!Attention A FAIRE
-!        if (cfg%Lmisr_sim) then
-!         print*,'Ecriture sorties Misr'
-!            call write_netcdf4d('clMISR.nc',use_vgrid,nlon,nlat,MISR_N_CTH,7, &
-!                                x,y,MISR_CTH,ISCCP_TAU,i,ndays,time,misr%fq_MISR)
-!        endif
-
-! Sorties ISCCP
-        if (cfg%Lisccp_sim) then
-          if (cfg%Lclisccp2) then
-            do ii=1,7
-              CALL histwrite_phy(nid_day_cosp,lCOSP, &
-     "clisccp2_"//chcol(ii),itau_wcosp,isccp%fq_isccp(:,ii,:))
-            enddo
-          endif
-          if (cfg%Lboxtauisccp) then
-             CALL histwrite_phy(nid_day_cosp,lCOSP,"boxtauisccp", &
-     itau_wcosp,isccp%boxtau)
-          endif
-          if (cfg%Lboxptopisccp) then
-             CALL histwrite_phy(nid_day_cosp,lCOSP,"boxptopisccp", &
-     itau_wcosp,isccp%boxptop)
-          endif
-          if (cfg%Ltclisccp) then
-             CALL histwrite_phy(nid_day_cosp,lCOSP,"tclisccp", &
-     itau_wcosp,isccp%totalcldarea)
-          endif
-          if (cfg%Lctpisccp) then
-             CALL histwrite_phy(nid_day_cosp,lCOSP,"ctpisccp", &
-     itau_wcosp,isccp%meanptop)
-          endif
-          if (cfg%Ltauisccp) then
-             CALL histwrite_phy(nid_day_cosp,lCOSP,"tauisccp", &
-     itau_wcosp,isccp%meantaucld)
-          endif
-          if (cfg%Lalbisccp) then
-             CALL histwrite_phy(nid_day_cosp,lCOSP,"albisccp", &
-     itau_wcosp,isccp%meanalbedocld)
-          endif
-          if (cfg%Lmeantbisccp) then
-             CALL histwrite_phy(nid_day_cosp,lCOSP,"meantbisccp", &
-     itau_wcosp,isccp%meantb)
-          endif
-          if (cfg%Lmeantbclrisccp) then
-             CALL histwrite_phy(nid_day_cosp,lCOSP,"meantbclrisccp", &
-     itau_wcosp,isccp%meantbclr)
-          endif
-        endif ! Isccp
-
-!       if (ok_sync) then
-!$OMP MASTER
-        call histsync(nid_day_cosp)
-!$OMP END MASTER      
-!       endif
-
-      ENDIF ! if freq_COSP
Index: LMDZ5/trunk/libf/cosp/write_histhfCOSP.h
===================================================================
--- LMDZ5/trunk/libf/cosp/write_histhfCOSP.h	(revision 1925)
+++ 	(revision )
@@ -1,140 +1,0 @@
-! Ecriture des fichiers de sorties COSP
-! Sorties journalierres
-! Abderrahmane Idelkadi Septembre 2009
-
-      IF (MOD(itap,NINT(freq_COSP/dtime)).EQ.0) THEN
-
-       itau_wcosp = itau_phy + itap
-
-! Sorties LIDAR
-       if (cfg%Llidar_sim) then
-         if (cfg%Lcllcalipso) then
-          CALL histwrite_phy(nid_hf_cosp,lCOSP,"cllcalipso", &
-     itau_wcosp,stlidar%cldlayer(:,1))
-         endif
-         if (cfg%Lclhcalipso) then
-          CALL histwrite_phy(nid_hf_cosp,lCOSP,"clhcalipso", &
-     itau_wcosp,stlidar%cldlayer(:,3))
-         endif
-         if (cfg%Lclmcalipso) then
-          CALL histwrite_phy(nid_hf_cosp,lCOSP,"clmcalipso", &
-     itau_wcosp,stlidar%cldlayer(:,2))
-         endif
-         if (cfg%Lcltcalipso) then
-          CALL histwrite_phy(nid_hf_cosp,lCOSP,"cltcalipso", &
-     itau_wcosp,stlidar%cldlayer(:,4)) 
-         endif
-         if (cfg%Lclcalipso) then
-          CALL histwrite_phy(nid_hf_cosp,lCOSP,"clcalipso", &
-     itau_wcosp,stlidar%lidarcld)
-         endif
-         if (cfg%Lcfad_lidarsr532) then
-           do ii=1,SR_BINS
-            CALL histwrite_phy(nid_hf_cosp,lCOSP, &
-     "cfad_lidarsr532_"//chcol(ii),itau_wcosp,stlidar%cfad_sr(:,ii,:))
-           enddo
-         endif
-         if (cfg%Lparasol_refl) then
-           CALL histwrite_phy(nid_hf_cosp,lCOSP,"parasol_refl", &
-     itau_wcosp,stlidar%parasolrefl)
-         endif
-         if (cfg%Latb532) then
-           do ii=1,Ncolumns
-            CALL histwrite_phy(nid_hf_cosp,lCOSP,"atb532_"//chcol(ii), &
-     itau_wcosp,sglidar%beta_tot(:,ii,:))
-           enddo
-         endif
-         if (cfg%Lbeta_mol532) then
-           CALL histwrite_phy(nid_hf_cosp,lCOSP,"beta_mol532", &
-     itau_wcosp,sglidar%beta_mol)
-         endif
-        endif ! Lidar
-
-! Sorties RADAR
-!Attention A FAIRE
-!        if (cfg%Lradar_sim) then
-!         print*,'Ecriture sorties Radar'
-!          if (cfg%Lcfad_dbze94) then
-!              print*,'Ecriture de cfad_dbze94.nc '
-!              A revoir l axe vertical Nlvgrid
-!               do ii=1,DBZE_BINS
-!                   dbze_ax(ii) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*(ii - 0.5)
-!               enddo
-!               call write_netcdf4d('cfad_dbze94.nc',use_vgrid,nlon,nlat,Nlevout,DBZE_BINS, &
-!                                   x,y,out_levs,dbze_ax,i,ndays,time,stradar%cfad_ze)
-!          endif
-!          if (cfg%Lclcalipso2) then
-!               call write_netcdf3d('clcalipso2.nc',use_vgrid,'clcalipso2', &
-!                              nlon,nlat,Nlevout,x,y,out_levs,i,ndays,time,stradar%lidar_only_freq_cloud)
-!          endif
-!          if (cfg%Ldbze94) then
-!             do ii=1,Ncolumns
-!                xcol(ii)=float(i)
-!             enddo
-!             call write_netcdf4d('dbze94.nc',use_vgrid,nlon,nlat,Nlevout,Ncolumns, &
-!                                 x,y,out_levs,xcol,i,ndays,time,sgradar%Ze_tot)
-!          endif
-!          if (cfg%Lcltlidarradar) then
-!             call write_netcdf2d('cltlidarradar.nc','cltlidarradar', &
-!                                 nlon,nlat,x,y,i,ndays,time,stradar%radar_lidar_tcc)
-!          endif
-!        endif  ! Radar
-
-! Sorties MISR
-!Attention A FAIRE
-!        if (cfg%Lmisr_sim) then
-!         print*,'Ecriture sorties Misr'
-!            call write_netcdf4d('clMISR.nc',use_vgrid,nlon,nlat,MISR_N_CTH,7, &
-!                                x,y,MISR_CTH,ISCCP_TAU,i,ndays,time,misr%fq_MISR)
-!        endif
-
-! Sorties ISCCP
-        if (cfg%Lisccp_sim) then
-          if (cfg%Lclisccp2) then
-            do ii=1,7
-              CALL histwrite_phy(nid_hf_cosp,lCOSP, &
-     "clisccp2_"//chcol(ii),itau_wcosp,isccp%fq_isccp(:,ii,:))
-            enddo
-          endif
-          if (cfg%Lboxtauisccp) then
-             CALL histwrite_phy(nid_hf_cosp,lCOSP,"boxtauisccp", &
-     itau_wcosp,isccp%boxtau)
-          endif
-          if (cfg%Lboxptopisccp) then
-             CALL histwrite_phy(nid_hf_cosp,lCOSP,"boxptopisccp", &
-     itau_wcosp,isccp%boxptop)
-          endif
-          if (cfg%Ltclisccp) then
-             CALL histwrite_phy(nid_hf_cosp,lCOSP,"tclisccp", &
-     itau_wcosp,isccp%totalcldarea)
-          endif
-          if (cfg%Lctpisccp) then
-             CALL histwrite_phy(nid_hf_cosp,lCOSP,"ctpisccp", &
-     itau_wcosp,isccp%meanptop)
-
-          endif
-          if (cfg%Ltauisccp) then
-             CALL histwrite_phy(nid_hf_cosp,lCOSP,"tauisccp", &
-     itau_wcosp,isccp%meantaucld)
-          endif
-          if (cfg%Lalbisccp) then
-             CALL histwrite_phy(nid_hf_cosp,lCOSP,"albisccp", &
-     itau_wcosp,isccp%meanalbedocld)
-          endif
-          if (cfg%Lmeantbisccp) then
-             CALL histwrite_phy(nid_hf_cosp,lCOSP,"meantbisccp", &
-     itau_wcosp,isccp%meantb)
-          endif
-          if (cfg%Lmeantbclrisccp) then
-             CALL histwrite_phy(nid_hf_cosp,lCOSP,"meantbclrisccp", &
-     itau_wcosp,isccp%meantbclr)
-          endif
-        endif ! Isccp
-
-!       if (ok_sync) then
-!$OMP MASTER
-        call histsync(nid_hf_cosp)
-!$OMP END MASTER      
-!       endif
-
-      ENDIF ! if freq_COSP
Index: LMDZ5/trunk/libf/cosp/write_histmthCOSP.h
===================================================================
--- LMDZ5/trunk/libf/cosp/write_histmthCOSP.h	(revision 1925)
+++ 	(revision )
@@ -1,139 +1,0 @@
-! Ecriture des fichiers de sorties COSP
-! Sorties journalierres
-! Abderrahmane Idelkadi Septembre 2009
-
-      IF (MOD(itap,NINT(freq_COSP/dtime)).EQ.0) THEN
-
-       itau_wcosp = itau_phy + itap
-
-! Sorties LIDAR
-       if (cfg%Llidar_sim) then
-         if (cfg%Lcllcalipso) then
-          CALL histwrite_phy(nid_mth_cosp,lCOSP,"cllcalipso",itau_wcosp, &
-     stlidar%cldlayer(:,1))
-         endif
-         if (cfg%Lclhcalipso) then
-          CALL histwrite_phy(nid_mth_cosp,lCOSP,"clhcalipso",itau_wcosp, &
-     stlidar%cldlayer(:,3))
-         endif
-         if (cfg%Lclmcalipso) then
-          CALL histwrite_phy(nid_mth_cosp,lCOSP,"clmcalipso",itau_wcosp, &
-     stlidar%cldlayer(:,2))
-         endif
-         if (cfg%Lcltcalipso) then
-          CALL histwrite_phy(nid_mth_cosp,lCOSP,"cltcalipso",itau_wcosp, &
-     stlidar%cldlayer(:,4)) 
-         endif
-         if (cfg%Lclcalipso) then
-          CALL histwrite_phy(nid_mth_cosp,lCOSP,"clcalipso",itau_wcosp, &
-     stlidar%lidarcld)
-         endif
-         if (cfg%Lcfad_lidarsr532) then
-           do ii=1,SR_BINS
-            CALL histwrite_phy(nid_mth_cosp,lCOSP, &
-     "cfad_lidarsr532_"//chcol(ii),itau_wcosp,stlidar%cfad_sr(:,ii,:))
-           enddo
-         endif
-         if (cfg%Lparasol_refl) then
-           CALL histwrite_phy(nid_mth_cosp,lCOSP,"parasol_refl", &
-     itau_wcosp,stlidar%parasolrefl)
-         endif
-         if (cfg%Latb532) then
-           do ii=1,Ncolumns
-            CALL histwrite_phy(nid_mth_cosp,lCOSP, &
-     "atb532_"//chcol(ii),itau_wcosp,sglidar%beta_tot(:,ii,:))
-           enddo
-         endif
-         if (cfg%Lbeta_mol532) then
-           CALL histwrite_phy(nid_mth_cosp,lCOSP,"beta_mol532", &
-     itau_wcosp,sglidar%beta_mol)
-         endif
-        endif ! Lidar
-
-! Sorties RADAR
-!Attention A FAIRE
-!        if (cfg%Lradar_sim) then
-!         print*,'Ecriture sorties Radar'
-!          if (cfg%Lcfad_dbze94) then
-!              print*,'Ecriture de cfad_dbze94.nc '
-!              A revoir l axe vertical Nlvgrid
-!               do ii=1,DBZE_BINS
-!                   dbze_ax(ii) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*(ii - 0.5)
-!               enddo
-!               call write_netcdf4d('cfad_dbze94.nc',use_vgrid,nlon,nlat,Nlevout,DBZE_BINS, &
-!                                   x,y,out_levs,dbze_ax,i,ndays,time,stradar%cfad_ze)
-!          endif
-!          if (cfg%Lclcalipso2) then
-!               call write_netcdf3d('clcalipso2.nc',use_vgrid,'clcalipso2', &
-!                              nlon,nlat,Nlevout,x,y,out_levs,i,ndays,time,stradar%lidar_only_freq_cloud)
-!          endif
-!          if (cfg%Ldbze94) then
-!             do ii=1,Ncolumns
-!                xcol(ii)=float(i)
-!             enddo
-!             call write_netcdf4d('dbze94.nc',use_vgrid,nlon,nlat,Nlevout,Ncolumns, &
-!                                 x,y,out_levs,xcol,i,ndays,time,sgradar%Ze_tot)
-!          endif
-!          if (cfg%Lcltlidarradar) then
-!             call write_netcdf2d('cltlidarradar.nc','cltlidarradar', &
-!                                 nlon,nlat,x,y,i,ndays,time,stradar%radar_lidar_tcc)
-!          endif
-!        endif  ! Radar
-
-! Sorties MISR
-!Attention A FAIRE
-!        if (cfg%Lmisr_sim) then
-!         print*,'Ecriture sorties Misr'
-!            call write_netcdf4d('clMISR.nc',use_vgrid,nlon,nlat,MISR_N_CTH,7, &
-!                                x,y,MISR_CTH,ISCCP_TAU,i,ndays,time,misr%fq_MISR)
-!        endif
-
-! Sorties ISCCP
-        if (cfg%Lisccp_sim) then
-          if (cfg%Lclisccp2) then
-            do ii=1,7
-              CALL histwrite_phy(nid_mth_cosp,lCOSP,"clisccp2_"//chcol(ii), &
-     itau_wcosp,isccp%fq_isccp(:,ii,:))
-            enddo
-          endif
-          if (cfg%Lboxtauisccp) then
-             CALL histwrite_phy(nid_mth_cosp,lCOSP,"boxtauisccp", &
-     itau_wcosp,isccp%boxtau)
-          endif
-          if (cfg%Lboxptopisccp) then
-             CALL histwrite_phy(nid_mth_cosp,lCOSP,"boxptopisccp", &
-     itau_wcosp,isccp%boxptop)
-          endif
-          if (cfg%Ltclisccp) then
-             CALL histwrite_phy(nid_mth_cosp,lCOSP,"tclisccp", &
-     itau_wcosp,isccp%totalcldarea)
-          endif
-          if (cfg%Lctpisccp) then
-             CALL histwrite_phy(nid_mth_cosp,lCOSP,"ctpisccp", &
-     itau_wcosp,isccp%meanptop)
-          endif
-          if (cfg%Ltauisccp) then
-             CALL histwrite_phy(nid_mth_cosp,lCOSP,"tauisccp", &
-     itau_wcosp,isccp%meantaucld)
-          endif
-          if (cfg%Lalbisccp) then
-             CALL histwrite_phy(nid_mth_cosp,lCOSP,"albisccp", &
-     itau_wcosp,isccp%meanalbedocld)
-          endif
-          if (cfg%Lmeantbisccp) then
-             CALL histwrite_phy(nid_mth_cosp,lCOSP,"meantbisccp", &
-     itau_wcosp,isccp%meantb)
-          endif
-          if (cfg%Lmeantbclrisccp) then
-             CALL histwrite_phy(nid_mth_cosp,lCOSP,"meantbclrisccp", &
-     itau_wcosp,isccp%meantbclr)
-          endif
-        endif ! Isccp
-
-!       if (ok_sync) then
-!$OMP MASTER
-        call histsync(nid_mth_cosp)
-!$OMP END MASTER      
-!       endif
-
-      ENDIF ! if freq_COSP
