Index: /palm/trunk/SOURCE/Makefile
===================================================================
--- /palm/trunk/SOURCE/Makefile	(revision 1956)
+++ /palm/trunk/SOURCE/Makefile	(revision 1957)
@@ -20,5 +20,5 @@
 # Current revisions:
 # ------------------
-# 
+# flight module added
 # 
 # Former revisions:
@@ -294,5 +294,5 @@
 	cuda_fft_interfaces_mod.f90 data_log.f90 data_output_dvrp.f90 \
 	data_output_mask.f90 data_output_profiles.f90 \
-	data_output_ptseries.f90 data_output_spectra.f90 \
+	data_output_ptseries.f90 data_output_spectra.f90 data_output_flight.f90\
 	data_output_tseries.f90 data_output_2d.f90 data_output_3d.f90 \
 	diffusion_e.f90 diffusion_s.f90 diffusion_u.f90 diffusion_v.f90 \
@@ -336,10 +336,10 @@
 	user_data_output_mask.f90 user_define_netcdf_grid.f90 \
 	user_dvrp_coltab.f90 user_header.f90 user_init.f90 \
-	user_init_3d_model.f90 user_init_grid.f90 user_init_land_surface.f90 \
-	user_init_plant_canopy.f90 user_init_radiation.f90 \
+	user_init_3d_model.f90 user_init_flight.f90 user_init_grid.f90 user_init_land_surface.f90 \
+	user_init_plant_canopy.f90 user_init_radiation.f90 user_flight.f90\
 	user_last_actions.f90 user_lpm_advec.f90 \
 	user_lpm_init.f90 user_lpm_set_attributes.f90 user_module.f90 \
 	user_parin.f90 user_read_restart_data.f90 \
-	user_spectra.f90 user_statistics.f90 wall_fluxes.f90 \
+	user_spectra.f90 user_statistics.f90 virtual_flight_mod.f90 wall_fluxes.f90 \
 	wind_turbine_model_mod.f90 write_3d_binary.f90 write_var_list.f90
 
@@ -422,4 +422,5 @@
    spectra_mod.o
 data_output_tseries.o: modules.o cpulog_mod.o mod_kinds.o netcdf_interface_mod.o
+data_output_flight.o: modules.o cpulog_mod.o mod_kinds.o netcdf_interface_mod.o virtual_flight_mod.o
 data_output_2d.o: modules.o cpulog_mod.o mod_kinds.o mod_particle_attributes.o \
    netcdf_interface_mod.o land_surface_model_mod.o radiation_model_mod.o
@@ -445,5 +446,5 @@
 header.o: modules.o cpulog_mod.o mod_kinds.o netcdf_interface_mod.o land_surface_model_mod.o\
    microphysics_mod.o plant_canopy_model_mod.o pmc_handle_communicator_mod.o pmc_interface_mod.o \
-   radiation_model_mod.o spectra_mod.o subsidence_mod.o
+   radiation_model_mod.o spectra_mod.o subsidence_mod.o virtual_flight_mod.o
 inflow_turbulence.o: modules.o cpulog_mod.o mod_kinds.o
 init_1d_model.o: modules.o mod_kinds.o
@@ -452,5 +453,5 @@
    radiation_model_mod.o random_function_mod.o random_generator_parallel_mod.o \
    surface_layer_fluxes_mod.o microphysics_mod.o mod_particle_attributes.o \
-   wind_turbine_model_mod.o
+   virtual_flight_mod.o wind_turbine_model_mod.o
 init_advec.o: modules.o mod_kinds.o
 init_cloud_physics.o: modules.o mod_kinds.o
@@ -509,5 +510,5 @@
 parin.o: modules.o cpulog_mod.o land_surface_model_mod.o mod_kinds.o netcdf_interface_mod.o \
    plant_canopy_model_mod.o pmc_interface_mod.o progress_bar_mod.o spectra_mod.o \
-   radiation_model_mod.o microphysics_mod.o wind_turbine_model_mod.o
+   radiation_model_mod.o microphysics_mod.o virtual_flight_mod.o wind_turbine_model_mod.o
 plant_canopy_model_mod.o: modules.o mod_kinds.o
 pmc_interface_mod.o: modules.o mod_kinds.o pmc_child_mod.o pmc_general_mod.o \
@@ -541,5 +542,5 @@
    spectra_mod.o
 read_var_list.o: modules.o mod_kinds.o netcdf_interface_mod.o plant_canopy_model_mod.o \
-   spectra_mod.o microphysics_mod.o
+   spectra_mod.o microphysics_mod.o virtual_flight_mod.o
 run_control.o: modules.o cpulog_mod.o mod_kinds.o
 set_slicer_attributes_dvrp.o: modules.o mod_kinds.o
@@ -556,9 +557,9 @@
 temperton_fft_mod.o: modules.o mod_kinds.o
 time_integration.o: modules.o advec_ws.o buoyancy.o calc_mean_profile.o \
-	cpulog_mod.o interaction_droplets_ptq.o land_surface_model_mod.o \
+	cpulog_mod.o data_output_flight.o interaction_droplets_ptq.o land_surface_model_mod.o \
 	ls_forcing_mod.o mod_kinds.o nudging_mod.o pmc_interface_mod.o production_e.o \
 	prognostic_equations.o progress_bar_mod.o radiation_model_mod.o \
 	spectra_mod.o user_actions.o surface_layer_fluxes_mod.o microphysics_mod.o \
-        wind_turbine_model_mod.o
+         virtual_flight_mod.o wind_turbine_model_mod.o
 time_to_string.o: mod_kinds.o
 timestep.o: modules.o cpulog_mod.o mod_kinds.o microphysics_mod.o
@@ -579,7 +580,9 @@
 user_define_netcdf_grid.o: modules.o mod_kinds.o user_module.o
 user_dvrp_coltab.o: modules.o mod_kinds.o user_module.o
+user_flight.o: modules.o mod_kinds.o user_module.o
 user_header.o: modules.o mod_kinds.o user_module.o
 user_init.o: modules.o mod_kinds.o netcdf_interface_mod.o user_module.o
 user_init_3d_model.o: modules.o mod_kinds.o user_module.o
+user_init_flight.o: modules.o mod_kinds.o netcdf_interface_mod.o user_module.o
 user_init_grid.o: modules.o mod_kinds.o user_module.o
 user_init_land_surface.o: modules.o mod_kinds.o user_module.o land_surface_model_mod.o
@@ -595,4 +598,5 @@
 user_spectra.o: modules.o mod_kinds.o spectra_mod.o user_module.o
 user_statistics.o: modules.o mod_kinds.o netcdf_interface_mod.o user_module.o
+virtual_flight_mod.o: modules.o cpulog_mod.o mod_kinds.o netcdf_interface_mod.o user_init_flight.o user_flight.o
 wall_fluxes.o: modules.o mod_kinds.o
 wind_turbine_model_mod.o: modules.o cpulog_mod.o mod_kinds.o
@@ -601,3 +605,3 @@
 	spectra_mod.o
 write_var_list.o: modules.o mod_kinds.o netcdf_interface_mod.o plant_canopy_model_mod.o\
-   spectra_mod.o microphysics_mod.o
+   spectra_mod.o microphysics_mod.o virtual_flight_mod.o
Index: /palm/trunk/SOURCE/check_open.f90
===================================================================
--- /palm/trunk/SOURCE/check_open.f90	(revision 1956)
+++ /palm/trunk/SOURCE/check_open.f90	(revision 1957)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! flight module added
 ! 
 ! Former revisions:
@@ -128,8 +128,8 @@
 
     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_create_file, netcdf_data_format, netcdf_define_header,   &
-               netcdf_handle_error, netcdf_open_write_file
+        ONLY:  id_set_fl, 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_create_file, netcdf_data_format,     &
+               netcdf_define_header, netcdf_handle_error, netcdf_open_write_file
 
     USE particle_attributes,                                                   &
@@ -1108,4 +1108,45 @@
           OPEN ( 117, FILE='PROGRESS'//TRIM( coupling_char ),                  &
                       STATUS='REPLACE', FORM='FORMATTED' )
