source: LMDZ5/tags/proto-testing-20131015/tools/Max_diff_nc_with_lib/NR_util/cumprod.f90 @ 2300

Last change on this file since 2300 was 1795, checked in by Ehouarn Millour, 11 years ago

Version testing basee sur la r1794


Testing release based on r1794

File size: 843 bytes
Line 
1module cumprod_m
2
3  implicit none
4
5contains
6
7  RECURSIVE FUNCTION cumprod(arr,seed) RESULT(ans)
8
9    ! Cumulative product on an array, with optional multiplicative seed.
10
11    USE nrtype, only: wp
12
13    REAL(WP), DIMENSION(:), INTENT(IN) :: arr
14    REAL(WP), OPTIONAL, INTENT(IN) :: seed
15    REAL(WP), DIMENSION(size(arr)) :: ans
16
17    ! Local:
18    INTEGER n,j
19    REAL(WP) :: sd
20    INTEGER, PARAMETER :: NPAR_CUMPROD=8
21
22    !--------------------------------------------------------
23
24    n=size(arr)
25    if (n == 0) RETURN
26    sd=1.0_wp
27    if (present(seed)) sd=seed
28    ans(1)=arr(1)*sd
29    if (n < NPAR_CUMPROD) then
30       do j=2,n
31          ans(j)=ans(j-1)*arr(j)
32       end do
33    else
34       ans(2:n:2)=cumprod(arr(2:n:2)*arr(1:n-1:2),sd)
35       ans(3:n:2)=ans(2:n-1:2)*arr(3:n:2)
36    end if
37
38  END FUNCTION cumprod
39
40end module cumprod_m
Note: See TracBrowser for help on using the repository browser.