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

Last change on this file since 2000 was 2000, checked in by knoop, 5 years ago

Forced header and separation lines into 80 columns

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