Module stack3s_mod


Uses:
    module kinds_mod
Types:
    public type stack3s
Subroutines and functions:
    private subroutine stack3s_create (st, inisize)
    private subroutine stack3s_delete (st)
    private subroutine stack3s_trim (st)
    private subroutine stack3s_push (st, v)

A simple stack of 3D coordinates (3 integers) which grows ad infinutum if required. Data is stored in a single contiguous array.

In contrast to the stack3, the stack3s stores the current top of the stack pos in the same contiguous memory as the actual data, which makes it easily possible to transfer the stack3s via message passing.

  type(stack3s) :: st
  call stack3s_create(st,10)
  stack3s_push(st,(/4,1,2/))
  stack3s_push(st,(/7,0,5/))
  print *,'first element on stack is:',st%a(:,1)
  call stack3s_delete(st)

Clear the stack, i.e. set topmost element = bottom. The size of the storage array is left unchanged.

  st%pos = 0

Get element from stack. The index must be in the interval 1 <= i <= size(st%a).

  st%a(:,i)

Add

  use stack3s_mod
to your module/subroutine and
  include 'stack3s.incf'
after the contains statement to enable inlining of the stack3s routines.

Author: Matthias Lieber

See also: module stack3_mod


Description of Types

stack3s

public type stack3s
    integer (kind=i_k), pointer, dimension (:,:) :: a => null ()
    integer (kind=i_k), pointer :: pos => null ()
    integer (kind=i_k), pointer, dimension (:,:) :: m => null ()
end type stack3s
Components:
a the data is stored in a
pos position of topmost element in the stack
m here we allocate the actual memory for both a and pos

Description of Subroutines and Functions

stack3s_create

private subroutine stack3s_create (st, inisize)
    type (stack3s), intent(inout) :: st
    integer (kind=i_k), intent(in) :: inisize
end subroutine stack3s_create
Parameters:
st the stack3s
inisize initial size of array
Create a stack3s or reallocate at given size.

If the stack3s is already allocated, the function reallocates the stack3s only in the case, that the current stack size is less then inisize. Otherwise the stack3s is only cleared, i.e. st%pos is set to 0.


stack3s_delete

private subroutine stack3s_delete (st)
    type (stack3s), intent(inout) :: st
end subroutine stack3s_delete
Parameters:
st the stack3s
Delete the stack3s and all of its memory.

stack3s_trim

private subroutine stack3s_trim (st)
    type (stack3s), intent(inout) :: st
end subroutine stack3s_trim
Parameters:
st the stack3s
Reallocate the stack3s array to exactly fit the required size.

stack3s_push

private subroutine stack3s_push (st, v)
    type (stack3s), intent(inout) :: st
    integer (kind=i_k), intent(in), dimension (3) :: v
end subroutine stack3s_push
Parameters:
st the stack3s
v value to push to stack3s
Push a new element to the top of the stack3s. The storage array will be enlarged by a factor of two if required.