Index: /branches/UKMO/AMM15_v3_6_STABLE_package_reanalysis3/NEMOGCM/NEMO/OPA_SRC/OBS/obs_level_search.h90
===================================================================
--- /branches/UKMO/AMM15_v3_6_STABLE_package_reanalysis3/NEMOGCM/NEMO/OPA_SRC/OBS/obs_level_search.h90	(revision 11259)
+++ /branches/UKMO/AMM15_v3_6_STABLE_package_reanalysis3/NEMOGCM/NEMO/OPA_SRC/OBS/obs_level_search.h90	(revision 11260)
@@ -21,4 +21,5 @@
       !!        !  2006-10  (A. Weaver) Cleanup
       !!        !  2008-10  (K. Mogensen) Remove assumptions on grid.
+      !!        !  2019-07  (R. Renshaw) Don't exceed model bottom.
       !!----------------------------------------------------------------------
 
@@ -46,5 +47,5 @@
             IF ( pgrddep(jk) >= pobsdep(ji) ) EXIT depk
          END DO depk
-         kobsk(ji) = jk
+         kobsk(ji) = MIN( jk, kgrd )
       END DO
 
Index: /branches/UKMO/AMM15_v3_6_STABLE_package_reanalysis3/NEMOGCM/NEMO/OPA_SRC/OBS/obsinter_z1d.h90
===================================================================
--- /branches/UKMO/AMM15_v3_6_STABLE_package_reanalysis3/NEMOGCM/NEMO/OPA_SRC/OBS/obsinter_z1d.h90	(revision 11259)
+++ /branches/UKMO/AMM15_v3_6_STABLE_package_reanalysis3/NEMOGCM/NEMO/OPA_SRC/OBS/obsinter_z1d.h90	(revision 11260)
@@ -26,5 +26,5 @@
       !!      ! 06-10 (A. Weaver) Cleanup
       !!      ! 07-01 (K. Mogensen) Use profile rather than single level
-      !!      ! 19-07 (R. Renshaw) Checks on kkco and zsum to avoid occasional NaNs
+      !!      ! 19-07 (R. Renshaw) Avoid division by zero
       !!---------------------------------------------------------------------
 
@@ -51,5 +51,4 @@
       REAL(KIND=wp) :: zsum2
       INTEGER :: jdep             ! Observation depths loop variable
-      INTEGER :: kkco_fix        ! kkco(jdep) limited to number of model levels
     
       !------------------------------------------------------------------------
@@ -62,12 +61,10 @@
          ! Initialization
          !---------------------------------------------------------------------
-!        kkco (from obs_level_search) sometimes has model level kpk+1 which doesn't exist
-         kkco_fix = MIN( kkco(jdep), kpk )
-         z1dm = ( pdep(kkco_fix) - pobsdep(jdep)      )
-         z1dp = ( pobsdep(jdep)    - pdep(kkco_fix-1) )
-!        Where ob is below model bottom, use model bottom and don't extrapolate
-         IF ( pdep(kkco_fix) <= pobsdep(jdep) ) z1dm = 0.0_wp
+         z1dm = ( pdep(kkco(jdep)) - pobsdep(jdep)      )
+         z1dp = ( pobsdep(jdep)    - pdep(kkco(jdep)-1) )
+!        Where ob is below model bottom, use model bottom rather than extrapolate
+         IF ( pdep(kkco(jdep)) <= pobsdep(jdep) ) z1dm = 0.0_wp
 !        Where lower level is missing, use higher level
-         IF ( pobsmask(kkco_fix) == 0.0_wp ) z1dp = 0.0_wp
+         IF ( pobsmask(kkco(jdep)) == 0.0_wp ) z1dp = 0.0_wp
 
          zsum = z1dm + z1dp
@@ -80,6 +77,6 @@
             !  Linear interpolation
             !-----------------------------------------------------------------
-            pobs(jdep) = (   z1dm * pobsk(kkco_fix-1) &
-               &           + z1dp * pobsk(kkco_fix  ) ) / zsum
+            pobs(jdep) = (   z1dm * pobsk(kkco(jdep)-1) &
+               &           + z1dp * pobsk(kkco(jdep)  ) ) / zsum
 
          ELSEIF ( k1dint == 1 ) THEN
@@ -89,8 +86,8 @@
             !-----------------------------------------------------------------
             zsum2 = zsum * zsum
-            pobs(jdep)  = (  z1dm                             * pobsk (kkco_fix-1) &
-               &           + z1dp                             * pobsk (kkco_fix  ) &
-               &           + ( z1dm * ( z1dm * z1dm - zsum2 ) * pobs2k(kkco_fix-1) &
-               &           +   z1dp * ( z1dp * z1dp - zsum2 ) * pobs2k(kkco_fix  ) &
+            pobs(jdep)  = (  z1dm                             * pobsk (kkco(jdep)-1) &
+               &           + z1dp                             * pobsk (kkco(jdep)  ) &
+               &           + ( z1dm * ( z1dm * z1dm - zsum2 ) * pobs2k(kkco(jdep)-1) &
+               &           +   z1dp * ( z1dp * z1dp - zsum2 ) * pobs2k(kkco(jdep)  ) &
                &             ) / 6.0_wp                                              &
                &          ) / zsum
@@ -99,5 +96,5 @@
 
          ELSE  ! take value directly from the higher model level
-            pobs(jdep)  = pobsk(kkco_fix-1)
+            pobs(jdep)  = pobsk(kkco(jdep)-1)
          ENDIF
 
