fill_and_remap Subroutine

private subroutine fill_and_remap(v, state_handle, z_out, rho_out, sigma_out, zstar_out)

Invoke the var’s fill (and remap if non-LAYER) so output_buffer holds the current sample. The accumulation / log emission step consumes output_buffer after this.

The single target-levels array the remap proc receives is selected by the var’s output_vgrid: Z_FIXED gets the z-level depths (z_out), DENSITY the isopycnal targets (rho_out), SIGMA the sigma fractions (sigma_out), ZSTAR the reference depths (zstar_out); other non-LAYER vgrids fall back to z_out.

Arguments

Type IntentOptional Attributes Name
type(diag_var_t), intent(inout) :: v
class(*), intent(in) :: state_handle
real(kind=wp), intent(in), allocatable :: z_out(:)
real(kind=wp), intent(in), allocatable :: rho_out(:)
real(kind=wp), intent(in), allocatable :: sigma_out(:)
real(kind=wp), intent(in), allocatable :: zstar_out(:)

Calls

proc~~fill_and_remap~~CallsGraph proc~fill_and_remap fill_and_remap proc~finalise_copy_impl finalise_copy_impl proc~fill_and_remap->proc~finalise_copy_impl

Called by

proc~~fill_and_remap~~CalledByGraph proc~fill_and_remap fill_and_remap proc~ocean_diag_step ocean_diag_t%ocean_diag_step proc~ocean_diag_step->proc~fill_and_remap proc~engine_step_finalize engine_step_finalize proc~engine_step_finalize->proc~ocean_diag_step proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_step_finalize proc~rdb_ocean_step rdb_ocean_step proc~rdb_ocean_step->proc~engine_step_finalize proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean

Source Code

   subroutine fill_and_remap(v, state_handle, z_out, rho_out, sigma_out, zstar_out)
      !! Invoke the var's `fill` (and `remap` if non-LAYER) so
      !! `output_buffer` holds the current sample.  The accumulation
      !! / log emission step consumes `output_buffer` after this.
      !!
      !! The single target-levels array the `remap` proc receives is
      !! selected by the var's `output_vgrid`: Z_FIXED gets the z-level
      !! depths (`z_out`), DENSITY the isopycnal targets (`rho_out`), SIGMA
      !! the sigma fractions (`sigma_out`), ZSTAR the reference depths
      !! (`zstar_out`); other non-LAYER vgrids fall back to `z_out`.
      type(diag_var_t), intent(inout) :: v
      class(*), intent(in) :: state_handle
      ! Allocatable so an unconfigured (unallocated) target array is a legal
      ! actual argument — the select case below dereferences only the array
      ! matching the var's output_vgrid, which is allocated when that vgrid
      ! is in use.  (Non-allocatable dummies would make passing an
      ! unallocated `this%*_out` undefined behaviour, F2018 15.5.2.4.)
      real(wp), intent(in), allocatable :: z_out(:)
      real(wp), intent(in), allocatable :: rho_out(:)
      real(wp), intent(in), allocatable :: sigma_out(:)
      real(wp), intent(in), allocatable :: zstar_out(:)
      if (v%output_vgrid == DIAG_VGRID_LAYER) then
         call v%fill(state_handle, v%output_buffer)
      else
         call v%fill(state_handle, v%layer_buffer)
         if (associated(v%remap)) then
            select case (v%output_vgrid)
            case (DIAG_VGRID_DENSITY)
               call v%remap(state_handle, rho_out, v%layer_buffer, v%output_buffer, &
                            v%is_extensive)
            case (DIAG_VGRID_SIGMA)
               call v%remap(state_handle, sigma_out, v%layer_buffer, v%output_buffer, &
                            v%is_extensive)
            case (DIAG_VGRID_ZSTAR)
               call v%remap(state_handle, zstar_out, v%layer_buffer, v%output_buffer, &
                            v%is_extensive)
            case default
               call v%remap(state_handle, z_out, v%layer_buffer, v%output_buffer, &
                            v%is_extensive)
            end select
         else
            ! Identity passthrough when caller registered a non-LAYER
            ! output vgrid but no remap proc — device-side copy because
            ! both buffers are device-resident under the GPU-resident
            ! pipeline.
            call finalise_copy_impl(v%output_buffer, v%layer_buffer)
         end if
      end if
   end subroutine fill_and_remap