source: LMDZ6/branches/LMDZ-INCA-Dyn/tools/Max_diff_nc_with_lib/Jumble/avg_mag.f90

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

Added a copyright property to every file of the distribution, except
for the fcm files (which have their own copyright). Use svn propget on
a file to see the copyright. For instance:

$ svn propget copyright libf/phylmd/physiq.F90
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

Also added the files defining the CeCILL version 2 license, in French
and English, at the top of the LMDZ tree.

  • 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: 2.9 KB
Line 
1module avg_mag_m
2
3  ! The generic procedure computes the average magnitude, that is
4  ! log10 of absolute value of an array.
5  ! The difference between the specific procedures is the kind and
6  ! rank of the array.
7  ! We do not care here about precision so all specific procedures
8  ! compute and return a default real kind value.
9
10  implicit none
11
12  interface avg_mag
13     module procedure avg_mag1, avg_mag1_dble, avg_mag2, avg_mag2_dble, &
14          avg_mag3, avg_mag3_dble, avg_mag4, avg_mag4_dble
15  end interface
16
17  private
18  public avg_mag
19
20contains
21
22  pure real function avg_mag1(a)
23
24    real, intent(in):: a(:)
25
26    ! Variables local to the procedure:
27    logical not_zero(size(a)) ! not zero in "a"
28    real magnit(size(a)) ! magnitudes of elements of "a"
29
30    !-------------------------------------
31
32    not_zero = a /= 0.
33
34    if (any(not_zero)) then
35       where (not_zero) magnit = log10(abs(a))
36       avg_mag1 = sum(magnit, mask=not_zero) / count(not_zero)
37    else
38       avg_mag1 = - huge(0.) ! minus infinity
39    end if
40
41  end function avg_mag1
42
43  !*******************************************************************
44
45  pure real function avg_mag1_dble(a)
46
47    double precision, intent(in):: a(:)
48
49    !-------------------------------------
50
51    avg_mag1_dble = avg_mag1(real(a))
52
53  end function avg_mag1_dble
54
55  !*******************************************************************
56
57  pure real function avg_mag2(a)
58
59    real, intent(in):: a(:, :)
60
61    !-------------------------------------
62
63    avg_mag2 = avg_mag1(pack(a, .true.))
64
65  end function avg_mag2
66
67  !*******************************************************************
68
69  pure real function avg_mag2_dble(a)
70
71    double precision, intent(in):: a(:, :)
72
73    !-------------------------------------
74
75    avg_mag2_dble = avg_mag1(pack(real(a), .true.))
76
77  end function avg_mag2_dble
78
79  !*******************************************************************
80
81  pure real function avg_mag3(a)
82
83    real, intent(in):: a(:, :, :)
84
85    !-------------------------------------
86
87    avg_mag3 = avg_mag1(pack(a, .true.))
88
89  end function avg_mag3
90
91  !*******************************************************************
92
93  pure real function avg_mag3_dble(a)
94
95    double precision, intent(in):: a(:, :, :)
96
97    !-------------------------------------
98
99    avg_mag3_dble = avg_mag1(pack(real(a), .true.))
100
101  end function avg_mag3_dble
102
103  !*******************************************************************
104
105  pure real function avg_mag4(a)
106
107    real, intent(in):: a(:, :, :, :)
108
109    !-------------------------------------
110
111    avg_mag4 = avg_mag1(pack(a, .true.))
112
113  end function avg_mag4
114
115  !*******************************************************************
116
117  pure real function avg_mag4_dble(a)
118
119    double precision, intent(in):: a(:, :, :, :)
120
121    !-------------------------------------
122
123    avg_mag4_dble = avg_mag1(pack(real(a), .true.))
124
125  end function avg_mag4_dble
126
127end module avg_mag_m
Note: See TracBrowser for help on using the repository browser.