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

Last change on this file since 4455 was 4444, checked in by raasch, 4 years ago

bugfix: cpp-directives for serial mode added

  • Property svn:keywords set to Id
File size: 25.9 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!
[4360]17! Copyright 1997-2020 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 4444 2020-03-05 15:59:50Z Giersch $
[4444]27! bugfix: cpp-directives for serial mode added
28!
29! 4360 2020-01-07 11:25:50Z suehring
[4346]30! Introduction of wall_flags_total_0, which currently sets bits based on static
31! topography information used in wall_flags_static_0
32!
33! 4329 2019-12-10 15:46:36Z motisi
[4329]34! Renamed wall_flags_0 to wall_flags_static_0
35!
36! 4182 2019-08-22 15:20:23Z scharf
[4182]37! Corrected "Former revisions" section
38!
39! 4162 2019-08-16 05:54:29Z raasch
[4162]40! bugfix for r4155
41!
42! 4155 2019-08-14 06:25:18Z raasch
[4155]43! bugfix for 3d-output in serial mode (ghost points must not be written)
44!
45! 4127 2019-07-30 14:47:10Z suehring
[4127]46! Adjustment for top boundary index for plant-canopy model outputs
47! (merge from branch resler)
48!
49! 4048 2019-06-21 21:00:21Z knoop
[4048]50! Moved tcm_data_output_3d to module_interface
51!
52! 4039 2019-06-18 10:32:41Z suehring
[4039]53! modularize diagnostic output
54!
55! 3994 2019-05-22 18:08:09Z suehring
[3994]56! output of turbulence intensity added
57!
58! 3987 2019-05-22 09:52:13Z kanani
[3987]59! Introduce alternative switch for debug output during timestepping
60!
61! 3885 2019-04-11 11:29:34Z kanani
[3885]62! Changes related to global restructuring of location messages and introduction
63! of additional debug messages
64!
65! 3814 2019-03-26 08:40:31Z pavelkrc
[3766]66! unused variables removed
67!
68! 3655 2019-01-07 16:51:22Z knoop
[3646]69! Bugfix: use time_since_reference_point instead of simulated_time (relevant
70! when using wall/soil spinup)
[3582]71!
[4182]72! Revision 1.1  1997/09/03 06:29:36  raasch
73! Initial revision
74!
75!
[1]76! Description:
77! ------------
[1682]78!> Output of the 3D-arrays in netCDF and/or AVS format.
[1]79!------------------------------------------------------------------------------!
[1682]80 SUBROUTINE data_output_3d( av )
81 
[1]82
[1320]83    USE arrays_3d,                                                             &
[3766]84        ONLY:  d_exner, e, p, pt, q, ql, ql_c, ql_v, s, tend, u, v, vpt, w
[3274]85
[1]86    USE averaging
[3274]87
88    USE basic_constants_and_equations_mod,                                     &
89        ONLY:  lv_d_cp
90
91    USE bulk_cloud_model_mod,                                                  &
[3637]92        ONLY:  bulk_cloud_model
[3274]93
[1320]94    USE control_parameters,                                                    &
[4444]95        ONLY:  debug_output_timestep, do3d, do3d_no, do3d_time_count,          &
[4127]96               land_surface, message_string, ntdim_3d, nz_do3d, plant_canopy,  &
97               psolver, time_since_reference_point, urban_surface,             &
98               varnamelength
[3274]99
[4444]100#if defined( __parallel )
101    USE control_parameters,                                                    &
102        ONLY:  io_blocks, io_group
103#endif
104
[1320]105    USE cpulog,                                                                &
106        ONLY:  log_point, cpu_log
[2817]107
[1320]108    USE indices,                                                               &
[3241]109        ONLY:  nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt,     &
[4346]110               wall_flags_total_0
[4444]111
112#if ! defined( __parallel )
[3405]113    USE indices,                                                               &
[4444]114        ONLY:  nx, ny
[3405]115#endif
[3274]116
[1320]117    USE kinds
[3274]118
[1551]119    USE land_surface_model_mod,                                                &
[2232]120        ONLY: lsm_data_output_3d, nzb_soil, nzt_soil
[1551]121
[3637]122    USE module_interface,                                                      &
123        ONLY:  module_interface_data_output_3d
124
[1783]125#if defined( __netcdf )
126    USE NETCDF
127#endif
128
129    USE netcdf_interface,                                                      &
[2696]130        ONLY:  fill_value, id_set_3d, id_var_do3d, id_var_time_3d, nc_stat,    &
[1783]131               netcdf_data_format, netcdf_handle_error
[3294]132
[1320]133    USE particle_attributes,                                                   &
[1359]134        ONLY:  grid_particles, number_of_particles, particles,                 &
135               particle_advection_start, prt_count
[3637]136
[1]137    USE pegrid
138
[4127]139    USE plant_canopy_model_mod,                                                &
140        ONLY:  pch_index
141
[1585]142    USE radiation_model_mod,                                                   &
[3814]143        ONLY:  nz_urban_b, nz_urban_t
[1585]144
[2007]145    USE urban_surface_mod,                                                     &
[2696]146        ONLY:  usm_data_output_3d
[1585]147
[2007]148
[1]149    IMPLICIT NONE
150
[3554]151    INTEGER(iwp) ::  av        !< flag for (non-)average output
[2696]152    INTEGER(iwp) ::  flag_nr   !< number of masking flag
[3554]153    INTEGER(iwp) ::  i         !< loop index
154    INTEGER(iwp) ::  ivar      !< variable index
155    INTEGER(iwp) ::  j         !< loop index
156    INTEGER(iwp) ::  k         !< loop index
157    INTEGER(iwp) ::  n         !< loop index
[1682]158    INTEGER(iwp) ::  nzb_do    !< vertical lower limit for data output
159    INTEGER(iwp) ::  nzt_do    !< vertical upper limit for data output
[1]160
[3554]161    LOGICAL      ::  found     !< true if output variable was found
162    LOGICAL      ::  resorted  !< true if variable is resorted
[1]163
[3554]164    REAL(wp)     ::  mean_r    !< mean particle radius
165    REAL(wp)     ::  s_r2      !< sum( particle-radius**2 )
166    REAL(wp)     ::  s_r3      !< sum( particle-radius**3 )
[1]167
[3554]168    REAL(sp), DIMENSION(:,:,:), ALLOCATABLE ::  local_pf  !< output array
[1]169
[3554]170    REAL(wp), DIMENSION(:,:,:), POINTER ::  to_be_resorted  !< pointer to array which shall be output
[1]171
[2011]172    CHARACTER (LEN=varnamelength) ::  trimvar  !< TRIM of output-variable string
[2007]173
[1]174!
175!-- Return, if nothing to output
176    IF ( do3d_no(av) == 0 )  RETURN
177
[3987]178    IF ( debug_output_timestep )  CALL debug_message( 'data_output_3d', 'start' )
[3885]179
[1]180    CALL cpu_log (log_point(14),'data_output_3d','start')
181
182!
183!-- Open output file.
[2512]184!-- For classic or 64bit netCDF output on more than one PE, each PE opens its
185!-- own file and writes the data of its subdomain in binary format. After the
186!-- run, these files are combined to one NetCDF file by combine_plot_fields.
[1031]187!-- For netCDF4/HDF5 output, data is written in parallel into one file.
[1327]188    IF ( netcdf_data_format < 5 )  THEN
[2967]189#if defined( __parallel )
[1327]190       CALL check_open( 30 )
[2967]191#endif
[1327]192       IF ( myid == 0 )  CALL check_open( 106+av*10 )
[493]193    ELSE
[1327]194       CALL check_open( 106+av*10 )
[493]195    ENDIF
[1]196
197!
[1745]198!-- For parallel netcdf output the time axis must be limited. Return, if this
199!-- limit is exceeded. This could be the case, if the simulated time exceeds
200!-- the given end time by the length of the given output interval.
201    IF ( netcdf_data_format > 4 )  THEN
202       IF ( do3d_time_count(av) + 1 > ntdim_3d(av) )  THEN
[3646]203          WRITE ( message_string, * ) 'Output of 3d data is not given at t=',               &
204                                      time_since_reference_point, 's because the maximum ', & 
205                                      'number of output time levels is ',                   &
[1745]206                                      'exceeded.'
207          CALL message( 'data_output_3d', 'PA0387', 0, 1, 0, 6, 0 )
208          CALL cpu_log( log_point(14), 'data_output_3d', 'stop' )
209          RETURN
210       ENDIF
211    ENDIF
212
213!
[1031]214!-- Update the netCDF time axis
[1308]215!-- In case of parallel output, this is only done by PE0 to increase the
216!-- performance.
[1]217#if defined( __netcdf )
[1308]218    do3d_time_count(av) = do3d_time_count(av) + 1
219    IF ( myid == 0 )  THEN
[1327]220       nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_time_3d(av),           &
221                               (/ time_since_reference_point /),            &
222                               start = (/ do3d_time_count(av) /),           &
223                               count = (/ 1 /) )
[1783]224       CALL netcdf_handle_error( 'data_output_3d', 376 )
[1]225    ENDIF
226#endif
227
228!
229!-- Loop over all variables to be written.
[3554]230    ivar = 1
[1]231
[3554]232    DO  WHILE ( do3d(av,ivar)(1:1) /= ' ' )
[2007]233
[1]234!
[3637]235!--    Initiate found flag and resorting flag
236       found = .FALSE.
237       resorted = .FALSE.
[4127]238       trimvar = TRIM( do3d(av,ivar) )
239
[3637]240!
241!--    Temporary solution to account for data output within the new urban
[2007]242!--    surface model (urban_surface_mod.f90), see also SELECT CASE ( trimvar ).
[1]243!--    Store the array chosen on the temporary array.
[3637]244       nzb_do   = nzb
[4127]245!
246!--    Set top index for 3D output. Note in case of plant-canopy model
247!--    these index is determined by pch_index.
248       IF ( plant_canopy  .AND.  trimvar(1:4) == 'pcm_' )  THEN
249          nzt_do   = pch_index
250       ELSE
251          nzt_do   = nz_do3d
252       ENDIF
[3637]253
[1551]254!
255!--    Allocate a temporary array with the desired output dimensions.
[2512]256       ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
[2696]257!
258!--    Before each output, set array local_pf to fill value
259       local_pf = fill_value
260!
261!--    Set masking flag for topography for not resorted arrays
262       flag_nr = 0
[1551]263
[2007]264       SELECT CASE ( trimvar )
[1]265
266          CASE ( 'e' )
267             IF ( av == 0 )  THEN
268                to_be_resorted => e
269             ELSE
[3004]270                IF ( .NOT. ALLOCATED( e_av ) ) THEN
271                   ALLOCATE( e_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
272                   e_av = REAL( fill_value, KIND = wp )
273                ENDIF
[1]274                to_be_resorted => e_av
275             ENDIF
276
[3421]277          CASE ( 'thetal' )
[771]278             IF ( av == 0 )  THEN
279                to_be_resorted => pt
280             ELSE
[3004]281                IF ( .NOT. ALLOCATED( lpt_av ) ) THEN
282                   ALLOCATE( lpt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
283                   lpt_av = REAL( fill_value, KIND = wp )
284                ENDIF
[771]285                to_be_resorted => lpt_av
286             ENDIF
287
[1]288          CASE ( 'p' )
289             IF ( av == 0 )  THEN
[727]290                IF ( psolver /= 'sor' )  CALL exchange_horiz( p, nbgp )
[1]291                to_be_resorted => p
292             ELSE
[3004]293                IF ( .NOT. ALLOCATED( p_av ) ) THEN
294                   ALLOCATE( p_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
295                   p_av = REAL( fill_value, KIND = wp )
296                ENDIF
[727]297                IF ( psolver /= 'sor' )  CALL exchange_horiz( p_av, nbgp )
[1]298                to_be_resorted => p_av
299             ENDIF
300
301          CASE ( 'pc' )  ! particle concentration (requires ghostpoint exchange)
302             IF ( av == 0 )  THEN
[3646]303                IF ( time_since_reference_point >= particle_advection_start )  THEN
[1359]304                   tend = prt_count
305                ELSE
306                   tend = 0.0_wp
307                ENDIF
[2512]308                DO  i = nxl, nxr
309                   DO  j = nys, nyn
[1551]310                      DO  k = nzb_do, nzt_do
[1]311                         local_pf(i,j,k) = tend(k,j,i)
312                      ENDDO
313                   ENDDO
314                ENDDO
315                resorted = .TRUE.
316             ELSE
[3004]317                IF ( .NOT. ALLOCATED( pc_av ) ) THEN
318                   ALLOCATE( pc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
319                   pc_av = REAL( fill_value, KIND = wp )
320                ENDIF
[1]321                to_be_resorted => pc_av
322             ENDIF
323
[1359]324          CASE ( 'pr' )  ! mean particle radius (effective radius)
[1]325             IF ( av == 0 )  THEN
[3646]326                IF ( time_since_reference_point >= particle_advection_start )  THEN
[1359]327                   DO  i = nxl, nxr
328                      DO  j = nys, nyn
[1551]329                         DO  k = nzb_do, nzt_do
[1359]330                            number_of_particles = prt_count(k,j,i)
331                            IF (number_of_particles <= 0)  CYCLE
332                            particles => grid_particles(k,j,i)%particles(1:number_of_particles)
333                            s_r2 = 0.0_wp
334                            s_r3 = 0.0_wp
335                            DO  n = 1, number_of_particles
336                               IF ( particles(n)%particle_mask )  THEN
337                                  s_r2 = s_r2 + particles(n)%radius**2 * &
338                                         particles(n)%weight_factor
339                                  s_r3 = s_r3 + particles(n)%radius**3 * &
340                                         particles(n)%weight_factor
341                               ENDIF
342                            ENDDO
343                            IF ( s_r2 > 0.0_wp )  THEN
344                               mean_r = s_r3 / s_r2
345                            ELSE
346                               mean_r = 0.0_wp
347                            ENDIF
348                            tend(k,j,i) = mean_r
[1]349                         ENDDO
350                      ENDDO
351                   ENDDO
[1359]352                ELSE
353                   tend = 0.0_wp
354                ENDIF
[2512]355                DO  i = nxl, nxr
356                   DO  j = nys, nyn
[1551]357                      DO  k = nzb_do, nzt_do
[1]358                         local_pf(i,j,k) = tend(k,j,i)
359                      ENDDO
360                   ENDDO
361                ENDDO
362                resorted = .TRUE.
363             ELSE
[3004]364                IF ( .NOT. ALLOCATED( pr_av ) ) THEN
365                   ALLOCATE( pr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
366                   pr_av = REAL( fill_value, KIND = wp )
367                ENDIF
[1]368                to_be_resorted => pr_av
369             ENDIF
370
[3421]371          CASE ( 'theta' )
[1]372             IF ( av == 0 )  THEN
[3274]373                IF ( .NOT. bulk_cloud_model ) THEN
[1]374                   to_be_resorted => pt
375                ELSE
[2512]376                   DO  i = nxl, nxr
377                      DO  j = nys, nyn
[1551]378                         DO  k = nzb_do, nzt_do
[3274]379                            local_pf(i,j,k) = pt(k,j,i) + lv_d_cp *            &
380                                                          d_exner(k) *         &
[1]381                                                          ql(k,j,i)
382                         ENDDO
383                      ENDDO
384                   ENDDO
385                   resorted = .TRUE.
386                ENDIF
387             ELSE
[3004]388                IF ( .NOT. ALLOCATED( pt_av ) ) THEN
389                   ALLOCATE( pt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
390                   pt_av = REAL( fill_value, KIND = wp )
391                ENDIF
[1]392                to_be_resorted => pt_av
393             ENDIF
394
395          CASE ( 'q' )
396             IF ( av == 0 )  THEN
397                to_be_resorted => q
398             ELSE
[3004]399                IF ( .NOT. ALLOCATED( q_av ) ) THEN
400                   ALLOCATE( q_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
401                   q_av = REAL( fill_value, KIND = wp )
402                ENDIF
[1]403                to_be_resorted => q_av
404             ENDIF
[691]405
[1053]406          CASE ( 'ql' )
407             IF ( av == 0 )  THEN
[1115]408                to_be_resorted => ql
[1053]409             ELSE
[3004]410                IF ( .NOT. ALLOCATED( ql_av ) ) THEN
411                   ALLOCATE( ql_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
412                   ql_av = REAL( fill_value, KIND = wp )
413                ENDIF
[1115]414                to_be_resorted => ql_av
[1053]415             ENDIF
416
[1]417          CASE ( 'ql_c' )
418             IF ( av == 0 )  THEN
419                to_be_resorted => ql_c
420             ELSE
[3004]421                IF ( .NOT. ALLOCATED( ql_c_av ) ) THEN
422                   ALLOCATE( ql_c_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
423                   ql_c_av = REAL( fill_value, KIND = wp )
424                ENDIF
[1]425                to_be_resorted => ql_c_av
426             ENDIF
427
428          CASE ( 'ql_v' )
429             IF ( av == 0 )  THEN
430                to_be_resorted => ql_v
431             ELSE
[3004]432                IF ( .NOT. ALLOCATED( ql_v_av ) ) THEN
433                   ALLOCATE( ql_v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
434                   ql_v_av = REAL( fill_value, KIND = wp )
435                ENDIF
[1]436                to_be_resorted => ql_v_av
437             ENDIF
438
439          CASE ( 'ql_vp' )
440             IF ( av == 0 )  THEN
[3646]441                IF ( time_since_reference_point >= particle_advection_start )  THEN
[1359]442                   DO  i = nxl, nxr
443                      DO  j = nys, nyn
[1551]444                         DO  k = nzb_do, nzt_do
[1359]445                            number_of_particles = prt_count(k,j,i)
446                            IF (number_of_particles <= 0)  CYCLE
447                            particles => grid_particles(k,j,i)%particles(1:number_of_particles)
448                            DO  n = 1, number_of_particles
449                               IF ( particles(n)%particle_mask )  THEN
450                                  tend(k,j,i) =  tend(k,j,i) +                 &
451                                                 particles(n)%weight_factor /  &
452                                                 prt_count(k,j,i)
453                               ENDIF
454                            ENDDO
[1007]455                         ENDDO
456                      ENDDO
457                   ENDDO
[1359]458                ELSE
459                   tend = 0.0_wp
460                ENDIF
[2512]461                DO  i = nxl, nxr
462                   DO  j = nys, nyn
[1551]463                      DO  k = nzb_do, nzt_do
[1007]464                         local_pf(i,j,k) = tend(k,j,i)
465                      ENDDO
466                   ENDDO
467                ENDDO
468                resorted = .TRUE.
[1]469             ELSE
[3004]470                IF ( .NOT. ALLOCATED( ql_vp_av ) ) THEN
471                   ALLOCATE( ql_vp_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
472                   ql_vp_av = REAL( fill_value, KIND = wp )
473                ENDIF
[1]474                to_be_resorted => ql_vp_av
475             ENDIF
476
477          CASE ( 'qv' )
478             IF ( av == 0 )  THEN
[2512]479                DO  i = nxl, nxr
480                   DO  j = nys, nyn
[1551]481                      DO  k = nzb_do, nzt_do
[1]482                         local_pf(i,j,k) = q(k,j,i) - ql(k,j,i)
483                      ENDDO
484                   ENDDO
485                ENDDO
486                resorted = .TRUE.
487             ELSE
[3004]488                IF ( .NOT. ALLOCATED( qv_av ) ) THEN
489                   ALLOCATE( qv_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
490                   qv_av = REAL( fill_value, KIND = wp )
491                ENDIF
[1]492                to_be_resorted => qv_av
493             ENDIF
494
495          CASE ( 's' )
496             IF ( av == 0 )  THEN
[1960]497                to_be_resorted => s
[1]498             ELSE
[3004]499                IF ( .NOT. ALLOCATED( s_av ) ) THEN
500                   ALLOCATE( s_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
501                   s_av = REAL( fill_value, KIND = wp )
502                ENDIF
[355]503                to_be_resorted => s_av
[1]504             ENDIF
[691]505
[1]506          CASE ( 'u' )
[2696]507             flag_nr = 1
[1]508             IF ( av == 0 )  THEN
509                to_be_resorted => u
510             ELSE
[3004]511                IF ( .NOT. ALLOCATED( u_av ) ) THEN
512                   ALLOCATE( u_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
513                   u_av = REAL( fill_value, KIND = wp )
514                ENDIF
[1]515                to_be_resorted => u_av
516             ENDIF
517
518          CASE ( 'v' )
[2696]519             flag_nr = 2
[1]520             IF ( av == 0 )  THEN
521                to_be_resorted => v
522             ELSE
[3004]523                IF ( .NOT. ALLOCATED( v_av ) ) THEN
524                   ALLOCATE( v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
525                   v_av = REAL( fill_value, KIND = wp )
526                ENDIF
[1]527                to_be_resorted => v_av
528             ENDIF
529
[3421]530          CASE ( 'thetav' )
[1]531             IF ( av == 0 )  THEN
532                to_be_resorted => vpt
533             ELSE
[3004]534                IF ( .NOT. ALLOCATED( vpt_av ) ) THEN
535                   ALLOCATE( vpt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
536                   vpt_av = REAL( fill_value, KIND = wp )
537                ENDIF
[1]538                to_be_resorted => vpt_av
539             ENDIF
540
541          CASE ( 'w' )
[2696]542             flag_nr = 3
[1]543             IF ( av == 0 )  THEN
544                to_be_resorted => w
545             ELSE
[3004]546                IF ( .NOT. ALLOCATED( w_av ) ) THEN
547                   ALLOCATE( w_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
548                   w_av = REAL( fill_value, KIND = wp )
549                ENDIF
[1]550                to_be_resorted => w_av
551             ENDIF
552
553          CASE DEFAULT
[3637]554!
555!--          Quantities of other modules
556             IF ( .NOT. found )  THEN
557                CALL module_interface_data_output_3d(                          &
558                        av, trimvar, found, local_pf,                          &
559                        fill_value, resorted, nzb_do, nzt_do                   &
560                     )
[3294]561             ENDIF
562
[1972]563!
[3637]564!--          Temporary workaround: ToDo: refactor local_pf allocation
565             IF ( .NOT. found  .AND.  urban_surface  .AND.  trimvar(1:4) == 'usm_' )  THEN
566!
567!--             For urban model quantities, it is required to re-allocate local_pf
[3814]568                nzb_do = nz_urban_b
569                nzt_do = nz_urban_t
[1972]570
571                DEALLOCATE ( local_pf )
[2512]572                ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
[2696]573                local_pf = fill_value
[1972]574
[3637]575                CALL usm_data_output_3d( av, trimvar, found, local_pf,         &
576                                         nzb_do, nzt_do )
[1972]577                resorted = .TRUE.
[1976]578
579!
580!--             If no soil model variable was found, re-allocate local_pf
581                IF ( .NOT. found )  THEN
582                   nzb_do = nzb
583                   nzt_do = nz_do3d
584
585                   DEALLOCATE ( local_pf )
[3637]586                   ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
[1976]587                ENDIF
588
[1972]589             ENDIF
590
[3637]591!
592!--          Temporary workaround: ToDo: refactor local_pf allocation
593             IF ( .NOT. found  .AND.  land_surface )  THEN
594!
595!--             For soil model quantities, it is required to re-allocate local_pf
596                nzb_do = nzb_soil
597                nzt_do = nzt_soil
[1976]598
[3637]599                DEALLOCATE ( local_pf )
600                ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
601                local_pf = fill_value
[2817]602
[3637]603                CALL lsm_data_output_3d( av, trimvar, found, local_pf )
[2696]604                resorted = .TRUE.
605
[3467]606!
[3637]607!--             If no soil model variable was found, re-allocate local_pf
608                IF ( .NOT. found )  THEN
609                   nzb_do = nzb
610                   nzt_do = nz_do3d
[2209]611
[3637]612                   DEALLOCATE ( local_pf )
613                   ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
614                ENDIF
[3448]615
[1972]616             ENDIF
[1]617
[254]618             IF ( .NOT. found )  THEN
[1320]619                message_string =  'no output available for: ' //               &
[3554]620                                  TRIM( do3d(av,ivar) )
[254]621                CALL message( 'data_output_3d', 'PA0182', 0, 0, 0, 6, 0 )
[1]622             ENDIF
623
624       END SELECT
625
626!
627!--    Resort the array to be output, if not done above
628       IF ( .NOT. resorted )  THEN
[2512]629          DO  i = nxl, nxr
630             DO  j = nys, nyn
[1551]631                DO  k = nzb_do, nzt_do
[2696]632                   local_pf(i,j,k) = MERGE(                                    &
633                                      to_be_resorted(k,j,i),                   &
634                                      REAL( fill_value, KIND = wp ),           &
[4346]635                                      BTEST( wall_flags_total_0(k,j,i), flag_nr ) )
[1]636                ENDDO
637             ENDDO
638          ENDDO
639       ENDIF
640
641!
[1327]642!--    Output of the 3D-array
643#if defined( __parallel )
644       IF ( netcdf_data_format < 5 )  THEN
[1]645!
[1327]646!--       Non-parallel netCDF output. Data is output in parallel in
647!--       FORTRAN binary format here, and later collected into one file by
648!--       combine_plot_fields
649          IF ( myid == 0 )  THEN
650             WRITE ( 30 )  time_since_reference_point,                   &
651                           do3d_time_count(av), av
[1]652          ENDIF
[1327]653          DO  i = 0, io_blocks-1
654             IF ( i == io_group )  THEN
[2512]655                WRITE ( 30 )  nxl, nxr, nys, nyn, nzb_do, nzt_do
[1551]656                WRITE ( 30 )  local_pf(:,:,nzb_do:nzt_do)
[1327]657             ENDIF
[1972]658
[1327]659             CALL MPI_BARRIER( comm2d, ierr )
[1972]660
[1327]661          ENDDO
[559]662
[1327]663       ELSE
[646]664#if defined( __netcdf )
[493]665!
[1327]666!--       Parallel output in netCDF4/HDF5 format.
[2512]667!          IF ( nxr == nx  .AND.  nyn /= ny )  THEN
[3554]668!             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar),  &
[2512]669!                               local_pf(nxl:nxr+1,nys:nyn,nzb_do:nzt_do),    &
670!                start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /),  &
671!                count = (/ nxr-nxl+2, nyn-nys+1, nzt_do-nzb_do+1, 1 /) )
672!          ELSEIF ( nxr /= nx  .AND.  nyn == ny )  THEN
[3554]673!             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar),  &
[2512]674!                               local_pf(nxl:nxr,nys:nyn+1,nzb_do:nzt_do),    &
675!                start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /),  &
676!                count = (/ nxr-nxl+1, nyn-nys+2, nzt_do-nzb_do+1, 1 /) )
677!          ELSEIF ( nxr == nx  .AND.  nyn == ny )  THEN
[3554]678!             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar),  &
[2512]679!                             local_pf(nxl:nxr+1,nys:nyn+1,nzb_do:nzt_do  ),  &
680!                start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /),  &
681!                count = (/ nxr-nxl+2, nyn-nys+2, nzt_do-nzb_do+1, 1 /) )
682!          ELSE
[3554]683             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar),  &
[1551]684                                 local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do),    &
685                start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /),  &
686                count = (/ nxr-nxl+1, nyn-nys+1, nzt_do-nzb_do+1, 1 /) )
[2512]687!          ENDIF
[1783]688          CALL netcdf_handle_error( 'data_output_3d', 386 )
[646]689#endif
[1327]690       ENDIF
[1]691#else
692#if defined( __netcdf )
[3554]693       nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar),        &
[4155]694                         local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do),          &
695                         start = (/ 1, 1, 1, do3d_time_count(av) /),       &
[4162]696                         count = (/ nx+1, ny+1, nzt_do-nzb_do+1, 1 /) )
[1783]697       CALL netcdf_handle_error( 'data_output_3d', 446 )
[1]698#endif
699#endif
700
[3554]701       ivar = ivar + 1
[1]702
703!
[1551]704!--    Deallocate temporary array
705       DEALLOCATE ( local_pf )
[1]706
[1551]707    ENDDO
[1]708
[1318]709    CALL cpu_log( log_point(14), 'data_output_3d', 'stop' )
[1]710
[3987]711    IF ( debug_output_timestep )  CALL debug_message( 'data_output_3d', 'end' )
[3885]712
[3987]713
[1]714 END SUBROUTINE data_output_3d
Note: See TracBrowser for help on using the repository browser.