Index: palm/trunk/SOURCE/boundary_conds.f90
===================================================================
--- palm/trunk/SOURCE/boundary_conds.f90	(revision 1991)
+++ palm/trunk/SOURCE/boundary_conds.f90	(revision 1992)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Adjustments for top boundary condition for passive scalar
 ! 
 ! Former revisions:
@@ -259,5 +259,5 @@
     ELSEIF ( ibc_pt_t == 2 )  THEN
        !$acc kernels present( dzu, pt_p )
-        pt_p(nzt+1,:,:) = pt_p(nzt,:,:)   + bc_pt_t_val * dzu(nzt+1)
+        pt_p(nzt+1,:,:) = pt_p(nzt,:,:) + bc_pt_t_val * dzu(nzt+1)
        !$acc end kernels
     ENDIF
@@ -327,5 +327,5 @@
           q_p(nzt+1,:,:) = q(nzt+1,:,:)
        ELSEIF ( ibc_q_t == 1 ) THEN
-          q_p(nzt+1,:,:) = q_p(nzt,:,:)   + bc_q_t_val * dzu(nzt+1)
+          q_p(nzt+1,:,:) = q_p(nzt,:,:) + bc_q_t_val * dzu(nzt+1)
        ENDIF
 
@@ -366,9 +366,11 @@
        ENDIF
 !
-!--    Top boundary
-       IF ( ibc_s_t == 0 ) THEN
+!--    Top boundary condition
+       IF ( ibc_s_t == 0 )  THEN
           s_p(nzt+1,:,:) = s(nzt+1,:,:)
-       ELSEIF ( ibc_s_t == 1 ) THEN
-          s_p(nzt+1,:,:) = s_p(nzt,:,:)   + bc_s_t_val * dzu(nzt+1)
+       ELSEIF ( ibc_s_t == 1 )  THEN
+          s_p(nzt+1,:,:) = s_p(nzt,:,:)
+       ELSEIF ( ibc_s_t == 2 )  THEN
+          s_p(nzt+1,:,:) = s_p(nzt,:,:) + bc_s_t_val * dzu(nzt+1)
        ENDIF
 
Index: palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- palm/trunk/SOURCE/check_parameters.f90	(revision 1991)
+++ palm/trunk/SOURCE/check_parameters.f90	(revision 1992)
@@ -19,5 +19,6 @@
 ! Current revisions:
 ! -----------------
-! 
+! New checks for top_scalarflux
+! Bugfixes concerning data output of profiles in case of passive_scalar
 ! 
 ! Former revisions:
@@ -1706,5 +1707,5 @@
           message_string = 'boundary condition: bc_sa_t = "' //                &
                            TRIM( bc_sa_t ) // '" is not allowed with ' //      &
-                           'constant_top_salinityflux = .TRUE.'
+                           'top_salinityflux /= 0.0'
           CALL message( 'check_parameters', 'PA0070', 1, 2, 0, 6, 0 )
        ENDIF
@@ -1749,4 +1750,17 @@
        CALL check_bc_scalars( 's', bc_s_b, ibc_s_b, 'PA0073', 'PA0074',        &
                               constant_scalarflux, s_surface_initial_change )
+
+       IF ( top_scalarflux == 9999999.9_wp )  constant_top_scalarflux = .FALSE.
+!
+!--    A fixed scalar concentration at the top implies Dirichlet boundary
+!--    condition for scalar. Hence, in this case specification of a constant 
+!--    scalar flux is forbidden.
+       IF ( ( ibc_s_t == 0 .OR. ibc_s_t == 2 )  .AND.  constant_top_scalarflux &
+               .AND.  top_scalarflux /= 0.0_wp )  THEN
+          message_string = 'boundary condition: bc_s_t = "' //                 &
+                           TRIM( bc_sa_t ) // '" is not allowed with ' //      &
+                           'top_scalarflux /= 0.0'
+          CALL message( 'check_parameters', 'PA0441', 1, 2, 0, 6, 0 )
+       ENDIF
     ENDIF
 !
