source: palm/trunk/SOURCE/data_output_spectra.f90 @ 96

Last change on this file since 96 was 4, checked in by raasch, 17 years ago

Id keyword set as property for all *.f90 files

  • Property svn:keywords set to Id
File size: 16.0 KB
Line 
1 SUBROUTINE data_output_spectra
2
3!------------------------------------------------------------------------------!
4! Actual revisions:
5! -----------------
6!
7!
8! Former revisions:
9! -----------------
10! $Id: data_output_spectra.f90 4 2007-02-13 11:33:16Z raasch $
11! RCS Log replace by Id keyword, revision history cleaned up
12!
13! Revision 1.7  2006/04/11 14:56:38  raasch
14! pl_spectra renamed data_output_sp
15!
16! Revision 1.1  2001/01/05 15:14:20  raasch
17! Initial revision
18!
19!
20! Description:
21! ------------
22! Writing spectra data on file, using a special format which allows
23! plotting of these data with PROFIL-graphic-software
24!------------------------------------------------------------------------------!
25#if defined( __spectra )
26
27    USE arrays_3d
28    USE control_parameters
29    USE cpulog
30    USE interfaces
31    USE netcdf_control
32    USE pegrid
33    USE spectrum
34    USE statistics
35
36
37    IMPLICIT NONE
38
39    INTEGER :: m, pr, cranz_x, cranz_y
40    LOGICAL :: frame_x, frame_y
41
42    CALL cpu_log( log_point(31), 'data_output_spectra', 'start' )
43
44!
45!-- Output is only performed on PE0
46    IF ( myid == 0 )  THEN
47
48!
49!--    Open file for spectra output in NetCDF format
50       IF ( netcdf_output )  CALL check_open( 107 )
51
52!
53!--    Increment the counter for number of output times
54       dosp_time_count = dosp_time_count + 1
55
56#if defined( __netcdf )
57!
58!--    Update the spectra time axis
59       nc_stat = NF90_PUT_VAR( id_set_sp, id_var_time_sp, (/ simulated_time /),&
60                               start = (/ dosp_time_count /), count = (/ 1 /) )
61       IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 47 )
62#endif
63
64       IF ( profil_output )  THEN
65!
66!--       Compute RAHMEN-Parameter CRANZ for x- and y-spectra separately
67          cranz_x = 0; cranz_y = 0; frame_x = .FALSE.; frame_y = .FALSE.
68
69          m = 1
70          DO WHILE ( data_output_sp(m) /= ' ' .AND. m <= 10 )
71
72             IF ( INDEX( spectra_direction(m), 'x' ) /= 0 )  THEN
73                cranz_x = cranz_x + 1
74             ENDIF
75             IF ( INDEX( spectra_direction(m), 'y' ) /= 0 )  THEN
76                cranz_y = cranz_y + 1
77             ENDIF
78
79             m = m + 1
80
81          ENDDO
82
83       ENDIF
84
85!
86!--    If necessary, calculate time average and reset average counter
87       IF ( average_count_sp == 0 )  THEN
88          PRINT*, '+++ data_output_spectra: no spectra data available'
89       ENDIF
90       IF ( average_count_sp /= 1 )  THEN
91          spectrum_x = spectrum_x / REAL( average_count_sp )
92          spectrum_y = spectrum_y / REAL( average_count_sp )
93          average_count_sp = 0
94       ENDIF
95
96!
97!--    Loop over all spectra defined by the user
98       m = 1
99       DO WHILE ( data_output_sp(m) /= ' '  .AND.  m <= 10 )
100
101          SELECT CASE ( TRIM( data_output_sp(m) ) )
102
103             CASE ( 'u' )
104                pr = 1
105
106             CASE ( 'v' )
107                pr = 2
108
109             CASE ( 'w' )
110                pr = 3
111
112             CASE ( 'pt' )
113                pr = 4
114
115             CASE ( 'q' )
116                pr = 5
117
118             CASE DEFAULT
119                PRINT*, '+++ data_output_spectra: Spectra of ', &
120                             TRIM( data_output_sp(m) ), ' are not defined'
121
122          END SELECT
123
124!
125!--       Output of spectra in NetCDF format
126          IF ( netcdf_output )  THEN
127!
128!--          Output of x-spectra
129             IF ( INDEX( spectra_direction(m), 'x' ) /= 0 ) THEN
130                CALL output_spectra_netcdf( m, 'x' )
131             ENDIF
132!
133!--          Output of y-spectra
134             IF ( INDEX( spectra_direction(m), 'y' ) /= 0 ) THEN
135                CALL output_spectra_netcdf( m, 'y' )
136             ENDIF
137          ENDIF
138
139!
140!--       Output of spectra in profil format
141          IF ( profil_output )  THEN
142!
143!--          Output of x-spectra
144             IF ( INDEX( spectra_direction(m), 'x' ) /= 0 ) THEN
145                CALL data_output_spectra_x( m, cranz_x, pr, frame_x )
146             ENDIF
147
148!
149!--          Output of y-spectra
150             IF ( INDEX( spectra_direction(m), 'y' ) /= 0 ) THEN
151                CALL data_output_spectra_y( m, cranz_y, pr, frame_y )
152             ENDIF
153          ENDIF
154
155!
156!--       Increase counter for next spectrum
157          m = m + 1
158
159       ENDDO
160
161!
162!--    Reset spectra values
163       spectrum_x = 0.0; spectrum_y = 0.0
164
165    ENDIF
166
167    CALL cpu_log( log_point(31), 'data_output_spectra', 'stop' )
168
169#if defined( __parallel )
170!    CALL MPI_BARRIER( comm2d, ierr )  ! really necessary
171#endif
172
173#endif
174 END SUBROUTINE data_output_spectra
175
176
177 SUBROUTINE output_spectra_netcdf( nsp, direction )
178#if defined( __netcdf )
179
180    USE constants
181    USE control_parameters
182    USE grid_variables
183    USE indices
184    USE netcdf_control
185    USE spectrum
186    USE statistics
187
188    IMPLICIT NONE
189
190    CHARACTER (LEN=1), INTENT(IN) ::  direction
191
192    INTEGER, INTENT(IN) ::  nsp
193
194    INTEGER ::  i, k
195
196    REAL ::  frequency
197
198    REAL, DIMENSION(nx/2) ::  netcdf_data_x
199    REAL, DIMENSION(ny/2) ::  netcdf_data_y
200
201
202    IF ( direction == 'x' )  THEN
203
204       DO  k = 1, n_sp_x
205
206          DO  i = 1, nx/2
207             frequency = 2.0 * pi * i / ( dx * ( nx + 1 ) )
208             netcdf_data_x(i) = frequency * spectrum_x(i,k,nsp)
209          ENDDO
210
211          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospx(nsp), netcdf_data_x, &
212                                  start = (/ 1, k, dosp_time_count /), &
213                                  count = (/ nx/2, 1, 1 /) )
214          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 348 )
215
216       ENDDO
217
218    ENDIF
219
220    IF ( direction == 'y' )  THEN
221
222       DO  k = 1, n_sp_y
223
224          DO  i = 1, ny/2
225             frequency = 2.0 * pi * i / ( dy * ( ny + 1 ) )
226             netcdf_data_y(i) = frequency * spectrum_y(i,k,nsp)
227          ENDDO
228
229          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospy(nsp), netcdf_data_y, &
230                                  start = (/ 1, k, dosp_time_count /), &
231                                  count = (/ ny/2, 1, 1 /) )
232          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 349 )
233
234       ENDDO
235
236    ENDIF
237
238#endif
239 END SUBROUTINE output_spectra_netcdf
240
241
242#if defined( __spectra )
243 SUBROUTINE data_output_spectra_x( m, cranz, pr, frame_written )
244
245    USE arrays_3d
246    USE constants
247    USE control_parameters
248    USE grid_variables
249    USE indices
250    USE pegrid
251    USE singleton
252    USE spectrum
253    USE statistics
254    USE transpose_indices
255
256    IMPLICIT NONE
257
258    CHARACTER (LEN=30) ::  atext
259    INTEGER            ::  i, j, k, m, pr
260    LOGICAL            ::  frame_written
261    REAL               ::  frequency = 0.0
262
263!
264!-- Variables needed for PROFIL-namelist
265    INTEGER                  :: cranz, labforx = 3, labfory = 3, legpos = 3, &
266                                timodex = 1
267    INTEGER, DIMENSION(1:10) :: cucol = 1, klist = 999999, lstyle = 0
268    LOGICAL                  :: datleg = .TRUE., grid = .TRUE., &
269                                lclose = .TRUE., rand = .TRUE., &
270                                swap = .TRUE., twoxa = .TRUE.,  &
271                                xlog = .TRUE., ylog = .TRUE.
272    CHARACTER (LEN=80)       :: rtext, utext, xtext = 'k in m>->1', ytext
273    REAL                     :: gwid = 0.1, rlegfak = 0.7, uxmin, uxmax, &
274                                uymin, uymax
275    REAL, DIMENSION(1:10)    :: lwid = 0.6
276    REAL, DIMENSION(10)      :: uyma, uymi
277
278    NAMELIST /RAHMEN/  cranz, datleg, rtext, swap
279    NAMELIST /CROSS/   rand, cucol, grid, gwid, klist, labforx, labfory,      &
280                       legpos, lclose, lstyle, lwid, rlegfak, timodex, utext, &
281                       uxmin, uxmax, uymin, uymax, twoxa, xlog, xtext, ylog,  &
282                       ytext
283
284
285    rtext = '\0.5 ' // run_description_header
286
287!
288!-- Open parameter- and data-file
289    CALL check_open( 81 )
290    CALL check_open( 82 )
291
292!
293!-- Write file header,
294!-- write RAHMEN-parameters (pr=3: w-array is on zw, other arrys on zu,
295!-- pr serves as an index for output of strings (axis-labels) of the
296!-- different quantities u, v, w, pt and q)
297    DO  k = 1, n_sp_x
298       IF ( k < 10 )  THEN
299          IF ( pr == 3 )  THEN
300             WRITE ( 82, 100 )  '#', k, header_char( pr ),        &
301                                INT( zw(comp_spectra_level(k)) ), &
302                                simulated_time_chr
303          ELSE
304             WRITE ( 82, 100 )  '#', k, header_char( pr ),        &
305                                INT( zu(comp_spectra_level(k)) ), &
306                                simulated_time_chr
307          ENDIF
308       ELSE
309          IF ( pr == 3 )  THEN
310             WRITE ( 82, 101 )  '#', k, header_char( pr ),        &
311                                INT( zw(comp_spectra_level(k)) ), &
312                                simulated_time_chr
313          ELSE
314             WRITE ( 82, 101 )  '#', k, header_char( pr ),        &
315                                INT( zu(comp_spectra_level(k)) ), &
316                                simulated_time_chr
317          ENDIF
318       ENDIF
319    ENDDO
320
321    IF ( .NOT. frame_written )  THEN
322       WRITE ( 81, RAHMEN )
323       frame_written = .TRUE.
324    ENDIF
325
326!
327!-- Write all data and calculate uymi and uyma. They serve to calculate
328!-- the CROSS-parameters uymin and uymax
329    uymi = 999.999; uyma = -999.999
330    DO  i = 1, nx/2
331       frequency = 2.0 * pi * i / ( dx * ( nx + 1 ) )
332       WRITE ( 82, 102 )  frequency, ( frequency * spectrum_x(i,k,m), k = 1, &
333                          n_sp_x )
334       DO  k = 1, n_sp_x
335          uymi(k) = MIN( uymi(k), frequency * spectrum_x(i,k,m) )
336          uyma(k) = MAX( uyma(k), frequency * spectrum_x(i,k,m) )
337       ENDDO
338    ENDDO
339
340!
341!-- Determine CROSS-parameters
342    cucol(1:n_sp_x)  = (/ ( k, k = 1, n_sp_x ) /)
343    lstyle(1:n_sp_x) = (/ ( lstyles(k), k = 1, n_sp_x ) /)
344
345!
346!-- Calculate klist-values from the available comp_spectra_level values
347    i = 1; k = 1
348    DO WHILE ( i <= 10  .AND.  plot_spectra_level(i) /= 999999 )
349       DO WHILE ( k <= n_sp_x  .AND. &
350                  plot_spectra_level(i) >= comp_spectra_level(k) )
351          IF ( plot_spectra_level(i) == comp_spectra_level(k) )  THEN
352             klist(i) = k + klist_x
353          ELSE
354             uymi(k) =  999.999
355             uyma(k) = -999.999
356          ENDIF
357          k = k + 1
358       ENDDO
359       i = i + 1
360    ENDDO
361    uymi(k:n_sp_x) =  999.999
362    uyma(k:n_sp_x) = -999.999
363    utext = 'x'//utext_char( pr )
364    IF ( averaging_interval_sp /= 0.0 ) THEN
365       WRITE ( atext, 104 )  averaging_interval_sp
366       utext = TRIM(utext) // ',  ' // TRIM( atext )
367    ENDIF
368    uxmin = 0.8 * 2.0 * pi        / ( dx * ( nx + 1 ) )
369    uxmax = 1.2 * 2.0 * pi * nx/2 / ( dx * ( nx + 1 ) )
370    uymin = 0.8 * MIN (  999.999, MINVAL ( uymi ) )
371    uymax = 1.2 * MAX ( -999.999, MAXVAL ( uyma ) )
372    ytext = ytext_char( pr )
373
374!
375!-- Output of CROSS-parameters
376    WRITE ( 81, CROSS )
377
378!
379!-- Increase counter by the number of profiles written in the actual block
380    klist_x = klist_x + n_sp_x
381
382!
383!-- Write end-mark
384    WRITE ( 82, 103 )
385
386!
387!-- Close parameter- and data-file
388    CALL close_file( 81 )
389    CALL close_file( 82 )
390
391!
392!-- Formats
393100 FORMAT (A,I1,1X,A,1X,I4,'m ',A)
394101 FORMAT (A,I2,1X,A,1X,I4,'m ',A)
395102 FORMAT (E15.7,10(1X,E15.7))
396103 FORMAT ('NEXT')
397104 FORMAT ('time averaged over',F7.1,' s')
398
399 END SUBROUTINE data_output_spectra_x
400
401
402 SUBROUTINE data_output_spectra_y( m, cranz, pr, frame_written )
403
404    USE arrays_3d
405    USE constants
406    USE control_parameters
407    USE grid_variables
408    USE indices
409    USE pegrid
410    USE singleton
411    USE spectrum
412    USE statistics
413    USE transpose_indices
414
415    IMPLICIT NONE
416
417    CHARACTER (LEN=30) ::  atext
418    INTEGER            :: i, j, k, m, pr
419    LOGICAL            :: frame_written
420    REAL               :: frequency = 0.0
421
422!
423!-- Variables needed for PROFIL-namelist
424    INTEGER                  :: cranz, labforx = 3, labfory = 3, legpos = 3, &
425                                timodex = 1
426    INTEGER, DIMENSION(1:10) :: cucol = 1, klist = 999999, lstyle = 0
427    LOGICAL                  :: datleg = .TRUE., grid = .TRUE., &
428                                lclose = .TRUE., rand = .TRUE., &
429                                swap = .TRUE., twoxa = .TRUE.,  &
430                                xlog = .TRUE., ylog = .TRUE.
431    CHARACTER (LEN=80)       :: rtext, utext, xtext = 'k in m>->1', ytext
432    REAL                     :: gwid = 0.1, rlegfak = 0.7, uxmin, uxmax, &
433                                uymin, uymax
434    REAL, DIMENSION(1:10)    :: lwid = 0.6
435    REAL, DIMENSION(10)      :: uyma, uymi
436
437    NAMELIST /RAHMEN/  cranz, datleg, rtext, swap
438    NAMELIST /CROSS/   rand, cucol, grid, gwid, klist, labforx, labfory,      &
439                       legpos, lclose, lstyle, lwid, rlegfak, timodex, utext, &
440                       uxmin, uxmax, uymin, uymax, twoxa, xlog, xtext, ylog,  &
441                       ytext
442
443
444    rtext = '\0.5 ' // run_description_header
445
446!
447!-- Open parameter- and data-file
448    CALL check_open( 83 )
449    CALL check_open( 84 )
450
451!
452!-- Write file header,
453!-- write RAHMEN-parameters (pr=3: w-array is on zw, other arrys on zu,
454!-- pr serves as an index for output of strings (axis-labels) of the
455!-- different quantities u, v, w, pt and q)
456    DO  k = 1, n_sp_y
457       IF ( k < 10 )  THEN
458          IF ( pr == 3 ) THEN
459             WRITE ( 84, 100 )  '#', k, header_char( pr ),        &
460                                INT( zw(comp_spectra_level(k)) ), &
461                                simulated_time_chr
462          ELSE
463             WRITE ( 84, 100 )  '#', k, header_char( pr ),        &
464                                INT( zu(comp_spectra_level(k)) ), &
465                                simulated_time_chr
466          ENDIF
467       ELSE
468          IF ( pr == 3 )  THEN
469             WRITE ( 84, 101 )  '#', k, header_char( pr ),        &
470                                INT( zw(comp_spectra_level(k)) ), &
471                                simulated_time_chr
472          ELSE
473             WRITE ( 84, 101 )  '#', k, header_char( pr ),        &
474                                INT( zu(comp_spectra_level(k)) ), &
475                                simulated_time_chr
476          ENDIF
477       ENDIF
478    ENDDO
479
480    IF ( .NOT. frame_written )  THEN
481       WRITE ( 83, RAHMEN )
482       frame_written = .TRUE.
483    ENDIF
484
485!
486!-- Write all data and calculate uymi and uyma. They serve to calculate
487!-- the CROSS-parameters uymin and uymax
488    uymi = 999.999; uyma = -999.999
489    DO  j = 1, ny/2
490       frequency = 2.0 * pi * j / ( dy * ( ny + 1 ) )
491       WRITE ( 84, 102 ) frequency, ( frequency * spectrum_y(j,k,m), &
492                                      k = 1, n_sp_y ) 
493       DO k = 1, n_sp_y
494          uymi(k) = MIN( uymi(k), frequency * spectrum_y(j,k,m) )
495          uyma(k) = MAX( uyma(k), frequency * spectrum_y(j,k,m) )
496       ENDDO
497    ENDDO
498
499!
500!-- Determine CROSS-parameters
501    cucol(1:n_sp_y)  = (/ ( k, k = 1, n_sp_y ) /)
502    lstyle(1:n_sp_y) = (/ ( lstyles(k), k = 1, n_sp_y ) /)
503
504!
505!-- Calculate klist-values from the available comp_spectra_level values
506    j = 1; k = 1
507    DO WHILE ( j <= 10  .AND.  plot_spectra_level(j) /= 999999 )
508       DO WHILE ( k <= n_sp_y  .AND. &
509                  plot_spectra_level(j) >= comp_spectra_level(k) )
510          IF ( plot_spectra_level(j) == comp_spectra_level(k) )  THEN
511             klist(j) = k + klist_y
512          ELSE
513             uymi(k) =  999.999
514             uyma(k) = -999.999
515          ENDIF
516          k = k + 1
517       ENDDO
518       j = j + 1
519    ENDDO
520    uymi(k:n_sp_y) =  999.999
521    uyma(k:n_sp_y) = -999.999
522    utext = 'y'//utext_char( pr )
523    IF ( averaging_interval_sp /= 0.0 )  THEN
524       WRITE ( atext, 104 )  averaging_interval_sp
525       utext = TRIM(utext) // ',  ' // TRIM( atext )
526    ENDIF
527    uxmin = 0.8 * 2.0 * pi        / ( dy * ( ny + 1 ) )
528    uxmax = 1.2 * 2.0 * pi * ny/2 / ( dy * ( ny + 1 ) )
529    uymin = 0.8 * MIN (  999.999, MINVAL ( uymi ) )
530    uymax = 1.2 * MAX ( -999.999, MAXVAL ( uyma ) )
531    ytext = ytext_char( pr )
532
533!
534!-- Output CROSS-parameters
535    WRITE ( 83, CROSS )
536
537!
538!-- Increase counter by the number of profiles written in the actual block
539    klist_y = klist_y + n_sp_y
540
541!
542!-- Write end-mark
543    WRITE ( 84, 103 ) 
544
545!
546!-- Close parameter- and data-file
547    CALL close_file( 83 )
548    CALL close_file( 84 )
549
550!
551!-- Formats
552100 FORMAT (A,I1,1X,A,1X,I4,'m ',A)
553101 FORMAT (A,I2,1X,A,1X,I4,'m ',A)
554102 FORMAT (E15.7,10(1X,E15.7))
555103 FORMAT ('NEXT')
556104 FORMAT ('time averaged over',F7.1,' s')
557
558 END SUBROUTINE data_output_spectra_y
559#endif
Note: See TracBrowser for help on using the repository browser.