+!
+!--    nc-file for virtual flight measurements
+       CASE ( 199 )
+!
+!--       Set filename
+          filename = 'DATA_1D_FL_NETCDF' // TRIM( coupling_char )
+
+!
+!--       Inquire, if there is a netCDF file from a previuos run. This should
+!--       be opened for extension, if its variables match the actual run.
+          INQUIRE( FILE=filename, EXIST=netcdf_extend )
+
+          IF ( netcdf_extend )  THEN
+!
+!--          Open an existing netCDF file for output
+             CALL netcdf_open_write_file( filename, id_set_fl, .FALSE., 532 )
+!
+!--          Read header information and set all ids. If there is a mismatch
+!--          between the previuos and the actual run, netcdf_extend is returned
+!--          as .FALSE.
+             CALL netcdf_define_header( 'fl', netcdf_extend, 0 )
+
+!
+!--          Remove the local file, if it can not be extended
+             IF ( .NOT. netcdf_extend )  THEN
+                nc_stat = NF90_CLOSE( id_set_fl )
+                CALL netcdf_handle_error( 'check_open', 533 )
+                CALL local_system( 'rm ' // TRIM( filename ) )
+             ENDIF
+
+          ENDIF          
+
+          IF ( .NOT. netcdf_extend )  THEN
+!
+!--          Create a new netCDF output file with requested netCDF format
+             CALL netcdf_create_file( filename, id_set_fl, .FALSE., 534 )
+!
+!--          Define the header
+             CALL netcdf_define_header( 'fl', netcdf_extend, 0 )
+
+          ENDIF
 
 
Index: /palm/trunk/SOURCE/data_output_flight.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_flight.f90	(revision 1957)
+++ /palm/trunk/SOURCE/data_output_flight.f90	(revision 1957)
@@ -0,0 +1,126 @@
+!> @file data_output_flight.f90
+!--------------------------------------------------------------------------------!
+! This file is part of PALM.
+!
+! PALM is free software: you can redistribute it and/or modify it under the terms
+! of the GNU General Public License as published by the Free Software Foundation,
+! either version 3 of the License, or (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2016 Leibniz Universitaet Hannover
+!--------------------------------------------------------------------------------!
+!
+! Current revisions:
+! ------------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+!
+! Revision 1.1  2001/01/05 15:14:20  raasch
+! Initial revision
+!
+!
+! Description:
+! ------------
+!> Writing data from flight measurements on file.
+!------------------------------------------------------------------------------!
+ SUBROUTINE data_output_flight
+ 
+#if defined( __netcdf )
+    USE control_parameters,                                                    &
+        ONLY:  message_string, num_leg, num_var_fl, run_description_header,    &
+               time_since_reference_point, virtual_flight
+
+    USE cpulog,                                                                &
+        ONLY:  cpu_log, log_point
+
+    USE flight_mod,                                                            &
+        ONLY:  sensor, x_pos, y_pos, z_pos
+
+    USE kinds
+
+    USE NETCDF
+
+    USE netcdf_interface,                                                      &
+        ONLY:  dofl_time_count, id_set_fl, id_var_dofl, id_var_time_fl,        &
+               id_var_x_fl, id_var_y_fl, id_var_z_fl, netcdf_handle_error,     &
+               nc_stat 
+              
+    USE pegrid
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i !< loop variable for output quantities
+    INTEGER(iwp) ::  l !< loop variable for flight legs
+    INTEGER(iwp) ::  k !< internal count for variable labels and units
+
+    CALL cpu_log( log_point(64), 'data_output_flight', 'start' )
+
+!
+!-- Check if virtual flights are carried out
+    IF ( .NOT. virtual_flight )  RETURN
+
+!
+!-- Output is only performed on PE0
+    IF ( myid == 0 )  THEN
+
+!
+!--    Open file for flight output in NetCDF format
+       CALL check_open( 199 )
+
+!
+!--    Increment the counter for number of output times
+       dofl_time_count = dofl_time_count + 1
+
+!
+!--    Update the flight-output time and spatial coordinates
+       nc_stat = NF90_PUT_VAR( id_set_fl, id_var_time_fl,                      &
+                               (/ time_since_reference_point /),               &
+                               start = (/ dofl_time_count /),                  &
+                               count = (/ 1 /) )
+       CALL netcdf_handle_error( 'data_output_flight', 554 )
+
+       DO  l = 1, num_leg
+          nc_stat = NF90_PUT_VAR( id_set_fl, id_var_x_fl(l),                   &
+                                  (/ x_pos(l) /),                              &
+                                  start = (/ dofl_time_count /),               &
+                                  count = (/ 1 /) )
+          nc_stat = NF90_PUT_VAR( id_set_fl, id_var_y_fl(l),                   &
+                                  (/ y_pos(l) /),                              &
+                                  start = (/ dofl_time_count /),               &
+                                  count = (/ 1 /) )
+          nc_stat = NF90_PUT_VAR( id_set_fl, id_var_z_fl(l),                   &
+                                  (/ z_pos(l) /),                              &
+                                  start = (/ dofl_time_count /),               &
+                                  count = (/ 1 /) )
+          CALL netcdf_handle_error( 'data_output_flight', 555 )
+       ENDDO
+!
+!--    Output measured quantities
+       k = 1
+       DO  l = 1, num_leg
+          DO i = 1, num_var_fl
+             nc_stat = NF90_PUT_VAR( id_set_fl, id_var_dofl(k),                &
+                                     (/ sensor(i,l) /),                        &
+                                     start = (/ dofl_time_count /),            &
+                                     count = (/ 1 /) )
+
+             CALL netcdf_handle_error( 'data_output_flight', 556 )
+          
+             k = k + 1
+          ENDDO
+       ENDDO
+    ENDIF
+    
+    CALL cpu_log( log_point(64), 'data_output_flight', 'stop' )
+    
+#endif
+ END SUBROUTINE data_output_flight
Index: /palm/trunk/SOURCE/header.f90
===================================================================
--- /palm/trunk/SOURCE/header.f90	(revision 1956)
+++ /palm/trunk/SOURCE/header.f90	(revision 1957)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! flight module added
 ! 
 ! Former revisions:
@@ -275,4 +275,7 @@
     USE dvrp_variables,                                                        &
         ONLY:  use_seperate_pe_for_dvrp_output
+        
+    USE flight_mod,                                                            &
+        ONLY:  flight_header
         
     USE grid_variables,                                                        &
@@ -1644,4 +1647,7 @@
     ENDIF
 #endif
+!
+!-- Output of virtual flight information
+    IF ( virtual_flight )  CALL flight_header( io )
 
 !
Index: /palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- /palm/trunk/SOURCE/init_3d_model.f90	(revision 1956)
+++ /palm/trunk/SOURCE/init_3d_model.f90	(revision 1957)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! flight module added
 !
 ! Former revisions:
@@ -292,4 +292,7 @@
     USE control_parameters
     
+    USE flight_mod,                                                            &
+        ONLY:  flight_init
+    
     USE grid_variables,                                                        &
         ONLY:  dx, dy
@@ -707,4 +710,10 @@
        CALL wtm_init_arrays
     ENDIF
+    
+!
+!-- Initialize virtual flight measurements
+    IF ( virtual_flight )  THEN
+       CALL flight_init
+    ENDIF
 
 !
@@ -1311,4 +1320,6 @@
 #endif
        ENDDO
+       write(9,*) "EOF read binary"
+       flush(9)
 
 !
Index: /palm/trunk/SOURCE/modules.f90
===================================================================
--- /palm/trunk/SOURCE/modules.f90	(revision 1956)
+++ /palm/trunk/SOURCE/modules.f90	(revision 1957)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! +fl_max, num_leg, num_var_fl, num_var_fl_user, var_fl_max, virtual_flight
 !
 ! Former revisions:
@@ -615,4 +615,6 @@
     CHARACTER (LEN=20), DIMENSION(0:1,100) ::  do2d = ' ', do3d = ' '
 
+    INTEGER(iwp), PARAMETER :: fl_max = 100, var_fl_max = 20
+    
     INTEGER(iwp) ::  abort_mode = 1, average_count_pr = 0, &
                      average_count_3d = 0, current_timestep_number = 0, &
@@ -637,4 +639,5 @@
                      nr_timesteps_this_run = 0, &
                      nsor = 20, nsor_ini = 100, n_sor, normalizing_region = 0, &
+                     num_leg=0, num_var_fl, num_var_fl_user=0, &
                      nz_do3d = -9999, prt_time_count = 0, &
                      recycling_plane, runnr = 0, &
@@ -701,5 +704,5 @@
                 microphysics_seifert = .FALSE., &
                 mg_switch_to_pe0 = .FALSE., &
-                monotonic_adjustment = .FALSE.
+                monotonic_adjustment = .FALSE., virtual_flight = .FALSE.
     LOGICAL ::  nest_bound_l = .FALSE. !< nested boundary on left side
     LOGICAL ::  nest_bound_n = .FALSE. !< nested boundary on north side
Index: /palm/trunk/SOURCE/netcdf_interface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 1956)
+++ /palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 1957)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! flight module added
 ! 
 ! Former revisions:
@@ -139,5 +139,5 @@
  MODULE netcdf_interface
 
-    USE control_parameters, ONLY: max_masks
+    USE control_parameters, ONLY: max_masks, fl_max, var_fl_max
     USE kinds
 #if defined( __netcdf )
@@ -238,11 +238,12 @@
     CHARACTER(LEN=40) ::  netcdf_data_format_string
 
-    INTEGER(iwp) ::  id_dim_prtnum, id_dim_time_pr, id_dim_time_prt, &
+    INTEGER(iwp) ::  id_dim_prtnum, id_dim_time_fl, id_dim_time_pr, id_dim_time_prt, &
                      id_dim_time_pts, id_dim_time_sp, id_dim_time_ts, id_dim_x_sp, &
-                     id_dim_y_sp, id_dim_zu_sp, id_dim_zw_sp, id_set_pr, &
-                     id_set_prt, id_set_pts, id_set_sp, id_set_ts, id_var_prtnum, &
-                     id_var_rnop_prt, id_var_time_pr, id_var_time_prt, &
+                     id_dim_y_sp, id_dim_zu_sp, id_dim_zw_sp, id_set_fl, id_set_pr, &
+                     id_set_prt, id_set_pts, id_set_sp, id_set_ts, id_var_time_fl, &
+                     id_var_prtnum, id_var_rnop_prt, id_var_time_pr, id_var_time_prt, &
                      id_var_time_pts, id_var_time_sp, id_var_time_ts, id_var_x_sp, &
                      id_var_y_sp, id_var_zu_sp, id_var_zw_sp, nc_stat
+
 
     INTEGER(iwp), DIMENSION(0:1) ::  id_dim_time_xy, id_dim_time_xz, &
@@ -271,8 +272,20 @@
                                         !< compression
 
+    INTEGER(iwp)                 ::  dofl_time_count
     INTEGER(iwp), DIMENSION(10)  ::  id_var_dospx, id_var_dospy
     INTEGER(iwp), DIMENSION(20)  ::  id_var_prt
     INTEGER(iwp), DIMENSION(11)  ::  nc_precision
     INTEGER(iwp), DIMENSION(dopr_norm_num) ::  id_var_norm_dopr
+    
+    INTEGER(iwp), DIMENSION(fl_max) ::  id_dim_x_fl, id_dim_y_fl, id_dim_z_fl
+    INTEGER(iwp), DIMENSION(fl_max) ::  id_var_x_fl, id_var_y_fl, id_var_z_fl
+    
+    CHARACTER (LEN=20), DIMENSION(fl_max*var_fl_max) :: dofl_label
+    CHARACTER (LEN=20), DIMENSION(fl_max*var_fl_max) :: dofl_unit 
+    CHARACTER (LEN=20), DIMENSION(fl_max) :: dofl_dim_label_x
+    CHARACTER (LEN=20), DIMENSION(fl_max) :: dofl_dim_label_y
+    CHARACTER (LEN=20), DIMENSION(fl_max) :: dofl_dim_label_z
+
+    INTEGER(iwp), DIMENSION(fl_max*var_fl_max) :: id_var_dofl    
 
     INTEGER(iwp), DIMENSION(dopts_num,0:10) ::  id_var_dopts
