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

Last change on this file since 1833 was 1833, checked in by raasch, 5 years ago

spectrum renamed spactra_par and further modularized, POINTER-attributes added in coupler-routines to avoid gfortran error messages

  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1!> @file data_output_spectra.f90
2!--------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
16! Copyright 1997-2016 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! ------------------
21! spectrum renamed spectra_mod, spectra related variables moved to spectra_mod,
22! routines data_output_spectra_x/y removed
23!
24! Former revisions:
25! -----------------
26! $Id: data_output_spectra.f90 1833 2016-04-07 14:23:03Z raasch $
27!
28! 1786 2016-03-08 05:49:27Z raasch
29! cpp-directives for spectra removed, immediate return if no spectra levels are
30! given
31!
32! 1783 2016-03-06 18:36:17Z raasch
33! name change of netcdf routines and module + related changes
34!
35! 1682 2015-10-07 23:56:08Z knoop
36! Code annotations made doxygen readable
37!
38! 1353 2014-04-08 15:21:23Z heinze
39! REAL constants provided with KIND-attribute
40!
41! 1327 2014-03-21 11:00:16Z raasch
42! -netcdf output queries
43!
44! 1324 2014-03-21 09:13:16Z suehring
45! Bugfix: module statistics and module spectrum added, missing variables in ONLY
46! arguments added
47!
48! 1322 2014-03-20 16:38:49Z raasch
49! REAL functions provided with KIND-attribute
50!
51! 1320 2014-03-20 08:40:49Z raasch
52! ONLY-attribute added to USE-statements,
53! kind-parameters added to all INTEGER and REAL declaration statements,
54! kinds are defined in new module kinds,
55! revision history before 2012 removed,
56! comment fields (!:) to be used for variable explanations added to
57! all variable declaration statements
58!
59! 1318 2014-03-17 13:35:16Z raasch
60! module interfaces removed
61!
62! 1036 2012-10-22 13:43:42Z raasch
63! code put under GPL (PALM 3.9)
64!
65! 964 2012-07-26 09:14:24Z raasch
66! code for profil-output removed
67!
68! Revision 1.1  2001/01/05 15:14:20  raasch
69! Initial revision
70!
71!
72! Description:
73! ------------
74!> Writing spectra data on file, using a special format which allows
75!> plotting of these data with PROFIL-graphic-software
76!------------------------------------------------------------------------------!
77 SUBROUTINE data_output_spectra
78 
79#if defined( __netcdf )
80    USE control_parameters,                                                    &
81        ONLY:  message_string, run_description_header,                         &
82               time_since_reference_point
83
84    USE cpulog,                                                                &
85        ONLY:  cpu_log, log_point
86
87    USE kinds
88
89    USE NETCDF
90
91    USE netcdf_interface,                                                      &
92        ONLY:  id_set_sp, id_var_time_sp, nc_stat, netcdf_handle_error
93
94    USE pegrid
95
96    USE spectra_mod,                                                           &
97        ONLY:  average_count_sp, averaging_interval_sp, comp_spectra_level,    &
98               data_output_sp, dosp_time_count, spectra_direction, spectrum_x, &
99               spectrum_y
100
101
102    IMPLICIT NONE
103
104    INTEGER(iwp) ::  cranz_x !<
105    INTEGER(iwp) ::  cranz_y !<
106    INTEGER(iwp) ::  m       !<
107    INTEGER(iwp) ::  pr      !<
108   
109    LOGICAL      ::  frame_x !<
110    LOGICAL      ::  frame_y !<
111
112    CALL cpu_log( log_point(31), 'data_output_spectra', 'start' )
113
114!
115!-- Check if user gave any levels for spectra to be calculated
116    IF ( comp_spectra_level(1) == 999999 )  RETURN
117
118!
119!-- Output is only performed on PE0
120    IF ( myid == 0 )  THEN
121
122!
123!--    Open file for spectra output in NetCDF format
124       CALL check_open( 107 )
125
126!
127!--    Increment the counter for number of output times
128       dosp_time_count = dosp_time_count + 1
129
130!
131!--    Update the spectra time axis
132       nc_stat = NF90_PUT_VAR( id_set_sp, id_var_time_sp,        &
133                               (/ time_since_reference_point /), &
134                               start = (/ dosp_time_count /), count = (/ 1 /) )
135       CALL netcdf_handle_error( 'data_output_spectra', 47 )
136
137!
138!--    If necessary, calculate time average and reset average counter
139       IF ( average_count_sp == 0 )  THEN
140           message_string = 'no spectra data available'
141           CALL message( 'data_output_spectra', 'PA0186', 0, 0, 0, 6, 0 )
142       ENDIF
143       IF ( average_count_sp /= 1 )  THEN
144          spectrum_x = spectrum_x / REAL( average_count_sp, KIND=wp )
145          spectrum_y = spectrum_y / REAL( average_count_sp, KIND=wp )
146          average_count_sp = 0
147       ENDIF
148
149!
150!--    Loop over all spectra defined by the user
151       m = 1
152       DO WHILE ( data_output_sp(m) /= ' '  .AND.  m <= 10 )
153
154          SELECT CASE ( TRIM( data_output_sp(m) ) )
155
156             CASE ( 'u' )
157                pr = 1
158
159             CASE ( 'v' )
160                pr = 2
161
162             CASE ( 'w' )
163                pr = 3
164
165             CASE ( 'pt' )
166                pr = 4
167
168             CASE ( 'q' )
169                pr = 5
170
171             CASE DEFAULT
172!
173!--             The DEFAULT case is reached either if the parameter
174!--             data_output_sp(m) contains a wrong character string or if the
175!--             user has coded a special case in the user interface. There, the
176!--             subroutine user_spectra checks which of these two conditions
177!--             applies.
178                CALL user_spectra( 'data_output', m, pr )
179
180          END SELECT
181
182!
183!--       Output of spectra in NetCDF format
184!--       Output of x-spectra
185          IF ( INDEX( spectra_direction(m), 'x' ) /= 0 ) THEN
186             CALL output_spectra_netcdf( m, 'x' )
187          ENDIF
188!
189!--       Output of y-spectra
190          IF ( INDEX( spectra_direction(m), 'y' ) /= 0 ) THEN
191             CALL output_spectra_netcdf( m, 'y' )
192          ENDIF
193
194!
195!--       Increase counter for next spectrum
196          m = m + 1
197
198       ENDDO
199
200!
201!--    Reset spectra values
202       spectrum_x = 0.0_wp; spectrum_y = 0.0_wp
203
204    ENDIF
205
206    CALL cpu_log( log_point(31), 'data_output_spectra', 'stop' )
207
208#if defined( __parallel )
209!    CALL MPI_BARRIER( comm2d, ierr )  ! really necessary
210#endif
211
212#endif
213 END SUBROUTINE data_output_spectra
214
215
216!------------------------------------------------------------------------------!
217! Description:
218! ------------
219!> @todo Missing subroutine description.
220!------------------------------------------------------------------------------!
221 SUBROUTINE output_spectra_netcdf( nsp, direction )
222#if defined( __netcdf )
223
224    USE constants,                                                             &
225        ONLY:  pi
226
227    USE grid_variables,                                                        &
228        ONLY:  dx, dy
229
230    USE indices,                                                               &
231        ONLY:  nx, ny
232
233    USE kinds
234
235    USE NETCDF
236
237    USE netcdf_interface,                                                      &
238        ONLY:  id_set_sp, id_var_dospx, id_var_dospy, nc_stat,                 &
239               netcdf_handle_error
240
241    USE spectra_mod,                                                           &
242        ONLY:  dosp_time_count, n_sp_x, n_sp_y, spectrum_x, spectrum_y
243
244
245    IMPLICIT NONE
246
247    CHARACTER (LEN=1), INTENT(IN) ::  direction     !<
248
249    INTEGER(iwp), INTENT(IN)      ::  nsp           !<
250
251    INTEGER(iwp)                  ::  i             !<
252    INTEGER(iwp)                  ::  k             !<
253
254    REAL(wp)                      ::  frequency     !<
255
256    REAL(wp), DIMENSION(nx/2)     ::  netcdf_data_x !<
257    REAL(wp), DIMENSION(ny/2)     ::  netcdf_data_y !<
258
259
260    IF ( direction == 'x' )  THEN
261
262       DO  k = 1, n_sp_x
263
264          DO  i = 1, nx/2
265             frequency = 2.0_wp * pi * i / ( dx * ( nx + 1 ) )
266             netcdf_data_x(i) = frequency * spectrum_x(i,k,nsp)
267          ENDDO
268
269          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospx(nsp), netcdf_data_x, &
270                                  start = (/ 1, k, dosp_time_count /), &
271                                  count = (/ nx/2, 1, 1 /) )
272          CALL netcdf_handle_error( 'data_output_spectra', 348 )
273
274       ENDDO
275
276    ENDIF
277
278    IF ( direction == 'y' )  THEN
279
280       DO  k = 1, n_sp_y
281
282          DO  i = 1, ny/2
283             frequency = 2.0_wp * pi * i / ( dy * ( ny + 1 ) )
284             netcdf_data_y(i) = frequency * spectrum_y(i,k,nsp)
285          ENDDO
286
287          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospy(nsp), netcdf_data_y, &
288                                  start = (/ 1, k, dosp_time_count /), &
289                                  count = (/ ny/2, 1, 1 /) )
290          CALL netcdf_handle_error( 'data_output_spectra', 349 )
291
292       ENDDO
293
294    ENDIF
295
296#endif
297 END SUBROUTINE output_spectra_netcdf
Note: See TracBrowser for help on using the repository browser.