Index: LMDZ5/trunk/libf/phylmd/rrtm/aeropt_5wv_rrtm.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/rrtm/aeropt_5wv_rrtm.F90	(revision 2627)
+++ LMDZ5/trunk/libf/phylmd/rrtm/aeropt_5wv_rrtm.F90	(revision 2634)
@@ -94,10 +94,9 @@
   REAL :: od670aer(klon)  ! epaisseur optique aerosol extinction 670 nm
   REAL :: fac
-  REAL :: zdp1(klon,klev) 
   INTEGER, ALLOCATABLE, DIMENSION(:)  :: aerosol_name
   INTEGER :: nb_aer, itau
   LOGICAL :: ok_itau
   
-  REAL :: dh(KLON,KLEV)
+  REAL :: zdh(klon,klev)
   
    ! Soluble components 1- BC soluble; 2- POM soluble; 3- SO4 acc.; 4- SO4 coarse; 5 seasalt super-coarse; 6 seasalt coarse; 7 seasalt acc.
@@ -106,11 +105,8 @@
   REAL :: alpha_aeri_5wv(las,naero_insoluble)         ! Ext. coeff. ** m2/g 
 
-  REAL, DIMENSION(klon,klev,naero_tot) :: mass_temp
-  
   !
   ! Proprietes optiques
   !
   REAL :: fact_RH(nbre_RH)
-  LOGICAL :: used_tau(naero_tot)
   INTEGER :: n
 
@@ -209,12 +205,10 @@
   ai(:) = 0.
   tausum(:,:,:) = 0.
+  tau(:,:,:,:)=0.
 
   DO k=1, klev
     DO i=1, klon
       zrho=pplay(i,k)/t_seri(i,k)/RD                  ! kg/m3
-      dh(i,k)=pdel(i,k)/(RG*zrho)
-!CDIR UNROLL=naero_spc
-      mass_temp(i,k,:) = m_allaer(i,k,:) / zrho / 1.e+9
-      zdp1(i,k)=pdel(i,k)/(RG*delt)     ! air mass auxiliary  variable --> zdp1 [kg/(m^2 *s)]
+      zdh(i,k)=pdel(i,k)/(RG*zrho)                    ! m
     ENDDO
   ENDDO
@@ -270,15 +264,10 @@
   !      
 
-!CDIR ON_ADB(RH_tab)
-!CDIR ON_ADB(fact_RH)
-!CDIR NOVECTOR
   DO n=1,nbre_RH-1
     fact_RH(n)=1./(RH_tab(n+1)-RH_tab(n))
   ENDDO
    
-  DO k=1, KLEV
-!CDIR ON_ADB(RH_tab)
-!CDIR ON_ADB(fact_RH)
-    DO i=1, KLON
+  DO k=1, klev
+    DO i=1, klon
       rh(i,k)=MIN(RHcl(i,k)*100.,RH_MAX)
       RH_num(i,k) = INT( rh(i,k)/10. + 1.)
@@ -289,7 +278,4 @@
   ENDDO
 
-!CDIR SHORTLOOP  
-  used_tau(:)=.FALSE.
-    
   DO m=1,nb_aer   ! tau is only computed for each mass    
     fac=1.0
@@ -330,23 +316,19 @@
     ENDIF
 
-    IF (soluble) then
-      used_tau(spsol)=.TRUE.
-    ELSE
-      used_tau(naero_soluble+spinsol)=.TRUE.
-    ENDIF
-
     aerindex=aerosol_name(m)
 
     DO la=1,las
 
+    !--only 550, 670 and 865 nm are used
+    IF (la.NE.la550.AND.la.NE.la670.AND.la.NE.la865) CYCLE
+
       IF (soluble) THEN            ! For soluble aerosol
 
-          DO k=1, KLEV
-            DO i=1, KLON
+          DO k=1, klev
+            DO i=1, klon
               tau_ae5wv_int = alpha_aers_5wv(RH_num(i,k),la,spsol)+DELTA(i,k)* &
                              (alpha_aers_5wv(RH_num(i,k)+1,la,spsol) - & 
                               alpha_aers_5wv(RH_num(i,k),la,spsol))
-              tau(i,k,la,aerindex) = mass_temp(i,k,aerindex)*1000.*zdp1(i,k)*   &
-                                    tau_ae5wv_int*delt*fac
+              tau(i,k,la,aerindex) = m_allaer(i,k,aerindex)/1.e6*zdh(i,k)*tau_ae5wv_int*fac
               tausum(i,la,aerindex)=tausum(i,la,aerindex)+tau(i,k,la,aerindex)
             ENDDO
@@ -355,9 +337,8 @@
       ELSE                         ! For insoluble aerosol
 
-        DO k=1, KLEV
-          DO i=1, KLON
+        DO k=1, klev
+          DO i=1, klon
             tau_ae5wv_int = alpha_aeri_5wv(la,spinsol)