@@ -300,16 +313,19 @@
 
 
-    PUBLIC  domask_unit, dopr_unit, dopts_num, dots_label, dots_max, dots_num, &
-            dots_rad, dots_soil, dots_unit, do2d_unit, do3d_unit, 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, id_var_domask,         &
-            id_var_dopr, id_var_dopts, id_var_dospx, id_var_dospy,             &
-            id_var_dots, id_var_do2d, id_var_do3d, id_var_norm_dopr,           &
-            id_var_time_mask, id_var_time_pr, id_var_time_pts, id_var_time_sp, &
-            id_var_time_ts, id_var_time_xy, id_var_time_xz, id_var_time_yz,    &
-            id_var_time_3d, nc_stat, netcdf_data_format,                       &
-            netcdf_data_format_string, netcdf_deflate, netcdf_precision,       &
-            output_for_t0
-
+    PUBLIC  dofl_dim_label_x, dofl_dim_label_y, dofl_dim_label_z, dofl_label,  &
+            dofl_time_count, dofl_unit, domask_unit, dopr_unit, dopts_num,     &
+            dots_label, dots_max, dots_num, dots_rad, dots_soil, dots_unit,    &
+            do2d_unit, do3d_unit, id_set_fl, 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, id_var_domask, id_var_dofl, id_var_dopr,     &
+            id_var_dopts, id_var_dospx, id_var_dospy, id_var_dots, id_var_do2d,&
+            id_var_do3d, id_var_norm_dopr, id_var_time_fl, id_var_time_mask,   &
+            id_var_time_pr, id_var_time_pts, id_var_time_sp, id_var_time_ts,   &
+            id_var_time_xy, id_var_time_xz, id_var_time_yz, id_var_time_3d,    &
+            id_var_x_fl, id_var_y_fl, id_var_z_fl,  nc_stat,                   &
+            netcdf_data_format, netcdf_data_format_string, netcdf_deflate,     &
+            netcdf_precision, output_for_t0
+            
+            
     SAVE
 
@@ -366,5 +382,5 @@
                simulated_time_at_begin, skip_time_data_output_av,              &
                skip_time_do2d_xy, skip_time_do2d_xz, skip_time_do2d_yz,        &
-               skip_time_do3d, topography
+               skip_time_do3d, topography, num_leg, num_var_fl
 
     USE grid_variables,                                                        &
@@ -433,4 +449,5 @@
     INTEGER(iwp) ::  ntime_count                             !< number of time levels found in file
     INTEGER(iwp) ::  nz_old                                  !<
+    INTEGER(iwp) ::  l                                       !<
 
     INTEGER(iwp), SAVE ::  oldmode                           !<
@@ -510,4 +527,6 @@
              CASE ( 'masks' )
                 nc_precision(11) = j
+             CASE ( 'fl' )
+                nc_precision(9) = j
              CASE ( 'all' )
                 nc_precision    = j
@@ -4887,5 +4906,184 @@
           CALL message( 'netcdf_define_header', 'PA0269', 0, 0, 0, 6, 0 )
 
-
+!
+!--    Flight data
+       CASE ( 'fl_new' )
+!
+!--       Define some global attributes of the dataset
+          nc_stat = NF90_PUT_ATT( id_set_fl, NF90_GLOBAL, 'title',             &
+                                  TRIM( run_description_header ) )
+          CALL netcdf_handle_error( 'netcdf_define_header', 249 )
+
+!
+!--       Define time and location coordinates for flight space-time series
+!--       (unlimited dimension)
+!--       Error number must still be set appropriately.
+          CALL netcdf_create_dim( id_set_fl, 'time', NF90_UNLIMITED,           &
+                                  id_dim_time_fl, 250 )
+          CALL netcdf_create_var( id_set_fl, (/ id_dim_time_fl /), 'time',     &
+                                  NF90_DOUBLE, id_var_time_fl, 'seconds', '',  &
+                                  251, 252, 000 )
+
+          DO l = 1, num_leg
+             CALL netcdf_create_dim( id_set_fl, dofl_dim_label_x(l),           &
+                                     NF90_UNLIMITED, id_dim_x_fl(l), 250 )
+             CALL netcdf_create_dim( id_set_fl, dofl_dim_label_y(l),           &
+                                     NF90_UNLIMITED, id_dim_y_fl(l), 250 )
+             CALL netcdf_create_dim( id_set_fl, dofl_dim_label_z(l),           &
+                                     NF90_UNLIMITED, id_dim_z_fl(l), 250 )
+
+             CALL netcdf_create_var( id_set_fl, (/ id_dim_x_fl(l) /),          &
+                                     dofl_dim_label_x(l), NF90_DOUBLE,         &
+                                     id_var_x_fl(l), 'm', '', 251, 252, 000 )
+             CALL netcdf_create_var( id_set_fl, (/ id_dim_y_fl(l) /),          &
+                                     dofl_dim_label_y(l), NF90_DOUBLE,         &
+                                     id_var_y_fl(l), 'm', '', 251, 252, 000 )
+             CALL netcdf_create_var( id_set_fl, (/ id_dim_z_fl(l) /),          &
+                                     dofl_dim_label_z(l), NF90_DOUBLE,         &
+                                     id_var_z_fl(l), 'm', '', 251, 252, 000 )
+          ENDDO
+!
+!--       Define the variables
+          var_list = ';'
+          k = 1
+          DO  l = 1, num_leg
+             DO i = 1, num_var_fl
+
+                CALL netcdf_create_var( id_set_fl, (/ id_dim_time_fl /),       &
+                                        dofl_label(k), nc_precision(9),        &
+                                        id_var_dofl(k),                        &
+                                        TRIM( dofl_unit(k) ),                  &
+                                        TRIM( dofl_label(k) ), 253, 254, 255 )
+
+                k = k + 1
+                
+             ENDDO
+
+          ENDDO
+
+!
+!--       Write the list of variables as global attribute (this is used by
+!--       restart runs)
+          nc_stat = NF90_PUT_ATT( id_set_fl, NF90_GLOBAL, 'VAR_LIST', var_list )
+          CALL netcdf_handle_error( 'netcdf_define_header', 258 )
+
+!
+!--       Leave netCDF define mode
+          nc_stat = NF90_ENDDEF( id_set_fl )
+          CALL netcdf_handle_error( 'netcdf_define_header', 259 )
+
+
+       CASE ( 'fl_ext' )
+
+!
+!--       Get the list of variables and compare with the actual run.
+!--       First var_list_old has to be reset, since GET_ATT does not assign
+!--       trailing blanks.
+          var_list_old = ' '
+          nc_stat = NF90_GET_ATT( id_set_fl, NF90_GLOBAL, 'VAR_LIST',          &
+                                  var_list_old )
+          CALL netcdf_handle_error( 'netcdf_define_header', 260 )
+
+          var_list = ';'
+          i = 1
+          DO  i = 1, num_leg * num_var_fl
+
+             var_list = TRIM( var_list ) // TRIM( dofl_label(i) ) // ';'
+
+          ENDDO
+
+          IF ( TRIM( var_list ) /= TRIM( var_list_old ) )  THEN
+             message_string = 'netCDF file for flight time series ' //         &
+                              'from previous run found,' //                    &
+                              '& but this file cannot be extended due to' //   &
+                              ' variable mismatch.' //                         &
+                              '&New file is created instead.'
+             CALL message( 'define_netcdf_header', 'PA0257', 0, 1, 0, 6, 0 )
+             extend = .FALSE.
+             RETURN
+          ENDIF
+
+!
+!--       Get the id of the time coordinate (unlimited coordinate) and its
+!--       last index on the file. The next time level is dofl_time_count+1.
+!--       The current time must be larger than the last output time
+!--       on the file.
+          nc_stat = NF90_INQ_VARID( id_set_fl, 'time', id_var_time_fl )
+          CALL netcdf_handle_error( 'netcdf_define_header', 261 )
+
+          nc_stat = NF90_INQUIRE_VARIABLE( id_set_fl, id_var_time_fl, &
+                                           dimids = id_dim_time_old )
+          CALL netcdf_handle_error( 'netcdf_define_header', 262 )
+          id_dim_time_fl = id_dim_time_old(1)
+
+          nc_stat = NF90_INQUIRE_DIMENSION( id_set_fl, id_dim_time_fl, &
+                                            len = dofl_time_count )
+          CALL netcdf_handle_error( 'netcdf_define_header', 263 )
+
+          nc_stat = NF90_GET_VAR( id_set_fl, id_var_time_fl,        &
+                                  last_time_coordinate,             &
+                                  start = (/ dofl_time_count /), &
+                                  count = (/ 1 /) )
+          CALL netcdf_handle_error( 'netcdf_define_header', 264 )
+
+          IF ( last_time_coordinate(1) >= simulated_time )  THEN
+             message_string = 'netCDF file for flight-time series ' //      &
+                              'from previous run found,' //                 &
+                              '&but this file cannot be extended becaus' // &
+                              'e the current output time' //                &
+                              '&is less or equal than the last output t' // &
+                              'ime on this file.' //                        &
+                              '&New file is created instead.'
+             CALL message( 'define_netcdf_header', 'PA0258', 0, 1, 0, 6, 0 )
+             dofl_time_count = 0
+             extend = .FALSE.
+             RETURN
+          ENDIF
+
+!
+!--       Dataset seems to be extendable.
+!--       Now get the remaining dimension and variable ids
+          DO l = 1, num_leg
+             nc_stat = NF90_INQ_VARID( id_set_fl, dofl_dim_label_x(l),         &
+                                       id_var_x_fl(l) )
+             CALL netcdf_handle_error( 'netcdf_define_header', 265 )
+             nc_stat = NF90_INQ_VARID( id_set_fl, dofl_dim_label_y(l),         &
+                                       id_var_y_fl(l) )
+             CALL netcdf_handle_error( 'netcdf_define_header', 265 )
+             nc_stat = NF90_INQ_VARID( id_set_fl, dofl_dim_label_z(l),         &
+                                       id_var_z_fl(l) )
+             CALL netcdf_handle_error( 'netcdf_define_header', 265 )
+
+          ENDDO
+
+
+          DO  i = 1, num_leg * num_var_fl
+ 
+            nc_stat = NF90_INQ_VARID( id_set_fl, dofl_label(i), &
+                                       id_var_dofl(i) )
+            CALL netcdf_handle_error( 'netcdf_define_header', 265 )
+
+          ENDDO
+
+!
+!--       Update the title attribute on file
+!--       In order to avoid 'data mode' errors if updated attributes are larger 
+!--       than their original size, NF90_PUT_ATT is called in 'define mode' 
+!--       enclosed by NF90_REDEF and NF90_ENDDEF calls. This implies a possible 
+!--       performance loss due to data copying; an alternative strategy would be 
+!--       to ensure equal attribute size in a job chain. Maybe revise later.
+          nc_stat = NF90_REDEF( id_set_fl )
+          CALL netcdf_handle_error( 'netcdf_define_header', 439 )
+          nc_stat = NF90_PUT_ATT( id_set_fl, NF90_GLOBAL, 'title',             &
+                                  TRIM( run_description_header ) )
+          CALL netcdf_handle_error( 'netcdf_define_header', 267 )
+          nc_stat = NF90_ENDDEF( id_set_fl )
+          CALL netcdf_handle_error( 'netcdf_define_header', 440 )
+          message_string = 'netCDF file for flight-time series ' //            &
+                           'from previous run found.' //                       &
+                           '&This file will be extended.'
+          CALL message( 'define_netcdf_header', 'PA0259', 0, 0, 0, 6, 0 )
+
+          
        CASE DEFAULT
 
