anchor.diff:        outgoing  =  maxval(incoming, mask = incoming.ne.missing .and. pressure.ge.targetPressure)
   
   end subroutine max_over_layer
  +
  +
  +!---------------------------------------------------------------------------------
  +!
  +! function: Minimum over a certain layer
  +!
  +!---------------------------------------------------------------------------------
  +subroutine min_over_layer (incoming, targetPressure, pressure, nlev, missing, outgoing )
  +
  +      integer, intent(in )  ::  nlev
  +      real(8), intent(in )  ::  incoming(nlev), pressure(nlev)
  +      real(8), intent(in )  ::  targetPressure
  +      real(8), intent(in )  ::  missing
  +      real(8), intent(out)  ::  outgoing
  +
  +      outgoing  =  missing
  +      outgoing  =  minval(incoming, mask = incoming.ne.missing .and. pressure.ge.targetPressure)
  +
  +end subroutine min_over_layer
   
   
   
  
positive.code: 
        real(8)               ::  updated_qhum(nlev), updated_temp(nlev), updated_pblp
        real(8)               ::  tbm, tdef, bclp, qbcl
        real(8)               ::  max_omega
  
  
        !-----------------------------------------------------------------------------
  
negative.code: 
  !---------------------------------------------------------------------------------
  !
  ! function: Maximum over a certain layer
  !
  !---------------------------------------------------------------------------------
  subroutine max_over_layer (incoming, targetPressure, pressure, nlev, missing, outgoing )
  