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

Last change on this file since 1114 was 1107, checked in by raasch, 11 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 20.9 KB
Line 
1 SUBROUTINE data_output_3d( av )
2
3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later 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-2012  Leibniz University Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: data_output_3d.f90 1107 2013-03-04 06:23:14Z raasch $
27!
28! 1106 2013-03-04 05:31:38Z raasch
29! array_kind renamed precision_kind
30!
31! 1076 2012-12-05 08:30:18Z hoffmann
32! Bugfix in output of ql
33!
34! 1053 2012-11-13 17:11:03Z hoffmann
35! +nr, qr, prr, qc and averaged quantities
36!
37! 1036 2012-10-22 13:43:42Z raasch
38! code put under GPL (PALM 3.9)
39!
40! 1031 2012-10-19 14:35:30Z raasch
41! netCDF4 without parallel file support implemented
42!
43! 1007 2012-09-19 14:30:36Z franke
44! Bugfix: missing calculation of ql_vp added
45!
46! 790 2011-11-29 03:11:20Z raasch
47! bugfix: calculation of 'pr' must depend on the particle weighting factor,
48! nzt+1 replaced by nz_do3d for 'pr'
49!
50! 771 2011-10-27 10:56:21Z heinze
51! +lpt
52!
53! 759 2011-09-15 13:58:31Z raasch
54! Splitting of parallel I/O
55!
56! 727 2011-04-20 20:05:25Z suehring
57! Exchange ghost layers also for p_av.
58!
59! 725 2011-04-11 09:37:01Z suehring
60! Exchange ghost layers for p regardless of used pressure solver (except SOR).
61!
62! 691 2011-03-04 08:45:30Z maronga
63! Replaced simulated_time by time_since_reference_point
64!
65! 673 2011-01-18 16:19:48Z suehring
66! When using Multigrid or SOR solver an additional CALL exchange_horiz is
67! is needed for pressure output.
68!
69! 667 2010-12-23 12:06:00Z suehring/gryschka
70! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng in loops and
71! allocation of arrays.  Calls of exchange_horiz are modified.
72! Skip-value skip_do_avs changed to a dynamic adaption of ghost points.
73!
74! 646 2010-12-15 13:03:52Z raasch
75! bugfix: missing define statements for netcdf added
76!
77! 493 2010-03-01 08:30:24Z raasch
78! netCDF4 support (parallel output)
79!
80! 355 2009-07-17 01:03:01Z letzel
81! simulated_time in netCDF output replaced by time_since_reference_point.
82! Output of netCDF messages with aid of message handling routine.
83! Output of messages replaced by message handling routine.
84! Bugfix: to_be_resorted => s_av for time-averaged scalars
85!
86! 96 2007-06-04 08:07:41Z raasch
87! Output of density and salinity
88!
89! 75 2007-03-22 09:54:05Z raasch
90! 2nd+3rd argument removed from exchange horiz
91!
92! RCS Log replace by Id keyword, revision history cleaned up
93!
94! Revision 1.3  2006/06/02 15:18:59  raasch
95! +argument "found", -argument grid in call of routine user_data_output_3d
96!
97! Revision 1.2  2006/02/23 10:23:07  raasch
98! Former subroutine plot_3d renamed data_output_3d, pl.. renamed do..,
99! .._anz renamed .._n,
100! output extended to (almost) all quantities, output of user-defined quantities
101!
102! Revision 1.1  1997/09/03 06:29:36  raasch
103! Initial revision
104!
105!
106! Description:
107! ------------
108! Output of the 3D-arrays in netCDF and/or AVS format.
109!------------------------------------------------------------------------------!
110
111    USE arrays_3d
112    USE averaging
113    USE cloud_parameters
114    USE control_parameters
115    USE cpulog
116    USE indices
117    USE interfaces
118    USE netcdf_control
119    USE particle_attributes
120    USE pegrid
121    USE precision_kind
122
123    IMPLICIT NONE
124
125    CHARACTER (LEN=9) ::  simulated_time_mod
126
127    INTEGER           ::  av, i, if, j, k, n, pos, prec, psi
128
129    LOGICAL           ::  found, resorted
130
131    REAL              ::  mean_r, s_r3, s_r4
132
133    REAL(spk), DIMENSION(:,:,:), ALLOCATABLE  ::  local_pf
134
135    REAL, DIMENSION(:,:,:), POINTER ::  to_be_resorted
136
137!
138!-- Return, if nothing to output
139    IF ( do3d_no(av) == 0 )  RETURN
140
141    CALL cpu_log (log_point(14),'data_output_3d','start')
142
143!
144!-- Open output file.
145!-- Also creates coordinate and fld-file for AVS.
146!-- For classic or 64bit netCDF output or output of other (old) data formats,
147!-- for a run on more than one PE, each PE opens its own file and
148!-- writes the data of its subdomain in binary format (regardless of the format
149!-- the user has requested). After the run, these files are combined to one
150!-- file by combine_plot_fields in the format requested by the user (netcdf
151!-- and/or avs).
152!-- For netCDF4/HDF5 output, data is written in parallel into one file.
153    IF ( netcdf_output )  THEN
154       IF ( netcdf_data_format < 5 )  THEN
155          CALL check_open( 30 )
156          IF ( myid == 0 )  CALL check_open( 106+av*10 )
157       ELSE
158          CALL check_open( 106+av*10 )
159       ENDIF
160    ELSE
161       IF ( avs_output  .OR.  ( numprocs > 1 ) )  CALL check_open( 30 )
162    ENDIF
163
164!
165!-- Allocate a temporary array with the desired output dimensions.
166    ALLOCATE( local_pf(nxlg:nxrg,nysg:nyng,nzb:nz_do3d) )
167
168!
169!-- Update the netCDF time axis
170#if defined( __netcdf )
171    IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
172       do3d_time_count(av) = do3d_time_count(av) + 1
173       IF ( netcdf_output )  THEN
174          nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_time_3d(av), &
175                                  (/ time_since_reference_point /),  &
176                                  start = (/ do3d_time_count(av) /), &
177                                  count = (/ 1 /) )
178          CALL handle_netcdf_error( 'data_output_3d', 376 )
179       ENDIF
180    ENDIF
181#endif
182
183!
184!-- Loop over all variables to be written.
185    if = 1
186
187    DO  WHILE ( do3d(av,if)(1:1) /= ' ' )
188!
189!--    Set the precision for data compression.
190       IF ( do3d_compress )  THEN
191          DO  i = 1, 100
192             IF ( plot_3d_precision(i)%variable == do3d(av,if) )  THEN
193                prec = plot_3d_precision(i)%precision
194                EXIT
195             ENDIF
196          ENDDO
197       ENDIF
198
199!
200!--    Store the array chosen on the temporary array.
201       resorted = .FALSE.
202       SELECT CASE ( TRIM( do3d(av,if) ) )
203
204          CASE ( 'e' )
205             IF ( av == 0 )  THEN
206                to_be_resorted => e
207             ELSE
208                to_be_resorted => e_av
209             ENDIF
210
211          CASE ( 'lpt' )
212             IF ( av == 0 )  THEN
213                to_be_resorted => pt
214             ELSE
215                to_be_resorted => lpt_av
216             ENDIF
217
218          CASE ( 'nr' )
219             IF ( av == 0 )  THEN
220                to_be_resorted => nr
221             ELSE
222                to_be_resorted => nr_av
223             ENDIF
224
225          CASE ( 'p' )
226             IF ( av == 0 )  THEN
227                IF ( psolver /= 'sor' )  CALL exchange_horiz( p, nbgp )
228                to_be_resorted => p
229             ELSE
230                IF ( psolver /= 'sor' )  CALL exchange_horiz( p_av, nbgp )
231                to_be_resorted => p_av
232             ENDIF
233
234          CASE ( 'pc' )  ! particle concentration (requires ghostpoint exchange)
235             IF ( av == 0 )  THEN
236                tend = prt_count
237                CALL exchange_horiz( tend, nbgp )
238                DO  i = nxlg, nxrg
239                   DO  j = nysg, nyng
240                      DO  k = nzb, nz_do3d
241                         local_pf(i,j,k) = tend(k,j,i)
242                      ENDDO
243                   ENDDO
244                ENDDO
245                resorted = .TRUE.
246             ELSE
247                CALL exchange_horiz( pc_av, nbgp )
248                to_be_resorted => pc_av
249             ENDIF
250
251          CASE ( 'pr' )  ! mean particle radius
252             IF ( av == 0 )  THEN
253                DO  i = nxl, nxr
254                   DO  j = nys, nyn
255                      DO  k = nzb, nz_do3d
256                         psi = prt_start_index(k,j,i)
257                         s_r3 = 0.0
258                         s_r4 = 0.0
259                         DO  n = psi, psi+prt_count(k,j,i)-1
260                         s_r3 = s_r3 + particles(n)%radius**3 * &
261                                       particles(n)%weight_factor
262                         s_r4 = s_r4 + particles(n)%radius**4 * &
263                                       particles(n)%weight_factor
264                         ENDDO
265                         IF ( s_r3 /= 0.0 )  THEN
266                            mean_r = s_r4 / s_r3
267                         ELSE
268                            mean_r = 0.0
269                         ENDIF
270                         tend(k,j,i) = mean_r
271                      ENDDO
272                   ENDDO
273                ENDDO
274                CALL exchange_horiz( tend, nbgp )
275                DO  i = nxlg, nxrg
276                   DO  j = nysg, nyng
277                      DO  k = nzb, nz_do3d
278                         local_pf(i,j,k) = tend(k,j,i)
279                      ENDDO
280                   ENDDO
281                ENDDO
282                resorted = .TRUE.
283             ELSE
284                CALL exchange_horiz( pr_av, nbgp )
285                to_be_resorted => pr_av
286             ENDIF
287
288          CASE ( 'prr' )
289             IF ( av == 0 )  THEN
290                CALL exchange_horiz( prr, nbgp )
291                DO  i = nxlg, nxrg
292                   DO  j = nysg, nyng
293                      DO  k = nzb, nzt+1
294                         local_pf(i,j,k) = prr(k,j,i)
295                      ENDDO
296                   ENDDO
297                ENDDO
298             ELSE
299                CALL exchange_horiz( prr_av, nbgp )
300                DO  i = nxlg, nxrg
301                   DO  j = nysg, nyng
302                      DO  k = nzb, nzt+1
303                         local_pf(i,j,k) = prr_av(k,j,i)
304                      ENDDO
305                   ENDDO
306                ENDDO
307             ENDIF
308             resorted = .TRUE.
309
310          CASE ( 'pt' )
311             IF ( av == 0 )  THEN
312                IF ( .NOT. cloud_physics ) THEN
313                   to_be_resorted => pt
314                ELSE
315                   DO  i = nxlg, nxrg
316                      DO  j = nysg, nyng
317                         DO  k = nzb, nz_do3d
318                            local_pf(i,j,k) = pt(k,j,i) + l_d_cp *    &
319                                                          pt_d_t(k) * &
320                                                          ql(k,j,i)
321                         ENDDO
322                      ENDDO
323                   ENDDO
324                   resorted = .TRUE.
325                ENDIF
326             ELSE
327                to_be_resorted => pt_av
328             ENDIF
329
330          CASE ( 'q' )
331             IF ( av == 0 )  THEN
332                to_be_resorted => q
333             ELSE
334                to_be_resorted => q_av
335             ENDIF
336
337          CASE ( 'qc' )
338             IF ( av == 0 )  THEN
339                to_be_resorted => ql
340             ELSE
341                to_be_resorted => ql_av
342             ENDIF
343
344          CASE ( 'ql' )
345             IF ( av == 0 )  THEN
346                IF ( cloud_physics  .AND.  icloud_scheme == 0 )  THEN
347                   DO  i = nxlg, nxrg
348                      DO  j = nysg, nyng
349                         DO  k = nzb, nz_do3d
350                            local_pf(i,j,k) = ql(k,j,i) + qr(k,j,i)
351                         ENDDO
352                      ENDDO
353                   ENDDO
354                   resorted = .TRUE.
355                ELSE
356                   to_be_resorted => ql
357                ENDIF
358             ELSE
359                IF ( cloud_physics  .AND.  icloud_scheme == 0 )  THEN
360                   DO  i = nxlg, nxrg
361                      DO  j = nysg, nyng
362                         DO  k = nzb, nz_do3d
363                            local_pf(i,j,k) = ql_av(k,j,i) + qr_av(k,j,i)
364                         ENDDO
365                      ENDDO
366                   ENDDO
367                   resorted = .TRUE.
368                ELSE
369                   to_be_resorted => ql_av
370                ENDIF
371             ENDIF
372
373          CASE ( 'ql_c' )
374             IF ( av == 0 )  THEN
375                to_be_resorted => ql_c
376             ELSE
377                to_be_resorted => ql_c_av
378             ENDIF
379
380          CASE ( 'ql_v' )
381             IF ( av == 0 )  THEN
382                to_be_resorted => ql_v
383             ELSE
384                to_be_resorted => ql_v_av
385             ENDIF
386
387          CASE ( 'ql_vp' )
388             IF ( av == 0 )  THEN
389                DO  i = nxl, nxr
390                   DO  j = nys, nyn
391                      DO  k = nzb, nz_do3d
392                         psi = prt_start_index(k,j,i)
393                         DO  n = psi, psi+prt_count(k,j,i)-1
394                            tend(k,j,i) = tend(k,j,i) + &
395                                          particles(n)%weight_factor / &
396                                          prt_count(k,j,i)
397                         ENDDO
398                      ENDDO
399                   ENDDO
400                ENDDO
401                CALL exchange_horiz( tend, nbgp )
402                DO  i = nxlg, nxrg
403                   DO  j = nysg, nyng
404                      DO  k = nzb, nz_do3d
405                         local_pf(i,j,k) = tend(k,j,i)
406                      ENDDO
407                   ENDDO
408                ENDDO
409                resorted = .TRUE.
410             ELSE
411                CALL exchange_horiz( ql_vp_av, nbgp )
412                to_be_resorted => ql_vp_av
413             ENDIF
414
415          CASE ( 'qr' )
416             IF ( av == 0 )  THEN
417                to_be_resorted => qr
418             ELSE
419                to_be_resorted => qr_av
420             ENDIF
421
422          CASE ( 'qv' )
423             IF ( av == 0 )  THEN
424                DO  i = nxlg, nxrg
425                   DO  j = nysg, nyng
426                      DO  k = nzb, nz_do3d
427                         local_pf(i,j,k) = q(k,j,i) - ql(k,j,i)
428                      ENDDO
429                   ENDDO
430                ENDDO
431                resorted = .TRUE.
432             ELSE
433                to_be_resorted => qv_av
434             ENDIF
435
436          CASE ( 'rho' )
437             IF ( av == 0 )  THEN
438                to_be_resorted => rho
439             ELSE
440                to_be_resorted => rho_av
441             ENDIF
442
443          CASE ( 's' )
444             IF ( av == 0 )  THEN
445                to_be_resorted => q
446             ELSE
447                to_be_resorted => s_av
448             ENDIF
449
450          CASE ( 'sa' )
451             IF ( av == 0 )  THEN
452                to_be_resorted => sa
453             ELSE
454                to_be_resorted => sa_av
455             ENDIF
456
457          CASE ( 'u' )
458             IF ( av == 0 )  THEN
459                to_be_resorted => u
460             ELSE
461                to_be_resorted => u_av
462             ENDIF
463
464          CASE ( 'v' )
465             IF ( av == 0 )  THEN
466                to_be_resorted => v
467             ELSE
468                to_be_resorted => v_av
469             ENDIF
470
471          CASE ( 'vpt' )
472             IF ( av == 0 )  THEN
473                to_be_resorted => vpt
474             ELSE
475                to_be_resorted => vpt_av
476             ENDIF
477
478          CASE ( 'w' )
479             IF ( av == 0 )  THEN
480                to_be_resorted => w
481             ELSE
482                to_be_resorted => w_av
483             ENDIF
484
485          CASE DEFAULT
486!
487!--          User defined quantity
488             CALL user_data_output_3d( av, do3d(av,if), found, local_pf, &
489                                       nz_do3d )
490             resorted = .TRUE.
491
492             IF ( .NOT. found )  THEN
493                message_string =  'no output available for: ' //   &
494                                  TRIM( do3d(av,if) )
495                CALL message( 'data_output_3d', 'PA0182', 0, 0, 0, 6, 0 )
496             ENDIF
497
498       END SELECT
499
500!
501!--    Resort the array to be output, if not done above
502       IF ( .NOT. resorted )  THEN
503          DO  i = nxlg, nxrg
504             DO  j = nysg, nyng
505                DO  k = nzb, nz_do3d
506                   local_pf(i,j,k) = to_be_resorted(k,j,i)
507                ENDDO
508             ENDDO
509          ENDDO
510       ENDIF
511
512!
513!--    Output of the volume data information for the AVS-FLD-file.
514       do3d_avs_n = do3d_avs_n + 1
515       IF ( myid == 0  .AND.  avs_output )  THEN
516!
517!--       AVS-labels must not contain any colons. Hence they must be removed
518!--       from the time character string.
519          simulated_time_mod = simulated_time_chr
520          DO  WHILE ( SCAN( simulated_time_mod, ':' ) /= 0 )
521             pos = SCAN( simulated_time_mod, ':' )
522             simulated_time_mod(pos:pos) = '/'
523          ENDDO
524
525          IF ( av == 0 )  THEN
526             WRITE ( 33, 3300 )  do3d_avs_n, TRIM( avs_data_file ), &
527                                 skip_do_avs, TRIM( do3d(av,if) ), &
528                                 TRIM( simulated_time_mod )
529          ELSE
530             WRITE ( 33, 3300 )  do3d_avs_n, TRIM( avs_data_file ), &
531                                 skip_do_avs, TRIM( do3d(av,if) ) // &
532                                 ' averaged', TRIM( simulated_time_mod )
533          ENDIF
534!
535!--       Determine the Skip-value for the next array. Record end and start
536!--       require 4 byte each.
537          skip_do_avs = skip_do_avs + ( ( ( nx+2*nbgp ) * ( ny+2*nbgp ) * &
538                                          ( nz_do3d+1 ) ) * 4 + 8 )
539       ENDIF
540
541!
542!--    Output of the 3D-array. (compressed/uncompressed)
543       IF ( do3d_compress )  THEN
544!
545!--       Compression, output of compression information on FLD-file and output
546!--       of compressed data.
547          CALL write_compressed( local_pf, 30, 33, myid, nxl, nxr, nyn, nys, &
548                                 nzb, nz_do3d, prec, nbgp )
549       ELSE
550!
551!--       Uncompressed output.
552#if defined( __parallel )
553          IF ( netcdf_output )  THEN
554             IF ( netcdf_data_format < 5 )  THEN
555!
556!--             Non-parallel netCDF output. Data is output in parallel in
557!--             FORTRAN binary format here, and later collected into one file by
558!--             combine_plot_fields
559                IF ( myid == 0 )  THEN
560                   WRITE ( 30 )  time_since_reference_point,                   &
561                                 do3d_time_count(av), av
562                ENDIF
563                DO  i = 0, io_blocks-1
564                   IF ( i == io_group )  THEN
565                      WRITE ( 30 )  nxlg, nxrg, nysg, nyng, nzb, nz_do3d
566                      WRITE ( 30 )  local_pf
567                   ENDIF
568#if defined( __parallel )
569                   CALL MPI_BARRIER( comm2d, ierr )
570#endif
571                ENDDO
572
573             ELSE
574#if defined( __netcdf )
575!
576!--             Parallel output in netCDF4/HDF5 format.
577!--             Do not output redundant ghost point data except for the
578!--             boundaries of the total domain.
579                IF ( nxr == nx  .AND.  nyn /= ny )  THEN
580                   nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if), &
581                                  local_pf(nxl:nxrg,nys:nyn,nzb:nz_do3d),    &
582                      start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /), &
583                      count = (/ nxr-nxl+1+nbgp, nyn-nys+1, nz_do3d-nzb+1, 1 /) )
584                ELSEIF ( nxr /= nx  .AND.  nyn == ny )  THEN
585                   nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if), &
586                                  local_pf(nxl:nxr,nys:nyng,nzb:nz_do3d),    &
587                      start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /), &
588                      count = (/ nxr-nxl+1, nyn-nys+1+nbgp, nz_do3d-nzb+1, 1 /) )
589                ELSEIF ( nxr == nx  .AND.  nyn == ny )  THEN
590                   nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if), &
591                                  local_pf(nxl:nxrg,nys:nyng,nzb:nz_do3d),  &
592                      start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /), &
593                      count = (/ nxr-nxl+1+nbgp, nyn-nys+1+nbgp, nz_do3d-nzb+1, 1 /) )
594                ELSE
595                   nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if), &
596                                  local_pf(nxl:nxr,nys:nyn,nzb:nz_do3d),      &
597                      start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /), &
598                      count = (/ nxr-nxl+1, nyn-nys+1, nz_do3d-nzb+1, 1 /) )
599                ENDIF
600                CALL handle_netcdf_error( 'data_output_3d', 386 )
601#endif
602             ENDIF
603          ENDIF
604#else
605          IF ( avs_output )  THEN
606             WRITE ( 30 )  local_pf(nxl:nxr+1,nys:nyn+1,:)
607          ENDIF
608#if defined( __netcdf )
609          IF ( netcdf_output )  THEN
610
611             nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if),    &
612                               local_pf(nxl:nxr+1,nys:nyn+1,nzb:nz_do3d),  &
613                               start = (/ 1, 1, 1, do3d_time_count(av) /), &
614                               count = (/ nx+2, ny+2, nz_do3d-nzb+1, 1 /) )
615             CALL handle_netcdf_error( 'data_output_3d', 446 )
616
617          ENDIF
618#endif
619#endif
620       ENDIF
621
622       if = if + 1
623
624    ENDDO
625
626!
627!-- Deallocate temporary array.
628    DEALLOCATE( local_pf )
629
630
631    CALL cpu_log (log_point(14),'data_output_3d','stop','nobarrier')
632
633!
634!-- Formats.
6353300 FORMAT ('variable ',I4,'  file=',A,'  filetype=unformatted  skip=',I12/ &
636             'label = ',A,A)
637
638 END SUBROUTINE data_output_3d
Note: See TracBrowser for help on using the repository browser.