source: trunk/LMDZ.GENERIC/libf/phygeneric/util_lagrange_interpolation.F90 @ 4083

Last change on this file since 4083 was 4083, checked in by emillour, 5 weeks ago

Generic PCM:
More tidying concerning OpenMP and radiative transfert routines. Ideally all
saved variables should be threadprivate (even though it is not always necessary)
It is also better practice to only read in data from file via the master core
and then broadcast the information (works for both MPI and OpenMP).
EM

File size: 1.4 KB
Line 
1module util_lagrange_interpolation_mod
2
3implicit none
4
5contains
6
7!======================================================================!
8      subroutine lagrange4(x, xi, yi, ans)
9
10!  Lagrange interpolation - Polynomial interpolation at point x
11!  (3rd order since relying on 4 points)
12!  xi(1) <= x <= xi(4).  Yi(n) is the functional value at XI(n).
13
14      implicit none
15
16      real*8,intent(in) :: x, xi(4), yi(4)
17      real*8, intent(out) :: ans
18
19      real*8 fm1, fm2, fm3, fm4
20
21!======================================================================!
22
23      fm1   = x - XI(1)
24      fm2   = x - XI(2)
25      fm3   = x - XI(3)
26      fm4   = x - XI(4)
27
28!  Get the answer at the requested X
29 
30      ans = fm2*fm3*fm4*YI(1)/                                        &
31                      ((XI(1)-XI(2))*(XI(1)-XI(3))*(XI(1)-XI(4)))  +  &
32            fm1*fm3*fm4*YI(2)/                                        &
33                      ((XI(2)-XI(1))*(XI(2)-XI(3))*(XI(2)-XI(4)))  +  &
34            fm1*fm2*fm4*YI(3)/                                        &
35                      ((XI(3)-XI(1))*(XI(3)-XI(2))*(XI(3)-XI(4)))  +  &
36            fm1*fm2*fm3*YI(4)/                                        &
37                      ((XI(4)-XI(1))*(XI(4)-XI(2))*(XI(4)-XI(3)))
38
39      end subroutine lagrange4
40
41!======================================================================!
42
43end module util_lagrange_interpolation_mod
Note: See TracBrowser for help on using the repository browser.