Index: palm/trunk/UTIL/combine_virtual_measurements/combine_virtual_measurements.f90
===================================================================
--- palm/trunk/UTIL/combine_virtual_measurements/combine_virtual_measurements.f90	(revision 3705)
+++ palm/trunk/UTIL/combine_virtual_measurements/combine_virtual_measurements.f90	(revision 3928)
@@ -25,6 +25,11 @@
 ! -----------------
 ! $Id$
+! rename subroutines
+! remove space dimensions; add positions dimension
+! add output path to namelist
+!
+! 3705 2019-01-29 19:56:39Z suehring
 ! Initial revsion
-! 
+!
 ! 3704 2019-01-29 19:51:41Z suehring
 !
@@ -37,28 +42,29 @@
 ! Description:
 ! ------------
-!> This routines merges binary output from virtual measurements taken from 
+!> This routines merges binary output from virtual measurements taken from
 !> different subdomains and creates a NetCDF output file according to the (UC)2
-!> data standard. 
+!> data standard.
 !------------------------------------------------------------------------------!
  PROGRAM combine_virtual_measurements
- 
-#if defined( __netcdf )  
+
+#if defined( __netcdf )
     USE NETCDF
 #endif
- 
+
     IMPLICIT NONE
-    
+
     CHARACTER(LEN=34)  ::  char_in                !< dummy string
-    CHARACTER(LEN=4)   ::  file_suffix = '.bin'   !< string which contain the suffix indicating virtual measurement data  
+    CHARACTER(LEN=4)   ::  file_suffix = '.bin'   !< string which contain the suffix indicating virtual measurement data
     CHARACTER(LEN=30)  ::  myid_char              !< combined string indicating binary file
-    CHARACTER(LEN=100) ::  path                   !< path to the binary data 
+    CHARACTER(LEN=100) ::  path_input             !< path to the binary input data
+    CHARACTER(LEN=100) ::  path_output            !< path to the netcdf output files
     CHARACTER(LEN=100) ::  run                    !< name of the run
-    
+
     CHARACTER(LEN=100), DIMENSION(:),   ALLOCATABLE ::  site          !< name of the site
     CHARACTER(LEN=100), DIMENSION(:),   ALLOCATABLE ::  filename      !< name of the original file
     CHARACTER(LEN=100), DIMENSION(:),   ALLOCATABLE ::  feature_type  !< string indicating the type of the measurement
     CHARACTER(LEN=100), DIMENSION(:),   ALLOCATABLE ::  soil_quantity !< string indicating soil measurements
-    CHARACTER(LEN=10),  DIMENSION(:,:), ALLOCATABLE ::  variables     !< list of measured variables 
-    
+    CHARACTER(LEN=10),  DIMENSION(:,:), ALLOCATABLE ::  variables     !< list of measured variables
+
     CHARACTER(LEN=6), DIMENSION(5) ::  soil_quantities = (/                   & !< list of measurable soil variables
                             "t_soil",                                         &
@@ -67,11 +73,11 @@
                             "lwcs  ",                                         &
                             "smp   "                    /)
-    
+
     INTEGER, PARAMETER ::  iwp = 4                !< integer precision
     INTEGER, PARAMETER ::  wp  = 8                !< float precision
-    
+
     INTEGER(iwp) ::  cycle_number                 !< cycle number
     INTEGER(iwp) ::  f                            !< running index over all binary files
-    INTEGER(iwp) ::  file_id_in = 18              !< file unit for input binaray file    
+    INTEGER(iwp) ::  file_id_in = 18              !< file unit for input binaray file
     INTEGER(iwp) ::  l                            !< running index indicating the actual site
     INTEGER(iwp) ::  n                            !< running index over all variables measured at a site
@@ -79,19 +85,15 @@
     INTEGER(iwp) ::  nvm                          !< number of sites
     INTEGER(iwp) ::  status_nc                    !< NetCDF error code, return value
