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

Last change on this file since 760 was 760, checked in by raasch, 13 years ago

last commit documented

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