20 implicit none ;
private
32 logical :: boundary_extrapolation
35 logical :: answers_2018 = .true.
79 ppoly0_coefs, degree, h_neglect, h_neglect_edge)
81 real,
dimension(:),
intent(in) :: densities
82 integer,
intent(in) :: n0
83 real,
dimension(:),
intent(in) :: h0
84 real,
dimension(:,:),
intent(inout) :: ppoly0_e
85 real,
dimension(:,:),
intent(inout) :: ppoly0_s
86 real,
dimension(:,:),
intent(inout) :: ppoly0_coefs
87 integer,
intent(inout) :: degree
88 real,
optional,
intent(in) :: h_neglect
91 real,
optional,
intent(in) :: h_neglect_edge
95 logical :: extrapolate
100 ppoly0_coefs(:,:) = 0.0
102 extrapolate = cs%boundary_extrapolation
105 select case (cs%interpolation_scheme)
109 call edge_values_explicit_h2( n0, h0, densities, ppoly0_e, h_neglect_edge )
111 if (extrapolate)
then
118 call edge_values_explicit_h4( n0, h0, densities, ppoly0_e, h_neglect_edge, answers_2018=cs%answers_2018 )
120 call edge_values_explicit_h2( n0, h0, densities, ppoly0_e, h_neglect_edge )
123 if (extrapolate)
then
132 call edge_values_explicit_h2( n0, h0, densities, ppoly0_e, h_neglect_edge )
135 if (extrapolate)
then
142 if (extrapolate)
then
149 call edge_values_explicit_h4( n0, h0, densities, ppoly0_e, h_neglect_edge, answers_2018=cs%answers_2018 )
151 if (extrapolate)
then
153 ppoly0_coefs, h_neglect )
157 call edge_values_explicit_h2( n0, h0, densities, ppoly0_e, h_neglect_edge )
159 if (extrapolate)
then
169 if (extrapolate)
then
171 ppoly0_coefs, h_neglect )
175 call edge_values_explicit_h2( n0, h0, densities, ppoly0_e, h_neglect_edge )
177 if (extrapolate)
then
188 ppoly0_coefs, h_neglect )
189 if (extrapolate)
then
191 ppoly0_coefs, h_neglect, h_neglect_edge )
195 call edge_values_explicit_h2( n0, h0, densities, ppoly0_e, h_neglect_edge )
197 if (extrapolate)
then
208 ppoly0_coefs, h_neglect )
209 if (extrapolate)
then
211 ppoly0_coefs, h_neglect, h_neglect_edge )
215 call edge_values_explicit_h2( n0, h0, densities, ppoly0_e, h_neglect_edge )
217 if (extrapolate)
then
228 ppoly0_coefs, h_neglect )
229 if (extrapolate)
then
231 ppoly0_coefs, h_neglect )
235 call edge_values_explicit_h2( n0, h0, densities, ppoly0_e, h_neglect_edge )
237 if (extrapolate)
then
248 ppoly0_coefs, h_neglect )
249 if (extrapolate)
then
251 ppoly0_coefs, h_neglect )
255 call edge_values_explicit_h2( n0, h0, densities, ppoly0_e, h_neglect_edge )
257 if (extrapolate)
then
270 target_values, degree, n1, h1, x1, answers_2018 )
271 integer,
intent(in) :: n0
272 real,
dimension(:),
intent(in) :: h0
273 real,
dimension(:),
intent(in) :: x0
274 real,
dimension(:,:),
intent(in) :: ppoly0_e
275 real,
dimension(:,:),
intent(in) :: ppoly0_coefs
276 real,
dimension(:),
intent(in) :: target_values
277 integer,
intent(in) :: degree
278 integer,
intent(in) :: n1
279 real,
dimension(:),
intent(inout) :: h1
280 real,
dimension(:),
intent(inout) :: x1
281 logical,
optional,
intent(in) :: answers_2018
284 logical :: use_2018_answers
297 answers_2018=answers_2018 )
298 h1(k-1) = x1(k) - x1(k-1)
300 h1(n1) = x1(n1+1) - x1(n1)
306 n1, h1, x1, h_neglect, h_neglect_edge)
308 real,
dimension(:),
intent(in) :: densities
309 real,
dimension(:),
intent(in) :: target_values
310 integer,
intent(in) :: n0
311 real,
dimension(:),
intent(in) :: h0
312 real,
dimension(:),
intent(in) :: x0
313 integer,
intent(in) :: n1
314 real,
dimension(:),
intent(inout) :: h1
315 real,
dimension(:),
intent(inout) :: x1
316 real,
optional,
intent(in) :: h_neglect
319 real,
optional,
intent(in) :: h_neglect_edge
323 real,
dimension(n0,2) :: ppoly0_e, ppoly0_s
324 real,
dimension(n0,DEGREE_MAX+1) :: ppoly0_c
328 degree, h_neglect, h_neglect_edge)
329 call interpolate_grid(n0, h0, x0, ppoly0_e, ppoly0_c, target_values, degree, &
330 n1, h1, x1, answers_2018=cs%answers_2018)
350 target_value, degree, answers_2018 )
result ( x_tgt )
352 integer,
intent(in) :: n
353 real,
dimension(:),
intent(in) :: h
354 real,
dimension(:),
intent(in) :: x_g
355 real,
dimension(:,:),
intent(in) :: ppoly_e
356 real,
dimension(:,:),
intent(in) :: ppoly_coefs
357 real,
intent(in) :: target_value
358 integer,
intent(in) :: degree
359 logical,
optional,
intent(in) :: answers_2018
366 real,
dimension(DEGREE_MAX) :: a
374 logical :: use_2018_answers
378 use_2018_answers = .true. ;
if (
present(answers_2018)) use_2018_answers = answers_2018
383 if ( target_value <= ppoly_e(1,1) )
then
391 if ( ( target_value >= ppoly_e(k-1,2) ) .AND. &
392 ( target_value <= ppoly_e(k,1) ) )
then
402 if ( target_value >= ppoly_e(n,2) )
then
413 if ( ( target_value > ppoly_e(k,1) ) .AND. &
414 ( target_value < ppoly_e(k,2) ) )
then
425 if ( k_found == -1 )
then
426 write(*,*) target_value, ppoly_e(1,1), ppoly_e(n,2)
427 write(*,*)
'Could not find target coordinate in ' //&
428 '"get_polynomial_coordinate". This is caused by an '//&
429 'inconsistent interpolant (perhaps not monotonically '//&
431 call mom_error( fatal,
'Aborting execution' )
438 a(i) = ppoly_coefs(k_found,i)
454 if (use_2018_answers)
then
455 numerator = a(1) + a(2)*xi0 + a(3)*xi0*xi0 + a(4)*xi0*xi0*xi0 + &
456 a(5)*xi0*xi0*xi0*xi0 - target_value
457 denominator = a(2) + 2*a(3)*xi0 + 3*a(4)*xi0*xi0 + 4*a(5)*xi0*xi0*xi0
459 numerator = (a(1) - target_value) + xi0*(a(2) + xi0*(a(3) + xi0*(a(4) + a(5)*xi0)))
460 denominator = a(2) + xi0*(2.*a(3) + xi0*(3.*a(4) + 4.*a(5)*xi0))
463 delta = -numerator / denominator
472 if ( xi0 < 0.0 )
then
475 if ( grad == 0.0 ) xi0 = xi0 + eps
478 if ( xi0 > 1.0 )
then
480 if (use_2018_answers)
then
481 grad = a(2) + 2*a(3) + 3*a(4) + 4*a(5)
483 grad = a(2) + (2.*a(3) + (3.*a(4) + 4.*a(5)))
485 if ( grad == 0.0 ) xi0 = xi0 - eps
491 x_tgt = x_g(k_found) + xi0 * h(k_found)
496 character(len=*),
intent(in) :: interp_scheme
500 select case (
uppercase(trim(interp_scheme)) )
511 case default ;
call mom_error(fatal,
"regrid_interp: "//&
512 "Unrecognized choice for INTERPOLATION_SCHEME ("//trim(interp_scheme)//
").")
519 character(len=*),
intent(in) :: interp_scheme
529 logical,
intent(in) :: extrap
532 cs%boundary_extrapolation = extrap