-            tau(i,k,la,aerindex) = mass_temp(i,k,aerindex)*1000.*zdp1(i,k)* &
-                                   tau_ae5wv_int*delt*fac
+            tau(i,k,la,aerindex) = m_allaer(i,k,aerindex)/1.e6*zdh(i,k)*tau_ae5wv_int*fac
             tausum(i,la,aerindex)= tausum(i,la,aerindex)+tau(i,k,la,aerindex)
           ENDDO
@@ -369,41 +350,14 @@
   ENDDO     ! Boucle sur les masses de traceurs
 
-  DO m=1,naero_tot
-    IF (.NOT.used_tau(m)) tau(:,:,:,m)=0.
-  ENDDO  
-
-  DO i=1, klon
-     od550aer(i)=0.
-     DO m=1,naero_tot
-        od550aer(i)=od550aer(i)+tausum(i,la550,m)
-     END DO
-  END DO
-
-  DO i=1, klon
-     od670aer(i)=0.
-     DO m=1,naero_tot
-        od670aer(i)=od670aer(i)+tausum(i,la670,m)
-     END DO
-  END DO
-
-  DO i=1, klon
-     od865aer(i)=0.
-     DO m=1,naero_tot
-        od865aer(i)=od865aer(i)+tausum(i,la865,m)
-     END DO
-  END DO
-
-  DO i=1, klon
-     DO k=1, KLEV
-        ec550aer(i,k)=0.
-        DO m=1,naero_tot
-           ec550aer(i,k)=ec550aer(i,k)+tau(i,k,la550,m)/dh(i,k)
-        END DO
-     END DO
-  END DO
-  
-  DO i=1, klon
-    ai(i)=-LOG(MAX(od670aer(i),1.e-8)/MAX(od865aer(i),1.e-8))/LOG(670./865.)
-  ENDDO
+!--AOD calculations for diagnostics
+  od550aer(:)=SUM(tausum(:,la550,:),dim=2)
+  od670aer(:)=SUM(tausum(:,la670,:),dim=2)
+  od865aer(:)=SUM(tausum(:,la865,:),dim=2)
+
+!--extinction coefficient for diagnostic
+  ec550aer(:,:)=SUM(tau(:,:,la550,:),dim=3)/zdh(:,:)
+
+!--aerosol index
+  ai(:)=-LOG(MAX(od670aer(:),1.e-8)/MAX(od865aer(:),1.e-8))/LOG(670./865.)
 
   od550lt1aer(:)=tausum(:,la550,id_ASSO4M_phy)+tausum(:,la550,id_ASBCM_phy) +tausum(:,la550,id_AIBCM_phy)+ &
Index: LMDZ5/trunk/libf/phylmd/rrtm/aeropt_6bands_rrtm.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/rrtm/aeropt_6bands_rrtm.F90	(revision 2627)
+++ LMDZ5/trunk/libf/phylmd/rrtm/aeropt_6bands_rrtm.F90	(revision 2634)
@@ -36,6 +36,6 @@
   !
   ! Output arguments:
-  ! 1= total aerosols 
-  ! 2= natural aerosols
+  ! 2= total aerosols 
+  ! 1= natural aerosols
   !
   REAL, DIMENSION(klon,klev,2,nbands_sw_rrtm), INTENT(out) :: tau_allaer ! epaisseur optique aerosol
@@ -66,16 +66,12 @@
   REAL :: Fact_RH(nbre_RH)
   REAL :: fac
-  REAL :: zdp1(klon,klev) 
+  REAL :: zdh(klon,klev) 
   INTEGER, ALLOCATABLE, DIMENSION(:)   :: aerosol_name
   INTEGER :: nb_aer
 
-  REAL, DIMENSION(klon,klev,naero_tot) :: mass_temp
-  REAL, DIMENSION(klon,klev,naero_tot) :: mass_temp_pi
   REAL, DIMENSION(klon,klev,naero_tot,nbands_sw_rrtm) ::  tau_ae
   REAL, DIMENSION(klon,klev,naero_tot,nbands_sw_rrtm) ::  tau_ae_pi
   REAL, DIMENSION(klon,klev,naero_tot,nbands_sw_rrtm) ::  piz_ae
   REAL, DIMENSION(klon,klev,naero_tot,nbands_sw_rrtm) ::  cg_ae
-
-
   !
   ! Proprietes optiques
@@ -89,5 +85,4 @@
 
   INTEGER :: id
-  LOGICAL :: used_aer(naero_tot)
   REAL :: tmp_var, tmp_var_pi
 
@@ -277,4 +272,5 @@
   spsol = 0
   spinsol = 0 
+
   IF (NSW.NE.nbands_sw_rrtm) THEN
      print *,'Erreur NSW doit etre egal a 6 pour cette routine'
