source: LMDZ6/branches/Amaury_dev/libf/obsolete/regr1_step_av_m.F90 @ 5214

Last change on this file since 5214 was 5117, checked in by abarral, 2 months ago

rename modules properly lmdz_*
move some unused files to obsolete/
(lint) uppercase fortran keywords

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
File size: 8.2 KB
Line 
1! Amaury (07/24): ce module n'est utilisé nulle part à part dans obsolete/, où il en existe déjà une autre version....
2
3! $Id$
4module regr1_step_av_m
5
6  ! Author: Lionel GUEZ
7
8  implicit none
9
10  interface regr1_step_av
11
12     ! Each procedure regrids a step function by averaging it.
13     ! The regridding operation is done on the first dimension of the
14     ! input array.
15     ! Source grid contains edges of steps.
16     ! Target grid contains positions of cell edges.
17     ! The target grid should be included in the source grid: no
18     ! extrapolation is allowed.
19     ! The difference between the procedures is the rank of the first argument.
20
21     module procedure regr11_step_av, regr12_step_av, regr13_step_av, &
22          regr14_step_av
23  end interface
24
25  private
26  public regr1_step_av
27
28contains
29
30  function regr11_step_av(vs, xs, xt) result(vt)
31
32    ! "vs" has rank 1.
33
34    use assert_eq_m, only: assert_eq
35    use assert_m, only: assert
36    use interpolation, only: locate
37
38    real, intent(in):: vs(:) ! values of steps on the source grid
39    ! (Step "is" is between "xs(is)" and "xs(is + 1)".)
40
41    real, intent(in):: xs(:)
42    ! (edges of of steps on the source grid, in strictly increasing order)
43
44    real, intent(in):: xt(:)
45    ! (edges of cells of the target grid, in strictly increasing order)
46
47    real vt(size(xt) - 1) ! average values on the target grid
48    ! (Cell "it" is between "xt(it)" and "xt(it + 1)".)
49
50    ! Variables local to the procedure:
51    integer is, it, ns, nt
52    real left_edge
53
54    !---------------------------------------------
55
56    ns = assert_eq(size(vs), size(xs) - 1, "regr11_step_av ns")
57    nt = size(xt) - 1
58    ! Quick check on sort order:
59    call assert(xs(1) < xs(2), "regr11_step_av xs bad order")
60    call assert(xt(1) < xt(2), "regr11_step_av xt bad order")
61
62    call assert(xs(1) <= xt(1) .and. xt(nt + 1) <= xs(ns + 1), &
63         "regr11_step_av extrapolation")
64
65    is = locate(xs, xt(1)) ! 1 <= is <= ns, because we forbid extrapolation
66    do it = 1, nt
67       ! 1 <= is <= ns
68       ! xs(is) <= xt(it) < xs(is + 1)
69       ! Compute "vt(it)":
70       left_edge = xt(it)
71       vt(it) = 0.
72       do while (xs(is + 1) < xt(it + 1))
73          ! 1 <= is <= ns - 1
74          vt(it) = vt(it) + (xs(is + 1) - left_edge) * vs(is)
75          is = is + 1
76          left_edge = xs(is)
77       END DO
78       ! 1 <= is <= ns
79       vt(it) = (vt(it) + (xt(it + 1) - left_edge) * vs(is)) &
80            / (xt(it + 1) - xt(it))
81       if (xs(is + 1) == xt(it + 1)) is = is + 1
82       ! 1 <= is <= ns .or. it == nt
83    END DO
84
85  end function regr11_step_av
86
87  !********************************************
88
89  function regr12_step_av(vs, xs, xt) result(vt)
90
91    ! "vs" has rank 2.
92
93    use assert_eq_m, only: assert_eq
94    use assert_m, only: assert
95    use interpolation, only: locate
96
97    real, intent(in):: vs(:, :) ! values of steps on the source grid
98    ! (Step "is" is between "xs(is)" and "xs(is + 1)".)
99
100    real, intent(in):: xs(:)
101    ! (edges of steps on the source grid, in strictly increasing order)
102
103    real, intent(in):: xt(:)
104    ! (edges of cells of the target grid, in strictly increasing order)
105
106    real vt(size(xt) - 1, size(vs, 2)) ! average values on the target grid
107    ! (Cell "it" is between "xt(it)" and "xt(it + 1)".)
108
109    ! Variables local to the procedure:
110    integer is, it, ns, nt
111    real left_edge
112
113    !---------------------------------------------
114
115    ns = assert_eq(size(vs, 1), size(xs) - 1, "regr12_step_av ns")
116    nt = size(xt) - 1
117
118    ! Quick check on sort order:
119    call assert(xs(1) < xs(2), "regr12_step_av xs bad order")
120    call assert(xt(1) < xt(2), "regr12_step_av xt bad order")
121
122    call assert(xs(1) <= xt(1) .and. xt(nt + 1) <= xs(ns + 1), &
123         "regr12_step_av extrapolation")
124
125    is = locate(xs, xt(1)) ! 1 <= is <= ns, because we forbid extrapolation
126    do it = 1, nt
127       ! 1 <= is <= ns
128       ! xs(is) <= xt(it) < xs(is + 1)
129       ! Compute "vt(it, :)":
130       left_edge = xt(it)
131       vt(it, :) = 0.
132       do while (xs(is + 1) < xt(it + 1))
133          ! 1 <= is <= ns - 1
134          vt(it, :) = vt(it, :) + (xs(is + 1) - left_edge) * vs(is, :)
135          is = is + 1
136          left_edge = xs(is)
137       END DO
138       ! 1 <= is <= ns
139       vt(it, :) = (vt(it, :) + (xt(it + 1) - left_edge) * vs(is, :)) &
140            / (xt(it + 1) - xt(it))
141       if (xs(is + 1) == xt(it + 1)) is = is + 1
142       ! 1 <= is <= ns .or. it == nt
143    END DO
144
145  end function regr12_step_av
146
147  !********************************************
148
149  function regr13_step_av(vs, xs, xt) result(vt)
150
151    ! "vs" has rank 3.
152
153    use assert_eq_m, only: assert_eq
154    use assert_m, only: assert
155    use interpolation, only: locate
156
157    real, intent(in):: vs(:, :, :) ! values of steps on the source grid
158    ! (Step "is" is between "xs(is)" and "xs(is + 1)".)
159
160    real, intent(in):: xs(:)
161    ! (edges of steps on the source grid, in strictly increasing order)
162
163    real, intent(in):: xt(:)
164    ! (edges of cells of the target grid, in strictly increasing order)
165
166    real vt(size(xt) - 1, size(vs, 2), size(vs, 3))
167    ! (average values on the target grid)
168    ! (Cell "it" is between "xt(it)" and "xt(it + 1)".)
169
170    ! Variables local to the procedure:
171    integer is, it, ns, nt
172    real left_edge
173
174    !---------------------------------------------
175
176    ns = assert_eq(size(vs, 1), size(xs) - 1, "regr13_step_av ns")
177    nt = size(xt) - 1
178
179    ! Quick check on sort order:
180    call assert(xs(1) < xs(2), "regr13_step_av xs bad order")
181    call assert(xt(1) < xt(2), "regr13_step_av xt bad order")
182
183    call assert(xs(1) <= xt(1) .and. xt(nt + 1) <= xs(ns + 1), &
184         "regr13_step_av extrapolation")
185
186    is = locate(xs, xt(1)) ! 1 <= is <= ns, because we forbid extrapolation
187    do it = 1, nt
188       ! 1 <= is <= ns
189       ! xs(is) <= xt(it) < xs(is + 1)
190       ! Compute "vt(it, :, :)":
191       left_edge = xt(it)
192       vt(it, :, :) = 0.
193       do while (xs(is + 1) < xt(it + 1))
194          ! 1 <= is <= ns - 1
195          vt(it, :, :) = vt(it, :, :) + (xs(is + 1) - left_edge) * vs(is, :, :)
196          is = is + 1
197          left_edge = xs(is)
198       END DO
199       ! 1 <= is <= ns
200       vt(it, :, :) = (vt(it, :, :) &
201            + (xt(it + 1) - left_edge) * vs(is, :, :)) / (xt(it + 1) - xt(it))
202       if (xs(is + 1) == xt(it + 1)) is = is + 1
203       ! 1 <= is <= ns .or. it == nt
204    END DO
205
206  end function regr13_step_av
207
208  !********************************************
209
210  function regr14_step_av(vs, xs, xt) result(vt)
211
212    ! "vs" has rank 4.
213
214    use assert_eq_m, only: assert_eq
215    use assert_m, only: assert
216    use interpolation, only: locate
217
218    real, intent(in):: vs(:, :, :, :) ! values of steps on the source grid
219    ! (Step "is" is between "xs(is)" and "xs(is + 1)".)
220
221    real, intent(in):: xs(:)
222    ! (edges of steps on the source grid, in strictly increasing order)
223
224    real, intent(in):: xt(:)
225    ! (edges of cells of the target grid, in strictly increasing order)
226
227    real vt(size(xt) - 1, size(vs, 2), size(vs, 3), size(vs, 4))
228    ! (average values on the target grid)
229    ! (Cell "it" is between "xt(it)" and "xt(it + 1)".)
230
231    ! Variables local to the procedure:
232    integer is, it, ns, nt
233    real left_edge
234
235    !---------------------------------------------
236
237    ns = assert_eq(size(vs, 1), size(xs) - 1, "regr14_step_av ns")
238    nt = size(xt) - 1
239
240    ! Quick check on sort order:
241    call assert(xs(1) < xs(2), "regr14_step_av xs bad order")
242    call assert(xt(1) < xt(2), "regr14_step_av xt bad order")
243
244    call assert(xs(1) <= xt(1) .and. xt(nt + 1) <= xs(ns + 1), &
245         "regr14_step_av extrapolation")
246
247    is = locate(xs, xt(1)) ! 1 <= is <= ns, because we forbid extrapolation
248    do it = 1, nt
249       ! 1 <= is <= ns
250       ! xs(is) <= xt(it) < xs(is + 1)
251       ! Compute "vt(it, :, :, :)":
252       left_edge = xt(it)
253       vt(it, :, :, :) = 0.
254       do while (xs(is + 1) < xt(it + 1))
255          ! 1 <= is <= ns - 1
256          vt(it, :, :, :) = vt(it, :, :, :) + (xs(is + 1) - left_edge) &
257               * vs(is, :, :, :)
258          is = is + 1
259          left_edge = xs(is)
260       END DO
261       ! 1 <= is <= ns
262       vt(it, :, :, :) = (vt(it, :, :, :) + (xt(it + 1) - left_edge) &
263            * vs(is, :, :, :)) / (xt(it + 1) - xt(it))
264       if (xs(is + 1) == xt(it + 1)) is = is + 1
265       ! 1 <= is <= ns .or. it == nt
266    END DO
267
268  end function regr14_step_av
269
270end module regr1_step_av_m
Note: See TracBrowser for help on using the repository browser.