flush_kipp_fields Subroutine

private subroutine flush_kipp_fields(recs, counter, model, nz, fb, nf, ifirst, ilast)

Bin one model's accumulated field values into its record's fld layers.

Values reversed from surface-to-centre (as read) to centre-to-surface; out-of-range or empty models skipped, as in pass one.

Arguments

Type IntentOptional Attributes Name
type(convtype), intent(inout) :: recs(:)

Records of pass one, in stream order.

integer(kind=int32), intent(inout) :: counter

Index of last filled record, advanced by one when model is kept.

integer(kind=int32), intent(in) :: model

Model number.

integer(kind=int32), intent(in) :: nz

Number of cells.

real(kind=real64), intent(in) :: fb(:,:)

Value of each field (rows) and cell (columns, surface to centre).

integer(kind=int32), intent(in) :: nf

Number of registered fields.

integer(kind=int32), intent(in) :: ifirst

First model number to load.

integer(kind=int32), intent(in) :: ilast

Last model number to load.


Source Code

   subroutine flush_kipp_fields(recs, counter, model, nz, fb, nf, ifirst, ilast)
      !! Bin one model's accumulated field values into its record's `fld` layers.
      !!
      !! Values reversed from surface-to-centre (as read) to centre-to-surface; out-of-range or
      !! empty models skipped, as in pass one.
      ! Arguments
      type(convtype), intent(inout) :: recs(:)
         !! Records of pass one, in stream order.
      integer(int32), intent(inout) :: counter
         !! Index of last filled record, advanced by one when model is kept.
      integer(int32), intent(in) :: model
         !! Model number.
      integer(int32), intent(in) :: nz
         !! Number of cells.
      integer(int32), intent(in) :: nf
         !! Number of registered fields.
      integer(int32), intent(in) :: ifirst
         !! First model number to load.
      integer(int32), intent(in) :: ilast
         !! Last model number to load.
      real(real64), intent(in) :: fb(:, :)
         !! Value of each field (rows) and cell (columns, surface to centre).
      real(real64), allocatable :: raw(:)
      integer(int32) :: f, k

      if (nz < 1) return
      if (model < ifirst .or. model > ilast) return
      counter = counter + 1
      if (recs(counter)%ncyc /= model) &
         error stop '[flush_kipp_fields] record/model mismatch between passes'

      recs(counter)%nfld = nf
      allocate (recs(counter)%fld(2, nf))
      allocate (raw(nz))
      do f = 1, nf
         do k = 1, nz
            raw(k) = fb(f, nz - k + 1)
         end do
         call build_field_layer(raw, nz, f, recs(counter)%fld(:, f))
      end do
      deallocate (raw)
   end subroutine flush_kipp_fields