Index: LMDZ4/branches/V3_test/libf/phylmd/radlwsw.F
===================================================================
--- LMDZ4/branches/V3_test/libf/phylmd/radlwsw.F	(revision 703)
+++ LMDZ4/branches/V3_test/libf/phylmd/radlwsw.F	(revision 704)
@@ -16,4 +16,5 @@
      .                  cldtaupi, topswai, solswai)
 c      
+      USE dimphy
       IMPLICIT none
 c======================================================================
@@ -69,7 +70,7 @@
       
 c======================================================================
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "YOETHF.h"
 c
@@ -403,10 +404,10 @@
      S              PTOPSWAD,PSOLSWAD,PTOPSWAI,PSOLSWAI,
      J              ok_ade, ok_aie )
-      
+      USE dimphy      
       IMPLICIT none
 
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "YOMCST.h"
 C
@@ -509,4 +510,7 @@
       DATA itapsw /0/
       DATA appel1er /.TRUE./
+      SAVE itapsw,appel1er
+c$OMP THREADPRIVATE(appel1er)
+c$OMP THREADPRIVATE(itapsw)
 cjq-Introduced for aerosol forcings
       real*8 flag_aer
@@ -522,17 +526,33 @@
       REAL*8 PSOLSWAI(KDLON)     ! SHORTWAVE FLUX AT SURFACE(+AEROSOL IND)
 cjq - Fluxes including aerosol effects
-      REAL*8 ZFSUPAD(KDLON,KFLEV+1)
-      REAL*8 ZFSDNAD(KDLON,KFLEV+1)
-      REAL*8 ZFSUPAI(KDLON,KFLEV+1)
-      REAL*8 ZFSDNAI(KDLON,KFLEV+1)
+      REAL*8,allocatable,save :: ZFSUPAD(:,:)
+c$OMP THREADPRIVATE(ZFSUPAD)
+      REAL*8,allocatable,save :: ZFSDNAD(:,:)
+c$OMP THREADPRIVATE(ZFSDNAD)
+      REAL*8,allocatable,save :: ZFSUPAI(:,:)
+c$OMP THREADPRIVATE(ZFSUPAI)
+      REAL*8,allocatable,save :: ZFSDNAI(:,:)
+c$OMP THREADPRIVATE(ZFSDNAI)
       logical initialized
-      SAVE ZFSUPAD, ZFSDNAD, ZFSUPAI, ZFSDNAI ! aerosol fluxes
+cym      SAVE ZFSUPAD, ZFSDNAD, ZFSUPAI, ZFSDNAI ! aerosol fluxes
 !rv
       save flag_aer
+c$OMP THREADPRIVATE(flag_aer)
       data initialized/.false./
+      save initialized
+c$OMP THREADPRIVATE(initialized)
 cjq-end
       if(.not.initialized) then
         flag_aer=0.
         initialized=.TRUE.
+        allocate(ZFSUPAD(KDLON,KFLEV+1))
+        allocate(ZFSDNAD(KDLON,KFLEV+1))
+        allocate(ZFSUPAI(KDLON,KFLEV+1))
+        allocate(ZFSDNAI(KDLON,KFLEV+1))
+	ZFSUPAD(:,:)=0.
+        ZFSDNAD(:,:)=0.
+        ZFSUPAI(:,:)=0.
+        ZFSDNAI(:,:)=0.
+	
       endif
 !rv
@@ -710,8 +730,9 @@
      S                PTAVE,PWV,PAKI,PCLD,PCLEAR,PDSIG,PFACT,
      S                PRMU,PSEC,PUD)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "radepsi.h"
 #include "radopt.h"
@@ -761,10 +782,14 @@
       REAL*8 ZPDH2O,ZPDUMG
       SAVE ZPDH2O,ZPDUMG
+c$OMP THREADPRIVATE(ZPDH2O,ZPDUMG)
       REAL*8 ZPRH2O,ZPRUMG
       SAVE ZPRH2O,ZPRUMG
+c$OMP THREADPRIVATE(ZPRH2O,ZPRUMG)
       REAL*8 RTDH2O,RTDUMG
       SAVE RTDH2O,RTDUMG