-       
+
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  ns           !< number of observation coordinates on current subdomain
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  ns_tot       !< total number of observation coordinates for a site 
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  ns_tot       !< total number of observation coordinates for a site
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  ns_soil      !< number of observation coordinates for soil quantities (on current subdomain)
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  ns_soil_tot  !< total number of observation coordinates for a site (for the soil)
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  nvar         !< number of sampled variables at a site 
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  nvar         !< number of sampled variables at a site
 !
 !-- NetCDF varialbes
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  nc_id                 !< NetCDF file ID
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_eutm               !< NetCDF dimension ID for E_UTM
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_nutm               !< NetCDF dimension ID for N_UTM
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_hao                !< NetCDF dimension ID for the height coordinate
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_eutm_soil          !< NetCDF dimension ID for E_UTM for soil quantity
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_nutm_soil          !< NetCDF dimension ID for N_UTM for soil quantity
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_depth              !< NetCDF dimension ID for soil depth
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_position           !< NetCDF dimension ID for vm position
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_position_soil      !< NetCDF dimension ID for vm position in soil
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_time               !< NetCDF dimension ID for time
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_var_eutm           !< NetCDF variable ID for E_UTM
@@ -100,15 +102,15 @@
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_var_eutm_soil      !< NetCDF variable ID for E_UTM for soil quantity
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_var_nutm_soil      !< NetCDF variable ID for N_UTM for soil quantity
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_var_depth          !< NetCDF variable ID for soil depth 
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_var_depth          !< NetCDF variable ID for soil depth
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  id_var_time           !< NetCDF variable ID for the time coordinate
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  start_count_time      !< NetCDF start index for the time dimension
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  start_count_utm       !< NetCDF start index for the UTM dimension 
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  start_count_utm       !< NetCDF start index for the UTM dimension
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  start_count_utm_soil  !< NetCDF start index for the UTM dimension in the soil
-    
+
     INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  id_var              !< NetCDF variable IDs for the sampled variables at a site
-    
+
     LOGICAL, DIMENSION(:), ALLOCATABLE ::  soil  !< flag indicating sampled soil quantities
-    
-    REAL(wp)                              ::  output_time    !< output time   
+
+    REAL(wp)                              ::  output_time    !< output time
     REAL(wp), DIMENSION(:), ALLOCATABLE   ::  var            !< sampled data
     REAL(wp), DIMENSION(:), ALLOCATABLE   ::  var_soil       !< sampled data of a soil varialbe
@@ -121,5 +123,5 @@
     REAL(wp), DIMENSION(:), ALLOCATABLE   ::  n_utm_soil     !< N_UTM coordinates where measurements were taken (soil)
     REAL(wp), DIMENSION(:), ALLOCATABLE   ::  depth          !< soil depth where measurements were taken (soil)
-       
+
 !
 !-- Read namelist.
@@ -131,11 +133,11 @@
 !
 !-- Open binary file for processor 0.