Index: /palm/trunk/SOURCE/parin.f90
===================================================================
--- /palm/trunk/SOURCE/parin.f90	(revision 1956)
+++ /palm/trunk/SOURCE/parin.f90	(revision 1957)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! flight module added
 ! 
 ! Former revisions:
@@ -30,5 +30,5 @@
 ! initialized for nest domains. Prognostic variables are later initialized by 
 ! interpolation from the parent domain. 
-! 
+!
 ! 1917 2016-05-27 14:28:12Z witha
 ! Initial version of purely vertical nesting introduced.
@@ -228,4 +228,7 @@
     USE dvrp_variables,                                                        &
         ONLY:  local_dvrserver_running
+
+    USE flight_mod,                                                            &
+        ONLY:  flight_parin
 
     USE grid_variables,                                                        &
@@ -481,4 +484,5 @@
           ENDIF
 
+            
 !
 !--       Check validity of lateral boundary conditions. This has to be done
@@ -555,4 +559,8 @@
 !--       required
           CALL wtm_parin
+!
+!--       Check if virtual flights should be carried out and read &flight_part
+!--       if required
+          CALL flight_parin
 
 !
Index: /palm/trunk/SOURCE/read_var_list.f90
===================================================================
--- /palm/trunk/SOURCE/read_var_list.f90	(revision 1956)
+++ /palm/trunk/SOURCE/read_var_list.f90	(revision 1957)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! ------------------
-!
+! flight module added
 !
 ! Former revisions:
@@ -176,4 +176,7 @@
     USE control_parameters
 
+    USE flight_mod,                                                            &
+        ONLY:  flight_read_restart_data
+    
     USE grid_variables,                                                        &
         ONLY:  dx, dy
@@ -507,4 +510,6 @@
           CASE ( 'nudging' )
              READ ( 13 )  nudging
+          CASE ( 'num_leg' )
+             READ ( 13 )  num_leg
           CASE ( 'nx' )
              READ ( 13 )  nx
@@ -725,4 +730,6 @@
           CASE ( 'vg_vertical_gradient_level_ind' )
              READ ( 13 )  vg_vertical_gradient_level_ind
+          CASE ( 'virtual_flight' )
+             READ ( 13 ) virtual_flight  
           CASE ( 'volume_flow_area' )
              READ ( 13 )  volume_flow_area
@@ -759,4 +766,6 @@
 
     ENDDO
+    
+    IF ( virtual_flight )  CALL flight_read_restart_data
 
 
@@ -988,5 +997,10 @@
  SUBROUTINE skip_var_list
 
-
+    USE control_parameters,                                                    &
+        ONLY:  virtual_flight
+ 
+    USE flight_mod,                                                            &
+        ONLY:  flight_skip_var_list
+ 
     IMPLICIT NONE
 
@@ -1007,5 +1021,9 @@
 
     ENDDO
-
+!
+!-- In case of virtual flights, skip also variables related to 
+!-- this module.
+    IF ( virtual_flight )  CALL flight_skip_var_list
+    
 
  END SUBROUTINE skip_var_list
Index: /palm/trunk/SOURCE/time_integration.f90
===================================================================
--- /palm/trunk/SOURCE/time_integration.f90	(revision 1956)
+++ /palm/trunk/SOURCE/time_integration.f90	(revision 1957)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! flight module added
 ! 
 ! Former revisions:
@@ -260,9 +260,13 @@
                time_run_control, time_since_reference_point,                   &
                turbulent_inflow, use_initial_profile_as_reference,             &
-               use_single_reference_value, u_gtrans, v_gtrans, ws_scheme_mom,  &
-               ws_scheme_sca
+               use_single_reference_value, u_gtrans, v_gtrans, virtual_flight, &
+               ws_scheme_mom, ws_scheme_sca
 
     USE cpulog,                                                                &
         ONLY:  cpu_log, log_point, log_point_s
+
+    USE flight_mod,                                                            &
+        ONLY:  flight_measurement
+
 
     USE indices,                                                               &
@@ -912,4 +916,6 @@
        time_since_reference_point = simulated_time - coupling_start_time
 
+
+
        IF ( simulated_time >= skip_time_data_output_av )  THEN
           time_do_av         = time_do_av       + dt_3d
@@ -1031,4 +1037,11 @@
                                  MAX( dt_averaging_input_pr, dt_3d ) )
           ENDIF
+       ENDIF
+
+!
+!--    Call flight module and output data
+       IF ( virtual_flight )  THEN
+          CALL flight_measurement
+          CALL data_output_flight
        ENDIF
 
