draw_colorbar Subroutine

public subroutine draw_colorbar(layer)

Draw energy-layer colorbar in right margin.

Framed strip of cells: gain stacks from top (deepest blue strongest), loss from bottom (deepest magenta strongest), half-cell gap between. Each cell labelled w/ its level nint(log10|eps|), naming the cell, not a boundary; GAIN, title and LOSS run up outer edge.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: layer

Energy layer, numbered as in layers.f90.


Source Code

   subroutine draw_colorbar(layer)
      !! Draw energy-layer colorbar in right margin.
      !!
      !! Framed strip of cells: gain stacks from top (deepest blue strongest), loss from bottom
      !! (deepest magenta strongest), half-cell gap between. Each cell labelled w/ its level
      !! nint(log10|eps|), naming the cell, not a boundary; GAIN, title and LOSS run up outer edge.
      ! Arguments
      integer(int32), intent(in) :: layer
         !! Energy layer, numbered as in layers.f90.
      integer(int32) :: gmax, lmax, gmin, lmin, lev
      real(real64) :: dy, y0, f
      character(len=16) :: txt

      if (.not. ecache(layer)%valid) call build_energy_cache(layer)
      gmax = ecache(layer)%gmax; lmax = ecache(layer)%lmax
      call level_mins(layer, gmin, lmin)
      lmin = max(lmin, gmin)             ! convplot clamps loss min to gain min
      if (gmax + lmax <= 0) return

      dy = 1.d0/(real(gmax + lmax, real64) + merge(0.5d0, 0.d0, gmax > 0 .and. lmax > 0))
      call colorbar_viewport()
      call giza_set_fill(1)

      ! gain cells from the top; colours match draw_energy exactly
      do lev = 1, gmax
         f = real(lev, real64)/real(gmax, real64)
         call giza_set_colour_representation(7, 1.d0 - 0.85d0*f, 1.d0 - 0.85d0*f, 1.d0)
         call giza_set_colour_index(7)
         y0 = 1.d0 - real(gmax - lev + 1, real64)*dy
         call giza_rectangle(0.d0, 1.d0, y0, y0 + dy)
         write (txt, '(i0)') gmin + lev - 1
         call cell_label(y0 + 0.5d0*dy, trim(txt))
      end do
      ! loss cells from the bottom
      do lev = 1, lmax
         f = real(lev, real64)/real(lmax, real64)
         call giza_set_colour_representation(7, 1.d0, 1.d0 - 0.85d0*f, 1.d0)
         call giza_set_colour_index(7)
         y0 = real(lmax - lev, real64)*dy
         call giza_rectangle(0.d0, 1.d0, y0, y0 + dy)
         write (txt, '(i0)') lmin + lev - 1
         call cell_label(y0 + 0.5d0*dy, trim(txt))
      end do

      call giza_set_colour_index(1)
      call giza_set_fill(2)
      if (gmax > 0) call giza_rectangle(0.d0, 1.d0, 1.d0 - real(gmax, real64)*dy, 1.d0)
      if (lmax > 0) call giza_rectangle(0.d0, 1.d0, 0.d0, real(lmax, real64)*dy)
      call giza_set_fill(1)
      if (gmax > 0) call colorbar_title(1.d0, 1.d0, CB_TICK, 'GAIN')
      if (lmax > 0) call colorbar_title(0.d0, 0.d0, CB_TICK, 'LOSS')
      call colorbar_title(0.5d0, 0.5d0, 1.d0, &
         merge('log \ge_{nuc} (erg g^{-1} s^{-1})', 'log \ge_{\gn} (erg g^{-1} s^{-1})', layer /= 2))
      call giza_set_character_height(chs)
   end subroutine draw_colorbar