1 | !> @virtual_measurement_mod.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 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: virtual_measurement_mod.f90 3718 2019-02-06 11:08:28Z suehring $ |
---|
27 | ! Adjust variable name connections between UC2 and chemistry variables |
---|
28 | ! |
---|
29 | ! 3717 2019-02-05 17:21:16Z suehring |
---|
30 | ! Additional check + error numbers adjusted |
---|
31 | ! |
---|
32 | ! 3706 2019-01-29 20:02:26Z suehring |
---|
33 | ! unused variables removed |
---|
34 | ! |
---|
35 | ! 3705 2019-01-29 19:56:39Z suehring |
---|
36 | ! - initialization revised |
---|
37 | ! - binary data output |
---|
38 | ! - list of allowed variables extended |
---|
39 | ! |
---|
40 | ! 3704 2019-01-29 19:51:41Z suehring |
---|
41 | ! Sampling of variables |
---|
42 | ! |
---|
43 | ! 3494 2018-11-06 14:51:27Z suehring |
---|
44 | ! Bugfixing |
---|
45 | ! |
---|
46 | ! 3473 2018-10-30 20:50:15Z suehring |
---|
47 | ! Initial revision |
---|
48 | ! |
---|
49 | ! Authors: |
---|
50 | ! -------- |
---|
51 | ! @author Matthias Suehring |
---|
52 | ! |
---|
53 | ! Description: |
---|
54 | ! ------------ |
---|
55 | !> The module acts as an interface between 'real-world' observations and |
---|
56 | !> model simulations. Virtual measurements will be taken in the model at the |
---|
57 | !> coordinates representative for the 'real-world' observation coordinates. |
---|
58 | !> More precisely, coordinates and measured quanties will be read from a |
---|
59 | !> NetCDF file which contains all required information. In the model, |
---|
60 | !> the same quantities (as long as all the required components are switched-on) |
---|
61 | !> will be sampled at the respective positions and output into an extra file, |
---|
62 | !> which allows for straight-forward comparison of model results with |
---|
63 | !> observations. |
---|
64 | !> |
---|
65 | !> @todo list_of_allowed variables needs careful checking |
---|
66 | !> @todo Check if sign of surface fluxes for heat, radiation, etc., follows |
---|
67 | !> the (UC)2 standard |
---|
68 | !> @note Fluxes are not processed |
---|
69 | !------------------------------------------------------------------------------! |
---|
70 | MODULE virtual_measurement_mod |
---|
71 | |
---|
72 | USE arrays_3d, & |
---|
73 | ONLY: q, pt, u, v, w, zu, zw |
---|
74 | |
---|
75 | USE chem_modules, & |
---|
76 | ONLY: nspec |
---|
77 | |
---|
78 | USE chemistry_model_mod, & |
---|
79 | ONLY: chem_species |
---|
80 | |
---|
81 | USE control_parameters, & |
---|
82 | ONLY: air_chemistry, dz, humidity, io_blocks, io_group, neutral, & |
---|
83 | message_string, time_since_reference_point, virtual_measurement |
---|
84 | |
---|
85 | USE cpulog, & |
---|
86 | ONLY: cpu_log, log_point |
---|
87 | |
---|
88 | USE grid_variables, & |
---|
89 | ONLY: dx, dy |
---|
90 | |
---|
91 | USE indices, & |
---|
92 | ONLY: nzb, nzt, nxl, nxr, nys, nyn, nx, ny, wall_flags_0 |
---|
93 | |
---|
94 | USE kinds |
---|
95 | |
---|
96 | USE netcdf_data_input_mod, & |
---|
97 | ONLY: init_model |
---|
98 | |
---|
99 | USE pegrid |
---|
100 | |
---|
101 | USE surface_mod, & |
---|
102 | ONLY: surf_lsm_h, surf_usm_h |
---|
103 | |
---|
104 | USE land_surface_model_mod, & |
---|
105 | ONLY: nzb_soil, nzs, nzt_soil, zs, t_soil_h, m_soil_h |
---|
106 | |
---|
107 | USE radiation_model_mod |
---|
108 | |
---|
109 | USE urban_surface_mod, & |
---|
110 | ONLY: nzb_wall, nzt_wall, t_wall_h |
---|
111 | |
---|
112 | |
---|
113 | IMPLICIT NONE |
---|
114 | |
---|
115 | TYPE virt_general |
---|
116 | INTEGER(iwp) :: id_vm !< NetCDF file id for virtual measurements |
---|
117 | INTEGER(iwp) :: nvm = 0 !< number of virtual measurements |
---|
118 | END TYPE virt_general |
---|
119 | |
---|
120 | TYPE virt_mea |
---|
121 | |
---|
122 | CHARACTER(LEN=100) :: feature_type !< type of the measurement |
---|
123 | CHARACTER(LEN=100) :: filename_original !< name of the original file |
---|
124 | CHARACTER(LEN=100) :: site !< name of the measurement site |
---|
125 | |
---|
126 | CHARACTER(LEN=10), DIMENSION(:), ALLOCATABLE :: measured_vars_name !< name of the measured variables |
---|
127 | |
---|
128 | INTEGER(iwp) :: ns = 0 !< number of observation coordinates on subdomain, for atmospheric measurements |
---|
129 | INTEGER(iwp) :: ns_tot = 0 !< total number of observation coordinates, for atmospheric measurements |
---|
130 | INTEGER(iwp) :: ntraj !< number of trajectories of a measurement |
---|
131 | INTEGER(iwp) :: nvar !< number of measured variables (atmosphere + soil) |
---|
132 | |
---|
133 | INTEGER(iwp) :: ns_soil = 0 !< number of observation coordinates on subdomain, for soil measurements |
---|
134 | INTEGER(iwp) :: ns_soil_tot = 0 !< total number of observation coordinates, for soil measurements |
---|
135 | |
---|
136 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: dim_t !< number observations individual for each trajectory or station that are no _FillValues |
---|
137 | |
---|
138 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: i !< grid index for measurement position in x-direction |
---|
139 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: j !< grid index for measurement position in y-direction |
---|
140 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: k !< grid index for measurement position in k-direction |
---|
141 | |
---|
142 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: i_soil !< grid index for measurement position in x-direction |
---|
143 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: j_soil !< grid index for measurement position in y-direction |
---|
144 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: k_soil !< grid index for measurement position in k-direction |
---|
145 | |
---|
146 | LOGICAL :: trajectory = .FALSE. !< flag indicating that the observation is a mobile observation |
---|
147 | LOGICAL :: timseries = .FALSE. !< flag indicating that the observation is a stationary point measurement |
---|
148 | LOGICAL :: timseries_profile = .FALSE. !< flag indicating that the observation is a stationary profile measurement |
---|
149 | LOGICAL :: soil_sampling = .FALSE. !< flag indicating that soil state variables were sampled |
---|
150 | |
---|
151 | REAL(wp) :: fill_eutm !< fill value for UTM coordinates in case of missing values |
---|
152 | REAL(wp) :: fill_nutm !< fill value for UTM coordinates in case of missing values |
---|
153 | REAL(wp) :: fill_zag !< fill value for heigth coordinates in case of missing values |
---|
154 | REAL(wp) :: fillout = -999.9 !< fill value for output in case a observation is taken from inside a building |
---|
155 | REAL(wp) :: origin_x_obs !< origin of the observation in UTM coordiates in x-direction |
---|
156 | REAL(wp) :: origin_y_obs !< origin of the observation in UTM coordiates in y-direction |
---|
157 | |
---|
158 | REAL(wp), DIMENSION(:), ALLOCATABLE :: z_ag !< measurement height above ground level |
---|
159 | REAL(wp), DIMENSION(:), ALLOCATABLE :: depth !< measurement depth in soil |
---|
160 | |
---|
161 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: measured_vars !< measured variables |
---|
162 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: measured_vars_soil !< measured variables |
---|
163 | |
---|
164 | END TYPE virt_mea |
---|
165 | |
---|
166 | CHARACTER(LEN=5) :: char_eutm = "E_UTM" !< dimension name for UTM coordinate easting |
---|
167 | CHARACTER(LEN=11) :: char_feature = "featureType" !< attribute name for feature type |
---|
168 | |
---|
169 | ! This need to generalized |
---|
170 | CHARACTER(LEN=8) :: char_filename = "filename" !< attribute name for filename |
---|
171 | CHARACTER(LEN=11) :: char_soil = "soil_sample" !< attribute name for soil sampling indication |
---|
172 | CHARACTER(LEN=10) :: char_fillvalue = "_FillValue" !< variable attribute name for _FillValue |
---|
173 | CHARACTER(LEN=18) :: char_mv = "measured_variables" !< variable name for the array with the measured variable names |
---|
174 | CHARACTER(LEN=5) :: char_nutm = "N_UTM" !< dimension name for UTM coordinate northing |
---|
175 | CHARACTER(LEN=18) :: char_numstations = "number_of_stations" !< attribute name for number of stations |
---|
176 | CHARACTER(LEN=8) :: char_origx = "origin_x" !< attribute name for station coordinate in x |
---|
177 | CHARACTER(LEN=8) :: char_origy = "origin_y" !< attribute name for station coordinate in y |
---|
178 | CHARACTER(LEN=4) :: char_site = "site" !< attribute name for site name |
---|
179 | CHARACTER(LEN=19) :: char_zag = "height_above_ground" !< attribute name for height above ground variable |
---|
180 | CHARACTER(LEN=10) :: type_ts = 'timeSeries' !< name of stationary point measurements |
---|
181 | CHARACTER(LEN=10) :: type_traj = 'trajectory' !< name of line measurements |
---|
182 | CHARACTER(LEN=17) :: type_tspr = 'timeSeriesProfile' !< name of stationary profile measurements |
---|
183 | |
---|
184 | CHARACTER(LEN=6), DIMENSION(1:5) :: soil_vars = (/ & !< list of soil variables |
---|
185 | 't_soil', & |
---|
186 | 'm_soil', & |
---|
187 | 'lwc ', & |
---|
188 | 'lwcs ', & |
---|
189 | 'smp ' /) |
---|
190 | |
---|
191 | CHARACTER(LEN=10), DIMENSION(0:1,1:8) :: chem_vars = RESHAPE( (/ & |
---|
192 | 'mcpm1 ', 'PM1 ', & |
---|
193 | 'mcpm2p5 ', 'PM2.5 ', & |
---|
194 | 'mcpm25 ', 'PM25 ', & |
---|
195 | 'mcpm10 ', 'PM10 ', & |
---|
196 | 'mfno2 ', 'NO2 ', & |
---|
197 | 'mfno ', 'NO ', & |
---|
198 | 'tro3 ', 'O3 ', & |
---|
199 | 'mfco ', 'CO ' & |
---|
200 | /), (/ 2, 8 /) ) |
---|
201 | ! |
---|
202 | !-- MS: List requires careful revision! |
---|
203 | CHARACTER(LEN=10), DIMENSION(1:54), PARAMETER :: list_allowed_variables = & !< variables that can be sampled in PALM |
---|
204 | (/ 'hfls ', & ! surface latent heat flux (W/m2) |
---|
205 | 'hfss ', & ! surface sensible heat flux (W/m2) |
---|
206 | 'hur ', & ! relative humidity (-) |
---|
207 | 'hus ', & ! specific humidity (g/kg) |
---|
208 | 'haa ', & ! absolute atmospheric humidity (kg/m3) |
---|
209 | 'mcpm1 ', & ! mass concentration of PM1 (kg/m3) |
---|
210 | 'mcpm2p5 ', & ! mass concentration of PM2.5 (kg/m3) |
---|
211 | 'mcpm10 ', & ! mass concentration of PM10 (kg/m3) |
---|
212 | 'mcco ', & ! mass concentration of CO (kg/m3) |
---|
213 | 'mcco2 ', & ! mass concentration of CO2 (kg/m3) |
---|
214 | 'mcbcda ', & ! mass concentration of black carbon paritcles (kg/m3) |
---|
215 | 'ncaa ', & ! number concentation of particles (1/m3) |
---|
216 | 'mfco ', & ! mole fraction of CO (mol/mol) |
---|
217 | 'mfco2 ', & ! mole fraction of CO2 (mol/mol) |
---|
218 | 'mfch4 ', & ! mole fraction of methane (mol/mol) |
---|
219 | 'mfnh3 ', & ! mole fraction of amonia (mol/mol) |
---|
220 | 'mfno ', & ! mole fraction of nitrogen monoxide (mol/mol) |
---|
221 | 'mfno2 ', & ! mole fraction of nitrogen dioxide (mol/mol) |
---|
222 | 'mfso2 ', & ! mole fraction of sulfur dioxide (mol/mol) |
---|
223 | 'mfh20 ', & ! mole fraction of water (mol/mol) |
---|
224 | 'plev ', & ! ? air pressure - hydrostaic + perturbation? |
---|
225 | 'rlds ', & ! surface downward longwave flux (W/m2) |
---|
226 | 'rlus ', & ! surface upward longwave flux (W/m2) |
---|
227 | 'rsds ', & ! surface downward shortwave flux (W/m2) |
---|
228 | 'rsus ', & ! surface upward shortwave flux (W/m2) |
---|
229 | 'ta ', & ! air temperature (degree C) |
---|
230 | 't_va ', & ! virtual accoustic temperature (K) |
---|
231 | 'theta ', & ! potential temperature (K) |
---|
232 | 'tro3 ', & ! mole fraction of ozone air (mol/mol) |
---|
233 | 'ts ', & ! scaling parameter of temperature (K) |
---|
234 | 'wspeed ', & ! ? wind speed - horizontal? |
---|
235 | 'wdir ', & ! wind direction |
---|
236 | 'us ', & ! friction velocity |
---|
237 | 'msoil ', & ! ? soil moisture - which depth? |
---|
238 | 'tsoil ', & ! ? soil temperature - which depth? |
---|
239 | 'u ', & ! u-component |
---|
240 | 'utheta ', & ! total eastward kinematic heat flux |
---|
241 | 'ua ', & ! eastward wind (is there any difference to u?) |
---|
242 | 'v ', & ! v-component |
---|
243 | 'vtheta ', & ! total northward kinematic heat flux |
---|
244 | 'va ', & ! northward wind (is there any difference to v?) |
---|
245 | 'w ', & ! w-component |
---|
246 | 'wtheta ', & ! total vertical kinematic heat flux |
---|
247 | 'rld ', & ! downward longwave radiative flux (W/m2) |
---|
248 | 'rlu ', & ! upnward longwave radiative flux (W/m2) |
---|
249 | 'rsd ', & ! downward shortwave radiative flux (W/m2) |
---|
250 | 'rsu ', & ! upward shortwave radiative flux (W/m2) |
---|
251 | 'rsddif ', & ! downward shortwave diffuse radiative flux (W/m2) |
---|
252 | 'rnds ', & ! surface net downward radiative flux (W/m2) |
---|
253 | 't_soil ', & |
---|
254 | 'm_soil ', & |
---|
255 | 'lwc ', & |
---|
256 | 'lwcs ', & |
---|
257 | 'smp ' & |
---|
258 | /) |
---|
259 | |
---|
260 | |
---|
261 | LOGICAL :: global_attribute = .TRUE. !< flag indicating a global attribute |
---|
262 | LOGICAL :: init = .TRUE. !< flag indicating initialization of data output |
---|
263 | LOGICAL :: use_virtual_measurement = .FALSE. !< Namelist parameter |
---|
264 | |
---|
265 | REAL(wp) :: vm_time_start = 0.0 !< time after virtual measurements should start |
---|
266 | |
---|
267 | TYPE( virt_general ) :: vmea_general !< data structure which encompass general variables |
---|
268 | TYPE( virt_mea ), DIMENSION(:), ALLOCATABLE :: vmea !< virtual measurement data structure |
---|
269 | |
---|
270 | INTERFACE vm_check_parameters |
---|
271 | MODULE PROCEDURE vm_check_parameters |
---|
272 | END INTERFACE vm_check_parameters |
---|
273 | |
---|
274 | INTERFACE vm_data_output |
---|
275 | MODULE PROCEDURE vm_data_output |
---|
276 | END INTERFACE vm_data_output |
---|
277 | |
---|
278 | INTERFACE vm_init |
---|
279 | MODULE PROCEDURE vm_init |
---|
280 | END INTERFACE vm_init |
---|
281 | |
---|
282 | INTERFACE vm_last_actions |
---|
283 | MODULE PROCEDURE vm_last_actions |
---|
284 | END INTERFACE vm_last_actions |
---|
285 | |
---|
286 | INTERFACE vm_parin |
---|
287 | MODULE PROCEDURE vm_parin |
---|
288 | END INTERFACE vm_parin |
---|
289 | |
---|
290 | INTERFACE vm_sampling |
---|
291 | MODULE PROCEDURE vm_sampling |
---|
292 | END INTERFACE vm_sampling |
---|
293 | |
---|
294 | SAVE |
---|
295 | |
---|
296 | PRIVATE |
---|
297 | |
---|
298 | ! |
---|
299 | !-- Public interfaces |
---|
300 | PUBLIC vm_check_parameters, vm_data_output, vm_init, vm_last_actions, & |
---|
301 | vm_parin, vm_sampling |
---|
302 | |
---|
303 | ! |
---|
304 | !-- Public variables |
---|
305 | PUBLIC vmea, vmea_general, vm_time_start |
---|
306 | |
---|
307 | CONTAINS |
---|
308 | |
---|
309 | |
---|
310 | !------------------------------------------------------------------------------! |
---|
311 | ! Description: |
---|
312 | ! ------------ |
---|
313 | !> Check parameters for virtual measurement module |
---|
314 | !------------------------------------------------------------------------------! |
---|
315 | SUBROUTINE vm_check_parameters |
---|
316 | |
---|
317 | USE control_parameters, & |
---|
318 | ONLY: message_string, virtual_measurement |
---|
319 | |
---|
320 | USE netcdf_data_input_mod, & |
---|
321 | ONLY: input_pids_static, input_pids_vm |
---|
322 | |
---|
323 | IMPLICIT NONE |
---|
324 | |
---|
325 | ! |
---|
326 | !-- Virtual measurements require a setup file. |
---|
327 | IF ( virtual_measurement .AND. .NOT. input_pids_vm ) THEN |
---|
328 | message_string = 'If virtual measurements are taken, a setup input ' // & |
---|
329 | 'file for the site locations is mandatory.' |
---|
330 | CALL message( 'vm_check_parameters', 'PA0533', 1, 2, 0, 6, 0 ) |
---|
331 | ENDIF |
---|
332 | ! |
---|
333 | !-- In case virtual measurements are taken, a static input file is required. |
---|
334 | !-- This is because UTM coordinates for the PALM domain origin are required |
---|
335 | !-- for correct mapping of the measurements. |
---|
336 | !-- ToDo: Revise this later and remove this requirement. |
---|
337 | IF ( virtual_measurement .AND. .NOT. input_pids_static ) THEN |
---|
338 | message_string = 'If virtual measurements are taken, a static input ' //& |
---|
339 | 'file is mandatory.' |
---|
340 | CALL message( 'vm_check_parameters', 'PA0534', 1, 2, 0, 6, 0 ) |
---|
341 | ENDIF |
---|
342 | |
---|
343 | END SUBROUTINE vm_check_parameters |
---|
344 | |
---|
345 | !------------------------------------------------------------------------------! |
---|
346 | ! Description: |
---|
347 | ! ------------ |
---|
348 | !> Read namelist for the virtual measurement module |
---|
349 | !------------------------------------------------------------------------------! |
---|
350 | SUBROUTINE vm_parin |
---|
351 | |
---|
352 | CHARACTER (LEN=80) :: line !< dummy string that contains the current line of the parameter file |
---|
353 | |
---|
354 | NAMELIST /virtual_measurement_parameters/ use_virtual_measurement, & |
---|
355 | vm_time_start |
---|
356 | |
---|
357 | line = ' ' |
---|
358 | |
---|
359 | ! |
---|
360 | !-- Try to find stg package |
---|
361 | REWIND ( 11 ) |
---|
362 | line = ' ' |
---|
363 | DO WHILE ( INDEX( line, '&virtual_measurement_parameters' ) == 0 ) |
---|
364 | READ ( 11, '(A)', END=20 ) line |
---|
365 | ENDDO |
---|
366 | BACKSPACE ( 11 ) |
---|
367 | |
---|
368 | ! |
---|
369 | !-- Read namelist |
---|
370 | READ ( 11, virtual_measurement_parameters, ERR = 10, END = 20 ) |
---|
371 | |
---|
372 | ! |
---|
373 | !-- Set flag that indicates that the virtual measurement module is switched on |
---|
374 | IF ( use_virtual_measurement ) virtual_measurement = .TRUE. |
---|
375 | |
---|
376 | GOTO 20 |
---|
377 | |
---|
378 | 10 BACKSPACE( 11 ) |
---|
379 | READ( 11 , '(A)') line |
---|
380 | CALL parin_fail_message( 'virtual_measurement_parameters', line ) |
---|
381 | |
---|
382 | 20 CONTINUE |
---|
383 | |
---|
384 | END SUBROUTINE vm_parin |
---|
385 | |
---|
386 | |
---|
387 | !------------------------------------------------------------------------------! |
---|
388 | ! Description: |
---|
389 | ! ------------ |
---|
390 | !> Initialize virtual measurements: read coordiante arrays and measured |
---|
391 | !> variables, set indicies indicating the measurement points, read further |
---|
392 | !> attributes, etc.. |
---|
393 | !------------------------------------------------------------------------------! |
---|
394 | SUBROUTINE vm_init |
---|
395 | |
---|
396 | USE arrays_3d, & |
---|
397 | ONLY: zu, zw |
---|
398 | |
---|
399 | USE grid_variables, & |
---|
400 | ONLY: ddx, ddy, dx, dy |
---|
401 | |
---|
402 | USE indices, & |
---|
403 | ONLY: nxl, nxr, nyn, nys |
---|
404 | |
---|
405 | USE netcdf_data_input_mod, & |
---|
406 | ONLY: init_model, input_file_vm, & |
---|
407 | netcdf_data_input_get_dimension_length, & |
---|
408 | netcdf_data_input_att, netcdf_data_input_var |
---|
409 | |
---|
410 | USE surface_mod, & |
---|
411 | ONLY: get_topography_top_index_ji |
---|
412 | |
---|
413 | IMPLICIT NONE |
---|
414 | |
---|
415 | CHARACTER(LEN=5) :: dum !< dummy string indicate station id |
---|
416 | CHARACTER(LEN=5) :: dummy_read !< dummy string indicate station id |
---|
417 | CHARACTER(LEN=10), DIMENSION(50) :: measured_variables_file = '' !< array with all measured variables read from NetCDF |
---|
418 | CHARACTER(LEN=10), DIMENSION(50) :: measured_variables = '' !< dummy array with all measured variables that are allowed |
---|
419 | |
---|
420 | INTEGER(iwp) :: dim_ntime !< dimension size of time coordinate |
---|
421 | INTEGER(iwp) :: i !< grid index of virtual observation point in x-direction |
---|
422 | INTEGER(iwp) :: is !< grid index of real observation point of the respective station in x-direction |
---|
423 | INTEGER(iwp) :: j !< grid index of observation point in x-direction |
---|
424 | INTEGER(iwp) :: js !< grid index of real observation point of the respective station in y-direction |
---|
425 | INTEGER(iwp) :: k !< grid index of observation point in x-direction |
---|
426 | INTEGER(iwp) :: kl !< lower vertical index of surrounding grid points of an observation coordinate |
---|
427 | INTEGER(iwp) :: ks !< grid index of real observation point of the respective station in z-direction |
---|
428 | INTEGER(iwp) :: ksurf !< topography top index |
---|
429 | INTEGER(iwp) :: ku !< upper vertical index of surrounding grid points of an observation coordinate |
---|
430 | INTEGER(iwp) :: l !< running index over all stations |
---|
431 | INTEGER(iwp) :: len_char !< character length of single measured variables without Null character |
---|
432 | INTEGER(iwp) :: ll !< running index over all measured variables in file |
---|
433 | INTEGER(iwp) :: lll !< running index over all allowed variables |
---|
434 | INTEGER(iwp) :: n !< running index over trajectory coordinates |
---|
435 | INTEGER(iwp) :: ns !< counter variable for number of observation points on subdomain |
---|
436 | INTEGER(iwp) :: t !< running index over number of trajectories |
---|
437 | INTEGER(iwp) :: m |
---|
438 | |
---|
439 | INTEGER(KIND=1):: soil_dum |
---|
440 | |
---|
441 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: ns_all !< dummy array used to sum-up the number of observation coordinates |
---|
442 | |
---|
443 | INTEGER(iwp), DIMENSION(:,:,:), ALLOCATABLE :: meas_flag !< mask array indicating measurement positions |
---|
444 | |
---|
445 | LOGICAL :: chem_include !< flag indicating that chemical species is considered in modelled mechanism |
---|
446 | LOGICAL :: on_pe !< flag indicating that the respective measurement coordinate is on subdomain |
---|
447 | |
---|
448 | REAL(wp) :: fill_eutm !< _FillValue for coordinate array E_UTM |
---|
449 | REAL(wp) :: fill_nutm !< _FillValue for coordinate array N_UTM |
---|
450 | REAL(wp) :: fill_zag !< _FillValue for height coordinate |
---|
451 | |
---|
452 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: e_utm !< easting UTM coordinate, temporary variable |
---|
453 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: n_utm !< northing UTM coordinate, temporary variable, |
---|
454 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: z_ag !< height coordinate relative to origin_z, temporary variable |
---|
455 | ! |
---|
456 | !-- Obtain number of sites. Also, pass the 'open' string, in order to initially |
---|
457 | !-- open the measurement driver. |
---|
458 | CALL netcdf_data_input_att( vmea_general%nvm, char_numstations, & |
---|
459 | vmea_general%id_vm, input_file_vm, & |
---|
460 | global_attribute, 'open', '' ) |
---|
461 | |
---|
462 | ! |
---|
463 | !-- Allocate data structure which encompass all required information, such as |
---|
464 | !-- grid points indicies, absolute UTM coordinates, the measured quantities, |
---|
465 | !-- etc. . |
---|
466 | ALLOCATE( vmea(1:vmea_general%nvm) ) |
---|
467 | ! |
---|
468 | !-- Allocate flag array. This dummy array is used to identify grid points |
---|
469 | !-- where virtual measurements should be taken. Please note, at least one |
---|
470 | !-- ghost point is required, in order to include also the surrounding |
---|
471 | !-- grid points of the original coordinate. |
---|
472 | ALLOCATE( meas_flag(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) |
---|
473 | meas_flag = 0 |
---|
474 | ! |
---|
475 | !-- Loop over all sites. |
---|
476 | DO l = 1, vmea_general%nvm |
---|
477 | ! |
---|
478 | !-- Determine suffix which contains the ID, ordered according to the number |
---|
479 | !-- of measurements. |
---|
480 | IF( l < 10 ) THEN |
---|
481 | WRITE( dum, '(I1)') l |
---|
482 | ELSEIF( l < 100 ) THEN |
---|
483 | WRITE( dum, '(I2)') l |
---|
484 | ELSEIF( l < 1000 ) THEN |
---|
485 | WRITE( dum, '(I3)') l |
---|
486 | ELSEIF( l < 10000 ) THEN |
---|
487 | WRITE( dum, '(I4)') l |
---|
488 | ELSEIF( l < 100000 ) THEN |
---|
489 | WRITE( dum, '(I5)') l |
---|
490 | ENDIF |
---|
491 | ! |
---|
492 | !-- Read site coordinates (UTM). |
---|
493 | CALL netcdf_data_input_att( vmea(l)%origin_x_obs, char_origx // & |
---|
494 | TRIM( dum ), vmea_general%id_vm, '', & |
---|
495 | global_attribute, '', '' ) |
---|
496 | CALL netcdf_data_input_att( vmea(l)%origin_y_obs, char_origy // & |
---|
497 | TRIM( dum ), vmea_general%id_vm, '', & |
---|
498 | global_attribute, '', '' ) |
---|
499 | ! |
---|
500 | !-- Read site name |
---|
501 | CALL netcdf_data_input_att( vmea(l)%site, char_site // TRIM( dum ), & |
---|
502 | vmea_general%id_vm, '', global_attribute, & |
---|
503 | '', '' ) |
---|
504 | ! |
---|
505 | !-- Read type of the measurement (trajectory, profile, timeseries). |
---|
506 | CALL netcdf_data_input_att( vmea(l)%feature_type, char_feature // & |
---|
507 | TRIM( dum ), vmea_general%id_vm, '', & |
---|
508 | global_attribute, '', '' ) |
---|
509 | ! |
---|
510 | !-- Read the name of the original file where observational data is stored. |
---|
511 | CALL netcdf_data_input_att( vmea(l)%filename_original, char_filename // & |
---|
512 | TRIM( dum ), vmea_general%id_vm, '', & |
---|
513 | global_attribute, '', '' ) |
---|
514 | ! |
---|
515 | !-- Read a flag which indicates that also soil quantities are take at the |
---|
516 | !-- respective site (is part of the virtual measurement driver). |
---|
517 | CALL netcdf_data_input_att( soil_dum, char_soil // TRIM( dum ), & |
---|
518 | vmea_general%id_vm, '', global_attribute, & |
---|
519 | '', '' ) |
---|
520 | ! |
---|
521 | !-- Set flag for soil-sampling. |
---|
522 | IF ( soil_dum == 1 ) vmea(l)%soil_sampling = .TRUE. |
---|
523 | ! |
---|
524 | !--- Set logicals depending on the type of the measurement |
---|
525 | IF ( INDEX( vmea(l)%feature_type, type_tspr ) /= 0 ) THEN |
---|
526 | vmea(l)%timseries_profile = .TRUE. |
---|
527 | ELSEIF ( INDEX( vmea(l)%feature_type, type_ts ) /= 0 ) THEN |
---|
528 | vmea(l)%timseries = .TRUE. |
---|
529 | ELSEIF ( INDEX( vmea(l)%feature_type, type_traj ) /= 0 ) THEN |
---|
530 | vmea(l)%trajectory = .TRUE. |
---|
531 | ! |
---|
532 | !-- Give error message in case the type matches non of the pre-defined types. |
---|
533 | ELSE |
---|
534 | message_string = 'Attribue featureType = ' // & |
---|
535 | TRIM( vmea(l)%feature_type ) // & |
---|
536 | ' is not allowed.' |
---|
537 | CALL message( 'vm_init', 'PA0535', 1, 2, 0, 6, 0 ) |
---|
538 | ENDIF |
---|
539 | ! |
---|
540 | !-- Read string with all measured variables at this site |
---|
541 | measured_variables_file = '' |
---|
542 | CALL netcdf_data_input_var( measured_variables_file, & |
---|
543 | char_mv // TRIM( dum ), vmea_general%id_vm ) |
---|
544 | ! |
---|
545 | !-- Count the number of measured variables. Only count variables that match |
---|
546 | !-- with the allowed variables. |
---|
547 | !-- Please note, for some NetCDF interal reasons characters end with a NULL, |
---|
548 | !-- i.e. also empty characters contain a NULL. Therefore, check the strings |
---|
549 | !-- for a NULL to get the correct character length in order to compare |
---|
550 | !-- them with the list of allowed variables. |
---|
551 | vmea(l)%nvar = 0 |
---|
552 | DO ll = 1, SIZE( measured_variables_file ) |
---|
553 | IF ( measured_variables_file(ll)(1:1) /= CHAR(0) .AND. & |
---|
554 | measured_variables_file(ll)(1:1) /= ' ') THEN |
---|
555 | ! |
---|
556 | !-- Obtain character length of the character |
---|
557 | len_char = 1 |
---|
558 | DO WHILE ( measured_variables_file(ll)(len_char:len_char) /= CHAR(0)& |
---|
559 | .AND. measured_variables_file(ll)(len_char:len_char) /= ' ' ) |
---|
560 | len_char = len_char + 1 |
---|
561 | ENDDO |
---|
562 | len_char = len_char - 1 |
---|
563 | ! |
---|
564 | !-- Now, compare the measured variable with the list of allowed |
---|
565 | !-- variables. |
---|
566 | DO lll= 1, SIZE( list_allowed_variables ) |
---|
567 | IF ( measured_variables_file(ll)(1:len_char) == & |
---|
568 | TRIM( list_allowed_variables(lll) ) ) THEN |
---|
569 | vmea(l)%nvar = vmea(l)%nvar + 1 |
---|
570 | measured_variables(vmea(l)%nvar) = & |
---|
571 | measured_variables_file(ll)(1:len_char) |
---|
572 | ENDIF |
---|
573 | ENDDO |
---|
574 | ENDIF |
---|
575 | ENDDO |
---|
576 | ! |
---|
577 | !-- Allocate array for the measured variables names for the respective site. |
---|
578 | ALLOCATE( vmea(l)%measured_vars_name(1:vmea(l)%nvar) ) |
---|
579 | |
---|
580 | DO ll = 1, vmea(l)%nvar |
---|
581 | vmea(l)%measured_vars_name(ll) = TRIM( measured_variables(ll) ) |
---|
582 | ENDDO |
---|
583 | ! |
---|
584 | !-- In case of chemistry, check if species is considered in the modelled |
---|
585 | !-- chemistry mechanism. |
---|
586 | ! IF ( air_chemistry ) THEN |
---|
587 | ! DO ll = 1, vmea(l)%nvar |
---|
588 | ! chem_include = .FALSE. |
---|
589 | ! DO n = 1, nspec |
---|
590 | ! IF ( TRIM( vmea(l)%measured_vars_name(ll) ) == & |
---|
591 | ! TRIM( chem_species(n)%name ) ) chem_include = .TRUE. |
---|
592 | ! ENDDO |
---|
593 | ! ! |
---|
594 | ! !-- Revise this. It should only check for chemistry variables and not for all! |
---|
595 | ! IF ( .NOT. chem_include ) THEN |
---|
596 | ! message_string = TRIM( vmea(l)%measured_vars_name(ll) ) // & |
---|
597 | ! ' is not considered in the modelled ' // & |
---|
598 | ! 'chemistry mechanism' |
---|
599 | ! CALL message( 'vm_init', 'PA0000', 0, 0, 0, 6, 0 ) |
---|
600 | ! ENDIF |
---|
601 | ! ENDDO |
---|
602 | ! ENDIF |
---|
603 | ! |
---|
604 | !-- Read the UTM coordinates for the actual site. Based on the coordinates, |
---|
605 | !-- define the grid-index space on each subdomain where virtual measurements |
---|
606 | !-- should be taken. Note, the entire coordinate arrays will not be stored |
---|
607 | !-- as this would exceed memory requirements, particularly for trajectory |
---|
608 | !-- measurements. |
---|
609 | IF ( vmea(l)%nvar > 0 ) THEN |
---|
610 | ! |
---|
611 | !-- For stationary measurements UTM coordinates are just one value and |
---|
612 | !-- its dimension is "station", while for mobile measurements UTM |
---|
613 | !-- coordinates are arrays depending on the number of trajectories and |
---|
614 | !-- time, according to (UC)2 standard. First, inquire dimension length |
---|
615 | !-- of the UTM coordinates. |
---|
616 | IF ( vmea(l)%trajectory ) THEN |
---|
617 | ! |
---|
618 | !-- For non-stationary measurements read the number of trajectories |
---|
619 | !-- and the number of time coordinates. |
---|
620 | CALL netcdf_data_input_get_dimension_length( vmea_general%id_vm, & |
---|
621 | vmea(l)%ntraj, & |
---|
622 | "traj" // & |
---|
623 | TRIM( dum ) ) |
---|
624 | CALL netcdf_data_input_get_dimension_length( vmea_general%id_vm, & |
---|
625 | dim_ntime, & |
---|
626 | "ntime" // & |
---|
627 | TRIM( dum ) ) |
---|
628 | ! |
---|
629 | !-- For stationary measurements the dimension for UTM and time |
---|
630 | !-- coordinates is 1. |
---|
631 | ELSE |
---|
632 | vmea(l)%ntraj = 1 |
---|
633 | dim_ntime = 1 |
---|
634 | ENDIF |
---|
635 | ! |
---|
636 | !- Allocate array which defines individual time frame for each |
---|
637 | !-- trajectory or station. |
---|
638 | ALLOCATE( vmea(l)%dim_t(1:vmea(l)%ntraj) ) |
---|
639 | ! |
---|
640 | !-- Allocate temporary arrays for UTM and height coordinates. Note, |
---|
641 | !-- on file UTM coordinates might be 1D or 2D variables |
---|
642 | ALLOCATE( e_utm(1:vmea(l)%ntraj,1:dim_ntime) ) |
---|
643 | ALLOCATE( n_utm(1:vmea(l)%ntraj,1:dim_ntime) ) |
---|
644 | ALLOCATE( z_ag(1:vmea(l)%ntraj,1:dim_ntime) ) |
---|
645 | ! |
---|
646 | !-- Read _FillValue attributes of the coordinate dimensions. |
---|
647 | CALL netcdf_data_input_att( fill_eutm, char_fillvalue, & |
---|
648 | vmea_general%id_vm, '', & |
---|
649 | .NOT. global_attribute, '', & |
---|
650 | char_eutm // TRIM( dum ) ) |
---|
651 | CALL netcdf_data_input_att( fill_nutm, char_fillvalue, & |
---|
652 | vmea_general%id_vm, '', & |
---|
653 | .NOT. global_attribute, '', & |
---|
654 | char_nutm // TRIM( dum ) ) |
---|
655 | CALL netcdf_data_input_att( fill_zag, char_fillvalue, & |
---|
656 | vmea_general%id_vm, '', & |
---|
657 | .NOT. global_attribute, '', & |
---|
658 | char_zag // TRIM( dum ) ) |
---|
659 | ! |
---|
660 | !-- Read UTM and height coordinates coordinates for all trajectories and |
---|
661 | !-- times. |
---|
662 | IF ( vmea(l)%trajectory ) THEN |
---|
663 | CALL netcdf_data_input_var( e_utm, char_eutm // TRIM( dum ), & |
---|
664 | vmea_general%id_vm, & |
---|
665 | 0, dim_ntime-1, 0, vmea(l)%ntraj-1 ) |
---|
666 | CALL netcdf_data_input_var( n_utm, char_nutm // TRIM( dum ), & |
---|
667 | vmea_general%id_vm, & |
---|
668 | 0, dim_ntime-1, 0, vmea(l)%ntraj-1 ) |
---|
669 | CALL netcdf_data_input_var( z_ag, char_zag // TRIM( dum ), & |
---|
670 | vmea_general%id_vm, & |
---|
671 | 0, dim_ntime-1, 0, vmea(l)%ntraj-1 ) |
---|
672 | ELSE |
---|
673 | CALL netcdf_data_input_var( e_utm(1,:), char_eutm // TRIM( dum ), & |
---|
674 | vmea_general%id_vm ) |
---|
675 | CALL netcdf_data_input_var( n_utm(1,:), char_nutm // TRIM( dum ), & |
---|
676 | vmea_general%id_vm ) |
---|
677 | CALL netcdf_data_input_var( z_ag(1,:), char_zag // TRIM( dum ), & |
---|
678 | vmea_general%id_vm ) |
---|
679 | ENDIF |
---|
680 | ! |
---|
681 | !-- Based on UTM coordinates, check if the measurement station or parts |
---|
682 | !-- of the trajectory is on subdomain. This case, setup grid index space |
---|
683 | !-- sample these quantities. |
---|
684 | meas_flag = 0 |
---|
685 | DO t = 1, vmea(l)%ntraj |
---|
686 | ! |
---|
687 | !-- First, compute relative x- and y-coordinates with respect to the |
---|
688 | !-- lower-left origin of the model domain, which is the difference |
---|
689 | !-- betwen UTM coordinates. Note, if the origin is not correct, the |
---|
690 | !-- virtual sites will be misplaced. |
---|
691 | e_utm(t,1:dim_ntime) = e_utm(t,1:dim_ntime) - init_model%origin_x |
---|
692 | n_utm(t,1:dim_ntime) = n_utm(t,1:dim_ntime) - init_model%origin_y |
---|
693 | ! |
---|
694 | !-- Determine the individual time coordinate length for each station and |
---|
695 | !-- trajectory. This is required as several stations and trajectories |
---|
696 | !-- are merged into one file but they do not have the same number of |
---|
697 | !-- points in time, hence, missing values may occur and cannot be |
---|
698 | !-- processed further. This is actually a work-around for the specific |
---|
699 | !-- (UC)2 dataset, but it won't harm in anyway. |
---|
700 | vmea(l)%dim_t(t) = 0 |
---|
701 | DO n = 1, dim_ntime |
---|
702 | IF ( e_utm(t,n) /= fill_eutm .AND. & |
---|
703 | n_utm(t,n) /= fill_nutm .AND. & |
---|
704 | z_ag(t,n) /= fill_zag ) vmea(l)%dim_t(t) = n |
---|
705 | ENDDO |
---|
706 | ! |
---|
707 | !-- Compute grid indices relative to origin and check if these are |
---|
708 | !-- on the subdomain. Note, virtual measurements will be taken also |
---|
709 | !-- at grid points surrounding the station, hence, check also for |
---|
710 | !-- these grid points. |
---|
711 | DO n = 1, vmea(l)%dim_t(t) |
---|
712 | is = INT( ( e_utm(t,n) + 0.5_wp * dx ) * ddx, KIND = iwp ) |
---|
713 | js = INT( ( n_utm(t,n) + 0.5_wp * dy ) * ddy, KIND = iwp ) |
---|
714 | ! |
---|
715 | !-- Is the observation point on subdomain? |
---|
716 | on_pe = ( is >= nxl .AND. is <= nxr .AND. & |
---|
717 | js >= nys .AND. js <= nyn ) |
---|
718 | ! |
---|
719 | !-- Check if observation coordinate is on subdomain |
---|
720 | IF ( on_pe ) THEN |
---|
721 | ! |
---|
722 | !-- Determine vertical index which correspond to the observation |
---|
723 | !-- height. |
---|
724 | ksurf = get_topography_top_index_ji( js, is, 's' ) |
---|
725 | ks = MINLOC( ABS( zu - zw(ksurf) - z_ag(t,n) ), DIM = 1 ) - 1 |
---|
726 | ! |
---|
727 | !-- Set mask array at the observation coordinates. Also, flag the |
---|
728 | !-- surrounding coordinate points, but first check whether the |
---|
729 | !-- surrounding coordinate points are on the subdomain. |
---|
730 | kl = MERGE( ks-1, ks, ks-1 >= nzb .AND. ks-1 >= ksurf ) |
---|
731 | ku = MERGE( ks+1, ks, ks+1 < nzt+1 ) |
---|
732 | |
---|
733 | DO i = is-1, is+1 |
---|
734 | DO j = js-1, js+1 |
---|
735 | DO k = kl, ku |
---|
736 | meas_flag(k,j,i) = MERGE( & |
---|
737 | IBSET( meas_flag(k,j,i), 0 ), & |
---|
738 | 0, & |
---|
739 | BTEST( wall_flags_0(k,j,i), 0 ) & |
---|
740 | ) |
---|
741 | ENDDO |
---|
742 | ENDDO |
---|
743 | ENDDO |
---|
744 | ENDIF |
---|
745 | ENDDO |
---|
746 | |
---|
747 | ENDDO |
---|
748 | ! |
---|
749 | !-- Based on the flag array count the number of of sampling coordinates. |
---|
750 | !-- Please note, sampling coordinates in atmosphere and soil may be |
---|
751 | !-- different, as within the soil all levels will be measured. |
---|
752 | !-- Hence, count individually. Start with atmoshere. |
---|
753 | ns = 0 |
---|
754 | DO i = nxl-1, nxr+1 |
---|
755 | DO j = nys-1, nyn+1 |
---|
756 | DO k = nzb, nzt+1 |
---|
757 | ns = ns + MERGE( 1, 0, BTEST( meas_flag(k,j,i), 0 ) ) |
---|
758 | ENDDO |
---|
759 | ENDDO |
---|
760 | ENDDO |
---|
761 | |
---|
762 | ! |
---|
763 | !-- Store number of observation points on subdomain and allocate index |
---|
764 | !-- arrays as well as array containing height information. |
---|
765 | vmea(l)%ns = ns |
---|
766 | |
---|
767 | ALLOCATE( vmea(l)%i(1:vmea(l)%ns) ) |
---|
768 | ALLOCATE( vmea(l)%j(1:vmea(l)%ns) ) |
---|
769 | ALLOCATE( vmea(l)%k(1:vmea(l)%ns) ) |
---|
770 | ALLOCATE( vmea(l)%z_ag(1:vmea(l)%ns) ) |
---|
771 | ! |
---|
772 | !-- Based on the flag array store the grid indices which correspond to |
---|
773 | !-- the observation coordinates. |
---|
774 | ns = 0 |
---|
775 | DO i = nxl-1, nxr+1 |
---|
776 | DO j = nys-1, nyn+1 |
---|
777 | DO k = nzb, nzt+1 |
---|
778 | IF ( BTEST( meas_flag(k,j,i), 0 ) ) THEN |
---|
779 | ns = ns + 1 |
---|
780 | vmea(l)%i(ns) = i |
---|
781 | vmea(l)%j(ns) = j |
---|
782 | vmea(l)%k(ns) = k |
---|
783 | vmea(l)%z_ag(ns) = zu(k) - & |
---|
784 | zw(get_topography_top_index_ji( j, i, 's' )) |
---|
785 | ENDIF |
---|
786 | ENDDO |
---|
787 | ENDDO |
---|
788 | ENDDO |
---|
789 | ! |
---|
790 | !-- Same for the soil. Based on the flag array, count the number of |
---|
791 | !-- sampling coordinates in soil. Sample at all soil levels in this case. |
---|
792 | IF ( vmea(l)%soil_sampling ) THEN |
---|
793 | DO i = nxl, nxr |
---|
794 | DO j = nys, nyn |
---|
795 | IF ( ANY( BTEST( meas_flag(:,j,i), 0 ) ) ) THEN |
---|
796 | IF ( surf_lsm_h%start_index(j,i) <= & |
---|
797 | surf_lsm_h%end_index(j,i) ) THEN |
---|
798 | vmea(l)%ns_soil = vmea(l)%ns_soil + & |
---|
799 | nzt_soil - nzb_soil + 1 |
---|
800 | ENDIF |
---|
801 | IF ( surf_usm_h%start_index(j,i) <= & |
---|
802 | surf_usm_h%end_index(j,i) ) THEN |
---|
803 | vmea(l)%ns_soil = vmea(l)%ns_soil + & |
---|
804 | nzt_wall - nzb_wall + 1 |
---|
805 | ENDIF |
---|
806 | ENDIF |
---|
807 | ENDDO |
---|
808 | ENDDO |
---|
809 | ENDIF |
---|
810 | ! |
---|
811 | !-- Allocate index arrays as well as array containing height information |
---|
812 | !-- for soil. |
---|
813 | IF ( vmea(l)%soil_sampling ) THEN |
---|
814 | ALLOCATE( vmea(l)%i_soil(1:vmea(l)%ns_soil) ) |
---|
815 | ALLOCATE( vmea(l)%j_soil(1:vmea(l)%ns_soil) ) |
---|
816 | ALLOCATE( vmea(l)%k_soil(1:vmea(l)%ns_soil) ) |
---|
817 | ALLOCATE( vmea(l)%depth(1:vmea(l)%ns_soil) ) |
---|
818 | ENDIF |
---|
819 | ! |
---|
820 | !-- For soil, store the grid indices. |
---|
821 | ns = 0 |
---|
822 | IF ( vmea(l)%soil_sampling ) THEN |
---|
823 | DO i = nxl, nxr |
---|
824 | DO j = nys, nyn |
---|
825 | IF ( ANY( BTEST( meas_flag(:,j,i), 0 ) ) ) THEN |
---|
826 | IF ( surf_lsm_h%start_index(j,i) <= & |
---|
827 | surf_lsm_h%end_index(j,i) ) THEN |
---|
828 | m = surf_lsm_h%start_index(j,i) |
---|
829 | DO k = nzb_soil, nzt_soil |
---|
830 | ns = ns + 1 |
---|
831 | vmea(l)%i_soil(ns) = i |
---|
832 | vmea(l)%j_soil(ns) = j |
---|
833 | vmea(l)%k_soil(ns) = k |
---|
834 | vmea(l)%depth(ns) = zs(k) |
---|
835 | ENDDO |
---|
836 | ENDIF |
---|
837 | |
---|
838 | IF ( surf_usm_h%start_index(j,i) <= & |
---|
839 | surf_usm_h%end_index(j,i) ) THEN |
---|
840 | m = surf_usm_h%start_index(j,i) |
---|
841 | DO k = nzb_wall, nzt_wall |
---|
842 | ns = ns + 1 |
---|
843 | vmea(l)%i_soil(ns) = i |
---|
844 | vmea(l)%j_soil(ns) = j |
---|
845 | vmea(l)%k_soil(ns) = k |
---|
846 | vmea(l)%depth(ns) = surf_usm_h%zw(k,m) |
---|
847 | ENDDO |
---|
848 | ENDIF |
---|
849 | ENDIF |
---|
850 | ENDDO |
---|
851 | ENDDO |
---|
852 | ENDIF |
---|
853 | ! |
---|
854 | !-- Allocate array to save the sampled values. |
---|
855 | ALLOCATE( vmea(l)%measured_vars(1:vmea(l)%ns,1:vmea(l)%nvar) ) |
---|
856 | |
---|
857 | IF ( vmea(l)%soil_sampling ) & |
---|
858 | ALLOCATE( vmea(l)%measured_vars_soil(1:vmea(l)%ns_soil, & |
---|
859 | 1:vmea(l)%nvar) ) |
---|
860 | ! |
---|
861 | !-- Initialize with _FillValues |
---|
862 | vmea(l)%measured_vars(1:vmea(l)%ns,1:vmea(l)%nvar) = vmea(l)%fillout |
---|
863 | IF ( vmea(l)%soil_sampling ) & |
---|
864 | vmea(l)%measured_vars_soil(1:vmea(l)%ns_soil,1:vmea(l)%nvar) = & |
---|
865 | vmea(l)%fillout |
---|
866 | ! |
---|
867 | !-- Deallocate temporary coordinate arrays |
---|
868 | IF ( ALLOCATED( e_utm ) ) DEALLOCATE( e_utm ) |
---|
869 | IF ( ALLOCATED( n_utm ) ) DEALLOCATE( n_utm ) |
---|
870 | IF ( ALLOCATED( z_ag ) ) DEALLOCATE( z_ag ) |
---|
871 | IF ( ALLOCATED( z_ag ) ) DEALLOCATE( vmea(l)%dim_t ) |
---|
872 | ENDIF |
---|
873 | ENDDO |
---|
874 | ! |
---|
875 | !-- Close input file for virtual measurements. Therefore, just call |
---|
876 | !-- the read attribute routine with the "close" option. |
---|
877 | CALL netcdf_data_input_att( vmea_general%nvm, char_numstations, & |
---|
878 | vmea_general%id_vm, '', & |
---|
879 | global_attribute, 'close', '' ) |
---|
880 | ! |
---|
881 | !-- Sum-up the number of observation coordiates, for atmosphere first. |
---|
882 | !-- This is actually only required for data output. |
---|
883 | ALLOCATE( ns_all(1:vmea_general%nvm) ) |
---|
884 | ns_all = 0 |
---|
885 | #if defined( __parallel ) |
---|
886 | CALL MPI_ALLREDUCE( vmea(:)%ns, ns_all(:), vmea_general%nvm, MPI_INTEGER, & |
---|
887 | MPI_SUM, comm2d, ierr ) |
---|
888 | #else |
---|
889 | ns_all(:) = vmea(:)%ns |
---|
890 | #endif |
---|
891 | vmea(:)%ns_tot = ns_all(:) |
---|
892 | ! |
---|
893 | !-- Now for soil |
---|
894 | ns_all = 0 |
---|
895 | #if defined( __parallel ) |
---|
896 | CALL MPI_ALLREDUCE( vmea(:)%ns_soil, ns_all(:), vmea_general%nvm, & |
---|
897 | MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
898 | #else |
---|
899 | ns_all(:) = vmea(:)%ns_soil |
---|
900 | #endif |
---|
901 | vmea(:)%ns_soil_tot = ns_all(:) |
---|
902 | |
---|
903 | DEALLOCATE( ns_all ) |
---|
904 | ! |
---|
905 | !-- Dellocate flag array |
---|
906 | DEALLOCATE( meas_flag ) |
---|
907 | ! |
---|
908 | !-- Initialize binary data output of virtual measurements. |
---|
909 | !-- Open binary output file. |
---|
910 | CALL check_open( 27 ) |
---|
911 | ! |
---|
912 | !-- Output header information. |
---|
913 | CALL vm_data_output |
---|
914 | |
---|
915 | END SUBROUTINE vm_init |
---|
916 | |
---|
917 | |
---|
918 | !------------------------------------------------------------------------------! |
---|
919 | ! Description: |
---|
920 | ! ------------ |
---|
921 | !> Binary data output. |
---|
922 | !------------------------------------------------------------------------------! |
---|
923 | SUBROUTINE vm_data_output |
---|
924 | |
---|
925 | USE pegrid |
---|
926 | |
---|
927 | IMPLICIT NONE |
---|
928 | |
---|
929 | INTEGER(iwp) :: i !< running index over IO blocks |
---|
930 | INTEGER(iwp) :: l !< running index over all stations |
---|
931 | INTEGER(iwp) :: n !< running index over all measured variables at a station |
---|
932 | ! |
---|
933 | !-- Header output on each PE |
---|
934 | IF ( init ) THEN |
---|
935 | |
---|
936 | DO i = 0, io_blocks-1 |
---|
937 | IF ( i == io_group ) THEN |
---|
938 | WRITE ( 27 ) 'number of measurements ' |
---|
939 | WRITE ( 27 ) vmea_general%nvm |
---|
940 | |
---|
941 | DO l = 1, vmea_general%nvm |
---|
942 | WRITE ( 27 ) 'site ' |
---|
943 | WRITE ( 27 ) vmea(l)%site |
---|
944 | WRITE ( 27 ) 'file ' |
---|
945 | WRITE ( 27 ) vmea(l)%filename_original |
---|
946 | WRITE ( 27 ) 'feature_type ' |
---|
947 | WRITE ( 27 ) vmea(l)%feature_type |
---|
948 | WRITE ( 27 ) 'origin_x_obs ' |
---|
949 | WRITE ( 27 ) vmea(l)%origin_x_obs |
---|
950 | WRITE ( 27 ) 'origin_y_obs ' |
---|
951 | WRITE ( 27 ) vmea(l)%origin_y_obs |
---|
952 | WRITE ( 27 ) 'total number of observation points' |
---|
953 | WRITE ( 27 ) vmea(l)%ns_tot |
---|
954 | WRITE ( 27 ) 'number of measured variables ' |
---|
955 | WRITE ( 27 ) vmea(l)%nvar |
---|
956 | WRITE ( 27 ) 'variables ' |
---|
957 | WRITE ( 27 ) vmea(l)%measured_vars_name(:) |
---|
958 | WRITE ( 27 ) 'number of observation points ' |
---|
959 | WRITE ( 27 ) vmea(l)%ns |
---|
960 | WRITE ( 27 ) 'E_UTM ' |
---|
961 | WRITE ( 27 ) init_model%origin_x + & |
---|
962 | REAL( vmea(l)%i(1:vmea(l)%ns) + 0.5_wp, KIND = wp ) * dx |
---|
963 | WRITE ( 27 ) 'N_UTM ' |
---|
964 | WRITE ( 27 ) init_model%origin_y + & |
---|
965 | REAL( vmea(l)%j(1:vmea(l)%ns) + 0.5_wp, KIND = wp ) * dy |
---|
966 | WRITE ( 27 ) 'Z_AG ' |
---|
967 | WRITE ( 27 ) vmea(l)%z_ag(1:vmea(l)%ns) |
---|
968 | WRITE ( 27 ) 'soil sampling ' |
---|
969 | WRITE ( 27 ) MERGE( 'yes ', & |
---|
970 | 'no ', & |
---|
971 | vmea(l)%soil_sampling ) |
---|
972 | |
---|
973 | IF ( vmea(l)%soil_sampling ) THEN |
---|
974 | WRITE ( 27 ) 'total number of soil points ' |
---|
975 | WRITE ( 27 ) vmea(l)%ns_soil_tot |
---|
976 | print*, "vmea(l)%ns_soil_tot", vmea(l)%ns_soil_tot |
---|
977 | WRITE ( 27 ) 'number of soil points ' |
---|
978 | WRITE ( 27 ) vmea(l)%ns_soil |
---|
979 | WRITE ( 27 ) 'E_UTM soil ' |
---|
980 | WRITE ( 27 ) init_model%origin_x + & |
---|
981 | REAL( vmea(l)%i_soil(1:vmea(l)%ns_soil) + 0.5_wp, & |
---|
982 | KIND = wp ) * dx |
---|
983 | WRITE ( 27 ) 'N_UTM soil ' |
---|
984 | WRITE ( 27 ) init_model%origin_y + & |
---|
985 | REAL( vmea(l)%j_soil(1:vmea(l)%ns_soil) + 0.5_wp, & |
---|
986 | KIND = wp ) * dy |
---|
987 | WRITE ( 27 ) 'DEPTH ' |
---|
988 | WRITE ( 27 ) vmea(l)%depth(1:vmea(l)%ns_soil) |
---|
989 | ENDIF |
---|
990 | ENDDO |
---|
991 | |
---|
992 | ENDIF |
---|
993 | ENDDO |
---|
994 | |
---|
995 | #if defined( __parallel ) |
---|
996 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
997 | #endif |
---|
998 | ! |
---|
999 | !-- After header information is written, set control flag to .FALSE. |
---|
1000 | init = .FALSE. |
---|
1001 | ! |
---|
1002 | !-- Data output at each measurement timestep on each PE |
---|
1003 | ELSE |
---|
1004 | DO i = 0, io_blocks-1 |
---|
1005 | |
---|
1006 | IF ( i == io_group ) THEN |
---|
1007 | WRITE( 27 ) 'output time ' |
---|
1008 | WRITE( 27 ) time_since_reference_point |
---|
1009 | DO l = 1, vmea_general%nvm |
---|
1010 | ! |
---|
1011 | !-- Skip binary writing if no observation points are defined on PE |
---|
1012 | IF ( vmea(l)%ns < 1 .AND. vmea(l)%ns_soil < 1) CYCLE |
---|
1013 | DO n = 1, vmea(l)%nvar |
---|
1014 | WRITE( 27 ) vmea(l)%measured_vars_name(n) |
---|
1015 | IF ( vmea(l)%soil_sampling .AND. & |
---|
1016 | ANY( TRIM( vmea(l)%measured_vars_name(n)) == & |
---|
1017 | soil_vars ) ) THEN |
---|
1018 | WRITE( 27 ) vmea(l)%measured_vars_soil(:,n) |
---|
1019 | ELSE |
---|
1020 | WRITE( 27 ) vmea(l)%measured_vars(:,n) |
---|
1021 | ENDIF |
---|
1022 | ENDDO |
---|
1023 | |
---|
1024 | ENDDO |
---|
1025 | ENDIF |
---|
1026 | ENDDO |
---|
1027 | #if defined( __parallel ) |
---|
1028 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
1029 | #endif |
---|
1030 | ENDIF |
---|
1031 | |
---|
1032 | END SUBROUTINE vm_data_output |
---|
1033 | |
---|
1034 | |
---|
1035 | !------------------------------------------------------------------------------! |
---|
1036 | ! Description: |
---|
1037 | ! ------------ |
---|
1038 | !> Write end-of-file statement as last action. |
---|
1039 | !------------------------------------------------------------------------------! |
---|
1040 | SUBROUTINE vm_last_actions |
---|
1041 | |
---|
1042 | USE pegrid |
---|
1043 | |
---|
1044 | IMPLICIT NONE |
---|
1045 | |
---|
1046 | INTEGER(iwp) :: i !< running index over IO blocks |
---|
1047 | INTEGER(iwp) :: l !< running index over all stations |
---|
1048 | INTEGER(iwp) :: n !< running index over all measured variables at a station |
---|
1049 | |
---|
1050 | DO i = 0, io_blocks-1 |
---|
1051 | IF ( i == io_group ) THEN |
---|
1052 | WRITE( 27 ) 'EOF ' |
---|
1053 | ENDIF |
---|
1054 | ENDDO |
---|
1055 | #if defined( __parallel ) |
---|
1056 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
1057 | #endif |
---|
1058 | ! |
---|
1059 | !-- Close binary file |
---|
1060 | CALL close_file( 27 ) |
---|
1061 | |
---|
1062 | END SUBROUTINE vm_last_actions |
---|
1063 | |
---|
1064 | !------------------------------------------------------------------------------! |
---|
1065 | ! Description: |
---|
1066 | ! ------------ |
---|
1067 | !> Sampling of the actual quantities along the observation coordinates |
---|
1068 | !------------------------------------------------------------------------------! |
---|
1069 | SUBROUTINE vm_sampling |
---|
1070 | |
---|
1071 | USE arrays_3d, & |
---|
1072 | ONLY: exner, pt, q, u, v, w |
---|
1073 | |
---|
1074 | USE basic_constants_and_equations_mod, & |
---|
1075 | ONLY: pi |
---|
1076 | |
---|
1077 | USE radiation_model_mod, & |
---|
1078 | ONLY: radiation |
---|
1079 | |
---|
1080 | USE surface_mod, & |
---|
1081 | ONLY: surf_def_h, surf_lsm_h, surf_usm_h |
---|
1082 | |
---|
1083 | IMPLICIT NONE |
---|
1084 | |
---|
1085 | INTEGER(iwp) :: i !< grid index in x-direction |
---|
1086 | INTEGER(iwp) :: j !< grid index in y-direction |
---|
1087 | INTEGER(iwp) :: k !< grid index in z-direction |
---|
1088 | INTEGER(iwp) :: ind_chem !< dummy index to identify chemistry variable and translate it from (UC)2 standard to interal naming |
---|
1089 | INTEGER(iwp) :: l !< running index over the number of stations |
---|
1090 | INTEGER(iwp) :: m !< running index over all virtual observation coordinates |
---|
1091 | INTEGER(iwp) :: mm !< index of surface element which corresponds to the virtual observation coordinate |
---|
1092 | INTEGER(iwp) :: n !< running index over all measured variables at a station |
---|
1093 | INTEGER(iwp) :: nn !< running index over the number of chemcal species |
---|
1094 | |
---|
1095 | LOGICAL :: match_lsm !< flag indicating natural-type surface |
---|
1096 | LOGICAL :: match_usm !< flag indicating urban-type surface |
---|
1097 | ! |
---|
1098 | !-- Loop over all sites. |
---|
1099 | DO l = 1, vmea_general%nvm |
---|
1100 | ! |
---|
1101 | !-- At the beginning, set _FillValues |
---|
1102 | IF ( ALLOCATED( vmea(l)%measured_vars ) ) & |
---|
1103 | vmea(l)%measured_vars = vmea(l)%fillout |
---|
1104 | IF ( ALLOCATED( vmea(l)%measured_vars_soil ) ) & |
---|
1105 | vmea(l)%measured_vars_soil = vmea(l)%fillout |
---|
1106 | ! |
---|
1107 | !-- Loop over all variables measured at this site. |
---|
1108 | DO n = 1, vmea(l)%nvar |
---|
1109 | |
---|
1110 | SELECT CASE ( TRIM( vmea(l)%measured_vars_name(n) ) ) |
---|
1111 | |
---|
1112 | CASE ( 'theta' ) |
---|
1113 | IF ( .NOT. neutral ) THEN |
---|
1114 | DO m = 1, vmea(l)%ns |
---|
1115 | k = vmea(l)%k(m) |
---|
1116 | j = vmea(l)%j(m) |
---|
1117 | i = vmea(l)%i(m) |
---|
1118 | vmea(l)%measured_vars(m,n) = pt(k,j,i) |
---|
1119 | ENDDO |
---|
1120 | ENDIF |
---|
1121 | |
---|
1122 | CASE ( 'ta' ) |
---|
1123 | IF ( .NOT. neutral ) THEN |
---|
1124 | DO m = 1, vmea(l)%ns |
---|
1125 | k = vmea(l)%k(m) |
---|
1126 | j = vmea(l)%j(m) |
---|
1127 | i = vmea(l)%i(m) |
---|
1128 | vmea(l)%measured_vars(m,n) = pt(k,j,i) * exner( k ) |
---|
1129 | ENDDO |
---|
1130 | ENDIF |
---|
1131 | |
---|
1132 | CASE ( 't_va' ) |
---|
1133 | |
---|
1134 | CASE ( 'hus', 'haa' ) |
---|
1135 | IF ( humidity ) THEN |
---|
1136 | DO m = 1, vmea(l)%ns |
---|
1137 | k = vmea(l)%k(m) |
---|
1138 | j = vmea(l)%j(m) |
---|
1139 | i = vmea(l)%i(m) |
---|
1140 | vmea(l)%measured_vars(m,n) = q(k,j,i) |
---|
1141 | ENDDO |
---|
1142 | ENDIF |
---|
1143 | |
---|
1144 | CASE ( 'u', 'ua' ) |
---|
1145 | DO m = 1, vmea(l)%ns |
---|
1146 | k = vmea(l)%k(m) |
---|
1147 | j = vmea(l)%j(m) |
---|
1148 | i = vmea(l)%i(m) |
---|
1149 | vmea(l)%measured_vars(m,n) = 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) |
---|
1150 | ENDDO |
---|
1151 | |
---|
1152 | CASE ( 'v', 'va' ) |
---|
1153 | DO m = 1, vmea(l)%ns |
---|
1154 | k = vmea(l)%k(m) |
---|
1155 | j = vmea(l)%j(m) |
---|
1156 | i = vmea(l)%i(m) |
---|
1157 | vmea(l)%measured_vars(m,n) = 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) |
---|
1158 | ENDDO |
---|
1159 | |
---|
1160 | CASE ( 'w' ) |
---|
1161 | DO m = 1, vmea(l)%ns |
---|
1162 | k = MAX ( 1, vmea(l)%k(m) ) |
---|
1163 | j = vmea(l)%j(m) |
---|
1164 | i = vmea(l)%i(m) |
---|
1165 | vmea(l)%measured_vars(m,n) = 0.5_wp * ( w(k,j,i) + w(k-1,j,i) ) |
---|
1166 | ENDDO |
---|
1167 | |
---|
1168 | CASE ( 'wspeed' ) |
---|
1169 | DO m = 1, vmea(l)%ns |
---|
1170 | k = vmea(l)%k(m) |
---|
1171 | j = vmea(l)%j(m) |
---|
1172 | i = vmea(l)%i(m) |
---|
1173 | vmea(l)%measured_vars(m,n) = SQRT( & |
---|
1174 | ( 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) )**2 + & |
---|
1175 | ( 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) )**2 & |
---|
1176 | ) |
---|
1177 | ENDDO |
---|
1178 | |
---|
1179 | CASE ( 'wdir' ) |
---|
1180 | DO m = 1, vmea(l)%ns |
---|
1181 | k = vmea(l)%k(m) |
---|
1182 | j = vmea(l)%j(m) |
---|
1183 | i = vmea(l)%i(m) |
---|
1184 | |
---|
1185 | vmea(l)%measured_vars(m,n) = ATAN2( & |
---|
1186 | - 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ), & |
---|
1187 | - 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) & |
---|
1188 | ) * 180.0_wp / pi |
---|
1189 | ENDDO |
---|
1190 | |
---|
1191 | CASE ( 'utheta' ) |
---|
1192 | DO m = 1, vmea(l)%ns |
---|
1193 | k = vmea(l)%k(m) |
---|
1194 | j = vmea(l)%j(m) |
---|
1195 | i = vmea(l)%i(m) |
---|
1196 | vmea(l)%measured_vars(m,n) = 0.5_wp * & |
---|
1197 | ( u(k,j,i) + u(k,j,i+1) ) * & |
---|
1198 | pt(k,j,i) |
---|
1199 | ENDDO |
---|
1200 | |
---|
1201 | CASE ( 'vtheta' ) |
---|
1202 | DO m = 1, vmea(l)%ns |
---|
1203 | k = vmea(l)%k(m) |
---|
1204 | j = vmea(l)%j(m) |
---|
1205 | i = vmea(l)%i(m) |
---|
1206 | vmea(l)%measured_vars(m,n) = 0.5_wp * & |
---|
1207 | ( v(k,j,i) + v(k,j+1,i) ) * & |
---|
1208 | pt(k,j,i) |
---|
1209 | ENDDO |
---|
1210 | |
---|
1211 | CASE ( 'wtheta' ) |
---|
1212 | DO m = 1, vmea(l)%ns |
---|
1213 | k = MAX ( 1, vmea(l)%k(m) ) |
---|
1214 | j = vmea(l)%j(m) |
---|
1215 | i = vmea(l)%i(m) |
---|
1216 | vmea(l)%measured_vars(m,n) = 0.5_wp * & |
---|
1217 | ( w(k-1,j,i) + w(k,j,i) ) * & |
---|
1218 | pt(k,j,i) |
---|
1219 | ENDDO |
---|
1220 | |
---|
1221 | CASE ( 'uw' ) |
---|
1222 | DO m = 1, vmea(l)%ns |
---|
1223 | k = MAX ( 1, vmea(l)%k(m) ) |
---|
1224 | j = vmea(l)%j(m) |
---|
1225 | i = vmea(l)%i(m) |
---|
1226 | vmea(l)%measured_vars(m,n) = 0.25_wp * & |
---|
1227 | ( w(k-1,j,i) + w(k,j,i) ) * & |
---|
1228 | ( u(k,j,i) + u(k,j,i+1) ) |
---|
1229 | ENDDO |
---|
1230 | |
---|
1231 | CASE ( 'vw' ) |
---|
1232 | DO m = 1, vmea(l)%ns |
---|
1233 | k = MAX ( 1, vmea(l)%k(m) ) |
---|
1234 | j = vmea(l)%j(m) |
---|
1235 | i = vmea(l)%i(m) |
---|
1236 | vmea(l)%measured_vars(m,n) = 0.25_wp * & |
---|
1237 | ( w(k-1,j,i) + w(k,j,i) ) * & |
---|
1238 | ( v(k,j,i) + v(k,j+1,i) ) |
---|
1239 | ENDDO |
---|
1240 | |
---|
1241 | CASE ( 'uv' ) |
---|
1242 | DO m = 1, vmea(l)%ns |
---|
1243 | k = MAX ( 1, vmea(l)%k(m) ) |
---|
1244 | j = vmea(l)%j(m) |
---|
1245 | i = vmea(l)%i(m) |
---|
1246 | vmea(l)%measured_vars(m,n) = 0.25_wp * & |
---|
1247 | ( u(k,j,i) + u(k,j,i+1) ) * & |
---|
1248 | ( v(k,j,i) + v(k,j+1,i) ) |
---|
1249 | ENDDO |
---|
1250 | ! |
---|
1251 | !-- List of variables may need extension. |
---|
1252 | CASE ( 'mcpm1', 'mcpm2p5', 'mcpm10', 'mfco', 'mfno', 'mfno2', & |
---|
1253 | 'tro3' ) |
---|
1254 | IF ( air_chemistry ) THEN |
---|
1255 | ! |
---|
1256 | !-- First, search for the measured variable in the chem_vars |
---|
1257 | !-- list, in order to get the internal name of the variable. |
---|
1258 | DO nn = 1, UBOUND( chem_vars, 2 ) |
---|
1259 | IF ( TRIM( vmea(l)%measured_vars_name(m) ) == & |
---|
1260 | TRIM( chem_vars(0,nn) ) ) ind_chem = nn |
---|
1261 | ENDDO |
---|
1262 | ! |
---|
1263 | !-- Run loop over all chemical species, if the measured |
---|
1264 | !-- variable matches the interal name, sample the variable. |
---|
1265 | DO nn = 1, nspec |
---|
1266 | IF ( TRIM( chem_vars(1,ind_chem) ) == & |
---|
1267 | TRIM( chem_species(nn)%name ) ) THEN |
---|
1268 | DO m = 1, vmea(l)%ns |
---|
1269 | k = vmea(l)%k(m) |
---|
1270 | j = vmea(l)%j(m) |
---|
1271 | i = vmea(l)%i(m) |
---|
1272 | vmea(l)%measured_vars(m,n) = & |
---|
1273 | chem_species(nn)%conc(k,j,i) |
---|
1274 | ENDDO |
---|
1275 | ENDIF |
---|
1276 | ENDDO |
---|
1277 | ENDIF |
---|
1278 | |
---|
1279 | CASE ( 'us' ) |
---|
1280 | DO m = 1, vmea(l)%ns |
---|
1281 | ! |
---|
1282 | !-- Surface data is only available on inner subdomains, not |
---|
1283 | !-- on ghost points. Hence, limit the indices. |
---|
1284 | j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) < nys ) |
---|
1285 | j = MERGE( j , nyn, j > nyn ) |
---|
1286 | i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) < nxl ) |
---|
1287 | i = MERGE( i , nxr, i > nxr ) |
---|
1288 | |
---|
1289 | DO mm = surf_def_h(0)%start_index(j,i), & |
---|
1290 | surf_def_h(0)%end_index(j,i) |
---|
1291 | vmea(l)%measured_vars(m,n) = surf_def_h(0)%us(mm) |
---|
1292 | ENDDO |
---|
1293 | DO mm = surf_lsm_h%start_index(j,i), & |
---|
1294 | surf_lsm_h%end_index(j,i) |
---|
1295 | vmea(l)%measured_vars(m,n) = surf_lsm_h%us(mm) |
---|
1296 | ENDDO |
---|
1297 | DO mm = surf_usm_h%start_index(j,i), & |
---|
1298 | surf_usm_h%end_index(j,i) |
---|
1299 | vmea(l)%measured_vars(m,n) = surf_usm_h%us(mm) |
---|
1300 | ENDDO |
---|
1301 | ENDDO |
---|
1302 | |
---|
1303 | CASE ( 'ts' ) |
---|
1304 | DO m = 1, vmea(l)%ns |
---|
1305 | ! |
---|
1306 | !-- Surface data is only available on inner subdomains, not |
---|
1307 | !-- on ghost points. Hence, limit the indices. |
---|
1308 | j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) < nys ) |
---|
1309 | j = MERGE( j , nyn, j > nyn ) |
---|
1310 | i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) < nxl ) |
---|
1311 | i = MERGE( i , nxr, i > nxr ) |
---|
1312 | |
---|
1313 | DO mm = surf_def_h(0)%start_index(j,i), & |
---|
1314 | surf_def_h(0)%end_index(j,i) |
---|
1315 | vmea(l)%measured_vars(m,n) = surf_def_h(0)%ts(mm) |
---|
1316 | ENDDO |
---|
1317 | DO mm = surf_lsm_h%start_index(j,i), & |
---|
1318 | surf_lsm_h%end_index(j,i) |
---|
1319 | vmea(l)%measured_vars(m,n) = surf_lsm_h%ts(mm) |
---|
1320 | ENDDO |
---|
1321 | DO mm = surf_usm_h%start_index(j,i), & |
---|
1322 | surf_usm_h%end_index(j,i) |
---|
1323 | vmea(l)%measured_vars(m,n) = surf_usm_h%ts(mm) |
---|
1324 | ENDDO |
---|
1325 | ENDDO |
---|
1326 | |
---|
1327 | CASE ( 'hfls' ) |
---|
1328 | DO m = 1, vmea(l)%ns |
---|
1329 | ! |
---|
1330 | !-- Surface data is only available on inner subdomains, not |
---|
1331 | !-- on ghost points. Hence, limit the indices. |
---|
1332 | j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) < nys ) |
---|
1333 | j = MERGE( j , nyn, j > nyn ) |
---|
1334 | i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) < nxl ) |
---|
1335 | i = MERGE( i , nxr, i > nxr ) |
---|
1336 | |
---|
1337 | DO mm = surf_def_h(0)%start_index(j,i), & |
---|
1338 | surf_def_h(0)%end_index(j,i) |
---|
1339 | vmea(l)%measured_vars(m,n) = surf_def_h(0)%qsws(mm) |
---|
1340 | ENDDO |
---|
1341 | DO mm = surf_lsm_h%start_index(j,i), & |
---|
1342 | surf_lsm_h%end_index(j,i) |
---|
1343 | vmea(l)%measured_vars(m,n) = surf_lsm_h%qsws(mm) |
---|
1344 | ENDDO |
---|
1345 | DO mm = surf_usm_h%start_index(j,i), & |
---|
1346 | surf_usm_h%end_index(j,i) |
---|
1347 | vmea(l)%measured_vars(m,n) = surf_usm_h%qsws(mm) |
---|
1348 | ENDDO |
---|
1349 | ENDDO |
---|
1350 | |
---|
1351 | CASE ( 'hfss' ) |
---|
1352 | DO m = 1, vmea(l)%ns |
---|
1353 | ! |
---|
1354 | !-- Surface data is only available on inner subdomains, not |
---|
1355 | !-- on ghost points. Hence, limit the indices. |
---|
1356 | j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) < nys ) |
---|
1357 | j = MERGE( j , nyn, j > nyn ) |
---|
1358 | i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) < nxl ) |
---|
1359 | i = MERGE( i , nxr, i > nxr ) |
---|
1360 | |
---|
1361 | DO mm = surf_def_h(0)%start_index(j,i), & |
---|
1362 | surf_def_h(0)%end_index(j,i) |
---|
1363 | vmea(l)%measured_vars(m,n) = surf_def_h(0)%shf(mm) |
---|
1364 | ENDDO |
---|
1365 | DO mm = surf_lsm_h%start_index(j,i), & |
---|
1366 | surf_lsm_h%end_index(j,i) |
---|
1367 | vmea(l)%measured_vars(m,n) = surf_lsm_h%shf(mm) |
---|
1368 | ENDDO |
---|
1369 | DO mm = surf_usm_h%start_index(j,i), & |
---|
1370 | surf_usm_h%end_index(j,i) |
---|
1371 | vmea(l)%measured_vars(m,n) = surf_usm_h%shf(mm) |
---|
1372 | ENDDO |
---|
1373 | ENDDO |
---|
1374 | |
---|
1375 | CASE ( 'rnds' ) |
---|
1376 | IF ( radiation ) THEN |
---|
1377 | DO m = 1, vmea(l)%ns |
---|
1378 | ! |
---|
1379 | !-- Surface data is only available on inner subdomains, not |
---|
1380 | !-- on ghost points. Hence, limit the indices. |
---|
1381 | j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) < nys ) |
---|
1382 | j = MERGE( j , nyn, j > nyn ) |
---|
1383 | i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) < nxl ) |
---|
1384 | i = MERGE( i , nxr, i > nxr ) |
---|
1385 | |
---|
1386 | DO mm = surf_lsm_h%start_index(j,i), & |
---|
1387 | surf_lsm_h%end_index(j,i) |
---|
1388 | vmea(l)%measured_vars(m,n) = surf_lsm_h%rad_net(mm) |
---|
1389 | ENDDO |
---|
1390 | DO mm = surf_usm_h%start_index(j,i), & |
---|
1391 | surf_usm_h%end_index(j,i) |
---|
1392 | vmea(l)%measured_vars(m,n) = surf_usm_h%rad_net(mm) |
---|
1393 | ENDDO |
---|
1394 | ENDDO |
---|
1395 | ENDIF |
---|
1396 | |
---|
1397 | CASE ( 'rsus' ) |
---|
1398 | IF ( radiation ) THEN |
---|
1399 | DO m = 1, vmea(l)%ns |
---|
1400 | ! |
---|
1401 | !-- Surface data is only available on inner subdomains, not |
---|
1402 | !-- on ghost points. Hence, limit the indices. |
---|
1403 | j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) < nys ) |
---|
1404 | j = MERGE( j , nyn, j > nyn ) |
---|
1405 | i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) < nxl ) |
---|
1406 | i = MERGE( i , nxr, i > nxr ) |
---|
1407 | |
---|
1408 | DO mm = surf_lsm_h%start_index(j,i), & |
---|
1409 | surf_lsm_h%end_index(j,i) |
---|
1410 | vmea(l)%measured_vars(m,n) = surf_lsm_h%rad_sw_out(mm) |
---|
1411 | ENDDO |
---|
1412 | DO mm = surf_usm_h%start_index(j,i), & |
---|
1413 | surf_usm_h%end_index(j,i) |
---|
1414 | vmea(l)%measured_vars(m,n) = surf_usm_h%rad_sw_out(mm) |
---|
1415 | ENDDO |
---|
1416 | ENDDO |
---|
1417 | ENDIF |
---|
1418 | |
---|
1419 | CASE ( 'rsds' ) |
---|
1420 | IF ( radiation ) THEN |
---|
1421 | DO m = 1, vmea(l)%ns |
---|
1422 | ! |
---|
1423 | !-- Surface data is only available on inner subdomains, not |
---|
1424 | !-- on ghost points. Hence, limit the indices. |
---|
1425 | j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) < nys ) |
---|
1426 | j = MERGE( j , nyn, j > nyn ) |
---|
1427 | i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) < nxl ) |
---|
1428 | i = MERGE( i , nxr, i > nxr ) |
---|
1429 | |
---|
1430 | DO mm = surf_lsm_h%start_index(j,i), & |
---|
1431 | surf_lsm_h%end_index(j,i) |
---|
1432 | vmea(l)%measured_vars(m,n) = surf_lsm_h%rad_sw_in(mm) |
---|
1433 | ENDDO |
---|
1434 | DO mm = surf_usm_h%start_index(j,i), & |
---|
1435 | surf_usm_h%end_index(j,i) |
---|
1436 | vmea(l)%measured_vars(m,n) = surf_usm_h%rad_sw_in(mm) |
---|
1437 | ENDDO |
---|
1438 | ENDDO |
---|
1439 | ENDIF |
---|
1440 | |
---|
1441 | CASE ( 'rlus' ) |
---|
1442 | IF ( radiation ) THEN |
---|
1443 | DO m = 1, vmea(l)%ns |
---|
1444 | ! |
---|
1445 | !-- Surface data is only available on inner subdomains, not |
---|
1446 | !-- on ghost points. Hence, limit the indices. |
---|
1447 | j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) < nys ) |
---|
1448 | j = MERGE( j , nyn, j > nyn ) |
---|
1449 | i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) < nxl ) |
---|
1450 | i = MERGE( i , nxr, i > nxr ) |
---|
1451 | |
---|
1452 | DO mm = surf_lsm_h%start_index(j,i), & |
---|
1453 | surf_lsm_h%end_index(j,i) |
---|
1454 | vmea(l)%measured_vars(m,n) = surf_lsm_h%rad_lw_out(mm) |
---|
1455 | ENDDO |
---|
1456 | DO mm = surf_usm_h%start_index(j,i), & |
---|
1457 | surf_usm_h%end_index(j,i) |
---|
1458 | vmea(l)%measured_vars(m,n) = surf_usm_h%rad_lw_out(mm) |
---|
1459 | ENDDO |
---|
1460 | ENDDO |
---|
1461 | ENDIF |
---|
1462 | |
---|
1463 | CASE ( 'rlds' ) |
---|
1464 | IF ( radiation ) THEN |
---|
1465 | DO m = 1, vmea(l)%ns |
---|
1466 | ! |
---|
1467 | !-- Surface data is only available on inner subdomains, not |
---|
1468 | !-- on ghost points. Hence, limit the indices. |
---|
1469 | j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) < nys ) |
---|
1470 | j = MERGE( j , nyn, j > nyn ) |
---|
1471 | i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) < nxl ) |
---|
1472 | i = MERGE( i , nxr, i > nxr ) |
---|
1473 | |
---|
1474 | DO mm = surf_lsm_h%start_index(j,i), & |
---|
1475 | surf_lsm_h%end_index(j,i) |
---|
1476 | vmea(l)%measured_vars(m,n) = surf_lsm_h%rad_lw_in(mm) |
---|
1477 | ENDDO |
---|
1478 | DO mm = surf_usm_h%start_index(j,i), & |
---|
1479 | surf_usm_h%end_index(j,i) |
---|
1480 | vmea(l)%measured_vars(m,n) = surf_usm_h%rad_lw_in(mm) |
---|
1481 | ENDDO |
---|
1482 | ENDDO |
---|
1483 | ENDIF |
---|
1484 | |
---|
1485 | CASE ( 'rsd' ) |
---|
1486 | IF ( radiation ) THEN |
---|
1487 | DO m = 1, vmea(l)%ns |
---|
1488 | k = MERGE( 0, vmea(l)%k(m), radiation_scheme /= 'rrtmg' ) |
---|
1489 | j = vmea(l)%j(m) |
---|
1490 | i = vmea(l)%i(m) |
---|
1491 | |
---|
1492 | vmea(l)%measured_vars(m,n) = rad_sw_in(k,j,i) |
---|
1493 | ENDDO |
---|
1494 | ENDIF |
---|
1495 | |
---|
1496 | CASE ( 'rsu' ) |
---|
1497 | IF ( radiation ) THEN |
---|
1498 | DO m = 1, vmea(l)%ns |
---|
1499 | k = MERGE( 0, vmea(l)%k(m), radiation_scheme /= 'rrtmg' ) |
---|
1500 | j = vmea(l)%j(m) |
---|
1501 | i = vmea(l)%i(m) |
---|
1502 | |
---|
1503 | vmea(l)%measured_vars(m,n) = rad_sw_out(k,j,i) |
---|
1504 | ENDDO |
---|
1505 | ENDIF |
---|
1506 | |
---|
1507 | CASE ( 'rlu' ) |
---|
1508 | IF ( radiation ) THEN |
---|
1509 | DO m = 1, vmea(l)%ns |
---|
1510 | k = MERGE( 0, vmea(l)%k(m), radiation_scheme /= 'rrtmg' ) |
---|
1511 | j = vmea(l)%j(m) |
---|
1512 | i = vmea(l)%i(m) |
---|
1513 | |
---|
1514 | vmea(l)%measured_vars(m,n) = rad_lw_out(k,j,i) |
---|
1515 | ENDDO |
---|
1516 | ENDIF |
---|
1517 | |
---|
1518 | CASE ( 'rld' ) |
---|
1519 | IF ( radiation ) THEN |
---|
1520 | DO m = 1, vmea(l)%ns |
---|
1521 | k = MERGE( 0, vmea(l)%k(m), radiation_scheme /= 'rrtmg' ) |
---|
1522 | j = vmea(l)%j(m) |
---|
1523 | i = vmea(l)%i(m) |
---|
1524 | |
---|
1525 | vmea(l)%measured_vars(m,n) = rad_lw_in(k,j,i) |
---|
1526 | ENDDO |
---|
1527 | ENDIF |
---|
1528 | |
---|
1529 | CASE ( 'rsddif' ) |
---|
1530 | IF ( radiation ) THEN |
---|
1531 | DO m = 1, vmea(l)%ns |
---|
1532 | j = vmea(l)%j(m) |
---|
1533 | i = vmea(l)%i(m) |
---|
1534 | |
---|
1535 | vmea(l)%measured_vars(m,n) = rad_sw_in_diff(j,i) |
---|
1536 | ENDDO |
---|
1537 | ENDIF |
---|
1538 | |
---|
1539 | CASE ( 't_soil' ) |
---|
1540 | DO m = 1, vmea(l)%ns_soil |
---|
1541 | i = vmea(l)%i_soil(m) |
---|
1542 | j = vmea(l)%j_soil(m) |
---|
1543 | k = vmea(l)%k_soil(m) |
---|
1544 | |
---|
1545 | match_lsm = surf_lsm_h%start_index(j,i) <= & |
---|
1546 | surf_lsm_h%end_index(j,i) |
---|
1547 | match_usm = surf_usm_h%start_index(j,i) <= & |
---|
1548 | surf_usm_h%end_index(j,i) |
---|
1549 | |
---|
1550 | IF ( match_lsm ) THEN |
---|
1551 | mm = surf_lsm_h%start_index(j,i) |
---|
1552 | vmea(l)%measured_vars_soil(m,n) = t_soil_h%var_2d(k,mm) |
---|
1553 | ENDIF |
---|
1554 | |
---|
1555 | IF ( match_usm ) THEN |
---|
1556 | mm = surf_usm_h%start_index(j,i) |
---|
1557 | vmea(l)%measured_vars_soil(m,n) = t_wall_h(k,mm) |
---|
1558 | ENDIF |
---|
1559 | ENDDO |
---|
1560 | |
---|
1561 | CASE ( 'm_soil' ) |
---|
1562 | DO m = 1, vmea(l)%ns_soil |
---|
1563 | i = vmea(l)%i_soil(m) |
---|
1564 | j = vmea(l)%j_soil(m) |
---|
1565 | k = vmea(l)%k_soil(m) |
---|
1566 | |
---|
1567 | match_lsm = surf_lsm_h%start_index(j,i) <= & |
---|
1568 | surf_lsm_h%end_index(j,i) |
---|
1569 | |
---|
1570 | IF ( match_lsm ) THEN |
---|
1571 | mm = surf_lsm_h%start_index(j,i) |
---|
1572 | vmea(l)%measured_vars_soil(m,n) = m_soil_h%var_2d(k,mm) |
---|
1573 | ENDIF |
---|
1574 | |
---|
1575 | ENDDO |
---|
1576 | ! |
---|
1577 | !-- More will follow ... |
---|
1578 | |
---|
1579 | ! |
---|
1580 | !-- No match found - just set a fill value |
---|
1581 | CASE DEFAULT |
---|
1582 | vmea(l)%measured_vars(:,n) = vmea(l)%fillout |
---|
1583 | END SELECT |
---|
1584 | |
---|
1585 | ENDDO |
---|
1586 | |
---|
1587 | ENDDO |
---|
1588 | |
---|
1589 | END SUBROUTINE vm_sampling |
---|
1590 | |
---|
1591 | |
---|
1592 | END MODULE virtual_measurement_mod |
---|