build_zones Subroutine

public subroutine build_zones(zones, nz, cnv)

Run-length compress cell zone types into yzip and iconv.

Each run of equal types is one zone, iconv its outer cell index. Radiative runs included, so zones tile whole star ("Convection zones", docs/cnvfiles.md).

Arguments

Type IntentOptional Attributes Name
character(len=1), intent(in) :: zones(:)

ZONE_CHAR type of each cell, centre to surface, already mapped from reader's codes.

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

Number of cells.

type(convtype), intent(inout) :: cnv

Record receiving nconv, yzip, iconv.


Source Code

   subroutine build_zones(zones, nz, cnv)
      !! Run-length compress cell zone types into `yzip` and `iconv`.
      !!
      !! Each run of equal types is one zone, `iconv` its outer cell index. Radiative runs included,
      !! so zones tile whole star ("Convection zones", docs/cnvfiles.md).
      ! Arguments
      character(len=1), intent(in) :: zones(:)
         !! `ZONE_CHAR` type of each cell, centre to surface, already mapped from reader's codes.
      integer(int32), intent(in) :: nz
         !! Number of cells.
      type(convtype), intent(inout) :: cnv
         !! Record receiving `nconv`, `yzip`, `iconv`.
      integer(int32) :: k, nconv
      character(len=1), allocatable :: yz(:)
      integer(int32), allocatable :: ic(:)

      allocate (yz(nz), ic(nz))
      nconv = 0
      do k = 1, nz
         if (k == nz) then
            nconv = nconv + 1
            yz(nconv) = zones(k)
            ic(nconv) = k
         else if (zones(k) /= zones(k + 1)) then
            nconv = nconv + 1
            yz(nconv) = zones(k)
            ic(nconv) = k
         end if
      end do

      cnv%nconv = nconv
      allocate (cnv%yzip(nconv), cnv%iconv(nconv))
      cnv%yzip = yz(1:nconv)
      cnv%iconv = int(ic(1:nconv), idx_kind)
      deallocate (yz, ic)
   end subroutine build_zones