Index: palm/trunk/SOURCE/prognostic_equations.f90
===================================================================
--- palm/trunk/SOURCE/prognostic_equations.f90	(revision 3840)
+++ palm/trunk/SOURCE/prognostic_equations.f90	(revision 3864)
@@ -25,4 +25,11 @@
 ! -----------------
 ! $Id$
+! Modifications made for salsa:
+! - salsa_prognostic_equations moved to salsa_mod (and the call to 
+!   module_interface_mod)
+! - Renamed nbins --> nbins_aerosol, ncc_tot --> ncomponents_mass and 
+!   ngast --> ngases_salsa and loop indices b, c and sg to ib, ic and ig
+! 
+! 3840 2019-03-29 10:35:52Z knoop
 ! added USE chem_gasphase_mod for nvar, nspec and spc_names
 ! 
@@ -376,5 +383,5 @@
     USE buoyancy_mod,                                                          &
         ONLY:  buoyancy
-           
+
     USE chem_modules,                                                          &
         ONLY:  call_chem_at_all_substeps, chem_gasphase_on, cs_name,           &
@@ -447,14 +454,14 @@
                skip_time_do_radiation
 #endif
-                          
+
     USE salsa_mod,                                                             &
-        ONLY:  aerosol_mass, aerosol_number, dt_salsa, last_salsa_time, nbins, &
-               ncc_tot, ngast, salsa_boundary_conds, salsa_diagnostics,        &
-               salsa_driver, salsa_gas, salsa_gases_from_chem, salsa_tendency, &
-               skip_time_do_salsa
-               
+        ONLY:  aerosol_mass, aerosol_number, dt_salsa, last_salsa_time,        &
+               nbins_aerosol, ncomponents_mass, ngases_salsa,                  &
+               salsa_boundary_conds, salsa_diagnostics, salsa_driver,          &
+               salsa_gas, salsa_gases_from_chem, skip_time_do_salsa
+
     USE salsa_util_mod,                                                        &
-        ONLY:  sums_salsa_ws_l                              
-    
+        ONLY:  sums_salsa_ws_l
+
     USE statistics,                                                            &
         ONLY:  hom
@@ -506,10 +513,11 @@
 
     IMPLICIT NONE
-    
-    INTEGER(iwp) ::  b                   !< index for aerosol size bins (salsa)
-    INTEGER(iwp) ::  c                   !< index for chemical compounds (salsa)
-    INTEGER(iwp) ::  g                   !< index for gaseous compounds (salsa)
+
     INTEGER(iwp) ::  i                   !<
     INTEGER(iwp) ::  i_omp_start         !<
+    INTEGER(iwp) ::  ib                  !< index for aerosol size bins (salsa)
+    INTEGER(iwp) ::  ic                  !< index for chemical compounds (salsa)
+    INTEGER(iwp) ::  icc                 !< additional index for chemical compounds (salsa)
+    INTEGER(iwp) ::  ig                  !< index for gaseous compounds (salsa)
     INTEGER(iwp) ::  j                   !<
     INTEGER(iwp) ::  k                   !<
@@ -587,5 +595,5 @@
        CALL cpu_log( log_point_s(84), 'chem.exch-horiz', 'stop' )
 
-    ENDIF       
+    ENDIF
 !
 !-- Run SALSA and aerosol dynamic processes. SALSA is run with a longer time 
@@ -593,10 +601,10 @@
 !-- concentrations of aerosol number and mass 
     IF ( salsa )  THEN
-       
-       IF ( time_since_reference_point >= skip_time_do_salsa )  THEN                 
+
+       IF ( time_since_reference_point >= skip_time_do_salsa )  THEN
           IF ( ( time_since_reference_point - last_salsa_time ) >= dt_salsa )  &
           THEN
              CALL cpu_log( log_point_s(90), 'salsa processes ', 'start' )
-             !$OMP PARALLEL PRIVATE (i,j,b,c,g)
+             !$OMP PARALLEL PRIVATE (i,j,ib,ic,icc,ig)
              !$OMP DO
 !
