bathymetry_median Function

private pure function bathymetry_median(b) result(med)

Approximate median via a full sort — b is a setup-time array (called once per create(), never per-step), so O(n log n) is fine; this exists purely to make the sign-error message name a representative depth rather than minval/maxval (which a single outlier cell would distort).

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: b(:,:)

Return Value real(kind=wp)


Calls

proc~~bathymetry_median~~CallsGraph proc~bathymetry_median bathymetry_median proc~sort_real sort_real proc~bathymetry_median->proc~sort_real

Called by

proc~~bathymetry_median~~CalledByGraph proc~bathymetry_median bathymetry_median proc~bathymetry_normalise_sign bathymetry_normalise_sign proc~bathymetry_normalise_sign->proc~bathymetry_median proc~ocean_state_seed_from_cfg ocean_state_seed_from_cfg proc~ocean_state_seed_from_cfg->proc~bathymetry_normalise_sign proc~engine_setup engine_setup proc~engine_setup->proc~ocean_state_seed_from_cfg proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~engine_setup proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_setup proc~driver_validate driver_validate proc~driver_validate->proc~engine_setup proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean proc~rdb_ocean_create_finalize rdb_ocean_create_finalize proc~rdb_ocean_create_finalize->proc~complete_ocean_create proc~rdb_ocean_create_from_string rdb_ocean_create_from_string proc~rdb_ocean_create_from_string->proc~complete_ocean_create

Variables

Type Visibility Attributes Name Initial
real(kind=wp), private, allocatable :: flat(:)
integer, private :: n

Source Code

   pure function bathymetry_median(b) result(med)
      !! Approximate median via a full sort — `b` is a setup-time array
      !! (called once per `create()`, never per-step), so O(n log n) is
      !! fine; this exists purely to make the sign-error message name a
      !! representative depth rather than `minval`/`maxval` (which a single
      !! outlier cell would distort).
      real(wp), intent(in) :: b(:, :)
      real(wp) :: med
      real(wp), allocatable :: flat(:)
      integer :: n

      n = size(b)
      allocate (flat(n), source=reshape(b, [n]))
      call sort_real(flat)
      if (mod(n, 2) == 1) then
         med = flat((n + 1)/2)
      else
         med = 0.5_wp*(flat(n/2) + flat(n/2 + 1))
      end if
   end function bathymetry_median