Index: /palm/trunk/SOURCE/modules.f90
===================================================================
--- /palm/trunk/SOURCE/modules.f90	(revision 3197)
+++ /palm/trunk/SOURCE/modules.f90	(revision 3198)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Added multi_agent_system_end and multi_agent_system_start
+! 
+! 3183 2018-07-27 14:25:55Z suehring
 ! Rename offline nesting variables:
 ! -inflow_l, inflow_n, inflow_r, inflow_s, 
@@ -1470,4 +1473,6 @@
     REAL(wp) ::  maximum_cpu_time_allowed = 0.0_wp             !< given wall time for run
     REAL(wp) ::  molecular_viscosity = 1.461E-5_wp             !< molecular viscosity (used in lsm and lpm)
+    REAL(wp) ::  multi_agent_system_end   = 9999999.9_wp       !< namelist parameter (see documentation)
+    REAL(wp) ::  multi_agent_system_start = 0.0_wp             !< namelist parameter (see documentation)
     REAL(wp) ::  old_dt = 1.0E-10_wp                           !< length of previous timestep
     REAL(wp) ::  omega = 7.29212E-5_wp                         !< namelist parameter
Index: /palm/trunk/SOURCE/multi_agent_system_mod.f90
===================================================================
--- /palm/trunk/SOURCE/multi_agent_system_mod.f90	(revision 3197)
+++ /palm/trunk/SOURCE/multi_agent_system_mod.f90	(revision 3198)
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$
+! Now using time_since_reference_point; moved multi_agent_system_start and
+! multi_agent_system_end to control_parameters; renamed NAMELIST agents_par to
+! agent_parameters
+! 
+! 3187 2018-07-31 10:32:34Z sward
 ! Reworked agent pathfinding to avoid collisions with walls
 ! 
@@ -56,5 +61,5 @@
 
     USE control_parameters,                                                    &
-        ONLY:  dt_3d, message_string, simulated_time, dt_write_agent_data
+        ONLY:  dt_3d, message_string, time_since_reference_point, dt_write_agent_data
 
     USE cpulog,                                                                &
@@ -121,34 +126,33 @@
     LOGICAL, DIMENSION(max_number_of_agent_groups) ::  a_rand_target = .FALSE. !< namelist parameter (see documentation)
 
