Index: /palm/trunk/UTIL/agent_preprocessing/agent_preprocessing.f90
===================================================================
--- /palm/trunk/UTIL/agent_preprocessing/agent_preprocessing.f90	(revision 3258)
+++ /palm/trunk/UTIL/agent_preprocessing/agent_preprocessing.f90	(revision 3259)
@@ -25,4 +25,7 @@
 ! -----------------!
 ! $Id$
+! Removed unused variables and fixed real to real comparisons
+! 
+! 3216 2018-08-29 10:22:12Z sward
 ! Bubfix for gfortran: reordering of type definitions
 ! 
@@ -248,17 +251,12 @@
 
        INTEGER(iwp) ::  i            !< running index along x-direction
-       INTEGER(iwp) ::  ii           !< running index for IO blocks
        INTEGER(iwp) ::  k_head       !< minimum k index for agents to walk underneath overhanging buildings
        INTEGER(iwp) ::  id_topo      !< NetCDF id of topograhy input file
        INTEGER(iwp) ::  j            !< running index along y-direction
-       INTEGER(iwp) ::  k            !< running index along z-direction
        INTEGER(iwp) ::  num_vars     !< number of variables in netcdf input file
-       INTEGER(iwp) ::  skip_n_rows  !< counting variable to skip rows while reading topography file
 
        LOGICAL ::  netcdf_flag = .FALSE.     !< indicates whether netcdf file is used for input
        LOGICAL ::  lod_flag = .FALSE.        !< true if 3d building data is used
        LOGICAL ::  topo_file_flag = .FALSE.  !< true if 3d building data is used
-
-       REAL(wp) ::  dum  !< dummy variable to skip columns while reading topography file   
 
        WRITE(*,'((X,A,/))') 'Looking for topography/building information'
@@ -514,5 +512,4 @@
        CHARACTER (LEN=*), INTENT(IN) ::  filename  !< filename
        INTEGER(iwp), INTENT(INOUT)   ::  id        !< file id
-       LOGICAL                       ::  file_open = .FALSE.
 
        nc_stat = NF90_OPEN( filename, NF90_NOWRITE, id )
@@ -803,6 +800,4 @@
        INTEGER(iwp), INTENT(IN)      ::  n3              !< number of data-points along 3rd dimension
        INTEGER(iwp), INTENT(IN)      ::  n4              !< number of data-points along 4th dimension
-
-       INTEGER(iwp), DIMENSION(3)    ::  id_dim
 
        REAL(wp), DIMENSION(:,:), INTENT(INOUT) ::  var     !< variable to be read
@@ -1242,5 +1237,4 @@
        IMPLICIT NONE
 
-       CHARACTER(LEN=20)  ::  FMT
        CHARACTER(LEN=200) ::  dirname
        CHARACTER(LEN=200) ::  rundir
@@ -1355,5 +1349,5 @@
 !--    If tolerance_dp was not set, put in default values
        DO i = 0, 2
-          IF ( tolerance_dp(i) == 999999.0_wp ) THEN
+          IF ( tolerance_dp(i) > 999998.0_wp ) THEN
              tolerance_dp(i) = SQRT(dx*dy)*1.41/(2**i)
           ELSE
@@ -1368,5 +1362,5 @@
 !
 !--    Set null_vertex
-       CALL set_vertex(null_vertex,0_iwp,0.0_wp,0.0_wp)
+       CALL set_vertex(null_vertex,0.0_wp,0.0_wp)
 !
 !--    Some initializations
@@ -1571,5 +1565,4 @@
        IMPLICIT NONE
 
-       INTEGER(iwp) ::  il    !< local counter
        INTEGER(iwp) ::  p_id  !< current polygon_id
 !
@@ -1588,5 +1581,5 @@
                    polygons(p_id)%nov = polygons(p_id)%nov + 1
                    nov = polygons(p_id)%nov