-    OPEN ( file_id_in, FILE = TRIM( path ) // TRIM( run ) //                   &
+    OPEN ( file_id_in, FILE = TRIM( path_input ) // TRIM( run ) //             &
            TRIM( myid_char ), FORM = 'UNFORMATTED' )
 !
-!-- Reader global information, such as number of stations, their type, 
-!-- number of observation coordinates for each station on subdomain and 
-!-- total. Read number of sites. 
-    READ( file_id_in )  char_in   
+!-- Reader global information, such as number of stations, their type,
+!-- number of observation coordinates for each station on subdomain and
+!-- total. Read number of sites.
+    READ( file_id_in )  char_in
     READ( file_id_in )  nvm
 !
@@ -147,5 +149,5 @@
     ALLOCATE( nvar(1:nvm)          )
     ALLOCATE( origin_x_obs(1:nvm)  )
-    ALLOCATE( origin_y_obs(1:nvm)  )    
+    ALLOCATE( origin_y_obs(1:nvm)  )
     ALLOCATE( ns(1:nvm)            )
     ALLOCATE( ns_tot(1:nvm)        )
@@ -153,7 +155,7 @@
     ALLOCATE( ns_soil_tot(1:nvm)   )
     ALLOCATE( soil(1:nvm)          )
-    
+
     ns_soil = 0
-    ns_soil_tot = 0  
+    ns_soil_tot = 0
 !
 !-- Allocate array with the measured variables at each station
@@ -162,28 +164,24 @@
 !-- Allocate arrays for NetCDF IDs
     ALLOCATE( nc_id(1:nvm)        )
-    ALLOCATE( id_eutm(1:nvm)      )
-    ALLOCATE( id_nutm(1:nvm)      )
-    ALLOCATE( id_hao(1:nvm)       )
-    ALLOCATE( id_eutm_soil(1:nvm) )
-    ALLOCATE( id_nutm_soil(1:nvm) )
-    ALLOCATE( id_depth(1:nvm)     )
+    ALLOCATE( id_position(1:nvm)      )
+    ALLOCATE( id_position_soil(1:nvm) )
     ALLOCATE( id_time(1:nvm)      )
     ALLOCATE( id_var_eutm(1:nvm)  )
     ALLOCATE( id_var_nutm(1:nvm)  )
-    ALLOCATE( id_var_hao(1:nvm)   ) 
+    ALLOCATE( id_var_hao(1:nvm)   )
     ALLOCATE( id_var_eutm_soil(1:nvm) )
     ALLOCATE( id_var_nutm_soil(1:nvm) )
-    ALLOCATE( id_var_depth(1:nvm) )    
+    ALLOCATE( id_var_depth(1:nvm) )
     ALLOCATE( id_var_time(1:nvm)  )
     ALLOCATE( id_var(1:50,1:nvm)  )
-    id_var = 0    
+    id_var = 0
     nc_id  = 0
 !
-!-- Allocate arrays that contain information about the start index in the 
+!-- Allocate arrays that contain information about the start index in the
 !-- dimension array, used to write binary data at the correct position in
-!-- the NetCDF file.    
+!-- the NetCDF file.
     ALLOCATE( start_count_utm(1:nvm) )
     ALLOCATE( start_count_utm_soil(1:nvm) )
-    
+
     ALLOCATE( start_count_time(1:nvm) )
 !
@@ -194,7 +192,7 @@
 !--    Read sitename
        READ( file_id_in )  char_in
-       READ( file_id_in )  site(l)   
-!
-!--    Read filename (original name where real-world data is stored) 
+       READ( file_id_in )  site(l)
+!
+!--    Read filename (original name where real-world data is stored)
        READ( file_id_in )  char_in
        READ( file_id_in )  filename(l)
@@ -210,5 +208,5 @@
        READ( file_id_in )  origin_y_obs(l)
 !
-!--    Read total number of observation grid points (dimension size of the 
+!--    Read total number of observation grid points (dimension size of the
 !--    virtual measurement)
        READ( file_id_in )  char_in
@@ -219,13 +217,13 @@
        READ( file_id_in )  nvar(l)
 !
-!--    Read names of observed quantities 
+!--    Read names of observed quantities
        READ( file_id_in )  char_in
        READ( file_id_in )  variables(1:nvar(l),l)
 !
-!--    Further dummy arguments are read (number of observation points 
-!--    on subdomains and its UTM coordinates). 
+!--    Further dummy arguments are read (number of observation points
+!--    on subdomains and its UTM coordinates).
        READ( file_id_in )  char_in
        READ( file_id_in )  ns(l)
-             
+
        ALLOCATE( e_utm(1:ns(l)) )
        ALLOCATE( n_utm(1:ns(l)) )
@@ -234,6 +232,6 @@
 !--    Read the local coordinate arrays
        READ( file_id_in )  char_in
-       READ( file_id_in )  e_utm 
-      
+       READ( file_id_in )  e_utm
+
        READ( file_id_in )  char_in
        READ( file_id_in )  n_utm
@@ -241,24 +239,24 @@
        READ( file_id_in )  char_in
        READ( file_id_in )  z_ag
-       
+
        DEALLOCATE( e_utm )
        DEALLOCATE( n_utm )
-       DEALLOCATE( z_ag  )  
-       
+       DEALLOCATE( z_ag  )
+
 !
 !--    Read flag indicating whether soil data is also present or not
        READ( file_id_in )  char_in
        READ( file_id_in )  char_in
-       
+
        soil(l) = MERGE( .TRUE., .FALSE., TRIM( char_in ) == "yes" )
-       
+
        IF ( soil(l) )  THEN
-       
+
           READ( file_id_in )  char_in
           READ( file_id_in )  ns_soil_tot(l)
-          
+
           READ( file_id_in )  char_in
           READ( file_id_in )  ns_soil(l)
-       
+
           ALLOCATE( e_utm_soil(1:ns_soil(l)) )
           ALLOCATE( n_utm_soil(1:ns_soil(l)) )
@@ -267,6 +265,6 @@
 !--       Read the local coordinate arrays
           READ( file_id_in )  char_in
-          READ( file_id_in )  e_utm_soil 
-      
+          READ( file_id_in )  e_utm_soil
+
           READ( file_id_in )  char_in
           READ( file_id_in )  n_utm_soil
@@ -274,14 +272,14 @@
           READ( file_id_in )  char_in
           READ( file_id_in )  depth
-       
+
           DEALLOCATE( e_utm_soil )
           DEALLOCATE( n_utm_soil )
           DEALLOCATE( depth      )
-       
+
        ENDIF
 !
 !--    Create netcdf file and setup header information
        CALL netcdf_create_file
-       
+
     ENDDO
 !
@@ -300,5 +298,5 @@
 !
 !--    Open binary file for processor f.
-       OPEN ( file_id_in, FILE = TRIM( path ) // TRIM( run ) //                &
+       OPEN ( file_id_in, FILE = TRIM( path_input ) // TRIM( run ) //          &
               TRIM( myid_char ), FORM = 'UNFORMATTED' )
 !
@@ -306,18 +304,18 @@
        start_count_time = 1
 !
-!--    Reader global information, such as number of stations, their type, 
-!--    number of observation coordinates for each station on subdomain and 
-!--    total. 
-!--    Again, read number of sites. 
+!--    Reader global information, such as number of stations, their type,
+!--    number of observation coordinates for each station on subdomain and
+!--    total.
+!--    Again, read number of sites.
        READ( file_id_in ) char_in
        READ( file_id_in ) nvm
-             
+
        DO  l = 1, nvm
 !
 !--       Read sitename
           READ( file_id_in )  char_in
-          READ( file_id_in )  site(l)   
-!
-!--       Read filename (original name where real-world data is stored) 
+          READ( file_id_in )  site(l)
+!
+!--       Read filename (original name where real-world data is stored)
           READ( file_id_in )  char_in
           READ( file_id_in )  filename(l)
@@ -333,5 +331,5 @@
           READ( file_id_in )  origin_y_obs(l)
 !
-!--       Read total number of observation grid points (dimension size of the 
+!--       Read total number of observation grid points (dimension size of the
 !--       virtual measurement)
           READ( file_id_in )  char_in
@@ -342,13 +340,13 @@
           READ( file_id_in )  nvar(l)
 !
-!--       Read names of observed quantities 
+!--       Read names of observed quantities
           READ( file_id_in )  char_in
           READ( file_id_in )  variables(1:nvar(l),l)
 !
-!--       Further dummy arguments are read (number of observation points 
-!--       on subdomains and its UTM coordinates). 
+!--       Further dummy arguments are read (number of observation points
+!--       on subdomains and its UTM coordinates).
           READ( file_id_in )  char_in
           READ( file_id_in )  ns(l)
-             
+
           ALLOCATE( e_utm(1:ns(l)) )
           ALLOCATE( n_utm(1:ns(l)) )
@@ -357,26 +355,26 @@
 !--       Read the local coordinate arrays
           READ( file_id_in )  char_in
-          READ( file_id_in )  e_utm 
-      
+          READ( file_id_in )  e_utm
+
           READ( file_id_in )  char_in
           READ( file_id_in )  n_utm
-   
-          READ( file_id_in )  char_in
-          READ( file_id_in )  z_ag      
+
+          READ( file_id_in )  char_in
+          READ( file_id_in )  z_ag
 !
 !--       Read flag indicating whether soil data is also present or not
           READ( file_id_in )  char_in
           READ( file_id_in )  char_in
-       
+
           soil(l) = MERGE( .TRUE., .FALSE., TRIM( char_in ) == "yes" )
-       
+
           IF ( soil(l) )  THEN
-       
+
              READ( file_id_in )  char_in
              READ( file_id_in )  ns_soil_tot(l)
-          
+
              READ( file_id_in )  char_in
              READ( file_id_in )  ns_soil(l)
-       
+
              ALLOCATE( e_utm_soil(1:ns_soil(l)) )
              ALLOCATE( n_utm_soil(1:ns_soil(l)) )
@@ -385,21 +383,21 @@
 !--          Read the local coordinate arrays
              READ( file_id_in )  char_in
-             READ( file_id_in )  e_utm_soil 
-      
+             READ( file_id_in )  e_utm_soil
+
              READ( file_id_in )  char_in
              READ( file_id_in )  n_utm_soil
-   
+
              READ( file_id_in )  char_in
              READ( file_id_in )  depth
-       
+
           ENDIF
 !
-!--       Setup the NetCDF dimensions for the UTM coordinates
-          CALL netcdf_define_utm_dimension
-          
+!--       Write the spatial coordinates to the NetCDF file
+          CALL netcdf_write_spatial_coordinates
+
           DEALLOCATE( e_utm )
           DEALLOCATE( n_utm )
           DEALLOCATE( z_ag )
-          
+
           IF ( soil(l) )  THEN
              DEALLOCATE( e_utm_soil )
@@ -407,13 +405,13 @@
              DEALLOCATE( depth      )
           ENDIF
-          
+
        ENDDO
 !
-!--    Read the actual data, starting with the identification string for the 
+!--    Read the actual data, starting with the identification string for the
 !--    output time
-       READ( file_id_in )  char_in          
+       READ( file_id_in )  char_in
        DO WHILE ( TRIM( char_in ) == 'output time')
-       
-          READ( file_id_in )  output_time 
+
+          READ( file_id_in )  output_time
 !
 !--       Loop over all sites
@@ -423,13 +421,13 @@
              IF ( ns(l) < 1  .AND.  ns_soil(l) < 1 )  CYCLE
 !
-!--          Setup time coordinate
-             CALL netcdf_define_time_dimension
+!--          Write time coordinate
+             CALL netcdf_write_time_coordinate
 !
 !--          Read the actual data, therefore, allocate appropriate array with
-!--          size of the subdomain coordinates. Output data immediately into 
-!--          NetCDF file. 
+!--          size of the subdomain coordinates. Output data immediately into
+!--          NetCDF file.
              ALLOCATE( var(1:ns(l)) )
              IF ( soil(l) )  ALLOCATE( var_soil(1:ns_soil(l)) )
-             
+
              DO  n = 1, nvar(l)
                 READ( file_id_in )  variables(n,l)
@@ -441,8 +439,8 @@
                 ENDIF
 !
-!--             Write data to NetCDF file 
+!--             Write data to NetCDF file
                 CALL netcdf_data_output
-             ENDDO        
-             
+             ENDDO
+
              DEALLOCATE( var )
              IF( ALLOCATED(var_soil) )  DEALLOCATE( var_soil )
@@ -454,8 +452,8 @@
 !--       Read next identification string
           READ( file_id_in )  char_in
-          
+
        ENDDO
 !
-!--    After data from processor f is read and output into NetCDF file, 
+!--    After data from processor f is read and output into NetCDF file,
 !--    the start index of the UTM coordinate array need to be incremented
        start_count_utm      = start_count_utm      + ns
@@ -470,7 +468,7 @@
        CALL netcdf_close_file
     ENDDO
-    
+
  CONTAINS
- 
+
 !------------------------------------------------------------------------------!
 ! Description:
@@ -479,10 +477,10 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE cvm_parin
-       
+
        IMPLICIT NONE
-       
+
        INTEGER(iwp) ::  file_id_parin = 90
-       
-       NAMELIST /vm/  cycle_number, num_pe, path, run
+
+       NAMELIST /vm/  cycle_number, num_pe, path_input, path_output, run
 
 !
@@ -495,7 +493,7 @@
 !--    Close namelist file.
        CLOSE( file_id_parin )
-       
+
     END SUBROUTINE cvm_parin
-      
+
 !------------------------------------------------------------------------------!
 ! Description:
@@ -504,10 +502,10 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE create_file_string
-       
+
        IMPLICIT NONE
-       
+
        CHARACTER(LEN=4)   ::  char_cycle = '' !< dummy string for cycle number
        CHARACTER(LEN=10)  ::  char_dum        !< dummy string for processor ID
-       
+
 !
 !--    Create substring for the cycle number.
@@ -551,8 +549,8 @@
                       TRIM( char_cycle ) // file_suffix
        ENDIF
-       
+
     END SUBROUTINE create_file_string
-    
-    
+
+
 !------------------------------------------------------------------------------!
 ! Description:
@@ -561,11 +559,11 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE netcdf_create_file
-       
+
        IMPLICIT NONE
-       
-       
+
+
        CHARACTER(LEN=5)   ::  char_cycle = ''  !< dummy string for cycle number
        CHARACTER(LEN=200) ::  nc_filename = '' !< NetCDF filename
-       
+
 !
 !--    Create substring for the cycle number.
@@ -584,5 +582,5 @@
           char_cycle = '.'
        ENDIF
-#if defined( __netcdf )     
+#if defined( __netcdf )
 
        nc_filename = site(l)(1:LEN_TRIM(site(l))-1) // '_palm4U' //            &
@@ -590,5 +588,6 @@
 !
 !--    Create NetCDF file
-       status_nc = NF90_CREATE( nc_filename(1:LEN_TRIM(nc_filename)),          &
+       status_nc = NF90_CREATE( TRIM(path_output) //                           &
+                                nc_filename(1:LEN_TRIM(nc_filename)),          &
                                 IOR( NF90_CLOBBER, NF90_NETCDF4 ), nc_id(l) )
        CALL handle_error( "create file" )
@@ -598,13 +597,13 @@
                                  TRIM( feature_type(l) ) )
        CALL handle_error( "define attribue featureType" )
-       
+
        status_nc = NF90_PUT_ATT( nc_id(l), NF90_GLOBAL, "origin_x",            &
                                  origin_x_obs(l) )
        CALL handle_error( "define attribue origin_x" )
-       
+
        status_nc = NF90_PUT_ATT( nc_id(l), NF90_GLOBAL, "origin_y",            &
                                  origin_y_obs(l) )
        CALL handle_error( "define attribue origin_y" )
-       
+
        status_nc = NF90_PUT_ATT( nc_id(l), NF90_GLOBAL, "site",                &
                                  TRIM( site(l) ) )
@@ -612,57 +611,48 @@
 !
 !--    Define dimensions
-       status_nc = NF90_DEF_DIM( nc_id(l), 'E_UTM', ns_tot(l), id_eutm(l) )
-       CALL handle_error( "define dimension E_UTM" )
-       
-       status_nc = NF90_DEF_DIM( nc_id(l), 'N_UTM', ns_tot(l), id_nutm(l) )
-       CALL handle_error( "define dimension N_UTM" )
-       
-       status_nc = NF90_DEF_DIM( nc_id(l), 'height_above_origin', ns_tot(l),   &
-                                 id_hao(l) )
-       CALL handle_error( "define dimension height_above_origin" )
-       
+       status_nc = NF90_DEF_DIM( nc_id(l), 'time', NF90_UNLIMITED, id_time(l) )
+       CALL handle_error( "define dimension time" )
+
+       status_nc = NF90_DEF_DIM( nc_id(l), 'position', ns_tot(l),              &
+                                 id_position(l) )
+       CALL handle_error( "define dimension position" )
+
        IF ( soil(l) )  THEN
-          status_nc = NF90_DEF_DIM( nc_id(l), 'E_UTM soil', ns_soil_tot(l),    &
-                                    id_eutm_soil(l) )
-          CALL handle_error( "define dimension E_UTM soil" )
-          
-          status_nc = NF90_DEF_DIM( nc_id(l), 'N_UTM soil', ns_soil_tot(l),    &
-                                    id_nutm_soil(l) )
-          CALL handle_error( "define dimension N_UTM soil" )
-          status_nc = NF90_DEF_DIM( nc_id(l), 'depth', ns_soil_tot(l),         &
-                                    id_depth(l) )
-          CALL handle_error( "define dimension depth" )
+          status_nc = NF90_DEF_DIM( nc_id(l), 'position_soil', ns_soil_tot(l), &
+                                    id_position_soil(l) )
+          CALL handle_error( "define dimension position_soil" )
        ENDIF
-       
-       status_nc = NF90_DEF_DIM( nc_id(l), 'time', NF90_UNLIMITED, id_time(l) )
-       CALL handle_error( "define dimension time" )      
-
-!
-!--    Define dimension variables
+!
+!--    Define coordinate variables
        status_nc = NF90_DEF_VAR( nc_id(l), 'E_UTM', NF90_DOUBLE,               &
-                                 (/ id_eutm(l) /), id_var_eutm(l) )
+                                 (/ id_position(l) /), id_var_eutm(l) )
        CALL handle_error( "define variable E_UTM" )
-       
+
        status_nc = NF90_DEF_VAR( nc_id(l), 'N_UTM', NF90_DOUBLE,               &
-                                 (/ id_nutm(l) /), id_var_nutm(l) )
+                                 (/ id_position(l) /), id_var_nutm(l) )
        CALL handle_error( "define variable N_UTM" )
+
        status_nc = NF90_DEF_VAR( nc_id(l), 'height_above_origin', NF90_DOUBLE, &
-                                 (/ id_hao(l)  /), id_var_hao(l)  )
+                                 (/ id_position(l)  /), id_var_hao(l)  )
        CALL handle_error( "define variable height_above_origin" )
+
        status_nc = NF90_DEF_VAR( nc_id(l), 'time', NF90_DOUBLE,                &
                                  (/ id_time(l) /), id_var_time(l) )
        CALL handle_error( "define variable time" )
-       
+
        IF ( soil(l) )  THEN
           status_nc = NF90_DEF_VAR( nc_id(l), 'E_UTM soil', NF90_DOUBLE,       &
-                                    (/ id_eutm_soil(l) /), id_var_eutm_soil(l) )
+                                    (/ id_position_soil(l) /),                 &
+                                    id_var_eutm_soil(l) )
           CALL handle_error( "define variable E_UTM soil" )