@@ -2210,11 +2224,11 @@
                 CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
              ELSE
-                dopr_index(i) = 41
+                dopr_index(i) = 117
                 dopr_unit(i)  = 'kg/m3'
-                hom(:,2,41,:) = SPREAD( zu, 2, statistic_regions+1 )
+                hom(:,2,117,:) = SPREAD( zu, 2, statistic_regions+1 )
                 IF ( data_output_pr(i)(1:1) == '#' )  THEN
-                   dopr_initial_index(i) = 26
-                   hom(:,2,26,:)         = SPREAD( zu, 2, statistic_regions+1 )
-                   hom(nzb,2,26,:)       = 0.0_wp    ! because zu(nzb) is negative
+                   dopr_initial_index(i) = 117
+                   hom(:,2,117,:)        = SPREAD( zu, 2, statistic_regions+1 )
+                   hom(nzb,2,117,:)      = 0.0_wp    ! because zu(nzb) is negative
                    data_output_pr(i)     = data_output_pr(i)(2:)
                 ENDIF
@@ -2331,7 +2345,7 @@
                 CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
              ELSE
-                dopr_index(i) = 48
+                dopr_index(i) = 119
                 dopr_unit(i)  = 'kg/m3 m/s'
-                hom(:,2,48,:) = SPREAD( zw, 2, statistic_regions+1 )
+                hom(:,2,119,:) = SPREAD( zw, 2, statistic_regions+1 )
              ENDIF
 
@@ -2343,7 +2357,7 @@
                 CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
              ELSE
-                dopr_index(i) = 49
+                dopr_index(i) = 116
                 dopr_unit(i)  = 'kg/m3 m/s'
-                hom(:,2,49,:) = SPREAD( zw, 2, statistic_regions+1 )
+                hom(:,2,116,:) = SPREAD( zw, 2, statistic_regions+1 )
              ENDIF
 
@@ -2355,7 +2369,7 @@
                 CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
              ELSE
-                dopr_index(i) = 50
+                dopr_index(i) = 120
                 dopr_unit(i)  = 'kg/m3 m/s'
-                hom(:,2,50,:) = SPREAD( zw, 2, statistic_regions+1 )
+                hom(:,2,120,:) = SPREAD( zw, 2, statistic_regions+1 )
              ENDIF
 
@@ -3916,4 +3930,6 @@
        ELSEIF ( bc_t == 'neumann' )  THEN
           ibc_t = 1
+       ELSEIF ( bc_t == 'initial_gradient' )  THEN
+          ibc_t = 2
        ELSEIF ( bc_t == 'nested' )  THEN
           ibc_t = 3
Index: palm/trunk/SOURCE/close_file.f90
===================================================================
--- palm/trunk/SOURCE/close_file.f90	(revision 1991)
+++ palm/trunk/SOURCE/close_file.f90	(revision 1992)
@@ -19,5 +19,6 @@
 ! Current revisions:
 ! -----------------
-! 
+! -Close file containing flight data
+! -Some tabs removed.
 !
 ! Former revisions:
@@ -85,6 +86,6 @@
     USE netcdf_interface,                                                      &
         ONLY:  id_set_mask, id_set_pr, id_set_prt, id_set_pts, id_set_sp,      &
-               id_set_ts, id_set_xy, id_set_xz, id_set_yz, id_set_3d, nc_stat, &
-               netcdf_data_format, netcdf_handle_error
+               id_set_ts, id_set_xy, id_set_xz, id_set_yz, id_set_3d,          &
+               id_set_fl, nc_stat, netcdf_data_format, netcdf_handle_error
                 
     USE pegrid                                           
@@ -223,6 +224,13 @@
                 ENDIF
 
+             CASE ( 199 )
+
+                IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
+                   nc_stat = NF90_CLOSE( id_set_fl )
+                   CALL netcdf_handle_error( 'close_file', 353 )
+                ENDIF
+
              CASE ( 201:200+2*max_masks )
