Index: palm/trunk/SOURCE/data_output_3d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_3d.f90	(revision 3589)
+++ palm/trunk/SOURCE/data_output_3d.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3589 2018-11-30 15:09:51Z suehring
 ! Move the control parameter "salsa" from salsa_mod to control_parameters 
 ! (M. Kurppa)
@@ -245,12 +248,6 @@
         ONLY:  lv_d_cp
 
-    USE biometeorology_mod,                                                    &
-        ONLY:  bio_data_output_3d
-
     USE bulk_cloud_model_mod,                                                  &
-        ONLY:  bulk_cloud_model, bcm_data_output_3d
-
-    USE chemistry_model_mod,                                                   &
-        ONLY:  chem_data_output_3d
+        ONLY:  bulk_cloud_model
 
     USE control_parameters,                                                    &
@@ -263,7 +260,4 @@
     USE cpulog,                                                                &
         ONLY:  log_point, cpu_log
-
-    USE gust_mod,                                                              &
-        ONLY: gust_data_output_3d, gust_module_enabled
 
 #if defined( __parallel )
@@ -282,4 +276,7 @@
         ONLY: lsm_data_output_3d, nzb_soil, nzt_soil
 
+    USE module_interface,                                                      &
+        ONLY:  module_interface_data_output_3d
+
 #if defined( __netcdf )
     USE NETCDF
@@ -289,22 +286,13 @@
         ONLY:  fill_value, id_set_3d, id_var_do3d, id_var_time_3d, nc_stat,    &
                netcdf_data_format, netcdf_handle_error
-        
-    USE ocean_mod,                                                             &
-        ONLY:  ocean_data_output_3d
 
     USE particle_attributes,                                                   &
         ONLY:  grid_particles, number_of_particles, particles,                 &
                particle_advection_start, prt_count
-        
+
     USE pegrid
 
-    USE plant_canopy_model_mod,                                                &
-        ONLY:  pcm_data_output_3d
-        
     USE radiation_model_mod,                                                   &
-        ONLY:  nzub, nzut, radiation, radiation_data_output_3d
-               
-    USE salsa_mod,                                                             &
-        ONLY:  salsa_data_output_3d     
+        ONLY:  nzub, nzut
 
     USE turbulence_closure_mod,                                                &
@@ -399,22 +387,15 @@
 
 !
-!--    Temporary solution to account for data output within the new urban 
+!--    Initiate found flag and resorting flag
+       found = .FALSE.
+       resorted = .FALSE.
+!
+!--    Temporary solution to account for data output within the new urban
 !--    surface model (urban_surface_mod.f90), see also SELECT CASE ( trimvar ).
 !--    Store the array chosen on the temporary array.
+       nzb_do   = nzb
+       nzt_do   = nz_do3d
+
        trimvar = TRIM( do3d(av,ivar) )
-       IF ( urban_surface  .AND.  trimvar(1:4) == 'usm_' )  THEN
-          trimvar = 'usm_output'
-          resorted = .TRUE.
-          nzb_do   = nzub
-          nzt_do   = nzut
-       ELSE
-          resorted = .FALSE.
-          nzb_do   = nzb
-          nzt_do   = nz_do3d
-       ENDIF
-!
-!--    Set flag to steer output of radiation, land-surface, or user-defined
-!--    quantities
-       found = .FALSE.
 !
 !--    Allocate a temporary array with the desired output dimensions.
@@ -715,37 +696,29 @@
                 to_be_resorted => w_av
              ENDIF
-!             
-!--       Block of urban surface model outputs   
-          CASE ( 'usm_output' )
-             CALL usm_data_output_3d( av, do3d(av,ivar), found, local_pf,        &
-                                         nzb_do, nzt_do )
 
           CASE DEFAULT
 
