function indx_full=indx_full_calc(dims,indx)
%
% Call indx_full=indx_full_calc(dims,indx);
%
% Computes n_indx by ndim array of full indices into array with dimensions dims
% for the n_indx-length vector of single indices in indx;
%
% Inputs:
% dims      = dimensions of array;
% indx      = [n_indx,1] column vector of absolute indices into array ([] give all);
%
% Output:
% indx_full = [n_indx,ndim] array of full indices into array;
%
% See also indx_calc to do the reverse operation.
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
ndim=length(dims);
dim_fac=[1;cumprod(dims(:))];
%
if isempty(indx), indx=[1:dim_fac(ndim+1)]; end
%
n_indx=length(indx);
indx_full=zeros(n_indx,ndim);
ii=indx(:);
for jdim=ndim:-1:1,
    indx_full(:,jdim)=floor((ii-1)/dim_fac(jdim))+1;
    ii=ii - (indx_full(:,jdim)-1)*dim_fac(jdim);
end
