Index: palm/trunk/SCRIPTS/.palm.iofiles
===================================================================
--- palm/trunk/SCRIPTS/.palm.iofiles	(revision 4433)
+++ palm/trunk/SCRIPTS/.palm.iofiles	(revision 4434)
@@ -16,4 +16,5 @@
 PIDS_UVEM                inopt:tr   d3#:d3r  $base_data/$run_identifier/INPUT          _uvlookup*
 PIDS_VM                  inopt:tr   d3#:d3r  $base_data/$run_identifier/INPUT          _vmeas*
+PIDS_WTM                 inopt:tr   d3#:d3r  $base_data/$run_identifier/INPUT          _wtmpar*
 rrtmg_lw.nc              inopt:tr   d3#:d3r  $base_data/$run_identifier/INPUT          _rlw
 rrtmg_sw.nc              inopt:tr   d3#:d3r  $base_data/$run_identifier/INPUT          _rsw
Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 4433)
+++ palm/trunk/SOURCE/Makefile	(revision 4434)
@@ -1303,4 +1303,5 @@
 	cpulog_mod.o \
 	data_output_module.o \
+	netcdf_data_input_mod.o \
 	mod_kinds.o \
 	modules.o
Index: palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4433)
+++ palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4434)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! added optional netcdf data input for wtm array input parameters
+! 
+! 4404 2020-02-12 17:01:53Z suehring
 ! Fix misplaced preprocessor directives.
 ! 
@@ -646,5 +649,6 @@
     CHARACTER(LEN=100) ::  input_file_uvem    = 'PIDS_UVEM'    !< Name of file which comprises static uv_exposure model input data
     CHARACTER(LEN=100) ::  input_file_vm      = 'PIDS_VM'      !< Name of file which comprises virtual measurement data
-    
+    CHARACTER(LEN=100) ::  input_file_wtm     = 'PIDS_WTM'     !< Name of file which comprises wind turbine model input data
+        
     CHARACTER(LEN=25), ALLOCATABLE, DIMENSION(:) ::  string_values  !< output of string variables read from netcdf input files
     CHARACTER(LEN=50), DIMENSION(:), ALLOCATABLE ::  vars_pids      !< variable in input file
@@ -661,4 +665,5 @@
     LOGICAL ::  input_pids_uvem    = .FALSE.   !< Flag indicating whether uv-expoure-model input file containing static information exists
     LOGICAL ::  input_pids_vm      = .FALSE.   !< Flag indicating whether input file for virtual measurements exist
+    LOGICAL ::  input_pids_wtm     = .FALSE.   !< Flag indicating whether input file for wind turbine model exists
 
     LOGICAL ::  collective_read = .FALSE.      !< Enable NetCDF collective read
@@ -764,4 +769,5 @@
            input_pids_static,                                                  &
            input_pids_dynamic, input_pids_vm, input_file_vm,                   &
+           input_pids_wtm, input_file_wtm,                                     &
            num_var_pids,                                                       &
            pavement_pars_f, pavement_subsurface_pars_f, pavement_type_f,       &
@@ -827,4 +833,6 @@
        INQUIRE( FILE = TRIM( input_file_vm )      // TRIM( coupling_char ),    &
                 EXIST = input_pids_vm )
+       INQUIRE( FILE = TRIM( input_file_wtm )     // TRIM( coupling_char ),    &
+                EXIST = input_pids_wtm )
 #endif
 
Index: palm/trunk/SOURCE/wind_turbine_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/wind_turbine_model_mod.f90	(revision 4433)
+++ palm/trunk/SOURCE/wind_turbine_model_mod.f90	(revision 4434)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! added optional netcdf data input for wtm array input parameters
+! 
+! 4426 2020-02-27 10:02:19Z oliver.maas
 ! define time as unlimited dimension so that no maximum number
 ! of time steps has to be given for wtm_data_output
@@ -145,4 +148,17 @@
     USE kinds
 