-    REAL(wp) ::  agent_maximum_age = 9999999.9_wp    !< namelist parameter (see documentation)
-    REAL(wp) ::  alloc_factor_mas = 20.0_wp          !< namelist parameter (see documentation)
-    REAL(wp) ::  coll_t_0 = 3.                       !< namelist parameter (see documentation)
-    REAL(wp) ::  corner_gate_start = 0.5_wp          !< namelist parameter (see documentation)
-    REAL(wp) ::  corner_gate_width = 1.0_wp          !< namelist parameter (see documentation)    
-    REAL(wp) ::  d_sigma_rep_agent                   !< inverse of sigma_rep_agent
-    REAL(wp) ::  d_sigma_rep_wall                    !< inverse of sigma_rep_wall
-    REAL(wp) ::  d_tau_accel_agent                   !< inverse of tau_accel_agent
-    REAL(wp) ::  desired_speed = 1.2_wp              !< namelist parameter (see documentation)
-    REAL(wp) ::  des_sp_sig = .2_wp                  !< namelist parameter (see documentation)
-    REAL(wp) ::  dist_target_reached = 2.0_wp        !< distance at which target counts as reached
-    REAL(wp) ::  dist_to_int_target = .25_wp         !< namelist parameter (see documentation)
-    REAL(wp) ::  dt_agent = 0.02_wp                  !< namelist parameter (see documentation)
-    REAL(wp) ::  dt_arel = 9999999.9_wp              !< namelist parameter (see documentation)
-    REAL(wp) ::  end_time_arel = 9999999.9_wp        !< namelist parameter (see documentation)
-    REAL(wp) ::  force_x                             !< dummy value for force on current agent in x-direction
-    REAL(wp) ::  force_y                             !< dummy value for force on current agent in y-direction
-    REAL(wp) ::  max_dist_from_path = 0.25_wp        !< distance from current path at which a new path is calculated
-    REAL(wp) ::  multi_agent_system_start = 0.0_wp   !< namelist parameter (see documentation)
-    REAL(wp) ::  radius_agent = .25_wp               !< namelist parameter (see documentation)
-    REAL(wp) ::  repuls_agent = 1.5_wp               !< namelist parameter (see documentation)
-    REAL(wp) ::  repuls_wall = 7.0_wp                !< namelist parameter (see documentation)
-    REAL(wp) ::  scan_radius_agent = 3.0_wp          !< namelist parameter (see documentation)
-    REAL(wp) ::  scan_radius_wall = 2.0_wp           !< namelist parameter (see documentation)
-    REAL(wp) ::  sigma_rep_agent = 0.3_wp            !< namelist parameter (see documentation)
-    REAL(wp) ::  sigma_rep_wall = 0.1_wp             !< namelist parameter (see documentation)
-    REAL(wp) ::  tau_accel_agent = 0.5_wp            !< namelist parameter (see documentation)
-    REAL(wp) ::  time_arel = 0.0_wp                  !< time for agent release
-    REAL(wp) ::  time_write_agent_data = 0.0_wp      !< write agent data at current time on file
-    REAL(wp) ::  v_max_agent = 1.3_wp                !< namelist parameter (see documentation)
+    REAL(wp) ::  agent_maximum_age = 9999999.9_wp          !< namelist parameter (see documentation)
+    REAL(wp) ::  alloc_factor_mas = 20.0_wp                !< namelist parameter (see documentation)
+    REAL(wp) ::  coll_t_0 = 3.                             !< namelist parameter (see documentation)
+    REAL(wp) ::  corner_gate_start = 0.5_wp                !< namelist parameter (see documentation)
+    REAL(wp) ::  corner_gate_width = 1.0_wp                !< namelist parameter (see documentation)    
+    REAL(wp) ::  d_sigma_rep_agent                         !< inverse of sigma_rep_agent
+    REAL(wp) ::  d_sigma_rep_wall                          !< inverse of sigma_rep_wall
+    REAL(wp) ::  d_tau_accel_agent                         !< inverse of tau_accel_agent
+    REAL(wp) ::  desired_speed = 1.2_wp                    !< namelist parameter (see documentation)
+    REAL(wp) ::  des_sp_sig = .2_wp                        !< namelist parameter (see documentation)
+    REAL(wp) ::  dist_target_reached = 2.0_wp              !< distance at which target counts as reached
+    REAL(wp) ::  dist_to_int_target = .25_wp               !< namelist parameter (see documentation)
+    REAL(wp) ::  dt_agent = 0.02_wp                        !< namelist parameter (see documentation)
+    REAL(wp) ::  dt_arel = 9999999.9_wp                    !< namelist parameter (see documentation)
+    REAL(wp) ::  end_time_arel = 9999999.9_wp              !< namelist parameter (see documentation)
+    REAL(wp) ::  force_x                                   !< dummy value for force on current agent in x-direction
+    REAL(wp) ::  force_y                                   !< dummy value for force on current agent in y-direction
+    REAL(wp) ::  max_dist_from_path = 0.25_wp              !< distance from current path at which a new path is calculated
+    REAL(wp) ::  radius_agent = .25_wp                     !< namelist parameter (see documentation)
+    REAL(wp) ::  repuls_agent = 1.5_wp                     !< namelist parameter (see documentation)
+    REAL(wp) ::  repuls_wall = 7.0_wp                      !< namelist parameter (see documentation)
+    REAL(wp) ::  scan_radius_agent = 3.0_wp                !< namelist parameter (see documentation)
+    REAL(wp) ::  scan_radius_wall = 2.0_wp                 !< namelist parameter (see documentation)
+    REAL(wp) ::  sigma_rep_agent = 0.3_wp                  !< namelist parameter (see documentation)
+    REAL(wp) ::  sigma_rep_wall = 0.1_wp                   !< namelist parameter (see documentation)
+    REAL(wp) ::  tau_accel_agent = 0.5_wp                  !< namelist parameter (see documentation)
+    REAL(wp) ::  time_arel = 0.0_wp                        !< time for agent release
+    REAL(wp) ::  time_write_agent_data = 0.0_wp            !< write agent data at current time on file
+    REAL(wp) ::  v_max_agent = 1.3_wp                      !< namelist parameter (see documentation)
 
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  dummy_path_x  !<  dummy path (x-coordinate)
@@ -269,5 +273,5 @@
 !
 !-- Public parameters, constants and initial values
-    PUBLIC agents_active, multi_agent_system_start
+    PUBLIC agents_active
 
     INTERFACE mas_parin
@@ -318,5 +322,5 @@
 !
 !-- If necessary, release new set of agents
-    IF ( time_arel >= dt_arel  .AND.  end_time_arel > simulated_time )  THEN
+    IF ( time_arel >= dt_arel  .AND.  end_time_arel > time_since_reference_point )  THEN
 
        CALL mas_create_agent(PHASE_RELEASE)
