Index: palm/trunk/SOURCE/CURRENT_MODIFICATIONS
===================================================================
--- palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 148)
+++ palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 150)
@@ -21,7 +21,10 @@
 'read_data_for_recycling').
 
+Particle advection adjusted for ocean runs.
+
+
 User-defined spectra.
 
-calc_spectra, check_open, check_parameters, data_output_spectra, init_pegrid, init_3d_model, modules, netcdf, read_var_list, read_3d_binary, user_interface, write_var_list, write_3d_binary
+advec_particles, calc_spectra, check_open, check_parameters, data_output_spectra, init_particles, init_pegrid, init_3d_model, modules, netcdf, particle_boundary_conds, read_var_list, read_3d_binary, user_interface, write_var_list, write_3d_binary
 
 
@@ -63,4 +66,5 @@
 
 
+
 flow_statistics, local_stop, plant_canopy_model, read_3d_binary, user_interface, write_3d_binary
 
Index: palm/trunk/SOURCE/advec_particles.f90
===================================================================
--- palm/trunk/SOURCE/advec_particles.f90	(revision 148)
+++ palm/trunk/SOURCE/advec_particles.f90	(revision 150)
@@ -4,5 +4,6 @@
 ! Actual revisions:
 ! -----------------
-! 
+! Bottom boundary condition and vertical index calculations adjusted for
+! ocean runs.
 ! TEST: PRINT statements on unit 9 (commented out)
 !
@@ -207,5 +208,6 @@
           i = particles(n)%x * ddx
           j = particles(n)%y * ddy
-          k = ( particles(n)%z + 0.5 * dz ) / dz  ! only exact if equidistant
+          k = ( particles(n)%z + 0.5 * dz * atmos_ocean_sign ) / dz  &
+              + offset_ocean_nzt                     ! only exact if equidistant
 
           x  = particles(n)%x - i * dx
@@ -295,5 +297,6 @@
           i = ( particles(n)%x + 0.5 * dx ) * ddx
           j = ( particles(n)%y + 0.5 * dy ) * ddy
-          k = particles(n)%z / dz + 1  ! only exact if equidistant
+          k = particles(n)%z / dz + 1 + offset_ocean_nzt_m1
+              ! only exact if equidistant
 
           ql_c(k,j,i) = ql_c(k,j,i) + particles(n)%weight_factor *            &
@@ -832,5 +835,6 @@
           i = ( particles(n)%x + 0.5 * dx ) * ddx
           j =   particles(n)%y * ddy
-          k = ( particles(n)%z + 0.5 * dz ) / dz  ! only exact if equidistant
+          k = ( particles(n)%z + 0.5 * dz * atmos_ocean_sign ) / dz  &
+              + offset_ocean_nzt                     ! only exact if equidistant
                                                
 !
@@ -889,5 +893,5 @@
           IF ( vertical_particle_advection )  THEN
              j = particles(n)%y * ddy
-             k = particles(n)%z / dz
+             k = particles(n)%z / dz + offset_ocean_nzt_m1
 
              x  = particles(n)%x - i * dx
@@ -925,5 +929,6 @@
              i = particles(n)%x * ddx
              j = particles(n)%y * ddy
-             k = ( particles(n)%z + 0.5 * dz ) / dz  ! only exact if eq.dist
+             k = ( particles(n)%z + 0.5 * dz * atmos_ocean_sign ) / dz  &
+                 + offset_ocean_nzt                      ! only exact if eq.dist
 
              IF ( topography == 'flat' )  THEN        
@@ -3117,5 +3122,5 @@
              ENDIF
           ENDIF
-          IF ( particles(n)%z < 0.0  .AND.  particle_mask(n) )  THEN
+          IF ( particles(n)%z < zw(0)  .AND.  particle_mask(n) )  THEN
              IF ( ibc_par_b == 1 )  THEN
 !
@@ -3130,5 +3135,5 @@
 !
 !--             Particle reflection
