Index: /palm/trunk/SOURCE/virtual_measurement_mod.f90
===================================================================
--- /palm/trunk/SOURCE/virtual_measurement_mod.f90	(revision 3909)
+++ /palm/trunk/SOURCE/virtual_measurement_mod.f90	(revision 3910)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Bugfix in rotation of UTM coordinates
+! 
+! 3904 2019-04-16 18:22:51Z gronemeier
 ! Rotate coordinates of stations by given rotation_angle
 ! 
@@ -465,7 +468,9 @@
     REAL(wp)     ::  fill_zag  !< _FillValue for height coordinate
     
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  e_utm !< easting UTM coordinate, temporary variable
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  n_utm !< northing UTM coordinate, temporary variable,
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  z_ag  !< height coordinate relative to origin_z, temporary variable
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  e_utm     !< easting UTM coordinate, temporary variable
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  n_utm     !< northing UTM coordinate, temporary variable
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  e_utm_tmp !< EUTM coordinate before rotation
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  n_utm_tmp !< NUTM coordinate before rotation
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  z_ag      !< height coordinate relative to origin_z, temporary variable
 !
 !-- Obtain number of sites. Also, pass the 'open' string, in order to initially
@@ -474,5 +479,4 @@
                                 vmea_general%id_vm, input_file_vm,             &
                                 global_attribute, 'open', '' )
-                                
 !
 !-- Allocate data structure which encompass all required information, such as
@@ -589,4 +593,6 @@
           ENDIF
        ENDDO
+       
+       
 !
 !--    Allocate array for the measured variables names for the respective site.
@@ -658,4 +664,7 @@
           ALLOCATE( n_utm(1:vmea(l)%ntraj,1:dim_ntime) )
           ALLOCATE( z_ag(1:vmea(l)%ntraj,1:dim_ntime)  )
+          
+          ALLOCATE( e_utm_tmp(1:vmea(l)%ntraj,1:dim_ntime) )
+          ALLOCATE( n_utm_tmp(1:vmea(l)%ntraj,1:dim_ntime) )
 !
 !--       Read _FillValue attributes of the coordinate dimensions.
@@ -704,14 +713,14 @@
 !--          between UTM coordinates. Note, if the origin is not correct, the
 !--          virtual sites will be misplaced. 
-             e_utm(t,1:dim_ntime) = e_utm(t,1:dim_ntime) - init_model%origin_x
-             n_utm(t,1:dim_ntime) = n_utm(t,1:dim_ntime) - init_model%origin_y
+             e_utm_tmp(t,1:dim_ntime) = e_utm(t,1:dim_ntime) - init_model%origin_x
+             n_utm_tmp(t,1:dim_ntime) = n_utm(t,1:dim_ntime) - init_model%origin_y
              e_utm(t,1:dim_ntime) = COS( init_model%rotation_angle * pi / 180.0_wp ) &
-                                    * e_utm(t,1:dim_ntime)                           &
+                                    * e_utm_tmp(t,1:dim_ntime)                       &
                                   - SIN( init_model%rotation_angle * pi / 180.0_wp ) &
-                                    * n_utm(t,1:dim_ntime)
+                                    * n_utm_tmp(t,1:dim_ntime)
              n_utm(t,1:dim_ntime) = SIN( init_model%rotation_angle * pi / 180.0_wp ) &
-                                    * e_utm(t,1:dim_ntime)                           &
+                                    * e_utm_tmp(t,1:dim_ntime)                       &
                                   + COS( init_model%rotation_angle * pi / 180.0_wp ) &
-                                    * n_utm(t,1:dim_ntime)
+                                    * n_utm_tmp(t,1:dim_ntime)
 !
 !--          Determine the individual time coordinate length for each station and
@@ -791,5 +800,5 @@
           ALLOCATE( vmea(l)%j(1:vmea(l)%ns) )
           ALLOCATE( vmea(l)%k(1:vmea(l)%ns) )
-          ALLOCATE( vmea(l)%z_ag(1:vmea(l)%ns) )          
+          ALLOCATE( vmea(l)%z_ag(1:vmea(l)%ns) )      
 !
 !--       Based on the flag array store the grid indices which correspond to 
@@ -889,8 +898,11 @@
 !
 !--       Deallocate temporary coordinate arrays
-          IF ( ALLOCATED( e_utm ) )  DEALLOCATE( e_utm )
-          IF ( ALLOCATED( n_utm ) )  DEALLOCATE( n_utm )
-          IF ( ALLOCATED( z_ag  ) )  DEALLOCATE( z_ag  )
-          IF ( ALLOCATED( z_ag  ) )  DEALLOCATE( vmea(l)%dim_t )
+          IF ( ALLOCATED( e_utm )     )  DEALLOCATE( e_utm )
+          IF ( ALLOCATED( n_utm )     )  DEALLOCATE( n_utm )
+          IF ( ALLOCATED( e_utm_tmp ) )  DEALLOCATE( e_utm_tmp )
+          IF ( ALLOCATED( n_utm_tmp ) )  DEALLOCATE( n_utm_tmp )
+          IF ( ALLOCATED( n_utm )     )  DEALLOCATE( n_utm )
+          IF ( ALLOCATED( z_ag  )     )  DEALLOCATE( z_ag  )
+          IF ( ALLOCATED( z_ag  )     )  DEALLOCATE( vmea(l)%dim_t )
        ENDIF
     ENDDO