-	     
+
                 IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
 !
@@ -237,5 +245,5 @@
                    nc_stat = NF90_CLOSE( id_set_mask(mid,av) )
                    CALL netcdf_handle_error( 'close_file', 459 )
-		
+
                 ENDIF
 
Index: palm/trunk/SOURCE/header.f90
===================================================================
--- palm/trunk/SOURCE/header.f90	(revision 1991)
+++ palm/trunk/SOURCE/header.f90	(revision 1992)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Adapted for top_scalarflux
 ! 
 ! Former revisions:
@@ -1017,10 +1017,10 @@
 
        ELSE
-          r_lower = 'q(0)     = q(1)'
+          r_lower = 'q(0)      = q(1)'
        ENDIF
        IF ( ibc_q_t == 0 )  THEN
-          r_upper =  'q(nzt)   = q_top'
+          r_upper =  'q(nzt+1) = q_top'
        ELSE
-          r_upper =  'q(nzt)   = q(nzt-1) + dq/dz'
+          r_upper =  'q(nzt+1) = q(nzt) + dq/dz'
        ENDIF
        WRITE ( io, 301 ) 'q', r_lower, r_upper
@@ -1029,12 +1029,14 @@
     IF ( passive_scalar )  THEN
        IF ( ibc_s_b == 0 )  THEN
-          r_lower = 's(0)     = s_surface'
+          r_lower = 's(0)      = s_surface'
        ELSE
-          r_lower = 's(0)     = s(1)'
+          r_lower = 's(0)      = s(1)'
        ENDIF
        IF ( ibc_s_t == 0 )  THEN
-          r_upper =  's(nzt)   = s_top'
-       ELSE
-          r_upper =  's(nzt)   = s(nzt-1) + ds/dz'
+          r_upper =  's(nzt+1) = s_top'
+       ELSEIF ( ibc_s_t == 1 )  THEN
+          r_upper =  's(nzt+1) = s(nzt)'
+       ELSEIF ( ibc_s_t == 2 )  THEN
+          r_upper =  's(nzt+1) = s(nzt) + ds/dz'
        ENDIF
        WRITE ( io, 301 ) 's', r_lower, r_upper
@@ -1073,9 +1075,9 @@
           WRITE ( io, 316 )
        ENDIF
-       IF ( ocean  .AND.  constant_top_salinityflux )  THEN
+       IF ( ocean  .AND.  constant_top_salinityflux )                          &
           WRITE ( io, 309 )  top_salinityflux
-       ENDIF
        IF ( humidity       )  WRITE ( io, 315 )
-       IF ( passive_scalar )  WRITE ( io, 315 )
+       IF ( passive_scalar .AND.  constant_top_scalarflux )                    &
+          WRITE ( io, 302 ) top_scalarflux
     ENDIF
 
@@ -2033,5 +2035,6 @@
 313 FORMAT ('       Predefined constant scalar flux: ',E10.3,' kg/(m**2 s)')
 314 FORMAT ('       Predefined scalar value at the surface')
-315 FORMAT ('       Humidity / scalar flux at top surface is 0.0')
+302 FORMAT ('       Predefined constant scalarflux:   ',F9.6,' kg/(m**2 s)')
+315 FORMAT ('       Humidity flux at top surface is 0.0')
 316 FORMAT ('       Sensible heatflux and momentum flux from coupled ', &
                     'atmosphere model')
Index: palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- palm/trunk/SOURCE/init_3d_model.f90	(revision 1991)
+++ palm/trunk/SOURCE/init_3d_model.f90	(revision 1992)
@@ -19,5 +19,7 @@
 ! Current revisions:
 ! ------------------
-! 
+! Initializaton of scalarflux at model top
+! Bugfixes in initialization of surface and top salinity flux, top scalar and 
+! humidity fluxes
 ! 
 ! Former revisions:
