source: palm/trunk/SOURCE/data_output_3d.f90 @ 3885

Last change on this file since 3885 was 3885, checked in by kanani, 5 years ago

restructure/add location/debug messages

  • Property svn:keywords set to Id
File size: 31.2 KB
RevLine 
[1682]1!> @file data_output_3d.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
[3655]17! Copyright 1997-2019 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[254]20! Current revisions:
[1106]21! ------------------
[3589]22!
23!
24! Former revisions:
25! -----------------
26! $Id: data_output_3d.f90 3885 2019-04-11 11:29:34Z kanani $
[3885]27! Changes related to global restructuring of location messages and introduction
28! of additional debug messages
29!
30! 3814 2019-03-26 08:40:31Z pavelkrc
[3766]31! unused variables removed
32!
33! 3655 2019-01-07 16:51:22Z knoop
[3646]34! Bugfix: use time_since_reference_point instead of simulated_time (relevant
35! when using wall/soil spinup)
36!
37! 3637 2018-12-20 01:51:36Z knoop
[3637]38! Implementation of the PALM module interface
39!
40! 3589 2018-11-30 15:09:51Z suehring
[3582]41! Move the control parameter "salsa" from salsa_mod to control_parameters
42! (M. Kurppa)
43!
[3589]44! 3582 2018-11-29 19:16:36Z suehring
[3554]45! add variable description; rename variable 'if' into 'ivar'
46!
47! 3525 2018-11-14 16:06:14Z kanani
[3525]48! Changes related to clean-up of biometeorology (dom_dwd_user)
49!
50! 3467 2018-10-30 19:05:21Z suehring
[3467]51! Implementation of a new aerosol module salsa.
52!
53! 3448 2018-10-29 18:14:31Z kanani
[3448]54! Adjustment of biometeorology calls
55!
56! 3421 2018-10-24 18:39:32Z gronemeier
[3421]57! Renamed output variables
58!
59! 3419 2018-10-24 17:27:31Z gronemeier
[3405]60! bugfix: nx, ny are required in non-parallel case
61!
62! 3337 2018-10-12 15:17:09Z kanani
[3337]63! (from branch resler)
64! Add Biometeorology
65!
66! 3294 2018-10-01 02:37:10Z raasch
[3294]67! changes concerning modularization of ocean option
68!
69! 3274 2018-09-24 15:42:55Z knoop
[3274]70! Modularization of all bulk cloud physics code components
71!
72! 3241 2018-09-12 15:02:00Z raasch
[3241]73! unused variables and format statements removed
74!
75! 3049 2018-05-29 13:52:36Z Giersch
[3049]76! Error messages revised
77!
78! 3045 2018-05-28 07:55:41Z Giersch
[3045]79! Error message revised
80!
81! 3014 2018-05-09 08:42:38Z maronga
[3014]82! Added nzb_do and nzt_do for some modules for 3d output
83!
84! 3004 2018-04-27 12:33:25Z Giersch
[3004]85! Allocation checks implemented (averaged data will be assigned to fill values
86! if no allocation happened so far)
87!
88! 2967 2018-04-13 11:22:08Z raasch
[2967]89! bugfix: missing parallel cpp-directives added
90!
91! 2817 2018-02-19 16:32:21Z knoop
[2817]92! Preliminary gust module interface implemented
93!
94! 2766 2018-01-22 17:17:47Z kanani
[2766]95! Removed preprocessor directive __chem
96!
97! 2756 2018-01-16 18:11:14Z suehring
[2756]98! Fill values for 3D output of chemical species introduced.
99!
100! 2746 2018-01-15 12:06:04Z suehring
[2746]101! Move flag plant canopy to modules
102!
103! 2718 2018-01-02 08:49:38Z maronga
[2716]104! Corrected "Former revisions" section
105!
106! 2696 2017-12-14 17:12:51Z kanani
107! Change in file header (GPL part)
[2696]108! Implementation of turbulence_closure_mod (TG)
109! Implementation of chemistry module (FK)
110! Set fill values at topography grid points or e.g. non-natural-type surface
111! in case of LSM output (MS)
112!
113! 2512 2017-10-04 08:26:59Z raasch
[2512]114! upper bounds of 3d output changed from nx+1,ny+1 to nx,ny
115! no output of ghost layer data
116!
117! 2292 2017-06-20 09:51:42Z schwenkel
[2292]118! Implementation of new microphysic scheme: cloud_scheme = 'morrison'
119! includes two more prognostic equations for cloud drop concentration (nc) 
120! and cloud water content (qc).
121!
122! 2233 2017-05-30 18:08:54Z suehring
[1552]123!
[2233]124! 2232 2017-05-30 17:47:52Z suehring
125! Adjustments to new topography concept
126!
[2210]127! 2209 2017-04-19 09:34:46Z kanani
128! Added plant canopy model output
129!
[2032]130! 2031 2016-10-21 15:11:58Z knoop
131! renamed variable rho to rho_ocean and rho_av to rho_ocean_av
132!
[2012]133! 2011 2016-09-19 17:29:57Z kanani
134! Flag urban_surface is now defined in module control_parameters,
135! changed prefix for urban surface model output to "usm_",
136! introduced control parameter varnamelength for LEN of trimvar.
137!
[2008]138! 2007 2016-08-24 15:47:17Z kanani
139! Added support for new urban surface model (temporary modifications of
140! SELECT CASE ( ) necessary, see variable trimvar)
141!
[2001]142! 2000 2016-08-20 18:09:15Z knoop
143! Forced header and separation lines into 80 columns
144!
[1981]145! 1980 2016-07-29 15:51:57Z suehring
146! Bugfix, in order to steer user-defined output, setting flag found explicitly
147! to .F.
148!
[1977]149! 1976 2016-07-27 13:28:04Z maronga
150! Output of radiation quantities is now done directly in the respective module
151!
[1973]152! 1972 2016-07-26 07:52:02Z maronga
153! Output of land surface quantities is now done directly in the respective module.
154! Unnecessary directive __parallel removed.
155!
[1961]156! 1960 2016-07-12 16:34:24Z suehring
157! Scalar surface flux added
158!
[1851]159! 1849 2016-04-08 11:33:18Z hoffmann
160! prr moved to arrays_3d
161!
[1823]162! 1822 2016-04-07 07:49:42Z hoffmann
163! prr vertical dimensions set to nzb_do to nzt_do. Unused variables deleted.
164!
[1809]165! 1808 2016-04-05 19:44:00Z raasch
166! test output removed
167!
[1784]168! 1783 2016-03-06 18:36:17Z raasch
169! name change of netcdf routines and module + related changes
170!
[1746]171! 1745 2016-02-05 13:06:51Z gronemeier
172! Bugfix: test if time axis limit exceeds moved to point after call of check_open
173!
[1692]174! 1691 2015-10-26 16:17:44Z maronga
175! Added output of radiative heating rates for RRTMG
176!
[1683]177! 1682 2015-10-07 23:56:08Z knoop
178! Code annotations made doxygen readable
179!
[1586]180! 1585 2015-04-30 07:05:52Z maronga
181! Added support for RRTMG
182!
[1552]183! 1551 2015-03-03 14:18:16Z maronga
[1551]184! Added suppport for land surface model and radiation model output. In the course
185! of this action, the limits for vertical loops have been changed (from nzb and
186! nzt+1 to nzb_do and nzt_do, respectively in order to allow soil model output).
187! Moreover, a new vertical grid zs was introduced.
[1329]188!
[1360]189! 1359 2014-04-11 17:15:14Z hoffmann
190! New particle structure integrated.
191!
[1354]192! 1353 2014-04-08 15:21:23Z heinze
193! REAL constants provided with KIND-attribute
194!
[1329]195! 1327 2014-03-21 11:00:16Z raasch
196! parts concerning avs output removed,
197! -netcdf output queries
198!
[1321]199! 1320 2014-03-20 08:40:49Z raasch
[1320]200! ONLY-attribute added to USE-statements,
201! kind-parameters added to all INTEGER and REAL declaration statements,
202! kinds are defined in new module kinds,
203! old module precision_kind is removed,
204! revision history before 2012 removed,
205! comment fields (!:) to be used for variable explanations added to
206! all variable declaration statements
[674]207!
[1319]208! 1318 2014-03-17 13:35:16Z raasch
209! barrier argument removed from cpu_log,
210! module interfaces removed
211!
[1309]212! 1308 2014-03-13 14:58:42Z fricke
213! Check, if the limit of the time dimension is exceeded for parallel output
214! To increase the performance for parallel output, the following is done:
215! - Update of time axis is only done by PE0
216!
[1245]217! 1244 2013-10-31 08:16:56Z raasch
218! Bugfix for index bounds in case of 3d-parallel output
219!
[1116]220! 1115 2013-03-26 18:16:16Z hoffmann
221! ql is calculated by calc_liquid_water_content
222!
[1107]223! 1106 2013-03-04 05:31:38Z raasch
224! array_kind renamed precision_kind
225!
[1077]226! 1076 2012-12-05 08:30:18Z hoffmann
227! Bugfix in output of ql
228!
[1054]229! 1053 2012-11-13 17:11:03Z hoffmann
230! +nr, qr, prr, qc and averaged quantities
231!
[1037]232! 1036 2012-10-22 13:43:42Z raasch
233! code put under GPL (PALM 3.9)
234!
[1035]235! 1031 2012-10-19 14:35:30Z raasch
236! netCDF4 without parallel file support implemented
237!
[1008]238! 1007 2012-09-19 14:30:36Z franke
239! Bugfix: missing calculation of ql_vp added
240!
[1]241! Revision 1.1  1997/09/03 06:29:36  raasch
242! Initial revision
243!
244!
245! Description:
246! ------------
[1682]247!> Output of the 3D-arrays in netCDF and/or AVS format.
[1]248!------------------------------------------------------------------------------!
[1682]249 SUBROUTINE data_output_3d( av )
250 
[1]251
[1320]252    USE arrays_3d,                                                             &
[3766]253        ONLY:  d_exner, e, p, pt, q, ql, ql_c, ql_v, s, tend, u, v, vpt, w
[3274]254
[1]255    USE averaging
[3274]256
257    USE basic_constants_and_equations_mod,                                     &
258        ONLY:  lv_d_cp
259
260    USE bulk_cloud_model_mod,                                                  &
[3637]261        ONLY:  bulk_cloud_model
[3274]262
[1320]263    USE control_parameters,                                                    &
[3885]264        ONLY:  debug_output, debug_string,                                     &
265               do3d, do3d_no, do3d_time_count, io_blocks, io_group,            &
[3766]266               land_surface, message_string, ntdim_3d, nz_do3d, psolver,       &
267               time_since_reference_point, urban_surface, varnamelength
[3274]268
[1320]269    USE cpulog,                                                                &
270        ONLY:  log_point, cpu_log
[2817]271
[3405]272#if defined( __parallel )
[1320]273    USE indices,                                                               &
[3241]274        ONLY:  nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt,     &
275               wall_flags_0
[3405]276#else
277    USE indices,                                                               &
278        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb,  &
279               nzt, wall_flags_0
280#endif
[3274]281
[1320]282    USE kinds
[3274]283
[1551]284    USE land_surface_model_mod,                                                &
[2232]285        ONLY: lsm_data_output_3d, nzb_soil, nzt_soil
[1551]286
[3637]287    USE module_interface,                                                      &
288        ONLY:  module_interface_data_output_3d
289
[1783]290#if defined( __netcdf )
291    USE NETCDF
292#endif
293
294    USE netcdf_interface,                                                      &
[2696]295        ONLY:  fill_value, id_set_3d, id_var_do3d, id_var_time_3d, nc_stat,    &
[1783]296               netcdf_data_format, netcdf_handle_error
[3294]297
[1320]298    USE particle_attributes,                                                   &
[1359]299        ONLY:  grid_particles, number_of_particles, particles,                 &
300               particle_advection_start, prt_count
[3637]301
[1]302    USE pegrid
303
[1585]304    USE radiation_model_mod,                                                   &
[3814]305        ONLY:  nz_urban_b, nz_urban_t
[1585]306
[2696]307    USE turbulence_closure_mod,                                                &
308        ONLY:  tcm_data_output_3d
309
[2007]310    USE urban_surface_mod,                                                     &
[2696]311        ONLY:  usm_data_output_3d
[1585]312
[2007]313
[1]314    IMPLICIT NONE
315
[3554]316    INTEGER(iwp) ::  av        !< flag for (non-)average output
[2696]317    INTEGER(iwp) ::  flag_nr   !< number of masking flag
[3554]318    INTEGER(iwp) ::  i         !< loop index
319    INTEGER(iwp) ::  ivar      !< variable index
320    INTEGER(iwp) ::  j         !< loop index
321    INTEGER(iwp) ::  k         !< loop index
322    INTEGER(iwp) ::  n         !< loop index
[1682]323    INTEGER(iwp) ::  nzb_do    !< vertical lower limit for data output
324    INTEGER(iwp) ::  nzt_do    !< vertical upper limit for data output
[1]325
[3554]326    LOGICAL      ::  found     !< true if output variable was found
327    LOGICAL      ::  resorted  !< true if variable is resorted
[1]328
[3554]329    REAL(wp)     ::  mean_r    !< mean particle radius
330    REAL(wp)     ::  s_r2      !< sum( particle-radius**2 )
331    REAL(wp)     ::  s_r3      !< sum( particle-radius**3 )
[1]332
[3554]333    REAL(sp), DIMENSION(:,:,:), ALLOCATABLE ::  local_pf  !< output array
[1]334
[3554]335    REAL(wp), DIMENSION(:,:,:), POINTER ::  to_be_resorted  !< pointer to array which shall be output
[1]336
[2011]337    CHARACTER (LEN=varnamelength) ::  trimvar  !< TRIM of output-variable string
[2007]338
[1]339!
340!-- Return, if nothing to output
341    IF ( do3d_no(av) == 0 )  RETURN
342
[3885]343    IF ( debug_output )  THEN
344       WRITE( debug_string, * ) 'data_output_3d'
345       CALL debug_message( debug_string, 'start' )
346    ENDIF
347
[1]348    CALL cpu_log (log_point(14),'data_output_3d','start')
349
350!
351!-- Open output file.
[2512]352!-- For classic or 64bit netCDF output on more than one PE, each PE opens its
353!-- own file and writes the data of its subdomain in binary format. After the
354!-- run, these files are combined to one NetCDF file by combine_plot_fields.
[1031]355!-- For netCDF4/HDF5 output, data is written in parallel into one file.
[1327]356    IF ( netcdf_data_format < 5 )  THEN
[2967]357#if defined( __parallel )
[1327]358       CALL check_open( 30 )
[2967]359#endif
[1327]360       IF ( myid == 0 )  CALL check_open( 106+av*10 )
[493]361    ELSE
[1327]362       CALL check_open( 106+av*10 )
[493]363    ENDIF
[1]364
365!
[1745]366!-- For parallel netcdf output the time axis must be limited. Return, if this
367!-- limit is exceeded. This could be the case, if the simulated time exceeds
368!-- the given end time by the length of the given output interval.
369    IF ( netcdf_data_format > 4 )  THEN
370       IF ( do3d_time_count(av) + 1 > ntdim_3d(av) )  THEN
[3646]371          WRITE ( message_string, * ) 'Output of 3d data is not given at t=',               &
372                                      time_since_reference_point, 's because the maximum ', & 
373                                      'number of output time levels is ',                   &
[1745]374                                      'exceeded.'
375          CALL message( 'data_output_3d', 'PA0387', 0, 1, 0, 6, 0 )
376          CALL cpu_log( log_point(14), 'data_output_3d', 'stop' )
377          RETURN
378       ENDIF
379    ENDIF
380
381!
[1031]382!-- Update the netCDF time axis
[1308]383!-- In case of parallel output, this is only done by PE0 to increase the
384!-- performance.
[1]385#if defined( __netcdf )
[1308]386    do3d_time_count(av) = do3d_time_count(av) + 1
387    IF ( myid == 0 )  THEN
[1327]388       nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_time_3d(av),           &
389                               (/ time_since_reference_point /),            &
390                               start = (/ do3d_time_count(av) /),           &
391                               count = (/ 1 /) )
[1783]392       CALL netcdf_handle_error( 'data_output_3d', 376 )
[1]393    ENDIF
394#endif
395
396!
397!-- Loop over all variables to be written.
[3554]398    ivar = 1
[1]399
[3554]400    DO  WHILE ( do3d(av,ivar)(1:1) /= ' ' )
[2007]401
[1]402!
[3637]403!--    Initiate found flag and resorting flag
404       found = .FALSE.
405       resorted = .FALSE.
406!
407!--    Temporary solution to account for data output within the new urban
[2007]408!--    surface model (urban_surface_mod.f90), see also SELECT CASE ( trimvar ).
[1]409!--    Store the array chosen on the temporary array.
[3637]410       nzb_do   = nzb
411       nzt_do   = nz_do3d
412
[3554]413       trimvar = TRIM( do3d(av,ivar) )
[1551]414!
415!--    Allocate a temporary array with the desired output dimensions.
[2512]416       ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
[2696]417!
418!--    Before each output, set array local_pf to fill value
419       local_pf = fill_value
420!
421!--    Set masking flag for topography for not resorted arrays
422       flag_nr = 0
[1551]423
[2007]424       SELECT CASE ( trimvar )
[1]425
426          CASE ( 'e' )
427             IF ( av == 0 )  THEN
428                to_be_resorted => e
429             ELSE
[3004]430                IF ( .NOT. ALLOCATED( e_av ) ) THEN
431                   ALLOCATE( e_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
432                   e_av = REAL( fill_value, KIND = wp )
433                ENDIF
[1]434                to_be_resorted => e_av
435             ENDIF
436
[3421]437          CASE ( 'thetal' )
[771]438             IF ( av == 0 )  THEN
439                to_be_resorted => pt
440             ELSE
[3004]441                IF ( .NOT. ALLOCATED( lpt_av ) ) THEN
442                   ALLOCATE( lpt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
443                   lpt_av = REAL( fill_value, KIND = wp )
444                ENDIF
[771]445                to_be_resorted => lpt_av
446             ENDIF
447
[1]448          CASE ( 'p' )
449             IF ( av == 0 )  THEN
[727]450                IF ( psolver /= 'sor' )  CALL exchange_horiz( p, nbgp )
[1]451                to_be_resorted => p
452             ELSE
[3004]453                IF ( .NOT. ALLOCATED( p_av ) ) THEN
454                   ALLOCATE( p_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
455                   p_av = REAL( fill_value, KIND = wp )
456                ENDIF
[727]457                IF ( psolver /= 'sor' )  CALL exchange_horiz( p_av, nbgp )
[1]458                to_be_resorted => p_av
459             ENDIF
460
461          CASE ( 'pc' )  ! particle concentration (requires ghostpoint exchange)
462             IF ( av == 0 )  THEN
[3646]463                IF ( time_since_reference_point >= particle_advection_start )  THEN
[1359]464                   tend = prt_count
465                ELSE
466                   tend = 0.0_wp
467                ENDIF
[2512]468                DO  i = nxl, nxr
469                   DO  j = nys, nyn
[1551]470                      DO  k = nzb_do, nzt_do
[1]471                         local_pf(i,j,k) = tend(k,j,i)
472                      ENDDO
473                   ENDDO
474                ENDDO
475                resorted = .TRUE.
476             ELSE
[3004]477                IF ( .NOT. ALLOCATED( pc_av ) ) THEN
478                   ALLOCATE( pc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
479                   pc_av = REAL( fill_value, KIND = wp )
480                ENDIF
[1]481                to_be_resorted => pc_av
482             ENDIF
483
[1359]484          CASE ( 'pr' )  ! mean particle radius (effective radius)
[1]485             IF ( av == 0 )  THEN
[3646]486                IF ( time_since_reference_point >= particle_advection_start )  THEN
[1359]487                   DO  i = nxl, nxr
488                      DO  j = nys, nyn
[1551]489                         DO  k = nzb_do, nzt_do
[1359]490                            number_of_particles = prt_count(k,j,i)
491                            IF (number_of_particles <= 0)  CYCLE
492                            particles => grid_particles(k,j,i)%particles(1:number_of_particles)
493                            s_r2 = 0.0_wp
494                            s_r3 = 0.0_wp
495                            DO  n = 1, number_of_particles
496                               IF ( particles(n)%particle_mask )  THEN
497                                  s_r2 = s_r2 + particles(n)%radius**2 * &
498                                         particles(n)%weight_factor
499                                  s_r3 = s_r3 + particles(n)%radius**3 * &
500                                         particles(n)%weight_factor
501                               ENDIF
502                            ENDDO
503                            IF ( s_r2 > 0.0_wp )  THEN
504                               mean_r = s_r3 / s_r2
505                            ELSE
506                               mean_r = 0.0_wp
507                            ENDIF
508                            tend(k,j,i) = mean_r
[1]509                         ENDDO
510                      ENDDO
511                   ENDDO
[1359]512                ELSE
513                   tend = 0.0_wp
514                ENDIF
[2512]515                DO  i = nxl, nxr
516                   DO  j = nys, nyn
[1551]517                      DO  k = nzb_do, nzt_do
[1]518                         local_pf(i,j,k) = tend(k,j,i)
519                      ENDDO
520                   ENDDO
521                ENDDO
522                resorted = .TRUE.
523             ELSE
[3004]524                IF ( .NOT. ALLOCATED( pr_av ) ) THEN
525                   ALLOCATE( pr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
526                   pr_av = REAL( fill_value, KIND = wp )
527                ENDIF
[1]528                to_be_resorted => pr_av
529             ENDIF
530
[3421]531          CASE ( 'theta' )
[1]532             IF ( av == 0 )  THEN
[3274]533                IF ( .NOT. bulk_cloud_model ) THEN
[1]534                   to_be_resorted => pt
535                ELSE
[2512]536                   DO  i = nxl, nxr
537                      DO  j = nys, nyn
[1551]538                         DO  k = nzb_do, nzt_do
[3274]539                            local_pf(i,j,k) = pt(k,j,i) + lv_d_cp *            &
540                                                          d_exner(k) *         &
[1]541                                                          ql(k,j,i)
542                         ENDDO
543                      ENDDO
544                   ENDDO
545                   resorted = .TRUE.
546                ENDIF
547             ELSE
[3004]548                IF ( .NOT. ALLOCATED( pt_av ) ) THEN
549                   ALLOCATE( pt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
550                   pt_av = REAL( fill_value, KIND = wp )
551                ENDIF
[1]552                to_be_resorted => pt_av
553             ENDIF
554
555          CASE ( 'q' )
556             IF ( av == 0 )  THEN
557                to_be_resorted => q
558             ELSE
[3004]559                IF ( .NOT. ALLOCATED( q_av ) ) THEN
560                   ALLOCATE( q_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
561                   q_av = REAL( fill_value, KIND = wp )
562                ENDIF
[1]563                to_be_resorted => q_av
564             ENDIF
[691]565
[1053]566          CASE ( 'ql' )
567             IF ( av == 0 )  THEN
[1115]568                to_be_resorted => ql
[1053]569             ELSE
[3004]570                IF ( .NOT. ALLOCATED( ql_av ) ) THEN
571                   ALLOCATE( ql_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
572                   ql_av = REAL( fill_value, KIND = wp )
573                ENDIF
[1115]574                to_be_resorted => ql_av
[1053]575             ENDIF
576
[1]577          CASE ( 'ql_c' )
578             IF ( av == 0 )  THEN
579                to_be_resorted => ql_c
580             ELSE
[3004]581                IF ( .NOT. ALLOCATED( ql_c_av ) ) THEN
582                   ALLOCATE( ql_c_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
583                   ql_c_av = REAL( fill_value, KIND = wp )
584                ENDIF
[1]585                to_be_resorted => ql_c_av
586             ENDIF
587
588          CASE ( 'ql_v' )
589             IF ( av == 0 )  THEN
590                to_be_resorted => ql_v
591             ELSE
[3004]592                IF ( .NOT. ALLOCATED( ql_v_av ) ) THEN
593                   ALLOCATE( ql_v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
594                   ql_v_av = REAL( fill_value, KIND = wp )
595                ENDIF
[1]596                to_be_resorted => ql_v_av
597             ENDIF
598
599          CASE ( 'ql_vp' )
600             IF ( av == 0 )  THEN
[3646]601                IF ( time_since_reference_point >= particle_advection_start )  THEN
[1359]602                   DO  i = nxl, nxr
603                      DO  j = nys, nyn
[1551]604                         DO  k = nzb_do, nzt_do
[1359]605                            number_of_particles = prt_count(k,j,i)
606                            IF (number_of_particles <= 0)  CYCLE
607                            particles => grid_particles(k,j,i)%particles(1:number_of_particles)
608                            DO  n = 1, number_of_particles
609                               IF ( particles(n)%particle_mask )  THEN
610                                  tend(k,j,i) =  tend(k,j,i) +                 &
611                                                 particles(n)%weight_factor /  &
612                                                 prt_count(k,j,i)
613                               ENDIF
614                            ENDDO
[1007]615                         ENDDO
616                      ENDDO
617                   ENDDO
[1359]618                ELSE
619                   tend = 0.0_wp
620                ENDIF
[2512]621                DO  i = nxl, nxr
622                   DO  j = nys, nyn
[1551]623                      DO  k = nzb_do, nzt_do
[1007]624                         local_pf(i,j,k) = tend(k,j,i)
625                      ENDDO
626                   ENDDO
627                ENDDO
628                resorted = .TRUE.
[1]629             ELSE
[3004]630                IF ( .NOT. ALLOCATED( ql_vp_av ) ) THEN
631                   ALLOCATE( ql_vp_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
632                   ql_vp_av = REAL( fill_value, KIND = wp )
633                ENDIF
[1]634                to_be_resorted => ql_vp_av
635             ENDIF
636
637          CASE ( 'qv' )
638             IF ( av == 0 )  THEN
[2512]639                DO  i = nxl, nxr
640                   DO  j = nys, nyn
[1551]641                      DO  k = nzb_do, nzt_do
[1]642                         local_pf(i,j,k) = q(k,j,i) - ql(k,j,i)
643                      ENDDO
644                   ENDDO
645                ENDDO
646                resorted = .TRUE.
647             ELSE
[3004]648                IF ( .NOT. ALLOCATED( qv_av ) ) THEN
649                   ALLOCATE( qv_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
650                   qv_av = REAL( fill_value, KIND = wp )
651                ENDIF
[1]652                to_be_resorted => qv_av
653             ENDIF
654
655          CASE ( 's' )
656             IF ( av == 0 )  THEN
[1960]657                to_be_resorted => s
[1]658             ELSE
[3004]659                IF ( .NOT. ALLOCATED( s_av ) ) THEN
660                   ALLOCATE( s_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
661                   s_av = REAL( fill_value, KIND = wp )
662                ENDIF
[355]663                to_be_resorted => s_av
[1]664             ENDIF
[691]665
[1]666          CASE ( 'u' )
[2696]667             flag_nr = 1
[1]668             IF ( av == 0 )  THEN
669                to_be_resorted => u
670             ELSE
[3004]671                IF ( .NOT. ALLOCATED( u_av ) ) THEN
672                   ALLOCATE( u_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
673                   u_av = REAL( fill_value, KIND = wp )
674                ENDIF
[1]675                to_be_resorted => u_av
676             ENDIF
677
678          CASE ( 'v' )
[2696]679             flag_nr = 2
[1]680             IF ( av == 0 )  THEN
681                to_be_resorted => v
682             ELSE
[3004]683                IF ( .NOT. ALLOCATED( v_av ) ) THEN
684                   ALLOCATE( v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
685                   v_av = REAL( fill_value, KIND = wp )
686                ENDIF
[1]687                to_be_resorted => v_av
688             ENDIF
689
[3421]690          CASE ( 'thetav' )
[1]691             IF ( av == 0 )  THEN
692                to_be_resorted => vpt
693             ELSE
[3004]694                IF ( .NOT. ALLOCATED( vpt_av ) ) THEN
695                   ALLOCATE( vpt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
696                   vpt_av = REAL( fill_value, KIND = wp )
697                ENDIF
[1]698                to_be_resorted => vpt_av
699             ENDIF
700
701          CASE ( 'w' )
[2696]702             flag_nr = 3
[1]703             IF ( av == 0 )  THEN
704                to_be_resorted => w
705             ELSE
[3004]706                IF ( .NOT. ALLOCATED( w_av ) ) THEN
707                   ALLOCATE( w_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
708                   w_av = REAL( fill_value, KIND = wp )
709                ENDIF
[1]710                to_be_resorted => w_av
711             ENDIF
712
713          CASE DEFAULT
[1972]714
[3637]715             IF ( .NOT. found )  THEN
716                CALL tcm_data_output_3d( av, trimvar, found, local_pf,   &
[3274]717                                         nzb_do, nzt_do )
718                resorted = .TRUE.
719             ENDIF
720
[3637]721!
722!--          Quantities of other modules
723             IF ( .NOT. found )  THEN
724                CALL module_interface_data_output_3d(                          &
725                        av, trimvar, found, local_pf,                          &
726                        fill_value, resorted, nzb_do, nzt_do                   &
727                     )
[3294]728             ENDIF
729
[1972]730!
[3637]731!--          Temporary workaround: ToDo: refactor local_pf allocation
732             IF ( .NOT. found  .AND.  urban_surface  .AND.  trimvar(1:4) == 'usm_' )  THEN
733!
734!--             For urban model quantities, it is required to re-allocate local_pf
[3814]735                nzb_do = nz_urban_b
736                nzt_do = nz_urban_t
[1972]737
738                DEALLOCATE ( local_pf )
[2512]739                ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
[2696]740                local_pf = fill_value
[1972]741
[3637]742                CALL usm_data_output_3d( av, trimvar, found, local_pf,         &
743                                         nzb_do, nzt_do )
[1972]744                resorted = .TRUE.
[1976]745
746!
747!--             If no soil model variable was found, re-allocate local_pf
748                IF ( .NOT. found )  THEN
749                   nzb_do = nzb
750                   nzt_do = nz_do3d
751
752                   DEALLOCATE ( local_pf )
[3637]753                   ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
[1976]754                ENDIF
755
[1972]756             ENDIF
757
[3637]758!
759!--          Temporary workaround: ToDo: refactor local_pf allocation
760             IF ( .NOT. found  .AND.  land_surface )  THEN
761!
762!--             For soil model quantities, it is required to re-allocate local_pf
763                nzb_do = nzb_soil
764                nzt_do = nzt_soil
[1976]765
[3637]766                DEALLOCATE ( local_pf )
767                ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
768                local_pf = fill_value
[2817]769
[3637]770                CALL lsm_data_output_3d( av, trimvar, found, local_pf )
[2696]771                resorted = .TRUE.
772
[3467]773!
[3637]774!--             If no soil model variable was found, re-allocate local_pf
775                IF ( .NOT. found )  THEN
776                   nzb_do = nzb
777                   nzt_do = nz_do3d
[2209]778
[3637]779                   DEALLOCATE ( local_pf )
780                   ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
781                ENDIF
[3448]782
[1972]783             ENDIF
[1]784
[254]785             IF ( .NOT. found )  THEN
[1320]786                message_string =  'no output available for: ' //               &
[3554]787                                  TRIM( do3d(av,ivar) )
[254]788                CALL message( 'data_output_3d', 'PA0182', 0, 0, 0, 6, 0 )
[1]789             ENDIF
790
791       END SELECT
792
793!
794!--    Resort the array to be output, if not done above
795       IF ( .NOT. resorted )  THEN
[2512]796          DO  i = nxl, nxr
797             DO  j = nys, nyn
[1551]798                DO  k = nzb_do, nzt_do
[2696]799                   local_pf(i,j,k) = MERGE(                                    &
800                                      to_be_resorted(k,j,i),                   &
801                                      REAL( fill_value, KIND = wp ),           &
802                                      BTEST( wall_flags_0(k,j,i), flag_nr ) )
[1]803                ENDDO
804             ENDDO
805          ENDDO
806       ENDIF
807
808!
[1327]809!--    Output of the 3D-array
810#if defined( __parallel )
811       IF ( netcdf_data_format < 5 )  THEN
[1]812!
[1327]813!--       Non-parallel netCDF output. Data is output in parallel in
814!--       FORTRAN binary format here, and later collected into one file by
815!--       combine_plot_fields
816          IF ( myid == 0 )  THEN
817             WRITE ( 30 )  time_since_reference_point,                   &
818                           do3d_time_count(av), av
[1]819          ENDIF
[1327]820          DO  i = 0, io_blocks-1
821             IF ( i == io_group )  THEN
[2512]822                WRITE ( 30 )  nxl, nxr, nys, nyn, nzb_do, nzt_do
[1551]823                WRITE ( 30 )  local_pf(:,:,nzb_do:nzt_do)
[1327]824             ENDIF
[1972]825
[1327]826             CALL MPI_BARRIER( comm2d, ierr )
[1972]827
[1327]828          ENDDO
[559]829
[1327]830       ELSE
[646]831#if defined( __netcdf )
[493]832!
[1327]833!--       Parallel output in netCDF4/HDF5 format.
[2512]834!          IF ( nxr == nx  .AND.  nyn /= ny )  THEN
[3554]835!             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar),  &
[2512]836!                               local_pf(nxl:nxr+1,nys:nyn,nzb_do:nzt_do),    &
837!                start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /),  &
838!                count = (/ nxr-nxl+2, nyn-nys+1, nzt_do-nzb_do+1, 1 /) )
839!          ELSEIF ( nxr /= nx  .AND.  nyn == ny )  THEN
[3554]840!             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar),  &
[2512]841!                               local_pf(nxl:nxr,nys:nyn+1,nzb_do:nzt_do),    &
842!                start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /),  &
843!                count = (/ nxr-nxl+1, nyn-nys+2, nzt_do-nzb_do+1, 1 /) )
844!          ELSEIF ( nxr == nx  .AND.  nyn == ny )  THEN
[3554]845!             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar),  &
[2512]846!                             local_pf(nxl:nxr+1,nys:nyn+1,nzb_do:nzt_do  ),  &
847!                start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /),  &
848!                count = (/ nxr-nxl+2, nyn-nys+2, nzt_do-nzb_do+1, 1 /) )
849!          ELSE
[3554]850             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar),  &
[1551]851                                 local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do),    &
852                start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /),  &
853                count = (/ nxr-nxl+1, nyn-nys+1, nzt_do-nzb_do+1, 1 /) )
[2512]854!          ENDIF
[1783]855          CALL netcdf_handle_error( 'data_output_3d', 386 )
[646]856#endif
[1327]857       ENDIF
[1]858#else
859#if defined( __netcdf )
[3554]860       nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar),        &
[1551]861                         local_pf(nxl:nxr+1,nys:nyn+1,nzb_do:nzt_do),        &
[1327]862                         start = (/ 1, 1, 1, do3d_time_count(av) /),     &
[2512]863                         count = (/ nx+1, ny+1, nzt_do-nzb_do+1, 1 /) )
[1783]864       CALL netcdf_handle_error( 'data_output_3d', 446 )
[1]865#endif
866#endif
867
[3554]868       ivar = ivar + 1
[1]869
870!
[1551]871!--    Deallocate temporary array
872       DEALLOCATE ( local_pf )
[1]873
[1551]874    ENDDO
[1]875
[1318]876    CALL cpu_log( log_point(14), 'data_output_3d', 'stop' )
[1]877
[3885]878    IF ( debug_output )  THEN
879       WRITE( debug_string, * ) 'data_output_3d'
880       CALL debug_message( debug_string, 'end' )
881    ENDIF
882
[1]883 END SUBROUTINE data_output_3d
Note: See TracBrowser for help on using the repository browser.