/*
3d_mat.src is written by Kristian Jönsson (January 10, 2003), Department of Economics, Lund University.
Contact info:  kristian.jonsson@nek.lu.se

See separate documentation.

Note:
This code can be used freely as long as proper reference is given.
No performance guarantee is made.
Bug reports are welcome.
*/


/*
These procedures handles three-dimensional matrices.
Throughout x refers to the number of rows, y to the number of columns and z to the number of sheets.
Kristian Jönsson 2003
*/




/* ************************************************************************** */

proc (1)=make_3d(x,y,z);
local res_mat;

res_mat=zeros(x*y,z);

retp(res_mat);
endp;

/* ************************************************************************** */

proc (1)=put_3d(mat,mat_3d,z);
local r_m,r_3d;

r_m=rows(vec(mat));
r_3d=rows(mat_3d);

if r_m == r_3d;
mat_3d[.,z]=vec(mat);
else;
Print; Print "****************************";
Print "Can't perform put_3d!";
Print "Matrices not comformable";
Print "****************************"; Print;
endif;

retp(mat_3d);
endp;

/* ************************************************************************** */

proc (1)=get_3d(mat_3d,x_3d,y_3d,z);
local mat;

mat=reshape(mat_3d[.,z]',y_3d,x_3d)';

retp(mat);
endp;

/* ************************************************************************** */

proc (1)=del_3d(mat_3d,x_3d,y_3d,z);
local res_mat;

mat_3d[.,z]=zeros(x_3d*y_3d,1);

retp(mat_3d);
endp;

/* ************************************************************************** */