@@ -609,5 +617,5 @@
                 ENDDO
              ENDDO
-             
+
              CALL cpu_log( log_point_s(90), 'salsa processes ', 'stop' )
              
@@ -615,21 +623,21 @@
 !
 !--          Exchange ghost points and decycle if needed.
-             DO  b = 1, nbins
-                CALL exchange_horiz( aerosol_number(b)%conc, nbgp )
-                CALL salsa_boundary_conds( aerosol_number(b)%conc_p,           &
-                                           aerosol_number(b)%init )
-                DO  c = 1, ncc_tot
-                   CALL exchange_horiz( aerosol_mass((c-1)*nbins+b)%conc, nbgp )
-                   CALL salsa_boundary_conds(                                  &
-                                           aerosol_mass((c-1)*nbins+b)%conc_p, &
-                                           aerosol_mass((c-1)*nbins+b)%init )
-                ENDDO
-             ENDDO
-             
+             DO  ib = 1, nbins_aerosol
+                CALL exchange_horiz( aerosol_number(ib)%conc, nbgp )
+                CALL salsa_boundary_conds( aerosol_number(ib)%conc,            &
+                                           aerosol_number(ib)%init )
+                DO  ic = 1, ncomponents_mass
+                   icc = ( ic - 1 ) * nbins_aerosol + ib
+                   CALL exchange_horiz( aerosol_mass(icc)%conc, nbgp )
+                   CALL salsa_boundary_conds( aerosol_mass(icc)%conc,          &
+                                              aerosol_mass(icc)%init )
+                ENDDO
+             ENDDO
+
              IF ( .NOT. salsa_gases_from_chem )  THEN
-                DO  g = 1, ngast
-                   CALL exchange_horiz( salsa_gas(g)%conc, nbgp )
-                   CALL salsa_boundary_conds( salsa_gas(g)%conc_p,             &
-                                              salsa_gas(g)%init )
+                DO  ig = 1, ngases_salsa
+                   CALL exchange_horiz( salsa_gas(ig)%conc, nbgp )
+                   CALL salsa_boundary_conds( salsa_gas(ig)%conc,              &
+                                              salsa_gas(ig)%init )
                 ENDDO
              ENDIF
@@ -638,9 +646,9 @@
              !$OMP END PARALLEL
              last_salsa_time = time_since_reference_point
-             
-          ENDIF
-          
-       ENDIF
-       
+
+          ENDIF
+
+       ENDIF
+
     ENDIF 
 
@@ -1442,56 +1450,6 @@
                                      chem_species(lsp)%diss_l_cs )       
              ENDDO
-          
+
           ENDIF   ! Chemical equations