+c$OMP THREADPRIVATE(RTDH2O,RTDUMG)
       REAL*8 RTH2O ,RTUMG
       SAVE RTH2O ,RTUMG
+c$OMP THREADPRIVATE(RTH2O ,RTUMG)
       DATA ZPDH2O,ZPDUMG / 0.8   , 0.75 /
       DATA ZPRH2O,ZPRUMG / 30000., 30000. /
@@ -900,8 +925,9 @@
      S  ,  PDSIG , POMEGA, POZ  , PRMU , PSEC , PTAU  , PUD  
      S  ,  PFD   , PFU)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 C
 C     ------------------------------------------------------------------
@@ -991,6 +1017,8 @@
       REAL*8 RSUN(2)
       SAVE RSUN
+c$OMP THREADPRIVATE(RSUN)
       REAL*8 RRAY(2,6)
       SAVE RRAY
+c$OMP THREADPRIVATE(RRAY)
       DATA RSUN(1) / 0.441676 /
       DATA RSUN(2) / 0.558324 /
@@ -1140,8 +1168,9 @@
      S  ,  PUD   ,PWV , PQS
      S  ,  PFDOWN,PFUP                                            )
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "radepsi.h"
 C
@@ -1264,6 +1293,8 @@
       REAL*8 RSUN(2)
       SAVE RSUN
+c$OMP THREADPRIVATE(RSUN)
       REAL*8 RRAY(2,6)
       SAVE RRAY
+c$OMP THREADPRIVATE(RRAY)
       DATA RSUN(1) / 0.441676 /
       DATA RSUN(2) / 0.558324 /
@@ -1686,8 +1717,9 @@
      S  , PCGAZ , PPIZAZ, PRAY1 , PRAY2 , PREFZ , PRJ  
      S  , PRK   , PRMU0 , PTAUAZ, PTRA1 , PTRA2                   )
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "radepsi.h"
 #include "radopt.h"
@@ -1759,4 +1791,5 @@
       REAL*8 TAUA(2,5), RPIZA(2,5), RCGA(2,5)
       SAVE TAUA, RPIZA, RCGA
+c$OMP THREADPRIVATE(TAUA, RPIZA, RCGA)
       DATA ((TAUA(IN,JA),JA=1,5),IN=1,2) /
      S .730719, .912819, .725059, .745405, .682188 ,
@@ -2046,8 +2079,9 @@
      S  , PCGAZ , PPIZAZ, PRAY1, PRAY2, PREFZ , PRJ  , PRK , PRMUE
      S  , PTAUAZ, PTRA1 , PTRA2 )
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "radepsi.h"
 #include "radopt.h"
@@ -2402,8 +2436,9 @@
       SUBROUTINE SWDE (PGG,PREF,PRMUZ,PTO1,PW,
      S                 PRE1,PRE2,PTR1,PTR2)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 C
 C     ------------------------------------------------------------------
@@ -2533,8 +2568,9 @@
       END
       SUBROUTINE SWTT (KNU,KA,PU,PTR)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 C
 C-----------------------------------------------------------------------
@@ -2583,4 +2619,5 @@
       REAL*8 APAD(2,3,7), BPAD(2,3,7), D(2,3)
       SAVE APAD, BPAD, D
+c$OMP THREADPRIVATE(APAD, BPAD, D)
       DATA ((APAD(1,I,J),I=1,3),J=1,7) /
      S 0.912418292E+05, 0.000000000E-00, 0.925887084E-04,
@@ -2649,8 +2686,9 @@
       END
       SUBROUTINE SWTT1(KNU,KABS,KIND, PU, PTR)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 C
 C-----------------------------------------------------------------------
@@ -2701,4 +2739,5 @@
       REAL*8 APAD(2,3,7), BPAD(2,3,7), D(2,3)
       SAVE APAD, BPAD, D
+c$OMP THREADPRIVATE(APAD, BPAD, D)
       DATA ((APAD(1,I,J),I=1,3),J=1,7) /
      S 0.912418292E+05, 0.000000000E-00, 0.925887084E-04,
@@ -2778,9 +2817,12 @@
      .              PTOPLW,PSOLLW,PTOPLW0,PSOLLW0,
      .              psollwdown,