+    USE netcdf_data_input_mod,                                                 &
+        ONLY:  check_existence,                                                &
+               close_input_file,                                               &
+               get_variable,                                                   &
+               input_pids_wtm,                                                 &
+               inquire_num_variables,                                          &
+               inquire_variable_names,                                         &
+               input_file_wtm,                                                 &
+               num_var_pids,                                                   &
+               open_read_file,                                                 &
+               pids_id,                                                        &
+               vars_pids
+    
     USE pegrid
 
@@ -479,10 +495,8 @@
     SUBROUTINE wtm_parin
 
-
        IMPLICIT NONE
-       
+
        CHARACTER (LEN=80) ::  line  !< dummy string that contains the current line of the parameter file 
 
-                                  
        NAMELIST /wind_turbine_parameters/                                      &
                                   air_dens, dtow, dt_data_output_wtm, gear_eff,&
@@ -520,7 +534,5 @@
        CALL parin_fail_message( 'wind_turbine_parameters', line )
 
-
  12    CONTINUE   ! TBD Change from continue, mit ierrn machen
-
 
     END SUBROUTINE wtm_parin
@@ -635,27 +647,28 @@
        IMPLICIT NONE
     
-       IF ( ( .NOT.speed_control ) .AND. pitch_control )  THEN
-          message_string = 'pitch_control = .TRUE. requires '//                &
-                           'speed_control = .TRUE.'
-          CALL message( 'wtm_check_parameters', 'PA0461', 1, 2, 0, 6, 0 )
+       IF ( .NOT. input_pids_wtm )  THEN
+          IF ( ( .NOT.speed_control ) .AND. pitch_control )  THEN
+             message_string = 'pitch_control = .TRUE. requires '//                &
+                               'speed_control = .TRUE.'
+             CALL message( 'wtm_check_parameters', 'PA0461', 1, 2, 0, 6, 0 )
+          ENDIF
+          
+          IF ( ANY( omega_rot(1:nturbines) < 0.0 ) )  THEN
+             message_string = 'omega_rot < 0.0, Please set omega_rot to '     // &
+                               'a value equal or larger than zero'
+             CALL message( 'wtm_check_parameters', 'PA0462', 1, 2, 0, 6, 0 )
+          ENDIF
+          
+          
+          IF ( ANY( rcx(1:nturbines) == 9999999.9_wp ) .OR.                       &
+                ANY( rcy(1:nturbines) == 9999999.9_wp ) .OR.                       &
+                ANY( rcz(1:nturbines) == 9999999.9_wp ) )  THEN
+             
+             message_string = 'rcx, rcy, rcz '                                 // &
+                               'have to be given for each turbine.'          
+             CALL message( 'wtm_check_parameters', 'PA0463', 1, 2, 0, 6, 0 )          
+          ENDIF
        ENDIF
        
-       IF ( ANY( omega_rot(1:nturbines) < 0.0 ) )  THEN
-          message_string = 'omega_rot < 0.0, Please set omega_rot to '     // &
-                           'a value equal or larger than zero'
-          CALL message( 'wtm_check_parameters', 'PA0462', 1, 2, 0, 6, 0 )
-       ENDIF
-       
-       
-       IF ( ANY( rcx(1:nturbines) == 9999999.9_wp ) .OR.                       &
-            ANY( rcy(1:nturbines) == 9999999.9_wp ) .OR.                       &
-            ANY( rcz(1:nturbines) == 9999999.9_wp ) )  THEN
-          
-          message_string = 'rcx, rcy, rcz '                                 // &
-                           'have to be given for each turbine.'          
-          CALL message( 'wtm_check_parameters', 'PA0463', 1, 2, 0, 6, 0 )          
-          
-       ENDIF
-
     END SUBROUTINE wtm_check_parameters 
 !     
@@ -668,9 +681,77 @@
     SUBROUTINE wtm_init_arrays
 
-
        IMPLICIT NONE
 
        REAL(wp) ::  delta_r_factor   !< 
        REAL(wp) ::  delta_r_init     !< 