@@ -1205,5 +1207,8 @@
                 ENDIF
              ENDIF
-          ENDIF          
+          ENDIF    
+!
+!--       Initialize near-surface salinity flux
+          IF ( ocean )  saswsb = bottom_salinityflux
 
        ENDIF
@@ -1214,25 +1219,24 @@
 !--    The latent flux is zero in this case!
        IF ( use_top_fluxes )  THEN
-
-          IF ( constant_top_heatflux )  THEN
-!
-!--          Heat flux is prescribed
-             tswst = top_heatflux
-
-             IF ( humidity )  THEN
-                qswst = 0.0_wp
-                IF ( cloud_physics  .AND.  microphysics_seifert ) THEN
-                   nrswst = 0.0_wp
-                   qrswst = 0.0_wp
-                ENDIF
+!
+!--       Prescribe to heat flux
+          IF ( constant_top_heatflux )  tswst = top_heatflux
+!
+!--       Prescribe zero latent flux at the top      
+          IF ( humidity )  THEN
+             qswst = 0.0_wp
+             IF ( cloud_physics  .AND.  microphysics_seifert ) THEN
+                nrswst = 0.0_wp
+                qrswst = 0.0_wp
              ENDIF
-             IF ( passive_scalar )  sswst = 0.0_wp
-
-             IF ( ocean )  THEN
-                saswsb = bottom_salinityflux
-                saswst = top_salinityflux
-             ENDIF
-          ENDIF
-
+          ENDIF
+!
+!--       Prescribe top scalar flux
+          IF ( passive_scalar .AND. constant_top_scalarflux )                  &
+             sswst = top_scalarflux
+!
+!--       Prescribe top salinity flux
+          IF ( ocean .AND. constant_top_salinityflux)                          &
+             saswst = top_salinityflux
 !
 !--       Initialization in case of a coupled model run
Index: palm/trunk/SOURCE/modules.f90
===================================================================
--- palm/trunk/SOURCE/modules.f90	(revision 1991)
+++ palm/trunk/SOURCE/modules.f90	(revision 1992)
@@ -19,5 +19,6 @@
 ! Current revisions:
 ! ------------------
-! 
+! +constant_top_scalarflux, top_scalarflux
+! default of bc_s_t adjusted
 ! 
 ! Former revisions:
@@ -603,5 +604,5 @@
                              bc_pt_t = 'initial_gradient', &
                              bc_q_b = 'dirichlet', bc_q_t = 'neumann', &
-                             bc_s_b = 'dirichlet', bc_s_t = 'neumann', &
+                             bc_s_b = 'dirichlet', bc_s_t = 'initial_gradient', &
                              bc_sa_t = 'neumann', &
                              bc_uv_b = 'dirichlet', bc_uv_t = 'dirichlet', &
@@ -701,4 +702,5 @@
                 constant_top_momentumflux = .FALSE., &
                 constant_top_salinityflux = .TRUE., &
+                constant_top_scalarflux = .TRUE., &
                 constant_scalarflux = .TRUE., &              
                 constant_waterflux = .TRUE., create_disturbances = .TRUE., &
@@ -818,4 +820,5 @@
                  top_momentumflux_u = 9999999.9_wp, &
                  top_momentumflux_v = 9999999.9_wp, top_salinityflux = 9999999.9_wp, &
+                 top_scalarflux = 9999999.9_wp, &
                  ug_surface = 0.0_wp, u_bulk = 0.0_wp, u_gtrans = 0.0_wp, &
                  vg_surface = 0.0_wp, vpt_reference = 9999999.9_wp, &
Index: palm/trunk/SOURCE/parin.f90
===================================================================
--- palm/trunk/SOURCE/parin.f90	(revision 1991)
+++ palm/trunk/SOURCE/parin.f90	(revision 1992)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! +top_scalarflux
 ! 
 ! Former revisions:
@@ -340,5 +340,5 @@
              topography, topography_grid_convention, top_heatflux,             &
              top_momentumflux_u, top_momentumflux_v, top_salinityflux,         &