@@ -1223,5 +1227,5 @@
 
           nc_stat = NF90_PUT_VAR( id_set_agt, id_var_time_agt, &
-                                  (/ simulated_time /),        &
+                                  (/ time_since_reference_point /),        &
                                   start = (/ agt_time_count /), count = (/ 1 /) )
           CALL netcdf_handle_error( 'mas_data_output_agents', 1 )
@@ -3638,5 +3642,6 @@
 
        USE control_parameters,                                                 &
-           ONLY: agent_time_unlimited
+           ONLY: agent_time_unlimited, multi_agent_system_end,                 &
+                 multi_agent_system_start
 
        IMPLICIT NONE
@@ -3644,16 +3649,42 @@
        CHARACTER (LEN=80) ::  line  !<
 
-       NAMELIST /agents_par/  a_rand_target, adx, ady, agent_maximum_age,      &
-                              agent_time_unlimited, alloc_factor_mas, asl, asn,&
-                              asr, ass, at_x, at_y, bc_mas_lr, bc_mas_ns,      &
-                              coll_t_0, corner_gate_start, corner_gate_width,  &
-                              deallocate_memory_mas, dist_to_int_target,       &
-                              dt_agent, dt_arel, dt_write_agent_data,&
-                              end_time_arel, max_dist_from_path, min_nr_agent, &
-                              multi_agent_system_start, number_of_agent_groups,&
-                              radius_agent, random_start_position_agents,      &
-                              read_agents_from_restartfile, repuls_agent,      &
-                              repuls_wall, scan_radius_agent, sigma_rep_agent, &
-                              sigma_rep_wall, step_dealloc_mas, tau_accel_agent
+       NAMELIST /agent_parameters/  a_rand_target,                             &
+                                    adx,                                       &
+                                    ady,                                       &
+                                    agent_maximum_age,                         &
+                                    agent_time_unlimited,                      &
+                                    alloc_factor_mas,                          &
+                                    asl,                                       &
+                                    asn,                                       &
+                                    asr,                                       &
+                                    ass,                                       &
+                                    at_x,                                      &
+                                    at_y,                                      &
+                                    bc_mas_lr,                                 &
+                                    bc_mas_ns,                                 &
+                                    coll_t_0,                                  &
+                                    corner_gate_start,                         &
+                                    corner_gate_width,                         &
+                                    deallocate_memory_mas,                     &
+                                    dist_to_int_target,                        &
+                                    dt_agent,                                  &
+                                    dt_arel,                                   &
+                                    dt_write_agent_data,                       &
+                                    end_time_arel,                             &
+                                    max_dist_from_path,                        &
+                                    min_nr_agent,                              &
+                                    multi_agent_system_end,                    &
+                                    multi_agent_system_start,                  &
+                                    number_of_agent_groups,                    &
+                                    radius_agent,                              &
+                                    random_start_position_agents,              &
+                                    read_agents_from_restartfile,              &
+                                    repuls_agent,                              &
+                                    repuls_wall,                               &
+                                    scan_radius_agent,                         &
+                                    sigma_rep_agent,                           &
+                                    sigma_rep_wall,                            &
+                                    step_dealloc_mas,                          &
+                                    tau_accel_agent
 
 !
@@ -3661,5 +3692,5 @@
        REWIND ( 11 )
        line = ' '
-       DO   WHILE ( INDEX( line, '&agents_par' ) == 0 )
+       DO   WHILE ( INDEX( line, '&agent_parameters' ) == 0 )
           READ ( 11, '(A)', END=20 )  line
        ENDDO
@@ -3668,5 +3699,5 @@
 !
 !--    Read user-defined namelist
-       READ ( 11, agents_par )
+       READ ( 11, agent_parameters )
 
 !
Index: /palm/trunk/SOURCE/netcdf_interface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 3197)
+++ /palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 3198)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Redefined MAS limited time dimension to fit usage of multi_agent_system_end
+! 
+! 3187 2018-07-31 10:32:34Z sward
 ! Changed agent output to precision NF90_DOUBLE
 ! 
@@ -283,5 +286,6 @@
 
     USE control_parameters,                                                    &
-        ONLY:  max_masks, fl_max, var_fl_max, varnamelength
+        ONLY:  fl_max, max_masks, multi_agent_system_end,                      &
+               multi_agent_system_start, var_fl_max, varnamelength
     USE kinds
 #if defined( __netcdf )
