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

Last change on this file since 4180 was 4180, checked in by scharf, 5 years ago

removed comments in 'Former revisions' section that are older than 01.01.2019

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