Index: /palm/trunk/SOURCE/virtual_measurement_mod.f90
===================================================================
--- /palm/trunk/SOURCE/virtual_measurement_mod.f90	(revision 4420)
+++ /palm/trunk/SOURCE/virtual_measurement_mod.f90	(revision 4421)
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$
+! - Output of character string station_name after DOM has been enabled to
+!   output character variables
+! - Bugfix, missing coupling char statement when opening the input file
+! 
+! 4408 2020-02-14 10:04:39Z gronemeier
 ! write fill_value attribute
 !
@@ -111,9 +116,4 @@
 !> which allows for straight-forward comparison of model results with
 !> observations.
-!>
-!> @todo Check why there is an error when _FillValue attributes are added via
-!>       dom.
-!> @todo Output of character variable station_name (dom hasn't this feature
-!>       yet implemented).
 !------------------------------------------------------------------------------!
  MODULE virtual_measurement_mod
@@ -882,5 +882,5 @@
 !
 !-- Open the input file.
-    CALL open_read_file( input_file_vm, pids_id )
+    CALL open_read_file( input_file_vm // TRIM( coupling_char ), pids_id )
 !
 !-- Obtain number of sites.
@@ -1462,5 +1462,5 @@
 !
 !--    Define output file.
-       WRITE( vmea(l)%nc_filename, '(A,I4.4)')  'VM_OUTPUT' //                 &
+       WRITE( vmea(l)%nc_filename, '(A,I4.4)' ) 'VM_OUTPUT' //                 &
                                                 TRIM( coupling_char ) // '/' //&
                                                 'site', l
@@ -1615,5 +1615,5 @@
                                    dimension_name = 'max_name_len',            &
                                    output_type = 'int32',                      &
-                                   bounds = (/1_iwp, 32_iwp/),                 &
+                                   bounds = (/1_iwp, maximum_name_length /),   &
                                    values_int32 = ndim )
        DEALLOCATE( ndim )
@@ -1628,11 +1628,11 @@
                                    output_type = 'real32' )
 !
-!--    station_name. DOM needs to be enabled to define CHARACTER variables.
-!        variable_name = 'station_name'
-!        return_value = dom_def_var( vmea(l)%nc_filename,                        &
-!                                    variable_name = variable_name,              &
-!                                    dimension_names = (/ 'max_name_len',        &
-!                                                         'station     '/),      &
-!                                    output_type = 'char' )
+!--    station_name
+       variable_name = 'station_name'
+       return_value = dom_def_var( vmea(l)%nc_filename,                        &
+                                   variable_name = variable_name,              &
+                                   dimension_names = (/ 'max_name_len',        &
+                                                        'station     ' /),     &
+                                   output_type = 'char' )
 !
 !--    vrs (vertical reference system)
@@ -1966,5 +1966,5 @@
                                       variable_name = variable_name,           &
                                       dimension_names = (/ 'max_name_len',     &
-                                                           'station_soil'/),   &
+                                                           'station_soil' /),  &
                                       output_type = 'char' )
 !
@@ -2260,7 +2260,12 @@
 
     CHARACTER(LEN=100) ::  variable_name !< name of output variable
-
-    INTEGER(iwp)       ::  l             !< loop index
-    INTEGER(iwp)       ::  n             !< loop index
+    CHARACTER(LEN=maximum_name_length), DIMENSION(:), ALLOCATABLE :: station_name !< string for station name, consecutively ordered
+
+    CHARACTER(LEN=1), DIMENSION(:,:), ALLOCATABLE, TARGET ::  output_values_2d_char_target  !< target for output name arrays
+    CHARACTER(LEN=1), DIMENSION(:,:), POINTER             ::  output_values_2d_char_pointer !< pointer for output name arrays
+
+    INTEGER(iwp)       ::  l             !< loop index for the number of sites
+    INTEGER(iwp)       ::  n             !< loop index for observation points
+    INTEGER(iwp)       ::  nn            !< loop index for number of characters in a name
     INTEGER            ::  return_value  !< returned status value of called function
 
@@ -2347,4 +2352,29 @@
           DEALLOCATE( oro_rel )
           DEALLOCATE( output_values_1d_target )
+!
+!--       Write station name
+          ALLOCATE ( station_name(vmea(l)%start_coord_a:vmea(l)%end_coord_a) )
+          ALLOCATE ( output_values_2d_char_target(vmea(l)%start_coord_a:vmea(l)%end_coord_a, &
+                                                  1:maximum_name_length) )
+
+          DO  n = vmea(l)%start_coord_a, vmea(l)%end_coord_a
+             station_name(n) = REPEAT( ' ', maximum_name_length )
+             WRITE( station_name(n), '(A,I10.10)') "station", n
+             DO  nn = 1, maximum_name_length
+                output_values_2d_char_target(n,nn) = station_name(n)(nn:nn)
+             ENDDO
+          ENDDO
+
+          output_values_2d_char_pointer => output_values_2d_char_target
+
+          return_value =                                                       &
+                  dom_write_var( vmea(l)%nc_filename,                          &
+                                 'station_name',                               &
+                                 values_char_2d = output_values_2d_char_pointer,&
+                                 bounds_start = (/ 1,                   vmea(l)%start_coord_a /),&
+                                 bounds_end   = (/ maximum_name_length, vmea(l)%end_coord_a /) )
+
+          DEALLOCATE( station_name )
+          DEALLOCATE( output_values_2d_char_target )
 !
 !--       In case of sampled soil quantities, output also the respective
@@ -2414,5 +2444,27 @@
              DEALLOCATE( output_values_1d_target )
 !
-!--          Write the stations name
+!--          Write station name
+             ALLOCATE ( station_name(vmea(l)%start_coord_s:vmea(l)%end_coord_s) )
+             ALLOCATE ( output_values_2d_char_target(vmea(l)%start_coord_s:vmea(l)%end_coord_s, &
+                                                     1:maximum_name_length) )
+
+             DO  n = vmea(l)%start_coord_s, vmea(l)%end_coord_s
+                station_name(n) = REPEAT( ' ', maximum_name_length )
+                WRITE( station_name(n), '(A,I10.10)') "station", n
+                DO  nn = 1, maximum_name_length
+                   output_values_2d_char_target(n,nn) = station_name(n)(nn:nn)
+                ENDDO
+             ENDDO
+             output_values_2d_char_pointer => output_values_2d_char_target
+
+             return_value =                                                    &
+                  dom_write_var( vmea(l)%nc_filename,                          &
+                                 'station_name_soil',                          &
+                                 values_char_2d = output_values_2d_char_pointer,&
+                                 bounds_start = (/ 1,                   vmea(l)%start_coord_s /),&
+                                 bounds_end   = (/ maximum_name_length, vmea(l)%end_coord_s   /) )
+
+             DEALLOCATE( station_name )
+             DEALLOCATE( output_values_2d_char_target )
 
           ENDIF
