Index: palm/trunk/SOURCE/wind_turbine_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/wind_turbine_model_mod.f90	(revision 4828)
+++ palm/trunk/SOURCE/wind_turbine_model_mod.f90	(revision 4843)
@@ -21,9 +21,15 @@
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! reading of namelist file and actions in case of namelist errors revised so that statement labels
+! and goto statements are not required any more,
+! local namelist parameter added to switch off the module although the respective module namelist
+! appears in the namelist file
+!
+! 4828 2021-01-05 11:21:41Z Giersch
 ! reset n_turbines_max to 1E4 (10 000), because it was set to 1 000 in r4497 by mistake
 ! 
@@ -530,43 +536,75 @@
     IMPLICIT NONE
 
-    CHARACTER(LEN=80) ::  line  !< dummy string that contains the current line of the parameter file
-
-    NAMELIST /wind_turbine_parameters/                                                             &
-             air_density, tower_diameter, dt_data_output_wtm,                                      &
-                gear_efficiency, gear_ratio, generator_efficiency,                                 &
-                generator_inertia, rotor_inertia, yaw_misalignment_max,                            &
-                generator_torque_max, generator_torque_rate_max, yaw_misalignment_min,             &
-                region_15_min, region_2_min, n_airfoils, n_turbines,                               &
-                rotor_speed, yaw_angle, pitch_angle, pitch_control,                                &
-                generator_speed_rated, generator_power_rated, hub_x, hub_y, hub_z,                 &
-                nacelle_radius, rotor_radius, segment_length_tangential, segment_width_radial,     &
-                region_2_slope, speed_control, tilt_angle, time_turbine_on,                        &
-                smearing_kernel_size, tower_cd, pitch_rate,                                        &
-                yaw_control, yaw_speed, tip_loss_correction
-!                , nacelle_cd
-
-!
-!-- Try to find wind turbine model package:
-    REWIND ( 11 )
-    line = ' '
-    DO WHILE ( INDEX ( line, '&wind_turbine_parameters' ) == 0 )
-       READ ( 11, '(A)', END = 12 )  line
-    ENDDO
-    BACKSPACE ( 11 )
-
-!
-!-- Read user-defined namelist:
-    READ ( 11, wind_turbine_parameters, ERR = 10, END = 12 )
-!
-!-- Set flag that indicates that the wind turbine model is switched on:
-    wind_turbine = .TRUE.
-
-    GOTO 12
-
- 10 BACKSPACE ( 11 )
-    READ ( 11, '(A)' ) line
-    CALL parin_fail_message( 'wind_turbine_parameters', line )
-
- 12 CONTINUE  ! TBD Change from continue, mit ierrn machen
+    CHARACTER(LEN=100) ::  line  !< dummy string that contains the current line of the parameter file
+
+    INTEGER(iwp) ::  io_status   !< status after reading the namelist file
+
+    LOGICAL ::  switch_off_module = .FALSE.  !< local namelist parameter to switch off the module
+                                             !< although the respective module namelist appears in
+                                             !< the namelist file
+
+    NAMELIST /wind_turbine_parameters/  air_density,                                               &
+                                        dt_data_output_wtm,                                        &
+                                        gear_efficiency,                                           &
+                                        gear_ratio,                                                &
+                                        generator_efficiency,                                      &
+                                        generator_inertia,                                         &
+                                        generator_power_rated,                                     &
+                                        generator_speed_rated,                                     &
+                                        generator_torque_max,                                      &
+                                        generator_torque_rate_max,                                 &
+                                        hub_x,                                                     &
+                                        hub_y,                                                     &
+                                        hub_z,                                                     &
+                                        nacelle_radius,                                            &
+                                        n_airfoils,                                                &
+                                        n_turbines,                                                &
+                                        pitch_angle,                                               &
+                                        pitch_control,                                             &
+                                        pitch_rate,                                                &
+                                        region_15_min,                                             &
+                                        region_2_min,                                              &
+                                        region_2_slope,                                            &
+                                        rotor_inertia,                                             &
+                                        rotor_radius,                                              &
+                                        rotor_speed,                                               &
+                                        segment_length_tangential,                                 &
+                                        segment_width_radial,                                      &
+                                        smearing_kernel_size,                                      &
+                                        speed_control,                                             &
+                                        switch_off_module,                                         &
+                                        tilt_angle,                                                &
+                                        time_turbine_on,                                           &
+                                        tip_loss_correction,                                       &
+                                        tower_cd,                                                  &
+                                        tower_diameter,                                            &
+                                        yaw_angle,                                                 &
+                                        yaw_control,                                               &
+                                        yaw_misalignment_max,                                      &
+                                        yaw_misalignment_min,                                      &
+                                        yaw_speed
+
+!
+!-- Move to the beginning of the namelist file and try to find and read the namelist.
+    REWIND( 11 )
+    READ( 11, wind_turbine_parameters, IOSTAT=io_status )
+
+!
+!-- Action depending on the READ status
+    IF ( io_status == 0 )  THEN
+!
+!--    wind_turbine_parameters namelist was found and read correctly. Enable the
+!--    wind turbine module.
+       IF ( .NOT. switch_off_module )  wind_turbine = .TRUE.
+
+    ELSEIF ( io_status > 0 )  THEN
+!
+!--    wind_turbine_parameters namelist was found but contained errors. Print an error message
+!--    including the line that caused the problem.
+       BACKSPACE( 11 )
+       READ( 11 , '(A)' ) line
+       CALL parin_fail_message( 'wind_turbine_parameters', line )
+
+    ENDIF
 
  END SUBROUTINE wtm_parin
