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

Last change on this file since 3241 was 3241, checked in by raasch, 6 years ago

various changes to avoid compiler warnings (mainly removal of unused variables)

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