UFO
ufo_gnssroonedvarcheck_get_bmatrix_mod.f90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
2 ! (C) British Crown Copyright 2020 Met Office
3 !
4 ! This software is licensed under the terms of the Apache Licence Version 2.0
5 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 !-------------------------------------------------------------------------------
7 
8 !> Set up the background error covariance matrix (B matrix).
9 
11 
12 use kinds, only: kind_real
13 use fckit_log_module, only : fckit_log
15 
17  INTEGER :: nlevp
18  INTEGER :: nlevq
19  INTEGER :: nstate
20  INTEGER :: nband
21  INTEGER :: nseason
22  REAL(kind_real), POINTER :: band_up_lim(:) ! band_up_lim(nband)
23  REAL(kind_real), POINTER :: sigma(:,:,:) ! sigma(nseason,nband,nstate)
24  REAL(kind_real), POINTER :: inverse(:,:,:,:) ! inverse(nseason,nband,nstate,nstate)
25 end type
26 
27 private
29 
30 contains
31 
32 SUBROUTINE ops_gpsro_getbmatrix (filename, &
33  cx_nlevp, &
34  cx_nlevq, &
35  Bmatrix)
36 
37 IMPLICIT NONE
38 
39 ! Subroutine arguments:
40 CHARACTER(LEN=*) :: filename
41 INTEGER, INTENT(IN) :: cx_nlevp
42 INTEGER, INTENT(IN) :: cx_nlevq
43 TYPE (bmatrix_type), INTENT(OUT) :: bmatrix
44 
45 ! Local declarations:
46 CHARACTER(len=*), PARAMETER :: routinename = "Ops_GPSRO_GetBmatrix"
47 INTEGER :: i
48 INTEGER :: j
49 INTEGER :: m
50 INTEGER :: n
51 INTEGER :: nlevp
52 INTEGER :: nlevq
53 INTEGER :: nstate
54 INTEGER :: nband
55 INTEGER :: nseason
56 INTEGER :: fileunit
57 CHARACTER(len=*), PARAMETER :: filetype_name = "Bmatrix"
58 CHARACTER(len=20) :: prefix
59 CHARACTER(len=256) :: errormessage
60 INTEGER :: return_code
61 
62 !-----------------------------------------------
63 ! 0. Determine BMatrix environment variable name
64 !-----------------------------------------------
65 
66 prefix = 'GPSRO_'
67 fileunit = ufo_utils_iogetfreeunit()
68 
69 OPEN(unit=fileunit, file=filename, action='READ', status='OLD', iostat=return_code)
70 if (return_code /= 0) then
71  WRITE(errormessage, '(3A,I0)') "Error opening ", trim(filename), &
72  ", return code = ", return_code
73  call abor1_ftn(errormessage)
74 end if
75 
76 !---------------------
77 ! 2. Read in the file
78 !---------------------
79 
80 READ (fileunit, '(5I5)') nlevp, nlevq, nstate, nband, nseason
81 
82 IF (cx_nlevp /= nlevp) THEN
83 
84  WRITE (errormessage, '(A,I0,A,I0)')'nlevp = ', nlevp, ' cx_nlevp = ', cx_nlevp
85  call fckit_log % error(errormessage)
86  errormessage = 'no. of pressure levels in vector and bmatrix not the same'
87  call abor1_ftn(errormessage)
88 
89 END IF
90 
91 IF (cx_nlevq /= nlevq) THEN
92 
93  WRITE (errormessage, '(A,I0,A,I0)') 'nlevq = ', nlevq, ' cx_nlevq = ', cx_nlevq
94  call fckit_log % error(errormessage)
95  errormessage = 'no. of humidity levels in vector and bmatrix not the same'
96  call abor1_ftn(errormessage)
97 
98 END IF
99 
100 ! Allocate storage variables
101 
102 bmatrix % nlevp = nlevp
103 bmatrix % nlevq = nlevq
104 bmatrix % nstate = nstate
105 bmatrix % nband = nband
106 bmatrix % nseason = nseason
107 
108 ! Allocate the arrays in Bmatrix type
109 
110 ALLOCATE (bmatrix % band_up_lim(nband))
111 ALLOCATE (bmatrix % sigma(nseason,nband,nstate))
112 ALLOCATE (bmatrix % inverse(nseason,nband,nstate,nstate))
113 
114 ! Read the band upper limit
115 
116 READ (fileunit, '(3F5.1)') (bmatrix % band_up_lim(i), i = 1, nband)
117 
118 DO n = 1,nseason
119 
120  DO m = 1,nband
121 
122  READ (fileunit, *) ! space
123 
124  ! Read in the sigma values
125 
126  READ (fileunit, '(10E15.6)') (bmatrix % sigma (n,m,i), i = 1, nstate)
127 
128  ! Read in the inverse B matrix
129 
130  DO i = 1,nstate
131 
132  READ (fileunit, *) ! space
133  READ (fileunit, '(10E15.6)') (bmatrix % inverse (n,m,i,j), j = 1, nstate)
134 
135  END DO ! each B matrix
136 
137  END DO ! each band
138 
139 END DO ! each season
140 
141 ! Close the file
142 
143 CLOSE(fileunit)
144 
145 END SUBROUTINE ops_gpsro_getbmatrix
146 
Set up the background error covariance matrix (B matrix).
subroutine, public ops_gpsro_getbmatrix(filename, cx_nlevp, cx_nlevq, Bmatrix)
Fortran module with various useful routines.
integer function, public ufo_utils_iogetfreeunit()
Find a free file unit.