/
SHAdmitCorr.f95
185 lines (167 loc) · 6.61 KB
/
SHAdmitCorr.f95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
subroutine SHAdmitCorr(gilm, tilm, lmax, admit, corr, admit_error, exitstatus)
!------------------------------------------------------------------------------
!
! This subroutine will compute the admittance and correlation between the two
! input spherical harmonic coefficients. The optional "error" on the
! admittance estimates assumes that the two fields are perfectly correlated,
! which may not necessarily true for certain models (such as Forsyth's
! loading model).
!
! Assuming that the two input fields are related by
!
! gilm = Z tilm + N
!
! where N is noise, the admittance is calcalated as
!
! Z = < gilm tilm > / < tilm tilm >,
!
! the correlation is
!
! correlation = < gilm tilm > / sqrt(< gilm gilm > < tilm tilm >).
!
! Assuming that the two fields are perfectly correlated, and that the lack of
! coherence is a result of noise, the uncertainty on the admittance can be
! calculaed from
!
! sigma^2 = ( < gilm gilm > / < tilm tilm > ) ( 1 - gamma^2) / (2 l).
!
! < > signifies an average of over all m. Since only ratios are being used,
! < > is implemented only as sums over all m (i.e., by the cross spectra of
! the fields). Note that the correlation can possess values between -1 and 1,
! in contrast to the "coherence" (or coherence-squared; the terminology is
! ambiguous) which only possesses values between 0 and 1.
!
! Note that in order for the magnitude of the admittance to be correct, the
! input coefficients must be multiplied by all constants. For instance, in the
! case of gravity-topography admittances, the potential coefficients must
! first be multiplied by GM (l+1) (R/r)**(l+2) where R is the refernce radius
! of the coefficients, and r is the radius at which the field is evaluated.
!
! Calling Parameters
!
! IN
! gilm First input spherical harmonic coefficients.
! tilm Second input spherical harmonic coefficients.
! lmax Maximum spherical harmonic degree of the input fields.
!
! OUT
! admit Admittance spectra (length lmax+1).
! corr Correlation spectra (length lmax+1).
!
! OPTIONAL
! admit_error Addittance error spectra (length lmax+1)
! assuming that the two fields perfectly correlated in
! the abscence of noise.
!
! OPTIONAL (OUT)
! exitstatus If present, instead of executing a STOP when an error
! is encountered, the variable exitstatus will be
! returned describing the error.
! 0 = No errors;
! 1 = Improper dimensions of input array;
! 2 = Improper bounds for input variable;
! 3 = Error allocating memory;
! 4 = File IO error.
!
! Copyright (c) 2005-2019, SHTOOLS
! All rights reserved.
!
!------------------------------------------------------------------------------
use SHTOOLS, only: SHPowerSpectrum, SHCrossPowerSpectrum
use ftypes
implicit none
real(dp), intent(in) :: gilm(:,:,:), tilm(:,:,:)
integer(int32), intent(in) :: lmax
real(dp), intent(out) :: admit(:), corr(:)
real(dp), intent(out), optional :: admit_error(:)
integer(int32), intent(out), optional :: exitstatus
real(dp) :: gt(lmax+1), gg(lmax+1), tt(lmax+1)
integer(int32) :: l, l1
if (present(exitstatus)) exitstatus = 0
if (size(gilm(:,1,1)) < 2 .or. size(gilm(1,:,1)) < lmax+1 .or. &
size(gilm(1,1,:)) < lmax+1) then
print*, "Error --- SHAdmitCorr"
print*, "GILM must be dimensioned as (2, LMAX+1, LMAX+1) where " // &
"LMAX is ", lmax
print*, "Input dimension is ", size(gilm(:,1,1)), size(gilm(1,:,1)), &
size(gilm(1,1,:))
if (present(exitstatus)) then
exitstatus = 1
return
else
stop
end if
else if (size(tilm(:,1,1)) < 2 .or. size(tilm(1,:,1)) < lmax+1 .or. &
size(tilm(1,1,:)) < lmax+1) then
print*, "Error --- SHAdmitCorr"
print*, "TILM must be dimensioned as (2, LMAX+1, LMAX+1) " // &
"where LMAX is ", lmax
print*, "Input dimension is ", size(tilm(:,1,1)), size(tilm(1,:,1)), &
size(tilm(1,1,:))
if (present(exitstatus)) then
exitstatus = 1
return
else
stop
end if
else if (size(admit) < lmax+1) then
print*, "Error --- SHAdmitCorr"
print*, "ADMIT must be dimensioned as (LMAX+1) where LMAX is ", lmax
print*, "Input dimension is ", size(admit)
if (present(exitstatus)) then
exitstatus = 1
return
else
stop
end if
else if (size(corr) < lmax+1) then
print*, "Error --- SHAdmitCorr"
print*, "CORR must be dimensioned as (LMAX+1) where LMAX is ", lmax
print*, "Input dimension is ", size(corr)
if (present(exitstatus)) then
exitstatus = 1
return
else
stop
end if
end if
if (present(admit_error)) then
if (size(admit_error) < lmax+1) then
print*, "Error --- SHAdmitCorr"
print*, "ADMIT_ERROR must be dimensioned as (LMAX+1) " // &
"where LMAX is ", lmax
print*, "Input dimension is ", size(admit_error)
if (present(exitstatus)) then
exitstatus = 1
return
else
stop
end if
end if
end if
admit = 0.0_dp
corr = 0.0_dp
if (present(exitstatus)) then
call SHCrossPowerSpectrum(gilm, tilm, lmax, gt, exitstatus=exitstatus)
if (exitstatus /= 0) return
call SHPowerSpectrum(gilm, lmax, gg, exitstatus=exitstatus)
if (exitstatus /= 0) return
call SHPowerSpectrum(tilm, lmax, tt, exitstatus=exitstatus)
if (exitstatus /= 0) return
else
call SHCrossPowerSpectrum(gilm, tilm, lmax, gt) ! < gilm tilm >
call SHPowerSpectrum(gilm, lmax, gg) ! < gilm gilm >
call SHPowerSpectrum(tilm, lmax, tt) ! < tilm tilm >
end if
admit(1:lmax+1) = gt(1:lmax+1) / tt(1:lmax+1)
corr(1:lmax+1) = gt(1:lmax+1) / sqrt( tt(1:lmax+1) * gg(1:lmax+1) )
if (present(admit_error)) then
admit_error = 0.0_dp
do l = 1, lmax, 1
l1 = l + 1
admit_error(l1) = gg(l1)*(1.0_dp - corr(l1)**2) &
/ ( tt(l1) * dble(2*l) )
end do
admit_error(1:lmax+1) = sqrt(admit_error(1:lmax+1))
end if
end subroutine SHAdmitCorr