FMS  2025.04
Flexible Modeling System
fms_diag_elem_weight_procs.F90
1 !***********************************************************************
2 !* Apache License 2.0
3 !*
4 !* This file is part of the GFDL Flexible Modeling System (FMS).
5 !*
6 !* Licensed under the Apache License, Version 2.0 (the "License");
7 !* you may not use this file except in compliance with the License.
8 !* You may obtain a copy of the License at
9 !*
10 !* http://www.apache.org/licenses/LICENSE-2.0
11 !*
12 !* FMS is distributed in the hope that it will be useful, but WITHOUT
13 !* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
14 !* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 !* PARTICULAR PURPOSE. See the License for the specific language
16 !* governing permissions and limitations under the License.
17 !***********************************************************************
18 
19 !> @defgroup fms_diag_elem_weight_procs_mod fms_diag_elem_weight_procs_mod
20 !> @ingroup diag_manager
21 !> @brief fms_diag_elem_weight_procs_mod Contains elemental functions for uddating
22 !! one element of a buffer array with field data.
23 !!
24 !> @author Miguel Zuniga
25 !!
26 !! <TT>fms_diag_elem_weight_procs_mod</TT> Contains elemental functions for uddating
27 !! one element of a buffer array with field data,
28 !!
29 !> @file
30 !> @brief File for @ref fms_diag_elem_weight_procs_mod
31 !> @addtogroup fms_diag_elem_weight_procs_mod
32 !> @{
33 MODULE fms_diag_elem_weight_procs_mod
34  USE platform_mod
35 
36  implicit none
37 
38  !> @brief Interface for the elemental function addwf, which
39  !! Calculates and returns the value given by this formula:
40  !! returned_value = buff + (weight * field)**pow_value
41  !> @ingroup fms_diag_elem_weight_procs_mod
42  INTERFACE addwf
43  module procedure addwf_r4
44  module procedure addwf_r8
45  module procedure addwf_i4
46  module procedure addwf_i8
47  END INTERFACE
48 
49 CONTAINS
50 
51  !!TODO: Note that in the functions below, the case for pow_value == 2 was
52  !! not in the original send_data_3d code and the power function was used.
53  !! So this case may need to be deleted if reproducability is an issue.
54 
55  !!TODO: (MDM) Discuss whether or not the pow_value should be allowed to
56  !! also be real though legacy interface has it satic.
57 
58  !> @brief Calculates and returns the value given by this formula:
59  !! returned_value = buff + (weight * field)**pow_value
60  !! Special cases when pow_value is equal to 1 or 2 do not explicitly use the power function.
61  ELEMENTAL REAL(r4_kind) FUNCTION addwf_r4(buff, field, weight, pow_value )
62  REAL(r4_kind), INTENT(in) :: buff !< The buffer cell (point) value
63  REAL(r4_kind), INTENT(IN) :: field !< The field value
64  REAL(r4_kind), INTENT(IN) :: weight !< The weight factor for the field
65  INTEGER, INTENT(IN) :: pow_value !< The power value for the power function
66 
67  SELECT CASE(pow_value)
68  CASE (1)
69  addwf_r4 = buff + weight * field
70  CASE (2)
71  addwf_r4 = buff + (weight * field) * (weight * field)
72  CASE default
73  addwf_r4 = buff + (weight * field) ** pow_value
74  END SELECT
75  END FUNCTION addwf_r4
76 
77  !> @brief Calculates and returns the value given by this formula:
78  !! returned_value = buff + (weight * field)**pow_value
79  !! Special cases when pow_value is equal to 1 or 2 do not explicitly use the power function.
80  ELEMENTAL REAL(r8_kind) FUNCTION addwf_r8(buff, field, weight, pow_value )
81  REAL(r8_kind), INTENT(in) :: buff !< The buffer cell (point) value
82  REAL(r8_kind) ,INTENT(IN) :: field !< The field value
83  REAL(r8_kind), INTENT(IN) :: weight !< The weight factor for the field
84  INTEGER, INTENT(IN) :: pow_value !< The power value for the power function
85 
86  SELECT CASE(pow_value)
87  CASE (1)
88  addwf_r8 = buff + weight * field
89  CASE (2)
90  addwf_r8 = buff + (weight * field) * (weight * field)
91  CASE default
92  addwf_r8 = buff + (weight * field) ** pow_value
93  END SELECT
94  END FUNCTION addwf_r8
95 
96  !> @brief Calculates and returns the value given by this formula:
97  !! returned_value = buff + (weight * field)**pow_value
98  !! Special cases when pow_value is equal to 1 or 2 do not explicitly use the power function.
99  ELEMENTAL INTEGER(i4_kind) FUNCTION addwf_i4(buff, field, weight, pow_value )
100  INTEGER(i4_kind), INTENT(in) :: buff !< The buffer cell (point) value
101  INTEGER(i4_kind), INTENT(IN) :: field !< The field value
102  INTEGER, INTENT(IN) :: weight !< The weight factor for the field
103  INTEGER, INTENT(IN) :: pow_value !< The power value for the power function
104  SELECT CASE(pow_value)
105  CASE (1)
106  addwf_i4 = buff + weight * field
107  CASE (2)
108  addwf_i4 = buff + (weight * field) * (weight * field)
109  CASE default
110  addwf_i4 = buff + (weight * field) ** pow_value
111  END SELECT
112  END FUNCTION addwf_i4
113 
114  !> @brief Calculates and returns the value given by this formula:
115  !! returned_value = buff + (weight * field)**pow_value
116  !! Special cases when pow_value is equal to 1 or 2 do not explicitly use the power function.
117  ELEMENTAL INTEGER(i8_kind) FUNCTION addwf_i8(buff, field, weight, pow_value )
118  INTEGER(i8_kind), INTENT(in) :: buff !< The buffer cell (point) value
119  INTEGER(i8_kind) ,INTENT(IN) :: field !< The field value
120  INTEGER, INTENT(IN) :: weight !< The weight factor for the field
121  INTEGER, INTENT(IN) :: pow_value !< The power value for the power function
122 
123  SELECT CASE(pow_value)
124  CASE (1)
125  addwf_i8 = buff + weight * field
126  CASE (2)
127  addwf_i8 = buff + (weight * field) * (weight * field)
128  CASE default
129  addwf_i8 = buff + (weight * field) ** pow_value
130  END SELECT
131  END FUNCTION addwf_i8
132 END MODULE fms_diag_elem_weight_procs_mod
133 !> @}
134 ! close documentation grouping
135 
elemental integer(i8_kind) function addwf_i8(buff, field, weight, pow_value)
Calculates and returns the value given by this formula: returned_value = buff + (weight * field)**pow...
elemental real(r4_kind) function addwf_r4(buff, field, weight, pow_value)
Calculates and returns the value given by this formula: returned_value = buff + (weight * field)**pow...
elemental real(r8_kind) function addwf_r8(buff, field, weight, pow_value)
Calculates and returns the value given by this formula: returned_value = buff + (weight * field)**pow...
elemental integer(i4_kind) function addwf_i4(buff, field, weight, pow_value)
Calculates and returns the value given by this formula: returned_value = buff + (weight * field)**pow...
Interface for the elemental function addwf, which Calculates and returns the value given by this form...