+cIM  .              psollwdown,psollwdownclr,
+cIM  .              ptoplwdown,ptoplwdownclr)
      .              plwup, plwdn, plwup0, plwdn0)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "raddimlw.h"
 #include "YOMCST.h"
@@ -2844,4 +2886,8 @@
 c Rajout LF
       real*8 psollwdown(kdlon)    ! LONGWAVE downwards flux at surface
+c Rajout IM
+cIM   real*8 psollwdownclr(kdlon) ! LONGWAVE CS downwards flux at surface
+cIM   real*8 ptoplwdown(kdlon)    ! LONGWAVE downwards flux at T.O.A.
+cIM   real*8 ptoplwdownclr(kdlon) ! LONGWAVE CS downwards flux at T.O.A.
 cIM
       REAL*8 plwup(KDLON,KFLEV+1)  ! LW up total sky
@@ -2853,11 +2899,18 @@
       REAL*8 ZOZ(KDLON,KFLEV)
 c
-      REAL*8 ZFLUX(KDLON,2,KFLEV+1) ! RADIATIVE FLUXES (1:up; 2:down)
-      REAL*8 ZFLUC(KDLON,2,KFLEV+1) ! CLEAR-SKY RADIATIVE FLUXES
-      REAL*8 ZBINT(KDLON,KFLEV+1)            ! Intermediate variable
-      REAL*8 ZBSUI(KDLON)                    ! Intermediate variable
-      REAL*8 ZCTS(KDLON,KFLEV)               ! Intermediate variable
-      REAL*8 ZCNTRB(KDLON,KFLEV+1,KFLEV+1)   ! Intermediate variable
-      SAVE ZFLUX, ZFLUC, ZBINT, ZBSUI, ZCTS, ZCNTRB
+cym      REAL*8 ZFLUX(KDLON,2,KFLEV+1) ! RADIATIVE FLUXES (1:up; 2:down)
+cym      REAL*8 ZFLUC(KDLON,2,KFLEV+1) ! CLEAR-SKY RADIATIVE FLUXES
+cym      REAL*8 ZBINT(KDLON,KFLEV+1)            ! Intermediate variable
+cym      REAL*8 ZBSUI(KDLON)                    ! Intermediate variable
+cym      REAL*8,ZCTS(KDLON,KFLEV)               ! Intermediate variable
+cym      REAL*8 ZCNTRB(KDLON,KFLEV+1,KFLEV+1)   ! Intermediate variable
+cym      SAVE ZFLUX, ZFLUC, ZBINT, ZBSUI, ZCTS, ZCNTRB
+      REAL*8,allocatable,save :: ZFLUX(:,:,:) ! RADIATIVE FLUXES (1:up; 2:down)
+      REAL*8,allocatable,save :: ZFLUC(:,:,:) ! CLEAR-SKY RADIATIVE FLUXES
+      REAL*8,allocatable,save :: ZBINT(:,:)            ! Intermediate variable
+      REAL*8,allocatable,save :: ZBSUI(:)                    ! Intermediate variable
+      REAL*8,allocatable,save :: ZCTS(:,:)               ! Intermediate variable
+      REAL*8,allocatable,save :: ZCNTRB(:,:,:)   ! Intermediate variable
+c$OMP THREADPRIVATE(ZFLUX, ZFLUC, ZBINT, ZBSUI, ZCTS, ZCNTRB)
 c
       INTEGER ilim, i, k, kpl1
@@ -2871,6 +2924,8 @@
       LOGICAL appel1er
       SAVE appel1er, itaplw0, itaplw
+c$OMP THREADPRIVATE(appel1er, itaplw0, itaplw)
       DATA appel1er /.TRUE./
       DATA itaplw0,itaplw /0,0/
+
 C     ------------------------------------------------------------------
       IF (appel1er) THEN
@@ -2878,4 +2933,11 @@
          PRINT*, "LW cloudy-sky calling frequency: ", lwpas
          PRINT*, "   In general, they should be 1"
+cym
+	 allocate(ZFLUX(KDLON,2,KFLEV+1) )
+         allocate(ZFLUC(KDLON,2,KFLEV+1) )
+         allocate(ZBINT(KDLON,KFLEV+1))
+         allocate(ZBSUI(KDLON))
+         allocate(ZCTS(KDLON,KFLEV))
+         allocate(ZCNTRB(KDLON,KFLEV+1,KFLEV+1))
          appel1er=.FALSE.
       ENDIF
