source: palm/trunk/SOURCE/user_module.f90 @ 4142

Last change on this file since 4142 was 3986, checked in by Giersch, 5 years ago

Case statement in gust_rrd_local modifed, redundant integration of control parameters in user_rrd_global removed

  • Property svn:keywords set to Id
File size: 37.3 KB
Line 
1!> @file user_module.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2019 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: user_module.f90 3986 2019-05-20 14:08:14Z suehring $
27! Redundant integration of control parameters in user_rrd_global removed
28!
29! 3911 2019-04-17 12:26:19Z knoop
30! Bugfix: added before_prognostic_equations case in user_actions
31!
32! 3768 2019-02-27 14:35:58Z raasch
33! variables commented + statements added to avoid compiler warnings about unused variables
34!
35! 3767 2019-02-27 08:18:02Z raasch
36! unused variable for file index removed from rrd-subroutines parameter list
37!
38! 3747 2019-02-16 15:15:23Z gronemeier
39! Add routine user_init_arrays
40!
41! 3703 2019-01-29 16:43:53Z knoop
42! An example for a user defined global variable has been added (Giersch)
43!
44! 2718 2018-01-02 08:49:38Z suehring
45! Corrected "Former revisions" section
46!
47! 2696 2017-12-14 17:12:51Z kanani
48! Change in file header (GPL part)
49!
50! 2101 2017-01-05 16:42:31Z suehring
51!
52! 2000 2016-08-20 18:09:15Z knoop
53! Forced header and separation lines into 80 columns
54!
55! 1873 2016-04-18 14:50:06Z maronga
56! Module renamed (removed _mod)
57!
58!
59! 1850 2016-04-08 13:29:27Z maronga
60! Module renamed
61!
62!
63! 1682 2015-10-07 23:56:08Z knoop
64! Code annotations made doxygen readable
65!
66! 1320 2014-03-20 08:40:49Z raasch
67! kind-parameters added to all INTEGER and REAL declaration statements,
68! kinds are defined in new module kinds,
69! old module precision_kind is removed,
70! revision history before 2012 removed,
71! comment fields (!:) to be used for variable explanations added to
72! all variable declaration statements
73!
74! 1036 2012-10-22 13:43:42Z raasch
75! code put under GPL (PALM 3.9)
76!
77! Revision 1.1  1998/03/24 15:29:04  raasch
78! Initial revision
79!
80!
81! Description:
82! ------------
83!> Declaration of user-defined variables. This module may only be used
84!> in the user-defined routines (contained in user_interface.f90).
85!------------------------------------------------------------------------------!
86 MODULE user
87
88
89    USE arrays_3d
90
91    USE control_parameters
92
93    USE cpulog
94
95    USE indices
96
97    USE kinds
98
99    USE pegrid
100
101    USE statistics
102
103    USE surface_mod
104
105    IMPLICIT NONE
106
107    INTEGER(iwp) ::  dots_num_palm   !<
108    INTEGER(iwp) ::  dots_num_user = 0  !<
109    INTEGER(iwp) ::  user_idummy     !<
110   
111    LOGICAL ::  user_module_enabled = .FALSE.   !<
112   
113    REAL(wp) ::  user_rdummy   !<
114
115!
116!-- Sample for user-defined output
117!    REAL(wp) :: global_parameter !< user defined global parameter
118!
119!    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u2       !< user defined array
120!    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u2_av    !< user defined array
121!    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  ustvst   !< user defined array
122
123    SAVE
124
125    PRIVATE
126
127!
128!- Public functions
129    PUBLIC &
130       user_parin, &
131       user_check_parameters, &
132       user_check_data_output_ts, &
133       user_check_data_output_pr, &
134       user_check_data_output, &
135       user_define_netcdf_grid, &
136       user_init, &
137       user_init_arrays, &
138       user_header, &
139       user_actions, &
140       user_3d_data_averaging, &
141       user_data_output_2d, &
142       user_data_output_3d, &
143       user_statistics, &
144       user_rrd_global, &
145       user_rrd_local, &
146       user_wrd_global, &
147       user_wrd_local, &
148       user_last_actions
149
150!
151!- Public parameters, constants and initial values
152   PUBLIC &
153      user_module_enabled
154
155    INTERFACE user_parin
156       MODULE PROCEDURE user_parin
157    END INTERFACE user_parin
158
159    INTERFACE user_check_parameters
160       MODULE PROCEDURE user_check_parameters
161    END INTERFACE user_check_parameters
162
163    INTERFACE user_check_data_output_ts
164       MODULE PROCEDURE user_check_data_output_ts
165    END INTERFACE user_check_data_output_ts
166
167    INTERFACE user_check_data_output_pr
168       MODULE PROCEDURE user_check_data_output_pr
169    END INTERFACE user_check_data_output_pr
170
171    INTERFACE user_check_data_output
172       MODULE PROCEDURE user_check_data_output
173    END INTERFACE user_check_data_output
174
175    INTERFACE user_define_netcdf_grid
176       MODULE PROCEDURE user_define_netcdf_grid
177    END INTERFACE user_define_netcdf_grid
178
179    INTERFACE user_init
180       MODULE PROCEDURE user_init
181    END INTERFACE user_init
182
183    INTERFACE user_init_arrays
184       MODULE PROCEDURE user_init_arrays
185    END INTERFACE user_init_arrays
186
187    INTERFACE user_header
188       MODULE PROCEDURE user_header
189    END INTERFACE user_header
190
191    INTERFACE user_actions
192       MODULE PROCEDURE user_actions
193       MODULE PROCEDURE user_actions_ij
194    END INTERFACE user_actions
195
196    INTERFACE user_3d_data_averaging
197       MODULE PROCEDURE user_3d_data_averaging
198    END INTERFACE user_3d_data_averaging
199
200    INTERFACE user_data_output_2d
201       MODULE PROCEDURE user_data_output_2d
202    END INTERFACE user_data_output_2d
203
204    INTERFACE user_data_output_3d
205       MODULE PROCEDURE user_data_output_3d
206    END INTERFACE user_data_output_3d
207
208    INTERFACE user_statistics
209       MODULE PROCEDURE user_statistics
210    END INTERFACE user_statistics
211
212    INTERFACE user_rrd_global
213       MODULE PROCEDURE user_rrd_global
214    END INTERFACE user_rrd_global
215
216    INTERFACE user_rrd_local
217       MODULE PROCEDURE user_rrd_local
218    END INTERFACE user_rrd_local
219
220    INTERFACE user_wrd_global
221       MODULE PROCEDURE user_wrd_global
222    END INTERFACE user_wrd_global
223
224    INTERFACE user_wrd_local
225       MODULE PROCEDURE user_wrd_local
226    END INTERFACE user_wrd_local
227
228    INTERFACE user_last_actions
229       MODULE PROCEDURE user_last_actions
230    END INTERFACE user_last_actions
231
232
233 CONTAINS
234
235
236!------------------------------------------------------------------------------!
237! Description:
238! ------------
239!> Parin for &user_parameters for user module
240!------------------------------------------------------------------------------!
241 SUBROUTINE user_parin
242
243
244    CHARACTER (LEN=80) ::  line   !<
245
246    INTEGER(iwp) ::  i                 !<
247    INTEGER(iwp) ::  j                 !<
248
249
250    NAMELIST /user_parameters/  &
251       user_module_enabled, &
252       data_output_pr_user, &
253       data_output_user, &
254       region, &
255       data_output_masks_user
256
257!
258!-- Next statement is to avoid compiler warnings about unused variables. Please remove in case
259!-- that you are using them.
260    IF ( dots_num_palm == 0  .OR.  dots_num_user == 0  .OR.  user_idummy == 0  .OR.                &
261         user_rdummy == 0.0_wp )  CONTINUE
262
263!
264!-- Set revision number of this default interface version. It will be checked within
265!-- the main program (palm). Please change the revision number in case that the
266!-- current revision does not match with previous revisions (e.g. if routines
267!-- have been added/deleted or if parameter lists in subroutines have been changed).
268    user_interface_current_revision = 'r3703'
269
270!
271!-- Position the namelist-file at the beginning (it was already opened in
272!-- parin), search for user-defined namelist-group ("userpar", but any other
273!-- name can be choosed) and position the file at this line.
274    REWIND ( 11 )
275
276    line = ' '
277    DO WHILE ( INDEX( line, '&user_parameters' ) == 0 )
278       READ ( 11, '(A)', END=12 )  line
279    ENDDO
280    BACKSPACE ( 11 )
281
282!-- Set default module switch to true
283    user_module_enabled = .TRUE.
284
285!-- Read user-defined namelist
286    READ ( 11, user_parameters, ERR = 10 )
287
288    GOTO 12
289
29010  BACKSPACE( 11 )
291    READ( 11 , '(A)') line
292    CALL parin_fail_message( 'user_parameters', line )
293
29412  CONTINUE
295
296!
297!-- Determine the number of user-defined profiles and append them to the
298!-- standard data output (data_output_pr)
299    IF ( user_module_enabled )  THEN
300       IF ( data_output_pr_user(1) /= ' ' )  THEN
301          i = 1
302          DO WHILE ( data_output_pr(i) /= ' '  .AND.  i <= 100 )
303             i = i + 1
304          ENDDO
305          j = 1
306          DO WHILE ( data_output_pr_user(j) /= ' '  .AND.  j <= 100 )
307             data_output_pr(i) = data_output_pr_user(j)
308             max_pr_user_tmp   = max_pr_user_tmp + 1
309             i = i + 1
310             j = j + 1
311          ENDDO
312       ENDIF
313    ENDIF
314
315
316 END SUBROUTINE user_parin
317
318
319!------------------------------------------------------------------------------!
320! Description:
321! ------------
322!> Check &userpar control parameters and deduce further quantities.
323!------------------------------------------------------------------------------!
324 SUBROUTINE user_check_parameters
325
326
327!-- Here the user may add code to check the validity of further &userpar
328!-- control parameters or deduce further quantities.
329
330
331 END SUBROUTINE user_check_parameters
332
333
334!------------------------------------------------------------------------------!
335! Description:
336! ------------
337!> Set module-specific timeseries units and labels
338!------------------------------------------------------------------------------!
339 SUBROUTINE user_check_data_output_ts( dots_max, dots_num, dots_label, dots_unit )
340
341
342    INTEGER(iwp),      INTENT(IN)     ::  dots_max
343    INTEGER(iwp),      INTENT(INOUT)  ::  dots_num
344    CHARACTER (LEN=*), DIMENSION(dots_max), INTENT(INOUT)  :: dots_label
345    CHARACTER (LEN=*), DIMENSION(dots_max), INTENT(INOUT)  :: dots_unit
346
347!
348!-- Next line is to avoid compiler warning about unused variables. Please remove.
349    IF ( dots_num == 0  .OR.  dots_label(1)(1:1) == ' '  .OR.  dots_unit(1)(1:1) == ' ' )  CONTINUE
350
351!
352!-- Sample for user-defined time series
353!-- For each time series quantity you have to give a label and a unit,
354!-- which will be used for the NetCDF file. They must not contain more than
355!-- seven characters. The value of dots_num has to be increased by the
356!-- number of new time series quantities. Its old value has to be store in
357!-- dots_num_palm. See routine user_statistics on how to output calculate
358!-- and output these quantities.
359
360!    dots_num_palm = dots_num
361
362!    dots_num = dots_num + 1
363!    dots_num_user = dots_num_user + 1
364!    dots_label(dots_num) = 'abs_umx'
365!    dots_unit(dots_num)  = 'm/s'
366
367!    dots_num = dots_num + 1
368!    dots_num_user = dots_num_user + 1
369!    dots_label(dots_num) = 'abs_vmx'
370!    dots_unit(dots_num)  = 'm/s'
371
372
373 END SUBROUTINE user_check_data_output_ts
374
375
376!------------------------------------------------------------------------------!
377! Description:
378! ------------
379!> Set the unit of user defined profile output quantities. For those variables
380!> not recognized by the user, the parameter unit is set to "illegal", which
381!> tells the calling routine that the output variable is not defined and leads
382!> to a program abort.
383!------------------------------------------------------------------------------!
384 SUBROUTINE user_check_data_output_pr( variable, var_count, unit, dopr_unit )
385
386
387    USE profil_parameter
388
389
390    CHARACTER (LEN=*) ::  unit     !<
391    CHARACTER (LEN=*) ::  variable !<
392    CHARACTER (LEN=*) ::  dopr_unit !< local value of dopr_unit
393
394!    INTEGER(iwp) ::  user_pr_index !<
395    INTEGER(iwp) ::  var_count     !<
396
397!
398!-- Next line is to avoid compiler warning about unused variables. Please remove.
399    IF ( unit(1:1) == ' '  .OR.  dopr_unit(1:1) == ' '  .OR.  var_count == 0 )  CONTINUE
400
401    SELECT CASE ( TRIM( variable ) )
402
403!
404!--    Uncomment and extend the following lines, if necessary.
405!--    Add additional CASE statements depending on the number of quantities
406!--    for which profiles are to be calculated. The respective calculations
407!--    to be performed have to be added in routine user_statistics.
408!--    The quantities are (internally) identified by a user-profile-number
409!--    (see variable "user_pr_index" below). The first user-profile must be assigned
410!--    the number "pr_palm+1", the second one "pr_palm+2", etc. The respective
411!--    user-profile-numbers have also to be used in routine user_statistics!
412!       CASE ( 'u*v*' )                      ! quantity string as given in
413!                                            ! data_output_pr_user
414!          user_pr_index = pr_palm + 1
415!          dopr_index(var_count)  = user_pr_index    ! quantities' user-profile-number
416!          dopr_unit = 'm2/s2'  ! quantity unit
417!          unit = dopr_unit
418!          hom(:,2,user_pr_index,:)       = SPREAD( zu, 2, statistic_regions+1 )
419!                                            ! grid on which the quantity is
420!                                            ! defined (use zu or zw)
421
422       CASE DEFAULT
423          unit = 'illegal'
424
425    END SELECT
426
427
428 END SUBROUTINE user_check_data_output_pr
429
430
431!------------------------------------------------------------------------------!
432! Description:
433! ------------
434!> Set the unit of user defined output quantities. For those variables
435!> not recognized by the user, the parameter unit is set to "illegal", which
436!> tells the calling routine that the output variable is not defined and leads
437!> to a program abort.
438!------------------------------------------------------------------------------!
439 SUBROUTINE user_check_data_output( variable, unit )
440
441
442    CHARACTER (LEN=*) ::  unit     !<
443    CHARACTER (LEN=*) ::  variable !<
444
445
446    SELECT CASE ( TRIM( variable ) )
447
448!
449!--    Uncomment and extend the following lines, if necessary
450!       CASE ( 'u2' )
451!          unit = 'm2/s2'
452!
453!       CASE ( 'u*v*' )
454!          unit = 'm2/s2'
455!
456       CASE DEFAULT
457          unit = 'illegal'
458
459    END SELECT
460
461
462 END SUBROUTINE user_check_data_output
463
464
465!------------------------------------------------------------------------------!
466! Description:
467! ------------
468!> Initialize user-defined arrays
469!------------------------------------------------------------------------------!
470 SUBROUTINE user_init_arrays
471
472
473!    INTEGER(iwp) :: i       !< loop index
474!    INTEGER(iwp) :: j       !< loop index
475!    INTEGER(iwp) :: region  !< index for loop over statistic regions
476
477!
478!-- Allocate user-defined arrays and set flags for statistic regions.
479!-- Sample for user-defined output
480!    ALLOCATE( u2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
481!    ALLOCATE( ustvst(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
482
483!
484!-- Example for defining a statistic region:
485!     IF ( statistic_regions >= 1 )  THEN
486!        region = 1
487!
488!        rmask(:,:,region) = 0.0_wp
489!        DO  i = nxl, nxr
490!           IF ( i >= INT( 0.25 * nx ) .AND. i <= INT( 0.75 * nx ) )  THEN
491!              DO  j = nys, nyn
492!                 IF ( i >= INT( 0.25 * ny ) .AND. i <= INT( 0.75 * ny ) )  THEN
493!                    rmask(j,i,region) = 1.0_wp
494!                 ENDIF
495!              ENDDO
496!           ENDIF
497!        ENDDO
498!
499!     ENDIF
500
501 END SUBROUTINE user_init_arrays
502
503
504!------------------------------------------------------------------------------!
505! Description:
506! ------------
507!> Execution of user-defined initializing actions
508!------------------------------------------------------------------------------!
509 SUBROUTINE user_init
510
511
512!    CHARACTER (LEN=20) :: field_char   !<
513!
514!-- Here the user-defined initializing actions follow:
515!-- Sample for user-defined output
516!    ustvst = 0.0_wp
517
518
519 END SUBROUTINE user_init
520
521
522!------------------------------------------------------------------------------!
523! Description:
524! ------------
525!> Set the grids on which user-defined output quantities are defined.
526!> Allowed values for grid_x are "x" and "xu", for grid_y "y" and "yv", and
527!> for grid_z "zu" and "zw".
528!------------------------------------------------------------------------------!
529 SUBROUTINE user_define_netcdf_grid( variable, found, grid_x, grid_y, grid_z )
530
531
532    CHARACTER (LEN=*) ::  grid_x     !<
533    CHARACTER (LEN=*) ::  grid_y     !<
534    CHARACTER (LEN=*) ::  grid_z     !<
535    CHARACTER (LEN=*) ::  variable   !<
536
537    LOGICAL ::  found   !<
538
539
540    SELECT CASE ( TRIM( variable ) )
541
542!
543!--    Uncomment and extend the following lines, if necessary
544!       CASE ( 'u2', 'u2_xy', 'u2_xz', 'u2_yz' )
545!          found  = .TRUE.
546!          grid_x = 'xu'
547!          grid_y = 'y'
548!          grid_z = 'zu'
549
550!       CASE ( 'u*v*', 'u*v*_xy', 'u*v*_xz', 'u*v*_yz' )
551!          found  = .TRUE.
552!          grid_x = 'x'
553!          grid_y = 'y'
554!          grid_z = 'zu'
555
556       CASE DEFAULT
557          found  = .FALSE.
558          grid_x = 'none'
559          grid_y = 'none'
560          grid_z = 'none'
561
562    END SELECT
563
564
565 END SUBROUTINE user_define_netcdf_grid
566
567
568
569
570!------------------------------------------------------------------------------!
571! Description:
572! ------------
573!> Print a header with user-defined information.
574!------------------------------------------------------------------------------!
575 SUBROUTINE user_header( io )
576
577
578    INTEGER(iwp) ::  i    !<
579    INTEGER(iwp) ::  io   !<
580
581!
582!-- If no user-defined variables are read from the namelist-file, no
583!-- information will be printed.
584    IF ( .NOT. user_module_enabled )  THEN
585       WRITE ( io, 100 )
586       RETURN
587    ENDIF
588
589!
590!-- Printing the information.
591    WRITE ( io, 110 )
592
593    IF ( statistic_regions /= 0 )  THEN
594       WRITE ( io, 200 )
595       DO  i = 0, statistic_regions
596          WRITE ( io, 201 )  i, region(i)
597       ENDDO
598    ENDIF
599
600!
601!-- Format-descriptors
602100 FORMAT (//' *** no user-defined variables found'/)
603110 FORMAT (//1X,78('#')                                                       &
604            //' User-defined variables and actions:'/                          &
605              ' -----------------------------------'//)
606200 FORMAT (' Output of profiles and time series for following regions:' /)
607201 FORMAT (4X,'Region ',I1,':   ',A)
608
609
610 END SUBROUTINE user_header
611
612
613!------------------------------------------------------------------------------!
614! Description:
615! ------------
616!> Call for all grid points
617!------------------------------------------------------------------------------!
618 SUBROUTINE user_actions( location )
619
620
621    CHARACTER (LEN=*) ::  location !<
622
623!    INTEGER(iwp) ::  i !<
624!    INTEGER(iwp) ::  j !<
625!    INTEGER(iwp) ::  k !<
626
627    CALL cpu_log( log_point(24), 'user_actions', 'start' )
628
629!
630!-- Here the user-defined actions follow
631!-- No calls for single grid points are allowed at locations before and
632!-- after the timestep, since these calls are not within an i,j-loop
633    SELECT CASE ( location )
634
635       CASE ( 'before_timestep' )
636!
637!--       Enter actions to be done before every timestep here
638
639       CASE ( 'before_prognostic_equations' )
640!
641!--       Enter actions to be done before all prognostic equations here
642
643       CASE ( 'after_integration' )
644!
645!--       Enter actions to be done after every time integration (before
646!--       data output)
647!--       Sample for user-defined output:
648!          DO  i = nxlg, nxrg
649!             DO  j = nysg, nyng
650!                DO  k = nzb, nzt
651!                   u2(k,j,i) = u(k,j,i)**2
652!                ENDDO
653!             ENDDO
654!          ENDDO
655!          DO  i = nxlg, nxr
656!             DO  j = nysg, nyn
657!                DO  k = nzb, nzt+1
658!                   ustvst(k,j,i) =  &
659!                      ( 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) - hom(k,1,1,0) ) * &
660!                      ( 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) - hom(k,1,2,0) )
661!                ENDDO
662!             ENDDO
663!          ENDDO
664
665
666       CASE ( 'after_timestep' )
667!
668!--       Enter actions to be done after every timestep here
669
670
671       CASE ( 'u-tendency' )
672!
673!--       Enter actions to be done in the u-tendency term here
674
675
676       CASE ( 'v-tendency' )
677
678
679       CASE ( 'w-tendency' )
680
681
682       CASE ( 'pt-tendency' )
683
684
685       CASE ( 'sa-tendency' )
686
687
688       CASE ( 'e-tendency' )
689
690
691       CASE ( 'q-tendency' )
692
693
694       CASE ( 's-tendency' )
695
696
697       CASE DEFAULT
698          CONTINUE
699
700    END SELECT
701
702    CALL cpu_log( log_point(24), 'user_actions', 'stop' )
703
704 END SUBROUTINE user_actions
705
706
707!------------------------------------------------------------------------------!
708! Description:
709! ------------
710!> Call for grid point i,j
711!------------------------------------------------------------------------------!
712 SUBROUTINE user_actions_ij( i, j, location )
713
714
715    CHARACTER (LEN=*) ::  location
716
717    INTEGER(iwp) ::  i
718    INTEGER(iwp) ::  j
719
720!
721!-- Here the user-defined actions follow
722    SELECT CASE ( location )
723
724       CASE ( 'u-tendency' )
725
726!
727!--       Next line is to avoid compiler warning about unused variables. Please remove.
728          IF ( i == 0  .OR.  j == 0 )  CONTINUE
729
730!
731!--       Enter actions to be done in the u-tendency term here
732
733
734       CASE ( 'v-tendency' )
735
736
737       CASE ( 'w-tendency' )
738
739
740       CASE ( 'pt-tendency' )
741
742
743       CASE ( 'sa-tendency' )
744
745
746       CASE ( 'e-tendency' )
747
748
749       CASE ( 'q-tendency' )
750
751
752       CASE ( 's-tendency' )
753
754
755       CASE DEFAULT
756          CONTINUE
757
758    END SELECT
759
760 END SUBROUTINE user_actions_ij
761
762
763!------------------------------------------------------------------------------!
764! Description:
765! ------------
766!> Sum up and time-average user-defined output quantities as well as allocate
767!> the array necessary for storing the average.
768!------------------------------------------------------------------------------!
769 SUBROUTINE user_3d_data_averaging( mode, variable )
770
771
772    CHARACTER (LEN=*) ::  mode    !<
773    CHARACTER (LEN=*) :: variable !<
774
775!    INTEGER(iwp) ::  i !<
776!    INTEGER(iwp) ::  j !<
777!    INTEGER(iwp) ::  k !<
778
779    IF ( mode == 'allocate' )  THEN
780
781       SELECT CASE ( TRIM( variable ) )
782
783!
784!--       Uncomment and extend the following lines, if necessary.
785!--       The arrays for storing the user defined quantities (here u2_av) have
786!--       to be declared and defined by the user!
787!--       Sample for user-defined output:
788!          CASE ( 'u2' )
789!             IF ( .NOT. ALLOCATED( u2_av ) )  THEN
790!                ALLOCATE( u2_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
791!             ENDIF
792!             u2_av = 0.0_wp
793
794          CASE DEFAULT
795             CONTINUE
796
797       END SELECT
798
799    ELSEIF ( mode == 'sum' )  THEN
800
801       SELECT CASE ( TRIM( variable ) )
802
803!
804!--       Uncomment and extend the following lines, if necessary.
805!--       The arrays for storing the user defined quantities (here u2 and
806!--       u2_av) have to be declared and defined by the user!
807!--       Sample for user-defined output:
808!          CASE ( 'u2' )
809!             IF ( ALLOCATED( u2_av ) ) THEN
810!                DO  i = nxlg, nxrg
811!                   DO  j = nysg, nyng
812!                      DO  k = nzb, nzt+1
813!                         u2_av(k,j,i) = u2_av(k,j,i) + u2(k,j,i)
814!                      ENDDO
815!                   ENDDO
816!                ENDDO
817!             ENDIF
818
819          CASE DEFAULT
820             CONTINUE
821
822       END SELECT
823
824    ELSEIF ( mode == 'average' )  THEN
825
826       SELECT CASE ( TRIM( variable ) )
827
828!
829!--       Uncomment and extend the following lines, if necessary.
830!--       The arrays for storing the user defined quantities (here u2_av) have
831!--       to be declared and defined by the user!
832!--       Sample for user-defined output:
833!          CASE ( 'u2' )
834!             IF ( ALLOCATED( u2_av ) ) THEN
835!                DO  i = nxlg, nxrg
836!                   DO  j = nysg, nyng
837!                      DO  k = nzb, nzt+1
838!                         u2_av(k,j,i) = u2_av(k,j,i) / REAL( average_count_3d, KIND=wp )
839!                      ENDDO
840!                   ENDDO
841!                ENDDO
842!             ENDIF
843
844       END SELECT
845
846    ENDIF
847
848
849 END SUBROUTINE user_3d_data_averaging
850
851
852!------------------------------------------------------------------------------!
853! Description:
854! ------------
855!> Resorts the user-defined output quantity with indices (k,j,i) to a
856!> temporary array with indices (i,j,k) and sets the grid on which it is defined.
857!> Allowed values for grid are "zu" and "zw".
858!------------------------------------------------------------------------------!
859 SUBROUTINE user_data_output_2d( av, variable, found, grid, local_pf, two_d, nzb_do, nzt_do )
860
861
862    CHARACTER (LEN=*) ::  grid     !<
863    CHARACTER (LEN=*) ::  variable !<
864
865    INTEGER(iwp) ::  av     !< flag to control data output of instantaneous or time-averaged data
866!    INTEGER(iwp) ::  i      !< grid index along x-direction
867!    INTEGER(iwp) ::  j      !< grid index along y-direction
868!    INTEGER(iwp) ::  k      !< grid index along z-direction
869!    INTEGER(iwp) ::  m      !< running index surface elements
870    INTEGER(iwp) ::  nzb_do !< lower limit of the domain (usually nzb)
871    INTEGER(iwp) ::  nzt_do !< upper limit of the domain (usually nzt+1)
872
873    LOGICAL      ::  found !<
874    LOGICAL      ::  two_d !< flag parameter that indicates 2D variables (horizontal cross sections)
875
876!    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
877
878    REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !<
879
880!
881!-- Next line is to avoid compiler warning about unused variables. Please remove.
882    IF ( av == 0  .OR.  local_pf(nxl,nys,nzb_do) == 0.0_wp  .OR.  two_d )  CONTINUE
883
884
885    found = .TRUE.
886
887    SELECT CASE ( TRIM( variable ) )
888
889!
890!--    Uncomment and extend the following lines, if necessary.
891!--    The arrays for storing the user defined quantities (here u2 and u2_av)
892!--    have to be declared and defined by the user!
893!--    Sample for user-defined output:
894!       CASE ( 'u2_xy', 'u2_xz', 'u2_yz' )
895!          IF ( av == 0 )  THEN
896!             DO  i = nxl, nxr
897!                DO  j = nys, nyn
898!                   DO  k = nzb_do, nzt_do
899!                      local_pf(i,j,k) = u2(k,j,i)
900!                   ENDDO
901!                ENDDO
902!             ENDDO
903!          ELSE
904!             IF ( .NOT. ALLOCATED( u2_av ) ) THEN
905!                ALLOCATE( u2_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
906!                u2_av = REAL( fill_value, KIND = wp )
907!             ENDIF
908!             DO  i = nxl, nxr
909!                DO  j = nys, nyn
910!                   DO  k = nzb_do, nzt_do
911!                      local_pf(i,j,k) = u2_av(k,j,i)
912!                   ENDDO
913!                ENDDO
914!             ENDDO
915!          ENDIF
916!
917!          grid = 'zu'
918!
919!--    In case two-dimensional surface variables are output, the user
920!--    has to access related surface-type. Uncomment and extend following lines
921!--    appropriately (example output of vertical surface momentum flux of u-
922!--    component). Please note, surface elements can be distributed over
923!--    several data type, depending on their respective surface properties.
924!       CASE ( 'usws_xy' )
925!          IF ( av == 0 )  THEN
926!
927!--           Horizontal default-type surfaces
928!             DO  m = 1, surf_def_h(0)%ns
929!                i = surf_def_h(0)%i(m)
930!                j = surf_def_h(0)%j(m)
931!                local_pf(i,j,1) = surf_def_h(0)%usws(m)
932!             ENDDO
933!
934!--           Horizontal natural-type surfaces
935!             DO  m = 1, surf_lsm_h%ns
936!                i = surf_lsm_h%i(m)
937!                j = surf_lsm_h%j(m)
938!                local_pf(i,j,1) = surf_lsm_h%usws(m)
939!             ENDDO
940!
941!--           Horizontal urban-type surfaces
942!             DO  m = 1, surf_usm_h%ns
943!                i = surf_usm_h%i(m)
944!                j = surf_usm_h%j(m)
945!                local_pf(i,j,1) = surf_usm_h%usws(m)
946!             ENDDO
947!          ENDIF
948!
949!          grid = 'zu'
950!--       
951
952
953       CASE DEFAULT
954          found = .FALSE.
955          grid  = 'none'
956
957    END SELECT
958
959
960 END SUBROUTINE user_data_output_2d
961
962
963!------------------------------------------------------------------------------!
964! Description:
965! ------------
966!> Resorts the user-defined output quantity with indices (k,j,i) to a
967!> temporary array with indices (i,j,k).
968!------------------------------------------------------------------------------!
969 SUBROUTINE user_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
970
971
972    CHARACTER (LEN=*) ::  variable !<
973
974    INTEGER(iwp) ::  av    !<
975!    INTEGER(iwp) ::  i     !<
976!    INTEGER(iwp) ::  j     !<
977!    INTEGER(iwp) ::  k     !<
978    INTEGER(iwp) ::  nzb_do !< lower limit of the data output (usually 0)
979    INTEGER(iwp) ::  nzt_do !< vertical upper limit of the data output (usually nz_do3d)
980
981    LOGICAL      ::  found !<
982
983!    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
984
985    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !<
986
987!
988!-- Next line is to avoid compiler warning about unused variables. Please remove.
989    IF ( av == 0  .OR.  local_pf(nxl,nys,nzb_do) == 0.0_wp )  CONTINUE
990
991
992    found = .TRUE.
993
994    SELECT CASE ( TRIM( variable ) )
995
996!
997!--    Uncomment and extend the following lines, if necessary.
998!--    The arrays for storing the user defined quantities (here u2 and u2_av)
999!--    have to be declared and defined by the user!
1000!--    Sample for user-defined output:
1001!       CASE ( 'u2' )
1002!          IF ( av == 0 )  THEN
1003!             DO  i = nxl, nxr
1004!                DO  j = nys, nyn
1005!                   DO  k = nzb_do, nzt_do
1006!                      local_pf(i,j,k) = u2(k,j,i)
1007!                   ENDDO
1008!                ENDDO
1009!             ENDDO
1010!          ELSE
1011!             IF ( .NOT. ALLOCATED( u2_av ) ) THEN
1012!                ALLOCATE( u2_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
1013!                u2_av = REAL( fill_value, KIND = wp )
1014!             ENDIF
1015!             DO  i = nxl, nxr
1016!                DO  j = nys, nyn
1017!                   DO  k = nzb_do, nzt_do
1018!                      local_pf(i,j,k) = u2_av(k,j,i)
1019!                   ENDDO
1020!                ENDDO
1021!             ENDDO
1022!          ENDIF
1023!
1024
1025       CASE DEFAULT
1026          found = .FALSE.
1027
1028    END SELECT
1029
1030
1031 END SUBROUTINE user_data_output_3d
1032
1033
1034!------------------------------------------------------------------------------!
1035! Description:
1036! ------------
1037!> Calculation of user-defined statistics, i.e. horizontally averaged profiles
1038!> and time series.
1039!> This routine is called for every statistic region sr defined by the user,
1040!> but at least for the region "total domain" (sr=0).
1041!> See section 3.5.4 on how to define, calculate, and output user defined
1042!> quantities.
1043!------------------------------------------------------------------------------!
1044 SUBROUTINE user_statistics( mode, sr, tn )
1045
1046
1047    CHARACTER (LEN=*) ::  mode   !<
1048!    INTEGER(iwp) ::  i    !<
1049!    INTEGER(iwp) ::  j    !<
1050!    INTEGER(iwp) ::  k    !<
1051    INTEGER(iwp) ::  sr   !<
1052    INTEGER(iwp) ::  tn   !<
1053
1054!    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ts_value_l   !<
1055
1056!
1057!-- Next line is to avoid compiler warning about unused variables. Please remove.
1058    IF ( sr == 0  .OR.  tn == 0 )  CONTINUE
1059
1060    IF ( mode == 'profiles' )  THEN
1061
1062!
1063!--    Sample on how to calculate horizontally averaged profiles of user-
1064!--    defined quantities. Each quantity is identified by the index
1065!--    "pr_palm+#" where "#" is an integer starting from 1. These
1066!--    user-profile-numbers must also be assigned to the respective strings
1067!--    given by data_output_pr_user in routine user_check_data_output_pr.
1068!       !$OMP DO
1069!       DO  i = nxl, nxr
1070!          DO  j = nys, nyn
1071!             DO  k = nzb+1, nzt
1072!!
1073!!--             Sample on how to calculate the profile of the resolved-scale
1074!!--             horizontal momentum flux u*v*
1075!                sums_l(k,pr_palm+1,tn) = sums_l(k,pr_palm+1,tn) +             &
1076!                      ( 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) - hom(k,1,1,sr) ) *&
1077!                      ( 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) - hom(k,1,2,sr) )  &
1078!                                     * rmask(j,i,sr)                          &
1079!                                     * MERGE( 1.0_wp, 0.0_wp,                 &
1080!                                              BTEST( wall_flags_0(k,j,i), 0 ) )
1081!!
1082!!--             Further profiles can be defined and calculated by increasing
1083!!--             the second index of array sums_l (replace ... appropriately)
1084!                sums_l(k,pr_palm+2,tn) = sums_l(k,pr_palm+2,tn) + ...           &
1085!                                         * rmask(j,i,sr)
1086!             ENDDO
1087!          ENDDO
1088!       ENDDO
1089
1090    ELSEIF ( mode == 'time_series' )  THEN
1091
1092
1093!       ALLOCATE ( ts_value_l(dots_num_user) )
1094!
1095!--    Sample on how to add values for the user-defined time series quantities.
1096!--    These have to be defined before in routine user_init. This sample
1097!--    creates two time series for the absolut values of the horizontal
1098!--    velocities u and v.
1099!       ts_value_l = 0.0_wp
1100!       ts_value_l(1) = ABS( u_max )
1101!       ts_value_l(2) = ABS( v_max )
1102!
1103!--     Collect / send values to PE0, because only PE0 outputs the time series.
1104!--     CAUTION: Collection is done by taking the sum over all processors.
1105!--              You may have to normalize this sum, depending on the quantity
1106!--              that you like to calculate. For serial runs, nothing has to be
1107!--              done.
1108!--     HINT: If the time series value that you are calculating has the same
1109!--           value on all PEs, you can omit the MPI_ALLREDUCE call and
1110!--           assign ts_value(dots_num_palm+1:,sr) = ts_value_l directly.
1111!#if defined( __parallel )
1112!       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1113!       CALL MPI_ALLREDUCE( ts_value_l(1),                         &
1114!                           ts_value(dots_num_palm+1,sr),                        &
1115!                           dots_num_user, MPI_REAL, MPI_MAX, comm2d,   &
1116!                           ierr )
1117!#else
1118!       ts_value(dots_num_palm+1:dots_num_palm+dots_num_user,sr) = ts_value_l
1119!#endif
1120
1121    ENDIF
1122
1123 END SUBROUTINE user_statistics
1124
1125
1126!------------------------------------------------------------------------------!
1127! Description:
1128! ------------
1129!> Reading global restart data that has been defined by the user.
1130!------------------------------------------------------------------------------!
1131 SUBROUTINE user_rrd_global( found )
1132
1133
1134    LOGICAL, INTENT(OUT)  ::  found
1135
1136
1137    found = .TRUE.
1138
1139
1140    SELECT CASE ( restart_string(1:length) )
1141
1142       CASE ( 'global_paramter' )
1143!          READ ( 13 )  global_parameter
1144
1145       CASE DEFAULT
1146 
1147          found = .FALSE.
1148
1149    END SELECT
1150
1151
1152 END SUBROUTINE user_rrd_global
1153
1154
1155!------------------------------------------------------------------------------!
1156! Description:
1157! ------------
1158!> Reading processor specific restart data from file(s) that has been defined
1159!> by the user.
1160!> Subdomain index limits on file are given by nxl_on_file, etc.
1161!> Indices nxlc, etc. indicate the range of gridpoints to be mapped from the
1162!> subdomain on file (f) to the subdomain of the current PE (c). They have been
1163!> calculated in routine rrd_local.
1164!------------------------------------------------------------------------------!
1165 SUBROUTINE user_rrd_local( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc,         &
1166                            nxr_on_file, nynf, nync, nyn_on_file, nysf,     &
1167                            nysc, nys_on_file, tmp_3d, found )
1168
1169
1170    INTEGER(iwp) ::  idum            !<
1171    INTEGER(iwp) ::  k               !<
1172    INTEGER(iwp) ::  nxlc            !<
1173    INTEGER(iwp) ::  nxlf            !<
1174    INTEGER(iwp) ::  nxl_on_file     !<
1175    INTEGER(iwp) ::  nxrc            !<
1176    INTEGER(iwp) ::  nxrf            !<
1177    INTEGER(iwp) ::  nxr_on_file     !<
1178    INTEGER(iwp) ::  nync            !<
1179    INTEGER(iwp) ::  nynf            !<
1180    INTEGER(iwp) ::  nyn_on_file     !<
1181    INTEGER(iwp) ::  nysc            !<
1182    INTEGER(iwp) ::  nysf            !<
1183    INTEGER(iwp) ::  nys_on_file     !<
1184
1185    LOGICAL, INTENT(OUT)  ::  found
1186
1187    REAL(wp), DIMENSION(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp) :: tmp_3d   !<
1188
1189!
1190!-- Next line is to avoid compiler warning about unused variables. Please remove.
1191    idum = k + nxlc + nxlf + nxrc + nxrf + nync + nynf + nysc + nysf +                             &
1192           INT( tmp_3d(nzb,nys_on_file,nxl_on_file) )
1193
1194!
1195!-- Here the reading of user-defined restart data follows:
1196!-- Sample for user-defined output
1197
1198    found = .TRUE.
1199
1200    SELECT CASE ( restart_string(1:length) )
1201
1202       CASE ( 'u2_av' )
1203!          IF ( .NOT. ALLOCATED( u2_av ) ) THEN
1204!               ALLOCATE( u2_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
1205!          ENDIF
1206!          IF ( k == 1 )  READ ( 13 )  tmp_3d
1207!             u2_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =         &
1208!                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
1209!
1210       CASE DEFAULT
1211
1212          found = .FALSE.
1213
1214    END SELECT
1215
1216 END SUBROUTINE user_rrd_local
1217
1218
1219!------------------------------------------------------------------------------!
1220! Description:
1221! ------------
1222!> Writes global and user-defined restart data into binary file(s) for restart
1223!> runs.
1224!------------------------------------------------------------------------------!
1225 SUBROUTINE user_wrd_global
1226
1227!    CALL wrd_write_string( 'global_parameter' )
1228!    WRITE ( 14 )  global_parameter
1229
1230 END SUBROUTINE user_wrd_global
1231
1232
1233!------------------------------------------------------------------------------!
1234! Description:
1235! ------------
1236!> Writes processor specific and user-defined restart data into binary file(s)
1237!> for restart runs.
1238!------------------------------------------------------------------------------!
1239 SUBROUTINE user_wrd_local
1240
1241!
1242!-- Here the user-defined actions at the end of a job follow.
1243!-- Sample for user-defined output:
1244!    IF ( ALLOCATED( u2_av ) )  THEN
1245!       CALL wrd_write_string( 'u2_av' )
1246!       WRITE ( 14 )  u2_av
1247!    ENDIF
1248
1249 END SUBROUTINE user_wrd_local
1250
1251
1252!------------------------------------------------------------------------------!
1253! Description:
1254! ------------
1255!> Execution of user-defined actions at the end of a job.
1256!------------------------------------------------------------------------------!
1257 SUBROUTINE user_last_actions
1258
1259!
1260!-- Here the user-defined actions at the end of a job might follow.
1261
1262
1263 END SUBROUTINE user_last_actions
1264
1265 END MODULE user
Note: See TracBrowser for help on using the repository browser.