source: palm/trunk/SOURCE/data_output_mask.f90 @ 3288

Last change on this file since 3288 was 3274, checked in by knoop, 6 years ago

Modularization of all bulk cloud physics code components

  • Property svn:keywords set to Id
File size: 24.9 KB
Line 
1!> @file data_output_mask.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
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.
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!
17! Copyright 1997-2018 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: data_output_mask.f90 3274 2018-09-24 15:42:55Z suehring $
27! Modularization of all bulk cloud physics code components
28!
29! 3241 2018-09-12 15:02:00Z raasch
30! unused variable removed
31!
32! 3083 2018-06-19 14:03:12Z gronemeier
33!
34!
35! 3045 2018-05-28 07:55:41Z Giersch
36! Error messages revised
37!
38! 3030 2018-05-23 14:37:00Z raasch
39! variable if renamed ivar
40!
41! 2718 2018-01-02 08:49:38Z maronga
42! Corrected "Former revisions" section
43!
44! 2696 2017-12-14 17:12:51Z kanani
45! Change in file header (GPL part)
46!
47! 2292 2017-06-20 09:51:42Z schwenkel
48! Implementation of new microphysic scheme: cloud_scheme = 'morrison'
49! includes two more prognostic equations for cloud drop concentration (nc) 
50! and cloud water content (qc).
51!
52! 2101 2017-01-05 16:42:31Z suehring
53!
54! 2031 2016-10-21 15:11:58Z knoop
55! renamed variable rho to rho_ocean and rho_av to rho_ocean_av
56!
57! 2000 2016-08-20 18:09:15Z knoop
58! Forced header and separation lines into 80 columns
59!
60! 1980 2016-07-29 15:51:57Z suehring
61! Bugfix, in order to steer user-defined output, setting flag found explicitly
62! to .F.
63!
64! 1976 2016-07-27 13:28:04Z maronga
65! Output of radiation quantities is now done directly in the respective module
66!
67! 1960 2016-07-12 16:34:24Z suehring
68! Separate humidity and passive scalar
69!
70! 2016-03-06 18:36:17Z raasch
71! name change of netcdf routines and module + related changes,
72! switch back of netcdf data format moved from time integration routine to here
73!
74! 1691 2015-10-26 16:17:44Z maronga
75! Added output of radiative heating rates for RRTMG
76!
77! 1682 2015-10-07 23:56:08Z knoop
78! Code annotations made doxygen readable
79!
80! 1585 2015-04-30 07:05:52Z maronga
81! Added support for RRTMG
82!
83! 1438 2014-07-22 14:14:06Z heinze
84! +nr, qc, qr
85!
86! 1359 2014-04-11 17:15:14Z hoffmann
87! New particle structure integrated.
88!
89! 1353 2014-04-08 15:21:23Z heinze
90! REAL constants provided with KIND-attribute
91!
92! 1327 2014-03-21 11:00:16Z raasch
93!
94!
95! 1320 2014-03-20 08:40:49Z raasch
96! ONLY-attribute added to USE-statements,
97! kind-parameters added to all INTEGER and REAL declaration statements,
98! kinds are defined in new module kinds,
99! revision history before 2012 removed,
100! comment fields (!:) to be used for variable explanations added to
101! all variable declaration statements
102!
103! 1318 2014-03-17 13:35:16Z raasch
104! barrier argument removed from cpu_log,
105! module interfaces removed
106!
107! 1092 2013-02-02 11:24:22Z raasch
108! unused variables removed
109!
110! 1036 2012-10-22 13:43:42Z raasch
111! code put under GPL (PALM 3.9)
112!
113! 1031 2012-10-19 14:35:30Z raasch
114! netCDF4 without parallel file support implemented
115!
116! 1007 2012-09-19 14:30:36Z franke
117! Bugfix: calculation of pr must depend on the particle weighting factor,
118! missing calculation of ql_vp added
119!
120! 410 2009-12-04 17:05:40Z letzel
121! Initial version
122!
123! Description:
124! ------------
125!> Masked data output in netCDF format for current mask (current value of mid).
126!------------------------------------------------------------------------------!
127 SUBROUTINE data_output_mask( av )
128
129 
130
131#if defined( __netcdf )
132    USE arrays_3d,                                                             &
133        ONLY:  e, nc, nr, p, pt, q, qc, ql, ql_c, ql_v, qr, rho_ocean, s, sa,  &
134               tend, u, v, vpt, w, d_exner
135   
136    USE averaging,                                                             &
137        ONLY:  e_av, lpt_av, nc_av, nr_av, p_av, pc_av, pr_av, pt_av, q_av,    &
138               qc_av, ql_av, ql_c_av, ql_v_av, ql_vp_av, qv_av, qr_av,         &
139               rho_ocean_av, s_av, sa_av, u_av, v_av, vpt_av, w_av 
140
141    USE basic_constants_and_equations_mod,                                     &
142        ONLY:  lv_d_cp
143   
144    USE control_parameters,                                                    &
145        ONLY:  domask, domask_no, domask_time_count, mask_i,                   &
146               mask_j, mask_k, mask_size, mask_size_l, mask_start_l,           &
147               max_masks, message_string, mid, nz_do3d, simulated_time
148    USE cpulog,                                                                &
149        ONLY:  cpu_log, log_point
150
151    USE indices,                                                               &
152        ONLY:  nbgp, nxl, nxr, nyn, nys, nzb
153       
154    USE kinds
155
156    USE bulk_cloud_model_mod,                                                  &
157        ONLY:  bulk_cloud_model
158   
159    USE NETCDF
160   
161    USE netcdf_interface,                                                      &
162        ONLY:  id_set_mask, id_var_domask, id_var_time_mask, nc_stat,          &
163               netcdf_data_format, netcdf_handle_error
164   
165    USE particle_attributes,                                                   &
166        ONLY:  grid_particles, number_of_particles, particles,                 &
167               particle_advection_start, prt_count
168   
169    USE pegrid
170
171    USE radiation_model_mod,                                                   &
172        ONLY:  radiation, radiation_data_output_mask
173
174    IMPLICIT NONE
175
176    INTEGER(iwp) ::  av       !<
177    INTEGER(iwp) ::  ngp      !<
178    INTEGER(iwp) ::  i        !<
179    INTEGER(iwp) ::  ivar     !<
180    INTEGER(iwp) ::  j        !<
181    INTEGER(iwp) ::  k        !<
182    INTEGER(iwp) ::  n        !<
183    INTEGER(iwp) ::  netcdf_data_format_save !<
184    INTEGER(iwp) ::  sender   !<
185    INTEGER(iwp) ::  ind(6)   !<
186   
187    LOGICAL ::  found         !<
188    LOGICAL ::  resorted      !<
189   
190    REAL(wp) ::  mean_r       !<
191    REAL(wp) ::  s_r2         !<
192    REAL(wp) ::  s_r3         !<
193   
194    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  local_pf    !<
195#if defined( __parallel )
196    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  total_pf    !<
197#endif
198    REAL(wp), DIMENSION(:,:,:), POINTER ::  to_be_resorted  !<
199
200!
201!-- Return, if nothing to output
202    IF ( domask_no(mid,av) == 0 )  RETURN
203
204    CALL cpu_log (log_point(49),'data_output_mask','start')
205
206!
207!-- Parallel netcdf output is not tested so far for masked data, hence
208!-- netcdf_data_format is switched back to non-paralell output.
209    netcdf_data_format_save = netcdf_data_format
210    IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
211    IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
212
213!
214!-- Open output file.
215    IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
216       CALL check_open( 200+mid+av*max_masks )
217    ENDIF 
218
219!
220!-- Allocate total and local output arrays.
221#if defined( __parallel )
222    IF ( myid == 0 )  THEN
223       ALLOCATE( total_pf(mask_size(mid,1),mask_size(mid,2),mask_size(mid,3)) )
224    ENDIF
225#endif
226    ALLOCATE( local_pf(mask_size_l(mid,1),mask_size_l(mid,2), &
227                       mask_size_l(mid,3)) )
228
229!
230!-- Update the netCDF time axis.
231    domask_time_count(mid,av) = domask_time_count(mid,av) + 1
232    IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
233       nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), id_var_time_mask(mid,av), &
234                               (/ simulated_time /),                          &
235                               start = (/ domask_time_count(mid,av) /),       &
236                               count = (/ 1 /) )
237       CALL netcdf_handle_error( 'data_output_mask', 460 )
238    ENDIF
239
240!
241!-- Loop over all variables to be written.
242    ivar = 1
243
244    DO  WHILE ( domask(mid,av,ivar)(1:1) /= ' ' )
245!
246!--    Reallocate local_pf on PE 0 since its shape changes during MPI exchange
247       IF ( netcdf_data_format < 5   .AND.  myid == 0  .AND.  ivar > 1 )  THEN
248          DEALLOCATE( local_pf )
249          ALLOCATE( local_pf(mask_size_l(mid,1),mask_size_l(mid,2), &
250                             mask_size_l(mid,3)) )
251       ENDIF
252!
253!--    Set flag to steer output of radiation, land-surface, or user-defined
254!--    quantities
255       found = .FALSE.
256!
257!--    Store the variable chosen.
258       resorted = .FALSE.
259       SELECT CASE ( TRIM( domask(mid,av,ivar) ) )
260
261          CASE ( 'e' )
262             IF ( av == 0 )  THEN
263                to_be_resorted => e
264             ELSE
265                to_be_resorted => e_av
266             ENDIF
267
268          CASE ( 'lpt' )
269             IF ( av == 0 )  THEN
270                to_be_resorted => pt
271             ELSE
272                to_be_resorted => lpt_av
273             ENDIF
274
275          CASE ( 'nc' )
276             IF ( av == 0 )  THEN
277                to_be_resorted => nc
278             ELSE
279                to_be_resorted => nc_av
280             ENDIF
281
282          CASE ( 'nr' )
283             IF ( av == 0 )  THEN
284                to_be_resorted => nr
285             ELSE
286                to_be_resorted => nr_av
287             ENDIF
288
289          CASE ( 'p' )
290             IF ( av == 0 )  THEN
291                to_be_resorted => p
292             ELSE
293                to_be_resorted => p_av
294             ENDIF
295
296          CASE ( 'pc' )  ! particle concentration (requires ghostpoint exchange)
297             IF ( av == 0 )  THEN
298                tend = prt_count
299                CALL exchange_horiz( tend, nbgp )
300                DO  i = 1, mask_size_l(mid,1)
301                   DO  j = 1, mask_size_l(mid,2)
302                      DO  k = 1, mask_size_l(mid,3)
303                         local_pf(i,j,k) =  tend(mask_k(mid,k), &
304                                   mask_j(mid,j),mask_i(mid,i))
305                      ENDDO
306                   ENDDO
307                ENDDO
308                resorted = .TRUE.
309             ELSE
310                CALL exchange_horiz( pc_av, nbgp )
311                to_be_resorted => pc_av
312             ENDIF
313
314          CASE ( 'pr' )  ! mean particle radius (effective radius)
315             IF ( av == 0 )  THEN
316                IF ( simulated_time >= particle_advection_start )  THEN
317                   DO  i = nxl, nxr
318                      DO  j = nys, nyn
319                         DO  k = nzb, nz_do3d
320                            number_of_particles = prt_count(k,j,i)
321                            IF (number_of_particles <= 0)  CYCLE
322                            particles => grid_particles(k,j,i)%particles(1:number_of_particles)
323                            s_r2 = 0.0_wp
324                            s_r3 = 0.0_wp
325                            DO  n = 1, number_of_particles
326                               IF ( particles(n)%particle_mask )  THEN
327                                  s_r2 = s_r2 + grid_particles(k,j,i)%particles(n)%radius**2 * &
328                                         grid_particles(k,j,i)%particles(n)%weight_factor
329                                  s_r3 = s_r3 + grid_particles(k,j,i)%particles(n)%radius**3 * &
330                                         grid_particles(k,j,i)%particles(n)%weight_factor
331                               ENDIF
332                            ENDDO
333                            IF ( s_r2 > 0.0_wp )  THEN
334                               mean_r = s_r3 / s_r2
335                            ELSE
336                               mean_r = 0.0_wp
337                            ENDIF
338                            tend(k,j,i) = mean_r
339                         ENDDO
340                      ENDDO
341                   ENDDO
342                   CALL exchange_horiz( tend, nbgp )
343                ELSE
344                   tend = 0.0_wp
345                ENDIF
346                DO  i = 1, mask_size_l(mid,1)
347                   DO  j = 1, mask_size_l(mid,2)
348                      DO  k = 1, mask_size_l(mid,3)
349                         local_pf(i,j,k) =  tend(mask_k(mid,k), &
350                                   mask_j(mid,j),mask_i(mid,i))
351                      ENDDO
352                   ENDDO
353                ENDDO
354                resorted = .TRUE.
355             ELSE
356                CALL exchange_horiz( pr_av, nbgp )
357                to_be_resorted => pr_av
358             ENDIF
359
360          CASE ( 'pt' )
361             IF ( av == 0 )  THEN
362                IF ( .NOT. bulk_cloud_model ) THEN
363                   to_be_resorted => pt
364                ELSE
365                   DO  i = 1, mask_size_l(mid,1)
366                      DO  j = 1, mask_size_l(mid,2)
367                         DO  k = 1, mask_size_l(mid,3)
368                            local_pf(i,j,k) =  &
369                                 pt(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) &
370                                 + lv_d_cp * d_exner(mask_k(mid,k)) *          &
371                                   ql(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i))
372                         ENDDO
373                      ENDDO
374                   ENDDO
375                   resorted = .TRUE.
376                ENDIF
377             ELSE
378                to_be_resorted => pt_av
379             ENDIF
380
381          CASE ( 'q' )
382             IF ( av == 0 )  THEN
383                to_be_resorted => q
384             ELSE
385                to_be_resorted => q_av
386             ENDIF
387
388          CASE ( 'qc' )
389             IF ( av == 0 )  THEN
390                to_be_resorted => qc
391             ELSE
392                to_be_resorted => qc_av
393             ENDIF
394
395          CASE ( 'ql' )
396             IF ( av == 0 )  THEN
397                to_be_resorted => ql
398             ELSE
399                to_be_resorted => ql_av
400             ENDIF
401
402          CASE ( 'ql_c' )
403             IF ( av == 0 )  THEN
404                to_be_resorted => ql_c
405             ELSE
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
413                to_be_resorted => ql_v_av
414             ENDIF
415
416          CASE ( 'ql_vp' )
417             IF ( av == 0 )  THEN
418                IF ( simulated_time >= particle_advection_start )  THEN
419                   DO  i = nxl, nxr
420                      DO  j = nys, nyn
421                         DO  k = nzb, nz_do3d
422                            number_of_particles = prt_count(k,j,i)
423                            IF (number_of_particles <= 0)  CYCLE
424                            particles => grid_particles(k,j,i)%particles(1:number_of_particles)
425                            DO  n = 1, number_of_particles
426                               IF ( particles(n)%particle_mask )  THEN
427                                  tend(k,j,i) = tend(k,j,i) + &
428                                          particles(n)%weight_factor / &
429                                          prt_count(k,j,i)
430                               ENDIF
431                            ENDDO
432                         ENDDO
433                      ENDDO
434                   ENDDO
435                   CALL exchange_horiz( tend, nbgp )
436                ELSE
437                   tend = 0.0_wp
438                ENDIF
439                DO  i = 1, mask_size_l(mid,1)
440                   DO  j = 1, mask_size_l(mid,2)
441                      DO  k = 1, mask_size_l(mid,3)
442                         local_pf(i,j,k) =  tend(mask_k(mid,k), &
443                                   mask_j(mid,j),mask_i(mid,i))
444                      ENDDO
445                   ENDDO
446                ENDDO
447                resorted = .TRUE.
448             ELSE
449                CALL exchange_horiz( ql_vp_av, nbgp )
450                to_be_resorted => ql_vp_av
451             ENDIF
452
453          CASE ( 'qv' )
454             IF ( av == 0 )  THEN
455                DO  i = 1, mask_size_l(mid,1)
456                   DO  j = 1, mask_size_l(mid,2)
457                      DO  k = 1, mask_size_l(mid,3)
458                         local_pf(i,j,k) =  &
459                              q(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) -  &
460                              ql(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i))
461                      ENDDO
462                   ENDDO
463                ENDDO
464                resorted = .TRUE.
465             ELSE
466                to_be_resorted => qv_av
467             ENDIF
468
469          CASE ( 'qr' )
470             IF ( av == 0 )  THEN
471                to_be_resorted => qr
472             ELSE
473                to_be_resorted => qr_av
474             ENDIF
475
476          CASE ( 'rho_ocean' )
477             IF ( av == 0 )  THEN
478                to_be_resorted => rho_ocean
479             ELSE
480                to_be_resorted => rho_ocean_av
481             ENDIF
482
483          CASE ( 's' )
484             IF ( av == 0 )  THEN
485                to_be_resorted => s
486             ELSE
487                to_be_resorted => s_av
488             ENDIF
489
490          CASE ( 'sa' )
491             IF ( av == 0 )  THEN
492                to_be_resorted => sa
493             ELSE
494                to_be_resorted => sa_av
495             ENDIF
496
497          CASE ( 'u' )
498             IF ( av == 0 )  THEN
499                to_be_resorted => u
500             ELSE
501                to_be_resorted => u_av
502             ENDIF
503
504          CASE ( 'v' )
505             IF ( av == 0 )  THEN
506                to_be_resorted => v
507             ELSE
508                to_be_resorted => v_av
509             ENDIF
510
511          CASE ( 'vpt' )
512             IF ( av == 0 )  THEN
513                to_be_resorted => vpt
514             ELSE
515                to_be_resorted => vpt_av
516             ENDIF
517
518          CASE ( 'w' )
519             IF ( av == 0 )  THEN
520                to_be_resorted => w
521             ELSE
522                to_be_resorted => w_av
523             ENDIF
524
525          CASE DEFAULT
526
527!
528!--          Radiation quantity
529             IF ( radiation )  THEN
530                CALL radiation_data_output_mask(av, domask(mid,av,ivar), found,&
531                                                local_pf )
532             ENDIF
533
534!
535!--          User defined quantity
536             IF ( .NOT. found )  THEN
537                CALL user_data_output_mask(av, domask(mid,av,ivar), found,     &
538                                           local_pf )
539             ENDIF
540
541             resorted = .TRUE.
542
543             IF ( .NOT. found )  THEN
544                WRITE ( message_string, * ) 'no masked output available for: ',&
545                                            TRIM( domask(mid,av,ivar) )
546                CALL message( 'data_output_mask', 'PA0327', 0, 0, 0, 6, 0 )
547             ENDIF
548
549       END SELECT
550
551!
552!--    Resort the array to be output, if not done above
553       IF ( .NOT. resorted )  THEN
554          DO  i = 1, mask_size_l(mid,1)
555             DO  j = 1, mask_size_l(mid,2)
556                DO  k = 1, mask_size_l(mid,3)
557                   local_pf(i,j,k) =  to_be_resorted(mask_k(mid,k), &
558                                      mask_j(mid,j),mask_i(mid,i))
559                ENDDO
560             ENDDO
561          ENDDO
562       ENDIF
563
564!
565!--    I/O block. I/O methods are implemented
566!--    (1) for parallel execution
567!--     a. with netCDF 4 parallel I/O-enabled library
568!--     b. with netCDF 3 library
569!--    (2) for serial execution.
570!--    The choice of method depends on the correct setting of preprocessor
571!--    directives __parallel and __netcdf4_parallel as well as on the parameter
572!--    netcdf_data_format.
573#if defined( __parallel )
574#if defined( __netcdf4_parallel )
575       IF ( netcdf_data_format > 4 )  THEN
576!
577!--       (1) a. Parallel I/O using netCDF 4 (not yet tested)
578          nc_stat = NF90_PUT_VAR( id_set_mask(mid,av),                         &
579               id_var_domask(mid,av,ivar), local_pf,                           &
580               start = (/ mask_start_l(mid,1), mask_start_l(mid,2),            &
581                          mask_start_l(mid,3), domask_time_count(mid,av) /),   &
582               count = (/ mask_size_l(mid,1), mask_size_l(mid,2),              &
583                          mask_size_l(mid,3), 1 /) )
584          CALL netcdf_handle_error( 'data_output_mask', 461 )
585       ELSE
586#endif
587!
588!--       (1) b. Conventional I/O only through PE0
589!--       PE0 receives partial arrays from all processors of the respective mask
590!--       and outputs them. Here a barrier has to be set, because otherwise
591!--       "-MPI- FATAL: Remote protocol queue full" may occur.
592          CALL MPI_BARRIER( comm2d, ierr )
593
594          ngp = mask_size_l(mid,1) * mask_size_l(mid,2) * mask_size_l(mid,3)
595          IF ( myid == 0 )  THEN
596!
597!--          Local array can be relocated directly.
598             total_pf( &
599               mask_start_l(mid,1):mask_start_l(mid,1)+mask_size_l(mid,1)-1, &
600               mask_start_l(mid,2):mask_start_l(mid,2)+mask_size_l(mid,2)-1, &
601               mask_start_l(mid,3):mask_start_l(mid,3)+mask_size_l(mid,3)-1 ) &
602               = local_pf
603!
604!--          Receive data from all other PEs.
605             DO  n = 1, numprocs-1
606!
607!--             Receive index limits first, then array.
608!--             Index limits are received in arbitrary order from the PEs.
609                CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0,  &
610                     comm2d, status, ierr )
611!
612!--             Not all PEs have data for the mask
613                IF ( ind(1) /= -9999 )  THEN
614                   ngp = ( ind(2)-ind(1)+1 ) * (ind(4)-ind(3)+1 ) *  &
615                         ( ind(6)-ind(5)+1 )
616                   sender = status(MPI_SOURCE)
617                   DEALLOCATE( local_pf )
618                   ALLOCATE(local_pf(ind(1):ind(2),ind(3):ind(4),ind(5):ind(6)))
619                   CALL MPI_RECV( local_pf(ind(1),ind(3),ind(5)), ngp,  &
620                        MPI_REAL, sender, 1, comm2d, status, ierr )
621                   total_pf(ind(1):ind(2),ind(3):ind(4),ind(5):ind(6)) &
622                        = local_pf
623                ENDIF
624             ENDDO
625
626             nc_stat = NF90_PUT_VAR( id_set_mask(mid,av),                      &
627                  id_var_domask(mid,av,ivar), total_pf,                        &
628                  start = (/ 1, 1, 1, domask_time_count(mid,av) /),            &
629                  count = (/ mask_size(mid,1), mask_size(mid,2),               &
630                             mask_size(mid,3), 1 /) )
631             CALL netcdf_handle_error( 'data_output_mask', 462 )
632
633          ELSE
634!
635!--          If at least part of the mask resides on the PE, send the index
636!--          limits for the target array, otherwise send -9999 to PE0.
637             IF ( mask_size_l(mid,1) > 0 .AND.  mask_size_l(mid,2) > 0 .AND. &
638                  mask_size_l(mid,3) > 0  ) &
639                  THEN
640                ind(1) = mask_start_l(mid,1)
641                ind(2) = mask_start_l(mid,1) + mask_size_l(mid,1) - 1
642                ind(3) = mask_start_l(mid,2)
643                ind(4) = mask_start_l(mid,2) + mask_size_l(mid,2) - 1
644                ind(5) = mask_start_l(mid,3)
645                ind(6) = mask_start_l(mid,3) + mask_size_l(mid,3) - 1
646             ELSE
647                ind(1) = -9999; ind(2) = -9999
648                ind(3) = -9999; ind(4) = -9999
649                ind(5) = -9999; ind(6) = -9999
650             ENDIF
651             CALL MPI_SEND( ind(1), 6, MPI_INTEGER, 0, 0, comm2d, ierr )
652!
653!--          If applicable, send data to PE0.
654             IF ( ind(1) /= -9999 )  THEN
655                CALL MPI_SEND( local_pf(1,1,1), ngp, MPI_REAL, 0, 1, comm2d, &
656                     ierr )
657             ENDIF
658          ENDIF
659!
660!--       A barrier has to be set, because otherwise some PEs may proceed too
661!--       fast so that PE0 may receive wrong data on tag 0.
662          CALL MPI_BARRIER( comm2d, ierr )
663#if defined( __netcdf4_parallel )
664       ENDIF
665#endif
666#else
667!
668!--    (2) For serial execution of PALM, the single processor (PE0) holds all
669!--    data and writes them directly to file.
670       nc_stat = NF90_PUT_VAR( id_set_mask(mid,av),                            &
671                               id_var_domask(mid,av,ivar), local_pf,           &
672                             start = (/ 1, 1, 1, domask_time_count(mid,av) /), &
673                             count = (/ mask_size_l(mid,1), mask_size_l(mid,2),&
674                               mask_size_l(mid,3), 1 /) )
675       CALL netcdf_handle_error( 'data_output_mask', 463 )
676#endif
677
678       ivar = ivar + 1
679
680    ENDDO
681
682!
683!-- Deallocate temporary arrays.
684    DEALLOCATE( local_pf )
685#if defined( __parallel )
686    IF ( myid == 0 )  THEN
687       DEALLOCATE( total_pf )
688    ENDIF
689#endif
690
691!
692!-- Switch back to original format given by user (see beginning of this routine)
693    netcdf_data_format = netcdf_data_format_save
694
695    CALL cpu_log( log_point(49), 'data_output_mask', 'stop' )
696#endif
697
698 END SUBROUTINE data_output_mask
Note: See TracBrowser for help on using the repository browser.