1 | !> @file src/inifor.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 2017-2021 Leibniz Universitaet Hannover |
---|
18 | ! Copyright 2017-2021 Deutscher Wetterdienst Offenbach |
---|
19 | !------------------------------------------------------------------------------! |
---|
20 | ! |
---|
21 | ! Current revisions: |
---|
22 | ! ----------------- |
---|
23 | ! |
---|
24 | ! |
---|
25 | ! Former revisions: |
---|
26 | ! ----------------- |
---|
27 | ! $Id: inifor.f90 4843 2021-01-15 15:22:11Z raasch $ |
---|
28 | ! Improved variable naming and code readabilty |
---|
29 | ! |
---|
30 | ! |
---|
31 | ! 4675 2020-09-11 10:00:26Z eckhard |
---|
32 | ! Support for soil profile initialization |
---|
33 | ! Improved code formatting |
---|
34 | ! |
---|
35 | ! |
---|
36 | ! 4659 2020-08-31 11:21:17Z eckhard |
---|
37 | ! List all warnings after successful run |
---|
38 | ! Only define netCDF variables in enabled IO groups |
---|
39 | ! |
---|
40 | ! |
---|
41 | ! 4523 2020-05-07 15:58:16Z eckhard |
---|
42 | ! respect integer working precision (iwp) specified in inifor_defs.f90 |
---|
43 | ! |
---|
44 | ! |
---|
45 | ! 4481 2020-03-31 18:55:54Z maronga |
---|
46 | ! Alert user to warnings if any |
---|
47 | ! |
---|
48 | ! |
---|
49 | ! 3866 2019-04-05 14:25:01Z eckhard |
---|
50 | ! Use PALM's working precision |
---|
51 | ! Show error message if compiled without netCDF support |
---|
52 | ! Renamed run_control -> log_runtime |
---|
53 | ! Improved coding style added comments |
---|
54 | ! |
---|
55 | ! |
---|
56 | ! 3785 2019-03-06 10:41:14Z eckhard |
---|
57 | ! Average geostrophic wind components on coarse COSMO levels instead of fine PALM levels |
---|
58 | ! Remove --debug netCDF output of internal pressure profiles |
---|
59 | ! |
---|
60 | ! 3680 2019-01-18 14:54:12Z knoop |
---|
61 | ! Prefixed all INIFOR modules with inifor_ |
---|
62 | ! |
---|
63 | ! |
---|
64 | ! 3615 2018-12-10 07:21:03Z raasch |
---|
65 | ! bugfix: abort replaced by inifor_abort |
---|
66 | ! |
---|
67 | ! 3613 2018-12-07 18:20:37Z eckhard |
---|
68 | ! Moved version output to setup_parameters() |
---|
69 | ! |
---|
70 | ! 3557 2018-11-22 16:01:22Z eckhard |
---|
71 | ! Updated documentation |
---|
72 | ! |
---|
73 | ! 3537 2018-11-20 10:53:14Z eckhard |
---|
74 | ! Print version number on program start |
---|
75 | ! |
---|
76 | ! |
---|
77 | ! 3456 2018-10-30 14:29:54Z eckhard |
---|
78 | ! NetCDf output of internal arrays only with --debug option |
---|
79 | ! |
---|
80 | ! |
---|
81 | ! 3401 2018-10-23 09:33:31Z eckhard |
---|
82 | ! Re-compute geostrophic winds every time step |
---|
83 | ! |
---|
84 | ! 3395 2018-10-22 17:32:49Z eckhard |
---|
85 | ! Added main loop support for computation of geostrophic winds and surface |
---|
86 | ! pressure |
---|
87 | ! Cleaned up terminal output, show some messages only with --debug option |
---|
88 | ! |
---|
89 | ! 3183 2018-07-27 14:25:55Z suehring |
---|
90 | ! Introduced new PALM grid stretching |
---|
91 | ! Renamend initial-condition mode variable 'mode' to 'ic_mode' |
---|
92 | ! Improved log messages |
---|
93 | ! |
---|
94 | ! |
---|
95 | ! 3182 2018-07-27 13:36:03Z suehring |
---|
96 | ! Initial revision |
---|
97 | ! |
---|
98 | ! |
---|
99 | ! |
---|
100 | ! Authors: |
---|
101 | ! -------- |
---|
102 | !> @author Eckhard Kadasch, (Deutscher Wetterdienst, Offenbach) |
---|
103 | ! |
---|
104 | ! Description: |
---|
105 | ! ------------ |
---|
106 | !> INIFOR is an interpolation tool for generating meteorological initialization |
---|
107 | !> and forcing data for the urban climate model PALM-4U. The required |
---|
108 | !> meteorological fields are interpolated from output data of the mesoscale |
---|
109 | !> model COSMO. This is the main program file. |
---|
110 | !------------------------------------------------------------------------------! |
---|
111 | PROGRAM inifor |
---|
112 | |
---|
113 | #if defined ( __netcdf ) |
---|
114 | |
---|
115 | USE inifor_control |
---|
116 | USE inifor_defs |
---|
117 | USE inifor_grid, & |
---|
118 | ONLY: averaging_width_ns, & |
---|
119 | averaging_width_ew, & |
---|
120 | cfg, & |
---|
121 | cosmo_grid, & |
---|
122 | f3, & |
---|
123 | fini_grids, & |
---|
124 | fini_io_groups, & |
---|
125 | fini_variables, & |
---|
126 | fini_file_lists, & |
---|
127 | io_group_list, & |
---|
128 | lam_centre, & |
---|
129 | lambda_n, & |
---|
130 | nx, ny, nz, & |
---|
131 | origin_lat, & |
---|
132 | origin_lon, & |
---|
133 | output_file, & |
---|
134 | p0, & |
---|
135 | phi_centre, & |
---|
136 | phi_n, & |
---|
137 | preprocess, & |
---|
138 | palm_grid, & |
---|
139 | setup_grids, & |
---|
140 | setup_parameters, & |
---|
141 | setup_variable_tables, & |
---|
142 | setup_io_groups |
---|
143 | USE inifor_io |
---|
144 | USE inifor_transform, & |
---|
145 | ONLY: average_pressure_perturbation, & |
---|
146 | average_profile, & |
---|
147 | geostrophic_winds, & |
---|
148 | get_surface_pressure, & |
---|
149 | interp_average_profile, & |
---|
150 | interpolate_1d, & |
---|
151 | interpolate_1d_arr, & |
---|
152 | interpolate_2d, & |
---|
153 | interpolate_3d |
---|
154 | USE inifor_types |
---|
155 | |
---|
156 | IMPLICIT NONE |
---|
157 | |
---|
158 | INTEGER(iwp) :: igroup !< loop index for IO groups |
---|
159 | INTEGER(iwp) :: ivar !< loop index for output variables |
---|
160 | INTEGER(iwp) :: iter !< loop index for time steps |
---|
161 | |
---|
162 | REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: output_arr !< array buffer for interpolated quantities |
---|
163 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: rho_centre_cosmo !< density profile of the centre averaging domain |
---|
164 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: ug_cosmo !< profile of the geostrophic wind in x direction on COSMO levels |
---|
165 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: vg_cosmo !< profile of the geostrophic wind in y direction on COSMO levels |
---|
166 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: ug_palm !< profile of the geostrophic wind in x direction interpolated onto PALM levels |
---|
167 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: vg_palm !< profile of the geostrophic wind in y direction interpolated onto PALM levels |
---|
168 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: rho_north_cosmo !< density profile of the northern averaging domain |
---|
169 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: rho_south_cosmo !< density profile of the southern averaging domain |
---|
170 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: rho_east_cosmo !< density profile of the eastern averaging domain |
---|
171 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: rho_west_cosmo !< density profile of the western averaging domain |
---|
172 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: p_north_cosmo !< pressure profile of the northern averaging domain |
---|
173 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: p_south_cosmo !< pressure profile of the southern averaging domain |
---|
174 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: p_east_cosmo !< pressure profile of the eastern averaging domain |
---|
175 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: p_west_cosmo !< pressure profile of the western averaging domain |
---|
176 | |
---|
177 | REAL(wp), POINTER, DIMENSION(:) :: internal_cosmo_arr !< pointer to the currently processed internal array (density, pressure) |
---|
178 | REAL(wp), POINTER, DIMENSION(:) :: ug_vg_palm !< pointer to the currently processed geostrophic wind component |
---|
179 | |
---|
180 | TYPE(nc_var), POINTER :: output_var !< pointer to the currently processed output variable |
---|
181 | TYPE(io_group), POINTER :: group !< pointer to the currently processed IO group |
---|
182 | TYPE(container), ALLOCATABLE :: input_buffer(:) !< buffer of the current IO group's input arrays |
---|
183 | |
---|
184 | LOGICAL, SAVE :: ug_vg_have_been_computed = .FALSE. !< flag for managing geostrophic wind allocation and computation |
---|
185 | !LOGICAL, SAVE :: debugging_output = .TRUE. !< flag controllging output of internal variables |
---|
186 | |
---|
187 | !> \mainpage About INIFOR |
---|
188 | !> ... |
---|
189 | ! |
---|
190 | !------------------------------------------------------------------------------ |
---|
191 | !- Section 1: Initialization |
---|
192 | !------------------------------------------------------------------------------ |
---|
193 | CALL log_runtime( 'init', 'void' ) |
---|
194 | |
---|
195 | ! |
---|
196 | !-- Initialize INIFOR's parameters from command-line interface and namelists |
---|
197 | CALL setup_parameters |
---|
198 | |
---|
199 | ! |
---|
200 | !-- Initialize all grids, including interpolation neighbours and weights |
---|
201 | CALL setup_grids |
---|
202 | CALL log_runtime( 'time', 'init' ) |
---|
203 | |
---|
204 | ! |
---|
205 | !-- Initialize the netCDF output file and define dimensions |
---|
206 | CALL setup_netcdf_dimensions( output_file, palm_grid, cfg%start_date, & |
---|
207 | origin_lon, origin_lat ) |
---|
208 | CALL log_runtime( 'time', 'write' ) |
---|
209 | |
---|
210 | ! |
---|
211 | !-- Set up the tables containing the input and output variables and set |
---|
212 | !-- the corresponding netCDF dimensions for each output variable |
---|
213 | CALL setup_variable_tables |
---|
214 | CALL setup_io_groups |
---|
215 | CALL log_runtime( 'time', 'init' ) |
---|
216 | ! |
---|
217 | !-- Add the output variables to the netCDF output file |
---|
218 | CALL setup_netcdf_variables( output_file%name, io_group_list) |
---|
219 | CALL log_runtime( 'time', 'write' ) |
---|
220 | |
---|
221 | !------------------------------------------------------------------------------ |
---|
222 | !-- Section 2: Main loop |
---|
223 | !------------------------------------------------------------------------------ |
---|
224 | ! |
---|
225 | !-- Input and output variables are organized into IO groups. For instance, the |
---|
226 | !-- 'thermodynamics' IO group bundles the input variaebls T, P, QV and the |
---|
227 | !-- output variables p, theta, rho, and qv. |
---|
228 | !-- An IO group bunldes variables that are physically dependent on each other. |
---|
229 | !-- In case of the 'thermodynamics' group, theta = f(P,T), rho = f(P,T,QV). |
---|
230 | DO igroup = 1, SIZE( io_group_list ) |
---|
231 | |
---|
232 | group => io_group_list(igroup) |
---|
233 | IF ( group%to_be_processed ) THEN |
---|
234 | |
---|
235 | !-- Loop over all output time steps for the current group. |
---|
236 | DO iter = 1, group%nt |
---|
237 | |
---|
238 | !------------------------------------------------------------------------------ |
---|
239 | !-- Section 2.1: Read and preprocess input data |
---|
240 | !------------------------------------------------------------------------------ |
---|
241 | CALL read_input_variables( group, iter, input_buffer ) |
---|
242 | CALL log_runtime( 'time', 'read' ) |
---|
243 | |
---|
244 | !-- Carry out all required physical conversion of the input variables |
---|
245 | !-- of the current IO group on the input (COSMO) grid. For instance, |
---|
246 | !-- horizontal velocities are rotated to the PALM coordinate system and |
---|
247 | !-- potential temperature is computed from the absolute temperature and |
---|
248 | !-- pressure. |
---|
249 | CALL preprocess( group, input_buffer, cosmo_grid ) |
---|
250 | CALL log_runtime( 'time', 'comp' ) |
---|
251 | |
---|
252 | !TODO: move this assertion into 'preprocess'. |
---|
253 | IF ( .NOT. ALL(input_buffer(:)%is_preprocessed .AND. .TRUE.) ) THEN |
---|
254 | message = "Input buffers for group '" // TRIM( group%kind ) // & |
---|
255 | "' could not be preprocessed sucessfully." |
---|
256 | CALL inifor_abort( 'main loop', message ) |
---|
257 | ENDIF |
---|
258 | |
---|
259 | !------------------------------------------------------------------------------ |
---|
260 | !-- Section 2.2: Interpolate each output variable of the group |
---|
261 | !------------------------------------------------------------------------------ |
---|
262 | DO ivar = 1, group%nv |
---|
263 | |
---|
264 | output_var => group%out_vars(ivar) |
---|
265 | |
---|
266 | IF ( output_var%to_be_processed .AND. & |
---|
267 | iter .LE. output_var%nt ) THEN |
---|
268 | |
---|
269 | message = "Processing '" // TRIM( output_var%name ) // & |
---|
270 | "' (" // TRIM( output_var%kind ) // & |
---|
271 | "), iteration " // TRIM( str( iter ) ) //" of " //& |
---|
272 | TRIM( str( output_var%nt ) ) |
---|
273 | CALL report( 'main loop', message ) |
---|
274 | |
---|
275 | SELECT CASE( TRIM( output_var%task ) ) |
---|
276 | |
---|
277 | !-- 2D horizontal interpolation |
---|
278 | CASE( 'interpolate_2d' ) |
---|
279 | |
---|
280 | SELECT CASE( TRIM( output_var%kind ) ) |
---|
281 | |
---|
282 | CASE( 'init soil' ) |
---|
283 | |
---|
284 | ALLOCATE( output_arr(0:output_var%grid%nx, & |
---|
285 | 0:output_var%grid%ny, & |
---|
286 | SIZE( output_var%grid%depths )) ) |
---|
287 | |
---|
288 | CASE ( 'surface forcing' ) |
---|
289 | |
---|
290 | ALLOCATE( output_arr(0:output_var%grid%nx, & |
---|
291 | 0:output_var%grid%ny, 1) ) |
---|
292 | |
---|
293 | CASE DEFAULT |
---|
294 | |
---|
295 | message = "'" // TRIM( output_var%kind ) // "' is not a soil variable" |
---|
296 | CALL inifor_abort( "main loop", message ) |
---|
297 | |
---|
298 | END SELECT |
---|
299 | CALL log_runtime( 'time', 'alloc' ) |
---|
300 | |
---|
301 | CALL interpolate_2d( input_buffer(output_var%input_id)%array(:,:,:), & |
---|
302 | output_arr(:,:,:), output_var%intermediate_grid, output_var ) |
---|
303 | CALL log_runtime( 'time', 'comp' ) |
---|
304 | |
---|
305 | |
---|
306 | !-- Interpolation in 3D, used for atmospheric initial and |
---|
307 | !-- boundary conditions. |
---|
308 | CASE ( 'interpolate_3d' ) |
---|
309 | |
---|
310 | ALLOCATE( output_arr(0:output_var%grid % nx, & |
---|
311 | 0:output_var%grid % ny, & |
---|
312 | 1:output_var%grid % nz) ) |
---|
313 | |
---|
314 | CALL log_runtime( 'time', 'alloc' ) |
---|
315 | CALL interpolate_3d( & |
---|
316 | input_buffer(output_var%input_id)%array(:,:,:), & |
---|
317 | output_arr(:,:,:), & |
---|
318 | output_var%intermediate_grid, & |
---|
319 | output_var%grid) |
---|
320 | CALL log_runtime( 'time', 'comp' ) |
---|
321 | |
---|
322 | !-- Compute initial avaerage profiles (if --init-mode profile |
---|
323 | !-- is used) |
---|
324 | CASE ( 'average profile' ) |
---|
325 | |
---|
326 | ALLOCATE( output_arr(0:0, 0:0, 1:output_var%averaging_grid%nz) ) |
---|
327 | CALL log_runtime( 'time', 'alloc' ) |
---|
328 | CALL interp_average_profile( & |
---|
329 | input_buffer(output_var%input_id)%array(:,:,:), & |
---|
330 | output_arr(0,0,:), & |
---|
331 | output_var%averaging_grid ) |
---|
332 | |
---|
333 | IF ( TRIM( output_var%name ) == & |
---|
334 | 'surface_forcing_surface_pressure' ) THEN |
---|
335 | |
---|
336 | IF ( cfg%p0_is_set ) THEN |
---|
337 | output_arr(0,0,1) = p0 |
---|
338 | ELSE |
---|
339 | CALL get_surface_pressure( & |
---|
340 | output_arr(0,0,:), & |
---|
341 | rho_centre_cosmo, & |
---|
342 | output_var%averaging_grid ) |
---|
343 | ENDIF |
---|
344 | |
---|
345 | ENDIF |
---|
346 | CALL log_runtime( 'time', 'comp' ) |
---|
347 | |
---|
348 | CASE ( 'average levels' ) |
---|
349 | |
---|
350 | ALLOCATE( output_arr(0:0, 0:0, 1:output_var%averaging_grid%nz) ) |
---|
351 | CALL log_runtime( 'time', 'alloc' ) |
---|
352 | CALL average_profile( & |
---|
353 | input_buffer(output_var%input_id)%array(:,:,:), & |
---|
354 | output_arr(0,0,:), & |
---|
355 | output_var%averaging_grid & |
---|
356 | ) |
---|
357 | CALL log_runtime( 'time', 'comp' ) |
---|
358 | |
---|
359 | !-- Compute internal profiles, required for differentiation of |
---|
360 | !-- geostrophic wind |
---|
361 | CASE ( 'internal profile' ) |
---|
362 | |
---|
363 | message = "Averaging of internal profile for variable '" //& |
---|
364 | TRIM( output_var%name ) // "' is not supported." |
---|
365 | |
---|
366 | SELECT CASE ( TRIM( output_var%name ) ) |
---|
367 | |
---|
368 | CASE( 'internal_density_centre' ) |
---|
369 | ALLOCATE( rho_centre_cosmo(1:cosmo_grid%nz) ) |
---|
370 | internal_cosmo_arr => rho_centre_cosmo |
---|
371 | |
---|
372 | CASE( 'internal_density_north' ) |
---|
373 | ALLOCATE( rho_north_cosmo(1:cosmo_grid%nz) ) |
---|
374 | internal_cosmo_arr => rho_north_cosmo |
---|
375 | |
---|
376 | CASE( 'internal_density_south' ) |
---|
377 | ALLOCATE( rho_south_cosmo(1:cosmo_grid%nz) ) |
---|
378 | internal_cosmo_arr => rho_south_cosmo |
---|
379 | |
---|
380 | CASE( 'internal_density_east' ) |
---|
381 | ALLOCATE( rho_east_cosmo(1:cosmo_grid%nz) ) |
---|
382 | internal_cosmo_arr => rho_east_cosmo |
---|
383 | |
---|
384 | CASE( 'internal_density_west' ) |
---|
385 | ALLOCATE( rho_west_cosmo(1:cosmo_grid%nz) ) |
---|
386 | internal_cosmo_arr => rho_west_cosmo |
---|
387 | |
---|
388 | CASE( 'internal_pressure_north' ) |
---|
389 | ALLOCATE( p_north_cosmo(1:cosmo_grid%nz) ) |
---|
390 | internal_cosmo_arr => p_north_cosmo |
---|
391 | |
---|
392 | CASE( 'internal_pressure_south' ) |
---|
393 | ALLOCATE( p_south_cosmo(1:cosmo_grid%nz) ) |
---|
394 | internal_cosmo_arr => p_south_cosmo |
---|
395 | |
---|
396 | CASE( 'internal_pressure_east' ) |
---|
397 | ALLOCATE( p_east_cosmo(1:cosmo_grid%nz) ) |
---|
398 | internal_cosmo_arr => p_east_cosmo |
---|
399 | |
---|
400 | CASE( 'internal_pressure_west' ) |
---|
401 | ALLOCATE( p_west_cosmo(1:cosmo_grid%nz) ) |
---|
402 | internal_cosmo_arr => p_west_cosmo |
---|
403 | |
---|
404 | CASE DEFAULT |
---|
405 | CALL inifor_abort( 'main loop', message ) |
---|
406 | |
---|
407 | END SELECT |
---|
408 | CALL log_runtime( 'time', 'alloc' ) |
---|
409 | |
---|
410 | |
---|
411 | SELECT CASE( TRIM( output_var%name ) ) |
---|
412 | |
---|
413 | CASE( 'internal_pressure_north', & |
---|
414 | 'internal_pressure_south', & |
---|
415 | 'internal_pressure_east', & |
---|
416 | 'internal_pressure_west' ) |
---|
417 | |
---|
418 | CALL average_pressure_perturbation( & |
---|
419 | input_buffer(output_var%input_id)%array(:,:,:), & |
---|
420 | internal_cosmo_arr(:), & |
---|
421 | cosmo_grid, output_var%averaging_grid & |
---|
422 | ) |
---|
423 | |
---|
424 | CASE DEFAULT |
---|
425 | |
---|
426 | CALL average_profile( & |
---|
427 | input_buffer(output_var%input_id)%array(:,:,:), & |
---|
428 | internal_cosmo_arr(:), & |
---|
429 | output_var%averaging_grid & |
---|
430 | ) |
---|
431 | |
---|
432 | END SELECT |
---|
433 | |
---|
434 | CALL log_runtime( 'time', 'comp' ) |
---|
435 | |
---|
436 | ! |
---|
437 | !-- This case gets called twice, the first time for ug, the |
---|
438 | !-- second time for vg. We compute ug and vg at the first call |
---|
439 | !-- and keep both of them around for the second call. |
---|
440 | CASE ( 'geostrophic winds' ) |
---|
441 | |
---|
442 | IF (.NOT. ug_vg_have_been_computed ) THEN |
---|
443 | ALLOCATE( ug_palm(output_var%grid%nz) ) |
---|
444 | ALLOCATE( vg_palm(output_var%grid%nz) ) |
---|
445 | ALLOCATE( ug_cosmo(cosmo_grid%nz) ) |
---|
446 | ALLOCATE( vg_cosmo(cosmo_grid%nz) ) |
---|
447 | |
---|
448 | IF ( cfg%ug_defined_by_user ) THEN |
---|
449 | ug_palm = cfg%ug |
---|
450 | vg_palm = cfg%vg |
---|
451 | ELSE |
---|
452 | CALL geostrophic_winds( & |
---|
453 | p_north_cosmo, p_south_cosmo, p_east_cosmo, & |
---|
454 | p_west_cosmo, rho_centre_cosmo, f3, & |
---|
455 | averaging_width_ew, & |
---|
456 | averaging_width_ns, & |
---|
457 | phi_n, lambda_n, & |
---|
458 | phi_centre, lam_centre, & |
---|
459 | ug_cosmo, vg_cosmo & |
---|
460 | ) |
---|
461 | |
---|
462 | CALL interpolate_1d( ug_cosmo, ug_palm, & |
---|
463 | output_var%grid ) |
---|
464 | |
---|
465 | CALL interpolate_1d( vg_cosmo, vg_palm, & |
---|
466 | output_var%grid ) |
---|
467 | ENDIF |
---|
468 | |
---|
469 | ug_vg_have_been_computed = .TRUE. |
---|
470 | |
---|
471 | ENDIF |
---|
472 | |
---|
473 | ! |
---|
474 | !-- Select output array of current geostrophic wind component |
---|
475 | SELECT CASE( TRIM( output_var%name ) ) |
---|
476 | CASE ( 'ls_forcing_ug' ) |
---|
477 | ug_vg_palm => ug_palm |
---|
478 | CASE ( 'ls_forcing_vg' ) |
---|
479 | ug_vg_palm => vg_palm |
---|
480 | END SELECT |
---|
481 | |
---|
482 | ALLOCATE( output_arr(1,1,output_var%grid%nz) ) |
---|
483 | output_arr(1,1,:) = ug_vg_palm(:) |
---|
484 | |
---|
485 | !-- User defined constant profiles |
---|
486 | CASE ( 'set profile' ) |
---|
487 | |
---|
488 | ALLOCATE( output_arr(1,1,1:nz) ) |
---|
489 | CALL log_runtime( 'time', 'alloc' ) |
---|
490 | |
---|
491 | SELECT CASE ( TRIM( output_var%name ) ) |
---|
492 | |
---|
493 | CASE ( 'nudging_tau' ) |
---|
494 | output_arr(1, 1, :) = NUDGING_TAU |
---|
495 | |
---|
496 | CASE DEFAULT |
---|
497 | message = "'" // TRIM( output_var%name ) // & |
---|
498 | "' is not a valid '" // TRIM( output_var%kind ) //& |
---|
499 | "' variable kind." |
---|
500 | CALL inifor_abort( 'main loop', message ) |
---|
501 | END SELECT |
---|
502 | CALL log_runtime( 'time', 'comp' ) |
---|
503 | |
---|
504 | CASE DEFAULT |
---|
505 | message = "Processing task '" // TRIM( output_var%task ) //& |
---|
506 | "' not recognized." |
---|
507 | CALL inifor_abort( '', message ) |
---|
508 | |
---|
509 | END SELECT |
---|
510 | CALL log_runtime( 'time', 'comp' ) |
---|
511 | |
---|
512 | !------------------------------------------------------------------------------ |
---|
513 | !- Section 2.3: Write current time step of current variable |
---|
514 | !------------------------------------------------------------------------------ |
---|
515 | ! |
---|
516 | !-- Output of geostrophic pressure profiles (with --debug |
---|
517 | !-- option) is currently deactivated, since they are now |
---|
518 | !-- defined on averaged COSMO levels instead of PALM levels |
---|
519 | !-- (requires definiton of COSMO levels in netCDF output.) |
---|
520 | !IF (.NOT. output_var%is_internal .OR. debugging_output) THEN |
---|
521 | |
---|
522 | IF ( .NOT. output_var%is_internal ) THEN |
---|
523 | message = "Writing variable '" // TRIM( output_var%name ) // "'." |
---|
524 | CALL report( 'main loop', message ) |
---|
525 | CALL update_output( output_var, output_arr, iter, & |
---|
526 | output_file, cfg ) |
---|
527 | CALL log_runtime( 'time', 'write' ) |
---|
528 | ENDIF |
---|
529 | |
---|
530 | IF ( ALLOCATED( output_arr ) ) DEALLOCATE( output_arr ) |
---|
531 | CALL log_runtime( 'time', 'alloc' ) |
---|
532 | |
---|
533 | ENDIF |
---|
534 | |
---|
535 | ! |
---|
536 | !-- output variable loop |
---|
537 | ENDDO |
---|
538 | |
---|
539 | ug_vg_have_been_computed = .FALSE. |
---|
540 | IF ( group%kind == 'thermodynamics' ) THEN |
---|
541 | DEALLOCATE( rho_centre_cosmo ) |
---|
542 | DEALLOCATE( ug_palm ) |
---|
543 | DEALLOCATE( vg_palm ) |
---|
544 | DEALLOCATE( ug_cosmo ) |
---|
545 | DEALLOCATE( vg_cosmo ) |
---|
546 | IF ( .NOT. cfg%ug_defined_by_user ) THEN |
---|
547 | DEALLOCATE( rho_north_cosmo ) |
---|
548 | DEALLOCATE( rho_south_cosmo ) |
---|
549 | DEALLOCATE( rho_east_cosmo ) |
---|
550 | DEALLOCATE( rho_west_cosmo ) |
---|
551 | DEALLOCATE( p_north_cosmo ) |
---|
552 | DEALLOCATE( p_south_cosmo ) |
---|
553 | DEALLOCATE( p_east_cosmo ) |
---|
554 | DEALLOCATE( p_west_cosmo ) |
---|
555 | ENDIF |
---|
556 | ENDIF |
---|
557 | |
---|
558 | ! |
---|
559 | !-- Keep input buffer around for averaged (radiation) and |
---|
560 | !-- accumulated COSMO quantities (precipitation). |
---|
561 | IF ( group%kind == 'running average' .OR. & |
---|
562 | group%kind == 'accumulated' ) THEN |
---|
563 | ELSE |
---|
564 | CALL report( 'main loop', 'Deallocating input buffer', cfg%debug ) |
---|
565 | DEALLOCATE( input_buffer ) |
---|
566 | ENDIF |
---|
567 | CALL log_runtime( 'time', 'alloc' ) |
---|
568 | |
---|
569 | ! |
---|
570 | !-- time steps / input files loop |
---|
571 | ENDDO |
---|
572 | |
---|
573 | IF ( ALLOCATED( input_buffer ) ) THEN |
---|
574 | CALL report( 'main loop', 'Deallocating input buffer', cfg%debug ) |
---|
575 | DEALLOCATE( input_buffer ) |
---|
576 | ENDIF |
---|
577 | CALL log_runtime( 'time', 'alloc' ) |
---|
578 | |
---|
579 | ELSE |
---|
580 | |
---|
581 | message = "Skipping IO group " // TRIM( str( igroup ) ) // " '" // TRIM( group%kind ) // "'" |
---|
582 | IF ( ALLOCATED( group%in_var_list ) ) THEN |
---|
583 | message = TRIM( message ) // " with input variable '" // & |
---|
584 | TRIM( group%in_var_list(1)%name ) // "'." |
---|
585 | ENDIF |
---|
586 | |
---|
587 | CALL report( 'main loop', message, cfg%debug ) |
---|
588 | |
---|
589 | ! |
---|
590 | !-- IO group%to_be_processed conditional |
---|
591 | ENDIF |
---|
592 | |
---|
593 | ! |
---|
594 | !-- IO groups loop |
---|
595 | ENDDO |
---|
596 | |
---|
597 | !------------------------------------------------------------------------------ |
---|
598 | !- Section 3: Clean up. |
---|
599 | !------------------------------------------------------------------------------ |
---|
600 | CALL fini_file_lists |
---|
601 | CALL fini_io_groups |
---|
602 | CALL fini_variables |
---|
603 | !CALL fini_grids |
---|
604 | CALL log_runtime( 'time', 'alloc' ) |
---|
605 | |
---|
606 | CALL report_warnings |
---|
607 | CALL report_success( output_file%name ) |
---|
608 | CALL report_runtime |
---|
609 | CALL close_log |
---|
610 | |
---|
611 | #else |
---|
612 | |
---|
613 | USE inifor_control |
---|
614 | IMPLICIT NONE |
---|
615 | |
---|
616 | message = "INIFOR was compiled without netCDF support, which is required for it to run. " // & |
---|
617 | "To use INIFOR, recompile PALM with netCDF support by adding the -D__netcdf " // & |
---|
618 | "precompiler flag to your .palm.config file." |
---|
619 | CALL inifor_abort( 'main loop', message ) |
---|
620 | |
---|
621 | #endif |
---|
622 | |
---|
623 | END PROGRAM inifor |
---|