source: LMDZ5/branches/LMDZ5-DOFOCO/tools/Max_diff_nc_with_lib/NR_util/scatter_add.f90

Last change on this file was 1765, checked in by lguez, 11 years ago

A tool to compare NetCDF files.

File size: 1.2 KB
Line 
1MODULE scatter_add_m
2
3  ! Bug correction: intent of "dest".
4
5  IMPLICIT NONE
6
7  INTERFACE scatter_add
8     MODULE PROCEDURE scatter_add_r,scatter_add_d
9  END INTERFACE
10
11  private scatter_add_r,scatter_add_d
12
13CONTAINS
14
15  SUBROUTINE scatter_add_r(dest,source,dest_index)
16    use assert_eq_m, only: assert_eq
17    REAL, DIMENSION(:), INTENT(inOUT) :: dest
18    REAL, DIMENSION(:), INTENT(IN) :: source
19    INTEGER, DIMENSION(:), INTENT(IN) :: dest_index
20    INTEGER :: m,n,j,i
21    n=assert_eq(size(source),size(dest_index),'scatter_add_r')
22    m=size(dest)
23    do j=1,n
24       i=dest_index(j)
25       if (i > 0 .and. i <= m) dest(i)=dest(i)+source(j)
26    end do
27  END SUBROUTINE scatter_add_r
28
29  SUBROUTINE scatter_add_d(dest,source,dest_index)
30    use assert_eq_m, only: assert_eq
31    DOUBLE PRECISION, DIMENSION(:), INTENT(inOUT) :: dest
32    DOUBLE PRECISION, DIMENSION(:), INTENT(IN) :: source
33    INTEGER, DIMENSION(:), INTENT(IN) :: dest_index
34    INTEGER :: m,n,j,i
35    n=assert_eq(size(source),size(dest_index),'scatter_add_d')
36    m=size(dest)
37    do j=1,n
38       i=dest_index(j)
39       if (i > 0 .and. i <= m) dest(i)=dest(i)+source(j)
40    end do
41  END SUBROUTINE scatter_add_d
42
43END MODULE scatter_add_m
Note: See TracBrowser for help on using the repository browser.