New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
obsinter_z1d.h90 in branches/UKMO/dev_r5518_obs_oper_update_DepthBug/NEMOGCM/NEMO/OPA_SRC/OBS – NEMO

source: branches/UKMO/dev_r5518_obs_oper_update_DepthBug/NEMOGCM/NEMO/OPA_SRC/OBS/obsinter_z1d.h90 @ 15396

Last change on this file since 15396 was 15396, checked in by kingr, 12 months ago

Corrected logic to avoid masked levels in obs_inter_z1d

File size: 8.4 KB
Line 
1   !!----------------------------------------------------------------------
2   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
3   !! $Id$
4   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
5   !!----------------------------------------------------------------------
6
7   SUBROUTINE obs_int_z1d( kpk, kkco, k1dint, kdep, &
8      &                    pobsdep, pobsk, pobs2k,  &
9      &                    pobs, pdep, pobsmask )
10      !!---------------------------------------------------------------------
11      !!
12      !!                   ***  ROUTINE obs_int_z1d ***
13      !!
14      !! ** Purpose : Vertical interpolation to the observation point.
15      !! 
16      !! ** Method  : If k1dint = 0 then use linear interpolation.
17      !!              If k1dint = 1 then use cubic spline interpolation.
18      !!
19      !! ** Action  :
20      !!
21      !! References :
22      !!
23      !! History
24      !!      ! 97-11 (A. Weaver, S. Ricci, N. Daget)
25      !!      ! 06-03 (G. Smith) Conversion to F90 for use with NEMOVAR
26      !!      ! 06-10 (A. Weaver) Cleanup
27      !!      ! 07-01 (K. Mogensen) Use profile rather than single level
28      !!---------------------------------------------------------------------
29
30      !! * Arguments
31      INTEGER, INTENT(IN) :: kpk        ! Number of vertical levels
32      INTEGER, INTENT(IN) :: k1dint     ! 0 = linear; 1 = cubic spline interpolation
33      INTEGER, INTENT(IN) :: kdep       ! Number of levels in profile
34      INTEGER, INTENT(IN), DIMENSION(kdep) :: &
35         & kkco                 ! Array indicies for interpolation
36      REAL(KIND=wp), INTENT(IN), DIMENSION(kdep) :: &
37         & pobsdep              ! Depth of the observation
38      REAL(KIND=wp), INTENT(IN), DIMENSION(kpk) :: &
39         & pobsk,  &            ! Model profile at a given (lon,lat)
40         & pobs2k, &            ! 2nd derivative of the interpolating function
41         & pdep,   &            ! Model depth array
42         & pobsmask             ! Vertical mask
43      REAL(KIND=wp), INTENT(OUT), DIMENSION(kdep) :: &
44         & pobs                 ! Model equivalent at observation point
45 
46      !! * Local declarations
47      REAL(KIND=wp) :: z1dm       ! Distance above and below obs to model grid points
48      REAL(KIND=wp) :: z1dp         
49      REAL(KIND=wp) :: zsum       ! Dummy variables for computation
50      REAL(KIND=wp) :: zsum2
51      INTEGER :: jdep             ! Observation depths loop variable
52   
53      !------------------------------------------------------------------------
54      ! Loop over all observation depths
55      !------------------------------------------------------------------------
56
57      DO jdep = 1, kdep
58
59         !---------------------------------------------------------------------
60         ! Initialization
61         !---------------------------------------------------------------------
62         z1dm = ( pdep(kkco(jdep)) - pobsdep(jdep)      )
63         z1dp = ( pobsdep(jdep)    - pdep(kkco(jdep)-1) )
64
65         
66         ! Where both levels are masked, return a fill value
67         IF ( ( pobsmask(kkco(jdep)-1) == 0.0_wp ) .AND. (pobsmask(kkco(jdep)) == 0.0_wp) ) THEN
68            pobs(jdep)  = 99999.
69         ELSE
70         
71            ! Where upper level is masked (e.g., under ice cavity), only use deeper level
72            ! otherwise where ob is at or above upper level model T-point,
73            ! use upper model level rather than extrapolate
74            IF ( pobsmask(kkco(jdep)-1) == 0.0_wp ) THEN
75               z1dm = 0.0_wp
76            ELSE IF ( pobsdep(jdep) <= pdep(kkco(jdep)-1) ) THEN
77               z1dp = 0.0_wp   
78            END IF   
79
80            ! Where deeper level is masked (e.g., near sea bed), only use upper level
81            ! otherwise where ob is at or below deeper level model T-point,
82            ! use deeper model level rather than extrapolate
83            IF ( pobsmask(kkco(jdep)) == 0.0_wp ) THEN
84               z1dp = 0.0_wp
85            ELSE IF ( pobsdep(jdep) >= pdep(kkco(jdep)) ) THEN
86               z1dm = 0.0_wp   
87            END IF   
88
89            zsum = z1dm + z1dp
90         
91            IF ( k1dint == 0 ) THEN
92
93               !-----------------------------------------------------------------
94               !  Linear interpolation
95               !-----------------------------------------------------------------
96               pobs(jdep) = (   z1dm * pobsk(kkco(jdep)-1) &
97                  &           + z1dp * pobsk(kkco(jdep)  ) ) / zsum
98
99            ELSEIF ( k1dint == 1 ) THEN
100
101               !-----------------------------------------------------------------
102               ! Cubic spline interpolation
103               !-----------------------------------------------------------------
104               zsum2 = zsum * zsum
105               pobs(jdep)  = (  z1dm                             * pobsk (kkco(jdep)-1) &
106                  &           + z1dp                             * pobsk (kkco(jdep)  ) &
107                  &           + ( z1dm * ( z1dm * z1dm - zsum2 ) * pobs2k(kkco(jdep)-1) &
108                  &           +   z1dp * ( z1dp * z1dp - zsum2 ) * pobs2k(kkco(jdep)  ) &
109                  &             ) / 6.0_wp                                              &
110                  &          ) / zsum
111
112            ENDIF
113         ENDIF   
114      END DO
115
116   END SUBROUTINE obs_int_z1d
117
118   SUBROUTINE obs_int_z1d_spl( kpk, pobsk, pobs2k, &
119      &                        pdep, pobsmask )
120      !!--------------------------------------------------------------------
121      !!
122      !!                  *** ROUTINE obs_int_z1d_spl ***
123      !!
124      !! ** Purpose : Compute the local vector of vertical second-derivatives
125      !!              of the interpolating function used with a cubic spline.
126      !! 
127      !! ** Method  :
128      !!
129      !!    Top and bottom boundary conditions on the 2nd derivative are
130      !!    set to zero.
131      !!
132      !! ** Action  :
133      !!
134      !! References :
135      !!
136      !! History
137      !!      ! 01-11 (A. Weaver, S. Ricci, N. Daget)
138      !!      ! 06-03 (G. Smith) Conversion to F90 for use with NEMOVAR
139      !!      ! 06-10 (A. Weaver) Cleanup
140      !!----------------------------------------------------------------------
141     
142      !! * Arguments
143      INTEGER, INTENT(IN) :: kpk               ! Number of vertical levels
144      REAL(KIND=wp), INTENT(IN), DIMENSION(kpk) :: &
145         & pobsk, &          ! Model profile at a given (lon,lat)
146         & pdep,  &          ! Model depth array
147         & pobsmask          ! Vertical mask
148      REAL(KIND=wp), INTENT(OUT), DIMENSION(kpk) :: &
149         & pobs2k            ! 2nd derivative of the interpolating function
150 
151      !! * Local declarations
152      INTEGER :: jk
153      REAL(KIND=wp) :: za
154      REAL(KIND=wp) :: zb
155      REAL(KIND=wp) :: zc
156      REAL(KIND=wp) :: zpa
157      REAL(KIND=wp) :: zkm
158      REAL(KIND=wp) :: zkp
159      REAL(KIND=wp) :: zk
160      REAL(KIND=wp), DIMENSION(kpk-1) :: &
161         & zs, &
162         & zp, &
163         & zu, &
164         & zv
165
166      !-----------------------------------------------------------------------
167      ! Matrix initialisation
168      !-----------------------------------------------------------------------
169      zs(1) =  0.0_wp
170      zp(1) =  0.0_wp
171      zv(1) = -0.5_wp
172      DO jk = 2, kpk-1
173         zs(jk) =  ( pdep(jk  ) - pdep(jk-1) ) &
174            &    / ( pdep(jk+1) - pdep(jk-1) )
175         zp(jk) = zs(jk) * zv(jk-1) + 2.0_wp
176         zv(jk) = ( zs(jk) - 1.0_wp ) / zp(jk)
177      END DO
178 
179      !-----------------------------------------------------------------------
180      ! Solution of the tridiagonal system
181      !-----------------------------------------------------------------------
182 
183      ! Top boundary condition
184      zu(1) = 0.0_wp
185 
186      DO jk = 2, kpk-1
187         za = pdep(jk+1) - pdep(jk-1)
188         zb = pdep(jk+1) - pdep(jk  )
189         zc = pdep(jk  ) - pdep(jk-1)
190 
191         zpa = 6.0_wp / ( zp(jk) * za )
192         zkm = zpa / zc
193         zkp = zpa / zb
194         zk  = - ( zkm + zkp )
195 
196         zu(jk) =  pobsk(jk+1) * zkp  &
197            &    + pobsk(jk  ) * zk   &
198            &    + pobsk(jk-1) * zkm  &
199            &    + zu(jk-1) * ( -zs(jk) / zp(jk) )
200      END DO
201 
202      !-----------------------------------------------------------------------
203      ! Second derivative
204      !-----------------------------------------------------------------------
205      pobs2k(kpk) = 0.0_wp
206 
207      ! Bottom boundary condition
208      DO jk = kpk-1, 1, -1
209         pobs2k(jk) = zv(jk) * pobs2k(jk+1) + zu(jk)
210         IF ( pobsmask(jk+1) == 0.0_wp ) pobs2k(jk) = 0.0_wp
211      END DO
212 
213  END SUBROUTINE obs_int_z1d_spl
214
215
Note: See TracBrowser for help on using the repository browser.