@@ -282,13 +278,5 @@
   ENDIF
 
-  DO k=1, klev
-    DO i=1, klon
-!CDIR UNROLL=naero_tot
-      mass_temp(i,k,:) = m_allaer(i,k,:) / zrho(i,k) / 1.e+9  !--kg/kg
-!CDIR UNROLL=naero_tot
-      mass_temp_pi(i,k,:) = m_allaer_pi(i,k,:) / zrho(i,k) / 1.e+9
-      zdp1(i,k)=pdel(i,k)/(RG*delt)      ! air mass auxiliary  variable --> zdp1 [kg/(m^2 *s)]
-    ENDDO
-  ENDDO
+  zdh(:,:)=pdel(:,:)/(RG*zrho(:,:))      ! m
 
   IF (flag_aerosol .EQ. 1) THEN 
@@ -339,14 +327,10 @@
   !      compute optical_thickness_at_gridpoint_per_species
 
-!!CDIR ON_ADB(RH_tab)
-!CDIR ON_ADB(fact_RH)
-!CDIR SHORTLOOP
   DO n=1,nbre_RH-1
     fact_RH(n)=1./(RH_tab(n+1)-RH_tab(n))
   ENDDO
    
-  DO k=1, KLEV
-!CDIR ON_ADB(fact_RH)
-    DO i=1, KLON
+  DO k=1, klev
+    DO i=1, klon
       rh(i,k)=MIN(RHcl(i,k)*100.,RH_MAX)
       RH_num(i,k) = INT(rh(i,k)/10. + 1.)
@@ -357,5 +341,8 @@
   ENDDO
 
-  used_aer(:)=.FALSE.
+  tau_ae(:,:,:,:)=0.
+  tau_ae_pi(:,:,:,:)=0.
+  piz_ae(:,:,:,:)=0.
+  cg_ae(:,:,:,:)=0.
     
   DO m=1,nb_aer   ! tau is only computed for each mass
@@ -398,12 +385,11 @@
 
     id=aerosol_name(m)
-    used_aer(id)=.TRUE.
 
     IF (soluble) THEN
 
-       DO k=1, KLEV
-         DO i=1, KLON
-           tmp_var=mass_temp(i,k,spsol)*1000.*zdp1(i,k)*delt*fac
-           tmp_var_pi=mass_temp_pi(i,k,spsol)*1000.*zdp1(i,k)*delt*fac
+       DO k=1, klev
+         DO i=1, klon
+           tmp_var=m_allaer(i,k,spsol)/1.e6*zdh(i,k)*fac
+           tmp_var_pi=m_allaer_pi(i,k,spsol)/1.e6*zdh(i,k)*fac
 
            DO inu=1,NSW
@@ -432,8 +418,8 @@
      ELSE    ! For all aerosol insoluble components
 
-       DO k=1, KLEV
-         DO i=1, KLON
-           tmp_var=mass_temp(i,k,naero_soluble+ spinsol)*1000.*zdp1(i,k)*delt*fac
-           tmp_var_pi=mass_temp_pi(i,k,naero_soluble+spinsol)*1000.*zdp1(i,k)*delt*fac
+       DO k=1, klev
+         DO i=1, klon
+           tmp_var=m_allaer(i,k,naero_soluble+spinsol)/1.e6*zdh(i,k)*fac
+           tmp_var_pi=m_allaer_pi(i,k,naero_soluble+spinsol)/1.e6*zdh(i,k)*fac
 
            DO inu=1,NSW
@@ -454,16 +440,7 @@
   ENDDO  ! nb_aer  
 
-  DO m=1,naero_tot
-    IF (.NOT. used_aer(m)) THEN
-      tau_ae(:,:,m,:)=0.
-      tau_ae_pi(:,:,m,:)=0.
-      piz_ae(:,:,m,:)=0.
-      cg_ae(:,:,m,:)=0.
-    ENDIF
-  ENDDO
-
   DO inu=1, NSW 
-     DO k=1, KLEV
-       DO i=1, KLON
+     DO k=1, klev
+       DO i=1, klon
 !--anthropogenic aerosol
          tau_allaer(i,k,2,inu)=tau_ae(i,k,id_ASSO4M_phy,inu)+tau_ae(i,k,id_CSSO4M_phy,inu)+ &
@@ -536,9 +513,9 @@
     ENDDO
    
-!--???????
-  inu=1
-  DO i=1, KLON
-     absvisaer(i)=SUM((1-piz_allaer(i,:,:,inu))*tau_allaer(i,:,:,inu))
-  END DO	
+!--waveband 2 and all aerosol
+  inu=2
+  DO i=1, klon
+     absvisaer(i)=SUM((1-piz_allaer(i,:,2,inu))*tau_allaer(i,:,2,inu))
+  ENDDO
 
   DEALLOCATE(aerosol_name) 