-       
-          IF ( salsa )  THEN 
-!
-!--          Loop over aerosol size bins: number and mass bins
-             IF ( time_since_reference_point >= skip_time_do_salsa )  THEN
-             
-                DO  b = 1, nbins                
-                   sums_salsa_ws_l = aerosol_number(b)%sums_ws_l
-                   CALL salsa_tendency( 'aerosol_number',                      &
-                                         aerosol_number(b)%conc_p,             &
-                                         aerosol_number(b)%conc,               &
-                                         aerosol_number(b)%tconc_m,            &
-                                         i, j, i_omp_start, tn, b, b,          &
-                                         aerosol_number(b)%flux_s,             &
-                                         aerosol_number(b)%diss_s,             &
-                                         aerosol_number(b)%flux_l,             &
-                                         aerosol_number(b)%diss_l,             &
-                                         aerosol_number(b)%init )
-                   aerosol_number(b)%sums_ws_l = sums_salsa_ws_l
-                   DO  c = 1, ncc_tot
-                      sums_salsa_ws_l = aerosol_mass((c-1)*nbins+b)%sums_ws_l 
-                      CALL salsa_tendency( 'aerosol_mass',                     &
-                                            aerosol_mass((c-1)*nbins+b)%conc_p,&
-                                            aerosol_mass((c-1)*nbins+b)%conc,  &
-                                            aerosol_mass((c-1)*nbins+b)%tconc_m,&
-                                            i, j, i_omp_start, tn, b, c,       &
-                                            aerosol_mass((c-1)*nbins+b)%flux_s,&
-                                            aerosol_mass((c-1)*nbins+b)%diss_s,&
-                                            aerosol_mass((c-1)*nbins+b)%flux_l,&
-                                            aerosol_mass((c-1)*nbins+b)%diss_l,&
-                                            aerosol_mass((c-1)*nbins+b)%init )
-                      aerosol_mass((c-1)*nbins+b)%sums_ws_l = sums_salsa_ws_l
-                   ENDDO
-                ENDDO
-                IF ( .NOT. salsa_gases_from_chem )  THEN
-                   DO  g = 1, ngast
-                      sums_salsa_ws_l = salsa_gas(g)%sums_ws_l
-                      CALL salsa_tendency( 'salsa_gas', salsa_gas(g)%conc_p,   &
-                                      salsa_gas(g)%conc, salsa_gas(g)%tconc_m, &
-                                      i, j, i_omp_start, tn, g, g,             &
-                                      salsa_gas(g)%flux_s, salsa_gas(g)%diss_s,&
-                                      salsa_gas(g)%flux_l, salsa_gas(g)%diss_l,&
-                                      salsa_gas(g)%init )
-                      salsa_gas(g)%sums_ws_l = sums_salsa_ws_l
-                   ENDDO
-                ENDIF
-             
-             ENDIF
-             
-          ENDIF        
 
        ENDDO  ! loop over j
@@ -1517,8 +1475,9 @@
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  b     !< index for aerosol size bins (salsa)
-    INTEGER(iwp) ::  c     !< index for chemical compounds (salsa)
-    INTEGER(iwp) ::  g     !< index for gaseous compounds (salsa)
     INTEGER(iwp) ::  i     !<
+    INTEGER(iwp) ::  ib    !< index for aerosol size bins (salsa)
+    INTEGER(iwp) ::  ic    !< index for chemical compounds (salsa)
+    INTEGER(iwp) ::  icc   !< additional index for chemical compounds (salsa)
+    INTEGER(iwp) ::  ig    !< index for gaseous compounds (salsa)
     INTEGER(iwp) ::  j     !<
     INTEGER(iwp) ::  k     !<
@@ -1532,12 +1491,9 @@
 !-- concentrations of aerosol number and mass 
     IF ( salsa )  THEN
-       
        IF ( time_since_reference_point >= skip_time_do_salsa )  THEN
-       
           IF ( ( time_since_reference_point - last_salsa_time ) >= dt_salsa )  &
           THEN
-          
              CALL cpu_log( log_point_s(90), 'salsa processes ', 'start' )
-             !$OMP PARALLEL PRIVATE (i,j,b,c,g)
+             !$OMP PARALLEL PRIVATE (i,j,ib,ic,icc,ig)
              !$OMP DO
 !
@@ -1550,38 +1506,32 @@
                 ENDDO
              ENDDO
-             
+
              CALL cpu_log( log_point_s(90), 'salsa processes ', 'stop' )
-             
              CALL cpu_log( log_point_s(91), 'salsa exch-horiz ', 'start' )
 !
 !--          Exchange ghost points and decycle if needed.
