draw_scene Subroutine

private subroutine draw_scene()

Draw one frame of Kippenhahn diagram on current device.

Clamps view and updates time unit and offset first, then draws bottom to top: colour layer, convection hatch, grid, surface, then axes, colorbar, model-number strip.

Arguments

None

Source Code

   subroutine draw_scene()
      !! Draw one frame of Kippenhahn diagram on current device.
      !!
      !! Clamps view and updates time unit and offset first, then draws bottom to top: colour layer,
      !! convection hatch, grid, surface, then axes, colorbar, model-number strip.
      character(len=16) :: xopt, yopt
      character(len=64) :: xlabel, ylabel
      real(real64) :: wx1, wx2, wy1, wy2, vx2, xstep, ystep, xlim
      integer(c_int) :: nxsub, nysub
      integer(int32) :: layer, fidx
      logical :: colored, crowded

      ! define convection colours (match ConvPlot.conv_hatch)
      call giza_set_colour_representation(2, 0.0d0, 0.6d0, 0.0d0)  ! conv  green
      call giza_set_colour_representation(3, 0.9d0, 0.0d0, 0.0d0)  ! semi  red
      call giza_set_colour_representation(4, 0.0d0, 0.8d0, 0.9d0)  ! neut  cyan
      call giza_set_colour_representation(5, 0.9d0, 0.0d0, 0.9d0)  ! osht  magenta
      call giza_set_colour_representation(6, 0.85d0, 0.85d0, 0.0d0)! thal  yellow

      call clamp_view()
      ! log ticks are powers of ten in any unit, so a log axis keeps its unit
      if (st%tauto .and. st%xaxis == 'time' .and. .not. st%xlog) &
         call set_time_unit(auto_time_unit((st%xmax - st%xmin)*UFAC(unit_id(st%tunit))))
      call set_visible_range()
      xoff = 0.d0; xofftxt = ''
      if (st%xoffset .and. st%xaxis == 'time' .and. .not. st%xlog) &
         call axis_offset(st%xmin, st%xmax, unit_id(st%tunit), xoff, xofftxt)
      wx1 = xtrans(st%xmin); wx2 = xtrans(st%xmax)
      wy1 = ytrans2(st%ymin); wy2 = ytrans2(st%ymax)
      ! emit clamp box: coordinates handed to giza are limited to ~1e3
      ! window spans around the view.  cairo stores device coordinates in
      ! 24.8 fixed point, and vertices mapping millions of pixels
      ! off-screen (a region interface far outside a deep zoom) wrap or
      ! degenerate -- fills then vanish or flood the window.  Points that
      ! far out are never visible, so the clamp is exact for the
      ! axis-aligned band/outline geometry and sub-pixel for the surface.
      exlo = wx1 - CLAMP_SPANS*(wx2 - wx1)
      exhi = wx2 + CLAMP_SPANS*(wx2 - wx1)
      eylo = wy1 - CLAMP_SPANS*(wy2 - wy1)
      eyhi = wy2 + CLAMP_SPANS*(wy2 - wy1)

      ! leave the right margin for the colorbar whenever a colour field is
      ! shown (an energy layer, or a generic quantized column)
      layer = layer_of_cfield()
      fidx = 0
      if (layer < 0) fidx = field_of_cfield()
      colored = (layer >= 0 .or. fidx > 0)
      vx2 = merge(0.84d0, 0.95d0, colored)

      ! there used to be a bug in giza_open_device that didnt let it to respect
      ! clipping, so you had to call it twice to absorb the default one.
      ! fixed upstream.
      call giza_set_viewport(0.12d0, vx2, 0.12d0, 0.96d0)
      call giza_set_window(wx1, wx2, wy1, wy2)
      ! erase the full page here, not just at change-page: on /xw a window
      ! resize detected inside giza_set_viewport recreates the pixmap, so
      ! an erase done before this point can be silently discarded and the
      ! frame composites over undefined pixmap memory (ghost artifacts)
      call giza_draw_background()
      call giza_set_character_height(chs)
      call ensure_scratch(4*nmodels + 4)

      ! Convection zones are always drawn (hatched, like convplot's hatch-only
      ! patches).
      !
      ! When `color` selects a nuclear/neutrino energy field, it is
      ! drawn first as solid gain (blue) / loss (magenta) bands, and the
      ! convection hatching is overlaid on top.  A generic column field is
      ! drawn the same way as nested colormap contours.
      if (layer >= 0) then
         call draw_energy(layer)             ! color/energy layer
      else if (fidx > 0) then
         call draw_field(fidx)               ! generic column colour field
      end if
      call draw_convection() ! convective hatch
      call draw_grid(wx1, wx2, wy1, wy2)
      call draw_surface() ! surface of star

      ! axes on top
      call giza_set_colour_index(1)
      call giza_set_line_width(1.d0)
      xopt = 'BCST'; yopt = 'BCST'
      if (st%xlog) xopt = 'BCSTL'
      if (st%ylog) yopt = 'BCSTL'
      ! x labels may reach the page edge, or the colorbar strip when shown
      xlim = merge(0.86d0, 1.d0, colored)
      ! giza_box's automatic step is capped at 0.2 of the range (always
      ! reached on y for kippy's viewport, pixel-checked on png and pdf with
      ! giza's default font); x widens it until its labels fit.  the steps
      ! are passed explicitly so tick_labels' labels land on the ticks.
      ! log axes tick each decade and ignore the step
      xstep = 1.d0; nxsub = 1; ystep = 1.d0; nysub = 1
      if (.not. st%ylog) ystep = c_giza_round(0.2d0*(wy2 - wy1), nysub)
      if (.not. st%xlog) call fit_x_step(wx1, wx2, wy1, wy2, xlim, xstep, nxsub)
      call c_giza_box(trim(xopt)//c_null_char, xstep, nxsub, trim(yopt)//c_null_char, ystep, nysub)
      call tick_labels(wx1, wx2, wy1, wy2, xstep, ystep, xlim, .false., crowded)
      call labels(xlabel, ylabel)
      call giza_label(trim(xlabel), trim(ylabel), '')
      ! matplotlib's spot: right end of the axis, below the tick labels
      if (len_trim(xofftxt) > 0) call giza_annotate('B', 3.0, 1.0, 1.0, trim(xofftxt))

      ! make colorbar + other
      if (colored) then
         if (layer >= 0) then
            call draw_colorbar(layer)
         else
            call draw_field_colorbar(fidx)
         end if
         ! restore the plot viewport/window so the interactive cursor
         ! keeps mapping pixels to data coordinates
         call giza_set_viewport(0.12d0, vx2, 0.12d0, 0.96d0)
         call giza_set_window(wx1, wx2, wy1, wy2)
      end if
      call draw_models(wx1, wx2, wy1, wy2, vx2)
   end subroutine draw_scene