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

Last change on this file since 3245 was 3241, checked in by raasch, 6 years ago

various changes to avoid compiler warnings (mainly removal of unused variables)

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