-                   CALL set_vertex(dummy_vertex, p_id, i*dx, j*dy)
+                   CALL set_vertex(dummy_vertex, i*dx, j*dy)
                    CALL add_vertex_to_polygon(dummy_vertex, p_id, nov)
                 ENDIF
@@ -1599,5 +1592,5 @@
                    polygons(p_id)%nov = polygons(p_id)%nov + 1
                    nov = polygons(p_id)%nov
-                   CALL set_vertex(dummy_vertex, p_id, i*dx, (j+1)*dy)
+                   CALL set_vertex(dummy_vertex, i*dx, (j+1)*dy)
                    CALL add_vertex_to_polygon(dummy_vertex, p_id, nov)
                 ENDIF
@@ -1610,5 +1603,5 @@
                    polygons(p_id)%nov = polygons(p_id)%nov + 1
                    nov = polygons(p_id)%nov
-                   CALL set_vertex(dummy_vertex, p_id, (i+1)*dx, (j+1)*dy)
+                   CALL set_vertex(dummy_vertex, (i+1)*dx, (j+1)*dy)
                    CALL add_vertex_to_polygon(dummy_vertex, p_id, nov)
                 ENDIF
@@ -1621,5 +1614,5 @@
                    polygons(p_id)%nov = polygons(p_id)%nov + 1
                    nov = polygons(p_id)%nov
-                   CALL set_vertex(dummy_vertex, p_id, (i+1)*dx, j*dy)
+                   CALL set_vertex(dummy_vertex, (i+1)*dx, j*dy)
                    CALL add_vertex_to_polygon(dummy_vertex, p_id, nov)
                 ENDIF
@@ -1636,5 +1629,5 @@
                    polygons(p_id)%nov = polygons(p_id)%nov + 1
                    nov = polygons(p_id)%nov
-                   CALL set_vertex(dummy_vertex, p_id, i*dx, j*dy)
+                   CALL set_vertex(dummy_vertex, i*dx, j*dy)
                    CALL add_vertex_to_polygon(dummy_vertex, p_id, nov)
                 ENDIF
@@ -1648,5 +1641,5 @@
                    polygons(p_id)%nov = polygons(p_id)%nov + 1
                    nov = polygons(p_id)%nov
-                   CALL set_vertex(dummy_vertex, p_id, i*dx, (j+1)*dy)
+                   CALL set_vertex(dummy_vertex, i*dx, (j+1)*dy)
                    CALL add_vertex_to_polygon(dummy_vertex, p_id, nov)
                 ENDIF
@@ -1660,5 +1653,5 @@
                    polygons(p_id)%nov = polygons(p_id)%nov + 1
                    nov = polygons(p_id)%nov
-                   CALL set_vertex(dummy_vertex, p_id, (i+1)*dx, (j+1)*dy)
+                   CALL set_vertex(dummy_vertex, (i+1)*dx, (j+1)*dy)
                    CALL add_vertex_to_polygon(dummy_vertex, p_id, nov)
                 ENDIF
@@ -1672,5 +1665,5 @@
                    polygons(p_id)%nov = polygons(p_id)%nov + 1
                    nov = polygons(p_id)%nov
-                   CALL set_vertex(dummy_vertex, p_id, (i+1)*dx, j*dy)
+                   CALL set_vertex(dummy_vertex, (i+1)*dx, j*dy)
                    CALL add_vertex_to_polygon(dummy_vertex, p_id, nov)
                 ENDIF
@@ -1686,9 +1679,7 @@
 !> Initializes a vertex
 !------------------------------------------------------------------------------!
-    SUBROUTINE set_vertex (in_vertex, p_id, x, y)
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  p_id  !< polygon ID
+    SUBROUTINE set_vertex (in_vertex, x, y)
+
+       IMPLICIT NONE
 
        REAL(wp) ::  x  !< x-coordinate of vertex position
@@ -1798,5 +1789,5 @@
        ENDIF
        DO il = 1, nov
-          IF ( sorted_p(il)%x == m_x ) THEN
+          IF ( ABS( sorted_p(il)%x - m_x ) < .01 * dx ) THEN
              counter = counter + 1
              dummy_vertex = sorted_p(il)
