hex_insert Subroutine

public pure subroutine hex_insert(vec, val)

Utility to grow type(hex) arrays, it is a poor man implementation of a dynamic array insertion, a là std::vector (but with no preallocation and smart doubling...)

Arguments

Type IntentOptional Attributes Name
type(hex), intent(inout), allocatable :: vec(:)
type(hex), intent(in) :: val

Called by

proc~~hex_insert~~CalledByGraph proc~hex_insert hex_geometries::hex_insert proc~hex_armchair_stripe hex_geometries::hex_armchair_stripe proc~hex_armchair_stripe->proc~hex_insert proc~hex_flake hex_geometries::hex_flake proc~hex_flake->proc~hex_insert proc~hex_line hex_geometries::hex_line proc~hex_line->proc~hex_insert proc~hex_triangle hex_geometries::hex_triangle proc~hex_triangle->proc~hex_insert proc~hex_zigzag_stripe hex_geometries::hex_zigzag_stripe proc~hex_zigzag_stripe->proc~hex_insert proc~get_flake honeytools::get_flake proc~get_flake->proc~hex_flake proc~get_stripe honeytools::get_stripe proc~get_stripe->proc~hex_armchair_stripe proc~get_stripe->proc~hex_zigzag_stripe proc~get_triangle honeytools::get_triangle proc~get_triangle->proc~hex_triangle

Source Code

   pure subroutine hex_insert(vec,val)
      !! Utility to grow type(hex) arrays, it is a
      !! poor man implementation of a dynamic array
      !! insertion, a là std::vector (but with no
      !! preallocation and smart doubling...)
      type(hex),intent(inout),allocatable :: vec(:)
      type(hex),intent(in)                :: val
      type(hex),allocatable               :: tmp(:)
      integer                             :: len
      if(allocated(vec))then
         len = size(vec)
         allocate(tmp(len+1))
         tmp(:len) = vec
         call move_alloc(tmp,vec)
         len = len + 1
      else
         len = 1
         allocate(vec(len))
      end if
      ! Insert val at back
      vec(len) = val
   end subroutine hex_insert