module kinds_modTypes:
public type stack3Subroutines and functions:
private subroutine stack3_create (st, inisize) private subroutine stack3_delete (st) private subroutine stack3_push (st, v) private subroutine stack3_move (st_src, st_dest) private subroutine stack3_remove_duplicates (st)
type(stack3) :: st call stack3_create(st,10) stack3_push(st,(/4,1,2/)) stack3_push(st,(/7,0,5/)) print *,'first element on stack is:',st%a(:,1) call stack3_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 stack3_modto your module/subroutine and
include 'stack3.incf'after the contains statement to enable inlining of the stack3 routines.
Author: Matthias Lieber
public type stack3 integer (kind=i_k), pointer, dimension (:,:) :: a => null () integer (kind=i_k) :: pos = 0 end type stack3Components:
a | the actual data is stored in a |
pos | position of topmost element in the stack |
private subroutine stack3_create (st, inisize) type (stack3), intent(inout) :: st integer (kind=i_k), intent(in) :: inisize end subroutine stack3_createParameters:
st | the stack3 |
inisize | initial size of array |
If the stack3 is already allocated, the function reallocates the stack3 only in the case, that the current stack size is less then inisize. Otherwise the stack3 is only cleared, i.e. st%pos is set to 0.
private subroutine stack3_delete (st) type (stack3), intent(inout) :: st end subroutine stack3_deleteParameters:
st | the stack3 |
private subroutine stack3_push (st, v) type (stack3), intent(inout) :: st integer (kind=i_k), intent(in), dimension (3) :: v end subroutine stack3_pushParameters:
st | the stack3 |
v | value to push to stack3 |
private subroutine stack3_move (st_src, st_dest) type (stack3), intent(inout) :: st_src type (stack3), intent(inout) :: st_dest end subroutine stack3_moveParameters:
st_src | the stack3 |
st_dest | the stack3 |
private subroutine stack3_remove_duplicates (st) type (stack3), intent(inout) :: st end subroutine stack3_remove_duplicatesParameters:
st | the stack3 |