-             transpose_compute_overlap, turbulent_inflow,                      &
+             top_scalarflux, transpose_compute_overlap, turbulent_inflow,      &
              use_subsidence_tendencies, ug_surface, ug_vertical_gradient,      &
              ug_vertical_gradient_level, use_surface_fluxes, use_cmax,         &
Index: palm/trunk/SOURCE/read_var_list.f90
===================================================================
--- palm/trunk/SOURCE/read_var_list.f90	(revision 1991)
+++ palm/trunk/SOURCE/read_var_list.f90	(revision 1992)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! top_scalarflux added
 ! 
 ! Former revisions:
@@ -689,4 +689,6 @@
           CASE ( 'top_salinityflux' )
              READ ( 13 )  top_salinityflux
+          CASE ( 'top_scalarflux' )
+             READ ( 13 )  top_scalarflux
           CASE ( 'tsc' )
              READ ( 13 )  tsc
Index: palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 1991)
+++ palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 1992)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Bugfix in summation of passive scalar
 ! 
 ! Former revisions:
@@ -110,5 +110,5 @@
     USE arrays_3d,                                                             &
         ONLY:  dzw, e, nr, ol, p, pt, precipitation_rate, q, qc, ql, ql_c,     &
-               ql_v, qr, qsws, rho, sa, shf, ssws, ts, u, us, v, vpt, w, z0,   &
+               ql_v, qr, qsws, rho, s, sa, shf, ssws, ts, u, us, v, vpt, w, z0,&
                z0h, z0q
 
@@ -619,5 +619,5 @@
                 DO  j = nysg, nyng
                    DO  k = nzb, nzt+1
-                      s_av(k,j,i) = s_av(k,j,i) + q(k,j,i)
+                      s_av(k,j,i) = s_av(k,j,i) + s(k,j,i)
                    ENDDO
                 ENDDO
Index: palm/trunk/SOURCE/surface_layer_fluxes_mod.f90
===================================================================
--- palm/trunk/SOURCE/surface_layer_fluxes_mod.f90	(revision 1991)
+++ palm/trunk/SOURCE/surface_layer_fluxes_mod.f90	(revision 1992)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! Minor bug, declaration of look-up index as INTEGER
 ! 
 ! Former revisions:
@@ -179,7 +179,8 @@
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i            !< loop index x direction
-    INTEGER(iwp) ::  j            !< loop index y direction
-    INTEGER(iwp) ::  k            !< loop index z direction
+    INTEGER(iwp) ::  i              !< loop index x direction
+    INTEGER(iwp) ::  j              !< loop index y direction
+    INTEGER(iwp) ::  k              !< loop index z direction
+    INTEGER(iwp) ::  l_bnd  = 7500  !< Lookup table index of the last time step
 
     INTEGER(iwp), PARAMETER     :: num_steps = 15000  !< number of steps in the lookup table
@@ -195,5 +196,4 @@
 
     REAL(wp)     ::  e_s,               & !< Saturation water vapor pressure
-                     l_bnd  = 7500,     & !< Lookup table index of the last time step
                      ol_max = 1.0E6_wp, & !< Maximum Obukhov length
                      rib_max,           & !< Maximum Richardson number in lookup table
Index: palm/trunk/SOURCE/write_var_list.f90
===================================================================
--- palm/trunk/SOURCE/write_var_list.f90	(revision 1991)
+++ palm/trunk/SOURCE/write_var_list.f90	(revision 1992)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! top scalarflux added 
 !
 ! Former revisions:
@@ -600,4 +600,6 @@
     WRITE ( 14 )  'top_salinityflux              '
     WRITE ( 14 )  top_salinityflux
+    WRITE ( 14 )  'top_scalarflux                '
+    WRITE ( 14 )  top_scalarflux
     WRITE ( 14 )  'tsc                           '
     WRITE ( 14 )  tsc