-          
+
           status_nc = NF90_DEF_VAR( nc_id(l), 'N_UTM soil', NF90_DOUBLE,       &
-                                    (/ id_nutm_soil(l) /), id_var_nutm_soil(l) )
+                                    (/ id_position_soil(l) /),                 &
+                                    id_var_nutm_soil(l) )
           CALL handle_error( "define variable N_UTM soil" )
-          
+
           status_nc = NF90_DEF_VAR( nc_id(l), 'depth', NF90_DOUBLE,            &
-                                    (/ id_depth(l)  /), id_var_depth(l) )
+                                    (/ id_position_soil(l)  /),                &
+                                    id_var_depth(l) )
           CALL handle_error( "define variable depth" )
        ENDIF
@@ -674,5 +664,5 @@
              status_nc = NF90_DEF_VAR( nc_id(l), TRIM( variables(n,l) ),       &
                                        NF90_DOUBLE,                            &
-                                       (/ id_time(l), id_eutm_soil(l) /),      &
+                                       (/ id_time(l), id_position_soil(l) /),  &
                                        id_var(n,l) )
              CALL handle_error( "define variable " // TRIM( variables(n,l) ) )
@@ -680,12 +670,12 @@
              status_nc = NF90_DEF_VAR( nc_id(l), TRIM( variables(n,l) ),       &
                                        NF90_DOUBLE,                            &
-                                       (/ id_time(l), id_eutm(l) /),           &
+                                       (/ id_time(l), id_position(l) /),       &
                                        id_var(n,l) )
              CALL handle_error( "define variable " // TRIM( variables(n,l) ) )
           ENDIF
        ENDDO
-#endif        
+#endif
     END SUBROUTINE netcdf_create_file
-    
+
 !------------------------------------------------------------------------------!
 ! Description:
@@ -694,52 +684,52 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE netcdf_close_file
-       
+
        IMPLICIT NONE
-       
-#if defined( __netcdf )        
+
+#if defined( __netcdf )
        status_nc = NF90_CLOSE( nc_id(l) )
        CALL handle_error( "close file" )
-#endif   
-       
+#endif
+
     END SUBROUTINE netcdf_close_file
-    
+
 !------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> This subroutine defines the UTM dimensions
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_define_utm_dimension
-       
+!> This subroutine writes the spatial coordinates
+!------------------------------------------------------------------------------!
+    SUBROUTINE netcdf_write_spatial_coordinates
+
        IMPLICIT NONE
-       
-!
-!--    Define dimensions
-#if defined( __netcdf ) 
+
+!
+!--    Write coordinates
+#if defined( __netcdf )
        status_nc = NF90_PUT_VAR( nc_id(l), id_var_eutm(l), e_utm,              &
-                                 start = (/ start_count_utm(l) /),             & 
+                                 start = (/ start_count_utm(l) /),             &
                                  count = (/ ns(l) /) )
        CALL handle_error( "write variable E_UTM" )
-       
+
        status_nc = NF90_PUT_VAR( nc_id(l), id_var_nutm(l), n_utm,              &
                                  start = (/ start_count_utm(l) /),             &
                                  count = (/ ns(l) /) )
        CALL handle_error( "write variable N_UTM" )
-       
+
        status_nc = NF90_PUT_VAR( nc_id(l), id_var_hao(l),  z_ag,               &
                                  start = (/ start_count_utm(l) /),             &
                                  count = (/ ns(l) /) )
        CALL handle_error( "write variable height_above_origin" )
-       
+
        IF ( soil(l) )  THEN
           status_nc = NF90_PUT_VAR( nc_id(l), id_var_eutm_soil(l), e_utm_soil, &
-                                 start = (/ start_count_utm_soil(l) /),        & 
+                                 start = (/ start_count_utm_soil(l) /),        &
                                  count = (/ ns_soil(l) /) )
           CALL handle_error( "write variable E_UTM soil" )
-          
+
           status_nc = NF90_PUT_VAR( nc_id(l), id_var_nutm_soil(l), n_utm_soil, &
                                  start = (/ start_count_utm_soil(l) /),        &
                                  count = (/ ns_soil(l) /) )
           CALL handle_error( "write variable N_UTM soil" )
-          
+
           status_nc = NF90_PUT_VAR( nc_id(l), id_var_depth(l),  depth,         &
                                  start = (/ start_count_utm_soil(l) /),        &
@@ -750,19 +740,17 @@
 !--    End of NetCDF file definition
        status_nc = NF90_ENDDEF( nc_id(l) )
-#endif       
-    END SUBROUTINE netcdf_define_utm_dimension
-    
+#endif
+END SUBROUTINE netcdf_write_spatial_coordinates
+
 !------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> This subroutine updates the unlimited time dimension.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_define_time_dimension
-       
+!> This subroutine writes another time step to the unlimited time dimension.
+!------------------------------------------------------------------------------!
+    SUBROUTINE netcdf_write_time_coordinate
+
        IMPLICIT NONE
-       
-!
-!--    Define dimensions
-#if defined( __netcdf )   
+
+#if defined( __netcdf )
        status_nc = NF90_PUT_VAR( nc_id(l), id_var_time(l), (/ output_time /),  &
                                  start = (/ start_count_time(l) /),            &
@@ -770,8 +758,8 @@
        CALL handle_error( "write variable time" )
 #endif
-       
-    END SUBROUTINE netcdf_define_time_dimension
-
-    
+
+END SUBROUTINE netcdf_write_time_coordinate
+
+
 !------------------------------------------------------------------------------!
 ! Description:
@@ -780,7 +768,7 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE netcdf_data_output
-       
+
        IMPLICIT NONE
-       
+
 
        IF ( soil(l)  .AND.                                                     &
@@ -798,12 +786,12 @@
           CALL handle_error( "write variable " // TRIM( variables(n,l) ) )
        ENDIF
-       
+
     END SUBROUTINE netcdf_data_output
-    
+
 !------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> NetCDF error handling.
-!------------------------------------------------------------------------------!    
+!------------------------------------------------------------------------------!
     SUBROUTINE handle_error( action )
 
@@ -811,8 +799,8 @@
 
        CHARACTER(LEN=*) ::  action !< string indicating the current file action
-       
-#if defined( __netcdf )       
+
+#if defined( __netcdf )
        IF ( status_nc /= NF90_NOERR )  THEN
-          PRINT*, TRIM( NF90_STRERROR( status_nc ) ) // ' -- ' // action 
+          PRINT*, TRIM( NF90_STRERROR( status_nc ) ) // ' -- ' // action
           STOP
        ENDIF
@@ -820,4 +808,4 @@
 
     END SUBROUTINE handle_error
-        
+
  END PROGRAM combine_virtual_measurements
Index: palm/trunk/UTIL/combine_virtual_measurements/vm_parin
===================================================================
--- palm/trunk/UTIL/combine_virtual_measurements/vm_parin	(revision 3705)
+++ palm/trunk/UTIL/combine_virtual_measurements/vm_parin	(revision 3928)
@@ -2,13 +2,16 @@
 !
 !-- Number of processors of the run.
-    num_pe = 36, 
+    num_pe = 4,
 !
-!-- Path to the output binary files.
-    path = '~/palm/current_version/JOBS/test_urban/OUTPUT/', 
+!-- Path to the binary input files.
+    path_input = '~/palm/current_version/JOBS/test_run/OUTPUT/',
+!
+!-- Path to the NetCDF output files
+    path_output = '~/palm/current_version/JOBS/test_run/OUTPUT/',
 !
 !-- Name of the run.
-    run = 'test_berlin',
+    run = 'test_run',
 !
 !-- Cycle number of the output data which should be processed
-    cycle_number = 0, 
-/  
+    cycle_number = 0,
+/