+
+!
+! Read wtm input file (netcdf) if it exists
+       IF ( input_pids_wtm )  THEN
+
+!
+!--       Open the wtm  input file
+#if defined( __netcdf )
+          CALL open_read_file( TRIM( input_file_wtm ) //                       &
+                               TRIM( coupling_char ), pids_id )
+
+          CALL inquire_num_variables( pids_id, num_var_pids )
+
+!
+!--       Allocate memory to store variable names and read them
+          ALLOCATE( vars_pids(1:num_var_pids) )
+          CALL inquire_variable_names( pids_id, vars_pids )
+
+!
+!--       Input of all wtm parameters
+          IF ( check_existence( vars_pids, 'dtow' ) )  THEN
+             CALL get_variable( pids_id, 'dtow', dtow(1:nturbines))
+          ENDIF
+
+          IF ( check_existence( vars_pids, 'omega_rot' ) )  THEN
+             CALL get_variable( pids_id, 'omega_rot', omega_rot(1:nturbines))
+          ENDIF
+
+          IF ( check_existence( vars_pids, 'pitch_add' ) )  THEN
+             CALL get_variable( pids_id, 'pitch_add', pitch_add(1:nturbines))
+          ENDIF
+
+          IF ( check_existence( vars_pids, 'phi_yaw' ) )  THEN
+             CALL get_variable( pids_id, 'phi_yaw', phi_yaw(1:nturbines))
+          ENDIF
+
+          IF ( check_existence( vars_pids, 'rcx' ) )  THEN
+             CALL get_variable( pids_id, 'rcx', rcx(1:nturbines))
+          ENDIF
+
+          IF ( check_existence( vars_pids, 'rcy' ) )  THEN
+             CALL get_variable( pids_id, 'rcy', rcy(1:nturbines))
+          ENDIF
+
+          IF ( check_existence( vars_pids, 'rcz' ) )  THEN
+             CALL get_variable( pids_id, 'rcz', rcz(1:nturbines))
+          ENDIF
+
+          IF ( check_existence( vars_pids, 'rnac' ) )  THEN
+             CALL get_variable( pids_id, 'rnac', rnac(1:nturbines))
+          ENDIF
+
+          IF ( check_existence( vars_pids, 'rr' ) )  THEN
+             CALL get_variable( pids_id, 'rr', rr(1:nturbines))
+          ENDIF
+! 
+!           IF ( check_existence( vars_pids, 'turb_cd_nacelle' ) )  THEN
+!              CALL get_variable( pids_id, 'turb_cd_nacelle', turb_cd_nacelle(1:nturbines))
+!           ENDIF
+
+          IF ( check_existence( vars_pids, 'turb_cd_tower' ) )  THEN
+             CALL get_variable( pids_id, 'turb_cd_tower', turb_cd_tower(1:nturbines))
+          ENDIF
+!
+!--       Close wtm input file
+          CALL close_input_file( pids_id )
+
+       ENDIF
+#endif
 
 !
@@ -1273,8 +1354,4 @@
        CALL wtm_read_blade_tables
 
-       
-   
-       
-     
        IF ( debug_output )  CALL debug_message( 'wtm_init', 'end' )
  
@@ -2216,5 +2293,5 @@
 !--                and the direction of the flow relative to the rotor:
 
-                   phi_rel(rseg) = ATAN( u_rot /                               &
+                   phi_rel(rseg) = ATAN2( u_rot ,                               &
                                          ( omega_rot(inot) * cur_r -           &
                                            vtheta(rseg) ) )
@@ -2574,10 +2651,10 @@
 !--          Can't be allocated before dt_3d is set
              IF ( start_up )  THEN
-                WDLON = NINT( 30.0_wp / dt_3d )  ! 30s running mean array
+                WDLON = MAX( 1 , NINT( 30.0_wp / dt_3d ) )  ! 30s running mean array
                 ALLOCATE( wd30(1:nturbines,1:WDLON) )
                 wd30 = 999.0_wp                  ! Set to dummy value
                 ALLOCATE( wd30_l(1:WDLON) )
                 
-                WDSHO = NINT( 2.0_wp / dt_3d )   ! 2s running mean array
+                WDSHO = MAX( 1 , NINT( 2.0_wp / dt_3d ) )   ! 2s running mean array
                 ALLOCATE( wd2(1:nturbines,1:WDSHO) )
                 wd2 = 999.0_wp                   ! Set to dummy value