@@ -1811,5 +1802,5 @@
        ENDIF
        DO il = 1, counter
-          IF ( sorted_p(il)%y == m_y ) THEN
+          IF ( ABS(sorted_p(il)%y - m_y) < .01 * dy ) THEN
              dummy_vertex = sorted_p(il)
              sorted_p(il) = sorted_p(1)
@@ -1860,6 +1851,6 @@
              IF ( nosv < nov ) THEN
                 DO il = nosv+1, nov
-                   IF ( current_v%x == sorted_p(il)%x .OR.                  &
-                        current_v%y == sorted_p(il)%y)                      &
+                   IF ( ABS( current_v%x - sorted_p(il)%x ) < .01 * dx .OR.    &
+                        ABS( current_v%y - sorted_p(il)%y ) < .01 * dy )       &
                    THEN
 !
@@ -1888,4 +1879,5 @@
 !--          all tests fail, is the candidate one of a maximum of two possible
 !--          neighbors.
+             id_neighbor  = -999
              id_neighbor1 = -999
              id_neighbor2 = -999
@@ -1907,7 +1899,9 @@
                                      (candidates(il)%y - current_v%y)**2 )
                 IF ( nosv > 1 ) THEN
-                   IF ( dist < .9*dx .OR.                                      &
-                        (sorted_p(nosv-1)%x == candidates(il)%x .AND.          &
-                         sorted_p(nosv-1)%y == candidates(il)%y) )             &
+                   IF ( dist < .9 * dx .OR.                                    &
+                        ( ( ABS( sorted_p(nosv-1)%x                            &
+                        - candidates(il)%x ) < .01 * dx ) .AND.                &
+                          ( ABS( sorted_p(nosv-1)%y                            &
+                        - candidates(il)%y ) < .01 * dy ) ) )                  &
                    THEN
                       CYCLE
@@ -1919,5 +1913,5 @@
 !--             (4 cases)
 !--             First: for vertical connection
-                IF ( candidates(il)%x == current_v%x ) THEN
+                IF ( ABS( candidates(il)%x - current_v%x ) < .01 * dx ) THEN
                    xs = NINT(current_v%x*ddx)-1
                    xe = xs + 1
@@ -1947,5 +1941,5 @@
 !
 !--             Horizontal connection
-                ELSEIF ( candidates(il)%y == current_v%y ) THEN
+                ELSEIF ( ABS( candidates(il)%y - current_v%y ) < .01 * dy ) THEN
 
                    ys = NINT(current_v%y*ddy)-1
@@ -1982,6 +1976,8 @@
                    id_neighbor1 = candidate_id(il)
                 ELSEIF ( id_neighbor1 /=  -999 .AND.                           &
-                       ( sorted_p(id_neighbor1)%x /= candidates(il)%x ) .OR.   &
-                       ( sorted_p(id_neighbor1)%y /= candidates(il)%y ) )      &
+                       ( ( ABS( sorted_p(id_neighbor1)%x - candidates(il)%x )  &
+                                > .01 * dx ) .OR.                              &
+                         ( ABS( sorted_p(id_neighbor1)%y - candidates(il)%y )  &
+                                > .01 * dy ) ) )                               &
                 THEN
                    id_neighbor2 = candidate_id(il)
@@ -2321,6 +2317,5 @@
        INTEGER(iwp) ::  vid_t  !< vertex id of tested mesh point
        INTEGER(iwp) ::  vl     !< vertex counter
-       
-       REAL(wp) ::  left          !< counter: current mesh point
+
        REAL(wp) ::  v1x           !< x-coordinate of test vertex 1 for intersection test
        REAL(wp) ::  v1y           !< y-coordinate of test vertex 1 for intersection test
@@ -2678,5 +2673,4 @@
        IMPLICIT NONE
 
-       INTEGER(iwp) ::  il  !< Local counter
        INTEGER(iwp) ::  noc !< Number of connections
 