-!
-!--          Quantities of other modules
-             IF ( .NOT. found  .AND.  bulk_cloud_model )  THEN
-                CALL bcm_data_output_3d( av, do3d(av,ivar), found, local_pf,     &
+             IF ( .NOT. found )  THEN
+                CALL tcm_data_output_3d( av, trimvar, found, local_pf,   &
                                          nzb_do, nzt_do )
                 resorted = .TRUE.
              ENDIF
 
-             IF ( .NOT. found  .AND.  air_chemistry )  THEN
-                CALL chem_data_output_3d( av, do3d(av,ivar), found,              &
-                                          local_pf, fill_value, nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF
-
-             IF ( .NOT. found  .AND.  gust_module_enabled )  THEN
-                CALL gust_data_output_3d( av, do3d(av,ivar), found, local_pf,    &
-                                          nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF
-
-             IF ( .NOT. found  .AND.  land_surface )  THEN
-!
-!--             For soil model quantities, it is required to re-allocate local_pf
-                nzb_do = nzb_soil
-                nzt_do = nzt_soil
+!
+!--          Quantities of other modules
+             IF ( .NOT. found )  THEN
+                CALL module_interface_data_output_3d(                          &
+                        av, trimvar, found, local_pf,                          &
+                        fill_value, resorted, nzb_do, nzt_do                   &
+                     )
+             ENDIF
+
+!
+!--          Temporary workaround: ToDo: refactor local_pf allocation
+             IF ( .NOT. found  .AND.  urban_surface  .AND.  trimvar(1:4) == 'usm_' )  THEN
+!
+!--             For urban model quantities, it is required to re-allocate local_pf
+                nzb_do = nzub
+                nzt_do = nzut
 
                 DEALLOCATE ( local_pf )
@@ -753,5 +726,6 @@
                 local_pf = fill_value
 
-                CALL lsm_data_output_3d( av, do3d(av,ivar), found, local_pf )
+                CALL usm_data_output_3d( av, trimvar, found, local_pf,         &
+                                         nzb_do, nzt_do )
                 resorted = .TRUE.
 
@@ -763,52 +737,34 @@
 
                    DEALLOCATE ( local_pf )
-                   ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )                 
-                ENDIF
-
-             ENDIF
-
-             IF ( .NOT. found  .AND.  ocean_mode )  THEN
-                CALL ocean_data_output_3d( av, do3d(av,ivar), found, local_pf,   &
-                                           nzb_do, nzt_do )
+                   ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
+                ENDIF
+
+             ENDIF
+
+!
+!--          Temporary workaround: ToDo: refactor local_pf allocation
+             IF ( .NOT. found  .AND.  land_surface )  THEN
+!
+!--             For soil model quantities, it is required to re-allocate local_pf
+                nzb_do = nzb_soil
+                nzt_do = nzt_soil
+
+                DEALLOCATE ( local_pf )
+                ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
+                local_pf = fill_value
+
+                CALL lsm_data_output_3d( av, trimvar, found, local_pf )
                 resorted = .TRUE.
-             ENDIF
-
-             IF ( .NOT. found  .AND.  plant_canopy )  THEN
-                CALL pcm_data_output_3d( av, do3d(av,ivar), found, local_pf,     &
-                                         fill_value, nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF
-
-             IF ( .NOT. found  .AND.  radiation )  THEN
-                CALL radiation_data_output_3d( av, do3d(av,ivar), found,         &
-                                               local_pf, nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF
-
-             IF ( .NOT. found )  THEN
-                CALL tcm_data_output_3d( av, do3d(av,ivar), found, local_pf,     &
-                                         nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF
-             
-!
-!--          SALSA output
-             IF ( .NOT. found  .AND.  salsa )  THEN
-                CALL salsa_data_output_3d( av, do3d(av,ivar), found, local_pf, &
-                                           nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF                  
-
-             IF ( .NOT. found  .AND.  biometeorology )  THEN
-                 CALL bio_data_output_3d( av, do3d(av,ivar), found, local_pf,    &
-                                          nzb_do, nzt_do )
-             ENDIF
-
-!
-!--          User defined quantities
-             IF ( .NOT. found )  THEN
-                CALL user_data_output_3d( av, do3d(av,ivar), found, local_pf,    &
-                                          nzb_do, nzt_do )
-                resorted = .TRUE.
+
+!
+!--             If no soil model variable was found, re-allocate local_pf
+                IF ( .NOT. found )  THEN
+                   nzb_do = nzb
+                   nzt_do = nz_do3d
+
+                   DEALLOCATE ( local_pf )
+                   ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
+                ENDIF
+
              ENDIF
 