@@ -1968,5 +1972,8 @@
           ELSE
              CALL netcdf_create_dim( id_set_agt, 'time',                       &
-                                     INT(end_time/dt_write_agent_data*1.2),    &
+                                     INT( ( MIN( multi_agent_system_end,       &
+                                                 end_time ) -                  &
+                                            multi_agent_system_start ) /       &
+                                            dt_write_agent_data * 1.1 ),       &
                                      id_dim_time_agt, 331 )
           ENDIF
Index: /palm/trunk/SOURCE/time_integration.f90
===================================================================
--- /palm/trunk/SOURCE/time_integration.f90	(revision 3197)
+++ /palm/trunk/SOURCE/time_integration.f90	(revision 3198)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Added multi_agent_system_end; defined start time for MAS relative to
+! time_since_reference_point
+! 
+! 3183 2018-07-27 14:25:55Z suehring
 ! Replace simulated_time by time_since_reference_point in COSMO nesting mode. 
 ! Rename subroutines and variables in COSMO nesting mode
@@ -388,4 +392,5 @@
                loop_optimization, lsf_surf, lsf_vert, masks,                   &
                microphysics_morrison, microphysics_seifert, mid,               &
+               multi_agent_system_end, multi_agent_system_start,               &
                nesting_offline, neutral, nr_timesteps_this_run, nudging,       &
                ocean, passive_scalar, prho_reference, pt_reference,            &
@@ -440,5 +445,5 @@
 
     USE multi_agent_system_mod,                                                &
-        ONLY:  agents_active, multi_agent_system, multi_agent_system_start
+        ONLY:  agents_active, multi_agent_system
 
     USE particle_attributes,                                                   &
@@ -719,5 +724,6 @@
 !--       Movement of agents in multi agent system
           IF ( agents_active  .AND.                                            &
-               simulated_time >= multi_agent_system_start  .AND.               &
+               time_since_reference_point >= multi_agent_system_start  .AND.   &
+               time_since_reference_point <= multi_agent_system_end    .AND.   &
                intermediate_timestep_count == 1 )  THEN
              CALL multi_agent_system
Index: /palm/trunk/UTIL/nav_mesh/nav_mesh.f90
===================================================================
--- /palm/trunk/UTIL/nav_mesh/nav_mesh.f90	(revision 3197)
+++ /palm/trunk/UTIL/nav_mesh/nav_mesh.f90	(revision 3198)
@@ -25,4 +25,7 @@
 ! -----------------!
 ! $Id$
+! Reduced tolerance_dp to 3 entries, fixed its initialization
+! 
+! 3168 2018-07-25 06:40:29Z sward
 ! Updated NetCDF ororgraphy and building input
 ! 
@@ -95,5 +98,5 @@
     REAL(wp)    ::  start            !< variable for CPU time measurement
 
-    REAL(wp), DIMENSION(0:4) ::  tolerance_dp  !< tolerance in Douglas-Poicker algorithm
+    REAL(wp), DIMENSION(0:2) ::  tolerance_dp = 999999.0_wp  !< tolerance in Douglas-Peucker algorithm
 
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  obstacle_height  !< height of obstacles
@@ -1338,9 +1341,12 @@
 !
 !--    If tolerance_dp was not set, put in default values
-       IF ( tolerance_dp(0) == 999999.0_wp ) tolerance_dp(0) = SQRT(dx*dy)*2.99
-       IF ( tolerance_dp(1) == 999999.0_wp ) tolerance_dp(1) = SQRT(dx*dy)*1.99
-       IF ( tolerance_dp(2) == 999999.0_wp ) tolerance_dp(2) = SQRT(dx*dy)*1.41
-       IF ( tolerance_dp(3) == 999999.0_wp ) tolerance_dp(3) = SQRT(dx*dy)*.7
-       IF ( tolerance_dp(4) == 999999.0_wp ) tolerance_dp(4) = SQRT(dx*dy)*.35
+       DO i = 0, 2
+          IF ( tolerance_dp(i) == 999999.0_wp ) THEN
+             tolerance_dp(i) = SQRT(dx*dy)*1.41/(2**i)
+          ELSE
+             tolerance_dp(i) = tolerance_dp(i)*SQRT(dx*dy)
+          ENDIF
+       ENDDO
+
 !
 !--    Allocate arrays
@@ -2784,5 +2790,5 @@
 !--    of vertices would fall below 4 due to this procedure, the tolerance
 !--    for the algorithm is reduced and it is run again. 
-       DO i_sc = 0, 4
+       DO i_sc = 0, 2
           CALL simplify_polygon(1,nov+1,tolerance_dp(i_sc))
           i_cn = 0