Index: /palm/trunk/SOURCE/user_flight.f90
===================================================================
--- /palm/trunk/SOURCE/user_flight.f90	(revision 1957)
+++ /palm/trunk/SOURCE/user_flight.f90	(revision 1957)
@@ -0,0 +1,86 @@
+!> @file user_actions.f90
+!--------------------------------------------------------------------------------!
+! This file is part of PALM.
+!
+! PALM is free software: you can redistribute it and/or modify it under the terms
+! of the GNU General Public License as published by the Free Software Foundation,
+! either version 3 of the License, or (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2016 Leibniz Universitaet Hannover
+!--------------------------------------------------------------------------------!
+!
+! Current revisions:
+! ------------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+!
+! Description:
+! ------------
+!> Calculation of user-defined output quantity for flight measurements after 
+!> each timestep. 
+!------------------------------------------------------------------------------!
+ SUBROUTINE user_flight( var, id )
+
+    USE control_parameters
+    
+    USE grid_variables
+
+    USE indices
+
+    USE kinds
+
+    USE user
+
+    USE arrays_3d
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i  !< index along x
+    INTEGER(iwp) ::  j  !< index along y
+    INTEGER(iwp) ::  k  !< index along z
+    INTEGER(iwp) ::  id !< variable identifyer, according to the settings in user_init_flight
+        
+    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  var !< treated variable
+
+!
+!-- Here, the respective variable is calculated. There is no call of 
+!-- exchange_horiz necessary. 
+!-- The variable identifyer (id) must be set according to the settings in 
+!-- user_init_flight.
+!-- Please note, so far, variable must be located at the center of a grid box.
+!     var = 0.0_wp
+
+!     SELECT CASE ( id )
+! 
+!        CASE ( 1 )
+!           DO i = nxl-1, nxr+1
+!              DO j = nys-1, nyn+1
+!                 DO k = nzb, nzt
+!                    var(k,j,i) = ABS( u(k,j,i )
+!                 ENDDO
+!              ENDDO
+!           ENDDO
+!           
+!        CASE ( 2 )
+!           DO i = nxl-1, nxr+1
+!              DO j = nys-1, nyn+1
+!                 DO k = nzb, nzt
+!                    var(k,j,i) = ABS( v(k,j,i) )
+!                 ENDDO
+!              ENDDO
+!           ENDDO
+! 
+!     END SELECT
+
+
+ END SUBROUTINE user_flight
Index: /palm/trunk/SOURCE/user_init_flight.f90
===================================================================
--- /palm/trunk/SOURCE/user_init_flight.f90	(revision 1957)
+++ /palm/trunk/SOURCE/user_init_flight.f90	(revision 1957)
@@ -0,0 +1,92 @@
+!> @file user_init_flight.f90
+!--------------------------------------------------------------------------------!
+! This file is part of PALM.
+!
+! PALM is free software: you can redistribute it and/or modify it under the terms
+! of the GNU General Public License as published by the Free Software Foundation,
+! either version 3 of the License, or (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2016 Leibniz Universitaet Hannover
+!--------------------------------------------------------------------------------!
+!
+! Current revisions:
+! -----------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+!
+!
+! Description:
+! ------------
+!> Execution of user-defined initialization for flight measurements.
+!------------------------------------------------------------------------------!
+ SUBROUTINE user_init_flight( init, k, id, label_leg )
+ 
+
+    USE control_parameters
+    
+    USE indices
+    
+    USE kinds
+    
+    USE netcdf_interface,                                                      &
+        ONLY: dofl_label, dofl_unit
+    
+    USE user
+
+    IMPLICIT NONE
+    
+    CHARACTER(LEN=10), OPTIONAL ::  label_leg     !< label of the respective leg
+   
+    INTEGER(iwp), OPTIONAL                ::  id  !< variable index
+    INTEGER(iwp), OPTIONAL, INTENT(INOUT) ::  k   !< index for respective variable and leg
+    
+    LOGICAL ::  init  !< variable to recognize initial call 
+!
+!-- Sample for user-defined flight-time series.
+!-- For each quantity you have to give a label and a unit, which will be used
+!-- for the output into NetCDF file. They must not contain more than
+!-- twenty characters. 
+
+
+    IF ( init )  THEN
+!
+!--    The number of user-defined quantity has to be increased appropriately.
+!--    In the following example, 2 user-defined quantities are added.
+!        num_var_fl_user = num_var_fl_user + 2 
+
+       init = .FALSE.
+    
+    ELSE
+    
+!
+!--    Please add the respective number of new variables as following:
+      
+!        SELECT CASE ( id )
+!        
+!           CASE ( 1 )
+!              dofl_label(k)   = TRIM(label_leg) // '_' // 'abs_u'
+!              dofl_unit(k)    = 'm/s'
+!              k               = k + 1
+!              
+!           CASE ( 2 )
+!     
+!              dofl_label(k)   = TRIM(label_leg) // '_' // 'abs_v'
+!              dofl_unit(k)    = 'm/s'
+!              k               = k + 1
+!              
+!        END SELECT
+
+    ENDIF
+       
+ END SUBROUTINE user_init_flight
+
Index: /palm/trunk/SOURCE/virtual_flight_mod.f90
===================================================================
--- /palm/trunk/SOURCE/virtual_flight_mod.f90	(revision 1957)
+++ /palm/trunk/SOURCE/virtual_flight_mod.f90	(revision 1957)
@@ -0,0 +1,916 @@
+!> @file virtual_flights_mod.f90
+!--------------------------------------------------------------------------------!
+! This file is part of PALM.
+!
+! PALM is free software: you can redistribute it and/or modify it under the terms
+! of the GNU General Public License as published by the Free Software Foundation,
+! either version 3 of the License, or (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2016 Leibniz Universitaet Hannover
+!--------------------------------------------------------------------------------!
+!
+! Current revisions:
+! ------------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+!
+! 1241 2013-10-30 11:36:58Z heinze
+! Initial revision
+!
+! Description:
+! ------------
+!> Module for virtual flight measurements.
+!--------------------------------------------------------------------------------!
+ MODULE flight_mod
+ 
+    USE control_parameters,                                                    &
+        ONLY:  fl_max, num_leg, num_var_fl, num_var_fl_user, virtual_flight
+ 
+    USE kinds
+
+    CHARACTER(LEN=6), DIMENSION(fl_max) ::  leg_mode = 'cyclic'  !< flight mode through the model domain, either 'cyclic' or 'return' 
+
+    INTEGER(iwp) ::  l           !< index for flight leg
+    INTEGER(iwp) ::  var_index   !< index for measured variable
+
+    LOGICAL, DIMENSION(:), ALLOCATABLE  ::  cyclic_leg !< flag to identify fly mode
+
+    REAL(wp) ::  flight_end = 9999999.9_wp  !< end time of virtual flight
+    REAL(wp) ::  flight_begin = 0.0_wp      !< end time of virtual flight
+
+    REAL(wp), DIMENSION(fl_max) ::  flight_angle = 45.0_wp   !< angle determining the horizontal flight direction
+    REAL(wp), DIMENSION(fl_max) ::  flight_level = 100.0_wp  !< flight level 
+    REAL(wp), DIMENSION(fl_max) ::  max_elev_change = 0.0_wp !< maximum elevation change for the respective flight leg 
+    REAL(wp), DIMENSION(fl_max) ::  rate_of_climb = 0.0_wp   !< rate of climb or descent
+    REAL(wp), DIMENSION(fl_max) ::  speed_agl = 25.0_wp      !< absolute horizontal flight speed above ground level (agl)
+    REAL(wp), DIMENSION(fl_max) ::  x_start = 999999999.0_wp !< start x position 
+    REAL(wp), DIMENSION(fl_max) ::  x_end   = 999999999.0_wp !< end x position
+    REAL(wp), DIMENSION(fl_max) ::  y_start = 999999999.0_wp !< start y position
+    REAL(wp), DIMENSION(fl_max) ::  y_end   = 999999999.0_wp !< end y position
+
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  u_agl      !< u-component of flight speed
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  v_agl      !< v-component of flight speed
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  w_agl      !< w-component of flight speed
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  x_pos      !< aircraft x-position 
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  y_pos      !< aircraft y-position 
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  z_pos      !< aircraft z-position 
+
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  sensor_l !< measured data on local PE
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  sensor   !< measured data
+
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  var_u  !< dummy array for possibly user-defined quantities
+
+    SAVE
+
+    PRIVATE
+
+    INTERFACE flight_header
+       MODULE PROCEDURE flight_header
+    END INTERFACE flight_header
+    
+    INTERFACE flight_init
+       MODULE PROCEDURE flight_init
+    END INTERFACE flight_init
+
+    INTERFACE flight_init_output
+       MODULE PROCEDURE flight_init_output
+    END INTERFACE flight_init_output
+
+    INTERFACE flight_check_parameters
+       MODULE PROCEDURE flight_check_parameters
+    END INTERFACE flight_check_parameters
+
+    INTERFACE flight_parin
+       MODULE PROCEDURE flight_parin
+    END INTERFACE flight_parin
+
+    INTERFACE interpolate_xyz
+       MODULE PROCEDURE interpolate_xyz
+    END INTERFACE interpolate_xyz
+
+    INTERFACE flight_measurement
+       MODULE PROCEDURE flight_measurement
+    END INTERFACE flight_measurement
+    
+    INTERFACE flight_skip_var_list 
+       MODULE PROCEDURE flight_skip_var_list
+    END INTERFACE flight_skip_var_list
+    
+    INTERFACE flight_read_restart_data 
+       MODULE PROCEDURE flight_read_restart_data
+    END INTERFACE flight_read_restart_data
+    
+    INTERFACE flight_write_restart_data 
+       MODULE PROCEDURE flight_write_restart_data 
+    END INTERFACE flight_write_restart_data 
+
+!
+!-- Private interfaces
+    PRIVATE flight_check_parameters, flight_init_output, interpolate_xyz
+!
+!-- Public interfaces
+    PUBLIC flight_init, flight_header, flight_parin, flight_measurement,       &
+           flight_skip_var_list, flight_read_restart_data,                     &
+           flight_write_restart_data
+!
+!-- Public variables
+    PUBLIC fl_max, sensor, x_pos, y_pos, z_pos
+
+ CONTAINS
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Header output for flight module.
+!------------------------------------------------------------------------------!
+    SUBROUTINE flight_header ( io )
+
+    
+       IMPLICIT NONE
+
+       INTEGER(iwp), INTENT(IN) ::  io            !< Unit of the output file
+
+       WRITE ( io, 1  )
+       WRITE ( io, 2  )
+       WRITE ( io, 3  ) num_leg
+       WRITE ( io, 4  ) flight_begin
+       WRITE ( io, 5  ) flight_end
+       
+       DO l=1, num_leg
+          WRITE ( io, 6   ) l
+          WRITE ( io, 7   ) speed_agl(l)
+          WRITE ( io, 8   ) flight_level(l)
+          WRITE ( io, 9   ) max_elev_change(l)
+          WRITE ( io, 10  ) rate_of_climb(l)
+          WRITE ( io, 11  ) leg_mode(l)
+       ENDDO
+
+       
+     1   FORMAT (' Virtual flights:'/                                           &
+               ' ----------------')
+     2   FORMAT ('       Output every timestep')
+     3   FORMAT ('       Number of flight legs:',    I3                )
+     4   FORMAT ('       Begin of measurements:',    F10.1    , ' s'   )
+     5   FORMAT ('       End of measurements:',      F10.1    , ' s'   )
+     6   FORMAT ('       Leg', I3/,                                             &
+                '       ------' )
+     7   FORMAT ('          Flight speed            : ', F5.1, ' m/s' )
+     8   FORMAT ('          Flight level            : ', F5.1, ' m'   )
+     9   FORMAT ('          Maximum elevation change: ', F5.1, ' m/s' )
+     10  FORMAT ('          Rate of climb / descent : ', F5.1, ' m/s' )
+     11  FORMAT ('          Leg mode                : ', A/           )
+ 
+    END SUBROUTINE flight_header 
+ 
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Reads the namelist flight_par.
+!------------------------------------------------------------------------------!
+    SUBROUTINE flight_parin 
+
+    
+       IMPLICIT NONE
+
+       CHARACTER (LEN=80) ::  line  !< dummy string that contains the current line of the parameter file
+
+       NAMELIST /flight_par/  flight_angle, flight_end, flight_begin, leg_mode,&
+                              flight_level, max_elev_change, rate_of_climb,    &
+                              speed_agl, x_end, x_start, y_end, y_start
+                              
+!
+!--    Try to find the namelist flight_par
+       REWIND ( 11 )
+       line = ' '
+       DO   WHILE ( INDEX( line, '&flight_par' ) == 0 )
+          READ ( 11, '(A)', END=10 )  line
+       ENDDO
+       BACKSPACE ( 11 )
+
+!
+!--    Read namelist
+       READ ( 11, flight_par )
+!
+!--    Set switch that virtual flights shall be carried out
+       virtual_flight = .TRUE.
+
+ 10    CONTINUE
+
+    END SUBROUTINE flight_parin
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Inititalization of required arrays, number of legs and flags. Moreover,
+!> initialize flight speed and -direction, as well as start positions.
+!------------------------------------------------------------------------------!
+    SUBROUTINE flight_init
+ 
+       USE constants,                                                          &
+           ONLY:  pi
+    
+       USE control_parameters,                                                 &
+           ONLY:  initializing_actions 
+                  
+       USE indices,                                                            &
+           ONLY:  nxlg, nxrg, nysg, nyng, nzb, nzt
+
+       IMPLICIT NONE
+
+       REAL(wp) ::  distance  !< distance between start and end position of a flight leg
+!
+!--    Determine the number of flight legs
+       l = 1
+       DO WHILE ( x_start(l) /= 999999999.0_wp  .AND.  l <= SIZE(x_start) )
+          l       = l + 1
+       ENDDO
+       num_leg = l-1
+!
+!--    Check for proper parameter settings
+       CALL flight_check_parameters
+!
+!--    Allocate and initialize logical array for flight pattern
+       ALLOCATE( cyclic_leg(1:num_leg) )
+!
+!--    Initialize flags for cyclic/return legs
+       DO l = 1, num_leg
+          cyclic_leg(l) = MERGE( .TRUE., .FALSE.,                              &
+                                 TRIM( leg_mode(l) ) == 'cyclic'               &
+                               )
+       ENDDO
+!
+!--    Allocate and initialize arraxs for flight position and speed. In case of 
+!--    restart runs these data are read by the routine read_flight_restart_data
+!--    instead.
+       IF (  TRIM( initializing_actions ) /= 'read_restart_data' )  THEN 
+       
+          ALLOCATE( x_pos(1:num_leg), y_pos(1:num_leg ), z_pos(1:num_leg) )
+!
+!--       Inititalize x-, y-, and z-positions with initial start position          
+          x_pos(1:num_leg) = x_start(1:num_leg)
+          y_pos(1:num_leg) = y_start(1:num_leg)
+          z_pos(1:num_leg) = flight_level(1:num_leg)
+!
+!--       Allocate arrays for flight-speed components
+          ALLOCATE( u_agl(1:num_leg),                                          &
+                    v_agl(1:num_leg),                                          &
+                    w_agl(1:num_leg) )
+!
+!--       Inititalize u-, v- and w-component. 
+          DO  l = 1, num_leg
+!
+!--          In case of return-legs, the flight direction, i.e. the horizontal
+!--          flight-speed components, are derived from the given start/end 
+!--          positions.
+             IF (  .NOT.  cyclic_leg(l) )  THEN
+                distance = SQRT( ( x_end(l) - x_start(l) )**2                  &
+                               + ( y_end(l) - y_start(l) )**2 )
+                u_agl(l) = speed_agl(l) * ( x_end(l) - x_start(l) ) / distance
+                v_agl(l) = speed_agl(l) * ( y_end(l) - y_start(l) ) / distance
+                w_agl(l) = rate_of_climb(l)
+!
+!--          In case of cyclic-legs, flight direction is directly derived from 
+!--          the given flight angle.
+             ELSE
+                u_agl(l) = speed_agl(l) * COS( flight_angle(l) * pi / 180.0_wp )
+                v_agl(l) = speed_agl(l) * SIN( flight_angle(l) * pi / 180.0_wp )
+                w_agl(l) = rate_of_climb(l)
+             ENDIF
+
+          ENDDO
+             
+       ENDIF    
+!
+!--    Initialized data output
+       CALL flight_init_output       
+!
+!--    Allocate array required for user-defined quantities if necessary.
+       IF ( num_var_fl_user  > 0 )                                             &
+          ALLOCATE( var_u(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+!
+!--    Allocate and initialize arrays containing the measured data
+       ALLOCATE( sensor_l(1:num_var_fl,1:num_leg) )
+       ALLOCATE( sensor(1:num_var_fl,1:num_leg)   )
+       sensor_l = 0.0_wp
+       sensor   = 0.0_wp
+
+    END SUBROUTINE flight_init
+    
+    
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Initialization of output-variable names and units.
+!------------------------------------------------------------------------------!
+    SUBROUTINE flight_init_output
+    
+       USE control_parameters,                                                 &
+          ONLY:  cloud_droplets, cloud_physics, humidity, neutral,             &
+                 passive_scalar
+          
+       USE netcdf_interface
+    
+       IMPLICIT NONE
+
+       CHARACTER(LEN=10) ::  label_leg  !< dummy argument to convert integer to string
+       
+       INTEGER(iwp) ::  i               !< loop variable
+       INTEGER(iwp) ::  k               !< index variable
+       
+       LOGICAL      ::  init = .TRUE.   !< flag to distiquish calls of user_init_flight
+!
+!--    Define output quanities, at least three variables are measured (u,v,w)
+       num_var_fl = 3
+       IF ( .NOT. neutral )                      num_var_fl = num_var_fl + 1
+       IF ( humidity .OR. passive_scalar )       num_var_fl = num_var_fl + 1
+       IF ( cloud_physics .OR. cloud_droplets )  num_var_fl = num_var_fl + 1  
+!
+!--    Write output strings for dimensions x, y, z
+       DO l=1, num_leg
+
+          IF ( l < 10                    )  WRITE( label_leg, '(I1)')  l
+          IF ( l >= 10   .AND.  l < 100  )  WRITE( label_leg, '(I2)')  l
+          IF ( l >= 100  .AND.  l < 1000 )  WRITE( label_leg, '(I3)')  l
+
+          dofl_dim_label_x(l)  = 'x_' // TRIM( label_leg )
+          dofl_dim_label_y(l)  = 'y_' // TRIM( label_leg )
+          dofl_dim_label_z(l)  = 'z_' // TRIM( label_leg )
+
+       ENDDO
+       
+!
+!--    Call user routine to initialize further variables
+       CALL user_init_flight( init )
+!
+!--    Write output labels and units for the quanities
+       k = 1
+       DO l=1, num_leg
+       
+          IF ( l < 10                    )  WRITE( label_leg, '(I1)')  l
+          IF ( l >= 10   .AND.  l < 100  )  WRITE( label_leg, '(I2)')  l
+          IF ( l >= 100  .AND.  l < 1000 )  WRITE( label_leg, '(I3)')  l
+          
+          label_leg = 'leg_' // TRIM(label_leg) 
+          DO i=1, num_var_fl
+
+             SELECT CASE ( i )
+                      
+                CASE( 1 )
+                   dofl_label(k) = TRIM( label_leg ) // '_u'
+                   dofl_unit(k)  = 'm/s'
+                   k             = k + 1
+
+                CASE( 2 )
+                   dofl_label(k) = TRIM( label_leg ) // '_v'
+                   dofl_unit(k)  = 'm/s'
+                   k             = k + 1
+
+                CASE( 3 )
+                   dofl_label(k) = TRIM( label_leg ) // '_w'
+                   dofl_unit(k)  = 'm/s'
+                   k             = k + 1
+
+                CASE( 4 )
+                   dofl_label(k) = TRIM( label_leg ) // '_pt'
+                   dofl_unit(k)  = 'K'
+                   k             = k + 1
+
+                CASE( 5 )
+                   dofl_label(k) = TRIM( label_leg ) // '_q'
+                   dofl_unit(k)  = 'kg/kg'
+                   k             = k + 1
+
+                CASE( 6 )
+                   dofl_label(k) = TRIM( label_leg ) // '_ql'
+                   dofl_unit(k)  = 'kg/kg'
+                   k             = k + 1
+
+             END SELECT
+
+          ENDDO
+          
+          DO i=1, num_var_fl_user
+             CALL user_init_flight( init, k, i, label_leg )
+          ENDDO
+          
+       ENDDO 
+!
+!--    Finally, set the total number of flight-output quantities.
+       num_var_fl = num_var_fl + num_var_fl_user
+       
+    END SUBROUTINE flight_init_output
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This routine calculates the current flight positions and calls the 
+!> respective interpolation routine to measures the data at the current 
+!> flight position.
+!------------------------------------------------------------------------------!
+    SUBROUTINE flight_measurement
+
+       USE arrays_3d,                                                          &
+           ONLY:  ddzu, ddzw, pt, q, ql, u, v, w, zu, zw
+
+       USE control_parameters,                                                 &
+           ONLY:  cloud_droplets, cloud_physics, dz, dz_stretch_level, dt_3d,  &
+                  humidity, neutral, passive_scalar, simulated_time
+                  
+       USE cpulog,                                                             &
+           ONLY:  cpu_log, log_point
+
+       USE grid_variables,                                                     &
+           ONLY:  ddx, ddy, dx, dy
+
+       USE indices,                                                            &
+           ONLY:  nx, nxl, nxlg, nxr, nxrg, ny, nys, nysg, nyn, nyng, nzb, nzt
+
+       USE pegrid
+
+       IMPLICIT NONE
+
+       LOGICAL  ::  on_pe  !< flag to check if current flight position is on current PE
+
+       REAL(wp) ::  x  !< distance between left edge of current grid box and flight position
+       REAL(wp) ::  y  !< distance between south edge of current grid box and flight position
+
+       INTEGER(iwp) ::  i   !< index of current grid box along x
+       INTEGER(iwp) ::  j   !< index of current grid box along y
+       INTEGER(iwp) ::  n   !< loop variable for number of user-defined output quantities
+       
+       CALL cpu_log( log_point(65), 'flight_measurement', 'start' )
+!
+!--    Perform flight measurement if start time is reached.
+       IF ( simulated_time >= flight_begin  .AND.                              &
+            simulated_time <= flight_end )  THEN
+
+          sensor_l = 0.0_wp
+          sensor   = 0.0_wp
+!
+!--       Loop over all flight legs
+          DO l=1, num_leg
+!
+!--          Update location for each leg
+             x_pos(l) = x_pos(l) + u_agl(l) * dt_3d 
+             y_pos(l) = y_pos(l) + v_agl(l) * dt_3d 
+             z_pos(l) = z_pos(l) + w_agl(l) * dt_3d
+!
+!--          Check if location must be modified for return legs.  
+!--          Carry out horizontal reflection if required.
+             IF ( .NOT. cyclic_leg(l) )  THEN
+!
+!--             Outward flight, i.e. from start to end
+                IF ( u_agl(l) >= 0.0_wp  .AND.  x_pos(l) > x_end(l)      )  THEN
+                   x_pos(l) = 2.0_wp * x_end(l)   - x_pos(l)
+                   u_agl(l) = - u_agl(l)
+!
+!--             Return flight, i.e. from end to start
+                ELSEIF ( u_agl(l) < 0.0_wp  .AND.  x_pos(l) < x_start(l) )  THEN 
+                   x_pos(l) = 2.0_wp * x_start(l) - x_pos(l)
+                   u_agl(l) = - u_agl(l)
+                ENDIF
+!
+!--             Outward flight, i.e. from start to end
+                IF ( v_agl(l) >= 0.0_wp  .AND.  y_pos(l) > y_end(l)      )  THEN
+                   y_pos(l) = 2.0_wp * y_end(l)   - y_pos(l)
+                   v_agl(l) = - v_agl(l)
+!
+!--             Return flight, i.e. from end to start                  
+                ELSEIF ( v_agl(l) < 0.0_wp  .AND.  y_pos(l) < y_start(l) )  THEN 
+                   y_pos(l) = 2.0_wp * y_start(l) - y_pos(l)
+                   v_agl(l) = - v_agl(l)
+                ENDIF
+!
+!--          Check if flight position is out of the model domain and apply
+!--          cyclic conditions if required
+             ELSEIF ( cyclic_leg(l) )  THEN
+!
+!--             Check if aircraft leaves the model domain at the right boundary
+                IF ( ( flight_angle(l) >= 0.0_wp     .AND.                     &
+                       flight_angle(l) <= 90.0_wp )  .OR.                      &  
+                     ( flight_angle(l) >= 270.0_wp   .AND.                     &
+                       flight_angle(l) <= 360.0_wp ) )  THEN
+                   IF ( x_pos(l) >= ( nx + 0.5_wp ) * dx )                     &
+                      x_pos(l) = x_pos(l) - ( nx + 1 ) * dx 
+!
+!--             Check if aircraft leaves the model domain at the left boundary
+                ELSEIF ( flight_angle(l) > 90.0_wp  .AND.                      &
+                         flight_angle(l) < 270.0_wp )  THEN
+                   IF ( x_pos(l) < -0.5_wp * dx )                             &
+                      x_pos(l) = ( nx + 1 ) * dx + x_pos(l)  
+                ENDIF 
+!
+!--             Check if aircraft leaves the model domain at the north boundary
+                IF ( flight_angle(l) >= 0.0_wp  .AND.                          &
+                     flight_angle(l) <= 180.0_wp )  THEN
+                   IF ( y_pos(l) >= ( ny + 0.5_wp ) * dy )                     &
+                      y_pos(l) = y_pos(l) - ( ny + 1 ) * dy 
+!
+!--             Check if aircraft leaves the model domain at the south boundary
+                ELSEIF ( flight_angle(l) > 180.0_wp  .AND.                     &
+                         flight_angle(l) < 360.0_wp )  THEN
+                   IF ( y_pos(l) < -0.5_wp * dy )                              &
+                      y_pos(l) = ( ny + 1 ) * dy + y_pos(l) 
+                ENDIF
+                
+             ENDIF
+!
+!--          Check if maximum elevation change is already reached. If required
+!--          reflect vertically.
+             IF ( rate_of_climb(l) /= 0.0_wp )  THEN
+!
+!--             First check if aircraft is too high
+                IF (  w_agl(l) > 0.0_wp  .AND.                                 &
+                      z_pos(l) - flight_level(l) > max_elev_change(l) )  THEN
+                   z_pos(l) = 2.0_wp * ( flight_level(l) + max_elev_change(l) )&
+                              - z_pos(l)
+                   w_agl(l) = - w_agl(l)
+!
+!--             Check if aircraft is too low
+                ELSEIF (  w_agl(l) < 0.0_wp  .AND.  z_pos(l) < flight_level(l) )  THEN
+                   z_pos(l) = 2.0_wp * flight_level(l) - z_pos(l)
+                   w_agl(l) = - w_agl(l)
+                ENDIF
+                
+             ENDIF 
+!
+!--          Determine grid indices for flight position along x- and y-direction.
+!--          Please note, there is a special treatment for the index 
+!--          along z-direction, which is due to vertical grid stretching. 
+             i = ( x_pos(l) + 0.5_wp * dx ) * ddx
+             j = ( y_pos(l) + 0.5_wp * dy ) * ddy
+!
+!--          Check if indices are on current PE
+             on_pe = ( i >= nxl  .AND.  i <= nxr  .AND.                        &
+                       j >= nys  .AND.  j <= nyn )
+
+             IF ( on_pe )  THEN
+
+                var_index = 1
+!
+!--             Recalculate indices, as u is shifted by -0.5*dx.
+                i =   x_pos(l) * ddx
+                j = ( y_pos(l) + 0.5_wp * dy ) * ddy
+!
+!--             Calculate distance from left and south grid-box edges.
+                x  = x_pos(l) - ( 0.5_wp - i ) * dx
+                y  = y_pos(l) - j * dy
+!
+!--             Interpolate u-component onto current flight position.
+                CALL interpolate_xyz( u, zu, ddzu, 1.0_wp, x, y, var_index, j, i )
+                var_index = var_index + 1
+!
+!--             Recalculate indices, as v is shifted by -0.5*dy.
+                i = ( x_pos(l) + 0.5_wp * dx ) * ddx
+                j =   y_pos(l) * ddy
+
+                x  = x_pos(l) - i * dx
+                y  = y_pos(l) - ( 0.5_wp - j ) * dy
+                CALL interpolate_xyz( v, zu, ddzu, 1.0_wp, x, y, var_index, j, i )
+                var_index = var_index + 1
+!
+!--             Interpolate w and scalar quantities. Recalculate indices.
+                i  = ( x_pos(l) + 0.5_wp * dx ) * ddx
+                j  = ( y_pos(l) + 0.5_wp * dy ) * ddy
+                x  = x_pos(l) - i * dx
+                y  = y_pos(l) - j * dy
+!
+!--             Interpolate w-velocity component.
+                CALL interpolate_xyz( w, zw, ddzw, 0.0_wp, x, y, var_index, j, i )
+                var_index = var_index + 1
+!
+!--             Potential temerature
+                IF ( .NOT. neutral )  THEN
+                   CALL interpolate_xyz( pt, zu, ddzu, 1.0_wp, x, y, var_index, j, i )
+                   var_index = var_index + 1
+                ENDIF
+!
+!--             Humidity or passive scalar
+                IF ( humidity .OR. passive_scalar )  THEN
+                   CALL interpolate_xyz( q, zu, ddzu, 1.0_wp, x, y, var_index, j, i )
+                   var_index = var_index + 1
+                ENDIF
+!
+!--             Liquid water content
+                IF ( cloud_physics .OR. cloud_droplets )  THEN
+                   CALL interpolate_xyz( ql, zu, ddzu, 1.0_wp, x, y, var_index, j, i )
+                   var_index = var_index + 1
+                ENDIF
+!
+!--             Treat user-defined variables if required
+                DO n = 1, num_var_fl_user                
+                   CALL user_flight( var_u, n )
+                   CALL interpolate_xyz( var_u, zu, ddzu, 1.0_wp, x, y, var_index, j, i )
+                   var_index = var_index + 1
+                ENDDO
+             ENDIF
+
+          ENDDO
+!
+!--       Write local data on global array.
+#if defined( __parallel )
+          CALL MPI_ALLREDUCE(sensor_l(1,1), sensor(1,1),                       &
+                             num_var_fl*num_leg, MPI_REAL, MPI_SUM,               &
+                             comm2d, ierr )
+#else
+          sensor     = sensor_l
+#endif
+       ENDIF
+       
+       CALL cpu_log( log_point(65), 'flight_measurement', 'stop' )
+
+    END SUBROUTINE flight_measurement
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This subroutine bi-linearly interpolates the respective data onto the current
+!> flight position.
+!------------------------------------------------------------------------------!
+    SUBROUTINE interpolate_xyz( var, z_uw, ddz_uw, fac, x, y, var_ind, j, i )
+
+       USE control_parameters,                                                 &
+           ONLY:  dz, dz_stretch_level   
+  
+      USE grid_variables,                                                     &
+          ONLY:  dx, dy
+    
+       USE indices,                                                            &
+           ONLY:  nzb, nzt, nxlg, nxrg, nysg, nyng
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i        !< index along x
+       INTEGER(iwp) ::  j        !< index along y
+       INTEGER(iwp) ::  k        !< index along z
+       INTEGER(iwp) ::  k1       !< dummy variable
+       INTEGER(iwp) ::  var_ind  !< index variable for output quantity
+
+       REAL(wp) ::  aa        !< dummy argument for horizontal interpolation   
+       REAL(wp) ::  bb        !< dummy argument for horizontal interpolation
+       REAL(wp) ::  cc        !< dummy argument for horizontal interpolation
+       REAL(wp) ::  dd        !< dummy argument for horizontal interpolation
+       REAL(wp) ::  gg        !< dummy argument for horizontal interpolation
+       REAL(wp) ::  fac       !< flag to indentify if quantity is on zu or zw level
+       REAL(wp) ::  var_int   !< horizontal interpolated variable at current position
+       REAL(wp) ::  var_int_l !< horizontal interpolated variable at k-level
+       REAL(wp) ::  var_int_u !< horizontal interpolated variable at (k+1)-level
+       REAL(wp) ::  x         !< distance between left edge of current grid box and flight position
+       REAL(wp) ::  y         !< distance between south edge of current grid box and flight position
+
+       REAL(wp), DIMENSION(1:nzt+1)   ::  ddz_uw !< inverse vertical grid spacing
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  z_uw   !< height level
+
+       REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  var !< treted quantity
+!
+!--    Calculate interpolation coefficients
+       aa = x**2          + y**2
+       bb = ( dx - x )**2 + y**2
+       cc = x**2          + ( dy - y )**2
+       dd = ( dx - x )**2 + ( dy - y )**2
+       gg = aa + bb + cc + dd
+!
+!--    Obtain vertical index. Special treatment for grid index along z-direction
+!--    if flight position is above the vertical grid-stretching level.
+!--    fac=1 if variable is on scalar grid level, fac=0 for w-component.
+       IF ( z_pos(l) < dz_stretch_level )  THEN
+          k = ( z_pos(l) + fac * 0.5_wp * dz ) / dz
+       ELSE
+!
+!--       Search for k-index
+          DO k1=nzb, nzt
+             IF ( z_pos(l) >= z_uw(k1) .AND. z_pos(l) < z_uw(k1+1) )  THEN
+                k = k1
+                EXIT
+             ENDIF                   
+          ENDDO
+       ENDIF
+!
+!--    (x,y)-interpolation at k-level
+       var_int_l = ( ( gg - aa ) * var(k,j,i)       +                          &
+                     ( gg - bb ) * var(k,j,i+1)     +                          &
+                     ( gg - cc ) * var(k,j+1,i)     +                          &
+                     ( gg - dd ) * var(k,j+1,i+1)                              &
+                   ) / ( 3.0_wp * gg )
+!
+!--    (x,y)-interpolation on (k+1)-level
+       var_int_u = ( ( gg - aa ) * var(k+1,j,i)     +                          &
+                     ( gg - bb ) * var(k+1,j,i+1)   +                          &
+                     ( gg - cc ) * var(k+1,j+1,i)   +                          &
+                     ( gg - dd ) * var(k+1,j+1,i+1)                            &
+                   ) / ( 3.0_wp * gg )
+!
+!--    z-interpolation onto current flight postion
+       var_int = var_int_l                                                     &
+                           + ( z_pos(l) - z_uw(k) ) * ddz_uw(k+1)              &
+                           * (var_int_u - var_int_l )
+!
+!--    Store on local data array
+       sensor_l(var_ind,l) = var_int
+
+    END SUBROUTINE interpolate_xyz
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Perform parameter checks.
+!------------------------------------------------------------------------------!
+    SUBROUTINE flight_check_parameters
+
+       USE arrays_3d,                                                          &
+           ONLY:  zu
+    
+       USE control_parameters,                                                 &
+           ONLY:  bc_lr_cyc, bc_ns_cyc, dz, message_string
+
+       USE grid_variables,                                                     &
+           ONLY:  dx, dy   
+          
+       USE indices,                                                            &
+           ONLY:  nx, ny, nz
+           
+       USE netcdf_interface,                                                   &
+           ONLY:  netcdf_data_format
+
+       IMPLICIT NONE
+       
+!
+!--    Check if start positions are properly set.
+       DO l=1, num_leg
+          IF ( x_start(l) < 0.0_wp  .OR.  x_start(l) > ( nx + 1 ) * dx )  THEN
+             message_string = 'Start x position is outside the model domain'
+             CALL message( 'flight_check_parameters', 'PA0431', 1, 2, 0, 6, 0 )
+          ENDIF 
+          IF ( y_start(l) < 0.0_wp  .OR.  y_start(l) > ( ny + 1 ) * dy )  THEN
+             message_string = 'Start y position is outside the model domain'
+             CALL message( 'flight_check_parameters', 'PA0432', 1, 2, 0, 6, 0 )
+          ENDIF 
+
+       ENDDO
+!
+!--    Check for leg mode
+       DO l=1, num_leg
+!
+!--       Check if leg mode matches the overall lateral model boundary 
+!--       conditions.
+          IF ( TRIM( leg_mode(l) ) == 'cyclic' )  THEN
+             IF ( .NOT. bc_lr_cyc  .OR.  .NOT. bc_ns_cyc )  THEN
+                message_string = 'Cyclic flight leg does not match ' //        &
+                                 'lateral boundary condition'
+                CALL message( 'flight_check_parameters', 'PA0433', 1, 2, 0, 6, 0 )
+             ENDIF 
+!
+!--       Check if end-positions are inside the model domain in case of 
+!..       return-legs.  
+          ELSEIF ( TRIM( leg_mode(l) ) == 'return' )  THEN
+             IF ( x_end(l) > ( nx + 1 ) * dx  .OR.                             &
+                  y_end(l) > ( ny + 1 ) * dx )  THEN
+                message_string = 'Flight leg or parts of it are outside ' //   &
+                                 'the model domain'
+                CALL message( 'flight_check_parameters', 'PA0434', 1, 2, 0, 6, 0 )
+             ENDIF 
+          ELSE
+             message_string = 'Unknown flight mode'
+             CALL message( 'flight_check_parameters', 'PA0435', 1, 2, 0, 6, 0 )
+          ENDIF
+
+       ENDDO          
+!
+!--    Check if start and end positions are properly set in case of return legs.
+       DO l=1, num_leg
+
+          IF ( x_start(l) > x_end(l) .AND. leg_mode(l) == 'return' )  THEN
+             message_string = 'x_start position must be <= x_end ' //          &
+                              'position for return legs'
+             CALL message( 'flight_check_parameters', 'PA0436', 1, 2, 0, 6, 0 )
+          ENDIF 
+          IF ( y_start(l) > y_end(l) .AND. leg_mode(l) == 'return' )  THEN
+             message_string = 'y_start position must be <= y_end ' //          &
+                              'position for return legs'
+             CALL message( 'flight_check_parameters', 'PA0437', 1, 2, 0, 6, 0 )
+          ENDIF 
+       ENDDO
+!
+!--    Check if given flight object remains inside model domain if a rate of 
+!--    climb / descent is prescribed. 
+       DO l=1, num_leg
+          IF ( flight_level(l) + max_elev_change(l) > zu(nz) .OR.              &
+               flight_level(l) + max_elev_change(l) <= 0.0_wp )  THEN
+             message_string = 'Flight level is outside the model domain '
+             CALL message( 'flight_check_parameters', 'PA0438', 1, 2, 0, 6, 0 )
+          ENDIF 
+       ENDDO       
+!
+!--    Check for appropriate NetCDF format. Definition of more than one 
+!--    unlimited dimension is unfortunately only possible with NetCDF4/HDF5. 
+       IF (  netcdf_data_format <= 2 )  THEN
+          message_string = 'netcdf_data_format must be > 2'
+          CALL message( 'flight_check_parameters', 'PA0439', 1, 2, 0, 6, 0 )
+       ENDIF
+
+
+    END SUBROUTINE flight_check_parameters
+    
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Skipping the flight-module variables from restart-file (binary format).
+!------------------------------------------------------------------------------!
+    SUBROUTINE flight_skip_var_list  
+           
+       IMPLICIT NONE
+       
+       CHARACTER (LEN=1)  ::  cdum
+       CHARACTER (LEN=30) ::  variable_chr
+       
+       READ ( 13 )  variable_chr
+       DO  WHILE ( TRIM( variable_chr ) /= '*** end flight ***' )
+          READ ( 13 )  cdum
+          READ ( 13 )  variable_chr
+       ENDDO    
+       
+    END SUBROUTINE flight_skip_var_list  
+   
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This routine reads the respective restart data.
+!------------------------------------------------------------------------------!
+    SUBROUTINE flight_read_restart_data  
+
+    
+       IMPLICIT NONE
+       
+       CHARACTER (LEN=30) ::  variable_chr !< dummy variable to read string
+       
+       
+       READ ( 13 )  variable_chr
+       DO  WHILE ( TRIM( variable_chr ) /= '*** end flight ***' )
+
+          SELECT CASE ( TRIM( variable_chr ) )
+          
+             CASE ( 'u_agl' )
+                IF ( .NOT. ALLOCATED( u_agl ) )  ALLOCATE( u_agl(1:num_leg) )
+                READ ( 13 )  u_agl   
+             CASE ( 'v_agl' )
+                IF ( .NOT. ALLOCATED( v_agl ) )  ALLOCATE( v_agl(1:num_leg) )
+                READ ( 13 )  v_agl
+             CASE ( 'w_agl' )
+                IF ( .NOT. ALLOCATED( w_agl ) )  ALLOCATE( w_agl(1:num_leg) )
+                READ ( 13 )  w_agl
+             CASE ( 'x_pos' )
+                IF ( .NOT. ALLOCATED( x_pos ) )  ALLOCATE( x_pos(1:num_leg) )
+                READ ( 13 )  x_pos
+             CASE ( 'y_pos' )
+                IF ( .NOT. ALLOCATED( y_pos ) )  ALLOCATE( y_pos(1:num_leg) )
+                READ ( 13 )  y_pos
+             CASE ( 'z_pos' )
+                IF ( .NOT. ALLOCATED( z_pos ) )  ALLOCATE( z_pos(1:num_leg) )
+                READ ( 13 )  z_pos
+          
+          END SELECT
+          
+          READ ( 13 )  variable_chr
+          
+       ENDDO
+
+    END SUBROUTINE flight_read_restart_data  
+    
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This routine writes the respective restart data.
+!------------------------------------------------------------------------------!
+    SUBROUTINE flight_write_restart_data  
+
+       IMPLICIT NONE
+       
+       WRITE ( 14 )  'u_agl                         '
+       WRITE ( 14 )  u_agl       
+       WRITE ( 14 )  'v_agl                         '
+       WRITE ( 14 )  v_agl
+       WRITE ( 14 )  'w_agl                         '
+       WRITE ( 14 )  w_agl
+       WRITE ( 14 )  'x_pos                         '
+       WRITE ( 14 )  x_pos
+       WRITE ( 14 )  'y_pos                         '
+       WRITE ( 14 )  y_pos
+       WRITE ( 14 )  'z_pos                         '
+       WRITE ( 14 )  z_pos
+       
+       WRITE ( 14 )  '*** end flight ***            '
+       
+    END SUBROUTINE flight_write_restart_data    
+    
+
+ END MODULE flight_mod
Index: /palm/trunk/SOURCE/write_var_list.f90
===================================================================
--- /palm/trunk/SOURCE/write_var_list.f90	(revision 1956)
+++ /palm/trunk/SOURCE/write_var_list.f90	(revision 1957)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! -----------------
-!
+! flight module added
 !
 ! Former revisions:
@@ -154,4 +154,7 @@
 
     USE control_parameters
+    
+    USE flight_mod,                                                            &
+        ONLY:  flight_write_restart_data
     
     USE grid_variables,                                                        &
@@ -418,4 +421,6 @@
     WRITE ( 14 )  'nudging                       '
     WRITE ( 14 )  nudging
+    WRITE ( 14 )  'num_leg                       '
+    WRITE ( 14 )  num_leg
     WRITE ( 14 )  'nx                            '
     WRITE ( 14 )  nx
@@ -632,4 +637,6 @@
     WRITE ( 14 )  'vg_vertical_gradient_level_ind'
     WRITE ( 14 )  vg_vertical_gradient_level_ind
+    WRITE ( 14 )  'virtual_flight                '
+    WRITE ( 14 )  virtual_flight
     WRITE ( 14 )  'volume_flow_area              '
     WRITE ( 14 )  volume_flow_area
@@ -653,10 +660,12 @@
     WRITE ( 14 )  zeta_min
     WRITE ( 14 )  'z0h_factor                    '
-    WRITE ( 14 )  z0h_factor
-
+    WRITE ( 14 )  z0h_factor  
 !
 !-- Set the end-of-file mark
     WRITE ( 14 )  '*** end ***                   '
-
-
+!
+!-- If required, write restart data for virtual measurements.
+    IF ( virtual_flight )  CALL flight_write_restart_data  
+    
+    
  END SUBROUTINE write_var_list
