Index: palm/trunk/SOURCE/prognostic_equations.f90
===================================================================
--- palm/trunk/SOURCE/prognostic_equations.f90	(revision 94)
+++ palm/trunk/SOURCE/prognostic_equations.f90	(revision 95)
@@ -4,4 +4,5 @@
 ! Actual revisions:
 ! -----------------
+! prognostic equation for salinity
 ! new argument zw in calls of diffusion_e
 !
@@ -414,4 +415,93 @@
 
 !
+!-- If required, compute prognostic equation for salinity
+    IF ( ocean )  THEN
+
+       CALL cpu_log( log_point(37), 'sa-equation', 'start' )
+
+!
+!--    sa-tendency terms with communication
+       sat = tsc(1)
+       sbt = tsc(2)
+       IF ( scalar_advec == 'bc-scheme' )  THEN
+
+          IF ( timestep_scheme(1:5) /= 'runge' )  THEN
+!
+!--          Bott-Chlond scheme always uses Euler time step when leapfrog is
+!--          switched on. Thus:
+             sat = 1.0
+             sbt = 1.0
+          ENDIF
+          tend = 0.0
+          CALL advec_s_bc( sa, 'sa' )
+       ELSE
+          IF ( tsc(2) /= 2.0 )  THEN
+             IF ( scalar_advec == 'ups-scheme' )  THEN
+                tend = 0.0
+                CALL advec_s_ups( sa, 'sa' )
+             ENDIF
+          ENDIF
+       ENDIF
+
+!
+!--    sa terms with no communication
+       DO  i = nxl, nxr
+          DO  j = nys, nyn
+!
+!--          Tendency-terms
+             IF ( scalar_advec == 'bc-scheme' )  THEN
+                CALL diffusion_s( i, j, ddzu, ddzw, kh, sa, saswsb, saswst, &
+                                  tend )
+             ELSE
+                IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' ) THEN
+                   tend(:,j,i) = 0.0
+                   CALL advec_s_pw( i, j, sa )
+                ELSE
+                   IF ( scalar_advec /= 'ups-scheme' )  THEN
+                      tend(:,j,i) = 0.0
+                      CALL advec_s_up( i, j, sa )
+                   ENDIF
+                ENDIF
+                CALL diffusion_s( i, j, ddzu, ddzw, kh, sa, saswsb, saswst, &
+                                  tend )
+             ENDIF
+       
+             CALL user_actions( i, j, 'sa-tendency' )
+
+!
+!--          Prognostic equation for salinity
+             DO  k = nzb_s_inner(j,i)+1, nzt
+                sa_p(k,j,i) = sat * sa(k,j,i) +                                &
+                              dt_3d * (                                        &
+                                     sbt * tend(k,j,i) + tsc(3) * tsa_m(k,j,i) &
+                                      ) -                                      &
+                              tsc(5) * rdf(k) * ( sa(k,j,i) - sa_init(k) )
+                IF ( sa_p(k,j,i) < 0.0 )  sa_p(k,j,i) = 0.1 * sa(k,j,i)
+             ENDDO
+
+!
+!--          Calculate tendencies for the next Runge-Kutta step
+             IF ( timestep_scheme(1:5) == 'runge' )  THEN
+                IF ( intermediate_timestep_count == 1 )  THEN
+                   DO  k = nzb_s_inner(j,i)+1, nzt
+                      tsa_m(k,j,i) = tend(k,j,i)
+                   ENDDO
+                ELSEIF ( intermediate_timestep_count < &
+                         intermediate_timestep_count_max )  THEN
+                   DO  k = nzb_s_inner(j,i)+1, nzt
+                      tsa_m(k,j,i) = -9.5625 * tend(k,j,i) + &
+                                      5.3125 * tsa_m(k,j,i)
+                   ENDDO
+                ENDIF
+             ENDIF
+
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point(37), 'sa-equation', 'stop' )
+
+    ENDIF
+
+!
 !-- If required, compute prognostic equation for total water content / scalar
     IF ( humidity  .OR.  passive_scalar )  THEN
@@ -647,6 +737,7 @@
 ! be called for the standard Piascek-Williams advection scheme.
 !
-! The call of this subroutine is embedded in two DO loops over i and j, thus
-! communication between CPUs is not allowed in this subroutine.
+! Here the calls of most subroutines are embedded in two DO loops over i and j,
+! so communication between CPUs is not allowed (does not make sense) within
+! these loops.
 !
 ! (Optimized to avoid cache missings, i.e. for Power4/5-architectures.)
@@ -883,4 +974,51 @@
                    ENDDO
                 ENDIF