@@ -2940,8 +3002,9 @@
      S               PAER,PDP,PPMB,PPSOL,POZ,PTAVE,PVIEW,PWV,
      S               PABCU)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "raddimlw.h"
 #include "YOMCST.h"
@@ -3038,12 +3101,17 @@
       REAL*8 TREF
       SAVE TREF
+c$OMP THREADPRIVATE(TREF)
       REAL*8 RT1(2)
       SAVE RT1
+c$OMP THREADPRIVATE(RT1)
       REAL*8 RAER(5,5)
       SAVE RAER
+c$OMP THREADPRIVATE(RAER)
       REAL*8 AT(8,3), BT(8,3)
       SAVE AT, BT
+c$OMP THREADPRIVATE(AT, BT)
       REAL*8 OCT(4)
       SAVE OCT
+c$OMP THREADPRIVATE(OCT)
       DATA TREF /250.0/
       DATA (RT1(IG1),IG1=1,2) / -0.577350269, +0.577350269 /
@@ -3333,8 +3401,9 @@
       SUBROUTINE LWBV(KLIM,PDP,PDT0,PEMIS,PPMB,PTL,PTAVE,PABCU,
      S                PFLUC,PBINT,PBSUI,PCTS,PCNTRB)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "raddimlw.h"
 #include "YOMCST.h"
@@ -3424,8 +3493,9 @@
      R               PBINT,PBSUIN,PCTS,PCNTRB,
      S               PFLUX)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "radepsi.h"
 #include "radopt.h"
@@ -3829,8 +3899,9 @@
      S  , PB,PBINT,PBSUIN,PBSUR,PBTOP,PDBSL
      S  , PGA,PGB,PGASUR,PGBSUR,PGATOP,PGBTOP)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "raddimlw.h"
 C
@@ -3925,8 +3996,11 @@
       REAL*8 TINTP(11)
       SAVE TINTP
+c$OMP THREADPRIVATE(TINTP)
       REAL*8 GA(11,16,3), GB(11,16,3)
       SAVE GA, GB
+c$OMP THREADPRIVATE(GA, GB)
       REAL*8 XP(6,6)
       SAVE XP
+c$OMP THREADPRIVATE(XP)
 c
       DATA TINTP / 187.5, 200., 212.5, 225., 237.5, 250.,
@@ -5240,8 +5314,9 @@
      R  , PGA,PGB,PGASUR,PGBSUR,PGATOP,PGBTOP
      S  , PCNTRB,PCTS,PFLUC)
+       USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "raddimlw.h"
 #include "YOMCST.h"
@@ -5353,8 +5428,9 @@
      R  , PGA,PGB,PGASUR,PGBSUR,PGATOP,PGBTOP
      S  , PCTS,PFLUC)
+       USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "raddimlw.h"
 #include "radopt.h"
@@ -5685,8 +5761,9 @@
      R  , PGA,PGB
      S  , PCNTRB,PDISD,PDISU)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "raddimlw.h"
 C
@@ -5937,8 +6014,9 @@
      R  , PABCU,PDBSL,PGA,PGB
      S  , PADJD,PADJU,PCNTRB,PDBDT)
+       USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "raddimlw.h"
 C
@@ -6001,4 +6079,5 @@
       REAL*8 WG1(2)
       SAVE WG1
+c$OMP THREADPRIVATE(WG1)
       DATA (WG1(jk),jk=1,2) /1.0, 1.0/
 C-----------------------------------------------------------------------
@@ -6144,8 +6223,9 @@
       END
       SUBROUTINE LWTT(PGA,PGB,PUU, PTT)
+       USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "raddimlw.h"
 C
@@ -6319,8 +6399,9 @@
       END
       SUBROUTINE LWTTM(PGA,PGB,PUU1,PUU2, PTT)
+      USE dimphy
       IMPLICIT none
-#include "dimensions.h"
-#include "dimphy.h"
-#include "raddim.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
+cym#include "raddim.h"
 #include "raddimlw.h"
 C