-             DO  b = 1, nbins
-                CALL exchange_horiz( aerosol_number(b)%conc, nbgp )
-                CALL salsa_boundary_conds( aerosol_number(b)%conc_p,           &
-                                           aerosol_number(b)%init )
-                DO  c = 1, ncc_tot
-                   CALL exchange_horiz( aerosol_mass((c-1)*nbins+b)%conc, nbgp )
-                   CALL salsa_boundary_conds(                                  &
-                                           aerosol_mass((c-1)*nbins+b)%conc_p, &
-                                           aerosol_mass((c-1)*nbins+b)%init )
-                ENDDO
-             ENDDO
-             
+             DO  ib = 1, nbins_aerosol
+                CALL exchange_horiz( aerosol_number(ib)%conc, nbgp )
+                CALL salsa_boundary_conds( aerosol_number(ib)%conc,            &
+                                           aerosol_number(ib)%init )
+                DO  ic = 1, ncomponents_mass
+                   icc = ( ic - 1 ) * nbins_aerosol + ib
+                   CALL exchange_horiz( aerosol_mass(icc)%conc, nbgp )
+                   CALL salsa_boundary_conds( aerosol_mass(icc)%conc,          &
+                                              aerosol_mass(icc)%init )
+                ENDDO
+             ENDDO
              IF ( .NOT. salsa_gases_from_chem )  THEN
-                DO  g = 1, ngast
-                   CALL exchange_horiz( salsa_gas(g)%conc, nbgp )
-                   CALL salsa_boundary_conds( salsa_gas(g)%conc_p,             &
-                                              salsa_gas(g)%init )
+                DO  ig = 1, ngases_salsa
+                   CALL exchange_horiz( salsa_gas(ig)%conc, nbgp )
+                   CALL salsa_boundary_conds( salsa_gas(ig)%conc,              &
+                                              salsa_gas(ig)%init )
                 ENDDO
              ENDIF
              CALL cpu_log( log_point_s(91), 'salsa exch-horiz ', 'stop' )
-             
              !$OMP END PARALLEL
              last_salsa_time = time_since_reference_point
-             
-          ENDIF
-          
-       ENDIF
-       
+          ENDIF
+       ENDIF
     ENDIF 
 
@@ -2661,43 +2611,4 @@
        CALL cpu_log( log_point_s(25), 'chem.advec+diff+prog', 'stop' )             
     ENDIF   ! Chemicals equations
-        
-    IF ( salsa )  THEN 
-       CALL cpu_log( log_point_s(92), 'salsa advec+diff+prog ', 'start' )
-!
-!--          Loop over aerosol size bins: number and mass bins
-       IF ( time_since_reference_point >= skip_time_do_salsa )  THEN
-       
-          DO  b = 1, nbins                
-             sums_salsa_ws_l = aerosol_number(b)%sums_ws_l
-             CALL salsa_tendency( 'aerosol_number', aerosol_number(b)%conc_p,  &
-                                   aerosol_number(b)%conc,                     &
-                                   aerosol_number(b)%tconc_m,                  &
-                                   b, b, aerosol_number(b)%init )
-             aerosol_number(b)%sums_ws_l = sums_salsa_ws_l
-             DO  c = 1, ncc_tot
-                sums_salsa_ws_l = aerosol_mass((c-1)*nbins+b)%sums_ws_l 
-                CALL salsa_tendency( 'aerosol_mass',                           &
-                                      aerosol_mass((c-1)*nbins+b)%conc_p,      &
-                                      aerosol_mass((c-1)*nbins+b)%conc,        &
-                                      aerosol_mass((c-1)*nbins+b)%tconc_m,     &
-                                      b, c, aerosol_mass((c-1)*nbins+b)%init )
-                aerosol_mass((c-1)*nbins+b)%sums_ws_l = sums_salsa_ws_l
-             ENDDO
-          ENDDO
-          IF ( .NOT. salsa_gases_from_chem )  THEN
-             DO  g = 1, ngast
-                sums_salsa_ws_l = salsa_gas(g)%sums_ws_l
-                CALL salsa_tendency( 'salsa_gas', salsa_gas(g)%conc_p,         &
-                                      salsa_gas(g)%conc, salsa_gas(g)%tconc_m, &
-                                      g, g, salsa_gas(g)%init )
-                salsa_gas(g)%sums_ws_l = sums_salsa_ws_l
-             ENDDO
-          ENDIF
-       
-       ENDIF
-       
-       CALL cpu_log( log_point_s(92), 'salsa advec+diff+prog ', 'stop' )
-    ENDIF
-
 
  END SUBROUTINE prognostic_equations_vector
