module kinds_modTypes:
public type stack3sSubroutines and functions:
private subroutine stack3s_create (st, inisize) private subroutine stack3s_delete (st) private subroutine stack3s_trim (st) private subroutine stack3s_push (st, v)
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_modto 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
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 stack3sComponents:
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 |
private subroutine stack3s_create (st, inisize) type (stack3s), intent(inout) :: st integer (kind=i_k), intent(in) :: inisize end subroutine stack3s_createParameters:
st | the stack3s |
inisize | initial size of array |
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.
private subroutine stack3s_delete (st) type (stack3s), intent(inout) :: st end subroutine stack3s_deleteParameters:
st | the stack3s |
private subroutine stack3s_trim (st) type (stack3s), intent(inout) :: st end subroutine stack3s_trimParameters:
st | the stack3s |
private subroutine stack3s_push (st, v) type (stack3s), intent(inout) :: st integer (kind=i_k), intent(in), dimension (3) :: v end subroutine stack3s_pushParameters:
st | the stack3s |
v | value to push to stack3s |