20 real(kind_real),
allocatable :: matrix(:,:)
21 real(kind_real),
allocatable :: inv_matrix(:,:)
22 real(kind_real),
allocatable :: diagonal(:)
23 logical :: diagonal_flag
52 integer,
intent(in) :: nchans
53 integer,
intent(in) :: channels(:)
56 character(len=*),
parameter :: &
57 routinename =
"rsubmatrix_setup"
58 character(len=max_string) :: err_msg
60 character(len=max_string) :: mat_type
62 self % nchans = nchans
63 self % full_flag = .false.
64 self % diagonal_flag = .false.
67 if (full_rmatrix % rtype == 1)
then
69 else if (full_rmatrix % rtype == 2)
then
72 call abor1_ftn(
'Unknown r matrix type')
76 select case (trim(mat_type))
90 call abor1_ftn(
'full r matrix under development - use a diagonal')
92 allocate(self % diagonal(nchans))
93 self % diagonal(:) = 0.0_kind_real
94 self % diagonal_flag = .true.
96 do ff=1,full_rmatrix % nchans
98 if (full_rmatrix % channels(ff) == channels(ss))
then
99 self % diagonal(ss) = full_rmatrix % errors(ff) * full_rmatrix % errors(ff)
104 call abor1_ftn(
'Unknown r matrix type')
121 if (
allocated(self % matrix))
deallocate(self % matrix)
122 if (
allocated(self % inv_matrix))
deallocate(self % inv_matrix)
123 if (
allocated(self % diagonal))
deallocate(self % diagonal)
138 real(kind_real),
intent(in) :: xin(:)
139 real(kind_real),
intent(inout) :: xout(:)
141 if (
size(xout) /= self % nchans)
then
142 call abor1_ftn(
"rsubmatrix_multiply: arrays incompatible sizes")
146 if (self % full_flag) xout(:) = matmul(xin(:), self % matrix(:,:))
149 if (self % diagonal_flag) xout(:) = xin(:) * self % diagonal(:)
164 real(kind_real),
intent(in) :: xin(:,:)
165 real(kind_real),
intent(inout) :: xout(:,:)
169 if (
size(xout, 2) /= self % nchans)
then
170 call abor1_ftn(
"rsubmatrix_multiply_matrix: arrays incompatible sizes")
174 if (self % full_flag) xout = matmul(xin, self % matrix(:,:))
177 if (self % diagonal_flag)
then
178 do ii=1, self % nchans
179 xout(:,ii) = xin(:,ii) * self % diagonal(ii)
196 real(kind_real),
intent(in) :: xin(:)
197 real(kind_real),
intent(inout) :: xout(:)
199 if (
size(xout) /= self % nchans)
then
200 call abor1_ftn(
"rsubmatrix_inv_multiply: arrays incompatible sizes")
204 if (self % full_flag) xout(:) = matmul(xin(:), self % inv_matrix(:,:))
207 if (self % diagonal_flag) xout(:) = xin(:) / self % diagonal(:)
222 real(kind_real),
intent(in) :: xin(:,:)
223 real(kind_real),
intent(out) :: xout(:,:)
227 if (
size(xout, 2) /= self % nchans)
then
228 call abor1_ftn(
"rsubmatrix_multiply_inv_matrix: arrays incompatible sizes")
232 if (self % full_flag) xout = matmul(xin, self % inv_matrix(:,:))
235 if (self % diagonal_flag)
then
236 do ii=1, self % nchans
237 xout(:,ii) = xin(:,ii) / self % diagonal(ii)
254 real(kind_real),
intent(in) :: uin(:,:)
255 real(kind_real),
intent(inout) :: uout(:,:)
259 if (
size(uout) /= self % nchans * self % nchans)
then
260 call abor1_ftn(
"rsubmatrix_add_to_u: arrays incompatible sizes")
264 if (self % full_flag) uout = uin + self % matrix
267 if (self % diagonal_flag)
then
268 do ii=1, self % nchans
269 uout(ii,ii) = uin(ii,ii) + self % diagonal(ii)
286 real(kind_real),
intent(in) :: factor
287 real(kind_real),
intent(inout) :: xout(:)
291 if (
size(xout) /= self % nchans)
then
292 call abor1_ftn(
"rsubmatrix_multiply_factor_by_stdev: arrays incompatible sizes")
296 if (self % full_flag)
then
297 do ii=1, self % nchans
298 xout(ii) = factor * sqrt(self % matrix(ii,ii))
303 if (self % diagonal_flag) xout(:) = factor * sqrt(self % diagonal(:))
321 if (self % full_flag)
then
323 write(*,*)
"Full R matrix used printing diagonal"
324 write(*,*)
"nchans = ",self % nchans
325 write(*,*)
"Matrix diagonal elements = "
326 do ii = 1, self % nchans
327 write(*,*) self % matrix(ii,ii)
329 write(*,*)
"Inverse Matrix diagonal elements = "
330 do ii = 1, self % nchans
331 write(*,*) self % inv_matrix(ii,ii)
336 if (self % diagonal_flag)
then
338 write(*,*)
"Diagonal R matrix used"
339 write(*,*)
"nchans = ",self % nchans
340 write(*,*)
"Diagonal = ",self % diagonal(:)
Fortran derived type to hold data for the observation covariance.
Fortran module constants used throughout the rttovonedvarcheck filter.
integer, parameter, public max_string
maximum string length
Fortran derived type to hold data for the observation covariance.
subroutine rsubmatrix_inv_multiply(self, xin, xout)
Multiply a vector by the inverse of the r-matrix.
subroutine rsubmatrix_multiply_factor_by_stdev(self, factor, xout)
Multiply a vector by the r-matrix diagonal standard deviation.
subroutine rsubmatrix_multiply(self, xin, xout)
Multiply a vector by the r-matrix.
subroutine rsubmatrix_multiply_inv_matrix(self, xin, xout)
Multiply a matrix by the inverse of the r-matrix.
subroutine rsubmatrix_delete(self)
Delete method for the r_matrix.
subroutine rsubmatrix_setup(self, nchans, channels, full_rmatrix)
Setup for the r sub-matrix.
subroutine rsubmatrix_multiply_matrix(self, xin, xout)
Multiply a matrix by the r-matrix.
subroutine rsubmatrix_print(self)
Print the contents of the r-matrix.
subroutine rsubmatrix_add_to_u(self, uin, uout)
Add a matrix to the r-matrix.