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

Last change on this file since 978 was 791, checked in by raasch, 12 years ago

last commit documented

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