+             ENDIF
+
+!
+!--          If required, compute prognostic equation for salinity
+             IF ( ocean )  THEN
+
+!
+!--             Tendency-terms for salinity
+                tend(:,j,i) = 0.0
+                IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' ) &
+                THEN
+                   CALL advec_s_pw( i, j, sa )
+                ELSE
+                   CALL advec_s_up( i, j, sa )
+                ENDIF
+                CALL diffusion_s( i, j, ddzu, ddzw, kh, sa, saswsb, saswst, &
+                                  tend )
+       
+                CALL user_actions( i, j, 'sa-tendency' )
+
+!
+!--             Prognostic equation for salinity
+                DO  k = nzb_s_inner(j,i)+1, nzt
+                   sa_p(k,j,i) = tsc(1) * sa(k,j,i) +                          &
+                                 dt_3d * (                                     &
+                                  tsc(2) * tend(k,j,i) + tsc(3) * tsa_m(k,j,i) &
+                                         ) -                                   &
+                                tsc(5) * rdf(k) * ( sa(k,j,i) - sa_init(k) )
+                   IF ( sa_p(k,j,i) < 0.0 )  sa_p(k,j,i) = 0.1 * sa(k,j,i)
+                ENDDO
+
+!
+!--             Calculate tendencies for the next Runge-Kutta step
+                IF ( timestep_scheme(1:5) == 'runge' )  THEN
+                   IF ( intermediate_timestep_count == 1 )  THEN
+                      DO  k = nzb_s_inner(j,i)+1, nzt
+                         tsa_m(k,j,i) = tend(k,j,i)
+                      ENDDO
+                   ELSEIF ( intermediate_timestep_count < &
+                            intermediate_timestep_count_max )  THEN
+                      DO  k = nzb_s_inner(j,i)+1, nzt
+                         tsa_m(k,j,i) = -9.5625 * tend(k,j,i) + &
+                                         5.3125 * tsa_m(k,j,i)
+                      ENDDO
+                   ENDIF
+                ENDIF
+
              ENDIF
 
@@ -1363,4 +1501,96 @@
 
 !
+!-- If required, compute prognostic equation for salinity
+    IF ( ocean )  THEN
+
+       CALL cpu_log( log_point(37), 'sa-equation', 'start' )
+
+!
+!--    sa-tendency terms with communication
+       sat = tsc(1)
+       sbt = tsc(2)
+       IF ( scalar_advec == 'bc-scheme' )  THEN
+
+          IF ( timestep_scheme(1:5) /= 'runge' )  THEN
+!
+!--          Bott-Chlond scheme always uses Euler time step when leapfrog is
+!--          switched on. Thus:
+             sat = 1.0
+             sbt = 1.0
+          ENDIF
+          tend = 0.0
+          CALL advec_s_bc( sa, 'sa' )
+       ELSE
+          IF ( tsc(2) /= 2.0 )  THEN
+             IF ( scalar_advec == 'ups-scheme' )  THEN
+                tend = 0.0
+                CALL advec_s_ups( sa, 'sa' )
+             ENDIF
+          ENDIF
+       ENDIF
+
+!
+!--    Scalar/q-tendency terms with no communication
+       IF ( scalar_advec == 'bc-scheme' )  THEN
+          CALL diffusion_s( ddzu, ddzw, kh, sa, saswsb, saswst, tend )
+       ELSE
+          IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' )  THEN
+             tend = 0.0
+             CALL advec_s_pw( sa )
+          ELSE
+             IF ( scalar_advec /= 'ups-scheme' )  THEN
+                tend = 0.0
+                CALL advec_s_up( sa )
+             ENDIF
+          ENDIF
+          CALL diffusion_s( ddzu, ddzw, kh, sa, saswsb, saswst, tend )
+       ENDIF
+       
+       CALL user_actions( 'sa-tendency' )
+
+!
+!--    Prognostic equation for salinity
+       DO  i = nxl, nxr
+          DO  j = nys, nyn
+             DO  k = nzb_s_inner(j,i)+1, nzt
+                sa_p(k,j,i) = sat * sa(k,j,i) +                                &
+                              dt_3d * (                                        &
+                                     sbt * tend(k,j,i) + tsc(3) * tsa_m(k,j,i) &
+                                      ) -                                      &
+                              tsc(5) * rdf(k) * ( sa(k,j,i) - sa_init(k) )
+                IF ( sa_p(k,j,i) < 0.0 )  sa_p(k,j,i) = 0.1 * sa(k,j,i)
+             ENDDO
+          ENDDO
+       ENDDO
+
+!
+!--    Calculate tendencies for the next Runge-Kutta step
+       IF ( timestep_scheme(1:5) == 'runge' )  THEN
+          IF ( intermediate_timestep_count == 1 )  THEN
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb_s_inner(j,i)+1, nzt
+                      tsa_m(k,j,i) = tend(k,j,i)
+                   ENDDO
+                ENDDO
+             ENDDO
+          ELSEIF ( intermediate_timestep_count < &
+                   intermediate_timestep_count_max )  THEN
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb_s_inner(j,i)+1, nzt
+                      tsa_m(k,j,i) = -9.5625 * tend(k,j,i) + &
+                                      5.3125 * tsa_m(k,j,i)
+                   ENDDO
+                ENDDO
+             ENDDO
+          ENDIF
+       ENDIF
+
+       CALL cpu_log( log_point(37), 'sa-equation', 'stop' )
+
+    ENDIF
+
+!
 !-- If required, compute prognostic equation for total water content / scalar
     IF ( humidity  .OR.  passive_scalar )  THEN