-                particles(n)%z       = -particles(n)%z
+                particles(n)%z       = 2.0 * zw(0) - particles(n)%z
                 particles(n)%speed_z = -particles(n)%speed_z
                 IF ( use_sgs_for_particles  .AND. &
@@ -3141,6 +3146,6 @@
                 ENDIF
                 IF ( use_particle_tails  .AND.  nn /= 0 )  THEN
-                   particle_tail_coordinates(1,3,nn) = &
-                                              -particle_tail_coordinates(1,3,nn)
+                   particle_tail_coordinates(1,3,nn) = 2.0 * zw(0) - &
+                                               particle_tail_coordinates(1,3,nn)
                 ENDIF
              ENDIF
@@ -3883,5 +3888,6 @@
        i = ( particles(n)%x + 0.5 * dx ) * ddx
        j = ( particles(n)%y + 0.5 * dy ) * ddy
-       k = particles(n)%z / dz + 1  ! only exact if equidistant
+       k = particles(n)%z / dz + 1 + offset_ocean_nzt_m1
+           ! only exact if equidistant
 
        prt_count(k,j,i) = prt_count(k,j,i) + 1
@@ -3917,5 +3923,6 @@
        i = ( particles(n)%x + 0.5 * dx ) * ddx
        j = ( particles(n)%y + 0.5 * dy ) * ddy
-       k = particles(n)%z / dz + 1  ! only exact if equidistant
+       k = particles(n)%z / dz + 1 + offset_ocean_nzt_m1
+           ! only exact if equidistant
 
        particles_temp(prt_start_index(k,j,i)) = particles(n)
Index: palm/trunk/SOURCE/init_particles.f90
===================================================================
--- palm/trunk/SOURCE/init_particles.f90	(revision 148)
+++ palm/trunk/SOURCE/init_particles.f90	(revision 150)
@@ -4,5 +4,5 @@
 ! Actual revisions:
 ! -----------------
-! 
+! Set offset_ocean_* needed for calculating vertical indices within ocean runs
 !
 ! Former revisions:
@@ -79,4 +79,13 @@
     CALL MPI_TYPE_COMMIT( mpi_particle_type, ierr )
 #endif
+
+!
+!-- In case of oceans runs, the vertical index calculations need an offset,
+!-- because otherwise the k indices will become negative
+    IF ( ocean )  THEN
+       offset_ocean_nzt    = nzt
+       offset_ocean_nzt_m1 = nzt - 1
+    ENDIF
+
 
 !
Index: palm/trunk/SOURCE/modules.f90
===================================================================
--- palm/trunk/SOURCE/modules.f90	(revision 148)
+++ palm/trunk/SOURCE/modules.f90	(revision 150)
@@ -6,5 +6,5 @@
 ! -----------------
 ! +hor_index_bounds, hor_index_bounds_previous_run, numprocs_previous_run,
-! nx_on_file, ny_on_file
+! nx_on_file, ny_on_file, offset_ocean_*
 ! -myid_char_14
 !
@@ -880,5 +880,6 @@
                 number_of_initial_particles = 0, number_of_particles = 0,      &
                 number_of_particle_groups = 1, number_of_tails = 0,            &
-                number_of_initial_tails = 0, particles_per_point = 1,          &
+                number_of_initial_tails = 0, offset_ocean_nzt = 0,             &
+                offset_ocean_nzt_m1 = 0, particles_per_point = 1,              &
                 particle_file_count = 0, skip_particles_for_tail = 100,        &
                 total_number_of_particles, total_number_of_tails = 0
Index: palm/trunk/SOURCE/particle_boundary_conds.f90
===================================================================
--- palm/trunk/SOURCE/particle_boundary_conds.f90	(revision 148)
+++ palm/trunk/SOURCE/particle_boundary_conds.f90	(revision 150)
@@ -4,5 +4,5 @@
 ! Actual revisions:
 ! -----------------
-! 
+! Vertical index calculations adjusted for ocean runs.
 !
 ! Former revisions:
@@ -18,4 +18,5 @@
 !        reflection conditions is basically the same for all four cases, so it
 !        should be possible to further simplify/shorten it.
+! THIS ROUTINE HAS NOT BEEN TESTED FOR OCEAN RUNS SO FAR! (see offset_ocean_*)
 !------------------------------------------------------------------------------!
 
@@ -54,5 +55,5 @@
        i2 = ( particles(n)%x + 0.5 * dx ) * ddx
        j2 = ( particles(n)%y + 0.5 * dy ) * ddy
-       k2 = particles(n)%z / dz + 1
+       k2 = particles(n)%z / dz + 1 + offset_ocean_nzt_m1
 
        prt_x = particles(n)%x
@@ -69,5 +70,5 @@
           i1 = ( pos_x_old + 0.5 * dx ) * ddx
           j1 = ( pos_y_old + 0.5 * dy ) * ddy
-          k1 = pos_z_old / dz
+          k1 = pos_z_old / dz + offset_ocean_nzt_m1
 
 !
@@ -132,9 +133,9 @@
                 i3 = ( pos_x + 0.5 * dx ) * ddx   
                 j3 = ( pos_y + 0.5 * dy ) * ddy
-                k3 = pos_z / dz
+                k3 = pos_z / dz + offset_ocean_nzt_m1
 
                 i5 = pos_x * ddx
                 j5 = pos_y * ddy
-                k5 = pos_z / dz
+                k5 = pos_z / dz + offset_ocean_nzt_m1
 
                 IF ( k5 <= nzb_s_inner(j5,i3)  .AND. &
@@ -246,9 +247,9 @@
                 i3 = ( pos_x + 0.5 * dx ) * ddx
                 j3 = ( pos_y + 0.5 * dy ) * ddy
-                k3 = pos_z / dz
+                k3 = pos_z / dz + offset_ocean_nzt_m1
 
                 i5 = pos_x * ddx
                 j5 = pos_y * ddy
-                k5 = pos_z / dz
+                k5 = pos_z / dz + offset_ocean_nzt_m1
 
                 IF ( k5 <= nzb_s_inner(j3,i5)  .AND. &
@@ -361,9 +362,9 @@
                 i3 = ( pos_x + 0.5 * dx ) * ddx
                 j3 = ( pos_y + 0.5 * dy ) * ddy
-                k3 =  pos_z / dz
+                k3 = pos_z / dz + offset_ocean_nzt_m1
 
                 i5 = pos_x * ddx
                 j5 = pos_y * ddy
-                k5 = pos_z / dz
+                k5 = pos_z / dz + offset_ocean_nzt_m1
 
                 IF ( k5 <= nzb_s_inner(j5,i3)  .AND. &
@@ -476,9 +477,9 @@
                 i3 = ( pos_x + 0.5 * dx ) * ddx   
                 j3 = ( pos_y + 0.5 * dy ) * ddy
-                k3 = pos_z / dz
+                k3 = pos_z / dz + offset_ocean_nzt_m1
 
                 i5 = pos_x * ddx
                 j5 = pos_y * ddy
-                k5 = pos_z / dz
+                k5 = pos_z / dz + offset_ocean_nzt_m1
 
                 IF ( k3 <= nzb_s_inner(j3,i3)  .AND. &
Index: palm/trunk/SOURCE/read_3d_binary.f90
===================================================================
--- palm/trunk/SOURCE/read_3d_binary.f90	(revision 148)
+++ palm/trunk/SOURCE/read_3d_binary.f90	(revision 150)
@@ -63,5 +63,5 @@
     CHARACTER (LEN=20) ::  field_chr
 
-    INTEGER ::  files_to_be_opened, i, idum1, j, myid_on_file,                &
+    INTEGER ::  files_to_be_opened, i, j, myid_on_file,                       &
                 numprocs_on_file, nxlc, nxlf, nxlpr, nxl_on_file, nxrc, nxrf, &
                 nxrpr, nxr_on_file, nync, nynf, nynpr, nyn_on_file, nysc,     &
